Annotation of loncom/homework/grades.pm, revision 1.596.2.12.2.17
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. 7(raebur 4:3): # $Id: grades.pm,v 1.596.2.12.2.16 2013/06/28 22:54:50 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.596.2.12.2. (raeburn 55:): my %old_essays=();
1.447 foxr 56:
1.513 foxr 57: # These variables are used to recover from ssi errors
58:
59: my $ssi_retries = 5;
60: my $ssi_error;
61: my $ssi_error_resource;
62: my $ssi_error_message;
63:
64:
65: sub ssi_with_retries {
66: my ($resource, $retries, %form) = @_;
67: my ($content, $response) = &Apache::loncommon::ssi_with_retries($resource, $retries, %form);
68: if ($response->is_error) {
69: $ssi_error = 1;
70: $ssi_error_resource = $resource;
71: $ssi_error_message = $response->code . " " . $response->message;
72: }
73:
74: return $content;
75:
76: }
77: #
78: # Prodcuces an ssi retry failure error message to the user:
79: #
80:
81: sub ssi_print_error {
82: my ($r) = @_;
1.516 raeburn 83: my $helpurl = &Apache::loncommon::top_nav_help('Helpdesk');
84: $r->print('
85: <br />
86: <h2>'.&mt('An unrecoverable network error occurred:').'</h2>
87: <p>
88: '.&mt('Unable to retrieve a resource from a server:').'<br />
89: '.&mt('Resource:').' '.$ssi_error_resource.'<br />
90: '.&mt('Error:').' '.$ssi_error_message.'
91: </p>
92: <p>'.
93: &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 />'.
94: &mt('If the error persists, please contact the [_1] for assistance.',$helpurl).
95: '</p>');
96: return;
1.513 foxr 97: }
98:
1.44 ng 99: #
1.146 albertel 100: # --- Retrieve the parts from the metadata file.---
1.44 ng 101: sub getpartlist {
1.582 raeburn 102: my ($symb,$errorref) = @_;
1.439 albertel 103:
104: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 105: unless (ref($navmap)) {
106: if (ref($errorref)) {
107: $$errorref = 'navmap';
108: return;
109: }
110: }
1.439 albertel 111: my $res = $navmap->getBySymb($symb);
112: my $partlist = $res->parts();
113: my $url = $res->src();
114: my @metakeys = split(/,/,&Apache::lonnet::metadata($url,'keys'));
115:
1.146 albertel 116: my @stores;
1.439 albertel 117: foreach my $part (@{ $partlist }) {
1.146 albertel 118: foreach my $key (@metakeys) {
119: if ($key =~ m/^stores_\Q$part\E_/) { push(@stores,$key); }
120: }
121: }
122: return @stores;
1.2 albertel 123: }
124:
1.44 ng 125: # --- Get the symbolic name of a problem and the url
1.324 albertel 126: sub get_symb {
1.173 albertel 127: my ($request,$silent) = @_;
1.596.2.12.2. (raeburn 128:): my $symb=$env{'form.symb'};
129:): unless ($symb) {
130:): (my $url=$env{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
131:): $symb = &Apache::lonnet::symbread($url);
132:): if ($symb eq '') {
133:): if (!$silent) {
134:): $request->print(&mt("Unable to handle ambiguous references: [_1].",$url));
135:): return ();
136:): }
137:): }
1.173 albertel 138: }
1.418 albertel 139: &Apache::lonenc::check_decrypt(\$symb);
1.324 albertel 140: return ($symb);
1.32 ng 141: }
142:
1.129 ng 143: #--- Format fullname, username:domain if different for display
144: #--- Use anywhere where the student names are listed
145: sub nameUserString {
146: my ($type,$fullname,$uname,$udom) = @_;
147: if ($type eq 'header') {
1.485 albertel 148: return '<b> '.&mt('Fullname').' </b><span class="LC_internal_info">('.&mt('Username').')</span>';
1.129 ng 149: } else {
1.398 albertel 150: return ' '.$fullname.'<span class="LC_internal_info"> ('.$uname.
151: ($env{'user.domain'} eq $udom ? '' : ' ('.$udom.')').')</span>';
1.129 ng 152: }
153: }
154:
1.44 ng 155: #--- Get the partlist and the response type for a given problem. ---
156: #--- Indicate if a response type is coded handgraded or not. ---
1.39 ng 157: sub response_type {
1.582 raeburn 158: my ($symb,$response_error) = @_;
1.377 albertel 159:
160: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 161: unless (ref($navmap)) {
162: if (ref($response_error)) {
163: $$response_error = 1;
164: }
165: return;
166: }
1.377 albertel 167: my $res = $navmap->getBySymb($symb);
1.593 raeburn 168: unless (ref($res)) {
169: $$response_error = 1;
170: return;
171: }
1.377 albertel 172: my $partlist = $res->parts();
1.392 albertel 173: my %vPart =
174: map { $_ => 1 } (&Apache::loncommon::get_env_multiple('form.vPart'));
1.377 albertel 175: my (%response_types,%handgrade);
176: foreach my $part (@{ $partlist }) {
1.392 albertel 177: next if (%vPart && !exists($vPart{$part}));
178:
1.377 albertel 179: my @types = $res->responseType($part);
180: my @ids = $res->responseIds($part);
181: for (my $i=0; $i < scalar(@ids); $i++) {
182: $response_types{$part}{$ids[$i]} = $types[$i];
183: $handgrade{$part.'_'.$ids[$i]} =
184: &Apache::lonnet::EXT('resource.'.$part.'_'.$ids[$i].
185: '.handgrade',$symb);
1.41 ng 186: }
187: }
1.377 albertel 188: return ($partlist,\%handgrade,\%response_types);
1.39 ng 189: }
190:
1.375 albertel 191: sub flatten_responseType {
192: my ($responseType) = @_;
193: my @part_response_id =
194: map {
195: my $part = $_;
196: map {
197: [$part,$_]
198: } sort(keys(%{ $responseType->{$part} }));
199: } sort(keys(%$responseType));
200: return @part_response_id;
201: }
202:
1.207 albertel 203: sub get_display_part {
1.324 albertel 204: my ($partID,$symb)=@_;
1.207 albertel 205: my $display=&Apache::lonnet::EXT('resource.'.$partID.'.display',$symb);
206: if (defined($display) and $display ne '') {
1.577 bisitz 207: $display.= ' (<span class="LC_internal_info">'
208: .&mt('Part ID: [_1]',$partID).'</span>)';
1.207 albertel 209: } else {
210: $display=$partID;
211: }
212: return $display;
213: }
1.269 raeburn 214:
1.118 ng 215: #--- Show resource title
216: #--- and parts and response type
217: sub showResourceInfo {
1.582 raeburn 218: my ($symb,$probTitle,$checkboxes,$res_error) = @_;
1.398 albertel 219: my $result = '<h3>'.&mt('Current Resource').': '.$probTitle.'</h3>'."\n";
1.582 raeburn 220: my ($partlist,$handgrade,$responseType) = &response_type($symb,$res_error);
221: if (ref($res_error)) {
222: if ($$res_error) {
223: return;
224: }
225: }
1.584 bisitz 226: $result.=&Apache::loncommon::start_data_table()
227: .&Apache::loncommon::start_data_table_header_row();
228: if ($checkboxes) {
229: $result.='<th> </th>';
230: }
231: $result.='<th>'.&mt('Problem Part').'</th>'
232: .'<th>'.&mt('Res. ID').'</th>'
233: .'<th>'.&mt('Type').'</th>'
234: .&Apache::loncommon::end_data_table_header_row();
1.126 ng 235: my %resptype = ();
1.122 ng 236: my $hdgrade='no';
1.154 albertel 237: my %partsseen;
1.524 raeburn 238: foreach my $partID (sort(keys(%$responseType))) {
1.584 bisitz 239: foreach my $resID (sort(keys(%{ $responseType->{$partID} }))) {
240: my $handgrade=$$handgrade{$partID.'_'.$resID};
241: my $responsetype = $responseType->{$partID}->{$resID};
242: $hdgrade = $handgrade if ($handgrade eq 'yes');
243: $result.=&Apache::loncommon::start_data_table_row();
244: if ($checkboxes) {
245: if (exists($partsseen{$partID})) {
246: $result.="<td> </td>";
247: } else {
248: $result.="<td><input type='checkbox' name='vPart' value='$partID' checked='checked' /></td>";
249: }
250: $partsseen{$partID}=1;
251: }
252: my $display_part=&get_display_part($partID,$symb);
253: $result.='<td>'.$display_part.'</td>'
254: .'<td>'.'<span class="LC_internal_info">'.$resID.'</span></td>'
255: .'<td>'.&mt($responsetype).'</td>'
1.596.2.12.2. 2(raebur 256:2): # .'<td><b>'.&mt('Handgrade: [_1]',$handgrade).'</b></td>'
1.584 bisitz 257: .&Apache::loncommon::end_data_table_row();
258: }
1.118 ng 259: }
1.584 bisitz 260: $result.=&Apache::loncommon::end_data_table();
1.147 albertel 261: return $result,$responseType,$hdgrade,$partlist,$handgrade;
1.118 ng 262: }
263:
1.434 albertel 264: sub reset_caches {
265: &reset_analyze_cache();
266: &reset_perm();
1.596.2.12.2. (raeburn 267:): &reset_old_essays();
1.434 albertel 268: }
269:
270: {
271: my %analyze_cache;
1.557 raeburn 272: my %analyze_cache_formkeys;
1.148 albertel 273:
1.434 albertel 274: sub reset_analyze_cache {
275: undef(%analyze_cache);
1.557 raeburn 276: undef(%analyze_cache_formkeys);
1.434 albertel 277: }
278:
279: sub get_analyze {
1.596.2.12.2. (raeburn 280:): my ($symb,$uname,$udom,$no_increment,$add_to_hash,$type,$trial,$rndseed,$bubbles_per_row)=@_;
1.434 albertel 281: my $key = "$symb\0$uname\0$udom";
1.596.2.2 raeburn 282: if ($type eq 'randomizetry') {
283: if ($trial ne '') {
284: $key .= "\0".$trial;
285: }
286: }
1.557 raeburn 287: if (exists($analyze_cache{$key})) {
288: my $getupdate = 0;
289: if (ref($add_to_hash) eq 'HASH') {
290: foreach my $item (keys(%{$add_to_hash})) {
291: if (ref($analyze_cache_formkeys{$key}) eq 'HASH') {
292: if (!exists($analyze_cache_formkeys{$key}{$item})) {
293: $getupdate = 1;
294: last;
295: }
296: } else {
297: $getupdate = 1;
298: }
299: }
300: }
301: if (!$getupdate) {
302: return $analyze_cache{$key};
303: }
304: }
1.434 albertel 305:
306: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
307: $url=&Apache::lonnet::clutter($url);
1.557 raeburn 308: my %form = ('grade_target' => 'analyze',
309: 'grade_domain' => $udom,
310: 'grade_symb' => $symb,
311: 'grade_courseid' => $env{'request.course.id'},
312: 'grade_username' => $uname,
313: 'grade_noincrement' => $no_increment);
1.596.2.12.2. (raeburn 314:): if ($bubbles_per_row ne '') {
315:): $form{'bubbles_per_row'} = $bubbles_per_row;
316:): }
1.596.2.2 raeburn 317: if ($type eq 'randomizetry') {
318: $form{'grade_questiontype'} = $type;
319: if ($rndseed ne '') {
320: $form{'grade_rndseed'} = $rndseed;
321: }
322: }
1.557 raeburn 323: if (ref($add_to_hash)) {
324: %form = (%form,%{$add_to_hash});
1.596.2.2 raeburn 325: }
1.557 raeburn 326: my $subresult=&ssi_with_retries($url, $ssi_retries,%form);
1.434 albertel 327: (undef,$subresult)=split(/_HASH_REF__/,$subresult,2);
328: my %analyze=&Apache::lonnet::str2hash($subresult);
1.557 raeburn 329: if (ref($add_to_hash) eq 'HASH') {
330: $analyze_cache_formkeys{$key} = $add_to_hash;
331: } else {
332: $analyze_cache_formkeys{$key} = {};
333: }
1.434 albertel 334: return $analyze_cache{$key} = \%analyze;
335: }
336:
337: sub get_order {
1.596.2.2 raeburn 338: my ($partid,$respid,$symb,$uname,$udom,$no_increment,$type,$trial,$rndseed)=@_;
339: my $analyze = &get_analyze($symb,$uname,$udom,$no_increment,undef,$type,$trial,$rndseed);
1.434 albertel 340: return $analyze->{"$partid.$respid.shown"};
341: }
342:
343: sub get_radiobutton_correct_foil {
1.596.2.2 raeburn 344: my ($partid,$respid,$symb,$uname,$udom,$type,$trial,$rndseed)=@_;
345: my $analyze = &get_analyze($symb,$uname,$udom,undef,undef,$type,$trial,$rndseed);
346: my $foils = &get_order($partid,$respid,$symb,$uname,$udom,undef,$type,$trial,$rndseed);
1.555 raeburn 347: if (ref($foils) eq 'ARRAY') {
348: foreach my $foil (@{$foils}) {
349: if ($analyze->{"$partid.$respid.foil.value.$foil"} eq 'true') {
350: return $foil;
351: }
1.434 albertel 352: }
353: }
354: }
1.554 raeburn 355:
356: sub scantron_partids_tograde {
1.596.2.12.2. (raeburn 357:): my ($resource,$cid,$uname,$udom,$check_for_randomlist,$bubbles_per_row) = @_;
1.554 raeburn 358: my (%analysis,@parts);
359: if (ref($resource)) {
360: my $symb = $resource->symb();
1.557 raeburn 361: my $add_to_form;
362: if ($check_for_randomlist) {
363: $add_to_form = { 'check_parts_withrandomlist' => 1,};
364: }
1.596.2.12.2. (raeburn 365:): my $analyze =
366:): &get_analyze($symb,$uname,$udom,undef,$add_to_form,
367:): undef,undef,undef,$bubbles_per_row);
1.554 raeburn 368: if (ref($analyze) eq 'HASH') {
369: %analysis = %{$analyze};
370: }
371: if (ref($analysis{'parts'}) eq 'ARRAY') {
372: foreach my $part (@{$analysis{'parts'}}) {
373: my ($id,$respid) = split(/\./,$part);
374: if (!&Apache::loncommon::check_if_partid_hidden($id,$symb,$udom,$uname)) {
375: push(@parts,$part);
376: }
377: }
378: }
379: }
380: return (\%analysis,\@parts);
381: }
382:
1.148 albertel 383: }
1.434 albertel 384:
1.118 ng 385: #--- Clean response type for display
1.335 albertel 386: #--- Currently filters option/rank/radiobutton/match/essay/Task
387: # response types only.
1.118 ng 388: sub cleanRecord {
1.336 albertel 389: my ($answer,$response,$symb,$partid,$respid,$record,$order,$version,
1.596.2.2 raeburn 390: $uname,$udom,$type,$trial,$rndseed) = @_;
1.398 albertel 391: my $grayFont = '<span class="LC_internal_info">';
1.148 albertel 392: if ($response =~ /^(option|rank)$/) {
393: my %answer=&Apache::lonnet::str2hash($answer);
394: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
395: my ($toprow,$bottomrow);
396: foreach my $foil (@$order) {
397: if ($grading{$foil} == 1) {
398: $toprow.='<td><b>'.$answer{$foil}.' </b></td>';
399: } else {
400: $toprow.='<td><i>'.$answer{$foil}.' </i></td>';
401: }
1.398 albertel 402: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.148 albertel 403: }
404: return '<blockquote><table border="1">'.
1.466 albertel 405: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
406: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.596.2.1 raeburn 407: $bottomrow.'</tr></table></blockquote>';
1.148 albertel 408: } elsif ($response eq 'match') {
409: my %answer=&Apache::lonnet::str2hash($answer);
410: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
411: my @items=&Apache::lonnet::str2array($record->{$version."resource.$partid.$respid.submissionitems"});
412: my ($toprow,$middlerow,$bottomrow);
413: foreach my $foil (@$order) {
414: my $item=shift(@items);
415: if ($grading{$foil} == 1) {
416: $toprow.='<td><b>'.$item.' </b></td>';
1.398 albertel 417: $middlerow.='<td><b>'.$grayFont.$answer{$foil}.' </span></b></td>';
1.148 albertel 418: } else {
419: $toprow.='<td><i>'.$item.' </i></td>';
1.398 albertel 420: $middlerow.='<td><i>'.$grayFont.$answer{$foil}.' </span></i></td>';
1.148 albertel 421: }
1.398 albertel 422: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.118 ng 423: }
1.126 ng 424: return '<blockquote><table border="1">'.
1.466 albertel 425: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
426: '<tr valign="top"><td>'.$grayFont.&mt('Item ID').'</span></td>'.
1.148 albertel 427: $middlerow.'</tr>'.
1.466 albertel 428: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.596.2.8 raeburn 429: $bottomrow.'</tr></table></blockquote>';
1.148 albertel 430: } elsif ($response eq 'radiobutton') {
431: my %answer=&Apache::lonnet::str2hash($answer);
432: my ($toprow,$bottomrow);
1.434 albertel 433: my $correct =
1.596.2.2 raeburn 434: &get_radiobutton_correct_foil($partid,$respid,$symb,$uname,$udom,$type,$trial,$rndseed);
1.434 albertel 435: foreach my $foil (@$order) {
1.148 albertel 436: if (exists($answer{$foil})) {
1.434 albertel 437: if ($foil eq $correct) {
1.466 albertel 438: $toprow.='<td><b>'.&mt('true').'</b></td>';
1.148 albertel 439: } else {
1.466 albertel 440: $toprow.='<td><i>'.&mt('true').'</i></td>';
1.148 albertel 441: }
442: } else {
1.466 albertel 443: $toprow.='<td>'.&mt('false').'</td>';
1.148 albertel 444: }
1.398 albertel 445: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.148 albertel 446: }
447: return '<blockquote><table border="1">'.
1.466 albertel 448: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
449: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.596.2.4 raeburn 450: $bottomrow.'</tr></table></blockquote>';
1.148 albertel 451: } elsif ($response eq 'essay') {
1.257 albertel 452: if (! exists ($env{'form.'.$symb})) {
1.122 ng 453: my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 454: $env{'course.'.$env{'request.course.id'}.'.domain'},
455: $env{'course.'.$env{'request.course.id'}.'.num'});
1.122 ng 456:
1.257 albertel 457: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
458: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
459: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
460: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
461: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
462: $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 463: }
1.166 albertel 464: $answer =~ s-\n-<br />-g;
465: return '<br /><br /><blockquote><tt>'.&keywords_highlight($answer).'</tt></blockquote>';
1.268 albertel 466: } elsif ( $response eq 'organic') {
467: my $result='Smile representation: "<tt>'.$answer.'</tt>"';
468: my $jme=$record->{$version."resource.$partid.$respid.molecule"};
469: $result.=&Apache::chemresponse::jme_img($jme,$answer,400);
470: return $result;
1.335 albertel 471: } elsif ( $response eq 'Task') {
472: if ( $answer eq 'SUBMITTED') {
473: my $files = $record->{$version."resource.$respid.$partid.bridgetask.portfiles"};
1.336 albertel 474: my $result = &Apache::bridgetask::file_list($files,$uname,$udom);
1.335 albertel 475: return $result;
476: } elsif ( grep(/^\Q$version\E.*?\.instance$/, keys(%{$record})) ) {
477: my @matches = grep(/^\Q$version\E.*?\.instance$/,
478: keys(%{$record}));
479: return join('<br />',($version,@matches));
480:
481:
482: } else {
483: my $result =
484: '<p>'
485: .&mt('Overall result: [_1]',
486: $record->{$version."resource.$respid.$partid.status"})
487: .'</p>';
488:
489: $result .= '<ul>';
490: my @grade = grep(/^\Q${version}resource.$respid.$partid.\E[^.]*[.]status$/,
491: keys(%{$record}));
492: foreach my $grade (sort(@grade)) {
493: my ($dim) = ($grade =~/[.]([^.]+)[.]status$/);
494: $result.= '<li>'.&mt("Dimension: [_1], status [_2] ",
495: $dim, $record->{$grade}).
496: '</li>';
497: }
498: $result.='</ul>';
499: return $result;
500: }
1.440 albertel 501: } elsif ( $response =~ m/(?:numerical|formula)/) {
502: $answer =
503: &Apache::loncommon::format_previous_attempt_value('submission',
504: $answer);
1.122 ng 505: }
1.118 ng 506: return $answer;
507: }
508:
509: #-- A couple of common js functions
510: sub commonJSfunctions {
511: my $request = shift;
512: $request->print(<<COMMONJSFUNCTIONS);
513: <script type="text/javascript" language="javascript">
514: function radioSelection(radioButton) {
515: var selection=null;
516: if (radioButton.length > 1) {
517: for (var i=0; i<radioButton.length; i++) {
518: if (radioButton[i].checked) {
519: return radioButton[i].value;
520: }
521: }
522: } else {
523: if (radioButton.checked) return radioButton.value;
524: }
525: return selection;
526: }
527:
528: function pullDownSelection(selectOne) {
529: var selection="";
530: if (selectOne.length > 1) {
531: for (var i=0; i<selectOne.length; i++) {
532: if (selectOne[i].selected) {
533: return selectOne[i].value;
534: }
535: }
536: } else {
1.138 albertel 537: // only one value it must be the selected one
538: return selectOne.value;
1.118 ng 539: }
540: }
541: </script>
542: COMMONJSFUNCTIONS
543: }
544:
1.44 ng 545: #--- Dumps the class list with usernames,list of sections,
546: #--- section, ids and fullnames for each user.
547: sub getclasslist {
1.449 banghart 548: my ($getsec,$filterlist,$getgroup) = @_;
1.291 albertel 549: my @getsec;
1.450 banghart 550: my @getgroup;
1.442 banghart 551: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.291 albertel 552: if (!ref($getsec)) {
553: if ($getsec ne '' && $getsec ne 'all') {
554: @getsec=($getsec);
555: }
556: } else {
557: @getsec=@{$getsec};
558: }
559: if (grep(/^all$/,@getsec)) { undef(@getsec); }
1.450 banghart 560: if (!ref($getgroup)) {
561: if ($getgroup ne '' && $getgroup ne 'all') {
562: @getgroup=($getgroup);
563: }
564: } else {
565: @getgroup=@{$getgroup};
566: }
567: if (grep(/^all$/,@getgroup)) { undef(@getgroup); }
1.291 albertel 568:
1.449 banghart 569: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
1.49 albertel 570: # Bail out if we were unable to get the classlist
1.56 matthew 571: return if (! defined($classlist));
1.449 banghart 572: &Apache::loncoursedata::get_group_memberships($classlist,$keylist);
1.56 matthew 573: #
574: my %sections;
575: my %fullnames;
1.205 matthew 576: foreach my $student (keys(%$classlist)) {
577: my $end =
578: $classlist->{$student}->[&Apache::loncoursedata::CL_END()];
579: my $start =
580: $classlist->{$student}->[&Apache::loncoursedata::CL_START()];
581: my $id =
582: $classlist->{$student}->[&Apache::loncoursedata::CL_ID()];
583: my $section =
584: $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
585: my $fullname =
586: $classlist->{$student}->[&Apache::loncoursedata::CL_FULLNAME()];
587: my $status =
588: $classlist->{$student}->[&Apache::loncoursedata::CL_STATUS()];
1.449 banghart 589: my $group =
590: $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1.76 ng 591: # filter students according to status selected
1.442 banghart 592: if ($filterlist && (!($stu_status =~ /Any/))) {
593: if (!($stu_status =~ $status)) {
1.450 banghart 594: delete($classlist->{$student});
1.76 ng 595: next;
596: }
597: }
1.450 banghart 598: # filter students according to groups selected
1.453 banghart 599: my @stu_groups = split(/,/,$group);
1.450 banghart 600: if (@getgroup) {
601: my $exclude = 1;
1.454 banghart 602: foreach my $grp (@getgroup) {
603: foreach my $stu_group (@stu_groups) {
1.453 banghart 604: if ($stu_group eq $grp) {
605: $exclude = 0;
606: }
1.450 banghart 607: }
1.453 banghart 608: if (($grp eq 'none') && !$group) {
609: $exclude = 0;
610: }
1.450 banghart 611: }
612: if ($exclude) {
613: delete($classlist->{$student});
614: }
615: }
1.205 matthew 616: $section = ($section ne '' ? $section : 'none');
1.106 albertel 617: if (&canview($section)) {
1.291 albertel 618: if (!@getsec || grep(/^\Q$section\E$/,@getsec)) {
1.103 albertel 619: $sections{$section}++;
1.450 banghart 620: if ($classlist->{$student}) {
621: $fullnames{$student}=$fullname;
622: }
1.103 albertel 623: } else {
1.205 matthew 624: delete($classlist->{$student});
1.103 albertel 625: }
626: } else {
1.205 matthew 627: delete($classlist->{$student});
1.103 albertel 628: }
1.44 ng 629: }
630: my %seen = ();
1.56 matthew 631: my @sections = sort(keys(%sections));
632: return ($classlist,\@sections,\%fullnames);
1.44 ng 633: }
634:
1.103 albertel 635: sub canmodify {
636: my ($sec)=@_;
637: if ($perm{'mgr'}) {
638: if (!defined($perm{'mgr_section'})) {
639: # can modify whole class
640: return 1;
641: } else {
642: if ($sec eq $perm{'mgr_section'}) {
643: #can modify the requested section
644: return 1;
645: } else {
646: # can't modify the request section
647: return 0;
648: }
649: }
650: }
651: #can't modify
652: return 0;
653: }
654:
655: sub canview {
656: my ($sec)=@_;
657: if ($perm{'vgr'}) {
658: if (!defined($perm{'vgr_section'})) {
659: # can modify whole class
660: return 1;
661: } else {
662: if ($sec eq $perm{'vgr_section'}) {
663: #can modify the requested section
664: return 1;
665: } else {
666: # can't modify the request section
667: return 0;
668: }
669: }
670: }
671: #can't modify
672: return 0;
673: }
674:
1.44 ng 675: #--- Retrieve the grade status of a student for all the parts
676: sub student_gradeStatus {
1.324 albertel 677: my ($symb,$udom,$uname,$partlist) = @_;
1.257 albertel 678: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.44 ng 679: my %partstatus = ();
680: foreach (@$partlist) {
1.128 ng 681: my ($status,undef) = split(/_/,$record{"resource.$_.solved"},2);
1.44 ng 682: $status = 'nothing' if ($status eq '');
683: $partstatus{$_} = $status;
684: my $subkey = "resource.$_.submitted_by";
685: $partstatus{$subkey} = $record{$subkey} if ($record{$subkey} ne '');
686: }
687: return %partstatus;
688: }
689:
1.45 ng 690: # hidden form and javascript that calls the form
691: # Use by verifyscript and viewgrades
692: # Shows a student's view of problem and submission
693: sub jscriptNform {
1.324 albertel 694: my ($symb) = @_;
1.442 banghart 695: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.45 ng 696: my $jscript='<script type="text/javascript" language="javascript">'."\n".
697: ' function viewOneStudent(user,domain) {'."\n".
698: ' document.onestudent.student.value = user;'."\n".
699: ' document.onestudent.userdom.value = domain;'."\n".
700: ' document.onestudent.submit();'."\n".
701: ' }'."\n".
702: '</script>'."\n";
703: $jscript.= '<form action="/adm/grades" method="post" name="onestudent">'."\n".
1.418 albertel 704: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 705: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
706: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.442 banghart 707: '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.45 ng 708: '<input type="hidden" name="command" value="submission" />'."\n".
709: '<input type="hidden" name="student" value="" />'."\n".
710: '<input type="hidden" name="userdom" value="" />'."\n".
711: '</form>'."\n";
712: return $jscript;
713: }
1.39 ng 714:
1.447 foxr 715:
716:
1.315 bowersj2 717: # Given the score (as a number [0-1] and the weight) what is the final
718: # point value? This function will round to the nearest tenth, third,
719: # or quarter if one of those is within the tolerance of .00001.
1.316 albertel 720: sub compute_points {
1.315 bowersj2 721: my ($score, $weight) = @_;
722:
723: my $tolerance = .00001;
724: my $points = $score * $weight;
725:
726: # Check for nearness to 1/x.
727: my $check_for_nearness = sub {
728: my ($factor) = @_;
729: my $num = ($points * $factor) + $tolerance;
730: my $floored_num = floor($num);
1.316 albertel 731: if ($num - $floored_num < 2 * $tolerance * $factor) {
1.315 bowersj2 732: return $floored_num / $factor;
733: }
734: return $points;
735: };
736:
737: $points = $check_for_nearness->(10);
738: $points = $check_for_nearness->(3);
739: $points = $check_for_nearness->(4);
740:
741: return $points;
742: }
743:
1.44 ng 744: #------------------ End of general use routines --------------------
1.87 www 745:
746: #
747: # Find most similar essay
748: #
749:
750: sub most_similar {
1.596.2.12.2. (raeburn 751:): my ($uname,$udom,$symb,$uessay)=@_;
752:):
753:): unless ($symb) { return ''; }
754:):
755:): unless (ref($old_essays{$symb}) eq 'HASH') { return ''; }
1.87 www 756:
757: # ignore spaces and punctuation
758:
759: $uessay=~s/\W+/ /gs;
760:
1.282 www 761: # ignore empty submissions (occuring when only files are sent)
762:
1.596.2.4 raeburn 763: unless ($uessay=~/\w+/s) { return ''; }
1.282 www 764:
1.87 www 765: # these will be returned. Do not care if not at least 50 percent similar
1.88 www 766: my $limit=0.6;
1.87 www 767: my $sname='';
768: my $sdom='';
769: my $scrsid='';
770: my $sessay='';
771: # go through all essays ...
1.596.2.12.2. (raeburn 772:): foreach my $tkey (keys(%{$old_essays{$symb}})) {
1.426 albertel 773: my ($tname,$tdom,$tcrsid)=map {&unescape($_)} (split(/\./,$tkey));
1.87 www 774: # ... except the same student
1.426 albertel 775: next if (($tname eq $uname) && ($tdom eq $udom));
1.596.2.12.2. (raeburn 776:): my $tessay=$old_essays{$symb}{$tkey};
1.426 albertel 777: $tessay=~s/\W+/ /gs;
1.87 www 778: # String similarity gives up if not even limit
1.426 albertel 779: my $tsimilar=&String::Similarity::similarity($uessay,$tessay,$limit);
1.87 www 780: # Found one
1.426 albertel 781: if ($tsimilar>$limit) {
782: $limit=$tsimilar;
783: $sname=$tname;
784: $sdom=$tdom;
785: $scrsid=$tcrsid;
1.596.2.12.2. (raeburn 786:): $sessay=$old_essays{$symb}{$tkey};
1.426 albertel 787: }
1.87 www 788: }
1.88 www 789: if ($limit>0.6) {
1.87 www 790: return ($sname,$sdom,$scrsid,$sessay,$limit);
791: } else {
792: return ('','','','',0);
793: }
794: }
795:
1.44 ng 796: #-------------------------------------------------------------------
797:
798: #------------------------------------ Receipt Verification Routines
1.45 ng 799: #
1.44 ng 800: #--- Check whether a receipt number is valid.---
801: sub verifyreceipt {
802: my $request = shift;
803:
1.257 albertel 804: my $courseid = $env{'request.course.id'};
1.184 www 805: my $receipt = &Apache::lonnet::recprefix($courseid).'-'.
1.257 albertel 806: $env{'form.receipt'};
1.44 ng 807: $receipt =~ s/[^\-\d]//g;
1.378 albertel 808: my ($symb) = &get_symb($request);
1.44 ng 809:
1.487 albertel 810: my $title.=
811: '<h3><span class="LC_info">'.
1.584 bisitz 812: &mt('Verifying Receipt No. [_1]',$receipt).
1.487 albertel 813: '</span></h3>'."\n".
814: '<h4>'.&mt('<b>Resource: </b>[_1]',$env{'form.probTitle'}).
815: '</h4>'."\n";
1.44 ng 816:
817: my ($string,$contents,$matches) = ('','',0);
1.56 matthew 818: my (undef,undef,$fullname) = &getclasslist('all','0');
1.177 albertel 819:
820: my $receiptparts=0;
1.390 albertel 821: if ($env{"course.$courseid.receiptalg"} eq 'receipt2' ||
822: $env{"course.$courseid.receiptalg"} eq 'receipt3') { $receiptparts=1; }
1.177 albertel 823: my $parts=['0'];
1.582 raeburn 824: if ($receiptparts) {
825: my $res_error;
826: ($parts)=&response_type($symb,\$res_error);
827: if ($res_error) {
828: return &navmap_errormsg();
829: }
830: }
1.486 albertel 831:
832: my $header =
833: &Apache::loncommon::start_data_table().
834: &Apache::loncommon::start_data_table_header_row().
1.487 albertel 835: '<th> '.&mt('Fullname').' </th>'."\n".
836: '<th> '.&mt('Username').' </th>'."\n".
837: '<th> '.&mt('Domain').' </th>';
1.486 albertel 838: if ($receiptparts) {
1.487 albertel 839: $header.='<th> '.&mt('Problem Part').' </th>';
1.486 albertel 840: }
841: $header.=
842: &Apache::loncommon::end_data_table_header_row();
843:
1.294 albertel 844: foreach (sort
845: {
846: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
847: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
848: }
849: return $a cmp $b;
850: } (keys(%$fullname))) {
1.44 ng 851: my ($uname,$udom)=split(/\:/);
1.177 albertel 852: foreach my $part (@$parts) {
853: if ($receipt eq &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb,$part)) {
1.486 albertel 854: $contents.=
855: &Apache::loncommon::start_data_table_row().
856: '<td> '."\n".
1.177 albertel 857: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 858: '\');" target="_self">'.$$fullname{$_}.'</a> </td>'."\n".
1.177 albertel 859: '<td> '.$uname.' </td>'.
860: '<td> '.$udom.' </td>';
861: if ($receiptparts) {
862: $contents.='<td> '.$part.' </td>';
863: }
1.486 albertel 864: $contents.=
865: &Apache::loncommon::end_data_table_row()."\n";
1.177 albertel 866:
867: $matches++;
868: }
1.44 ng 869: }
870: }
871: if ($matches == 0) {
1.584 bisitz 872: $string = $title
873: .'<p class="LC_warning">'
874: .&mt('No match found for the above receipt number.')
875: .'</p>';
1.44 ng 876: } else {
1.324 albertel 877: $string = &jscriptNform($symb).$title.
1.487 albertel 878: '<p>'.
1.584 bisitz 879: &mt('The above receipt number matches the following [quant,_1,student].',$matches).
1.487 albertel 880: '</p>'.
1.486 albertel 881: $header.
882: $contents.
883: &Apache::loncommon::end_data_table()."\n";
1.44 ng 884: }
1.324 albertel 885: return $string.&show_grading_menu_form($symb);
1.44 ng 886: }
887:
888: #--- This is called by a number of programs.
889: #--- Called from the Grading Menu - View/Grade an individual student
890: #--- Also called directly when one clicks on the subm button
891: # on the problem page.
1.30 ng 892: sub listStudents {
1.41 ng 893: my ($request) = shift;
1.49 albertel 894:
1.324 albertel 895: my ($symb) = &get_symb($request);
1.257 albertel 896: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
897: my $cnum = $env{"course.$env{'request.course.id'}.num"};
898: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.449 banghart 899: my $getgroup = $env{'form.group'} eq '' ? 'all' : $env{'form.group'};
1.257 albertel 900: my $submitonly= $env{'form.submitonly'} eq '' ? 'all' : $env{'form.submitonly'};
1.548 bisitz 901: my $viewgrade = $env{'form.showgrading'} eq 'yes' ? 'View/Grade/Regrade' : 'View';
1.257 albertel 902: $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
903: &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
1.49 albertel 904:
1.548 bisitz 905: my $result='<h3><span class="LC_info"> '
906: .&mt("$viewgrade Submissions for a Student or a Group of Students")
1.485 albertel 907: .'</span></h3>';
1.118 ng 908:
1.324 albertel 909: my ($table,undef,$hdgrade,$partlist,$handgrade) = &showResourceInfo($symb,$env{'form.probTitle'},($env{'form.showgrading'} eq 'yes'));
1.49 albertel 910:
1.559 raeburn 911: my %lt = &Apache::lonlocal::texthash (
912: 'multiple' => 'Please select a student or group of students before clicking on the Next button.',
913: 'single' => 'Please select the student before clicking on the Next button.',
914: );
1.45 ng 915: $request->print(<<LISTJAVASCRIPT);
916: <script type="text/javascript" language="javascript">
1.110 ng 917: function checkSelect(checkBox) {
918: var ctr=0;
919: var sense="";
920: if (checkBox.length > 1) {
921: for (var i=0; i<checkBox.length; i++) {
922: if (checkBox[i].checked) {
923: ctr++;
924: }
925: }
1.485 albertel 926: sense = '$lt{'multiple'}';
1.110 ng 927: } else {
928: if (checkBox.checked) {
929: ctr = 1;
930: }
1.485 albertel 931: sense = '$lt{'single'}';
1.110 ng 932: }
933: if (ctr == 0) {
1.485 albertel 934: alert(sense);
1.110 ng 935: return false;
936: }
937: document.gradesub.submit();
938: }
939:
940: function reLoadList(formname) {
1.112 ng 941: if (formname.saveStatusOld.value == pullDownSelection(formname.Status)) {return;}
1.110 ng 942: formname.command.value = 'submission';
943: formname.submit();
944: }
1.45 ng 945: </script>
946: LISTJAVASCRIPT
947:
1.118 ng 948: &commonJSfunctions($request);
1.41 ng 949: $request->print($result);
1.39 ng 950:
1.401 albertel 951: my $checkhdgrade = ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1 ) ? 'checked="checked"' : '';
952: my $checklastsub = $checkhdgrade eq '' ? 'checked="checked"' : '';
1.154 albertel 953: my $gradeTable='<form action="/adm/grades" method="post" name="gradesub">'.
1.485 albertel 954: "\n".$table;
955:
1.561 bisitz 956: $gradeTable .= &Apache::lonhtmlcommon::start_pick_box();
957: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Problem Text'))
958: .'<label><input type="radio" name="vProb" value="no" checked="checked" /> '.&mt('no').' </label>'."\n"
959: .'<label><input type="radio" name="vProb" value="yes" /> '.&mt('one student').' </label>'."\n"
960: .'<label><input type="radio" name="vProb" value="all" /> '.&mt('all students').' </label><br />'."\n"
961: .&Apache::lonhtmlcommon::row_closure();
962: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Answer'))
963: .'<label><input type="radio" name="vAns" value="no" /> '.&mt('no').' </label>'."\n"
964: .'<label><input type="radio" name="vAns" value="yes" /> '.&mt('one student').' </label>'."\n"
965: .'<label><input type="radio" name="vAns" value="all" checked="checked" /> '.&mt('all students').' </label><br />'."\n"
966: .&Apache::lonhtmlcommon::row_closure();
1.485 albertel 967:
968: my $submission_options;
1.257 albertel 969: if ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1) {
1.485 albertel 970: $submission_options.=
971: '<label><input type="radio" name="lastSub" value="hdgrade" '.$checkhdgrade.' /> '.&mt('essay part only').' </label>'."\n";
1.49 albertel 972: }
1.442 banghart 973: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
974: my $saveStatus = $stu_status eq '' ? 'Active' : $stu_status;
1.257 albertel 975: $env{'form.Status'} = $saveStatus;
1.485 albertel 976: $submission_options.=
1.592 bisitz 977: '<span class="LC_nobreak">'.
978: '<label><input type="radio" name="lastSub" value="lastonly" '.$checklastsub.' /> '.
979: &mt('last submission only').' </label></span>'."\n".
980: '<span class="LC_nobreak">'.
981: '<label><input type="radio" name="lastSub" value="last" /> '.
982: &mt('last submission & parts info').' </label></span>'."\n".
983: '<span class="LC_nobreak">'.
984: '<label><input type="radio" name="lastSub" value="datesub" /> '.
985: &mt('by dates and submissions').'</label></span>'."\n".
986: '<span class="LC_nobreak">'.
987: '<label><input type="radio" name="lastSub" value="all" /> '.
988: &mt('all details').'</label></span>';
1.561 bisitz 989: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Submissions'))
990: .$submission_options
991: .&Apache::lonhtmlcommon::row_closure();
992:
993: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Grading Increments'))
994: .'<select name="increment">'
995: .'<option value="1">'.&mt('Whole Points').'</option>'
996: .'<option value=".5">'.&mt('Half Points').'</option>'
997: .'<option value=".25">'.&mt('Quarter Points').'</option>'
998: .'<option value=".1">'.&mt('Tenths of a Point').'</option>'
999: .'</select>'
1000: .&Apache::lonhtmlcommon::row_closure();
1.485 albertel 1001:
1002: $gradeTable .=
1.432 banghart 1003: &build_section_inputs().
1.45 ng 1004: '<input type="hidden" name="submitonly" value="'.$submitonly.'" />'."\n".
1.257 albertel 1005: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" /><br />'."\n".
1006: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" /><br />'."\n".
1007: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1008: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.418 albertel 1009: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.110 ng 1010: '<input type="hidden" name="saveStatusOld" value="'.$saveStatus.'" />'."\n";
1011:
1.257 albertel 1012: if (exists($env{'form.gradingMenu'}) && exists($env{'form.Status'})) {
1.561 bisitz 1013: $gradeTable .= '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n";
1.124 ng 1014: } else {
1.561 bisitz 1015: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Student Status'))
1016: .&Apache::lonhtmlcommon::StatusOptions(
1017: $saveStatus,undef,1,'javascript:reLoadList(this.form);')
1018: .&Apache::lonhtmlcommon::row_closure();
1.124 ng 1019: }
1.112 ng 1020:
1.561 bisitz 1021: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Check For Plagiarism'))
1022: .'<input type="checkbox" name="checkPlag" checked="checked" />'
1023: .&Apache::lonhtmlcommon::row_closure(1)
1024: .&Apache::lonhtmlcommon::end_pick_box();
1025:
1026: $gradeTable .= '<p>'
1027: .&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"
1028: .'<input type="hidden" name="command" value="processGroup" />'
1029: .'</p>';
1.249 albertel 1030:
1031: # checkall buttons
1032: $gradeTable.=&check_script('gradesub', 'stuinfo');
1.110 ng 1033: $gradeTable.='<input type="button" '."\n".
1.589 bisitz 1034: 'onclick="javascript:checkSelect(this.form.stuinfo);" '."\n".
1035: 'value="'.&mt('Next').' →" /> <br />'."\n";
1.249 albertel 1036: $gradeTable.=&check_buttons();
1.450 banghart 1037: my ($classlist, undef, $fullname) = &getclasslist($getsec,'1',$getgroup);
1.474 albertel 1038: $gradeTable.= &Apache::loncommon::start_data_table().
1039: &Apache::loncommon::start_data_table_header_row();
1.110 ng 1040: my $loop = 0;
1041: while ($loop < 2) {
1.485 albertel 1042: $gradeTable.='<th>'.&mt('No.').'</th><th>'.&mt('Select').'</th>'.
1043: '<th>'.&nameUserString('header').' '.&mt('Section/Group').'</th>';
1.301 albertel 1044: if ($env{'form.showgrading'} eq 'yes'
1045: && $submitonly ne 'queued'
1046: && $submitonly ne 'all') {
1.485 albertel 1047: foreach my $part (sort(@$partlist)) {
1048: my $display_part=
1049: &get_display_part((split(/_/,$part))[0],$symb);
1050: $gradeTable.=
1051: '<th>'.&mt('Part: [_1] Status',$display_part).'</th>';
1.110 ng 1052: }
1.301 albertel 1053: } elsif ($submitonly eq 'queued') {
1.474 albertel 1054: $gradeTable.='<th>'.&mt('Queue Status').' </th>';
1.110 ng 1055: }
1056: $loop++;
1.126 ng 1057: # $gradeTable.='<td></td>' if ($loop%2 ==1);
1.41 ng 1058: }
1.474 albertel 1059: $gradeTable.=&Apache::loncommon::end_data_table_header_row()."\n";
1.41 ng 1060:
1.45 ng 1061: my $ctr = 0;
1.294 albertel 1062: foreach my $student (sort
1063: {
1064: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
1065: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
1066: }
1067: return $a cmp $b;
1068: }
1069: (keys(%$fullname))) {
1.41 ng 1070: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 1071:
1.110 ng 1072: my %status = ();
1.301 albertel 1073:
1074: if ($submitonly eq 'queued') {
1075: my %queue_status =
1076: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
1077: $udom,$uname);
1078: next if (!defined($queue_status{'gradingqueue'}));
1079: $status{'gradingqueue'} = $queue_status{'gradingqueue'};
1080: }
1081:
1082: if ($env{'form.showgrading'} eq 'yes'
1083: && $submitonly ne 'queued'
1084: && $submitonly ne 'all') {
1.324 albertel 1085: (%status) =&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 1086: my $submitted = 0;
1.164 albertel 1087: my $graded = 0;
1.248 albertel 1088: my $incorrect = 0;
1.110 ng 1089: foreach (keys(%status)) {
1.145 albertel 1090: $submitted = 1 if ($status{$_} ne 'nothing');
1.248 albertel 1091: $graded = 1 if ($status{$_} =~ /^ungraded/);
1092: $incorrect = 1 if ($status{$_} =~ /^incorrect/);
1093:
1.110 ng 1094: my ($foo,$partid,$foo1) = split(/\./,$_);
1095: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
1.145 albertel 1096: $submitted = 0;
1.150 albertel 1097: my ($part)=split(/\./,$partid);
1.110 ng 1098: $gradeTable.='<input type="hidden" name="'.
1.150 albertel 1099: $student.':'.$part.':submitted_by" value="'.
1.110 ng 1100: $status{'resource.'.$partid.'.submitted_by'}.'" />';
1101: }
1.41 ng 1102: }
1.248 albertel 1103:
1.156 albertel 1104: next if (!$submitted && ($submitonly eq 'yes' ||
1105: $submitonly eq 'incorrect' ||
1106: $submitonly eq 'graded'));
1.248 albertel 1107: next if (!$graded && ($submitonly eq 'graded'));
1108: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 1109: }
1.34 ng 1110:
1.45 ng 1111: $ctr++;
1.249 albertel 1112: my $section = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
1.452 banghart 1113: my $group = $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1.104 albertel 1114: if ( $perm{'vgr'} eq 'F' ) {
1.474 albertel 1115: if ($ctr%2 ==1) {
1116: $gradeTable.= &Apache::loncommon::start_data_table_row();
1117: }
1.126 ng 1118: $gradeTable.='<td align="right">'.$ctr.' </td>'.
1.563 bisitz 1119: '<td align="center"><label><input type="checkbox" name="stuinfo" value="'.
1.249 albertel 1120: $student.':'.$$fullname{$student}.':::SECTION'.$section.
1121: ') " /> </label></td>'."\n".'<td>'.
1122: &nameUserString(undef,$$fullname{$student},$uname,$udom).
1.474 albertel 1123: ' '.$section.($group ne '' ?'/'.$group:'').'</td>'."\n";
1.110 ng 1124:
1.257 albertel 1125: if ($env{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
1.524 raeburn 1126: foreach (sort(keys(%status))) {
1.485 albertel 1127: next if ($_ =~ /^resource.*?submitted_by$/);
1128: $gradeTable.='<td align="center"> '.&mt($status{$_}).' </td>'."\n";
1.110 ng 1129: }
1.41 ng 1130: }
1.126 ng 1131: # $gradeTable.='<td></td>' if ($ctr%2 ==1);
1.474 albertel 1132: if ($ctr%2 ==0) {
1133: $gradeTable.=&Apache::loncommon::end_data_table_row()."\n";
1134: }
1.41 ng 1135: }
1136: }
1.110 ng 1137: if ($ctr%2 ==1) {
1.126 ng 1138: $gradeTable.='<td> </td><td> </td><td> </td>';
1.301 albertel 1139: if ($env{'form.showgrading'} eq 'yes'
1140: && $submitonly ne 'queued'
1141: && $submitonly ne 'all') {
1.110 ng 1142: foreach (@$partlist) {
1143: $gradeTable.='<td> </td>';
1144: }
1.301 albertel 1145: } elsif ($submitonly eq 'queued') {
1146: $gradeTable.='<td> </td>';
1.110 ng 1147: }
1.474 albertel 1148: $gradeTable.=&Apache::loncommon::end_data_table_row();
1.110 ng 1149: }
1150:
1.474 albertel 1151: $gradeTable.=&Apache::loncommon::end_data_table()."\n".
1.589 bisitz 1152: '<input type="button" '.
1153: 'onclick="javascript:checkSelect(this.form.stuinfo);" '.
1154: 'value="'.&mt('Next').' →" /></form>'."\n";
1.45 ng 1155: if ($ctr == 0) {
1.96 albertel 1156: my $num_students=(scalar(keys(%$fullname)));
1157: if ($num_students eq 0) {
1.485 albertel 1158: $gradeTable='<br /> <span class="LC_warning">'.&mt('There are no students currently enrolled.').'</span>';
1.96 albertel 1159: } else {
1.171 albertel 1160: my $submissions='submissions';
1161: if ($submitonly eq 'incorrect') { $submissions = 'incorrect submissions'; }
1162: if ($submitonly eq 'graded' ) { $submissions = 'ungraded submissions'; }
1.301 albertel 1163: if ($submitonly eq 'queued' ) { $submissions = 'queued submissions'; }
1.398 albertel 1164: $gradeTable='<br /> <span class="LC_warning">'.
1.485 albertel 1165: &mt('No '.$submissions.' found for this resource for any students. ([_1] students checked for '.$submissions.')',
1166: $num_students).
1167: '</span><br />';
1.96 albertel 1168: }
1.46 ng 1169: } elsif ($ctr == 1) {
1.474 albertel 1170: $gradeTable =~ s/type="checkbox"/type="checkbox" checked="checked"/;
1.45 ng 1171: }
1.324 albertel 1172: $gradeTable.=&show_grading_menu_form($symb);
1.45 ng 1173: $request->print($gradeTable);
1.44 ng 1174: return '';
1.10 ng 1175: }
1176:
1.44 ng 1177: #---- Called from the listStudents routine
1.249 albertel 1178:
1179: sub check_script {
1180: my ($form, $type)=@_;
1181: my $chkallscript='<script type="text/javascript">
1182: function checkall() {
1183: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1184: ele = document.forms.'.$form.'.elements[i];
1185: if (ele.name == "'.$type.'") {
1186: document.forms.'.$form.'.elements[i].checked=true;
1187: }
1188: }
1189: }
1190:
1191: function checksec() {
1192: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1193: ele = document.forms.'.$form.'.elements[i];
1194: string = document.forms.'.$form.'.chksec.value;
1195: if
1196: (ele.value.indexOf(":::SECTION"+string)>0) {
1197: document.forms.'.$form.'.elements[i].checked=true;
1198: }
1199: }
1200: }
1201:
1202:
1203: function uncheckall() {
1204: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1205: ele = document.forms.'.$form.'.elements[i];
1206: if (ele.name == "'.$type.'") {
1207: document.forms.'.$form.'.elements[i].checked=false;
1208: }
1209: }
1210: }
1211:
1212: </script>'."\n";
1213: return $chkallscript;
1214: }
1215:
1216: sub check_buttons {
1.485 albertel 1217: my $buttons.='<input type="button" onclick="checkall()" value="'.&mt('Check All').'" />';
1218: $buttons.='<input type="button" onclick="uncheckall()" value="'.&mt('Uncheck All').'" /> ';
1219: $buttons.='<input type="button" onclick="checksec()" value="'.&mt('Check Section/Group').'" />';
1.249 albertel 1220: $buttons.='<input type="text" size="5" name="chksec" /> ';
1221: return $buttons;
1222: }
1223:
1.44 ng 1224: # Displays the submissions for one student or a group of students
1.34 ng 1225: sub processGroup {
1.41 ng 1226: my ($request) = shift;
1227: my $ctr = 0;
1.155 albertel 1228: my @stuchecked = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.41 ng 1229: my $total = scalar(@stuchecked)-1;
1.45 ng 1230:
1.396 banghart 1231: foreach my $student (@stuchecked) {
1232: my ($uname,$udom,$fullname) = split(/:/,$student);
1.257 albertel 1233: $env{'form.student'} = $uname;
1234: $env{'form.userdom'} = $udom;
1235: $env{'form.fullname'} = $fullname;
1.41 ng 1236: &submission($request,$ctr,$total);
1237: $ctr++;
1238: }
1239: return '';
1.35 ng 1240: }
1.34 ng 1241:
1.44 ng 1242: #------------------------------------------------------------------------------------
1243: #
1244: #-------------------------- Next few routines handles grading by student, essentially
1245: # handles essay response type problem/part
1246: #
1247: #--- Javascript to handle the submission page functionality ---
1248: sub sub_page_js {
1249: my $request = shift;
1.539 riegler 1250: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
1.44 ng 1251: $request->print(<<SUBJAVASCRIPT);
1252: <script type="text/javascript" language="javascript">
1.71 ng 1253: function updateRadio(formname,id,weight) {
1.125 ng 1254: var gradeBox = formname["GD_BOX"+id];
1255: var radioButton = formname["RADVAL"+id];
1256: var oldpts = formname["oldpts"+id].value;
1.72 ng 1257: var pts = checkSolved(formname,id) == 'update' ? gradeBox.value : oldpts;
1.71 ng 1258: gradeBox.value = pts;
1259: var resetbox = false;
1260: if (isNaN(pts) || pts < 0) {
1.539 riegler 1261: alert("$alertmsg"+pts);
1.71 ng 1262: for (var i=0; i<radioButton.length; i++) {
1263: if (radioButton[i].checked) {
1264: gradeBox.value = i;
1265: resetbox = true;
1266: }
1267: }
1268: if (!resetbox) {
1269: formtextbox.value = "";
1270: }
1271: return;
1.44 ng 1272: }
1.71 ng 1273:
1274: if (pts > weight) {
1275: var resp = confirm("You entered a value ("+pts+
1276: ") greater than the weight for the part. Accept?");
1277: if (resp == false) {
1.125 ng 1278: gradeBox.value = oldpts;
1.71 ng 1279: return;
1280: }
1.44 ng 1281: }
1.13 albertel 1282:
1.71 ng 1283: for (var i=0; i<radioButton.length; i++) {
1284: radioButton[i].checked=false;
1285: if (pts == i && pts != "") {
1286: radioButton[i].checked=true;
1287: }
1288: }
1289: updateSelect(formname,id);
1.125 ng 1290: formname["stores"+id].value = "0";
1.41 ng 1291: }
1.5 albertel 1292:
1.72 ng 1293: function writeBox(formname,id,pts) {
1.125 ng 1294: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1295: if (checkSolved(formname,id) == 'update') {
1296: gradeBox.value = pts;
1297: } else {
1.125 ng 1298: var oldpts = formname["oldpts"+id].value;
1.72 ng 1299: gradeBox.value = oldpts;
1.125 ng 1300: var radioButton = formname["RADVAL"+id];
1.71 ng 1301: for (var i=0; i<radioButton.length; i++) {
1302: radioButton[i].checked=false;
1.72 ng 1303: if (i == oldpts) {
1.71 ng 1304: radioButton[i].checked=true;
1305: }
1306: }
1.41 ng 1307: }
1.125 ng 1308: formname["stores"+id].value = "0";
1.71 ng 1309: updateSelect(formname,id);
1310: return;
1.41 ng 1311: }
1.44 ng 1312:
1.71 ng 1313: function clearRadBox(formname,id) {
1314: if (checkSolved(formname,id) == 'noupdate') {
1315: updateSelect(formname,id);
1316: return;
1317: }
1.125 ng 1318: gradeSelect = formname["GD_SEL"+id];
1.71 ng 1319: for (var i=0; i<gradeSelect.length; i++) {
1320: if (gradeSelect[i].selected) {
1321: var selectx=i;
1322: }
1323: }
1.125 ng 1324: var stores = formname["stores"+id];
1.71 ng 1325: if (selectx == stores.value) { return };
1.125 ng 1326: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1327: gradeBox.value = "";
1.125 ng 1328: var radioButton = formname["RADVAL"+id];
1.71 ng 1329: for (var i=0; i<radioButton.length; i++) {
1330: radioButton[i].checked=false;
1331: }
1332: stores.value = selectx;
1333: }
1.5 albertel 1334:
1.71 ng 1335: function checkSolved(formname,id) {
1.125 ng 1336: if (formname["solved"+id].value == "correct_by_student" && formname.overRideScore.value == 'no') {
1.118 ng 1337: var reply = confirm("This problem has been graded correct by the computer. Do you want to change the score?");
1338: if (!reply) {return "noupdate";}
1.120 ng 1339: formname.overRideScore.value = 'yes';
1.41 ng 1340: }
1.71 ng 1341: return "update";
1.13 albertel 1342: }
1.71 ng 1343:
1344: function updateSelect(formname,id) {
1.125 ng 1345: formname["GD_SEL"+id][0].selected = true;
1.71 ng 1346: return;
1.41 ng 1347: }
1.33 ng 1348:
1.121 ng 1349: //=========== Check that a point is assigned for all the parts ============
1.71 ng 1350: function checksubmit(formname,val,total,parttot) {
1.121 ng 1351: formname.gradeOpt.value = val;
1.71 ng 1352: if (val == "Save & Next") {
1353: for (i=0;i<=total;i++) {
1354: for (j=0;j<parttot;j++) {
1.125 ng 1355: var partid = formname["partid"+i+"_"+j].value;
1.127 ng 1356: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1357: var points = formname["GD_BOX"+i+"_"+partid].value;
1.71 ng 1358: if (points == "") {
1.125 ng 1359: var name = formname["name"+i].value;
1.129 ng 1360: var studentID = (name != '' ? name : formname["unamedom"+i].value);
1361: var resp = confirm("You did not assign a score for "+studentID+
1362: ", part "+partid+". Continue?");
1.71 ng 1363: if (resp == false) {
1.125 ng 1364: formname["GD_BOX"+i+"_"+partid].focus();
1.71 ng 1365: return false;
1366: }
1367: }
1368: }
1369:
1370: }
1371: }
1372:
1373: }
1.121 ng 1374: if (val == "Grade Student") {
1375: formname.showgrading.value = "yes";
1376: if (formname.Status.value == "") {
1377: formname.Status.value = "Active";
1378: }
1379: formname.studentNo.value = total;
1380: }
1.120 ng 1381: formname.submit();
1382: }
1383:
1.71 ng 1384: //======= Check that a score is assigned for all the problems (page/sequence grading only) =========
1385: function checkSubmitPage(formname,total) {
1386: noscore = new Array(100);
1387: var ptr = 0;
1388: for (i=1;i<total;i++) {
1.125 ng 1389: var partid = formname["q_"+i].value;
1.127 ng 1390: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1391: var points = formname["GD_BOX"+i+"_"+partid].value;
1392: var status = formname["solved"+i+"_"+partid].value;
1.71 ng 1393: if (points == "" && status != "correct_by_student") {
1394: noscore[ptr] = i;
1395: ptr++;
1396: }
1397: }
1398: }
1399: if (ptr != 0) {
1400: var sense = ptr == 1 ? ": " : "s: ";
1401: var prolist = "";
1402: if (ptr == 1) {
1403: prolist = noscore[0];
1404: } else {
1405: var i = 0;
1406: while (i < ptr-1) {
1407: prolist += noscore[i]+", ";
1408: i++;
1409: }
1410: prolist += "and "+noscore[i];
1411: }
1412: var resp = confirm("You did not assign any score for the following problem"+sense+prolist+". Continue?");
1413: if (resp == false) {
1414: return false;
1415: }
1416: }
1.45 ng 1417:
1.71 ng 1418: formname.submit();
1419: }
1420: </script>
1421: SUBJAVASCRIPT
1422: }
1.45 ng 1423:
1.71 ng 1424: #--- javascript for essay type problem --
1425: sub sub_page_kw_js {
1426: my $request = shift;
1.80 ng 1427: my $iconpath = $request->dir_config('lonIconsURL');
1.118 ng 1428: &commonJSfunctions($request);
1.350 albertel 1429:
1.351 albertel 1430: my $inner_js_msg_central=<<INNERJS;
1.350 albertel 1431: <script text="text/javascript">
1432: function checkInput() {
1433: opener.document.SCORE.msgsub.value = opener.checkEntities(document.msgcenter.msgsub.value);
1434: var nmsg = opener.document.SCORE.savemsgN.value;
1435: var usrctr = document.msgcenter.usrctr.value;
1436: var newval = opener.document.SCORE["newmsg"+usrctr];
1437: newval.value = opener.checkEntities(document.msgcenter.newmsg.value);
1438:
1439: var msgchk = "";
1440: if (document.msgcenter.subchk.checked) {
1441: msgchk = "msgsub,";
1442: }
1443: var includemsg = 0;
1444: for (var i=1; i<=nmsg; i++) {
1445: var opnmsg = opener.document.SCORE["savemsg"+i];
1446: var frmmsg = document.msgcenter["msg"+i];
1447: opnmsg.value = opener.checkEntities(frmmsg.value);
1448: var showflg = opener.document.SCORE["shownOnce"+i];
1449: showflg.value = "1";
1450: var chkbox = document.msgcenter["msgn"+i];
1451: if (chkbox.checked) {
1452: msgchk += "savemsg"+i+",";
1453: includemsg = 1;
1454: }
1455: }
1456: if (document.msgcenter.newmsgchk.checked) {
1457: msgchk += "newmsg"+usrctr;
1458: includemsg = 1;
1459: }
1460: imgformname = opener.document.SCORE["mailicon"+usrctr];
1461: imgformname.src = "$iconpath/"+((includemsg) ? "mailto.gif" : "mailbkgrd.gif");
1462: var includemsg = opener.document.SCORE["includemsg"+usrctr];
1463: includemsg.value = msgchk;
1464:
1465: self.close()
1466:
1467: }
1468: </script>
1469: INNERJS
1470:
1.351 albertel 1471: my $inner_js_highlight_central=<<INNERJS;
1472: <script type="text/javascript">
1473: function updateChoice(flag) {
1474: opener.document.SCORE.kwclr.value = opener.radioSelection(document.hlCenter.kwdclr);
1475: opener.document.SCORE.kwsize.value = opener.radioSelection(document.hlCenter.kwdsize);
1476: opener.document.SCORE.kwstyle.value = opener.radioSelection(document.hlCenter.kwdstyle);
1477: opener.document.SCORE.refresh.value = "on";
1478: if (opener.document.SCORE.keywords.value!=""){
1479: opener.document.SCORE.submit();
1480: }
1481: self.close()
1482: }
1483: </script>
1484: INNERJS
1485:
1486: my $start_page_msg_central =
1487: &Apache::loncommon::start_page('Message Central',$inner_js_msg_central,
1488: {'js_ready' => 1,
1489: 'only_body' => 1,
1490: 'bgcolor' =>'#FFFFFF',});
1491: my $end_page_msg_central =
1492: &Apache::loncommon::end_page({'js_ready' => 1});
1493:
1494:
1495: my $start_page_highlight_central =
1496: &Apache::loncommon::start_page('Highlight Central',
1497: $inner_js_highlight_central,
1.350 albertel 1498: {'js_ready' => 1,
1499: 'only_body' => 1,
1500: 'bgcolor' =>'#FFFFFF',});
1.351 albertel 1501: my $end_page_highlight_central =
1.350 albertel 1502: &Apache::loncommon::end_page({'js_ready' => 1});
1503:
1.219 www 1504: my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
1.236 albertel 1505: $docopen=~s/^document\.//;
1.596.2.4 raeburn 1506: my %lt = &Apache::lonlocal::texthash(
1507: keyw => 'Keywords list, separated by a space. Add/delete to list if desired.',
1508: plse => 'Please select a word or group of words from document and then click this link.',
1509: adds => 'Add selection to keyword list? Edit if desired.',
1510: comp => 'Compose Message for: ',
1511: incl => 'Include',
1512: type => 'Type',
1513: subj => 'Subject',
1514: mesa => 'Message',
1515: new => 'New',
1516: save => 'Save',
1517: canc => 'Cancel',
1518: kehi => 'Keyword Highlight Options',
1519: txtc => 'Text Color',
1520: font => 'Font Size',
1521: fnst => 'Font Style',
1522: );
1.71 ng 1523: $request->print(<<SUBJAVASCRIPT);
1524: <script type="text/javascript" language="javascript">
1.45 ng 1525:
1.44 ng 1526: //===================== Show list of keywords ====================
1.122 ng 1527: function keywords(formname) {
1.596.2.4 raeburn 1528: var nret = prompt("$lt{'keyw'}",formname.keywords.value);
1.44 ng 1529: if (nret==null) return;
1.122 ng 1530: formname.keywords.value = nret;
1.44 ng 1531:
1.122 ng 1532: if (formname.keywords.value != "") {
1.128 ng 1533: formname.refresh.value = "on";
1.122 ng 1534: formname.submit();
1.44 ng 1535: }
1536: return;
1537: }
1538:
1539: //===================== Script to view submitted by ==================
1540: function viewSubmitter(submitter) {
1541: document.SCORE.refresh.value = "on";
1542: document.SCORE.NCT.value = "1";
1543: document.SCORE.unamedom0.value = submitter;
1544: document.SCORE.submit();
1545: return;
1546: }
1547:
1548: //===================== Script to add keyword(s) ==================
1549: function getSel() {
1550: if (document.getSelection) txt = document.getSelection();
1551: else if (document.selection) txt = document.selection.createRange().text;
1552: else return;
1553: var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
1554: if (cleantxt=="") {
1.596.2.4 raeburn 1555: alert("$lt{'plse'}");
1.44 ng 1556: return;
1557: }
1.596.2.4 raeburn 1558: var nret = prompt("$lt{'adds'}",cleantxt);
1.44 ng 1559: if (nret==null) return;
1.127 ng 1560: document.SCORE.keywords.value = document.SCORE.keywords.value+" "+nret;
1.44 ng 1561: if (document.SCORE.keywords.value != "") {
1.127 ng 1562: document.SCORE.refresh.value = "on";
1.44 ng 1563: document.SCORE.submit();
1564: }
1565: return;
1566: }
1567:
1568: //====================== Script for composing message ==============
1.80 ng 1569: // preload images
1570: img1 = new Image();
1571: img1.src = "$iconpath/mailbkgrd.gif";
1572: img2 = new Image();
1573: img2.src = "$iconpath/mailto.gif";
1574:
1.44 ng 1575: function msgCenter(msgform,usrctr,fullname) {
1576: var Nmsg = msgform.savemsgN.value;
1577: savedMsgHeader(Nmsg,usrctr,fullname);
1578: var subject = msgform.msgsub.value;
1.127 ng 1579: var msgchk = document.SCORE["includemsg"+usrctr].value;
1.44 ng 1580: re = /msgsub/;
1581: var shwsel = "";
1582: if (re.test(msgchk)) { shwsel = "checked" }
1.123 ng 1583: subject = (document.SCORE.shownSub.value == 0 ? checkEntities(subject) : subject);
1584: displaySubject(checkEntities(subject),shwsel);
1.44 ng 1585: for (var i=1; i<=Nmsg; i++) {
1.123 ng 1586: var testmsg = "savemsg"+i+",";
1587: re = new RegExp(testmsg,"g");
1.44 ng 1588: shwsel = "";
1589: if (re.test(msgchk)) { shwsel = "checked" }
1.125 ng 1590: var message = document.SCORE["savemsg"+i].value;
1.126 ng 1591: message = (document.SCORE["shownOnce"+i].value == 0 ? checkEntities(message) : message);
1.123 ng 1592: displaySavedMsg(i,message,shwsel); //I do not get it. w/o checkEntities on saved messages,
1593: //any < is already converted to <, etc. However, only once!!
1.44 ng 1594: }
1.125 ng 1595: newmsg = document.SCORE["newmsg"+usrctr].value;
1.44 ng 1596: shwsel = "";
1597: re = /newmsg/;
1598: if (re.test(msgchk)) { shwsel = "checked" }
1599: newMsg(newmsg,shwsel);
1600: msgTail();
1601: return;
1602: }
1603:
1.123 ng 1604: function checkEntities(strx) {
1605: if (strx.length == 0) return strx;
1606: var orgStr = ["&", "<", ">", '"'];
1607: var newStr = ["&", "<", ">", """];
1608: var counter = 0;
1609: while (counter < 4) {
1610: strx = strReplace(strx,orgStr[counter],newStr[counter]);
1611: counter++;
1612: }
1613: return strx;
1614: }
1615:
1616: function strReplace(strx, orgStr, newStr) {
1617: return strx.split(orgStr).join(newStr);
1618: }
1619:
1.44 ng 1620: function savedMsgHeader(Nmsg,usrctr,fullname) {
1.76 ng 1621: var height = 70*Nmsg+250;
1.44 ng 1622: if (height > 600) {
1623: height = 600;
1624: }
1.118 ng 1625: var xpos = (screen.width-600)/2;
1626: xpos = (xpos < 0) ? '0' : xpos;
1627: var ypos = (screen.height-height)/2-30;
1628: ypos = (ypos < 0) ? '0' : ypos;
1629:
1.596.2.12.2. (raeburn 1630:): pWin = window.open('', 'MessageCenter', 'resizable=yes,toolbar=no,location=no,scrollbars=yes,screenx='+xpos+',screeny='+ypos+',width=700,height='+height);
1.76 ng 1631: pWin.focus();
1632: pDoc = pWin.document;
1.219 www 1633: pDoc.$docopen;
1.351 albertel 1634: pDoc.write('$start_page_msg_central');
1.76 ng 1635:
1636: pDoc.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
1637: pDoc.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
1.596.2.4 raeburn 1638: pDoc.write("<h3><span class=\\"LC_info\\"> $lt{'comp'}\"+fullname+\"<\\/span><\\/h3><br /><br />");
1.76 ng 1639:
1.564 bisitz 1640: pDoc.write('<table border="0" width="100%"><tr><td bgcolor="#777777">');
1641: pDoc.write('<table border="0" width="100%"><tr bgcolor="#DDFFFF">');
1.596.2.4 raeburn 1642: pDoc.write("<td><b>$lt{'type'}<\\/b><\\/td><td><b>$lt{'incl'}<\\/b><\\/td><td><b>$lt{'mesa'}<\\/td><\\/tr>");
1.44 ng 1643: }
1644: function displaySubject(msg,shwsel) {
1.76 ng 1645: pDoc = pWin.document;
1646: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.596.2.4 raeburn 1647: pDoc.write("<td>$lt{'subj'}<\\/td>");
1.465 albertel 1648: pDoc.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1649: pDoc.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+"\\"size=\\"60\\" maxlength=\\"80\\"><\\/td><\\/tr>");
1.44 ng 1650: }
1651:
1.72 ng 1652: function displaySavedMsg(ctr,msg,shwsel) {
1.76 ng 1653: pDoc = pWin.document;
1654: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.465 albertel 1655: pDoc.write("<td align=\\"center\\">"+ctr+"<\\/td>");
1656: pDoc.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1657: pDoc.write("<td><textarea name=\\"msg"+ctr+"\\" cols=\\"60\\" rows=\\"3\\">"+msg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 1658: }
1659:
1660: function newMsg(newmsg,shwsel) {
1.76 ng 1661: pDoc = pWin.document;
1662: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.596.2.4 raeburn 1663: pDoc.write("<td align=\\"center\\">$lt{'new'}<\\/td>");
1.465 albertel 1664: pDoc.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1665: pDoc.write("<td><textarea name=\\"newmsg\\" cols=\\"60\\" rows=\\"3\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" >"+newmsg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 1666: }
1667:
1668: function msgTail() {
1.76 ng 1669: pDoc = pWin.document;
1.465 albertel 1670: pDoc.write("<\\/table>");
1671: pDoc.write("<\\/td><\\/tr><\\/table> ");
1.596.2.4 raeburn 1672: pDoc.write("<input type=\\"button\\" value=\\"$lt{'save'}\\" onclick=\\"javascript:checkInput()\\"> ");
1673: pDoc.write("<input type=\\"button\\" value=\\"$lt{'canc'}\\" onclick=\\"self.close()\\"><br /><br />");
1.465 albertel 1674: pDoc.write("<\\/form>");
1.351 albertel 1675: pDoc.write('$end_page_msg_central');
1.128 ng 1676: pDoc.close();
1.44 ng 1677: }
1678:
1679: //====================== Script for keyword highlight options ==============
1680: function kwhighlight() {
1681: var kwclr = document.SCORE.kwclr.value;
1682: var kwsize = document.SCORE.kwsize.value;
1683: var kwstyle = document.SCORE.kwstyle.value;
1684: var redsel = "";
1685: var grnsel = "";
1686: var blusel = "";
1687: if (kwclr=="red") {var redsel="checked"};
1688: if (kwclr=="green") {var grnsel="checked"};
1689: if (kwclr=="blue") {var blusel="checked"};
1690: var sznsel = "";
1691: var sz1sel = "";
1692: var sz2sel = "";
1693: if (kwsize=="0") {var sznsel="checked"};
1694: if (kwsize=="+1") {var sz1sel="checked"};
1695: if (kwsize=="+2") {var sz2sel="checked"};
1696: var synsel = "";
1697: var syisel = "";
1698: var sybsel = "";
1699: if (kwstyle=="") {var synsel="checked"};
1700: if (kwstyle=="<i>") {var syisel="checked"};
1701: if (kwstyle=="<b>") {var sybsel="checked"};
1702: highlightCentral();
1703: highlightbody('red','red',redsel,'0','normal',sznsel,'','normal',synsel);
1704: highlightbody('green','green',grnsel,'+1','+1',sz1sel,'<i>','italic',syisel);
1705: highlightbody('blue','blue',blusel,'+2','+2',sz2sel,'<b>','bold',sybsel);
1706: highlightend();
1707: return;
1708: }
1709:
1710: function highlightCentral() {
1.76 ng 1711: // if (window.hwdWin) window.hwdWin.close();
1.118 ng 1712: var xpos = (screen.width-400)/2;
1713: xpos = (xpos < 0) ? '0' : xpos;
1714: var ypos = (screen.height-330)/2-30;
1715: ypos = (ypos < 0) ? '0' : ypos;
1716:
1.206 albertel 1717: hwdWin = window.open('', 'KeywordHighlightCentral', 'resizeable=yes,toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx='+xpos+',screeny='+ypos);
1.76 ng 1718: hwdWin.focus();
1719: var hDoc = hwdWin.document;
1.219 www 1720: hDoc.$docopen;
1.351 albertel 1721: hDoc.write('$start_page_highlight_central');
1.76 ng 1722: hDoc.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
1.596.2.4 raeburn 1723: hDoc.write("<h3><span class=\\"LC_info\\"> $lt{'kehi'}<\\/span><\\/h3><br /><br />");
1.76 ng 1724:
1.564 bisitz 1725: hDoc.write('<table border="0" width="100%"><tr><td bgcolor="#777777">');
1726: hDoc.write('<table border="0" width="100%"><tr bgcolor="#DDFFFF">');
1.596.2.4 raeburn 1727: hDoc.write("<td><b>$lt{'txtc'}<\\/b><\\/td><td><b>$lt{'font'}<\\/b><\\/td><td><b>$lt{'fnst'}<\\/td><\\/tr>");
1.44 ng 1728: }
1729:
1730: function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) {
1.76 ng 1731: var hDoc = hwdWin.document;
1732: hDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1733: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1734: hDoc.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+"> "+clrtxt+"<\\/td>");
1.76 ng 1735: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1736: hDoc.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+"> "+sztxt+"<\\/td>");
1.76 ng 1737: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1738: hDoc.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+"> "+sytxt+"<\\/td>");
1739: hDoc.write("<\\/tr>");
1.44 ng 1740: }
1741:
1742: function highlightend() {
1.76 ng 1743: var hDoc = hwdWin.document;
1.465 albertel 1744: hDoc.write("<\\/table>");
1745: hDoc.write("<\\/td><\\/tr><\\/table> ");
1.596.2.4 raeburn 1746: hDoc.write("<input type=\\"button\\" value=\\"$lt{'save'}\\" onclick=\\"javascript:updateChoice(1)\\"> ");
1747: hDoc.write("<input type=\\"button\\" value=\\"$lt{'canc'}\\" onclick=\\"self.close()\\"><br /><br />");
1.465 albertel 1748: hDoc.write("<\\/form>");
1.351 albertel 1749: hDoc.write('$end_page_highlight_central');
1.128 ng 1750: hDoc.close();
1.44 ng 1751: }
1752:
1753: </script>
1754: SUBJAVASCRIPT
1755: }
1756:
1.349 albertel 1757: sub get_increment {
1.348 bowersj2 1758: my $increment = $env{'form.increment'};
1759: if ($increment != 1 && $increment != .5 && $increment != .25 &&
1760: $increment != .1) {
1761: $increment = 1;
1762: }
1763: return $increment;
1764: }
1765:
1.585 bisitz 1766: sub gradeBox_start {
1767: return (
1768: &Apache::loncommon::start_data_table()
1769: .&Apache::loncommon::start_data_table_header_row()
1770: .'<th>'.&mt('Part').'</th>'
1771: .'<th>'.&mt('Points').'</th>'
1772: .'<th> </th>'
1773: .'<th>'.&mt('Assign Grade').'</th>'
1774: .'<th>'.&mt('Weight').'</th>'
1775: .'<th>'.&mt('Grade Status').'</th>'
1776: .&Apache::loncommon::end_data_table_header_row()
1777: );
1778: }
1779:
1780: sub gradeBox_end {
1781: return (
1782: &Apache::loncommon::end_data_table()
1783: );
1784: }
1.71 ng 1785: #--- displays the grading box, used in essay type problem and grading by page/sequence
1786: sub gradeBox {
1.322 albertel 1787: my ($request,$symb,$uname,$udom,$counter,$partid,$record) = @_;
1.381 albertel 1788: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 1789: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 1790: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
1.466 albertel 1791: my $wgtmsg = ($wgt > 0) ? &mt('(problem weight)')
1792: : '<span class="LC_info">'.&mt('problem weight assigned by computer').'</span>';
1.71 ng 1793: $wgt = ($wgt > 0 ? $wgt : '1');
1794: my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
1.320 albertel 1795: '' : &compute_points($$record{'resource.'.$partid.'.awarded'},$wgt));
1.71 ng 1796: my $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />'."\n";
1.466 albertel 1797: my $display_part= &get_display_part($partid,$symb);
1.270 albertel 1798: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
1799: [$partid]);
1800: my $aggtries = $$record{'resource.'.$partid.'.tries'};
1.269 raeburn 1801: if ($last_resets{$partid}) {
1802: $aggtries = &get_num_tries($record,$last_resets{$partid},$partid);
1803: }
1.585 bisitz 1804: $result.=&Apache::loncommon::start_data_table_row();
1.71 ng 1805: my $ctr = 0;
1.348 bowersj2 1806: my $thisweight = 0;
1.349 albertel 1807: my $increment = &get_increment();
1.485 albertel 1808:
1809: my $radio.='<table border="0"><tr>'."\n"; # display radio buttons in a nice table 10 across
1.348 bowersj2 1810: while ($thisweight<=$wgt) {
1.532 bisitz 1811: $radio.= '<td><span class="LC_nobreak"><label><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
1.589 bisitz 1812: 'onclick="javascript:writeBox(this.form,\''.$counter.'_'.$partid.'\','.
1.348 bowersj2 1813: $thisweight.')" value="'.$thisweight.'" '.
1.401 albertel 1814: ($score eq $thisweight ? 'checked="checked"':'').' /> '.$thisweight."</label></span></td>\n";
1.485 albertel 1815: $radio.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1.348 bowersj2 1816: $thisweight += $increment;
1.71 ng 1817: $ctr++;
1818: }
1.485 albertel 1819: $radio.='</tr></table>';
1820:
1821: my $line.='<input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
1.71 ng 1822: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
1.589 bisitz 1823: 'onchange="javascript:updateRadio(this.form,\''.$counter.'_'.$partid.'\','.
1.71 ng 1824: $wgt.')" /></td>'."\n";
1.485 albertel 1825: $line.='<td>/'.$wgt.' '.$wgtmsg.
1.71 ng 1826: ($$record{'resource.'.$partid.'.solved'} eq 'correct_by_student' ? ' '.$checkIcon : '').
1.585 bisitz 1827: ' </td>'."\n";
1828: $line.='<td><select name="GD_SEL'.$counter.'_'.$partid.'" '.
1.589 bisitz 1829: 'onchange="javascript:clearRadBox(this.form,\''.$counter.'_'.$partid.'\')" >'."\n";
1.71 ng 1830: if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
1.485 albertel 1831: $line.='<option></option>'.
1832: '<option value="excused" selected="selected">'.&mt('excused').'</option>';
1.71 ng 1833: } else {
1.485 albertel 1834: $line.='<option selected="selected"></option>'.
1835: '<option value="excused" >'.&mt('excused').'</option>';
1.71 ng 1836: }
1.485 albertel 1837: $line.='<option value="reset status">'.&mt('reset status').'</option></select>'."\n";
1838:
1839:
1840: $result .=
1.585 bisitz 1841: '<td>'.$display_part.'</td><td>'.$radio.'</td><td>'.&mt('or').'</td><td>'.$line.'</td>';
1842: $result.=&Apache::loncommon::end_data_table_row();
1.71 ng 1843: $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="" />'."\n".
1844: '<input type="hidden" name="oldpts'.$counter.'_'.$partid.'" value="'.$score.'" />'."\n".
1845: '<input type="hidden" name="solved'.$counter.'_'.$partid.'" value="'.
1.269 raeburn 1846: $$record{'resource.'.$partid.'.solved'}.'" />'."\n".
1847: '<input type="hidden" name="totaltries'.$counter.'_'.$partid.'" value="'.
1848: $$record{'resource.'.$partid.'.tries'}.'" />'."\n".
1849: '<input type="hidden" name="aggtries'.$counter.'_'.$partid.'" value="'.
1850: $aggtries.'" />'."\n";
1.582 raeburn 1851: my $res_error;
1852: $result.=&handback_box($symb,$uname,$udom,$counter,$partid,$record,\$res_error);
1853: if ($res_error) {
1854: return &navmap_errormsg();
1855: }
1.318 banghart 1856: return $result;
1857: }
1.322 albertel 1858:
1859: sub handback_box {
1.582 raeburn 1860: my ($symb,$uname,$udom,$counter,$partid,$record,$res_error) = @_;
1861: my ($partlist,$handgrade,$responseType) = &response_type($symb,$res_error);
1.323 banghart 1862: my (@respids);
1.596.2.4 raeburn 1863: my @part_response_id = &flatten_responseType($responseType);
1.375 albertel 1864: foreach my $part_response_id (@part_response_id) {
1865: my ($part,$resp) = @{ $part_response_id };
1.323 banghart 1866: if ($part eq $partid) {
1.375 albertel 1867: push(@respids,$resp);
1.323 banghart 1868: }
1869: }
1.318 banghart 1870: my $result;
1.323 banghart 1871: foreach my $respid (@respids) {
1.322 albertel 1872: my $prefix = $counter.'_'.$partid.'_'.$respid.'_';
1873: my $files=&get_submitted_files($udom,$uname,$partid,$respid,$record);
1874: next if (!@$files);
1.596.2.4 raeburn 1875: my $file_counter = 0;
1.313 banghart 1876: foreach my $file (@$files) {
1.368 banghart 1877: if ($file =~ /\/portfolio\//) {
1.596.2.4 raeburn 1878: $file_counter++;
1.368 banghart 1879: my ($file_path, $file_disp) = ($file =~ m|(.+/)(.+)$|);
1880: my ($name,$version,$ext) = &file_name_version_ext($file_disp);
1881: $file_disp = "$name.$ext";
1882: $file = $file_path.$file_disp;
1883: $result.=&mt('Return commented version of [_1] to student.',
1884: '<span class="LC_filename">'.$file_disp.'</span>');
1885: $result.='<input type="file" name="'.$prefix.'returndoc'.$file_counter.'" />'."\n";
1.596.2.4 raeburn 1886: $result.='<input type="hidden" name="'.$prefix.'origdoc'.$file_counter.'" value="'.$file.'" /><br />'."\n";
1.368 banghart 1887: }
1.322 albertel 1888: }
1.596.2.4 raeburn 1889: if ($file_counter) {
1890: $result .= '<input type="hidden" name="'.$prefix.'countreturndoc" value="'.$file_counter.'" />'."\n".
1891: '<span class="LC_info">'.
1892: '('.&mt('File(s) will be uploaded when you click on Save & Next below.',$file_counter).')</span><br /><br />';
1893: }
1.313 banghart 1894: }
1.318 banghart 1895: return $result;
1.71 ng 1896: }
1.44 ng 1897:
1.58 albertel 1898: sub show_problem {
1.382 albertel 1899: my ($request,$symb,$uname,$udom,$removeform,$viewon,$mode,$form) = @_;
1.144 albertel 1900: my $rendered;
1.382 albertel 1901: my %form = ((ref($form) eq 'HASH')? %{$form} : ());
1.329 albertel 1902: &Apache::lonxml::remember_problem_counter();
1.144 albertel 1903: if ($mode eq 'both' or $mode eq 'text') {
1904: $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
1.382 albertel 1905: $env{'request.course.id'},
1906: undef,\%form);
1.144 albertel 1907: }
1.58 albertel 1908: if ($removeform) {
1909: $rendered=~s|<form(.*?)>||g;
1910: $rendered=~s|</form>||g;
1.374 albertel 1911: $rendered=~s|(<input[^>]*name\s*=\s*"?)(\w+)("?)|$1would_have_been_$2$3|g;
1.58 albertel 1912: }
1.144 albertel 1913: my $companswer;
1914: if ($mode eq 'both' or $mode eq 'answer') {
1.329 albertel 1915: &Apache::lonxml::restore_problem_counter();
1.382 albertel 1916: $companswer=
1917: &Apache::loncommon::get_student_answers($symb,$uname,$udom,
1918: $env{'request.course.id'},
1919: %form);
1.144 albertel 1920: }
1.58 albertel 1921: if ($removeform) {
1922: $companswer=~s|<form(.*?)>||g;
1923: $companswer=~s|</form>||g;
1.144 albertel 1924: $companswer=~s|name="submit"|name="would_have_been_submit"|g;
1.58 albertel 1925: }
1.596.2.12.2. (raeburn 1926:): my $renderheading = &mt('View of the problem');
1927:): my $answerheading = &mt('Correct answer');
1928:): if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1929:): my $stu_fullname = $env{'form.fullname'};
1930:): if ($stu_fullname eq '') {
1931:): $stu_fullname = &Apache::loncommon::plainname($uname,$udom,'lastname');
1932:): }
1933:): my $forwhom = &nameUserString(undef,$stu_fullname,$uname,$udom);
1934:): if ($forwhom ne '') {
1935:): $renderheading = &mt('View of the problem for[_1]',$forwhom);
1936:): $answerheading = &mt('Correct answer for[_1]',$forwhom);
1937:): }
1938:): }
1.468 albertel 1939: $rendered=
1.588 bisitz 1940: '<div class="LC_Box">'
1.596.2.12.2. (raeburn 1941:): .'<h3 class="LC_hcell">'.$renderheading.'</h3>'
1.588 bisitz 1942: .$rendered
1943: .'</div>';
1.468 albertel 1944: $companswer=
1.588 bisitz 1945: '<div class="LC_Box">'
1.596.2.12.2. (raeburn 1946:): .'<h3 class="LC_hcell">'.$answerheading.'</h3>'
1.588 bisitz 1947: .$companswer
1948: .'</div>';
1.468 albertel 1949: my $result;
1.144 albertel 1950: if ($mode eq 'both') {
1.588 bisitz 1951: $result=$rendered.$companswer;
1.144 albertel 1952: } elsif ($mode eq 'text') {
1.588 bisitz 1953: $result=$rendered;
1.144 albertel 1954: } elsif ($mode eq 'answer') {
1.588 bisitz 1955: $result=$companswer;
1.144 albertel 1956: }
1.71 ng 1957: return $result;
1.58 albertel 1958: }
1.397 albertel 1959:
1.396 banghart 1960: sub files_exist {
1961: my ($r, $symb) = @_;
1962: my @students = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.397 albertel 1963:
1.396 banghart 1964: foreach my $student (@students) {
1965: my ($uname,$udom,$fullname) = split(/:/,$student);
1.397 albertel 1966: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1967: $udom,$uname);
1.396 banghart 1968: my ($string,$timestamp)= &get_last_submission(\%record);
1.397 albertel 1969: foreach my $submission (@$string) {
1970: my ($partid,$respid) =
1971: ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
1972: my $files=&get_submitted_files($udom,$uname,$partid,$respid,
1973: \%record);
1974: return 1 if (@$files);
1.396 banghart 1975: }
1976: }
1.397 albertel 1977: return 0;
1.396 banghart 1978: }
1.397 albertel 1979:
1.394 banghart 1980: sub download_all_link {
1981: my ($r,$symb) = @_;
1.395 albertel 1982: my $all_students =
1983: join("\n", &Apache::loncommon::get_env_multiple('form.stuinfo'));
1984:
1985: my $parts =
1986: join("\n",&Apache::loncommon::get_env_multiple('form.vPart'));
1987:
1.394 banghart 1988: my $identifier = &Apache::loncommon::get_cgi_id();
1.514 raeburn 1989: &Apache::lonnet::appenv({'cgi.'.$identifier.'.students' => $all_students,
1990: 'cgi.'.$identifier.'.symb' => $symb,
1991: 'cgi.'.$identifier.'.parts' => $parts,});
1.395 albertel 1992: $r->print('<a href="/cgi-bin/multidownload.pl?'.$identifier.'">'.
1993: &mt('Download All Submitted Documents').'</a>');
1.394 banghart 1994: return
1995: }
1.395 albertel 1996:
1.432 banghart 1997: sub build_section_inputs {
1998: my $section_inputs;
1999: if ($env{'form.section'} eq '') {
2000: $section_inputs .= '<input type="hidden" name="section" value="all" />'."\n";
2001: } else {
2002: my @sections = &Apache::loncommon::get_env_multiple('form.section');
1.434 albertel 2003: foreach my $section (@sections) {
1.432 banghart 2004: $section_inputs .= '<input type="hidden" name="section" value="'.$section.'" />'."\n";
2005: }
2006: }
2007: return $section_inputs;
2008: }
2009:
1.44 ng 2010: # --------------------------- show submissions of a student, option to grade
2011: sub submission {
2012: my ($request,$counter,$total) = @_;
1.257 albertel 2013: my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
2014: $udom = ($udom eq '' ? $env{'user.domain'} : $udom); #has form.userdom changed for a student?
2015: my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
2016: $env{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $env{'form.fullname'} eq '';
1.596.2.12.2. (raeburn 2017:): my ($symb) = &get_symb($request);
1.324 albertel 2018: if ($symb eq '') { $request->print("Unable to handle ambiguous references:."); return ''; }
1.104 albertel 2019:
2020: if (!&canview($usec)) {
1.398 albertel 2021: $request->print('<span class="LC_warning">Unable to view requested student.('.
2022: $uname.':'.$udom.' in section '.$usec.' in course id '.
2023: $env{'request.course.id'}.')</span>');
1.324 albertel 2024: $request->print(&show_grading_menu_form($symb));
1.104 albertel 2025: return;
2026: }
2027:
1.257 albertel 2028: if (!$env{'form.lastSub'}) { $env{'form.lastSub'} = 'datesub'; }
2029: if (!$env{'form.vProb'}) { $env{'form.vProb'} = 'yes'; }
2030: if (!$env{'form.vAns'}) { $env{'form.vAns'} = 'yes'; }
2031: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.381 albertel 2032: my $checkIcon = '<img alt="'.&mt('Check Mark').
2033: '" src="'.$request->dir_config('lonIconsURL').
1.122 ng 2034: '/check.gif" height="16" border="0" />';
1.41 ng 2035:
2036: # header info
2037: if ($counter == 0) {
2038: &sub_page_js($request);
1.257 albertel 2039: &sub_page_kw_js($request) if ($env{'form.handgrade'} eq 'yes');
2040: $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
2041: &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
1.397 albertel 2042: if ($env{'form.handgrade'} eq 'yes' && &files_exist($request, $symb)) {
1.396 banghart 2043: &download_all_link($request, $symb);
2044: }
1.485 albertel 2045: $request->print('<h3> <span class="LC_info">'.&mt('Submission Record').'</span></h3>'."\n".
2046: '<h4> '.&mt('<b>Resource: </b> [_1]',$env{'form.probTitle'}).'</h4>'."\n");
1.118 ng 2047:
1.44 ng 2048: # option to display problem, only once else it cause problems
2049: # with the form later since the problem has a form.
1.257 albertel 2050: if ($env{'form.vProb'} eq 'yes' or $env{'form.vAns'} eq 'yes') {
1.144 albertel 2051: my $mode;
1.257 albertel 2052: if ($env{'form.vProb'} eq 'yes' && $env{'form.vAns'} eq 'yes') {
1.144 albertel 2053: $mode='both';
1.257 albertel 2054: } elsif ($env{'form.vProb'} eq 'yes') {
1.144 albertel 2055: $mode='text';
1.257 albertel 2056: } elsif ($env{'form.vAns'} eq 'yes') {
1.144 albertel 2057: $mode='answer';
2058: }
1.329 albertel 2059: &Apache::lonxml::clear_problem_counter();
1.144 albertel 2060: $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
1.41 ng 2061: }
1.441 www 2062:
1.44 ng 2063: # kwclr is the only variable that is guaranteed to be non blank
2064: # if this subroutine has been called once.
1.41 ng 2065: my %keyhash = ();
1.257 albertel 2066: if ($env{'form.kwclr'} eq '' && $env{'form.handgrade'} eq 'yes') {
1.41 ng 2067: %keyhash = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 2068: $env{'course.'.$env{'request.course.id'}.'.domain'},
2069: $env{'course.'.$env{'request.course.id'}.'.num'});
1.41 ng 2070:
1.257 albertel 2071: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
2072: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
2073: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
2074: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
2075: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
2076: $env{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
2077: $keyhash{$symb.'_subject'} : $env{'form.probTitle'};
2078: $env{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1.41 ng 2079: }
1.257 albertel 2080: my $overRideScore = $env{'form.overRideScore'} eq '' ? 'no' : $env{'form.overRideScore'};
1.442 banghart 2081: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.303 banghart 2082: $request->print('<form action="/adm/grades" method="post" name="SCORE" enctype="multipart/form-data">'."\n".
1.41 ng 2083: '<input type="hidden" name="command" value="handgrade" />'."\n".
1.257 albertel 2084: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.442 banghart 2085: '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.120 ng 2086: '<input type="hidden" name="overRideScore" value="'.$overRideScore.'" />'."\n".
1.257 albertel 2087: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.41 ng 2088: '<input type="hidden" name="refresh" value="off" />'."\n".
1.120 ng 2089: '<input type="hidden" name="studentNo" value="" />'."\n".
2090: '<input type="hidden" name="gradeOpt" value="" />'."\n".
1.418 albertel 2091: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 2092: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" />'."\n".
2093: '<input type="hidden" name="vProb" value="'.$env{'form.vProb'}.'" />'."\n".
2094: '<input type="hidden" name="vAns" value="'.$env{'form.vAns'}.'" />'."\n".
2095: '<input type="hidden" name="lastSub" value="'.$env{'form.lastSub'}.'" />'."\n".
1.432 banghart 2096: &build_section_inputs().
1.326 albertel 2097: '<input type="hidden" name="submitonly" value="'.$env{'form.submitonly'}.'" />'."\n".
2098: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" />'."\n".
1.41 ng 2099: '<input type="hidden" name="NCT"'.
1.257 albertel 2100: ' value="'.($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : $total+1).'" />'."\n");
2101: if ($env{'form.handgrade'} eq 'yes') {
2102: $request->print('<input type="hidden" name="keywords" value="'.$env{'form.keywords'}.'" />'."\n".
2103: '<input type="hidden" name="kwclr" value="'.$env{'form.kwclr'}.'" />'."\n".
2104: '<input type="hidden" name="kwsize" value="'.$env{'form.kwsize'}.'" />'."\n".
2105: '<input type="hidden" name="kwstyle" value="'.$env{'form.kwstyle'}.'" />'."\n".
2106: '<input type="hidden" name="msgsub" value="'.$env{'form.msgsub'}.'" />'."\n".
1.123 ng 2107: '<input type="hidden" name="shownSub" value="0" />'."\n".
1.257 albertel 2108: '<input type="hidden" name="savemsgN" value="'.$env{'form.savemsgN'}.'" />'."\n");
1.154 albertel 2109: foreach my $partid (&Apache::loncommon::get_env_multiple('form.vPart')) {
2110: $request->print('<input type="hidden" name="vPart" value="'.$partid.'" />'."\n");
2111: }
1.123 ng 2112: }
1.41 ng 2113:
2114: my ($cts,$prnmsg) = (1,'');
1.257 albertel 2115: while ($cts <= $env{'form.savemsgN'}) {
1.41 ng 2116: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
1.123 ng 2117: (!exists($keyhash{$symb.'_savemsg'.$cts}) ?
1.257 albertel 2118: &Apache::lonfeedback::clear_out_html($env{'form.savemsg'.$cts}) :
1.80 ng 2119: &Apache::lonfeedback::clear_out_html($keyhash{$symb.'_savemsg'.$cts})).
1.123 ng 2120: '" />'."\n".
2121: '<input type="hidden" name="shownOnce'.$cts.'" value="0" />'."\n";
1.41 ng 2122: $cts++;
2123: }
2124: $request->print($prnmsg);
1.32 ng 2125:
1.257 albertel 2126: if ($env{'form.handgrade'} eq 'yes' && $env{'form.showgrading'} eq 'yes') {
1.596.2.4 raeburn 2127:
2128: my %lt = &Apache::lonlocal::texthash(
2129: keyw => 'Keyword Options',
2130: list => 'List',
2131: past => 'Paste Selection to List',
1.596.2.9 raeburn 2132: high => 'Highlight Attribute',
1.596.2.4 raeburn 2133: );
1.88 www 2134: #
2135: # Print out the keyword options line
2136: #
1.41 ng 2137: $request->print(<<KEYWORDS);
1.596.2.4 raeburn 2138: <b>$lt{'keyw'}:</b>
2139: <a href="javascript:keywords(document.SCORE);" target="_self">$lt{'list'}</a>
1.589 bisitz 2140: <a href="#" onmousedown="javascript:getSel(); return false"
1.596.2.4 raeburn 2141: CLASS="page">$lt{'past'}</a>
2142: <a href="javascript:kwhighlight();" target="_self">$lt{'high'}</a><br /><br />
1.38 ng 2143: KEYWORDS
1.88 www 2144: #
2145: # Load the other essays for similarity check
2146: #
1.324 albertel 2147: my (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb);
1.384 albertel 2148: my ($adom,$aname,$apath)=($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
1.359 www 2149: $apath=&escape($apath);
1.88 www 2150: $apath=~s/\W/\_/gs;
1.596.2.12.2. (raeburn 2151:): &init_old_essays($symb,$apath,$adom,$aname);
1.41 ng 2152: }
2153: }
1.44 ng 2154:
1.441 www 2155: # This is where output for one specific student would start
1.592 bisitz 2156: my $add_class = ($counter%2) ? ' LC_grade_show_user_odd_row' : '';
2157: $request->print(
2158: "\n\n"
2159: .'<div class="LC_grade_show_user'.$add_class.'">'
2160: .'<h2>'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).'</h2>'
2161: ."\n"
2162: );
1.441 www 2163:
1.592 bisitz 2164: # Show additional functions if allowed
2165: if ($perm{'vgr'}) {
2166: $request->print(
2167: &Apache::loncommon::track_student_link(
2168: &mt('View recent activity'),
2169: $uname,$udom,'check')
2170: .' '
2171: );
2172: }
2173: if ($perm{'opa'}) {
2174: $request->print(
2175: &Apache::loncommon::pprmlink(
2176: &mt('Set/Change parameters'),
2177: $uname,$udom,$symb,'check'));
2178: }
2179:
2180: # Show Problem
1.257 albertel 2181: if ($env{'form.vProb'} eq 'all' or $env{'form.vAns'} eq 'all') {
1.144 albertel 2182: my $mode;
1.257 albertel 2183: if ($env{'form.vProb'} eq 'all' && $env{'form.vAns'} eq 'all') {
1.144 albertel 2184: $mode='both';
1.257 albertel 2185: } elsif ($env{'form.vProb'} eq 'all' ) {
1.144 albertel 2186: $mode='text';
1.257 albertel 2187: } elsif ($env{'form.vAns'} eq 'all') {
1.144 albertel 2188: $mode='answer';
2189: }
1.329 albertel 2190: &Apache::lonxml::clear_problem_counter();
1.475 albertel 2191: $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode,{'request.prefix' => 'ctr'.$counter}));
1.58 albertel 2192: }
1.144 albertel 2193:
1.257 albertel 2194: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.582 raeburn 2195: my $res_error;
2196: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
2197: if ($res_error) {
2198: $request->print(&navmap_errormsg());
2199: return;
2200: }
1.41 ng 2201:
1.44 ng 2202: # Display student info
1.41 ng 2203: $request->print(($counter == 0 ? '' : '<br />'));
1.590 bisitz 2204:
2205: my $result='<div class="LC_Box">'
2206: .'<h3 class="LC_hcell">'.&mt('Submissions').'</h3>';
1.45 ng 2207: $result.='<input type="hidden" name="name'.$counter.
1.588 bisitz 2208: '" value="'.$env{'form.fullname'}.'" />'."\n";
1.469 albertel 2209: if ($env{'form.handgrade'} eq 'no') {
1.588 bisitz 2210: $result.='<p class="LC_info">'
2211: .&mt('Part(s) graded correct by the computer is marked with a [_1] symbol.',$checkIcon)
2212: ."</p>\n";
1.469 albertel 2213: }
2214:
1.118 ng 2215: # If any part of the problem is an essay-response (handgraded), then check for collaborators
1.464 albertel 2216: my $fullname;
2217: my $col_fullnames = [];
1.257 albertel 2218: if ($env{'form.handgrade'} eq 'yes') {
1.464 albertel 2219: (my $sub_result,$fullname,$col_fullnames)=
2220: &check_collaborators($symb,$uname,$udom,\%record,$handgrade,
2221: $counter);
2222: $result.=$sub_result;
1.41 ng 2223: }
1.44 ng 2224: $request->print($result."\n");
1.588 bisitz 2225:
1.44 ng 2226: # print student answer/submission
1.588 bisitz 2227: # Options are (1) Handgraded submission only
1.44 ng 2228: # (2) Last submission, includes submission that is not handgraded
2229: # (for multi-response type part)
2230: # (3) Last submission plus the parts info
2231: # (4) The whole record for this student
1.257 albertel 2232: if ($env{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
1.151 albertel 2233: my ($string,$timestamp)= &get_last_submission(\%record);
1.468 albertel 2234:
2235: my $lastsubonly;
2236:
1.588 bisitz 2237: if ($$timestamp eq '') {
2238: $lastsubonly.='<div class="LC_grade_submissions_body">'.$$string[0].'</div>';
2239: } else {
1.592 bisitz 2240: $lastsubonly =
2241: '<div class="LC_grade_submissions_body">'
2242: .'<b>'.&mt('Date Submitted:').'</b> '.$$timestamp."\n";
1.468 albertel 2243:
1.151 albertel 2244: my %seenparts;
1.375 albertel 2245: my @part_response_id = &flatten_responseType($responseType);
2246: foreach my $part (@part_response_id) {
1.393 albertel 2247: next if ($env{'form.lastSub'} eq 'hdgrade'
2248: && $$handgrade{$$part[0].'_'.$$part[1]} ne 'yes');
2249:
1.375 albertel 2250: my ($partid,$respid) = @{ $part };
1.324 albertel 2251: my $display_part=&get_display_part($partid,$symb);
1.257 albertel 2252: if ($env{"form.$uname:$udom:$partid:submitted_by"}) {
1.151 albertel 2253: if (exists($seenparts{$partid})) { next; }
2254: $seenparts{$partid}=1;
1.207 albertel 2255: my $submitby='<b>Part:</b> '.$display_part.
2256: ' <b>Collaborative submission by:</b> '.
1.151 albertel 2257: '<a href="javascript:viewSubmitter(\''.
1.257 albertel 2258: $env{"form.$uname:$udom:$partid:submitted_by"}.
1.417 albertel 2259: '\');" target="_self">'.
1.257 albertel 2260: $$fullname{$env{"form.$uname:$udom:$partid:submitted_by"}}.'</a><br />';
1.151 albertel 2261: $request->print($submitby);
2262: next;
2263: }
2264: my $responsetype = $responseType->{$partid}->{$respid};
2265: if (!exists($record{"resource.$partid.$respid.submission"})) {
1.577 bisitz 2266: $lastsubonly.="\n".'<div class="LC_grade_submission_part">'.
2267: '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
2268: ' <span class="LC_internal_info">'.
1.596.2.4 raeburn 2269: '('.&mt('Response ID: [_1]',$respid).')'.
1.577 bisitz 2270: '</span> '.
1.539 riegler 2271: '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br /><br /></div>';
1.151 albertel 2272: next;
2273: }
1.468 albertel 2274: foreach my $submission (@$string) {
2275: my ($partid,$respid) = ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
1.375 albertel 2276: if (join('_',@{$part}) ne ($partid.'_'.$respid)) { next; }
1.596 raeburn 2277: my ($ressub,$hide,$subval) = split(/:/,$submission,3);
1.151 albertel 2278: # Similarity check
2279: my $similar='';
1.596.2.2 raeburn 2280: my ($type,$trial,$rndseed);
2281: if ($hide eq 'rand') {
2282: $type = 'randomizetry';
2283: $trial = $record{"resource.$partid.tries"};
2284: $rndseed = $record{"resource.$partid.rndseed"};
2285: }
1.257 albertel 2286: if($env{'form.checkPlag'}){
1.151 albertel 2287: my ($oname,$odom,$ocrsid,$oessay,$osim)=
1.596.2.12.2. (raeburn 2288:): &most_similar($uname,$udom,$symb,$subval);
1.151 albertel 2289: if ($osim) {
2290: $osim=int($osim*100.0);
1.426 albertel 2291: my %old_course_desc =
2292: &Apache::lonnet::coursedescription($ocrsid,
2293: {'one_time' => 1});
2294:
1.596.2.2 raeburn 2295: if ($hide eq 'anon') {
1.596 raeburn 2296: $similar='<hr /><span class="LC_warning">'.&mt("Essay was found to be similar to another essay submitted for this assignment.").'<br />'.
2297: &mt('As the current submission is for an anonymous survey, no other details are available.').'</span><hr />';
2298: } else {
2299: $similar="<hr /><h3><span class=\"LC_warning\">".
2300: &mt('Essay is [_1]% similar to an essay by [_2] in course [_3] (course id [_4]:[_5])',
2301: $osim,
2302: &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')',
2303: $old_course_desc{'description'},
2304: $old_course_desc{'num'},
2305: $old_course_desc{'domain'}).
2306: '</span></h3><blockquote><i>'.
2307: &keywords_highlight($oessay).
2308: '</i></blockquote><hr />';
2309: }
1.151 albertel 2310: }
1.150 albertel 2311: }
1.596.2.2 raeburn 2312: my $order=&get_order($partid,$respid,$symb,$uname,$udom,
2313: undef,$type,$trial,$rndseed);
1.257 albertel 2314: if ($env{'form.lastSub'} eq 'lastonly' ||
2315: ($env{'form.lastSub'} eq 'hdgrade' &&
1.377 albertel 2316: $$handgrade{$$part[0].'_'.$$part[1]} eq 'yes')) {
1.324 albertel 2317: my $display_part=&get_display_part($partid,$symb);
1.577 bisitz 2318: $lastsubonly.='<div class="LC_grade_submission_part">'.
2319: '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
2320: ' <span class="LC_internal_info">'.
1.596.2.4 raeburn 2321: '('.&mt('Response ID: [_1]',$respid).')'.
2322: '</span> ';
1.313 banghart 2323: my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record);
2324: if (@$files) {
1.596.2.2 raeburn 2325: if ($hide eq 'anon') {
1.596 raeburn 2326: $lastsubonly.='<br />'.&mt('[quant,_1,file] uploaded to this anonymous survey',scalar(@{$files}));
2327: } else {
2328: $lastsubonly.='<br /><span class="LC_warning">'.&mt('Like all files provided by users, this file may contain viruses').'</span><br />';
2329: foreach my $file (@$files) {
2330: &Apache::lonnet::allowuploaded('/adm/grades',$file);
2331: $lastsubonly.='<br /><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.&Apache::loncommon::icon($file).'" border="0" /> '.$file.'</a>';
2332: }
2333: }
1.236 albertel 2334: $lastsubonly.='<br />';
1.41 ng 2335: }
1.596.2.2 raeburn 2336: if ($hide eq 'anon') {
1.596 raeburn 2337: $lastsubonly.='<b>'.&mt('Anonymous Survey').'</b>';
2338: } else {
2339: $lastsubonly.='<b>'.&mt('Submitted Answer:').' </b>'.
2340: &cleanRecord($subval,$responsetype,$symb,$partid,
1.596.2.2 raeburn 2341: $respid,\%record,$order,undef,$uname,$udom,$type,$trial,$rndseed);
1.596 raeburn 2342: }
1.151 albertel 2343: if ($similar) {$lastsubonly.="<br /><br />$similar\n";}
1.468 albertel 2344: $lastsubonly.='</div>';
1.41 ng 2345: }
2346: }
2347: }
1.588 bisitz 2348: $lastsubonly.='</div>'."\n"; # End: LC_grade_submissions_body
1.151 albertel 2349: }
2350: $request->print($lastsubonly);
1.468 albertel 2351: } elsif ($env{'form.lastSub'} eq 'datesub') {
1.324 albertel 2352: my (undef,$responseType,undef,$parts) = &showResourceInfo($symb);
1.148 albertel 2353: $request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
1.257 albertel 2354: } elsif ($env{'form.lastSub'} =~ /^(last|all)$/) {
1.41 ng 2355: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
1.257 albertel 2356: $env{'request.course.id'},
1.44 ng 2357: $last,'.submission',
2358: 'Apache::grades::keywords_highlight'));
1.41 ng 2359: }
1.120 ng 2360:
1.121 ng 2361: $request->print('<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
2362: .$udom.'" />'."\n");
1.44 ng 2363: # return if view submission with no grading option
1.257 albertel 2364: if ($env{'form.showgrading'} eq '' || (!&canmodify($usec))) {
1.120 ng 2365: my $toGrade.='<input type="button" value="Grade Student" '.
1.589 bisitz 2366: 'onclick="javascript:checksubmit(this.form,\'Grade Student\',\''
1.417 albertel 2367: .$counter.'\');" target="_self" /> '."\n" if (&canmodify($usec));
1.468 albertel 2368: $toGrade.='</div>'."\n";
1.257 albertel 2369: if (($env{'form.command'} eq 'submission') ||
2370: ($env{'form.command'} eq 'processGroup' && $counter == $total)) {
1.324 albertel 2371: $toGrade.='</form>'.&show_grading_menu_form($symb);
1.169 albertel 2372: }
1.180 albertel 2373: $request->print($toGrade);
1.41 ng 2374: return;
1.180 albertel 2375: } else {
1.468 albertel 2376: $request->print('</div>'."\n");
1.41 ng 2377: }
1.33 ng 2378:
1.121 ng 2379: # essay grading message center
1.257 albertel 2380: if ($env{'form.handgrade'} eq 'yes') {
1.468 albertel 2381: my $result='<div class="LC_grade_message_center">';
2382:
2383: $result.='<div class="LC_grade_message_center_header">'.
2384: &mt('Send Message').'</div><div class="LC_grade_message_center_body">';
1.257 albertel 2385: my ($lastname,$givenn) = split(/,/,$env{'form.fullname'});
1.118 ng 2386: my $msgfor = $givenn.' '.$lastname;
1.464 albertel 2387: if (scalar(@$col_fullnames) > 0) {
2388: my $lastone = pop(@$col_fullnames);
2389: $msgfor .= ', '.(join ', ',@$col_fullnames).' and '.$lastone.'.';
1.118 ng 2390: }
2391: $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
1.468 albertel 2392: $result.='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
1.121 ng 2393: '<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n";
2394: $result.=' <a href="javascript:msgCenter(document.SCORE,'.$counter.
1.417 albertel 2395: ',\''.$msgfor.'\');" target="_self">'.
1.464 albertel 2396: &mt('Compose message to student').(scalar(@$col_fullnames) >= 1 ? 's' : '').'</a><label> ('.
1.350 albertel 2397: &mt('incl. grades').' <input type="checkbox" name="withgrades'.$counter.'" /></label>)'.
1.118 ng 2398: '<img src="'.$request->dir_config('lonIconsURL').
2399: '/mailbkgrd.gif" width="14" height="10" name="mailicon'.$counter.'" />'."\n".
1.298 www 2400: '<br /> ('.
1.468 albertel 2401: &mt('Message will be sent when you click on Save & Next below.').")\n";
2402: $result.='</div></div>';
1.121 ng 2403: $request->print($result);
1.118 ng 2404: }
1.41 ng 2405:
2406: my %seen = ();
2407: my @partlist;
1.129 ng 2408: my @gradePartRespid;
1.375 albertel 2409: my @part_response_id = &flatten_responseType($responseType);
1.585 bisitz 2410: $request->print(
1.588 bisitz 2411: '<div class="LC_Box">'
2412: .'<h3 class="LC_hcell">'.&mt('Assign Grades').'</h3>'
1.585 bisitz 2413: );
1.592 bisitz 2414: $request->print(&gradeBox_start());
1.375 albertel 2415: foreach my $part_response_id (@part_response_id) {
2416: my ($partid,$respid) = @{ $part_response_id };
2417: my $part_resp = join('_',@{ $part_response_id });
1.322 albertel 2418: next if ($seen{$partid} > 0);
1.41 ng 2419: $seen{$partid}++;
1.393 albertel 2420: next if ($$handgrade{$part_resp} ne 'yes'
2421: && $env{'form.lastSub'} eq 'hdgrade');
1.524 raeburn 2422: push(@partlist,$partid);
2423: push(@gradePartRespid,$partid.'.'.$respid);
1.322 albertel 2424: $request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
1.41 ng 2425: }
1.585 bisitz 2426: $request->print(&gradeBox_end()); # </div>
2427: $request->print('</div>');
1.468 albertel 2428:
2429: $request->print('<div class="LC_grade_info_links">');
2430: $request->print('</div>');
2431:
1.45 ng 2432: $result='<input type="hidden" name="partlist'.$counter.
2433: '" value="'.(join ":",@partlist).'" />'."\n";
1.129 ng 2434: $result.='<input type="hidden" name="gradePartRespid'.
2435: '" value="'.(join ":",@gradePartRespid).'" />'."\n" if ($counter == 0);
1.45 ng 2436: my $ctr = 0;
2437: while ($ctr < scalar(@partlist)) {
2438: $result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
2439: $partlist[$ctr].'" />'."\n";
2440: $ctr++;
2441: }
1.468 albertel 2442: $request->print($result.''."\n");
1.41 ng 2443:
1.441 www 2444: # Done with printing info for one student
2445:
1.468 albertel 2446: $request->print('</div>');#LC_grade_show_user
1.441 www 2447:
2448:
1.41 ng 2449: # print end of form
2450: if ($counter == $total) {
1.592 bisitz 2451: my $endform='<br /><hr /><table border="0"><tr><td>'."\n";
1.485 albertel 2452: $endform.='<input type="button" value="'.&mt('Save & Next').'" '.
1.589 bisitz 2453: 'onclick="javascript:checksubmit(this.form,\'Save & Next\','.
1.417 albertel 2454: $total.','.scalar(@partlist).');" target="_self" /> '."\n";
1.119 ng 2455: my $ntstu ='<select name="NTSTU">'.
2456: '<option>1</option><option>2</option>'.
2457: '<option>3</option><option>5</option>'.
2458: '<option>7</option><option>10</option></select>'."\n";
1.257 albertel 2459: my $nsel = ($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : '1');
1.401 albertel 2460: $ntstu =~ s/<option>$nsel</<option selected="selected">$nsel</;
1.578 raeburn 2461: $endform.=&mt('[_1]student(s)',$ntstu);
1.485 albertel 2462: $endform.=' <input type="button" value="'.&mt('Previous').'" '.
1.589 bisitz 2463: 'onclick="javascript:checksubmit(this.form,\'Previous\');" target="_self" /> '."\n".
1.485 albertel 2464: '<input type="button" value="'.&mt('Next').'" '.
1.589 bisitz 2465: 'onclick="javascript:checksubmit(this.form,\'Next\');" target="_self" /> ';
1.592 bisitz 2466: $endform.='<span class="LC_warning">'.
2467: &mt('(Next and Previous (student) do not save the scores.)').
2468: '</span>'."\n" ;
1.349 albertel 2469: $endform.="<input type='hidden' value='".&get_increment().
1.348 bowersj2 2470: "' name='increment' />";
1.485 albertel 2471: $endform.='</td></tr></table></form>';
1.324 albertel 2472: $endform.=&show_grading_menu_form($symb);
1.41 ng 2473: $request->print($endform);
2474: }
2475: return '';
1.38 ng 2476: }
2477:
1.464 albertel 2478: sub check_collaborators {
2479: my ($symb,$uname,$udom,$record,$handgrade,$counter) = @_;
2480: my ($result,@col_fullnames);
2481: my ($classlist,undef,$fullname) = &getclasslist('all','0');
2482: foreach my $part (keys(%$handgrade)) {
2483: my $ncol = &Apache::lonnet::EXT('resource.'.$part.
2484: '.maxcollaborators',
2485: $symb,$udom,$uname);
2486: next if ($ncol <= 0);
2487: $part =~ s/\_/\./g;
2488: next if ($record->{'resource.'.$part.'.collaborators'} eq '');
2489: my (@good_collaborators, @bad_collaborators);
2490: foreach my $possible_collaborator
1.596.2.4 raeburn 2491: (split(/[,;\s]+/,$record->{'resource.'.$part.'.collaborators'})) {
1.464 albertel 2492: $possible_collaborator =~ s/[\$\^\(\)]//g;
2493: next if ($possible_collaborator eq '');
1.596.2.8 raeburn 2494: my ($co_name,$co_dom) = split(/:/,$possible_collaborator);
1.464 albertel 2495: $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
2496: next if ($co_name eq $uname && $co_dom eq $udom);
2497: # Doing this grep allows 'fuzzy' specification
2498: my @matches = grep(/^\Q$co_name\E:\Q$co_dom\E$/i,
2499: keys(%$classlist));
2500: if (! scalar(@matches)) {
2501: push(@bad_collaborators, $possible_collaborator);
2502: } else {
2503: push(@good_collaborators, @matches);
2504: }
2505: }
2506: if (scalar(@good_collaborators) != 0) {
1.596.2.8 raeburn 2507: $result.='<br />'.&mt('Collaborators:').'<ol>';
1.464 albertel 2508: foreach my $name (@good_collaborators) {
2509: my ($lastname,$givenn) = split(/,/,$$fullname{$name});
2510: push(@col_fullnames, $givenn.' '.$lastname);
1.596.2.4 raeburn 2511: $result.='<li>'.$fullname->{$name}.'</li>';
1.464 albertel 2512: }
1.596.2.4 raeburn 2513: $result.='</ol><br />'."\n";
1.466 albertel 2514: my ($part)=split(/\./,$part);
1.464 albertel 2515: $result.='<input type="hidden" name="collaborator'.$counter.
2516: '" value="'.$part.':'.(join ':',@good_collaborators).'" />'.
2517: "\n";
2518: }
2519: if (scalar(@bad_collaborators) > 0) {
1.466 albertel 2520: $result.='<div class="LC_warning">';
1.464 albertel 2521: $result.=&mt('This student has submitted [quant,_1,invalid collaborator]: [_2]',scalar(@bad_collaborators),join(', ',@bad_collaborators));
2522: $result .= '</div>';
2523: }
2524: if (scalar(@bad_collaborators > $ncol)) {
1.466 albertel 2525: $result .= '<div class="LC_warning">';
1.464 albertel 2526: $result .= &mt('This student has submitted too many '.
2527: 'collaborators. Maximum is [_1].',$ncol);
2528: $result .= '</div>';
2529: }
2530: }
2531: return ($result,$fullname,\@col_fullnames);
2532: }
2533:
1.44 ng 2534: #--- Retrieve the last submission for all the parts
1.38 ng 2535: sub get_last_submission {
1.119 ng 2536: my ($returnhash)=@_;
1.596 raeburn 2537: my (@string,$timestamp,%lasthidden);
1.119 ng 2538: if ($$returnhash{'version'}) {
1.46 ng 2539: my %lasthash=();
2540: my ($version);
1.119 ng 2541: for ($version=1;$version<=$$returnhash{'version'};$version++) {
1.397 albertel 2542: foreach my $key (sort(split(/\:/,
2543: $$returnhash{$version.':keys'}))) {
2544: $lasthash{$key}=$$returnhash{$version.':'.$key};
2545: $timestamp =
1.545 raeburn 2546: &Apache::lonlocal::locallocaltime($$returnhash{$version.':timestamp'});
1.46 ng 2547: }
2548: }
1.596.2.2 raeburn 2549: my (%typeparts,%randombytry);
1.596 raeburn 2550: my $showsurv =
2551: &Apache::lonnet::allowed('vas',$env{'request.course.id'});
2552: foreach my $key (sort(keys(%lasthash))) {
2553: if ($key =~ /\.type$/) {
2554: if (($lasthash{$key} eq 'anonsurvey') ||
1.596.2.2 raeburn 2555: ($lasthash{$key} eq 'anonsurveycred') ||
2556: ($lasthash{$key} eq 'randomizetry')) {
1.596 raeburn 2557: my ($ign,@parts) = split(/\./,$key);
2558: pop(@parts);
1.596.2.3 raeburn 2559: my $id = join('.',@parts);
1.596.2.2 raeburn 2560: if ($lasthash{$key} eq 'randomizetry') {
2561: $randombytry{$ign.'.'.$id} = $lasthash{$key};
2562: } else {
2563: unless ($showsurv) {
2564: $typeparts{$ign.'.'.$id} = $lasthash{$key};
2565: }
1.596 raeburn 2566: }
2567: delete($lasthash{$key});
2568: }
2569: }
2570: }
2571: my @hidden = keys(%typeparts);
1.596.2.2 raeburn 2572: my @randomize = keys(%randombytry);
1.397 albertel 2573: foreach my $key (keys(%lasthash)) {
2574: next if ($key !~ /\.submission$/);
1.596 raeburn 2575: my $hide;
2576: if (@hidden) {
2577: foreach my $id (@hidden) {
2578: if ($key =~ /^\Q$id\E/) {
1.596.2.2 raeburn 2579: $hide = 'anon';
1.596 raeburn 2580: last;
2581: }
2582: }
2583: }
1.596.2.2 raeburn 2584: unless ($hide) {
2585: if (@randomize) {
2586: foreach my $id (@hidden) {
2587: if ($key =~ /^\Q$id\E/) {
2588: $hide = 'rand';
2589: last;
2590: }
2591: }
2592: }
2593: }
1.397 albertel 2594: my ($partid,$foo) = split(/submission$/,$key);
2595: my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
1.398 albertel 2596: '<span class="LC_warning">Draft Copy</span> ' : '';
1.596 raeburn 2597: push(@string, join(':', $key, $hide, $draft.$lasthash{$key}));
1.41 ng 2598: }
2599: }
1.397 albertel 2600: if (!@string) {
2601: $string[0] =
1.539 riegler 2602: '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span>';
1.397 albertel 2603: }
2604: return (\@string,\$timestamp);
1.38 ng 2605: }
1.35 ng 2606:
1.44 ng 2607: #--- High light keywords, with style choosen by user.
1.38 ng 2608: sub keywords_highlight {
1.44 ng 2609: my $string = shift;
1.257 albertel 2610: my $size = $env{'form.kwsize'} eq '0' ? '' : 'size='.$env{'form.kwsize'};
2611: my $styleon = $env{'form.kwstyle'} eq '' ? '' : $env{'form.kwstyle'};
1.41 ng 2612: (my $styleoff = $styleon) =~ s/\</\<\//;
1.257 albertel 2613: my @keylist = split(/[,\s+]/,$env{'form.keywords'});
1.398 albertel 2614: foreach my $keyword (@keylist) {
2615: $string =~ s/\b\Q$keyword\E(\b|\.)/<font color\=$env{'form.kwclr'} $size\>$styleon$keyword$styleoff<\/font>/gi;
1.41 ng 2616: }
2617: return $string;
1.38 ng 2618: }
1.36 ng 2619:
1.596.2.12.2. (raeburn 2620:): # For Tasks provide a mechanism to display previous version for one specific student
2621:):
2622:): sub show_previous_task_version {
2623:): my ($request,$symb) = @_;
2624:): if ($symb eq '') {
2625:): $request->print("Unable to handle ambiguous references.");
2626:):
2627:): return '';
2628:): }
2629:): my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
2630:): my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
2631:): if (!&canview($usec)) {
2632:): $request->print('<span class="LC_warning">Unable to view previous version for requested student.('.
2633:): $uname.':'.$udom.' in section '.$usec.' in course id '.
2634:): $env{'request.course.id'}.')</span>');
2635:): return;
2636:): }
2637:): my $mode = 'both';
2638:): my $isTask = ($symb =~/\.task$/);
2639:): if ($isTask) {
2640:): if ($env{'form.previousversion'} =~ /^\d+$/) {
2641:): if ($env{'form.fullname'} eq '') {
2642:): $env{'form.fullname'} =
2643:): &Apache::loncommon::plainname($uname,$udom,'lastname');
2644:): }
2645:): my $probtitle=&Apache::lonnet::gettitle($symb);
2646:): $request->print("\n\n".
2647:): '<div class="LC_grade_show_user">'.
2648:): '<h2>'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
2649:): '</h2>'."\n");
2650:): &Apache::lonxml::clear_problem_counter();
2651:): $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode,
2652:): {'previousversion' => $env{'form.previousversion'} }));
2653:): $request->print("\n</div>");
2654:): }
2655:): }
2656:): return;
2657:): }
2658:):
2659:): sub choose_task_version_form {
2660:): my ($symb,$uname,$udom,$nomenu) = @_;
2661:): my $isTask = ($symb =~/\.task$/);
2662:): my ($current,$version,$result,$js,$displayed,$rowtitle);
2663:): if ($isTask) {
2664:): my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
2665:): $udom,$uname);
2666:): if (($record{'resource.0.version'} eq '') ||
2667:): ($record{'resource.0.version'} < 2)) {
2668:): return ($record{'resource.0.version'},
2669:): $record{'resource.0.version'},$result,$js);
2670:): } else {
2671:): $current = $record{'resource.0.version'};
2672:): }
2673:): if ($env{'form.previousversion'}) {
2674:): $displayed = $env{'form.previousversion'};
2675:): $rowtitle = &mt('Choose another version:')
2676:): } else {
2677:): $displayed = $current;
2678:): $rowtitle = &mt('Show earlier version:');
2679:): }
2680:): $result = '<div class="LC_left_float">';
2681:): my $list;
2682:): my $numversions = 0;
2683:): for (my $i=1; $i<=$record{'resource.0.version'}; $i++) {
2684:): if ($i == $current) {
2685:): if (!$env{'form.previousversion'} || $nomenu) {
2686:): next;
2687:): } else {
2688:): $list .= '<option value="'.$i.'">'.&mt('Current').'</option>'."\n";
2689:): $numversions ++;
2690:): }
2691:): } elsif (defined($record{'resource.'.$i.'.0.status'})) {
2692:): unless ($i == $env{'form.previousversion'}) {
2693:): $numversions ++;
2694:): }
2695:): $list .= '<option value="'.$i.'">'.$i.'</option>'."\n";
2696:): }
2697:): }
2698:): if ($numversions) {
2699:): $symb = &HTML::Entities::encode($symb,'<>"&');
2700:): $result .=
2701:): '<form name="getprev" method="post" action=""'.
2702:): ' onsubmit="return previousVersion('."'$uname','$udom','$symb','$displayed'".');">'.
2703:): &Apache::loncommon::start_data_table().
2704:): &Apache::loncommon::start_data_table_row().
2705:): '<th align="left">'.$rowtitle.'</th>'.
2706:): '<td><select name="version">'.
2707:): '<option>'.&mt('Select').'</option>'.
2708:): $list.
2709:): '</select></td>'.
2710:): &Apache::loncommon::end_data_table_row();
2711:): unless ($nomenu) {
2712:): $result .= &Apache::loncommon::start_data_table_row().
2713:): '<th align="left">'.&mt('Open in new window').'</th>'.
2714:): '<td><span class="LC_nobreak">'.
2715:): '<label><input type="radio" name="prevwin" value="1" />'.
2716:): &mt('Yes').'</label>'.
2717:): '<label><input type="radio" name="prevwin" value="0" checked="checked" />'.&mt('No').'</label>'.
2718:): '</span></td>'.
2719:): &Apache::loncommon::end_data_table_row();
2720:): }
2721:): $result .=
2722:): &Apache::loncommon::start_data_table_row().
2723:): '<th align="left"> </th>'.
2724:): '<td>'.
2725:): '<input type="submit" name="prevsub" value="'.&mt('Display').'" />'.
2726:): '</td>'.
2727:): &Apache::loncommon::end_data_table_row().
2728:): &Apache::loncommon::end_data_table().
2729:): '</form>';
2730:): $js = &previous_display_javascript($nomenu,$current);
2731:): } elsif ($displayed && $nomenu) {
2732:): $result .= '<a href="javascript:window.close()">'.&mt('Close window').'</a>';
2733:): } else {
2734:): $result .= &mt('No previous versions to show for this student');
2735:): }
2736:): $result .= '</div>';
2737:): }
2738:): return ($current,$displayed,$result,$js);
2739:): }
2740:):
2741:): sub previous_display_javascript {
2742:): my ($nomenu,$current) = @_;
2743:): my $js = <<"JSONE";
2744:): <script type="text/javascript">
2745:): // <![CDATA[
2746:): function previousVersion(uname,udom,symb) {
2747:): var current = '$current';
2748:): var version = document.getprev.version.options[document.getprev.version.selectedIndex].value;
2749:): var prevstr = new RegExp("^\\\\d+\$");
2750:): if (!prevstr.test(version)) {
2751:): return false;
2752:): }
2753:): var url = '';
2754:): if (version == current) {
2755:): url = '/adm/grades?student='+uname+'&userdom='+udom+'&symb='+symb+'&command=submission';
2756:): } else {
2757:): url = '/adm/grades?student='+uname+'&userdom='+udom+'&symb='+symb+'&command=versionsub&previousversion='+version;
2758:): }
2759:): JSONE
2760:): if ($nomenu) {
2761:): $js .= <<"JSTWO";
2762:): document.location.href = url;
2763:): JSTWO
2764:): } else {
2765:): $js .= <<"JSTHREE";
2766:): var newwin = 0;
2767:): for (var i=0; i<document.getprev.prevwin.length; i++) {
2768:): if (document.getprev.prevwin[i].checked == true) {
2769:): newwin = document.getprev.prevwin[i].value;
2770:): }
2771:): }
2772:): if (newwin == 1) {
2773:): var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
2774:): url = url+'&inhibitmenu=yes';
2775:): if (typeof(previousWin) == 'undefined' || previousWin.closed) {
2776:): previousWin = window.open(url,'',options,1);
2777:): } else {
2778:): previousWin.location.href = url;
2779:): }
2780:): previousWin.focus();
2781:): return false;
2782:): } else {
2783:): document.location.href = url;
2784:): return false;
2785:): }
2786:): JSTHREE
2787:): }
2788:): $js .= <<"ENDJS";
2789:): return false;
2790:): }
2791:): // ]]>
2792:): </script>
2793:): ENDJS
2794:):
2795:): }
2796:):
1.44 ng 2797: #--- Called from submission routine
1.38 ng 2798: sub processHandGrade {
1.41 ng 2799: my ($request) = shift;
1.596.2.12.2. (raeburn 2800:): my ($symb) = &get_symb($request);
1.324 albertel 2801: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.257 albertel 2802: my $button = $env{'form.gradeOpt'};
2803: my $ngrade = $env{'form.NCT'};
2804: my $ntstu = $env{'form.NTSTU'};
1.301 albertel 2805: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2806: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2807:
1.44 ng 2808: if ($button eq 'Save & Next') {
2809: my $ctr = 0;
2810: while ($ctr < $ngrade) {
1.257 albertel 2811: my ($uname,$udom) = split(/:/,$env{'form.unamedom'.$ctr});
1.324 albertel 2812: my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$symb,$uname,$udom,$ctr);
1.71 ng 2813: if ($errorflag eq 'no_score') {
2814: $ctr++;
2815: next;
2816: }
1.104 albertel 2817: if ($errorflag eq 'not_allowed') {
1.398 albertel 2818: $request->print("<span class=\"LC_warning\">Not allowed to modify grades for $uname:$udom</span>");
1.104 albertel 2819: $ctr++;
2820: next;
2821: }
1.257 albertel 2822: my $includemsg = $env{'form.includemsg'.$ctr};
1.44 ng 2823: my ($subject,$message,$msgstatus) = ('','','');
1.418 albertel 2824: my $restitle = &Apache::lonnet::gettitle($symb);
2825: my ($feedurl,$showsymb) =
2826: &get_feedurl_and_symb($symb,$uname,$udom);
2827: my $messagetail;
1.62 albertel 2828: if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.298 www 2829: $subject = $env{'form.msgsub'} if ($includemsg =~ /msgsub/);
1.295 www 2830: unless ($subject=~/\w/) { $subject=&mt('Grading Feedback'); }
1.386 raeburn 2831: $subject.=' ['.$restitle.']';
1.44 ng 2832: my (@msgnum) = split(/,/,$includemsg);
2833: foreach (@msgnum) {
1.257 albertel 2834: $message.=$env{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
1.44 ng 2835: }
1.80 ng 2836: $message =&Apache::lonfeedback::clear_out_html($message);
1.298 www 2837: if ($env{'form.withgrades'.$ctr}) {
2838: $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
1.386 raeburn 2839: $messagetail = " for <a href=\"".
1.418 albertel 2840: $feedurl."?symb=$showsymb\">$env{'form.probTitle'}</a>";
1.386 raeburn 2841: }
2842: $msgstatus =
2843: &Apache::lonmsg::user_normal_msg($uname,$udom,$subject,
2844: $message.$messagetail,
1.418 albertel 2845: undef,$feedurl,undef,
1.386 raeburn 2846: undef,undef,$showsymb,
2847: $restitle);
1.574 bisitz 2848: $request->print('<br />'.&mt('Sending message to [_1]',$uname.':'.$udom).': '.
1.596.2.4 raeburn 2849: $msgstatus.'<br />');
1.44 ng 2850: }
1.257 albertel 2851: if ($env{'form.collaborator'.$ctr}) {
1.155 albertel 2852: my @collabstrs=&Apache::loncommon::get_env_multiple("form.collaborator$ctr");
1.150 albertel 2853: foreach my $collabstr (@collabstrs) {
2854: my ($part,@collaborators) = split(/:/,$collabstr);
1.310 banghart 2855: foreach my $collaborator (@collaborators) {
1.150 albertel 2856: my ($errorflag,$pts,$wgt) =
1.324 albertel 2857: &saveHandGrade($request,$symb,$collaborator,$udom,$ctr,
1.257 albertel 2858: $env{'form.unamedom'.$ctr},$part);
1.150 albertel 2859: if ($errorflag eq 'not_allowed') {
1.362 albertel 2860: $request->print("<span class=\"LC_error\">".&mt('Not allowed to modify grades for [_1]',"$collaborator:$udom")."</span>");
1.150 albertel 2861: next;
1.418 albertel 2862: } elsif ($message ne '') {
2863: my ($baseurl,$showsymb) =
2864: &get_feedurl_and_symb($symb,$collaborator,
2865: $udom);
2866: if ($env{'form.withgrades'.$ctr}) {
2867: $messagetail = " for <a href=\"".
1.386 raeburn 2868: $baseurl."?symb=$showsymb\">$env{'form.probTitle'}</a>";
1.150 albertel 2869: }
1.418 albertel 2870: $msgstatus =
2871: &Apache::lonmsg::user_normal_msg($collaborator,$udom,$subject,$message.$messagetail,undef,$baseurl,undef,undef,undef,$showsymb,$restitle);
1.104 albertel 2872: }
1.44 ng 2873: }
2874: }
2875: }
2876: $ctr++;
2877: }
2878: }
2879:
1.257 albertel 2880: if ($env{'form.handgrade'} eq 'yes') {
1.119 ng 2881: # Keywords sorted in alphabatical order
1.257 albertel 2882: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1.119 ng 2883: my %keyhash = ();
1.257 albertel 2884: $env{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
2885: $env{'form.keywords'} =~ s/^\s+|\s+$//;
2886: my (@keywords) = sort(split(/\s+/,$env{'form.keywords'}));
2887: $env{'form.keywords'} = join(' ',@keywords);
2888: $keyhash{$symb.'_keywords'} = $env{'form.keywords'};
2889: $keyhash{$symb.'_subject'} = $env{'form.msgsub'};
2890: $keyhash{$loginuser.'_kwclr'} = $env{'form.kwclr'};
2891: $keyhash{$loginuser.'_kwsize'} = $env{'form.kwsize'};
2892: $keyhash{$loginuser.'_kwstyle'} = $env{'form.kwstyle'};
1.119 ng 2893:
2894: # message center - Order of message gets changed. Blank line is eliminated.
1.257 albertel 2895: # New messages are saved in env for the next student.
1.119 ng 2896: # All messages are saved in nohist_handgrade.db
2897: my ($ctr,$idx) = (1,1);
1.257 albertel 2898: while ($ctr <= $env{'form.savemsgN'}) {
2899: if ($env{'form.savemsg'.$ctr} ne '') {
2900: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.savemsg'.$ctr};
1.119 ng 2901: $idx++;
2902: }
2903: $ctr++;
1.41 ng 2904: }
1.119 ng 2905: $ctr = 0;
2906: while ($ctr < $ngrade) {
1.257 albertel 2907: if ($env{'form.newmsg'.$ctr} ne '') {
2908: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.newmsg'.$ctr};
2909: $env{'form.savemsg'.$idx} = $env{'form.newmsg'.$ctr};
1.119 ng 2910: $idx++;
2911: }
2912: $ctr++;
1.41 ng 2913: }
1.257 albertel 2914: $env{'form.savemsgN'} = --$idx;
2915: $keyhash{$symb.'_savemsgN'} = $env{'form.savemsgN'};
1.119 ng 2916: my $putresult = &Apache::lonnet::put
1.301 albertel 2917: ('nohist_handgrade',\%keyhash,$cdom,$cnum);
1.41 ng 2918: }
1.44 ng 2919: # Called by Save & Refresh from Highlight Attribute Window
1.257 albertel 2920: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
2921: if ($env{'form.refresh'} eq 'on') {
1.86 ng 2922: my ($ctr,$total) = (0,0);
2923: while ($ctr < $ngrade) {
1.257 albertel 2924: $total++ if $env{'form.unamedom'.$ctr} ne '';
1.86 ng 2925: $ctr++;
2926: }
1.257 albertel 2927: $env{'form.NTSTU'}=$ngrade;
1.86 ng 2928: $ctr = 0;
2929: while ($ctr < $total) {
1.257 albertel 2930: my $processUser = $env{'form.unamedom'.$ctr};
2931: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2932: $env{'form.fullname'} = $$fullname{$processUser};
1.86 ng 2933: &submission($request,$ctr,$total-1);
1.41 ng 2934: $ctr++;
2935: }
2936: return '';
2937: }
1.36 ng 2938:
1.121 ng 2939: # Go directly to grade student - from submission or link from chart page
1.120 ng 2940: if ($button eq 'Grade Student') {
1.324 albertel 2941: (undef,undef,$env{'form.handgrade'},undef,undef) = &showResourceInfo($symb);
1.257 albertel 2942: my $processUser = $env{'form.unamedom'.$env{'form.studentNo'}};
2943: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2944: $env{'form.fullname'} = $$fullname{$processUser};
1.120 ng 2945: &submission($request,0,0);
2946: return '';
2947: }
2948:
1.44 ng 2949: # Get the next/previous one or group of students
1.257 albertel 2950: my $firststu = $env{'form.unamedom0'};
2951: my $laststu = $env{'form.unamedom'.($ngrade-1)};
1.119 ng 2952: my $ctr = 2;
1.41 ng 2953: while ($laststu eq '') {
1.257 albertel 2954: $laststu = $env{'form.unamedom'.($ngrade-$ctr)};
1.41 ng 2955: $ctr++;
2956: $laststu = $firststu if ($ctr > $ngrade);
2957: }
1.44 ng 2958:
1.41 ng 2959: my (@parsedlist,@nextlist);
2960: my ($nextflg) = 0;
1.524 raeburn 2961: foreach my $item (sort
1.294 albertel 2962: {
2963: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
2964: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
2965: }
2966: return $a cmp $b;
2967: } (keys(%$fullname))) {
1.41 ng 2968: if ($nextflg == 1 && $button =~ /Next$/) {
1.524 raeburn 2969: push(@parsedlist,$item);
1.41 ng 2970: }
1.524 raeburn 2971: $nextflg = 1 if ($item eq $laststu);
1.41 ng 2972: if ($button eq 'Previous') {
1.524 raeburn 2973: last if ($item eq $firststu);
2974: push(@parsedlist,$item);
1.41 ng 2975: }
2976: }
2977: $ctr = 0;
2978: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
1.582 raeburn 2979: my $res_error;
2980: my ($partlist) = &response_type($symb,\$res_error);
2981: if ($res_error) {
2982: $request->print(&navmap_errormsg());
2983: return;
2984: }
1.41 ng 2985: foreach my $student (@parsedlist) {
1.257 albertel 2986: my $submitonly=$env{'form.submitonly'};
1.41 ng 2987: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 2988:
2989: if ($submitonly eq 'queued') {
2990: my %queue_status =
2991: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
2992: $udom,$uname);
2993: next if (!defined($queue_status{'gradingqueue'}));
2994: }
2995:
1.156 albertel 2996: if ($submitonly =~ /^(yes|graded|incorrect)$/) {
1.257 albertel 2997: # my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 2998: my %status=&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 2999: my $submitted = 0;
1.248 albertel 3000: my $ungraded = 0;
3001: my $incorrect = 0;
1.524 raeburn 3002: foreach my $item (keys(%status)) {
3003: $submitted = 1 if ($status{$item} ne 'nothing');
3004: $ungraded = 1 if ($status{$item} =~ /^ungraded/);
3005: $incorrect = 1 if ($status{$item} =~ /^incorrect/);
3006: my ($foo,$partid,$foo1) = split(/\./,$item);
1.145 albertel 3007: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
3008: $submitted = 0;
3009: }
1.41 ng 3010: }
1.156 albertel 3011: next if (!$submitted && ($submitonly eq 'yes' ||
3012: $submitonly eq 'incorrect' ||
3013: $submitonly eq 'graded'));
1.248 albertel 3014: next if (!$ungraded && ($submitonly eq 'graded'));
3015: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 3016: }
1.524 raeburn 3017: push(@nextlist,$student) if ($ctr < $ntstu);
1.129 ng 3018: last if ($ctr == $ntstu);
1.41 ng 3019: $ctr++;
3020: }
1.36 ng 3021:
1.41 ng 3022: $ctr = 0;
3023: my $total = scalar(@nextlist)-1;
1.39 ng 3024:
1.524 raeburn 3025: foreach (sort(@nextlist)) {
1.41 ng 3026: my ($uname,$udom,$submitter) = split(/:/);
1.257 albertel 3027: $env{'form.student'} = $uname;
3028: $env{'form.userdom'} = $udom;
3029: $env{'form.fullname'} = $$fullname{$_};
1.41 ng 3030: &submission($request,$ctr,$total);
3031: $ctr++;
3032: }
3033: if ($total < 0) {
1.485 albertel 3034: my $the_end = '<h3><span class="LC_info">'.&mt('LON-CAPA User Message').'</span></h3><br />'."\n";
1.596.2.4 raeburn 3035: $the_end.='<p>'.&mt('[_1]Message:[_2] No more students for this section or class.','<b>','</b>').'</p>'."\n";
1.485 albertel 3036: $the_end.=&mt('Click on the button below to return to the grading menu.').'<br /><br />'."\n";
1.324 albertel 3037: $the_end.=&show_grading_menu_form($symb);
1.41 ng 3038: $request->print($the_end);
3039: }
3040: return '';
1.38 ng 3041: }
1.36 ng 3042:
1.44 ng 3043: #---- Save the score and award for each student, if changed
1.38 ng 3044: sub saveHandGrade {
1.324 albertel 3045: my ($request,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
1.342 banghart 3046: my @version_parts;
1.104 albertel 3047: my $usec = &Apache::lonnet::getsection($domain,$stuname,
1.257 albertel 3048: $env{'request.course.id'});
1.104 albertel 3049: if (!&canmodify($usec)) { return('not_allowed'); }
1.337 banghart 3050: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
1.251 banghart 3051: my @parts_graded;
1.77 ng 3052: my %newrecord = ();
3053: my ($pts,$wgt) = ('','');
1.269 raeburn 3054: my %aggregate = ();
3055: my $aggregateflag = 0;
1.301 albertel 3056: my @parts = split(/:/,$env{'form.partlist'.$newflg});
3057: foreach my $new_part (@parts) {
1.337 banghart 3058: #collaborator ($submi may vary for different parts
1.259 banghart 3059: if ($submitter && $new_part ne $part) { next; }
3060: my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
1.125 ng 3061: if ($dropMenu eq 'excused') {
1.259 banghart 3062: if ($record{'resource.'.$new_part.'.solved'} ne 'excused') {
3063: $newrecord{'resource.'.$new_part.'.solved'} = 'excused';
3064: if (exists($record{'resource.'.$new_part.'.awarded'})) {
3065: $newrecord{'resource.'.$new_part.'.awarded'} = '';
1.58 albertel 3066: }
1.364 banghart 3067: $newrecord{'resource.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.58 albertel 3068: }
1.125 ng 3069: } elsif ($dropMenu eq 'reset status'
1.259 banghart 3070: && exists($record{'resource.'.$new_part.'.solved'})) { #don't bother if no old records -> no attempts
1.524 raeburn 3071: foreach my $key (keys(%record)) {
1.259 banghart 3072: if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
1.197 albertel 3073: }
1.259 banghart 3074: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 3075: "$env{'user.name'}:$env{'user.domain'}";
1.270 albertel 3076: my $totaltries = $record{'resource.'.$part.'.tries'};
3077:
3078: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
3079: [$new_part]);
3080: my $aggtries =$totaltries;
1.269 raeburn 3081: if ($last_resets{$new_part}) {
1.270 albertel 3082: $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
3083: $new_part);
1.269 raeburn 3084: }
1.270 albertel 3085:
3086: my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
1.269 raeburn 3087: if ($aggtries > 0) {
1.327 albertel 3088: &decrement_aggs($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
1.269 raeburn 3089: $aggregateflag = 1;
3090: }
1.125 ng 3091: } elsif ($dropMenu eq '') {
1.259 banghart 3092: $pts = ($env{'form.GD_BOX'.$newflg.'_'.$new_part} ne '' ?
3093: $env{'form.GD_BOX'.$newflg.'_'.$new_part} :
3094: $env{'form.RADVAL'.$newflg.'_'.$new_part});
3095: if ($pts eq '' && $env{'form.GD_SEL'.$newflg.'_'.$new_part} eq '') {
1.153 albertel 3096: next;
3097: }
1.259 banghart 3098: $wgt = $env{'form.WGT'.$newflg.'_'.$new_part} eq '' ? 1 :
3099: $env{'form.WGT'.$newflg.'_'.$new_part};
1.41 ng 3100: my $partial= $pts/$wgt;
1.259 banghart 3101: if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
1.153 albertel 3102: #do not update score for part if not changed.
1.346 banghart 3103: &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
1.153 albertel 3104: next;
1.251 banghart 3105: } else {
1.524 raeburn 3106: push(@parts_graded,$new_part);
1.153 albertel 3107: }
1.259 banghart 3108: if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
3109: $newrecord{'resource.'.$new_part.'.awarded'} = $partial;
1.153 albertel 3110: }
1.259 banghart 3111: my $reckey = 'resource.'.$new_part.'.solved';
1.41 ng 3112: if ($partial == 0) {
1.153 albertel 3113: if ($record{$reckey} ne 'incorrect_by_override') {
3114: $newrecord{$reckey} = 'incorrect_by_override';
3115: }
1.41 ng 3116: } else {
1.153 albertel 3117: if ($record{$reckey} ne 'correct_by_override') {
3118: $newrecord{$reckey} = 'correct_by_override';
3119: }
3120: }
3121: if ($submitter &&
1.259 banghart 3122: ($record{'resource.'.$new_part.'.submitted_by'} ne $submitter)) {
3123: $newrecord{'resource.'.$new_part.'.submitted_by'} = $submitter;
1.41 ng 3124: }
1.259 banghart 3125: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 3126: "$env{'user.name'}:$env{'user.domain'}";
1.41 ng 3127: }
1.259 banghart 3128: # unless problem has been graded, set flag to version the submitted files
1.305 banghart 3129: unless ($record{'resource.'.$new_part.'.solved'} =~ /^correct_/ ||
3130: $record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override' ||
3131: $dropMenu eq 'reset status')
3132: {
1.524 raeburn 3133: push(@version_parts,$new_part);
1.259 banghart 3134: }
1.41 ng 3135: }
1.301 albertel 3136: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3137: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3138:
1.344 albertel 3139: if (%newrecord) {
3140: if (@version_parts) {
1.364 banghart 3141: my @changed_keys = &version_portfiles(\%record, \@parts_graded,
3142: $env{'request.course.id'}, $symb, $domain, $stuname, \@version_parts);
1.344 albertel 3143: @newrecord{@changed_keys} = @record{@changed_keys};
1.367 albertel 3144: foreach my $new_part (@version_parts) {
3145: &handback_files($request,$symb,$stuname,$domain,$newflg,
3146: $new_part,\%newrecord);
3147: }
1.259 banghart 3148: }
1.44 ng 3149: &Apache::lonnet::cstore(\%newrecord,$symb,
1.257 albertel 3150: $env{'request.course.id'},$domain,$stuname);
1.380 albertel 3151: &check_and_remove_from_queue(\@parts,\%record,\%newrecord,$symb,
3152: $cdom,$cnum,$domain,$stuname);
1.41 ng 3153: }
1.269 raeburn 3154: if ($aggregateflag) {
3155: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 3156: $cdom,$cnum);
1.269 raeburn 3157: }
1.301 albertel 3158: return ('',$pts,$wgt);
1.36 ng 3159: }
1.322 albertel 3160:
1.380 albertel 3161: sub check_and_remove_from_queue {
3162: my ($parts,$record,$newrecord,$symb,$cdom,$cnum,$domain,$stuname) = @_;
3163: my @ungraded_parts;
3164: foreach my $part (@{$parts}) {
3165: if ( $record->{ 'resource.'.$part.'.awarded'} eq ''
3166: && $record->{ 'resource.'.$part.'.solved' } ne 'excused'
3167: && $newrecord->{'resource.'.$part.'.awarded'} eq ''
3168: && $newrecord->{'resource.'.$part.'.solved' } ne 'excused'
3169: ) {
3170: push(@ungraded_parts, $part);
3171: }
3172: }
3173: if ( !@ungraded_parts ) {
3174: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,
3175: $cnum,$domain,$stuname);
3176: }
3177: }
3178:
1.337 banghart 3179: sub handback_files {
3180: my ($request,$symb,$stuname,$domain,$newflg,$new_part,$newrecord) = @_;
1.517 raeburn 3181: my $portfolio_root = '/userfiles/portfolio';
1.582 raeburn 3182: my $res_error;
3183: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
3184: if ($res_error) {
3185: $request->print('<br />'.&navmap_errormsg().'<br />');
3186: return;
3187: }
1.596.2.4 raeburn 3188: my @handedback;
3189: my $file_msg;
1.375 albertel 3190: my @part_response_id = &flatten_responseType($responseType);
3191: foreach my $part_response_id (@part_response_id) {
3192: my ($part_id,$resp_id) = @{ $part_response_id };
3193: my $part_resp = join('_',@{ $part_response_id });
1.596.2.4 raeburn 3194: if (($env{'form.'.$newflg.'_'.$part_resp.'_countreturndoc'} =~ /^\d+$/) & ($new_part eq $part_id)) {
3195: for (my $counter=1; $counter<=$env{'form.'.$newflg.'_'.$part_resp.'_countreturndoc'}; $counter++) {
1.337 banghart 3196: # if multiple files are uploaded names will be 'returndoc2','returndoc3'
1.596.2.4 raeburn 3197: if ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$counter}) {
3198: my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$counter.'.filename'};
1.338 banghart 3199: my ($directory,$answer_file) =
1.596.2.4 raeburn 3200: ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$counter} =~ /^(.*?)([^\/]*)$/);
1.338 banghart 3201: my ($answer_name,$answer_ver,$answer_ext) =
3202: &file_name_version_ext($answer_file);
1.355 banghart 3203: my ($portfolio_path) = ($directory =~ /^.+$stuname\/portfolio(.*)/);
1.517 raeburn 3204: my $getpropath = 1;
1.596.2.12.2. (raeburn 3205:): my ($dir_list,$listerror) =
3206:): &Apache::lonnet::dirlist($portfolio_root.$portfolio_path,
3207:): $domain,$stuname,$getpropath);
3208:): my $version = &get_next_version($answer_name,$answer_ext,$dir_list);
3(raebur 3209:3): # fix filename
1.355 banghart 3210: my ($save_file_name) = (($directory.$answer_name.".$version.".$answer_ext) =~ /^.+\/${stuname}\/(.*)/);
3211: my $result=&Apache::lonnet::finishuserfileupload($stuname,$domain,
1.596.2.4 raeburn 3212: $newflg.'_'.$part_resp.'_returndoc'.$counter,
1.355 banghart 3213: $save_file_name);
1.337 banghart 3214: if ($result !~ m|^/uploaded/|) {
1.536 raeburn 3215: $request->print('<br /><span class="LC_error">'.
3216: &mt('An error occurred ([_1]) while trying to upload [_2].',
1.596.2.4 raeburn 3217: $result,$newflg.'_'.$part_resp.'_returndoc'.$counter).
1.536 raeburn 3218: '</span>');
1.356 banghart 3219: } else {
1.360 banghart 3220: # mark the file as read only
1.596.2.4 raeburn 3221: push(@handedback,$save_file_name);
1.367 albertel 3222: if (exists($$newrecord{"resource.$new_part.$resp_id.handback"})) {
3223: $$newrecord{"resource.$new_part.$resp_id.handback"}.=',';
3224: }
3225: $$newrecord{"resource.$new_part.$resp_id.handback"} .= $save_file_name;
1.596.2.4 raeburn 3226: $file_msg.='<span class="LC_filename"><a href="/uploaded/'."$domain/$stuname/".$save_file_name.'">'.$save_file_name."</a></span> <br />";
1.367 albertel 3227:
1.337 banghart 3228: }
1.596.2.12.2. 3(raebur 3229:3): $request->print('<br />'.&mt('[_1] will be the uploaded filename [_2]','<span class="LC_info">'.$fname.'</span>','<span class="LC_filename">'.$env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$counter}.'</span>'));
1.337 banghart 3230: }
3231: }
3232: }
1.596.2.4 raeburn 3233: }
3234: if (@handedback > 0) {
3235: $request->print('<br />');
3236: my @what = ($symb,$env{'request.course.id'},'handback');
3237: &Apache::lonnet::mark_as_readonly($domain,$stuname,\@handedback,\@what);
3238: my $user_lh = &Apache::loncommon::user_lang($stuname,$domain,$env{'request.course.id'});
3239: my ($subject,$message);
3240: if (scalar(@handedback) == 1) {
3241: $subject = &mt_user($user_lh,'File Handed Back by Instructor');
3242: } else {
3243: $subject = &mt_user($user_lh,'Files Handed Back by Instructor');
3244: $message = &mt_user($user_lh,'Files have been returned that were originally submitted in response to: ');
3245: }
3246: $message .= "<p><strong>".&Apache::lonnet::gettitle($symb)." </strong></p>";
3247: $message .= &mt_user($user_lh,'The returned file(s) are named: [_1]',"<br />$file_msg <br />").
3248: &mt_user($user_lh,'The file(s) can be found in your [_1]portfolio[_2].','<a href="/adm/portfolio">','</a>');
3249: my ($feedurl,$showsymb) =
3250: &get_feedurl_and_symb($symb,$domain,$stuname);
3251: my $restitle = &Apache::lonnet::gettitle($symb);
3252: $subject .= ' '.&mt_user($user_lh,'(File Returned)').' ['.$restitle.']';
3253: my $msgstatus =
3254: &Apache::lonmsg::user_normal_msg($stuname,$domain,$subject,
3255: $message,undef,$feedurl,undef,undef,undef,$showsymb,
3256: $restitle);
3257: if ($msgstatus) {
3258: $request->print(&mt('Notification message status: [_1]','<span class="LC_info">'.$msgstatus.'</span>').'<br />');
3259: }
3260: }
1.338 banghart 3261: return;
1.337 banghart 3262: }
3263:
1.418 albertel 3264: sub get_feedurl_and_symb {
3265: my ($symb,$uname,$udom) = @_;
3266: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
3267: $url = &Apache::lonnet::clutter($url);
3268: my $encrypturl=&Apache::lonnet::EXT('resource.0.encrypturl',
3269: $symb,$udom,$uname);
3270: if ($encrypturl =~ /^yes$/i) {
3271: &Apache::lonenc::encrypted(\$url,1);
3272: &Apache::lonenc::encrypted(\$symb,1);
3273: }
3274: return ($url,$symb);
3275: }
3276:
1.313 banghart 3277: sub get_submitted_files {
3278: my ($udom,$uname,$partid,$respid,$record) = @_;
3279: my @files;
3280: if ($$record{"resource.$partid.$respid.portfiles"}) {
3281: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
3282: foreach my $file (split(',',$$record{"resource.$partid.$respid.portfiles"})) {
3283: push(@files,$file_url.$file);
3284: }
3285: }
3286: if ($$record{"resource.$partid.$respid.uploadedurl"}) {
3287: push(@files,$$record{"resource.$partid.$respid.uploadedurl"});
3288: }
3289: return (\@files);
3290: }
1.322 albertel 3291:
1.269 raeburn 3292: # ----------- Provides number of tries since last reset.
3293: sub get_num_tries {
3294: my ($record,$last_reset,$part) = @_;
3295: my $timestamp = '';
3296: my $num_tries = 0;
3297: if ($$record{'version'}) {
3298: for (my $version=$$record{'version'};$version>=1;$version--) {
3299: if (exists($$record{$version.':resource.'.$part.'.solved'})) {
3300: $timestamp = $$record{$version.':timestamp'};
3301: if ($timestamp > $last_reset) {
3302: $num_tries ++;
3303: } else {
3304: last;
3305: }
3306: }
3307: }
3308: }
3309: return $num_tries;
3310: }
3311:
3312: # ----------- Determine decrements required in aggregate totals
3313: sub decrement_aggs {
3314: my ($symb,$part,$aggregate,$aggtries,$totaltries,$solvedstatus) = @_;
3315: my %decrement = (
3316: attempts => 0,
3317: users => 0,
3318: correct => 0
3319: );
3320: $decrement{'attempts'} = $aggtries;
3321: if ($solvedstatus =~ /^correct/) {
3322: $decrement{'correct'} = 1;
3323: }
3324: if ($aggtries == $totaltries) {
3325: $decrement{'users'} = 1;
3326: }
1.524 raeburn 3327: foreach my $type (keys(%decrement)) {
1.269 raeburn 3328: $$aggregate{$symb."\0".$part."\0".$type} = -$decrement{$type};
3329: }
3330: return;
3331: }
3332:
3333: # ----------- Determine timestamps for last reset of aggregate totals for parts
3334: sub get_last_resets {
1.270 albertel 3335: my ($symb,$courseid,$partids) =@_;
3336: my %last_resets;
1.269 raeburn 3337: my $cdom = $env{'course.'.$courseid.'.domain'};
3338: my $cname = $env{'course.'.$courseid.'.num'};
1.271 albertel 3339: my @keys;
3340: foreach my $part (@{$partids}) {
3341: push(@keys,"$symb\0$part\0resettime");
3342: }
3343: my %results=&Apache::lonnet::get('nohist_resourcetracker',\@keys,
3344: $cdom,$cname);
3345: foreach my $part (@{$partids}) {
3346: $last_resets{$part}=$results{"$symb\0$part\0resettime"};
1.269 raeburn 3347: }
1.270 albertel 3348: return %last_resets;
1.269 raeburn 3349: }
3350:
1.251 banghart 3351: # ----------- Handles creating versions for portfolio files as answers
3352: sub version_portfiles {
1.343 banghart 3353: my ($record, $parts_graded, $courseid, $symb, $domain, $stu_name, $v_flag) = @_;
1.263 banghart 3354: my $version_parts = join('|',@$v_flag);
1.343 banghart 3355: my @returned_keys;
1.255 banghart 3356: my $parts = join('|', @$parts_graded);
1.517 raeburn 3357: my $portfolio_root = '/userfiles/portfolio';
1.277 albertel 3358: foreach my $key (keys(%$record)) {
1.259 banghart 3359: my $new_portfiles;
1.263 banghart 3360: if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
1.342 banghart 3361: my @versioned_portfiles;
1.367 albertel 3362: my @portfiles = split(/\s*,\s*/,$$record{$key});
1.252 banghart 3363: foreach my $file (@portfiles) {
1.306 banghart 3364: &Apache::lonnet::unmark_as_readonly($domain,$stu_name,[$symb,$env{'request.course.id'}],$file);
1.304 albertel 3365: my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*)$/);
3366: my ($answer_name,$answer_ver,$answer_ext) =
3367: &file_name_version_ext($answer_file);
1.596.2.12.2. (raeburn 3368:): my $getpropath = 1;
3369:): my ($dir_list,$listerror) =
3370:): &Apache::lonnet::dirlist($portfolio_root.$directory,$domain,
3371:): $stu_name,$getpropath);
3372:): my $version = &get_next_version($answer_name,$answer_ext,$dir_list);
1.306 banghart 3373: my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version);
3374: if ($new_answer ne 'problem getting file') {
1.342 banghart 3375: push(@versioned_portfiles, $directory.$new_answer);
1.306 banghart 3376: &Apache::lonnet::mark_as_readonly($domain,$stu_name,
1.367 albertel 3377: [$directory.$new_answer],
1.306 banghart 3378: [$symb,$env{'request.course.id'},'graded']);
1.259 banghart 3379: }
1.252 banghart 3380: }
1.343 banghart 3381: $$record{$key} = join(',',@versioned_portfiles);
3382: push(@returned_keys,$key);
1.251 banghart 3383: }
3384: }
1.343 banghart 3385: return (@returned_keys);
1.305 banghart 3386: }
3387:
1.307 banghart 3388: sub get_next_version {
1.341 banghart 3389: my ($answer_name, $answer_ext, $dir_list) = @_;
1.307 banghart 3390: my $version;
1.596.2.12.2. (raeburn 3391:): if (ref($dir_list) eq 'ARRAY') {
3392:): foreach my $row (@{$dir_list}) {
3393:): my ($file) = split(/\&/,$row,2);
3394:): my ($file_name,$file_version,$file_ext) =
3395:): &file_name_version_ext($file);
3396:): if (($file_name eq $answer_name) &&
3397:): ($file_ext eq $answer_ext)) {
3398:): # gets here if filename and extension match,
3399:): # regardless of version
1.307 banghart 3400: if ($file_version ne '') {
1.596.2.12.2. (raeburn 3401:): # a versioned file is found so save it for later
3402:): if ($file_version > $version) {
3403:): $version = $file_version;
3404:): }
1.307 banghart 3405: }
3406: }
3407: }
1.596.2.12.2. (raeburn 3408:): }
1.307 banghart 3409: $version ++;
3410: return($version);
3411: }
3412:
1.305 banghart 3413: sub version_selected_portfile {
1.306 banghart 3414: my ($domain,$stu_name,$directory,$file_name,$version) = @_;
3415: my ($answer_name,$answer_ver,$answer_ext) =
3416: &file_name_version_ext($file_name);
3417: my $new_answer;
3418: $env{'form.copy'} = &Apache::lonnet::getfile("/uploaded/$domain/$stu_name/portfolio$directory$file_name");
3419: if($env{'form.copy'} eq '-1') {
3420: $new_answer = 'problem getting file';
3421: } else {
3422: $new_answer = $answer_name.'.'.$version.'.'.$answer_ext;
3423: my $copy_result = &Apache::lonnet::finishuserfileupload(
3424: $stu_name,$domain,'copy',
3425: '/portfolio'.$directory.$new_answer);
3426: }
3427: return ($new_answer);
1.251 banghart 3428: }
3429:
1.304 albertel 3430: sub file_name_version_ext {
3431: my ($file)=@_;
3432: my @file_parts = split(/\./, $file);
3433: my ($name,$version,$ext);
3434: if (@file_parts > 1) {
3435: $ext=pop(@file_parts);
3436: if (@file_parts > 1 && $file_parts[-1] =~ /^\d+$/) {
3437: $version=pop(@file_parts);
3438: }
3439: $name=join('.',@file_parts);
3440: } else {
3441: $name=join('.',@file_parts);
3442: }
3443: return($name,$version,$ext);
3444: }
3445:
1.44 ng 3446: #--------------------------------------------------------------------------------------
3447: #
3448: #-------------------------- Next few routines handles grading by section or whole class
3449: #
3450: #--- Javascript to handle grading by section or whole class
1.42 ng 3451: sub viewgrades_js {
3452: my ($request) = shift;
3453:
1.539 riegler 3454: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
1.41 ng 3455: $request->print(<<VIEWJAVASCRIPT);
3456: <script type="text/javascript" language="javascript">
1.45 ng 3457: function writePoint(partid,weight,point) {
1.125 ng 3458: var radioButton = document.classgrade["RADVAL_"+partid];
3459: var textbox = document.classgrade["TEXTVAL_"+partid];
1.42 ng 3460: if (point == "textval") {
1.125 ng 3461: point = document.classgrade["TEXTVAL_"+partid].value;
1.109 matthew 3462: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 3463: alert("$alertmsg"+parseFloat(point));
1.42 ng 3464: var resetbox = false;
3465: for (var i=0; i<radioButton.length; i++) {
3466: if (radioButton[i].checked) {
3467: textbox.value = i;
3468: resetbox = true;
3469: }
3470: }
3471: if (!resetbox) {
3472: textbox.value = "";
3473: }
3474: return;
3475: }
1.109 matthew 3476: if (parseFloat(point) > parseFloat(weight)) {
3477: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 3478: ") greater than the weight for the part. Accept?");
3479: if (resp == false) {
3480: textbox.value = "";
3481: return;
3482: }
3483: }
1.42 ng 3484: for (var i=0; i<radioButton.length; i++) {
3485: radioButton[i].checked=false;
1.109 matthew 3486: if (parseFloat(point) == i) {
1.42 ng 3487: radioButton[i].checked=true;
3488: }
3489: }
1.41 ng 3490:
1.42 ng 3491: } else {
1.125 ng 3492: textbox.value = parseFloat(point);
1.42 ng 3493: }
1.41 ng 3494: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3495: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3496: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3497: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3498: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3499: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 3500: if (saveval != "correct") {
3501: scorename.value = point;
1.43 ng 3502: if (selname[0].selected != true) {
3503: selname[0].selected = true;
3504: }
1.42 ng 3505: }
3506: }
1.125 ng 3507: document.classgrade["SELVAL_"+partid][0].selected = true;
1.42 ng 3508: }
3509:
3510: function writeRadText(partid,weight) {
1.125 ng 3511: var selval = document.classgrade["SELVAL_"+partid];
3512: var radioButton = document.classgrade["RADVAL_"+partid];
1.265 www 3513: var override = document.classgrade["FORCE_"+partid].checked;
1.125 ng 3514: var textbox = document.classgrade["TEXTVAL_"+partid];
3515: if (selval[1].selected || selval[2].selected) {
1.42 ng 3516: for (var i=0; i<radioButton.length; i++) {
3517: radioButton[i].checked=false;
3518:
3519: }
3520: textbox.value = "";
3521:
3522: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3523: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3524: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3525: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3526: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3527: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 3528: if ((saveval != "correct") || override) {
1.42 ng 3529: scorename.value = "";
1.125 ng 3530: if (selval[1].selected) {
3531: selname[1].selected = true;
3532: } else {
3533: selname[2].selected = true;
3534: if (Number(document.classgrade["GD_"+user+"_"+partid+"_tries"].value))
3535: {document.classgrade["GD_"+user+"_"+partid+"_tries"].value = '0';}
3536: }
1.42 ng 3537: }
3538: }
1.43 ng 3539: } else {
3540: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3541: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3542: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3543: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3544: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3545: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 3546: if ((saveval != "correct") || override) {
1.125 ng 3547: scorename.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
1.43 ng 3548: selname[0].selected = true;
3549: }
3550: }
3551: }
1.42 ng 3552: }
3553:
3554: function changeSelect(partid,user) {
1.125 ng 3555: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
3556: var textbox = document.classgrade["GD_"+user+'_'+partid+"_awarded"];
1.44 ng 3557: var point = textbox.value;
1.125 ng 3558: var weight = document.classgrade["weight_"+partid].value;
1.44 ng 3559:
1.109 matthew 3560: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 3561: alert("$alertmsg"+parseFloat(point));
1.44 ng 3562: textbox.value = "";
3563: return;
3564: }
1.109 matthew 3565: if (parseFloat(point) > parseFloat(weight)) {
3566: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 3567: ") greater than the weight of the part. Accept?");
3568: if (resp == false) {
3569: textbox.value = "";
3570: return;
3571: }
3572: }
1.42 ng 3573: selval[0].selected = true;
3574: }
3575:
3576: function changeOneScore(partid,user) {
1.125 ng 3577: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
3578: if (selval[1].selected || selval[2].selected) {
3579: document.classgrade["GD_"+user+'_'+partid+"_awarded"].value = "";
3580: if (selval[2].selected) {
3581: document.classgrade["GD_"+user+'_'+partid+"_tries"].value = "0";
3582: }
1.269 raeburn 3583: }
1.42 ng 3584: }
3585:
3586: function resetEntry(numpart) {
3587: for (ctpart=0;ctpart<numpart;ctpart++) {
1.125 ng 3588: var partid = document.classgrade["partid_"+ctpart].value;
3589: var radioButton = document.classgrade["RADVAL_"+partid];
3590: var textbox = document.classgrade["TEXTVAL_"+partid];
3591: var selval = document.classgrade["SELVAL_"+partid];
1.42 ng 3592: for (var i=0; i<radioButton.length; i++) {
3593: radioButton[i].checked=false;
3594:
3595: }
3596: textbox.value = "";
3597: selval[0].selected = true;
3598:
3599: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3600: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3601: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3602: var resetscore = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3603: resetscore.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
3604: var resettries = document.classgrade["GD_"+user+"_"+partid+"_tries"];
3605: resettries.value = document.classgrade["GD_"+user+"_"+partid+"_tries_s"].value;
3606: var saveselval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3607: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 3608: if (saveselval == "excused") {
1.43 ng 3609: if (selname[1].selected == false) { selname[1].selected = true;}
1.42 ng 3610: } else {
1.43 ng 3611: if (selname[0].selected == false) {selname[0].selected = true};
1.42 ng 3612: }
3613: }
1.41 ng 3614: }
1.42 ng 3615: }
3616:
1.41 ng 3617: </script>
3618: VIEWJAVASCRIPT
1.42 ng 3619: }
3620:
1.44 ng 3621: #--- show scores for a section or whole class w/ option to change/update a score
1.42 ng 3622: sub viewgrades {
3623: my ($request) = shift;
3624: &viewgrades_js($request);
1.41 ng 3625:
1.324 albertel 3626: my ($symb) = &get_symb($request);
1.168 albertel 3627: #need to make sure we have the correct data for later EXT calls,
3628: #thus invalidate the cache
3629: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 3630: $env{'course.'.$env{'request.course.id'}.'.num'},
3631: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 3632: &Apache::lonnet::clear_EXT_cache_status();
3633:
1.398 albertel 3634: my $result='<h3><span class="LC_info">'.&mt('Manual Grading').'</span></h3>';
1.485 albertel 3635: $result.='<h4>'.&mt('<b>Current Resource: </b>[_1]',$env{'form.probTitle'}).'</h4>'."\n";
1.41 ng 3636:
3637: #view individual student submission form - called using Javascript viewOneStudent
1.324 albertel 3638: $result.=&jscriptNform($symb);
1.41 ng 3639:
1.44 ng 3640: #beginning of class grading form
1.442 banghart 3641: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.41 ng 3642: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1.418 albertel 3643: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.38 ng 3644: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.432 banghart 3645: &build_section_inputs().
1.257 albertel 3646: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.442 banghart 3647: '<input type="hidden" name="Status" value="'.$env{'stu_status'}.'" />'."\n".
1.257 albertel 3648: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.72 ng 3649:
1.560 raeburn 3650: my ($common_header,$specific_header);
1.257 albertel 3651: if ($env{'form.section'} eq 'all') {
1.560 raeburn 3652: $common_header = &mt('Assign Common Grade to Class');
3653: $specific_header = &mt('Assign Grade to Specific Students in Class');
1.257 albertel 3654: } elsif ($env{'form.section'} eq 'none') {
1.560 raeburn 3655: $common_header = &mt('Assign Common Grade to Students in no Section');
3656: $specific_header = &mt('Assign Grade to Specific Students in no Section');
1.52 albertel 3657: } else {
1.560 raeburn 3658: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
3659: $common_header = &mt('Assign Common Grade to Students in Section(s) [_1]',$section_display);
3660: $specific_header = &mt('Assign Grade to Specific Students in Section(s) [_1]',$section_display);
1.52 albertel 3661: }
1.560 raeburn 3662: $result.= '<h3>'.$common_header.'</h3>'.&Apache::loncommon::start_data_table();
1.44 ng 3663: #radio buttons/text box for assigning points for a section or class.
3664: #handles different parts of a problem
1.582 raeburn 3665: my $res_error;
3666: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
3667: if ($res_error) {
3668: return &navmap_errormsg();
3669: }
1.42 ng 3670: my %weight = ();
3671: my $ctsparts = 0;
1.45 ng 3672: my %seen = ();
1.375 albertel 3673: my @part_response_id = &flatten_responseType($responseType);
3674: foreach my $part_response_id (@part_response_id) {
3675: my ($partid,$respid) = @{ $part_response_id };
3676: my $part_resp = join('_',@{ $part_response_id });
1.45 ng 3677: next if $seen{$partid};
3678: $seen{$partid}++;
1.375 albertel 3679: my $handgrade=$$handgrade{$part_resp};
1.42 ng 3680: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
3681: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
3682:
1.324 albertel 3683: my $display_part=&get_display_part($partid,$symb);
1.485 albertel 3684: my $radio.='<table border="0"><tr>';
1.41 ng 3685: my $ctr = 0;
1.42 ng 3686: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
1.485 albertel 3687: $radio.= '<td><label><input type="radio" name="RADVAL_'.$partid.'" '.
1.54 albertel 3688: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.288 albertel 3689: ','.$ctr.')" />'.$ctr."</label></td>\n";
1.41 ng 3690: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
3691: $ctr++;
3692: }
1.485 albertel 3693: $radio.='</tr></table>';
3694: my $line = '<input type="text" name="TEXTVAL_'.
1.589 bisitz 3695: $partid.'" size="4" '.'onchange="javascript:writePoint(\''.
1.54 albertel 3696: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.539 riegler 3697: $weight{$partid}.' '.&mt('(problem weight)').'</td>'."\n";
3698: $line.= '<td><b>'.&mt('Grade Status').':</b><select name="SELVAL_'.$partid.'"'.
1.589 bisitz 3699: 'onchange="javascript:writeRadText(\''.$partid.'\','.
1.59 albertel 3700: $weight{$partid}.')"> '.
1.401 albertel 3701: '<option selected="selected"> </option>'.
1.485 albertel 3702: '<option value="excused">'.&mt('excused').'</option>'.
3703: '<option value="reset status">'.&mt('reset status').'</option>'.
3704: '</select></td>'.
3705: '<td><label><input type="checkbox" name="FORCE_'.$partid.'" />'.&mt('Override "Correct"').'</label>';
3706: $line.='<input type="hidden" name="partid_'.
3707: $ctsparts.'" value="'.$partid.'" />'."\n";
3708: $line.='<input type="hidden" name="weight_'.
3709: $partid.'" value="'.$weight{$partid}.'" />'."\n";
3710:
3711: $result.=
3712: &Apache::loncommon::start_data_table_row()."\n".
1.577 bisitz 3713: '<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 3714: &Apache::loncommon::end_data_table_row()."\n";
1.42 ng 3715: $ctsparts++;
1.41 ng 3716: }
1.474 albertel 3717: $result.=&Apache::loncommon::end_data_table()."\n".
1.52 albertel 3718: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.485 albertel 3719: $result.='<input type="button" value="'.&mt('Revert to Default').'" '.
1.589 bisitz 3720: 'onclick="javascript:resetEntry('.$ctsparts.');" />';
1.41 ng 3721:
1.44 ng 3722: #table listing all the students in a section/class
3723: #header of table
1.560 raeburn 3724: $result.= '<h3>'.$specific_header.'</h3>'.
3725: &Apache::loncommon::start_data_table().
3726: &Apache::loncommon::start_data_table_header_row().
3727: '<th>'.&mt('No.').'</th>'.
3728: '<th>'.&nameUserString('header')."</th>\n";
1.582 raeburn 3729: my $partserror;
3730: my (@parts) = sort(&getpartlist($symb,\$partserror));
3731: if ($partserror) {
3732: return &navmap_errormsg();
3733: }
1.324 albertel 3734: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.269 raeburn 3735: my @partids = ();
1.41 ng 3736: foreach my $part (@parts) {
3737: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1.539 riegler 3738: my $narrowtext = &mt('Tries');
3739: $display =~ s|^Number of Attempts|$narrowtext <br />|; # makes the column narrower
1.41 ng 3740: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
1.207 albertel 3741: my ($partid) = &split_part_type($part);
1.524 raeburn 3742: push(@partids,$partid);
1.324 albertel 3743: my $display_part=&get_display_part($partid,$symb);
1.41 ng 3744: if ($display =~ /^Partial Credit Factor/) {
1.485 albertel 3745: $result.='<th>'.
3746: &mt('Score Part: [_1]<br /> (weight = [_2])',
3747: $display_part,$weight{$partid}).'</th>'."\n";
1.41 ng 3748: next;
1.485 albertel 3749:
1.207 albertel 3750: } else {
1.485 albertel 3751: if ($display =~ /Problem Status/) {
3752: my $grade_status_mt = &mt('Grade Status');
3753: $display =~ s{Problem Status}{$grade_status_mt<br />};
3754: }
3755: my $part_mt = &mt('Part:');
3756: $display =~s{\[Part: \Q$partid\E\]}{$part_mt $display_part};
1.41 ng 3757: }
1.485 albertel 3758:
1.474 albertel 3759: $result.='<th>'.$display.'</th>'."\n";
1.41 ng 3760: }
1.474 albertel 3761: $result.=&Apache::loncommon::end_data_table_header_row();
1.44 ng 3762:
1.270 albertel 3763: my %last_resets =
3764: &get_last_resets($symb,$env{'request.course.id'},\@partids);
1.269 raeburn 3765:
1.41 ng 3766: #get info for each student
1.44 ng 3767: #list all the students - with points and grade status
1.257 albertel 3768: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
1.41 ng 3769: my $ctr = 0;
1.294 albertel 3770: foreach (sort
3771: {
3772: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
3773: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
3774: }
3775: return $a cmp $b;
3776: } (keys(%$fullname))) {
1.126 ng 3777: $ctr++;
1.324 albertel 3778: $result.=&viewstudentgrade($symb,$env{'request.course.id'},
1.269 raeburn 3779: $_,$$fullname{$_},\@parts,\%weight,$ctr,\%last_resets);
1.41 ng 3780: }
1.474 albertel 3781: $result.=&Apache::loncommon::end_data_table();
1.41 ng 3782: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.485 albertel 3783: $result.='<input type="button" value="'.&mt('Save').'" '.
1.589 bisitz 3784: 'onclick="javascript:submit();" target="_self" /></form>'."\n";
1.96 albertel 3785: if (scalar(%$fullname) eq 0) {
3786: my $colspan=3+scalar(@parts);
1.433 banghart 3787: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.442 banghart 3788: my $stu_status = join(' or ',&Apache::loncommon::get_env_multiple('form.Status'));
1.433 banghart 3789: $result='<span class="LC_warning">'.
1.485 albertel 3790: &mt('There are no students in section(s) [_1] with enrollment status [_2] to modify or grade.',
1.442 banghart 3791: $section_display, $stu_status).
1.433 banghart 3792: '</span>';
1.96 albertel 3793: }
1.324 albertel 3794: $result.=&show_grading_menu_form($symb);
1.41 ng 3795: return $result;
3796: }
3797:
1.44 ng 3798: #--- call by previous routine to display each student
1.41 ng 3799: sub viewstudentgrade {
1.324 albertel 3800: my ($symb,$courseid,$student,$fullname,$parts,$weight,$ctr,$last_resets) = @_;
1.44 ng 3801: my ($uname,$udom) = split(/:/,$student);
3802: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.269 raeburn 3803: my %aggregates = ();
1.474 albertel 3804: my $result=&Apache::loncommon::start_data_table_row().'<td align="right">'.
1.233 albertel 3805: '<input type="hidden" name="ctr'.($ctr-1).'" value="'.$student.'" />'.
3806: "\n".$ctr.' </td><td> '.
1.44 ng 3807: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 3808: '\');" target="_self">'.$fullname.'</a> '.
1.398 albertel 3809: '<span class="LC_internal_info">('.$uname.($env{'user.domain'} eq $udom ? '' : ':'.$udom).')</span></td>'."\n";
1.281 albertel 3810: $student=~s/:/_/; # colon doen't work in javascript for names
1.63 albertel 3811: foreach my $apart (@$parts) {
3812: my ($part,$type) = &split_part_type($apart);
1.41 ng 3813: my $score=$record{"resource.$part.$type"};
1.276 albertel 3814: $result.='<td align="center">';
1.269 raeburn 3815: my ($aggtries,$totaltries);
3816: unless (exists($aggregates{$part})) {
1.270 albertel 3817: $totaltries = $record{'resource.'.$part.'.tries'};
3818:
3819: $aggtries = $totaltries;
1.269 raeburn 3820: if ($$last_resets{$part}) {
1.270 albertel 3821: $aggtries = &get_num_tries(\%record,$$last_resets{$part},
3822: $part);
3823: }
1.269 raeburn 3824: $result.='<input type="hidden" name="'.
3825: 'GD_'.$student.'_'.$part.'_aggtries" value="'.$aggtries.'" />'."\n";
3826: $result.='<input type="hidden" name="'.
3827: 'GD_'.$student.'_'.$part.'_totaltries" value="'.$totaltries.'" />'."\n";
3828: $aggregates{$part} = 1;
3829: }
1.41 ng 3830: if ($type eq 'awarded') {
1.320 albertel 3831: my $pts = $score eq '' ? '' : &compute_points($score,$$weight{$part});
1.42 ng 3832: $result.='<input type="hidden" name="'.
1.89 albertel 3833: 'GD_'.$student.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.233 albertel 3834: $result.='<input type="text" name="'.
1.89 albertel 3835: 'GD_'.$student.'_'.$part.'_awarded" '.
1.589 bisitz 3836: 'onchange="javascript:changeSelect(\''.$part.'\',\''.$student.
1.44 ng 3837: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41 ng 3838: } elsif ($type eq 'solved') {
3839: my ($status,$foo)=split(/_/,$score,2);
3840: $status = 'nothing' if ($status eq '');
1.89 albertel 3841: $result.='<input type="hidden" name="'.'GD_'.$student.'_'.
1.54 albertel 3842: $part.'_solved_s" value="'.$status.'" />'."\n";
1.233 albertel 3843: $result.=' <select name="'.
1.89 albertel 3844: 'GD_'.$student.'_'.$part.'_solved" '.
1.589 bisitz 3845: 'onchange="javascript:changeOneScore(\''.$part.'\',\''.$student.'\')" >'."\n";
1.485 albertel 3846: $result.= (($status eq 'excused') ? '<option> </option><option selected="selected" value="excused">'.&mt('excused').'</option>'
3847: : '<option selected="selected"> </option><option value="excused">'.&mt('excused').'</option>')."\n";
3848: $result.='<option value="reset status">'.&mt('reset status').'</option>';
1.126 ng 3849: $result.="</select> </td>\n";
1.122 ng 3850: } else {
3851: $result.='<input type="hidden" name="'.
3852: 'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
3853: "\n";
1.233 albertel 3854: $result.='<input type="text" name="'.
1.122 ng 3855: 'GD_'.$student.'_'.$part.'_'.$type.'" '.
3856: 'value="'.$score.'" size="4" /></td>'."\n";
1.41 ng 3857: }
3858: }
1.474 albertel 3859: $result.=&Apache::loncommon::end_data_table_row();
1.41 ng 3860: return $result;
1.38 ng 3861: }
3862:
1.44 ng 3863: #--- change scores for all the students in a section/class
3864: # record does not get update if unchanged
1.38 ng 3865: sub editgrades {
1.41 ng 3866: my ($request) = @_;
3867:
1.596.2.12.2. (raeburn 3868:): my ($symb)=&get_symb($request);
1.433 banghart 3869: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.477 albertel 3870: my $title='<h2>'.&mt('Current Grade Status').'</h2>';
3871: $title.='<h4>'.&mt('<b>Current Resource: </b>[_1]',$env{'form.probTitle'}).'</h4>'."\n";
1.433 banghart 3872: $title.='<h4>'.&mt('<b>Section: </b>[_1]',$section_display).'</h4>'."\n";
1.126 ng 3873:
1.477 albertel 3874: my $result= &Apache::loncommon::start_data_table().
3875: &Apache::loncommon::start_data_table_header_row().
3876: '<th rowspan="2" valign="middle">'.&mt('No.').'</th>'.
3877: '<th rowspan="2" valign="middle">'.&nameUserString('header')."</th>\n";
1.43 ng 3878: my %scoreptr = (
3879: 'correct' =>'correct_by_override',
3880: 'incorrect'=>'incorrect_by_override',
3881: 'excused' =>'excused',
3882: 'ungraded' =>'ungraded_attempted',
1.596 raeburn 3883: 'credited' =>'credit_attempted',
1.43 ng 3884: 'nothing' => '',
3885: );
1.257 albertel 3886: my ($classlist,undef,$fullname) = &getclasslist($env{'form.section'},'0');
1.34 ng 3887:
1.44 ng 3888: my (@partid);
3889: my %weight = ();
1.54 albertel 3890: my %columns = ();
1.44 ng 3891: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54 albertel 3892:
1.582 raeburn 3893: my $partserror;
3894: my (@parts) = sort(&getpartlist($symb,\$partserror));
3895: if ($partserror) {
3896: return &navmap_errormsg();
3897: }
1.54 albertel 3898: my $header;
1.257 albertel 3899: while ($ctr < $env{'form.totalparts'}) {
3900: my $partid = $env{'form.partid_'.$ctr};
1.524 raeburn 3901: push(@partid,$partid);
1.257 albertel 3902: $weight{$partid} = $env{'form.weight_'.$partid};
1.44 ng 3903: $ctr++;
1.54 albertel 3904: }
1.324 albertel 3905: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.54 albertel 3906: foreach my $partid (@partid) {
1.478 albertel 3907: $header .= '<th align="center">'.&mt('Old Score').'</th>'.
3908: '<th align="center">'.&mt('New Score').'</th>';
1.54 albertel 3909: $columns{$partid}=2;
3910: foreach my $stores (@parts) {
3911: my ($part,$type) = &split_part_type($stores);
3912: if ($part !~ m/^\Q$partid\E/) { next;}
3913: if ($type eq 'awarded' || $type eq 'solved') { next; }
3914: my $display=&Apache::lonnet::metadata($url,$stores.'.display');
1.551 raeburn 3915: $display =~ s/\[Part: \Q$part\E\]//;
1.539 riegler 3916: my $narrowtext = &mt('Tries');
3917: $display =~ s/Number of Attempts/$narrowtext/;
3918: $header .= '<th align="center">'.&mt('Old').' '.$display.'</th>'.
3919: '<th align="center">'.&mt('New').' '.$display.'</th>';
1.54 albertel 3920: $columns{$partid}+=2;
3921: }
3922: }
3923: foreach my $partid (@partid) {
1.324 albertel 3924: my $display_part=&get_display_part($partid,$symb);
1.478 albertel 3925: $result .= '<th colspan="'.$columns{$partid}.'" align="center">'.
3926: &mt('Part: [_1] (Weight = [_2])',$display_part,$weight{$partid}).
3927: '</th>';
1.54 albertel 3928:
1.44 ng 3929: }
1.477 albertel 3930: $result .= &Apache::loncommon::end_data_table_header_row().
3931: &Apache::loncommon::start_data_table_header_row().
3932: $header.
3933: &Apache::loncommon::end_data_table_header_row();
3934: my @noupdate;
1.126 ng 3935: my ($updateCtr,$noupdateCtr) = (1,1);
1.257 albertel 3936: for ($i=0; $i<$env{'form.total'}; $i++) {
1.93 albertel 3937: my $line;
1.257 albertel 3938: my $user = $env{'form.ctr'.$i};
1.281 albertel 3939: my ($uname,$udom)=split(/:/,$user);
1.44 ng 3940: my %newrecord;
3941: my $updateflag = 0;
1.281 albertel 3942: $line .= '<td>'.&nameUserString(undef,$$fullname{$user},$uname,$udom).'</td>';
1.108 albertel 3943: my $usec=$classlist->{"$uname:$udom"}[5];
1.105 albertel 3944: if (!&canmodify($usec)) {
1.126 ng 3945: my $numcols=scalar(@partid)*4+2;
1.477 albertel 3946: push(@noupdate,
1.478 albertel 3947: $line."<td colspan=\"$numcols\"><span class=\"LC_warning\">".
3948: &mt('Not allowed to modify student')."</span></td></tr>");
1.105 albertel 3949: next;
3950: }
1.269 raeburn 3951: my %aggregate = ();
3952: my $aggregateflag = 0;
1.281 albertel 3953: $user=~s/:/_/; # colon doen't work in javascript for names
1.44 ng 3954: foreach (@partid) {
1.257 albertel 3955: my $old_aw = $env{'form.GD_'.$user.'_'.$_.'_awarded_s'};
1.54 albertel 3956: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
3957: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
1.257 albertel 3958: my $old_score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
3959: my $awarded = $env{'form.GD_'.$user.'_'.$_.'_awarded'};
1.54 albertel 3960: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
3961: my $partial = $awarded eq '' ? '' : $pcr;
1.44 ng 3962: my $score;
3963: if ($partial eq '') {
1.257 albertel 3964: $score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 3965: } elsif ($partial > 0) {
3966: $score = 'correct_by_override';
3967: } elsif ($partial == 0) {
3968: $score = 'incorrect_by_override';
3969: }
1.257 albertel 3970: my $dropMenu = $env{'form.GD_'.$user.'_'.$_.'_solved'};
1.125 ng 3971: $score = 'excused' if (($dropMenu eq 'excused') && ($score ne 'excused'));
3972:
1.292 albertel 3973: $newrecord{'resource.'.$_.'.regrader'}=
3974: "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 3975: if ($dropMenu eq 'reset status' &&
3976: $old_score ne '') { # ignore if no previous attempts => nothing to reset
1.299 albertel 3977: $newrecord{'resource.'.$_.'.tries'} = '';
1.125 ng 3978: $newrecord{'resource.'.$_.'.solved'} = '';
3979: $newrecord{'resource.'.$_.'.award'} = '';
1.299 albertel 3980: $newrecord{'resource.'.$_.'.awarded'} = '';
1.125 ng 3981: $updateflag = 1;
1.269 raeburn 3982: if ($env{'form.GD_'.$user.'_'.$_.'_aggtries'} > 0) {
3983: my $aggtries = $env{'form.GD_'.$user.'_'.$_.'_aggtries'};
3984: my $totaltries = $env{'form.GD_'.$user.'_'.$_.'_totaltries'};
3985: my $solvedstatus = $env{'form.GD_'.$user.'_'.$_.'_solved_s'};
3986: &decrement_aggs($symb,$_,\%aggregate,$aggtries,$totaltries,$solvedstatus);
3987: $aggregateflag = 1;
3988: }
1.139 albertel 3989: } elsif (!($old_part eq $partial && $old_score eq $score)) {
3990: $updateflag = 1;
3991: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
3992: $newrecord{'resource.'.$_.'.solved'} = $score;
3993: $rec_update++;
1.125 ng 3994: }
3995:
1.93 albertel 3996: $line .= '<td align="center">'.$old_aw.' </td>'.
1.44 ng 3997: '<td align="center">'.$awarded.
3998: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 3999:
1.54 albertel 4000:
4001: my $partid=$_;
4002: foreach my $stores (@parts) {
4003: my ($part,$type) = &split_part_type($stores);
4004: if ($part !~ m/^\Q$partid\E/) { next;}
4005: if ($type eq 'awarded' || $type eq 'solved') { next; }
1.257 albertel 4006: my $old_aw = $env{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
4007: my $awarded = $env{'form.GD_'.$user.'_'.$part.'_'.$type};
1.54 albertel 4008: if ($awarded ne '' && $awarded ne $old_aw) {
4009: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.257 albertel 4010: $newrecord{'resource.'.$part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.54 albertel 4011: $updateflag=1;
4012: }
1.93 albertel 4013: $line .= '<td align="center">'.$old_aw.' </td>'.
1.54 albertel 4014: '<td align="center">'.$awarded.' </td>';
4015: }
1.44 ng 4016: }
1.477 albertel 4017: $line.="\n";
1.301 albertel 4018:
4019: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4020: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4021:
1.44 ng 4022: if ($updateflag) {
4023: $count++;
1.257 albertel 4024: &Apache::lonnet::cstore(\%newrecord,$symb,$env{'request.course.id'},
1.89 albertel 4025: $udom,$uname);
1.301 albertel 4026:
4027: if (&Apache::bridgetask::in_queue('gradingqueue',$symb,$cdom,
4028: $cnum,$udom,$uname)) {
4029: # need to figure out if should be in queue.
4030: my %record =
4031: &Apache::lonnet::restore($symb,$env{'request.course.id'},
4032: $udom,$uname);
4033: my $all_graded = 1;
4034: my $none_graded = 1;
4035: foreach my $part (@parts) {
4036: if ( $record{'resource.'.$part.'.awarded'} eq '' ) {
4037: $all_graded = 0;
4038: } else {
4039: $none_graded = 0;
4040: }
4041: }
4042:
4043: if ($all_graded || $none_graded) {
4044: &Apache::bridgetask::remove_from_queue('gradingqueue',
4045: $symb,$cdom,$cnum,
4046: $udom,$uname);
4047: }
4048: }
4049:
1.477 albertel 4050: $result.=&Apache::loncommon::start_data_table_row().
4051: '<td align="right"> '.$updateCtr.' </td>'.$line.
4052: &Apache::loncommon::end_data_table_row();
1.126 ng 4053: $updateCtr++;
1.93 albertel 4054: } else {
1.477 albertel 4055: push(@noupdate,
4056: '<td align="right"> '.$noupdateCtr.' </td>'.$line);
1.126 ng 4057: $noupdateCtr++;
1.44 ng 4058: }
1.269 raeburn 4059: if ($aggregateflag) {
4060: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 4061: $cdom,$cnum);
1.269 raeburn 4062: }
1.93 albertel 4063: }
1.477 albertel 4064: if (@noupdate) {
1.126 ng 4065: # my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3;
4066: my $numcols=scalar(@partid)*4+2;
1.477 albertel 4067: $result .= &Apache::loncommon::start_data_table_row('LC_empty_row').
1.478 albertel 4068: '<td align="center" colspan="'.$numcols.'">'.
4069: &mt('No Changes Occurred For the Students Below').
4070: '</td>'.
1.477 albertel 4071: &Apache::loncommon::end_data_table_row();
4072: foreach my $line (@noupdate) {
4073: $result.=
4074: &Apache::loncommon::start_data_table_row().
4075: $line.
4076: &Apache::loncommon::end_data_table_row();
4077: }
1.44 ng 4078: }
1.477 albertel 4079: $result .= &Apache::loncommon::end_data_table().
4080: &show_grading_menu_form($symb);
1.478 albertel 4081: my $msg = '<p><b>'.
4082: &mt('Number of records updated = [_1] for [quant,_2,student].',
4083: $rec_update,$count).'</b><br />'.
4084: '<b>'.&mt('Total number of students = [_1]',$env{'form.total'}).
4085: '</b></p>';
1.44 ng 4086: return $title.$msg.$result;
1.5 albertel 4087: }
1.54 albertel 4088:
4089: sub split_part_type {
4090: my ($partstr) = @_;
4091: my ($temp,@allparts)=split(/_/,$partstr);
4092: my $type=pop(@allparts);
1.439 albertel 4093: my $part=join('_',@allparts);
1.54 albertel 4094: return ($part,$type);
4095: }
4096:
1.44 ng 4097: #------------- end of section for handling grading by section/class ---------
4098: #
4099: #----------------------------------------------------------------------------
4100:
1.5 albertel 4101:
1.44 ng 4102: #----------------------------------------------------------------------------
4103: #
4104: #-------------------------- Next few routines handles grading by csv upload
4105: #
4106: #--- Javascript to handle csv upload
1.27 albertel 4107: sub csvupload_javascript_reverse_associate {
1.573 bisitz 4108: my $error1=&mt('You need to specify the username or the student/employee ID');
1.246 albertel 4109: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 4110: return(<<ENDPICK);
4111: function verify(vf) {
4112: var foundsomething=0;
4113: var founduname=0;
1.243 albertel 4114: var foundID=0;
1.27 albertel 4115: for (i=0;i<=vf.nfields.value;i++) {
4116: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 4117: if (i==0 && tw!=0) { foundID=1; }
4118: if (i==1 && tw!=0) { founduname=1; }
4119: if (i!=0 && i!=1 && i!=2 && tw!=0) { foundsomething=1; }
1.27 albertel 4120: }
1.246 albertel 4121: if (founduname==0 && foundID==0) {
4122: alert('$error1');
4123: return;
1.27 albertel 4124: }
4125: if (foundsomething==0) {
1.246 albertel 4126: alert('$error2');
4127: return;
1.27 albertel 4128: }
4129: vf.submit();
4130: }
4131: function flip(vf,tf) {
4132: var nw=eval('vf.f'+tf+'.selectedIndex');
4133: var i;
4134: for (i=0;i<=vf.nfields.value;i++) {
4135: //can not pick the same destination field for both name and domain
4136: if (((i ==0)||(i ==1)) &&
4137: ((tf==0)||(tf==1)) &&
4138: (i!=tf) &&
4139: (eval('vf.f'+i+'.selectedIndex')==nw)) {
4140: eval('vf.f'+i+'.selectedIndex=0;')
4141: }
4142: }
4143: }
4144: ENDPICK
4145: }
4146:
4147: sub csvupload_javascript_forward_associate {
1.573 bisitz 4148: my $error1=&mt('You need to specify the username or the student/employee ID');
1.246 albertel 4149: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 4150: return(<<ENDPICK);
4151: function verify(vf) {
4152: var foundsomething=0;
4153: var founduname=0;
1.243 albertel 4154: var foundID=0;
1.27 albertel 4155: for (i=0;i<=vf.nfields.value;i++) {
4156: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 4157: if (tw==1) { foundID=1; }
4158: if (tw==2) { founduname=1; }
4159: if (tw>3) { foundsomething=1; }
1.27 albertel 4160: }
1.246 albertel 4161: if (founduname==0 && foundID==0) {
4162: alert('$error1');
4163: return;
1.27 albertel 4164: }
4165: if (foundsomething==0) {
1.246 albertel 4166: alert('$error2');
4167: return;
1.27 albertel 4168: }
4169: vf.submit();
4170: }
4171: function flip(vf,tf) {
4172: var nw=eval('vf.f'+tf+'.selectedIndex');
4173: var i;
4174: //can not pick the same destination field twice
4175: for (i=0;i<=vf.nfields.value;i++) {
4176: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
4177: eval('vf.f'+i+'.selectedIndex=0;')
4178: }
4179: }
4180: }
4181: ENDPICK
4182: }
4183:
1.26 albertel 4184: sub csvuploadmap_header {
1.324 albertel 4185: my ($request,$symb,$datatoken,$distotal)= @_;
1.41 ng 4186: my $javascript;
1.257 albertel 4187: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 4188: $javascript=&csvupload_javascript_reverse_associate();
4189: } else {
4190: $javascript=&csvupload_javascript_forward_associate();
4191: }
1.45 ng 4192:
1.324 albertel 4193: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.257 albertel 4194: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1.245 albertel 4195: my $ignore=&mt('Ignore First Line');
1.418 albertel 4196: $symb = &Apache::lonenc::check_encrypt($symb);
1.41 ng 4197: $request->print(<<ENDPICK);
1.26 albertel 4198: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.398 albertel 4199: <h3><span class="LC_info">Uploading Class Grades</span></h3>
1.45 ng 4200: $result
1.326 albertel 4201: <hr />
1.26 albertel 4202: <h3>Identify fields</h3>
4203: Total number of records found in file: $distotal <hr />
4204: Enter as many fields as you can. The system will inform you and bring you back
4205: to this page if the data selected is insufficient to run your class.<hr />
1.589 bisitz 4206: <input type="button" value="Reverse Association" onclick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1.245 albertel 4207: <label><input type="checkbox" name="noFirstLine" $checked />$ignore</label>
1.26 albertel 4208: <input type="hidden" name="associate" value="" />
4209: <input type="hidden" name="phase" value="three" />
4210: <input type="hidden" name="datatoken" value="$datatoken" />
1.257 albertel 4211: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
4212: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
1.26 albertel 4213: <input type="hidden" name="upfile_associate"
1.257 albertel 4214: value="$env{'form.upfile_associate'}" />
1.26 albertel 4215: <input type="hidden" name="symb" value="$symb" />
1.257 albertel 4216: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
4217: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
1.246 albertel 4218: <input type="hidden" name="command" value="csvuploadoptions" />
1.26 albertel 4219: <hr />
4220: <script type="text/javascript" language="Javascript">
4221: $javascript
4222: </script>
4223: ENDPICK
1.118 ng 4224: return '';
1.26 albertel 4225:
4226: }
4227:
4228: sub csvupload_fields {
1.582 raeburn 4229: my ($symb,$errorref) = @_;
4230: my (@parts) = &getpartlist($symb,$errorref);
4231: if (ref($errorref)) {
4232: if ($$errorref) {
4233: return;
4234: }
4235: }
4236:
1.556 weissno 4237: my @fields=(['ID','Student/Employee ID'],
1.243 albertel 4238: ['username','Student Username'],
4239: ['domain','Student Domain']);
1.324 albertel 4240: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.41 ng 4241: foreach my $part (sort(@parts)) {
4242: my @datum;
4243: my $display=&Apache::lonnet::metadata($url,$part.'.display');
4244: my $name=$part;
4245: if (!$display) { $display = $name; }
4246: @datum=($name,$display);
1.244 albertel 4247: if ($name=~/^stores_(.*)_awarded/) {
4248: push(@fields,['stores_'.$1.'_points',"Points [Part: $1]"]);
4249: }
1.41 ng 4250: push(@fields,\@datum);
4251: }
4252: return (@fields);
1.26 albertel 4253: }
4254:
4255: sub csvuploadmap_footer {
1.41 ng 4256: my ($request,$i,$keyfields) =@_;
4257: $request->print(<<ENDPICK);
1.26 albertel 4258: </table>
4259: <input type="hidden" name="nfields" value="$i" />
4260: <input type="hidden" name="keyfields" value="$keyfields" />
1.589 bisitz 4261: <input type="button" onclick="javascript:verify(this.form)" value="Assign Grades" /><br />
1.26 albertel 4262: </form>
4263: ENDPICK
4264: }
4265:
1.283 albertel 4266: sub checkforfile_js {
1.539 riegler 4267: my $alertmsg = &mt('Please use the browse button to select a file from your local directory.');
1.86 ng 4268: my $result =<<CSVFORMJS;
4269: <script type="text/javascript" language="javascript">
4270: function checkUpload(formname) {
4271: if (formname.upfile.value == "") {
1.539 riegler 4272: alert("$alertmsg");
1.86 ng 4273: return false;
4274: }
4275: formname.submit();
4276: }
4277: </script>
4278: CSVFORMJS
1.283 albertel 4279: return $result;
4280: }
4281:
4282: sub upcsvScores_form {
4283: my ($request) = shift;
1.324 albertel 4284: my ($symb)=&get_symb($request);
1.283 albertel 4285: if (!$symb) {return '';}
4286: my $result=&checkforfile_js();
1.257 albertel 4287: $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
1.324 albertel 4288: my ($table) = &showResourceInfo($symb,$env{'form.probTitle'});
1.118 ng 4289: $result.=$table;
1.326 albertel 4290: $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
4291: $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
1.538 schulted 4292: $result.=' <b>'.&mt('Specify a file containing the class scores for current resource.').
4293: '</b></td></tr>'."\n";
1.596.2.4 raeburn 4294: $result.='<tr bgcolor="#ffffe6"><td>'."\n";
1.370 www 4295: my $upload=&mt("Upload Scores");
1.86 ng 4296: my $upfile_select=&Apache::loncommon::upfile_select_html();
1.245 albertel 4297: my $ignore=&mt('Ignore First Line');
1.418 albertel 4298: $symb = &Apache::lonenc::check_encrypt($symb);
1.86 ng 4299: $result.=<<ENDUPFORM;
1.106 albertel 4300: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.86 ng 4301: <input type="hidden" name="symb" value="$symb" />
4302: <input type="hidden" name="command" value="csvuploadmap" />
1.257 albertel 4303: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
4304: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
1.86 ng 4305: $upfile_select
1.589 bisitz 4306: <br /><input type="button" onclick="javascript:checkUpload(this.form);" value="$upload" />
1.283 albertel 4307: <label><input type="checkbox" name="noFirstLine" />$ignore</label>
1.86 ng 4308: </form>
4309: ENDUPFORM
1.370 www 4310: $result.=&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
4311: &mt("How do I create a CSV file from a spreadsheet"))
4312: .'</td></tr></table>'."\n";
1.86 ng 4313: $result.='</td></tr></table><br /><br />'."\n";
1.324 albertel 4314: $result.=&show_grading_menu_form($symb);
1.86 ng 4315: return $result;
4316: }
4317:
4318:
1.26 albertel 4319: sub csvuploadmap {
1.41 ng 4320: my ($request)= @_;
1.324 albertel 4321: my ($symb)=&get_symb($request);
1.41 ng 4322: if (!$symb) {return '';}
1.72 ng 4323:
1.41 ng 4324: my $datatoken;
1.257 albertel 4325: if (!$env{'form.datatoken'}) {
1.41 ng 4326: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 4327: } else {
1.257 albertel 4328: $datatoken=$env{'form.datatoken'};
1.41 ng 4329: &Apache::loncommon::load_tmp_file($request);
1.26 albertel 4330: }
1.41 ng 4331: my @records=&Apache::loncommon::upfile_record_sep();
1.257 albertel 4332: if ($env{'form.noFirstLine'}) { shift(@records); }
1.324 albertel 4333: &csvuploadmap_header($request,$symb,$datatoken,$#records+1);
1.41 ng 4334: my ($i,$keyfields);
4335: if (@records) {
1.582 raeburn 4336: my $fieldserror;
4337: my @fields=&csvupload_fields($symb,\$fieldserror);
4338: if ($fieldserror) {
4339: $request->print(&navmap_errormsg());
4340: return;
4341: }
1.257 albertel 4342: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 4343: &Apache::loncommon::csv_print_samples($request,\@records);
4344: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
4345: \@fields);
4346: foreach (@fields) { $keyfields.=$_->[0].','; }
4347: chop($keyfields);
4348: } else {
4349: unshift(@fields,['none','']);
4350: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
4351: \@fields);
1.311 banghart 4352: foreach my $rec (@records) {
4353: my %temp = &Apache::loncommon::record_sep($rec);
4354: if (%temp) {
4355: $keyfields=join(',',sort(keys(%temp)));
4356: last;
4357: }
4358: }
1.41 ng 4359: }
4360: }
4361: &csvuploadmap_footer($request,$i,$keyfields);
1.324 albertel 4362: $request->print(&show_grading_menu_form($symb));
1.72 ng 4363:
1.41 ng 4364: return '';
1.27 albertel 4365: }
4366:
1.246 albertel 4367: sub csvuploadoptions {
1.41 ng 4368: my ($request)= @_;
1.324 albertel 4369: my ($symb)=&get_symb($request);
1.257 albertel 4370: my $checked=(($env{'form.noFirstLine'})?'1':'0');
1.246 albertel 4371: my $ignore=&mt('Ignore First Line');
4372: $request->print(<<ENDPICK);
4373: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.398 albertel 4374: <h3><span class="LC_info">Uploading Class Grade Options</span></h3>
1.246 albertel 4375: <input type="hidden" name="command" value="csvuploadassign" />
1.302 albertel 4376: <!--
1.246 albertel 4377: <p>
4378: <label>
4379: <input type="checkbox" name="show_full_results" />
4380: Show a table of all changes
4381: </label>
4382: </p>
1.302 albertel 4383: -->
1.246 albertel 4384: <p>
4385: <label>
4386: <input type="checkbox" name="overwite_scores" checked="checked" />
4387: Overwrite any existing score
4388: </label>
4389: </p>
4390: ENDPICK
4391: my %fields=&get_fields();
4392: if (!defined($fields{'domain'})) {
1.257 albertel 4393: my $domform = &Apache::loncommon::select_dom_form($env{'request.role.domain'},'default_domain');
1.246 albertel 4394: $request->print("\n<p> Users are in domain: ".$domform."</p>\n");
4395: }
1.257 albertel 4396: foreach my $key (sort(keys(%env))) {
1.246 albertel 4397: if ($key !~ /^form\.(.*)$/) { next; }
4398: my $cleankey=$1;
4399: if ($cleankey eq 'command') { next; }
4400: $request->print('<input type="hidden" name="'.$cleankey.
1.257 albertel 4401: '" value="'.$env{$key}.'" />'."\n");
1.246 albertel 4402: }
4403: # FIXME do a check for any duplicated user ids...
4404: # FIXME do a check for any invalid user ids?...
1.290 albertel 4405: $request->print('<input type="submit" value="Assign Grades" /><br />
4406: <hr /></form>'."\n");
1.324 albertel 4407: $request->print(&show_grading_menu_form($symb));
1.246 albertel 4408: return '';
4409: }
4410:
4411: sub get_fields {
4412: my %fields;
1.257 albertel 4413: my @keyfields = split(/\,/,$env{'form.keyfields'});
4414: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
4415: if ($env{'form.upfile_associate'} eq 'reverse') {
4416: if ($env{'form.f'.$i} ne 'none') {
4417: $fields{$keyfields[$i]}=$env{'form.f'.$i};
1.41 ng 4418: }
4419: } else {
1.257 albertel 4420: if ($env{'form.f'.$i} ne 'none') {
4421: $fields{$env{'form.f'.$i}}=$keyfields[$i];
1.41 ng 4422: }
4423: }
1.27 albertel 4424: }
1.246 albertel 4425: return %fields;
4426: }
4427:
4428: sub csvuploadassign {
4429: my ($request)= @_;
1.324 albertel 4430: my ($symb)=&get_symb($request);
1.246 albertel 4431: if (!$symb) {return '';}
1.345 bowersj2 4432: my $error_msg = '';
1.246 albertel 4433: &Apache::loncommon::load_tmp_file($request);
4434: my @gradedata = &Apache::loncommon::upfile_record_sep();
1.257 albertel 4435: if ($env{'form.noFirstLine'}) { shift(@gradedata); }
1.246 albertel 4436: my %fields=&get_fields();
1.41 ng 4437: $request->print('<h3>Assigning Grades</h3>');
1.257 albertel 4438: my $courseid=$env{'request.course.id'};
1.97 albertel 4439: my ($classlist) = &getclasslist('all',0);
1.106 albertel 4440: my @notallowed;
1.41 ng 4441: my @skipped;
1.596.2.4 raeburn 4442: my @warnings;
1.41 ng 4443: my $countdone=0;
4444: foreach my $grade (@gradedata) {
4445: my %entries=&Apache::loncommon::record_sep($grade);
1.246 albertel 4446: my $domain;
4447: if ($entries{$fields{'domain'}}) {
4448: $domain=$entries{$fields{'domain'}};
4449: } else {
1.257 albertel 4450: $domain=$env{'form.default_domain'};
1.246 albertel 4451: }
1.243 albertel 4452: $domain=~s/\s//g;
1.41 ng 4453: my $username=$entries{$fields{'username'}};
1.160 albertel 4454: $username=~s/\s//g;
1.243 albertel 4455: if (!$username) {
4456: my $id=$entries{$fields{'ID'}};
1.247 albertel 4457: $id=~s/\s//g;
1.243 albertel 4458: my %ids=&Apache::lonnet::idget($domain,$id);
4459: $username=$ids{$id};
4460: }
1.41 ng 4461: if (!exists($$classlist{"$username:$domain"})) {
1.247 albertel 4462: my $id=$entries{$fields{'ID'}};
4463: $id=~s/\s//g;
4464: if ($id) {
4465: push(@skipped,"$id:$domain");
4466: } else {
4467: push(@skipped,"$username:$domain");
4468: }
1.41 ng 4469: next;
4470: }
1.108 albertel 4471: my $usec=$classlist->{"$username:$domain"}[5];
1.106 albertel 4472: if (!&canmodify($usec)) {
4473: push(@notallowed,"$username:$domain");
4474: next;
4475: }
1.244 albertel 4476: my %points;
1.41 ng 4477: my %grades;
4478: foreach my $dest (keys(%fields)) {
1.244 albertel 4479: if ($dest eq 'ID' || $dest eq 'username' ||
4480: $dest eq 'domain') { next; }
4481: if ($entries{$fields{$dest}} =~ /^\s*$/) { next; }
4482: if ($dest=~/stores_(.*)_points/) {
4483: my $part=$1;
4484: my $wgt =&Apache::lonnet::EXT('resource.'.$part.'.weight',
4485: $symb,$domain,$username);
1.345 bowersj2 4486: if ($wgt) {
4487: $entries{$fields{$dest}}=~s/\s//g;
4488: my $pcr=$entries{$fields{$dest}} / $wgt;
1.463 albertel 4489: my $award=($pcr == 0) ? 'incorrect_by_override'
4490: : 'correct_by_override';
1.596.2.4 raeburn 4491: if ($pcr>1) {
4492: push(@warnings,&mt("[_1]: point value larger than weight","$username:$domain"));
4493: }
1.345 bowersj2 4494: $grades{"resource.$part.awarded"}=$pcr;
4495: $grades{"resource.$part.solved"}=$award;
4496: $points{$part}=1;
4497: } else {
4498: $error_msg = "<br />" .
4499: &mt("Some point values were assigned"
4500: ." for problems with a weight "
4501: ."of zero. These values were "
4502: ."ignored.");
4503: }
1.244 albertel 4504: } else {
4505: if ($dest=~/stores_(.*)_awarded/) { if ($points{$1}) {next;} }
4506: if ($dest=~/stores_(.*)_solved/) { if ($points{$1}) {next;} }
4507: my $store_key=$dest;
4508: $store_key=~s/^stores/resource/;
4509: $store_key=~s/_/\./g;
4510: $grades{$store_key}=$entries{$fields{$dest}};
4511: }
1.41 ng 4512: }
1.508 www 4513: if (! %grades) {
4514: push(@skipped,&mt("[_1]: no data to save","$username:$domain"));
4515: } else {
4516: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
4517: my $result=&Apache::lonnet::cstore(\%grades,$symb,
1.302 albertel 4518: $env{'request.course.id'},
4519: $domain,$username);
1.508 www 4520: if ($result eq 'ok') {
4521: $request->print('.');
1.596.2.4 raeburn 4522: # Remove from grading queue
4523: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,
4524: $env{'course.'.$env{'request.course.id'}.'.domain'},
4525: $env{'course.'.$env{'request.course.id'}.'.num'},
4526: $domain,$username);
1.508 www 4527: } else {
4528: $request->print("<p><span class=\"LC_error\">".
4529: &mt("Failed to save data for student [_1]. Message when trying to save was: [_2]",
4530: "$username:$domain",$result)."</span></p>");
4531: }
4532: $request->rflush();
4533: $countdone++;
4534: }
1.41 ng 4535: }
1.570 www 4536: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt("Saved scores for [quant,_1,student]",$countdone),$countdone==0));
1.596.2.4 raeburn 4537: if (@warnings) {
4538: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('Warnings generated for the following saved scores:'),1).'<br />');
4539: $request->print(join(', ',@warnings));
4540: }
1.41 ng 4541: if (@skipped) {
1.571 www 4542: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('No scores stored for the following username(s):'),1).'<br />');
4543: $request->print(join(', ',@skipped));
1.106 albertel 4544: }
4545: if (@notallowed) {
1.571 www 4546: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('Modification of scores not allowed for the following username(s):'),1).'<br />');
4547: $request->print(join(', ',@notallowed));
1.41 ng 4548: }
1.106 albertel 4549: $request->print("<br />\n");
1.324 albertel 4550: $request->print(&show_grading_menu_form($symb));
1.345 bowersj2 4551: return $error_msg;
1.26 albertel 4552: }
1.44 ng 4553: #------------- end of section for handling csv file upload ---------
4554: #
4555: #-------------------------------------------------------------------
4556: #
1.122 ng 4557: #-------------- Next few routines handle grading by page/sequence
1.72 ng 4558: #
4559: #--- Select a page/sequence and a student to grade
1.68 ng 4560: sub pickStudentPage {
4561: my ($request) = shift;
4562:
1.539 riegler 4563: my $alertmsg = &mt('Please select the student you wish to grade.');
1.68 ng 4564: $request->print(<<LISTJAVASCRIPT);
4565: <script type="text/javascript" language="javascript">
4566:
4567: function checkPickOne(formname) {
1.76 ng 4568: if (radioSelection(formname.student) == null) {
1.539 riegler 4569: alert("$alertmsg");
1.68 ng 4570: return;
4571: }
1.125 ng 4572: ptr = pullDownSelection(formname.selectpage);
4573: formname.page.value = formname["page"+ptr].value;
4574: formname.title.value = formname["title"+ptr].value;
1.68 ng 4575: formname.submit();
4576: }
4577:
4578: </script>
4579: LISTJAVASCRIPT
1.118 ng 4580: &commonJSfunctions($request);
1.324 albertel 4581: my ($symb) = &get_symb($request);
1.257 albertel 4582: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4583: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4584: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.68 ng 4585:
1.398 albertel 4586: my $result='<h3><span class="LC_info"> '.
1.485 albertel 4587: &mt('Manual Grading by Page or Sequence').'</span></h3>';
1.68 ng 4588:
1.80 ng 4589: $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
1.582 raeburn 4590: my $map_error;
4591: my ($titles,$symbx) = &getSymbMap($map_error);
4592: if ($map_error) {
4593: $request->print(&navmap_errormsg());
4594: return;
4595: }
1.137 albertel 4596: my ($curpage) =&Apache::lonnet::decode_symb($symb);
4597: # my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb);
4598: # my $type=($curpage =~ /\.(page|sequence)/);
1.485 albertel 4599: my $select = '<select name="selectpage">'."\n";
1.70 ng 4600: my $ctr=0;
1.68 ng 4601: foreach (@$titles) {
4602: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.485 albertel 4603: $select.='<option value="'.$ctr.'" '.
1.401 albertel 4604: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.71 ng 4605: '>'.$showtitle.'</option>'."\n";
1.70 ng 4606: $ctr++;
1.68 ng 4607: }
1.485 albertel 4608: $select.= '</select>';
1.539 riegler 4609: $result.=' <b>'.&mt('Problems from').':</b> '.$select."<br />\n";
1.485 albertel 4610:
1.70 ng 4611: $ctr=0;
4612: foreach (@$titles) {
4613: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
4614: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
4615: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
4616: $ctr++;
4617: }
1.72 ng 4618: $result.='<input type="hidden" name="page" />'."\n".
4619: '<input type="hidden" name="title" />'."\n";
1.68 ng 4620:
1.485 albertel 4621: my $options =
4622: '<label><input type="radio" name="vProb" value="no" checked="checked" /> '.&mt('no').' </label>'."\n".
4623: '<label><input type="radio" name="vProb" value="yes" /> '.&mt('yes').' </label>'."<br />\n";
1.539 riegler 4624: $result.=' <b>'.&mt('View Problem Text').': </b>'.$options;
1.485 albertel 4625:
4626: $options =
4627: '<label><input type="radio" name="lastSub" value="none" /> '.&mt('none').' </label>'."\n".
4628: '<label><input type="radio" name="lastSub" value="datesub" checked="checked" /> '.&mt('by dates and submissions').'</label>'."\n".
4629: '<label><input type="radio" name="lastSub" value="all" /> '.&mt('all details').' </label>'."\n";
1.539 riegler 4630: $result.=' <b>'.&mt('Submissions').': </b>'.$options;
1.432 banghart 4631:
4632: $result.=&build_section_inputs();
1.442 banghart 4633: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
4634: $result.='<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.72 ng 4635: '<input type="hidden" name="command" value="displayPage" />'."\n".
1.418 albertel 4636: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 4637: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."<br />\n";
1.72 ng 4638:
1.539 riegler 4639: $result.=' <b>'.&mt('Use CODE').': </b> <input type="text" name="CODE" value="" /> <br />'."\n";
1.382 albertel 4640:
1.80 ng 4641: $result.=' <input type="button" '.
1.589 bisitz 4642: 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /><br />'."\n";
1.72 ng 4643:
1.68 ng 4644: $request->print($result);
4645:
1.485 albertel 4646: my $studentTable.=' <b>'.&mt('Select a student you wish to grade and then click on the Next button.').'</b><br />'.
1.484 albertel 4647: &Apache::loncommon::start_data_table().
4648: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 4649: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 4650: '<th>'.&nameUserString('header').'</th>'.
1.485 albertel 4651: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 4652: '<th>'.&nameUserString('header').'</th>'.
4653: &Apache::loncommon::end_data_table_header_row();
1.68 ng 4654:
1.76 ng 4655: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.68 ng 4656: my $ptr = 1;
1.294 albertel 4657: foreach my $student (sort
4658: {
4659: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
4660: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
4661: }
4662: return $a cmp $b;
4663: } (keys(%$fullname))) {
1.68 ng 4664: my ($uname,$udom) = split(/:/,$student);
1.484 albertel 4665: $studentTable.=($ptr%2==1 ? &Apache::loncommon::start_data_table_row()
4666: : '</td>');
1.126 ng 4667: $studentTable.='<td align="right">'.$ptr.' </td>';
1.288 albertel 4668: $studentTable.='<td> <label><input type="radio" name="student" value="'.$student.'" /> '
4669: .&nameUserString(undef,$$fullname{$student},$uname,$udom)."</label>\n";
1.484 albertel 4670: $studentTable.=
4671: ($ptr%2 == 0 ? '</td>'.&Apache::loncommon::end_data_table_row()
4672: : '');
1.68 ng 4673: $ptr++;
4674: }
1.484 albertel 4675: if ($ptr%2 == 0) {
4676: $studentTable.='</td><td> </td><td> </td>'.
4677: &Apache::loncommon::end_data_table_row();
4678: }
4679: $studentTable.=&Apache::loncommon::end_data_table()."\n";
1.126 ng 4680: $studentTable.='<input type="button" '.
1.589 bisitz 4681: 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /></form>'."\n";
1.68 ng 4682:
1.324 albertel 4683: $studentTable.=&show_grading_menu_form($symb);
1.68 ng 4684: $request->print($studentTable);
4685:
4686: return '';
4687: }
4688:
4689: sub getSymbMap {
1.582 raeburn 4690: my ($map_error) = @_;
1.132 bowersj2 4691: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 4692: unless (ref($navmap)) {
4693: if (ref($map_error)) {
4694: $$map_error = 'navmap';
4695: }
4696: return;
4697: }
1.68 ng 4698: my %symbx = ();
4699: my @titles = ();
1.117 bowersj2 4700: my $minder = 0;
4701:
4702: # Gather every sequence that has problems.
1.240 albertel 4703: my @sequences = $navmap->retrieveResources(undef, sub { shift->is_map(); },
4704: 1,0,1);
1.117 bowersj2 4705: for my $sequence ($navmap->getById('0.0'), @sequences) {
1.241 albertel 4706: if ($navmap->hasResource($sequence, sub { shift->is_problem(); }, 0) ) {
1.381 albertel 4707: my $title = $minder.'.'.
4708: &HTML::Entities::encode($sequence->compTitle(),'"\'&');
4709: push(@titles, $title); # minder in case two titles are identical
4710: $symbx{$title} = &HTML::Entities::encode($sequence->symb(),'"\'&');
1.117 bowersj2 4711: $minder++;
1.241 albertel 4712: }
1.68 ng 4713: }
4714: return \@titles,\%symbx;
4715: }
4716:
1.72 ng 4717: #
4718: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68 ng 4719: sub displayPage {
4720: my ($request) = shift;
4721:
1.324 albertel 4722: my ($symb) = &get_symb($request);
1.257 albertel 4723: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4724: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4725: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
4726: my $pageTitle = $env{'form.page'};
1.103 albertel 4727: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 4728: my ($uname,$udom) = split(/:/,$env{'form.student'});
4729: my $usec=$classlist->{$env{'form.student'}}[5];
1.168 albertel 4730:
4731: #need to make sure we have the correct data for later EXT calls,
4732: #thus invalidate the cache
4733: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 4734: $env{'course.'.$env{'request.course.id'}.'.num'},
4735: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 4736: &Apache::lonnet::clear_EXT_cache_status();
4737:
1.103 albertel 4738: if (!&canview($usec)) {
1.485 albertel 4739: $request->print('<span class="LC_warning">'.&mt('Unable to view requested student. ([_1])',$env{'form.student'}).'</span>');
1.324 albertel 4740: $request->print(&show_grading_menu_form($symb));
1.103 albertel 4741: return;
4742: }
1.398 albertel 4743: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.485 albertel 4744: $result.='<h3> '.&mt('Student: [_1]',&nameUserString(undef,$$fullname{$env{'form.student'}},$uname,$udom)).
1.129 ng 4745: '</h3>'."\n";
1.500 albertel 4746: $env{'form.CODE'} = uc($env{'form.CODE'});
1.501 foxr 4747: if (&Apache::lonnet::validCODE(uc($env{'form.CODE'}))) {
1.485 albertel 4748: $result.='<h3> '.&mt('CODE: [_1]',$env{'form.CODE'}).'</h3>'."\n";
1.382 albertel 4749: } else {
4750: delete($env{'form.CODE'});
4751: }
1.71 ng 4752: &sub_page_js($request);
4753: $request->print($result);
4754:
1.132 bowersj2 4755: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 4756: unless (ref($navmap)) {
4757: $request->print(&navmap_errormsg());
4758: $request->print(&show_grading_menu_form($symb));
4759: return;
4760: }
1.257 albertel 4761: my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($env{'form.page'});
1.68 ng 4762: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 4763: if (!$map) {
1.485 albertel 4764: $request->print('<span class="LC_warning">'.&mt('Unable to view requested sequence. ([_1])',$resUrl).'</span>');
1.324 albertel 4765: $request->print(&show_grading_menu_form($symb));
1.288 albertel 4766: return;
4767: }
1.68 ng 4768: my $iterator = $navmap->getIterator($map->map_start(),
4769: $map->map_finish());
4770:
1.71 ng 4771: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72 ng 4772: '<input type="hidden" name="command" value="gradeByPage" />'."\n".
1.257 albertel 4773: '<input type="hidden" name="fullname" value="'.$$fullname{$env{'form.student'}}.'" />'."\n".
4774: '<input type="hidden" name="student" value="'.$env{'form.student'}.'" />'."\n".
1.72 ng 4775: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
1.257 albertel 4776: '<input type="hidden" name="title" value="'.$env{'form.title'}.'" />'."\n".
1.418 albertel 4777: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.125 ng 4778: '<input type="hidden" name="overRideScore" value="no" />'."\n".
1.257 albertel 4779: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n";
1.71 ng 4780:
1.382 albertel 4781: if (defined($env{'form.CODE'})) {
4782: $studentTable.=
4783: '<input type="hidden" name="CODE" value="'.$env{'form.CODE'}.'" />'."\n";
4784: }
1.381 albertel 4785: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 4786: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 4787:
1.594 bisitz 4788: $studentTable.=' <span class="LC_info">'.
4789: &mt('Problems graded correct by the computer are marked with a [_1] symbol.',$checkIcon).
4790: '</span>'."\n".
1.484 albertel 4791: &Apache::loncommon::start_data_table().
4792: &Apache::loncommon::start_data_table_header_row().
4793: '<th align="center"> Prob. </th>'.
1.485 albertel 4794: '<th> '.($env{'form.vProb'} eq 'no' ? &mt('Title') : &mt('Problem Text')).'/'.&mt('Grade').'</th>'.
1.484 albertel 4795: &Apache::loncommon::end_data_table_header_row();
1.71 ng 4796:
1.329 albertel 4797: &Apache::lonxml::clear_problem_counter();
1.196 albertel 4798: my ($depth,$question,$prob) = (1,1,1);
1.68 ng 4799: $iterator->next(); # skip the first BEGIN_MAP
4800: my $curRes = $iterator->next(); # for "current resource"
1.101 albertel 4801: while ($depth > 0) {
1.68 ng 4802: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4803: if($curRes == $iterator->END_MAP) { $depth--; }
1.68 ng 4804:
1.385 albertel 4805: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4806: my $parts = $curRes->parts();
1.68 ng 4807: my $title = $curRes->compTitle();
1.71 ng 4808: my $symbx = $curRes->symb();
1.484 albertel 4809: $studentTable.=
4810: &Apache::loncommon::start_data_table_row().
4811: '<td align="center" valign="top" >'.$prob.
1.485 albertel 4812: (scalar(@{$parts}) == 1 ? ''
1.596.2.12.2. 2(raebur 4813:2): : '<br />('.&mt('[_1]parts',
4814:2): scalar(@{$parts}).' ').')'
1.485 albertel 4815: ).
4816: '</td>';
1.71 ng 4817: $studentTable.='<td valign="top">';
1.382 albertel 4818: my %form = ('CODE' => $env{'form.CODE'},);
1.257 albertel 4819: if ($env{'form.vProb'} eq 'yes' ) {
1.144 albertel 4820: $studentTable.=&show_problem($request,$symbx,$uname,$udom,1,
1.383 albertel 4821: undef,'both',\%form);
1.71 ng 4822: } else {
1.382 albertel 4823: my $companswer = &Apache::loncommon::get_student_answers($symbx,$uname,$udom,$env{'request.course.id'},%form);
1.80 ng 4824: $companswer =~ s|<form(.*?)>||g;
4825: $companswer =~ s|</form>||g;
1.71 ng 4826: # while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
1.116 ng 4827: # $companswer =~ s/$1/ /ms;
1.326 albertel 4828: # $request->print('match='.$1."<br />\n");
1.71 ng 4829: # }
1.116 ng 4830: # $companswer =~ s|<table border=\"1\">|<table border=\"0\">|g;
1.539 riegler 4831: $studentTable.=' <b>'.$title.'</b> <br /> <b>'.&mt('Correct answer').':</b><br />'.$companswer;
1.71 ng 4832: }
4833:
1.257 albertel 4834: my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
1.125 ng 4835:
1.257 albertel 4836: if ($env{'form.lastSub'} eq 'datesub') {
1.71 ng 4837: if ($record{'version'} eq '') {
1.485 albertel 4838: $studentTable.='<br /> <span class="LC_warning">'.&mt('No recorded submission for this problem.').'</span><br />';
1.71 ng 4839: } else {
1.116 ng 4840: my %responseType = ();
4841: foreach my $partid (@{$parts}) {
1.147 albertel 4842: my @responseIds =$curRes->responseIds($partid);
4843: my @responseType =$curRes->responseType($partid);
4844: my %responseIds;
4845: for (my $i=0;$i<=$#responseIds;$i++) {
4846: $responseIds{$responseIds[$i]}=$responseType[$i];
4847: }
4848: $responseType{$partid} = \%responseIds;
1.116 ng 4849: }
1.148 albertel 4850: $studentTable.= &displaySubByDates($symbx,\%record,$parts,\%responseType,$checkIcon,$uname,$udom);
1.147 albertel 4851:
1.71 ng 4852: }
1.257 albertel 4853: } elsif ($env{'form.lastSub'} eq 'all') {
4854: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.71 ng 4855: $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
1.257 albertel 4856: $env{'request.course.id'},
1.71 ng 4857: '','.submission');
4858:
4859: }
1.103 albertel 4860: if (&canmodify($usec)) {
1.585 bisitz 4861: $studentTable.=&gradeBox_start();
1.103 albertel 4862: foreach my $partid (@{$parts}) {
4863: $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
4864: $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
4865: $question++;
4866: }
1.585 bisitz 4867: $studentTable.=&gradeBox_end();
1.196 albertel 4868: $prob++;
1.71 ng 4869: }
4870: $studentTable.='</td></tr>';
1.68 ng 4871:
1.103 albertel 4872: }
1.68 ng 4873: $curRes = $iterator->next();
4874: }
4875:
1.589 bisitz 4876: $studentTable.=
4877: '</table>'."\n".
4878: '<input type="button" value="'.&mt('Save').'" '.
4879: 'onclick="javascript:checkSubmitPage(this.form,'.$question.');" />'.
4880: '</form>'."\n";
1.324 albertel 4881: $studentTable.=&show_grading_menu_form($symb);
1.71 ng 4882: $request->print($studentTable);
4883:
4884: return '';
1.119 ng 4885: }
4886:
4887: sub displaySubByDates {
1.148 albertel 4888: my ($symb,$record,$parts,$responseType,$checkIcon,$uname,$udom) = @_;
1.224 albertel 4889: my $isCODE=0;
1.335 albertel 4890: my $isTask = ($symb =~/\.task$/);
1.224 albertel 4891: if (exists($record->{'resource.CODE'})) { $isCODE=1; }
1.467 albertel 4892: my $studentTable=&Apache::loncommon::start_data_table().
4893: &Apache::loncommon::start_data_table_header_row().
4894: '<th>'.&mt('Date/Time').'</th>'.
4895: ($isCODE?'<th>'.&mt('CODE').'</th>':'').
1.596.2.12.2. (raeburn 4896:): ($isTask?'<th>'.&mt('Version').'</th>':'').
1.467 albertel 4897: '<th>'.&mt('Submission').'</th>'.
4898: '<th>'.&mt('Status').'</th>'.
4899: &Apache::loncommon::end_data_table_header_row();
1.119 ng 4900: my ($version);
4901: my %mark;
1.148 albertel 4902: my %orders;
1.119 ng 4903: $mark{'correct_by_student'} = $checkIcon;
1.147 albertel 4904: if (!exists($$record{'1:timestamp'})) {
1.539 riegler 4905: return '<br /> <span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br />';
1.147 albertel 4906: }
1.335 albertel 4907:
4908: my $interaction;
1.525 raeburn 4909: my $no_increment = 1;
1.596.2.2 raeburn 4910: my %lastrndseed;
1.119 ng 4911: for ($version=1;$version<=$$record{'version'};$version++) {
1.467 albertel 4912: my $timestamp =
4913: &Apache::lonlocal::locallocaltime($$record{$version.':timestamp'});
1.335 albertel 4914: if (exists($$record{$version.':resource.0.version'})) {
4915: $interaction = $$record{$version.':resource.0.version'};
4916: }
1.596.2.12.2. (raeburn 4917:): if ($isTask && $env{'form.previousversion'}) {
4918:): next unless ($interaction == $env{'form.previousversion'});
4919:): }
1.335 albertel 4920: my $where = ($isTask ? "$version:resource.$interaction"
4921: : "$version:resource");
1.467 albertel 4922: $studentTable.=&Apache::loncommon::start_data_table_row().
4923: '<td>'.$timestamp.'</td>';
1.224 albertel 4924: if ($isCODE) {
4925: $studentTable.='<td>'.$record->{$version.':resource.CODE'}.'</td>';
4926: }
1.596.2.12.2. (raeburn 4927:): if ($isTask) {
4928:): $studentTable.='<td>'.$interaction.'</td>';
4929:): }
1.119 ng 4930: my @versionKeys = split(/\:/,$$record{$version.':keys'});
4931: my @displaySub = ();
4932: foreach my $partid (@{$parts}) {
1.596.2.2 raeburn 4933: my ($hidden,$type);
4934: $type = $$record{$version.':resource.'.$partid.'.type'};
4935: if (($type eq 'anonsurvey') || ($type eq 'anonsurveycred')) {
1.596 raeburn 4936: $hidden = 1;
4937: }
1.335 albertel 4938: my @matchKey = ($isTask ? sort(grep /^resource\.\d+\.\Q$partid\E\.award$/,@versionKeys)
4939: : sort(grep /^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys));
4940:
1.122 ng 4941: # next if ($$record{"$version:resource.$partid.solved"} eq '');
1.324 albertel 4942: my $display_part=&get_display_part($partid,$symb);
1.147 albertel 4943: foreach my $matchKey (@matchKey) {
1.198 albertel 4944: if (exists($$record{$version.':'.$matchKey}) &&
4945: $$record{$version.':'.$matchKey} ne '') {
1.596 raeburn 4946:
1.335 albertel 4947: my ($responseId)= ($isTask ? ($matchKey=~ /^resource\.(.*?)\.\Q$partid\E\.award$/)
4948: : ($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/));
1.596.2.12.2. (raeburn 4949:): $displaySub[0].='<span class="LC_nobreak">';
1.577 bisitz 4950: $displaySub[0].='<b>'.&mt('Part: [_1]',$display_part).'</b>'
4951: .' <span class="LC_internal_info">'
1.596.2.4 raeburn 4952: .'('.&mt('Response ID: [_1]',$responseId).')'
1.577 bisitz 4953: .'</span>'
4954: .' <b>';
1.596 raeburn 4955: if ($hidden) {
4956: $displaySub[0].= &mt('Anonymous Survey').'</b>';
4957: } else {
1.596.2.2 raeburn 4958: my ($trial,$rndseed,$newvariation);
4959: if ($type eq 'randomizetry') {
4960: $trial = $$record{"$where.$partid.tries"};
4961: $rndseed = $$record{"$where.$partid.rndseed"};
4962: }
1.596 raeburn 4963: if ($$record{"$where.$partid.tries"} eq '') {
4964: $displaySub[0].=&mt('Trial not counted');
4965: } else {
4966: $displaySub[0].=&mt('Trial: [_1]',
1.467 albertel 4967: $$record{"$where.$partid.tries"});
1.596.2.2 raeburn 4968: if ($rndseed || $lastrndseed{$partid}) {
4969: if ($rndseed ne $lastrndseed{$partid}) {
4970: $newvariation = ' ('.&mt('New variation this try').')';
4971: }
4972: }
1.596 raeburn 4973: }
4974: my $responseType=($isTask ? 'Task'
1.335 albertel 4975: : $responseType->{$partid}->{$responseId});
1.596 raeburn 4976: if (!exists($orders{$partid})) { $orders{$partid}={}; }
1.596.2.2 raeburn 4977: if ((!exists($orders{$partid}->{$responseId})) || ($trial)) {
1.596 raeburn 4978: $orders{$partid}->{$responseId}=
4979: &get_order($partid,$responseId,$symb,$uname,$udom,
1.596.2.2 raeburn 4980: $no_increment,$type,$trial,$rndseed);
1.596 raeburn 4981: }
1.596.2.2 raeburn 4982: $displaySub[0].='</b>'.$newvariation.'</span>'; # /nobreak
1.596 raeburn 4983: $displaySub[0].=' '.
1.596.2.2 raeburn 4984: &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:",$uname,$udom,$type,$trial,$rndseed).'<br />';
1.596 raeburn 4985: }
1.147 albertel 4986: }
4987: }
1.335 albertel 4988: if (exists($$record{"$where.$partid.checkedin"})) {
1.485 albertel 4989: $displaySub[1].=&mt('Checked in by [_1] into slot [_2]',
4990: $$record{"$where.$partid.checkedin"},
4991: $$record{"$where.$partid.checkedin.slot"}).
4992: '<br />';
1.335 albertel 4993: }
4994: if (exists $$record{"$where.$partid.award"}) {
1.485 albertel 4995: $displaySub[1].='<b>'.&mt('Part:').'</b> '.$display_part.' '.
1.335 albertel 4996: lc($$record{"$where.$partid.award"}).' '.
4997: $mark{$$record{"$where.$partid.solved"}}.
1.147 albertel 4998: '<br />';
4999: }
1.335 albertel 5000: if (exists $$record{"$where.$partid.regrader"}) {
5001: $displaySub[2].=$$record{"$where.$partid.regrader"}.
5002: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
5003: } elsif ($$record{"$version:resource.$partid.regrader"} =~ /\S/) {
5004: $displaySub[2].=
5005: $$record{"$version:resource.$partid.regrader"}.
1.207 albertel 5006: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
1.147 albertel 5007: }
5008: }
5009: # needed because old essay regrader has not parts info
5010: if (exists $$record{"$version:resource.regrader"}) {
5011: $displaySub[2].=$$record{"$version:resource.regrader"};
5012: }
5013: $studentTable.='<td>'.$displaySub[0].' </td><td>'.$displaySub[1];
5014: if ($displaySub[2]) {
1.467 albertel 5015: $studentTable.=&mt('Manually graded by [_1]',$displaySub[2]);
1.147 albertel 5016: }
1.467 albertel 5017: $studentTable.=' </td>'.
5018: &Apache::loncommon::end_data_table_row();
1.119 ng 5019: }
1.467 albertel 5020: $studentTable.=&Apache::loncommon::end_data_table();
1.119 ng 5021: return $studentTable;
1.71 ng 5022: }
5023:
5024: sub updateGradeByPage {
5025: my ($request) = shift;
5026:
1.257 albertel 5027: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
5028: my $cnum = $env{"course.$env{'request.course.id'}.num"};
5029: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
5030: my $pageTitle = $env{'form.page'};
1.103 albertel 5031: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 5032: my ($uname,$udom) = split(/:/,$env{'form.student'});
5033: my $usec=$classlist->{$env{'form.student'}}[5];
1.103 albertel 5034: if (!&canmodify($usec)) {
1.526 raeburn 5035: $request->print('<span class="LC_warning">'.&mt('Unable to modify requested student ([_1])',$env{'form.student'}).'</span>');
1.324 albertel 5036: $request->print(&show_grading_menu_form($env{'form.symb'}));
1.103 albertel 5037: return;
5038: }
1.398 albertel 5039: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.526 raeburn 5040: $result.='<h3> '.&mt('Student: ').&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
1.129 ng 5041: '</h3>'."\n";
1.70 ng 5042:
1.68 ng 5043: $request->print($result);
5044:
1.582 raeburn 5045:
1.132 bowersj2 5046: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 5047: unless (ref($navmap)) {
5048: $request->print(&navmap_errormsg());
5049: return;
5050: }
1.257 albertel 5051: my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $env{'form.page'});
1.71 ng 5052: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 5053: if (!$map) {
1.527 raeburn 5054: $request->print('<span class="LC_warning">'.&mt('Unable to grade requested sequence ([_1]).',$resUrl).'</span>');
1.324 albertel 5055: my ($symb)=&get_symb($request);
5056: $request->print(&show_grading_menu_form($symb));
1.288 albertel 5057: return;
5058: }
1.71 ng 5059: my $iterator = $navmap->getIterator($map->map_start(),
5060: $map->map_finish());
1.70 ng 5061:
1.484 albertel 5062: my $studentTable=
5063: &Apache::loncommon::start_data_table().
5064: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 5065: '<th align="center"> '.&mt('Prob.').' </th>'.
5066: '<th> '.&mt('Title').' </th>'.
5067: '<th> '.&mt('Previous Score').' </th>'.
5068: '<th> '.&mt('New Score').' </th>'.
1.484 albertel 5069: &Apache::loncommon::end_data_table_header_row();
1.71 ng 5070:
5071: $iterator->next(); # skip the first BEGIN_MAP
5072: my $curRes = $iterator->next(); # for "current resource"
1.196 albertel 5073: my ($depth,$question,$prob,$changeflag)= (1,1,1,0);
1.101 albertel 5074: while ($depth > 0) {
1.71 ng 5075: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 5076: if($curRes == $iterator->END_MAP) { $depth--; }
1.71 ng 5077:
1.385 albertel 5078: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 5079: my $parts = $curRes->parts();
1.71 ng 5080: my $title = $curRes->compTitle();
5081: my $symbx = $curRes->symb();
1.484 albertel 5082: $studentTable.=
5083: &Apache::loncommon::start_data_table_row().
5084: '<td align="center" valign="top" >'.$prob.
1.485 albertel 5085: (scalar(@{$parts}) == 1 ? ''
1.596.2.2 raeburn 5086: : '<br />('.&mt('[quant,_1,part]',scalar(@{$parts}))
1.526 raeburn 5087: .')').'</td>';
1.71 ng 5088: $studentTable.='<td valign="top"> <b>'.$title.'</b> </td>';
5089:
5090: my %newrecord=();
5091: my @displayPts=();
1.269 raeburn 5092: my %aggregate = ();
5093: my $aggregateflag = 0;
1.71 ng 5094: foreach my $partid (@{$parts}) {
1.257 albertel 5095: my $newpts = $env{'form.GD_BOX'.$question.'_'.$partid};
5096: my $oldpts = $env{'form.oldpts'.$question.'_'.$partid};
1.71 ng 5097:
1.257 albertel 5098: my $wgt = $env{'form.WGT'.$question.'_'.$partid} != 0 ?
5099: $env{'form.WGT'.$question.'_'.$partid} : 1;
1.71 ng 5100: my $partial = $newpts/$wgt;
5101: my $score;
5102: if ($partial > 0) {
5103: $score = 'correct_by_override';
1.125 ng 5104: } elsif ($newpts ne '') { #empty is taken as 0
1.71 ng 5105: $score = 'incorrect_by_override';
5106: }
1.257 albertel 5107: my $dropMenu = $env{'form.GD_SEL'.$question.'_'.$partid};
1.125 ng 5108: if ($dropMenu eq 'excused') {
1.71 ng 5109: $partial = '';
5110: $score = 'excused';
1.125 ng 5111: } elsif ($dropMenu eq 'reset status'
1.257 albertel 5112: && $env{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
1.125 ng 5113: $newrecord{'resource.'.$partid.'.tries'} = 0;
5114: $newrecord{'resource.'.$partid.'.solved'} = '';
5115: $newrecord{'resource.'.$partid.'.award'} = '';
5116: $newrecord{'resource.'.$partid.'.awarded'} = 0;
1.257 albertel 5117: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 5118: $changeflag++;
5119: $newpts = '';
1.269 raeburn 5120:
5121: my $aggtries = $env{'form.aggtries'.$question.'_'.$partid};
5122: my $totaltries = $env{'form.totaltries'.$question.'_'.$partid};
5123: my $solvedstatus = $env{'form.solved'.$question.'_'.$partid};
5124: if ($aggtries > 0) {
5125: &decrement_aggs($symbx,$partid,\%aggregate,$aggtries,$totaltries,$solvedstatus);
5126: $aggregateflag = 1;
5127: }
1.71 ng 5128: }
1.324 albertel 5129: my $display_part=&get_display_part($partid,$curRes->symb());
1.257 albertel 5130: my $oldstatus = $env{'form.solved'.$question.'_'.$partid};
1.526 raeburn 5131: $displayPts[0].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.71 ng 5132: (($oldstatus eq 'excused') ? 'excused' : $oldpts).
1.326 albertel 5133: ' <br />';
1.526 raeburn 5134: $displayPts[1].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.125 ng 5135: (($score eq 'excused') ? 'excused' : $newpts).
1.326 albertel 5136: ' <br />';
1.71 ng 5137: $question++;
1.380 albertel 5138: next if ($dropMenu eq 'reset status' || ($newpts eq $oldpts && $score ne 'excused'));
1.125 ng 5139:
1.71 ng 5140: $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
1.125 ng 5141: $newrecord{'resource.'.$partid.'.solved'} = $score if $score ne '';
1.257 albertel 5142: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}"
1.125 ng 5143: if (scalar(keys(%newrecord)) > 0);
1.71 ng 5144:
5145: $changeflag++;
5146: }
5147: if (scalar(keys(%newrecord)) > 0) {
1.382 albertel 5148: my %record =
5149: &Apache::lonnet::restore($symbx,$env{'request.course.id'},
5150: $udom,$uname);
5151:
5152: if (&Apache::lonnet::validCODE($env{'form.CODE'})) {
5153: $newrecord{'resource.CODE'} = $env{'form.CODE'};
5154: } elsif (&Apache::lonnet::validCODE($record{'resource.CODE'})) {
5155: $newrecord{'resource.CODE'} = '';
5156: }
1.257 albertel 5157: &Apache::lonnet::cstore(\%newrecord,$symbx,$env{'request.course.id'},
1.71 ng 5158: $udom,$uname);
1.382 albertel 5159: %record = &Apache::lonnet::restore($symbx,
5160: $env{'request.course.id'},
5161: $udom,$uname);
1.380 albertel 5162: &check_and_remove_from_queue($parts,\%record,undef,$symbx,
5163: $cdom,$cnum,$udom,$uname);
1.71 ng 5164: }
1.380 albertel 5165:
1.269 raeburn 5166: if ($aggregateflag) {
5167: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
5168: $env{'course.'.$env{'request.course.id'}.'.domain'},
5169: $env{'course.'.$env{'request.course.id'}.'.num'});
5170: }
1.125 ng 5171:
1.71 ng 5172: $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
5173: '<td valign="top">'.$displayPts[1].'</td>'.
1.484 albertel 5174: &Apache::loncommon::end_data_table_row();
1.68 ng 5175:
1.196 albertel 5176: $prob++;
1.68 ng 5177: }
1.71 ng 5178: $curRes = $iterator->next();
1.68 ng 5179: }
1.98 albertel 5180:
1.484 albertel 5181: $studentTable.=&Apache::loncommon::end_data_table();
1.324 albertel 5182: $studentTable.=&show_grading_menu_form($env{'form.symb'});
1.526 raeburn 5183: my $grademsg=($changeflag == 0 ? &mt('No score was changed or updated.') :
5184: &mt('The scores were changed for [quant,_1,problem].',
5185: $changeflag));
1.76 ng 5186: $request->print($grademsg.$studentTable);
1.68 ng 5187:
1.70 ng 5188: return '';
5189: }
5190:
1.72 ng 5191: #-------- end of section for handling grading by page/sequence ---------
5192: #
5193: #-------------------------------------------------------------------
5194:
1.581 www 5195: #-------------------- Bubblesheet (Scantron) Grading -------------------
1.75 albertel 5196: #
5197: #------ start of section for handling grading by page/sequence ---------
5198:
1.423 albertel 5199: =pod
5200:
5201: =head1 Bubble sheet grading routines
5202:
1.424 albertel 5203: For this documentation:
5204:
5205: 'scanline' refers to the full line of characters
5206: from the file that we are parsing that represents one entire sheet
5207:
5208: 'bubble line' refers to the data
1.596.2.6 raeburn 5209: representing the line of bubbles that are on the physical bubblesheet
1.424 albertel 5210:
5211:
1.596.2.6 raeburn 5212: The overall process is that a scanned in bubblesheet data is uploaded
1.424 albertel 5213: into a course. When a user wants to grade, they select a
1.596.2.6 raeburn 5214: sequence/folder of resources, a file of bubblesheet info, and pick
1.424 albertel 5215: one of the predefined configurations for what each scanline looks
5216: like.
5217:
5218: Next each scanline is checked for any errors of either 'missing
1.435 foxr 5219: bubbles' (it's an error because it may have been mis-scanned
1.424 albertel 5220: because too light bubbling), 'double bubble' (each bubble line should
5221: have no more that one letter picked), invalid or duplicated CODE,
1.556 weissno 5222: invalid student/employee ID
1.424 albertel 5223:
5224: If the CODE option is used that determines the randomization of the
1.556 weissno 5225: homework problems, either way the student/employee ID is looked up into a
1.424 albertel 5226: username:domain.
5227:
5228: During the validation phase the instructor can choose to skip scanlines.
5229:
1.596.2.6 raeburn 5230: After the validation phase, there are now 3 bubblesheet files
1.424 albertel 5231:
5232: scantron_original_filename (unmodified original file)
5233: scantron_corrected_filename (file where the corrected information has replaced the original information)
5234: scantron_skipped_filename (contains the exact text of scanlines that where skipped)
5235:
5236: Also there is a separate hash nohist_scantrondata that contains extra
1.596.2.6 raeburn 5237: correction information that isn't representable in the bubblesheet
1.424 albertel 5238: file (see &scantron_getfile() for more information)
5239:
5240: After all scanlines are either valid, marked as valid or skipped, then
5241: foreach line foreach problem in the picked sequence, an ssi request is
5242: made that simulates a user submitting their selected letter(s) against
5243: the homework problem.
1.423 albertel 5244:
5245: =over 4
5246:
5247:
5248:
5249: =item defaultFormData
5250:
5251: Returns html hidden inputs used to hold context/default values.
5252:
5253: Arguments:
5254: $symb - $symb of the current resource
5255:
5256: =cut
1.422 foxr 5257:
1.81 albertel 5258: sub defaultFormData {
1.324 albertel 5259: my ($symb)=@_;
1.447 foxr 5260: return '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 5261: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
5262: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.81 albertel 5263: }
5264:
1.447 foxr 5265:
1.423 albertel 5266: =pod
5267:
5268: =item getSequenceDropDown
5269:
5270: Return html dropdown of possible sequences to grade
5271:
5272: Arguments:
1.582 raeburn 5273: $symb - $symb of the current resource
5274: $map_error - ref to scalar which will container error if
5275: $navmap object is unavailable in &getSymbMap().
1.423 albertel 5276:
5277: =cut
1.422 foxr 5278:
1.75 albertel 5279: sub getSequenceDropDown {
1.582 raeburn 5280: my ($symb,$map_error)=@_;
1.75 albertel 5281: my $result='<select name="selectpage">'."\n";
1.582 raeburn 5282: my ($titles,$symbx) = &getSymbMap($map_error);
5283: if (ref($map_error)) {
5284: return if ($$map_error);
5285: }
1.137 albertel 5286: my ($curpage)=&Apache::lonnet::decode_symb($symb);
1.75 albertel 5287: my $ctr=0;
5288: foreach (@$titles) {
5289: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
5290: $result.='<option value="'.$$symbx{$_}.'" '.
1.401 albertel 5291: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.75 albertel 5292: '>'.$showtitle.'</option>'."\n";
5293: $ctr++;
5294: }
5295: $result.= '</select>';
5296: return $result;
5297: }
5298:
1.495 albertel 5299: my %bubble_lines_per_response; # no. bubble lines for each response.
1.554 raeburn 5300: # key is zero-based index - 0, 1, 2 ...
1.495 albertel 5301:
5302: my %first_bubble_line; # First bubble line no. for each bubble.
5303:
1.509 raeburn 5304: my %subdivided_bubble_lines; # no. bubble lines for optionresponse,
5305: # matchresponse or rankresponse, where
5306: # an individual response can have multiple
5307: # lines
1.503 raeburn 5308:
5309: my %responsetype_per_response; # responsetype for each response
5310:
1.596.2.12.2. 6(raebur 5311:3): my %masterseq_id_responsenum; # src_id (e.g., 12.3_0.11 etc.) for each
5312:3): # numbered response. Needed when randomorder
5313:3): # or randompick are in use. Key is ID, value
5314:3): # is response number.
5315:3):
1.495 albertel 5316: # Save and restore the bubble lines array to the form env.
5317:
5318:
5319: sub save_bubble_lines {
5320: foreach my $line (keys(%bubble_lines_per_response)) {
5321: $env{"form.scantron.bubblelines.$line"} = $bubble_lines_per_response{$line};
5322: $env{"form.scantron.first_bubble_line.$line"} =
5323: $first_bubble_line{$line};
1.503 raeburn 5324: $env{"form.scantron.sub_bubblelines.$line"} =
5325: $subdivided_bubble_lines{$line};
5326: $env{"form.scantron.responsetype.$line"} =
5327: $responsetype_per_response{$line};
1.495 albertel 5328: }
1.596.2.12.2. 6(raebur 5329:3): foreach my $resid (keys(%masterseq_id_responsenum)) {
5330:3): my $line = $masterseq_id_responsenum{$resid};
5331:3): $env{"form.scantron.residpart.$line"} = $resid;
5332:3): }
1.495 albertel 5333: }
5334:
5335:
5336: sub restore_bubble_lines {
5337: my $line = 0;
5338: %bubble_lines_per_response = ();
1.596.2.12.2. 6(raebur 5339:3): %masterseq_id_responsenum = ();
1.495 albertel 5340: while ($env{"form.scantron.bubblelines.$line"}) {
5341: my $value = $env{"form.scantron.bubblelines.$line"};
5342: $bubble_lines_per_response{$line} = $value;
5343: $first_bubble_line{$line} =
5344: $env{"form.scantron.first_bubble_line.$line"};
1.503 raeburn 5345: $subdivided_bubble_lines{$line} =
5346: $env{"form.scantron.sub_bubblelines.$line"};
5347: $responsetype_per_response{$line} =
5348: $env{"form.scantron.responsetype.$line"};
1.596.2.12.2. 6(raebur 5349:3): my $id = $env{"form.scantron.residpart.$line"};
5350:3): $masterseq_id_responsenum{$id} = $line;
1.495 albertel 5351: $line++;
5352: }
5353: }
5354:
1.423 albertel 5355: =pod
5356:
5357: =item scantron_filenames
5358:
5359: Returns a list of the scantron files in the current course
5360:
5361: =cut
1.422 foxr 5362:
1.202 albertel 5363: sub scantron_filenames {
1.257 albertel 5364: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5365: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
1.517 raeburn 5366: my $getpropath = 1;
1.596.2.12.2. (raeburn 5367:): my ($dirlist,$listerror) = &Apache::lonnet::dirlist('userfiles',$cdom,
5368:): $cname,$getpropath);
1.202 albertel 5369: my @possiblenames;
1.596.2.12.2. (raeburn 5370:): if (ref($dirlist) eq 'ARRAY') {
5371:): foreach my $filename (sort(@{$dirlist})) {
5372:): ($filename)=split(/&/,$filename);
5373:): if ($filename!~/^scantron_orig_/) { next ; }
5374:): $filename=~s/^scantron_orig_//;
5375:): push(@possiblenames,$filename);
5376:): }
1.202 albertel 5377: }
5378: return @possiblenames;
5379: }
5380:
1.423 albertel 5381: =pod
5382:
5383: =item scantron_uploads
5384:
5385: Returns html drop-down list of scantron files in current course.
5386:
5387: Arguments:
5388: $file2grade - filename to set as selected in the dropdown
5389:
5390: =cut
1.422 foxr 5391:
1.202 albertel 5392: sub scantron_uploads {
1.209 ng 5393: my ($file2grade) = @_;
1.202 albertel 5394: my $result= '<select name="scantron_selectfile">';
5395: $result.="<option></option>";
5396: foreach my $filename (sort(&scantron_filenames())) {
1.401 albertel 5397: $result.="<option".($filename eq $file2grade ? ' selected="selected"':'').">$filename</option>\n";
1.81 albertel 5398: }
5399: $result.="</select>";
5400: return $result;
5401: }
5402:
1.423 albertel 5403: =pod
5404:
5405: =item scantron_scantab
5406:
5407: Returns html drop down of the scantron formats in the scantronformat.tab
5408: file.
5409:
5410: =cut
1.422 foxr 5411:
1.82 albertel 5412: sub scantron_scantab {
5413: my $result='<select name="scantron_format">'."\n";
1.191 albertel 5414: $result.='<option></option>'."\n";
1.518 raeburn 5415: my @lines = &get_scantronformat_file();
5416: if (@lines > 0) {
5417: foreach my $line (@lines) {
5418: next if (($line =~ /^\#/) || ($line eq ''));
5419: my ($name,$descrip)=split(/:/,$line);
5420: $result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
5421: }
1.82 albertel 5422: }
5423: $result.='</select>'."\n";
1.518 raeburn 5424: return $result;
5425: }
5426:
5427: =pod
5428:
5429: =item get_scantronformat_file
5430:
5431: Returns an array containing lines from the scantron format file for
5432: the domain of the course.
5433:
5434: If a url for a custom.tab file is listed in domain's configuration.db,
5435: lines are from this file.
5436:
5437: Otherwise, if a default.tab has been published in RES space by the
5438: domainconfig user, lines are from this file.
5439:
5440: Otherwise, fall back to getting lines from the legacy file on the
1.519 raeburn 5441: local server: /home/httpd/lonTabs/default_scantronformat.tab
1.82 albertel 5442:
1.518 raeburn 5443: =cut
5444:
5445: sub get_scantronformat_file {
5446: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
5447: my %domconfig = &Apache::lonnet::get_dom('configuration',['scantron'],$cdom);
5448: my $gottab = 0;
5449: my @lines;
5450: if (ref($domconfig{'scantron'}) eq 'HASH') {
5451: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
5452: my $formatfile = &Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.$domconfig{'scantron'}{'scantronformat'});
5453: if ($formatfile ne '-1') {
5454: @lines = split("\n",$formatfile,-1);
5455: $gottab = 1;
5456: }
5457: }
5458: }
5459: if (!$gottab) {
5460: my $confname = $cdom.'-domainconfig';
5461: my $default = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res/'.$cdom.'/'.$confname.'/default.tab';
5462: my $formatfile = &Apache::lonnet::getfile($default);
5463: if ($formatfile ne '-1') {
5464: @lines = split("\n",$formatfile,-1);
5465: $gottab = 1;
5466: }
5467: }
5468: if (!$gottab) {
1.519 raeburn 5469: my @domains = &Apache::lonnet::current_machine_domains();
5470: if (grep(/^\Q$cdom\E$/,@domains)) {
5471: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
5472: @lines = <$fh>;
5473: close($fh);
5474: } else {
5475: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab');
5476: @lines = <$fh>;
5477: close($fh);
5478: }
1.518 raeburn 5479: }
5480: return @lines;
1.82 albertel 5481: }
5482:
1.423 albertel 5483: =pod
5484:
5485: =item scantron_CODElist
5486:
5487: Returns html drop down of the saved CODE lists from current course,
5488: generated from earlier printings.
5489:
5490: =cut
1.422 foxr 5491:
1.186 albertel 5492: sub scantron_CODElist {
1.257 albertel 5493: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5494: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.186 albertel 5495: my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
5496: my $namechoice='<option></option>';
1.225 albertel 5497: foreach my $name (sort {uc($a) cmp uc($b)} @names) {
1.191 albertel 5498: if ($name =~ /^error: 2 /) { next; }
1.278 albertel 5499: if ($name =~ /^type\0/) { next; }
1.186 albertel 5500: $namechoice.='<option value="'.$name.'">'.$name.'</option>';
5501: }
5502: $namechoice='<select name="scantron_CODElist">'.$namechoice.'</select>';
5503: return $namechoice;
5504: }
5505:
1.423 albertel 5506: =pod
5507:
5508: =item scantron_CODEunique
5509:
5510: Returns the html for "Each CODE to be used once" radio.
5511:
5512: =cut
1.422 foxr 5513:
1.186 albertel 5514: sub scantron_CODEunique {
1.532 bisitz 5515: my $result='<span class="LC_nobreak">
1.272 albertel 5516: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 5517: value="yes" checked="checked" />'.&mt('Yes').' </label>
1.381 albertel 5518: </span>
1.532 bisitz 5519: <span class="LC_nobreak">
1.272 albertel 5520: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 5521: value="no" />'.&mt('No').' </label>
1.381 albertel 5522: </span>';
1.186 albertel 5523: return $result;
5524: }
1.423 albertel 5525:
5526: =pod
5527:
5528: =item scantron_selectphase
5529:
1.596.2.6 raeburn 5530: Generates the initial screen to start the bubblesheet process.
1.423 albertel 5531: Allows for - starting a grading run.
1.424 albertel 5532: - downloading existing scan data (original, corrected
1.423 albertel 5533: or skipped info)
5534:
5535: - uploading new scan data
5536:
5537: Arguments:
5538: $r - The Apache request object
5539: $file2grade - name of the file that contain the scanned data to score
5540:
5541: =cut
1.186 albertel 5542:
1.75 albertel 5543: sub scantron_selectphase {
1.209 ng 5544: my ($r,$file2grade) = @_;
1.324 albertel 5545: my ($symb)=&get_symb($r);
1.75 albertel 5546: if (!$symb) {return '';}
1.582 raeburn 5547: my $map_error;
5548: my $sequence_selector=&getSequenceDropDown($symb,\$map_error);
5549: if ($map_error) {
5550: $r->print('<br />'.&navmap_errormsg().'<br />');
5551: return;
5552: }
1.324 albertel 5553: my $default_form_data=&defaultFormData($symb);
5554: my $grading_menu_button=&show_grading_menu_form($symb);
1.209 ng 5555: my $file_selector=&scantron_uploads($file2grade);
1.82 albertel 5556: my $format_selector=&scantron_scantab();
1.186 albertel 5557: my $CODE_selector=&scantron_CODElist();
5558: my $CODE_unique=&scantron_CODEunique();
1.75 albertel 5559: my $result;
1.422 foxr 5560:
1.513 foxr 5561: $ssi_error = 0;
5562:
1.596.2.4 raeburn 5563: if (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) ||
5564: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
5565:
5566: # Chunk of form to prompt for a scantron file upload.
5567:
5568: $r->print('
5569: <br />
5570: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5571: '.&Apache::loncommon::start_data_table_header_row().'
5572: <th>
5573: '.&mt('Specify a bubblesheet data file to upload.').'
5574: </th>
5575: '.&Apache::loncommon::end_data_table_header_row().'
5576: '.&Apache::loncommon::start_data_table_row().'
5577: <td>
5578: ');
5579: my $default_form_data=&defaultFormData(&get_symb($r,1));
5580: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
5581: my $cnum= $env{'course.'.$env{'request.course.id'}.'.num'};
5582: $r->print('
5583: <script type="text/javascript" language="javascript">
5584: function checkUpload(formname) {
5585: if (formname.upfile.value == "") {
5586: alert("'.&mt('Please use the browse button to select a file from your local directory.').'");
5587: return false;
5588: }
5589: formname.submit();
5590: }
5591: </script>
5592:
5593: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
5594: '.$default_form_data.'
5595: <input name="courseid" type="hidden" value="'.$cnum.'" />
5596: <input name="domainid" type="hidden" value="'.$cdom.'" />
5597: <input name="command" value="scantronupload_save" type="hidden" />
5598: '.&mt('File to upload: [_1]','<input type="file" name="upfile" size="50" />').'
5599: <br />
5600: <input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
5601: </form>
5602: ');
5603:
5604: $r->print('
5605: </td>
5606: '.&Apache::loncommon::end_data_table_row().'
5607: '.&Apache::loncommon::end_data_table().'
5608: ');
5609: }
5610:
1.422 foxr 5611: # Chunk of form to prompt for a file to grade and how:
5612:
1.489 albertel 5613: $result.= '
5614: <br />
5615: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantron_process">
5616: <input type="hidden" name="command" value="scantron_warning" />
5617: '.$default_form_data.'
5618: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5619: '.&Apache::loncommon::start_data_table_header_row().'
5620: <th colspan="2">
1.492 albertel 5621: '.&mt('Specify file and which Folder/Sequence to grade').'
1.489 albertel 5622: </th>
5623: '.&Apache::loncommon::end_data_table_header_row().'
5624: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5625: <td> '.&mt('Sequence to grade:').' </td><td> '.$sequence_selector.' </td>
1.489 albertel 5626: '.&Apache::loncommon::end_data_table_row().'
5627: '.&Apache::loncommon::start_data_table_row().'
1.572 www 5628: <td> '.&mt('Filename of bubblesheet data file:').' </td><td> '.$file_selector.' </td>
1.489 albertel 5629: '.&Apache::loncommon::end_data_table_row().'
5630: '.&Apache::loncommon::start_data_table_row().'
1.572 www 5631: <td> '.&mt('Format of bubblesheet data file:').' </td><td> '.$format_selector.' </td>
1.489 albertel 5632: '.&Apache::loncommon::end_data_table_row().'
5633: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5634: <td> '.&mt('Saved CODEs to validate against:').' </td><td> '.$CODE_selector.' </td>
1.489 albertel 5635: '.&Apache::loncommon::end_data_table_row().'
5636: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5637: <td> '.&mt('Each CODE is only to be used once:').'</td><td> '.$CODE_unique.' </td>
1.489 albertel 5638: '.&Apache::loncommon::end_data_table_row().'
5639: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5640: <td> '.&mt('Options:').' </td>
1.187 albertel 5641: <td>
1.492 albertel 5642: <label><input type="checkbox" name="scantron_options_redo" value="redo_skipped"/> '.&mt('Do only previously skipped records').'</label> <br />
5643: <label><input type="checkbox" name="scantron_options_ignore" value="ignore_corrections"/> '.&mt('Remove all existing corrections').'</label> <br />
5644: <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources when grading').'</label>
1.187 albertel 5645: </td>
1.489 albertel 5646: '.&Apache::loncommon::end_data_table_row().'
5647: '.&Apache::loncommon::start_data_table_row().'
1.174 albertel 5648: <td colspan="2">
1.572 www 5649: <input type="submit" value="'.&mt('Grading: Validate Bubblesheet Records').'" />
1.162 albertel 5650: </td>
1.489 albertel 5651: '.&Apache::loncommon::end_data_table_row().'
5652: '.&Apache::loncommon::end_data_table().'
5653: </form>
5654: ';
1.162 albertel 5655:
5656: $r->print($result);
5657:
1.422 foxr 5658: # Chunk of the form that prompts to view a scoring office file,
5659: # corrected file, skipped records in a file.
5660:
1.489 albertel 5661: $r->print('
5662: <br />
5663: <form action="/adm/grades" name="scantron_download">
5664: '.$default_form_data.'
5665: <input type="hidden" name="command" value="scantron_download" />
5666: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5667: '.&Apache::loncommon::start_data_table_header_row().'
5668: <th>
1.492 albertel 5669: '.&mt('Download a scoring office file').'
1.489 albertel 5670: </th>
5671: '.&Apache::loncommon::end_data_table_header_row().'
5672: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5673: <td> '.&mt('Filename of scoring office file: [_1]',$file_selector).'
1.489 albertel 5674: <br />
1.492 albertel 5675: <input type="submit" value="'.&mt('Download: Show List of Associated Files').'" />
1.489 albertel 5676: '.&Apache::loncommon::end_data_table_row().'
5677: '.&Apache::loncommon::end_data_table().'
5678: </form>
5679: <br />
5680: ');
1.162 albertel 5681:
1.457 banghart 5682: &Apache::lonpickcode::code_list($r,2);
1.523 raeburn 5683:
1.528 raeburn 5684: $r->print('<br /><form method="post" name="checkscantron">'.
1.523 raeburn 5685: $default_form_data."\n".
5686: &Apache::loncommon::start_data_table('LC_scantron_action')."\n".
5687: &Apache::loncommon::start_data_table_header_row()."\n".
5688: '<th colspan="2">
1.572 www 5689: '.&mt('Review bubblesheet data and submissions for a previously graded folder/sequence')."\n".
1.523 raeburn 5690: '</th>'."\n".
5691: &Apache::loncommon::end_data_table_header_row()."\n".
5692: &Apache::loncommon::start_data_table_row()."\n".
5693: '<td> '.&mt('Graded folder/sequence:').' </td>'."\n".
5694: '<td> '.$sequence_selector.' </td>'.
5695: &Apache::loncommon::end_data_table_row()."\n".
5696: &Apache::loncommon::start_data_table_row()."\n".
5697: '<td> '.&mt('Filename of scoring office file:').' </td>'."\n".
5698: '<td> '.$file_selector.' </td>'."\n".
5699: &Apache::loncommon::end_data_table_row()."\n".
5700: &Apache::loncommon::start_data_table_row()."\n".
5701: '<td> '.&mt('Format of data file:').' </td>'."\n".
5702: '<td> '.$format_selector.' </td>'."\n".
5703: &Apache::loncommon::end_data_table_row()."\n".
5704: &Apache::loncommon::start_data_table_row()."\n".
1.557 raeburn 5705: '<td> '.&mt('Options').' </td>'."\n".
5706: '<td> <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources').'</label></td>'.
5707: &Apache::loncommon::end_data_table_row()."\n".
5708: &Apache::loncommon::start_data_table_row()."\n".
1.523 raeburn 5709: '<td colspan="2">'."\n".
5710: '<input type="hidden" name="command" value="checksubmissions" />'."\n".
1.575 www 5711: '<input type="submit" value="'.&mt('Review Bubblesheet Data and Submission Records').'" />'."\n".
1.523 raeburn 5712: '</td>'."\n".
5713: &Apache::loncommon::end_data_table_row()."\n".
5714: &Apache::loncommon::end_data_table()."\n".
5715: '</form><br />');
1.457 banghart 5716: $r->print($grading_menu_button);
1.523 raeburn 5717: return;
1.75 albertel 5718: }
5719:
1.423 albertel 5720: =pod
5721:
5722: =item get_scantron_config
5723:
5724: Parse and return the scantron configuration line selected as a
5725: hash of configuration file fields.
5726:
5727: Arguments:
5728: which - the name of the configuration to parse from the file.
5729:
5730:
5731: Returns:
5732: If the named configuration is not in the file, an empty
5733: hash is returned.
5734: a hash with the fields
5735: name - internal name for the this configuration setup
5736: description - text to display to operator that describes this config
5737: CODElocation - if 0 or the string 'none'
5738: - no CODE exists for this config
5739: if -1 || the string 'letter'
5740: - a CODE exists for this config and is
5741: a string of letters
5742: Unsupported value (but planned for future support)
5743: if a positive integer
5744: - The CODE exists as the first n items from
5745: the question section of the form
5746: if the string 'number'
5747: - The CODE exists for this config and is
5748: a string of numbers
5749: CODEstart - (only matter if a CODE exists) column in the line where
5750: the CODE starts
5751: CODElength - length of the CODE
1.573 bisitz 5752: IDstart - column where the student/employee ID starts
1.556 weissno 5753: IDlength - length of the student/employee ID info
1.423 albertel 5754: Qstart - column where the information from the bubbled
5755: 'questions' start
5756: Qlength - number of columns comprising a single bubble line from
5757: the sheet. (usually either 1 or 10)
1.424 albertel 5758: Qon - either a single character representing the character used
1.423 albertel 5759: to signal a bubble was chosen in the positional setup, or
5760: the string 'letter' if the letter of the chosen bubble is
5761: in the final, or 'number' if a number representing the
5762: chosen bubble is in the file (1->A 0->J)
1.424 albertel 5763: Qoff - the character used to represent that a bubble was
5764: left blank
1.423 albertel 5765: PaperID - if the scanning process generates a unique number for each
5766: sheet scanned the column that this ID number starts in
5767: PaperIDlength - number of columns that comprise the unique ID number
5768: for the sheet of paper
1.424 albertel 5769: FirstName - column that the first name starts in
1.423 albertel 5770: FirstNameLength - number of columns that the first name spans
5771:
5772: LastName - column that the last name starts in
5773: LastNameLength - number of columns that the last name spans
1.596.2.12.2. (raeburn 5774:): BubblesPerRow - number of bubbles available in each row used to
5775:): bubble an answer. (If not specified, 10 assumed).
1.423 albertel 5776:
5777: =cut
1.422 foxr 5778:
1.82 albertel 5779: sub get_scantron_config {
5780: my ($which) = @_;
1.518 raeburn 5781: my @lines = &get_scantronformat_file();
1.82 albertel 5782: my %config;
1.157 albertel 5783: #FIXME probably should move to XML it has already gotten a bit much now
1.518 raeburn 5784: foreach my $line (@lines) {
1.82 albertel 5785: my ($name,$descrip)=split(/:/,$line);
5786: if ($name ne $which ) { next; }
5787: chomp($line);
5788: my @config=split(/:/,$line);
5789: $config{'name'}=$config[0];
5790: $config{'description'}=$config[1];
5791: $config{'CODElocation'}=$config[2];
5792: $config{'CODEstart'}=$config[3];
5793: $config{'CODElength'}=$config[4];
5794: $config{'IDstart'}=$config[5];
5795: $config{'IDlength'}=$config[6];
5796: $config{'Qstart'}=$config[7];
1.497 foxr 5797: $config{'Qlength'}=$config[8];
1.82 albertel 5798: $config{'Qoff'}=$config[9];
5799: $config{'Qon'}=$config[10];
1.157 albertel 5800: $config{'PaperID'}=$config[11];
5801: $config{'PaperIDlength'}=$config[12];
5802: $config{'FirstName'}=$config[13];
5803: $config{'FirstNamelength'}=$config[14];
5804: $config{'LastName'}=$config[15];
5805: $config{'LastNamelength'}=$config[16];
1.596.2.12.2. (raeburn 5806:): $config{'BubblesPerRow'}=$config[17];
1.82 albertel 5807: last;
5808: }
5809: return %config;
5810: }
5811:
1.423 albertel 5812: =pod
5813:
5814: =item username_to_idmap
5815:
1.556 weissno 5816: creates a hash keyed by student/employee ID with values of the corresponding
1.423 albertel 5817: student username:domain.
5818:
5819: Arguments:
5820:
5821: $classlist - reference to the class list hash. This is a hash
5822: keyed by student name:domain whose elements are references
1.424 albertel 5823: to arrays containing various chunks of information
1.423 albertel 5824: about the student. (See loncoursedata for more info).
5825:
5826: Returns
5827: %idmap - the constructed hash
5828:
5829: =cut
5830:
1.82 albertel 5831: sub username_to_idmap {
5832: my ($classlist)= @_;
5833: my %idmap;
5834: foreach my $student (keys(%$classlist)) {
5835: $idmap{$classlist->{$student}->[&Apache::loncoursedata::CL_ID]}=
5836: $student;
5837: }
5838: return %idmap;
5839: }
1.423 albertel 5840:
5841: =pod
5842:
1.424 albertel 5843: =item scantron_fixup_scanline
1.423 albertel 5844:
5845: Process a requested correction to a scanline.
5846:
5847: Arguments:
5848: $scantron_config - hash from &get_scantron_config()
5849: $scan_data - hash of correction information
5850: (see &scantron_getfile())
5851: $line - existing scanline
5852: $whichline - line number of the passed in scanline
5853: $field - type of change to process
5854: (either
1.573 bisitz 5855: 'ID' -> correct the student/employee ID
1.423 albertel 5856: 'CODE' -> correct the CODE
5857: 'answer' -> fixup the submitted answers)
5858:
5859: $args - hash of additional info,
5860: - 'ID'
5861: 'newid' -> studentID to use in replacement
1.424 albertel 5862: of existing one
1.423 albertel 5863: - 'CODE'
5864: 'CODE_ignore_dup' - set to true if duplicates
5865: should be ignored.
5866: 'CODE' - is new code or 'use_unfound'
1.424 albertel 5867: if the existing unfound code should
1.423 albertel 5868: be used as is
5869: - 'answer'
5870: 'response' - new answer or 'none' if blank
5871: 'question' - the bubble line to change
1.503 raeburn 5872: 'questionnum' - the question identifier,
5873: may include subquestion.
1.423 albertel 5874:
5875: Returns:
5876: $line - the modified scanline
5877:
5878: Side effects:
5879: $scan_data - may be updated
5880:
5881: =cut
5882:
1.82 albertel 5883:
1.157 albertel 5884: sub scantron_fixup_scanline {
5885: my ($scantron_config,$scan_data,$line,$whichline,$field,$args)=@_;
5886: if ($field eq 'ID') {
5887: if (length($args->{'newid'}) > $$scantron_config{'IDlength'}) {
1.186 albertel 5888: return ($line,1,'New value too large');
1.157 albertel 5889: }
5890: if (length($args->{'newid'}) < $$scantron_config{'IDlength'}) {
5891: $args->{'newid'}=sprintf('%-'.$$scantron_config{'IDlength'}.'s',
5892: $args->{'newid'});
5893: }
5894: substr($line,$$scantron_config{'IDstart'}-1,
5895: $$scantron_config{'IDlength'})=$args->{'newid'};
5896: if ($args->{'newid'}=~/^\s*$/) {
5897: &scan_data($scan_data,"$whichline.user",
5898: $args->{'username'}.':'.$args->{'domain'});
5899: }
1.186 albertel 5900: } elsif ($field eq 'CODE') {
1.192 albertel 5901: if ($args->{'CODE_ignore_dup'}) {
5902: &scan_data($scan_data,"$whichline.CODE_ignore_dup",'1');
5903: }
5904: &scan_data($scan_data,"$whichline.useCODE",'1');
5905: if ($args->{'CODE'} ne 'use_unfound') {
1.191 albertel 5906: if (length($args->{'CODE'}) > $$scantron_config{'CODElength'}) {
5907: return ($line,1,'New CODE value too large');
5908: }
5909: if (length($args->{'CODE'}) < $$scantron_config{'CODElength'}) {
5910: $args->{'CODE'}=sprintf('%-'.$$scantron_config{'CODElength'}.'s',$args->{'CODE'});
5911: }
5912: substr($line,$$scantron_config{'CODEstart'}-1,
5913: $$scantron_config{'CODElength'})=$args->{'CODE'};
1.186 albertel 5914: }
1.157 albertel 5915: } elsif ($field eq 'answer') {
1.497 foxr 5916: my $length=$scantron_config->{'Qlength'};
1.157 albertel 5917: my $off=$scantron_config->{'Qoff'};
5918: my $on=$scantron_config->{'Qon'};
1.497 foxr 5919: my $answer=${off}x$length;
5920: if ($args->{'response'} eq 'none') {
5921: &scan_data($scan_data,
1.503 raeburn 5922: "$whichline.no_bubble.".$args->{'questionnum'},'1');
1.497 foxr 5923: } else {
5924: if ($on eq 'letter') {
5925: my @alphabet=('A'..'Z');
5926: $answer=$alphabet[$args->{'response'}];
5927: } elsif ($on eq 'number') {
5928: $answer=$args->{'response'}+1;
5929: if ($answer == 10) { $answer = '0'; }
1.274 albertel 5930: } else {
1.497 foxr 5931: substr($answer,$args->{'response'},1)=$on;
1.274 albertel 5932: }
1.497 foxr 5933: &scan_data($scan_data,
1.503 raeburn 5934: "$whichline.no_bubble.".$args->{'questionnum'},undef,'1');
1.157 albertel 5935: }
1.497 foxr 5936: my $where=$length*($args->{'question'}-1)+$scantron_config->{'Qstart'};
5937: substr($line,$where-1,$length)=$answer;
1.157 albertel 5938: }
5939: return $line;
5940: }
1.423 albertel 5941:
5942: =pod
5943:
5944: =item scan_data
5945:
5946: Edit or look up an item in the scan_data hash.
5947:
5948: Arguments:
5949: $scan_data - The hash (see scantron_getfile)
5950: $key - shorthand of the key to edit (actual key is
1.424 albertel 5951: scantronfilename_key).
1.423 albertel 5952: $data - New value of the hash entry.
5953: $delete - If true, the entry is removed from the hash.
5954:
5955: Returns:
5956: The new value of the hash table field (undefined if deleted).
5957:
5958: =cut
5959:
5960:
1.157 albertel 5961: sub scan_data {
5962: my ($scan_data,$key,$value,$delete)=@_;
1.257 albertel 5963: my $filename=$env{'form.scantron_selectfile'};
1.157 albertel 5964: if (defined($value)) {
5965: $scan_data->{$filename.'_'.$key} = $value;
5966: }
5967: if ($delete) { delete($scan_data->{$filename.'_'.$key}); }
5968: return $scan_data->{$filename.'_'.$key};
5969: }
1.423 albertel 5970:
1.495 albertel 5971: # ----- These first few routines are general use routines.----
5972:
5973: # Return the number of occurences of a pattern in a string.
5974:
5975: sub occurence_count {
5976: my ($string, $pattern) = @_;
5977:
5978: my @matches = ($string =~ /$pattern/g);
5979:
5980: return scalar(@matches);
5981: }
5982:
5983:
5984: # Take a string known to have digits and convert all the
5985: # digits into letters in the range J,A..I.
5986:
5987: sub digits_to_letters {
5988: my ($input) = @_;
5989:
5990: my @alphabet = ('J', 'A'..'I');
5991:
5992: my @input = split(//, $input);
5993: my $output ='';
5994: for (my $i = 0; $i < scalar(@input); $i++) {
5995: if ($input[$i] =~ /\d/) {
5996: $output .= $alphabet[$input[$i]];
5997: } else {
5998: $output .= $input[$i];
5999: }
6000: }
6001: return $output;
6002: }
6003:
1.423 albertel 6004: =pod
6005:
6006: =item scantron_parse_scanline
6007:
6008: Decodes a scanline from the selected scantron file
6009:
6010: Arguments:
6011: line - The text of the scantron file line to process
6012: whichline - Line number
6013: scantron_config - Hash describing the format of the scantron lines.
6014: scan_data - Hash of extra information about the scanline
6015: (see scantron_getfile for more information)
6016: just_header - True if should not process question answers but only
6017: the stuff to the left of the answers.
1.596.2.12.2. 6(raebur 6018:3): randomorder - True if randomorder in use
6019:3): randompick - True if randompick in use
6020:3): sequence - Exam folder URL
6021:3): master_seq - Ref to array containing symbs in exam folder
6022:3): symb_to_resource - Ref to hash of symbs for resources in exam folder
6023:3): (corresponding values are resource objects)
6024:3): partids_by_symb - Ref to hash of symb -> array ref of partIDs
6025:3): orderedforcode - Ref to hash of arrays. keys are CODEs and values
6026:3): are refs to an array of resource objects, ordered
6027:3): according to order used for CODE, when randomorder
6028:3): and or randompick are in use.
6029:3): respnumlookup - Ref to hash mapping question numbers in bubble lines
6030:3): for current line to question number used for same question
6031:3): in "Master Sequence" (as seen by Course Coordinator).
6032:3): startline - Ref to hash where key is question number (0 is first)
6033:3): and value is number of first bubble line for current
6034:3): student or code-based randompick and/or randomorder.
6035:3): totalref - Ref of scalar used to score total number of bubble
6036:3): lines needed for responses in a scan line (used when
6037:3): randompick in use.
6038:3):
1.423 albertel 6039: Returns:
6040: Hash containing the result of parsing the scanline
6041:
6042: Keys are all proceeded by the string 'scantron.'
6043:
6044: CODE - the CODE in use for this scanline
6045: useCODE - 1 if the CODE is invalid but it usage has been forced
6046: by the operator
6047: CODE_ignore_dup - 1 if the CODE is a duplicated use when unique
6048: CODEs were selected, but the usage has been
6049: forced by the operator
1.556 weissno 6050: ID - student/employee ID
1.423 albertel 6051: PaperID - if used, the ID number printed on the sheet when the
6052: paper was scanned
6053: FirstName - first name from the sheet
6054: LastName - last name from the sheet
6055:
6056: if just_header was not true these key may also exist
6057:
1.447 foxr 6058: missingerror - a list of bubble ranges that are considered to be answers
6059: to a single question that don't have any bubbles filled in.
6060: Of the form questionnumber:firstbubblenumber:count.
6061: doubleerror - a list of bubble ranges that are considered to be answers
6062: to a single question that have more than one bubble filled in.
6063: Of the form questionnumber::firstbubblenumber:count
6064:
6065: In the above, count is the number of bubble responses in the
6066: input line needed to represent the possible answers to the question.
6067: e.g. a radioresponse with 15 choices in an answer sheet with 10 choices
6068: per line would have count = 2.
6069:
1.423 albertel 6070: maxquest - the number of the last bubble line that was parsed
6071:
6072: (<number> starts at 1)
6073: <number>.answer - zero or more letters representing the selected
6074: letters from the scanline for the bubble line
6075: <number>.
6076: if blank there was either no bubble or there where
6077: multiple bubbles, (consult the keys missingerror and
6078: doubleerror if this is an error condition)
6079:
6080: =cut
6081:
1.82 albertel 6082: sub scantron_parse_scanline {
1.596.2.12.2. 6(raebur 6083:3): my ($line,$whichline,$scantron_config,$scan_data,$just_header,$idmap,
6084:3): $randomorder,$randompick,$sequence,$master_seq,$symb_to_resource,
6085:3): $partids_by_symb,$orderedforcode,$respnumlookup,$startline,$totalref)=@_;
1.470 foxr 6086:
1.82 albertel 6087: my %record;
1.596.2.12.2. 6(raebur 6088:3): my $data=substr($line,0,$$scantron_config{'Qstart'}-1); # stuff before answers
1.278 albertel 6089: if (!($$scantron_config{'CODElocation'} eq 0 ||
6090: $$scantron_config{'CODElocation'} eq 'none')) {
6091: if ($$scantron_config{'CODElocation'} < 0 ||
6092: $$scantron_config{'CODElocation'} eq 'letter' ||
6093: $$scantron_config{'CODElocation'} eq 'number') {
1.191 albertel 6094: $record{'scantron.CODE'}=substr($data,
6095: $$scantron_config{'CODEstart'}-1,
1.83 albertel 6096: $$scantron_config{'CODElength'});
1.191 albertel 6097: if (&scan_data($scan_data,"$whichline.useCODE")) {
6098: $record{'scantron.useCODE'}=1;
6099: }
1.192 albertel 6100: if (&scan_data($scan_data,"$whichline.CODE_ignore_dup")) {
6101: $record{'scantron.CODE_ignore_dup'}=1;
6102: }
1.82 albertel 6103: } else {
6104: #FIXME interpret first N questions
6105: }
6106: }
1.83 albertel 6107: $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
6108: $$scantron_config{'IDlength'});
1.157 albertel 6109: $record{'scantron.PaperID'}=
6110: substr($data,$$scantron_config{'PaperID'}-1,
6111: $$scantron_config{'PaperIDlength'});
6112: $record{'scantron.FirstName'}=
6113: substr($data,$$scantron_config{'FirstName'}-1,
6114: $$scantron_config{'FirstNamelength'});
6115: $record{'scantron.LastName'}=
6116: substr($data,$$scantron_config{'LastName'}-1,
6117: $$scantron_config{'LastNamelength'});
1.423 albertel 6118: if ($just_header) { return \%record; }
1.194 albertel 6119:
1.82 albertel 6120: my @alphabet=('A'..'Z');
6121: my $questnum=0;
1.447 foxr 6122: my $ansnum =1; # Multiple 'answer lines'/question.
6123:
1.596.2.12.2. 6(raebur 6124:3): my $lastpos = $env{'form.scantron_maxbubble'}*$$scantron_config{'Qlength'};
6125:3): if ($randompick || $randomorder) {
6126:3): my $total = &get_respnum_lookups($sequence,$scan_data,$idmap,$line,\%record,
6127:3): $master_seq,$symb_to_resource,
6128:3): $partids_by_symb,$orderedforcode,
6129:3): $respnumlookup,$startline);
6130:3): if ($total) {
6131:3): $lastpos = $total*$$scantron_config{'Qlength'};
6132:3): }
6133:3): if (ref($totalref)) {
6134:3): $$totalref = $total;
6135:3): }
6136:3): }
6137:3): my $questions=substr($line,$$scantron_config{'Qstart'}-1,$lastpos); # Answers
1.470 foxr 6138: chomp($questions); # Get rid of any trailing \n.
6139: $questions =~ s/\r$//; # Get rid of trailing \r too (MAC or Win uploads).
6140: while (length($questions)) {
1.596.2.12.2. 6(raebur 6141:3): my $answers_needed;
6142:3): if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
6143:3): $answers_needed = $bubble_lines_per_response{$respnumlookup->{$questnum}};
6144:3): } else {
6145:3): $answers_needed = $bubble_lines_per_response{$questnum};
6146:3): }
1.503 raeburn 6147: my $answer_length = ($$scantron_config{'Qlength'} * $answers_needed)
6148: || 1;
6149: $questnum++;
6150: my $quest_id = $questnum;
6151: my $currentquest = substr($questions,0,$answer_length);
6152: $questions = substr($questions,$answer_length);
6153: if (length($currentquest) < $answer_length) { next; }
6154:
1.596.2.12.2. 6(raebur 6155:3): my $subdivided;
6156:3): if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
6157:3): $subdivided = $subdivided_bubble_lines{$respnumlookup->{$questnum-1}};
6158:3): } else {
6159:3): $subdivided = $subdivided_bubble_lines{$questnum-1};
6160:3): }
6161:3): if ($subdivided =~ /,/) {
1.503 raeburn 6162: my $subquestnum = 1;
6163: my $subquestions = $currentquest;
1.596.2.12.2. 6(raebur 6164:3): my @subanswers_needed = split(/,/,$subdivided);
1.503 raeburn 6165: foreach my $subans (@subanswers_needed) {
6166: my $subans_length =
6167: ($$scantron_config{'Qlength'} * $subans) || 1;
6168: my $currsubquest = substr($subquestions,0,$subans_length);
6169: $subquestions = substr($subquestions,$subans_length);
6170: $quest_id = "$questnum.$subquestnum";
6171: if (($$scantron_config{'Qon'} eq 'letter') ||
6172: ($$scantron_config{'Qon'} eq 'number')) {
6173: $ansnum = &scantron_validator_lettnum($ansnum,
6174: $questnum,$quest_id,$subans,$currsubquest,$whichline,
1.596.2.12.2. 6(raebur 6175:3): \@alphabet,\%record,$scantron_config,$scan_data,
6176:3): $randomorder,$randompick,$respnumlookup);
1.503 raeburn 6177: } else {
6178: $ansnum = &scantron_validator_positional($ansnum,
1.596.2.12.2. 6(raebur 6179:3): $questnum,$quest_id,$subans,$currsubquest,$whichline,
6180:3): \@alphabet,\%record,$scantron_config,$scan_data,
6181:3): $randomorder,$randompick,$respnumlookup);
1.503 raeburn 6182: }
6183: $subquestnum ++;
6184: }
6185: } else {
6186: if (($$scantron_config{'Qon'} eq 'letter') ||
6187: ($$scantron_config{'Qon'} eq 'number')) {
6188: $ansnum = &scantron_validator_lettnum($ansnum,$questnum,
6189: $quest_id,$answers_needed,$currentquest,$whichline,
1.596.2.12.2. 6(raebur 6190:3): \@alphabet,\%record,$scantron_config,$scan_data,
6191:3): $randomorder,$randompick,$respnumlookup);
1.503 raeburn 6192: } else {
6193: $ansnum = &scantron_validator_positional($ansnum,$questnum,
6194: $quest_id,$answers_needed,$currentquest,$whichline,
1.596.2.12.2. 6(raebur 6195:3): \@alphabet,\%record,$scantron_config,$scan_data,
6196:3): $randomorder,$randompick,$respnumlookup);
1.503 raeburn 6197: }
6198: }
6199: }
6200: $record{'scantron.maxquest'}=$questnum;
6201: return \%record;
6202: }
1.447 foxr 6203:
1.596.2.12.2. 6(raebur 6204:3): sub get_master_seq {
6205:3): my ($resources,$master_seq,$symb_to_resource) = @_;
6206:3): return unless ((ref($resources) eq 'ARRAY') && (ref($master_seq) eq 'ARRAY') &&
6207:3): (ref($symb_to_resource) eq 'HASH'));
6208:3): my $resource_error;
6209:3): foreach my $resource (@{$resources}) {
6210:3): my $ressymb;
6211:3): if (ref($resource)) {
6212:3): $ressymb = $resource->symb();
6213:3): push(@{$master_seq},$ressymb);
6214:3): $symb_to_resource->{$ressymb} = $resource;
6215:3): } else {
6216:3): $resource_error = 1;
6217:3): last;
6218:3): }
6219:3): }
6220:3): return $resource_error;
6221:3): }
6222:3):
6223:3): sub get_respnum_lookups {
6224:3): my ($sequence,$scan_data,$idmap,$line,$record,$master_seq,$symb_to_resource,
6225:3): $partids_by_symb,$orderedforcode,$respnumlookup,$startline) = @_;
6226:3): return unless ((ref($record) eq 'HASH') && (ref($master_seq) eq 'ARRAY') &&
6227:3): (ref($symb_to_resource) eq 'HASH') && (ref($partids_by_symb) eq 'HASH') &&
6228:3): (ref($orderedforcode) eq 'HASH') && (ref($respnumlookup) eq 'HASH') &&
6229:3): (ref($startline) eq 'HASH'));
6230:3): my ($user,$scancode);
6231:3): if ((exists($record->{'scantron.CODE'})) &&
6232:3): (&Apache::lonnet::validCODE($record->{'scantron.CODE'}))) {
6233:3): $scancode = $record->{'scantron.CODE'};
6234:3): } else {
6235:3): $user = &scantron_find_student($record,$scan_data,$idmap,$line);
6236:3): }
6237:3): my @mapresources =
6238:3): &users_order($user,$scancode,$sequence,$master_seq,$symb_to_resource,
6239:3): $orderedforcode);
6240:3): my $total = 0;
6241:3): my $count = 0;
6242:3): foreach my $resource (@mapresources) {
6243:3): my $id = $resource->id();
6244:3): my $symb = $resource->symb();
6245:3): if (ref($partids_by_symb->{$symb}) eq 'ARRAY') {
6246:3): foreach my $partid (@{$partids_by_symb->{$symb}}) {
6247:3): my $respnum = $masterseq_id_responsenum{$id.'_'.$partid};
6248:3): if ($respnum ne '') {
6249:3): $respnumlookup->{$count} = $respnum;
6250:3): $startline->{$count} = $total;
6251:3): $total += $bubble_lines_per_response{$respnum};
6252:3): $count ++;
6253:3): }
6254:3): }
6255:3): }
6256:3): }
6257:3): return $total;
6258:3): }
6259:3):
1.503 raeburn 6260: sub scantron_validator_lettnum {
6261: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,$whichline,
1.596.2.12.2. 6(raebur 6262:3): $alphabet,$record,$scantron_config,$scan_data,$randomorder,
6263:3): $randompick,$respnumlookup) = @_;
1.503 raeburn 6264:
6265: # Qon 'letter' implies for each slot in currquest we have:
6266: # ? or * for doubles, a letter in A-Z for a bubble, and
6267: # about anything else (esp. a value of Qoff) for missing
6268: # bubbles.
6269: #
6270: # Qon 'number' implies each slot gives a digit that indexes the
6271: # bubbles filled, or Qoff, or a non-number for unbubbled lines,
6272: # and * or ? for double bubbles on a single line.
6273: #
1.447 foxr 6274:
1.503 raeburn 6275: my $matchon;
6276: if ($$scantron_config{'Qon'} eq 'letter') {
6277: $matchon = '[A-Z]';
6278: } elsif ($$scantron_config{'Qon'} eq 'number') {
6279: $matchon = '\d';
6280: }
6281: my $occurrences = 0;
1.596.2.12.2. 6(raebur 6282:3): my $responsenum = $questnum-1;
6283:3): if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
6284:3): $responsenum = $respnumlookup->{$questnum-1}
6285:3): }
6286:3): if (($responsetype_per_response{$responsenum} eq 'essayresponse') ||
6287:3): ($responsetype_per_response{$responsenum} eq 'formularesponse') ||
6288:3): ($responsetype_per_response{$responsenum} eq 'stringresponse') ||
6289:3): ($responsetype_per_response{$responsenum} eq 'imageresponse') ||
6290:3): ($responsetype_per_response{$responsenum} eq 'reactionresponse') ||
6291:3): ($responsetype_per_response{$responsenum} eq 'organicresponse')) {
1.503 raeburn 6292: my @singlelines = split('',$currquest);
6293: foreach my $entry (@singlelines) {
6294: $occurrences = &occurence_count($entry,$matchon);
6295: if ($occurrences > 1) {
6296: last;
6297: }
1.596.2.12.2. 6(raebur 6298:3): }
1.503 raeburn 6299: } else {
6300: $occurrences = &occurence_count($currquest,$matchon);
6301: }
6302: if (($currquest =~ /\?/ || $currquest =~ /\*/) || ($occurrences > 1)) {
6303: push(@{$record->{'scantron.doubleerror'}},$quest_id);
6304: for (my $ans=0; $ans<$answers_needed; $ans++) {
6305: my $bubble = substr($currquest,$ans,1);
6306: if ($bubble =~ /$matchon/ ) {
6307: if ($$scantron_config{'Qon'} eq 'number') {
6308: if ($bubble == 0) {
6309: $bubble = 10;
6310: }
6311: $record->{"scantron.$ansnum.answer"} =
6312: $alphabet->[$bubble-1];
6313: } else {
6314: $record->{"scantron.$ansnum.answer"} = $bubble;
6315: }
6316: } else {
6317: $record->{"scantron.$ansnum.answer"}='';
6318: }
6319: $ansnum++;
6320: }
6321: } elsif (!defined($currquest)
6322: || (&occurence_count($currquest, $$scantron_config{'Qoff'}) == length($currquest))
6323: || (&occurence_count($currquest,$matchon) == 0)) {
6324: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
6325: $record->{"scantron.$ansnum.answer"}='';
6326: $ansnum++;
6327: }
6328: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
6329: push(@{$record->{'scantron.missingerror'}},$quest_id);
6330: }
6331: } else {
6332: if ($$scantron_config{'Qon'} eq 'number') {
6333: $currquest = &digits_to_letters($currquest);
6334: }
6335: for (my $ans=0; $ans<$answers_needed; $ans++) {
6336: my $bubble = substr($currquest,$ans,1);
6337: $record->{"scantron.$ansnum.answer"} = $bubble;
6338: $ansnum++;
6339: }
6340: }
6341: return $ansnum;
6342: }
1.447 foxr 6343:
1.503 raeburn 6344: sub scantron_validator_positional {
6345: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,
1.596.2.12.2. 6(raebur 6346:3): $whichline,$alphabet,$record,$scantron_config,$scan_data,
6347:3): $randomorder,$randompick,$respnumlookup) = @_;
1.447 foxr 6348:
1.503 raeburn 6349: # Otherwise there's a positional notation;
6350: # each bubble line requires Qlength items, and there are filled in
6351: # bubbles for each case where there 'Qon' characters.
6352: #
1.447 foxr 6353:
1.503 raeburn 6354: my @array=split($$scantron_config{'Qon'},$currquest,-1);
1.447 foxr 6355:
1.503 raeburn 6356: # If the split only gives us one element.. the full length of the
6357: # answer string, no bubbles are filled in:
1.447 foxr 6358:
1.507 raeburn 6359: if ($answers_needed eq '') {
6360: return;
6361: }
6362:
1.503 raeburn 6363: if (length($array[0]) eq $$scantron_config{'Qlength'}*$answers_needed) {
6364: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
6365: $record->{"scantron.$ansnum.answer"}='';
6366: $ansnum++;
6367: }
6368: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
6369: push(@{$record->{"scantron.missingerror"}},$quest_id);
6370: }
6371: } elsif (scalar(@array) == 2) {
6372: my $location = length($array[0]);
6373: my $line_num = int($location / $$scantron_config{'Qlength'});
6374: my $bubble = $alphabet->[$location % $$scantron_config{'Qlength'}];
6375: for (my $ans=0; $ans<$answers_needed; $ans++) {
6376: if ($ans eq $line_num) {
6377: $record->{"scantron.$ansnum.answer"} = $bubble;
6378: } else {
6379: $record->{"scantron.$ansnum.answer"} = ' ';
6380: }
6381: $ansnum++;
6382: }
6383: } else {
6384: # If there's more than one instance of a bubble character
6385: # That's a double bubble; with positional notation we can
6386: # record all the bubbles filled in as well as the
6387: # fact this response consists of multiple bubbles.
6388: #
1.596.2.12.2. 6(raebur 6389:3): my $responsenum = $questnum-1;
6390:3): if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
6391:3): $responsenum = $respnumlookup->{$questnum-1}
6392:3): }
6393:3): if (($responsetype_per_response{$responsenum} eq 'essayresponse') ||
6394:3): ($responsetype_per_response{$responsenum} eq 'formularesponse') ||
6395:3): ($responsetype_per_response{$responsenum} eq 'stringresponse') ||
6396:3): ($responsetype_per_response{$responsenum} eq 'imageresponse') ||
6397:3): ($responsetype_per_response{$responsenum} eq 'reactionresponse') ||
6398:3): ($responsetype_per_response{$responsenum} eq 'organicresponse')) {
1.503 raeburn 6399: my $doubleerror = 0;
6400: while (($currquest >= $$scantron_config{'Qlength'}) &&
6401: (!$doubleerror)) {
6402: my $currline = substr($currquest,0,$$scantron_config{'Qlength'});
6403: $currquest = substr($currquest,$$scantron_config{'Qlength'});
6404: my @currarray = split($$scantron_config{'Qon'},$currline,-1);
6405: if (length(@currarray) > 2) {
6406: $doubleerror = 1;
6407: }
6408: }
6409: if ($doubleerror) {
6410: push(@{$record->{'scantron.doubleerror'}},$quest_id);
6411: }
6412: } else {
6413: push(@{$record->{'scantron.doubleerror'}},$quest_id);
6414: }
6415: my $item = $ansnum;
6416: for (my $ans=0; $ans<$answers_needed; $ans++) {
6417: $record->{"scantron.$item.answer"} = '';
6418: $item ++;
6419: }
1.447 foxr 6420:
1.503 raeburn 6421: my @ans=@array;
6422: my $i=0;
6423: my $increment = 0;
6424: while ($#ans) {
6425: $i+=length($ans[0]) + $increment;
6426: my $line = int($i/$$scantron_config{'Qlength'} + $ansnum);
6427: my $bubble = $i%$$scantron_config{'Qlength'};
6428: $record->{"scantron.$line.answer"}.=$alphabet->[$bubble];
6429: shift(@ans);
6430: $increment = 1;
6431: }
6432: $ansnum += $answers_needed;
1.82 albertel 6433: }
1.503 raeburn 6434: return $ansnum;
1.82 albertel 6435: }
6436:
1.423 albertel 6437: =pod
6438:
6439: =item scantron_add_delay
6440:
6441: Adds an error message that occurred during the grading phase to a
6442: queue of messages to be shown after grading pass is complete
6443:
6444: Arguments:
1.424 albertel 6445: $delayqueue - arrary ref of hash ref of error messages
1.423 albertel 6446: $scanline - the scanline that caused the error
6447: $errormesage - the error message
6448: $errorcode - a numeric code for the error
6449:
6450: Side Effects:
1.424 albertel 6451: updates the $delayqueue to have a new hash ref of the error
1.423 albertel 6452:
6453: =cut
6454:
1.82 albertel 6455: sub scantron_add_delay {
1.140 albertel 6456: my ($delayqueue,$scanline,$errormessage,$errorcode)=@_;
6457: push(@$delayqueue,
6458: {'line' => $scanline, 'emsg' => $errormessage,
6459: 'ecode' => $errorcode }
6460: );
1.82 albertel 6461: }
6462:
1.423 albertel 6463: =pod
6464:
6465: =item scantron_find_student
6466:
1.424 albertel 6467: Finds the username for the current scanline
6468:
6469: Arguments:
6470: $scantron_record - hash result from scantron_parse_scanline
6471: $scan_data - hash of correction information
6472: (see &scantron_getfile() form more information)
6473: $idmap - hash from &username_to_idmap()
6474: $line - number of current scanline
6475:
6476: Returns:
6477: Either 'username:domain' or undef if unknown
6478:
1.423 albertel 6479: =cut
6480:
1.82 albertel 6481: sub scantron_find_student {
1.157 albertel 6482: my ($scantron_record,$scan_data,$idmap,$line)=@_;
1.83 albertel 6483: my $scanID=$$scantron_record{'scantron.ID'};
1.157 albertel 6484: if ($scanID =~ /^\s*$/) {
6485: return &scan_data($scan_data,"$line.user");
6486: }
1.83 albertel 6487: foreach my $id (keys(%$idmap)) {
1.157 albertel 6488: if (lc($id) eq lc($scanID)) {
6489: return $$idmap{$id};
6490: }
1.83 albertel 6491: }
6492: return undef;
6493: }
6494:
1.423 albertel 6495: =pod
6496:
6497: =item scantron_filter
6498:
1.424 albertel 6499: Filter sub for lonnavmaps, filters out hidden resources if ignore
6500: hidden resources was selected
6501:
1.423 albertel 6502: =cut
6503:
1.83 albertel 6504: sub scantron_filter {
6505: my ($curres)=@_;
1.331 albertel 6506:
6507: if (ref($curres) && $curres->is_problem()) {
6508: # if the user has asked to not have either hidden
6509: # or 'randomout' controlled resources to be graded
6510: # don't include them
6511: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
6512: && $curres->randomout) {
6513: return 0;
6514: }
1.83 albertel 6515: return 1;
6516: }
6517: return 0;
1.82 albertel 6518: }
6519:
1.423 albertel 6520: =pod
6521:
6522: =item scantron_process_corrections
6523:
1.424 albertel 6524: Gets correction information out of submitted form data and corrects
6525: the scanline
6526:
1.423 albertel 6527: =cut
6528:
1.157 albertel 6529: sub scantron_process_corrections {
6530: my ($r) = @_;
1.257 albertel 6531: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 6532: my ($scanlines,$scan_data)=&scantron_getfile();
6533: my $classlist=&Apache::loncoursedata::get_classlist();
1.257 albertel 6534: my $which=$env{'form.scantron_line'};
1.200 albertel 6535: my $line=&scantron_get_line($scanlines,$scan_data,$which);
1.157 albertel 6536: my ($skip,$err,$errmsg);
1.257 albertel 6537: if ($env{'form.scantron_skip_record'}) {
1.157 albertel 6538: $skip=1;
1.257 albertel 6539: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)ID$/) {
6540: my $newstudent=$env{'form.scantron_username'}.':'.
6541: $env{'form.scantron_domain'};
1.157 albertel 6542: my $newid=$classlist->{$newstudent}->[&Apache::loncoursedata::CL_ID];
6543: ($line,$err,$errmsg)=
6544: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
6545: 'ID',{'newid'=>$newid,
1.257 albertel 6546: 'username'=>$env{'form.scantron_username'},
6547: 'domain'=>$env{'form.scantron_domain'}});
6548: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)CODE$/) {
6549: my $resolution=$env{'form.scantron_CODE_resolution'};
1.190 albertel 6550: my $newCODE;
1.192 albertel 6551: my %args;
1.190 albertel 6552: if ($resolution eq 'use_unfound') {
1.191 albertel 6553: $newCODE='use_unfound';
1.190 albertel 6554: } elsif ($resolution eq 'use_found') {
1.257 albertel 6555: $newCODE=$env{'form.scantron_CODE_selectedvalue'};
1.190 albertel 6556: } elsif ($resolution eq 'use_typed') {
1.257 albertel 6557: $newCODE=$env{'form.scantron_CODE_newvalue'};
1.194 albertel 6558: } elsif ($resolution =~ /^use_closest_(\d+)/) {
1.257 albertel 6559: $newCODE=$env{"form.scantron_CODE_closest_$1"};
1.190 albertel 6560: }
1.257 albertel 6561: if ($env{'form.scantron_corrections'} eq 'duplicateCODE') {
1.192 albertel 6562: $args{'CODE_ignore_dup'}=1;
6563: }
6564: $args{'CODE'}=$newCODE;
1.186 albertel 6565: ($line,$err,$errmsg)=
6566: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
1.192 albertel 6567: 'CODE',\%args);
1.257 albertel 6568: } elsif ($env{'form.scantron_corrections'} =~ /^(missing|double)bubble$/) {
6569: foreach my $question (split(',',$env{'form.scantron_questions'})) {
1.157 albertel 6570: ($line,$err,$errmsg)=
6571: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,
6572: $which,'answer',
6573: { 'question'=>$question,
1.503 raeburn 6574: 'response'=>$env{"form.scantron_correct_Q_$question"},
6575: 'questionnum'=>$env{"form.scantron_questionnum_Q_$question"}});
1.157 albertel 6576: if ($err) { last; }
6577: }
6578: }
6579: if ($err) {
1.398 albertel 6580: $r->print("<span class=\"LC_warning\">Unable to accept last correction, an error occurred :$errmsg:</span>");
1.157 albertel 6581: } else {
1.200 albertel 6582: &scantron_put_line($scanlines,$scan_data,$which,$line,$skip);
1.157 albertel 6583: &scantron_putfile($scanlines,$scan_data);
6584: }
6585: }
6586:
1.423 albertel 6587: =pod
6588:
6589: =item reset_skipping_status
6590:
1.424 albertel 6591: Forgets the current set of remember skipped scanlines (and thus
6592: reverts back to considering all lines in the
6593: scantron_skipped_<filename> file)
6594:
1.423 albertel 6595: =cut
6596:
1.200 albertel 6597: sub reset_skipping_status {
6598: my ($scanlines,$scan_data)=&scantron_getfile();
6599: &scan_data($scan_data,'remember_skipping',undef,1);
6600: &scantron_putfile(undef,$scan_data);
6601: }
6602:
1.423 albertel 6603: =pod
6604:
6605: =item start_skipping
6606:
1.424 albertel 6607: Marks a scanline to be skipped.
6608:
1.423 albertel 6609: =cut
6610:
1.376 albertel 6611: sub start_skipping {
1.200 albertel 6612: my ($scan_data,$i)=@_;
6613: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 6614: if ($env{'form.scantron_options_redo'} =~ /^redo_/) {
6615: $remembered{$i}=2;
6616: } else {
6617: $remembered{$i}=1;
6618: }
1.200 albertel 6619: &scan_data($scan_data,'remember_skipping',join(':',%remembered));
6620: }
6621:
1.423 albertel 6622: =pod
6623:
6624: =item should_be_skipped
6625:
1.424 albertel 6626: Checks whether a scanline should be skipped.
6627:
1.423 albertel 6628: =cut
6629:
1.200 albertel 6630: sub should_be_skipped {
1.376 albertel 6631: my ($scanlines,$scan_data,$i)=@_;
1.257 albertel 6632: if ($env{'form.scantron_options_redo'} !~ /^redo_/) {
1.200 albertel 6633: # not redoing old skips
1.376 albertel 6634: if ($scanlines->{'skipped'}[$i]) { return 1; }
1.200 albertel 6635: return 0;
6636: }
6637: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 6638:
6639: if (exists($remembered{$i}) && $remembered{$i} != 2 ) {
6640: return 0;
6641: }
1.200 albertel 6642: return 1;
6643: }
6644:
1.423 albertel 6645: =pod
6646:
6647: =item remember_current_skipped
6648:
1.424 albertel 6649: Discovers what scanlines are in the scantron_skipped_<filename>
6650: file and remembers them into scan_data for later use.
6651:
1.423 albertel 6652: =cut
6653:
1.200 albertel 6654: sub remember_current_skipped {
6655: my ($scanlines,$scan_data)=&scantron_getfile();
6656: my %to_remember;
6657: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
6658: if ($scanlines->{'skipped'}[$i]) {
6659: $to_remember{$i}=1;
6660: }
6661: }
1.376 albertel 6662:
1.200 albertel 6663: &scan_data($scan_data,'remember_skipping',join(':',%to_remember));
6664: &scantron_putfile(undef,$scan_data);
6665: }
6666:
1.423 albertel 6667: =pod
6668:
6669: =item check_for_error
6670:
1.424 albertel 6671: Checks if there was an error when attempting to remove a specific
1.596.2.6 raeburn 6672: scantron_.. bubblesheet data file. Prints out an error if
1.424 albertel 6673: something went wrong.
6674:
1.423 albertel 6675: =cut
6676:
1.200 albertel 6677: sub check_for_error {
6678: my ($r,$result)=@_;
6679: if ($result ne 'ok' && $result ne 'not_found' ) {
1.492 albertel 6680: $r->print(&mt("An error occurred ([_1]) when trying to remove the existing corrections.",$result));
1.200 albertel 6681: }
6682: }
1.157 albertel 6683:
1.423 albertel 6684: =pod
6685:
6686: =item scantron_warning_screen
6687:
1.424 albertel 6688: Interstitial screen to make sure the operator has selected the
6689: correct options before we start the validation phase.
6690:
1.423 albertel 6691: =cut
6692:
1.203 albertel 6693: sub scantron_warning_screen {
6694: my ($button_text)=@_;
1.257 albertel 6695: my $title=&Apache::lonnet::gettitle($env{'form.selectpage'});
1.284 albertel 6696: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.373 albertel 6697: my $CODElist;
1.284 albertel 6698: if ($scantron_config{'CODElocation'} &&
6699: $scantron_config{'CODEstart'} &&
6700: $scantron_config{'CODElength'}) {
6701: $CODElist=$env{'form.scantron_CODElist'};
1.398 albertel 6702: if ($env{'form.scantron_CODElist'} eq '') { $CODElist='<span class="LC_warning">None</span>'; }
1.284 albertel 6703: $CODElist=
1.492 albertel 6704: '<tr><td><b>'.&mt('List of CODES to validate against:').'</b></td><td><tt>'.
1.373 albertel 6705: $env{'form.scantron_CODElist'}.'</tt></td></tr>';
1.284 albertel 6706: }
1.596.2.12.2. (raeburn 6707:): my $lastbubblepoints;
6708:): if ($env{'form.scantron_lastbubblepoints'} ne '') {
6709:): $lastbubblepoints =
6710:): '<tr><td><b>'.&mt('Hand-graded items: points from last bubble in row').'</b></td><td><tt>'.
6711:): $env{'form.scantron_lastbubblepoints'}.'</tt></td></tr>';
6712:): }
1.492 albertel 6713: return ('
1.203 albertel 6714: <p>
1.492 albertel 6715: <span class="LC_warning">
6716: '.&mt('Please double check the information below before clicking on \'[_1]\'',&mt($button_text)).'</span>
1.203 albertel 6717: </p>
6718: <table>
1.492 albertel 6719: <tr><td><b>'.&mt('Sequence to be Graded:').'</b></td><td>'.$title.'</td></tr>
6720: <tr><td><b>'.&mt('Data File that will be used:').'</b></td><td><tt>'.$env{'form.scantron_selectfile'}.'</tt></td></tr>
1.596.2.12.2. (raeburn 6721:): '.$CODElist.$lastbubblepoints.'
1.203 albertel 6722: </table>
6723: <br />
1.596.2.12.2. 2(raebur 6724:2): <p> '.&mt("If this information is correct, please click on '[_1]'.",&mt($button_text)).'</p>
6725:2): <p> '.&mt("If something is incorrect, please click the 'Grading Menu' button to start over.").'</p>
1.203 albertel 6726:
6727: <br />
1.492 albertel 6728: ');
1.203 albertel 6729: }
6730:
1.423 albertel 6731: =pod
6732:
6733: =item scantron_do_warning
6734:
1.424 albertel 6735: Check if the operator has picked something for all required
6736: fields. Error out if something is missing.
6737:
1.423 albertel 6738: =cut
6739:
1.203 albertel 6740: sub scantron_do_warning {
6741: my ($r)=@_;
1.324 albertel 6742: my ($symb)=&get_symb($r);
1.203 albertel 6743: if (!$symb) {return '';}
1.324 albertel 6744: my $default_form_data=&defaultFormData($symb);
1.203 albertel 6745: $r->print(&scantron_form_start().$default_form_data);
1.257 albertel 6746: if ( $env{'form.selectpage'} eq '' ||
6747: $env{'form.scantron_selectfile'} eq '' ||
6748: $env{'form.scantron_format'} eq '' ) {
1.596.2.4 raeburn 6749: $r->print("<p>".&mt('You have forgotten to specify some information. Please go Back and try again.')."</p>");
1.257 albertel 6750: if ( $env{'form.selectpage'} eq '') {
1.492 albertel 6751: $r->print('<p><span class="LC_error">'.&mt('You have not selected a Sequence to grade').'</span></p>');
1.237 albertel 6752: }
1.257 albertel 6753: if ( $env{'form.scantron_selectfile'} eq '') {
1.596.2.4 raeburn 6754: $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 6755: }
1.257 albertel 6756: if ( $env{'form.scantron_format'} eq '') {
1.596.2.5 raeburn 6757: $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 6758: }
6759: } else {
1.265 www 6760: my $warning=&scantron_warning_screen('Grading: Validate Records');
1.596.2.12.2. (raeburn 6761:): my $bubbledbyhand=&hand_bubble_option();
1.492 albertel 6762: $r->print('
1.596.2.12.2. (raeburn 6763:): '.$warning.$bubbledbyhand.'
1.492 albertel 6764: <input type="submit" name="submit" value="'.&mt('Grading: Validate Records').'" />
1.203 albertel 6765: <input type="hidden" name="command" value="scantron_validate" />
1.492 albertel 6766: ');
1.237 albertel 6767: }
1.352 albertel 6768: $r->print("</form><br />".&show_grading_menu_form($symb));
1.203 albertel 6769: return '';
6770: }
6771:
1.423 albertel 6772: =pod
6773:
6774: =item scantron_form_start
6775:
1.424 albertel 6776: html hidden input for remembering all selected grading options
6777:
1.423 albertel 6778: =cut
6779:
1.203 albertel 6780: sub scantron_form_start {
6781: my ($max_bubble)=@_;
6782: my $result= <<SCANTRONFORM;
6783: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
1.257 albertel 6784: <input type="hidden" name="selectpage" value="$env{'form.selectpage'}" />
6785: <input type="hidden" name="scantron_format" value="$env{'form.scantron_format'}" />
6786: <input type="hidden" name="scantron_selectfile" value="$env{'form.scantron_selectfile'}" />
1.218 albertel 6787: <input type="hidden" name="scantron_maxbubble" value="$max_bubble" />
1.257 albertel 6788: <input type="hidden" name="scantron_CODElist" value="$env{'form.scantron_CODElist'}" />
6789: <input type="hidden" name="scantron_CODEunique" value="$env{'form.scantron_CODEunique'}" />
6790: <input type="hidden" name="scantron_options_redo" value="$env{'form.scantron_options_redo'}" />
6791: <input type="hidden" name="scantron_options_ignore" value="$env{'form.scantron_options_ignore'}" />
1.331 albertel 6792: <input type="hidden" name="scantron_options_hidden" value="$env{'form.scantron_options_hidden'}" />
1.203 albertel 6793: SCANTRONFORM
1.447 foxr 6794:
6795: my $line = 0;
6796: while (defined($env{"form.scantron.bubblelines.$line"})) {
6797: my $chunk =
6798: '<input type="hidden" name="scantron.bubblelines.'.$line.'" value="'.$env{"form.scantron.bubblelines.$line"}.'" />'."\n";
1.448 foxr 6799: $chunk .=
6800: '<input type="hidden" name="scantron.first_bubble_line.'.$line.'" value="'.$env{"form.scantron.first_bubble_line.$line"}.'" />'."\n";
1.503 raeburn 6801: $chunk .=
6802: '<input type="hidden" name="scantron.sub_bubblelines.'.$line.'" value="'.$env{"form.scantron.sub_bubblelines.$line"}.'" />'."\n";
1.504 raeburn 6803: $chunk .=
6804: '<input type="hidden" name="scantron.responsetype.'.$line.'" value="'.$env{"form.scantron.responsetype.$line"}.'" />'."\n";
1.596.2.12.2. 6(raebur 6805:3): $chunk .=
6806:3): '<input type="hidden" name="scantron.residpart.'.$line.'" value="'.$env{"form.scantron.residpart.$line"}.'" />'."\n";
1.447 foxr 6807: $result .= $chunk;
6808: $line++;
1.596.2.12.2. 6(raebur 6809:3): }
1.203 albertel 6810: return $result;
6811: }
6812:
1.423 albertel 6813: =pod
6814:
6815: =item scantron_validate_file
6816:
1.596.2.6 raeburn 6817: Dispatch routine for doing validation of a bubblesheet data file.
1.424 albertel 6818:
6819: Also processes any necessary information resets that need to
6820: occur before validation begins (ignore previous corrections,
6821: restarting the skipped records processing)
6822:
1.423 albertel 6823: =cut
6824:
1.157 albertel 6825: sub scantron_validate_file {
6826: my ($r) = @_;
1.324 albertel 6827: my ($symb)=&get_symb($r);
1.157 albertel 6828: if (!$symb) {return '';}
1.324 albertel 6829: my $default_form_data=&defaultFormData($symb);
1.200 albertel 6830:
6831: # do the detection of only doing skipped records first befroe we delete
1.424 albertel 6832: # them when doing the corrections reset
1.257 albertel 6833: if ($env{'form.scantron_options_redo'} ne 'redo_skipped_ready') {
1.200 albertel 6834: &reset_skipping_status();
6835: }
1.257 albertel 6836: if ($env{'form.scantron_options_redo'} eq 'redo_skipped') {
1.200 albertel 6837: &remember_current_skipped();
1.257 albertel 6838: $env{'form.scantron_options_redo'}='redo_skipped_ready';
1.200 albertel 6839: }
6840:
1.257 albertel 6841: if ($env{'form.scantron_options_ignore'} eq 'ignore_corrections') {
1.200 albertel 6842: &check_for_error($r,&scantron_remove_file('corrected'));
6843: &check_for_error($r,&scantron_remove_file('skipped'));
6844: &check_for_error($r,&scantron_remove_scan_data());
1.257 albertel 6845: $env{'form.scantron_options_ignore'}='done';
1.192 albertel 6846: }
1.200 albertel 6847:
1.257 albertel 6848: if ($env{'form.scantron_corrections'}) {
1.157 albertel 6849: &scantron_process_corrections($r);
6850: }
1.503 raeburn 6851: $r->print('<p>'.&mt('Gathering necessary information.').'</p>');$r->rflush();
1.157 albertel 6852: #get the student pick code ready
6853: $r->print(&Apache::loncommon::studentbrowser_javascript());
1.582 raeburn 6854: my $nav_error;
1.596.2.12.2. (raeburn 6855:): my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
6856:): my $max_bubble=&scantron_get_maxbubble(\$nav_error,\%scantron_config);
1.582 raeburn 6857: if ($nav_error) {
6858: $r->print(&navmap_errormsg());
6859: return '';
6860: }
1.203 albertel 6861: my $result=&scantron_form_start($max_bubble).$default_form_data;
1.596.2.12.2. (raeburn 6862:): if ($env{'form.scantron_lastbubblepoints'} ne '') {
6863:): $result .= '<input type="hidden" name="scantron_lastbubblepoints" value="'.$env{'form.scantron_lastbubblepoints'}.'" />';
6864:): }
1.157 albertel 6865: $r->print($result);
6866:
1.334 albertel 6867: my @validate_phases=( 'sequence',
6868: 'ID',
1.157 albertel 6869: 'CODE',
6870: 'doublebubble',
6871: 'missingbubbles');
1.257 albertel 6872: if (!$env{'form.validatepass'}) {
6873: $env{'form.validatepass'} = 0;
1.157 albertel 6874: }
1.257 albertel 6875: my $currentphase=$env{'form.validatepass'};
1.157 albertel 6876:
1.448 foxr 6877:
1.157 albertel 6878: my $stop=0;
6879: while (!$stop && $currentphase < scalar(@validate_phases)) {
1.503 raeburn 6880: $r->print(&mt('Validating '.$validate_phases[$currentphase]).'<br />');
1.157 albertel 6881: $r->rflush();
1.596.2.12.2. 6(raebur 6882:3):
1.157 albertel 6883: my $which="scantron_validate_".$validate_phases[$currentphase];
6884: {
6885: no strict 'refs';
6886: ($stop,$currentphase)=&$which($r,$currentphase);
6887: }
6888: }
6889: if (!$stop) {
1.203 albertel 6890: my $warning=&scantron_warning_screen('Start Grading');
1.542 raeburn 6891: $r->print(&mt('Validation process complete.').'<br />'.
6892: $warning.
6893: &mt('Perform verification for each student after storage of submissions?').
6894: ' <span class="LC_nobreak"><label>'.
6895: '<input type="radio" name="verifyrecord" value="1" />'.&mt('Yes').'</label>'.
6896: (' 'x3).'<label>'.
6897: '<input type="radio" name="verifyrecord" value="0" checked="checked" />'.&mt('No').
6898: '</label></span><br />'.
6899: &mt('Grading will take longer if you use verification.').'<br />'.
1.572 www 6900: &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 6901: '<input type="submit" name="submit" value="'.&mt('Start Grading').'" />'.
6902: '<input type="hidden" name="command" value="scantron_process" />'."\n");
1.157 albertel 6903: } else {
6904: $r->print('<input type="hidden" name="command" value="scantron_validate" />');
6905: $r->print("<input type='hidden' name='validatepass' value='".$currentphase."' />");
6906: }
6907: if ($stop) {
1.334 albertel 6908: if ($validate_phases[$currentphase] eq 'sequence') {
1.539 riegler 6909: $r->print('<input type="submit" name="submit" value="'.&mt('Ignore').' → " />');
1.492 albertel 6910: $r->print(' '.&mt('this error').' <br />');
1.334 albertel 6911:
1.492 albertel 6912: $r->print(" <p>".&mt("Or click the 'Grading Menu' button to start over.")."</p>");
1.334 albertel 6913: } else {
1.503 raeburn 6914: if ($validate_phases[$currentphase] eq 'doublebubble' || $validate_phases[$currentphase] eq 'missingbubbles') {
1.539 riegler 6915: $r->print('<input type="button" name="submitbutton" value="'.&mt('Continue').' →" onclick="javascript:verify_bubble_radio(this.form)" />');
1.503 raeburn 6916: } else {
1.539 riegler 6917: $r->print('<input type="submit" name="submit" value="'.&mt('Continue').' →" />');
1.503 raeburn 6918: }
1.492 albertel 6919: $r->print(' '.&mt('using corrected info').' <br />');
6920: $r->print("<input type='submit' value='".&mt("Skip")."' name='scantron_skip_record' />");
6921: $r->print(" ".&mt("this scanline saving it for later."));
1.334 albertel 6922: }
1.157 albertel 6923: }
1.352 albertel 6924: $r->print(" </form><br />".&show_grading_menu_form($symb));
1.157 albertel 6925: return '';
6926: }
6927:
1.423 albertel 6928:
6929: =pod
6930:
6931: =item scantron_remove_file
6932:
1.596.2.6 raeburn 6933: Removes the requested bubblesheet data file, makes sure that
1.424 albertel 6934: scantron_original_<filename> is never removed
6935:
6936:
1.423 albertel 6937: =cut
6938:
1.200 albertel 6939: sub scantron_remove_file {
1.192 albertel 6940: my ($which)=@_;
1.257 albertel 6941: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6942: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 6943: my $file='scantron_';
1.200 albertel 6944: if ($which eq 'corrected' || $which eq 'skipped') {
6945: $file.=$which.'_';
1.192 albertel 6946: } else {
6947: return 'refused';
6948: }
1.257 albertel 6949: $file.=$env{'form.scantron_selectfile'};
1.200 albertel 6950: return &Apache::lonnet::removeuserfile($cname,$cdom,$file);
6951: }
6952:
1.423 albertel 6953:
6954: =pod
6955:
6956: =item scantron_remove_scan_data
6957:
1.596.2.6 raeburn 6958: Removes all scan_data correction for the requested bubblesheet
1.424 albertel 6959: data file. (In the case that both the are doing skipped records we need
6960: to remember the old skipped lines for the time being so that element
6961: persists for a while.)
6962:
1.423 albertel 6963: =cut
6964:
1.200 albertel 6965: sub scantron_remove_scan_data {
1.257 albertel 6966: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6967: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 6968: my @keys=&Apache::lonnet::getkeys('nohist_scantrondata',$cdom,$cname);
6969: my @todelete;
1.257 albertel 6970: my $filename=$env{'form.scantron_selectfile'};
1.192 albertel 6971: foreach my $key (@keys) {
6972: if ($key=~/^\Q$filename\E_/) {
1.257 albertel 6973: if ($env{'form.scantron_options_redo'} eq 'redo_skipped_ready' &&
1.200 albertel 6974: $key=~/remember_skipping/) {
6975: next;
6976: }
1.192 albertel 6977: push(@todelete,$key);
6978: }
6979: }
1.200 albertel 6980: my $result;
1.192 albertel 6981: if (@todelete) {
1.491 albertel 6982: $result = &Apache::lonnet::del('nohist_scantrondata',
6983: \@todelete,$cdom,$cname);
6984: } else {
6985: $result = 'ok';
1.192 albertel 6986: }
6987: return $result;
6988: }
6989:
1.423 albertel 6990:
6991: =pod
6992:
6993: =item scantron_getfile
6994:
1.596.2.6 raeburn 6995: Fetches the requested bubblesheet data file (all 3 versions), and
1.424 albertel 6996: the scan_data hash
6997:
6998: Arguments:
6999: None
7000:
7001: Returns:
7002: 2 hash references
7003:
7004: - first one has
7005: orig -
7006: corrected -
7007: skipped - each of which points to an array ref of the specified
7008: file broken up into individual lines
7009: count - number of scanlines
7010:
7011: - second is the scan_data hash possible keys are
1.425 albertel 7012: ($number refers to scanline numbered $number and thus the key affects
7013: only that scanline
7014: $bubline refers to the specific bubble line element and the aspects
7015: refers to that specific bubble line element)
7016:
7017: $number.user - username:domain to use
7018: $number.CODE_ignore_dup
7019: - ignore the duplicate CODE error
7020: $number.useCODE
7021: - use the CODE in the scanline as is
7022: $number.no_bubble.$bubline
7023: - it is valid that there is no bubbled in bubble
7024: at $number $bubline
7025: remember_skipping
7026: - a frozen hash containing keys of $number and values
7027: of either
7028: 1 - we are on a 'do skipped records pass' and plan
7029: on processing this line
7030: 2 - we are on a 'do skipped records pass' and this
7031: scanline has been marked to skip yet again
1.424 albertel 7032:
1.423 albertel 7033: =cut
7034:
1.157 albertel 7035: sub scantron_getfile {
1.200 albertel 7036: #FIXME really would prefer a scantron directory
1.257 albertel 7037: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
7038: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.157 albertel 7039: my $lines;
7040: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 7041: 'scantron_orig_'.$env{'form.scantron_selectfile'});
1.157 albertel 7042: my %scanlines;
7043: $scanlines{'orig'}=[(split("\n",$lines,-1))];
7044: my $temp=$scanlines{'orig'};
7045: $scanlines{'count'}=$#$temp;
7046:
7047: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 7048: 'scantron_corrected_'.$env{'form.scantron_selectfile'});
1.157 albertel 7049: if ($lines eq '-1') {
7050: $scanlines{'corrected'}=[];
7051: } else {
7052: $scanlines{'corrected'}=[(split("\n",$lines,-1))];
7053: }
7054: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 7055: 'scantron_skipped_'.$env{'form.scantron_selectfile'});
1.157 albertel 7056: if ($lines eq '-1') {
7057: $scanlines{'skipped'}=[];
7058: } else {
7059: $scanlines{'skipped'}=[(split("\n",$lines,-1))];
7060: }
1.175 albertel 7061: my @tmp=&Apache::lonnet::dump('nohist_scantrondata',$cdom,$cname);
1.157 albertel 7062: if ($tmp[0] =~ /^(error:|no_such_host)/) { @tmp=(); }
7063: my %scan_data = @tmp;
7064: return (\%scanlines,\%scan_data);
7065: }
7066:
1.423 albertel 7067: =pod
7068:
7069: =item lonnet_putfile
7070:
1.424 albertel 7071: Wrapper routine to call &Apache::lonnet::finishuserfileupload
7072:
7073: Arguments:
7074: $contents - data to store
7075: $filename - filename to store $contents into
7076:
7077: Returns:
7078: result value from &Apache::lonnet::finishuserfileupload
7079:
1.423 albertel 7080: =cut
7081:
1.157 albertel 7082: sub lonnet_putfile {
7083: my ($contents,$filename)=@_;
1.257 albertel 7084: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7085: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7086: $env{'form.sillywaytopassafilearound'}=$contents;
1.275 albertel 7087: &Apache::lonnet::finishuserfileupload($docuname,$docudom,'sillywaytopassafilearound',$filename);
1.157 albertel 7088:
7089: }
7090:
1.423 albertel 7091: =pod
7092:
7093: =item scantron_putfile
7094:
1.596.2.6 raeburn 7095: Stores the current version of the bubblesheet data files, and the
1.424 albertel 7096: scan_data hash. (Does not modify the original version only the
7097: corrected and skipped versions.
7098:
7099: Arguments:
7100: $scanlines - hash ref that looks like the first return value from
7101: &scantron_getfile()
7102: $scan_data - hash ref that looks like the second return value from
7103: &scantron_getfile()
7104:
1.423 albertel 7105: =cut
7106:
1.157 albertel 7107: sub scantron_putfile {
7108: my ($scanlines,$scan_data) = @_;
1.200 albertel 7109: #FIXME really would prefer a scantron directory
1.257 albertel 7110: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
7111: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.200 albertel 7112: if ($scanlines) {
7113: my $prefix='scantron_';
1.157 albertel 7114: # no need to update orig, shouldn't change
7115: # &lonnet_putfile(join("\n",@{$scanlines->{'orig'}}),$prefix.'orig_'.
1.257 albertel 7116: # $env{'form.scantron_selectfile'});
1.200 albertel 7117: &lonnet_putfile(join("\n",@{$scanlines->{'corrected'}}),
7118: $prefix.'corrected_'.
1.257 albertel 7119: $env{'form.scantron_selectfile'});
1.200 albertel 7120: &lonnet_putfile(join("\n",@{$scanlines->{'skipped'}}),
7121: $prefix.'skipped_'.
1.257 albertel 7122: $env{'form.scantron_selectfile'});
1.200 albertel 7123: }
1.175 albertel 7124: &Apache::lonnet::put('nohist_scantrondata',$scan_data,$cdom,$cname);
1.157 albertel 7125: }
7126:
1.423 albertel 7127: =pod
7128:
7129: =item scantron_get_line
7130:
1.424 albertel 7131: Returns the correct version of the scanline
7132:
7133: Arguments:
7134: $scanlines - hash ref that looks like the first return value from
7135: &scantron_getfile()
7136: $scan_data - hash ref that looks like the second return value from
7137: &scantron_getfile()
7138: $i - number of the requested line (starts at 0)
7139:
7140: Returns:
7141: A scanline, (either the original or the corrected one if it
7142: exists), or undef if the requested scanline should be
7143: skipped. (Either because it's an skipped scanline, or it's an
7144: unskipped scanline and we are not doing a 'do skipped scanlines'
7145: pass.
7146:
1.423 albertel 7147: =cut
7148:
1.157 albertel 7149: sub scantron_get_line {
1.200 albertel 7150: my ($scanlines,$scan_data,$i)=@_;
1.376 albertel 7151: if (&should_be_skipped($scanlines,$scan_data,$i)) { return undef; }
7152: #if ($scanlines->{'skipped'}[$i]) { return undef; }
1.157 albertel 7153: if ($scanlines->{'corrected'}[$i]) {return $scanlines->{'corrected'}[$i];}
7154: return $scanlines->{'orig'}[$i];
7155: }
7156:
1.423 albertel 7157: =pod
7158:
7159: =item scantron_todo_count
7160:
1.424 albertel 7161: Counts the number of scanlines that need processing.
7162:
7163: Arguments:
7164: $scanlines - hash ref that looks like the first return value from
7165: &scantron_getfile()
7166: $scan_data - hash ref that looks like the second return value from
7167: &scantron_getfile()
7168:
7169: Returns:
7170: $count - number of scanlines to process
7171:
1.423 albertel 7172: =cut
7173:
1.200 albertel 7174: sub get_todo_count {
7175: my ($scanlines,$scan_data)=@_;
7176: my $count=0;
7177: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
7178: my $line=&scantron_get_line($scanlines,$scan_data,$i);
7179: if ($line=~/^[\s\cz]*$/) { next; }
7180: $count++;
7181: }
7182: return $count;
7183: }
7184:
1.423 albertel 7185: =pod
7186:
7187: =item scantron_put_line
7188:
1.596.2.6 raeburn 7189: Updates the 'corrected' or 'skipped' versions of the bubblesheet
1.424 albertel 7190: data file.
7191:
7192: Arguments:
7193: $scanlines - hash ref that looks like the first return value from
7194: &scantron_getfile()
7195: $scan_data - hash ref that looks like the second return value from
7196: &scantron_getfile()
7197: $i - line number to update
7198: $newline - contents of the updated scanline
7199: $skip - if true make the line for skipping and update the
7200: 'skipped' file
7201:
1.423 albertel 7202: =cut
7203:
1.157 albertel 7204: sub scantron_put_line {
1.200 albertel 7205: my ($scanlines,$scan_data,$i,$newline,$skip)=@_;
1.157 albertel 7206: if ($skip) {
7207: $scanlines->{'skipped'}[$i]=$newline;
1.376 albertel 7208: &start_skipping($scan_data,$i);
1.157 albertel 7209: return;
7210: }
7211: $scanlines->{'corrected'}[$i]=$newline;
7212: }
7213:
1.423 albertel 7214: =pod
7215:
7216: =item scantron_clear_skip
7217:
1.424 albertel 7218: Remove a line from the 'skipped' file
7219:
7220: Arguments:
7221: $scanlines - hash ref that looks like the first return value from
7222: &scantron_getfile()
7223: $scan_data - hash ref that looks like the second return value from
7224: &scantron_getfile()
7225: $i - line number to update
7226:
1.423 albertel 7227: =cut
7228:
1.376 albertel 7229: sub scantron_clear_skip {
7230: my ($scanlines,$scan_data,$i)=@_;
7231: if (exists($scanlines->{'skipped'}[$i])) {
7232: undef($scanlines->{'skipped'}[$i]);
7233: return 1;
7234: }
7235: return 0;
7236: }
7237:
1.423 albertel 7238: =pod
7239:
7240: =item scantron_filter_not_exam
7241:
1.424 albertel 7242: Filter routine used by &Apache::lonnavmaps::retrieveResources(), to
7243: filter out resources that are not marked as 'exam' mode
7244:
1.423 albertel 7245: =cut
7246:
1.334 albertel 7247: sub scantron_filter_not_exam {
7248: my ($curres)=@_;
7249:
7250: if (ref($curres) && $curres->is_problem() && !$curres->is_exam()) {
7251: # if the user has asked to not have either hidden
7252: # or 'randomout' controlled resources to be graded
7253: # don't include them
7254: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
7255: && $curres->randomout) {
7256: return 0;
7257: }
7258: return 1;
7259: }
7260: return 0;
7261: }
7262:
1.423 albertel 7263: =pod
7264:
7265: =item scantron_validate_sequence
7266:
1.424 albertel 7267: Validates the selected sequence, checking for resource that are
7268: not set to exam mode.
7269:
1.423 albertel 7270: =cut
7271:
1.334 albertel 7272: sub scantron_validate_sequence {
7273: my ($r,$currentphase) = @_;
7274:
7275: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 7276: unless (ref($navmap)) {
7277: $r->print(&navmap_errormsg());
7278: return (1,$currentphase);
7279: }
1.334 albertel 7280: my (undef,undef,$sequence)=
7281: &Apache::lonnet::decode_symb($env{'form.selectpage'});
7282:
7283: my $map=$navmap->getResourceByUrl($sequence);
7284:
7285: $r->print('<input type="hidden" name="validate_sequence_exam"
7286: value="ignore" />');
7287: if ($env{'form.validate_sequence_exam'} ne 'ignore') {
7288: my @resources=
7289: $navmap->retrieveResources($map,\&scantron_filter_not_exam,1,0);
7290: if (@resources) {
1.596.2.12.2. 0(raebur 7291:2): $r->print('<p class="LC_warning">'
7292:2): .&mt('Some resources in the sequence currently are not set to'
7293:2): .' exam mode. Grading these resources currently may not'
7294:2): .' work correctly.')
7295:2): .'</p>'
7296:2): );
1.334 albertel 7297: return (1,$currentphase);
7298: }
7299: }
7300:
7301: return (0,$currentphase+1);
7302: }
7303:
1.423 albertel 7304:
7305:
1.157 albertel 7306: sub scantron_validate_ID {
7307: my ($r,$currentphase) = @_;
7308:
7309: #get student info
7310: my $classlist=&Apache::loncoursedata::get_classlist();
7311: my %idmap=&username_to_idmap($classlist);
7312:
7313: #get scantron line setup
1.257 albertel 7314: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7315: my ($scanlines,$scan_data)=&scantron_getfile();
1.582 raeburn 7316:
7317: my $nav_error;
1.596.2.12.2. (raeburn 7318:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the bubble_lines.. array.
1.582 raeburn 7319: if ($nav_error) {
7320: $r->print(&navmap_errormsg());
7321: return(1,$currentphase);
7322: }
1.157 albertel 7323:
7324: my %found=('ids'=>{},'usernames'=>{});
7325: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7326: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7327: if ($line=~/^[\s\cz]*$/) { next; }
7328: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7329: $scan_data);
7330: my $id=$$scan_record{'scantron.ID'};
7331: my $found;
7332: foreach my $checkid (keys(%idmap)) {
7333: if (lc($checkid) eq lc($id)) { $found=$checkid;last; }
7334: }
7335: if ($found) {
7336: my $username=$idmap{$found};
7337: if ($found{'ids'}{$found}) {
7338: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
7339: $line,'duplicateID',$found);
1.194 albertel 7340: return(1,$currentphase);
1.157 albertel 7341: } elsif ($found{'usernames'}{$username}) {
7342: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
7343: $line,'duplicateID',$username);
1.194 albertel 7344: return(1,$currentphase);
1.157 albertel 7345: }
1.186 albertel 7346: #FIXME store away line we previously saw the ID on to use above
1.157 albertel 7347: $found{'ids'}{$found}++;
7348: $found{'usernames'}{$username}++;
7349: } else {
7350: if ($id =~ /^\s*$/) {
1.158 albertel 7351: my $username=&scan_data($scan_data,"$i.user");
1.157 albertel 7352: if (defined($username) && $found{'usernames'}{$username}) {
7353: &scantron_get_correction($r,$i,$scan_record,
7354: \%scantron_config,
7355: $line,'duplicateID',$username);
1.194 albertel 7356: return(1,$currentphase);
1.157 albertel 7357: } elsif (!defined($username)) {
7358: &scantron_get_correction($r,$i,$scan_record,
7359: \%scantron_config,
7360: $line,'incorrectID');
1.194 albertel 7361: return(1,$currentphase);
1.157 albertel 7362: }
7363: $found{'usernames'}{$username}++;
7364: } else {
7365: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
7366: $line,'incorrectID');
1.194 albertel 7367: return(1,$currentphase);
1.157 albertel 7368: }
7369: }
7370: }
7371:
7372: return (0,$currentphase+1);
7373: }
7374:
1.423 albertel 7375:
1.157 albertel 7376: sub scantron_get_correction {
1.596.2.12.2. 6(raebur 7377:3): my ($r,$i,$scan_record,$scan_config,$line,$error,$arg,
7378:3): $randomorder,$randompick,$respnumlookup,$startline)=@_;
1.454 banghart 7379: #FIXME in the case of a duplicated ID the previous line, probably need
1.157 albertel 7380: #to show both the current line and the previous one and allow skipping
7381: #the previous one or the current one
7382:
1.333 albertel 7383: if ( $$scan_record{'scantron.PaperID'} =~ /\S/) {
1.596.2.6 raeburn 7384: $r->print(
7385: '<p class="LC_warning">'
7386: .&mt('An error was detected ([_1]) for PaperID [_2]',
7387: "<b>$error</b>",
7388: '<tt>'.$$scan_record{'scantron.PaperID'}.'</tt>')
7389: ."</p> \n");
1.157 albertel 7390: } else {
1.596.2.6 raeburn 7391: $r->print(
7392: '<p class="LC_warning">'
7393: .&mt('An error was detected ([_1]) in scanline [_2] [_3]',
7394: "<b>$error</b>", $i, "<pre>$line</pre>")
7395: ."</p> \n");
7396: }
7397: my $message =
7398: '<p>'
7399: .&mt('The ID on the form is [_1]',
7400: "<tt>$$scan_record{'scantron.ID'}</tt>")
7401: .'<br />'
1.596.2.12 raeburn 7402: .&mt('The name on the paper is [_1], [_2]',
1.596.2.6 raeburn 7403: $$scan_record{'scantron.LastName'},
7404: $$scan_record{'scantron.FirstName'})
7405: .'</p>';
1.242 albertel 7406:
1.157 albertel 7407: $r->print('<input type="hidden" name="scantron_corrections" value="'.$error.'" />'."\n");
7408: $r->print('<input type="hidden" name="scantron_line" value="'.$i.'" />'."\n");
1.503 raeburn 7409: # Array populated for doublebubble or
7410: my @lines_to_correct; # missingbubble errors to build javascript
7411: # to validate radio button checking
7412:
1.157 albertel 7413: if ($error =~ /ID$/) {
1.186 albertel 7414: if ($error eq 'incorrectID') {
1.596.2.6 raeburn 7415: $r->print('<p class="LC_warning">'.&mt("The encoded ID is not in the classlist").
1.492 albertel 7416: "</p>\n");
1.157 albertel 7417: } elsif ($error eq 'duplicateID') {
1.596.2.6 raeburn 7418: $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 7419: }
1.242 albertel 7420: $r->print($message);
1.492 albertel 7421: $r->print("<p>".&mt("How should I handle this?")." <br /> \n");
1.157 albertel 7422: $r->print("\n<ul><li> ");
7423: #FIXME it would be nice if this sent back the user ID and
7424: #could do partial userID matches
7425: $r->print(&Apache::loncommon::selectstudent_link('scantronupload',
7426: 'scantron_username','scantron_domain'));
7427: $r->print(": <input type='text' name='scantron_username' value='' />");
1.596.2.12.2. 3(raebur 7428:3): $r->print("\n:\n".
1.257 albertel 7429: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'scantron_domain'));
1.157 albertel 7430:
7431: $r->print('</li>');
1.186 albertel 7432: } elsif ($error =~ /CODE$/) {
7433: if ($error eq 'incorrectCODE') {
1.596.2.6 raeburn 7434: $r->print('<p class="LC_warning">'.&mt("The encoded CODE is not in the list of possible CODEs.")."</p>\n");
1.186 albertel 7435: } elsif ($error eq 'duplicateCODE') {
1.596.2.6 raeburn 7436: $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 7437: }
1.596.2.6 raeburn 7438: $r->print("<p>".&mt('The CODE on the form is [_1]',
7439: "<tt>'$$scan_record{'scantron.CODE'}'</tt>")
7440: ."</p>\n");
1.242 albertel 7441: $r->print($message);
1.596.2.6 raeburn 7442: $r->print("<p>".&mt("How should I handle this?")."</p>\n");
1.187 albertel 7443: $r->print("\n<br /> ");
1.194 albertel 7444: my $i=0;
1.273 albertel 7445: if ($error eq 'incorrectCODE'
7446: && $$scan_record{'scantron.CODE'}=~/\S/ ) {
1.194 albertel 7447: my ($max,$closest)=&scantron_get_closely_matching_CODEs($arg,$$scan_record{'scantron.CODE'});
1.278 albertel 7448: if ($closest > 0) {
7449: foreach my $testcode (@{$closest}) {
7450: my $checked='';
1.569 bisitz 7451: if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 7452: $r->print("
7453: <label>
1.569 bisitz 7454: <input type='radio' name='scantron_CODE_resolution' value='use_closest_$i'$checked />
1.492 albertel 7455: ".&mt("Use the similar CODE [_1] instead.",
7456: "<b><tt>".$testcode."</tt></b>")."
7457: </label>
7458: <input type='hidden' name='scantron_CODE_closest_$i' value='$testcode' />");
1.278 albertel 7459: $r->print("\n<br />");
7460: $i++;
7461: }
1.194 albertel 7462: }
7463: }
1.273 albertel 7464: if ($$scan_record{'scantron.CODE'}=~/\S/ ) {
1.569 bisitz 7465: my $checked; if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 7466: $r->print("
7467: <label>
1.569 bisitz 7468: <input type='radio' name='scantron_CODE_resolution' value='use_unfound'$checked />
1.596.2.6 raeburn 7469: ".&mt("Use the CODE [_1] that was on the paper, ignoring the error.",
1.492 albertel 7470: "<b><tt>".$$scan_record{'scantron.CODE'}."</tt></b>")."
7471: </label>");
1.273 albertel 7472: $r->print("\n<br />");
7473: }
1.194 albertel 7474:
1.188 albertel 7475: $r->print(<<ENDSCRIPT);
7476: <script type="text/javascript">
7477: function change_radio(field) {
1.190 albertel 7478: var slct=document.scantronupload.scantron_CODE_resolution;
1.188 albertel 7479: var i;
7480: for (i=0;i<slct.length;i++) {
7481: if (slct[i].value==field) { slct[i].checked=true; }
7482: }
7483: }
7484: </script>
7485: ENDSCRIPT
1.187 albertel 7486: my $href="/adm/pickcode?".
1.359 www 7487: "form=".&escape("scantronupload").
7488: "&scantron_format=".&escape($env{'form.scantron_format'}).
7489: "&scantron_CODElist=".&escape($env{'form.scantron_CODElist'}).
7490: "&curCODE=".&escape($$scan_record{'scantron.CODE'}).
7491: "&scantron_selectfile=".&escape($env{'form.scantron_selectfile'});
1.332 albertel 7492: if ($env{'form.scantron_CODElist'} =~ /\S/) {
1.492 albertel 7493: $r->print("
7494: <label>
7495: <input type='radio' name='scantron_CODE_resolution' value='use_found' />
7496: ".&mt("[_1]Select[_2] a CODE from the list of all CODEs and use it.",
7497: "<a target='_blank' href='$href'>","</a>")."
7498: </label>
1.558 bisitz 7499: ".&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 7500: $r->print("\n<br />");
7501: }
1.492 albertel 7502: $r->print("
7503: <label>
7504: <input type='radio' name='scantron_CODE_resolution' value='use_typed' />
7505: ".&mt("Use [_1] as the CODE.",
7506: "</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 7507: $r->print("\n<br /><br />");
1.157 albertel 7508: } elsif ($error eq 'doublebubble') {
1.596.2.6 raeburn 7509: $r->print('<p class="LC_warning">'.&mt("There have been multiple bubbles scanned for some question(s)")."</p>\n");
1.497 foxr 7510:
7511: # The form field scantron_questions is acutally a list of line numbers.
7512: # represented by this form so:
7513:
1.596.2.12.2. 6(raebur 7514:3): my $line_list = &questions_to_line_list($arg,$randomorder,$randompick,
7515:3): $respnumlookup,$startline);
1.497 foxr 7516:
1.157 albertel 7517: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 7518: $line_list.'" />');
1.242 albertel 7519: $r->print($message);
1.492 albertel 7520: $r->print("<p>".&mt("Please indicate which bubble should be used for grading")."</p>");
1.157 albertel 7521: foreach my $question (@{$arg}) {
1.503 raeburn 7522: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
1.596.2.12.2. 6(raebur 7523:3): $scan_record, $error,
7524:3): $randomorder,$randompick,
7525:3): $respnumlookup,$startline);
1.524 raeburn 7526: push(@lines_to_correct,@linenums);
1.157 albertel 7527: }
1.503 raeburn 7528: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 7529: } elsif ($error eq 'missingbubble') {
1.596.2.9 raeburn 7530: $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 7531: $r->print($message);
1.492 albertel 7532: $r->print("<p>".&mt("Please indicate which bubble should be used for grading.")."</p>");
1.503 raeburn 7533: $r->print(&mt("Some questions have no scanned bubbles.")."\n");
1.497 foxr 7534:
1.503 raeburn 7535: # The form field scantron_questions is actually a list of line numbers not
1.497 foxr 7536: # a list of question numbers. Therefore:
7537: #
7538:
1.596.2.12.2. 6(raebur 7539:3): my $line_list = &questions_to_line_list($arg,$randomorder,$randompick,
7540:3): $respnumlookup,$startline);
1.497 foxr 7541:
1.157 albertel 7542: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 7543: $line_list.'" />');
1.157 albertel 7544: foreach my $question (@{$arg}) {
1.503 raeburn 7545: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
1.596.2.12.2. 6(raebur 7546:3): $scan_record, $error,
7547:3): $randomorder,$randompick,
7548:3): $respnumlookup,$startline);
1.524 raeburn 7549: push(@lines_to_correct,@linenums);
1.157 albertel 7550: }
1.503 raeburn 7551: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 7552: } else {
7553: $r->print("\n<ul>");
7554: }
7555: $r->print("\n</li></ul>");
1.497 foxr 7556: }
7557:
1.503 raeburn 7558: sub verify_bubbles_checked {
7559: my (@ansnums) = @_;
7560: my $ansnumstr = join('","',@ansnums);
7561: my $warning = &mt("A bubble or 'No bubble' selection has not been made for one or more lines.");
7562: my $output = (<<ENDSCRIPT);
7563: <script type="text/javascript">
7564: function verify_bubble_radio(form) {
7565: var ansnumArray = new Array ("$ansnumstr");
7566: var need_bubble_count = 0;
7567: for (var i=0; i<ansnumArray.length; i++) {
7568: if (form.elements["scantron_correct_Q_"+ansnumArray[i]].length > 1) {
7569: var bubble_picked = 0;
7570: for (var j=0; j<form.elements["scantron_correct_Q_"+ansnumArray[i]].length; j++) {
7571: if (form.elements["scantron_correct_Q_"+ansnumArray[i]][j].checked == true) {
7572: bubble_picked = 1;
7573: }
7574: }
7575: if (bubble_picked == 0) {
7576: need_bubble_count ++;
7577: }
7578: }
7579: }
7580: if (need_bubble_count) {
7581: alert("$warning");
7582: return;
7583: }
7584: form.submit();
7585: }
7586: </script>
7587: ENDSCRIPT
7588: return $output;
7589: }
7590:
1.497 foxr 7591: =pod
7592:
7593: =item questions_to_line_list
1.157 albertel 7594:
1.497 foxr 7595: Converts a list of questions into a string of comma separated
7596: line numbers in the answer sheet used by the questions. This is
7597: used to fill in the scantron_questions form field.
7598:
7599: Arguments:
7600: questions - Reference to an array of questions.
1.596.2.12.2. 6(raebur 7601:3): randomorder - True if randomorder in use.
7602:3): randompick - True if randompick in use.
7603:3): respnumlookup - Reference to HASH mapping question numbers in bubble lines
7604:3): for current line to question number used for same question
7605:3): in "Master Seqence" (as seen by Course Coordinator).
7606:3): startline - Reference to hash where key is question number (0 is first)
7607:3): and key is number of first bubble line for current student
7608:3): or code-based randompick and/or randomorder.
1.497 foxr 7609:
7610: =cut
7611:
7612:
7613: sub questions_to_line_list {
1.596.2.12.2. 6(raebur 7614:3): my ($questions,$randomorder,$randompick,$respnumlookup,$startline) = @_;
1.497 foxr 7615: my @lines;
7616:
1.503 raeburn 7617: foreach my $item (@{$questions}) {
7618: my $question = $item;
7619: my ($first,$count,$last);
7620: if ($item =~ /^(\d+)\.(\d+)$/) {
7621: $question = $1;
7622: my $subquestion = $2;
1.596.2.12.2. 6(raebur 7623:3): my $responsenum = $question-1;
7624:3): if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
7625:3): $responsenum = $respnumlookup->{$question-1};
7626:3): if (ref($startline) eq 'HASH') {
7627:3): $first = $startline->{$question-1} + 1;
7628:3): }
7629:3): } else {
7630:3): $first = $first_bubble_line{$responsenum} + 1;
7631:3): }
7(raebur 7632:3): my @subans = split(/,/,$subdivided_bubble_lines{$responsenum});
1.503 raeburn 7633: my $subcount = 1;
7634: while ($subcount<$subquestion) {
7635: $first += $subans[$subcount-1];
7636: $subcount ++;
7637: }
7638: $count = $subans[$subquestion-1];
7639: } else {
1.596.2.12.2. 7(raebur 7640:3): my $responsenum = $question-1;
7641:3): if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
7642:3): $responsenum = $respnumlookup->{$question-1};
7643:3): if (ref($startline) eq 'HASH') {
7644:3): $first = $startline->{$question-1} + 1;
7645:3): }
7646:3): } else {
7647:3): $first = $first_bubble_line{$responsenum} + 1;
7648:3): }
7649:3): $count = $bubble_lines_per_response{$responsenum};
1.503 raeburn 7650: }
1.506 raeburn 7651: $last = $first+$count-1;
1.503 raeburn 7652: push(@lines, ($first..$last));
1.497 foxr 7653: }
7654: return join(',', @lines);
7655: }
7656:
7657: =pod
7658:
7659: =item prompt_for_corrections
7660:
7661: Prompts for a potentially multiline correction to the
7662: user's bubbling (factors out common code from scantron_get_correction
7663: for multi and missing bubble cases).
7664:
7665: Arguments:
7666: $r - Apache request object.
7667: $question - The question number to prompt for.
7668: $scan_config - The scantron file configuration hash.
7669: $scan_record - Reference to the hash that has the the parsed scanlines.
1.503 raeburn 7670: $error - Type of error
1.596.2.12.2. 7(raebur 7671:3): $randomorder - True if randomorder in use.
7672:3): $randompick - True if randompick in use.
7673:3): $respnumlookup - Reference to HASH mapping question numbers in bubble lines
7674:3): for current line to question number used for same question
7675:3): in "Master Seqence" (as seen by Course Coordinator).
7676:3): $startline - Reference to hash where key is question number (0 is first)
7677:3): and value is number of first bubble line for current student
7678:3): or code-based randompick and/or randomorder.
1.497 foxr 7679:
7680: Implicit inputs:
7681: %bubble_lines_per_response - Starting line numbers for each question.
7682: Numbered from 0 (but question numbers are from
7683: 1.
7684: %first_bubble_line - Starting bubble line for each question.
1.509 raeburn 7685: %subdivided_bubble_lines - optionresponse, matchresponse and rankresponse
7686: type problems render as separate sub-questions,
1.503 raeburn 7687: in exam mode. This hash contains a
7688: comma-separated list of the lines per
7689: sub-question.
1.510 raeburn 7690: %responsetype_per_response - essayresponse, formularesponse,
7691: stringresponse, imageresponse, reactionresponse,
7692: and organicresponse type problem parts can have
1.503 raeburn 7693: multiple lines per response if the weight
7694: assigned exceeds 10. In this case, only
7695: one bubble per line is permitted, but more
7696: than one line might contain bubbles, e.g.
7697: bubbling of: line 1 - J, line 2 - J,
7698: line 3 - B would assign 22 points.
1.497 foxr 7699:
7700: =cut
7701:
7702: sub prompt_for_corrections {
1.596.2.12.2. 6(raebur 7703:3): my ($r, $question, $scan_config, $scan_record, $error, $randomorder,
7704:3): $randompick, $respnumlookup, $startline) = @_;
1.503 raeburn 7705: my ($current_line,$lines);
7706: my @linenums;
7707: my $questionnum = $question;
1.596.2.12.2. 6(raebur 7708:3): my ($first,$responsenum);
1.503 raeburn 7709: if ($question =~ /^(\d+)\.(\d+)$/) {
7710: $question = $1;
7711: my $subquestion = $2;
1.596.2.12.2. 6(raebur 7712:3): if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
7713:3): $responsenum = $respnumlookup->{$question-1};
7714:3): if (ref($startline) eq 'HASH') {
7715:3): $first = $startline->{$question-1};
7716:3): }
7717:3): } else {
7718:3): $responsenum = $question-1;
7719:3): $first = $first_bubble_line{$responsenum} + 1;
7720:3): }
7721:3): $current_line = $first + 1 ;
7722:3): my @subans = split(/,/,$subdivided_bubble_lines{$responsenum});
1.503 raeburn 7723: my $subcount = 1;
7724: while ($subcount<$subquestion) {
7725: $current_line += $subans[$subcount-1];
7726: $subcount ++;
7727: }
7728: $lines = $subans[$subquestion-1];
7729: } else {
1.596.2.12.2. 6(raebur 7730:3): if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
7731:3): $responsenum = $respnumlookup->{$question-1};
7732:3): if (ref($startline) eq 'HASH') {
7733:3): $first = $startline->{$question-1};
7734:3): }
7735:3): } else {
7736:3): $responsenum = $question-1;
7737:3): $first = $first_bubble_line{$responsenum};
7738:3): }
7739:3): $current_line = $first + 1;
7740:3): $lines = $bubble_lines_per_response{$responsenum};
1.503 raeburn 7741: }
1.497 foxr 7742: if ($lines > 1) {
1.503 raeburn 7743: $r->print(&mt('The group of bubble lines below responds to a single question.').'<br />');
1.596.2.12.2. 6(raebur 7744:3): if (($responsetype_per_response{$responsenum} eq 'essayresponse') ||
7745:3): ($responsetype_per_response{$responsenum} eq 'formularesponse') ||
7746:3): ($responsetype_per_response{$responsenum} eq 'stringresponse') ||
7747:3): ($responsetype_per_response{$responsenum} eq 'imageresponse') ||
7748:3): ($responsetype_per_response{$responsenum} eq 'reactionresponse') ||
7749:3): ($responsetype_per_response{$responsenum} eq 'organicresponse')) {
4(raebur 7750:3): $r->print(&mt("Although this particular question type requires handgrading, the instructions for this question in the bubblesheet 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 7751: } else {
7752: $r->print(&mt("Select at most one bubble in a single line and select 'No Bubble' in all the other lines. ")."<br />");
7753: }
1.497 foxr 7754: }
7755: for (my $i =0; $i < $lines; $i++) {
1.503 raeburn 7756: my $selected = $$scan_record{"scantron.$current_line.answer"};
1.596.2.12.2. 6(raebur 7757:3): &scantron_bubble_selector($r,$scan_config,$current_line,
1.503 raeburn 7758: $questionnum,$error,split('', $selected));
1.524 raeburn 7759: push(@linenums,$current_line);
1.497 foxr 7760: $current_line++;
7761: }
7762: if ($lines > 1) {
7763: $r->print("<hr /><br />");
7764: }
1.503 raeburn 7765: return @linenums;
1.157 albertel 7766: }
1.423 albertel 7767:
7768: =pod
7769:
7770: =item scantron_bubble_selector
7771:
7772: Generates the html radiobuttons to correct a single bubble line
1.424 albertel 7773: possibly showing the existing the selected bubbles if known
1.423 albertel 7774:
7775: Arguments:
7776: $r - Apache request object
7777: $scan_config - hash from &get_scantron_config()
1.497 foxr 7778: $line - Number of the line being displayed.
1.503 raeburn 7779: $questionnum - Question number (may include subquestion)
7780: $error - Type of error.
1.497 foxr 7781: @selected - Array of bubbles picked on this line.
1.423 albertel 7782:
7783: =cut
7784:
1.157 albertel 7785: sub scantron_bubble_selector {
1.503 raeburn 7786: my ($r,$scan_config,$line,$questionnum,$error,@selected)=@_;
1.157 albertel 7787: my $max=$$scan_config{'Qlength'};
1.274 albertel 7788:
7789: my $scmode=$$scan_config{'Qon'};
1.596.2.12.2. (raeburn 7790:): if ($scmode eq 'number' || $scmode eq 'letter') {
7791:): if (($$scan_config{'BubblesPerRow'} =~ /^\d+$/) &&
7792:): ($$scan_config{'BubblesPerRow'} > 0)) {
7793:): $max=$$scan_config{'BubblesPerRow'};
7794:): if (($scmode eq 'number') && ($max > 10)) {
7795:): $max = 10;
7796:): } elsif (($scmode eq 'letter') && $max > 26) {
7797:): $max = 26;
7798:): }
7799:): } else {
7800:): $max = 10;
7801:): }
7802:): }
1.274 albertel 7803:
1.157 albertel 7804: my @alphabet=('A'..'Z');
1.503 raeburn 7805: $r->print(&Apache::loncommon::start_data_table().
7806: &Apache::loncommon::start_data_table_row());
7807: $r->print('<td rowspan="2" class="LC_leftcol_header">'.$line.'</td>');
1.497 foxr 7808: for (my $i=0;$i<$max+1;$i++) {
7809: $r->print("\n".'<td align="center">');
7810: if ($selected[0] eq $alphabet[$i]) { $r->print('X'); shift(@selected) }
7811: else { $r->print(' '); }
7812: $r->print('</td>');
7813: }
1.503 raeburn 7814: $r->print(&Apache::loncommon::end_data_table_row().
7815: &Apache::loncommon::start_data_table_row());
1.497 foxr 7816: for (my $i=0;$i<$max;$i++) {
7817: $r->print("\n".
7818: '<td><label><input type="radio" name="scantron_correct_Q_'.
7819: $line.'" value="'.$i.'" />'.$alphabet[$i]."</label></td>");
7820: }
1.503 raeburn 7821: my $nobub_checked = ' ';
7822: if ($error eq 'missingbubble') {
7823: $nobub_checked = ' checked = "checked" ';
7824: }
7825: $r->print("\n".'<td><label><input type="radio" name="scantron_correct_Q_'.
7826: $line.'" value="none"'.$nobub_checked.'/>'.&mt('No bubble').
7827: '</label>'."\n".'<input type="hidden" name="scantron_questionnum_Q_'.
7828: $line.'" value="'.$questionnum.'" /></td>');
7829: $r->print(&Apache::loncommon::end_data_table_row().
7830: &Apache::loncommon::end_data_table());
1.157 albertel 7831: }
7832:
1.423 albertel 7833: =pod
7834:
7835: =item num_matches
7836:
1.424 albertel 7837: Counts the number of characters that are the same between the two arguments.
7838:
7839: Arguments:
7840: $orig - CODE from the scanline
7841: $code - CODE to match against
7842:
7843: Returns:
7844: $count - integer count of the number of same characters between the
7845: two arguments
7846:
1.423 albertel 7847: =cut
7848:
1.194 albertel 7849: sub num_matches {
7850: my ($orig,$code) = @_;
7851: my @code=split(//,$code);
7852: my @orig=split(//,$orig);
7853: my $same=0;
7854: for (my $i=0;$i<scalar(@code);$i++) {
7855: if ($code[$i] eq $orig[$i]) { $same++; }
7856: }
7857: return $same;
7858: }
7859:
1.423 albertel 7860: =pod
7861:
7862: =item scantron_get_closely_matching_CODEs
7863:
1.424 albertel 7864: Cycles through all CODEs and finds the set that has the greatest
7865: number of same characters as the provided CODE
7866:
7867: Arguments:
7868: $allcodes - hash ref returned by &get_codes()
7869: $CODE - CODE from the current scanline
7870:
7871: Returns:
7872: 2 element list
7873: - first elements is number of how closely matching the best fit is
7874: (5 means best set has 5 matching characters)
7875: - second element is an arrary ref containing the set of valid CODEs
7876: that best fit the passed in CODE
7877:
1.423 albertel 7878: =cut
7879:
1.194 albertel 7880: sub scantron_get_closely_matching_CODEs {
7881: my ($allcodes,$CODE)=@_;
7882: my @CODEs;
7883: foreach my $testcode (sort(keys(%{$allcodes}))) {
7884: push(@{$CODEs[&num_matches($CODE,$testcode)]},$testcode);
7885: }
7886:
7887: return ($#CODEs,$CODEs[-1]);
7888: }
7889:
1.423 albertel 7890: =pod
7891:
7892: =item get_codes
7893:
1.424 albertel 7894: Builds a hash which has keys of all of the valid CODEs from the selected
7895: set of remembered CODEs.
7896:
7897: Arguments:
7898: $old_name - name of the set of remembered CODEs
7899: $cdom - domain of the course
7900: $cnum - internal course name
7901:
7902: Returns:
7903: %allcodes - keys are the valid CODEs, values are all 1
7904:
1.423 albertel 7905: =cut
7906:
1.194 albertel 7907: sub get_codes {
1.280 foxr 7908: my ($old_name, $cdom, $cnum) = @_;
7909: if (!$old_name) {
7910: $old_name=$env{'form.scantron_CODElist'};
7911: }
7912: if (!$cdom) {
7913: $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
7914: }
7915: if (!$cnum) {
7916: $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
7917: }
1.278 albertel 7918: my %result=&Apache::lonnet::get('CODEs',[$old_name,"type\0$old_name"],
7919: $cdom,$cnum);
7920: my %allcodes;
7921: if ($result{"type\0$old_name"} eq 'number') {
7922: %allcodes=map {($_,1)} split(',',$result{$old_name});
7923: } else {
7924: %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
7925: }
1.194 albertel 7926: return %allcodes;
7927: }
7928:
1.423 albertel 7929: =pod
7930:
7931: =item scantron_validate_CODE
7932:
1.424 albertel 7933: Validates all scanlines in the selected file to not have any
7934: invalid or underspecified CODEs and that none of the codes are
7935: duplicated if this was requested.
7936:
1.423 albertel 7937: =cut
7938:
1.157 albertel 7939: sub scantron_validate_CODE {
7940: my ($r,$currentphase) = @_;
1.257 albertel 7941: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.186 albertel 7942: if ($scantron_config{'CODElocation'} &&
7943: $scantron_config{'CODEstart'} &&
7944: $scantron_config{'CODElength'}) {
1.257 albertel 7945: if (!defined($env{'form.scantron_CODElist'})) {
1.186 albertel 7946: &FIXME_blow_up()
7947: }
7948: } else {
7949: return (0,$currentphase+1);
7950: }
7951:
7952: my %usedCODEs;
7953:
1.194 albertel 7954: my %allcodes=&get_codes();
1.186 albertel 7955:
1.582 raeburn 7956: my $nav_error;
1.596.2.12.2. (raeburn 7957:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the lines per response array.
1.582 raeburn 7958: if ($nav_error) {
7959: $r->print(&navmap_errormsg());
7960: return(1,$currentphase);
7961: }
1.447 foxr 7962:
1.186 albertel 7963: my ($scanlines,$scan_data)=&scantron_getfile();
7964: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7965: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.186 albertel 7966: if ($line=~/^[\s\cz]*$/) { next; }
7967: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7968: $scan_data);
7969: my $CODE=$$scan_record{'scantron.CODE'};
7970: my $error=0;
1.224 albertel 7971: if (!&Apache::lonnet::validCODE($CODE)) {
7972: &scantron_get_correction($r,$i,$scan_record,
7973: \%scantron_config,
7974: $line,'incorrectCODE',\%allcodes);
7975: return(1,$currentphase);
7976: }
1.221 albertel 7977: if (%allcodes && !exists($allcodes{$CODE})
7978: && !$$scan_record{'scantron.useCODE'}) {
1.186 albertel 7979: &scantron_get_correction($r,$i,$scan_record,
7980: \%scantron_config,
1.194 albertel 7981: $line,'incorrectCODE',\%allcodes);
7982: return(1,$currentphase);
1.186 albertel 7983: }
1.214 albertel 7984: if (exists($usedCODEs{$CODE})
1.257 albertel 7985: && $env{'form.scantron_CODEunique'} eq 'yes'
1.192 albertel 7986: && !$$scan_record{'scantron.CODE_ignore_dup'}) {
1.186 albertel 7987: &scantron_get_correction($r,$i,$scan_record,
7988: \%scantron_config,
1.194 albertel 7989: $line,'duplicateCODE',$usedCODEs{$CODE});
7990: return(1,$currentphase);
1.186 albertel 7991: }
1.524 raeburn 7992: push(@{$usedCODEs{$CODE}},$$scan_record{'scantron.PaperID'});
1.186 albertel 7993: }
1.157 albertel 7994: return (0,$currentphase+1);
7995: }
7996:
1.423 albertel 7997: =pod
7998:
7999: =item scantron_validate_doublebubble
8000:
1.424 albertel 8001: Validates all scanlines in the selected file to not have any
8002: bubble lines with multiple bubbles marked.
8003:
1.423 albertel 8004: =cut
8005:
1.157 albertel 8006: sub scantron_validate_doublebubble {
8007: my ($r,$currentphase) = @_;
8008: #get student info
8009: my $classlist=&Apache::loncoursedata::get_classlist();
8010: my %idmap=&username_to_idmap($classlist);
1.596.2.12.2. 6(raebur 8011:3): my (undef,undef,$sequence)=
8012:3): &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.157 albertel 8013:
8014: #get scantron line setup
1.257 albertel 8015: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 8016: my ($scanlines,$scan_data)=&scantron_getfile();
1.596.2.12.2. 6(raebur 8017:3):
8018:3): my $navmap = Apache::lonnavmaps::navmap->new();
8019:3): unless (ref($navmap)) {
8020:3): $r->print(&navmap_errormsg());
8021:3): return(1,$currentphase);
8022:3): }
8023:3): my $map=$navmap->getResourceByUrl($sequence);
8024:3): my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
8025:3): my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
8026:3): %grader_randomlists_by_symb,%orderedforcode,%respnumlookup,%startline);
8027:3): my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
8028:3):
1.583 raeburn 8029: my $nav_error;
1.596.2.12.2. 6(raebur 8030:3): if (ref($map)) {
8031:3): $randomorder = $map->randomorder();
8032:3): $randompick = $map->randompick();
8033:3): if ($randomorder || $randompick) {
8034:3): $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource);
8035:3): if ($nav_error) {
8036:3): $r->print(&navmap_errormsg());
8037:3): return(1,$currentphase);
8038:3): }
8039:3): &graders_resources_pass(\@resources,\%grader_partids_by_symb,
8040:3): \%grader_randomlists_by_symb,$bubbles_per_row);
8041:3): }
8042:3): } else {
8043:3): $r->print(&navmap_errormsg());
8044:3): return(1,$currentphase);
8045:3): }
8046:3):
(raeburn 8047:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the bubble line array.
1.583 raeburn 8048: if ($nav_error) {
8049: $r->print(&navmap_errormsg());
8050: return(1,$currentphase);
8051: }
1.447 foxr 8052:
1.157 albertel 8053: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 8054: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 8055: if ($line=~/^[\s\cz]*$/) { next; }
8056: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
1.596.2.12.2. 6(raebur 8057:3): $scan_data,undef,\%idmap,$randomorder,
8058:3): $randompick,$sequence,\@master_seq,
8059:3): \%symb_to_resource,\%grader_partids_by_symb,
8060:3): \%orderedforcode,\%respnumlookup,\%startline);
1.157 albertel 8061: if (!defined($$scan_record{'scantron.doubleerror'})) { next; }
8062: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,$line,
8063: 'doublebubble',
1.596.2.12.2. 6(raebur 8064:3): $$scan_record{'scantron.doubleerror'},
8065:3): $randomorder,$randompick,\%respnumlookup,\%startline);
1.157 albertel 8066: return (1,$currentphase);
8067: }
8068: return (0,$currentphase+1);
8069: }
8070:
1.423 albertel 8071:
1.503 raeburn 8072: sub scantron_get_maxbubble {
1.596.2.12.2. (raeburn 8073:): my ($nav_error,$scantron_config) = @_;
1.257 albertel 8074: if (defined($env{'form.scantron_maxbubble'}) &&
8075: $env{'form.scantron_maxbubble'}) {
1.447 foxr 8076: &restore_bubble_lines();
1.257 albertel 8077: return $env{'form.scantron_maxbubble'};
1.191 albertel 8078: }
1.330 albertel 8079:
1.447 foxr 8080: my (undef, undef, $sequence) =
1.257 albertel 8081: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.330 albertel 8082:
1.447 foxr 8083: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 8084: unless (ref($navmap)) {
8085: if (ref($nav_error)) {
8086: $$nav_error = 1;
8087: }
1.591 raeburn 8088: return;
1.582 raeburn 8089: }
1.191 albertel 8090: my $map=$navmap->getResourceByUrl($sequence);
8091: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.596.2.12.2. (raeburn 8092:): my $bubbles_per_row = &bubblesheet_bubbles_per_row($scantron_config);
1.330 albertel 8093:
8094: &Apache::lonxml::clear_problem_counter();
8095:
1.557 raeburn 8096: my $uname = $env{'user.name'};
8097: my $udom = $env{'user.domain'};
1.435 foxr 8098: my $cid = $env{'request.course.id'};
8099: my $total_lines = 0;
8100: %bubble_lines_per_response = ();
1.447 foxr 8101: %first_bubble_line = ();
1.503 raeburn 8102: %subdivided_bubble_lines = ();
8103: %responsetype_per_response = ();
1.596.2.12.2. 6(raebur 8104:3): %masterseq_id_responsenum = ();
1.554 raeburn 8105:
1.447 foxr 8106: my $response_number = 0;
8107: my $bubble_line = 0;
1.191 albertel 8108: foreach my $resource (@resources) {
1.596.2.12.2. 6(raebur 8109:3): my $resid = $resource->id();
(raeburn 8110:): my ($analysis,$parts) = &scantron_partids_tograde($resource,$cid,$uname,
7(raebur 8111:3): $udom,undef,$bubbles_per_row);
1.542 raeburn 8112: if ((ref($analysis) eq 'HASH') && (ref($parts) eq 'ARRAY')) {
8113: foreach my $part_id (@{$parts}) {
8114: my $lines;
8115:
8116: # TODO - make this a persistent hash not an array.
8117:
8118: # optionresponse, matchresponse and rankresponse type items
8119: # render as separate sub-questions in exam mode.
8120: if (($analysis->{$part_id.'.type'} eq 'optionresponse') ||
8121: ($analysis->{$part_id.'.type'} eq 'matchresponse') ||
8122: ($analysis->{$part_id.'.type'} eq 'rankresponse')) {
8123: my ($numbub,$numshown);
8124: if ($analysis->{$part_id.'.type'} eq 'optionresponse') {
8125: if (ref($analysis->{$part_id.'.options'}) eq 'ARRAY') {
8126: $numbub = scalar(@{$analysis->{$part_id.'.options'}});
8127: }
8128: } elsif ($analysis->{$part_id.'.type'} eq 'matchresponse') {
8129: if (ref($analysis->{$part_id.'.items'}) eq 'ARRAY') {
8130: $numbub = scalar(@{$analysis->{$part_id.'.items'}});
8131: }
8132: } elsif ($analysis->{$part_id.'.type'} eq 'rankresponse') {
8133: if (ref($analysis->{$part_id.'.foils'}) eq 'ARRAY') {
8134: $numbub = scalar(@{$analysis->{$part_id.'.foils'}});
8135: }
8136: }
8137: if (ref($analysis->{$part_id.'.shown'}) eq 'ARRAY') {
8138: $numshown = scalar(@{$analysis->{$part_id.'.shown'}});
8139: }
1.596.2.12.2. (raeburn 8140:): my $bubbles_per_row =
8141:): &bubblesheet_bubbles_per_row($scantron_config);
8142:): my $inner_bubble_lines = int($numbub/$bubbles_per_row);
8143:): if (($numbub % $bubbles_per_row) != 0) {
1.542 raeburn 8144: $inner_bubble_lines++;
8145: }
8146: for (my $i=0; $i<$numshown; $i++) {
8147: $subdivided_bubble_lines{$response_number} .=
8148: $inner_bubble_lines.',';
8149: }
8150: $subdivided_bubble_lines{$response_number} =~ s/,$//;
8151: $lines = $numshown * $inner_bubble_lines;
8152: } else {
8153: $lines = $analysis->{"$part_id.bubble_lines"};
1.596.2.12.2. (raeburn 8154:): }
1.542 raeburn 8155:
8156: $first_bubble_line{$response_number} = $bubble_line;
8157: $bubble_lines_per_response{$response_number} = $lines;
8158: $responsetype_per_response{$response_number} =
8159: $analysis->{$part_id.'.type'};
1.596.2.12.2. 6(raebur 8160:3): $masterseq_id_responsenum{$resid.'_'.$part_id} = $response_number;
1.542 raeburn 8161: $response_number++;
8162:
8163: $bubble_line += $lines;
8164: $total_lines += $lines;
8165: }
8166: }
8167: }
1.552 raeburn 8168: &Apache::lonnet::delenv('scantron.');
1.542 raeburn 8169:
8170: &save_bubble_lines();
8171: $env{'form.scantron_maxbubble'} =
8172: $total_lines;
8173: return $env{'form.scantron_maxbubble'};
8174: }
1.523 raeburn 8175:
1.596.2.12.2. (raeburn 8176:): sub bubblesheet_bubbles_per_row {
8177:): my ($scantron_config) = @_;
8178:): my $bubbles_per_row;
8179:): if (ref($scantron_config) eq 'HASH') {
8180:): $bubbles_per_row = $scantron_config->{'BubblesPerRow'};
8181:): }
8182:): if ((!$bubbles_per_row) || ($bubbles_per_row < 1)) {
8183:): $bubbles_per_row = 10;
8184:): }
8185:): return $bubbles_per_row;
8186:): }
8187:):
1.157 albertel 8188: sub scantron_validate_missingbubbles {
8189: my ($r,$currentphase) = @_;
8190: #get student info
8191: my $classlist=&Apache::loncoursedata::get_classlist();
8192: my %idmap=&username_to_idmap($classlist);
1.596.2.12.2. 6(raebur 8193:3): my (undef,undef,$sequence)=
8194:3): &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.157 albertel 8195:
8196: #get scantron line setup
1.257 albertel 8197: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 8198: my ($scanlines,$scan_data)=&scantron_getfile();
1.596.2.12.2. 6(raebur 8199:3):
8200:3): my $navmap = Apache::lonnavmaps::navmap->new();
8201:3): unless (ref($navmap)) {
8202:3): $r->print(&navmap_errormsg());
8203:3): return(1,$currentphase);
8204:3): }
8205:3):
8206:3): my $map=$navmap->getResourceByUrl($sequence);
8207:3): my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
8208:3): my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
8209:3): %grader_randomlists_by_symb,%orderedforcode,%respnumlookup,%startline);
8210:3): my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
8211:3):
1.582 raeburn 8212: my $nav_error;
1.596.2.12.2. 6(raebur 8213:3): if (ref($map)) {
8214:3): $randomorder = $map->randomorder();
8215:3): $randompick = $map->randompick();
7(raebur 8216:3): if ($randomorder || $randompick) {
8217:3): $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource);
8218:3): if ($nav_error) {
8219:3): $r->print(&navmap_errormsg());
8220:3): return(1,$currentphase);
8221:3): }
8222:3): &graders_resources_pass(\@resources,\%grader_partids_by_symb,
8223:3): \%grader_randomlists_by_symb,$bubbles_per_row);
8224:3): }
6(raebur 8225:3): } else {
8226:3): $r->print(&navmap_errormsg());
7(raebur 8227:3): return(1,$currentphase);
6(raebur 8228:3): }
8229:3):
8230:3):
(raeburn 8231:): my $max_bubble=&scantron_get_maxbubble(\$nav_error,\%scantron_config);
1.582 raeburn 8232: if ($nav_error) {
1.596.2.12.2. 6(raebur 8233:3): $r->print(&navmap_errormsg());
1.582 raeburn 8234: return(1,$currentphase);
8235: }
1.596.2.12.2. 6(raebur 8236:3):
1.157 albertel 8237: if (!$max_bubble) { $max_bubble=2**31; }
8238: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 8239: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 8240: if ($line=~/^[\s\cz]*$/) { next; }
1.596.2.12.2. 6(raebur 8241:3): my $scan_record =
8242:3): &scantron_parse_scanline($line,$i,\%scantron_config,$scan_data,undef,\%idmap,
8243:3): $randomorder,$randompick,$sequence,\@master_seq,
8244:3): \%symb_to_resource,\%grader_partids_by_symb,
8245:3): \%orderedforcode,\%respnumlookup,\%startline);
1.157 albertel 8246: if (!defined($$scan_record{'scantron.missingerror'})) { next; }
8247: my @to_correct;
1.470 foxr 8248:
8249: # Probably here's where the error is...
8250:
1.157 albertel 8251: foreach my $missing (@{$$scan_record{'scantron.missingerror'}}) {
1.505 raeburn 8252: my $lastbubble;
8253: if ($missing =~ /^(\d+)\.(\d+)$/) {
1.596.2.12.2. 6(raebur 8254:3): my $question = $1;
8255:3): my $subquestion = $2;
8256:3): my ($first,$responsenum);
8257:3): if ($randomorder || $randompick) {
8258:3): $responsenum = $respnumlookup{$question-1};
8259:3): $first = $startline{$question-1};
8260:3): } else {
8261:3): $responsenum = $question-1;
8262:3): $first = $first_bubble_line{$responsenum};
8263:3): }
8264:3): if (!defined($first)) { next; }
7(raebur 8265:3): my @subans = split(/,/,$subdivided_bubble_lines{$responsenum});
6(raebur 8266:3): my $subcount = 1;
8267:3): while ($subcount<$subquestion) {
8268:3): $first += $subans[$subcount-1];
8269:3): $subcount ++;
8270:3): }
8271:3): my $count = $subans[$subquestion-1];
8272:3): $lastbubble = $first + $count;
1.505 raeburn 8273: } else {
1.596.2.12.2. 6(raebur 8274:3): my ($first,$responsenum);
8275:3): if ($randomorder || $randompick) {
8276:3): $responsenum = $respnumlookup{$missing-1};
8277:3): $first = $startline{$missing-1};
8278:3): } else {
8279:3): $responsenum = $missing-1;
8280:3): $first = $first_bubble_line{$responsenum};
8281:3): }
8282:3): if (!defined($first)) { next; }
8283:3): $lastbubble = $first + $bubble_lines_per_response{$responsenum};
1.505 raeburn 8284: }
8285: if ($lastbubble > $max_bubble) { next; }
1.157 albertel 8286: push(@to_correct,$missing);
8287: }
8288: if (@to_correct) {
8289: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
1.596.2.12.2. 6(raebur 8290:3): $line,'missingbubble',\@to_correct,
8291:3): $randomorder,$randompick,\%respnumlookup,
8292:3): \%startline);
1.157 albertel 8293: return (1,$currentphase);
8294: }
8295:
8296: }
8297: return (0,$currentphase+1);
8298: }
8299:
1.596.2.12.2. (raeburn 8300:): sub hand_bubble_option {
8301:): my (undef, undef, $sequence) =
8302:): &Apache::lonnet::decode_symb($env{'form.selectpage'});
8303:): return if ($sequence eq '');
8304:): my $navmap = Apache::lonnavmaps::navmap->new();
8305:): unless (ref($navmap)) {
8306:): return;
8307:): }
8308:): my $needs_hand_bubbles;
8309:): my $map=$navmap->getResourceByUrl($sequence);
8310:): my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
8311:): foreach my $res (@resources) {
8312:): if (ref($res)) {
8313:): if ($res->is_problem()) {
8314:): my $partlist = $res->parts();
8315:): foreach my $part (@{ $partlist }) {
8316:): my @types = $res->responseType($part);
8317:): if (grep(/^(chem|essay|image|formula|math|string|functionplot)$/,@types)) {
8318:): $needs_hand_bubbles = 1;
8319:): last;
8320:): }
8321:): }
8322:): }
8323:): }
8324:): }
8325:): if ($needs_hand_bubbles) {
8326:): my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
8327:): my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
8328:): return &mt('The sequence to be graded contains response types which are handgraded.').'<p>'.
8329:): &mt('If you have already graded these by bubbling sheets to indicate points awarded, [_1]what point value is assigned to a filled last bubble in each row?','<br />').
8330:): '<label><input type="radio" name="scantron_lastbubblepoints" value="'.$bubbles_per_row.'" checked="checked" />'.&mt('[quant,_1,point]',$bubbles_per_row).'</label> '.&mt('or').' '.
8331:): '<label><input type="radio" name="scantron_lastbubblepoints" value="0"/>0 points</label></p>';
8332:): }
8333:): return;
8334:): }
1.423 albertel 8335:
1.82 albertel 8336: sub scantron_process_students {
1.75 albertel 8337: my ($r) = @_;
1.513 foxr 8338:
1.257 albertel 8339: my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($env{'form.selectpage'});
1.324 albertel 8340: my ($symb)=&get_symb($r);
1.513 foxr 8341: if (!$symb) {
8342: return '';
8343: }
1.324 albertel 8344: my $default_form_data=&defaultFormData($symb);
1.82 albertel 8345:
1.257 albertel 8346: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.596.2.12.2. 6(raebur 8347:3): my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
1.157 albertel 8348: my ($scanlines,$scan_data)=&scantron_getfile();
1.82 albertel 8349: my $classlist=&Apache::loncoursedata::get_classlist();
8350: my %idmap=&username_to_idmap($classlist);
1.132 bowersj2 8351: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 8352: unless (ref($navmap)) {
8353: $r->print(&navmap_errormsg());
8354: return '';
1.596.2.12.2. 6(raebur 8355:3): }
1.83 albertel 8356: my $map=$navmap->getResourceByUrl($sequence);
1.596.2.12.2. 6(raebur 8357:3): my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
8358:3): %grader_randomlists_by_symb);
1(raebur 8359:2): if (ref($map)) {
8360:2): $randomorder = $map->randomorder();
6(raebur 8361:3): $randompick = $map->randompick();
8362:3): } else {
8363:3): $r->print(&navmap_errormsg());
8364:3): return '';
1(raebur 8365:2): }
6(raebur 8366:3): my $nav_error;
1.83 albertel 8367: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.596.2.12.2. 1(raebur 8368:2): my (%grader_partids_by_symb,%grader_randomlists_by_symb,%ordered);
6(raebur 8369:3): if ($randomorder || $randompick) {
8370:3): $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource);
8371:3): if ($nav_error) {
8372:3): $r->print(&navmap_errormsg());
8373:3): return '';
1.586 raeburn 8374: }
8375: }
1.596.2.12.2. 6(raebur 8376:3): &graders_resources_pass(\@resources,\%grader_partids_by_symb,
8377:3): \%grader_randomlists_by_symb,$bubbles_per_row);
1.557 raeburn 8378:
1.554 raeburn 8379: my ($uname,$udom);
1.82 albertel 8380: my $result= <<SCANTRONFORM;
1.81 albertel 8381: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
8382: <input type="hidden" name="command" value="scantron_configphase" />
8383: $default_form_data
8384: SCANTRONFORM
1.82 albertel 8385: $r->print($result);
8386:
8387: my @delayqueue;
1.542 raeburn 8388: my (%completedstudents,%scandata);
1.140 albertel 8389:
1.520 www 8390: my $lock=&Apache::lonnet::set_lock(&mt('Grading bubblesheet exam'));
1.200 albertel 8391: my $count=&get_todo_count($scanlines,$scan_data);
1.596.2.12.2. (raeburn 8392:): my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$count);
1.140 albertel 8393: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
8394: 'Processing first student');
1.542 raeburn 8395: $r->print('<br />');
1.140 albertel 8396: my $start=&Time::HiRes::time();
1.158 albertel 8397: my $i=-1;
1.542 raeburn 8398: my $started;
1.447 foxr 8399:
1.596.2.12.2. (raeburn 8400:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # Need the bubble lines array to parse.
1.582 raeburn 8401: if ($nav_error) {
8402: $r->print(&navmap_errormsg());
8403: return '';
8404: }
8405:
1.513 foxr 8406: # If an ssi failed in scantron_get_maxbubble, put an error message out to
8407: # the user and return.
8408:
8409: if ($ssi_error) {
8410: $r->print("</form>");
8411: &ssi_print_error($r);
8412: $r->print(&show_grading_menu_form($symb));
1.520 www 8413: &Apache::lonnet::remove_lock($lock);
1.513 foxr 8414: return ''; # Dunno why the other returns return '' rather than just returning.
8415: }
1.447 foxr 8416:
1.542 raeburn 8417: my %lettdig = &letter_to_digits();
8418: my $numletts = scalar(keys(%lettdig));
1.596.2.12.2. 6(raebur 8419:3): my %orderedforcode;
1.542 raeburn 8420:
1.157 albertel 8421: while ($i<$scanlines->{'count'}) {
8422: ($uname,$udom)=('','');
8423: $i++;
1.200 albertel 8424: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 8425: if ($line=~/^[\s\cz]*$/) { next; }
1.200 albertel 8426: if ($started) {
8427: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
8428: 'last student');
8429: }
8430: $started=1;
1.596.2.12.2. 6(raebur 8431:3): my %respnumlookup = ();
8432:3): my %startline = ();
8433:3): my $total;
1.157 albertel 8434: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
1.596.2.12.2. 6(raebur 8435:3): $scan_data,undef,\%idmap,$randomorder,
8436:3): $randompick,$sequence,\@master_seq,
8437:3): \%symb_to_resource,\%grader_partids_by_symb,
8438:3): \%orderedforcode,\%respnumlookup,\%startline,
8439:3): \$total);
1.157 albertel 8440: unless ($uname=&scantron_find_student($scan_record,$scan_data,
8441: \%idmap,$i)) {
8442: &scantron_add_delay(\@delayqueue,$line,
8443: 'Unable to find a student that matches',1);
8444: next;
8445: }
8446: if (exists $completedstudents{$uname}) {
8447: &scantron_add_delay(\@delayqueue,$line,
8448: 'Student '.$uname.' has multiple sheets',2);
8449: next;
8450: }
1.596.2.12.2. 1(raebur 8451:2): my $usec = $classlist->{$uname}->[&Apache::loncoursedata::CL_SECTION];
8452:2): my $user = $uname.':'.$usec;
1.157 albertel 8453: ($uname,$udom)=split(/:/,$uname);
1.330 albertel 8454:
1.596.2.12.2. 1(raebur 8455:2): my $scancode;
8456:2): if ((exists($scan_record->{'scantron.CODE'})) &&
8457:2): (&Apache::lonnet::validCODE($scan_record->{'scantron.CODE'}))) {
8458:2): $scancode = $scan_record->{'scantron.CODE'};
8459:2): } else {
8460:2): $scancode = '';
8461:2): }
8462:2):
8463:2): my @mapresources = @resources;
6(raebur 8464:3): if ($randomorder || $randompick) {
1(raebur 8465:2): @mapresources =
6(raebur 8466:3): &users_order($user,$scancode,$sequence,\@master_seq,\%symb_to_resource,
8467:3): \%orderedforcode);
1(raebur 8468:2): }
1.586 raeburn 8469: my (%partids_by_symb,$res_error);
1.596.2.12.2. 1(raebur 8470:2): foreach my $resource (@mapresources) {
1.586 raeburn 8471: my $ressymb;
8472: if (ref($resource)) {
8473: $ressymb = $resource->symb();
8474: } else {
8475: $res_error = 1;
8476: last;
8477: }
1.557 raeburn 8478: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
8479: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
8480: my ($analysis,$parts) =
1.596.2.12.2. (raeburn 8481:): &scantron_partids_tograde($resource,$env{'request.course.id'},
8482:): $uname,$udom,undef,$bubbles_per_row);
1.557 raeburn 8483: $partids_by_symb{$ressymb} = $parts;
8484: } else {
8485: $partids_by_symb{$ressymb} = $grader_partids_by_symb{$ressymb};
8486: }
1.554 raeburn 8487: }
8488:
1.586 raeburn 8489: if ($res_error) {
8490: &scantron_add_delay(\@delayqueue,$line,
8491: 'An error occurred while grading student '.$uname,2);
8492: next;
8493: }
8494:
1.330 albertel 8495: &Apache::lonxml::clear_problem_counter();
1.514 raeburn 8496: &Apache::lonnet::appenv($scan_record);
1.376 albertel 8497:
8498: if (&scantron_clear_skip($scanlines,$scan_data,$i)) {
8499: &scantron_putfile($scanlines,$scan_data);
8500: }
1.161 albertel 8501:
1.542 raeburn 8502: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
1.596.2.12.2. 1(raebur 8503:2): \@mapresources,\%partids_by_symb,
6(raebur 8504:3): $bubbles_per_row,$randomorder,$randompick,
8505:3): \%respnumlookup,\%startline)
8506:3): eq 'ssi_error') {
1.542 raeburn 8507: $ssi_error = 0; # So end of handler error message does not trigger.
8508: $r->print("</form>");
8509: &ssi_print_error($r);
8510: $r->print(&show_grading_menu_form($symb));
8511: &Apache::lonnet::remove_lock($lock);
8512: return ''; # Why return ''? Beats me.
8513: }
1.513 foxr 8514:
1.596.2.12.2. 6(raebur 8515:3): if (($scancode) && ($randomorder || $randompick)) {
8516:3): my $parmresult =
8517:3): &Apache::lonparmset::storeparm_by_symb($symb,
8518:3): '0_examcode',2,$scancode,
8519:3): 'string_examcode',$uname,
8520:3): $udom);
8521:3): }
1.140 albertel 8522: $completedstudents{$uname}={'line'=>$line};
1.542 raeburn 8523: if ($env{'form.verifyrecord'}) {
8524: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
1.596.2.12.2. 6(raebur 8525:3): if ($randompick) {
8526:3): if ($total) {
8527:3): $lastpos = $total*$scantron_config{'Qlength'};
8528:3): }
8529:3): }
8530:3):
1.542 raeburn 8531: my $studentdata = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
8532: chomp($studentdata);
8533: $studentdata =~ s/\r$//;
8534: my $studentrecord = '';
8535: my $counter = -1;
1.596.2.12.2. 1(raebur 8536:2): foreach my $resource (@mapresources) {
1.554 raeburn 8537: my $ressymb = $resource->symb();
1.542 raeburn 8538: ($counter,my $recording) =
8539: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 8540: $counter,$studentdata,$partids_by_symb{$ressymb},
1.596.2.12.2. 6(raebur 8541:3): \%scantron_config,\%lettdig,$numletts,$randomorder,
8542:3): $randompick,\%respnumlookup,\%startline);
1.542 raeburn 8543: $studentrecord .= $recording;
8544: }
8545: if ($studentrecord ne $studentdata) {
1.554 raeburn 8546: &Apache::lonxml::clear_problem_counter();
8547: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
1.596.2.12.2. 1(raebur 8548:2): \@mapresources,\%partids_by_symb,
6(raebur 8549:3): $bubbles_per_row,$randomorder,$randompick,
8550:3): \%respnumlookup,\%startline)
8551:3): eq 'ssi_error') {
1.554 raeburn 8552: $ssi_error = 0; # So end of handler error message does not trigger.
8553: $r->print("</form>");
8554: &ssi_print_error($r);
8555: $r->print(&show_grading_menu_form($symb));
8556: &Apache::lonnet::remove_lock($lock);
8557: delete($completedstudents{$uname});
8558: return '';
8559: }
1.542 raeburn 8560: $counter = -1;
8561: $studentrecord = '';
1.596.2.12.2. 1(raebur 8562:2): foreach my $resource (@mapresources) {
1.554 raeburn 8563: my $ressymb = $resource->symb();
1.542 raeburn 8564: ($counter,my $recording) =
8565: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 8566: $counter,$studentdata,$partids_by_symb{$ressymb},
1.596.2.12.2. 6(raebur 8567:3): \%scantron_config,\%lettdig,$numletts,
8568:3): $randomorder,$randompick,\%respnumlookup,
8569:3): \%startline);
1.542 raeburn 8570: $studentrecord .= $recording;
8571: }
8572: if ($studentrecord ne $studentdata) {
1.596.2.6 raeburn 8573: $r->print('<p><span class="LC_warning">');
1.542 raeburn 8574: if ($scancode eq '') {
1.596.2.6 raeburn 8575: $r->print(&mt('Mismatch grading bubblesheet for user: [_1] with ID: [_2].',
1.542 raeburn 8576: $uname.':'.$udom,$scan_record->{'scantron.ID'}));
8577: } else {
1.596.2.6 raeburn 8578: $r->print(&mt('Mismatch grading bubblesheet for user: [_1] with ID: [_2] and CODE: [_3].',
1.542 raeburn 8579: $uname.':'.$udom,$scan_record->{'scantron.ID'},$scancode));
8580: }
8581: $r->print('</span><br />'.&Apache::loncommon::start_data_table()."\n".
8582: &Apache::loncommon::start_data_table_header_row()."\n".
8583: '<th>'.&mt('Source').'</th><th>'.&mt('Bubbled responses').'</th>'.
8584: &Apache::loncommon::end_data_table_header_row()."\n".
8585: &Apache::loncommon::start_data_table_row().
1.596.2.6 raeburn 8586: '<td>'.&mt('Bubblesheet').'</td>'.
1.542 raeburn 8587: '<td><span class="LC_nobreak">'.$studentdata.'</span></td>'.
8588: &Apache::loncommon::end_data_table_row().
8589: &Apache::loncommon::start_data_table_row().
1.596.2.6 raeburn 8590: '<td>'.&mt('Stored submissions').'</td>'.
1.542 raeburn 8591: '<td><span class="LC_nobreak">'.$studentrecord.'</span></td>'."\n".
8592: &Apache::loncommon::end_data_table_row().
8593: &Apache::loncommon::end_data_table().'</p>');
8594: } else {
8595: $r->print('<br /><span class="LC_warning">'.
8596: &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 />'.
8597: &mt("As a consequence, this user's submission history records two tries.").
8598: '</span><br />');
8599: }
8600: }
8601: }
1.543 raeburn 8602: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.140 albertel 8603: } continue {
1.330 albertel 8604: &Apache::lonxml::clear_problem_counter();
1.552 raeburn 8605: &Apache::lonnet::delenv('scantron.');
1.82 albertel 8606: }
1.140 albertel 8607: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.520 www 8608: &Apache::lonnet::remove_lock($lock);
1.172 albertel 8609: # my $lasttime = &Time::HiRes::time()-$start;
8610: # $r->print("<p>took $lasttime</p>");
1.140 albertel 8611:
1.200 albertel 8612: $r->print("</form>");
1.324 albertel 8613: $r->print(&show_grading_menu_form($symb));
1.157 albertel 8614: return '';
1.75 albertel 8615: }
1.157 albertel 8616:
1.557 raeburn 8617: sub graders_resources_pass {
1.596.2.12.2. (raeburn 8618:): my ($resources,$grader_partids_by_symb,$grader_randomlists_by_symb,
8619:): $bubbles_per_row) = @_;
1.557 raeburn 8620: if ((ref($resources) eq 'ARRAY') && (ref($grader_partids_by_symb)) &&
8621: (ref($grader_randomlists_by_symb) eq 'HASH')) {
8622: foreach my $resource (@{$resources}) {
8623: my $ressymb = $resource->symb();
8624: my ($analysis,$parts) =
8625: &scantron_partids_tograde($resource,$env{'request.course.id'},
1.596.2.12.2. (raeburn 8626:): $env{'user.name'},$env{'user.domain'},
8627:): 1,$bubbles_per_row);
1.557 raeburn 8628: $grader_partids_by_symb->{$ressymb} = $parts;
8629: if (ref($analysis) eq 'HASH') {
8630: if (ref($analysis->{'parts_withrandomlist'}) eq 'ARRAY') {
8631: $grader_randomlists_by_symb->{$ressymb} =
8632: $analysis->{'parts_withrandomlist'};
8633: }
8634: }
8635: }
8636: }
8637: return;
8638: }
8639:
1.596.2.12.2. 1(raebur 8640:2): =pod
8641:2):
8642:2): =item users_order
8643:2):
8644:2): Returns array of resources in current map, ordered based on either CODE,
8645:2): if this is a CODEd exam, or based on student's identity if this is a
8646:2): "NAMEd" exam.
8647:2):
6(raebur 8648:3): Should be used when randomorder and/or randompick applied when the
8649:3): corresponding exam was printed, prior to students completing bubblesheets
8650:3): for the version of the exam the student received.
1(raebur 8651:2):
8652:2): =cut
8653:2):
8654:2): sub users_order {
6(raebur 8655:3): my ($user,$scancode,$mapurl,$master_seq,$symb_to_resource,$orderedforcode) = @_;
1(raebur 8656:2): my @mapresources;
6(raebur 8657:3): unless ((ref($master_seq) eq 'ARRAY') && (ref($symb_to_resource) eq 'HASH')) {
1(raebur 8658:2): return @mapresources;
8659:2): }
6(raebur 8660:3): if ($scancode) {
8661:3): if ((ref($orderedforcode) eq 'HASH') && (ref($orderedforcode->{$scancode}) eq 'ARRAY')) {
8662:3): @mapresources = @{$orderedforcode->{$scancode}};
8663:3): } else {
8664:3): $env{'form.CODE'} = $scancode;
8665:3): my $actual_seq =
8666:3): &Apache::lonprintout::master_seq_to_person_seq($mapurl,
8667:3): $master_seq,
8668:3): $user,$scancode,1);
8669:3): if (ref($actual_seq) eq 'ARRAY') {
8670:3): @mapresources = map { $symb_to_resource->{$_}; } @{$actual_seq};
8671:3): if (ref($orderedforcode) eq 'HASH') {
8672:3): if (@mapresources > 0) {
8673:3): $orderedforcode->{$scancode} = \@mapresources;
8674:3): }
8675:3): }
8676:3): }
8677:3): delete($env{'form.CODE'});
1(raebur 8678:2): }
8679:2): } else {
8680:2): my $actual_seq =
8681:2): &Apache::lonprintout::master_seq_to_person_seq($mapurl,
8682:2): $master_seq,
5(raebur 8683:3): $user,undef,1);
1(raebur 8684:2): if (ref($actual_seq) eq 'ARRAY') {
8685:2): @mapresources =
8686:2): map { $symb_to_resource->{$_}; } @{$actual_seq};
8687:2): }
6(raebur 8688:3): }
8689:3): return @mapresources;
1(raebur 8690:2): }
8691:2):
1.542 raeburn 8692: sub grade_student_bubbles {
1.596.2.12.2. 6(raebur 8693:3): my ($r,$uname,$udom,$scan_record,$scancode,$resources,$parts,$bubbles_per_row,
8694:3): $randomorder,$randompick,$respnumlookup,$startline) = @_;
8695:3): my $uselookup = 0;
8696:3): if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH') &&
8697:3): (ref($startline) eq 'HASH')) {
8698:3): $uselookup = 1;
8699:3): }
8700:3):
1.554 raeburn 8701: if (ref($resources) eq 'ARRAY') {
8702: my $count = 0;
8703: foreach my $resource (@{$resources}) {
8704: my $ressymb = $resource->symb();
8705: my %form = ('submitted' => 'scantron',
8706: 'grade_target' => 'grade',
8707: 'grade_username' => $uname,
8708: 'grade_domain' => $udom,
8709: 'grade_courseid' => $env{'request.course.id'},
8710: 'grade_symb' => $ressymb,
8711: 'CODE' => $scancode
8712: );
1.596.2.12.2. (raeburn 8713:): if ($bubbles_per_row ne '') {
8714:): $form{'bubbles_per_row'} = $bubbles_per_row;
8715:): }
8716:): if ($env{'form.scantron_lastbubblepoints'} ne '') {
8717:): $form{'scantron_lastbubblepoints'} = $env{'form.scantron_lastbubblepoints'};
8718:): }
1.554 raeburn 8719: if (ref($parts) eq 'HASH') {
8720: if (ref($parts->{$ressymb}) eq 'ARRAY') {
8721: foreach my $part (@{$parts->{$ressymb}}) {
1.596.2.12.2. 6(raebur 8722:3): if ($uselookup) {
8723:3): $form{'scantron_questnum_start.'.$part} = $startline->{$count} + 1;
8724:3): } else {
8725:3): $form{'scantron_questnum_start.'.$part} =
8726:3): 1+$env{'form.scantron.first_bubble_line.'.$count};
8727:3): }
1.554 raeburn 8728: $count++;
8729: }
8730: }
8731: }
8732: my $result=&ssi_with_retries($resource->src(),$ssi_retries,%form);
8733: return 'ssi_error' if ($ssi_error);
8734: last if (&Apache::loncommon::connection_aborted($r));
8735: }
1.542 raeburn 8736: }
8737: return;
8738: }
8739:
1.157 albertel 8740: sub scantron_upload_scantron_data {
8741: my ($r)=@_;
1.565 raeburn 8742: my $dom = $env{'request.role.domain'};
8743: my $domdesc = &Apache::lonnet::domain($dom,'description');
8744: $r->print(&Apache::loncommon::coursebrowser_javascript($dom));
1.157 albertel 8745: my $select_link=&Apache::loncommon::selectcourse_link('rules','courseid',
1.181 albertel 8746: 'domainid',
1.565 raeburn 8747: 'coursename',$dom);
8748: my $syllabuslink = '<a href="javascript:ToSyllabus();">'.&mt('Syllabus').'</a>'.
1.596.2.12.2. (raeburn 8749:): (' 'x2).&mt('(shows course personnel)');
8750:): my ($symb) = &get_symb($r,1);
8751:): my $default_form_data=&defaultFormData($symb);
1.579 raeburn 8752: my $nofile_alert = &mt('Please use the browse button to select a file from your local directory.');
8753: 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 8754: $r->print('
1.157 albertel 8755: <script type="text/javascript" language="javascript">
8756: function checkUpload(formname) {
8757: if (formname.upfile.value == "") {
1.579 raeburn 8758: alert("'.$nofile_alert.'");
1.157 albertel 8759: return false;
8760: }
1.565 raeburn 8761: if (formname.courseid.value == "") {
1.579 raeburn 8762: alert("'.$nocourseid_alert.'");
1.565 raeburn 8763: return false;
8764: }
1.157 albertel 8765: formname.submit();
8766: }
1.565 raeburn 8767:
8768: function ToSyllabus() {
8769: var cdom = '."'$dom'".';
8770: var cnum = document.rules.courseid.value;
8771: if (cdom == "" || cdom == null) {
8772: return;
8773: }
8774: if (cnum == "" || cnum == null) {
8775: return;
8776: }
8777: syllwin=window.open("/public/"+cdom+"/"+cnum+"/syllabus","LONCAPASyllabus",
8778: "height=350,width=350,scrollbars=yes,menubar=no");
8779: return;
8780: }
8781:
1.157 albertel 8782: </script>
8783:
1.596.2.4 raeburn 8784: <h3>'.&mt('Send bubblesheet data to a course').'</h3>
1.566 raeburn 8785:
1.492 albertel 8786: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
1.565 raeburn 8787: '.$default_form_data.
8788: &Apache::lonhtmlcommon::start_pick_box().
8789: &Apache::lonhtmlcommon::row_title(&mt('Course ID')).
8790: '<input name="courseid" type="text" size="30" />'.$select_link.
8791: &Apache::lonhtmlcommon::row_closure().
8792: &Apache::lonhtmlcommon::row_title(&mt('Course Name')).
8793: '<input name="coursename" type="text" size="30" />'.$syllabuslink.
8794: &Apache::lonhtmlcommon::row_closure().
8795: &Apache::lonhtmlcommon::row_title(&mt('Domain')).
8796: '<input name="domainid" type="hidden" />'.$domdesc.
8797: &Apache::lonhtmlcommon::row_closure().
8798: &Apache::lonhtmlcommon::row_title(&mt('File to upload')).
8799: '<input type="file" name="upfile" size="50" />'.
8800: &Apache::lonhtmlcommon::row_closure(1).
8801: &Apache::lonhtmlcommon::end_pick_box().'<br />
8802:
1.492 albertel 8803: <input name="command" value="scantronupload_save" type="hidden" />
1.589 bisitz 8804: <input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
1.157 albertel 8805: </form>
1.492 albertel 8806: ');
1.157 albertel 8807: return '';
8808: }
8809:
1.423 albertel 8810:
1.157 albertel 8811: sub scantron_upload_scantron_data_save {
8812: my($r)=@_;
1.324 albertel 8813: my ($symb)=&get_symb($r,1);
1.182 albertel 8814: my $doanotherupload=
8815: '<br /><form action="/adm/grades" method="post">'."\n".
8816: '<input type="hidden" name="command" value="scantronupload" />'."\n".
1.492 albertel 8817: '<input type="submit" name="submit" value="'.&mt('Do Another Upload').'" />'."\n".
1.182 albertel 8818: '</form>'."\n";
1.257 albertel 8819: if (!&Apache::lonnet::allowed('usc',$env{'form.domainid'}) &&
1.162 albertel 8820: !&Apache::lonnet::allowed('usc',
1.257 albertel 8821: $env{'form.domainid'}.'_'.$env{'form.courseid'})) {
1.575 www 8822: $r->print(&mt("You are not allowed to upload bubblesheet data to the requested course.")."<br />");
1.182 albertel 8823: if ($symb) {
1.324 albertel 8824: $r->print(&show_grading_menu_form($symb));
1.182 albertel 8825: } else {
8826: $r->print($doanotherupload);
8827: }
1.162 albertel 8828: return '';
8829: }
1.257 albertel 8830: my %coursedata=&Apache::lonnet::coursedescription($env{'form.domainid'}.'_'.$env{'form.courseid'});
1.568 raeburn 8831: my $uploadedfile;
1.567 raeburn 8832: $r->print('<h3>'.&mt("Uploading file to [_1]",$coursedata{'description'}).'</h3>');
1.257 albertel 8833: if (length($env{'form.upfile'}) < 2) {
1.568 raeburn 8834: $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 8835: } else {
1.568 raeburn 8836: my $result =
8837: &Apache::lonnet::userfileupload('upfile','','scantron','','','',
8838: $env{'form.courseid'},$env{'form.domainid'});
8839: if ($result =~ m{^/uploaded/}) {
1.567 raeburn 8840: $r->print(&mt('[_1]Success:[_2] Successfully uploaded [_3] bytes of data into location: [_4]',
8841: '<span class="LC_success">','</span>',(length($env{'form.upfile'})-1),
8842: '<span class="LC_filename">'.$result.'</span>'));
1.568 raeburn 8843: ($uploadedfile) = ($result =~ m{/([^/]+)$});
1.567 raeburn 8844: $r->print(&validate_uploaded_scantron_file($env{'form.domainid'},
1.568 raeburn 8845: $env{'form.courseid'},$uploadedfile));
1.210 albertel 8846: } else {
1.567 raeburn 8847: $r->print(&mt('[_1]Error:[_2] An error ([_3]) occurred when attempting to upload the file, [_4]',
8848: '<span class="LC_error">','</span>',$result,
1.568 raeburn 8849: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'));
1.183 albertel 8850: }
8851: }
1.174 albertel 8852: if ($symb) {
1.209 ng 8853: $r->print(&scantron_selectphase($r,$uploadedfile));
1.174 albertel 8854: } else {
1.182 albertel 8855: $r->print($doanotherupload);
1.174 albertel 8856: }
1.157 albertel 8857: return '';
8858: }
8859:
1.567 raeburn 8860: sub validate_uploaded_scantron_file {
8861: my ($cdom,$cname,$fname) = @_;
8862: my $scanlines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.$fname);
8863: my @lines;
8864: if ($scanlines ne '-1') {
8865: @lines=split("\n",$scanlines,-1);
8866: }
8867: my $output;
8868: if (@lines) {
8869: my (%counts,$max_match_format);
8870: my ($max_match_count,$max_match_pct) = (0,0);
8871: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cname);
8872: my %idmap = &username_to_idmap($classlist);
8873: foreach my $key (keys(%idmap)) {
8874: my $lckey = lc($key);
8875: $idmap{$lckey} = $idmap{$key};
8876: }
8877: my %unique_formats;
8878: my @formatlines = &get_scantronformat_file();
8879: foreach my $line (@formatlines) {
8880: chomp($line);
8881: my @config = split(/:/,$line);
8882: my $idstart = $config[5];
8883: my $idlength = $config[6];
8884: if (($idstart ne '') && ($idlength > 0)) {
8885: if (ref($unique_formats{$idstart.':'.$idlength}) eq 'ARRAY') {
8886: push(@{$unique_formats{$idstart.':'.$idlength}},$config[0].':'.$config[1]);
8887: } else {
8888: $unique_formats{$idstart.':'.$idlength} = [$config[0].':'.$config[1]];
8889: }
8890: }
8891: }
8892: foreach my $key (keys(%unique_formats)) {
8893: my ($idstart,$idlength) = split(':',$key);
8894: %{$counts{$key}} = (
8895: 'found' => 0,
8896: 'total' => 0,
8897: );
8898: foreach my $line (@lines) {
8899: next if ($line =~ /^#/);
8900: next if ($line =~ /^[\s\cz]*$/);
8901: my $id = substr($line,$idstart-1,$idlength);
8902: $id = lc($id);
8903: if (exists($idmap{$id})) {
8904: $counts{$key}{'found'} ++;
8905: }
8906: $counts{$key}{'total'} ++;
8907: }
8908: if ($counts{$key}{'total'}) {
8909: my $percent_match = (100*$counts{$key}{'found'})/($counts{$key}{'total'});
8910: if (($max_match_format eq '') || ($percent_match > $max_match_pct)) {
8911: $max_match_pct = $percent_match;
8912: $max_match_format = $key;
8913: $max_match_count = $counts{$key}{'total'};
8914: }
8915: }
8916: }
8917: if (ref($unique_formats{$max_match_format}) eq 'ARRAY') {
8918: my $format_descs;
8919: my $numwithformat = @{$unique_formats{$max_match_format}};
8920: for (my $i=0; $i<$numwithformat; $i++) {
8921: my ($name,$desc) = split(':',$unique_formats{$max_match_format}[$i]);
8922: if ($i<$numwithformat-2) {
8923: $format_descs .= '"<i>'.$desc.'</i>", ';
8924: } elsif ($i==$numwithformat-2) {
8925: $format_descs .= '"<i>'.$desc.'</i>" '.&mt('and').' ';
8926: } elsif ($i==$numwithformat-1) {
8927: $format_descs .= '"<i>'.$desc.'</i>"';
8928: }
8929: }
8930: my $showpct = sprintf("%.0f",$max_match_pct).'%';
8931: $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).
8932: '<br />'.&mt('A low percentage of matches results from one of the following:').'<ul>'.
8933: '<li>'.&mt('The file was uploaded to the wrong course').'</li>'.
8934: '<li>'.&mt('The data are not in the format expected for the domain: [_1]',
8935: '<i>'.$cdom.'</i>').'</li>'.
8936: '<li>'.&mt('Students did not bubble their IDs, or mis-bubbled them').'</li>'.
8937: '<li>'.&mt('The course roster is not up to date').'</li>'.
8938: '</ul>';
8939: }
8940: } else {
8941: $output = '<span class="LC_warning">'.&mt('Uploaded file contained no data').'</span>';
8942: }
8943: return $output;
8944: }
8945:
1.202 albertel 8946: sub valid_file {
8947: my ($requested_file)=@_;
8948: foreach my $filename (sort(&scantron_filenames())) {
8949: if ($requested_file eq $filename) { return 1; }
8950: }
8951: return 0;
8952: }
8953:
8954: sub scantron_download_scantron_data {
8955: my ($r)=@_;
1.596.2.12.2. (raeburn 8956:): my ($symb) = &get_symb($r,1);
8957:): my $default_form_data=&defaultFormData($symb);
1.257 albertel 8958: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
8959: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
8960: my $file=$env{'form.scantron_selectfile'};
1.202 albertel 8961: if (! &valid_file($file)) {
1.492 albertel 8962: $r->print('
1.202 albertel 8963: <p>
1.596.2.12.2. 3(raebur 8964:3): '.&mt('The requested filename was invalid.').'
1.202 albertel 8965: </p>
1.492 albertel 8966: ');
1.596.2.12.2. (raeburn 8967:): $r->print(&show_grading_menu_form($symb));
1.202 albertel 8968: return;
8969: }
8970: my $orig='/uploaded/'.$cdom.'/'.$cname.'/scantron_orig_'.$file;
8971: my $corrected='/uploaded/'.$cdom.'/'.$cname.'/scantron_corrected_'.$file;
8972: my $skipped='/uploaded/'.$cdom.'/'.$cname.'/scantron_skipped_'.$file;
8973: &Apache::lonnet::allowuploaded('/adm/grades',$orig);
8974: &Apache::lonnet::allowuploaded('/adm/grades',$corrected);
8975: &Apache::lonnet::allowuploaded('/adm/grades',$skipped);
1.492 albertel 8976: $r->print('
1.202 albertel 8977: <p>
1.492 albertel 8978: '.&mt('[_1]Original[_2] file as uploaded by the scantron office.',
8979: '<a href="'.$orig.'">','</a>').'
1.202 albertel 8980: </p>
8981: <p>
1.492 albertel 8982: '.&mt('[_1]Corrections[_2], a file of corrected records that were used in grading.',
8983: '<a href="'.$corrected.'">','</a>').'
1.202 albertel 8984: </p>
8985: <p>
1.492 albertel 8986: '.&mt('[_1]Skipped[_2], a file of records that were skipped.',
8987: '<a href="'.$skipped.'">','</a>').'
1.202 albertel 8988: </p>
1.492 albertel 8989: ');
1.596.2.12.2. (raeburn 8990:): $r->print(&show_grading_menu_form($symb));
1.202 albertel 8991: return '';
8992: }
1.157 albertel 8993:
1.523 raeburn 8994: sub checkscantron_results {
8995: my ($r) = @_;
8996: my ($symb)=&get_symb($r);
8997: if (!$symb) {return '';}
8998: my $grading_menu_button=&show_grading_menu_form($symb);
8999: my $cid = $env{'request.course.id'};
1.542 raeburn 9000: my %lettdig = &letter_to_digits();
1.523 raeburn 9001: my $numletts = scalar(keys(%lettdig));
9002: my $cnum = $env{'course.'.$cid.'.num'};
9003: my $cdom = $env{'course.'.$cid.'.domain'};
9004: my (undef, undef, $sequence) = &Apache::lonnet::decode_symb($env{'form.selectpage'});
9005: my %record;
9006: my %scantron_config =
9007: &Apache::grades::get_scantron_config($env{'form.scantron_format'});
1.596.2.12.2. (raeburn 9008:): my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
1.523 raeburn 9009: my ($scanlines,$scan_data)=&Apache::grades::scantron_getfile();
9010: my $classlist=&Apache::loncoursedata::get_classlist();
9011: my %idmap=&Apache::grades::username_to_idmap($classlist);
9012: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 9013: unless (ref($navmap)) {
9014: $r->print(&navmap_errormsg());
9015: return '';
9016: }
1.523 raeburn 9017: my $map=$navmap->getResourceByUrl($sequence);
1.596.2.12.2. 6(raebur 9018:3): my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
9019:3): %grader_randomlists_by_symb,%orderedforcode);
1(raebur 9020:2): if (ref($map)) {
9021:2): $randomorder=$map->randomorder();
7(raebur 9022:3): $randompick=$map->randompick();
1(raebur 9023:2): }
1.557 raeburn 9024: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.596.2.12.2. 6(raebur 9025:3): my $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource);
9026:3): if ($nav_error) {
9027:3): $r->print(&navmap_errormsg());
9028:3): return '';
1(raebur 9029:2): }
(raeburn 9030:): &graders_resources_pass(\@resources,\%grader_partids_by_symb,
9031:): \%grader_randomlists_by_symb,$bubbles_per_row);
1.554 raeburn 9032: my ($uname,$udom);
1.523 raeburn 9033: my (%scandata,%lastname,%bylast);
9034: $r->print('
9035: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="checkscantron">'."\n");
9036:
9037: my @delayqueue;
9038: my %completedstudents;
9039:
1.596.2.12.2. 6(raebur 9040:3): my $count=&get_todo_count($scanlines,$scan_data);
(raeburn 9041:): my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$count);
1(raebur 9042:2): my ($username,$domain,$started,%ordered);
(raeburn 9043:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # Need the bubble lines array to parse.
1.582 raeburn 9044: if ($nav_error) {
9045: $r->print(&navmap_errormsg());
9046: return '';
9047: }
1.523 raeburn 9048:
9049: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
9050: 'Processing first student');
9051: my $start=&Time::HiRes::time();
9052: my $i=-1;
9053:
9054: while ($i<$scanlines->{'count'}) {
9055: ($username,$domain,$uname)=('','','');
9056: $i++;
9057: my $line=&Apache::grades::scantron_get_line($scanlines,$scan_data,$i);
9058: if ($line=~/^[\s\cz]*$/) { next; }
9059: if ($started) {
9060: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
9061: 'last student');
9062: }
9063: $started=1;
9064: my $scan_record=
9065: &Apache::grades::scantron_parse_scanline($line,$i,\%scantron_config,
9066: $scan_data);
1.596.2.12.2. 6(raebur 9067:3): unless ($uname=&scantron_find_student($scan_record,$scan_data,
9068:3): \%idmap,$i)) {
1.523 raeburn 9069: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
9070: 'Unable to find a student that matches',1);
9071: next;
9072: }
9073: if (exists $completedstudents{$uname}) {
9074: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
9075: 'Student '.$uname.' has multiple sheets',2);
9076: next;
9077: }
9078: my $pid = $scan_record->{'scantron.ID'};
9079: $lastname{$pid} = $scan_record->{'scantron.LastName'};
9080: push(@{$bylast{$lastname{$pid}}},$pid);
1.596.2.12.2. 1(raebur 9081:2): my $usec = $classlist->{$uname}->[&Apache::loncoursedata::CL_SECTION];
9082:2): my $user = $uname.':'.$usec;
1.523 raeburn 9083: ($username,$domain)=split(/:/,$uname);
1.596.2.12.2. 1(raebur 9084:2):
9085:2): my $scancode;
9086:2): if ((exists($scan_record->{'scantron.CODE'})) &&
9087:2): (&Apache::lonnet::validCODE($scan_record->{'scantron.CODE'}))) {
9088:2): $scancode = $scan_record->{'scantron.CODE'};
9089:2): } else {
9090:2): $scancode = '';
9091:2): }
9092:2):
9093:2): my @mapresources = @resources;
6(raebur 9094:3): my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
9095:3): my %respnumlookup=();
9096:3): my %startline=();
9097:3): if ($randomorder || $randompick) {
1(raebur 9098:2): @mapresources =
6(raebur 9099:3): &users_order($user,$scancode,$sequence,\@master_seq,\%symb_to_resource,
9100:3): \%orderedforcode);
9101:3): my $total = &get_respnum_lookups($sequence,$scan_data,\%idmap,$line,
9102:3): $scan_record,\@master_seq,\%symb_to_resource,
9103:3): \%grader_partids_by_symb,\%orderedforcode,
9104:3): \%respnumlookup,\%startline);
9105:3): if ($randompick && $total) {
9106:3): $lastpos = $total*$scantron_config{'Qlength'};
9107:3): }
1(raebur 9108:2): }
6(raebur 9109:3): $scandata{$pid} = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
9110:3): chomp($scandata{$pid});
9111:3): $scandata{$pid} =~ s/\r$//;
9112:3):
1.523 raeburn 9113: my $counter = -1;
1.596.2.12.2. 1(raebur 9114:2): foreach my $resource (@mapresources) {
1.557 raeburn 9115: my $parts;
1.554 raeburn 9116: my $ressymb = $resource->symb();
1.557 raeburn 9117: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
9118: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
9119: (my $analysis,$parts) =
1.596.2.12.2. (raeburn 9120:): &scantron_partids_tograde($resource,$env{'request.course.id'},
9121:): $username,$domain,undef,
9122:): $bubbles_per_row);
1.557 raeburn 9123: } else {
9124: $parts = $grader_partids_by_symb{$ressymb};
9125: }
1.542 raeburn 9126: ($counter,my $recording) =
9127: &verify_scantron_grading($resource,$domain,$username,$cid,$counter,
1.554 raeburn 9128: $scandata{$pid},$parts,
1.596.2.12.2. 6(raebur 9129:3): \%scantron_config,\%lettdig,$numletts,
9130:3): $randomorder,$randompick,
9131:3): \%respnumlookup,\%startline);
1.542 raeburn 9132: $record{$pid} .= $recording;
1.523 raeburn 9133: }
9134: }
9135: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
9136: $r->print('<br />');
9137: my ($okstudents,$badstudents,$numstudents,$passed,$failed);
9138: $passed = 0;
9139: $failed = 0;
9140: $numstudents = 0;
9141: foreach my $last (sort(keys(%bylast))) {
9142: if (ref($bylast{$last}) eq 'ARRAY') {
9143: foreach my $pid (sort(@{$bylast{$last}})) {
9144: my $showscandata = $scandata{$pid};
9145: my $showrecord = $record{$pid};
9146: $showscandata =~ s/\s/ /g;
9147: $showrecord =~ s/\s/ /g;
9148: if ($scandata{$pid} eq $record{$pid}) {
9149: my $css_class = ($passed % 2)?'LC_odd_row':'LC_even_row';
9150: $okstudents .= '<tr class="'.$css_class.'">'.
1.581 www 9151: '<td>'.&mt('Bubblesheet').'</td><td>'.$showscandata.'</td><td rowspan="2">'.$last.'</td><td rowspan="2">'.$pid.'</td>'."\n".
1.523 raeburn 9152: '</tr>'."\n".
9153: '<tr class="'.$css_class.'">'."\n".
9154: '<td>Submissions</td><td>'.$showrecord.'</td></tr>'."\n";
9155: $passed ++;
9156: } else {
9157: my $css_class = ($failed % 2)?'LC_odd_row':'LC_even_row';
1.581 www 9158: $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 9159: '</tr>'."\n".
9160: '<tr class="'.$css_class.'">'."\n".
9161: '<td>Submissions</td><td><span class="LC_nobreak">'.$record{$pid}.'</span></td>'."\n".
9162: '</tr>'."\n";
9163: $failed ++;
9164: }
9165: $numstudents ++;
9166: }
9167: }
9168: }
1.596.2.4 raeburn 9169: $r->print('<p>'.
1.596.2.8 raeburn 9170: &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 9171: '<b>',
9172: $numstudents,
9173: '</b>',
9174: $env{'form.scantron_maxbubble'}).
9175: '</p>'
9176: );
1.596.2.12.2. 2(raebur 9177:2): $r->print('<p>'
9178:2): .&mt('Exact matches for [_1][quant,_2,student][_3].','<b>',$passed,'</b>')
9179:2): .'<br />'
9180:2): .&mt('Discrepancies detected for [_1][quant,_2,student][_3].','<b>',$failed,'</b>')
9181:2): .'</p>');
1.523 raeburn 9182: if ($passed) {
1.572 www 9183: $r->print(&mt('Students with exact correspondence between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 9184: $r->print(&Apache::loncommon::start_data_table()."\n".
9185: &Apache::loncommon::start_data_table_header_row()."\n".
9186: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
9187: &Apache::loncommon::end_data_table_header_row()."\n".
9188: $okstudents."\n".
9189: &Apache::loncommon::end_data_table().'<br />');
9190: }
9191: if ($failed) {
1.572 www 9192: $r->print(&mt('Students with differences between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 9193: $r->print(&Apache::loncommon::start_data_table()."\n".
9194: &Apache::loncommon::start_data_table_header_row()."\n".
9195: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
9196: &Apache::loncommon::end_data_table_header_row()."\n".
9197: $badstudents."\n".
9198: &Apache::loncommon::end_data_table()).'<br />'.
1.572 www 9199: &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 9200: }
9201: $r->print('</form><br />'.$grading_menu_button);
9202: return;
9203: }
9204:
1.542 raeburn 9205: sub verify_scantron_grading {
1.554 raeburn 9206: my ($resource,$domain,$username,$cid,$counter,$scandata,$partids,
1.596.2.12.2. 6(raebur 9207:3): $scantron_config,$lettdig,$numletts,$randomorder,$randompick,
9208:3): $respnumlookup,$startline) = @_;
1.542 raeburn 9209: my ($record,%expected,%startpos);
9210: return ($counter,$record) if (!ref($resource));
9211: return ($counter,$record) if (!$resource->is_problem());
9212: my $symb = $resource->symb();
1.554 raeburn 9213: return ($counter,$record) if (ref($partids) ne 'ARRAY');
9214: foreach my $part_id (@{$partids}) {
1.542 raeburn 9215: $counter ++;
9216: $expected{$part_id} = 0;
1.596.2.12.2. 6(raebur 9217:3): my $respnum = $counter;
9218:3): if ($randomorder || $randompick) {
9219:3): $respnum = $respnumlookup->{$counter};
9220:3): $startpos{$part_id} = $startline->{$counter} + 1;
9221:3): } else {
9222:3): $startpos{$part_id} = $env{"form.scantron.first_bubble_line.$counter"};
9223:3): }
9224:3): if ($env{"form.scantron.sub_bubblelines.$respnum"}) {
9225:3): my @sub_lines = split(/,/,$env{"form.scantron.sub_bubblelines.$respnum"});
1.542 raeburn 9226: foreach my $item (@sub_lines) {
9227: $expected{$part_id} += $item;
9228: }
9229: } else {
1.596.2.12.2. 6(raebur 9230:3): $expected{$part_id} = $env{"form.scantron.bubblelines.$respnum"};
1.542 raeburn 9231: }
9232: }
9233: if ($symb) {
9234: my %recorded;
9235: my (%returnhash) = &Apache::lonnet::restore($symb,$cid,$domain,$username);
9236: if ($returnhash{'version'}) {
9237: my %lasthash=();
9238: my $version;
9239: for ($version=1;$version<=$returnhash{'version'};$version++) {
9240: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
9241: $lasthash{$key}=$returnhash{$version.':'.$key};
9242: }
9243: }
9244: foreach my $key (keys(%lasthash)) {
9245: if ($key =~ /\.scantron$/) {
9246: my $value = &unescape($lasthash{$key});
9247: my ($part_id) = ($key =~ /^resource\.(.+)\.scantron$/);
9248: if ($value eq '') {
9249: for (my $i=0; $i<$expected{$part_id}; $i++) {
9250: for (my $j=0; $j<$scantron_config->{'length'}; $j++) {
9251: $recorded{$part_id} .= $scantron_config->{'Qoff'};
9252: }
9253: }
9254: } else {
9255: my @tocheck;
9256: my @items = split(//,$value);
9257: if (($scantron_config->{'Qon'} eq 'letter') ||
9258: ($scantron_config->{'Qon'} eq 'number')) {
9259: if (@items < $expected{$part_id}) {
9260: my $fragment = substr($scandata,$startpos{$part_id},$expected{$part_id});
9261: my @singles = split(//,$fragment);
9262: foreach my $pos (@singles) {
9263: if ($pos eq ' ') {
9264: push(@tocheck,$pos);
9265: } else {
9266: my $next = shift(@items);
9267: push(@tocheck,$next);
9268: }
9269: }
9270: } else {
9271: @tocheck = @items;
9272: }
9273: foreach my $letter (@tocheck) {
9274: if ($scantron_config->{'Qon'} eq 'letter') {
9275: if ($letter !~ /^[A-J]$/) {
9276: $letter = $scantron_config->{'Qoff'};
9277: }
9278: $recorded{$part_id} .= $letter;
9279: } elsif ($scantron_config->{'Qon'} eq 'number') {
9280: my $digit;
9281: if ($letter !~ /^[A-J]$/) {
9282: $digit = $scantron_config->{'Qoff'};
9283: } else {
9284: $digit = $lettdig->{$letter};
9285: }
9286: $recorded{$part_id} .= $digit;
9287: }
9288: }
9289: } else {
9290: @tocheck = @items;
9291: for (my $i=0; $i<$expected{$part_id}; $i++) {
9292: my $curr_sub = shift(@tocheck);
9293: my $digit;
9294: if ($curr_sub =~ /^[A-J]$/) {
9295: $digit = $lettdig->{$curr_sub}-1;
9296: }
9297: if ($curr_sub eq 'J') {
9298: $digit += scalar($numletts);
9299: }
9300: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
9301: if ($j == $digit) {
9302: $recorded{$part_id} .= $scantron_config->{'Qon'};
9303: } else {
9304: $recorded{$part_id} .= $scantron_config->{'Qoff'};
9305: }
9306: }
9307: }
9308: }
9309: }
9310: }
9311: }
9312: }
1.554 raeburn 9313: foreach my $part_id (@{$partids}) {
1.542 raeburn 9314: if ($recorded{$part_id} eq '') {
9315: for (my $i=0; $i<$expected{$part_id}; $i++) {
9316: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
9317: $recorded{$part_id} .= $scantron_config->{'Qoff'};
9318: }
9319: }
9320: }
9321: $record .= $recorded{$part_id};
9322: }
9323: }
9324: return ($counter,$record);
9325: }
9326:
1.596.2.12.2. 6(raebur 9327:3): sub letter_to_digits {
1.542 raeburn 9328: my %lettdig = (
9329: A => 1,
9330: B => 2,
9331: C => 3,
9332: D => 4,
9333: E => 5,
9334: F => 6,
9335: G => 7,
9336: H => 8,
9337: I => 9,
9338: J => 0,
9339: );
9340: return %lettdig;
9341: }
9342:
1.423 albertel 9343:
1.75 albertel 9344: #-------- end of section for handling grading scantron forms -------
9345: #
9346: #-------------------------------------------------------------------
9347:
1.72 ng 9348: #-------------------------- Menu interface -------------------------
9349: #
9350: #--- Show a Grading Menu button - Calls the next routine ---
9351: sub show_grading_menu_form {
1.324 albertel 9352: my ($symb)=@_;
1.125 ng 9353: my $result.='<br /><form action="/adm/grades" method="post">'."\n".
1.418 albertel 9354: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 9355: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.72 ng 9356: '<input type="hidden" name="command" value="gradingmenu" />'."\n".
1.478 albertel 9357: '<input type="submit" name="submit" value="'.&mt('Grading Menu').'" />'."\n".
1.72 ng 9358: '</form>'."\n";
9359: return $result;
9360: }
9361:
1.77 ng 9362: # -- Retrieve choices for grading form
9363: sub savedState {
9364: my %savedState = ();
1.257 albertel 9365: if ($env{'form.saveState'}) {
9366: foreach (split(/:/,$env{'form.saveState'})) {
1.77 ng 9367: my ($key,$value) = split(/=/,$_,2);
9368: $savedState{$key} = $value;
9369: }
9370: }
9371: return \%savedState;
9372: }
1.76 ng 9373:
1.596.2.12.2. (raeburn 9374:): #--- Href with symb and command ---
9375:):
9376:): sub href_symb_cmd {
9377:): my ($symb,$cmd)=@_;
9378:): return '/adm/grades?symb='.&HTML::Entities::encode(&Apache::lonenc::check_encrypt($symb),'<>&"').'&command='.$cmd;
9379:): }
9380:):
1.443 banghart 9381: sub grading_menu {
9382: my ($request) = @_;
9383: my ($symb)=&get_symb($request);
9384: if (!$symb) {return '';}
9385: my $probTitle = &Apache::lonnet::gettitle($symb);
9386: my ($table,undef,$hdgrade) = &showResourceInfo($symb,$probTitle);
9387:
1.444 banghart 9388: $request->print($table);
1.443 banghart 9389: my %fields = ('symb'=>&Apache::lonenc::check_encrypt($symb),
9390: 'handgrade'=>$hdgrade,
9391: 'probTitle'=>$probTitle,
9392: 'command'=>'submit_options',
9393: 'saveState'=>"",
9394: 'gradingMenu'=>1,
9395: 'showgrading'=>"yes");
1.538 schulted 9396:
9397: my $url1 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
9398:
1.443 banghart 9399: $fields{'command'} = 'csvform';
1.538 schulted 9400: my $url2 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
9401:
1.443 banghart 9402: $fields{'command'} = 'processclicker';
1.538 schulted 9403: my $url3 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
9404:
1.443 banghart 9405: $fields{'command'} = 'scantron_selectphase';
1.538 schulted 9406: my $url4 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
9407:
9408: my @menu = ({ categorytitle=>'Course Grading',
9409: items =>[
9410: { linktext => 'Manual Grading/View Submissions',
9411: url => $url1,
9412: permission => 'F',
9413: icon => 'edit-find-replace.png',
9414: linktitle => 'Start the process of hand grading submissions.'
9415: },
9416: { linktext => 'Upload Scores',
9417: url => $url2,
9418: permission => 'F',
9419: icon => 'uploadscores.png',
9420: linktitle => 'Specify a file containing the class scores for current resource.'
9421: },
9422: { linktext => 'Process Clicker',
9423: url => $url3,
9424: permission => 'F',
9425: icon => 'addClickerInfoFile.png',
9426: linktitle => 'Specify a file containing the clicker information for this resource.'
9427: },
1.587 raeburn 9428: { linktext => 'Grade/Manage/Review Bubblesheets',
1.538 schulted 9429: url => $url4,
9430: permission => 'F',
9431: icon => 'stat.png',
1.596.2.4 raeburn 9432: linktitle => 'Grade bubblesheet exams, upload/download bubblesheet data files, and review previously graded bubblesheet exams.'
1.538 schulted 9433: }
9434: ]
9435: });
9436:
9437: #$fields{'command'} = 'verify';
9438: #$url = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
1.443 banghart 9439: #
9440: # Create the menu
9441: my $Str;
1.444 banghart 9442: # $Str .= '<h2>'.&mt('Please select a grading task').'</h2>';
1.445 banghart 9443: $Str .= '<form method="post" action="" name="gradingMenu">';
9444: $Str .= '<input type="hidden" name="command" value="" />'.
9445: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
9446: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
1.476 albertel 9447: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.445 banghart 9448: '<input type="hidden" name="saveState" value="" />'."\n".
9449: '<input type="hidden" name="gradingMenu" value="1" />'."\n".
9450: '<input type="hidden" name="showgrading" value="yes" />'."\n";
9451:
1.538 schulted 9452: $Str .= Apache::lonhtmlcommon::generate_menu(@menu);
9453: #$menudata->{'jscript'}
1.584 bisitz 9454: $Str .='<hr /><input type="button" value="'.&mt('Verify Receipt No.').'" '.
1.589 bisitz 9455: ' onclick="javascript:checkChoice(document.forms.gradingMenu,\'5\',\'verify\')" '.
1.538 schulted 9456: ' /> '.
9457: &Apache::lonnet::recprefix($env{'request.course.id'}).
1.589 bisitz 9458: '-<input type="text" name="receipt" size="4" onchange="javascript:checkReceiptNo(this.form,\'OK\')" />';
1.538 schulted 9459:
1.444 banghart 9460: $Str .="</form>\n";
1.539 riegler 9461: my $receiptalert = &mt("Please enter a receipt number given by a student in the receipt box.");
1.443 banghart 9462: $request->print(<<GRADINGMENUJS);
9463: <script type="text/javascript" language="javascript">
9464: function checkChoice(formname,val,cmdx) {
9465: if (val <= 2) {
9466: var cmd = radioSelection(formname.radioChoice);
9467: var cmdsave = cmd;
9468: } else {
9469: cmd = cmdx;
9470: cmdsave = 'submission';
9471: }
9472: formname.command.value = cmd;
9473: if (val < 5) formname.submit();
9474: if (val == 5) {
1.458 banghart 9475: if (!checkReceiptNo(formname,'notOK')) {
9476: return false;
9477: } else {
9478: formname.submit();
9479: }
1.445 banghart 9480: }
9481: }
1.443 banghart 9482:
9483: function checkReceiptNo(formname,nospace) {
9484: var receiptNo = formname.receipt.value;
9485: var checkOpt = false;
9486: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
9487: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
9488: if (checkOpt) {
1.539 riegler 9489: alert("$receiptalert");
1.443 banghart 9490: formname.receipt.value = "";
9491: formname.receipt.focus();
9492: return false;
9493: }
9494: return true;
9495: }
9496: </script>
9497: GRADINGMENUJS
9498: &commonJSfunctions($request);
9499: return $Str;
9500: }
9501:
9502:
9503: #--- Displays the submissions first page -------
9504: sub submit_options {
1.72 ng 9505: my ($request) = @_;
1.324 albertel 9506: my ($symb)=&get_symb($request);
1.72 ng 9507: if (!$symb) {return '';}
1.76 ng 9508: my $probTitle = &Apache::lonnet::gettitle($symb);
1.72 ng 9509:
1.539 riegler 9510: my $receiptalert = &mt("Please enter a receipt number given by a student in the receipt box.");
1.72 ng 9511: $request->print(<<GRADINGMENUJS);
9512: <script type="text/javascript" language="javascript">
1.116 ng 9513: function checkChoice(formname,val,cmdx) {
9514: if (val <= 2) {
9515: var cmd = radioSelection(formname.radioChoice);
1.118 ng 9516: var cmdsave = cmd;
1.116 ng 9517: } else {
9518: cmd = cmdx;
1.118 ng 9519: cmdsave = 'submission';
1.116 ng 9520: }
9521: formname.command.value = cmd;
1.118 ng 9522: formname.saveState.value = "saveCmd="+cmdsave+":saveSec="+pullDownSelection(formname.section)+
1.145 albertel 9523: ":saveSub="+pullDownSelection(formname.submitonly)+":saveStatus="+pullDownSelection(formname.Status);
1.116 ng 9524: if (val < 5) formname.submit();
9525: if (val == 5) {
1.72 ng 9526: if (!checkReceiptNo(formname,'notOK')) { return false;}
9527: formname.submit();
9528: }
1.238 albertel 9529: if (val < 7) formname.submit();
1.72 ng 9530: }
9531:
9532: function checkReceiptNo(formname,nospace) {
9533: var receiptNo = formname.receipt.value;
9534: var checkOpt = false;
9535: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
9536: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
9537: if (checkOpt) {
1.539 riegler 9538: alert("$receiptalert");
1.72 ng 9539: formname.receipt.value = "";
9540: formname.receipt.focus();
9541: return false;
9542: }
9543: return true;
9544: }
9545: </script>
9546: GRADINGMENUJS
1.118 ng 9547: &commonJSfunctions($request);
1.324 albertel 9548: my ($table,undef,$hdgrade) = &showResourceInfo($symb,$probTitle);
1.473 albertel 9549: my $result;
1.76 ng 9550: my (undef,$sections) = &getclasslist('all','0');
1.77 ng 9551: my $savedState = &savedState();
1.118 ng 9552: my $saveCmd = ($$savedState{'saveCmd'} eq '' ? 'submission' : $$savedState{'saveCmd'});
1.77 ng 9553: my $saveSec = ($$savedState{'saveSec'} eq '' ? 'all' : $$savedState{'saveSec'});
1.118 ng 9554: my $saveSub = ($$savedState{'saveSub'} eq '' ? 'all' : $$savedState{'saveSub'});
1.77 ng 9555: my $saveStatus = ($$savedState{'saveStatus'} eq '' ? 'Active' : $$savedState{'saveStatus'});
1.72 ng 9556:
1.533 bisitz 9557: # Preselect sections
9558: my $selsec="";
9559: if (ref($sections)) {
9560: foreach my $section (sort(@$sections)) {
9561: $selsec.='<option value="'.$section.'" '.
9562: ($saveSec eq $section ? 'selected="selected"':'').'>'.$section.'</option>'."\n";
9563: }
9564: }
9565:
1.72 ng 9566: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.418 albertel 9567: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.72 ng 9568: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
9569: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.116 ng 9570: '<input type="hidden" name="command" value="" />'."\n".
1.77 ng 9571: '<input type="hidden" name="saveState" value="" />'."\n".
1.124 ng 9572: '<input type="hidden" name="gradingMenu" value="1" />'."\n".
1.72 ng 9573: '<input type="hidden" name="showgrading" value="yes" />'."\n";
9574:
1.472 albertel 9575: $result.='
1.533 bisitz 9576: <h2>
9577: '.&mt('Grade Current Resource').'
9578: </h2>
9579: <div>
9580: '.$table.'
9581: </div>
9582:
1.537 harmsja 9583: <div class="LC_columnSection">
9584:
1.533 bisitz 9585: <fieldset>
9586: <legend>
9587: '.&mt('Sections').'
9588: </legend>
9589: <select name="section" multiple="multiple" size="5">'."\n";
9590: $result.= $selsec;
1.401 albertel 9591: $result.= '<option value="all" '.($saveSec eq 'all' ? 'selected="selected"' : ''). '>all</option></select> ';
1.472 albertel 9592: $result.='
1.533 bisitz 9593: </fieldset>
1.537 harmsja 9594:
1.533 bisitz 9595: <fieldset>
9596: <legend>
9597: '.&mt('Groups').'
9598: </legend>
9599: '.&Apache::lonstatistics::GroupSelect('group','multiple',5).'
9600: </fieldset>
1.537 harmsja 9601:
1.533 bisitz 9602: <fieldset>
9603: <legend>
9604: '.&mt('Access Status').'
9605: </legend>
9606: '.&Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,5,undef,'mult').'
9607: </fieldset>
1.537 harmsja 9608:
1.533 bisitz 9609: <fieldset>
9610: <legend>
9611: '.&mt('Submission Status').'
9612: </legend>
9613: <select name="submitonly" size="5">
1.473 albertel 9614: <option value="yes" '. ($saveSub eq 'yes' ? 'selected="selected"' : '').'>'.&mt('with submissions').'</option>
9615: <option value="queued" '. ($saveSub eq 'queued' ? 'selected="selected"' : '').'>'.&mt('in grading queue').'</option>
9616: <option value="graded" '. ($saveSub eq 'graded' ? 'selected="selected"' : '').'>'.&mt('with ungraded submissions').'</option>
9617: <option value="incorrect" '.($saveSub eq 'incorrect' ? 'selected="selected"' : '').'>'.&mt('with incorrect submissions').'</option>
9618: <option value="all" '. ($saveSub eq 'all' ? 'selected="selected"' : '').'>'.&mt('with any status').'</option>
1.533 bisitz 9619: </select>
9620: </fieldset>
1.537 harmsja 9621:
1.533 bisitz 9622: </div>
9623:
9624: <br />
9625: <div>
9626: <div>
1.473 albertel 9627: <label>
9628: <input type="radio" name="radioChoice" value="submission" '.
9629: ($saveCmd eq 'submission' ? 'checked="checked"' : '').' /> '.
9630: &mt('Select individual students to grade and view submissions.').'
9631: </label>
9632: </div>
1.533 bisitz 9633: <div>
1.473 albertel 9634: <label>
9635: <input type="radio" name="radioChoice" value="viewgrades" '.
9636: ($saveCmd eq 'viewgrades' ? 'checked="checked"' : '').' /> '.
9637: &mt('Grade all selected students in a grading table.').'
9638: </label>
9639: </div>
1.533 bisitz 9640: <div>
1.589 bisitz 9641: <input type="button" onclick="javascript:checkChoice(this.form,\'2\');" value="'.&mt('Next').' →" />
1.473 albertel 9642: </div>
1.472 albertel 9643: </div>
1.533 bisitz 9644:
9645:
1.473 albertel 9646: <h2>
9647: '.&mt('Grade Complete Folder for One Student').'
9648: </h2>
1.533 bisitz 9649: <div>
9650: <div>
1.473 albertel 9651: <label>
9652: <input type="radio" name="radioChoice" value="pickStudentPage" '.
9653: ($saveCmd eq 'pickStudentPage' ? 'checked="checked"' : '').' /> '.
9654: &mt('The <b>complete</b> page/sequence/folder: For one student').'
9655: </label>
9656: </div>
1.533 bisitz 9657: <div>
1.589 bisitz 9658: <input type="button" onclick="javascript:checkChoice(this.form,\'2\');" value="'.&mt('Next').' →" />
1.473 albertel 9659: </div>
1.472 albertel 9660: </div>
9661: </form>';
1.499 albertel 9662: $result .= &show_grading_menu_form($symb);
1.44 ng 9663: return $result;
1.2 albertel 9664: }
9665:
1.285 albertel 9666: sub reset_perm {
9667: undef(%perm);
9668: }
9669:
9670: sub init_perm {
9671: &reset_perm();
1.300 albertel 9672: foreach my $test_perm ('vgr','mgr','opa') {
9673:
9674: my $scope = $env{'request.course.id'};
9675: if (!($perm{$test_perm}=&Apache::lonnet::allowed($test_perm,$scope))) {
9676:
9677: $scope .= '/'.$env{'request.course.sec'};
9678: if ( $perm{$test_perm}=
9679: &Apache::lonnet::allowed($test_perm,$scope)) {
9680: $perm{$test_perm.'_section'}=$env{'request.course.sec'};
9681: } else {
9682: delete($perm{$test_perm});
9683: }
1.285 albertel 9684: }
9685: }
9686: }
9687:
1.596.2.12.2. (raeburn 9688:): sub init_old_essays {
9689:): my ($symb,$apath,$adom,$aname) = @_;
9690:): if ($symb ne '') {
9691:): my %essays = &Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
9692:): if (keys(%essays) > 0) {
9693:): $old_essays{$symb} = \%essays;
9694:): }
9695:): }
9696:): return;
9697:): }
9698:):
9699:): sub reset_old_essays {
9700:): undef(%old_essays);
9701:): }
9702:):
1.400 www 9703: sub gather_clicker_ids {
1.408 albertel 9704: my %clicker_ids;
1.400 www 9705:
9706: my $classlist = &Apache::loncoursedata::get_classlist();
9707:
9708: # Set up a couple variables.
1.407 albertel 9709: my $username_idx = &Apache::loncoursedata::CL_SNAME();
9710: my $domain_idx = &Apache::loncoursedata::CL_SDOM();
1.438 www 9711: my $status_idx = &Apache::loncoursedata::CL_STATUS();
1.400 www 9712:
1.407 albertel 9713: foreach my $student (keys(%$classlist)) {
1.438 www 9714: if ($classlist->{$student}->[$status_idx] ne 'Active') { next; }
1.407 albertel 9715: my $username = $classlist->{$student}->[$username_idx];
9716: my $domain = $classlist->{$student}->[$domain_idx];
1.400 www 9717: my $clickers =
1.408 albertel 9718: (&Apache::lonnet::userenvironment($domain,$username,'clickers'))[1];
1.400 www 9719: foreach my $id (split(/\,/,$clickers)) {
1.414 www 9720: $id=~s/^[\#0]+//;
1.421 www 9721: $id=~s/[\-\:]//g;
1.407 albertel 9722: if (exists($clicker_ids{$id})) {
1.408 albertel 9723: $clicker_ids{$id}.=','.$username.':'.$domain;
1.400 www 9724: } else {
1.408 albertel 9725: $clicker_ids{$id}=$username.':'.$domain;
1.400 www 9726: }
9727: }
9728: }
1.407 albertel 9729: return %clicker_ids;
1.400 www 9730: }
9731:
1.402 www 9732: sub gather_adv_clicker_ids {
1.408 albertel 9733: my %clicker_ids;
1.402 www 9734: my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'};
9735: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
9736: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
1.409 albertel 9737: foreach my $element (sort(keys(%coursepersonnel))) {
1.402 www 9738: foreach my $person (split(/\,/,$coursepersonnel{$element})) {
9739: my ($puname,$pudom)=split(/\:/,$person);
9740: my $clickers =
1.408 albertel 9741: (&Apache::lonnet::userenvironment($pudom,$puname,'clickers'))[1];
1.405 www 9742: foreach my $id (split(/\,/,$clickers)) {
1.414 www 9743: $id=~s/^[\#0]+//;
1.421 www 9744: $id=~s/[\-\:]//g;
1.408 albertel 9745: if (exists($clicker_ids{$id})) {
9746: $clicker_ids{$id}.=','.$puname.':'.$pudom;
9747: } else {
9748: $clicker_ids{$id}=$puname.':'.$pudom;
9749: }
1.405 www 9750: }
1.402 www 9751: }
9752: }
1.407 albertel 9753: return %clicker_ids;
1.402 www 9754: }
9755:
1.413 www 9756: sub clicker_grading_parameters {
9757: return ('gradingmechanism' => 'scalar',
9758: 'upfiletype' => 'scalar',
9759: 'specificid' => 'scalar',
9760: 'pcorrect' => 'scalar',
9761: 'pincorrect' => 'scalar');
9762: }
9763:
1.400 www 9764: sub process_clicker {
9765: my ($r)=@_;
9766: my ($symb)=&get_symb($r);
9767: if (!$symb) {return '';}
9768: my $result=&checkforfile_js();
9769: $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
9770: my ($table) = &showResourceInfo($symb,$env{'form.probTitle'});
9771: $result.=$table;
9772: $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
9773: $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
1.538 schulted 9774: $result.=' <b>'.&mt('Specify a file containing the clicker information for this resource.').
9775: '</b></td></tr>'."\n";
1.596.2.4 raeburn 9776: $result.='<tr bgcolor="#ffffe6"><td>'."\n";
1.413 www 9777: # Attempt to restore parameters from last session, set defaults if not present
9778: my %Saveable_Parameters=&clicker_grading_parameters();
9779: &Apache::loncommon::restore_course_settings('grades_clicker',
9780: \%Saveable_Parameters);
9781: if (!$env{'form.pcorrect'}) { $env{'form.pcorrect'}=100; }
9782: if (!$env{'form.pincorrect'}) { $env{'form.pincorrect'}=100; }
9783: if (!$env{'form.gradingmechanism'}) { $env{'form.gradingmechanism'}='attendance'; }
9784: if (!$env{'form.upfiletype'}) { $env{'form.upfiletype'}='iclicker'; }
9785:
9786: my %checked;
1.521 www 9787: foreach my $gradingmechanism ('attendance','personnel','specific','given') {
1.413 www 9788: if ($env{'form.gradingmechanism'} eq $gradingmechanism) {
1.569 bisitz 9789: $checked{$gradingmechanism}=' checked="checked"';
1.413 www 9790: }
9791: }
9792:
1.400 www 9793: my $upload=&mt("Upload File");
9794: my $type=&mt("Type");
1.402 www 9795: my $attendance=&mt("Award points just for participation");
9796: my $personnel=&mt("Correctness determined from response by course personnel");
1.414 www 9797: my $specific=&mt("Correctness determined from response with clicker ID(s)");
1.521 www 9798: my $given=&mt("Correctness determined from given list of answers").' '.
9799: '<font size="-2"><tt>('.&mt("Provide comma-separated list. Use '*' for any answer correct, '-' for skip").')</tt></font>';
1.402 www 9800: my $pcorrect=&mt("Percentage points for correct solution");
9801: my $pincorrect=&mt("Percentage points for incorrect solution");
1.413 www 9802: my $selectform=&Apache::loncommon::select_form($env{'form.upfiletype'},'upfiletype',
1.596.2.1 raeburn 9803: {'iclicker' => 'i>clicker',
1.596.2.12.2. (raeburn 9804:): 'interwrite' => 'interwrite PRS',
9805:): 'turning' => 'Turning Technologies'});
1.418 albertel 9806: $symb = &Apache::lonenc::check_encrypt($symb);
1.400 www 9807: $result.=<<ENDUPFORM;
1.402 www 9808: <script type="text/javascript">
9809: function sanitycheck() {
9810: // Accept only integer percentages
9811: document.forms.gradesupload.pcorrect.value=Math.round(document.forms.gradesupload.pcorrect.value);
9812: document.forms.gradesupload.pincorrect.value=Math.round(document.forms.gradesupload.pincorrect.value);
9813: // Find out grading choice
9814: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
9815: if (document.forms.gradesupload.gradingmechanism[i].checked) {
9816: gradingchoice=document.forms.gradesupload.gradingmechanism[i].value;
9817: }
9818: }
9819: // By default, new choice equals user selection
9820: newgradingchoice=gradingchoice;
9821: // Not good to give more points for false answers than correct ones
9822: if (Math.round(document.forms.gradesupload.pcorrect.value)<Math.round(document.forms.gradesupload.pincorrect.value)) {
9823: document.forms.gradesupload.pcorrect.value=document.forms.gradesupload.pincorrect.value;
9824: }
9825: // If new choice is attendance only, and old choice was correctness-based, restore defaults
9826: if ((gradingchoice=='attendance') && (document.forms.gradesupload.waschecked.value!='attendance')) {
9827: document.forms.gradesupload.pcorrect.value=100;
9828: document.forms.gradesupload.pincorrect.value=100;
9829: }
9830: // If the values are different, cannot be attendance only
9831: if ((Math.round(document.forms.gradesupload.pcorrect.value)!=Math.round(document.forms.gradesupload.pincorrect.value)) &&
9832: (gradingchoice=='attendance')) {
9833: newgradingchoice='personnel';
9834: }
9835: // Change grading choice to new one
9836: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
9837: if (document.forms.gradesupload.gradingmechanism[i].value==newgradingchoice) {
9838: document.forms.gradesupload.gradingmechanism[i].checked=true;
9839: } else {
9840: document.forms.gradesupload.gradingmechanism[i].checked=false;
9841: }
9842: }
9843: // Remember the old state
9844: document.forms.gradesupload.waschecked.value=newgradingchoice;
9845: }
9846: </script>
1.400 www 9847: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
9848: <input type="hidden" name="symb" value="$symb" />
9849: <input type="hidden" name="command" value="processclickerfile" />
9850: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
9851: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
9852: <input type="file" name="upfile" size="50" />
9853: <br /><label>$type: $selectform</label>
1.589 bisitz 9854: <br /><label><input type="radio" name="gradingmechanism" value="attendance"$checked{'attendance'} onclick="sanitycheck()" />$attendance </label>
9855: <br /><label><input type="radio" name="gradingmechanism" value="personnel"$checked{'personnel'} onclick="sanitycheck()" />$personnel</label>
9856: <br /><label><input type="radio" name="gradingmechanism" value="specific"$checked{'specific'} onclick="sanitycheck()" />$specific </label>
1.414 www 9857: <input type="text" name="specificid" value="$env{'form.specificid'}" size="20" />
1.589 bisitz 9858: <br /><label><input type="radio" name="gradingmechanism" value="given"$checked{'given'} onclick="sanitycheck()" />$given </label>
1.521 www 9859: <br />
9860: <input type="text" name="givenanswer" size="50" />
1.413 www 9861: <input type="hidden" name="waschecked" value="$env{'form.gradingmechanism'}" />
1.589 bisitz 9862: <br /><label>$pcorrect: <input type="text" name="pcorrect" size="4" value="$env{'form.pcorrect'}" onchange="sanitycheck()" /></label>
9863: <br /><label>$pincorrect: <input type="text" name="pincorrect" size="4" value="$env{'form.pincorrect'}" onchange="sanitycheck()" /></label>
9864: <br /><input type="button" onclick="javascript:checkUpload(this.form);" value="$upload" />
1.400 www 9865: </form>
9866: ENDUPFORM
9867: $result.='</td></tr></table>'."\n".
9868: '</td></tr></table><br /><br />'."\n";
9869: $result.=&show_grading_menu_form($symb);
9870: return $result;
9871: }
9872:
9873: sub process_clicker_file {
9874: my ($r)=@_;
9875: my ($symb)=&get_symb($r);
9876: if (!$symb) {return '';}
1.413 www 9877:
9878: my %Saveable_Parameters=&clicker_grading_parameters();
9879: &Apache::loncommon::store_course_settings('grades_clicker',
9880: \%Saveable_Parameters);
9881:
1.400 www 9882: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.404 www 9883: if (($env{'form.gradingmechanism'} eq 'specific') && ($env{'form.specificid'}!~/\w/)) {
1.408 albertel 9884: $result.='<span class="LC_error">'.&mt('You need to specify a clicker ID for the correct answer').'</span>';
9885: return $result.&show_grading_menu_form($symb);
1.404 www 9886: }
1.522 www 9887: if (($env{'form.gradingmechanism'} eq 'given') && ($env{'form.givenanswer'}!~/\S/)) {
1.521 www 9888: $result.='<span class="LC_error">'.&mt('You need to specify the correct answer').'</span>';
9889: return $result.&show_grading_menu_form($symb);
9890: }
1.522 www 9891: my $foundgiven=0;
1.521 www 9892: if ($env{'form.gradingmechanism'} eq 'given') {
9893: $env{'form.givenanswer'}=~s/^\s*//gs;
9894: $env{'form.givenanswer'}=~s/\s*$//gs;
1.596.2.4 raeburn 9895: $env{'form.givenanswer'}=~s/[^a-zA-Z0-9\.\*\-\+]+/\,/g;
1.521 www 9896: $env{'form.givenanswer'}=uc($env{'form.givenanswer'});
1.522 www 9897: my @answers=split(/\,/,$env{'form.givenanswer'});
9898: $foundgiven=$#answers+1;
1.521 www 9899: }
1.407 albertel 9900: my %clicker_ids=&gather_clicker_ids();
1.408 albertel 9901: my %correct_ids;
1.404 www 9902: if ($env{'form.gradingmechanism'} eq 'personnel') {
1.408 albertel 9903: %correct_ids=&gather_adv_clicker_ids();
1.404 www 9904: }
9905: if ($env{'form.gradingmechanism'} eq 'specific') {
1.414 www 9906: foreach my $correct_id (split(/[\s\,]/,$env{'form.specificid'})) {;
9907: $correct_id=~tr/a-z/A-Z/;
9908: $correct_id=~s/\s//gs;
9909: $correct_id=~s/^[\#0]+//;
1.421 www 9910: $correct_id=~s/[\-\:]//g;
1.414 www 9911: if ($correct_id) {
9912: $correct_ids{$correct_id}='specified';
9913: }
9914: }
1.400 www 9915: }
1.404 www 9916: if ($env{'form.gradingmechanism'} eq 'attendance') {
1.408 albertel 9917: $result.=&mt('Score based on attendance only');
1.521 www 9918: } elsif ($env{'form.gradingmechanism'} eq 'given') {
1.522 www 9919: $result.=&mt('Score based on [_1] ([_2] answers)','<tt>'.$env{'form.givenanswer'}.'</tt>',$foundgiven);
1.404 www 9920: } else {
1.408 albertel 9921: my $number=0;
1.411 www 9922: $result.='<p><b>'.&mt('Correctness determined by the following IDs').'</b>';
1.408 albertel 9923: foreach my $id (sort(keys(%correct_ids))) {
1.411 www 9924: $result.='<br /><tt>'.$id.'</tt> - ';
1.408 albertel 9925: if ($correct_ids{$id} eq 'specified') {
9926: $result.=&mt('specified');
9927: } else {
9928: my ($uname,$udom)=split(/\:/,$correct_ids{$id});
9929: $result.=&Apache::loncommon::plainname($uname,$udom);
9930: }
9931: $number++;
9932: }
1.411 www 9933: $result.="</p>\n";
1.408 albertel 9934: if ($number==0) {
9935: $result.='<span class="LC_error">'.&mt('No IDs found to determine correct answer').'</span>';
9936: return $result.&show_grading_menu_form($symb);
9937: }
1.404 www 9938: }
1.405 www 9939: if (length($env{'form.upfile'}) < 2) {
1.407 albertel 9940: $result.=&mt('[_1] Error: [_2] The file you attempted to upload, [_3] contained no information. Please check that you entered the correct filename.',
9941: '<span class="LC_error">',
9942: '</span>',
9943: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>');
1.405 www 9944: return $result.&show_grading_menu_form($symb);
9945: }
1.410 www 9946:
9947: # Were able to get all the info needed, now analyze the file
9948:
1.411 www 9949: $result.=&Apache::loncommon::studentbrowser_javascript();
1.418 albertel 9950: $symb = &Apache::lonenc::check_encrypt($symb);
1.410 www 9951: my $heading=&mt('Scanning clicker file');
9952: $result.=(<<ENDHEADER);
9953: <br /><table width="100%" border="0"><tr><td bgcolor="#777777">
9954: <table width="100%" border="0"><tr bgcolor="#e6ffff"><td>
1.596.2.4 raeburn 9955: <b>$heading</b></td></tr><tr bgcolor="#ffffe6"><td>
1.410 www 9956: <form method="post" action="/adm/grades" name="clickeranalysis">
9957: <input type="hidden" name="symb" value="$symb" />
9958: <input type="hidden" name="command" value="assignclickergrades" />
9959: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
9960: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
1.411 www 9961: <input type="hidden" name="gradingmechanism" value="$env{'form.gradingmechanism'}" />
9962: <input type="hidden" name="pcorrect" value="$env{'form.pcorrect'}" />
9963: <input type="hidden" name="pincorrect" value="$env{'form.pincorrect'}" />
1.410 www 9964: ENDHEADER
1.522 www 9965: if ($env{'form.gradingmechanism'} eq 'given') {
9966: $result.='<input type="hidden" name="correct:given" value="'.$env{'form.givenanswer'}.'" />';
9967: }
1.408 albertel 9968: my %responses;
9969: my @questiontitles;
1.405 www 9970: my $errormsg='';
9971: my $number=0;
9972: if ($env{'form.upfiletype'} eq 'iclicker') {
1.408 albertel 9973: ($errormsg,$number)=&iclicker_eval(\@questiontitles,\%responses);
1.406 www 9974: }
1.419 www 9975: if ($env{'form.upfiletype'} eq 'interwrite') {
9976: ($errormsg,$number)=&interwrite_eval(\@questiontitles,\%responses);
9977: }
1.596.2.12.2. (raeburn 9978:): if ($env{'form.upfiletype'} eq 'turning') {
9979:): ($errormsg,$number)=&turning_eval(\@questiontitles,\%responses);
9980:): }
1.411 www 9981: $result.='<br />'.&mt('Found [_1] question(s)',$number).'<br />'.
9982: '<input type="hidden" name="number" value="'.$number.'" />'.
9983: &mt('Awarding [_1] percent for correct and [_2] percent for incorrect responses',
9984: $env{'form.pcorrect'},$env{'form.pincorrect'}).
9985: '<br />';
1.522 www 9986: if (($env{'form.gradingmechanism'} eq 'given') && ($number!=$foundgiven)) {
9987: $result.='<span class="LC_error">'.&mt('Number of given answers does not agree with number of questions in file.').'</span>';
9988: return $result.&show_grading_menu_form($symb);
9989: }
1.414 www 9990: # Remember Question Titles
9991: # FIXME: Possibly need delimiter other than ":"
9992: for (my $i=0;$i<$number;$i++) {
9993: $result.='<input type="hidden" name="question:'.$i.'" value="'.
9994: &HTML::Entities::encode($questiontitles[$i],'"&<>').'" />';
9995: }
1.411 www 9996: my $correct_count=0;
9997: my $student_count=0;
9998: my $unknown_count=0;
1.414 www 9999: # Match answers with usernames
10000: # FIXME: Possibly need delimiter other than ":"
1.409 albertel 10001: foreach my $id (keys(%responses)) {
1.410 www 10002: if ($correct_ids{$id}) {
1.414 www 10003: $result.="\n".'<input type="hidden" name="correct:'.$correct_count.':'.$correct_ids{$id}.'" value="'.$responses{$id}.'" />';
1.411 www 10004: $correct_count++;
1.410 www 10005: } elsif ($clicker_ids{$id}) {
1.437 www 10006: if ($clicker_ids{$id}=~/\,/) {
10007: # More than one user with the same clicker!
10008: $result.="\n<hr />".&mt('Clicker registered more than once').": <tt>".$id."</tt><br />";
10009: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
10010: "<select name='multi".$id."'>";
10011: foreach my $reguser (sort(split(/\,/,$clicker_ids{$id}))) {
10012: $result.="<option value='".$reguser."'>".&Apache::loncommon::plainname(split(/\:/,$reguser)).' ('.$reguser.')</option>';
10013: }
10014: $result.='</select>';
10015: $unknown_count++;
10016: } else {
10017: # Good: found one and only one user with the right clicker
10018: $result.="\n".'<input type="hidden" name="student:'.$clicker_ids{$id}.'" value="'.$responses{$id}.'" />';
10019: $student_count++;
10020: }
1.410 www 10021: } else {
1.411 www 10022: $result.="\n<hr />".&mt('Unregistered Clicker')." <tt>".$id."</tt><br />";
10023: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
10024: "\n".&mt("Username").": <input type='text' name='uname".$id."' /> ".
10025: "\n".&mt("Domain").": ".
10026: &Apache::loncommon::select_dom_form($env{'course.'.$env{'request.course.id'}.'.domain'},'udom'.$id).' '.
1.596.2.4 raeburn 10027: &Apache::loncommon::selectstudent_link('clickeranalysis','uname'.$id,'udom'.$id,0,$id);
1.411 www 10028: $unknown_count++;
1.410 www 10029: }
1.405 www 10030: }
1.412 www 10031: $result.='<hr />'.
10032: &mt('Found [_1] registered and [_2] unregistered clickers.',$student_count,$unknown_count);
1.521 www 10033: if (($env{'form.gradingmechanism'} ne 'attendance') && ($env{'form.gradingmechanism'} ne 'given')) {
1.412 www 10034: if ($correct_count==0) {
10035: $errormsg.="Found no correct answers answers for grading!";
10036: } elsif ($correct_count>1) {
1.414 www 10037: $result.='<br /><span class="LC_warning">'.&mt("Found [_1] entries for grading!",$correct_count).'</span>';
1.412 www 10038: }
10039: }
1.428 www 10040: if ($number<1) {
10041: $errormsg.="Found no questions.";
10042: }
1.412 www 10043: if ($errormsg) {
10044: $result.='<br /><span class="LC_error">'.&mt($errormsg).'</span>';
10045: } else {
10046: $result.='<br /><input type="submit" name="finalize" value="'.&mt('Finalize Grading').'" />';
10047: }
10048: $result.='</form></td></tr></table>'."\n".
1.410 www 10049: '</td></tr></table><br /><br />'."\n";
1.404 www 10050: return $result.&show_grading_menu_form($symb);
1.400 www 10051: }
10052:
1.405 www 10053: sub iclicker_eval {
1.406 www 10054: my ($questiontitles,$responses)=@_;
1.405 www 10055: my $number=0;
10056: my $errormsg='';
10057: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
1.410 www 10058: my %components=&Apache::loncommon::record_sep($line);
10059: my @entries=map {$components{$_}} (sort(keys(%components)));
1.408 albertel 10060: if ($entries[0] eq 'Question') {
10061: for (my $i=3;$i<$#entries;$i+=6) {
10062: $$questiontitles[$number]=$entries[$i];
10063: $number++;
10064: }
10065: }
10066: if ($entries[0]=~/^\#/) {
10067: my $id=$entries[0];
10068: my @idresponses;
10069: $id=~s/^[\#0]+//;
10070: for (my $i=0;$i<$number;$i++) {
10071: my $idx=3+$i*6;
1.596.2.4 raeburn 10072: $entries[$idx]=~s/[^a-zA-Z0-9\.\*\-\+]+//g;
1.408 albertel 10073: push(@idresponses,$entries[$idx]);
10074: }
10075: $$responses{$id}=join(',',@idresponses);
10076: }
1.405 www 10077: }
10078: return ($errormsg,$number);
10079: }
10080:
1.419 www 10081: sub interwrite_eval {
10082: my ($questiontitles,$responses)=@_;
10083: my $number=0;
10084: my $errormsg='';
1.420 www 10085: my $skipline=1;
10086: my $questionnumber=0;
10087: my %idresponses=();
1.419 www 10088: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
10089: my %components=&Apache::loncommon::record_sep($line);
10090: my @entries=map {$components{$_}} (sort(keys(%components)));
1.420 www 10091: if ($entries[1] eq 'Time') { $skipline=0; next; }
10092: if ($entries[1] eq 'Response') { $skipline=1; }
10093: next if $skipline;
10094: if ($entries[0]!=$questionnumber) {
10095: $questionnumber=$entries[0];
10096: $$questiontitles[$number]=&mt('Question [_1]',$questionnumber);
10097: $number++;
1.419 www 10098: }
1.420 www 10099: my $id=$entries[4];
10100: $id=~s/^[\#0]+//;
1.421 www 10101: $id=~s/^v\d*\://i;
10102: $id=~s/[\-\:]//g;
1.420 www 10103: $idresponses{$id}[$number]=$entries[6];
10104: }
1.524 raeburn 10105: foreach my $id (keys(%idresponses)) {
1.420 www 10106: $$responses{$id}=join(',',@{$idresponses{$id}});
10107: $$responses{$id}=~s/^\s*\,//;
1.419 www 10108: }
10109: return ($errormsg,$number);
10110: }
10111:
1.596.2.12.2. (raeburn 10112:): sub turning_eval {
10113:): my ($questiontitles,$responses)=@_;
10114:): my $number=0;
10115:): my $errormsg='';
10116:): foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
10117:): my %components=&Apache::loncommon::record_sep($line);
10118:): my @entries=map {$components{$_}} (sort(keys(%components)));
10119:): if ($#entries>$number) { $number=$#entries; }
10120:): my $id=$entries[0];
10121:): my @idresponses;
10122:): $id=~s/^[\#0]+//;
10123:): unless ($id) { next; }
10124:): for (my $idx=1;$idx<=$#entries;$idx++) {
10125:): $entries[$idx]=~s/\,/\;/g;
10126:): $entries[$idx]=~s/[^a-zA-Z0-9\.\*\-\+\;]+//g;
10127:): push(@idresponses,$entries[$idx]);
10128:): }
10129:): $$responses{$id}=join(',',@idresponses);
10130:): }
10131:): for (my $i=1; $i<=$number; $i++) {
10132:): $$questiontitles[$i]=&mt('Question [_1]',$i);
10133:): }
10134:): return ($errormsg,$number);
10135:): }
10136:):
1.414 www 10137: sub assign_clicker_grades {
10138: my ($r)=@_;
10139: my ($symb)=&get_symb($r);
10140: if (!$symb) {return '';}
1.416 www 10141: # See which part we are saving to
1.582 raeburn 10142: my $res_error;
10143: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
10144: if ($res_error) {
10145: return &navmap_errormsg();
10146: }
1.416 www 10147: # FIXME: This should probably look for the first handgradeable part
10148: my $part=$$partlist[0];
10149: # Start screen output
1.596.2.10 raeburn 10150: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.596.2.4 raeburn 10151:
1.596.2.10 raeburn 10152: $result .= '<br />'.
10153: &Apache::loncommon::start_data_table().
1.596.2.4 raeburn 10154: &Apache::loncommon::start_data_table_header_row().
10155: '<th>'.&mt('Assigning grades based on clicker file').'</th>'.
10156: &Apache::loncommon::end_data_table_header_row().
10157: &Apache::loncommon::start_data_table_row().'<td>';
1.416 www 10158:
1.414 www 10159: # Get correct result
10160: # FIXME: Possibly need delimiter other than ":"
10161: my @correct=();
1.415 www 10162: my $gradingmechanism=$env{'form.gradingmechanism'};
10163: my $number=$env{'form.number'};
10164: if ($gradingmechanism ne 'attendance') {
1.414 www 10165: foreach my $key (keys(%env)) {
10166: if ($key=~/^form\.correct\:/) {
10167: my @input=split(/\,/,$env{$key});
10168: for (my $i=0;$i<=$#input;$i++) {
10169: if (($correct[$i]) && ($input[$i]) &&
10170: ($correct[$i] ne $input[$i])) {
10171: $result.='<br /><span class="LC_warning">'.
10172: &mt('More than one correct result given for question "[_1]": [_2] versus [_3].',
10173: $env{'form.question:'.$i},$correct[$i],$input[$i]).'</span>';
1.596.2.4 raeburn 10174: } elsif (($input[$i]) || ($input[$i] eq '0')) {
1.414 www 10175: $correct[$i]=$input[$i];
10176: }
10177: }
10178: }
10179: }
1.415 www 10180: for (my $i=0;$i<$number;$i++) {
1.596.2.4 raeburn 10181: if ((!$correct[$i]) && ($correct[$i] ne '0')) {
1.414 www 10182: $result.='<br /><span class="LC_error">'.
10183: &mt('No correct result given for question "[_1]"!',
10184: $env{'form.question:'.$i}).'</span>';
10185: }
10186: }
1.596.2.4 raeburn 10187: $result.='<br />'.&mt("Correct answer: [_1]",join(', ',map { ((($_) || ($_ eq '0'))?$_:'-') } @correct));
1.414 www 10188: }
10189: # Start grading
1.415 www 10190: my $pcorrect=$env{'form.pcorrect'};
10191: my $pincorrect=$env{'form.pincorrect'};
1.416 www 10192: my $storecount=0;
1.596.2.4 raeburn 10193: my %users=();
1.415 www 10194: foreach my $key (keys(%env)) {
1.420 www 10195: my $user='';
1.415 www 10196: if ($key=~/^form\.student\:(.*)$/) {
1.420 www 10197: $user=$1;
10198: }
10199: if ($key=~/^form\.unknown\:(.*)$/) {
10200: my $id=$1;
10201: if (($env{'form.uname'.$id}) && ($env{'form.udom'.$id})) {
10202: $user=$env{'form.uname'.$id}.':'.$env{'form.udom'.$id};
1.437 www 10203: } elsif ($env{'form.multi'.$id}) {
10204: $user=$env{'form.multi'.$id};
1.420 www 10205: }
10206: }
1.596.2.4 raeburn 10207: if ($user) {
10208: if ($users{$user}) {
10209: $result.='<br /><span class="LC_warning">'.
10210: &mt("More than one entry found for <tt>[_1]</tt>!",$user).
10211: '</span><br />';
10212: }
10213: $users{$user}=1;
1.415 www 10214: my @answer=split(/\,/,$env{$key});
10215: my $sum=0;
1.522 www 10216: my $realnumber=$number;
1.415 www 10217: for (my $i=0;$i<$number;$i++) {
1.576 www 10218: if ($correct[$i] eq '-') {
10219: $realnumber--;
10220: } elsif ($answer[$i]) {
1.415 www 10221: if ($gradingmechanism eq 'attendance') {
10222: $sum+=$pcorrect;
1.576 www 10223: } elsif ($correct[$i] eq '*') {
1.522 www 10224: $sum+=$pcorrect;
1.415 www 10225: } else {
1.596.2.4 raeburn 10226: # We actually grade if correct or not
10227: my $increment=$pincorrect;
10228: # Special case: numerical answer "0"
10229: if ($correct[$i] eq '0') {
10230: if ($answer[$i]=~/^[0\.]+$/) {
10231: $increment=$pcorrect;
10232: }
10233: # General numerical answer, both evaluate to something non-zero
10234: } elsif ((1.0*$correct[$i]!=0) && (1.0*$answer[$i]!=0)) {
10235: if (1.0*$correct[$i]==1.0*$answer[$i]) {
10236: $increment=$pcorrect;
10237: }
10238: # Must be just alphanumeric
10239: } elsif ($answer[$i] eq $correct[$i]) {
10240: $increment=$pcorrect;
1.415 www 10241: }
1.596.2.4 raeburn 10242: $sum+=$increment;
1.415 www 10243: }
10244: }
10245: }
1.522 www 10246: my $ave=$sum/(100*$realnumber);
1.416 www 10247: # Store
10248: my ($username,$domain)=split(/\:/,$user);
10249: my %grades=();
10250: $grades{"resource.$part.solved"}='correct_by_override';
10251: $grades{"resource.$part.awarded"}=$ave;
10252: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
10253: my $returncode=&Apache::lonnet::cstore(\%grades,$symb,
10254: $env{'request.course.id'},
10255: $domain,$username);
10256: if ($returncode ne 'ok') {
10257: $result.="<br /><span class=\"LC_error\">Failed to save student $username:$domain. Message when trying to save was ($returncode)</span>";
10258: } else {
10259: $storecount++;
10260: }
1.415 www 10261: }
10262: }
10263: # We are done
1.549 hauer 10264: $result.='<br />'.&mt('Successfully stored grades for [quant,_1,student].',$storecount).
1.596.2.4 raeburn 10265: '</td>'.
10266: &Apache::loncommon::end_data_table_row().
10267: &Apache::loncommon::end_data_table()."<br /><br />\n";
1.414 www 10268: return $result.&show_grading_menu_form($symb);
10269: }
10270:
1.582 raeburn 10271: sub navmap_errormsg {
10272: return '<div class="LC_error">'.
10273: &mt('An error occurred retrieving information about resources in the course.').'<br />'.
1.595 raeburn 10274: &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 10275: '</div>';
10276: }
10277:
1.596.2.12.2. (raeburn 10278:): sub startpage {
10279:): my ($r,$symb,$crumbs,$onlyfolderflag,$nodisplayflag,$stuvcurrent,$stuvdisp,$nomenu,$js) = @_;
10280:): if ($nomenu) {
10281:): $r->print(&Apache::loncommon::start_page("Student's Version",$js,{'only_body' => '1'}));
10282:): } else {
10283:): $r->print(&Apache::loncommon::start_page('Grading',$js,
10284:): {'bread_crumbs' => $crumbs}));
10285:): }
10286:): unless ($nodisplayflag) {
10287:): $r->print(&Apache::lonhtmlcommon::resource_info_box($symb,$onlyfolderflag,$stuvcurrent,$stuvdisp));
10288:): }
10289:): }
10290:):
1.1 albertel 10291: sub handler {
1.41 ng 10292: my $request=$_[0];
1.434 albertel 10293: &reset_caches();
1.596.2.4 raeburn 10294: if ($request->header_only) {
10295: &Apache::loncommon::content_type($request,'text/html');
10296: $request->send_http_header;
10297: return OK;
1.41 ng 10298: }
10299: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.596.2.4 raeburn 10300:
1.324 albertel 10301: my $symb=&get_symb($request,1);
1.160 albertel 10302: my @commands=&Apache::loncommon::get_env_multiple('form.command');
10303: my $command=$commands[0];
1.447 foxr 10304:
1.160 albertel 10305: if ($#commands > 0) {
10306: &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands));
10307: }
1.447 foxr 10308:
1.513 foxr 10309: $ssi_error = 0;
1.535 raeburn 10310: my $brcrum = [{href=>"/adm/grades",text=>"Grading"}];
1.596.2.4 raeburn 10311: my $start_page = &Apache::loncommon::start_page('Grading',undef,
1.596.2.12.2. (raeburn 10312:): {'bread_crumbs' => $brcrum});
1.324 albertel 10313: if ($symb eq '' && $command eq '') {
1.257 albertel 10314: if ($env{'user.adv'}) {
1.596.2.4 raeburn 10315: &Apache::loncommon::content_type($request,'text/html');
10316: $request->send_http_header;
10317: $request->print($start_page);
1.257 albertel 10318: if (($env{'form.codeone'}) && ($env{'form.codetwo'}) &&
10319: ($env{'form.codethree'})) {
10320: my $token=$env{'form.codeone'}.'*'.$env{'form.codetwo'}.'*'.
10321: $env{'form.codethree'};
1.41 ng 10322: my ($tsymb,$tuname,$tudom,$tcrsid)=
10323: &Apache::lonnet::checkin($token);
10324: if ($tsymb) {
1.137 albertel 10325: my ($map,$id,$url)=&Apache::lonnet::decode_symb($tsymb);
1.41 ng 10326: if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
1.513 foxr 10327: $request->print(&ssi_with_retries('/res/'.$url, $ssi_retries,
1.99 albertel 10328: ('grade_username' => $tuname,
10329: 'grade_domain' => $tudom,
10330: 'grade_courseid' => $tcrsid,
10331: 'grade_symb' => $tsymb)));
1.41 ng 10332: } else {
1.45 ng 10333: $request->print('<h3>Not authorized: '.$token.'</h3>');
1.99 albertel 10334: }
1.41 ng 10335: } else {
1.45 ng 10336: $request->print('<h3>Not a valid DocID: '.$token.'</h3>');
1.41 ng 10337: }
1.14 www 10338: } else {
1.41 ng 10339: $request->print(&Apache::lonxml::tokeninputfield());
10340: }
1.596.2.4 raeburn 10341: } elsif ($env{'request.course.id'}) {
10342: &init_perm();
10343: if (!%perm) {
10344: $request->internal_redirect('/adm/quickgrades');
1.596.2.12.2. 3(raebur 10345:3): return OK;
1.596.2.4 raeburn 10346: } else {
10347: &Apache::loncommon::content_type($request,'text/html');
10348: $request->send_http_header;
10349: $request->print($start_page);
10350: }
10351: }
1.41 ng 10352: } else {
1.596.2.4 raeburn 10353: &init_perm();
10354: if (!$env{'request.course.id'}) {
1.596.2.11 raeburn 10355: unless ((&Apache::lonnet::allowed('usc',$env{'request.role.domain'})) &&
10356: ($command =~ /^scantronupload/)) {
10357: # Not in a course.
10358: $env{'user.error.msg'}="/adm/grades::vgr:0:0:Cannot display grades page outside course context";
10359: return HTTP_NOT_ACCEPTABLE;
10360: }
1.596.2.4 raeburn 10361: } elsif (!%perm) {
10362: $request->internal_redirect('/adm/quickgrades');
10363: }
10364: &Apache::loncommon::content_type($request,'text/html');
10365: $request->send_http_header;
1.596.2.12.2. (raeburn 10366:): unless ((($command eq 'submission' || $command eq 'versionsub')) && ($perm{'vgr'})) {
10367:): $request->print($start_page);
10368:): }
1.104 albertel 10369: if ($command eq 'submission' && $perm{'vgr'}) {
1.596.2.12.2. (raeburn 10370:): my ($stuvcurrent,$stuvdisp,$versionform,$js);
10371:): if (($env{'form.student'} ne '') && ($env{'form.userdom'} ne '')) {
10372:): ($stuvcurrent,$stuvdisp,$versionform,$js) =
10373:): &choose_task_version_form($symb,$env{'form.student'},
10374:): $env{'form.userdom'});
10375:): }
10376:): &startpage($request,$symb,[{href=>"", text=>"Student Submissions"}],undef,undef,$stuvcurrent,$stuvdisp,undef,$js);
10377:): if ($versionform) {
10378:): $request->print($versionform);
10379:): }
10380:): $request->print('<br clear="all" />');
1.257 albertel 10381: ($env{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0));
1.596.2.12.2. (raeburn 10382:): } elsif ($command eq 'versionsub' && $perm{'vgr'}) {
10383:): my ($stuvcurrent,$stuvdisp,$versionform,$js) =
10384:): &choose_task_version_form($symb,$env{'form.student'},
10385:): $env{'form.userdom'},
10386:): $env{'form.inhibitmenu'});
10387:): &startpage($request,$symb,[{href=>"", text=>"Previous Student Version"}],undef,undef,$stuvcurrent,$stuvdisp,$env{'form.inhibitmenu'},$js);
10388:): if ($versionform) {
10389:): $request->print($versionform);
10390:): }
10391:): $request->print('<br clear="all" />');
10392:): $request->print(&show_previous_task_version($request,$symb));
1.103 albertel 10393: } elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) {
1.68 ng 10394: &pickStudentPage($request);
1.103 albertel 10395: } elsif ($command eq 'displayPage' && $perm{'vgr'}) {
1.68 ng 10396: &displayPage($request);
1.104 albertel 10397: } elsif ($command eq 'gradeByPage' && $perm{'mgr'}) {
1.71 ng 10398: &updateGradeByPage($request);
1.104 albertel 10399: } elsif ($command eq 'processGroup' && $perm{'vgr'}) {
1.41 ng 10400: &processGroup($request);
1.104 albertel 10401: } elsif ($command eq 'gradingmenu' && $perm{'vgr'}) {
1.443 banghart 10402: $request->print(&grading_menu($request));
10403: } elsif ($command eq 'submit_options' && $perm{'vgr'}) {
10404: $request->print(&submit_options($request));
1.104 albertel 10405: } elsif ($command eq 'viewgrades' && $perm{'vgr'}) {
1.41 ng 10406: $request->print(&viewgrades($request));
1.104 albertel 10407: } elsif ($command eq 'handgrade' && $perm{'mgr'}) {
1.41 ng 10408: $request->print(&processHandGrade($request));
1.106 albertel 10409: } elsif ($command eq 'editgrades' && $perm{'mgr'}) {
1.41 ng 10410: $request->print(&editgrades($request));
1.106 albertel 10411: } elsif ($command eq 'verify' && $perm{'vgr'}) {
1.41 ng 10412: $request->print(&verifyreceipt($request));
1.400 www 10413: } elsif ($command eq 'processclicker' && $perm{'mgr'}) {
10414: $request->print(&process_clicker($request));
10415: } elsif ($command eq 'processclickerfile' && $perm{'mgr'}) {
10416: $request->print(&process_clicker_file($request));
1.414 www 10417: } elsif ($command eq 'assignclickergrades' && $perm{'mgr'}) {
10418: $request->print(&assign_clicker_grades($request));
1.106 albertel 10419: } elsif ($command eq 'csvform' && $perm{'mgr'}) {
1.72 ng 10420: $request->print(&upcsvScores_form($request));
1.106 albertel 10421: } elsif ($command eq 'csvupload' && $perm{'mgr'}) {
1.41 ng 10422: $request->print(&csvupload($request));
1.106 albertel 10423: } elsif ($command eq 'csvuploadmap' && $perm{'mgr'} ) {
1.41 ng 10424: $request->print(&csvuploadmap($request));
1.246 albertel 10425: } elsif ($command eq 'csvuploadoptions' && $perm{'mgr'}) {
1.257 albertel 10426: if ($env{'form.associate'} ne 'Reverse Association') {
1.246 albertel 10427: $request->print(&csvuploadoptions($request));
1.41 ng 10428: } else {
1.257 albertel 10429: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
10430: $env{'form.upfile_associate'} = 'reverse';
1.41 ng 10431: } else {
1.257 albertel 10432: $env{'form.upfile_associate'} = 'forward';
1.41 ng 10433: }
10434: $request->print(&csvuploadmap($request));
10435: }
1.246 albertel 10436: } elsif ($command eq 'csvuploadassign' && $perm{'mgr'} ) {
10437: $request->print(&csvuploadassign($request));
1.106 albertel 10438: } elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
1.75 albertel 10439: $request->print(&scantron_selectphase($request));
1.203 albertel 10440: } elsif ($command eq 'scantron_warning' && $perm{'mgr'}) {
10441: $request->print(&scantron_do_warning($request));
1.142 albertel 10442: } elsif ($command eq 'scantron_validate' && $perm{'mgr'}) {
10443: $request->print(&scantron_validate_file($request));
1.106 albertel 10444: } elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
1.82 albertel 10445: $request->print(&scantron_process_students($request));
1.157 albertel 10446: } elsif ($command eq 'scantronupload' &&
1.257 albertel 10447: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
10448: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.162 albertel 10449: $request->print(&scantron_upload_scantron_data($request));
1.157 albertel 10450: } elsif ($command eq 'scantronupload_save' &&
1.257 albertel 10451: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
10452: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.157 albertel 10453: $request->print(&scantron_upload_scantron_data_save($request));
1.202 albertel 10454: } elsif ($command eq 'scantron_download' &&
1.257 albertel 10455: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.162 albertel 10456: $request->print(&scantron_download_scantron_data($request));
1.523 raeburn 10457: } elsif ($command eq 'checksubmissions' && $perm{'vgr'}) {
10458: $request->print(&checkscantron_results($request));
1.106 albertel 10459: } elsif ($command) {
1.562 bisitz 10460: $request->print('<p class="LC_error">'.&mt('Access Denied ([_1])',$command).'</p>');
1.26 albertel 10461: }
1.2 albertel 10462: }
1.513 foxr 10463: if ($ssi_error) {
10464: &ssi_print_error($request);
10465: }
1.353 albertel 10466: $request->print(&Apache::loncommon::end_page());
1.434 albertel 10467: &reset_caches();
1.596.2.4 raeburn 10468: return OK;
1.44 ng 10469: }
10470:
1.1 albertel 10471: 1;
10472:
1.13 albertel 10473: __END__;
1.531 jms 10474:
10475:
10476: =head1 NAME
10477:
10478: Apache::grades
10479:
10480: =head1 SYNOPSIS
10481:
10482: Handles the viewing of grades.
10483:
10484: This is part of the LearningOnline Network with CAPA project
10485: described at http://www.lon-capa.org.
10486:
10487: =head1 OVERVIEW
10488:
10489: Do an ssi with retries:
10490: While I'd love to factor out this with the vesrion in lonprintout,
10491: 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
10492: I'm not quite ready to invent (e.g. an ssi_with_retry object).
10493:
10494: At least the logic that drives this has been pulled out into loncommon.
10495:
10496:
10497:
10498: ssi_with_retries - Does the server side include of a resource.
10499: if the ssi call returns an error we'll retry it up to
10500: the number of times requested by the caller.
10501: If we still have a proble, no text is appended to the
10502: output and we set some global variables.
10503: to indicate to the caller an SSI error occurred.
10504: All of this is supposed to deal with the issues described
10505: in LonCAPA BZ 5631 see:
10506: http://bugs.lon-capa.org/show_bug.cgi?id=5631
10507: by informing the user that this happened.
10508:
10509: Parameters:
10510: resource - The resource to include. This is passed directly, without
10511: interpretation to lonnet::ssi.
10512: form - The form hash parameters that guide the interpretation of the resource
10513:
10514: retries - Number of retries allowed before giving up completely.
10515: Returns:
10516: On success, returns the rendered resource identified by the resource parameter.
10517: Side Effects:
10518: The following global variables can be set:
10519: ssi_error - If an unrecoverable error occurred this becomes true.
10520: It is up to the caller to initialize this to false
10521: if desired.
10522: ssi_error_resource - If an unrecoverable error occurred, this is the value
10523: of the resource that could not be rendered by the ssi
10524: call.
10525: ssi_error_message - The error string fetched from the ssi response
10526: in the event of an error.
10527:
10528:
10529: =head1 HANDLER SUBROUTINE
10530:
10531: ssi_with_retries()
10532:
10533: =head1 SUBROUTINES
10534:
10535: =over
10536:
10537: =item scantron_get_correction() :
10538:
10539: Builds the interface screen to interact with the operator to fix a
10540: specific error condition in a specific scanline
10541:
10542: Arguments:
10543: $r - Apache request object
10544: $i - number of the current scanline
10545: $scan_record - hash ref as returned from &scantron_parse_scanline()
10546: $scan_config - hash ref as returned from &get_scantron_config()
10547: $line - full contents of the current scanline
10548: $error - error condition, valid values are
10549: 'incorrectCODE', 'duplicateCODE',
10550: 'doublebubble', 'missingbubble',
10551: 'duplicateID', 'incorrectID'
10552: $arg - extra information needed
10553: For errors:
10554: - duplicateID - paper number that this studentID was seen before on
10555: - duplicateCODE - array ref of the paper numbers this CODE was
10556: seen on before
10557: - incorrectCODE - current incorrect CODE
10558: - doublebubble - array ref of the bubble lines that have double
10559: bubble errors
10560: - missingbubble - array ref of the bubble lines that have missing
10561: bubble errors
10562:
1.596.2.12.2. 6(raebur 10563:3): $randomorder - True if exam folder has randomorder set
10564:3): $randompick - True if exam folder has randompick set
10565:3): $respnumlookup - Reference to HASH mapping question numbers in bubble lines
10566:3): for current line to question number used for same question
10567:3): in "Master Seqence" (as seen by Course Coordinator).
10568:3): $startline - Reference to hash where key is question number (0 is first)
10569:3): and value is number of first bubble line for current student
10570:3): or code-based randompick and/or randomorder.
10571:3):
10572:3):
1.531 jms 10573: =item scantron_get_maxbubble() :
10574:
1.582 raeburn 10575: Arguments:
10576: $nav_error - Reference to scalar which is a flag to indicate a
10577: failure to retrieve a navmap object.
10578: if $nav_error is set to 1 by scantron_get_maxbubble(), the
10579: calling routine should trap the error condition and display the warning
10580: found in &navmap_errormsg().
10581:
1.596.2.12.2. (raeburn 10582:): $scantron_config - Reference to bubblesheet format configuration hash.
10583:):
1.531 jms 10584: Returns the maximum number of bubble lines that are expected to
10585: occur. Does this by walking the selected sequence rendering the
10586: resource and then checking &Apache::lonxml::get_problem_counter()
10587: for what the current value of the problem counter is.
10588:
10589: Caches the results to $env{'form.scantron_maxbubble'},
10590: $env{'form.scantron.bubble_lines.n'},
10591: $env{'form.scantron.first_bubble_line.n'} and
10592: $env{"form.scantron.sub_bubblelines.n"}
1.596.2.12.2. 6(raebur 10593:3): which are the total number of bubble lines, the number of bubble
1.531 jms 10594: lines for response n and number of the first bubble line for response n,
10595: and a comma separated list of numbers of bubble lines for sub-questions
10596: (for optionresponse, matchresponse, and rankresponse items), for response n.
10597:
10598:
10599: =item scantron_validate_missingbubbles() :
10600:
10601: Validates all scanlines in the selected file to not have any
10602: answers that don't have bubbles that have not been verified
10603: to be bubble free.
10604:
10605: =item scantron_process_students() :
10606:
1.596.2.6 raeburn 10607: Routine that does the actual grading of the bubblesheet information.
1.531 jms 10608:
10609: The parsed scanline hash is added to %env
10610:
10611: Then foreach unskipped scanline it does an &Apache::lonnet::ssi()
10612: foreach resource , with the form data of
10613:
10614: 'submitted' =>'scantron'
10615: 'grade_target' =>'grade',
10616: 'grade_username'=> username of student
10617: 'grade_domain' => domain of student
10618: 'grade_courseid'=> of course
10619: 'grade_symb' => symb of resource to grade
10620:
10621: This triggers a grading pass. The problem grading code takes care
10622: of converting the bubbled letter information (now in %env) into a
10623: valid submission.
10624:
10625: =item scantron_upload_scantron_data() :
10626:
1.596.2.6 raeburn 10627: Creates the screen for adding a new bubblesheet data file to a course.
1.531 jms 10628:
10629: =item scantron_upload_scantron_data_save() :
10630:
10631: Adds a provided bubble information data file to the course if user
10632: has the correct privileges to do so.
10633:
10634: =item valid_file() :
10635:
10636: Validates that the requested bubble data file exists in the course.
10637:
10638: =item scantron_download_scantron_data() :
10639:
10640: Shows a list of the three internal files (original, corrected,
1.596.2.6 raeburn 10641: skipped) for a specific bubblesheet data file that exists in the
1.531 jms 10642: course.
10643:
10644: =item scantron_validate_ID() :
10645:
10646: Validates all scanlines in the selected file to not have any
1.556 weissno 10647: invalid or underspecified student/employee IDs
1.531 jms 10648:
1.582 raeburn 10649: =item navmap_errormsg() :
10650:
10651: Returns HTML mark-up inside a <div></div> with a link to re-initialize the course.
10652: Should be called whenever the request to instantiate a navmap object fails.
10653:
1.531 jms 10654: =back
10655:
10656: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>