Annotation of loncom/homework/grades.pm, revision 1.699
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.699 ! kruse 4: # $Id: grades.pm,v 1.698 2013/07/24 15:12:33 kruse 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.699 ! kruse 911: &mt('last submission').' </label></span>'."\n".
1.592 bisitz 912: '<span class="LC_nobreak">'.
913: '<label><input type="radio" name="lastSub" value="last" /> '.
1.699 ! kruse 914: &mt('last submission with details').' </label></span>'."\n".
1.592 bisitz 915: '<span class="LC_nobreak">'.
1.628 www 916: '<label><input type="radio" name="lastSub" value="datesub" checked="checked" /> '.
1.699 ! kruse 917: &mt('all submissions').'</label></span>'."\n".
1.592 bisitz 918: '<span class="LC_nobreak">'.
919: '<label><input type="radio" name="lastSub" value="all" /> '.
1.699 ! kruse 920: &mt('all submissions with details').'</label></span>';
! 921: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Submissions'))
1.561 bisitz 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.695 bisitz 1705: my $data_WGT='<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.695 bisitz 1713: my $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.695 bisitz 1750: '<td>'.$data_WGT.$display_part.'</td><td>'.$radio.'</td><td>'.&mt('or').'</td><td>'.$line.'</td>';
1.585 bisitz 1751: $result.=&Apache::loncommon::end_data_table_row();
1.695 bisitz 1752: $result.=&Apache::loncommon::start_data_table_row().'<td colspan="6">';
1.71 ng 1753: $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="" />'."\n".
1754: '<input type="hidden" name="oldpts'.$counter.'_'.$partid.'" value="'.$score.'" />'."\n".
1755: '<input type="hidden" name="solved'.$counter.'_'.$partid.'" value="'.
1.269 raeburn 1756: $$record{'resource.'.$partid.'.solved'}.'" />'."\n".
1757: '<input type="hidden" name="totaltries'.$counter.'_'.$partid.'" value="'.
1758: $$record{'resource.'.$partid.'.tries'}.'" />'."\n".
1759: '<input type="hidden" name="aggtries'.$counter.'_'.$partid.'" value="'.
1760: $aggtries.'" />'."\n";
1.582 raeburn 1761: my $res_error;
1762: $result.=&handback_box($symb,$uname,$udom,$counter,$partid,$record,\$res_error);
1.695 bisitz 1763: $result.='</td>'.&Apache::loncommon::end_data_table_row();
1.582 raeburn 1764: if ($res_error) {
1765: return &navmap_errormsg();
1766: }
1.318 banghart 1767: return $result;
1768: }
1.322 albertel 1769:
1770: sub handback_box {
1.623 www 1771: my ($symb,$uname,$udom,$counter,$partid,$record,$res_error_pointer) = @_;
1772: my ($partlist,$handgrade,$responseType) = &response_type($symb,$res_error_pointer);
1.323 banghart 1773: my (@respids);
1.652 raeburn 1774: my @part_response_id = &flatten_responseType($responseType);
1.375 albertel 1775: foreach my $part_response_id (@part_response_id) {
1776: my ($part,$resp) = @{ $part_response_id };
1.323 banghart 1777: if ($part eq $partid) {
1.375 albertel 1778: push(@respids,$resp);
1.323 banghart 1779: }
1780: }
1.318 banghart 1781: my $result;
1.323 banghart 1782: foreach my $respid (@respids) {
1.322 albertel 1783: my $prefix = $counter.'_'.$partid.'_'.$respid.'_';
1784: my $files=&get_submitted_files($udom,$uname,$partid,$respid,$record);
1785: next if (!@$files);
1.654 raeburn 1786: my $file_counter = 0;
1.313 banghart 1787: foreach my $file (@$files) {
1.368 banghart 1788: if ($file =~ /\/portfolio\//) {
1.654 raeburn 1789: $file_counter++;
1.368 banghart 1790: my ($file_path, $file_disp) = ($file =~ m|(.+/)(.+)$|);
1791: my ($name,$version,$ext) = &file_name_version_ext($file_disp);
1792: $file_disp = "$name.$ext";
1793: $file = $file_path.$file_disp;
1794: $result.=&mt('Return commented version of [_1] to student.',
1795: '<span class="LC_filename">'.$file_disp.'</span>');
1796: $result.='<input type="file" name="'.$prefix.'returndoc'.$file_counter.'" />'."\n";
1.654 raeburn 1797: $result.='<input type="hidden" name="'.$prefix.'origdoc'.$file_counter.'" value="'.$file.'" /><br />'."\n";
1.368 banghart 1798: }
1.322 albertel 1799: }
1.654 raeburn 1800: if ($file_counter) {
1801: $result .= '<input type="hidden" name="'.$prefix.'countreturndoc" value="'.$file_counter.'" />'."\n".
1802: '<span class="LC_info">'.
1803: '('.&mt('File(s) will be uploaded when you click on Save & Next below.',$file_counter).')</span><br /><br />';
1804: }
1.313 banghart 1805: }
1.318 banghart 1806: return $result;
1.71 ng 1807: }
1.44 ng 1808:
1.58 albertel 1809: sub show_problem {
1.382 albertel 1810: my ($request,$symb,$uname,$udom,$removeform,$viewon,$mode,$form) = @_;
1.144 albertel 1811: my $rendered;
1.382 albertel 1812: my %form = ((ref($form) eq 'HASH')? %{$form} : ());
1.329 albertel 1813: &Apache::lonxml::remember_problem_counter();
1.144 albertel 1814: if ($mode eq 'both' or $mode eq 'text') {
1815: $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
1.382 albertel 1816: $env{'request.course.id'},
1817: undef,\%form);
1.144 albertel 1818: }
1.58 albertel 1819: if ($removeform) {
1820: $rendered=~s|<form(.*?)>||g;
1821: $rendered=~s|</form>||g;
1.374 albertel 1822: $rendered=~s|(<input[^>]*name\s*=\s*"?)(\w+)("?)|$1would_have_been_$2$3|g;
1.58 albertel 1823: }
1.144 albertel 1824: my $companswer;
1825: if ($mode eq 'both' or $mode eq 'answer') {
1.329 albertel 1826: &Apache::lonxml::restore_problem_counter();
1.382 albertel 1827: $companswer=
1828: &Apache::loncommon::get_student_answers($symb,$uname,$udom,
1829: $env{'request.course.id'},
1830: %form);
1.144 albertel 1831: }
1.58 albertel 1832: if ($removeform) {
1833: $companswer=~s|<form(.*?)>||g;
1834: $companswer=~s|</form>||g;
1.144 albertel 1835: $companswer=~s|name="submit"|name="would_have_been_submit"|g;
1.58 albertel 1836: }
1.671 raeburn 1837: my $renderheading = &mt('View of the problem');
1838: my $answerheading = &mt('Correct answer');
1839: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1840: my $stu_fullname = $env{'form.fullname'};
1841: if ($stu_fullname eq '') {
1842: $stu_fullname = &Apache::loncommon::plainname($uname,$udom,'lastname');
1843: }
1844: my $forwhom = &nameUserString(undef,$stu_fullname,$uname,$udom);
1845: if ($forwhom ne '') {
1846: $renderheading = &mt('View of the problem for[_1]',$forwhom);
1847: $answerheading = &mt('Correct answer for[_1]',$forwhom);
1848: }
1849: }
1.468 albertel 1850: $rendered=
1.588 bisitz 1851: '<div class="LC_Box">'
1.671 raeburn 1852: .'<h3 class="LC_hcell">'.$renderheading.'</h3>'
1.588 bisitz 1853: .$rendered
1854: .'</div>';
1.468 albertel 1855: $companswer=
1.588 bisitz 1856: '<div class="LC_Box">'
1.671 raeburn 1857: .'<h3 class="LC_hcell">'.$answerheading.'</h3>'
1.588 bisitz 1858: .$companswer
1859: .'</div>';
1.468 albertel 1860: my $result;
1.144 albertel 1861: if ($mode eq 'both') {
1.588 bisitz 1862: $result=$rendered.$companswer;
1.144 albertel 1863: } elsif ($mode eq 'text') {
1.588 bisitz 1864: $result=$rendered;
1.144 albertel 1865: } elsif ($mode eq 'answer') {
1.588 bisitz 1866: $result=$companswer;
1.144 albertel 1867: }
1.71 ng 1868: return $result;
1.58 albertel 1869: }
1.397 albertel 1870:
1.396 banghart 1871: sub files_exist {
1872: my ($r, $symb) = @_;
1873: my @students = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.397 albertel 1874:
1.396 banghart 1875: foreach my $student (@students) {
1876: my ($uname,$udom,$fullname) = split(/:/,$student);
1.397 albertel 1877: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1878: $udom,$uname);
1.396 banghart 1879: my ($string,$timestamp)= &get_last_submission(\%record);
1.397 albertel 1880: foreach my $submission (@$string) {
1881: my ($partid,$respid) =
1882: ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
1883: my $files=&get_submitted_files($udom,$uname,$partid,$respid,
1884: \%record);
1885: return 1 if (@$files);
1.396 banghart 1886: }
1887: }
1.397 albertel 1888: return 0;
1.396 banghart 1889: }
1.397 albertel 1890:
1.394 banghart 1891: sub download_all_link {
1892: my ($r,$symb) = @_;
1.621 www 1893: unless (&files_exist($r, $symb)) {
1894: $r->print(&mt('There are currently no submitted documents.'));
1895: return;
1896: }
1897:
1.395 albertel 1898: my $all_students =
1899: join("\n", &Apache::loncommon::get_env_multiple('form.stuinfo'));
1900:
1901: my $parts =
1902: join("\n",&Apache::loncommon::get_env_multiple('form.vPart'));
1903:
1.394 banghart 1904: my $identifier = &Apache::loncommon::get_cgi_id();
1.514 raeburn 1905: &Apache::lonnet::appenv({'cgi.'.$identifier.'.students' => $all_students,
1906: 'cgi.'.$identifier.'.symb' => $symb,
1907: 'cgi.'.$identifier.'.parts' => $parts,});
1.395 albertel 1908: $r->print('<a href="/cgi-bin/multidownload.pl?'.$identifier.'">'.
1909: &mt('Download All Submitted Documents').'</a>');
1.621 www 1910: return;
1911: }
1912:
1913: sub submit_download_link {
1914: my ($request,$symb) = @_;
1915: if (!$symb) { return ''; }
1916: #FIXME: Figure out which type of problem this is and provide appropriate download
1917: &download_all_link($request,$symb);
1.394 banghart 1918: }
1.395 albertel 1919:
1.432 banghart 1920: sub build_section_inputs {
1921: my $section_inputs;
1922: if ($env{'form.section'} eq '') {
1923: $section_inputs .= '<input type="hidden" name="section" value="all" />'."\n";
1924: } else {
1925: my @sections = &Apache::loncommon::get_env_multiple('form.section');
1.434 albertel 1926: foreach my $section (@sections) {
1.432 banghart 1927: $section_inputs .= '<input type="hidden" name="section" value="'.$section.'" />'."\n";
1928: }
1929: }
1930: return $section_inputs;
1931: }
1932:
1.44 ng 1933: # --------------------------- show submissions of a student, option to grade
1934: sub submission {
1.608 www 1935: my ($request,$counter,$total,$symb) = @_;
1.257 albertel 1936: my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
1937: $udom = ($udom eq '' ? $env{'user.domain'} : $udom); #has form.userdom changed for a student?
1938: my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
1939: $env{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $env{'form.fullname'} eq '';
1.608 www 1940:
1.605 www 1941: my $probtitle=&Apache::lonnet::gettitle($symb);
1.324 albertel 1942: if ($symb eq '') { $request->print("Unable to handle ambiguous references:."); return ''; }
1.104 albertel 1943:
1944: if (!&canview($usec)) {
1.398 albertel 1945: $request->print('<span class="LC_warning">Unable to view requested student.('.
1946: $uname.':'.$udom.' in section '.$usec.' in course id '.
1947: $env{'request.course.id'}.')</span>');
1.104 albertel 1948: return;
1949: }
1950:
1.257 albertel 1951: if (!$env{'form.lastSub'}) { $env{'form.lastSub'} = 'datesub'; }
1952: if (!$env{'form.vProb'}) { $env{'form.vProb'} = 'yes'; }
1953: if (!$env{'form.vAns'}) { $env{'form.vAns'} = 'yes'; }
1954: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.381 albertel 1955: my $checkIcon = '<img alt="'.&mt('Check Mark').
1956: '" src="'.$request->dir_config('lonIconsURL').
1.122 ng 1957: '/check.gif" height="16" border="0" />';
1.41 ng 1958:
1959: # header info
1960: if ($counter == 0) {
1961: &sub_page_js($request);
1.621 www 1962: &sub_page_kw_js($request);
1.118 ng 1963:
1.44 ng 1964: # option to display problem, only once else it cause problems
1965: # with the form later since the problem has a form.
1.257 albertel 1966: if ($env{'form.vProb'} eq 'yes' or $env{'form.vAns'} eq 'yes') {
1.144 albertel 1967: my $mode;
1.257 albertel 1968: if ($env{'form.vProb'} eq 'yes' && $env{'form.vAns'} eq 'yes') {
1.144 albertel 1969: $mode='both';
1.257 albertel 1970: } elsif ($env{'form.vProb'} eq 'yes') {
1.144 albertel 1971: $mode='text';
1.257 albertel 1972: } elsif ($env{'form.vAns'} eq 'yes') {
1.144 albertel 1973: $mode='answer';
1974: }
1.329 albertel 1975: &Apache::lonxml::clear_problem_counter();
1.144 albertel 1976: $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
1.41 ng 1977: }
1.441 www 1978:
1.44 ng 1979: # kwclr is the only variable that is guaranteed to be non blank
1980: # if this subroutine has been called once.
1.41 ng 1981: my %keyhash = ();
1.624 www 1982: # if ($env{'form.kwclr'} eq '' && $env{'form.handgrade'} eq 'yes') {
1983: if (1) {
1.41 ng 1984: %keyhash = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 1985: $env{'course.'.$env{'request.course.id'}.'.domain'},
1986: $env{'course.'.$env{'request.course.id'}.'.num'});
1.41 ng 1987:
1.257 albertel 1988: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1989: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
1990: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
1991: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
1992: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
1993: $env{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
1.605 www 1994: $keyhash{$symb.'_subject'} : $probtitle;
1.257 albertel 1995: $env{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1.41 ng 1996: }
1.257 albertel 1997: my $overRideScore = $env{'form.overRideScore'} eq '' ? 'no' : $env{'form.overRideScore'};
1.442 banghart 1998: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.303 banghart 1999: $request->print('<form action="/adm/grades" method="post" name="SCORE" enctype="multipart/form-data">'."\n".
1.41 ng 2000: '<input type="hidden" name="command" value="handgrade" />'."\n".
1.442 banghart 2001: '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.120 ng 2002: '<input type="hidden" name="overRideScore" value="'.$overRideScore.'" />'."\n".
1.41 ng 2003: '<input type="hidden" name="refresh" value="off" />'."\n".
1.120 ng 2004: '<input type="hidden" name="studentNo" value="" />'."\n".
2005: '<input type="hidden" name="gradeOpt" value="" />'."\n".
1.418 albertel 2006: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 2007: '<input type="hidden" name="vProb" value="'.$env{'form.vProb'}.'" />'."\n".
2008: '<input type="hidden" name="vAns" value="'.$env{'form.vAns'}.'" />'."\n".
2009: '<input type="hidden" name="lastSub" value="'.$env{'form.lastSub'}.'" />'."\n".
1.432 banghart 2010: &build_section_inputs().
1.326 albertel 2011: '<input type="hidden" name="submitonly" value="'.$env{'form.submitonly'}.'" />'."\n".
1.41 ng 2012: '<input type="hidden" name="NCT"'.
1.257 albertel 2013: ' value="'.($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : $total+1).'" />'."\n");
1.624 www 2014: # if ($env{'form.handgrade'} eq 'yes') {
2015: if (1) {
1.257 albertel 2016: $request->print('<input type="hidden" name="keywords" value="'.$env{'form.keywords'}.'" />'."\n".
2017: '<input type="hidden" name="kwclr" value="'.$env{'form.kwclr'}.'" />'."\n".
2018: '<input type="hidden" name="kwsize" value="'.$env{'form.kwsize'}.'" />'."\n".
2019: '<input type="hidden" name="kwstyle" value="'.$env{'form.kwstyle'}.'" />'."\n".
2020: '<input type="hidden" name="msgsub" value="'.$env{'form.msgsub'}.'" />'."\n".
1.123 ng 2021: '<input type="hidden" name="shownSub" value="0" />'."\n".
1.257 albertel 2022: '<input type="hidden" name="savemsgN" value="'.$env{'form.savemsgN'}.'" />'."\n");
1.154 albertel 2023: foreach my $partid (&Apache::loncommon::get_env_multiple('form.vPart')) {
2024: $request->print('<input type="hidden" name="vPart" value="'.$partid.'" />'."\n");
2025: }
1.123 ng 2026: }
1.41 ng 2027:
2028: my ($cts,$prnmsg) = (1,'');
1.257 albertel 2029: while ($cts <= $env{'form.savemsgN'}) {
1.41 ng 2030: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
1.123 ng 2031: (!exists($keyhash{$symb.'_savemsg'.$cts}) ?
1.257 albertel 2032: &Apache::lonfeedback::clear_out_html($env{'form.savemsg'.$cts}) :
1.80 ng 2033: &Apache::lonfeedback::clear_out_html($keyhash{$symb.'_savemsg'.$cts})).
1.123 ng 2034: '" />'."\n".
2035: '<input type="hidden" name="shownOnce'.$cts.'" value="0" />'."\n";
1.41 ng 2036: $cts++;
2037: }
2038: $request->print($prnmsg);
1.32 ng 2039:
1.624 www 2040: # if ($env{'form.handgrade'} eq 'yes') {
2041: if (1) {
1.652 raeburn 2042:
2043: my %lt = &Apache::lonlocal::texthash(
2044: keyw => 'Keyword Options',
1.655 raeburn 2045: list => 'List',
1.652 raeburn 2046: past => 'Paste Selection to List',
1.661 www 2047: high => 'Highlight Attribute',
1.652 raeburn 2048: );
1.88 www 2049: #
2050: # Print out the keyword options line
2051: #
1.41 ng 2052: $request->print(<<KEYWORDS);
1.652 raeburn 2053: <br /><b>$lt{'keyw'}:</b>
1.655 raeburn 2054: <a href="javascript:keywords(document.SCORE);" target="_self">$lt{'list'}</a>
1.589 bisitz 2055: <a href="#" onmousedown="javascript:getSel(); return false"
1.695 bisitz 2056: class="page">$lt{'past'}</a>
1.652 raeburn 2057: <a href="javascript:kwhighlight();" target="_self">$lt{'high'}</a><br /><br />
1.38 ng 2058: KEYWORDS
1.88 www 2059: #
2060: # Load the other essays for similarity check
2061: #
1.324 albertel 2062: my (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb);
1.384 albertel 2063: my ($adom,$aname,$apath)=($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
1.359 www 2064: $apath=&escape($apath);
1.88 www 2065: $apath=~s/\W/\_/gs;
1.674 raeburn 2066: &init_old_essays($symb,$apath,$adom,$aname);
1.41 ng 2067: }
2068: }
1.44 ng 2069:
1.441 www 2070: # This is where output for one specific student would start
1.592 bisitz 2071: my $add_class = ($counter%2) ? ' LC_grade_show_user_odd_row' : '';
2072: $request->print(
2073: "\n\n"
2074: .'<div class="LC_grade_show_user'.$add_class.'">'
2075: .'<h2>'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).'</h2>'
2076: ."\n"
2077: );
1.441 www 2078:
1.592 bisitz 2079: # Show additional functions if allowed
2080: if ($perm{'vgr'}) {
2081: $request->print(
2082: &Apache::loncommon::track_student_link(
2083: &mt('View recent activity'),
2084: $uname,$udom,'check')
2085: .' '
2086: );
2087: }
2088: if ($perm{'opa'}) {
2089: $request->print(
2090: &Apache::loncommon::pprmlink(
2091: &mt('Set/Change parameters'),
2092: $uname,$udom,$symb,'check'));
2093: }
2094:
2095: # Show Problem
1.257 albertel 2096: if ($env{'form.vProb'} eq 'all' or $env{'form.vAns'} eq 'all') {
1.144 albertel 2097: my $mode;
1.257 albertel 2098: if ($env{'form.vProb'} eq 'all' && $env{'form.vAns'} eq 'all') {
1.144 albertel 2099: $mode='both';
1.257 albertel 2100: } elsif ($env{'form.vProb'} eq 'all' ) {
1.144 albertel 2101: $mode='text';
1.257 albertel 2102: } elsif ($env{'form.vAns'} eq 'all') {
1.144 albertel 2103: $mode='answer';
2104: }
1.329 albertel 2105: &Apache::lonxml::clear_problem_counter();
1.475 albertel 2106: $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode,{'request.prefix' => 'ctr'.$counter}));
1.58 albertel 2107: }
1.144 albertel 2108:
1.257 albertel 2109: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.582 raeburn 2110: my $res_error;
2111: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
2112: if ($res_error) {
2113: $request->print(&navmap_errormsg());
2114: return;
2115: }
1.41 ng 2116:
1.44 ng 2117: # Display student info
1.41 ng 2118: $request->print(($counter == 0 ? '' : '<br />'));
1.590 bisitz 2119:
2120: my $result='<div class="LC_Box">'
2121: .'<h3 class="LC_hcell">'.&mt('Submissions').'</h3>';
1.45 ng 2122: $result.='<input type="hidden" name="name'.$counter.
1.588 bisitz 2123: '" value="'.$env{'form.fullname'}.'" />'."\n";
1.624 www 2124: # if ($env{'form.handgrade'} eq 'no') {
2125: if (1) {
1.588 bisitz 2126: $result.='<p class="LC_info">'
2127: .&mt('Part(s) graded correct by the computer is marked with a [_1] symbol.',$checkIcon)
2128: ."</p>\n";
1.469 albertel 2129: }
2130:
1.118 ng 2131: # If any part of the problem is an essay-response (handgraded), then check for collaborators
1.464 albertel 2132: my $fullname;
2133: my $col_fullnames = [];
1.624 www 2134: # if ($env{'form.handgrade'} eq 'yes') {
2135: if (1) {
1.464 albertel 2136: (my $sub_result,$fullname,$col_fullnames)=
2137: &check_collaborators($symb,$uname,$udom,\%record,$handgrade,
2138: $counter);
2139: $result.=$sub_result;
1.41 ng 2140: }
1.44 ng 2141: $request->print($result."\n");
1.588 bisitz 2142:
1.44 ng 2143: # print student answer/submission
1.588 bisitz 2144: # Options are (1) Handgraded submission only
1.44 ng 2145: # (2) Last submission, includes submission that is not handgraded
2146: # (for multi-response type part)
2147: # (3) Last submission plus the parts info
2148: # (4) The whole record for this student
1.257 albertel 2149: if ($env{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
1.151 albertel 2150: my ($string,$timestamp)= &get_last_submission(\%record);
1.468 albertel 2151:
2152: my $lastsubonly;
2153:
1.588 bisitz 2154: if ($$timestamp eq '') {
2155: $lastsubonly.='<div class="LC_grade_submissions_body">'.$$string[0].'</div>';
2156: } else {
1.592 bisitz 2157: $lastsubonly =
2158: '<div class="LC_grade_submissions_body">'
2159: .'<b>'.&mt('Date Submitted:').'</b> '.$$timestamp."\n";
1.468 albertel 2160:
1.151 albertel 2161: my %seenparts;
1.375 albertel 2162: my @part_response_id = &flatten_responseType($responseType);
2163: foreach my $part (@part_response_id) {
1.393 albertel 2164: next if ($env{'form.lastSub'} eq 'hdgrade'
2165: && $$handgrade{$$part[0].'_'.$$part[1]} ne 'yes');
2166:
1.375 albertel 2167: my ($partid,$respid) = @{ $part };
1.324 albertel 2168: my $display_part=&get_display_part($partid,$symb);
1.257 albertel 2169: if ($env{"form.$uname:$udom:$partid:submitted_by"}) {
1.151 albertel 2170: if (exists($seenparts{$partid})) { next; }
2171: $seenparts{$partid}=1;
1.695 bisitz 2172: $request->print(
2173: '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
2174: ' <b>'.&mt('Collaborative submission by: [_1]',
2175: '<a href="javascript:viewSubmitter(\''.
2176: $env{"form.$uname:$udom:$partid:submitted_by"}.
2177: '\');" target="_self">'.
2178: $$fullname{$env{"form.$uname:$udom:$partid:submitted_by"}}.'</a>').
2179: '<br />');
1.151 albertel 2180: next;
2181: }
2182: my $responsetype = $responseType->{$partid}->{$respid};
2183: if (!exists($record{"resource.$partid.$respid.submission"})) {
1.577 bisitz 2184: $lastsubonly.="\n".'<div class="LC_grade_submission_part">'.
2185: '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
2186: ' <span class="LC_internal_info">'.
1.623 www 2187: '('.&mt('Response ID: [_1]',$respid).')'.
1.577 bisitz 2188: '</span> '.
1.539 riegler 2189: '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br /><br /></div>';
1.151 albertel 2190: next;
2191: }
1.468 albertel 2192: foreach my $submission (@$string) {
2193: my ($partid,$respid) = ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
1.375 albertel 2194: if (join('_',@{$part}) ne ($partid.'_'.$respid)) { next; }
1.596 raeburn 2195: my ($ressub,$hide,$subval) = split(/:/,$submission,3);
1.151 albertel 2196: # Similarity check
2197: my $similar='';
1.640 raeburn 2198: my ($type,$trial,$rndseed);
2199: if ($hide eq 'rand') {
2200: $type = 'randomizetry';
2201: $trial = $record{"resource.$partid.tries"};
2202: $rndseed = $record{"resource.$partid.rndseed"};
2203: }
1.257 albertel 2204: if($env{'form.checkPlag'}){
1.151 albertel 2205: my ($oname,$odom,$ocrsid,$oessay,$osim)=
1.674 raeburn 2206: &most_similar($uname,$udom,$symb,$subval);
1.151 albertel 2207: if ($osim) {
2208: $osim=int($osim*100.0);
1.426 albertel 2209: my %old_course_desc =
2210: &Apache::lonnet::coursedescription($ocrsid,
2211: {'one_time' => 1});
2212:
1.640 raeburn 2213: if ($hide eq 'anon') {
1.596 raeburn 2214: $similar='<hr /><span class="LC_warning">'.&mt("Essay was found to be similar to another essay submitted for this assignment.").'<br />'.
2215: &mt('As the current submission is for an anonymous survey, no other details are available.').'</span><hr />';
2216: } else {
2217: $similar="<hr /><h3><span class=\"LC_warning\">".
2218: &mt('Essay is [_1]% similar to an essay by [_2] in course [_3] (course id [_4]:[_5])',
2219: $osim,
2220: &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')',
2221: $old_course_desc{'description'},
2222: $old_course_desc{'num'},
2223: $old_course_desc{'domain'}).
2224: '</span></h3><blockquote><i>'.
2225: &keywords_highlight($oessay).
2226: '</i></blockquote><hr />';
2227: }
1.151 albertel 2228: }
1.150 albertel 2229: }
1.640 raeburn 2230: my $order=&get_order($partid,$respid,$symb,$uname,$udom,
2231: undef,$type,$trial,$rndseed);
1.257 albertel 2232: if ($env{'form.lastSub'} eq 'lastonly' ||
2233: ($env{'form.lastSub'} eq 'hdgrade' &&
1.377 albertel 2234: $$handgrade{$$part[0].'_'.$$part[1]} eq 'yes')) {
1.324 albertel 2235: my $display_part=&get_display_part($partid,$symb);
1.577 bisitz 2236: $lastsubonly.='<div class="LC_grade_submission_part">'.
2237: '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
2238: ' <span class="LC_internal_info">'.
1.623 www 2239: '('.&mt('Response ID: [_1]',$respid).')'.
1.597 wenzelju 2240: '</span> ';
1.313 banghart 2241: my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record);
1.698 kruse 2242:
1.313 banghart 2243: if (@$files) {
1.640 raeburn 2244: if ($hide eq 'anon') {
1.596 raeburn 2245: $lastsubonly.='<br />'.&mt('[quant,_1,file] uploaded to this anonymous survey',scalar(@{$files}));
2246: } else {
1.698 kruse 2247: $lastsubonly.='<br /><br />'.'<b>'.&mt('Submitted Files:').'</b>'
2248: .'<br /><span class="LC_warning">';
2249: if(@$files == 1) {
2250: $lastsubonly .= &mt('Like all files provided by users, this file may contain viruses!');
2251: } else {
2252: $lastsubonly .= &mt('Like all files provided by users, these files may contain viruses!');
2253: }
2254: $lastsubonly .= '</span>';
1.596 raeburn 2255: foreach my $file (@$files) {
2256: &Apache::lonnet::allowuploaded('/adm/grades',$file);
1.695 bisitz 2257: $lastsubonly.='<br /><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.&Apache::loncommon::icon($file).'" border="0" alt="" /> '.$file.'</a>';
1.596 raeburn 2258: }
2259: }
1.236 albertel 2260: $lastsubonly.='<br />';
1.41 ng 2261: }
1.640 raeburn 2262: if ($hide eq 'anon') {
1.698 kruse 2263: $lastsubonly.='<br /><b>'.&mt('Anonymous Survey').'</b>';
1.596 raeburn 2264: } else {
1.698 kruse 2265: $lastsubonly.='<br /><b>'.&mt('Submitted Answer:').' </b>'.
1.596 raeburn 2266: &cleanRecord($subval,$responsetype,$symb,$partid,
1.640 raeburn 2267: $respid,\%record,$order,undef,$uname,$udom,$type,$trial,$rndseed);
1.596 raeburn 2268: }
1.151 albertel 2269: if ($similar) {$lastsubonly.="<br /><br />$similar\n";}
1.468 albertel 2270: $lastsubonly.='</div>';
1.41 ng 2271: }
2272: }
2273: }
1.588 bisitz 2274: $lastsubonly.='</div>'."\n"; # End: LC_grade_submissions_body
1.151 albertel 2275: }
2276: $request->print($lastsubonly);
1.468 albertel 2277: } elsif ($env{'form.lastSub'} eq 'datesub') {
1.623 www 2278: my ($parts,$handgrade,$responseType) = &response_type($symb,\$res_error);
1.148 albertel 2279: $request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
1.257 albertel 2280: } elsif ($env{'form.lastSub'} =~ /^(last|all)$/) {
1.41 ng 2281: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
1.257 albertel 2282: $env{'request.course.id'},
1.44 ng 2283: $last,'.submission',
2284: 'Apache::grades::keywords_highlight'));
1.41 ng 2285: }
1.121 ng 2286: $request->print('<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
2287: .$udom.'" />'."\n");
1.44 ng 2288: # return if view submission with no grading option
1.618 www 2289: if (!&canmodify($usec)) {
1.633 www 2290: $request->print('<p><span class="LC_warning">'.&mt('No grading privileges').'</span></p></div>');
1.41 ng 2291: return;
1.180 albertel 2292: } else {
1.468 albertel 2293: $request->print('</div>'."\n");
1.41 ng 2294: }
1.33 ng 2295:
1.121 ng 2296: # essay grading message center
1.624 www 2297: # if ($env{'form.handgrade'} eq 'yes') {
2298: if (1) {
1.468 albertel 2299: my $result='<div class="LC_grade_message_center">';
2300:
2301: $result.='<div class="LC_grade_message_center_header">'.
2302: &mt('Send Message').'</div><div class="LC_grade_message_center_body">';
1.257 albertel 2303: my ($lastname,$givenn) = split(/,/,$env{'form.fullname'});
1.118 ng 2304: my $msgfor = $givenn.' '.$lastname;
1.464 albertel 2305: if (scalar(@$col_fullnames) > 0) {
2306: my $lastone = pop(@$col_fullnames);
2307: $msgfor .= ', '.(join ', ',@$col_fullnames).' and '.$lastone.'.';
1.118 ng 2308: }
2309: $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
1.468 albertel 2310: $result.='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
1.121 ng 2311: '<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n";
2312: $result.=' <a href="javascript:msgCenter(document.SCORE,'.$counter.
1.417 albertel 2313: ',\''.$msgfor.'\');" target="_self">'.
1.695 bisitz 2314: &mt('Compose message to student'.(scalar(@$col_fullnames) >= 1 ? 's' : '')).'</a><label> ('.
1.350 albertel 2315: &mt('incl. grades').' <input type="checkbox" name="withgrades'.$counter.'" /></label>)'.
1.695 bisitz 2316: ' <img src="'.$request->dir_config('lonIconsURL').
2317: '/mailbkgrd.gif" width="14" height="10" alt="" name="mailicon'.$counter.'" />'."\n".
1.298 www 2318: '<br /> ('.
1.468 albertel 2319: &mt('Message will be sent when you click on Save & Next below.').")\n";
2320: $result.='</div></div>';
1.121 ng 2321: $request->print($result);
1.118 ng 2322: }
1.41 ng 2323:
2324: my %seen = ();
2325: my @partlist;
1.129 ng 2326: my @gradePartRespid;
1.375 albertel 2327: my @part_response_id = &flatten_responseType($responseType);
1.585 bisitz 2328: $request->print(
1.588 bisitz 2329: '<div class="LC_Box">'
2330: .'<h3 class="LC_hcell">'.&mt('Assign Grades').'</h3>'
1.585 bisitz 2331: );
1.592 bisitz 2332: $request->print(&gradeBox_start());
1.375 albertel 2333: foreach my $part_response_id (@part_response_id) {
2334: my ($partid,$respid) = @{ $part_response_id };
2335: my $part_resp = join('_',@{ $part_response_id });
1.322 albertel 2336: next if ($seen{$partid} > 0);
1.41 ng 2337: $seen{$partid}++;
1.393 albertel 2338: next if ($$handgrade{$part_resp} ne 'yes'
2339: && $env{'form.lastSub'} eq 'hdgrade');
1.524 raeburn 2340: push(@partlist,$partid);
2341: push(@gradePartRespid,$partid.'.'.$respid);
1.322 albertel 2342: $request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
1.41 ng 2343: }
1.585 bisitz 2344: $request->print(&gradeBox_end()); # </div>
2345: $request->print('</div>');
1.468 albertel 2346:
2347: $request->print('<div class="LC_grade_info_links">');
2348: $request->print('</div>');
2349:
1.45 ng 2350: $result='<input type="hidden" name="partlist'.$counter.
2351: '" value="'.(join ":",@partlist).'" />'."\n";
1.129 ng 2352: $result.='<input type="hidden" name="gradePartRespid'.
2353: '" value="'.(join ":",@gradePartRespid).'" />'."\n" if ($counter == 0);
1.45 ng 2354: my $ctr = 0;
2355: while ($ctr < scalar(@partlist)) {
2356: $result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
2357: $partlist[$ctr].'" />'."\n";
2358: $ctr++;
2359: }
1.468 albertel 2360: $request->print($result.''."\n");
1.41 ng 2361:
1.441 www 2362: # Done with printing info for one student
2363:
1.468 albertel 2364: $request->print('</div>');#LC_grade_show_user
1.441 www 2365:
2366:
1.41 ng 2367: # print end of form
2368: if ($counter == $total) {
1.592 bisitz 2369: my $endform='<br /><hr /><table border="0"><tr><td>'."\n";
1.485 albertel 2370: $endform.='<input type="button" value="'.&mt('Save & Next').'" '.
1.589 bisitz 2371: 'onclick="javascript:checksubmit(this.form,\'Save & Next\','.
1.417 albertel 2372: $total.','.scalar(@partlist).');" target="_self" /> '."\n";
1.119 ng 2373: my $ntstu ='<select name="NTSTU">'.
2374: '<option>1</option><option>2</option>'.
2375: '<option>3</option><option>5</option>'.
2376: '<option>7</option><option>10</option></select>'."\n";
1.257 albertel 2377: my $nsel = ($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : '1');
1.401 albertel 2378: $ntstu =~ s/<option>$nsel</<option selected="selected">$nsel</;
1.578 raeburn 2379: $endform.=&mt('[_1]student(s)',$ntstu);
1.485 albertel 2380: $endform.=' <input type="button" value="'.&mt('Previous').'" '.
1.589 bisitz 2381: 'onclick="javascript:checksubmit(this.form,\'Previous\');" target="_self" /> '."\n".
1.485 albertel 2382: '<input type="button" value="'.&mt('Next').'" '.
1.589 bisitz 2383: 'onclick="javascript:checksubmit(this.form,\'Next\');" target="_self" /> ';
1.592 bisitz 2384: $endform.='<span class="LC_warning">'.
2385: &mt('(Next and Previous (student) do not save the scores.)').
2386: '</span>'."\n" ;
1.349 albertel 2387: $endform.="<input type='hidden' value='".&get_increment().
1.348 bowersj2 2388: "' name='increment' />";
1.485 albertel 2389: $endform.='</td></tr></table></form>';
1.41 ng 2390: $request->print($endform);
2391: }
2392: return '';
1.38 ng 2393: }
2394:
1.464 albertel 2395: sub check_collaborators {
2396: my ($symb,$uname,$udom,$record,$handgrade,$counter) = @_;
2397: my ($result,@col_fullnames);
2398: my ($classlist,undef,$fullname) = &getclasslist('all','0');
2399: foreach my $part (keys(%$handgrade)) {
2400: my $ncol = &Apache::lonnet::EXT('resource.'.$part.
2401: '.maxcollaborators',
2402: $symb,$udom,$uname);
2403: next if ($ncol <= 0);
2404: $part =~ s/\_/\./g;
2405: next if ($record->{'resource.'.$part.'.collaborators'} eq '');
2406: my (@good_collaborators, @bad_collaborators);
2407: foreach my $possible_collaborator
1.630 www 2408: (split(/[,;\s]+/,$record->{'resource.'.$part.'.collaborators'})) {
1.464 albertel 2409: $possible_collaborator =~ s/[\$\^\(\)]//g;
2410: next if ($possible_collaborator eq '');
1.631 www 2411: my ($co_name,$co_dom) = split(/:/,$possible_collaborator);
1.464 albertel 2412: $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
2413: next if ($co_name eq $uname && $co_dom eq $udom);
2414: # Doing this grep allows 'fuzzy' specification
2415: my @matches = grep(/^\Q$co_name\E:\Q$co_dom\E$/i,
2416: keys(%$classlist));
2417: if (! scalar(@matches)) {
2418: push(@bad_collaborators, $possible_collaborator);
2419: } else {
2420: push(@good_collaborators, @matches);
2421: }
2422: }
2423: if (scalar(@good_collaborators) != 0) {
1.630 www 2424: $result.='<br />'.&mt('Collaborators:').'<ol>';
1.464 albertel 2425: foreach my $name (@good_collaborators) {
2426: my ($lastname,$givenn) = split(/,/,$$fullname{$name});
2427: push(@col_fullnames, $givenn.' '.$lastname);
1.630 www 2428: $result.='<li>'.$fullname->{$name}.'</li>';
1.464 albertel 2429: }
1.630 www 2430: $result.='</ol><br />'."\n";
1.466 albertel 2431: my ($part)=split(/\./,$part);
1.464 albertel 2432: $result.='<input type="hidden" name="collaborator'.$counter.
2433: '" value="'.$part.':'.(join ':',@good_collaborators).'" />'.
2434: "\n";
2435: }
2436: if (scalar(@bad_collaborators) > 0) {
1.466 albertel 2437: $result.='<div class="LC_warning">';
1.464 albertel 2438: $result.=&mt('This student has submitted [quant,_1,invalid collaborator]: [_2]',scalar(@bad_collaborators),join(', ',@bad_collaborators));
2439: $result .= '</div>';
2440: }
2441: if (scalar(@bad_collaborators > $ncol)) {
1.466 albertel 2442: $result .= '<div class="LC_warning">';
1.464 albertel 2443: $result .= &mt('This student has submitted too many '.
2444: 'collaborators. Maximum is [_1].',$ncol);
2445: $result .= '</div>';
2446: }
2447: }
2448: return ($result,$fullname,\@col_fullnames);
2449: }
2450:
1.44 ng 2451: #--- Retrieve the last submission for all the parts
1.38 ng 2452: sub get_last_submission {
1.119 ng 2453: my ($returnhash)=@_;
1.596 raeburn 2454: my (@string,$timestamp,%lasthidden);
1.119 ng 2455: if ($$returnhash{'version'}) {
1.46 ng 2456: my %lasthash=();
2457: my ($version);
1.119 ng 2458: for ($version=1;$version<=$$returnhash{'version'};$version++) {
1.397 albertel 2459: foreach my $key (sort(split(/\:/,
2460: $$returnhash{$version.':keys'}))) {
2461: $lasthash{$key}=$$returnhash{$version.':'.$key};
2462: $timestamp =
1.545 raeburn 2463: &Apache::lonlocal::locallocaltime($$returnhash{$version.':timestamp'});
1.46 ng 2464: }
2465: }
1.640 raeburn 2466: my (%typeparts,%randombytry);
1.596 raeburn 2467: my $showsurv =
2468: &Apache::lonnet::allowed('vas',$env{'request.course.id'});
2469: foreach my $key (sort(keys(%lasthash))) {
2470: if ($key =~ /\.type$/) {
2471: if (($lasthash{$key} eq 'anonsurvey') ||
1.640 raeburn 2472: ($lasthash{$key} eq 'anonsurveycred') ||
2473: ($lasthash{$key} eq 'randomizetry')) {
1.596 raeburn 2474: my ($ign,@parts) = split(/\./,$key);
2475: pop(@parts);
1.641 raeburn 2476: my $id = join('.',@parts);
1.640 raeburn 2477: if ($lasthash{$key} eq 'randomizetry') {
2478: $randombytry{$ign.'.'.$id} = $lasthash{$key};
2479: } else {
2480: unless ($showsurv) {
2481: $typeparts{$ign.'.'.$id} = $lasthash{$key};
2482: }
1.596 raeburn 2483: }
2484: delete($lasthash{$key});
2485: }
2486: }
2487: }
2488: my @hidden = keys(%typeparts);
1.640 raeburn 2489: my @randomize = keys(%randombytry);
1.397 albertel 2490: foreach my $key (keys(%lasthash)) {
2491: next if ($key !~ /\.submission$/);
1.596 raeburn 2492: my $hide;
2493: if (@hidden) {
2494: foreach my $id (@hidden) {
2495: if ($key =~ /^\Q$id\E/) {
1.640 raeburn 2496: $hide = 'anon';
1.596 raeburn 2497: last;
2498: }
2499: }
2500: }
1.640 raeburn 2501: unless ($hide) {
2502: if (@randomize) {
2503: foreach my $id (@hidden) {
2504: if ($key =~ /^\Q$id\E/) {
2505: $hide = 'rand';
2506: last;
2507: }
2508: }
2509: }
2510: }
1.397 albertel 2511: my ($partid,$foo) = split(/submission$/,$key);
2512: my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
1.398 albertel 2513: '<span class="LC_warning">Draft Copy</span> ' : '';
1.596 raeburn 2514: push(@string, join(':', $key, $hide, $draft.$lasthash{$key}));
1.41 ng 2515: }
2516: }
1.397 albertel 2517: if (!@string) {
2518: $string[0] =
1.539 riegler 2519: '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span>';
1.397 albertel 2520: }
2521: return (\@string,\$timestamp);
1.38 ng 2522: }
1.35 ng 2523:
1.44 ng 2524: #--- High light keywords, with style choosen by user.
1.38 ng 2525: sub keywords_highlight {
1.44 ng 2526: my $string = shift;
1.257 albertel 2527: my $size = $env{'form.kwsize'} eq '0' ? '' : 'size='.$env{'form.kwsize'};
2528: my $styleon = $env{'form.kwstyle'} eq '' ? '' : $env{'form.kwstyle'};
1.41 ng 2529: (my $styleoff = $styleon) =~ s/\</\<\//;
1.257 albertel 2530: my @keylist = split(/[,\s+]/,$env{'form.keywords'});
1.398 albertel 2531: foreach my $keyword (@keylist) {
2532: $string =~ s/\b\Q$keyword\E(\b|\.)/<font color\=$env{'form.kwclr'} $size\>$styleon$keyword$styleoff<\/font>/gi;
1.41 ng 2533: }
2534: return $string;
1.38 ng 2535: }
1.36 ng 2536:
1.671 raeburn 2537: # For Tasks provide a mechanism to display previous version for one specific student
2538:
2539: sub show_previous_task_version {
2540: my ($request,$symb) = @_;
2541: if ($symb eq '') {
2542: $request->print("Unable to handle ambiguous references.");
2543:
2544: return '';
2545: }
2546: my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
2547: my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
2548: if (!&canview($usec)) {
2549: $request->print('<span class="LC_warning">Unable to view previous version for requested student.('.
2550: $uname.':'.$udom.' in section '.$usec.' in course id '.
2551: $env{'request.course.id'}.')</span>');
2552: return;
2553: }
2554: my $mode = 'both';
2555: my $isTask = ($symb =~/\.task$/);
2556: if ($isTask) {
2557: if ($env{'form.previousversion'} =~ /^\d+$/) {
2558: if ($env{'form.fullname'} eq '') {
2559: $env{'form.fullname'} =
2560: &Apache::loncommon::plainname($uname,$udom,'lastname');
2561: }
2562: my $probtitle=&Apache::lonnet::gettitle($symb);
2563: $request->print("\n\n".
2564: '<div class="LC_grade_show_user">'.
2565: '<h2>'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
2566: '</h2>'."\n");
2567: &Apache::lonxml::clear_problem_counter();
2568: $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode,
2569: {'previousversion' => $env{'form.previousversion'} }));
2570: $request->print("\n</div>");
2571: }
2572: }
2573: return;
2574: }
2575:
2576: sub choose_task_version_form {
2577: my ($symb,$uname,$udom,$nomenu) = @_;
2578: my $isTask = ($symb =~/\.task$/);
2579: my ($current,$version,$result,$js,$displayed,$rowtitle);
2580: if ($isTask) {
2581: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
2582: $udom,$uname);
2583: if (($record{'resource.0.version'} eq '') ||
2584: ($record{'resource.0.version'} < 2)) {
2585: return ($record{'resource.0.version'},
2586: $record{'resource.0.version'},$result,$js);
2587: } else {
2588: $current = $record{'resource.0.version'};
2589: }
2590: if ($env{'form.previousversion'}) {
2591: $displayed = $env{'form.previousversion'};
2592: $rowtitle = &mt('Choose another version:')
2593: } else {
2594: $displayed = $current;
2595: $rowtitle = &mt('Show earlier version:');
2596: }
2597: $result = '<div class="LC_left_float">';
2598: my $list;
2599: my $numversions = 0;
2600: for (my $i=1; $i<=$record{'resource.0.version'}; $i++) {
2601: if ($i == $current) {
2602: if (!$env{'form.previousversion'} || $nomenu) {
2603: next;
2604: } else {
2605: $list .= '<option value="'.$i.'">'.&mt('Current').'</option>'."\n";
2606: $numversions ++;
2607: }
2608: } elsif (defined($record{'resource.'.$i.'.0.status'})) {
2609: unless ($i == $env{'form.previousversion'}) {
2610: $numversions ++;
2611: }
2612: $list .= '<option value="'.$i.'">'.$i.'</option>'."\n";
2613: }
2614: }
2615: if ($numversions) {
2616: $symb = &HTML::Entities::encode($symb,'<>"&');
2617: $result .=
2618: '<form name="getprev" method="post" action=""'.
2619: ' onsubmit="return previousVersion('."'$uname','$udom','$symb','$displayed'".');">'.
2620: &Apache::loncommon::start_data_table().
2621: &Apache::loncommon::start_data_table_row().
2622: '<th align="left">'.$rowtitle.'</th>'.
2623: '<td><select name="version">'.
2624: '<option>'.&mt('Select').'</option>'.
2625: $list.
2626: '</select></td>'.
2627: &Apache::loncommon::end_data_table_row();
2628: unless ($nomenu) {
2629: $result .= &Apache::loncommon::start_data_table_row().
2630: '<th align="left">'.&mt('Open in new window').'</th>'.
2631: '<td><span class="LC_nobreak">'.
2632: '<label><input type="radio" name="prevwin" value="1" />'.
2633: &mt('Yes').'</label>'.
2634: '<label><input type="radio" name="prevwin" value="0" checked="checked" />'.&mt('No').'</label>'.
2635: '</span></td>'.
2636: &Apache::loncommon::end_data_table_row();
2637: }
2638: $result .=
2639: &Apache::loncommon::start_data_table_row().
2640: '<th align="left"> </th>'.
2641: '<td>'.
2642: '<input type="submit" name="prevsub" value="'.&mt('Display').'" />'.
2643: '</td>'.
2644: &Apache::loncommon::end_data_table_row().
2645: &Apache::loncommon::end_data_table().
2646: '</form>';
2647: $js = &previous_display_javascript($nomenu,$current);
2648: } elsif ($displayed && $nomenu) {
2649: $result .= '<a href="javascript:window.close()">'.&mt('Close window').'</a>';
2650: } else {
2651: $result .= &mt('No previous versions to show for this student');
2652: }
2653: $result .= '</div>';
2654: }
2655: return ($current,$displayed,$result,$js);
2656: }
2657:
2658: sub previous_display_javascript {
2659: my ($nomenu,$current) = @_;
2660: my $js = <<"JSONE";
2661: <script type="text/javascript">
2662: // <![CDATA[
2663: function previousVersion(uname,udom,symb) {
2664: var current = '$current';
2665: var version = document.getprev.version.options[document.getprev.version.selectedIndex].value;
2666: var prevstr = new RegExp("^\\\\d+\$");
2667: if (!prevstr.test(version)) {
2668: return false;
2669: }
2670: var url = '';
2671: if (version == current) {
2672: url = '/adm/grades?student='+uname+'&userdom='+udom+'&symb='+symb+'&command=submission';
2673: } else {
2674: url = '/adm/grades?student='+uname+'&userdom='+udom+'&symb='+symb+'&command=versionsub&previousversion='+version;
2675: }
2676: JSONE
2677: if ($nomenu) {
2678: $js .= <<"JSTWO";
2679: document.location.href = url;
2680: JSTWO
2681: } else {
2682: $js .= <<"JSTHREE";
2683: var newwin = 0;
2684: for (var i=0; i<document.getprev.prevwin.length; i++) {
2685: if (document.getprev.prevwin[i].checked == true) {
2686: newwin = document.getprev.prevwin[i].value;
2687: }
2688: }
2689: if (newwin == 1) {
2690: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
2691: url = url+'&inhibitmenu=yes';
2692: if (typeof(previousWin) == 'undefined' || previousWin.closed) {
2693: previousWin = window.open(url,'',options,1);
2694: } else {
2695: previousWin.location.href = url;
2696: }
2697: previousWin.focus();
2698: return false;
2699: } else {
2700: document.location.href = url;
2701: return false;
2702: }
2703: JSTHREE
2704: }
2705: $js .= <<"ENDJS";
2706: return false;
2707: }
2708: // ]]>
2709: </script>
2710: ENDJS
2711:
2712: }
2713:
1.44 ng 2714: #--- Called from submission routine
1.38 ng 2715: sub processHandGrade {
1.608 www 2716: my ($request,$symb) = @_;
1.324 albertel 2717: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.257 albertel 2718: my $button = $env{'form.gradeOpt'};
2719: my $ngrade = $env{'form.NCT'};
2720: my $ntstu = $env{'form.NTSTU'};
1.301 albertel 2721: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2722: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2723:
1.44 ng 2724: if ($button eq 'Save & Next') {
2725: my $ctr = 0;
2726: while ($ctr < $ngrade) {
1.257 albertel 2727: my ($uname,$udom) = split(/:/,$env{'form.unamedom'.$ctr});
1.324 albertel 2728: my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$symb,$uname,$udom,$ctr);
1.71 ng 2729: if ($errorflag eq 'no_score') {
2730: $ctr++;
2731: next;
2732: }
1.104 albertel 2733: if ($errorflag eq 'not_allowed') {
1.398 albertel 2734: $request->print("<span class=\"LC_warning\">Not allowed to modify grades for $uname:$udom</span>");
1.104 albertel 2735: $ctr++;
2736: next;
2737: }
1.257 albertel 2738: my $includemsg = $env{'form.includemsg'.$ctr};
1.44 ng 2739: my ($subject,$message,$msgstatus) = ('','','');
1.418 albertel 2740: my $restitle = &Apache::lonnet::gettitle($symb);
2741: my ($feedurl,$showsymb) =
2742: &get_feedurl_and_symb($symb,$uname,$udom);
2743: my $messagetail;
1.62 albertel 2744: if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.298 www 2745: $subject = $env{'form.msgsub'} if ($includemsg =~ /msgsub/);
1.295 www 2746: unless ($subject=~/\w/) { $subject=&mt('Grading Feedback'); }
1.386 raeburn 2747: $subject.=' ['.$restitle.']';
1.44 ng 2748: my (@msgnum) = split(/,/,$includemsg);
2749: foreach (@msgnum) {
1.257 albertel 2750: $message.=$env{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
1.44 ng 2751: }
1.80 ng 2752: $message =&Apache::lonfeedback::clear_out_html($message);
1.298 www 2753: if ($env{'form.withgrades'.$ctr}) {
2754: $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
1.386 raeburn 2755: $messagetail = " for <a href=\"".
1.605 www 2756: $feedurl."?symb=$showsymb\">$restitle</a>";
1.386 raeburn 2757: }
2758: $msgstatus =
2759: &Apache::lonmsg::user_normal_msg($uname,$udom,$subject,
2760: $message.$messagetail,
1.418 albertel 2761: undef,$feedurl,undef,
1.386 raeburn 2762: undef,undef,$showsymb,
2763: $restitle);
1.574 bisitz 2764: $request->print('<br />'.&mt('Sending message to [_1]',$uname.':'.$udom).': '.
1.652 raeburn 2765: $msgstatus.'<br />');
1.44 ng 2766: }
1.257 albertel 2767: if ($env{'form.collaborator'.$ctr}) {
1.155 albertel 2768: my @collabstrs=&Apache::loncommon::get_env_multiple("form.collaborator$ctr");
1.150 albertel 2769: foreach my $collabstr (@collabstrs) {
2770: my ($part,@collaborators) = split(/:/,$collabstr);
1.310 banghart 2771: foreach my $collaborator (@collaborators) {
1.150 albertel 2772: my ($errorflag,$pts,$wgt) =
1.324 albertel 2773: &saveHandGrade($request,$symb,$collaborator,$udom,$ctr,
1.257 albertel 2774: $env{'form.unamedom'.$ctr},$part);
1.150 albertel 2775: if ($errorflag eq 'not_allowed') {
1.362 albertel 2776: $request->print("<span class=\"LC_error\">".&mt('Not allowed to modify grades for [_1]',"$collaborator:$udom")."</span>");
1.150 albertel 2777: next;
1.418 albertel 2778: } elsif ($message ne '') {
2779: my ($baseurl,$showsymb) =
2780: &get_feedurl_and_symb($symb,$collaborator,
2781: $udom);
2782: if ($env{'form.withgrades'.$ctr}) {
2783: $messagetail = " for <a href=\"".
1.605 www 2784: $baseurl."?symb=$showsymb\">$restitle</a>";
1.150 albertel 2785: }
1.418 albertel 2786: $msgstatus =
2787: &Apache::lonmsg::user_normal_msg($collaborator,$udom,$subject,$message.$messagetail,undef,$baseurl,undef,undef,undef,$showsymb,$restitle);
1.104 albertel 2788: }
1.44 ng 2789: }
2790: }
2791: }
2792: $ctr++;
2793: }
2794: }
2795:
1.624 www 2796: # if ($env{'form.handgrade'} eq 'yes') {
2797: if (1) {
1.119 ng 2798: # Keywords sorted in alphabatical order
1.257 albertel 2799: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1.119 ng 2800: my %keyhash = ();
1.257 albertel 2801: $env{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
2802: $env{'form.keywords'} =~ s/^\s+|\s+$//;
2803: my (@keywords) = sort(split(/\s+/,$env{'form.keywords'}));
2804: $env{'form.keywords'} = join(' ',@keywords);
2805: $keyhash{$symb.'_keywords'} = $env{'form.keywords'};
2806: $keyhash{$symb.'_subject'} = $env{'form.msgsub'};
2807: $keyhash{$loginuser.'_kwclr'} = $env{'form.kwclr'};
2808: $keyhash{$loginuser.'_kwsize'} = $env{'form.kwsize'};
2809: $keyhash{$loginuser.'_kwstyle'} = $env{'form.kwstyle'};
1.119 ng 2810:
2811: # message center - Order of message gets changed. Blank line is eliminated.
1.257 albertel 2812: # New messages are saved in env for the next student.
1.119 ng 2813: # All messages are saved in nohist_handgrade.db
2814: my ($ctr,$idx) = (1,1);
1.257 albertel 2815: while ($ctr <= $env{'form.savemsgN'}) {
2816: if ($env{'form.savemsg'.$ctr} ne '') {
2817: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.savemsg'.$ctr};
1.119 ng 2818: $idx++;
2819: }
2820: $ctr++;
1.41 ng 2821: }
1.119 ng 2822: $ctr = 0;
2823: while ($ctr < $ngrade) {
1.257 albertel 2824: if ($env{'form.newmsg'.$ctr} ne '') {
2825: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.newmsg'.$ctr};
2826: $env{'form.savemsg'.$idx} = $env{'form.newmsg'.$ctr};
1.119 ng 2827: $idx++;
2828: }
2829: $ctr++;
1.41 ng 2830: }
1.257 albertel 2831: $env{'form.savemsgN'} = --$idx;
2832: $keyhash{$symb.'_savemsgN'} = $env{'form.savemsgN'};
1.119 ng 2833: my $putresult = &Apache::lonnet::put
1.301 albertel 2834: ('nohist_handgrade',\%keyhash,$cdom,$cnum);
1.41 ng 2835: }
1.44 ng 2836: # Called by Save & Refresh from Highlight Attribute Window
1.257 albertel 2837: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
2838: if ($env{'form.refresh'} eq 'on') {
1.86 ng 2839: my ($ctr,$total) = (0,0);
2840: while ($ctr < $ngrade) {
1.257 albertel 2841: $total++ if $env{'form.unamedom'.$ctr} ne '';
1.86 ng 2842: $ctr++;
2843: }
1.257 albertel 2844: $env{'form.NTSTU'}=$ngrade;
1.86 ng 2845: $ctr = 0;
2846: while ($ctr < $total) {
1.257 albertel 2847: my $processUser = $env{'form.unamedom'.$ctr};
2848: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2849: $env{'form.fullname'} = $$fullname{$processUser};
1.625 www 2850: &submission($request,$ctr,$total-1,$symb);
1.41 ng 2851: $ctr++;
2852: }
2853: return '';
2854: }
1.36 ng 2855:
1.44 ng 2856: # Get the next/previous one or group of students
1.257 albertel 2857: my $firststu = $env{'form.unamedom0'};
2858: my $laststu = $env{'form.unamedom'.($ngrade-1)};
1.119 ng 2859: my $ctr = 2;
1.41 ng 2860: while ($laststu eq '') {
1.257 albertel 2861: $laststu = $env{'form.unamedom'.($ngrade-$ctr)};
1.41 ng 2862: $ctr++;
2863: $laststu = $firststu if ($ctr > $ngrade);
2864: }
1.44 ng 2865:
1.41 ng 2866: my (@parsedlist,@nextlist);
2867: my ($nextflg) = 0;
1.524 raeburn 2868: foreach my $item (sort
1.294 albertel 2869: {
2870: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
2871: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
2872: }
2873: return $a cmp $b;
2874: } (keys(%$fullname))) {
1.605 www 2875: # FIXME: this is fishy, looks like the button label
1.41 ng 2876: if ($nextflg == 1 && $button =~ /Next$/) {
1.524 raeburn 2877: push(@parsedlist,$item);
1.41 ng 2878: }
1.524 raeburn 2879: $nextflg = 1 if ($item eq $laststu);
1.41 ng 2880: if ($button eq 'Previous') {
1.524 raeburn 2881: last if ($item eq $firststu);
2882: push(@parsedlist,$item);
1.41 ng 2883: }
2884: }
2885: $ctr = 0;
1.605 www 2886: # FIXME: this is fishy, looks like the button label
1.41 ng 2887: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
1.582 raeburn 2888: my $res_error;
2889: my ($partlist) = &response_type($symb,\$res_error);
2890: if ($res_error) {
2891: $request->print(&navmap_errormsg());
2892: return;
2893: }
1.41 ng 2894: foreach my $student (@parsedlist) {
1.257 albertel 2895: my $submitonly=$env{'form.submitonly'};
1.41 ng 2896: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 2897:
2898: if ($submitonly eq 'queued') {
2899: my %queue_status =
2900: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
2901: $udom,$uname);
2902: next if (!defined($queue_status{'gradingqueue'}));
2903: }
2904:
1.156 albertel 2905: if ($submitonly =~ /^(yes|graded|incorrect)$/) {
1.257 albertel 2906: # my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 2907: my %status=&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 2908: my $submitted = 0;
1.248 albertel 2909: my $ungraded = 0;
2910: my $incorrect = 0;
1.524 raeburn 2911: foreach my $item (keys(%status)) {
2912: $submitted = 1 if ($status{$item} ne 'nothing');
2913: $ungraded = 1 if ($status{$item} =~ /^ungraded/);
2914: $incorrect = 1 if ($status{$item} =~ /^incorrect/);
2915: my ($foo,$partid,$foo1) = split(/\./,$item);
1.145 albertel 2916: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
2917: $submitted = 0;
2918: }
1.41 ng 2919: }
1.156 albertel 2920: next if (!$submitted && ($submitonly eq 'yes' ||
2921: $submitonly eq 'incorrect' ||
2922: $submitonly eq 'graded'));
1.248 albertel 2923: next if (!$ungraded && ($submitonly eq 'graded'));
2924: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 2925: }
1.524 raeburn 2926: push(@nextlist,$student) if ($ctr < $ntstu);
1.129 ng 2927: last if ($ctr == $ntstu);
1.41 ng 2928: $ctr++;
2929: }
1.36 ng 2930:
1.41 ng 2931: $ctr = 0;
2932: my $total = scalar(@nextlist)-1;
1.39 ng 2933:
1.524 raeburn 2934: foreach (sort(@nextlist)) {
1.41 ng 2935: my ($uname,$udom,$submitter) = split(/:/);
1.257 albertel 2936: $env{'form.student'} = $uname;
2937: $env{'form.userdom'} = $udom;
2938: $env{'form.fullname'} = $$fullname{$_};
1.625 www 2939: &submission($request,$ctr,$total,$symb);
1.41 ng 2940: $ctr++;
2941: }
2942: if ($total < 0) {
1.653 raeburn 2943: my $the_end.='<p>'.&mt('[_1]Message:[_2] No more students for this section or class.','<b>','</b>').'</p>'."\n";
1.41 ng 2944: $request->print($the_end);
2945: }
2946: return '';
1.38 ng 2947: }
1.36 ng 2948:
1.44 ng 2949: #---- Save the score and award for each student, if changed
1.38 ng 2950: sub saveHandGrade {
1.324 albertel 2951: my ($request,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
1.342 banghart 2952: my @version_parts;
1.104 albertel 2953: my $usec = &Apache::lonnet::getsection($domain,$stuname,
1.257 albertel 2954: $env{'request.course.id'});
1.104 albertel 2955: if (!&canmodify($usec)) { return('not_allowed'); }
1.337 banghart 2956: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
1.251 banghart 2957: my @parts_graded;
1.77 ng 2958: my %newrecord = ();
2959: my ($pts,$wgt) = ('','');
1.269 raeburn 2960: my %aggregate = ();
2961: my $aggregateflag = 0;
1.301 albertel 2962: my @parts = split(/:/,$env{'form.partlist'.$newflg});
2963: foreach my $new_part (@parts) {
1.337 banghart 2964: #collaborator ($submi may vary for different parts
1.259 banghart 2965: if ($submitter && $new_part ne $part) { next; }
2966: my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
1.125 ng 2967: if ($dropMenu eq 'excused') {
1.259 banghart 2968: if ($record{'resource.'.$new_part.'.solved'} ne 'excused') {
2969: $newrecord{'resource.'.$new_part.'.solved'} = 'excused';
2970: if (exists($record{'resource.'.$new_part.'.awarded'})) {
2971: $newrecord{'resource.'.$new_part.'.awarded'} = '';
1.58 albertel 2972: }
1.364 banghart 2973: $newrecord{'resource.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.58 albertel 2974: }
1.125 ng 2975: } elsif ($dropMenu eq 'reset status'
1.259 banghart 2976: && exists($record{'resource.'.$new_part.'.solved'})) { #don't bother if no old records -> no attempts
1.524 raeburn 2977: foreach my $key (keys(%record)) {
1.259 banghart 2978: if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
1.197 albertel 2979: }
1.259 banghart 2980: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2981: "$env{'user.name'}:$env{'user.domain'}";
1.270 albertel 2982: my $totaltries = $record{'resource.'.$part.'.tries'};
2983:
2984: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
2985: [$new_part]);
2986: my $aggtries =$totaltries;
1.269 raeburn 2987: if ($last_resets{$new_part}) {
1.270 albertel 2988: $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
2989: $new_part);
1.269 raeburn 2990: }
1.270 albertel 2991:
2992: my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
1.269 raeburn 2993: if ($aggtries > 0) {
1.327 albertel 2994: &decrement_aggs($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
1.269 raeburn 2995: $aggregateflag = 1;
2996: }
1.125 ng 2997: } elsif ($dropMenu eq '') {
1.259 banghart 2998: $pts = ($env{'form.GD_BOX'.$newflg.'_'.$new_part} ne '' ?
2999: $env{'form.GD_BOX'.$newflg.'_'.$new_part} :
3000: $env{'form.RADVAL'.$newflg.'_'.$new_part});
3001: if ($pts eq '' && $env{'form.GD_SEL'.$newflg.'_'.$new_part} eq '') {
1.153 albertel 3002: next;
3003: }
1.259 banghart 3004: $wgt = $env{'form.WGT'.$newflg.'_'.$new_part} eq '' ? 1 :
3005: $env{'form.WGT'.$newflg.'_'.$new_part};
1.41 ng 3006: my $partial= $pts/$wgt;
1.259 banghart 3007: if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
1.153 albertel 3008: #do not update score for part if not changed.
1.346 banghart 3009: &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
1.153 albertel 3010: next;
1.251 banghart 3011: } else {
1.524 raeburn 3012: push(@parts_graded,$new_part);
1.153 albertel 3013: }
1.259 banghart 3014: if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
3015: $newrecord{'resource.'.$new_part.'.awarded'} = $partial;
1.153 albertel 3016: }
1.259 banghart 3017: my $reckey = 'resource.'.$new_part.'.solved';
1.41 ng 3018: if ($partial == 0) {
1.153 albertel 3019: if ($record{$reckey} ne 'incorrect_by_override') {
3020: $newrecord{$reckey} = 'incorrect_by_override';
3021: }
1.41 ng 3022: } else {
1.153 albertel 3023: if ($record{$reckey} ne 'correct_by_override') {
3024: $newrecord{$reckey} = 'correct_by_override';
3025: }
3026: }
3027: if ($submitter &&
1.259 banghart 3028: ($record{'resource.'.$new_part.'.submitted_by'} ne $submitter)) {
3029: $newrecord{'resource.'.$new_part.'.submitted_by'} = $submitter;
1.41 ng 3030: }
1.259 banghart 3031: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 3032: "$env{'user.name'}:$env{'user.domain'}";
1.41 ng 3033: }
1.259 banghart 3034: # unless problem has been graded, set flag to version the submitted files
1.305 banghart 3035: unless ($record{'resource.'.$new_part.'.solved'} =~ /^correct_/ ||
3036: $record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override' ||
3037: $dropMenu eq 'reset status')
3038: {
1.524 raeburn 3039: push(@version_parts,$new_part);
1.259 banghart 3040: }
1.41 ng 3041: }
1.301 albertel 3042: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3043: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3044:
1.344 albertel 3045: if (%newrecord) {
3046: if (@version_parts) {
1.364 banghart 3047: my @changed_keys = &version_portfiles(\%record, \@parts_graded,
3048: $env{'request.course.id'}, $symb, $domain, $stuname, \@version_parts);
1.344 albertel 3049: @newrecord{@changed_keys} = @record{@changed_keys};
1.367 albertel 3050: foreach my $new_part (@version_parts) {
3051: &handback_files($request,$symb,$stuname,$domain,$newflg,
3052: $new_part,\%newrecord);
3053: }
1.259 banghart 3054: }
1.44 ng 3055: &Apache::lonnet::cstore(\%newrecord,$symb,
1.257 albertel 3056: $env{'request.course.id'},$domain,$stuname);
1.380 albertel 3057: &check_and_remove_from_queue(\@parts,\%record,\%newrecord,$symb,
3058: $cdom,$cnum,$domain,$stuname);
1.41 ng 3059: }
1.269 raeburn 3060: if ($aggregateflag) {
3061: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 3062: $cdom,$cnum);
1.269 raeburn 3063: }
1.301 albertel 3064: return ('',$pts,$wgt);
1.36 ng 3065: }
1.322 albertel 3066:
1.380 albertel 3067: sub check_and_remove_from_queue {
3068: my ($parts,$record,$newrecord,$symb,$cdom,$cnum,$domain,$stuname) = @_;
3069: my @ungraded_parts;
3070: foreach my $part (@{$parts}) {
3071: if ( $record->{ 'resource.'.$part.'.awarded'} eq ''
3072: && $record->{ 'resource.'.$part.'.solved' } ne 'excused'
3073: && $newrecord->{'resource.'.$part.'.awarded'} eq ''
3074: && $newrecord->{'resource.'.$part.'.solved' } ne 'excused'
3075: ) {
3076: push(@ungraded_parts, $part);
3077: }
3078: }
3079: if ( !@ungraded_parts ) {
3080: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,
3081: $cnum,$domain,$stuname);
3082: }
3083: }
3084:
1.337 banghart 3085: sub handback_files {
3086: my ($request,$symb,$stuname,$domain,$newflg,$new_part,$newrecord) = @_;
1.517 raeburn 3087: my $portfolio_root = '/userfiles/portfolio';
1.582 raeburn 3088: my $res_error;
3089: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
3090: if ($res_error) {
3091: $request->print('<br />'.&navmap_errormsg().'<br />');
3092: return;
3093: }
1.654 raeburn 3094: my @handedback;
3095: my $file_msg;
1.375 albertel 3096: my @part_response_id = &flatten_responseType($responseType);
3097: foreach my $part_response_id (@part_response_id) {
3098: my ($part_id,$resp_id) = @{ $part_response_id };
3099: my $part_resp = join('_',@{ $part_response_id });
1.654 raeburn 3100: if (($env{'form.'.$newflg.'_'.$part_resp.'_countreturndoc'} =~ /^\d+$/) & ($new_part eq $part_id)) {
3101: for (my $counter=1; $counter<=$env{'form.'.$newflg.'_'.$part_resp.'_countreturndoc'}; $counter++) {
3102: # if multiple files are uploaded names will be 'returndoc2','returndoc3'
3103: if ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$counter}) {
3104: my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$counter.'.filename'};
1.338 banghart 3105: my ($directory,$answer_file) =
1.654 raeburn 3106: ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$counter} =~ /^(.*?)([^\/]*)$/);
1.338 banghart 3107: my ($answer_name,$answer_ver,$answer_ext) =
3108: &file_name_version_ext($answer_file);
1.355 banghart 3109: my ($portfolio_path) = ($directory =~ /^.+$stuname\/portfolio(.*)/);
1.517 raeburn 3110: my $getpropath = 1;
1.662 raeburn 3111: my ($dir_list,$listerror) =
3112: &Apache::lonnet::dirlist($portfolio_root.$portfolio_path,
3113: $domain,$stuname,$getpropath);
3114: my $version = &get_next_version($answer_name,$answer_ext,$dir_list);
1.686 bisitz 3115: # fix filename
1.355 banghart 3116: my ($save_file_name) = (($directory.$answer_name.".$version.".$answer_ext) =~ /^.+\/${stuname}\/(.*)/);
3117: my $result=&Apache::lonnet::finishuserfileupload($stuname,$domain,
1.654 raeburn 3118: $newflg.'_'.$part_resp.'_returndoc'.$counter,
1.355 banghart 3119: $save_file_name);
1.337 banghart 3120: if ($result !~ m|^/uploaded/|) {
1.536 raeburn 3121: $request->print('<br /><span class="LC_error">'.
3122: &mt('An error occurred ([_1]) while trying to upload [_2].',
1.654 raeburn 3123: $result,$newflg.'_'.$part_resp.'_returndoc'.$counter).
1.536 raeburn 3124: '</span>');
1.356 banghart 3125: } else {
1.360 banghart 3126: # mark the file as read only
1.654 raeburn 3127: push(@handedback,$save_file_name);
1.367 albertel 3128: if (exists($$newrecord{"resource.$new_part.$resp_id.handback"})) {
3129: $$newrecord{"resource.$new_part.$resp_id.handback"}.=',';
3130: }
3131: $$newrecord{"resource.$new_part.$resp_id.handback"} .= $save_file_name;
1.654 raeburn 3132: $file_msg.= '<span class="LC_filename"><a href="/uploaded/'."$domain/$stuname/".$save_file_name.'">'.$save_file_name."</a></span> <br />";
1.337 banghart 3133: }
1.686 bisitz 3134: $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 3135: }
3136: }
3137: }
1.654 raeburn 3138: }
3139: if (@handedback > 0) {
3140: $request->print('<br />');
3141: my @what = ($symb,$env{'request.course.id'},'handback');
3142: &Apache::lonnet::mark_as_readonly($domain,$stuname,\@handedback,\@what);
3143: my $user_lh = &Apache::loncommon::user_lang($stuname,$domain,$env{'request.course.id'});
3144: my ($subject,$message);
3145: if (scalar(@handedback) == 1) {
3146: $subject = &mt_user($user_lh,'File Handed Back by Instructor');
3147: $message = &mt_user($user_lh,'A file has been returned that was originally submitted in response to: ');
3148: } else {
3149: $subject = &mt_user($user_lh,'Files Handed Back by Instructor');
3150: $message = &mt_user($user_lh,'Files have been returned that were originally submitted in response to: ');
3151: }
3152: $message .= "<p><strong>".&Apache::lonnet::gettitle($symb)." </strong></p>";
3153: $message .= &mt_user($user_lh,'The returned file(s) are named: [_1]',"<br />$file_msg <br />").
3154: &mt_user($user_lh,'The file(s) can be found in your [_1]portfolio[_2].','<a href="/adm/portfolio">','</a>');
3155: my ($feedurl,$showsymb) =
3156: &get_feedurl_and_symb($symb,$domain,$stuname);
3157: my $restitle = &Apache::lonnet::gettitle($symb);
3158: $subject .= ' '.&mt_user($user_lh,'(File Returned)').' ['.$restitle.']';
3159: my $msgstatus =
3160: &Apache::lonmsg::user_normal_msg($stuname,$domain,$subject,
3161: $message,undef,$feedurl,undef,undef,undef,$showsymb,
3162: $restitle);
3163: if ($msgstatus) {
3164: $request->print(&mt('Notification message status: [_1]','<span class="LC_info">'.$msgstatus.'</span>').'<br />');
3165: }
3166: }
1.338 banghart 3167: return;
1.337 banghart 3168: }
3169:
1.418 albertel 3170: sub get_feedurl_and_symb {
3171: my ($symb,$uname,$udom) = @_;
3172: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
3173: $url = &Apache::lonnet::clutter($url);
3174: my $encrypturl=&Apache::lonnet::EXT('resource.0.encrypturl',
3175: $symb,$udom,$uname);
3176: if ($encrypturl =~ /^yes$/i) {
3177: &Apache::lonenc::encrypted(\$url,1);
3178: &Apache::lonenc::encrypted(\$symb,1);
3179: }
3180: return ($url,$symb);
3181: }
3182:
1.313 banghart 3183: sub get_submitted_files {
3184: my ($udom,$uname,$partid,$respid,$record) = @_;
3185: my @files;
3186: if ($$record{"resource.$partid.$respid.portfiles"}) {
3187: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
3188: foreach my $file (split(',',$$record{"resource.$partid.$respid.portfiles"})) {
3189: push(@files,$file_url.$file);
3190: }
3191: }
3192: if ($$record{"resource.$partid.$respid.uploadedurl"}) {
3193: push(@files,$$record{"resource.$partid.$respid.uploadedurl"});
3194: }
3195: return (\@files);
3196: }
1.322 albertel 3197:
1.269 raeburn 3198: # ----------- Provides number of tries since last reset.
3199: sub get_num_tries {
3200: my ($record,$last_reset,$part) = @_;
3201: my $timestamp = '';
3202: my $num_tries = 0;
3203: if ($$record{'version'}) {
3204: for (my $version=$$record{'version'};$version>=1;$version--) {
3205: if (exists($$record{$version.':resource.'.$part.'.solved'})) {
3206: $timestamp = $$record{$version.':timestamp'};
3207: if ($timestamp > $last_reset) {
3208: $num_tries ++;
3209: } else {
3210: last;
3211: }
3212: }
3213: }
3214: }
3215: return $num_tries;
3216: }
3217:
3218: # ----------- Determine decrements required in aggregate totals
3219: sub decrement_aggs {
3220: my ($symb,$part,$aggregate,$aggtries,$totaltries,$solvedstatus) = @_;
3221: my %decrement = (
3222: attempts => 0,
3223: users => 0,
3224: correct => 0
3225: );
3226: $decrement{'attempts'} = $aggtries;
3227: if ($solvedstatus =~ /^correct/) {
3228: $decrement{'correct'} = 1;
3229: }
3230: if ($aggtries == $totaltries) {
3231: $decrement{'users'} = 1;
3232: }
1.524 raeburn 3233: foreach my $type (keys(%decrement)) {
1.269 raeburn 3234: $$aggregate{$symb."\0".$part."\0".$type} = -$decrement{$type};
3235: }
3236: return;
3237: }
3238:
3239: # ----------- Determine timestamps for last reset of aggregate totals for parts
3240: sub get_last_resets {
1.270 albertel 3241: my ($symb,$courseid,$partids) =@_;
3242: my %last_resets;
1.269 raeburn 3243: my $cdom = $env{'course.'.$courseid.'.domain'};
3244: my $cname = $env{'course.'.$courseid.'.num'};
1.271 albertel 3245: my @keys;
3246: foreach my $part (@{$partids}) {
3247: push(@keys,"$symb\0$part\0resettime");
3248: }
3249: my %results=&Apache::lonnet::get('nohist_resourcetracker',\@keys,
3250: $cdom,$cname);
3251: foreach my $part (@{$partids}) {
3252: $last_resets{$part}=$results{"$symb\0$part\0resettime"};
1.269 raeburn 3253: }
1.270 albertel 3254: return %last_resets;
1.269 raeburn 3255: }
3256:
1.251 banghart 3257: # ----------- Handles creating versions for portfolio files as answers
3258: sub version_portfiles {
1.343 banghart 3259: my ($record, $parts_graded, $courseid, $symb, $domain, $stu_name, $v_flag) = @_;
1.263 banghart 3260: my $version_parts = join('|',@$v_flag);
1.343 banghart 3261: my @returned_keys;
1.255 banghart 3262: my $parts = join('|', @$parts_graded);
1.517 raeburn 3263: my $portfolio_root = '/userfiles/portfolio';
1.277 albertel 3264: foreach my $key (keys(%$record)) {
1.259 banghart 3265: my $new_portfiles;
1.263 banghart 3266: if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
1.342 banghart 3267: my @versioned_portfiles;
1.367 albertel 3268: my @portfiles = split(/\s*,\s*/,$$record{$key});
1.252 banghart 3269: foreach my $file (@portfiles) {
1.306 banghart 3270: &Apache::lonnet::unmark_as_readonly($domain,$stu_name,[$symb,$env{'request.course.id'}],$file);
1.304 albertel 3271: my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*)$/);
3272: my ($answer_name,$answer_ver,$answer_ext) =
3273: &file_name_version_ext($answer_file);
1.517 raeburn 3274: my $getpropath = 1;
1.662 raeburn 3275: my ($dir_list,$listerror) =
3276: &Apache::lonnet::dirlist($portfolio_root.$directory,$domain,
3277: $stu_name,$getpropath);
3278: my $version = &get_next_version($answer_name,$answer_ext,$dir_list);
1.306 banghart 3279: my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version);
3280: if ($new_answer ne 'problem getting file') {
1.342 banghart 3281: push(@versioned_portfiles, $directory.$new_answer);
1.306 banghart 3282: &Apache::lonnet::mark_as_readonly($domain,$stu_name,
1.367 albertel 3283: [$directory.$new_answer],
1.306 banghart 3284: [$symb,$env{'request.course.id'},'graded']);
1.259 banghart 3285: }
1.252 banghart 3286: }
1.343 banghart 3287: $$record{$key} = join(',',@versioned_portfiles);
3288: push(@returned_keys,$key);
1.251 banghart 3289: }
3290: }
1.343 banghart 3291: return (@returned_keys);
1.305 banghart 3292: }
3293:
1.307 banghart 3294: sub get_next_version {
1.341 banghart 3295: my ($answer_name, $answer_ext, $dir_list) = @_;
1.307 banghart 3296: my $version;
1.662 raeburn 3297: if (ref($dir_list) eq 'ARRAY') {
3298: foreach my $row (@{$dir_list}) {
3299: my ($file) = split(/\&/,$row,2);
3300: my ($file_name,$file_version,$file_ext) =
3301: &file_name_version_ext($file);
3302: if (($file_name eq $answer_name) &&
3303: ($file_ext eq $answer_ext)) {
3304: # gets here if filename and extension match,
3305: # regardless of version
1.307 banghart 3306: if ($file_version ne '') {
1.662 raeburn 3307: # a versioned file is found so save it for later
3308: if ($file_version > $version) {
3309: $version = $file_version;
3310: }
3311: }
1.307 banghart 3312: }
3313: }
1.662 raeburn 3314: }
1.307 banghart 3315: $version ++;
3316: return($version);
3317: }
3318:
1.305 banghart 3319: sub version_selected_portfile {
1.306 banghart 3320: my ($domain,$stu_name,$directory,$file_name,$version) = @_;
3321: my ($answer_name,$answer_ver,$answer_ext) =
3322: &file_name_version_ext($file_name);
3323: my $new_answer;
3324: $env{'form.copy'} = &Apache::lonnet::getfile("/uploaded/$domain/$stu_name/portfolio$directory$file_name");
3325: if($env{'form.copy'} eq '-1') {
3326: $new_answer = 'problem getting file';
3327: } else {
3328: $new_answer = $answer_name.'.'.$version.'.'.$answer_ext;
3329: my $copy_result = &Apache::lonnet::finishuserfileupload(
3330: $stu_name,$domain,'copy',
3331: '/portfolio'.$directory.$new_answer);
3332: }
3333: return ($new_answer);
1.251 banghart 3334: }
3335:
1.304 albertel 3336: sub file_name_version_ext {
3337: my ($file)=@_;
3338: my @file_parts = split(/\./, $file);
3339: my ($name,$version,$ext);
3340: if (@file_parts > 1) {
3341: $ext=pop(@file_parts);
3342: if (@file_parts > 1 && $file_parts[-1] =~ /^\d+$/) {
3343: $version=pop(@file_parts);
3344: }
3345: $name=join('.',@file_parts);
3346: } else {
3347: $name=join('.',@file_parts);
3348: }
3349: return($name,$version,$ext);
3350: }
3351:
1.44 ng 3352: #--------------------------------------------------------------------------------------
3353: #
3354: #-------------------------- Next few routines handles grading by section or whole class
3355: #
3356: #--- Javascript to handle grading by section or whole class
1.42 ng 3357: sub viewgrades_js {
3358: my ($request) = shift;
3359:
1.539 riegler 3360: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
1.597 wenzelju 3361: $request->print(&Apache::lonhtmlcommon::scripttag(<<VIEWJAVASCRIPT));
1.45 ng 3362: function writePoint(partid,weight,point) {
1.125 ng 3363: var radioButton = document.classgrade["RADVAL_"+partid];
3364: var textbox = document.classgrade["TEXTVAL_"+partid];
1.42 ng 3365: if (point == "textval") {
1.125 ng 3366: point = document.classgrade["TEXTVAL_"+partid].value;
1.109 matthew 3367: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 3368: alert("$alertmsg"+parseFloat(point));
1.42 ng 3369: var resetbox = false;
3370: for (var i=0; i<radioButton.length; i++) {
3371: if (radioButton[i].checked) {
3372: textbox.value = i;
3373: resetbox = true;
3374: }
3375: }
3376: if (!resetbox) {
3377: textbox.value = "";
3378: }
3379: return;
3380: }
1.109 matthew 3381: if (parseFloat(point) > parseFloat(weight)) {
3382: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 3383: ") greater than the weight for the part. Accept?");
3384: if (resp == false) {
3385: textbox.value = "";
3386: return;
3387: }
3388: }
1.42 ng 3389: for (var i=0; i<radioButton.length; i++) {
3390: radioButton[i].checked=false;
1.109 matthew 3391: if (parseFloat(point) == i) {
1.42 ng 3392: radioButton[i].checked=true;
3393: }
3394: }
1.41 ng 3395:
1.42 ng 3396: } else {
1.125 ng 3397: textbox.value = parseFloat(point);
1.42 ng 3398: }
1.41 ng 3399: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3400: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3401: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3402: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3403: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3404: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 3405: if (saveval != "correct") {
3406: scorename.value = point;
1.43 ng 3407: if (selname[0].selected != true) {
3408: selname[0].selected = true;
3409: }
1.42 ng 3410: }
3411: }
1.125 ng 3412: document.classgrade["SELVAL_"+partid][0].selected = true;
1.42 ng 3413: }
3414:
3415: function writeRadText(partid,weight) {
1.125 ng 3416: var selval = document.classgrade["SELVAL_"+partid];
3417: var radioButton = document.classgrade["RADVAL_"+partid];
1.265 www 3418: var override = document.classgrade["FORCE_"+partid].checked;
1.125 ng 3419: var textbox = document.classgrade["TEXTVAL_"+partid];
3420: if (selval[1].selected || selval[2].selected) {
1.42 ng 3421: for (var i=0; i<radioButton.length; i++) {
3422: radioButton[i].checked=false;
3423:
3424: }
3425: textbox.value = "";
3426:
3427: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3428: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3429: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3430: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3431: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3432: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 3433: if ((saveval != "correct") || override) {
1.42 ng 3434: scorename.value = "";
1.125 ng 3435: if (selval[1].selected) {
3436: selname[1].selected = true;
3437: } else {
3438: selname[2].selected = true;
3439: if (Number(document.classgrade["GD_"+user+"_"+partid+"_tries"].value))
3440: {document.classgrade["GD_"+user+"_"+partid+"_tries"].value = '0';}
3441: }
1.42 ng 3442: }
3443: }
1.43 ng 3444: } else {
3445: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3446: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3447: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3448: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3449: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3450: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 3451: if ((saveval != "correct") || override) {
1.125 ng 3452: scorename.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
1.43 ng 3453: selname[0].selected = true;
3454: }
3455: }
3456: }
1.42 ng 3457: }
3458:
3459: function changeSelect(partid,user) {
1.125 ng 3460: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
3461: var textbox = document.classgrade["GD_"+user+'_'+partid+"_awarded"];
1.44 ng 3462: var point = textbox.value;
1.125 ng 3463: var weight = document.classgrade["weight_"+partid].value;
1.44 ng 3464:
1.109 matthew 3465: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 3466: alert("$alertmsg"+parseFloat(point));
1.44 ng 3467: textbox.value = "";
3468: return;
3469: }
1.109 matthew 3470: if (parseFloat(point) > parseFloat(weight)) {
3471: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 3472: ") greater than the weight of the part. Accept?");
3473: if (resp == false) {
3474: textbox.value = "";
3475: return;
3476: }
3477: }
1.42 ng 3478: selval[0].selected = true;
3479: }
3480:
3481: function changeOneScore(partid,user) {
1.125 ng 3482: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
3483: if (selval[1].selected || selval[2].selected) {
3484: document.classgrade["GD_"+user+'_'+partid+"_awarded"].value = "";
3485: if (selval[2].selected) {
3486: document.classgrade["GD_"+user+'_'+partid+"_tries"].value = "0";
3487: }
1.269 raeburn 3488: }
1.42 ng 3489: }
3490:
3491: function resetEntry(numpart) {
3492: for (ctpart=0;ctpart<numpart;ctpart++) {
1.125 ng 3493: var partid = document.classgrade["partid_"+ctpart].value;
3494: var radioButton = document.classgrade["RADVAL_"+partid];
3495: var textbox = document.classgrade["TEXTVAL_"+partid];
3496: var selval = document.classgrade["SELVAL_"+partid];
1.42 ng 3497: for (var i=0; i<radioButton.length; i++) {
3498: radioButton[i].checked=false;
3499:
3500: }
3501: textbox.value = "";
3502: selval[0].selected = true;
3503:
3504: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3505: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3506: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3507: var resetscore = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3508: resetscore.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
3509: var resettries = document.classgrade["GD_"+user+"_"+partid+"_tries"];
3510: resettries.value = document.classgrade["GD_"+user+"_"+partid+"_tries_s"].value;
3511: var saveselval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3512: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 3513: if (saveselval == "excused") {
1.43 ng 3514: if (selname[1].selected == false) { selname[1].selected = true;}
1.42 ng 3515: } else {
1.43 ng 3516: if (selname[0].selected == false) {selname[0].selected = true};
1.42 ng 3517: }
3518: }
1.41 ng 3519: }
1.42 ng 3520: }
3521:
1.41 ng 3522: VIEWJAVASCRIPT
1.42 ng 3523: }
3524:
1.44 ng 3525: #--- show scores for a section or whole class w/ option to change/update a score
1.42 ng 3526: sub viewgrades {
1.608 www 3527: my ($request,$symb) = @_;
1.42 ng 3528: &viewgrades_js($request);
1.41 ng 3529:
1.168 albertel 3530: #need to make sure we have the correct data for later EXT calls,
3531: #thus invalidate the cache
3532: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 3533: $env{'course.'.$env{'request.course.id'}.'.num'},
3534: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 3535: &Apache::lonnet::clear_EXT_cache_status();
3536:
1.398 albertel 3537: my $result='<h3><span class="LC_info">'.&mt('Manual Grading').'</span></h3>';
1.41 ng 3538:
3539: #view individual student submission form - called using Javascript viewOneStudent
1.324 albertel 3540: $result.=&jscriptNform($symb);
1.41 ng 3541:
1.44 ng 3542: #beginning of class grading form
1.442 banghart 3543: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.41 ng 3544: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1.418 albertel 3545: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.38 ng 3546: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.432 banghart 3547: &build_section_inputs().
1.442 banghart 3548: '<input type="hidden" name="Status" value="'.$env{'stu_status'}.'" />'."\n".
1.72 ng 3549:
1.560 raeburn 3550: my ($common_header,$specific_header);
1.257 albertel 3551: if ($env{'form.section'} eq 'all') {
1.560 raeburn 3552: $common_header = &mt('Assign Common Grade to Class');
3553: $specific_header = &mt('Assign Grade to Specific Students in Class');
1.257 albertel 3554: } elsif ($env{'form.section'} eq 'none') {
1.560 raeburn 3555: $common_header = &mt('Assign Common Grade to Students in no Section');
3556: $specific_header = &mt('Assign Grade to Specific Students in no Section');
1.52 albertel 3557: } else {
1.560 raeburn 3558: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
3559: $common_header = &mt('Assign Common Grade to Students in Section(s) [_1]',$section_display);
3560: $specific_header = &mt('Assign Grade to Specific Students in Section(s) [_1]',$section_display);
1.52 albertel 3561: }
1.560 raeburn 3562: $result.= '<h3>'.$common_header.'</h3>'.&Apache::loncommon::start_data_table();
1.44 ng 3563: #radio buttons/text box for assigning points for a section or class.
3564: #handles different parts of a problem
1.582 raeburn 3565: my $res_error;
3566: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
3567: if ($res_error) {
3568: return &navmap_errormsg();
3569: }
1.42 ng 3570: my %weight = ();
3571: my $ctsparts = 0;
1.45 ng 3572: my %seen = ();
1.375 albertel 3573: my @part_response_id = &flatten_responseType($responseType);
3574: foreach my $part_response_id (@part_response_id) {
3575: my ($partid,$respid) = @{ $part_response_id };
3576: my $part_resp = join('_',@{ $part_response_id });
1.45 ng 3577: next if $seen{$partid};
3578: $seen{$partid}++;
1.375 albertel 3579: my $handgrade=$$handgrade{$part_resp};
1.42 ng 3580: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
3581: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
3582:
1.324 albertel 3583: my $display_part=&get_display_part($partid,$symb);
1.485 albertel 3584: my $radio.='<table border="0"><tr>';
1.41 ng 3585: my $ctr = 0;
1.42 ng 3586: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
1.485 albertel 3587: $radio.= '<td><label><input type="radio" name="RADVAL_'.$partid.'" '.
1.54 albertel 3588: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.288 albertel 3589: ','.$ctr.')" />'.$ctr."</label></td>\n";
1.41 ng 3590: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
3591: $ctr++;
3592: }
1.485 albertel 3593: $radio.='</tr></table>';
3594: my $line = '<input type="text" name="TEXTVAL_'.
1.589 bisitz 3595: $partid.'" size="4" '.'onchange="javascript:writePoint(\''.
1.54 albertel 3596: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.539 riegler 3597: $weight{$partid}.' '.&mt('(problem weight)').'</td>'."\n";
3598: $line.= '<td><b>'.&mt('Grade Status').':</b><select name="SELVAL_'.$partid.'"'.
1.589 bisitz 3599: 'onchange="javascript:writeRadText(\''.$partid.'\','.
1.59 albertel 3600: $weight{$partid}.')"> '.
1.401 albertel 3601: '<option selected="selected"> </option>'.
1.485 albertel 3602: '<option value="excused">'.&mt('excused').'</option>'.
3603: '<option value="reset status">'.&mt('reset status').'</option>'.
3604: '</select></td>'.
3605: '<td><label><input type="checkbox" name="FORCE_'.$partid.'" />'.&mt('Override "Correct"').'</label>';
3606: $line.='<input type="hidden" name="partid_'.
3607: $ctsparts.'" value="'.$partid.'" />'."\n";
3608: $line.='<input type="hidden" name="weight_'.
3609: $partid.'" value="'.$weight{$partid}.'" />'."\n";
3610:
3611: $result.=
3612: &Apache::loncommon::start_data_table_row()."\n".
1.577 bisitz 3613: '<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 3614: &Apache::loncommon::end_data_table_row()."\n";
1.42 ng 3615: $ctsparts++;
1.41 ng 3616: }
1.474 albertel 3617: $result.=&Apache::loncommon::end_data_table()."\n".
1.52 albertel 3618: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.485 albertel 3619: $result.='<input type="button" value="'.&mt('Revert to Default').'" '.
1.589 bisitz 3620: 'onclick="javascript:resetEntry('.$ctsparts.');" />';
1.41 ng 3621:
1.44 ng 3622: #table listing all the students in a section/class
3623: #header of table
1.560 raeburn 3624: $result.= '<h3>'.$specific_header.'</h3>'.
3625: &Apache::loncommon::start_data_table().
3626: &Apache::loncommon::start_data_table_header_row().
3627: '<th>'.&mt('No.').'</th>'.
3628: '<th>'.&nameUserString('header')."</th>\n";
1.582 raeburn 3629: my $partserror;
3630: my (@parts) = sort(&getpartlist($symb,\$partserror));
3631: if ($partserror) {
3632: return &navmap_errormsg();
3633: }
1.324 albertel 3634: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.269 raeburn 3635: my @partids = ();
1.41 ng 3636: foreach my $part (@parts) {
3637: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1.539 riegler 3638: my $narrowtext = &mt('Tries');
3639: $display =~ s|^Number of Attempts|$narrowtext <br />|; # makes the column narrower
1.41 ng 3640: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
1.207 albertel 3641: my ($partid) = &split_part_type($part);
1.524 raeburn 3642: push(@partids,$partid);
1.628 www 3643: #
3644: # FIXME: Looks like $display looks at English text
3645: #
1.324 albertel 3646: my $display_part=&get_display_part($partid,$symb);
1.41 ng 3647: if ($display =~ /^Partial Credit Factor/) {
1.485 albertel 3648: $result.='<th>'.
1.697 bisitz 3649: &mt('Score Part: [_1][_2](weight = [_3])',
3650: $display_part,'<br />',$weight{$partid}).'</th>'."\n";
1.41 ng 3651: next;
1.485 albertel 3652:
1.207 albertel 3653: } else {
1.485 albertel 3654: if ($display =~ /Problem Status/) {
3655: my $grade_status_mt = &mt('Grade Status');
3656: $display =~ s{Problem Status}{$grade_status_mt<br />};
3657: }
3658: my $part_mt = &mt('Part:');
3659: $display =~s{\[Part: \Q$partid\E\]}{$part_mt $display_part};
1.41 ng 3660: }
1.485 albertel 3661:
1.474 albertel 3662: $result.='<th>'.$display.'</th>'."\n";
1.41 ng 3663: }
1.474 albertel 3664: $result.=&Apache::loncommon::end_data_table_header_row();
1.44 ng 3665:
1.270 albertel 3666: my %last_resets =
3667: &get_last_resets($symb,$env{'request.course.id'},\@partids);
1.269 raeburn 3668:
1.41 ng 3669: #get info for each student
1.44 ng 3670: #list all the students - with points and grade status
1.257 albertel 3671: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
1.41 ng 3672: my $ctr = 0;
1.294 albertel 3673: foreach (sort
3674: {
3675: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
3676: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
3677: }
3678: return $a cmp $b;
3679: } (keys(%$fullname))) {
1.126 ng 3680: $ctr++;
1.324 albertel 3681: $result.=&viewstudentgrade($symb,$env{'request.course.id'},
1.269 raeburn 3682: $_,$$fullname{$_},\@parts,\%weight,$ctr,\%last_resets);
1.41 ng 3683: }
1.474 albertel 3684: $result.=&Apache::loncommon::end_data_table();
1.41 ng 3685: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.485 albertel 3686: $result.='<input type="button" value="'.&mt('Save').'" '.
1.589 bisitz 3687: 'onclick="javascript:submit();" target="_self" /></form>'."\n";
1.96 albertel 3688: if (scalar(%$fullname) eq 0) {
3689: my $colspan=3+scalar(@parts);
1.433 banghart 3690: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.442 banghart 3691: my $stu_status = join(' or ',&Apache::loncommon::get_env_multiple('form.Status'));
1.433 banghart 3692: $result='<span class="LC_warning">'.
1.485 albertel 3693: &mt('There are no students in section(s) [_1] with enrollment status [_2] to modify or grade.',
1.442 banghart 3694: $section_display, $stu_status).
1.433 banghart 3695: '</span>';
1.96 albertel 3696: }
1.41 ng 3697: return $result;
3698: }
3699:
1.44 ng 3700: #--- call by previous routine to display each student
1.41 ng 3701: sub viewstudentgrade {
1.324 albertel 3702: my ($symb,$courseid,$student,$fullname,$parts,$weight,$ctr,$last_resets) = @_;
1.44 ng 3703: my ($uname,$udom) = split(/:/,$student);
3704: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.269 raeburn 3705: my %aggregates = ();
1.474 albertel 3706: my $result=&Apache::loncommon::start_data_table_row().'<td align="right">'.
1.233 albertel 3707: '<input type="hidden" name="ctr'.($ctr-1).'" value="'.$student.'" />'.
3708: "\n".$ctr.' </td><td> '.
1.44 ng 3709: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 3710: '\');" target="_self">'.$fullname.'</a> '.
1.398 albertel 3711: '<span class="LC_internal_info">('.$uname.($env{'user.domain'} eq $udom ? '' : ':'.$udom).')</span></td>'."\n";
1.281 albertel 3712: $student=~s/:/_/; # colon doen't work in javascript for names
1.63 albertel 3713: foreach my $apart (@$parts) {
3714: my ($part,$type) = &split_part_type($apart);
1.41 ng 3715: my $score=$record{"resource.$part.$type"};
1.276 albertel 3716: $result.='<td align="center">';
1.269 raeburn 3717: my ($aggtries,$totaltries);
3718: unless (exists($aggregates{$part})) {
1.270 albertel 3719: $totaltries = $record{'resource.'.$part.'.tries'};
3720:
3721: $aggtries = $totaltries;
1.269 raeburn 3722: if ($$last_resets{$part}) {
1.270 albertel 3723: $aggtries = &get_num_tries(\%record,$$last_resets{$part},
3724: $part);
3725: }
1.269 raeburn 3726: $result.='<input type="hidden" name="'.
3727: 'GD_'.$student.'_'.$part.'_aggtries" value="'.$aggtries.'" />'."\n";
3728: $result.='<input type="hidden" name="'.
3729: 'GD_'.$student.'_'.$part.'_totaltries" value="'.$totaltries.'" />'."\n";
3730: $aggregates{$part} = 1;
3731: }
1.41 ng 3732: if ($type eq 'awarded') {
1.320 albertel 3733: my $pts = $score eq '' ? '' : &compute_points($score,$$weight{$part});
1.42 ng 3734: $result.='<input type="hidden" name="'.
1.89 albertel 3735: 'GD_'.$student.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.233 albertel 3736: $result.='<input type="text" name="'.
1.89 albertel 3737: 'GD_'.$student.'_'.$part.'_awarded" '.
1.589 bisitz 3738: 'onchange="javascript:changeSelect(\''.$part.'\',\''.$student.
1.44 ng 3739: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41 ng 3740: } elsif ($type eq 'solved') {
3741: my ($status,$foo)=split(/_/,$score,2);
3742: $status = 'nothing' if ($status eq '');
1.89 albertel 3743: $result.='<input type="hidden" name="'.'GD_'.$student.'_'.
1.54 albertel 3744: $part.'_solved_s" value="'.$status.'" />'."\n";
1.233 albertel 3745: $result.=' <select name="'.
1.89 albertel 3746: 'GD_'.$student.'_'.$part.'_solved" '.
1.589 bisitz 3747: 'onchange="javascript:changeOneScore(\''.$part.'\',\''.$student.'\')" >'."\n";
1.485 albertel 3748: $result.= (($status eq 'excused') ? '<option> </option><option selected="selected" value="excused">'.&mt('excused').'</option>'
3749: : '<option selected="selected"> </option><option value="excused">'.&mt('excused').'</option>')."\n";
3750: $result.='<option value="reset status">'.&mt('reset status').'</option>';
1.126 ng 3751: $result.="</select> </td>\n";
1.122 ng 3752: } else {
3753: $result.='<input type="hidden" name="'.
3754: 'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
3755: "\n";
1.233 albertel 3756: $result.='<input type="text" name="'.
1.122 ng 3757: 'GD_'.$student.'_'.$part.'_'.$type.'" '.
3758: 'value="'.$score.'" size="4" /></td>'."\n";
1.41 ng 3759: }
3760: }
1.474 albertel 3761: $result.=&Apache::loncommon::end_data_table_row();
1.41 ng 3762: return $result;
1.38 ng 3763: }
3764:
1.44 ng 3765: #--- change scores for all the students in a section/class
3766: # record does not get update if unchanged
1.38 ng 3767: sub editgrades {
1.608 www 3768: my ($request,$symb) = @_;
1.41 ng 3769:
1.433 banghart 3770: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.477 albertel 3771: my $title='<h2>'.&mt('Current Grade Status').'</h2>';
1.433 banghart 3772: $title.='<h4>'.&mt('<b>Section: </b>[_1]',$section_display).'</h4>'."\n";
1.126 ng 3773:
1.477 albertel 3774: my $result= &Apache::loncommon::start_data_table().
3775: &Apache::loncommon::start_data_table_header_row().
3776: '<th rowspan="2" valign="middle">'.&mt('No.').'</th>'.
3777: '<th rowspan="2" valign="middle">'.&nameUserString('header')."</th>\n";
1.43 ng 3778: my %scoreptr = (
3779: 'correct' =>'correct_by_override',
3780: 'incorrect'=>'incorrect_by_override',
3781: 'excused' =>'excused',
3782: 'ungraded' =>'ungraded_attempted',
1.596 raeburn 3783: 'credited' =>'credit_attempted',
1.43 ng 3784: 'nothing' => '',
3785: );
1.257 albertel 3786: my ($classlist,undef,$fullname) = &getclasslist($env{'form.section'},'0');
1.34 ng 3787:
1.44 ng 3788: my (@partid);
3789: my %weight = ();
1.54 albertel 3790: my %columns = ();
1.44 ng 3791: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54 albertel 3792:
1.582 raeburn 3793: my $partserror;
3794: my (@parts) = sort(&getpartlist($symb,\$partserror));
3795: if ($partserror) {
3796: return &navmap_errormsg();
3797: }
1.54 albertel 3798: my $header;
1.257 albertel 3799: while ($ctr < $env{'form.totalparts'}) {
3800: my $partid = $env{'form.partid_'.$ctr};
1.524 raeburn 3801: push(@partid,$partid);
1.257 albertel 3802: $weight{$partid} = $env{'form.weight_'.$partid};
1.44 ng 3803: $ctr++;
1.54 albertel 3804: }
1.324 albertel 3805: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.54 albertel 3806: foreach my $partid (@partid) {
1.478 albertel 3807: $header .= '<th align="center">'.&mt('Old Score').'</th>'.
3808: '<th align="center">'.&mt('New Score').'</th>';
1.54 albertel 3809: $columns{$partid}=2;
3810: foreach my $stores (@parts) {
3811: my ($part,$type) = &split_part_type($stores);
3812: if ($part !~ m/^\Q$partid\E/) { next;}
3813: if ($type eq 'awarded' || $type eq 'solved') { next; }
3814: my $display=&Apache::lonnet::metadata($url,$stores.'.display');
1.551 raeburn 3815: $display =~ s/\[Part: \Q$part\E\]//;
1.539 riegler 3816: my $narrowtext = &mt('Tries');
3817: $display =~ s/Number of Attempts/$narrowtext/;
3818: $header .= '<th align="center">'.&mt('Old').' '.$display.'</th>'.
3819: '<th align="center">'.&mt('New').' '.$display.'</th>';
1.54 albertel 3820: $columns{$partid}+=2;
3821: }
3822: }
3823: foreach my $partid (@partid) {
1.324 albertel 3824: my $display_part=&get_display_part($partid,$symb);
1.478 albertel 3825: $result .= '<th colspan="'.$columns{$partid}.'" align="center">'.
3826: &mt('Part: [_1] (Weight = [_2])',$display_part,$weight{$partid}).
3827: '</th>';
1.54 albertel 3828:
1.44 ng 3829: }
1.477 albertel 3830: $result .= &Apache::loncommon::end_data_table_header_row().
3831: &Apache::loncommon::start_data_table_header_row().
3832: $header.
3833: &Apache::loncommon::end_data_table_header_row();
3834: my @noupdate;
1.126 ng 3835: my ($updateCtr,$noupdateCtr) = (1,1);
1.257 albertel 3836: for ($i=0; $i<$env{'form.total'}; $i++) {
1.93 albertel 3837: my $line;
1.257 albertel 3838: my $user = $env{'form.ctr'.$i};
1.281 albertel 3839: my ($uname,$udom)=split(/:/,$user);
1.44 ng 3840: my %newrecord;
3841: my $updateflag = 0;
1.281 albertel 3842: $line .= '<td>'.&nameUserString(undef,$$fullname{$user},$uname,$udom).'</td>';
1.108 albertel 3843: my $usec=$classlist->{"$uname:$udom"}[5];
1.105 albertel 3844: if (!&canmodify($usec)) {
1.126 ng 3845: my $numcols=scalar(@partid)*4+2;
1.477 albertel 3846: push(@noupdate,
1.478 albertel 3847: $line."<td colspan=\"$numcols\"><span class=\"LC_warning\">".
3848: &mt('Not allowed to modify student')."</span></td></tr>");
1.105 albertel 3849: next;
3850: }
1.269 raeburn 3851: my %aggregate = ();
3852: my $aggregateflag = 0;
1.281 albertel 3853: $user=~s/:/_/; # colon doen't work in javascript for names
1.44 ng 3854: foreach (@partid) {
1.257 albertel 3855: my $old_aw = $env{'form.GD_'.$user.'_'.$_.'_awarded_s'};
1.54 albertel 3856: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
3857: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
1.257 albertel 3858: my $old_score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
3859: my $awarded = $env{'form.GD_'.$user.'_'.$_.'_awarded'};
1.54 albertel 3860: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
3861: my $partial = $awarded eq '' ? '' : $pcr;
1.44 ng 3862: my $score;
3863: if ($partial eq '') {
1.257 albertel 3864: $score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 3865: } elsif ($partial > 0) {
3866: $score = 'correct_by_override';
3867: } elsif ($partial == 0) {
3868: $score = 'incorrect_by_override';
3869: }
1.257 albertel 3870: my $dropMenu = $env{'form.GD_'.$user.'_'.$_.'_solved'};
1.125 ng 3871: $score = 'excused' if (($dropMenu eq 'excused') && ($score ne 'excused'));
3872:
1.292 albertel 3873: $newrecord{'resource.'.$_.'.regrader'}=
3874: "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 3875: if ($dropMenu eq 'reset status' &&
3876: $old_score ne '') { # ignore if no previous attempts => nothing to reset
1.299 albertel 3877: $newrecord{'resource.'.$_.'.tries'} = '';
1.125 ng 3878: $newrecord{'resource.'.$_.'.solved'} = '';
3879: $newrecord{'resource.'.$_.'.award'} = '';
1.299 albertel 3880: $newrecord{'resource.'.$_.'.awarded'} = '';
1.125 ng 3881: $updateflag = 1;
1.269 raeburn 3882: if ($env{'form.GD_'.$user.'_'.$_.'_aggtries'} > 0) {
3883: my $aggtries = $env{'form.GD_'.$user.'_'.$_.'_aggtries'};
3884: my $totaltries = $env{'form.GD_'.$user.'_'.$_.'_totaltries'};
3885: my $solvedstatus = $env{'form.GD_'.$user.'_'.$_.'_solved_s'};
3886: &decrement_aggs($symb,$_,\%aggregate,$aggtries,$totaltries,$solvedstatus);
3887: $aggregateflag = 1;
3888: }
1.139 albertel 3889: } elsif (!($old_part eq $partial && $old_score eq $score)) {
3890: $updateflag = 1;
3891: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
3892: $newrecord{'resource.'.$_.'.solved'} = $score;
3893: $rec_update++;
1.125 ng 3894: }
3895:
1.93 albertel 3896: $line .= '<td align="center">'.$old_aw.' </td>'.
1.44 ng 3897: '<td align="center">'.$awarded.
3898: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 3899:
1.54 albertel 3900:
3901: my $partid=$_;
3902: foreach my $stores (@parts) {
3903: my ($part,$type) = &split_part_type($stores);
3904: if ($part !~ m/^\Q$partid\E/) { next;}
3905: if ($type eq 'awarded' || $type eq 'solved') { next; }
1.257 albertel 3906: my $old_aw = $env{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
3907: my $awarded = $env{'form.GD_'.$user.'_'.$part.'_'.$type};
1.54 albertel 3908: if ($awarded ne '' && $awarded ne $old_aw) {
3909: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.257 albertel 3910: $newrecord{'resource.'.$part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.54 albertel 3911: $updateflag=1;
3912: }
1.93 albertel 3913: $line .= '<td align="center">'.$old_aw.' </td>'.
1.54 albertel 3914: '<td align="center">'.$awarded.' </td>';
3915: }
1.44 ng 3916: }
1.477 albertel 3917: $line.="\n";
1.301 albertel 3918:
3919: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3920: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3921:
1.44 ng 3922: if ($updateflag) {
3923: $count++;
1.257 albertel 3924: &Apache::lonnet::cstore(\%newrecord,$symb,$env{'request.course.id'},
1.89 albertel 3925: $udom,$uname);
1.301 albertel 3926:
3927: if (&Apache::bridgetask::in_queue('gradingqueue',$symb,$cdom,
3928: $cnum,$udom,$uname)) {
3929: # need to figure out if should be in queue.
3930: my %record =
3931: &Apache::lonnet::restore($symb,$env{'request.course.id'},
3932: $udom,$uname);
3933: my $all_graded = 1;
3934: my $none_graded = 1;
3935: foreach my $part (@parts) {
3936: if ( $record{'resource.'.$part.'.awarded'} eq '' ) {
3937: $all_graded = 0;
3938: } else {
3939: $none_graded = 0;
3940: }
3941: }
3942:
3943: if ($all_graded || $none_graded) {
3944: &Apache::bridgetask::remove_from_queue('gradingqueue',
3945: $symb,$cdom,$cnum,
3946: $udom,$uname);
3947: }
3948: }
3949:
1.477 albertel 3950: $result.=&Apache::loncommon::start_data_table_row().
3951: '<td align="right"> '.$updateCtr.' </td>'.$line.
3952: &Apache::loncommon::end_data_table_row();
1.126 ng 3953: $updateCtr++;
1.93 albertel 3954: } else {
1.477 albertel 3955: push(@noupdate,
3956: '<td align="right"> '.$noupdateCtr.' </td>'.$line);
1.126 ng 3957: $noupdateCtr++;
1.44 ng 3958: }
1.269 raeburn 3959: if ($aggregateflag) {
3960: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 3961: $cdom,$cnum);
1.269 raeburn 3962: }
1.93 albertel 3963: }
1.477 albertel 3964: if (@noupdate) {
1.126 ng 3965: # my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3;
3966: my $numcols=scalar(@partid)*4+2;
1.477 albertel 3967: $result .= &Apache::loncommon::start_data_table_row('LC_empty_row').
1.478 albertel 3968: '<td align="center" colspan="'.$numcols.'">'.
3969: &mt('No Changes Occurred For the Students Below').
3970: '</td>'.
1.477 albertel 3971: &Apache::loncommon::end_data_table_row();
3972: foreach my $line (@noupdate) {
3973: $result.=
3974: &Apache::loncommon::start_data_table_row().
3975: $line.
3976: &Apache::loncommon::end_data_table_row();
3977: }
1.44 ng 3978: }
1.614 www 3979: $result .= &Apache::loncommon::end_data_table();
1.478 albertel 3980: my $msg = '<p><b>'.
3981: &mt('Number of records updated = [_1] for [quant,_2,student].',
3982: $rec_update,$count).'</b><br />'.
3983: '<b>'.&mt('Total number of students = [_1]',$env{'form.total'}).
3984: '</b></p>';
1.44 ng 3985: return $title.$msg.$result;
1.5 albertel 3986: }
1.54 albertel 3987:
3988: sub split_part_type {
3989: my ($partstr) = @_;
3990: my ($temp,@allparts)=split(/_/,$partstr);
3991: my $type=pop(@allparts);
1.439 albertel 3992: my $part=join('_',@allparts);
1.54 albertel 3993: return ($part,$type);
3994: }
3995:
1.44 ng 3996: #------------- end of section for handling grading by section/class ---------
3997: #
3998: #----------------------------------------------------------------------------
3999:
1.5 albertel 4000:
1.44 ng 4001: #----------------------------------------------------------------------------
4002: #
4003: #-------------------------- Next few routines handles grading by csv upload
4004: #
4005: #--- Javascript to handle csv upload
1.27 albertel 4006: sub csvupload_javascript_reverse_associate {
1.573 bisitz 4007: my $error1=&mt('You need to specify the username or the student/employee ID');
1.246 albertel 4008: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 4009: return(<<ENDPICK);
4010: function verify(vf) {
4011: var foundsomething=0;
4012: var founduname=0;
1.243 albertel 4013: var foundID=0;
1.27 albertel 4014: for (i=0;i<=vf.nfields.value;i++) {
4015: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 4016: if (i==0 && tw!=0) { foundID=1; }
4017: if (i==1 && tw!=0) { founduname=1; }
4018: if (i!=0 && i!=1 && i!=2 && tw!=0) { foundsomething=1; }
1.27 albertel 4019: }
1.246 albertel 4020: if (founduname==0 && foundID==0) {
4021: alert('$error1');
4022: return;
1.27 albertel 4023: }
4024: if (foundsomething==0) {
1.246 albertel 4025: alert('$error2');
4026: return;
1.27 albertel 4027: }
4028: vf.submit();
4029: }
4030: function flip(vf,tf) {
4031: var nw=eval('vf.f'+tf+'.selectedIndex');
4032: var i;
4033: for (i=0;i<=vf.nfields.value;i++) {
4034: //can not pick the same destination field for both name and domain
4035: if (((i ==0)||(i ==1)) &&
4036: ((tf==0)||(tf==1)) &&
4037: (i!=tf) &&
4038: (eval('vf.f'+i+'.selectedIndex')==nw)) {
4039: eval('vf.f'+i+'.selectedIndex=0;')
4040: }
4041: }
4042: }
4043: ENDPICK
4044: }
4045:
4046: sub csvupload_javascript_forward_associate {
1.573 bisitz 4047: my $error1=&mt('You need to specify the username or the student/employee ID');
1.246 albertel 4048: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 4049: return(<<ENDPICK);
4050: function verify(vf) {
4051: var foundsomething=0;
4052: var founduname=0;
1.243 albertel 4053: var foundID=0;
1.27 albertel 4054: for (i=0;i<=vf.nfields.value;i++) {
4055: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 4056: if (tw==1) { foundID=1; }
4057: if (tw==2) { founduname=1; }
4058: if (tw>3) { foundsomething=1; }
1.27 albertel 4059: }
1.246 albertel 4060: if (founduname==0 && foundID==0) {
4061: alert('$error1');
4062: return;
1.27 albertel 4063: }
4064: if (foundsomething==0) {
1.246 albertel 4065: alert('$error2');
4066: return;
1.27 albertel 4067: }
4068: vf.submit();
4069: }
4070: function flip(vf,tf) {
4071: var nw=eval('vf.f'+tf+'.selectedIndex');
4072: var i;
4073: //can not pick the same destination field twice
4074: for (i=0;i<=vf.nfields.value;i++) {
4075: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
4076: eval('vf.f'+i+'.selectedIndex=0;')
4077: }
4078: }
4079: }
4080: ENDPICK
4081: }
4082:
1.26 albertel 4083: sub csvuploadmap_header {
1.324 albertel 4084: my ($request,$symb,$datatoken,$distotal)= @_;
1.41 ng 4085: my $javascript;
1.257 albertel 4086: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 4087: $javascript=&csvupload_javascript_reverse_associate();
4088: } else {
4089: $javascript=&csvupload_javascript_forward_associate();
4090: }
1.45 ng 4091:
1.418 albertel 4092: $symb = &Apache::lonenc::check_encrypt($symb);
1.632 www 4093: $request->print('<form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">'.
4094: &mt('Total number of records found in file: [_1]',$distotal).'<hr />'.
4095: &mt('Associate entries from the uploaded file with as many fields as you can.'));
4096: my $reverse=&mt("Reverse Association");
1.41 ng 4097: $request->print(<<ENDPICK);
1.632 www 4098: <br />
4099: <input type="button" value="$reverse" onclick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1.26 albertel 4100: <input type="hidden" name="associate" value="" />
4101: <input type="hidden" name="phase" value="three" />
4102: <input type="hidden" name="datatoken" value="$datatoken" />
1.257 albertel 4103: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
4104: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
1.26 albertel 4105: <input type="hidden" name="upfile_associate"
1.257 albertel 4106: value="$env{'form.upfile_associate'}" />
1.26 albertel 4107: <input type="hidden" name="symb" value="$symb" />
1.246 albertel 4108: <input type="hidden" name="command" value="csvuploadoptions" />
1.26 albertel 4109: <hr />
4110: ENDPICK
1.597 wenzelju 4111: $request->print(&Apache::lonhtmlcommon::scripttag($javascript));
1.118 ng 4112: return '';
1.26 albertel 4113:
4114: }
4115:
4116: sub csvupload_fields {
1.582 raeburn 4117: my ($symb,$errorref) = @_;
4118: my (@parts) = &getpartlist($symb,$errorref);
4119: if (ref($errorref)) {
4120: if ($$errorref) {
4121: return;
4122: }
4123: }
4124:
1.556 weissno 4125: my @fields=(['ID','Student/Employee ID'],
1.243 albertel 4126: ['username','Student Username'],
4127: ['domain','Student Domain']);
1.324 albertel 4128: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.41 ng 4129: foreach my $part (sort(@parts)) {
4130: my @datum;
4131: my $display=&Apache::lonnet::metadata($url,$part.'.display');
4132: my $name=$part;
4133: if (!$display) { $display = $name; }
4134: @datum=($name,$display);
1.244 albertel 4135: if ($name=~/^stores_(.*)_awarded/) {
4136: push(@fields,['stores_'.$1.'_points',"Points [Part: $1]"]);
4137: }
1.41 ng 4138: push(@fields,\@datum);
4139: }
4140: return (@fields);
1.26 albertel 4141: }
4142:
4143: sub csvuploadmap_footer {
1.41 ng 4144: my ($request,$i,$keyfields) =@_;
4145: $request->print(<<ENDPICK);
1.26 albertel 4146: </table>
4147: <input type="hidden" name="nfields" value="$i" />
4148: <input type="hidden" name="keyfields" value="$keyfields" />
1.589 bisitz 4149: <input type="button" onclick="javascript:verify(this.form)" value="Assign Grades" /><br />
1.26 albertel 4150: </form>
4151: ENDPICK
4152: }
4153:
1.283 albertel 4154: sub checkforfile_js {
1.638 www 4155: my $alertmsg = &mt('Please use the browse button to select a file from your local directory.');
1.597 wenzelju 4156: my $result = &Apache::lonhtmlcommon::scripttag(<<CSVFORMJS);
1.86 ng 4157: function checkUpload(formname) {
4158: if (formname.upfile.value == "") {
1.539 riegler 4159: alert("$alertmsg");
1.86 ng 4160: return false;
4161: }
4162: formname.submit();
4163: }
4164: CSVFORMJS
1.283 albertel 4165: return $result;
4166: }
4167:
4168: sub upcsvScores_form {
1.608 www 4169: my ($request,$symb) = @_;
1.283 albertel 4170: if (!$symb) {return '';}
4171: my $result=&checkforfile_js();
1.632 www 4172: $result.=&Apache::loncommon::start_data_table().
4173: &Apache::loncommon::start_data_table_header_row().
4174: '<th>'.&mt('Specify a file containing the class scores for current resource.').'</th>'.
4175: &Apache::loncommon::end_data_table_header_row().
4176: &Apache::loncommon::start_data_table_row().'<td>';
1.370 www 4177: my $upload=&mt("Upload Scores");
1.86 ng 4178: my $upfile_select=&Apache::loncommon::upfile_select_html();
1.245 albertel 4179: my $ignore=&mt('Ignore First Line');
1.418 albertel 4180: $symb = &Apache::lonenc::check_encrypt($symb);
1.86 ng 4181: $result.=<<ENDUPFORM;
1.106 albertel 4182: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.86 ng 4183: <input type="hidden" name="symb" value="$symb" />
4184: <input type="hidden" name="command" value="csvuploadmap" />
4185: $upfile_select
1.589 bisitz 4186: <br /><input type="button" onclick="javascript:checkUpload(this.form);" value="$upload" />
1.86 ng 4187: </form>
4188: ENDUPFORM
1.370 www 4189: $result.=&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
1.632 www 4190: &mt("How do I create a CSV file from a spreadsheet")).
4191: '</td>'.
4192: &Apache::loncommon::end_data_table_row().
4193: &Apache::loncommon::end_data_table();
1.86 ng 4194: return $result;
4195: }
4196:
4197:
1.26 albertel 4198: sub csvuploadmap {
1.608 www 4199: my ($request,$symb)= @_;
1.41 ng 4200: if (!$symb) {return '';}
1.72 ng 4201:
1.41 ng 4202: my $datatoken;
1.257 albertel 4203: if (!$env{'form.datatoken'}) {
1.41 ng 4204: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 4205: } else {
1.257 albertel 4206: $datatoken=$env{'form.datatoken'};
1.41 ng 4207: &Apache::loncommon::load_tmp_file($request);
1.26 albertel 4208: }
1.41 ng 4209: my @records=&Apache::loncommon::upfile_record_sep();
1.324 albertel 4210: &csvuploadmap_header($request,$symb,$datatoken,$#records+1);
1.41 ng 4211: my ($i,$keyfields);
4212: if (@records) {
1.582 raeburn 4213: my $fieldserror;
4214: my @fields=&csvupload_fields($symb,\$fieldserror);
4215: if ($fieldserror) {
4216: $request->print(&navmap_errormsg());
4217: return;
4218: }
1.257 albertel 4219: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 4220: &Apache::loncommon::csv_print_samples($request,\@records);
4221: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
4222: \@fields);
4223: foreach (@fields) { $keyfields.=$_->[0].','; }
4224: chop($keyfields);
4225: } else {
4226: unshift(@fields,['none','']);
4227: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
4228: \@fields);
1.311 banghart 4229: foreach my $rec (@records) {
4230: my %temp = &Apache::loncommon::record_sep($rec);
4231: if (%temp) {
4232: $keyfields=join(',',sort(keys(%temp)));
4233: last;
4234: }
4235: }
1.41 ng 4236: }
4237: }
4238: &csvuploadmap_footer($request,$i,$keyfields);
1.72 ng 4239:
1.41 ng 4240: return '';
1.27 albertel 4241: }
4242:
1.246 albertel 4243: sub csvuploadoptions {
1.608 www 4244: my ($request,$symb)= @_;
1.632 www 4245: my $overwrite=&mt('Overwrite any existing score');
1.246 albertel 4246: $request->print(<<ENDPICK);
4247: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
4248: <input type="hidden" name="command" value="csvuploadassign" />
4249: <p>
4250: <label>
4251: <input type="checkbox" name="overwite_scores" checked="checked" />
1.632 www 4252: $overwrite
1.246 albertel 4253: </label>
4254: </p>
4255: ENDPICK
4256: my %fields=&get_fields();
4257: if (!defined($fields{'domain'})) {
1.257 albertel 4258: my $domform = &Apache::loncommon::select_dom_form($env{'request.role.domain'},'default_domain');
1.632 www 4259: $request->print("\n<p>".&mt('Users are in domain: [_1]',$domform)."</p>\n");
1.246 albertel 4260: }
1.257 albertel 4261: foreach my $key (sort(keys(%env))) {
1.246 albertel 4262: if ($key !~ /^form\.(.*)$/) { next; }
4263: my $cleankey=$1;
4264: if ($cleankey eq 'command') { next; }
4265: $request->print('<input type="hidden" name="'.$cleankey.
1.257 albertel 4266: '" value="'.$env{$key}.'" />'."\n");
1.246 albertel 4267: }
4268: # FIXME do a check for any duplicated user ids...
4269: # FIXME do a check for any invalid user ids?...
1.290 albertel 4270: $request->print('<input type="submit" value="Assign Grades" /><br />
4271: <hr /></form>'."\n");
1.246 albertel 4272: return '';
4273: }
4274:
4275: sub get_fields {
4276: my %fields;
1.257 albertel 4277: my @keyfields = split(/\,/,$env{'form.keyfields'});
4278: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
4279: if ($env{'form.upfile_associate'} eq 'reverse') {
4280: if ($env{'form.f'.$i} ne 'none') {
4281: $fields{$keyfields[$i]}=$env{'form.f'.$i};
1.41 ng 4282: }
4283: } else {
1.257 albertel 4284: if ($env{'form.f'.$i} ne 'none') {
4285: $fields{$env{'form.f'.$i}}=$keyfields[$i];
1.41 ng 4286: }
4287: }
1.27 albertel 4288: }
1.246 albertel 4289: return %fields;
4290: }
4291:
4292: sub csvuploadassign {
1.608 www 4293: my ($request,$symb)= @_;
1.246 albertel 4294: if (!$symb) {return '';}
1.345 bowersj2 4295: my $error_msg = '';
1.246 albertel 4296: &Apache::loncommon::load_tmp_file($request);
4297: my @gradedata = &Apache::loncommon::upfile_record_sep();
4298: my %fields=&get_fields();
1.257 albertel 4299: my $courseid=$env{'request.course.id'};
1.97 albertel 4300: my ($classlist) = &getclasslist('all',0);
1.106 albertel 4301: my @notallowed;
1.41 ng 4302: my @skipped;
1.657 raeburn 4303: my @warnings;
1.41 ng 4304: my $countdone=0;
4305: foreach my $grade (@gradedata) {
4306: my %entries=&Apache::loncommon::record_sep($grade);
1.246 albertel 4307: my $domain;
4308: if ($entries{$fields{'domain'}}) {
4309: $domain=$entries{$fields{'domain'}};
4310: } else {
1.257 albertel 4311: $domain=$env{'form.default_domain'};
1.246 albertel 4312: }
1.243 albertel 4313: $domain=~s/\s//g;
1.41 ng 4314: my $username=$entries{$fields{'username'}};
1.160 albertel 4315: $username=~s/\s//g;
1.243 albertel 4316: if (!$username) {
4317: my $id=$entries{$fields{'ID'}};
1.247 albertel 4318: $id=~s/\s//g;
1.243 albertel 4319: my %ids=&Apache::lonnet::idget($domain,$id);
4320: $username=$ids{$id};
4321: }
1.41 ng 4322: if (!exists($$classlist{"$username:$domain"})) {
1.247 albertel 4323: my $id=$entries{$fields{'ID'}};
4324: $id=~s/\s//g;
4325: if ($id) {
4326: push(@skipped,"$id:$domain");
4327: } else {
4328: push(@skipped,"$username:$domain");
4329: }
1.41 ng 4330: next;
4331: }
1.108 albertel 4332: my $usec=$classlist->{"$username:$domain"}[5];
1.106 albertel 4333: if (!&canmodify($usec)) {
4334: push(@notallowed,"$username:$domain");
4335: next;
4336: }
1.244 albertel 4337: my %points;
1.41 ng 4338: my %grades;
4339: foreach my $dest (keys(%fields)) {
1.244 albertel 4340: if ($dest eq 'ID' || $dest eq 'username' ||
4341: $dest eq 'domain') { next; }
4342: if ($entries{$fields{$dest}} =~ /^\s*$/) { next; }
4343: if ($dest=~/stores_(.*)_points/) {
4344: my $part=$1;
4345: my $wgt =&Apache::lonnet::EXT('resource.'.$part.'.weight',
4346: $symb,$domain,$username);
1.345 bowersj2 4347: if ($wgt) {
4348: $entries{$fields{$dest}}=~s/\s//g;
4349: my $pcr=$entries{$fields{$dest}} / $wgt;
1.463 albertel 4350: my $award=($pcr == 0) ? 'incorrect_by_override'
4351: : 'correct_by_override';
1.638 www 4352: if ($pcr>1) {
1.657 raeburn 4353: push(@warnings,&mt("[_1]: point value larger than weight","$username:$domain"));
1.638 www 4354: }
1.345 bowersj2 4355: $grades{"resource.$part.awarded"}=$pcr;
4356: $grades{"resource.$part.solved"}=$award;
4357: $points{$part}=1;
4358: } else {
4359: $error_msg = "<br />" .
4360: &mt("Some point values were assigned"
4361: ." for problems with a weight "
4362: ."of zero. These values were "
4363: ."ignored.");
4364: }
1.244 albertel 4365: } else {
4366: if ($dest=~/stores_(.*)_awarded/) { if ($points{$1}) {next;} }
4367: if ($dest=~/stores_(.*)_solved/) { if ($points{$1}) {next;} }
4368: my $store_key=$dest;
4369: $store_key=~s/^stores/resource/;
4370: $store_key=~s/_/\./g;
4371: $grades{$store_key}=$entries{$fields{$dest}};
4372: }
1.41 ng 4373: }
1.508 www 4374: if (! %grades) {
4375: push(@skipped,&mt("[_1]: no data to save","$username:$domain"));
4376: } else {
4377: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
4378: my $result=&Apache::lonnet::cstore(\%grades,$symb,
1.302 albertel 4379: $env{'request.course.id'},
4380: $domain,$username);
1.508 www 4381: if ($result eq 'ok') {
1.627 www 4382: # Successfully stored
1.508 www 4383: $request->print('.');
1.627 www 4384: # Remove from grading queue
4385: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,
4386: $env{'course.'.$env{'request.course.id'}.'.domain'},
4387: $env{'course.'.$env{'request.course.id'}.'.num'},
4388: $domain,$username);
4389: $countdone++;
4390: } else {
1.508 www 4391: $request->print("<p><span class=\"LC_error\">".
4392: &mt("Failed to save data for student [_1]. Message when trying to save was: [_2]",
4393: "$username:$domain",$result)."</span></p>");
4394: }
4395: $request->rflush();
4396: }
1.41 ng 4397: }
1.570 www 4398: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt("Saved scores for [quant,_1,student]",$countdone),$countdone==0));
1.657 raeburn 4399: if (@warnings) {
4400: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('Warnings generated for the following saved scores:'),1).'<br />');
4401: $request->print(join(', ',@warnings));
4402: }
1.41 ng 4403: if (@skipped) {
1.571 www 4404: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('No scores stored for the following username(s):'),1).'<br />');
4405: $request->print(join(', ',@skipped));
1.106 albertel 4406: }
4407: if (@notallowed) {
1.571 www 4408: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('Modification of scores not allowed for the following username(s):'),1).'<br />');
4409: $request->print(join(', ',@notallowed));
1.41 ng 4410: }
1.106 albertel 4411: $request->print("<br />\n");
1.345 bowersj2 4412: return $error_msg;
1.26 albertel 4413: }
1.44 ng 4414: #------------- end of section for handling csv file upload ---------
4415: #
4416: #-------------------------------------------------------------------
4417: #
1.122 ng 4418: #-------------- Next few routines handle grading by page/sequence
1.72 ng 4419: #
4420: #--- Select a page/sequence and a student to grade
1.68 ng 4421: sub pickStudentPage {
1.608 www 4422: my ($request,$symb) = @_;
1.68 ng 4423:
1.539 riegler 4424: my $alertmsg = &mt('Please select the student you wish to grade.');
1.597 wenzelju 4425: $request->print(&Apache::lonhtmlcommon::scripttag(<<LISTJAVASCRIPT));
1.68 ng 4426:
4427: function checkPickOne(formname) {
1.76 ng 4428: if (radioSelection(formname.student) == null) {
1.539 riegler 4429: alert("$alertmsg");
1.68 ng 4430: return;
4431: }
1.125 ng 4432: ptr = pullDownSelection(formname.selectpage);
4433: formname.page.value = formname["page"+ptr].value;
4434: formname.title.value = formname["title"+ptr].value;
1.68 ng 4435: formname.submit();
4436: }
4437:
4438: LISTJAVASCRIPT
1.118 ng 4439: &commonJSfunctions($request);
1.608 www 4440:
1.257 albertel 4441: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4442: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4443: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.68 ng 4444:
1.398 albertel 4445: my $result='<h3><span class="LC_info"> '.
1.485 albertel 4446: &mt('Manual Grading by Page or Sequence').'</span></h3>';
1.68 ng 4447:
1.80 ng 4448: $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
1.582 raeburn 4449: my $map_error;
4450: my ($titles,$symbx) = &getSymbMap($map_error);
4451: if ($map_error) {
4452: $request->print(&navmap_errormsg());
4453: return;
4454: }
1.137 albertel 4455: my ($curpage) =&Apache::lonnet::decode_symb($symb);
4456: # my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb);
4457: # my $type=($curpage =~ /\.(page|sequence)/);
1.485 albertel 4458: my $select = '<select name="selectpage">'."\n";
1.70 ng 4459: my $ctr=0;
1.68 ng 4460: foreach (@$titles) {
4461: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.485 albertel 4462: $select.='<option value="'.$ctr.'" '.
1.401 albertel 4463: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.71 ng 4464: '>'.$showtitle.'</option>'."\n";
1.70 ng 4465: $ctr++;
1.68 ng 4466: }
1.485 albertel 4467: $select.= '</select>';
1.539 riegler 4468: $result.=' <b>'.&mt('Problems from').':</b> '.$select."<br />\n";
1.485 albertel 4469:
1.70 ng 4470: $ctr=0;
4471: foreach (@$titles) {
4472: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
4473: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
4474: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
4475: $ctr++;
4476: }
1.72 ng 4477: $result.='<input type="hidden" name="page" />'."\n".
4478: '<input type="hidden" name="title" />'."\n";
1.68 ng 4479:
1.485 albertel 4480: my $options =
4481: '<label><input type="radio" name="vProb" value="no" checked="checked" /> '.&mt('no').' </label>'."\n".
4482: '<label><input type="radio" name="vProb" value="yes" /> '.&mt('yes').' </label>'."<br />\n";
1.539 riegler 4483: $result.=' <b>'.&mt('View Problem Text').': </b>'.$options;
1.485 albertel 4484:
4485: $options =
4486: '<label><input type="radio" name="lastSub" value="none" /> '.&mt('none').' </label>'."\n".
1.699 ! kruse 4487: '<label><input type="radio" name="lastSub" value="datesub" checked="checked" /> '.&mt('all submissions').'</label>'."\n".
! 4488: '<label><input type="radio" name="lastSub" value="all" /> '.&mt('all submissions with details').' </label>'."\n";
! 4489: $result.=' <b>'.&mt('View Submissions').': </b>'.$options;
1.432 banghart 4490:
4491: $result.=&build_section_inputs();
1.442 banghart 4492: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
4493: $result.='<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.72 ng 4494: '<input type="hidden" name="command" value="displayPage" />'."\n".
1.613 www 4495: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."<br />\n";
1.72 ng 4496:
1.539 riegler 4497: $result.=' <b>'.&mt('Use CODE').': </b> <input type="text" name="CODE" value="" /> <br />'."\n";
1.382 albertel 4498:
1.80 ng 4499: $result.=' <input type="button" '.
1.589 bisitz 4500: 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /><br />'."\n";
1.72 ng 4501:
1.68 ng 4502: $request->print($result);
4503:
1.485 albertel 4504: my $studentTable.=' <b>'.&mt('Select a student you wish to grade and then click on the Next button.').'</b><br />'.
1.484 albertel 4505: &Apache::loncommon::start_data_table().
4506: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 4507: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 4508: '<th>'.&nameUserString('header').'</th>'.
1.485 albertel 4509: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 4510: '<th>'.&nameUserString('header').'</th>'.
4511: &Apache::loncommon::end_data_table_header_row();
1.68 ng 4512:
1.76 ng 4513: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.68 ng 4514: my $ptr = 1;
1.294 albertel 4515: foreach my $student (sort
4516: {
4517: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
4518: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
4519: }
4520: return $a cmp $b;
4521: } (keys(%$fullname))) {
1.68 ng 4522: my ($uname,$udom) = split(/:/,$student);
1.484 albertel 4523: $studentTable.=($ptr%2==1 ? &Apache::loncommon::start_data_table_row()
4524: : '</td>');
1.126 ng 4525: $studentTable.='<td align="right">'.$ptr.' </td>';
1.288 albertel 4526: $studentTable.='<td> <label><input type="radio" name="student" value="'.$student.'" /> '
4527: .&nameUserString(undef,$$fullname{$student},$uname,$udom)."</label>\n";
1.484 albertel 4528: $studentTable.=
4529: ($ptr%2 == 0 ? '</td>'.&Apache::loncommon::end_data_table_row()
4530: : '');
1.68 ng 4531: $ptr++;
4532: }
1.484 albertel 4533: if ($ptr%2 == 0) {
4534: $studentTable.='</td><td> </td><td> </td>'.
4535: &Apache::loncommon::end_data_table_row();
4536: }
4537: $studentTable.=&Apache::loncommon::end_data_table()."\n";
1.126 ng 4538: $studentTable.='<input type="button" '.
1.589 bisitz 4539: 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /></form>'."\n";
1.68 ng 4540:
4541: $request->print($studentTable);
4542:
4543: return '';
4544: }
4545:
4546: sub getSymbMap {
1.582 raeburn 4547: my ($map_error) = @_;
1.132 bowersj2 4548: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 4549: unless (ref($navmap)) {
4550: if (ref($map_error)) {
4551: $$map_error = 'navmap';
4552: }
4553: return;
4554: }
1.68 ng 4555: my %symbx = ();
4556: my @titles = ();
1.117 bowersj2 4557: my $minder = 0;
4558:
4559: # Gather every sequence that has problems.
1.240 albertel 4560: my @sequences = $navmap->retrieveResources(undef, sub { shift->is_map(); },
4561: 1,0,1);
1.117 bowersj2 4562: for my $sequence ($navmap->getById('0.0'), @sequences) {
1.241 albertel 4563: if ($navmap->hasResource($sequence, sub { shift->is_problem(); }, 0) ) {
1.381 albertel 4564: my $title = $minder.'.'.
4565: &HTML::Entities::encode($sequence->compTitle(),'"\'&');
4566: push(@titles, $title); # minder in case two titles are identical
4567: $symbx{$title} = &HTML::Entities::encode($sequence->symb(),'"\'&');
1.117 bowersj2 4568: $minder++;
1.241 albertel 4569: }
1.68 ng 4570: }
4571: return \@titles,\%symbx;
4572: }
4573:
1.72 ng 4574: #
4575: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68 ng 4576: sub displayPage {
1.608 www 4577: my ($request,$symb) = @_;
1.257 albertel 4578: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4579: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4580: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
4581: my $pageTitle = $env{'form.page'};
1.103 albertel 4582: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 4583: my ($uname,$udom) = split(/:/,$env{'form.student'});
4584: my $usec=$classlist->{$env{'form.student'}}[5];
1.168 albertel 4585:
4586: #need to make sure we have the correct data for later EXT calls,
4587: #thus invalidate the cache
4588: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 4589: $env{'course.'.$env{'request.course.id'}.'.num'},
4590: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 4591: &Apache::lonnet::clear_EXT_cache_status();
4592:
1.103 albertel 4593: if (!&canview($usec)) {
1.485 albertel 4594: $request->print('<span class="LC_warning">'.&mt('Unable to view requested student. ([_1])',$env{'form.student'}).'</span>');
1.103 albertel 4595: return;
4596: }
1.398 albertel 4597: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.485 albertel 4598: $result.='<h3> '.&mt('Student: [_1]',&nameUserString(undef,$$fullname{$env{'form.student'}},$uname,$udom)).
1.129 ng 4599: '</h3>'."\n";
1.500 albertel 4600: $env{'form.CODE'} = uc($env{'form.CODE'});
1.501 foxr 4601: if (&Apache::lonnet::validCODE(uc($env{'form.CODE'}))) {
1.485 albertel 4602: $result.='<h3> '.&mt('CODE: [_1]',$env{'form.CODE'}).'</h3>'."\n";
1.382 albertel 4603: } else {
4604: delete($env{'form.CODE'});
4605: }
1.71 ng 4606: &sub_page_js($request);
4607: $request->print($result);
4608:
1.132 bowersj2 4609: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 4610: unless (ref($navmap)) {
4611: $request->print(&navmap_errormsg());
4612: return;
4613: }
1.257 albertel 4614: my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($env{'form.page'});
1.68 ng 4615: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 4616: if (!$map) {
1.485 albertel 4617: $request->print('<span class="LC_warning">'.&mt('Unable to view requested sequence. ([_1])',$resUrl).'</span>');
1.288 albertel 4618: return;
4619: }
1.68 ng 4620: my $iterator = $navmap->getIterator($map->map_start(),
4621: $map->map_finish());
4622:
1.71 ng 4623: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72 ng 4624: '<input type="hidden" name="command" value="gradeByPage" />'."\n".
1.257 albertel 4625: '<input type="hidden" name="fullname" value="'.$$fullname{$env{'form.student'}}.'" />'."\n".
4626: '<input type="hidden" name="student" value="'.$env{'form.student'}.'" />'."\n".
1.72 ng 4627: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
1.257 albertel 4628: '<input type="hidden" name="title" value="'.$env{'form.title'}.'" />'."\n".
1.418 albertel 4629: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.613 www 4630: '<input type="hidden" name="overRideScore" value="no" />'."\n";
1.71 ng 4631:
1.382 albertel 4632: if (defined($env{'form.CODE'})) {
4633: $studentTable.=
4634: '<input type="hidden" name="CODE" value="'.$env{'form.CODE'}.'" />'."\n";
4635: }
1.381 albertel 4636: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 4637: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 4638:
1.594 bisitz 4639: $studentTable.=' <span class="LC_info">'.
4640: &mt('Problems graded correct by the computer are marked with a [_1] symbol.',$checkIcon).
4641: '</span>'."\n".
1.484 albertel 4642: &Apache::loncommon::start_data_table().
4643: &Apache::loncommon::start_data_table_header_row().
4644: '<th align="center"> Prob. </th>'.
1.485 albertel 4645: '<th> '.($env{'form.vProb'} eq 'no' ? &mt('Title') : &mt('Problem Text')).'/'.&mt('Grade').'</th>'.
1.484 albertel 4646: &Apache::loncommon::end_data_table_header_row();
1.71 ng 4647:
1.329 albertel 4648: &Apache::lonxml::clear_problem_counter();
1.196 albertel 4649: my ($depth,$question,$prob) = (1,1,1);
1.68 ng 4650: $iterator->next(); # skip the first BEGIN_MAP
4651: my $curRes = $iterator->next(); # for "current resource"
1.101 albertel 4652: while ($depth > 0) {
1.68 ng 4653: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4654: if($curRes == $iterator->END_MAP) { $depth--; }
1.68 ng 4655:
1.385 albertel 4656: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4657: my $parts = $curRes->parts();
1.68 ng 4658: my $title = $curRes->compTitle();
1.71 ng 4659: my $symbx = $curRes->symb();
1.484 albertel 4660: $studentTable.=
4661: &Apache::loncommon::start_data_table_row().
4662: '<td align="center" valign="top" >'.$prob.
1.485 albertel 4663: (scalar(@{$parts}) == 1 ? ''
1.681 raeburn 4664: : '<br />('.&mt('[_1]parts',
4665: scalar(@{$parts}).' ').')'
1.485 albertel 4666: ).
4667: '</td>';
1.71 ng 4668: $studentTable.='<td valign="top">';
1.382 albertel 4669: my %form = ('CODE' => $env{'form.CODE'},);
1.257 albertel 4670: if ($env{'form.vProb'} eq 'yes' ) {
1.144 albertel 4671: $studentTable.=&show_problem($request,$symbx,$uname,$udom,1,
1.383 albertel 4672: undef,'both',\%form);
1.71 ng 4673: } else {
1.382 albertel 4674: my $companswer = &Apache::loncommon::get_student_answers($symbx,$uname,$udom,$env{'request.course.id'},%form);
1.80 ng 4675: $companswer =~ s|<form(.*?)>||g;
4676: $companswer =~ s|</form>||g;
1.71 ng 4677: # while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
1.116 ng 4678: # $companswer =~ s/$1/ /ms;
1.326 albertel 4679: # $request->print('match='.$1."<br />\n");
1.71 ng 4680: # }
1.116 ng 4681: # $companswer =~ s|<table border=\"1\">|<table border=\"0\">|g;
1.539 riegler 4682: $studentTable.=' <b>'.$title.'</b> <br /> <b>'.&mt('Correct answer').':</b><br />'.$companswer;
1.71 ng 4683: }
4684:
1.257 albertel 4685: my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
1.125 ng 4686:
1.257 albertel 4687: if ($env{'form.lastSub'} eq 'datesub') {
1.71 ng 4688: if ($record{'version'} eq '') {
1.485 albertel 4689: $studentTable.='<br /> <span class="LC_warning">'.&mt('No recorded submission for this problem.').'</span><br />';
1.71 ng 4690: } else {
1.116 ng 4691: my %responseType = ();
4692: foreach my $partid (@{$parts}) {
1.147 albertel 4693: my @responseIds =$curRes->responseIds($partid);
4694: my @responseType =$curRes->responseType($partid);
4695: my %responseIds;
4696: for (my $i=0;$i<=$#responseIds;$i++) {
4697: $responseIds{$responseIds[$i]}=$responseType[$i];
4698: }
4699: $responseType{$partid} = \%responseIds;
1.116 ng 4700: }
1.148 albertel 4701: $studentTable.= &displaySubByDates($symbx,\%record,$parts,\%responseType,$checkIcon,$uname,$udom);
1.147 albertel 4702:
1.71 ng 4703: }
1.257 albertel 4704: } elsif ($env{'form.lastSub'} eq 'all') {
4705: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.71 ng 4706: $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
1.257 albertel 4707: $env{'request.course.id'},
1.71 ng 4708: '','.submission');
4709:
4710: }
1.103 albertel 4711: if (&canmodify($usec)) {
1.585 bisitz 4712: $studentTable.=&gradeBox_start();
1.103 albertel 4713: foreach my $partid (@{$parts}) {
4714: $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
4715: $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
4716: $question++;
4717: }
1.585 bisitz 4718: $studentTable.=&gradeBox_end();
1.196 albertel 4719: $prob++;
1.71 ng 4720: }
4721: $studentTable.='</td></tr>';
1.68 ng 4722:
1.103 albertel 4723: }
1.68 ng 4724: $curRes = $iterator->next();
4725: }
4726:
1.589 bisitz 4727: $studentTable.=
4728: '</table>'."\n".
4729: '<input type="button" value="'.&mt('Save').'" '.
4730: 'onclick="javascript:checkSubmitPage(this.form,'.$question.');" />'.
4731: '</form>'."\n";
1.71 ng 4732: $request->print($studentTable);
4733:
4734: return '';
1.119 ng 4735: }
4736:
4737: sub displaySubByDates {
1.148 albertel 4738: my ($symb,$record,$parts,$responseType,$checkIcon,$uname,$udom) = @_;
1.224 albertel 4739: my $isCODE=0;
1.335 albertel 4740: my $isTask = ($symb =~/\.task$/);
1.224 albertel 4741: if (exists($record->{'resource.CODE'})) { $isCODE=1; }
1.467 albertel 4742: my $studentTable=&Apache::loncommon::start_data_table().
4743: &Apache::loncommon::start_data_table_header_row().
4744: '<th>'.&mt('Date/Time').'</th>'.
4745: ($isCODE?'<th>'.&mt('CODE').'</th>':'').
1.671 raeburn 4746: ($isTask?'<th>'.&mt('Version').'</th>':'').
1.467 albertel 4747: '<th>'.&mt('Submission').'</th>'.
4748: '<th>'.&mt('Status').'</th>'.
4749: &Apache::loncommon::end_data_table_header_row();
1.119 ng 4750: my ($version);
4751: my %mark;
1.148 albertel 4752: my %orders;
1.119 ng 4753: $mark{'correct_by_student'} = $checkIcon;
1.147 albertel 4754: if (!exists($$record{'1:timestamp'})) {
1.539 riegler 4755: return '<br /> <span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br />';
1.147 albertel 4756: }
1.335 albertel 4757:
4758: my $interaction;
1.525 raeburn 4759: my $no_increment = 1;
1.640 raeburn 4760: my %lastrndseed;
1.119 ng 4761: for ($version=1;$version<=$$record{'version'};$version++) {
1.467 albertel 4762: my $timestamp =
4763: &Apache::lonlocal::locallocaltime($$record{$version.':timestamp'});
1.335 albertel 4764: if (exists($$record{$version.':resource.0.version'})) {
4765: $interaction = $$record{$version.':resource.0.version'};
4766: }
1.671 raeburn 4767: if ($isTask && $env{'form.previousversion'}) {
4768: next unless ($interaction == $env{'form.previousversion'});
4769: }
1.335 albertel 4770: my $where = ($isTask ? "$version:resource.$interaction"
4771: : "$version:resource");
1.467 albertel 4772: $studentTable.=&Apache::loncommon::start_data_table_row().
4773: '<td>'.$timestamp.'</td>';
1.224 albertel 4774: if ($isCODE) {
4775: $studentTable.='<td>'.$record->{$version.':resource.CODE'}.'</td>';
4776: }
1.671 raeburn 4777: if ($isTask) {
4778: $studentTable.='<td>'.$interaction.'</td>';
4779: }
1.119 ng 4780: my @versionKeys = split(/\:/,$$record{$version.':keys'});
4781: my @displaySub = ();
4782: foreach my $partid (@{$parts}) {
1.640 raeburn 4783: my ($hidden,$type);
4784: $type = $$record{$version.':resource.'.$partid.'.type'};
4785: if (($type eq 'anonsurvey') || ($type eq 'anonsurveycred')) {
1.596 raeburn 4786: $hidden = 1;
4787: }
1.335 albertel 4788: my @matchKey = ($isTask ? sort(grep /^resource\.\d+\.\Q$partid\E\.award$/,@versionKeys)
4789: : sort(grep /^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys));
4790:
1.122 ng 4791: # next if ($$record{"$version:resource.$partid.solved"} eq '');
1.324 albertel 4792: my $display_part=&get_display_part($partid,$symb);
1.147 albertel 4793: foreach my $matchKey (@matchKey) {
1.198 albertel 4794: if (exists($$record{$version.':'.$matchKey}) &&
4795: $$record{$version.':'.$matchKey} ne '') {
1.596 raeburn 4796:
1.335 albertel 4797: my ($responseId)= ($isTask ? ($matchKey=~ /^resource\.(.*?)\.\Q$partid\E\.award$/)
4798: : ($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/));
1.670 raeburn 4799: $displaySub[0].='<span class="LC_nobreak">';
1.577 bisitz 4800: $displaySub[0].='<b>'.&mt('Part: [_1]',$display_part).'</b>'
4801: .' <span class="LC_internal_info">'
1.625 www 4802: .'('.&mt('Response ID: [_1]',$responseId).')'
1.577 bisitz 4803: .'</span>'
4804: .' <b>';
1.596 raeburn 4805: if ($hidden) {
4806: $displaySub[0].= &mt('Anonymous Survey').'</b>';
4807: } else {
1.640 raeburn 4808: my ($trial,$rndseed,$newvariation);
4809: if ($type eq 'randomizetry') {
4810: $trial = $$record{"$where.$partid.tries"};
4811: $rndseed = $$record{"$where.$partid.rndseed"};
4812: }
1.596 raeburn 4813: if ($$record{"$where.$partid.tries"} eq '') {
4814: $displaySub[0].=&mt('Trial not counted');
4815: } else {
4816: $displaySub[0].=&mt('Trial: [_1]',
1.467 albertel 4817: $$record{"$where.$partid.tries"});
1.640 raeburn 4818: if ($rndseed || $lastrndseed{$partid}) {
4819: if ($rndseed ne $lastrndseed{$partid}) {
4820: $newvariation = ' ('.&mt('New variation this try').')';
4821: }
4822: }
4823: $lastrndseed{$partid} = $rndseed;
1.596 raeburn 4824: }
4825: my $responseType=($isTask ? 'Task'
1.335 albertel 4826: : $responseType->{$partid}->{$responseId});
1.596 raeburn 4827: if (!exists($orders{$partid})) { $orders{$partid}={}; }
1.640 raeburn 4828: if ((!exists($orders{$partid}->{$responseId})) || ($trial)) {
1.596 raeburn 4829: $orders{$partid}->{$responseId}=
4830: &get_order($partid,$responseId,$symb,$uname,$udom,
1.640 raeburn 4831: $no_increment,$type,$trial,$rndseed);
1.596 raeburn 4832: }
1.640 raeburn 4833: $displaySub[0].='</b>'.$newvariation.'</span>'; # /nobreak
1.596 raeburn 4834: $displaySub[0].=' '.
1.640 raeburn 4835: &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:",$uname,$udom,$type,$trial,$rndseed).'<br />';
1.596 raeburn 4836: }
1.147 albertel 4837: }
4838: }
1.335 albertel 4839: if (exists($$record{"$where.$partid.checkedin"})) {
1.485 albertel 4840: $displaySub[1].=&mt('Checked in by [_1] into slot [_2]',
4841: $$record{"$where.$partid.checkedin"},
4842: $$record{"$where.$partid.checkedin.slot"}).
4843: '<br />';
1.335 albertel 4844: }
4845: if (exists $$record{"$where.$partid.award"}) {
1.485 albertel 4846: $displaySub[1].='<b>'.&mt('Part:').'</b> '.$display_part.' '.
1.335 albertel 4847: lc($$record{"$where.$partid.award"}).' '.
4848: $mark{$$record{"$where.$partid.solved"}}.
1.147 albertel 4849: '<br />';
4850: }
1.335 albertel 4851: if (exists $$record{"$where.$partid.regrader"}) {
4852: $displaySub[2].=$$record{"$where.$partid.regrader"}.
4853: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
4854: } elsif ($$record{"$version:resource.$partid.regrader"} =~ /\S/) {
4855: $displaySub[2].=
4856: $$record{"$version:resource.$partid.regrader"}.
1.207 albertel 4857: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
1.147 albertel 4858: }
4859: }
4860: # needed because old essay regrader has not parts info
4861: if (exists $$record{"$version:resource.regrader"}) {
4862: $displaySub[2].=$$record{"$version:resource.regrader"};
4863: }
4864: $studentTable.='<td>'.$displaySub[0].' </td><td>'.$displaySub[1];
4865: if ($displaySub[2]) {
1.467 albertel 4866: $studentTable.=&mt('Manually graded by [_1]',$displaySub[2]);
1.147 albertel 4867: }
1.467 albertel 4868: $studentTable.=' </td>'.
4869: &Apache::loncommon::end_data_table_row();
1.119 ng 4870: }
1.467 albertel 4871: $studentTable.=&Apache::loncommon::end_data_table();
1.119 ng 4872: return $studentTable;
1.71 ng 4873: }
4874:
4875: sub updateGradeByPage {
1.608 www 4876: my ($request,$symb) = @_;
1.71 ng 4877:
1.257 albertel 4878: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4879: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4880: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
4881: my $pageTitle = $env{'form.page'};
1.103 albertel 4882: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 4883: my ($uname,$udom) = split(/:/,$env{'form.student'});
4884: my $usec=$classlist->{$env{'form.student'}}[5];
1.103 albertel 4885: if (!&canmodify($usec)) {
1.526 raeburn 4886: $request->print('<span class="LC_warning">'.&mt('Unable to modify requested student ([_1])',$env{'form.student'}).'</span>');
1.103 albertel 4887: return;
4888: }
1.398 albertel 4889: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.526 raeburn 4890: $result.='<h3> '.&mt('Student: ').&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
1.129 ng 4891: '</h3>'."\n";
1.70 ng 4892:
1.68 ng 4893: $request->print($result);
4894:
1.582 raeburn 4895:
1.132 bowersj2 4896: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 4897: unless (ref($navmap)) {
4898: $request->print(&navmap_errormsg());
4899: return;
4900: }
1.257 albertel 4901: my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $env{'form.page'});
1.71 ng 4902: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 4903: if (!$map) {
1.527 raeburn 4904: $request->print('<span class="LC_warning">'.&mt('Unable to grade requested sequence ([_1]).',$resUrl).'</span>');
1.288 albertel 4905: return;
4906: }
1.71 ng 4907: my $iterator = $navmap->getIterator($map->map_start(),
4908: $map->map_finish());
1.70 ng 4909:
1.484 albertel 4910: my $studentTable=
4911: &Apache::loncommon::start_data_table().
4912: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 4913: '<th align="center"> '.&mt('Prob.').' </th>'.
4914: '<th> '.&mt('Title').' </th>'.
4915: '<th> '.&mt('Previous Score').' </th>'.
4916: '<th> '.&mt('New Score').' </th>'.
1.484 albertel 4917: &Apache::loncommon::end_data_table_header_row();
1.71 ng 4918:
4919: $iterator->next(); # skip the first BEGIN_MAP
4920: my $curRes = $iterator->next(); # for "current resource"
1.196 albertel 4921: my ($depth,$question,$prob,$changeflag)= (1,1,1,0);
1.101 albertel 4922: while ($depth > 0) {
1.71 ng 4923: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4924: if($curRes == $iterator->END_MAP) { $depth--; }
1.71 ng 4925:
1.385 albertel 4926: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4927: my $parts = $curRes->parts();
1.71 ng 4928: my $title = $curRes->compTitle();
4929: my $symbx = $curRes->symb();
1.484 albertel 4930: $studentTable.=
4931: &Apache::loncommon::start_data_table_row().
4932: '<td align="center" valign="top" >'.$prob.
1.485 albertel 4933: (scalar(@{$parts}) == 1 ? ''
1.640 raeburn 4934: : '<br />('.&mt('[quant,_1,part]',scalar(@{$parts}))
1.526 raeburn 4935: .')').'</td>';
1.71 ng 4936: $studentTable.='<td valign="top"> <b>'.$title.'</b> </td>';
4937:
4938: my %newrecord=();
4939: my @displayPts=();
1.269 raeburn 4940: my %aggregate = ();
4941: my $aggregateflag = 0;
1.71 ng 4942: foreach my $partid (@{$parts}) {
1.257 albertel 4943: my $newpts = $env{'form.GD_BOX'.$question.'_'.$partid};
4944: my $oldpts = $env{'form.oldpts'.$question.'_'.$partid};
1.71 ng 4945:
1.257 albertel 4946: my $wgt = $env{'form.WGT'.$question.'_'.$partid} != 0 ?
4947: $env{'form.WGT'.$question.'_'.$partid} : 1;
1.71 ng 4948: my $partial = $newpts/$wgt;
4949: my $score;
4950: if ($partial > 0) {
4951: $score = 'correct_by_override';
1.125 ng 4952: } elsif ($newpts ne '') { #empty is taken as 0
1.71 ng 4953: $score = 'incorrect_by_override';
4954: }
1.257 albertel 4955: my $dropMenu = $env{'form.GD_SEL'.$question.'_'.$partid};
1.125 ng 4956: if ($dropMenu eq 'excused') {
1.71 ng 4957: $partial = '';
4958: $score = 'excused';
1.125 ng 4959: } elsif ($dropMenu eq 'reset status'
1.257 albertel 4960: && $env{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
1.125 ng 4961: $newrecord{'resource.'.$partid.'.tries'} = 0;
4962: $newrecord{'resource.'.$partid.'.solved'} = '';
4963: $newrecord{'resource.'.$partid.'.award'} = '';
4964: $newrecord{'resource.'.$partid.'.awarded'} = 0;
1.257 albertel 4965: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 4966: $changeflag++;
4967: $newpts = '';
1.269 raeburn 4968:
4969: my $aggtries = $env{'form.aggtries'.$question.'_'.$partid};
4970: my $totaltries = $env{'form.totaltries'.$question.'_'.$partid};
4971: my $solvedstatus = $env{'form.solved'.$question.'_'.$partid};
4972: if ($aggtries > 0) {
4973: &decrement_aggs($symbx,$partid,\%aggregate,$aggtries,$totaltries,$solvedstatus);
4974: $aggregateflag = 1;
4975: }
1.71 ng 4976: }
1.324 albertel 4977: my $display_part=&get_display_part($partid,$curRes->symb());
1.257 albertel 4978: my $oldstatus = $env{'form.solved'.$question.'_'.$partid};
1.526 raeburn 4979: $displayPts[0].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.71 ng 4980: (($oldstatus eq 'excused') ? 'excused' : $oldpts).
1.326 albertel 4981: ' <br />';
1.526 raeburn 4982: $displayPts[1].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.125 ng 4983: (($score eq 'excused') ? 'excused' : $newpts).
1.326 albertel 4984: ' <br />';
1.71 ng 4985: $question++;
1.380 albertel 4986: next if ($dropMenu eq 'reset status' || ($newpts eq $oldpts && $score ne 'excused'));
1.125 ng 4987:
1.71 ng 4988: $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
1.125 ng 4989: $newrecord{'resource.'.$partid.'.solved'} = $score if $score ne '';
1.257 albertel 4990: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}"
1.125 ng 4991: if (scalar(keys(%newrecord)) > 0);
1.71 ng 4992:
4993: $changeflag++;
4994: }
4995: if (scalar(keys(%newrecord)) > 0) {
1.382 albertel 4996: my %record =
4997: &Apache::lonnet::restore($symbx,$env{'request.course.id'},
4998: $udom,$uname);
4999:
5000: if (&Apache::lonnet::validCODE($env{'form.CODE'})) {
5001: $newrecord{'resource.CODE'} = $env{'form.CODE'};
5002: } elsif (&Apache::lonnet::validCODE($record{'resource.CODE'})) {
5003: $newrecord{'resource.CODE'} = '';
5004: }
1.257 albertel 5005: &Apache::lonnet::cstore(\%newrecord,$symbx,$env{'request.course.id'},
1.71 ng 5006: $udom,$uname);
1.382 albertel 5007: %record = &Apache::lonnet::restore($symbx,
5008: $env{'request.course.id'},
5009: $udom,$uname);
1.380 albertel 5010: &check_and_remove_from_queue($parts,\%record,undef,$symbx,
5011: $cdom,$cnum,$udom,$uname);
1.71 ng 5012: }
1.380 albertel 5013:
1.269 raeburn 5014: if ($aggregateflag) {
5015: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
5016: $env{'course.'.$env{'request.course.id'}.'.domain'},
5017: $env{'course.'.$env{'request.course.id'}.'.num'});
5018: }
1.125 ng 5019:
1.71 ng 5020: $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
5021: '<td valign="top">'.$displayPts[1].'</td>'.
1.484 albertel 5022: &Apache::loncommon::end_data_table_row();
1.68 ng 5023:
1.196 albertel 5024: $prob++;
1.68 ng 5025: }
1.71 ng 5026: $curRes = $iterator->next();
1.68 ng 5027: }
1.98 albertel 5028:
1.484 albertel 5029: $studentTable.=&Apache::loncommon::end_data_table();
1.526 raeburn 5030: my $grademsg=($changeflag == 0 ? &mt('No score was changed or updated.') :
5031: &mt('The scores were changed for [quant,_1,problem].',
5032: $changeflag));
1.76 ng 5033: $request->print($grademsg.$studentTable);
1.68 ng 5034:
1.70 ng 5035: return '';
5036: }
5037:
1.72 ng 5038: #-------- end of section for handling grading by page/sequence ---------
5039: #
5040: #-------------------------------------------------------------------
5041:
1.581 www 5042: #-------------------- Bubblesheet (Scantron) Grading -------------------
1.75 albertel 5043: #
5044: #------ start of section for handling grading by page/sequence ---------
5045:
1.423 albertel 5046: =pod
5047:
5048: =head1 Bubble sheet grading routines
5049:
1.424 albertel 5050: For this documentation:
5051:
5052: 'scanline' refers to the full line of characters
5053: from the file that we are parsing that represents one entire sheet
5054:
5055: 'bubble line' refers to the data
1.659 raeburn 5056: representing the line of bubbles that are on the physical bubblesheet
1.424 albertel 5057:
5058:
1.659 raeburn 5059: The overall process is that a scanned in bubblesheet data is uploaded
1.424 albertel 5060: into a course. When a user wants to grade, they select a
1.659 raeburn 5061: sequence/folder of resources, a file of bubblesheet info, and pick
1.424 albertel 5062: one of the predefined configurations for what each scanline looks
5063: like.
5064:
5065: Next each scanline is checked for any errors of either 'missing
1.435 foxr 5066: bubbles' (it's an error because it may have been mis-scanned
1.424 albertel 5067: because too light bubbling), 'double bubble' (each bubble line should
5068: have no more that one letter picked), invalid or duplicated CODE,
1.556 weissno 5069: invalid student/employee ID
1.424 albertel 5070:
5071: If the CODE option is used that determines the randomization of the
1.556 weissno 5072: homework problems, either way the student/employee ID is looked up into a
1.424 albertel 5073: username:domain.
5074:
5075: During the validation phase the instructor can choose to skip scanlines.
5076:
1.659 raeburn 5077: After the validation phase, there are now 3 bubblesheet files
1.424 albertel 5078:
5079: scantron_original_filename (unmodified original file)
5080: scantron_corrected_filename (file where the corrected information has replaced the original information)
5081: scantron_skipped_filename (contains the exact text of scanlines that where skipped)
5082:
5083: Also there is a separate hash nohist_scantrondata that contains extra
1.659 raeburn 5084: correction information that isn't representable in the bubblesheet
1.424 albertel 5085: file (see &scantron_getfile() for more information)
5086:
5087: After all scanlines are either valid, marked as valid or skipped, then
5088: foreach line foreach problem in the picked sequence, an ssi request is
5089: made that simulates a user submitting their selected letter(s) against
5090: the homework problem.
1.423 albertel 5091:
5092: =over 4
5093:
5094:
5095:
5096: =item defaultFormData
5097:
5098: Returns html hidden inputs used to hold context/default values.
5099:
5100: Arguments:
5101: $symb - $symb of the current resource
5102:
5103: =cut
1.422 foxr 5104:
1.81 albertel 5105: sub defaultFormData {
1.324 albertel 5106: my ($symb)=@_;
1.613 www 5107: return '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />';
1.81 albertel 5108: }
5109:
1.447 foxr 5110:
1.423 albertel 5111: =pod
5112:
5113: =item getSequenceDropDown
5114:
5115: Return html dropdown of possible sequences to grade
5116:
5117: Arguments:
1.582 raeburn 5118: $symb - $symb of the current resource
5119: $map_error - ref to scalar which will container error if
5120: $navmap object is unavailable in &getSymbMap().
1.423 albertel 5121:
5122: =cut
1.422 foxr 5123:
1.75 albertel 5124: sub getSequenceDropDown {
1.582 raeburn 5125: my ($symb,$map_error)=@_;
1.75 albertel 5126: my $result='<select name="selectpage">'."\n";
1.582 raeburn 5127: my ($titles,$symbx) = &getSymbMap($map_error);
5128: if (ref($map_error)) {
5129: return if ($$map_error);
5130: }
1.137 albertel 5131: my ($curpage)=&Apache::lonnet::decode_symb($symb);
1.75 albertel 5132: my $ctr=0;
5133: foreach (@$titles) {
5134: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
5135: $result.='<option value="'.$$symbx{$_}.'" '.
1.401 albertel 5136: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.75 albertel 5137: '>'.$showtitle.'</option>'."\n";
5138: $ctr++;
5139: }
5140: $result.= '</select>';
5141: return $result;
5142: }
5143:
1.495 albertel 5144: my %bubble_lines_per_response; # no. bubble lines for each response.
1.554 raeburn 5145: # key is zero-based index - 0, 1, 2 ...
1.495 albertel 5146:
5147: my %first_bubble_line; # First bubble line no. for each bubble.
5148:
1.509 raeburn 5149: my %subdivided_bubble_lines; # no. bubble lines for optionresponse,
5150: # matchresponse or rankresponse, where
5151: # an individual response can have multiple
5152: # lines
1.503 raeburn 5153:
5154: my %responsetype_per_response; # responsetype for each response
5155:
1.691 raeburn 5156: my %masterseq_id_responsenum; # src_id (e.g., 12.3_0.11 etc.) for each
5157: # numbered response. Needed when randomorder
5158: # or randompick are in use. Key is ID, value
5159: # is response number.
5160:
1.495 albertel 5161: # Save and restore the bubble lines array to the form env.
5162:
5163:
5164: sub save_bubble_lines {
5165: foreach my $line (keys(%bubble_lines_per_response)) {
5166: $env{"form.scantron.bubblelines.$line"} = $bubble_lines_per_response{$line};
5167: $env{"form.scantron.first_bubble_line.$line"} =
5168: $first_bubble_line{$line};
1.503 raeburn 5169: $env{"form.scantron.sub_bubblelines.$line"} =
5170: $subdivided_bubble_lines{$line};
5171: $env{"form.scantron.responsetype.$line"} =
5172: $responsetype_per_response{$line};
1.495 albertel 5173: }
1.691 raeburn 5174: foreach my $resid (keys(%masterseq_id_responsenum)) {
5175: my $line = $masterseq_id_responsenum{$resid};
5176: $env{"form.scantron.residpart.$line"} = $resid;
5177: }
1.495 albertel 5178: }
5179:
5180:
5181: sub restore_bubble_lines {
5182: my $line = 0;
5183: %bubble_lines_per_response = ();
1.691 raeburn 5184: %masterseq_id_responsenum = ();
1.495 albertel 5185: while ($env{"form.scantron.bubblelines.$line"}) {
5186: my $value = $env{"form.scantron.bubblelines.$line"};
5187: $bubble_lines_per_response{$line} = $value;
5188: $first_bubble_line{$line} =
5189: $env{"form.scantron.first_bubble_line.$line"};
1.503 raeburn 5190: $subdivided_bubble_lines{$line} =
5191: $env{"form.scantron.sub_bubblelines.$line"};
5192: $responsetype_per_response{$line} =
5193: $env{"form.scantron.responsetype.$line"};
1.691 raeburn 5194: my $id = $env{"form.scantron.residpart.$line"};
5195: $masterseq_id_responsenum{$id} = $line;
1.495 albertel 5196: $line++;
5197: }
5198: }
5199:
1.423 albertel 5200: =pod
5201:
5202: =item scantron_filenames
5203:
5204: Returns a list of the scantron files in the current course
5205:
5206: =cut
1.422 foxr 5207:
1.202 albertel 5208: sub scantron_filenames {
1.257 albertel 5209: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5210: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
1.517 raeburn 5211: my $getpropath = 1;
1.662 raeburn 5212: my ($dirlist,$listerror) = &Apache::lonnet::dirlist('userfiles',$cdom,
5213: $cname,$getpropath);
1.202 albertel 5214: my @possiblenames;
1.662 raeburn 5215: if (ref($dirlist) eq 'ARRAY') {
5216: foreach my $filename (sort(@{$dirlist})) {
5217: ($filename)=split(/&/,$filename);
5218: if ($filename!~/^scantron_orig_/) { next ; }
5219: $filename=~s/^scantron_orig_//;
5220: push(@possiblenames,$filename);
5221: }
1.202 albertel 5222: }
5223: return @possiblenames;
5224: }
5225:
1.423 albertel 5226: =pod
5227:
5228: =item scantron_uploads
5229:
5230: Returns html drop-down list of scantron files in current course.
5231:
5232: Arguments:
5233: $file2grade - filename to set as selected in the dropdown
5234:
5235: =cut
1.422 foxr 5236:
1.202 albertel 5237: sub scantron_uploads {
1.209 ng 5238: my ($file2grade) = @_;
1.202 albertel 5239: my $result= '<select name="scantron_selectfile">';
5240: $result.="<option></option>";
5241: foreach my $filename (sort(&scantron_filenames())) {
1.401 albertel 5242: $result.="<option".($filename eq $file2grade ? ' selected="selected"':'').">$filename</option>\n";
1.81 albertel 5243: }
5244: $result.="</select>";
5245: return $result;
5246: }
5247:
1.423 albertel 5248: =pod
5249:
5250: =item scantron_scantab
5251:
5252: Returns html drop down of the scantron formats in the scantronformat.tab
5253: file.
5254:
5255: =cut
1.422 foxr 5256:
1.82 albertel 5257: sub scantron_scantab {
5258: my $result='<select name="scantron_format">'."\n";
1.191 albertel 5259: $result.='<option></option>'."\n";
1.518 raeburn 5260: my @lines = &get_scantronformat_file();
5261: if (@lines > 0) {
5262: foreach my $line (@lines) {
5263: next if (($line =~ /^\#/) || ($line eq ''));
5264: my ($name,$descrip)=split(/:/,$line);
5265: $result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
5266: }
1.82 albertel 5267: }
5268: $result.='</select>'."\n";
1.518 raeburn 5269: return $result;
5270: }
5271:
5272: =pod
5273:
5274: =item get_scantronformat_file
5275:
5276: Returns an array containing lines from the scantron format file for
5277: the domain of the course.
5278:
5279: If a url for a custom.tab file is listed in domain's configuration.db,
5280: lines are from this file.
5281:
5282: Otherwise, if a default.tab has been published in RES space by the
5283: domainconfig user, lines are from this file.
5284:
5285: Otherwise, fall back to getting lines from the legacy file on the
1.519 raeburn 5286: local server: /home/httpd/lonTabs/default_scantronformat.tab
1.82 albertel 5287:
1.518 raeburn 5288: =cut
5289:
5290: sub get_scantronformat_file {
5291: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
5292: my %domconfig = &Apache::lonnet::get_dom('configuration',['scantron'],$cdom);
5293: my $gottab = 0;
5294: my @lines;
5295: if (ref($domconfig{'scantron'}) eq 'HASH') {
5296: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
5297: my $formatfile = &Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.$domconfig{'scantron'}{'scantronformat'});
5298: if ($formatfile ne '-1') {
5299: @lines = split("\n",$formatfile,-1);
5300: $gottab = 1;
5301: }
5302: }
5303: }
5304: if (!$gottab) {
5305: my $confname = $cdom.'-domainconfig';
5306: my $default = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res/'.$cdom.'/'.$confname.'/default.tab';
5307: my $formatfile = &Apache::lonnet::getfile($default);
5308: if ($formatfile ne '-1') {
5309: @lines = split("\n",$formatfile,-1);
5310: $gottab = 1;
5311: }
5312: }
5313: if (!$gottab) {
1.519 raeburn 5314: my @domains = &Apache::lonnet::current_machine_domains();
5315: if (grep(/^\Q$cdom\E$/,@domains)) {
5316: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
5317: @lines = <$fh>;
5318: close($fh);
5319: } else {
5320: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab');
5321: @lines = <$fh>;
5322: close($fh);
5323: }
1.518 raeburn 5324: }
5325: return @lines;
1.82 albertel 5326: }
5327:
1.423 albertel 5328: =pod
5329:
5330: =item scantron_CODElist
5331:
5332: Returns html drop down of the saved CODE lists from current course,
5333: generated from earlier printings.
5334:
5335: =cut
1.422 foxr 5336:
1.186 albertel 5337: sub scantron_CODElist {
1.257 albertel 5338: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5339: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.186 albertel 5340: my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
5341: my $namechoice='<option></option>';
1.225 albertel 5342: foreach my $name (sort {uc($a) cmp uc($b)} @names) {
1.191 albertel 5343: if ($name =~ /^error: 2 /) { next; }
1.278 albertel 5344: if ($name =~ /^type\0/) { next; }
1.186 albertel 5345: $namechoice.='<option value="'.$name.'">'.$name.'</option>';
5346: }
5347: $namechoice='<select name="scantron_CODElist">'.$namechoice.'</select>';
5348: return $namechoice;
5349: }
5350:
1.423 albertel 5351: =pod
5352:
5353: =item scantron_CODEunique
5354:
5355: Returns the html for "Each CODE to be used once" radio.
5356:
5357: =cut
1.422 foxr 5358:
1.186 albertel 5359: sub scantron_CODEunique {
1.532 bisitz 5360: my $result='<span class="LC_nobreak">
1.272 albertel 5361: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 5362: value="yes" checked="checked" />'.&mt('Yes').' </label>
1.381 albertel 5363: </span>
1.532 bisitz 5364: <span class="LC_nobreak">
1.272 albertel 5365: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 5366: value="no" />'.&mt('No').' </label>
1.381 albertel 5367: </span>';
1.186 albertel 5368: return $result;
5369: }
1.423 albertel 5370:
5371: =pod
5372:
5373: =item scantron_selectphase
5374:
1.659 raeburn 5375: Generates the initial screen to start the bubblesheet process.
1.423 albertel 5376: Allows for - starting a grading run.
1.424 albertel 5377: - downloading existing scan data (original, corrected
1.423 albertel 5378: or skipped info)
5379:
5380: - uploading new scan data
5381:
5382: Arguments:
5383: $r - The Apache request object
5384: $file2grade - name of the file that contain the scanned data to score
5385:
5386: =cut
1.186 albertel 5387:
1.75 albertel 5388: sub scantron_selectphase {
1.608 www 5389: my ($r,$file2grade,$symb) = @_;
1.75 albertel 5390: if (!$symb) {return '';}
1.582 raeburn 5391: my $map_error;
5392: my $sequence_selector=&getSequenceDropDown($symb,\$map_error);
5393: if ($map_error) {
5394: $r->print('<br />'.&navmap_errormsg().'<br />');
5395: return;
5396: }
1.324 albertel 5397: my $default_form_data=&defaultFormData($symb);
1.209 ng 5398: my $file_selector=&scantron_uploads($file2grade);
1.82 albertel 5399: my $format_selector=&scantron_scantab();
1.186 albertel 5400: my $CODE_selector=&scantron_CODElist();
5401: my $CODE_unique=&scantron_CODEunique();
1.75 albertel 5402: my $result;
1.422 foxr 5403:
1.513 foxr 5404: $ssi_error = 0;
5405:
1.606 wenzelju 5406: if (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) ||
5407: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
5408:
5409: # Chunk of form to prompt for a scantron file upload.
5410:
5411: $r->print('
5412: <br />
5413: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5414: '.&Apache::loncommon::start_data_table_header_row().'
5415: <th>
5416: '.&mt('Specify a bubblesheet data file to upload.').'
5417: </th>
5418: '.&Apache::loncommon::end_data_table_header_row().'
5419: '.&Apache::loncommon::start_data_table_row().'
5420: <td>
5421: ');
1.608 www 5422: my $default_form_data=&defaultFormData($symb);
1.606 wenzelju 5423: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
5424: my $cnum= $env{'course.'.$env{'request.course.id'}.'.num'};
5425: $r->print(&Apache::lonhtmlcommon::scripttag('
5426: function checkUpload(formname) {
5427: if (formname.upfile.value == "") {
5428: alert("'.&mt('Please use the browse button to select a file from your local directory.').'");
5429: return false;
5430: }
5431: formname.submit();
5432: }'));
5433: $r->print('
5434: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
5435: '.$default_form_data.'
5436: <input name="courseid" type="hidden" value="'.$cnum.'" />
5437: <input name="domainid" type="hidden" value="'.$cdom.'" />
5438: <input name="command" value="scantronupload_save" type="hidden" />
5439: '.&mt('File to upload: [_1]','<input type="file" name="upfile" size="50" />').'
5440: <br />
5441: <input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
5442: </form>
5443: ');
5444:
5445: $r->print('
5446: </td>
5447: '.&Apache::loncommon::end_data_table_row().'
5448: '.&Apache::loncommon::end_data_table().'
5449: ');
5450: }
5451:
1.422 foxr 5452: # Chunk of form to prompt for a file to grade and how:
5453:
1.489 albertel 5454: $result.= '
5455: <br />
5456: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantron_process">
5457: <input type="hidden" name="command" value="scantron_warning" />
5458: '.$default_form_data.'
5459: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5460: '.&Apache::loncommon::start_data_table_header_row().'
5461: <th colspan="2">
1.492 albertel 5462: '.&mt('Specify file and which Folder/Sequence to grade').'
1.489 albertel 5463: </th>
5464: '.&Apache::loncommon::end_data_table_header_row().'
5465: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5466: <td> '.&mt('Sequence to grade:').' </td><td> '.$sequence_selector.' </td>
1.489 albertel 5467: '.&Apache::loncommon::end_data_table_row().'
5468: '.&Apache::loncommon::start_data_table_row().'
1.572 www 5469: <td> '.&mt('Filename of bubblesheet data file:').' </td><td> '.$file_selector.' </td>
1.489 albertel 5470: '.&Apache::loncommon::end_data_table_row().'
5471: '.&Apache::loncommon::start_data_table_row().'
1.572 www 5472: <td> '.&mt('Format of bubblesheet data file:').' </td><td> '.$format_selector.' </td>
1.489 albertel 5473: '.&Apache::loncommon::end_data_table_row().'
5474: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5475: <td> '.&mt('Saved CODEs to validate against:').' </td><td> '.$CODE_selector.' </td>
1.489 albertel 5476: '.&Apache::loncommon::end_data_table_row().'
5477: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5478: <td> '.&mt('Each CODE is only to be used once:').'</td><td> '.$CODE_unique.' </td>
1.489 albertel 5479: '.&Apache::loncommon::end_data_table_row().'
5480: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5481: <td> '.&mt('Options:').' </td>
1.187 albertel 5482: <td>
1.492 albertel 5483: <label><input type="checkbox" name="scantron_options_redo" value="redo_skipped"/> '.&mt('Do only previously skipped records').'</label> <br />
5484: <label><input type="checkbox" name="scantron_options_ignore" value="ignore_corrections"/> '.&mt('Remove all existing corrections').'</label> <br />
5485: <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources when grading').'</label>
1.187 albertel 5486: </td>
1.489 albertel 5487: '.&Apache::loncommon::end_data_table_row().'
5488: '.&Apache::loncommon::start_data_table_row().'
1.174 albertel 5489: <td colspan="2">
1.572 www 5490: <input type="submit" value="'.&mt('Grading: Validate Bubblesheet Records').'" />
1.162 albertel 5491: </td>
1.489 albertel 5492: '.&Apache::loncommon::end_data_table_row().'
5493: '.&Apache::loncommon::end_data_table().'
5494: </form>
5495: ';
1.162 albertel 5496:
5497: $r->print($result);
5498:
1.422 foxr 5499:
5500:
5501: # Chunk of the form that prompts to view a scoring office file,
5502: # corrected file, skipped records in a file.
5503:
1.489 albertel 5504: $r->print('
5505: <br />
5506: <form action="/adm/grades" name="scantron_download">
5507: '.$default_form_data.'
5508: <input type="hidden" name="command" value="scantron_download" />
5509: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5510: '.&Apache::loncommon::start_data_table_header_row().'
5511: <th>
1.492 albertel 5512: '.&mt('Download a scoring office file').'
1.489 albertel 5513: </th>
5514: '.&Apache::loncommon::end_data_table_header_row().'
5515: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5516: <td> '.&mt('Filename of scoring office file: [_1]',$file_selector).'
1.489 albertel 5517: <br />
1.492 albertel 5518: <input type="submit" value="'.&mt('Download: Show List of Associated Files').'" />
1.489 albertel 5519: '.&Apache::loncommon::end_data_table_row().'
5520: '.&Apache::loncommon::end_data_table().'
5521: </form>
5522: <br />
5523: ');
1.162 albertel 5524:
1.457 banghart 5525: &Apache::lonpickcode::code_list($r,2);
1.523 raeburn 5526:
1.694 bisitz 5527: $r->print('<br /><form method="post" name="checkscantron" action="">'.
1.523 raeburn 5528: $default_form_data."\n".
5529: &Apache::loncommon::start_data_table('LC_scantron_action')."\n".
5530: &Apache::loncommon::start_data_table_header_row()."\n".
5531: '<th colspan="2">
1.572 www 5532: '.&mt('Review bubblesheet data and submissions for a previously graded folder/sequence')."\n".
1.523 raeburn 5533: '</th>'."\n".
5534: &Apache::loncommon::end_data_table_header_row()."\n".
5535: &Apache::loncommon::start_data_table_row()."\n".
5536: '<td> '.&mt('Graded folder/sequence:').' </td>'."\n".
5537: '<td> '.$sequence_selector.' </td>'.
5538: &Apache::loncommon::end_data_table_row()."\n".
5539: &Apache::loncommon::start_data_table_row()."\n".
5540: '<td> '.&mt('Filename of scoring office file:').' </td>'."\n".
5541: '<td> '.$file_selector.' </td>'."\n".
5542: &Apache::loncommon::end_data_table_row()."\n".
5543: &Apache::loncommon::start_data_table_row()."\n".
5544: '<td> '.&mt('Format of data file:').' </td>'."\n".
5545: '<td> '.$format_selector.' </td>'."\n".
5546: &Apache::loncommon::end_data_table_row()."\n".
5547: &Apache::loncommon::start_data_table_row()."\n".
1.557 raeburn 5548: '<td> '.&mt('Options').' </td>'."\n".
5549: '<td> <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources').'</label></td>'.
5550: &Apache::loncommon::end_data_table_row()."\n".
5551: &Apache::loncommon::start_data_table_row()."\n".
1.523 raeburn 5552: '<td colspan="2">'."\n".
5553: '<input type="hidden" name="command" value="checksubmissions" />'."\n".
1.575 www 5554: '<input type="submit" value="'.&mt('Review Bubblesheet Data and Submission Records').'" />'."\n".
1.523 raeburn 5555: '</td>'."\n".
5556: &Apache::loncommon::end_data_table_row()."\n".
5557: &Apache::loncommon::end_data_table()."\n".
5558: '</form><br />');
5559: return;
1.75 albertel 5560: }
5561:
1.423 albertel 5562: =pod
5563:
5564: =item get_scantron_config
5565:
5566: Parse and return the scantron configuration line selected as a
5567: hash of configuration file fields.
5568:
5569: Arguments:
5570: which - the name of the configuration to parse from the file.
5571:
5572:
5573: Returns:
5574: If the named configuration is not in the file, an empty
5575: hash is returned.
5576: a hash with the fields
5577: name - internal name for the this configuration setup
5578: description - text to display to operator that describes this config
5579: CODElocation - if 0 or the string 'none'
5580: - no CODE exists for this config
5581: if -1 || the string 'letter'
5582: - a CODE exists for this config and is
5583: a string of letters
5584: Unsupported value (but planned for future support)
5585: if a positive integer
5586: - The CODE exists as the first n items from
5587: the question section of the form
5588: if the string 'number'
5589: - The CODE exists for this config and is
5590: a string of numbers
5591: CODEstart - (only matter if a CODE exists) column in the line where
5592: the CODE starts
5593: CODElength - length of the CODE
1.573 bisitz 5594: IDstart - column where the student/employee ID starts
1.556 weissno 5595: IDlength - length of the student/employee ID info
1.423 albertel 5596: Qstart - column where the information from the bubbled
5597: 'questions' start
5598: Qlength - number of columns comprising a single bubble line from
5599: the sheet. (usually either 1 or 10)
1.424 albertel 5600: Qon - either a single character representing the character used
1.423 albertel 5601: to signal a bubble was chosen in the positional setup, or
5602: the string 'letter' if the letter of the chosen bubble is
5603: in the final, or 'number' if a number representing the
5604: chosen bubble is in the file (1->A 0->J)
1.424 albertel 5605: Qoff - the character used to represent that a bubble was
5606: left blank
1.423 albertel 5607: PaperID - if the scanning process generates a unique number for each
5608: sheet scanned the column that this ID number starts in
5609: PaperIDlength - number of columns that comprise the unique ID number
5610: for the sheet of paper
1.424 albertel 5611: FirstName - column that the first name starts in
1.423 albertel 5612: FirstNameLength - number of columns that the first name spans
5613:
5614: LastName - column that the last name starts in
5615: LastNameLength - number of columns that the last name spans
1.649 raeburn 5616: BubblesPerRow - number of bubbles available in each row used to
5617: bubble an answer. (If not specified, 10 assumed).
1.671 raeburn 5618:
1.423 albertel 5619: =cut
1.422 foxr 5620:
1.82 albertel 5621: sub get_scantron_config {
5622: my ($which) = @_;
1.518 raeburn 5623: my @lines = &get_scantronformat_file();
1.82 albertel 5624: my %config;
1.157 albertel 5625: #FIXME probably should move to XML it has already gotten a bit much now
1.518 raeburn 5626: foreach my $line (@lines) {
1.82 albertel 5627: my ($name,$descrip)=split(/:/,$line);
5628: if ($name ne $which ) { next; }
5629: chomp($line);
5630: my @config=split(/:/,$line);
5631: $config{'name'}=$config[0];
5632: $config{'description'}=$config[1];
5633: $config{'CODElocation'}=$config[2];
5634: $config{'CODEstart'}=$config[3];
5635: $config{'CODElength'}=$config[4];
5636: $config{'IDstart'}=$config[5];
5637: $config{'IDlength'}=$config[6];
5638: $config{'Qstart'}=$config[7];
1.497 foxr 5639: $config{'Qlength'}=$config[8];
1.82 albertel 5640: $config{'Qoff'}=$config[9];
5641: $config{'Qon'}=$config[10];
1.157 albertel 5642: $config{'PaperID'}=$config[11];
5643: $config{'PaperIDlength'}=$config[12];
5644: $config{'FirstName'}=$config[13];
5645: $config{'FirstNamelength'}=$config[14];
5646: $config{'LastName'}=$config[15];
5647: $config{'LastNamelength'}=$config[16];
1.649 raeburn 5648: $config{'BubblesPerRow'}=$config[17];
1.82 albertel 5649: last;
5650: }
5651: return %config;
5652: }
5653:
1.423 albertel 5654: =pod
5655:
5656: =item username_to_idmap
5657:
1.556 weissno 5658: creates a hash keyed by student/employee ID with values of the corresponding
1.423 albertel 5659: student username:domain.
5660:
5661: Arguments:
5662:
5663: $classlist - reference to the class list hash. This is a hash
5664: keyed by student name:domain whose elements are references
1.424 albertel 5665: to arrays containing various chunks of information
1.423 albertel 5666: about the student. (See loncoursedata for more info).
5667:
5668: Returns
5669: %idmap - the constructed hash
5670:
5671: =cut
5672:
1.82 albertel 5673: sub username_to_idmap {
5674: my ($classlist)= @_;
5675: my %idmap;
5676: foreach my $student (keys(%$classlist)) {
5677: $idmap{$classlist->{$student}->[&Apache::loncoursedata::CL_ID]}=
5678: $student;
5679: }
5680: return %idmap;
5681: }
1.423 albertel 5682:
5683: =pod
5684:
1.424 albertel 5685: =item scantron_fixup_scanline
1.423 albertel 5686:
5687: Process a requested correction to a scanline.
5688:
5689: Arguments:
5690: $scantron_config - hash from &get_scantron_config()
5691: $scan_data - hash of correction information
5692: (see &scantron_getfile())
5693: $line - existing scanline
5694: $whichline - line number of the passed in scanline
5695: $field - type of change to process
5696: (either
1.573 bisitz 5697: 'ID' -> correct the student/employee ID
1.423 albertel 5698: 'CODE' -> correct the CODE
5699: 'answer' -> fixup the submitted answers)
5700:
5701: $args - hash of additional info,
5702: - 'ID'
5703: 'newid' -> studentID to use in replacement
1.424 albertel 5704: of existing one
1.423 albertel 5705: - 'CODE'
5706: 'CODE_ignore_dup' - set to true if duplicates
5707: should be ignored.
5708: 'CODE' - is new code or 'use_unfound'
1.424 albertel 5709: if the existing unfound code should
1.423 albertel 5710: be used as is
5711: - 'answer'
5712: 'response' - new answer or 'none' if blank
5713: 'question' - the bubble line to change
1.503 raeburn 5714: 'questionnum' - the question identifier,
5715: may include subquestion.
1.423 albertel 5716:
5717: Returns:
5718: $line - the modified scanline
5719:
5720: Side effects:
5721: $scan_data - may be updated
5722:
5723: =cut
5724:
1.82 albertel 5725:
1.157 albertel 5726: sub scantron_fixup_scanline {
5727: my ($scantron_config,$scan_data,$line,$whichline,$field,$args)=@_;
5728: if ($field eq 'ID') {
5729: if (length($args->{'newid'}) > $$scantron_config{'IDlength'}) {
1.186 albertel 5730: return ($line,1,'New value too large');
1.157 albertel 5731: }
5732: if (length($args->{'newid'}) < $$scantron_config{'IDlength'}) {
5733: $args->{'newid'}=sprintf('%-'.$$scantron_config{'IDlength'}.'s',
5734: $args->{'newid'});
5735: }
5736: substr($line,$$scantron_config{'IDstart'}-1,
5737: $$scantron_config{'IDlength'})=$args->{'newid'};
5738: if ($args->{'newid'}=~/^\s*$/) {
5739: &scan_data($scan_data,"$whichline.user",
5740: $args->{'username'}.':'.$args->{'domain'});
5741: }
1.186 albertel 5742: } elsif ($field eq 'CODE') {
1.192 albertel 5743: if ($args->{'CODE_ignore_dup'}) {
5744: &scan_data($scan_data,"$whichline.CODE_ignore_dup",'1');
5745: }
5746: &scan_data($scan_data,"$whichline.useCODE",'1');
5747: if ($args->{'CODE'} ne 'use_unfound') {
1.191 albertel 5748: if (length($args->{'CODE'}) > $$scantron_config{'CODElength'}) {
5749: return ($line,1,'New CODE value too large');
5750: }
5751: if (length($args->{'CODE'}) < $$scantron_config{'CODElength'}) {
5752: $args->{'CODE'}=sprintf('%-'.$$scantron_config{'CODElength'}.'s',$args->{'CODE'});
5753: }
5754: substr($line,$$scantron_config{'CODEstart'}-1,
5755: $$scantron_config{'CODElength'})=$args->{'CODE'};
1.186 albertel 5756: }
1.157 albertel 5757: } elsif ($field eq 'answer') {
1.497 foxr 5758: my $length=$scantron_config->{'Qlength'};
1.157 albertel 5759: my $off=$scantron_config->{'Qoff'};
5760: my $on=$scantron_config->{'Qon'};
1.497 foxr 5761: my $answer=${off}x$length;
5762: if ($args->{'response'} eq 'none') {
5763: &scan_data($scan_data,
1.503 raeburn 5764: "$whichline.no_bubble.".$args->{'questionnum'},'1');
1.497 foxr 5765: } else {
5766: if ($on eq 'letter') {
5767: my @alphabet=('A'..'Z');
5768: $answer=$alphabet[$args->{'response'}];
5769: } elsif ($on eq 'number') {
5770: $answer=$args->{'response'}+1;
5771: if ($answer == 10) { $answer = '0'; }
1.274 albertel 5772: } else {
1.497 foxr 5773: substr($answer,$args->{'response'},1)=$on;
1.274 albertel 5774: }
1.497 foxr 5775: &scan_data($scan_data,
1.503 raeburn 5776: "$whichline.no_bubble.".$args->{'questionnum'},undef,'1');
1.157 albertel 5777: }
1.497 foxr 5778: my $where=$length*($args->{'question'}-1)+$scantron_config->{'Qstart'};
5779: substr($line,$where-1,$length)=$answer;
1.157 albertel 5780: }
5781: return $line;
5782: }
1.423 albertel 5783:
5784: =pod
5785:
5786: =item scan_data
5787:
5788: Edit or look up an item in the scan_data hash.
5789:
5790: Arguments:
5791: $scan_data - The hash (see scantron_getfile)
5792: $key - shorthand of the key to edit (actual key is
1.424 albertel 5793: scantronfilename_key).
1.423 albertel 5794: $data - New value of the hash entry.
5795: $delete - If true, the entry is removed from the hash.
5796:
5797: Returns:
5798: The new value of the hash table field (undefined if deleted).
5799:
5800: =cut
5801:
5802:
1.157 albertel 5803: sub scan_data {
5804: my ($scan_data,$key,$value,$delete)=@_;
1.257 albertel 5805: my $filename=$env{'form.scantron_selectfile'};
1.157 albertel 5806: if (defined($value)) {
5807: $scan_data->{$filename.'_'.$key} = $value;
5808: }
5809: if ($delete) { delete($scan_data->{$filename.'_'.$key}); }
5810: return $scan_data->{$filename.'_'.$key};
5811: }
1.423 albertel 5812:
1.495 albertel 5813: # ----- These first few routines are general use routines.----
5814:
5815: # Return the number of occurences of a pattern in a string.
5816:
5817: sub occurence_count {
5818: my ($string, $pattern) = @_;
5819:
5820: my @matches = ($string =~ /$pattern/g);
5821:
5822: return scalar(@matches);
5823: }
5824:
5825:
5826: # Take a string known to have digits and convert all the
5827: # digits into letters in the range J,A..I.
5828:
5829: sub digits_to_letters {
5830: my ($input) = @_;
5831:
5832: my @alphabet = ('J', 'A'..'I');
5833:
5834: my @input = split(//, $input);
5835: my $output ='';
5836: for (my $i = 0; $i < scalar(@input); $i++) {
5837: if ($input[$i] =~ /\d/) {
5838: $output .= $alphabet[$input[$i]];
5839: } else {
5840: $output .= $input[$i];
5841: }
5842: }
5843: return $output;
5844: }
5845:
1.423 albertel 5846: =pod
5847:
5848: =item scantron_parse_scanline
5849:
5850: Decodes a scanline from the selected scantron file
5851:
5852: Arguments:
5853: line - The text of the scantron file line to process
5854: whichline - Line number
5855: scantron_config - Hash describing the format of the scantron lines.
5856: scan_data - Hash of extra information about the scanline
5857: (see scantron_getfile for more information)
5858: just_header - True if should not process question answers but only
5859: the stuff to the left of the answers.
1.691 raeburn 5860: randomorder - True if randomorder in use
5861: randompick - True if randompick in use
5862: sequence - Exam folder URL
5863: master_seq - Ref to array containing symbs in exam folder
5864: symb_to_resource - Ref to hash of symbs for resources in exam folder
5865: (corresponding values are resource objects)
5866: partids_by_symb - Ref to hash of symb -> array ref of partIDs
5867: orderedforcode - Ref to hash of arrays. keys are CODEs and values
5868: are refs to an array of resource objects, ordered
5869: according to order used for CODE, when randomorder
5870: and or randompick are in use.
5871: respnumlookup - Ref to hash mapping question numbers in bubble lines
5872: for current line to question number used for same question
5873: in "Master Sequence" (as seen by Course Coordinator).
5874: startline - Ref to hash where key is question number (0 is first)
5875: and value is number of first bubble line for current
5876: student or code-based randompick and/or randomorder.
5877: totalref - Ref of scalar used to score total number of bubble
5878: lines needed for responses in a scan line (used when
5879: randompick in use.
5880:
1.423 albertel 5881: Returns:
5882: Hash containing the result of parsing the scanline
5883:
5884: Keys are all proceeded by the string 'scantron.'
5885:
5886: CODE - the CODE in use for this scanline
5887: useCODE - 1 if the CODE is invalid but it usage has been forced
5888: by the operator
5889: CODE_ignore_dup - 1 if the CODE is a duplicated use when unique
5890: CODEs were selected, but the usage has been
5891: forced by the operator
1.556 weissno 5892: ID - student/employee ID
1.423 albertel 5893: PaperID - if used, the ID number printed on the sheet when the
5894: paper was scanned
5895: FirstName - first name from the sheet
5896: LastName - last name from the sheet
5897:
5898: if just_header was not true these key may also exist
5899:
1.447 foxr 5900: missingerror - a list of bubble ranges that are considered to be answers
5901: to a single question that don't have any bubbles filled in.
5902: Of the form questionnumber:firstbubblenumber:count.
5903: doubleerror - a list of bubble ranges that are considered to be answers
5904: to a single question that have more than one bubble filled in.
5905: Of the form questionnumber::firstbubblenumber:count
5906:
5907: In the above, count is the number of bubble responses in the
5908: input line needed to represent the possible answers to the question.
5909: e.g. a radioresponse with 15 choices in an answer sheet with 10 choices
5910: per line would have count = 2.
5911:
1.423 albertel 5912: maxquest - the number of the last bubble line that was parsed
5913:
5914: (<number> starts at 1)
5915: <number>.answer - zero or more letters representing the selected
5916: letters from the scanline for the bubble line
5917: <number>.
5918: if blank there was either no bubble or there where
5919: multiple bubbles, (consult the keys missingerror and
5920: doubleerror if this is an error condition)
5921:
5922: =cut
5923:
1.82 albertel 5924: sub scantron_parse_scanline {
1.691 raeburn 5925: my ($line,$whichline,$scantron_config,$scan_data,$just_header,$idmap,
5926: $randomorder,$randompick,$sequence,$master_seq,$symb_to_resource,
5927: $partids_by_symb,$orderedforcode,$respnumlookup,$startline,$totalref)=@_;
1.470 foxr 5928:
1.82 albertel 5929: my %record;
1.691 raeburn 5930: my $data=substr($line,0,$$scantron_config{'Qstart'}-1); # stuff before answers
1.278 albertel 5931: if (!($$scantron_config{'CODElocation'} eq 0 ||
5932: $$scantron_config{'CODElocation'} eq 'none')) {
5933: if ($$scantron_config{'CODElocation'} < 0 ||
5934: $$scantron_config{'CODElocation'} eq 'letter' ||
5935: $$scantron_config{'CODElocation'} eq 'number') {
1.191 albertel 5936: $record{'scantron.CODE'}=substr($data,
5937: $$scantron_config{'CODEstart'}-1,
1.83 albertel 5938: $$scantron_config{'CODElength'});
1.191 albertel 5939: if (&scan_data($scan_data,"$whichline.useCODE")) {
5940: $record{'scantron.useCODE'}=1;
5941: }
1.192 albertel 5942: if (&scan_data($scan_data,"$whichline.CODE_ignore_dup")) {
5943: $record{'scantron.CODE_ignore_dup'}=1;
5944: }
1.82 albertel 5945: } else {
5946: #FIXME interpret first N questions
5947: }
5948: }
1.83 albertel 5949: $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
5950: $$scantron_config{'IDlength'});
1.157 albertel 5951: $record{'scantron.PaperID'}=
5952: substr($data,$$scantron_config{'PaperID'}-1,
5953: $$scantron_config{'PaperIDlength'});
5954: $record{'scantron.FirstName'}=
5955: substr($data,$$scantron_config{'FirstName'}-1,
5956: $$scantron_config{'FirstNamelength'});
5957: $record{'scantron.LastName'}=
5958: substr($data,$$scantron_config{'LastName'}-1,
5959: $$scantron_config{'LastNamelength'});
1.423 albertel 5960: if ($just_header) { return \%record; }
1.194 albertel 5961:
1.82 albertel 5962: my @alphabet=('A'..'Z');
5963: my $questnum=0;
1.447 foxr 5964: my $ansnum =1; # Multiple 'answer lines'/question.
5965:
1.691 raeburn 5966: my $lastpos = $env{'form.scantron_maxbubble'}*$$scantron_config{'Qlength'};
5967: if ($randompick || $randomorder) {
5968: my $total = &get_respnum_lookups($sequence,$scan_data,$idmap,$line,\%record,
5969: $master_seq,$symb_to_resource,
5970: $partids_by_symb,$orderedforcode,
5971: $respnumlookup,$startline);
5972: if ($total) {
5973: $lastpos = $total*$$scantron_config{'Qlength'};
5974: }
5975: if (ref($totalref)) {
5976: $$totalref = $total;
5977: }
5978: }
5979: my $questions=substr($line,$$scantron_config{'Qstart'}-1,$lastpos); # Answers
1.470 foxr 5980: chomp($questions); # Get rid of any trailing \n.
5981: $questions =~ s/\r$//; # Get rid of trailing \r too (MAC or Win uploads).
5982: while (length($questions)) {
1.691 raeburn 5983: my $answers_needed;
5984: if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
5985: $answers_needed = $bubble_lines_per_response{$respnumlookup->{$questnum}};
5986: } else {
5987: $answers_needed = $bubble_lines_per_response{$questnum};
5988: }
1.503 raeburn 5989: my $answer_length = ($$scantron_config{'Qlength'} * $answers_needed)
5990: || 1;
5991: $questnum++;
5992: my $quest_id = $questnum;
5993: my $currentquest = substr($questions,0,$answer_length);
5994: $questions = substr($questions,$answer_length);
5995: if (length($currentquest) < $answer_length) { next; }
5996:
1.691 raeburn 5997: my $subdivided;
5998: if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
5999: $subdivided = $subdivided_bubble_lines{$respnumlookup->{$questnum-1}};
6000: } else {
6001: $subdivided = $subdivided_bubble_lines{$questnum-1};
6002: }
6003: if ($subdivided =~ /,/) {
1.503 raeburn 6004: my $subquestnum = 1;
6005: my $subquestions = $currentquest;
1.691 raeburn 6006: my @subanswers_needed = split(/,/,$subdivided);
1.503 raeburn 6007: foreach my $subans (@subanswers_needed) {
6008: my $subans_length =
6009: ($$scantron_config{'Qlength'} * $subans) || 1;
6010: my $currsubquest = substr($subquestions,0,$subans_length);
6011: $subquestions = substr($subquestions,$subans_length);
6012: $quest_id = "$questnum.$subquestnum";
6013: if (($$scantron_config{'Qon'} eq 'letter') ||
6014: ($$scantron_config{'Qon'} eq 'number')) {
6015: $ansnum = &scantron_validator_lettnum($ansnum,
6016: $questnum,$quest_id,$subans,$currsubquest,$whichline,
1.691 raeburn 6017: \@alphabet,\%record,$scantron_config,$scan_data,
6018: $randomorder,$randompick,$respnumlookup);
1.503 raeburn 6019: } else {
6020: $ansnum = &scantron_validator_positional($ansnum,
1.691 raeburn 6021: $questnum,$quest_id,$subans,$currsubquest,$whichline,
6022: \@alphabet,\%record,$scantron_config,$scan_data,
6023: $randomorder,$randompick,$respnumlookup);
1.503 raeburn 6024: }
6025: $subquestnum ++;
6026: }
6027: } else {
6028: if (($$scantron_config{'Qon'} eq 'letter') ||
6029: ($$scantron_config{'Qon'} eq 'number')) {
6030: $ansnum = &scantron_validator_lettnum($ansnum,$questnum,
6031: $quest_id,$answers_needed,$currentquest,$whichline,
1.691 raeburn 6032: \@alphabet,\%record,$scantron_config,$scan_data,
6033: $randomorder,$randompick,$respnumlookup);
1.503 raeburn 6034: } else {
6035: $ansnum = &scantron_validator_positional($ansnum,$questnum,
6036: $quest_id,$answers_needed,$currentquest,$whichline,
1.691 raeburn 6037: \@alphabet,\%record,$scantron_config,$scan_data,
6038: $randomorder,$randompick,$respnumlookup);
1.503 raeburn 6039: }
6040: }
6041: }
6042: $record{'scantron.maxquest'}=$questnum;
6043: return \%record;
6044: }
1.447 foxr 6045:
1.691 raeburn 6046: sub get_master_seq {
6047: my ($resources,$master_seq,$symb_to_resource) = @_;
6048: return unless ((ref($resources) eq 'ARRAY') && (ref($master_seq) eq 'ARRAY') &&
6049: (ref($symb_to_resource) eq 'HASH'));
6050: my $resource_error;
6051: foreach my $resource (@{$resources}) {
6052: my $ressymb;
6053: if (ref($resource)) {
6054: $ressymb = $resource->symb();
6055: push(@{$master_seq},$ressymb);
6056: $symb_to_resource->{$ressymb} = $resource;
6057: } else {
6058: $resource_error = 1;
6059: last;
6060: }
6061: }
6062: return $resource_error;
6063: }
6064:
6065: sub get_respnum_lookups {
6066: my ($sequence,$scan_data,$idmap,$line,$record,$master_seq,$symb_to_resource,
6067: $partids_by_symb,$orderedforcode,$respnumlookup,$startline) = @_;
6068: return unless ((ref($record) eq 'HASH') && (ref($master_seq) eq 'ARRAY') &&
6069: (ref($symb_to_resource) eq 'HASH') && (ref($partids_by_symb) eq 'HASH') &&
6070: (ref($orderedforcode) eq 'HASH') && (ref($respnumlookup) eq 'HASH') &&
6071: (ref($startline) eq 'HASH'));
6072: my ($user,$scancode);
6073: if ((exists($record->{'scantron.CODE'})) &&
6074: (&Apache::lonnet::validCODE($record->{'scantron.CODE'}))) {
6075: $scancode = $record->{'scantron.CODE'};
6076: } else {
6077: $user = &scantron_find_student($record,$scan_data,$idmap,$line);
6078: }
6079: my @mapresources =
6080: &users_order($user,$scancode,$sequence,$master_seq,$symb_to_resource,
6081: $orderedforcode);
6082: my $total = 0;
6083: my $count = 0;
6084: foreach my $resource (@mapresources) {
6085: my $id = $resource->id();
6086: my $symb = $resource->symb();
6087: if (ref($partids_by_symb->{$symb}) eq 'ARRAY') {
6088: foreach my $partid (@{$partids_by_symb->{$symb}}) {
6089: my $respnum = $masterseq_id_responsenum{$id.'_'.$partid};
6090: if ($respnum ne '') {
6091: $respnumlookup->{$count} = $respnum;
6092: $startline->{$count} = $total;
6093: $total += $bubble_lines_per_response{$respnum};
6094: $count ++;
6095: }
6096: }
6097: }
6098: }
6099: return $total;
6100: }
6101:
1.503 raeburn 6102: sub scantron_validator_lettnum {
6103: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,$whichline,
1.691 raeburn 6104: $alphabet,$record,$scantron_config,$scan_data,$randomorder,
6105: $randompick,$respnumlookup) = @_;
1.503 raeburn 6106:
6107: # Qon 'letter' implies for each slot in currquest we have:
6108: # ? or * for doubles, a letter in A-Z for a bubble, and
6109: # about anything else (esp. a value of Qoff) for missing
6110: # bubbles.
6111: #
6112: # Qon 'number' implies each slot gives a digit that indexes the
6113: # bubbles filled, or Qoff, or a non-number for unbubbled lines,
6114: # and * or ? for double bubbles on a single line.
6115: #
1.447 foxr 6116:
1.503 raeburn 6117: my $matchon;
6118: if ($$scantron_config{'Qon'} eq 'letter') {
6119: $matchon = '[A-Z]';
6120: } elsif ($$scantron_config{'Qon'} eq 'number') {
6121: $matchon = '\d';
6122: }
6123: my $occurrences = 0;
1.691 raeburn 6124: my $responsenum = $questnum-1;
6125: if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
6126: $responsenum = $respnumlookup->{$questnum-1}
6127: }
6128: if (($responsetype_per_response{$responsenum} eq 'essayresponse') ||
6129: ($responsetype_per_response{$responsenum} eq 'formularesponse') ||
6130: ($responsetype_per_response{$responsenum} eq 'stringresponse') ||
6131: ($responsetype_per_response{$responsenum} eq 'imageresponse') ||
6132: ($responsetype_per_response{$responsenum} eq 'reactionresponse') ||
6133: ($responsetype_per_response{$responsenum} eq 'organicresponse')) {
1.503 raeburn 6134: my @singlelines = split('',$currquest);
6135: foreach my $entry (@singlelines) {
6136: $occurrences = &occurence_count($entry,$matchon);
6137: if ($occurrences > 1) {
6138: last;
6139: }
1.691 raeburn 6140: }
1.503 raeburn 6141: } else {
6142: $occurrences = &occurence_count($currquest,$matchon);
6143: }
6144: if (($currquest =~ /\?/ || $currquest =~ /\*/) || ($occurrences > 1)) {
6145: push(@{$record->{'scantron.doubleerror'}},$quest_id);
6146: for (my $ans=0; $ans<$answers_needed; $ans++) {
6147: my $bubble = substr($currquest,$ans,1);
6148: if ($bubble =~ /$matchon/ ) {
6149: if ($$scantron_config{'Qon'} eq 'number') {
6150: if ($bubble == 0) {
6151: $bubble = 10;
6152: }
6153: $record->{"scantron.$ansnum.answer"} =
6154: $alphabet->[$bubble-1];
6155: } else {
6156: $record->{"scantron.$ansnum.answer"} = $bubble;
6157: }
6158: } else {
6159: $record->{"scantron.$ansnum.answer"}='';
6160: }
6161: $ansnum++;
6162: }
6163: } elsif (!defined($currquest)
6164: || (&occurence_count($currquest, $$scantron_config{'Qoff'}) == length($currquest))
6165: || (&occurence_count($currquest,$matchon) == 0)) {
6166: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
6167: $record->{"scantron.$ansnum.answer"}='';
6168: $ansnum++;
6169: }
6170: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
6171: push(@{$record->{'scantron.missingerror'}},$quest_id);
6172: }
6173: } else {
6174: if ($$scantron_config{'Qon'} eq 'number') {
6175: $currquest = &digits_to_letters($currquest);
6176: }
6177: for (my $ans=0; $ans<$answers_needed; $ans++) {
6178: my $bubble = substr($currquest,$ans,1);
6179: $record->{"scantron.$ansnum.answer"} = $bubble;
6180: $ansnum++;
6181: }
6182: }
6183: return $ansnum;
6184: }
1.447 foxr 6185:
1.503 raeburn 6186: sub scantron_validator_positional {
6187: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,
1.691 raeburn 6188: $whichline,$alphabet,$record,$scantron_config,$scan_data,
6189: $randomorder,$randompick,$respnumlookup) = @_;
1.447 foxr 6190:
1.503 raeburn 6191: # Otherwise there's a positional notation;
6192: # each bubble line requires Qlength items, and there are filled in
6193: # bubbles for each case where there 'Qon' characters.
6194: #
1.447 foxr 6195:
1.503 raeburn 6196: my @array=split($$scantron_config{'Qon'},$currquest,-1);
1.447 foxr 6197:
1.503 raeburn 6198: # If the split only gives us one element.. the full length of the
6199: # answer string, no bubbles are filled in:
1.447 foxr 6200:
1.507 raeburn 6201: if ($answers_needed eq '') {
6202: return;
6203: }
6204:
1.503 raeburn 6205: if (length($array[0]) eq $$scantron_config{'Qlength'}*$answers_needed) {
6206: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
6207: $record->{"scantron.$ansnum.answer"}='';
6208: $ansnum++;
6209: }
6210: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
6211: push(@{$record->{"scantron.missingerror"}},$quest_id);
6212: }
6213: } elsif (scalar(@array) == 2) {
6214: my $location = length($array[0]);
6215: my $line_num = int($location / $$scantron_config{'Qlength'});
6216: my $bubble = $alphabet->[$location % $$scantron_config{'Qlength'}];
6217: for (my $ans=0; $ans<$answers_needed; $ans++) {
6218: if ($ans eq $line_num) {
6219: $record->{"scantron.$ansnum.answer"} = $bubble;
6220: } else {
6221: $record->{"scantron.$ansnum.answer"} = ' ';
6222: }
6223: $ansnum++;
6224: }
6225: } else {
6226: # If there's more than one instance of a bubble character
6227: # That's a double bubble; with positional notation we can
6228: # record all the bubbles filled in as well as the
6229: # fact this response consists of multiple bubbles.
6230: #
1.691 raeburn 6231: my $responsenum = $questnum-1;
6232: if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
6233: $responsenum = $respnumlookup->{$questnum-1}
6234: }
6235: if (($responsetype_per_response{$responsenum} eq 'essayresponse') ||
6236: ($responsetype_per_response{$responsenum} eq 'formularesponse') ||
6237: ($responsetype_per_response{$responsenum} eq 'stringresponse') ||
6238: ($responsetype_per_response{$responsenum} eq 'imageresponse') ||
6239: ($responsetype_per_response{$responsenum} eq 'reactionresponse') ||
6240: ($responsetype_per_response{$responsenum} eq 'organicresponse')) {
1.503 raeburn 6241: my $doubleerror = 0;
6242: while (($currquest >= $$scantron_config{'Qlength'}) &&
6243: (!$doubleerror)) {
6244: my $currline = substr($currquest,0,$$scantron_config{'Qlength'});
6245: $currquest = substr($currquest,$$scantron_config{'Qlength'});
6246: my @currarray = split($$scantron_config{'Qon'},$currline,-1);
6247: if (length(@currarray) > 2) {
6248: $doubleerror = 1;
6249: }
6250: }
6251: if ($doubleerror) {
6252: push(@{$record->{'scantron.doubleerror'}},$quest_id);
6253: }
6254: } else {
6255: push(@{$record->{'scantron.doubleerror'}},$quest_id);
6256: }
6257: my $item = $ansnum;
6258: for (my $ans=0; $ans<$answers_needed; $ans++) {
6259: $record->{"scantron.$item.answer"} = '';
6260: $item ++;
6261: }
1.447 foxr 6262:
1.503 raeburn 6263: my @ans=@array;
6264: my $i=0;
6265: my $increment = 0;
6266: while ($#ans) {
6267: $i+=length($ans[0]) + $increment;
6268: my $line = int($i/$$scantron_config{'Qlength'} + $ansnum);
6269: my $bubble = $i%$$scantron_config{'Qlength'};
6270: $record->{"scantron.$line.answer"}.=$alphabet->[$bubble];
6271: shift(@ans);
6272: $increment = 1;
6273: }
6274: $ansnum += $answers_needed;
1.82 albertel 6275: }
1.503 raeburn 6276: return $ansnum;
1.82 albertel 6277: }
6278:
1.423 albertel 6279: =pod
6280:
6281: =item scantron_add_delay
6282:
6283: Adds an error message that occurred during the grading phase to a
6284: queue of messages to be shown after grading pass is complete
6285:
6286: Arguments:
1.424 albertel 6287: $delayqueue - arrary ref of hash ref of error messages
1.423 albertel 6288: $scanline - the scanline that caused the error
6289: $errormesage - the error message
6290: $errorcode - a numeric code for the error
6291:
6292: Side Effects:
1.424 albertel 6293: updates the $delayqueue to have a new hash ref of the error
1.423 albertel 6294:
6295: =cut
6296:
1.82 albertel 6297: sub scantron_add_delay {
1.140 albertel 6298: my ($delayqueue,$scanline,$errormessage,$errorcode)=@_;
6299: push(@$delayqueue,
6300: {'line' => $scanline, 'emsg' => $errormessage,
6301: 'ecode' => $errorcode }
6302: );
1.82 albertel 6303: }
6304:
1.423 albertel 6305: =pod
6306:
6307: =item scantron_find_student
6308:
1.424 albertel 6309: Finds the username for the current scanline
6310:
6311: Arguments:
6312: $scantron_record - hash result from scantron_parse_scanline
6313: $scan_data - hash of correction information
6314: (see &scantron_getfile() form more information)
6315: $idmap - hash from &username_to_idmap()
6316: $line - number of current scanline
6317:
6318: Returns:
6319: Either 'username:domain' or undef if unknown
6320:
1.423 albertel 6321: =cut
6322:
1.82 albertel 6323: sub scantron_find_student {
1.157 albertel 6324: my ($scantron_record,$scan_data,$idmap,$line)=@_;
1.83 albertel 6325: my $scanID=$$scantron_record{'scantron.ID'};
1.157 albertel 6326: if ($scanID =~ /^\s*$/) {
6327: return &scan_data($scan_data,"$line.user");
6328: }
1.83 albertel 6329: foreach my $id (keys(%$idmap)) {
1.157 albertel 6330: if (lc($id) eq lc($scanID)) {
6331: return $$idmap{$id};
6332: }
1.83 albertel 6333: }
6334: return undef;
6335: }
6336:
1.423 albertel 6337: =pod
6338:
6339: =item scantron_filter
6340:
1.424 albertel 6341: Filter sub for lonnavmaps, filters out hidden resources if ignore
6342: hidden resources was selected
6343:
1.423 albertel 6344: =cut
6345:
1.83 albertel 6346: sub scantron_filter {
6347: my ($curres)=@_;
1.331 albertel 6348:
6349: if (ref($curres) && $curres->is_problem()) {
6350: # if the user has asked to not have either hidden
6351: # or 'randomout' controlled resources to be graded
6352: # don't include them
6353: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
6354: && $curres->randomout) {
6355: return 0;
6356: }
1.83 albertel 6357: return 1;
6358: }
6359: return 0;
1.82 albertel 6360: }
6361:
1.423 albertel 6362: =pod
6363:
6364: =item scantron_process_corrections
6365:
1.424 albertel 6366: Gets correction information out of submitted form data and corrects
6367: the scanline
6368:
1.423 albertel 6369: =cut
6370:
1.157 albertel 6371: sub scantron_process_corrections {
6372: my ($r) = @_;
1.257 albertel 6373: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 6374: my ($scanlines,$scan_data)=&scantron_getfile();
6375: my $classlist=&Apache::loncoursedata::get_classlist();
1.257 albertel 6376: my $which=$env{'form.scantron_line'};
1.200 albertel 6377: my $line=&scantron_get_line($scanlines,$scan_data,$which);
1.157 albertel 6378: my ($skip,$err,$errmsg);
1.257 albertel 6379: if ($env{'form.scantron_skip_record'}) {
1.157 albertel 6380: $skip=1;
1.257 albertel 6381: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)ID$/) {
6382: my $newstudent=$env{'form.scantron_username'}.':'.
6383: $env{'form.scantron_domain'};
1.157 albertel 6384: my $newid=$classlist->{$newstudent}->[&Apache::loncoursedata::CL_ID];
6385: ($line,$err,$errmsg)=
6386: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
6387: 'ID',{'newid'=>$newid,
1.257 albertel 6388: 'username'=>$env{'form.scantron_username'},
6389: 'domain'=>$env{'form.scantron_domain'}});
6390: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)CODE$/) {
6391: my $resolution=$env{'form.scantron_CODE_resolution'};
1.190 albertel 6392: my $newCODE;
1.192 albertel 6393: my %args;
1.190 albertel 6394: if ($resolution eq 'use_unfound') {
1.191 albertel 6395: $newCODE='use_unfound';
1.190 albertel 6396: } elsif ($resolution eq 'use_found') {
1.257 albertel 6397: $newCODE=$env{'form.scantron_CODE_selectedvalue'};
1.190 albertel 6398: } elsif ($resolution eq 'use_typed') {
1.257 albertel 6399: $newCODE=$env{'form.scantron_CODE_newvalue'};
1.194 albertel 6400: } elsif ($resolution =~ /^use_closest_(\d+)/) {
1.257 albertel 6401: $newCODE=$env{"form.scantron_CODE_closest_$1"};
1.190 albertel 6402: }
1.257 albertel 6403: if ($env{'form.scantron_corrections'} eq 'duplicateCODE') {
1.192 albertel 6404: $args{'CODE_ignore_dup'}=1;
6405: }
6406: $args{'CODE'}=$newCODE;
1.186 albertel 6407: ($line,$err,$errmsg)=
6408: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
1.192 albertel 6409: 'CODE',\%args);
1.257 albertel 6410: } elsif ($env{'form.scantron_corrections'} =~ /^(missing|double)bubble$/) {
6411: foreach my $question (split(',',$env{'form.scantron_questions'})) {
1.157 albertel 6412: ($line,$err,$errmsg)=
6413: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,
6414: $which,'answer',
6415: { 'question'=>$question,
1.503 raeburn 6416: 'response'=>$env{"form.scantron_correct_Q_$question"},
6417: 'questionnum'=>$env{"form.scantron_questionnum_Q_$question"}});
1.157 albertel 6418: if ($err) { last; }
6419: }
6420: }
6421: if ($err) {
1.398 albertel 6422: $r->print("<span class=\"LC_warning\">Unable to accept last correction, an error occurred :$errmsg:</span>");
1.157 albertel 6423: } else {
1.200 albertel 6424: &scantron_put_line($scanlines,$scan_data,$which,$line,$skip);
1.157 albertel 6425: &scantron_putfile($scanlines,$scan_data);
6426: }
6427: }
6428:
1.423 albertel 6429: =pod
6430:
6431: =item reset_skipping_status
6432:
1.424 albertel 6433: Forgets the current set of remember skipped scanlines (and thus
6434: reverts back to considering all lines in the
6435: scantron_skipped_<filename> file)
6436:
1.423 albertel 6437: =cut
6438:
1.200 albertel 6439: sub reset_skipping_status {
6440: my ($scanlines,$scan_data)=&scantron_getfile();
6441: &scan_data($scan_data,'remember_skipping',undef,1);
6442: &scantron_putfile(undef,$scan_data);
6443: }
6444:
1.423 albertel 6445: =pod
6446:
6447: =item start_skipping
6448:
1.424 albertel 6449: Marks a scanline to be skipped.
6450:
1.423 albertel 6451: =cut
6452:
1.376 albertel 6453: sub start_skipping {
1.200 albertel 6454: my ($scan_data,$i)=@_;
6455: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 6456: if ($env{'form.scantron_options_redo'} =~ /^redo_/) {
6457: $remembered{$i}=2;
6458: } else {
6459: $remembered{$i}=1;
6460: }
1.200 albertel 6461: &scan_data($scan_data,'remember_skipping',join(':',%remembered));
6462: }
6463:
1.423 albertel 6464: =pod
6465:
6466: =item should_be_skipped
6467:
1.424 albertel 6468: Checks whether a scanline should be skipped.
6469:
1.423 albertel 6470: =cut
6471:
1.200 albertel 6472: sub should_be_skipped {
1.376 albertel 6473: my ($scanlines,$scan_data,$i)=@_;
1.257 albertel 6474: if ($env{'form.scantron_options_redo'} !~ /^redo_/) {
1.200 albertel 6475: # not redoing old skips
1.376 albertel 6476: if ($scanlines->{'skipped'}[$i]) { return 1; }
1.200 albertel 6477: return 0;
6478: }
6479: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 6480:
6481: if (exists($remembered{$i}) && $remembered{$i} != 2 ) {
6482: return 0;
6483: }
1.200 albertel 6484: return 1;
6485: }
6486:
1.423 albertel 6487: =pod
6488:
6489: =item remember_current_skipped
6490:
1.424 albertel 6491: Discovers what scanlines are in the scantron_skipped_<filename>
6492: file and remembers them into scan_data for later use.
6493:
1.423 albertel 6494: =cut
6495:
1.200 albertel 6496: sub remember_current_skipped {
6497: my ($scanlines,$scan_data)=&scantron_getfile();
6498: my %to_remember;
6499: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
6500: if ($scanlines->{'skipped'}[$i]) {
6501: $to_remember{$i}=1;
6502: }
6503: }
1.376 albertel 6504:
1.200 albertel 6505: &scan_data($scan_data,'remember_skipping',join(':',%to_remember));
6506: &scantron_putfile(undef,$scan_data);
6507: }
6508:
1.423 albertel 6509: =pod
6510:
6511: =item check_for_error
6512:
1.424 albertel 6513: Checks if there was an error when attempting to remove a specific
1.659 raeburn 6514: scantron_.. bubblesheet data file. Prints out an error if
1.424 albertel 6515: something went wrong.
6516:
1.423 albertel 6517: =cut
6518:
1.200 albertel 6519: sub check_for_error {
6520: my ($r,$result)=@_;
6521: if ($result ne 'ok' && $result ne 'not_found' ) {
1.492 albertel 6522: $r->print(&mt("An error occurred ([_1]) when trying to remove the existing corrections.",$result));
1.200 albertel 6523: }
6524: }
1.157 albertel 6525:
1.423 albertel 6526: =pod
6527:
6528: =item scantron_warning_screen
6529:
1.424 albertel 6530: Interstitial screen to make sure the operator has selected the
6531: correct options before we start the validation phase.
6532:
1.423 albertel 6533: =cut
6534:
1.203 albertel 6535: sub scantron_warning_screen {
1.650 raeburn 6536: my ($button_text,$symb)=@_;
1.257 albertel 6537: my $title=&Apache::lonnet::gettitle($env{'form.selectpage'});
1.284 albertel 6538: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.373 albertel 6539: my $CODElist;
1.284 albertel 6540: if ($scantron_config{'CODElocation'} &&
6541: $scantron_config{'CODEstart'} &&
6542: $scantron_config{'CODElength'}) {
6543: $CODElist=$env{'form.scantron_CODElist'};
1.398 albertel 6544: if ($env{'form.scantron_CODElist'} eq '') { $CODElist='<span class="LC_warning">None</span>'; }
1.284 albertel 6545: $CODElist=
1.492 albertel 6546: '<tr><td><b>'.&mt('List of CODES to validate against:').'</b></td><td><tt>'.
1.373 albertel 6547: $env{'form.scantron_CODElist'}.'</tt></td></tr>';
1.284 albertel 6548: }
1.663 raeburn 6549: my $lastbubblepoints;
6550: if ($env{'form.scantron_lastbubblepoints'} ne '') {
6551: $lastbubblepoints =
6552: '<tr><td><b>'.&mt('Hand-graded items: points from last bubble in row').'</b></td><td><tt>'.
6553: $env{'form.scantron_lastbubblepoints'}.'</tt></td></tr>';
6554: }
1.492 albertel 6555: return ('
1.203 albertel 6556: <p>
1.492 albertel 6557: <span class="LC_warning">
6558: '.&mt('Please double check the information below before clicking on \'[_1]\'',&mt($button_text)).'</span>
1.203 albertel 6559: </p>
6560: <table>
1.492 albertel 6561: <tr><td><b>'.&mt('Sequence to be Graded:').'</b></td><td>'.$title.'</td></tr>
6562: <tr><td><b>'.&mt('Data File that will be used:').'</b></td><td><tt>'.$env{'form.scantron_selectfile'}.'</tt></td></tr>
1.663 raeburn 6563: '.$CODElist.$lastbubblepoints.'
1.203 albertel 6564: </table>
1.680 raeburn 6565: <p> '.&mt("If this information is correct, please click on '[_1]'.",&mt($button_text)).'<br />
1.650 raeburn 6566: '.&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 6567:
6568: <br />
1.492 albertel 6569: ');
1.203 albertel 6570: }
6571:
1.423 albertel 6572: =pod
6573:
6574: =item scantron_do_warning
6575:
1.424 albertel 6576: Check if the operator has picked something for all required
6577: fields. Error out if something is missing.
6578:
1.423 albertel 6579: =cut
6580:
1.203 albertel 6581: sub scantron_do_warning {
1.608 www 6582: my ($r,$symb)=@_;
1.203 albertel 6583: if (!$symb) {return '';}
1.324 albertel 6584: my $default_form_data=&defaultFormData($symb);
1.203 albertel 6585: $r->print(&scantron_form_start().$default_form_data);
1.257 albertel 6586: if ( $env{'form.selectpage'} eq '' ||
6587: $env{'form.scantron_selectfile'} eq '' ||
6588: $env{'form.scantron_format'} eq '' ) {
1.642 raeburn 6589: $r->print("<p>".&mt('You have forgotten to specify some information. Please go Back and try again.')."</p>");
1.257 albertel 6590: if ( $env{'form.selectpage'} eq '') {
1.492 albertel 6591: $r->print('<p><span class="LC_error">'.&mt('You have not selected a Sequence to grade').'</span></p>');
1.237 albertel 6592: }
1.257 albertel 6593: if ( $env{'form.scantron_selectfile'} eq '') {
1.642 raeburn 6594: $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 6595: }
1.257 albertel 6596: if ( $env{'form.scantron_format'} eq '') {
1.642 raeburn 6597: $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 6598: }
6599: } else {
1.650 raeburn 6600: my $warning=&scantron_warning_screen('Grading: Validate Records',$symb);
1.663 raeburn 6601: my $bubbledbyhand=&hand_bubble_option();
1.492 albertel 6602: $r->print('
1.663 raeburn 6603: '.$warning.$bubbledbyhand.'
1.492 albertel 6604: <input type="submit" name="submit" value="'.&mt('Grading: Validate Records').'" />
1.203 albertel 6605: <input type="hidden" name="command" value="scantron_validate" />
1.492 albertel 6606: ');
1.237 albertel 6607: }
1.614 www 6608: $r->print("</form><br />");
1.203 albertel 6609: return '';
6610: }
6611:
1.423 albertel 6612: =pod
6613:
6614: =item scantron_form_start
6615:
1.424 albertel 6616: html hidden input for remembering all selected grading options
6617:
1.423 albertel 6618: =cut
6619:
1.203 albertel 6620: sub scantron_form_start {
6621: my ($max_bubble)=@_;
6622: my $result= <<SCANTRONFORM;
6623: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
1.257 albertel 6624: <input type="hidden" name="selectpage" value="$env{'form.selectpage'}" />
6625: <input type="hidden" name="scantron_format" value="$env{'form.scantron_format'}" />
6626: <input type="hidden" name="scantron_selectfile" value="$env{'form.scantron_selectfile'}" />
1.218 albertel 6627: <input type="hidden" name="scantron_maxbubble" value="$max_bubble" />
1.257 albertel 6628: <input type="hidden" name="scantron_CODElist" value="$env{'form.scantron_CODElist'}" />
6629: <input type="hidden" name="scantron_CODEunique" value="$env{'form.scantron_CODEunique'}" />
6630: <input type="hidden" name="scantron_options_redo" value="$env{'form.scantron_options_redo'}" />
6631: <input type="hidden" name="scantron_options_ignore" value="$env{'form.scantron_options_ignore'}" />
1.331 albertel 6632: <input type="hidden" name="scantron_options_hidden" value="$env{'form.scantron_options_hidden'}" />
1.203 albertel 6633: SCANTRONFORM
1.447 foxr 6634:
6635: my $line = 0;
6636: while (defined($env{"form.scantron.bubblelines.$line"})) {
6637: my $chunk =
6638: '<input type="hidden" name="scantron.bubblelines.'.$line.'" value="'.$env{"form.scantron.bubblelines.$line"}.'" />'."\n";
1.448 foxr 6639: $chunk .=
6640: '<input type="hidden" name="scantron.first_bubble_line.'.$line.'" value="'.$env{"form.scantron.first_bubble_line.$line"}.'" />'."\n";
1.503 raeburn 6641: $chunk .=
6642: '<input type="hidden" name="scantron.sub_bubblelines.'.$line.'" value="'.$env{"form.scantron.sub_bubblelines.$line"}.'" />'."\n";
1.504 raeburn 6643: $chunk .=
6644: '<input type="hidden" name="scantron.responsetype.'.$line.'" value="'.$env{"form.scantron.responsetype.$line"}.'" />'."\n";
1.691 raeburn 6645: $chunk .=
6646: '<input type="hidden" name="scantron.residpart.'.$line.'" value="'.$env{"form.scantron.residpart.$line"}.'" />'."\n";
1.447 foxr 6647: $result .= $chunk;
6648: $line++;
1.691 raeburn 6649: }
1.203 albertel 6650: return $result;
6651: }
6652:
1.423 albertel 6653: =pod
6654:
6655: =item scantron_validate_file
6656:
1.659 raeburn 6657: Dispatch routine for doing validation of a bubblesheet data file.
1.424 albertel 6658:
6659: Also processes any necessary information resets that need to
6660: occur before validation begins (ignore previous corrections,
6661: restarting the skipped records processing)
6662:
1.423 albertel 6663: =cut
6664:
1.157 albertel 6665: sub scantron_validate_file {
1.608 www 6666: my ($r,$symb) = @_;
1.157 albertel 6667: if (!$symb) {return '';}
1.324 albertel 6668: my $default_form_data=&defaultFormData($symb);
1.200 albertel 6669:
6670: # do the detection of only doing skipped records first befroe we delete
1.424 albertel 6671: # them when doing the corrections reset
1.257 albertel 6672: if ($env{'form.scantron_options_redo'} ne 'redo_skipped_ready') {
1.200 albertel 6673: &reset_skipping_status();
6674: }
1.257 albertel 6675: if ($env{'form.scantron_options_redo'} eq 'redo_skipped') {
1.200 albertel 6676: &remember_current_skipped();
1.257 albertel 6677: $env{'form.scantron_options_redo'}='redo_skipped_ready';
1.200 albertel 6678: }
6679:
1.257 albertel 6680: if ($env{'form.scantron_options_ignore'} eq 'ignore_corrections') {
1.200 albertel 6681: &check_for_error($r,&scantron_remove_file('corrected'));
6682: &check_for_error($r,&scantron_remove_file('skipped'));
6683: &check_for_error($r,&scantron_remove_scan_data());
1.257 albertel 6684: $env{'form.scantron_options_ignore'}='done';
1.192 albertel 6685: }
1.200 albertel 6686:
1.257 albertel 6687: if ($env{'form.scantron_corrections'}) {
1.157 albertel 6688: &scantron_process_corrections($r);
6689: }
1.503 raeburn 6690: $r->print('<p>'.&mt('Gathering necessary information.').'</p>');$r->rflush();
1.157 albertel 6691: #get the student pick code ready
6692: $r->print(&Apache::loncommon::studentbrowser_javascript());
1.582 raeburn 6693: my $nav_error;
1.649 raeburn 6694: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
6695: my $max_bubble=&scantron_get_maxbubble(\$nav_error,\%scantron_config);
1.582 raeburn 6696: if ($nav_error) {
6697: $r->print(&navmap_errormsg());
6698: return '';
6699: }
1.203 albertel 6700: my $result=&scantron_form_start($max_bubble).$default_form_data;
1.663 raeburn 6701: if ($env{'form.scantron_lastbubblepoints'} ne '') {
6702: $result .= '<input type="hidden" name="scantron_lastbubblepoints" value="'.$env{'form.scantron_lastbubblepoints'}.'" />';
6703: }
1.157 albertel 6704: $r->print($result);
6705:
1.334 albertel 6706: my @validate_phases=( 'sequence',
6707: 'ID',
1.157 albertel 6708: 'CODE',
6709: 'doublebubble',
6710: 'missingbubbles');
1.257 albertel 6711: if (!$env{'form.validatepass'}) {
6712: $env{'form.validatepass'} = 0;
1.157 albertel 6713: }
1.257 albertel 6714: my $currentphase=$env{'form.validatepass'};
1.157 albertel 6715:
1.448 foxr 6716:
1.157 albertel 6717: my $stop=0;
6718: while (!$stop && $currentphase < scalar(@validate_phases)) {
1.503 raeburn 6719: $r->print(&mt('Validating '.$validate_phases[$currentphase]).'<br />');
1.157 albertel 6720: $r->rflush();
1.691 raeburn 6721:
1.157 albertel 6722: my $which="scantron_validate_".$validate_phases[$currentphase];
6723: {
6724: no strict 'refs';
6725: ($stop,$currentphase)=&$which($r,$currentphase);
6726: }
6727: }
6728: if (!$stop) {
1.650 raeburn 6729: my $warning=&scantron_warning_screen('Start Grading',$symb);
1.542 raeburn 6730: $r->print(&mt('Validation process complete.').'<br />'.
6731: $warning.
6732: &mt('Perform verification for each student after storage of submissions?').
6733: ' <span class="LC_nobreak"><label>'.
6734: '<input type="radio" name="verifyrecord" value="1" />'.&mt('Yes').'</label>'.
6735: (' 'x3).'<label>'.
6736: '<input type="radio" name="verifyrecord" value="0" checked="checked" />'.&mt('No').
6737: '</label></span><br />'.
6738: &mt('Grading will take longer if you use verification.').'<br />'.
1.650 raeburn 6739: &mt('Otherwise, Grade/Manage/Review Bubblesheets [_1] Review bubblesheet data can be used once grading is complete.','»').'<br /><br />'.
1.542 raeburn 6740: '<input type="submit" name="submit" value="'.&mt('Start Grading').'" />'.
6741: '<input type="hidden" name="command" value="scantron_process" />'."\n");
1.157 albertel 6742: } else {
6743: $r->print('<input type="hidden" name="command" value="scantron_validate" />');
6744: $r->print("<input type='hidden' name='validatepass' value='".$currentphase."' />");
6745: }
6746: if ($stop) {
1.334 albertel 6747: if ($validate_phases[$currentphase] eq 'sequence') {
1.539 riegler 6748: $r->print('<input type="submit" name="submit" value="'.&mt('Ignore').' → " />');
1.492 albertel 6749: $r->print(' '.&mt('this error').' <br />');
1.334 albertel 6750:
1.650 raeburn 6751: $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 6752: } else {
1.503 raeburn 6753: if ($validate_phases[$currentphase] eq 'doublebubble' || $validate_phases[$currentphase] eq 'missingbubbles') {
1.539 riegler 6754: $r->print('<input type="button" name="submitbutton" value="'.&mt('Continue').' →" onclick="javascript:verify_bubble_radio(this.form)" />');
1.503 raeburn 6755: } else {
1.539 riegler 6756: $r->print('<input type="submit" name="submit" value="'.&mt('Continue').' →" />');
1.503 raeburn 6757: }
1.492 albertel 6758: $r->print(' '.&mt('using corrected info').' <br />');
6759: $r->print("<input type='submit' value='".&mt("Skip")."' name='scantron_skip_record' />");
6760: $r->print(" ".&mt("this scanline saving it for later."));
1.334 albertel 6761: }
1.157 albertel 6762: }
1.614 www 6763: $r->print(" </form><br />");
1.157 albertel 6764: return '';
6765: }
6766:
1.423 albertel 6767:
6768: =pod
6769:
6770: =item scantron_remove_file
6771:
1.659 raeburn 6772: Removes the requested bubblesheet data file, makes sure that
1.424 albertel 6773: scantron_original_<filename> is never removed
6774:
6775:
1.423 albertel 6776: =cut
6777:
1.200 albertel 6778: sub scantron_remove_file {
1.192 albertel 6779: my ($which)=@_;
1.257 albertel 6780: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6781: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 6782: my $file='scantron_';
1.200 albertel 6783: if ($which eq 'corrected' || $which eq 'skipped') {
6784: $file.=$which.'_';
1.192 albertel 6785: } else {
6786: return 'refused';
6787: }
1.257 albertel 6788: $file.=$env{'form.scantron_selectfile'};
1.200 albertel 6789: return &Apache::lonnet::removeuserfile($cname,$cdom,$file);
6790: }
6791:
1.423 albertel 6792:
6793: =pod
6794:
6795: =item scantron_remove_scan_data
6796:
1.659 raeburn 6797: Removes all scan_data correction for the requested bubblesheet
1.424 albertel 6798: data file. (In the case that both the are doing skipped records we need
6799: to remember the old skipped lines for the time being so that element
6800: persists for a while.)
6801:
1.423 albertel 6802: =cut
6803:
1.200 albertel 6804: sub scantron_remove_scan_data {
1.257 albertel 6805: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6806: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 6807: my @keys=&Apache::lonnet::getkeys('nohist_scantrondata',$cdom,$cname);
6808: my @todelete;
1.257 albertel 6809: my $filename=$env{'form.scantron_selectfile'};
1.192 albertel 6810: foreach my $key (@keys) {
6811: if ($key=~/^\Q$filename\E_/) {
1.257 albertel 6812: if ($env{'form.scantron_options_redo'} eq 'redo_skipped_ready' &&
1.200 albertel 6813: $key=~/remember_skipping/) {
6814: next;
6815: }
1.192 albertel 6816: push(@todelete,$key);
6817: }
6818: }
1.200 albertel 6819: my $result;
1.192 albertel 6820: if (@todelete) {
1.491 albertel 6821: $result = &Apache::lonnet::del('nohist_scantrondata',
6822: \@todelete,$cdom,$cname);
6823: } else {
6824: $result = 'ok';
1.192 albertel 6825: }
6826: return $result;
6827: }
6828:
1.423 albertel 6829:
6830: =pod
6831:
6832: =item scantron_getfile
6833:
1.659 raeburn 6834: Fetches the requested bubblesheet data file (all 3 versions), and
1.424 albertel 6835: the scan_data hash
6836:
6837: Arguments:
6838: None
6839:
6840: Returns:
6841: 2 hash references
6842:
6843: - first one has
6844: orig -
6845: corrected -
6846: skipped - each of which points to an array ref of the specified
6847: file broken up into individual lines
6848: count - number of scanlines
6849:
6850: - second is the scan_data hash possible keys are
1.425 albertel 6851: ($number refers to scanline numbered $number and thus the key affects
6852: only that scanline
6853: $bubline refers to the specific bubble line element and the aspects
6854: refers to that specific bubble line element)
6855:
6856: $number.user - username:domain to use
6857: $number.CODE_ignore_dup
6858: - ignore the duplicate CODE error
6859: $number.useCODE
6860: - use the CODE in the scanline as is
6861: $number.no_bubble.$bubline
6862: - it is valid that there is no bubbled in bubble
6863: at $number $bubline
6864: remember_skipping
6865: - a frozen hash containing keys of $number and values
6866: of either
6867: 1 - we are on a 'do skipped records pass' and plan
6868: on processing this line
6869: 2 - we are on a 'do skipped records pass' and this
6870: scanline has been marked to skip yet again
1.424 albertel 6871:
1.423 albertel 6872: =cut
6873:
1.157 albertel 6874: sub scantron_getfile {
1.200 albertel 6875: #FIXME really would prefer a scantron directory
1.257 albertel 6876: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6877: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.157 albertel 6878: my $lines;
6879: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6880: 'scantron_orig_'.$env{'form.scantron_selectfile'});
1.157 albertel 6881: my %scanlines;
6882: $scanlines{'orig'}=[(split("\n",$lines,-1))];
6883: my $temp=$scanlines{'orig'};
6884: $scanlines{'count'}=$#$temp;
6885:
6886: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6887: 'scantron_corrected_'.$env{'form.scantron_selectfile'});
1.157 albertel 6888: if ($lines eq '-1') {
6889: $scanlines{'corrected'}=[];
6890: } else {
6891: $scanlines{'corrected'}=[(split("\n",$lines,-1))];
6892: }
6893: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6894: 'scantron_skipped_'.$env{'form.scantron_selectfile'});
1.157 albertel 6895: if ($lines eq '-1') {
6896: $scanlines{'skipped'}=[];
6897: } else {
6898: $scanlines{'skipped'}=[(split("\n",$lines,-1))];
6899: }
1.175 albertel 6900: my @tmp=&Apache::lonnet::dump('nohist_scantrondata',$cdom,$cname);
1.157 albertel 6901: if ($tmp[0] =~ /^(error:|no_such_host)/) { @tmp=(); }
6902: my %scan_data = @tmp;
6903: return (\%scanlines,\%scan_data);
6904: }
6905:
1.423 albertel 6906: =pod
6907:
6908: =item lonnet_putfile
6909:
1.424 albertel 6910: Wrapper routine to call &Apache::lonnet::finishuserfileupload
6911:
6912: Arguments:
6913: $contents - data to store
6914: $filename - filename to store $contents into
6915:
6916: Returns:
6917: result value from &Apache::lonnet::finishuserfileupload
6918:
1.423 albertel 6919: =cut
6920:
1.157 albertel 6921: sub lonnet_putfile {
6922: my ($contents,$filename)=@_;
1.257 albertel 6923: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6924: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6925: $env{'form.sillywaytopassafilearound'}=$contents;
1.275 albertel 6926: &Apache::lonnet::finishuserfileupload($docuname,$docudom,'sillywaytopassafilearound',$filename);
1.157 albertel 6927:
6928: }
6929:
1.423 albertel 6930: =pod
6931:
6932: =item scantron_putfile
6933:
1.659 raeburn 6934: Stores the current version of the bubblesheet data files, and the
1.424 albertel 6935: scan_data hash. (Does not modify the original version only the
6936: corrected and skipped versions.
6937:
6938: Arguments:
6939: $scanlines - hash ref that looks like the first return value from
6940: &scantron_getfile()
6941: $scan_data - hash ref that looks like the second return value from
6942: &scantron_getfile()
6943:
1.423 albertel 6944: =cut
6945:
1.157 albertel 6946: sub scantron_putfile {
6947: my ($scanlines,$scan_data) = @_;
1.200 albertel 6948: #FIXME really would prefer a scantron directory
1.257 albertel 6949: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6950: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.200 albertel 6951: if ($scanlines) {
6952: my $prefix='scantron_';
1.157 albertel 6953: # no need to update orig, shouldn't change
6954: # &lonnet_putfile(join("\n",@{$scanlines->{'orig'}}),$prefix.'orig_'.
1.257 albertel 6955: # $env{'form.scantron_selectfile'});
1.200 albertel 6956: &lonnet_putfile(join("\n",@{$scanlines->{'corrected'}}),
6957: $prefix.'corrected_'.
1.257 albertel 6958: $env{'form.scantron_selectfile'});
1.200 albertel 6959: &lonnet_putfile(join("\n",@{$scanlines->{'skipped'}}),
6960: $prefix.'skipped_'.
1.257 albertel 6961: $env{'form.scantron_selectfile'});
1.200 albertel 6962: }
1.175 albertel 6963: &Apache::lonnet::put('nohist_scantrondata',$scan_data,$cdom,$cname);
1.157 albertel 6964: }
6965:
1.423 albertel 6966: =pod
6967:
6968: =item scantron_get_line
6969:
1.424 albertel 6970: Returns the correct version of the scanline
6971:
6972: Arguments:
6973: $scanlines - hash ref that looks like the first return value from
6974: &scantron_getfile()
6975: $scan_data - hash ref that looks like the second return value from
6976: &scantron_getfile()
6977: $i - number of the requested line (starts at 0)
6978:
6979: Returns:
6980: A scanline, (either the original or the corrected one if it
6981: exists), or undef if the requested scanline should be
6982: skipped. (Either because it's an skipped scanline, or it's an
6983: unskipped scanline and we are not doing a 'do skipped scanlines'
6984: pass.
6985:
1.423 albertel 6986: =cut
6987:
1.157 albertel 6988: sub scantron_get_line {
1.200 albertel 6989: my ($scanlines,$scan_data,$i)=@_;
1.376 albertel 6990: if (&should_be_skipped($scanlines,$scan_data,$i)) { return undef; }
6991: #if ($scanlines->{'skipped'}[$i]) { return undef; }
1.157 albertel 6992: if ($scanlines->{'corrected'}[$i]) {return $scanlines->{'corrected'}[$i];}
6993: return $scanlines->{'orig'}[$i];
6994: }
6995:
1.423 albertel 6996: =pod
6997:
6998: =item scantron_todo_count
6999:
1.424 albertel 7000: Counts the number of scanlines that need processing.
7001:
7002: Arguments:
7003: $scanlines - hash ref that looks like the first return value from
7004: &scantron_getfile()
7005: $scan_data - hash ref that looks like the second return value from
7006: &scantron_getfile()
7007:
7008: Returns:
7009: $count - number of scanlines to process
7010:
1.423 albertel 7011: =cut
7012:
1.200 albertel 7013: sub get_todo_count {
7014: my ($scanlines,$scan_data)=@_;
7015: my $count=0;
7016: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
7017: my $line=&scantron_get_line($scanlines,$scan_data,$i);
7018: if ($line=~/^[\s\cz]*$/) { next; }
7019: $count++;
7020: }
7021: return $count;
7022: }
7023:
1.423 albertel 7024: =pod
7025:
7026: =item scantron_put_line
7027:
1.659 raeburn 7028: Updates the 'corrected' or 'skipped' versions of the bubblesheet
1.424 albertel 7029: data file.
7030:
7031: Arguments:
7032: $scanlines - hash ref that looks like the first return value from
7033: &scantron_getfile()
7034: $scan_data - hash ref that looks like the second return value from
7035: &scantron_getfile()
7036: $i - line number to update
7037: $newline - contents of the updated scanline
7038: $skip - if true make the line for skipping and update the
7039: 'skipped' file
7040:
1.423 albertel 7041: =cut
7042:
1.157 albertel 7043: sub scantron_put_line {
1.200 albertel 7044: my ($scanlines,$scan_data,$i,$newline,$skip)=@_;
1.157 albertel 7045: if ($skip) {
7046: $scanlines->{'skipped'}[$i]=$newline;
1.376 albertel 7047: &start_skipping($scan_data,$i);
1.157 albertel 7048: return;
7049: }
7050: $scanlines->{'corrected'}[$i]=$newline;
7051: }
7052:
1.423 albertel 7053: =pod
7054:
7055: =item scantron_clear_skip
7056:
1.424 albertel 7057: Remove a line from the 'skipped' file
7058:
7059: Arguments:
7060: $scanlines - hash ref that looks like the first return value from
7061: &scantron_getfile()
7062: $scan_data - hash ref that looks like the second return value from
7063: &scantron_getfile()
7064: $i - line number to update
7065:
1.423 albertel 7066: =cut
7067:
1.376 albertel 7068: sub scantron_clear_skip {
7069: my ($scanlines,$scan_data,$i)=@_;
7070: if (exists($scanlines->{'skipped'}[$i])) {
7071: undef($scanlines->{'skipped'}[$i]);
7072: return 1;
7073: }
7074: return 0;
7075: }
7076:
1.423 albertel 7077: =pod
7078:
7079: =item scantron_filter_not_exam
7080:
1.424 albertel 7081: Filter routine used by &Apache::lonnavmaps::retrieveResources(), to
7082: filter out resources that are not marked as 'exam' mode
7083:
1.423 albertel 7084: =cut
7085:
1.334 albertel 7086: sub scantron_filter_not_exam {
7087: my ($curres)=@_;
7088:
7089: if (ref($curres) && $curres->is_problem() && !$curres->is_exam()) {
7090: # if the user has asked to not have either hidden
7091: # or 'randomout' controlled resources to be graded
7092: # don't include them
7093: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
7094: && $curres->randomout) {
7095: return 0;
7096: }
7097: return 1;
7098: }
7099: return 0;
7100: }
7101:
1.423 albertel 7102: =pod
7103:
7104: =item scantron_validate_sequence
7105:
1.424 albertel 7106: Validates the selected sequence, checking for resource that are
7107: not set to exam mode.
7108:
1.423 albertel 7109: =cut
7110:
1.334 albertel 7111: sub scantron_validate_sequence {
7112: my ($r,$currentphase) = @_;
7113:
7114: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 7115: unless (ref($navmap)) {
7116: $r->print(&navmap_errormsg());
7117: return (1,$currentphase);
7118: }
1.334 albertel 7119: my (undef,undef,$sequence)=
7120: &Apache::lonnet::decode_symb($env{'form.selectpage'});
7121:
7122: my $map=$navmap->getResourceByUrl($sequence);
7123:
7124: $r->print('<input type="hidden" name="validate_sequence_exam"
7125: value="ignore" />');
7126: if ($env{'form.validate_sequence_exam'} ne 'ignore') {
7127: my @resources=
7128: $navmap->retrieveResources($map,\&scantron_filter_not_exam,1,0);
7129: if (@resources) {
1.675 bisitz 7130: $r->print(
7131: '<p class="LC_warning">'
7132: .&mt('Some resources in the sequence currently are not set to'
1.684 bisitz 7133: .' bubblesheet exam mode. Grading these resources currently may not'
1.675 bisitz 7134: .' work correctly.')
7135: .'</p>'
7136: );
1.334 albertel 7137: return (1,$currentphase);
7138: }
7139: }
7140:
7141: return (0,$currentphase+1);
7142: }
7143:
1.423 albertel 7144:
7145:
1.157 albertel 7146: sub scantron_validate_ID {
7147: my ($r,$currentphase) = @_;
7148:
7149: #get student info
7150: my $classlist=&Apache::loncoursedata::get_classlist();
7151: my %idmap=&username_to_idmap($classlist);
7152:
7153: #get scantron line setup
1.257 albertel 7154: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7155: my ($scanlines,$scan_data)=&scantron_getfile();
1.582 raeburn 7156:
7157: my $nav_error;
1.649 raeburn 7158: &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the bubble_lines.. array.
1.582 raeburn 7159: if ($nav_error) {
7160: $r->print(&navmap_errormsg());
7161: return(1,$currentphase);
7162: }
1.157 albertel 7163:
7164: my %found=('ids'=>{},'usernames'=>{});
7165: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7166: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7167: if ($line=~/^[\s\cz]*$/) { next; }
7168: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7169: $scan_data);
7170: my $id=$$scan_record{'scantron.ID'};
7171: my $found;
7172: foreach my $checkid (keys(%idmap)) {
7173: if (lc($checkid) eq lc($id)) { $found=$checkid;last; }
7174: }
7175: if ($found) {
7176: my $username=$idmap{$found};
7177: if ($found{'ids'}{$found}) {
7178: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
7179: $line,'duplicateID',$found);
1.194 albertel 7180: return(1,$currentphase);
1.157 albertel 7181: } elsif ($found{'usernames'}{$username}) {
7182: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
7183: $line,'duplicateID',$username);
1.194 albertel 7184: return(1,$currentphase);
1.157 albertel 7185: }
1.186 albertel 7186: #FIXME store away line we previously saw the ID on to use above
1.157 albertel 7187: $found{'ids'}{$found}++;
7188: $found{'usernames'}{$username}++;
7189: } else {
7190: if ($id =~ /^\s*$/) {
1.158 albertel 7191: my $username=&scan_data($scan_data,"$i.user");
1.157 albertel 7192: if (defined($username) && $found{'usernames'}{$username}) {
7193: &scantron_get_correction($r,$i,$scan_record,
7194: \%scantron_config,
7195: $line,'duplicateID',$username);
1.194 albertel 7196: return(1,$currentphase);
1.157 albertel 7197: } elsif (!defined($username)) {
7198: &scantron_get_correction($r,$i,$scan_record,
7199: \%scantron_config,
7200: $line,'incorrectID');
1.194 albertel 7201: return(1,$currentphase);
1.157 albertel 7202: }
7203: $found{'usernames'}{$username}++;
7204: } else {
7205: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
7206: $line,'incorrectID');
1.194 albertel 7207: return(1,$currentphase);
1.157 albertel 7208: }
7209: }
7210: }
7211:
7212: return (0,$currentphase+1);
7213: }
7214:
1.423 albertel 7215:
1.157 albertel 7216: sub scantron_get_correction {
1.691 raeburn 7217: my ($r,$i,$scan_record,$scan_config,$line,$error,$arg,
7218: $randomorder,$randompick,$respnumlookup,$startline)=@_;
1.454 banghart 7219: #FIXME in the case of a duplicated ID the previous line, probably need
1.157 albertel 7220: #to show both the current line and the previous one and allow skipping
7221: #the previous one or the current one
7222:
1.333 albertel 7223: if ( $$scan_record{'scantron.PaperID'} =~ /\S/) {
1.658 bisitz 7224: $r->print(
7225: '<p class="LC_warning">'
7226: .&mt('An error was detected ([_1]) for PaperID [_2]',
7227: "<b>$error</b>",
7228: '<tt>'.$$scan_record{'scantron.PaperID'}.'</tt>')
7229: ."</p> \n");
1.157 albertel 7230: } else {
1.658 bisitz 7231: $r->print(
7232: '<p class="LC_warning">'
7233: .&mt('An error was detected ([_1]) in scanline [_2] [_3]',
7234: "<b>$error</b>", $i, "<pre>$line</pre>")
7235: ."</p> \n");
7236: }
7237: my $message =
7238: '<p>'
7239: .&mt('The ID on the form is [_1]',
7240: "<tt>$$scan_record{'scantron.ID'}</tt>")
7241: .'<br />'
1.665 raeburn 7242: .&mt('The name on the paper is [_1], [_2]',
1.658 bisitz 7243: $$scan_record{'scantron.LastName'},
7244: $$scan_record{'scantron.FirstName'})
7245: .'</p>';
1.242 albertel 7246:
1.157 albertel 7247: $r->print('<input type="hidden" name="scantron_corrections" value="'.$error.'" />'."\n");
7248: $r->print('<input type="hidden" name="scantron_line" value="'.$i.'" />'."\n");
1.503 raeburn 7249: # Array populated for doublebubble or
7250: my @lines_to_correct; # missingbubble errors to build javascript
7251: # to validate radio button checking
7252:
1.157 albertel 7253: if ($error =~ /ID$/) {
1.186 albertel 7254: if ($error eq 'incorrectID') {
1.658 bisitz 7255: $r->print('<p class="LC_warning">'.&mt("The encoded ID is not in the classlist").
1.492 albertel 7256: "</p>\n");
1.157 albertel 7257: } elsif ($error eq 'duplicateID') {
1.658 bisitz 7258: $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 7259: }
1.242 albertel 7260: $r->print($message);
1.492 albertel 7261: $r->print("<p>".&mt("How should I handle this?")." <br /> \n");
1.157 albertel 7262: $r->print("\n<ul><li> ");
7263: #FIXME it would be nice if this sent back the user ID and
7264: #could do partial userID matches
7265: $r->print(&Apache::loncommon::selectstudent_link('scantronupload',
7266: 'scantron_username','scantron_domain'));
7267: $r->print(": <input type='text' name='scantron_username' value='' />");
1.685 bisitz 7268: $r->print("\n:\n".
1.257 albertel 7269: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'scantron_domain'));
1.157 albertel 7270:
7271: $r->print('</li>');
1.186 albertel 7272: } elsif ($error =~ /CODE$/) {
7273: if ($error eq 'incorrectCODE') {
1.658 bisitz 7274: $r->print('<p class="LC_warning">'.&mt("The encoded CODE is not in the list of possible CODEs.")."</p>\n");
1.186 albertel 7275: } elsif ($error eq 'duplicateCODE') {
1.658 bisitz 7276: $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 7277: }
1.658 bisitz 7278: $r->print("<p>".&mt('The CODE on the form is [_1]',
7279: "<tt>'$$scan_record{'scantron.CODE'}'</tt>")
7280: ."</p>\n");
1.242 albertel 7281: $r->print($message);
1.658 bisitz 7282: $r->print("<p>".&mt("How should I handle this?")."</p>\n");
1.187 albertel 7283: $r->print("\n<br /> ");
1.194 albertel 7284: my $i=0;
1.273 albertel 7285: if ($error eq 'incorrectCODE'
7286: && $$scan_record{'scantron.CODE'}=~/\S/ ) {
1.194 albertel 7287: my ($max,$closest)=&scantron_get_closely_matching_CODEs($arg,$$scan_record{'scantron.CODE'});
1.278 albertel 7288: if ($closest > 0) {
7289: foreach my $testcode (@{$closest}) {
7290: my $checked='';
1.569 bisitz 7291: if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 7292: $r->print("
7293: <label>
1.569 bisitz 7294: <input type='radio' name='scantron_CODE_resolution' value='use_closest_$i'$checked />
1.492 albertel 7295: ".&mt("Use the similar CODE [_1] instead.",
7296: "<b><tt>".$testcode."</tt></b>")."
7297: </label>
7298: <input type='hidden' name='scantron_CODE_closest_$i' value='$testcode' />");
1.278 albertel 7299: $r->print("\n<br />");
7300: $i++;
7301: }
1.194 albertel 7302: }
7303: }
1.273 albertel 7304: if ($$scan_record{'scantron.CODE'}=~/\S/ ) {
1.569 bisitz 7305: my $checked; if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 7306: $r->print("
7307: <label>
1.569 bisitz 7308: <input type='radio' name='scantron_CODE_resolution' value='use_unfound'$checked />
1.659 raeburn 7309: ".&mt("Use the CODE [_1] that was on the paper, ignoring the error.",
1.492 albertel 7310: "<b><tt>".$$scan_record{'scantron.CODE'}."</tt></b>")."
7311: </label>");
1.273 albertel 7312: $r->print("\n<br />");
7313: }
1.194 albertel 7314:
1.597 wenzelju 7315: $r->print(&Apache::lonhtmlcommon::scripttag(<<ENDSCRIPT));
1.188 albertel 7316: function change_radio(field) {
1.190 albertel 7317: var slct=document.scantronupload.scantron_CODE_resolution;
1.188 albertel 7318: var i;
7319: for (i=0;i<slct.length;i++) {
7320: if (slct[i].value==field) { slct[i].checked=true; }
7321: }
7322: }
7323: ENDSCRIPT
1.187 albertel 7324: my $href="/adm/pickcode?".
1.359 www 7325: "form=".&escape("scantronupload").
7326: "&scantron_format=".&escape($env{'form.scantron_format'}).
7327: "&scantron_CODElist=".&escape($env{'form.scantron_CODElist'}).
7328: "&curCODE=".&escape($$scan_record{'scantron.CODE'}).
7329: "&scantron_selectfile=".&escape($env{'form.scantron_selectfile'});
1.332 albertel 7330: if ($env{'form.scantron_CODElist'} =~ /\S/) {
1.492 albertel 7331: $r->print("
7332: <label>
7333: <input type='radio' name='scantron_CODE_resolution' value='use_found' />
7334: ".&mt("[_1]Select[_2] a CODE from the list of all CODEs and use it.",
7335: "<a target='_blank' href='$href'>","</a>")."
7336: </label>
1.558 bisitz 7337: ".&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 7338: $r->print("\n<br />");
7339: }
1.492 albertel 7340: $r->print("
7341: <label>
7342: <input type='radio' name='scantron_CODE_resolution' value='use_typed' />
7343: ".&mt("Use [_1] as the CODE.",
7344: "</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 7345: $r->print("\n<br /><br />");
1.157 albertel 7346: } elsif ($error eq 'doublebubble') {
1.658 bisitz 7347: $r->print('<p class="LC_warning">'.&mt("There have been multiple bubbles scanned for some question(s)")."</p>\n");
1.497 foxr 7348:
7349: # The form field scantron_questions is acutally a list of line numbers.
7350: # represented by this form so:
7351:
1.691 raeburn 7352: my $line_list = &questions_to_line_list($arg,$randomorder,$randompick,
7353: $respnumlookup,$startline);
1.497 foxr 7354:
1.157 albertel 7355: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 7356: $line_list.'" />');
1.242 albertel 7357: $r->print($message);
1.492 albertel 7358: $r->print("<p>".&mt("Please indicate which bubble should be used for grading")."</p>");
1.157 albertel 7359: foreach my $question (@{$arg}) {
1.503 raeburn 7360: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
1.691 raeburn 7361: $scan_record, $error,
7362: $randomorder,$randompick,
7363: $respnumlookup,$startline);
1.524 raeburn 7364: push(@lines_to_correct,@linenums);
1.157 albertel 7365: }
1.503 raeburn 7366: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 7367: } elsif ($error eq 'missingbubble') {
1.658 bisitz 7368: $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 7369: $r->print($message);
1.492 albertel 7370: $r->print("<p>".&mt("Please indicate which bubble should be used for grading.")."</p>");
1.503 raeburn 7371: $r->print(&mt("Some questions have no scanned bubbles.")."\n");
1.497 foxr 7372:
1.503 raeburn 7373: # The form field scantron_questions is actually a list of line numbers not
1.497 foxr 7374: # a list of question numbers. Therefore:
7375: #
1.691 raeburn 7376:
7377: my $line_list = &questions_to_line_list($arg,$randomorder,$randompick,
7378: $respnumlookup,$startline);
1.497 foxr 7379:
1.157 albertel 7380: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 7381: $line_list.'" />');
1.157 albertel 7382: foreach my $question (@{$arg}) {
1.503 raeburn 7383: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
1.691 raeburn 7384: $scan_record, $error,
7385: $randomorder,$randompick,
7386: $respnumlookup,$startline);
1.524 raeburn 7387: push(@lines_to_correct,@linenums);
1.157 albertel 7388: }
1.503 raeburn 7389: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 7390: } else {
7391: $r->print("\n<ul>");
7392: }
7393: $r->print("\n</li></ul>");
1.497 foxr 7394: }
7395:
1.503 raeburn 7396: sub verify_bubbles_checked {
7397: my (@ansnums) = @_;
7398: my $ansnumstr = join('","',@ansnums);
7399: my $warning = &mt("A bubble or 'No bubble' selection has not been made for one or more lines.");
1.597 wenzelju 7400: my $output = &Apache::lonhtmlcommon::scripttag((<<ENDSCRIPT));
1.503 raeburn 7401: function verify_bubble_radio(form) {
7402: var ansnumArray = new Array ("$ansnumstr");
7403: var need_bubble_count = 0;
7404: for (var i=0; i<ansnumArray.length; i++) {
7405: if (form.elements["scantron_correct_Q_"+ansnumArray[i]].length > 1) {
7406: var bubble_picked = 0;
7407: for (var j=0; j<form.elements["scantron_correct_Q_"+ansnumArray[i]].length; j++) {
7408: if (form.elements["scantron_correct_Q_"+ansnumArray[i]][j].checked == true) {
7409: bubble_picked = 1;
7410: }
7411: }
7412: if (bubble_picked == 0) {
7413: need_bubble_count ++;
7414: }
7415: }
7416: }
7417: if (need_bubble_count) {
7418: alert("$warning");
7419: return;
7420: }
7421: form.submit();
7422: }
7423: ENDSCRIPT
7424: return $output;
7425: }
7426:
1.497 foxr 7427: =pod
7428:
7429: =item questions_to_line_list
1.157 albertel 7430:
1.497 foxr 7431: Converts a list of questions into a string of comma separated
7432: line numbers in the answer sheet used by the questions. This is
7433: used to fill in the scantron_questions form field.
7434:
7435: Arguments:
7436: questions - Reference to an array of questions.
1.691 raeburn 7437: randomorder - True if randomorder in use.
7438: randompick - True if randompick in use.
7439: respnumlookup - Reference to HASH mapping question numbers in bubble lines
7440: for current line to question number used for same question
7441: in "Master Seqence" (as seen by Course Coordinator).
7442: startline - Reference to hash where key is question number (0 is first)
7443: and key is number of first bubble line for current student
7444: or code-based randompick and/or randomorder.
1.693 raeburn 7445:
1.497 foxr 7446: =cut
7447:
7448:
7449: sub questions_to_line_list {
1.691 raeburn 7450: my ($questions,$randomorder,$randompick,$respnumlookup,$startline) = @_;
1.497 foxr 7451: my @lines;
7452:
1.503 raeburn 7453: foreach my $item (@{$questions}) {
7454: my $question = $item;
7455: my ($first,$count,$last);
7456: if ($item =~ /^(\d+)\.(\d+)$/) {
7457: $question = $1;
7458: my $subquestion = $2;
1.691 raeburn 7459: my $responsenum = $question-1;
7460: if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
7461: $responsenum = $respnumlookup->{$question-1};
7462: if (ref($startline) eq 'HASH') {
7463: $first = $startline->{$question-1} + 1;
7464: }
7465: } else {
7466: $first = $first_bubble_line{$responsenum} + 1;
7467: }
7468: my @subans = split(/,/,$subdivided_bubble_lines{$responsenum});
1.503 raeburn 7469: my $subcount = 1;
7470: while ($subcount<$subquestion) {
7471: $first += $subans[$subcount-1];
7472: $subcount ++;
7473: }
7474: $count = $subans[$subquestion-1];
7475: } else {
1.691 raeburn 7476: my $responsenum = $question-1;
7477: if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
7478: $responsenum = $respnumlookup->{$question-1};
7479: if (ref($startline) eq 'HASH') {
7480: $first = $startline->{$question-1} + 1;
7481: }
7482: } else {
7483: $first = $first_bubble_line{$responsenum} + 1;
7484: }
7485: $count = $bubble_lines_per_response{$responsenum};
1.503 raeburn 7486: }
1.506 raeburn 7487: $last = $first+$count-1;
1.503 raeburn 7488: push(@lines, ($first..$last));
1.497 foxr 7489: }
7490: return join(',', @lines);
7491: }
7492:
7493: =pod
7494:
7495: =item prompt_for_corrections
7496:
7497: Prompts for a potentially multiline correction to the
7498: user's bubbling (factors out common code from scantron_get_correction
7499: for multi and missing bubble cases).
7500:
7501: Arguments:
7502: $r - Apache request object.
7503: $question - The question number to prompt for.
7504: $scan_config - The scantron file configuration hash.
7505: $scan_record - Reference to the hash that has the the parsed scanlines.
1.503 raeburn 7506: $error - Type of error
1.691 raeburn 7507: $randomorder - True if randomorder in use.
7508: $randompick - True if randompick in use.
7509: $respnumlookup - Reference to HASH mapping question numbers in bubble lines
7510: for current line to question number used for same question
7511: in "Master Seqence" (as seen by Course Coordinator).
7512: $startline - Reference to hash where key is question number (0 is first)
7513: and value is number of first bubble line for current student
7514: or code-based randompick and/or randomorder.
7515:
1.497 foxr 7516:
7517: Implicit inputs:
7518: %bubble_lines_per_response - Starting line numbers for each question.
7519: Numbered from 0 (but question numbers are from
7520: 1.
7521: %first_bubble_line - Starting bubble line for each question.
1.509 raeburn 7522: %subdivided_bubble_lines - optionresponse, matchresponse and rankresponse
7523: type problems render as separate sub-questions,
1.503 raeburn 7524: in exam mode. This hash contains a
7525: comma-separated list of the lines per
7526: sub-question.
1.510 raeburn 7527: %responsetype_per_response - essayresponse, formularesponse,
7528: stringresponse, imageresponse, reactionresponse,
7529: and organicresponse type problem parts can have
1.503 raeburn 7530: multiple lines per response if the weight
7531: assigned exceeds 10. In this case, only
7532: one bubble per line is permitted, but more
7533: than one line might contain bubbles, e.g.
7534: bubbling of: line 1 - J, line 2 - J,
7535: line 3 - B would assign 22 points.
1.497 foxr 7536:
7537: =cut
7538:
7539: sub prompt_for_corrections {
1.691 raeburn 7540: my ($r, $question, $scan_config, $scan_record, $error, $randomorder,
7541: $randompick, $respnumlookup, $startline) = @_;
1.503 raeburn 7542: my ($current_line,$lines);
7543: my @linenums;
7544: my $questionnum = $question;
1.691 raeburn 7545: my ($first,$responsenum);
1.503 raeburn 7546: if ($question =~ /^(\d+)\.(\d+)$/) {
7547: $question = $1;
7548: my $subquestion = $2;
1.691 raeburn 7549: if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
7550: $responsenum = $respnumlookup->{$question-1};
7551: if (ref($startline) eq 'HASH') {
7552: $first = $startline->{$question-1};
7553: }
7554: } else {
7555: $responsenum = $question-1;
7556: $first = $first_bubble_line{$responsenum} + 1;
7557: }
7558: $current_line = $first + 1 ;
7559: my @subans = split(/,/,$subdivided_bubble_lines{$responsenum});
1.503 raeburn 7560: my $subcount = 1;
7561: while ($subcount<$subquestion) {
7562: $current_line += $subans[$subcount-1];
7563: $subcount ++;
7564: }
7565: $lines = $subans[$subquestion-1];
7566: } else {
1.691 raeburn 7567: if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
7568: $responsenum = $respnumlookup->{$question-1};
7569: if (ref($startline) eq 'HASH') {
7570: $first = $startline->{$question-1};
7571: }
7572: } else {
7573: $responsenum = $question-1;
7574: $first = $first_bubble_line{$responsenum};
7575: }
7576: $current_line = $first + 1;
7577: $lines = $bubble_lines_per_response{$responsenum};
1.503 raeburn 7578: }
1.497 foxr 7579: if ($lines > 1) {
1.503 raeburn 7580: $r->print(&mt('The group of bubble lines below responds to a single question.').'<br />');
1.691 raeburn 7581: if (($responsetype_per_response{$responsenum} eq 'essayresponse') ||
7582: ($responsetype_per_response{$responsenum} eq 'formularesponse') ||
7583: ($responsetype_per_response{$responsenum} eq 'stringresponse') ||
7584: ($responsetype_per_response{$responsenum} eq 'imageresponse') ||
7585: ($responsetype_per_response{$responsenum} eq 'reactionresponse') ||
7586: ($responsetype_per_response{$responsenum} eq 'organicresponse')) {
1.684 bisitz 7587: $r->print(
7588: &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)
7589: .'<br /><br />'
7590: .&mt('A non-zero score can be assigned to the student during bubblesheet grading by selecting a bubble in at least one line.')
7591: .'<br />'
7592: .&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.')
7593: .'<br />'
7594: .&mt("To assign a score of zero for this question, mark all lines as 'No bubble'.")
7595: .'<br /><br />'
7596: );
1.503 raeburn 7597: } else {
7598: $r->print(&mt("Select at most one bubble in a single line and select 'No Bubble' in all the other lines. ")."<br />");
7599: }
1.497 foxr 7600: }
7601: for (my $i =0; $i < $lines; $i++) {
1.503 raeburn 7602: my $selected = $$scan_record{"scantron.$current_line.answer"};
1.691 raeburn 7603: &scantron_bubble_selector($r,$scan_config,$current_line,
1.503 raeburn 7604: $questionnum,$error,split('', $selected));
1.524 raeburn 7605: push(@linenums,$current_line);
1.497 foxr 7606: $current_line++;
7607: }
7608: if ($lines > 1) {
7609: $r->print("<hr /><br />");
7610: }
1.503 raeburn 7611: return @linenums;
1.157 albertel 7612: }
1.423 albertel 7613:
7614: =pod
7615:
7616: =item scantron_bubble_selector
7617:
7618: Generates the html radiobuttons to correct a single bubble line
1.424 albertel 7619: possibly showing the existing the selected bubbles if known
1.423 albertel 7620:
7621: Arguments:
7622: $r - Apache request object
7623: $scan_config - hash from &get_scantron_config()
1.497 foxr 7624: $line - Number of the line being displayed.
1.503 raeburn 7625: $questionnum - Question number (may include subquestion)
7626: $error - Type of error.
1.497 foxr 7627: @selected - Array of bubbles picked on this line.
1.423 albertel 7628:
7629: =cut
7630:
1.157 albertel 7631: sub scantron_bubble_selector {
1.503 raeburn 7632: my ($r,$scan_config,$line,$questionnum,$error,@selected)=@_;
1.157 albertel 7633: my $max=$$scan_config{'Qlength'};
1.274 albertel 7634:
7635: my $scmode=$$scan_config{'Qon'};
1.649 raeburn 7636: if ($scmode eq 'number' || $scmode eq 'letter') {
7637: if (($$scan_config{'BubblesPerRow'} =~ /^\d+$/) &&
7638: ($$scan_config{'BubblesPerRow'} > 0)) {
7639: $max=$$scan_config{'BubblesPerRow'};
7640: if (($scmode eq 'number') && ($max > 10)) {
7641: $max = 10;
7642: } elsif (($scmode eq 'letter') && $max > 26) {
7643: $max = 26;
7644: }
7645: } else {
7646: $max = 10;
7647: }
7648: }
1.274 albertel 7649:
1.157 albertel 7650: my @alphabet=('A'..'Z');
1.503 raeburn 7651: $r->print(&Apache::loncommon::start_data_table().
7652: &Apache::loncommon::start_data_table_row());
7653: $r->print('<td rowspan="2" class="LC_leftcol_header">'.$line.'</td>');
1.497 foxr 7654: for (my $i=0;$i<$max+1;$i++) {
7655: $r->print("\n".'<td align="center">');
7656: if ($selected[0] eq $alphabet[$i]) { $r->print('X'); shift(@selected) }
7657: else { $r->print(' '); }
7658: $r->print('</td>');
7659: }
1.503 raeburn 7660: $r->print(&Apache::loncommon::end_data_table_row().
7661: &Apache::loncommon::start_data_table_row());
1.497 foxr 7662: for (my $i=0;$i<$max;$i++) {
7663: $r->print("\n".
7664: '<td><label><input type="radio" name="scantron_correct_Q_'.
7665: $line.'" value="'.$i.'" />'.$alphabet[$i]."</label></td>");
7666: }
1.503 raeburn 7667: my $nobub_checked = ' ';
7668: if ($error eq 'missingbubble') {
7669: $nobub_checked = ' checked = "checked" ';
7670: }
7671: $r->print("\n".'<td><label><input type="radio" name="scantron_correct_Q_'.
7672: $line.'" value="none"'.$nobub_checked.'/>'.&mt('No bubble').
7673: '</label>'."\n".'<input type="hidden" name="scantron_questionnum_Q_'.
7674: $line.'" value="'.$questionnum.'" /></td>');
7675: $r->print(&Apache::loncommon::end_data_table_row().
7676: &Apache::loncommon::end_data_table());
1.157 albertel 7677: }
7678:
1.423 albertel 7679: =pod
7680:
7681: =item num_matches
7682:
1.424 albertel 7683: Counts the number of characters that are the same between the two arguments.
7684:
7685: Arguments:
7686: $orig - CODE from the scanline
7687: $code - CODE to match against
7688:
7689: Returns:
7690: $count - integer count of the number of same characters between the
7691: two arguments
7692:
1.423 albertel 7693: =cut
7694:
1.194 albertel 7695: sub num_matches {
7696: my ($orig,$code) = @_;
7697: my @code=split(//,$code);
7698: my @orig=split(//,$orig);
7699: my $same=0;
7700: for (my $i=0;$i<scalar(@code);$i++) {
7701: if ($code[$i] eq $orig[$i]) { $same++; }
7702: }
7703: return $same;
7704: }
7705:
1.423 albertel 7706: =pod
7707:
7708: =item scantron_get_closely_matching_CODEs
7709:
1.424 albertel 7710: Cycles through all CODEs and finds the set that has the greatest
7711: number of same characters as the provided CODE
7712:
7713: Arguments:
7714: $allcodes - hash ref returned by &get_codes()
7715: $CODE - CODE from the current scanline
7716:
7717: Returns:
7718: 2 element list
7719: - first elements is number of how closely matching the best fit is
7720: (5 means best set has 5 matching characters)
7721: - second element is an arrary ref containing the set of valid CODEs
7722: that best fit the passed in CODE
7723:
1.423 albertel 7724: =cut
7725:
1.194 albertel 7726: sub scantron_get_closely_matching_CODEs {
7727: my ($allcodes,$CODE)=@_;
7728: my @CODEs;
7729: foreach my $testcode (sort(keys(%{$allcodes}))) {
7730: push(@{$CODEs[&num_matches($CODE,$testcode)]},$testcode);
7731: }
7732:
7733: return ($#CODEs,$CODEs[-1]);
7734: }
7735:
1.423 albertel 7736: =pod
7737:
7738: =item get_codes
7739:
1.424 albertel 7740: Builds a hash which has keys of all of the valid CODEs from the selected
7741: set of remembered CODEs.
7742:
7743: Arguments:
7744: $old_name - name of the set of remembered CODEs
7745: $cdom - domain of the course
7746: $cnum - internal course name
7747:
7748: Returns:
7749: %allcodes - keys are the valid CODEs, values are all 1
7750:
1.423 albertel 7751: =cut
7752:
1.194 albertel 7753: sub get_codes {
1.280 foxr 7754: my ($old_name, $cdom, $cnum) = @_;
7755: if (!$old_name) {
7756: $old_name=$env{'form.scantron_CODElist'};
7757: }
7758: if (!$cdom) {
7759: $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
7760: }
7761: if (!$cnum) {
7762: $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
7763: }
1.278 albertel 7764: my %result=&Apache::lonnet::get('CODEs',[$old_name,"type\0$old_name"],
7765: $cdom,$cnum);
7766: my %allcodes;
7767: if ($result{"type\0$old_name"} eq 'number') {
7768: %allcodes=map {($_,1)} split(',',$result{$old_name});
7769: } else {
7770: %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
7771: }
1.194 albertel 7772: return %allcodes;
7773: }
7774:
1.423 albertel 7775: =pod
7776:
7777: =item scantron_validate_CODE
7778:
1.424 albertel 7779: Validates all scanlines in the selected file to not have any
7780: invalid or underspecified CODEs and that none of the codes are
7781: duplicated if this was requested.
7782:
1.423 albertel 7783: =cut
7784:
1.157 albertel 7785: sub scantron_validate_CODE {
7786: my ($r,$currentphase) = @_;
1.257 albertel 7787: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.186 albertel 7788: if ($scantron_config{'CODElocation'} &&
7789: $scantron_config{'CODEstart'} &&
7790: $scantron_config{'CODElength'}) {
1.257 albertel 7791: if (!defined($env{'form.scantron_CODElist'})) {
1.186 albertel 7792: &FIXME_blow_up()
7793: }
7794: } else {
7795: return (0,$currentphase+1);
7796: }
7797:
7798: my %usedCODEs;
7799:
1.194 albertel 7800: my %allcodes=&get_codes();
1.186 albertel 7801:
1.582 raeburn 7802: my $nav_error;
1.649 raeburn 7803: &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the lines per response array.
1.582 raeburn 7804: if ($nav_error) {
7805: $r->print(&navmap_errormsg());
7806: return(1,$currentphase);
7807: }
1.447 foxr 7808:
1.186 albertel 7809: my ($scanlines,$scan_data)=&scantron_getfile();
7810: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7811: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.186 albertel 7812: if ($line=~/^[\s\cz]*$/) { next; }
7813: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7814: $scan_data);
7815: my $CODE=$$scan_record{'scantron.CODE'};
7816: my $error=0;
1.224 albertel 7817: if (!&Apache::lonnet::validCODE($CODE)) {
7818: &scantron_get_correction($r,$i,$scan_record,
7819: \%scantron_config,
7820: $line,'incorrectCODE',\%allcodes);
7821: return(1,$currentphase);
7822: }
1.221 albertel 7823: if (%allcodes && !exists($allcodes{$CODE})
7824: && !$$scan_record{'scantron.useCODE'}) {
1.186 albertel 7825: &scantron_get_correction($r,$i,$scan_record,
7826: \%scantron_config,
1.194 albertel 7827: $line,'incorrectCODE',\%allcodes);
7828: return(1,$currentphase);
1.186 albertel 7829: }
1.214 albertel 7830: if (exists($usedCODEs{$CODE})
1.257 albertel 7831: && $env{'form.scantron_CODEunique'} eq 'yes'
1.192 albertel 7832: && !$$scan_record{'scantron.CODE_ignore_dup'}) {
1.186 albertel 7833: &scantron_get_correction($r,$i,$scan_record,
7834: \%scantron_config,
1.194 albertel 7835: $line,'duplicateCODE',$usedCODEs{$CODE});
7836: return(1,$currentphase);
1.186 albertel 7837: }
1.524 raeburn 7838: push(@{$usedCODEs{$CODE}},$$scan_record{'scantron.PaperID'});
1.186 albertel 7839: }
1.157 albertel 7840: return (0,$currentphase+1);
7841: }
7842:
1.423 albertel 7843: =pod
7844:
7845: =item scantron_validate_doublebubble
7846:
1.424 albertel 7847: Validates all scanlines in the selected file to not have any
7848: bubble lines with multiple bubbles marked.
7849:
1.423 albertel 7850: =cut
7851:
1.157 albertel 7852: sub scantron_validate_doublebubble {
7853: my ($r,$currentphase) = @_;
7854: #get student info
7855: my $classlist=&Apache::loncoursedata::get_classlist();
7856: my %idmap=&username_to_idmap($classlist);
1.691 raeburn 7857: my (undef,undef,$sequence)=
7858: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.157 albertel 7859:
7860: #get scantron line setup
1.257 albertel 7861: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7862: my ($scanlines,$scan_data)=&scantron_getfile();
1.691 raeburn 7863:
7864: my $navmap = Apache::lonnavmaps::navmap->new();
7865: unless (ref($navmap)) {
7866: $r->print(&navmap_errormsg());
7867: return(1,$currentphase);
7868: }
7869: my $map=$navmap->getResourceByUrl($sequence);
7870: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
7871: my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
7872: %grader_randomlists_by_symb,%orderedforcode,%respnumlookup,%startline);
7873: my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
7874:
1.583 raeburn 7875: my $nav_error;
1.691 raeburn 7876: if (ref($map)) {
7877: $randomorder = $map->randomorder();
7878: $randompick = $map->randompick();
7879: if ($randomorder || $randompick) {
7880: $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource);
7881: if ($nav_error) {
7882: $r->print(&navmap_errormsg());
7883: return(1,$currentphase);
7884: }
7885: &graders_resources_pass(\@resources,\%grader_partids_by_symb,
7886: \%grader_randomlists_by_symb,$bubbles_per_row);
7887: }
7888: } else {
7889: $r->print(&navmap_errormsg());
7890: return(1,$currentphase);
7891: }
7892:
1.649 raeburn 7893: &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the bubble line array.
1.583 raeburn 7894: if ($nav_error) {
7895: $r->print(&navmap_errormsg());
7896: return(1,$currentphase);
7897: }
1.447 foxr 7898:
1.157 albertel 7899: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7900: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7901: if ($line=~/^[\s\cz]*$/) { next; }
7902: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
1.691 raeburn 7903: $scan_data,undef,\%idmap,$randomorder,
7904: $randompick,$sequence,\@master_seq,
7905: \%symb_to_resource,\%grader_partids_by_symb,
7906: \%orderedforcode,\%respnumlookup,\%startline);
1.157 albertel 7907: if (!defined($$scan_record{'scantron.doubleerror'})) { next; }
7908: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,$line,
7909: 'doublebubble',
1.691 raeburn 7910: $$scan_record{'scantron.doubleerror'},
7911: $randomorder,$randompick,\%respnumlookup,\%startline);
1.157 albertel 7912: return (1,$currentphase);
7913: }
7914: return (0,$currentphase+1);
7915: }
7916:
1.423 albertel 7917:
1.503 raeburn 7918: sub scantron_get_maxbubble {
1.649 raeburn 7919: my ($nav_error,$scantron_config) = @_;
1.257 albertel 7920: if (defined($env{'form.scantron_maxbubble'}) &&
7921: $env{'form.scantron_maxbubble'}) {
1.447 foxr 7922: &restore_bubble_lines();
1.257 albertel 7923: return $env{'form.scantron_maxbubble'};
1.191 albertel 7924: }
1.330 albertel 7925:
1.447 foxr 7926: my (undef, undef, $sequence) =
1.257 albertel 7927: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.330 albertel 7928:
1.447 foxr 7929: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 7930: unless (ref($navmap)) {
7931: if (ref($nav_error)) {
7932: $$nav_error = 1;
7933: }
1.591 raeburn 7934: return;
1.582 raeburn 7935: }
1.191 albertel 7936: my $map=$navmap->getResourceByUrl($sequence);
7937: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.649 raeburn 7938: my $bubbles_per_row = &bubblesheet_bubbles_per_row($scantron_config);
1.330 albertel 7939:
7940: &Apache::lonxml::clear_problem_counter();
7941:
1.557 raeburn 7942: my $uname = $env{'user.name'};
7943: my $udom = $env{'user.domain'};
1.435 foxr 7944: my $cid = $env{'request.course.id'};
7945: my $total_lines = 0;
7946: %bubble_lines_per_response = ();
1.447 foxr 7947: %first_bubble_line = ();
1.503 raeburn 7948: %subdivided_bubble_lines = ();
7949: %responsetype_per_response = ();
1.691 raeburn 7950: %masterseq_id_responsenum = ();
1.554 raeburn 7951:
1.447 foxr 7952: my $response_number = 0;
7953: my $bubble_line = 0;
1.191 albertel 7954: foreach my $resource (@resources) {
1.691 raeburn 7955: my $resid = $resource->id();
1.672 raeburn 7956: my ($analysis,$parts) = &scantron_partids_tograde($resource,$cid,$uname,
7957: $udom,undef,$bubbles_per_row);
1.542 raeburn 7958: if ((ref($analysis) eq 'HASH') && (ref($parts) eq 'ARRAY')) {
7959: foreach my $part_id (@{$parts}) {
7960: my $lines;
7961:
7962: # TODO - make this a persistent hash not an array.
7963:
7964: # optionresponse, matchresponse and rankresponse type items
7965: # render as separate sub-questions in exam mode.
7966: if (($analysis->{$part_id.'.type'} eq 'optionresponse') ||
7967: ($analysis->{$part_id.'.type'} eq 'matchresponse') ||
7968: ($analysis->{$part_id.'.type'} eq 'rankresponse')) {
7969: my ($numbub,$numshown);
7970: if ($analysis->{$part_id.'.type'} eq 'optionresponse') {
7971: if (ref($analysis->{$part_id.'.options'}) eq 'ARRAY') {
7972: $numbub = scalar(@{$analysis->{$part_id.'.options'}});
7973: }
7974: } elsif ($analysis->{$part_id.'.type'} eq 'matchresponse') {
7975: if (ref($analysis->{$part_id.'.items'}) eq 'ARRAY') {
7976: $numbub = scalar(@{$analysis->{$part_id.'.items'}});
7977: }
7978: } elsif ($analysis->{$part_id.'.type'} eq 'rankresponse') {
7979: if (ref($analysis->{$part_id.'.foils'}) eq 'ARRAY') {
7980: $numbub = scalar(@{$analysis->{$part_id.'.foils'}});
7981: }
7982: }
7983: if (ref($analysis->{$part_id.'.shown'}) eq 'ARRAY') {
7984: $numshown = scalar(@{$analysis->{$part_id.'.shown'}});
7985: }
1.649 raeburn 7986: my $bubbles_per_row =
7987: &bubblesheet_bubbles_per_row($scantron_config);
7988: my $inner_bubble_lines = int($numbub/$bubbles_per_row);
7989: if (($numbub % $bubbles_per_row) != 0) {
1.542 raeburn 7990: $inner_bubble_lines++;
7991: }
7992: for (my $i=0; $i<$numshown; $i++) {
7993: $subdivided_bubble_lines{$response_number} .=
7994: $inner_bubble_lines.',';
7995: }
7996: $subdivided_bubble_lines{$response_number} =~ s/,$//;
7997: $lines = $numshown * $inner_bubble_lines;
7998: } else {
7999: $lines = $analysis->{"$part_id.bubble_lines"};
1.649 raeburn 8000: }
1.542 raeburn 8001:
8002: $first_bubble_line{$response_number} = $bubble_line;
8003: $bubble_lines_per_response{$response_number} = $lines;
8004: $responsetype_per_response{$response_number} =
8005: $analysis->{$part_id.'.type'};
1.691 raeburn 8006: $masterseq_id_responsenum{$resid.'_'.$part_id} = $response_number;
1.542 raeburn 8007: $response_number++;
8008:
8009: $bubble_line += $lines;
8010: $total_lines += $lines;
8011: }
8012: }
8013: }
1.552 raeburn 8014: &Apache::lonnet::delenv('scantron.');
1.542 raeburn 8015:
8016: &save_bubble_lines();
8017: $env{'form.scantron_maxbubble'} =
8018: $total_lines;
8019: return $env{'form.scantron_maxbubble'};
8020: }
1.523 raeburn 8021:
1.649 raeburn 8022: sub bubblesheet_bubbles_per_row {
8023: my ($scantron_config) = @_;
8024: my $bubbles_per_row;
8025: if (ref($scantron_config) eq 'HASH') {
8026: $bubbles_per_row = $scantron_config->{'BubblesPerRow'};
8027: }
8028: if ((!$bubbles_per_row) || ($bubbles_per_row < 1)) {
8029: $bubbles_per_row = 10;
8030: }
8031: return $bubbles_per_row;
8032: }
8033:
1.157 albertel 8034: sub scantron_validate_missingbubbles {
8035: my ($r,$currentphase) = @_;
8036: #get student info
8037: my $classlist=&Apache::loncoursedata::get_classlist();
8038: my %idmap=&username_to_idmap($classlist);
1.691 raeburn 8039: my (undef,undef,$sequence)=
8040: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.157 albertel 8041:
8042: #get scantron line setup
1.257 albertel 8043: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 8044: my ($scanlines,$scan_data)=&scantron_getfile();
1.691 raeburn 8045:
8046: my $navmap = Apache::lonnavmaps::navmap->new();
8047: unless (ref($navmap)) {
8048: $r->print(&navmap_errormsg());
8049: return(1,$currentphase);
8050: }
8051:
8052: my $map=$navmap->getResourceByUrl($sequence);
8053: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
8054: my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
8055: %grader_randomlists_by_symb,%orderedforcode,%respnumlookup,%startline);
8056: my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
8057:
1.582 raeburn 8058: my $nav_error;
1.691 raeburn 8059: if (ref($map)) {
8060: $randomorder = $map->randomorder();
8061: $randompick = $map->randompick();
8062: if ($randomorder || $randompick) {
8063: $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource);
8064: if ($nav_error) {
8065: $r->print(&navmap_errormsg());
8066: return(1,$currentphase);
8067: }
8068: &graders_resources_pass(\@resources,\%grader_partids_by_symb,
8069: \%grader_randomlists_by_symb,$bubbles_per_row);
8070: }
8071: } else {
8072: $r->print(&navmap_errormsg());
8073: return(1,$currentphase);
8074: }
8075:
8076:
1.649 raeburn 8077: my $max_bubble=&scantron_get_maxbubble(\$nav_error,\%scantron_config);
1.582 raeburn 8078: if ($nav_error) {
1.691 raeburn 8079: $r->print(&navmap_errormsg());
1.693 raeburn 8080: return(1,$currentphase);
1.582 raeburn 8081: }
1.691 raeburn 8082:
1.157 albertel 8083: if (!$max_bubble) { $max_bubble=2**31; }
8084: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 8085: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 8086: if ($line=~/^[\s\cz]*$/) { next; }
1.691 raeburn 8087: my $scan_record =
8088: &scantron_parse_scanline($line,$i,\%scantron_config,$scan_data,undef,\%idmap,
8089: $randomorder,$randompick,$sequence,\@master_seq,
8090: \%symb_to_resource,\%grader_partids_by_symb,
8091: \%orderedforcode,\%respnumlookup,\%startline);
1.157 albertel 8092: if (!defined($$scan_record{'scantron.missingerror'})) { next; }
8093: my @to_correct;
1.470 foxr 8094:
8095: # Probably here's where the error is...
8096:
1.157 albertel 8097: foreach my $missing (@{$$scan_record{'scantron.missingerror'}}) {
1.505 raeburn 8098: my $lastbubble;
8099: if ($missing =~ /^(\d+)\.(\d+)$/) {
8100: my $question = $1;
8101: my $subquestion = $2;
1.691 raeburn 8102: my ($first,$responsenum);
8103: if ($randomorder || $randompick) {
8104: $responsenum = $respnumlookup{$question-1};
8105: $first = $startline{$question-1};
8106: } else {
8107: $responsenum = $question-1;
8108: $first = $first_bubble_line{$responsenum};
8109: }
8110: if (!defined($first)) { next; }
8111: my @subans = split(/,/,$subdivided_bubble_lines{$responsenum});
1.505 raeburn 8112: my $subcount = 1;
8113: while ($subcount<$subquestion) {
8114: $first += $subans[$subcount-1];
8115: $subcount ++;
8116: }
8117: my $count = $subans[$subquestion-1];
8118: $lastbubble = $first + $count;
8119: } else {
1.691 raeburn 8120: my ($first,$responsenum);
8121: if ($randomorder || $randompick) {
8122: $responsenum = $respnumlookup{$missing-1};
8123: $first = $startline{$missing-1};
8124: } else {
8125: $responsenum = $missing-1;
8126: $first = $first_bubble_line{$responsenum};
8127: }
8128: if (!defined($first)) { next; }
8129: $lastbubble = $first + $bubble_lines_per_response{$responsenum};
1.505 raeburn 8130: }
8131: if ($lastbubble > $max_bubble) { next; }
1.157 albertel 8132: push(@to_correct,$missing);
8133: }
8134: if (@to_correct) {
8135: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
1.691 raeburn 8136: $line,'missingbubble',\@to_correct,
8137: $randomorder,$randompick,\%respnumlookup,
8138: \%startline);
1.157 albertel 8139: return (1,$currentphase);
8140: }
8141:
8142: }
8143: return (0,$currentphase+1);
8144: }
8145:
1.663 raeburn 8146: sub hand_bubble_option {
8147: my (undef, undef, $sequence) =
8148: &Apache::lonnet::decode_symb($env{'form.selectpage'});
8149: return if ($sequence eq '');
8150: my $navmap = Apache::lonnavmaps::navmap->new();
8151: unless (ref($navmap)) {
8152: return;
8153: }
8154: my $needs_hand_bubbles;
8155: my $map=$navmap->getResourceByUrl($sequence);
8156: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
8157: foreach my $res (@resources) {
8158: if (ref($res)) {
8159: if ($res->is_problem()) {
8160: my $partlist = $res->parts();
8161: foreach my $part (@{ $partlist }) {
8162: my @types = $res->responseType($part);
8163: if (grep(/^(chem|essay|image|formula|math|string|functionplot)$/,@types)) {
8164: $needs_hand_bubbles = 1;
8165: last;
8166: }
8167: }
8168: }
8169: }
8170: }
8171: if ($needs_hand_bubbles) {
8172: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
8173: my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
8174: return &mt('The sequence to be graded contains response types which are handgraded.').'<p>'.
8175: &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 />').
8176: '<label><input type="radio" name="scantron_lastbubblepoints" value="'.$bubbles_per_row.'" checked="checked" />'.&mt('[quant,_1,point]',$bubbles_per_row).'</label> '.&mt('or').' '.
8177: '<label><input type="radio" name="scantron_lastbubblepoints" value="0"/>0 points</label></p>';
8178: }
8179: return;
8180: }
1.423 albertel 8181:
1.82 albertel 8182: sub scantron_process_students {
1.608 www 8183: my ($r,$symb) = @_;
1.513 foxr 8184:
1.257 albertel 8185: my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($env{'form.selectpage'});
1.513 foxr 8186: if (!$symb) {
8187: return '';
8188: }
1.324 albertel 8189: my $default_form_data=&defaultFormData($symb);
1.82 albertel 8190:
1.257 albertel 8191: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.691 raeburn 8192: my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
1.157 albertel 8193: my ($scanlines,$scan_data)=&scantron_getfile();
1.82 albertel 8194: my $classlist=&Apache::loncoursedata::get_classlist();
8195: my %idmap=&username_to_idmap($classlist);
1.132 bowersj2 8196: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 8197: unless (ref($navmap)) {
8198: $r->print(&navmap_errormsg());
8199: return '';
1.691 raeburn 8200: }
1.83 albertel 8201: my $map=$navmap->getResourceByUrl($sequence);
1.691 raeburn 8202: my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
1.693 raeburn 8203: %grader_randomlists_by_symb);
1.677 raeburn 8204: if (ref($map)) {
8205: $randomorder = $map->randomorder();
1.689 raeburn 8206: $randompick = $map->randompick();
1.691 raeburn 8207: } else {
8208: $r->print(&navmap_errormsg());
8209: return '';
1.677 raeburn 8210: }
1.691 raeburn 8211: my $nav_error;
1.83 albertel 8212: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.691 raeburn 8213: if ($randomorder || $randompick) {
8214: $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource);
8215: if ($nav_error) {
8216: $r->print(&navmap_errormsg());
8217: return '';
8218: }
8219: }
1.557 raeburn 8220: &graders_resources_pass(\@resources,\%grader_partids_by_symb,
1.649 raeburn 8221: \%grader_randomlists_by_symb,$bubbles_per_row);
1.557 raeburn 8222:
1.554 raeburn 8223: my ($uname,$udom);
1.82 albertel 8224: my $result= <<SCANTRONFORM;
1.81 albertel 8225: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
8226: <input type="hidden" name="command" value="scantron_configphase" />
8227: $default_form_data
8228: SCANTRONFORM
1.82 albertel 8229: $r->print($result);
8230:
8231: my @delayqueue;
1.542 raeburn 8232: my (%completedstudents,%scandata);
1.140 albertel 8233:
1.520 www 8234: my $lock=&Apache::lonnet::set_lock(&mt('Grading bubblesheet exam'));
1.200 albertel 8235: my $count=&get_todo_count($scanlines,$scan_data);
1.667 www 8236: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$count);
8237: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,'Processing first student');
1.542 raeburn 8238: $r->print('<br />');
1.140 albertel 8239: my $start=&Time::HiRes::time();
1.158 albertel 8240: my $i=-1;
1.542 raeburn 8241: my $started;
1.447 foxr 8242:
1.649 raeburn 8243: &scantron_get_maxbubble(\$nav_error,\%scantron_config); # Need the bubble lines array to parse.
1.582 raeburn 8244: if ($nav_error) {
8245: $r->print(&navmap_errormsg());
8246: return '';
8247: }
8248:
1.513 foxr 8249: # If an ssi failed in scantron_get_maxbubble, put an error message out to
8250: # the user and return.
8251:
8252: if ($ssi_error) {
8253: $r->print("</form>");
8254: &ssi_print_error($r);
1.520 www 8255: &Apache::lonnet::remove_lock($lock);
1.513 foxr 8256: return ''; # Dunno why the other returns return '' rather than just returning.
8257: }
1.447 foxr 8258:
1.542 raeburn 8259: my %lettdig = &letter_to_digits();
8260: my $numletts = scalar(keys(%lettdig));
1.691 raeburn 8261: my %orderedforcode;
1.542 raeburn 8262:
1.157 albertel 8263: while ($i<$scanlines->{'count'}) {
8264: ($uname,$udom)=('','');
8265: $i++;
1.200 albertel 8266: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 8267: if ($line=~/^[\s\cz]*$/) { next; }
1.200 albertel 8268: if ($started) {
1.667 www 8269: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student');
1.200 albertel 8270: }
8271: $started=1;
1.691 raeburn 8272: my %respnumlookup = ();
8273: my %startline = ();
8274: my $total;
1.157 albertel 8275: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
1.691 raeburn 8276: $scan_data,undef,\%idmap,$randomorder,
8277: $randompick,$sequence,\@master_seq,
8278: \%symb_to_resource,\%grader_partids_by_symb,
8279: \%orderedforcode,\%respnumlookup,\%startline,
8280: \$total);
1.157 albertel 8281: unless ($uname=&scantron_find_student($scan_record,$scan_data,
8282: \%idmap,$i)) {
8283: &scantron_add_delay(\@delayqueue,$line,
8284: 'Unable to find a student that matches',1);
8285: next;
8286: }
8287: if (exists $completedstudents{$uname}) {
8288: &scantron_add_delay(\@delayqueue,$line,
8289: 'Student '.$uname.' has multiple sheets',2);
8290: next;
8291: }
1.677 raeburn 8292: my $usec = $classlist->{$uname}->[&Apache::loncoursedata::CL_SECTION];
8293: my $user = $uname.':'.$usec;
1.157 albertel 8294: ($uname,$udom)=split(/:/,$uname);
1.330 albertel 8295:
1.677 raeburn 8296: my $scancode;
8297: if ((exists($scan_record->{'scantron.CODE'})) &&
8298: (&Apache::lonnet::validCODE($scan_record->{'scantron.CODE'}))) {
8299: $scancode = $scan_record->{'scantron.CODE'};
8300: } else {
8301: $scancode = '';
8302: }
8303:
8304: my @mapresources = @resources;
1.689 raeburn 8305: if ($randomorder || $randompick) {
1.678 raeburn 8306: @mapresources =
1.691 raeburn 8307: &users_order($user,$scancode,$sequence,\@master_seq,\%symb_to_resource,
8308: \%orderedforcode);
1.677 raeburn 8309: }
1.586 raeburn 8310: my (%partids_by_symb,$res_error);
1.677 raeburn 8311: foreach my $resource (@mapresources) {
1.586 raeburn 8312: my $ressymb;
8313: if (ref($resource)) {
8314: $ressymb = $resource->symb();
8315: } else {
8316: $res_error = 1;
8317: last;
8318: }
1.557 raeburn 8319: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
8320: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
8321: my ($analysis,$parts) =
1.672 raeburn 8322: &scantron_partids_tograde($resource,$env{'request.course.id'},
8323: $uname,$udom,undef,$bubbles_per_row);
1.557 raeburn 8324: $partids_by_symb{$ressymb} = $parts;
8325: } else {
8326: $partids_by_symb{$ressymb} = $grader_partids_by_symb{$ressymb};
8327: }
1.554 raeburn 8328: }
8329:
1.586 raeburn 8330: if ($res_error) {
8331: &scantron_add_delay(\@delayqueue,$line,
8332: 'An error occurred while grading student '.$uname,2);
8333: next;
8334: }
8335:
1.330 albertel 8336: &Apache::lonxml::clear_problem_counter();
1.514 raeburn 8337: &Apache::lonnet::appenv($scan_record);
1.376 albertel 8338:
8339: if (&scantron_clear_skip($scanlines,$scan_data,$i)) {
8340: &scantron_putfile($scanlines,$scan_data);
8341: }
1.161 albertel 8342:
1.542 raeburn 8343: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
1.677 raeburn 8344: \@mapresources,\%partids_by_symb,
1.691 raeburn 8345: $bubbles_per_row,$randomorder,$randompick,
8346: \%respnumlookup,\%startline)
8347: eq 'ssi_error') {
1.542 raeburn 8348: $ssi_error = 0; # So end of handler error message does not trigger.
8349: $r->print("</form>");
8350: &ssi_print_error($r);
8351: &Apache::lonnet::remove_lock($lock);
8352: return ''; # Why return ''? Beats me.
8353: }
1.513 foxr 8354:
1.692 raeburn 8355: if (($scancode) && ($randomorder || $randompick)) {
8356: my $parmresult =
8357: &Apache::lonparmset::storeparm_by_symb($symb,
8358: '0_examcode',2,$scancode,
8359: 'string_examcode',$uname,
8360: $udom);
8361: }
1.140 albertel 8362: $completedstudents{$uname}={'line'=>$line};
1.542 raeburn 8363: if ($env{'form.verifyrecord'}) {
8364: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
1.691 raeburn 8365: if ($randompick) {
8366: if ($total) {
8367: $lastpos = $total*$scantron_config{'Qlength'};
8368: }
8369: }
8370:
1.542 raeburn 8371: my $studentdata = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
8372: chomp($studentdata);
8373: $studentdata =~ s/\r$//;
8374: my $studentrecord = '';
8375: my $counter = -1;
1.677 raeburn 8376: foreach my $resource (@mapresources) {
1.554 raeburn 8377: my $ressymb = $resource->symb();
1.542 raeburn 8378: ($counter,my $recording) =
8379: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 8380: $counter,$studentdata,$partids_by_symb{$ressymb},
1.691 raeburn 8381: \%scantron_config,\%lettdig,$numletts,$randomorder,
8382: $randompick,\%respnumlookup,\%startline);
1.542 raeburn 8383: $studentrecord .= $recording;
8384: }
8385: if ($studentrecord ne $studentdata) {
1.554 raeburn 8386: &Apache::lonxml::clear_problem_counter();
8387: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
1.677 raeburn 8388: \@mapresources,\%partids_by_symb,
1.691 raeburn 8389: $bubbles_per_row,$randomorder,$randompick,
8390: \%respnumlookup,\%startline)
8391: eq 'ssi_error') {
1.554 raeburn 8392: $ssi_error = 0; # So end of handler error message does not trigger.
8393: $r->print("</form>");
8394: &ssi_print_error($r);
8395: &Apache::lonnet::remove_lock($lock);
8396: delete($completedstudents{$uname});
8397: return '';
8398: }
1.542 raeburn 8399: $counter = -1;
8400: $studentrecord = '';
1.677 raeburn 8401: foreach my $resource (@mapresources) {
1.554 raeburn 8402: my $ressymb = $resource->symb();
1.542 raeburn 8403: ($counter,my $recording) =
8404: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 8405: $counter,$studentdata,$partids_by_symb{$ressymb},
1.691 raeburn 8406: \%scantron_config,\%lettdig,$numletts,
8407: $randomorder,$randompick,\%respnumlookup,
8408: \%startline);
1.542 raeburn 8409: $studentrecord .= $recording;
8410: }
8411: if ($studentrecord ne $studentdata) {
1.658 bisitz 8412: $r->print('<p><span class="LC_warning">');
1.542 raeburn 8413: if ($scancode eq '') {
1.658 bisitz 8414: $r->print(&mt('Mismatch grading bubblesheet for user: [_1] with ID: [_2].',
1.542 raeburn 8415: $uname.':'.$udom,$scan_record->{'scantron.ID'}));
8416: } else {
1.658 bisitz 8417: $r->print(&mt('Mismatch grading bubblesheet for user: [_1] with ID: [_2] and CODE: [_3].',
1.542 raeburn 8418: $uname.':'.$udom,$scan_record->{'scantron.ID'},$scancode));
8419: }
8420: $r->print('</span><br />'.&Apache::loncommon::start_data_table()."\n".
8421: &Apache::loncommon::start_data_table_header_row()."\n".
8422: '<th>'.&mt('Source').'</th><th>'.&mt('Bubbled responses').'</th>'.
8423: &Apache::loncommon::end_data_table_header_row()."\n".
8424: &Apache::loncommon::start_data_table_row().
1.658 bisitz 8425: '<td>'.&mt('Bubblesheet').'</td>'.
8426: '<td><span class="LC_nobreak"><tt>'.$studentdata.'</tt></span></td>'.
1.542 raeburn 8427: &Apache::loncommon::end_data_table_row().
8428: &Apache::loncommon::start_data_table_row().
1.658 bisitz 8429: '<td>'.&mt('Stored submissions').'</td>'.
8430: '<td><span class="LC_nobreak"><tt>'.$studentrecord.'</tt></span></td>'."\n".
1.542 raeburn 8431: &Apache::loncommon::end_data_table_row().
8432: &Apache::loncommon::end_data_table().'</p>');
8433: } else {
8434: $r->print('<br /><span class="LC_warning">'.
8435: &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 />'.
8436: &mt("As a consequence, this user's submission history records two tries.").
8437: '</span><br />');
8438: }
8439: }
8440: }
1.543 raeburn 8441: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.140 albertel 8442: } continue {
1.330 albertel 8443: &Apache::lonxml::clear_problem_counter();
1.552 raeburn 8444: &Apache::lonnet::delenv('scantron.');
1.82 albertel 8445: }
1.140 albertel 8446: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.520 www 8447: &Apache::lonnet::remove_lock($lock);
1.172 albertel 8448: # my $lasttime = &Time::HiRes::time()-$start;
8449: # $r->print("<p>took $lasttime</p>");
1.140 albertel 8450:
1.200 albertel 8451: $r->print("</form>");
1.157 albertel 8452: return '';
1.75 albertel 8453: }
1.157 albertel 8454:
1.557 raeburn 8455: sub graders_resources_pass {
1.649 raeburn 8456: my ($resources,$grader_partids_by_symb,$grader_randomlists_by_symb,
8457: $bubbles_per_row) = @_;
1.557 raeburn 8458: if ((ref($resources) eq 'ARRAY') && (ref($grader_partids_by_symb)) &&
8459: (ref($grader_randomlists_by_symb) eq 'HASH')) {
8460: foreach my $resource (@{$resources}) {
8461: my $ressymb = $resource->symb();
8462: my ($analysis,$parts) =
8463: &scantron_partids_tograde($resource,$env{'request.course.id'},
1.672 raeburn 8464: $env{'user.name'},$env{'user.domain'},
8465: 1,$bubbles_per_row);
1.557 raeburn 8466: $grader_partids_by_symb->{$ressymb} = $parts;
8467: if (ref($analysis) eq 'HASH') {
8468: if (ref($analysis->{'parts_withrandomlist'}) eq 'ARRAY') {
8469: $grader_randomlists_by_symb->{$ressymb} =
8470: $analysis->{'parts_withrandomlist'};
8471: }
8472: }
8473: }
8474: }
8475: return;
8476: }
8477:
1.678 raeburn 8478: =pod
8479:
8480: =item users_order
8481:
8482: Returns array of resources in current map, ordered based on either CODE,
8483: if this is a CODEd exam, or based on student's identity if this is a
8484: "NAMEd" exam.
8485:
1.691 raeburn 8486: Should be used when randomorder and/or randompick applied when the
8487: corresponding exam was printed, prior to students completing bubblesheets
8488: for the version of the exam the student received.
1.678 raeburn 8489:
8490: =cut
8491:
8492: sub users_order {
1.691 raeburn 8493: my ($user,$scancode,$mapurl,$master_seq,$symb_to_resource,$orderedforcode) = @_;
1.678 raeburn 8494: my @mapresources;
1.691 raeburn 8495: unless ((ref($master_seq) eq 'ARRAY') && (ref($symb_to_resource) eq 'HASH')) {
1.678 raeburn 8496: return @mapresources;
1.691 raeburn 8497: }
8498: if ($scancode) {
8499: if ((ref($orderedforcode) eq 'HASH') && (ref($orderedforcode->{$scancode}) eq 'ARRAY')) {
8500: @mapresources = @{$orderedforcode->{$scancode}};
8501: } else {
8502: $env{'form.CODE'} = $scancode;
8503: my $actual_seq =
8504: &Apache::lonprintout::master_seq_to_person_seq($mapurl,
8505: $master_seq,
8506: $user,$scancode,1);
8507: if (ref($actual_seq) eq 'ARRAY') {
8508: @mapresources = map { $symb_to_resource->{$_}; } @{$actual_seq};
8509: if (ref($orderedforcode) eq 'HASH') {
8510: if (@mapresources > 0) {
8511: $orderedforcode->{$scancode} = \@mapresources;
8512: }
8513: }
8514: }
8515: delete($env{'form.CODE'});
1.678 raeburn 8516: }
8517: } else {
8518: my $actual_seq =
8519: &Apache::lonprintout::master_seq_to_person_seq($mapurl,
8520: $master_seq,
1.688 raeburn 8521: $user,undef,1);
1.678 raeburn 8522: if (ref($actual_seq) eq 'ARRAY') {
8523: @mapresources =
8524: map { $symb_to_resource->{$_}; } @{$actual_seq};
8525: }
1.691 raeburn 8526: }
8527: return @mapresources;
1.678 raeburn 8528: }
8529:
1.542 raeburn 8530: sub grade_student_bubbles {
1.691 raeburn 8531: my ($r,$uname,$udom,$scan_record,$scancode,$resources,$parts,$bubbles_per_row,
8532: $randomorder,$randompick,$respnumlookup,$startline) = @_;
8533: my $uselookup = 0;
8534: if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH') &&
8535: (ref($startline) eq 'HASH')) {
8536: $uselookup = 1;
8537: }
8538:
1.554 raeburn 8539: if (ref($resources) eq 'ARRAY') {
8540: my $count = 0;
8541: foreach my $resource (@{$resources}) {
8542: my $ressymb = $resource->symb();
8543: my %form = ('submitted' => 'scantron',
8544: 'grade_target' => 'grade',
8545: 'grade_username' => $uname,
8546: 'grade_domain' => $udom,
8547: 'grade_courseid' => $env{'request.course.id'},
8548: 'grade_symb' => $ressymb,
8549: 'CODE' => $scancode
8550: );
1.649 raeburn 8551: if ($bubbles_per_row ne '') {
8552: $form{'bubbles_per_row'} = $bubbles_per_row;
8553: }
1.663 raeburn 8554: if ($env{'form.scantron_lastbubblepoints'} ne '') {
8555: $form{'scantron_lastbubblepoints'} = $env{'form.scantron_lastbubblepoints'};
8556: }
1.554 raeburn 8557: if (ref($parts) eq 'HASH') {
8558: if (ref($parts->{$ressymb}) eq 'ARRAY') {
8559: foreach my $part (@{$parts->{$ressymb}}) {
1.691 raeburn 8560: if ($uselookup) {
8561: $form{'scantron_questnum_start.'.$part} = $startline->{$count} + 1;
8562: } else {
8563: $form{'scantron_questnum_start.'.$part} =
8564: 1+$env{'form.scantron.first_bubble_line.'.$count};
8565: }
1.554 raeburn 8566: $count++;
8567: }
8568: }
8569: }
8570: my $result=&ssi_with_retries($resource->src(),$ssi_retries,%form);
8571: return 'ssi_error' if ($ssi_error);
8572: last if (&Apache::loncommon::connection_aborted($r));
8573: }
1.542 raeburn 8574: }
8575: return;
8576: }
8577:
1.157 albertel 8578: sub scantron_upload_scantron_data {
1.608 www 8579: my ($r,$symb)=@_;
1.565 raeburn 8580: my $dom = $env{'request.role.domain'};
8581: my $domdesc = &Apache::lonnet::domain($dom,'description');
8582: $r->print(&Apache::loncommon::coursebrowser_javascript($dom));
1.157 albertel 8583: my $select_link=&Apache::loncommon::selectcourse_link('rules','courseid',
1.181 albertel 8584: 'domainid',
1.565 raeburn 8585: 'coursename',$dom);
8586: my $syllabuslink = '<a href="javascript:ToSyllabus();">'.&mt('Syllabus').'</a>'.
8587: (' 'x2).&mt('(shows course personnel)');
1.608 www 8588: my $default_form_data=&defaultFormData($symb);
1.579 raeburn 8589: my $nofile_alert = &mt('Please use the browse button to select a file from your local directory.');
8590: 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 8591: $r->print(&Apache::lonhtmlcommon::scripttag('
1.157 albertel 8592: function checkUpload(formname) {
8593: if (formname.upfile.value == "") {
1.579 raeburn 8594: alert("'.$nofile_alert.'");
1.157 albertel 8595: return false;
8596: }
1.565 raeburn 8597: if (formname.courseid.value == "") {
1.579 raeburn 8598: alert("'.$nocourseid_alert.'");
1.565 raeburn 8599: return false;
8600: }
1.157 albertel 8601: formname.submit();
8602: }
1.565 raeburn 8603:
8604: function ToSyllabus() {
8605: var cdom = '."'$dom'".';
8606: var cnum = document.rules.courseid.value;
8607: if (cdom == "" || cdom == null) {
8608: return;
8609: }
8610: if (cnum == "" || cnum == null) {
8611: return;
8612: }
8613: syllwin=window.open("/public/"+cdom+"/"+cnum+"/syllabus","LONCAPASyllabus",
8614: "height=350,width=350,scrollbars=yes,menubar=no");
8615: return;
8616: }
8617:
1.597 wenzelju 8618: '));
8619: $r->print('
1.648 bisitz 8620: <h3>'.&mt('Send bubblesheet data to a course').'</h3>
1.566 raeburn 8621:
1.492 albertel 8622: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
1.565 raeburn 8623: '.$default_form_data.
8624: &Apache::lonhtmlcommon::start_pick_box().
8625: &Apache::lonhtmlcommon::row_title(&mt('Course ID')).
8626: '<input name="courseid" type="text" size="30" />'.$select_link.
8627: &Apache::lonhtmlcommon::row_closure().
8628: &Apache::lonhtmlcommon::row_title(&mt('Course Name')).
8629: '<input name="coursename" type="text" size="30" />'.$syllabuslink.
8630: &Apache::lonhtmlcommon::row_closure().
8631: &Apache::lonhtmlcommon::row_title(&mt('Domain')).
8632: '<input name="domainid" type="hidden" />'.$domdesc.
8633: &Apache::lonhtmlcommon::row_closure().
8634: &Apache::lonhtmlcommon::row_title(&mt('File to upload')).
8635: '<input type="file" name="upfile" size="50" />'.
8636: &Apache::lonhtmlcommon::row_closure(1).
8637: &Apache::lonhtmlcommon::end_pick_box().'<br />
8638:
1.492 albertel 8639: <input name="command" value="scantronupload_save" type="hidden" />
1.589 bisitz 8640: <input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
1.157 albertel 8641: </form>
1.492 albertel 8642: ');
1.157 albertel 8643: return '';
8644: }
8645:
1.423 albertel 8646:
1.157 albertel 8647: sub scantron_upload_scantron_data_save {
1.608 www 8648: my($r,$symb)=@_;
1.182 albertel 8649: my $doanotherupload=
8650: '<br /><form action="/adm/grades" method="post">'."\n".
8651: '<input type="hidden" name="command" value="scantronupload" />'."\n".
1.492 albertel 8652: '<input type="submit" name="submit" value="'.&mt('Do Another Upload').'" />'."\n".
1.182 albertel 8653: '</form>'."\n";
1.257 albertel 8654: if (!&Apache::lonnet::allowed('usc',$env{'form.domainid'}) &&
1.162 albertel 8655: !&Apache::lonnet::allowed('usc',
1.257 albertel 8656: $env{'form.domainid'}.'_'.$env{'form.courseid'})) {
1.575 www 8657: $r->print(&mt("You are not allowed to upload bubblesheet data to the requested course.")."<br />");
1.614 www 8658: unless ($symb) {
1.182 albertel 8659: $r->print($doanotherupload);
8660: }
1.162 albertel 8661: return '';
8662: }
1.257 albertel 8663: my %coursedata=&Apache::lonnet::coursedescription($env{'form.domainid'}.'_'.$env{'form.courseid'});
1.568 raeburn 8664: my $uploadedfile;
1.567 raeburn 8665: $r->print('<h3>'.&mt("Uploading file to [_1]",$coursedata{'description'}).'</h3>');
1.257 albertel 8666: if (length($env{'form.upfile'}) < 2) {
1.568 raeburn 8667: $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 8668: } else {
1.568 raeburn 8669: my $result =
8670: &Apache::lonnet::userfileupload('upfile','','scantron','','','',
8671: $env{'form.courseid'},$env{'form.domainid'});
8672: if ($result =~ m{^/uploaded/}) {
1.567 raeburn 8673: $r->print(&mt('[_1]Success:[_2] Successfully uploaded [_3] bytes of data into location: [_4]',
8674: '<span class="LC_success">','</span>',(length($env{'form.upfile'})-1),
8675: '<span class="LC_filename">'.$result.'</span>'));
1.568 raeburn 8676: ($uploadedfile) = ($result =~ m{/([^/]+)$});
1.567 raeburn 8677: $r->print(&validate_uploaded_scantron_file($env{'form.domainid'},
1.568 raeburn 8678: $env{'form.courseid'},$uploadedfile));
1.210 albertel 8679: } else {
1.567 raeburn 8680: $r->print(&mt('[_1]Error:[_2] An error ([_3]) occurred when attempting to upload the file, [_4]',
8681: '<span class="LC_error">','</span>',$result,
1.568 raeburn 8682: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'));
1.183 albertel 8683: }
8684: }
1.174 albertel 8685: if ($symb) {
1.612 www 8686: $r->print(&scantron_selectphase($r,$uploadedfile,$symb));
1.174 albertel 8687: } else {
1.182 albertel 8688: $r->print($doanotherupload);
1.174 albertel 8689: }
1.157 albertel 8690: return '';
8691: }
8692:
1.567 raeburn 8693: sub validate_uploaded_scantron_file {
8694: my ($cdom,$cname,$fname) = @_;
8695: my $scanlines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.$fname);
8696: my @lines;
8697: if ($scanlines ne '-1') {
8698: @lines=split("\n",$scanlines,-1);
8699: }
8700: my $output;
8701: if (@lines) {
8702: my (%counts,$max_match_format);
8703: my ($max_match_count,$max_match_pct) = (0,0);
8704: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cname);
8705: my %idmap = &username_to_idmap($classlist);
8706: foreach my $key (keys(%idmap)) {
8707: my $lckey = lc($key);
8708: $idmap{$lckey} = $idmap{$key};
8709: }
8710: my %unique_formats;
8711: my @formatlines = &get_scantronformat_file();
8712: foreach my $line (@formatlines) {
8713: chomp($line);
8714: my @config = split(/:/,$line);
8715: my $idstart = $config[5];
8716: my $idlength = $config[6];
8717: if (($idstart ne '') && ($idlength > 0)) {
8718: if (ref($unique_formats{$idstart.':'.$idlength}) eq 'ARRAY') {
8719: push(@{$unique_formats{$idstart.':'.$idlength}},$config[0].':'.$config[1]);
8720: } else {
8721: $unique_formats{$idstart.':'.$idlength} = [$config[0].':'.$config[1]];
8722: }
8723: }
8724: }
8725: foreach my $key (keys(%unique_formats)) {
8726: my ($idstart,$idlength) = split(':',$key);
8727: %{$counts{$key}} = (
8728: 'found' => 0,
8729: 'total' => 0,
8730: );
8731: foreach my $line (@lines) {
8732: next if ($line =~ /^#/);
8733: next if ($line =~ /^[\s\cz]*$/);
8734: my $id = substr($line,$idstart-1,$idlength);
8735: $id = lc($id);
8736: if (exists($idmap{$id})) {
8737: $counts{$key}{'found'} ++;
8738: }
8739: $counts{$key}{'total'} ++;
8740: }
8741: if ($counts{$key}{'total'}) {
8742: my $percent_match = (100*$counts{$key}{'found'})/($counts{$key}{'total'});
8743: if (($max_match_format eq '') || ($percent_match > $max_match_pct)) {
8744: $max_match_pct = $percent_match;
8745: $max_match_format = $key;
8746: $max_match_count = $counts{$key}{'total'};
8747: }
8748: }
8749: }
8750: if (ref($unique_formats{$max_match_format}) eq 'ARRAY') {
8751: my $format_descs;
8752: my $numwithformat = @{$unique_formats{$max_match_format}};
8753: for (my $i=0; $i<$numwithformat; $i++) {
8754: my ($name,$desc) = split(':',$unique_formats{$max_match_format}[$i]);
8755: if ($i<$numwithformat-2) {
8756: $format_descs .= '"<i>'.$desc.'</i>", ';
8757: } elsif ($i==$numwithformat-2) {
8758: $format_descs .= '"<i>'.$desc.'</i>" '.&mt('and').' ';
8759: } elsif ($i==$numwithformat-1) {
8760: $format_descs .= '"<i>'.$desc.'</i>"';
8761: }
8762: }
8763: my $showpct = sprintf("%.0f",$max_match_pct).'%';
8764: $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).
8765: '<br />'.&mt('A low percentage of matches results from one of the following:').'<ul>'.
8766: '<li>'.&mt('The file was uploaded to the wrong course').'</li>'.
8767: '<li>'.&mt('The data are not in the format expected for the domain: [_1]',
8768: '<i>'.$cdom.'</i>').'</li>'.
8769: '<li>'.&mt('Students did not bubble their IDs, or mis-bubbled them').'</li>'.
8770: '<li>'.&mt('The course roster is not up to date').'</li>'.
8771: '</ul>';
8772: }
8773: } else {
8774: $output = '<span class="LC_warning">'.&mt('Uploaded file contained no data').'</span>';
8775: }
8776: return $output;
8777: }
8778:
1.202 albertel 8779: sub valid_file {
8780: my ($requested_file)=@_;
8781: foreach my $filename (sort(&scantron_filenames())) {
8782: if ($requested_file eq $filename) { return 1; }
8783: }
8784: return 0;
8785: }
8786:
8787: sub scantron_download_scantron_data {
1.608 www 8788: my ($r,$symb)=@_;
8789: my $default_form_data=&defaultFormData($symb);
1.257 albertel 8790: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
8791: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
8792: my $file=$env{'form.scantron_selectfile'};
1.202 albertel 8793: if (! &valid_file($file)) {
1.492 albertel 8794: $r->print('
1.202 albertel 8795: <p>
1.686 bisitz 8796: '.&mt('The requested filename was invalid.').'
1.202 albertel 8797: </p>
1.492 albertel 8798: ');
1.202 albertel 8799: return;
8800: }
8801: my $orig='/uploaded/'.$cdom.'/'.$cname.'/scantron_orig_'.$file;
8802: my $corrected='/uploaded/'.$cdom.'/'.$cname.'/scantron_corrected_'.$file;
8803: my $skipped='/uploaded/'.$cdom.'/'.$cname.'/scantron_skipped_'.$file;
8804: &Apache::lonnet::allowuploaded('/adm/grades',$orig);
8805: &Apache::lonnet::allowuploaded('/adm/grades',$corrected);
8806: &Apache::lonnet::allowuploaded('/adm/grades',$skipped);
1.492 albertel 8807: $r->print('
1.202 albertel 8808: <p>
1.492 albertel 8809: '.&mt('[_1]Original[_2] file as uploaded by the scantron office.',
8810: '<a href="'.$orig.'">','</a>').'
1.202 albertel 8811: </p>
8812: <p>
1.492 albertel 8813: '.&mt('[_1]Corrections[_2], a file of corrected records that were used in grading.',
8814: '<a href="'.$corrected.'">','</a>').'
1.202 albertel 8815: </p>
8816: <p>
1.492 albertel 8817: '.&mt('[_1]Skipped[_2], a file of records that were skipped.',
8818: '<a href="'.$skipped.'">','</a>').'
1.202 albertel 8819: </p>
1.492 albertel 8820: ');
1.202 albertel 8821: return '';
8822: }
1.157 albertel 8823:
1.523 raeburn 8824: sub checkscantron_results {
1.608 www 8825: my ($r,$symb) = @_;
1.523 raeburn 8826: if (!$symb) {return '';}
8827: my $cid = $env{'request.course.id'};
1.542 raeburn 8828: my %lettdig = &letter_to_digits();
1.523 raeburn 8829: my $numletts = scalar(keys(%lettdig));
8830: my $cnum = $env{'course.'.$cid.'.num'};
8831: my $cdom = $env{'course.'.$cid.'.domain'};
8832: my (undef, undef, $sequence) = &Apache::lonnet::decode_symb($env{'form.selectpage'});
8833: my %record;
8834: my %scantron_config =
8835: &Apache::grades::get_scantron_config($env{'form.scantron_format'});
1.649 raeburn 8836: my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
1.523 raeburn 8837: my ($scanlines,$scan_data)=&Apache::grades::scantron_getfile();
8838: my $classlist=&Apache::loncoursedata::get_classlist();
8839: my %idmap=&Apache::grades::username_to_idmap($classlist);
8840: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 8841: unless (ref($navmap)) {
8842: $r->print(&navmap_errormsg());
8843: return '';
8844: }
1.523 raeburn 8845: my $map=$navmap->getResourceByUrl($sequence);
1.691 raeburn 8846: my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
8847: %grader_randomlists_by_symb,%orderedforcode);
1.677 raeburn 8848: if (ref($map)) {
8849: $randomorder=$map->randomorder();
1.689 raeburn 8850: $randompick=$map->randompick();
1.677 raeburn 8851: }
1.557 raeburn 8852: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.691 raeburn 8853: my $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource);
8854: if ($nav_error) {
8855: $r->print(&navmap_errormsg());
8856: return '';
1.678 raeburn 8857: }
1.673 raeburn 8858: &graders_resources_pass(\@resources,\%grader_partids_by_symb,
8859: \%grader_randomlists_by_symb,$bubbles_per_row);
1.554 raeburn 8860: my ($uname,$udom);
1.523 raeburn 8861: my (%scandata,%lastname,%bylast);
8862: $r->print('
8863: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="checkscantron">'."\n");
8864:
8865: my @delayqueue;
8866: my %completedstudents;
8867:
1.691 raeburn 8868: my $count=&get_todo_count($scanlines,$scan_data);
1.667 www 8869: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$count);
1.678 raeburn 8870: my ($username,$domain,$started,%ordered);
1.649 raeburn 8871: &scantron_get_maxbubble(\$nav_error,\%scantron_config); # Need the bubble lines array to parse.
1.582 raeburn 8872: if ($nav_error) {
8873: $r->print(&navmap_errormsg());
8874: return '';
8875: }
1.523 raeburn 8876:
1.667 www 8877: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,'Processing first student');
1.523 raeburn 8878: my $start=&Time::HiRes::time();
8879: my $i=-1;
8880:
8881: while ($i<$scanlines->{'count'}) {
8882: ($username,$domain,$uname)=('','','');
8883: $i++;
8884: my $line=&Apache::grades::scantron_get_line($scanlines,$scan_data,$i);
8885: if ($line=~/^[\s\cz]*$/) { next; }
8886: if ($started) {
1.667 www 8887: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student');
1.523 raeburn 8888: }
8889: $started=1;
8890: my $scan_record=
8891: &Apache::grades::scantron_parse_scanline($line,$i,\%scantron_config,
8892: $scan_data);
1.693 raeburn 8893: unless ($uname=&scantron_find_student($scan_record,$scan_data,
8894: \%idmap,$i)) {
1.523 raeburn 8895: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
8896: 'Unable to find a student that matches',1);
8897: next;
8898: }
8899: if (exists $completedstudents{$uname}) {
8900: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
8901: 'Student '.$uname.' has multiple sheets',2);
8902: next;
8903: }
8904: my $pid = $scan_record->{'scantron.ID'};
8905: $lastname{$pid} = $scan_record->{'scantron.LastName'};
8906: push(@{$bylast{$lastname{$pid}}},$pid);
1.678 raeburn 8907: my $usec = $classlist->{$uname}->[&Apache::loncoursedata::CL_SECTION];
8908: my $user = $uname.':'.$usec;
1.523 raeburn 8909: ($username,$domain)=split(/:/,$uname);
1.677 raeburn 8910:
1.678 raeburn 8911: my $scancode;
1.677 raeburn 8912: if ((exists($scan_record->{'scantron.CODE'})) &&
8913: (&Apache::lonnet::validCODE($scan_record->{'scantron.CODE'}))) {
8914: $scancode = $scan_record->{'scantron.CODE'};
8915: } else {
8916: $scancode = '';
8917: }
8918:
8919: my @mapresources = @resources;
1.691 raeburn 8920: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
8921: my %respnumlookup=();
8922: my %startline=();
1.689 raeburn 8923: if ($randomorder || $randompick) {
1.678 raeburn 8924: @mapresources =
1.691 raeburn 8925: &users_order($user,$scancode,$sequence,\@master_seq,\%symb_to_resource,
8926: \%orderedforcode);
8927: my $total = &get_respnum_lookups($sequence,$scan_data,\%idmap,$line,
8928: $scan_record,\@master_seq,\%symb_to_resource,
8929: \%grader_partids_by_symb,\%orderedforcode,
8930: \%respnumlookup,\%startline);
8931: if ($randompick && $total) {
8932: $lastpos = $total*$scantron_config{'Qlength'};
8933: }
1.677 raeburn 8934: }
1.691 raeburn 8935: $scandata{$pid} = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
8936: chomp($scandata{$pid});
8937: $scandata{$pid} =~ s/\r$//;
8938:
1.523 raeburn 8939: my $counter = -1;
1.677 raeburn 8940: foreach my $resource (@mapresources) {
1.557 raeburn 8941: my $parts;
1.554 raeburn 8942: my $ressymb = $resource->symb();
1.557 raeburn 8943: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
8944: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
8945: (my $analysis,$parts) =
1.672 raeburn 8946: &scantron_partids_tograde($resource,$env{'request.course.id'},
8947: $username,$domain,undef,
8948: $bubbles_per_row);
1.557 raeburn 8949: } else {
8950: $parts = $grader_partids_by_symb{$ressymb};
8951: }
1.542 raeburn 8952: ($counter,my $recording) =
8953: &verify_scantron_grading($resource,$domain,$username,$cid,$counter,
1.554 raeburn 8954: $scandata{$pid},$parts,
1.691 raeburn 8955: \%scantron_config,\%lettdig,$numletts,
8956: $randomorder,$randompick,
8957: \%respnumlookup,\%startline);
1.542 raeburn 8958: $record{$pid} .= $recording;
1.523 raeburn 8959: }
8960: }
8961: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
8962: $r->print('<br />');
8963: my ($okstudents,$badstudents,$numstudents,$passed,$failed);
8964: $passed = 0;
8965: $failed = 0;
8966: $numstudents = 0;
8967: foreach my $last (sort(keys(%bylast))) {
8968: if (ref($bylast{$last}) eq 'ARRAY') {
8969: foreach my $pid (sort(@{$bylast{$last}})) {
8970: my $showscandata = $scandata{$pid};
8971: my $showrecord = $record{$pid};
8972: $showscandata =~ s/\s/ /g;
8973: $showrecord =~ s/\s/ /g;
8974: if ($scandata{$pid} eq $record{$pid}) {
8975: my $css_class = ($passed % 2)?'LC_odd_row':'LC_even_row';
8976: $okstudents .= '<tr class="'.$css_class.'">'.
1.581 www 8977: '<td>'.&mt('Bubblesheet').'</td><td>'.$showscandata.'</td><td rowspan="2">'.$last.'</td><td rowspan="2">'.$pid.'</td>'."\n".
1.523 raeburn 8978: '</tr>'."\n".
8979: '<tr class="'.$css_class.'">'."\n".
8980: '<td>Submissions</td><td>'.$showrecord.'</td></tr>'."\n";
8981: $passed ++;
8982: } else {
8983: my $css_class = ($failed % 2)?'LC_odd_row':'LC_even_row';
1.581 www 8984: $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 8985: '</tr>'."\n".
8986: '<tr class="'.$css_class.'">'."\n".
8987: '<td>Submissions</td><td><span class="LC_nobreak">'.$record{$pid}.'</span></td>'."\n".
8988: '</tr>'."\n";
8989: $failed ++;
8990: }
8991: $numstudents ++;
8992: }
8993: }
8994: }
1.648 bisitz 8995: $r->print(
8996: '<p>'
8997: .&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).',
8998: '<b>',
8999: $numstudents,
9000: '</b>',
9001: $env{'form.scantron_maxbubble'})
9002: .'</p>'
9003: );
1.682 raeburn 9004: $r->print('<p>'
1.683 raeburn 9005: .&mt('Exact matches for [_1][quant,_2,student][_3].','<b>',$passed,'</b>')
1.682 raeburn 9006: .'<br />'
9007: .&mt('Discrepancies detected for [_1][quant,_2,student][_3].','<b>',$failed,'</b>')
9008: .'</p>'
9009: );
1.523 raeburn 9010: if ($passed) {
1.572 www 9011: $r->print(&mt('Students with exact correspondence between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 9012: $r->print(&Apache::loncommon::start_data_table()."\n".
9013: &Apache::loncommon::start_data_table_header_row()."\n".
9014: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
9015: &Apache::loncommon::end_data_table_header_row()."\n".
9016: $okstudents."\n".
9017: &Apache::loncommon::end_data_table().'<br />');
9018: }
9019: if ($failed) {
1.572 www 9020: $r->print(&mt('Students with differences between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 9021: $r->print(&Apache::loncommon::start_data_table()."\n".
9022: &Apache::loncommon::start_data_table_header_row()."\n".
9023: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
9024: &Apache::loncommon::end_data_table_header_row()."\n".
9025: $badstudents."\n".
9026: &Apache::loncommon::end_data_table()).'<br />'.
1.572 www 9027: &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 9028: }
1.614 www 9029: $r->print('</form><br />');
1.523 raeburn 9030: return;
9031: }
9032:
1.542 raeburn 9033: sub verify_scantron_grading {
1.554 raeburn 9034: my ($resource,$domain,$username,$cid,$counter,$scandata,$partids,
1.691 raeburn 9035: $scantron_config,$lettdig,$numletts,$randomorder,$randompick,
9036: $respnumlookup,$startline) = @_;
1.542 raeburn 9037: my ($record,%expected,%startpos);
9038: return ($counter,$record) if (!ref($resource));
9039: return ($counter,$record) if (!$resource->is_problem());
9040: my $symb = $resource->symb();
1.554 raeburn 9041: return ($counter,$record) if (ref($partids) ne 'ARRAY');
9042: foreach my $part_id (@{$partids}) {
1.542 raeburn 9043: $counter ++;
9044: $expected{$part_id} = 0;
1.691 raeburn 9045: my $respnum = $counter;
9046: if ($randomorder || $randompick) {
9047: $respnum = $respnumlookup->{$counter};
9048: $startpos{$part_id} = $startline->{$counter} + 1;
9049: } else {
9050: $startpos{$part_id} = $env{"form.scantron.first_bubble_line.$counter"};
9051: }
9052: if ($env{"form.scantron.sub_bubblelines.$respnum"}) {
9053: my @sub_lines = split(/,/,$env{"form.scantron.sub_bubblelines.$respnum"});
1.542 raeburn 9054: foreach my $item (@sub_lines) {
9055: $expected{$part_id} += $item;
9056: }
9057: } else {
1.691 raeburn 9058: $expected{$part_id} = $env{"form.scantron.bubblelines.$respnum"};
1.542 raeburn 9059: }
9060: }
9061: if ($symb) {
9062: my %recorded;
9063: my (%returnhash) = &Apache::lonnet::restore($symb,$cid,$domain,$username);
9064: if ($returnhash{'version'}) {
9065: my %lasthash=();
9066: my $version;
9067: for ($version=1;$version<=$returnhash{'version'};$version++) {
9068: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
9069: $lasthash{$key}=$returnhash{$version.':'.$key};
9070: }
9071: }
9072: foreach my $key (keys(%lasthash)) {
9073: if ($key =~ /\.scantron$/) {
9074: my $value = &unescape($lasthash{$key});
9075: my ($part_id) = ($key =~ /^resource\.(.+)\.scantron$/);
9076: if ($value eq '') {
9077: for (my $i=0; $i<$expected{$part_id}; $i++) {
9078: for (my $j=0; $j<$scantron_config->{'length'}; $j++) {
9079: $recorded{$part_id} .= $scantron_config->{'Qoff'};
9080: }
9081: }
9082: } else {
9083: my @tocheck;
9084: my @items = split(//,$value);
9085: if (($scantron_config->{'Qon'} eq 'letter') ||
9086: ($scantron_config->{'Qon'} eq 'number')) {
9087: if (@items < $expected{$part_id}) {
9088: my $fragment = substr($scandata,$startpos{$part_id},$expected{$part_id});
9089: my @singles = split(//,$fragment);
9090: foreach my $pos (@singles) {
9091: if ($pos eq ' ') {
9092: push(@tocheck,$pos);
9093: } else {
9094: my $next = shift(@items);
9095: push(@tocheck,$next);
9096: }
9097: }
9098: } else {
9099: @tocheck = @items;
9100: }
9101: foreach my $letter (@tocheck) {
9102: if ($scantron_config->{'Qon'} eq 'letter') {
9103: if ($letter !~ /^[A-J]$/) {
9104: $letter = $scantron_config->{'Qoff'};
9105: }
9106: $recorded{$part_id} .= $letter;
9107: } elsif ($scantron_config->{'Qon'} eq 'number') {
9108: my $digit;
9109: if ($letter !~ /^[A-J]$/) {
9110: $digit = $scantron_config->{'Qoff'};
9111: } else {
9112: $digit = $lettdig->{$letter};
9113: }
9114: $recorded{$part_id} .= $digit;
9115: }
9116: }
9117: } else {
9118: @tocheck = @items;
9119: for (my $i=0; $i<$expected{$part_id}; $i++) {
9120: my $curr_sub = shift(@tocheck);
9121: my $digit;
9122: if ($curr_sub =~ /^[A-J]$/) {
9123: $digit = $lettdig->{$curr_sub}-1;
9124: }
9125: if ($curr_sub eq 'J') {
9126: $digit += scalar($numletts);
9127: }
9128: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
9129: if ($j == $digit) {
9130: $recorded{$part_id} .= $scantron_config->{'Qon'};
9131: } else {
9132: $recorded{$part_id} .= $scantron_config->{'Qoff'};
9133: }
9134: }
9135: }
9136: }
9137: }
9138: }
9139: }
9140: }
1.554 raeburn 9141: foreach my $part_id (@{$partids}) {
1.542 raeburn 9142: if ($recorded{$part_id} eq '') {
9143: for (my $i=0; $i<$expected{$part_id}; $i++) {
9144: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
9145: $recorded{$part_id} .= $scantron_config->{'Qoff'};
9146: }
9147: }
9148: }
9149: $record .= $recorded{$part_id};
9150: }
9151: }
9152: return ($counter,$record);
9153: }
9154:
1.691 raeburn 9155: sub letter_to_digits {
1.542 raeburn 9156: my %lettdig = (
9157: A => 1,
9158: B => 2,
9159: C => 3,
9160: D => 4,
9161: E => 5,
9162: F => 6,
9163: G => 7,
9164: H => 8,
9165: I => 9,
9166: J => 0,
9167: );
9168: return %lettdig;
9169: }
9170:
1.423 albertel 9171:
1.75 albertel 9172: #-------- end of section for handling grading scantron forms -------
9173: #
9174: #-------------------------------------------------------------------
9175:
1.72 ng 9176: #-------------------------- Menu interface -------------------------
9177: #
1.614 www 9178: #--- Href with symb and command ---
9179:
9180: sub href_symb_cmd {
9181: my ($symb,$cmd)=@_;
1.669 raeburn 9182: return '/adm/grades?symb='.&HTML::Entities::encode(&Apache::lonenc::check_encrypt($symb),'<>&"').'&command='.$cmd;
1.72 ng 9183: }
9184:
1.443 banghart 9185: sub grading_menu {
1.608 www 9186: my ($request,$symb) = @_;
1.443 banghart 9187: if (!$symb) {return '';}
9188:
9189: my %fields = ('symb'=>&Apache::lonenc::check_encrypt($symb),
1.618 www 9190: 'command'=>'individual');
1.538 schulted 9191:
1.598 www 9192: my $url1a = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
9193:
9194: $fields{'command'}='ungraded';
9195: my $url1b=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
9196:
9197: $fields{'command'}='table';
9198: my $url1c=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
9199:
9200: $fields{'command'}='all_for_one';
9201: my $url1d=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
9202:
1.621 www 9203: $fields{'command'}='downloadfilesselect';
9204: my $url1e=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
9205:
1.443 banghart 9206: $fields{'command'} = 'csvform';
1.538 schulted 9207: my $url2 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
9208:
1.443 banghart 9209: $fields{'command'} = 'processclicker';
1.538 schulted 9210: my $url3 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
9211:
1.443 banghart 9212: $fields{'command'} = 'scantron_selectphase';
1.538 schulted 9213: my $url4 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
1.602 www 9214:
9215: $fields{'command'} = 'initialverifyreceipt';
9216: my $url5 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
1.538 schulted 9217:
1.598 www 9218: my @menu = ({ categorytitle=>'Hand Grading',
1.538 schulted 9219: items =>[
1.598 www 9220: { linktext => 'Select individual students to grade',
9221: url => $url1a,
1.538 schulted 9222: permission => 'F',
1.636 wenzelju 9223: icon => 'grade_students.png',
1.598 www 9224: linktitle => 'Grade current resource for a selection of students.'
9225: },
9226: { linktext => 'Grade ungraded submissions.',
9227: url => $url1b,
9228: permission => 'F',
1.636 wenzelju 9229: icon => 'ungrade_sub.png',
1.598 www 9230: linktitle => 'Grade all submissions that have not been graded yet.'
1.538 schulted 9231: },
1.598 www 9232:
9233: { linktext => 'Grading table',
9234: url => $url1c,
9235: permission => 'F',
1.636 wenzelju 9236: icon => 'grading_table.png',
1.598 www 9237: linktitle => 'Grade current resource for all students.'
9238: },
1.615 www 9239: { linktext => 'Grade page/folder for one student',
1.598 www 9240: url => $url1d,
9241: permission => 'F',
1.636 wenzelju 9242: icon => 'grade_PageFolder.png',
1.598 www 9243: linktitle => 'Grade all resources in current page/sequence/folder for one student.'
1.621 www 9244: },
9245: { linktext => 'Download submissions',
9246: url => $url1e,
9247: permission => 'F',
1.636 wenzelju 9248: icon => 'download_sub.png',
1.621 www 9249: linktitle => 'Download all students submissions.'
1.598 www 9250: }]},
9251: { categorytitle=>'Automated Grading',
9252: items =>[
9253:
1.538 schulted 9254: { linktext => 'Upload Scores',
9255: url => $url2,
9256: permission => 'F',
9257: icon => 'uploadscores.png',
9258: linktitle => 'Specify a file containing the class scores for current resource.'
9259: },
9260: { linktext => 'Process Clicker',
9261: url => $url3,
9262: permission => 'F',
9263: icon => 'addClickerInfoFile.png',
9264: linktitle => 'Specify a file containing the clicker information for this resource.'
9265: },
1.587 raeburn 9266: { linktext => 'Grade/Manage/Review Bubblesheets',
1.538 schulted 9267: url => $url4,
9268: permission => 'F',
1.636 wenzelju 9269: icon => 'bubblesheet.png',
1.648 bisitz 9270: linktitle => 'Grade bubblesheet exams, upload/download bubblesheet data files, and review previously graded bubblesheet exams.'
1.602 www 9271: },
1.616 www 9272: { linktext => 'Verify Receipt Number',
1.602 www 9273: url => $url5,
9274: permission => 'F',
1.636 wenzelju 9275: icon => 'receipt_number.png',
1.602 www 9276: linktitle => 'Verify a system-generated receipt number for correct problem solution.'
9277: }
9278:
1.538 schulted 9279: ]
9280: });
9281:
1.443 banghart 9282: # Create the menu
9283: my $Str;
1.445 banghart 9284: $Str .= '<form method="post" action="" name="gradingMenu">';
9285: $Str .= '<input type="hidden" name="command" value="" />'.
1.618 www 9286: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.445 banghart 9287:
1.602 www 9288: $Str .= &Apache::lonhtmlcommon::generate_menu(@menu);
1.443 banghart 9289: return $Str;
9290: }
9291:
1.598 www 9292:
9293: sub ungraded {
9294: my ($request)=@_;
9295: &submit_options($request);
9296: }
9297:
1.599 www 9298: sub submit_options_sequence {
1.608 www 9299: my ($request,$symb) = @_;
1.599 www 9300: if (!$symb) {return '';}
1.600 www 9301: &commonJSfunctions($request);
9302: my $result;
1.599 www 9303:
1.600 www 9304: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.618 www 9305: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.632 www 9306: $result.=&selectfield(0).
1.601 www 9307: '<input type="hidden" name="command" value="pickStudentPage" />
1.600 www 9308: <div>
9309: <input type="submit" value="'.&mt('Next').' →" />
9310: </div>
9311: </div>
9312: </form>';
9313: return $result;
9314: }
9315:
9316: sub submit_options_table {
1.608 www 9317: my ($request,$symb) = @_;
1.600 www 9318: if (!$symb) {return '';}
1.599 www 9319: &commonJSfunctions($request);
9320: my $result;
9321:
9322: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.618 www 9323: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.599 www 9324:
1.632 www 9325: $result.=&selectfield(0).
1.601 www 9326: '<input type="hidden" name="command" value="viewgrades" />
1.599 www 9327: <div>
9328: <input type="submit" value="'.&mt('Next').' →" />
9329: </div>
9330: </div>
9331: </form>';
9332: return $result;
9333: }
1.443 banghart 9334:
1.621 www 9335: sub submit_options_download {
9336: my ($request,$symb) = @_;
9337: if (!$symb) {return '';}
9338:
9339: &commonJSfunctions($request);
9340:
9341: my $result='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
9342: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
9343: $result.='
9344: <h2>
9345: '.&mt('Select Students for Which to Download Submissions').'
9346: </h2>'.&selectfield(1).'
9347: <input type="hidden" name="command" value="downloadfileslink" />
9348: <input type="submit" value="'.&mt('Next').' →" />
9349: </div>
9350: </div>
1.600 www 9351:
9352:
1.621 www 9353: </form>';
9354: return $result;
9355: }
9356:
1.443 banghart 9357: #--- Displays the submissions first page -------
9358: sub submit_options {
1.608 www 9359: my ($request,$symb) = @_;
1.72 ng 9360: if (!$symb) {return '';}
9361:
1.118 ng 9362: &commonJSfunctions($request);
1.473 albertel 9363: my $result;
1.533 bisitz 9364:
1.72 ng 9365: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.618 www 9366: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.632 www 9367: $result.=&selectfield(1).'
1.601 www 9368: <input type="hidden" name="command" value="submission" />
9369: <input type="submit" value="'.&mt('Next').' →" />
9370: </div>
9371: </div>
9372:
9373:
9374: </form>';
9375: return $result;
9376: }
1.533 bisitz 9377:
1.601 www 9378: sub selectfield {
9379: my ($full)=@_;
1.635 raeburn 9380: my %options =
9381: (&Apache::lonlocal::texthash(
9382: 'yes' => 'with submissions',
9383: 'queued' => 'in grading queue',
9384: 'graded' => 'with ungraded submissions',
9385: 'incorrect' => 'with incorrect submissions',
9386: 'all' => 'with any status'),
9387: 'select_form_order' => ['yes','queued','graded','incorrect','all']);
1.601 www 9388: my $result='<div class="LC_columnSection">
1.537 harmsja 9389:
1.533 bisitz 9390: <fieldset>
9391: <legend>
9392: '.&mt('Sections').'
9393: </legend>
1.601 www 9394: '.&Apache::lonstatistics::SectionSelect('section','multiple',5).'
1.533 bisitz 9395: </fieldset>
1.537 harmsja 9396:
1.533 bisitz 9397: <fieldset>
9398: <legend>
9399: '.&mt('Groups').'
9400: </legend>
9401: '.&Apache::lonstatistics::GroupSelect('group','multiple',5).'
9402: </fieldset>
1.537 harmsja 9403:
1.533 bisitz 9404: <fieldset>
9405: <legend>
9406: '.&mt('Access Status').'
9407: </legend>
1.601 www 9408: '.&Apache::lonhtmlcommon::StatusOptions(undef,undef,5,undef,'mult').'
9409: </fieldset>';
9410: if ($full) {
9411: $result.='
1.533 bisitz 9412: <fieldset>
9413: <legend>
9414: '.&mt('Submission Status').'
1.601 www 9415: </legend>'.
1.635 raeburn 9416: &Apache::loncommon::select_form('all','submitonly',\%options).
1.601 www 9417: '</fieldset>';
9418: }
9419: $result.='</div><br />';
1.44 ng 9420: return $result;
1.2 albertel 9421: }
9422:
1.285 albertel 9423: sub reset_perm {
9424: undef(%perm);
9425: }
9426:
9427: sub init_perm {
9428: &reset_perm();
1.300 albertel 9429: foreach my $test_perm ('vgr','mgr','opa') {
9430:
9431: my $scope = $env{'request.course.id'};
9432: if (!($perm{$test_perm}=&Apache::lonnet::allowed($test_perm,$scope))) {
9433:
9434: $scope .= '/'.$env{'request.course.sec'};
9435: if ( $perm{$test_perm}=
9436: &Apache::lonnet::allowed($test_perm,$scope)) {
9437: $perm{$test_perm.'_section'}=$env{'request.course.sec'};
9438: } else {
9439: delete($perm{$test_perm});
9440: }
1.285 albertel 9441: }
9442: }
9443: }
9444:
1.674 raeburn 9445: sub init_old_essays {
9446: my ($symb,$apath,$adom,$aname) = @_;
9447: if ($symb ne '') {
9448: my %essays = &Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
9449: if (keys(%essays) > 0) {
9450: $old_essays{$symb} = \%essays;
9451: }
9452: }
9453: return;
9454: }
9455:
9456: sub reset_old_essays {
9457: undef(%old_essays);
9458: }
9459:
1.400 www 9460: sub gather_clicker_ids {
1.408 albertel 9461: my %clicker_ids;
1.400 www 9462:
9463: my $classlist = &Apache::loncoursedata::get_classlist();
9464:
9465: # Set up a couple variables.
1.407 albertel 9466: my $username_idx = &Apache::loncoursedata::CL_SNAME();
9467: my $domain_idx = &Apache::loncoursedata::CL_SDOM();
1.438 www 9468: my $status_idx = &Apache::loncoursedata::CL_STATUS();
1.400 www 9469:
1.407 albertel 9470: foreach my $student (keys(%$classlist)) {
1.438 www 9471: if ($classlist->{$student}->[$status_idx] ne 'Active') { next; }
1.407 albertel 9472: my $username = $classlist->{$student}->[$username_idx];
9473: my $domain = $classlist->{$student}->[$domain_idx];
1.400 www 9474: my $clickers =
1.408 albertel 9475: (&Apache::lonnet::userenvironment($domain,$username,'clickers'))[1];
1.400 www 9476: foreach my $id (split(/\,/,$clickers)) {
1.414 www 9477: $id=~s/^[\#0]+//;
1.421 www 9478: $id=~s/[\-\:]//g;
1.407 albertel 9479: if (exists($clicker_ids{$id})) {
1.408 albertel 9480: $clicker_ids{$id}.=','.$username.':'.$domain;
1.400 www 9481: } else {
1.408 albertel 9482: $clicker_ids{$id}=$username.':'.$domain;
1.400 www 9483: }
9484: }
9485: }
1.407 albertel 9486: return %clicker_ids;
1.400 www 9487: }
9488:
1.402 www 9489: sub gather_adv_clicker_ids {
1.408 albertel 9490: my %clicker_ids;
1.402 www 9491: my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'};
9492: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
9493: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
1.409 albertel 9494: foreach my $element (sort(keys(%coursepersonnel))) {
1.402 www 9495: foreach my $person (split(/\,/,$coursepersonnel{$element})) {
9496: my ($puname,$pudom)=split(/\:/,$person);
9497: my $clickers =
1.408 albertel 9498: (&Apache::lonnet::userenvironment($pudom,$puname,'clickers'))[1];
1.405 www 9499: foreach my $id (split(/\,/,$clickers)) {
1.414 www 9500: $id=~s/^[\#0]+//;
1.421 www 9501: $id=~s/[\-\:]//g;
1.408 albertel 9502: if (exists($clicker_ids{$id})) {
9503: $clicker_ids{$id}.=','.$puname.':'.$pudom;
9504: } else {
9505: $clicker_ids{$id}=$puname.':'.$pudom;
9506: }
1.405 www 9507: }
1.402 www 9508: }
9509: }
1.407 albertel 9510: return %clicker_ids;
1.402 www 9511: }
9512:
1.413 www 9513: sub clicker_grading_parameters {
9514: return ('gradingmechanism' => 'scalar',
9515: 'upfiletype' => 'scalar',
9516: 'specificid' => 'scalar',
9517: 'pcorrect' => 'scalar',
9518: 'pincorrect' => 'scalar');
9519: }
9520:
1.400 www 9521: sub process_clicker {
1.608 www 9522: my ($r,$symb)=@_;
1.400 www 9523: if (!$symb) {return '';}
9524: my $result=&checkforfile_js();
1.632 www 9525: $result.=&Apache::loncommon::start_data_table().
9526: &Apache::loncommon::start_data_table_header_row().
9527: '<th>'.&mt('Specify a file containing clicker information and set grading options.').'</th>'.
9528: &Apache::loncommon::end_data_table_header_row().
9529: &Apache::loncommon::start_data_table_row()."<td>\n";
1.413 www 9530: # Attempt to restore parameters from last session, set defaults if not present
9531: my %Saveable_Parameters=&clicker_grading_parameters();
9532: &Apache::loncommon::restore_course_settings('grades_clicker',
9533: \%Saveable_Parameters);
9534: if (!$env{'form.pcorrect'}) { $env{'form.pcorrect'}=100; }
9535: if (!$env{'form.pincorrect'}) { $env{'form.pincorrect'}=100; }
9536: if (!$env{'form.gradingmechanism'}) { $env{'form.gradingmechanism'}='attendance'; }
9537: if (!$env{'form.upfiletype'}) { $env{'form.upfiletype'}='iclicker'; }
9538:
9539: my %checked;
1.521 www 9540: foreach my $gradingmechanism ('attendance','personnel','specific','given') {
1.413 www 9541: if ($env{'form.gradingmechanism'} eq $gradingmechanism) {
1.569 bisitz 9542: $checked{$gradingmechanism}=' checked="checked"';
1.413 www 9543: }
9544: }
9545:
1.632 www 9546: my $upload=&mt("Evaluate File");
1.400 www 9547: my $type=&mt("Type");
1.402 www 9548: my $attendance=&mt("Award points just for participation");
9549: my $personnel=&mt("Correctness determined from response by course personnel");
1.414 www 9550: my $specific=&mt("Correctness determined from response with clicker ID(s)");
1.521 www 9551: my $given=&mt("Correctness determined from given list of answers").' '.
9552: '<font size="-2"><tt>('.&mt("Provide comma-separated list. Use '*' for any answer correct, '-' for skip").')</tt></font>';
1.402 www 9553: my $pcorrect=&mt("Percentage points for correct solution");
9554: my $pincorrect=&mt("Percentage points for incorrect solution");
1.413 www 9555: my $selectform=&Apache::loncommon::select_form($env{'form.upfiletype'},'upfiletype',
1.635 raeburn 9556: {'iclicker' => 'i>clicker',
1.666 www 9557: 'interwrite' => 'interwrite PRS',
9558: 'turning' => 'Turning Technologies'});
1.418 albertel 9559: $symb = &Apache::lonenc::check_encrypt($symb);
1.597 wenzelju 9560: $result.= &Apache::lonhtmlcommon::scripttag(<<ENDUPFORM);
1.402 www 9561: function sanitycheck() {
9562: // Accept only integer percentages
9563: document.forms.gradesupload.pcorrect.value=Math.round(document.forms.gradesupload.pcorrect.value);
9564: document.forms.gradesupload.pincorrect.value=Math.round(document.forms.gradesupload.pincorrect.value);
9565: // Find out grading choice
9566: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
9567: if (document.forms.gradesupload.gradingmechanism[i].checked) {
9568: gradingchoice=document.forms.gradesupload.gradingmechanism[i].value;
9569: }
9570: }
9571: // By default, new choice equals user selection
9572: newgradingchoice=gradingchoice;
9573: // Not good to give more points for false answers than correct ones
9574: if (Math.round(document.forms.gradesupload.pcorrect.value)<Math.round(document.forms.gradesupload.pincorrect.value)) {
9575: document.forms.gradesupload.pcorrect.value=document.forms.gradesupload.pincorrect.value;
9576: }
9577: // If new choice is attendance only, and old choice was correctness-based, restore defaults
9578: if ((gradingchoice=='attendance') && (document.forms.gradesupload.waschecked.value!='attendance')) {
9579: document.forms.gradesupload.pcorrect.value=100;
9580: document.forms.gradesupload.pincorrect.value=100;
9581: }
9582: // If the values are different, cannot be attendance only
9583: if ((Math.round(document.forms.gradesupload.pcorrect.value)!=Math.round(document.forms.gradesupload.pincorrect.value)) &&
9584: (gradingchoice=='attendance')) {
9585: newgradingchoice='personnel';
9586: }
9587: // Change grading choice to new one
9588: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
9589: if (document.forms.gradesupload.gradingmechanism[i].value==newgradingchoice) {
9590: document.forms.gradesupload.gradingmechanism[i].checked=true;
9591: } else {
9592: document.forms.gradesupload.gradingmechanism[i].checked=false;
9593: }
9594: }
9595: // Remember the old state
9596: document.forms.gradesupload.waschecked.value=newgradingchoice;
9597: }
1.597 wenzelju 9598: ENDUPFORM
9599: $result.= <<ENDUPFORM;
1.400 www 9600: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
9601: <input type="hidden" name="symb" value="$symb" />
9602: <input type="hidden" name="command" value="processclickerfile" />
9603: <input type="file" name="upfile" size="50" />
9604: <br /><label>$type: $selectform</label>
1.632 www 9605: ENDUPFORM
9606: $result.='</td>'.&Apache::loncommon::end_data_table_row().
9607: &Apache::loncommon::start_data_table_row().'<td>'.(<<ENDGRADINGFORM);
9608: <label><input type="radio" name="gradingmechanism" value="attendance"$checked{'attendance'} onclick="sanitycheck()" />$attendance </label>
1.589 bisitz 9609: <br /><label><input type="radio" name="gradingmechanism" value="personnel"$checked{'personnel'} onclick="sanitycheck()" />$personnel</label>
9610: <br /><label><input type="radio" name="gradingmechanism" value="specific"$checked{'specific'} onclick="sanitycheck()" />$specific </label>
1.414 www 9611: <input type="text" name="specificid" value="$env{'form.specificid'}" size="20" />
1.589 bisitz 9612: <br /><label><input type="radio" name="gradingmechanism" value="given"$checked{'given'} onclick="sanitycheck()" />$given </label>
1.521 www 9613: <br />
9614: <input type="text" name="givenanswer" size="50" />
1.413 www 9615: <input type="hidden" name="waschecked" value="$env{'form.gradingmechanism'}" />
1.632 www 9616: ENDGRADINGFORM
9617: $result.='</td>'.&Apache::loncommon::end_data_table_row().
9618: &Apache::loncommon::start_data_table_row().'<td>'.(<<ENDPERCFORM);
9619: <label>$pcorrect: <input type="text" name="pcorrect" size="4" value="$env{'form.pcorrect'}" onchange="sanitycheck()" /></label>
1.589 bisitz 9620: <br /><label>$pincorrect: <input type="text" name="pincorrect" size="4" value="$env{'form.pincorrect'}" onchange="sanitycheck()" /></label>
9621: <br /><input type="button" onclick="javascript:checkUpload(this.form);" value="$upload" />
1.597 wenzelju 9622: </form>'
1.632 www 9623: ENDPERCFORM
9624: $result.='</td>'.
9625: &Apache::loncommon::end_data_table_row().
9626: &Apache::loncommon::end_data_table();
1.400 www 9627: return $result;
9628: }
9629:
9630: sub process_clicker_file {
1.608 www 9631: my ($r,$symb)=@_;
1.400 www 9632: if (!$symb) {return '';}
1.413 www 9633:
9634: my %Saveable_Parameters=&clicker_grading_parameters();
9635: &Apache::loncommon::store_course_settings('grades_clicker',
9636: \%Saveable_Parameters);
1.598 www 9637: my $result='';
1.404 www 9638: if (($env{'form.gradingmechanism'} eq 'specific') && ($env{'form.specificid'}!~/\w/)) {
1.408 albertel 9639: $result.='<span class="LC_error">'.&mt('You need to specify a clicker ID for the correct answer').'</span>';
1.614 www 9640: return $result;
1.404 www 9641: }
1.522 www 9642: if (($env{'form.gradingmechanism'} eq 'given') && ($env{'form.givenanswer'}!~/\S/)) {
1.521 www 9643: $result.='<span class="LC_error">'.&mt('You need to specify the correct answer').'</span>';
1.614 www 9644: return $result;
1.521 www 9645: }
1.522 www 9646: my $foundgiven=0;
1.521 www 9647: if ($env{'form.gradingmechanism'} eq 'given') {
9648: $env{'form.givenanswer'}=~s/^\s*//gs;
9649: $env{'form.givenanswer'}=~s/\s*$//gs;
1.644 www 9650: $env{'form.givenanswer'}=~s/[^a-zA-Z0-9\.\*\-\+]+/\,/g;
1.521 www 9651: $env{'form.givenanswer'}=uc($env{'form.givenanswer'});
1.522 www 9652: my @answers=split(/\,/,$env{'form.givenanswer'});
9653: $foundgiven=$#answers+1;
1.521 www 9654: }
1.407 albertel 9655: my %clicker_ids=&gather_clicker_ids();
1.408 albertel 9656: my %correct_ids;
1.404 www 9657: if ($env{'form.gradingmechanism'} eq 'personnel') {
1.408 albertel 9658: %correct_ids=&gather_adv_clicker_ids();
1.404 www 9659: }
9660: if ($env{'form.gradingmechanism'} eq 'specific') {
1.414 www 9661: foreach my $correct_id (split(/[\s\,]/,$env{'form.specificid'})) {;
9662: $correct_id=~tr/a-z/A-Z/;
9663: $correct_id=~s/\s//gs;
9664: $correct_id=~s/^[\#0]+//;
1.421 www 9665: $correct_id=~s/[\-\:]//g;
1.414 www 9666: if ($correct_id) {
9667: $correct_ids{$correct_id}='specified';
9668: }
9669: }
1.400 www 9670: }
1.404 www 9671: if ($env{'form.gradingmechanism'} eq 'attendance') {
1.408 albertel 9672: $result.=&mt('Score based on attendance only');
1.521 www 9673: } elsif ($env{'form.gradingmechanism'} eq 'given') {
1.522 www 9674: $result.=&mt('Score based on [_1] ([_2] answers)','<tt>'.$env{'form.givenanswer'}.'</tt>',$foundgiven);
1.404 www 9675: } else {
1.408 albertel 9676: my $number=0;
1.411 www 9677: $result.='<p><b>'.&mt('Correctness determined by the following IDs').'</b>';
1.408 albertel 9678: foreach my $id (sort(keys(%correct_ids))) {
1.411 www 9679: $result.='<br /><tt>'.$id.'</tt> - ';
1.408 albertel 9680: if ($correct_ids{$id} eq 'specified') {
9681: $result.=&mt('specified');
9682: } else {
9683: my ($uname,$udom)=split(/\:/,$correct_ids{$id});
9684: $result.=&Apache::loncommon::plainname($uname,$udom);
9685: }
9686: $number++;
9687: }
1.411 www 9688: $result.="</p>\n";
1.408 albertel 9689: if ($number==0) {
9690: $result.='<span class="LC_error">'.&mt('No IDs found to determine correct answer').'</span>';
1.614 www 9691: return $result;
1.408 albertel 9692: }
1.404 www 9693: }
1.405 www 9694: if (length($env{'form.upfile'}) < 2) {
1.407 albertel 9695: $result.=&mt('[_1] Error: [_2] The file you attempted to upload, [_3] contained no information. Please check that you entered the correct filename.',
9696: '<span class="LC_error">',
9697: '</span>',
9698: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>');
1.614 www 9699: return $result;
1.405 www 9700: }
1.410 www 9701:
9702: # Were able to get all the info needed, now analyze the file
9703:
1.411 www 9704: $result.=&Apache::loncommon::studentbrowser_javascript();
1.418 albertel 9705: $symb = &Apache::lonenc::check_encrypt($symb);
1.632 www 9706: $result.=&Apache::loncommon::start_data_table().
9707: &Apache::loncommon::start_data_table_header_row().
9708: '<th>'.&mt('Evaluate clicker file').'</th>'.
9709: &Apache::loncommon::end_data_table_header_row().
9710: &Apache::loncommon::start_data_table_row().(<<ENDHEADER);
9711: <td>
1.410 www 9712: <form method="post" action="/adm/grades" name="clickeranalysis">
9713: <input type="hidden" name="symb" value="$symb" />
9714: <input type="hidden" name="command" value="assignclickergrades" />
1.411 www 9715: <input type="hidden" name="gradingmechanism" value="$env{'form.gradingmechanism'}" />
9716: <input type="hidden" name="pcorrect" value="$env{'form.pcorrect'}" />
9717: <input type="hidden" name="pincorrect" value="$env{'form.pincorrect'}" />
1.410 www 9718: ENDHEADER
1.522 www 9719: if ($env{'form.gradingmechanism'} eq 'given') {
9720: $result.='<input type="hidden" name="correct:given" value="'.$env{'form.givenanswer'}.'" />';
9721: }
1.408 albertel 9722: my %responses;
9723: my @questiontitles;
1.405 www 9724: my $errormsg='';
9725: my $number=0;
9726: if ($env{'form.upfiletype'} eq 'iclicker') {
1.408 albertel 9727: ($errormsg,$number)=&iclicker_eval(\@questiontitles,\%responses);
1.406 www 9728: }
1.419 www 9729: if ($env{'form.upfiletype'} eq 'interwrite') {
9730: ($errormsg,$number)=&interwrite_eval(\@questiontitles,\%responses);
9731: }
1.666 www 9732: if ($env{'form.upfiletype'} eq 'turning') {
9733: ($errormsg,$number)=&turning_eval(\@questiontitles,\%responses);
9734: }
1.411 www 9735: $result.='<br />'.&mt('Found [_1] question(s)',$number).'<br />'.
9736: '<input type="hidden" name="number" value="'.$number.'" />'.
9737: &mt('Awarding [_1] percent for correct and [_2] percent for incorrect responses',
9738: $env{'form.pcorrect'},$env{'form.pincorrect'}).
9739: '<br />';
1.522 www 9740: if (($env{'form.gradingmechanism'} eq 'given') && ($number!=$foundgiven)) {
9741: $result.='<span class="LC_error">'.&mt('Number of given answers does not agree with number of questions in file.').'</span>';
1.614 www 9742: return $result;
1.522 www 9743: }
1.414 www 9744: # Remember Question Titles
9745: # FIXME: Possibly need delimiter other than ":"
9746: for (my $i=0;$i<$number;$i++) {
9747: $result.='<input type="hidden" name="question:'.$i.'" value="'.
9748: &HTML::Entities::encode($questiontitles[$i],'"&<>').'" />';
9749: }
1.411 www 9750: my $correct_count=0;
9751: my $student_count=0;
9752: my $unknown_count=0;
1.414 www 9753: # Match answers with usernames
9754: # FIXME: Possibly need delimiter other than ":"
1.409 albertel 9755: foreach my $id (keys(%responses)) {
1.410 www 9756: if ($correct_ids{$id}) {
1.414 www 9757: $result.="\n".'<input type="hidden" name="correct:'.$correct_count.':'.$correct_ids{$id}.'" value="'.$responses{$id}.'" />';
1.411 www 9758: $correct_count++;
1.410 www 9759: } elsif ($clicker_ids{$id}) {
1.437 www 9760: if ($clicker_ids{$id}=~/\,/) {
9761: # More than one user with the same clicker!
1.632 www 9762: $result.="</td>".&Apache::loncommon::end_data_table_row().
9763: &Apache::loncommon::start_data_table_row()."<td>".
9764: &mt('Clicker registered more than once').": <tt>".$id."</tt><br />";
1.437 www 9765: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
9766: "<select name='multi".$id."'>";
9767: foreach my $reguser (sort(split(/\,/,$clicker_ids{$id}))) {
9768: $result.="<option value='".$reguser."'>".&Apache::loncommon::plainname(split(/\:/,$reguser)).' ('.$reguser.')</option>';
9769: }
9770: $result.='</select>';
9771: $unknown_count++;
9772: } else {
9773: # Good: found one and only one user with the right clicker
9774: $result.="\n".'<input type="hidden" name="student:'.$clicker_ids{$id}.'" value="'.$responses{$id}.'" />';
9775: $student_count++;
9776: }
1.410 www 9777: } else {
1.632 www 9778: $result.="</td>".&Apache::loncommon::end_data_table_row().
9779: &Apache::loncommon::start_data_table_row()."<td>".
9780: &mt('Unregistered Clicker')." <tt>".$id."</tt><br />";
1.411 www 9781: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
9782: "\n".&mt("Username").": <input type='text' name='uname".$id."' /> ".
9783: "\n".&mt("Domain").": ".
9784: &Apache::loncommon::select_dom_form($env{'course.'.$env{'request.course.id'}.'.domain'},'udom'.$id).' '.
1.643 www 9785: &Apache::loncommon::selectstudent_link('clickeranalysis','uname'.$id,'udom'.$id,0,$id);
1.411 www 9786: $unknown_count++;
1.410 www 9787: }
1.405 www 9788: }
1.412 www 9789: $result.='<hr />'.
9790: &mt('Found [_1] registered and [_2] unregistered clickers.',$student_count,$unknown_count);
1.521 www 9791: if (($env{'form.gradingmechanism'} ne 'attendance') && ($env{'form.gradingmechanism'} ne 'given')) {
1.412 www 9792: if ($correct_count==0) {
1.696 bisitz 9793: $errormsg.="Found no correct answers for grading!";
1.412 www 9794: } elsif ($correct_count>1) {
1.414 www 9795: $result.='<br /><span class="LC_warning">'.&mt("Found [_1] entries for grading!",$correct_count).'</span>';
1.412 www 9796: }
9797: }
1.428 www 9798: if ($number<1) {
9799: $errormsg.="Found no questions.";
9800: }
1.412 www 9801: if ($errormsg) {
9802: $result.='<br /><span class="LC_error">'.&mt($errormsg).'</span>';
9803: } else {
9804: $result.='<br /><input type="submit" name="finalize" value="'.&mt('Finalize Grading').'" />';
9805: }
1.632 www 9806: $result.='</form></td>'.
9807: &Apache::loncommon::end_data_table_row().
9808: &Apache::loncommon::end_data_table();
1.614 www 9809: return $result;
1.400 www 9810: }
9811:
1.405 www 9812: sub iclicker_eval {
1.406 www 9813: my ($questiontitles,$responses)=@_;
1.405 www 9814: my $number=0;
9815: my $errormsg='';
9816: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
1.410 www 9817: my %components=&Apache::loncommon::record_sep($line);
9818: my @entries=map {$components{$_}} (sort(keys(%components)));
1.408 albertel 9819: if ($entries[0] eq 'Question') {
9820: for (my $i=3;$i<$#entries;$i+=6) {
9821: $$questiontitles[$number]=$entries[$i];
9822: $number++;
9823: }
9824: }
9825: if ($entries[0]=~/^\#/) {
9826: my $id=$entries[0];
9827: my @idresponses;
9828: $id=~s/^[\#0]+//;
9829: for (my $i=0;$i<$number;$i++) {
9830: my $idx=3+$i*6;
1.644 www 9831: $entries[$idx]=~s/[^a-zA-Z0-9\.\*\-\+]+//g;
1.408 albertel 9832: push(@idresponses,$entries[$idx]);
9833: }
9834: $$responses{$id}=join(',',@idresponses);
9835: }
1.405 www 9836: }
9837: return ($errormsg,$number);
9838: }
9839:
1.419 www 9840: sub interwrite_eval {
9841: my ($questiontitles,$responses)=@_;
9842: my $number=0;
9843: my $errormsg='';
1.420 www 9844: my $skipline=1;
9845: my $questionnumber=0;
9846: my %idresponses=();
1.419 www 9847: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
9848: my %components=&Apache::loncommon::record_sep($line);
9849: my @entries=map {$components{$_}} (sort(keys(%components)));
1.420 www 9850: if ($entries[1] eq 'Time') { $skipline=0; next; }
9851: if ($entries[1] eq 'Response') { $skipline=1; }
9852: next if $skipline;
9853: if ($entries[0]!=$questionnumber) {
9854: $questionnumber=$entries[0];
9855: $$questiontitles[$number]=&mt('Question [_1]',$questionnumber);
9856: $number++;
1.419 www 9857: }
1.420 www 9858: my $id=$entries[4];
9859: $id=~s/^[\#0]+//;
1.421 www 9860: $id=~s/^v\d*\://i;
9861: $id=~s/[\-\:]//g;
1.420 www 9862: $idresponses{$id}[$number]=$entries[6];
9863: }
1.524 raeburn 9864: foreach my $id (keys(%idresponses)) {
1.420 www 9865: $$responses{$id}=join(',',@{$idresponses{$id}});
9866: $$responses{$id}=~s/^\s*\,//;
1.419 www 9867: }
9868: return ($errormsg,$number);
9869: }
9870:
1.666 www 9871: sub turning_eval {
9872: my ($questiontitles,$responses)=@_;
9873: my $number=0;
9874: my $errormsg='';
9875: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
9876: my %components=&Apache::loncommon::record_sep($line);
9877: my @entries=map {$components{$_}} (sort(keys(%components)));
9878: if ($#entries>$number) { $number=$#entries; }
9879: my $id=$entries[0];
9880: my @idresponses;
9881: $id=~s/^[\#0]+//;
9882: unless ($id) { next; }
9883: for (my $idx=1;$idx<=$#entries;$idx++) {
9884: $entries[$idx]=~s/\,/\;/g;
9885: $entries[$idx]=~s/[^a-zA-Z0-9\.\*\-\+\;]+//g;
9886: push(@idresponses,$entries[$idx]);
9887: }
9888: $$responses{$id}=join(',',@idresponses);
9889: }
9890: for (my $i=1; $i<=$number; $i++) {
9891: $$questiontitles[$i]=&mt('Question [_1]',$i);
9892: }
9893: return ($errormsg,$number);
9894: }
9895:
9896:
1.414 www 9897: sub assign_clicker_grades {
1.608 www 9898: my ($r,$symb)=@_;
1.414 www 9899: if (!$symb) {return '';}
1.416 www 9900: # See which part we are saving to
1.582 raeburn 9901: my $res_error;
9902: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
9903: if ($res_error) {
9904: return &navmap_errormsg();
9905: }
1.416 www 9906: # FIXME: This should probably look for the first handgradeable part
9907: my $part=$$partlist[0];
9908: # Start screen output
1.632 www 9909: my $result=&Apache::loncommon::start_data_table().
9910: &Apache::loncommon::start_data_table_header_row().
9911: '<th>'.&mt('Assigning grades based on clicker file').'</th>'.
9912: &Apache::loncommon::end_data_table_header_row().
9913: &Apache::loncommon::start_data_table_row().'<td>';
1.414 www 9914: # Get correct result
9915: # FIXME: Possibly need delimiter other than ":"
9916: my @correct=();
1.415 www 9917: my $gradingmechanism=$env{'form.gradingmechanism'};
9918: my $number=$env{'form.number'};
9919: if ($gradingmechanism ne 'attendance') {
1.414 www 9920: foreach my $key (keys(%env)) {
9921: if ($key=~/^form\.correct\:/) {
9922: my @input=split(/\,/,$env{$key});
9923: for (my $i=0;$i<=$#input;$i++) {
9924: if (($correct[$i]) && ($input[$i]) &&
9925: ($correct[$i] ne $input[$i])) {
9926: $result.='<br /><span class="LC_warning">'.
9927: &mt('More than one correct result given for question "[_1]": [_2] versus [_3].',
9928: $env{'form.question:'.$i},$correct[$i],$input[$i]).'</span>';
1.644 www 9929: } elsif (($input[$i]) || ($input[$i] eq '0')) {
1.414 www 9930: $correct[$i]=$input[$i];
9931: }
9932: }
9933: }
9934: }
1.415 www 9935: for (my $i=0;$i<$number;$i++) {
1.644 www 9936: if ((!$correct[$i]) && ($correct[$i] ne '0')) {
1.414 www 9937: $result.='<br /><span class="LC_error">'.
9938: &mt('No correct result given for question "[_1]"!',
9939: $env{'form.question:'.$i}).'</span>';
9940: }
9941: }
1.644 www 9942: $result.='<br />'.&mt("Correct answer: [_1]",join(', ',map { ((($_) || ($_ eq '0'))?$_:'-') } @correct));
1.414 www 9943: }
9944: # Start grading
1.415 www 9945: my $pcorrect=$env{'form.pcorrect'};
9946: my $pincorrect=$env{'form.pincorrect'};
1.416 www 9947: my $storecount=0;
1.632 www 9948: my %users=();
1.415 www 9949: foreach my $key (keys(%env)) {
1.420 www 9950: my $user='';
1.415 www 9951: if ($key=~/^form\.student\:(.*)$/) {
1.420 www 9952: $user=$1;
9953: }
9954: if ($key=~/^form\.unknown\:(.*)$/) {
9955: my $id=$1;
9956: if (($env{'form.uname'.$id}) && ($env{'form.udom'.$id})) {
9957: $user=$env{'form.uname'.$id}.':'.$env{'form.udom'.$id};
1.437 www 9958: } elsif ($env{'form.multi'.$id}) {
9959: $user=$env{'form.multi'.$id};
1.420 www 9960: }
9961: }
1.632 www 9962: if ($user) {
9963: if ($users{$user}) {
9964: $result.='<br /><span class="LC_warning">'.
1.696 bisitz 9965: &mt('More than one entry found for [_1]!','<tt>'.$user.'</tt>').
1.632 www 9966: '</span><br />';
9967: }
9968: $users{$user}=1;
1.415 www 9969: my @answer=split(/\,/,$env{$key});
9970: my $sum=0;
1.522 www 9971: my $realnumber=$number;
1.415 www 9972: for (my $i=0;$i<$number;$i++) {
1.576 www 9973: if ($correct[$i] eq '-') {
9974: $realnumber--;
1.644 www 9975: } elsif (($answer[$i]) || ($answer[$i]=~/^[0\.]+$/)) {
1.415 www 9976: if ($gradingmechanism eq 'attendance') {
9977: $sum+=$pcorrect;
1.576 www 9978: } elsif ($correct[$i] eq '*') {
1.522 www 9979: $sum+=$pcorrect;
1.415 www 9980: } else {
1.644 www 9981: # We actually grade if correct or not
9982: my $increment=$pincorrect;
9983: # Special case: numerical answer "0"
9984: if ($correct[$i] eq '0') {
9985: if ($answer[$i]=~/^[0\.]+$/) {
9986: $increment=$pcorrect;
9987: }
9988: # General numerical answer, both evaluate to something non-zero
9989: } elsif ((1.0*$correct[$i]!=0) && (1.0*$answer[$i]!=0)) {
9990: if (1.0*$correct[$i]==1.0*$answer[$i]) {
9991: $increment=$pcorrect;
9992: }
9993: # Must be just alphanumeric
9994: } elsif ($answer[$i] eq $correct[$i]) {
9995: $increment=$pcorrect;
1.415 www 9996: }
1.644 www 9997: $sum+=$increment;
1.415 www 9998: }
9999: }
10000: }
1.522 www 10001: my $ave=$sum/(100*$realnumber);
1.416 www 10002: # Store
10003: my ($username,$domain)=split(/\:/,$user);
10004: my %grades=();
10005: $grades{"resource.$part.solved"}='correct_by_override';
10006: $grades{"resource.$part.awarded"}=$ave;
10007: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
10008: my $returncode=&Apache::lonnet::cstore(\%grades,$symb,
10009: $env{'request.course.id'},
10010: $domain,$username);
10011: if ($returncode ne 'ok') {
10012: $result.="<br /><span class=\"LC_error\">Failed to save student $username:$domain. Message when trying to save was ($returncode)</span>";
10013: } else {
10014: $storecount++;
10015: }
1.415 www 10016: }
10017: }
10018: # We are done
1.549 hauer 10019: $result.='<br />'.&mt('Successfully stored grades for [quant,_1,student].',$storecount).
1.632 www 10020: '</td>'.
10021: &Apache::loncommon::end_data_table_row().
10022: &Apache::loncommon::end_data_table();
1.614 www 10023: return $result;
1.414 www 10024: }
10025:
1.582 raeburn 10026: sub navmap_errormsg {
10027: return '<div class="LC_error">'.
10028: &mt('An error occurred retrieving information about resources in the course.').'<br />'.
1.595 raeburn 10029: &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 10030: '</div>';
10031: }
1.607 droeschl 10032:
1.609 www 10033: sub startpage {
1.671 raeburn 10034: my ($r,$symb,$crumbs,$onlyfolderflag,$nodisplayflag,$stuvcurrent,$stuvdisp,$nomenu,$js) = @_;
10035: if ($nomenu) {
10036: $r->print(&Apache::loncommon::start_page("Student's Version",$js,{'only_body' => '1'}));
10037: } else {
10038: unshift(@$crumbs,{href=>&href_symb_cmd($symb,'gradingmenu'),text=>"Grading"});
10039: $r->print(&Apache::loncommon::start_page('Grading',$js,
10040: {'bread_crumbs' => $crumbs}));
10041: &Apache::lonquickgrades::startGradeScreen($r,($env{'form.symb'}?'probgrading':'grading'));
10042: }
1.613 www 10043: unless ($nodisplayflag) {
1.671 raeburn 10044: $r->print(&Apache::lonhtmlcommon::resource_info_box($symb,$onlyfolderflag,$stuvcurrent,$stuvdisp));
1.613 www 10045: }
1.607 droeschl 10046: }
1.582 raeburn 10047:
1.622 www 10048: sub select_problem {
10049: my ($r)=@_;
1.632 www 10050: $r->print('<h3>'.&mt('Select the problem or one of the problems you want to grade').'</h3><form action="/adm/grades">');
1.622 www 10051: $r->print(&Apache::lonstathelpers::problem_selector('.',undef,1));
10052: $r->print('<input type="hidden" name="command" value="gradingmenu" />');
10053: $r->print('<input type="submit" value="'.&mt('Next').' →" /></form>');
10054: }
10055:
1.1 albertel 10056: sub handler {
1.41 ng 10057: my $request=$_[0];
1.434 albertel 10058: &reset_caches();
1.646 raeburn 10059: if ($request->header_only) {
10060: &Apache::loncommon::content_type($request,'text/html');
10061: $request->send_http_header;
10062: return OK;
10063: }
10064: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
10065:
1.664 raeburn 10066: # see what command we need to execute
10067:
10068: my @commands=&Apache::loncommon::get_env_multiple('form.command');
10069: my $command=$commands[0];
10070:
1.646 raeburn 10071: &init_perm();
10072: if (!$env{'request.course.id'}) {
1.664 raeburn 10073: unless ((&Apache::lonnet::allowed('usc',$env{'request.role.domain'})) &&
10074: ($command =~ /^scantronupload/)) {
10075: # Not in a course.
10076: $env{'user.error.msg'}="/adm/grades::vgr:0:0:Cannot display grades page outside course context";
10077: return HTTP_NOT_ACCEPTABLE;
10078: }
1.646 raeburn 10079: } elsif (!%perm) {
10080: $request->internal_redirect('/adm/quickgrades');
1.687 raeburn 10081: return OK;
1.41 ng 10082: }
1.646 raeburn 10083: &Apache::loncommon::content_type($request,'text/html');
1.41 ng 10084: $request->send_http_header;
1.646 raeburn 10085:
1.160 albertel 10086: if ($#commands > 0) {
10087: &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands));
10088: }
1.608 www 10089:
10090: # see what the symb is
10091:
10092: my $symb=$env{'form.symb'};
10093: unless ($symb) {
10094: (my $url=$env{'form.url'}) =~ s-^https*://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
10095: $symb=&Apache::lonnet::symbread($url);
10096: }
1.646 raeburn 10097: &Apache::lonenc::check_decrypt(\$symb);
1.608 www 10098:
1.513 foxr 10099: $ssi_error = 0;
1.637 www 10100: if (($symb eq '' || $command eq '') && ($env{'request.course.id'})) {
1.601 www 10101: #
1.637 www 10102: # Not called from a resource, but inside a course
1.601 www 10103: #
1.622 www 10104: &startpage($request,undef,[],1,1);
10105: &select_problem($request);
1.41 ng 10106: } else {
1.104 albertel 10107: if ($command eq 'submission' && $perm{'vgr'}) {
1.671 raeburn 10108: my ($stuvcurrent,$stuvdisp,$versionform,$js);
10109: if (($env{'form.student'} ne '') && ($env{'form.userdom'} ne '')) {
10110: ($stuvcurrent,$stuvdisp,$versionform,$js) =
10111: &choose_task_version_form($symb,$env{'form.student'},
10112: $env{'form.userdom'});
10113: }
10114: &startpage($request,$symb,[{href=>"", text=>"Student Submissions"}],undef,undef,$stuvcurrent,$stuvdisp,undef,$js);
10115: if ($versionform) {
10116: $request->print($versionform);
10117: }
10118: $request->print('<br clear="all" />');
1.611 www 10119: ($env{'form.student'} eq '' ? &listStudents($request,$symb) : &submission($request,0,0,$symb));
1.671 raeburn 10120: } elsif ($command eq 'versionsub' && $perm{'vgr'}) {
10121: my ($stuvcurrent,$stuvdisp,$versionform,$js) =
10122: &choose_task_version_form($symb,$env{'form.student'},
10123: $env{'form.userdom'},
10124: $env{'form.inhibitmenu'});
10125: &startpage($request,$symb,[{href=>"", text=>"Previous Student Version"}],undef,undef,$stuvcurrent,$stuvdisp,$env{'form.inhibitmenu'},$js);
10126: if ($versionform) {
10127: $request->print($versionform);
10128: }
10129: $request->print('<br clear="all" />');
10130: $request->print(&show_previous_task_version($request,$symb));
1.103 albertel 10131: } elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) {
1.615 www 10132: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'all_for_one'),text=>'Grade page/folder for one student'},
10133: {href=>'',text=>'Select student'}],1,1);
1.608 www 10134: &pickStudentPage($request,$symb);
1.103 albertel 10135: } elsif ($command eq 'displayPage' && $perm{'vgr'}) {
1.615 www 10136: &startpage($request,$symb,
10137: [{href=>&href_symb_cmd($symb,'all_for_one'),text=>'Grade page/folder for one student'},
10138: {href=>'',text=>'Select student'},
10139: {href=>'',text=>'Grade student'}],1,1);
1.608 www 10140: &displayPage($request,$symb);
1.104 albertel 10141: } elsif ($command eq 'gradeByPage' && $perm{'mgr'}) {
1.616 www 10142: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'all_for_one'),text=>'Grade page/folder for one student'},
10143: {href=>'',text=>'Select student'},
10144: {href=>'',text=>'Grade student'},
10145: {href=>'',text=>'Store grades'}],1,1);
1.608 www 10146: &updateGradeByPage($request,$symb);
1.104 albertel 10147: } elsif ($command eq 'processGroup' && $perm{'vgr'}) {
1.619 www 10148: &startpage($request,$symb,[{href=>'',text=>'...'},
10149: {href=>'',text=>'Modify grades'}]);
1.608 www 10150: &processGroup($request,$symb);
1.104 albertel 10151: } elsif ($command eq 'gradingmenu' && $perm{'vgr'}) {
1.608 www 10152: &startpage($request,$symb);
10153: $request->print(&grading_menu($request,$symb));
1.598 www 10154: } elsif ($command eq 'individual' && $perm{'vgr'}) {
1.617 www 10155: &startpage($request,$symb,[{href=>'',text=>'Select individual students to grade'}]);
1.608 www 10156: $request->print(&submit_options($request,$symb));
1.598 www 10157: } elsif ($command eq 'ungraded' && $perm{'vgr'}) {
1.617 www 10158: &startpage($request,$symb,[{href=>'',text=>'Grade ungraded submissions'}]);
10159: $request->print(&listStudents($request,$symb,'graded'));
1.598 www 10160: } elsif ($command eq 'table' && $perm{'vgr'}) {
1.614 www 10161: &startpage($request,$symb,[{href=>"", text=>"Grading table"}]);
1.611 www 10162: $request->print(&submit_options_table($request,$symb));
1.598 www 10163: } elsif ($command eq 'all_for_one' && $perm{'vgr'}) {
1.615 www 10164: &startpage($request,$symb,[{href=>'',text=>'Grade page/folder for one student'}],1,1);
1.608 www 10165: $request->print(&submit_options_sequence($request,$symb));
1.104 albertel 10166: } elsif ($command eq 'viewgrades' && $perm{'vgr'}) {
1.614 www 10167: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,"table"), text=>"Grading table"},{href=>'', text=>"Modify grades"}]);
1.608 www 10168: $request->print(&viewgrades($request,$symb));
1.104 albertel 10169: } elsif ($command eq 'handgrade' && $perm{'mgr'}) {
1.620 www 10170: &startpage($request,$symb,[{href=>'',text=>'...'},
10171: {href=>'',text=>'Store grades'}]);
1.608 www 10172: $request->print(&processHandGrade($request,$symb));
1.106 albertel 10173: } elsif ($command eq 'editgrades' && $perm{'mgr'}) {
1.614 www 10174: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,"table"), text=>"Grading table"},
10175: {href=>&href_symb_cmd($symb,'viewgrades').'&group=all§ion=all&Status=Active',
10176: text=>"Modify grades"},
10177: {href=>'', text=>"Store grades"}]);
1.608 www 10178: $request->print(&editgrades($request,$symb));
1.602 www 10179: } elsif ($command eq 'initialverifyreceipt' && $perm{'vgr'}) {
1.616 www 10180: &startpage($request,$symb,[{href=>'',text=>'Verify Receipt Number'}]);
1.611 www 10181: $request->print(&initialverifyreceipt($request,$symb));
1.106 albertel 10182: } elsif ($command eq 'verify' && $perm{'vgr'}) {
1.616 www 10183: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,"initialverifyreceipt"),text=>'Verify Receipt Number'},
10184: {href=>'',text=>'Verification Result'}]);
1.608 www 10185: $request->print(&verifyreceipt($request,$symb));
1.400 www 10186: } elsif ($command eq 'processclicker' && $perm{'mgr'}) {
1.615 www 10187: &startpage($request,$symb,[{href=>'', text=>'Process clicker'}]);
1.608 www 10188: $request->print(&process_clicker($request,$symb));
1.400 www 10189: } elsif ($command eq 'processclickerfile' && $perm{'mgr'}) {
1.615 www 10190: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'processclicker'), text=>'Process clicker'},
10191: {href=>'', text=>'Process clicker file'}]);
1.608 www 10192: $request->print(&process_clicker_file($request,$symb));
1.414 www 10193: } elsif ($command eq 'assignclickergrades' && $perm{'mgr'}) {
1.615 www 10194: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'processclicker'), text=>'Process clicker'},
10195: {href=>'', text=>'Process clicker file'},
10196: {href=>'', text=>'Store grades'}]);
1.608 www 10197: $request->print(&assign_clicker_grades($request,$symb));
1.106 albertel 10198: } elsif ($command eq 'csvform' && $perm{'mgr'}) {
1.627 www 10199: &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
1.608 www 10200: $request->print(&upcsvScores_form($request,$symb));
1.106 albertel 10201: } elsif ($command eq 'csvupload' && $perm{'mgr'}) {
1.627 www 10202: &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
1.608 www 10203: $request->print(&csvupload($request,$symb));
1.106 albertel 10204: } elsif ($command eq 'csvuploadmap' && $perm{'mgr'} ) {
1.627 www 10205: &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
1.608 www 10206: $request->print(&csvuploadmap($request,$symb));
1.246 albertel 10207: } elsif ($command eq 'csvuploadoptions' && $perm{'mgr'}) {
1.257 albertel 10208: if ($env{'form.associate'} ne 'Reverse Association') {
1.627 www 10209: &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
1.608 www 10210: $request->print(&csvuploadoptions($request,$symb));
1.41 ng 10211: } else {
1.257 albertel 10212: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
10213: $env{'form.upfile_associate'} = 'reverse';
1.41 ng 10214: } else {
1.257 albertel 10215: $env{'form.upfile_associate'} = 'forward';
1.41 ng 10216: }
1.627 www 10217: &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
1.608 www 10218: $request->print(&csvuploadmap($request,$symb));
1.41 ng 10219: }
1.246 albertel 10220: } elsif ($command eq 'csvuploadassign' && $perm{'mgr'} ) {
1.627 www 10221: &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
1.608 www 10222: $request->print(&csvuploadassign($request,$symb));
1.106 albertel 10223: } elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
1.616 www 10224: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.612 www 10225: $request->print(&scantron_selectphase($request,undef,$symb));
1.203 albertel 10226: } elsif ($command eq 'scantron_warning' && $perm{'mgr'}) {
1.616 www 10227: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 10228: $request->print(&scantron_do_warning($request,$symb));
1.142 albertel 10229: } elsif ($command eq 'scantron_validate' && $perm{'mgr'}) {
1.616 www 10230: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 10231: $request->print(&scantron_validate_file($request,$symb));
1.106 albertel 10232: } elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
1.616 www 10233: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 10234: $request->print(&scantron_process_students($request,$symb));
1.157 albertel 10235: } elsif ($command eq 'scantronupload' &&
1.257 albertel 10236: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
10237: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.616 www 10238: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 10239: $request->print(&scantron_upload_scantron_data($request,$symb));
1.157 albertel 10240: } elsif ($command eq 'scantronupload_save' &&
1.257 albertel 10241: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
10242: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.616 www 10243: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 10244: $request->print(&scantron_upload_scantron_data_save($request,$symb));
1.202 albertel 10245: } elsif ($command eq 'scantron_download' &&
1.257 albertel 10246: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.616 www 10247: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 10248: $request->print(&scantron_download_scantron_data($request,$symb));
1.523 raeburn 10249: } elsif ($command eq 'checksubmissions' && $perm{'vgr'}) {
1.616 www 10250: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.621 www 10251: $request->print(&checkscantron_results($request,$symb));
10252: } elsif ($command eq 'downloadfilesselect' && $perm{'vgr'}) {
10253: &startpage($request,$symb,[{href=>'', text=>'Select which submissions to download'}]);
10254: $request->print(&submit_options_download($request,$symb));
10255: } elsif ($command eq 'downloadfileslink' && $perm{'vgr'}) {
10256: &startpage($request,$symb,
10257: [{href=>&href_symb_cmd($symb,'downloadfilesselect'), text=>'Select which submissions to download'},
10258: {href=>'', text=>'Download submissions'}]);
10259: &submit_download_link($request,$symb);
1.106 albertel 10260: } elsif ($command) {
1.620 www 10261: &startpage($request,$symb,[{href=>'', text=>'Access denied'}]);
1.562 bisitz 10262: $request->print('<p class="LC_error">'.&mt('Access Denied ([_1])',$command).'</p>');
1.26 albertel 10263: }
1.2 albertel 10264: }
1.513 foxr 10265: if ($ssi_error) {
10266: &ssi_print_error($request);
10267: }
1.671 raeburn 10268: if ($env{'form.inhibitmenu'}) {
10269: $request->print(&Apache::loncommon::end_page());
10270: } else {
10271: &Apache::lonquickgrades::endGradeScreen($request);
10272: }
1.434 albertel 10273: &reset_caches();
1.646 raeburn 10274: return OK;
1.44 ng 10275: }
10276:
1.1 albertel 10277: 1;
10278:
1.13 albertel 10279: __END__;
1.531 jms 10280:
10281:
10282: =head1 NAME
10283:
10284: Apache::grades
10285:
10286: =head1 SYNOPSIS
10287:
10288: Handles the viewing of grades.
10289:
10290: This is part of the LearningOnline Network with CAPA project
10291: described at http://www.lon-capa.org.
10292:
10293: =head1 OVERVIEW
10294:
10295: Do an ssi with retries:
10296: While I'd love to factor out this with the vesrion in lonprintout,
10297: 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
10298: I'm not quite ready to invent (e.g. an ssi_with_retry object).
10299:
10300: At least the logic that drives this has been pulled out into loncommon.
10301:
10302:
10303:
10304: ssi_with_retries - Does the server side include of a resource.
10305: if the ssi call returns an error we'll retry it up to
10306: the number of times requested by the caller.
10307: If we still have a proble, no text is appended to the
10308: output and we set some global variables.
10309: to indicate to the caller an SSI error occurred.
10310: All of this is supposed to deal with the issues described
10311: in LonCAPA BZ 5631 see:
10312: http://bugs.lon-capa.org/show_bug.cgi?id=5631
10313: by informing the user that this happened.
10314:
10315: Parameters:
10316: resource - The resource to include. This is passed directly, without
10317: interpretation to lonnet::ssi.
10318: form - The form hash parameters that guide the interpretation of the resource
10319:
10320: retries - Number of retries allowed before giving up completely.
10321: Returns:
10322: On success, returns the rendered resource identified by the resource parameter.
10323: Side Effects:
10324: The following global variables can be set:
10325: ssi_error - If an unrecoverable error occurred this becomes true.
10326: It is up to the caller to initialize this to false
10327: if desired.
10328: ssi_error_resource - If an unrecoverable error occurred, this is the value
10329: of the resource that could not be rendered by the ssi
10330: call.
10331: ssi_error_message - The error string fetched from the ssi response
10332: in the event of an error.
10333:
10334:
10335: =head1 HANDLER SUBROUTINE
10336:
10337: ssi_with_retries()
10338:
10339: =head1 SUBROUTINES
10340:
10341: =over
10342:
1.671 raeburn 10343: =head1 Routines to display previous version of a Task for a specific student
10344:
10345: Tasks are graded pass/fail. Students who have yet to pass a particular Task
10346: can receive another opportunity. Access to tasks is slot-based. If a slot
10347: requires a proctor to check-in the student, a new version of the Task will
10348: be created when the student is checked in to the new opportunity.
10349:
10350: If a particular student has tried two or more versions of a particular task,
10351: the submission screen provides a user with vgr privileges (e.g., a Course
10352: Coordinator) the ability to display a previous version worked on by the
10353: student. By default, the current version is displayed. If a previous version
10354: has been selected for display, submission data are only shown that pertain
10355: to that particular version, and the interface to submit grades is not shown.
10356:
10357: =over 4
10358:
10359: =item show_previous_task_version()
10360:
10361: Displays a specified version of a student's Task, as the student sees it.
10362:
10363: Inputs: 2
10364: request - request object
10365: symb - unique symb for current instance of resource
10366:
10367: Output: None.
10368:
10369: Side Effects: calls &show_problem() to print version of Task, with
10370: version contained in form item: $env{'form.previousversion'}
10371:
10372: =item choose_task_version_form()
10373:
10374: Displays a web form used to select which version of a student's view of a
10375: Task should be displayed. Either launches a pop-up window, or replaces
10376: content in existing pop-up, or replaces page in main window.
10377:
10378: Inputs: 4
10379: symb - unique symb for current instance of resource
10380: uname - username of student
10381: udom - domain of student
10382: nomenu - 1 if display is in a pop-up window, and hence no menu
10383: breadcrumbs etc., are displayed
10384:
10385: Output: 4
10386: current - student's current version
10387: displayed - student's version being displayed
10388: result - scalar containing HTML for web form used to switch to
10389: a different version (or a link to close window, if pop-up).
10390: js - javascript for processing selection in versions web form
10391:
10392: Side Effects: None.
10393:
10394: =item previous_display_javascript()
10395:
10396: Inputs: 2
10397: nomenu - 1 if display is in a pop-up window, and hence no menu
10398: breadcrumbs etc., are displayed.
10399: current - student's current version number.
10400:
10401: Output: 1
10402: js - javascript for processing selection in versions web form.
10403:
10404: Side Effects: None.
10405:
10406: =back
10407:
10408: =head1 Routines to process bubblesheet data.
10409:
10410: =over 4
10411:
1.531 jms 10412: =item scantron_get_correction() :
10413:
10414: Builds the interface screen to interact with the operator to fix a
10415: specific error condition in a specific scanline
10416:
10417: Arguments:
10418: $r - Apache request object
10419: $i - number of the current scanline
10420: $scan_record - hash ref as returned from &scantron_parse_scanline()
10421: $scan_config - hash ref as returned from &get_scantron_config()
10422: $line - full contents of the current scanline
10423: $error - error condition, valid values are
10424: 'incorrectCODE', 'duplicateCODE',
10425: 'doublebubble', 'missingbubble',
10426: 'duplicateID', 'incorrectID'
10427: $arg - extra information needed
10428: For errors:
10429: - duplicateID - paper number that this studentID was seen before on
10430: - duplicateCODE - array ref of the paper numbers this CODE was
10431: seen on before
10432: - incorrectCODE - current incorrect CODE
10433: - doublebubble - array ref of the bubble lines that have double
10434: bubble errors
10435: - missingbubble - array ref of the bubble lines that have missing
10436: bubble errors
10437:
1.691 raeburn 10438: $randomorder - True if exam folder has randomorder set
10439: $randompick - True if exam folder has randompick set
10440: $respnumlookup - Reference to HASH mapping question numbers in bubble lines
10441: for current line to question number used for same question
10442: in "Master Seqence" (as seen by Course Coordinator).
10443: $startline - Reference to hash where key is question number (0 is first)
10444: and value is number of first bubble line for current student
10445: or code-based randompick and/or randomorder.
10446:
10447:
10448:
1.531 jms 10449: =item scantron_get_maxbubble() :
10450:
1.582 raeburn 10451: Arguments:
10452: $nav_error - Reference to scalar which is a flag to indicate a
10453: failure to retrieve a navmap object.
10454: if $nav_error is set to 1 by scantron_get_maxbubble(), the
10455: calling routine should trap the error condition and display the warning
10456: found in &navmap_errormsg().
10457:
1.649 raeburn 10458: $scantron_config - Reference to bubblesheet format configuration hash.
10459:
1.531 jms 10460: Returns the maximum number of bubble lines that are expected to
10461: occur. Does this by walking the selected sequence rendering the
10462: resource and then checking &Apache::lonxml::get_problem_counter()
10463: for what the current value of the problem counter is.
10464:
10465: Caches the results to $env{'form.scantron_maxbubble'},
10466: $env{'form.scantron.bubble_lines.n'},
10467: $env{'form.scantron.first_bubble_line.n'} and
10468: $env{"form.scantron.sub_bubblelines.n"}
1.691 raeburn 10469: which are the total number of bubble lines, the number of bubble
1.531 jms 10470: lines for response n and number of the first bubble line for response n,
10471: and a comma separated list of numbers of bubble lines for sub-questions
10472: (for optionresponse, matchresponse, and rankresponse items), for response n.
10473:
10474:
10475: =item scantron_validate_missingbubbles() :
10476:
10477: Validates all scanlines in the selected file to not have any
10478: answers that don't have bubbles that have not been verified
10479: to be bubble free.
10480:
10481: =item scantron_process_students() :
10482:
1.659 raeburn 10483: Routine that does the actual grading of the bubblesheet information.
1.531 jms 10484:
10485: The parsed scanline hash is added to %env
10486:
10487: Then foreach unskipped scanline it does an &Apache::lonnet::ssi()
10488: foreach resource , with the form data of
10489:
10490: 'submitted' =>'scantron'
10491: 'grade_target' =>'grade',
10492: 'grade_username'=> username of student
10493: 'grade_domain' => domain of student
10494: 'grade_courseid'=> of course
10495: 'grade_symb' => symb of resource to grade
10496:
10497: This triggers a grading pass. The problem grading code takes care
10498: of converting the bubbled letter information (now in %env) into a
10499: valid submission.
10500:
10501: =item scantron_upload_scantron_data() :
10502:
1.659 raeburn 10503: Creates the screen for adding a new bubblesheet data file to a course.
1.531 jms 10504:
10505: =item scantron_upload_scantron_data_save() :
10506:
10507: Adds a provided bubble information data file to the course if user
10508: has the correct privileges to do so.
10509:
10510: =item valid_file() :
10511:
10512: Validates that the requested bubble data file exists in the course.
10513:
10514: =item scantron_download_scantron_data() :
10515:
10516: Shows a list of the three internal files (original, corrected,
1.659 raeburn 10517: skipped) for a specific bubblesheet data file that exists in the
1.531 jms 10518: course.
10519:
10520: =item scantron_validate_ID() :
10521:
10522: Validates all scanlines in the selected file to not have any
1.556 weissno 10523: invalid or underspecified student/employee IDs
1.531 jms 10524:
1.582 raeburn 10525: =item navmap_errormsg() :
10526:
10527: Returns HTML mark-up inside a <div></div> with a link to re-initialize the course.
1.671 raeburn 10528: Should be called whenever the request to instantiate a navmap object fails.
10529:
10530: =back
1.582 raeburn 10531:
1.531 jms 10532: =back
10533:
10534: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>