Annotation of loncom/homework/grades.pm, revision 1.596.2.12.2.1
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.596.2.12.2. (raeburn 4:): # $Id: grades.pm,v 1.596.2.12 2011/12/01 00:36:59 raeburn Exp $
1.17 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: #
1.1 albertel 28:
1.529 jms 29:
30:
1.1 albertel 31: package Apache::grades;
32: use strict;
33: use Apache::style;
34: use Apache::lonxml;
35: use Apache::lonnet;
1.3 albertel 36: use Apache::loncommon;
1.112 ng 37: use Apache::lonhtmlcommon;
1.68 ng 38: use Apache::lonnavmaps;
1.1 albertel 39: use Apache::lonhomework;
1.456 banghart 40: use Apache::lonpickcode;
1.55 matthew 41: use Apache::loncoursedata;
1.362 albertel 42: use Apache::lonmsg();
1.596.2.4 raeburn 43: use Apache::Constants qw(:common :http);
1.167 sakharuk 44: use Apache::lonlocal;
1.386 raeburn 45: use Apache::lonenc;
1.596.2.4 raeburn 46: use Apache::bridgetask();
1.170 albertel 47: use String::Similarity;
1.359 www 48: use LONCAPA;
49:
1.315 bowersj2 50: use POSIX qw(floor);
1.87 www 51:
1.435 foxr 52:
1.513 foxr 53:
1.435 foxr 54: my %perm=();
1.447 foxr 55:
1.513 foxr 56: # These variables are used to recover from ssi errors
57:
58: my $ssi_retries = 5;
59: my $ssi_error;
60: my $ssi_error_resource;
61: my $ssi_error_message;
62:
63:
64: sub ssi_with_retries {
65: my ($resource, $retries, %form) = @_;
66: my ($content, $response) = &Apache::loncommon::ssi_with_retries($resource, $retries, %form);
67: if ($response->is_error) {
68: $ssi_error = 1;
69: $ssi_error_resource = $resource;
70: $ssi_error_message = $response->code . " " . $response->message;
71: }
72:
73: return $content;
74:
75: }
76: #
77: # Prodcuces an ssi retry failure error message to the user:
78: #
79:
80: sub ssi_print_error {
81: my ($r) = @_;
1.516 raeburn 82: my $helpurl = &Apache::loncommon::top_nav_help('Helpdesk');
83: $r->print('
84: <br />
85: <h2>'.&mt('An unrecoverable network error occurred:').'</h2>
86: <p>
87: '.&mt('Unable to retrieve a resource from a server:').'<br />
88: '.&mt('Resource:').' '.$ssi_error_resource.'<br />
89: '.&mt('Error:').' '.$ssi_error_message.'
90: </p>
91: <p>'.
92: &mt('It is recommended that you try again later, as this error may mean the server was just temporarily unavailable, or is down for maintenance.').'<br />'.
93: &mt('If the error persists, please contact the [_1] for assistance.',$helpurl).
94: '</p>');
95: return;
1.513 foxr 96: }
97:
1.44 ng 98: #
1.146 albertel 99: # --- Retrieve the parts from the metadata file.---
1.44 ng 100: sub getpartlist {
1.582 raeburn 101: my ($symb,$errorref) = @_;
1.439 albertel 102:
103: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 104: unless (ref($navmap)) {
105: if (ref($errorref)) {
106: $$errorref = 'navmap';
107: return;
108: }
109: }
1.439 albertel 110: my $res = $navmap->getBySymb($symb);
111: my $partlist = $res->parts();
112: my $url = $res->src();
113: my @metakeys = split(/,/,&Apache::lonnet::metadata($url,'keys'));
114:
1.146 albertel 115: my @stores;
1.439 albertel 116: foreach my $part (@{ $partlist }) {
1.146 albertel 117: foreach my $key (@metakeys) {
118: if ($key =~ m/^stores_\Q$part\E_/) { push(@stores,$key); }
119: }
120: }
121: return @stores;
1.2 albertel 122: }
123:
1.44 ng 124: # --- Get the symbolic name of a problem and the url
1.324 albertel 125: sub get_symb {
1.173 albertel 126: my ($request,$silent) = @_;
1.257 albertel 127: (my $url=$env{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
128: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
1.173 albertel 129: if ($symb eq '') {
130: if (!$silent) {
1.596.2.4 raeburn 131: $request->print(&mt("Unable to handle ambiguous references: [_1].",$url));
1.173 albertel 132: return ();
133: }
134: }
1.418 albertel 135: &Apache::lonenc::check_decrypt(\$symb);
1.324 albertel 136: return ($symb);
1.32 ng 137: }
138:
1.129 ng 139: #--- Format fullname, username:domain if different for display
140: #--- Use anywhere where the student names are listed
141: sub nameUserString {
142: my ($type,$fullname,$uname,$udom) = @_;
143: if ($type eq 'header') {
1.485 albertel 144: return '<b> '.&mt('Fullname').' </b><span class="LC_internal_info">('.&mt('Username').')</span>';
1.129 ng 145: } else {
1.398 albertel 146: return ' '.$fullname.'<span class="LC_internal_info"> ('.$uname.
147: ($env{'user.domain'} eq $udom ? '' : ' ('.$udom.')').')</span>';
1.129 ng 148: }
149: }
150:
1.44 ng 151: #--- Get the partlist and the response type for a given problem. ---
152: #--- Indicate if a response type is coded handgraded or not. ---
1.39 ng 153: sub response_type {
1.582 raeburn 154: my ($symb,$response_error) = @_;
1.377 albertel 155:
156: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 157: unless (ref($navmap)) {
158: if (ref($response_error)) {
159: $$response_error = 1;
160: }
161: return;
162: }
1.377 albertel 163: my $res = $navmap->getBySymb($symb);
1.593 raeburn 164: unless (ref($res)) {
165: $$response_error = 1;
166: return;
167: }
1.377 albertel 168: my $partlist = $res->parts();
1.392 albertel 169: my %vPart =
170: map { $_ => 1 } (&Apache::loncommon::get_env_multiple('form.vPart'));
1.377 albertel 171: my (%response_types,%handgrade);
172: foreach my $part (@{ $partlist }) {
1.392 albertel 173: next if (%vPart && !exists($vPart{$part}));
174:
1.377 albertel 175: my @types = $res->responseType($part);
176: my @ids = $res->responseIds($part);
177: for (my $i=0; $i < scalar(@ids); $i++) {
178: $response_types{$part}{$ids[$i]} = $types[$i];
179: $handgrade{$part.'_'.$ids[$i]} =
180: &Apache::lonnet::EXT('resource.'.$part.'_'.$ids[$i].
181: '.handgrade',$symb);
1.41 ng 182: }
183: }
1.377 albertel 184: return ($partlist,\%handgrade,\%response_types);
1.39 ng 185: }
186:
1.375 albertel 187: sub flatten_responseType {
188: my ($responseType) = @_;
189: my @part_response_id =
190: map {
191: my $part = $_;
192: map {
193: [$part,$_]
194: } sort(keys(%{ $responseType->{$part} }));
195: } sort(keys(%$responseType));
196: return @part_response_id;
197: }
198:
1.207 albertel 199: sub get_display_part {
1.324 albertel 200: my ($partID,$symb)=@_;
1.207 albertel 201: my $display=&Apache::lonnet::EXT('resource.'.$partID.'.display',$symb);
202: if (defined($display) and $display ne '') {
1.577 bisitz 203: $display.= ' (<span class="LC_internal_info">'
204: .&mt('Part ID: [_1]',$partID).'</span>)';
1.207 albertel 205: } else {
206: $display=$partID;
207: }
208: return $display;
209: }
1.269 raeburn 210:
1.118 ng 211: #--- Show resource title
212: #--- and parts and response type
213: sub showResourceInfo {
1.582 raeburn 214: my ($symb,$probTitle,$checkboxes,$res_error) = @_;
1.398 albertel 215: my $result = '<h3>'.&mt('Current Resource').': '.$probTitle.'</h3>'."\n";
1.582 raeburn 216: my ($partlist,$handgrade,$responseType) = &response_type($symb,$res_error);
217: if (ref($res_error)) {
218: if ($$res_error) {
219: return;
220: }
221: }
1.584 bisitz 222: $result.=&Apache::loncommon::start_data_table()
223: .&Apache::loncommon::start_data_table_header_row();
224: if ($checkboxes) {
225: $result.='<th> </th>';
226: }
227: $result.='<th>'.&mt('Problem Part').'</th>'
228: .'<th>'.&mt('Res. ID').'</th>'
229: .'<th>'.&mt('Type').'</th>'
230: .&Apache::loncommon::end_data_table_header_row();
1.126 ng 231: my %resptype = ();
1.122 ng 232: my $hdgrade='no';
1.154 albertel 233: my %partsseen;
1.524 raeburn 234: foreach my $partID (sort(keys(%$responseType))) {
1.584 bisitz 235: foreach my $resID (sort(keys(%{ $responseType->{$partID} }))) {
236: my $handgrade=$$handgrade{$partID.'_'.$resID};
237: my $responsetype = $responseType->{$partID}->{$resID};
238: $hdgrade = $handgrade if ($handgrade eq 'yes');
239: $result.=&Apache::loncommon::start_data_table_row();
240: if ($checkboxes) {
241: if (exists($partsseen{$partID})) {
242: $result.="<td> </td>";
243: } else {
244: $result.="<td><input type='checkbox' name='vPart' value='$partID' checked='checked' /></td>";
245: }
246: $partsseen{$partID}=1;
247: }
248: my $display_part=&get_display_part($partID,$symb);
249: $result.='<td>'.$display_part.'</td>'
250: .'<td>'.'<span class="LC_internal_info">'.$resID.'</span></td>'
251: .'<td>'.&mt($responsetype).'</td>'
252: # .'<td>'.&mt('<b>Handgrade: </b>[_1]',$handgrade).'</td>'
253: .&Apache::loncommon::end_data_table_row();
254: }
1.118 ng 255: }
1.584 bisitz 256: $result.=&Apache::loncommon::end_data_table();
1.147 albertel 257: return $result,$responseType,$hdgrade,$partlist,$handgrade;
1.118 ng 258: }
259:
1.434 albertel 260: sub reset_caches {
261: &reset_analyze_cache();
262: &reset_perm();
263: }
264:
265: {
266: my %analyze_cache;
1.557 raeburn 267: my %analyze_cache_formkeys;
1.148 albertel 268:
1.434 albertel 269: sub reset_analyze_cache {
270: undef(%analyze_cache);
1.557 raeburn 271: undef(%analyze_cache_formkeys);
1.434 albertel 272: }
273:
274: sub get_analyze {
1.596.2.12.2. (raeburn 275:): my ($symb,$uname,$udom,$no_increment,$add_to_hash,$type,$trial,$rndseed,$bubbles_per_row)=@_;
1.434 albertel 276: my $key = "$symb\0$uname\0$udom";
1.596.2.2 raeburn 277: if ($type eq 'randomizetry') {
278: if ($trial ne '') {
279: $key .= "\0".$trial;
280: }
281: }
1.557 raeburn 282: if (exists($analyze_cache{$key})) {
283: my $getupdate = 0;
284: if (ref($add_to_hash) eq 'HASH') {
285: foreach my $item (keys(%{$add_to_hash})) {
286: if (ref($analyze_cache_formkeys{$key}) eq 'HASH') {
287: if (!exists($analyze_cache_formkeys{$key}{$item})) {
288: $getupdate = 1;
289: last;
290: }
291: } else {
292: $getupdate = 1;
293: }
294: }
295: }
296: if (!$getupdate) {
297: return $analyze_cache{$key};
298: }
299: }
1.434 albertel 300:
301: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
302: $url=&Apache::lonnet::clutter($url);
1.557 raeburn 303: my %form = ('grade_target' => 'analyze',
304: 'grade_domain' => $udom,
305: 'grade_symb' => $symb,
306: 'grade_courseid' => $env{'request.course.id'},
307: 'grade_username' => $uname,
308: 'grade_noincrement' => $no_increment);
1.596.2.12.2. (raeburn 309:): if ($bubbles_per_row ne '') {
310:): $form{'bubbles_per_row'} = $bubbles_per_row;
311:): }
1.596.2.2 raeburn 312: if ($type eq 'randomizetry') {
313: $form{'grade_questiontype'} = $type;
314: if ($rndseed ne '') {
315: $form{'grade_rndseed'} = $rndseed;
316: }
317: }
1.557 raeburn 318: if (ref($add_to_hash)) {
319: %form = (%form,%{$add_to_hash});
1.596.2.2 raeburn 320: }
1.557 raeburn 321: my $subresult=&ssi_with_retries($url, $ssi_retries,%form);
1.434 albertel 322: (undef,$subresult)=split(/_HASH_REF__/,$subresult,2);
323: my %analyze=&Apache::lonnet::str2hash($subresult);
1.557 raeburn 324: if (ref($add_to_hash) eq 'HASH') {
325: $analyze_cache_formkeys{$key} = $add_to_hash;
326: } else {
327: $analyze_cache_formkeys{$key} = {};
328: }
1.434 albertel 329: return $analyze_cache{$key} = \%analyze;
330: }
331:
332: sub get_order {
1.596.2.2 raeburn 333: my ($partid,$respid,$symb,$uname,$udom,$no_increment,$type,$trial,$rndseed)=@_;
334: my $analyze = &get_analyze($symb,$uname,$udom,$no_increment,undef,$type,$trial,$rndseed);
1.434 albertel 335: return $analyze->{"$partid.$respid.shown"};
336: }
337:
338: sub get_radiobutton_correct_foil {
1.596.2.2 raeburn 339: my ($partid,$respid,$symb,$uname,$udom,$type,$trial,$rndseed)=@_;
340: my $analyze = &get_analyze($symb,$uname,$udom,undef,undef,$type,$trial,$rndseed);
341: my $foils = &get_order($partid,$respid,$symb,$uname,$udom,undef,$type,$trial,$rndseed);
1.555 raeburn 342: if (ref($foils) eq 'ARRAY') {
343: foreach my $foil (@{$foils}) {
344: if ($analyze->{"$partid.$respid.foil.value.$foil"} eq 'true') {
345: return $foil;
346: }
1.434 albertel 347: }
348: }
349: }
1.554 raeburn 350:
351: sub scantron_partids_tograde {
1.596.2.12.2. (raeburn 352:): my ($resource,$cid,$uname,$udom,$check_for_randomlist,$bubbles_per_row) = @_;
1.554 raeburn 353: my (%analysis,@parts);
354: if (ref($resource)) {
355: my $symb = $resource->symb();
1.557 raeburn 356: my $add_to_form;
357: if ($check_for_randomlist) {
358: $add_to_form = { 'check_parts_withrandomlist' => 1,};
359: }
1.596.2.12.2. (raeburn 360:): my $analyze =
361:): &get_analyze($symb,$uname,$udom,undef,$add_to_form,
362:): undef,undef,undef,$bubbles_per_row);
1.554 raeburn 363: if (ref($analyze) eq 'HASH') {
364: %analysis = %{$analyze};
365: }
366: if (ref($analysis{'parts'}) eq 'ARRAY') {
367: foreach my $part (@{$analysis{'parts'}}) {
368: my ($id,$respid) = split(/\./,$part);
369: if (!&Apache::loncommon::check_if_partid_hidden($id,$symb,$udom,$uname)) {
370: push(@parts,$part);
371: }
372: }
373: }
374: }
375: return (\%analysis,\@parts);
376: }
377:
1.148 albertel 378: }
1.434 albertel 379:
1.118 ng 380: #--- Clean response type for display
1.335 albertel 381: #--- Currently filters option/rank/radiobutton/match/essay/Task
382: # response types only.
1.118 ng 383: sub cleanRecord {
1.336 albertel 384: my ($answer,$response,$symb,$partid,$respid,$record,$order,$version,
1.596.2.2 raeburn 385: $uname,$udom,$type,$trial,$rndseed) = @_;
1.398 albertel 386: my $grayFont = '<span class="LC_internal_info">';
1.148 albertel 387: if ($response =~ /^(option|rank)$/) {
388: my %answer=&Apache::lonnet::str2hash($answer);
389: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
390: my ($toprow,$bottomrow);
391: foreach my $foil (@$order) {
392: if ($grading{$foil} == 1) {
393: $toprow.='<td><b>'.$answer{$foil}.' </b></td>';
394: } else {
395: $toprow.='<td><i>'.$answer{$foil}.' </i></td>';
396: }
1.398 albertel 397: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.148 albertel 398: }
399: return '<blockquote><table border="1">'.
1.466 albertel 400: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
401: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.596.2.1 raeburn 402: $bottomrow.'</tr></table></blockquote>';
1.148 albertel 403: } elsif ($response eq 'match') {
404: my %answer=&Apache::lonnet::str2hash($answer);
405: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
406: my @items=&Apache::lonnet::str2array($record->{$version."resource.$partid.$respid.submissionitems"});
407: my ($toprow,$middlerow,$bottomrow);
408: foreach my $foil (@$order) {
409: my $item=shift(@items);
410: if ($grading{$foil} == 1) {
411: $toprow.='<td><b>'.$item.' </b></td>';
1.398 albertel 412: $middlerow.='<td><b>'.$grayFont.$answer{$foil}.' </span></b></td>';
1.148 albertel 413: } else {
414: $toprow.='<td><i>'.$item.' </i></td>';
1.398 albertel 415: $middlerow.='<td><i>'.$grayFont.$answer{$foil}.' </span></i></td>';
1.148 albertel 416: }
1.398 albertel 417: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.118 ng 418: }
1.126 ng 419: return '<blockquote><table border="1">'.
1.466 albertel 420: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
421: '<tr valign="top"><td>'.$grayFont.&mt('Item ID').'</span></td>'.
1.148 albertel 422: $middlerow.'</tr>'.
1.466 albertel 423: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.596.2.8 raeburn 424: $bottomrow.'</tr></table></blockquote>';
1.148 albertel 425: } elsif ($response eq 'radiobutton') {
426: my %answer=&Apache::lonnet::str2hash($answer);
427: my ($toprow,$bottomrow);
1.434 albertel 428: my $correct =
1.596.2.2 raeburn 429: &get_radiobutton_correct_foil($partid,$respid,$symb,$uname,$udom,$type,$trial,$rndseed);
1.434 albertel 430: foreach my $foil (@$order) {
1.148 albertel 431: if (exists($answer{$foil})) {
1.434 albertel 432: if ($foil eq $correct) {
1.466 albertel 433: $toprow.='<td><b>'.&mt('true').'</b></td>';
1.148 albertel 434: } else {
1.466 albertel 435: $toprow.='<td><i>'.&mt('true').'</i></td>';
1.148 albertel 436: }
437: } else {
1.466 albertel 438: $toprow.='<td>'.&mt('false').'</td>';
1.148 albertel 439: }
1.398 albertel 440: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.148 albertel 441: }
442: return '<blockquote><table border="1">'.
1.466 albertel 443: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
444: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.596.2.4 raeburn 445: $bottomrow.'</tr></table></blockquote>';
1.148 albertel 446: } elsif ($response eq 'essay') {
1.257 albertel 447: if (! exists ($env{'form.'.$symb})) {
1.122 ng 448: my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 449: $env{'course.'.$env{'request.course.id'}.'.domain'},
450: $env{'course.'.$env{'request.course.id'}.'.num'});
1.122 ng 451:
1.257 albertel 452: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
453: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
454: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
455: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
456: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
457: $env{'form.'.$symb} = 1; # so that we don't have to read it from disk for multiple sub of the same prob.
1.122 ng 458: }
1.166 albertel 459: $answer =~ s-\n-<br />-g;
460: return '<br /><br /><blockquote><tt>'.&keywords_highlight($answer).'</tt></blockquote>';
1.268 albertel 461: } elsif ( $response eq 'organic') {
462: my $result='Smile representation: "<tt>'.$answer.'</tt>"';
463: my $jme=$record->{$version."resource.$partid.$respid.molecule"};
464: $result.=&Apache::chemresponse::jme_img($jme,$answer,400);
465: return $result;
1.335 albertel 466: } elsif ( $response eq 'Task') {
467: if ( $answer eq 'SUBMITTED') {
468: my $files = $record->{$version."resource.$respid.$partid.bridgetask.portfiles"};
1.336 albertel 469: my $result = &Apache::bridgetask::file_list($files,$uname,$udom);
1.335 albertel 470: return $result;
471: } elsif ( grep(/^\Q$version\E.*?\.instance$/, keys(%{$record})) ) {
472: my @matches = grep(/^\Q$version\E.*?\.instance$/,
473: keys(%{$record}));
474: return join('<br />',($version,@matches));
475:
476:
477: } else {
478: my $result =
479: '<p>'
480: .&mt('Overall result: [_1]',
481: $record->{$version."resource.$respid.$partid.status"})
482: .'</p>';
483:
484: $result .= '<ul>';
485: my @grade = grep(/^\Q${version}resource.$respid.$partid.\E[^.]*[.]status$/,
486: keys(%{$record}));
487: foreach my $grade (sort(@grade)) {
488: my ($dim) = ($grade =~/[.]([^.]+)[.]status$/);
489: $result.= '<li>'.&mt("Dimension: [_1], status [_2] ",
490: $dim, $record->{$grade}).
491: '</li>';
492: }
493: $result.='</ul>';
494: return $result;
495: }
1.440 albertel 496: } elsif ( $response =~ m/(?:numerical|formula)/) {
497: $answer =
498: &Apache::loncommon::format_previous_attempt_value('submission',
499: $answer);
1.122 ng 500: }
1.118 ng 501: return $answer;
502: }
503:
504: #-- A couple of common js functions
505: sub commonJSfunctions {
506: my $request = shift;
507: $request->print(<<COMMONJSFUNCTIONS);
508: <script type="text/javascript" language="javascript">
509: function radioSelection(radioButton) {
510: var selection=null;
511: if (radioButton.length > 1) {
512: for (var i=0; i<radioButton.length; i++) {
513: if (radioButton[i].checked) {
514: return radioButton[i].value;
515: }
516: }
517: } else {
518: if (radioButton.checked) return radioButton.value;
519: }
520: return selection;
521: }
522:
523: function pullDownSelection(selectOne) {
524: var selection="";
525: if (selectOne.length > 1) {
526: for (var i=0; i<selectOne.length; i++) {
527: if (selectOne[i].selected) {
528: return selectOne[i].value;
529: }
530: }
531: } else {
1.138 albertel 532: // only one value it must be the selected one
533: return selectOne.value;
1.118 ng 534: }
535: }
536: </script>
537: COMMONJSFUNCTIONS
538: }
539:
1.44 ng 540: #--- Dumps the class list with usernames,list of sections,
541: #--- section, ids and fullnames for each user.
542: sub getclasslist {
1.449 banghart 543: my ($getsec,$filterlist,$getgroup) = @_;
1.291 albertel 544: my @getsec;
1.450 banghart 545: my @getgroup;
1.442 banghart 546: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.291 albertel 547: if (!ref($getsec)) {
548: if ($getsec ne '' && $getsec ne 'all') {
549: @getsec=($getsec);
550: }
551: } else {
552: @getsec=@{$getsec};
553: }
554: if (grep(/^all$/,@getsec)) { undef(@getsec); }
1.450 banghart 555: if (!ref($getgroup)) {
556: if ($getgroup ne '' && $getgroup ne 'all') {
557: @getgroup=($getgroup);
558: }
559: } else {
560: @getgroup=@{$getgroup};
561: }
562: if (grep(/^all$/,@getgroup)) { undef(@getgroup); }
1.291 albertel 563:
1.449 banghart 564: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
1.49 albertel 565: # Bail out if we were unable to get the classlist
1.56 matthew 566: return if (! defined($classlist));
1.449 banghart 567: &Apache::loncoursedata::get_group_memberships($classlist,$keylist);
1.56 matthew 568: #
569: my %sections;
570: my %fullnames;
1.205 matthew 571: foreach my $student (keys(%$classlist)) {
572: my $end =
573: $classlist->{$student}->[&Apache::loncoursedata::CL_END()];
574: my $start =
575: $classlist->{$student}->[&Apache::loncoursedata::CL_START()];
576: my $id =
577: $classlist->{$student}->[&Apache::loncoursedata::CL_ID()];
578: my $section =
579: $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
580: my $fullname =
581: $classlist->{$student}->[&Apache::loncoursedata::CL_FULLNAME()];
582: my $status =
583: $classlist->{$student}->[&Apache::loncoursedata::CL_STATUS()];
1.449 banghart 584: my $group =
585: $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1.76 ng 586: # filter students according to status selected
1.442 banghart 587: if ($filterlist && (!($stu_status =~ /Any/))) {
588: if (!($stu_status =~ $status)) {
1.450 banghart 589: delete($classlist->{$student});
1.76 ng 590: next;
591: }
592: }
1.450 banghart 593: # filter students according to groups selected
1.453 banghart 594: my @stu_groups = split(/,/,$group);
1.450 banghart 595: if (@getgroup) {
596: my $exclude = 1;
1.454 banghart 597: foreach my $grp (@getgroup) {
598: foreach my $stu_group (@stu_groups) {
1.453 banghart 599: if ($stu_group eq $grp) {
600: $exclude = 0;
601: }
1.450 banghart 602: }
1.453 banghart 603: if (($grp eq 'none') && !$group) {
604: $exclude = 0;
605: }
1.450 banghart 606: }
607: if ($exclude) {
608: delete($classlist->{$student});
609: }
610: }
1.205 matthew 611: $section = ($section ne '' ? $section : 'none');
1.106 albertel 612: if (&canview($section)) {
1.291 albertel 613: if (!@getsec || grep(/^\Q$section\E$/,@getsec)) {
1.103 albertel 614: $sections{$section}++;
1.450 banghart 615: if ($classlist->{$student}) {
616: $fullnames{$student}=$fullname;
617: }
1.103 albertel 618: } else {
1.205 matthew 619: delete($classlist->{$student});
1.103 albertel 620: }
621: } else {
1.205 matthew 622: delete($classlist->{$student});
1.103 albertel 623: }
1.44 ng 624: }
625: my %seen = ();
1.56 matthew 626: my @sections = sort(keys(%sections));
627: return ($classlist,\@sections,\%fullnames);
1.44 ng 628: }
629:
1.103 albertel 630: sub canmodify {
631: my ($sec)=@_;
632: if ($perm{'mgr'}) {
633: if (!defined($perm{'mgr_section'})) {
634: # can modify whole class
635: return 1;
636: } else {
637: if ($sec eq $perm{'mgr_section'}) {
638: #can modify the requested section
639: return 1;
640: } else {
641: # can't modify the request section
642: return 0;
643: }
644: }
645: }
646: #can't modify
647: return 0;
648: }
649:
650: sub canview {
651: my ($sec)=@_;
652: if ($perm{'vgr'}) {
653: if (!defined($perm{'vgr_section'})) {
654: # can modify whole class
655: return 1;
656: } else {
657: if ($sec eq $perm{'vgr_section'}) {
658: #can modify the requested section
659: return 1;
660: } else {
661: # can't modify the request section
662: return 0;
663: }
664: }
665: }
666: #can't modify
667: return 0;
668: }
669:
1.44 ng 670: #--- Retrieve the grade status of a student for all the parts
671: sub student_gradeStatus {
1.324 albertel 672: my ($symb,$udom,$uname,$partlist) = @_;
1.257 albertel 673: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.44 ng 674: my %partstatus = ();
675: foreach (@$partlist) {
1.128 ng 676: my ($status,undef) = split(/_/,$record{"resource.$_.solved"},2);
1.44 ng 677: $status = 'nothing' if ($status eq '');
678: $partstatus{$_} = $status;
679: my $subkey = "resource.$_.submitted_by";
680: $partstatus{$subkey} = $record{$subkey} if ($record{$subkey} ne '');
681: }
682: return %partstatus;
683: }
684:
1.45 ng 685: # hidden form and javascript that calls the form
686: # Use by verifyscript and viewgrades
687: # Shows a student's view of problem and submission
688: sub jscriptNform {
1.324 albertel 689: my ($symb) = @_;
1.442 banghart 690: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.45 ng 691: my $jscript='<script type="text/javascript" language="javascript">'."\n".
692: ' function viewOneStudent(user,domain) {'."\n".
693: ' document.onestudent.student.value = user;'."\n".
694: ' document.onestudent.userdom.value = domain;'."\n".
695: ' document.onestudent.submit();'."\n".
696: ' }'."\n".
697: '</script>'."\n";
698: $jscript.= '<form action="/adm/grades" method="post" name="onestudent">'."\n".
1.418 albertel 699: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 700: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
701: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.442 banghart 702: '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.45 ng 703: '<input type="hidden" name="command" value="submission" />'."\n".
704: '<input type="hidden" name="student" value="" />'."\n".
705: '<input type="hidden" name="userdom" value="" />'."\n".
706: '</form>'."\n";
707: return $jscript;
708: }
1.39 ng 709:
1.447 foxr 710:
711:
1.315 bowersj2 712: # Given the score (as a number [0-1] and the weight) what is the final
713: # point value? This function will round to the nearest tenth, third,
714: # or quarter if one of those is within the tolerance of .00001.
1.316 albertel 715: sub compute_points {
1.315 bowersj2 716: my ($score, $weight) = @_;
717:
718: my $tolerance = .00001;
719: my $points = $score * $weight;
720:
721: # Check for nearness to 1/x.
722: my $check_for_nearness = sub {
723: my ($factor) = @_;
724: my $num = ($points * $factor) + $tolerance;
725: my $floored_num = floor($num);
1.316 albertel 726: if ($num - $floored_num < 2 * $tolerance * $factor) {
1.315 bowersj2 727: return $floored_num / $factor;
728: }
729: return $points;
730: };
731:
732: $points = $check_for_nearness->(10);
733: $points = $check_for_nearness->(3);
734: $points = $check_for_nearness->(4);
735:
736: return $points;
737: }
738:
1.44 ng 739: #------------------ End of general use routines --------------------
1.87 www 740:
741: #
742: # Find most similar essay
743: #
744:
745: sub most_similar {
1.426 albertel 746: my ($uname,$udom,$uessay,$old_essays)=@_;
1.87 www 747:
748: # ignore spaces and punctuation
749:
750: $uessay=~s/\W+/ /gs;
751:
1.282 www 752: # ignore empty submissions (occuring when only files are sent)
753:
1.596.2.4 raeburn 754: unless ($uessay=~/\w+/s) { return ''; }
1.282 www 755:
1.87 www 756: # these will be returned. Do not care if not at least 50 percent similar
1.88 www 757: my $limit=0.6;
1.87 www 758: my $sname='';
759: my $sdom='';
760: my $scrsid='';
761: my $sessay='';
762: # go through all essays ...
1.426 albertel 763: foreach my $tkey (keys(%$old_essays)) {
764: my ($tname,$tdom,$tcrsid)=map {&unescape($_)} (split(/\./,$tkey));
1.87 www 765: # ... except the same student
1.426 albertel 766: next if (($tname eq $uname) && ($tdom eq $udom));
767: my $tessay=$old_essays->{$tkey};
768: $tessay=~s/\W+/ /gs;
1.87 www 769: # String similarity gives up if not even limit
1.426 albertel 770: my $tsimilar=&String::Similarity::similarity($uessay,$tessay,$limit);
1.87 www 771: # Found one
1.426 albertel 772: if ($tsimilar>$limit) {
773: $limit=$tsimilar;
774: $sname=$tname;
775: $sdom=$tdom;
776: $scrsid=$tcrsid;
777: $sessay=$old_essays->{$tkey};
778: }
1.87 www 779: }
1.88 www 780: if ($limit>0.6) {
1.87 www 781: return ($sname,$sdom,$scrsid,$sessay,$limit);
782: } else {
783: return ('','','','',0);
784: }
785: }
786:
1.44 ng 787: #-------------------------------------------------------------------
788:
789: #------------------------------------ Receipt Verification Routines
1.45 ng 790: #
1.44 ng 791: #--- Check whether a receipt number is valid.---
792: sub verifyreceipt {
793: my $request = shift;
794:
1.257 albertel 795: my $courseid = $env{'request.course.id'};
1.184 www 796: my $receipt = &Apache::lonnet::recprefix($courseid).'-'.
1.257 albertel 797: $env{'form.receipt'};
1.44 ng 798: $receipt =~ s/[^\-\d]//g;
1.378 albertel 799: my ($symb) = &get_symb($request);
1.44 ng 800:
1.487 albertel 801: my $title.=
802: '<h3><span class="LC_info">'.
1.584 bisitz 803: &mt('Verifying Receipt No. [_1]',$receipt).
1.487 albertel 804: '</span></h3>'."\n".
805: '<h4>'.&mt('<b>Resource: </b>[_1]',$env{'form.probTitle'}).
806: '</h4>'."\n";
1.44 ng 807:
808: my ($string,$contents,$matches) = ('','',0);
1.56 matthew 809: my (undef,undef,$fullname) = &getclasslist('all','0');
1.177 albertel 810:
811: my $receiptparts=0;
1.390 albertel 812: if ($env{"course.$courseid.receiptalg"} eq 'receipt2' ||
813: $env{"course.$courseid.receiptalg"} eq 'receipt3') { $receiptparts=1; }
1.177 albertel 814: my $parts=['0'];
1.582 raeburn 815: if ($receiptparts) {
816: my $res_error;
817: ($parts)=&response_type($symb,\$res_error);
818: if ($res_error) {
819: return &navmap_errormsg();
820: }
821: }
1.486 albertel 822:
823: my $header =
824: &Apache::loncommon::start_data_table().
825: &Apache::loncommon::start_data_table_header_row().
1.487 albertel 826: '<th> '.&mt('Fullname').' </th>'."\n".
827: '<th> '.&mt('Username').' </th>'."\n".
828: '<th> '.&mt('Domain').' </th>';
1.486 albertel 829: if ($receiptparts) {
1.487 albertel 830: $header.='<th> '.&mt('Problem Part').' </th>';
1.486 albertel 831: }
832: $header.=
833: &Apache::loncommon::end_data_table_header_row();
834:
1.294 albertel 835: foreach (sort
836: {
837: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
838: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
839: }
840: return $a cmp $b;
841: } (keys(%$fullname))) {
1.44 ng 842: my ($uname,$udom)=split(/\:/);
1.177 albertel 843: foreach my $part (@$parts) {
844: if ($receipt eq &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb,$part)) {
1.486 albertel 845: $contents.=
846: &Apache::loncommon::start_data_table_row().
847: '<td> '."\n".
1.177 albertel 848: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 849: '\');" target="_self">'.$$fullname{$_}.'</a> </td>'."\n".
1.177 albertel 850: '<td> '.$uname.' </td>'.
851: '<td> '.$udom.' </td>';
852: if ($receiptparts) {
853: $contents.='<td> '.$part.' </td>';
854: }
1.486 albertel 855: $contents.=
856: &Apache::loncommon::end_data_table_row()."\n";
1.177 albertel 857:
858: $matches++;
859: }
1.44 ng 860: }
861: }
862: if ($matches == 0) {
1.584 bisitz 863: $string = $title
864: .'<p class="LC_warning">'
865: .&mt('No match found for the above receipt number.')
866: .'</p>';
1.44 ng 867: } else {
1.324 albertel 868: $string = &jscriptNform($symb).$title.
1.487 albertel 869: '<p>'.
1.584 bisitz 870: &mt('The above receipt number matches the following [quant,_1,student].',$matches).
1.487 albertel 871: '</p>'.
1.486 albertel 872: $header.
873: $contents.
874: &Apache::loncommon::end_data_table()."\n";
1.44 ng 875: }
1.324 albertel 876: return $string.&show_grading_menu_form($symb);
1.44 ng 877: }
878:
879: #--- This is called by a number of programs.
880: #--- Called from the Grading Menu - View/Grade an individual student
881: #--- Also called directly when one clicks on the subm button
882: # on the problem page.
1.30 ng 883: sub listStudents {
1.41 ng 884: my ($request) = shift;
1.49 albertel 885:
1.324 albertel 886: my ($symb) = &get_symb($request);
1.257 albertel 887: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
888: my $cnum = $env{"course.$env{'request.course.id'}.num"};
889: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.449 banghart 890: my $getgroup = $env{'form.group'} eq '' ? 'all' : $env{'form.group'};
1.257 albertel 891: my $submitonly= $env{'form.submitonly'} eq '' ? 'all' : $env{'form.submitonly'};
1.548 bisitz 892: my $viewgrade = $env{'form.showgrading'} eq 'yes' ? 'View/Grade/Regrade' : 'View';
1.257 albertel 893: $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
894: &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
1.49 albertel 895:
1.548 bisitz 896: my $result='<h3><span class="LC_info"> '
897: .&mt("$viewgrade Submissions for a Student or a Group of Students")
1.485 albertel 898: .'</span></h3>';
1.118 ng 899:
1.324 albertel 900: my ($table,undef,$hdgrade,$partlist,$handgrade) = &showResourceInfo($symb,$env{'form.probTitle'},($env{'form.showgrading'} eq 'yes'));
1.49 albertel 901:
1.559 raeburn 902: my %lt = &Apache::lonlocal::texthash (
903: 'multiple' => 'Please select a student or group of students before clicking on the Next button.',
904: 'single' => 'Please select the student before clicking on the Next button.',
905: );
1.45 ng 906: $request->print(<<LISTJAVASCRIPT);
907: <script type="text/javascript" language="javascript">
1.110 ng 908: function checkSelect(checkBox) {
909: var ctr=0;
910: var sense="";
911: if (checkBox.length > 1) {
912: for (var i=0; i<checkBox.length; i++) {
913: if (checkBox[i].checked) {
914: ctr++;
915: }
916: }
1.485 albertel 917: sense = '$lt{'multiple'}';
1.110 ng 918: } else {
919: if (checkBox.checked) {
920: ctr = 1;
921: }
1.485 albertel 922: sense = '$lt{'single'}';
1.110 ng 923: }
924: if (ctr == 0) {
1.485 albertel 925: alert(sense);
1.110 ng 926: return false;
927: }
928: document.gradesub.submit();
929: }
930:
931: function reLoadList(formname) {
1.112 ng 932: if (formname.saveStatusOld.value == pullDownSelection(formname.Status)) {return;}
1.110 ng 933: formname.command.value = 'submission';
934: formname.submit();
935: }
1.45 ng 936: </script>
937: LISTJAVASCRIPT
938:
1.118 ng 939: &commonJSfunctions($request);
1.41 ng 940: $request->print($result);
1.39 ng 941:
1.401 albertel 942: my $checkhdgrade = ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1 ) ? 'checked="checked"' : '';
943: my $checklastsub = $checkhdgrade eq '' ? 'checked="checked"' : '';
1.154 albertel 944: my $gradeTable='<form action="/adm/grades" method="post" name="gradesub">'.
1.485 albertel 945: "\n".$table;
946:
1.561 bisitz 947: $gradeTable .= &Apache::lonhtmlcommon::start_pick_box();
948: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Problem Text'))
949: .'<label><input type="radio" name="vProb" value="no" checked="checked" /> '.&mt('no').' </label>'."\n"
950: .'<label><input type="radio" name="vProb" value="yes" /> '.&mt('one student').' </label>'."\n"
951: .'<label><input type="radio" name="vProb" value="all" /> '.&mt('all students').' </label><br />'."\n"
952: .&Apache::lonhtmlcommon::row_closure();
953: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Answer'))
954: .'<label><input type="radio" name="vAns" value="no" /> '.&mt('no').' </label>'."\n"
955: .'<label><input type="radio" name="vAns" value="yes" /> '.&mt('one student').' </label>'."\n"
956: .'<label><input type="radio" name="vAns" value="all" checked="checked" /> '.&mt('all students').' </label><br />'."\n"
957: .&Apache::lonhtmlcommon::row_closure();
1.485 albertel 958:
959: my $submission_options;
1.257 albertel 960: if ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1) {
1.485 albertel 961: $submission_options.=
962: '<label><input type="radio" name="lastSub" value="hdgrade" '.$checkhdgrade.' /> '.&mt('essay part only').' </label>'."\n";
1.49 albertel 963: }
1.442 banghart 964: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
965: my $saveStatus = $stu_status eq '' ? 'Active' : $stu_status;
1.257 albertel 966: $env{'form.Status'} = $saveStatus;
1.485 albertel 967: $submission_options.=
1.592 bisitz 968: '<span class="LC_nobreak">'.
969: '<label><input type="radio" name="lastSub" value="lastonly" '.$checklastsub.' /> '.
970: &mt('last submission only').' </label></span>'."\n".
971: '<span class="LC_nobreak">'.
972: '<label><input type="radio" name="lastSub" value="last" /> '.
973: &mt('last submission & parts info').' </label></span>'."\n".
974: '<span class="LC_nobreak">'.
975: '<label><input type="radio" name="lastSub" value="datesub" /> '.
976: &mt('by dates and submissions').'</label></span>'."\n".
977: '<span class="LC_nobreak">'.
978: '<label><input type="radio" name="lastSub" value="all" /> '.
979: &mt('all details').'</label></span>';
1.561 bisitz 980: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Submissions'))
981: .$submission_options
982: .&Apache::lonhtmlcommon::row_closure();
983:
984: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Grading Increments'))
985: .'<select name="increment">'
986: .'<option value="1">'.&mt('Whole Points').'</option>'
987: .'<option value=".5">'.&mt('Half Points').'</option>'
988: .'<option value=".25">'.&mt('Quarter Points').'</option>'
989: .'<option value=".1">'.&mt('Tenths of a Point').'</option>'
990: .'</select>'
991: .&Apache::lonhtmlcommon::row_closure();
1.485 albertel 992:
993: $gradeTable .=
1.432 banghart 994: &build_section_inputs().
1.45 ng 995: '<input type="hidden" name="submitonly" value="'.$submitonly.'" />'."\n".
1.257 albertel 996: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" /><br />'."\n".
997: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" /><br />'."\n".
998: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
999: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.418 albertel 1000: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.110 ng 1001: '<input type="hidden" name="saveStatusOld" value="'.$saveStatus.'" />'."\n";
1002:
1.257 albertel 1003: if (exists($env{'form.gradingMenu'}) && exists($env{'form.Status'})) {
1.561 bisitz 1004: $gradeTable .= '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n";
1.124 ng 1005: } else {
1.561 bisitz 1006: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Student Status'))
1007: .&Apache::lonhtmlcommon::StatusOptions(
1008: $saveStatus,undef,1,'javascript:reLoadList(this.form);')
1009: .&Apache::lonhtmlcommon::row_closure();
1.124 ng 1010: }
1.112 ng 1011:
1.561 bisitz 1012: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Check For Plagiarism'))
1013: .'<input type="checkbox" name="checkPlag" checked="checked" />'
1014: .&Apache::lonhtmlcommon::row_closure(1)
1015: .&Apache::lonhtmlcommon::end_pick_box();
1016:
1017: $gradeTable .= '<p>'
1018: .&mt('To '.lc($viewgrade)." a submission or a group of submissions, click on the check box(es) next to the student's name(s). Then click on the Next button.")."\n"
1019: .'<input type="hidden" name="command" value="processGroup" />'
1020: .'</p>';
1.249 albertel 1021:
1022: # checkall buttons
1023: $gradeTable.=&check_script('gradesub', 'stuinfo');
1.110 ng 1024: $gradeTable.='<input type="button" '."\n".
1.589 bisitz 1025: 'onclick="javascript:checkSelect(this.form.stuinfo);" '."\n".
1026: 'value="'.&mt('Next').' →" /> <br />'."\n";
1.249 albertel 1027: $gradeTable.=&check_buttons();
1.450 banghart 1028: my ($classlist, undef, $fullname) = &getclasslist($getsec,'1',$getgroup);
1.474 albertel 1029: $gradeTable.= &Apache::loncommon::start_data_table().
1030: &Apache::loncommon::start_data_table_header_row();
1.110 ng 1031: my $loop = 0;
1032: while ($loop < 2) {
1.485 albertel 1033: $gradeTable.='<th>'.&mt('No.').'</th><th>'.&mt('Select').'</th>'.
1034: '<th>'.&nameUserString('header').' '.&mt('Section/Group').'</th>';
1.301 albertel 1035: if ($env{'form.showgrading'} eq 'yes'
1036: && $submitonly ne 'queued'
1037: && $submitonly ne 'all') {
1.485 albertel 1038: foreach my $part (sort(@$partlist)) {
1039: my $display_part=
1040: &get_display_part((split(/_/,$part))[0],$symb);
1041: $gradeTable.=
1042: '<th>'.&mt('Part: [_1] Status',$display_part).'</th>';
1.110 ng 1043: }
1.301 albertel 1044: } elsif ($submitonly eq 'queued') {
1.474 albertel 1045: $gradeTable.='<th>'.&mt('Queue Status').' </th>';
1.110 ng 1046: }
1047: $loop++;
1.126 ng 1048: # $gradeTable.='<td></td>' if ($loop%2 ==1);
1.41 ng 1049: }
1.474 albertel 1050: $gradeTable.=&Apache::loncommon::end_data_table_header_row()."\n";
1.41 ng 1051:
1.45 ng 1052: my $ctr = 0;
1.294 albertel 1053: foreach my $student (sort
1054: {
1055: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
1056: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
1057: }
1058: return $a cmp $b;
1059: }
1060: (keys(%$fullname))) {
1.41 ng 1061: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 1062:
1.110 ng 1063: my %status = ();
1.301 albertel 1064:
1065: if ($submitonly eq 'queued') {
1066: my %queue_status =
1067: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
1068: $udom,$uname);
1069: next if (!defined($queue_status{'gradingqueue'}));
1070: $status{'gradingqueue'} = $queue_status{'gradingqueue'};
1071: }
1072:
1073: if ($env{'form.showgrading'} eq 'yes'
1074: && $submitonly ne 'queued'
1075: && $submitonly ne 'all') {
1.324 albertel 1076: (%status) =&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 1077: my $submitted = 0;
1.164 albertel 1078: my $graded = 0;
1.248 albertel 1079: my $incorrect = 0;
1.110 ng 1080: foreach (keys(%status)) {
1.145 albertel 1081: $submitted = 1 if ($status{$_} ne 'nothing');
1.248 albertel 1082: $graded = 1 if ($status{$_} =~ /^ungraded/);
1083: $incorrect = 1 if ($status{$_} =~ /^incorrect/);
1084:
1.110 ng 1085: my ($foo,$partid,$foo1) = split(/\./,$_);
1086: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
1.145 albertel 1087: $submitted = 0;
1.150 albertel 1088: my ($part)=split(/\./,$partid);
1.110 ng 1089: $gradeTable.='<input type="hidden" name="'.
1.150 albertel 1090: $student.':'.$part.':submitted_by" value="'.
1.110 ng 1091: $status{'resource.'.$partid.'.submitted_by'}.'" />';
1092: }
1.41 ng 1093: }
1.248 albertel 1094:
1.156 albertel 1095: next if (!$submitted && ($submitonly eq 'yes' ||
1096: $submitonly eq 'incorrect' ||
1097: $submitonly eq 'graded'));
1.248 albertel 1098: next if (!$graded && ($submitonly eq 'graded'));
1099: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 1100: }
1.34 ng 1101:
1.45 ng 1102: $ctr++;
1.249 albertel 1103: my $section = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
1.452 banghart 1104: my $group = $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1.104 albertel 1105: if ( $perm{'vgr'} eq 'F' ) {
1.474 albertel 1106: if ($ctr%2 ==1) {
1107: $gradeTable.= &Apache::loncommon::start_data_table_row();
1108: }
1.126 ng 1109: $gradeTable.='<td align="right">'.$ctr.' </td>'.
1.563 bisitz 1110: '<td align="center"><label><input type="checkbox" name="stuinfo" value="'.
1.249 albertel 1111: $student.':'.$$fullname{$student}.':::SECTION'.$section.
1112: ') " /> </label></td>'."\n".'<td>'.
1113: &nameUserString(undef,$$fullname{$student},$uname,$udom).
1.474 albertel 1114: ' '.$section.($group ne '' ?'/'.$group:'').'</td>'."\n";
1.110 ng 1115:
1.257 albertel 1116: if ($env{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
1.524 raeburn 1117: foreach (sort(keys(%status))) {
1.485 albertel 1118: next if ($_ =~ /^resource.*?submitted_by$/);
1119: $gradeTable.='<td align="center"> '.&mt($status{$_}).' </td>'."\n";
1.110 ng 1120: }
1.41 ng 1121: }
1.126 ng 1122: # $gradeTable.='<td></td>' if ($ctr%2 ==1);
1.474 albertel 1123: if ($ctr%2 ==0) {
1124: $gradeTable.=&Apache::loncommon::end_data_table_row()."\n";
1125: }
1.41 ng 1126: }
1127: }
1.110 ng 1128: if ($ctr%2 ==1) {
1.126 ng 1129: $gradeTable.='<td> </td><td> </td><td> </td>';
1.301 albertel 1130: if ($env{'form.showgrading'} eq 'yes'
1131: && $submitonly ne 'queued'
1132: && $submitonly ne 'all') {
1.110 ng 1133: foreach (@$partlist) {
1134: $gradeTable.='<td> </td>';
1135: }
1.301 albertel 1136: } elsif ($submitonly eq 'queued') {
1137: $gradeTable.='<td> </td>';
1.110 ng 1138: }
1.474 albertel 1139: $gradeTable.=&Apache::loncommon::end_data_table_row();
1.110 ng 1140: }
1141:
1.474 albertel 1142: $gradeTable.=&Apache::loncommon::end_data_table()."\n".
1.589 bisitz 1143: '<input type="button" '.
1144: 'onclick="javascript:checkSelect(this.form.stuinfo);" '.
1145: 'value="'.&mt('Next').' →" /></form>'."\n";
1.45 ng 1146: if ($ctr == 0) {
1.96 albertel 1147: my $num_students=(scalar(keys(%$fullname)));
1148: if ($num_students eq 0) {
1.485 albertel 1149: $gradeTable='<br /> <span class="LC_warning">'.&mt('There are no students currently enrolled.').'</span>';
1.96 albertel 1150: } else {
1.171 albertel 1151: my $submissions='submissions';
1152: if ($submitonly eq 'incorrect') { $submissions = 'incorrect submissions'; }
1153: if ($submitonly eq 'graded' ) { $submissions = 'ungraded submissions'; }
1.301 albertel 1154: if ($submitonly eq 'queued' ) { $submissions = 'queued submissions'; }
1.398 albertel 1155: $gradeTable='<br /> <span class="LC_warning">'.
1.485 albertel 1156: &mt('No '.$submissions.' found for this resource for any students. ([_1] students checked for '.$submissions.')',
1157: $num_students).
1158: '</span><br />';
1.96 albertel 1159: }
1.46 ng 1160: } elsif ($ctr == 1) {
1.474 albertel 1161: $gradeTable =~ s/type="checkbox"/type="checkbox" checked="checked"/;
1.45 ng 1162: }
1.324 albertel 1163: $gradeTable.=&show_grading_menu_form($symb);
1.45 ng 1164: $request->print($gradeTable);
1.44 ng 1165: return '';
1.10 ng 1166: }
1167:
1.44 ng 1168: #---- Called from the listStudents routine
1.249 albertel 1169:
1170: sub check_script {
1171: my ($form, $type)=@_;
1172: my $chkallscript='<script type="text/javascript">
1173: function checkall() {
1174: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1175: ele = document.forms.'.$form.'.elements[i];
1176: if (ele.name == "'.$type.'") {
1177: document.forms.'.$form.'.elements[i].checked=true;
1178: }
1179: }
1180: }
1181:
1182: function checksec() {
1183: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1184: ele = document.forms.'.$form.'.elements[i];
1185: string = document.forms.'.$form.'.chksec.value;
1186: if
1187: (ele.value.indexOf(":::SECTION"+string)>0) {
1188: document.forms.'.$form.'.elements[i].checked=true;
1189: }
1190: }
1191: }
1192:
1193:
1194: function uncheckall() {
1195: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1196: ele = document.forms.'.$form.'.elements[i];
1197: if (ele.name == "'.$type.'") {
1198: document.forms.'.$form.'.elements[i].checked=false;
1199: }
1200: }
1201: }
1202:
1203: </script>'."\n";
1204: return $chkallscript;
1205: }
1206:
1207: sub check_buttons {
1.485 albertel 1208: my $buttons.='<input type="button" onclick="checkall()" value="'.&mt('Check All').'" />';
1209: $buttons.='<input type="button" onclick="uncheckall()" value="'.&mt('Uncheck All').'" /> ';
1210: $buttons.='<input type="button" onclick="checksec()" value="'.&mt('Check Section/Group').'" />';
1.249 albertel 1211: $buttons.='<input type="text" size="5" name="chksec" /> ';
1212: return $buttons;
1213: }
1214:
1.44 ng 1215: # Displays the submissions for one student or a group of students
1.34 ng 1216: sub processGroup {
1.41 ng 1217: my ($request) = shift;
1218: my $ctr = 0;
1.155 albertel 1219: my @stuchecked = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.41 ng 1220: my $total = scalar(@stuchecked)-1;
1.45 ng 1221:
1.396 banghart 1222: foreach my $student (@stuchecked) {
1223: my ($uname,$udom,$fullname) = split(/:/,$student);
1.257 albertel 1224: $env{'form.student'} = $uname;
1225: $env{'form.userdom'} = $udom;
1226: $env{'form.fullname'} = $fullname;
1.41 ng 1227: &submission($request,$ctr,$total);
1228: $ctr++;
1229: }
1230: return '';
1.35 ng 1231: }
1.34 ng 1232:
1.44 ng 1233: #------------------------------------------------------------------------------------
1234: #
1235: #-------------------------- Next few routines handles grading by student, essentially
1236: # handles essay response type problem/part
1237: #
1238: #--- Javascript to handle the submission page functionality ---
1239: sub sub_page_js {
1240: my $request = shift;
1.539 riegler 1241: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
1.44 ng 1242: $request->print(<<SUBJAVASCRIPT);
1243: <script type="text/javascript" language="javascript">
1.71 ng 1244: function updateRadio(formname,id,weight) {
1.125 ng 1245: var gradeBox = formname["GD_BOX"+id];
1246: var radioButton = formname["RADVAL"+id];
1247: var oldpts = formname["oldpts"+id].value;
1.72 ng 1248: var pts = checkSolved(formname,id) == 'update' ? gradeBox.value : oldpts;
1.71 ng 1249: gradeBox.value = pts;
1250: var resetbox = false;
1251: if (isNaN(pts) || pts < 0) {
1.539 riegler 1252: alert("$alertmsg"+pts);
1.71 ng 1253: for (var i=0; i<radioButton.length; i++) {
1254: if (radioButton[i].checked) {
1255: gradeBox.value = i;
1256: resetbox = true;
1257: }
1258: }
1259: if (!resetbox) {
1260: formtextbox.value = "";
1261: }
1262: return;
1.44 ng 1263: }
1.71 ng 1264:
1265: if (pts > weight) {
1266: var resp = confirm("You entered a value ("+pts+
1267: ") greater than the weight for the part. Accept?");
1268: if (resp == false) {
1.125 ng 1269: gradeBox.value = oldpts;
1.71 ng 1270: return;
1271: }
1.44 ng 1272: }
1.13 albertel 1273:
1.71 ng 1274: for (var i=0; i<radioButton.length; i++) {
1275: radioButton[i].checked=false;
1276: if (pts == i && pts != "") {
1277: radioButton[i].checked=true;
1278: }
1279: }
1280: updateSelect(formname,id);
1.125 ng 1281: formname["stores"+id].value = "0";
1.41 ng 1282: }
1.5 albertel 1283:
1.72 ng 1284: function writeBox(formname,id,pts) {
1.125 ng 1285: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1286: if (checkSolved(formname,id) == 'update') {
1287: gradeBox.value = pts;
1288: } else {
1.125 ng 1289: var oldpts = formname["oldpts"+id].value;
1.72 ng 1290: gradeBox.value = oldpts;
1.125 ng 1291: var radioButton = formname["RADVAL"+id];
1.71 ng 1292: for (var i=0; i<radioButton.length; i++) {
1293: radioButton[i].checked=false;
1.72 ng 1294: if (i == oldpts) {
1.71 ng 1295: radioButton[i].checked=true;
1296: }
1297: }
1.41 ng 1298: }
1.125 ng 1299: formname["stores"+id].value = "0";
1.71 ng 1300: updateSelect(formname,id);
1301: return;
1.41 ng 1302: }
1.44 ng 1303:
1.71 ng 1304: function clearRadBox(formname,id) {
1305: if (checkSolved(formname,id) == 'noupdate') {
1306: updateSelect(formname,id);
1307: return;
1308: }
1.125 ng 1309: gradeSelect = formname["GD_SEL"+id];
1.71 ng 1310: for (var i=0; i<gradeSelect.length; i++) {
1311: if (gradeSelect[i].selected) {
1312: var selectx=i;
1313: }
1314: }
1.125 ng 1315: var stores = formname["stores"+id];
1.71 ng 1316: if (selectx == stores.value) { return };
1.125 ng 1317: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1318: gradeBox.value = "";
1.125 ng 1319: var radioButton = formname["RADVAL"+id];
1.71 ng 1320: for (var i=0; i<radioButton.length; i++) {
1321: radioButton[i].checked=false;
1322: }
1323: stores.value = selectx;
1324: }
1.5 albertel 1325:
1.71 ng 1326: function checkSolved(formname,id) {
1.125 ng 1327: if (formname["solved"+id].value == "correct_by_student" && formname.overRideScore.value == 'no') {
1.118 ng 1328: var reply = confirm("This problem has been graded correct by the computer. Do you want to change the score?");
1329: if (!reply) {return "noupdate";}
1.120 ng 1330: formname.overRideScore.value = 'yes';
1.41 ng 1331: }
1.71 ng 1332: return "update";
1.13 albertel 1333: }
1.71 ng 1334:
1335: function updateSelect(formname,id) {
1.125 ng 1336: formname["GD_SEL"+id][0].selected = true;
1.71 ng 1337: return;
1.41 ng 1338: }
1.33 ng 1339:
1.121 ng 1340: //=========== Check that a point is assigned for all the parts ============
1.71 ng 1341: function checksubmit(formname,val,total,parttot) {
1.121 ng 1342: formname.gradeOpt.value = val;
1.71 ng 1343: if (val == "Save & Next") {
1344: for (i=0;i<=total;i++) {
1345: for (j=0;j<parttot;j++) {
1.125 ng 1346: var partid = formname["partid"+i+"_"+j].value;
1.127 ng 1347: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1348: var points = formname["GD_BOX"+i+"_"+partid].value;
1.71 ng 1349: if (points == "") {
1.125 ng 1350: var name = formname["name"+i].value;
1.129 ng 1351: var studentID = (name != '' ? name : formname["unamedom"+i].value);
1352: var resp = confirm("You did not assign a score for "+studentID+
1353: ", part "+partid+". Continue?");
1.71 ng 1354: if (resp == false) {
1.125 ng 1355: formname["GD_BOX"+i+"_"+partid].focus();
1.71 ng 1356: return false;
1357: }
1358: }
1359: }
1360:
1361: }
1362: }
1363:
1364: }
1.121 ng 1365: if (val == "Grade Student") {
1366: formname.showgrading.value = "yes";
1367: if (formname.Status.value == "") {
1368: formname.Status.value = "Active";
1369: }
1370: formname.studentNo.value = total;
1371: }
1.120 ng 1372: formname.submit();
1373: }
1374:
1.71 ng 1375: //======= Check that a score is assigned for all the problems (page/sequence grading only) =========
1376: function checkSubmitPage(formname,total) {
1377: noscore = new Array(100);
1378: var ptr = 0;
1379: for (i=1;i<total;i++) {
1.125 ng 1380: var partid = formname["q_"+i].value;
1.127 ng 1381: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1382: var points = formname["GD_BOX"+i+"_"+partid].value;
1383: var status = formname["solved"+i+"_"+partid].value;
1.71 ng 1384: if (points == "" && status != "correct_by_student") {
1385: noscore[ptr] = i;
1386: ptr++;
1387: }
1388: }
1389: }
1390: if (ptr != 0) {
1391: var sense = ptr == 1 ? ": " : "s: ";
1392: var prolist = "";
1393: if (ptr == 1) {
1394: prolist = noscore[0];
1395: } else {
1396: var i = 0;
1397: while (i < ptr-1) {
1398: prolist += noscore[i]+", ";
1399: i++;
1400: }
1401: prolist += "and "+noscore[i];
1402: }
1403: var resp = confirm("You did not assign any score for the following problem"+sense+prolist+". Continue?");
1404: if (resp == false) {
1405: return false;
1406: }
1407: }
1.45 ng 1408:
1.71 ng 1409: formname.submit();
1410: }
1411: </script>
1412: SUBJAVASCRIPT
1413: }
1.45 ng 1414:
1.71 ng 1415: #--- javascript for essay type problem --
1416: sub sub_page_kw_js {
1417: my $request = shift;
1.80 ng 1418: my $iconpath = $request->dir_config('lonIconsURL');
1.118 ng 1419: &commonJSfunctions($request);
1.350 albertel 1420:
1.351 albertel 1421: my $inner_js_msg_central=<<INNERJS;
1.350 albertel 1422: <script text="text/javascript">
1423: function checkInput() {
1424: opener.document.SCORE.msgsub.value = opener.checkEntities(document.msgcenter.msgsub.value);
1425: var nmsg = opener.document.SCORE.savemsgN.value;
1426: var usrctr = document.msgcenter.usrctr.value;
1427: var newval = opener.document.SCORE["newmsg"+usrctr];
1428: newval.value = opener.checkEntities(document.msgcenter.newmsg.value);
1429:
1430: var msgchk = "";
1431: if (document.msgcenter.subchk.checked) {
1432: msgchk = "msgsub,";
1433: }
1434: var includemsg = 0;
1435: for (var i=1; i<=nmsg; i++) {
1436: var opnmsg = opener.document.SCORE["savemsg"+i];
1437: var frmmsg = document.msgcenter["msg"+i];
1438: opnmsg.value = opener.checkEntities(frmmsg.value);
1439: var showflg = opener.document.SCORE["shownOnce"+i];
1440: showflg.value = "1";
1441: var chkbox = document.msgcenter["msgn"+i];
1442: if (chkbox.checked) {
1443: msgchk += "savemsg"+i+",";
1444: includemsg = 1;
1445: }
1446: }
1447: if (document.msgcenter.newmsgchk.checked) {
1448: msgchk += "newmsg"+usrctr;
1449: includemsg = 1;
1450: }
1451: imgformname = opener.document.SCORE["mailicon"+usrctr];
1452: imgformname.src = "$iconpath/"+((includemsg) ? "mailto.gif" : "mailbkgrd.gif");
1453: var includemsg = opener.document.SCORE["includemsg"+usrctr];
1454: includemsg.value = msgchk;
1455:
1456: self.close()
1457:
1458: }
1459: </script>
1460: INNERJS
1461:
1.351 albertel 1462: my $inner_js_highlight_central=<<INNERJS;
1463: <script type="text/javascript">
1464: function updateChoice(flag) {
1465: opener.document.SCORE.kwclr.value = opener.radioSelection(document.hlCenter.kwdclr);
1466: opener.document.SCORE.kwsize.value = opener.radioSelection(document.hlCenter.kwdsize);
1467: opener.document.SCORE.kwstyle.value = opener.radioSelection(document.hlCenter.kwdstyle);
1468: opener.document.SCORE.refresh.value = "on";
1469: if (opener.document.SCORE.keywords.value!=""){
1470: opener.document.SCORE.submit();
1471: }
1472: self.close()
1473: }
1474: </script>
1475: INNERJS
1476:
1477: my $start_page_msg_central =
1478: &Apache::loncommon::start_page('Message Central',$inner_js_msg_central,
1479: {'js_ready' => 1,
1480: 'only_body' => 1,
1481: 'bgcolor' =>'#FFFFFF',});
1482: my $end_page_msg_central =
1483: &Apache::loncommon::end_page({'js_ready' => 1});
1484:
1485:
1486: my $start_page_highlight_central =
1487: &Apache::loncommon::start_page('Highlight Central',
1488: $inner_js_highlight_central,
1.350 albertel 1489: {'js_ready' => 1,
1490: 'only_body' => 1,
1491: 'bgcolor' =>'#FFFFFF',});
1.351 albertel 1492: my $end_page_highlight_central =
1.350 albertel 1493: &Apache::loncommon::end_page({'js_ready' => 1});
1494:
1.219 www 1495: my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
1.236 albertel 1496: $docopen=~s/^document\.//;
1.596.2.4 raeburn 1497: my %lt = &Apache::lonlocal::texthash(
1498: keyw => 'Keywords list, separated by a space. Add/delete to list if desired.',
1499: plse => 'Please select a word or group of words from document and then click this link.',
1500: adds => 'Add selection to keyword list? Edit if desired.',
1501: comp => 'Compose Message for: ',
1502: incl => 'Include',
1503: type => 'Type',
1504: subj => 'Subject',
1505: mesa => 'Message',
1506: new => 'New',
1507: save => 'Save',
1508: canc => 'Cancel',
1509: kehi => 'Keyword Highlight Options',
1510: txtc => 'Text Color',
1511: font => 'Font Size',
1512: fnst => 'Font Style',
1513: );
1.71 ng 1514: $request->print(<<SUBJAVASCRIPT);
1515: <script type="text/javascript" language="javascript">
1.45 ng 1516:
1.44 ng 1517: //===================== Show list of keywords ====================
1.122 ng 1518: function keywords(formname) {
1.596.2.4 raeburn 1519: var nret = prompt("$lt{'keyw'}",formname.keywords.value);
1.44 ng 1520: if (nret==null) return;
1.122 ng 1521: formname.keywords.value = nret;
1.44 ng 1522:
1.122 ng 1523: if (formname.keywords.value != "") {
1.128 ng 1524: formname.refresh.value = "on";
1.122 ng 1525: formname.submit();
1.44 ng 1526: }
1527: return;
1528: }
1529:
1530: //===================== Script to view submitted by ==================
1531: function viewSubmitter(submitter) {
1532: document.SCORE.refresh.value = "on";
1533: document.SCORE.NCT.value = "1";
1534: document.SCORE.unamedom0.value = submitter;
1535: document.SCORE.submit();
1536: return;
1537: }
1538:
1539: //===================== Script to add keyword(s) ==================
1540: function getSel() {
1541: if (document.getSelection) txt = document.getSelection();
1542: else if (document.selection) txt = document.selection.createRange().text;
1543: else return;
1544: var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
1545: if (cleantxt=="") {
1.596.2.4 raeburn 1546: alert("$lt{'plse'}");
1.44 ng 1547: return;
1548: }
1.596.2.4 raeburn 1549: var nret = prompt("$lt{'adds'}",cleantxt);
1.44 ng 1550: if (nret==null) return;
1.127 ng 1551: document.SCORE.keywords.value = document.SCORE.keywords.value+" "+nret;
1.44 ng 1552: if (document.SCORE.keywords.value != "") {
1.127 ng 1553: document.SCORE.refresh.value = "on";
1.44 ng 1554: document.SCORE.submit();
1555: }
1556: return;
1557: }
1558:
1559: //====================== Script for composing message ==============
1.80 ng 1560: // preload images
1561: img1 = new Image();
1562: img1.src = "$iconpath/mailbkgrd.gif";
1563: img2 = new Image();
1564: img2.src = "$iconpath/mailto.gif";
1565:
1.44 ng 1566: function msgCenter(msgform,usrctr,fullname) {
1567: var Nmsg = msgform.savemsgN.value;
1568: savedMsgHeader(Nmsg,usrctr,fullname);
1569: var subject = msgform.msgsub.value;
1.127 ng 1570: var msgchk = document.SCORE["includemsg"+usrctr].value;
1.44 ng 1571: re = /msgsub/;
1572: var shwsel = "";
1573: if (re.test(msgchk)) { shwsel = "checked" }
1.123 ng 1574: subject = (document.SCORE.shownSub.value == 0 ? checkEntities(subject) : subject);
1575: displaySubject(checkEntities(subject),shwsel);
1.44 ng 1576: for (var i=1; i<=Nmsg; i++) {
1.123 ng 1577: var testmsg = "savemsg"+i+",";
1578: re = new RegExp(testmsg,"g");
1.44 ng 1579: shwsel = "";
1580: if (re.test(msgchk)) { shwsel = "checked" }
1.125 ng 1581: var message = document.SCORE["savemsg"+i].value;
1.126 ng 1582: message = (document.SCORE["shownOnce"+i].value == 0 ? checkEntities(message) : message);
1.123 ng 1583: displaySavedMsg(i,message,shwsel); //I do not get it. w/o checkEntities on saved messages,
1584: //any < is already converted to <, etc. However, only once!!
1.44 ng 1585: }
1.125 ng 1586: newmsg = document.SCORE["newmsg"+usrctr].value;
1.44 ng 1587: shwsel = "";
1588: re = /newmsg/;
1589: if (re.test(msgchk)) { shwsel = "checked" }
1590: newMsg(newmsg,shwsel);
1591: msgTail();
1592: return;
1593: }
1594:
1.123 ng 1595: function checkEntities(strx) {
1596: if (strx.length == 0) return strx;
1597: var orgStr = ["&", "<", ">", '"'];
1598: var newStr = ["&", "<", ">", """];
1599: var counter = 0;
1600: while (counter < 4) {
1601: strx = strReplace(strx,orgStr[counter],newStr[counter]);
1602: counter++;
1603: }
1604: return strx;
1605: }
1606:
1607: function strReplace(strx, orgStr, newStr) {
1608: return strx.split(orgStr).join(newStr);
1609: }
1610:
1.44 ng 1611: function savedMsgHeader(Nmsg,usrctr,fullname) {
1.76 ng 1612: var height = 70*Nmsg+250;
1.44 ng 1613: var scrollbar = "no";
1614: if (height > 600) {
1615: height = 600;
1616: scrollbar = "yes";
1617: }
1.118 ng 1618: var xpos = (screen.width-600)/2;
1619: xpos = (xpos < 0) ? '0' : xpos;
1620: var ypos = (screen.height-height)/2-30;
1621: ypos = (ypos < 0) ? '0' : ypos;
1622:
1.596.2.4 raeburn 1623: pWin = window.open('', 'MessageCenter', 'resizable=yes,toolbar=no,location=no,scrollbars='+scrollbar+',screenx='+xpos+',screeny='+ypos+',width=700,height='+height);
1.76 ng 1624: pWin.focus();
1625: pDoc = pWin.document;
1.219 www 1626: pDoc.$docopen;
1.351 albertel 1627: pDoc.write('$start_page_msg_central');
1.76 ng 1628:
1629: pDoc.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
1630: pDoc.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
1.596.2.4 raeburn 1631: pDoc.write("<h3><span class=\\"LC_info\\"> $lt{'comp'}\"+fullname+\"<\\/span><\\/h3><br /><br />");
1.76 ng 1632:
1.564 bisitz 1633: pDoc.write('<table border="0" width="100%"><tr><td bgcolor="#777777">');
1634: pDoc.write('<table border="0" width="100%"><tr bgcolor="#DDFFFF">');
1.596.2.4 raeburn 1635: pDoc.write("<td><b>$lt{'type'}<\\/b><\\/td><td><b>$lt{'incl'}<\\/b><\\/td><td><b>$lt{'mesa'}<\\/td><\\/tr>");
1.44 ng 1636: }
1637: function displaySubject(msg,shwsel) {
1.76 ng 1638: pDoc = pWin.document;
1639: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.596.2.4 raeburn 1640: pDoc.write("<td>$lt{'subj'}<\\/td>");
1.465 albertel 1641: pDoc.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1642: pDoc.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+"\\"size=\\"60\\" maxlength=\\"80\\"><\\/td><\\/tr>");
1.44 ng 1643: }
1644:
1.72 ng 1645: function displaySavedMsg(ctr,msg,shwsel) {
1.76 ng 1646: pDoc = pWin.document;
1647: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.465 albertel 1648: pDoc.write("<td align=\\"center\\">"+ctr+"<\\/td>");
1649: pDoc.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1650: pDoc.write("<td><textarea name=\\"msg"+ctr+"\\" cols=\\"60\\" rows=\\"3\\">"+msg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 1651: }
1652:
1653: function newMsg(newmsg,shwsel) {
1.76 ng 1654: pDoc = pWin.document;
1655: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.596.2.4 raeburn 1656: pDoc.write("<td align=\\"center\\">$lt{'new'}<\\/td>");
1.465 albertel 1657: pDoc.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1658: pDoc.write("<td><textarea name=\\"newmsg\\" cols=\\"60\\" rows=\\"3\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" >"+newmsg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 1659: }
1660:
1661: function msgTail() {
1.76 ng 1662: pDoc = pWin.document;
1.465 albertel 1663: pDoc.write("<\\/table>");
1664: pDoc.write("<\\/td><\\/tr><\\/table> ");
1.596.2.4 raeburn 1665: pDoc.write("<input type=\\"button\\" value=\\"$lt{'save'}\\" onclick=\\"javascript:checkInput()\\"> ");
1666: pDoc.write("<input type=\\"button\\" value=\\"$lt{'canc'}\\" onclick=\\"self.close()\\"><br /><br />");
1.465 albertel 1667: pDoc.write("<\\/form>");
1.351 albertel 1668: pDoc.write('$end_page_msg_central');
1.128 ng 1669: pDoc.close();
1.44 ng 1670: }
1671:
1672: //====================== Script for keyword highlight options ==============
1673: function kwhighlight() {
1674: var kwclr = document.SCORE.kwclr.value;
1675: var kwsize = document.SCORE.kwsize.value;
1676: var kwstyle = document.SCORE.kwstyle.value;
1677: var redsel = "";
1678: var grnsel = "";
1679: var blusel = "";
1680: if (kwclr=="red") {var redsel="checked"};
1681: if (kwclr=="green") {var grnsel="checked"};
1682: if (kwclr=="blue") {var blusel="checked"};
1683: var sznsel = "";
1684: var sz1sel = "";
1685: var sz2sel = "";
1686: if (kwsize=="0") {var sznsel="checked"};
1687: if (kwsize=="+1") {var sz1sel="checked"};
1688: if (kwsize=="+2") {var sz2sel="checked"};
1689: var synsel = "";
1690: var syisel = "";
1691: var sybsel = "";
1692: if (kwstyle=="") {var synsel="checked"};
1693: if (kwstyle=="<i>") {var syisel="checked"};
1694: if (kwstyle=="<b>") {var sybsel="checked"};
1695: highlightCentral();
1696: highlightbody('red','red',redsel,'0','normal',sznsel,'','normal',synsel);
1697: highlightbody('green','green',grnsel,'+1','+1',sz1sel,'<i>','italic',syisel);
1698: highlightbody('blue','blue',blusel,'+2','+2',sz2sel,'<b>','bold',sybsel);
1699: highlightend();
1700: return;
1701: }
1702:
1703: function highlightCentral() {
1.76 ng 1704: // if (window.hwdWin) window.hwdWin.close();
1.118 ng 1705: var xpos = (screen.width-400)/2;
1706: xpos = (xpos < 0) ? '0' : xpos;
1707: var ypos = (screen.height-330)/2-30;
1708: ypos = (ypos < 0) ? '0' : ypos;
1709:
1.206 albertel 1710: hwdWin = window.open('', 'KeywordHighlightCentral', 'resizeable=yes,toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx='+xpos+',screeny='+ypos);
1.76 ng 1711: hwdWin.focus();
1712: var hDoc = hwdWin.document;
1.219 www 1713: hDoc.$docopen;
1.351 albertel 1714: hDoc.write('$start_page_highlight_central');
1.76 ng 1715: hDoc.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
1.596.2.4 raeburn 1716: hDoc.write("<h3><span class=\\"LC_info\\"> $lt{'kehi'}<\\/span><\\/h3><br /><br />");
1.76 ng 1717:
1.564 bisitz 1718: hDoc.write('<table border="0" width="100%"><tr><td bgcolor="#777777">');
1719: hDoc.write('<table border="0" width="100%"><tr bgcolor="#DDFFFF">');
1.596.2.4 raeburn 1720: hDoc.write("<td><b>$lt{'txtc'}<\\/b><\\/td><td><b>$lt{'font'}<\\/b><\\/td><td><b>$lt{'fnst'}<\\/td><\\/tr>");
1.44 ng 1721: }
1722:
1723: function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) {
1.76 ng 1724: var hDoc = hwdWin.document;
1725: hDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1726: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1727: hDoc.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+"> "+clrtxt+"<\\/td>");
1.76 ng 1728: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1729: hDoc.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+"> "+sztxt+"<\\/td>");
1.76 ng 1730: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1731: hDoc.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+"> "+sytxt+"<\\/td>");
1732: hDoc.write("<\\/tr>");
1.44 ng 1733: }
1734:
1735: function highlightend() {
1.76 ng 1736: var hDoc = hwdWin.document;
1.465 albertel 1737: hDoc.write("<\\/table>");
1738: hDoc.write("<\\/td><\\/tr><\\/table> ");
1.596.2.4 raeburn 1739: hDoc.write("<input type=\\"button\\" value=\\"$lt{'save'}\\" onclick=\\"javascript:updateChoice(1)\\"> ");
1740: hDoc.write("<input type=\\"button\\" value=\\"$lt{'canc'}\\" onclick=\\"self.close()\\"><br /><br />");
1.465 albertel 1741: hDoc.write("<\\/form>");
1.351 albertel 1742: hDoc.write('$end_page_highlight_central');
1.128 ng 1743: hDoc.close();
1.44 ng 1744: }
1745:
1746: </script>
1747: SUBJAVASCRIPT
1748: }
1749:
1.349 albertel 1750: sub get_increment {
1.348 bowersj2 1751: my $increment = $env{'form.increment'};
1752: if ($increment != 1 && $increment != .5 && $increment != .25 &&
1753: $increment != .1) {
1754: $increment = 1;
1755: }
1756: return $increment;
1757: }
1758:
1.585 bisitz 1759: sub gradeBox_start {
1760: return (
1761: &Apache::loncommon::start_data_table()
1762: .&Apache::loncommon::start_data_table_header_row()
1763: .'<th>'.&mt('Part').'</th>'
1764: .'<th>'.&mt('Points').'</th>'
1765: .'<th> </th>'
1766: .'<th>'.&mt('Assign Grade').'</th>'
1767: .'<th>'.&mt('Weight').'</th>'
1768: .'<th>'.&mt('Grade Status').'</th>'
1769: .&Apache::loncommon::end_data_table_header_row()
1770: );
1771: }
1772:
1773: sub gradeBox_end {
1774: return (
1775: &Apache::loncommon::end_data_table()
1776: );
1777: }
1.71 ng 1778: #--- displays the grading box, used in essay type problem and grading by page/sequence
1779: sub gradeBox {
1.322 albertel 1780: my ($request,$symb,$uname,$udom,$counter,$partid,$record) = @_;
1.381 albertel 1781: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 1782: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 1783: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
1.466 albertel 1784: my $wgtmsg = ($wgt > 0) ? &mt('(problem weight)')
1785: : '<span class="LC_info">'.&mt('problem weight assigned by computer').'</span>';
1.71 ng 1786: $wgt = ($wgt > 0 ? $wgt : '1');
1787: my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
1.320 albertel 1788: '' : &compute_points($$record{'resource.'.$partid.'.awarded'},$wgt));
1.71 ng 1789: my $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />'."\n";
1.466 albertel 1790: my $display_part= &get_display_part($partid,$symb);
1.270 albertel 1791: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
1792: [$partid]);
1793: my $aggtries = $$record{'resource.'.$partid.'.tries'};
1.269 raeburn 1794: if ($last_resets{$partid}) {
1795: $aggtries = &get_num_tries($record,$last_resets{$partid},$partid);
1796: }
1.585 bisitz 1797: $result.=&Apache::loncommon::start_data_table_row();
1.71 ng 1798: my $ctr = 0;
1.348 bowersj2 1799: my $thisweight = 0;
1.349 albertel 1800: my $increment = &get_increment();
1.485 albertel 1801:
1802: my $radio.='<table border="0"><tr>'."\n"; # display radio buttons in a nice table 10 across
1.348 bowersj2 1803: while ($thisweight<=$wgt) {
1.532 bisitz 1804: $radio.= '<td><span class="LC_nobreak"><label><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
1.589 bisitz 1805: 'onclick="javascript:writeBox(this.form,\''.$counter.'_'.$partid.'\','.
1.348 bowersj2 1806: $thisweight.')" value="'.$thisweight.'" '.
1.401 albertel 1807: ($score eq $thisweight ? 'checked="checked"':'').' /> '.$thisweight."</label></span></td>\n";
1.485 albertel 1808: $radio.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1.348 bowersj2 1809: $thisweight += $increment;
1.71 ng 1810: $ctr++;
1811: }
1.485 albertel 1812: $radio.='</tr></table>';
1813:
1814: my $line.='<input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
1.71 ng 1815: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
1.589 bisitz 1816: 'onchange="javascript:updateRadio(this.form,\''.$counter.'_'.$partid.'\','.
1.71 ng 1817: $wgt.')" /></td>'."\n";
1.485 albertel 1818: $line.='<td>/'.$wgt.' '.$wgtmsg.
1.71 ng 1819: ($$record{'resource.'.$partid.'.solved'} eq 'correct_by_student' ? ' '.$checkIcon : '').
1.585 bisitz 1820: ' </td>'."\n";
1821: $line.='<td><select name="GD_SEL'.$counter.'_'.$partid.'" '.
1.589 bisitz 1822: 'onchange="javascript:clearRadBox(this.form,\''.$counter.'_'.$partid.'\')" >'."\n";
1.71 ng 1823: if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
1.485 albertel 1824: $line.='<option></option>'.
1825: '<option value="excused" selected="selected">'.&mt('excused').'</option>';
1.71 ng 1826: } else {
1.485 albertel 1827: $line.='<option selected="selected"></option>'.
1828: '<option value="excused" >'.&mt('excused').'</option>';
1.71 ng 1829: }
1.485 albertel 1830: $line.='<option value="reset status">'.&mt('reset status').'</option></select>'."\n";
1831:
1832:
1833: $result .=
1.585 bisitz 1834: '<td>'.$display_part.'</td><td>'.$radio.'</td><td>'.&mt('or').'</td><td>'.$line.'</td>';
1835: $result.=&Apache::loncommon::end_data_table_row();
1.71 ng 1836: $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="" />'."\n".
1837: '<input type="hidden" name="oldpts'.$counter.'_'.$partid.'" value="'.$score.'" />'."\n".
1838: '<input type="hidden" name="solved'.$counter.'_'.$partid.'" value="'.
1.269 raeburn 1839: $$record{'resource.'.$partid.'.solved'}.'" />'."\n".
1840: '<input type="hidden" name="totaltries'.$counter.'_'.$partid.'" value="'.
1841: $$record{'resource.'.$partid.'.tries'}.'" />'."\n".
1842: '<input type="hidden" name="aggtries'.$counter.'_'.$partid.'" value="'.
1843: $aggtries.'" />'."\n";
1.582 raeburn 1844: my $res_error;
1845: $result.=&handback_box($symb,$uname,$udom,$counter,$partid,$record,\$res_error);
1846: if ($res_error) {
1847: return &navmap_errormsg();
1848: }
1.318 banghart 1849: return $result;
1850: }
1.322 albertel 1851:
1852: sub handback_box {
1.582 raeburn 1853: my ($symb,$uname,$udom,$counter,$partid,$record,$res_error) = @_;
1854: my ($partlist,$handgrade,$responseType) = &response_type($symb,$res_error);
1.323 banghart 1855: my (@respids);
1.596.2.4 raeburn 1856: my @part_response_id = &flatten_responseType($responseType);
1.375 albertel 1857: foreach my $part_response_id (@part_response_id) {
1858: my ($part,$resp) = @{ $part_response_id };
1.323 banghart 1859: if ($part eq $partid) {
1.375 albertel 1860: push(@respids,$resp);
1.323 banghart 1861: }
1862: }
1.318 banghart 1863: my $result;
1.323 banghart 1864: foreach my $respid (@respids) {
1.322 albertel 1865: my $prefix = $counter.'_'.$partid.'_'.$respid.'_';
1866: my $files=&get_submitted_files($udom,$uname,$partid,$respid,$record);
1867: next if (!@$files);
1.596.2.4 raeburn 1868: my $file_counter = 0;
1.313 banghart 1869: foreach my $file (@$files) {
1.368 banghart 1870: if ($file =~ /\/portfolio\//) {
1.596.2.4 raeburn 1871: $file_counter++;
1.368 banghart 1872: my ($file_path, $file_disp) = ($file =~ m|(.+/)(.+)$|);
1873: my ($name,$version,$ext) = &file_name_version_ext($file_disp);
1874: $file_disp = "$name.$ext";
1875: $file = $file_path.$file_disp;
1876: $result.=&mt('Return commented version of [_1] to student.',
1877: '<span class="LC_filename">'.$file_disp.'</span>');
1878: $result.='<input type="file" name="'.$prefix.'returndoc'.$file_counter.'" />'."\n";
1.596.2.4 raeburn 1879: $result.='<input type="hidden" name="'.$prefix.'origdoc'.$file_counter.'" value="'.$file.'" /><br />'."\n";
1.368 banghart 1880: }
1.322 albertel 1881: }
1.596.2.4 raeburn 1882: if ($file_counter) {
1883: $result .= '<input type="hidden" name="'.$prefix.'countreturndoc" value="'.$file_counter.'" />'."\n".
1884: '<span class="LC_info">'.
1885: '('.&mt('File(s) will be uploaded when you click on Save & Next below.',$file_counter).')</span><br /><br />';
1886: }
1.313 banghart 1887: }
1.318 banghart 1888: return $result;
1.71 ng 1889: }
1.44 ng 1890:
1.58 albertel 1891: sub show_problem {
1.382 albertel 1892: my ($request,$symb,$uname,$udom,$removeform,$viewon,$mode,$form) = @_;
1.144 albertel 1893: my $rendered;
1.382 albertel 1894: my %form = ((ref($form) eq 'HASH')? %{$form} : ());
1.329 albertel 1895: &Apache::lonxml::remember_problem_counter();
1.144 albertel 1896: if ($mode eq 'both' or $mode eq 'text') {
1897: $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
1.382 albertel 1898: $env{'request.course.id'},
1899: undef,\%form);
1.144 albertel 1900: }
1.58 albertel 1901: if ($removeform) {
1902: $rendered=~s|<form(.*?)>||g;
1903: $rendered=~s|</form>||g;
1.374 albertel 1904: $rendered=~s|(<input[^>]*name\s*=\s*"?)(\w+)("?)|$1would_have_been_$2$3|g;
1.58 albertel 1905: }
1.144 albertel 1906: my $companswer;
1907: if ($mode eq 'both' or $mode eq 'answer') {
1.329 albertel 1908: &Apache::lonxml::restore_problem_counter();
1.382 albertel 1909: $companswer=
1910: &Apache::loncommon::get_student_answers($symb,$uname,$udom,
1911: $env{'request.course.id'},
1912: %form);
1.144 albertel 1913: }
1.58 albertel 1914: if ($removeform) {
1915: $companswer=~s|<form(.*?)>||g;
1916: $companswer=~s|</form>||g;
1.144 albertel 1917: $companswer=~s|name="submit"|name="would_have_been_submit"|g;
1.58 albertel 1918: }
1.468 albertel 1919: $rendered=
1.588 bisitz 1920: '<div class="LC_Box">'
1921: .'<h3 class="LC_hcell">'.&mt('View of the problem').'</h3>'
1922: .$rendered
1923: .'</div>';
1.468 albertel 1924: $companswer=
1.588 bisitz 1925: '<div class="LC_Box">'
1926: .'<h3 class="LC_hcell">'.&mt('Correct answer').'</h3>'
1927: .$companswer
1928: .'</div>';
1.468 albertel 1929: my $result;
1.144 albertel 1930: if ($mode eq 'both') {
1.588 bisitz 1931: $result=$rendered.$companswer;
1.144 albertel 1932: } elsif ($mode eq 'text') {
1.588 bisitz 1933: $result=$rendered;
1.144 albertel 1934: } elsif ($mode eq 'answer') {
1.588 bisitz 1935: $result=$companswer;
1.144 albertel 1936: }
1.71 ng 1937: return $result;
1.58 albertel 1938: }
1.397 albertel 1939:
1.396 banghart 1940: sub files_exist {
1941: my ($r, $symb) = @_;
1942: my @students = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.397 albertel 1943:
1.396 banghart 1944: foreach my $student (@students) {
1945: my ($uname,$udom,$fullname) = split(/:/,$student);
1.397 albertel 1946: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1947: $udom,$uname);
1.396 banghart 1948: my ($string,$timestamp)= &get_last_submission(\%record);
1.397 albertel 1949: foreach my $submission (@$string) {
1950: my ($partid,$respid) =
1951: ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
1952: my $files=&get_submitted_files($udom,$uname,$partid,$respid,
1953: \%record);
1954: return 1 if (@$files);
1.396 banghart 1955: }
1956: }
1.397 albertel 1957: return 0;
1.396 banghart 1958: }
1.397 albertel 1959:
1.394 banghart 1960: sub download_all_link {
1961: my ($r,$symb) = @_;
1.395 albertel 1962: my $all_students =
1963: join("\n", &Apache::loncommon::get_env_multiple('form.stuinfo'));
1964:
1965: my $parts =
1966: join("\n",&Apache::loncommon::get_env_multiple('form.vPart'));
1967:
1.394 banghart 1968: my $identifier = &Apache::loncommon::get_cgi_id();
1.514 raeburn 1969: &Apache::lonnet::appenv({'cgi.'.$identifier.'.students' => $all_students,
1970: 'cgi.'.$identifier.'.symb' => $symb,
1971: 'cgi.'.$identifier.'.parts' => $parts,});
1.395 albertel 1972: $r->print('<a href="/cgi-bin/multidownload.pl?'.$identifier.'">'.
1973: &mt('Download All Submitted Documents').'</a>');
1.394 banghart 1974: return
1975: }
1.395 albertel 1976:
1.432 banghart 1977: sub build_section_inputs {
1978: my $section_inputs;
1979: if ($env{'form.section'} eq '') {
1980: $section_inputs .= '<input type="hidden" name="section" value="all" />'."\n";
1981: } else {
1982: my @sections = &Apache::loncommon::get_env_multiple('form.section');
1.434 albertel 1983: foreach my $section (@sections) {
1.432 banghart 1984: $section_inputs .= '<input type="hidden" name="section" value="'.$section.'" />'."\n";
1985: }
1986: }
1987: return $section_inputs;
1988: }
1989:
1.44 ng 1990: # --------------------------- show submissions of a student, option to grade
1991: sub submission {
1992: my ($request,$counter,$total) = @_;
1.257 albertel 1993: my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
1994: $udom = ($udom eq '' ? $env{'user.domain'} : $udom); #has form.userdom changed for a student?
1995: my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
1996: $env{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $env{'form.fullname'} eq '';
1.324 albertel 1997: my $symb = &get_symb($request);
1998: if ($symb eq '') { $request->print("Unable to handle ambiguous references:."); return ''; }
1.104 albertel 1999:
2000: if (!&canview($usec)) {
1.398 albertel 2001: $request->print('<span class="LC_warning">Unable to view requested student.('.
2002: $uname.':'.$udom.' in section '.$usec.' in course id '.
2003: $env{'request.course.id'}.')</span>');
1.324 albertel 2004: $request->print(&show_grading_menu_form($symb));
1.104 albertel 2005: return;
2006: }
2007:
1.257 albertel 2008: if (!$env{'form.lastSub'}) { $env{'form.lastSub'} = 'datesub'; }
2009: if (!$env{'form.vProb'}) { $env{'form.vProb'} = 'yes'; }
2010: if (!$env{'form.vAns'}) { $env{'form.vAns'} = 'yes'; }
2011: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.381 albertel 2012: my $checkIcon = '<img alt="'.&mt('Check Mark').
2013: '" src="'.$request->dir_config('lonIconsURL').
1.122 ng 2014: '/check.gif" height="16" border="0" />';
1.41 ng 2015:
1.426 albertel 2016: my %old_essays;
1.41 ng 2017: # header info
2018: if ($counter == 0) {
2019: &sub_page_js($request);
1.257 albertel 2020: &sub_page_kw_js($request) if ($env{'form.handgrade'} eq 'yes');
2021: $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
2022: &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
1.397 albertel 2023: if ($env{'form.handgrade'} eq 'yes' && &files_exist($request, $symb)) {
1.396 banghart 2024: &download_all_link($request, $symb);
2025: }
1.485 albertel 2026: $request->print('<h3> <span class="LC_info">'.&mt('Submission Record').'</span></h3>'."\n".
2027: '<h4> '.&mt('<b>Resource: </b> [_1]',$env{'form.probTitle'}).'</h4>'."\n");
1.118 ng 2028:
1.44 ng 2029: # option to display problem, only once else it cause problems
2030: # with the form later since the problem has a form.
1.257 albertel 2031: if ($env{'form.vProb'} eq 'yes' or $env{'form.vAns'} eq 'yes') {
1.144 albertel 2032: my $mode;
1.257 albertel 2033: if ($env{'form.vProb'} eq 'yes' && $env{'form.vAns'} eq 'yes') {
1.144 albertel 2034: $mode='both';
1.257 albertel 2035: } elsif ($env{'form.vProb'} eq 'yes') {
1.144 albertel 2036: $mode='text';
1.257 albertel 2037: } elsif ($env{'form.vAns'} eq 'yes') {
1.144 albertel 2038: $mode='answer';
2039: }
1.329 albertel 2040: &Apache::lonxml::clear_problem_counter();
1.144 albertel 2041: $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
1.41 ng 2042: }
1.441 www 2043:
1.44 ng 2044: # kwclr is the only variable that is guaranteed to be non blank
2045: # if this subroutine has been called once.
1.41 ng 2046: my %keyhash = ();
1.257 albertel 2047: if ($env{'form.kwclr'} eq '' && $env{'form.handgrade'} eq 'yes') {
1.41 ng 2048: %keyhash = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 2049: $env{'course.'.$env{'request.course.id'}.'.domain'},
2050: $env{'course.'.$env{'request.course.id'}.'.num'});
1.41 ng 2051:
1.257 albertel 2052: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
2053: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
2054: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
2055: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
2056: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
2057: $env{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
2058: $keyhash{$symb.'_subject'} : $env{'form.probTitle'};
2059: $env{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1.41 ng 2060: }
1.257 albertel 2061: my $overRideScore = $env{'form.overRideScore'} eq '' ? 'no' : $env{'form.overRideScore'};
1.442 banghart 2062: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.303 banghart 2063: $request->print('<form action="/adm/grades" method="post" name="SCORE" enctype="multipart/form-data">'."\n".
1.41 ng 2064: '<input type="hidden" name="command" value="handgrade" />'."\n".
1.257 albertel 2065: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.442 banghart 2066: '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.120 ng 2067: '<input type="hidden" name="overRideScore" value="'.$overRideScore.'" />'."\n".
1.257 albertel 2068: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.41 ng 2069: '<input type="hidden" name="refresh" value="off" />'."\n".
1.120 ng 2070: '<input type="hidden" name="studentNo" value="" />'."\n".
2071: '<input type="hidden" name="gradeOpt" value="" />'."\n".
1.418 albertel 2072: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 2073: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" />'."\n".
2074: '<input type="hidden" name="vProb" value="'.$env{'form.vProb'}.'" />'."\n".
2075: '<input type="hidden" name="vAns" value="'.$env{'form.vAns'}.'" />'."\n".
2076: '<input type="hidden" name="lastSub" value="'.$env{'form.lastSub'}.'" />'."\n".
1.432 banghart 2077: &build_section_inputs().
1.326 albertel 2078: '<input type="hidden" name="submitonly" value="'.$env{'form.submitonly'}.'" />'."\n".
2079: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" />'."\n".
1.41 ng 2080: '<input type="hidden" name="NCT"'.
1.257 albertel 2081: ' value="'.($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : $total+1).'" />'."\n");
2082: if ($env{'form.handgrade'} eq 'yes') {
2083: $request->print('<input type="hidden" name="keywords" value="'.$env{'form.keywords'}.'" />'."\n".
2084: '<input type="hidden" name="kwclr" value="'.$env{'form.kwclr'}.'" />'."\n".
2085: '<input type="hidden" name="kwsize" value="'.$env{'form.kwsize'}.'" />'."\n".
2086: '<input type="hidden" name="kwstyle" value="'.$env{'form.kwstyle'}.'" />'."\n".
2087: '<input type="hidden" name="msgsub" value="'.$env{'form.msgsub'}.'" />'."\n".
1.123 ng 2088: '<input type="hidden" name="shownSub" value="0" />'."\n".
1.257 albertel 2089: '<input type="hidden" name="savemsgN" value="'.$env{'form.savemsgN'}.'" />'."\n");
1.154 albertel 2090: foreach my $partid (&Apache::loncommon::get_env_multiple('form.vPart')) {
2091: $request->print('<input type="hidden" name="vPart" value="'.$partid.'" />'."\n");
2092: }
1.123 ng 2093: }
1.41 ng 2094:
2095: my ($cts,$prnmsg) = (1,'');
1.257 albertel 2096: while ($cts <= $env{'form.savemsgN'}) {
1.41 ng 2097: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
1.123 ng 2098: (!exists($keyhash{$symb.'_savemsg'.$cts}) ?
1.257 albertel 2099: &Apache::lonfeedback::clear_out_html($env{'form.savemsg'.$cts}) :
1.80 ng 2100: &Apache::lonfeedback::clear_out_html($keyhash{$symb.'_savemsg'.$cts})).
1.123 ng 2101: '" />'."\n".
2102: '<input type="hidden" name="shownOnce'.$cts.'" value="0" />'."\n";
1.41 ng 2103: $cts++;
2104: }
2105: $request->print($prnmsg);
1.32 ng 2106:
1.257 albertel 2107: if ($env{'form.handgrade'} eq 'yes' && $env{'form.showgrading'} eq 'yes') {
1.596.2.4 raeburn 2108:
2109: my %lt = &Apache::lonlocal::texthash(
2110: keyw => 'Keyword Options',
2111: list => 'List',
2112: past => 'Paste Selection to List',
1.596.2.9 raeburn 2113: high => 'Highlight Attribute',
1.596.2.4 raeburn 2114: );
1.88 www 2115: #
2116: # Print out the keyword options line
2117: #
1.41 ng 2118: $request->print(<<KEYWORDS);
1.596.2.4 raeburn 2119: <b>$lt{'keyw'}:</b>
2120: <a href="javascript:keywords(document.SCORE);" target="_self">$lt{'list'}</a>
1.589 bisitz 2121: <a href="#" onmousedown="javascript:getSel(); return false"
1.596.2.4 raeburn 2122: CLASS="page">$lt{'past'}</a>
2123: <a href="javascript:kwhighlight();" target="_self">$lt{'high'}</a><br /><br />
1.38 ng 2124: KEYWORDS
1.88 www 2125: #
2126: # Load the other essays for similarity check
2127: #
1.324 albertel 2128: my (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb);
1.384 albertel 2129: my ($adom,$aname,$apath)=($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
1.359 www 2130: $apath=&escape($apath);
1.88 www 2131: $apath=~s/\W/\_/gs;
1.426 albertel 2132: %old_essays=&Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
1.41 ng 2133: }
2134: }
1.44 ng 2135:
1.441 www 2136: # This is where output for one specific student would start
1.592 bisitz 2137: my $add_class = ($counter%2) ? ' LC_grade_show_user_odd_row' : '';
2138: $request->print(
2139: "\n\n"
2140: .'<div class="LC_grade_show_user'.$add_class.'">'
2141: .'<h2>'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).'</h2>'
2142: ."\n"
2143: );
1.441 www 2144:
1.592 bisitz 2145: # Show additional functions if allowed
2146: if ($perm{'vgr'}) {
2147: $request->print(
2148: &Apache::loncommon::track_student_link(
2149: &mt('View recent activity'),
2150: $uname,$udom,'check')
2151: .' '
2152: );
2153: }
2154: if ($perm{'opa'}) {
2155: $request->print(
2156: &Apache::loncommon::pprmlink(
2157: &mt('Set/Change parameters'),
2158: $uname,$udom,$symb,'check'));
2159: }
2160:
2161: # Show Problem
1.257 albertel 2162: if ($env{'form.vProb'} eq 'all' or $env{'form.vAns'} eq 'all') {
1.144 albertel 2163: my $mode;
1.257 albertel 2164: if ($env{'form.vProb'} eq 'all' && $env{'form.vAns'} eq 'all') {
1.144 albertel 2165: $mode='both';
1.257 albertel 2166: } elsif ($env{'form.vProb'} eq 'all' ) {
1.144 albertel 2167: $mode='text';
1.257 albertel 2168: } elsif ($env{'form.vAns'} eq 'all') {
1.144 albertel 2169: $mode='answer';
2170: }
1.329 albertel 2171: &Apache::lonxml::clear_problem_counter();
1.475 albertel 2172: $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode,{'request.prefix' => 'ctr'.$counter}));
1.58 albertel 2173: }
1.144 albertel 2174:
1.257 albertel 2175: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.582 raeburn 2176: my $res_error;
2177: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
2178: if ($res_error) {
2179: $request->print(&navmap_errormsg());
2180: return;
2181: }
1.41 ng 2182:
1.44 ng 2183: # Display student info
1.41 ng 2184: $request->print(($counter == 0 ? '' : '<br />'));
1.590 bisitz 2185:
2186: my $result='<div class="LC_Box">'
2187: .'<h3 class="LC_hcell">'.&mt('Submissions').'</h3>';
1.45 ng 2188: $result.='<input type="hidden" name="name'.$counter.
1.588 bisitz 2189: '" value="'.$env{'form.fullname'}.'" />'."\n";
1.469 albertel 2190: if ($env{'form.handgrade'} eq 'no') {
1.588 bisitz 2191: $result.='<p class="LC_info">'
2192: .&mt('Part(s) graded correct by the computer is marked with a [_1] symbol.',$checkIcon)
2193: ."</p>\n";
1.469 albertel 2194: }
2195:
1.118 ng 2196: # If any part of the problem is an essay-response (handgraded), then check for collaborators
1.464 albertel 2197: my $fullname;
2198: my $col_fullnames = [];
1.257 albertel 2199: if ($env{'form.handgrade'} eq 'yes') {
1.464 albertel 2200: (my $sub_result,$fullname,$col_fullnames)=
2201: &check_collaborators($symb,$uname,$udom,\%record,$handgrade,
2202: $counter);
2203: $result.=$sub_result;
1.41 ng 2204: }
1.44 ng 2205: $request->print($result."\n");
1.588 bisitz 2206:
1.44 ng 2207: # print student answer/submission
1.588 bisitz 2208: # Options are (1) Handgraded submission only
1.44 ng 2209: # (2) Last submission, includes submission that is not handgraded
2210: # (for multi-response type part)
2211: # (3) Last submission plus the parts info
2212: # (4) The whole record for this student
1.257 albertel 2213: if ($env{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
1.151 albertel 2214: my ($string,$timestamp)= &get_last_submission(\%record);
1.468 albertel 2215:
2216: my $lastsubonly;
2217:
1.588 bisitz 2218: if ($$timestamp eq '') {
2219: $lastsubonly.='<div class="LC_grade_submissions_body">'.$$string[0].'</div>';
2220: } else {
1.592 bisitz 2221: $lastsubonly =
2222: '<div class="LC_grade_submissions_body">'
2223: .'<b>'.&mt('Date Submitted:').'</b> '.$$timestamp."\n";
1.468 albertel 2224:
1.151 albertel 2225: my %seenparts;
1.375 albertel 2226: my @part_response_id = &flatten_responseType($responseType);
2227: foreach my $part (@part_response_id) {
1.393 albertel 2228: next if ($env{'form.lastSub'} eq 'hdgrade'
2229: && $$handgrade{$$part[0].'_'.$$part[1]} ne 'yes');
2230:
1.375 albertel 2231: my ($partid,$respid) = @{ $part };
1.324 albertel 2232: my $display_part=&get_display_part($partid,$symb);
1.257 albertel 2233: if ($env{"form.$uname:$udom:$partid:submitted_by"}) {
1.151 albertel 2234: if (exists($seenparts{$partid})) { next; }
2235: $seenparts{$partid}=1;
1.207 albertel 2236: my $submitby='<b>Part:</b> '.$display_part.
2237: ' <b>Collaborative submission by:</b> '.
1.151 albertel 2238: '<a href="javascript:viewSubmitter(\''.
1.257 albertel 2239: $env{"form.$uname:$udom:$partid:submitted_by"}.
1.417 albertel 2240: '\');" target="_self">'.
1.257 albertel 2241: $$fullname{$env{"form.$uname:$udom:$partid:submitted_by"}}.'</a><br />';
1.151 albertel 2242: $request->print($submitby);
2243: next;
2244: }
2245: my $responsetype = $responseType->{$partid}->{$respid};
2246: if (!exists($record{"resource.$partid.$respid.submission"})) {
1.577 bisitz 2247: $lastsubonly.="\n".'<div class="LC_grade_submission_part">'.
2248: '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
2249: ' <span class="LC_internal_info">'.
1.596.2.4 raeburn 2250: '('.&mt('Response ID: [_1]',$respid).')'.
1.577 bisitz 2251: '</span> '.
1.539 riegler 2252: '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br /><br /></div>';
1.151 albertel 2253: next;
2254: }
1.468 albertel 2255: foreach my $submission (@$string) {
2256: my ($partid,$respid) = ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
1.375 albertel 2257: if (join('_',@{$part}) ne ($partid.'_'.$respid)) { next; }
1.596 raeburn 2258: my ($ressub,$hide,$subval) = split(/:/,$submission,3);
1.151 albertel 2259: # Similarity check
2260: my $similar='';
1.596.2.2 raeburn 2261: my ($type,$trial,$rndseed);
2262: if ($hide eq 'rand') {
2263: $type = 'randomizetry';
2264: $trial = $record{"resource.$partid.tries"};
2265: $rndseed = $record{"resource.$partid.rndseed"};
2266: }
1.257 albertel 2267: if($env{'form.checkPlag'}){
1.151 albertel 2268: my ($oname,$odom,$ocrsid,$oessay,$osim)=
1.426 albertel 2269: &most_similar($uname,$udom,$subval,\%old_essays);
1.151 albertel 2270: if ($osim) {
2271: $osim=int($osim*100.0);
1.426 albertel 2272: my %old_course_desc =
2273: &Apache::lonnet::coursedescription($ocrsid,
2274: {'one_time' => 1});
2275:
1.596.2.2 raeburn 2276: if ($hide eq 'anon') {
1.596 raeburn 2277: $similar='<hr /><span class="LC_warning">'.&mt("Essay was found to be similar to another essay submitted for this assignment.").'<br />'.
2278: &mt('As the current submission is for an anonymous survey, no other details are available.').'</span><hr />';
2279: } else {
2280: $similar="<hr /><h3><span class=\"LC_warning\">".
2281: &mt('Essay is [_1]% similar to an essay by [_2] in course [_3] (course id [_4]:[_5])',
2282: $osim,
2283: &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')',
2284: $old_course_desc{'description'},
2285: $old_course_desc{'num'},
2286: $old_course_desc{'domain'}).
2287: '</span></h3><blockquote><i>'.
2288: &keywords_highlight($oessay).
2289: '</i></blockquote><hr />';
2290: }
1.151 albertel 2291: }
1.150 albertel 2292: }
1.596.2.2 raeburn 2293: my $order=&get_order($partid,$respid,$symb,$uname,$udom,
2294: undef,$type,$trial,$rndseed);
1.257 albertel 2295: if ($env{'form.lastSub'} eq 'lastonly' ||
2296: ($env{'form.lastSub'} eq 'hdgrade' &&
1.377 albertel 2297: $$handgrade{$$part[0].'_'.$$part[1]} eq 'yes')) {
1.324 albertel 2298: my $display_part=&get_display_part($partid,$symb);
1.577 bisitz 2299: $lastsubonly.='<div class="LC_grade_submission_part">'.
2300: '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
2301: ' <span class="LC_internal_info">'.
1.596.2.4 raeburn 2302: '('.&mt('Response ID: [_1]',$respid).')'.
2303: '</span> ';
1.313 banghart 2304: my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record);
2305: if (@$files) {
1.596.2.2 raeburn 2306: if ($hide eq 'anon') {
1.596 raeburn 2307: $lastsubonly.='<br />'.&mt('[quant,_1,file] uploaded to this anonymous survey',scalar(@{$files}));
2308: } else {
2309: $lastsubonly.='<br /><span class="LC_warning">'.&mt('Like all files provided by users, this file may contain viruses').'</span><br />';
2310: foreach my $file (@$files) {
2311: &Apache::lonnet::allowuploaded('/adm/grades',$file);
2312: $lastsubonly.='<br /><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.&Apache::loncommon::icon($file).'" border="0" /> '.$file.'</a>';
2313: }
2314: }
1.236 albertel 2315: $lastsubonly.='<br />';
1.41 ng 2316: }
1.596.2.2 raeburn 2317: if ($hide eq 'anon') {
1.596 raeburn 2318: $lastsubonly.='<b>'.&mt('Anonymous Survey').'</b>';
2319: } else {
2320: $lastsubonly.='<b>'.&mt('Submitted Answer:').' </b>'.
2321: &cleanRecord($subval,$responsetype,$symb,$partid,
1.596.2.2 raeburn 2322: $respid,\%record,$order,undef,$uname,$udom,$type,$trial,$rndseed);
1.596 raeburn 2323: }
1.151 albertel 2324: if ($similar) {$lastsubonly.="<br /><br />$similar\n";}
1.468 albertel 2325: $lastsubonly.='</div>';
1.41 ng 2326: }
2327: }
2328: }
1.588 bisitz 2329: $lastsubonly.='</div>'."\n"; # End: LC_grade_submissions_body
1.151 albertel 2330: }
2331: $request->print($lastsubonly);
1.468 albertel 2332: } elsif ($env{'form.lastSub'} eq 'datesub') {
1.324 albertel 2333: my (undef,$responseType,undef,$parts) = &showResourceInfo($symb);
1.148 albertel 2334: $request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
1.257 albertel 2335: } elsif ($env{'form.lastSub'} =~ /^(last|all)$/) {
1.41 ng 2336: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
1.257 albertel 2337: $env{'request.course.id'},
1.44 ng 2338: $last,'.submission',
2339: 'Apache::grades::keywords_highlight'));
1.41 ng 2340: }
1.120 ng 2341:
1.121 ng 2342: $request->print('<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
2343: .$udom.'" />'."\n");
1.44 ng 2344: # return if view submission with no grading option
1.257 albertel 2345: if ($env{'form.showgrading'} eq '' || (!&canmodify($usec))) {
1.120 ng 2346: my $toGrade.='<input type="button" value="Grade Student" '.
1.589 bisitz 2347: 'onclick="javascript:checksubmit(this.form,\'Grade Student\',\''
1.417 albertel 2348: .$counter.'\');" target="_self" /> '."\n" if (&canmodify($usec));
1.468 albertel 2349: $toGrade.='</div>'."\n";
1.257 albertel 2350: if (($env{'form.command'} eq 'submission') ||
2351: ($env{'form.command'} eq 'processGroup' && $counter == $total)) {
1.324 albertel 2352: $toGrade.='</form>'.&show_grading_menu_form($symb);
1.169 albertel 2353: }
1.180 albertel 2354: $request->print($toGrade);
1.41 ng 2355: return;
1.180 albertel 2356: } else {
1.468 albertel 2357: $request->print('</div>'."\n");
1.41 ng 2358: }
1.33 ng 2359:
1.121 ng 2360: # essay grading message center
1.257 albertel 2361: if ($env{'form.handgrade'} eq 'yes') {
1.468 albertel 2362: my $result='<div class="LC_grade_message_center">';
2363:
2364: $result.='<div class="LC_grade_message_center_header">'.
2365: &mt('Send Message').'</div><div class="LC_grade_message_center_body">';
1.257 albertel 2366: my ($lastname,$givenn) = split(/,/,$env{'form.fullname'});
1.118 ng 2367: my $msgfor = $givenn.' '.$lastname;
1.464 albertel 2368: if (scalar(@$col_fullnames) > 0) {
2369: my $lastone = pop(@$col_fullnames);
2370: $msgfor .= ', '.(join ', ',@$col_fullnames).' and '.$lastone.'.';
1.118 ng 2371: }
2372: $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
1.468 albertel 2373: $result.='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
1.121 ng 2374: '<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n";
2375: $result.=' <a href="javascript:msgCenter(document.SCORE,'.$counter.
1.417 albertel 2376: ',\''.$msgfor.'\');" target="_self">'.
1.464 albertel 2377: &mt('Compose message to student').(scalar(@$col_fullnames) >= 1 ? 's' : '').'</a><label> ('.
1.350 albertel 2378: &mt('incl. grades').' <input type="checkbox" name="withgrades'.$counter.'" /></label>)'.
1.118 ng 2379: '<img src="'.$request->dir_config('lonIconsURL').
2380: '/mailbkgrd.gif" width="14" height="10" name="mailicon'.$counter.'" />'."\n".
1.298 www 2381: '<br /> ('.
1.468 albertel 2382: &mt('Message will be sent when you click on Save & Next below.').")\n";
2383: $result.='</div></div>';
1.121 ng 2384: $request->print($result);
1.118 ng 2385: }
1.41 ng 2386:
2387: my %seen = ();
2388: my @partlist;
1.129 ng 2389: my @gradePartRespid;
1.375 albertel 2390: my @part_response_id = &flatten_responseType($responseType);
1.585 bisitz 2391: $request->print(
1.588 bisitz 2392: '<div class="LC_Box">'
2393: .'<h3 class="LC_hcell">'.&mt('Assign Grades').'</h3>'
1.585 bisitz 2394: );
1.592 bisitz 2395: $request->print(&gradeBox_start());
1.375 albertel 2396: foreach my $part_response_id (@part_response_id) {
2397: my ($partid,$respid) = @{ $part_response_id };
2398: my $part_resp = join('_',@{ $part_response_id });
1.322 albertel 2399: next if ($seen{$partid} > 0);
1.41 ng 2400: $seen{$partid}++;
1.393 albertel 2401: next if ($$handgrade{$part_resp} ne 'yes'
2402: && $env{'form.lastSub'} eq 'hdgrade');
1.524 raeburn 2403: push(@partlist,$partid);
2404: push(@gradePartRespid,$partid.'.'.$respid);
1.322 albertel 2405: $request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
1.41 ng 2406: }
1.585 bisitz 2407: $request->print(&gradeBox_end()); # </div>
2408: $request->print('</div>');
1.468 albertel 2409:
2410: $request->print('<div class="LC_grade_info_links">');
2411: $request->print('</div>');
2412:
1.45 ng 2413: $result='<input type="hidden" name="partlist'.$counter.
2414: '" value="'.(join ":",@partlist).'" />'."\n";
1.129 ng 2415: $result.='<input type="hidden" name="gradePartRespid'.
2416: '" value="'.(join ":",@gradePartRespid).'" />'."\n" if ($counter == 0);
1.45 ng 2417: my $ctr = 0;
2418: while ($ctr < scalar(@partlist)) {
2419: $result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
2420: $partlist[$ctr].'" />'."\n";
2421: $ctr++;
2422: }
1.468 albertel 2423: $request->print($result.''."\n");
1.41 ng 2424:
1.441 www 2425: # Done with printing info for one student
2426:
1.468 albertel 2427: $request->print('</div>');#LC_grade_show_user
1.441 www 2428:
2429:
1.41 ng 2430: # print end of form
2431: if ($counter == $total) {
1.592 bisitz 2432: my $endform='<br /><hr /><table border="0"><tr><td>'."\n";
1.485 albertel 2433: $endform.='<input type="button" value="'.&mt('Save & Next').'" '.
1.589 bisitz 2434: 'onclick="javascript:checksubmit(this.form,\'Save & Next\','.
1.417 albertel 2435: $total.','.scalar(@partlist).');" target="_self" /> '."\n";
1.119 ng 2436: my $ntstu ='<select name="NTSTU">'.
2437: '<option>1</option><option>2</option>'.
2438: '<option>3</option><option>5</option>'.
2439: '<option>7</option><option>10</option></select>'."\n";
1.257 albertel 2440: my $nsel = ($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : '1');
1.401 albertel 2441: $ntstu =~ s/<option>$nsel</<option selected="selected">$nsel</;
1.578 raeburn 2442: $endform.=&mt('[_1]student(s)',$ntstu);
1.485 albertel 2443: $endform.=' <input type="button" value="'.&mt('Previous').'" '.
1.589 bisitz 2444: 'onclick="javascript:checksubmit(this.form,\'Previous\');" target="_self" /> '."\n".
1.485 albertel 2445: '<input type="button" value="'.&mt('Next').'" '.
1.589 bisitz 2446: 'onclick="javascript:checksubmit(this.form,\'Next\');" target="_self" /> ';
1.592 bisitz 2447: $endform.='<span class="LC_warning">'.
2448: &mt('(Next and Previous (student) do not save the scores.)').
2449: '</span>'."\n" ;
1.349 albertel 2450: $endform.="<input type='hidden' value='".&get_increment().
1.348 bowersj2 2451: "' name='increment' />";
1.485 albertel 2452: $endform.='</td></tr></table></form>';
1.324 albertel 2453: $endform.=&show_grading_menu_form($symb);
1.41 ng 2454: $request->print($endform);
2455: }
2456: return '';
1.38 ng 2457: }
2458:
1.464 albertel 2459: sub check_collaborators {
2460: my ($symb,$uname,$udom,$record,$handgrade,$counter) = @_;
2461: my ($result,@col_fullnames);
2462: my ($classlist,undef,$fullname) = &getclasslist('all','0');
2463: foreach my $part (keys(%$handgrade)) {
2464: my $ncol = &Apache::lonnet::EXT('resource.'.$part.
2465: '.maxcollaborators',
2466: $symb,$udom,$uname);
2467: next if ($ncol <= 0);
2468: $part =~ s/\_/\./g;
2469: next if ($record->{'resource.'.$part.'.collaborators'} eq '');
2470: my (@good_collaborators, @bad_collaborators);
2471: foreach my $possible_collaborator
1.596.2.4 raeburn 2472: (split(/[,;\s]+/,$record->{'resource.'.$part.'.collaborators'})) {
1.464 albertel 2473: $possible_collaborator =~ s/[\$\^\(\)]//g;
2474: next if ($possible_collaborator eq '');
1.596.2.8 raeburn 2475: my ($co_name,$co_dom) = split(/:/,$possible_collaborator);
1.464 albertel 2476: $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
2477: next if ($co_name eq $uname && $co_dom eq $udom);
2478: # Doing this grep allows 'fuzzy' specification
2479: my @matches = grep(/^\Q$co_name\E:\Q$co_dom\E$/i,
2480: keys(%$classlist));
2481: if (! scalar(@matches)) {
2482: push(@bad_collaborators, $possible_collaborator);
2483: } else {
2484: push(@good_collaborators, @matches);
2485: }
2486: }
2487: if (scalar(@good_collaborators) != 0) {
1.596.2.8 raeburn 2488: $result.='<br />'.&mt('Collaborators:').'<ol>';
1.464 albertel 2489: foreach my $name (@good_collaborators) {
2490: my ($lastname,$givenn) = split(/,/,$$fullname{$name});
2491: push(@col_fullnames, $givenn.' '.$lastname);
1.596.2.4 raeburn 2492: $result.='<li>'.$fullname->{$name}.'</li>';
1.464 albertel 2493: }
1.596.2.4 raeburn 2494: $result.='</ol><br />'."\n";
1.466 albertel 2495: my ($part)=split(/\./,$part);
1.464 albertel 2496: $result.='<input type="hidden" name="collaborator'.$counter.
2497: '" value="'.$part.':'.(join ':',@good_collaborators).'" />'.
2498: "\n";
2499: }
2500: if (scalar(@bad_collaborators) > 0) {
1.466 albertel 2501: $result.='<div class="LC_warning">';
1.464 albertel 2502: $result.=&mt('This student has submitted [quant,_1,invalid collaborator]: [_2]',scalar(@bad_collaborators),join(', ',@bad_collaborators));
2503: $result .= '</div>';
2504: }
2505: if (scalar(@bad_collaborators > $ncol)) {
1.466 albertel 2506: $result .= '<div class="LC_warning">';
1.464 albertel 2507: $result .= &mt('This student has submitted too many '.
2508: 'collaborators. Maximum is [_1].',$ncol);
2509: $result .= '</div>';
2510: }
2511: }
2512: return ($result,$fullname,\@col_fullnames);
2513: }
2514:
1.44 ng 2515: #--- Retrieve the last submission for all the parts
1.38 ng 2516: sub get_last_submission {
1.119 ng 2517: my ($returnhash)=@_;
1.596 raeburn 2518: my (@string,$timestamp,%lasthidden);
1.119 ng 2519: if ($$returnhash{'version'}) {
1.46 ng 2520: my %lasthash=();
2521: my ($version);
1.119 ng 2522: for ($version=1;$version<=$$returnhash{'version'};$version++) {
1.397 albertel 2523: foreach my $key (sort(split(/\:/,
2524: $$returnhash{$version.':keys'}))) {
2525: $lasthash{$key}=$$returnhash{$version.':'.$key};
2526: $timestamp =
1.545 raeburn 2527: &Apache::lonlocal::locallocaltime($$returnhash{$version.':timestamp'});
1.46 ng 2528: }
2529: }
1.596.2.2 raeburn 2530: my (%typeparts,%randombytry);
1.596 raeburn 2531: my $showsurv =
2532: &Apache::lonnet::allowed('vas',$env{'request.course.id'});
2533: foreach my $key (sort(keys(%lasthash))) {
2534: if ($key =~ /\.type$/) {
2535: if (($lasthash{$key} eq 'anonsurvey') ||
1.596.2.2 raeburn 2536: ($lasthash{$key} eq 'anonsurveycred') ||
2537: ($lasthash{$key} eq 'randomizetry')) {
1.596 raeburn 2538: my ($ign,@parts) = split(/\./,$key);
2539: pop(@parts);
1.596.2.3 raeburn 2540: my $id = join('.',@parts);
1.596.2.2 raeburn 2541: if ($lasthash{$key} eq 'randomizetry') {
2542: $randombytry{$ign.'.'.$id} = $lasthash{$key};
2543: } else {
2544: unless ($showsurv) {
2545: $typeparts{$ign.'.'.$id} = $lasthash{$key};
2546: }
1.596 raeburn 2547: }
2548: delete($lasthash{$key});
2549: }
2550: }
2551: }
2552: my @hidden = keys(%typeparts);
1.596.2.2 raeburn 2553: my @randomize = keys(%randombytry);
1.397 albertel 2554: foreach my $key (keys(%lasthash)) {
2555: next if ($key !~ /\.submission$/);
1.596 raeburn 2556: my $hide;
2557: if (@hidden) {
2558: foreach my $id (@hidden) {
2559: if ($key =~ /^\Q$id\E/) {
1.596.2.2 raeburn 2560: $hide = 'anon';
1.596 raeburn 2561: last;
2562: }
2563: }
2564: }
1.596.2.2 raeburn 2565: unless ($hide) {
2566: if (@randomize) {
2567: foreach my $id (@hidden) {
2568: if ($key =~ /^\Q$id\E/) {
2569: $hide = 'rand';
2570: last;
2571: }
2572: }
2573: }
2574: }
1.397 albertel 2575: my ($partid,$foo) = split(/submission$/,$key);
2576: my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
1.398 albertel 2577: '<span class="LC_warning">Draft Copy</span> ' : '';
1.596 raeburn 2578: push(@string, join(':', $key, $hide, $draft.$lasthash{$key}));
1.41 ng 2579: }
2580: }
1.397 albertel 2581: if (!@string) {
2582: $string[0] =
1.539 riegler 2583: '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span>';
1.397 albertel 2584: }
2585: return (\@string,\$timestamp);
1.38 ng 2586: }
1.35 ng 2587:
1.44 ng 2588: #--- High light keywords, with style choosen by user.
1.38 ng 2589: sub keywords_highlight {
1.44 ng 2590: my $string = shift;
1.257 albertel 2591: my $size = $env{'form.kwsize'} eq '0' ? '' : 'size='.$env{'form.kwsize'};
2592: my $styleon = $env{'form.kwstyle'} eq '' ? '' : $env{'form.kwstyle'};
1.41 ng 2593: (my $styleoff = $styleon) =~ s/\</\<\//;
1.257 albertel 2594: my @keylist = split(/[,\s+]/,$env{'form.keywords'});
1.398 albertel 2595: foreach my $keyword (@keylist) {
2596: $string =~ s/\b\Q$keyword\E(\b|\.)/<font color\=$env{'form.kwclr'} $size\>$styleon$keyword$styleoff<\/font>/gi;
1.41 ng 2597: }
2598: return $string;
1.38 ng 2599: }
1.36 ng 2600:
1.44 ng 2601: #--- Called from submission routine
1.38 ng 2602: sub processHandGrade {
1.41 ng 2603: my ($request) = shift;
1.324 albertel 2604: my $symb = &get_symb($request);
2605: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.257 albertel 2606: my $button = $env{'form.gradeOpt'};
2607: my $ngrade = $env{'form.NCT'};
2608: my $ntstu = $env{'form.NTSTU'};
1.301 albertel 2609: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2610: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2611:
1.44 ng 2612: if ($button eq 'Save & Next') {
2613: my $ctr = 0;
2614: while ($ctr < $ngrade) {
1.257 albertel 2615: my ($uname,$udom) = split(/:/,$env{'form.unamedom'.$ctr});
1.324 albertel 2616: my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$symb,$uname,$udom,$ctr);
1.71 ng 2617: if ($errorflag eq 'no_score') {
2618: $ctr++;
2619: next;
2620: }
1.104 albertel 2621: if ($errorflag eq 'not_allowed') {
1.398 albertel 2622: $request->print("<span class=\"LC_warning\">Not allowed to modify grades for $uname:$udom</span>");
1.104 albertel 2623: $ctr++;
2624: next;
2625: }
1.257 albertel 2626: my $includemsg = $env{'form.includemsg'.$ctr};
1.44 ng 2627: my ($subject,$message,$msgstatus) = ('','','');
1.418 albertel 2628: my $restitle = &Apache::lonnet::gettitle($symb);
2629: my ($feedurl,$showsymb) =
2630: &get_feedurl_and_symb($symb,$uname,$udom);
2631: my $messagetail;
1.62 albertel 2632: if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.298 www 2633: $subject = $env{'form.msgsub'} if ($includemsg =~ /msgsub/);
1.295 www 2634: unless ($subject=~/\w/) { $subject=&mt('Grading Feedback'); }
1.386 raeburn 2635: $subject.=' ['.$restitle.']';
1.44 ng 2636: my (@msgnum) = split(/,/,$includemsg);
2637: foreach (@msgnum) {
1.257 albertel 2638: $message.=$env{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
1.44 ng 2639: }
1.80 ng 2640: $message =&Apache::lonfeedback::clear_out_html($message);
1.298 www 2641: if ($env{'form.withgrades'.$ctr}) {
2642: $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
1.386 raeburn 2643: $messagetail = " for <a href=\"".
1.418 albertel 2644: $feedurl."?symb=$showsymb\">$env{'form.probTitle'}</a>";
1.386 raeburn 2645: }
2646: $msgstatus =
2647: &Apache::lonmsg::user_normal_msg($uname,$udom,$subject,
2648: $message.$messagetail,
1.418 albertel 2649: undef,$feedurl,undef,
1.386 raeburn 2650: undef,undef,$showsymb,
2651: $restitle);
1.574 bisitz 2652: $request->print('<br />'.&mt('Sending message to [_1]',$uname.':'.$udom).': '.
1.596.2.4 raeburn 2653: $msgstatus.'<br />');
1.44 ng 2654: }
1.257 albertel 2655: if ($env{'form.collaborator'.$ctr}) {
1.155 albertel 2656: my @collabstrs=&Apache::loncommon::get_env_multiple("form.collaborator$ctr");
1.150 albertel 2657: foreach my $collabstr (@collabstrs) {
2658: my ($part,@collaborators) = split(/:/,$collabstr);
1.310 banghart 2659: foreach my $collaborator (@collaborators) {
1.150 albertel 2660: my ($errorflag,$pts,$wgt) =
1.324 albertel 2661: &saveHandGrade($request,$symb,$collaborator,$udom,$ctr,
1.257 albertel 2662: $env{'form.unamedom'.$ctr},$part);
1.150 albertel 2663: if ($errorflag eq 'not_allowed') {
1.362 albertel 2664: $request->print("<span class=\"LC_error\">".&mt('Not allowed to modify grades for [_1]',"$collaborator:$udom")."</span>");
1.150 albertel 2665: next;
1.418 albertel 2666: } elsif ($message ne '') {
2667: my ($baseurl,$showsymb) =
2668: &get_feedurl_and_symb($symb,$collaborator,
2669: $udom);
2670: if ($env{'form.withgrades'.$ctr}) {
2671: $messagetail = " for <a href=\"".
1.386 raeburn 2672: $baseurl."?symb=$showsymb\">$env{'form.probTitle'}</a>";
1.150 albertel 2673: }
1.418 albertel 2674: $msgstatus =
2675: &Apache::lonmsg::user_normal_msg($collaborator,$udom,$subject,$message.$messagetail,undef,$baseurl,undef,undef,undef,$showsymb,$restitle);
1.104 albertel 2676: }
1.44 ng 2677: }
2678: }
2679: }
2680: $ctr++;
2681: }
2682: }
2683:
1.257 albertel 2684: if ($env{'form.handgrade'} eq 'yes') {
1.119 ng 2685: # Keywords sorted in alphabatical order
1.257 albertel 2686: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1.119 ng 2687: my %keyhash = ();
1.257 albertel 2688: $env{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
2689: $env{'form.keywords'} =~ s/^\s+|\s+$//;
2690: my (@keywords) = sort(split(/\s+/,$env{'form.keywords'}));
2691: $env{'form.keywords'} = join(' ',@keywords);
2692: $keyhash{$symb.'_keywords'} = $env{'form.keywords'};
2693: $keyhash{$symb.'_subject'} = $env{'form.msgsub'};
2694: $keyhash{$loginuser.'_kwclr'} = $env{'form.kwclr'};
2695: $keyhash{$loginuser.'_kwsize'} = $env{'form.kwsize'};
2696: $keyhash{$loginuser.'_kwstyle'} = $env{'form.kwstyle'};
1.119 ng 2697:
2698: # message center - Order of message gets changed. Blank line is eliminated.
1.257 albertel 2699: # New messages are saved in env for the next student.
1.119 ng 2700: # All messages are saved in nohist_handgrade.db
2701: my ($ctr,$idx) = (1,1);
1.257 albertel 2702: while ($ctr <= $env{'form.savemsgN'}) {
2703: if ($env{'form.savemsg'.$ctr} ne '') {
2704: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.savemsg'.$ctr};
1.119 ng 2705: $idx++;
2706: }
2707: $ctr++;
1.41 ng 2708: }
1.119 ng 2709: $ctr = 0;
2710: while ($ctr < $ngrade) {
1.257 albertel 2711: if ($env{'form.newmsg'.$ctr} ne '') {
2712: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.newmsg'.$ctr};
2713: $env{'form.savemsg'.$idx} = $env{'form.newmsg'.$ctr};
1.119 ng 2714: $idx++;
2715: }
2716: $ctr++;
1.41 ng 2717: }
1.257 albertel 2718: $env{'form.savemsgN'} = --$idx;
2719: $keyhash{$symb.'_savemsgN'} = $env{'form.savemsgN'};
1.119 ng 2720: my $putresult = &Apache::lonnet::put
1.301 albertel 2721: ('nohist_handgrade',\%keyhash,$cdom,$cnum);
1.41 ng 2722: }
1.44 ng 2723: # Called by Save & Refresh from Highlight Attribute Window
1.257 albertel 2724: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
2725: if ($env{'form.refresh'} eq 'on') {
1.86 ng 2726: my ($ctr,$total) = (0,0);
2727: while ($ctr < $ngrade) {
1.257 albertel 2728: $total++ if $env{'form.unamedom'.$ctr} ne '';
1.86 ng 2729: $ctr++;
2730: }
1.257 albertel 2731: $env{'form.NTSTU'}=$ngrade;
1.86 ng 2732: $ctr = 0;
2733: while ($ctr < $total) {
1.257 albertel 2734: my $processUser = $env{'form.unamedom'.$ctr};
2735: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2736: $env{'form.fullname'} = $$fullname{$processUser};
1.86 ng 2737: &submission($request,$ctr,$total-1);
1.41 ng 2738: $ctr++;
2739: }
2740: return '';
2741: }
1.36 ng 2742:
1.121 ng 2743: # Go directly to grade student - from submission or link from chart page
1.120 ng 2744: if ($button eq 'Grade Student') {
1.324 albertel 2745: (undef,undef,$env{'form.handgrade'},undef,undef) = &showResourceInfo($symb);
1.257 albertel 2746: my $processUser = $env{'form.unamedom'.$env{'form.studentNo'}};
2747: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2748: $env{'form.fullname'} = $$fullname{$processUser};
1.120 ng 2749: &submission($request,0,0);
2750: return '';
2751: }
2752:
1.44 ng 2753: # Get the next/previous one or group of students
1.257 albertel 2754: my $firststu = $env{'form.unamedom0'};
2755: my $laststu = $env{'form.unamedom'.($ngrade-1)};
1.119 ng 2756: my $ctr = 2;
1.41 ng 2757: while ($laststu eq '') {
1.257 albertel 2758: $laststu = $env{'form.unamedom'.($ngrade-$ctr)};
1.41 ng 2759: $ctr++;
2760: $laststu = $firststu if ($ctr > $ngrade);
2761: }
1.44 ng 2762:
1.41 ng 2763: my (@parsedlist,@nextlist);
2764: my ($nextflg) = 0;
1.524 raeburn 2765: foreach my $item (sort
1.294 albertel 2766: {
2767: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
2768: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
2769: }
2770: return $a cmp $b;
2771: } (keys(%$fullname))) {
1.41 ng 2772: if ($nextflg == 1 && $button =~ /Next$/) {
1.524 raeburn 2773: push(@parsedlist,$item);
1.41 ng 2774: }
1.524 raeburn 2775: $nextflg = 1 if ($item eq $laststu);
1.41 ng 2776: if ($button eq 'Previous') {
1.524 raeburn 2777: last if ($item eq $firststu);
2778: push(@parsedlist,$item);
1.41 ng 2779: }
2780: }
2781: $ctr = 0;
2782: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
1.582 raeburn 2783: my $res_error;
2784: my ($partlist) = &response_type($symb,\$res_error);
2785: if ($res_error) {
2786: $request->print(&navmap_errormsg());
2787: return;
2788: }
1.41 ng 2789: foreach my $student (@parsedlist) {
1.257 albertel 2790: my $submitonly=$env{'form.submitonly'};
1.41 ng 2791: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 2792:
2793: if ($submitonly eq 'queued') {
2794: my %queue_status =
2795: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
2796: $udom,$uname);
2797: next if (!defined($queue_status{'gradingqueue'}));
2798: }
2799:
1.156 albertel 2800: if ($submitonly =~ /^(yes|graded|incorrect)$/) {
1.257 albertel 2801: # my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 2802: my %status=&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 2803: my $submitted = 0;
1.248 albertel 2804: my $ungraded = 0;
2805: my $incorrect = 0;
1.524 raeburn 2806: foreach my $item (keys(%status)) {
2807: $submitted = 1 if ($status{$item} ne 'nothing');
2808: $ungraded = 1 if ($status{$item} =~ /^ungraded/);
2809: $incorrect = 1 if ($status{$item} =~ /^incorrect/);
2810: my ($foo,$partid,$foo1) = split(/\./,$item);
1.145 albertel 2811: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
2812: $submitted = 0;
2813: }
1.41 ng 2814: }
1.156 albertel 2815: next if (!$submitted && ($submitonly eq 'yes' ||
2816: $submitonly eq 'incorrect' ||
2817: $submitonly eq 'graded'));
1.248 albertel 2818: next if (!$ungraded && ($submitonly eq 'graded'));
2819: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 2820: }
1.524 raeburn 2821: push(@nextlist,$student) if ($ctr < $ntstu);
1.129 ng 2822: last if ($ctr == $ntstu);
1.41 ng 2823: $ctr++;
2824: }
1.36 ng 2825:
1.41 ng 2826: $ctr = 0;
2827: my $total = scalar(@nextlist)-1;
1.39 ng 2828:
1.524 raeburn 2829: foreach (sort(@nextlist)) {
1.41 ng 2830: my ($uname,$udom,$submitter) = split(/:/);
1.257 albertel 2831: $env{'form.student'} = $uname;
2832: $env{'form.userdom'} = $udom;
2833: $env{'form.fullname'} = $$fullname{$_};
1.41 ng 2834: &submission($request,$ctr,$total);
2835: $ctr++;
2836: }
2837: if ($total < 0) {
1.485 albertel 2838: my $the_end = '<h3><span class="LC_info">'.&mt('LON-CAPA User Message').'</span></h3><br />'."\n";
1.596.2.4 raeburn 2839: $the_end.='<p>'.&mt('[_1]Message:[_2] No more students for this section or class.','<b>','</b>').'</p>'."\n";
1.485 albertel 2840: $the_end.=&mt('Click on the button below to return to the grading menu.').'<br /><br />'."\n";
1.324 albertel 2841: $the_end.=&show_grading_menu_form($symb);
1.41 ng 2842: $request->print($the_end);
2843: }
2844: return '';
1.38 ng 2845: }
1.36 ng 2846:
1.44 ng 2847: #---- Save the score and award for each student, if changed
1.38 ng 2848: sub saveHandGrade {
1.324 albertel 2849: my ($request,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
1.342 banghart 2850: my @version_parts;
1.104 albertel 2851: my $usec = &Apache::lonnet::getsection($domain,$stuname,
1.257 albertel 2852: $env{'request.course.id'});
1.104 albertel 2853: if (!&canmodify($usec)) { return('not_allowed'); }
1.337 banghart 2854: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
1.251 banghart 2855: my @parts_graded;
1.77 ng 2856: my %newrecord = ();
2857: my ($pts,$wgt) = ('','');
1.269 raeburn 2858: my %aggregate = ();
2859: my $aggregateflag = 0;
1.301 albertel 2860: my @parts = split(/:/,$env{'form.partlist'.$newflg});
2861: foreach my $new_part (@parts) {
1.337 banghart 2862: #collaborator ($submi may vary for different parts
1.259 banghart 2863: if ($submitter && $new_part ne $part) { next; }
2864: my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
1.125 ng 2865: if ($dropMenu eq 'excused') {
1.259 banghart 2866: if ($record{'resource.'.$new_part.'.solved'} ne 'excused') {
2867: $newrecord{'resource.'.$new_part.'.solved'} = 'excused';
2868: if (exists($record{'resource.'.$new_part.'.awarded'})) {
2869: $newrecord{'resource.'.$new_part.'.awarded'} = '';
1.58 albertel 2870: }
1.364 banghart 2871: $newrecord{'resource.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.58 albertel 2872: }
1.125 ng 2873: } elsif ($dropMenu eq 'reset status'
1.259 banghart 2874: && exists($record{'resource.'.$new_part.'.solved'})) { #don't bother if no old records -> no attempts
1.524 raeburn 2875: foreach my $key (keys(%record)) {
1.259 banghart 2876: if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
1.197 albertel 2877: }
1.259 banghart 2878: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2879: "$env{'user.name'}:$env{'user.domain'}";
1.270 albertel 2880: my $totaltries = $record{'resource.'.$part.'.tries'};
2881:
2882: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
2883: [$new_part]);
2884: my $aggtries =$totaltries;
1.269 raeburn 2885: if ($last_resets{$new_part}) {
1.270 albertel 2886: $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
2887: $new_part);
1.269 raeburn 2888: }
1.270 albertel 2889:
2890: my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
1.269 raeburn 2891: if ($aggtries > 0) {
1.327 albertel 2892: &decrement_aggs($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
1.269 raeburn 2893: $aggregateflag = 1;
2894: }
1.125 ng 2895: } elsif ($dropMenu eq '') {
1.259 banghart 2896: $pts = ($env{'form.GD_BOX'.$newflg.'_'.$new_part} ne '' ?
2897: $env{'form.GD_BOX'.$newflg.'_'.$new_part} :
2898: $env{'form.RADVAL'.$newflg.'_'.$new_part});
2899: if ($pts eq '' && $env{'form.GD_SEL'.$newflg.'_'.$new_part} eq '') {
1.153 albertel 2900: next;
2901: }
1.259 banghart 2902: $wgt = $env{'form.WGT'.$newflg.'_'.$new_part} eq '' ? 1 :
2903: $env{'form.WGT'.$newflg.'_'.$new_part};
1.41 ng 2904: my $partial= $pts/$wgt;
1.259 banghart 2905: if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
1.153 albertel 2906: #do not update score for part if not changed.
1.346 banghart 2907: &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
1.153 albertel 2908: next;
1.251 banghart 2909: } else {
1.524 raeburn 2910: push(@parts_graded,$new_part);
1.153 albertel 2911: }
1.259 banghart 2912: if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
2913: $newrecord{'resource.'.$new_part.'.awarded'} = $partial;
1.153 albertel 2914: }
1.259 banghart 2915: my $reckey = 'resource.'.$new_part.'.solved';
1.41 ng 2916: if ($partial == 0) {
1.153 albertel 2917: if ($record{$reckey} ne 'incorrect_by_override') {
2918: $newrecord{$reckey} = 'incorrect_by_override';
2919: }
1.41 ng 2920: } else {
1.153 albertel 2921: if ($record{$reckey} ne 'correct_by_override') {
2922: $newrecord{$reckey} = 'correct_by_override';
2923: }
2924: }
2925: if ($submitter &&
1.259 banghart 2926: ($record{'resource.'.$new_part.'.submitted_by'} ne $submitter)) {
2927: $newrecord{'resource.'.$new_part.'.submitted_by'} = $submitter;
1.41 ng 2928: }
1.259 banghart 2929: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2930: "$env{'user.name'}:$env{'user.domain'}";
1.41 ng 2931: }
1.259 banghart 2932: # unless problem has been graded, set flag to version the submitted files
1.305 banghart 2933: unless ($record{'resource.'.$new_part.'.solved'} =~ /^correct_/ ||
2934: $record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override' ||
2935: $dropMenu eq 'reset status')
2936: {
1.524 raeburn 2937: push(@version_parts,$new_part);
1.259 banghart 2938: }
1.41 ng 2939: }
1.301 albertel 2940: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2941: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2942:
1.344 albertel 2943: if (%newrecord) {
2944: if (@version_parts) {
1.364 banghart 2945: my @changed_keys = &version_portfiles(\%record, \@parts_graded,
2946: $env{'request.course.id'}, $symb, $domain, $stuname, \@version_parts);
1.344 albertel 2947: @newrecord{@changed_keys} = @record{@changed_keys};
1.367 albertel 2948: foreach my $new_part (@version_parts) {
2949: &handback_files($request,$symb,$stuname,$domain,$newflg,
2950: $new_part,\%newrecord);
2951: }
1.259 banghart 2952: }
1.44 ng 2953: &Apache::lonnet::cstore(\%newrecord,$symb,
1.257 albertel 2954: $env{'request.course.id'},$domain,$stuname);
1.380 albertel 2955: &check_and_remove_from_queue(\@parts,\%record,\%newrecord,$symb,
2956: $cdom,$cnum,$domain,$stuname);
1.41 ng 2957: }
1.269 raeburn 2958: if ($aggregateflag) {
2959: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 2960: $cdom,$cnum);
1.269 raeburn 2961: }
1.301 albertel 2962: return ('',$pts,$wgt);
1.36 ng 2963: }
1.322 albertel 2964:
1.380 albertel 2965: sub check_and_remove_from_queue {
2966: my ($parts,$record,$newrecord,$symb,$cdom,$cnum,$domain,$stuname) = @_;
2967: my @ungraded_parts;
2968: foreach my $part (@{$parts}) {
2969: if ( $record->{ 'resource.'.$part.'.awarded'} eq ''
2970: && $record->{ 'resource.'.$part.'.solved' } ne 'excused'
2971: && $newrecord->{'resource.'.$part.'.awarded'} eq ''
2972: && $newrecord->{'resource.'.$part.'.solved' } ne 'excused'
2973: ) {
2974: push(@ungraded_parts, $part);
2975: }
2976: }
2977: if ( !@ungraded_parts ) {
2978: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,
2979: $cnum,$domain,$stuname);
2980: }
2981: }
2982:
1.337 banghart 2983: sub handback_files {
2984: my ($request,$symb,$stuname,$domain,$newflg,$new_part,$newrecord) = @_;
1.517 raeburn 2985: my $portfolio_root = '/userfiles/portfolio';
1.582 raeburn 2986: my $res_error;
2987: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
2988: if ($res_error) {
2989: $request->print('<br />'.&navmap_errormsg().'<br />');
2990: return;
2991: }
1.596.2.4 raeburn 2992: my @handedback;
2993: my $file_msg;
1.375 albertel 2994: my @part_response_id = &flatten_responseType($responseType);
2995: foreach my $part_response_id (@part_response_id) {
2996: my ($part_id,$resp_id) = @{ $part_response_id };
2997: my $part_resp = join('_',@{ $part_response_id });
1.596.2.4 raeburn 2998: if (($env{'form.'.$newflg.'_'.$part_resp.'_countreturndoc'} =~ /^\d+$/) & ($new_part eq $part_id)) {
2999: for (my $counter=1; $counter<=$env{'form.'.$newflg.'_'.$part_resp.'_countreturndoc'}; $counter++) {
1.337 banghart 3000: # if multiple files are uploaded names will be 'returndoc2','returndoc3'
1.596.2.4 raeburn 3001: if ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$counter}) {
3002: my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$counter.'.filename'};
1.338 banghart 3003: my ($directory,$answer_file) =
1.596.2.4 raeburn 3004: ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$counter} =~ /^(.*?)([^\/]*)$/);
1.338 banghart 3005: my ($answer_name,$answer_ver,$answer_ext) =
3006: &file_name_version_ext($answer_file);
1.355 banghart 3007: my ($portfolio_path) = ($directory =~ /^.+$stuname\/portfolio(.*)/);
1.517 raeburn 3008: my $getpropath = 1;
3009: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$portfolio_path,$domain,$stuname,$getpropath);
1.338 banghart 3010: my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
1.355 banghart 3011: # fix file name
3012: my ($save_file_name) = (($directory.$answer_name.".$version.".$answer_ext) =~ /^.+\/${stuname}\/(.*)/);
3013: my $result=&Apache::lonnet::finishuserfileupload($stuname,$domain,
1.596.2.4 raeburn 3014: $newflg.'_'.$part_resp.'_returndoc'.$counter,
1.355 banghart 3015: $save_file_name);
1.337 banghart 3016: if ($result !~ m|^/uploaded/|) {
1.536 raeburn 3017: $request->print('<br /><span class="LC_error">'.
3018: &mt('An error occurred ([_1]) while trying to upload [_2].',
1.596.2.4 raeburn 3019: $result,$newflg.'_'.$part_resp.'_returndoc'.$counter).
1.536 raeburn 3020: '</span>');
1.356 banghart 3021: } else {
1.360 banghart 3022: # mark the file as read only
1.596.2.4 raeburn 3023: push(@handedback,$save_file_name);
1.367 albertel 3024: if (exists($$newrecord{"resource.$new_part.$resp_id.handback"})) {
3025: $$newrecord{"resource.$new_part.$resp_id.handback"}.=',';
3026: }
3027: $$newrecord{"resource.$new_part.$resp_id.handback"} .= $save_file_name;
1.596.2.4 raeburn 3028: $file_msg.='<span class="LC_filename"><a href="/uploaded/'."$domain/$stuname/".$save_file_name.'">'.$save_file_name."</a></span> <br />";
1.367 albertel 3029:
1.337 banghart 3030: }
1.596.2.4 raeburn 3031: $request->print('<br />'.&mt('[_1] will be the uploaded file name [_2]','<span class="LC_info">'.$fname.'</span>','<span class="LC_filename">'.$env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$counter}.'</span>'));
1.337 banghart 3032: }
3033: }
3034: }
1.596.2.4 raeburn 3035: }
3036: if (@handedback > 0) {
3037: $request->print('<br />');
3038: my @what = ($symb,$env{'request.course.id'},'handback');
3039: &Apache::lonnet::mark_as_readonly($domain,$stuname,\@handedback,\@what);
3040: my $user_lh = &Apache::loncommon::user_lang($stuname,$domain,$env{'request.course.id'});
3041: my ($subject,$message);
3042: if (scalar(@handedback) == 1) {
3043: $subject = &mt_user($user_lh,'File Handed Back by Instructor');
3044: } else {
3045: $subject = &mt_user($user_lh,'Files Handed Back by Instructor');
3046: $message = &mt_user($user_lh,'Files have been returned that were originally submitted in response to: ');
3047: }
3048: $message .= "<p><strong>".&Apache::lonnet::gettitle($symb)." </strong></p>";
3049: $message .= &mt_user($user_lh,'The returned file(s) are named: [_1]',"<br />$file_msg <br />").
3050: &mt_user($user_lh,'The file(s) can be found in your [_1]portfolio[_2].','<a href="/adm/portfolio">','</a>');
3051: my ($feedurl,$showsymb) =
3052: &get_feedurl_and_symb($symb,$domain,$stuname);
3053: my $restitle = &Apache::lonnet::gettitle($symb);
3054: $subject .= ' '.&mt_user($user_lh,'(File Returned)').' ['.$restitle.']';
3055: my $msgstatus =
3056: &Apache::lonmsg::user_normal_msg($stuname,$domain,$subject,
3057: $message,undef,$feedurl,undef,undef,undef,$showsymb,
3058: $restitle);
3059: if ($msgstatus) {
3060: $request->print(&mt('Notification message status: [_1]','<span class="LC_info">'.$msgstatus.'</span>').'<br />');
3061: }
3062: }
1.338 banghart 3063: return;
1.337 banghart 3064: }
3065:
1.418 albertel 3066: sub get_feedurl_and_symb {
3067: my ($symb,$uname,$udom) = @_;
3068: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
3069: $url = &Apache::lonnet::clutter($url);
3070: my $encrypturl=&Apache::lonnet::EXT('resource.0.encrypturl',
3071: $symb,$udom,$uname);
3072: if ($encrypturl =~ /^yes$/i) {
3073: &Apache::lonenc::encrypted(\$url,1);
3074: &Apache::lonenc::encrypted(\$symb,1);
3075: }
3076: return ($url,$symb);
3077: }
3078:
1.313 banghart 3079: sub get_submitted_files {
3080: my ($udom,$uname,$partid,$respid,$record) = @_;
3081: my @files;
3082: if ($$record{"resource.$partid.$respid.portfiles"}) {
3083: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
3084: foreach my $file (split(',',$$record{"resource.$partid.$respid.portfiles"})) {
3085: push(@files,$file_url.$file);
3086: }
3087: }
3088: if ($$record{"resource.$partid.$respid.uploadedurl"}) {
3089: push(@files,$$record{"resource.$partid.$respid.uploadedurl"});
3090: }
3091: return (\@files);
3092: }
1.322 albertel 3093:
1.269 raeburn 3094: # ----------- Provides number of tries since last reset.
3095: sub get_num_tries {
3096: my ($record,$last_reset,$part) = @_;
3097: my $timestamp = '';
3098: my $num_tries = 0;
3099: if ($$record{'version'}) {
3100: for (my $version=$$record{'version'};$version>=1;$version--) {
3101: if (exists($$record{$version.':resource.'.$part.'.solved'})) {
3102: $timestamp = $$record{$version.':timestamp'};
3103: if ($timestamp > $last_reset) {
3104: $num_tries ++;
3105: } else {
3106: last;
3107: }
3108: }
3109: }
3110: }
3111: return $num_tries;
3112: }
3113:
3114: # ----------- Determine decrements required in aggregate totals
3115: sub decrement_aggs {
3116: my ($symb,$part,$aggregate,$aggtries,$totaltries,$solvedstatus) = @_;
3117: my %decrement = (
3118: attempts => 0,
3119: users => 0,
3120: correct => 0
3121: );
3122: $decrement{'attempts'} = $aggtries;
3123: if ($solvedstatus =~ /^correct/) {
3124: $decrement{'correct'} = 1;
3125: }
3126: if ($aggtries == $totaltries) {
3127: $decrement{'users'} = 1;
3128: }
1.524 raeburn 3129: foreach my $type (keys(%decrement)) {
1.269 raeburn 3130: $$aggregate{$symb."\0".$part."\0".$type} = -$decrement{$type};
3131: }
3132: return;
3133: }
3134:
3135: # ----------- Determine timestamps for last reset of aggregate totals for parts
3136: sub get_last_resets {
1.270 albertel 3137: my ($symb,$courseid,$partids) =@_;
3138: my %last_resets;
1.269 raeburn 3139: my $cdom = $env{'course.'.$courseid.'.domain'};
3140: my $cname = $env{'course.'.$courseid.'.num'};
1.271 albertel 3141: my @keys;
3142: foreach my $part (@{$partids}) {
3143: push(@keys,"$symb\0$part\0resettime");
3144: }
3145: my %results=&Apache::lonnet::get('nohist_resourcetracker',\@keys,
3146: $cdom,$cname);
3147: foreach my $part (@{$partids}) {
3148: $last_resets{$part}=$results{"$symb\0$part\0resettime"};
1.269 raeburn 3149: }
1.270 albertel 3150: return %last_resets;
1.269 raeburn 3151: }
3152:
1.251 banghart 3153: # ----------- Handles creating versions for portfolio files as answers
3154: sub version_portfiles {
1.343 banghart 3155: my ($record, $parts_graded, $courseid, $symb, $domain, $stu_name, $v_flag) = @_;
1.263 banghart 3156: my $version_parts = join('|',@$v_flag);
1.343 banghart 3157: my @returned_keys;
1.255 banghart 3158: my $parts = join('|', @$parts_graded);
1.517 raeburn 3159: my $portfolio_root = '/userfiles/portfolio';
1.277 albertel 3160: foreach my $key (keys(%$record)) {
1.259 banghart 3161: my $new_portfiles;
1.263 banghart 3162: if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
1.342 banghart 3163: my @versioned_portfiles;
1.367 albertel 3164: my @portfiles = split(/\s*,\s*/,$$record{$key});
1.252 banghart 3165: foreach my $file (@portfiles) {
1.306 banghart 3166: &Apache::lonnet::unmark_as_readonly($domain,$stu_name,[$symb,$env{'request.course.id'}],$file);
1.304 albertel 3167: my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*)$/);
3168: my ($answer_name,$answer_ver,$answer_ext) =
3169: &file_name_version_ext($answer_file);
1.517 raeburn 3170: my $getpropath = 1;
3171: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$directory,$domain,$stu_name,$getpropath);
1.342 banghart 3172: my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
1.306 banghart 3173: my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version);
3174: if ($new_answer ne 'problem getting file') {
1.342 banghart 3175: push(@versioned_portfiles, $directory.$new_answer);
1.306 banghart 3176: &Apache::lonnet::mark_as_readonly($domain,$stu_name,
1.367 albertel 3177: [$directory.$new_answer],
1.306 banghart 3178: [$symb,$env{'request.course.id'},'graded']);
1.259 banghart 3179: }
1.252 banghart 3180: }
1.343 banghart 3181: $$record{$key} = join(',',@versioned_portfiles);
3182: push(@returned_keys,$key);
1.251 banghart 3183: }
3184: }
1.343 banghart 3185: return (@returned_keys);
1.305 banghart 3186: }
3187:
1.307 banghart 3188: sub get_next_version {
1.341 banghart 3189: my ($answer_name, $answer_ext, $dir_list) = @_;
1.307 banghart 3190: my $version;
3191: foreach my $row (@$dir_list) {
3192: my ($file) = split(/\&/,$row,2);
3193: my ($file_name,$file_version,$file_ext) =
3194: &file_name_version_ext($file);
3195: if (($file_name eq $answer_name) &&
3196: ($file_ext eq $answer_ext)) {
3197: # gets here if filename and extension match, regardless of version
3198: if ($file_version ne '') {
3199: # a versioned file is found so save it for later
3200: if ($file_version > $version) {
3201: $version = $file_version;
3202: }
3203: }
3204: }
3205: }
3206: $version ++;
3207: return($version);
3208: }
3209:
1.305 banghart 3210: sub version_selected_portfile {
1.306 banghart 3211: my ($domain,$stu_name,$directory,$file_name,$version) = @_;
3212: my ($answer_name,$answer_ver,$answer_ext) =
3213: &file_name_version_ext($file_name);
3214: my $new_answer;
3215: $env{'form.copy'} = &Apache::lonnet::getfile("/uploaded/$domain/$stu_name/portfolio$directory$file_name");
3216: if($env{'form.copy'} eq '-1') {
3217: $new_answer = 'problem getting file';
3218: } else {
3219: $new_answer = $answer_name.'.'.$version.'.'.$answer_ext;
3220: my $copy_result = &Apache::lonnet::finishuserfileupload(
3221: $stu_name,$domain,'copy',
3222: '/portfolio'.$directory.$new_answer);
3223: }
3224: return ($new_answer);
1.251 banghart 3225: }
3226:
1.304 albertel 3227: sub file_name_version_ext {
3228: my ($file)=@_;
3229: my @file_parts = split(/\./, $file);
3230: my ($name,$version,$ext);
3231: if (@file_parts > 1) {
3232: $ext=pop(@file_parts);
3233: if (@file_parts > 1 && $file_parts[-1] =~ /^\d+$/) {
3234: $version=pop(@file_parts);
3235: }
3236: $name=join('.',@file_parts);
3237: } else {
3238: $name=join('.',@file_parts);
3239: }
3240: return($name,$version,$ext);
3241: }
3242:
1.44 ng 3243: #--------------------------------------------------------------------------------------
3244: #
3245: #-------------------------- Next few routines handles grading by section or whole class
3246: #
3247: #--- Javascript to handle grading by section or whole class
1.42 ng 3248: sub viewgrades_js {
3249: my ($request) = shift;
3250:
1.539 riegler 3251: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
1.41 ng 3252: $request->print(<<VIEWJAVASCRIPT);
3253: <script type="text/javascript" language="javascript">
1.45 ng 3254: function writePoint(partid,weight,point) {
1.125 ng 3255: var radioButton = document.classgrade["RADVAL_"+partid];
3256: var textbox = document.classgrade["TEXTVAL_"+partid];
1.42 ng 3257: if (point == "textval") {
1.125 ng 3258: point = document.classgrade["TEXTVAL_"+partid].value;
1.109 matthew 3259: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 3260: alert("$alertmsg"+parseFloat(point));
1.42 ng 3261: var resetbox = false;
3262: for (var i=0; i<radioButton.length; i++) {
3263: if (radioButton[i].checked) {
3264: textbox.value = i;
3265: resetbox = true;
3266: }
3267: }
3268: if (!resetbox) {
3269: textbox.value = "";
3270: }
3271: return;
3272: }
1.109 matthew 3273: if (parseFloat(point) > parseFloat(weight)) {
3274: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 3275: ") greater than the weight for the part. Accept?");
3276: if (resp == false) {
3277: textbox.value = "";
3278: return;
3279: }
3280: }
1.42 ng 3281: for (var i=0; i<radioButton.length; i++) {
3282: radioButton[i].checked=false;
1.109 matthew 3283: if (parseFloat(point) == i) {
1.42 ng 3284: radioButton[i].checked=true;
3285: }
3286: }
1.41 ng 3287:
1.42 ng 3288: } else {
1.125 ng 3289: textbox.value = parseFloat(point);
1.42 ng 3290: }
1.41 ng 3291: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3292: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3293: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3294: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3295: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3296: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 3297: if (saveval != "correct") {
3298: scorename.value = point;
1.43 ng 3299: if (selname[0].selected != true) {
3300: selname[0].selected = true;
3301: }
1.42 ng 3302: }
3303: }
1.125 ng 3304: document.classgrade["SELVAL_"+partid][0].selected = true;
1.42 ng 3305: }
3306:
3307: function writeRadText(partid,weight) {
1.125 ng 3308: var selval = document.classgrade["SELVAL_"+partid];
3309: var radioButton = document.classgrade["RADVAL_"+partid];
1.265 www 3310: var override = document.classgrade["FORCE_"+partid].checked;
1.125 ng 3311: var textbox = document.classgrade["TEXTVAL_"+partid];
3312: if (selval[1].selected || selval[2].selected) {
1.42 ng 3313: for (var i=0; i<radioButton.length; i++) {
3314: radioButton[i].checked=false;
3315:
3316: }
3317: textbox.value = "";
3318:
3319: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3320: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3321: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3322: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3323: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3324: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 3325: if ((saveval != "correct") || override) {
1.42 ng 3326: scorename.value = "";
1.125 ng 3327: if (selval[1].selected) {
3328: selname[1].selected = true;
3329: } else {
3330: selname[2].selected = true;
3331: if (Number(document.classgrade["GD_"+user+"_"+partid+"_tries"].value))
3332: {document.classgrade["GD_"+user+"_"+partid+"_tries"].value = '0';}
3333: }
1.42 ng 3334: }
3335: }
1.43 ng 3336: } else {
3337: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3338: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3339: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3340: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3341: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3342: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 3343: if ((saveval != "correct") || override) {
1.125 ng 3344: scorename.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
1.43 ng 3345: selname[0].selected = true;
3346: }
3347: }
3348: }
1.42 ng 3349: }
3350:
3351: function changeSelect(partid,user) {
1.125 ng 3352: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
3353: var textbox = document.classgrade["GD_"+user+'_'+partid+"_awarded"];
1.44 ng 3354: var point = textbox.value;
1.125 ng 3355: var weight = document.classgrade["weight_"+partid].value;
1.44 ng 3356:
1.109 matthew 3357: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 3358: alert("$alertmsg"+parseFloat(point));
1.44 ng 3359: textbox.value = "";
3360: return;
3361: }
1.109 matthew 3362: if (parseFloat(point) > parseFloat(weight)) {
3363: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 3364: ") greater than the weight of the part. Accept?");
3365: if (resp == false) {
3366: textbox.value = "";
3367: return;
3368: }
3369: }
1.42 ng 3370: selval[0].selected = true;
3371: }
3372:
3373: function changeOneScore(partid,user) {
1.125 ng 3374: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
3375: if (selval[1].selected || selval[2].selected) {
3376: document.classgrade["GD_"+user+'_'+partid+"_awarded"].value = "";
3377: if (selval[2].selected) {
3378: document.classgrade["GD_"+user+'_'+partid+"_tries"].value = "0";
3379: }
1.269 raeburn 3380: }
1.42 ng 3381: }
3382:
3383: function resetEntry(numpart) {
3384: for (ctpart=0;ctpart<numpart;ctpart++) {
1.125 ng 3385: var partid = document.classgrade["partid_"+ctpart].value;
3386: var radioButton = document.classgrade["RADVAL_"+partid];
3387: var textbox = document.classgrade["TEXTVAL_"+partid];
3388: var selval = document.classgrade["SELVAL_"+partid];
1.42 ng 3389: for (var i=0; i<radioButton.length; i++) {
3390: radioButton[i].checked=false;
3391:
3392: }
3393: textbox.value = "";
3394: selval[0].selected = true;
3395:
3396: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3397: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3398: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3399: var resetscore = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3400: resetscore.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
3401: var resettries = document.classgrade["GD_"+user+"_"+partid+"_tries"];
3402: resettries.value = document.classgrade["GD_"+user+"_"+partid+"_tries_s"].value;
3403: var saveselval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3404: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 3405: if (saveselval == "excused") {
1.43 ng 3406: if (selname[1].selected == false) { selname[1].selected = true;}
1.42 ng 3407: } else {
1.43 ng 3408: if (selname[0].selected == false) {selname[0].selected = true};
1.42 ng 3409: }
3410: }
1.41 ng 3411: }
1.42 ng 3412: }
3413:
1.41 ng 3414: </script>
3415: VIEWJAVASCRIPT
1.42 ng 3416: }
3417:
1.44 ng 3418: #--- show scores for a section or whole class w/ option to change/update a score
1.42 ng 3419: sub viewgrades {
3420: my ($request) = shift;
3421: &viewgrades_js($request);
1.41 ng 3422:
1.324 albertel 3423: my ($symb) = &get_symb($request);
1.168 albertel 3424: #need to make sure we have the correct data for later EXT calls,
3425: #thus invalidate the cache
3426: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 3427: $env{'course.'.$env{'request.course.id'}.'.num'},
3428: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 3429: &Apache::lonnet::clear_EXT_cache_status();
3430:
1.398 albertel 3431: my $result='<h3><span class="LC_info">'.&mt('Manual Grading').'</span></h3>';
1.485 albertel 3432: $result.='<h4>'.&mt('<b>Current Resource: </b>[_1]',$env{'form.probTitle'}).'</h4>'."\n";
1.41 ng 3433:
3434: #view individual student submission form - called using Javascript viewOneStudent
1.324 albertel 3435: $result.=&jscriptNform($symb);
1.41 ng 3436:
1.44 ng 3437: #beginning of class grading form
1.442 banghart 3438: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.41 ng 3439: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1.418 albertel 3440: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.38 ng 3441: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.432 banghart 3442: &build_section_inputs().
1.257 albertel 3443: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.442 banghart 3444: '<input type="hidden" name="Status" value="'.$env{'stu_status'}.'" />'."\n".
1.257 albertel 3445: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.72 ng 3446:
1.560 raeburn 3447: my ($common_header,$specific_header);
1.257 albertel 3448: if ($env{'form.section'} eq 'all') {
1.560 raeburn 3449: $common_header = &mt('Assign Common Grade to Class');
3450: $specific_header = &mt('Assign Grade to Specific Students in Class');
1.257 albertel 3451: } elsif ($env{'form.section'} eq 'none') {
1.560 raeburn 3452: $common_header = &mt('Assign Common Grade to Students in no Section');
3453: $specific_header = &mt('Assign Grade to Specific Students in no Section');
1.52 albertel 3454: } else {
1.560 raeburn 3455: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
3456: $common_header = &mt('Assign Common Grade to Students in Section(s) [_1]',$section_display);
3457: $specific_header = &mt('Assign Grade to Specific Students in Section(s) [_1]',$section_display);
1.52 albertel 3458: }
1.560 raeburn 3459: $result.= '<h3>'.$common_header.'</h3>'.&Apache::loncommon::start_data_table();
1.44 ng 3460: #radio buttons/text box for assigning points for a section or class.
3461: #handles different parts of a problem
1.582 raeburn 3462: my $res_error;
3463: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
3464: if ($res_error) {
3465: return &navmap_errormsg();
3466: }
1.42 ng 3467: my %weight = ();
3468: my $ctsparts = 0;
1.45 ng 3469: my %seen = ();
1.375 albertel 3470: my @part_response_id = &flatten_responseType($responseType);
3471: foreach my $part_response_id (@part_response_id) {
3472: my ($partid,$respid) = @{ $part_response_id };
3473: my $part_resp = join('_',@{ $part_response_id });
1.45 ng 3474: next if $seen{$partid};
3475: $seen{$partid}++;
1.375 albertel 3476: my $handgrade=$$handgrade{$part_resp};
1.42 ng 3477: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
3478: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
3479:
1.324 albertel 3480: my $display_part=&get_display_part($partid,$symb);
1.485 albertel 3481: my $radio.='<table border="0"><tr>';
1.41 ng 3482: my $ctr = 0;
1.42 ng 3483: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
1.485 albertel 3484: $radio.= '<td><label><input type="radio" name="RADVAL_'.$partid.'" '.
1.54 albertel 3485: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.288 albertel 3486: ','.$ctr.')" />'.$ctr."</label></td>\n";
1.41 ng 3487: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
3488: $ctr++;
3489: }
1.485 albertel 3490: $radio.='</tr></table>';
3491: my $line = '<input type="text" name="TEXTVAL_'.
1.589 bisitz 3492: $partid.'" size="4" '.'onchange="javascript:writePoint(\''.
1.54 albertel 3493: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.539 riegler 3494: $weight{$partid}.' '.&mt('(problem weight)').'</td>'."\n";
3495: $line.= '<td><b>'.&mt('Grade Status').':</b><select name="SELVAL_'.$partid.'"'.
1.589 bisitz 3496: 'onchange="javascript:writeRadText(\''.$partid.'\','.
1.59 albertel 3497: $weight{$partid}.')"> '.
1.401 albertel 3498: '<option selected="selected"> </option>'.
1.485 albertel 3499: '<option value="excused">'.&mt('excused').'</option>'.
3500: '<option value="reset status">'.&mt('reset status').'</option>'.
3501: '</select></td>'.
3502: '<td><label><input type="checkbox" name="FORCE_'.$partid.'" />'.&mt('Override "Correct"').'</label>';
3503: $line.='<input type="hidden" name="partid_'.
3504: $ctsparts.'" value="'.$partid.'" />'."\n";
3505: $line.='<input type="hidden" name="weight_'.
3506: $partid.'" value="'.$weight{$partid}.'" />'."\n";
3507:
3508: $result.=
3509: &Apache::loncommon::start_data_table_row()."\n".
1.577 bisitz 3510: '<td><b>'.&mt('Part:').'</b></td><td>'.$display_part.'</td><td><b>'.&mt('Points:').'</b></td><td>'.$radio.'</td><td>'.&mt('or').'</td><td>'.$line.'</td>'.
1.485 albertel 3511: &Apache::loncommon::end_data_table_row()."\n";
1.42 ng 3512: $ctsparts++;
1.41 ng 3513: }
1.474 albertel 3514: $result.=&Apache::loncommon::end_data_table()."\n".
1.52 albertel 3515: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.485 albertel 3516: $result.='<input type="button" value="'.&mt('Revert to Default').'" '.
1.589 bisitz 3517: 'onclick="javascript:resetEntry('.$ctsparts.');" />';
1.41 ng 3518:
1.44 ng 3519: #table listing all the students in a section/class
3520: #header of table
1.560 raeburn 3521: $result.= '<h3>'.$specific_header.'</h3>'.
3522: &Apache::loncommon::start_data_table().
3523: &Apache::loncommon::start_data_table_header_row().
3524: '<th>'.&mt('No.').'</th>'.
3525: '<th>'.&nameUserString('header')."</th>\n";
1.582 raeburn 3526: my $partserror;
3527: my (@parts) = sort(&getpartlist($symb,\$partserror));
3528: if ($partserror) {
3529: return &navmap_errormsg();
3530: }
1.324 albertel 3531: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.269 raeburn 3532: my @partids = ();
1.41 ng 3533: foreach my $part (@parts) {
3534: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1.539 riegler 3535: my $narrowtext = &mt('Tries');
3536: $display =~ s|^Number of Attempts|$narrowtext <br />|; # makes the column narrower
1.41 ng 3537: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
1.207 albertel 3538: my ($partid) = &split_part_type($part);
1.524 raeburn 3539: push(@partids,$partid);
1.324 albertel 3540: my $display_part=&get_display_part($partid,$symb);
1.41 ng 3541: if ($display =~ /^Partial Credit Factor/) {
1.485 albertel 3542: $result.='<th>'.
3543: &mt('Score Part: [_1]<br /> (weight = [_2])',
3544: $display_part,$weight{$partid}).'</th>'."\n";
1.41 ng 3545: next;
1.485 albertel 3546:
1.207 albertel 3547: } else {
1.485 albertel 3548: if ($display =~ /Problem Status/) {
3549: my $grade_status_mt = &mt('Grade Status');
3550: $display =~ s{Problem Status}{$grade_status_mt<br />};
3551: }
3552: my $part_mt = &mt('Part:');
3553: $display =~s{\[Part: \Q$partid\E\]}{$part_mt $display_part};
1.41 ng 3554: }
1.485 albertel 3555:
1.474 albertel 3556: $result.='<th>'.$display.'</th>'."\n";
1.41 ng 3557: }
1.474 albertel 3558: $result.=&Apache::loncommon::end_data_table_header_row();
1.44 ng 3559:
1.270 albertel 3560: my %last_resets =
3561: &get_last_resets($symb,$env{'request.course.id'},\@partids);
1.269 raeburn 3562:
1.41 ng 3563: #get info for each student
1.44 ng 3564: #list all the students - with points and grade status
1.257 albertel 3565: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
1.41 ng 3566: my $ctr = 0;
1.294 albertel 3567: foreach (sort
3568: {
3569: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
3570: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
3571: }
3572: return $a cmp $b;
3573: } (keys(%$fullname))) {
1.126 ng 3574: $ctr++;
1.324 albertel 3575: $result.=&viewstudentgrade($symb,$env{'request.course.id'},
1.269 raeburn 3576: $_,$$fullname{$_},\@parts,\%weight,$ctr,\%last_resets);
1.41 ng 3577: }
1.474 albertel 3578: $result.=&Apache::loncommon::end_data_table();
1.41 ng 3579: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.485 albertel 3580: $result.='<input type="button" value="'.&mt('Save').'" '.
1.589 bisitz 3581: 'onclick="javascript:submit();" target="_self" /></form>'."\n";
1.96 albertel 3582: if (scalar(%$fullname) eq 0) {
3583: my $colspan=3+scalar(@parts);
1.433 banghart 3584: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.442 banghart 3585: my $stu_status = join(' or ',&Apache::loncommon::get_env_multiple('form.Status'));
1.433 banghart 3586: $result='<span class="LC_warning">'.
1.485 albertel 3587: &mt('There are no students in section(s) [_1] with enrollment status [_2] to modify or grade.',
1.442 banghart 3588: $section_display, $stu_status).
1.433 banghart 3589: '</span>';
1.96 albertel 3590: }
1.324 albertel 3591: $result.=&show_grading_menu_form($symb);
1.41 ng 3592: return $result;
3593: }
3594:
1.44 ng 3595: #--- call by previous routine to display each student
1.41 ng 3596: sub viewstudentgrade {
1.324 albertel 3597: my ($symb,$courseid,$student,$fullname,$parts,$weight,$ctr,$last_resets) = @_;
1.44 ng 3598: my ($uname,$udom) = split(/:/,$student);
3599: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.269 raeburn 3600: my %aggregates = ();
1.474 albertel 3601: my $result=&Apache::loncommon::start_data_table_row().'<td align="right">'.
1.233 albertel 3602: '<input type="hidden" name="ctr'.($ctr-1).'" value="'.$student.'" />'.
3603: "\n".$ctr.' </td><td> '.
1.44 ng 3604: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 3605: '\');" target="_self">'.$fullname.'</a> '.
1.398 albertel 3606: '<span class="LC_internal_info">('.$uname.($env{'user.domain'} eq $udom ? '' : ':'.$udom).')</span></td>'."\n";
1.281 albertel 3607: $student=~s/:/_/; # colon doen't work in javascript for names
1.63 albertel 3608: foreach my $apart (@$parts) {
3609: my ($part,$type) = &split_part_type($apart);
1.41 ng 3610: my $score=$record{"resource.$part.$type"};
1.276 albertel 3611: $result.='<td align="center">';
1.269 raeburn 3612: my ($aggtries,$totaltries);
3613: unless (exists($aggregates{$part})) {
1.270 albertel 3614: $totaltries = $record{'resource.'.$part.'.tries'};
3615:
3616: $aggtries = $totaltries;
1.269 raeburn 3617: if ($$last_resets{$part}) {
1.270 albertel 3618: $aggtries = &get_num_tries(\%record,$$last_resets{$part},
3619: $part);
3620: }
1.269 raeburn 3621: $result.='<input type="hidden" name="'.
3622: 'GD_'.$student.'_'.$part.'_aggtries" value="'.$aggtries.'" />'."\n";
3623: $result.='<input type="hidden" name="'.
3624: 'GD_'.$student.'_'.$part.'_totaltries" value="'.$totaltries.'" />'."\n";
3625: $aggregates{$part} = 1;
3626: }
1.41 ng 3627: if ($type eq 'awarded') {
1.320 albertel 3628: my $pts = $score eq '' ? '' : &compute_points($score,$$weight{$part});
1.42 ng 3629: $result.='<input type="hidden" name="'.
1.89 albertel 3630: 'GD_'.$student.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.233 albertel 3631: $result.='<input type="text" name="'.
1.89 albertel 3632: 'GD_'.$student.'_'.$part.'_awarded" '.
1.589 bisitz 3633: 'onchange="javascript:changeSelect(\''.$part.'\',\''.$student.
1.44 ng 3634: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41 ng 3635: } elsif ($type eq 'solved') {
3636: my ($status,$foo)=split(/_/,$score,2);
3637: $status = 'nothing' if ($status eq '');
1.89 albertel 3638: $result.='<input type="hidden" name="'.'GD_'.$student.'_'.
1.54 albertel 3639: $part.'_solved_s" value="'.$status.'" />'."\n";
1.233 albertel 3640: $result.=' <select name="'.
1.89 albertel 3641: 'GD_'.$student.'_'.$part.'_solved" '.
1.589 bisitz 3642: 'onchange="javascript:changeOneScore(\''.$part.'\',\''.$student.'\')" >'."\n";
1.485 albertel 3643: $result.= (($status eq 'excused') ? '<option> </option><option selected="selected" value="excused">'.&mt('excused').'</option>'
3644: : '<option selected="selected"> </option><option value="excused">'.&mt('excused').'</option>')."\n";
3645: $result.='<option value="reset status">'.&mt('reset status').'</option>';
1.126 ng 3646: $result.="</select> </td>\n";
1.122 ng 3647: } else {
3648: $result.='<input type="hidden" name="'.
3649: 'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
3650: "\n";
1.233 albertel 3651: $result.='<input type="text" name="'.
1.122 ng 3652: 'GD_'.$student.'_'.$part.'_'.$type.'" '.
3653: 'value="'.$score.'" size="4" /></td>'."\n";
1.41 ng 3654: }
3655: }
1.474 albertel 3656: $result.=&Apache::loncommon::end_data_table_row();
1.41 ng 3657: return $result;
1.38 ng 3658: }
3659:
1.44 ng 3660: #--- change scores for all the students in a section/class
3661: # record does not get update if unchanged
1.38 ng 3662: sub editgrades {
1.41 ng 3663: my ($request) = @_;
3664:
1.324 albertel 3665: my $symb=&get_symb($request);
1.433 banghart 3666: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.477 albertel 3667: my $title='<h2>'.&mt('Current Grade Status').'</h2>';
3668: $title.='<h4>'.&mt('<b>Current Resource: </b>[_1]',$env{'form.probTitle'}).'</h4>'."\n";
1.433 banghart 3669: $title.='<h4>'.&mt('<b>Section: </b>[_1]',$section_display).'</h4>'."\n";
1.126 ng 3670:
1.477 albertel 3671: my $result= &Apache::loncommon::start_data_table().
3672: &Apache::loncommon::start_data_table_header_row().
3673: '<th rowspan="2" valign="middle">'.&mt('No.').'</th>'.
3674: '<th rowspan="2" valign="middle">'.&nameUserString('header')."</th>\n";
1.43 ng 3675: my %scoreptr = (
3676: 'correct' =>'correct_by_override',
3677: 'incorrect'=>'incorrect_by_override',
3678: 'excused' =>'excused',
3679: 'ungraded' =>'ungraded_attempted',
1.596 raeburn 3680: 'credited' =>'credit_attempted',
1.43 ng 3681: 'nothing' => '',
3682: );
1.257 albertel 3683: my ($classlist,undef,$fullname) = &getclasslist($env{'form.section'},'0');
1.34 ng 3684:
1.44 ng 3685: my (@partid);
3686: my %weight = ();
1.54 albertel 3687: my %columns = ();
1.44 ng 3688: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54 albertel 3689:
1.582 raeburn 3690: my $partserror;
3691: my (@parts) = sort(&getpartlist($symb,\$partserror));
3692: if ($partserror) {
3693: return &navmap_errormsg();
3694: }
1.54 albertel 3695: my $header;
1.257 albertel 3696: while ($ctr < $env{'form.totalparts'}) {
3697: my $partid = $env{'form.partid_'.$ctr};
1.524 raeburn 3698: push(@partid,$partid);
1.257 albertel 3699: $weight{$partid} = $env{'form.weight_'.$partid};
1.44 ng 3700: $ctr++;
1.54 albertel 3701: }
1.324 albertel 3702: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.54 albertel 3703: foreach my $partid (@partid) {
1.478 albertel 3704: $header .= '<th align="center">'.&mt('Old Score').'</th>'.
3705: '<th align="center">'.&mt('New Score').'</th>';
1.54 albertel 3706: $columns{$partid}=2;
3707: foreach my $stores (@parts) {
3708: my ($part,$type) = &split_part_type($stores);
3709: if ($part !~ m/^\Q$partid\E/) { next;}
3710: if ($type eq 'awarded' || $type eq 'solved') { next; }
3711: my $display=&Apache::lonnet::metadata($url,$stores.'.display');
1.551 raeburn 3712: $display =~ s/\[Part: \Q$part\E\]//;
1.539 riegler 3713: my $narrowtext = &mt('Tries');
3714: $display =~ s/Number of Attempts/$narrowtext/;
3715: $header .= '<th align="center">'.&mt('Old').' '.$display.'</th>'.
3716: '<th align="center">'.&mt('New').' '.$display.'</th>';
1.54 albertel 3717: $columns{$partid}+=2;
3718: }
3719: }
3720: foreach my $partid (@partid) {
1.324 albertel 3721: my $display_part=&get_display_part($partid,$symb);
1.478 albertel 3722: $result .= '<th colspan="'.$columns{$partid}.'" align="center">'.
3723: &mt('Part: [_1] (Weight = [_2])',$display_part,$weight{$partid}).
3724: '</th>';
1.54 albertel 3725:
1.44 ng 3726: }
1.477 albertel 3727: $result .= &Apache::loncommon::end_data_table_header_row().
3728: &Apache::loncommon::start_data_table_header_row().
3729: $header.
3730: &Apache::loncommon::end_data_table_header_row();
3731: my @noupdate;
1.126 ng 3732: my ($updateCtr,$noupdateCtr) = (1,1);
1.257 albertel 3733: for ($i=0; $i<$env{'form.total'}; $i++) {
1.93 albertel 3734: my $line;
1.257 albertel 3735: my $user = $env{'form.ctr'.$i};
1.281 albertel 3736: my ($uname,$udom)=split(/:/,$user);
1.44 ng 3737: my %newrecord;
3738: my $updateflag = 0;
1.281 albertel 3739: $line .= '<td>'.&nameUserString(undef,$$fullname{$user},$uname,$udom).'</td>';
1.108 albertel 3740: my $usec=$classlist->{"$uname:$udom"}[5];
1.105 albertel 3741: if (!&canmodify($usec)) {
1.126 ng 3742: my $numcols=scalar(@partid)*4+2;
1.477 albertel 3743: push(@noupdate,
1.478 albertel 3744: $line."<td colspan=\"$numcols\"><span class=\"LC_warning\">".
3745: &mt('Not allowed to modify student')."</span></td></tr>");
1.105 albertel 3746: next;
3747: }
1.269 raeburn 3748: my %aggregate = ();
3749: my $aggregateflag = 0;
1.281 albertel 3750: $user=~s/:/_/; # colon doen't work in javascript for names
1.44 ng 3751: foreach (@partid) {
1.257 albertel 3752: my $old_aw = $env{'form.GD_'.$user.'_'.$_.'_awarded_s'};
1.54 albertel 3753: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
3754: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
1.257 albertel 3755: my $old_score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
3756: my $awarded = $env{'form.GD_'.$user.'_'.$_.'_awarded'};
1.54 albertel 3757: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
3758: my $partial = $awarded eq '' ? '' : $pcr;
1.44 ng 3759: my $score;
3760: if ($partial eq '') {
1.257 albertel 3761: $score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 3762: } elsif ($partial > 0) {
3763: $score = 'correct_by_override';
3764: } elsif ($partial == 0) {
3765: $score = 'incorrect_by_override';
3766: }
1.257 albertel 3767: my $dropMenu = $env{'form.GD_'.$user.'_'.$_.'_solved'};
1.125 ng 3768: $score = 'excused' if (($dropMenu eq 'excused') && ($score ne 'excused'));
3769:
1.292 albertel 3770: $newrecord{'resource.'.$_.'.regrader'}=
3771: "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 3772: if ($dropMenu eq 'reset status' &&
3773: $old_score ne '') { # ignore if no previous attempts => nothing to reset
1.299 albertel 3774: $newrecord{'resource.'.$_.'.tries'} = '';
1.125 ng 3775: $newrecord{'resource.'.$_.'.solved'} = '';
3776: $newrecord{'resource.'.$_.'.award'} = '';
1.299 albertel 3777: $newrecord{'resource.'.$_.'.awarded'} = '';
1.125 ng 3778: $updateflag = 1;
1.269 raeburn 3779: if ($env{'form.GD_'.$user.'_'.$_.'_aggtries'} > 0) {
3780: my $aggtries = $env{'form.GD_'.$user.'_'.$_.'_aggtries'};
3781: my $totaltries = $env{'form.GD_'.$user.'_'.$_.'_totaltries'};
3782: my $solvedstatus = $env{'form.GD_'.$user.'_'.$_.'_solved_s'};
3783: &decrement_aggs($symb,$_,\%aggregate,$aggtries,$totaltries,$solvedstatus);
3784: $aggregateflag = 1;
3785: }
1.139 albertel 3786: } elsif (!($old_part eq $partial && $old_score eq $score)) {
3787: $updateflag = 1;
3788: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
3789: $newrecord{'resource.'.$_.'.solved'} = $score;
3790: $rec_update++;
1.125 ng 3791: }
3792:
1.93 albertel 3793: $line .= '<td align="center">'.$old_aw.' </td>'.
1.44 ng 3794: '<td align="center">'.$awarded.
3795: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 3796:
1.54 albertel 3797:
3798: my $partid=$_;
3799: foreach my $stores (@parts) {
3800: my ($part,$type) = &split_part_type($stores);
3801: if ($part !~ m/^\Q$partid\E/) { next;}
3802: if ($type eq 'awarded' || $type eq 'solved') { next; }
1.257 albertel 3803: my $old_aw = $env{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
3804: my $awarded = $env{'form.GD_'.$user.'_'.$part.'_'.$type};
1.54 albertel 3805: if ($awarded ne '' && $awarded ne $old_aw) {
3806: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.257 albertel 3807: $newrecord{'resource.'.$part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.54 albertel 3808: $updateflag=1;
3809: }
1.93 albertel 3810: $line .= '<td align="center">'.$old_aw.' </td>'.
1.54 albertel 3811: '<td align="center">'.$awarded.' </td>';
3812: }
1.44 ng 3813: }
1.477 albertel 3814: $line.="\n";
1.301 albertel 3815:
3816: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3817: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3818:
1.44 ng 3819: if ($updateflag) {
3820: $count++;
1.257 albertel 3821: &Apache::lonnet::cstore(\%newrecord,$symb,$env{'request.course.id'},
1.89 albertel 3822: $udom,$uname);
1.301 albertel 3823:
3824: if (&Apache::bridgetask::in_queue('gradingqueue',$symb,$cdom,
3825: $cnum,$udom,$uname)) {
3826: # need to figure out if should be in queue.
3827: my %record =
3828: &Apache::lonnet::restore($symb,$env{'request.course.id'},
3829: $udom,$uname);
3830: my $all_graded = 1;
3831: my $none_graded = 1;
3832: foreach my $part (@parts) {
3833: if ( $record{'resource.'.$part.'.awarded'} eq '' ) {
3834: $all_graded = 0;
3835: } else {
3836: $none_graded = 0;
3837: }
3838: }
3839:
3840: if ($all_graded || $none_graded) {
3841: &Apache::bridgetask::remove_from_queue('gradingqueue',
3842: $symb,$cdom,$cnum,
3843: $udom,$uname);
3844: }
3845: }
3846:
1.477 albertel 3847: $result.=&Apache::loncommon::start_data_table_row().
3848: '<td align="right"> '.$updateCtr.' </td>'.$line.
3849: &Apache::loncommon::end_data_table_row();
1.126 ng 3850: $updateCtr++;
1.93 albertel 3851: } else {
1.477 albertel 3852: push(@noupdate,
3853: '<td align="right"> '.$noupdateCtr.' </td>'.$line);
1.126 ng 3854: $noupdateCtr++;
1.44 ng 3855: }
1.269 raeburn 3856: if ($aggregateflag) {
3857: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 3858: $cdom,$cnum);
1.269 raeburn 3859: }
1.93 albertel 3860: }
1.477 albertel 3861: if (@noupdate) {
1.126 ng 3862: # my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3;
3863: my $numcols=scalar(@partid)*4+2;
1.477 albertel 3864: $result .= &Apache::loncommon::start_data_table_row('LC_empty_row').
1.478 albertel 3865: '<td align="center" colspan="'.$numcols.'">'.
3866: &mt('No Changes Occurred For the Students Below').
3867: '</td>'.
1.477 albertel 3868: &Apache::loncommon::end_data_table_row();
3869: foreach my $line (@noupdate) {
3870: $result.=
3871: &Apache::loncommon::start_data_table_row().
3872: $line.
3873: &Apache::loncommon::end_data_table_row();
3874: }
1.44 ng 3875: }
1.477 albertel 3876: $result .= &Apache::loncommon::end_data_table().
3877: &show_grading_menu_form($symb);
1.478 albertel 3878: my $msg = '<p><b>'.
3879: &mt('Number of records updated = [_1] for [quant,_2,student].',
3880: $rec_update,$count).'</b><br />'.
3881: '<b>'.&mt('Total number of students = [_1]',$env{'form.total'}).
3882: '</b></p>';
1.44 ng 3883: return $title.$msg.$result;
1.5 albertel 3884: }
1.54 albertel 3885:
3886: sub split_part_type {
3887: my ($partstr) = @_;
3888: my ($temp,@allparts)=split(/_/,$partstr);
3889: my $type=pop(@allparts);
1.439 albertel 3890: my $part=join('_',@allparts);
1.54 albertel 3891: return ($part,$type);
3892: }
3893:
1.44 ng 3894: #------------- end of section for handling grading by section/class ---------
3895: #
3896: #----------------------------------------------------------------------------
3897:
1.5 albertel 3898:
1.44 ng 3899: #----------------------------------------------------------------------------
3900: #
3901: #-------------------------- Next few routines handles grading by csv upload
3902: #
3903: #--- Javascript to handle csv upload
1.27 albertel 3904: sub csvupload_javascript_reverse_associate {
1.573 bisitz 3905: my $error1=&mt('You need to specify the username or the student/employee ID');
1.246 albertel 3906: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3907: return(<<ENDPICK);
3908: function verify(vf) {
3909: var foundsomething=0;
3910: var founduname=0;
1.243 albertel 3911: var foundID=0;
1.27 albertel 3912: for (i=0;i<=vf.nfields.value;i++) {
3913: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3914: if (i==0 && tw!=0) { foundID=1; }
3915: if (i==1 && tw!=0) { founduname=1; }
3916: if (i!=0 && i!=1 && i!=2 && tw!=0) { foundsomething=1; }
1.27 albertel 3917: }
1.246 albertel 3918: if (founduname==0 && foundID==0) {
3919: alert('$error1');
3920: return;
1.27 albertel 3921: }
3922: if (foundsomething==0) {
1.246 albertel 3923: alert('$error2');
3924: return;
1.27 albertel 3925: }
3926: vf.submit();
3927: }
3928: function flip(vf,tf) {
3929: var nw=eval('vf.f'+tf+'.selectedIndex');
3930: var i;
3931: for (i=0;i<=vf.nfields.value;i++) {
3932: //can not pick the same destination field for both name and domain
3933: if (((i ==0)||(i ==1)) &&
3934: ((tf==0)||(tf==1)) &&
3935: (i!=tf) &&
3936: (eval('vf.f'+i+'.selectedIndex')==nw)) {
3937: eval('vf.f'+i+'.selectedIndex=0;')
3938: }
3939: }
3940: }
3941: ENDPICK
3942: }
3943:
3944: sub csvupload_javascript_forward_associate {
1.573 bisitz 3945: my $error1=&mt('You need to specify the username or the student/employee ID');
1.246 albertel 3946: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3947: return(<<ENDPICK);
3948: function verify(vf) {
3949: var foundsomething=0;
3950: var founduname=0;
1.243 albertel 3951: var foundID=0;
1.27 albertel 3952: for (i=0;i<=vf.nfields.value;i++) {
3953: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3954: if (tw==1) { foundID=1; }
3955: if (tw==2) { founduname=1; }
3956: if (tw>3) { foundsomething=1; }
1.27 albertel 3957: }
1.246 albertel 3958: if (founduname==0 && foundID==0) {
3959: alert('$error1');
3960: return;
1.27 albertel 3961: }
3962: if (foundsomething==0) {
1.246 albertel 3963: alert('$error2');
3964: return;
1.27 albertel 3965: }
3966: vf.submit();
3967: }
3968: function flip(vf,tf) {
3969: var nw=eval('vf.f'+tf+'.selectedIndex');
3970: var i;
3971: //can not pick the same destination field twice
3972: for (i=0;i<=vf.nfields.value;i++) {
3973: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
3974: eval('vf.f'+i+'.selectedIndex=0;')
3975: }
3976: }
3977: }
3978: ENDPICK
3979: }
3980:
1.26 albertel 3981: sub csvuploadmap_header {
1.324 albertel 3982: my ($request,$symb,$datatoken,$distotal)= @_;
1.41 ng 3983: my $javascript;
1.257 albertel 3984: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3985: $javascript=&csvupload_javascript_reverse_associate();
3986: } else {
3987: $javascript=&csvupload_javascript_forward_associate();
3988: }
1.45 ng 3989:
1.324 albertel 3990: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.257 albertel 3991: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1.245 albertel 3992: my $ignore=&mt('Ignore First Line');
1.418 albertel 3993: $symb = &Apache::lonenc::check_encrypt($symb);
1.41 ng 3994: $request->print(<<ENDPICK);
1.26 albertel 3995: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.398 albertel 3996: <h3><span class="LC_info">Uploading Class Grades</span></h3>
1.45 ng 3997: $result
1.326 albertel 3998: <hr />
1.26 albertel 3999: <h3>Identify fields</h3>
4000: Total number of records found in file: $distotal <hr />
4001: Enter as many fields as you can. The system will inform you and bring you back
4002: to this page if the data selected is insufficient to run your class.<hr />
1.589 bisitz 4003: <input type="button" value="Reverse Association" onclick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1.245 albertel 4004: <label><input type="checkbox" name="noFirstLine" $checked />$ignore</label>
1.26 albertel 4005: <input type="hidden" name="associate" value="" />
4006: <input type="hidden" name="phase" value="three" />
4007: <input type="hidden" name="datatoken" value="$datatoken" />
1.257 albertel 4008: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
4009: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
1.26 albertel 4010: <input type="hidden" name="upfile_associate"
1.257 albertel 4011: value="$env{'form.upfile_associate'}" />
1.26 albertel 4012: <input type="hidden" name="symb" value="$symb" />
1.257 albertel 4013: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
4014: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
1.246 albertel 4015: <input type="hidden" name="command" value="csvuploadoptions" />
1.26 albertel 4016: <hr />
4017: <script type="text/javascript" language="Javascript">
4018: $javascript
4019: </script>
4020: ENDPICK
1.118 ng 4021: return '';
1.26 albertel 4022:
4023: }
4024:
4025: sub csvupload_fields {
1.582 raeburn 4026: my ($symb,$errorref) = @_;
4027: my (@parts) = &getpartlist($symb,$errorref);
4028: if (ref($errorref)) {
4029: if ($$errorref) {
4030: return;
4031: }
4032: }
4033:
1.556 weissno 4034: my @fields=(['ID','Student/Employee ID'],
1.243 albertel 4035: ['username','Student Username'],
4036: ['domain','Student Domain']);
1.324 albertel 4037: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.41 ng 4038: foreach my $part (sort(@parts)) {
4039: my @datum;
4040: my $display=&Apache::lonnet::metadata($url,$part.'.display');
4041: my $name=$part;
4042: if (!$display) { $display = $name; }
4043: @datum=($name,$display);
1.244 albertel 4044: if ($name=~/^stores_(.*)_awarded/) {
4045: push(@fields,['stores_'.$1.'_points',"Points [Part: $1]"]);
4046: }
1.41 ng 4047: push(@fields,\@datum);
4048: }
4049: return (@fields);
1.26 albertel 4050: }
4051:
4052: sub csvuploadmap_footer {
1.41 ng 4053: my ($request,$i,$keyfields) =@_;
4054: $request->print(<<ENDPICK);
1.26 albertel 4055: </table>
4056: <input type="hidden" name="nfields" value="$i" />
4057: <input type="hidden" name="keyfields" value="$keyfields" />
1.589 bisitz 4058: <input type="button" onclick="javascript:verify(this.form)" value="Assign Grades" /><br />
1.26 albertel 4059: </form>
4060: ENDPICK
4061: }
4062:
1.283 albertel 4063: sub checkforfile_js {
1.539 riegler 4064: my $alertmsg = &mt('Please use the browse button to select a file from your local directory.');
1.86 ng 4065: my $result =<<CSVFORMJS;
4066: <script type="text/javascript" language="javascript">
4067: function checkUpload(formname) {
4068: if (formname.upfile.value == "") {
1.539 riegler 4069: alert("$alertmsg");
1.86 ng 4070: return false;
4071: }
4072: formname.submit();
4073: }
4074: </script>
4075: CSVFORMJS
1.283 albertel 4076: return $result;
4077: }
4078:
4079: sub upcsvScores_form {
4080: my ($request) = shift;
1.324 albertel 4081: my ($symb)=&get_symb($request);
1.283 albertel 4082: if (!$symb) {return '';}
4083: my $result=&checkforfile_js();
1.257 albertel 4084: $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
1.324 albertel 4085: my ($table) = &showResourceInfo($symb,$env{'form.probTitle'});
1.118 ng 4086: $result.=$table;
1.326 albertel 4087: $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
4088: $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
1.538 schulted 4089: $result.=' <b>'.&mt('Specify a file containing the class scores for current resource.').
4090: '</b></td></tr>'."\n";
1.596.2.4 raeburn 4091: $result.='<tr bgcolor="#ffffe6"><td>'."\n";
1.370 www 4092: my $upload=&mt("Upload Scores");
1.86 ng 4093: my $upfile_select=&Apache::loncommon::upfile_select_html();
1.245 albertel 4094: my $ignore=&mt('Ignore First Line');
1.418 albertel 4095: $symb = &Apache::lonenc::check_encrypt($symb);
1.86 ng 4096: $result.=<<ENDUPFORM;
1.106 albertel 4097: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.86 ng 4098: <input type="hidden" name="symb" value="$symb" />
4099: <input type="hidden" name="command" value="csvuploadmap" />
1.257 albertel 4100: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
4101: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
1.86 ng 4102: $upfile_select
1.589 bisitz 4103: <br /><input type="button" onclick="javascript:checkUpload(this.form);" value="$upload" />
1.283 albertel 4104: <label><input type="checkbox" name="noFirstLine" />$ignore</label>
1.86 ng 4105: </form>
4106: ENDUPFORM
1.370 www 4107: $result.=&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
4108: &mt("How do I create a CSV file from a spreadsheet"))
4109: .'</td></tr></table>'."\n";
1.86 ng 4110: $result.='</td></tr></table><br /><br />'."\n";
1.324 albertel 4111: $result.=&show_grading_menu_form($symb);
1.86 ng 4112: return $result;
4113: }
4114:
4115:
1.26 albertel 4116: sub csvuploadmap {
1.41 ng 4117: my ($request)= @_;
1.324 albertel 4118: my ($symb)=&get_symb($request);
1.41 ng 4119: if (!$symb) {return '';}
1.72 ng 4120:
1.41 ng 4121: my $datatoken;
1.257 albertel 4122: if (!$env{'form.datatoken'}) {
1.41 ng 4123: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 4124: } else {
1.257 albertel 4125: $datatoken=$env{'form.datatoken'};
1.41 ng 4126: &Apache::loncommon::load_tmp_file($request);
1.26 albertel 4127: }
1.41 ng 4128: my @records=&Apache::loncommon::upfile_record_sep();
1.257 albertel 4129: if ($env{'form.noFirstLine'}) { shift(@records); }
1.324 albertel 4130: &csvuploadmap_header($request,$symb,$datatoken,$#records+1);
1.41 ng 4131: my ($i,$keyfields);
4132: if (@records) {
1.582 raeburn 4133: my $fieldserror;
4134: my @fields=&csvupload_fields($symb,\$fieldserror);
4135: if ($fieldserror) {
4136: $request->print(&navmap_errormsg());
4137: return;
4138: }
1.257 albertel 4139: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 4140: &Apache::loncommon::csv_print_samples($request,\@records);
4141: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
4142: \@fields);
4143: foreach (@fields) { $keyfields.=$_->[0].','; }
4144: chop($keyfields);
4145: } else {
4146: unshift(@fields,['none','']);
4147: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
4148: \@fields);
1.311 banghart 4149: foreach my $rec (@records) {
4150: my %temp = &Apache::loncommon::record_sep($rec);
4151: if (%temp) {
4152: $keyfields=join(',',sort(keys(%temp)));
4153: last;
4154: }
4155: }
1.41 ng 4156: }
4157: }
4158: &csvuploadmap_footer($request,$i,$keyfields);
1.324 albertel 4159: $request->print(&show_grading_menu_form($symb));
1.72 ng 4160:
1.41 ng 4161: return '';
1.27 albertel 4162: }
4163:
1.246 albertel 4164: sub csvuploadoptions {
1.41 ng 4165: my ($request)= @_;
1.324 albertel 4166: my ($symb)=&get_symb($request);
1.257 albertel 4167: my $checked=(($env{'form.noFirstLine'})?'1':'0');
1.246 albertel 4168: my $ignore=&mt('Ignore First Line');
4169: $request->print(<<ENDPICK);
4170: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.398 albertel 4171: <h3><span class="LC_info">Uploading Class Grade Options</span></h3>
1.246 albertel 4172: <input type="hidden" name="command" value="csvuploadassign" />
1.302 albertel 4173: <!--
1.246 albertel 4174: <p>
4175: <label>
4176: <input type="checkbox" name="show_full_results" />
4177: Show a table of all changes
4178: </label>
4179: </p>
1.302 albertel 4180: -->
1.246 albertel 4181: <p>
4182: <label>
4183: <input type="checkbox" name="overwite_scores" checked="checked" />
4184: Overwrite any existing score
4185: </label>
4186: </p>
4187: ENDPICK
4188: my %fields=&get_fields();
4189: if (!defined($fields{'domain'})) {
1.257 albertel 4190: my $domform = &Apache::loncommon::select_dom_form($env{'request.role.domain'},'default_domain');
1.246 albertel 4191: $request->print("\n<p> Users are in domain: ".$domform."</p>\n");
4192: }
1.257 albertel 4193: foreach my $key (sort(keys(%env))) {
1.246 albertel 4194: if ($key !~ /^form\.(.*)$/) { next; }
4195: my $cleankey=$1;
4196: if ($cleankey eq 'command') { next; }
4197: $request->print('<input type="hidden" name="'.$cleankey.
1.257 albertel 4198: '" value="'.$env{$key}.'" />'."\n");
1.246 albertel 4199: }
4200: # FIXME do a check for any duplicated user ids...
4201: # FIXME do a check for any invalid user ids?...
1.290 albertel 4202: $request->print('<input type="submit" value="Assign Grades" /><br />
4203: <hr /></form>'."\n");
1.324 albertel 4204: $request->print(&show_grading_menu_form($symb));
1.246 albertel 4205: return '';
4206: }
4207:
4208: sub get_fields {
4209: my %fields;
1.257 albertel 4210: my @keyfields = split(/\,/,$env{'form.keyfields'});
4211: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
4212: if ($env{'form.upfile_associate'} eq 'reverse') {
4213: if ($env{'form.f'.$i} ne 'none') {
4214: $fields{$keyfields[$i]}=$env{'form.f'.$i};
1.41 ng 4215: }
4216: } else {
1.257 albertel 4217: if ($env{'form.f'.$i} ne 'none') {
4218: $fields{$env{'form.f'.$i}}=$keyfields[$i];
1.41 ng 4219: }
4220: }
1.27 albertel 4221: }
1.246 albertel 4222: return %fields;
4223: }
4224:
4225: sub csvuploadassign {
4226: my ($request)= @_;
1.324 albertel 4227: my ($symb)=&get_symb($request);
1.246 albertel 4228: if (!$symb) {return '';}
1.345 bowersj2 4229: my $error_msg = '';
1.246 albertel 4230: &Apache::loncommon::load_tmp_file($request);
4231: my @gradedata = &Apache::loncommon::upfile_record_sep();
1.257 albertel 4232: if ($env{'form.noFirstLine'}) { shift(@gradedata); }
1.246 albertel 4233: my %fields=&get_fields();
1.41 ng 4234: $request->print('<h3>Assigning Grades</h3>');
1.257 albertel 4235: my $courseid=$env{'request.course.id'};
1.97 albertel 4236: my ($classlist) = &getclasslist('all',0);
1.106 albertel 4237: my @notallowed;
1.41 ng 4238: my @skipped;
1.596.2.4 raeburn 4239: my @warnings;
1.41 ng 4240: my $countdone=0;
4241: foreach my $grade (@gradedata) {
4242: my %entries=&Apache::loncommon::record_sep($grade);
1.246 albertel 4243: my $domain;
4244: if ($entries{$fields{'domain'}}) {
4245: $domain=$entries{$fields{'domain'}};
4246: } else {
1.257 albertel 4247: $domain=$env{'form.default_domain'};
1.246 albertel 4248: }
1.243 albertel 4249: $domain=~s/\s//g;
1.41 ng 4250: my $username=$entries{$fields{'username'}};
1.160 albertel 4251: $username=~s/\s//g;
1.243 albertel 4252: if (!$username) {
4253: my $id=$entries{$fields{'ID'}};
1.247 albertel 4254: $id=~s/\s//g;
1.243 albertel 4255: my %ids=&Apache::lonnet::idget($domain,$id);
4256: $username=$ids{$id};
4257: }
1.41 ng 4258: if (!exists($$classlist{"$username:$domain"})) {
1.247 albertel 4259: my $id=$entries{$fields{'ID'}};
4260: $id=~s/\s//g;
4261: if ($id) {
4262: push(@skipped,"$id:$domain");
4263: } else {
4264: push(@skipped,"$username:$domain");
4265: }
1.41 ng 4266: next;
4267: }
1.108 albertel 4268: my $usec=$classlist->{"$username:$domain"}[5];
1.106 albertel 4269: if (!&canmodify($usec)) {
4270: push(@notallowed,"$username:$domain");
4271: next;
4272: }
1.244 albertel 4273: my %points;
1.41 ng 4274: my %grades;
4275: foreach my $dest (keys(%fields)) {
1.244 albertel 4276: if ($dest eq 'ID' || $dest eq 'username' ||
4277: $dest eq 'domain') { next; }
4278: if ($entries{$fields{$dest}} =~ /^\s*$/) { next; }
4279: if ($dest=~/stores_(.*)_points/) {
4280: my $part=$1;
4281: my $wgt =&Apache::lonnet::EXT('resource.'.$part.'.weight',
4282: $symb,$domain,$username);
1.345 bowersj2 4283: if ($wgt) {
4284: $entries{$fields{$dest}}=~s/\s//g;
4285: my $pcr=$entries{$fields{$dest}} / $wgt;
1.463 albertel 4286: my $award=($pcr == 0) ? 'incorrect_by_override'
4287: : 'correct_by_override';
1.596.2.4 raeburn 4288: if ($pcr>1) {
4289: push(@warnings,&mt("[_1]: point value larger than weight","$username:$domain"));
4290: }
1.345 bowersj2 4291: $grades{"resource.$part.awarded"}=$pcr;
4292: $grades{"resource.$part.solved"}=$award;
4293: $points{$part}=1;
4294: } else {
4295: $error_msg = "<br />" .
4296: &mt("Some point values were assigned"
4297: ." for problems with a weight "
4298: ."of zero. These values were "
4299: ."ignored.");
4300: }
1.244 albertel 4301: } else {
4302: if ($dest=~/stores_(.*)_awarded/) { if ($points{$1}) {next;} }
4303: if ($dest=~/stores_(.*)_solved/) { if ($points{$1}) {next;} }
4304: my $store_key=$dest;
4305: $store_key=~s/^stores/resource/;
4306: $store_key=~s/_/\./g;
4307: $grades{$store_key}=$entries{$fields{$dest}};
4308: }
1.41 ng 4309: }
1.508 www 4310: if (! %grades) {
4311: push(@skipped,&mt("[_1]: no data to save","$username:$domain"));
4312: } else {
4313: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
4314: my $result=&Apache::lonnet::cstore(\%grades,$symb,
1.302 albertel 4315: $env{'request.course.id'},
4316: $domain,$username);
1.508 www 4317: if ($result eq 'ok') {
4318: $request->print('.');
1.596.2.4 raeburn 4319: # Remove from grading queue
4320: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,
4321: $env{'course.'.$env{'request.course.id'}.'.domain'},
4322: $env{'course.'.$env{'request.course.id'}.'.num'},
4323: $domain,$username);
1.508 www 4324: } else {
4325: $request->print("<p><span class=\"LC_error\">".
4326: &mt("Failed to save data for student [_1]. Message when trying to save was: [_2]",
4327: "$username:$domain",$result)."</span></p>");
4328: }
4329: $request->rflush();
4330: $countdone++;
4331: }
1.41 ng 4332: }
1.570 www 4333: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt("Saved scores for [quant,_1,student]",$countdone),$countdone==0));
1.596.2.4 raeburn 4334: if (@warnings) {
4335: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('Warnings generated for the following saved scores:'),1).'<br />');
4336: $request->print(join(', ',@warnings));
4337: }
1.41 ng 4338: if (@skipped) {
1.571 www 4339: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('No scores stored for the following username(s):'),1).'<br />');
4340: $request->print(join(', ',@skipped));
1.106 albertel 4341: }
4342: if (@notallowed) {
1.571 www 4343: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('Modification of scores not allowed for the following username(s):'),1).'<br />');
4344: $request->print(join(', ',@notallowed));
1.41 ng 4345: }
1.106 albertel 4346: $request->print("<br />\n");
1.324 albertel 4347: $request->print(&show_grading_menu_form($symb));
1.345 bowersj2 4348: return $error_msg;
1.26 albertel 4349: }
1.44 ng 4350: #------------- end of section for handling csv file upload ---------
4351: #
4352: #-------------------------------------------------------------------
4353: #
1.122 ng 4354: #-------------- Next few routines handle grading by page/sequence
1.72 ng 4355: #
4356: #--- Select a page/sequence and a student to grade
1.68 ng 4357: sub pickStudentPage {
4358: my ($request) = shift;
4359:
1.539 riegler 4360: my $alertmsg = &mt('Please select the student you wish to grade.');
1.68 ng 4361: $request->print(<<LISTJAVASCRIPT);
4362: <script type="text/javascript" language="javascript">
4363:
4364: function checkPickOne(formname) {
1.76 ng 4365: if (radioSelection(formname.student) == null) {
1.539 riegler 4366: alert("$alertmsg");
1.68 ng 4367: return;
4368: }
1.125 ng 4369: ptr = pullDownSelection(formname.selectpage);
4370: formname.page.value = formname["page"+ptr].value;
4371: formname.title.value = formname["title"+ptr].value;
1.68 ng 4372: formname.submit();
4373: }
4374:
4375: </script>
4376: LISTJAVASCRIPT
1.118 ng 4377: &commonJSfunctions($request);
1.324 albertel 4378: my ($symb) = &get_symb($request);
1.257 albertel 4379: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4380: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4381: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.68 ng 4382:
1.398 albertel 4383: my $result='<h3><span class="LC_info"> '.
1.485 albertel 4384: &mt('Manual Grading by Page or Sequence').'</span></h3>';
1.68 ng 4385:
1.80 ng 4386: $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
1.582 raeburn 4387: my $map_error;
4388: my ($titles,$symbx) = &getSymbMap($map_error);
4389: if ($map_error) {
4390: $request->print(&navmap_errormsg());
4391: return;
4392: }
1.137 albertel 4393: my ($curpage) =&Apache::lonnet::decode_symb($symb);
4394: # my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb);
4395: # my $type=($curpage =~ /\.(page|sequence)/);
1.485 albertel 4396: my $select = '<select name="selectpage">'."\n";
1.70 ng 4397: my $ctr=0;
1.68 ng 4398: foreach (@$titles) {
4399: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.485 albertel 4400: $select.='<option value="'.$ctr.'" '.
1.401 albertel 4401: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.71 ng 4402: '>'.$showtitle.'</option>'."\n";
1.70 ng 4403: $ctr++;
1.68 ng 4404: }
1.485 albertel 4405: $select.= '</select>';
1.539 riegler 4406: $result.=' <b>'.&mt('Problems from').':</b> '.$select."<br />\n";
1.485 albertel 4407:
1.70 ng 4408: $ctr=0;
4409: foreach (@$titles) {
4410: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
4411: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
4412: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
4413: $ctr++;
4414: }
1.72 ng 4415: $result.='<input type="hidden" name="page" />'."\n".
4416: '<input type="hidden" name="title" />'."\n";
1.68 ng 4417:
1.485 albertel 4418: my $options =
4419: '<label><input type="radio" name="vProb" value="no" checked="checked" /> '.&mt('no').' </label>'."\n".
4420: '<label><input type="radio" name="vProb" value="yes" /> '.&mt('yes').' </label>'."<br />\n";
1.539 riegler 4421: $result.=' <b>'.&mt('View Problem Text').': </b>'.$options;
1.485 albertel 4422:
4423: $options =
4424: '<label><input type="radio" name="lastSub" value="none" /> '.&mt('none').' </label>'."\n".
4425: '<label><input type="radio" name="lastSub" value="datesub" checked="checked" /> '.&mt('by dates and submissions').'</label>'."\n".
4426: '<label><input type="radio" name="lastSub" value="all" /> '.&mt('all details').' </label>'."\n";
1.539 riegler 4427: $result.=' <b>'.&mt('Submissions').': </b>'.$options;
1.432 banghart 4428:
4429: $result.=&build_section_inputs();
1.442 banghart 4430: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
4431: $result.='<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.72 ng 4432: '<input type="hidden" name="command" value="displayPage" />'."\n".
1.418 albertel 4433: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 4434: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."<br />\n";
1.72 ng 4435:
1.539 riegler 4436: $result.=' <b>'.&mt('Use CODE').': </b> <input type="text" name="CODE" value="" /> <br />'."\n";
1.382 albertel 4437:
1.80 ng 4438: $result.=' <input type="button" '.
1.589 bisitz 4439: 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /><br />'."\n";
1.72 ng 4440:
1.68 ng 4441: $request->print($result);
4442:
1.485 albertel 4443: my $studentTable.=' <b>'.&mt('Select a student you wish to grade and then click on the Next button.').'</b><br />'.
1.484 albertel 4444: &Apache::loncommon::start_data_table().
4445: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 4446: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 4447: '<th>'.&nameUserString('header').'</th>'.
1.485 albertel 4448: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 4449: '<th>'.&nameUserString('header').'</th>'.
4450: &Apache::loncommon::end_data_table_header_row();
1.68 ng 4451:
1.76 ng 4452: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.68 ng 4453: my $ptr = 1;
1.294 albertel 4454: foreach my $student (sort
4455: {
4456: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
4457: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
4458: }
4459: return $a cmp $b;
4460: } (keys(%$fullname))) {
1.68 ng 4461: my ($uname,$udom) = split(/:/,$student);
1.484 albertel 4462: $studentTable.=($ptr%2==1 ? &Apache::loncommon::start_data_table_row()
4463: : '</td>');
1.126 ng 4464: $studentTable.='<td align="right">'.$ptr.' </td>';
1.288 albertel 4465: $studentTable.='<td> <label><input type="radio" name="student" value="'.$student.'" /> '
4466: .&nameUserString(undef,$$fullname{$student},$uname,$udom)."</label>\n";
1.484 albertel 4467: $studentTable.=
4468: ($ptr%2 == 0 ? '</td>'.&Apache::loncommon::end_data_table_row()
4469: : '');
1.68 ng 4470: $ptr++;
4471: }
1.484 albertel 4472: if ($ptr%2 == 0) {
4473: $studentTable.='</td><td> </td><td> </td>'.
4474: &Apache::loncommon::end_data_table_row();
4475: }
4476: $studentTable.=&Apache::loncommon::end_data_table()."\n";
1.126 ng 4477: $studentTable.='<input type="button" '.
1.589 bisitz 4478: 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /></form>'."\n";
1.68 ng 4479:
1.324 albertel 4480: $studentTable.=&show_grading_menu_form($symb);
1.68 ng 4481: $request->print($studentTable);
4482:
4483: return '';
4484: }
4485:
4486: sub getSymbMap {
1.582 raeburn 4487: my ($map_error) = @_;
1.132 bowersj2 4488: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 4489: unless (ref($navmap)) {
4490: if (ref($map_error)) {
4491: $$map_error = 'navmap';
4492: }
4493: return;
4494: }
1.68 ng 4495: my %symbx = ();
4496: my @titles = ();
1.117 bowersj2 4497: my $minder = 0;
4498:
4499: # Gather every sequence that has problems.
1.240 albertel 4500: my @sequences = $navmap->retrieveResources(undef, sub { shift->is_map(); },
4501: 1,0,1);
1.117 bowersj2 4502: for my $sequence ($navmap->getById('0.0'), @sequences) {
1.241 albertel 4503: if ($navmap->hasResource($sequence, sub { shift->is_problem(); }, 0) ) {
1.381 albertel 4504: my $title = $minder.'.'.
4505: &HTML::Entities::encode($sequence->compTitle(),'"\'&');
4506: push(@titles, $title); # minder in case two titles are identical
4507: $symbx{$title} = &HTML::Entities::encode($sequence->symb(),'"\'&');
1.117 bowersj2 4508: $minder++;
1.241 albertel 4509: }
1.68 ng 4510: }
4511: return \@titles,\%symbx;
4512: }
4513:
1.72 ng 4514: #
4515: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68 ng 4516: sub displayPage {
4517: my ($request) = shift;
4518:
1.324 albertel 4519: my ($symb) = &get_symb($request);
1.257 albertel 4520: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4521: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4522: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
4523: my $pageTitle = $env{'form.page'};
1.103 albertel 4524: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 4525: my ($uname,$udom) = split(/:/,$env{'form.student'});
4526: my $usec=$classlist->{$env{'form.student'}}[5];
1.168 albertel 4527:
4528: #need to make sure we have the correct data for later EXT calls,
4529: #thus invalidate the cache
4530: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 4531: $env{'course.'.$env{'request.course.id'}.'.num'},
4532: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 4533: &Apache::lonnet::clear_EXT_cache_status();
4534:
1.103 albertel 4535: if (!&canview($usec)) {
1.485 albertel 4536: $request->print('<span class="LC_warning">'.&mt('Unable to view requested student. ([_1])',$env{'form.student'}).'</span>');
1.324 albertel 4537: $request->print(&show_grading_menu_form($symb));
1.103 albertel 4538: return;
4539: }
1.398 albertel 4540: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.485 albertel 4541: $result.='<h3> '.&mt('Student: [_1]',&nameUserString(undef,$$fullname{$env{'form.student'}},$uname,$udom)).
1.129 ng 4542: '</h3>'."\n";
1.500 albertel 4543: $env{'form.CODE'} = uc($env{'form.CODE'});
1.501 foxr 4544: if (&Apache::lonnet::validCODE(uc($env{'form.CODE'}))) {
1.485 albertel 4545: $result.='<h3> '.&mt('CODE: [_1]',$env{'form.CODE'}).'</h3>'."\n";
1.382 albertel 4546: } else {
4547: delete($env{'form.CODE'});
4548: }
1.71 ng 4549: &sub_page_js($request);
4550: $request->print($result);
4551:
1.132 bowersj2 4552: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 4553: unless (ref($navmap)) {
4554: $request->print(&navmap_errormsg());
4555: $request->print(&show_grading_menu_form($symb));
4556: return;
4557: }
1.257 albertel 4558: my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($env{'form.page'});
1.68 ng 4559: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 4560: if (!$map) {
1.485 albertel 4561: $request->print('<span class="LC_warning">'.&mt('Unable to view requested sequence. ([_1])',$resUrl).'</span>');
1.324 albertel 4562: $request->print(&show_grading_menu_form($symb));
1.288 albertel 4563: return;
4564: }
1.68 ng 4565: my $iterator = $navmap->getIterator($map->map_start(),
4566: $map->map_finish());
4567:
1.71 ng 4568: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72 ng 4569: '<input type="hidden" name="command" value="gradeByPage" />'."\n".
1.257 albertel 4570: '<input type="hidden" name="fullname" value="'.$$fullname{$env{'form.student'}}.'" />'."\n".
4571: '<input type="hidden" name="student" value="'.$env{'form.student'}.'" />'."\n".
1.72 ng 4572: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
1.257 albertel 4573: '<input type="hidden" name="title" value="'.$env{'form.title'}.'" />'."\n".
1.418 albertel 4574: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.125 ng 4575: '<input type="hidden" name="overRideScore" value="no" />'."\n".
1.257 albertel 4576: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n";
1.71 ng 4577:
1.382 albertel 4578: if (defined($env{'form.CODE'})) {
4579: $studentTable.=
4580: '<input type="hidden" name="CODE" value="'.$env{'form.CODE'}.'" />'."\n";
4581: }
1.381 albertel 4582: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 4583: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 4584:
1.594 bisitz 4585: $studentTable.=' <span class="LC_info">'.
4586: &mt('Problems graded correct by the computer are marked with a [_1] symbol.',$checkIcon).
4587: '</span>'."\n".
1.484 albertel 4588: &Apache::loncommon::start_data_table().
4589: &Apache::loncommon::start_data_table_header_row().
4590: '<th align="center"> Prob. </th>'.
1.485 albertel 4591: '<th> '.($env{'form.vProb'} eq 'no' ? &mt('Title') : &mt('Problem Text')).'/'.&mt('Grade').'</th>'.
1.484 albertel 4592: &Apache::loncommon::end_data_table_header_row();
1.71 ng 4593:
1.329 albertel 4594: &Apache::lonxml::clear_problem_counter();
1.196 albertel 4595: my ($depth,$question,$prob) = (1,1,1);
1.68 ng 4596: $iterator->next(); # skip the first BEGIN_MAP
4597: my $curRes = $iterator->next(); # for "current resource"
1.101 albertel 4598: while ($depth > 0) {
1.68 ng 4599: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4600: if($curRes == $iterator->END_MAP) { $depth--; }
1.68 ng 4601:
1.385 albertel 4602: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4603: my $parts = $curRes->parts();
1.68 ng 4604: my $title = $curRes->compTitle();
1.71 ng 4605: my $symbx = $curRes->symb();
1.484 albertel 4606: $studentTable.=
4607: &Apache::loncommon::start_data_table_row().
4608: '<td align="center" valign="top" >'.$prob.
1.485 albertel 4609: (scalar(@{$parts}) == 1 ? ''
1.596.2.2 raeburn 4610: : '<br />('.&mt('[_1]parts)',
4611: scalar(@{$parts}).' ')
1.485 albertel 4612: ).
4613: '</td>';
1.71 ng 4614: $studentTable.='<td valign="top">';
1.382 albertel 4615: my %form = ('CODE' => $env{'form.CODE'},);
1.257 albertel 4616: if ($env{'form.vProb'} eq 'yes' ) {
1.144 albertel 4617: $studentTable.=&show_problem($request,$symbx,$uname,$udom,1,
1.383 albertel 4618: undef,'both',\%form);
1.71 ng 4619: } else {
1.382 albertel 4620: my $companswer = &Apache::loncommon::get_student_answers($symbx,$uname,$udom,$env{'request.course.id'},%form);
1.80 ng 4621: $companswer =~ s|<form(.*?)>||g;
4622: $companswer =~ s|</form>||g;
1.71 ng 4623: # while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
1.116 ng 4624: # $companswer =~ s/$1/ /ms;
1.326 albertel 4625: # $request->print('match='.$1."<br />\n");
1.71 ng 4626: # }
1.116 ng 4627: # $companswer =~ s|<table border=\"1\">|<table border=\"0\">|g;
1.539 riegler 4628: $studentTable.=' <b>'.$title.'</b> <br /> <b>'.&mt('Correct answer').':</b><br />'.$companswer;
1.71 ng 4629: }
4630:
1.257 albertel 4631: my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
1.125 ng 4632:
1.257 albertel 4633: if ($env{'form.lastSub'} eq 'datesub') {
1.71 ng 4634: if ($record{'version'} eq '') {
1.485 albertel 4635: $studentTable.='<br /> <span class="LC_warning">'.&mt('No recorded submission for this problem.').'</span><br />';
1.71 ng 4636: } else {
1.116 ng 4637: my %responseType = ();
4638: foreach my $partid (@{$parts}) {
1.147 albertel 4639: my @responseIds =$curRes->responseIds($partid);
4640: my @responseType =$curRes->responseType($partid);
4641: my %responseIds;
4642: for (my $i=0;$i<=$#responseIds;$i++) {
4643: $responseIds{$responseIds[$i]}=$responseType[$i];
4644: }
4645: $responseType{$partid} = \%responseIds;
1.116 ng 4646: }
1.148 albertel 4647: $studentTable.= &displaySubByDates($symbx,\%record,$parts,\%responseType,$checkIcon,$uname,$udom);
1.147 albertel 4648:
1.71 ng 4649: }
1.257 albertel 4650: } elsif ($env{'form.lastSub'} eq 'all') {
4651: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.71 ng 4652: $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
1.257 albertel 4653: $env{'request.course.id'},
1.71 ng 4654: '','.submission');
4655:
4656: }
1.103 albertel 4657: if (&canmodify($usec)) {
1.585 bisitz 4658: $studentTable.=&gradeBox_start();
1.103 albertel 4659: foreach my $partid (@{$parts}) {
4660: $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
4661: $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
4662: $question++;
4663: }
1.585 bisitz 4664: $studentTable.=&gradeBox_end();
1.196 albertel 4665: $prob++;
1.71 ng 4666: }
4667: $studentTable.='</td></tr>';
1.68 ng 4668:
1.103 albertel 4669: }
1.68 ng 4670: $curRes = $iterator->next();
4671: }
4672:
1.589 bisitz 4673: $studentTable.=
4674: '</table>'."\n".
4675: '<input type="button" value="'.&mt('Save').'" '.
4676: 'onclick="javascript:checkSubmitPage(this.form,'.$question.');" />'.
4677: '</form>'."\n";
1.324 albertel 4678: $studentTable.=&show_grading_menu_form($symb);
1.71 ng 4679: $request->print($studentTable);
4680:
4681: return '';
1.119 ng 4682: }
4683:
4684: sub displaySubByDates {
1.148 albertel 4685: my ($symb,$record,$parts,$responseType,$checkIcon,$uname,$udom) = @_;
1.224 albertel 4686: my $isCODE=0;
1.335 albertel 4687: my $isTask = ($symb =~/\.task$/);
1.224 albertel 4688: if (exists($record->{'resource.CODE'})) { $isCODE=1; }
1.467 albertel 4689: my $studentTable=&Apache::loncommon::start_data_table().
4690: &Apache::loncommon::start_data_table_header_row().
4691: '<th>'.&mt('Date/Time').'</th>'.
4692: ($isCODE?'<th>'.&mt('CODE').'</th>':'').
4693: '<th>'.&mt('Submission').'</th>'.
4694: '<th>'.&mt('Status').'</th>'.
4695: &Apache::loncommon::end_data_table_header_row();
1.119 ng 4696: my ($version);
4697: my %mark;
1.148 albertel 4698: my %orders;
1.119 ng 4699: $mark{'correct_by_student'} = $checkIcon;
1.147 albertel 4700: if (!exists($$record{'1:timestamp'})) {
1.539 riegler 4701: return '<br /> <span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br />';
1.147 albertel 4702: }
1.335 albertel 4703:
4704: my $interaction;
1.525 raeburn 4705: my $no_increment = 1;
1.596.2.2 raeburn 4706: my %lastrndseed;
1.119 ng 4707: for ($version=1;$version<=$$record{'version'};$version++) {
1.467 albertel 4708: my $timestamp =
4709: &Apache::lonlocal::locallocaltime($$record{$version.':timestamp'});
1.335 albertel 4710: if (exists($$record{$version.':resource.0.version'})) {
4711: $interaction = $$record{$version.':resource.0.version'};
4712: }
4713:
4714: my $where = ($isTask ? "$version:resource.$interaction"
4715: : "$version:resource");
1.467 albertel 4716: $studentTable.=&Apache::loncommon::start_data_table_row().
4717: '<td>'.$timestamp.'</td>';
1.224 albertel 4718: if ($isCODE) {
4719: $studentTable.='<td>'.$record->{$version.':resource.CODE'}.'</td>';
4720: }
1.119 ng 4721: my @versionKeys = split(/\:/,$$record{$version.':keys'});
4722: my @displaySub = ();
4723: foreach my $partid (@{$parts}) {
1.596.2.2 raeburn 4724: my ($hidden,$type);
4725: $type = $$record{$version.':resource.'.$partid.'.type'};
4726: if (($type eq 'anonsurvey') || ($type eq 'anonsurveycred')) {
1.596 raeburn 4727: $hidden = 1;
4728: }
1.335 albertel 4729: my @matchKey = ($isTask ? sort(grep /^resource\.\d+\.\Q$partid\E\.award$/,@versionKeys)
4730: : sort(grep /^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys));
4731:
1.122 ng 4732: # next if ($$record{"$version:resource.$partid.solved"} eq '');
1.324 albertel 4733: my $display_part=&get_display_part($partid,$symb);
1.147 albertel 4734: foreach my $matchKey (@matchKey) {
1.198 albertel 4735: if (exists($$record{$version.':'.$matchKey}) &&
4736: $$record{$version.':'.$matchKey} ne '') {
1.596 raeburn 4737:
1.335 albertel 4738: my ($responseId)= ($isTask ? ($matchKey=~ /^resource\.(.*?)\.\Q$partid\E\.award$/)
4739: : ($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/));
1.577 bisitz 4740: $displaySub[0].='<span class="LC_nobreak"';
4741: $displaySub[0].='<b>'.&mt('Part: [_1]',$display_part).'</b>'
4742: .' <span class="LC_internal_info">'
1.596.2.4 raeburn 4743: .'('.&mt('Response ID: [_1]',$responseId).')'
1.577 bisitz 4744: .'</span>'
4745: .' <b>';
1.596 raeburn 4746: if ($hidden) {
4747: $displaySub[0].= &mt('Anonymous Survey').'</b>';
4748: } else {
1.596.2.2 raeburn 4749: my ($trial,$rndseed,$newvariation);
4750: if ($type eq 'randomizetry') {
4751: $trial = $$record{"$where.$partid.tries"};
4752: $rndseed = $$record{"$where.$partid.rndseed"};
4753: }
1.596 raeburn 4754: if ($$record{"$where.$partid.tries"} eq '') {
4755: $displaySub[0].=&mt('Trial not counted');
4756: } else {
4757: $displaySub[0].=&mt('Trial: [_1]',
1.467 albertel 4758: $$record{"$where.$partid.tries"});
1.596.2.2 raeburn 4759: if ($rndseed || $lastrndseed{$partid}) {
4760: if ($rndseed ne $lastrndseed{$partid}) {
4761: $newvariation = ' ('.&mt('New variation this try').')';
4762: }
4763: }
1.596 raeburn 4764: }
4765: my $responseType=($isTask ? 'Task'
1.335 albertel 4766: : $responseType->{$partid}->{$responseId});
1.596 raeburn 4767: if (!exists($orders{$partid})) { $orders{$partid}={}; }
1.596.2.2 raeburn 4768: if ((!exists($orders{$partid}->{$responseId})) || ($trial)) {
1.596 raeburn 4769: $orders{$partid}->{$responseId}=
4770: &get_order($partid,$responseId,$symb,$uname,$udom,
1.596.2.2 raeburn 4771: $no_increment,$type,$trial,$rndseed);
1.596 raeburn 4772: }
1.596.2.2 raeburn 4773: $displaySub[0].='</b>'.$newvariation.'</span>'; # /nobreak
1.596 raeburn 4774: $displaySub[0].=' '.
1.596.2.2 raeburn 4775: &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:",$uname,$udom,$type,$trial,$rndseed).'<br />';
1.596 raeburn 4776: }
1.147 albertel 4777: }
4778: }
1.335 albertel 4779: if (exists($$record{"$where.$partid.checkedin"})) {
1.485 albertel 4780: $displaySub[1].=&mt('Checked in by [_1] into slot [_2]',
4781: $$record{"$where.$partid.checkedin"},
4782: $$record{"$where.$partid.checkedin.slot"}).
4783: '<br />';
1.335 albertel 4784: }
4785: if (exists $$record{"$where.$partid.award"}) {
1.485 albertel 4786: $displaySub[1].='<b>'.&mt('Part:').'</b> '.$display_part.' '.
1.335 albertel 4787: lc($$record{"$where.$partid.award"}).' '.
4788: $mark{$$record{"$where.$partid.solved"}}.
1.147 albertel 4789: '<br />';
4790: }
1.335 albertel 4791: if (exists $$record{"$where.$partid.regrader"}) {
4792: $displaySub[2].=$$record{"$where.$partid.regrader"}.
4793: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
4794: } elsif ($$record{"$version:resource.$partid.regrader"} =~ /\S/) {
4795: $displaySub[2].=
4796: $$record{"$version:resource.$partid.regrader"}.
1.207 albertel 4797: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
1.147 albertel 4798: }
4799: }
4800: # needed because old essay regrader has not parts info
4801: if (exists $$record{"$version:resource.regrader"}) {
4802: $displaySub[2].=$$record{"$version:resource.regrader"};
4803: }
4804: $studentTable.='<td>'.$displaySub[0].' </td><td>'.$displaySub[1];
4805: if ($displaySub[2]) {
1.467 albertel 4806: $studentTable.=&mt('Manually graded by [_1]',$displaySub[2]);
1.147 albertel 4807: }
1.467 albertel 4808: $studentTable.=' </td>'.
4809: &Apache::loncommon::end_data_table_row();
1.119 ng 4810: }
1.467 albertel 4811: $studentTable.=&Apache::loncommon::end_data_table();
1.119 ng 4812: return $studentTable;
1.71 ng 4813: }
4814:
4815: sub updateGradeByPage {
4816: my ($request) = shift;
4817:
1.257 albertel 4818: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4819: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4820: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
4821: my $pageTitle = $env{'form.page'};
1.103 albertel 4822: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 4823: my ($uname,$udom) = split(/:/,$env{'form.student'});
4824: my $usec=$classlist->{$env{'form.student'}}[5];
1.103 albertel 4825: if (!&canmodify($usec)) {
1.526 raeburn 4826: $request->print('<span class="LC_warning">'.&mt('Unable to modify requested student ([_1])',$env{'form.student'}).'</span>');
1.324 albertel 4827: $request->print(&show_grading_menu_form($env{'form.symb'}));
1.103 albertel 4828: return;
4829: }
1.398 albertel 4830: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.526 raeburn 4831: $result.='<h3> '.&mt('Student: ').&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
1.129 ng 4832: '</h3>'."\n";
1.70 ng 4833:
1.68 ng 4834: $request->print($result);
4835:
1.582 raeburn 4836:
1.132 bowersj2 4837: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 4838: unless (ref($navmap)) {
4839: $request->print(&navmap_errormsg());
4840: return;
4841: }
1.257 albertel 4842: my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $env{'form.page'});
1.71 ng 4843: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 4844: if (!$map) {
1.527 raeburn 4845: $request->print('<span class="LC_warning">'.&mt('Unable to grade requested sequence ([_1]).',$resUrl).'</span>');
1.324 albertel 4846: my ($symb)=&get_symb($request);
4847: $request->print(&show_grading_menu_form($symb));
1.288 albertel 4848: return;
4849: }
1.71 ng 4850: my $iterator = $navmap->getIterator($map->map_start(),
4851: $map->map_finish());
1.70 ng 4852:
1.484 albertel 4853: my $studentTable=
4854: &Apache::loncommon::start_data_table().
4855: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 4856: '<th align="center"> '.&mt('Prob.').' </th>'.
4857: '<th> '.&mt('Title').' </th>'.
4858: '<th> '.&mt('Previous Score').' </th>'.
4859: '<th> '.&mt('New Score').' </th>'.
1.484 albertel 4860: &Apache::loncommon::end_data_table_header_row();
1.71 ng 4861:
4862: $iterator->next(); # skip the first BEGIN_MAP
4863: my $curRes = $iterator->next(); # for "current resource"
1.196 albertel 4864: my ($depth,$question,$prob,$changeflag)= (1,1,1,0);
1.101 albertel 4865: while ($depth > 0) {
1.71 ng 4866: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4867: if($curRes == $iterator->END_MAP) { $depth--; }
1.71 ng 4868:
1.385 albertel 4869: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4870: my $parts = $curRes->parts();
1.71 ng 4871: my $title = $curRes->compTitle();
4872: my $symbx = $curRes->symb();
1.484 albertel 4873: $studentTable.=
4874: &Apache::loncommon::start_data_table_row().
4875: '<td align="center" valign="top" >'.$prob.
1.485 albertel 4876: (scalar(@{$parts}) == 1 ? ''
1.596.2.2 raeburn 4877: : '<br />('.&mt('[quant,_1,part]',scalar(@{$parts}))
1.526 raeburn 4878: .')').'</td>';
1.71 ng 4879: $studentTable.='<td valign="top"> <b>'.$title.'</b> </td>';
4880:
4881: my %newrecord=();
4882: my @displayPts=();
1.269 raeburn 4883: my %aggregate = ();
4884: my $aggregateflag = 0;
1.71 ng 4885: foreach my $partid (@{$parts}) {
1.257 albertel 4886: my $newpts = $env{'form.GD_BOX'.$question.'_'.$partid};
4887: my $oldpts = $env{'form.oldpts'.$question.'_'.$partid};
1.71 ng 4888:
1.257 albertel 4889: my $wgt = $env{'form.WGT'.$question.'_'.$partid} != 0 ?
4890: $env{'form.WGT'.$question.'_'.$partid} : 1;
1.71 ng 4891: my $partial = $newpts/$wgt;
4892: my $score;
4893: if ($partial > 0) {
4894: $score = 'correct_by_override';
1.125 ng 4895: } elsif ($newpts ne '') { #empty is taken as 0
1.71 ng 4896: $score = 'incorrect_by_override';
4897: }
1.257 albertel 4898: my $dropMenu = $env{'form.GD_SEL'.$question.'_'.$partid};
1.125 ng 4899: if ($dropMenu eq 'excused') {
1.71 ng 4900: $partial = '';
4901: $score = 'excused';
1.125 ng 4902: } elsif ($dropMenu eq 'reset status'
1.257 albertel 4903: && $env{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
1.125 ng 4904: $newrecord{'resource.'.$partid.'.tries'} = 0;
4905: $newrecord{'resource.'.$partid.'.solved'} = '';
4906: $newrecord{'resource.'.$partid.'.award'} = '';
4907: $newrecord{'resource.'.$partid.'.awarded'} = 0;
1.257 albertel 4908: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 4909: $changeflag++;
4910: $newpts = '';
1.269 raeburn 4911:
4912: my $aggtries = $env{'form.aggtries'.$question.'_'.$partid};
4913: my $totaltries = $env{'form.totaltries'.$question.'_'.$partid};
4914: my $solvedstatus = $env{'form.solved'.$question.'_'.$partid};
4915: if ($aggtries > 0) {
4916: &decrement_aggs($symbx,$partid,\%aggregate,$aggtries,$totaltries,$solvedstatus);
4917: $aggregateflag = 1;
4918: }
1.71 ng 4919: }
1.324 albertel 4920: my $display_part=&get_display_part($partid,$curRes->symb());
1.257 albertel 4921: my $oldstatus = $env{'form.solved'.$question.'_'.$partid};
1.526 raeburn 4922: $displayPts[0].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.71 ng 4923: (($oldstatus eq 'excused') ? 'excused' : $oldpts).
1.326 albertel 4924: ' <br />';
1.526 raeburn 4925: $displayPts[1].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.125 ng 4926: (($score eq 'excused') ? 'excused' : $newpts).
1.326 albertel 4927: ' <br />';
1.71 ng 4928: $question++;
1.380 albertel 4929: next if ($dropMenu eq 'reset status' || ($newpts eq $oldpts && $score ne 'excused'));
1.125 ng 4930:
1.71 ng 4931: $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
1.125 ng 4932: $newrecord{'resource.'.$partid.'.solved'} = $score if $score ne '';
1.257 albertel 4933: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}"
1.125 ng 4934: if (scalar(keys(%newrecord)) > 0);
1.71 ng 4935:
4936: $changeflag++;
4937: }
4938: if (scalar(keys(%newrecord)) > 0) {
1.382 albertel 4939: my %record =
4940: &Apache::lonnet::restore($symbx,$env{'request.course.id'},
4941: $udom,$uname);
4942:
4943: if (&Apache::lonnet::validCODE($env{'form.CODE'})) {
4944: $newrecord{'resource.CODE'} = $env{'form.CODE'};
4945: } elsif (&Apache::lonnet::validCODE($record{'resource.CODE'})) {
4946: $newrecord{'resource.CODE'} = '';
4947: }
1.257 albertel 4948: &Apache::lonnet::cstore(\%newrecord,$symbx,$env{'request.course.id'},
1.71 ng 4949: $udom,$uname);
1.382 albertel 4950: %record = &Apache::lonnet::restore($symbx,
4951: $env{'request.course.id'},
4952: $udom,$uname);
1.380 albertel 4953: &check_and_remove_from_queue($parts,\%record,undef,$symbx,
4954: $cdom,$cnum,$udom,$uname);
1.71 ng 4955: }
1.380 albertel 4956:
1.269 raeburn 4957: if ($aggregateflag) {
4958: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
4959: $env{'course.'.$env{'request.course.id'}.'.domain'},
4960: $env{'course.'.$env{'request.course.id'}.'.num'});
4961: }
1.125 ng 4962:
1.71 ng 4963: $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
4964: '<td valign="top">'.$displayPts[1].'</td>'.
1.484 albertel 4965: &Apache::loncommon::end_data_table_row();
1.68 ng 4966:
1.196 albertel 4967: $prob++;
1.68 ng 4968: }
1.71 ng 4969: $curRes = $iterator->next();
1.68 ng 4970: }
1.98 albertel 4971:
1.484 albertel 4972: $studentTable.=&Apache::loncommon::end_data_table();
1.324 albertel 4973: $studentTable.=&show_grading_menu_form($env{'form.symb'});
1.526 raeburn 4974: my $grademsg=($changeflag == 0 ? &mt('No score was changed or updated.') :
4975: &mt('The scores were changed for [quant,_1,problem].',
4976: $changeflag));
1.76 ng 4977: $request->print($grademsg.$studentTable);
1.68 ng 4978:
1.70 ng 4979: return '';
4980: }
4981:
1.72 ng 4982: #-------- end of section for handling grading by page/sequence ---------
4983: #
4984: #-------------------------------------------------------------------
4985:
1.581 www 4986: #-------------------- Bubblesheet (Scantron) Grading -------------------
1.75 albertel 4987: #
4988: #------ start of section for handling grading by page/sequence ---------
4989:
1.423 albertel 4990: =pod
4991:
4992: =head1 Bubble sheet grading routines
4993:
1.424 albertel 4994: For this documentation:
4995:
4996: 'scanline' refers to the full line of characters
4997: from the file that we are parsing that represents one entire sheet
4998:
4999: 'bubble line' refers to the data
1.596.2.6 raeburn 5000: representing the line of bubbles that are on the physical bubblesheet
1.424 albertel 5001:
5002:
1.596.2.6 raeburn 5003: The overall process is that a scanned in bubblesheet data is uploaded
1.424 albertel 5004: into a course. When a user wants to grade, they select a
1.596.2.6 raeburn 5005: sequence/folder of resources, a file of bubblesheet info, and pick
1.424 albertel 5006: one of the predefined configurations for what each scanline looks
5007: like.
5008:
5009: Next each scanline is checked for any errors of either 'missing
1.435 foxr 5010: bubbles' (it's an error because it may have been mis-scanned
1.424 albertel 5011: because too light bubbling), 'double bubble' (each bubble line should
5012: have no more that one letter picked), invalid or duplicated CODE,
1.556 weissno 5013: invalid student/employee ID
1.424 albertel 5014:
5015: If the CODE option is used that determines the randomization of the
1.556 weissno 5016: homework problems, either way the student/employee ID is looked up into a
1.424 albertel 5017: username:domain.
5018:
5019: During the validation phase the instructor can choose to skip scanlines.
5020:
1.596.2.6 raeburn 5021: After the validation phase, there are now 3 bubblesheet files
1.424 albertel 5022:
5023: scantron_original_filename (unmodified original file)
5024: scantron_corrected_filename (file where the corrected information has replaced the original information)
5025: scantron_skipped_filename (contains the exact text of scanlines that where skipped)
5026:
5027: Also there is a separate hash nohist_scantrondata that contains extra
1.596.2.6 raeburn 5028: correction information that isn't representable in the bubblesheet
1.424 albertel 5029: file (see &scantron_getfile() for more information)
5030:
5031: After all scanlines are either valid, marked as valid or skipped, then
5032: foreach line foreach problem in the picked sequence, an ssi request is
5033: made that simulates a user submitting their selected letter(s) against
5034: the homework problem.
1.423 albertel 5035:
5036: =over 4
5037:
5038:
5039:
5040: =item defaultFormData
5041:
5042: Returns html hidden inputs used to hold context/default values.
5043:
5044: Arguments:
5045: $symb - $symb of the current resource
5046:
5047: =cut
1.422 foxr 5048:
1.81 albertel 5049: sub defaultFormData {
1.324 albertel 5050: my ($symb)=@_;
1.447 foxr 5051: return '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 5052: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
5053: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.81 albertel 5054: }
5055:
1.447 foxr 5056:
1.423 albertel 5057: =pod
5058:
5059: =item getSequenceDropDown
5060:
5061: Return html dropdown of possible sequences to grade
5062:
5063: Arguments:
1.582 raeburn 5064: $symb - $symb of the current resource
5065: $map_error - ref to scalar which will container error if
5066: $navmap object is unavailable in &getSymbMap().
1.423 albertel 5067:
5068: =cut
1.422 foxr 5069:
1.75 albertel 5070: sub getSequenceDropDown {
1.582 raeburn 5071: my ($symb,$map_error)=@_;
1.75 albertel 5072: my $result='<select name="selectpage">'."\n";
1.582 raeburn 5073: my ($titles,$symbx) = &getSymbMap($map_error);
5074: if (ref($map_error)) {
5075: return if ($$map_error);
5076: }
1.137 albertel 5077: my ($curpage)=&Apache::lonnet::decode_symb($symb);
1.75 albertel 5078: my $ctr=0;
5079: foreach (@$titles) {
5080: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
5081: $result.='<option value="'.$$symbx{$_}.'" '.
1.401 albertel 5082: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.75 albertel 5083: '>'.$showtitle.'</option>'."\n";
5084: $ctr++;
5085: }
5086: $result.= '</select>';
5087: return $result;
5088: }
5089:
1.495 albertel 5090: my %bubble_lines_per_response; # no. bubble lines for each response.
1.554 raeburn 5091: # key is zero-based index - 0, 1, 2 ...
1.495 albertel 5092:
5093: my %first_bubble_line; # First bubble line no. for each bubble.
5094:
1.509 raeburn 5095: my %subdivided_bubble_lines; # no. bubble lines for optionresponse,
5096: # matchresponse or rankresponse, where
5097: # an individual response can have multiple
5098: # lines
1.503 raeburn 5099:
5100: my %responsetype_per_response; # responsetype for each response
5101:
1.495 albertel 5102: # Save and restore the bubble lines array to the form env.
5103:
5104:
5105: sub save_bubble_lines {
5106: foreach my $line (keys(%bubble_lines_per_response)) {
5107: $env{"form.scantron.bubblelines.$line"} = $bubble_lines_per_response{$line};
5108: $env{"form.scantron.first_bubble_line.$line"} =
5109: $first_bubble_line{$line};
1.503 raeburn 5110: $env{"form.scantron.sub_bubblelines.$line"} =
5111: $subdivided_bubble_lines{$line};
5112: $env{"form.scantron.responsetype.$line"} =
5113: $responsetype_per_response{$line};
1.495 albertel 5114: }
5115: }
5116:
5117:
5118: sub restore_bubble_lines {
5119: my $line = 0;
5120: %bubble_lines_per_response = ();
5121: while ($env{"form.scantron.bubblelines.$line"}) {
5122: my $value = $env{"form.scantron.bubblelines.$line"};
5123: $bubble_lines_per_response{$line} = $value;
5124: $first_bubble_line{$line} =
5125: $env{"form.scantron.first_bubble_line.$line"};
1.503 raeburn 5126: $subdivided_bubble_lines{$line} =
5127: $env{"form.scantron.sub_bubblelines.$line"};
5128: $responsetype_per_response{$line} =
5129: $env{"form.scantron.responsetype.$line"};
1.495 albertel 5130: $line++;
5131: }
5132: }
5133:
5134: # Given the parsed scanline, get the response for
5135: # 'answer' number n:
5136:
5137: sub get_response_bubbles {
5138: my ($parsed_line, $response) = @_;
5139:
5140: my $bubble_line = $first_bubble_line{$response-1} +1;
5141: my $bubble_lines= $bubble_lines_per_response{$response-1};
5142:
5143: my $selected = "";
5144:
5145: for (my $bline = 0; $bline < $bubble_lines; $bline++) {
5146: $selected .= $$parsed_line{"scantron.$bubble_line.answer"}.":";
5147: $bubble_line++;
5148: }
5149: return $selected;
5150: }
1.423 albertel 5151:
5152: =pod
5153:
5154: =item scantron_filenames
5155:
5156: Returns a list of the scantron files in the current course
5157:
5158: =cut
1.422 foxr 5159:
1.202 albertel 5160: sub scantron_filenames {
1.257 albertel 5161: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5162: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
1.517 raeburn 5163: my $getpropath = 1;
1.157 albertel 5164: my @files=&Apache::lonnet::dirlist('userfiles',$cdom,$cname,
1.517 raeburn 5165: $getpropath);
1.202 albertel 5166: my @possiblenames;
1.201 albertel 5167: foreach my $filename (sort(@files)) {
1.157 albertel 5168: ($filename)=split(/&/,$filename);
5169: if ($filename!~/^scantron_orig_/) { next ; }
5170: $filename=~s/^scantron_orig_//;
1.202 albertel 5171: push(@possiblenames,$filename);
5172: }
5173: return @possiblenames;
5174: }
5175:
1.423 albertel 5176: =pod
5177:
5178: =item scantron_uploads
5179:
5180: Returns html drop-down list of scantron files in current course.
5181:
5182: Arguments:
5183: $file2grade - filename to set as selected in the dropdown
5184:
5185: =cut
1.422 foxr 5186:
1.202 albertel 5187: sub scantron_uploads {
1.209 ng 5188: my ($file2grade) = @_;
1.202 albertel 5189: my $result= '<select name="scantron_selectfile">';
5190: $result.="<option></option>";
5191: foreach my $filename (sort(&scantron_filenames())) {
1.401 albertel 5192: $result.="<option".($filename eq $file2grade ? ' selected="selected"':'').">$filename</option>\n";
1.81 albertel 5193: }
5194: $result.="</select>";
5195: return $result;
5196: }
5197:
1.423 albertel 5198: =pod
5199:
5200: =item scantron_scantab
5201:
5202: Returns html drop down of the scantron formats in the scantronformat.tab
5203: file.
5204:
5205: =cut
1.422 foxr 5206:
1.82 albertel 5207: sub scantron_scantab {
5208: my $result='<select name="scantron_format">'."\n";
1.191 albertel 5209: $result.='<option></option>'."\n";
1.518 raeburn 5210: my @lines = &get_scantronformat_file();
5211: if (@lines > 0) {
5212: foreach my $line (@lines) {
5213: next if (($line =~ /^\#/) || ($line eq ''));
5214: my ($name,$descrip)=split(/:/,$line);
5215: $result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
5216: }
1.82 albertel 5217: }
5218: $result.='</select>'."\n";
1.518 raeburn 5219: return $result;
5220: }
5221:
5222: =pod
5223:
5224: =item get_scantronformat_file
5225:
5226: Returns an array containing lines from the scantron format file for
5227: the domain of the course.
5228:
5229: If a url for a custom.tab file is listed in domain's configuration.db,
5230: lines are from this file.
5231:
5232: Otherwise, if a default.tab has been published in RES space by the
5233: domainconfig user, lines are from this file.
5234:
5235: Otherwise, fall back to getting lines from the legacy file on the
1.519 raeburn 5236: local server: /home/httpd/lonTabs/default_scantronformat.tab
1.82 albertel 5237:
1.518 raeburn 5238: =cut
5239:
5240: sub get_scantronformat_file {
5241: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
5242: my %domconfig = &Apache::lonnet::get_dom('configuration',['scantron'],$cdom);
5243: my $gottab = 0;
5244: my @lines;
5245: if (ref($domconfig{'scantron'}) eq 'HASH') {
5246: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
5247: my $formatfile = &Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.$domconfig{'scantron'}{'scantronformat'});
5248: if ($formatfile ne '-1') {
5249: @lines = split("\n",$formatfile,-1);
5250: $gottab = 1;
5251: }
5252: }
5253: }
5254: if (!$gottab) {
5255: my $confname = $cdom.'-domainconfig';
5256: my $default = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res/'.$cdom.'/'.$confname.'/default.tab';
5257: my $formatfile = &Apache::lonnet::getfile($default);
5258: if ($formatfile ne '-1') {
5259: @lines = split("\n",$formatfile,-1);
5260: $gottab = 1;
5261: }
5262: }
5263: if (!$gottab) {
1.519 raeburn 5264: my @domains = &Apache::lonnet::current_machine_domains();
5265: if (grep(/^\Q$cdom\E$/,@domains)) {
5266: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
5267: @lines = <$fh>;
5268: close($fh);
5269: } else {
5270: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab');
5271: @lines = <$fh>;
5272: close($fh);
5273: }
1.518 raeburn 5274: }
5275: return @lines;
1.82 albertel 5276: }
5277:
1.423 albertel 5278: =pod
5279:
5280: =item scantron_CODElist
5281:
5282: Returns html drop down of the saved CODE lists from current course,
5283: generated from earlier printings.
5284:
5285: =cut
1.422 foxr 5286:
1.186 albertel 5287: sub scantron_CODElist {
1.257 albertel 5288: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5289: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.186 albertel 5290: my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
5291: my $namechoice='<option></option>';
1.225 albertel 5292: foreach my $name (sort {uc($a) cmp uc($b)} @names) {
1.191 albertel 5293: if ($name =~ /^error: 2 /) { next; }
1.278 albertel 5294: if ($name =~ /^type\0/) { next; }
1.186 albertel 5295: $namechoice.='<option value="'.$name.'">'.$name.'</option>';
5296: }
5297: $namechoice='<select name="scantron_CODElist">'.$namechoice.'</select>';
5298: return $namechoice;
5299: }
5300:
1.423 albertel 5301: =pod
5302:
5303: =item scantron_CODEunique
5304:
5305: Returns the html for "Each CODE to be used once" radio.
5306:
5307: =cut
1.422 foxr 5308:
1.186 albertel 5309: sub scantron_CODEunique {
1.532 bisitz 5310: my $result='<span class="LC_nobreak">
1.272 albertel 5311: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 5312: value="yes" checked="checked" />'.&mt('Yes').' </label>
1.381 albertel 5313: </span>
1.532 bisitz 5314: <span class="LC_nobreak">
1.272 albertel 5315: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 5316: value="no" />'.&mt('No').' </label>
1.381 albertel 5317: </span>';
1.186 albertel 5318: return $result;
5319: }
1.423 albertel 5320:
5321: =pod
5322:
5323: =item scantron_selectphase
5324:
1.596.2.6 raeburn 5325: Generates the initial screen to start the bubblesheet process.
1.423 albertel 5326: Allows for - starting a grading run.
1.424 albertel 5327: - downloading existing scan data (original, corrected
1.423 albertel 5328: or skipped info)
5329:
5330: - uploading new scan data
5331:
5332: Arguments:
5333: $r - The Apache request object
5334: $file2grade - name of the file that contain the scanned data to score
5335:
5336: =cut
1.186 albertel 5337:
1.75 albertel 5338: sub scantron_selectphase {
1.209 ng 5339: my ($r,$file2grade) = @_;
1.324 albertel 5340: my ($symb)=&get_symb($r);
1.75 albertel 5341: if (!$symb) {return '';}
1.582 raeburn 5342: my $map_error;
5343: my $sequence_selector=&getSequenceDropDown($symb,\$map_error);
5344: if ($map_error) {
5345: $r->print('<br />'.&navmap_errormsg().'<br />');
5346: return;
5347: }
1.324 albertel 5348: my $default_form_data=&defaultFormData($symb);
5349: my $grading_menu_button=&show_grading_menu_form($symb);
1.209 ng 5350: my $file_selector=&scantron_uploads($file2grade);
1.82 albertel 5351: my $format_selector=&scantron_scantab();
1.186 albertel 5352: my $CODE_selector=&scantron_CODElist();
5353: my $CODE_unique=&scantron_CODEunique();
1.75 albertel 5354: my $result;
1.422 foxr 5355:
1.513 foxr 5356: $ssi_error = 0;
5357:
1.596.2.4 raeburn 5358: if (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) ||
5359: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
5360:
5361: # Chunk of form to prompt for a scantron file upload.
5362:
5363: $r->print('
5364: <br />
5365: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5366: '.&Apache::loncommon::start_data_table_header_row().'
5367: <th>
5368: '.&mt('Specify a bubblesheet data file to upload.').'
5369: </th>
5370: '.&Apache::loncommon::end_data_table_header_row().'
5371: '.&Apache::loncommon::start_data_table_row().'
5372: <td>
5373: ');
5374: my $default_form_data=&defaultFormData(&get_symb($r,1));
5375: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
5376: my $cnum= $env{'course.'.$env{'request.course.id'}.'.num'};
5377: $r->print('
5378: <script type="text/javascript" language="javascript">
5379: function checkUpload(formname) {
5380: if (formname.upfile.value == "") {
5381: alert("'.&mt('Please use the browse button to select a file from your local directory.').'");
5382: return false;
5383: }
5384: formname.submit();
5385: }
5386: </script>
5387:
5388: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
5389: '.$default_form_data.'
5390: <input name="courseid" type="hidden" value="'.$cnum.'" />
5391: <input name="domainid" type="hidden" value="'.$cdom.'" />
5392: <input name="command" value="scantronupload_save" type="hidden" />
5393: '.&mt('File to upload: [_1]','<input type="file" name="upfile" size="50" />').'
5394: <br />
5395: <input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
5396: </form>
5397: ');
5398:
5399: $r->print('
5400: </td>
5401: '.&Apache::loncommon::end_data_table_row().'
5402: '.&Apache::loncommon::end_data_table().'
5403: ');
5404: }
5405:
1.422 foxr 5406: # Chunk of form to prompt for a file to grade and how:
5407:
1.489 albertel 5408: $result.= '
5409: <br />
5410: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantron_process">
5411: <input type="hidden" name="command" value="scantron_warning" />
5412: '.$default_form_data.'
5413: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5414: '.&Apache::loncommon::start_data_table_header_row().'
5415: <th colspan="2">
1.492 albertel 5416: '.&mt('Specify file and which Folder/Sequence to grade').'
1.489 albertel 5417: </th>
5418: '.&Apache::loncommon::end_data_table_header_row().'
5419: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5420: <td> '.&mt('Sequence to grade:').' </td><td> '.$sequence_selector.' </td>
1.489 albertel 5421: '.&Apache::loncommon::end_data_table_row().'
5422: '.&Apache::loncommon::start_data_table_row().'
1.572 www 5423: <td> '.&mt('Filename of bubblesheet data file:').' </td><td> '.$file_selector.' </td>
1.489 albertel 5424: '.&Apache::loncommon::end_data_table_row().'
5425: '.&Apache::loncommon::start_data_table_row().'
1.572 www 5426: <td> '.&mt('Format of bubblesheet data file:').' </td><td> '.$format_selector.' </td>
1.489 albertel 5427: '.&Apache::loncommon::end_data_table_row().'
5428: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5429: <td> '.&mt('Saved CODEs to validate against:').' </td><td> '.$CODE_selector.' </td>
1.489 albertel 5430: '.&Apache::loncommon::end_data_table_row().'
5431: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5432: <td> '.&mt('Each CODE is only to be used once:').'</td><td> '.$CODE_unique.' </td>
1.489 albertel 5433: '.&Apache::loncommon::end_data_table_row().'
5434: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5435: <td> '.&mt('Options:').' </td>
1.187 albertel 5436: <td>
1.492 albertel 5437: <label><input type="checkbox" name="scantron_options_redo" value="redo_skipped"/> '.&mt('Do only previously skipped records').'</label> <br />
5438: <label><input type="checkbox" name="scantron_options_ignore" value="ignore_corrections"/> '.&mt('Remove all existing corrections').'</label> <br />
5439: <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources when grading').'</label>
1.187 albertel 5440: </td>
1.489 albertel 5441: '.&Apache::loncommon::end_data_table_row().'
5442: '.&Apache::loncommon::start_data_table_row().'
1.174 albertel 5443: <td colspan="2">
1.572 www 5444: <input type="submit" value="'.&mt('Grading: Validate Bubblesheet Records').'" />
1.162 albertel 5445: </td>
1.489 albertel 5446: '.&Apache::loncommon::end_data_table_row().'
5447: '.&Apache::loncommon::end_data_table().'
5448: </form>
5449: ';
1.162 albertel 5450:
5451: $r->print($result);
5452:
1.422 foxr 5453: # Chunk of the form that prompts to view a scoring office file,
5454: # corrected file, skipped records in a file.
5455:
1.489 albertel 5456: $r->print('
5457: <br />
5458: <form action="/adm/grades" name="scantron_download">
5459: '.$default_form_data.'
5460: <input type="hidden" name="command" value="scantron_download" />
5461: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5462: '.&Apache::loncommon::start_data_table_header_row().'
5463: <th>
1.492 albertel 5464: '.&mt('Download a scoring office file').'
1.489 albertel 5465: </th>
5466: '.&Apache::loncommon::end_data_table_header_row().'
5467: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5468: <td> '.&mt('Filename of scoring office file: [_1]',$file_selector).'
1.489 albertel 5469: <br />
1.492 albertel 5470: <input type="submit" value="'.&mt('Download: Show List of Associated Files').'" />
1.489 albertel 5471: '.&Apache::loncommon::end_data_table_row().'
5472: '.&Apache::loncommon::end_data_table().'
5473: </form>
5474: <br />
5475: ');
1.162 albertel 5476:
1.457 banghart 5477: &Apache::lonpickcode::code_list($r,2);
1.523 raeburn 5478:
1.528 raeburn 5479: $r->print('<br /><form method="post" name="checkscantron">'.
1.523 raeburn 5480: $default_form_data."\n".
5481: &Apache::loncommon::start_data_table('LC_scantron_action')."\n".
5482: &Apache::loncommon::start_data_table_header_row()."\n".
5483: '<th colspan="2">
1.572 www 5484: '.&mt('Review bubblesheet data and submissions for a previously graded folder/sequence')."\n".
1.523 raeburn 5485: '</th>'."\n".
5486: &Apache::loncommon::end_data_table_header_row()."\n".
5487: &Apache::loncommon::start_data_table_row()."\n".
5488: '<td> '.&mt('Graded folder/sequence:').' </td>'."\n".
5489: '<td> '.$sequence_selector.' </td>'.
5490: &Apache::loncommon::end_data_table_row()."\n".
5491: &Apache::loncommon::start_data_table_row()."\n".
5492: '<td> '.&mt('Filename of scoring office file:').' </td>'."\n".
5493: '<td> '.$file_selector.' </td>'."\n".
5494: &Apache::loncommon::end_data_table_row()."\n".
5495: &Apache::loncommon::start_data_table_row()."\n".
5496: '<td> '.&mt('Format of data file:').' </td>'."\n".
5497: '<td> '.$format_selector.' </td>'."\n".
5498: &Apache::loncommon::end_data_table_row()."\n".
5499: &Apache::loncommon::start_data_table_row()."\n".
1.557 raeburn 5500: '<td> '.&mt('Options').' </td>'."\n".
5501: '<td> <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources').'</label></td>'.
5502: &Apache::loncommon::end_data_table_row()."\n".
5503: &Apache::loncommon::start_data_table_row()."\n".
1.523 raeburn 5504: '<td colspan="2">'."\n".
5505: '<input type="hidden" name="command" value="checksubmissions" />'."\n".
1.575 www 5506: '<input type="submit" value="'.&mt('Review Bubblesheet Data and Submission Records').'" />'."\n".
1.523 raeburn 5507: '</td>'."\n".
5508: &Apache::loncommon::end_data_table_row()."\n".
5509: &Apache::loncommon::end_data_table()."\n".
5510: '</form><br />');
1.457 banghart 5511: $r->print($grading_menu_button);
1.523 raeburn 5512: return;
1.75 albertel 5513: }
5514:
1.423 albertel 5515: =pod
5516:
5517: =item get_scantron_config
5518:
5519: Parse and return the scantron configuration line selected as a
5520: hash of configuration file fields.
5521:
5522: Arguments:
5523: which - the name of the configuration to parse from the file.
5524:
5525:
5526: Returns:
5527: If the named configuration is not in the file, an empty
5528: hash is returned.
5529: a hash with the fields
5530: name - internal name for the this configuration setup
5531: description - text to display to operator that describes this config
5532: CODElocation - if 0 or the string 'none'
5533: - no CODE exists for this config
5534: if -1 || the string 'letter'
5535: - a CODE exists for this config and is
5536: a string of letters
5537: Unsupported value (but planned for future support)
5538: if a positive integer
5539: - The CODE exists as the first n items from
5540: the question section of the form
5541: if the string 'number'
5542: - The CODE exists for this config and is
5543: a string of numbers
5544: CODEstart - (only matter if a CODE exists) column in the line where
5545: the CODE starts
5546: CODElength - length of the CODE
1.573 bisitz 5547: IDstart - column where the student/employee ID starts
1.556 weissno 5548: IDlength - length of the student/employee ID info
1.423 albertel 5549: Qstart - column where the information from the bubbled
5550: 'questions' start
5551: Qlength - number of columns comprising a single bubble line from
5552: the sheet. (usually either 1 or 10)
1.424 albertel 5553: Qon - either a single character representing the character used
1.423 albertel 5554: to signal a bubble was chosen in the positional setup, or
5555: the string 'letter' if the letter of the chosen bubble is
5556: in the final, or 'number' if a number representing the
5557: chosen bubble is in the file (1->A 0->J)
1.424 albertel 5558: Qoff - the character used to represent that a bubble was
5559: left blank
1.423 albertel 5560: PaperID - if the scanning process generates a unique number for each
5561: sheet scanned the column that this ID number starts in
5562: PaperIDlength - number of columns that comprise the unique ID number
5563: for the sheet of paper
1.424 albertel 5564: FirstName - column that the first name starts in
1.423 albertel 5565: FirstNameLength - number of columns that the first name spans
5566:
5567: LastName - column that the last name starts in
5568: LastNameLength - number of columns that the last name spans
1.596.2.12.2. (raeburn 5569:): BubblesPerRow - number of bubbles available in each row used to
5570:): bubble an answer. (If not specified, 10 assumed).
1.423 albertel 5571:
5572: =cut
1.422 foxr 5573:
1.82 albertel 5574: sub get_scantron_config {
5575: my ($which) = @_;
1.518 raeburn 5576: my @lines = &get_scantronformat_file();
1.82 albertel 5577: my %config;
1.157 albertel 5578: #FIXME probably should move to XML it has already gotten a bit much now
1.518 raeburn 5579: foreach my $line (@lines) {
1.82 albertel 5580: my ($name,$descrip)=split(/:/,$line);
5581: if ($name ne $which ) { next; }
5582: chomp($line);
5583: my @config=split(/:/,$line);
5584: $config{'name'}=$config[0];
5585: $config{'description'}=$config[1];
5586: $config{'CODElocation'}=$config[2];
5587: $config{'CODEstart'}=$config[3];
5588: $config{'CODElength'}=$config[4];
5589: $config{'IDstart'}=$config[5];
5590: $config{'IDlength'}=$config[6];
5591: $config{'Qstart'}=$config[7];
1.497 foxr 5592: $config{'Qlength'}=$config[8];
1.82 albertel 5593: $config{'Qoff'}=$config[9];
5594: $config{'Qon'}=$config[10];
1.157 albertel 5595: $config{'PaperID'}=$config[11];
5596: $config{'PaperIDlength'}=$config[12];
5597: $config{'FirstName'}=$config[13];
5598: $config{'FirstNamelength'}=$config[14];
5599: $config{'LastName'}=$config[15];
5600: $config{'LastNamelength'}=$config[16];
1.596.2.12.2. (raeburn 5601:): $config{'BubblesPerRow'}=$config[17];
1.82 albertel 5602: last;
5603: }
5604: return %config;
5605: }
5606:
1.423 albertel 5607: =pod
5608:
5609: =item username_to_idmap
5610:
1.556 weissno 5611: creates a hash keyed by student/employee ID with values of the corresponding
1.423 albertel 5612: student username:domain.
5613:
5614: Arguments:
5615:
5616: $classlist - reference to the class list hash. This is a hash
5617: keyed by student name:domain whose elements are references
1.424 albertel 5618: to arrays containing various chunks of information
1.423 albertel 5619: about the student. (See loncoursedata for more info).
5620:
5621: Returns
5622: %idmap - the constructed hash
5623:
5624: =cut
5625:
1.82 albertel 5626: sub username_to_idmap {
5627: my ($classlist)= @_;
5628: my %idmap;
5629: foreach my $student (keys(%$classlist)) {
5630: $idmap{$classlist->{$student}->[&Apache::loncoursedata::CL_ID]}=
5631: $student;
5632: }
5633: return %idmap;
5634: }
1.423 albertel 5635:
5636: =pod
5637:
1.424 albertel 5638: =item scantron_fixup_scanline
1.423 albertel 5639:
5640: Process a requested correction to a scanline.
5641:
5642: Arguments:
5643: $scantron_config - hash from &get_scantron_config()
5644: $scan_data - hash of correction information
5645: (see &scantron_getfile())
5646: $line - existing scanline
5647: $whichline - line number of the passed in scanline
5648: $field - type of change to process
5649: (either
1.573 bisitz 5650: 'ID' -> correct the student/employee ID
1.423 albertel 5651: 'CODE' -> correct the CODE
5652: 'answer' -> fixup the submitted answers)
5653:
5654: $args - hash of additional info,
5655: - 'ID'
5656: 'newid' -> studentID to use in replacement
1.424 albertel 5657: of existing one
1.423 albertel 5658: - 'CODE'
5659: 'CODE_ignore_dup' - set to true if duplicates
5660: should be ignored.
5661: 'CODE' - is new code or 'use_unfound'
1.424 albertel 5662: if the existing unfound code should
1.423 albertel 5663: be used as is
5664: - 'answer'
5665: 'response' - new answer or 'none' if blank
5666: 'question' - the bubble line to change
1.503 raeburn 5667: 'questionnum' - the question identifier,
5668: may include subquestion.
1.423 albertel 5669:
5670: Returns:
5671: $line - the modified scanline
5672:
5673: Side effects:
5674: $scan_data - may be updated
5675:
5676: =cut
5677:
1.82 albertel 5678:
1.157 albertel 5679: sub scantron_fixup_scanline {
5680: my ($scantron_config,$scan_data,$line,$whichline,$field,$args)=@_;
5681: if ($field eq 'ID') {
5682: if (length($args->{'newid'}) > $$scantron_config{'IDlength'}) {
1.186 albertel 5683: return ($line,1,'New value too large');
1.157 albertel 5684: }
5685: if (length($args->{'newid'}) < $$scantron_config{'IDlength'}) {
5686: $args->{'newid'}=sprintf('%-'.$$scantron_config{'IDlength'}.'s',
5687: $args->{'newid'});
5688: }
5689: substr($line,$$scantron_config{'IDstart'}-1,
5690: $$scantron_config{'IDlength'})=$args->{'newid'};
5691: if ($args->{'newid'}=~/^\s*$/) {
5692: &scan_data($scan_data,"$whichline.user",
5693: $args->{'username'}.':'.$args->{'domain'});
5694: }
1.186 albertel 5695: } elsif ($field eq 'CODE') {
1.192 albertel 5696: if ($args->{'CODE_ignore_dup'}) {
5697: &scan_data($scan_data,"$whichline.CODE_ignore_dup",'1');
5698: }
5699: &scan_data($scan_data,"$whichline.useCODE",'1');
5700: if ($args->{'CODE'} ne 'use_unfound') {
1.191 albertel 5701: if (length($args->{'CODE'}) > $$scantron_config{'CODElength'}) {
5702: return ($line,1,'New CODE value too large');
5703: }
5704: if (length($args->{'CODE'}) < $$scantron_config{'CODElength'}) {
5705: $args->{'CODE'}=sprintf('%-'.$$scantron_config{'CODElength'}.'s',$args->{'CODE'});
5706: }
5707: substr($line,$$scantron_config{'CODEstart'}-1,
5708: $$scantron_config{'CODElength'})=$args->{'CODE'};
1.186 albertel 5709: }
1.157 albertel 5710: } elsif ($field eq 'answer') {
1.497 foxr 5711: my $length=$scantron_config->{'Qlength'};
1.157 albertel 5712: my $off=$scantron_config->{'Qoff'};
5713: my $on=$scantron_config->{'Qon'};
1.497 foxr 5714: my $answer=${off}x$length;
5715: if ($args->{'response'} eq 'none') {
5716: &scan_data($scan_data,
1.503 raeburn 5717: "$whichline.no_bubble.".$args->{'questionnum'},'1');
1.497 foxr 5718: } else {
5719: if ($on eq 'letter') {
5720: my @alphabet=('A'..'Z');
5721: $answer=$alphabet[$args->{'response'}];
5722: } elsif ($on eq 'number') {
5723: $answer=$args->{'response'}+1;
5724: if ($answer == 10) { $answer = '0'; }
1.274 albertel 5725: } else {
1.497 foxr 5726: substr($answer,$args->{'response'},1)=$on;
1.274 albertel 5727: }
1.497 foxr 5728: &scan_data($scan_data,
1.503 raeburn 5729: "$whichline.no_bubble.".$args->{'questionnum'},undef,'1');
1.157 albertel 5730: }
1.497 foxr 5731: my $where=$length*($args->{'question'}-1)+$scantron_config->{'Qstart'};
5732: substr($line,$where-1,$length)=$answer;
1.157 albertel 5733: }
5734: return $line;
5735: }
1.423 albertel 5736:
5737: =pod
5738:
5739: =item scan_data
5740:
5741: Edit or look up an item in the scan_data hash.
5742:
5743: Arguments:
5744: $scan_data - The hash (see scantron_getfile)
5745: $key - shorthand of the key to edit (actual key is
1.424 albertel 5746: scantronfilename_key).
1.423 albertel 5747: $data - New value of the hash entry.
5748: $delete - If true, the entry is removed from the hash.
5749:
5750: Returns:
5751: The new value of the hash table field (undefined if deleted).
5752:
5753: =cut
5754:
5755:
1.157 albertel 5756: sub scan_data {
5757: my ($scan_data,$key,$value,$delete)=@_;
1.257 albertel 5758: my $filename=$env{'form.scantron_selectfile'};
1.157 albertel 5759: if (defined($value)) {
5760: $scan_data->{$filename.'_'.$key} = $value;
5761: }
5762: if ($delete) { delete($scan_data->{$filename.'_'.$key}); }
5763: return $scan_data->{$filename.'_'.$key};
5764: }
1.423 albertel 5765:
1.495 albertel 5766: # ----- These first few routines are general use routines.----
5767:
5768: # Return the number of occurences of a pattern in a string.
5769:
5770: sub occurence_count {
5771: my ($string, $pattern) = @_;
5772:
5773: my @matches = ($string =~ /$pattern/g);
5774:
5775: return scalar(@matches);
5776: }
5777:
5778:
5779: # Take a string known to have digits and convert all the
5780: # digits into letters in the range J,A..I.
5781:
5782: sub digits_to_letters {
5783: my ($input) = @_;
5784:
5785: my @alphabet = ('J', 'A'..'I');
5786:
5787: my @input = split(//, $input);
5788: my $output ='';
5789: for (my $i = 0; $i < scalar(@input); $i++) {
5790: if ($input[$i] =~ /\d/) {
5791: $output .= $alphabet[$input[$i]];
5792: } else {
5793: $output .= $input[$i];
5794: }
5795: }
5796: return $output;
5797: }
5798:
1.423 albertel 5799: =pod
5800:
5801: =item scantron_parse_scanline
5802:
5803: Decodes a scanline from the selected scantron file
5804:
5805: Arguments:
5806: line - The text of the scantron file line to process
5807: whichline - Line number
5808: scantron_config - Hash describing the format of the scantron lines.
5809: scan_data - Hash of extra information about the scanline
5810: (see scantron_getfile for more information)
5811: just_header - True if should not process question answers but only
5812: the stuff to the left of the answers.
5813: Returns:
5814: Hash containing the result of parsing the scanline
5815:
5816: Keys are all proceeded by the string 'scantron.'
5817:
5818: CODE - the CODE in use for this scanline
5819: useCODE - 1 if the CODE is invalid but it usage has been forced
5820: by the operator
5821: CODE_ignore_dup - 1 if the CODE is a duplicated use when unique
5822: CODEs were selected, but the usage has been
5823: forced by the operator
1.556 weissno 5824: ID - student/employee ID
1.423 albertel 5825: PaperID - if used, the ID number printed on the sheet when the
5826: paper was scanned
5827: FirstName - first name from the sheet
5828: LastName - last name from the sheet
5829:
5830: if just_header was not true these key may also exist
5831:
1.447 foxr 5832: missingerror - a list of bubble ranges that are considered to be answers
5833: to a single question that don't have any bubbles filled in.
5834: Of the form questionnumber:firstbubblenumber:count.
5835: doubleerror - a list of bubble ranges that are considered to be answers
5836: to a single question that have more than one bubble filled in.
5837: Of the form questionnumber::firstbubblenumber:count
5838:
5839: In the above, count is the number of bubble responses in the
5840: input line needed to represent the possible answers to the question.
5841: e.g. a radioresponse with 15 choices in an answer sheet with 10 choices
5842: per line would have count = 2.
5843:
1.423 albertel 5844: maxquest - the number of the last bubble line that was parsed
5845:
5846: (<number> starts at 1)
5847: <number>.answer - zero or more letters representing the selected
5848: letters from the scanline for the bubble line
5849: <number>.
5850: if blank there was either no bubble or there where
5851: multiple bubbles, (consult the keys missingerror and
5852: doubleerror if this is an error condition)
5853:
5854: =cut
5855:
1.82 albertel 5856: sub scantron_parse_scanline {
1.423 albertel 5857: my ($line,$whichline,$scantron_config,$scan_data,$just_header)=@_;
1.470 foxr 5858:
1.82 albertel 5859: my %record;
1.550 raeburn 5860: my $lastpos = $env{'form.scantron_maxbubble'}*$$scantron_config{'Qlength'};
5861: my $questions=substr($line,$$scantron_config{'Qstart'}-1,$lastpos); # Answers
1.422 foxr 5862: my $data=substr($line,0,$$scantron_config{'Qstart'}-1); # earlier stuff
1.278 albertel 5863: if (!($$scantron_config{'CODElocation'} eq 0 ||
5864: $$scantron_config{'CODElocation'} eq 'none')) {
5865: if ($$scantron_config{'CODElocation'} < 0 ||
5866: $$scantron_config{'CODElocation'} eq 'letter' ||
5867: $$scantron_config{'CODElocation'} eq 'number') {
1.191 albertel 5868: $record{'scantron.CODE'}=substr($data,
5869: $$scantron_config{'CODEstart'}-1,
1.83 albertel 5870: $$scantron_config{'CODElength'});
1.191 albertel 5871: if (&scan_data($scan_data,"$whichline.useCODE")) {
5872: $record{'scantron.useCODE'}=1;
5873: }
1.192 albertel 5874: if (&scan_data($scan_data,"$whichline.CODE_ignore_dup")) {
5875: $record{'scantron.CODE_ignore_dup'}=1;
5876: }
1.82 albertel 5877: } else {
5878: #FIXME interpret first N questions
5879: }
5880: }
1.83 albertel 5881: $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
5882: $$scantron_config{'IDlength'});
1.157 albertel 5883: $record{'scantron.PaperID'}=
5884: substr($data,$$scantron_config{'PaperID'}-1,
5885: $$scantron_config{'PaperIDlength'});
5886: $record{'scantron.FirstName'}=
5887: substr($data,$$scantron_config{'FirstName'}-1,
5888: $$scantron_config{'FirstNamelength'});
5889: $record{'scantron.LastName'}=
5890: substr($data,$$scantron_config{'LastName'}-1,
5891: $$scantron_config{'LastNamelength'});
1.423 albertel 5892: if ($just_header) { return \%record; }
1.194 albertel 5893:
1.82 albertel 5894: my @alphabet=('A'..'Z');
5895: my $questnum=0;
1.447 foxr 5896: my $ansnum =1; # Multiple 'answer lines'/question.
5897:
1.470 foxr 5898: chomp($questions); # Get rid of any trailing \n.
5899: $questions =~ s/\r$//; # Get rid of trailing \r too (MAC or Win uploads).
5900: while (length($questions)) {
1.447 foxr 5901: my $answers_needed = $bubble_lines_per_response{$questnum};
1.503 raeburn 5902: my $answer_length = ($$scantron_config{'Qlength'} * $answers_needed)
5903: || 1;
5904: $questnum++;
5905: my $quest_id = $questnum;
5906: my $currentquest = substr($questions,0,$answer_length);
5907: $questions = substr($questions,$answer_length);
5908: if (length($currentquest) < $answer_length) { next; }
5909:
5910: if ($subdivided_bubble_lines{$questnum-1} =~ /,/) {
5911: my $subquestnum = 1;
5912: my $subquestions = $currentquest;
5913: my @subanswers_needed =
5914: split(/,/,$subdivided_bubble_lines{$questnum-1});
5915: foreach my $subans (@subanswers_needed) {
5916: my $subans_length =
5917: ($$scantron_config{'Qlength'} * $subans) || 1;
5918: my $currsubquest = substr($subquestions,0,$subans_length);
5919: $subquestions = substr($subquestions,$subans_length);
5920: $quest_id = "$questnum.$subquestnum";
5921: if (($$scantron_config{'Qon'} eq 'letter') ||
5922: ($$scantron_config{'Qon'} eq 'number')) {
5923: $ansnum = &scantron_validator_lettnum($ansnum,
5924: $questnum,$quest_id,$subans,$currsubquest,$whichline,
5925: \@alphabet,\%record,$scantron_config,$scan_data);
5926: } else {
5927: $ansnum = &scantron_validator_positional($ansnum,
5928: $questnum,$quest_id,$subans,$currsubquest,$whichline, \@alphabet,\%record,$scantron_config,$scan_data);
5929: }
5930: $subquestnum ++;
5931: }
5932: } else {
5933: if (($$scantron_config{'Qon'} eq 'letter') ||
5934: ($$scantron_config{'Qon'} eq 'number')) {
5935: $ansnum = &scantron_validator_lettnum($ansnum,$questnum,
5936: $quest_id,$answers_needed,$currentquest,$whichline,
5937: \@alphabet,\%record,$scantron_config,$scan_data);
5938: } else {
5939: $ansnum = &scantron_validator_positional($ansnum,$questnum,
5940: $quest_id,$answers_needed,$currentquest,$whichline,
5941: \@alphabet,\%record,$scantron_config,$scan_data);
5942: }
5943: }
5944: }
5945: $record{'scantron.maxquest'}=$questnum;
5946: return \%record;
5947: }
1.447 foxr 5948:
1.503 raeburn 5949: sub scantron_validator_lettnum {
5950: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,$whichline,
5951: $alphabet,$record,$scantron_config,$scan_data) = @_;
5952:
5953: # Qon 'letter' implies for each slot in currquest we have:
5954: # ? or * for doubles, a letter in A-Z for a bubble, and
5955: # about anything else (esp. a value of Qoff) for missing
5956: # bubbles.
5957: #
5958: # Qon 'number' implies each slot gives a digit that indexes the
5959: # bubbles filled, or Qoff, or a non-number for unbubbled lines,
5960: # and * or ? for double bubbles on a single line.
5961: #
1.447 foxr 5962:
1.503 raeburn 5963: my $matchon;
5964: if ($$scantron_config{'Qon'} eq 'letter') {
5965: $matchon = '[A-Z]';
5966: } elsif ($$scantron_config{'Qon'} eq 'number') {
5967: $matchon = '\d';
5968: }
5969: my $occurrences = 0;
5970: if (($responsetype_per_response{$questnum-1} eq 'essayresponse') ||
5971: ($responsetype_per_response{$questnum-1} eq 'formularesponse') ||
1.510 raeburn 5972: ($responsetype_per_response{$questnum-1} eq 'stringresponse') ||
5973: ($responsetype_per_response{$questnum-1} eq 'imageresponse') ||
5974: ($responsetype_per_response{$questnum-1} eq 'reactionresponse') ||
5975: ($responsetype_per_response{$questnum-1} eq 'organicresponse')) {
1.503 raeburn 5976: my @singlelines = split('',$currquest);
5977: foreach my $entry (@singlelines) {
5978: $occurrences = &occurence_count($entry,$matchon);
5979: if ($occurrences > 1) {
5980: last;
5981: }
5982: }
5983: } else {
5984: $occurrences = &occurence_count($currquest,$matchon);
5985: }
5986: if (($currquest =~ /\?/ || $currquest =~ /\*/) || ($occurrences > 1)) {
5987: push(@{$record->{'scantron.doubleerror'}},$quest_id);
5988: for (my $ans=0; $ans<$answers_needed; $ans++) {
5989: my $bubble = substr($currquest,$ans,1);
5990: if ($bubble =~ /$matchon/ ) {
5991: if ($$scantron_config{'Qon'} eq 'number') {
5992: if ($bubble == 0) {
5993: $bubble = 10;
5994: }
5995: $record->{"scantron.$ansnum.answer"} =
5996: $alphabet->[$bubble-1];
5997: } else {
5998: $record->{"scantron.$ansnum.answer"} = $bubble;
5999: }
6000: } else {
6001: $record->{"scantron.$ansnum.answer"}='';
6002: }
6003: $ansnum++;
6004: }
6005: } elsif (!defined($currquest)
6006: || (&occurence_count($currquest, $$scantron_config{'Qoff'}) == length($currquest))
6007: || (&occurence_count($currquest,$matchon) == 0)) {
6008: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
6009: $record->{"scantron.$ansnum.answer"}='';
6010: $ansnum++;
6011: }
6012: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
6013: push(@{$record->{'scantron.missingerror'}},$quest_id);
6014: }
6015: } else {
6016: if ($$scantron_config{'Qon'} eq 'number') {
6017: $currquest = &digits_to_letters($currquest);
6018: }
6019: for (my $ans=0; $ans<$answers_needed; $ans++) {
6020: my $bubble = substr($currquest,$ans,1);
6021: $record->{"scantron.$ansnum.answer"} = $bubble;
6022: $ansnum++;
6023: }
6024: }
6025: return $ansnum;
6026: }
1.447 foxr 6027:
1.503 raeburn 6028: sub scantron_validator_positional {
6029: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,
6030: $whichline,$alphabet,$record,$scantron_config,$scan_data) = @_;
1.447 foxr 6031:
1.503 raeburn 6032: # Otherwise there's a positional notation;
6033: # each bubble line requires Qlength items, and there are filled in
6034: # bubbles for each case where there 'Qon' characters.
6035: #
1.447 foxr 6036:
1.503 raeburn 6037: my @array=split($$scantron_config{'Qon'},$currquest,-1);
1.447 foxr 6038:
1.503 raeburn 6039: # If the split only gives us one element.. the full length of the
6040: # answer string, no bubbles are filled in:
1.447 foxr 6041:
1.507 raeburn 6042: if ($answers_needed eq '') {
6043: return;
6044: }
6045:
1.503 raeburn 6046: if (length($array[0]) eq $$scantron_config{'Qlength'}*$answers_needed) {
6047: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
6048: $record->{"scantron.$ansnum.answer"}='';
6049: $ansnum++;
6050: }
6051: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
6052: push(@{$record->{"scantron.missingerror"}},$quest_id);
6053: }
6054: } elsif (scalar(@array) == 2) {
6055: my $location = length($array[0]);
6056: my $line_num = int($location / $$scantron_config{'Qlength'});
6057: my $bubble = $alphabet->[$location % $$scantron_config{'Qlength'}];
6058: for (my $ans=0; $ans<$answers_needed; $ans++) {
6059: if ($ans eq $line_num) {
6060: $record->{"scantron.$ansnum.answer"} = $bubble;
6061: } else {
6062: $record->{"scantron.$ansnum.answer"} = ' ';
6063: }
6064: $ansnum++;
6065: }
6066: } else {
6067: # If there's more than one instance of a bubble character
6068: # That's a double bubble; with positional notation we can
6069: # record all the bubbles filled in as well as the
6070: # fact this response consists of multiple bubbles.
6071: #
6072: if (($responsetype_per_response{$questnum-1} eq 'essayresponse') ||
6073: ($responsetype_per_response{$questnum-1} eq 'formularesponse') ||
1.510 raeburn 6074: ($responsetype_per_response{$questnum-1} eq 'stringresponse') ||
6075: ($responsetype_per_response{$questnum-1} eq 'imageresponse') ||
6076: ($responsetype_per_response{$questnum-1} eq 'reactionresponse') ||
6077: ($responsetype_per_response{$questnum-1} eq 'organicresponse')) {
1.503 raeburn 6078: my $doubleerror = 0;
6079: while (($currquest >= $$scantron_config{'Qlength'}) &&
6080: (!$doubleerror)) {
6081: my $currline = substr($currquest,0,$$scantron_config{'Qlength'});
6082: $currquest = substr($currquest,$$scantron_config{'Qlength'});
6083: my @currarray = split($$scantron_config{'Qon'},$currline,-1);
6084: if (length(@currarray) > 2) {
6085: $doubleerror = 1;
6086: }
6087: }
6088: if ($doubleerror) {
6089: push(@{$record->{'scantron.doubleerror'}},$quest_id);
6090: }
6091: } else {
6092: push(@{$record->{'scantron.doubleerror'}},$quest_id);
6093: }
6094: my $item = $ansnum;
6095: for (my $ans=0; $ans<$answers_needed; $ans++) {
6096: $record->{"scantron.$item.answer"} = '';
6097: $item ++;
6098: }
1.447 foxr 6099:
1.503 raeburn 6100: my @ans=@array;
6101: my $i=0;
6102: my $increment = 0;
6103: while ($#ans) {
6104: $i+=length($ans[0]) + $increment;
6105: my $line = int($i/$$scantron_config{'Qlength'} + $ansnum);
6106: my $bubble = $i%$$scantron_config{'Qlength'};
6107: $record->{"scantron.$line.answer"}.=$alphabet->[$bubble];
6108: shift(@ans);
6109: $increment = 1;
6110: }
6111: $ansnum += $answers_needed;
1.82 albertel 6112: }
1.503 raeburn 6113: return $ansnum;
1.82 albertel 6114: }
6115:
1.423 albertel 6116: =pod
6117:
6118: =item scantron_add_delay
6119:
6120: Adds an error message that occurred during the grading phase to a
6121: queue of messages to be shown after grading pass is complete
6122:
6123: Arguments:
1.424 albertel 6124: $delayqueue - arrary ref of hash ref of error messages
1.423 albertel 6125: $scanline - the scanline that caused the error
6126: $errormesage - the error message
6127: $errorcode - a numeric code for the error
6128:
6129: Side Effects:
1.424 albertel 6130: updates the $delayqueue to have a new hash ref of the error
1.423 albertel 6131:
6132: =cut
6133:
1.82 albertel 6134: sub scantron_add_delay {
1.140 albertel 6135: my ($delayqueue,$scanline,$errormessage,$errorcode)=@_;
6136: push(@$delayqueue,
6137: {'line' => $scanline, 'emsg' => $errormessage,
6138: 'ecode' => $errorcode }
6139: );
1.82 albertel 6140: }
6141:
1.423 albertel 6142: =pod
6143:
6144: =item scantron_find_student
6145:
1.424 albertel 6146: Finds the username for the current scanline
6147:
6148: Arguments:
6149: $scantron_record - hash result from scantron_parse_scanline
6150: $scan_data - hash of correction information
6151: (see &scantron_getfile() form more information)
6152: $idmap - hash from &username_to_idmap()
6153: $line - number of current scanline
6154:
6155: Returns:
6156: Either 'username:domain' or undef if unknown
6157:
1.423 albertel 6158: =cut
6159:
1.82 albertel 6160: sub scantron_find_student {
1.157 albertel 6161: my ($scantron_record,$scan_data,$idmap,$line)=@_;
1.83 albertel 6162: my $scanID=$$scantron_record{'scantron.ID'};
1.157 albertel 6163: if ($scanID =~ /^\s*$/) {
6164: return &scan_data($scan_data,"$line.user");
6165: }
1.83 albertel 6166: foreach my $id (keys(%$idmap)) {
1.157 albertel 6167: if (lc($id) eq lc($scanID)) {
6168: return $$idmap{$id};
6169: }
1.83 albertel 6170: }
6171: return undef;
6172: }
6173:
1.423 albertel 6174: =pod
6175:
6176: =item scantron_filter
6177:
1.424 albertel 6178: Filter sub for lonnavmaps, filters out hidden resources if ignore
6179: hidden resources was selected
6180:
1.423 albertel 6181: =cut
6182:
1.83 albertel 6183: sub scantron_filter {
6184: my ($curres)=@_;
1.331 albertel 6185:
6186: if (ref($curres) && $curres->is_problem()) {
6187: # if the user has asked to not have either hidden
6188: # or 'randomout' controlled resources to be graded
6189: # don't include them
6190: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
6191: && $curres->randomout) {
6192: return 0;
6193: }
1.83 albertel 6194: return 1;
6195: }
6196: return 0;
1.82 albertel 6197: }
6198:
1.423 albertel 6199: =pod
6200:
6201: =item scantron_process_corrections
6202:
1.424 albertel 6203: Gets correction information out of submitted form data and corrects
6204: the scanline
6205:
1.423 albertel 6206: =cut
6207:
1.157 albertel 6208: sub scantron_process_corrections {
6209: my ($r) = @_;
1.257 albertel 6210: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 6211: my ($scanlines,$scan_data)=&scantron_getfile();
6212: my $classlist=&Apache::loncoursedata::get_classlist();
1.257 albertel 6213: my $which=$env{'form.scantron_line'};
1.200 albertel 6214: my $line=&scantron_get_line($scanlines,$scan_data,$which);
1.157 albertel 6215: my ($skip,$err,$errmsg);
1.257 albertel 6216: if ($env{'form.scantron_skip_record'}) {
1.157 albertel 6217: $skip=1;
1.257 albertel 6218: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)ID$/) {
6219: my $newstudent=$env{'form.scantron_username'}.':'.
6220: $env{'form.scantron_domain'};
1.157 albertel 6221: my $newid=$classlist->{$newstudent}->[&Apache::loncoursedata::CL_ID];
6222: ($line,$err,$errmsg)=
6223: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
6224: 'ID',{'newid'=>$newid,
1.257 albertel 6225: 'username'=>$env{'form.scantron_username'},
6226: 'domain'=>$env{'form.scantron_domain'}});
6227: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)CODE$/) {
6228: my $resolution=$env{'form.scantron_CODE_resolution'};
1.190 albertel 6229: my $newCODE;
1.192 albertel 6230: my %args;
1.190 albertel 6231: if ($resolution eq 'use_unfound') {
1.191 albertel 6232: $newCODE='use_unfound';
1.190 albertel 6233: } elsif ($resolution eq 'use_found') {
1.257 albertel 6234: $newCODE=$env{'form.scantron_CODE_selectedvalue'};
1.190 albertel 6235: } elsif ($resolution eq 'use_typed') {
1.257 albertel 6236: $newCODE=$env{'form.scantron_CODE_newvalue'};
1.194 albertel 6237: } elsif ($resolution =~ /^use_closest_(\d+)/) {
1.257 albertel 6238: $newCODE=$env{"form.scantron_CODE_closest_$1"};
1.190 albertel 6239: }
1.257 albertel 6240: if ($env{'form.scantron_corrections'} eq 'duplicateCODE') {
1.192 albertel 6241: $args{'CODE_ignore_dup'}=1;
6242: }
6243: $args{'CODE'}=$newCODE;
1.186 albertel 6244: ($line,$err,$errmsg)=
6245: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
1.192 albertel 6246: 'CODE',\%args);
1.257 albertel 6247: } elsif ($env{'form.scantron_corrections'} =~ /^(missing|double)bubble$/) {
6248: foreach my $question (split(',',$env{'form.scantron_questions'})) {
1.157 albertel 6249: ($line,$err,$errmsg)=
6250: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,
6251: $which,'answer',
6252: { 'question'=>$question,
1.503 raeburn 6253: 'response'=>$env{"form.scantron_correct_Q_$question"},
6254: 'questionnum'=>$env{"form.scantron_questionnum_Q_$question"}});
1.157 albertel 6255: if ($err) { last; }
6256: }
6257: }
6258: if ($err) {
1.398 albertel 6259: $r->print("<span class=\"LC_warning\">Unable to accept last correction, an error occurred :$errmsg:</span>");
1.157 albertel 6260: } else {
1.200 albertel 6261: &scantron_put_line($scanlines,$scan_data,$which,$line,$skip);
1.157 albertel 6262: &scantron_putfile($scanlines,$scan_data);
6263: }
6264: }
6265:
1.423 albertel 6266: =pod
6267:
6268: =item reset_skipping_status
6269:
1.424 albertel 6270: Forgets the current set of remember skipped scanlines (and thus
6271: reverts back to considering all lines in the
6272: scantron_skipped_<filename> file)
6273:
1.423 albertel 6274: =cut
6275:
1.200 albertel 6276: sub reset_skipping_status {
6277: my ($scanlines,$scan_data)=&scantron_getfile();
6278: &scan_data($scan_data,'remember_skipping',undef,1);
6279: &scantron_putfile(undef,$scan_data);
6280: }
6281:
1.423 albertel 6282: =pod
6283:
6284: =item start_skipping
6285:
1.424 albertel 6286: Marks a scanline to be skipped.
6287:
1.423 albertel 6288: =cut
6289:
1.376 albertel 6290: sub start_skipping {
1.200 albertel 6291: my ($scan_data,$i)=@_;
6292: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 6293: if ($env{'form.scantron_options_redo'} =~ /^redo_/) {
6294: $remembered{$i}=2;
6295: } else {
6296: $remembered{$i}=1;
6297: }
1.200 albertel 6298: &scan_data($scan_data,'remember_skipping',join(':',%remembered));
6299: }
6300:
1.423 albertel 6301: =pod
6302:
6303: =item should_be_skipped
6304:
1.424 albertel 6305: Checks whether a scanline should be skipped.
6306:
1.423 albertel 6307: =cut
6308:
1.200 albertel 6309: sub should_be_skipped {
1.376 albertel 6310: my ($scanlines,$scan_data,$i)=@_;
1.257 albertel 6311: if ($env{'form.scantron_options_redo'} !~ /^redo_/) {
1.200 albertel 6312: # not redoing old skips
1.376 albertel 6313: if ($scanlines->{'skipped'}[$i]) { return 1; }
1.200 albertel 6314: return 0;
6315: }
6316: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 6317:
6318: if (exists($remembered{$i}) && $remembered{$i} != 2 ) {
6319: return 0;
6320: }
1.200 albertel 6321: return 1;
6322: }
6323:
1.423 albertel 6324: =pod
6325:
6326: =item remember_current_skipped
6327:
1.424 albertel 6328: Discovers what scanlines are in the scantron_skipped_<filename>
6329: file and remembers them into scan_data for later use.
6330:
1.423 albertel 6331: =cut
6332:
1.200 albertel 6333: sub remember_current_skipped {
6334: my ($scanlines,$scan_data)=&scantron_getfile();
6335: my %to_remember;
6336: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
6337: if ($scanlines->{'skipped'}[$i]) {
6338: $to_remember{$i}=1;
6339: }
6340: }
1.376 albertel 6341:
1.200 albertel 6342: &scan_data($scan_data,'remember_skipping',join(':',%to_remember));
6343: &scantron_putfile(undef,$scan_data);
6344: }
6345:
1.423 albertel 6346: =pod
6347:
6348: =item check_for_error
6349:
1.424 albertel 6350: Checks if there was an error when attempting to remove a specific
1.596.2.6 raeburn 6351: scantron_.. bubblesheet data file. Prints out an error if
1.424 albertel 6352: something went wrong.
6353:
1.423 albertel 6354: =cut
6355:
1.200 albertel 6356: sub check_for_error {
6357: my ($r,$result)=@_;
6358: if ($result ne 'ok' && $result ne 'not_found' ) {
1.492 albertel 6359: $r->print(&mt("An error occurred ([_1]) when trying to remove the existing corrections.",$result));
1.200 albertel 6360: }
6361: }
1.157 albertel 6362:
1.423 albertel 6363: =pod
6364:
6365: =item scantron_warning_screen
6366:
1.424 albertel 6367: Interstitial screen to make sure the operator has selected the
6368: correct options before we start the validation phase.
6369:
1.423 albertel 6370: =cut
6371:
1.203 albertel 6372: sub scantron_warning_screen {
6373: my ($button_text)=@_;
1.257 albertel 6374: my $title=&Apache::lonnet::gettitle($env{'form.selectpage'});
1.284 albertel 6375: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.373 albertel 6376: my $CODElist;
1.284 albertel 6377: if ($scantron_config{'CODElocation'} &&
6378: $scantron_config{'CODEstart'} &&
6379: $scantron_config{'CODElength'}) {
6380: $CODElist=$env{'form.scantron_CODElist'};
1.398 albertel 6381: if ($env{'form.scantron_CODElist'} eq '') { $CODElist='<span class="LC_warning">None</span>'; }
1.284 albertel 6382: $CODElist=
1.492 albertel 6383: '<tr><td><b>'.&mt('List of CODES to validate against:').'</b></td><td><tt>'.
1.373 albertel 6384: $env{'form.scantron_CODElist'}.'</tt></td></tr>';
1.284 albertel 6385: }
1.492 albertel 6386: return ('
1.203 albertel 6387: <p>
1.492 albertel 6388: <span class="LC_warning">
6389: '.&mt('Please double check the information below before clicking on \'[_1]\'',&mt($button_text)).'</span>
1.203 albertel 6390: </p>
6391: <table>
1.492 albertel 6392: <tr><td><b>'.&mt('Sequence to be Graded:').'</b></td><td>'.$title.'</td></tr>
6393: <tr><td><b>'.&mt('Data File that will be used:').'</b></td><td><tt>'.$env{'form.scantron_selectfile'}.'</tt></td></tr>
6394: '.$CODElist.'
1.203 albertel 6395: </table>
6396: <br />
1.492 albertel 6397: <p> '.&mt('If this information is correct, please click on \'[_1]\'.',&mt($button_text)).'</p>
6398: <p> '.&mt('If something is incorrect, please click the \'Grading Menu\' button to start over.').'</p>
1.203 albertel 6399:
6400: <br />
1.492 albertel 6401: ');
1.203 albertel 6402: }
6403:
1.423 albertel 6404: =pod
6405:
6406: =item scantron_do_warning
6407:
1.424 albertel 6408: Check if the operator has picked something for all required
6409: fields. Error out if something is missing.
6410:
1.423 albertel 6411: =cut
6412:
1.203 albertel 6413: sub scantron_do_warning {
6414: my ($r)=@_;
1.324 albertel 6415: my ($symb)=&get_symb($r);
1.203 albertel 6416: if (!$symb) {return '';}
1.324 albertel 6417: my $default_form_data=&defaultFormData($symb);
1.203 albertel 6418: $r->print(&scantron_form_start().$default_form_data);
1.257 albertel 6419: if ( $env{'form.selectpage'} eq '' ||
6420: $env{'form.scantron_selectfile'} eq '' ||
6421: $env{'form.scantron_format'} eq '' ) {
1.596.2.4 raeburn 6422: $r->print("<p>".&mt('You have forgotten to specify some information. Please go Back and try again.')."</p>");
1.257 albertel 6423: if ( $env{'form.selectpage'} eq '') {
1.492 albertel 6424: $r->print('<p><span class="LC_error">'.&mt('You have not selected a Sequence to grade').'</span></p>');
1.237 albertel 6425: }
1.257 albertel 6426: if ( $env{'form.scantron_selectfile'} eq '') {
1.596.2.4 raeburn 6427: $r->print('<p><span class="LC_error">'.&mt("You have not selected a file that contains the student's response data.").'</span></p>');
1.237 albertel 6428: }
1.257 albertel 6429: if ( $env{'form.scantron_format'} eq '') {
1.596.2.5 raeburn 6430: $r->print('<p><span class="LC_error">'.&mt("You have not selected the format of the student's response data.").'</span></p>');
1.237 albertel 6431: }
6432: } else {
1.265 www 6433: my $warning=&scantron_warning_screen('Grading: Validate Records');
1.492 albertel 6434: $r->print('
6435: '.$warning.'
6436: <input type="submit" name="submit" value="'.&mt('Grading: Validate Records').'" />
1.203 albertel 6437: <input type="hidden" name="command" value="scantron_validate" />
1.492 albertel 6438: ');
1.237 albertel 6439: }
1.352 albertel 6440: $r->print("</form><br />".&show_grading_menu_form($symb));
1.203 albertel 6441: return '';
6442: }
6443:
1.423 albertel 6444: =pod
6445:
6446: =item scantron_form_start
6447:
1.424 albertel 6448: html hidden input for remembering all selected grading options
6449:
1.423 albertel 6450: =cut
6451:
1.203 albertel 6452: sub scantron_form_start {
6453: my ($max_bubble)=@_;
6454: my $result= <<SCANTRONFORM;
6455: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
1.257 albertel 6456: <input type="hidden" name="selectpage" value="$env{'form.selectpage'}" />
6457: <input type="hidden" name="scantron_format" value="$env{'form.scantron_format'}" />
6458: <input type="hidden" name="scantron_selectfile" value="$env{'form.scantron_selectfile'}" />
1.218 albertel 6459: <input type="hidden" name="scantron_maxbubble" value="$max_bubble" />
1.257 albertel 6460: <input type="hidden" name="scantron_CODElist" value="$env{'form.scantron_CODElist'}" />
6461: <input type="hidden" name="scantron_CODEunique" value="$env{'form.scantron_CODEunique'}" />
6462: <input type="hidden" name="scantron_options_redo" value="$env{'form.scantron_options_redo'}" />
6463: <input type="hidden" name="scantron_options_ignore" value="$env{'form.scantron_options_ignore'}" />
1.331 albertel 6464: <input type="hidden" name="scantron_options_hidden" value="$env{'form.scantron_options_hidden'}" />
1.203 albertel 6465: SCANTRONFORM
1.447 foxr 6466:
6467: my $line = 0;
6468: while (defined($env{"form.scantron.bubblelines.$line"})) {
6469: my $chunk =
6470: '<input type="hidden" name="scantron.bubblelines.'.$line.'" value="'.$env{"form.scantron.bubblelines.$line"}.'" />'."\n";
1.448 foxr 6471: $chunk .=
6472: '<input type="hidden" name="scantron.first_bubble_line.'.$line.'" value="'.$env{"form.scantron.first_bubble_line.$line"}.'" />'."\n";
1.503 raeburn 6473: $chunk .=
6474: '<input type="hidden" name="scantron.sub_bubblelines.'.$line.'" value="'.$env{"form.scantron.sub_bubblelines.$line"}.'" />'."\n";
1.504 raeburn 6475: $chunk .=
6476: '<input type="hidden" name="scantron.responsetype.'.$line.'" value="'.$env{"form.scantron.responsetype.$line"}.'" />'."\n";
1.447 foxr 6477: $result .= $chunk;
6478: $line++;
6479: }
1.203 albertel 6480: return $result;
6481: }
6482:
1.423 albertel 6483: =pod
6484:
6485: =item scantron_validate_file
6486:
1.596.2.6 raeburn 6487: Dispatch routine for doing validation of a bubblesheet data file.
1.424 albertel 6488:
6489: Also processes any necessary information resets that need to
6490: occur before validation begins (ignore previous corrections,
6491: restarting the skipped records processing)
6492:
1.423 albertel 6493: =cut
6494:
1.157 albertel 6495: sub scantron_validate_file {
6496: my ($r) = @_;
1.324 albertel 6497: my ($symb)=&get_symb($r);
1.157 albertel 6498: if (!$symb) {return '';}
1.324 albertel 6499: my $default_form_data=&defaultFormData($symb);
1.200 albertel 6500:
6501: # do the detection of only doing skipped records first befroe we delete
1.424 albertel 6502: # them when doing the corrections reset
1.257 albertel 6503: if ($env{'form.scantron_options_redo'} ne 'redo_skipped_ready') {
1.200 albertel 6504: &reset_skipping_status();
6505: }
1.257 albertel 6506: if ($env{'form.scantron_options_redo'} eq 'redo_skipped') {
1.200 albertel 6507: &remember_current_skipped();
1.257 albertel 6508: $env{'form.scantron_options_redo'}='redo_skipped_ready';
1.200 albertel 6509: }
6510:
1.257 albertel 6511: if ($env{'form.scantron_options_ignore'} eq 'ignore_corrections') {
1.200 albertel 6512: &check_for_error($r,&scantron_remove_file('corrected'));
6513: &check_for_error($r,&scantron_remove_file('skipped'));
6514: &check_for_error($r,&scantron_remove_scan_data());
1.257 albertel 6515: $env{'form.scantron_options_ignore'}='done';
1.192 albertel 6516: }
1.200 albertel 6517:
1.257 albertel 6518: if ($env{'form.scantron_corrections'}) {
1.157 albertel 6519: &scantron_process_corrections($r);
6520: }
1.503 raeburn 6521: $r->print('<p>'.&mt('Gathering necessary information.').'</p>');$r->rflush();
1.157 albertel 6522: #get the student pick code ready
6523: $r->print(&Apache::loncommon::studentbrowser_javascript());
1.582 raeburn 6524: my $nav_error;
1.596.2.12.2. (raeburn 6525:): my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
6526:): my $max_bubble=&scantron_get_maxbubble(\$nav_error,\%scantron_config);
1.582 raeburn 6527: if ($nav_error) {
6528: $r->print(&navmap_errormsg());
6529: return '';
6530: }
1.203 albertel 6531: my $result=&scantron_form_start($max_bubble).$default_form_data;
1.157 albertel 6532: $r->print($result);
6533:
1.334 albertel 6534: my @validate_phases=( 'sequence',
6535: 'ID',
1.157 albertel 6536: 'CODE',
6537: 'doublebubble',
6538: 'missingbubbles');
1.257 albertel 6539: if (!$env{'form.validatepass'}) {
6540: $env{'form.validatepass'} = 0;
1.157 albertel 6541: }
1.257 albertel 6542: my $currentphase=$env{'form.validatepass'};
1.157 albertel 6543:
1.448 foxr 6544:
1.157 albertel 6545: my $stop=0;
6546: while (!$stop && $currentphase < scalar(@validate_phases)) {
1.503 raeburn 6547: $r->print(&mt('Validating '.$validate_phases[$currentphase]).'<br />');
1.157 albertel 6548: $r->rflush();
6549: my $which="scantron_validate_".$validate_phases[$currentphase];
6550: {
6551: no strict 'refs';
6552: ($stop,$currentphase)=&$which($r,$currentphase);
6553: }
6554: }
6555: if (!$stop) {
1.203 albertel 6556: my $warning=&scantron_warning_screen('Start Grading');
1.542 raeburn 6557: $r->print(&mt('Validation process complete.').'<br />'.
6558: $warning.
6559: &mt('Perform verification for each student after storage of submissions?').
6560: ' <span class="LC_nobreak"><label>'.
6561: '<input type="radio" name="verifyrecord" value="1" />'.&mt('Yes').'</label>'.
6562: (' 'x3).'<label>'.
6563: '<input type="radio" name="verifyrecord" value="0" checked="checked" />'.&mt('No').
6564: '</label></span><br />'.
6565: &mt('Grading will take longer if you use verification.').'<br />'.
1.572 www 6566: &mt("Alternatively, the 'Review bubblesheet data' utility (see grading menu) can be used for all students after grading is complete.").'<br /><br />'.
1.542 raeburn 6567: '<input type="submit" name="submit" value="'.&mt('Start Grading').'" />'.
6568: '<input type="hidden" name="command" value="scantron_process" />'."\n");
1.157 albertel 6569: } else {
6570: $r->print('<input type="hidden" name="command" value="scantron_validate" />');
6571: $r->print("<input type='hidden' name='validatepass' value='".$currentphase."' />");
6572: }
6573: if ($stop) {
1.334 albertel 6574: if ($validate_phases[$currentphase] eq 'sequence') {
1.539 riegler 6575: $r->print('<input type="submit" name="submit" value="'.&mt('Ignore').' → " />');
1.492 albertel 6576: $r->print(' '.&mt('this error').' <br />');
1.334 albertel 6577:
1.492 albertel 6578: $r->print(" <p>".&mt("Or click the 'Grading Menu' button to start over.")."</p>");
1.334 albertel 6579: } else {
1.503 raeburn 6580: if ($validate_phases[$currentphase] eq 'doublebubble' || $validate_phases[$currentphase] eq 'missingbubbles') {
1.539 riegler 6581: $r->print('<input type="button" name="submitbutton" value="'.&mt('Continue').' →" onclick="javascript:verify_bubble_radio(this.form)" />');
1.503 raeburn 6582: } else {
1.539 riegler 6583: $r->print('<input type="submit" name="submit" value="'.&mt('Continue').' →" />');
1.503 raeburn 6584: }
1.492 albertel 6585: $r->print(' '.&mt('using corrected info').' <br />');
6586: $r->print("<input type='submit' value='".&mt("Skip")."' name='scantron_skip_record' />");
6587: $r->print(" ".&mt("this scanline saving it for later."));
1.334 albertel 6588: }
1.157 albertel 6589: }
1.352 albertel 6590: $r->print(" </form><br />".&show_grading_menu_form($symb));
1.157 albertel 6591: return '';
6592: }
6593:
1.423 albertel 6594:
6595: =pod
6596:
6597: =item scantron_remove_file
6598:
1.596.2.6 raeburn 6599: Removes the requested bubblesheet data file, makes sure that
1.424 albertel 6600: scantron_original_<filename> is never removed
6601:
6602:
1.423 albertel 6603: =cut
6604:
1.200 albertel 6605: sub scantron_remove_file {
1.192 albertel 6606: my ($which)=@_;
1.257 albertel 6607: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6608: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 6609: my $file='scantron_';
1.200 albertel 6610: if ($which eq 'corrected' || $which eq 'skipped') {
6611: $file.=$which.'_';
1.192 albertel 6612: } else {
6613: return 'refused';
6614: }
1.257 albertel 6615: $file.=$env{'form.scantron_selectfile'};
1.200 albertel 6616: return &Apache::lonnet::removeuserfile($cname,$cdom,$file);
6617: }
6618:
1.423 albertel 6619:
6620: =pod
6621:
6622: =item scantron_remove_scan_data
6623:
1.596.2.6 raeburn 6624: Removes all scan_data correction for the requested bubblesheet
1.424 albertel 6625: data file. (In the case that both the are doing skipped records we need
6626: to remember the old skipped lines for the time being so that element
6627: persists for a while.)
6628:
1.423 albertel 6629: =cut
6630:
1.200 albertel 6631: sub scantron_remove_scan_data {
1.257 albertel 6632: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6633: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 6634: my @keys=&Apache::lonnet::getkeys('nohist_scantrondata',$cdom,$cname);
6635: my @todelete;
1.257 albertel 6636: my $filename=$env{'form.scantron_selectfile'};
1.192 albertel 6637: foreach my $key (@keys) {
6638: if ($key=~/^\Q$filename\E_/) {
1.257 albertel 6639: if ($env{'form.scantron_options_redo'} eq 'redo_skipped_ready' &&
1.200 albertel 6640: $key=~/remember_skipping/) {
6641: next;
6642: }
1.192 albertel 6643: push(@todelete,$key);
6644: }
6645: }
1.200 albertel 6646: my $result;
1.192 albertel 6647: if (@todelete) {
1.491 albertel 6648: $result = &Apache::lonnet::del('nohist_scantrondata',
6649: \@todelete,$cdom,$cname);
6650: } else {
6651: $result = 'ok';
1.192 albertel 6652: }
6653: return $result;
6654: }
6655:
1.423 albertel 6656:
6657: =pod
6658:
6659: =item scantron_getfile
6660:
1.596.2.6 raeburn 6661: Fetches the requested bubblesheet data file (all 3 versions), and
1.424 albertel 6662: the scan_data hash
6663:
6664: Arguments:
6665: None
6666:
6667: Returns:
6668: 2 hash references
6669:
6670: - first one has
6671: orig -
6672: corrected -
6673: skipped - each of which points to an array ref of the specified
6674: file broken up into individual lines
6675: count - number of scanlines
6676:
6677: - second is the scan_data hash possible keys are
1.425 albertel 6678: ($number refers to scanline numbered $number and thus the key affects
6679: only that scanline
6680: $bubline refers to the specific bubble line element and the aspects
6681: refers to that specific bubble line element)
6682:
6683: $number.user - username:domain to use
6684: $number.CODE_ignore_dup
6685: - ignore the duplicate CODE error
6686: $number.useCODE
6687: - use the CODE in the scanline as is
6688: $number.no_bubble.$bubline
6689: - it is valid that there is no bubbled in bubble
6690: at $number $bubline
6691: remember_skipping
6692: - a frozen hash containing keys of $number and values
6693: of either
6694: 1 - we are on a 'do skipped records pass' and plan
6695: on processing this line
6696: 2 - we are on a 'do skipped records pass' and this
6697: scanline has been marked to skip yet again
1.424 albertel 6698:
1.423 albertel 6699: =cut
6700:
1.157 albertel 6701: sub scantron_getfile {
1.200 albertel 6702: #FIXME really would prefer a scantron directory
1.257 albertel 6703: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6704: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.157 albertel 6705: my $lines;
6706: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6707: 'scantron_orig_'.$env{'form.scantron_selectfile'});
1.157 albertel 6708: my %scanlines;
6709: $scanlines{'orig'}=[(split("\n",$lines,-1))];
6710: my $temp=$scanlines{'orig'};
6711: $scanlines{'count'}=$#$temp;
6712:
6713: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6714: 'scantron_corrected_'.$env{'form.scantron_selectfile'});
1.157 albertel 6715: if ($lines eq '-1') {
6716: $scanlines{'corrected'}=[];
6717: } else {
6718: $scanlines{'corrected'}=[(split("\n",$lines,-1))];
6719: }
6720: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6721: 'scantron_skipped_'.$env{'form.scantron_selectfile'});
1.157 albertel 6722: if ($lines eq '-1') {
6723: $scanlines{'skipped'}=[];
6724: } else {
6725: $scanlines{'skipped'}=[(split("\n",$lines,-1))];
6726: }
1.175 albertel 6727: my @tmp=&Apache::lonnet::dump('nohist_scantrondata',$cdom,$cname);
1.157 albertel 6728: if ($tmp[0] =~ /^(error:|no_such_host)/) { @tmp=(); }
6729: my %scan_data = @tmp;
6730: return (\%scanlines,\%scan_data);
6731: }
6732:
1.423 albertel 6733: =pod
6734:
6735: =item lonnet_putfile
6736:
1.424 albertel 6737: Wrapper routine to call &Apache::lonnet::finishuserfileupload
6738:
6739: Arguments:
6740: $contents - data to store
6741: $filename - filename to store $contents into
6742:
6743: Returns:
6744: result value from &Apache::lonnet::finishuserfileupload
6745:
1.423 albertel 6746: =cut
6747:
1.157 albertel 6748: sub lonnet_putfile {
6749: my ($contents,$filename)=@_;
1.257 albertel 6750: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6751: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6752: $env{'form.sillywaytopassafilearound'}=$contents;
1.275 albertel 6753: &Apache::lonnet::finishuserfileupload($docuname,$docudom,'sillywaytopassafilearound',$filename);
1.157 albertel 6754:
6755: }
6756:
1.423 albertel 6757: =pod
6758:
6759: =item scantron_putfile
6760:
1.596.2.6 raeburn 6761: Stores the current version of the bubblesheet data files, and the
1.424 albertel 6762: scan_data hash. (Does not modify the original version only the
6763: corrected and skipped versions.
6764:
6765: Arguments:
6766: $scanlines - hash ref that looks like the first return value from
6767: &scantron_getfile()
6768: $scan_data - hash ref that looks like the second return value from
6769: &scantron_getfile()
6770:
1.423 albertel 6771: =cut
6772:
1.157 albertel 6773: sub scantron_putfile {
6774: my ($scanlines,$scan_data) = @_;
1.200 albertel 6775: #FIXME really would prefer a scantron directory
1.257 albertel 6776: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6777: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.200 albertel 6778: if ($scanlines) {
6779: my $prefix='scantron_';
1.157 albertel 6780: # no need to update orig, shouldn't change
6781: # &lonnet_putfile(join("\n",@{$scanlines->{'orig'}}),$prefix.'orig_'.
1.257 albertel 6782: # $env{'form.scantron_selectfile'});
1.200 albertel 6783: &lonnet_putfile(join("\n",@{$scanlines->{'corrected'}}),
6784: $prefix.'corrected_'.
1.257 albertel 6785: $env{'form.scantron_selectfile'});
1.200 albertel 6786: &lonnet_putfile(join("\n",@{$scanlines->{'skipped'}}),
6787: $prefix.'skipped_'.
1.257 albertel 6788: $env{'form.scantron_selectfile'});
1.200 albertel 6789: }
1.175 albertel 6790: &Apache::lonnet::put('nohist_scantrondata',$scan_data,$cdom,$cname);
1.157 albertel 6791: }
6792:
1.423 albertel 6793: =pod
6794:
6795: =item scantron_get_line
6796:
1.424 albertel 6797: Returns the correct version of the scanline
6798:
6799: Arguments:
6800: $scanlines - hash ref that looks like the first return value from
6801: &scantron_getfile()
6802: $scan_data - hash ref that looks like the second return value from
6803: &scantron_getfile()
6804: $i - number of the requested line (starts at 0)
6805:
6806: Returns:
6807: A scanline, (either the original or the corrected one if it
6808: exists), or undef if the requested scanline should be
6809: skipped. (Either because it's an skipped scanline, or it's an
6810: unskipped scanline and we are not doing a 'do skipped scanlines'
6811: pass.
6812:
1.423 albertel 6813: =cut
6814:
1.157 albertel 6815: sub scantron_get_line {
1.200 albertel 6816: my ($scanlines,$scan_data,$i)=@_;
1.376 albertel 6817: if (&should_be_skipped($scanlines,$scan_data,$i)) { return undef; }
6818: #if ($scanlines->{'skipped'}[$i]) { return undef; }
1.157 albertel 6819: if ($scanlines->{'corrected'}[$i]) {return $scanlines->{'corrected'}[$i];}
6820: return $scanlines->{'orig'}[$i];
6821: }
6822:
1.423 albertel 6823: =pod
6824:
6825: =item scantron_todo_count
6826:
1.424 albertel 6827: Counts the number of scanlines that need processing.
6828:
6829: Arguments:
6830: $scanlines - hash ref that looks like the first return value from
6831: &scantron_getfile()
6832: $scan_data - hash ref that looks like the second return value from
6833: &scantron_getfile()
6834:
6835: Returns:
6836: $count - number of scanlines to process
6837:
1.423 albertel 6838: =cut
6839:
1.200 albertel 6840: sub get_todo_count {
6841: my ($scanlines,$scan_data)=@_;
6842: my $count=0;
6843: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
6844: my $line=&scantron_get_line($scanlines,$scan_data,$i);
6845: if ($line=~/^[\s\cz]*$/) { next; }
6846: $count++;
6847: }
6848: return $count;
6849: }
6850:
1.423 albertel 6851: =pod
6852:
6853: =item scantron_put_line
6854:
1.596.2.6 raeburn 6855: Updates the 'corrected' or 'skipped' versions of the bubblesheet
1.424 albertel 6856: data file.
6857:
6858: Arguments:
6859: $scanlines - hash ref that looks like the first return value from
6860: &scantron_getfile()
6861: $scan_data - hash ref that looks like the second return value from
6862: &scantron_getfile()
6863: $i - line number to update
6864: $newline - contents of the updated scanline
6865: $skip - if true make the line for skipping and update the
6866: 'skipped' file
6867:
1.423 albertel 6868: =cut
6869:
1.157 albertel 6870: sub scantron_put_line {
1.200 albertel 6871: my ($scanlines,$scan_data,$i,$newline,$skip)=@_;
1.157 albertel 6872: if ($skip) {
6873: $scanlines->{'skipped'}[$i]=$newline;
1.376 albertel 6874: &start_skipping($scan_data,$i);
1.157 albertel 6875: return;
6876: }
6877: $scanlines->{'corrected'}[$i]=$newline;
6878: }
6879:
1.423 albertel 6880: =pod
6881:
6882: =item scantron_clear_skip
6883:
1.424 albertel 6884: Remove a line from the 'skipped' file
6885:
6886: Arguments:
6887: $scanlines - hash ref that looks like the first return value from
6888: &scantron_getfile()
6889: $scan_data - hash ref that looks like the second return value from
6890: &scantron_getfile()
6891: $i - line number to update
6892:
1.423 albertel 6893: =cut
6894:
1.376 albertel 6895: sub scantron_clear_skip {
6896: my ($scanlines,$scan_data,$i)=@_;
6897: if (exists($scanlines->{'skipped'}[$i])) {
6898: undef($scanlines->{'skipped'}[$i]);
6899: return 1;
6900: }
6901: return 0;
6902: }
6903:
1.423 albertel 6904: =pod
6905:
6906: =item scantron_filter_not_exam
6907:
1.424 albertel 6908: Filter routine used by &Apache::lonnavmaps::retrieveResources(), to
6909: filter out resources that are not marked as 'exam' mode
6910:
1.423 albertel 6911: =cut
6912:
1.334 albertel 6913: sub scantron_filter_not_exam {
6914: my ($curres)=@_;
6915:
6916: if (ref($curres) && $curres->is_problem() && !$curres->is_exam()) {
6917: # if the user has asked to not have either hidden
6918: # or 'randomout' controlled resources to be graded
6919: # don't include them
6920: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
6921: && $curres->randomout) {
6922: return 0;
6923: }
6924: return 1;
6925: }
6926: return 0;
6927: }
6928:
1.423 albertel 6929: =pod
6930:
6931: =item scantron_validate_sequence
6932:
1.424 albertel 6933: Validates the selected sequence, checking for resource that are
6934: not set to exam mode.
6935:
1.423 albertel 6936: =cut
6937:
1.334 albertel 6938: sub scantron_validate_sequence {
6939: my ($r,$currentphase) = @_;
6940:
6941: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 6942: unless (ref($navmap)) {
6943: $r->print(&navmap_errormsg());
6944: return (1,$currentphase);
6945: }
1.334 albertel 6946: my (undef,undef,$sequence)=
6947: &Apache::lonnet::decode_symb($env{'form.selectpage'});
6948:
6949: my $map=$navmap->getResourceByUrl($sequence);
6950:
6951: $r->print('<input type="hidden" name="validate_sequence_exam"
6952: value="ignore" />');
6953: if ($env{'form.validate_sequence_exam'} ne 'ignore') {
6954: my @resources=
6955: $navmap->retrieveResources($map,\&scantron_filter_not_exam,1,0);
6956: if (@resources) {
1.357 banghart 6957: $r->print("<p>".&mt('Some resources in the sequence currently are not set to exam mode. Grading these resources currently may not work correctly.')."</p>");
1.334 albertel 6958: return (1,$currentphase);
6959: }
6960: }
6961:
6962: return (0,$currentphase+1);
6963: }
6964:
1.423 albertel 6965:
6966:
1.157 albertel 6967: sub scantron_validate_ID {
6968: my ($r,$currentphase) = @_;
6969:
6970: #get student info
6971: my $classlist=&Apache::loncoursedata::get_classlist();
6972: my %idmap=&username_to_idmap($classlist);
6973:
6974: #get scantron line setup
1.257 albertel 6975: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 6976: my ($scanlines,$scan_data)=&scantron_getfile();
1.582 raeburn 6977:
6978: my $nav_error;
1.596.2.12.2. (raeburn 6979:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the bubble_lines.. array.
1.582 raeburn 6980: if ($nav_error) {
6981: $r->print(&navmap_errormsg());
6982: return(1,$currentphase);
6983: }
1.157 albertel 6984:
6985: my %found=('ids'=>{},'usernames'=>{});
6986: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 6987: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 6988: if ($line=~/^[\s\cz]*$/) { next; }
6989: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
6990: $scan_data);
6991: my $id=$$scan_record{'scantron.ID'};
6992: my $found;
6993: foreach my $checkid (keys(%idmap)) {
6994: if (lc($checkid) eq lc($id)) { $found=$checkid;last; }
6995: }
6996: if ($found) {
6997: my $username=$idmap{$found};
6998: if ($found{'ids'}{$found}) {
6999: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
7000: $line,'duplicateID',$found);
1.194 albertel 7001: return(1,$currentphase);
1.157 albertel 7002: } elsif ($found{'usernames'}{$username}) {
7003: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
7004: $line,'duplicateID',$username);
1.194 albertel 7005: return(1,$currentphase);
1.157 albertel 7006: }
1.186 albertel 7007: #FIXME store away line we previously saw the ID on to use above
1.157 albertel 7008: $found{'ids'}{$found}++;
7009: $found{'usernames'}{$username}++;
7010: } else {
7011: if ($id =~ /^\s*$/) {
1.158 albertel 7012: my $username=&scan_data($scan_data,"$i.user");
1.157 albertel 7013: if (defined($username) && $found{'usernames'}{$username}) {
7014: &scantron_get_correction($r,$i,$scan_record,
7015: \%scantron_config,
7016: $line,'duplicateID',$username);
1.194 albertel 7017: return(1,$currentphase);
1.157 albertel 7018: } elsif (!defined($username)) {
7019: &scantron_get_correction($r,$i,$scan_record,
7020: \%scantron_config,
7021: $line,'incorrectID');
1.194 albertel 7022: return(1,$currentphase);
1.157 albertel 7023: }
7024: $found{'usernames'}{$username}++;
7025: } else {
7026: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
7027: $line,'incorrectID');
1.194 albertel 7028: return(1,$currentphase);
1.157 albertel 7029: }
7030: }
7031: }
7032:
7033: return (0,$currentphase+1);
7034: }
7035:
1.423 albertel 7036:
1.157 albertel 7037: sub scantron_get_correction {
7038: my ($r,$i,$scan_record,$scan_config,$line,$error,$arg)=@_;
1.454 banghart 7039: #FIXME in the case of a duplicated ID the previous line, probably need
1.157 albertel 7040: #to show both the current line and the previous one and allow skipping
7041: #the previous one or the current one
7042:
1.333 albertel 7043: if ( $$scan_record{'scantron.PaperID'} =~ /\S/) {
1.596.2.6 raeburn 7044: $r->print(
7045: '<p class="LC_warning">'
7046: .&mt('An error was detected ([_1]) for PaperID [_2]',
7047: "<b>$error</b>",
7048: '<tt>'.$$scan_record{'scantron.PaperID'}.'</tt>')
7049: ."</p> \n");
1.157 albertel 7050: } else {
1.596.2.6 raeburn 7051: $r->print(
7052: '<p class="LC_warning">'
7053: .&mt('An error was detected ([_1]) in scanline [_2] [_3]',
7054: "<b>$error</b>", $i, "<pre>$line</pre>")
7055: ."</p> \n");
7056: }
7057: my $message =
7058: '<p>'
7059: .&mt('The ID on the form is [_1]',
7060: "<tt>$$scan_record{'scantron.ID'}</tt>")
7061: .'<br />'
1.596.2.12 raeburn 7062: .&mt('The name on the paper is [_1], [_2]',
1.596.2.6 raeburn 7063: $$scan_record{'scantron.LastName'},
7064: $$scan_record{'scantron.FirstName'})
7065: .'</p>';
1.242 albertel 7066:
1.157 albertel 7067: $r->print('<input type="hidden" name="scantron_corrections" value="'.$error.'" />'."\n");
7068: $r->print('<input type="hidden" name="scantron_line" value="'.$i.'" />'."\n");
1.503 raeburn 7069: # Array populated for doublebubble or
7070: my @lines_to_correct; # missingbubble errors to build javascript
7071: # to validate radio button checking
7072:
1.157 albertel 7073: if ($error =~ /ID$/) {
1.186 albertel 7074: if ($error eq 'incorrectID') {
1.596.2.6 raeburn 7075: $r->print('<p class="LC_warning">'.&mt("The encoded ID is not in the classlist").
1.492 albertel 7076: "</p>\n");
1.157 albertel 7077: } elsif ($error eq 'duplicateID') {
1.596.2.6 raeburn 7078: $r->print('<p class="LC_warning">'.&mt("The encoded ID has also been used by a previous paper [_1]",$arg)."</p>\n");
1.157 albertel 7079: }
1.242 albertel 7080: $r->print($message);
1.492 albertel 7081: $r->print("<p>".&mt("How should I handle this?")." <br /> \n");
1.157 albertel 7082: $r->print("\n<ul><li> ");
7083: #FIXME it would be nice if this sent back the user ID and
7084: #could do partial userID matches
7085: $r->print(&Apache::loncommon::selectstudent_link('scantronupload',
7086: 'scantron_username','scantron_domain'));
7087: $r->print(": <input type='text' name='scantron_username' value='' />");
7088: $r->print("\n@".
1.257 albertel 7089: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'scantron_domain'));
1.157 albertel 7090:
7091: $r->print('</li>');
1.186 albertel 7092: } elsif ($error =~ /CODE$/) {
7093: if ($error eq 'incorrectCODE') {
1.596.2.6 raeburn 7094: $r->print('<p class="LC_warning">'.&mt("The encoded CODE is not in the list of possible CODEs.")."</p>\n");
1.186 albertel 7095: } elsif ($error eq 'duplicateCODE') {
1.596.2.6 raeburn 7096: $r->print('<p class="LC_warning">'.&mt("The encoded CODE has also been used by a previous paper [_1], and CODEs are supposed to be unique.",join(', ',@{$arg}))."</p>\n");
1.186 albertel 7097: }
1.596.2.6 raeburn 7098: $r->print("<p>".&mt('The CODE on the form is [_1]',
7099: "<tt>'$$scan_record{'scantron.CODE'}'</tt>")
7100: ."</p>\n");
1.242 albertel 7101: $r->print($message);
1.596.2.6 raeburn 7102: $r->print("<p>".&mt("How should I handle this?")."</p>\n");
1.187 albertel 7103: $r->print("\n<br /> ");
1.194 albertel 7104: my $i=0;
1.273 albertel 7105: if ($error eq 'incorrectCODE'
7106: && $$scan_record{'scantron.CODE'}=~/\S/ ) {
1.194 albertel 7107: my ($max,$closest)=&scantron_get_closely_matching_CODEs($arg,$$scan_record{'scantron.CODE'});
1.278 albertel 7108: if ($closest > 0) {
7109: foreach my $testcode (@{$closest}) {
7110: my $checked='';
1.569 bisitz 7111: if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 7112: $r->print("
7113: <label>
1.569 bisitz 7114: <input type='radio' name='scantron_CODE_resolution' value='use_closest_$i'$checked />
1.492 albertel 7115: ".&mt("Use the similar CODE [_1] instead.",
7116: "<b><tt>".$testcode."</tt></b>")."
7117: </label>
7118: <input type='hidden' name='scantron_CODE_closest_$i' value='$testcode' />");
1.278 albertel 7119: $r->print("\n<br />");
7120: $i++;
7121: }
1.194 albertel 7122: }
7123: }
1.273 albertel 7124: if ($$scan_record{'scantron.CODE'}=~/\S/ ) {
1.569 bisitz 7125: my $checked; if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 7126: $r->print("
7127: <label>
1.569 bisitz 7128: <input type='radio' name='scantron_CODE_resolution' value='use_unfound'$checked />
1.596.2.6 raeburn 7129: ".&mt("Use the CODE [_1] that was on the paper, ignoring the error.",
1.492 albertel 7130: "<b><tt>".$$scan_record{'scantron.CODE'}."</tt></b>")."
7131: </label>");
1.273 albertel 7132: $r->print("\n<br />");
7133: }
1.194 albertel 7134:
1.188 albertel 7135: $r->print(<<ENDSCRIPT);
7136: <script type="text/javascript">
7137: function change_radio(field) {
1.190 albertel 7138: var slct=document.scantronupload.scantron_CODE_resolution;
1.188 albertel 7139: var i;
7140: for (i=0;i<slct.length;i++) {
7141: if (slct[i].value==field) { slct[i].checked=true; }
7142: }
7143: }
7144: </script>
7145: ENDSCRIPT
1.187 albertel 7146: my $href="/adm/pickcode?".
1.359 www 7147: "form=".&escape("scantronupload").
7148: "&scantron_format=".&escape($env{'form.scantron_format'}).
7149: "&scantron_CODElist=".&escape($env{'form.scantron_CODElist'}).
7150: "&curCODE=".&escape($$scan_record{'scantron.CODE'}).
7151: "&scantron_selectfile=".&escape($env{'form.scantron_selectfile'});
1.332 albertel 7152: if ($env{'form.scantron_CODElist'} =~ /\S/) {
1.492 albertel 7153: $r->print("
7154: <label>
7155: <input type='radio' name='scantron_CODE_resolution' value='use_found' />
7156: ".&mt("[_1]Select[_2] a CODE from the list of all CODEs and use it.",
7157: "<a target='_blank' href='$href'>","</a>")."
7158: </label>
1.558 bisitz 7159: ".&mt("Selected CODE is [_1]",'<input readonly="readonly" type="text" size="8" name="scantron_CODE_selectedvalue" onfocus="javascript:change_radio(\'use_found\')" onchange="javascript:change_radio(\'use_found\')" />'));
1.332 albertel 7160: $r->print("\n<br />");
7161: }
1.492 albertel 7162: $r->print("
7163: <label>
7164: <input type='radio' name='scantron_CODE_resolution' value='use_typed' />
7165: ".&mt("Use [_1] as the CODE.",
7166: "</label><input type='text' size='8' name='scantron_CODE_newvalue' onfocus=\"javascript:change_radio('use_typed')\" onkeypress=\"javascript:change_radio('use_typed')\" />"));
1.187 albertel 7167: $r->print("\n<br /><br />");
1.157 albertel 7168: } elsif ($error eq 'doublebubble') {
1.596.2.6 raeburn 7169: $r->print('<p class="LC_warning">'.&mt("There have been multiple bubbles scanned for some question(s)")."</p>\n");
1.497 foxr 7170:
7171: # The form field scantron_questions is acutally a list of line numbers.
7172: # represented by this form so:
7173:
7174: my $line_list = &questions_to_line_list($arg);
7175:
1.157 albertel 7176: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 7177: $line_list.'" />');
1.242 albertel 7178: $r->print($message);
1.492 albertel 7179: $r->print("<p>".&mt("Please indicate which bubble should be used for grading")."</p>");
1.157 albertel 7180: foreach my $question (@{$arg}) {
1.503 raeburn 7181: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
7182: $scan_record, $error);
1.524 raeburn 7183: push(@lines_to_correct,@linenums);
1.157 albertel 7184: }
1.503 raeburn 7185: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 7186: } elsif ($error eq 'missingbubble') {
1.596.2.9 raeburn 7187: $r->print('<p class="LC_warning">'.&mt("There have been [_1]no[_2] bubbles scanned for some question(s)",'<b>','</b>')."</p>\n");
1.242 albertel 7188: $r->print($message);
1.492 albertel 7189: $r->print("<p>".&mt("Please indicate which bubble should be used for grading.")."</p>");
1.503 raeburn 7190: $r->print(&mt("Some questions have no scanned bubbles.")."\n");
1.497 foxr 7191:
1.503 raeburn 7192: # The form field scantron_questions is actually a list of line numbers not
1.497 foxr 7193: # a list of question numbers. Therefore:
7194: #
7195:
7196: my $line_list = &questions_to_line_list($arg);
7197:
1.157 albertel 7198: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 7199: $line_list.'" />');
1.157 albertel 7200: foreach my $question (@{$arg}) {
1.503 raeburn 7201: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
7202: $scan_record, $error);
1.524 raeburn 7203: push(@lines_to_correct,@linenums);
1.157 albertel 7204: }
1.503 raeburn 7205: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 7206: } else {
7207: $r->print("\n<ul>");
7208: }
7209: $r->print("\n</li></ul>");
1.497 foxr 7210: }
7211:
1.503 raeburn 7212: sub verify_bubbles_checked {
7213: my (@ansnums) = @_;
7214: my $ansnumstr = join('","',@ansnums);
7215: my $warning = &mt("A bubble or 'No bubble' selection has not been made for one or more lines.");
7216: my $output = (<<ENDSCRIPT);
7217: <script type="text/javascript">
7218: function verify_bubble_radio(form) {
7219: var ansnumArray = new Array ("$ansnumstr");
7220: var need_bubble_count = 0;
7221: for (var i=0; i<ansnumArray.length; i++) {
7222: if (form.elements["scantron_correct_Q_"+ansnumArray[i]].length > 1) {
7223: var bubble_picked = 0;
7224: for (var j=0; j<form.elements["scantron_correct_Q_"+ansnumArray[i]].length; j++) {
7225: if (form.elements["scantron_correct_Q_"+ansnumArray[i]][j].checked == true) {
7226: bubble_picked = 1;
7227: }
7228: }
7229: if (bubble_picked == 0) {
7230: need_bubble_count ++;
7231: }
7232: }
7233: }
7234: if (need_bubble_count) {
7235: alert("$warning");
7236: return;
7237: }
7238: form.submit();
7239: }
7240: </script>
7241: ENDSCRIPT
7242: return $output;
7243: }
7244:
1.497 foxr 7245: =pod
7246:
7247: =item questions_to_line_list
1.157 albertel 7248:
1.497 foxr 7249: Converts a list of questions into a string of comma separated
7250: line numbers in the answer sheet used by the questions. This is
7251: used to fill in the scantron_questions form field.
7252:
7253: Arguments:
7254: questions - Reference to an array of questions.
7255:
7256: =cut
7257:
7258:
7259: sub questions_to_line_list {
7260: my ($questions) = @_;
7261: my @lines;
7262:
1.503 raeburn 7263: foreach my $item (@{$questions}) {
7264: my $question = $item;
7265: my ($first,$count,$last);
7266: if ($item =~ /^(\d+)\.(\d+)$/) {
7267: $question = $1;
7268: my $subquestion = $2;
7269: $first = $first_bubble_line{$question-1} + 1;
7270: my @subans = split(/,/,$subdivided_bubble_lines{$question-1});
7271: my $subcount = 1;
7272: while ($subcount<$subquestion) {
7273: $first += $subans[$subcount-1];
7274: $subcount ++;
7275: }
7276: $count = $subans[$subquestion-1];
7277: } else {
7278: $first = $first_bubble_line{$question-1} + 1;
7279: $count = $bubble_lines_per_response{$question-1};
7280: }
1.506 raeburn 7281: $last = $first+$count-1;
1.503 raeburn 7282: push(@lines, ($first..$last));
1.497 foxr 7283: }
7284: return join(',', @lines);
7285: }
7286:
7287: =pod
7288:
7289: =item prompt_for_corrections
7290:
7291: Prompts for a potentially multiline correction to the
7292: user's bubbling (factors out common code from scantron_get_correction
7293: for multi and missing bubble cases).
7294:
7295: Arguments:
7296: $r - Apache request object.
7297: $question - The question number to prompt for.
7298: $scan_config - The scantron file configuration hash.
7299: $scan_record - Reference to the hash that has the the parsed scanlines.
1.503 raeburn 7300: $error - Type of error
1.497 foxr 7301:
7302: Implicit inputs:
7303: %bubble_lines_per_response - Starting line numbers for each question.
7304: Numbered from 0 (but question numbers are from
7305: 1.
7306: %first_bubble_line - Starting bubble line for each question.
1.509 raeburn 7307: %subdivided_bubble_lines - optionresponse, matchresponse and rankresponse
7308: type problems render as separate sub-questions,
1.503 raeburn 7309: in exam mode. This hash contains a
7310: comma-separated list of the lines per
7311: sub-question.
1.510 raeburn 7312: %responsetype_per_response - essayresponse, formularesponse,
7313: stringresponse, imageresponse, reactionresponse,
7314: and organicresponse type problem parts can have
1.503 raeburn 7315: multiple lines per response if the weight
7316: assigned exceeds 10. In this case, only
7317: one bubble per line is permitted, but more
7318: than one line might contain bubbles, e.g.
7319: bubbling of: line 1 - J, line 2 - J,
7320: line 3 - B would assign 22 points.
1.497 foxr 7321:
7322: =cut
7323:
7324: sub prompt_for_corrections {
1.503 raeburn 7325: my ($r, $question, $scan_config, $scan_record, $error) = @_;
7326: my ($current_line,$lines);
7327: my @linenums;
7328: my $questionnum = $question;
7329: if ($question =~ /^(\d+)\.(\d+)$/) {
7330: $question = $1;
7331: $current_line = $first_bubble_line{$question-1} + 1 ;
7332: my $subquestion = $2;
7333: my @subans = split(/,/,$subdivided_bubble_lines{$question-1});
7334: my $subcount = 1;
7335: while ($subcount<$subquestion) {
7336: $current_line += $subans[$subcount-1];
7337: $subcount ++;
7338: }
7339: $lines = $subans[$subquestion-1];
7340: } else {
7341: $current_line = $first_bubble_line{$question-1} + 1 ;
7342: $lines = $bubble_lines_per_response{$question-1};
7343: }
1.497 foxr 7344: if ($lines > 1) {
1.503 raeburn 7345: $r->print(&mt('The group of bubble lines below responds to a single question.').'<br />');
7346: if (($responsetype_per_response{$question-1} eq 'essayresponse') ||
7347: ($responsetype_per_response{$question-1} eq 'formularesponse') ||
1.510 raeburn 7348: ($responsetype_per_response{$question-1} eq 'stringresponse') ||
7349: ($responsetype_per_response{$question-1} eq 'imageresponse') ||
7350: ($responsetype_per_response{$question-1} eq 'reactionresponse') ||
7351: ($responsetype_per_response{$question-1} eq 'organicresponse')) {
1.572 www 7352: $r->print(&mt("Although this particular question type requires handgrading, the instructions for this question in the exam directed students to leave [quant,_1,line] blank on their bubblesheets.",$lines).'<br /><br />'.&mt('A non-zero score can be assigned to the student during bubblesheet grading by selecting a bubble in at least one line.').'<br />'.&mt('The score for this question will be a sum of the numeric values for the selected bubbles from each line, where A=1 point, B=2 points etc.').'<br />'.&mt("To assign a score of zero for this question, mark all lines as 'No bubble'.").'<br /><br />');
1.503 raeburn 7353: } else {
7354: $r->print(&mt("Select at most one bubble in a single line and select 'No Bubble' in all the other lines. ")."<br />");
7355: }
1.497 foxr 7356: }
7357: for (my $i =0; $i < $lines; $i++) {
1.503 raeburn 7358: my $selected = $$scan_record{"scantron.$current_line.answer"};
7359: &scantron_bubble_selector($r,$scan_config,$current_line,
7360: $questionnum,$error,split('', $selected));
1.524 raeburn 7361: push(@linenums,$current_line);
1.497 foxr 7362: $current_line++;
7363: }
7364: if ($lines > 1) {
7365: $r->print("<hr /><br />");
7366: }
1.503 raeburn 7367: return @linenums;
1.157 albertel 7368: }
1.423 albertel 7369:
7370: =pod
7371:
7372: =item scantron_bubble_selector
7373:
7374: Generates the html radiobuttons to correct a single bubble line
1.424 albertel 7375: possibly showing the existing the selected bubbles if known
1.423 albertel 7376:
7377: Arguments:
7378: $r - Apache request object
7379: $scan_config - hash from &get_scantron_config()
1.497 foxr 7380: $line - Number of the line being displayed.
1.503 raeburn 7381: $questionnum - Question number (may include subquestion)
7382: $error - Type of error.
1.497 foxr 7383: @selected - Array of bubbles picked on this line.
1.423 albertel 7384:
7385: =cut
7386:
1.157 albertel 7387: sub scantron_bubble_selector {
1.503 raeburn 7388: my ($r,$scan_config,$line,$questionnum,$error,@selected)=@_;
1.157 albertel 7389: my $max=$$scan_config{'Qlength'};
1.274 albertel 7390:
7391: my $scmode=$$scan_config{'Qon'};
1.596.2.12.2. (raeburn 7392:): if ($scmode eq 'number' || $scmode eq 'letter') {
7393:): if (($$scan_config{'BubblesPerRow'} =~ /^\d+$/) &&
7394:): ($$scan_config{'BubblesPerRow'} > 0)) {
7395:): $max=$$scan_config{'BubblesPerRow'};
7396:): if (($scmode eq 'number') && ($max > 10)) {
7397:): $max = 10;
7398:): } elsif (($scmode eq 'letter') && $max > 26) {
7399:): $max = 26;
7400:): }
7401:): } else {
7402:): $max = 10;
7403:): }
7404:): }
1.274 albertel 7405:
1.157 albertel 7406: my @alphabet=('A'..'Z');
1.503 raeburn 7407: $r->print(&Apache::loncommon::start_data_table().
7408: &Apache::loncommon::start_data_table_row());
7409: $r->print('<td rowspan="2" class="LC_leftcol_header">'.$line.'</td>');
1.497 foxr 7410: for (my $i=0;$i<$max+1;$i++) {
7411: $r->print("\n".'<td align="center">');
7412: if ($selected[0] eq $alphabet[$i]) { $r->print('X'); shift(@selected) }
7413: else { $r->print(' '); }
7414: $r->print('</td>');
7415: }
1.503 raeburn 7416: $r->print(&Apache::loncommon::end_data_table_row().
7417: &Apache::loncommon::start_data_table_row());
1.497 foxr 7418: for (my $i=0;$i<$max;$i++) {
7419: $r->print("\n".
7420: '<td><label><input type="radio" name="scantron_correct_Q_'.
7421: $line.'" value="'.$i.'" />'.$alphabet[$i]."</label></td>");
7422: }
1.503 raeburn 7423: my $nobub_checked = ' ';
7424: if ($error eq 'missingbubble') {
7425: $nobub_checked = ' checked = "checked" ';
7426: }
7427: $r->print("\n".'<td><label><input type="radio" name="scantron_correct_Q_'.
7428: $line.'" value="none"'.$nobub_checked.'/>'.&mt('No bubble').
7429: '</label>'."\n".'<input type="hidden" name="scantron_questionnum_Q_'.
7430: $line.'" value="'.$questionnum.'" /></td>');
7431: $r->print(&Apache::loncommon::end_data_table_row().
7432: &Apache::loncommon::end_data_table());
1.157 albertel 7433: }
7434:
1.423 albertel 7435: =pod
7436:
7437: =item num_matches
7438:
1.424 albertel 7439: Counts the number of characters that are the same between the two arguments.
7440:
7441: Arguments:
7442: $orig - CODE from the scanline
7443: $code - CODE to match against
7444:
7445: Returns:
7446: $count - integer count of the number of same characters between the
7447: two arguments
7448:
1.423 albertel 7449: =cut
7450:
1.194 albertel 7451: sub num_matches {
7452: my ($orig,$code) = @_;
7453: my @code=split(//,$code);
7454: my @orig=split(//,$orig);
7455: my $same=0;
7456: for (my $i=0;$i<scalar(@code);$i++) {
7457: if ($code[$i] eq $orig[$i]) { $same++; }
7458: }
7459: return $same;
7460: }
7461:
1.423 albertel 7462: =pod
7463:
7464: =item scantron_get_closely_matching_CODEs
7465:
1.424 albertel 7466: Cycles through all CODEs and finds the set that has the greatest
7467: number of same characters as the provided CODE
7468:
7469: Arguments:
7470: $allcodes - hash ref returned by &get_codes()
7471: $CODE - CODE from the current scanline
7472:
7473: Returns:
7474: 2 element list
7475: - first elements is number of how closely matching the best fit is
7476: (5 means best set has 5 matching characters)
7477: - second element is an arrary ref containing the set of valid CODEs
7478: that best fit the passed in CODE
7479:
1.423 albertel 7480: =cut
7481:
1.194 albertel 7482: sub scantron_get_closely_matching_CODEs {
7483: my ($allcodes,$CODE)=@_;
7484: my @CODEs;
7485: foreach my $testcode (sort(keys(%{$allcodes}))) {
7486: push(@{$CODEs[&num_matches($CODE,$testcode)]},$testcode);
7487: }
7488:
7489: return ($#CODEs,$CODEs[-1]);
7490: }
7491:
1.423 albertel 7492: =pod
7493:
7494: =item get_codes
7495:
1.424 albertel 7496: Builds a hash which has keys of all of the valid CODEs from the selected
7497: set of remembered CODEs.
7498:
7499: Arguments:
7500: $old_name - name of the set of remembered CODEs
7501: $cdom - domain of the course
7502: $cnum - internal course name
7503:
7504: Returns:
7505: %allcodes - keys are the valid CODEs, values are all 1
7506:
1.423 albertel 7507: =cut
7508:
1.194 albertel 7509: sub get_codes {
1.280 foxr 7510: my ($old_name, $cdom, $cnum) = @_;
7511: if (!$old_name) {
7512: $old_name=$env{'form.scantron_CODElist'};
7513: }
7514: if (!$cdom) {
7515: $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
7516: }
7517: if (!$cnum) {
7518: $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
7519: }
1.278 albertel 7520: my %result=&Apache::lonnet::get('CODEs',[$old_name,"type\0$old_name"],
7521: $cdom,$cnum);
7522: my %allcodes;
7523: if ($result{"type\0$old_name"} eq 'number') {
7524: %allcodes=map {($_,1)} split(',',$result{$old_name});
7525: } else {
7526: %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
7527: }
1.194 albertel 7528: return %allcodes;
7529: }
7530:
1.423 albertel 7531: =pod
7532:
7533: =item scantron_validate_CODE
7534:
1.424 albertel 7535: Validates all scanlines in the selected file to not have any
7536: invalid or underspecified CODEs and that none of the codes are
7537: duplicated if this was requested.
7538:
1.423 albertel 7539: =cut
7540:
1.157 albertel 7541: sub scantron_validate_CODE {
7542: my ($r,$currentphase) = @_;
1.257 albertel 7543: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.186 albertel 7544: if ($scantron_config{'CODElocation'} &&
7545: $scantron_config{'CODEstart'} &&
7546: $scantron_config{'CODElength'}) {
1.257 albertel 7547: if (!defined($env{'form.scantron_CODElist'})) {
1.186 albertel 7548: &FIXME_blow_up()
7549: }
7550: } else {
7551: return (0,$currentphase+1);
7552: }
7553:
7554: my %usedCODEs;
7555:
1.194 albertel 7556: my %allcodes=&get_codes();
1.186 albertel 7557:
1.582 raeburn 7558: my $nav_error;
1.596.2.12.2. (raeburn 7559:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the lines per response array.
1.582 raeburn 7560: if ($nav_error) {
7561: $r->print(&navmap_errormsg());
7562: return(1,$currentphase);
7563: }
1.447 foxr 7564:
1.186 albertel 7565: my ($scanlines,$scan_data)=&scantron_getfile();
7566: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7567: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.186 albertel 7568: if ($line=~/^[\s\cz]*$/) { next; }
7569: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7570: $scan_data);
7571: my $CODE=$$scan_record{'scantron.CODE'};
7572: my $error=0;
1.224 albertel 7573: if (!&Apache::lonnet::validCODE($CODE)) {
7574: &scantron_get_correction($r,$i,$scan_record,
7575: \%scantron_config,
7576: $line,'incorrectCODE',\%allcodes);
7577: return(1,$currentphase);
7578: }
1.221 albertel 7579: if (%allcodes && !exists($allcodes{$CODE})
7580: && !$$scan_record{'scantron.useCODE'}) {
1.186 albertel 7581: &scantron_get_correction($r,$i,$scan_record,
7582: \%scantron_config,
1.194 albertel 7583: $line,'incorrectCODE',\%allcodes);
7584: return(1,$currentphase);
1.186 albertel 7585: }
1.214 albertel 7586: if (exists($usedCODEs{$CODE})
1.257 albertel 7587: && $env{'form.scantron_CODEunique'} eq 'yes'
1.192 albertel 7588: && !$$scan_record{'scantron.CODE_ignore_dup'}) {
1.186 albertel 7589: &scantron_get_correction($r,$i,$scan_record,
7590: \%scantron_config,
1.194 albertel 7591: $line,'duplicateCODE',$usedCODEs{$CODE});
7592: return(1,$currentphase);
1.186 albertel 7593: }
1.524 raeburn 7594: push(@{$usedCODEs{$CODE}},$$scan_record{'scantron.PaperID'});
1.186 albertel 7595: }
1.157 albertel 7596: return (0,$currentphase+1);
7597: }
7598:
1.423 albertel 7599: =pod
7600:
7601: =item scantron_validate_doublebubble
7602:
1.424 albertel 7603: Validates all scanlines in the selected file to not have any
7604: bubble lines with multiple bubbles marked.
7605:
1.423 albertel 7606: =cut
7607:
1.157 albertel 7608: sub scantron_validate_doublebubble {
7609: my ($r,$currentphase) = @_;
7610: #get student info
7611: my $classlist=&Apache::loncoursedata::get_classlist();
7612: my %idmap=&username_to_idmap($classlist);
7613:
7614: #get scantron line setup
1.257 albertel 7615: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7616: my ($scanlines,$scan_data)=&scantron_getfile();
1.583 raeburn 7617: my $nav_error;
1.596.2.12.2. (raeburn 7618:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the bubble line array.
1.583 raeburn 7619: if ($nav_error) {
7620: $r->print(&navmap_errormsg());
7621: return(1,$currentphase);
7622: }
1.447 foxr 7623:
1.157 albertel 7624: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7625: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7626: if ($line=~/^[\s\cz]*$/) { next; }
7627: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7628: $scan_data);
7629: if (!defined($$scan_record{'scantron.doubleerror'})) { next; }
7630: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,$line,
7631: 'doublebubble',
7632: $$scan_record{'scantron.doubleerror'});
7633: return (1,$currentphase);
7634: }
7635: return (0,$currentphase+1);
7636: }
7637:
1.423 albertel 7638:
1.503 raeburn 7639: sub scantron_get_maxbubble {
1.596.2.12.2. (raeburn 7640:): my ($nav_error,$scantron_config) = @_;
1.257 albertel 7641: if (defined($env{'form.scantron_maxbubble'}) &&
7642: $env{'form.scantron_maxbubble'}) {
1.447 foxr 7643: &restore_bubble_lines();
1.257 albertel 7644: return $env{'form.scantron_maxbubble'};
1.191 albertel 7645: }
1.330 albertel 7646:
1.447 foxr 7647: my (undef, undef, $sequence) =
1.257 albertel 7648: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.330 albertel 7649:
1.447 foxr 7650: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 7651: unless (ref($navmap)) {
7652: if (ref($nav_error)) {
7653: $$nav_error = 1;
7654: }
1.591 raeburn 7655: return;
1.582 raeburn 7656: }
1.191 albertel 7657: my $map=$navmap->getResourceByUrl($sequence);
7658: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.596.2.12.2. (raeburn 7659:): my $bubbles_per_row = &bubblesheet_bubbles_per_row($scantron_config);
1.330 albertel 7660:
7661: &Apache::lonxml::clear_problem_counter();
7662:
1.557 raeburn 7663: my $uname = $env{'user.name'};
7664: my $udom = $env{'user.domain'};
1.435 foxr 7665: my $cid = $env{'request.course.id'};
7666: my $total_lines = 0;
7667: %bubble_lines_per_response = ();
1.447 foxr 7668: %first_bubble_line = ();
1.503 raeburn 7669: %subdivided_bubble_lines = ();
7670: %responsetype_per_response = ();
1.554 raeburn 7671:
1.447 foxr 7672: my $response_number = 0;
7673: my $bubble_line = 0;
1.191 albertel 7674: foreach my $resource (@resources) {
1.596.2.12.2. (raeburn 7675:): my ($analysis,$parts) = &scantron_partids_tograde($resource,$cid,$uname,
7676:): $udom,$bubbles_per_row);
1.542 raeburn 7677: if ((ref($analysis) eq 'HASH') && (ref($parts) eq 'ARRAY')) {
7678: foreach my $part_id (@{$parts}) {
7679: my $lines;
7680:
7681: # TODO - make this a persistent hash not an array.
7682:
7683: # optionresponse, matchresponse and rankresponse type items
7684: # render as separate sub-questions in exam mode.
7685: if (($analysis->{$part_id.'.type'} eq 'optionresponse') ||
7686: ($analysis->{$part_id.'.type'} eq 'matchresponse') ||
7687: ($analysis->{$part_id.'.type'} eq 'rankresponse')) {
7688: my ($numbub,$numshown);
7689: if ($analysis->{$part_id.'.type'} eq 'optionresponse') {
7690: if (ref($analysis->{$part_id.'.options'}) eq 'ARRAY') {
7691: $numbub = scalar(@{$analysis->{$part_id.'.options'}});
7692: }
7693: } elsif ($analysis->{$part_id.'.type'} eq 'matchresponse') {
7694: if (ref($analysis->{$part_id.'.items'}) eq 'ARRAY') {
7695: $numbub = scalar(@{$analysis->{$part_id.'.items'}});
7696: }
7697: } elsif ($analysis->{$part_id.'.type'} eq 'rankresponse') {
7698: if (ref($analysis->{$part_id.'.foils'}) eq 'ARRAY') {
7699: $numbub = scalar(@{$analysis->{$part_id.'.foils'}});
7700: }
7701: }
7702: if (ref($analysis->{$part_id.'.shown'}) eq 'ARRAY') {
7703: $numshown = scalar(@{$analysis->{$part_id.'.shown'}});
7704: }
1.596.2.12.2. (raeburn 7705:): my $bubbles_per_row =
7706:): &bubblesheet_bubbles_per_row($scantron_config);
7707:): my $inner_bubble_lines = int($numbub/$bubbles_per_row);
7708:): if (($numbub % $bubbles_per_row) != 0) {
1.542 raeburn 7709: $inner_bubble_lines++;
7710: }
7711: for (my $i=0; $i<$numshown; $i++) {
7712: $subdivided_bubble_lines{$response_number} .=
7713: $inner_bubble_lines.',';
7714: }
7715: $subdivided_bubble_lines{$response_number} =~ s/,$//;
7716: $lines = $numshown * $inner_bubble_lines;
7717: } else {
7718: $lines = $analysis->{"$part_id.bubble_lines"};
1.596.2.12.2. (raeburn 7719:): }
1.542 raeburn 7720:
7721: $first_bubble_line{$response_number} = $bubble_line;
7722: $bubble_lines_per_response{$response_number} = $lines;
7723: $responsetype_per_response{$response_number} =
7724: $analysis->{$part_id.'.type'};
7725: $response_number++;
7726:
7727: $bubble_line += $lines;
7728: $total_lines += $lines;
7729: }
7730: }
7731: }
1.552 raeburn 7732: &Apache::lonnet::delenv('scantron.');
1.542 raeburn 7733:
7734: &save_bubble_lines();
7735: $env{'form.scantron_maxbubble'} =
7736: $total_lines;
7737: return $env{'form.scantron_maxbubble'};
7738: }
1.523 raeburn 7739:
1.596.2.12.2. (raeburn 7740:): sub bubblesheet_bubbles_per_row {
7741:): my ($scantron_config) = @_;
7742:): my $bubbles_per_row;
7743:): if (ref($scantron_config) eq 'HASH') {
7744:): $bubbles_per_row = $scantron_config->{'BubblesPerRow'};
7745:): }
7746:): if ((!$bubbles_per_row) || ($bubbles_per_row < 1)) {
7747:): $bubbles_per_row = 10;
7748:): }
7749:): return $bubbles_per_row;
7750:): }
7751:):
1.157 albertel 7752: sub scantron_validate_missingbubbles {
7753: my ($r,$currentphase) = @_;
7754: #get student info
7755: my $classlist=&Apache::loncoursedata::get_classlist();
7756: my %idmap=&username_to_idmap($classlist);
7757:
7758: #get scantron line setup
1.257 albertel 7759: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7760: my ($scanlines,$scan_data)=&scantron_getfile();
1.582 raeburn 7761: my $nav_error;
1.596.2.12.2. (raeburn 7762:): my $max_bubble=&scantron_get_maxbubble(\$nav_error,\%scantron_config);
1.582 raeburn 7763: if ($nav_error) {
7764: return(1,$currentphase);
7765: }
1.157 albertel 7766: if (!$max_bubble) { $max_bubble=2**31; }
7767: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7768: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7769: if ($line=~/^[\s\cz]*$/) { next; }
7770: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7771: $scan_data);
7772: if (!defined($$scan_record{'scantron.missingerror'})) { next; }
7773: my @to_correct;
1.470 foxr 7774:
7775: # Probably here's where the error is...
7776:
1.157 albertel 7777: foreach my $missing (@{$$scan_record{'scantron.missingerror'}}) {
1.505 raeburn 7778: my $lastbubble;
7779: if ($missing =~ /^(\d+)\.(\d+)$/) {
7780: my $question = $1;
7781: my $subquestion = $2;
7782: if (!defined($first_bubble_line{$question -1})) { next; }
7783: my $first = $first_bubble_line{$question-1};
7784: my @subans = split(/,/,$subdivided_bubble_lines{$question-1});
7785: my $subcount = 1;
7786: while ($subcount<$subquestion) {
7787: $first += $subans[$subcount-1];
7788: $subcount ++;
7789: }
7790: my $count = $subans[$subquestion-1];
7791: $lastbubble = $first + $count;
7792: } else {
7793: if (!defined($first_bubble_line{$missing - 1})) { next; }
7794: $lastbubble = $first_bubble_line{$missing - 1} + $bubble_lines_per_response{$missing - 1};
7795: }
7796: if ($lastbubble > $max_bubble) { next; }
1.157 albertel 7797: push(@to_correct,$missing);
7798: }
7799: if (@to_correct) {
7800: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
7801: $line,'missingbubble',\@to_correct);
7802: return (1,$currentphase);
7803: }
7804:
7805: }
7806: return (0,$currentphase+1);
7807: }
7808:
1.423 albertel 7809:
1.82 albertel 7810: sub scantron_process_students {
1.75 albertel 7811: my ($r) = @_;
1.513 foxr 7812:
1.257 albertel 7813: my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($env{'form.selectpage'});
1.324 albertel 7814: my ($symb)=&get_symb($r);
1.513 foxr 7815: if (!$symb) {
7816: return '';
7817: }
1.324 albertel 7818: my $default_form_data=&defaultFormData($symb);
1.82 albertel 7819:
1.257 albertel 7820: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7821: my ($scanlines,$scan_data)=&scantron_getfile();
1.82 albertel 7822: my $classlist=&Apache::loncoursedata::get_classlist();
7823: my %idmap=&username_to_idmap($classlist);
1.132 bowersj2 7824: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 7825: unless (ref($navmap)) {
7826: $r->print(&navmap_errormsg());
7827: return '';
7828: }
1.83 albertel 7829: my $map=$navmap->getResourceByUrl($sequence);
7830: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.557 raeburn 7831: my (%grader_partids_by_symb,%grader_randomlists_by_symb);
7832: &graders_resources_pass(\@resources,\%grader_partids_by_symb,
7833: \%grader_randomlists_by_symb);
1.586 raeburn 7834: my $resource_error;
1.557 raeburn 7835: foreach my $resource (@resources) {
1.586 raeburn 7836: my $ressymb;
7837: if (ref($resource)) {
7838: $ressymb = $resource->symb();
7839: } else {
7840: $resource_error = 1;
7841: last;
7842: }
1.557 raeburn 7843: my ($analysis,$parts) =
7844: &scantron_partids_tograde($resource,$env{'request.course.id'},
1.596.2.12.2. (raeburn 7845:): $env{'user.name'},$env{'user.domain'},
7846:): 1,$bubbles_per_row);
1.557 raeburn 7847: $grader_partids_by_symb{$ressymb} = $parts;
7848: if (ref($analysis) eq 'HASH') {
7849: if (ref($analysis->{'parts_withrandomlist'}) eq 'ARRAY') {
7850: $grader_randomlists_by_symb{$ressymb} =
7851: $analysis->{'parts_withrandomlist'};
7852: }
7853: }
7854: }
1.586 raeburn 7855: if ($resource_error) {
7856: $r->print(&navmap_errormsg());
7857: return '';
7858: }
1.557 raeburn 7859:
1.554 raeburn 7860: my ($uname,$udom);
1.82 albertel 7861: my $result= <<SCANTRONFORM;
1.81 albertel 7862: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
7863: <input type="hidden" name="command" value="scantron_configphase" />
7864: $default_form_data
7865: SCANTRONFORM
1.82 albertel 7866: $r->print($result);
7867:
7868: my @delayqueue;
1.542 raeburn 7869: my (%completedstudents,%scandata);
1.140 albertel 7870:
1.520 www 7871: my $lock=&Apache::lonnet::set_lock(&mt('Grading bubblesheet exam'));
1.200 albertel 7872: my $count=&get_todo_count($scanlines,$scan_data);
1.575 www 7873: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Bubblesheet Status',
7874: 'Bubblesheet Progress',$count,
1.195 albertel 7875: 'inline',undef,'scantronupload');
1.140 albertel 7876: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
7877: 'Processing first student');
1.542 raeburn 7878: $r->print('<br />');
1.140 albertel 7879: my $start=&Time::HiRes::time();
1.158 albertel 7880: my $i=-1;
1.542 raeburn 7881: my $started;
1.447 foxr 7882:
1.582 raeburn 7883: my $nav_error;
1.596.2.12.2. (raeburn 7884:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # Need the bubble lines array to parse.
1.582 raeburn 7885: if ($nav_error) {
7886: $r->print(&navmap_errormsg());
7887: return '';
7888: }
7889:
1.513 foxr 7890: # If an ssi failed in scantron_get_maxbubble, put an error message out to
7891: # the user and return.
7892:
7893: if ($ssi_error) {
7894: $r->print("</form>");
7895: &ssi_print_error($r);
7896: $r->print(&show_grading_menu_form($symb));
1.520 www 7897: &Apache::lonnet::remove_lock($lock);
1.513 foxr 7898: return ''; # Dunno why the other returns return '' rather than just returning.
7899: }
1.447 foxr 7900:
1.542 raeburn 7901: my %lettdig = &letter_to_digits();
7902: my $numletts = scalar(keys(%lettdig));
7903:
1.157 albertel 7904: while ($i<$scanlines->{'count'}) {
7905: ($uname,$udom)=('','');
7906: $i++;
1.200 albertel 7907: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7908: if ($line=~/^[\s\cz]*$/) { next; }
1.200 albertel 7909: if ($started) {
7910: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
7911: 'last student');
7912: }
7913: $started=1;
1.157 albertel 7914: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7915: $scan_data);
7916: unless ($uname=&scantron_find_student($scan_record,$scan_data,
7917: \%idmap,$i)) {
7918: &scantron_add_delay(\@delayqueue,$line,
7919: 'Unable to find a student that matches',1);
7920: next;
7921: }
7922: if (exists $completedstudents{$uname}) {
7923: &scantron_add_delay(\@delayqueue,$line,
7924: 'Student '.$uname.' has multiple sheets',2);
7925: next;
7926: }
7927: ($uname,$udom)=split(/:/,$uname);
1.330 albertel 7928:
1.586 raeburn 7929: my (%partids_by_symb,$res_error);
1.554 raeburn 7930: foreach my $resource (@resources) {
1.586 raeburn 7931: my $ressymb;
7932: if (ref($resource)) {
7933: $ressymb = $resource->symb();
7934: } else {
7935: $res_error = 1;
7936: last;
7937: }
1.557 raeburn 7938: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
7939: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
7940: my ($analysis,$parts) =
1.596.2.12.2. (raeburn 7941:): &scantron_partids_tograde($resource,$env{'request.course.id'},
7942:): $uname,$udom,undef,$bubbles_per_row);
1.557 raeburn 7943: $partids_by_symb{$ressymb} = $parts;
7944: } else {
7945: $partids_by_symb{$ressymb} = $grader_partids_by_symb{$ressymb};
7946: }
1.554 raeburn 7947: }
7948:
1.586 raeburn 7949: if ($res_error) {
7950: &scantron_add_delay(\@delayqueue,$line,
7951: 'An error occurred while grading student '.$uname,2);
7952: next;
7953: }
7954:
1.330 albertel 7955: &Apache::lonxml::clear_problem_counter();
1.514 raeburn 7956: &Apache::lonnet::appenv($scan_record);
1.376 albertel 7957:
7958: if (&scantron_clear_skip($scanlines,$scan_data,$i)) {
7959: &scantron_putfile($scanlines,$scan_data);
7960: }
1.161 albertel 7961:
1.542 raeburn 7962: my $scancode;
7963: if ((exists($scan_record->{'scantron.CODE'})) &&
7964: (&Apache::lonnet::validCODE($scan_record->{'scantron.CODE'}))) {
7965: $scancode = $scan_record->{'scantron.CODE'};
7966: } else {
7967: $scancode = '';
7968: }
7969:
7970: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
1.596.2.12.2. (raeburn 7971:): \@resources,\%partids_by_symb,
7972:): $bubbles_per_row) eq 'ssi_error') {
1.542 raeburn 7973: $ssi_error = 0; # So end of handler error message does not trigger.
7974: $r->print("</form>");
7975: &ssi_print_error($r);
7976: $r->print(&show_grading_menu_form($symb));
7977: &Apache::lonnet::remove_lock($lock);
7978: return ''; # Why return ''? Beats me.
7979: }
1.513 foxr 7980:
1.140 albertel 7981: $completedstudents{$uname}={'line'=>$line};
1.542 raeburn 7982: if ($env{'form.verifyrecord'}) {
7983: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
7984: my $studentdata = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
7985: chomp($studentdata);
7986: $studentdata =~ s/\r$//;
7987: my $studentrecord = '';
7988: my $counter = -1;
7989: foreach my $resource (@resources) {
1.554 raeburn 7990: my $ressymb = $resource->symb();
1.542 raeburn 7991: ($counter,my $recording) =
7992: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 7993: $counter,$studentdata,$partids_by_symb{$ressymb},
1.542 raeburn 7994: \%scantron_config,\%lettdig,$numletts);
7995: $studentrecord .= $recording;
7996: }
7997: if ($studentrecord ne $studentdata) {
1.554 raeburn 7998: &Apache::lonxml::clear_problem_counter();
7999: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
1.596.2.12.2. (raeburn 8000:): \@resources,\%partids_by_symb,
8001:): $bubbles_per_row) eq 'ssi_error') {
1.554 raeburn 8002: $ssi_error = 0; # So end of handler error message does not trigger.
8003: $r->print("</form>");
8004: &ssi_print_error($r);
8005: $r->print(&show_grading_menu_form($symb));
8006: &Apache::lonnet::remove_lock($lock);
8007: delete($completedstudents{$uname});
8008: return '';
8009: }
1.542 raeburn 8010: $counter = -1;
8011: $studentrecord = '';
8012: foreach my $resource (@resources) {
1.554 raeburn 8013: my $ressymb = $resource->symb();
1.542 raeburn 8014: ($counter,my $recording) =
8015: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 8016: $counter,$studentdata,$partids_by_symb{$ressymb},
1.542 raeburn 8017: \%scantron_config,\%lettdig,$numletts);
8018: $studentrecord .= $recording;
8019: }
8020: if ($studentrecord ne $studentdata) {
1.596.2.6 raeburn 8021: $r->print('<p><span class="LC_warning">');
1.542 raeburn 8022: if ($scancode eq '') {
1.596.2.6 raeburn 8023: $r->print(&mt('Mismatch grading bubblesheet for user: [_1] with ID: [_2].',
1.542 raeburn 8024: $uname.':'.$udom,$scan_record->{'scantron.ID'}));
8025: } else {
1.596.2.6 raeburn 8026: $r->print(&mt('Mismatch grading bubblesheet for user: [_1] with ID: [_2] and CODE: [_3].',
1.542 raeburn 8027: $uname.':'.$udom,$scan_record->{'scantron.ID'},$scancode));
8028: }
8029: $r->print('</span><br />'.&Apache::loncommon::start_data_table()."\n".
8030: &Apache::loncommon::start_data_table_header_row()."\n".
8031: '<th>'.&mt('Source').'</th><th>'.&mt('Bubbled responses').'</th>'.
8032: &Apache::loncommon::end_data_table_header_row()."\n".
8033: &Apache::loncommon::start_data_table_row().
1.596.2.6 raeburn 8034: '<td>'.&mt('Bubblesheet').'</td>'.
1.542 raeburn 8035: '<td><span class="LC_nobreak">'.$studentdata.'</span></td>'.
8036: &Apache::loncommon::end_data_table_row().
8037: &Apache::loncommon::start_data_table_row().
1.596.2.6 raeburn 8038: '<td>'.&mt('Stored submissions').'</td>'.
1.542 raeburn 8039: '<td><span class="LC_nobreak">'.$studentrecord.'</span></td>'."\n".
8040: &Apache::loncommon::end_data_table_row().
8041: &Apache::loncommon::end_data_table().'</p>');
8042: } else {
8043: $r->print('<br /><span class="LC_warning">'.
8044: &mt('A second grading pass was needed for user: [_1] with ID: [_2], because a mismatch was seen on the first pass.',$uname.':'.$udom,$scan_record->{'scantron.ID'}).'<br />'.
8045: &mt("As a consequence, this user's submission history records two tries.").
8046: '</span><br />');
8047: }
8048: }
8049: }
1.543 raeburn 8050: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.140 albertel 8051: } continue {
1.330 albertel 8052: &Apache::lonxml::clear_problem_counter();
1.552 raeburn 8053: &Apache::lonnet::delenv('scantron.');
1.82 albertel 8054: }
1.140 albertel 8055: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.520 www 8056: &Apache::lonnet::remove_lock($lock);
1.172 albertel 8057: # my $lasttime = &Time::HiRes::time()-$start;
8058: # $r->print("<p>took $lasttime</p>");
1.140 albertel 8059:
1.200 albertel 8060: $r->print("</form>");
1.324 albertel 8061: $r->print(&show_grading_menu_form($symb));
1.157 albertel 8062: return '';
1.75 albertel 8063: }
1.157 albertel 8064:
1.557 raeburn 8065: sub graders_resources_pass {
8066: my ($resources,$grader_partids_by_symb,$grader_randomlists_by_symb) = @_;
8067: if ((ref($resources) eq 'ARRAY') && (ref($grader_partids_by_symb)) &&
8068: (ref($grader_randomlists_by_symb) eq 'HASH')) {
8069: foreach my $resource (@{$resources}) {
8070: my $ressymb = $resource->symb();
8071: my ($analysis,$parts) =
8072: &scantron_partids_tograde($resource,$env{'request.course.id'},
1.596.2.12.2. (raeburn 8073:): $env{'user.name'},$env{'user.domain'},
8074:): 1,$bubbles_per_row);
1.557 raeburn 8075: $grader_partids_by_symb->{$ressymb} = $parts;
8076: if (ref($analysis) eq 'HASH') {
8077: if (ref($analysis->{'parts_withrandomlist'}) eq 'ARRAY') {
8078: $grader_randomlists_by_symb->{$ressymb} =
8079: $analysis->{'parts_withrandomlist'};
8080: }
8081: }
8082: }
8083: }
8084: return;
8085: }
8086:
1.542 raeburn 8087: sub grade_student_bubbles {
1.596.2.12.2. (raeburn 8088:): my ($r,$uname,$udom,$scan_record,$scancode,$resources,$parts,$bubbles_per_row) = @_;
1.554 raeburn 8089: if (ref($resources) eq 'ARRAY') {
8090: my $count = 0;
8091: foreach my $resource (@{$resources}) {
8092: my $ressymb = $resource->symb();
8093: my %form = ('submitted' => 'scantron',
8094: 'grade_target' => 'grade',
8095: 'grade_username' => $uname,
8096: 'grade_domain' => $udom,
8097: 'grade_courseid' => $env{'request.course.id'},
8098: 'grade_symb' => $ressymb,
8099: 'CODE' => $scancode
8100: );
1.596.2.12.2. (raeburn 8101:): if ($bubbles_per_row ne '') {
8102:): $form{'bubbles_per_row'} = $bubbles_per_row;
8103:): }
1.554 raeburn 8104: if (ref($parts) eq 'HASH') {
8105: if (ref($parts->{$ressymb}) eq 'ARRAY') {
8106: foreach my $part (@{$parts->{$ressymb}}) {
8107: $form{'scantron_questnum_start.'.$part} =
8108: 1+$env{'form.scantron.first_bubble_line.'.$count};
8109: $count++;
8110: }
8111: }
8112: }
8113: my $result=&ssi_with_retries($resource->src(),$ssi_retries,%form);
8114: return 'ssi_error' if ($ssi_error);
8115: last if (&Apache::loncommon::connection_aborted($r));
8116: }
1.542 raeburn 8117: }
8118: return;
8119: }
8120:
1.157 albertel 8121: sub scantron_upload_scantron_data {
8122: my ($r)=@_;
1.565 raeburn 8123: my $dom = $env{'request.role.domain'};
8124: my $domdesc = &Apache::lonnet::domain($dom,'description');
8125: $r->print(&Apache::loncommon::coursebrowser_javascript($dom));
1.157 albertel 8126: my $select_link=&Apache::loncommon::selectcourse_link('rules','courseid',
1.181 albertel 8127: 'domainid',
1.565 raeburn 8128: 'coursename',$dom);
8129: my $syllabuslink = '<a href="javascript:ToSyllabus();">'.&mt('Syllabus').'</a>'.
8130: (' 'x2).&mt('(shows course personnel)');
1.324 albertel 8131: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.579 raeburn 8132: my $nofile_alert = &mt('Please use the browse button to select a file from your local directory.');
8133: my $nocourseid_alert = &mt("Please use the 'Select Course' link to open a separate window where you can search for a course to which a file can be uploaded.");
1.492 albertel 8134: $r->print('
1.157 albertel 8135: <script type="text/javascript" language="javascript">
8136: function checkUpload(formname) {
8137: if (formname.upfile.value == "") {
1.579 raeburn 8138: alert("'.$nofile_alert.'");
1.157 albertel 8139: return false;
8140: }
1.565 raeburn 8141: if (formname.courseid.value == "") {
1.579 raeburn 8142: alert("'.$nocourseid_alert.'");
1.565 raeburn 8143: return false;
8144: }
1.157 albertel 8145: formname.submit();
8146: }
1.565 raeburn 8147:
8148: function ToSyllabus() {
8149: var cdom = '."'$dom'".';
8150: var cnum = document.rules.courseid.value;
8151: if (cdom == "" || cdom == null) {
8152: return;
8153: }
8154: if (cnum == "" || cnum == null) {
8155: return;
8156: }
8157: syllwin=window.open("/public/"+cdom+"/"+cnum+"/syllabus","LONCAPASyllabus",
8158: "height=350,width=350,scrollbars=yes,menubar=no");
8159: return;
8160: }
8161:
1.157 albertel 8162: </script>
8163:
1.596.2.4 raeburn 8164: <h3>'.&mt('Send bubblesheet data to a course').'</h3>
1.566 raeburn 8165:
1.492 albertel 8166: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
1.565 raeburn 8167: '.$default_form_data.
8168: &Apache::lonhtmlcommon::start_pick_box().
8169: &Apache::lonhtmlcommon::row_title(&mt('Course ID')).
8170: '<input name="courseid" type="text" size="30" />'.$select_link.
8171: &Apache::lonhtmlcommon::row_closure().
8172: &Apache::lonhtmlcommon::row_title(&mt('Course Name')).
8173: '<input name="coursename" type="text" size="30" />'.$syllabuslink.
8174: &Apache::lonhtmlcommon::row_closure().
8175: &Apache::lonhtmlcommon::row_title(&mt('Domain')).
8176: '<input name="domainid" type="hidden" />'.$domdesc.
8177: &Apache::lonhtmlcommon::row_closure().
8178: &Apache::lonhtmlcommon::row_title(&mt('File to upload')).
8179: '<input type="file" name="upfile" size="50" />'.
8180: &Apache::lonhtmlcommon::row_closure(1).
8181: &Apache::lonhtmlcommon::end_pick_box().'<br />
8182:
1.492 albertel 8183: <input name="command" value="scantronupload_save" type="hidden" />
1.589 bisitz 8184: <input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
1.157 albertel 8185: </form>
1.492 albertel 8186: ');
1.157 albertel 8187: return '';
8188: }
8189:
1.423 albertel 8190:
1.157 albertel 8191: sub scantron_upload_scantron_data_save {
8192: my($r)=@_;
1.324 albertel 8193: my ($symb)=&get_symb($r,1);
1.182 albertel 8194: my $doanotherupload=
8195: '<br /><form action="/adm/grades" method="post">'."\n".
8196: '<input type="hidden" name="command" value="scantronupload" />'."\n".
1.492 albertel 8197: '<input type="submit" name="submit" value="'.&mt('Do Another Upload').'" />'."\n".
1.182 albertel 8198: '</form>'."\n";
1.257 albertel 8199: if (!&Apache::lonnet::allowed('usc',$env{'form.domainid'}) &&
1.162 albertel 8200: !&Apache::lonnet::allowed('usc',
1.257 albertel 8201: $env{'form.domainid'}.'_'.$env{'form.courseid'})) {
1.575 www 8202: $r->print(&mt("You are not allowed to upload bubblesheet data to the requested course.")."<br />");
1.182 albertel 8203: if ($symb) {
1.324 albertel 8204: $r->print(&show_grading_menu_form($symb));
1.182 albertel 8205: } else {
8206: $r->print($doanotherupload);
8207: }
1.162 albertel 8208: return '';
8209: }
1.257 albertel 8210: my %coursedata=&Apache::lonnet::coursedescription($env{'form.domainid'}.'_'.$env{'form.courseid'});
1.568 raeburn 8211: my $uploadedfile;
1.567 raeburn 8212: $r->print('<h3>'.&mt("Uploading file to [_1]",$coursedata{'description'}).'</h3>');
1.257 albertel 8213: if (length($env{'form.upfile'}) < 2) {
1.568 raeburn 8214: $r->print(&mt('[_1]Error:[_2] The file you attempted to upload, [_3] contained no information. Please check that you entered the correct filename.','<span class="LC_error">','</span>','<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'));
1.183 albertel 8215: } else {
1.568 raeburn 8216: my $result =
8217: &Apache::lonnet::userfileupload('upfile','','scantron','','','',
8218: $env{'form.courseid'},$env{'form.domainid'});
8219: if ($result =~ m{^/uploaded/}) {
1.567 raeburn 8220: $r->print(&mt('[_1]Success:[_2] Successfully uploaded [_3] bytes of data into location: [_4]',
8221: '<span class="LC_success">','</span>',(length($env{'form.upfile'})-1),
8222: '<span class="LC_filename">'.$result.'</span>'));
1.568 raeburn 8223: ($uploadedfile) = ($result =~ m{/([^/]+)$});
1.567 raeburn 8224: $r->print(&validate_uploaded_scantron_file($env{'form.domainid'},
1.568 raeburn 8225: $env{'form.courseid'},$uploadedfile));
1.210 albertel 8226: } else {
1.567 raeburn 8227: $r->print(&mt('[_1]Error:[_2] An error ([_3]) occurred when attempting to upload the file, [_4]',
8228: '<span class="LC_error">','</span>',$result,
1.568 raeburn 8229: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'));
1.183 albertel 8230: }
8231: }
1.174 albertel 8232: if ($symb) {
1.209 ng 8233: $r->print(&scantron_selectphase($r,$uploadedfile));
1.174 albertel 8234: } else {
1.182 albertel 8235: $r->print($doanotherupload);
1.174 albertel 8236: }
1.157 albertel 8237: return '';
8238: }
8239:
1.567 raeburn 8240: sub validate_uploaded_scantron_file {
8241: my ($cdom,$cname,$fname) = @_;
8242: my $scanlines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.$fname);
8243: my @lines;
8244: if ($scanlines ne '-1') {
8245: @lines=split("\n",$scanlines,-1);
8246: }
8247: my $output;
8248: if (@lines) {
8249: my (%counts,$max_match_format);
8250: my ($max_match_count,$max_match_pct) = (0,0);
8251: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cname);
8252: my %idmap = &username_to_idmap($classlist);
8253: foreach my $key (keys(%idmap)) {
8254: my $lckey = lc($key);
8255: $idmap{$lckey} = $idmap{$key};
8256: }
8257: my %unique_formats;
8258: my @formatlines = &get_scantronformat_file();
8259: foreach my $line (@formatlines) {
8260: chomp($line);
8261: my @config = split(/:/,$line);
8262: my $idstart = $config[5];
8263: my $idlength = $config[6];
8264: if (($idstart ne '') && ($idlength > 0)) {
8265: if (ref($unique_formats{$idstart.':'.$idlength}) eq 'ARRAY') {
8266: push(@{$unique_formats{$idstart.':'.$idlength}},$config[0].':'.$config[1]);
8267: } else {
8268: $unique_formats{$idstart.':'.$idlength} = [$config[0].':'.$config[1]];
8269: }
8270: }
8271: }
8272: foreach my $key (keys(%unique_formats)) {
8273: my ($idstart,$idlength) = split(':',$key);
8274: %{$counts{$key}} = (
8275: 'found' => 0,
8276: 'total' => 0,
8277: );
8278: foreach my $line (@lines) {
8279: next if ($line =~ /^#/);
8280: next if ($line =~ /^[\s\cz]*$/);
8281: my $id = substr($line,$idstart-1,$idlength);
8282: $id = lc($id);
8283: if (exists($idmap{$id})) {
8284: $counts{$key}{'found'} ++;
8285: }
8286: $counts{$key}{'total'} ++;
8287: }
8288: if ($counts{$key}{'total'}) {
8289: my $percent_match = (100*$counts{$key}{'found'})/($counts{$key}{'total'});
8290: if (($max_match_format eq '') || ($percent_match > $max_match_pct)) {
8291: $max_match_pct = $percent_match;
8292: $max_match_format = $key;
8293: $max_match_count = $counts{$key}{'total'};
8294: }
8295: }
8296: }
8297: if (ref($unique_formats{$max_match_format}) eq 'ARRAY') {
8298: my $format_descs;
8299: my $numwithformat = @{$unique_formats{$max_match_format}};
8300: for (my $i=0; $i<$numwithformat; $i++) {
8301: my ($name,$desc) = split(':',$unique_formats{$max_match_format}[$i]);
8302: if ($i<$numwithformat-2) {
8303: $format_descs .= '"<i>'.$desc.'</i>", ';
8304: } elsif ($i==$numwithformat-2) {
8305: $format_descs .= '"<i>'.$desc.'</i>" '.&mt('and').' ';
8306: } elsif ($i==$numwithformat-1) {
8307: $format_descs .= '"<i>'.$desc.'</i>"';
8308: }
8309: }
8310: my $showpct = sprintf("%.0f",$max_match_pct).'%';
8311: $output .= '<br />'.&mt('Comparison of student IDs in the uploaded file with the course roster found matches for [_1] of the [_2] entries in the file (for the format defined for [_3]).','<b>'.$showpct.'</b>','<b>'.$max_match_count.'</b>',$format_descs).
8312: '<br />'.&mt('A low percentage of matches results from one of the following:').'<ul>'.
8313: '<li>'.&mt('The file was uploaded to the wrong course').'</li>'.
8314: '<li>'.&mt('The data are not in the format expected for the domain: [_1]',
8315: '<i>'.$cdom.'</i>').'</li>'.
8316: '<li>'.&mt('Students did not bubble their IDs, or mis-bubbled them').'</li>'.
8317: '<li>'.&mt('The course roster is not up to date').'</li>'.
8318: '</ul>';
8319: }
8320: } else {
8321: $output = '<span class="LC_warning">'.&mt('Uploaded file contained no data').'</span>';
8322: }
8323: return $output;
8324: }
8325:
1.202 albertel 8326: sub valid_file {
8327: my ($requested_file)=@_;
8328: foreach my $filename (sort(&scantron_filenames())) {
8329: if ($requested_file eq $filename) { return 1; }
8330: }
8331: return 0;
8332: }
8333:
8334: sub scantron_download_scantron_data {
8335: my ($r)=@_;
1.324 albertel 8336: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.257 albertel 8337: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
8338: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
8339: my $file=$env{'form.scantron_selectfile'};
1.202 albertel 8340: if (! &valid_file($file)) {
1.492 albertel 8341: $r->print('
1.202 albertel 8342: <p>
1.492 albertel 8343: '.&mt('The requested file name was invalid.').'
1.202 albertel 8344: </p>
1.492 albertel 8345: ');
1.324 albertel 8346: $r->print(&show_grading_menu_form(&get_symb($r,1)));
1.202 albertel 8347: return;
8348: }
8349: my $orig='/uploaded/'.$cdom.'/'.$cname.'/scantron_orig_'.$file;
8350: my $corrected='/uploaded/'.$cdom.'/'.$cname.'/scantron_corrected_'.$file;
8351: my $skipped='/uploaded/'.$cdom.'/'.$cname.'/scantron_skipped_'.$file;
8352: &Apache::lonnet::allowuploaded('/adm/grades',$orig);
8353: &Apache::lonnet::allowuploaded('/adm/grades',$corrected);
8354: &Apache::lonnet::allowuploaded('/adm/grades',$skipped);
1.492 albertel 8355: $r->print('
1.202 albertel 8356: <p>
1.492 albertel 8357: '.&mt('[_1]Original[_2] file as uploaded by the scantron office.',
8358: '<a href="'.$orig.'">','</a>').'
1.202 albertel 8359: </p>
8360: <p>
1.492 albertel 8361: '.&mt('[_1]Corrections[_2], a file of corrected records that were used in grading.',
8362: '<a href="'.$corrected.'">','</a>').'
1.202 albertel 8363: </p>
8364: <p>
1.492 albertel 8365: '.&mt('[_1]Skipped[_2], a file of records that were skipped.',
8366: '<a href="'.$skipped.'">','</a>').'
1.202 albertel 8367: </p>
1.492 albertel 8368: ');
1.324 albertel 8369: $r->print(&show_grading_menu_form(&get_symb($r,1)));
1.202 albertel 8370: return '';
8371: }
1.157 albertel 8372:
1.523 raeburn 8373: sub checkscantron_results {
8374: my ($r) = @_;
8375: my ($symb)=&get_symb($r);
8376: if (!$symb) {return '';}
8377: my $grading_menu_button=&show_grading_menu_form($symb);
8378: my $cid = $env{'request.course.id'};
1.542 raeburn 8379: my %lettdig = &letter_to_digits();
1.523 raeburn 8380: my $numletts = scalar(keys(%lettdig));
8381: my $cnum = $env{'course.'.$cid.'.num'};
8382: my $cdom = $env{'course.'.$cid.'.domain'};
8383: my (undef, undef, $sequence) = &Apache::lonnet::decode_symb($env{'form.selectpage'});
8384: my %record;
8385: my %scantron_config =
8386: &Apache::grades::get_scantron_config($env{'form.scantron_format'});
8387: my ($scanlines,$scan_data)=&Apache::grades::scantron_getfile();
8388: my $classlist=&Apache::loncoursedata::get_classlist();
8389: my %idmap=&Apache::grades::username_to_idmap($classlist);
8390: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 8391: unless (ref($navmap)) {
8392: $r->print(&navmap_errormsg());
8393: return '';
8394: }
1.523 raeburn 8395: my $map=$navmap->getResourceByUrl($sequence);
1.557 raeburn 8396: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
8397: my (%grader_partids_by_symb,%grader_randomlists_by_symb);
8398: &graders_resources_pass(\@resources,\%grader_partids_by_symb, \%grader_randomlists_by_symb);
8399:
1.554 raeburn 8400: my ($uname,$udom);
1.523 raeburn 8401: my (%scandata,%lastname,%bylast);
8402: $r->print('
8403: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="checkscantron">'."\n");
8404:
8405: my @delayqueue;
8406: my %completedstudents;
8407:
8408: my $count=&Apache::grades::get_todo_count($scanlines,$scan_data);
1.581 www 8409: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Bubblesheet/Submissions Comparison Status',
8410: 'Progress of Bubblesheet Data/Submission Records Comparison',$count,
1.523 raeburn 8411: 'inline',undef,'checkscantron');
1.546 raeburn 8412: my ($username,$domain,$started);
1.582 raeburn 8413: my $nav_error;
1.596.2.12.2. (raeburn 8414:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # Need the bubble lines array to parse.
1.582 raeburn 8415: if ($nav_error) {
8416: $r->print(&navmap_errormsg());
8417: return '';
8418: }
1.523 raeburn 8419:
8420: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
8421: 'Processing first student');
8422: my $start=&Time::HiRes::time();
8423: my $i=-1;
8424:
8425: while ($i<$scanlines->{'count'}) {
8426: ($username,$domain,$uname)=('','','');
8427: $i++;
8428: my $line=&Apache::grades::scantron_get_line($scanlines,$scan_data,$i);
8429: if ($line=~/^[\s\cz]*$/) { next; }
8430: if ($started) {
8431: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
8432: 'last student');
8433: }
8434: $started=1;
8435: my $scan_record=
8436: &Apache::grades::scantron_parse_scanline($line,$i,\%scantron_config,
8437: $scan_data);
8438: unless ($uname=&Apache::grades::scantron_find_student($scan_record,$scan_data,
8439: \%idmap,$i)) {
8440: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
8441: 'Unable to find a student that matches',1);
8442: next;
8443: }
8444: if (exists $completedstudents{$uname}) {
8445: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
8446: 'Student '.$uname.' has multiple sheets',2);
8447: next;
8448: }
8449: my $pid = $scan_record->{'scantron.ID'};
8450: $lastname{$pid} = $scan_record->{'scantron.LastName'};
8451: push(@{$bylast{$lastname{$pid}}},$pid);
8452: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
8453: $scandata{$pid} = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
8454: chomp($scandata{$pid});
8455: $scandata{$pid} =~ s/\r$//;
8456: ($username,$domain)=split(/:/,$uname);
8457: my $counter = -1;
8458: foreach my $resource (@resources) {
1.557 raeburn 8459: my $parts;
1.554 raeburn 8460: my $ressymb = $resource->symb();
1.557 raeburn 8461: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
8462: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
8463: (my $analysis,$parts) =
1.596.2.12.2. (raeburn 8464:): &scantron_partids_tograde($resource,$env{'request.course.id'},
8465:): $username,$domain,undef,
8466:): $bubbles_per_row);
1.557 raeburn 8467: } else {
8468: $parts = $grader_partids_by_symb{$ressymb};
8469: }
1.542 raeburn 8470: ($counter,my $recording) =
8471: &verify_scantron_grading($resource,$domain,$username,$cid,$counter,
1.554 raeburn 8472: $scandata{$pid},$parts,
1.542 raeburn 8473: \%scantron_config,\%lettdig,$numletts);
8474: $record{$pid} .= $recording;
1.523 raeburn 8475: }
8476: }
8477: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
8478: $r->print('<br />');
8479: my ($okstudents,$badstudents,$numstudents,$passed,$failed);
8480: $passed = 0;
8481: $failed = 0;
8482: $numstudents = 0;
8483: foreach my $last (sort(keys(%bylast))) {
8484: if (ref($bylast{$last}) eq 'ARRAY') {
8485: foreach my $pid (sort(@{$bylast{$last}})) {
8486: my $showscandata = $scandata{$pid};
8487: my $showrecord = $record{$pid};
8488: $showscandata =~ s/\s/ /g;
8489: $showrecord =~ s/\s/ /g;
8490: if ($scandata{$pid} eq $record{$pid}) {
8491: my $css_class = ($passed % 2)?'LC_odd_row':'LC_even_row';
8492: $okstudents .= '<tr class="'.$css_class.'">'.
1.581 www 8493: '<td>'.&mt('Bubblesheet').'</td><td>'.$showscandata.'</td><td rowspan="2">'.$last.'</td><td rowspan="2">'.$pid.'</td>'."\n".
1.523 raeburn 8494: '</tr>'."\n".
8495: '<tr class="'.$css_class.'">'."\n".
8496: '<td>Submissions</td><td>'.$showrecord.'</td></tr>'."\n";
8497: $passed ++;
8498: } else {
8499: my $css_class = ($failed % 2)?'LC_odd_row':'LC_even_row';
1.581 www 8500: $badstudents .= '<tr class="'.$css_class.'"><td>'.&mt('Bubblesheet').'</td><td><span class="LC_nobreak">'.$scandata{$pid}.'</span></td><td rowspan="2">'.$last.'</td><td rowspan="2">'.$pid.'</td>'."\n".
1.523 raeburn 8501: '</tr>'."\n".
8502: '<tr class="'.$css_class.'">'."\n".
8503: '<td>Submissions</td><td><span class="LC_nobreak">'.$record{$pid}.'</span></td>'."\n".
8504: '</tr>'."\n";
8505: $failed ++;
8506: }
8507: $numstudents ++;
8508: }
8509: }
8510: }
1.596.2.4 raeburn 8511: $r->print('<p>'.
1.596.2.8 raeburn 8512: &mt('Comparison of bubblesheet data (including corrections) with corresponding submission records (most recent submission) for [_1][quant,_2,student][_3] ([quant,_4,bubblesheet line] per student).',
1.596.2.4 raeburn 8513: '<b>',
8514: $numstudents,
8515: '</b>',
8516: $env{'form.scantron_maxbubble'}).
8517: '</p>'
8518: );
1.523 raeburn 8519: $r->print('<p>'.&mt('Exact matches for <b>[quant,_1,student]</b>.',$passed).'<br />'.&mt('Discrepancies detected for <b>[quant,_1,student]</b>.',$failed).'</p>');
8520: if ($passed) {
1.572 www 8521: $r->print(&mt('Students with exact correspondence between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 8522: $r->print(&Apache::loncommon::start_data_table()."\n".
8523: &Apache::loncommon::start_data_table_header_row()."\n".
8524: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
8525: &Apache::loncommon::end_data_table_header_row()."\n".
8526: $okstudents."\n".
8527: &Apache::loncommon::end_data_table().'<br />');
8528: }
8529: if ($failed) {
1.572 www 8530: $r->print(&mt('Students with differences between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 8531: $r->print(&Apache::loncommon::start_data_table()."\n".
8532: &Apache::loncommon::start_data_table_header_row()."\n".
8533: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
8534: &Apache::loncommon::end_data_table_header_row()."\n".
8535: $badstudents."\n".
8536: &Apache::loncommon::end_data_table()).'<br />'.
1.572 www 8537: &mt('Differences can occur if submissions were modified using manual grading after a bubblesheet grading pass.').'<br />'.&mt('If unexpected discrepancies were detected, it is recommended that you inspect the original bubblesheets.');
1.523 raeburn 8538: }
8539: $r->print('</form><br />'.$grading_menu_button);
8540: return;
8541: }
8542:
1.542 raeburn 8543: sub verify_scantron_grading {
1.554 raeburn 8544: my ($resource,$domain,$username,$cid,$counter,$scandata,$partids,
1.542 raeburn 8545: $scantron_config,$lettdig,$numletts) = @_;
8546: my ($record,%expected,%startpos);
8547: return ($counter,$record) if (!ref($resource));
8548: return ($counter,$record) if (!$resource->is_problem());
8549: my $symb = $resource->symb();
1.554 raeburn 8550: return ($counter,$record) if (ref($partids) ne 'ARRAY');
8551: foreach my $part_id (@{$partids}) {
1.542 raeburn 8552: $counter ++;
8553: $expected{$part_id} = 0;
8554: if ($env{"form.scantron.sub_bubblelines.$counter"}) {
8555: my @sub_lines = split(/,/,$env{"form.scantron.sub_bubblelines.$counter"});
8556: foreach my $item (@sub_lines) {
8557: $expected{$part_id} += $item;
8558: }
8559: } else {
8560: $expected{$part_id} = $env{"form.scantron.bubblelines.$counter"};
8561: }
8562: $startpos{$part_id} = $env{"form.scantron.first_bubble_line.$counter"};
8563: }
8564: if ($symb) {
8565: my %recorded;
8566: my (%returnhash) = &Apache::lonnet::restore($symb,$cid,$domain,$username);
8567: if ($returnhash{'version'}) {
8568: my %lasthash=();
8569: my $version;
8570: for ($version=1;$version<=$returnhash{'version'};$version++) {
8571: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
8572: $lasthash{$key}=$returnhash{$version.':'.$key};
8573: }
8574: }
8575: foreach my $key (keys(%lasthash)) {
8576: if ($key =~ /\.scantron$/) {
8577: my $value = &unescape($lasthash{$key});
8578: my ($part_id) = ($key =~ /^resource\.(.+)\.scantron$/);
8579: if ($value eq '') {
8580: for (my $i=0; $i<$expected{$part_id}; $i++) {
8581: for (my $j=0; $j<$scantron_config->{'length'}; $j++) {
8582: $recorded{$part_id} .= $scantron_config->{'Qoff'};
8583: }
8584: }
8585: } else {
8586: my @tocheck;
8587: my @items = split(//,$value);
8588: if (($scantron_config->{'Qon'} eq 'letter') ||
8589: ($scantron_config->{'Qon'} eq 'number')) {
8590: if (@items < $expected{$part_id}) {
8591: my $fragment = substr($scandata,$startpos{$part_id},$expected{$part_id});
8592: my @singles = split(//,$fragment);
8593: foreach my $pos (@singles) {
8594: if ($pos eq ' ') {
8595: push(@tocheck,$pos);
8596: } else {
8597: my $next = shift(@items);
8598: push(@tocheck,$next);
8599: }
8600: }
8601: } else {
8602: @tocheck = @items;
8603: }
8604: foreach my $letter (@tocheck) {
8605: if ($scantron_config->{'Qon'} eq 'letter') {
8606: if ($letter !~ /^[A-J]$/) {
8607: $letter = $scantron_config->{'Qoff'};
8608: }
8609: $recorded{$part_id} .= $letter;
8610: } elsif ($scantron_config->{'Qon'} eq 'number') {
8611: my $digit;
8612: if ($letter !~ /^[A-J]$/) {
8613: $digit = $scantron_config->{'Qoff'};
8614: } else {
8615: $digit = $lettdig->{$letter};
8616: }
8617: $recorded{$part_id} .= $digit;
8618: }
8619: }
8620: } else {
8621: @tocheck = @items;
8622: for (my $i=0; $i<$expected{$part_id}; $i++) {
8623: my $curr_sub = shift(@tocheck);
8624: my $digit;
8625: if ($curr_sub =~ /^[A-J]$/) {
8626: $digit = $lettdig->{$curr_sub}-1;
8627: }
8628: if ($curr_sub eq 'J') {
8629: $digit += scalar($numletts);
8630: }
8631: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
8632: if ($j == $digit) {
8633: $recorded{$part_id} .= $scantron_config->{'Qon'};
8634: } else {
8635: $recorded{$part_id} .= $scantron_config->{'Qoff'};
8636: }
8637: }
8638: }
8639: }
8640: }
8641: }
8642: }
8643: }
1.554 raeburn 8644: foreach my $part_id (@{$partids}) {
1.542 raeburn 8645: if ($recorded{$part_id} eq '') {
8646: for (my $i=0; $i<$expected{$part_id}; $i++) {
8647: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
8648: $recorded{$part_id} .= $scantron_config->{'Qoff'};
8649: }
8650: }
8651: }
8652: $record .= $recorded{$part_id};
8653: }
8654: }
8655: return ($counter,$record);
8656: }
8657:
8658: sub letter_to_digits {
8659: my %lettdig = (
8660: A => 1,
8661: B => 2,
8662: C => 3,
8663: D => 4,
8664: E => 5,
8665: F => 6,
8666: G => 7,
8667: H => 8,
8668: I => 9,
8669: J => 0,
8670: );
8671: return %lettdig;
8672: }
8673:
1.423 albertel 8674:
1.75 albertel 8675: #-------- end of section for handling grading scantron forms -------
8676: #
8677: #-------------------------------------------------------------------
8678:
1.72 ng 8679: #-------------------------- Menu interface -------------------------
8680: #
8681: #--- Show a Grading Menu button - Calls the next routine ---
8682: sub show_grading_menu_form {
1.324 albertel 8683: my ($symb)=@_;
1.125 ng 8684: my $result.='<br /><form action="/adm/grades" method="post">'."\n".
1.418 albertel 8685: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 8686: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.72 ng 8687: '<input type="hidden" name="command" value="gradingmenu" />'."\n".
1.478 albertel 8688: '<input type="submit" name="submit" value="'.&mt('Grading Menu').'" />'."\n".
1.72 ng 8689: '</form>'."\n";
8690: return $result;
8691: }
8692:
1.77 ng 8693: # -- Retrieve choices for grading form
8694: sub savedState {
8695: my %savedState = ();
1.257 albertel 8696: if ($env{'form.saveState'}) {
8697: foreach (split(/:/,$env{'form.saveState'})) {
1.77 ng 8698: my ($key,$value) = split(/=/,$_,2);
8699: $savedState{$key} = $value;
8700: }
8701: }
8702: return \%savedState;
8703: }
1.76 ng 8704:
1.443 banghart 8705: sub grading_menu {
8706: my ($request) = @_;
8707: my ($symb)=&get_symb($request);
8708: if (!$symb) {return '';}
8709: my $probTitle = &Apache::lonnet::gettitle($symb);
8710: my ($table,undef,$hdgrade) = &showResourceInfo($symb,$probTitle);
8711:
1.444 banghart 8712: $request->print($table);
1.443 banghart 8713: my %fields = ('symb'=>&Apache::lonenc::check_encrypt($symb),
8714: 'handgrade'=>$hdgrade,
8715: 'probTitle'=>$probTitle,
8716: 'command'=>'submit_options',
8717: 'saveState'=>"",
8718: 'gradingMenu'=>1,
8719: 'showgrading'=>"yes");
1.538 schulted 8720:
8721: my $url1 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8722:
1.443 banghart 8723: $fields{'command'} = 'csvform';
1.538 schulted 8724: my $url2 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8725:
1.443 banghart 8726: $fields{'command'} = 'processclicker';
1.538 schulted 8727: my $url3 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8728:
1.443 banghart 8729: $fields{'command'} = 'scantron_selectphase';
1.538 schulted 8730: my $url4 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8731:
8732: my @menu = ({ categorytitle=>'Course Grading',
8733: items =>[
8734: { linktext => 'Manual Grading/View Submissions',
8735: url => $url1,
8736: permission => 'F',
8737: icon => 'edit-find-replace.png',
8738: linktitle => 'Start the process of hand grading submissions.'
8739: },
8740: { linktext => 'Upload Scores',
8741: url => $url2,
8742: permission => 'F',
8743: icon => 'uploadscores.png',
8744: linktitle => 'Specify a file containing the class scores for current resource.'
8745: },
8746: { linktext => 'Process Clicker',
8747: url => $url3,
8748: permission => 'F',
8749: icon => 'addClickerInfoFile.png',
8750: linktitle => 'Specify a file containing the clicker information for this resource.'
8751: },
1.587 raeburn 8752: { linktext => 'Grade/Manage/Review Bubblesheets',
1.538 schulted 8753: url => $url4,
8754: permission => 'F',
8755: icon => 'stat.png',
1.596.2.4 raeburn 8756: linktitle => 'Grade bubblesheet exams, upload/download bubblesheet data files, and review previously graded bubblesheet exams.'
1.538 schulted 8757: }
8758: ]
8759: });
8760:
8761: #$fields{'command'} = 'verify';
8762: #$url = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
1.443 banghart 8763: #
8764: # Create the menu
8765: my $Str;
1.444 banghart 8766: # $Str .= '<h2>'.&mt('Please select a grading task').'</h2>';
1.445 banghart 8767: $Str .= '<form method="post" action="" name="gradingMenu">';
8768: $Str .= '<input type="hidden" name="command" value="" />'.
8769: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
8770: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
1.476 albertel 8771: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.445 banghart 8772: '<input type="hidden" name="saveState" value="" />'."\n".
8773: '<input type="hidden" name="gradingMenu" value="1" />'."\n".
8774: '<input type="hidden" name="showgrading" value="yes" />'."\n";
8775:
1.538 schulted 8776: $Str .= Apache::lonhtmlcommon::generate_menu(@menu);
8777: #$menudata->{'jscript'}
1.584 bisitz 8778: $Str .='<hr /><input type="button" value="'.&mt('Verify Receipt No.').'" '.
1.589 bisitz 8779: ' onclick="javascript:checkChoice(document.forms.gradingMenu,\'5\',\'verify\')" '.
1.538 schulted 8780: ' /> '.
8781: &Apache::lonnet::recprefix($env{'request.course.id'}).
1.589 bisitz 8782: '-<input type="text" name="receipt" size="4" onchange="javascript:checkReceiptNo(this.form,\'OK\')" />';
1.538 schulted 8783:
1.444 banghart 8784: $Str .="</form>\n";
1.539 riegler 8785: my $receiptalert = &mt("Please enter a receipt number given by a student in the receipt box.");
1.443 banghart 8786: $request->print(<<GRADINGMENUJS);
8787: <script type="text/javascript" language="javascript">
8788: function checkChoice(formname,val,cmdx) {
8789: if (val <= 2) {
8790: var cmd = radioSelection(formname.radioChoice);
8791: var cmdsave = cmd;
8792: } else {
8793: cmd = cmdx;
8794: cmdsave = 'submission';
8795: }
8796: formname.command.value = cmd;
8797: if (val < 5) formname.submit();
8798: if (val == 5) {
1.458 banghart 8799: if (!checkReceiptNo(formname,'notOK')) {
8800: return false;
8801: } else {
8802: formname.submit();
8803: }
1.445 banghart 8804: }
8805: }
1.443 banghart 8806:
8807: function checkReceiptNo(formname,nospace) {
8808: var receiptNo = formname.receipt.value;
8809: var checkOpt = false;
8810: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
8811: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
8812: if (checkOpt) {
1.539 riegler 8813: alert("$receiptalert");
1.443 banghart 8814: formname.receipt.value = "";
8815: formname.receipt.focus();
8816: return false;
8817: }
8818: return true;
8819: }
8820: </script>
8821: GRADINGMENUJS
8822: &commonJSfunctions($request);
8823: return $Str;
8824: }
8825:
8826:
8827: #--- Displays the submissions first page -------
8828: sub submit_options {
1.72 ng 8829: my ($request) = @_;
1.324 albertel 8830: my ($symb)=&get_symb($request);
1.72 ng 8831: if (!$symb) {return '';}
1.76 ng 8832: my $probTitle = &Apache::lonnet::gettitle($symb);
1.72 ng 8833:
1.539 riegler 8834: my $receiptalert = &mt("Please enter a receipt number given by a student in the receipt box.");
1.72 ng 8835: $request->print(<<GRADINGMENUJS);
8836: <script type="text/javascript" language="javascript">
1.116 ng 8837: function checkChoice(formname,val,cmdx) {
8838: if (val <= 2) {
8839: var cmd = radioSelection(formname.radioChoice);
1.118 ng 8840: var cmdsave = cmd;
1.116 ng 8841: } else {
8842: cmd = cmdx;
1.118 ng 8843: cmdsave = 'submission';
1.116 ng 8844: }
8845: formname.command.value = cmd;
1.118 ng 8846: formname.saveState.value = "saveCmd="+cmdsave+":saveSec="+pullDownSelection(formname.section)+
1.145 albertel 8847: ":saveSub="+pullDownSelection(formname.submitonly)+":saveStatus="+pullDownSelection(formname.Status);
1.116 ng 8848: if (val < 5) formname.submit();
8849: if (val == 5) {
1.72 ng 8850: if (!checkReceiptNo(formname,'notOK')) { return false;}
8851: formname.submit();
8852: }
1.238 albertel 8853: if (val < 7) formname.submit();
1.72 ng 8854: }
8855:
8856: function checkReceiptNo(formname,nospace) {
8857: var receiptNo = formname.receipt.value;
8858: var checkOpt = false;
8859: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
8860: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
8861: if (checkOpt) {
1.539 riegler 8862: alert("$receiptalert");
1.72 ng 8863: formname.receipt.value = "";
8864: formname.receipt.focus();
8865: return false;
8866: }
8867: return true;
8868: }
8869: </script>
8870: GRADINGMENUJS
1.118 ng 8871: &commonJSfunctions($request);
1.324 albertel 8872: my ($table,undef,$hdgrade) = &showResourceInfo($symb,$probTitle);
1.473 albertel 8873: my $result;
1.76 ng 8874: my (undef,$sections) = &getclasslist('all','0');
1.77 ng 8875: my $savedState = &savedState();
1.118 ng 8876: my $saveCmd = ($$savedState{'saveCmd'} eq '' ? 'submission' : $$savedState{'saveCmd'});
1.77 ng 8877: my $saveSec = ($$savedState{'saveSec'} eq '' ? 'all' : $$savedState{'saveSec'});
1.118 ng 8878: my $saveSub = ($$savedState{'saveSub'} eq '' ? 'all' : $$savedState{'saveSub'});
1.77 ng 8879: my $saveStatus = ($$savedState{'saveStatus'} eq '' ? 'Active' : $$savedState{'saveStatus'});
1.72 ng 8880:
1.533 bisitz 8881: # Preselect sections
8882: my $selsec="";
8883: if (ref($sections)) {
8884: foreach my $section (sort(@$sections)) {
8885: $selsec.='<option value="'.$section.'" '.
8886: ($saveSec eq $section ? 'selected="selected"':'').'>'.$section.'</option>'."\n";
8887: }
8888: }
8889:
1.72 ng 8890: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.418 albertel 8891: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.72 ng 8892: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
8893: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.116 ng 8894: '<input type="hidden" name="command" value="" />'."\n".
1.77 ng 8895: '<input type="hidden" name="saveState" value="" />'."\n".
1.124 ng 8896: '<input type="hidden" name="gradingMenu" value="1" />'."\n".
1.72 ng 8897: '<input type="hidden" name="showgrading" value="yes" />'."\n";
8898:
1.472 albertel 8899: $result.='
1.533 bisitz 8900: <h2>
8901: '.&mt('Grade Current Resource').'
8902: </h2>
8903: <div>
8904: '.$table.'
8905: </div>
8906:
1.537 harmsja 8907: <div class="LC_columnSection">
8908:
1.533 bisitz 8909: <fieldset>
8910: <legend>
8911: '.&mt('Sections').'
8912: </legend>
8913: <select name="section" multiple="multiple" size="5">'."\n";
8914: $result.= $selsec;
1.401 albertel 8915: $result.= '<option value="all" '.($saveSec eq 'all' ? 'selected="selected"' : ''). '>all</option></select> ';
1.472 albertel 8916: $result.='
1.533 bisitz 8917: </fieldset>
1.537 harmsja 8918:
1.533 bisitz 8919: <fieldset>
8920: <legend>
8921: '.&mt('Groups').'
8922: </legend>
8923: '.&Apache::lonstatistics::GroupSelect('group','multiple',5).'
8924: </fieldset>
1.537 harmsja 8925:
1.533 bisitz 8926: <fieldset>
8927: <legend>
8928: '.&mt('Access Status').'
8929: </legend>
8930: '.&Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,5,undef,'mult').'
8931: </fieldset>
1.537 harmsja 8932:
1.533 bisitz 8933: <fieldset>
8934: <legend>
8935: '.&mt('Submission Status').'
8936: </legend>
8937: <select name="submitonly" size="5">
1.473 albertel 8938: <option value="yes" '. ($saveSub eq 'yes' ? 'selected="selected"' : '').'>'.&mt('with submissions').'</option>
8939: <option value="queued" '. ($saveSub eq 'queued' ? 'selected="selected"' : '').'>'.&mt('in grading queue').'</option>
8940: <option value="graded" '. ($saveSub eq 'graded' ? 'selected="selected"' : '').'>'.&mt('with ungraded submissions').'</option>
8941: <option value="incorrect" '.($saveSub eq 'incorrect' ? 'selected="selected"' : '').'>'.&mt('with incorrect submissions').'</option>
8942: <option value="all" '. ($saveSub eq 'all' ? 'selected="selected"' : '').'>'.&mt('with any status').'</option>
1.533 bisitz 8943: </select>
8944: </fieldset>
1.537 harmsja 8945:
1.533 bisitz 8946: </div>
8947:
8948: <br />
8949: <div>
8950: <div>
1.473 albertel 8951: <label>
8952: <input type="radio" name="radioChoice" value="submission" '.
8953: ($saveCmd eq 'submission' ? 'checked="checked"' : '').' /> '.
8954: &mt('Select individual students to grade and view submissions.').'
8955: </label>
8956: </div>
1.533 bisitz 8957: <div>
1.473 albertel 8958: <label>
8959: <input type="radio" name="radioChoice" value="viewgrades" '.
8960: ($saveCmd eq 'viewgrades' ? 'checked="checked"' : '').' /> '.
8961: &mt('Grade all selected students in a grading table.').'
8962: </label>
8963: </div>
1.533 bisitz 8964: <div>
1.589 bisitz 8965: <input type="button" onclick="javascript:checkChoice(this.form,\'2\');" value="'.&mt('Next').' →" />
1.473 albertel 8966: </div>
1.472 albertel 8967: </div>
1.533 bisitz 8968:
8969:
1.473 albertel 8970: <h2>
8971: '.&mt('Grade Complete Folder for One Student').'
8972: </h2>
1.533 bisitz 8973: <div>
8974: <div>
1.473 albertel 8975: <label>
8976: <input type="radio" name="radioChoice" value="pickStudentPage" '.
8977: ($saveCmd eq 'pickStudentPage' ? 'checked="checked"' : '').' /> '.
8978: &mt('The <b>complete</b> page/sequence/folder: For one student').'
8979: </label>
8980: </div>
1.533 bisitz 8981: <div>
1.589 bisitz 8982: <input type="button" onclick="javascript:checkChoice(this.form,\'2\');" value="'.&mt('Next').' →" />
1.473 albertel 8983: </div>
1.472 albertel 8984: </div>
8985: </form>';
1.499 albertel 8986: $result .= &show_grading_menu_form($symb);
1.44 ng 8987: return $result;
1.2 albertel 8988: }
8989:
1.285 albertel 8990: sub reset_perm {
8991: undef(%perm);
8992: }
8993:
8994: sub init_perm {
8995: &reset_perm();
1.300 albertel 8996: foreach my $test_perm ('vgr','mgr','opa') {
8997:
8998: my $scope = $env{'request.course.id'};
8999: if (!($perm{$test_perm}=&Apache::lonnet::allowed($test_perm,$scope))) {
9000:
9001: $scope .= '/'.$env{'request.course.sec'};
9002: if ( $perm{$test_perm}=
9003: &Apache::lonnet::allowed($test_perm,$scope)) {
9004: $perm{$test_perm.'_section'}=$env{'request.course.sec'};
9005: } else {
9006: delete($perm{$test_perm});
9007: }
1.285 albertel 9008: }
9009: }
9010: }
9011:
1.400 www 9012: sub gather_clicker_ids {
1.408 albertel 9013: my %clicker_ids;
1.400 www 9014:
9015: my $classlist = &Apache::loncoursedata::get_classlist();
9016:
9017: # Set up a couple variables.
1.407 albertel 9018: my $username_idx = &Apache::loncoursedata::CL_SNAME();
9019: my $domain_idx = &Apache::loncoursedata::CL_SDOM();
1.438 www 9020: my $status_idx = &Apache::loncoursedata::CL_STATUS();
1.400 www 9021:
1.407 albertel 9022: foreach my $student (keys(%$classlist)) {
1.438 www 9023: if ($classlist->{$student}->[$status_idx] ne 'Active') { next; }
1.407 albertel 9024: my $username = $classlist->{$student}->[$username_idx];
9025: my $domain = $classlist->{$student}->[$domain_idx];
1.400 www 9026: my $clickers =
1.408 albertel 9027: (&Apache::lonnet::userenvironment($domain,$username,'clickers'))[1];
1.400 www 9028: foreach my $id (split(/\,/,$clickers)) {
1.414 www 9029: $id=~s/^[\#0]+//;
1.421 www 9030: $id=~s/[\-\:]//g;
1.407 albertel 9031: if (exists($clicker_ids{$id})) {
1.408 albertel 9032: $clicker_ids{$id}.=','.$username.':'.$domain;
1.400 www 9033: } else {
1.408 albertel 9034: $clicker_ids{$id}=$username.':'.$domain;
1.400 www 9035: }
9036: }
9037: }
1.407 albertel 9038: return %clicker_ids;
1.400 www 9039: }
9040:
1.402 www 9041: sub gather_adv_clicker_ids {
1.408 albertel 9042: my %clicker_ids;
1.402 www 9043: my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'};
9044: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
9045: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
1.409 albertel 9046: foreach my $element (sort(keys(%coursepersonnel))) {
1.402 www 9047: foreach my $person (split(/\,/,$coursepersonnel{$element})) {
9048: my ($puname,$pudom)=split(/\:/,$person);
9049: my $clickers =
1.408 albertel 9050: (&Apache::lonnet::userenvironment($pudom,$puname,'clickers'))[1];
1.405 www 9051: foreach my $id (split(/\,/,$clickers)) {
1.414 www 9052: $id=~s/^[\#0]+//;
1.421 www 9053: $id=~s/[\-\:]//g;
1.408 albertel 9054: if (exists($clicker_ids{$id})) {
9055: $clicker_ids{$id}.=','.$puname.':'.$pudom;
9056: } else {
9057: $clicker_ids{$id}=$puname.':'.$pudom;
9058: }
1.405 www 9059: }
1.402 www 9060: }
9061: }
1.407 albertel 9062: return %clicker_ids;
1.402 www 9063: }
9064:
1.413 www 9065: sub clicker_grading_parameters {
9066: return ('gradingmechanism' => 'scalar',
9067: 'upfiletype' => 'scalar',
9068: 'specificid' => 'scalar',
9069: 'pcorrect' => 'scalar',
9070: 'pincorrect' => 'scalar');
9071: }
9072:
1.400 www 9073: sub process_clicker {
9074: my ($r)=@_;
9075: my ($symb)=&get_symb($r);
9076: if (!$symb) {return '';}
9077: my $result=&checkforfile_js();
9078: $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
9079: my ($table) = &showResourceInfo($symb,$env{'form.probTitle'});
9080: $result.=$table;
9081: $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
9082: $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
1.538 schulted 9083: $result.=' <b>'.&mt('Specify a file containing the clicker information for this resource.').
9084: '</b></td></tr>'."\n";
1.596.2.4 raeburn 9085: $result.='<tr bgcolor="#ffffe6"><td>'."\n";
1.413 www 9086: # Attempt to restore parameters from last session, set defaults if not present
9087: my %Saveable_Parameters=&clicker_grading_parameters();
9088: &Apache::loncommon::restore_course_settings('grades_clicker',
9089: \%Saveable_Parameters);
9090: if (!$env{'form.pcorrect'}) { $env{'form.pcorrect'}=100; }
9091: if (!$env{'form.pincorrect'}) { $env{'form.pincorrect'}=100; }
9092: if (!$env{'form.gradingmechanism'}) { $env{'form.gradingmechanism'}='attendance'; }
9093: if (!$env{'form.upfiletype'}) { $env{'form.upfiletype'}='iclicker'; }
9094:
9095: my %checked;
1.521 www 9096: foreach my $gradingmechanism ('attendance','personnel','specific','given') {
1.413 www 9097: if ($env{'form.gradingmechanism'} eq $gradingmechanism) {
1.569 bisitz 9098: $checked{$gradingmechanism}=' checked="checked"';
1.413 www 9099: }
9100: }
9101:
1.400 www 9102: my $upload=&mt("Upload File");
9103: my $type=&mt("Type");
1.402 www 9104: my $attendance=&mt("Award points just for participation");
9105: my $personnel=&mt("Correctness determined from response by course personnel");
1.414 www 9106: my $specific=&mt("Correctness determined from response with clicker ID(s)");
1.521 www 9107: my $given=&mt("Correctness determined from given list of answers").' '.
9108: '<font size="-2"><tt>('.&mt("Provide comma-separated list. Use '*' for any answer correct, '-' for skip").')</tt></font>';
1.402 www 9109: my $pcorrect=&mt("Percentage points for correct solution");
9110: my $pincorrect=&mt("Percentage points for incorrect solution");
1.413 www 9111: my $selectform=&Apache::loncommon::select_form($env{'form.upfiletype'},'upfiletype',
1.596.2.1 raeburn 9112: {'iclicker' => 'i>clicker',
9113: 'interwrite' => 'interwrite PRS'});
1.418 albertel 9114: $symb = &Apache::lonenc::check_encrypt($symb);
1.400 www 9115: $result.=<<ENDUPFORM;
1.402 www 9116: <script type="text/javascript">
9117: function sanitycheck() {
9118: // Accept only integer percentages
9119: document.forms.gradesupload.pcorrect.value=Math.round(document.forms.gradesupload.pcorrect.value);
9120: document.forms.gradesupload.pincorrect.value=Math.round(document.forms.gradesupload.pincorrect.value);
9121: // Find out grading choice
9122: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
9123: if (document.forms.gradesupload.gradingmechanism[i].checked) {
9124: gradingchoice=document.forms.gradesupload.gradingmechanism[i].value;
9125: }
9126: }
9127: // By default, new choice equals user selection
9128: newgradingchoice=gradingchoice;
9129: // Not good to give more points for false answers than correct ones
9130: if (Math.round(document.forms.gradesupload.pcorrect.value)<Math.round(document.forms.gradesupload.pincorrect.value)) {
9131: document.forms.gradesupload.pcorrect.value=document.forms.gradesupload.pincorrect.value;
9132: }
9133: // If new choice is attendance only, and old choice was correctness-based, restore defaults
9134: if ((gradingchoice=='attendance') && (document.forms.gradesupload.waschecked.value!='attendance')) {
9135: document.forms.gradesupload.pcorrect.value=100;
9136: document.forms.gradesupload.pincorrect.value=100;
9137: }
9138: // If the values are different, cannot be attendance only
9139: if ((Math.round(document.forms.gradesupload.pcorrect.value)!=Math.round(document.forms.gradesupload.pincorrect.value)) &&
9140: (gradingchoice=='attendance')) {
9141: newgradingchoice='personnel';
9142: }
9143: // Change grading choice to new one
9144: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
9145: if (document.forms.gradesupload.gradingmechanism[i].value==newgradingchoice) {
9146: document.forms.gradesupload.gradingmechanism[i].checked=true;
9147: } else {
9148: document.forms.gradesupload.gradingmechanism[i].checked=false;
9149: }
9150: }
9151: // Remember the old state
9152: document.forms.gradesupload.waschecked.value=newgradingchoice;
9153: }
9154: </script>
1.400 www 9155: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
9156: <input type="hidden" name="symb" value="$symb" />
9157: <input type="hidden" name="command" value="processclickerfile" />
9158: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
9159: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
9160: <input type="file" name="upfile" size="50" />
9161: <br /><label>$type: $selectform</label>
1.589 bisitz 9162: <br /><label><input type="radio" name="gradingmechanism" value="attendance"$checked{'attendance'} onclick="sanitycheck()" />$attendance </label>
9163: <br /><label><input type="radio" name="gradingmechanism" value="personnel"$checked{'personnel'} onclick="sanitycheck()" />$personnel</label>
9164: <br /><label><input type="radio" name="gradingmechanism" value="specific"$checked{'specific'} onclick="sanitycheck()" />$specific </label>
1.414 www 9165: <input type="text" name="specificid" value="$env{'form.specificid'}" size="20" />
1.589 bisitz 9166: <br /><label><input type="radio" name="gradingmechanism" value="given"$checked{'given'} onclick="sanitycheck()" />$given </label>
1.521 www 9167: <br />
9168: <input type="text" name="givenanswer" size="50" />
1.413 www 9169: <input type="hidden" name="waschecked" value="$env{'form.gradingmechanism'}" />
1.589 bisitz 9170: <br /><label>$pcorrect: <input type="text" name="pcorrect" size="4" value="$env{'form.pcorrect'}" onchange="sanitycheck()" /></label>
9171: <br /><label>$pincorrect: <input type="text" name="pincorrect" size="4" value="$env{'form.pincorrect'}" onchange="sanitycheck()" /></label>
9172: <br /><input type="button" onclick="javascript:checkUpload(this.form);" value="$upload" />
1.400 www 9173: </form>
9174: ENDUPFORM
9175: $result.='</td></tr></table>'."\n".
9176: '</td></tr></table><br /><br />'."\n";
9177: $result.=&show_grading_menu_form($symb);
9178: return $result;
9179: }
9180:
9181: sub process_clicker_file {
9182: my ($r)=@_;
9183: my ($symb)=&get_symb($r);
9184: if (!$symb) {return '';}
1.413 www 9185:
9186: my %Saveable_Parameters=&clicker_grading_parameters();
9187: &Apache::loncommon::store_course_settings('grades_clicker',
9188: \%Saveable_Parameters);
9189:
1.400 www 9190: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.404 www 9191: if (($env{'form.gradingmechanism'} eq 'specific') && ($env{'form.specificid'}!~/\w/)) {
1.408 albertel 9192: $result.='<span class="LC_error">'.&mt('You need to specify a clicker ID for the correct answer').'</span>';
9193: return $result.&show_grading_menu_form($symb);
1.404 www 9194: }
1.522 www 9195: if (($env{'form.gradingmechanism'} eq 'given') && ($env{'form.givenanswer'}!~/\S/)) {
1.521 www 9196: $result.='<span class="LC_error">'.&mt('You need to specify the correct answer').'</span>';
9197: return $result.&show_grading_menu_form($symb);
9198: }
1.522 www 9199: my $foundgiven=0;
1.521 www 9200: if ($env{'form.gradingmechanism'} eq 'given') {
9201: $env{'form.givenanswer'}=~s/^\s*//gs;
9202: $env{'form.givenanswer'}=~s/\s*$//gs;
1.596.2.4 raeburn 9203: $env{'form.givenanswer'}=~s/[^a-zA-Z0-9\.\*\-\+]+/\,/g;
1.521 www 9204: $env{'form.givenanswer'}=uc($env{'form.givenanswer'});
1.522 www 9205: my @answers=split(/\,/,$env{'form.givenanswer'});
9206: $foundgiven=$#answers+1;
1.521 www 9207: }
1.407 albertel 9208: my %clicker_ids=&gather_clicker_ids();
1.408 albertel 9209: my %correct_ids;
1.404 www 9210: if ($env{'form.gradingmechanism'} eq 'personnel') {
1.408 albertel 9211: %correct_ids=&gather_adv_clicker_ids();
1.404 www 9212: }
9213: if ($env{'form.gradingmechanism'} eq 'specific') {
1.414 www 9214: foreach my $correct_id (split(/[\s\,]/,$env{'form.specificid'})) {;
9215: $correct_id=~tr/a-z/A-Z/;
9216: $correct_id=~s/\s//gs;
9217: $correct_id=~s/^[\#0]+//;
1.421 www 9218: $correct_id=~s/[\-\:]//g;
1.414 www 9219: if ($correct_id) {
9220: $correct_ids{$correct_id}='specified';
9221: }
9222: }
1.400 www 9223: }
1.404 www 9224: if ($env{'form.gradingmechanism'} eq 'attendance') {
1.408 albertel 9225: $result.=&mt('Score based on attendance only');
1.521 www 9226: } elsif ($env{'form.gradingmechanism'} eq 'given') {
1.522 www 9227: $result.=&mt('Score based on [_1] ([_2] answers)','<tt>'.$env{'form.givenanswer'}.'</tt>',$foundgiven);
1.404 www 9228: } else {
1.408 albertel 9229: my $number=0;
1.411 www 9230: $result.='<p><b>'.&mt('Correctness determined by the following IDs').'</b>';
1.408 albertel 9231: foreach my $id (sort(keys(%correct_ids))) {
1.411 www 9232: $result.='<br /><tt>'.$id.'</tt> - ';
1.408 albertel 9233: if ($correct_ids{$id} eq 'specified') {
9234: $result.=&mt('specified');
9235: } else {
9236: my ($uname,$udom)=split(/\:/,$correct_ids{$id});
9237: $result.=&Apache::loncommon::plainname($uname,$udom);
9238: }
9239: $number++;
9240: }
1.411 www 9241: $result.="</p>\n";
1.408 albertel 9242: if ($number==0) {
9243: $result.='<span class="LC_error">'.&mt('No IDs found to determine correct answer').'</span>';
9244: return $result.&show_grading_menu_form($symb);
9245: }
1.404 www 9246: }
1.405 www 9247: if (length($env{'form.upfile'}) < 2) {
1.407 albertel 9248: $result.=&mt('[_1] Error: [_2] The file you attempted to upload, [_3] contained no information. Please check that you entered the correct filename.',
9249: '<span class="LC_error">',
9250: '</span>',
9251: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>');
1.405 www 9252: return $result.&show_grading_menu_form($symb);
9253: }
1.410 www 9254:
9255: # Were able to get all the info needed, now analyze the file
9256:
1.411 www 9257: $result.=&Apache::loncommon::studentbrowser_javascript();
1.418 albertel 9258: $symb = &Apache::lonenc::check_encrypt($symb);
1.410 www 9259: my $heading=&mt('Scanning clicker file');
9260: $result.=(<<ENDHEADER);
9261: <br /><table width="100%" border="0"><tr><td bgcolor="#777777">
9262: <table width="100%" border="0"><tr bgcolor="#e6ffff"><td>
1.596.2.4 raeburn 9263: <b>$heading</b></td></tr><tr bgcolor="#ffffe6"><td>
1.410 www 9264: <form method="post" action="/adm/grades" name="clickeranalysis">
9265: <input type="hidden" name="symb" value="$symb" />
9266: <input type="hidden" name="command" value="assignclickergrades" />
9267: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
9268: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
1.411 www 9269: <input type="hidden" name="gradingmechanism" value="$env{'form.gradingmechanism'}" />
9270: <input type="hidden" name="pcorrect" value="$env{'form.pcorrect'}" />
9271: <input type="hidden" name="pincorrect" value="$env{'form.pincorrect'}" />
1.410 www 9272: ENDHEADER
1.522 www 9273: if ($env{'form.gradingmechanism'} eq 'given') {
9274: $result.='<input type="hidden" name="correct:given" value="'.$env{'form.givenanswer'}.'" />';
9275: }
1.408 albertel 9276: my %responses;
9277: my @questiontitles;
1.405 www 9278: my $errormsg='';
9279: my $number=0;
9280: if ($env{'form.upfiletype'} eq 'iclicker') {
1.408 albertel 9281: ($errormsg,$number)=&iclicker_eval(\@questiontitles,\%responses);
1.406 www 9282: }
1.419 www 9283: if ($env{'form.upfiletype'} eq 'interwrite') {
9284: ($errormsg,$number)=&interwrite_eval(\@questiontitles,\%responses);
9285: }
1.411 www 9286: $result.='<br />'.&mt('Found [_1] question(s)',$number).'<br />'.
9287: '<input type="hidden" name="number" value="'.$number.'" />'.
9288: &mt('Awarding [_1] percent for correct and [_2] percent for incorrect responses',
9289: $env{'form.pcorrect'},$env{'form.pincorrect'}).
9290: '<br />';
1.522 www 9291: if (($env{'form.gradingmechanism'} eq 'given') && ($number!=$foundgiven)) {
9292: $result.='<span class="LC_error">'.&mt('Number of given answers does not agree with number of questions in file.').'</span>';
9293: return $result.&show_grading_menu_form($symb);
9294: }
1.414 www 9295: # Remember Question Titles
9296: # FIXME: Possibly need delimiter other than ":"
9297: for (my $i=0;$i<$number;$i++) {
9298: $result.='<input type="hidden" name="question:'.$i.'" value="'.
9299: &HTML::Entities::encode($questiontitles[$i],'"&<>').'" />';
9300: }
1.411 www 9301: my $correct_count=0;
9302: my $student_count=0;
9303: my $unknown_count=0;
1.414 www 9304: # Match answers with usernames
9305: # FIXME: Possibly need delimiter other than ":"
1.409 albertel 9306: foreach my $id (keys(%responses)) {
1.410 www 9307: if ($correct_ids{$id}) {
1.414 www 9308: $result.="\n".'<input type="hidden" name="correct:'.$correct_count.':'.$correct_ids{$id}.'" value="'.$responses{$id}.'" />';
1.411 www 9309: $correct_count++;
1.410 www 9310: } elsif ($clicker_ids{$id}) {
1.437 www 9311: if ($clicker_ids{$id}=~/\,/) {
9312: # More than one user with the same clicker!
9313: $result.="\n<hr />".&mt('Clicker registered more than once').": <tt>".$id."</tt><br />";
9314: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
9315: "<select name='multi".$id."'>";
9316: foreach my $reguser (sort(split(/\,/,$clicker_ids{$id}))) {
9317: $result.="<option value='".$reguser."'>".&Apache::loncommon::plainname(split(/\:/,$reguser)).' ('.$reguser.')</option>';
9318: }
9319: $result.='</select>';
9320: $unknown_count++;
9321: } else {
9322: # Good: found one and only one user with the right clicker
9323: $result.="\n".'<input type="hidden" name="student:'.$clicker_ids{$id}.'" value="'.$responses{$id}.'" />';
9324: $student_count++;
9325: }
1.410 www 9326: } else {
1.411 www 9327: $result.="\n<hr />".&mt('Unregistered Clicker')." <tt>".$id."</tt><br />";
9328: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
9329: "\n".&mt("Username").": <input type='text' name='uname".$id."' /> ".
9330: "\n".&mt("Domain").": ".
9331: &Apache::loncommon::select_dom_form($env{'course.'.$env{'request.course.id'}.'.domain'},'udom'.$id).' '.
1.596.2.4 raeburn 9332: &Apache::loncommon::selectstudent_link('clickeranalysis','uname'.$id,'udom'.$id,0,$id);
1.411 www 9333: $unknown_count++;
1.410 www 9334: }
1.405 www 9335: }
1.412 www 9336: $result.='<hr />'.
9337: &mt('Found [_1] registered and [_2] unregistered clickers.',$student_count,$unknown_count);
1.521 www 9338: if (($env{'form.gradingmechanism'} ne 'attendance') && ($env{'form.gradingmechanism'} ne 'given')) {
1.412 www 9339: if ($correct_count==0) {
9340: $errormsg.="Found no correct answers answers for grading!";
9341: } elsif ($correct_count>1) {
1.414 www 9342: $result.='<br /><span class="LC_warning">'.&mt("Found [_1] entries for grading!",$correct_count).'</span>';
1.412 www 9343: }
9344: }
1.428 www 9345: if ($number<1) {
9346: $errormsg.="Found no questions.";
9347: }
1.412 www 9348: if ($errormsg) {
9349: $result.='<br /><span class="LC_error">'.&mt($errormsg).'</span>';
9350: } else {
9351: $result.='<br /><input type="submit" name="finalize" value="'.&mt('Finalize Grading').'" />';
9352: }
9353: $result.='</form></td></tr></table>'."\n".
1.410 www 9354: '</td></tr></table><br /><br />'."\n";
1.404 www 9355: return $result.&show_grading_menu_form($symb);
1.400 www 9356: }
9357:
1.405 www 9358: sub iclicker_eval {
1.406 www 9359: my ($questiontitles,$responses)=@_;
1.405 www 9360: my $number=0;
9361: my $errormsg='';
9362: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
1.410 www 9363: my %components=&Apache::loncommon::record_sep($line);
9364: my @entries=map {$components{$_}} (sort(keys(%components)));
1.408 albertel 9365: if ($entries[0] eq 'Question') {
9366: for (my $i=3;$i<$#entries;$i+=6) {
9367: $$questiontitles[$number]=$entries[$i];
9368: $number++;
9369: }
9370: }
9371: if ($entries[0]=~/^\#/) {
9372: my $id=$entries[0];
9373: my @idresponses;
9374: $id=~s/^[\#0]+//;
9375: for (my $i=0;$i<$number;$i++) {
9376: my $idx=3+$i*6;
1.596.2.4 raeburn 9377: $entries[$idx]=~s/[^a-zA-Z0-9\.\*\-\+]+//g;
1.408 albertel 9378: push(@idresponses,$entries[$idx]);
9379: }
9380: $$responses{$id}=join(',',@idresponses);
9381: }
1.405 www 9382: }
9383: return ($errormsg,$number);
9384: }
9385:
1.419 www 9386: sub interwrite_eval {
9387: my ($questiontitles,$responses)=@_;
9388: my $number=0;
9389: my $errormsg='';
1.420 www 9390: my $skipline=1;
9391: my $questionnumber=0;
9392: my %idresponses=();
1.419 www 9393: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
9394: my %components=&Apache::loncommon::record_sep($line);
9395: my @entries=map {$components{$_}} (sort(keys(%components)));
1.420 www 9396: if ($entries[1] eq 'Time') { $skipline=0; next; }
9397: if ($entries[1] eq 'Response') { $skipline=1; }
9398: next if $skipline;
9399: if ($entries[0]!=$questionnumber) {
9400: $questionnumber=$entries[0];
9401: $$questiontitles[$number]=&mt('Question [_1]',$questionnumber);
9402: $number++;
1.419 www 9403: }
1.420 www 9404: my $id=$entries[4];
9405: $id=~s/^[\#0]+//;
1.421 www 9406: $id=~s/^v\d*\://i;
9407: $id=~s/[\-\:]//g;
1.420 www 9408: $idresponses{$id}[$number]=$entries[6];
9409: }
1.524 raeburn 9410: foreach my $id (keys(%idresponses)) {
1.420 www 9411: $$responses{$id}=join(',',@{$idresponses{$id}});
9412: $$responses{$id}=~s/^\s*\,//;
1.419 www 9413: }
9414: return ($errormsg,$number);
9415: }
9416:
1.414 www 9417: sub assign_clicker_grades {
9418: my ($r)=@_;
9419: my ($symb)=&get_symb($r);
9420: if (!$symb) {return '';}
1.416 www 9421: # See which part we are saving to
1.582 raeburn 9422: my $res_error;
9423: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
9424: if ($res_error) {
9425: return &navmap_errormsg();
9426: }
1.416 www 9427: # FIXME: This should probably look for the first handgradeable part
9428: my $part=$$partlist[0];
9429: # Start screen output
1.596.2.10 raeburn 9430: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.596.2.4 raeburn 9431:
1.596.2.10 raeburn 9432: $result .= '<br />'.
9433: &Apache::loncommon::start_data_table().
1.596.2.4 raeburn 9434: &Apache::loncommon::start_data_table_header_row().
9435: '<th>'.&mt('Assigning grades based on clicker file').'</th>'.
9436: &Apache::loncommon::end_data_table_header_row().
9437: &Apache::loncommon::start_data_table_row().'<td>';
1.416 www 9438:
1.414 www 9439: # Get correct result
9440: # FIXME: Possibly need delimiter other than ":"
9441: my @correct=();
1.415 www 9442: my $gradingmechanism=$env{'form.gradingmechanism'};
9443: my $number=$env{'form.number'};
9444: if ($gradingmechanism ne 'attendance') {
1.414 www 9445: foreach my $key (keys(%env)) {
9446: if ($key=~/^form\.correct\:/) {
9447: my @input=split(/\,/,$env{$key});
9448: for (my $i=0;$i<=$#input;$i++) {
9449: if (($correct[$i]) && ($input[$i]) &&
9450: ($correct[$i] ne $input[$i])) {
9451: $result.='<br /><span class="LC_warning">'.
9452: &mt('More than one correct result given for question "[_1]": [_2] versus [_3].',
9453: $env{'form.question:'.$i},$correct[$i],$input[$i]).'</span>';
1.596.2.4 raeburn 9454: } elsif (($input[$i]) || ($input[$i] eq '0')) {
1.414 www 9455: $correct[$i]=$input[$i];
9456: }
9457: }
9458: }
9459: }
1.415 www 9460: for (my $i=0;$i<$number;$i++) {
1.596.2.4 raeburn 9461: if ((!$correct[$i]) && ($correct[$i] ne '0')) {
1.414 www 9462: $result.='<br /><span class="LC_error">'.
9463: &mt('No correct result given for question "[_1]"!',
9464: $env{'form.question:'.$i}).'</span>';
9465: }
9466: }
1.596.2.4 raeburn 9467: $result.='<br />'.&mt("Correct answer: [_1]",join(', ',map { ((($_) || ($_ eq '0'))?$_:'-') } @correct));
1.414 www 9468: }
9469: # Start grading
1.415 www 9470: my $pcorrect=$env{'form.pcorrect'};
9471: my $pincorrect=$env{'form.pincorrect'};
1.416 www 9472: my $storecount=0;
1.596.2.4 raeburn 9473: my %users=();
1.415 www 9474: foreach my $key (keys(%env)) {
1.420 www 9475: my $user='';
1.415 www 9476: if ($key=~/^form\.student\:(.*)$/) {
1.420 www 9477: $user=$1;
9478: }
9479: if ($key=~/^form\.unknown\:(.*)$/) {
9480: my $id=$1;
9481: if (($env{'form.uname'.$id}) && ($env{'form.udom'.$id})) {
9482: $user=$env{'form.uname'.$id}.':'.$env{'form.udom'.$id};
1.437 www 9483: } elsif ($env{'form.multi'.$id}) {
9484: $user=$env{'form.multi'.$id};
1.420 www 9485: }
9486: }
1.596.2.4 raeburn 9487: if ($user) {
9488: if ($users{$user}) {
9489: $result.='<br /><span class="LC_warning">'.
9490: &mt("More than one entry found for <tt>[_1]</tt>!",$user).
9491: '</span><br />';
9492: }
9493: $users{$user}=1;
1.415 www 9494: my @answer=split(/\,/,$env{$key});
9495: my $sum=0;
1.522 www 9496: my $realnumber=$number;
1.415 www 9497: for (my $i=0;$i<$number;$i++) {
1.576 www 9498: if ($correct[$i] eq '-') {
9499: $realnumber--;
9500: } elsif ($answer[$i]) {
1.415 www 9501: if ($gradingmechanism eq 'attendance') {
9502: $sum+=$pcorrect;
1.576 www 9503: } elsif ($correct[$i] eq '*') {
1.522 www 9504: $sum+=$pcorrect;
1.415 www 9505: } else {
1.596.2.4 raeburn 9506: # We actually grade if correct or not
9507: my $increment=$pincorrect;
9508: # Special case: numerical answer "0"
9509: if ($correct[$i] eq '0') {
9510: if ($answer[$i]=~/^[0\.]+$/) {
9511: $increment=$pcorrect;
9512: }
9513: # General numerical answer, both evaluate to something non-zero
9514: } elsif ((1.0*$correct[$i]!=0) && (1.0*$answer[$i]!=0)) {
9515: if (1.0*$correct[$i]==1.0*$answer[$i]) {
9516: $increment=$pcorrect;
9517: }
9518: # Must be just alphanumeric
9519: } elsif ($answer[$i] eq $correct[$i]) {
9520: $increment=$pcorrect;
1.415 www 9521: }
1.596.2.4 raeburn 9522: $sum+=$increment;
1.415 www 9523: }
9524: }
9525: }
1.522 www 9526: my $ave=$sum/(100*$realnumber);
1.416 www 9527: # Store
9528: my ($username,$domain)=split(/\:/,$user);
9529: my %grades=();
9530: $grades{"resource.$part.solved"}='correct_by_override';
9531: $grades{"resource.$part.awarded"}=$ave;
9532: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
9533: my $returncode=&Apache::lonnet::cstore(\%grades,$symb,
9534: $env{'request.course.id'},
9535: $domain,$username);
9536: if ($returncode ne 'ok') {
9537: $result.="<br /><span class=\"LC_error\">Failed to save student $username:$domain. Message when trying to save was ($returncode)</span>";
9538: } else {
9539: $storecount++;
9540: }
1.415 www 9541: }
9542: }
9543: # We are done
1.549 hauer 9544: $result.='<br />'.&mt('Successfully stored grades for [quant,_1,student].',$storecount).
1.596.2.4 raeburn 9545: '</td>'.
9546: &Apache::loncommon::end_data_table_row().
9547: &Apache::loncommon::end_data_table()."<br /><br />\n";
1.414 www 9548: return $result.&show_grading_menu_form($symb);
9549: }
9550:
1.582 raeburn 9551: sub navmap_errormsg {
9552: return '<div class="LC_error">'.
9553: &mt('An error occurred retrieving information about resources in the course.').'<br />'.
1.595 raeburn 9554: &mt('It is recommended that you [_1]re-initialize the course[_2] and then return to this grading page.','<a href="/adm/roles?selectrole=1&newrole='.$env{'request.role'}.'">','</a>').
1.582 raeburn 9555: '</div>';
9556: }
9557:
1.1 albertel 9558: sub handler {
1.41 ng 9559: my $request=$_[0];
1.434 albertel 9560: &reset_caches();
1.596.2.4 raeburn 9561: if ($request->header_only) {
9562: &Apache::loncommon::content_type($request,'text/html');
9563: $request->send_http_header;
9564: return OK;
1.41 ng 9565: }
9566: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.596.2.4 raeburn 9567:
1.324 albertel 9568: my $symb=&get_symb($request,1);
1.160 albertel 9569: my @commands=&Apache::loncommon::get_env_multiple('form.command');
9570: my $command=$commands[0];
1.447 foxr 9571:
1.160 albertel 9572: if ($#commands > 0) {
9573: &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands));
9574: }
1.447 foxr 9575:
1.513 foxr 9576: $ssi_error = 0;
1.535 raeburn 9577: my $brcrum = [{href=>"/adm/grades",text=>"Grading"}];
1.596.2.4 raeburn 9578: my $start_page = &Apache::loncommon::start_page('Grading',undef,
1.596.2.5 raeburn 9579: {'bread_crumbs' => $brcrum});
1.324 albertel 9580: if ($symb eq '' && $command eq '') {
1.257 albertel 9581: if ($env{'user.adv'}) {
1.596.2.4 raeburn 9582: &Apache::loncommon::content_type($request,'text/html');
9583: $request->send_http_header;
9584: $request->print($start_page);
1.257 albertel 9585: if (($env{'form.codeone'}) && ($env{'form.codetwo'}) &&
9586: ($env{'form.codethree'})) {
9587: my $token=$env{'form.codeone'}.'*'.$env{'form.codetwo'}.'*'.
9588: $env{'form.codethree'};
1.41 ng 9589: my ($tsymb,$tuname,$tudom,$tcrsid)=
9590: &Apache::lonnet::checkin($token);
9591: if ($tsymb) {
1.137 albertel 9592: my ($map,$id,$url)=&Apache::lonnet::decode_symb($tsymb);
1.41 ng 9593: if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
1.513 foxr 9594: $request->print(&ssi_with_retries('/res/'.$url, $ssi_retries,
1.99 albertel 9595: ('grade_username' => $tuname,
9596: 'grade_domain' => $tudom,
9597: 'grade_courseid' => $tcrsid,
9598: 'grade_symb' => $tsymb)));
1.41 ng 9599: } else {
1.45 ng 9600: $request->print('<h3>Not authorized: '.$token.'</h3>');
1.99 albertel 9601: }
1.41 ng 9602: } else {
1.45 ng 9603: $request->print('<h3>Not a valid DocID: '.$token.'</h3>');
1.41 ng 9604: }
1.14 www 9605: } else {
1.41 ng 9606: $request->print(&Apache::lonxml::tokeninputfield());
9607: }
1.596.2.4 raeburn 9608: } elsif ($env{'request.course.id'}) {
9609: &init_perm();
9610: if (!%perm) {
9611: $request->internal_redirect('/adm/quickgrades');
9612: } else {
9613: &Apache::loncommon::content_type($request,'text/html');
9614: $request->send_http_header;
9615: $request->print($start_page);
9616: }
9617: }
1.41 ng 9618: } else {
1.596.2.4 raeburn 9619: &init_perm();
9620: if (!$env{'request.course.id'}) {
1.596.2.11 raeburn 9621: unless ((&Apache::lonnet::allowed('usc',$env{'request.role.domain'})) &&
9622: ($command =~ /^scantronupload/)) {
9623: # Not in a course.
9624: $env{'user.error.msg'}="/adm/grades::vgr:0:0:Cannot display grades page outside course context";
9625: return HTTP_NOT_ACCEPTABLE;
9626: }
1.596.2.4 raeburn 9627: } elsif (!%perm) {
9628: $request->internal_redirect('/adm/quickgrades');
9629: }
9630: &Apache::loncommon::content_type($request,'text/html');
9631: $request->send_http_header;
9632: $request->print($start_page);
1.104 albertel 9633: if ($command eq 'submission' && $perm{'vgr'}) {
1.257 albertel 9634: ($env{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0));
1.103 albertel 9635: } elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) {
1.68 ng 9636: &pickStudentPage($request);
1.103 albertel 9637: } elsif ($command eq 'displayPage' && $perm{'vgr'}) {
1.68 ng 9638: &displayPage($request);
1.104 albertel 9639: } elsif ($command eq 'gradeByPage' && $perm{'mgr'}) {
1.71 ng 9640: &updateGradeByPage($request);
1.104 albertel 9641: } elsif ($command eq 'processGroup' && $perm{'vgr'}) {
1.41 ng 9642: &processGroup($request);
1.104 albertel 9643: } elsif ($command eq 'gradingmenu' && $perm{'vgr'}) {
1.443 banghart 9644: $request->print(&grading_menu($request));
9645: } elsif ($command eq 'submit_options' && $perm{'vgr'}) {
9646: $request->print(&submit_options($request));
1.104 albertel 9647: } elsif ($command eq 'viewgrades' && $perm{'vgr'}) {
1.41 ng 9648: $request->print(&viewgrades($request));
1.104 albertel 9649: } elsif ($command eq 'handgrade' && $perm{'mgr'}) {
1.41 ng 9650: $request->print(&processHandGrade($request));
1.106 albertel 9651: } elsif ($command eq 'editgrades' && $perm{'mgr'}) {
1.41 ng 9652: $request->print(&editgrades($request));
1.106 albertel 9653: } elsif ($command eq 'verify' && $perm{'vgr'}) {
1.41 ng 9654: $request->print(&verifyreceipt($request));
1.400 www 9655: } elsif ($command eq 'processclicker' && $perm{'mgr'}) {
9656: $request->print(&process_clicker($request));
9657: } elsif ($command eq 'processclickerfile' && $perm{'mgr'}) {
9658: $request->print(&process_clicker_file($request));
1.414 www 9659: } elsif ($command eq 'assignclickergrades' && $perm{'mgr'}) {
9660: $request->print(&assign_clicker_grades($request));
1.106 albertel 9661: } elsif ($command eq 'csvform' && $perm{'mgr'}) {
1.72 ng 9662: $request->print(&upcsvScores_form($request));
1.106 albertel 9663: } elsif ($command eq 'csvupload' && $perm{'mgr'}) {
1.41 ng 9664: $request->print(&csvupload($request));
1.106 albertel 9665: } elsif ($command eq 'csvuploadmap' && $perm{'mgr'} ) {
1.41 ng 9666: $request->print(&csvuploadmap($request));
1.246 albertel 9667: } elsif ($command eq 'csvuploadoptions' && $perm{'mgr'}) {
1.257 albertel 9668: if ($env{'form.associate'} ne 'Reverse Association') {
1.246 albertel 9669: $request->print(&csvuploadoptions($request));
1.41 ng 9670: } else {
1.257 albertel 9671: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
9672: $env{'form.upfile_associate'} = 'reverse';
1.41 ng 9673: } else {
1.257 albertel 9674: $env{'form.upfile_associate'} = 'forward';
1.41 ng 9675: }
9676: $request->print(&csvuploadmap($request));
9677: }
1.246 albertel 9678: } elsif ($command eq 'csvuploadassign' && $perm{'mgr'} ) {
9679: $request->print(&csvuploadassign($request));
1.106 albertel 9680: } elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
1.75 albertel 9681: $request->print(&scantron_selectphase($request));
1.203 albertel 9682: } elsif ($command eq 'scantron_warning' && $perm{'mgr'}) {
9683: $request->print(&scantron_do_warning($request));
1.142 albertel 9684: } elsif ($command eq 'scantron_validate' && $perm{'mgr'}) {
9685: $request->print(&scantron_validate_file($request));
1.106 albertel 9686: } elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
1.82 albertel 9687: $request->print(&scantron_process_students($request));
1.157 albertel 9688: } elsif ($command eq 'scantronupload' &&
1.257 albertel 9689: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
9690: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.162 albertel 9691: $request->print(&scantron_upload_scantron_data($request));
1.157 albertel 9692: } elsif ($command eq 'scantronupload_save' &&
1.257 albertel 9693: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
9694: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.157 albertel 9695: $request->print(&scantron_upload_scantron_data_save($request));
1.202 albertel 9696: } elsif ($command eq 'scantron_download' &&
1.257 albertel 9697: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.162 albertel 9698: $request->print(&scantron_download_scantron_data($request));
1.523 raeburn 9699: } elsif ($command eq 'checksubmissions' && $perm{'vgr'}) {
9700: $request->print(&checkscantron_results($request));
1.106 albertel 9701: } elsif ($command) {
1.562 bisitz 9702: $request->print('<p class="LC_error">'.&mt('Access Denied ([_1])',$command).'</p>');
1.26 albertel 9703: }
1.2 albertel 9704: }
1.513 foxr 9705: if ($ssi_error) {
9706: &ssi_print_error($request);
9707: }
1.353 albertel 9708: $request->print(&Apache::loncommon::end_page());
1.434 albertel 9709: &reset_caches();
1.596.2.4 raeburn 9710: return OK;
1.44 ng 9711: }
9712:
1.1 albertel 9713: 1;
9714:
1.13 albertel 9715: __END__;
1.531 jms 9716:
9717:
9718: =head1 NAME
9719:
9720: Apache::grades
9721:
9722: =head1 SYNOPSIS
9723:
9724: Handles the viewing of grades.
9725:
9726: This is part of the LearningOnline Network with CAPA project
9727: described at http://www.lon-capa.org.
9728:
9729: =head1 OVERVIEW
9730:
9731: Do an ssi with retries:
9732: While I'd love to factor out this with the vesrion in lonprintout,
9733: that would either require a data coupling between modules, which I refuse to perpetuate (there's quite enough of that already), or would require the invention of another infrastructure
9734: I'm not quite ready to invent (e.g. an ssi_with_retry object).
9735:
9736: At least the logic that drives this has been pulled out into loncommon.
9737:
9738:
9739:
9740: ssi_with_retries - Does the server side include of a resource.
9741: if the ssi call returns an error we'll retry it up to
9742: the number of times requested by the caller.
9743: If we still have a proble, no text is appended to the
9744: output and we set some global variables.
9745: to indicate to the caller an SSI error occurred.
9746: All of this is supposed to deal with the issues described
9747: in LonCAPA BZ 5631 see:
9748: http://bugs.lon-capa.org/show_bug.cgi?id=5631
9749: by informing the user that this happened.
9750:
9751: Parameters:
9752: resource - The resource to include. This is passed directly, without
9753: interpretation to lonnet::ssi.
9754: form - The form hash parameters that guide the interpretation of the resource
9755:
9756: retries - Number of retries allowed before giving up completely.
9757: Returns:
9758: On success, returns the rendered resource identified by the resource parameter.
9759: Side Effects:
9760: The following global variables can be set:
9761: ssi_error - If an unrecoverable error occurred this becomes true.
9762: It is up to the caller to initialize this to false
9763: if desired.
9764: ssi_error_resource - If an unrecoverable error occurred, this is the value
9765: of the resource that could not be rendered by the ssi
9766: call.
9767: ssi_error_message - The error string fetched from the ssi response
9768: in the event of an error.
9769:
9770:
9771: =head1 HANDLER SUBROUTINE
9772:
9773: ssi_with_retries()
9774:
9775: =head1 SUBROUTINES
9776:
9777: =over
9778:
9779: =item scantron_get_correction() :
9780:
9781: Builds the interface screen to interact with the operator to fix a
9782: specific error condition in a specific scanline
9783:
9784: Arguments:
9785: $r - Apache request object
9786: $i - number of the current scanline
9787: $scan_record - hash ref as returned from &scantron_parse_scanline()
9788: $scan_config - hash ref as returned from &get_scantron_config()
9789: $line - full contents of the current scanline
9790: $error - error condition, valid values are
9791: 'incorrectCODE', 'duplicateCODE',
9792: 'doublebubble', 'missingbubble',
9793: 'duplicateID', 'incorrectID'
9794: $arg - extra information needed
9795: For errors:
9796: - duplicateID - paper number that this studentID was seen before on
9797: - duplicateCODE - array ref of the paper numbers this CODE was
9798: seen on before
9799: - incorrectCODE - current incorrect CODE
9800: - doublebubble - array ref of the bubble lines that have double
9801: bubble errors
9802: - missingbubble - array ref of the bubble lines that have missing
9803: bubble errors
9804:
9805: =item scantron_get_maxbubble() :
9806:
1.582 raeburn 9807: Arguments:
9808: $nav_error - Reference to scalar which is a flag to indicate a
9809: failure to retrieve a navmap object.
9810: if $nav_error is set to 1 by scantron_get_maxbubble(), the
9811: calling routine should trap the error condition and display the warning
9812: found in &navmap_errormsg().
9813:
1.596.2.12.2. (raeburn 9814:): $scantron_config - Reference to bubblesheet format configuration hash.
9815:):
1.531 jms 9816: Returns the maximum number of bubble lines that are expected to
9817: occur. Does this by walking the selected sequence rendering the
9818: resource and then checking &Apache::lonxml::get_problem_counter()
9819: for what the current value of the problem counter is.
9820:
9821: Caches the results to $env{'form.scantron_maxbubble'},
9822: $env{'form.scantron.bubble_lines.n'},
9823: $env{'form.scantron.first_bubble_line.n'} and
9824: $env{"form.scantron.sub_bubblelines.n"}
9825: which are the total number of bubble, lines, the number of bubble
9826: lines for response n and number of the first bubble line for response n,
9827: and a comma separated list of numbers of bubble lines for sub-questions
9828: (for optionresponse, matchresponse, and rankresponse items), for response n.
9829:
9830:
9831: =item scantron_validate_missingbubbles() :
9832:
9833: Validates all scanlines in the selected file to not have any
9834: answers that don't have bubbles that have not been verified
9835: to be bubble free.
9836:
9837: =item scantron_process_students() :
9838:
1.596.2.6 raeburn 9839: Routine that does the actual grading of the bubblesheet information.
1.531 jms 9840:
9841: The parsed scanline hash is added to %env
9842:
9843: Then foreach unskipped scanline it does an &Apache::lonnet::ssi()
9844: foreach resource , with the form data of
9845:
9846: 'submitted' =>'scantron'
9847: 'grade_target' =>'grade',
9848: 'grade_username'=> username of student
9849: 'grade_domain' => domain of student
9850: 'grade_courseid'=> of course
9851: 'grade_symb' => symb of resource to grade
9852:
9853: This triggers a grading pass. The problem grading code takes care
9854: of converting the bubbled letter information (now in %env) into a
9855: valid submission.
9856:
9857: =item scantron_upload_scantron_data() :
9858:
1.596.2.6 raeburn 9859: Creates the screen for adding a new bubblesheet data file to a course.
1.531 jms 9860:
9861: =item scantron_upload_scantron_data_save() :
9862:
9863: Adds a provided bubble information data file to the course if user
9864: has the correct privileges to do so.
9865:
9866: =item valid_file() :
9867:
9868: Validates that the requested bubble data file exists in the course.
9869:
9870: =item scantron_download_scantron_data() :
9871:
9872: Shows a list of the three internal files (original, corrected,
1.596.2.6 raeburn 9873: skipped) for a specific bubblesheet data file that exists in the
1.531 jms 9874: course.
9875:
9876: =item scantron_validate_ID() :
9877:
9878: Validates all scanlines in the selected file to not have any
1.556 weissno 9879: invalid or underspecified student/employee IDs
1.531 jms 9880:
1.582 raeburn 9881: =item navmap_errormsg() :
9882:
9883: Returns HTML mark-up inside a <div></div> with a link to re-initialize the course.
9884: Should be called whenever the request to instantiate a navmap object fails.
9885:
1.531 jms 9886: =back
9887:
9888: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>