Annotation of loncom/homework/grades.pm, revision 1.694
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.694 ! bisitz 4: # $Id: grades.pm,v 1.693 2013/06/28 22:40:04 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.646 raeburn 43: use Apache::Constants qw(:common :http);
1.167 sakharuk 44: use Apache::lonlocal;
1.386 raeburn 45: use Apache::lonenc;
1.622 www 46: use Apache::lonstathelpers;
1.639 www 47: use Apache::lonquickgrades;
1.657 raeburn 48: use Apache::bridgetask();
1.170 albertel 49: use String::Similarity;
1.359 www 50: use LONCAPA;
51:
1.315 bowersj2 52: use POSIX qw(floor);
1.87 www 53:
1.435 foxr 54:
1.513 foxr 55:
1.435 foxr 56: my %perm=();
1.674 raeburn 57: my %old_essays=();
1.447 foxr 58:
1.513 foxr 59: # These variables are used to recover from ssi errors
60:
61: my $ssi_retries = 5;
62: my $ssi_error;
63: my $ssi_error_resource;
64: my $ssi_error_message;
65:
66:
67: sub ssi_with_retries {
68: my ($resource, $retries, %form) = @_;
69: my ($content, $response) = &Apache::loncommon::ssi_with_retries($resource, $retries, %form);
70: if ($response->is_error) {
71: $ssi_error = 1;
72: $ssi_error_resource = $resource;
73: $ssi_error_message = $response->code . " " . $response->message;
74: }
75:
76: return $content;
77:
78: }
79: #
80: # Prodcuces an ssi retry failure error message to the user:
81: #
82:
83: sub ssi_print_error {
84: my ($r) = @_;
1.516 raeburn 85: my $helpurl = &Apache::loncommon::top_nav_help('Helpdesk');
86: $r->print('
87: <br />
88: <h2>'.&mt('An unrecoverable network error occurred:').'</h2>
89: <p>
90: '.&mt('Unable to retrieve a resource from a server:').'<br />
91: '.&mt('Resource:').' '.$ssi_error_resource.'<br />
92: '.&mt('Error:').' '.$ssi_error_message.'
93: </p>
94: <p>'.
95: &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 />'.
96: &mt('If the error persists, please contact the [_1] for assistance.',$helpurl).
97: '</p>');
98: return;
1.513 foxr 99: }
100:
1.44 ng 101: #
1.146 albertel 102: # --- Retrieve the parts from the metadata file.---
1.598 www 103: # Returns an array of everything that the resources stores away
104: #
105:
1.44 ng 106: sub getpartlist {
1.582 raeburn 107: my ($symb,$errorref) = @_;
1.439 albertel 108:
109: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 110: unless (ref($navmap)) {
111: if (ref($errorref)) {
112: $$errorref = 'navmap';
113: return;
114: }
115: }
1.439 albertel 116: my $res = $navmap->getBySymb($symb);
117: my $partlist = $res->parts();
118: my $url = $res->src();
119: my @metakeys = split(/,/,&Apache::lonnet::metadata($url,'keys'));
120:
1.146 albertel 121: my @stores;
1.439 albertel 122: foreach my $part (@{ $partlist }) {
1.146 albertel 123: foreach my $key (@metakeys) {
124: if ($key =~ m/^stores_\Q$part\E_/) { push(@stores,$key); }
125: }
126: }
127: return @stores;
1.2 albertel 128: }
129:
1.129 ng 130: #--- Format fullname, username:domain if different for display
131: #--- Use anywhere where the student names are listed
132: sub nameUserString {
133: my ($type,$fullname,$uname,$udom) = @_;
134: if ($type eq 'header') {
1.485 albertel 135: return '<b> '.&mt('Fullname').' </b><span class="LC_internal_info">('.&mt('Username').')</span>';
1.129 ng 136: } else {
1.398 albertel 137: return ' '.$fullname.'<span class="LC_internal_info"> ('.$uname.
138: ($env{'user.domain'} eq $udom ? '' : ' ('.$udom.')').')</span>';
1.129 ng 139: }
140: }
141:
1.44 ng 142: #--- Get the partlist and the response type for a given problem. ---
143: #--- Indicate if a response type is coded handgraded or not. ---
1.623 www 144: #--- Sets response_error pointer to "1" if navmaps object broken ---
1.39 ng 145: sub response_type {
1.582 raeburn 146: my ($symb,$response_error) = @_;
1.377 albertel 147:
148: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 149: unless (ref($navmap)) {
150: if (ref($response_error)) {
151: $$response_error = 1;
152: }
153: return;
154: }
1.377 albertel 155: my $res = $navmap->getBySymb($symb);
1.593 raeburn 156: unless (ref($res)) {
157: $$response_error = 1;
158: return;
159: }
1.377 albertel 160: my $partlist = $res->parts();
1.392 albertel 161: my %vPart =
162: map { $_ => 1 } (&Apache::loncommon::get_env_multiple('form.vPart'));
1.377 albertel 163: my (%response_types,%handgrade);
164: foreach my $part (@{ $partlist }) {
1.392 albertel 165: next if (%vPart && !exists($vPart{$part}));
166:
1.377 albertel 167: my @types = $res->responseType($part);
168: my @ids = $res->responseIds($part);
169: for (my $i=0; $i < scalar(@ids); $i++) {
170: $response_types{$part}{$ids[$i]} = $types[$i];
171: $handgrade{$part.'_'.$ids[$i]} =
172: &Apache::lonnet::EXT('resource.'.$part.'_'.$ids[$i].
173: '.handgrade',$symb);
1.41 ng 174: }
175: }
1.377 albertel 176: return ($partlist,\%handgrade,\%response_types);
1.39 ng 177: }
178:
1.375 albertel 179: sub flatten_responseType {
180: my ($responseType) = @_;
181: my @part_response_id =
182: map {
183: my $part = $_;
184: map {
185: [$part,$_]
186: } sort(keys(%{ $responseType->{$part} }));
187: } sort(keys(%$responseType));
188: return @part_response_id;
189: }
190:
1.207 albertel 191: sub get_display_part {
1.324 albertel 192: my ($partID,$symb)=@_;
1.207 albertel 193: my $display=&Apache::lonnet::EXT('resource.'.$partID.'.display',$symb);
194: if (defined($display) and $display ne '') {
1.577 bisitz 195: $display.= ' (<span class="LC_internal_info">'
196: .&mt('Part ID: [_1]',$partID).'</span>)';
1.207 albertel 197: } else {
198: $display=$partID;
199: }
200: return $display;
201: }
1.269 raeburn 202:
1.434 albertel 203: sub reset_caches {
204: &reset_analyze_cache();
205: &reset_perm();
1.674 raeburn 206: &reset_old_essays();
1.434 albertel 207: }
208:
209: {
210: my %analyze_cache;
1.557 raeburn 211: my %analyze_cache_formkeys;
1.148 albertel 212:
1.434 albertel 213: sub reset_analyze_cache {
214: undef(%analyze_cache);
1.557 raeburn 215: undef(%analyze_cache_formkeys);
1.434 albertel 216: }
217:
218: sub get_analyze {
1.649 raeburn 219: my ($symb,$uname,$udom,$no_increment,$add_to_hash,$type,$trial,$rndseed,$bubbles_per_row)=@_;
1.434 albertel 220: my $key = "$symb\0$uname\0$udom";
1.640 raeburn 221: if ($type eq 'randomizetry') {
222: if ($trial ne '') {
223: $key .= "\0".$trial;
224: }
225: }
1.557 raeburn 226: if (exists($analyze_cache{$key})) {
227: my $getupdate = 0;
228: if (ref($add_to_hash) eq 'HASH') {
229: foreach my $item (keys(%{$add_to_hash})) {
230: if (ref($analyze_cache_formkeys{$key}) eq 'HASH') {
231: if (!exists($analyze_cache_formkeys{$key}{$item})) {
232: $getupdate = 1;
233: last;
234: }
235: } else {
236: $getupdate = 1;
237: }
238: }
239: }
240: if (!$getupdate) {
241: return $analyze_cache{$key};
242: }
243: }
1.434 albertel 244:
245: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
246: $url=&Apache::lonnet::clutter($url);
1.557 raeburn 247: my %form = ('grade_target' => 'analyze',
248: 'grade_domain' => $udom,
249: 'grade_symb' => $symb,
250: 'grade_courseid' => $env{'request.course.id'},
251: 'grade_username' => $uname,
252: 'grade_noincrement' => $no_increment);
1.649 raeburn 253: if ($bubbles_per_row ne '') {
254: $form{'bubbles_per_row'} = $bubbles_per_row;
255: }
1.640 raeburn 256: if ($type eq 'randomizetry') {
257: $form{'grade_questiontype'} = $type;
258: if ($rndseed ne '') {
259: $form{'grade_rndseed'} = $rndseed;
260: }
261: }
1.557 raeburn 262: if (ref($add_to_hash)) {
263: %form = (%form,%{$add_to_hash});
1.640 raeburn 264: }
1.557 raeburn 265: my $subresult=&ssi_with_retries($url, $ssi_retries,%form);
1.434 albertel 266: (undef,$subresult)=split(/_HASH_REF__/,$subresult,2);
267: my %analyze=&Apache::lonnet::str2hash($subresult);
1.557 raeburn 268: if (ref($add_to_hash) eq 'HASH') {
269: $analyze_cache_formkeys{$key} = $add_to_hash;
270: } else {
271: $analyze_cache_formkeys{$key} = {};
272: }
1.434 albertel 273: return $analyze_cache{$key} = \%analyze;
274: }
275:
276: sub get_order {
1.640 raeburn 277: my ($partid,$respid,$symb,$uname,$udom,$no_increment,$type,$trial,$rndseed)=@_;
278: my $analyze = &get_analyze($symb,$uname,$udom,$no_increment,undef,$type,$trial,$rndseed);
1.434 albertel 279: return $analyze->{"$partid.$respid.shown"};
280: }
281:
282: sub get_radiobutton_correct_foil {
1.640 raeburn 283: my ($partid,$respid,$symb,$uname,$udom,$type,$trial,$rndseed)=@_;
284: my $analyze = &get_analyze($symb,$uname,$udom,undef,undef,$type,$trial,$rndseed);
285: my $foils = &get_order($partid,$respid,$symb,$uname,$udom,undef,$type,$trial,$rndseed);
1.555 raeburn 286: if (ref($foils) eq 'ARRAY') {
287: foreach my $foil (@{$foils}) {
288: if ($analyze->{"$partid.$respid.foil.value.$foil"} eq 'true') {
289: return $foil;
290: }
1.434 albertel 291: }
292: }
293: }
1.554 raeburn 294:
295: sub scantron_partids_tograde {
1.649 raeburn 296: my ($resource,$cid,$uname,$udom,$check_for_randomlist,$bubbles_per_row) = @_;
1.554 raeburn 297: my (%analysis,@parts);
298: if (ref($resource)) {
299: my $symb = $resource->symb();
1.557 raeburn 300: my $add_to_form;
301: if ($check_for_randomlist) {
302: $add_to_form = { 'check_parts_withrandomlist' => 1,};
303: }
1.649 raeburn 304: my $analyze =
305: &get_analyze($symb,$uname,$udom,undef,$add_to_form,
306: undef,undef,undef,$bubbles_per_row);
1.554 raeburn 307: if (ref($analyze) eq 'HASH') {
308: %analysis = %{$analyze};
309: }
310: if (ref($analysis{'parts'}) eq 'ARRAY') {
311: foreach my $part (@{$analysis{'parts'}}) {
312: my ($id,$respid) = split(/\./,$part);
313: if (!&Apache::loncommon::check_if_partid_hidden($id,$symb,$udom,$uname)) {
314: push(@parts,$part);
315: }
316: }
317: }
318: }
319: return (\%analysis,\@parts);
320: }
321:
1.148 albertel 322: }
1.434 albertel 323:
1.118 ng 324: #--- Clean response type for display
1.335 albertel 325: #--- Currently filters option/rank/radiobutton/match/essay/Task
326: # response types only.
1.118 ng 327: sub cleanRecord {
1.336 albertel 328: my ($answer,$response,$symb,$partid,$respid,$record,$order,$version,
1.640 raeburn 329: $uname,$udom,$type,$trial,$rndseed) = @_;
1.398 albertel 330: my $grayFont = '<span class="LC_internal_info">';
1.148 albertel 331: if ($response =~ /^(option|rank)$/) {
332: my %answer=&Apache::lonnet::str2hash($answer);
333: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
334: my ($toprow,$bottomrow);
335: foreach my $foil (@$order) {
336: if ($grading{$foil} == 1) {
337: $toprow.='<td><b>'.$answer{$foil}.' </b></td>';
338: } else {
339: $toprow.='<td><i>'.$answer{$foil}.' </i></td>';
340: }
1.398 albertel 341: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.148 albertel 342: }
343: return '<blockquote><table border="1">'.
1.466 albertel 344: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
345: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.660 raeburn 346: $bottomrow.'</tr></table></blockquote>';
1.148 albertel 347: } elsif ($response eq 'match') {
348: my %answer=&Apache::lonnet::str2hash($answer);
349: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
350: my @items=&Apache::lonnet::str2array($record->{$version."resource.$partid.$respid.submissionitems"});
351: my ($toprow,$middlerow,$bottomrow);
352: foreach my $foil (@$order) {
353: my $item=shift(@items);
354: if ($grading{$foil} == 1) {
355: $toprow.='<td><b>'.$item.' </b></td>';
1.398 albertel 356: $middlerow.='<td><b>'.$grayFont.$answer{$foil}.' </span></b></td>';
1.148 albertel 357: } else {
358: $toprow.='<td><i>'.$item.' </i></td>';
1.398 albertel 359: $middlerow.='<td><i>'.$grayFont.$answer{$foil}.' </span></i></td>';
1.148 albertel 360: }
1.398 albertel 361: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.118 ng 362: }
1.126 ng 363: return '<blockquote><table border="1">'.
1.466 albertel 364: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
365: '<tr valign="top"><td>'.$grayFont.&mt('Item ID').'</span></td>'.
1.148 albertel 366: $middlerow.'</tr>'.
1.466 albertel 367: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.660 raeburn 368: $bottomrow.'</tr></table></blockquote>';
1.148 albertel 369: } elsif ($response eq 'radiobutton') {
370: my %answer=&Apache::lonnet::str2hash($answer);
371: my ($toprow,$bottomrow);
1.434 albertel 372: my $correct =
1.640 raeburn 373: &get_radiobutton_correct_foil($partid,$respid,$symb,$uname,$udom,$type,$trial,$rndseed);
1.434 albertel 374: foreach my $foil (@$order) {
1.148 albertel 375: if (exists($answer{$foil})) {
1.434 albertel 376: if ($foil eq $correct) {
1.466 albertel 377: $toprow.='<td><b>'.&mt('true').'</b></td>';
1.148 albertel 378: } else {
1.466 albertel 379: $toprow.='<td><i>'.&mt('true').'</i></td>';
1.148 albertel 380: }
381: } else {
1.466 albertel 382: $toprow.='<td>'.&mt('false').'</td>';
1.148 albertel 383: }
1.398 albertel 384: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.148 albertel 385: }
386: return '<blockquote><table border="1">'.
1.466 albertel 387: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
388: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.660 raeburn 389: $bottomrow.'</tr></table></blockquote>';
1.148 albertel 390: } elsif ($response eq 'essay') {
1.257 albertel 391: if (! exists ($env{'form.'.$symb})) {
1.122 ng 392: my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 393: $env{'course.'.$env{'request.course.id'}.'.domain'},
394: $env{'course.'.$env{'request.course.id'}.'.num'});
1.122 ng 395:
1.257 albertel 396: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
397: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
398: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
399: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
400: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
401: $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 402: }
1.166 albertel 403: $answer =~ s-\n-<br />-g;
404: return '<br /><br /><blockquote><tt>'.&keywords_highlight($answer).'</tt></blockquote>';
1.268 albertel 405: } elsif ( $response eq 'organic') {
406: my $result='Smile representation: "<tt>'.$answer.'</tt>"';
407: my $jme=$record->{$version."resource.$partid.$respid.molecule"};
408: $result.=&Apache::chemresponse::jme_img($jme,$answer,400);
409: return $result;
1.335 albertel 410: } elsif ( $response eq 'Task') {
411: if ( $answer eq 'SUBMITTED') {
412: my $files = $record->{$version."resource.$respid.$partid.bridgetask.portfiles"};
1.336 albertel 413: my $result = &Apache::bridgetask::file_list($files,$uname,$udom);
1.335 albertel 414: return $result;
415: } elsif ( grep(/^\Q$version\E.*?\.instance$/, keys(%{$record})) ) {
416: my @matches = grep(/^\Q$version\E.*?\.instance$/,
417: keys(%{$record}));
418: return join('<br />',($version,@matches));
419:
420:
421: } else {
422: my $result =
423: '<p>'
424: .&mt('Overall result: [_1]',
425: $record->{$version."resource.$respid.$partid.status"})
426: .'</p>';
427:
428: $result .= '<ul>';
429: my @grade = grep(/^\Q${version}resource.$respid.$partid.\E[^.]*[.]status$/,
430: keys(%{$record}));
431: foreach my $grade (sort(@grade)) {
432: my ($dim) = ($grade =~/[.]([^.]+)[.]status$/);
433: $result.= '<li>'.&mt("Dimension: [_1], status [_2] ",
434: $dim, $record->{$grade}).
435: '</li>';
436: }
437: $result.='</ul>';
438: return $result;
439: }
1.440 albertel 440: } elsif ( $response =~ m/(?:numerical|formula)/) {
441: $answer =
442: &Apache::loncommon::format_previous_attempt_value('submission',
443: $answer);
1.122 ng 444: }
1.118 ng 445: return $answer;
446: }
447:
448: #-- A couple of common js functions
449: sub commonJSfunctions {
450: my $request = shift;
1.597 wenzelju 451: $request->print(&Apache::lonhtmlcommon::scripttag(<<COMMONJSFUNCTIONS));
1.118 ng 452: function radioSelection(radioButton) {
453: var selection=null;
454: if (radioButton.length > 1) {
455: for (var i=0; i<radioButton.length; i++) {
456: if (radioButton[i].checked) {
457: return radioButton[i].value;
458: }
459: }
460: } else {
461: if (radioButton.checked) return radioButton.value;
462: }
463: return selection;
464: }
465:
466: function pullDownSelection(selectOne) {
467: var selection="";
468: if (selectOne.length > 1) {
469: for (var i=0; i<selectOne.length; i++) {
470: if (selectOne[i].selected) {
471: return selectOne[i].value;
472: }
473: }
474: } else {
1.138 albertel 475: // only one value it must be the selected one
476: return selectOne.value;
1.118 ng 477: }
478: }
479: COMMONJSFUNCTIONS
480: }
481:
1.44 ng 482: #--- Dumps the class list with usernames,list of sections,
483: #--- section, ids and fullnames for each user.
484: sub getclasslist {
1.449 banghart 485: my ($getsec,$filterlist,$getgroup) = @_;
1.291 albertel 486: my @getsec;
1.450 banghart 487: my @getgroup;
1.442 banghart 488: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.291 albertel 489: if (!ref($getsec)) {
490: if ($getsec ne '' && $getsec ne 'all') {
491: @getsec=($getsec);
492: }
493: } else {
494: @getsec=@{$getsec};
495: }
496: if (grep(/^all$/,@getsec)) { undef(@getsec); }
1.450 banghart 497: if (!ref($getgroup)) {
498: if ($getgroup ne '' && $getgroup ne 'all') {
499: @getgroup=($getgroup);
500: }
501: } else {
502: @getgroup=@{$getgroup};
503: }
504: if (grep(/^all$/,@getgroup)) { undef(@getgroup); }
1.291 albertel 505:
1.449 banghart 506: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
1.49 albertel 507: # Bail out if we were unable to get the classlist
1.56 matthew 508: return if (! defined($classlist));
1.449 banghart 509: &Apache::loncoursedata::get_group_memberships($classlist,$keylist);
1.56 matthew 510: #
511: my %sections;
512: my %fullnames;
1.205 matthew 513: foreach my $student (keys(%$classlist)) {
514: my $end =
515: $classlist->{$student}->[&Apache::loncoursedata::CL_END()];
516: my $start =
517: $classlist->{$student}->[&Apache::loncoursedata::CL_START()];
518: my $id =
519: $classlist->{$student}->[&Apache::loncoursedata::CL_ID()];
520: my $section =
521: $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
522: my $fullname =
523: $classlist->{$student}->[&Apache::loncoursedata::CL_FULLNAME()];
524: my $status =
525: $classlist->{$student}->[&Apache::loncoursedata::CL_STATUS()];
1.449 banghart 526: my $group =
527: $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1.76 ng 528: # filter students according to status selected
1.442 banghart 529: if ($filterlist && (!($stu_status =~ /Any/))) {
530: if (!($stu_status =~ $status)) {
1.450 banghart 531: delete($classlist->{$student});
1.76 ng 532: next;
533: }
534: }
1.450 banghart 535: # filter students according to groups selected
1.453 banghart 536: my @stu_groups = split(/,/,$group);
1.450 banghart 537: if (@getgroup) {
538: my $exclude = 1;
1.454 banghart 539: foreach my $grp (@getgroup) {
540: foreach my $stu_group (@stu_groups) {
1.453 banghart 541: if ($stu_group eq $grp) {
542: $exclude = 0;
543: }
1.450 banghart 544: }
1.453 banghart 545: if (($grp eq 'none') && !$group) {
546: $exclude = 0;
547: }
1.450 banghart 548: }
549: if ($exclude) {
550: delete($classlist->{$student});
551: }
552: }
1.205 matthew 553: $section = ($section ne '' ? $section : 'none');
1.106 albertel 554: if (&canview($section)) {
1.291 albertel 555: if (!@getsec || grep(/^\Q$section\E$/,@getsec)) {
1.103 albertel 556: $sections{$section}++;
1.450 banghart 557: if ($classlist->{$student}) {
558: $fullnames{$student}=$fullname;
559: }
1.103 albertel 560: } else {
1.205 matthew 561: delete($classlist->{$student});
1.103 albertel 562: }
563: } else {
1.205 matthew 564: delete($classlist->{$student});
1.103 albertel 565: }
1.44 ng 566: }
567: my %seen = ();
1.56 matthew 568: my @sections = sort(keys(%sections));
569: return ($classlist,\@sections,\%fullnames);
1.44 ng 570: }
571:
1.103 albertel 572: sub canmodify {
573: my ($sec)=@_;
574: if ($perm{'mgr'}) {
575: if (!defined($perm{'mgr_section'})) {
576: # can modify whole class
577: return 1;
578: } else {
579: if ($sec eq $perm{'mgr_section'}) {
580: #can modify the requested section
581: return 1;
582: } else {
583: # can't modify the request section
584: return 0;
585: }
586: }
587: }
588: #can't modify
589: return 0;
590: }
591:
592: sub canview {
593: my ($sec)=@_;
594: if ($perm{'vgr'}) {
595: if (!defined($perm{'vgr_section'})) {
596: # can modify whole class
597: return 1;
598: } else {
599: if ($sec eq $perm{'vgr_section'}) {
600: #can modify the requested section
601: return 1;
602: } else {
603: # can't modify the request section
604: return 0;
605: }
606: }
607: }
608: #can't modify
609: return 0;
610: }
611:
1.44 ng 612: #--- Retrieve the grade status of a student for all the parts
613: sub student_gradeStatus {
1.324 albertel 614: my ($symb,$udom,$uname,$partlist) = @_;
1.257 albertel 615: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.44 ng 616: my %partstatus = ();
617: foreach (@$partlist) {
1.128 ng 618: my ($status,undef) = split(/_/,$record{"resource.$_.solved"},2);
1.44 ng 619: $status = 'nothing' if ($status eq '');
620: $partstatus{$_} = $status;
621: my $subkey = "resource.$_.submitted_by";
622: $partstatus{$subkey} = $record{$subkey} if ($record{$subkey} ne '');
623: }
624: return %partstatus;
625: }
626:
1.45 ng 627: # hidden form and javascript that calls the form
628: # Use by verifyscript and viewgrades
629: # Shows a student's view of problem and submission
630: sub jscriptNform {
1.324 albertel 631: my ($symb) = @_;
1.442 banghart 632: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.597 wenzelju 633: my $jscript= &Apache::lonhtmlcommon::scripttag(
1.45 ng 634: ' function viewOneStudent(user,domain) {'."\n".
635: ' document.onestudent.student.value = user;'."\n".
636: ' document.onestudent.userdom.value = domain;'."\n".
637: ' document.onestudent.submit();'."\n".
638: ' }'."\n".
1.597 wenzelju 639: "\n");
1.45 ng 640: $jscript.= '<form action="/adm/grades" method="post" name="onestudent">'."\n".
1.418 albertel 641: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.442 banghart 642: '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.45 ng 643: '<input type="hidden" name="command" value="submission" />'."\n".
644: '<input type="hidden" name="student" value="" />'."\n".
645: '<input type="hidden" name="userdom" value="" />'."\n".
646: '</form>'."\n";
647: return $jscript;
648: }
1.39 ng 649:
1.447 foxr 650:
651:
1.315 bowersj2 652: # Given the score (as a number [0-1] and the weight) what is the final
653: # point value? This function will round to the nearest tenth, third,
654: # or quarter if one of those is within the tolerance of .00001.
1.316 albertel 655: sub compute_points {
1.315 bowersj2 656: my ($score, $weight) = @_;
657:
658: my $tolerance = .00001;
659: my $points = $score * $weight;
660:
661: # Check for nearness to 1/x.
662: my $check_for_nearness = sub {
663: my ($factor) = @_;
664: my $num = ($points * $factor) + $tolerance;
665: my $floored_num = floor($num);
1.316 albertel 666: if ($num - $floored_num < 2 * $tolerance * $factor) {
1.315 bowersj2 667: return $floored_num / $factor;
668: }
669: return $points;
670: };
671:
672: $points = $check_for_nearness->(10);
673: $points = $check_for_nearness->(3);
674: $points = $check_for_nearness->(4);
675:
676: return $points;
677: }
678:
1.44 ng 679: #------------------ End of general use routines --------------------
1.87 www 680:
681: #
682: # Find most similar essay
683: #
684:
685: sub most_similar {
1.674 raeburn 686: my ($uname,$udom,$symb,$uessay)=@_;
687:
688: unless ($symb) { return ''; }
689:
690: unless (ref($old_essays{$symb}) eq 'HASH') { return ''; }
1.87 www 691:
692: # ignore spaces and punctuation
693:
694: $uessay=~s/\W+/ /gs;
695:
1.282 www 696: # ignore empty submissions (occuring when only files are sent)
697:
1.598 www 698: unless ($uessay=~/\w+/s) { return ''; }
1.282 www 699:
1.87 www 700: # these will be returned. Do not care if not at least 50 percent similar
1.88 www 701: my $limit=0.6;
1.87 www 702: my $sname='';
703: my $sdom='';
704: my $scrsid='';
705: my $sessay='';
706: # go through all essays ...
1.674 raeburn 707: foreach my $tkey (keys(%{$old_essays{$symb}})) {
1.426 albertel 708: my ($tname,$tdom,$tcrsid)=map {&unescape($_)} (split(/\./,$tkey));
1.87 www 709: # ... except the same student
1.426 albertel 710: next if (($tname eq $uname) && ($tdom eq $udom));
1.674 raeburn 711: my $tessay=$old_essays{$symb}{$tkey};
1.426 albertel 712: $tessay=~s/\W+/ /gs;
1.87 www 713: # String similarity gives up if not even limit
1.426 albertel 714: my $tsimilar=&String::Similarity::similarity($uessay,$tessay,$limit);
1.87 www 715: # Found one
1.426 albertel 716: if ($tsimilar>$limit) {
717: $limit=$tsimilar;
718: $sname=$tname;
719: $sdom=$tdom;
720: $scrsid=$tcrsid;
1.674 raeburn 721: $sessay=$old_essays{$symb}{$tkey};
1.426 albertel 722: }
1.87 www 723: }
1.88 www 724: if ($limit>0.6) {
1.87 www 725: return ($sname,$sdom,$scrsid,$sessay,$limit);
726: } else {
727: return ('','','','',0);
728: }
729: }
730:
1.44 ng 731: #-------------------------------------------------------------------
732:
733: #------------------------------------ Receipt Verification Routines
1.45 ng 734: #
1.602 www 735:
736: sub initialverifyreceipt {
1.608 www 737: my ($request,$symb) = @_;
1.602 www 738: &commonJSfunctions($request);
1.694 ! bisitz 739: return '<form name="gradingMenu" action=""><input type="submit" value="'.&mt('Verify Receipt Number.').'" />'.
1.602 www 740: &Apache::lonnet::recprefix($env{'request.course.id'}).
741: '-<input type="text" name="receipt" size="4" />'.
1.603 www 742: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
743: '<input type="hidden" name="command" value="verify" />'.
744: "</form>\n";
1.602 www 745: }
746:
1.44 ng 747: #--- Check whether a receipt number is valid.---
748: sub verifyreceipt {
1.608 www 749: my ($request,$symb) = @_;
1.44 ng 750:
1.257 albertel 751: my $courseid = $env{'request.course.id'};
1.184 www 752: my $receipt = &Apache::lonnet::recprefix($courseid).'-'.
1.257 albertel 753: $env{'form.receipt'};
1.44 ng 754: $receipt =~ s/[^\-\d]//g;
755:
1.487 albertel 756: my $title.=
757: '<h3><span class="LC_info">'.
1.605 www 758: &mt('Verifying Receipt Number [_1]',$receipt).
759: '</span></h3>'."\n";
1.44 ng 760:
761: my ($string,$contents,$matches) = ('','',0);
1.56 matthew 762: my (undef,undef,$fullname) = &getclasslist('all','0');
1.177 albertel 763:
764: my $receiptparts=0;
1.390 albertel 765: if ($env{"course.$courseid.receiptalg"} eq 'receipt2' ||
766: $env{"course.$courseid.receiptalg"} eq 'receipt3') { $receiptparts=1; }
1.177 albertel 767: my $parts=['0'];
1.582 raeburn 768: if ($receiptparts) {
769: my $res_error;
770: ($parts)=&response_type($symb,\$res_error);
771: if ($res_error) {
772: return &navmap_errormsg();
773: }
774: }
1.486 albertel 775:
776: my $header =
777: &Apache::loncommon::start_data_table().
778: &Apache::loncommon::start_data_table_header_row().
1.487 albertel 779: '<th> '.&mt('Fullname').' </th>'."\n".
780: '<th> '.&mt('Username').' </th>'."\n".
781: '<th> '.&mt('Domain').' </th>';
1.486 albertel 782: if ($receiptparts) {
1.487 albertel 783: $header.='<th> '.&mt('Problem Part').' </th>';
1.486 albertel 784: }
785: $header.=
786: &Apache::loncommon::end_data_table_header_row();
787:
1.294 albertel 788: foreach (sort
789: {
790: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
791: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
792: }
793: return $a cmp $b;
794: } (keys(%$fullname))) {
1.44 ng 795: my ($uname,$udom)=split(/\:/);
1.177 albertel 796: foreach my $part (@$parts) {
797: if ($receipt eq &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb,$part)) {
1.486 albertel 798: $contents.=
799: &Apache::loncommon::start_data_table_row().
800: '<td> '."\n".
1.177 albertel 801: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 802: '\');" target="_self">'.$$fullname{$_}.'</a> </td>'."\n".
1.177 albertel 803: '<td> '.$uname.' </td>'.
804: '<td> '.$udom.' </td>';
805: if ($receiptparts) {
806: $contents.='<td> '.$part.' </td>';
807: }
1.486 albertel 808: $contents.=
809: &Apache::loncommon::end_data_table_row()."\n";
1.177 albertel 810:
811: $matches++;
812: }
1.44 ng 813: }
814: }
815: if ($matches == 0) {
1.584 bisitz 816: $string = $title
817: .'<p class="LC_warning">'
818: .&mt('No match found for the above receipt number.')
819: .'</p>';
1.44 ng 820: } else {
1.324 albertel 821: $string = &jscriptNform($symb).$title.
1.487 albertel 822: '<p>'.
1.584 bisitz 823: &mt('The above receipt number matches the following [quant,_1,student].',$matches).
1.487 albertel 824: '</p>'.
1.486 albertel 825: $header.
826: $contents.
827: &Apache::loncommon::end_data_table()."\n";
1.44 ng 828: }
1.614 www 829: return $string;
1.44 ng 830: }
831:
832: #--- This is called by a number of programs.
833: #--- Called from the Grading Menu - View/Grade an individual student
834: #--- Also called directly when one clicks on the subm button
835: # on the problem page.
1.30 ng 836: sub listStudents {
1.617 www 837: my ($request,$symb,$submitonly) = @_;
1.49 albertel 838:
1.257 albertel 839: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
840: my $cnum = $env{"course.$env{'request.course.id'}.num"};
841: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.449 banghart 842: my $getgroup = $env{'form.group'} eq '' ? 'all' : $env{'form.group'};
1.617 www 843: unless ($submitonly) {
844: $submitonly= $env{'form.submitonly'} eq '' ? 'all' : $env{'form.submitonly'};
845: }
1.49 albertel 846:
1.632 www 847: my $result='';
1.623 www 848: my $res_error;
849: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
1.49 albertel 850:
1.559 raeburn 851: my %lt = &Apache::lonlocal::texthash (
852: 'multiple' => 'Please select a student or group of students before clicking on the Next button.',
853: 'single' => 'Please select the student before clicking on the Next button.',
854: );
1.597 wenzelju 855: $request->print(&Apache::lonhtmlcommon::scripttag(<<LISTJAVASCRIPT));
1.110 ng 856: function checkSelect(checkBox) {
857: var ctr=0;
858: var sense="";
859: if (checkBox.length > 1) {
860: for (var i=0; i<checkBox.length; i++) {
861: if (checkBox[i].checked) {
862: ctr++;
863: }
864: }
1.485 albertel 865: sense = '$lt{'multiple'}';
1.110 ng 866: } else {
867: if (checkBox.checked) {
868: ctr = 1;
869: }
1.485 albertel 870: sense = '$lt{'single'}';
1.110 ng 871: }
872: if (ctr == 0) {
1.485 albertel 873: alert(sense);
1.110 ng 874: return false;
875: }
876: document.gradesub.submit();
877: }
878:
879: function reLoadList(formname) {
1.112 ng 880: if (formname.saveStatusOld.value == pullDownSelection(formname.Status)) {return;}
1.110 ng 881: formname.command.value = 'submission';
882: formname.submit();
883: }
1.45 ng 884: LISTJAVASCRIPT
885:
1.118 ng 886: &commonJSfunctions($request);
1.41 ng 887: $request->print($result);
1.39 ng 888:
1.154 albertel 889: my $gradeTable='<form action="/adm/grades" method="post" name="gradesub">'.
1.598 www 890: "\n";
1.485 albertel 891:
1.561 bisitz 892: $gradeTable .= &Apache::lonhtmlcommon::start_pick_box();
893: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Problem Text'))
894: .'<label><input type="radio" name="vProb" value="no" checked="checked" /> '.&mt('no').' </label>'."\n"
895: .'<label><input type="radio" name="vProb" value="yes" /> '.&mt('one student').' </label>'."\n"
896: .'<label><input type="radio" name="vProb" value="all" /> '.&mt('all students').' </label><br />'."\n"
897: .&Apache::lonhtmlcommon::row_closure();
898: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Answer'))
899: .'<label><input type="radio" name="vAns" value="no" /> '.&mt('no').' </label>'."\n"
900: .'<label><input type="radio" name="vAns" value="yes" /> '.&mt('one student').' </label>'."\n"
901: .'<label><input type="radio" name="vAns" value="all" checked="checked" /> '.&mt('all students').' </label><br />'."\n"
902: .&Apache::lonhtmlcommon::row_closure();
1.485 albertel 903:
904: my $submission_options;
1.442 banghart 905: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
906: my $saveStatus = $stu_status eq '' ? 'Active' : $stu_status;
1.257 albertel 907: $env{'form.Status'} = $saveStatus;
1.485 albertel 908: $submission_options.=
1.592 bisitz 909: '<span class="LC_nobreak">'.
1.624 www 910: '<label><input type="radio" name="lastSub" value="lastonly" /> '.
1.592 bisitz 911: &mt('last submission only').' </label></span>'."\n".
912: '<span class="LC_nobreak">'.
913: '<label><input type="radio" name="lastSub" value="last" /> '.
914: &mt('last submission & parts info').' </label></span>'."\n".
915: '<span class="LC_nobreak">'.
1.628 www 916: '<label><input type="radio" name="lastSub" value="datesub" checked="checked" /> '.
1.592 bisitz 917: &mt('by dates and submissions').'</label></span>'."\n".
918: '<span class="LC_nobreak">'.
919: '<label><input type="radio" name="lastSub" value="all" /> '.
920: &mt('all details').'</label></span>';
1.561 bisitz 921: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Submissions'))
922: .$submission_options
923: .&Apache::lonhtmlcommon::row_closure();
924:
925: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Grading Increments'))
926: .'<select name="increment">'
927: .'<option value="1">'.&mt('Whole Points').'</option>'
928: .'<option value=".5">'.&mt('Half Points').'</option>'
929: .'<option value=".25">'.&mt('Quarter Points').'</option>'
930: .'<option value=".1">'.&mt('Tenths of a Point').'</option>'
931: .'</select>'
932: .&Apache::lonhtmlcommon::row_closure();
1.485 albertel 933:
934: $gradeTable .=
1.432 banghart 935: &build_section_inputs().
1.45 ng 936: '<input type="hidden" name="submitonly" value="'.$submitonly.'" />'."\n".
1.418 albertel 937: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.110 ng 938: '<input type="hidden" name="saveStatusOld" value="'.$saveStatus.'" />'."\n";
939:
1.618 www 940: if (exists($env{'form.Status'})) {
1.561 bisitz 941: $gradeTable .= '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n";
1.124 ng 942: } else {
1.561 bisitz 943: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Student Status'))
944: .&Apache::lonhtmlcommon::StatusOptions(
945: $saveStatus,undef,1,'javascript:reLoadList(this.form);')
946: .&Apache::lonhtmlcommon::row_closure();
1.124 ng 947: }
1.112 ng 948:
1.561 bisitz 949: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Check For Plagiarism'))
950: .'<input type="checkbox" name="checkPlag" checked="checked" />'
951: .&Apache::lonhtmlcommon::row_closure(1)
952: .&Apache::lonhtmlcommon::end_pick_box();
953:
954: $gradeTable .= '<p>'
1.618 www 955: .&mt("To view/grade/regrade 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"
1.561 bisitz 956: .'<input type="hidden" name="command" value="processGroup" />'
957: .'</p>';
1.249 albertel 958:
959: # checkall buttons
960: $gradeTable.=&check_script('gradesub', 'stuinfo');
1.110 ng 961: $gradeTable.='<input type="button" '."\n".
1.589 bisitz 962: 'onclick="javascript:checkSelect(this.form.stuinfo);" '."\n".
963: 'value="'.&mt('Next').' →" /> <br />'."\n";
1.249 albertel 964: $gradeTable.=&check_buttons();
1.450 banghart 965: my ($classlist, undef, $fullname) = &getclasslist($getsec,'1',$getgroup);
1.474 albertel 966: $gradeTable.= &Apache::loncommon::start_data_table().
967: &Apache::loncommon::start_data_table_header_row();
1.110 ng 968: my $loop = 0;
969: while ($loop < 2) {
1.485 albertel 970: $gradeTable.='<th>'.&mt('No.').'</th><th>'.&mt('Select').'</th>'.
971: '<th>'.&nameUserString('header').' '.&mt('Section/Group').'</th>';
1.618 www 972: if (($submitonly ne 'queued') && ($submitonly ne 'all')) {
1.485 albertel 973: foreach my $part (sort(@$partlist)) {
974: my $display_part=
975: &get_display_part((split(/_/,$part))[0],$symb);
976: $gradeTable.=
977: '<th>'.&mt('Part: [_1] Status',$display_part).'</th>';
1.110 ng 978: }
1.301 albertel 979: } elsif ($submitonly eq 'queued') {
1.474 albertel 980: $gradeTable.='<th>'.&mt('Queue Status').' </th>';
1.110 ng 981: }
982: $loop++;
1.126 ng 983: # $gradeTable.='<td></td>' if ($loop%2 ==1);
1.41 ng 984: }
1.474 albertel 985: $gradeTable.=&Apache::loncommon::end_data_table_header_row()."\n";
1.41 ng 986:
1.45 ng 987: my $ctr = 0;
1.294 albertel 988: foreach my $student (sort
989: {
990: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
991: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
992: }
993: return $a cmp $b;
994: }
995: (keys(%$fullname))) {
1.41 ng 996: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 997:
1.110 ng 998: my %status = ();
1.301 albertel 999:
1000: if ($submitonly eq 'queued') {
1001: my %queue_status =
1002: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
1003: $udom,$uname);
1004: next if (!defined($queue_status{'gradingqueue'}));
1005: $status{'gradingqueue'} = $queue_status{'gradingqueue'};
1006: }
1007:
1.618 www 1008: if (($submitonly ne 'queued') && ($submitonly ne 'all')) {
1.324 albertel 1009: (%status) =&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 1010: my $submitted = 0;
1.164 albertel 1011: my $graded = 0;
1.248 albertel 1012: my $incorrect = 0;
1.110 ng 1013: foreach (keys(%status)) {
1.145 albertel 1014: $submitted = 1 if ($status{$_} ne 'nothing');
1.248 albertel 1015: $graded = 1 if ($status{$_} =~ /^ungraded/);
1016: $incorrect = 1 if ($status{$_} =~ /^incorrect/);
1017:
1.110 ng 1018: my ($foo,$partid,$foo1) = split(/\./,$_);
1019: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
1.145 albertel 1020: $submitted = 0;
1.150 albertel 1021: my ($part)=split(/\./,$partid);
1.110 ng 1022: $gradeTable.='<input type="hidden" name="'.
1.150 albertel 1023: $student.':'.$part.':submitted_by" value="'.
1.110 ng 1024: $status{'resource.'.$partid.'.submitted_by'}.'" />';
1025: }
1.41 ng 1026: }
1.248 albertel 1027:
1.156 albertel 1028: next if (!$submitted && ($submitonly eq 'yes' ||
1029: $submitonly eq 'incorrect' ||
1030: $submitonly eq 'graded'));
1.248 albertel 1031: next if (!$graded && ($submitonly eq 'graded'));
1032: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 1033: }
1.34 ng 1034:
1.45 ng 1035: $ctr++;
1.249 albertel 1036: my $section = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
1.452 banghart 1037: my $group = $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1.104 albertel 1038: if ( $perm{'vgr'} eq 'F' ) {
1.474 albertel 1039: if ($ctr%2 ==1) {
1040: $gradeTable.= &Apache::loncommon::start_data_table_row();
1041: }
1.126 ng 1042: $gradeTable.='<td align="right">'.$ctr.' </td>'.
1.563 bisitz 1043: '<td align="center"><label><input type="checkbox" name="stuinfo" value="'.
1.249 albertel 1044: $student.':'.$$fullname{$student}.':::SECTION'.$section.
1045: ') " /> </label></td>'."\n".'<td>'.
1046: &nameUserString(undef,$$fullname{$student},$uname,$udom).
1.474 albertel 1047: ' '.$section.($group ne '' ?'/'.$group:'').'</td>'."\n";
1.110 ng 1048:
1.618 www 1049: if ($submitonly ne 'all') {
1.524 raeburn 1050: foreach (sort(keys(%status))) {
1.485 albertel 1051: next if ($_ =~ /^resource.*?submitted_by$/);
1052: $gradeTable.='<td align="center"> '.&mt($status{$_}).' </td>'."\n";
1.110 ng 1053: }
1.41 ng 1054: }
1.126 ng 1055: # $gradeTable.='<td></td>' if ($ctr%2 ==1);
1.474 albertel 1056: if ($ctr%2 ==0) {
1057: $gradeTable.=&Apache::loncommon::end_data_table_row()."\n";
1058: }
1.41 ng 1059: }
1060: }
1.110 ng 1061: if ($ctr%2 ==1) {
1.126 ng 1062: $gradeTable.='<td> </td><td> </td><td> </td>';
1.618 www 1063: if (($submitonly ne 'queued') && ($submitonly ne 'all')) {
1.110 ng 1064: foreach (@$partlist) {
1065: $gradeTable.='<td> </td>';
1066: }
1.301 albertel 1067: } elsif ($submitonly eq 'queued') {
1068: $gradeTable.='<td> </td>';
1.110 ng 1069: }
1.474 albertel 1070: $gradeTable.=&Apache::loncommon::end_data_table_row();
1.110 ng 1071: }
1072:
1.474 albertel 1073: $gradeTable.=&Apache::loncommon::end_data_table()."\n".
1.589 bisitz 1074: '<input type="button" '.
1075: 'onclick="javascript:checkSelect(this.form.stuinfo);" '.
1076: 'value="'.&mt('Next').' →" /></form>'."\n";
1.45 ng 1077: if ($ctr == 0) {
1.96 albertel 1078: my $num_students=(scalar(keys(%$fullname)));
1079: if ($num_students eq 0) {
1.485 albertel 1080: $gradeTable='<br /> <span class="LC_warning">'.&mt('There are no students currently enrolled.').'</span>';
1.96 albertel 1081: } else {
1.171 albertel 1082: my $submissions='submissions';
1083: if ($submitonly eq 'incorrect') { $submissions = 'incorrect submissions'; }
1084: if ($submitonly eq 'graded' ) { $submissions = 'ungraded submissions'; }
1.301 albertel 1085: if ($submitonly eq 'queued' ) { $submissions = 'queued submissions'; }
1.398 albertel 1086: $gradeTable='<br /> <span class="LC_warning">'.
1.485 albertel 1087: &mt('No '.$submissions.' found for this resource for any students. ([_1] students checked for '.$submissions.')',
1088: $num_students).
1089: '</span><br />';
1.96 albertel 1090: }
1.46 ng 1091: } elsif ($ctr == 1) {
1.474 albertel 1092: $gradeTable =~ s/type="checkbox"/type="checkbox" checked="checked"/;
1.45 ng 1093: }
1094: $request->print($gradeTable);
1.44 ng 1095: return '';
1.10 ng 1096: }
1097:
1.44 ng 1098: #---- Called from the listStudents routine
1.249 albertel 1099:
1100: sub check_script {
1101: my ($form, $type)=@_;
1.597 wenzelju 1102: my $chkallscript= &Apache::lonhtmlcommon::scripttag('
1.249 albertel 1103: function checkall() {
1104: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1105: ele = document.forms.'.$form.'.elements[i];
1106: if (ele.name == "'.$type.'") {
1107: document.forms.'.$form.'.elements[i].checked=true;
1108: }
1109: }
1110: }
1111:
1112: function checksec() {
1113: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1114: ele = document.forms.'.$form.'.elements[i];
1115: string = document.forms.'.$form.'.chksec.value;
1116: if
1117: (ele.value.indexOf(":::SECTION"+string)>0) {
1118: document.forms.'.$form.'.elements[i].checked=true;
1119: }
1120: }
1121: }
1122:
1123:
1124: function uncheckall() {
1125: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1126: ele = document.forms.'.$form.'.elements[i];
1127: if (ele.name == "'.$type.'") {
1128: document.forms.'.$form.'.elements[i].checked=false;
1129: }
1130: }
1131: }
1132:
1.597 wenzelju 1133: '."\n");
1.249 albertel 1134: return $chkallscript;
1135: }
1136:
1137: sub check_buttons {
1.485 albertel 1138: my $buttons.='<input type="button" onclick="checkall()" value="'.&mt('Check All').'" />';
1139: $buttons.='<input type="button" onclick="uncheckall()" value="'.&mt('Uncheck All').'" /> ';
1140: $buttons.='<input type="button" onclick="checksec()" value="'.&mt('Check Section/Group').'" />';
1.249 albertel 1141: $buttons.='<input type="text" size="5" name="chksec" /> ';
1142: return $buttons;
1143: }
1144:
1.44 ng 1145: # Displays the submissions for one student or a group of students
1.34 ng 1146: sub processGroup {
1.619 www 1147: my ($request,$symb) = @_;
1.41 ng 1148: my $ctr = 0;
1.155 albertel 1149: my @stuchecked = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.41 ng 1150: my $total = scalar(@stuchecked)-1;
1.45 ng 1151:
1.396 banghart 1152: foreach my $student (@stuchecked) {
1153: my ($uname,$udom,$fullname) = split(/:/,$student);
1.257 albertel 1154: $env{'form.student'} = $uname;
1155: $env{'form.userdom'} = $udom;
1156: $env{'form.fullname'} = $fullname;
1.619 www 1157: &submission($request,$ctr,$total,$symb);
1.41 ng 1158: $ctr++;
1159: }
1160: return '';
1.35 ng 1161: }
1.34 ng 1162:
1.44 ng 1163: #------------------------------------------------------------------------------------
1164: #
1165: #-------------------------- Next few routines handles grading by student, essentially
1166: # handles essay response type problem/part
1167: #
1168: #--- Javascript to handle the submission page functionality ---
1169: sub sub_page_js {
1170: my $request = shift;
1.539 riegler 1171: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
1.597 wenzelju 1172: $request->print(&Apache::lonhtmlcommon::scripttag(<<SUBJAVASCRIPT));
1.71 ng 1173: function updateRadio(formname,id,weight) {
1.125 ng 1174: var gradeBox = formname["GD_BOX"+id];
1175: var radioButton = formname["RADVAL"+id];
1176: var oldpts = formname["oldpts"+id].value;
1.72 ng 1177: var pts = checkSolved(formname,id) == 'update' ? gradeBox.value : oldpts;
1.71 ng 1178: gradeBox.value = pts;
1179: var resetbox = false;
1180: if (isNaN(pts) || pts < 0) {
1.539 riegler 1181: alert("$alertmsg"+pts);
1.71 ng 1182: for (var i=0; i<radioButton.length; i++) {
1183: if (radioButton[i].checked) {
1184: gradeBox.value = i;
1185: resetbox = true;
1186: }
1187: }
1188: if (!resetbox) {
1189: formtextbox.value = "";
1190: }
1191: return;
1.44 ng 1192: }
1.71 ng 1193:
1194: if (pts > weight) {
1195: var resp = confirm("You entered a value ("+pts+
1196: ") greater than the weight for the part. Accept?");
1197: if (resp == false) {
1.125 ng 1198: gradeBox.value = oldpts;
1.71 ng 1199: return;
1200: }
1.44 ng 1201: }
1.13 albertel 1202:
1.71 ng 1203: for (var i=0; i<radioButton.length; i++) {
1204: radioButton[i].checked=false;
1205: if (pts == i && pts != "") {
1206: radioButton[i].checked=true;
1207: }
1208: }
1209: updateSelect(formname,id);
1.125 ng 1210: formname["stores"+id].value = "0";
1.41 ng 1211: }
1.5 albertel 1212:
1.72 ng 1213: function writeBox(formname,id,pts) {
1.125 ng 1214: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1215: if (checkSolved(formname,id) == 'update') {
1216: gradeBox.value = pts;
1217: } else {
1.125 ng 1218: var oldpts = formname["oldpts"+id].value;
1.72 ng 1219: gradeBox.value = oldpts;
1.125 ng 1220: var radioButton = formname["RADVAL"+id];
1.71 ng 1221: for (var i=0; i<radioButton.length; i++) {
1222: radioButton[i].checked=false;
1.72 ng 1223: if (i == oldpts) {
1.71 ng 1224: radioButton[i].checked=true;
1225: }
1226: }
1.41 ng 1227: }
1.125 ng 1228: formname["stores"+id].value = "0";
1.71 ng 1229: updateSelect(formname,id);
1230: return;
1.41 ng 1231: }
1.44 ng 1232:
1.71 ng 1233: function clearRadBox(formname,id) {
1234: if (checkSolved(formname,id) == 'noupdate') {
1235: updateSelect(formname,id);
1236: return;
1237: }
1.125 ng 1238: gradeSelect = formname["GD_SEL"+id];
1.71 ng 1239: for (var i=0; i<gradeSelect.length; i++) {
1240: if (gradeSelect[i].selected) {
1241: var selectx=i;
1242: }
1243: }
1.125 ng 1244: var stores = formname["stores"+id];
1.71 ng 1245: if (selectx == stores.value) { return };
1.125 ng 1246: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1247: gradeBox.value = "";
1.125 ng 1248: var radioButton = formname["RADVAL"+id];
1.71 ng 1249: for (var i=0; i<radioButton.length; i++) {
1250: radioButton[i].checked=false;
1251: }
1252: stores.value = selectx;
1253: }
1.5 albertel 1254:
1.71 ng 1255: function checkSolved(formname,id) {
1.125 ng 1256: if (formname["solved"+id].value == "correct_by_student" && formname.overRideScore.value == 'no') {
1.118 ng 1257: var reply = confirm("This problem has been graded correct by the computer. Do you want to change the score?");
1258: if (!reply) {return "noupdate";}
1.120 ng 1259: formname.overRideScore.value = 'yes';
1.41 ng 1260: }
1.71 ng 1261: return "update";
1.13 albertel 1262: }
1.71 ng 1263:
1264: function updateSelect(formname,id) {
1.125 ng 1265: formname["GD_SEL"+id][0].selected = true;
1.71 ng 1266: return;
1.41 ng 1267: }
1.33 ng 1268:
1.121 ng 1269: //=========== Check that a point is assigned for all the parts ============
1.71 ng 1270: function checksubmit(formname,val,total,parttot) {
1.121 ng 1271: formname.gradeOpt.value = val;
1.71 ng 1272: if (val == "Save & Next") {
1273: for (i=0;i<=total;i++) {
1274: for (j=0;j<parttot;j++) {
1.125 ng 1275: var partid = formname["partid"+i+"_"+j].value;
1.127 ng 1276: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1277: var points = formname["GD_BOX"+i+"_"+partid].value;
1.71 ng 1278: if (points == "") {
1.125 ng 1279: var name = formname["name"+i].value;
1.129 ng 1280: var studentID = (name != '' ? name : formname["unamedom"+i].value);
1281: var resp = confirm("You did not assign a score for "+studentID+
1282: ", part "+partid+". Continue?");
1.71 ng 1283: if (resp == false) {
1.125 ng 1284: formname["GD_BOX"+i+"_"+partid].focus();
1.71 ng 1285: return false;
1286: }
1287: }
1288: }
1289:
1290: }
1291: }
1292:
1293: }
1.120 ng 1294: formname.submit();
1295: }
1296:
1.71 ng 1297: //======= Check that a score is assigned for all the problems (page/sequence grading only) =========
1298: function checkSubmitPage(formname,total) {
1299: noscore = new Array(100);
1300: var ptr = 0;
1301: for (i=1;i<total;i++) {
1.125 ng 1302: var partid = formname["q_"+i].value;
1.127 ng 1303: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1304: var points = formname["GD_BOX"+i+"_"+partid].value;
1305: var status = formname["solved"+i+"_"+partid].value;
1.71 ng 1306: if (points == "" && status != "correct_by_student") {
1307: noscore[ptr] = i;
1308: ptr++;
1309: }
1310: }
1311: }
1312: if (ptr != 0) {
1313: var sense = ptr == 1 ? ": " : "s: ";
1314: var prolist = "";
1315: if (ptr == 1) {
1316: prolist = noscore[0];
1317: } else {
1318: var i = 0;
1319: while (i < ptr-1) {
1320: prolist += noscore[i]+", ";
1321: i++;
1322: }
1323: prolist += "and "+noscore[i];
1324: }
1325: var resp = confirm("You did not assign any score for the following problem"+sense+prolist+". Continue?");
1326: if (resp == false) {
1327: return false;
1328: }
1329: }
1.45 ng 1330:
1.71 ng 1331: formname.submit();
1332: }
1333: SUBJAVASCRIPT
1334: }
1.45 ng 1335:
1.71 ng 1336: #--- javascript for essay type problem --
1337: sub sub_page_kw_js {
1338: my $request = shift;
1.80 ng 1339: my $iconpath = $request->dir_config('lonIconsURL');
1.118 ng 1340: &commonJSfunctions($request);
1.350 albertel 1341:
1.629 www 1342: my $inner_js_msg_central= (<<INNERJS);
1343: <script type="text/javascript">
1.350 albertel 1344: function checkInput() {
1345: opener.document.SCORE.msgsub.value = opener.checkEntities(document.msgcenter.msgsub.value);
1346: var nmsg = opener.document.SCORE.savemsgN.value;
1347: var usrctr = document.msgcenter.usrctr.value;
1348: var newval = opener.document.SCORE["newmsg"+usrctr];
1349: newval.value = opener.checkEntities(document.msgcenter.newmsg.value);
1350:
1351: var msgchk = "";
1352: if (document.msgcenter.subchk.checked) {
1353: msgchk = "msgsub,";
1354: }
1355: var includemsg = 0;
1356: for (var i=1; i<=nmsg; i++) {
1357: var opnmsg = opener.document.SCORE["savemsg"+i];
1358: var frmmsg = document.msgcenter["msg"+i];
1359: opnmsg.value = opener.checkEntities(frmmsg.value);
1360: var showflg = opener.document.SCORE["shownOnce"+i];
1361: showflg.value = "1";
1362: var chkbox = document.msgcenter["msgn"+i];
1363: if (chkbox.checked) {
1364: msgchk += "savemsg"+i+",";
1365: includemsg = 1;
1366: }
1367: }
1368: if (document.msgcenter.newmsgchk.checked) {
1369: msgchk += "newmsg"+usrctr;
1370: includemsg = 1;
1371: }
1372: imgformname = opener.document.SCORE["mailicon"+usrctr];
1373: imgformname.src = "$iconpath/"+((includemsg) ? "mailto.gif" : "mailbkgrd.gif");
1374: var includemsg = opener.document.SCORE["includemsg"+usrctr];
1375: includemsg.value = msgchk;
1376:
1377: self.close()
1378:
1379: }
1.629 www 1380: </script>
1.350 albertel 1381: INNERJS
1382:
1.629 www 1383: my $inner_js_highlight_central= (<<INNERJS);
1384: <script type="text/javascript">
1.351 albertel 1385: function updateChoice(flag) {
1386: opener.document.SCORE.kwclr.value = opener.radioSelection(document.hlCenter.kwdclr);
1387: opener.document.SCORE.kwsize.value = opener.radioSelection(document.hlCenter.kwdsize);
1388: opener.document.SCORE.kwstyle.value = opener.radioSelection(document.hlCenter.kwdstyle);
1389: opener.document.SCORE.refresh.value = "on";
1390: if (opener.document.SCORE.keywords.value!=""){
1391: opener.document.SCORE.submit();
1392: }
1393: self.close()
1394: }
1.629 www 1395: </script>
1.351 albertel 1396: INNERJS
1397:
1398: my $start_page_msg_central =
1399: &Apache::loncommon::start_page('Message Central',$inner_js_msg_central,
1400: {'js_ready' => 1,
1401: 'only_body' => 1,
1402: 'bgcolor' =>'#FFFFFF',});
1403: my $end_page_msg_central =
1404: &Apache::loncommon::end_page({'js_ready' => 1});
1405:
1406:
1407: my $start_page_highlight_central =
1408: &Apache::loncommon::start_page('Highlight Central',
1409: $inner_js_highlight_central,
1.350 albertel 1410: {'js_ready' => 1,
1411: 'only_body' => 1,
1412: 'bgcolor' =>'#FFFFFF',});
1.351 albertel 1413: my $end_page_highlight_central =
1.350 albertel 1414: &Apache::loncommon::end_page({'js_ready' => 1});
1415:
1.219 www 1416: my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
1.236 albertel 1417: $docopen=~s/^document\.//;
1.652 raeburn 1418: my %lt = &Apache::lonlocal::texthash(
1419: keyw => 'Keywords list, separated by a space. Add/delete to list if desired.',
1420: plse => 'Please select a word or group of words from document and then click this link.',
1421: adds => 'Add selection to keyword list? Edit if desired.',
1422: comp => 'Compose Message for: ',
1423: incl => 'Include',
1.656 raeburn 1424: type => 'Type',
1.652 raeburn 1425: subj => 'Subject',
1426: mesa => 'Message',
1427: new => 'New',
1428: save => 'Save',
1429: canc => 'Cancel',
1430: kehi => 'Keyword Highlight Options',
1431: txtc => 'Text Color',
1432: font => 'Font Size',
1.656 raeburn 1433: fnst => 'Font Style',
1.652 raeburn 1434: );
1.597 wenzelju 1435: $request->print(&Apache::lonhtmlcommon::scripttag(<<SUBJAVASCRIPT));
1.45 ng 1436:
1.44 ng 1437: //===================== Show list of keywords ====================
1.122 ng 1438: function keywords(formname) {
1.652 raeburn 1439: var nret = prompt("$lt{'keyw'}",formname.keywords.value);
1.44 ng 1440: if (nret==null) return;
1.122 ng 1441: formname.keywords.value = nret;
1.44 ng 1442:
1.122 ng 1443: if (formname.keywords.value != "") {
1.128 ng 1444: formname.refresh.value = "on";
1.122 ng 1445: formname.submit();
1.44 ng 1446: }
1447: return;
1448: }
1449:
1450: //===================== Script to view submitted by ==================
1451: function viewSubmitter(submitter) {
1452: document.SCORE.refresh.value = "on";
1453: document.SCORE.NCT.value = "1";
1454: document.SCORE.unamedom0.value = submitter;
1455: document.SCORE.submit();
1456: return;
1457: }
1458:
1459: //===================== Script to add keyword(s) ==================
1460: function getSel() {
1461: if (document.getSelection) txt = document.getSelection();
1462: else if (document.selection) txt = document.selection.createRange().text;
1463: else return;
1464: var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
1465: if (cleantxt=="") {
1.652 raeburn 1466: alert("$lt{'plse'}");
1.44 ng 1467: return;
1468: }
1.652 raeburn 1469: var nret = prompt("$lt{'adds'}",cleantxt);
1.44 ng 1470: if (nret==null) return;
1.127 ng 1471: document.SCORE.keywords.value = document.SCORE.keywords.value+" "+nret;
1.44 ng 1472: if (document.SCORE.keywords.value != "") {
1.127 ng 1473: document.SCORE.refresh.value = "on";
1.44 ng 1474: document.SCORE.submit();
1475: }
1476: return;
1477: }
1478:
1479: //====================== Script for composing message ==============
1.80 ng 1480: // preload images
1481: img1 = new Image();
1482: img1.src = "$iconpath/mailbkgrd.gif";
1483: img2 = new Image();
1484: img2.src = "$iconpath/mailto.gif";
1485:
1.44 ng 1486: function msgCenter(msgform,usrctr,fullname) {
1487: var Nmsg = msgform.savemsgN.value;
1488: savedMsgHeader(Nmsg,usrctr,fullname);
1489: var subject = msgform.msgsub.value;
1.127 ng 1490: var msgchk = document.SCORE["includemsg"+usrctr].value;
1.44 ng 1491: re = /msgsub/;
1492: var shwsel = "";
1493: if (re.test(msgchk)) { shwsel = "checked" }
1.123 ng 1494: subject = (document.SCORE.shownSub.value == 0 ? checkEntities(subject) : subject);
1495: displaySubject(checkEntities(subject),shwsel);
1.44 ng 1496: for (var i=1; i<=Nmsg; i++) {
1.123 ng 1497: var testmsg = "savemsg"+i+",";
1498: re = new RegExp(testmsg,"g");
1.44 ng 1499: shwsel = "";
1500: if (re.test(msgchk)) { shwsel = "checked" }
1.125 ng 1501: var message = document.SCORE["savemsg"+i].value;
1.126 ng 1502: message = (document.SCORE["shownOnce"+i].value == 0 ? checkEntities(message) : message);
1.123 ng 1503: displaySavedMsg(i,message,shwsel); //I do not get it. w/o checkEntities on saved messages,
1504: //any < is already converted to <, etc. However, only once!!
1.44 ng 1505: }
1.125 ng 1506: newmsg = document.SCORE["newmsg"+usrctr].value;
1.44 ng 1507: shwsel = "";
1508: re = /newmsg/;
1509: if (re.test(msgchk)) { shwsel = "checked" }
1510: newMsg(newmsg,shwsel);
1511: msgTail();
1512: return;
1513: }
1514:
1.123 ng 1515: function checkEntities(strx) {
1516: if (strx.length == 0) return strx;
1517: var orgStr = ["&", "<", ">", '"'];
1518: var newStr = ["&", "<", ">", """];
1519: var counter = 0;
1520: while (counter < 4) {
1521: strx = strReplace(strx,orgStr[counter],newStr[counter]);
1522: counter++;
1523: }
1524: return strx;
1525: }
1526:
1527: function strReplace(strx, orgStr, newStr) {
1528: return strx.split(orgStr).join(newStr);
1529: }
1530:
1.44 ng 1531: function savedMsgHeader(Nmsg,usrctr,fullname) {
1.76 ng 1532: var height = 70*Nmsg+250;
1.44 ng 1533: if (height > 600) {
1534: height = 600;
1535: }
1.118 ng 1536: var xpos = (screen.width-600)/2;
1537: xpos = (xpos < 0) ? '0' : xpos;
1538: var ypos = (screen.height-height)/2-30;
1539: ypos = (ypos < 0) ? '0' : ypos;
1540:
1.668 www 1541: pWin = window.open('', 'MessageCenter', 'resizable=yes,toolbar=no,location=no,scrollbars=yes,screenx='+xpos+',screeny='+ypos+',width=700,height='+height);
1.76 ng 1542: pWin.focus();
1543: pDoc = pWin.document;
1.219 www 1544: pDoc.$docopen;
1.351 albertel 1545: pDoc.write('$start_page_msg_central');
1.76 ng 1546:
1547: pDoc.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
1548: pDoc.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
1.676 golterma 1549: pDoc.write("<h1> $lt{'comp'}\"+fullname+\"<\\/h1>");
1.76 ng 1550:
1.676 golterma 1551: pDoc.write('<table style="border:1px solid black;"><tr>');
1552: pDoc.write("<td><b>$lt{'incl'}<\\/b><\\/td><td><b>$lt{'type'}<\\/b><\\/td><td><b>$lt{'mesa'}<\\/td><\\/tr>");
1.44 ng 1553: }
1554: function displaySubject(msg,shwsel) {
1.76 ng 1555: pDoc = pWin.document;
1.676 golterma 1556: pDoc.write("<tr>");
1557: pDoc.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1.652 raeburn 1558: pDoc.write("<td>$lt{'subj'}<\\/td>");
1.676 golterma 1559: pDoc.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+"\\"size=\\"40\\" maxlength=\\"80\\"><\\/td><\\/tr>");
1.44 ng 1560: }
1561:
1.72 ng 1562: function displaySavedMsg(ctr,msg,shwsel) {
1.76 ng 1563: pDoc = pWin.document;
1.676 golterma 1564: pDoc.write("<tr>");
1565: pDoc.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1.465 albertel 1566: pDoc.write("<td align=\\"center\\">"+ctr+"<\\/td>");
1567: pDoc.write("<td><textarea name=\\"msg"+ctr+"\\" cols=\\"60\\" rows=\\"3\\">"+msg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 1568: }
1569:
1570: function newMsg(newmsg,shwsel) {
1.76 ng 1571: pDoc = pWin.document;
1.676 golterma 1572: pDoc.write("<tr>");
1573: pDoc.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1.652 raeburn 1574: pDoc.write("<td align=\\"center\\">$lt{'new'}<\\/td>");
1.465 albertel 1575: pDoc.write("<td><textarea name=\\"newmsg\\" cols=\\"60\\" rows=\\"3\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" >"+newmsg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 1576: }
1577:
1578: function msgTail() {
1.76 ng 1579: pDoc = pWin.document;
1.676 golterma 1580: //pDoc.write("<\\/table>");
1.465 albertel 1581: pDoc.write("<\\/td><\\/tr><\\/table> ");
1.652 raeburn 1582: pDoc.write("<input type=\\"button\\" value=\\"$lt{'save'}\\" onclick=\\"javascript:checkInput()\\"> ");
1583: pDoc.write("<input type=\\"button\\" value=\\"$lt{'canc'}\\" onclick=\\"self.close()\\"><br /><br />");
1.465 albertel 1584: pDoc.write("<\\/form>");
1.351 albertel 1585: pDoc.write('$end_page_msg_central');
1.128 ng 1586: pDoc.close();
1.44 ng 1587: }
1588:
1589: //====================== Script for keyword highlight options ==============
1590: function kwhighlight() {
1591: var kwclr = document.SCORE.kwclr.value;
1592: var kwsize = document.SCORE.kwsize.value;
1593: var kwstyle = document.SCORE.kwstyle.value;
1594: var redsel = "";
1595: var grnsel = "";
1596: var blusel = "";
1597: if (kwclr=="red") {var redsel="checked"};
1598: if (kwclr=="green") {var grnsel="checked"};
1599: if (kwclr=="blue") {var blusel="checked"};
1600: var sznsel = "";
1601: var sz1sel = "";
1602: var sz2sel = "";
1603: if (kwsize=="0") {var sznsel="checked"};
1604: if (kwsize=="+1") {var sz1sel="checked"};
1605: if (kwsize=="+2") {var sz2sel="checked"};
1606: var synsel = "";
1607: var syisel = "";
1608: var sybsel = "";
1609: if (kwstyle=="") {var synsel="checked"};
1610: if (kwstyle=="<i>") {var syisel="checked"};
1611: if (kwstyle=="<b>") {var sybsel="checked"};
1612: highlightCentral();
1613: highlightbody('red','red',redsel,'0','normal',sznsel,'','normal',synsel);
1614: highlightbody('green','green',grnsel,'+1','+1',sz1sel,'<i>','italic',syisel);
1615: highlightbody('blue','blue',blusel,'+2','+2',sz2sel,'<b>','bold',sybsel);
1616: highlightend();
1617: return;
1618: }
1619:
1620: function highlightCentral() {
1.76 ng 1621: // if (window.hwdWin) window.hwdWin.close();
1.118 ng 1622: var xpos = (screen.width-400)/2;
1623: xpos = (xpos < 0) ? '0' : xpos;
1624: var ypos = (screen.height-330)/2-30;
1625: ypos = (ypos < 0) ? '0' : ypos;
1626:
1.206 albertel 1627: hwdWin = window.open('', 'KeywordHighlightCentral', 'resizeable=yes,toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx='+xpos+',screeny='+ypos);
1.76 ng 1628: hwdWin.focus();
1629: var hDoc = hwdWin.document;
1.219 www 1630: hDoc.$docopen;
1.351 albertel 1631: hDoc.write('$start_page_highlight_central');
1.76 ng 1632: hDoc.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
1.652 raeburn 1633: hDoc.write("<h3><span class=\\"LC_info\\"> $lt{'kehi'}<\\/span><\\/h3><br /><br />");
1.76 ng 1634:
1.564 bisitz 1635: hDoc.write('<table border="0" width="100%"><tr><td bgcolor="#777777">');
1636: hDoc.write('<table border="0" width="100%"><tr bgcolor="#DDFFFF">');
1.656 raeburn 1637: hDoc.write("<td><b>$lt{'txtc'}<\\/b><\\/td><td><b>$lt{'font'}<\\/b><\\/td><td><b>$lt{'fnst'}<\\/td><\\/tr>");
1.44 ng 1638: }
1639:
1640: function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) {
1.76 ng 1641: var hDoc = hwdWin.document;
1642: hDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1643: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1644: hDoc.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+"> "+clrtxt+"<\\/td>");
1.76 ng 1645: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1646: hDoc.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+"> "+sztxt+"<\\/td>");
1.76 ng 1647: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1648: hDoc.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+"> "+sytxt+"<\\/td>");
1649: hDoc.write("<\\/tr>");
1.44 ng 1650: }
1651:
1652: function highlightend() {
1.76 ng 1653: var hDoc = hwdWin.document;
1.465 albertel 1654: hDoc.write("<\\/table>");
1655: hDoc.write("<\\/td><\\/tr><\\/table> ");
1.652 raeburn 1656: hDoc.write("<input type=\\"button\\" value=\\"$lt{'save'}\\" onclick=\\"javascript:updateChoice(1)\\"> ");
1657: hDoc.write("<input type=\\"button\\" value=\\"$lt{'canc'}\\" onclick=\\"self.close()\\"><br /><br />");
1.465 albertel 1658: hDoc.write("<\\/form>");
1.351 albertel 1659: hDoc.write('$end_page_highlight_central');
1.128 ng 1660: hDoc.close();
1.44 ng 1661: }
1662:
1663: SUBJAVASCRIPT
1664: }
1665:
1.349 albertel 1666: sub get_increment {
1.348 bowersj2 1667: my $increment = $env{'form.increment'};
1668: if ($increment != 1 && $increment != .5 && $increment != .25 &&
1669: $increment != .1) {
1670: $increment = 1;
1671: }
1672: return $increment;
1673: }
1674:
1.585 bisitz 1675: sub gradeBox_start {
1676: return (
1677: &Apache::loncommon::start_data_table()
1678: .&Apache::loncommon::start_data_table_header_row()
1679: .'<th>'.&mt('Part').'</th>'
1680: .'<th>'.&mt('Points').'</th>'
1681: .'<th> </th>'
1682: .'<th>'.&mt('Assign Grade').'</th>'
1683: .'<th>'.&mt('Weight').'</th>'
1684: .'<th>'.&mt('Grade Status').'</th>'
1685: .&Apache::loncommon::end_data_table_header_row()
1686: );
1687: }
1688:
1689: sub gradeBox_end {
1690: return (
1691: &Apache::loncommon::end_data_table()
1692: );
1693: }
1.71 ng 1694: #--- displays the grading box, used in essay type problem and grading by page/sequence
1695: sub gradeBox {
1.322 albertel 1696: my ($request,$symb,$uname,$udom,$counter,$partid,$record) = @_;
1.381 albertel 1697: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 1698: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 1699: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
1.466 albertel 1700: my $wgtmsg = ($wgt > 0) ? &mt('(problem weight)')
1701: : '<span class="LC_info">'.&mt('problem weight assigned by computer').'</span>';
1.71 ng 1702: $wgt = ($wgt > 0 ? $wgt : '1');
1703: my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
1.320 albertel 1704: '' : &compute_points($$record{'resource.'.$partid.'.awarded'},$wgt));
1.71 ng 1705: my $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />'."\n";
1.466 albertel 1706: my $display_part= &get_display_part($partid,$symb);
1.270 albertel 1707: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
1708: [$partid]);
1709: my $aggtries = $$record{'resource.'.$partid.'.tries'};
1.269 raeburn 1710: if ($last_resets{$partid}) {
1711: $aggtries = &get_num_tries($record,$last_resets{$partid},$partid);
1712: }
1.585 bisitz 1713: $result.=&Apache::loncommon::start_data_table_row();
1.71 ng 1714: my $ctr = 0;
1.348 bowersj2 1715: my $thisweight = 0;
1.349 albertel 1716: my $increment = &get_increment();
1.485 albertel 1717:
1718: my $radio.='<table border="0"><tr>'."\n"; # display radio buttons in a nice table 10 across
1.348 bowersj2 1719: while ($thisweight<=$wgt) {
1.532 bisitz 1720: $radio.= '<td><span class="LC_nobreak"><label><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
1.589 bisitz 1721: 'onclick="javascript:writeBox(this.form,\''.$counter.'_'.$partid.'\','.
1.348 bowersj2 1722: $thisweight.')" value="'.$thisweight.'" '.
1.401 albertel 1723: ($score eq $thisweight ? 'checked="checked"':'').' /> '.$thisweight."</label></span></td>\n";
1.485 albertel 1724: $radio.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1.348 bowersj2 1725: $thisweight += $increment;
1.71 ng 1726: $ctr++;
1727: }
1.485 albertel 1728: $radio.='</tr></table>';
1729:
1730: my $line.='<input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
1.71 ng 1731: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
1.589 bisitz 1732: 'onchange="javascript:updateRadio(this.form,\''.$counter.'_'.$partid.'\','.
1.71 ng 1733: $wgt.')" /></td>'."\n";
1.485 albertel 1734: $line.='<td>/'.$wgt.' '.$wgtmsg.
1.71 ng 1735: ($$record{'resource.'.$partid.'.solved'} eq 'correct_by_student' ? ' '.$checkIcon : '').
1.585 bisitz 1736: ' </td>'."\n";
1737: $line.='<td><select name="GD_SEL'.$counter.'_'.$partid.'" '.
1.589 bisitz 1738: 'onchange="javascript:clearRadBox(this.form,\''.$counter.'_'.$partid.'\')" >'."\n";
1.71 ng 1739: if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
1.485 albertel 1740: $line.='<option></option>'.
1741: '<option value="excused" selected="selected">'.&mt('excused').'</option>';
1.71 ng 1742: } else {
1.485 albertel 1743: $line.='<option selected="selected"></option>'.
1744: '<option value="excused" >'.&mt('excused').'</option>';
1.71 ng 1745: }
1.485 albertel 1746: $line.='<option value="reset status">'.&mt('reset status').'</option></select>'."\n";
1747:
1748:
1749: $result .=
1.585 bisitz 1750: '<td>'.$display_part.'</td><td>'.$radio.'</td><td>'.&mt('or').'</td><td>'.$line.'</td>';
1751: $result.=&Apache::loncommon::end_data_table_row();
1.71 ng 1752: $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="" />'."\n".
1753: '<input type="hidden" name="oldpts'.$counter.'_'.$partid.'" value="'.$score.'" />'."\n".
1754: '<input type="hidden" name="solved'.$counter.'_'.$partid.'" value="'.
1.269 raeburn 1755: $$record{'resource.'.$partid.'.solved'}.'" />'."\n".
1756: '<input type="hidden" name="totaltries'.$counter.'_'.$partid.'" value="'.
1757: $$record{'resource.'.$partid.'.tries'}.'" />'."\n".
1758: '<input type="hidden" name="aggtries'.$counter.'_'.$partid.'" value="'.
1759: $aggtries.'" />'."\n";
1.582 raeburn 1760: my $res_error;
1761: $result.=&handback_box($symb,$uname,$udom,$counter,$partid,$record,\$res_error);
1762: if ($res_error) {
1763: return &navmap_errormsg();
1764: }
1.318 banghart 1765: return $result;
1766: }
1.322 albertel 1767:
1768: sub handback_box {
1.623 www 1769: my ($symb,$uname,$udom,$counter,$partid,$record,$res_error_pointer) = @_;
1770: my ($partlist,$handgrade,$responseType) = &response_type($symb,$res_error_pointer);
1.323 banghart 1771: my (@respids);
1.652 raeburn 1772: my @part_response_id = &flatten_responseType($responseType);
1.375 albertel 1773: foreach my $part_response_id (@part_response_id) {
1774: my ($part,$resp) = @{ $part_response_id };
1.323 banghart 1775: if ($part eq $partid) {
1.375 albertel 1776: push(@respids,$resp);
1.323 banghart 1777: }
1778: }
1.318 banghart 1779: my $result;
1.323 banghart 1780: foreach my $respid (@respids) {
1.322 albertel 1781: my $prefix = $counter.'_'.$partid.'_'.$respid.'_';
1782: my $files=&get_submitted_files($udom,$uname,$partid,$respid,$record);
1783: next if (!@$files);
1.654 raeburn 1784: my $file_counter = 0;
1.313 banghart 1785: foreach my $file (@$files) {
1.368 banghart 1786: if ($file =~ /\/portfolio\//) {
1.654 raeburn 1787: $file_counter++;
1.368 banghart 1788: my ($file_path, $file_disp) = ($file =~ m|(.+/)(.+)$|);
1789: my ($name,$version,$ext) = &file_name_version_ext($file_disp);
1790: $file_disp = "$name.$ext";
1791: $file = $file_path.$file_disp;
1792: $result.=&mt('Return commented version of [_1] to student.',
1793: '<span class="LC_filename">'.$file_disp.'</span>');
1794: $result.='<input type="file" name="'.$prefix.'returndoc'.$file_counter.'" />'."\n";
1.654 raeburn 1795: $result.='<input type="hidden" name="'.$prefix.'origdoc'.$file_counter.'" value="'.$file.'" /><br />'."\n";
1.368 banghart 1796: }
1.322 albertel 1797: }
1.654 raeburn 1798: if ($file_counter) {
1799: $result .= '<input type="hidden" name="'.$prefix.'countreturndoc" value="'.$file_counter.'" />'."\n".
1800: '<span class="LC_info">'.
1801: '('.&mt('File(s) will be uploaded when you click on Save & Next below.',$file_counter).')</span><br /><br />';
1802: }
1.313 banghart 1803: }
1.318 banghart 1804: return $result;
1.71 ng 1805: }
1.44 ng 1806:
1.58 albertel 1807: sub show_problem {
1.382 albertel 1808: my ($request,$symb,$uname,$udom,$removeform,$viewon,$mode,$form) = @_;
1.144 albertel 1809: my $rendered;
1.382 albertel 1810: my %form = ((ref($form) eq 'HASH')? %{$form} : ());
1.329 albertel 1811: &Apache::lonxml::remember_problem_counter();
1.144 albertel 1812: if ($mode eq 'both' or $mode eq 'text') {
1813: $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
1.382 albertel 1814: $env{'request.course.id'},
1815: undef,\%form);
1.144 albertel 1816: }
1.58 albertel 1817: if ($removeform) {
1818: $rendered=~s|<form(.*?)>||g;
1819: $rendered=~s|</form>||g;
1.374 albertel 1820: $rendered=~s|(<input[^>]*name\s*=\s*"?)(\w+)("?)|$1would_have_been_$2$3|g;
1.58 albertel 1821: }
1.144 albertel 1822: my $companswer;
1823: if ($mode eq 'both' or $mode eq 'answer') {
1.329 albertel 1824: &Apache::lonxml::restore_problem_counter();
1.382 albertel 1825: $companswer=
1826: &Apache::loncommon::get_student_answers($symb,$uname,$udom,
1827: $env{'request.course.id'},
1828: %form);
1.144 albertel 1829: }
1.58 albertel 1830: if ($removeform) {
1831: $companswer=~s|<form(.*?)>||g;
1832: $companswer=~s|</form>||g;
1.144 albertel 1833: $companswer=~s|name="submit"|name="would_have_been_submit"|g;
1.58 albertel 1834: }
1.671 raeburn 1835: my $renderheading = &mt('View of the problem');
1836: my $answerheading = &mt('Correct answer');
1837: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1838: my $stu_fullname = $env{'form.fullname'};
1839: if ($stu_fullname eq '') {
1840: $stu_fullname = &Apache::loncommon::plainname($uname,$udom,'lastname');
1841: }
1842: my $forwhom = &nameUserString(undef,$stu_fullname,$uname,$udom);
1843: if ($forwhom ne '') {
1844: $renderheading = &mt('View of the problem for[_1]',$forwhom);
1845: $answerheading = &mt('Correct answer for[_1]',$forwhom);
1846: }
1847: }
1.468 albertel 1848: $rendered=
1.588 bisitz 1849: '<div class="LC_Box">'
1.671 raeburn 1850: .'<h3 class="LC_hcell">'.$renderheading.'</h3>'
1.588 bisitz 1851: .$rendered
1852: .'</div>';
1.468 albertel 1853: $companswer=
1.588 bisitz 1854: '<div class="LC_Box">'
1.671 raeburn 1855: .'<h3 class="LC_hcell">'.$answerheading.'</h3>'
1.588 bisitz 1856: .$companswer
1857: .'</div>';
1.468 albertel 1858: my $result;
1.144 albertel 1859: if ($mode eq 'both') {
1.588 bisitz 1860: $result=$rendered.$companswer;
1.144 albertel 1861: } elsif ($mode eq 'text') {
1.588 bisitz 1862: $result=$rendered;
1.144 albertel 1863: } elsif ($mode eq 'answer') {
1.588 bisitz 1864: $result=$companswer;
1.144 albertel 1865: }
1.71 ng 1866: return $result;
1.58 albertel 1867: }
1.397 albertel 1868:
1.396 banghart 1869: sub files_exist {
1870: my ($r, $symb) = @_;
1871: my @students = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.397 albertel 1872:
1.396 banghart 1873: foreach my $student (@students) {
1874: my ($uname,$udom,$fullname) = split(/:/,$student);
1.397 albertel 1875: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1876: $udom,$uname);
1.396 banghart 1877: my ($string,$timestamp)= &get_last_submission(\%record);
1.397 albertel 1878: foreach my $submission (@$string) {
1879: my ($partid,$respid) =
1880: ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
1881: my $files=&get_submitted_files($udom,$uname,$partid,$respid,
1882: \%record);
1883: return 1 if (@$files);
1.396 banghart 1884: }
1885: }
1.397 albertel 1886: return 0;
1.396 banghart 1887: }
1.397 albertel 1888:
1.394 banghart 1889: sub download_all_link {
1890: my ($r,$symb) = @_;
1.621 www 1891: unless (&files_exist($r, $symb)) {
1892: $r->print(&mt('There are currently no submitted documents.'));
1893: return;
1894: }
1895:
1.395 albertel 1896: my $all_students =
1897: join("\n", &Apache::loncommon::get_env_multiple('form.stuinfo'));
1898:
1899: my $parts =
1900: join("\n",&Apache::loncommon::get_env_multiple('form.vPart'));
1901:
1.394 banghart 1902: my $identifier = &Apache::loncommon::get_cgi_id();
1.514 raeburn 1903: &Apache::lonnet::appenv({'cgi.'.$identifier.'.students' => $all_students,
1904: 'cgi.'.$identifier.'.symb' => $symb,
1905: 'cgi.'.$identifier.'.parts' => $parts,});
1.395 albertel 1906: $r->print('<a href="/cgi-bin/multidownload.pl?'.$identifier.'">'.
1907: &mt('Download All Submitted Documents').'</a>');
1.621 www 1908: return;
1909: }
1910:
1911: sub submit_download_link {
1912: my ($request,$symb) = @_;
1913: if (!$symb) { return ''; }
1914: #FIXME: Figure out which type of problem this is and provide appropriate download
1915: &download_all_link($request,$symb);
1.394 banghart 1916: }
1.395 albertel 1917:
1.432 banghart 1918: sub build_section_inputs {
1919: my $section_inputs;
1920: if ($env{'form.section'} eq '') {
1921: $section_inputs .= '<input type="hidden" name="section" value="all" />'."\n";
1922: } else {
1923: my @sections = &Apache::loncommon::get_env_multiple('form.section');
1.434 albertel 1924: foreach my $section (@sections) {
1.432 banghart 1925: $section_inputs .= '<input type="hidden" name="section" value="'.$section.'" />'."\n";
1926: }
1927: }
1928: return $section_inputs;
1929: }
1930:
1.44 ng 1931: # --------------------------- show submissions of a student, option to grade
1932: sub submission {
1.608 www 1933: my ($request,$counter,$total,$symb) = @_;
1.257 albertel 1934: my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
1935: $udom = ($udom eq '' ? $env{'user.domain'} : $udom); #has form.userdom changed for a student?
1936: my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
1937: $env{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $env{'form.fullname'} eq '';
1.608 www 1938:
1.605 www 1939: my $probtitle=&Apache::lonnet::gettitle($symb);
1.324 albertel 1940: if ($symb eq '') { $request->print("Unable to handle ambiguous references:."); return ''; }
1.104 albertel 1941:
1942: if (!&canview($usec)) {
1.398 albertel 1943: $request->print('<span class="LC_warning">Unable to view requested student.('.
1944: $uname.':'.$udom.' in section '.$usec.' in course id '.
1945: $env{'request.course.id'}.')</span>');
1.104 albertel 1946: return;
1947: }
1948:
1.257 albertel 1949: if (!$env{'form.lastSub'}) { $env{'form.lastSub'} = 'datesub'; }
1950: if (!$env{'form.vProb'}) { $env{'form.vProb'} = 'yes'; }
1951: if (!$env{'form.vAns'}) { $env{'form.vAns'} = 'yes'; }
1952: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.381 albertel 1953: my $checkIcon = '<img alt="'.&mt('Check Mark').
1954: '" src="'.$request->dir_config('lonIconsURL').
1.122 ng 1955: '/check.gif" height="16" border="0" />';
1.41 ng 1956:
1957: # header info
1958: if ($counter == 0) {
1959: &sub_page_js($request);
1.621 www 1960: &sub_page_kw_js($request);
1.118 ng 1961:
1.44 ng 1962: # option to display problem, only once else it cause problems
1963: # with the form later since the problem has a form.
1.257 albertel 1964: if ($env{'form.vProb'} eq 'yes' or $env{'form.vAns'} eq 'yes') {
1.144 albertel 1965: my $mode;
1.257 albertel 1966: if ($env{'form.vProb'} eq 'yes' && $env{'form.vAns'} eq 'yes') {
1.144 albertel 1967: $mode='both';
1.257 albertel 1968: } elsif ($env{'form.vProb'} eq 'yes') {
1.144 albertel 1969: $mode='text';
1.257 albertel 1970: } elsif ($env{'form.vAns'} eq 'yes') {
1.144 albertel 1971: $mode='answer';
1972: }
1.329 albertel 1973: &Apache::lonxml::clear_problem_counter();
1.144 albertel 1974: $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
1.41 ng 1975: }
1.441 www 1976:
1.44 ng 1977: # kwclr is the only variable that is guaranteed to be non blank
1978: # if this subroutine has been called once.
1.41 ng 1979: my %keyhash = ();
1.624 www 1980: # if ($env{'form.kwclr'} eq '' && $env{'form.handgrade'} eq 'yes') {
1981: if (1) {
1.41 ng 1982: %keyhash = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 1983: $env{'course.'.$env{'request.course.id'}.'.domain'},
1984: $env{'course.'.$env{'request.course.id'}.'.num'});
1.41 ng 1985:
1.257 albertel 1986: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1987: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
1988: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
1989: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
1990: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
1991: $env{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
1.605 www 1992: $keyhash{$symb.'_subject'} : $probtitle;
1.257 albertel 1993: $env{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1.41 ng 1994: }
1.257 albertel 1995: my $overRideScore = $env{'form.overRideScore'} eq '' ? 'no' : $env{'form.overRideScore'};
1.442 banghart 1996: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.303 banghart 1997: $request->print('<form action="/adm/grades" method="post" name="SCORE" enctype="multipart/form-data">'."\n".
1.41 ng 1998: '<input type="hidden" name="command" value="handgrade" />'."\n".
1.442 banghart 1999: '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.120 ng 2000: '<input type="hidden" name="overRideScore" value="'.$overRideScore.'" />'."\n".
1.41 ng 2001: '<input type="hidden" name="refresh" value="off" />'."\n".
1.120 ng 2002: '<input type="hidden" name="studentNo" value="" />'."\n".
2003: '<input type="hidden" name="gradeOpt" value="" />'."\n".
1.418 albertel 2004: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 2005: '<input type="hidden" name="vProb" value="'.$env{'form.vProb'}.'" />'."\n".
2006: '<input type="hidden" name="vAns" value="'.$env{'form.vAns'}.'" />'."\n".
2007: '<input type="hidden" name="lastSub" value="'.$env{'form.lastSub'}.'" />'."\n".
1.432 banghart 2008: &build_section_inputs().
1.326 albertel 2009: '<input type="hidden" name="submitonly" value="'.$env{'form.submitonly'}.'" />'."\n".
1.41 ng 2010: '<input type="hidden" name="NCT"'.
1.257 albertel 2011: ' value="'.($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : $total+1).'" />'."\n");
1.624 www 2012: # if ($env{'form.handgrade'} eq 'yes') {
2013: if (1) {
1.257 albertel 2014: $request->print('<input type="hidden" name="keywords" value="'.$env{'form.keywords'}.'" />'."\n".
2015: '<input type="hidden" name="kwclr" value="'.$env{'form.kwclr'}.'" />'."\n".
2016: '<input type="hidden" name="kwsize" value="'.$env{'form.kwsize'}.'" />'."\n".
2017: '<input type="hidden" name="kwstyle" value="'.$env{'form.kwstyle'}.'" />'."\n".
2018: '<input type="hidden" name="msgsub" value="'.$env{'form.msgsub'}.'" />'."\n".
1.123 ng 2019: '<input type="hidden" name="shownSub" value="0" />'."\n".
1.257 albertel 2020: '<input type="hidden" name="savemsgN" value="'.$env{'form.savemsgN'}.'" />'."\n");
1.154 albertel 2021: foreach my $partid (&Apache::loncommon::get_env_multiple('form.vPart')) {
2022: $request->print('<input type="hidden" name="vPart" value="'.$partid.'" />'."\n");
2023: }
1.123 ng 2024: }
1.41 ng 2025:
2026: my ($cts,$prnmsg) = (1,'');
1.257 albertel 2027: while ($cts <= $env{'form.savemsgN'}) {
1.41 ng 2028: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
1.123 ng 2029: (!exists($keyhash{$symb.'_savemsg'.$cts}) ?
1.257 albertel 2030: &Apache::lonfeedback::clear_out_html($env{'form.savemsg'.$cts}) :
1.80 ng 2031: &Apache::lonfeedback::clear_out_html($keyhash{$symb.'_savemsg'.$cts})).
1.123 ng 2032: '" />'."\n".
2033: '<input type="hidden" name="shownOnce'.$cts.'" value="0" />'."\n";
1.41 ng 2034: $cts++;
2035: }
2036: $request->print($prnmsg);
1.32 ng 2037:
1.624 www 2038: # if ($env{'form.handgrade'} eq 'yes') {
2039: if (1) {
1.652 raeburn 2040:
2041: my %lt = &Apache::lonlocal::texthash(
2042: keyw => 'Keyword Options',
1.655 raeburn 2043: list => 'List',
1.652 raeburn 2044: past => 'Paste Selection to List',
1.661 www 2045: high => 'Highlight Attribute',
1.652 raeburn 2046: );
1.88 www 2047: #
2048: # Print out the keyword options line
2049: #
1.41 ng 2050: $request->print(<<KEYWORDS);
1.652 raeburn 2051: <br /><b>$lt{'keyw'}:</b>
1.655 raeburn 2052: <a href="javascript:keywords(document.SCORE);" target="_self">$lt{'list'}</a>
1.589 bisitz 2053: <a href="#" onmousedown="javascript:getSel(); return false"
1.652 raeburn 2054: CLASS="page">$lt{'past'}</a>
2055: <a href="javascript:kwhighlight();" target="_self">$lt{'high'}</a><br /><br />
1.38 ng 2056: KEYWORDS
1.88 www 2057: #
2058: # Load the other essays for similarity check
2059: #
1.324 albertel 2060: my (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb);
1.384 albertel 2061: my ($adom,$aname,$apath)=($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
1.359 www 2062: $apath=&escape($apath);
1.88 www 2063: $apath=~s/\W/\_/gs;
1.674 raeburn 2064: &init_old_essays($symb,$apath,$adom,$aname);
1.41 ng 2065: }
2066: }
1.44 ng 2067:
1.441 www 2068: # This is where output for one specific student would start
1.592 bisitz 2069: my $add_class = ($counter%2) ? ' LC_grade_show_user_odd_row' : '';
2070: $request->print(
2071: "\n\n"
2072: .'<div class="LC_grade_show_user'.$add_class.'">'
2073: .'<h2>'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).'</h2>'
2074: ."\n"
2075: );
1.441 www 2076:
1.592 bisitz 2077: # Show additional functions if allowed
2078: if ($perm{'vgr'}) {
2079: $request->print(
2080: &Apache::loncommon::track_student_link(
2081: &mt('View recent activity'),
2082: $uname,$udom,'check')
2083: .' '
2084: );
2085: }
2086: if ($perm{'opa'}) {
2087: $request->print(
2088: &Apache::loncommon::pprmlink(
2089: &mt('Set/Change parameters'),
2090: $uname,$udom,$symb,'check'));
2091: }
2092:
2093: # Show Problem
1.257 albertel 2094: if ($env{'form.vProb'} eq 'all' or $env{'form.vAns'} eq 'all') {
1.144 albertel 2095: my $mode;
1.257 albertel 2096: if ($env{'form.vProb'} eq 'all' && $env{'form.vAns'} eq 'all') {
1.144 albertel 2097: $mode='both';
1.257 albertel 2098: } elsif ($env{'form.vProb'} eq 'all' ) {
1.144 albertel 2099: $mode='text';
1.257 albertel 2100: } elsif ($env{'form.vAns'} eq 'all') {
1.144 albertel 2101: $mode='answer';
2102: }
1.329 albertel 2103: &Apache::lonxml::clear_problem_counter();
1.475 albertel 2104: $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode,{'request.prefix' => 'ctr'.$counter}));
1.58 albertel 2105: }
1.144 albertel 2106:
1.257 albertel 2107: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.582 raeburn 2108: my $res_error;
2109: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
2110: if ($res_error) {
2111: $request->print(&navmap_errormsg());
2112: return;
2113: }
1.41 ng 2114:
1.44 ng 2115: # Display student info
1.41 ng 2116: $request->print(($counter == 0 ? '' : '<br />'));
1.590 bisitz 2117:
2118: my $result='<div class="LC_Box">'
2119: .'<h3 class="LC_hcell">'.&mt('Submissions').'</h3>';
1.45 ng 2120: $result.='<input type="hidden" name="name'.$counter.
1.588 bisitz 2121: '" value="'.$env{'form.fullname'}.'" />'."\n";
1.624 www 2122: # if ($env{'form.handgrade'} eq 'no') {
2123: if (1) {
1.588 bisitz 2124: $result.='<p class="LC_info">'
2125: .&mt('Part(s) graded correct by the computer is marked with a [_1] symbol.',$checkIcon)
2126: ."</p>\n";
1.469 albertel 2127: }
2128:
1.118 ng 2129: # If any part of the problem is an essay-response (handgraded), then check for collaborators
1.464 albertel 2130: my $fullname;
2131: my $col_fullnames = [];
1.624 www 2132: # if ($env{'form.handgrade'} eq 'yes') {
2133: if (1) {
1.464 albertel 2134: (my $sub_result,$fullname,$col_fullnames)=
2135: &check_collaborators($symb,$uname,$udom,\%record,$handgrade,
2136: $counter);
2137: $result.=$sub_result;
1.41 ng 2138: }
1.44 ng 2139: $request->print($result."\n");
1.588 bisitz 2140:
1.44 ng 2141: # print student answer/submission
1.588 bisitz 2142: # Options are (1) Handgraded submission only
1.44 ng 2143: # (2) Last submission, includes submission that is not handgraded
2144: # (for multi-response type part)
2145: # (3) Last submission plus the parts info
2146: # (4) The whole record for this student
1.257 albertel 2147: if ($env{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
1.151 albertel 2148: my ($string,$timestamp)= &get_last_submission(\%record);
1.468 albertel 2149:
2150: my $lastsubonly;
2151:
1.588 bisitz 2152: if ($$timestamp eq '') {
2153: $lastsubonly.='<div class="LC_grade_submissions_body">'.$$string[0].'</div>';
2154: } else {
1.592 bisitz 2155: $lastsubonly =
2156: '<div class="LC_grade_submissions_body">'
2157: .'<b>'.&mt('Date Submitted:').'</b> '.$$timestamp."\n";
1.468 albertel 2158:
1.151 albertel 2159: my %seenparts;
1.375 albertel 2160: my @part_response_id = &flatten_responseType($responseType);
2161: foreach my $part (@part_response_id) {
1.393 albertel 2162: next if ($env{'form.lastSub'} eq 'hdgrade'
2163: && $$handgrade{$$part[0].'_'.$$part[1]} ne 'yes');
2164:
1.375 albertel 2165: my ($partid,$respid) = @{ $part };
1.324 albertel 2166: my $display_part=&get_display_part($partid,$symb);
1.257 albertel 2167: if ($env{"form.$uname:$udom:$partid:submitted_by"}) {
1.151 albertel 2168: if (exists($seenparts{$partid})) { next; }
2169: $seenparts{$partid}=1;
1.207 albertel 2170: my $submitby='<b>Part:</b> '.$display_part.
2171: ' <b>Collaborative submission by:</b> '.
1.151 albertel 2172: '<a href="javascript:viewSubmitter(\''.
1.257 albertel 2173: $env{"form.$uname:$udom:$partid:submitted_by"}.
1.417 albertel 2174: '\');" target="_self">'.
1.257 albertel 2175: $$fullname{$env{"form.$uname:$udom:$partid:submitted_by"}}.'</a><br />';
1.151 albertel 2176: $request->print($submitby);
2177: next;
2178: }
2179: my $responsetype = $responseType->{$partid}->{$respid};
2180: if (!exists($record{"resource.$partid.$respid.submission"})) {
1.577 bisitz 2181: $lastsubonly.="\n".'<div class="LC_grade_submission_part">'.
2182: '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
2183: ' <span class="LC_internal_info">'.
1.623 www 2184: '('.&mt('Response ID: [_1]',$respid).')'.
1.577 bisitz 2185: '</span> '.
1.539 riegler 2186: '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br /><br /></div>';
1.151 albertel 2187: next;
2188: }
1.468 albertel 2189: foreach my $submission (@$string) {
2190: my ($partid,$respid) = ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
1.375 albertel 2191: if (join('_',@{$part}) ne ($partid.'_'.$respid)) { next; }
1.596 raeburn 2192: my ($ressub,$hide,$subval) = split(/:/,$submission,3);
1.151 albertel 2193: # Similarity check
2194: my $similar='';
1.640 raeburn 2195: my ($type,$trial,$rndseed);
2196: if ($hide eq 'rand') {
2197: $type = 'randomizetry';
2198: $trial = $record{"resource.$partid.tries"};
2199: $rndseed = $record{"resource.$partid.rndseed"};
2200: }
1.257 albertel 2201: if($env{'form.checkPlag'}){
1.151 albertel 2202: my ($oname,$odom,$ocrsid,$oessay,$osim)=
1.674 raeburn 2203: &most_similar($uname,$udom,$symb,$subval);
1.151 albertel 2204: if ($osim) {
2205: $osim=int($osim*100.0);
1.426 albertel 2206: my %old_course_desc =
2207: &Apache::lonnet::coursedescription($ocrsid,
2208: {'one_time' => 1});
2209:
1.640 raeburn 2210: if ($hide eq 'anon') {
1.596 raeburn 2211: $similar='<hr /><span class="LC_warning">'.&mt("Essay was found to be similar to another essay submitted for this assignment.").'<br />'.
2212: &mt('As the current submission is for an anonymous survey, no other details are available.').'</span><hr />';
2213: } else {
2214: $similar="<hr /><h3><span class=\"LC_warning\">".
2215: &mt('Essay is [_1]% similar to an essay by [_2] in course [_3] (course id [_4]:[_5])',
2216: $osim,
2217: &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')',
2218: $old_course_desc{'description'},
2219: $old_course_desc{'num'},
2220: $old_course_desc{'domain'}).
2221: '</span></h3><blockquote><i>'.
2222: &keywords_highlight($oessay).
2223: '</i></blockquote><hr />';
2224: }
1.151 albertel 2225: }
1.150 albertel 2226: }
1.640 raeburn 2227: my $order=&get_order($partid,$respid,$symb,$uname,$udom,
2228: undef,$type,$trial,$rndseed);
1.257 albertel 2229: if ($env{'form.lastSub'} eq 'lastonly' ||
2230: ($env{'form.lastSub'} eq 'hdgrade' &&
1.377 albertel 2231: $$handgrade{$$part[0].'_'.$$part[1]} eq 'yes')) {
1.324 albertel 2232: my $display_part=&get_display_part($partid,$symb);
1.577 bisitz 2233: $lastsubonly.='<div class="LC_grade_submission_part">'.
2234: '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
2235: ' <span class="LC_internal_info">'.
1.623 www 2236: '('.&mt('Response ID: [_1]',$respid).')'.
1.597 wenzelju 2237: '</span> ';
1.313 banghart 2238: my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record);
2239: if (@$files) {
1.640 raeburn 2240: if ($hide eq 'anon') {
1.596 raeburn 2241: $lastsubonly.='<br />'.&mt('[quant,_1,file] uploaded to this anonymous survey',scalar(@{$files}));
2242: } else {
2243: $lastsubonly.='<br /><span class="LC_warning">'.&mt('Like all files provided by users, this file may contain viruses').'</span><br />';
2244: foreach my $file (@$files) {
2245: &Apache::lonnet::allowuploaded('/adm/grades',$file);
2246: $lastsubonly.='<br /><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.&Apache::loncommon::icon($file).'" border="0" /> '.$file.'</a>';
2247: }
2248: }
1.236 albertel 2249: $lastsubonly.='<br />';
1.41 ng 2250: }
1.640 raeburn 2251: if ($hide eq 'anon') {
1.596 raeburn 2252: $lastsubonly.='<b>'.&mt('Anonymous Survey').'</b>';
2253: } else {
2254: $lastsubonly.='<b>'.&mt('Submitted Answer:').' </b>'.
2255: &cleanRecord($subval,$responsetype,$symb,$partid,
1.640 raeburn 2256: $respid,\%record,$order,undef,$uname,$udom,$type,$trial,$rndseed);
1.596 raeburn 2257: }
1.151 albertel 2258: if ($similar) {$lastsubonly.="<br /><br />$similar\n";}
1.468 albertel 2259: $lastsubonly.='</div>';
1.41 ng 2260: }
2261: }
2262: }
1.588 bisitz 2263: $lastsubonly.='</div>'."\n"; # End: LC_grade_submissions_body
1.151 albertel 2264: }
2265: $request->print($lastsubonly);
1.468 albertel 2266: } elsif ($env{'form.lastSub'} eq 'datesub') {
1.623 www 2267: my ($parts,$handgrade,$responseType) = &response_type($symb,\$res_error);
1.148 albertel 2268: $request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
1.257 albertel 2269: } elsif ($env{'form.lastSub'} =~ /^(last|all)$/) {
1.41 ng 2270: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
1.257 albertel 2271: $env{'request.course.id'},
1.44 ng 2272: $last,'.submission',
2273: 'Apache::grades::keywords_highlight'));
1.41 ng 2274: }
1.121 ng 2275: $request->print('<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
2276: .$udom.'" />'."\n");
1.44 ng 2277: # return if view submission with no grading option
1.618 www 2278: if (!&canmodify($usec)) {
1.633 www 2279: $request->print('<p><span class="LC_warning">'.&mt('No grading privileges').'</span></p></div>');
1.41 ng 2280: return;
1.180 albertel 2281: } else {
1.468 albertel 2282: $request->print('</div>'."\n");
1.41 ng 2283: }
1.33 ng 2284:
1.121 ng 2285: # essay grading message center
1.624 www 2286: # if ($env{'form.handgrade'} eq 'yes') {
2287: if (1) {
1.468 albertel 2288: my $result='<div class="LC_grade_message_center">';
2289:
2290: $result.='<div class="LC_grade_message_center_header">'.
2291: &mt('Send Message').'</div><div class="LC_grade_message_center_body">';
1.257 albertel 2292: my ($lastname,$givenn) = split(/,/,$env{'form.fullname'});
1.118 ng 2293: my $msgfor = $givenn.' '.$lastname;
1.464 albertel 2294: if (scalar(@$col_fullnames) > 0) {
2295: my $lastone = pop(@$col_fullnames);
2296: $msgfor .= ', '.(join ', ',@$col_fullnames).' and '.$lastone.'.';
1.118 ng 2297: }
2298: $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
1.468 albertel 2299: $result.='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
1.121 ng 2300: '<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n";
2301: $result.=' <a href="javascript:msgCenter(document.SCORE,'.$counter.
1.417 albertel 2302: ',\''.$msgfor.'\');" target="_self">'.
1.464 albertel 2303: &mt('Compose message to student').(scalar(@$col_fullnames) >= 1 ? 's' : '').'</a><label> ('.
1.350 albertel 2304: &mt('incl. grades').' <input type="checkbox" name="withgrades'.$counter.'" /></label>)'.
1.118 ng 2305: '<img src="'.$request->dir_config('lonIconsURL').
2306: '/mailbkgrd.gif" width="14" height="10" name="mailicon'.$counter.'" />'."\n".
1.298 www 2307: '<br /> ('.
1.468 albertel 2308: &mt('Message will be sent when you click on Save & Next below.').")\n";
2309: $result.='</div></div>';
1.121 ng 2310: $request->print($result);
1.118 ng 2311: }
1.41 ng 2312:
2313: my %seen = ();
2314: my @partlist;
1.129 ng 2315: my @gradePartRespid;
1.375 albertel 2316: my @part_response_id = &flatten_responseType($responseType);
1.585 bisitz 2317: $request->print(
1.588 bisitz 2318: '<div class="LC_Box">'
2319: .'<h3 class="LC_hcell">'.&mt('Assign Grades').'</h3>'
1.585 bisitz 2320: );
1.592 bisitz 2321: $request->print(&gradeBox_start());
1.375 albertel 2322: foreach my $part_response_id (@part_response_id) {
2323: my ($partid,$respid) = @{ $part_response_id };
2324: my $part_resp = join('_',@{ $part_response_id });
1.322 albertel 2325: next if ($seen{$partid} > 0);
1.41 ng 2326: $seen{$partid}++;
1.393 albertel 2327: next if ($$handgrade{$part_resp} ne 'yes'
2328: && $env{'form.lastSub'} eq 'hdgrade');
1.524 raeburn 2329: push(@partlist,$partid);
2330: push(@gradePartRespid,$partid.'.'.$respid);
1.322 albertel 2331: $request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
1.41 ng 2332: }
1.585 bisitz 2333: $request->print(&gradeBox_end()); # </div>
2334: $request->print('</div>');
1.468 albertel 2335:
2336: $request->print('<div class="LC_grade_info_links">');
2337: $request->print('</div>');
2338:
1.45 ng 2339: $result='<input type="hidden" name="partlist'.$counter.
2340: '" value="'.(join ":",@partlist).'" />'."\n";
1.129 ng 2341: $result.='<input type="hidden" name="gradePartRespid'.
2342: '" value="'.(join ":",@gradePartRespid).'" />'."\n" if ($counter == 0);
1.45 ng 2343: my $ctr = 0;
2344: while ($ctr < scalar(@partlist)) {
2345: $result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
2346: $partlist[$ctr].'" />'."\n";
2347: $ctr++;
2348: }
1.468 albertel 2349: $request->print($result.''."\n");
1.41 ng 2350:
1.441 www 2351: # Done with printing info for one student
2352:
1.468 albertel 2353: $request->print('</div>');#LC_grade_show_user
1.441 www 2354:
2355:
1.41 ng 2356: # print end of form
2357: if ($counter == $total) {
1.592 bisitz 2358: my $endform='<br /><hr /><table border="0"><tr><td>'."\n";
1.485 albertel 2359: $endform.='<input type="button" value="'.&mt('Save & Next').'" '.
1.589 bisitz 2360: 'onclick="javascript:checksubmit(this.form,\'Save & Next\','.
1.417 albertel 2361: $total.','.scalar(@partlist).');" target="_self" /> '."\n";
1.119 ng 2362: my $ntstu ='<select name="NTSTU">'.
2363: '<option>1</option><option>2</option>'.
2364: '<option>3</option><option>5</option>'.
2365: '<option>7</option><option>10</option></select>'."\n";
1.257 albertel 2366: my $nsel = ($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : '1');
1.401 albertel 2367: $ntstu =~ s/<option>$nsel</<option selected="selected">$nsel</;
1.578 raeburn 2368: $endform.=&mt('[_1]student(s)',$ntstu);
1.485 albertel 2369: $endform.=' <input type="button" value="'.&mt('Previous').'" '.
1.589 bisitz 2370: 'onclick="javascript:checksubmit(this.form,\'Previous\');" target="_self" /> '."\n".
1.485 albertel 2371: '<input type="button" value="'.&mt('Next').'" '.
1.589 bisitz 2372: 'onclick="javascript:checksubmit(this.form,\'Next\');" target="_self" /> ';
1.592 bisitz 2373: $endform.='<span class="LC_warning">'.
2374: &mt('(Next and Previous (student) do not save the scores.)').
2375: '</span>'."\n" ;
1.349 albertel 2376: $endform.="<input type='hidden' value='".&get_increment().
1.348 bowersj2 2377: "' name='increment' />";
1.485 albertel 2378: $endform.='</td></tr></table></form>';
1.41 ng 2379: $request->print($endform);
2380: }
2381: return '';
1.38 ng 2382: }
2383:
1.464 albertel 2384: sub check_collaborators {
2385: my ($symb,$uname,$udom,$record,$handgrade,$counter) = @_;
2386: my ($result,@col_fullnames);
2387: my ($classlist,undef,$fullname) = &getclasslist('all','0');
2388: foreach my $part (keys(%$handgrade)) {
2389: my $ncol = &Apache::lonnet::EXT('resource.'.$part.
2390: '.maxcollaborators',
2391: $symb,$udom,$uname);
2392: next if ($ncol <= 0);
2393: $part =~ s/\_/\./g;
2394: next if ($record->{'resource.'.$part.'.collaborators'} eq '');
2395: my (@good_collaborators, @bad_collaborators);
2396: foreach my $possible_collaborator
1.630 www 2397: (split(/[,;\s]+/,$record->{'resource.'.$part.'.collaborators'})) {
1.464 albertel 2398: $possible_collaborator =~ s/[\$\^\(\)]//g;
2399: next if ($possible_collaborator eq '');
1.631 www 2400: my ($co_name,$co_dom) = split(/:/,$possible_collaborator);
1.464 albertel 2401: $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
2402: next if ($co_name eq $uname && $co_dom eq $udom);
2403: # Doing this grep allows 'fuzzy' specification
2404: my @matches = grep(/^\Q$co_name\E:\Q$co_dom\E$/i,
2405: keys(%$classlist));
2406: if (! scalar(@matches)) {
2407: push(@bad_collaborators, $possible_collaborator);
2408: } else {
2409: push(@good_collaborators, @matches);
2410: }
2411: }
2412: if (scalar(@good_collaborators) != 0) {
1.630 www 2413: $result.='<br />'.&mt('Collaborators:').'<ol>';
1.464 albertel 2414: foreach my $name (@good_collaborators) {
2415: my ($lastname,$givenn) = split(/,/,$$fullname{$name});
2416: push(@col_fullnames, $givenn.' '.$lastname);
1.630 www 2417: $result.='<li>'.$fullname->{$name}.'</li>';
1.464 albertel 2418: }
1.630 www 2419: $result.='</ol><br />'."\n";
1.466 albertel 2420: my ($part)=split(/\./,$part);
1.464 albertel 2421: $result.='<input type="hidden" name="collaborator'.$counter.
2422: '" value="'.$part.':'.(join ':',@good_collaborators).'" />'.
2423: "\n";
2424: }
2425: if (scalar(@bad_collaborators) > 0) {
1.466 albertel 2426: $result.='<div class="LC_warning">';
1.464 albertel 2427: $result.=&mt('This student has submitted [quant,_1,invalid collaborator]: [_2]',scalar(@bad_collaborators),join(', ',@bad_collaborators));
2428: $result .= '</div>';
2429: }
2430: if (scalar(@bad_collaborators > $ncol)) {
1.466 albertel 2431: $result .= '<div class="LC_warning">';
1.464 albertel 2432: $result .= &mt('This student has submitted too many '.
2433: 'collaborators. Maximum is [_1].',$ncol);
2434: $result .= '</div>';
2435: }
2436: }
2437: return ($result,$fullname,\@col_fullnames);
2438: }
2439:
1.44 ng 2440: #--- Retrieve the last submission for all the parts
1.38 ng 2441: sub get_last_submission {
1.119 ng 2442: my ($returnhash)=@_;
1.596 raeburn 2443: my (@string,$timestamp,%lasthidden);
1.119 ng 2444: if ($$returnhash{'version'}) {
1.46 ng 2445: my %lasthash=();
2446: my ($version);
1.119 ng 2447: for ($version=1;$version<=$$returnhash{'version'};$version++) {
1.397 albertel 2448: foreach my $key (sort(split(/\:/,
2449: $$returnhash{$version.':keys'}))) {
2450: $lasthash{$key}=$$returnhash{$version.':'.$key};
2451: $timestamp =
1.545 raeburn 2452: &Apache::lonlocal::locallocaltime($$returnhash{$version.':timestamp'});
1.46 ng 2453: }
2454: }
1.640 raeburn 2455: my (%typeparts,%randombytry);
1.596 raeburn 2456: my $showsurv =
2457: &Apache::lonnet::allowed('vas',$env{'request.course.id'});
2458: foreach my $key (sort(keys(%lasthash))) {
2459: if ($key =~ /\.type$/) {
2460: if (($lasthash{$key} eq 'anonsurvey') ||
1.640 raeburn 2461: ($lasthash{$key} eq 'anonsurveycred') ||
2462: ($lasthash{$key} eq 'randomizetry')) {
1.596 raeburn 2463: my ($ign,@parts) = split(/\./,$key);
2464: pop(@parts);
1.641 raeburn 2465: my $id = join('.',@parts);
1.640 raeburn 2466: if ($lasthash{$key} eq 'randomizetry') {
2467: $randombytry{$ign.'.'.$id} = $lasthash{$key};
2468: } else {
2469: unless ($showsurv) {
2470: $typeparts{$ign.'.'.$id} = $lasthash{$key};
2471: }
1.596 raeburn 2472: }
2473: delete($lasthash{$key});
2474: }
2475: }
2476: }
2477: my @hidden = keys(%typeparts);
1.640 raeburn 2478: my @randomize = keys(%randombytry);
1.397 albertel 2479: foreach my $key (keys(%lasthash)) {
2480: next if ($key !~ /\.submission$/);
1.596 raeburn 2481: my $hide;
2482: if (@hidden) {
2483: foreach my $id (@hidden) {
2484: if ($key =~ /^\Q$id\E/) {
1.640 raeburn 2485: $hide = 'anon';
1.596 raeburn 2486: last;
2487: }
2488: }
2489: }
1.640 raeburn 2490: unless ($hide) {
2491: if (@randomize) {
2492: foreach my $id (@hidden) {
2493: if ($key =~ /^\Q$id\E/) {
2494: $hide = 'rand';
2495: last;
2496: }
2497: }
2498: }
2499: }
1.397 albertel 2500: my ($partid,$foo) = split(/submission$/,$key);
2501: my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
1.398 albertel 2502: '<span class="LC_warning">Draft Copy</span> ' : '';
1.596 raeburn 2503: push(@string, join(':', $key, $hide, $draft.$lasthash{$key}));
1.41 ng 2504: }
2505: }
1.397 albertel 2506: if (!@string) {
2507: $string[0] =
1.539 riegler 2508: '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span>';
1.397 albertel 2509: }
2510: return (\@string,\$timestamp);
1.38 ng 2511: }
1.35 ng 2512:
1.44 ng 2513: #--- High light keywords, with style choosen by user.
1.38 ng 2514: sub keywords_highlight {
1.44 ng 2515: my $string = shift;
1.257 albertel 2516: my $size = $env{'form.kwsize'} eq '0' ? '' : 'size='.$env{'form.kwsize'};
2517: my $styleon = $env{'form.kwstyle'} eq '' ? '' : $env{'form.kwstyle'};
1.41 ng 2518: (my $styleoff = $styleon) =~ s/\</\<\//;
1.257 albertel 2519: my @keylist = split(/[,\s+]/,$env{'form.keywords'});
1.398 albertel 2520: foreach my $keyword (@keylist) {
2521: $string =~ s/\b\Q$keyword\E(\b|\.)/<font color\=$env{'form.kwclr'} $size\>$styleon$keyword$styleoff<\/font>/gi;
1.41 ng 2522: }
2523: return $string;
1.38 ng 2524: }
1.36 ng 2525:
1.671 raeburn 2526: # For Tasks provide a mechanism to display previous version for one specific student
2527:
2528: sub show_previous_task_version {
2529: my ($request,$symb) = @_;
2530: if ($symb eq '') {
2531: $request->print("Unable to handle ambiguous references.");
2532:
2533: return '';
2534: }
2535: my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
2536: my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
2537: if (!&canview($usec)) {
2538: $request->print('<span class="LC_warning">Unable to view previous version for requested student.('.
2539: $uname.':'.$udom.' in section '.$usec.' in course id '.
2540: $env{'request.course.id'}.')</span>');
2541: return;
2542: }
2543: my $mode = 'both';
2544: my $isTask = ($symb =~/\.task$/);
2545: if ($isTask) {
2546: if ($env{'form.previousversion'} =~ /^\d+$/) {
2547: if ($env{'form.fullname'} eq '') {
2548: $env{'form.fullname'} =
2549: &Apache::loncommon::plainname($uname,$udom,'lastname');
2550: }
2551: my $probtitle=&Apache::lonnet::gettitle($symb);
2552: $request->print("\n\n".
2553: '<div class="LC_grade_show_user">'.
2554: '<h2>'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
2555: '</h2>'."\n");
2556: &Apache::lonxml::clear_problem_counter();
2557: $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode,
2558: {'previousversion' => $env{'form.previousversion'} }));
2559: $request->print("\n</div>");
2560: }
2561: }
2562: return;
2563: }
2564:
2565: sub choose_task_version_form {
2566: my ($symb,$uname,$udom,$nomenu) = @_;
2567: my $isTask = ($symb =~/\.task$/);
2568: my ($current,$version,$result,$js,$displayed,$rowtitle);
2569: if ($isTask) {
2570: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
2571: $udom,$uname);
2572: if (($record{'resource.0.version'} eq '') ||
2573: ($record{'resource.0.version'} < 2)) {
2574: return ($record{'resource.0.version'},
2575: $record{'resource.0.version'},$result,$js);
2576: } else {
2577: $current = $record{'resource.0.version'};
2578: }
2579: if ($env{'form.previousversion'}) {
2580: $displayed = $env{'form.previousversion'};
2581: $rowtitle = &mt('Choose another version:')
2582: } else {
2583: $displayed = $current;
2584: $rowtitle = &mt('Show earlier version:');
2585: }
2586: $result = '<div class="LC_left_float">';
2587: my $list;
2588: my $numversions = 0;
2589: for (my $i=1; $i<=$record{'resource.0.version'}; $i++) {
2590: if ($i == $current) {
2591: if (!$env{'form.previousversion'} || $nomenu) {
2592: next;
2593: } else {
2594: $list .= '<option value="'.$i.'">'.&mt('Current').'</option>'."\n";
2595: $numversions ++;
2596: }
2597: } elsif (defined($record{'resource.'.$i.'.0.status'})) {
2598: unless ($i == $env{'form.previousversion'}) {
2599: $numversions ++;
2600: }
2601: $list .= '<option value="'.$i.'">'.$i.'</option>'."\n";
2602: }
2603: }
2604: if ($numversions) {
2605: $symb = &HTML::Entities::encode($symb,'<>"&');
2606: $result .=
2607: '<form name="getprev" method="post" action=""'.
2608: ' onsubmit="return previousVersion('."'$uname','$udom','$symb','$displayed'".');">'.
2609: &Apache::loncommon::start_data_table().
2610: &Apache::loncommon::start_data_table_row().
2611: '<th align="left">'.$rowtitle.'</th>'.
2612: '<td><select name="version">'.
2613: '<option>'.&mt('Select').'</option>'.
2614: $list.
2615: '</select></td>'.
2616: &Apache::loncommon::end_data_table_row();
2617: unless ($nomenu) {
2618: $result .= &Apache::loncommon::start_data_table_row().
2619: '<th align="left">'.&mt('Open in new window').'</th>'.
2620: '<td><span class="LC_nobreak">'.
2621: '<label><input type="radio" name="prevwin" value="1" />'.
2622: &mt('Yes').'</label>'.
2623: '<label><input type="radio" name="prevwin" value="0" checked="checked" />'.&mt('No').'</label>'.
2624: '</span></td>'.
2625: &Apache::loncommon::end_data_table_row();
2626: }
2627: $result .=
2628: &Apache::loncommon::start_data_table_row().
2629: '<th align="left"> </th>'.
2630: '<td>'.
2631: '<input type="submit" name="prevsub" value="'.&mt('Display').'" />'.
2632: '</td>'.
2633: &Apache::loncommon::end_data_table_row().
2634: &Apache::loncommon::end_data_table().
2635: '</form>';
2636: $js = &previous_display_javascript($nomenu,$current);
2637: } elsif ($displayed && $nomenu) {
2638: $result .= '<a href="javascript:window.close()">'.&mt('Close window').'</a>';
2639: } else {
2640: $result .= &mt('No previous versions to show for this student');
2641: }
2642: $result .= '</div>';
2643: }
2644: return ($current,$displayed,$result,$js);
2645: }
2646:
2647: sub previous_display_javascript {
2648: my ($nomenu,$current) = @_;
2649: my $js = <<"JSONE";
2650: <script type="text/javascript">
2651: // <![CDATA[
2652: function previousVersion(uname,udom,symb) {
2653: var current = '$current';
2654: var version = document.getprev.version.options[document.getprev.version.selectedIndex].value;
2655: var prevstr = new RegExp("^\\\\d+\$");
2656: if (!prevstr.test(version)) {
2657: return false;
2658: }
2659: var url = '';
2660: if (version == current) {
2661: url = '/adm/grades?student='+uname+'&userdom='+udom+'&symb='+symb+'&command=submission';
2662: } else {
2663: url = '/adm/grades?student='+uname+'&userdom='+udom+'&symb='+symb+'&command=versionsub&previousversion='+version;
2664: }
2665: JSONE
2666: if ($nomenu) {
2667: $js .= <<"JSTWO";
2668: document.location.href = url;
2669: JSTWO
2670: } else {
2671: $js .= <<"JSTHREE";
2672: var newwin = 0;
2673: for (var i=0; i<document.getprev.prevwin.length; i++) {
2674: if (document.getprev.prevwin[i].checked == true) {
2675: newwin = document.getprev.prevwin[i].value;
2676: }
2677: }
2678: if (newwin == 1) {
2679: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
2680: url = url+'&inhibitmenu=yes';
2681: if (typeof(previousWin) == 'undefined' || previousWin.closed) {
2682: previousWin = window.open(url,'',options,1);
2683: } else {
2684: previousWin.location.href = url;
2685: }
2686: previousWin.focus();
2687: return false;
2688: } else {
2689: document.location.href = url;
2690: return false;
2691: }
2692: JSTHREE
2693: }
2694: $js .= <<"ENDJS";
2695: return false;
2696: }
2697: // ]]>
2698: </script>
2699: ENDJS
2700:
2701: }
2702:
1.44 ng 2703: #--- Called from submission routine
1.38 ng 2704: sub processHandGrade {
1.608 www 2705: my ($request,$symb) = @_;
1.324 albertel 2706: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.257 albertel 2707: my $button = $env{'form.gradeOpt'};
2708: my $ngrade = $env{'form.NCT'};
2709: my $ntstu = $env{'form.NTSTU'};
1.301 albertel 2710: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2711: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2712:
1.44 ng 2713: if ($button eq 'Save & Next') {
2714: my $ctr = 0;
2715: while ($ctr < $ngrade) {
1.257 albertel 2716: my ($uname,$udom) = split(/:/,$env{'form.unamedom'.$ctr});
1.324 albertel 2717: my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$symb,$uname,$udom,$ctr);
1.71 ng 2718: if ($errorflag eq 'no_score') {
2719: $ctr++;
2720: next;
2721: }
1.104 albertel 2722: if ($errorflag eq 'not_allowed') {
1.398 albertel 2723: $request->print("<span class=\"LC_warning\">Not allowed to modify grades for $uname:$udom</span>");
1.104 albertel 2724: $ctr++;
2725: next;
2726: }
1.257 albertel 2727: my $includemsg = $env{'form.includemsg'.$ctr};
1.44 ng 2728: my ($subject,$message,$msgstatus) = ('','','');
1.418 albertel 2729: my $restitle = &Apache::lonnet::gettitle($symb);
2730: my ($feedurl,$showsymb) =
2731: &get_feedurl_and_symb($symb,$uname,$udom);
2732: my $messagetail;
1.62 albertel 2733: if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.298 www 2734: $subject = $env{'form.msgsub'} if ($includemsg =~ /msgsub/);
1.295 www 2735: unless ($subject=~/\w/) { $subject=&mt('Grading Feedback'); }
1.386 raeburn 2736: $subject.=' ['.$restitle.']';
1.44 ng 2737: my (@msgnum) = split(/,/,$includemsg);
2738: foreach (@msgnum) {
1.257 albertel 2739: $message.=$env{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
1.44 ng 2740: }
1.80 ng 2741: $message =&Apache::lonfeedback::clear_out_html($message);
1.298 www 2742: if ($env{'form.withgrades'.$ctr}) {
2743: $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
1.386 raeburn 2744: $messagetail = " for <a href=\"".
1.605 www 2745: $feedurl."?symb=$showsymb\">$restitle</a>";
1.386 raeburn 2746: }
2747: $msgstatus =
2748: &Apache::lonmsg::user_normal_msg($uname,$udom,$subject,
2749: $message.$messagetail,
1.418 albertel 2750: undef,$feedurl,undef,
1.386 raeburn 2751: undef,undef,$showsymb,
2752: $restitle);
1.574 bisitz 2753: $request->print('<br />'.&mt('Sending message to [_1]',$uname.':'.$udom).': '.
1.652 raeburn 2754: $msgstatus.'<br />');
1.44 ng 2755: }
1.257 albertel 2756: if ($env{'form.collaborator'.$ctr}) {
1.155 albertel 2757: my @collabstrs=&Apache::loncommon::get_env_multiple("form.collaborator$ctr");
1.150 albertel 2758: foreach my $collabstr (@collabstrs) {
2759: my ($part,@collaborators) = split(/:/,$collabstr);
1.310 banghart 2760: foreach my $collaborator (@collaborators) {
1.150 albertel 2761: my ($errorflag,$pts,$wgt) =
1.324 albertel 2762: &saveHandGrade($request,$symb,$collaborator,$udom,$ctr,
1.257 albertel 2763: $env{'form.unamedom'.$ctr},$part);
1.150 albertel 2764: if ($errorflag eq 'not_allowed') {
1.362 albertel 2765: $request->print("<span class=\"LC_error\">".&mt('Not allowed to modify grades for [_1]',"$collaborator:$udom")."</span>");
1.150 albertel 2766: next;
1.418 albertel 2767: } elsif ($message ne '') {
2768: my ($baseurl,$showsymb) =
2769: &get_feedurl_and_symb($symb,$collaborator,
2770: $udom);
2771: if ($env{'form.withgrades'.$ctr}) {
2772: $messagetail = " for <a href=\"".
1.605 www 2773: $baseurl."?symb=$showsymb\">$restitle</a>";
1.150 albertel 2774: }
1.418 albertel 2775: $msgstatus =
2776: &Apache::lonmsg::user_normal_msg($collaborator,$udom,$subject,$message.$messagetail,undef,$baseurl,undef,undef,undef,$showsymb,$restitle);
1.104 albertel 2777: }
1.44 ng 2778: }
2779: }
2780: }
2781: $ctr++;
2782: }
2783: }
2784:
1.624 www 2785: # if ($env{'form.handgrade'} eq 'yes') {
2786: if (1) {
1.119 ng 2787: # Keywords sorted in alphabatical order
1.257 albertel 2788: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1.119 ng 2789: my %keyhash = ();
1.257 albertel 2790: $env{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
2791: $env{'form.keywords'} =~ s/^\s+|\s+$//;
2792: my (@keywords) = sort(split(/\s+/,$env{'form.keywords'}));
2793: $env{'form.keywords'} = join(' ',@keywords);
2794: $keyhash{$symb.'_keywords'} = $env{'form.keywords'};
2795: $keyhash{$symb.'_subject'} = $env{'form.msgsub'};
2796: $keyhash{$loginuser.'_kwclr'} = $env{'form.kwclr'};
2797: $keyhash{$loginuser.'_kwsize'} = $env{'form.kwsize'};
2798: $keyhash{$loginuser.'_kwstyle'} = $env{'form.kwstyle'};
1.119 ng 2799:
2800: # message center - Order of message gets changed. Blank line is eliminated.
1.257 albertel 2801: # New messages are saved in env for the next student.
1.119 ng 2802: # All messages are saved in nohist_handgrade.db
2803: my ($ctr,$idx) = (1,1);
1.257 albertel 2804: while ($ctr <= $env{'form.savemsgN'}) {
2805: if ($env{'form.savemsg'.$ctr} ne '') {
2806: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.savemsg'.$ctr};
1.119 ng 2807: $idx++;
2808: }
2809: $ctr++;
1.41 ng 2810: }
1.119 ng 2811: $ctr = 0;
2812: while ($ctr < $ngrade) {
1.257 albertel 2813: if ($env{'form.newmsg'.$ctr} ne '') {
2814: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.newmsg'.$ctr};
2815: $env{'form.savemsg'.$idx} = $env{'form.newmsg'.$ctr};
1.119 ng 2816: $idx++;
2817: }
2818: $ctr++;
1.41 ng 2819: }
1.257 albertel 2820: $env{'form.savemsgN'} = --$idx;
2821: $keyhash{$symb.'_savemsgN'} = $env{'form.savemsgN'};
1.119 ng 2822: my $putresult = &Apache::lonnet::put
1.301 albertel 2823: ('nohist_handgrade',\%keyhash,$cdom,$cnum);
1.41 ng 2824: }
1.44 ng 2825: # Called by Save & Refresh from Highlight Attribute Window
1.257 albertel 2826: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
2827: if ($env{'form.refresh'} eq 'on') {
1.86 ng 2828: my ($ctr,$total) = (0,0);
2829: while ($ctr < $ngrade) {
1.257 albertel 2830: $total++ if $env{'form.unamedom'.$ctr} ne '';
1.86 ng 2831: $ctr++;
2832: }
1.257 albertel 2833: $env{'form.NTSTU'}=$ngrade;
1.86 ng 2834: $ctr = 0;
2835: while ($ctr < $total) {
1.257 albertel 2836: my $processUser = $env{'form.unamedom'.$ctr};
2837: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2838: $env{'form.fullname'} = $$fullname{$processUser};
1.625 www 2839: &submission($request,$ctr,$total-1,$symb);
1.41 ng 2840: $ctr++;
2841: }
2842: return '';
2843: }
1.36 ng 2844:
1.44 ng 2845: # Get the next/previous one or group of students
1.257 albertel 2846: my $firststu = $env{'form.unamedom0'};
2847: my $laststu = $env{'form.unamedom'.($ngrade-1)};
1.119 ng 2848: my $ctr = 2;
1.41 ng 2849: while ($laststu eq '') {
1.257 albertel 2850: $laststu = $env{'form.unamedom'.($ngrade-$ctr)};
1.41 ng 2851: $ctr++;
2852: $laststu = $firststu if ($ctr > $ngrade);
2853: }
1.44 ng 2854:
1.41 ng 2855: my (@parsedlist,@nextlist);
2856: my ($nextflg) = 0;
1.524 raeburn 2857: foreach my $item (sort
1.294 albertel 2858: {
2859: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
2860: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
2861: }
2862: return $a cmp $b;
2863: } (keys(%$fullname))) {
1.605 www 2864: # FIXME: this is fishy, looks like the button label
1.41 ng 2865: if ($nextflg == 1 && $button =~ /Next$/) {
1.524 raeburn 2866: push(@parsedlist,$item);
1.41 ng 2867: }
1.524 raeburn 2868: $nextflg = 1 if ($item eq $laststu);
1.41 ng 2869: if ($button eq 'Previous') {
1.524 raeburn 2870: last if ($item eq $firststu);
2871: push(@parsedlist,$item);
1.41 ng 2872: }
2873: }
2874: $ctr = 0;
1.605 www 2875: # FIXME: this is fishy, looks like the button label
1.41 ng 2876: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
1.582 raeburn 2877: my $res_error;
2878: my ($partlist) = &response_type($symb,\$res_error);
2879: if ($res_error) {
2880: $request->print(&navmap_errormsg());
2881: return;
2882: }
1.41 ng 2883: foreach my $student (@parsedlist) {
1.257 albertel 2884: my $submitonly=$env{'form.submitonly'};
1.41 ng 2885: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 2886:
2887: if ($submitonly eq 'queued') {
2888: my %queue_status =
2889: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
2890: $udom,$uname);
2891: next if (!defined($queue_status{'gradingqueue'}));
2892: }
2893:
1.156 albertel 2894: if ($submitonly =~ /^(yes|graded|incorrect)$/) {
1.257 albertel 2895: # my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 2896: my %status=&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 2897: my $submitted = 0;
1.248 albertel 2898: my $ungraded = 0;
2899: my $incorrect = 0;
1.524 raeburn 2900: foreach my $item (keys(%status)) {
2901: $submitted = 1 if ($status{$item} ne 'nothing');
2902: $ungraded = 1 if ($status{$item} =~ /^ungraded/);
2903: $incorrect = 1 if ($status{$item} =~ /^incorrect/);
2904: my ($foo,$partid,$foo1) = split(/\./,$item);
1.145 albertel 2905: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
2906: $submitted = 0;
2907: }
1.41 ng 2908: }
1.156 albertel 2909: next if (!$submitted && ($submitonly eq 'yes' ||
2910: $submitonly eq 'incorrect' ||
2911: $submitonly eq 'graded'));
1.248 albertel 2912: next if (!$ungraded && ($submitonly eq 'graded'));
2913: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 2914: }
1.524 raeburn 2915: push(@nextlist,$student) if ($ctr < $ntstu);
1.129 ng 2916: last if ($ctr == $ntstu);
1.41 ng 2917: $ctr++;
2918: }
1.36 ng 2919:
1.41 ng 2920: $ctr = 0;
2921: my $total = scalar(@nextlist)-1;
1.39 ng 2922:
1.524 raeburn 2923: foreach (sort(@nextlist)) {
1.41 ng 2924: my ($uname,$udom,$submitter) = split(/:/);
1.257 albertel 2925: $env{'form.student'} = $uname;
2926: $env{'form.userdom'} = $udom;
2927: $env{'form.fullname'} = $$fullname{$_};
1.625 www 2928: &submission($request,$ctr,$total,$symb);
1.41 ng 2929: $ctr++;
2930: }
2931: if ($total < 0) {
1.653 raeburn 2932: my $the_end.='<p>'.&mt('[_1]Message:[_2] No more students for this section or class.','<b>','</b>').'</p>'."\n";
1.41 ng 2933: $request->print($the_end);
2934: }
2935: return '';
1.38 ng 2936: }
1.36 ng 2937:
1.44 ng 2938: #---- Save the score and award for each student, if changed
1.38 ng 2939: sub saveHandGrade {
1.324 albertel 2940: my ($request,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
1.342 banghart 2941: my @version_parts;
1.104 albertel 2942: my $usec = &Apache::lonnet::getsection($domain,$stuname,
1.257 albertel 2943: $env{'request.course.id'});
1.104 albertel 2944: if (!&canmodify($usec)) { return('not_allowed'); }
1.337 banghart 2945: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
1.251 banghart 2946: my @parts_graded;
1.77 ng 2947: my %newrecord = ();
2948: my ($pts,$wgt) = ('','');
1.269 raeburn 2949: my %aggregate = ();
2950: my $aggregateflag = 0;
1.301 albertel 2951: my @parts = split(/:/,$env{'form.partlist'.$newflg});
2952: foreach my $new_part (@parts) {
1.337 banghart 2953: #collaborator ($submi may vary for different parts
1.259 banghart 2954: if ($submitter && $new_part ne $part) { next; }
2955: my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
1.125 ng 2956: if ($dropMenu eq 'excused') {
1.259 banghart 2957: if ($record{'resource.'.$new_part.'.solved'} ne 'excused') {
2958: $newrecord{'resource.'.$new_part.'.solved'} = 'excused';
2959: if (exists($record{'resource.'.$new_part.'.awarded'})) {
2960: $newrecord{'resource.'.$new_part.'.awarded'} = '';
1.58 albertel 2961: }
1.364 banghart 2962: $newrecord{'resource.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.58 albertel 2963: }
1.125 ng 2964: } elsif ($dropMenu eq 'reset status'
1.259 banghart 2965: && exists($record{'resource.'.$new_part.'.solved'})) { #don't bother if no old records -> no attempts
1.524 raeburn 2966: foreach my $key (keys(%record)) {
1.259 banghart 2967: if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
1.197 albertel 2968: }
1.259 banghart 2969: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2970: "$env{'user.name'}:$env{'user.domain'}";
1.270 albertel 2971: my $totaltries = $record{'resource.'.$part.'.tries'};
2972:
2973: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
2974: [$new_part]);
2975: my $aggtries =$totaltries;
1.269 raeburn 2976: if ($last_resets{$new_part}) {
1.270 albertel 2977: $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
2978: $new_part);
1.269 raeburn 2979: }
1.270 albertel 2980:
2981: my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
1.269 raeburn 2982: if ($aggtries > 0) {
1.327 albertel 2983: &decrement_aggs($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
1.269 raeburn 2984: $aggregateflag = 1;
2985: }
1.125 ng 2986: } elsif ($dropMenu eq '') {
1.259 banghart 2987: $pts = ($env{'form.GD_BOX'.$newflg.'_'.$new_part} ne '' ?
2988: $env{'form.GD_BOX'.$newflg.'_'.$new_part} :
2989: $env{'form.RADVAL'.$newflg.'_'.$new_part});
2990: if ($pts eq '' && $env{'form.GD_SEL'.$newflg.'_'.$new_part} eq '') {
1.153 albertel 2991: next;
2992: }
1.259 banghart 2993: $wgt = $env{'form.WGT'.$newflg.'_'.$new_part} eq '' ? 1 :
2994: $env{'form.WGT'.$newflg.'_'.$new_part};
1.41 ng 2995: my $partial= $pts/$wgt;
1.259 banghart 2996: if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
1.153 albertel 2997: #do not update score for part if not changed.
1.346 banghart 2998: &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
1.153 albertel 2999: next;
1.251 banghart 3000: } else {
1.524 raeburn 3001: push(@parts_graded,$new_part);
1.153 albertel 3002: }
1.259 banghart 3003: if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
3004: $newrecord{'resource.'.$new_part.'.awarded'} = $partial;
1.153 albertel 3005: }
1.259 banghart 3006: my $reckey = 'resource.'.$new_part.'.solved';
1.41 ng 3007: if ($partial == 0) {
1.153 albertel 3008: if ($record{$reckey} ne 'incorrect_by_override') {
3009: $newrecord{$reckey} = 'incorrect_by_override';
3010: }
1.41 ng 3011: } else {
1.153 albertel 3012: if ($record{$reckey} ne 'correct_by_override') {
3013: $newrecord{$reckey} = 'correct_by_override';
3014: }
3015: }
3016: if ($submitter &&
1.259 banghart 3017: ($record{'resource.'.$new_part.'.submitted_by'} ne $submitter)) {
3018: $newrecord{'resource.'.$new_part.'.submitted_by'} = $submitter;
1.41 ng 3019: }
1.259 banghart 3020: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 3021: "$env{'user.name'}:$env{'user.domain'}";
1.41 ng 3022: }
1.259 banghart 3023: # unless problem has been graded, set flag to version the submitted files
1.305 banghart 3024: unless ($record{'resource.'.$new_part.'.solved'} =~ /^correct_/ ||
3025: $record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override' ||
3026: $dropMenu eq 'reset status')
3027: {
1.524 raeburn 3028: push(@version_parts,$new_part);
1.259 banghart 3029: }
1.41 ng 3030: }
1.301 albertel 3031: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3032: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3033:
1.344 albertel 3034: if (%newrecord) {
3035: if (@version_parts) {
1.364 banghart 3036: my @changed_keys = &version_portfiles(\%record, \@parts_graded,
3037: $env{'request.course.id'}, $symb, $domain, $stuname, \@version_parts);
1.344 albertel 3038: @newrecord{@changed_keys} = @record{@changed_keys};
1.367 albertel 3039: foreach my $new_part (@version_parts) {
3040: &handback_files($request,$symb,$stuname,$domain,$newflg,
3041: $new_part,\%newrecord);
3042: }
1.259 banghart 3043: }
1.44 ng 3044: &Apache::lonnet::cstore(\%newrecord,$symb,
1.257 albertel 3045: $env{'request.course.id'},$domain,$stuname);
1.380 albertel 3046: &check_and_remove_from_queue(\@parts,\%record,\%newrecord,$symb,
3047: $cdom,$cnum,$domain,$stuname);
1.41 ng 3048: }
1.269 raeburn 3049: if ($aggregateflag) {
3050: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 3051: $cdom,$cnum);
1.269 raeburn 3052: }
1.301 albertel 3053: return ('',$pts,$wgt);
1.36 ng 3054: }
1.322 albertel 3055:
1.380 albertel 3056: sub check_and_remove_from_queue {
3057: my ($parts,$record,$newrecord,$symb,$cdom,$cnum,$domain,$stuname) = @_;
3058: my @ungraded_parts;
3059: foreach my $part (@{$parts}) {
3060: if ( $record->{ 'resource.'.$part.'.awarded'} eq ''
3061: && $record->{ 'resource.'.$part.'.solved' } ne 'excused'
3062: && $newrecord->{'resource.'.$part.'.awarded'} eq ''
3063: && $newrecord->{'resource.'.$part.'.solved' } ne 'excused'
3064: ) {
3065: push(@ungraded_parts, $part);
3066: }
3067: }
3068: if ( !@ungraded_parts ) {
3069: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,
3070: $cnum,$domain,$stuname);
3071: }
3072: }
3073:
1.337 banghart 3074: sub handback_files {
3075: my ($request,$symb,$stuname,$domain,$newflg,$new_part,$newrecord) = @_;
1.517 raeburn 3076: my $portfolio_root = '/userfiles/portfolio';
1.582 raeburn 3077: my $res_error;
3078: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
3079: if ($res_error) {
3080: $request->print('<br />'.&navmap_errormsg().'<br />');
3081: return;
3082: }
1.654 raeburn 3083: my @handedback;
3084: my $file_msg;
1.375 albertel 3085: my @part_response_id = &flatten_responseType($responseType);
3086: foreach my $part_response_id (@part_response_id) {
3087: my ($part_id,$resp_id) = @{ $part_response_id };
3088: my $part_resp = join('_',@{ $part_response_id });
1.654 raeburn 3089: if (($env{'form.'.$newflg.'_'.$part_resp.'_countreturndoc'} =~ /^\d+$/) & ($new_part eq $part_id)) {
3090: for (my $counter=1; $counter<=$env{'form.'.$newflg.'_'.$part_resp.'_countreturndoc'}; $counter++) {
3091: # if multiple files are uploaded names will be 'returndoc2','returndoc3'
3092: if ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$counter}) {
3093: my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$counter.'.filename'};
1.338 banghart 3094: my ($directory,$answer_file) =
1.654 raeburn 3095: ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$counter} =~ /^(.*?)([^\/]*)$/);
1.338 banghart 3096: my ($answer_name,$answer_ver,$answer_ext) =
3097: &file_name_version_ext($answer_file);
1.355 banghart 3098: my ($portfolio_path) = ($directory =~ /^.+$stuname\/portfolio(.*)/);
1.517 raeburn 3099: my $getpropath = 1;
1.662 raeburn 3100: my ($dir_list,$listerror) =
3101: &Apache::lonnet::dirlist($portfolio_root.$portfolio_path,
3102: $domain,$stuname,$getpropath);
3103: my $version = &get_next_version($answer_name,$answer_ext,$dir_list);
1.686 bisitz 3104: # fix filename
1.355 banghart 3105: my ($save_file_name) = (($directory.$answer_name.".$version.".$answer_ext) =~ /^.+\/${stuname}\/(.*)/);
3106: my $result=&Apache::lonnet::finishuserfileupload($stuname,$domain,
1.654 raeburn 3107: $newflg.'_'.$part_resp.'_returndoc'.$counter,
1.355 banghart 3108: $save_file_name);
1.337 banghart 3109: if ($result !~ m|^/uploaded/|) {
1.536 raeburn 3110: $request->print('<br /><span class="LC_error">'.
3111: &mt('An error occurred ([_1]) while trying to upload [_2].',
1.654 raeburn 3112: $result,$newflg.'_'.$part_resp.'_returndoc'.$counter).
1.536 raeburn 3113: '</span>');
1.356 banghart 3114: } else {
1.360 banghart 3115: # mark the file as read only
1.654 raeburn 3116: push(@handedback,$save_file_name);
1.367 albertel 3117: if (exists($$newrecord{"resource.$new_part.$resp_id.handback"})) {
3118: $$newrecord{"resource.$new_part.$resp_id.handback"}.=',';
3119: }
3120: $$newrecord{"resource.$new_part.$resp_id.handback"} .= $save_file_name;
1.654 raeburn 3121: $file_msg.= '<span class="LC_filename"><a href="/uploaded/'."$domain/$stuname/".$save_file_name.'">'.$save_file_name."</a></span> <br />";
1.337 banghart 3122: }
1.686 bisitz 3123: $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 3124: }
3125: }
3126: }
1.654 raeburn 3127: }
3128: if (@handedback > 0) {
3129: $request->print('<br />');
3130: my @what = ($symb,$env{'request.course.id'},'handback');
3131: &Apache::lonnet::mark_as_readonly($domain,$stuname,\@handedback,\@what);
3132: my $user_lh = &Apache::loncommon::user_lang($stuname,$domain,$env{'request.course.id'});
3133: my ($subject,$message);
3134: if (scalar(@handedback) == 1) {
3135: $subject = &mt_user($user_lh,'File Handed Back by Instructor');
3136: $message = &mt_user($user_lh,'A file has been returned that was originally submitted in response to: ');
3137: } else {
3138: $subject = &mt_user($user_lh,'Files Handed Back by Instructor');
3139: $message = &mt_user($user_lh,'Files have been returned that were originally submitted in response to: ');
3140: }
3141: $message .= "<p><strong>".&Apache::lonnet::gettitle($symb)." </strong></p>";
3142: $message .= &mt_user($user_lh,'The returned file(s) are named: [_1]',"<br />$file_msg <br />").
3143: &mt_user($user_lh,'The file(s) can be found in your [_1]portfolio[_2].','<a href="/adm/portfolio">','</a>');
3144: my ($feedurl,$showsymb) =
3145: &get_feedurl_and_symb($symb,$domain,$stuname);
3146: my $restitle = &Apache::lonnet::gettitle($symb);
3147: $subject .= ' '.&mt_user($user_lh,'(File Returned)').' ['.$restitle.']';
3148: my $msgstatus =
3149: &Apache::lonmsg::user_normal_msg($stuname,$domain,$subject,
3150: $message,undef,$feedurl,undef,undef,undef,$showsymb,
3151: $restitle);
3152: if ($msgstatus) {
3153: $request->print(&mt('Notification message status: [_1]','<span class="LC_info">'.$msgstatus.'</span>').'<br />');
3154: }
3155: }
1.338 banghart 3156: return;
1.337 banghart 3157: }
3158:
1.418 albertel 3159: sub get_feedurl_and_symb {
3160: my ($symb,$uname,$udom) = @_;
3161: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
3162: $url = &Apache::lonnet::clutter($url);
3163: my $encrypturl=&Apache::lonnet::EXT('resource.0.encrypturl',
3164: $symb,$udom,$uname);
3165: if ($encrypturl =~ /^yes$/i) {
3166: &Apache::lonenc::encrypted(\$url,1);
3167: &Apache::lonenc::encrypted(\$symb,1);
3168: }
3169: return ($url,$symb);
3170: }
3171:
1.313 banghart 3172: sub get_submitted_files {
3173: my ($udom,$uname,$partid,$respid,$record) = @_;
3174: my @files;
3175: if ($$record{"resource.$partid.$respid.portfiles"}) {
3176: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
3177: foreach my $file (split(',',$$record{"resource.$partid.$respid.portfiles"})) {
3178: push(@files,$file_url.$file);
3179: }
3180: }
3181: if ($$record{"resource.$partid.$respid.uploadedurl"}) {
3182: push(@files,$$record{"resource.$partid.$respid.uploadedurl"});
3183: }
3184: return (\@files);
3185: }
1.322 albertel 3186:
1.269 raeburn 3187: # ----------- Provides number of tries since last reset.
3188: sub get_num_tries {
3189: my ($record,$last_reset,$part) = @_;
3190: my $timestamp = '';
3191: my $num_tries = 0;
3192: if ($$record{'version'}) {
3193: for (my $version=$$record{'version'};$version>=1;$version--) {
3194: if (exists($$record{$version.':resource.'.$part.'.solved'})) {
3195: $timestamp = $$record{$version.':timestamp'};
3196: if ($timestamp > $last_reset) {
3197: $num_tries ++;
3198: } else {
3199: last;
3200: }
3201: }
3202: }
3203: }
3204: return $num_tries;
3205: }
3206:
3207: # ----------- Determine decrements required in aggregate totals
3208: sub decrement_aggs {
3209: my ($symb,$part,$aggregate,$aggtries,$totaltries,$solvedstatus) = @_;
3210: my %decrement = (
3211: attempts => 0,
3212: users => 0,
3213: correct => 0
3214: );
3215: $decrement{'attempts'} = $aggtries;
3216: if ($solvedstatus =~ /^correct/) {
3217: $decrement{'correct'} = 1;
3218: }
3219: if ($aggtries == $totaltries) {
3220: $decrement{'users'} = 1;
3221: }
1.524 raeburn 3222: foreach my $type (keys(%decrement)) {
1.269 raeburn 3223: $$aggregate{$symb."\0".$part."\0".$type} = -$decrement{$type};
3224: }
3225: return;
3226: }
3227:
3228: # ----------- Determine timestamps for last reset of aggregate totals for parts
3229: sub get_last_resets {
1.270 albertel 3230: my ($symb,$courseid,$partids) =@_;
3231: my %last_resets;
1.269 raeburn 3232: my $cdom = $env{'course.'.$courseid.'.domain'};
3233: my $cname = $env{'course.'.$courseid.'.num'};
1.271 albertel 3234: my @keys;
3235: foreach my $part (@{$partids}) {
3236: push(@keys,"$symb\0$part\0resettime");
3237: }
3238: my %results=&Apache::lonnet::get('nohist_resourcetracker',\@keys,
3239: $cdom,$cname);
3240: foreach my $part (@{$partids}) {
3241: $last_resets{$part}=$results{"$symb\0$part\0resettime"};
1.269 raeburn 3242: }
1.270 albertel 3243: return %last_resets;
1.269 raeburn 3244: }
3245:
1.251 banghart 3246: # ----------- Handles creating versions for portfolio files as answers
3247: sub version_portfiles {
1.343 banghart 3248: my ($record, $parts_graded, $courseid, $symb, $domain, $stu_name, $v_flag) = @_;
1.263 banghart 3249: my $version_parts = join('|',@$v_flag);
1.343 banghart 3250: my @returned_keys;
1.255 banghart 3251: my $parts = join('|', @$parts_graded);
1.517 raeburn 3252: my $portfolio_root = '/userfiles/portfolio';
1.277 albertel 3253: foreach my $key (keys(%$record)) {
1.259 banghart 3254: my $new_portfiles;
1.263 banghart 3255: if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
1.342 banghart 3256: my @versioned_portfiles;
1.367 albertel 3257: my @portfiles = split(/\s*,\s*/,$$record{$key});
1.252 banghart 3258: foreach my $file (@portfiles) {
1.306 banghart 3259: &Apache::lonnet::unmark_as_readonly($domain,$stu_name,[$symb,$env{'request.course.id'}],$file);
1.304 albertel 3260: my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*)$/);
3261: my ($answer_name,$answer_ver,$answer_ext) =
3262: &file_name_version_ext($answer_file);
1.517 raeburn 3263: my $getpropath = 1;
1.662 raeburn 3264: my ($dir_list,$listerror) =
3265: &Apache::lonnet::dirlist($portfolio_root.$directory,$domain,
3266: $stu_name,$getpropath);
3267: my $version = &get_next_version($answer_name,$answer_ext,$dir_list);
1.306 banghart 3268: my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version);
3269: if ($new_answer ne 'problem getting file') {
1.342 banghart 3270: push(@versioned_portfiles, $directory.$new_answer);
1.306 banghart 3271: &Apache::lonnet::mark_as_readonly($domain,$stu_name,
1.367 albertel 3272: [$directory.$new_answer],
1.306 banghart 3273: [$symb,$env{'request.course.id'},'graded']);
1.259 banghart 3274: }
1.252 banghart 3275: }
1.343 banghart 3276: $$record{$key} = join(',',@versioned_portfiles);
3277: push(@returned_keys,$key);
1.251 banghart 3278: }
3279: }
1.343 banghart 3280: return (@returned_keys);
1.305 banghart 3281: }
3282:
1.307 banghart 3283: sub get_next_version {
1.341 banghart 3284: my ($answer_name, $answer_ext, $dir_list) = @_;
1.307 banghart 3285: my $version;
1.662 raeburn 3286: if (ref($dir_list) eq 'ARRAY') {
3287: foreach my $row (@{$dir_list}) {
3288: my ($file) = split(/\&/,$row,2);
3289: my ($file_name,$file_version,$file_ext) =
3290: &file_name_version_ext($file);
3291: if (($file_name eq $answer_name) &&
3292: ($file_ext eq $answer_ext)) {
3293: # gets here if filename and extension match,
3294: # regardless of version
1.307 banghart 3295: if ($file_version ne '') {
1.662 raeburn 3296: # a versioned file is found so save it for later
3297: if ($file_version > $version) {
3298: $version = $file_version;
3299: }
3300: }
1.307 banghart 3301: }
3302: }
1.662 raeburn 3303: }
1.307 banghart 3304: $version ++;
3305: return($version);
3306: }
3307:
1.305 banghart 3308: sub version_selected_portfile {
1.306 banghart 3309: my ($domain,$stu_name,$directory,$file_name,$version) = @_;
3310: my ($answer_name,$answer_ver,$answer_ext) =
3311: &file_name_version_ext($file_name);
3312: my $new_answer;
3313: $env{'form.copy'} = &Apache::lonnet::getfile("/uploaded/$domain/$stu_name/portfolio$directory$file_name");
3314: if($env{'form.copy'} eq '-1') {
3315: $new_answer = 'problem getting file';
3316: } else {
3317: $new_answer = $answer_name.'.'.$version.'.'.$answer_ext;
3318: my $copy_result = &Apache::lonnet::finishuserfileupload(
3319: $stu_name,$domain,'copy',
3320: '/portfolio'.$directory.$new_answer);
3321: }
3322: return ($new_answer);
1.251 banghart 3323: }
3324:
1.304 albertel 3325: sub file_name_version_ext {
3326: my ($file)=@_;
3327: my @file_parts = split(/\./, $file);
3328: my ($name,$version,$ext);
3329: if (@file_parts > 1) {
3330: $ext=pop(@file_parts);
3331: if (@file_parts > 1 && $file_parts[-1] =~ /^\d+$/) {
3332: $version=pop(@file_parts);
3333: }
3334: $name=join('.',@file_parts);
3335: } else {
3336: $name=join('.',@file_parts);
3337: }
3338: return($name,$version,$ext);
3339: }
3340:
1.44 ng 3341: #--------------------------------------------------------------------------------------
3342: #
3343: #-------------------------- Next few routines handles grading by section or whole class
3344: #
3345: #--- Javascript to handle grading by section or whole class
1.42 ng 3346: sub viewgrades_js {
3347: my ($request) = shift;
3348:
1.539 riegler 3349: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
1.597 wenzelju 3350: $request->print(&Apache::lonhtmlcommon::scripttag(<<VIEWJAVASCRIPT));
1.45 ng 3351: function writePoint(partid,weight,point) {
1.125 ng 3352: var radioButton = document.classgrade["RADVAL_"+partid];
3353: var textbox = document.classgrade["TEXTVAL_"+partid];
1.42 ng 3354: if (point == "textval") {
1.125 ng 3355: point = document.classgrade["TEXTVAL_"+partid].value;
1.109 matthew 3356: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 3357: alert("$alertmsg"+parseFloat(point));
1.42 ng 3358: var resetbox = false;
3359: for (var i=0; i<radioButton.length; i++) {
3360: if (radioButton[i].checked) {
3361: textbox.value = i;
3362: resetbox = true;
3363: }
3364: }
3365: if (!resetbox) {
3366: textbox.value = "";
3367: }
3368: return;
3369: }
1.109 matthew 3370: if (parseFloat(point) > parseFloat(weight)) {
3371: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 3372: ") greater than the weight for the part. Accept?");
3373: if (resp == false) {
3374: textbox.value = "";
3375: return;
3376: }
3377: }
1.42 ng 3378: for (var i=0; i<radioButton.length; i++) {
3379: radioButton[i].checked=false;
1.109 matthew 3380: if (parseFloat(point) == i) {
1.42 ng 3381: radioButton[i].checked=true;
3382: }
3383: }
1.41 ng 3384:
1.42 ng 3385: } else {
1.125 ng 3386: textbox.value = parseFloat(point);
1.42 ng 3387: }
1.41 ng 3388: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3389: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3390: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3391: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3392: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3393: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 3394: if (saveval != "correct") {
3395: scorename.value = point;
1.43 ng 3396: if (selname[0].selected != true) {
3397: selname[0].selected = true;
3398: }
1.42 ng 3399: }
3400: }
1.125 ng 3401: document.classgrade["SELVAL_"+partid][0].selected = true;
1.42 ng 3402: }
3403:
3404: function writeRadText(partid,weight) {
1.125 ng 3405: var selval = document.classgrade["SELVAL_"+partid];
3406: var radioButton = document.classgrade["RADVAL_"+partid];
1.265 www 3407: var override = document.classgrade["FORCE_"+partid].checked;
1.125 ng 3408: var textbox = document.classgrade["TEXTVAL_"+partid];
3409: if (selval[1].selected || selval[2].selected) {
1.42 ng 3410: for (var i=0; i<radioButton.length; i++) {
3411: radioButton[i].checked=false;
3412:
3413: }
3414: textbox.value = "";
3415:
3416: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3417: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3418: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3419: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3420: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3421: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 3422: if ((saveval != "correct") || override) {
1.42 ng 3423: scorename.value = "";
1.125 ng 3424: if (selval[1].selected) {
3425: selname[1].selected = true;
3426: } else {
3427: selname[2].selected = true;
3428: if (Number(document.classgrade["GD_"+user+"_"+partid+"_tries"].value))
3429: {document.classgrade["GD_"+user+"_"+partid+"_tries"].value = '0';}
3430: }
1.42 ng 3431: }
3432: }
1.43 ng 3433: } else {
3434: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3435: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3436: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3437: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3438: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3439: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 3440: if ((saveval != "correct") || override) {
1.125 ng 3441: scorename.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
1.43 ng 3442: selname[0].selected = true;
3443: }
3444: }
3445: }
1.42 ng 3446: }
3447:
3448: function changeSelect(partid,user) {
1.125 ng 3449: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
3450: var textbox = document.classgrade["GD_"+user+'_'+partid+"_awarded"];
1.44 ng 3451: var point = textbox.value;
1.125 ng 3452: var weight = document.classgrade["weight_"+partid].value;
1.44 ng 3453:
1.109 matthew 3454: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 3455: alert("$alertmsg"+parseFloat(point));
1.44 ng 3456: textbox.value = "";
3457: return;
3458: }
1.109 matthew 3459: if (parseFloat(point) > parseFloat(weight)) {
3460: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 3461: ") greater than the weight of the part. Accept?");
3462: if (resp == false) {
3463: textbox.value = "";
3464: return;
3465: }
3466: }
1.42 ng 3467: selval[0].selected = true;
3468: }
3469:
3470: function changeOneScore(partid,user) {
1.125 ng 3471: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
3472: if (selval[1].selected || selval[2].selected) {
3473: document.classgrade["GD_"+user+'_'+partid+"_awarded"].value = "";
3474: if (selval[2].selected) {
3475: document.classgrade["GD_"+user+'_'+partid+"_tries"].value = "0";
3476: }
1.269 raeburn 3477: }
1.42 ng 3478: }
3479:
3480: function resetEntry(numpart) {
3481: for (ctpart=0;ctpart<numpart;ctpart++) {
1.125 ng 3482: var partid = document.classgrade["partid_"+ctpart].value;
3483: var radioButton = document.classgrade["RADVAL_"+partid];
3484: var textbox = document.classgrade["TEXTVAL_"+partid];
3485: var selval = document.classgrade["SELVAL_"+partid];
1.42 ng 3486: for (var i=0; i<radioButton.length; i++) {
3487: radioButton[i].checked=false;
3488:
3489: }
3490: textbox.value = "";
3491: selval[0].selected = true;
3492:
3493: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3494: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3495: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3496: var resetscore = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3497: resetscore.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
3498: var resettries = document.classgrade["GD_"+user+"_"+partid+"_tries"];
3499: resettries.value = document.classgrade["GD_"+user+"_"+partid+"_tries_s"].value;
3500: var saveselval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3501: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 3502: if (saveselval == "excused") {
1.43 ng 3503: if (selname[1].selected == false) { selname[1].selected = true;}
1.42 ng 3504: } else {
1.43 ng 3505: if (selname[0].selected == false) {selname[0].selected = true};
1.42 ng 3506: }
3507: }
1.41 ng 3508: }
1.42 ng 3509: }
3510:
1.41 ng 3511: VIEWJAVASCRIPT
1.42 ng 3512: }
3513:
1.44 ng 3514: #--- show scores for a section or whole class w/ option to change/update a score
1.42 ng 3515: sub viewgrades {
1.608 www 3516: my ($request,$symb) = @_;
1.42 ng 3517: &viewgrades_js($request);
1.41 ng 3518:
1.168 albertel 3519: #need to make sure we have the correct data for later EXT calls,
3520: #thus invalidate the cache
3521: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 3522: $env{'course.'.$env{'request.course.id'}.'.num'},
3523: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 3524: &Apache::lonnet::clear_EXT_cache_status();
3525:
1.398 albertel 3526: my $result='<h3><span class="LC_info">'.&mt('Manual Grading').'</span></h3>';
1.41 ng 3527:
3528: #view individual student submission form - called using Javascript viewOneStudent
1.324 albertel 3529: $result.=&jscriptNform($symb);
1.41 ng 3530:
1.44 ng 3531: #beginning of class grading form
1.442 banghart 3532: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.41 ng 3533: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1.418 albertel 3534: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.38 ng 3535: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.432 banghart 3536: &build_section_inputs().
1.442 banghart 3537: '<input type="hidden" name="Status" value="'.$env{'stu_status'}.'" />'."\n".
1.72 ng 3538:
1.560 raeburn 3539: my ($common_header,$specific_header);
1.257 albertel 3540: if ($env{'form.section'} eq 'all') {
1.560 raeburn 3541: $common_header = &mt('Assign Common Grade to Class');
3542: $specific_header = &mt('Assign Grade to Specific Students in Class');
1.257 albertel 3543: } elsif ($env{'form.section'} eq 'none') {
1.560 raeburn 3544: $common_header = &mt('Assign Common Grade to Students in no Section');
3545: $specific_header = &mt('Assign Grade to Specific Students in no Section');
1.52 albertel 3546: } else {
1.560 raeburn 3547: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
3548: $common_header = &mt('Assign Common Grade to Students in Section(s) [_1]',$section_display);
3549: $specific_header = &mt('Assign Grade to Specific Students in Section(s) [_1]',$section_display);
1.52 albertel 3550: }
1.560 raeburn 3551: $result.= '<h3>'.$common_header.'</h3>'.&Apache::loncommon::start_data_table();
1.44 ng 3552: #radio buttons/text box for assigning points for a section or class.
3553: #handles different parts of a problem
1.582 raeburn 3554: my $res_error;
3555: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
3556: if ($res_error) {
3557: return &navmap_errormsg();
3558: }
1.42 ng 3559: my %weight = ();
3560: my $ctsparts = 0;
1.45 ng 3561: my %seen = ();
1.375 albertel 3562: my @part_response_id = &flatten_responseType($responseType);
3563: foreach my $part_response_id (@part_response_id) {
3564: my ($partid,$respid) = @{ $part_response_id };
3565: my $part_resp = join('_',@{ $part_response_id });
1.45 ng 3566: next if $seen{$partid};
3567: $seen{$partid}++;
1.375 albertel 3568: my $handgrade=$$handgrade{$part_resp};
1.42 ng 3569: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
3570: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
3571:
1.324 albertel 3572: my $display_part=&get_display_part($partid,$symb);
1.485 albertel 3573: my $radio.='<table border="0"><tr>';
1.41 ng 3574: my $ctr = 0;
1.42 ng 3575: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
1.485 albertel 3576: $radio.= '<td><label><input type="radio" name="RADVAL_'.$partid.'" '.
1.54 albertel 3577: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.288 albertel 3578: ','.$ctr.')" />'.$ctr."</label></td>\n";
1.41 ng 3579: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
3580: $ctr++;
3581: }
1.485 albertel 3582: $radio.='</tr></table>';
3583: my $line = '<input type="text" name="TEXTVAL_'.
1.589 bisitz 3584: $partid.'" size="4" '.'onchange="javascript:writePoint(\''.
1.54 albertel 3585: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.539 riegler 3586: $weight{$partid}.' '.&mt('(problem weight)').'</td>'."\n";
3587: $line.= '<td><b>'.&mt('Grade Status').':</b><select name="SELVAL_'.$partid.'"'.
1.589 bisitz 3588: 'onchange="javascript:writeRadText(\''.$partid.'\','.
1.59 albertel 3589: $weight{$partid}.')"> '.
1.401 albertel 3590: '<option selected="selected"> </option>'.
1.485 albertel 3591: '<option value="excused">'.&mt('excused').'</option>'.
3592: '<option value="reset status">'.&mt('reset status').'</option>'.
3593: '</select></td>'.
3594: '<td><label><input type="checkbox" name="FORCE_'.$partid.'" />'.&mt('Override "Correct"').'</label>';
3595: $line.='<input type="hidden" name="partid_'.
3596: $ctsparts.'" value="'.$partid.'" />'."\n";
3597: $line.='<input type="hidden" name="weight_'.
3598: $partid.'" value="'.$weight{$partid}.'" />'."\n";
3599:
3600: $result.=
3601: &Apache::loncommon::start_data_table_row()."\n".
1.577 bisitz 3602: '<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 3603: &Apache::loncommon::end_data_table_row()."\n";
1.42 ng 3604: $ctsparts++;
1.41 ng 3605: }
1.474 albertel 3606: $result.=&Apache::loncommon::end_data_table()."\n".
1.52 albertel 3607: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.485 albertel 3608: $result.='<input type="button" value="'.&mt('Revert to Default').'" '.
1.589 bisitz 3609: 'onclick="javascript:resetEntry('.$ctsparts.');" />';
1.41 ng 3610:
1.44 ng 3611: #table listing all the students in a section/class
3612: #header of table
1.560 raeburn 3613: $result.= '<h3>'.$specific_header.'</h3>'.
3614: &Apache::loncommon::start_data_table().
3615: &Apache::loncommon::start_data_table_header_row().
3616: '<th>'.&mt('No.').'</th>'.
3617: '<th>'.&nameUserString('header')."</th>\n";
1.582 raeburn 3618: my $partserror;
3619: my (@parts) = sort(&getpartlist($symb,\$partserror));
3620: if ($partserror) {
3621: return &navmap_errormsg();
3622: }
1.324 albertel 3623: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.269 raeburn 3624: my @partids = ();
1.41 ng 3625: foreach my $part (@parts) {
3626: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1.539 riegler 3627: my $narrowtext = &mt('Tries');
3628: $display =~ s|^Number of Attempts|$narrowtext <br />|; # makes the column narrower
1.41 ng 3629: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
1.207 albertel 3630: my ($partid) = &split_part_type($part);
1.524 raeburn 3631: push(@partids,$partid);
1.628 www 3632: #
3633: # FIXME: Looks like $display looks at English text
3634: #
1.324 albertel 3635: my $display_part=&get_display_part($partid,$symb);
1.41 ng 3636: if ($display =~ /^Partial Credit Factor/) {
1.485 albertel 3637: $result.='<th>'.
3638: &mt('Score Part: [_1]<br /> (weight = [_2])',
3639: $display_part,$weight{$partid}).'</th>'."\n";
1.41 ng 3640: next;
1.485 albertel 3641:
1.207 albertel 3642: } else {
1.485 albertel 3643: if ($display =~ /Problem Status/) {
3644: my $grade_status_mt = &mt('Grade Status');
3645: $display =~ s{Problem Status}{$grade_status_mt<br />};
3646: }
3647: my $part_mt = &mt('Part:');
3648: $display =~s{\[Part: \Q$partid\E\]}{$part_mt $display_part};
1.41 ng 3649: }
1.485 albertel 3650:
1.474 albertel 3651: $result.='<th>'.$display.'</th>'."\n";
1.41 ng 3652: }
1.474 albertel 3653: $result.=&Apache::loncommon::end_data_table_header_row();
1.44 ng 3654:
1.270 albertel 3655: my %last_resets =
3656: &get_last_resets($symb,$env{'request.course.id'},\@partids);
1.269 raeburn 3657:
1.41 ng 3658: #get info for each student
1.44 ng 3659: #list all the students - with points and grade status
1.257 albertel 3660: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
1.41 ng 3661: my $ctr = 0;
1.294 albertel 3662: foreach (sort
3663: {
3664: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
3665: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
3666: }
3667: return $a cmp $b;
3668: } (keys(%$fullname))) {
1.126 ng 3669: $ctr++;
1.324 albertel 3670: $result.=&viewstudentgrade($symb,$env{'request.course.id'},
1.269 raeburn 3671: $_,$$fullname{$_},\@parts,\%weight,$ctr,\%last_resets);
1.41 ng 3672: }
1.474 albertel 3673: $result.=&Apache::loncommon::end_data_table();
1.41 ng 3674: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.485 albertel 3675: $result.='<input type="button" value="'.&mt('Save').'" '.
1.589 bisitz 3676: 'onclick="javascript:submit();" target="_self" /></form>'."\n";
1.96 albertel 3677: if (scalar(%$fullname) eq 0) {
3678: my $colspan=3+scalar(@parts);
1.433 banghart 3679: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.442 banghart 3680: my $stu_status = join(' or ',&Apache::loncommon::get_env_multiple('form.Status'));
1.433 banghart 3681: $result='<span class="LC_warning">'.
1.485 albertel 3682: &mt('There are no students in section(s) [_1] with enrollment status [_2] to modify or grade.',
1.442 banghart 3683: $section_display, $stu_status).
1.433 banghart 3684: '</span>';
1.96 albertel 3685: }
1.41 ng 3686: return $result;
3687: }
3688:
1.44 ng 3689: #--- call by previous routine to display each student
1.41 ng 3690: sub viewstudentgrade {
1.324 albertel 3691: my ($symb,$courseid,$student,$fullname,$parts,$weight,$ctr,$last_resets) = @_;
1.44 ng 3692: my ($uname,$udom) = split(/:/,$student);
3693: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.269 raeburn 3694: my %aggregates = ();
1.474 albertel 3695: my $result=&Apache::loncommon::start_data_table_row().'<td align="right">'.
1.233 albertel 3696: '<input type="hidden" name="ctr'.($ctr-1).'" value="'.$student.'" />'.
3697: "\n".$ctr.' </td><td> '.
1.44 ng 3698: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 3699: '\');" target="_self">'.$fullname.'</a> '.
1.398 albertel 3700: '<span class="LC_internal_info">('.$uname.($env{'user.domain'} eq $udom ? '' : ':'.$udom).')</span></td>'."\n";
1.281 albertel 3701: $student=~s/:/_/; # colon doen't work in javascript for names
1.63 albertel 3702: foreach my $apart (@$parts) {
3703: my ($part,$type) = &split_part_type($apart);
1.41 ng 3704: my $score=$record{"resource.$part.$type"};
1.276 albertel 3705: $result.='<td align="center">';
1.269 raeburn 3706: my ($aggtries,$totaltries);
3707: unless (exists($aggregates{$part})) {
1.270 albertel 3708: $totaltries = $record{'resource.'.$part.'.tries'};
3709:
3710: $aggtries = $totaltries;
1.269 raeburn 3711: if ($$last_resets{$part}) {
1.270 albertel 3712: $aggtries = &get_num_tries(\%record,$$last_resets{$part},
3713: $part);
3714: }
1.269 raeburn 3715: $result.='<input type="hidden" name="'.
3716: 'GD_'.$student.'_'.$part.'_aggtries" value="'.$aggtries.'" />'."\n";
3717: $result.='<input type="hidden" name="'.
3718: 'GD_'.$student.'_'.$part.'_totaltries" value="'.$totaltries.'" />'."\n";
3719: $aggregates{$part} = 1;
3720: }
1.41 ng 3721: if ($type eq 'awarded') {
1.320 albertel 3722: my $pts = $score eq '' ? '' : &compute_points($score,$$weight{$part});
1.42 ng 3723: $result.='<input type="hidden" name="'.
1.89 albertel 3724: 'GD_'.$student.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.233 albertel 3725: $result.='<input type="text" name="'.
1.89 albertel 3726: 'GD_'.$student.'_'.$part.'_awarded" '.
1.589 bisitz 3727: 'onchange="javascript:changeSelect(\''.$part.'\',\''.$student.
1.44 ng 3728: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41 ng 3729: } elsif ($type eq 'solved') {
3730: my ($status,$foo)=split(/_/,$score,2);
3731: $status = 'nothing' if ($status eq '');
1.89 albertel 3732: $result.='<input type="hidden" name="'.'GD_'.$student.'_'.
1.54 albertel 3733: $part.'_solved_s" value="'.$status.'" />'."\n";
1.233 albertel 3734: $result.=' <select name="'.
1.89 albertel 3735: 'GD_'.$student.'_'.$part.'_solved" '.
1.589 bisitz 3736: 'onchange="javascript:changeOneScore(\''.$part.'\',\''.$student.'\')" >'."\n";
1.485 albertel 3737: $result.= (($status eq 'excused') ? '<option> </option><option selected="selected" value="excused">'.&mt('excused').'</option>'
3738: : '<option selected="selected"> </option><option value="excused">'.&mt('excused').'</option>')."\n";
3739: $result.='<option value="reset status">'.&mt('reset status').'</option>';
1.126 ng 3740: $result.="</select> </td>\n";
1.122 ng 3741: } else {
3742: $result.='<input type="hidden" name="'.
3743: 'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
3744: "\n";
1.233 albertel 3745: $result.='<input type="text" name="'.
1.122 ng 3746: 'GD_'.$student.'_'.$part.'_'.$type.'" '.
3747: 'value="'.$score.'" size="4" /></td>'."\n";
1.41 ng 3748: }
3749: }
1.474 albertel 3750: $result.=&Apache::loncommon::end_data_table_row();
1.41 ng 3751: return $result;
1.38 ng 3752: }
3753:
1.44 ng 3754: #--- change scores for all the students in a section/class
3755: # record does not get update if unchanged
1.38 ng 3756: sub editgrades {
1.608 www 3757: my ($request,$symb) = @_;
1.41 ng 3758:
1.433 banghart 3759: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.477 albertel 3760: my $title='<h2>'.&mt('Current Grade Status').'</h2>';
1.433 banghart 3761: $title.='<h4>'.&mt('<b>Section: </b>[_1]',$section_display).'</h4>'."\n";
1.126 ng 3762:
1.477 albertel 3763: my $result= &Apache::loncommon::start_data_table().
3764: &Apache::loncommon::start_data_table_header_row().
3765: '<th rowspan="2" valign="middle">'.&mt('No.').'</th>'.
3766: '<th rowspan="2" valign="middle">'.&nameUserString('header')."</th>\n";
1.43 ng 3767: my %scoreptr = (
3768: 'correct' =>'correct_by_override',
3769: 'incorrect'=>'incorrect_by_override',
3770: 'excused' =>'excused',
3771: 'ungraded' =>'ungraded_attempted',
1.596 raeburn 3772: 'credited' =>'credit_attempted',
1.43 ng 3773: 'nothing' => '',
3774: );
1.257 albertel 3775: my ($classlist,undef,$fullname) = &getclasslist($env{'form.section'},'0');
1.34 ng 3776:
1.44 ng 3777: my (@partid);
3778: my %weight = ();
1.54 albertel 3779: my %columns = ();
1.44 ng 3780: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54 albertel 3781:
1.582 raeburn 3782: my $partserror;
3783: my (@parts) = sort(&getpartlist($symb,\$partserror));
3784: if ($partserror) {
3785: return &navmap_errormsg();
3786: }
1.54 albertel 3787: my $header;
1.257 albertel 3788: while ($ctr < $env{'form.totalparts'}) {
3789: my $partid = $env{'form.partid_'.$ctr};
1.524 raeburn 3790: push(@partid,$partid);
1.257 albertel 3791: $weight{$partid} = $env{'form.weight_'.$partid};
1.44 ng 3792: $ctr++;
1.54 albertel 3793: }
1.324 albertel 3794: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.54 albertel 3795: foreach my $partid (@partid) {
1.478 albertel 3796: $header .= '<th align="center">'.&mt('Old Score').'</th>'.
3797: '<th align="center">'.&mt('New Score').'</th>';
1.54 albertel 3798: $columns{$partid}=2;
3799: foreach my $stores (@parts) {
3800: my ($part,$type) = &split_part_type($stores);
3801: if ($part !~ m/^\Q$partid\E/) { next;}
3802: if ($type eq 'awarded' || $type eq 'solved') { next; }
3803: my $display=&Apache::lonnet::metadata($url,$stores.'.display');
1.551 raeburn 3804: $display =~ s/\[Part: \Q$part\E\]//;
1.539 riegler 3805: my $narrowtext = &mt('Tries');
3806: $display =~ s/Number of Attempts/$narrowtext/;
3807: $header .= '<th align="center">'.&mt('Old').' '.$display.'</th>'.
3808: '<th align="center">'.&mt('New').' '.$display.'</th>';
1.54 albertel 3809: $columns{$partid}+=2;
3810: }
3811: }
3812: foreach my $partid (@partid) {
1.324 albertel 3813: my $display_part=&get_display_part($partid,$symb);
1.478 albertel 3814: $result .= '<th colspan="'.$columns{$partid}.'" align="center">'.
3815: &mt('Part: [_1] (Weight = [_2])',$display_part,$weight{$partid}).
3816: '</th>';
1.54 albertel 3817:
1.44 ng 3818: }
1.477 albertel 3819: $result .= &Apache::loncommon::end_data_table_header_row().
3820: &Apache::loncommon::start_data_table_header_row().
3821: $header.
3822: &Apache::loncommon::end_data_table_header_row();
3823: my @noupdate;
1.126 ng 3824: my ($updateCtr,$noupdateCtr) = (1,1);
1.257 albertel 3825: for ($i=0; $i<$env{'form.total'}; $i++) {
1.93 albertel 3826: my $line;
1.257 albertel 3827: my $user = $env{'form.ctr'.$i};
1.281 albertel 3828: my ($uname,$udom)=split(/:/,$user);
1.44 ng 3829: my %newrecord;
3830: my $updateflag = 0;
1.281 albertel 3831: $line .= '<td>'.&nameUserString(undef,$$fullname{$user},$uname,$udom).'</td>';
1.108 albertel 3832: my $usec=$classlist->{"$uname:$udom"}[5];
1.105 albertel 3833: if (!&canmodify($usec)) {
1.126 ng 3834: my $numcols=scalar(@partid)*4+2;
1.477 albertel 3835: push(@noupdate,
1.478 albertel 3836: $line."<td colspan=\"$numcols\"><span class=\"LC_warning\">".
3837: &mt('Not allowed to modify student')."</span></td></tr>");
1.105 albertel 3838: next;
3839: }
1.269 raeburn 3840: my %aggregate = ();
3841: my $aggregateflag = 0;
1.281 albertel 3842: $user=~s/:/_/; # colon doen't work in javascript for names
1.44 ng 3843: foreach (@partid) {
1.257 albertel 3844: my $old_aw = $env{'form.GD_'.$user.'_'.$_.'_awarded_s'};
1.54 albertel 3845: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
3846: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
1.257 albertel 3847: my $old_score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
3848: my $awarded = $env{'form.GD_'.$user.'_'.$_.'_awarded'};
1.54 albertel 3849: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
3850: my $partial = $awarded eq '' ? '' : $pcr;
1.44 ng 3851: my $score;
3852: if ($partial eq '') {
1.257 albertel 3853: $score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 3854: } elsif ($partial > 0) {
3855: $score = 'correct_by_override';
3856: } elsif ($partial == 0) {
3857: $score = 'incorrect_by_override';
3858: }
1.257 albertel 3859: my $dropMenu = $env{'form.GD_'.$user.'_'.$_.'_solved'};
1.125 ng 3860: $score = 'excused' if (($dropMenu eq 'excused') && ($score ne 'excused'));
3861:
1.292 albertel 3862: $newrecord{'resource.'.$_.'.regrader'}=
3863: "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 3864: if ($dropMenu eq 'reset status' &&
3865: $old_score ne '') { # ignore if no previous attempts => nothing to reset
1.299 albertel 3866: $newrecord{'resource.'.$_.'.tries'} = '';
1.125 ng 3867: $newrecord{'resource.'.$_.'.solved'} = '';
3868: $newrecord{'resource.'.$_.'.award'} = '';
1.299 albertel 3869: $newrecord{'resource.'.$_.'.awarded'} = '';
1.125 ng 3870: $updateflag = 1;
1.269 raeburn 3871: if ($env{'form.GD_'.$user.'_'.$_.'_aggtries'} > 0) {
3872: my $aggtries = $env{'form.GD_'.$user.'_'.$_.'_aggtries'};
3873: my $totaltries = $env{'form.GD_'.$user.'_'.$_.'_totaltries'};
3874: my $solvedstatus = $env{'form.GD_'.$user.'_'.$_.'_solved_s'};
3875: &decrement_aggs($symb,$_,\%aggregate,$aggtries,$totaltries,$solvedstatus);
3876: $aggregateflag = 1;
3877: }
1.139 albertel 3878: } elsif (!($old_part eq $partial && $old_score eq $score)) {
3879: $updateflag = 1;
3880: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
3881: $newrecord{'resource.'.$_.'.solved'} = $score;
3882: $rec_update++;
1.125 ng 3883: }
3884:
1.93 albertel 3885: $line .= '<td align="center">'.$old_aw.' </td>'.
1.44 ng 3886: '<td align="center">'.$awarded.
3887: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 3888:
1.54 albertel 3889:
3890: my $partid=$_;
3891: foreach my $stores (@parts) {
3892: my ($part,$type) = &split_part_type($stores);
3893: if ($part !~ m/^\Q$partid\E/) { next;}
3894: if ($type eq 'awarded' || $type eq 'solved') { next; }
1.257 albertel 3895: my $old_aw = $env{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
3896: my $awarded = $env{'form.GD_'.$user.'_'.$part.'_'.$type};
1.54 albertel 3897: if ($awarded ne '' && $awarded ne $old_aw) {
3898: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.257 albertel 3899: $newrecord{'resource.'.$part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.54 albertel 3900: $updateflag=1;
3901: }
1.93 albertel 3902: $line .= '<td align="center">'.$old_aw.' </td>'.
1.54 albertel 3903: '<td align="center">'.$awarded.' </td>';
3904: }
1.44 ng 3905: }
1.477 albertel 3906: $line.="\n";
1.301 albertel 3907:
3908: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3909: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3910:
1.44 ng 3911: if ($updateflag) {
3912: $count++;
1.257 albertel 3913: &Apache::lonnet::cstore(\%newrecord,$symb,$env{'request.course.id'},
1.89 albertel 3914: $udom,$uname);
1.301 albertel 3915:
3916: if (&Apache::bridgetask::in_queue('gradingqueue',$symb,$cdom,
3917: $cnum,$udom,$uname)) {
3918: # need to figure out if should be in queue.
3919: my %record =
3920: &Apache::lonnet::restore($symb,$env{'request.course.id'},
3921: $udom,$uname);
3922: my $all_graded = 1;
3923: my $none_graded = 1;
3924: foreach my $part (@parts) {
3925: if ( $record{'resource.'.$part.'.awarded'} eq '' ) {
3926: $all_graded = 0;
3927: } else {
3928: $none_graded = 0;
3929: }
3930: }
3931:
3932: if ($all_graded || $none_graded) {
3933: &Apache::bridgetask::remove_from_queue('gradingqueue',
3934: $symb,$cdom,$cnum,
3935: $udom,$uname);
3936: }
3937: }
3938:
1.477 albertel 3939: $result.=&Apache::loncommon::start_data_table_row().
3940: '<td align="right"> '.$updateCtr.' </td>'.$line.
3941: &Apache::loncommon::end_data_table_row();
1.126 ng 3942: $updateCtr++;
1.93 albertel 3943: } else {
1.477 albertel 3944: push(@noupdate,
3945: '<td align="right"> '.$noupdateCtr.' </td>'.$line);
1.126 ng 3946: $noupdateCtr++;
1.44 ng 3947: }
1.269 raeburn 3948: if ($aggregateflag) {
3949: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 3950: $cdom,$cnum);
1.269 raeburn 3951: }
1.93 albertel 3952: }
1.477 albertel 3953: if (@noupdate) {
1.126 ng 3954: # my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3;
3955: my $numcols=scalar(@partid)*4+2;
1.477 albertel 3956: $result .= &Apache::loncommon::start_data_table_row('LC_empty_row').
1.478 albertel 3957: '<td align="center" colspan="'.$numcols.'">'.
3958: &mt('No Changes Occurred For the Students Below').
3959: '</td>'.
1.477 albertel 3960: &Apache::loncommon::end_data_table_row();
3961: foreach my $line (@noupdate) {
3962: $result.=
3963: &Apache::loncommon::start_data_table_row().
3964: $line.
3965: &Apache::loncommon::end_data_table_row();
3966: }
1.44 ng 3967: }
1.614 www 3968: $result .= &Apache::loncommon::end_data_table();
1.478 albertel 3969: my $msg = '<p><b>'.
3970: &mt('Number of records updated = [_1] for [quant,_2,student].',
3971: $rec_update,$count).'</b><br />'.
3972: '<b>'.&mt('Total number of students = [_1]',$env{'form.total'}).
3973: '</b></p>';
1.44 ng 3974: return $title.$msg.$result;
1.5 albertel 3975: }
1.54 albertel 3976:
3977: sub split_part_type {
3978: my ($partstr) = @_;
3979: my ($temp,@allparts)=split(/_/,$partstr);
3980: my $type=pop(@allparts);
1.439 albertel 3981: my $part=join('_',@allparts);
1.54 albertel 3982: return ($part,$type);
3983: }
3984:
1.44 ng 3985: #------------- end of section for handling grading by section/class ---------
3986: #
3987: #----------------------------------------------------------------------------
3988:
1.5 albertel 3989:
1.44 ng 3990: #----------------------------------------------------------------------------
3991: #
3992: #-------------------------- Next few routines handles grading by csv upload
3993: #
3994: #--- Javascript to handle csv upload
1.27 albertel 3995: sub csvupload_javascript_reverse_associate {
1.573 bisitz 3996: my $error1=&mt('You need to specify the username or the student/employee ID');
1.246 albertel 3997: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3998: return(<<ENDPICK);
3999: function verify(vf) {
4000: var foundsomething=0;
4001: var founduname=0;
1.243 albertel 4002: var foundID=0;
1.27 albertel 4003: for (i=0;i<=vf.nfields.value;i++) {
4004: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 4005: if (i==0 && tw!=0) { foundID=1; }
4006: if (i==1 && tw!=0) { founduname=1; }
4007: if (i!=0 && i!=1 && i!=2 && tw!=0) { foundsomething=1; }
1.27 albertel 4008: }
1.246 albertel 4009: if (founduname==0 && foundID==0) {
4010: alert('$error1');
4011: return;
1.27 albertel 4012: }
4013: if (foundsomething==0) {
1.246 albertel 4014: alert('$error2');
4015: return;
1.27 albertel 4016: }
4017: vf.submit();
4018: }
4019: function flip(vf,tf) {
4020: var nw=eval('vf.f'+tf+'.selectedIndex');
4021: var i;
4022: for (i=0;i<=vf.nfields.value;i++) {
4023: //can not pick the same destination field for both name and domain
4024: if (((i ==0)||(i ==1)) &&
4025: ((tf==0)||(tf==1)) &&
4026: (i!=tf) &&
4027: (eval('vf.f'+i+'.selectedIndex')==nw)) {
4028: eval('vf.f'+i+'.selectedIndex=0;')
4029: }
4030: }
4031: }
4032: ENDPICK
4033: }
4034:
4035: sub csvupload_javascript_forward_associate {
1.573 bisitz 4036: my $error1=&mt('You need to specify the username or the student/employee ID');
1.246 albertel 4037: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 4038: return(<<ENDPICK);
4039: function verify(vf) {
4040: var foundsomething=0;
4041: var founduname=0;
1.243 albertel 4042: var foundID=0;
1.27 albertel 4043: for (i=0;i<=vf.nfields.value;i++) {
4044: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 4045: if (tw==1) { foundID=1; }
4046: if (tw==2) { founduname=1; }
4047: if (tw>3) { foundsomething=1; }
1.27 albertel 4048: }
1.246 albertel 4049: if (founduname==0 && foundID==0) {
4050: alert('$error1');
4051: return;
1.27 albertel 4052: }
4053: if (foundsomething==0) {
1.246 albertel 4054: alert('$error2');
4055: return;
1.27 albertel 4056: }
4057: vf.submit();
4058: }
4059: function flip(vf,tf) {
4060: var nw=eval('vf.f'+tf+'.selectedIndex');
4061: var i;
4062: //can not pick the same destination field twice
4063: for (i=0;i<=vf.nfields.value;i++) {
4064: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
4065: eval('vf.f'+i+'.selectedIndex=0;')
4066: }
4067: }
4068: }
4069: ENDPICK
4070: }
4071:
1.26 albertel 4072: sub csvuploadmap_header {
1.324 albertel 4073: my ($request,$symb,$datatoken,$distotal)= @_;
1.41 ng 4074: my $javascript;
1.257 albertel 4075: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 4076: $javascript=&csvupload_javascript_reverse_associate();
4077: } else {
4078: $javascript=&csvupload_javascript_forward_associate();
4079: }
1.45 ng 4080:
1.418 albertel 4081: $symb = &Apache::lonenc::check_encrypt($symb);
1.632 www 4082: $request->print('<form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">'.
4083: &mt('Total number of records found in file: [_1]',$distotal).'<hr />'.
4084: &mt('Associate entries from the uploaded file with as many fields as you can.'));
4085: my $reverse=&mt("Reverse Association");
1.41 ng 4086: $request->print(<<ENDPICK);
1.632 www 4087: <br />
4088: <input type="button" value="$reverse" onclick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1.26 albertel 4089: <input type="hidden" name="associate" value="" />
4090: <input type="hidden" name="phase" value="three" />
4091: <input type="hidden" name="datatoken" value="$datatoken" />
1.257 albertel 4092: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
4093: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
1.26 albertel 4094: <input type="hidden" name="upfile_associate"
1.257 albertel 4095: value="$env{'form.upfile_associate'}" />
1.26 albertel 4096: <input type="hidden" name="symb" value="$symb" />
1.246 albertel 4097: <input type="hidden" name="command" value="csvuploadoptions" />
1.26 albertel 4098: <hr />
4099: ENDPICK
1.597 wenzelju 4100: $request->print(&Apache::lonhtmlcommon::scripttag($javascript));
1.118 ng 4101: return '';
1.26 albertel 4102:
4103: }
4104:
4105: sub csvupload_fields {
1.582 raeburn 4106: my ($symb,$errorref) = @_;
4107: my (@parts) = &getpartlist($symb,$errorref);
4108: if (ref($errorref)) {
4109: if ($$errorref) {
4110: return;
4111: }
4112: }
4113:
1.556 weissno 4114: my @fields=(['ID','Student/Employee ID'],
1.243 albertel 4115: ['username','Student Username'],
4116: ['domain','Student Domain']);
1.324 albertel 4117: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.41 ng 4118: foreach my $part (sort(@parts)) {
4119: my @datum;
4120: my $display=&Apache::lonnet::metadata($url,$part.'.display');
4121: my $name=$part;
4122: if (!$display) { $display = $name; }
4123: @datum=($name,$display);
1.244 albertel 4124: if ($name=~/^stores_(.*)_awarded/) {
4125: push(@fields,['stores_'.$1.'_points',"Points [Part: $1]"]);
4126: }
1.41 ng 4127: push(@fields,\@datum);
4128: }
4129: return (@fields);
1.26 albertel 4130: }
4131:
4132: sub csvuploadmap_footer {
1.41 ng 4133: my ($request,$i,$keyfields) =@_;
4134: $request->print(<<ENDPICK);
1.26 albertel 4135: </table>
4136: <input type="hidden" name="nfields" value="$i" />
4137: <input type="hidden" name="keyfields" value="$keyfields" />
1.589 bisitz 4138: <input type="button" onclick="javascript:verify(this.form)" value="Assign Grades" /><br />
1.26 albertel 4139: </form>
4140: ENDPICK
4141: }
4142:
1.283 albertel 4143: sub checkforfile_js {
1.638 www 4144: my $alertmsg = &mt('Please use the browse button to select a file from your local directory.');
1.597 wenzelju 4145: my $result = &Apache::lonhtmlcommon::scripttag(<<CSVFORMJS);
1.86 ng 4146: function checkUpload(formname) {
4147: if (formname.upfile.value == "") {
1.539 riegler 4148: alert("$alertmsg");
1.86 ng 4149: return false;
4150: }
4151: formname.submit();
4152: }
4153: CSVFORMJS
1.283 albertel 4154: return $result;
4155: }
4156:
4157: sub upcsvScores_form {
1.608 www 4158: my ($request,$symb) = @_;
1.283 albertel 4159: if (!$symb) {return '';}
4160: my $result=&checkforfile_js();
1.632 www 4161: $result.=&Apache::loncommon::start_data_table().
4162: &Apache::loncommon::start_data_table_header_row().
4163: '<th>'.&mt('Specify a file containing the class scores for current resource.').'</th>'.
4164: &Apache::loncommon::end_data_table_header_row().
4165: &Apache::loncommon::start_data_table_row().'<td>';
1.370 www 4166: my $upload=&mt("Upload Scores");
1.86 ng 4167: my $upfile_select=&Apache::loncommon::upfile_select_html();
1.245 albertel 4168: my $ignore=&mt('Ignore First Line');
1.418 albertel 4169: $symb = &Apache::lonenc::check_encrypt($symb);
1.86 ng 4170: $result.=<<ENDUPFORM;
1.106 albertel 4171: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.86 ng 4172: <input type="hidden" name="symb" value="$symb" />
4173: <input type="hidden" name="command" value="csvuploadmap" />
4174: $upfile_select
1.589 bisitz 4175: <br /><input type="button" onclick="javascript:checkUpload(this.form);" value="$upload" />
1.86 ng 4176: </form>
4177: ENDUPFORM
1.370 www 4178: $result.=&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
1.632 www 4179: &mt("How do I create a CSV file from a spreadsheet")).
4180: '</td>'.
4181: &Apache::loncommon::end_data_table_row().
4182: &Apache::loncommon::end_data_table();
1.86 ng 4183: return $result;
4184: }
4185:
4186:
1.26 albertel 4187: sub csvuploadmap {
1.608 www 4188: my ($request,$symb)= @_;
1.41 ng 4189: if (!$symb) {return '';}
1.72 ng 4190:
1.41 ng 4191: my $datatoken;
1.257 albertel 4192: if (!$env{'form.datatoken'}) {
1.41 ng 4193: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 4194: } else {
1.257 albertel 4195: $datatoken=$env{'form.datatoken'};
1.41 ng 4196: &Apache::loncommon::load_tmp_file($request);
1.26 albertel 4197: }
1.41 ng 4198: my @records=&Apache::loncommon::upfile_record_sep();
1.324 albertel 4199: &csvuploadmap_header($request,$symb,$datatoken,$#records+1);
1.41 ng 4200: my ($i,$keyfields);
4201: if (@records) {
1.582 raeburn 4202: my $fieldserror;
4203: my @fields=&csvupload_fields($symb,\$fieldserror);
4204: if ($fieldserror) {
4205: $request->print(&navmap_errormsg());
4206: return;
4207: }
1.257 albertel 4208: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 4209: &Apache::loncommon::csv_print_samples($request,\@records);
4210: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
4211: \@fields);
4212: foreach (@fields) { $keyfields.=$_->[0].','; }
4213: chop($keyfields);
4214: } else {
4215: unshift(@fields,['none','']);
4216: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
4217: \@fields);
1.311 banghart 4218: foreach my $rec (@records) {
4219: my %temp = &Apache::loncommon::record_sep($rec);
4220: if (%temp) {
4221: $keyfields=join(',',sort(keys(%temp)));
4222: last;
4223: }
4224: }
1.41 ng 4225: }
4226: }
4227: &csvuploadmap_footer($request,$i,$keyfields);
1.72 ng 4228:
1.41 ng 4229: return '';
1.27 albertel 4230: }
4231:
1.246 albertel 4232: sub csvuploadoptions {
1.608 www 4233: my ($request,$symb)= @_;
1.632 www 4234: my $overwrite=&mt('Overwrite any existing score');
1.246 albertel 4235: $request->print(<<ENDPICK);
4236: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
4237: <input type="hidden" name="command" value="csvuploadassign" />
4238: <p>
4239: <label>
4240: <input type="checkbox" name="overwite_scores" checked="checked" />
1.632 www 4241: $overwrite
1.246 albertel 4242: </label>
4243: </p>
4244: ENDPICK
4245: my %fields=&get_fields();
4246: if (!defined($fields{'domain'})) {
1.257 albertel 4247: my $domform = &Apache::loncommon::select_dom_form($env{'request.role.domain'},'default_domain');
1.632 www 4248: $request->print("\n<p>".&mt('Users are in domain: [_1]',$domform)."</p>\n");
1.246 albertel 4249: }
1.257 albertel 4250: foreach my $key (sort(keys(%env))) {
1.246 albertel 4251: if ($key !~ /^form\.(.*)$/) { next; }
4252: my $cleankey=$1;
4253: if ($cleankey eq 'command') { next; }
4254: $request->print('<input type="hidden" name="'.$cleankey.
1.257 albertel 4255: '" value="'.$env{$key}.'" />'."\n");
1.246 albertel 4256: }
4257: # FIXME do a check for any duplicated user ids...
4258: # FIXME do a check for any invalid user ids?...
1.290 albertel 4259: $request->print('<input type="submit" value="Assign Grades" /><br />
4260: <hr /></form>'."\n");
1.246 albertel 4261: return '';
4262: }
4263:
4264: sub get_fields {
4265: my %fields;
1.257 albertel 4266: my @keyfields = split(/\,/,$env{'form.keyfields'});
4267: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
4268: if ($env{'form.upfile_associate'} eq 'reverse') {
4269: if ($env{'form.f'.$i} ne 'none') {
4270: $fields{$keyfields[$i]}=$env{'form.f'.$i};
1.41 ng 4271: }
4272: } else {
1.257 albertel 4273: if ($env{'form.f'.$i} ne 'none') {
4274: $fields{$env{'form.f'.$i}}=$keyfields[$i];
1.41 ng 4275: }
4276: }
1.27 albertel 4277: }
1.246 albertel 4278: return %fields;
4279: }
4280:
4281: sub csvuploadassign {
1.608 www 4282: my ($request,$symb)= @_;
1.246 albertel 4283: if (!$symb) {return '';}
1.345 bowersj2 4284: my $error_msg = '';
1.246 albertel 4285: &Apache::loncommon::load_tmp_file($request);
4286: my @gradedata = &Apache::loncommon::upfile_record_sep();
4287: my %fields=&get_fields();
1.257 albertel 4288: my $courseid=$env{'request.course.id'};
1.97 albertel 4289: my ($classlist) = &getclasslist('all',0);
1.106 albertel 4290: my @notallowed;
1.41 ng 4291: my @skipped;
1.657 raeburn 4292: my @warnings;
1.41 ng 4293: my $countdone=0;
4294: foreach my $grade (@gradedata) {
4295: my %entries=&Apache::loncommon::record_sep($grade);
1.246 albertel 4296: my $domain;
4297: if ($entries{$fields{'domain'}}) {
4298: $domain=$entries{$fields{'domain'}};
4299: } else {
1.257 albertel 4300: $domain=$env{'form.default_domain'};
1.246 albertel 4301: }
1.243 albertel 4302: $domain=~s/\s//g;
1.41 ng 4303: my $username=$entries{$fields{'username'}};
1.160 albertel 4304: $username=~s/\s//g;
1.243 albertel 4305: if (!$username) {
4306: my $id=$entries{$fields{'ID'}};
1.247 albertel 4307: $id=~s/\s//g;
1.243 albertel 4308: my %ids=&Apache::lonnet::idget($domain,$id);
4309: $username=$ids{$id};
4310: }
1.41 ng 4311: if (!exists($$classlist{"$username:$domain"})) {
1.247 albertel 4312: my $id=$entries{$fields{'ID'}};
4313: $id=~s/\s//g;
4314: if ($id) {
4315: push(@skipped,"$id:$domain");
4316: } else {
4317: push(@skipped,"$username:$domain");
4318: }
1.41 ng 4319: next;
4320: }
1.108 albertel 4321: my $usec=$classlist->{"$username:$domain"}[5];
1.106 albertel 4322: if (!&canmodify($usec)) {
4323: push(@notallowed,"$username:$domain");
4324: next;
4325: }
1.244 albertel 4326: my %points;
1.41 ng 4327: my %grades;
4328: foreach my $dest (keys(%fields)) {
1.244 albertel 4329: if ($dest eq 'ID' || $dest eq 'username' ||
4330: $dest eq 'domain') { next; }
4331: if ($entries{$fields{$dest}} =~ /^\s*$/) { next; }
4332: if ($dest=~/stores_(.*)_points/) {
4333: my $part=$1;
4334: my $wgt =&Apache::lonnet::EXT('resource.'.$part.'.weight',
4335: $symb,$domain,$username);
1.345 bowersj2 4336: if ($wgt) {
4337: $entries{$fields{$dest}}=~s/\s//g;
4338: my $pcr=$entries{$fields{$dest}} / $wgt;
1.463 albertel 4339: my $award=($pcr == 0) ? 'incorrect_by_override'
4340: : 'correct_by_override';
1.638 www 4341: if ($pcr>1) {
1.657 raeburn 4342: push(@warnings,&mt("[_1]: point value larger than weight","$username:$domain"));
1.638 www 4343: }
1.345 bowersj2 4344: $grades{"resource.$part.awarded"}=$pcr;
4345: $grades{"resource.$part.solved"}=$award;
4346: $points{$part}=1;
4347: } else {
4348: $error_msg = "<br />" .
4349: &mt("Some point values were assigned"
4350: ." for problems with a weight "
4351: ."of zero. These values were "
4352: ."ignored.");
4353: }
1.244 albertel 4354: } else {
4355: if ($dest=~/stores_(.*)_awarded/) { if ($points{$1}) {next;} }
4356: if ($dest=~/stores_(.*)_solved/) { if ($points{$1}) {next;} }
4357: my $store_key=$dest;
4358: $store_key=~s/^stores/resource/;
4359: $store_key=~s/_/\./g;
4360: $grades{$store_key}=$entries{$fields{$dest}};
4361: }
1.41 ng 4362: }
1.508 www 4363: if (! %grades) {
4364: push(@skipped,&mt("[_1]: no data to save","$username:$domain"));
4365: } else {
4366: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
4367: my $result=&Apache::lonnet::cstore(\%grades,$symb,
1.302 albertel 4368: $env{'request.course.id'},
4369: $domain,$username);
1.508 www 4370: if ($result eq 'ok') {
1.627 www 4371: # Successfully stored
1.508 www 4372: $request->print('.');
1.627 www 4373: # Remove from grading queue
4374: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,
4375: $env{'course.'.$env{'request.course.id'}.'.domain'},
4376: $env{'course.'.$env{'request.course.id'}.'.num'},
4377: $domain,$username);
4378: $countdone++;
4379: } else {
1.508 www 4380: $request->print("<p><span class=\"LC_error\">".
4381: &mt("Failed to save data for student [_1]. Message when trying to save was: [_2]",
4382: "$username:$domain",$result)."</span></p>");
4383: }
4384: $request->rflush();
4385: }
1.41 ng 4386: }
1.570 www 4387: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt("Saved scores for [quant,_1,student]",$countdone),$countdone==0));
1.657 raeburn 4388: if (@warnings) {
4389: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('Warnings generated for the following saved scores:'),1).'<br />');
4390: $request->print(join(', ',@warnings));
4391: }
1.41 ng 4392: if (@skipped) {
1.571 www 4393: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('No scores stored for the following username(s):'),1).'<br />');
4394: $request->print(join(', ',@skipped));
1.106 albertel 4395: }
4396: if (@notallowed) {
1.571 www 4397: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('Modification of scores not allowed for the following username(s):'),1).'<br />');
4398: $request->print(join(', ',@notallowed));
1.41 ng 4399: }
1.106 albertel 4400: $request->print("<br />\n");
1.345 bowersj2 4401: return $error_msg;
1.26 albertel 4402: }
1.44 ng 4403: #------------- end of section for handling csv file upload ---------
4404: #
4405: #-------------------------------------------------------------------
4406: #
1.122 ng 4407: #-------------- Next few routines handle grading by page/sequence
1.72 ng 4408: #
4409: #--- Select a page/sequence and a student to grade
1.68 ng 4410: sub pickStudentPage {
1.608 www 4411: my ($request,$symb) = @_;
1.68 ng 4412:
1.539 riegler 4413: my $alertmsg = &mt('Please select the student you wish to grade.');
1.597 wenzelju 4414: $request->print(&Apache::lonhtmlcommon::scripttag(<<LISTJAVASCRIPT));
1.68 ng 4415:
4416: function checkPickOne(formname) {
1.76 ng 4417: if (radioSelection(formname.student) == null) {
1.539 riegler 4418: alert("$alertmsg");
1.68 ng 4419: return;
4420: }
1.125 ng 4421: ptr = pullDownSelection(formname.selectpage);
4422: formname.page.value = formname["page"+ptr].value;
4423: formname.title.value = formname["title"+ptr].value;
1.68 ng 4424: formname.submit();
4425: }
4426:
4427: LISTJAVASCRIPT
1.118 ng 4428: &commonJSfunctions($request);
1.608 www 4429:
1.257 albertel 4430: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4431: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4432: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.68 ng 4433:
1.398 albertel 4434: my $result='<h3><span class="LC_info"> '.
1.485 albertel 4435: &mt('Manual Grading by Page or Sequence').'</span></h3>';
1.68 ng 4436:
1.80 ng 4437: $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
1.582 raeburn 4438: my $map_error;
4439: my ($titles,$symbx) = &getSymbMap($map_error);
4440: if ($map_error) {
4441: $request->print(&navmap_errormsg());
4442: return;
4443: }
1.137 albertel 4444: my ($curpage) =&Apache::lonnet::decode_symb($symb);
4445: # my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb);
4446: # my $type=($curpage =~ /\.(page|sequence)/);
1.485 albertel 4447: my $select = '<select name="selectpage">'."\n";
1.70 ng 4448: my $ctr=0;
1.68 ng 4449: foreach (@$titles) {
4450: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.485 albertel 4451: $select.='<option value="'.$ctr.'" '.
1.401 albertel 4452: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.71 ng 4453: '>'.$showtitle.'</option>'."\n";
1.70 ng 4454: $ctr++;
1.68 ng 4455: }
1.485 albertel 4456: $select.= '</select>';
1.539 riegler 4457: $result.=' <b>'.&mt('Problems from').':</b> '.$select."<br />\n";
1.485 albertel 4458:
1.70 ng 4459: $ctr=0;
4460: foreach (@$titles) {
4461: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
4462: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
4463: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
4464: $ctr++;
4465: }
1.72 ng 4466: $result.='<input type="hidden" name="page" />'."\n".
4467: '<input type="hidden" name="title" />'."\n";
1.68 ng 4468:
1.485 albertel 4469: my $options =
4470: '<label><input type="radio" name="vProb" value="no" checked="checked" /> '.&mt('no').' </label>'."\n".
4471: '<label><input type="radio" name="vProb" value="yes" /> '.&mt('yes').' </label>'."<br />\n";
1.539 riegler 4472: $result.=' <b>'.&mt('View Problem Text').': </b>'.$options;
1.485 albertel 4473:
4474: $options =
4475: '<label><input type="radio" name="lastSub" value="none" /> '.&mt('none').' </label>'."\n".
4476: '<label><input type="radio" name="lastSub" value="datesub" checked="checked" /> '.&mt('by dates and submissions').'</label>'."\n".
4477: '<label><input type="radio" name="lastSub" value="all" /> '.&mt('all details').' </label>'."\n";
1.539 riegler 4478: $result.=' <b>'.&mt('Submissions').': </b>'.$options;
1.432 banghart 4479:
4480: $result.=&build_section_inputs();
1.442 banghart 4481: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
4482: $result.='<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.72 ng 4483: '<input type="hidden" name="command" value="displayPage" />'."\n".
1.613 www 4484: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."<br />\n";
1.72 ng 4485:
1.539 riegler 4486: $result.=' <b>'.&mt('Use CODE').': </b> <input type="text" name="CODE" value="" /> <br />'."\n";
1.382 albertel 4487:
1.80 ng 4488: $result.=' <input type="button" '.
1.589 bisitz 4489: 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /><br />'."\n";
1.72 ng 4490:
1.68 ng 4491: $request->print($result);
4492:
1.485 albertel 4493: my $studentTable.=' <b>'.&mt('Select a student you wish to grade and then click on the Next button.').'</b><br />'.
1.484 albertel 4494: &Apache::loncommon::start_data_table().
4495: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 4496: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 4497: '<th>'.&nameUserString('header').'</th>'.
1.485 albertel 4498: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 4499: '<th>'.&nameUserString('header').'</th>'.
4500: &Apache::loncommon::end_data_table_header_row();
1.68 ng 4501:
1.76 ng 4502: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.68 ng 4503: my $ptr = 1;
1.294 albertel 4504: foreach my $student (sort
4505: {
4506: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
4507: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
4508: }
4509: return $a cmp $b;
4510: } (keys(%$fullname))) {
1.68 ng 4511: my ($uname,$udom) = split(/:/,$student);
1.484 albertel 4512: $studentTable.=($ptr%2==1 ? &Apache::loncommon::start_data_table_row()
4513: : '</td>');
1.126 ng 4514: $studentTable.='<td align="right">'.$ptr.' </td>';
1.288 albertel 4515: $studentTable.='<td> <label><input type="radio" name="student" value="'.$student.'" /> '
4516: .&nameUserString(undef,$$fullname{$student},$uname,$udom)."</label>\n";
1.484 albertel 4517: $studentTable.=
4518: ($ptr%2 == 0 ? '</td>'.&Apache::loncommon::end_data_table_row()
4519: : '');
1.68 ng 4520: $ptr++;
4521: }
1.484 albertel 4522: if ($ptr%2 == 0) {
4523: $studentTable.='</td><td> </td><td> </td>'.
4524: &Apache::loncommon::end_data_table_row();
4525: }
4526: $studentTable.=&Apache::loncommon::end_data_table()."\n";
1.126 ng 4527: $studentTable.='<input type="button" '.
1.589 bisitz 4528: 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /></form>'."\n";
1.68 ng 4529:
4530: $request->print($studentTable);
4531:
4532: return '';
4533: }
4534:
4535: sub getSymbMap {
1.582 raeburn 4536: my ($map_error) = @_;
1.132 bowersj2 4537: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 4538: unless (ref($navmap)) {
4539: if (ref($map_error)) {
4540: $$map_error = 'navmap';
4541: }
4542: return;
4543: }
1.68 ng 4544: my %symbx = ();
4545: my @titles = ();
1.117 bowersj2 4546: my $minder = 0;
4547:
4548: # Gather every sequence that has problems.
1.240 albertel 4549: my @sequences = $navmap->retrieveResources(undef, sub { shift->is_map(); },
4550: 1,0,1);
1.117 bowersj2 4551: for my $sequence ($navmap->getById('0.0'), @sequences) {
1.241 albertel 4552: if ($navmap->hasResource($sequence, sub { shift->is_problem(); }, 0) ) {
1.381 albertel 4553: my $title = $minder.'.'.
4554: &HTML::Entities::encode($sequence->compTitle(),'"\'&');
4555: push(@titles, $title); # minder in case two titles are identical
4556: $symbx{$title} = &HTML::Entities::encode($sequence->symb(),'"\'&');
1.117 bowersj2 4557: $minder++;
1.241 albertel 4558: }
1.68 ng 4559: }
4560: return \@titles,\%symbx;
4561: }
4562:
1.72 ng 4563: #
4564: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68 ng 4565: sub displayPage {
1.608 www 4566: my ($request,$symb) = @_;
1.257 albertel 4567: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4568: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4569: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
4570: my $pageTitle = $env{'form.page'};
1.103 albertel 4571: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 4572: my ($uname,$udom) = split(/:/,$env{'form.student'});
4573: my $usec=$classlist->{$env{'form.student'}}[5];
1.168 albertel 4574:
4575: #need to make sure we have the correct data for later EXT calls,
4576: #thus invalidate the cache
4577: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 4578: $env{'course.'.$env{'request.course.id'}.'.num'},
4579: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 4580: &Apache::lonnet::clear_EXT_cache_status();
4581:
1.103 albertel 4582: if (!&canview($usec)) {
1.485 albertel 4583: $request->print('<span class="LC_warning">'.&mt('Unable to view requested student. ([_1])',$env{'form.student'}).'</span>');
1.103 albertel 4584: return;
4585: }
1.398 albertel 4586: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.485 albertel 4587: $result.='<h3> '.&mt('Student: [_1]',&nameUserString(undef,$$fullname{$env{'form.student'}},$uname,$udom)).
1.129 ng 4588: '</h3>'."\n";
1.500 albertel 4589: $env{'form.CODE'} = uc($env{'form.CODE'});
1.501 foxr 4590: if (&Apache::lonnet::validCODE(uc($env{'form.CODE'}))) {
1.485 albertel 4591: $result.='<h3> '.&mt('CODE: [_1]',$env{'form.CODE'}).'</h3>'."\n";
1.382 albertel 4592: } else {
4593: delete($env{'form.CODE'});
4594: }
1.71 ng 4595: &sub_page_js($request);
4596: $request->print($result);
4597:
1.132 bowersj2 4598: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 4599: unless (ref($navmap)) {
4600: $request->print(&navmap_errormsg());
4601: return;
4602: }
1.257 albertel 4603: my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($env{'form.page'});
1.68 ng 4604: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 4605: if (!$map) {
1.485 albertel 4606: $request->print('<span class="LC_warning">'.&mt('Unable to view requested sequence. ([_1])',$resUrl).'</span>');
1.288 albertel 4607: return;
4608: }
1.68 ng 4609: my $iterator = $navmap->getIterator($map->map_start(),
4610: $map->map_finish());
4611:
1.71 ng 4612: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72 ng 4613: '<input type="hidden" name="command" value="gradeByPage" />'."\n".
1.257 albertel 4614: '<input type="hidden" name="fullname" value="'.$$fullname{$env{'form.student'}}.'" />'."\n".
4615: '<input type="hidden" name="student" value="'.$env{'form.student'}.'" />'."\n".
1.72 ng 4616: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
1.257 albertel 4617: '<input type="hidden" name="title" value="'.$env{'form.title'}.'" />'."\n".
1.418 albertel 4618: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.613 www 4619: '<input type="hidden" name="overRideScore" value="no" />'."\n";
1.71 ng 4620:
1.382 albertel 4621: if (defined($env{'form.CODE'})) {
4622: $studentTable.=
4623: '<input type="hidden" name="CODE" value="'.$env{'form.CODE'}.'" />'."\n";
4624: }
1.381 albertel 4625: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 4626: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 4627:
1.594 bisitz 4628: $studentTable.=' <span class="LC_info">'.
4629: &mt('Problems graded correct by the computer are marked with a [_1] symbol.',$checkIcon).
4630: '</span>'."\n".
1.484 albertel 4631: &Apache::loncommon::start_data_table().
4632: &Apache::loncommon::start_data_table_header_row().
4633: '<th align="center"> Prob. </th>'.
1.485 albertel 4634: '<th> '.($env{'form.vProb'} eq 'no' ? &mt('Title') : &mt('Problem Text')).'/'.&mt('Grade').'</th>'.
1.484 albertel 4635: &Apache::loncommon::end_data_table_header_row();
1.71 ng 4636:
1.329 albertel 4637: &Apache::lonxml::clear_problem_counter();
1.196 albertel 4638: my ($depth,$question,$prob) = (1,1,1);
1.68 ng 4639: $iterator->next(); # skip the first BEGIN_MAP
4640: my $curRes = $iterator->next(); # for "current resource"
1.101 albertel 4641: while ($depth > 0) {
1.68 ng 4642: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4643: if($curRes == $iterator->END_MAP) { $depth--; }
1.68 ng 4644:
1.385 albertel 4645: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4646: my $parts = $curRes->parts();
1.68 ng 4647: my $title = $curRes->compTitle();
1.71 ng 4648: my $symbx = $curRes->symb();
1.484 albertel 4649: $studentTable.=
4650: &Apache::loncommon::start_data_table_row().
4651: '<td align="center" valign="top" >'.$prob.
1.485 albertel 4652: (scalar(@{$parts}) == 1 ? ''
1.681 raeburn 4653: : '<br />('.&mt('[_1]parts',
4654: scalar(@{$parts}).' ').')'
1.485 albertel 4655: ).
4656: '</td>';
1.71 ng 4657: $studentTable.='<td valign="top">';
1.382 albertel 4658: my %form = ('CODE' => $env{'form.CODE'},);
1.257 albertel 4659: if ($env{'form.vProb'} eq 'yes' ) {
1.144 albertel 4660: $studentTable.=&show_problem($request,$symbx,$uname,$udom,1,
1.383 albertel 4661: undef,'both',\%form);
1.71 ng 4662: } else {
1.382 albertel 4663: my $companswer = &Apache::loncommon::get_student_answers($symbx,$uname,$udom,$env{'request.course.id'},%form);
1.80 ng 4664: $companswer =~ s|<form(.*?)>||g;
4665: $companswer =~ s|</form>||g;
1.71 ng 4666: # while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
1.116 ng 4667: # $companswer =~ s/$1/ /ms;
1.326 albertel 4668: # $request->print('match='.$1."<br />\n");
1.71 ng 4669: # }
1.116 ng 4670: # $companswer =~ s|<table border=\"1\">|<table border=\"0\">|g;
1.539 riegler 4671: $studentTable.=' <b>'.$title.'</b> <br /> <b>'.&mt('Correct answer').':</b><br />'.$companswer;
1.71 ng 4672: }
4673:
1.257 albertel 4674: my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
1.125 ng 4675:
1.257 albertel 4676: if ($env{'form.lastSub'} eq 'datesub') {
1.71 ng 4677: if ($record{'version'} eq '') {
1.485 albertel 4678: $studentTable.='<br /> <span class="LC_warning">'.&mt('No recorded submission for this problem.').'</span><br />';
1.71 ng 4679: } else {
1.116 ng 4680: my %responseType = ();
4681: foreach my $partid (@{$parts}) {
1.147 albertel 4682: my @responseIds =$curRes->responseIds($partid);
4683: my @responseType =$curRes->responseType($partid);
4684: my %responseIds;
4685: for (my $i=0;$i<=$#responseIds;$i++) {
4686: $responseIds{$responseIds[$i]}=$responseType[$i];
4687: }
4688: $responseType{$partid} = \%responseIds;
1.116 ng 4689: }
1.148 albertel 4690: $studentTable.= &displaySubByDates($symbx,\%record,$parts,\%responseType,$checkIcon,$uname,$udom);
1.147 albertel 4691:
1.71 ng 4692: }
1.257 albertel 4693: } elsif ($env{'form.lastSub'} eq 'all') {
4694: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.71 ng 4695: $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
1.257 albertel 4696: $env{'request.course.id'},
1.71 ng 4697: '','.submission');
4698:
4699: }
1.103 albertel 4700: if (&canmodify($usec)) {
1.585 bisitz 4701: $studentTable.=&gradeBox_start();
1.103 albertel 4702: foreach my $partid (@{$parts}) {
4703: $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
4704: $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
4705: $question++;
4706: }
1.585 bisitz 4707: $studentTable.=&gradeBox_end();
1.196 albertel 4708: $prob++;
1.71 ng 4709: }
4710: $studentTable.='</td></tr>';
1.68 ng 4711:
1.103 albertel 4712: }
1.68 ng 4713: $curRes = $iterator->next();
4714: }
4715:
1.589 bisitz 4716: $studentTable.=
4717: '</table>'."\n".
4718: '<input type="button" value="'.&mt('Save').'" '.
4719: 'onclick="javascript:checkSubmitPage(this.form,'.$question.');" />'.
4720: '</form>'."\n";
1.71 ng 4721: $request->print($studentTable);
4722:
4723: return '';
1.119 ng 4724: }
4725:
4726: sub displaySubByDates {
1.148 albertel 4727: my ($symb,$record,$parts,$responseType,$checkIcon,$uname,$udom) = @_;
1.224 albertel 4728: my $isCODE=0;
1.335 albertel 4729: my $isTask = ($symb =~/\.task$/);
1.224 albertel 4730: if (exists($record->{'resource.CODE'})) { $isCODE=1; }
1.467 albertel 4731: my $studentTable=&Apache::loncommon::start_data_table().
4732: &Apache::loncommon::start_data_table_header_row().
4733: '<th>'.&mt('Date/Time').'</th>'.
4734: ($isCODE?'<th>'.&mt('CODE').'</th>':'').
1.671 raeburn 4735: ($isTask?'<th>'.&mt('Version').'</th>':'').
1.467 albertel 4736: '<th>'.&mt('Submission').'</th>'.
4737: '<th>'.&mt('Status').'</th>'.
4738: &Apache::loncommon::end_data_table_header_row();
1.119 ng 4739: my ($version);
4740: my %mark;
1.148 albertel 4741: my %orders;
1.119 ng 4742: $mark{'correct_by_student'} = $checkIcon;
1.147 albertel 4743: if (!exists($$record{'1:timestamp'})) {
1.539 riegler 4744: return '<br /> <span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br />';
1.147 albertel 4745: }
1.335 albertel 4746:
4747: my $interaction;
1.525 raeburn 4748: my $no_increment = 1;
1.640 raeburn 4749: my %lastrndseed;
1.119 ng 4750: for ($version=1;$version<=$$record{'version'};$version++) {
1.467 albertel 4751: my $timestamp =
4752: &Apache::lonlocal::locallocaltime($$record{$version.':timestamp'});
1.335 albertel 4753: if (exists($$record{$version.':resource.0.version'})) {
4754: $interaction = $$record{$version.':resource.0.version'};
4755: }
1.671 raeburn 4756: if ($isTask && $env{'form.previousversion'}) {
4757: next unless ($interaction == $env{'form.previousversion'});
4758: }
1.335 albertel 4759: my $where = ($isTask ? "$version:resource.$interaction"
4760: : "$version:resource");
1.467 albertel 4761: $studentTable.=&Apache::loncommon::start_data_table_row().
4762: '<td>'.$timestamp.'</td>';
1.224 albertel 4763: if ($isCODE) {
4764: $studentTable.='<td>'.$record->{$version.':resource.CODE'}.'</td>';
4765: }
1.671 raeburn 4766: if ($isTask) {
4767: $studentTable.='<td>'.$interaction.'</td>';
4768: }
1.119 ng 4769: my @versionKeys = split(/\:/,$$record{$version.':keys'});
4770: my @displaySub = ();
4771: foreach my $partid (@{$parts}) {
1.640 raeburn 4772: my ($hidden,$type);
4773: $type = $$record{$version.':resource.'.$partid.'.type'};
4774: if (($type eq 'anonsurvey') || ($type eq 'anonsurveycred')) {
1.596 raeburn 4775: $hidden = 1;
4776: }
1.335 albertel 4777: my @matchKey = ($isTask ? sort(grep /^resource\.\d+\.\Q$partid\E\.award$/,@versionKeys)
4778: : sort(grep /^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys));
4779:
1.122 ng 4780: # next if ($$record{"$version:resource.$partid.solved"} eq '');
1.324 albertel 4781: my $display_part=&get_display_part($partid,$symb);
1.147 albertel 4782: foreach my $matchKey (@matchKey) {
1.198 albertel 4783: if (exists($$record{$version.':'.$matchKey}) &&
4784: $$record{$version.':'.$matchKey} ne '') {
1.596 raeburn 4785:
1.335 albertel 4786: my ($responseId)= ($isTask ? ($matchKey=~ /^resource\.(.*?)\.\Q$partid\E\.award$/)
4787: : ($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/));
1.670 raeburn 4788: $displaySub[0].='<span class="LC_nobreak">';
1.577 bisitz 4789: $displaySub[0].='<b>'.&mt('Part: [_1]',$display_part).'</b>'
4790: .' <span class="LC_internal_info">'
1.625 www 4791: .'('.&mt('Response ID: [_1]',$responseId).')'
1.577 bisitz 4792: .'</span>'
4793: .' <b>';
1.596 raeburn 4794: if ($hidden) {
4795: $displaySub[0].= &mt('Anonymous Survey').'</b>';
4796: } else {
1.640 raeburn 4797: my ($trial,$rndseed,$newvariation);
4798: if ($type eq 'randomizetry') {
4799: $trial = $$record{"$where.$partid.tries"};
4800: $rndseed = $$record{"$where.$partid.rndseed"};
4801: }
1.596 raeburn 4802: if ($$record{"$where.$partid.tries"} eq '') {
4803: $displaySub[0].=&mt('Trial not counted');
4804: } else {
4805: $displaySub[0].=&mt('Trial: [_1]',
1.467 albertel 4806: $$record{"$where.$partid.tries"});
1.640 raeburn 4807: if ($rndseed || $lastrndseed{$partid}) {
4808: if ($rndseed ne $lastrndseed{$partid}) {
4809: $newvariation = ' ('.&mt('New variation this try').')';
4810: }
4811: }
4812: $lastrndseed{$partid} = $rndseed;
1.596 raeburn 4813: }
4814: my $responseType=($isTask ? 'Task'
1.335 albertel 4815: : $responseType->{$partid}->{$responseId});
1.596 raeburn 4816: if (!exists($orders{$partid})) { $orders{$partid}={}; }
1.640 raeburn 4817: if ((!exists($orders{$partid}->{$responseId})) || ($trial)) {
1.596 raeburn 4818: $orders{$partid}->{$responseId}=
4819: &get_order($partid,$responseId,$symb,$uname,$udom,
1.640 raeburn 4820: $no_increment,$type,$trial,$rndseed);
1.596 raeburn 4821: }
1.640 raeburn 4822: $displaySub[0].='</b>'.$newvariation.'</span>'; # /nobreak
1.596 raeburn 4823: $displaySub[0].=' '.
1.640 raeburn 4824: &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:",$uname,$udom,$type,$trial,$rndseed).'<br />';
1.596 raeburn 4825: }
1.147 albertel 4826: }
4827: }
1.335 albertel 4828: if (exists($$record{"$where.$partid.checkedin"})) {
1.485 albertel 4829: $displaySub[1].=&mt('Checked in by [_1] into slot [_2]',
4830: $$record{"$where.$partid.checkedin"},
4831: $$record{"$where.$partid.checkedin.slot"}).
4832: '<br />';
1.335 albertel 4833: }
4834: if (exists $$record{"$where.$partid.award"}) {
1.485 albertel 4835: $displaySub[1].='<b>'.&mt('Part:').'</b> '.$display_part.' '.
1.335 albertel 4836: lc($$record{"$where.$partid.award"}).' '.
4837: $mark{$$record{"$where.$partid.solved"}}.
1.147 albertel 4838: '<br />';
4839: }
1.335 albertel 4840: if (exists $$record{"$where.$partid.regrader"}) {
4841: $displaySub[2].=$$record{"$where.$partid.regrader"}.
4842: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
4843: } elsif ($$record{"$version:resource.$partid.regrader"} =~ /\S/) {
4844: $displaySub[2].=
4845: $$record{"$version:resource.$partid.regrader"}.
1.207 albertel 4846: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
1.147 albertel 4847: }
4848: }
4849: # needed because old essay regrader has not parts info
4850: if (exists $$record{"$version:resource.regrader"}) {
4851: $displaySub[2].=$$record{"$version:resource.regrader"};
4852: }
4853: $studentTable.='<td>'.$displaySub[0].' </td><td>'.$displaySub[1];
4854: if ($displaySub[2]) {
1.467 albertel 4855: $studentTable.=&mt('Manually graded by [_1]',$displaySub[2]);
1.147 albertel 4856: }
1.467 albertel 4857: $studentTable.=' </td>'.
4858: &Apache::loncommon::end_data_table_row();
1.119 ng 4859: }
1.467 albertel 4860: $studentTable.=&Apache::loncommon::end_data_table();
1.119 ng 4861: return $studentTable;
1.71 ng 4862: }
4863:
4864: sub updateGradeByPage {
1.608 www 4865: my ($request,$symb) = @_;
1.71 ng 4866:
1.257 albertel 4867: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4868: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4869: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
4870: my $pageTitle = $env{'form.page'};
1.103 albertel 4871: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 4872: my ($uname,$udom) = split(/:/,$env{'form.student'});
4873: my $usec=$classlist->{$env{'form.student'}}[5];
1.103 albertel 4874: if (!&canmodify($usec)) {
1.526 raeburn 4875: $request->print('<span class="LC_warning">'.&mt('Unable to modify requested student ([_1])',$env{'form.student'}).'</span>');
1.103 albertel 4876: return;
4877: }
1.398 albertel 4878: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.526 raeburn 4879: $result.='<h3> '.&mt('Student: ').&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
1.129 ng 4880: '</h3>'."\n";
1.70 ng 4881:
1.68 ng 4882: $request->print($result);
4883:
1.582 raeburn 4884:
1.132 bowersj2 4885: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 4886: unless (ref($navmap)) {
4887: $request->print(&navmap_errormsg());
4888: return;
4889: }
1.257 albertel 4890: my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $env{'form.page'});
1.71 ng 4891: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 4892: if (!$map) {
1.527 raeburn 4893: $request->print('<span class="LC_warning">'.&mt('Unable to grade requested sequence ([_1]).',$resUrl).'</span>');
1.288 albertel 4894: return;
4895: }
1.71 ng 4896: my $iterator = $navmap->getIterator($map->map_start(),
4897: $map->map_finish());
1.70 ng 4898:
1.484 albertel 4899: my $studentTable=
4900: &Apache::loncommon::start_data_table().
4901: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 4902: '<th align="center"> '.&mt('Prob.').' </th>'.
4903: '<th> '.&mt('Title').' </th>'.
4904: '<th> '.&mt('Previous Score').' </th>'.
4905: '<th> '.&mt('New Score').' </th>'.
1.484 albertel 4906: &Apache::loncommon::end_data_table_header_row();
1.71 ng 4907:
4908: $iterator->next(); # skip the first BEGIN_MAP
4909: my $curRes = $iterator->next(); # for "current resource"
1.196 albertel 4910: my ($depth,$question,$prob,$changeflag)= (1,1,1,0);
1.101 albertel 4911: while ($depth > 0) {
1.71 ng 4912: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4913: if($curRes == $iterator->END_MAP) { $depth--; }
1.71 ng 4914:
1.385 albertel 4915: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4916: my $parts = $curRes->parts();
1.71 ng 4917: my $title = $curRes->compTitle();
4918: my $symbx = $curRes->symb();
1.484 albertel 4919: $studentTable.=
4920: &Apache::loncommon::start_data_table_row().
4921: '<td align="center" valign="top" >'.$prob.
1.485 albertel 4922: (scalar(@{$parts}) == 1 ? ''
1.640 raeburn 4923: : '<br />('.&mt('[quant,_1,part]',scalar(@{$parts}))
1.526 raeburn 4924: .')').'</td>';
1.71 ng 4925: $studentTable.='<td valign="top"> <b>'.$title.'</b> </td>';
4926:
4927: my %newrecord=();
4928: my @displayPts=();
1.269 raeburn 4929: my %aggregate = ();
4930: my $aggregateflag = 0;
1.71 ng 4931: foreach my $partid (@{$parts}) {
1.257 albertel 4932: my $newpts = $env{'form.GD_BOX'.$question.'_'.$partid};
4933: my $oldpts = $env{'form.oldpts'.$question.'_'.$partid};
1.71 ng 4934:
1.257 albertel 4935: my $wgt = $env{'form.WGT'.$question.'_'.$partid} != 0 ?
4936: $env{'form.WGT'.$question.'_'.$partid} : 1;
1.71 ng 4937: my $partial = $newpts/$wgt;
4938: my $score;
4939: if ($partial > 0) {
4940: $score = 'correct_by_override';
1.125 ng 4941: } elsif ($newpts ne '') { #empty is taken as 0
1.71 ng 4942: $score = 'incorrect_by_override';
4943: }
1.257 albertel 4944: my $dropMenu = $env{'form.GD_SEL'.$question.'_'.$partid};
1.125 ng 4945: if ($dropMenu eq 'excused') {
1.71 ng 4946: $partial = '';
4947: $score = 'excused';
1.125 ng 4948: } elsif ($dropMenu eq 'reset status'
1.257 albertel 4949: && $env{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
1.125 ng 4950: $newrecord{'resource.'.$partid.'.tries'} = 0;
4951: $newrecord{'resource.'.$partid.'.solved'} = '';
4952: $newrecord{'resource.'.$partid.'.award'} = '';
4953: $newrecord{'resource.'.$partid.'.awarded'} = 0;
1.257 albertel 4954: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 4955: $changeflag++;
4956: $newpts = '';
1.269 raeburn 4957:
4958: my $aggtries = $env{'form.aggtries'.$question.'_'.$partid};
4959: my $totaltries = $env{'form.totaltries'.$question.'_'.$partid};
4960: my $solvedstatus = $env{'form.solved'.$question.'_'.$partid};
4961: if ($aggtries > 0) {
4962: &decrement_aggs($symbx,$partid,\%aggregate,$aggtries,$totaltries,$solvedstatus);
4963: $aggregateflag = 1;
4964: }
1.71 ng 4965: }
1.324 albertel 4966: my $display_part=&get_display_part($partid,$curRes->symb());
1.257 albertel 4967: my $oldstatus = $env{'form.solved'.$question.'_'.$partid};
1.526 raeburn 4968: $displayPts[0].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.71 ng 4969: (($oldstatus eq 'excused') ? 'excused' : $oldpts).
1.326 albertel 4970: ' <br />';
1.526 raeburn 4971: $displayPts[1].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.125 ng 4972: (($score eq 'excused') ? 'excused' : $newpts).
1.326 albertel 4973: ' <br />';
1.71 ng 4974: $question++;
1.380 albertel 4975: next if ($dropMenu eq 'reset status' || ($newpts eq $oldpts && $score ne 'excused'));
1.125 ng 4976:
1.71 ng 4977: $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
1.125 ng 4978: $newrecord{'resource.'.$partid.'.solved'} = $score if $score ne '';
1.257 albertel 4979: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}"
1.125 ng 4980: if (scalar(keys(%newrecord)) > 0);
1.71 ng 4981:
4982: $changeflag++;
4983: }
4984: if (scalar(keys(%newrecord)) > 0) {
1.382 albertel 4985: my %record =
4986: &Apache::lonnet::restore($symbx,$env{'request.course.id'},
4987: $udom,$uname);
4988:
4989: if (&Apache::lonnet::validCODE($env{'form.CODE'})) {
4990: $newrecord{'resource.CODE'} = $env{'form.CODE'};
4991: } elsif (&Apache::lonnet::validCODE($record{'resource.CODE'})) {
4992: $newrecord{'resource.CODE'} = '';
4993: }
1.257 albertel 4994: &Apache::lonnet::cstore(\%newrecord,$symbx,$env{'request.course.id'},
1.71 ng 4995: $udom,$uname);
1.382 albertel 4996: %record = &Apache::lonnet::restore($symbx,
4997: $env{'request.course.id'},
4998: $udom,$uname);
1.380 albertel 4999: &check_and_remove_from_queue($parts,\%record,undef,$symbx,
5000: $cdom,$cnum,$udom,$uname);
1.71 ng 5001: }
1.380 albertel 5002:
1.269 raeburn 5003: if ($aggregateflag) {
5004: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
5005: $env{'course.'.$env{'request.course.id'}.'.domain'},
5006: $env{'course.'.$env{'request.course.id'}.'.num'});
5007: }
1.125 ng 5008:
1.71 ng 5009: $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
5010: '<td valign="top">'.$displayPts[1].'</td>'.
1.484 albertel 5011: &Apache::loncommon::end_data_table_row();
1.68 ng 5012:
1.196 albertel 5013: $prob++;
1.68 ng 5014: }
1.71 ng 5015: $curRes = $iterator->next();
1.68 ng 5016: }
1.98 albertel 5017:
1.484 albertel 5018: $studentTable.=&Apache::loncommon::end_data_table();
1.526 raeburn 5019: my $grademsg=($changeflag == 0 ? &mt('No score was changed or updated.') :
5020: &mt('The scores were changed for [quant,_1,problem].',
5021: $changeflag));
1.76 ng 5022: $request->print($grademsg.$studentTable);
1.68 ng 5023:
1.70 ng 5024: return '';
5025: }
5026:
1.72 ng 5027: #-------- end of section for handling grading by page/sequence ---------
5028: #
5029: #-------------------------------------------------------------------
5030:
1.581 www 5031: #-------------------- Bubblesheet (Scantron) Grading -------------------
1.75 albertel 5032: #
5033: #------ start of section for handling grading by page/sequence ---------
5034:
1.423 albertel 5035: =pod
5036:
5037: =head1 Bubble sheet grading routines
5038:
1.424 albertel 5039: For this documentation:
5040:
5041: 'scanline' refers to the full line of characters
5042: from the file that we are parsing that represents one entire sheet
5043:
5044: 'bubble line' refers to the data
1.659 raeburn 5045: representing the line of bubbles that are on the physical bubblesheet
1.424 albertel 5046:
5047:
1.659 raeburn 5048: The overall process is that a scanned in bubblesheet data is uploaded
1.424 albertel 5049: into a course. When a user wants to grade, they select a
1.659 raeburn 5050: sequence/folder of resources, a file of bubblesheet info, and pick
1.424 albertel 5051: one of the predefined configurations for what each scanline looks
5052: like.
5053:
5054: Next each scanline is checked for any errors of either 'missing
1.435 foxr 5055: bubbles' (it's an error because it may have been mis-scanned
1.424 albertel 5056: because too light bubbling), 'double bubble' (each bubble line should
5057: have no more that one letter picked), invalid or duplicated CODE,
1.556 weissno 5058: invalid student/employee ID
1.424 albertel 5059:
5060: If the CODE option is used that determines the randomization of the
1.556 weissno 5061: homework problems, either way the student/employee ID is looked up into a
1.424 albertel 5062: username:domain.
5063:
5064: During the validation phase the instructor can choose to skip scanlines.
5065:
1.659 raeburn 5066: After the validation phase, there are now 3 bubblesheet files
1.424 albertel 5067:
5068: scantron_original_filename (unmodified original file)
5069: scantron_corrected_filename (file where the corrected information has replaced the original information)
5070: scantron_skipped_filename (contains the exact text of scanlines that where skipped)
5071:
5072: Also there is a separate hash nohist_scantrondata that contains extra
1.659 raeburn 5073: correction information that isn't representable in the bubblesheet
1.424 albertel 5074: file (see &scantron_getfile() for more information)
5075:
5076: After all scanlines are either valid, marked as valid or skipped, then
5077: foreach line foreach problem in the picked sequence, an ssi request is
5078: made that simulates a user submitting their selected letter(s) against
5079: the homework problem.
1.423 albertel 5080:
5081: =over 4
5082:
5083:
5084:
5085: =item defaultFormData
5086:
5087: Returns html hidden inputs used to hold context/default values.
5088:
5089: Arguments:
5090: $symb - $symb of the current resource
5091:
5092: =cut
1.422 foxr 5093:
1.81 albertel 5094: sub defaultFormData {
1.324 albertel 5095: my ($symb)=@_;
1.613 www 5096: return '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />';
1.81 albertel 5097: }
5098:
1.447 foxr 5099:
1.423 albertel 5100: =pod
5101:
5102: =item getSequenceDropDown
5103:
5104: Return html dropdown of possible sequences to grade
5105:
5106: Arguments:
1.582 raeburn 5107: $symb - $symb of the current resource
5108: $map_error - ref to scalar which will container error if
5109: $navmap object is unavailable in &getSymbMap().
1.423 albertel 5110:
5111: =cut
1.422 foxr 5112:
1.75 albertel 5113: sub getSequenceDropDown {
1.582 raeburn 5114: my ($symb,$map_error)=@_;
1.75 albertel 5115: my $result='<select name="selectpage">'."\n";
1.582 raeburn 5116: my ($titles,$symbx) = &getSymbMap($map_error);
5117: if (ref($map_error)) {
5118: return if ($$map_error);
5119: }
1.137 albertel 5120: my ($curpage)=&Apache::lonnet::decode_symb($symb);
1.75 albertel 5121: my $ctr=0;
5122: foreach (@$titles) {
5123: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
5124: $result.='<option value="'.$$symbx{$_}.'" '.
1.401 albertel 5125: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.75 albertel 5126: '>'.$showtitle.'</option>'."\n";
5127: $ctr++;
5128: }
5129: $result.= '</select>';
5130: return $result;
5131: }
5132:
1.495 albertel 5133: my %bubble_lines_per_response; # no. bubble lines for each response.
1.554 raeburn 5134: # key is zero-based index - 0, 1, 2 ...
1.495 albertel 5135:
5136: my %first_bubble_line; # First bubble line no. for each bubble.
5137:
1.509 raeburn 5138: my %subdivided_bubble_lines; # no. bubble lines for optionresponse,
5139: # matchresponse or rankresponse, where
5140: # an individual response can have multiple
5141: # lines
1.503 raeburn 5142:
5143: my %responsetype_per_response; # responsetype for each response
5144:
1.691 raeburn 5145: my %masterseq_id_responsenum; # src_id (e.g., 12.3_0.11 etc.) for each
5146: # numbered response. Needed when randomorder
5147: # or randompick are in use. Key is ID, value
5148: # is response number.
5149:
1.495 albertel 5150: # Save and restore the bubble lines array to the form env.
5151:
5152:
5153: sub save_bubble_lines {
5154: foreach my $line (keys(%bubble_lines_per_response)) {
5155: $env{"form.scantron.bubblelines.$line"} = $bubble_lines_per_response{$line};
5156: $env{"form.scantron.first_bubble_line.$line"} =
5157: $first_bubble_line{$line};
1.503 raeburn 5158: $env{"form.scantron.sub_bubblelines.$line"} =
5159: $subdivided_bubble_lines{$line};
5160: $env{"form.scantron.responsetype.$line"} =
5161: $responsetype_per_response{$line};
1.495 albertel 5162: }
1.691 raeburn 5163: foreach my $resid (keys(%masterseq_id_responsenum)) {
5164: my $line = $masterseq_id_responsenum{$resid};
5165: $env{"form.scantron.residpart.$line"} = $resid;
5166: }
1.495 albertel 5167: }
5168:
5169:
5170: sub restore_bubble_lines {
5171: my $line = 0;
5172: %bubble_lines_per_response = ();
1.691 raeburn 5173: %masterseq_id_responsenum = ();
1.495 albertel 5174: while ($env{"form.scantron.bubblelines.$line"}) {
5175: my $value = $env{"form.scantron.bubblelines.$line"};
5176: $bubble_lines_per_response{$line} = $value;
5177: $first_bubble_line{$line} =
5178: $env{"form.scantron.first_bubble_line.$line"};
1.503 raeburn 5179: $subdivided_bubble_lines{$line} =
5180: $env{"form.scantron.sub_bubblelines.$line"};
5181: $responsetype_per_response{$line} =
5182: $env{"form.scantron.responsetype.$line"};
1.691 raeburn 5183: my $id = $env{"form.scantron.residpart.$line"};
5184: $masterseq_id_responsenum{$id} = $line;
1.495 albertel 5185: $line++;
5186: }
5187: }
5188:
1.423 albertel 5189: =pod
5190:
5191: =item scantron_filenames
5192:
5193: Returns a list of the scantron files in the current course
5194:
5195: =cut
1.422 foxr 5196:
1.202 albertel 5197: sub scantron_filenames {
1.257 albertel 5198: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5199: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
1.517 raeburn 5200: my $getpropath = 1;
1.662 raeburn 5201: my ($dirlist,$listerror) = &Apache::lonnet::dirlist('userfiles',$cdom,
5202: $cname,$getpropath);
1.202 albertel 5203: my @possiblenames;
1.662 raeburn 5204: if (ref($dirlist) eq 'ARRAY') {
5205: foreach my $filename (sort(@{$dirlist})) {
5206: ($filename)=split(/&/,$filename);
5207: if ($filename!~/^scantron_orig_/) { next ; }
5208: $filename=~s/^scantron_orig_//;
5209: push(@possiblenames,$filename);
5210: }
1.202 albertel 5211: }
5212: return @possiblenames;
5213: }
5214:
1.423 albertel 5215: =pod
5216:
5217: =item scantron_uploads
5218:
5219: Returns html drop-down list of scantron files in current course.
5220:
5221: Arguments:
5222: $file2grade - filename to set as selected in the dropdown
5223:
5224: =cut
1.422 foxr 5225:
1.202 albertel 5226: sub scantron_uploads {
1.209 ng 5227: my ($file2grade) = @_;
1.202 albertel 5228: my $result= '<select name="scantron_selectfile">';
5229: $result.="<option></option>";
5230: foreach my $filename (sort(&scantron_filenames())) {
1.401 albertel 5231: $result.="<option".($filename eq $file2grade ? ' selected="selected"':'').">$filename</option>\n";
1.81 albertel 5232: }
5233: $result.="</select>";
5234: return $result;
5235: }
5236:
1.423 albertel 5237: =pod
5238:
5239: =item scantron_scantab
5240:
5241: Returns html drop down of the scantron formats in the scantronformat.tab
5242: file.
5243:
5244: =cut
1.422 foxr 5245:
1.82 albertel 5246: sub scantron_scantab {
5247: my $result='<select name="scantron_format">'."\n";
1.191 albertel 5248: $result.='<option></option>'."\n";
1.518 raeburn 5249: my @lines = &get_scantronformat_file();
5250: if (@lines > 0) {
5251: foreach my $line (@lines) {
5252: next if (($line =~ /^\#/) || ($line eq ''));
5253: my ($name,$descrip)=split(/:/,$line);
5254: $result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
5255: }
1.82 albertel 5256: }
5257: $result.='</select>'."\n";
1.518 raeburn 5258: return $result;
5259: }
5260:
5261: =pod
5262:
5263: =item get_scantronformat_file
5264:
5265: Returns an array containing lines from the scantron format file for
5266: the domain of the course.
5267:
5268: If a url for a custom.tab file is listed in domain's configuration.db,
5269: lines are from this file.
5270:
5271: Otherwise, if a default.tab has been published in RES space by the
5272: domainconfig user, lines are from this file.
5273:
5274: Otherwise, fall back to getting lines from the legacy file on the
1.519 raeburn 5275: local server: /home/httpd/lonTabs/default_scantronformat.tab
1.82 albertel 5276:
1.518 raeburn 5277: =cut
5278:
5279: sub get_scantronformat_file {
5280: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
5281: my %domconfig = &Apache::lonnet::get_dom('configuration',['scantron'],$cdom);
5282: my $gottab = 0;
5283: my @lines;
5284: if (ref($domconfig{'scantron'}) eq 'HASH') {
5285: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
5286: my $formatfile = &Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.$domconfig{'scantron'}{'scantronformat'});
5287: if ($formatfile ne '-1') {
5288: @lines = split("\n",$formatfile,-1);
5289: $gottab = 1;
5290: }
5291: }
5292: }
5293: if (!$gottab) {
5294: my $confname = $cdom.'-domainconfig';
5295: my $default = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res/'.$cdom.'/'.$confname.'/default.tab';
5296: my $formatfile = &Apache::lonnet::getfile($default);
5297: if ($formatfile ne '-1') {
5298: @lines = split("\n",$formatfile,-1);
5299: $gottab = 1;
5300: }
5301: }
5302: if (!$gottab) {
1.519 raeburn 5303: my @domains = &Apache::lonnet::current_machine_domains();
5304: if (grep(/^\Q$cdom\E$/,@domains)) {
5305: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
5306: @lines = <$fh>;
5307: close($fh);
5308: } else {
5309: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab');
5310: @lines = <$fh>;
5311: close($fh);
5312: }
1.518 raeburn 5313: }
5314: return @lines;
1.82 albertel 5315: }
5316:
1.423 albertel 5317: =pod
5318:
5319: =item scantron_CODElist
5320:
5321: Returns html drop down of the saved CODE lists from current course,
5322: generated from earlier printings.
5323:
5324: =cut
1.422 foxr 5325:
1.186 albertel 5326: sub scantron_CODElist {
1.257 albertel 5327: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5328: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.186 albertel 5329: my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
5330: my $namechoice='<option></option>';
1.225 albertel 5331: foreach my $name (sort {uc($a) cmp uc($b)} @names) {
1.191 albertel 5332: if ($name =~ /^error: 2 /) { next; }
1.278 albertel 5333: if ($name =~ /^type\0/) { next; }
1.186 albertel 5334: $namechoice.='<option value="'.$name.'">'.$name.'</option>';
5335: }
5336: $namechoice='<select name="scantron_CODElist">'.$namechoice.'</select>';
5337: return $namechoice;
5338: }
5339:
1.423 albertel 5340: =pod
5341:
5342: =item scantron_CODEunique
5343:
5344: Returns the html for "Each CODE to be used once" radio.
5345:
5346: =cut
1.422 foxr 5347:
1.186 albertel 5348: sub scantron_CODEunique {
1.532 bisitz 5349: my $result='<span class="LC_nobreak">
1.272 albertel 5350: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 5351: value="yes" checked="checked" />'.&mt('Yes').' </label>
1.381 albertel 5352: </span>
1.532 bisitz 5353: <span class="LC_nobreak">
1.272 albertel 5354: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 5355: value="no" />'.&mt('No').' </label>
1.381 albertel 5356: </span>';
1.186 albertel 5357: return $result;
5358: }
1.423 albertel 5359:
5360: =pod
5361:
5362: =item scantron_selectphase
5363:
1.659 raeburn 5364: Generates the initial screen to start the bubblesheet process.
1.423 albertel 5365: Allows for - starting a grading run.
1.424 albertel 5366: - downloading existing scan data (original, corrected
1.423 albertel 5367: or skipped info)
5368:
5369: - uploading new scan data
5370:
5371: Arguments:
5372: $r - The Apache request object
5373: $file2grade - name of the file that contain the scanned data to score
5374:
5375: =cut
1.186 albertel 5376:
1.75 albertel 5377: sub scantron_selectphase {
1.608 www 5378: my ($r,$file2grade,$symb) = @_;
1.75 albertel 5379: if (!$symb) {return '';}
1.582 raeburn 5380: my $map_error;
5381: my $sequence_selector=&getSequenceDropDown($symb,\$map_error);
5382: if ($map_error) {
5383: $r->print('<br />'.&navmap_errormsg().'<br />');
5384: return;
5385: }
1.324 albertel 5386: my $default_form_data=&defaultFormData($symb);
1.209 ng 5387: my $file_selector=&scantron_uploads($file2grade);
1.82 albertel 5388: my $format_selector=&scantron_scantab();
1.186 albertel 5389: my $CODE_selector=&scantron_CODElist();
5390: my $CODE_unique=&scantron_CODEunique();
1.75 albertel 5391: my $result;
1.422 foxr 5392:
1.513 foxr 5393: $ssi_error = 0;
5394:
1.606 wenzelju 5395: if (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) ||
5396: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
5397:
5398: # Chunk of form to prompt for a scantron file upload.
5399:
5400: $r->print('
5401: <br />
5402: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5403: '.&Apache::loncommon::start_data_table_header_row().'
5404: <th>
5405: '.&mt('Specify a bubblesheet data file to upload.').'
5406: </th>
5407: '.&Apache::loncommon::end_data_table_header_row().'
5408: '.&Apache::loncommon::start_data_table_row().'
5409: <td>
5410: ');
1.608 www 5411: my $default_form_data=&defaultFormData($symb);
1.606 wenzelju 5412: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
5413: my $cnum= $env{'course.'.$env{'request.course.id'}.'.num'};
5414: $r->print(&Apache::lonhtmlcommon::scripttag('
5415: function checkUpload(formname) {
5416: if (formname.upfile.value == "") {
5417: alert("'.&mt('Please use the browse button to select a file from your local directory.').'");
5418: return false;
5419: }
5420: formname.submit();
5421: }'));
5422: $r->print('
5423: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
5424: '.$default_form_data.'
5425: <input name="courseid" type="hidden" value="'.$cnum.'" />
5426: <input name="domainid" type="hidden" value="'.$cdom.'" />
5427: <input name="command" value="scantronupload_save" type="hidden" />
5428: '.&mt('File to upload: [_1]','<input type="file" name="upfile" size="50" />').'
5429: <br />
5430: <input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
5431: </form>
5432: ');
5433:
5434: $r->print('
5435: </td>
5436: '.&Apache::loncommon::end_data_table_row().'
5437: '.&Apache::loncommon::end_data_table().'
5438: ');
5439: }
5440:
1.422 foxr 5441: # Chunk of form to prompt for a file to grade and how:
5442:
1.489 albertel 5443: $result.= '
5444: <br />
5445: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantron_process">
5446: <input type="hidden" name="command" value="scantron_warning" />
5447: '.$default_form_data.'
5448: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5449: '.&Apache::loncommon::start_data_table_header_row().'
5450: <th colspan="2">
1.492 albertel 5451: '.&mt('Specify file and which Folder/Sequence to grade').'
1.489 albertel 5452: </th>
5453: '.&Apache::loncommon::end_data_table_header_row().'
5454: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5455: <td> '.&mt('Sequence to grade:').' </td><td> '.$sequence_selector.' </td>
1.489 albertel 5456: '.&Apache::loncommon::end_data_table_row().'
5457: '.&Apache::loncommon::start_data_table_row().'
1.572 www 5458: <td> '.&mt('Filename of bubblesheet data file:').' </td><td> '.$file_selector.' </td>
1.489 albertel 5459: '.&Apache::loncommon::end_data_table_row().'
5460: '.&Apache::loncommon::start_data_table_row().'
1.572 www 5461: <td> '.&mt('Format of bubblesheet data file:').' </td><td> '.$format_selector.' </td>
1.489 albertel 5462: '.&Apache::loncommon::end_data_table_row().'
5463: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5464: <td> '.&mt('Saved CODEs to validate against:').' </td><td> '.$CODE_selector.' </td>
1.489 albertel 5465: '.&Apache::loncommon::end_data_table_row().'
5466: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5467: <td> '.&mt('Each CODE is only to be used once:').'</td><td> '.$CODE_unique.' </td>
1.489 albertel 5468: '.&Apache::loncommon::end_data_table_row().'
5469: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5470: <td> '.&mt('Options:').' </td>
1.187 albertel 5471: <td>
1.492 albertel 5472: <label><input type="checkbox" name="scantron_options_redo" value="redo_skipped"/> '.&mt('Do only previously skipped records').'</label> <br />
5473: <label><input type="checkbox" name="scantron_options_ignore" value="ignore_corrections"/> '.&mt('Remove all existing corrections').'</label> <br />
5474: <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources when grading').'</label>
1.187 albertel 5475: </td>
1.489 albertel 5476: '.&Apache::loncommon::end_data_table_row().'
5477: '.&Apache::loncommon::start_data_table_row().'
1.174 albertel 5478: <td colspan="2">
1.572 www 5479: <input type="submit" value="'.&mt('Grading: Validate Bubblesheet Records').'" />
1.162 albertel 5480: </td>
1.489 albertel 5481: '.&Apache::loncommon::end_data_table_row().'
5482: '.&Apache::loncommon::end_data_table().'
5483: </form>
5484: ';
1.162 albertel 5485:
5486: $r->print($result);
5487:
1.422 foxr 5488:
5489:
5490: # Chunk of the form that prompts to view a scoring office file,
5491: # corrected file, skipped records in a file.
5492:
1.489 albertel 5493: $r->print('
5494: <br />
5495: <form action="/adm/grades" name="scantron_download">
5496: '.$default_form_data.'
5497: <input type="hidden" name="command" value="scantron_download" />
5498: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5499: '.&Apache::loncommon::start_data_table_header_row().'
5500: <th>
1.492 albertel 5501: '.&mt('Download a scoring office file').'
1.489 albertel 5502: </th>
5503: '.&Apache::loncommon::end_data_table_header_row().'
5504: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5505: <td> '.&mt('Filename of scoring office file: [_1]',$file_selector).'
1.489 albertel 5506: <br />
1.492 albertel 5507: <input type="submit" value="'.&mt('Download: Show List of Associated Files').'" />
1.489 albertel 5508: '.&Apache::loncommon::end_data_table_row().'
5509: '.&Apache::loncommon::end_data_table().'
5510: </form>
5511: <br />
5512: ');
1.162 albertel 5513:
1.457 banghart 5514: &Apache::lonpickcode::code_list($r,2);
1.523 raeburn 5515:
1.694 ! bisitz 5516: $r->print('<br /><form method="post" name="checkscantron" action="">'.
1.523 raeburn 5517: $default_form_data."\n".
5518: &Apache::loncommon::start_data_table('LC_scantron_action')."\n".
5519: &Apache::loncommon::start_data_table_header_row()."\n".
5520: '<th colspan="2">
1.572 www 5521: '.&mt('Review bubblesheet data and submissions for a previously graded folder/sequence')."\n".
1.523 raeburn 5522: '</th>'."\n".
5523: &Apache::loncommon::end_data_table_header_row()."\n".
5524: &Apache::loncommon::start_data_table_row()."\n".
5525: '<td> '.&mt('Graded folder/sequence:').' </td>'."\n".
5526: '<td> '.$sequence_selector.' </td>'.
5527: &Apache::loncommon::end_data_table_row()."\n".
5528: &Apache::loncommon::start_data_table_row()."\n".
5529: '<td> '.&mt('Filename of scoring office file:').' </td>'."\n".
5530: '<td> '.$file_selector.' </td>'."\n".
5531: &Apache::loncommon::end_data_table_row()."\n".
5532: &Apache::loncommon::start_data_table_row()."\n".
5533: '<td> '.&mt('Format of data file:').' </td>'."\n".
5534: '<td> '.$format_selector.' </td>'."\n".
5535: &Apache::loncommon::end_data_table_row()."\n".
5536: &Apache::loncommon::start_data_table_row()."\n".
1.557 raeburn 5537: '<td> '.&mt('Options').' </td>'."\n".
5538: '<td> <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources').'</label></td>'.
5539: &Apache::loncommon::end_data_table_row()."\n".
5540: &Apache::loncommon::start_data_table_row()."\n".
1.523 raeburn 5541: '<td colspan="2">'."\n".
5542: '<input type="hidden" name="command" value="checksubmissions" />'."\n".
1.575 www 5543: '<input type="submit" value="'.&mt('Review Bubblesheet Data and Submission Records').'" />'."\n".
1.523 raeburn 5544: '</td>'."\n".
5545: &Apache::loncommon::end_data_table_row()."\n".
5546: &Apache::loncommon::end_data_table()."\n".
5547: '</form><br />');
5548: return;
1.75 albertel 5549: }
5550:
1.423 albertel 5551: =pod
5552:
5553: =item get_scantron_config
5554:
5555: Parse and return the scantron configuration line selected as a
5556: hash of configuration file fields.
5557:
5558: Arguments:
5559: which - the name of the configuration to parse from the file.
5560:
5561:
5562: Returns:
5563: If the named configuration is not in the file, an empty
5564: hash is returned.
5565: a hash with the fields
5566: name - internal name for the this configuration setup
5567: description - text to display to operator that describes this config
5568: CODElocation - if 0 or the string 'none'
5569: - no CODE exists for this config
5570: if -1 || the string 'letter'
5571: - a CODE exists for this config and is
5572: a string of letters
5573: Unsupported value (but planned for future support)
5574: if a positive integer
5575: - The CODE exists as the first n items from
5576: the question section of the form
5577: if the string 'number'
5578: - The CODE exists for this config and is
5579: a string of numbers
5580: CODEstart - (only matter if a CODE exists) column in the line where
5581: the CODE starts
5582: CODElength - length of the CODE
1.573 bisitz 5583: IDstart - column where the student/employee ID starts
1.556 weissno 5584: IDlength - length of the student/employee ID info
1.423 albertel 5585: Qstart - column where the information from the bubbled
5586: 'questions' start
5587: Qlength - number of columns comprising a single bubble line from
5588: the sheet. (usually either 1 or 10)
1.424 albertel 5589: Qon - either a single character representing the character used
1.423 albertel 5590: to signal a bubble was chosen in the positional setup, or
5591: the string 'letter' if the letter of the chosen bubble is
5592: in the final, or 'number' if a number representing the
5593: chosen bubble is in the file (1->A 0->J)
1.424 albertel 5594: Qoff - the character used to represent that a bubble was
5595: left blank
1.423 albertel 5596: PaperID - if the scanning process generates a unique number for each
5597: sheet scanned the column that this ID number starts in
5598: PaperIDlength - number of columns that comprise the unique ID number
5599: for the sheet of paper
1.424 albertel 5600: FirstName - column that the first name starts in
1.423 albertel 5601: FirstNameLength - number of columns that the first name spans
5602:
5603: LastName - column that the last name starts in
5604: LastNameLength - number of columns that the last name spans
1.649 raeburn 5605: BubblesPerRow - number of bubbles available in each row used to
5606: bubble an answer. (If not specified, 10 assumed).
1.671 raeburn 5607:
1.423 albertel 5608: =cut
1.422 foxr 5609:
1.82 albertel 5610: sub get_scantron_config {
5611: my ($which) = @_;
1.518 raeburn 5612: my @lines = &get_scantronformat_file();
1.82 albertel 5613: my %config;
1.157 albertel 5614: #FIXME probably should move to XML it has already gotten a bit much now
1.518 raeburn 5615: foreach my $line (@lines) {
1.82 albertel 5616: my ($name,$descrip)=split(/:/,$line);
5617: if ($name ne $which ) { next; }
5618: chomp($line);
5619: my @config=split(/:/,$line);
5620: $config{'name'}=$config[0];
5621: $config{'description'}=$config[1];
5622: $config{'CODElocation'}=$config[2];
5623: $config{'CODEstart'}=$config[3];
5624: $config{'CODElength'}=$config[4];
5625: $config{'IDstart'}=$config[5];
5626: $config{'IDlength'}=$config[6];
5627: $config{'Qstart'}=$config[7];
1.497 foxr 5628: $config{'Qlength'}=$config[8];
1.82 albertel 5629: $config{'Qoff'}=$config[9];
5630: $config{'Qon'}=$config[10];
1.157 albertel 5631: $config{'PaperID'}=$config[11];
5632: $config{'PaperIDlength'}=$config[12];
5633: $config{'FirstName'}=$config[13];
5634: $config{'FirstNamelength'}=$config[14];
5635: $config{'LastName'}=$config[15];
5636: $config{'LastNamelength'}=$config[16];
1.649 raeburn 5637: $config{'BubblesPerRow'}=$config[17];
1.82 albertel 5638: last;
5639: }
5640: return %config;
5641: }
5642:
1.423 albertel 5643: =pod
5644:
5645: =item username_to_idmap
5646:
1.556 weissno 5647: creates a hash keyed by student/employee ID with values of the corresponding
1.423 albertel 5648: student username:domain.
5649:
5650: Arguments:
5651:
5652: $classlist - reference to the class list hash. This is a hash
5653: keyed by student name:domain whose elements are references
1.424 albertel 5654: to arrays containing various chunks of information
1.423 albertel 5655: about the student. (See loncoursedata for more info).
5656:
5657: Returns
5658: %idmap - the constructed hash
5659:
5660: =cut
5661:
1.82 albertel 5662: sub username_to_idmap {
5663: my ($classlist)= @_;
5664: my %idmap;
5665: foreach my $student (keys(%$classlist)) {
5666: $idmap{$classlist->{$student}->[&Apache::loncoursedata::CL_ID]}=
5667: $student;
5668: }
5669: return %idmap;
5670: }
1.423 albertel 5671:
5672: =pod
5673:
1.424 albertel 5674: =item scantron_fixup_scanline
1.423 albertel 5675:
5676: Process a requested correction to a scanline.
5677:
5678: Arguments:
5679: $scantron_config - hash from &get_scantron_config()
5680: $scan_data - hash of correction information
5681: (see &scantron_getfile())
5682: $line - existing scanline
5683: $whichline - line number of the passed in scanline
5684: $field - type of change to process
5685: (either
1.573 bisitz 5686: 'ID' -> correct the student/employee ID
1.423 albertel 5687: 'CODE' -> correct the CODE
5688: 'answer' -> fixup the submitted answers)
5689:
5690: $args - hash of additional info,
5691: - 'ID'
5692: 'newid' -> studentID to use in replacement
1.424 albertel 5693: of existing one
1.423 albertel 5694: - 'CODE'
5695: 'CODE_ignore_dup' - set to true if duplicates
5696: should be ignored.
5697: 'CODE' - is new code or 'use_unfound'
1.424 albertel 5698: if the existing unfound code should
1.423 albertel 5699: be used as is
5700: - 'answer'
5701: 'response' - new answer or 'none' if blank
5702: 'question' - the bubble line to change
1.503 raeburn 5703: 'questionnum' - the question identifier,
5704: may include subquestion.
1.423 albertel 5705:
5706: Returns:
5707: $line - the modified scanline
5708:
5709: Side effects:
5710: $scan_data - may be updated
5711:
5712: =cut
5713:
1.82 albertel 5714:
1.157 albertel 5715: sub scantron_fixup_scanline {
5716: my ($scantron_config,$scan_data,$line,$whichline,$field,$args)=@_;
5717: if ($field eq 'ID') {
5718: if (length($args->{'newid'}) > $$scantron_config{'IDlength'}) {
1.186 albertel 5719: return ($line,1,'New value too large');
1.157 albertel 5720: }
5721: if (length($args->{'newid'}) < $$scantron_config{'IDlength'}) {
5722: $args->{'newid'}=sprintf('%-'.$$scantron_config{'IDlength'}.'s',
5723: $args->{'newid'});
5724: }
5725: substr($line,$$scantron_config{'IDstart'}-1,
5726: $$scantron_config{'IDlength'})=$args->{'newid'};
5727: if ($args->{'newid'}=~/^\s*$/) {
5728: &scan_data($scan_data,"$whichline.user",
5729: $args->{'username'}.':'.$args->{'domain'});
5730: }
1.186 albertel 5731: } elsif ($field eq 'CODE') {
1.192 albertel 5732: if ($args->{'CODE_ignore_dup'}) {
5733: &scan_data($scan_data,"$whichline.CODE_ignore_dup",'1');
5734: }
5735: &scan_data($scan_data,"$whichline.useCODE",'1');
5736: if ($args->{'CODE'} ne 'use_unfound') {
1.191 albertel 5737: if (length($args->{'CODE'}) > $$scantron_config{'CODElength'}) {
5738: return ($line,1,'New CODE value too large');
5739: }
5740: if (length($args->{'CODE'}) < $$scantron_config{'CODElength'}) {
5741: $args->{'CODE'}=sprintf('%-'.$$scantron_config{'CODElength'}.'s',$args->{'CODE'});
5742: }
5743: substr($line,$$scantron_config{'CODEstart'}-1,
5744: $$scantron_config{'CODElength'})=$args->{'CODE'};
1.186 albertel 5745: }
1.157 albertel 5746: } elsif ($field eq 'answer') {
1.497 foxr 5747: my $length=$scantron_config->{'Qlength'};
1.157 albertel 5748: my $off=$scantron_config->{'Qoff'};
5749: my $on=$scantron_config->{'Qon'};
1.497 foxr 5750: my $answer=${off}x$length;
5751: if ($args->{'response'} eq 'none') {
5752: &scan_data($scan_data,
1.503 raeburn 5753: "$whichline.no_bubble.".$args->{'questionnum'},'1');
1.497 foxr 5754: } else {
5755: if ($on eq 'letter') {
5756: my @alphabet=('A'..'Z');
5757: $answer=$alphabet[$args->{'response'}];
5758: } elsif ($on eq 'number') {
5759: $answer=$args->{'response'}+1;
5760: if ($answer == 10) { $answer = '0'; }
1.274 albertel 5761: } else {
1.497 foxr 5762: substr($answer,$args->{'response'},1)=$on;
1.274 albertel 5763: }
1.497 foxr 5764: &scan_data($scan_data,
1.503 raeburn 5765: "$whichline.no_bubble.".$args->{'questionnum'},undef,'1');
1.157 albertel 5766: }
1.497 foxr 5767: my $where=$length*($args->{'question'}-1)+$scantron_config->{'Qstart'};
5768: substr($line,$where-1,$length)=$answer;
1.157 albertel 5769: }
5770: return $line;
5771: }
1.423 albertel 5772:
5773: =pod
5774:
5775: =item scan_data
5776:
5777: Edit or look up an item in the scan_data hash.
5778:
5779: Arguments:
5780: $scan_data - The hash (see scantron_getfile)
5781: $key - shorthand of the key to edit (actual key is
1.424 albertel 5782: scantronfilename_key).
1.423 albertel 5783: $data - New value of the hash entry.
5784: $delete - If true, the entry is removed from the hash.
5785:
5786: Returns:
5787: The new value of the hash table field (undefined if deleted).
5788:
5789: =cut
5790:
5791:
1.157 albertel 5792: sub scan_data {
5793: my ($scan_data,$key,$value,$delete)=@_;
1.257 albertel 5794: my $filename=$env{'form.scantron_selectfile'};
1.157 albertel 5795: if (defined($value)) {
5796: $scan_data->{$filename.'_'.$key} = $value;
5797: }
5798: if ($delete) { delete($scan_data->{$filename.'_'.$key}); }
5799: return $scan_data->{$filename.'_'.$key};
5800: }
1.423 albertel 5801:
1.495 albertel 5802: # ----- These first few routines are general use routines.----
5803:
5804: # Return the number of occurences of a pattern in a string.
5805:
5806: sub occurence_count {
5807: my ($string, $pattern) = @_;
5808:
5809: my @matches = ($string =~ /$pattern/g);
5810:
5811: return scalar(@matches);
5812: }
5813:
5814:
5815: # Take a string known to have digits and convert all the
5816: # digits into letters in the range J,A..I.
5817:
5818: sub digits_to_letters {
5819: my ($input) = @_;
5820:
5821: my @alphabet = ('J', 'A'..'I');
5822:
5823: my @input = split(//, $input);
5824: my $output ='';
5825: for (my $i = 0; $i < scalar(@input); $i++) {
5826: if ($input[$i] =~ /\d/) {
5827: $output .= $alphabet[$input[$i]];
5828: } else {
5829: $output .= $input[$i];
5830: }
5831: }
5832: return $output;
5833: }
5834:
1.423 albertel 5835: =pod
5836:
5837: =item scantron_parse_scanline
5838:
5839: Decodes a scanline from the selected scantron file
5840:
5841: Arguments:
5842: line - The text of the scantron file line to process
5843: whichline - Line number
5844: scantron_config - Hash describing the format of the scantron lines.
5845: scan_data - Hash of extra information about the scanline
5846: (see scantron_getfile for more information)
5847: just_header - True if should not process question answers but only
5848: the stuff to the left of the answers.
1.691 raeburn 5849: randomorder - True if randomorder in use
5850: randompick - True if randompick in use
5851: sequence - Exam folder URL
5852: master_seq - Ref to array containing symbs in exam folder
5853: symb_to_resource - Ref to hash of symbs for resources in exam folder
5854: (corresponding values are resource objects)
5855: partids_by_symb - Ref to hash of symb -> array ref of partIDs
5856: orderedforcode - Ref to hash of arrays. keys are CODEs and values
5857: are refs to an array of resource objects, ordered
5858: according to order used for CODE, when randomorder
5859: and or randompick are in use.
5860: respnumlookup - Ref to hash mapping question numbers in bubble lines
5861: for current line to question number used for same question
5862: in "Master Sequence" (as seen by Course Coordinator).
5863: startline - Ref to hash where key is question number (0 is first)
5864: and value is number of first bubble line for current
5865: student or code-based randompick and/or randomorder.
5866: totalref - Ref of scalar used to score total number of bubble
5867: lines needed for responses in a scan line (used when
5868: randompick in use.
5869:
1.423 albertel 5870: Returns:
5871: Hash containing the result of parsing the scanline
5872:
5873: Keys are all proceeded by the string 'scantron.'
5874:
5875: CODE - the CODE in use for this scanline
5876: useCODE - 1 if the CODE is invalid but it usage has been forced
5877: by the operator
5878: CODE_ignore_dup - 1 if the CODE is a duplicated use when unique
5879: CODEs were selected, but the usage has been
5880: forced by the operator
1.556 weissno 5881: ID - student/employee ID
1.423 albertel 5882: PaperID - if used, the ID number printed on the sheet when the
5883: paper was scanned
5884: FirstName - first name from the sheet
5885: LastName - last name from the sheet
5886:
5887: if just_header was not true these key may also exist
5888:
1.447 foxr 5889: missingerror - a list of bubble ranges that are considered to be answers
5890: to a single question that don't have any bubbles filled in.
5891: Of the form questionnumber:firstbubblenumber:count.
5892: doubleerror - a list of bubble ranges that are considered to be answers
5893: to a single question that have more than one bubble filled in.
5894: Of the form questionnumber::firstbubblenumber:count
5895:
5896: In the above, count is the number of bubble responses in the
5897: input line needed to represent the possible answers to the question.
5898: e.g. a radioresponse with 15 choices in an answer sheet with 10 choices
5899: per line would have count = 2.
5900:
1.423 albertel 5901: maxquest - the number of the last bubble line that was parsed
5902:
5903: (<number> starts at 1)
5904: <number>.answer - zero or more letters representing the selected
5905: letters from the scanline for the bubble line
5906: <number>.
5907: if blank there was either no bubble or there where
5908: multiple bubbles, (consult the keys missingerror and
5909: doubleerror if this is an error condition)
5910:
5911: =cut
5912:
1.82 albertel 5913: sub scantron_parse_scanline {
1.691 raeburn 5914: my ($line,$whichline,$scantron_config,$scan_data,$just_header,$idmap,
5915: $randomorder,$randompick,$sequence,$master_seq,$symb_to_resource,
5916: $partids_by_symb,$orderedforcode,$respnumlookup,$startline,$totalref)=@_;
1.470 foxr 5917:
1.82 albertel 5918: my %record;
1.691 raeburn 5919: my $data=substr($line,0,$$scantron_config{'Qstart'}-1); # stuff before answers
1.278 albertel 5920: if (!($$scantron_config{'CODElocation'} eq 0 ||
5921: $$scantron_config{'CODElocation'} eq 'none')) {
5922: if ($$scantron_config{'CODElocation'} < 0 ||
5923: $$scantron_config{'CODElocation'} eq 'letter' ||
5924: $$scantron_config{'CODElocation'} eq 'number') {
1.191 albertel 5925: $record{'scantron.CODE'}=substr($data,
5926: $$scantron_config{'CODEstart'}-1,
1.83 albertel 5927: $$scantron_config{'CODElength'});
1.191 albertel 5928: if (&scan_data($scan_data,"$whichline.useCODE")) {
5929: $record{'scantron.useCODE'}=1;
5930: }
1.192 albertel 5931: if (&scan_data($scan_data,"$whichline.CODE_ignore_dup")) {
5932: $record{'scantron.CODE_ignore_dup'}=1;
5933: }
1.82 albertel 5934: } else {
5935: #FIXME interpret first N questions
5936: }
5937: }
1.83 albertel 5938: $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
5939: $$scantron_config{'IDlength'});
1.157 albertel 5940: $record{'scantron.PaperID'}=
5941: substr($data,$$scantron_config{'PaperID'}-1,
5942: $$scantron_config{'PaperIDlength'});
5943: $record{'scantron.FirstName'}=
5944: substr($data,$$scantron_config{'FirstName'}-1,
5945: $$scantron_config{'FirstNamelength'});
5946: $record{'scantron.LastName'}=
5947: substr($data,$$scantron_config{'LastName'}-1,
5948: $$scantron_config{'LastNamelength'});
1.423 albertel 5949: if ($just_header) { return \%record; }
1.194 albertel 5950:
1.82 albertel 5951: my @alphabet=('A'..'Z');
5952: my $questnum=0;
1.447 foxr 5953: my $ansnum =1; # Multiple 'answer lines'/question.
5954:
1.691 raeburn 5955: my $lastpos = $env{'form.scantron_maxbubble'}*$$scantron_config{'Qlength'};
5956: if ($randompick || $randomorder) {
5957: my $total = &get_respnum_lookups($sequence,$scan_data,$idmap,$line,\%record,
5958: $master_seq,$symb_to_resource,
5959: $partids_by_symb,$orderedforcode,
5960: $respnumlookup,$startline);
5961: if ($total) {
5962: $lastpos = $total*$$scantron_config{'Qlength'};
5963: }
5964: if (ref($totalref)) {
5965: $$totalref = $total;
5966: }
5967: }
5968: my $questions=substr($line,$$scantron_config{'Qstart'}-1,$lastpos); # Answers
1.470 foxr 5969: chomp($questions); # Get rid of any trailing \n.
5970: $questions =~ s/\r$//; # Get rid of trailing \r too (MAC or Win uploads).
5971: while (length($questions)) {
1.691 raeburn 5972: my $answers_needed;
5973: if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
5974: $answers_needed = $bubble_lines_per_response{$respnumlookup->{$questnum}};
5975: } else {
5976: $answers_needed = $bubble_lines_per_response{$questnum};
5977: }
1.503 raeburn 5978: my $answer_length = ($$scantron_config{'Qlength'} * $answers_needed)
5979: || 1;
5980: $questnum++;
5981: my $quest_id = $questnum;
5982: my $currentquest = substr($questions,0,$answer_length);
5983: $questions = substr($questions,$answer_length);
5984: if (length($currentquest) < $answer_length) { next; }
5985:
1.691 raeburn 5986: my $subdivided;
5987: if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
5988: $subdivided = $subdivided_bubble_lines{$respnumlookup->{$questnum-1}};
5989: } else {
5990: $subdivided = $subdivided_bubble_lines{$questnum-1};
5991: }
5992: if ($subdivided =~ /,/) {
1.503 raeburn 5993: my $subquestnum = 1;
5994: my $subquestions = $currentquest;
1.691 raeburn 5995: my @subanswers_needed = split(/,/,$subdivided);
1.503 raeburn 5996: foreach my $subans (@subanswers_needed) {
5997: my $subans_length =
5998: ($$scantron_config{'Qlength'} * $subans) || 1;
5999: my $currsubquest = substr($subquestions,0,$subans_length);
6000: $subquestions = substr($subquestions,$subans_length);
6001: $quest_id = "$questnum.$subquestnum";
6002: if (($$scantron_config{'Qon'} eq 'letter') ||
6003: ($$scantron_config{'Qon'} eq 'number')) {
6004: $ansnum = &scantron_validator_lettnum($ansnum,
6005: $questnum,$quest_id,$subans,$currsubquest,$whichline,
1.691 raeburn 6006: \@alphabet,\%record,$scantron_config,$scan_data,
6007: $randomorder,$randompick,$respnumlookup);
1.503 raeburn 6008: } else {
6009: $ansnum = &scantron_validator_positional($ansnum,
1.691 raeburn 6010: $questnum,$quest_id,$subans,$currsubquest,$whichline,
6011: \@alphabet,\%record,$scantron_config,$scan_data,
6012: $randomorder,$randompick,$respnumlookup);
1.503 raeburn 6013: }
6014: $subquestnum ++;
6015: }
6016: } else {
6017: if (($$scantron_config{'Qon'} eq 'letter') ||
6018: ($$scantron_config{'Qon'} eq 'number')) {
6019: $ansnum = &scantron_validator_lettnum($ansnum,$questnum,
6020: $quest_id,$answers_needed,$currentquest,$whichline,
1.691 raeburn 6021: \@alphabet,\%record,$scantron_config,$scan_data,
6022: $randomorder,$randompick,$respnumlookup);
1.503 raeburn 6023: } else {
6024: $ansnum = &scantron_validator_positional($ansnum,$questnum,
6025: $quest_id,$answers_needed,$currentquest,$whichline,
1.691 raeburn 6026: \@alphabet,\%record,$scantron_config,$scan_data,
6027: $randomorder,$randompick,$respnumlookup);
1.503 raeburn 6028: }
6029: }
6030: }
6031: $record{'scantron.maxquest'}=$questnum;
6032: return \%record;
6033: }
1.447 foxr 6034:
1.691 raeburn 6035: sub get_master_seq {
6036: my ($resources,$master_seq,$symb_to_resource) = @_;
6037: return unless ((ref($resources) eq 'ARRAY') && (ref($master_seq) eq 'ARRAY') &&
6038: (ref($symb_to_resource) eq 'HASH'));
6039: my $resource_error;
6040: foreach my $resource (@{$resources}) {
6041: my $ressymb;
6042: if (ref($resource)) {
6043: $ressymb = $resource->symb();
6044: push(@{$master_seq},$ressymb);
6045: $symb_to_resource->{$ressymb} = $resource;
6046: } else {
6047: $resource_error = 1;
6048: last;
6049: }
6050: }
6051: return $resource_error;
6052: }
6053:
6054: sub get_respnum_lookups {
6055: my ($sequence,$scan_data,$idmap,$line,$record,$master_seq,$symb_to_resource,
6056: $partids_by_symb,$orderedforcode,$respnumlookup,$startline) = @_;
6057: return unless ((ref($record) eq 'HASH') && (ref($master_seq) eq 'ARRAY') &&
6058: (ref($symb_to_resource) eq 'HASH') && (ref($partids_by_symb) eq 'HASH') &&
6059: (ref($orderedforcode) eq 'HASH') && (ref($respnumlookup) eq 'HASH') &&
6060: (ref($startline) eq 'HASH'));
6061: my ($user,$scancode);
6062: if ((exists($record->{'scantron.CODE'})) &&
6063: (&Apache::lonnet::validCODE($record->{'scantron.CODE'}))) {
6064: $scancode = $record->{'scantron.CODE'};
6065: } else {
6066: $user = &scantron_find_student($record,$scan_data,$idmap,$line);
6067: }
6068: my @mapresources =
6069: &users_order($user,$scancode,$sequence,$master_seq,$symb_to_resource,
6070: $orderedforcode);
6071: my $total = 0;
6072: my $count = 0;
6073: foreach my $resource (@mapresources) {
6074: my $id = $resource->id();
6075: my $symb = $resource->symb();
6076: if (ref($partids_by_symb->{$symb}) eq 'ARRAY') {
6077: foreach my $partid (@{$partids_by_symb->{$symb}}) {
6078: my $respnum = $masterseq_id_responsenum{$id.'_'.$partid};
6079: if ($respnum ne '') {
6080: $respnumlookup->{$count} = $respnum;
6081: $startline->{$count} = $total;
6082: $total += $bubble_lines_per_response{$respnum};
6083: $count ++;
6084: }
6085: }
6086: }
6087: }
6088: return $total;
6089: }
6090:
1.503 raeburn 6091: sub scantron_validator_lettnum {
6092: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,$whichline,
1.691 raeburn 6093: $alphabet,$record,$scantron_config,$scan_data,$randomorder,
6094: $randompick,$respnumlookup) = @_;
1.503 raeburn 6095:
6096: # Qon 'letter' implies for each slot in currquest we have:
6097: # ? or * for doubles, a letter in A-Z for a bubble, and
6098: # about anything else (esp. a value of Qoff) for missing
6099: # bubbles.
6100: #
6101: # Qon 'number' implies each slot gives a digit that indexes the
6102: # bubbles filled, or Qoff, or a non-number for unbubbled lines,
6103: # and * or ? for double bubbles on a single line.
6104: #
1.447 foxr 6105:
1.503 raeburn 6106: my $matchon;
6107: if ($$scantron_config{'Qon'} eq 'letter') {
6108: $matchon = '[A-Z]';
6109: } elsif ($$scantron_config{'Qon'} eq 'number') {
6110: $matchon = '\d';
6111: }
6112: my $occurrences = 0;
1.691 raeburn 6113: my $responsenum = $questnum-1;
6114: if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
6115: $responsenum = $respnumlookup->{$questnum-1}
6116: }
6117: if (($responsetype_per_response{$responsenum} eq 'essayresponse') ||
6118: ($responsetype_per_response{$responsenum} eq 'formularesponse') ||
6119: ($responsetype_per_response{$responsenum} eq 'stringresponse') ||
6120: ($responsetype_per_response{$responsenum} eq 'imageresponse') ||
6121: ($responsetype_per_response{$responsenum} eq 'reactionresponse') ||
6122: ($responsetype_per_response{$responsenum} eq 'organicresponse')) {
1.503 raeburn 6123: my @singlelines = split('',$currquest);
6124: foreach my $entry (@singlelines) {
6125: $occurrences = &occurence_count($entry,$matchon);
6126: if ($occurrences > 1) {
6127: last;
6128: }
1.691 raeburn 6129: }
1.503 raeburn 6130: } else {
6131: $occurrences = &occurence_count($currquest,$matchon);
6132: }
6133: if (($currquest =~ /\?/ || $currquest =~ /\*/) || ($occurrences > 1)) {
6134: push(@{$record->{'scantron.doubleerror'}},$quest_id);
6135: for (my $ans=0; $ans<$answers_needed; $ans++) {
6136: my $bubble = substr($currquest,$ans,1);
6137: if ($bubble =~ /$matchon/ ) {
6138: if ($$scantron_config{'Qon'} eq 'number') {
6139: if ($bubble == 0) {
6140: $bubble = 10;
6141: }
6142: $record->{"scantron.$ansnum.answer"} =
6143: $alphabet->[$bubble-1];
6144: } else {
6145: $record->{"scantron.$ansnum.answer"} = $bubble;
6146: }
6147: } else {
6148: $record->{"scantron.$ansnum.answer"}='';
6149: }
6150: $ansnum++;
6151: }
6152: } elsif (!defined($currquest)
6153: || (&occurence_count($currquest, $$scantron_config{'Qoff'}) == length($currquest))
6154: || (&occurence_count($currquest,$matchon) == 0)) {
6155: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
6156: $record->{"scantron.$ansnum.answer"}='';
6157: $ansnum++;
6158: }
6159: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
6160: push(@{$record->{'scantron.missingerror'}},$quest_id);
6161: }
6162: } else {
6163: if ($$scantron_config{'Qon'} eq 'number') {
6164: $currquest = &digits_to_letters($currquest);
6165: }
6166: for (my $ans=0; $ans<$answers_needed; $ans++) {
6167: my $bubble = substr($currquest,$ans,1);
6168: $record->{"scantron.$ansnum.answer"} = $bubble;
6169: $ansnum++;
6170: }
6171: }
6172: return $ansnum;
6173: }
1.447 foxr 6174:
1.503 raeburn 6175: sub scantron_validator_positional {
6176: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,
1.691 raeburn 6177: $whichline,$alphabet,$record,$scantron_config,$scan_data,
6178: $randomorder,$randompick,$respnumlookup) = @_;
1.447 foxr 6179:
1.503 raeburn 6180: # Otherwise there's a positional notation;
6181: # each bubble line requires Qlength items, and there are filled in
6182: # bubbles for each case where there 'Qon' characters.
6183: #
1.447 foxr 6184:
1.503 raeburn 6185: my @array=split($$scantron_config{'Qon'},$currquest,-1);
1.447 foxr 6186:
1.503 raeburn 6187: # If the split only gives us one element.. the full length of the
6188: # answer string, no bubbles are filled in:
1.447 foxr 6189:
1.507 raeburn 6190: if ($answers_needed eq '') {
6191: return;
6192: }
6193:
1.503 raeburn 6194: if (length($array[0]) eq $$scantron_config{'Qlength'}*$answers_needed) {
6195: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
6196: $record->{"scantron.$ansnum.answer"}='';
6197: $ansnum++;
6198: }
6199: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
6200: push(@{$record->{"scantron.missingerror"}},$quest_id);
6201: }
6202: } elsif (scalar(@array) == 2) {
6203: my $location = length($array[0]);
6204: my $line_num = int($location / $$scantron_config{'Qlength'});
6205: my $bubble = $alphabet->[$location % $$scantron_config{'Qlength'}];
6206: for (my $ans=0; $ans<$answers_needed; $ans++) {
6207: if ($ans eq $line_num) {
6208: $record->{"scantron.$ansnum.answer"} = $bubble;
6209: } else {
6210: $record->{"scantron.$ansnum.answer"} = ' ';
6211: }
6212: $ansnum++;
6213: }
6214: } else {
6215: # If there's more than one instance of a bubble character
6216: # That's a double bubble; with positional notation we can
6217: # record all the bubbles filled in as well as the
6218: # fact this response consists of multiple bubbles.
6219: #
1.691 raeburn 6220: my $responsenum = $questnum-1;
6221: if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
6222: $responsenum = $respnumlookup->{$questnum-1}
6223: }
6224: if (($responsetype_per_response{$responsenum} eq 'essayresponse') ||
6225: ($responsetype_per_response{$responsenum} eq 'formularesponse') ||
6226: ($responsetype_per_response{$responsenum} eq 'stringresponse') ||
6227: ($responsetype_per_response{$responsenum} eq 'imageresponse') ||
6228: ($responsetype_per_response{$responsenum} eq 'reactionresponse') ||
6229: ($responsetype_per_response{$responsenum} eq 'organicresponse')) {
1.503 raeburn 6230: my $doubleerror = 0;
6231: while (($currquest >= $$scantron_config{'Qlength'}) &&
6232: (!$doubleerror)) {
6233: my $currline = substr($currquest,0,$$scantron_config{'Qlength'});
6234: $currquest = substr($currquest,$$scantron_config{'Qlength'});
6235: my @currarray = split($$scantron_config{'Qon'},$currline,-1);
6236: if (length(@currarray) > 2) {
6237: $doubleerror = 1;
6238: }
6239: }
6240: if ($doubleerror) {
6241: push(@{$record->{'scantron.doubleerror'}},$quest_id);
6242: }
6243: } else {
6244: push(@{$record->{'scantron.doubleerror'}},$quest_id);
6245: }
6246: my $item = $ansnum;
6247: for (my $ans=0; $ans<$answers_needed; $ans++) {
6248: $record->{"scantron.$item.answer"} = '';
6249: $item ++;
6250: }
1.447 foxr 6251:
1.503 raeburn 6252: my @ans=@array;
6253: my $i=0;
6254: my $increment = 0;
6255: while ($#ans) {
6256: $i+=length($ans[0]) + $increment;
6257: my $line = int($i/$$scantron_config{'Qlength'} + $ansnum);
6258: my $bubble = $i%$$scantron_config{'Qlength'};
6259: $record->{"scantron.$line.answer"}.=$alphabet->[$bubble];
6260: shift(@ans);
6261: $increment = 1;
6262: }
6263: $ansnum += $answers_needed;
1.82 albertel 6264: }
1.503 raeburn 6265: return $ansnum;
1.82 albertel 6266: }
6267:
1.423 albertel 6268: =pod
6269:
6270: =item scantron_add_delay
6271:
6272: Adds an error message that occurred during the grading phase to a
6273: queue of messages to be shown after grading pass is complete
6274:
6275: Arguments:
1.424 albertel 6276: $delayqueue - arrary ref of hash ref of error messages
1.423 albertel 6277: $scanline - the scanline that caused the error
6278: $errormesage - the error message
6279: $errorcode - a numeric code for the error
6280:
6281: Side Effects:
1.424 albertel 6282: updates the $delayqueue to have a new hash ref of the error
1.423 albertel 6283:
6284: =cut
6285:
1.82 albertel 6286: sub scantron_add_delay {
1.140 albertel 6287: my ($delayqueue,$scanline,$errormessage,$errorcode)=@_;
6288: push(@$delayqueue,
6289: {'line' => $scanline, 'emsg' => $errormessage,
6290: 'ecode' => $errorcode }
6291: );
1.82 albertel 6292: }
6293:
1.423 albertel 6294: =pod
6295:
6296: =item scantron_find_student
6297:
1.424 albertel 6298: Finds the username for the current scanline
6299:
6300: Arguments:
6301: $scantron_record - hash result from scantron_parse_scanline
6302: $scan_data - hash of correction information
6303: (see &scantron_getfile() form more information)
6304: $idmap - hash from &username_to_idmap()
6305: $line - number of current scanline
6306:
6307: Returns:
6308: Either 'username:domain' or undef if unknown
6309:
1.423 albertel 6310: =cut
6311:
1.82 albertel 6312: sub scantron_find_student {
1.157 albertel 6313: my ($scantron_record,$scan_data,$idmap,$line)=@_;
1.83 albertel 6314: my $scanID=$$scantron_record{'scantron.ID'};
1.157 albertel 6315: if ($scanID =~ /^\s*$/) {
6316: return &scan_data($scan_data,"$line.user");
6317: }
1.83 albertel 6318: foreach my $id (keys(%$idmap)) {
1.157 albertel 6319: if (lc($id) eq lc($scanID)) {
6320: return $$idmap{$id};
6321: }
1.83 albertel 6322: }
6323: return undef;
6324: }
6325:
1.423 albertel 6326: =pod
6327:
6328: =item scantron_filter
6329:
1.424 albertel 6330: Filter sub for lonnavmaps, filters out hidden resources if ignore
6331: hidden resources was selected
6332:
1.423 albertel 6333: =cut
6334:
1.83 albertel 6335: sub scantron_filter {
6336: my ($curres)=@_;
1.331 albertel 6337:
6338: if (ref($curres) && $curres->is_problem()) {
6339: # if the user has asked to not have either hidden
6340: # or 'randomout' controlled resources to be graded
6341: # don't include them
6342: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
6343: && $curres->randomout) {
6344: return 0;
6345: }
1.83 albertel 6346: return 1;
6347: }
6348: return 0;
1.82 albertel 6349: }
6350:
1.423 albertel 6351: =pod
6352:
6353: =item scantron_process_corrections
6354:
1.424 albertel 6355: Gets correction information out of submitted form data and corrects
6356: the scanline
6357:
1.423 albertel 6358: =cut
6359:
1.157 albertel 6360: sub scantron_process_corrections {
6361: my ($r) = @_;
1.257 albertel 6362: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 6363: my ($scanlines,$scan_data)=&scantron_getfile();
6364: my $classlist=&Apache::loncoursedata::get_classlist();
1.257 albertel 6365: my $which=$env{'form.scantron_line'};
1.200 albertel 6366: my $line=&scantron_get_line($scanlines,$scan_data,$which);
1.157 albertel 6367: my ($skip,$err,$errmsg);
1.257 albertel 6368: if ($env{'form.scantron_skip_record'}) {
1.157 albertel 6369: $skip=1;
1.257 albertel 6370: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)ID$/) {
6371: my $newstudent=$env{'form.scantron_username'}.':'.
6372: $env{'form.scantron_domain'};
1.157 albertel 6373: my $newid=$classlist->{$newstudent}->[&Apache::loncoursedata::CL_ID];
6374: ($line,$err,$errmsg)=
6375: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
6376: 'ID',{'newid'=>$newid,
1.257 albertel 6377: 'username'=>$env{'form.scantron_username'},
6378: 'domain'=>$env{'form.scantron_domain'}});
6379: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)CODE$/) {
6380: my $resolution=$env{'form.scantron_CODE_resolution'};
1.190 albertel 6381: my $newCODE;
1.192 albertel 6382: my %args;
1.190 albertel 6383: if ($resolution eq 'use_unfound') {
1.191 albertel 6384: $newCODE='use_unfound';
1.190 albertel 6385: } elsif ($resolution eq 'use_found') {
1.257 albertel 6386: $newCODE=$env{'form.scantron_CODE_selectedvalue'};
1.190 albertel 6387: } elsif ($resolution eq 'use_typed') {
1.257 albertel 6388: $newCODE=$env{'form.scantron_CODE_newvalue'};
1.194 albertel 6389: } elsif ($resolution =~ /^use_closest_(\d+)/) {
1.257 albertel 6390: $newCODE=$env{"form.scantron_CODE_closest_$1"};
1.190 albertel 6391: }
1.257 albertel 6392: if ($env{'form.scantron_corrections'} eq 'duplicateCODE') {
1.192 albertel 6393: $args{'CODE_ignore_dup'}=1;
6394: }
6395: $args{'CODE'}=$newCODE;
1.186 albertel 6396: ($line,$err,$errmsg)=
6397: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
1.192 albertel 6398: 'CODE',\%args);
1.257 albertel 6399: } elsif ($env{'form.scantron_corrections'} =~ /^(missing|double)bubble$/) {
6400: foreach my $question (split(',',$env{'form.scantron_questions'})) {
1.157 albertel 6401: ($line,$err,$errmsg)=
6402: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,
6403: $which,'answer',
6404: { 'question'=>$question,
1.503 raeburn 6405: 'response'=>$env{"form.scantron_correct_Q_$question"},
6406: 'questionnum'=>$env{"form.scantron_questionnum_Q_$question"}});
1.157 albertel 6407: if ($err) { last; }
6408: }
6409: }
6410: if ($err) {
1.398 albertel 6411: $r->print("<span class=\"LC_warning\">Unable to accept last correction, an error occurred :$errmsg:</span>");
1.157 albertel 6412: } else {
1.200 albertel 6413: &scantron_put_line($scanlines,$scan_data,$which,$line,$skip);
1.157 albertel 6414: &scantron_putfile($scanlines,$scan_data);
6415: }
6416: }
6417:
1.423 albertel 6418: =pod
6419:
6420: =item reset_skipping_status
6421:
1.424 albertel 6422: Forgets the current set of remember skipped scanlines (and thus
6423: reverts back to considering all lines in the
6424: scantron_skipped_<filename> file)
6425:
1.423 albertel 6426: =cut
6427:
1.200 albertel 6428: sub reset_skipping_status {
6429: my ($scanlines,$scan_data)=&scantron_getfile();
6430: &scan_data($scan_data,'remember_skipping',undef,1);
6431: &scantron_putfile(undef,$scan_data);
6432: }
6433:
1.423 albertel 6434: =pod
6435:
6436: =item start_skipping
6437:
1.424 albertel 6438: Marks a scanline to be skipped.
6439:
1.423 albertel 6440: =cut
6441:
1.376 albertel 6442: sub start_skipping {
1.200 albertel 6443: my ($scan_data,$i)=@_;
6444: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 6445: if ($env{'form.scantron_options_redo'} =~ /^redo_/) {
6446: $remembered{$i}=2;
6447: } else {
6448: $remembered{$i}=1;
6449: }
1.200 albertel 6450: &scan_data($scan_data,'remember_skipping',join(':',%remembered));
6451: }
6452:
1.423 albertel 6453: =pod
6454:
6455: =item should_be_skipped
6456:
1.424 albertel 6457: Checks whether a scanline should be skipped.
6458:
1.423 albertel 6459: =cut
6460:
1.200 albertel 6461: sub should_be_skipped {
1.376 albertel 6462: my ($scanlines,$scan_data,$i)=@_;
1.257 albertel 6463: if ($env{'form.scantron_options_redo'} !~ /^redo_/) {
1.200 albertel 6464: # not redoing old skips
1.376 albertel 6465: if ($scanlines->{'skipped'}[$i]) { return 1; }
1.200 albertel 6466: return 0;
6467: }
6468: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 6469:
6470: if (exists($remembered{$i}) && $remembered{$i} != 2 ) {
6471: return 0;
6472: }
1.200 albertel 6473: return 1;
6474: }
6475:
1.423 albertel 6476: =pod
6477:
6478: =item remember_current_skipped
6479:
1.424 albertel 6480: Discovers what scanlines are in the scantron_skipped_<filename>
6481: file and remembers them into scan_data for later use.
6482:
1.423 albertel 6483: =cut
6484:
1.200 albertel 6485: sub remember_current_skipped {
6486: my ($scanlines,$scan_data)=&scantron_getfile();
6487: my %to_remember;
6488: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
6489: if ($scanlines->{'skipped'}[$i]) {
6490: $to_remember{$i}=1;
6491: }
6492: }
1.376 albertel 6493:
1.200 albertel 6494: &scan_data($scan_data,'remember_skipping',join(':',%to_remember));
6495: &scantron_putfile(undef,$scan_data);
6496: }
6497:
1.423 albertel 6498: =pod
6499:
6500: =item check_for_error
6501:
1.424 albertel 6502: Checks if there was an error when attempting to remove a specific
1.659 raeburn 6503: scantron_.. bubblesheet data file. Prints out an error if
1.424 albertel 6504: something went wrong.
6505:
1.423 albertel 6506: =cut
6507:
1.200 albertel 6508: sub check_for_error {
6509: my ($r,$result)=@_;
6510: if ($result ne 'ok' && $result ne 'not_found' ) {
1.492 albertel 6511: $r->print(&mt("An error occurred ([_1]) when trying to remove the existing corrections.",$result));
1.200 albertel 6512: }
6513: }
1.157 albertel 6514:
1.423 albertel 6515: =pod
6516:
6517: =item scantron_warning_screen
6518:
1.424 albertel 6519: Interstitial screen to make sure the operator has selected the
6520: correct options before we start the validation phase.
6521:
1.423 albertel 6522: =cut
6523:
1.203 albertel 6524: sub scantron_warning_screen {
1.650 raeburn 6525: my ($button_text,$symb)=@_;
1.257 albertel 6526: my $title=&Apache::lonnet::gettitle($env{'form.selectpage'});
1.284 albertel 6527: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.373 albertel 6528: my $CODElist;
1.284 albertel 6529: if ($scantron_config{'CODElocation'} &&
6530: $scantron_config{'CODEstart'} &&
6531: $scantron_config{'CODElength'}) {
6532: $CODElist=$env{'form.scantron_CODElist'};
1.398 albertel 6533: if ($env{'form.scantron_CODElist'} eq '') { $CODElist='<span class="LC_warning">None</span>'; }
1.284 albertel 6534: $CODElist=
1.492 albertel 6535: '<tr><td><b>'.&mt('List of CODES to validate against:').'</b></td><td><tt>'.
1.373 albertel 6536: $env{'form.scantron_CODElist'}.'</tt></td></tr>';
1.284 albertel 6537: }
1.663 raeburn 6538: my $lastbubblepoints;
6539: if ($env{'form.scantron_lastbubblepoints'} ne '') {
6540: $lastbubblepoints =
6541: '<tr><td><b>'.&mt('Hand-graded items: points from last bubble in row').'</b></td><td><tt>'.
6542: $env{'form.scantron_lastbubblepoints'}.'</tt></td></tr>';
6543: }
1.492 albertel 6544: return ('
1.203 albertel 6545: <p>
1.492 albertel 6546: <span class="LC_warning">
6547: '.&mt('Please double check the information below before clicking on \'[_1]\'',&mt($button_text)).'</span>
1.203 albertel 6548: </p>
6549: <table>
1.492 albertel 6550: <tr><td><b>'.&mt('Sequence to be Graded:').'</b></td><td>'.$title.'</td></tr>
6551: <tr><td><b>'.&mt('Data File that will be used:').'</b></td><td><tt>'.$env{'form.scantron_selectfile'}.'</tt></td></tr>
1.663 raeburn 6552: '.$CODElist.$lastbubblepoints.'
1.203 albertel 6553: </table>
1.680 raeburn 6554: <p> '.&mt("If this information is correct, please click on '[_1]'.",&mt($button_text)).'<br />
1.650 raeburn 6555: '.&mt('If something is incorrect, please return to [_1]Grade/Manage/Review Bubblesheets[_2] to start over.','<a href="/adm/grades?symb='.$symb.'&command=scantron_selectphase" class="LC_info">','</a>').'</p>
1.203 albertel 6556:
6557: <br />
1.492 albertel 6558: ');
1.203 albertel 6559: }
6560:
1.423 albertel 6561: =pod
6562:
6563: =item scantron_do_warning
6564:
1.424 albertel 6565: Check if the operator has picked something for all required
6566: fields. Error out if something is missing.
6567:
1.423 albertel 6568: =cut
6569:
1.203 albertel 6570: sub scantron_do_warning {
1.608 www 6571: my ($r,$symb)=@_;
1.203 albertel 6572: if (!$symb) {return '';}
1.324 albertel 6573: my $default_form_data=&defaultFormData($symb);
1.203 albertel 6574: $r->print(&scantron_form_start().$default_form_data);
1.257 albertel 6575: if ( $env{'form.selectpage'} eq '' ||
6576: $env{'form.scantron_selectfile'} eq '' ||
6577: $env{'form.scantron_format'} eq '' ) {
1.642 raeburn 6578: $r->print("<p>".&mt('You have forgotten to specify some information. Please go Back and try again.')."</p>");
1.257 albertel 6579: if ( $env{'form.selectpage'} eq '') {
1.492 albertel 6580: $r->print('<p><span class="LC_error">'.&mt('You have not selected a Sequence to grade').'</span></p>');
1.237 albertel 6581: }
1.257 albertel 6582: if ( $env{'form.scantron_selectfile'} eq '') {
1.642 raeburn 6583: $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 6584: }
1.257 albertel 6585: if ( $env{'form.scantron_format'} eq '') {
1.642 raeburn 6586: $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 6587: }
6588: } else {
1.650 raeburn 6589: my $warning=&scantron_warning_screen('Grading: Validate Records',$symb);
1.663 raeburn 6590: my $bubbledbyhand=&hand_bubble_option();
1.492 albertel 6591: $r->print('
1.663 raeburn 6592: '.$warning.$bubbledbyhand.'
1.492 albertel 6593: <input type="submit" name="submit" value="'.&mt('Grading: Validate Records').'" />
1.203 albertel 6594: <input type="hidden" name="command" value="scantron_validate" />
1.492 albertel 6595: ');
1.237 albertel 6596: }
1.614 www 6597: $r->print("</form><br />");
1.203 albertel 6598: return '';
6599: }
6600:
1.423 albertel 6601: =pod
6602:
6603: =item scantron_form_start
6604:
1.424 albertel 6605: html hidden input for remembering all selected grading options
6606:
1.423 albertel 6607: =cut
6608:
1.203 albertel 6609: sub scantron_form_start {
6610: my ($max_bubble)=@_;
6611: my $result= <<SCANTRONFORM;
6612: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
1.257 albertel 6613: <input type="hidden" name="selectpage" value="$env{'form.selectpage'}" />
6614: <input type="hidden" name="scantron_format" value="$env{'form.scantron_format'}" />
6615: <input type="hidden" name="scantron_selectfile" value="$env{'form.scantron_selectfile'}" />
1.218 albertel 6616: <input type="hidden" name="scantron_maxbubble" value="$max_bubble" />
1.257 albertel 6617: <input type="hidden" name="scantron_CODElist" value="$env{'form.scantron_CODElist'}" />
6618: <input type="hidden" name="scantron_CODEunique" value="$env{'form.scantron_CODEunique'}" />
6619: <input type="hidden" name="scantron_options_redo" value="$env{'form.scantron_options_redo'}" />
6620: <input type="hidden" name="scantron_options_ignore" value="$env{'form.scantron_options_ignore'}" />
1.331 albertel 6621: <input type="hidden" name="scantron_options_hidden" value="$env{'form.scantron_options_hidden'}" />
1.203 albertel 6622: SCANTRONFORM
1.447 foxr 6623:
6624: my $line = 0;
6625: while (defined($env{"form.scantron.bubblelines.$line"})) {
6626: my $chunk =
6627: '<input type="hidden" name="scantron.bubblelines.'.$line.'" value="'.$env{"form.scantron.bubblelines.$line"}.'" />'."\n";
1.448 foxr 6628: $chunk .=
6629: '<input type="hidden" name="scantron.first_bubble_line.'.$line.'" value="'.$env{"form.scantron.first_bubble_line.$line"}.'" />'."\n";
1.503 raeburn 6630: $chunk .=
6631: '<input type="hidden" name="scantron.sub_bubblelines.'.$line.'" value="'.$env{"form.scantron.sub_bubblelines.$line"}.'" />'."\n";
1.504 raeburn 6632: $chunk .=
6633: '<input type="hidden" name="scantron.responsetype.'.$line.'" value="'.$env{"form.scantron.responsetype.$line"}.'" />'."\n";
1.691 raeburn 6634: $chunk .=
6635: '<input type="hidden" name="scantron.residpart.'.$line.'" value="'.$env{"form.scantron.residpart.$line"}.'" />'."\n";
1.447 foxr 6636: $result .= $chunk;
6637: $line++;
1.691 raeburn 6638: }
1.203 albertel 6639: return $result;
6640: }
6641:
1.423 albertel 6642: =pod
6643:
6644: =item scantron_validate_file
6645:
1.659 raeburn 6646: Dispatch routine for doing validation of a bubblesheet data file.
1.424 albertel 6647:
6648: Also processes any necessary information resets that need to
6649: occur before validation begins (ignore previous corrections,
6650: restarting the skipped records processing)
6651:
1.423 albertel 6652: =cut
6653:
1.157 albertel 6654: sub scantron_validate_file {
1.608 www 6655: my ($r,$symb) = @_;
1.157 albertel 6656: if (!$symb) {return '';}
1.324 albertel 6657: my $default_form_data=&defaultFormData($symb);
1.200 albertel 6658:
6659: # do the detection of only doing skipped records first befroe we delete
1.424 albertel 6660: # them when doing the corrections reset
1.257 albertel 6661: if ($env{'form.scantron_options_redo'} ne 'redo_skipped_ready') {
1.200 albertel 6662: &reset_skipping_status();
6663: }
1.257 albertel 6664: if ($env{'form.scantron_options_redo'} eq 'redo_skipped') {
1.200 albertel 6665: &remember_current_skipped();
1.257 albertel 6666: $env{'form.scantron_options_redo'}='redo_skipped_ready';
1.200 albertel 6667: }
6668:
1.257 albertel 6669: if ($env{'form.scantron_options_ignore'} eq 'ignore_corrections') {
1.200 albertel 6670: &check_for_error($r,&scantron_remove_file('corrected'));
6671: &check_for_error($r,&scantron_remove_file('skipped'));
6672: &check_for_error($r,&scantron_remove_scan_data());
1.257 albertel 6673: $env{'form.scantron_options_ignore'}='done';
1.192 albertel 6674: }
1.200 albertel 6675:
1.257 albertel 6676: if ($env{'form.scantron_corrections'}) {
1.157 albertel 6677: &scantron_process_corrections($r);
6678: }
1.503 raeburn 6679: $r->print('<p>'.&mt('Gathering necessary information.').'</p>');$r->rflush();
1.157 albertel 6680: #get the student pick code ready
6681: $r->print(&Apache::loncommon::studentbrowser_javascript());
1.582 raeburn 6682: my $nav_error;
1.649 raeburn 6683: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
6684: my $max_bubble=&scantron_get_maxbubble(\$nav_error,\%scantron_config);
1.582 raeburn 6685: if ($nav_error) {
6686: $r->print(&navmap_errormsg());
6687: return '';
6688: }
1.203 albertel 6689: my $result=&scantron_form_start($max_bubble).$default_form_data;
1.663 raeburn 6690: if ($env{'form.scantron_lastbubblepoints'} ne '') {
6691: $result .= '<input type="hidden" name="scantron_lastbubblepoints" value="'.$env{'form.scantron_lastbubblepoints'}.'" />';
6692: }
1.157 albertel 6693: $r->print($result);
6694:
1.334 albertel 6695: my @validate_phases=( 'sequence',
6696: 'ID',
1.157 albertel 6697: 'CODE',
6698: 'doublebubble',
6699: 'missingbubbles');
1.257 albertel 6700: if (!$env{'form.validatepass'}) {
6701: $env{'form.validatepass'} = 0;
1.157 albertel 6702: }
1.257 albertel 6703: my $currentphase=$env{'form.validatepass'};
1.157 albertel 6704:
1.448 foxr 6705:
1.157 albertel 6706: my $stop=0;
6707: while (!$stop && $currentphase < scalar(@validate_phases)) {
1.503 raeburn 6708: $r->print(&mt('Validating '.$validate_phases[$currentphase]).'<br />');
1.157 albertel 6709: $r->rflush();
1.691 raeburn 6710:
1.157 albertel 6711: my $which="scantron_validate_".$validate_phases[$currentphase];
6712: {
6713: no strict 'refs';
6714: ($stop,$currentphase)=&$which($r,$currentphase);
6715: }
6716: }
6717: if (!$stop) {
1.650 raeburn 6718: my $warning=&scantron_warning_screen('Start Grading',$symb);
1.542 raeburn 6719: $r->print(&mt('Validation process complete.').'<br />'.
6720: $warning.
6721: &mt('Perform verification for each student after storage of submissions?').
6722: ' <span class="LC_nobreak"><label>'.
6723: '<input type="radio" name="verifyrecord" value="1" />'.&mt('Yes').'</label>'.
6724: (' 'x3).'<label>'.
6725: '<input type="radio" name="verifyrecord" value="0" checked="checked" />'.&mt('No').
6726: '</label></span><br />'.
6727: &mt('Grading will take longer if you use verification.').'<br />'.
1.650 raeburn 6728: &mt('Otherwise, Grade/Manage/Review Bubblesheets [_1] Review bubblesheet data can be used once grading is complete.','»').'<br /><br />'.
1.542 raeburn 6729: '<input type="submit" name="submit" value="'.&mt('Start Grading').'" />'.
6730: '<input type="hidden" name="command" value="scantron_process" />'."\n");
1.157 albertel 6731: } else {
6732: $r->print('<input type="hidden" name="command" value="scantron_validate" />');
6733: $r->print("<input type='hidden' name='validatepass' value='".$currentphase."' />");
6734: }
6735: if ($stop) {
1.334 albertel 6736: if ($validate_phases[$currentphase] eq 'sequence') {
1.539 riegler 6737: $r->print('<input type="submit" name="submit" value="'.&mt('Ignore').' → " />');
1.492 albertel 6738: $r->print(' '.&mt('this error').' <br />');
1.334 albertel 6739:
1.650 raeburn 6740: $r->print('<p>'.&mt('Or return to [_1]Grade/Manage/Review Bubblesheets[_2] to start over.','<a href="/adm/grades?symb='.$symb.'&command=scantron_selectphase" class="LC_info">','</a>').'</p>');
1.334 albertel 6741: } else {
1.503 raeburn 6742: if ($validate_phases[$currentphase] eq 'doublebubble' || $validate_phases[$currentphase] eq 'missingbubbles') {
1.539 riegler 6743: $r->print('<input type="button" name="submitbutton" value="'.&mt('Continue').' →" onclick="javascript:verify_bubble_radio(this.form)" />');
1.503 raeburn 6744: } else {
1.539 riegler 6745: $r->print('<input type="submit" name="submit" value="'.&mt('Continue').' →" />');
1.503 raeburn 6746: }
1.492 albertel 6747: $r->print(' '.&mt('using corrected info').' <br />');
6748: $r->print("<input type='submit' value='".&mt("Skip")."' name='scantron_skip_record' />");
6749: $r->print(" ".&mt("this scanline saving it for later."));
1.334 albertel 6750: }
1.157 albertel 6751: }
1.614 www 6752: $r->print(" </form><br />");
1.157 albertel 6753: return '';
6754: }
6755:
1.423 albertel 6756:
6757: =pod
6758:
6759: =item scantron_remove_file
6760:
1.659 raeburn 6761: Removes the requested bubblesheet data file, makes sure that
1.424 albertel 6762: scantron_original_<filename> is never removed
6763:
6764:
1.423 albertel 6765: =cut
6766:
1.200 albertel 6767: sub scantron_remove_file {
1.192 albertel 6768: my ($which)=@_;
1.257 albertel 6769: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6770: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 6771: my $file='scantron_';
1.200 albertel 6772: if ($which eq 'corrected' || $which eq 'skipped') {
6773: $file.=$which.'_';
1.192 albertel 6774: } else {
6775: return 'refused';
6776: }
1.257 albertel 6777: $file.=$env{'form.scantron_selectfile'};
1.200 albertel 6778: return &Apache::lonnet::removeuserfile($cname,$cdom,$file);
6779: }
6780:
1.423 albertel 6781:
6782: =pod
6783:
6784: =item scantron_remove_scan_data
6785:
1.659 raeburn 6786: Removes all scan_data correction for the requested bubblesheet
1.424 albertel 6787: data file. (In the case that both the are doing skipped records we need
6788: to remember the old skipped lines for the time being so that element
6789: persists for a while.)
6790:
1.423 albertel 6791: =cut
6792:
1.200 albertel 6793: sub scantron_remove_scan_data {
1.257 albertel 6794: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6795: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 6796: my @keys=&Apache::lonnet::getkeys('nohist_scantrondata',$cdom,$cname);
6797: my @todelete;
1.257 albertel 6798: my $filename=$env{'form.scantron_selectfile'};
1.192 albertel 6799: foreach my $key (@keys) {
6800: if ($key=~/^\Q$filename\E_/) {
1.257 albertel 6801: if ($env{'form.scantron_options_redo'} eq 'redo_skipped_ready' &&
1.200 albertel 6802: $key=~/remember_skipping/) {
6803: next;
6804: }
1.192 albertel 6805: push(@todelete,$key);
6806: }
6807: }
1.200 albertel 6808: my $result;
1.192 albertel 6809: if (@todelete) {
1.491 albertel 6810: $result = &Apache::lonnet::del('nohist_scantrondata',
6811: \@todelete,$cdom,$cname);
6812: } else {
6813: $result = 'ok';
1.192 albertel 6814: }
6815: return $result;
6816: }
6817:
1.423 albertel 6818:
6819: =pod
6820:
6821: =item scantron_getfile
6822:
1.659 raeburn 6823: Fetches the requested bubblesheet data file (all 3 versions), and
1.424 albertel 6824: the scan_data hash
6825:
6826: Arguments:
6827: None
6828:
6829: Returns:
6830: 2 hash references
6831:
6832: - first one has
6833: orig -
6834: corrected -
6835: skipped - each of which points to an array ref of the specified
6836: file broken up into individual lines
6837: count - number of scanlines
6838:
6839: - second is the scan_data hash possible keys are
1.425 albertel 6840: ($number refers to scanline numbered $number and thus the key affects
6841: only that scanline
6842: $bubline refers to the specific bubble line element and the aspects
6843: refers to that specific bubble line element)
6844:
6845: $number.user - username:domain to use
6846: $number.CODE_ignore_dup
6847: - ignore the duplicate CODE error
6848: $number.useCODE
6849: - use the CODE in the scanline as is
6850: $number.no_bubble.$bubline
6851: - it is valid that there is no bubbled in bubble
6852: at $number $bubline
6853: remember_skipping
6854: - a frozen hash containing keys of $number and values
6855: of either
6856: 1 - we are on a 'do skipped records pass' and plan
6857: on processing this line
6858: 2 - we are on a 'do skipped records pass' and this
6859: scanline has been marked to skip yet again
1.424 albertel 6860:
1.423 albertel 6861: =cut
6862:
1.157 albertel 6863: sub scantron_getfile {
1.200 albertel 6864: #FIXME really would prefer a scantron directory
1.257 albertel 6865: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6866: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.157 albertel 6867: my $lines;
6868: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6869: 'scantron_orig_'.$env{'form.scantron_selectfile'});
1.157 albertel 6870: my %scanlines;
6871: $scanlines{'orig'}=[(split("\n",$lines,-1))];
6872: my $temp=$scanlines{'orig'};
6873: $scanlines{'count'}=$#$temp;
6874:
6875: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6876: 'scantron_corrected_'.$env{'form.scantron_selectfile'});
1.157 albertel 6877: if ($lines eq '-1') {
6878: $scanlines{'corrected'}=[];
6879: } else {
6880: $scanlines{'corrected'}=[(split("\n",$lines,-1))];
6881: }
6882: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6883: 'scantron_skipped_'.$env{'form.scantron_selectfile'});
1.157 albertel 6884: if ($lines eq '-1') {
6885: $scanlines{'skipped'}=[];
6886: } else {
6887: $scanlines{'skipped'}=[(split("\n",$lines,-1))];
6888: }
1.175 albertel 6889: my @tmp=&Apache::lonnet::dump('nohist_scantrondata',$cdom,$cname);
1.157 albertel 6890: if ($tmp[0] =~ /^(error:|no_such_host)/) { @tmp=(); }
6891: my %scan_data = @tmp;
6892: return (\%scanlines,\%scan_data);
6893: }
6894:
1.423 albertel 6895: =pod
6896:
6897: =item lonnet_putfile
6898:
1.424 albertel 6899: Wrapper routine to call &Apache::lonnet::finishuserfileupload
6900:
6901: Arguments:
6902: $contents - data to store
6903: $filename - filename to store $contents into
6904:
6905: Returns:
6906: result value from &Apache::lonnet::finishuserfileupload
6907:
1.423 albertel 6908: =cut
6909:
1.157 albertel 6910: sub lonnet_putfile {
6911: my ($contents,$filename)=@_;
1.257 albertel 6912: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6913: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6914: $env{'form.sillywaytopassafilearound'}=$contents;
1.275 albertel 6915: &Apache::lonnet::finishuserfileupload($docuname,$docudom,'sillywaytopassafilearound',$filename);
1.157 albertel 6916:
6917: }
6918:
1.423 albertel 6919: =pod
6920:
6921: =item scantron_putfile
6922:
1.659 raeburn 6923: Stores the current version of the bubblesheet data files, and the
1.424 albertel 6924: scan_data hash. (Does not modify the original version only the
6925: corrected and skipped versions.
6926:
6927: Arguments:
6928: $scanlines - hash ref that looks like the first return value from
6929: &scantron_getfile()
6930: $scan_data - hash ref that looks like the second return value from
6931: &scantron_getfile()
6932:
1.423 albertel 6933: =cut
6934:
1.157 albertel 6935: sub scantron_putfile {
6936: my ($scanlines,$scan_data) = @_;
1.200 albertel 6937: #FIXME really would prefer a scantron directory
1.257 albertel 6938: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6939: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.200 albertel 6940: if ($scanlines) {
6941: my $prefix='scantron_';
1.157 albertel 6942: # no need to update orig, shouldn't change
6943: # &lonnet_putfile(join("\n",@{$scanlines->{'orig'}}),$prefix.'orig_'.
1.257 albertel 6944: # $env{'form.scantron_selectfile'});
1.200 albertel 6945: &lonnet_putfile(join("\n",@{$scanlines->{'corrected'}}),
6946: $prefix.'corrected_'.
1.257 albertel 6947: $env{'form.scantron_selectfile'});
1.200 albertel 6948: &lonnet_putfile(join("\n",@{$scanlines->{'skipped'}}),
6949: $prefix.'skipped_'.
1.257 albertel 6950: $env{'form.scantron_selectfile'});
1.200 albertel 6951: }
1.175 albertel 6952: &Apache::lonnet::put('nohist_scantrondata',$scan_data,$cdom,$cname);
1.157 albertel 6953: }
6954:
1.423 albertel 6955: =pod
6956:
6957: =item scantron_get_line
6958:
1.424 albertel 6959: Returns the correct version of the scanline
6960:
6961: Arguments:
6962: $scanlines - hash ref that looks like the first return value from
6963: &scantron_getfile()
6964: $scan_data - hash ref that looks like the second return value from
6965: &scantron_getfile()
6966: $i - number of the requested line (starts at 0)
6967:
6968: Returns:
6969: A scanline, (either the original or the corrected one if it
6970: exists), or undef if the requested scanline should be
6971: skipped. (Either because it's an skipped scanline, or it's an
6972: unskipped scanline and we are not doing a 'do skipped scanlines'
6973: pass.
6974:
1.423 albertel 6975: =cut
6976:
1.157 albertel 6977: sub scantron_get_line {
1.200 albertel 6978: my ($scanlines,$scan_data,$i)=@_;
1.376 albertel 6979: if (&should_be_skipped($scanlines,$scan_data,$i)) { return undef; }
6980: #if ($scanlines->{'skipped'}[$i]) { return undef; }
1.157 albertel 6981: if ($scanlines->{'corrected'}[$i]) {return $scanlines->{'corrected'}[$i];}
6982: return $scanlines->{'orig'}[$i];
6983: }
6984:
1.423 albertel 6985: =pod
6986:
6987: =item scantron_todo_count
6988:
1.424 albertel 6989: Counts the number of scanlines that need processing.
6990:
6991: Arguments:
6992: $scanlines - hash ref that looks like the first return value from
6993: &scantron_getfile()
6994: $scan_data - hash ref that looks like the second return value from
6995: &scantron_getfile()
6996:
6997: Returns:
6998: $count - number of scanlines to process
6999:
1.423 albertel 7000: =cut
7001:
1.200 albertel 7002: sub get_todo_count {
7003: my ($scanlines,$scan_data)=@_;
7004: my $count=0;
7005: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
7006: my $line=&scantron_get_line($scanlines,$scan_data,$i);
7007: if ($line=~/^[\s\cz]*$/) { next; }
7008: $count++;
7009: }
7010: return $count;
7011: }
7012:
1.423 albertel 7013: =pod
7014:
7015: =item scantron_put_line
7016:
1.659 raeburn 7017: Updates the 'corrected' or 'skipped' versions of the bubblesheet
1.424 albertel 7018: data file.
7019:
7020: Arguments:
7021: $scanlines - hash ref that looks like the first return value from
7022: &scantron_getfile()
7023: $scan_data - hash ref that looks like the second return value from
7024: &scantron_getfile()
7025: $i - line number to update
7026: $newline - contents of the updated scanline
7027: $skip - if true make the line for skipping and update the
7028: 'skipped' file
7029:
1.423 albertel 7030: =cut
7031:
1.157 albertel 7032: sub scantron_put_line {
1.200 albertel 7033: my ($scanlines,$scan_data,$i,$newline,$skip)=@_;
1.157 albertel 7034: if ($skip) {
7035: $scanlines->{'skipped'}[$i]=$newline;
1.376 albertel 7036: &start_skipping($scan_data,$i);
1.157 albertel 7037: return;
7038: }
7039: $scanlines->{'corrected'}[$i]=$newline;
7040: }
7041:
1.423 albertel 7042: =pod
7043:
7044: =item scantron_clear_skip
7045:
1.424 albertel 7046: Remove a line from the 'skipped' file
7047:
7048: Arguments:
7049: $scanlines - hash ref that looks like the first return value from
7050: &scantron_getfile()
7051: $scan_data - hash ref that looks like the second return value from
7052: &scantron_getfile()
7053: $i - line number to update
7054:
1.423 albertel 7055: =cut
7056:
1.376 albertel 7057: sub scantron_clear_skip {
7058: my ($scanlines,$scan_data,$i)=@_;
7059: if (exists($scanlines->{'skipped'}[$i])) {
7060: undef($scanlines->{'skipped'}[$i]);
7061: return 1;
7062: }
7063: return 0;
7064: }
7065:
1.423 albertel 7066: =pod
7067:
7068: =item scantron_filter_not_exam
7069:
1.424 albertel 7070: Filter routine used by &Apache::lonnavmaps::retrieveResources(), to
7071: filter out resources that are not marked as 'exam' mode
7072:
1.423 albertel 7073: =cut
7074:
1.334 albertel 7075: sub scantron_filter_not_exam {
7076: my ($curres)=@_;
7077:
7078: if (ref($curres) && $curres->is_problem() && !$curres->is_exam()) {
7079: # if the user has asked to not have either hidden
7080: # or 'randomout' controlled resources to be graded
7081: # don't include them
7082: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
7083: && $curres->randomout) {
7084: return 0;
7085: }
7086: return 1;
7087: }
7088: return 0;
7089: }
7090:
1.423 albertel 7091: =pod
7092:
7093: =item scantron_validate_sequence
7094:
1.424 albertel 7095: Validates the selected sequence, checking for resource that are
7096: not set to exam mode.
7097:
1.423 albertel 7098: =cut
7099:
1.334 albertel 7100: sub scantron_validate_sequence {
7101: my ($r,$currentphase) = @_;
7102:
7103: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 7104: unless (ref($navmap)) {
7105: $r->print(&navmap_errormsg());
7106: return (1,$currentphase);
7107: }
1.334 albertel 7108: my (undef,undef,$sequence)=
7109: &Apache::lonnet::decode_symb($env{'form.selectpage'});
7110:
7111: my $map=$navmap->getResourceByUrl($sequence);
7112:
7113: $r->print('<input type="hidden" name="validate_sequence_exam"
7114: value="ignore" />');
7115: if ($env{'form.validate_sequence_exam'} ne 'ignore') {
7116: my @resources=
7117: $navmap->retrieveResources($map,\&scantron_filter_not_exam,1,0);
7118: if (@resources) {
1.675 bisitz 7119: $r->print(
7120: '<p class="LC_warning">'
7121: .&mt('Some resources in the sequence currently are not set to'
1.684 bisitz 7122: .' bubblesheet exam mode. Grading these resources currently may not'
1.675 bisitz 7123: .' work correctly.')
7124: .'</p>'
7125: );
1.334 albertel 7126: return (1,$currentphase);
7127: }
7128: }
7129:
7130: return (0,$currentphase+1);
7131: }
7132:
1.423 albertel 7133:
7134:
1.157 albertel 7135: sub scantron_validate_ID {
7136: my ($r,$currentphase) = @_;
7137:
7138: #get student info
7139: my $classlist=&Apache::loncoursedata::get_classlist();
7140: my %idmap=&username_to_idmap($classlist);
7141:
7142: #get scantron line setup
1.257 albertel 7143: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7144: my ($scanlines,$scan_data)=&scantron_getfile();
1.582 raeburn 7145:
7146: my $nav_error;
1.649 raeburn 7147: &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the bubble_lines.. array.
1.582 raeburn 7148: if ($nav_error) {
7149: $r->print(&navmap_errormsg());
7150: return(1,$currentphase);
7151: }
1.157 albertel 7152:
7153: my %found=('ids'=>{},'usernames'=>{});
7154: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7155: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7156: if ($line=~/^[\s\cz]*$/) { next; }
7157: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7158: $scan_data);
7159: my $id=$$scan_record{'scantron.ID'};
7160: my $found;
7161: foreach my $checkid (keys(%idmap)) {
7162: if (lc($checkid) eq lc($id)) { $found=$checkid;last; }
7163: }
7164: if ($found) {
7165: my $username=$idmap{$found};
7166: if ($found{'ids'}{$found}) {
7167: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
7168: $line,'duplicateID',$found);
1.194 albertel 7169: return(1,$currentphase);
1.157 albertel 7170: } elsif ($found{'usernames'}{$username}) {
7171: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
7172: $line,'duplicateID',$username);
1.194 albertel 7173: return(1,$currentphase);
1.157 albertel 7174: }
1.186 albertel 7175: #FIXME store away line we previously saw the ID on to use above
1.157 albertel 7176: $found{'ids'}{$found}++;
7177: $found{'usernames'}{$username}++;
7178: } else {
7179: if ($id =~ /^\s*$/) {
1.158 albertel 7180: my $username=&scan_data($scan_data,"$i.user");
1.157 albertel 7181: if (defined($username) && $found{'usernames'}{$username}) {
7182: &scantron_get_correction($r,$i,$scan_record,
7183: \%scantron_config,
7184: $line,'duplicateID',$username);
1.194 albertel 7185: return(1,$currentphase);
1.157 albertel 7186: } elsif (!defined($username)) {
7187: &scantron_get_correction($r,$i,$scan_record,
7188: \%scantron_config,
7189: $line,'incorrectID');
1.194 albertel 7190: return(1,$currentphase);
1.157 albertel 7191: }
7192: $found{'usernames'}{$username}++;
7193: } else {
7194: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
7195: $line,'incorrectID');
1.194 albertel 7196: return(1,$currentphase);
1.157 albertel 7197: }
7198: }
7199: }
7200:
7201: return (0,$currentphase+1);
7202: }
7203:
1.423 albertel 7204:
1.157 albertel 7205: sub scantron_get_correction {
1.691 raeburn 7206: my ($r,$i,$scan_record,$scan_config,$line,$error,$arg,
7207: $randomorder,$randompick,$respnumlookup,$startline)=@_;
1.454 banghart 7208: #FIXME in the case of a duplicated ID the previous line, probably need
1.157 albertel 7209: #to show both the current line and the previous one and allow skipping
7210: #the previous one or the current one
7211:
1.333 albertel 7212: if ( $$scan_record{'scantron.PaperID'} =~ /\S/) {
1.658 bisitz 7213: $r->print(
7214: '<p class="LC_warning">'
7215: .&mt('An error was detected ([_1]) for PaperID [_2]',
7216: "<b>$error</b>",
7217: '<tt>'.$$scan_record{'scantron.PaperID'}.'</tt>')
7218: ."</p> \n");
1.157 albertel 7219: } else {
1.658 bisitz 7220: $r->print(
7221: '<p class="LC_warning">'
7222: .&mt('An error was detected ([_1]) in scanline [_2] [_3]',
7223: "<b>$error</b>", $i, "<pre>$line</pre>")
7224: ."</p> \n");
7225: }
7226: my $message =
7227: '<p>'
7228: .&mt('The ID on the form is [_1]',
7229: "<tt>$$scan_record{'scantron.ID'}</tt>")
7230: .'<br />'
1.665 raeburn 7231: .&mt('The name on the paper is [_1], [_2]',
1.658 bisitz 7232: $$scan_record{'scantron.LastName'},
7233: $$scan_record{'scantron.FirstName'})
7234: .'</p>';
1.242 albertel 7235:
1.157 albertel 7236: $r->print('<input type="hidden" name="scantron_corrections" value="'.$error.'" />'."\n");
7237: $r->print('<input type="hidden" name="scantron_line" value="'.$i.'" />'."\n");
1.503 raeburn 7238: # Array populated for doublebubble or
7239: my @lines_to_correct; # missingbubble errors to build javascript
7240: # to validate radio button checking
7241:
1.157 albertel 7242: if ($error =~ /ID$/) {
1.186 albertel 7243: if ($error eq 'incorrectID') {
1.658 bisitz 7244: $r->print('<p class="LC_warning">'.&mt("The encoded ID is not in the classlist").
1.492 albertel 7245: "</p>\n");
1.157 albertel 7246: } elsif ($error eq 'duplicateID') {
1.658 bisitz 7247: $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 7248: }
1.242 albertel 7249: $r->print($message);
1.492 albertel 7250: $r->print("<p>".&mt("How should I handle this?")." <br /> \n");
1.157 albertel 7251: $r->print("\n<ul><li> ");
7252: #FIXME it would be nice if this sent back the user ID and
7253: #could do partial userID matches
7254: $r->print(&Apache::loncommon::selectstudent_link('scantronupload',
7255: 'scantron_username','scantron_domain'));
7256: $r->print(": <input type='text' name='scantron_username' value='' />");
1.685 bisitz 7257: $r->print("\n:\n".
1.257 albertel 7258: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'scantron_domain'));
1.157 albertel 7259:
7260: $r->print('</li>');
1.186 albertel 7261: } elsif ($error =~ /CODE$/) {
7262: if ($error eq 'incorrectCODE') {
1.658 bisitz 7263: $r->print('<p class="LC_warning">'.&mt("The encoded CODE is not in the list of possible CODEs.")."</p>\n");
1.186 albertel 7264: } elsif ($error eq 'duplicateCODE') {
1.658 bisitz 7265: $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 7266: }
1.658 bisitz 7267: $r->print("<p>".&mt('The CODE on the form is [_1]',
7268: "<tt>'$$scan_record{'scantron.CODE'}'</tt>")
7269: ."</p>\n");
1.242 albertel 7270: $r->print($message);
1.658 bisitz 7271: $r->print("<p>".&mt("How should I handle this?")."</p>\n");
1.187 albertel 7272: $r->print("\n<br /> ");
1.194 albertel 7273: my $i=0;
1.273 albertel 7274: if ($error eq 'incorrectCODE'
7275: && $$scan_record{'scantron.CODE'}=~/\S/ ) {
1.194 albertel 7276: my ($max,$closest)=&scantron_get_closely_matching_CODEs($arg,$$scan_record{'scantron.CODE'});
1.278 albertel 7277: if ($closest > 0) {
7278: foreach my $testcode (@{$closest}) {
7279: my $checked='';
1.569 bisitz 7280: if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 7281: $r->print("
7282: <label>
1.569 bisitz 7283: <input type='radio' name='scantron_CODE_resolution' value='use_closest_$i'$checked />
1.492 albertel 7284: ".&mt("Use the similar CODE [_1] instead.",
7285: "<b><tt>".$testcode."</tt></b>")."
7286: </label>
7287: <input type='hidden' name='scantron_CODE_closest_$i' value='$testcode' />");
1.278 albertel 7288: $r->print("\n<br />");
7289: $i++;
7290: }
1.194 albertel 7291: }
7292: }
1.273 albertel 7293: if ($$scan_record{'scantron.CODE'}=~/\S/ ) {
1.569 bisitz 7294: my $checked; if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 7295: $r->print("
7296: <label>
1.569 bisitz 7297: <input type='radio' name='scantron_CODE_resolution' value='use_unfound'$checked />
1.659 raeburn 7298: ".&mt("Use the CODE [_1] that was on the paper, ignoring the error.",
1.492 albertel 7299: "<b><tt>".$$scan_record{'scantron.CODE'}."</tt></b>")."
7300: </label>");
1.273 albertel 7301: $r->print("\n<br />");
7302: }
1.194 albertel 7303:
1.597 wenzelju 7304: $r->print(&Apache::lonhtmlcommon::scripttag(<<ENDSCRIPT));
1.188 albertel 7305: function change_radio(field) {
1.190 albertel 7306: var slct=document.scantronupload.scantron_CODE_resolution;
1.188 albertel 7307: var i;
7308: for (i=0;i<slct.length;i++) {
7309: if (slct[i].value==field) { slct[i].checked=true; }
7310: }
7311: }
7312: ENDSCRIPT
1.187 albertel 7313: my $href="/adm/pickcode?".
1.359 www 7314: "form=".&escape("scantronupload").
7315: "&scantron_format=".&escape($env{'form.scantron_format'}).
7316: "&scantron_CODElist=".&escape($env{'form.scantron_CODElist'}).
7317: "&curCODE=".&escape($$scan_record{'scantron.CODE'}).
7318: "&scantron_selectfile=".&escape($env{'form.scantron_selectfile'});
1.332 albertel 7319: if ($env{'form.scantron_CODElist'} =~ /\S/) {
1.492 albertel 7320: $r->print("
7321: <label>
7322: <input type='radio' name='scantron_CODE_resolution' value='use_found' />
7323: ".&mt("[_1]Select[_2] a CODE from the list of all CODEs and use it.",
7324: "<a target='_blank' href='$href'>","</a>")."
7325: </label>
1.558 bisitz 7326: ".&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 7327: $r->print("\n<br />");
7328: }
1.492 albertel 7329: $r->print("
7330: <label>
7331: <input type='radio' name='scantron_CODE_resolution' value='use_typed' />
7332: ".&mt("Use [_1] as the CODE.",
7333: "</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 7334: $r->print("\n<br /><br />");
1.157 albertel 7335: } elsif ($error eq 'doublebubble') {
1.658 bisitz 7336: $r->print('<p class="LC_warning">'.&mt("There have been multiple bubbles scanned for some question(s)")."</p>\n");
1.497 foxr 7337:
7338: # The form field scantron_questions is acutally a list of line numbers.
7339: # represented by this form so:
7340:
1.691 raeburn 7341: my $line_list = &questions_to_line_list($arg,$randomorder,$randompick,
7342: $respnumlookup,$startline);
1.497 foxr 7343:
1.157 albertel 7344: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 7345: $line_list.'" />');
1.242 albertel 7346: $r->print($message);
1.492 albertel 7347: $r->print("<p>".&mt("Please indicate which bubble should be used for grading")."</p>");
1.157 albertel 7348: foreach my $question (@{$arg}) {
1.503 raeburn 7349: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
1.691 raeburn 7350: $scan_record, $error,
7351: $randomorder,$randompick,
7352: $respnumlookup,$startline);
1.524 raeburn 7353: push(@lines_to_correct,@linenums);
1.157 albertel 7354: }
1.503 raeburn 7355: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 7356: } elsif ($error eq 'missingbubble') {
1.658 bisitz 7357: $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 7358: $r->print($message);
1.492 albertel 7359: $r->print("<p>".&mt("Please indicate which bubble should be used for grading.")."</p>");
1.503 raeburn 7360: $r->print(&mt("Some questions have no scanned bubbles.")."\n");
1.497 foxr 7361:
1.503 raeburn 7362: # The form field scantron_questions is actually a list of line numbers not
1.497 foxr 7363: # a list of question numbers. Therefore:
7364: #
1.691 raeburn 7365:
7366: my $line_list = &questions_to_line_list($arg,$randomorder,$randompick,
7367: $respnumlookup,$startline);
1.497 foxr 7368:
1.157 albertel 7369: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 7370: $line_list.'" />');
1.157 albertel 7371: foreach my $question (@{$arg}) {
1.503 raeburn 7372: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
1.691 raeburn 7373: $scan_record, $error,
7374: $randomorder,$randompick,
7375: $respnumlookup,$startline);
1.524 raeburn 7376: push(@lines_to_correct,@linenums);
1.157 albertel 7377: }
1.503 raeburn 7378: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 7379: } else {
7380: $r->print("\n<ul>");
7381: }
7382: $r->print("\n</li></ul>");
1.497 foxr 7383: }
7384:
1.503 raeburn 7385: sub verify_bubbles_checked {
7386: my (@ansnums) = @_;
7387: my $ansnumstr = join('","',@ansnums);
7388: my $warning = &mt("A bubble or 'No bubble' selection has not been made for one or more lines.");
1.597 wenzelju 7389: my $output = &Apache::lonhtmlcommon::scripttag((<<ENDSCRIPT));
1.503 raeburn 7390: function verify_bubble_radio(form) {
7391: var ansnumArray = new Array ("$ansnumstr");
7392: var need_bubble_count = 0;
7393: for (var i=0; i<ansnumArray.length; i++) {
7394: if (form.elements["scantron_correct_Q_"+ansnumArray[i]].length > 1) {
7395: var bubble_picked = 0;
7396: for (var j=0; j<form.elements["scantron_correct_Q_"+ansnumArray[i]].length; j++) {
7397: if (form.elements["scantron_correct_Q_"+ansnumArray[i]][j].checked == true) {
7398: bubble_picked = 1;
7399: }
7400: }
7401: if (bubble_picked == 0) {
7402: need_bubble_count ++;
7403: }
7404: }
7405: }
7406: if (need_bubble_count) {
7407: alert("$warning");
7408: return;
7409: }
7410: form.submit();
7411: }
7412: ENDSCRIPT
7413: return $output;
7414: }
7415:
1.497 foxr 7416: =pod
7417:
7418: =item questions_to_line_list
1.157 albertel 7419:
1.497 foxr 7420: Converts a list of questions into a string of comma separated
7421: line numbers in the answer sheet used by the questions. This is
7422: used to fill in the scantron_questions form field.
7423:
7424: Arguments:
7425: questions - Reference to an array of questions.
1.691 raeburn 7426: randomorder - True if randomorder in use.
7427: randompick - True if randompick in use.
7428: respnumlookup - Reference to HASH mapping question numbers in bubble lines
7429: for current line to question number used for same question
7430: in "Master Seqence" (as seen by Course Coordinator).
7431: startline - Reference to hash where key is question number (0 is first)
7432: and key is number of first bubble line for current student
7433: or code-based randompick and/or randomorder.
1.693 raeburn 7434:
1.497 foxr 7435: =cut
7436:
7437:
7438: sub questions_to_line_list {
1.691 raeburn 7439: my ($questions,$randomorder,$randompick,$respnumlookup,$startline) = @_;
1.497 foxr 7440: my @lines;
7441:
1.503 raeburn 7442: foreach my $item (@{$questions}) {
7443: my $question = $item;
7444: my ($first,$count,$last);
7445: if ($item =~ /^(\d+)\.(\d+)$/) {
7446: $question = $1;
7447: my $subquestion = $2;
1.691 raeburn 7448: my $responsenum = $question-1;
7449: if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
7450: $responsenum = $respnumlookup->{$question-1};
7451: if (ref($startline) eq 'HASH') {
7452: $first = $startline->{$question-1} + 1;
7453: }
7454: } else {
7455: $first = $first_bubble_line{$responsenum} + 1;
7456: }
7457: my @subans = split(/,/,$subdivided_bubble_lines{$responsenum});
1.503 raeburn 7458: my $subcount = 1;
7459: while ($subcount<$subquestion) {
7460: $first += $subans[$subcount-1];
7461: $subcount ++;
7462: }
7463: $count = $subans[$subquestion-1];
7464: } else {
1.691 raeburn 7465: my $responsenum = $question-1;
7466: if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
7467: $responsenum = $respnumlookup->{$question-1};
7468: if (ref($startline) eq 'HASH') {
7469: $first = $startline->{$question-1} + 1;
7470: }
7471: } else {
7472: $first = $first_bubble_line{$responsenum} + 1;
7473: }
7474: $count = $bubble_lines_per_response{$responsenum};
1.503 raeburn 7475: }
1.506 raeburn 7476: $last = $first+$count-1;
1.503 raeburn 7477: push(@lines, ($first..$last));
1.497 foxr 7478: }
7479: return join(',', @lines);
7480: }
7481:
7482: =pod
7483:
7484: =item prompt_for_corrections
7485:
7486: Prompts for a potentially multiline correction to the
7487: user's bubbling (factors out common code from scantron_get_correction
7488: for multi and missing bubble cases).
7489:
7490: Arguments:
7491: $r - Apache request object.
7492: $question - The question number to prompt for.
7493: $scan_config - The scantron file configuration hash.
7494: $scan_record - Reference to the hash that has the the parsed scanlines.
1.503 raeburn 7495: $error - Type of error
1.691 raeburn 7496: $randomorder - True if randomorder in use.
7497: $randompick - True if randompick in use.
7498: $respnumlookup - Reference to HASH mapping question numbers in bubble lines
7499: for current line to question number used for same question
7500: in "Master Seqence" (as seen by Course Coordinator).
7501: $startline - Reference to hash where key is question number (0 is first)
7502: and value is number of first bubble line for current student
7503: or code-based randompick and/or randomorder.
7504:
1.497 foxr 7505:
7506: Implicit inputs:
7507: %bubble_lines_per_response - Starting line numbers for each question.
7508: Numbered from 0 (but question numbers are from
7509: 1.
7510: %first_bubble_line - Starting bubble line for each question.
1.509 raeburn 7511: %subdivided_bubble_lines - optionresponse, matchresponse and rankresponse
7512: type problems render as separate sub-questions,
1.503 raeburn 7513: in exam mode. This hash contains a
7514: comma-separated list of the lines per
7515: sub-question.
1.510 raeburn 7516: %responsetype_per_response - essayresponse, formularesponse,
7517: stringresponse, imageresponse, reactionresponse,
7518: and organicresponse type problem parts can have
1.503 raeburn 7519: multiple lines per response if the weight
7520: assigned exceeds 10. In this case, only
7521: one bubble per line is permitted, but more
7522: than one line might contain bubbles, e.g.
7523: bubbling of: line 1 - J, line 2 - J,
7524: line 3 - B would assign 22 points.
1.497 foxr 7525:
7526: =cut
7527:
7528: sub prompt_for_corrections {
1.691 raeburn 7529: my ($r, $question, $scan_config, $scan_record, $error, $randomorder,
7530: $randompick, $respnumlookup, $startline) = @_;
1.503 raeburn 7531: my ($current_line,$lines);
7532: my @linenums;
7533: my $questionnum = $question;
1.691 raeburn 7534: my ($first,$responsenum);
1.503 raeburn 7535: if ($question =~ /^(\d+)\.(\d+)$/) {
7536: $question = $1;
7537: my $subquestion = $2;
1.691 raeburn 7538: if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
7539: $responsenum = $respnumlookup->{$question-1};
7540: if (ref($startline) eq 'HASH') {
7541: $first = $startline->{$question-1};
7542: }
7543: } else {
7544: $responsenum = $question-1;
7545: $first = $first_bubble_line{$responsenum} + 1;
7546: }
7547: $current_line = $first + 1 ;
7548: my @subans = split(/,/,$subdivided_bubble_lines{$responsenum});
1.503 raeburn 7549: my $subcount = 1;
7550: while ($subcount<$subquestion) {
7551: $current_line += $subans[$subcount-1];
7552: $subcount ++;
7553: }
7554: $lines = $subans[$subquestion-1];
7555: } else {
1.691 raeburn 7556: if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
7557: $responsenum = $respnumlookup->{$question-1};
7558: if (ref($startline) eq 'HASH') {
7559: $first = $startline->{$question-1};
7560: }
7561: } else {
7562: $responsenum = $question-1;
7563: $first = $first_bubble_line{$responsenum};
7564: }
7565: $current_line = $first + 1;
7566: $lines = $bubble_lines_per_response{$responsenum};
1.503 raeburn 7567: }
1.497 foxr 7568: if ($lines > 1) {
1.503 raeburn 7569: $r->print(&mt('The group of bubble lines below responds to a single question.').'<br />');
1.691 raeburn 7570: if (($responsetype_per_response{$responsenum} eq 'essayresponse') ||
7571: ($responsetype_per_response{$responsenum} eq 'formularesponse') ||
7572: ($responsetype_per_response{$responsenum} eq 'stringresponse') ||
7573: ($responsetype_per_response{$responsenum} eq 'imageresponse') ||
7574: ($responsetype_per_response{$responsenum} eq 'reactionresponse') ||
7575: ($responsetype_per_response{$responsenum} eq 'organicresponse')) {
1.684 bisitz 7576: $r->print(
7577: &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)
7578: .'<br /><br />'
7579: .&mt('A non-zero score can be assigned to the student during bubblesheet grading by selecting a bubble in at least one line.')
7580: .'<br />'
7581: .&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.')
7582: .'<br />'
7583: .&mt("To assign a score of zero for this question, mark all lines as 'No bubble'.")
7584: .'<br /><br />'
7585: );
1.503 raeburn 7586: } else {
7587: $r->print(&mt("Select at most one bubble in a single line and select 'No Bubble' in all the other lines. ")."<br />");
7588: }
1.497 foxr 7589: }
7590: for (my $i =0; $i < $lines; $i++) {
1.503 raeburn 7591: my $selected = $$scan_record{"scantron.$current_line.answer"};
1.691 raeburn 7592: &scantron_bubble_selector($r,$scan_config,$current_line,
1.503 raeburn 7593: $questionnum,$error,split('', $selected));
1.524 raeburn 7594: push(@linenums,$current_line);
1.497 foxr 7595: $current_line++;
7596: }
7597: if ($lines > 1) {
7598: $r->print("<hr /><br />");
7599: }
1.503 raeburn 7600: return @linenums;
1.157 albertel 7601: }
1.423 albertel 7602:
7603: =pod
7604:
7605: =item scantron_bubble_selector
7606:
7607: Generates the html radiobuttons to correct a single bubble line
1.424 albertel 7608: possibly showing the existing the selected bubbles if known
1.423 albertel 7609:
7610: Arguments:
7611: $r - Apache request object
7612: $scan_config - hash from &get_scantron_config()
1.497 foxr 7613: $line - Number of the line being displayed.
1.503 raeburn 7614: $questionnum - Question number (may include subquestion)
7615: $error - Type of error.
1.497 foxr 7616: @selected - Array of bubbles picked on this line.
1.423 albertel 7617:
7618: =cut
7619:
1.157 albertel 7620: sub scantron_bubble_selector {
1.503 raeburn 7621: my ($r,$scan_config,$line,$questionnum,$error,@selected)=@_;
1.157 albertel 7622: my $max=$$scan_config{'Qlength'};
1.274 albertel 7623:
7624: my $scmode=$$scan_config{'Qon'};
1.649 raeburn 7625: if ($scmode eq 'number' || $scmode eq 'letter') {
7626: if (($$scan_config{'BubblesPerRow'} =~ /^\d+$/) &&
7627: ($$scan_config{'BubblesPerRow'} > 0)) {
7628: $max=$$scan_config{'BubblesPerRow'};
7629: if (($scmode eq 'number') && ($max > 10)) {
7630: $max = 10;
7631: } elsif (($scmode eq 'letter') && $max > 26) {
7632: $max = 26;
7633: }
7634: } else {
7635: $max = 10;
7636: }
7637: }
1.274 albertel 7638:
1.157 albertel 7639: my @alphabet=('A'..'Z');
1.503 raeburn 7640: $r->print(&Apache::loncommon::start_data_table().
7641: &Apache::loncommon::start_data_table_row());
7642: $r->print('<td rowspan="2" class="LC_leftcol_header">'.$line.'</td>');
1.497 foxr 7643: for (my $i=0;$i<$max+1;$i++) {
7644: $r->print("\n".'<td align="center">');
7645: if ($selected[0] eq $alphabet[$i]) { $r->print('X'); shift(@selected) }
7646: else { $r->print(' '); }
7647: $r->print('</td>');
7648: }
1.503 raeburn 7649: $r->print(&Apache::loncommon::end_data_table_row().
7650: &Apache::loncommon::start_data_table_row());
1.497 foxr 7651: for (my $i=0;$i<$max;$i++) {
7652: $r->print("\n".
7653: '<td><label><input type="radio" name="scantron_correct_Q_'.
7654: $line.'" value="'.$i.'" />'.$alphabet[$i]."</label></td>");
7655: }
1.503 raeburn 7656: my $nobub_checked = ' ';
7657: if ($error eq 'missingbubble') {
7658: $nobub_checked = ' checked = "checked" ';
7659: }
7660: $r->print("\n".'<td><label><input type="radio" name="scantron_correct_Q_'.
7661: $line.'" value="none"'.$nobub_checked.'/>'.&mt('No bubble').
7662: '</label>'."\n".'<input type="hidden" name="scantron_questionnum_Q_'.
7663: $line.'" value="'.$questionnum.'" /></td>');
7664: $r->print(&Apache::loncommon::end_data_table_row().
7665: &Apache::loncommon::end_data_table());
1.157 albertel 7666: }
7667:
1.423 albertel 7668: =pod
7669:
7670: =item num_matches
7671:
1.424 albertel 7672: Counts the number of characters that are the same between the two arguments.
7673:
7674: Arguments:
7675: $orig - CODE from the scanline
7676: $code - CODE to match against
7677:
7678: Returns:
7679: $count - integer count of the number of same characters between the
7680: two arguments
7681:
1.423 albertel 7682: =cut
7683:
1.194 albertel 7684: sub num_matches {
7685: my ($orig,$code) = @_;
7686: my @code=split(//,$code);
7687: my @orig=split(//,$orig);
7688: my $same=0;
7689: for (my $i=0;$i<scalar(@code);$i++) {
7690: if ($code[$i] eq $orig[$i]) { $same++; }
7691: }
7692: return $same;
7693: }
7694:
1.423 albertel 7695: =pod
7696:
7697: =item scantron_get_closely_matching_CODEs
7698:
1.424 albertel 7699: Cycles through all CODEs and finds the set that has the greatest
7700: number of same characters as the provided CODE
7701:
7702: Arguments:
7703: $allcodes - hash ref returned by &get_codes()
7704: $CODE - CODE from the current scanline
7705:
7706: Returns:
7707: 2 element list
7708: - first elements is number of how closely matching the best fit is
7709: (5 means best set has 5 matching characters)
7710: - second element is an arrary ref containing the set of valid CODEs
7711: that best fit the passed in CODE
7712:
1.423 albertel 7713: =cut
7714:
1.194 albertel 7715: sub scantron_get_closely_matching_CODEs {
7716: my ($allcodes,$CODE)=@_;
7717: my @CODEs;
7718: foreach my $testcode (sort(keys(%{$allcodes}))) {
7719: push(@{$CODEs[&num_matches($CODE,$testcode)]},$testcode);
7720: }
7721:
7722: return ($#CODEs,$CODEs[-1]);
7723: }
7724:
1.423 albertel 7725: =pod
7726:
7727: =item get_codes
7728:
1.424 albertel 7729: Builds a hash which has keys of all of the valid CODEs from the selected
7730: set of remembered CODEs.
7731:
7732: Arguments:
7733: $old_name - name of the set of remembered CODEs
7734: $cdom - domain of the course
7735: $cnum - internal course name
7736:
7737: Returns:
7738: %allcodes - keys are the valid CODEs, values are all 1
7739:
1.423 albertel 7740: =cut
7741:
1.194 albertel 7742: sub get_codes {
1.280 foxr 7743: my ($old_name, $cdom, $cnum) = @_;
7744: if (!$old_name) {
7745: $old_name=$env{'form.scantron_CODElist'};
7746: }
7747: if (!$cdom) {
7748: $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
7749: }
7750: if (!$cnum) {
7751: $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
7752: }
1.278 albertel 7753: my %result=&Apache::lonnet::get('CODEs',[$old_name,"type\0$old_name"],
7754: $cdom,$cnum);
7755: my %allcodes;
7756: if ($result{"type\0$old_name"} eq 'number') {
7757: %allcodes=map {($_,1)} split(',',$result{$old_name});
7758: } else {
7759: %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
7760: }
1.194 albertel 7761: return %allcodes;
7762: }
7763:
1.423 albertel 7764: =pod
7765:
7766: =item scantron_validate_CODE
7767:
1.424 albertel 7768: Validates all scanlines in the selected file to not have any
7769: invalid or underspecified CODEs and that none of the codes are
7770: duplicated if this was requested.
7771:
1.423 albertel 7772: =cut
7773:
1.157 albertel 7774: sub scantron_validate_CODE {
7775: my ($r,$currentphase) = @_;
1.257 albertel 7776: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.186 albertel 7777: if ($scantron_config{'CODElocation'} &&
7778: $scantron_config{'CODEstart'} &&
7779: $scantron_config{'CODElength'}) {
1.257 albertel 7780: if (!defined($env{'form.scantron_CODElist'})) {
1.186 albertel 7781: &FIXME_blow_up()
7782: }
7783: } else {
7784: return (0,$currentphase+1);
7785: }
7786:
7787: my %usedCODEs;
7788:
1.194 albertel 7789: my %allcodes=&get_codes();
1.186 albertel 7790:
1.582 raeburn 7791: my $nav_error;
1.649 raeburn 7792: &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the lines per response array.
1.582 raeburn 7793: if ($nav_error) {
7794: $r->print(&navmap_errormsg());
7795: return(1,$currentphase);
7796: }
1.447 foxr 7797:
1.186 albertel 7798: my ($scanlines,$scan_data)=&scantron_getfile();
7799: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7800: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.186 albertel 7801: if ($line=~/^[\s\cz]*$/) { next; }
7802: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7803: $scan_data);
7804: my $CODE=$$scan_record{'scantron.CODE'};
7805: my $error=0;
1.224 albertel 7806: if (!&Apache::lonnet::validCODE($CODE)) {
7807: &scantron_get_correction($r,$i,$scan_record,
7808: \%scantron_config,
7809: $line,'incorrectCODE',\%allcodes);
7810: return(1,$currentphase);
7811: }
1.221 albertel 7812: if (%allcodes && !exists($allcodes{$CODE})
7813: && !$$scan_record{'scantron.useCODE'}) {
1.186 albertel 7814: &scantron_get_correction($r,$i,$scan_record,
7815: \%scantron_config,
1.194 albertel 7816: $line,'incorrectCODE',\%allcodes);
7817: return(1,$currentphase);
1.186 albertel 7818: }
1.214 albertel 7819: if (exists($usedCODEs{$CODE})
1.257 albertel 7820: && $env{'form.scantron_CODEunique'} eq 'yes'
1.192 albertel 7821: && !$$scan_record{'scantron.CODE_ignore_dup'}) {
1.186 albertel 7822: &scantron_get_correction($r,$i,$scan_record,
7823: \%scantron_config,
1.194 albertel 7824: $line,'duplicateCODE',$usedCODEs{$CODE});
7825: return(1,$currentphase);
1.186 albertel 7826: }
1.524 raeburn 7827: push(@{$usedCODEs{$CODE}},$$scan_record{'scantron.PaperID'});
1.186 albertel 7828: }
1.157 albertel 7829: return (0,$currentphase+1);
7830: }
7831:
1.423 albertel 7832: =pod
7833:
7834: =item scantron_validate_doublebubble
7835:
1.424 albertel 7836: Validates all scanlines in the selected file to not have any
7837: bubble lines with multiple bubbles marked.
7838:
1.423 albertel 7839: =cut
7840:
1.157 albertel 7841: sub scantron_validate_doublebubble {
7842: my ($r,$currentphase) = @_;
7843: #get student info
7844: my $classlist=&Apache::loncoursedata::get_classlist();
7845: my %idmap=&username_to_idmap($classlist);
1.691 raeburn 7846: my (undef,undef,$sequence)=
7847: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.157 albertel 7848:
7849: #get scantron line setup
1.257 albertel 7850: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7851: my ($scanlines,$scan_data)=&scantron_getfile();
1.691 raeburn 7852:
7853: my $navmap = Apache::lonnavmaps::navmap->new();
7854: unless (ref($navmap)) {
7855: $r->print(&navmap_errormsg());
7856: return(1,$currentphase);
7857: }
7858: my $map=$navmap->getResourceByUrl($sequence);
7859: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
7860: my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
7861: %grader_randomlists_by_symb,%orderedforcode,%respnumlookup,%startline);
7862: my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
7863:
1.583 raeburn 7864: my $nav_error;
1.691 raeburn 7865: if (ref($map)) {
7866: $randomorder = $map->randomorder();
7867: $randompick = $map->randompick();
7868: if ($randomorder || $randompick) {
7869: $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource);
7870: if ($nav_error) {
7871: $r->print(&navmap_errormsg());
7872: return(1,$currentphase);
7873: }
7874: &graders_resources_pass(\@resources,\%grader_partids_by_symb,
7875: \%grader_randomlists_by_symb,$bubbles_per_row);
7876: }
7877: } else {
7878: $r->print(&navmap_errormsg());
7879: return(1,$currentphase);
7880: }
7881:
1.649 raeburn 7882: &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the bubble line array.
1.583 raeburn 7883: if ($nav_error) {
7884: $r->print(&navmap_errormsg());
7885: return(1,$currentphase);
7886: }
1.447 foxr 7887:
1.157 albertel 7888: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7889: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7890: if ($line=~/^[\s\cz]*$/) { next; }
7891: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
1.691 raeburn 7892: $scan_data,undef,\%idmap,$randomorder,
7893: $randompick,$sequence,\@master_seq,
7894: \%symb_to_resource,\%grader_partids_by_symb,
7895: \%orderedforcode,\%respnumlookup,\%startline);
1.157 albertel 7896: if (!defined($$scan_record{'scantron.doubleerror'})) { next; }
7897: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,$line,
7898: 'doublebubble',
1.691 raeburn 7899: $$scan_record{'scantron.doubleerror'},
7900: $randomorder,$randompick,\%respnumlookup,\%startline);
1.157 albertel 7901: return (1,$currentphase);
7902: }
7903: return (0,$currentphase+1);
7904: }
7905:
1.423 albertel 7906:
1.503 raeburn 7907: sub scantron_get_maxbubble {
1.649 raeburn 7908: my ($nav_error,$scantron_config) = @_;
1.257 albertel 7909: if (defined($env{'form.scantron_maxbubble'}) &&
7910: $env{'form.scantron_maxbubble'}) {
1.447 foxr 7911: &restore_bubble_lines();
1.257 albertel 7912: return $env{'form.scantron_maxbubble'};
1.191 albertel 7913: }
1.330 albertel 7914:
1.447 foxr 7915: my (undef, undef, $sequence) =
1.257 albertel 7916: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.330 albertel 7917:
1.447 foxr 7918: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 7919: unless (ref($navmap)) {
7920: if (ref($nav_error)) {
7921: $$nav_error = 1;
7922: }
1.591 raeburn 7923: return;
1.582 raeburn 7924: }
1.191 albertel 7925: my $map=$navmap->getResourceByUrl($sequence);
7926: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.649 raeburn 7927: my $bubbles_per_row = &bubblesheet_bubbles_per_row($scantron_config);
1.330 albertel 7928:
7929: &Apache::lonxml::clear_problem_counter();
7930:
1.557 raeburn 7931: my $uname = $env{'user.name'};
7932: my $udom = $env{'user.domain'};
1.435 foxr 7933: my $cid = $env{'request.course.id'};
7934: my $total_lines = 0;
7935: %bubble_lines_per_response = ();
1.447 foxr 7936: %first_bubble_line = ();
1.503 raeburn 7937: %subdivided_bubble_lines = ();
7938: %responsetype_per_response = ();
1.691 raeburn 7939: %masterseq_id_responsenum = ();
1.554 raeburn 7940:
1.447 foxr 7941: my $response_number = 0;
7942: my $bubble_line = 0;
1.191 albertel 7943: foreach my $resource (@resources) {
1.691 raeburn 7944: my $resid = $resource->id();
1.672 raeburn 7945: my ($analysis,$parts) = &scantron_partids_tograde($resource,$cid,$uname,
7946: $udom,undef,$bubbles_per_row);
1.542 raeburn 7947: if ((ref($analysis) eq 'HASH') && (ref($parts) eq 'ARRAY')) {
7948: foreach my $part_id (@{$parts}) {
7949: my $lines;
7950:
7951: # TODO - make this a persistent hash not an array.
7952:
7953: # optionresponse, matchresponse and rankresponse type items
7954: # render as separate sub-questions in exam mode.
7955: if (($analysis->{$part_id.'.type'} eq 'optionresponse') ||
7956: ($analysis->{$part_id.'.type'} eq 'matchresponse') ||
7957: ($analysis->{$part_id.'.type'} eq 'rankresponse')) {
7958: my ($numbub,$numshown);
7959: if ($analysis->{$part_id.'.type'} eq 'optionresponse') {
7960: if (ref($analysis->{$part_id.'.options'}) eq 'ARRAY') {
7961: $numbub = scalar(@{$analysis->{$part_id.'.options'}});
7962: }
7963: } elsif ($analysis->{$part_id.'.type'} eq 'matchresponse') {
7964: if (ref($analysis->{$part_id.'.items'}) eq 'ARRAY') {
7965: $numbub = scalar(@{$analysis->{$part_id.'.items'}});
7966: }
7967: } elsif ($analysis->{$part_id.'.type'} eq 'rankresponse') {
7968: if (ref($analysis->{$part_id.'.foils'}) eq 'ARRAY') {
7969: $numbub = scalar(@{$analysis->{$part_id.'.foils'}});
7970: }
7971: }
7972: if (ref($analysis->{$part_id.'.shown'}) eq 'ARRAY') {
7973: $numshown = scalar(@{$analysis->{$part_id.'.shown'}});
7974: }
1.649 raeburn 7975: my $bubbles_per_row =
7976: &bubblesheet_bubbles_per_row($scantron_config);
7977: my $inner_bubble_lines = int($numbub/$bubbles_per_row);
7978: if (($numbub % $bubbles_per_row) != 0) {
1.542 raeburn 7979: $inner_bubble_lines++;
7980: }
7981: for (my $i=0; $i<$numshown; $i++) {
7982: $subdivided_bubble_lines{$response_number} .=
7983: $inner_bubble_lines.',';
7984: }
7985: $subdivided_bubble_lines{$response_number} =~ s/,$//;
7986: $lines = $numshown * $inner_bubble_lines;
7987: } else {
7988: $lines = $analysis->{"$part_id.bubble_lines"};
1.649 raeburn 7989: }
1.542 raeburn 7990:
7991: $first_bubble_line{$response_number} = $bubble_line;
7992: $bubble_lines_per_response{$response_number} = $lines;
7993: $responsetype_per_response{$response_number} =
7994: $analysis->{$part_id.'.type'};
1.691 raeburn 7995: $masterseq_id_responsenum{$resid.'_'.$part_id} = $response_number;
1.542 raeburn 7996: $response_number++;
7997:
7998: $bubble_line += $lines;
7999: $total_lines += $lines;
8000: }
8001: }
8002: }
1.552 raeburn 8003: &Apache::lonnet::delenv('scantron.');
1.542 raeburn 8004:
8005: &save_bubble_lines();
8006: $env{'form.scantron_maxbubble'} =
8007: $total_lines;
8008: return $env{'form.scantron_maxbubble'};
8009: }
1.523 raeburn 8010:
1.649 raeburn 8011: sub bubblesheet_bubbles_per_row {
8012: my ($scantron_config) = @_;
8013: my $bubbles_per_row;
8014: if (ref($scantron_config) eq 'HASH') {
8015: $bubbles_per_row = $scantron_config->{'BubblesPerRow'};
8016: }
8017: if ((!$bubbles_per_row) || ($bubbles_per_row < 1)) {
8018: $bubbles_per_row = 10;
8019: }
8020: return $bubbles_per_row;
8021: }
8022:
1.157 albertel 8023: sub scantron_validate_missingbubbles {
8024: my ($r,$currentphase) = @_;
8025: #get student info
8026: my $classlist=&Apache::loncoursedata::get_classlist();
8027: my %idmap=&username_to_idmap($classlist);
1.691 raeburn 8028: my (undef,undef,$sequence)=
8029: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.157 albertel 8030:
8031: #get scantron line setup
1.257 albertel 8032: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 8033: my ($scanlines,$scan_data)=&scantron_getfile();
1.691 raeburn 8034:
8035: my $navmap = Apache::lonnavmaps::navmap->new();
8036: unless (ref($navmap)) {
8037: $r->print(&navmap_errormsg());
8038: return(1,$currentphase);
8039: }
8040:
8041: my $map=$navmap->getResourceByUrl($sequence);
8042: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
8043: my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
8044: %grader_randomlists_by_symb,%orderedforcode,%respnumlookup,%startline);
8045: my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
8046:
1.582 raeburn 8047: my $nav_error;
1.691 raeburn 8048: if (ref($map)) {
8049: $randomorder = $map->randomorder();
8050: $randompick = $map->randompick();
8051: if ($randomorder || $randompick) {
8052: $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource);
8053: if ($nav_error) {
8054: $r->print(&navmap_errormsg());
8055: return(1,$currentphase);
8056: }
8057: &graders_resources_pass(\@resources,\%grader_partids_by_symb,
8058: \%grader_randomlists_by_symb,$bubbles_per_row);
8059: }
8060: } else {
8061: $r->print(&navmap_errormsg());
8062: return(1,$currentphase);
8063: }
8064:
8065:
1.649 raeburn 8066: my $max_bubble=&scantron_get_maxbubble(\$nav_error,\%scantron_config);
1.582 raeburn 8067: if ($nav_error) {
1.691 raeburn 8068: $r->print(&navmap_errormsg());
1.693 raeburn 8069: return(1,$currentphase);
1.582 raeburn 8070: }
1.691 raeburn 8071:
1.157 albertel 8072: if (!$max_bubble) { $max_bubble=2**31; }
8073: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 8074: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 8075: if ($line=~/^[\s\cz]*$/) { next; }
1.691 raeburn 8076: my $scan_record =
8077: &scantron_parse_scanline($line,$i,\%scantron_config,$scan_data,undef,\%idmap,
8078: $randomorder,$randompick,$sequence,\@master_seq,
8079: \%symb_to_resource,\%grader_partids_by_symb,
8080: \%orderedforcode,\%respnumlookup,\%startline);
1.157 albertel 8081: if (!defined($$scan_record{'scantron.missingerror'})) { next; }
8082: my @to_correct;
1.470 foxr 8083:
8084: # Probably here's where the error is...
8085:
1.157 albertel 8086: foreach my $missing (@{$$scan_record{'scantron.missingerror'}}) {
1.505 raeburn 8087: my $lastbubble;
8088: if ($missing =~ /^(\d+)\.(\d+)$/) {
8089: my $question = $1;
8090: my $subquestion = $2;
1.691 raeburn 8091: my ($first,$responsenum);
8092: if ($randomorder || $randompick) {
8093: $responsenum = $respnumlookup{$question-1};
8094: $first = $startline{$question-1};
8095: } else {
8096: $responsenum = $question-1;
8097: $first = $first_bubble_line{$responsenum};
8098: }
8099: if (!defined($first)) { next; }
8100: my @subans = split(/,/,$subdivided_bubble_lines{$responsenum});
1.505 raeburn 8101: my $subcount = 1;
8102: while ($subcount<$subquestion) {
8103: $first += $subans[$subcount-1];
8104: $subcount ++;
8105: }
8106: my $count = $subans[$subquestion-1];
8107: $lastbubble = $first + $count;
8108: } else {
1.691 raeburn 8109: my ($first,$responsenum);
8110: if ($randomorder || $randompick) {
8111: $responsenum = $respnumlookup{$missing-1};
8112: $first = $startline{$missing-1};
8113: } else {
8114: $responsenum = $missing-1;
8115: $first = $first_bubble_line{$responsenum};
8116: }
8117: if (!defined($first)) { next; }
8118: $lastbubble = $first + $bubble_lines_per_response{$responsenum};
1.505 raeburn 8119: }
8120: if ($lastbubble > $max_bubble) { next; }
1.157 albertel 8121: push(@to_correct,$missing);
8122: }
8123: if (@to_correct) {
8124: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
1.691 raeburn 8125: $line,'missingbubble',\@to_correct,
8126: $randomorder,$randompick,\%respnumlookup,
8127: \%startline);
1.157 albertel 8128: return (1,$currentphase);
8129: }
8130:
8131: }
8132: return (0,$currentphase+1);
8133: }
8134:
1.663 raeburn 8135: sub hand_bubble_option {
8136: my (undef, undef, $sequence) =
8137: &Apache::lonnet::decode_symb($env{'form.selectpage'});
8138: return if ($sequence eq '');
8139: my $navmap = Apache::lonnavmaps::navmap->new();
8140: unless (ref($navmap)) {
8141: return;
8142: }
8143: my $needs_hand_bubbles;
8144: my $map=$navmap->getResourceByUrl($sequence);
8145: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
8146: foreach my $res (@resources) {
8147: if (ref($res)) {
8148: if ($res->is_problem()) {
8149: my $partlist = $res->parts();
8150: foreach my $part (@{ $partlist }) {
8151: my @types = $res->responseType($part);
8152: if (grep(/^(chem|essay|image|formula|math|string|functionplot)$/,@types)) {
8153: $needs_hand_bubbles = 1;
8154: last;
8155: }
8156: }
8157: }
8158: }
8159: }
8160: if ($needs_hand_bubbles) {
8161: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
8162: my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
8163: return &mt('The sequence to be graded contains response types which are handgraded.').'<p>'.
8164: &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 />').
8165: '<label><input type="radio" name="scantron_lastbubblepoints" value="'.$bubbles_per_row.'" checked="checked" />'.&mt('[quant,_1,point]',$bubbles_per_row).'</label> '.&mt('or').' '.
8166: '<label><input type="radio" name="scantron_lastbubblepoints" value="0"/>0 points</label></p>';
8167: }
8168: return;
8169: }
1.423 albertel 8170:
1.82 albertel 8171: sub scantron_process_students {
1.608 www 8172: my ($r,$symb) = @_;
1.513 foxr 8173:
1.257 albertel 8174: my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($env{'form.selectpage'});
1.513 foxr 8175: if (!$symb) {
8176: return '';
8177: }
1.324 albertel 8178: my $default_form_data=&defaultFormData($symb);
1.82 albertel 8179:
1.257 albertel 8180: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.691 raeburn 8181: my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
1.157 albertel 8182: my ($scanlines,$scan_data)=&scantron_getfile();
1.82 albertel 8183: my $classlist=&Apache::loncoursedata::get_classlist();
8184: my %idmap=&username_to_idmap($classlist);
1.132 bowersj2 8185: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 8186: unless (ref($navmap)) {
8187: $r->print(&navmap_errormsg());
8188: return '';
1.691 raeburn 8189: }
1.83 albertel 8190: my $map=$navmap->getResourceByUrl($sequence);
1.691 raeburn 8191: my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
1.693 raeburn 8192: %grader_randomlists_by_symb);
1.677 raeburn 8193: if (ref($map)) {
8194: $randomorder = $map->randomorder();
1.689 raeburn 8195: $randompick = $map->randompick();
1.691 raeburn 8196: } else {
8197: $r->print(&navmap_errormsg());
8198: return '';
1.677 raeburn 8199: }
1.691 raeburn 8200: my $nav_error;
1.83 albertel 8201: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.691 raeburn 8202: if ($randomorder || $randompick) {
8203: $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource);
8204: if ($nav_error) {
8205: $r->print(&navmap_errormsg());
8206: return '';
8207: }
8208: }
1.557 raeburn 8209: &graders_resources_pass(\@resources,\%grader_partids_by_symb,
1.649 raeburn 8210: \%grader_randomlists_by_symb,$bubbles_per_row);
1.557 raeburn 8211:
1.554 raeburn 8212: my ($uname,$udom);
1.82 albertel 8213: my $result= <<SCANTRONFORM;
1.81 albertel 8214: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
8215: <input type="hidden" name="command" value="scantron_configphase" />
8216: $default_form_data
8217: SCANTRONFORM
1.82 albertel 8218: $r->print($result);
8219:
8220: my @delayqueue;
1.542 raeburn 8221: my (%completedstudents,%scandata);
1.140 albertel 8222:
1.520 www 8223: my $lock=&Apache::lonnet::set_lock(&mt('Grading bubblesheet exam'));
1.200 albertel 8224: my $count=&get_todo_count($scanlines,$scan_data);
1.667 www 8225: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$count);
8226: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,'Processing first student');
1.542 raeburn 8227: $r->print('<br />');
1.140 albertel 8228: my $start=&Time::HiRes::time();
1.158 albertel 8229: my $i=-1;
1.542 raeburn 8230: my $started;
1.447 foxr 8231:
1.649 raeburn 8232: &scantron_get_maxbubble(\$nav_error,\%scantron_config); # Need the bubble lines array to parse.
1.582 raeburn 8233: if ($nav_error) {
8234: $r->print(&navmap_errormsg());
8235: return '';
8236: }
8237:
1.513 foxr 8238: # If an ssi failed in scantron_get_maxbubble, put an error message out to
8239: # the user and return.
8240:
8241: if ($ssi_error) {
8242: $r->print("</form>");
8243: &ssi_print_error($r);
1.520 www 8244: &Apache::lonnet::remove_lock($lock);
1.513 foxr 8245: return ''; # Dunno why the other returns return '' rather than just returning.
8246: }
1.447 foxr 8247:
1.542 raeburn 8248: my %lettdig = &letter_to_digits();
8249: my $numletts = scalar(keys(%lettdig));
1.691 raeburn 8250: my %orderedforcode;
1.542 raeburn 8251:
1.157 albertel 8252: while ($i<$scanlines->{'count'}) {
8253: ($uname,$udom)=('','');
8254: $i++;
1.200 albertel 8255: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 8256: if ($line=~/^[\s\cz]*$/) { next; }
1.200 albertel 8257: if ($started) {
1.667 www 8258: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student');
1.200 albertel 8259: }
8260: $started=1;
1.691 raeburn 8261: my %respnumlookup = ();
8262: my %startline = ();
8263: my $total;
1.157 albertel 8264: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
1.691 raeburn 8265: $scan_data,undef,\%idmap,$randomorder,
8266: $randompick,$sequence,\@master_seq,
8267: \%symb_to_resource,\%grader_partids_by_symb,
8268: \%orderedforcode,\%respnumlookup,\%startline,
8269: \$total);
1.157 albertel 8270: unless ($uname=&scantron_find_student($scan_record,$scan_data,
8271: \%idmap,$i)) {
8272: &scantron_add_delay(\@delayqueue,$line,
8273: 'Unable to find a student that matches',1);
8274: next;
8275: }
8276: if (exists $completedstudents{$uname}) {
8277: &scantron_add_delay(\@delayqueue,$line,
8278: 'Student '.$uname.' has multiple sheets',2);
8279: next;
8280: }
1.677 raeburn 8281: my $usec = $classlist->{$uname}->[&Apache::loncoursedata::CL_SECTION];
8282: my $user = $uname.':'.$usec;
1.157 albertel 8283: ($uname,$udom)=split(/:/,$uname);
1.330 albertel 8284:
1.677 raeburn 8285: my $scancode;
8286: if ((exists($scan_record->{'scantron.CODE'})) &&
8287: (&Apache::lonnet::validCODE($scan_record->{'scantron.CODE'}))) {
8288: $scancode = $scan_record->{'scantron.CODE'};
8289: } else {
8290: $scancode = '';
8291: }
8292:
8293: my @mapresources = @resources;
1.689 raeburn 8294: if ($randomorder || $randompick) {
1.678 raeburn 8295: @mapresources =
1.691 raeburn 8296: &users_order($user,$scancode,$sequence,\@master_seq,\%symb_to_resource,
8297: \%orderedforcode);
1.677 raeburn 8298: }
1.586 raeburn 8299: my (%partids_by_symb,$res_error);
1.677 raeburn 8300: foreach my $resource (@mapresources) {
1.586 raeburn 8301: my $ressymb;
8302: if (ref($resource)) {
8303: $ressymb = $resource->symb();
8304: } else {
8305: $res_error = 1;
8306: last;
8307: }
1.557 raeburn 8308: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
8309: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
8310: my ($analysis,$parts) =
1.672 raeburn 8311: &scantron_partids_tograde($resource,$env{'request.course.id'},
8312: $uname,$udom,undef,$bubbles_per_row);
1.557 raeburn 8313: $partids_by_symb{$ressymb} = $parts;
8314: } else {
8315: $partids_by_symb{$ressymb} = $grader_partids_by_symb{$ressymb};
8316: }
1.554 raeburn 8317: }
8318:
1.586 raeburn 8319: if ($res_error) {
8320: &scantron_add_delay(\@delayqueue,$line,
8321: 'An error occurred while grading student '.$uname,2);
8322: next;
8323: }
8324:
1.330 albertel 8325: &Apache::lonxml::clear_problem_counter();
1.514 raeburn 8326: &Apache::lonnet::appenv($scan_record);
1.376 albertel 8327:
8328: if (&scantron_clear_skip($scanlines,$scan_data,$i)) {
8329: &scantron_putfile($scanlines,$scan_data);
8330: }
1.161 albertel 8331:
1.542 raeburn 8332: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
1.677 raeburn 8333: \@mapresources,\%partids_by_symb,
1.691 raeburn 8334: $bubbles_per_row,$randomorder,$randompick,
8335: \%respnumlookup,\%startline)
8336: eq 'ssi_error') {
1.542 raeburn 8337: $ssi_error = 0; # So end of handler error message does not trigger.
8338: $r->print("</form>");
8339: &ssi_print_error($r);
8340: &Apache::lonnet::remove_lock($lock);
8341: return ''; # Why return ''? Beats me.
8342: }
1.513 foxr 8343:
1.692 raeburn 8344: if (($scancode) && ($randomorder || $randompick)) {
8345: my $parmresult =
8346: &Apache::lonparmset::storeparm_by_symb($symb,
8347: '0_examcode',2,$scancode,
8348: 'string_examcode',$uname,
8349: $udom);
8350: }
1.140 albertel 8351: $completedstudents{$uname}={'line'=>$line};
1.542 raeburn 8352: if ($env{'form.verifyrecord'}) {
8353: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
1.691 raeburn 8354: if ($randompick) {
8355: if ($total) {
8356: $lastpos = $total*$scantron_config{'Qlength'};
8357: }
8358: }
8359:
1.542 raeburn 8360: my $studentdata = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
8361: chomp($studentdata);
8362: $studentdata =~ s/\r$//;
8363: my $studentrecord = '';
8364: my $counter = -1;
1.677 raeburn 8365: foreach my $resource (@mapresources) {
1.554 raeburn 8366: my $ressymb = $resource->symb();
1.542 raeburn 8367: ($counter,my $recording) =
8368: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 8369: $counter,$studentdata,$partids_by_symb{$ressymb},
1.691 raeburn 8370: \%scantron_config,\%lettdig,$numletts,$randomorder,
8371: $randompick,\%respnumlookup,\%startline);
1.542 raeburn 8372: $studentrecord .= $recording;
8373: }
8374: if ($studentrecord ne $studentdata) {
1.554 raeburn 8375: &Apache::lonxml::clear_problem_counter();
8376: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
1.677 raeburn 8377: \@mapresources,\%partids_by_symb,
1.691 raeburn 8378: $bubbles_per_row,$randomorder,$randompick,
8379: \%respnumlookup,\%startline)
8380: eq 'ssi_error') {
1.554 raeburn 8381: $ssi_error = 0; # So end of handler error message does not trigger.
8382: $r->print("</form>");
8383: &ssi_print_error($r);
8384: &Apache::lonnet::remove_lock($lock);
8385: delete($completedstudents{$uname});
8386: return '';
8387: }
1.542 raeburn 8388: $counter = -1;
8389: $studentrecord = '';
1.677 raeburn 8390: foreach my $resource (@mapresources) {
1.554 raeburn 8391: my $ressymb = $resource->symb();
1.542 raeburn 8392: ($counter,my $recording) =
8393: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 8394: $counter,$studentdata,$partids_by_symb{$ressymb},
1.691 raeburn 8395: \%scantron_config,\%lettdig,$numletts,
8396: $randomorder,$randompick,\%respnumlookup,
8397: \%startline);
1.542 raeburn 8398: $studentrecord .= $recording;
8399: }
8400: if ($studentrecord ne $studentdata) {
1.658 bisitz 8401: $r->print('<p><span class="LC_warning">');
1.542 raeburn 8402: if ($scancode eq '') {
1.658 bisitz 8403: $r->print(&mt('Mismatch grading bubblesheet for user: [_1] with ID: [_2].',
1.542 raeburn 8404: $uname.':'.$udom,$scan_record->{'scantron.ID'}));
8405: } else {
1.658 bisitz 8406: $r->print(&mt('Mismatch grading bubblesheet for user: [_1] with ID: [_2] and CODE: [_3].',
1.542 raeburn 8407: $uname.':'.$udom,$scan_record->{'scantron.ID'},$scancode));
8408: }
8409: $r->print('</span><br />'.&Apache::loncommon::start_data_table()."\n".
8410: &Apache::loncommon::start_data_table_header_row()."\n".
8411: '<th>'.&mt('Source').'</th><th>'.&mt('Bubbled responses').'</th>'.
8412: &Apache::loncommon::end_data_table_header_row()."\n".
8413: &Apache::loncommon::start_data_table_row().
1.658 bisitz 8414: '<td>'.&mt('Bubblesheet').'</td>'.
8415: '<td><span class="LC_nobreak"><tt>'.$studentdata.'</tt></span></td>'.
1.542 raeburn 8416: &Apache::loncommon::end_data_table_row().
8417: &Apache::loncommon::start_data_table_row().
1.658 bisitz 8418: '<td>'.&mt('Stored submissions').'</td>'.
8419: '<td><span class="LC_nobreak"><tt>'.$studentrecord.'</tt></span></td>'."\n".
1.542 raeburn 8420: &Apache::loncommon::end_data_table_row().
8421: &Apache::loncommon::end_data_table().'</p>');
8422: } else {
8423: $r->print('<br /><span class="LC_warning">'.
8424: &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 />'.
8425: &mt("As a consequence, this user's submission history records two tries.").
8426: '</span><br />');
8427: }
8428: }
8429: }
1.543 raeburn 8430: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.140 albertel 8431: } continue {
1.330 albertel 8432: &Apache::lonxml::clear_problem_counter();
1.552 raeburn 8433: &Apache::lonnet::delenv('scantron.');
1.82 albertel 8434: }
1.140 albertel 8435: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.520 www 8436: &Apache::lonnet::remove_lock($lock);
1.172 albertel 8437: # my $lasttime = &Time::HiRes::time()-$start;
8438: # $r->print("<p>took $lasttime</p>");
1.140 albertel 8439:
1.200 albertel 8440: $r->print("</form>");
1.157 albertel 8441: return '';
1.75 albertel 8442: }
1.157 albertel 8443:
1.557 raeburn 8444: sub graders_resources_pass {
1.649 raeburn 8445: my ($resources,$grader_partids_by_symb,$grader_randomlists_by_symb,
8446: $bubbles_per_row) = @_;
1.557 raeburn 8447: if ((ref($resources) eq 'ARRAY') && (ref($grader_partids_by_symb)) &&
8448: (ref($grader_randomlists_by_symb) eq 'HASH')) {
8449: foreach my $resource (@{$resources}) {
8450: my $ressymb = $resource->symb();
8451: my ($analysis,$parts) =
8452: &scantron_partids_tograde($resource,$env{'request.course.id'},
1.672 raeburn 8453: $env{'user.name'},$env{'user.domain'},
8454: 1,$bubbles_per_row);
1.557 raeburn 8455: $grader_partids_by_symb->{$ressymb} = $parts;
8456: if (ref($analysis) eq 'HASH') {
8457: if (ref($analysis->{'parts_withrandomlist'}) eq 'ARRAY') {
8458: $grader_randomlists_by_symb->{$ressymb} =
8459: $analysis->{'parts_withrandomlist'};
8460: }
8461: }
8462: }
8463: }
8464: return;
8465: }
8466:
1.678 raeburn 8467: =pod
8468:
8469: =item users_order
8470:
8471: Returns array of resources in current map, ordered based on either CODE,
8472: if this is a CODEd exam, or based on student's identity if this is a
8473: "NAMEd" exam.
8474:
1.691 raeburn 8475: Should be used when randomorder and/or randompick applied when the
8476: corresponding exam was printed, prior to students completing bubblesheets
8477: for the version of the exam the student received.
1.678 raeburn 8478:
8479: =cut
8480:
8481: sub users_order {
1.691 raeburn 8482: my ($user,$scancode,$mapurl,$master_seq,$symb_to_resource,$orderedforcode) = @_;
1.678 raeburn 8483: my @mapresources;
1.691 raeburn 8484: unless ((ref($master_seq) eq 'ARRAY') && (ref($symb_to_resource) eq 'HASH')) {
1.678 raeburn 8485: return @mapresources;
1.691 raeburn 8486: }
8487: if ($scancode) {
8488: if ((ref($orderedforcode) eq 'HASH') && (ref($orderedforcode->{$scancode}) eq 'ARRAY')) {
8489: @mapresources = @{$orderedforcode->{$scancode}};
8490: } else {
8491: $env{'form.CODE'} = $scancode;
8492: my $actual_seq =
8493: &Apache::lonprintout::master_seq_to_person_seq($mapurl,
8494: $master_seq,
8495: $user,$scancode,1);
8496: if (ref($actual_seq) eq 'ARRAY') {
8497: @mapresources = map { $symb_to_resource->{$_}; } @{$actual_seq};
8498: if (ref($orderedforcode) eq 'HASH') {
8499: if (@mapresources > 0) {
8500: $orderedforcode->{$scancode} = \@mapresources;
8501: }
8502: }
8503: }
8504: delete($env{'form.CODE'});
1.678 raeburn 8505: }
8506: } else {
8507: my $actual_seq =
8508: &Apache::lonprintout::master_seq_to_person_seq($mapurl,
8509: $master_seq,
1.688 raeburn 8510: $user,undef,1);
1.678 raeburn 8511: if (ref($actual_seq) eq 'ARRAY') {
8512: @mapresources =
8513: map { $symb_to_resource->{$_}; } @{$actual_seq};
8514: }
1.691 raeburn 8515: }
8516: return @mapresources;
1.678 raeburn 8517: }
8518:
1.542 raeburn 8519: sub grade_student_bubbles {
1.691 raeburn 8520: my ($r,$uname,$udom,$scan_record,$scancode,$resources,$parts,$bubbles_per_row,
8521: $randomorder,$randompick,$respnumlookup,$startline) = @_;
8522: my $uselookup = 0;
8523: if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH') &&
8524: (ref($startline) eq 'HASH')) {
8525: $uselookup = 1;
8526: }
8527:
1.554 raeburn 8528: if (ref($resources) eq 'ARRAY') {
8529: my $count = 0;
8530: foreach my $resource (@{$resources}) {
8531: my $ressymb = $resource->symb();
8532: my %form = ('submitted' => 'scantron',
8533: 'grade_target' => 'grade',
8534: 'grade_username' => $uname,
8535: 'grade_domain' => $udom,
8536: 'grade_courseid' => $env{'request.course.id'},
8537: 'grade_symb' => $ressymb,
8538: 'CODE' => $scancode
8539: );
1.649 raeburn 8540: if ($bubbles_per_row ne '') {
8541: $form{'bubbles_per_row'} = $bubbles_per_row;
8542: }
1.663 raeburn 8543: if ($env{'form.scantron_lastbubblepoints'} ne '') {
8544: $form{'scantron_lastbubblepoints'} = $env{'form.scantron_lastbubblepoints'};
8545: }
1.554 raeburn 8546: if (ref($parts) eq 'HASH') {
8547: if (ref($parts->{$ressymb}) eq 'ARRAY') {
8548: foreach my $part (@{$parts->{$ressymb}}) {
1.691 raeburn 8549: if ($uselookup) {
8550: $form{'scantron_questnum_start.'.$part} = $startline->{$count} + 1;
8551: } else {
8552: $form{'scantron_questnum_start.'.$part} =
8553: 1+$env{'form.scantron.first_bubble_line.'.$count};
8554: }
1.554 raeburn 8555: $count++;
8556: }
8557: }
8558: }
8559: my $result=&ssi_with_retries($resource->src(),$ssi_retries,%form);
8560: return 'ssi_error' if ($ssi_error);
8561: last if (&Apache::loncommon::connection_aborted($r));
8562: }
1.542 raeburn 8563: }
8564: return;
8565: }
8566:
1.157 albertel 8567: sub scantron_upload_scantron_data {
1.608 www 8568: my ($r,$symb)=@_;
1.565 raeburn 8569: my $dom = $env{'request.role.domain'};
8570: my $domdesc = &Apache::lonnet::domain($dom,'description');
8571: $r->print(&Apache::loncommon::coursebrowser_javascript($dom));
1.157 albertel 8572: my $select_link=&Apache::loncommon::selectcourse_link('rules','courseid',
1.181 albertel 8573: 'domainid',
1.565 raeburn 8574: 'coursename',$dom);
8575: my $syllabuslink = '<a href="javascript:ToSyllabus();">'.&mt('Syllabus').'</a>'.
8576: (' 'x2).&mt('(shows course personnel)');
1.608 www 8577: my $default_form_data=&defaultFormData($symb);
1.579 raeburn 8578: my $nofile_alert = &mt('Please use the browse button to select a file from your local directory.');
8579: 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.597 wenzelju 8580: $r->print(&Apache::lonhtmlcommon::scripttag('
1.157 albertel 8581: function checkUpload(formname) {
8582: if (formname.upfile.value == "") {
1.579 raeburn 8583: alert("'.$nofile_alert.'");
1.157 albertel 8584: return false;
8585: }
1.565 raeburn 8586: if (formname.courseid.value == "") {
1.579 raeburn 8587: alert("'.$nocourseid_alert.'");
1.565 raeburn 8588: return false;
8589: }
1.157 albertel 8590: formname.submit();
8591: }
1.565 raeburn 8592:
8593: function ToSyllabus() {
8594: var cdom = '."'$dom'".';
8595: var cnum = document.rules.courseid.value;
8596: if (cdom == "" || cdom == null) {
8597: return;
8598: }
8599: if (cnum == "" || cnum == null) {
8600: return;
8601: }
8602: syllwin=window.open("/public/"+cdom+"/"+cnum+"/syllabus","LONCAPASyllabus",
8603: "height=350,width=350,scrollbars=yes,menubar=no");
8604: return;
8605: }
8606:
1.597 wenzelju 8607: '));
8608: $r->print('
1.648 bisitz 8609: <h3>'.&mt('Send bubblesheet data to a course').'</h3>
1.566 raeburn 8610:
1.492 albertel 8611: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
1.565 raeburn 8612: '.$default_form_data.
8613: &Apache::lonhtmlcommon::start_pick_box().
8614: &Apache::lonhtmlcommon::row_title(&mt('Course ID')).
8615: '<input name="courseid" type="text" size="30" />'.$select_link.
8616: &Apache::lonhtmlcommon::row_closure().
8617: &Apache::lonhtmlcommon::row_title(&mt('Course Name')).
8618: '<input name="coursename" type="text" size="30" />'.$syllabuslink.
8619: &Apache::lonhtmlcommon::row_closure().
8620: &Apache::lonhtmlcommon::row_title(&mt('Domain')).
8621: '<input name="domainid" type="hidden" />'.$domdesc.
8622: &Apache::lonhtmlcommon::row_closure().
8623: &Apache::lonhtmlcommon::row_title(&mt('File to upload')).
8624: '<input type="file" name="upfile" size="50" />'.
8625: &Apache::lonhtmlcommon::row_closure(1).
8626: &Apache::lonhtmlcommon::end_pick_box().'<br />
8627:
1.492 albertel 8628: <input name="command" value="scantronupload_save" type="hidden" />
1.589 bisitz 8629: <input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
1.157 albertel 8630: </form>
1.492 albertel 8631: ');
1.157 albertel 8632: return '';
8633: }
8634:
1.423 albertel 8635:
1.157 albertel 8636: sub scantron_upload_scantron_data_save {
1.608 www 8637: my($r,$symb)=@_;
1.182 albertel 8638: my $doanotherupload=
8639: '<br /><form action="/adm/grades" method="post">'."\n".
8640: '<input type="hidden" name="command" value="scantronupload" />'."\n".
1.492 albertel 8641: '<input type="submit" name="submit" value="'.&mt('Do Another Upload').'" />'."\n".
1.182 albertel 8642: '</form>'."\n";
1.257 albertel 8643: if (!&Apache::lonnet::allowed('usc',$env{'form.domainid'}) &&
1.162 albertel 8644: !&Apache::lonnet::allowed('usc',
1.257 albertel 8645: $env{'form.domainid'}.'_'.$env{'form.courseid'})) {
1.575 www 8646: $r->print(&mt("You are not allowed to upload bubblesheet data to the requested course.")."<br />");
1.614 www 8647: unless ($symb) {
1.182 albertel 8648: $r->print($doanotherupload);
8649: }
1.162 albertel 8650: return '';
8651: }
1.257 albertel 8652: my %coursedata=&Apache::lonnet::coursedescription($env{'form.domainid'}.'_'.$env{'form.courseid'});
1.568 raeburn 8653: my $uploadedfile;
1.567 raeburn 8654: $r->print('<h3>'.&mt("Uploading file to [_1]",$coursedata{'description'}).'</h3>');
1.257 albertel 8655: if (length($env{'form.upfile'}) < 2) {
1.568 raeburn 8656: $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 8657: } else {
1.568 raeburn 8658: my $result =
8659: &Apache::lonnet::userfileupload('upfile','','scantron','','','',
8660: $env{'form.courseid'},$env{'form.domainid'});
8661: if ($result =~ m{^/uploaded/}) {
1.567 raeburn 8662: $r->print(&mt('[_1]Success:[_2] Successfully uploaded [_3] bytes of data into location: [_4]',
8663: '<span class="LC_success">','</span>',(length($env{'form.upfile'})-1),
8664: '<span class="LC_filename">'.$result.'</span>'));
1.568 raeburn 8665: ($uploadedfile) = ($result =~ m{/([^/]+)$});
1.567 raeburn 8666: $r->print(&validate_uploaded_scantron_file($env{'form.domainid'},
1.568 raeburn 8667: $env{'form.courseid'},$uploadedfile));
1.210 albertel 8668: } else {
1.567 raeburn 8669: $r->print(&mt('[_1]Error:[_2] An error ([_3]) occurred when attempting to upload the file, [_4]',
8670: '<span class="LC_error">','</span>',$result,
1.568 raeburn 8671: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'));
1.183 albertel 8672: }
8673: }
1.174 albertel 8674: if ($symb) {
1.612 www 8675: $r->print(&scantron_selectphase($r,$uploadedfile,$symb));
1.174 albertel 8676: } else {
1.182 albertel 8677: $r->print($doanotherupload);
1.174 albertel 8678: }
1.157 albertel 8679: return '';
8680: }
8681:
1.567 raeburn 8682: sub validate_uploaded_scantron_file {
8683: my ($cdom,$cname,$fname) = @_;
8684: my $scanlines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.$fname);
8685: my @lines;
8686: if ($scanlines ne '-1') {
8687: @lines=split("\n",$scanlines,-1);
8688: }
8689: my $output;
8690: if (@lines) {
8691: my (%counts,$max_match_format);
8692: my ($max_match_count,$max_match_pct) = (0,0);
8693: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cname);
8694: my %idmap = &username_to_idmap($classlist);
8695: foreach my $key (keys(%idmap)) {
8696: my $lckey = lc($key);
8697: $idmap{$lckey} = $idmap{$key};
8698: }
8699: my %unique_formats;
8700: my @formatlines = &get_scantronformat_file();
8701: foreach my $line (@formatlines) {
8702: chomp($line);
8703: my @config = split(/:/,$line);
8704: my $idstart = $config[5];
8705: my $idlength = $config[6];
8706: if (($idstart ne '') && ($idlength > 0)) {
8707: if (ref($unique_formats{$idstart.':'.$idlength}) eq 'ARRAY') {
8708: push(@{$unique_formats{$idstart.':'.$idlength}},$config[0].':'.$config[1]);
8709: } else {
8710: $unique_formats{$idstart.':'.$idlength} = [$config[0].':'.$config[1]];
8711: }
8712: }
8713: }
8714: foreach my $key (keys(%unique_formats)) {
8715: my ($idstart,$idlength) = split(':',$key);
8716: %{$counts{$key}} = (
8717: 'found' => 0,
8718: 'total' => 0,
8719: );
8720: foreach my $line (@lines) {
8721: next if ($line =~ /^#/);
8722: next if ($line =~ /^[\s\cz]*$/);
8723: my $id = substr($line,$idstart-1,$idlength);
8724: $id = lc($id);
8725: if (exists($idmap{$id})) {
8726: $counts{$key}{'found'} ++;
8727: }
8728: $counts{$key}{'total'} ++;
8729: }
8730: if ($counts{$key}{'total'}) {
8731: my $percent_match = (100*$counts{$key}{'found'})/($counts{$key}{'total'});
8732: if (($max_match_format eq '') || ($percent_match > $max_match_pct)) {
8733: $max_match_pct = $percent_match;
8734: $max_match_format = $key;
8735: $max_match_count = $counts{$key}{'total'};
8736: }
8737: }
8738: }
8739: if (ref($unique_formats{$max_match_format}) eq 'ARRAY') {
8740: my $format_descs;
8741: my $numwithformat = @{$unique_formats{$max_match_format}};
8742: for (my $i=0; $i<$numwithformat; $i++) {
8743: my ($name,$desc) = split(':',$unique_formats{$max_match_format}[$i]);
8744: if ($i<$numwithformat-2) {
8745: $format_descs .= '"<i>'.$desc.'</i>", ';
8746: } elsif ($i==$numwithformat-2) {
8747: $format_descs .= '"<i>'.$desc.'</i>" '.&mt('and').' ';
8748: } elsif ($i==$numwithformat-1) {
8749: $format_descs .= '"<i>'.$desc.'</i>"';
8750: }
8751: }
8752: my $showpct = sprintf("%.0f",$max_match_pct).'%';
8753: $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).
8754: '<br />'.&mt('A low percentage of matches results from one of the following:').'<ul>'.
8755: '<li>'.&mt('The file was uploaded to the wrong course').'</li>'.
8756: '<li>'.&mt('The data are not in the format expected for the domain: [_1]',
8757: '<i>'.$cdom.'</i>').'</li>'.
8758: '<li>'.&mt('Students did not bubble their IDs, or mis-bubbled them').'</li>'.
8759: '<li>'.&mt('The course roster is not up to date').'</li>'.
8760: '</ul>';
8761: }
8762: } else {
8763: $output = '<span class="LC_warning">'.&mt('Uploaded file contained no data').'</span>';
8764: }
8765: return $output;
8766: }
8767:
1.202 albertel 8768: sub valid_file {
8769: my ($requested_file)=@_;
8770: foreach my $filename (sort(&scantron_filenames())) {
8771: if ($requested_file eq $filename) { return 1; }
8772: }
8773: return 0;
8774: }
8775:
8776: sub scantron_download_scantron_data {
1.608 www 8777: my ($r,$symb)=@_;
8778: my $default_form_data=&defaultFormData($symb);
1.257 albertel 8779: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
8780: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
8781: my $file=$env{'form.scantron_selectfile'};
1.202 albertel 8782: if (! &valid_file($file)) {
1.492 albertel 8783: $r->print('
1.202 albertel 8784: <p>
1.686 bisitz 8785: '.&mt('The requested filename was invalid.').'
1.202 albertel 8786: </p>
1.492 albertel 8787: ');
1.202 albertel 8788: return;
8789: }
8790: my $orig='/uploaded/'.$cdom.'/'.$cname.'/scantron_orig_'.$file;
8791: my $corrected='/uploaded/'.$cdom.'/'.$cname.'/scantron_corrected_'.$file;
8792: my $skipped='/uploaded/'.$cdom.'/'.$cname.'/scantron_skipped_'.$file;
8793: &Apache::lonnet::allowuploaded('/adm/grades',$orig);
8794: &Apache::lonnet::allowuploaded('/adm/grades',$corrected);
8795: &Apache::lonnet::allowuploaded('/adm/grades',$skipped);
1.492 albertel 8796: $r->print('
1.202 albertel 8797: <p>
1.492 albertel 8798: '.&mt('[_1]Original[_2] file as uploaded by the scantron office.',
8799: '<a href="'.$orig.'">','</a>').'
1.202 albertel 8800: </p>
8801: <p>
1.492 albertel 8802: '.&mt('[_1]Corrections[_2], a file of corrected records that were used in grading.',
8803: '<a href="'.$corrected.'">','</a>').'
1.202 albertel 8804: </p>
8805: <p>
1.492 albertel 8806: '.&mt('[_1]Skipped[_2], a file of records that were skipped.',
8807: '<a href="'.$skipped.'">','</a>').'
1.202 albertel 8808: </p>
1.492 albertel 8809: ');
1.202 albertel 8810: return '';
8811: }
1.157 albertel 8812:
1.523 raeburn 8813: sub checkscantron_results {
1.608 www 8814: my ($r,$symb) = @_;
1.523 raeburn 8815: if (!$symb) {return '';}
8816: my $cid = $env{'request.course.id'};
1.542 raeburn 8817: my %lettdig = &letter_to_digits();
1.523 raeburn 8818: my $numletts = scalar(keys(%lettdig));
8819: my $cnum = $env{'course.'.$cid.'.num'};
8820: my $cdom = $env{'course.'.$cid.'.domain'};
8821: my (undef, undef, $sequence) = &Apache::lonnet::decode_symb($env{'form.selectpage'});
8822: my %record;
8823: my %scantron_config =
8824: &Apache::grades::get_scantron_config($env{'form.scantron_format'});
1.649 raeburn 8825: my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
1.523 raeburn 8826: my ($scanlines,$scan_data)=&Apache::grades::scantron_getfile();
8827: my $classlist=&Apache::loncoursedata::get_classlist();
8828: my %idmap=&Apache::grades::username_to_idmap($classlist);
8829: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 8830: unless (ref($navmap)) {
8831: $r->print(&navmap_errormsg());
8832: return '';
8833: }
1.523 raeburn 8834: my $map=$navmap->getResourceByUrl($sequence);
1.691 raeburn 8835: my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
8836: %grader_randomlists_by_symb,%orderedforcode);
1.677 raeburn 8837: if (ref($map)) {
8838: $randomorder=$map->randomorder();
1.689 raeburn 8839: $randompick=$map->randompick();
1.677 raeburn 8840: }
1.557 raeburn 8841: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.691 raeburn 8842: my $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource);
8843: if ($nav_error) {
8844: $r->print(&navmap_errormsg());
8845: return '';
1.678 raeburn 8846: }
1.673 raeburn 8847: &graders_resources_pass(\@resources,\%grader_partids_by_symb,
8848: \%grader_randomlists_by_symb,$bubbles_per_row);
1.554 raeburn 8849: my ($uname,$udom);
1.523 raeburn 8850: my (%scandata,%lastname,%bylast);
8851: $r->print('
8852: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="checkscantron">'."\n");
8853:
8854: my @delayqueue;
8855: my %completedstudents;
8856:
1.691 raeburn 8857: my $count=&get_todo_count($scanlines,$scan_data);
1.667 www 8858: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$count);
1.678 raeburn 8859: my ($username,$domain,$started,%ordered);
1.649 raeburn 8860: &scantron_get_maxbubble(\$nav_error,\%scantron_config); # Need the bubble lines array to parse.
1.582 raeburn 8861: if ($nav_error) {
8862: $r->print(&navmap_errormsg());
8863: return '';
8864: }
1.523 raeburn 8865:
1.667 www 8866: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,'Processing first student');
1.523 raeburn 8867: my $start=&Time::HiRes::time();
8868: my $i=-1;
8869:
8870: while ($i<$scanlines->{'count'}) {
8871: ($username,$domain,$uname)=('','','');
8872: $i++;
8873: my $line=&Apache::grades::scantron_get_line($scanlines,$scan_data,$i);
8874: if ($line=~/^[\s\cz]*$/) { next; }
8875: if ($started) {
1.667 www 8876: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student');
1.523 raeburn 8877: }
8878: $started=1;
8879: my $scan_record=
8880: &Apache::grades::scantron_parse_scanline($line,$i,\%scantron_config,
8881: $scan_data);
1.693 raeburn 8882: unless ($uname=&scantron_find_student($scan_record,$scan_data,
8883: \%idmap,$i)) {
1.523 raeburn 8884: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
8885: 'Unable to find a student that matches',1);
8886: next;
8887: }
8888: if (exists $completedstudents{$uname}) {
8889: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
8890: 'Student '.$uname.' has multiple sheets',2);
8891: next;
8892: }
8893: my $pid = $scan_record->{'scantron.ID'};
8894: $lastname{$pid} = $scan_record->{'scantron.LastName'};
8895: push(@{$bylast{$lastname{$pid}}},$pid);
1.678 raeburn 8896: my $usec = $classlist->{$uname}->[&Apache::loncoursedata::CL_SECTION];
8897: my $user = $uname.':'.$usec;
1.523 raeburn 8898: ($username,$domain)=split(/:/,$uname);
1.677 raeburn 8899:
1.678 raeburn 8900: my $scancode;
1.677 raeburn 8901: if ((exists($scan_record->{'scantron.CODE'})) &&
8902: (&Apache::lonnet::validCODE($scan_record->{'scantron.CODE'}))) {
8903: $scancode = $scan_record->{'scantron.CODE'};
8904: } else {
8905: $scancode = '';
8906: }
8907:
8908: my @mapresources = @resources;
1.691 raeburn 8909: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
8910: my %respnumlookup=();
8911: my %startline=();
1.689 raeburn 8912: if ($randomorder || $randompick) {
1.678 raeburn 8913: @mapresources =
1.691 raeburn 8914: &users_order($user,$scancode,$sequence,\@master_seq,\%symb_to_resource,
8915: \%orderedforcode);
8916: my $total = &get_respnum_lookups($sequence,$scan_data,\%idmap,$line,
8917: $scan_record,\@master_seq,\%symb_to_resource,
8918: \%grader_partids_by_symb,\%orderedforcode,
8919: \%respnumlookup,\%startline);
8920: if ($randompick && $total) {
8921: $lastpos = $total*$scantron_config{'Qlength'};
8922: }
1.677 raeburn 8923: }
1.691 raeburn 8924: $scandata{$pid} = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
8925: chomp($scandata{$pid});
8926: $scandata{$pid} =~ s/\r$//;
8927:
1.523 raeburn 8928: my $counter = -1;
1.677 raeburn 8929: foreach my $resource (@mapresources) {
1.557 raeburn 8930: my $parts;
1.554 raeburn 8931: my $ressymb = $resource->symb();
1.557 raeburn 8932: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
8933: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
8934: (my $analysis,$parts) =
1.672 raeburn 8935: &scantron_partids_tograde($resource,$env{'request.course.id'},
8936: $username,$domain,undef,
8937: $bubbles_per_row);
1.557 raeburn 8938: } else {
8939: $parts = $grader_partids_by_symb{$ressymb};
8940: }
1.542 raeburn 8941: ($counter,my $recording) =
8942: &verify_scantron_grading($resource,$domain,$username,$cid,$counter,
1.554 raeburn 8943: $scandata{$pid},$parts,
1.691 raeburn 8944: \%scantron_config,\%lettdig,$numletts,
8945: $randomorder,$randompick,
8946: \%respnumlookup,\%startline);
1.542 raeburn 8947: $record{$pid} .= $recording;
1.523 raeburn 8948: }
8949: }
8950: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
8951: $r->print('<br />');
8952: my ($okstudents,$badstudents,$numstudents,$passed,$failed);
8953: $passed = 0;
8954: $failed = 0;
8955: $numstudents = 0;
8956: foreach my $last (sort(keys(%bylast))) {
8957: if (ref($bylast{$last}) eq 'ARRAY') {
8958: foreach my $pid (sort(@{$bylast{$last}})) {
8959: my $showscandata = $scandata{$pid};
8960: my $showrecord = $record{$pid};
8961: $showscandata =~ s/\s/ /g;
8962: $showrecord =~ s/\s/ /g;
8963: if ($scandata{$pid} eq $record{$pid}) {
8964: my $css_class = ($passed % 2)?'LC_odd_row':'LC_even_row';
8965: $okstudents .= '<tr class="'.$css_class.'">'.
1.581 www 8966: '<td>'.&mt('Bubblesheet').'</td><td>'.$showscandata.'</td><td rowspan="2">'.$last.'</td><td rowspan="2">'.$pid.'</td>'."\n".
1.523 raeburn 8967: '</tr>'."\n".
8968: '<tr class="'.$css_class.'">'."\n".
8969: '<td>Submissions</td><td>'.$showrecord.'</td></tr>'."\n";
8970: $passed ++;
8971: } else {
8972: my $css_class = ($failed % 2)?'LC_odd_row':'LC_even_row';
1.581 www 8973: $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 8974: '</tr>'."\n".
8975: '<tr class="'.$css_class.'">'."\n".
8976: '<td>Submissions</td><td><span class="LC_nobreak">'.$record{$pid}.'</span></td>'."\n".
8977: '</tr>'."\n";
8978: $failed ++;
8979: }
8980: $numstudents ++;
8981: }
8982: }
8983: }
1.648 bisitz 8984: $r->print(
8985: '<p>'
8986: .&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).',
8987: '<b>',
8988: $numstudents,
8989: '</b>',
8990: $env{'form.scantron_maxbubble'})
8991: .'</p>'
8992: );
1.682 raeburn 8993: $r->print('<p>'
1.683 raeburn 8994: .&mt('Exact matches for [_1][quant,_2,student][_3].','<b>',$passed,'</b>')
1.682 raeburn 8995: .'<br />'
8996: .&mt('Discrepancies detected for [_1][quant,_2,student][_3].','<b>',$failed,'</b>')
8997: .'</p>'
8998: );
1.523 raeburn 8999: if ($passed) {
1.572 www 9000: $r->print(&mt('Students with exact correspondence between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 9001: $r->print(&Apache::loncommon::start_data_table()."\n".
9002: &Apache::loncommon::start_data_table_header_row()."\n".
9003: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
9004: &Apache::loncommon::end_data_table_header_row()."\n".
9005: $okstudents."\n".
9006: &Apache::loncommon::end_data_table().'<br />');
9007: }
9008: if ($failed) {
1.572 www 9009: $r->print(&mt('Students with differences between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 9010: $r->print(&Apache::loncommon::start_data_table()."\n".
9011: &Apache::loncommon::start_data_table_header_row()."\n".
9012: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
9013: &Apache::loncommon::end_data_table_header_row()."\n".
9014: $badstudents."\n".
9015: &Apache::loncommon::end_data_table()).'<br />'.
1.572 www 9016: &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 9017: }
1.614 www 9018: $r->print('</form><br />');
1.523 raeburn 9019: return;
9020: }
9021:
1.542 raeburn 9022: sub verify_scantron_grading {
1.554 raeburn 9023: my ($resource,$domain,$username,$cid,$counter,$scandata,$partids,
1.691 raeburn 9024: $scantron_config,$lettdig,$numletts,$randomorder,$randompick,
9025: $respnumlookup,$startline) = @_;
1.542 raeburn 9026: my ($record,%expected,%startpos);
9027: return ($counter,$record) if (!ref($resource));
9028: return ($counter,$record) if (!$resource->is_problem());
9029: my $symb = $resource->symb();
1.554 raeburn 9030: return ($counter,$record) if (ref($partids) ne 'ARRAY');
9031: foreach my $part_id (@{$partids}) {
1.542 raeburn 9032: $counter ++;
9033: $expected{$part_id} = 0;
1.691 raeburn 9034: my $respnum = $counter;
9035: if ($randomorder || $randompick) {
9036: $respnum = $respnumlookup->{$counter};
9037: $startpos{$part_id} = $startline->{$counter} + 1;
9038: } else {
9039: $startpos{$part_id} = $env{"form.scantron.first_bubble_line.$counter"};
9040: }
9041: if ($env{"form.scantron.sub_bubblelines.$respnum"}) {
9042: my @sub_lines = split(/,/,$env{"form.scantron.sub_bubblelines.$respnum"});
1.542 raeburn 9043: foreach my $item (@sub_lines) {
9044: $expected{$part_id} += $item;
9045: }
9046: } else {
1.691 raeburn 9047: $expected{$part_id} = $env{"form.scantron.bubblelines.$respnum"};
1.542 raeburn 9048: }
9049: }
9050: if ($symb) {
9051: my %recorded;
9052: my (%returnhash) = &Apache::lonnet::restore($symb,$cid,$domain,$username);
9053: if ($returnhash{'version'}) {
9054: my %lasthash=();
9055: my $version;
9056: for ($version=1;$version<=$returnhash{'version'};$version++) {
9057: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
9058: $lasthash{$key}=$returnhash{$version.':'.$key};
9059: }
9060: }
9061: foreach my $key (keys(%lasthash)) {
9062: if ($key =~ /\.scantron$/) {
9063: my $value = &unescape($lasthash{$key});
9064: my ($part_id) = ($key =~ /^resource\.(.+)\.scantron$/);
9065: if ($value eq '') {
9066: for (my $i=0; $i<$expected{$part_id}; $i++) {
9067: for (my $j=0; $j<$scantron_config->{'length'}; $j++) {
9068: $recorded{$part_id} .= $scantron_config->{'Qoff'};
9069: }
9070: }
9071: } else {
9072: my @tocheck;
9073: my @items = split(//,$value);
9074: if (($scantron_config->{'Qon'} eq 'letter') ||
9075: ($scantron_config->{'Qon'} eq 'number')) {
9076: if (@items < $expected{$part_id}) {
9077: my $fragment = substr($scandata,$startpos{$part_id},$expected{$part_id});
9078: my @singles = split(//,$fragment);
9079: foreach my $pos (@singles) {
9080: if ($pos eq ' ') {
9081: push(@tocheck,$pos);
9082: } else {
9083: my $next = shift(@items);
9084: push(@tocheck,$next);
9085: }
9086: }
9087: } else {
9088: @tocheck = @items;
9089: }
9090: foreach my $letter (@tocheck) {
9091: if ($scantron_config->{'Qon'} eq 'letter') {
9092: if ($letter !~ /^[A-J]$/) {
9093: $letter = $scantron_config->{'Qoff'};
9094: }
9095: $recorded{$part_id} .= $letter;
9096: } elsif ($scantron_config->{'Qon'} eq 'number') {
9097: my $digit;
9098: if ($letter !~ /^[A-J]$/) {
9099: $digit = $scantron_config->{'Qoff'};
9100: } else {
9101: $digit = $lettdig->{$letter};
9102: }
9103: $recorded{$part_id} .= $digit;
9104: }
9105: }
9106: } else {
9107: @tocheck = @items;
9108: for (my $i=0; $i<$expected{$part_id}; $i++) {
9109: my $curr_sub = shift(@tocheck);
9110: my $digit;
9111: if ($curr_sub =~ /^[A-J]$/) {
9112: $digit = $lettdig->{$curr_sub}-1;
9113: }
9114: if ($curr_sub eq 'J') {
9115: $digit += scalar($numletts);
9116: }
9117: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
9118: if ($j == $digit) {
9119: $recorded{$part_id} .= $scantron_config->{'Qon'};
9120: } else {
9121: $recorded{$part_id} .= $scantron_config->{'Qoff'};
9122: }
9123: }
9124: }
9125: }
9126: }
9127: }
9128: }
9129: }
1.554 raeburn 9130: foreach my $part_id (@{$partids}) {
1.542 raeburn 9131: if ($recorded{$part_id} eq '') {
9132: for (my $i=0; $i<$expected{$part_id}; $i++) {
9133: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
9134: $recorded{$part_id} .= $scantron_config->{'Qoff'};
9135: }
9136: }
9137: }
9138: $record .= $recorded{$part_id};
9139: }
9140: }
9141: return ($counter,$record);
9142: }
9143:
1.691 raeburn 9144: sub letter_to_digits {
1.542 raeburn 9145: my %lettdig = (
9146: A => 1,
9147: B => 2,
9148: C => 3,
9149: D => 4,
9150: E => 5,
9151: F => 6,
9152: G => 7,
9153: H => 8,
9154: I => 9,
9155: J => 0,
9156: );
9157: return %lettdig;
9158: }
9159:
1.423 albertel 9160:
1.75 albertel 9161: #-------- end of section for handling grading scantron forms -------
9162: #
9163: #-------------------------------------------------------------------
9164:
1.72 ng 9165: #-------------------------- Menu interface -------------------------
9166: #
1.614 www 9167: #--- Href with symb and command ---
9168:
9169: sub href_symb_cmd {
9170: my ($symb,$cmd)=@_;
1.669 raeburn 9171: return '/adm/grades?symb='.&HTML::Entities::encode(&Apache::lonenc::check_encrypt($symb),'<>&"').'&command='.$cmd;
1.72 ng 9172: }
9173:
1.443 banghart 9174: sub grading_menu {
1.608 www 9175: my ($request,$symb) = @_;
1.443 banghart 9176: if (!$symb) {return '';}
9177:
9178: my %fields = ('symb'=>&Apache::lonenc::check_encrypt($symb),
1.618 www 9179: 'command'=>'individual');
1.538 schulted 9180:
1.598 www 9181: my $url1a = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
9182:
9183: $fields{'command'}='ungraded';
9184: my $url1b=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
9185:
9186: $fields{'command'}='table';
9187: my $url1c=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
9188:
9189: $fields{'command'}='all_for_one';
9190: my $url1d=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
9191:
1.621 www 9192: $fields{'command'}='downloadfilesselect';
9193: my $url1e=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
9194:
1.443 banghart 9195: $fields{'command'} = 'csvform';
1.538 schulted 9196: my $url2 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
9197:
1.443 banghart 9198: $fields{'command'} = 'processclicker';
1.538 schulted 9199: my $url3 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
9200:
1.443 banghart 9201: $fields{'command'} = 'scantron_selectphase';
1.538 schulted 9202: my $url4 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
1.602 www 9203:
9204: $fields{'command'} = 'initialverifyreceipt';
9205: my $url5 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
1.538 schulted 9206:
1.598 www 9207: my @menu = ({ categorytitle=>'Hand Grading',
1.538 schulted 9208: items =>[
1.598 www 9209: { linktext => 'Select individual students to grade',
9210: url => $url1a,
1.538 schulted 9211: permission => 'F',
1.636 wenzelju 9212: icon => 'grade_students.png',
1.598 www 9213: linktitle => 'Grade current resource for a selection of students.'
9214: },
9215: { linktext => 'Grade ungraded submissions.',
9216: url => $url1b,
9217: permission => 'F',
1.636 wenzelju 9218: icon => 'ungrade_sub.png',
1.598 www 9219: linktitle => 'Grade all submissions that have not been graded yet.'
1.538 schulted 9220: },
1.598 www 9221:
9222: { linktext => 'Grading table',
9223: url => $url1c,
9224: permission => 'F',
1.636 wenzelju 9225: icon => 'grading_table.png',
1.598 www 9226: linktitle => 'Grade current resource for all students.'
9227: },
1.615 www 9228: { linktext => 'Grade page/folder for one student',
1.598 www 9229: url => $url1d,
9230: permission => 'F',
1.636 wenzelju 9231: icon => 'grade_PageFolder.png',
1.598 www 9232: linktitle => 'Grade all resources in current page/sequence/folder for one student.'
1.621 www 9233: },
9234: { linktext => 'Download submissions',
9235: url => $url1e,
9236: permission => 'F',
1.636 wenzelju 9237: icon => 'download_sub.png',
1.621 www 9238: linktitle => 'Download all students submissions.'
1.598 www 9239: }]},
9240: { categorytitle=>'Automated Grading',
9241: items =>[
9242:
1.538 schulted 9243: { linktext => 'Upload Scores',
9244: url => $url2,
9245: permission => 'F',
9246: icon => 'uploadscores.png',
9247: linktitle => 'Specify a file containing the class scores for current resource.'
9248: },
9249: { linktext => 'Process Clicker',
9250: url => $url3,
9251: permission => 'F',
9252: icon => 'addClickerInfoFile.png',
9253: linktitle => 'Specify a file containing the clicker information for this resource.'
9254: },
1.587 raeburn 9255: { linktext => 'Grade/Manage/Review Bubblesheets',
1.538 schulted 9256: url => $url4,
9257: permission => 'F',
1.636 wenzelju 9258: icon => 'bubblesheet.png',
1.648 bisitz 9259: linktitle => 'Grade bubblesheet exams, upload/download bubblesheet data files, and review previously graded bubblesheet exams.'
1.602 www 9260: },
1.616 www 9261: { linktext => 'Verify Receipt Number',
1.602 www 9262: url => $url5,
9263: permission => 'F',
1.636 wenzelju 9264: icon => 'receipt_number.png',
1.602 www 9265: linktitle => 'Verify a system-generated receipt number for correct problem solution.'
9266: }
9267:
1.538 schulted 9268: ]
9269: });
9270:
1.443 banghart 9271: # Create the menu
9272: my $Str;
1.445 banghart 9273: $Str .= '<form method="post" action="" name="gradingMenu">';
9274: $Str .= '<input type="hidden" name="command" value="" />'.
1.618 www 9275: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.445 banghart 9276:
1.602 www 9277: $Str .= &Apache::lonhtmlcommon::generate_menu(@menu);
1.443 banghart 9278: return $Str;
9279: }
9280:
1.598 www 9281:
9282: sub ungraded {
9283: my ($request)=@_;
9284: &submit_options($request);
9285: }
9286:
1.599 www 9287: sub submit_options_sequence {
1.608 www 9288: my ($request,$symb) = @_;
1.599 www 9289: if (!$symb) {return '';}
1.600 www 9290: &commonJSfunctions($request);
9291: my $result;
1.599 www 9292:
1.600 www 9293: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.618 www 9294: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.632 www 9295: $result.=&selectfield(0).
1.601 www 9296: '<input type="hidden" name="command" value="pickStudentPage" />
1.600 www 9297: <div>
9298: <input type="submit" value="'.&mt('Next').' →" />
9299: </div>
9300: </div>
9301: </form>';
9302: return $result;
9303: }
9304:
9305: sub submit_options_table {
1.608 www 9306: my ($request,$symb) = @_;
1.600 www 9307: if (!$symb) {return '';}
1.599 www 9308: &commonJSfunctions($request);
9309: my $result;
9310:
9311: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.618 www 9312: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.599 www 9313:
1.632 www 9314: $result.=&selectfield(0).
1.601 www 9315: '<input type="hidden" name="command" value="viewgrades" />
1.599 www 9316: <div>
9317: <input type="submit" value="'.&mt('Next').' →" />
9318: </div>
9319: </div>
9320: </form>';
9321: return $result;
9322: }
1.443 banghart 9323:
1.621 www 9324: sub submit_options_download {
9325: my ($request,$symb) = @_;
9326: if (!$symb) {return '';}
9327:
9328: &commonJSfunctions($request);
9329:
9330: my $result='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
9331: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
9332: $result.='
9333: <h2>
9334: '.&mt('Select Students for Which to Download Submissions').'
9335: </h2>'.&selectfield(1).'
9336: <input type="hidden" name="command" value="downloadfileslink" />
9337: <input type="submit" value="'.&mt('Next').' →" />
9338: </div>
9339: </div>
1.600 www 9340:
9341:
1.621 www 9342: </form>';
9343: return $result;
9344: }
9345:
1.443 banghart 9346: #--- Displays the submissions first page -------
9347: sub submit_options {
1.608 www 9348: my ($request,$symb) = @_;
1.72 ng 9349: if (!$symb) {return '';}
9350:
1.118 ng 9351: &commonJSfunctions($request);
1.473 albertel 9352: my $result;
1.533 bisitz 9353:
1.72 ng 9354: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.618 www 9355: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.632 www 9356: $result.=&selectfield(1).'
1.601 www 9357: <input type="hidden" name="command" value="submission" />
9358: <input type="submit" value="'.&mt('Next').' →" />
9359: </div>
9360: </div>
9361:
9362:
9363: </form>';
9364: return $result;
9365: }
1.533 bisitz 9366:
1.601 www 9367: sub selectfield {
9368: my ($full)=@_;
1.635 raeburn 9369: my %options =
9370: (&Apache::lonlocal::texthash(
9371: 'yes' => 'with submissions',
9372: 'queued' => 'in grading queue',
9373: 'graded' => 'with ungraded submissions',
9374: 'incorrect' => 'with incorrect submissions',
9375: 'all' => 'with any status'),
9376: 'select_form_order' => ['yes','queued','graded','incorrect','all']);
1.601 www 9377: my $result='<div class="LC_columnSection">
1.537 harmsja 9378:
1.533 bisitz 9379: <fieldset>
9380: <legend>
9381: '.&mt('Sections').'
9382: </legend>
1.601 www 9383: '.&Apache::lonstatistics::SectionSelect('section','multiple',5).'
1.533 bisitz 9384: </fieldset>
1.537 harmsja 9385:
1.533 bisitz 9386: <fieldset>
9387: <legend>
9388: '.&mt('Groups').'
9389: </legend>
9390: '.&Apache::lonstatistics::GroupSelect('group','multiple',5).'
9391: </fieldset>
1.537 harmsja 9392:
1.533 bisitz 9393: <fieldset>
9394: <legend>
9395: '.&mt('Access Status').'
9396: </legend>
1.601 www 9397: '.&Apache::lonhtmlcommon::StatusOptions(undef,undef,5,undef,'mult').'
9398: </fieldset>';
9399: if ($full) {
9400: $result.='
1.533 bisitz 9401: <fieldset>
9402: <legend>
9403: '.&mt('Submission Status').'
1.601 www 9404: </legend>'.
1.635 raeburn 9405: &Apache::loncommon::select_form('all','submitonly',\%options).
1.601 www 9406: '</fieldset>';
9407: }
9408: $result.='</div><br />';
1.44 ng 9409: return $result;
1.2 albertel 9410: }
9411:
1.285 albertel 9412: sub reset_perm {
9413: undef(%perm);
9414: }
9415:
9416: sub init_perm {
9417: &reset_perm();
1.300 albertel 9418: foreach my $test_perm ('vgr','mgr','opa') {
9419:
9420: my $scope = $env{'request.course.id'};
9421: if (!($perm{$test_perm}=&Apache::lonnet::allowed($test_perm,$scope))) {
9422:
9423: $scope .= '/'.$env{'request.course.sec'};
9424: if ( $perm{$test_perm}=
9425: &Apache::lonnet::allowed($test_perm,$scope)) {
9426: $perm{$test_perm.'_section'}=$env{'request.course.sec'};
9427: } else {
9428: delete($perm{$test_perm});
9429: }
1.285 albertel 9430: }
9431: }
9432: }
9433:
1.674 raeburn 9434: sub init_old_essays {
9435: my ($symb,$apath,$adom,$aname) = @_;
9436: if ($symb ne '') {
9437: my %essays = &Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
9438: if (keys(%essays) > 0) {
9439: $old_essays{$symb} = \%essays;
9440: }
9441: }
9442: return;
9443: }
9444:
9445: sub reset_old_essays {
9446: undef(%old_essays);
9447: }
9448:
1.400 www 9449: sub gather_clicker_ids {
1.408 albertel 9450: my %clicker_ids;
1.400 www 9451:
9452: my $classlist = &Apache::loncoursedata::get_classlist();
9453:
9454: # Set up a couple variables.
1.407 albertel 9455: my $username_idx = &Apache::loncoursedata::CL_SNAME();
9456: my $domain_idx = &Apache::loncoursedata::CL_SDOM();
1.438 www 9457: my $status_idx = &Apache::loncoursedata::CL_STATUS();
1.400 www 9458:
1.407 albertel 9459: foreach my $student (keys(%$classlist)) {
1.438 www 9460: if ($classlist->{$student}->[$status_idx] ne 'Active') { next; }
1.407 albertel 9461: my $username = $classlist->{$student}->[$username_idx];
9462: my $domain = $classlist->{$student}->[$domain_idx];
1.400 www 9463: my $clickers =
1.408 albertel 9464: (&Apache::lonnet::userenvironment($domain,$username,'clickers'))[1];
1.400 www 9465: foreach my $id (split(/\,/,$clickers)) {
1.414 www 9466: $id=~s/^[\#0]+//;
1.421 www 9467: $id=~s/[\-\:]//g;
1.407 albertel 9468: if (exists($clicker_ids{$id})) {
1.408 albertel 9469: $clicker_ids{$id}.=','.$username.':'.$domain;
1.400 www 9470: } else {
1.408 albertel 9471: $clicker_ids{$id}=$username.':'.$domain;
1.400 www 9472: }
9473: }
9474: }
1.407 albertel 9475: return %clicker_ids;
1.400 www 9476: }
9477:
1.402 www 9478: sub gather_adv_clicker_ids {
1.408 albertel 9479: my %clicker_ids;
1.402 www 9480: my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'};
9481: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
9482: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
1.409 albertel 9483: foreach my $element (sort(keys(%coursepersonnel))) {
1.402 www 9484: foreach my $person (split(/\,/,$coursepersonnel{$element})) {
9485: my ($puname,$pudom)=split(/\:/,$person);
9486: my $clickers =
1.408 albertel 9487: (&Apache::lonnet::userenvironment($pudom,$puname,'clickers'))[1];
1.405 www 9488: foreach my $id (split(/\,/,$clickers)) {
1.414 www 9489: $id=~s/^[\#0]+//;
1.421 www 9490: $id=~s/[\-\:]//g;
1.408 albertel 9491: if (exists($clicker_ids{$id})) {
9492: $clicker_ids{$id}.=','.$puname.':'.$pudom;
9493: } else {
9494: $clicker_ids{$id}=$puname.':'.$pudom;
9495: }
1.405 www 9496: }
1.402 www 9497: }
9498: }
1.407 albertel 9499: return %clicker_ids;
1.402 www 9500: }
9501:
1.413 www 9502: sub clicker_grading_parameters {
9503: return ('gradingmechanism' => 'scalar',
9504: 'upfiletype' => 'scalar',
9505: 'specificid' => 'scalar',
9506: 'pcorrect' => 'scalar',
9507: 'pincorrect' => 'scalar');
9508: }
9509:
1.400 www 9510: sub process_clicker {
1.608 www 9511: my ($r,$symb)=@_;
1.400 www 9512: if (!$symb) {return '';}
9513: my $result=&checkforfile_js();
1.632 www 9514: $result.=&Apache::loncommon::start_data_table().
9515: &Apache::loncommon::start_data_table_header_row().
9516: '<th>'.&mt('Specify a file containing clicker information and set grading options.').'</th>'.
9517: &Apache::loncommon::end_data_table_header_row().
9518: &Apache::loncommon::start_data_table_row()."<td>\n";
1.413 www 9519: # Attempt to restore parameters from last session, set defaults if not present
9520: my %Saveable_Parameters=&clicker_grading_parameters();
9521: &Apache::loncommon::restore_course_settings('grades_clicker',
9522: \%Saveable_Parameters);
9523: if (!$env{'form.pcorrect'}) { $env{'form.pcorrect'}=100; }
9524: if (!$env{'form.pincorrect'}) { $env{'form.pincorrect'}=100; }
9525: if (!$env{'form.gradingmechanism'}) { $env{'form.gradingmechanism'}='attendance'; }
9526: if (!$env{'form.upfiletype'}) { $env{'form.upfiletype'}='iclicker'; }
9527:
9528: my %checked;
1.521 www 9529: foreach my $gradingmechanism ('attendance','personnel','specific','given') {
1.413 www 9530: if ($env{'form.gradingmechanism'} eq $gradingmechanism) {
1.569 bisitz 9531: $checked{$gradingmechanism}=' checked="checked"';
1.413 www 9532: }
9533: }
9534:
1.632 www 9535: my $upload=&mt("Evaluate File");
1.400 www 9536: my $type=&mt("Type");
1.402 www 9537: my $attendance=&mt("Award points just for participation");
9538: my $personnel=&mt("Correctness determined from response by course personnel");
1.414 www 9539: my $specific=&mt("Correctness determined from response with clicker ID(s)");
1.521 www 9540: my $given=&mt("Correctness determined from given list of answers").' '.
9541: '<font size="-2"><tt>('.&mt("Provide comma-separated list. Use '*' for any answer correct, '-' for skip").')</tt></font>';
1.402 www 9542: my $pcorrect=&mt("Percentage points for correct solution");
9543: my $pincorrect=&mt("Percentage points for incorrect solution");
1.413 www 9544: my $selectform=&Apache::loncommon::select_form($env{'form.upfiletype'},'upfiletype',
1.635 raeburn 9545: {'iclicker' => 'i>clicker',
1.666 www 9546: 'interwrite' => 'interwrite PRS',
9547: 'turning' => 'Turning Technologies'});
1.418 albertel 9548: $symb = &Apache::lonenc::check_encrypt($symb);
1.597 wenzelju 9549: $result.= &Apache::lonhtmlcommon::scripttag(<<ENDUPFORM);
1.402 www 9550: function sanitycheck() {
9551: // Accept only integer percentages
9552: document.forms.gradesupload.pcorrect.value=Math.round(document.forms.gradesupload.pcorrect.value);
9553: document.forms.gradesupload.pincorrect.value=Math.round(document.forms.gradesupload.pincorrect.value);
9554: // Find out grading choice
9555: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
9556: if (document.forms.gradesupload.gradingmechanism[i].checked) {
9557: gradingchoice=document.forms.gradesupload.gradingmechanism[i].value;
9558: }
9559: }
9560: // By default, new choice equals user selection
9561: newgradingchoice=gradingchoice;
9562: // Not good to give more points for false answers than correct ones
9563: if (Math.round(document.forms.gradesupload.pcorrect.value)<Math.round(document.forms.gradesupload.pincorrect.value)) {
9564: document.forms.gradesupload.pcorrect.value=document.forms.gradesupload.pincorrect.value;
9565: }
9566: // If new choice is attendance only, and old choice was correctness-based, restore defaults
9567: if ((gradingchoice=='attendance') && (document.forms.gradesupload.waschecked.value!='attendance')) {
9568: document.forms.gradesupload.pcorrect.value=100;
9569: document.forms.gradesupload.pincorrect.value=100;
9570: }
9571: // If the values are different, cannot be attendance only
9572: if ((Math.round(document.forms.gradesupload.pcorrect.value)!=Math.round(document.forms.gradesupload.pincorrect.value)) &&
9573: (gradingchoice=='attendance')) {
9574: newgradingchoice='personnel';
9575: }
9576: // Change grading choice to new one
9577: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
9578: if (document.forms.gradesupload.gradingmechanism[i].value==newgradingchoice) {
9579: document.forms.gradesupload.gradingmechanism[i].checked=true;
9580: } else {
9581: document.forms.gradesupload.gradingmechanism[i].checked=false;
9582: }
9583: }
9584: // Remember the old state
9585: document.forms.gradesupload.waschecked.value=newgradingchoice;
9586: }
1.597 wenzelju 9587: ENDUPFORM
9588: $result.= <<ENDUPFORM;
1.400 www 9589: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
9590: <input type="hidden" name="symb" value="$symb" />
9591: <input type="hidden" name="command" value="processclickerfile" />
9592: <input type="file" name="upfile" size="50" />
9593: <br /><label>$type: $selectform</label>
1.632 www 9594: ENDUPFORM
9595: $result.='</td>'.&Apache::loncommon::end_data_table_row().
9596: &Apache::loncommon::start_data_table_row().'<td>'.(<<ENDGRADINGFORM);
9597: <label><input type="radio" name="gradingmechanism" value="attendance"$checked{'attendance'} onclick="sanitycheck()" />$attendance </label>
1.589 bisitz 9598: <br /><label><input type="radio" name="gradingmechanism" value="personnel"$checked{'personnel'} onclick="sanitycheck()" />$personnel</label>
9599: <br /><label><input type="radio" name="gradingmechanism" value="specific"$checked{'specific'} onclick="sanitycheck()" />$specific </label>
1.414 www 9600: <input type="text" name="specificid" value="$env{'form.specificid'}" size="20" />
1.589 bisitz 9601: <br /><label><input type="radio" name="gradingmechanism" value="given"$checked{'given'} onclick="sanitycheck()" />$given </label>
1.521 www 9602: <br />
9603: <input type="text" name="givenanswer" size="50" />
1.413 www 9604: <input type="hidden" name="waschecked" value="$env{'form.gradingmechanism'}" />
1.632 www 9605: ENDGRADINGFORM
9606: $result.='</td>'.&Apache::loncommon::end_data_table_row().
9607: &Apache::loncommon::start_data_table_row().'<td>'.(<<ENDPERCFORM);
9608: <label>$pcorrect: <input type="text" name="pcorrect" size="4" value="$env{'form.pcorrect'}" onchange="sanitycheck()" /></label>
1.589 bisitz 9609: <br /><label>$pincorrect: <input type="text" name="pincorrect" size="4" value="$env{'form.pincorrect'}" onchange="sanitycheck()" /></label>
9610: <br /><input type="button" onclick="javascript:checkUpload(this.form);" value="$upload" />
1.597 wenzelju 9611: </form>'
1.632 www 9612: ENDPERCFORM
9613: $result.='</td>'.
9614: &Apache::loncommon::end_data_table_row().
9615: &Apache::loncommon::end_data_table();
1.400 www 9616: return $result;
9617: }
9618:
9619: sub process_clicker_file {
1.608 www 9620: my ($r,$symb)=@_;
1.400 www 9621: if (!$symb) {return '';}
1.413 www 9622:
9623: my %Saveable_Parameters=&clicker_grading_parameters();
9624: &Apache::loncommon::store_course_settings('grades_clicker',
9625: \%Saveable_Parameters);
1.598 www 9626: my $result='';
1.404 www 9627: if (($env{'form.gradingmechanism'} eq 'specific') && ($env{'form.specificid'}!~/\w/)) {
1.408 albertel 9628: $result.='<span class="LC_error">'.&mt('You need to specify a clicker ID for the correct answer').'</span>';
1.614 www 9629: return $result;
1.404 www 9630: }
1.522 www 9631: if (($env{'form.gradingmechanism'} eq 'given') && ($env{'form.givenanswer'}!~/\S/)) {
1.521 www 9632: $result.='<span class="LC_error">'.&mt('You need to specify the correct answer').'</span>';
1.614 www 9633: return $result;
1.521 www 9634: }
1.522 www 9635: my $foundgiven=0;
1.521 www 9636: if ($env{'form.gradingmechanism'} eq 'given') {
9637: $env{'form.givenanswer'}=~s/^\s*//gs;
9638: $env{'form.givenanswer'}=~s/\s*$//gs;
1.644 www 9639: $env{'form.givenanswer'}=~s/[^a-zA-Z0-9\.\*\-\+]+/\,/g;
1.521 www 9640: $env{'form.givenanswer'}=uc($env{'form.givenanswer'});
1.522 www 9641: my @answers=split(/\,/,$env{'form.givenanswer'});
9642: $foundgiven=$#answers+1;
1.521 www 9643: }
1.407 albertel 9644: my %clicker_ids=&gather_clicker_ids();
1.408 albertel 9645: my %correct_ids;
1.404 www 9646: if ($env{'form.gradingmechanism'} eq 'personnel') {
1.408 albertel 9647: %correct_ids=&gather_adv_clicker_ids();
1.404 www 9648: }
9649: if ($env{'form.gradingmechanism'} eq 'specific') {
1.414 www 9650: foreach my $correct_id (split(/[\s\,]/,$env{'form.specificid'})) {;
9651: $correct_id=~tr/a-z/A-Z/;
9652: $correct_id=~s/\s//gs;
9653: $correct_id=~s/^[\#0]+//;
1.421 www 9654: $correct_id=~s/[\-\:]//g;
1.414 www 9655: if ($correct_id) {
9656: $correct_ids{$correct_id}='specified';
9657: }
9658: }
1.400 www 9659: }
1.404 www 9660: if ($env{'form.gradingmechanism'} eq 'attendance') {
1.408 albertel 9661: $result.=&mt('Score based on attendance only');
1.521 www 9662: } elsif ($env{'form.gradingmechanism'} eq 'given') {
1.522 www 9663: $result.=&mt('Score based on [_1] ([_2] answers)','<tt>'.$env{'form.givenanswer'}.'</tt>',$foundgiven);
1.404 www 9664: } else {
1.408 albertel 9665: my $number=0;
1.411 www 9666: $result.='<p><b>'.&mt('Correctness determined by the following IDs').'</b>';
1.408 albertel 9667: foreach my $id (sort(keys(%correct_ids))) {
1.411 www 9668: $result.='<br /><tt>'.$id.'</tt> - ';
1.408 albertel 9669: if ($correct_ids{$id} eq 'specified') {
9670: $result.=&mt('specified');
9671: } else {
9672: my ($uname,$udom)=split(/\:/,$correct_ids{$id});
9673: $result.=&Apache::loncommon::plainname($uname,$udom);
9674: }
9675: $number++;
9676: }
1.411 www 9677: $result.="</p>\n";
1.408 albertel 9678: if ($number==0) {
9679: $result.='<span class="LC_error">'.&mt('No IDs found to determine correct answer').'</span>';
1.614 www 9680: return $result;
1.408 albertel 9681: }
1.404 www 9682: }
1.405 www 9683: if (length($env{'form.upfile'}) < 2) {
1.407 albertel 9684: $result.=&mt('[_1] Error: [_2] The file you attempted to upload, [_3] contained no information. Please check that you entered the correct filename.',
9685: '<span class="LC_error">',
9686: '</span>',
9687: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>');
1.614 www 9688: return $result;
1.405 www 9689: }
1.410 www 9690:
9691: # Were able to get all the info needed, now analyze the file
9692:
1.411 www 9693: $result.=&Apache::loncommon::studentbrowser_javascript();
1.418 albertel 9694: $symb = &Apache::lonenc::check_encrypt($symb);
1.632 www 9695: $result.=&Apache::loncommon::start_data_table().
9696: &Apache::loncommon::start_data_table_header_row().
9697: '<th>'.&mt('Evaluate clicker file').'</th>'.
9698: &Apache::loncommon::end_data_table_header_row().
9699: &Apache::loncommon::start_data_table_row().(<<ENDHEADER);
9700: <td>
1.410 www 9701: <form method="post" action="/adm/grades" name="clickeranalysis">
9702: <input type="hidden" name="symb" value="$symb" />
9703: <input type="hidden" name="command" value="assignclickergrades" />
1.411 www 9704: <input type="hidden" name="gradingmechanism" value="$env{'form.gradingmechanism'}" />
9705: <input type="hidden" name="pcorrect" value="$env{'form.pcorrect'}" />
9706: <input type="hidden" name="pincorrect" value="$env{'form.pincorrect'}" />
1.410 www 9707: ENDHEADER
1.522 www 9708: if ($env{'form.gradingmechanism'} eq 'given') {
9709: $result.='<input type="hidden" name="correct:given" value="'.$env{'form.givenanswer'}.'" />';
9710: }
1.408 albertel 9711: my %responses;
9712: my @questiontitles;
1.405 www 9713: my $errormsg='';
9714: my $number=0;
9715: if ($env{'form.upfiletype'} eq 'iclicker') {
1.408 albertel 9716: ($errormsg,$number)=&iclicker_eval(\@questiontitles,\%responses);
1.406 www 9717: }
1.419 www 9718: if ($env{'form.upfiletype'} eq 'interwrite') {
9719: ($errormsg,$number)=&interwrite_eval(\@questiontitles,\%responses);
9720: }
1.666 www 9721: if ($env{'form.upfiletype'} eq 'turning') {
9722: ($errormsg,$number)=&turning_eval(\@questiontitles,\%responses);
9723: }
1.411 www 9724: $result.='<br />'.&mt('Found [_1] question(s)',$number).'<br />'.
9725: '<input type="hidden" name="number" value="'.$number.'" />'.
9726: &mt('Awarding [_1] percent for correct and [_2] percent for incorrect responses',
9727: $env{'form.pcorrect'},$env{'form.pincorrect'}).
9728: '<br />';
1.522 www 9729: if (($env{'form.gradingmechanism'} eq 'given') && ($number!=$foundgiven)) {
9730: $result.='<span class="LC_error">'.&mt('Number of given answers does not agree with number of questions in file.').'</span>';
1.614 www 9731: return $result;
1.522 www 9732: }
1.414 www 9733: # Remember Question Titles
9734: # FIXME: Possibly need delimiter other than ":"
9735: for (my $i=0;$i<$number;$i++) {
9736: $result.='<input type="hidden" name="question:'.$i.'" value="'.
9737: &HTML::Entities::encode($questiontitles[$i],'"&<>').'" />';
9738: }
1.411 www 9739: my $correct_count=0;
9740: my $student_count=0;
9741: my $unknown_count=0;
1.414 www 9742: # Match answers with usernames
9743: # FIXME: Possibly need delimiter other than ":"
1.409 albertel 9744: foreach my $id (keys(%responses)) {
1.410 www 9745: if ($correct_ids{$id}) {
1.414 www 9746: $result.="\n".'<input type="hidden" name="correct:'.$correct_count.':'.$correct_ids{$id}.'" value="'.$responses{$id}.'" />';
1.411 www 9747: $correct_count++;
1.410 www 9748: } elsif ($clicker_ids{$id}) {
1.437 www 9749: if ($clicker_ids{$id}=~/\,/) {
9750: # More than one user with the same clicker!
1.632 www 9751: $result.="</td>".&Apache::loncommon::end_data_table_row().
9752: &Apache::loncommon::start_data_table_row()."<td>".
9753: &mt('Clicker registered more than once').": <tt>".$id."</tt><br />";
1.437 www 9754: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
9755: "<select name='multi".$id."'>";
9756: foreach my $reguser (sort(split(/\,/,$clicker_ids{$id}))) {
9757: $result.="<option value='".$reguser."'>".&Apache::loncommon::plainname(split(/\:/,$reguser)).' ('.$reguser.')</option>';
9758: }
9759: $result.='</select>';
9760: $unknown_count++;
9761: } else {
9762: # Good: found one and only one user with the right clicker
9763: $result.="\n".'<input type="hidden" name="student:'.$clicker_ids{$id}.'" value="'.$responses{$id}.'" />';
9764: $student_count++;
9765: }
1.410 www 9766: } else {
1.632 www 9767: $result.="</td>".&Apache::loncommon::end_data_table_row().
9768: &Apache::loncommon::start_data_table_row()."<td>".
9769: &mt('Unregistered Clicker')." <tt>".$id."</tt><br />";
1.411 www 9770: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
9771: "\n".&mt("Username").": <input type='text' name='uname".$id."' /> ".
9772: "\n".&mt("Domain").": ".
9773: &Apache::loncommon::select_dom_form($env{'course.'.$env{'request.course.id'}.'.domain'},'udom'.$id).' '.
1.643 www 9774: &Apache::loncommon::selectstudent_link('clickeranalysis','uname'.$id,'udom'.$id,0,$id);
1.411 www 9775: $unknown_count++;
1.410 www 9776: }
1.405 www 9777: }
1.412 www 9778: $result.='<hr />'.
9779: &mt('Found [_1] registered and [_2] unregistered clickers.',$student_count,$unknown_count);
1.521 www 9780: if (($env{'form.gradingmechanism'} ne 'attendance') && ($env{'form.gradingmechanism'} ne 'given')) {
1.412 www 9781: if ($correct_count==0) {
9782: $errormsg.="Found no correct answers answers for grading!";
9783: } elsif ($correct_count>1) {
1.414 www 9784: $result.='<br /><span class="LC_warning">'.&mt("Found [_1] entries for grading!",$correct_count).'</span>';
1.412 www 9785: }
9786: }
1.428 www 9787: if ($number<1) {
9788: $errormsg.="Found no questions.";
9789: }
1.412 www 9790: if ($errormsg) {
9791: $result.='<br /><span class="LC_error">'.&mt($errormsg).'</span>';
9792: } else {
9793: $result.='<br /><input type="submit" name="finalize" value="'.&mt('Finalize Grading').'" />';
9794: }
1.632 www 9795: $result.='</form></td>'.
9796: &Apache::loncommon::end_data_table_row().
9797: &Apache::loncommon::end_data_table();
1.614 www 9798: return $result;
1.400 www 9799: }
9800:
1.405 www 9801: sub iclicker_eval {
1.406 www 9802: my ($questiontitles,$responses)=@_;
1.405 www 9803: my $number=0;
9804: my $errormsg='';
9805: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
1.410 www 9806: my %components=&Apache::loncommon::record_sep($line);
9807: my @entries=map {$components{$_}} (sort(keys(%components)));
1.408 albertel 9808: if ($entries[0] eq 'Question') {
9809: for (my $i=3;$i<$#entries;$i+=6) {
9810: $$questiontitles[$number]=$entries[$i];
9811: $number++;
9812: }
9813: }
9814: if ($entries[0]=~/^\#/) {
9815: my $id=$entries[0];
9816: my @idresponses;
9817: $id=~s/^[\#0]+//;
9818: for (my $i=0;$i<$number;$i++) {
9819: my $idx=3+$i*6;
1.644 www 9820: $entries[$idx]=~s/[^a-zA-Z0-9\.\*\-\+]+//g;
1.408 albertel 9821: push(@idresponses,$entries[$idx]);
9822: }
9823: $$responses{$id}=join(',',@idresponses);
9824: }
1.405 www 9825: }
9826: return ($errormsg,$number);
9827: }
9828:
1.419 www 9829: sub interwrite_eval {
9830: my ($questiontitles,$responses)=@_;
9831: my $number=0;
9832: my $errormsg='';
1.420 www 9833: my $skipline=1;
9834: my $questionnumber=0;
9835: my %idresponses=();
1.419 www 9836: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
9837: my %components=&Apache::loncommon::record_sep($line);
9838: my @entries=map {$components{$_}} (sort(keys(%components)));
1.420 www 9839: if ($entries[1] eq 'Time') { $skipline=0; next; }
9840: if ($entries[1] eq 'Response') { $skipline=1; }
9841: next if $skipline;
9842: if ($entries[0]!=$questionnumber) {
9843: $questionnumber=$entries[0];
9844: $$questiontitles[$number]=&mt('Question [_1]',$questionnumber);
9845: $number++;
1.419 www 9846: }
1.420 www 9847: my $id=$entries[4];
9848: $id=~s/^[\#0]+//;
1.421 www 9849: $id=~s/^v\d*\://i;
9850: $id=~s/[\-\:]//g;
1.420 www 9851: $idresponses{$id}[$number]=$entries[6];
9852: }
1.524 raeburn 9853: foreach my $id (keys(%idresponses)) {
1.420 www 9854: $$responses{$id}=join(',',@{$idresponses{$id}});
9855: $$responses{$id}=~s/^\s*\,//;
1.419 www 9856: }
9857: return ($errormsg,$number);
9858: }
9859:
1.666 www 9860: sub turning_eval {
9861: my ($questiontitles,$responses)=@_;
9862: my $number=0;
9863: my $errormsg='';
9864: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
9865: my %components=&Apache::loncommon::record_sep($line);
9866: my @entries=map {$components{$_}} (sort(keys(%components)));
9867: if ($#entries>$number) { $number=$#entries; }
9868: my $id=$entries[0];
9869: my @idresponses;
9870: $id=~s/^[\#0]+//;
9871: unless ($id) { next; }
9872: for (my $idx=1;$idx<=$#entries;$idx++) {
9873: $entries[$idx]=~s/\,/\;/g;
9874: $entries[$idx]=~s/[^a-zA-Z0-9\.\*\-\+\;]+//g;
9875: push(@idresponses,$entries[$idx]);
9876: }
9877: $$responses{$id}=join(',',@idresponses);
9878: }
9879: for (my $i=1; $i<=$number; $i++) {
9880: $$questiontitles[$i]=&mt('Question [_1]',$i);
9881: }
9882: return ($errormsg,$number);
9883: }
9884:
9885:
1.414 www 9886: sub assign_clicker_grades {
1.608 www 9887: my ($r,$symb)=@_;
1.414 www 9888: if (!$symb) {return '';}
1.416 www 9889: # See which part we are saving to
1.582 raeburn 9890: my $res_error;
9891: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
9892: if ($res_error) {
9893: return &navmap_errormsg();
9894: }
1.416 www 9895: # FIXME: This should probably look for the first handgradeable part
9896: my $part=$$partlist[0];
9897: # Start screen output
1.632 www 9898: my $result=&Apache::loncommon::start_data_table().
9899: &Apache::loncommon::start_data_table_header_row().
9900: '<th>'.&mt('Assigning grades based on clicker file').'</th>'.
9901: &Apache::loncommon::end_data_table_header_row().
9902: &Apache::loncommon::start_data_table_row().'<td>';
1.414 www 9903: # Get correct result
9904: # FIXME: Possibly need delimiter other than ":"
9905: my @correct=();
1.415 www 9906: my $gradingmechanism=$env{'form.gradingmechanism'};
9907: my $number=$env{'form.number'};
9908: if ($gradingmechanism ne 'attendance') {
1.414 www 9909: foreach my $key (keys(%env)) {
9910: if ($key=~/^form\.correct\:/) {
9911: my @input=split(/\,/,$env{$key});
9912: for (my $i=0;$i<=$#input;$i++) {
9913: if (($correct[$i]) && ($input[$i]) &&
9914: ($correct[$i] ne $input[$i])) {
9915: $result.='<br /><span class="LC_warning">'.
9916: &mt('More than one correct result given for question "[_1]": [_2] versus [_3].',
9917: $env{'form.question:'.$i},$correct[$i],$input[$i]).'</span>';
1.644 www 9918: } elsif (($input[$i]) || ($input[$i] eq '0')) {
1.414 www 9919: $correct[$i]=$input[$i];
9920: }
9921: }
9922: }
9923: }
1.415 www 9924: for (my $i=0;$i<$number;$i++) {
1.644 www 9925: if ((!$correct[$i]) && ($correct[$i] ne '0')) {
1.414 www 9926: $result.='<br /><span class="LC_error">'.
9927: &mt('No correct result given for question "[_1]"!',
9928: $env{'form.question:'.$i}).'</span>';
9929: }
9930: }
1.644 www 9931: $result.='<br />'.&mt("Correct answer: [_1]",join(', ',map { ((($_) || ($_ eq '0'))?$_:'-') } @correct));
1.414 www 9932: }
9933: # Start grading
1.415 www 9934: my $pcorrect=$env{'form.pcorrect'};
9935: my $pincorrect=$env{'form.pincorrect'};
1.416 www 9936: my $storecount=0;
1.632 www 9937: my %users=();
1.415 www 9938: foreach my $key (keys(%env)) {
1.420 www 9939: my $user='';
1.415 www 9940: if ($key=~/^form\.student\:(.*)$/) {
1.420 www 9941: $user=$1;
9942: }
9943: if ($key=~/^form\.unknown\:(.*)$/) {
9944: my $id=$1;
9945: if (($env{'form.uname'.$id}) && ($env{'form.udom'.$id})) {
9946: $user=$env{'form.uname'.$id}.':'.$env{'form.udom'.$id};
1.437 www 9947: } elsif ($env{'form.multi'.$id}) {
9948: $user=$env{'form.multi'.$id};
1.420 www 9949: }
9950: }
1.632 www 9951: if ($user) {
9952: if ($users{$user}) {
9953: $result.='<br /><span class="LC_warning">'.
9954: &mt("More than one entry found for <tt>[_1]</tt>!",$user).
9955: '</span><br />';
9956: }
9957: $users{$user}=1;
1.415 www 9958: my @answer=split(/\,/,$env{$key});
9959: my $sum=0;
1.522 www 9960: my $realnumber=$number;
1.415 www 9961: for (my $i=0;$i<$number;$i++) {
1.576 www 9962: if ($correct[$i] eq '-') {
9963: $realnumber--;
1.644 www 9964: } elsif (($answer[$i]) || ($answer[$i]=~/^[0\.]+$/)) {
1.415 www 9965: if ($gradingmechanism eq 'attendance') {
9966: $sum+=$pcorrect;
1.576 www 9967: } elsif ($correct[$i] eq '*') {
1.522 www 9968: $sum+=$pcorrect;
1.415 www 9969: } else {
1.644 www 9970: # We actually grade if correct or not
9971: my $increment=$pincorrect;
9972: # Special case: numerical answer "0"
9973: if ($correct[$i] eq '0') {
9974: if ($answer[$i]=~/^[0\.]+$/) {
9975: $increment=$pcorrect;
9976: }
9977: # General numerical answer, both evaluate to something non-zero
9978: } elsif ((1.0*$correct[$i]!=0) && (1.0*$answer[$i]!=0)) {
9979: if (1.0*$correct[$i]==1.0*$answer[$i]) {
9980: $increment=$pcorrect;
9981: }
9982: # Must be just alphanumeric
9983: } elsif ($answer[$i] eq $correct[$i]) {
9984: $increment=$pcorrect;
1.415 www 9985: }
1.644 www 9986: $sum+=$increment;
1.415 www 9987: }
9988: }
9989: }
1.522 www 9990: my $ave=$sum/(100*$realnumber);
1.416 www 9991: # Store
9992: my ($username,$domain)=split(/\:/,$user);
9993: my %grades=();
9994: $grades{"resource.$part.solved"}='correct_by_override';
9995: $grades{"resource.$part.awarded"}=$ave;
9996: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
9997: my $returncode=&Apache::lonnet::cstore(\%grades,$symb,
9998: $env{'request.course.id'},
9999: $domain,$username);
10000: if ($returncode ne 'ok') {
10001: $result.="<br /><span class=\"LC_error\">Failed to save student $username:$domain. Message when trying to save was ($returncode)</span>";
10002: } else {
10003: $storecount++;
10004: }
1.415 www 10005: }
10006: }
10007: # We are done
1.549 hauer 10008: $result.='<br />'.&mt('Successfully stored grades for [quant,_1,student].',$storecount).
1.632 www 10009: '</td>'.
10010: &Apache::loncommon::end_data_table_row().
10011: &Apache::loncommon::end_data_table();
1.614 www 10012: return $result;
1.414 www 10013: }
10014:
1.582 raeburn 10015: sub navmap_errormsg {
10016: return '<div class="LC_error">'.
10017: &mt('An error occurred retrieving information about resources in the course.').'<br />'.
1.595 raeburn 10018: &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 10019: '</div>';
10020: }
1.607 droeschl 10021:
1.609 www 10022: sub startpage {
1.671 raeburn 10023: my ($r,$symb,$crumbs,$onlyfolderflag,$nodisplayflag,$stuvcurrent,$stuvdisp,$nomenu,$js) = @_;
10024: if ($nomenu) {
10025: $r->print(&Apache::loncommon::start_page("Student's Version",$js,{'only_body' => '1'}));
10026: } else {
10027: unshift(@$crumbs,{href=>&href_symb_cmd($symb,'gradingmenu'),text=>"Grading"});
10028: $r->print(&Apache::loncommon::start_page('Grading',$js,
10029: {'bread_crumbs' => $crumbs}));
10030: &Apache::lonquickgrades::startGradeScreen($r,($env{'form.symb'}?'probgrading':'grading'));
10031: }
1.613 www 10032: unless ($nodisplayflag) {
1.671 raeburn 10033: $r->print(&Apache::lonhtmlcommon::resource_info_box($symb,$onlyfolderflag,$stuvcurrent,$stuvdisp));
1.613 www 10034: }
1.607 droeschl 10035: }
1.582 raeburn 10036:
1.622 www 10037: sub select_problem {
10038: my ($r)=@_;
1.632 www 10039: $r->print('<h3>'.&mt('Select the problem or one of the problems you want to grade').'</h3><form action="/adm/grades">');
1.622 www 10040: $r->print(&Apache::lonstathelpers::problem_selector('.',undef,1));
10041: $r->print('<input type="hidden" name="command" value="gradingmenu" />');
10042: $r->print('<input type="submit" value="'.&mt('Next').' →" /></form>');
10043: }
10044:
1.1 albertel 10045: sub handler {
1.41 ng 10046: my $request=$_[0];
1.434 albertel 10047: &reset_caches();
1.646 raeburn 10048: if ($request->header_only) {
10049: &Apache::loncommon::content_type($request,'text/html');
10050: $request->send_http_header;
10051: return OK;
10052: }
10053: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
10054:
1.664 raeburn 10055: # see what command we need to execute
10056:
10057: my @commands=&Apache::loncommon::get_env_multiple('form.command');
10058: my $command=$commands[0];
10059:
1.646 raeburn 10060: &init_perm();
10061: if (!$env{'request.course.id'}) {
1.664 raeburn 10062: unless ((&Apache::lonnet::allowed('usc',$env{'request.role.domain'})) &&
10063: ($command =~ /^scantronupload/)) {
10064: # Not in a course.
10065: $env{'user.error.msg'}="/adm/grades::vgr:0:0:Cannot display grades page outside course context";
10066: return HTTP_NOT_ACCEPTABLE;
10067: }
1.646 raeburn 10068: } elsif (!%perm) {
10069: $request->internal_redirect('/adm/quickgrades');
1.687 raeburn 10070: return OK;
1.41 ng 10071: }
1.646 raeburn 10072: &Apache::loncommon::content_type($request,'text/html');
1.41 ng 10073: $request->send_http_header;
1.646 raeburn 10074:
1.160 albertel 10075: if ($#commands > 0) {
10076: &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands));
10077: }
1.608 www 10078:
10079: # see what the symb is
10080:
10081: my $symb=$env{'form.symb'};
10082: unless ($symb) {
10083: (my $url=$env{'form.url'}) =~ s-^https*://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
10084: $symb=&Apache::lonnet::symbread($url);
10085: }
1.646 raeburn 10086: &Apache::lonenc::check_decrypt(\$symb);
1.608 www 10087:
1.513 foxr 10088: $ssi_error = 0;
1.637 www 10089: if (($symb eq '' || $command eq '') && ($env{'request.course.id'})) {
1.601 www 10090: #
1.637 www 10091: # Not called from a resource, but inside a course
1.601 www 10092: #
1.622 www 10093: &startpage($request,undef,[],1,1);
10094: &select_problem($request);
1.41 ng 10095: } else {
1.104 albertel 10096: if ($command eq 'submission' && $perm{'vgr'}) {
1.671 raeburn 10097: my ($stuvcurrent,$stuvdisp,$versionform,$js);
10098: if (($env{'form.student'} ne '') && ($env{'form.userdom'} ne '')) {
10099: ($stuvcurrent,$stuvdisp,$versionform,$js) =
10100: &choose_task_version_form($symb,$env{'form.student'},
10101: $env{'form.userdom'});
10102: }
10103: &startpage($request,$symb,[{href=>"", text=>"Student Submissions"}],undef,undef,$stuvcurrent,$stuvdisp,undef,$js);
10104: if ($versionform) {
10105: $request->print($versionform);
10106: }
10107: $request->print('<br clear="all" />');
1.611 www 10108: ($env{'form.student'} eq '' ? &listStudents($request,$symb) : &submission($request,0,0,$symb));
1.671 raeburn 10109: } elsif ($command eq 'versionsub' && $perm{'vgr'}) {
10110: my ($stuvcurrent,$stuvdisp,$versionform,$js) =
10111: &choose_task_version_form($symb,$env{'form.student'},
10112: $env{'form.userdom'},
10113: $env{'form.inhibitmenu'});
10114: &startpage($request,$symb,[{href=>"", text=>"Previous Student Version"}],undef,undef,$stuvcurrent,$stuvdisp,$env{'form.inhibitmenu'},$js);
10115: if ($versionform) {
10116: $request->print($versionform);
10117: }
10118: $request->print('<br clear="all" />');
10119: $request->print(&show_previous_task_version($request,$symb));
1.103 albertel 10120: } elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) {
1.615 www 10121: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'all_for_one'),text=>'Grade page/folder for one student'},
10122: {href=>'',text=>'Select student'}],1,1);
1.608 www 10123: &pickStudentPage($request,$symb);
1.103 albertel 10124: } elsif ($command eq 'displayPage' && $perm{'vgr'}) {
1.615 www 10125: &startpage($request,$symb,
10126: [{href=>&href_symb_cmd($symb,'all_for_one'),text=>'Grade page/folder for one student'},
10127: {href=>'',text=>'Select student'},
10128: {href=>'',text=>'Grade student'}],1,1);
1.608 www 10129: &displayPage($request,$symb);
1.104 albertel 10130: } elsif ($command eq 'gradeByPage' && $perm{'mgr'}) {
1.616 www 10131: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'all_for_one'),text=>'Grade page/folder for one student'},
10132: {href=>'',text=>'Select student'},
10133: {href=>'',text=>'Grade student'},
10134: {href=>'',text=>'Store grades'}],1,1);
1.608 www 10135: &updateGradeByPage($request,$symb);
1.104 albertel 10136: } elsif ($command eq 'processGroup' && $perm{'vgr'}) {
1.619 www 10137: &startpage($request,$symb,[{href=>'',text=>'...'},
10138: {href=>'',text=>'Modify grades'}]);
1.608 www 10139: &processGroup($request,$symb);
1.104 albertel 10140: } elsif ($command eq 'gradingmenu' && $perm{'vgr'}) {
1.608 www 10141: &startpage($request,$symb);
10142: $request->print(&grading_menu($request,$symb));
1.598 www 10143: } elsif ($command eq 'individual' && $perm{'vgr'}) {
1.617 www 10144: &startpage($request,$symb,[{href=>'',text=>'Select individual students to grade'}]);
1.608 www 10145: $request->print(&submit_options($request,$symb));
1.598 www 10146: } elsif ($command eq 'ungraded' && $perm{'vgr'}) {
1.617 www 10147: &startpage($request,$symb,[{href=>'',text=>'Grade ungraded submissions'}]);
10148: $request->print(&listStudents($request,$symb,'graded'));
1.598 www 10149: } elsif ($command eq 'table' && $perm{'vgr'}) {
1.614 www 10150: &startpage($request,$symb,[{href=>"", text=>"Grading table"}]);
1.611 www 10151: $request->print(&submit_options_table($request,$symb));
1.598 www 10152: } elsif ($command eq 'all_for_one' && $perm{'vgr'}) {
1.615 www 10153: &startpage($request,$symb,[{href=>'',text=>'Grade page/folder for one student'}],1,1);
1.608 www 10154: $request->print(&submit_options_sequence($request,$symb));
1.104 albertel 10155: } elsif ($command eq 'viewgrades' && $perm{'vgr'}) {
1.614 www 10156: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,"table"), text=>"Grading table"},{href=>'', text=>"Modify grades"}]);
1.608 www 10157: $request->print(&viewgrades($request,$symb));
1.104 albertel 10158: } elsif ($command eq 'handgrade' && $perm{'mgr'}) {
1.620 www 10159: &startpage($request,$symb,[{href=>'',text=>'...'},
10160: {href=>'',text=>'Store grades'}]);
1.608 www 10161: $request->print(&processHandGrade($request,$symb));
1.106 albertel 10162: } elsif ($command eq 'editgrades' && $perm{'mgr'}) {
1.614 www 10163: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,"table"), text=>"Grading table"},
10164: {href=>&href_symb_cmd($symb,'viewgrades').'&group=all§ion=all&Status=Active',
10165: text=>"Modify grades"},
10166: {href=>'', text=>"Store grades"}]);
1.608 www 10167: $request->print(&editgrades($request,$symb));
1.602 www 10168: } elsif ($command eq 'initialverifyreceipt' && $perm{'vgr'}) {
1.616 www 10169: &startpage($request,$symb,[{href=>'',text=>'Verify Receipt Number'}]);
1.611 www 10170: $request->print(&initialverifyreceipt($request,$symb));
1.106 albertel 10171: } elsif ($command eq 'verify' && $perm{'vgr'}) {
1.616 www 10172: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,"initialverifyreceipt"),text=>'Verify Receipt Number'},
10173: {href=>'',text=>'Verification Result'}]);
1.608 www 10174: $request->print(&verifyreceipt($request,$symb));
1.400 www 10175: } elsif ($command eq 'processclicker' && $perm{'mgr'}) {
1.615 www 10176: &startpage($request,$symb,[{href=>'', text=>'Process clicker'}]);
1.608 www 10177: $request->print(&process_clicker($request,$symb));
1.400 www 10178: } elsif ($command eq 'processclickerfile' && $perm{'mgr'}) {
1.615 www 10179: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'processclicker'), text=>'Process clicker'},
10180: {href=>'', text=>'Process clicker file'}]);
1.608 www 10181: $request->print(&process_clicker_file($request,$symb));
1.414 www 10182: } elsif ($command eq 'assignclickergrades' && $perm{'mgr'}) {
1.615 www 10183: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'processclicker'), text=>'Process clicker'},
10184: {href=>'', text=>'Process clicker file'},
10185: {href=>'', text=>'Store grades'}]);
1.608 www 10186: $request->print(&assign_clicker_grades($request,$symb));
1.106 albertel 10187: } elsif ($command eq 'csvform' && $perm{'mgr'}) {
1.627 www 10188: &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
1.608 www 10189: $request->print(&upcsvScores_form($request,$symb));
1.106 albertel 10190: } elsif ($command eq 'csvupload' && $perm{'mgr'}) {
1.627 www 10191: &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
1.608 www 10192: $request->print(&csvupload($request,$symb));
1.106 albertel 10193: } elsif ($command eq 'csvuploadmap' && $perm{'mgr'} ) {
1.627 www 10194: &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
1.608 www 10195: $request->print(&csvuploadmap($request,$symb));
1.246 albertel 10196: } elsif ($command eq 'csvuploadoptions' && $perm{'mgr'}) {
1.257 albertel 10197: if ($env{'form.associate'} ne 'Reverse Association') {
1.627 www 10198: &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
1.608 www 10199: $request->print(&csvuploadoptions($request,$symb));
1.41 ng 10200: } else {
1.257 albertel 10201: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
10202: $env{'form.upfile_associate'} = 'reverse';
1.41 ng 10203: } else {
1.257 albertel 10204: $env{'form.upfile_associate'} = 'forward';
1.41 ng 10205: }
1.627 www 10206: &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
1.608 www 10207: $request->print(&csvuploadmap($request,$symb));
1.41 ng 10208: }
1.246 albertel 10209: } elsif ($command eq 'csvuploadassign' && $perm{'mgr'} ) {
1.627 www 10210: &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
1.608 www 10211: $request->print(&csvuploadassign($request,$symb));
1.106 albertel 10212: } elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
1.616 www 10213: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.612 www 10214: $request->print(&scantron_selectphase($request,undef,$symb));
1.203 albertel 10215: } elsif ($command eq 'scantron_warning' && $perm{'mgr'}) {
1.616 www 10216: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 10217: $request->print(&scantron_do_warning($request,$symb));
1.142 albertel 10218: } elsif ($command eq 'scantron_validate' && $perm{'mgr'}) {
1.616 www 10219: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 10220: $request->print(&scantron_validate_file($request,$symb));
1.106 albertel 10221: } elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
1.616 www 10222: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 10223: $request->print(&scantron_process_students($request,$symb));
1.157 albertel 10224: } elsif ($command eq 'scantronupload' &&
1.257 albertel 10225: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
10226: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.616 www 10227: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 10228: $request->print(&scantron_upload_scantron_data($request,$symb));
1.157 albertel 10229: } elsif ($command eq 'scantronupload_save' &&
1.257 albertel 10230: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
10231: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.616 www 10232: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 10233: $request->print(&scantron_upload_scantron_data_save($request,$symb));
1.202 albertel 10234: } elsif ($command eq 'scantron_download' &&
1.257 albertel 10235: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.616 www 10236: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 10237: $request->print(&scantron_download_scantron_data($request,$symb));
1.523 raeburn 10238: } elsif ($command eq 'checksubmissions' && $perm{'vgr'}) {
1.616 www 10239: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.621 www 10240: $request->print(&checkscantron_results($request,$symb));
10241: } elsif ($command eq 'downloadfilesselect' && $perm{'vgr'}) {
10242: &startpage($request,$symb,[{href=>'', text=>'Select which submissions to download'}]);
10243: $request->print(&submit_options_download($request,$symb));
10244: } elsif ($command eq 'downloadfileslink' && $perm{'vgr'}) {
10245: &startpage($request,$symb,
10246: [{href=>&href_symb_cmd($symb,'downloadfilesselect'), text=>'Select which submissions to download'},
10247: {href=>'', text=>'Download submissions'}]);
10248: &submit_download_link($request,$symb);
1.106 albertel 10249: } elsif ($command) {
1.620 www 10250: &startpage($request,$symb,[{href=>'', text=>'Access denied'}]);
1.562 bisitz 10251: $request->print('<p class="LC_error">'.&mt('Access Denied ([_1])',$command).'</p>');
1.26 albertel 10252: }
1.2 albertel 10253: }
1.513 foxr 10254: if ($ssi_error) {
10255: &ssi_print_error($request);
10256: }
1.671 raeburn 10257: if ($env{'form.inhibitmenu'}) {
10258: $request->print(&Apache::loncommon::end_page());
10259: } else {
10260: &Apache::lonquickgrades::endGradeScreen($request);
10261: }
1.434 albertel 10262: &reset_caches();
1.646 raeburn 10263: return OK;
1.44 ng 10264: }
10265:
1.1 albertel 10266: 1;
10267:
1.13 albertel 10268: __END__;
1.531 jms 10269:
10270:
10271: =head1 NAME
10272:
10273: Apache::grades
10274:
10275: =head1 SYNOPSIS
10276:
10277: Handles the viewing of grades.
10278:
10279: This is part of the LearningOnline Network with CAPA project
10280: described at http://www.lon-capa.org.
10281:
10282: =head1 OVERVIEW
10283:
10284: Do an ssi with retries:
10285: While I'd love to factor out this with the vesrion in lonprintout,
10286: 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
10287: I'm not quite ready to invent (e.g. an ssi_with_retry object).
10288:
10289: At least the logic that drives this has been pulled out into loncommon.
10290:
10291:
10292:
10293: ssi_with_retries - Does the server side include of a resource.
10294: if the ssi call returns an error we'll retry it up to
10295: the number of times requested by the caller.
10296: If we still have a proble, no text is appended to the
10297: output and we set some global variables.
10298: to indicate to the caller an SSI error occurred.
10299: All of this is supposed to deal with the issues described
10300: in LonCAPA BZ 5631 see:
10301: http://bugs.lon-capa.org/show_bug.cgi?id=5631
10302: by informing the user that this happened.
10303:
10304: Parameters:
10305: resource - The resource to include. This is passed directly, without
10306: interpretation to lonnet::ssi.
10307: form - The form hash parameters that guide the interpretation of the resource
10308:
10309: retries - Number of retries allowed before giving up completely.
10310: Returns:
10311: On success, returns the rendered resource identified by the resource parameter.
10312: Side Effects:
10313: The following global variables can be set:
10314: ssi_error - If an unrecoverable error occurred this becomes true.
10315: It is up to the caller to initialize this to false
10316: if desired.
10317: ssi_error_resource - If an unrecoverable error occurred, this is the value
10318: of the resource that could not be rendered by the ssi
10319: call.
10320: ssi_error_message - The error string fetched from the ssi response
10321: in the event of an error.
10322:
10323:
10324: =head1 HANDLER SUBROUTINE
10325:
10326: ssi_with_retries()
10327:
10328: =head1 SUBROUTINES
10329:
10330: =over
10331:
1.671 raeburn 10332: =head1 Routines to display previous version of a Task for a specific student
10333:
10334: Tasks are graded pass/fail. Students who have yet to pass a particular Task
10335: can receive another opportunity. Access to tasks is slot-based. If a slot
10336: requires a proctor to check-in the student, a new version of the Task will
10337: be created when the student is checked in to the new opportunity.
10338:
10339: If a particular student has tried two or more versions of a particular task,
10340: the submission screen provides a user with vgr privileges (e.g., a Course
10341: Coordinator) the ability to display a previous version worked on by the
10342: student. By default, the current version is displayed. If a previous version
10343: has been selected for display, submission data are only shown that pertain
10344: to that particular version, and the interface to submit grades is not shown.
10345:
10346: =over 4
10347:
10348: =item show_previous_task_version()
10349:
10350: Displays a specified version of a student's Task, as the student sees it.
10351:
10352: Inputs: 2
10353: request - request object
10354: symb - unique symb for current instance of resource
10355:
10356: Output: None.
10357:
10358: Side Effects: calls &show_problem() to print version of Task, with
10359: version contained in form item: $env{'form.previousversion'}
10360:
10361: =item choose_task_version_form()
10362:
10363: Displays a web form used to select which version of a student's view of a
10364: Task should be displayed. Either launches a pop-up window, or replaces
10365: content in existing pop-up, or replaces page in main window.
10366:
10367: Inputs: 4
10368: symb - unique symb for current instance of resource
10369: uname - username of student
10370: udom - domain of student
10371: nomenu - 1 if display is in a pop-up window, and hence no menu
10372: breadcrumbs etc., are displayed
10373:
10374: Output: 4
10375: current - student's current version
10376: displayed - student's version being displayed
10377: result - scalar containing HTML for web form used to switch to
10378: a different version (or a link to close window, if pop-up).
10379: js - javascript for processing selection in versions web form
10380:
10381: Side Effects: None.
10382:
10383: =item previous_display_javascript()
10384:
10385: Inputs: 2
10386: nomenu - 1 if display is in a pop-up window, and hence no menu
10387: breadcrumbs etc., are displayed.
10388: current - student's current version number.
10389:
10390: Output: 1
10391: js - javascript for processing selection in versions web form.
10392:
10393: Side Effects: None.
10394:
10395: =back
10396:
10397: =head1 Routines to process bubblesheet data.
10398:
10399: =over 4
10400:
1.531 jms 10401: =item scantron_get_correction() :
10402:
10403: Builds the interface screen to interact with the operator to fix a
10404: specific error condition in a specific scanline
10405:
10406: Arguments:
10407: $r - Apache request object
10408: $i - number of the current scanline
10409: $scan_record - hash ref as returned from &scantron_parse_scanline()
10410: $scan_config - hash ref as returned from &get_scantron_config()
10411: $line - full contents of the current scanline
10412: $error - error condition, valid values are
10413: 'incorrectCODE', 'duplicateCODE',
10414: 'doublebubble', 'missingbubble',
10415: 'duplicateID', 'incorrectID'
10416: $arg - extra information needed
10417: For errors:
10418: - duplicateID - paper number that this studentID was seen before on
10419: - duplicateCODE - array ref of the paper numbers this CODE was
10420: seen on before
10421: - incorrectCODE - current incorrect CODE
10422: - doublebubble - array ref of the bubble lines that have double
10423: bubble errors
10424: - missingbubble - array ref of the bubble lines that have missing
10425: bubble errors
10426:
1.691 raeburn 10427: $randomorder - True if exam folder has randomorder set
10428: $randompick - True if exam folder has randompick set
10429: $respnumlookup - Reference to HASH mapping question numbers in bubble lines
10430: for current line to question number used for same question
10431: in "Master Seqence" (as seen by Course Coordinator).
10432: $startline - Reference to hash where key is question number (0 is first)
10433: and value is number of first bubble line for current student
10434: or code-based randompick and/or randomorder.
10435:
10436:
10437:
1.531 jms 10438: =item scantron_get_maxbubble() :
10439:
1.582 raeburn 10440: Arguments:
10441: $nav_error - Reference to scalar which is a flag to indicate a
10442: failure to retrieve a navmap object.
10443: if $nav_error is set to 1 by scantron_get_maxbubble(), the
10444: calling routine should trap the error condition and display the warning
10445: found in &navmap_errormsg().
10446:
1.649 raeburn 10447: $scantron_config - Reference to bubblesheet format configuration hash.
10448:
1.531 jms 10449: Returns the maximum number of bubble lines that are expected to
10450: occur. Does this by walking the selected sequence rendering the
10451: resource and then checking &Apache::lonxml::get_problem_counter()
10452: for what the current value of the problem counter is.
10453:
10454: Caches the results to $env{'form.scantron_maxbubble'},
10455: $env{'form.scantron.bubble_lines.n'},
10456: $env{'form.scantron.first_bubble_line.n'} and
10457: $env{"form.scantron.sub_bubblelines.n"}
1.691 raeburn 10458: which are the total number of bubble lines, the number of bubble
1.531 jms 10459: lines for response n and number of the first bubble line for response n,
10460: and a comma separated list of numbers of bubble lines for sub-questions
10461: (for optionresponse, matchresponse, and rankresponse items), for response n.
10462:
10463:
10464: =item scantron_validate_missingbubbles() :
10465:
10466: Validates all scanlines in the selected file to not have any
10467: answers that don't have bubbles that have not been verified
10468: to be bubble free.
10469:
10470: =item scantron_process_students() :
10471:
1.659 raeburn 10472: Routine that does the actual grading of the bubblesheet information.
1.531 jms 10473:
10474: The parsed scanline hash is added to %env
10475:
10476: Then foreach unskipped scanline it does an &Apache::lonnet::ssi()
10477: foreach resource , with the form data of
10478:
10479: 'submitted' =>'scantron'
10480: 'grade_target' =>'grade',
10481: 'grade_username'=> username of student
10482: 'grade_domain' => domain of student
10483: 'grade_courseid'=> of course
10484: 'grade_symb' => symb of resource to grade
10485:
10486: This triggers a grading pass. The problem grading code takes care
10487: of converting the bubbled letter information (now in %env) into a
10488: valid submission.
10489:
10490: =item scantron_upload_scantron_data() :
10491:
1.659 raeburn 10492: Creates the screen for adding a new bubblesheet data file to a course.
1.531 jms 10493:
10494: =item scantron_upload_scantron_data_save() :
10495:
10496: Adds a provided bubble information data file to the course if user
10497: has the correct privileges to do so.
10498:
10499: =item valid_file() :
10500:
10501: Validates that the requested bubble data file exists in the course.
10502:
10503: =item scantron_download_scantron_data() :
10504:
10505: Shows a list of the three internal files (original, corrected,
1.659 raeburn 10506: skipped) for a specific bubblesheet data file that exists in the
1.531 jms 10507: course.
10508:
10509: =item scantron_validate_ID() :
10510:
10511: Validates all scanlines in the selected file to not have any
1.556 weissno 10512: invalid or underspecified student/employee IDs
1.531 jms 10513:
1.582 raeburn 10514: =item navmap_errormsg() :
10515:
10516: Returns HTML mark-up inside a <div></div> with a link to re-initialize the course.
1.671 raeburn 10517: Should be called whenever the request to instantiate a navmap object fails.
10518:
10519: =back
1.582 raeburn 10520:
1.531 jms 10521: =back
10522:
10523: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>