Annotation of loncom/homework/grades.pm, revision 1.624
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.624 ! www 4: # $Id: grades.pm,v 1.623 2010/04/18 18:45:41 www 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.1 albertel 43: use Apache::Constants qw(:common);
1.167 sakharuk 44: use Apache::lonlocal;
1.386 raeburn 45: use Apache::lonenc;
1.622 www 46: use Apache::lonstathelpers;
1.170 albertel 47: use String::Similarity;
1.359 www 48: use LONCAPA;
49:
1.315 bowersj2 50: use POSIX qw(floor);
1.87 www 51:
1.435 foxr 52:
1.513 foxr 53:
1.435 foxr 54: my %perm=();
1.447 foxr 55:
1.513 foxr 56: # These variables are used to recover from ssi errors
57:
58: my $ssi_retries = 5;
59: my $ssi_error;
60: my $ssi_error_resource;
61: my $ssi_error_message;
62:
63:
64: sub ssi_with_retries {
65: my ($resource, $retries, %form) = @_;
66: my ($content, $response) = &Apache::loncommon::ssi_with_retries($resource, $retries, %form);
67: if ($response->is_error) {
68: $ssi_error = 1;
69: $ssi_error_resource = $resource;
70: $ssi_error_message = $response->code . " " . $response->message;
71: }
72:
73: return $content;
74:
75: }
76: #
77: # Prodcuces an ssi retry failure error message to the user:
78: #
79:
80: sub ssi_print_error {
81: my ($r) = @_;
1.516 raeburn 82: my $helpurl = &Apache::loncommon::top_nav_help('Helpdesk');
83: $r->print('
84: <br />
85: <h2>'.&mt('An unrecoverable network error occurred:').'</h2>
86: <p>
87: '.&mt('Unable to retrieve a resource from a server:').'<br />
88: '.&mt('Resource:').' '.$ssi_error_resource.'<br />
89: '.&mt('Error:').' '.$ssi_error_message.'
90: </p>
91: <p>'.
92: &mt('It is recommended that you try again later, as this error may mean the server was just temporarily unavailable, or is down for maintenance.').'<br />'.
93: &mt('If the error persists, please contact the [_1] for assistance.',$helpurl).
94: '</p>');
95: return;
1.513 foxr 96: }
97:
1.44 ng 98: #
1.146 albertel 99: # --- Retrieve the parts from the metadata file.---
1.598 www 100: # Returns an array of everything that the resources stores away
101: #
102:
1.44 ng 103: sub getpartlist {
1.582 raeburn 104: my ($symb,$errorref) = @_;
1.439 albertel 105:
106: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 107: unless (ref($navmap)) {
108: if (ref($errorref)) {
109: $$errorref = 'navmap';
110: return;
111: }
112: }
1.439 albertel 113: my $res = $navmap->getBySymb($symb);
114: my $partlist = $res->parts();
115: my $url = $res->src();
116: my @metakeys = split(/,/,&Apache::lonnet::metadata($url,'keys'));
117:
1.146 albertel 118: my @stores;
1.439 albertel 119: foreach my $part (@{ $partlist }) {
1.146 albertel 120: foreach my $key (@metakeys) {
121: if ($key =~ m/^stores_\Q$part\E_/) { push(@stores,$key); }
122: }
123: }
124: return @stores;
1.2 albertel 125: }
126:
1.129 ng 127: #--- Format fullname, username:domain if different for display
128: #--- Use anywhere where the student names are listed
129: sub nameUserString {
130: my ($type,$fullname,$uname,$udom) = @_;
131: if ($type eq 'header') {
1.485 albertel 132: return '<b> '.&mt('Fullname').' </b><span class="LC_internal_info">('.&mt('Username').')</span>';
1.129 ng 133: } else {
1.398 albertel 134: return ' '.$fullname.'<span class="LC_internal_info"> ('.$uname.
135: ($env{'user.domain'} eq $udom ? '' : ' ('.$udom.')').')</span>';
1.129 ng 136: }
137: }
138:
1.44 ng 139: #--- Get the partlist and the response type for a given problem. ---
140: #--- Indicate if a response type is coded handgraded or not. ---
1.623 www 141: #--- Sets response_error pointer to "1" if navmaps object broken ---
1.39 ng 142: sub response_type {
1.582 raeburn 143: my ($symb,$response_error) = @_;
1.377 albertel 144:
145: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 146: unless (ref($navmap)) {
147: if (ref($response_error)) {
148: $$response_error = 1;
149: }
150: return;
151: }
1.377 albertel 152: my $res = $navmap->getBySymb($symb);
1.593 raeburn 153: unless (ref($res)) {
154: $$response_error = 1;
155: return;
156: }
1.377 albertel 157: my $partlist = $res->parts();
1.392 albertel 158: my %vPart =
159: map { $_ => 1 } (&Apache::loncommon::get_env_multiple('form.vPart'));
1.377 albertel 160: my (%response_types,%handgrade);
161: foreach my $part (@{ $partlist }) {
1.392 albertel 162: next if (%vPart && !exists($vPart{$part}));
163:
1.377 albertel 164: my @types = $res->responseType($part);
165: my @ids = $res->responseIds($part);
166: for (my $i=0; $i < scalar(@ids); $i++) {
167: $response_types{$part}{$ids[$i]} = $types[$i];
168: $handgrade{$part.'_'.$ids[$i]} =
169: &Apache::lonnet::EXT('resource.'.$part.'_'.$ids[$i].
170: '.handgrade',$symb);
1.41 ng 171: }
172: }
1.377 albertel 173: return ($partlist,\%handgrade,\%response_types);
1.39 ng 174: }
175:
1.375 albertel 176: sub flatten_responseType {
177: my ($responseType) = @_;
178: my @part_response_id =
179: map {
180: my $part = $_;
181: map {
182: [$part,$_]
183: } sort(keys(%{ $responseType->{$part} }));
184: } sort(keys(%$responseType));
185: return @part_response_id;
186: }
187:
1.207 albertel 188: sub get_display_part {
1.324 albertel 189: my ($partID,$symb)=@_;
1.207 albertel 190: my $display=&Apache::lonnet::EXT('resource.'.$partID.'.display',$symb);
191: if (defined($display) and $display ne '') {
1.577 bisitz 192: $display.= ' (<span class="LC_internal_info">'
193: .&mt('Part ID: [_1]',$partID).'</span>)';
1.207 albertel 194: } else {
195: $display=$partID;
196: }
197: return $display;
198: }
1.269 raeburn 199:
1.434 albertel 200: sub reset_caches {
201: &reset_analyze_cache();
202: &reset_perm();
203: }
204:
205: {
206: my %analyze_cache;
1.557 raeburn 207: my %analyze_cache_formkeys;
1.148 albertel 208:
1.434 albertel 209: sub reset_analyze_cache {
210: undef(%analyze_cache);
1.557 raeburn 211: undef(%analyze_cache_formkeys);
1.434 albertel 212: }
213:
214: sub get_analyze {
1.557 raeburn 215: my ($symb,$uname,$udom,$no_increment,$add_to_hash)=@_;
1.434 albertel 216: my $key = "$symb\0$uname\0$udom";
1.557 raeburn 217: if (exists($analyze_cache{$key})) {
218: my $getupdate = 0;
219: if (ref($add_to_hash) eq 'HASH') {
220: foreach my $item (keys(%{$add_to_hash})) {
221: if (ref($analyze_cache_formkeys{$key}) eq 'HASH') {
222: if (!exists($analyze_cache_formkeys{$key}{$item})) {
223: $getupdate = 1;
224: last;
225: }
226: } else {
227: $getupdate = 1;
228: }
229: }
230: }
231: if (!$getupdate) {
232: return $analyze_cache{$key};
233: }
234: }
1.434 albertel 235:
236: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
237: $url=&Apache::lonnet::clutter($url);
1.557 raeburn 238: my %form = ('grade_target' => 'analyze',
239: 'grade_domain' => $udom,
240: 'grade_symb' => $symb,
241: 'grade_courseid' => $env{'request.course.id'},
242: 'grade_username' => $uname,
243: 'grade_noincrement' => $no_increment);
244: if (ref($add_to_hash)) {
245: %form = (%form,%{$add_to_hash});
246: }
247: my $subresult=&ssi_with_retries($url, $ssi_retries,%form);
1.434 albertel 248: (undef,$subresult)=split(/_HASH_REF__/,$subresult,2);
249: my %analyze=&Apache::lonnet::str2hash($subresult);
1.557 raeburn 250: if (ref($add_to_hash) eq 'HASH') {
251: $analyze_cache_formkeys{$key} = $add_to_hash;
252: } else {
253: $analyze_cache_formkeys{$key} = {};
254: }
1.434 albertel 255: return $analyze_cache{$key} = \%analyze;
256: }
257:
258: sub get_order {
1.525 raeburn 259: my ($partid,$respid,$symb,$uname,$udom,$no_increment)=@_;
260: my $analyze = &get_analyze($symb,$uname,$udom,$no_increment);
1.434 albertel 261: return $analyze->{"$partid.$respid.shown"};
262: }
263:
264: sub get_radiobutton_correct_foil {
265: my ($partid,$respid,$symb,$uname,$udom)=@_;
266: my $analyze = &get_analyze($symb,$uname,$udom);
1.555 raeburn 267: my $foils = &get_order($partid,$respid,$symb,$uname,$udom);
268: if (ref($foils) eq 'ARRAY') {
269: foreach my $foil (@{$foils}) {
270: if ($analyze->{"$partid.$respid.foil.value.$foil"} eq 'true') {
271: return $foil;
272: }
1.434 albertel 273: }
274: }
275: }
1.554 raeburn 276:
277: sub scantron_partids_tograde {
1.557 raeburn 278: my ($resource,$cid,$uname,$udom,$check_for_randomlist) = @_;
1.554 raeburn 279: my (%analysis,@parts);
280: if (ref($resource)) {
281: my $symb = $resource->symb();
1.557 raeburn 282: my $add_to_form;
283: if ($check_for_randomlist) {
284: $add_to_form = { 'check_parts_withrandomlist' => 1,};
285: }
286: my $analyze = &get_analyze($symb,$uname,$udom,undef,$add_to_form);
1.554 raeburn 287: if (ref($analyze) eq 'HASH') {
288: %analysis = %{$analyze};
289: }
290: if (ref($analysis{'parts'}) eq 'ARRAY') {
291: foreach my $part (@{$analysis{'parts'}}) {
292: my ($id,$respid) = split(/\./,$part);
293: if (!&Apache::loncommon::check_if_partid_hidden($id,$symb,$udom,$uname)) {
294: push(@parts,$part);
295: }
296: }
297: }
298: }
299: return (\%analysis,\@parts);
300: }
301:
1.148 albertel 302: }
1.434 albertel 303:
1.118 ng 304: #--- Clean response type for display
1.335 albertel 305: #--- Currently filters option/rank/radiobutton/match/essay/Task
306: # response types only.
1.118 ng 307: sub cleanRecord {
1.336 albertel 308: my ($answer,$response,$symb,$partid,$respid,$record,$order,$version,
309: $uname,$udom) = @_;
1.398 albertel 310: my $grayFont = '<span class="LC_internal_info">';
1.148 albertel 311: if ($response =~ /^(option|rank)$/) {
312: my %answer=&Apache::lonnet::str2hash($answer);
313: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
314: my ($toprow,$bottomrow);
315: foreach my $foil (@$order) {
316: if ($grading{$foil} == 1) {
317: $toprow.='<td><b>'.$answer{$foil}.' </b></td>';
318: } else {
319: $toprow.='<td><i>'.$answer{$foil}.' </i></td>';
320: }
1.398 albertel 321: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.148 albertel 322: }
323: return '<blockquote><table border="1">'.
1.466 albertel 324: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
325: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.148 albertel 326: $grayFont.$bottomrow.'</tr>'.'</table></blockquote>';
327: } elsif ($response eq 'match') {
328: my %answer=&Apache::lonnet::str2hash($answer);
329: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
330: my @items=&Apache::lonnet::str2array($record->{$version."resource.$partid.$respid.submissionitems"});
331: my ($toprow,$middlerow,$bottomrow);
332: foreach my $foil (@$order) {
333: my $item=shift(@items);
334: if ($grading{$foil} == 1) {
335: $toprow.='<td><b>'.$item.' </b></td>';
1.398 albertel 336: $middlerow.='<td><b>'.$grayFont.$answer{$foil}.' </span></b></td>';
1.148 albertel 337: } else {
338: $toprow.='<td><i>'.$item.' </i></td>';
1.398 albertel 339: $middlerow.='<td><i>'.$grayFont.$answer{$foil}.' </span></i></td>';
1.148 albertel 340: }
1.398 albertel 341: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.118 ng 342: }
1.126 ng 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('Item ID').'</span></td>'.
1.148 albertel 346: $middlerow.'</tr>'.
1.466 albertel 347: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.148 albertel 348: $bottomrow.'</tr>'.'</table></blockquote>';
349: } elsif ($response eq 'radiobutton') {
350: my %answer=&Apache::lonnet::str2hash($answer);
351: my ($toprow,$bottomrow);
1.434 albertel 352: my $correct =
353: &get_radiobutton_correct_foil($partid,$respid,$symb,$uname,$udom);
354: foreach my $foil (@$order) {
1.148 albertel 355: if (exists($answer{$foil})) {
1.434 albertel 356: if ($foil eq $correct) {
1.466 albertel 357: $toprow.='<td><b>'.&mt('true').'</b></td>';
1.148 albertel 358: } else {
1.466 albertel 359: $toprow.='<td><i>'.&mt('true').'</i></td>';
1.148 albertel 360: }
361: } else {
1.466 albertel 362: $toprow.='<td>'.&mt('false').'</td>';
1.148 albertel 363: }
1.398 albertel 364: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.148 albertel 365: }
366: return '<blockquote><table border="1">'.
1.466 albertel 367: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
368: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.597 wenzelju 369: $bottomrow.'</tr>'.'</table></blockquote>';
1.148 albertel 370: } elsif ($response eq 'essay') {
1.257 albertel 371: if (! exists ($env{'form.'.$symb})) {
1.122 ng 372: my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 373: $env{'course.'.$env{'request.course.id'}.'.domain'},
374: $env{'course.'.$env{'request.course.id'}.'.num'});
1.122 ng 375:
1.257 albertel 376: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
377: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
378: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
379: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
380: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
381: $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 382: }
1.166 albertel 383: $answer =~ s-\n-<br />-g;
384: return '<br /><br /><blockquote><tt>'.&keywords_highlight($answer).'</tt></blockquote>';
1.268 albertel 385: } elsif ( $response eq 'organic') {
386: my $result='Smile representation: "<tt>'.$answer.'</tt>"';
387: my $jme=$record->{$version."resource.$partid.$respid.molecule"};
388: $result.=&Apache::chemresponse::jme_img($jme,$answer,400);
389: return $result;
1.335 albertel 390: } elsif ( $response eq 'Task') {
391: if ( $answer eq 'SUBMITTED') {
392: my $files = $record->{$version."resource.$respid.$partid.bridgetask.portfiles"};
1.336 albertel 393: my $result = &Apache::bridgetask::file_list($files,$uname,$udom);
1.335 albertel 394: return $result;
395: } elsif ( grep(/^\Q$version\E.*?\.instance$/, keys(%{$record})) ) {
396: my @matches = grep(/^\Q$version\E.*?\.instance$/,
397: keys(%{$record}));
398: return join('<br />',($version,@matches));
399:
400:
401: } else {
402: my $result =
403: '<p>'
404: .&mt('Overall result: [_1]',
405: $record->{$version."resource.$respid.$partid.status"})
406: .'</p>';
407:
408: $result .= '<ul>';
409: my @grade = grep(/^\Q${version}resource.$respid.$partid.\E[^.]*[.]status$/,
410: keys(%{$record}));
411: foreach my $grade (sort(@grade)) {
412: my ($dim) = ($grade =~/[.]([^.]+)[.]status$/);
413: $result.= '<li>'.&mt("Dimension: [_1], status [_2] ",
414: $dim, $record->{$grade}).
415: '</li>';
416: }
417: $result.='</ul>';
418: return $result;
419: }
1.440 albertel 420: } elsif ( $response =~ m/(?:numerical|formula)/) {
421: $answer =
422: &Apache::loncommon::format_previous_attempt_value('submission',
423: $answer);
1.122 ng 424: }
1.118 ng 425: return $answer;
426: }
427:
428: #-- A couple of common js functions
429: sub commonJSfunctions {
430: my $request = shift;
1.597 wenzelju 431: $request->print(&Apache::lonhtmlcommon::scripttag(<<COMMONJSFUNCTIONS));
1.118 ng 432: function radioSelection(radioButton) {
433: var selection=null;
434: if (radioButton.length > 1) {
435: for (var i=0; i<radioButton.length; i++) {
436: if (radioButton[i].checked) {
437: return radioButton[i].value;
438: }
439: }
440: } else {
441: if (radioButton.checked) return radioButton.value;
442: }
443: return selection;
444: }
445:
446: function pullDownSelection(selectOne) {
447: var selection="";
448: if (selectOne.length > 1) {
449: for (var i=0; i<selectOne.length; i++) {
450: if (selectOne[i].selected) {
451: return selectOne[i].value;
452: }
453: }
454: } else {
1.138 albertel 455: // only one value it must be the selected one
456: return selectOne.value;
1.118 ng 457: }
458: }
459: COMMONJSFUNCTIONS
460: }
461:
1.44 ng 462: #--- Dumps the class list with usernames,list of sections,
463: #--- section, ids and fullnames for each user.
464: sub getclasslist {
1.449 banghart 465: my ($getsec,$filterlist,$getgroup) = @_;
1.291 albertel 466: my @getsec;
1.450 banghart 467: my @getgroup;
1.442 banghart 468: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.291 albertel 469: if (!ref($getsec)) {
470: if ($getsec ne '' && $getsec ne 'all') {
471: @getsec=($getsec);
472: }
473: } else {
474: @getsec=@{$getsec};
475: }
476: if (grep(/^all$/,@getsec)) { undef(@getsec); }
1.450 banghart 477: if (!ref($getgroup)) {
478: if ($getgroup ne '' && $getgroup ne 'all') {
479: @getgroup=($getgroup);
480: }
481: } else {
482: @getgroup=@{$getgroup};
483: }
484: if (grep(/^all$/,@getgroup)) { undef(@getgroup); }
1.291 albertel 485:
1.449 banghart 486: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
1.49 albertel 487: # Bail out if we were unable to get the classlist
1.56 matthew 488: return if (! defined($classlist));
1.449 banghart 489: &Apache::loncoursedata::get_group_memberships($classlist,$keylist);
1.56 matthew 490: #
491: my %sections;
492: my %fullnames;
1.205 matthew 493: foreach my $student (keys(%$classlist)) {
494: my $end =
495: $classlist->{$student}->[&Apache::loncoursedata::CL_END()];
496: my $start =
497: $classlist->{$student}->[&Apache::loncoursedata::CL_START()];
498: my $id =
499: $classlist->{$student}->[&Apache::loncoursedata::CL_ID()];
500: my $section =
501: $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
502: my $fullname =
503: $classlist->{$student}->[&Apache::loncoursedata::CL_FULLNAME()];
504: my $status =
505: $classlist->{$student}->[&Apache::loncoursedata::CL_STATUS()];
1.449 banghart 506: my $group =
507: $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1.76 ng 508: # filter students according to status selected
1.442 banghart 509: if ($filterlist && (!($stu_status =~ /Any/))) {
510: if (!($stu_status =~ $status)) {
1.450 banghart 511: delete($classlist->{$student});
1.76 ng 512: next;
513: }
514: }
1.450 banghart 515: # filter students according to groups selected
1.453 banghart 516: my @stu_groups = split(/,/,$group);
1.450 banghart 517: if (@getgroup) {
518: my $exclude = 1;
1.454 banghart 519: foreach my $grp (@getgroup) {
520: foreach my $stu_group (@stu_groups) {
1.453 banghart 521: if ($stu_group eq $grp) {
522: $exclude = 0;
523: }
1.450 banghart 524: }
1.453 banghart 525: if (($grp eq 'none') && !$group) {
526: $exclude = 0;
527: }
1.450 banghart 528: }
529: if ($exclude) {
530: delete($classlist->{$student});
531: }
532: }
1.205 matthew 533: $section = ($section ne '' ? $section : 'none');
1.106 albertel 534: if (&canview($section)) {
1.291 albertel 535: if (!@getsec || grep(/^\Q$section\E$/,@getsec)) {
1.103 albertel 536: $sections{$section}++;
1.450 banghart 537: if ($classlist->{$student}) {
538: $fullnames{$student}=$fullname;
539: }
1.103 albertel 540: } else {
1.205 matthew 541: delete($classlist->{$student});
1.103 albertel 542: }
543: } else {
1.205 matthew 544: delete($classlist->{$student});
1.103 albertel 545: }
1.44 ng 546: }
547: my %seen = ();
1.56 matthew 548: my @sections = sort(keys(%sections));
549: return ($classlist,\@sections,\%fullnames);
1.44 ng 550: }
551:
1.103 albertel 552: sub canmodify {
553: my ($sec)=@_;
554: if ($perm{'mgr'}) {
555: if (!defined($perm{'mgr_section'})) {
556: # can modify whole class
557: return 1;
558: } else {
559: if ($sec eq $perm{'mgr_section'}) {
560: #can modify the requested section
561: return 1;
562: } else {
563: # can't modify the request section
564: return 0;
565: }
566: }
567: }
568: #can't modify
569: return 0;
570: }
571:
572: sub canview {
573: my ($sec)=@_;
574: if ($perm{'vgr'}) {
575: if (!defined($perm{'vgr_section'})) {
576: # can modify whole class
577: return 1;
578: } else {
579: if ($sec eq $perm{'vgr_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:
1.44 ng 592: #--- Retrieve the grade status of a student for all the parts
593: sub student_gradeStatus {
1.324 albertel 594: my ($symb,$udom,$uname,$partlist) = @_;
1.257 albertel 595: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.44 ng 596: my %partstatus = ();
597: foreach (@$partlist) {
1.128 ng 598: my ($status,undef) = split(/_/,$record{"resource.$_.solved"},2);
1.44 ng 599: $status = 'nothing' if ($status eq '');
600: $partstatus{$_} = $status;
601: my $subkey = "resource.$_.submitted_by";
602: $partstatus{$subkey} = $record{$subkey} if ($record{$subkey} ne '');
603: }
604: return %partstatus;
605: }
606:
1.45 ng 607: # hidden form and javascript that calls the form
608: # Use by verifyscript and viewgrades
609: # Shows a student's view of problem and submission
610: sub jscriptNform {
1.324 albertel 611: my ($symb) = @_;
1.442 banghart 612: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.597 wenzelju 613: my $jscript= &Apache::lonhtmlcommon::scripttag(
1.45 ng 614: ' function viewOneStudent(user,domain) {'."\n".
615: ' document.onestudent.student.value = user;'."\n".
616: ' document.onestudent.userdom.value = domain;'."\n".
617: ' document.onestudent.submit();'."\n".
618: ' }'."\n".
1.597 wenzelju 619: "\n");
1.45 ng 620: $jscript.= '<form action="/adm/grades" method="post" name="onestudent">'."\n".
1.418 albertel 621: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.442 banghart 622: '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.45 ng 623: '<input type="hidden" name="command" value="submission" />'."\n".
624: '<input type="hidden" name="student" value="" />'."\n".
625: '<input type="hidden" name="userdom" value="" />'."\n".
626: '</form>'."\n";
627: return $jscript;
628: }
1.39 ng 629:
1.447 foxr 630:
631:
1.315 bowersj2 632: # Given the score (as a number [0-1] and the weight) what is the final
633: # point value? This function will round to the nearest tenth, third,
634: # or quarter if one of those is within the tolerance of .00001.
1.316 albertel 635: sub compute_points {
1.315 bowersj2 636: my ($score, $weight) = @_;
637:
638: my $tolerance = .00001;
639: my $points = $score * $weight;
640:
641: # Check for nearness to 1/x.
642: my $check_for_nearness = sub {
643: my ($factor) = @_;
644: my $num = ($points * $factor) + $tolerance;
645: my $floored_num = floor($num);
1.316 albertel 646: if ($num - $floored_num < 2 * $tolerance * $factor) {
1.315 bowersj2 647: return $floored_num / $factor;
648: }
649: return $points;
650: };
651:
652: $points = $check_for_nearness->(10);
653: $points = $check_for_nearness->(3);
654: $points = $check_for_nearness->(4);
655:
656: return $points;
657: }
658:
1.44 ng 659: #------------------ End of general use routines --------------------
1.87 www 660:
661: #
662: # Find most similar essay
663: #
664:
665: sub most_similar {
1.426 albertel 666: my ($uname,$udom,$uessay,$old_essays)=@_;
1.87 www 667:
668: # ignore spaces and punctuation
669:
670: $uessay=~s/\W+/ /gs;
671:
1.282 www 672: # ignore empty submissions (occuring when only files are sent)
673:
1.598 www 674: unless ($uessay=~/\w+/s) { return ''; }
1.282 www 675:
1.87 www 676: # these will be returned. Do not care if not at least 50 percent similar
1.88 www 677: my $limit=0.6;
1.87 www 678: my $sname='';
679: my $sdom='';
680: my $scrsid='';
681: my $sessay='';
682: # go through all essays ...
1.426 albertel 683: foreach my $tkey (keys(%$old_essays)) {
684: my ($tname,$tdom,$tcrsid)=map {&unescape($_)} (split(/\./,$tkey));
1.87 www 685: # ... except the same student
1.426 albertel 686: next if (($tname eq $uname) && ($tdom eq $udom));
687: my $tessay=$old_essays->{$tkey};
688: $tessay=~s/\W+/ /gs;
1.87 www 689: # String similarity gives up if not even limit
1.426 albertel 690: my $tsimilar=&String::Similarity::similarity($uessay,$tessay,$limit);
1.87 www 691: # Found one
1.426 albertel 692: if ($tsimilar>$limit) {
693: $limit=$tsimilar;
694: $sname=$tname;
695: $sdom=$tdom;
696: $scrsid=$tcrsid;
697: $sessay=$old_essays->{$tkey};
698: }
1.87 www 699: }
1.88 www 700: if ($limit>0.6) {
1.87 www 701: return ($sname,$sdom,$scrsid,$sessay,$limit);
702: } else {
703: return ('','','','',0);
704: }
705: }
706:
1.44 ng 707: #-------------------------------------------------------------------
708:
709: #------------------------------------ Receipt Verification Routines
1.45 ng 710: #
1.602 www 711:
712: sub initialverifyreceipt {
1.608 www 713: my ($request,$symb) = @_;
1.602 www 714: &commonJSfunctions($request);
1.605 www 715: return '<form name="gradingMenu"><input type="submit" value="'.&mt('Verify Receipt Number.').'" />'.
1.602 www 716: &Apache::lonnet::recprefix($env{'request.course.id'}).
717: '-<input type="text" name="receipt" size="4" />'.
1.603 www 718: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
719: '<input type="hidden" name="command" value="verify" />'.
720: "</form>\n";
1.602 www 721: }
722:
1.44 ng 723: #--- Check whether a receipt number is valid.---
724: sub verifyreceipt {
1.608 www 725: my ($request,$symb) = @_;
1.44 ng 726:
1.257 albertel 727: my $courseid = $env{'request.course.id'};
1.184 www 728: my $receipt = &Apache::lonnet::recprefix($courseid).'-'.
1.257 albertel 729: $env{'form.receipt'};
1.44 ng 730: $receipt =~ s/[^\-\d]//g;
731:
1.487 albertel 732: my $title.=
733: '<h3><span class="LC_info">'.
1.605 www 734: &mt('Verifying Receipt Number [_1]',$receipt).
735: '</span></h3>'."\n";
1.44 ng 736:
737: my ($string,$contents,$matches) = ('','',0);
1.56 matthew 738: my (undef,undef,$fullname) = &getclasslist('all','0');
1.177 albertel 739:
740: my $receiptparts=0;
1.390 albertel 741: if ($env{"course.$courseid.receiptalg"} eq 'receipt2' ||
742: $env{"course.$courseid.receiptalg"} eq 'receipt3') { $receiptparts=1; }
1.177 albertel 743: my $parts=['0'];
1.582 raeburn 744: if ($receiptparts) {
745: my $res_error;
746: ($parts)=&response_type($symb,\$res_error);
747: if ($res_error) {
748: return &navmap_errormsg();
749: }
750: }
1.486 albertel 751:
752: my $header =
753: &Apache::loncommon::start_data_table().
754: &Apache::loncommon::start_data_table_header_row().
1.487 albertel 755: '<th> '.&mt('Fullname').' </th>'."\n".
756: '<th> '.&mt('Username').' </th>'."\n".
757: '<th> '.&mt('Domain').' </th>';
1.486 albertel 758: if ($receiptparts) {
1.487 albertel 759: $header.='<th> '.&mt('Problem Part').' </th>';
1.486 albertel 760: }
761: $header.=
762: &Apache::loncommon::end_data_table_header_row();
763:
1.294 albertel 764: foreach (sort
765: {
766: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
767: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
768: }
769: return $a cmp $b;
770: } (keys(%$fullname))) {
1.44 ng 771: my ($uname,$udom)=split(/\:/);
1.177 albertel 772: foreach my $part (@$parts) {
773: if ($receipt eq &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb,$part)) {
1.486 albertel 774: $contents.=
775: &Apache::loncommon::start_data_table_row().
776: '<td> '."\n".
1.177 albertel 777: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 778: '\');" target="_self">'.$$fullname{$_}.'</a> </td>'."\n".
1.177 albertel 779: '<td> '.$uname.' </td>'.
780: '<td> '.$udom.' </td>';
781: if ($receiptparts) {
782: $contents.='<td> '.$part.' </td>';
783: }
1.486 albertel 784: $contents.=
785: &Apache::loncommon::end_data_table_row()."\n";
1.177 albertel 786:
787: $matches++;
788: }
1.44 ng 789: }
790: }
791: if ($matches == 0) {
1.584 bisitz 792: $string = $title
793: .'<p class="LC_warning">'
794: .&mt('No match found for the above receipt number.')
795: .'</p>';
1.44 ng 796: } else {
1.324 albertel 797: $string = &jscriptNform($symb).$title.
1.487 albertel 798: '<p>'.
1.584 bisitz 799: &mt('The above receipt number matches the following [quant,_1,student].',$matches).
1.487 albertel 800: '</p>'.
1.486 albertel 801: $header.
802: $contents.
803: &Apache::loncommon::end_data_table()."\n";
1.44 ng 804: }
1.614 www 805: return $string;
1.44 ng 806: }
807:
808: #--- This is called by a number of programs.
809: #--- Called from the Grading Menu - View/Grade an individual student
810: #--- Also called directly when one clicks on the subm button
811: # on the problem page.
1.30 ng 812: sub listStudents {
1.617 www 813: my ($request,$symb,$submitonly) = @_;
1.49 albertel 814:
1.257 albertel 815: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
816: my $cnum = $env{"course.$env{'request.course.id'}.num"};
817: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.449 banghart 818: my $getgroup = $env{'form.group'} eq '' ? 'all' : $env{'form.group'};
1.617 www 819: unless ($submitonly) {
820: $submitonly= $env{'form.submitonly'} eq '' ? 'all' : $env{'form.submitonly'};
821: }
1.49 albertel 822:
1.548 bisitz 823: my $result='<h3><span class="LC_info"> '
1.618 www 824: .&mt("View/Grade/Regrade Submissions for a Student or a Group of Students")
1.485 albertel 825: .'</span></h3>';
1.623 www 826: my $res_error;
827: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
1.49 albertel 828:
1.559 raeburn 829: my %lt = &Apache::lonlocal::texthash (
830: 'multiple' => 'Please select a student or group of students before clicking on the Next button.',
831: 'single' => 'Please select the student before clicking on the Next button.',
832: );
1.597 wenzelju 833: $request->print(&Apache::lonhtmlcommon::scripttag(<<LISTJAVASCRIPT));
1.110 ng 834: function checkSelect(checkBox) {
835: var ctr=0;
836: var sense="";
837: if (checkBox.length > 1) {
838: for (var i=0; i<checkBox.length; i++) {
839: if (checkBox[i].checked) {
840: ctr++;
841: }
842: }
1.485 albertel 843: sense = '$lt{'multiple'}';
1.110 ng 844: } else {
845: if (checkBox.checked) {
846: ctr = 1;
847: }
1.485 albertel 848: sense = '$lt{'single'}';
1.110 ng 849: }
850: if (ctr == 0) {
1.485 albertel 851: alert(sense);
1.110 ng 852: return false;
853: }
854: document.gradesub.submit();
855: }
856:
857: function reLoadList(formname) {
1.112 ng 858: if (formname.saveStatusOld.value == pullDownSelection(formname.Status)) {return;}
1.110 ng 859: formname.command.value = 'submission';
860: formname.submit();
861: }
1.45 ng 862: LISTJAVASCRIPT
863:
1.118 ng 864: &commonJSfunctions($request);
1.41 ng 865: $request->print($result);
1.39 ng 866:
1.154 albertel 867: my $gradeTable='<form action="/adm/grades" method="post" name="gradesub">'.
1.598 www 868: "\n";
1.485 albertel 869:
1.561 bisitz 870: $gradeTable .= &Apache::lonhtmlcommon::start_pick_box();
871: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Problem Text'))
872: .'<label><input type="radio" name="vProb" value="no" checked="checked" /> '.&mt('no').' </label>'."\n"
873: .'<label><input type="radio" name="vProb" value="yes" /> '.&mt('one student').' </label>'."\n"
874: .'<label><input type="radio" name="vProb" value="all" /> '.&mt('all students').' </label><br />'."\n"
875: .&Apache::lonhtmlcommon::row_closure();
876: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Answer'))
877: .'<label><input type="radio" name="vAns" value="no" /> '.&mt('no').' </label>'."\n"
878: .'<label><input type="radio" name="vAns" value="yes" /> '.&mt('one student').' </label>'."\n"
879: .'<label><input type="radio" name="vAns" value="all" checked="checked" /> '.&mt('all students').' </label><br />'."\n"
880: .&Apache::lonhtmlcommon::row_closure();
1.485 albertel 881:
882: my $submission_options;
1.442 banghart 883: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
884: my $saveStatus = $stu_status eq '' ? 'Active' : $stu_status;
1.257 albertel 885: $env{'form.Status'} = $saveStatus;
1.485 albertel 886: $submission_options.=
1.592 bisitz 887: '<span class="LC_nobreak">'.
1.624 ! www 888: '<label><input type="radio" name="lastSub" value="lastonly" /> '.
1.592 bisitz 889: &mt('last submission only').' </label></span>'."\n".
890: '<span class="LC_nobreak">'.
891: '<label><input type="radio" name="lastSub" value="last" /> '.
892: &mt('last submission & parts info').' </label></span>'."\n".
893: '<span class="LC_nobreak">'.
894: '<label><input type="radio" name="lastSub" value="datesub" /> '.
895: &mt('by dates and submissions').'</label></span>'."\n".
896: '<span class="LC_nobreak">'.
897: '<label><input type="radio" name="lastSub" value="all" /> '.
898: &mt('all details').'</label></span>';
1.561 bisitz 899: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Submissions'))
900: .$submission_options
901: .&Apache::lonhtmlcommon::row_closure();
902:
903: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Grading Increments'))
904: .'<select name="increment">'
905: .'<option value="1">'.&mt('Whole Points').'</option>'
906: .'<option value=".5">'.&mt('Half Points').'</option>'
907: .'<option value=".25">'.&mt('Quarter Points').'</option>'
908: .'<option value=".1">'.&mt('Tenths of a Point').'</option>'
909: .'</select>'
910: .&Apache::lonhtmlcommon::row_closure();
1.485 albertel 911:
912: $gradeTable .=
1.432 banghart 913: &build_section_inputs().
1.45 ng 914: '<input type="hidden" name="submitonly" value="'.$submitonly.'" />'."\n".
1.418 albertel 915: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.110 ng 916: '<input type="hidden" name="saveStatusOld" value="'.$saveStatus.'" />'."\n";
917:
1.618 www 918: if (exists($env{'form.Status'})) {
1.561 bisitz 919: $gradeTable .= '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n";
1.124 ng 920: } else {
1.561 bisitz 921: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Student Status'))
922: .&Apache::lonhtmlcommon::StatusOptions(
923: $saveStatus,undef,1,'javascript:reLoadList(this.form);')
924: .&Apache::lonhtmlcommon::row_closure();
1.124 ng 925: }
1.112 ng 926:
1.561 bisitz 927: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Check For Plagiarism'))
928: .'<input type="checkbox" name="checkPlag" checked="checked" />'
929: .&Apache::lonhtmlcommon::row_closure(1)
930: .&Apache::lonhtmlcommon::end_pick_box();
931:
932: $gradeTable .= '<p>'
1.618 www 933: .&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 934: .'<input type="hidden" name="command" value="processGroup" />'
935: .'</p>';
1.249 albertel 936:
937: # checkall buttons
938: $gradeTable.=&check_script('gradesub', 'stuinfo');
1.110 ng 939: $gradeTable.='<input type="button" '."\n".
1.589 bisitz 940: 'onclick="javascript:checkSelect(this.form.stuinfo);" '."\n".
941: 'value="'.&mt('Next').' →" /> <br />'."\n";
1.249 albertel 942: $gradeTable.=&check_buttons();
1.450 banghart 943: my ($classlist, undef, $fullname) = &getclasslist($getsec,'1',$getgroup);
1.474 albertel 944: $gradeTable.= &Apache::loncommon::start_data_table().
945: &Apache::loncommon::start_data_table_header_row();
1.110 ng 946: my $loop = 0;
947: while ($loop < 2) {
1.485 albertel 948: $gradeTable.='<th>'.&mt('No.').'</th><th>'.&mt('Select').'</th>'.
949: '<th>'.&nameUserString('header').' '.&mt('Section/Group').'</th>';
1.618 www 950: if (($submitonly ne 'queued') && ($submitonly ne 'all')) {
1.485 albertel 951: foreach my $part (sort(@$partlist)) {
952: my $display_part=
953: &get_display_part((split(/_/,$part))[0],$symb);
954: $gradeTable.=
955: '<th>'.&mt('Part: [_1] Status',$display_part).'</th>';
1.110 ng 956: }
1.301 albertel 957: } elsif ($submitonly eq 'queued') {
1.474 albertel 958: $gradeTable.='<th>'.&mt('Queue Status').' </th>';
1.110 ng 959: }
960: $loop++;
1.126 ng 961: # $gradeTable.='<td></td>' if ($loop%2 ==1);
1.41 ng 962: }
1.474 albertel 963: $gradeTable.=&Apache::loncommon::end_data_table_header_row()."\n";
1.41 ng 964:
1.45 ng 965: my $ctr = 0;
1.294 albertel 966: foreach my $student (sort
967: {
968: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
969: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
970: }
971: return $a cmp $b;
972: }
973: (keys(%$fullname))) {
1.41 ng 974: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 975:
1.110 ng 976: my %status = ();
1.301 albertel 977:
978: if ($submitonly eq 'queued') {
979: my %queue_status =
980: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
981: $udom,$uname);
982: next if (!defined($queue_status{'gradingqueue'}));
983: $status{'gradingqueue'} = $queue_status{'gradingqueue'};
984: }
985:
1.618 www 986: if (($submitonly ne 'queued') && ($submitonly ne 'all')) {
1.324 albertel 987: (%status) =&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 988: my $submitted = 0;
1.164 albertel 989: my $graded = 0;
1.248 albertel 990: my $incorrect = 0;
1.110 ng 991: foreach (keys(%status)) {
1.145 albertel 992: $submitted = 1 if ($status{$_} ne 'nothing');
1.248 albertel 993: $graded = 1 if ($status{$_} =~ /^ungraded/);
994: $incorrect = 1 if ($status{$_} =~ /^incorrect/);
995:
1.110 ng 996: my ($foo,$partid,$foo1) = split(/\./,$_);
997: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
1.145 albertel 998: $submitted = 0;
1.150 albertel 999: my ($part)=split(/\./,$partid);
1.110 ng 1000: $gradeTable.='<input type="hidden" name="'.
1.150 albertel 1001: $student.':'.$part.':submitted_by" value="'.
1.110 ng 1002: $status{'resource.'.$partid.'.submitted_by'}.'" />';
1003: }
1.41 ng 1004: }
1.248 albertel 1005:
1.156 albertel 1006: next if (!$submitted && ($submitonly eq 'yes' ||
1007: $submitonly eq 'incorrect' ||
1008: $submitonly eq 'graded'));
1.248 albertel 1009: next if (!$graded && ($submitonly eq 'graded'));
1010: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 1011: }
1.34 ng 1012:
1.45 ng 1013: $ctr++;
1.249 albertel 1014: my $section = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
1.452 banghart 1015: my $group = $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1.104 albertel 1016: if ( $perm{'vgr'} eq 'F' ) {
1.474 albertel 1017: if ($ctr%2 ==1) {
1018: $gradeTable.= &Apache::loncommon::start_data_table_row();
1019: }
1.126 ng 1020: $gradeTable.='<td align="right">'.$ctr.' </td>'.
1.563 bisitz 1021: '<td align="center"><label><input type="checkbox" name="stuinfo" value="'.
1.249 albertel 1022: $student.':'.$$fullname{$student}.':::SECTION'.$section.
1023: ') " /> </label></td>'."\n".'<td>'.
1024: &nameUserString(undef,$$fullname{$student},$uname,$udom).
1.474 albertel 1025: ' '.$section.($group ne '' ?'/'.$group:'').'</td>'."\n";
1.110 ng 1026:
1.618 www 1027: if ($submitonly ne 'all') {
1.524 raeburn 1028: foreach (sort(keys(%status))) {
1.485 albertel 1029: next if ($_ =~ /^resource.*?submitted_by$/);
1030: $gradeTable.='<td align="center"> '.&mt($status{$_}).' </td>'."\n";
1.110 ng 1031: }
1.41 ng 1032: }
1.126 ng 1033: # $gradeTable.='<td></td>' if ($ctr%2 ==1);
1.474 albertel 1034: if ($ctr%2 ==0) {
1035: $gradeTable.=&Apache::loncommon::end_data_table_row()."\n";
1036: }
1.41 ng 1037: }
1038: }
1.110 ng 1039: if ($ctr%2 ==1) {
1.126 ng 1040: $gradeTable.='<td> </td><td> </td><td> </td>';
1.618 www 1041: if (($submitonly ne 'queued') && ($submitonly ne 'all')) {
1.110 ng 1042: foreach (@$partlist) {
1043: $gradeTable.='<td> </td>';
1044: }
1.301 albertel 1045: } elsif ($submitonly eq 'queued') {
1046: $gradeTable.='<td> </td>';
1.110 ng 1047: }
1.474 albertel 1048: $gradeTable.=&Apache::loncommon::end_data_table_row();
1.110 ng 1049: }
1050:
1.474 albertel 1051: $gradeTable.=&Apache::loncommon::end_data_table()."\n".
1.589 bisitz 1052: '<input type="button" '.
1053: 'onclick="javascript:checkSelect(this.form.stuinfo);" '.
1054: 'value="'.&mt('Next').' →" /></form>'."\n";
1.45 ng 1055: if ($ctr == 0) {
1.96 albertel 1056: my $num_students=(scalar(keys(%$fullname)));
1057: if ($num_students eq 0) {
1.485 albertel 1058: $gradeTable='<br /> <span class="LC_warning">'.&mt('There are no students currently enrolled.').'</span>';
1.96 albertel 1059: } else {
1.171 albertel 1060: my $submissions='submissions';
1061: if ($submitonly eq 'incorrect') { $submissions = 'incorrect submissions'; }
1062: if ($submitonly eq 'graded' ) { $submissions = 'ungraded submissions'; }
1.301 albertel 1063: if ($submitonly eq 'queued' ) { $submissions = 'queued submissions'; }
1.398 albertel 1064: $gradeTable='<br /> <span class="LC_warning">'.
1.485 albertel 1065: &mt('No '.$submissions.' found for this resource for any students. ([_1] students checked for '.$submissions.')',
1066: $num_students).
1067: '</span><br />';
1.96 albertel 1068: }
1.46 ng 1069: } elsif ($ctr == 1) {
1.474 albertel 1070: $gradeTable =~ s/type="checkbox"/type="checkbox" checked="checked"/;
1.45 ng 1071: }
1072: $request->print($gradeTable);
1.44 ng 1073: return '';
1.10 ng 1074: }
1075:
1.44 ng 1076: #---- Called from the listStudents routine
1.249 albertel 1077:
1078: sub check_script {
1079: my ($form, $type)=@_;
1.597 wenzelju 1080: my $chkallscript= &Apache::lonhtmlcommon::scripttag('
1.249 albertel 1081: function checkall() {
1082: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1083: ele = document.forms.'.$form.'.elements[i];
1084: if (ele.name == "'.$type.'") {
1085: document.forms.'.$form.'.elements[i].checked=true;
1086: }
1087: }
1088: }
1089:
1090: function checksec() {
1091: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1092: ele = document.forms.'.$form.'.elements[i];
1093: string = document.forms.'.$form.'.chksec.value;
1094: if
1095: (ele.value.indexOf(":::SECTION"+string)>0) {
1096: document.forms.'.$form.'.elements[i].checked=true;
1097: }
1098: }
1099: }
1100:
1101:
1102: function uncheckall() {
1103: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1104: ele = document.forms.'.$form.'.elements[i];
1105: if (ele.name == "'.$type.'") {
1106: document.forms.'.$form.'.elements[i].checked=false;
1107: }
1108: }
1109: }
1110:
1.597 wenzelju 1111: '."\n");
1.249 albertel 1112: return $chkallscript;
1113: }
1114:
1115: sub check_buttons {
1.485 albertel 1116: my $buttons.='<input type="button" onclick="checkall()" value="'.&mt('Check All').'" />';
1117: $buttons.='<input type="button" onclick="uncheckall()" value="'.&mt('Uncheck All').'" /> ';
1118: $buttons.='<input type="button" onclick="checksec()" value="'.&mt('Check Section/Group').'" />';
1.249 albertel 1119: $buttons.='<input type="text" size="5" name="chksec" /> ';
1120: return $buttons;
1121: }
1122:
1.44 ng 1123: # Displays the submissions for one student or a group of students
1.34 ng 1124: sub processGroup {
1.619 www 1125: my ($request,$symb) = @_;
1.41 ng 1126: my $ctr = 0;
1.155 albertel 1127: my @stuchecked = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.41 ng 1128: my $total = scalar(@stuchecked)-1;
1.45 ng 1129:
1.396 banghart 1130: foreach my $student (@stuchecked) {
1131: my ($uname,$udom,$fullname) = split(/:/,$student);
1.257 albertel 1132: $env{'form.student'} = $uname;
1133: $env{'form.userdom'} = $udom;
1134: $env{'form.fullname'} = $fullname;
1.619 www 1135: &submission($request,$ctr,$total,$symb);
1.41 ng 1136: $ctr++;
1137: }
1138: return '';
1.35 ng 1139: }
1.34 ng 1140:
1.44 ng 1141: #------------------------------------------------------------------------------------
1142: #
1143: #-------------------------- Next few routines handles grading by student, essentially
1144: # handles essay response type problem/part
1145: #
1146: #--- Javascript to handle the submission page functionality ---
1147: sub sub_page_js {
1148: my $request = shift;
1.539 riegler 1149: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
1.597 wenzelju 1150: $request->print(&Apache::lonhtmlcommon::scripttag(<<SUBJAVASCRIPT));
1.71 ng 1151: function updateRadio(formname,id,weight) {
1.125 ng 1152: var gradeBox = formname["GD_BOX"+id];
1153: var radioButton = formname["RADVAL"+id];
1154: var oldpts = formname["oldpts"+id].value;
1.72 ng 1155: var pts = checkSolved(formname,id) == 'update' ? gradeBox.value : oldpts;
1.71 ng 1156: gradeBox.value = pts;
1157: var resetbox = false;
1158: if (isNaN(pts) || pts < 0) {
1.539 riegler 1159: alert("$alertmsg"+pts);
1.71 ng 1160: for (var i=0; i<radioButton.length; i++) {
1161: if (radioButton[i].checked) {
1162: gradeBox.value = i;
1163: resetbox = true;
1164: }
1165: }
1166: if (!resetbox) {
1167: formtextbox.value = "";
1168: }
1169: return;
1.44 ng 1170: }
1.71 ng 1171:
1172: if (pts > weight) {
1173: var resp = confirm("You entered a value ("+pts+
1174: ") greater than the weight for the part. Accept?");
1175: if (resp == false) {
1.125 ng 1176: gradeBox.value = oldpts;
1.71 ng 1177: return;
1178: }
1.44 ng 1179: }
1.13 albertel 1180:
1.71 ng 1181: for (var i=0; i<radioButton.length; i++) {
1182: radioButton[i].checked=false;
1183: if (pts == i && pts != "") {
1184: radioButton[i].checked=true;
1185: }
1186: }
1187: updateSelect(formname,id);
1.125 ng 1188: formname["stores"+id].value = "0";
1.41 ng 1189: }
1.5 albertel 1190:
1.72 ng 1191: function writeBox(formname,id,pts) {
1.125 ng 1192: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1193: if (checkSolved(formname,id) == 'update') {
1194: gradeBox.value = pts;
1195: } else {
1.125 ng 1196: var oldpts = formname["oldpts"+id].value;
1.72 ng 1197: gradeBox.value = oldpts;
1.125 ng 1198: var radioButton = formname["RADVAL"+id];
1.71 ng 1199: for (var i=0; i<radioButton.length; i++) {
1200: radioButton[i].checked=false;
1.72 ng 1201: if (i == oldpts) {
1.71 ng 1202: radioButton[i].checked=true;
1203: }
1204: }
1.41 ng 1205: }
1.125 ng 1206: formname["stores"+id].value = "0";
1.71 ng 1207: updateSelect(formname,id);
1208: return;
1.41 ng 1209: }
1.44 ng 1210:
1.71 ng 1211: function clearRadBox(formname,id) {
1212: if (checkSolved(formname,id) == 'noupdate') {
1213: updateSelect(formname,id);
1214: return;
1215: }
1.125 ng 1216: gradeSelect = formname["GD_SEL"+id];
1.71 ng 1217: for (var i=0; i<gradeSelect.length; i++) {
1218: if (gradeSelect[i].selected) {
1219: var selectx=i;
1220: }
1221: }
1.125 ng 1222: var stores = formname["stores"+id];
1.71 ng 1223: if (selectx == stores.value) { return };
1.125 ng 1224: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1225: gradeBox.value = "";
1.125 ng 1226: var radioButton = formname["RADVAL"+id];
1.71 ng 1227: for (var i=0; i<radioButton.length; i++) {
1228: radioButton[i].checked=false;
1229: }
1230: stores.value = selectx;
1231: }
1.5 albertel 1232:
1.71 ng 1233: function checkSolved(formname,id) {
1.125 ng 1234: if (formname["solved"+id].value == "correct_by_student" && formname.overRideScore.value == 'no') {
1.118 ng 1235: var reply = confirm("This problem has been graded correct by the computer. Do you want to change the score?");
1236: if (!reply) {return "noupdate";}
1.120 ng 1237: formname.overRideScore.value = 'yes';
1.41 ng 1238: }
1.71 ng 1239: return "update";
1.13 albertel 1240: }
1.71 ng 1241:
1242: function updateSelect(formname,id) {
1.125 ng 1243: formname["GD_SEL"+id][0].selected = true;
1.71 ng 1244: return;
1.41 ng 1245: }
1.33 ng 1246:
1.121 ng 1247: //=========== Check that a point is assigned for all the parts ============
1.71 ng 1248: function checksubmit(formname,val,total,parttot) {
1.121 ng 1249: formname.gradeOpt.value = val;
1.71 ng 1250: if (val == "Save & Next") {
1251: for (i=0;i<=total;i++) {
1252: for (j=0;j<parttot;j++) {
1.125 ng 1253: var partid = formname["partid"+i+"_"+j].value;
1.127 ng 1254: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1255: var points = formname["GD_BOX"+i+"_"+partid].value;
1.71 ng 1256: if (points == "") {
1.125 ng 1257: var name = formname["name"+i].value;
1.129 ng 1258: var studentID = (name != '' ? name : formname["unamedom"+i].value);
1259: var resp = confirm("You did not assign a score for "+studentID+
1260: ", part "+partid+". Continue?");
1.71 ng 1261: if (resp == false) {
1.125 ng 1262: formname["GD_BOX"+i+"_"+partid].focus();
1.71 ng 1263: return false;
1264: }
1265: }
1266: }
1267:
1268: }
1269: }
1270:
1271: }
1.121 ng 1272: if (val == "Grade Student") {
1273: if (formname.Status.value == "") {
1274: formname.Status.value = "Active";
1275: }
1276: formname.studentNo.value = total;
1277: }
1.120 ng 1278: formname.submit();
1279: }
1280:
1.71 ng 1281: //======= Check that a score is assigned for all the problems (page/sequence grading only) =========
1282: function checkSubmitPage(formname,total) {
1283: noscore = new Array(100);
1284: var ptr = 0;
1285: for (i=1;i<total;i++) {
1.125 ng 1286: var partid = formname["q_"+i].value;
1.127 ng 1287: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1288: var points = formname["GD_BOX"+i+"_"+partid].value;
1289: var status = formname["solved"+i+"_"+partid].value;
1.71 ng 1290: if (points == "" && status != "correct_by_student") {
1291: noscore[ptr] = i;
1292: ptr++;
1293: }
1294: }
1295: }
1296: if (ptr != 0) {
1297: var sense = ptr == 1 ? ": " : "s: ";
1298: var prolist = "";
1299: if (ptr == 1) {
1300: prolist = noscore[0];
1301: } else {
1302: var i = 0;
1303: while (i < ptr-1) {
1304: prolist += noscore[i]+", ";
1305: i++;
1306: }
1307: prolist += "and "+noscore[i];
1308: }
1309: var resp = confirm("You did not assign any score for the following problem"+sense+prolist+". Continue?");
1310: if (resp == false) {
1311: return false;
1312: }
1313: }
1.45 ng 1314:
1.71 ng 1315: formname.submit();
1316: }
1317: SUBJAVASCRIPT
1318: }
1.45 ng 1319:
1.71 ng 1320: #--- javascript for essay type problem --
1321: sub sub_page_kw_js {
1322: my $request = shift;
1.80 ng 1323: my $iconpath = $request->dir_config('lonIconsURL');
1.118 ng 1324: &commonJSfunctions($request);
1.350 albertel 1325:
1.597 wenzelju 1326: my $inner_js_msg_central= &Apache::lonhtmlcommon::scripttag(<<INNERJS);
1.350 albertel 1327: function checkInput() {
1328: opener.document.SCORE.msgsub.value = opener.checkEntities(document.msgcenter.msgsub.value);
1329: var nmsg = opener.document.SCORE.savemsgN.value;
1330: var usrctr = document.msgcenter.usrctr.value;
1331: var newval = opener.document.SCORE["newmsg"+usrctr];
1332: newval.value = opener.checkEntities(document.msgcenter.newmsg.value);
1333:
1334: var msgchk = "";
1335: if (document.msgcenter.subchk.checked) {
1336: msgchk = "msgsub,";
1337: }
1338: var includemsg = 0;
1339: for (var i=1; i<=nmsg; i++) {
1340: var opnmsg = opener.document.SCORE["savemsg"+i];
1341: var frmmsg = document.msgcenter["msg"+i];
1342: opnmsg.value = opener.checkEntities(frmmsg.value);
1343: var showflg = opener.document.SCORE["shownOnce"+i];
1344: showflg.value = "1";
1345: var chkbox = document.msgcenter["msgn"+i];
1346: if (chkbox.checked) {
1347: msgchk += "savemsg"+i+",";
1348: includemsg = 1;
1349: }
1350: }
1351: if (document.msgcenter.newmsgchk.checked) {
1352: msgchk += "newmsg"+usrctr;
1353: includemsg = 1;
1354: }
1355: imgformname = opener.document.SCORE["mailicon"+usrctr];
1356: imgformname.src = "$iconpath/"+((includemsg) ? "mailto.gif" : "mailbkgrd.gif");
1357: var includemsg = opener.document.SCORE["includemsg"+usrctr];
1358: includemsg.value = msgchk;
1359:
1360: self.close()
1361:
1362: }
1363: INNERJS
1364:
1.597 wenzelju 1365: my $inner_js_highlight_central= &Apache::lonhtmlcommon::scripttag(<<INNERJS);
1.351 albertel 1366: function updateChoice(flag) {
1367: opener.document.SCORE.kwclr.value = opener.radioSelection(document.hlCenter.kwdclr);
1368: opener.document.SCORE.kwsize.value = opener.radioSelection(document.hlCenter.kwdsize);
1369: opener.document.SCORE.kwstyle.value = opener.radioSelection(document.hlCenter.kwdstyle);
1370: opener.document.SCORE.refresh.value = "on";
1371: if (opener.document.SCORE.keywords.value!=""){
1372: opener.document.SCORE.submit();
1373: }
1374: self.close()
1375: }
1376: INNERJS
1377:
1378: my $start_page_msg_central =
1379: &Apache::loncommon::start_page('Message Central',$inner_js_msg_central,
1380: {'js_ready' => 1,
1381: 'only_body' => 1,
1382: 'bgcolor' =>'#FFFFFF',});
1383: my $end_page_msg_central =
1384: &Apache::loncommon::end_page({'js_ready' => 1});
1385:
1386:
1387: my $start_page_highlight_central =
1388: &Apache::loncommon::start_page('Highlight Central',
1389: $inner_js_highlight_central,
1.350 albertel 1390: {'js_ready' => 1,
1391: 'only_body' => 1,
1392: 'bgcolor' =>'#FFFFFF',});
1.351 albertel 1393: my $end_page_highlight_central =
1.350 albertel 1394: &Apache::loncommon::end_page({'js_ready' => 1});
1395:
1.219 www 1396: my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
1.236 albertel 1397: $docopen=~s/^document\.//;
1.539 riegler 1398: my $alertmsg = &mt('Please select a word or group of words from document and then click this link.');
1.597 wenzelju 1399: $request->print(&Apache::lonhtmlcommon::scripttag(<<SUBJAVASCRIPT));
1.45 ng 1400:
1.44 ng 1401: //===================== Show list of keywords ====================
1.122 ng 1402: function keywords(formname) {
1403: var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",formname.keywords.value);
1.44 ng 1404: if (nret==null) return;
1.122 ng 1405: formname.keywords.value = nret;
1.44 ng 1406:
1.122 ng 1407: if (formname.keywords.value != "") {
1.128 ng 1408: formname.refresh.value = "on";
1.122 ng 1409: formname.submit();
1.44 ng 1410: }
1411: return;
1412: }
1413:
1414: //===================== Script to view submitted by ==================
1415: function viewSubmitter(submitter) {
1416: document.SCORE.refresh.value = "on";
1417: document.SCORE.NCT.value = "1";
1418: document.SCORE.unamedom0.value = submitter;
1419: document.SCORE.submit();
1420: return;
1421: }
1422:
1423: //===================== Script to add keyword(s) ==================
1424: function getSel() {
1425: if (document.getSelection) txt = document.getSelection();
1426: else if (document.selection) txt = document.selection.createRange().text;
1427: else return;
1428: var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
1429: if (cleantxt=="") {
1.539 riegler 1430: alert("$alertmsg");
1.44 ng 1431: return;
1432: }
1433: var nret = prompt("Add selection to keyword list? Edit if desired.",cleantxt);
1434: if (nret==null) return;
1.127 ng 1435: document.SCORE.keywords.value = document.SCORE.keywords.value+" "+nret;
1.44 ng 1436: if (document.SCORE.keywords.value != "") {
1.127 ng 1437: document.SCORE.refresh.value = "on";
1.44 ng 1438: document.SCORE.submit();
1439: }
1440: return;
1441: }
1442:
1443: //====================== Script for composing message ==============
1.80 ng 1444: // preload images
1445: img1 = new Image();
1446: img1.src = "$iconpath/mailbkgrd.gif";
1447: img2 = new Image();
1448: img2.src = "$iconpath/mailto.gif";
1449:
1.44 ng 1450: function msgCenter(msgform,usrctr,fullname) {
1451: var Nmsg = msgform.savemsgN.value;
1452: savedMsgHeader(Nmsg,usrctr,fullname);
1453: var subject = msgform.msgsub.value;
1.127 ng 1454: var msgchk = document.SCORE["includemsg"+usrctr].value;
1.44 ng 1455: re = /msgsub/;
1456: var shwsel = "";
1457: if (re.test(msgchk)) { shwsel = "checked" }
1.123 ng 1458: subject = (document.SCORE.shownSub.value == 0 ? checkEntities(subject) : subject);
1459: displaySubject(checkEntities(subject),shwsel);
1.44 ng 1460: for (var i=1; i<=Nmsg; i++) {
1.123 ng 1461: var testmsg = "savemsg"+i+",";
1462: re = new RegExp(testmsg,"g");
1.44 ng 1463: shwsel = "";
1464: if (re.test(msgchk)) { shwsel = "checked" }
1.125 ng 1465: var message = document.SCORE["savemsg"+i].value;
1.126 ng 1466: message = (document.SCORE["shownOnce"+i].value == 0 ? checkEntities(message) : message);
1.123 ng 1467: displaySavedMsg(i,message,shwsel); //I do not get it. w/o checkEntities on saved messages,
1468: //any < is already converted to <, etc. However, only once!!
1.44 ng 1469: }
1.125 ng 1470: newmsg = document.SCORE["newmsg"+usrctr].value;
1.44 ng 1471: shwsel = "";
1472: re = /newmsg/;
1473: if (re.test(msgchk)) { shwsel = "checked" }
1474: newMsg(newmsg,shwsel);
1475: msgTail();
1476: return;
1477: }
1478:
1.123 ng 1479: function checkEntities(strx) {
1480: if (strx.length == 0) return strx;
1481: var orgStr = ["&", "<", ">", '"'];
1482: var newStr = ["&", "<", ">", """];
1483: var counter = 0;
1484: while (counter < 4) {
1485: strx = strReplace(strx,orgStr[counter],newStr[counter]);
1486: counter++;
1487: }
1488: return strx;
1489: }
1490:
1491: function strReplace(strx, orgStr, newStr) {
1492: return strx.split(orgStr).join(newStr);
1493: }
1494:
1.44 ng 1495: function savedMsgHeader(Nmsg,usrctr,fullname) {
1.76 ng 1496: var height = 70*Nmsg+250;
1.44 ng 1497: var scrollbar = "no";
1498: if (height > 600) {
1499: height = 600;
1500: scrollbar = "yes";
1501: }
1.118 ng 1502: var xpos = (screen.width-600)/2;
1503: xpos = (xpos < 0) ? '0' : xpos;
1504: var ypos = (screen.height-height)/2-30;
1505: ypos = (ypos < 0) ? '0' : ypos;
1506:
1.206 albertel 1507: pWin = window.open('', 'MessageCenter', 'resizable=yes,toolbar=no,location=no,scrollbars='+scrollbar+',screenx='+xpos+',screeny='+ypos+',width=600,height='+height);
1.76 ng 1508: pWin.focus();
1509: pDoc = pWin.document;
1.219 www 1510: pDoc.$docopen;
1.351 albertel 1511: pDoc.write('$start_page_msg_central');
1.76 ng 1512:
1513: pDoc.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
1514: pDoc.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
1.465 albertel 1515: pDoc.write("<h3><span class=\\"LC_info\\"> Compose Message for \"+fullname+\"<\\/span><\\/h3><br /><br />");
1.76 ng 1516:
1.564 bisitz 1517: pDoc.write('<table border="0" width="100%"><tr><td bgcolor="#777777">');
1518: pDoc.write('<table border="0" width="100%"><tr bgcolor="#DDFFFF">');
1.465 albertel 1519: pDoc.write("<td><b>Type<\\/b><\\/td><td><b>Include<\\/b><\\/td><td><b>Message<\\/td><\\/tr>");
1.44 ng 1520: }
1521: function displaySubject(msg,shwsel) {
1.76 ng 1522: pDoc = pWin.document;
1523: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.465 albertel 1524: pDoc.write("<td>Subject<\\/td>");
1525: pDoc.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1526: pDoc.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+"\\"size=\\"60\\" maxlength=\\"80\\"><\\/td><\\/tr>");
1.44 ng 1527: }
1528:
1.72 ng 1529: function displaySavedMsg(ctr,msg,shwsel) {
1.76 ng 1530: pDoc = pWin.document;
1531: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.465 albertel 1532: pDoc.write("<td align=\\"center\\">"+ctr+"<\\/td>");
1533: pDoc.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1534: pDoc.write("<td><textarea name=\\"msg"+ctr+"\\" cols=\\"60\\" rows=\\"3\\">"+msg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 1535: }
1536:
1537: function newMsg(newmsg,shwsel) {
1.76 ng 1538: pDoc = pWin.document;
1539: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.465 albertel 1540: pDoc.write("<td align=\\"center\\">New<\\/td>");
1541: pDoc.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1542: pDoc.write("<td><textarea name=\\"newmsg\\" cols=\\"60\\" rows=\\"3\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" >"+newmsg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 1543: }
1544:
1545: function msgTail() {
1.76 ng 1546: pDoc = pWin.document;
1.465 albertel 1547: pDoc.write("<\\/table>");
1548: pDoc.write("<\\/td><\\/tr><\\/table> ");
1.589 bisitz 1549: pDoc.write("<input type=\\"button\\" value=\\"Save\\" onclick=\\"javascript:checkInput()\\"> ");
1550: pDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onclick=\\"self.close()\\"><br /><br />");
1.465 albertel 1551: pDoc.write("<\\/form>");
1.351 albertel 1552: pDoc.write('$end_page_msg_central');
1.128 ng 1553: pDoc.close();
1.44 ng 1554: }
1555:
1556: //====================== Script for keyword highlight options ==============
1557: function kwhighlight() {
1558: var kwclr = document.SCORE.kwclr.value;
1559: var kwsize = document.SCORE.kwsize.value;
1560: var kwstyle = document.SCORE.kwstyle.value;
1561: var redsel = "";
1562: var grnsel = "";
1563: var blusel = "";
1564: if (kwclr=="red") {var redsel="checked"};
1565: if (kwclr=="green") {var grnsel="checked"};
1566: if (kwclr=="blue") {var blusel="checked"};
1567: var sznsel = "";
1568: var sz1sel = "";
1569: var sz2sel = "";
1570: if (kwsize=="0") {var sznsel="checked"};
1571: if (kwsize=="+1") {var sz1sel="checked"};
1572: if (kwsize=="+2") {var sz2sel="checked"};
1573: var synsel = "";
1574: var syisel = "";
1575: var sybsel = "";
1576: if (kwstyle=="") {var synsel="checked"};
1577: if (kwstyle=="<i>") {var syisel="checked"};
1578: if (kwstyle=="<b>") {var sybsel="checked"};
1579: highlightCentral();
1580: highlightbody('red','red',redsel,'0','normal',sznsel,'','normal',synsel);
1581: highlightbody('green','green',grnsel,'+1','+1',sz1sel,'<i>','italic',syisel);
1582: highlightbody('blue','blue',blusel,'+2','+2',sz2sel,'<b>','bold',sybsel);
1583: highlightend();
1584: return;
1585: }
1586:
1587: function highlightCentral() {
1.76 ng 1588: // if (window.hwdWin) window.hwdWin.close();
1.118 ng 1589: var xpos = (screen.width-400)/2;
1590: xpos = (xpos < 0) ? '0' : xpos;
1591: var ypos = (screen.height-330)/2-30;
1592: ypos = (ypos < 0) ? '0' : ypos;
1593:
1.206 albertel 1594: hwdWin = window.open('', 'KeywordHighlightCentral', 'resizeable=yes,toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx='+xpos+',screeny='+ypos);
1.76 ng 1595: hwdWin.focus();
1596: var hDoc = hwdWin.document;
1.219 www 1597: hDoc.$docopen;
1.351 albertel 1598: hDoc.write('$start_page_highlight_central');
1.76 ng 1599: hDoc.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
1.465 albertel 1600: hDoc.write("<h3><span class=\\"LC_info\\"> Keyword Highlight Options<\\/span><\\/h3><br /><br />");
1.76 ng 1601:
1.564 bisitz 1602: hDoc.write('<table border="0" width="100%"><tr><td bgcolor="#777777">');
1603: hDoc.write('<table border="0" width="100%"><tr bgcolor="#DDFFFF">');
1.465 albertel 1604: hDoc.write("<td><b>Text Color<\\/b><\\/td><td><b>Font Size<\\/b><\\/td><td><b>Font Style<\\/td><\\/tr>");
1.44 ng 1605: }
1606:
1607: function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) {
1.76 ng 1608: var hDoc = hwdWin.document;
1609: hDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1610: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1611: hDoc.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+"> "+clrtxt+"<\\/td>");
1.76 ng 1612: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1613: hDoc.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+"> "+sztxt+"<\\/td>");
1.76 ng 1614: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1615: hDoc.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+"> "+sytxt+"<\\/td>");
1616: hDoc.write("<\\/tr>");
1.44 ng 1617: }
1618:
1619: function highlightend() {
1.76 ng 1620: var hDoc = hwdWin.document;
1.465 albertel 1621: hDoc.write("<\\/table>");
1622: hDoc.write("<\\/td><\\/tr><\\/table> ");
1.589 bisitz 1623: hDoc.write("<input type=\\"button\\" value=\\"Save\\" onclick=\\"javascript:updateChoice(1)\\"> ");
1624: hDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onclick=\\"self.close()\\"><br /><br />");
1.465 albertel 1625: hDoc.write("<\\/form>");
1.351 albertel 1626: hDoc.write('$end_page_highlight_central');
1.128 ng 1627: hDoc.close();
1.44 ng 1628: }
1629:
1630: SUBJAVASCRIPT
1631: }
1632:
1.349 albertel 1633: sub get_increment {
1.348 bowersj2 1634: my $increment = $env{'form.increment'};
1635: if ($increment != 1 && $increment != .5 && $increment != .25 &&
1636: $increment != .1) {
1637: $increment = 1;
1638: }
1639: return $increment;
1640: }
1641:
1.585 bisitz 1642: sub gradeBox_start {
1643: return (
1644: &Apache::loncommon::start_data_table()
1645: .&Apache::loncommon::start_data_table_header_row()
1646: .'<th>'.&mt('Part').'</th>'
1647: .'<th>'.&mt('Points').'</th>'
1648: .'<th> </th>'
1649: .'<th>'.&mt('Assign Grade').'</th>'
1650: .'<th>'.&mt('Weight').'</th>'
1651: .'<th>'.&mt('Grade Status').'</th>'
1652: .&Apache::loncommon::end_data_table_header_row()
1653: );
1654: }
1655:
1656: sub gradeBox_end {
1657: return (
1658: &Apache::loncommon::end_data_table()
1659: );
1660: }
1.71 ng 1661: #--- displays the grading box, used in essay type problem and grading by page/sequence
1662: sub gradeBox {
1.322 albertel 1663: my ($request,$symb,$uname,$udom,$counter,$partid,$record) = @_;
1.381 albertel 1664: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 1665: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 1666: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
1.466 albertel 1667: my $wgtmsg = ($wgt > 0) ? &mt('(problem weight)')
1668: : '<span class="LC_info">'.&mt('problem weight assigned by computer').'</span>';
1.71 ng 1669: $wgt = ($wgt > 0 ? $wgt : '1');
1670: my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
1.320 albertel 1671: '' : &compute_points($$record{'resource.'.$partid.'.awarded'},$wgt));
1.71 ng 1672: my $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />'."\n";
1.466 albertel 1673: my $display_part= &get_display_part($partid,$symb);
1.270 albertel 1674: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
1675: [$partid]);
1676: my $aggtries = $$record{'resource.'.$partid.'.tries'};
1.269 raeburn 1677: if ($last_resets{$partid}) {
1678: $aggtries = &get_num_tries($record,$last_resets{$partid},$partid);
1679: }
1.585 bisitz 1680: $result.=&Apache::loncommon::start_data_table_row();
1.71 ng 1681: my $ctr = 0;
1.348 bowersj2 1682: my $thisweight = 0;
1.349 albertel 1683: my $increment = &get_increment();
1.485 albertel 1684:
1685: my $radio.='<table border="0"><tr>'."\n"; # display radio buttons in a nice table 10 across
1.348 bowersj2 1686: while ($thisweight<=$wgt) {
1.532 bisitz 1687: $radio.= '<td><span class="LC_nobreak"><label><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
1.589 bisitz 1688: 'onclick="javascript:writeBox(this.form,\''.$counter.'_'.$partid.'\','.
1.348 bowersj2 1689: $thisweight.')" value="'.$thisweight.'" '.
1.401 albertel 1690: ($score eq $thisweight ? 'checked="checked"':'').' /> '.$thisweight."</label></span></td>\n";
1.485 albertel 1691: $radio.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1.348 bowersj2 1692: $thisweight += $increment;
1.71 ng 1693: $ctr++;
1694: }
1.485 albertel 1695: $radio.='</tr></table>';
1696:
1697: my $line.='<input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
1.71 ng 1698: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
1.589 bisitz 1699: 'onchange="javascript:updateRadio(this.form,\''.$counter.'_'.$partid.'\','.
1.71 ng 1700: $wgt.')" /></td>'."\n";
1.485 albertel 1701: $line.='<td>/'.$wgt.' '.$wgtmsg.
1.71 ng 1702: ($$record{'resource.'.$partid.'.solved'} eq 'correct_by_student' ? ' '.$checkIcon : '').
1.585 bisitz 1703: ' </td>'."\n";
1704: $line.='<td><select name="GD_SEL'.$counter.'_'.$partid.'" '.
1.589 bisitz 1705: 'onchange="javascript:clearRadBox(this.form,\''.$counter.'_'.$partid.'\')" >'."\n";
1.71 ng 1706: if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
1.485 albertel 1707: $line.='<option></option>'.
1708: '<option value="excused" selected="selected">'.&mt('excused').'</option>';
1.71 ng 1709: } else {
1.485 albertel 1710: $line.='<option selected="selected"></option>'.
1711: '<option value="excused" >'.&mt('excused').'</option>';
1.71 ng 1712: }
1.485 albertel 1713: $line.='<option value="reset status">'.&mt('reset status').'</option></select>'."\n";
1714:
1715:
1716: $result .=
1.585 bisitz 1717: '<td>'.$display_part.'</td><td>'.$radio.'</td><td>'.&mt('or').'</td><td>'.$line.'</td>';
1718: $result.=&Apache::loncommon::end_data_table_row();
1.71 ng 1719: $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="" />'."\n".
1720: '<input type="hidden" name="oldpts'.$counter.'_'.$partid.'" value="'.$score.'" />'."\n".
1721: '<input type="hidden" name="solved'.$counter.'_'.$partid.'" value="'.
1.269 raeburn 1722: $$record{'resource.'.$partid.'.solved'}.'" />'."\n".
1723: '<input type="hidden" name="totaltries'.$counter.'_'.$partid.'" value="'.
1724: $$record{'resource.'.$partid.'.tries'}.'" />'."\n".
1725: '<input type="hidden" name="aggtries'.$counter.'_'.$partid.'" value="'.
1726: $aggtries.'" />'."\n";
1.582 raeburn 1727: my $res_error;
1728: $result.=&handback_box($symb,$uname,$udom,$counter,$partid,$record,\$res_error);
1729: if ($res_error) {
1730: return &navmap_errormsg();
1731: }
1.318 banghart 1732: return $result;
1733: }
1.322 albertel 1734:
1735: sub handback_box {
1.623 www 1736: my ($symb,$uname,$udom,$counter,$partid,$record,$res_error_pointer) = @_;
1737: my ($partlist,$handgrade,$responseType) = &response_type($symb,$res_error_pointer);
1.323 banghart 1738: my (@respids);
1.375 albertel 1739: my @part_response_id = &flatten_responseType($responseType);
1740: foreach my $part_response_id (@part_response_id) {
1741: my ($part,$resp) = @{ $part_response_id };
1.323 banghart 1742: if ($part eq $partid) {
1.375 albertel 1743: push(@respids,$resp);
1.323 banghart 1744: }
1745: }
1.318 banghart 1746: my $result;
1.323 banghart 1747: foreach my $respid (@respids) {
1.322 albertel 1748: my $prefix = $counter.'_'.$partid.'_'.$respid.'_';
1749: my $files=&get_submitted_files($udom,$uname,$partid,$respid,$record);
1750: next if (!@$files);
1751: my $file_counter = 1;
1.313 banghart 1752: foreach my $file (@$files) {
1.368 banghart 1753: if ($file =~ /\/portfolio\//) {
1754: my ($file_path, $file_disp) = ($file =~ m|(.+/)(.+)$|);
1755: my ($name,$version,$ext) = &file_name_version_ext($file_disp);
1756: $file_disp = "$name.$ext";
1757: $file = $file_path.$file_disp;
1758: $result.=&mt('Return commented version of [_1] to student.',
1759: '<span class="LC_filename">'.$file_disp.'</span>');
1760: $result.='<input type="file" name="'.$prefix.'returndoc'.$file_counter.'" />'."\n";
1761: $result.='<input type="hidden" name="'.$prefix.'origdoc'.$file_counter.'" value="'.$file.'" /><br />';
1.485 albertel 1762: $result.='('.&mt('File will be uploaded when you click on Save & Next below.').')<br />';
1.368 banghart 1763: $file_counter++;
1764: }
1.322 albertel 1765: }
1.313 banghart 1766: }
1.318 banghart 1767: return $result;
1.71 ng 1768: }
1.44 ng 1769:
1.58 albertel 1770: sub show_problem {
1.382 albertel 1771: my ($request,$symb,$uname,$udom,$removeform,$viewon,$mode,$form) = @_;
1.144 albertel 1772: my $rendered;
1.382 albertel 1773: my %form = ((ref($form) eq 'HASH')? %{$form} : ());
1.329 albertel 1774: &Apache::lonxml::remember_problem_counter();
1.144 albertel 1775: if ($mode eq 'both' or $mode eq 'text') {
1776: $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
1.382 albertel 1777: $env{'request.course.id'},
1778: undef,\%form);
1.144 albertel 1779: }
1.58 albertel 1780: if ($removeform) {
1781: $rendered=~s|<form(.*?)>||g;
1782: $rendered=~s|</form>||g;
1.374 albertel 1783: $rendered=~s|(<input[^>]*name\s*=\s*"?)(\w+)("?)|$1would_have_been_$2$3|g;
1.58 albertel 1784: }
1.144 albertel 1785: my $companswer;
1786: if ($mode eq 'both' or $mode eq 'answer') {
1.329 albertel 1787: &Apache::lonxml::restore_problem_counter();
1.382 albertel 1788: $companswer=
1789: &Apache::loncommon::get_student_answers($symb,$uname,$udom,
1790: $env{'request.course.id'},
1791: %form);
1.144 albertel 1792: }
1.58 albertel 1793: if ($removeform) {
1794: $companswer=~s|<form(.*?)>||g;
1795: $companswer=~s|</form>||g;
1.144 albertel 1796: $companswer=~s|name="submit"|name="would_have_been_submit"|g;
1.58 albertel 1797: }
1.468 albertel 1798: $rendered=
1.588 bisitz 1799: '<div class="LC_Box">'
1800: .'<h3 class="LC_hcell">'.&mt('View of the problem').'</h3>'
1801: .$rendered
1802: .'</div>';
1.468 albertel 1803: $companswer=
1.588 bisitz 1804: '<div class="LC_Box">'
1805: .'<h3 class="LC_hcell">'.&mt('Correct answer').'</h3>'
1806: .$companswer
1807: .'</div>';
1.468 albertel 1808: my $result;
1.144 albertel 1809: if ($mode eq 'both') {
1.588 bisitz 1810: $result=$rendered.$companswer;
1.144 albertel 1811: } elsif ($mode eq 'text') {
1.588 bisitz 1812: $result=$rendered;
1.144 albertel 1813: } elsif ($mode eq 'answer') {
1.588 bisitz 1814: $result=$companswer;
1.144 albertel 1815: }
1.71 ng 1816: return $result;
1.58 albertel 1817: }
1.397 albertel 1818:
1.396 banghart 1819: sub files_exist {
1820: my ($r, $symb) = @_;
1821: my @students = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.397 albertel 1822:
1.396 banghart 1823: foreach my $student (@students) {
1824: my ($uname,$udom,$fullname) = split(/:/,$student);
1.397 albertel 1825: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1826: $udom,$uname);
1.396 banghart 1827: my ($string,$timestamp)= &get_last_submission(\%record);
1.397 albertel 1828: foreach my $submission (@$string) {
1829: my ($partid,$respid) =
1830: ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
1831: my $files=&get_submitted_files($udom,$uname,$partid,$respid,
1832: \%record);
1833: return 1 if (@$files);
1.396 banghart 1834: }
1835: }
1.397 albertel 1836: return 0;
1.396 banghart 1837: }
1.397 albertel 1838:
1.394 banghart 1839: sub download_all_link {
1840: my ($r,$symb) = @_;
1.621 www 1841: unless (&files_exist($r, $symb)) {
1842: $r->print(&mt('There are currently no submitted documents.'));
1843: return;
1844: }
1845:
1.395 albertel 1846: my $all_students =
1847: join("\n", &Apache::loncommon::get_env_multiple('form.stuinfo'));
1848:
1849: my $parts =
1850: join("\n",&Apache::loncommon::get_env_multiple('form.vPart'));
1851:
1.394 banghart 1852: my $identifier = &Apache::loncommon::get_cgi_id();
1.514 raeburn 1853: &Apache::lonnet::appenv({'cgi.'.$identifier.'.students' => $all_students,
1854: 'cgi.'.$identifier.'.symb' => $symb,
1855: 'cgi.'.$identifier.'.parts' => $parts,});
1.395 albertel 1856: $r->print('<a href="/cgi-bin/multidownload.pl?'.$identifier.'">'.
1857: &mt('Download All Submitted Documents').'</a>');
1.621 www 1858: return;
1859: }
1860:
1861: sub submit_download_link {
1862: my ($request,$symb) = @_;
1863: if (!$symb) { return ''; }
1864: #FIXME: Figure out which type of problem this is and provide appropriate download
1865: &download_all_link($request,$symb);
1.394 banghart 1866: }
1.395 albertel 1867:
1.432 banghart 1868: sub build_section_inputs {
1869: my $section_inputs;
1870: if ($env{'form.section'} eq '') {
1871: $section_inputs .= '<input type="hidden" name="section" value="all" />'."\n";
1872: } else {
1873: my @sections = &Apache::loncommon::get_env_multiple('form.section');
1.434 albertel 1874: foreach my $section (@sections) {
1.432 banghart 1875: $section_inputs .= '<input type="hidden" name="section" value="'.$section.'" />'."\n";
1876: }
1877: }
1878: return $section_inputs;
1879: }
1880:
1.44 ng 1881: # --------------------------- show submissions of a student, option to grade
1882: sub submission {
1.608 www 1883: my ($request,$counter,$total,$symb) = @_;
1.257 albertel 1884: my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
1885: $udom = ($udom eq '' ? $env{'user.domain'} : $udom); #has form.userdom changed for a student?
1886: my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
1887: $env{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $env{'form.fullname'} eq '';
1.608 www 1888:
1.605 www 1889: my $probtitle=&Apache::lonnet::gettitle($symb);
1.324 albertel 1890: if ($symb eq '') { $request->print("Unable to handle ambiguous references:."); return ''; }
1.104 albertel 1891:
1892: if (!&canview($usec)) {
1.398 albertel 1893: $request->print('<span class="LC_warning">Unable to view requested student.('.
1894: $uname.':'.$udom.' in section '.$usec.' in course id '.
1895: $env{'request.course.id'}.')</span>');
1.104 albertel 1896: return;
1897: }
1898:
1.257 albertel 1899: if (!$env{'form.lastSub'}) { $env{'form.lastSub'} = 'datesub'; }
1900: if (!$env{'form.vProb'}) { $env{'form.vProb'} = 'yes'; }
1901: if (!$env{'form.vAns'}) { $env{'form.vAns'} = 'yes'; }
1902: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.381 albertel 1903: my $checkIcon = '<img alt="'.&mt('Check Mark').
1904: '" src="'.$request->dir_config('lonIconsURL').
1.122 ng 1905: '/check.gif" height="16" border="0" />';
1.41 ng 1906:
1.426 albertel 1907: my %old_essays;
1.41 ng 1908: # header info
1909: if ($counter == 0) {
1910: &sub_page_js($request);
1.621 www 1911: &sub_page_kw_js($request);
1.605 www 1912: $request->print('<h3> <span class="LC_info">'.&mt('Submission Record').'</span></h3>');
1.118 ng 1913:
1.44 ng 1914: # option to display problem, only once else it cause problems
1915: # with the form later since the problem has a form.
1.257 albertel 1916: if ($env{'form.vProb'} eq 'yes' or $env{'form.vAns'} eq 'yes') {
1.144 albertel 1917: my $mode;
1.257 albertel 1918: if ($env{'form.vProb'} eq 'yes' && $env{'form.vAns'} eq 'yes') {
1.144 albertel 1919: $mode='both';
1.257 albertel 1920: } elsif ($env{'form.vProb'} eq 'yes') {
1.144 albertel 1921: $mode='text';
1.257 albertel 1922: } elsif ($env{'form.vAns'} eq 'yes') {
1.144 albertel 1923: $mode='answer';
1924: }
1.329 albertel 1925: &Apache::lonxml::clear_problem_counter();
1.144 albertel 1926: $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
1.41 ng 1927: }
1.441 www 1928:
1.44 ng 1929: # kwclr is the only variable that is guaranteed to be non blank
1930: # if this subroutine has been called once.
1.41 ng 1931: my %keyhash = ();
1.624 ! www 1932: # if ($env{'form.kwclr'} eq '' && $env{'form.handgrade'} eq 'yes') {
! 1933: if (1) {
1.41 ng 1934: %keyhash = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 1935: $env{'course.'.$env{'request.course.id'}.'.domain'},
1936: $env{'course.'.$env{'request.course.id'}.'.num'});
1.41 ng 1937:
1.257 albertel 1938: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1939: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
1940: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
1941: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
1942: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
1943: $env{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
1.605 www 1944: $keyhash{$symb.'_subject'} : $probtitle;
1.257 albertel 1945: $env{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1.41 ng 1946: }
1.257 albertel 1947: my $overRideScore = $env{'form.overRideScore'} eq '' ? 'no' : $env{'form.overRideScore'};
1.442 banghart 1948: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.303 banghart 1949: $request->print('<form action="/adm/grades" method="post" name="SCORE" enctype="multipart/form-data">'."\n".
1.41 ng 1950: '<input type="hidden" name="command" value="handgrade" />'."\n".
1.442 banghart 1951: '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.120 ng 1952: '<input type="hidden" name="overRideScore" value="'.$overRideScore.'" />'."\n".
1.41 ng 1953: '<input type="hidden" name="refresh" value="off" />'."\n".
1.120 ng 1954: '<input type="hidden" name="studentNo" value="" />'."\n".
1955: '<input type="hidden" name="gradeOpt" value="" />'."\n".
1.418 albertel 1956: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 1957: '<input type="hidden" name="vProb" value="'.$env{'form.vProb'}.'" />'."\n".
1958: '<input type="hidden" name="vAns" value="'.$env{'form.vAns'}.'" />'."\n".
1959: '<input type="hidden" name="lastSub" value="'.$env{'form.lastSub'}.'" />'."\n".
1.432 banghart 1960: &build_section_inputs().
1.326 albertel 1961: '<input type="hidden" name="submitonly" value="'.$env{'form.submitonly'}.'" />'."\n".
1.41 ng 1962: '<input type="hidden" name="NCT"'.
1.257 albertel 1963: ' value="'.($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : $total+1).'" />'."\n");
1.624 ! www 1964: # if ($env{'form.handgrade'} eq 'yes') {
! 1965: if (1) {
1.257 albertel 1966: $request->print('<input type="hidden" name="keywords" value="'.$env{'form.keywords'}.'" />'."\n".
1967: '<input type="hidden" name="kwclr" value="'.$env{'form.kwclr'}.'" />'."\n".
1968: '<input type="hidden" name="kwsize" value="'.$env{'form.kwsize'}.'" />'."\n".
1969: '<input type="hidden" name="kwstyle" value="'.$env{'form.kwstyle'}.'" />'."\n".
1970: '<input type="hidden" name="msgsub" value="'.$env{'form.msgsub'}.'" />'."\n".
1.123 ng 1971: '<input type="hidden" name="shownSub" value="0" />'."\n".
1.257 albertel 1972: '<input type="hidden" name="savemsgN" value="'.$env{'form.savemsgN'}.'" />'."\n");
1.154 albertel 1973: foreach my $partid (&Apache::loncommon::get_env_multiple('form.vPart')) {
1974: $request->print('<input type="hidden" name="vPart" value="'.$partid.'" />'."\n");
1975: }
1.123 ng 1976: }
1.41 ng 1977:
1978: my ($cts,$prnmsg) = (1,'');
1.257 albertel 1979: while ($cts <= $env{'form.savemsgN'}) {
1.41 ng 1980: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
1.123 ng 1981: (!exists($keyhash{$symb.'_savemsg'.$cts}) ?
1.257 albertel 1982: &Apache::lonfeedback::clear_out_html($env{'form.savemsg'.$cts}) :
1.80 ng 1983: &Apache::lonfeedback::clear_out_html($keyhash{$symb.'_savemsg'.$cts})).
1.123 ng 1984: '" />'."\n".
1985: '<input type="hidden" name="shownOnce'.$cts.'" value="0" />'."\n";
1.41 ng 1986: $cts++;
1987: }
1988: $request->print($prnmsg);
1.32 ng 1989:
1.624 ! www 1990: # if ($env{'form.handgrade'} eq 'yes') {
! 1991: if (1) {
1.88 www 1992: #
1993: # Print out the keyword options line
1994: #
1.41 ng 1995: $request->print(<<KEYWORDS);
1.38 ng 1996: <b>Keyword Options:</b>
1.417 albertel 1997: <a href="javascript:keywords(document.SCORE);" target="_self">List</a>
1.589 bisitz 1998: <a href="#" onmousedown="javascript:getSel(); return false"
1.38 ng 1999: CLASS="page">Paste Selection to List</a>
1.417 albertel 2000: <a href="javascript:kwhighlight();" target="_self">Highlight Attribute</a><br /><br />
1.38 ng 2001: KEYWORDS
1.88 www 2002: #
2003: # Load the other essays for similarity check
2004: #
1.324 albertel 2005: my (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb);
1.384 albertel 2006: my ($adom,$aname,$apath)=($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
1.359 www 2007: $apath=&escape($apath);
1.88 www 2008: $apath=~s/\W/\_/gs;
1.426 albertel 2009: %old_essays=&Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
1.41 ng 2010: }
2011: }
1.44 ng 2012:
1.441 www 2013: # This is where output for one specific student would start
1.592 bisitz 2014: my $add_class = ($counter%2) ? ' LC_grade_show_user_odd_row' : '';
2015: $request->print(
2016: "\n\n"
2017: .'<div class="LC_grade_show_user'.$add_class.'">'
2018: .'<h2>'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).'</h2>'
2019: ."\n"
2020: );
1.441 www 2021:
1.592 bisitz 2022: # Show additional functions if allowed
2023: if ($perm{'vgr'}) {
2024: $request->print(
2025: &Apache::loncommon::track_student_link(
2026: &mt('View recent activity'),
2027: $uname,$udom,'check')
2028: .' '
2029: );
2030: }
2031: if ($perm{'opa'}) {
2032: $request->print(
2033: &Apache::loncommon::pprmlink(
2034: &mt('Set/Change parameters'),
2035: $uname,$udom,$symb,'check'));
2036: }
2037:
2038: # Show Problem
1.257 albertel 2039: if ($env{'form.vProb'} eq 'all' or $env{'form.vAns'} eq 'all') {
1.144 albertel 2040: my $mode;
1.257 albertel 2041: if ($env{'form.vProb'} eq 'all' && $env{'form.vAns'} eq 'all') {
1.144 albertel 2042: $mode='both';
1.257 albertel 2043: } elsif ($env{'form.vProb'} eq 'all' ) {
1.144 albertel 2044: $mode='text';
1.257 albertel 2045: } elsif ($env{'form.vAns'} eq 'all') {
1.144 albertel 2046: $mode='answer';
2047: }
1.329 albertel 2048: &Apache::lonxml::clear_problem_counter();
1.475 albertel 2049: $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode,{'request.prefix' => 'ctr'.$counter}));
1.58 albertel 2050: }
1.144 albertel 2051:
1.257 albertel 2052: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.582 raeburn 2053: my $res_error;
2054: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
2055: if ($res_error) {
2056: $request->print(&navmap_errormsg());
2057: return;
2058: }
1.41 ng 2059:
1.44 ng 2060: # Display student info
1.41 ng 2061: $request->print(($counter == 0 ? '' : '<br />'));
1.590 bisitz 2062:
2063: my $result='<div class="LC_Box">'
2064: .'<h3 class="LC_hcell">'.&mt('Submissions').'</h3>';
1.45 ng 2065: $result.='<input type="hidden" name="name'.$counter.
1.588 bisitz 2066: '" value="'.$env{'form.fullname'}.'" />'."\n";
1.624 ! www 2067: # if ($env{'form.handgrade'} eq 'no') {
! 2068: if (1) {
1.588 bisitz 2069: $result.='<p class="LC_info">'
2070: .&mt('Part(s) graded correct by the computer is marked with a [_1] symbol.',$checkIcon)
2071: ."</p>\n";
1.469 albertel 2072: }
2073:
1.118 ng 2074: # If any part of the problem is an essay-response (handgraded), then check for collaborators
1.464 albertel 2075: my $fullname;
2076: my $col_fullnames = [];
1.624 ! www 2077: # if ($env{'form.handgrade'} eq 'yes') {
! 2078: if (1) {
1.464 albertel 2079: (my $sub_result,$fullname,$col_fullnames)=
2080: &check_collaborators($symb,$uname,$udom,\%record,$handgrade,
2081: $counter);
2082: $result.=$sub_result;
1.41 ng 2083: }
1.44 ng 2084: $request->print($result."\n");
1.588 bisitz 2085:
1.44 ng 2086: # print student answer/submission
1.588 bisitz 2087: # Options are (1) Handgraded submission only
1.44 ng 2088: # (2) Last submission, includes submission that is not handgraded
2089: # (for multi-response type part)
2090: # (3) Last submission plus the parts info
2091: # (4) The whole record for this student
1.257 albertel 2092: if ($env{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
1.151 albertel 2093: my ($string,$timestamp)= &get_last_submission(\%record);
1.468 albertel 2094:
2095: my $lastsubonly;
2096:
1.588 bisitz 2097: if ($$timestamp eq '') {
2098: $lastsubonly.='<div class="LC_grade_submissions_body">'.$$string[0].'</div>';
2099: } else {
1.592 bisitz 2100: $lastsubonly =
2101: '<div class="LC_grade_submissions_body">'
2102: .'<b>'.&mt('Date Submitted:').'</b> '.$$timestamp."\n";
1.468 albertel 2103:
1.151 albertel 2104: my %seenparts;
1.375 albertel 2105: my @part_response_id = &flatten_responseType($responseType);
2106: foreach my $part (@part_response_id) {
1.393 albertel 2107: next if ($env{'form.lastSub'} eq 'hdgrade'
2108: && $$handgrade{$$part[0].'_'.$$part[1]} ne 'yes');
2109:
1.375 albertel 2110: my ($partid,$respid) = @{ $part };
1.324 albertel 2111: my $display_part=&get_display_part($partid,$symb);
1.257 albertel 2112: if ($env{"form.$uname:$udom:$partid:submitted_by"}) {
1.151 albertel 2113: if (exists($seenparts{$partid})) { next; }
2114: $seenparts{$partid}=1;
1.207 albertel 2115: my $submitby='<b>Part:</b> '.$display_part.
2116: ' <b>Collaborative submission by:</b> '.
1.151 albertel 2117: '<a href="javascript:viewSubmitter(\''.
1.257 albertel 2118: $env{"form.$uname:$udom:$partid:submitted_by"}.
1.417 albertel 2119: '\');" target="_self">'.
1.257 albertel 2120: $$fullname{$env{"form.$uname:$udom:$partid:submitted_by"}}.'</a><br />';
1.151 albertel 2121: $request->print($submitby);
2122: next;
2123: }
2124: my $responsetype = $responseType->{$partid}->{$respid};
2125: if (!exists($record{"resource.$partid.$respid.submission"})) {
1.577 bisitz 2126: $lastsubonly.="\n".'<div class="LC_grade_submission_part">'.
2127: '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
2128: ' <span class="LC_internal_info">'.
1.623 www 2129: '('.&mt('Response ID: [_1]',$respid).')'.
1.577 bisitz 2130: '</span> '.
1.539 riegler 2131: '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br /><br /></div>';
1.151 albertel 2132: next;
2133: }
1.468 albertel 2134: foreach my $submission (@$string) {
2135: my ($partid,$respid) = ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
1.375 albertel 2136: if (join('_',@{$part}) ne ($partid.'_'.$respid)) { next; }
1.596 raeburn 2137: my ($ressub,$hide,$subval) = split(/:/,$submission,3);
1.151 albertel 2138: # Similarity check
2139: my $similar='';
1.257 albertel 2140: if($env{'form.checkPlag'}){
1.151 albertel 2141: my ($oname,$odom,$ocrsid,$oessay,$osim)=
1.426 albertel 2142: &most_similar($uname,$udom,$subval,\%old_essays);
1.151 albertel 2143: if ($osim) {
2144: $osim=int($osim*100.0);
1.426 albertel 2145: my %old_course_desc =
2146: &Apache::lonnet::coursedescription($ocrsid,
2147: {'one_time' => 1});
2148:
1.596 raeburn 2149: if ($hide) {
2150: $similar='<hr /><span class="LC_warning">'.&mt("Essay was found to be similar to another essay submitted for this assignment.").'<br />'.
2151: &mt('As the current submission is for an anonymous survey, no other details are available.').'</span><hr />';
2152: } else {
2153: $similar="<hr /><h3><span class=\"LC_warning\">".
2154: &mt('Essay is [_1]% similar to an essay by [_2] in course [_3] (course id [_4]:[_5])',
2155: $osim,
2156: &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')',
2157: $old_course_desc{'description'},
2158: $old_course_desc{'num'},
2159: $old_course_desc{'domain'}).
2160: '</span></h3><blockquote><i>'.
2161: &keywords_highlight($oessay).
2162: '</i></blockquote><hr />';
2163: }
1.151 albertel 2164: }
1.150 albertel 2165: }
1.151 albertel 2166: my $order=&get_order($partid,$respid,$symb,$uname,$udom);
1.257 albertel 2167: if ($env{'form.lastSub'} eq 'lastonly' ||
2168: ($env{'form.lastSub'} eq 'hdgrade' &&
1.377 albertel 2169: $$handgrade{$$part[0].'_'.$$part[1]} eq 'yes')) {
1.324 albertel 2170: my $display_part=&get_display_part($partid,$symb);
1.577 bisitz 2171: $lastsubonly.='<div class="LC_grade_submission_part">'.
2172: '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
2173: ' <span class="LC_internal_info">'.
1.623 www 2174: '('.&mt('Response ID: [_1]',$respid).')'.
1.597 wenzelju 2175: '</span> ';
1.313 banghart 2176: my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record);
2177: if (@$files) {
1.596 raeburn 2178: if ($hide) {
2179: $lastsubonly.='<br />'.&mt('[quant,_1,file] uploaded to this anonymous survey',scalar(@{$files}));
2180: } else {
2181: $lastsubonly.='<br /><span class="LC_warning">'.&mt('Like all files provided by users, this file may contain viruses').'</span><br />';
2182: foreach my $file (@$files) {
2183: &Apache::lonnet::allowuploaded('/adm/grades',$file);
2184: $lastsubonly.='<br /><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.&Apache::loncommon::icon($file).'" border="0" /> '.$file.'</a>';
2185: }
2186: }
1.236 albertel 2187: $lastsubonly.='<br />';
1.41 ng 2188: }
1.596 raeburn 2189: if ($hide) {
2190: $lastsubonly.='<b>'.&mt('Anonymous Survey').'</b>';
2191: } else {
2192: $lastsubonly.='<b>'.&mt('Submitted Answer:').' </b>'.
2193: &cleanRecord($subval,$responsetype,$symb,$partid,
2194: $respid,\%record,$order,undef,$uname,$udom);
2195: }
1.151 albertel 2196: if ($similar) {$lastsubonly.="<br /><br />$similar\n";}
1.468 albertel 2197: $lastsubonly.='</div>';
1.41 ng 2198: }
2199: }
2200: }
1.588 bisitz 2201: $lastsubonly.='</div>'."\n"; # End: LC_grade_submissions_body
1.151 albertel 2202: }
2203: $request->print($lastsubonly);
1.468 albertel 2204: } elsif ($env{'form.lastSub'} eq 'datesub') {
1.623 www 2205: my ($parts,$handgrade,$responseType) = &response_type($symb,\$res_error);
1.148 albertel 2206: $request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
1.257 albertel 2207: } elsif ($env{'form.lastSub'} =~ /^(last|all)$/) {
1.41 ng 2208: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
1.257 albertel 2209: $env{'request.course.id'},
1.44 ng 2210: $last,'.submission',
2211: 'Apache::grades::keywords_highlight'));
1.41 ng 2212: }
1.121 ng 2213: $request->print('<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
2214: .$udom.'" />'."\n");
1.44 ng 2215: # return if view submission with no grading option
1.619 www 2216: # FIXME: the logic seems off here. Why show the grade button if you cannot grade?
1.618 www 2217: if (!&canmodify($usec)) {
1.120 ng 2218: my $toGrade.='<input type="button" value="Grade Student" '.
1.589 bisitz 2219: 'onclick="javascript:checksubmit(this.form,\'Grade Student\',\''
1.417 albertel 2220: .$counter.'\');" target="_self" /> '."\n" if (&canmodify($usec));
1.468 albertel 2221: $toGrade.='</div>'."\n";
1.180 albertel 2222: $request->print($toGrade);
1.41 ng 2223: return;
1.180 albertel 2224: } else {
1.468 albertel 2225: $request->print('</div>'."\n");
1.41 ng 2226: }
1.33 ng 2227:
1.121 ng 2228: # essay grading message center
1.624 ! www 2229: # if ($env{'form.handgrade'} eq 'yes') {
! 2230: if (1) {
1.468 albertel 2231: my $result='<div class="LC_grade_message_center">';
2232:
2233: $result.='<div class="LC_grade_message_center_header">'.
2234: &mt('Send Message').'</div><div class="LC_grade_message_center_body">';
1.257 albertel 2235: my ($lastname,$givenn) = split(/,/,$env{'form.fullname'});
1.118 ng 2236: my $msgfor = $givenn.' '.$lastname;
1.464 albertel 2237: if (scalar(@$col_fullnames) > 0) {
2238: my $lastone = pop(@$col_fullnames);
2239: $msgfor .= ', '.(join ', ',@$col_fullnames).' and '.$lastone.'.';
1.118 ng 2240: }
2241: $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
1.468 albertel 2242: $result.='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
1.121 ng 2243: '<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n";
2244: $result.=' <a href="javascript:msgCenter(document.SCORE,'.$counter.
1.417 albertel 2245: ',\''.$msgfor.'\');" target="_self">'.
1.464 albertel 2246: &mt('Compose message to student').(scalar(@$col_fullnames) >= 1 ? 's' : '').'</a><label> ('.
1.350 albertel 2247: &mt('incl. grades').' <input type="checkbox" name="withgrades'.$counter.'" /></label>)'.
1.118 ng 2248: '<img src="'.$request->dir_config('lonIconsURL').
2249: '/mailbkgrd.gif" width="14" height="10" name="mailicon'.$counter.'" />'."\n".
1.298 www 2250: '<br /> ('.
1.468 albertel 2251: &mt('Message will be sent when you click on Save & Next below.').")\n";
2252: $result.='</div></div>';
1.121 ng 2253: $request->print($result);
1.118 ng 2254: }
1.41 ng 2255:
2256: my %seen = ();
2257: my @partlist;
1.129 ng 2258: my @gradePartRespid;
1.375 albertel 2259: my @part_response_id = &flatten_responseType($responseType);
1.585 bisitz 2260: $request->print(
1.588 bisitz 2261: '<div class="LC_Box">'
2262: .'<h3 class="LC_hcell">'.&mt('Assign Grades').'</h3>'
1.585 bisitz 2263: );
1.592 bisitz 2264: $request->print(&gradeBox_start());
1.375 albertel 2265: foreach my $part_response_id (@part_response_id) {
2266: my ($partid,$respid) = @{ $part_response_id };
2267: my $part_resp = join('_',@{ $part_response_id });
1.322 albertel 2268: next if ($seen{$partid} > 0);
1.41 ng 2269: $seen{$partid}++;
1.393 albertel 2270: next if ($$handgrade{$part_resp} ne 'yes'
2271: && $env{'form.lastSub'} eq 'hdgrade');
1.524 raeburn 2272: push(@partlist,$partid);
2273: push(@gradePartRespid,$partid.'.'.$respid);
1.322 albertel 2274: $request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
1.41 ng 2275: }
1.585 bisitz 2276: $request->print(&gradeBox_end()); # </div>
2277: $request->print('</div>');
1.468 albertel 2278:
2279: $request->print('<div class="LC_grade_info_links">');
2280: $request->print('</div>');
2281:
1.45 ng 2282: $result='<input type="hidden" name="partlist'.$counter.
2283: '" value="'.(join ":",@partlist).'" />'."\n";
1.129 ng 2284: $result.='<input type="hidden" name="gradePartRespid'.
2285: '" value="'.(join ":",@gradePartRespid).'" />'."\n" if ($counter == 0);
1.45 ng 2286: my $ctr = 0;
2287: while ($ctr < scalar(@partlist)) {
2288: $result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
2289: $partlist[$ctr].'" />'."\n";
2290: $ctr++;
2291: }
1.468 albertel 2292: $request->print($result.''."\n");
1.41 ng 2293:
1.441 www 2294: # Done with printing info for one student
2295:
1.468 albertel 2296: $request->print('</div>');#LC_grade_show_user
1.441 www 2297:
2298:
1.41 ng 2299: # print end of form
2300: if ($counter == $total) {
1.592 bisitz 2301: my $endform='<br /><hr /><table border="0"><tr><td>'."\n";
1.485 albertel 2302: $endform.='<input type="button" value="'.&mt('Save & Next').'" '.
1.589 bisitz 2303: 'onclick="javascript:checksubmit(this.form,\'Save & Next\','.
1.417 albertel 2304: $total.','.scalar(@partlist).');" target="_self" /> '."\n";
1.119 ng 2305: my $ntstu ='<select name="NTSTU">'.
2306: '<option>1</option><option>2</option>'.
2307: '<option>3</option><option>5</option>'.
2308: '<option>7</option><option>10</option></select>'."\n";
1.257 albertel 2309: my $nsel = ($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : '1');
1.401 albertel 2310: $ntstu =~ s/<option>$nsel</<option selected="selected">$nsel</;
1.578 raeburn 2311: $endform.=&mt('[_1]student(s)',$ntstu);
1.485 albertel 2312: $endform.=' <input type="button" value="'.&mt('Previous').'" '.
1.589 bisitz 2313: 'onclick="javascript:checksubmit(this.form,\'Previous\');" target="_self" /> '."\n".
1.485 albertel 2314: '<input type="button" value="'.&mt('Next').'" '.
1.589 bisitz 2315: 'onclick="javascript:checksubmit(this.form,\'Next\');" target="_self" /> ';
1.592 bisitz 2316: $endform.='<span class="LC_warning">'.
2317: &mt('(Next and Previous (student) do not save the scores.)').
2318: '</span>'."\n" ;
1.349 albertel 2319: $endform.="<input type='hidden' value='".&get_increment().
1.348 bowersj2 2320: "' name='increment' />";
1.485 albertel 2321: $endform.='</td></tr></table></form>';
1.41 ng 2322: $request->print($endform);
2323: }
2324: return '';
1.38 ng 2325: }
2326:
1.464 albertel 2327: sub check_collaborators {
2328: my ($symb,$uname,$udom,$record,$handgrade,$counter) = @_;
2329: my ($result,@col_fullnames);
2330: my ($classlist,undef,$fullname) = &getclasslist('all','0');
2331: foreach my $part (keys(%$handgrade)) {
2332: my $ncol = &Apache::lonnet::EXT('resource.'.$part.
2333: '.maxcollaborators',
2334: $symb,$udom,$uname);
2335: next if ($ncol <= 0);
2336: $part =~ s/\_/\./g;
2337: next if ($record->{'resource.'.$part.'.collaborators'} eq '');
2338: my (@good_collaborators, @bad_collaborators);
2339: foreach my $possible_collaborator
2340: (split(/,?\s+/,$record->{'resource.'.$part.'.collaborators'})) {
2341: $possible_collaborator =~ s/[\$\^\(\)]//g;
2342: next if ($possible_collaborator eq '');
2343: my ($co_name,$co_dom) = split(/\@|:/,$possible_collaborator);
2344: $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
2345: next if ($co_name eq $uname && $co_dom eq $udom);
2346: # Doing this grep allows 'fuzzy' specification
2347: my @matches = grep(/^\Q$co_name\E:\Q$co_dom\E$/i,
2348: keys(%$classlist));
2349: if (! scalar(@matches)) {
2350: push(@bad_collaborators, $possible_collaborator);
2351: } else {
2352: push(@good_collaborators, @matches);
2353: }
2354: }
2355: if (scalar(@good_collaborators) != 0) {
1.466 albertel 2356: $result.='<br />'.&mt('Collaborators: ');
1.464 albertel 2357: foreach my $name (@good_collaborators) {
2358: my ($lastname,$givenn) = split(/,/,$$fullname{$name});
2359: push(@col_fullnames, $givenn.' '.$lastname);
2360: $result.=$fullname->{$name}.' ';
2361: }
2362: $result.='<br />'."\n";
1.466 albertel 2363: my ($part)=split(/\./,$part);
1.464 albertel 2364: $result.='<input type="hidden" name="collaborator'.$counter.
2365: '" value="'.$part.':'.(join ':',@good_collaborators).'" />'.
2366: "\n";
2367: }
2368: if (scalar(@bad_collaborators) > 0) {
1.466 albertel 2369: $result.='<div class="LC_warning">';
1.464 albertel 2370: $result.=&mt('This student has submitted [quant,_1,invalid collaborator]: [_2]',scalar(@bad_collaborators),join(', ',@bad_collaborators));
2371: $result .= '</div>';
2372: }
2373: if (scalar(@bad_collaborators > $ncol)) {
1.466 albertel 2374: $result .= '<div class="LC_warning">';
1.464 albertel 2375: $result .= &mt('This student has submitted too many '.
2376: 'collaborators. Maximum is [_1].',$ncol);
2377: $result .= '</div>';
2378: }
2379: }
2380: return ($result,$fullname,\@col_fullnames);
2381: }
2382:
1.44 ng 2383: #--- Retrieve the last submission for all the parts
1.38 ng 2384: sub get_last_submission {
1.119 ng 2385: my ($returnhash)=@_;
1.596 raeburn 2386: my (@string,$timestamp,%lasthidden);
1.119 ng 2387: if ($$returnhash{'version'}) {
1.46 ng 2388: my %lasthash=();
2389: my ($version);
1.119 ng 2390: for ($version=1;$version<=$$returnhash{'version'};$version++) {
1.397 albertel 2391: foreach my $key (sort(split(/\:/,
2392: $$returnhash{$version.':keys'}))) {
2393: $lasthash{$key}=$$returnhash{$version.':'.$key};
2394: $timestamp =
1.545 raeburn 2395: &Apache::lonlocal::locallocaltime($$returnhash{$version.':timestamp'});
1.46 ng 2396: }
2397: }
1.596 raeburn 2398: my %typeparts;
2399: my $showsurv =
2400: &Apache::lonnet::allowed('vas',$env{'request.course.id'});
2401: foreach my $key (sort(keys(%lasthash))) {
2402: if ($key =~ /\.type$/) {
2403: if (($lasthash{$key} eq 'anonsurvey') ||
2404: ($lasthash{$key} eq 'anonsurveycred')) {
2405: my ($ign,@parts) = split(/\./,$key);
2406: pop(@parts);
2407: unless ($showsurv) {
2408: my $id = join(',',@parts);
2409: $typeparts{$ign.'.'.$id} = $lasthash{$key};
2410: }
2411: delete($lasthash{$key});
2412: }
2413: }
2414: }
2415: my @hidden = keys(%typeparts);
1.397 albertel 2416: foreach my $key (keys(%lasthash)) {
2417: next if ($key !~ /\.submission$/);
1.596 raeburn 2418: my $hide;
2419: if (@hidden) {
2420: foreach my $id (@hidden) {
2421: if ($key =~ /^\Q$id\E/) {
2422: $hide = 1;
2423: last;
2424: }
2425: }
2426: }
1.397 albertel 2427: my ($partid,$foo) = split(/submission$/,$key);
2428: my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
1.398 albertel 2429: '<span class="LC_warning">Draft Copy</span> ' : '';
1.596 raeburn 2430: push(@string, join(':', $key, $hide, $draft.$lasthash{$key}));
1.41 ng 2431: }
2432: }
1.397 albertel 2433: if (!@string) {
2434: $string[0] =
1.539 riegler 2435: '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span>';
1.397 albertel 2436: }
2437: return (\@string,\$timestamp);
1.38 ng 2438: }
1.35 ng 2439:
1.44 ng 2440: #--- High light keywords, with style choosen by user.
1.38 ng 2441: sub keywords_highlight {
1.44 ng 2442: my $string = shift;
1.257 albertel 2443: my $size = $env{'form.kwsize'} eq '0' ? '' : 'size='.$env{'form.kwsize'};
2444: my $styleon = $env{'form.kwstyle'} eq '' ? '' : $env{'form.kwstyle'};
1.41 ng 2445: (my $styleoff = $styleon) =~ s/\</\<\//;
1.257 albertel 2446: my @keylist = split(/[,\s+]/,$env{'form.keywords'});
1.398 albertel 2447: foreach my $keyword (@keylist) {
2448: $string =~ s/\b\Q$keyword\E(\b|\.)/<font color\=$env{'form.kwclr'} $size\>$styleon$keyword$styleoff<\/font>/gi;
1.41 ng 2449: }
2450: return $string;
1.38 ng 2451: }
1.36 ng 2452:
1.44 ng 2453: #--- Called from submission routine
1.38 ng 2454: sub processHandGrade {
1.608 www 2455: my ($request,$symb) = @_;
1.324 albertel 2456: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.257 albertel 2457: my $button = $env{'form.gradeOpt'};
2458: my $ngrade = $env{'form.NCT'};
2459: my $ntstu = $env{'form.NTSTU'};
1.301 albertel 2460: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2461: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2462:
1.44 ng 2463: if ($button eq 'Save & Next') {
2464: my $ctr = 0;
2465: while ($ctr < $ngrade) {
1.257 albertel 2466: my ($uname,$udom) = split(/:/,$env{'form.unamedom'.$ctr});
1.324 albertel 2467: my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$symb,$uname,$udom,$ctr);
1.71 ng 2468: if ($errorflag eq 'no_score') {
2469: $ctr++;
2470: next;
2471: }
1.104 albertel 2472: if ($errorflag eq 'not_allowed') {
1.398 albertel 2473: $request->print("<span class=\"LC_warning\">Not allowed to modify grades for $uname:$udom</span>");
1.104 albertel 2474: $ctr++;
2475: next;
2476: }
1.257 albertel 2477: my $includemsg = $env{'form.includemsg'.$ctr};
1.44 ng 2478: my ($subject,$message,$msgstatus) = ('','','');
1.418 albertel 2479: my $restitle = &Apache::lonnet::gettitle($symb);
2480: my ($feedurl,$showsymb) =
2481: &get_feedurl_and_symb($symb,$uname,$udom);
2482: my $messagetail;
1.62 albertel 2483: if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.298 www 2484: $subject = $env{'form.msgsub'} if ($includemsg =~ /msgsub/);
1.295 www 2485: unless ($subject=~/\w/) { $subject=&mt('Grading Feedback'); }
1.386 raeburn 2486: $subject.=' ['.$restitle.']';
1.44 ng 2487: my (@msgnum) = split(/,/,$includemsg);
2488: foreach (@msgnum) {
1.257 albertel 2489: $message.=$env{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
1.44 ng 2490: }
1.80 ng 2491: $message =&Apache::lonfeedback::clear_out_html($message);
1.298 www 2492: if ($env{'form.withgrades'.$ctr}) {
2493: $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
1.386 raeburn 2494: $messagetail = " for <a href=\"".
1.605 www 2495: $feedurl."?symb=$showsymb\">$restitle</a>";
1.386 raeburn 2496: }
2497: $msgstatus =
2498: &Apache::lonmsg::user_normal_msg($uname,$udom,$subject,
2499: $message.$messagetail,
1.418 albertel 2500: undef,$feedurl,undef,
1.386 raeburn 2501: undef,undef,$showsymb,
2502: $restitle);
1.574 bisitz 2503: $request->print('<br />'.&mt('Sending message to [_1]',$uname.':'.$udom).': '.
1.296 www 2504: $msgstatus);
1.44 ng 2505: }
1.257 albertel 2506: if ($env{'form.collaborator'.$ctr}) {
1.155 albertel 2507: my @collabstrs=&Apache::loncommon::get_env_multiple("form.collaborator$ctr");
1.150 albertel 2508: foreach my $collabstr (@collabstrs) {
2509: my ($part,@collaborators) = split(/:/,$collabstr);
1.310 banghart 2510: foreach my $collaborator (@collaborators) {
1.150 albertel 2511: my ($errorflag,$pts,$wgt) =
1.324 albertel 2512: &saveHandGrade($request,$symb,$collaborator,$udom,$ctr,
1.257 albertel 2513: $env{'form.unamedom'.$ctr},$part);
1.150 albertel 2514: if ($errorflag eq 'not_allowed') {
1.362 albertel 2515: $request->print("<span class=\"LC_error\">".&mt('Not allowed to modify grades for [_1]',"$collaborator:$udom")."</span>");
1.150 albertel 2516: next;
1.418 albertel 2517: } elsif ($message ne '') {
2518: my ($baseurl,$showsymb) =
2519: &get_feedurl_and_symb($symb,$collaborator,
2520: $udom);
2521: if ($env{'form.withgrades'.$ctr}) {
2522: $messagetail = " for <a href=\"".
1.605 www 2523: $baseurl."?symb=$showsymb\">$restitle</a>";
1.150 albertel 2524: }
1.418 albertel 2525: $msgstatus =
2526: &Apache::lonmsg::user_normal_msg($collaborator,$udom,$subject,$message.$messagetail,undef,$baseurl,undef,undef,undef,$showsymb,$restitle);
1.104 albertel 2527: }
1.44 ng 2528: }
2529: }
2530: }
2531: $ctr++;
2532: }
2533: }
2534:
1.624 ! www 2535: # if ($env{'form.handgrade'} eq 'yes') {
! 2536: if (1) {
1.119 ng 2537: # Keywords sorted in alphabatical order
1.257 albertel 2538: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1.119 ng 2539: my %keyhash = ();
1.257 albertel 2540: $env{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
2541: $env{'form.keywords'} =~ s/^\s+|\s+$//;
2542: my (@keywords) = sort(split(/\s+/,$env{'form.keywords'}));
2543: $env{'form.keywords'} = join(' ',@keywords);
2544: $keyhash{$symb.'_keywords'} = $env{'form.keywords'};
2545: $keyhash{$symb.'_subject'} = $env{'form.msgsub'};
2546: $keyhash{$loginuser.'_kwclr'} = $env{'form.kwclr'};
2547: $keyhash{$loginuser.'_kwsize'} = $env{'form.kwsize'};
2548: $keyhash{$loginuser.'_kwstyle'} = $env{'form.kwstyle'};
1.119 ng 2549:
2550: # message center - Order of message gets changed. Blank line is eliminated.
1.257 albertel 2551: # New messages are saved in env for the next student.
1.119 ng 2552: # All messages are saved in nohist_handgrade.db
2553: my ($ctr,$idx) = (1,1);
1.257 albertel 2554: while ($ctr <= $env{'form.savemsgN'}) {
2555: if ($env{'form.savemsg'.$ctr} ne '') {
2556: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.savemsg'.$ctr};
1.119 ng 2557: $idx++;
2558: }
2559: $ctr++;
1.41 ng 2560: }
1.119 ng 2561: $ctr = 0;
2562: while ($ctr < $ngrade) {
1.257 albertel 2563: if ($env{'form.newmsg'.$ctr} ne '') {
2564: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.newmsg'.$ctr};
2565: $env{'form.savemsg'.$idx} = $env{'form.newmsg'.$ctr};
1.119 ng 2566: $idx++;
2567: }
2568: $ctr++;
1.41 ng 2569: }
1.257 albertel 2570: $env{'form.savemsgN'} = --$idx;
2571: $keyhash{$symb.'_savemsgN'} = $env{'form.savemsgN'};
1.119 ng 2572: my $putresult = &Apache::lonnet::put
1.301 albertel 2573: ('nohist_handgrade',\%keyhash,$cdom,$cnum);
1.41 ng 2574: }
1.44 ng 2575: # Called by Save & Refresh from Highlight Attribute Window
1.257 albertel 2576: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
2577: if ($env{'form.refresh'} eq 'on') {
1.86 ng 2578: my ($ctr,$total) = (0,0);
2579: while ($ctr < $ngrade) {
1.257 albertel 2580: $total++ if $env{'form.unamedom'.$ctr} ne '';
1.86 ng 2581: $ctr++;
2582: }
1.257 albertel 2583: $env{'form.NTSTU'}=$ngrade;
1.86 ng 2584: $ctr = 0;
2585: while ($ctr < $total) {
1.257 albertel 2586: my $processUser = $env{'form.unamedom'.$ctr};
2587: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2588: $env{'form.fullname'} = $$fullname{$processUser};
1.86 ng 2589: &submission($request,$ctr,$total-1);
1.41 ng 2590: $ctr++;
2591: }
2592: return '';
2593: }
1.36 ng 2594:
1.121 ng 2595: # Go directly to grade student - from submission or link from chart page
1.120 ng 2596: if ($button eq 'Grade Student') {
1.257 albertel 2597: my $processUser = $env{'form.unamedom'.$env{'form.studentNo'}};
2598: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2599: $env{'form.fullname'} = $$fullname{$processUser};
1.120 ng 2600: &submission($request,0,0);
2601: return '';
2602: }
2603:
1.44 ng 2604: # Get the next/previous one or group of students
1.257 albertel 2605: my $firststu = $env{'form.unamedom0'};
2606: my $laststu = $env{'form.unamedom'.($ngrade-1)};
1.119 ng 2607: my $ctr = 2;
1.41 ng 2608: while ($laststu eq '') {
1.257 albertel 2609: $laststu = $env{'form.unamedom'.($ngrade-$ctr)};
1.41 ng 2610: $ctr++;
2611: $laststu = $firststu if ($ctr > $ngrade);
2612: }
1.44 ng 2613:
1.41 ng 2614: my (@parsedlist,@nextlist);
2615: my ($nextflg) = 0;
1.524 raeburn 2616: foreach my $item (sort
1.294 albertel 2617: {
2618: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
2619: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
2620: }
2621: return $a cmp $b;
2622: } (keys(%$fullname))) {
1.605 www 2623: # FIXME: this is fishy, looks like the button label
1.41 ng 2624: if ($nextflg == 1 && $button =~ /Next$/) {
1.524 raeburn 2625: push(@parsedlist,$item);
1.41 ng 2626: }
1.524 raeburn 2627: $nextflg = 1 if ($item eq $laststu);
1.41 ng 2628: if ($button eq 'Previous') {
1.524 raeburn 2629: last if ($item eq $firststu);
2630: push(@parsedlist,$item);
1.41 ng 2631: }
2632: }
2633: $ctr = 0;
1.605 www 2634: # FIXME: this is fishy, looks like the button label
1.41 ng 2635: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
1.582 raeburn 2636: my $res_error;
2637: my ($partlist) = &response_type($symb,\$res_error);
2638: if ($res_error) {
2639: $request->print(&navmap_errormsg());
2640: return;
2641: }
1.41 ng 2642: foreach my $student (@parsedlist) {
1.257 albertel 2643: my $submitonly=$env{'form.submitonly'};
1.41 ng 2644: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 2645:
2646: if ($submitonly eq 'queued') {
2647: my %queue_status =
2648: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
2649: $udom,$uname);
2650: next if (!defined($queue_status{'gradingqueue'}));
2651: }
2652:
1.156 albertel 2653: if ($submitonly =~ /^(yes|graded|incorrect)$/) {
1.257 albertel 2654: # my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 2655: my %status=&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 2656: my $submitted = 0;
1.248 albertel 2657: my $ungraded = 0;
2658: my $incorrect = 0;
1.524 raeburn 2659: foreach my $item (keys(%status)) {
2660: $submitted = 1 if ($status{$item} ne 'nothing');
2661: $ungraded = 1 if ($status{$item} =~ /^ungraded/);
2662: $incorrect = 1 if ($status{$item} =~ /^incorrect/);
2663: my ($foo,$partid,$foo1) = split(/\./,$item);
1.145 albertel 2664: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
2665: $submitted = 0;
2666: }
1.41 ng 2667: }
1.156 albertel 2668: next if (!$submitted && ($submitonly eq 'yes' ||
2669: $submitonly eq 'incorrect' ||
2670: $submitonly eq 'graded'));
1.248 albertel 2671: next if (!$ungraded && ($submitonly eq 'graded'));
2672: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 2673: }
1.524 raeburn 2674: push(@nextlist,$student) if ($ctr < $ntstu);
1.129 ng 2675: last if ($ctr == $ntstu);
1.41 ng 2676: $ctr++;
2677: }
1.36 ng 2678:
1.41 ng 2679: $ctr = 0;
2680: my $total = scalar(@nextlist)-1;
1.39 ng 2681:
1.524 raeburn 2682: foreach (sort(@nextlist)) {
1.41 ng 2683: my ($uname,$udom,$submitter) = split(/:/);
1.257 albertel 2684: $env{'form.student'} = $uname;
2685: $env{'form.userdom'} = $udom;
2686: $env{'form.fullname'} = $$fullname{$_};
1.41 ng 2687: &submission($request,$ctr,$total);
2688: $ctr++;
2689: }
2690: if ($total < 0) {
1.485 albertel 2691: my $the_end = '<h3><span class="LC_info">'.&mt('LON-CAPA User Message').'</span></h3><br />'."\n";
2692: $the_end.=&mt('<b>Message: </b> No more students for this section or class.').'<br /><br />'."\n";
2693: $the_end.=&mt('Click on the button below to return to the grading menu.').'<br /><br />'."\n";
1.41 ng 2694: $request->print($the_end);
2695: }
2696: return '';
1.38 ng 2697: }
1.36 ng 2698:
1.44 ng 2699: #---- Save the score and award for each student, if changed
1.38 ng 2700: sub saveHandGrade {
1.324 albertel 2701: my ($request,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
1.342 banghart 2702: my @version_parts;
1.104 albertel 2703: my $usec = &Apache::lonnet::getsection($domain,$stuname,
1.257 albertel 2704: $env{'request.course.id'});
1.104 albertel 2705: if (!&canmodify($usec)) { return('not_allowed'); }
1.337 banghart 2706: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
1.251 banghart 2707: my @parts_graded;
1.77 ng 2708: my %newrecord = ();
2709: my ($pts,$wgt) = ('','');
1.269 raeburn 2710: my %aggregate = ();
2711: my $aggregateflag = 0;
1.301 albertel 2712: my @parts = split(/:/,$env{'form.partlist'.$newflg});
2713: foreach my $new_part (@parts) {
1.337 banghart 2714: #collaborator ($submi may vary for different parts
1.259 banghart 2715: if ($submitter && $new_part ne $part) { next; }
2716: my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
1.125 ng 2717: if ($dropMenu eq 'excused') {
1.259 banghart 2718: if ($record{'resource.'.$new_part.'.solved'} ne 'excused') {
2719: $newrecord{'resource.'.$new_part.'.solved'} = 'excused';
2720: if (exists($record{'resource.'.$new_part.'.awarded'})) {
2721: $newrecord{'resource.'.$new_part.'.awarded'} = '';
1.58 albertel 2722: }
1.364 banghart 2723: $newrecord{'resource.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.58 albertel 2724: }
1.125 ng 2725: } elsif ($dropMenu eq 'reset status'
1.259 banghart 2726: && exists($record{'resource.'.$new_part.'.solved'})) { #don't bother if no old records -> no attempts
1.524 raeburn 2727: foreach my $key (keys(%record)) {
1.259 banghart 2728: if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
1.197 albertel 2729: }
1.259 banghart 2730: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2731: "$env{'user.name'}:$env{'user.domain'}";
1.270 albertel 2732: my $totaltries = $record{'resource.'.$part.'.tries'};
2733:
2734: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
2735: [$new_part]);
2736: my $aggtries =$totaltries;
1.269 raeburn 2737: if ($last_resets{$new_part}) {
1.270 albertel 2738: $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
2739: $new_part);
1.269 raeburn 2740: }
1.270 albertel 2741:
2742: my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
1.269 raeburn 2743: if ($aggtries > 0) {
1.327 albertel 2744: &decrement_aggs($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
1.269 raeburn 2745: $aggregateflag = 1;
2746: }
1.125 ng 2747: } elsif ($dropMenu eq '') {
1.259 banghart 2748: $pts = ($env{'form.GD_BOX'.$newflg.'_'.$new_part} ne '' ?
2749: $env{'form.GD_BOX'.$newflg.'_'.$new_part} :
2750: $env{'form.RADVAL'.$newflg.'_'.$new_part});
2751: if ($pts eq '' && $env{'form.GD_SEL'.$newflg.'_'.$new_part} eq '') {
1.153 albertel 2752: next;
2753: }
1.259 banghart 2754: $wgt = $env{'form.WGT'.$newflg.'_'.$new_part} eq '' ? 1 :
2755: $env{'form.WGT'.$newflg.'_'.$new_part};
1.41 ng 2756: my $partial= $pts/$wgt;
1.259 banghart 2757: if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
1.153 albertel 2758: #do not update score for part if not changed.
1.346 banghart 2759: &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
1.153 albertel 2760: next;
1.251 banghart 2761: } else {
1.524 raeburn 2762: push(@parts_graded,$new_part);
1.153 albertel 2763: }
1.259 banghart 2764: if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
2765: $newrecord{'resource.'.$new_part.'.awarded'} = $partial;
1.153 albertel 2766: }
1.259 banghart 2767: my $reckey = 'resource.'.$new_part.'.solved';
1.41 ng 2768: if ($partial == 0) {
1.153 albertel 2769: if ($record{$reckey} ne 'incorrect_by_override') {
2770: $newrecord{$reckey} = 'incorrect_by_override';
2771: }
1.41 ng 2772: } else {
1.153 albertel 2773: if ($record{$reckey} ne 'correct_by_override') {
2774: $newrecord{$reckey} = 'correct_by_override';
2775: }
2776: }
2777: if ($submitter &&
1.259 banghart 2778: ($record{'resource.'.$new_part.'.submitted_by'} ne $submitter)) {
2779: $newrecord{'resource.'.$new_part.'.submitted_by'} = $submitter;
1.41 ng 2780: }
1.259 banghart 2781: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2782: "$env{'user.name'}:$env{'user.domain'}";
1.41 ng 2783: }
1.259 banghart 2784: # unless problem has been graded, set flag to version the submitted files
1.305 banghart 2785: unless ($record{'resource.'.$new_part.'.solved'} =~ /^correct_/ ||
2786: $record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override' ||
2787: $dropMenu eq 'reset status')
2788: {
1.524 raeburn 2789: push(@version_parts,$new_part);
1.259 banghart 2790: }
1.41 ng 2791: }
1.301 albertel 2792: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2793: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2794:
1.344 albertel 2795: if (%newrecord) {
2796: if (@version_parts) {
1.364 banghart 2797: my @changed_keys = &version_portfiles(\%record, \@parts_graded,
2798: $env{'request.course.id'}, $symb, $domain, $stuname, \@version_parts);
1.344 albertel 2799: @newrecord{@changed_keys} = @record{@changed_keys};
1.367 albertel 2800: foreach my $new_part (@version_parts) {
2801: &handback_files($request,$symb,$stuname,$domain,$newflg,
2802: $new_part,\%newrecord);
2803: }
1.259 banghart 2804: }
1.44 ng 2805: &Apache::lonnet::cstore(\%newrecord,$symb,
1.257 albertel 2806: $env{'request.course.id'},$domain,$stuname);
1.380 albertel 2807: &check_and_remove_from_queue(\@parts,\%record,\%newrecord,$symb,
2808: $cdom,$cnum,$domain,$stuname);
1.41 ng 2809: }
1.269 raeburn 2810: if ($aggregateflag) {
2811: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 2812: $cdom,$cnum);
1.269 raeburn 2813: }
1.301 albertel 2814: return ('',$pts,$wgt);
1.36 ng 2815: }
1.322 albertel 2816:
1.380 albertel 2817: sub check_and_remove_from_queue {
2818: my ($parts,$record,$newrecord,$symb,$cdom,$cnum,$domain,$stuname) = @_;
2819: my @ungraded_parts;
2820: foreach my $part (@{$parts}) {
2821: if ( $record->{ 'resource.'.$part.'.awarded'} eq ''
2822: && $record->{ 'resource.'.$part.'.solved' } ne 'excused'
2823: && $newrecord->{'resource.'.$part.'.awarded'} eq ''
2824: && $newrecord->{'resource.'.$part.'.solved' } ne 'excused'
2825: ) {
2826: push(@ungraded_parts, $part);
2827: }
2828: }
2829: if ( !@ungraded_parts ) {
2830: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,
2831: $cnum,$domain,$stuname);
2832: }
2833: }
2834:
1.337 banghart 2835: sub handback_files {
2836: my ($request,$symb,$stuname,$domain,$newflg,$new_part,$newrecord) = @_;
1.517 raeburn 2837: my $portfolio_root = '/userfiles/portfolio';
1.582 raeburn 2838: my $res_error;
2839: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
2840: if ($res_error) {
2841: $request->print('<br />'.&navmap_errormsg().'<br />');
2842: return;
2843: }
1.375 albertel 2844: my @part_response_id = &flatten_responseType($responseType);
2845: foreach my $part_response_id (@part_response_id) {
2846: my ($part_id,$resp_id) = @{ $part_response_id };
2847: my $part_resp = join('_',@{ $part_response_id });
1.337 banghart 2848: if (($env{'form.'.$newflg.'_'.$part_resp.'_returndoc1'}) && ($new_part == $part_id)) {
2849: # if multiple files are uploaded names will be 'returndoc2','returndoc3'
2850: my $file_counter = 1;
1.367 albertel 2851: my $file_msg;
1.337 banghart 2852: while ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter}) {
2853: my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.'.filename'};
1.338 banghart 2854: my ($directory,$answer_file) =
2855: ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter} =~ /^(.*?)([^\/]*)$/);
2856: my ($answer_name,$answer_ver,$answer_ext) =
2857: &file_name_version_ext($answer_file);
1.355 banghart 2858: my ($portfolio_path) = ($directory =~ /^.+$stuname\/portfolio(.*)/);
1.517 raeburn 2859: my $getpropath = 1;
2860: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$portfolio_path,$domain,$stuname,$getpropath);
1.338 banghart 2861: my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
1.355 banghart 2862: # fix file name
2863: my ($save_file_name) = (($directory.$answer_name.".$version.".$answer_ext) =~ /^.+\/${stuname}\/(.*)/);
2864: my $result=&Apache::lonnet::finishuserfileupload($stuname,$domain,
2865: $newflg.'_'.$part_resp.'_returndoc'.$file_counter,
2866: $save_file_name);
1.337 banghart 2867: if ($result !~ m|^/uploaded/|) {
1.536 raeburn 2868: $request->print('<br /><span class="LC_error">'.
2869: &mt('An error occurred ([_1]) while trying to upload [_2].',
2870: $result,$newflg.'_'.$part_resp.'_returndoc'.$file_counter).
2871: '</span>');
1.356 banghart 2872: } else {
1.360 banghart 2873: # mark the file as read only
2874: my @files = ($save_file_name);
1.372 albertel 2875: my @what = ($symb,$env{'request.course.id'},'handback');
1.360 banghart 2876: &Apache::lonnet::mark_as_readonly($domain,$stuname,\@files,\@what);
1.367 albertel 2877: if (exists($$newrecord{"resource.$new_part.$resp_id.handback"})) {
2878: $$newrecord{"resource.$new_part.$resp_id.handback"}.=',';
2879: }
2880: $$newrecord{"resource.$new_part.$resp_id.handback"} .= $save_file_name;
2881: $file_msg.= "\n".'<br /><span class="LC_filename"><a href="/uploaded/'."$domain/$stuname/".$save_file_name.'">'.$save_file_name."</a></span><br />";
2882:
1.337 banghart 2883: }
2884: $request->print("<br />".$fname." will be the uploaded file name");
1.354 albertel 2885: $request->print(" ".$env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter});
1.337 banghart 2886: $file_counter++;
2887: }
1.367 albertel 2888: my $subject = "File Handed Back by Instructor ";
2889: my $message = "A file has been returned that was originally submitted in reponse to: <br />";
2890: $message .= "<strong>".&Apache::lonnet::gettitle($symb)."</strong><br />";
2891: $message .= ' The returned file(s) are named: '. $file_msg;
2892: $message .= " and can be found in your portfolio space.";
1.418 albertel 2893: my ($feedurl,$showsymb) =
2894: &get_feedurl_and_symb($symb,$domain,$stuname);
1.386 raeburn 2895: my $restitle = &Apache::lonnet::gettitle($symb);
2896: my $msgstatus =
2897: &Apache::lonmsg::user_normal_msg($stuname,$domain,$subject.
2898: ' (File Returned) ['.$restitle.']',$message,undef,
1.418 albertel 2899: $feedurl,undef,undef,undef,$showsymb,$restitle);
1.337 banghart 2900: }
2901: }
1.338 banghart 2902: return;
1.337 banghart 2903: }
2904:
1.418 albertel 2905: sub get_feedurl_and_symb {
2906: my ($symb,$uname,$udom) = @_;
2907: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
2908: $url = &Apache::lonnet::clutter($url);
2909: my $encrypturl=&Apache::lonnet::EXT('resource.0.encrypturl',
2910: $symb,$udom,$uname);
2911: if ($encrypturl =~ /^yes$/i) {
2912: &Apache::lonenc::encrypted(\$url,1);
2913: &Apache::lonenc::encrypted(\$symb,1);
2914: }
2915: return ($url,$symb);
2916: }
2917:
1.313 banghart 2918: sub get_submitted_files {
2919: my ($udom,$uname,$partid,$respid,$record) = @_;
2920: my @files;
2921: if ($$record{"resource.$partid.$respid.portfiles"}) {
2922: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
2923: foreach my $file (split(',',$$record{"resource.$partid.$respid.portfiles"})) {
2924: push(@files,$file_url.$file);
2925: }
2926: }
2927: if ($$record{"resource.$partid.$respid.uploadedurl"}) {
2928: push(@files,$$record{"resource.$partid.$respid.uploadedurl"});
2929: }
2930: return (\@files);
2931: }
1.322 albertel 2932:
1.269 raeburn 2933: # ----------- Provides number of tries since last reset.
2934: sub get_num_tries {
2935: my ($record,$last_reset,$part) = @_;
2936: my $timestamp = '';
2937: my $num_tries = 0;
2938: if ($$record{'version'}) {
2939: for (my $version=$$record{'version'};$version>=1;$version--) {
2940: if (exists($$record{$version.':resource.'.$part.'.solved'})) {
2941: $timestamp = $$record{$version.':timestamp'};
2942: if ($timestamp > $last_reset) {
2943: $num_tries ++;
2944: } else {
2945: last;
2946: }
2947: }
2948: }
2949: }
2950: return $num_tries;
2951: }
2952:
2953: # ----------- Determine decrements required in aggregate totals
2954: sub decrement_aggs {
2955: my ($symb,$part,$aggregate,$aggtries,$totaltries,$solvedstatus) = @_;
2956: my %decrement = (
2957: attempts => 0,
2958: users => 0,
2959: correct => 0
2960: );
2961: $decrement{'attempts'} = $aggtries;
2962: if ($solvedstatus =~ /^correct/) {
2963: $decrement{'correct'} = 1;
2964: }
2965: if ($aggtries == $totaltries) {
2966: $decrement{'users'} = 1;
2967: }
1.524 raeburn 2968: foreach my $type (keys(%decrement)) {
1.269 raeburn 2969: $$aggregate{$symb."\0".$part."\0".$type} = -$decrement{$type};
2970: }
2971: return;
2972: }
2973:
2974: # ----------- Determine timestamps for last reset of aggregate totals for parts
2975: sub get_last_resets {
1.270 albertel 2976: my ($symb,$courseid,$partids) =@_;
2977: my %last_resets;
1.269 raeburn 2978: my $cdom = $env{'course.'.$courseid.'.domain'};
2979: my $cname = $env{'course.'.$courseid.'.num'};
1.271 albertel 2980: my @keys;
2981: foreach my $part (@{$partids}) {
2982: push(@keys,"$symb\0$part\0resettime");
2983: }
2984: my %results=&Apache::lonnet::get('nohist_resourcetracker',\@keys,
2985: $cdom,$cname);
2986: foreach my $part (@{$partids}) {
2987: $last_resets{$part}=$results{"$symb\0$part\0resettime"};
1.269 raeburn 2988: }
1.270 albertel 2989: return %last_resets;
1.269 raeburn 2990: }
2991:
1.251 banghart 2992: # ----------- Handles creating versions for portfolio files as answers
2993: sub version_portfiles {
1.343 banghart 2994: my ($record, $parts_graded, $courseid, $symb, $domain, $stu_name, $v_flag) = @_;
1.263 banghart 2995: my $version_parts = join('|',@$v_flag);
1.343 banghart 2996: my @returned_keys;
1.255 banghart 2997: my $parts = join('|', @$parts_graded);
1.517 raeburn 2998: my $portfolio_root = '/userfiles/portfolio';
1.277 albertel 2999: foreach my $key (keys(%$record)) {
1.259 banghart 3000: my $new_portfiles;
1.263 banghart 3001: if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
1.342 banghart 3002: my @versioned_portfiles;
1.367 albertel 3003: my @portfiles = split(/\s*,\s*/,$$record{$key});
1.252 banghart 3004: foreach my $file (@portfiles) {
1.306 banghart 3005: &Apache::lonnet::unmark_as_readonly($domain,$stu_name,[$symb,$env{'request.course.id'}],$file);
1.304 albertel 3006: my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*)$/);
3007: my ($answer_name,$answer_ver,$answer_ext) =
3008: &file_name_version_ext($answer_file);
1.517 raeburn 3009: my $getpropath = 1;
3010: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$directory,$domain,$stu_name,$getpropath);
1.342 banghart 3011: my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
1.306 banghart 3012: my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version);
3013: if ($new_answer ne 'problem getting file') {
1.342 banghart 3014: push(@versioned_portfiles, $directory.$new_answer);
1.306 banghart 3015: &Apache::lonnet::mark_as_readonly($domain,$stu_name,
1.367 albertel 3016: [$directory.$new_answer],
1.306 banghart 3017: [$symb,$env{'request.course.id'},'graded']);
1.259 banghart 3018: }
1.252 banghart 3019: }
1.343 banghart 3020: $$record{$key} = join(',',@versioned_portfiles);
3021: push(@returned_keys,$key);
1.251 banghart 3022: }
3023: }
1.343 banghart 3024: return (@returned_keys);
1.305 banghart 3025: }
3026:
1.307 banghart 3027: sub get_next_version {
1.341 banghart 3028: my ($answer_name, $answer_ext, $dir_list) = @_;
1.307 banghart 3029: my $version;
3030: foreach my $row (@$dir_list) {
3031: my ($file) = split(/\&/,$row,2);
3032: my ($file_name,$file_version,$file_ext) =
3033: &file_name_version_ext($file);
3034: if (($file_name eq $answer_name) &&
3035: ($file_ext eq $answer_ext)) {
3036: # gets here if filename and extension match, regardless of version
3037: if ($file_version ne '') {
3038: # a versioned file is found so save it for later
3039: if ($file_version > $version) {
3040: $version = $file_version;
3041: }
3042: }
3043: }
3044: }
3045: $version ++;
3046: return($version);
3047: }
3048:
1.305 banghart 3049: sub version_selected_portfile {
1.306 banghart 3050: my ($domain,$stu_name,$directory,$file_name,$version) = @_;
3051: my ($answer_name,$answer_ver,$answer_ext) =
3052: &file_name_version_ext($file_name);
3053: my $new_answer;
3054: $env{'form.copy'} = &Apache::lonnet::getfile("/uploaded/$domain/$stu_name/portfolio$directory$file_name");
3055: if($env{'form.copy'} eq '-1') {
3056: $new_answer = 'problem getting file';
3057: } else {
3058: $new_answer = $answer_name.'.'.$version.'.'.$answer_ext;
3059: my $copy_result = &Apache::lonnet::finishuserfileupload(
3060: $stu_name,$domain,'copy',
3061: '/portfolio'.$directory.$new_answer);
3062: }
3063: return ($new_answer);
1.251 banghart 3064: }
3065:
1.304 albertel 3066: sub file_name_version_ext {
3067: my ($file)=@_;
3068: my @file_parts = split(/\./, $file);
3069: my ($name,$version,$ext);
3070: if (@file_parts > 1) {
3071: $ext=pop(@file_parts);
3072: if (@file_parts > 1 && $file_parts[-1] =~ /^\d+$/) {
3073: $version=pop(@file_parts);
3074: }
3075: $name=join('.',@file_parts);
3076: } else {
3077: $name=join('.',@file_parts);
3078: }
3079: return($name,$version,$ext);
3080: }
3081:
1.44 ng 3082: #--------------------------------------------------------------------------------------
3083: #
3084: #-------------------------- Next few routines handles grading by section or whole class
3085: #
3086: #--- Javascript to handle grading by section or whole class
1.42 ng 3087: sub viewgrades_js {
3088: my ($request) = shift;
3089:
1.539 riegler 3090: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
1.597 wenzelju 3091: $request->print(&Apache::lonhtmlcommon::scripttag(<<VIEWJAVASCRIPT));
1.45 ng 3092: function writePoint(partid,weight,point) {
1.125 ng 3093: var radioButton = document.classgrade["RADVAL_"+partid];
3094: var textbox = document.classgrade["TEXTVAL_"+partid];
1.42 ng 3095: if (point == "textval") {
1.125 ng 3096: point = document.classgrade["TEXTVAL_"+partid].value;
1.109 matthew 3097: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 3098: alert("$alertmsg"+parseFloat(point));
1.42 ng 3099: var resetbox = false;
3100: for (var i=0; i<radioButton.length; i++) {
3101: if (radioButton[i].checked) {
3102: textbox.value = i;
3103: resetbox = true;
3104: }
3105: }
3106: if (!resetbox) {
3107: textbox.value = "";
3108: }
3109: return;
3110: }
1.109 matthew 3111: if (parseFloat(point) > parseFloat(weight)) {
3112: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 3113: ") greater than the weight for the part. Accept?");
3114: if (resp == false) {
3115: textbox.value = "";
3116: return;
3117: }
3118: }
1.42 ng 3119: for (var i=0; i<radioButton.length; i++) {
3120: radioButton[i].checked=false;
1.109 matthew 3121: if (parseFloat(point) == i) {
1.42 ng 3122: radioButton[i].checked=true;
3123: }
3124: }
1.41 ng 3125:
1.42 ng 3126: } else {
1.125 ng 3127: textbox.value = parseFloat(point);
1.42 ng 3128: }
1.41 ng 3129: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3130: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3131: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3132: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3133: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3134: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 3135: if (saveval != "correct") {
3136: scorename.value = point;
1.43 ng 3137: if (selname[0].selected != true) {
3138: selname[0].selected = true;
3139: }
1.42 ng 3140: }
3141: }
1.125 ng 3142: document.classgrade["SELVAL_"+partid][0].selected = true;
1.42 ng 3143: }
3144:
3145: function writeRadText(partid,weight) {
1.125 ng 3146: var selval = document.classgrade["SELVAL_"+partid];
3147: var radioButton = document.classgrade["RADVAL_"+partid];
1.265 www 3148: var override = document.classgrade["FORCE_"+partid].checked;
1.125 ng 3149: var textbox = document.classgrade["TEXTVAL_"+partid];
3150: if (selval[1].selected || selval[2].selected) {
1.42 ng 3151: for (var i=0; i<radioButton.length; i++) {
3152: radioButton[i].checked=false;
3153:
3154: }
3155: textbox.value = "";
3156:
3157: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3158: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3159: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3160: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3161: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3162: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 3163: if ((saveval != "correct") || override) {
1.42 ng 3164: scorename.value = "";
1.125 ng 3165: if (selval[1].selected) {
3166: selname[1].selected = true;
3167: } else {
3168: selname[2].selected = true;
3169: if (Number(document.classgrade["GD_"+user+"_"+partid+"_tries"].value))
3170: {document.classgrade["GD_"+user+"_"+partid+"_tries"].value = '0';}
3171: }
1.42 ng 3172: }
3173: }
1.43 ng 3174: } else {
3175: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3176: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3177: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3178: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3179: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3180: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 3181: if ((saveval != "correct") || override) {
1.125 ng 3182: scorename.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
1.43 ng 3183: selname[0].selected = true;
3184: }
3185: }
3186: }
1.42 ng 3187: }
3188:
3189: function changeSelect(partid,user) {
1.125 ng 3190: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
3191: var textbox = document.classgrade["GD_"+user+'_'+partid+"_awarded"];
1.44 ng 3192: var point = textbox.value;
1.125 ng 3193: var weight = document.classgrade["weight_"+partid].value;
1.44 ng 3194:
1.109 matthew 3195: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 3196: alert("$alertmsg"+parseFloat(point));
1.44 ng 3197: textbox.value = "";
3198: return;
3199: }
1.109 matthew 3200: if (parseFloat(point) > parseFloat(weight)) {
3201: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 3202: ") greater than the weight of the part. Accept?");
3203: if (resp == false) {
3204: textbox.value = "";
3205: return;
3206: }
3207: }
1.42 ng 3208: selval[0].selected = true;
3209: }
3210:
3211: function changeOneScore(partid,user) {
1.125 ng 3212: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
3213: if (selval[1].selected || selval[2].selected) {
3214: document.classgrade["GD_"+user+'_'+partid+"_awarded"].value = "";
3215: if (selval[2].selected) {
3216: document.classgrade["GD_"+user+'_'+partid+"_tries"].value = "0";
3217: }
1.269 raeburn 3218: }
1.42 ng 3219: }
3220:
3221: function resetEntry(numpart) {
3222: for (ctpart=0;ctpart<numpart;ctpart++) {
1.125 ng 3223: var partid = document.classgrade["partid_"+ctpart].value;
3224: var radioButton = document.classgrade["RADVAL_"+partid];
3225: var textbox = document.classgrade["TEXTVAL_"+partid];
3226: var selval = document.classgrade["SELVAL_"+partid];
1.42 ng 3227: for (var i=0; i<radioButton.length; i++) {
3228: radioButton[i].checked=false;
3229:
3230: }
3231: textbox.value = "";
3232: selval[0].selected = true;
3233:
3234: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3235: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3236: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3237: var resetscore = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3238: resetscore.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
3239: var resettries = document.classgrade["GD_"+user+"_"+partid+"_tries"];
3240: resettries.value = document.classgrade["GD_"+user+"_"+partid+"_tries_s"].value;
3241: var saveselval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3242: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 3243: if (saveselval == "excused") {
1.43 ng 3244: if (selname[1].selected == false) { selname[1].selected = true;}
1.42 ng 3245: } else {
1.43 ng 3246: if (selname[0].selected == false) {selname[0].selected = true};
1.42 ng 3247: }
3248: }
1.41 ng 3249: }
1.42 ng 3250: }
3251:
1.41 ng 3252: VIEWJAVASCRIPT
1.42 ng 3253: }
3254:
1.44 ng 3255: #--- show scores for a section or whole class w/ option to change/update a score
1.42 ng 3256: sub viewgrades {
1.608 www 3257: my ($request,$symb) = @_;
1.42 ng 3258: &viewgrades_js($request);
1.41 ng 3259:
1.168 albertel 3260: #need to make sure we have the correct data for later EXT calls,
3261: #thus invalidate the cache
3262: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 3263: $env{'course.'.$env{'request.course.id'}.'.num'},
3264: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 3265: &Apache::lonnet::clear_EXT_cache_status();
3266:
1.398 albertel 3267: my $result='<h3><span class="LC_info">'.&mt('Manual Grading').'</span></h3>';
1.41 ng 3268:
3269: #view individual student submission form - called using Javascript viewOneStudent
1.324 albertel 3270: $result.=&jscriptNform($symb);
1.41 ng 3271:
1.44 ng 3272: #beginning of class grading form
1.442 banghart 3273: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.41 ng 3274: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1.418 albertel 3275: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.38 ng 3276: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.432 banghart 3277: &build_section_inputs().
1.442 banghart 3278: '<input type="hidden" name="Status" value="'.$env{'stu_status'}.'" />'."\n".
1.72 ng 3279:
1.560 raeburn 3280: my ($common_header,$specific_header);
1.257 albertel 3281: if ($env{'form.section'} eq 'all') {
1.560 raeburn 3282: $common_header = &mt('Assign Common Grade to Class');
3283: $specific_header = &mt('Assign Grade to Specific Students in Class');
1.257 albertel 3284: } elsif ($env{'form.section'} eq 'none') {
1.560 raeburn 3285: $common_header = &mt('Assign Common Grade to Students in no Section');
3286: $specific_header = &mt('Assign Grade to Specific Students in no Section');
1.52 albertel 3287: } else {
1.560 raeburn 3288: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
3289: $common_header = &mt('Assign Common Grade to Students in Section(s) [_1]',$section_display);
3290: $specific_header = &mt('Assign Grade to Specific Students in Section(s) [_1]',$section_display);
1.52 albertel 3291: }
1.560 raeburn 3292: $result.= '<h3>'.$common_header.'</h3>'.&Apache::loncommon::start_data_table();
1.44 ng 3293: #radio buttons/text box for assigning points for a section or class.
3294: #handles different parts of a problem
1.582 raeburn 3295: my $res_error;
3296: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
3297: if ($res_error) {
3298: return &navmap_errormsg();
3299: }
1.42 ng 3300: my %weight = ();
3301: my $ctsparts = 0;
1.45 ng 3302: my %seen = ();
1.375 albertel 3303: my @part_response_id = &flatten_responseType($responseType);
3304: foreach my $part_response_id (@part_response_id) {
3305: my ($partid,$respid) = @{ $part_response_id };
3306: my $part_resp = join('_',@{ $part_response_id });
1.45 ng 3307: next if $seen{$partid};
3308: $seen{$partid}++;
1.375 albertel 3309: my $handgrade=$$handgrade{$part_resp};
1.42 ng 3310: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
3311: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
3312:
1.324 albertel 3313: my $display_part=&get_display_part($partid,$symb);
1.485 albertel 3314: my $radio.='<table border="0"><tr>';
1.41 ng 3315: my $ctr = 0;
1.42 ng 3316: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
1.485 albertel 3317: $radio.= '<td><label><input type="radio" name="RADVAL_'.$partid.'" '.
1.54 albertel 3318: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.288 albertel 3319: ','.$ctr.')" />'.$ctr."</label></td>\n";
1.41 ng 3320: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
3321: $ctr++;
3322: }
1.485 albertel 3323: $radio.='</tr></table>';
3324: my $line = '<input type="text" name="TEXTVAL_'.
1.589 bisitz 3325: $partid.'" size="4" '.'onchange="javascript:writePoint(\''.
1.54 albertel 3326: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.539 riegler 3327: $weight{$partid}.' '.&mt('(problem weight)').'</td>'."\n";
3328: $line.= '<td><b>'.&mt('Grade Status').':</b><select name="SELVAL_'.$partid.'"'.
1.589 bisitz 3329: 'onchange="javascript:writeRadText(\''.$partid.'\','.
1.59 albertel 3330: $weight{$partid}.')"> '.
1.401 albertel 3331: '<option selected="selected"> </option>'.
1.485 albertel 3332: '<option value="excused">'.&mt('excused').'</option>'.
3333: '<option value="reset status">'.&mt('reset status').'</option>'.
3334: '</select></td>'.
3335: '<td><label><input type="checkbox" name="FORCE_'.$partid.'" />'.&mt('Override "Correct"').'</label>';
3336: $line.='<input type="hidden" name="partid_'.
3337: $ctsparts.'" value="'.$partid.'" />'."\n";
3338: $line.='<input type="hidden" name="weight_'.
3339: $partid.'" value="'.$weight{$partid}.'" />'."\n";
3340:
3341: $result.=
3342: &Apache::loncommon::start_data_table_row()."\n".
1.577 bisitz 3343: '<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 3344: &Apache::loncommon::end_data_table_row()."\n";
1.42 ng 3345: $ctsparts++;
1.41 ng 3346: }
1.474 albertel 3347: $result.=&Apache::loncommon::end_data_table()."\n".
1.52 albertel 3348: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.485 albertel 3349: $result.='<input type="button" value="'.&mt('Revert to Default').'" '.
1.589 bisitz 3350: 'onclick="javascript:resetEntry('.$ctsparts.');" />';
1.41 ng 3351:
1.44 ng 3352: #table listing all the students in a section/class
3353: #header of table
1.560 raeburn 3354: $result.= '<h3>'.$specific_header.'</h3>'.
3355: &Apache::loncommon::start_data_table().
3356: &Apache::loncommon::start_data_table_header_row().
3357: '<th>'.&mt('No.').'</th>'.
3358: '<th>'.&nameUserString('header')."</th>\n";
1.582 raeburn 3359: my $partserror;
3360: my (@parts) = sort(&getpartlist($symb,\$partserror));
3361: if ($partserror) {
3362: return &navmap_errormsg();
3363: }
1.324 albertel 3364: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.269 raeburn 3365: my @partids = ();
1.41 ng 3366: foreach my $part (@parts) {
3367: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1.539 riegler 3368: my $narrowtext = &mt('Tries');
3369: $display =~ s|^Number of Attempts|$narrowtext <br />|; # makes the column narrower
1.41 ng 3370: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
1.207 albertel 3371: my ($partid) = &split_part_type($part);
1.524 raeburn 3372: push(@partids,$partid);
1.324 albertel 3373: my $display_part=&get_display_part($partid,$symb);
1.41 ng 3374: if ($display =~ /^Partial Credit Factor/) {
1.485 albertel 3375: $result.='<th>'.
3376: &mt('Score Part: [_1]<br /> (weight = [_2])',
3377: $display_part,$weight{$partid}).'</th>'."\n";
1.41 ng 3378: next;
1.485 albertel 3379:
1.207 albertel 3380: } else {
1.485 albertel 3381: if ($display =~ /Problem Status/) {
3382: my $grade_status_mt = &mt('Grade Status');
3383: $display =~ s{Problem Status}{$grade_status_mt<br />};
3384: }
3385: my $part_mt = &mt('Part:');
3386: $display =~s{\[Part: \Q$partid\E\]}{$part_mt $display_part};
1.41 ng 3387: }
1.485 albertel 3388:
1.474 albertel 3389: $result.='<th>'.$display.'</th>'."\n";
1.41 ng 3390: }
1.474 albertel 3391: $result.=&Apache::loncommon::end_data_table_header_row();
1.44 ng 3392:
1.270 albertel 3393: my %last_resets =
3394: &get_last_resets($symb,$env{'request.course.id'},\@partids);
1.269 raeburn 3395:
1.41 ng 3396: #get info for each student
1.44 ng 3397: #list all the students - with points and grade status
1.257 albertel 3398: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
1.41 ng 3399: my $ctr = 0;
1.294 albertel 3400: foreach (sort
3401: {
3402: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
3403: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
3404: }
3405: return $a cmp $b;
3406: } (keys(%$fullname))) {
1.126 ng 3407: $ctr++;
1.324 albertel 3408: $result.=&viewstudentgrade($symb,$env{'request.course.id'},
1.269 raeburn 3409: $_,$$fullname{$_},\@parts,\%weight,$ctr,\%last_resets);
1.41 ng 3410: }
1.474 albertel 3411: $result.=&Apache::loncommon::end_data_table();
1.41 ng 3412: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.485 albertel 3413: $result.='<input type="button" value="'.&mt('Save').'" '.
1.589 bisitz 3414: 'onclick="javascript:submit();" target="_self" /></form>'."\n";
1.96 albertel 3415: if (scalar(%$fullname) eq 0) {
3416: my $colspan=3+scalar(@parts);
1.433 banghart 3417: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.442 banghart 3418: my $stu_status = join(' or ',&Apache::loncommon::get_env_multiple('form.Status'));
1.433 banghart 3419: $result='<span class="LC_warning">'.
1.485 albertel 3420: &mt('There are no students in section(s) [_1] with enrollment status [_2] to modify or grade.',
1.442 banghart 3421: $section_display, $stu_status).
1.433 banghart 3422: '</span>';
1.96 albertel 3423: }
1.41 ng 3424: return $result;
3425: }
3426:
1.44 ng 3427: #--- call by previous routine to display each student
1.41 ng 3428: sub viewstudentgrade {
1.324 albertel 3429: my ($symb,$courseid,$student,$fullname,$parts,$weight,$ctr,$last_resets) = @_;
1.44 ng 3430: my ($uname,$udom) = split(/:/,$student);
3431: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.269 raeburn 3432: my %aggregates = ();
1.474 albertel 3433: my $result=&Apache::loncommon::start_data_table_row().'<td align="right">'.
1.233 albertel 3434: '<input type="hidden" name="ctr'.($ctr-1).'" value="'.$student.'" />'.
3435: "\n".$ctr.' </td><td> '.
1.44 ng 3436: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 3437: '\');" target="_self">'.$fullname.'</a> '.
1.398 albertel 3438: '<span class="LC_internal_info">('.$uname.($env{'user.domain'} eq $udom ? '' : ':'.$udom).')</span></td>'."\n";
1.281 albertel 3439: $student=~s/:/_/; # colon doen't work in javascript for names
1.63 albertel 3440: foreach my $apart (@$parts) {
3441: my ($part,$type) = &split_part_type($apart);
1.41 ng 3442: my $score=$record{"resource.$part.$type"};
1.276 albertel 3443: $result.='<td align="center">';
1.269 raeburn 3444: my ($aggtries,$totaltries);
3445: unless (exists($aggregates{$part})) {
1.270 albertel 3446: $totaltries = $record{'resource.'.$part.'.tries'};
3447:
3448: $aggtries = $totaltries;
1.269 raeburn 3449: if ($$last_resets{$part}) {
1.270 albertel 3450: $aggtries = &get_num_tries(\%record,$$last_resets{$part},
3451: $part);
3452: }
1.269 raeburn 3453: $result.='<input type="hidden" name="'.
3454: 'GD_'.$student.'_'.$part.'_aggtries" value="'.$aggtries.'" />'."\n";
3455: $result.='<input type="hidden" name="'.
3456: 'GD_'.$student.'_'.$part.'_totaltries" value="'.$totaltries.'" />'."\n";
3457: $aggregates{$part} = 1;
3458: }
1.41 ng 3459: if ($type eq 'awarded') {
1.320 albertel 3460: my $pts = $score eq '' ? '' : &compute_points($score,$$weight{$part});
1.42 ng 3461: $result.='<input type="hidden" name="'.
1.89 albertel 3462: 'GD_'.$student.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.233 albertel 3463: $result.='<input type="text" name="'.
1.89 albertel 3464: 'GD_'.$student.'_'.$part.'_awarded" '.
1.589 bisitz 3465: 'onchange="javascript:changeSelect(\''.$part.'\',\''.$student.
1.44 ng 3466: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41 ng 3467: } elsif ($type eq 'solved') {
3468: my ($status,$foo)=split(/_/,$score,2);
3469: $status = 'nothing' if ($status eq '');
1.89 albertel 3470: $result.='<input type="hidden" name="'.'GD_'.$student.'_'.
1.54 albertel 3471: $part.'_solved_s" value="'.$status.'" />'."\n";
1.233 albertel 3472: $result.=' <select name="'.
1.89 albertel 3473: 'GD_'.$student.'_'.$part.'_solved" '.
1.589 bisitz 3474: 'onchange="javascript:changeOneScore(\''.$part.'\',\''.$student.'\')" >'."\n";
1.485 albertel 3475: $result.= (($status eq 'excused') ? '<option> </option><option selected="selected" value="excused">'.&mt('excused').'</option>'
3476: : '<option selected="selected"> </option><option value="excused">'.&mt('excused').'</option>')."\n";
3477: $result.='<option value="reset status">'.&mt('reset status').'</option>';
1.126 ng 3478: $result.="</select> </td>\n";
1.122 ng 3479: } else {
3480: $result.='<input type="hidden" name="'.
3481: 'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
3482: "\n";
1.233 albertel 3483: $result.='<input type="text" name="'.
1.122 ng 3484: 'GD_'.$student.'_'.$part.'_'.$type.'" '.
3485: 'value="'.$score.'" size="4" /></td>'."\n";
1.41 ng 3486: }
3487: }
1.474 albertel 3488: $result.=&Apache::loncommon::end_data_table_row();
1.41 ng 3489: return $result;
1.38 ng 3490: }
3491:
1.44 ng 3492: #--- change scores for all the students in a section/class
3493: # record does not get update if unchanged
1.38 ng 3494: sub editgrades {
1.608 www 3495: my ($request,$symb) = @_;
1.41 ng 3496:
1.433 banghart 3497: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.477 albertel 3498: my $title='<h2>'.&mt('Current Grade Status').'</h2>';
1.433 banghart 3499: $title.='<h4>'.&mt('<b>Section: </b>[_1]',$section_display).'</h4>'."\n";
1.126 ng 3500:
1.477 albertel 3501: my $result= &Apache::loncommon::start_data_table().
3502: &Apache::loncommon::start_data_table_header_row().
3503: '<th rowspan="2" valign="middle">'.&mt('No.').'</th>'.
3504: '<th rowspan="2" valign="middle">'.&nameUserString('header')."</th>\n";
1.43 ng 3505: my %scoreptr = (
3506: 'correct' =>'correct_by_override',
3507: 'incorrect'=>'incorrect_by_override',
3508: 'excused' =>'excused',
3509: 'ungraded' =>'ungraded_attempted',
1.596 raeburn 3510: 'credited' =>'credit_attempted',
1.43 ng 3511: 'nothing' => '',
3512: );
1.257 albertel 3513: my ($classlist,undef,$fullname) = &getclasslist($env{'form.section'},'0');
1.34 ng 3514:
1.44 ng 3515: my (@partid);
3516: my %weight = ();
1.54 albertel 3517: my %columns = ();
1.44 ng 3518: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54 albertel 3519:
1.582 raeburn 3520: my $partserror;
3521: my (@parts) = sort(&getpartlist($symb,\$partserror));
3522: if ($partserror) {
3523: return &navmap_errormsg();
3524: }
1.54 albertel 3525: my $header;
1.257 albertel 3526: while ($ctr < $env{'form.totalparts'}) {
3527: my $partid = $env{'form.partid_'.$ctr};
1.524 raeburn 3528: push(@partid,$partid);
1.257 albertel 3529: $weight{$partid} = $env{'form.weight_'.$partid};
1.44 ng 3530: $ctr++;
1.54 albertel 3531: }
1.324 albertel 3532: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.54 albertel 3533: foreach my $partid (@partid) {
1.478 albertel 3534: $header .= '<th align="center">'.&mt('Old Score').'</th>'.
3535: '<th align="center">'.&mt('New Score').'</th>';
1.54 albertel 3536: $columns{$partid}=2;
3537: foreach my $stores (@parts) {
3538: my ($part,$type) = &split_part_type($stores);
3539: if ($part !~ m/^\Q$partid\E/) { next;}
3540: if ($type eq 'awarded' || $type eq 'solved') { next; }
3541: my $display=&Apache::lonnet::metadata($url,$stores.'.display');
1.551 raeburn 3542: $display =~ s/\[Part: \Q$part\E\]//;
1.539 riegler 3543: my $narrowtext = &mt('Tries');
3544: $display =~ s/Number of Attempts/$narrowtext/;
3545: $header .= '<th align="center">'.&mt('Old').' '.$display.'</th>'.
3546: '<th align="center">'.&mt('New').' '.$display.'</th>';
1.54 albertel 3547: $columns{$partid}+=2;
3548: }
3549: }
3550: foreach my $partid (@partid) {
1.324 albertel 3551: my $display_part=&get_display_part($partid,$symb);
1.478 albertel 3552: $result .= '<th colspan="'.$columns{$partid}.'" align="center">'.
3553: &mt('Part: [_1] (Weight = [_2])',$display_part,$weight{$partid}).
3554: '</th>';
1.54 albertel 3555:
1.44 ng 3556: }
1.477 albertel 3557: $result .= &Apache::loncommon::end_data_table_header_row().
3558: &Apache::loncommon::start_data_table_header_row().
3559: $header.
3560: &Apache::loncommon::end_data_table_header_row();
3561: my @noupdate;
1.126 ng 3562: my ($updateCtr,$noupdateCtr) = (1,1);
1.257 albertel 3563: for ($i=0; $i<$env{'form.total'}; $i++) {
1.93 albertel 3564: my $line;
1.257 albertel 3565: my $user = $env{'form.ctr'.$i};
1.281 albertel 3566: my ($uname,$udom)=split(/:/,$user);
1.44 ng 3567: my %newrecord;
3568: my $updateflag = 0;
1.281 albertel 3569: $line .= '<td>'.&nameUserString(undef,$$fullname{$user},$uname,$udom).'</td>';
1.108 albertel 3570: my $usec=$classlist->{"$uname:$udom"}[5];
1.105 albertel 3571: if (!&canmodify($usec)) {
1.126 ng 3572: my $numcols=scalar(@partid)*4+2;
1.477 albertel 3573: push(@noupdate,
1.478 albertel 3574: $line."<td colspan=\"$numcols\"><span class=\"LC_warning\">".
3575: &mt('Not allowed to modify student')."</span></td></tr>");
1.105 albertel 3576: next;
3577: }
1.269 raeburn 3578: my %aggregate = ();
3579: my $aggregateflag = 0;
1.281 albertel 3580: $user=~s/:/_/; # colon doen't work in javascript for names
1.44 ng 3581: foreach (@partid) {
1.257 albertel 3582: my $old_aw = $env{'form.GD_'.$user.'_'.$_.'_awarded_s'};
1.54 albertel 3583: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
3584: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
1.257 albertel 3585: my $old_score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
3586: my $awarded = $env{'form.GD_'.$user.'_'.$_.'_awarded'};
1.54 albertel 3587: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
3588: my $partial = $awarded eq '' ? '' : $pcr;
1.44 ng 3589: my $score;
3590: if ($partial eq '') {
1.257 albertel 3591: $score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 3592: } elsif ($partial > 0) {
3593: $score = 'correct_by_override';
3594: } elsif ($partial == 0) {
3595: $score = 'incorrect_by_override';
3596: }
1.257 albertel 3597: my $dropMenu = $env{'form.GD_'.$user.'_'.$_.'_solved'};
1.125 ng 3598: $score = 'excused' if (($dropMenu eq 'excused') && ($score ne 'excused'));
3599:
1.292 albertel 3600: $newrecord{'resource.'.$_.'.regrader'}=
3601: "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 3602: if ($dropMenu eq 'reset status' &&
3603: $old_score ne '') { # ignore if no previous attempts => nothing to reset
1.299 albertel 3604: $newrecord{'resource.'.$_.'.tries'} = '';
1.125 ng 3605: $newrecord{'resource.'.$_.'.solved'} = '';
3606: $newrecord{'resource.'.$_.'.award'} = '';
1.299 albertel 3607: $newrecord{'resource.'.$_.'.awarded'} = '';
1.125 ng 3608: $updateflag = 1;
1.269 raeburn 3609: if ($env{'form.GD_'.$user.'_'.$_.'_aggtries'} > 0) {
3610: my $aggtries = $env{'form.GD_'.$user.'_'.$_.'_aggtries'};
3611: my $totaltries = $env{'form.GD_'.$user.'_'.$_.'_totaltries'};
3612: my $solvedstatus = $env{'form.GD_'.$user.'_'.$_.'_solved_s'};
3613: &decrement_aggs($symb,$_,\%aggregate,$aggtries,$totaltries,$solvedstatus);
3614: $aggregateflag = 1;
3615: }
1.139 albertel 3616: } elsif (!($old_part eq $partial && $old_score eq $score)) {
3617: $updateflag = 1;
3618: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
3619: $newrecord{'resource.'.$_.'.solved'} = $score;
3620: $rec_update++;
1.125 ng 3621: }
3622:
1.93 albertel 3623: $line .= '<td align="center">'.$old_aw.' </td>'.
1.44 ng 3624: '<td align="center">'.$awarded.
3625: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 3626:
1.54 albertel 3627:
3628: my $partid=$_;
3629: foreach my $stores (@parts) {
3630: my ($part,$type) = &split_part_type($stores);
3631: if ($part !~ m/^\Q$partid\E/) { next;}
3632: if ($type eq 'awarded' || $type eq 'solved') { next; }
1.257 albertel 3633: my $old_aw = $env{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
3634: my $awarded = $env{'form.GD_'.$user.'_'.$part.'_'.$type};
1.54 albertel 3635: if ($awarded ne '' && $awarded ne $old_aw) {
3636: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.257 albertel 3637: $newrecord{'resource.'.$part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.54 albertel 3638: $updateflag=1;
3639: }
1.93 albertel 3640: $line .= '<td align="center">'.$old_aw.' </td>'.
1.54 albertel 3641: '<td align="center">'.$awarded.' </td>';
3642: }
1.44 ng 3643: }
1.477 albertel 3644: $line.="\n";
1.301 albertel 3645:
3646: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3647: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3648:
1.44 ng 3649: if ($updateflag) {
3650: $count++;
1.257 albertel 3651: &Apache::lonnet::cstore(\%newrecord,$symb,$env{'request.course.id'},
1.89 albertel 3652: $udom,$uname);
1.301 albertel 3653:
3654: if (&Apache::bridgetask::in_queue('gradingqueue',$symb,$cdom,
3655: $cnum,$udom,$uname)) {
3656: # need to figure out if should be in queue.
3657: my %record =
3658: &Apache::lonnet::restore($symb,$env{'request.course.id'},
3659: $udom,$uname);
3660: my $all_graded = 1;
3661: my $none_graded = 1;
3662: foreach my $part (@parts) {
3663: if ( $record{'resource.'.$part.'.awarded'} eq '' ) {
3664: $all_graded = 0;
3665: } else {
3666: $none_graded = 0;
3667: }
3668: }
3669:
3670: if ($all_graded || $none_graded) {
3671: &Apache::bridgetask::remove_from_queue('gradingqueue',
3672: $symb,$cdom,$cnum,
3673: $udom,$uname);
3674: }
3675: }
3676:
1.477 albertel 3677: $result.=&Apache::loncommon::start_data_table_row().
3678: '<td align="right"> '.$updateCtr.' </td>'.$line.
3679: &Apache::loncommon::end_data_table_row();
1.126 ng 3680: $updateCtr++;
1.93 albertel 3681: } else {
1.477 albertel 3682: push(@noupdate,
3683: '<td align="right"> '.$noupdateCtr.' </td>'.$line);
1.126 ng 3684: $noupdateCtr++;
1.44 ng 3685: }
1.269 raeburn 3686: if ($aggregateflag) {
3687: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 3688: $cdom,$cnum);
1.269 raeburn 3689: }
1.93 albertel 3690: }
1.477 albertel 3691: if (@noupdate) {
1.126 ng 3692: # my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3;
3693: my $numcols=scalar(@partid)*4+2;
1.477 albertel 3694: $result .= &Apache::loncommon::start_data_table_row('LC_empty_row').
1.478 albertel 3695: '<td align="center" colspan="'.$numcols.'">'.
3696: &mt('No Changes Occurred For the Students Below').
3697: '</td>'.
1.477 albertel 3698: &Apache::loncommon::end_data_table_row();
3699: foreach my $line (@noupdate) {
3700: $result.=
3701: &Apache::loncommon::start_data_table_row().
3702: $line.
3703: &Apache::loncommon::end_data_table_row();
3704: }
1.44 ng 3705: }
1.614 www 3706: $result .= &Apache::loncommon::end_data_table();
1.478 albertel 3707: my $msg = '<p><b>'.
3708: &mt('Number of records updated = [_1] for [quant,_2,student].',
3709: $rec_update,$count).'</b><br />'.
3710: '<b>'.&mt('Total number of students = [_1]',$env{'form.total'}).
3711: '</b></p>';
1.44 ng 3712: return $title.$msg.$result;
1.5 albertel 3713: }
1.54 albertel 3714:
3715: sub split_part_type {
3716: my ($partstr) = @_;
3717: my ($temp,@allparts)=split(/_/,$partstr);
3718: my $type=pop(@allparts);
1.439 albertel 3719: my $part=join('_',@allparts);
1.54 albertel 3720: return ($part,$type);
3721: }
3722:
1.44 ng 3723: #------------- end of section for handling grading by section/class ---------
3724: #
3725: #----------------------------------------------------------------------------
3726:
1.5 albertel 3727:
1.44 ng 3728: #----------------------------------------------------------------------------
3729: #
3730: #-------------------------- Next few routines handles grading by csv upload
3731: #
3732: #--- Javascript to handle csv upload
1.27 albertel 3733: sub csvupload_javascript_reverse_associate {
1.573 bisitz 3734: my $error1=&mt('You need to specify the username or the student/employee ID');
1.246 albertel 3735: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3736: return(<<ENDPICK);
3737: function verify(vf) {
3738: var foundsomething=0;
3739: var founduname=0;
1.243 albertel 3740: var foundID=0;
1.27 albertel 3741: for (i=0;i<=vf.nfields.value;i++) {
3742: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3743: if (i==0 && tw!=0) { foundID=1; }
3744: if (i==1 && tw!=0) { founduname=1; }
3745: if (i!=0 && i!=1 && i!=2 && tw!=0) { foundsomething=1; }
1.27 albertel 3746: }
1.246 albertel 3747: if (founduname==0 && foundID==0) {
3748: alert('$error1');
3749: return;
1.27 albertel 3750: }
3751: if (foundsomething==0) {
1.246 albertel 3752: alert('$error2');
3753: return;
1.27 albertel 3754: }
3755: vf.submit();
3756: }
3757: function flip(vf,tf) {
3758: var nw=eval('vf.f'+tf+'.selectedIndex');
3759: var i;
3760: for (i=0;i<=vf.nfields.value;i++) {
3761: //can not pick the same destination field for both name and domain
3762: if (((i ==0)||(i ==1)) &&
3763: ((tf==0)||(tf==1)) &&
3764: (i!=tf) &&
3765: (eval('vf.f'+i+'.selectedIndex')==nw)) {
3766: eval('vf.f'+i+'.selectedIndex=0;')
3767: }
3768: }
3769: }
3770: ENDPICK
3771: }
3772:
3773: sub csvupload_javascript_forward_associate {
1.573 bisitz 3774: my $error1=&mt('You need to specify the username or the student/employee ID');
1.246 albertel 3775: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3776: return(<<ENDPICK);
3777: function verify(vf) {
3778: var foundsomething=0;
3779: var founduname=0;
1.243 albertel 3780: var foundID=0;
1.27 albertel 3781: for (i=0;i<=vf.nfields.value;i++) {
3782: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3783: if (tw==1) { foundID=1; }
3784: if (tw==2) { founduname=1; }
3785: if (tw>3) { foundsomething=1; }
1.27 albertel 3786: }
1.246 albertel 3787: if (founduname==0 && foundID==0) {
3788: alert('$error1');
3789: return;
1.27 albertel 3790: }
3791: if (foundsomething==0) {
1.246 albertel 3792: alert('$error2');
3793: return;
1.27 albertel 3794: }
3795: vf.submit();
3796: }
3797: function flip(vf,tf) {
3798: var nw=eval('vf.f'+tf+'.selectedIndex');
3799: var i;
3800: //can not pick the same destination field twice
3801: for (i=0;i<=vf.nfields.value;i++) {
3802: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
3803: eval('vf.f'+i+'.selectedIndex=0;')
3804: }
3805: }
3806: }
3807: ENDPICK
3808: }
3809:
1.26 albertel 3810: sub csvuploadmap_header {
1.324 albertel 3811: my ($request,$symb,$datatoken,$distotal)= @_;
1.41 ng 3812: my $javascript;
1.257 albertel 3813: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3814: $javascript=&csvupload_javascript_reverse_associate();
3815: } else {
3816: $javascript=&csvupload_javascript_forward_associate();
3817: }
1.45 ng 3818:
1.598 www 3819: my $result='';
1.257 albertel 3820: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1.245 albertel 3821: my $ignore=&mt('Ignore First Line');
1.418 albertel 3822: $symb = &Apache::lonenc::check_encrypt($symb);
1.41 ng 3823: $request->print(<<ENDPICK);
1.26 albertel 3824: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.398 albertel 3825: <h3><span class="LC_info">Uploading Class Grades</span></h3>
1.45 ng 3826: $result
1.326 albertel 3827: <hr />
1.26 albertel 3828: <h3>Identify fields</h3>
3829: Total number of records found in file: $distotal <hr />
3830: Enter as many fields as you can. The system will inform you and bring you back
3831: to this page if the data selected is insufficient to run your class.<hr />
1.589 bisitz 3832: <input type="button" value="Reverse Association" onclick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1.245 albertel 3833: <label><input type="checkbox" name="noFirstLine" $checked />$ignore</label>
1.26 albertel 3834: <input type="hidden" name="associate" value="" />
3835: <input type="hidden" name="phase" value="three" />
3836: <input type="hidden" name="datatoken" value="$datatoken" />
1.257 albertel 3837: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
3838: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
1.26 albertel 3839: <input type="hidden" name="upfile_associate"
1.257 albertel 3840: value="$env{'form.upfile_associate'}" />
1.26 albertel 3841: <input type="hidden" name="symb" value="$symb" />
1.246 albertel 3842: <input type="hidden" name="command" value="csvuploadoptions" />
1.26 albertel 3843: <hr />
3844: ENDPICK
1.597 wenzelju 3845: $request->print(&Apache::lonhtmlcommon::scripttag($javascript));
1.118 ng 3846: return '';
1.26 albertel 3847:
3848: }
3849:
3850: sub csvupload_fields {
1.582 raeburn 3851: my ($symb,$errorref) = @_;
3852: my (@parts) = &getpartlist($symb,$errorref);
3853: if (ref($errorref)) {
3854: if ($$errorref) {
3855: return;
3856: }
3857: }
3858:
1.556 weissno 3859: my @fields=(['ID','Student/Employee ID'],
1.243 albertel 3860: ['username','Student Username'],
3861: ['domain','Student Domain']);
1.324 albertel 3862: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.41 ng 3863: foreach my $part (sort(@parts)) {
3864: my @datum;
3865: my $display=&Apache::lonnet::metadata($url,$part.'.display');
3866: my $name=$part;
3867: if (!$display) { $display = $name; }
3868: @datum=($name,$display);
1.244 albertel 3869: if ($name=~/^stores_(.*)_awarded/) {
3870: push(@fields,['stores_'.$1.'_points',"Points [Part: $1]"]);
3871: }
1.41 ng 3872: push(@fields,\@datum);
3873: }
3874: return (@fields);
1.26 albertel 3875: }
3876:
3877: sub csvuploadmap_footer {
1.41 ng 3878: my ($request,$i,$keyfields) =@_;
3879: $request->print(<<ENDPICK);
1.26 albertel 3880: </table>
3881: <input type="hidden" name="nfields" value="$i" />
3882: <input type="hidden" name="keyfields" value="$keyfields" />
1.589 bisitz 3883: <input type="button" onclick="javascript:verify(this.form)" value="Assign Grades" /><br />
1.26 albertel 3884: </form>
3885: ENDPICK
3886: }
3887:
1.283 albertel 3888: sub checkforfile_js {
1.539 riegler 3889: my $alertmsg = &mt('Please use the browse button to select a file from your local directory.');
1.597 wenzelju 3890: my $result = &Apache::lonhtmlcommon::scripttag(<<CSVFORMJS);
1.86 ng 3891: function checkUpload(formname) {
3892: if (formname.upfile.value == "") {
1.539 riegler 3893: alert("$alertmsg");
1.86 ng 3894: return false;
3895: }
3896: formname.submit();
3897: }
3898: CSVFORMJS
1.283 albertel 3899: return $result;
3900: }
3901:
3902: sub upcsvScores_form {
1.608 www 3903: my ($request,$symb) = @_;
1.283 albertel 3904: if (!$symb) {return '';}
3905: my $result=&checkforfile_js();
1.326 albertel 3906: $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
3907: $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
1.538 schulted 3908: $result.=' <b>'.&mt('Specify a file containing the class scores for current resource.').
3909: '</b></td></tr>'."\n";
1.86 ng 3910: $result.='<tr bgcolor=#ffffe6><td>'."\n";
1.370 www 3911: my $upload=&mt("Upload Scores");
1.86 ng 3912: my $upfile_select=&Apache::loncommon::upfile_select_html();
1.245 albertel 3913: my $ignore=&mt('Ignore First Line');
1.418 albertel 3914: $symb = &Apache::lonenc::check_encrypt($symb);
1.86 ng 3915: $result.=<<ENDUPFORM;
1.106 albertel 3916: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.86 ng 3917: <input type="hidden" name="symb" value="$symb" />
3918: <input type="hidden" name="command" value="csvuploadmap" />
3919: $upfile_select
1.589 bisitz 3920: <br /><input type="button" onclick="javascript:checkUpload(this.form);" value="$upload" />
1.283 albertel 3921: <label><input type="checkbox" name="noFirstLine" />$ignore</label>
1.86 ng 3922: </form>
3923: ENDUPFORM
1.370 www 3924: $result.=&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
3925: &mt("How do I create a CSV file from a spreadsheet"))
3926: .'</td></tr></table>'."\n";
1.86 ng 3927: $result.='</td></tr></table><br /><br />'."\n";
3928: return $result;
3929: }
3930:
3931:
1.26 albertel 3932: sub csvuploadmap {
1.608 www 3933: my ($request,$symb)= @_;
1.41 ng 3934: if (!$symb) {return '';}
1.72 ng 3935:
1.41 ng 3936: my $datatoken;
1.257 albertel 3937: if (!$env{'form.datatoken'}) {
1.41 ng 3938: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 3939: } else {
1.257 albertel 3940: $datatoken=$env{'form.datatoken'};
1.41 ng 3941: &Apache::loncommon::load_tmp_file($request);
1.26 albertel 3942: }
1.41 ng 3943: my @records=&Apache::loncommon::upfile_record_sep();
1.257 albertel 3944: if ($env{'form.noFirstLine'}) { shift(@records); }
1.324 albertel 3945: &csvuploadmap_header($request,$symb,$datatoken,$#records+1);
1.41 ng 3946: my ($i,$keyfields);
3947: if (@records) {
1.582 raeburn 3948: my $fieldserror;
3949: my @fields=&csvupload_fields($symb,\$fieldserror);
3950: if ($fieldserror) {
3951: $request->print(&navmap_errormsg());
3952: return;
3953: }
1.257 albertel 3954: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3955: &Apache::loncommon::csv_print_samples($request,\@records);
3956: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
3957: \@fields);
3958: foreach (@fields) { $keyfields.=$_->[0].','; }
3959: chop($keyfields);
3960: } else {
3961: unshift(@fields,['none','']);
3962: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
3963: \@fields);
1.311 banghart 3964: foreach my $rec (@records) {
3965: my %temp = &Apache::loncommon::record_sep($rec);
3966: if (%temp) {
3967: $keyfields=join(',',sort(keys(%temp)));
3968: last;
3969: }
3970: }
1.41 ng 3971: }
3972: }
3973: &csvuploadmap_footer($request,$i,$keyfields);
1.72 ng 3974:
1.41 ng 3975: return '';
1.27 albertel 3976: }
3977:
1.246 albertel 3978: sub csvuploadoptions {
1.608 www 3979: my ($request,$symb)= @_;
1.257 albertel 3980: my $checked=(($env{'form.noFirstLine'})?'1':'0');
1.246 albertel 3981: my $ignore=&mt('Ignore First Line');
3982: $request->print(<<ENDPICK);
3983: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.398 albertel 3984: <h3><span class="LC_info">Uploading Class Grade Options</span></h3>
1.246 albertel 3985: <input type="hidden" name="command" value="csvuploadassign" />
1.302 albertel 3986: <!--
1.246 albertel 3987: <p>
3988: <label>
3989: <input type="checkbox" name="show_full_results" />
3990: Show a table of all changes
3991: </label>
3992: </p>
1.302 albertel 3993: -->
1.246 albertel 3994: <p>
3995: <label>
3996: <input type="checkbox" name="overwite_scores" checked="checked" />
3997: Overwrite any existing score
3998: </label>
3999: </p>
4000: ENDPICK
4001: my %fields=&get_fields();
4002: if (!defined($fields{'domain'})) {
1.257 albertel 4003: my $domform = &Apache::loncommon::select_dom_form($env{'request.role.domain'},'default_domain');
1.246 albertel 4004: $request->print("\n<p> Users are in domain: ".$domform."</p>\n");
4005: }
1.257 albertel 4006: foreach my $key (sort(keys(%env))) {
1.246 albertel 4007: if ($key !~ /^form\.(.*)$/) { next; }
4008: my $cleankey=$1;
4009: if ($cleankey eq 'command') { next; }
4010: $request->print('<input type="hidden" name="'.$cleankey.
1.257 albertel 4011: '" value="'.$env{$key}.'" />'."\n");
1.246 albertel 4012: }
4013: # FIXME do a check for any duplicated user ids...
4014: # FIXME do a check for any invalid user ids?...
1.290 albertel 4015: $request->print('<input type="submit" value="Assign Grades" /><br />
4016: <hr /></form>'."\n");
1.246 albertel 4017: return '';
4018: }
4019:
4020: sub get_fields {
4021: my %fields;
1.257 albertel 4022: my @keyfields = split(/\,/,$env{'form.keyfields'});
4023: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
4024: if ($env{'form.upfile_associate'} eq 'reverse') {
4025: if ($env{'form.f'.$i} ne 'none') {
4026: $fields{$keyfields[$i]}=$env{'form.f'.$i};
1.41 ng 4027: }
4028: } else {
1.257 albertel 4029: if ($env{'form.f'.$i} ne 'none') {
4030: $fields{$env{'form.f'.$i}}=$keyfields[$i];
1.41 ng 4031: }
4032: }
1.27 albertel 4033: }
1.246 albertel 4034: return %fields;
4035: }
4036:
4037: sub csvuploadassign {
1.608 www 4038: my ($request,$symb)= @_;
1.246 albertel 4039: if (!$symb) {return '';}
1.345 bowersj2 4040: my $error_msg = '';
1.246 albertel 4041: &Apache::loncommon::load_tmp_file($request);
4042: my @gradedata = &Apache::loncommon::upfile_record_sep();
1.257 albertel 4043: if ($env{'form.noFirstLine'}) { shift(@gradedata); }
1.246 albertel 4044: my %fields=&get_fields();
1.41 ng 4045: $request->print('<h3>Assigning Grades</h3>');
1.257 albertel 4046: my $courseid=$env{'request.course.id'};
1.97 albertel 4047: my ($classlist) = &getclasslist('all',0);
1.106 albertel 4048: my @notallowed;
1.41 ng 4049: my @skipped;
4050: my $countdone=0;
4051: foreach my $grade (@gradedata) {
4052: my %entries=&Apache::loncommon::record_sep($grade);
1.246 albertel 4053: my $domain;
4054: if ($entries{$fields{'domain'}}) {
4055: $domain=$entries{$fields{'domain'}};
4056: } else {
1.257 albertel 4057: $domain=$env{'form.default_domain'};
1.246 albertel 4058: }
1.243 albertel 4059: $domain=~s/\s//g;
1.41 ng 4060: my $username=$entries{$fields{'username'}};
1.160 albertel 4061: $username=~s/\s//g;
1.243 albertel 4062: if (!$username) {
4063: my $id=$entries{$fields{'ID'}};
1.247 albertel 4064: $id=~s/\s//g;
1.243 albertel 4065: my %ids=&Apache::lonnet::idget($domain,$id);
4066: $username=$ids{$id};
4067: }
1.41 ng 4068: if (!exists($$classlist{"$username:$domain"})) {
1.247 albertel 4069: my $id=$entries{$fields{'ID'}};
4070: $id=~s/\s//g;
4071: if ($id) {
4072: push(@skipped,"$id:$domain");
4073: } else {
4074: push(@skipped,"$username:$domain");
4075: }
1.41 ng 4076: next;
4077: }
1.108 albertel 4078: my $usec=$classlist->{"$username:$domain"}[5];
1.106 albertel 4079: if (!&canmodify($usec)) {
4080: push(@notallowed,"$username:$domain");
4081: next;
4082: }
1.244 albertel 4083: my %points;
1.41 ng 4084: my %grades;
4085: foreach my $dest (keys(%fields)) {
1.244 albertel 4086: if ($dest eq 'ID' || $dest eq 'username' ||
4087: $dest eq 'domain') { next; }
4088: if ($entries{$fields{$dest}} =~ /^\s*$/) { next; }
4089: if ($dest=~/stores_(.*)_points/) {
4090: my $part=$1;
4091: my $wgt =&Apache::lonnet::EXT('resource.'.$part.'.weight',
4092: $symb,$domain,$username);
1.345 bowersj2 4093: if ($wgt) {
4094: $entries{$fields{$dest}}=~s/\s//g;
4095: my $pcr=$entries{$fields{$dest}} / $wgt;
1.463 albertel 4096: my $award=($pcr == 0) ? 'incorrect_by_override'
4097: : 'correct_by_override';
1.345 bowersj2 4098: $grades{"resource.$part.awarded"}=$pcr;
4099: $grades{"resource.$part.solved"}=$award;
4100: $points{$part}=1;
4101: } else {
4102: $error_msg = "<br />" .
4103: &mt("Some point values were assigned"
4104: ." for problems with a weight "
4105: ."of zero. These values were "
4106: ."ignored.");
4107: }
1.244 albertel 4108: } else {
4109: if ($dest=~/stores_(.*)_awarded/) { if ($points{$1}) {next;} }
4110: if ($dest=~/stores_(.*)_solved/) { if ($points{$1}) {next;} }
4111: my $store_key=$dest;
4112: $store_key=~s/^stores/resource/;
4113: $store_key=~s/_/\./g;
4114: $grades{$store_key}=$entries{$fields{$dest}};
4115: }
1.41 ng 4116: }
1.508 www 4117: if (! %grades) {
4118: push(@skipped,&mt("[_1]: no data to save","$username:$domain"));
4119: } else {
4120: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
4121: my $result=&Apache::lonnet::cstore(\%grades,$symb,
1.302 albertel 4122: $env{'request.course.id'},
4123: $domain,$username);
1.508 www 4124: if ($result eq 'ok') {
4125: $request->print('.');
4126: } else {
4127: $request->print("<p><span class=\"LC_error\">".
4128: &mt("Failed to save data for student [_1]. Message when trying to save was: [_2]",
4129: "$username:$domain",$result)."</span></p>");
4130: }
4131: $request->rflush();
4132: $countdone++;
4133: }
1.41 ng 4134: }
1.570 www 4135: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt("Saved scores for [quant,_1,student]",$countdone),$countdone==0));
1.41 ng 4136: if (@skipped) {
1.571 www 4137: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('No scores stored for the following username(s):'),1).'<br />');
4138: $request->print(join(', ',@skipped));
1.106 albertel 4139: }
4140: if (@notallowed) {
1.571 www 4141: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('Modification of scores not allowed for the following username(s):'),1).'<br />');
4142: $request->print(join(', ',@notallowed));
1.41 ng 4143: }
1.106 albertel 4144: $request->print("<br />\n");
1.345 bowersj2 4145: return $error_msg;
1.26 albertel 4146: }
1.44 ng 4147: #------------- end of section for handling csv file upload ---------
4148: #
4149: #-------------------------------------------------------------------
4150: #
1.122 ng 4151: #-------------- Next few routines handle grading by page/sequence
1.72 ng 4152: #
4153: #--- Select a page/sequence and a student to grade
1.68 ng 4154: sub pickStudentPage {
1.608 www 4155: my ($request,$symb) = @_;
1.68 ng 4156:
1.539 riegler 4157: my $alertmsg = &mt('Please select the student you wish to grade.');
1.597 wenzelju 4158: $request->print(&Apache::lonhtmlcommon::scripttag(<<LISTJAVASCRIPT));
1.68 ng 4159:
4160: function checkPickOne(formname) {
1.76 ng 4161: if (radioSelection(formname.student) == null) {
1.539 riegler 4162: alert("$alertmsg");
1.68 ng 4163: return;
4164: }
1.125 ng 4165: ptr = pullDownSelection(formname.selectpage);
4166: formname.page.value = formname["page"+ptr].value;
4167: formname.title.value = formname["title"+ptr].value;
1.68 ng 4168: formname.submit();
4169: }
4170:
4171: LISTJAVASCRIPT
1.118 ng 4172: &commonJSfunctions($request);
1.608 www 4173:
1.257 albertel 4174: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4175: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4176: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.68 ng 4177:
1.398 albertel 4178: my $result='<h3><span class="LC_info"> '.
1.485 albertel 4179: &mt('Manual Grading by Page or Sequence').'</span></h3>';
1.68 ng 4180:
1.80 ng 4181: $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
1.582 raeburn 4182: my $map_error;
4183: my ($titles,$symbx) = &getSymbMap($map_error);
4184: if ($map_error) {
4185: $request->print(&navmap_errormsg());
4186: return;
4187: }
1.137 albertel 4188: my ($curpage) =&Apache::lonnet::decode_symb($symb);
4189: # my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb);
4190: # my $type=($curpage =~ /\.(page|sequence)/);
1.485 albertel 4191: my $select = '<select name="selectpage">'."\n";
1.70 ng 4192: my $ctr=0;
1.68 ng 4193: foreach (@$titles) {
4194: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.485 albertel 4195: $select.='<option value="'.$ctr.'" '.
1.401 albertel 4196: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.71 ng 4197: '>'.$showtitle.'</option>'."\n";
1.70 ng 4198: $ctr++;
1.68 ng 4199: }
1.485 albertel 4200: $select.= '</select>';
1.539 riegler 4201: $result.=' <b>'.&mt('Problems from').':</b> '.$select."<br />\n";
1.485 albertel 4202:
1.70 ng 4203: $ctr=0;
4204: foreach (@$titles) {
4205: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
4206: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
4207: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
4208: $ctr++;
4209: }
1.72 ng 4210: $result.='<input type="hidden" name="page" />'."\n".
4211: '<input type="hidden" name="title" />'."\n";
1.68 ng 4212:
1.485 albertel 4213: my $options =
4214: '<label><input type="radio" name="vProb" value="no" checked="checked" /> '.&mt('no').' </label>'."\n".
4215: '<label><input type="radio" name="vProb" value="yes" /> '.&mt('yes').' </label>'."<br />\n";
1.539 riegler 4216: $result.=' <b>'.&mt('View Problem Text').': </b>'.$options;
1.485 albertel 4217:
4218: $options =
4219: '<label><input type="radio" name="lastSub" value="none" /> '.&mt('none').' </label>'."\n".
4220: '<label><input type="radio" name="lastSub" value="datesub" checked="checked" /> '.&mt('by dates and submissions').'</label>'."\n".
4221: '<label><input type="radio" name="lastSub" value="all" /> '.&mt('all details').' </label>'."\n";
1.539 riegler 4222: $result.=' <b>'.&mt('Submissions').': </b>'.$options;
1.432 banghart 4223:
4224: $result.=&build_section_inputs();
1.442 banghart 4225: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
4226: $result.='<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.72 ng 4227: '<input type="hidden" name="command" value="displayPage" />'."\n".
1.613 www 4228: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."<br />\n";
1.72 ng 4229:
1.539 riegler 4230: $result.=' <b>'.&mt('Use CODE').': </b> <input type="text" name="CODE" value="" /> <br />'."\n";
1.382 albertel 4231:
1.80 ng 4232: $result.=' <input type="button" '.
1.589 bisitz 4233: 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /><br />'."\n";
1.72 ng 4234:
1.68 ng 4235: $request->print($result);
4236:
1.485 albertel 4237: my $studentTable.=' <b>'.&mt('Select a student you wish to grade and then click on the Next button.').'</b><br />'.
1.484 albertel 4238: &Apache::loncommon::start_data_table().
4239: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 4240: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 4241: '<th>'.&nameUserString('header').'</th>'.
1.485 albertel 4242: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 4243: '<th>'.&nameUserString('header').'</th>'.
4244: &Apache::loncommon::end_data_table_header_row();
1.68 ng 4245:
1.76 ng 4246: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.68 ng 4247: my $ptr = 1;
1.294 albertel 4248: foreach my $student (sort
4249: {
4250: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
4251: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
4252: }
4253: return $a cmp $b;
4254: } (keys(%$fullname))) {
1.68 ng 4255: my ($uname,$udom) = split(/:/,$student);
1.484 albertel 4256: $studentTable.=($ptr%2==1 ? &Apache::loncommon::start_data_table_row()
4257: : '</td>');
1.126 ng 4258: $studentTable.='<td align="right">'.$ptr.' </td>';
1.288 albertel 4259: $studentTable.='<td> <label><input type="radio" name="student" value="'.$student.'" /> '
4260: .&nameUserString(undef,$$fullname{$student},$uname,$udom)."</label>\n";
1.484 albertel 4261: $studentTable.=
4262: ($ptr%2 == 0 ? '</td>'.&Apache::loncommon::end_data_table_row()
4263: : '');
1.68 ng 4264: $ptr++;
4265: }
1.484 albertel 4266: if ($ptr%2 == 0) {
4267: $studentTable.='</td><td> </td><td> </td>'.
4268: &Apache::loncommon::end_data_table_row();
4269: }
4270: $studentTable.=&Apache::loncommon::end_data_table()."\n";
1.126 ng 4271: $studentTable.='<input type="button" '.
1.589 bisitz 4272: 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /></form>'."\n";
1.68 ng 4273:
4274: $request->print($studentTable);
4275:
4276: return '';
4277: }
4278:
4279: sub getSymbMap {
1.582 raeburn 4280: my ($map_error) = @_;
1.132 bowersj2 4281: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 4282: unless (ref($navmap)) {
4283: if (ref($map_error)) {
4284: $$map_error = 'navmap';
4285: }
4286: return;
4287: }
1.68 ng 4288: my %symbx = ();
4289: my @titles = ();
1.117 bowersj2 4290: my $minder = 0;
4291:
4292: # Gather every sequence that has problems.
1.240 albertel 4293: my @sequences = $navmap->retrieveResources(undef, sub { shift->is_map(); },
4294: 1,0,1);
1.117 bowersj2 4295: for my $sequence ($navmap->getById('0.0'), @sequences) {
1.241 albertel 4296: if ($navmap->hasResource($sequence, sub { shift->is_problem(); }, 0) ) {
1.381 albertel 4297: my $title = $minder.'.'.
4298: &HTML::Entities::encode($sequence->compTitle(),'"\'&');
4299: push(@titles, $title); # minder in case two titles are identical
4300: $symbx{$title} = &HTML::Entities::encode($sequence->symb(),'"\'&');
1.117 bowersj2 4301: $minder++;
1.241 albertel 4302: }
1.68 ng 4303: }
4304: return \@titles,\%symbx;
4305: }
4306:
1.72 ng 4307: #
4308: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68 ng 4309: sub displayPage {
1.608 www 4310: my ($request,$symb) = @_;
1.257 albertel 4311: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4312: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4313: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
4314: my $pageTitle = $env{'form.page'};
1.103 albertel 4315: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 4316: my ($uname,$udom) = split(/:/,$env{'form.student'});
4317: my $usec=$classlist->{$env{'form.student'}}[5];
1.168 albertel 4318:
4319: #need to make sure we have the correct data for later EXT calls,
4320: #thus invalidate the cache
4321: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 4322: $env{'course.'.$env{'request.course.id'}.'.num'},
4323: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 4324: &Apache::lonnet::clear_EXT_cache_status();
4325:
1.103 albertel 4326: if (!&canview($usec)) {
1.485 albertel 4327: $request->print('<span class="LC_warning">'.&mt('Unable to view requested student. ([_1])',$env{'form.student'}).'</span>');
1.103 albertel 4328: return;
4329: }
1.398 albertel 4330: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.485 albertel 4331: $result.='<h3> '.&mt('Student: [_1]',&nameUserString(undef,$$fullname{$env{'form.student'}},$uname,$udom)).
1.129 ng 4332: '</h3>'."\n";
1.500 albertel 4333: $env{'form.CODE'} = uc($env{'form.CODE'});
1.501 foxr 4334: if (&Apache::lonnet::validCODE(uc($env{'form.CODE'}))) {
1.485 albertel 4335: $result.='<h3> '.&mt('CODE: [_1]',$env{'form.CODE'}).'</h3>'."\n";
1.382 albertel 4336: } else {
4337: delete($env{'form.CODE'});
4338: }
1.71 ng 4339: &sub_page_js($request);
4340: $request->print($result);
4341:
1.132 bowersj2 4342: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 4343: unless (ref($navmap)) {
4344: $request->print(&navmap_errormsg());
4345: return;
4346: }
1.257 albertel 4347: my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($env{'form.page'});
1.68 ng 4348: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 4349: if (!$map) {
1.485 albertel 4350: $request->print('<span class="LC_warning">'.&mt('Unable to view requested sequence. ([_1])',$resUrl).'</span>');
1.288 albertel 4351: return;
4352: }
1.68 ng 4353: my $iterator = $navmap->getIterator($map->map_start(),
4354: $map->map_finish());
4355:
1.71 ng 4356: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72 ng 4357: '<input type="hidden" name="command" value="gradeByPage" />'."\n".
1.257 albertel 4358: '<input type="hidden" name="fullname" value="'.$$fullname{$env{'form.student'}}.'" />'."\n".
4359: '<input type="hidden" name="student" value="'.$env{'form.student'}.'" />'."\n".
1.72 ng 4360: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
1.257 albertel 4361: '<input type="hidden" name="title" value="'.$env{'form.title'}.'" />'."\n".
1.418 albertel 4362: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.613 www 4363: '<input type="hidden" name="overRideScore" value="no" />'."\n";
1.71 ng 4364:
1.382 albertel 4365: if (defined($env{'form.CODE'})) {
4366: $studentTable.=
4367: '<input type="hidden" name="CODE" value="'.$env{'form.CODE'}.'" />'."\n";
4368: }
1.381 albertel 4369: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 4370: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 4371:
1.594 bisitz 4372: $studentTable.=' <span class="LC_info">'.
4373: &mt('Problems graded correct by the computer are marked with a [_1] symbol.',$checkIcon).
4374: '</span>'."\n".
1.484 albertel 4375: &Apache::loncommon::start_data_table().
4376: &Apache::loncommon::start_data_table_header_row().
4377: '<th align="center"> Prob. </th>'.
1.485 albertel 4378: '<th> '.($env{'form.vProb'} eq 'no' ? &mt('Title') : &mt('Problem Text')).'/'.&mt('Grade').'</th>'.
1.484 albertel 4379: &Apache::loncommon::end_data_table_header_row();
1.71 ng 4380:
1.329 albertel 4381: &Apache::lonxml::clear_problem_counter();
1.196 albertel 4382: my ($depth,$question,$prob) = (1,1,1);
1.68 ng 4383: $iterator->next(); # skip the first BEGIN_MAP
4384: my $curRes = $iterator->next(); # for "current resource"
1.101 albertel 4385: while ($depth > 0) {
1.68 ng 4386: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4387: if($curRes == $iterator->END_MAP) { $depth--; }
1.68 ng 4388:
1.385 albertel 4389: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4390: my $parts = $curRes->parts();
1.68 ng 4391: my $title = $curRes->compTitle();
1.71 ng 4392: my $symbx = $curRes->symb();
1.484 albertel 4393: $studentTable.=
4394: &Apache::loncommon::start_data_table_row().
4395: '<td align="center" valign="top" >'.$prob.
1.485 albertel 4396: (scalar(@{$parts}) == 1 ? ''
4397: : '<br />('.&mt('[_1] parts)',
4398: scalar(@{$parts}))
4399: ).
4400: '</td>';
1.71 ng 4401: $studentTable.='<td valign="top">';
1.382 albertel 4402: my %form = ('CODE' => $env{'form.CODE'},);
1.257 albertel 4403: if ($env{'form.vProb'} eq 'yes' ) {
1.144 albertel 4404: $studentTable.=&show_problem($request,$symbx,$uname,$udom,1,
1.383 albertel 4405: undef,'both',\%form);
1.71 ng 4406: } else {
1.382 albertel 4407: my $companswer = &Apache::loncommon::get_student_answers($symbx,$uname,$udom,$env{'request.course.id'},%form);
1.80 ng 4408: $companswer =~ s|<form(.*?)>||g;
4409: $companswer =~ s|</form>||g;
1.71 ng 4410: # while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
1.116 ng 4411: # $companswer =~ s/$1/ /ms;
1.326 albertel 4412: # $request->print('match='.$1."<br />\n");
1.71 ng 4413: # }
1.116 ng 4414: # $companswer =~ s|<table border=\"1\">|<table border=\"0\">|g;
1.539 riegler 4415: $studentTable.=' <b>'.$title.'</b> <br /> <b>'.&mt('Correct answer').':</b><br />'.$companswer;
1.71 ng 4416: }
4417:
1.257 albertel 4418: my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
1.125 ng 4419:
1.257 albertel 4420: if ($env{'form.lastSub'} eq 'datesub') {
1.71 ng 4421: if ($record{'version'} eq '') {
1.485 albertel 4422: $studentTable.='<br /> <span class="LC_warning">'.&mt('No recorded submission for this problem.').'</span><br />';
1.71 ng 4423: } else {
1.116 ng 4424: my %responseType = ();
4425: foreach my $partid (@{$parts}) {
1.147 albertel 4426: my @responseIds =$curRes->responseIds($partid);
4427: my @responseType =$curRes->responseType($partid);
4428: my %responseIds;
4429: for (my $i=0;$i<=$#responseIds;$i++) {
4430: $responseIds{$responseIds[$i]}=$responseType[$i];
4431: }
4432: $responseType{$partid} = \%responseIds;
1.116 ng 4433: }
1.148 albertel 4434: $studentTable.= &displaySubByDates($symbx,\%record,$parts,\%responseType,$checkIcon,$uname,$udom);
1.147 albertel 4435:
1.71 ng 4436: }
1.257 albertel 4437: } elsif ($env{'form.lastSub'} eq 'all') {
4438: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.71 ng 4439: $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
1.257 albertel 4440: $env{'request.course.id'},
1.71 ng 4441: '','.submission');
4442:
4443: }
1.103 albertel 4444: if (&canmodify($usec)) {
1.585 bisitz 4445: $studentTable.=&gradeBox_start();
1.103 albertel 4446: foreach my $partid (@{$parts}) {
4447: $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
4448: $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
4449: $question++;
4450: }
1.585 bisitz 4451: $studentTable.=&gradeBox_end();
1.196 albertel 4452: $prob++;
1.71 ng 4453: }
4454: $studentTable.='</td></tr>';
1.68 ng 4455:
1.103 albertel 4456: }
1.68 ng 4457: $curRes = $iterator->next();
4458: }
4459:
1.589 bisitz 4460: $studentTable.=
4461: '</table>'."\n".
4462: '<input type="button" value="'.&mt('Save').'" '.
4463: 'onclick="javascript:checkSubmitPage(this.form,'.$question.');" />'.
4464: '</form>'."\n";
1.71 ng 4465: $request->print($studentTable);
4466:
4467: return '';
1.119 ng 4468: }
4469:
4470: sub displaySubByDates {
1.148 albertel 4471: my ($symb,$record,$parts,$responseType,$checkIcon,$uname,$udom) = @_;
1.224 albertel 4472: my $isCODE=0;
1.335 albertel 4473: my $isTask = ($symb =~/\.task$/);
1.224 albertel 4474: if (exists($record->{'resource.CODE'})) { $isCODE=1; }
1.467 albertel 4475: my $studentTable=&Apache::loncommon::start_data_table().
4476: &Apache::loncommon::start_data_table_header_row().
4477: '<th>'.&mt('Date/Time').'</th>'.
4478: ($isCODE?'<th>'.&mt('CODE').'</th>':'').
4479: '<th>'.&mt('Submission').'</th>'.
4480: '<th>'.&mt('Status').'</th>'.
4481: &Apache::loncommon::end_data_table_header_row();
1.119 ng 4482: my ($version);
4483: my %mark;
1.148 albertel 4484: my %orders;
1.119 ng 4485: $mark{'correct_by_student'} = $checkIcon;
1.147 albertel 4486: if (!exists($$record{'1:timestamp'})) {
1.539 riegler 4487: return '<br /> <span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br />';
1.147 albertel 4488: }
1.335 albertel 4489:
4490: my $interaction;
1.525 raeburn 4491: my $no_increment = 1;
1.119 ng 4492: for ($version=1;$version<=$$record{'version'};$version++) {
1.467 albertel 4493: my $timestamp =
4494: &Apache::lonlocal::locallocaltime($$record{$version.':timestamp'});
1.335 albertel 4495: if (exists($$record{$version.':resource.0.version'})) {
4496: $interaction = $$record{$version.':resource.0.version'};
4497: }
4498:
4499: my $where = ($isTask ? "$version:resource.$interaction"
4500: : "$version:resource");
1.467 albertel 4501: $studentTable.=&Apache::loncommon::start_data_table_row().
4502: '<td>'.$timestamp.'</td>';
1.224 albertel 4503: if ($isCODE) {
4504: $studentTable.='<td>'.$record->{$version.':resource.CODE'}.'</td>';
4505: }
1.119 ng 4506: my @versionKeys = split(/\:/,$$record{$version.':keys'});
4507: my @displaySub = ();
4508: foreach my $partid (@{$parts}) {
1.596 raeburn 4509: my $hidden;
4510: if (($$record{$version.':resource.'.$partid.'.type'} eq 'anonsurvey') ||
4511: ($$record{$version.':resource.'.$partid.'.type'} eq 'anonsurveycred')) {
4512: $hidden = 1;
4513: }
1.335 albertel 4514: my @matchKey = ($isTask ? sort(grep /^resource\.\d+\.\Q$partid\E\.award$/,@versionKeys)
4515: : sort(grep /^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys));
4516:
1.122 ng 4517: # next if ($$record{"$version:resource.$partid.solved"} eq '');
1.324 albertel 4518: my $display_part=&get_display_part($partid,$symb);
1.147 albertel 4519: foreach my $matchKey (@matchKey) {
1.198 albertel 4520: if (exists($$record{$version.':'.$matchKey}) &&
4521: $$record{$version.':'.$matchKey} ne '') {
1.596 raeburn 4522:
1.335 albertel 4523: my ($responseId)= ($isTask ? ($matchKey=~ /^resource\.(.*?)\.\Q$partid\E\.award$/)
4524: : ($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/));
1.577 bisitz 4525: $displaySub[0].='<span class="LC_nobreak"';
4526: $displaySub[0].='<b>'.&mt('Part: [_1]',$display_part).'</b>'
4527: .' <span class="LC_internal_info">'
4528: .'('.&mt('Part ID: [_1]',$responseId).')'
4529: .'</span>'
4530: .' <b>';
1.596 raeburn 4531: if ($hidden) {
4532: $displaySub[0].= &mt('Anonymous Survey').'</b>';
4533: } else {
4534: if ($$record{"$where.$partid.tries"} eq '') {
4535: $displaySub[0].=&mt('Trial not counted');
4536: } else {
4537: $displaySub[0].=&mt('Trial: [_1]',
1.467 albertel 4538: $$record{"$where.$partid.tries"});
1.596 raeburn 4539: }
4540: my $responseType=($isTask ? 'Task'
1.335 albertel 4541: : $responseType->{$partid}->{$responseId});
1.596 raeburn 4542: if (!exists($orders{$partid})) { $orders{$partid}={}; }
4543: if (!exists($orders{$partid}->{$responseId})) {
4544: $orders{$partid}->{$responseId}=
4545: &get_order($partid,$responseId,$symb,$uname,$udom,
4546: $no_increment);
4547: }
4548: $displaySub[0].='</b></span>'; # /nobreak
4549: $displaySub[0].=' '.
4550: &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:",$uname,$udom).'<br />';
4551: }
1.147 albertel 4552: }
4553: }
1.335 albertel 4554: if (exists($$record{"$where.$partid.checkedin"})) {
1.485 albertel 4555: $displaySub[1].=&mt('Checked in by [_1] into slot [_2]',
4556: $$record{"$where.$partid.checkedin"},
4557: $$record{"$where.$partid.checkedin.slot"}).
4558: '<br />';
1.335 albertel 4559: }
4560: if (exists $$record{"$where.$partid.award"}) {
1.485 albertel 4561: $displaySub[1].='<b>'.&mt('Part:').'</b> '.$display_part.' '.
1.335 albertel 4562: lc($$record{"$where.$partid.award"}).' '.
4563: $mark{$$record{"$where.$partid.solved"}}.
1.147 albertel 4564: '<br />';
4565: }
1.335 albertel 4566: if (exists $$record{"$where.$partid.regrader"}) {
4567: $displaySub[2].=$$record{"$where.$partid.regrader"}.
4568: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
4569: } elsif ($$record{"$version:resource.$partid.regrader"} =~ /\S/) {
4570: $displaySub[2].=
4571: $$record{"$version:resource.$partid.regrader"}.
1.207 albertel 4572: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
1.147 albertel 4573: }
4574: }
4575: # needed because old essay regrader has not parts info
4576: if (exists $$record{"$version:resource.regrader"}) {
4577: $displaySub[2].=$$record{"$version:resource.regrader"};
4578: }
4579: $studentTable.='<td>'.$displaySub[0].' </td><td>'.$displaySub[1];
4580: if ($displaySub[2]) {
1.467 albertel 4581: $studentTable.=&mt('Manually graded by [_1]',$displaySub[2]);
1.147 albertel 4582: }
1.467 albertel 4583: $studentTable.=' </td>'.
4584: &Apache::loncommon::end_data_table_row();
1.119 ng 4585: }
1.467 albertel 4586: $studentTable.=&Apache::loncommon::end_data_table();
1.119 ng 4587: return $studentTable;
1.71 ng 4588: }
4589:
4590: sub updateGradeByPage {
1.608 www 4591: my ($request,$symb) = @_;
1.71 ng 4592:
1.257 albertel 4593: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4594: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4595: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
4596: my $pageTitle = $env{'form.page'};
1.103 albertel 4597: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 4598: my ($uname,$udom) = split(/:/,$env{'form.student'});
4599: my $usec=$classlist->{$env{'form.student'}}[5];
1.103 albertel 4600: if (!&canmodify($usec)) {
1.526 raeburn 4601: $request->print('<span class="LC_warning">'.&mt('Unable to modify requested student ([_1])',$env{'form.student'}).'</span>');
1.103 albertel 4602: return;
4603: }
1.398 albertel 4604: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.526 raeburn 4605: $result.='<h3> '.&mt('Student: ').&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
1.129 ng 4606: '</h3>'."\n";
1.70 ng 4607:
1.68 ng 4608: $request->print($result);
4609:
1.582 raeburn 4610:
1.132 bowersj2 4611: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 4612: unless (ref($navmap)) {
4613: $request->print(&navmap_errormsg());
4614: return;
4615: }
1.257 albertel 4616: my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $env{'form.page'});
1.71 ng 4617: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 4618: if (!$map) {
1.527 raeburn 4619: $request->print('<span class="LC_warning">'.&mt('Unable to grade requested sequence ([_1]).',$resUrl).'</span>');
1.288 albertel 4620: return;
4621: }
1.71 ng 4622: my $iterator = $navmap->getIterator($map->map_start(),
4623: $map->map_finish());
1.70 ng 4624:
1.484 albertel 4625: my $studentTable=
4626: &Apache::loncommon::start_data_table().
4627: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 4628: '<th align="center"> '.&mt('Prob.').' </th>'.
4629: '<th> '.&mt('Title').' </th>'.
4630: '<th> '.&mt('Previous Score').' </th>'.
4631: '<th> '.&mt('New Score').' </th>'.
1.484 albertel 4632: &Apache::loncommon::end_data_table_header_row();
1.71 ng 4633:
4634: $iterator->next(); # skip the first BEGIN_MAP
4635: my $curRes = $iterator->next(); # for "current resource"
1.196 albertel 4636: my ($depth,$question,$prob,$changeflag)= (1,1,1,0);
1.101 albertel 4637: while ($depth > 0) {
1.71 ng 4638: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4639: if($curRes == $iterator->END_MAP) { $depth--; }
1.71 ng 4640:
1.385 albertel 4641: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4642: my $parts = $curRes->parts();
1.71 ng 4643: my $title = $curRes->compTitle();
4644: my $symbx = $curRes->symb();
1.484 albertel 4645: $studentTable.=
4646: &Apache::loncommon::start_data_table_row().
4647: '<td align="center" valign="top" >'.$prob.
1.485 albertel 4648: (scalar(@{$parts}) == 1 ? ''
1.526 raeburn 4649: : '<br />('.&mt('[quant,_1, part]',scalar(@{$parts}))
4650: .')').'</td>';
1.71 ng 4651: $studentTable.='<td valign="top"> <b>'.$title.'</b> </td>';
4652:
4653: my %newrecord=();
4654: my @displayPts=();
1.269 raeburn 4655: my %aggregate = ();
4656: my $aggregateflag = 0;
1.71 ng 4657: foreach my $partid (@{$parts}) {
1.257 albertel 4658: my $newpts = $env{'form.GD_BOX'.$question.'_'.$partid};
4659: my $oldpts = $env{'form.oldpts'.$question.'_'.$partid};
1.71 ng 4660:
1.257 albertel 4661: my $wgt = $env{'form.WGT'.$question.'_'.$partid} != 0 ?
4662: $env{'form.WGT'.$question.'_'.$partid} : 1;
1.71 ng 4663: my $partial = $newpts/$wgt;
4664: my $score;
4665: if ($partial > 0) {
4666: $score = 'correct_by_override';
1.125 ng 4667: } elsif ($newpts ne '') { #empty is taken as 0
1.71 ng 4668: $score = 'incorrect_by_override';
4669: }
1.257 albertel 4670: my $dropMenu = $env{'form.GD_SEL'.$question.'_'.$partid};
1.125 ng 4671: if ($dropMenu eq 'excused') {
1.71 ng 4672: $partial = '';
4673: $score = 'excused';
1.125 ng 4674: } elsif ($dropMenu eq 'reset status'
1.257 albertel 4675: && $env{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
1.125 ng 4676: $newrecord{'resource.'.$partid.'.tries'} = 0;
4677: $newrecord{'resource.'.$partid.'.solved'} = '';
4678: $newrecord{'resource.'.$partid.'.award'} = '';
4679: $newrecord{'resource.'.$partid.'.awarded'} = 0;
1.257 albertel 4680: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 4681: $changeflag++;
4682: $newpts = '';
1.269 raeburn 4683:
4684: my $aggtries = $env{'form.aggtries'.$question.'_'.$partid};
4685: my $totaltries = $env{'form.totaltries'.$question.'_'.$partid};
4686: my $solvedstatus = $env{'form.solved'.$question.'_'.$partid};
4687: if ($aggtries > 0) {
4688: &decrement_aggs($symbx,$partid,\%aggregate,$aggtries,$totaltries,$solvedstatus);
4689: $aggregateflag = 1;
4690: }
1.71 ng 4691: }
1.324 albertel 4692: my $display_part=&get_display_part($partid,$curRes->symb());
1.257 albertel 4693: my $oldstatus = $env{'form.solved'.$question.'_'.$partid};
1.526 raeburn 4694: $displayPts[0].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.71 ng 4695: (($oldstatus eq 'excused') ? 'excused' : $oldpts).
1.326 albertel 4696: ' <br />';
1.526 raeburn 4697: $displayPts[1].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.125 ng 4698: (($score eq 'excused') ? 'excused' : $newpts).
1.326 albertel 4699: ' <br />';
1.71 ng 4700: $question++;
1.380 albertel 4701: next if ($dropMenu eq 'reset status' || ($newpts eq $oldpts && $score ne 'excused'));
1.125 ng 4702:
1.71 ng 4703: $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
1.125 ng 4704: $newrecord{'resource.'.$partid.'.solved'} = $score if $score ne '';
1.257 albertel 4705: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}"
1.125 ng 4706: if (scalar(keys(%newrecord)) > 0);
1.71 ng 4707:
4708: $changeflag++;
4709: }
4710: if (scalar(keys(%newrecord)) > 0) {
1.382 albertel 4711: my %record =
4712: &Apache::lonnet::restore($symbx,$env{'request.course.id'},
4713: $udom,$uname);
4714:
4715: if (&Apache::lonnet::validCODE($env{'form.CODE'})) {
4716: $newrecord{'resource.CODE'} = $env{'form.CODE'};
4717: } elsif (&Apache::lonnet::validCODE($record{'resource.CODE'})) {
4718: $newrecord{'resource.CODE'} = '';
4719: }
1.257 albertel 4720: &Apache::lonnet::cstore(\%newrecord,$symbx,$env{'request.course.id'},
1.71 ng 4721: $udom,$uname);
1.382 albertel 4722: %record = &Apache::lonnet::restore($symbx,
4723: $env{'request.course.id'},
4724: $udom,$uname);
1.380 albertel 4725: &check_and_remove_from_queue($parts,\%record,undef,$symbx,
4726: $cdom,$cnum,$udom,$uname);
1.71 ng 4727: }
1.380 albertel 4728:
1.269 raeburn 4729: if ($aggregateflag) {
4730: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
4731: $env{'course.'.$env{'request.course.id'}.'.domain'},
4732: $env{'course.'.$env{'request.course.id'}.'.num'});
4733: }
1.125 ng 4734:
1.71 ng 4735: $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
4736: '<td valign="top">'.$displayPts[1].'</td>'.
1.484 albertel 4737: &Apache::loncommon::end_data_table_row();
1.68 ng 4738:
1.196 albertel 4739: $prob++;
1.68 ng 4740: }
1.71 ng 4741: $curRes = $iterator->next();
1.68 ng 4742: }
1.98 albertel 4743:
1.484 albertel 4744: $studentTable.=&Apache::loncommon::end_data_table();
1.526 raeburn 4745: my $grademsg=($changeflag == 0 ? &mt('No score was changed or updated.') :
4746: &mt('The scores were changed for [quant,_1,problem].',
4747: $changeflag));
1.76 ng 4748: $request->print($grademsg.$studentTable);
1.68 ng 4749:
1.70 ng 4750: return '';
4751: }
4752:
1.72 ng 4753: #-------- end of section for handling grading by page/sequence ---------
4754: #
4755: #-------------------------------------------------------------------
4756:
1.581 www 4757: #-------------------- Bubblesheet (Scantron) Grading -------------------
1.75 albertel 4758: #
4759: #------ start of section for handling grading by page/sequence ---------
4760:
1.423 albertel 4761: =pod
4762:
4763: =head1 Bubble sheet grading routines
4764:
1.424 albertel 4765: For this documentation:
4766:
4767: 'scanline' refers to the full line of characters
4768: from the file that we are parsing that represents one entire sheet
4769:
4770: 'bubble line' refers to the data
4771: representing the line of bubbles that are on the physical bubble sheet
4772:
4773:
4774: The overall process is that a scanned in bubble sheet data is uploaded
4775: into a course. When a user wants to grade, they select a
4776: sequence/folder of resources, a file of bubble sheet info, and pick
4777: one of the predefined configurations for what each scanline looks
4778: like.
4779:
4780: Next each scanline is checked for any errors of either 'missing
1.435 foxr 4781: bubbles' (it's an error because it may have been mis-scanned
1.424 albertel 4782: because too light bubbling), 'double bubble' (each bubble line should
4783: have no more that one letter picked), invalid or duplicated CODE,
1.556 weissno 4784: invalid student/employee ID
1.424 albertel 4785:
4786: If the CODE option is used that determines the randomization of the
1.556 weissno 4787: homework problems, either way the student/employee ID is looked up into a
1.424 albertel 4788: username:domain.
4789:
4790: During the validation phase the instructor can choose to skip scanlines.
4791:
1.435 foxr 4792: After the validation phase, there are now 3 bubble sheet files
1.424 albertel 4793:
4794: scantron_original_filename (unmodified original file)
4795: scantron_corrected_filename (file where the corrected information has replaced the original information)
4796: scantron_skipped_filename (contains the exact text of scanlines that where skipped)
4797:
4798: Also there is a separate hash nohist_scantrondata that contains extra
4799: correction information that isn't representable in the bubble sheet
4800: file (see &scantron_getfile() for more information)
4801:
4802: After all scanlines are either valid, marked as valid or skipped, then
4803: foreach line foreach problem in the picked sequence, an ssi request is
4804: made that simulates a user submitting their selected letter(s) against
4805: the homework problem.
1.423 albertel 4806:
4807: =over 4
4808:
4809:
4810:
4811: =item defaultFormData
4812:
4813: Returns html hidden inputs used to hold context/default values.
4814:
4815: Arguments:
4816: $symb - $symb of the current resource
4817:
4818: =cut
1.422 foxr 4819:
1.81 albertel 4820: sub defaultFormData {
1.324 albertel 4821: my ($symb)=@_;
1.613 www 4822: return '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />';
1.81 albertel 4823: }
4824:
1.447 foxr 4825:
1.423 albertel 4826: =pod
4827:
4828: =item getSequenceDropDown
4829:
4830: Return html dropdown of possible sequences to grade
4831:
4832: Arguments:
1.582 raeburn 4833: $symb - $symb of the current resource
4834: $map_error - ref to scalar which will container error if
4835: $navmap object is unavailable in &getSymbMap().
1.423 albertel 4836:
4837: =cut
1.422 foxr 4838:
1.75 albertel 4839: sub getSequenceDropDown {
1.582 raeburn 4840: my ($symb,$map_error)=@_;
1.75 albertel 4841: my $result='<select name="selectpage">'."\n";
1.582 raeburn 4842: my ($titles,$symbx) = &getSymbMap($map_error);
4843: if (ref($map_error)) {
4844: return if ($$map_error);
4845: }
1.137 albertel 4846: my ($curpage)=&Apache::lonnet::decode_symb($symb);
1.75 albertel 4847: my $ctr=0;
4848: foreach (@$titles) {
4849: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
4850: $result.='<option value="'.$$symbx{$_}.'" '.
1.401 albertel 4851: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.75 albertel 4852: '>'.$showtitle.'</option>'."\n";
4853: $ctr++;
4854: }
4855: $result.= '</select>';
4856: return $result;
4857: }
4858:
1.495 albertel 4859: my %bubble_lines_per_response; # no. bubble lines for each response.
1.554 raeburn 4860: # key is zero-based index - 0, 1, 2 ...
1.495 albertel 4861:
4862: my %first_bubble_line; # First bubble line no. for each bubble.
4863:
1.509 raeburn 4864: my %subdivided_bubble_lines; # no. bubble lines for optionresponse,
4865: # matchresponse or rankresponse, where
4866: # an individual response can have multiple
4867: # lines
1.503 raeburn 4868:
4869: my %responsetype_per_response; # responsetype for each response
4870:
1.495 albertel 4871: # Save and restore the bubble lines array to the form env.
4872:
4873:
4874: sub save_bubble_lines {
4875: foreach my $line (keys(%bubble_lines_per_response)) {
4876: $env{"form.scantron.bubblelines.$line"} = $bubble_lines_per_response{$line};
4877: $env{"form.scantron.first_bubble_line.$line"} =
4878: $first_bubble_line{$line};
1.503 raeburn 4879: $env{"form.scantron.sub_bubblelines.$line"} =
4880: $subdivided_bubble_lines{$line};
4881: $env{"form.scantron.responsetype.$line"} =
4882: $responsetype_per_response{$line};
1.495 albertel 4883: }
4884: }
4885:
4886:
4887: sub restore_bubble_lines {
4888: my $line = 0;
4889: %bubble_lines_per_response = ();
4890: while ($env{"form.scantron.bubblelines.$line"}) {
4891: my $value = $env{"form.scantron.bubblelines.$line"};
4892: $bubble_lines_per_response{$line} = $value;
4893: $first_bubble_line{$line} =
4894: $env{"form.scantron.first_bubble_line.$line"};
1.503 raeburn 4895: $subdivided_bubble_lines{$line} =
4896: $env{"form.scantron.sub_bubblelines.$line"};
4897: $responsetype_per_response{$line} =
4898: $env{"form.scantron.responsetype.$line"};
1.495 albertel 4899: $line++;
4900: }
4901: }
4902:
4903: # Given the parsed scanline, get the response for
4904: # 'answer' number n:
4905:
4906: sub get_response_bubbles {
4907: my ($parsed_line, $response) = @_;
4908:
4909: my $bubble_line = $first_bubble_line{$response-1} +1;
4910: my $bubble_lines= $bubble_lines_per_response{$response-1};
4911:
4912: my $selected = "";
4913:
4914: for (my $bline = 0; $bline < $bubble_lines; $bline++) {
4915: $selected .= $$parsed_line{"scantron.$bubble_line.answer"}.":";
4916: $bubble_line++;
4917: }
4918: return $selected;
4919: }
1.423 albertel 4920:
4921: =pod
4922:
4923: =item scantron_filenames
4924:
4925: Returns a list of the scantron files in the current course
4926:
4927: =cut
1.422 foxr 4928:
1.202 albertel 4929: sub scantron_filenames {
1.257 albertel 4930: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4931: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
1.517 raeburn 4932: my $getpropath = 1;
1.157 albertel 4933: my @files=&Apache::lonnet::dirlist('userfiles',$cdom,$cname,
1.517 raeburn 4934: $getpropath);
1.202 albertel 4935: my @possiblenames;
1.201 albertel 4936: foreach my $filename (sort(@files)) {
1.157 albertel 4937: ($filename)=split(/&/,$filename);
4938: if ($filename!~/^scantron_orig_/) { next ; }
4939: $filename=~s/^scantron_orig_//;
1.202 albertel 4940: push(@possiblenames,$filename);
4941: }
4942: return @possiblenames;
4943: }
4944:
1.423 albertel 4945: =pod
4946:
4947: =item scantron_uploads
4948:
4949: Returns html drop-down list of scantron files in current course.
4950:
4951: Arguments:
4952: $file2grade - filename to set as selected in the dropdown
4953:
4954: =cut
1.422 foxr 4955:
1.202 albertel 4956: sub scantron_uploads {
1.209 ng 4957: my ($file2grade) = @_;
1.202 albertel 4958: my $result= '<select name="scantron_selectfile">';
4959: $result.="<option></option>";
4960: foreach my $filename (sort(&scantron_filenames())) {
1.401 albertel 4961: $result.="<option".($filename eq $file2grade ? ' selected="selected"':'').">$filename</option>\n";
1.81 albertel 4962: }
4963: $result.="</select>";
4964: return $result;
4965: }
4966:
1.423 albertel 4967: =pod
4968:
4969: =item scantron_scantab
4970:
4971: Returns html drop down of the scantron formats in the scantronformat.tab
4972: file.
4973:
4974: =cut
1.422 foxr 4975:
1.82 albertel 4976: sub scantron_scantab {
4977: my $result='<select name="scantron_format">'."\n";
1.191 albertel 4978: $result.='<option></option>'."\n";
1.518 raeburn 4979: my @lines = &get_scantronformat_file();
4980: if (@lines > 0) {
4981: foreach my $line (@lines) {
4982: next if (($line =~ /^\#/) || ($line eq ''));
4983: my ($name,$descrip)=split(/:/,$line);
4984: $result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
4985: }
1.82 albertel 4986: }
4987: $result.='</select>'."\n";
1.518 raeburn 4988: return $result;
4989: }
4990:
4991: =pod
4992:
4993: =item get_scantronformat_file
4994:
4995: Returns an array containing lines from the scantron format file for
4996: the domain of the course.
4997:
4998: If a url for a custom.tab file is listed in domain's configuration.db,
4999: lines are from this file.
5000:
5001: Otherwise, if a default.tab has been published in RES space by the
5002: domainconfig user, lines are from this file.
5003:
5004: Otherwise, fall back to getting lines from the legacy file on the
1.519 raeburn 5005: local server: /home/httpd/lonTabs/default_scantronformat.tab
1.82 albertel 5006:
1.518 raeburn 5007: =cut
5008:
5009: sub get_scantronformat_file {
5010: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
5011: my %domconfig = &Apache::lonnet::get_dom('configuration',['scantron'],$cdom);
5012: my $gottab = 0;
5013: my @lines;
5014: if (ref($domconfig{'scantron'}) eq 'HASH') {
5015: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
5016: my $formatfile = &Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.$domconfig{'scantron'}{'scantronformat'});
5017: if ($formatfile ne '-1') {
5018: @lines = split("\n",$formatfile,-1);
5019: $gottab = 1;
5020: }
5021: }
5022: }
5023: if (!$gottab) {
5024: my $confname = $cdom.'-domainconfig';
5025: my $default = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res/'.$cdom.'/'.$confname.'/default.tab';
5026: my $formatfile = &Apache::lonnet::getfile($default);
5027: if ($formatfile ne '-1') {
5028: @lines = split("\n",$formatfile,-1);
5029: $gottab = 1;
5030: }
5031: }
5032: if (!$gottab) {
1.519 raeburn 5033: my @domains = &Apache::lonnet::current_machine_domains();
5034: if (grep(/^\Q$cdom\E$/,@domains)) {
5035: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
5036: @lines = <$fh>;
5037: close($fh);
5038: } else {
5039: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab');
5040: @lines = <$fh>;
5041: close($fh);
5042: }
1.518 raeburn 5043: }
5044: return @lines;
1.82 albertel 5045: }
5046:
1.423 albertel 5047: =pod
5048:
5049: =item scantron_CODElist
5050:
5051: Returns html drop down of the saved CODE lists from current course,
5052: generated from earlier printings.
5053:
5054: =cut
1.422 foxr 5055:
1.186 albertel 5056: sub scantron_CODElist {
1.257 albertel 5057: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5058: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.186 albertel 5059: my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
5060: my $namechoice='<option></option>';
1.225 albertel 5061: foreach my $name (sort {uc($a) cmp uc($b)} @names) {
1.191 albertel 5062: if ($name =~ /^error: 2 /) { next; }
1.278 albertel 5063: if ($name =~ /^type\0/) { next; }
1.186 albertel 5064: $namechoice.='<option value="'.$name.'">'.$name.'</option>';
5065: }
5066: $namechoice='<select name="scantron_CODElist">'.$namechoice.'</select>';
5067: return $namechoice;
5068: }
5069:
1.423 albertel 5070: =pod
5071:
5072: =item scantron_CODEunique
5073:
5074: Returns the html for "Each CODE to be used once" radio.
5075:
5076: =cut
1.422 foxr 5077:
1.186 albertel 5078: sub scantron_CODEunique {
1.532 bisitz 5079: my $result='<span class="LC_nobreak">
1.272 albertel 5080: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 5081: value="yes" checked="checked" />'.&mt('Yes').' </label>
1.381 albertel 5082: </span>
1.532 bisitz 5083: <span class="LC_nobreak">
1.272 albertel 5084: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 5085: value="no" />'.&mt('No').' </label>
1.381 albertel 5086: </span>';
1.186 albertel 5087: return $result;
5088: }
1.423 albertel 5089:
5090: =pod
5091:
5092: =item scantron_selectphase
5093:
5094: Generates the initial screen to start the bubble sheet process.
5095: Allows for - starting a grading run.
1.424 albertel 5096: - downloading existing scan data (original, corrected
1.423 albertel 5097: or skipped info)
5098:
5099: - uploading new scan data
5100:
5101: Arguments:
5102: $r - The Apache request object
5103: $file2grade - name of the file that contain the scanned data to score
5104:
5105: =cut
1.186 albertel 5106:
1.75 albertel 5107: sub scantron_selectphase {
1.608 www 5108: my ($r,$file2grade,$symb) = @_;
1.75 albertel 5109: if (!$symb) {return '';}
1.582 raeburn 5110: my $map_error;
5111: my $sequence_selector=&getSequenceDropDown($symb,\$map_error);
5112: if ($map_error) {
5113: $r->print('<br />'.&navmap_errormsg().'<br />');
5114: return;
5115: }
1.324 albertel 5116: my $default_form_data=&defaultFormData($symb);
1.209 ng 5117: my $file_selector=&scantron_uploads($file2grade);
1.82 albertel 5118: my $format_selector=&scantron_scantab();
1.186 albertel 5119: my $CODE_selector=&scantron_CODElist();
5120: my $CODE_unique=&scantron_CODEunique();
1.75 albertel 5121: my $result;
1.422 foxr 5122:
1.513 foxr 5123: $ssi_error = 0;
5124:
1.606 wenzelju 5125: if (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) ||
5126: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
5127:
5128: # Chunk of form to prompt for a scantron file upload.
5129:
5130: $r->print('
5131: <br />
5132: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5133: '.&Apache::loncommon::start_data_table_header_row().'
5134: <th>
5135: '.&mt('Specify a bubblesheet data file to upload.').'
5136: </th>
5137: '.&Apache::loncommon::end_data_table_header_row().'
5138: '.&Apache::loncommon::start_data_table_row().'
5139: <td>
5140: ');
1.608 www 5141: my $default_form_data=&defaultFormData($symb);
1.606 wenzelju 5142: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
5143: my $cnum= $env{'course.'.$env{'request.course.id'}.'.num'};
5144: $r->print(&Apache::lonhtmlcommon::scripttag('
5145: function checkUpload(formname) {
5146: if (formname.upfile.value == "") {
5147: alert("'.&mt('Please use the browse button to select a file from your local directory.').'");
5148: return false;
5149: }
5150: formname.submit();
5151: }'));
5152: $r->print('
5153: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
5154: '.$default_form_data.'
5155: <input name="courseid" type="hidden" value="'.$cnum.'" />
5156: <input name="domainid" type="hidden" value="'.$cdom.'" />
5157: <input name="command" value="scantronupload_save" type="hidden" />
5158: '.&mt('File to upload: [_1]','<input type="file" name="upfile" size="50" />').'
5159: <br />
5160: <input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
5161: </form>
5162: ');
5163:
5164: $r->print('
5165: </td>
5166: '.&Apache::loncommon::end_data_table_row().'
5167: '.&Apache::loncommon::end_data_table().'
5168: ');
5169: }
5170:
1.422 foxr 5171: # Chunk of form to prompt for a file to grade and how:
5172:
1.489 albertel 5173: $result.= '
5174: <br />
5175: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantron_process">
5176: <input type="hidden" name="command" value="scantron_warning" />
5177: '.$default_form_data.'
5178: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5179: '.&Apache::loncommon::start_data_table_header_row().'
5180: <th colspan="2">
1.492 albertel 5181: '.&mt('Specify file and which Folder/Sequence to grade').'
1.489 albertel 5182: </th>
5183: '.&Apache::loncommon::end_data_table_header_row().'
5184: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5185: <td> '.&mt('Sequence to grade:').' </td><td> '.$sequence_selector.' </td>
1.489 albertel 5186: '.&Apache::loncommon::end_data_table_row().'
5187: '.&Apache::loncommon::start_data_table_row().'
1.572 www 5188: <td> '.&mt('Filename of bubblesheet data file:').' </td><td> '.$file_selector.' </td>
1.489 albertel 5189: '.&Apache::loncommon::end_data_table_row().'
5190: '.&Apache::loncommon::start_data_table_row().'
1.572 www 5191: <td> '.&mt('Format of bubblesheet data file:').' </td><td> '.$format_selector.' </td>
1.489 albertel 5192: '.&Apache::loncommon::end_data_table_row().'
5193: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5194: <td> '.&mt('Saved CODEs to validate against:').' </td><td> '.$CODE_selector.' </td>
1.489 albertel 5195: '.&Apache::loncommon::end_data_table_row().'
5196: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5197: <td> '.&mt('Each CODE is only to be used once:').'</td><td> '.$CODE_unique.' </td>
1.489 albertel 5198: '.&Apache::loncommon::end_data_table_row().'
5199: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5200: <td> '.&mt('Options:').' </td>
1.187 albertel 5201: <td>
1.492 albertel 5202: <label><input type="checkbox" name="scantron_options_redo" value="redo_skipped"/> '.&mt('Do only previously skipped records').'</label> <br />
5203: <label><input type="checkbox" name="scantron_options_ignore" value="ignore_corrections"/> '.&mt('Remove all existing corrections').'</label> <br />
5204: <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources when grading').'</label>
1.187 albertel 5205: </td>
1.489 albertel 5206: '.&Apache::loncommon::end_data_table_row().'
5207: '.&Apache::loncommon::start_data_table_row().'
1.174 albertel 5208: <td colspan="2">
1.572 www 5209: <input type="submit" value="'.&mt('Grading: Validate Bubblesheet Records').'" />
1.162 albertel 5210: </td>
1.489 albertel 5211: '.&Apache::loncommon::end_data_table_row().'
5212: '.&Apache::loncommon::end_data_table().'
5213: </form>
5214: ';
1.162 albertel 5215:
5216: $r->print($result);
5217:
1.422 foxr 5218:
5219:
5220: # Chunk of the form that prompts to view a scoring office file,
5221: # corrected file, skipped records in a file.
5222:
1.489 albertel 5223: $r->print('
5224: <br />
5225: <form action="/adm/grades" name="scantron_download">
5226: '.$default_form_data.'
5227: <input type="hidden" name="command" value="scantron_download" />
5228: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5229: '.&Apache::loncommon::start_data_table_header_row().'
5230: <th>
1.492 albertel 5231: '.&mt('Download a scoring office file').'
1.489 albertel 5232: </th>
5233: '.&Apache::loncommon::end_data_table_header_row().'
5234: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5235: <td> '.&mt('Filename of scoring office file: [_1]',$file_selector).'
1.489 albertel 5236: <br />
1.492 albertel 5237: <input type="submit" value="'.&mt('Download: Show List of Associated Files').'" />
1.489 albertel 5238: '.&Apache::loncommon::end_data_table_row().'
5239: '.&Apache::loncommon::end_data_table().'
5240: </form>
5241: <br />
5242: ');
1.162 albertel 5243:
1.457 banghart 5244: &Apache::lonpickcode::code_list($r,2);
1.523 raeburn 5245:
1.528 raeburn 5246: $r->print('<br /><form method="post" name="checkscantron">'.
1.523 raeburn 5247: $default_form_data."\n".
5248: &Apache::loncommon::start_data_table('LC_scantron_action')."\n".
5249: &Apache::loncommon::start_data_table_header_row()."\n".
5250: '<th colspan="2">
1.572 www 5251: '.&mt('Review bubblesheet data and submissions for a previously graded folder/sequence')."\n".
1.523 raeburn 5252: '</th>'."\n".
5253: &Apache::loncommon::end_data_table_header_row()."\n".
5254: &Apache::loncommon::start_data_table_row()."\n".
5255: '<td> '.&mt('Graded folder/sequence:').' </td>'."\n".
5256: '<td> '.$sequence_selector.' </td>'.
5257: &Apache::loncommon::end_data_table_row()."\n".
5258: &Apache::loncommon::start_data_table_row()."\n".
5259: '<td> '.&mt('Filename of scoring office file:').' </td>'."\n".
5260: '<td> '.$file_selector.' </td>'."\n".
5261: &Apache::loncommon::end_data_table_row()."\n".
5262: &Apache::loncommon::start_data_table_row()."\n".
5263: '<td> '.&mt('Format of data file:').' </td>'."\n".
5264: '<td> '.$format_selector.' </td>'."\n".
5265: &Apache::loncommon::end_data_table_row()."\n".
5266: &Apache::loncommon::start_data_table_row()."\n".
1.557 raeburn 5267: '<td> '.&mt('Options').' </td>'."\n".
5268: '<td> <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources').'</label></td>'.
5269: &Apache::loncommon::end_data_table_row()."\n".
5270: &Apache::loncommon::start_data_table_row()."\n".
1.523 raeburn 5271: '<td colspan="2">'."\n".
5272: '<input type="hidden" name="command" value="checksubmissions" />'."\n".
1.575 www 5273: '<input type="submit" value="'.&mt('Review Bubblesheet Data and Submission Records').'" />'."\n".
1.523 raeburn 5274: '</td>'."\n".
5275: &Apache::loncommon::end_data_table_row()."\n".
5276: &Apache::loncommon::end_data_table()."\n".
5277: '</form><br />');
5278: return;
1.75 albertel 5279: }
5280:
1.423 albertel 5281: =pod
5282:
5283: =item get_scantron_config
5284:
5285: Parse and return the scantron configuration line selected as a
5286: hash of configuration file fields.
5287:
5288: Arguments:
5289: which - the name of the configuration to parse from the file.
5290:
5291:
5292: Returns:
5293: If the named configuration is not in the file, an empty
5294: hash is returned.
5295: a hash with the fields
5296: name - internal name for the this configuration setup
5297: description - text to display to operator that describes this config
5298: CODElocation - if 0 or the string 'none'
5299: - no CODE exists for this config
5300: if -1 || the string 'letter'
5301: - a CODE exists for this config and is
5302: a string of letters
5303: Unsupported value (but planned for future support)
5304: if a positive integer
5305: - The CODE exists as the first n items from
5306: the question section of the form
5307: if the string 'number'
5308: - The CODE exists for this config and is
5309: a string of numbers
5310: CODEstart - (only matter if a CODE exists) column in the line where
5311: the CODE starts
5312: CODElength - length of the CODE
1.573 bisitz 5313: IDstart - column where the student/employee ID starts
1.556 weissno 5314: IDlength - length of the student/employee ID info
1.423 albertel 5315: Qstart - column where the information from the bubbled
5316: 'questions' start
5317: Qlength - number of columns comprising a single bubble line from
5318: the sheet. (usually either 1 or 10)
1.424 albertel 5319: Qon - either a single character representing the character used
1.423 albertel 5320: to signal a bubble was chosen in the positional setup, or
5321: the string 'letter' if the letter of the chosen bubble is
5322: in the final, or 'number' if a number representing the
5323: chosen bubble is in the file (1->A 0->J)
1.424 albertel 5324: Qoff - the character used to represent that a bubble was
5325: left blank
1.423 albertel 5326: PaperID - if the scanning process generates a unique number for each
5327: sheet scanned the column that this ID number starts in
5328: PaperIDlength - number of columns that comprise the unique ID number
5329: for the sheet of paper
1.424 albertel 5330: FirstName - column that the first name starts in
1.423 albertel 5331: FirstNameLength - number of columns that the first name spans
5332:
5333: LastName - column that the last name starts in
5334: LastNameLength - number of columns that the last name spans
5335:
5336: =cut
1.422 foxr 5337:
1.82 albertel 5338: sub get_scantron_config {
5339: my ($which) = @_;
1.518 raeburn 5340: my @lines = &get_scantronformat_file();
1.82 albertel 5341: my %config;
1.157 albertel 5342: #FIXME probably should move to XML it has already gotten a bit much now
1.518 raeburn 5343: foreach my $line (@lines) {
1.82 albertel 5344: my ($name,$descrip)=split(/:/,$line);
5345: if ($name ne $which ) { next; }
5346: chomp($line);
5347: my @config=split(/:/,$line);
5348: $config{'name'}=$config[0];
5349: $config{'description'}=$config[1];
5350: $config{'CODElocation'}=$config[2];
5351: $config{'CODEstart'}=$config[3];
5352: $config{'CODElength'}=$config[4];
5353: $config{'IDstart'}=$config[5];
5354: $config{'IDlength'}=$config[6];
5355: $config{'Qstart'}=$config[7];
1.497 foxr 5356: $config{'Qlength'}=$config[8];
1.82 albertel 5357: $config{'Qoff'}=$config[9];
5358: $config{'Qon'}=$config[10];
1.157 albertel 5359: $config{'PaperID'}=$config[11];
5360: $config{'PaperIDlength'}=$config[12];
5361: $config{'FirstName'}=$config[13];
5362: $config{'FirstNamelength'}=$config[14];
5363: $config{'LastName'}=$config[15];
5364: $config{'LastNamelength'}=$config[16];
1.82 albertel 5365: last;
5366: }
5367: return %config;
5368: }
5369:
1.423 albertel 5370: =pod
5371:
5372: =item username_to_idmap
5373:
1.556 weissno 5374: creates a hash keyed by student/employee ID with values of the corresponding
1.423 albertel 5375: student username:domain.
5376:
5377: Arguments:
5378:
5379: $classlist - reference to the class list hash. This is a hash
5380: keyed by student name:domain whose elements are references
1.424 albertel 5381: to arrays containing various chunks of information
1.423 albertel 5382: about the student. (See loncoursedata for more info).
5383:
5384: Returns
5385: %idmap - the constructed hash
5386:
5387: =cut
5388:
1.82 albertel 5389: sub username_to_idmap {
5390: my ($classlist)= @_;
5391: my %idmap;
5392: foreach my $student (keys(%$classlist)) {
5393: $idmap{$classlist->{$student}->[&Apache::loncoursedata::CL_ID]}=
5394: $student;
5395: }
5396: return %idmap;
5397: }
1.423 albertel 5398:
5399: =pod
5400:
1.424 albertel 5401: =item scantron_fixup_scanline
1.423 albertel 5402:
5403: Process a requested correction to a scanline.
5404:
5405: Arguments:
5406: $scantron_config - hash from &get_scantron_config()
5407: $scan_data - hash of correction information
5408: (see &scantron_getfile())
5409: $line - existing scanline
5410: $whichline - line number of the passed in scanline
5411: $field - type of change to process
5412: (either
1.573 bisitz 5413: 'ID' -> correct the student/employee ID
1.423 albertel 5414: 'CODE' -> correct the CODE
5415: 'answer' -> fixup the submitted answers)
5416:
5417: $args - hash of additional info,
5418: - 'ID'
5419: 'newid' -> studentID to use in replacement
1.424 albertel 5420: of existing one
1.423 albertel 5421: - 'CODE'
5422: 'CODE_ignore_dup' - set to true if duplicates
5423: should be ignored.
5424: 'CODE' - is new code or 'use_unfound'
1.424 albertel 5425: if the existing unfound code should
1.423 albertel 5426: be used as is
5427: - 'answer'
5428: 'response' - new answer or 'none' if blank
5429: 'question' - the bubble line to change
1.503 raeburn 5430: 'questionnum' - the question identifier,
5431: may include subquestion.
1.423 albertel 5432:
5433: Returns:
5434: $line - the modified scanline
5435:
5436: Side effects:
5437: $scan_data - may be updated
5438:
5439: =cut
5440:
1.82 albertel 5441:
1.157 albertel 5442: sub scantron_fixup_scanline {
5443: my ($scantron_config,$scan_data,$line,$whichline,$field,$args)=@_;
5444: if ($field eq 'ID') {
5445: if (length($args->{'newid'}) > $$scantron_config{'IDlength'}) {
1.186 albertel 5446: return ($line,1,'New value too large');
1.157 albertel 5447: }
5448: if (length($args->{'newid'}) < $$scantron_config{'IDlength'}) {
5449: $args->{'newid'}=sprintf('%-'.$$scantron_config{'IDlength'}.'s',
5450: $args->{'newid'});
5451: }
5452: substr($line,$$scantron_config{'IDstart'}-1,
5453: $$scantron_config{'IDlength'})=$args->{'newid'};
5454: if ($args->{'newid'}=~/^\s*$/) {
5455: &scan_data($scan_data,"$whichline.user",
5456: $args->{'username'}.':'.$args->{'domain'});
5457: }
1.186 albertel 5458: } elsif ($field eq 'CODE') {
1.192 albertel 5459: if ($args->{'CODE_ignore_dup'}) {
5460: &scan_data($scan_data,"$whichline.CODE_ignore_dup",'1');
5461: }
5462: &scan_data($scan_data,"$whichline.useCODE",'1');
5463: if ($args->{'CODE'} ne 'use_unfound') {
1.191 albertel 5464: if (length($args->{'CODE'}) > $$scantron_config{'CODElength'}) {
5465: return ($line,1,'New CODE value too large');
5466: }
5467: if (length($args->{'CODE'}) < $$scantron_config{'CODElength'}) {
5468: $args->{'CODE'}=sprintf('%-'.$$scantron_config{'CODElength'}.'s',$args->{'CODE'});
5469: }
5470: substr($line,$$scantron_config{'CODEstart'}-1,
5471: $$scantron_config{'CODElength'})=$args->{'CODE'};
1.186 albertel 5472: }
1.157 albertel 5473: } elsif ($field eq 'answer') {
1.497 foxr 5474: my $length=$scantron_config->{'Qlength'};
1.157 albertel 5475: my $off=$scantron_config->{'Qoff'};
5476: my $on=$scantron_config->{'Qon'};
1.497 foxr 5477: my $answer=${off}x$length;
5478: if ($args->{'response'} eq 'none') {
5479: &scan_data($scan_data,
1.503 raeburn 5480: "$whichline.no_bubble.".$args->{'questionnum'},'1');
1.497 foxr 5481: } else {
5482: if ($on eq 'letter') {
5483: my @alphabet=('A'..'Z');
5484: $answer=$alphabet[$args->{'response'}];
5485: } elsif ($on eq 'number') {
5486: $answer=$args->{'response'}+1;
5487: if ($answer == 10) { $answer = '0'; }
1.274 albertel 5488: } else {
1.497 foxr 5489: substr($answer,$args->{'response'},1)=$on;
1.274 albertel 5490: }
1.497 foxr 5491: &scan_data($scan_data,
1.503 raeburn 5492: "$whichline.no_bubble.".$args->{'questionnum'},undef,'1');
1.157 albertel 5493: }
1.497 foxr 5494: my $where=$length*($args->{'question'}-1)+$scantron_config->{'Qstart'};
5495: substr($line,$where-1,$length)=$answer;
1.157 albertel 5496: }
5497: return $line;
5498: }
1.423 albertel 5499:
5500: =pod
5501:
5502: =item scan_data
5503:
5504: Edit or look up an item in the scan_data hash.
5505:
5506: Arguments:
5507: $scan_data - The hash (see scantron_getfile)
5508: $key - shorthand of the key to edit (actual key is
1.424 albertel 5509: scantronfilename_key).
1.423 albertel 5510: $data - New value of the hash entry.
5511: $delete - If true, the entry is removed from the hash.
5512:
5513: Returns:
5514: The new value of the hash table field (undefined if deleted).
5515:
5516: =cut
5517:
5518:
1.157 albertel 5519: sub scan_data {
5520: my ($scan_data,$key,$value,$delete)=@_;
1.257 albertel 5521: my $filename=$env{'form.scantron_selectfile'};
1.157 albertel 5522: if (defined($value)) {
5523: $scan_data->{$filename.'_'.$key} = $value;
5524: }
5525: if ($delete) { delete($scan_data->{$filename.'_'.$key}); }
5526: return $scan_data->{$filename.'_'.$key};
5527: }
1.423 albertel 5528:
1.495 albertel 5529: # ----- These first few routines are general use routines.----
5530:
5531: # Return the number of occurences of a pattern in a string.
5532:
5533: sub occurence_count {
5534: my ($string, $pattern) = @_;
5535:
5536: my @matches = ($string =~ /$pattern/g);
5537:
5538: return scalar(@matches);
5539: }
5540:
5541:
5542: # Take a string known to have digits and convert all the
5543: # digits into letters in the range J,A..I.
5544:
5545: sub digits_to_letters {
5546: my ($input) = @_;
5547:
5548: my @alphabet = ('J', 'A'..'I');
5549:
5550: my @input = split(//, $input);
5551: my $output ='';
5552: for (my $i = 0; $i < scalar(@input); $i++) {
5553: if ($input[$i] =~ /\d/) {
5554: $output .= $alphabet[$input[$i]];
5555: } else {
5556: $output .= $input[$i];
5557: }
5558: }
5559: return $output;
5560: }
5561:
1.423 albertel 5562: =pod
5563:
5564: =item scantron_parse_scanline
5565:
5566: Decodes a scanline from the selected scantron file
5567:
5568: Arguments:
5569: line - The text of the scantron file line to process
5570: whichline - Line number
5571: scantron_config - Hash describing the format of the scantron lines.
5572: scan_data - Hash of extra information about the scanline
5573: (see scantron_getfile for more information)
5574: just_header - True if should not process question answers but only
5575: the stuff to the left of the answers.
5576: Returns:
5577: Hash containing the result of parsing the scanline
5578:
5579: Keys are all proceeded by the string 'scantron.'
5580:
5581: CODE - the CODE in use for this scanline
5582: useCODE - 1 if the CODE is invalid but it usage has been forced
5583: by the operator
5584: CODE_ignore_dup - 1 if the CODE is a duplicated use when unique
5585: CODEs were selected, but the usage has been
5586: forced by the operator
1.556 weissno 5587: ID - student/employee ID
1.423 albertel 5588: PaperID - if used, the ID number printed on the sheet when the
5589: paper was scanned
5590: FirstName - first name from the sheet
5591: LastName - last name from the sheet
5592:
5593: if just_header was not true these key may also exist
5594:
1.447 foxr 5595: missingerror - a list of bubble ranges that are considered to be answers
5596: to a single question that don't have any bubbles filled in.
5597: Of the form questionnumber:firstbubblenumber:count.
5598: doubleerror - a list of bubble ranges that are considered to be answers
5599: to a single question that have more than one bubble filled in.
5600: Of the form questionnumber::firstbubblenumber:count
5601:
5602: In the above, count is the number of bubble responses in the
5603: input line needed to represent the possible answers to the question.
5604: e.g. a radioresponse with 15 choices in an answer sheet with 10 choices
5605: per line would have count = 2.
5606:
1.423 albertel 5607: maxquest - the number of the last bubble line that was parsed
5608:
5609: (<number> starts at 1)
5610: <number>.answer - zero or more letters representing the selected
5611: letters from the scanline for the bubble line
5612: <number>.
5613: if blank there was either no bubble or there where
5614: multiple bubbles, (consult the keys missingerror and
5615: doubleerror if this is an error condition)
5616:
5617: =cut
5618:
1.82 albertel 5619: sub scantron_parse_scanline {
1.423 albertel 5620: my ($line,$whichline,$scantron_config,$scan_data,$just_header)=@_;
1.470 foxr 5621:
1.82 albertel 5622: my %record;
1.550 raeburn 5623: my $lastpos = $env{'form.scantron_maxbubble'}*$$scantron_config{'Qlength'};
5624: my $questions=substr($line,$$scantron_config{'Qstart'}-1,$lastpos); # Answers
1.422 foxr 5625: my $data=substr($line,0,$$scantron_config{'Qstart'}-1); # earlier stuff
1.278 albertel 5626: if (!($$scantron_config{'CODElocation'} eq 0 ||
5627: $$scantron_config{'CODElocation'} eq 'none')) {
5628: if ($$scantron_config{'CODElocation'} < 0 ||
5629: $$scantron_config{'CODElocation'} eq 'letter' ||
5630: $$scantron_config{'CODElocation'} eq 'number') {
1.191 albertel 5631: $record{'scantron.CODE'}=substr($data,
5632: $$scantron_config{'CODEstart'}-1,
1.83 albertel 5633: $$scantron_config{'CODElength'});
1.191 albertel 5634: if (&scan_data($scan_data,"$whichline.useCODE")) {
5635: $record{'scantron.useCODE'}=1;
5636: }
1.192 albertel 5637: if (&scan_data($scan_data,"$whichline.CODE_ignore_dup")) {
5638: $record{'scantron.CODE_ignore_dup'}=1;
5639: }
1.82 albertel 5640: } else {
5641: #FIXME interpret first N questions
5642: }
5643: }
1.83 albertel 5644: $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
5645: $$scantron_config{'IDlength'});
1.157 albertel 5646: $record{'scantron.PaperID'}=
5647: substr($data,$$scantron_config{'PaperID'}-1,
5648: $$scantron_config{'PaperIDlength'});
5649: $record{'scantron.FirstName'}=
5650: substr($data,$$scantron_config{'FirstName'}-1,
5651: $$scantron_config{'FirstNamelength'});
5652: $record{'scantron.LastName'}=
5653: substr($data,$$scantron_config{'LastName'}-1,
5654: $$scantron_config{'LastNamelength'});
1.423 albertel 5655: if ($just_header) { return \%record; }
1.194 albertel 5656:
1.82 albertel 5657: my @alphabet=('A'..'Z');
5658: my $questnum=0;
1.447 foxr 5659: my $ansnum =1; # Multiple 'answer lines'/question.
5660:
1.470 foxr 5661: chomp($questions); # Get rid of any trailing \n.
5662: $questions =~ s/\r$//; # Get rid of trailing \r too (MAC or Win uploads).
5663: while (length($questions)) {
1.447 foxr 5664: my $answers_needed = $bubble_lines_per_response{$questnum};
1.503 raeburn 5665: my $answer_length = ($$scantron_config{'Qlength'} * $answers_needed)
5666: || 1;
5667: $questnum++;
5668: my $quest_id = $questnum;
5669: my $currentquest = substr($questions,0,$answer_length);
5670: $questions = substr($questions,$answer_length);
5671: if (length($currentquest) < $answer_length) { next; }
5672:
5673: if ($subdivided_bubble_lines{$questnum-1} =~ /,/) {
5674: my $subquestnum = 1;
5675: my $subquestions = $currentquest;
5676: my @subanswers_needed =
5677: split(/,/,$subdivided_bubble_lines{$questnum-1});
5678: foreach my $subans (@subanswers_needed) {
5679: my $subans_length =
5680: ($$scantron_config{'Qlength'} * $subans) || 1;
5681: my $currsubquest = substr($subquestions,0,$subans_length);
5682: $subquestions = substr($subquestions,$subans_length);
5683: $quest_id = "$questnum.$subquestnum";
5684: if (($$scantron_config{'Qon'} eq 'letter') ||
5685: ($$scantron_config{'Qon'} eq 'number')) {
5686: $ansnum = &scantron_validator_lettnum($ansnum,
5687: $questnum,$quest_id,$subans,$currsubquest,$whichline,
5688: \@alphabet,\%record,$scantron_config,$scan_data);
5689: } else {
5690: $ansnum = &scantron_validator_positional($ansnum,
5691: $questnum,$quest_id,$subans,$currsubquest,$whichline, \@alphabet,\%record,$scantron_config,$scan_data);
5692: }
5693: $subquestnum ++;
5694: }
5695: } else {
5696: if (($$scantron_config{'Qon'} eq 'letter') ||
5697: ($$scantron_config{'Qon'} eq 'number')) {
5698: $ansnum = &scantron_validator_lettnum($ansnum,$questnum,
5699: $quest_id,$answers_needed,$currentquest,$whichline,
5700: \@alphabet,\%record,$scantron_config,$scan_data);
5701: } else {
5702: $ansnum = &scantron_validator_positional($ansnum,$questnum,
5703: $quest_id,$answers_needed,$currentquest,$whichline,
5704: \@alphabet,\%record,$scantron_config,$scan_data);
5705: }
5706: }
5707: }
5708: $record{'scantron.maxquest'}=$questnum;
5709: return \%record;
5710: }
1.447 foxr 5711:
1.503 raeburn 5712: sub scantron_validator_lettnum {
5713: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,$whichline,
5714: $alphabet,$record,$scantron_config,$scan_data) = @_;
5715:
5716: # Qon 'letter' implies for each slot in currquest we have:
5717: # ? or * for doubles, a letter in A-Z for a bubble, and
5718: # about anything else (esp. a value of Qoff) for missing
5719: # bubbles.
5720: #
5721: # Qon 'number' implies each slot gives a digit that indexes the
5722: # bubbles filled, or Qoff, or a non-number for unbubbled lines,
5723: # and * or ? for double bubbles on a single line.
5724: #
1.447 foxr 5725:
1.503 raeburn 5726: my $matchon;
5727: if ($$scantron_config{'Qon'} eq 'letter') {
5728: $matchon = '[A-Z]';
5729: } elsif ($$scantron_config{'Qon'} eq 'number') {
5730: $matchon = '\d';
5731: }
5732: my $occurrences = 0;
5733: if (($responsetype_per_response{$questnum-1} eq 'essayresponse') ||
5734: ($responsetype_per_response{$questnum-1} eq 'formularesponse') ||
1.510 raeburn 5735: ($responsetype_per_response{$questnum-1} eq 'stringresponse') ||
5736: ($responsetype_per_response{$questnum-1} eq 'imageresponse') ||
5737: ($responsetype_per_response{$questnum-1} eq 'reactionresponse') ||
5738: ($responsetype_per_response{$questnum-1} eq 'organicresponse')) {
1.503 raeburn 5739: my @singlelines = split('',$currquest);
5740: foreach my $entry (@singlelines) {
5741: $occurrences = &occurence_count($entry,$matchon);
5742: if ($occurrences > 1) {
5743: last;
5744: }
5745: }
5746: } else {
5747: $occurrences = &occurence_count($currquest,$matchon);
5748: }
5749: if (($currquest =~ /\?/ || $currquest =~ /\*/) || ($occurrences > 1)) {
5750: push(@{$record->{'scantron.doubleerror'}},$quest_id);
5751: for (my $ans=0; $ans<$answers_needed; $ans++) {
5752: my $bubble = substr($currquest,$ans,1);
5753: if ($bubble =~ /$matchon/ ) {
5754: if ($$scantron_config{'Qon'} eq 'number') {
5755: if ($bubble == 0) {
5756: $bubble = 10;
5757: }
5758: $record->{"scantron.$ansnum.answer"} =
5759: $alphabet->[$bubble-1];
5760: } else {
5761: $record->{"scantron.$ansnum.answer"} = $bubble;
5762: }
5763: } else {
5764: $record->{"scantron.$ansnum.answer"}='';
5765: }
5766: $ansnum++;
5767: }
5768: } elsif (!defined($currquest)
5769: || (&occurence_count($currquest, $$scantron_config{'Qoff'}) == length($currquest))
5770: || (&occurence_count($currquest,$matchon) == 0)) {
5771: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
5772: $record->{"scantron.$ansnum.answer"}='';
5773: $ansnum++;
5774: }
5775: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
5776: push(@{$record->{'scantron.missingerror'}},$quest_id);
5777: }
5778: } else {
5779: if ($$scantron_config{'Qon'} eq 'number') {
5780: $currquest = &digits_to_letters($currquest);
5781: }
5782: for (my $ans=0; $ans<$answers_needed; $ans++) {
5783: my $bubble = substr($currquest,$ans,1);
5784: $record->{"scantron.$ansnum.answer"} = $bubble;
5785: $ansnum++;
5786: }
5787: }
5788: return $ansnum;
5789: }
1.447 foxr 5790:
1.503 raeburn 5791: sub scantron_validator_positional {
5792: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,
5793: $whichline,$alphabet,$record,$scantron_config,$scan_data) = @_;
1.447 foxr 5794:
1.503 raeburn 5795: # Otherwise there's a positional notation;
5796: # each bubble line requires Qlength items, and there are filled in
5797: # bubbles for each case where there 'Qon' characters.
5798: #
1.447 foxr 5799:
1.503 raeburn 5800: my @array=split($$scantron_config{'Qon'},$currquest,-1);
1.447 foxr 5801:
1.503 raeburn 5802: # If the split only gives us one element.. the full length of the
5803: # answer string, no bubbles are filled in:
1.447 foxr 5804:
1.507 raeburn 5805: if ($answers_needed eq '') {
5806: return;
5807: }
5808:
1.503 raeburn 5809: if (length($array[0]) eq $$scantron_config{'Qlength'}*$answers_needed) {
5810: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
5811: $record->{"scantron.$ansnum.answer"}='';
5812: $ansnum++;
5813: }
5814: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
5815: push(@{$record->{"scantron.missingerror"}},$quest_id);
5816: }
5817: } elsif (scalar(@array) == 2) {
5818: my $location = length($array[0]);
5819: my $line_num = int($location / $$scantron_config{'Qlength'});
5820: my $bubble = $alphabet->[$location % $$scantron_config{'Qlength'}];
5821: for (my $ans=0; $ans<$answers_needed; $ans++) {
5822: if ($ans eq $line_num) {
5823: $record->{"scantron.$ansnum.answer"} = $bubble;
5824: } else {
5825: $record->{"scantron.$ansnum.answer"} = ' ';
5826: }
5827: $ansnum++;
5828: }
5829: } else {
5830: # If there's more than one instance of a bubble character
5831: # That's a double bubble; with positional notation we can
5832: # record all the bubbles filled in as well as the
5833: # fact this response consists of multiple bubbles.
5834: #
5835: if (($responsetype_per_response{$questnum-1} eq 'essayresponse') ||
5836: ($responsetype_per_response{$questnum-1} eq 'formularesponse') ||
1.510 raeburn 5837: ($responsetype_per_response{$questnum-1} eq 'stringresponse') ||
5838: ($responsetype_per_response{$questnum-1} eq 'imageresponse') ||
5839: ($responsetype_per_response{$questnum-1} eq 'reactionresponse') ||
5840: ($responsetype_per_response{$questnum-1} eq 'organicresponse')) {
1.503 raeburn 5841: my $doubleerror = 0;
5842: while (($currquest >= $$scantron_config{'Qlength'}) &&
5843: (!$doubleerror)) {
5844: my $currline = substr($currquest,0,$$scantron_config{'Qlength'});
5845: $currquest = substr($currquest,$$scantron_config{'Qlength'});
5846: my @currarray = split($$scantron_config{'Qon'},$currline,-1);
5847: if (length(@currarray) > 2) {
5848: $doubleerror = 1;
5849: }
5850: }
5851: if ($doubleerror) {
5852: push(@{$record->{'scantron.doubleerror'}},$quest_id);
5853: }
5854: } else {
5855: push(@{$record->{'scantron.doubleerror'}},$quest_id);
5856: }
5857: my $item = $ansnum;
5858: for (my $ans=0; $ans<$answers_needed; $ans++) {
5859: $record->{"scantron.$item.answer"} = '';
5860: $item ++;
5861: }
1.447 foxr 5862:
1.503 raeburn 5863: my @ans=@array;
5864: my $i=0;
5865: my $increment = 0;
5866: while ($#ans) {
5867: $i+=length($ans[0]) + $increment;
5868: my $line = int($i/$$scantron_config{'Qlength'} + $ansnum);
5869: my $bubble = $i%$$scantron_config{'Qlength'};
5870: $record->{"scantron.$line.answer"}.=$alphabet->[$bubble];
5871: shift(@ans);
5872: $increment = 1;
5873: }
5874: $ansnum += $answers_needed;
1.82 albertel 5875: }
1.503 raeburn 5876: return $ansnum;
1.82 albertel 5877: }
5878:
1.423 albertel 5879: =pod
5880:
5881: =item scantron_add_delay
5882:
5883: Adds an error message that occurred during the grading phase to a
5884: queue of messages to be shown after grading pass is complete
5885:
5886: Arguments:
1.424 albertel 5887: $delayqueue - arrary ref of hash ref of error messages
1.423 albertel 5888: $scanline - the scanline that caused the error
5889: $errormesage - the error message
5890: $errorcode - a numeric code for the error
5891:
5892: Side Effects:
1.424 albertel 5893: updates the $delayqueue to have a new hash ref of the error
1.423 albertel 5894:
5895: =cut
5896:
1.82 albertel 5897: sub scantron_add_delay {
1.140 albertel 5898: my ($delayqueue,$scanline,$errormessage,$errorcode)=@_;
5899: push(@$delayqueue,
5900: {'line' => $scanline, 'emsg' => $errormessage,
5901: 'ecode' => $errorcode }
5902: );
1.82 albertel 5903: }
5904:
1.423 albertel 5905: =pod
5906:
5907: =item scantron_find_student
5908:
1.424 albertel 5909: Finds the username for the current scanline
5910:
5911: Arguments:
5912: $scantron_record - hash result from scantron_parse_scanline
5913: $scan_data - hash of correction information
5914: (see &scantron_getfile() form more information)
5915: $idmap - hash from &username_to_idmap()
5916: $line - number of current scanline
5917:
5918: Returns:
5919: Either 'username:domain' or undef if unknown
5920:
1.423 albertel 5921: =cut
5922:
1.82 albertel 5923: sub scantron_find_student {
1.157 albertel 5924: my ($scantron_record,$scan_data,$idmap,$line)=@_;
1.83 albertel 5925: my $scanID=$$scantron_record{'scantron.ID'};
1.157 albertel 5926: if ($scanID =~ /^\s*$/) {
5927: return &scan_data($scan_data,"$line.user");
5928: }
1.83 albertel 5929: foreach my $id (keys(%$idmap)) {
1.157 albertel 5930: if (lc($id) eq lc($scanID)) {
5931: return $$idmap{$id};
5932: }
1.83 albertel 5933: }
5934: return undef;
5935: }
5936:
1.423 albertel 5937: =pod
5938:
5939: =item scantron_filter
5940:
1.424 albertel 5941: Filter sub for lonnavmaps, filters out hidden resources if ignore
5942: hidden resources was selected
5943:
1.423 albertel 5944: =cut
5945:
1.83 albertel 5946: sub scantron_filter {
5947: my ($curres)=@_;
1.331 albertel 5948:
5949: if (ref($curres) && $curres->is_problem()) {
5950: # if the user has asked to not have either hidden
5951: # or 'randomout' controlled resources to be graded
5952: # don't include them
5953: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
5954: && $curres->randomout) {
5955: return 0;
5956: }
1.83 albertel 5957: return 1;
5958: }
5959: return 0;
1.82 albertel 5960: }
5961:
1.423 albertel 5962: =pod
5963:
5964: =item scantron_process_corrections
5965:
1.424 albertel 5966: Gets correction information out of submitted form data and corrects
5967: the scanline
5968:
1.423 albertel 5969: =cut
5970:
1.157 albertel 5971: sub scantron_process_corrections {
5972: my ($r) = @_;
1.257 albertel 5973: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5974: my ($scanlines,$scan_data)=&scantron_getfile();
5975: my $classlist=&Apache::loncoursedata::get_classlist();
1.257 albertel 5976: my $which=$env{'form.scantron_line'};
1.200 albertel 5977: my $line=&scantron_get_line($scanlines,$scan_data,$which);
1.157 albertel 5978: my ($skip,$err,$errmsg);
1.257 albertel 5979: if ($env{'form.scantron_skip_record'}) {
1.157 albertel 5980: $skip=1;
1.257 albertel 5981: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)ID$/) {
5982: my $newstudent=$env{'form.scantron_username'}.':'.
5983: $env{'form.scantron_domain'};
1.157 albertel 5984: my $newid=$classlist->{$newstudent}->[&Apache::loncoursedata::CL_ID];
5985: ($line,$err,$errmsg)=
5986: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
5987: 'ID',{'newid'=>$newid,
1.257 albertel 5988: 'username'=>$env{'form.scantron_username'},
5989: 'domain'=>$env{'form.scantron_domain'}});
5990: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)CODE$/) {
5991: my $resolution=$env{'form.scantron_CODE_resolution'};
1.190 albertel 5992: my $newCODE;
1.192 albertel 5993: my %args;
1.190 albertel 5994: if ($resolution eq 'use_unfound') {
1.191 albertel 5995: $newCODE='use_unfound';
1.190 albertel 5996: } elsif ($resolution eq 'use_found') {
1.257 albertel 5997: $newCODE=$env{'form.scantron_CODE_selectedvalue'};
1.190 albertel 5998: } elsif ($resolution eq 'use_typed') {
1.257 albertel 5999: $newCODE=$env{'form.scantron_CODE_newvalue'};
1.194 albertel 6000: } elsif ($resolution =~ /^use_closest_(\d+)/) {
1.257 albertel 6001: $newCODE=$env{"form.scantron_CODE_closest_$1"};
1.190 albertel 6002: }
1.257 albertel 6003: if ($env{'form.scantron_corrections'} eq 'duplicateCODE') {
1.192 albertel 6004: $args{'CODE_ignore_dup'}=1;
6005: }
6006: $args{'CODE'}=$newCODE;
1.186 albertel 6007: ($line,$err,$errmsg)=
6008: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
1.192 albertel 6009: 'CODE',\%args);
1.257 albertel 6010: } elsif ($env{'form.scantron_corrections'} =~ /^(missing|double)bubble$/) {
6011: foreach my $question (split(',',$env{'form.scantron_questions'})) {
1.157 albertel 6012: ($line,$err,$errmsg)=
6013: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,
6014: $which,'answer',
6015: { 'question'=>$question,
1.503 raeburn 6016: 'response'=>$env{"form.scantron_correct_Q_$question"},
6017: 'questionnum'=>$env{"form.scantron_questionnum_Q_$question"}});
1.157 albertel 6018: if ($err) { last; }
6019: }
6020: }
6021: if ($err) {
1.398 albertel 6022: $r->print("<span class=\"LC_warning\">Unable to accept last correction, an error occurred :$errmsg:</span>");
1.157 albertel 6023: } else {
1.200 albertel 6024: &scantron_put_line($scanlines,$scan_data,$which,$line,$skip);
1.157 albertel 6025: &scantron_putfile($scanlines,$scan_data);
6026: }
6027: }
6028:
1.423 albertel 6029: =pod
6030:
6031: =item reset_skipping_status
6032:
1.424 albertel 6033: Forgets the current set of remember skipped scanlines (and thus
6034: reverts back to considering all lines in the
6035: scantron_skipped_<filename> file)
6036:
1.423 albertel 6037: =cut
6038:
1.200 albertel 6039: sub reset_skipping_status {
6040: my ($scanlines,$scan_data)=&scantron_getfile();
6041: &scan_data($scan_data,'remember_skipping',undef,1);
6042: &scantron_putfile(undef,$scan_data);
6043: }
6044:
1.423 albertel 6045: =pod
6046:
6047: =item start_skipping
6048:
1.424 albertel 6049: Marks a scanline to be skipped.
6050:
1.423 albertel 6051: =cut
6052:
1.376 albertel 6053: sub start_skipping {
1.200 albertel 6054: my ($scan_data,$i)=@_;
6055: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 6056: if ($env{'form.scantron_options_redo'} =~ /^redo_/) {
6057: $remembered{$i}=2;
6058: } else {
6059: $remembered{$i}=1;
6060: }
1.200 albertel 6061: &scan_data($scan_data,'remember_skipping',join(':',%remembered));
6062: }
6063:
1.423 albertel 6064: =pod
6065:
6066: =item should_be_skipped
6067:
1.424 albertel 6068: Checks whether a scanline should be skipped.
6069:
1.423 albertel 6070: =cut
6071:
1.200 albertel 6072: sub should_be_skipped {
1.376 albertel 6073: my ($scanlines,$scan_data,$i)=@_;
1.257 albertel 6074: if ($env{'form.scantron_options_redo'} !~ /^redo_/) {
1.200 albertel 6075: # not redoing old skips
1.376 albertel 6076: if ($scanlines->{'skipped'}[$i]) { return 1; }
1.200 albertel 6077: return 0;
6078: }
6079: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 6080:
6081: if (exists($remembered{$i}) && $remembered{$i} != 2 ) {
6082: return 0;
6083: }
1.200 albertel 6084: return 1;
6085: }
6086:
1.423 albertel 6087: =pod
6088:
6089: =item remember_current_skipped
6090:
1.424 albertel 6091: Discovers what scanlines are in the scantron_skipped_<filename>
6092: file and remembers them into scan_data for later use.
6093:
1.423 albertel 6094: =cut
6095:
1.200 albertel 6096: sub remember_current_skipped {
6097: my ($scanlines,$scan_data)=&scantron_getfile();
6098: my %to_remember;
6099: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
6100: if ($scanlines->{'skipped'}[$i]) {
6101: $to_remember{$i}=1;
6102: }
6103: }
1.376 albertel 6104:
1.200 albertel 6105: &scan_data($scan_data,'remember_skipping',join(':',%to_remember));
6106: &scantron_putfile(undef,$scan_data);
6107: }
6108:
1.423 albertel 6109: =pod
6110:
6111: =item check_for_error
6112:
1.424 albertel 6113: Checks if there was an error when attempting to remove a specific
6114: scantron_.. bubble sheet data file. Prints out an error if
6115: something went wrong.
6116:
1.423 albertel 6117: =cut
6118:
1.200 albertel 6119: sub check_for_error {
6120: my ($r,$result)=@_;
6121: if ($result ne 'ok' && $result ne 'not_found' ) {
1.492 albertel 6122: $r->print(&mt("An error occurred ([_1]) when trying to remove the existing corrections.",$result));
1.200 albertel 6123: }
6124: }
1.157 albertel 6125:
1.423 albertel 6126: =pod
6127:
6128: =item scantron_warning_screen
6129:
1.424 albertel 6130: Interstitial screen to make sure the operator has selected the
6131: correct options before we start the validation phase.
6132:
1.423 albertel 6133: =cut
6134:
1.203 albertel 6135: sub scantron_warning_screen {
6136: my ($button_text)=@_;
1.257 albertel 6137: my $title=&Apache::lonnet::gettitle($env{'form.selectpage'});
1.284 albertel 6138: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.373 albertel 6139: my $CODElist;
1.284 albertel 6140: if ($scantron_config{'CODElocation'} &&
6141: $scantron_config{'CODEstart'} &&
6142: $scantron_config{'CODElength'}) {
6143: $CODElist=$env{'form.scantron_CODElist'};
1.398 albertel 6144: if ($env{'form.scantron_CODElist'} eq '') { $CODElist='<span class="LC_warning">None</span>'; }
1.284 albertel 6145: $CODElist=
1.492 albertel 6146: '<tr><td><b>'.&mt('List of CODES to validate against:').'</b></td><td><tt>'.
1.373 albertel 6147: $env{'form.scantron_CODElist'}.'</tt></td></tr>';
1.284 albertel 6148: }
1.492 albertel 6149: return ('
1.203 albertel 6150: <p>
1.492 albertel 6151: <span class="LC_warning">
6152: '.&mt('Please double check the information below before clicking on \'[_1]\'',&mt($button_text)).'</span>
1.203 albertel 6153: </p>
6154: <table>
1.492 albertel 6155: <tr><td><b>'.&mt('Sequence to be Graded:').'</b></td><td>'.$title.'</td></tr>
6156: <tr><td><b>'.&mt('Data File that will be used:').'</b></td><td><tt>'.$env{'form.scantron_selectfile'}.'</tt></td></tr>
6157: '.$CODElist.'
1.203 albertel 6158: </table>
6159: <br />
1.492 albertel 6160: <p> '.&mt('If this information is correct, please click on \'[_1]\'.',&mt($button_text)).'</p>
6161: <p> '.&mt('If something is incorrect, please click the \'Grading Menu\' button to start over.').'</p>
1.203 albertel 6162:
6163: <br />
1.492 albertel 6164: ');
1.203 albertel 6165: }
6166:
1.423 albertel 6167: =pod
6168:
6169: =item scantron_do_warning
6170:
1.424 albertel 6171: Check if the operator has picked something for all required
6172: fields. Error out if something is missing.
6173:
1.423 albertel 6174: =cut
6175:
1.203 albertel 6176: sub scantron_do_warning {
1.608 www 6177: my ($r,$symb)=@_;
1.203 albertel 6178: if (!$symb) {return '';}
1.324 albertel 6179: my $default_form_data=&defaultFormData($symb);
1.203 albertel 6180: $r->print(&scantron_form_start().$default_form_data);
1.257 albertel 6181: if ( $env{'form.selectpage'} eq '' ||
6182: $env{'form.scantron_selectfile'} eq '' ||
6183: $env{'form.scantron_format'} eq '' ) {
1.492 albertel 6184: $r->print("<p>".&mt('You have forgetten to specify some information. Please go Back and try again.')."</p>");
1.257 albertel 6185: if ( $env{'form.selectpage'} eq '') {
1.492 albertel 6186: $r->print('<p><span class="LC_error">'.&mt('You have not selected a Sequence to grade').'</span></p>');
1.237 albertel 6187: }
1.257 albertel 6188: if ( $env{'form.scantron_selectfile'} eq '') {
1.492 albertel 6189: $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 6190: }
1.257 albertel 6191: if ( $env{'form.scantron_format'} eq '') {
1.492 albertel 6192: $r->print('<p><span class="LC_error">'.&mt('You have not selected a the format of the student\'s response data.').'</span></p>');
1.237 albertel 6193: }
6194: } else {
1.265 www 6195: my $warning=&scantron_warning_screen('Grading: Validate Records');
1.492 albertel 6196: $r->print('
6197: '.$warning.'
6198: <input type="submit" name="submit" value="'.&mt('Grading: Validate Records').'" />
1.203 albertel 6199: <input type="hidden" name="command" value="scantron_validate" />
1.492 albertel 6200: ');
1.237 albertel 6201: }
1.614 www 6202: $r->print("</form><br />");
1.203 albertel 6203: return '';
6204: }
6205:
1.423 albertel 6206: =pod
6207:
6208: =item scantron_form_start
6209:
1.424 albertel 6210: html hidden input for remembering all selected grading options
6211:
1.423 albertel 6212: =cut
6213:
1.203 albertel 6214: sub scantron_form_start {
6215: my ($max_bubble)=@_;
6216: my $result= <<SCANTRONFORM;
6217: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
1.257 albertel 6218: <input type="hidden" name="selectpage" value="$env{'form.selectpage'}" />
6219: <input type="hidden" name="scantron_format" value="$env{'form.scantron_format'}" />
6220: <input type="hidden" name="scantron_selectfile" value="$env{'form.scantron_selectfile'}" />
1.218 albertel 6221: <input type="hidden" name="scantron_maxbubble" value="$max_bubble" />
1.257 albertel 6222: <input type="hidden" name="scantron_CODElist" value="$env{'form.scantron_CODElist'}" />
6223: <input type="hidden" name="scantron_CODEunique" value="$env{'form.scantron_CODEunique'}" />
6224: <input type="hidden" name="scantron_options_redo" value="$env{'form.scantron_options_redo'}" />
6225: <input type="hidden" name="scantron_options_ignore" value="$env{'form.scantron_options_ignore'}" />
1.331 albertel 6226: <input type="hidden" name="scantron_options_hidden" value="$env{'form.scantron_options_hidden'}" />
1.203 albertel 6227: SCANTRONFORM
1.447 foxr 6228:
6229: my $line = 0;
6230: while (defined($env{"form.scantron.bubblelines.$line"})) {
6231: my $chunk =
6232: '<input type="hidden" name="scantron.bubblelines.'.$line.'" value="'.$env{"form.scantron.bubblelines.$line"}.'" />'."\n";
1.448 foxr 6233: $chunk .=
6234: '<input type="hidden" name="scantron.first_bubble_line.'.$line.'" value="'.$env{"form.scantron.first_bubble_line.$line"}.'" />'."\n";
1.503 raeburn 6235: $chunk .=
6236: '<input type="hidden" name="scantron.sub_bubblelines.'.$line.'" value="'.$env{"form.scantron.sub_bubblelines.$line"}.'" />'."\n";
1.504 raeburn 6237: $chunk .=
6238: '<input type="hidden" name="scantron.responsetype.'.$line.'" value="'.$env{"form.scantron.responsetype.$line"}.'" />'."\n";
1.447 foxr 6239: $result .= $chunk;
6240: $line++;
6241: }
1.203 albertel 6242: return $result;
6243: }
6244:
1.423 albertel 6245: =pod
6246:
6247: =item scantron_validate_file
6248:
1.424 albertel 6249: Dispatch routine for doing validation of a bubble sheet data file.
6250:
6251: Also processes any necessary information resets that need to
6252: occur before validation begins (ignore previous corrections,
6253: restarting the skipped records processing)
6254:
1.423 albertel 6255: =cut
6256:
1.157 albertel 6257: sub scantron_validate_file {
1.608 www 6258: my ($r,$symb) = @_;
1.157 albertel 6259: if (!$symb) {return '';}
1.324 albertel 6260: my $default_form_data=&defaultFormData($symb);
1.200 albertel 6261:
6262: # do the detection of only doing skipped records first befroe we delete
1.424 albertel 6263: # them when doing the corrections reset
1.257 albertel 6264: if ($env{'form.scantron_options_redo'} ne 'redo_skipped_ready') {
1.200 albertel 6265: &reset_skipping_status();
6266: }
1.257 albertel 6267: if ($env{'form.scantron_options_redo'} eq 'redo_skipped') {
1.200 albertel 6268: &remember_current_skipped();
1.257 albertel 6269: $env{'form.scantron_options_redo'}='redo_skipped_ready';
1.200 albertel 6270: }
6271:
1.257 albertel 6272: if ($env{'form.scantron_options_ignore'} eq 'ignore_corrections') {
1.200 albertel 6273: &check_for_error($r,&scantron_remove_file('corrected'));
6274: &check_for_error($r,&scantron_remove_file('skipped'));
6275: &check_for_error($r,&scantron_remove_scan_data());
1.257 albertel 6276: $env{'form.scantron_options_ignore'}='done';
1.192 albertel 6277: }
1.200 albertel 6278:
1.257 albertel 6279: if ($env{'form.scantron_corrections'}) {
1.157 albertel 6280: &scantron_process_corrections($r);
6281: }
1.503 raeburn 6282: $r->print('<p>'.&mt('Gathering necessary information.').'</p>');$r->rflush();
1.157 albertel 6283: #get the student pick code ready
6284: $r->print(&Apache::loncommon::studentbrowser_javascript());
1.582 raeburn 6285: my $nav_error;
6286: my $max_bubble=&scantron_get_maxbubble(\$nav_error);
6287: if ($nav_error) {
6288: $r->print(&navmap_errormsg());
6289: return '';
6290: }
1.203 albertel 6291: my $result=&scantron_form_start($max_bubble).$default_form_data;
1.157 albertel 6292: $r->print($result);
6293:
1.334 albertel 6294: my @validate_phases=( 'sequence',
6295: 'ID',
1.157 albertel 6296: 'CODE',
6297: 'doublebubble',
6298: 'missingbubbles');
1.257 albertel 6299: if (!$env{'form.validatepass'}) {
6300: $env{'form.validatepass'} = 0;
1.157 albertel 6301: }
1.257 albertel 6302: my $currentphase=$env{'form.validatepass'};
1.157 albertel 6303:
1.448 foxr 6304:
1.157 albertel 6305: my $stop=0;
6306: while (!$stop && $currentphase < scalar(@validate_phases)) {
1.503 raeburn 6307: $r->print(&mt('Validating '.$validate_phases[$currentphase]).'<br />');
1.157 albertel 6308: $r->rflush();
6309: my $which="scantron_validate_".$validate_phases[$currentphase];
6310: {
6311: no strict 'refs';
6312: ($stop,$currentphase)=&$which($r,$currentphase);
6313: }
6314: }
6315: if (!$stop) {
1.203 albertel 6316: my $warning=&scantron_warning_screen('Start Grading');
1.542 raeburn 6317: $r->print(&mt('Validation process complete.').'<br />'.
6318: $warning.
6319: &mt('Perform verification for each student after storage of submissions?').
6320: ' <span class="LC_nobreak"><label>'.
6321: '<input type="radio" name="verifyrecord" value="1" />'.&mt('Yes').'</label>'.
6322: (' 'x3).'<label>'.
6323: '<input type="radio" name="verifyrecord" value="0" checked="checked" />'.&mt('No').
6324: '</label></span><br />'.
6325: &mt('Grading will take longer if you use verification.').'<br />'.
1.572 www 6326: &mt("Alternatively, the 'Review bubblesheet data' utility (see grading menu) can be used for all students after grading is complete.").'<br /><br />'.
1.542 raeburn 6327: '<input type="submit" name="submit" value="'.&mt('Start Grading').'" />'.
6328: '<input type="hidden" name="command" value="scantron_process" />'."\n");
1.157 albertel 6329: } else {
6330: $r->print('<input type="hidden" name="command" value="scantron_validate" />');
6331: $r->print("<input type='hidden' name='validatepass' value='".$currentphase."' />");
6332: }
6333: if ($stop) {
1.334 albertel 6334: if ($validate_phases[$currentphase] eq 'sequence') {
1.539 riegler 6335: $r->print('<input type="submit" name="submit" value="'.&mt('Ignore').' → " />');
1.492 albertel 6336: $r->print(' '.&mt('this error').' <br />');
1.334 albertel 6337:
1.492 albertel 6338: $r->print(" <p>".&mt("Or click the 'Grading Menu' button to start over.")."</p>");
1.334 albertel 6339: } else {
1.503 raeburn 6340: if ($validate_phases[$currentphase] eq 'doublebubble' || $validate_phases[$currentphase] eq 'missingbubbles') {
1.539 riegler 6341: $r->print('<input type="button" name="submitbutton" value="'.&mt('Continue').' →" onclick="javascript:verify_bubble_radio(this.form)" />');
1.503 raeburn 6342: } else {
1.539 riegler 6343: $r->print('<input type="submit" name="submit" value="'.&mt('Continue').' →" />');
1.503 raeburn 6344: }
1.492 albertel 6345: $r->print(' '.&mt('using corrected info').' <br />');
6346: $r->print("<input type='submit' value='".&mt("Skip")."' name='scantron_skip_record' />");
6347: $r->print(" ".&mt("this scanline saving it for later."));
1.334 albertel 6348: }
1.157 albertel 6349: }
1.614 www 6350: $r->print(" </form><br />");
1.157 albertel 6351: return '';
6352: }
6353:
1.423 albertel 6354:
6355: =pod
6356:
6357: =item scantron_remove_file
6358:
1.424 albertel 6359: Removes the requested bubble sheet data file, makes sure that
6360: scantron_original_<filename> is never removed
6361:
6362:
1.423 albertel 6363: =cut
6364:
1.200 albertel 6365: sub scantron_remove_file {
1.192 albertel 6366: my ($which)=@_;
1.257 albertel 6367: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6368: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 6369: my $file='scantron_';
1.200 albertel 6370: if ($which eq 'corrected' || $which eq 'skipped') {
6371: $file.=$which.'_';
1.192 albertel 6372: } else {
6373: return 'refused';
6374: }
1.257 albertel 6375: $file.=$env{'form.scantron_selectfile'};
1.200 albertel 6376: return &Apache::lonnet::removeuserfile($cname,$cdom,$file);
6377: }
6378:
1.423 albertel 6379:
6380: =pod
6381:
6382: =item scantron_remove_scan_data
6383:
1.424 albertel 6384: Removes all scan_data correction for the requested bubble sheet
6385: data file. (In the case that both the are doing skipped records we need
6386: to remember the old skipped lines for the time being so that element
6387: persists for a while.)
6388:
1.423 albertel 6389: =cut
6390:
1.200 albertel 6391: sub scantron_remove_scan_data {
1.257 albertel 6392: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6393: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 6394: my @keys=&Apache::lonnet::getkeys('nohist_scantrondata',$cdom,$cname);
6395: my @todelete;
1.257 albertel 6396: my $filename=$env{'form.scantron_selectfile'};
1.192 albertel 6397: foreach my $key (@keys) {
6398: if ($key=~/^\Q$filename\E_/) {
1.257 albertel 6399: if ($env{'form.scantron_options_redo'} eq 'redo_skipped_ready' &&
1.200 albertel 6400: $key=~/remember_skipping/) {
6401: next;
6402: }
1.192 albertel 6403: push(@todelete,$key);
6404: }
6405: }
1.200 albertel 6406: my $result;
1.192 albertel 6407: if (@todelete) {
1.491 albertel 6408: $result = &Apache::lonnet::del('nohist_scantrondata',
6409: \@todelete,$cdom,$cname);
6410: } else {
6411: $result = 'ok';
1.192 albertel 6412: }
6413: return $result;
6414: }
6415:
1.423 albertel 6416:
6417: =pod
6418:
6419: =item scantron_getfile
6420:
1.424 albertel 6421: Fetches the requested bubble sheet data file (all 3 versions), and
6422: the scan_data hash
6423:
6424: Arguments:
6425: None
6426:
6427: Returns:
6428: 2 hash references
6429:
6430: - first one has
6431: orig -
6432: corrected -
6433: skipped - each of which points to an array ref of the specified
6434: file broken up into individual lines
6435: count - number of scanlines
6436:
6437: - second is the scan_data hash possible keys are
1.425 albertel 6438: ($number refers to scanline numbered $number and thus the key affects
6439: only that scanline
6440: $bubline refers to the specific bubble line element and the aspects
6441: refers to that specific bubble line element)
6442:
6443: $number.user - username:domain to use
6444: $number.CODE_ignore_dup
6445: - ignore the duplicate CODE error
6446: $number.useCODE
6447: - use the CODE in the scanline as is
6448: $number.no_bubble.$bubline
6449: - it is valid that there is no bubbled in bubble
6450: at $number $bubline
6451: remember_skipping
6452: - a frozen hash containing keys of $number and values
6453: of either
6454: 1 - we are on a 'do skipped records pass' and plan
6455: on processing this line
6456: 2 - we are on a 'do skipped records pass' and this
6457: scanline has been marked to skip yet again
1.424 albertel 6458:
1.423 albertel 6459: =cut
6460:
1.157 albertel 6461: sub scantron_getfile {
1.200 albertel 6462: #FIXME really would prefer a scantron directory
1.257 albertel 6463: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6464: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.157 albertel 6465: my $lines;
6466: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6467: 'scantron_orig_'.$env{'form.scantron_selectfile'});
1.157 albertel 6468: my %scanlines;
6469: $scanlines{'orig'}=[(split("\n",$lines,-1))];
6470: my $temp=$scanlines{'orig'};
6471: $scanlines{'count'}=$#$temp;
6472:
6473: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6474: 'scantron_corrected_'.$env{'form.scantron_selectfile'});
1.157 albertel 6475: if ($lines eq '-1') {
6476: $scanlines{'corrected'}=[];
6477: } else {
6478: $scanlines{'corrected'}=[(split("\n",$lines,-1))];
6479: }
6480: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6481: 'scantron_skipped_'.$env{'form.scantron_selectfile'});
1.157 albertel 6482: if ($lines eq '-1') {
6483: $scanlines{'skipped'}=[];
6484: } else {
6485: $scanlines{'skipped'}=[(split("\n",$lines,-1))];
6486: }
1.175 albertel 6487: my @tmp=&Apache::lonnet::dump('nohist_scantrondata',$cdom,$cname);
1.157 albertel 6488: if ($tmp[0] =~ /^(error:|no_such_host)/) { @tmp=(); }
6489: my %scan_data = @tmp;
6490: return (\%scanlines,\%scan_data);
6491: }
6492:
1.423 albertel 6493: =pod
6494:
6495: =item lonnet_putfile
6496:
1.424 albertel 6497: Wrapper routine to call &Apache::lonnet::finishuserfileupload
6498:
6499: Arguments:
6500: $contents - data to store
6501: $filename - filename to store $contents into
6502:
6503: Returns:
6504: result value from &Apache::lonnet::finishuserfileupload
6505:
1.423 albertel 6506: =cut
6507:
1.157 albertel 6508: sub lonnet_putfile {
6509: my ($contents,$filename)=@_;
1.257 albertel 6510: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6511: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6512: $env{'form.sillywaytopassafilearound'}=$contents;
1.275 albertel 6513: &Apache::lonnet::finishuserfileupload($docuname,$docudom,'sillywaytopassafilearound',$filename);
1.157 albertel 6514:
6515: }
6516:
1.423 albertel 6517: =pod
6518:
6519: =item scantron_putfile
6520:
1.424 albertel 6521: Stores the current version of the bubble sheet data files, and the
6522: scan_data hash. (Does not modify the original version only the
6523: corrected and skipped versions.
6524:
6525: Arguments:
6526: $scanlines - hash ref that looks like the first return value from
6527: &scantron_getfile()
6528: $scan_data - hash ref that looks like the second return value from
6529: &scantron_getfile()
6530:
1.423 albertel 6531: =cut
6532:
1.157 albertel 6533: sub scantron_putfile {
6534: my ($scanlines,$scan_data) = @_;
1.200 albertel 6535: #FIXME really would prefer a scantron directory
1.257 albertel 6536: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6537: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.200 albertel 6538: if ($scanlines) {
6539: my $prefix='scantron_';
1.157 albertel 6540: # no need to update orig, shouldn't change
6541: # &lonnet_putfile(join("\n",@{$scanlines->{'orig'}}),$prefix.'orig_'.
1.257 albertel 6542: # $env{'form.scantron_selectfile'});
1.200 albertel 6543: &lonnet_putfile(join("\n",@{$scanlines->{'corrected'}}),
6544: $prefix.'corrected_'.
1.257 albertel 6545: $env{'form.scantron_selectfile'});
1.200 albertel 6546: &lonnet_putfile(join("\n",@{$scanlines->{'skipped'}}),
6547: $prefix.'skipped_'.
1.257 albertel 6548: $env{'form.scantron_selectfile'});
1.200 albertel 6549: }
1.175 albertel 6550: &Apache::lonnet::put('nohist_scantrondata',$scan_data,$cdom,$cname);
1.157 albertel 6551: }
6552:
1.423 albertel 6553: =pod
6554:
6555: =item scantron_get_line
6556:
1.424 albertel 6557: Returns the correct version of the scanline
6558:
6559: Arguments:
6560: $scanlines - hash ref that looks like the first return value from
6561: &scantron_getfile()
6562: $scan_data - hash ref that looks like the second return value from
6563: &scantron_getfile()
6564: $i - number of the requested line (starts at 0)
6565:
6566: Returns:
6567: A scanline, (either the original or the corrected one if it
6568: exists), or undef if the requested scanline should be
6569: skipped. (Either because it's an skipped scanline, or it's an
6570: unskipped scanline and we are not doing a 'do skipped scanlines'
6571: pass.
6572:
1.423 albertel 6573: =cut
6574:
1.157 albertel 6575: sub scantron_get_line {
1.200 albertel 6576: my ($scanlines,$scan_data,$i)=@_;
1.376 albertel 6577: if (&should_be_skipped($scanlines,$scan_data,$i)) { return undef; }
6578: #if ($scanlines->{'skipped'}[$i]) { return undef; }
1.157 albertel 6579: if ($scanlines->{'corrected'}[$i]) {return $scanlines->{'corrected'}[$i];}
6580: return $scanlines->{'orig'}[$i];
6581: }
6582:
1.423 albertel 6583: =pod
6584:
6585: =item scantron_todo_count
6586:
1.424 albertel 6587: Counts the number of scanlines that need processing.
6588:
6589: Arguments:
6590: $scanlines - hash ref that looks like the first return value from
6591: &scantron_getfile()
6592: $scan_data - hash ref that looks like the second return value from
6593: &scantron_getfile()
6594:
6595: Returns:
6596: $count - number of scanlines to process
6597:
1.423 albertel 6598: =cut
6599:
1.200 albertel 6600: sub get_todo_count {
6601: my ($scanlines,$scan_data)=@_;
6602: my $count=0;
6603: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
6604: my $line=&scantron_get_line($scanlines,$scan_data,$i);
6605: if ($line=~/^[\s\cz]*$/) { next; }
6606: $count++;
6607: }
6608: return $count;
6609: }
6610:
1.423 albertel 6611: =pod
6612:
6613: =item scantron_put_line
6614:
1.424 albertel 6615: Updates the 'corrected' or 'skipped' versions of the bubble sheet
6616: data file.
6617:
6618: Arguments:
6619: $scanlines - hash ref that looks like the first return value from
6620: &scantron_getfile()
6621: $scan_data - hash ref that looks like the second return value from
6622: &scantron_getfile()
6623: $i - line number to update
6624: $newline - contents of the updated scanline
6625: $skip - if true make the line for skipping and update the
6626: 'skipped' file
6627:
1.423 albertel 6628: =cut
6629:
1.157 albertel 6630: sub scantron_put_line {
1.200 albertel 6631: my ($scanlines,$scan_data,$i,$newline,$skip)=@_;
1.157 albertel 6632: if ($skip) {
6633: $scanlines->{'skipped'}[$i]=$newline;
1.376 albertel 6634: &start_skipping($scan_data,$i);
1.157 albertel 6635: return;
6636: }
6637: $scanlines->{'corrected'}[$i]=$newline;
6638: }
6639:
1.423 albertel 6640: =pod
6641:
6642: =item scantron_clear_skip
6643:
1.424 albertel 6644: Remove a line from the 'skipped' file
6645:
6646: Arguments:
6647: $scanlines - hash ref that looks like the first return value from
6648: &scantron_getfile()
6649: $scan_data - hash ref that looks like the second return value from
6650: &scantron_getfile()
6651: $i - line number to update
6652:
1.423 albertel 6653: =cut
6654:
1.376 albertel 6655: sub scantron_clear_skip {
6656: my ($scanlines,$scan_data,$i)=@_;
6657: if (exists($scanlines->{'skipped'}[$i])) {
6658: undef($scanlines->{'skipped'}[$i]);
6659: return 1;
6660: }
6661: return 0;
6662: }
6663:
1.423 albertel 6664: =pod
6665:
6666: =item scantron_filter_not_exam
6667:
1.424 albertel 6668: Filter routine used by &Apache::lonnavmaps::retrieveResources(), to
6669: filter out resources that are not marked as 'exam' mode
6670:
1.423 albertel 6671: =cut
6672:
1.334 albertel 6673: sub scantron_filter_not_exam {
6674: my ($curres)=@_;
6675:
6676: if (ref($curres) && $curres->is_problem() && !$curres->is_exam()) {
6677: # if the user has asked to not have either hidden
6678: # or 'randomout' controlled resources to be graded
6679: # don't include them
6680: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
6681: && $curres->randomout) {
6682: return 0;
6683: }
6684: return 1;
6685: }
6686: return 0;
6687: }
6688:
1.423 albertel 6689: =pod
6690:
6691: =item scantron_validate_sequence
6692:
1.424 albertel 6693: Validates the selected sequence, checking for resource that are
6694: not set to exam mode.
6695:
1.423 albertel 6696: =cut
6697:
1.334 albertel 6698: sub scantron_validate_sequence {
6699: my ($r,$currentphase) = @_;
6700:
6701: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 6702: unless (ref($navmap)) {
6703: $r->print(&navmap_errormsg());
6704: return (1,$currentphase);
6705: }
1.334 albertel 6706: my (undef,undef,$sequence)=
6707: &Apache::lonnet::decode_symb($env{'form.selectpage'});
6708:
6709: my $map=$navmap->getResourceByUrl($sequence);
6710:
6711: $r->print('<input type="hidden" name="validate_sequence_exam"
6712: value="ignore" />');
6713: if ($env{'form.validate_sequence_exam'} ne 'ignore') {
6714: my @resources=
6715: $navmap->retrieveResources($map,\&scantron_filter_not_exam,1,0);
6716: if (@resources) {
1.357 banghart 6717: $r->print("<p>".&mt('Some resources in the sequence currently are not set to exam mode. Grading these resources currently may not work correctly.')."</p>");
1.334 albertel 6718: return (1,$currentphase);
6719: }
6720: }
6721:
6722: return (0,$currentphase+1);
6723: }
6724:
1.423 albertel 6725:
6726:
1.157 albertel 6727: sub scantron_validate_ID {
6728: my ($r,$currentphase) = @_;
6729:
6730: #get student info
6731: my $classlist=&Apache::loncoursedata::get_classlist();
6732: my %idmap=&username_to_idmap($classlist);
6733:
6734: #get scantron line setup
1.257 albertel 6735: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 6736: my ($scanlines,$scan_data)=&scantron_getfile();
1.582 raeburn 6737:
6738: my $nav_error;
6739: &scantron_get_maxbubble(\$nav_error); # parse needs the bubble_lines.. array.
6740: if ($nav_error) {
6741: $r->print(&navmap_errormsg());
6742: return(1,$currentphase);
6743: }
1.157 albertel 6744:
6745: my %found=('ids'=>{},'usernames'=>{});
6746: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 6747: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 6748: if ($line=~/^[\s\cz]*$/) { next; }
6749: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
6750: $scan_data);
6751: my $id=$$scan_record{'scantron.ID'};
6752: my $found;
6753: foreach my $checkid (keys(%idmap)) {
6754: if (lc($checkid) eq lc($id)) { $found=$checkid;last; }
6755: }
6756: if ($found) {
6757: my $username=$idmap{$found};
6758: if ($found{'ids'}{$found}) {
6759: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
6760: $line,'duplicateID',$found);
1.194 albertel 6761: return(1,$currentphase);
1.157 albertel 6762: } elsif ($found{'usernames'}{$username}) {
6763: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
6764: $line,'duplicateID',$username);
1.194 albertel 6765: return(1,$currentphase);
1.157 albertel 6766: }
1.186 albertel 6767: #FIXME store away line we previously saw the ID on to use above
1.157 albertel 6768: $found{'ids'}{$found}++;
6769: $found{'usernames'}{$username}++;
6770: } else {
6771: if ($id =~ /^\s*$/) {
1.158 albertel 6772: my $username=&scan_data($scan_data,"$i.user");
1.157 albertel 6773: if (defined($username) && $found{'usernames'}{$username}) {
6774: &scantron_get_correction($r,$i,$scan_record,
6775: \%scantron_config,
6776: $line,'duplicateID',$username);
1.194 albertel 6777: return(1,$currentphase);
1.157 albertel 6778: } elsif (!defined($username)) {
6779: &scantron_get_correction($r,$i,$scan_record,
6780: \%scantron_config,
6781: $line,'incorrectID');
1.194 albertel 6782: return(1,$currentphase);
1.157 albertel 6783: }
6784: $found{'usernames'}{$username}++;
6785: } else {
6786: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
6787: $line,'incorrectID');
1.194 albertel 6788: return(1,$currentphase);
1.157 albertel 6789: }
6790: }
6791: }
6792:
6793: return (0,$currentphase+1);
6794: }
6795:
1.423 albertel 6796:
1.157 albertel 6797: sub scantron_get_correction {
6798: my ($r,$i,$scan_record,$scan_config,$line,$error,$arg)=@_;
1.454 banghart 6799: #FIXME in the case of a duplicated ID the previous line, probably need
1.157 albertel 6800: #to show both the current line and the previous one and allow skipping
6801: #the previous one or the current one
6802:
1.333 albertel 6803: if ( $$scan_record{'scantron.PaperID'} =~ /\S/) {
1.492 albertel 6804: $r->print("<p>".&mt("<b>An error was detected ($error)</b>".
6805: " for PaperID <tt>[_1]</tt>",
6806: $$scan_record{'scantron.PaperID'})."</p> \n");
1.157 albertel 6807: } else {
1.492 albertel 6808: $r->print("<p>".&mt("<b>An error was detected ($error)</b>".
6809: " in scanline [_1] <pre>[_2]</pre>",
6810: $i,$line)."</p> \n");
6811: }
6812: my $message="<p>".&mt("The ID on the form is <tt>[_1]</tt><br />".
6813: "The name on the paper is [_2],[_3]",
6814: $$scan_record{'scantron.ID'},
6815: $$scan_record{'scantron.LastName'},
6816: $$scan_record{'scantron.FirstName'})."</p>";
1.242 albertel 6817:
1.157 albertel 6818: $r->print('<input type="hidden" name="scantron_corrections" value="'.$error.'" />'."\n");
6819: $r->print('<input type="hidden" name="scantron_line" value="'.$i.'" />'."\n");
1.503 raeburn 6820: # Array populated for doublebubble or
6821: my @lines_to_correct; # missingbubble errors to build javascript
6822: # to validate radio button checking
6823:
1.157 albertel 6824: if ($error =~ /ID$/) {
1.186 albertel 6825: if ($error eq 'incorrectID') {
1.492 albertel 6826: $r->print("<p>".&mt("The encoded ID is not in the classlist").
6827: "</p>\n");
1.157 albertel 6828: } elsif ($error eq 'duplicateID') {
1.492 albertel 6829: $r->print("<p>".&mt("The encoded ID has also been used by a previous paper [_1]",$arg)."</p>\n");
1.157 albertel 6830: }
1.242 albertel 6831: $r->print($message);
1.492 albertel 6832: $r->print("<p>".&mt("How should I handle this?")." <br /> \n");
1.157 albertel 6833: $r->print("\n<ul><li> ");
6834: #FIXME it would be nice if this sent back the user ID and
6835: #could do partial userID matches
6836: $r->print(&Apache::loncommon::selectstudent_link('scantronupload',
6837: 'scantron_username','scantron_domain'));
6838: $r->print(": <input type='text' name='scantron_username' value='' />");
6839: $r->print("\n@".
1.257 albertel 6840: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'scantron_domain'));
1.157 albertel 6841:
6842: $r->print('</li>');
1.186 albertel 6843: } elsif ($error =~ /CODE$/) {
6844: if ($error eq 'incorrectCODE') {
1.492 albertel 6845: $r->print("<p>".&mt("The encoded CODE is not in the list of possible CODEs.")."</p>\n");
1.186 albertel 6846: } elsif ($error eq 'duplicateCODE') {
1.492 albertel 6847: $r->print("<p>".&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 6848: }
1.492 albertel 6849: $r->print("<p>".&mt("The CODE on the form is <tt>'[_1]'</tt>",
6850: $$scan_record{'scantron.CODE'})."<br />\n");
1.242 albertel 6851: $r->print($message);
1.492 albertel 6852: $r->print("<p>".&mt("How should I handle this?")." <br /> \n");
1.187 albertel 6853: $r->print("\n<br /> ");
1.194 albertel 6854: my $i=0;
1.273 albertel 6855: if ($error eq 'incorrectCODE'
6856: && $$scan_record{'scantron.CODE'}=~/\S/ ) {
1.194 albertel 6857: my ($max,$closest)=&scantron_get_closely_matching_CODEs($arg,$$scan_record{'scantron.CODE'});
1.278 albertel 6858: if ($closest > 0) {
6859: foreach my $testcode (@{$closest}) {
6860: my $checked='';
1.569 bisitz 6861: if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 6862: $r->print("
6863: <label>
1.569 bisitz 6864: <input type='radio' name='scantron_CODE_resolution' value='use_closest_$i'$checked />
1.492 albertel 6865: ".&mt("Use the similar CODE [_1] instead.",
6866: "<b><tt>".$testcode."</tt></b>")."
6867: </label>
6868: <input type='hidden' name='scantron_CODE_closest_$i' value='$testcode' />");
1.278 albertel 6869: $r->print("\n<br />");
6870: $i++;
6871: }
1.194 albertel 6872: }
6873: }
1.273 albertel 6874: if ($$scan_record{'scantron.CODE'}=~/\S/ ) {
1.569 bisitz 6875: my $checked; if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 6876: $r->print("
6877: <label>
1.569 bisitz 6878: <input type='radio' name='scantron_CODE_resolution' value='use_unfound'$checked />
1.492 albertel 6879: ".&mt("Use the CODE [_1] that is was on the paper, ignoring the error.",
6880: "<b><tt>".$$scan_record{'scantron.CODE'}."</tt></b>")."
6881: </label>");
1.273 albertel 6882: $r->print("\n<br />");
6883: }
1.194 albertel 6884:
1.597 wenzelju 6885: $r->print(&Apache::lonhtmlcommon::scripttag(<<ENDSCRIPT));
1.188 albertel 6886: function change_radio(field) {
1.190 albertel 6887: var slct=document.scantronupload.scantron_CODE_resolution;
1.188 albertel 6888: var i;
6889: for (i=0;i<slct.length;i++) {
6890: if (slct[i].value==field) { slct[i].checked=true; }
6891: }
6892: }
6893: ENDSCRIPT
1.187 albertel 6894: my $href="/adm/pickcode?".
1.359 www 6895: "form=".&escape("scantronupload").
6896: "&scantron_format=".&escape($env{'form.scantron_format'}).
6897: "&scantron_CODElist=".&escape($env{'form.scantron_CODElist'}).
6898: "&curCODE=".&escape($$scan_record{'scantron.CODE'}).
6899: "&scantron_selectfile=".&escape($env{'form.scantron_selectfile'});
1.332 albertel 6900: if ($env{'form.scantron_CODElist'} =~ /\S/) {
1.492 albertel 6901: $r->print("
6902: <label>
6903: <input type='radio' name='scantron_CODE_resolution' value='use_found' />
6904: ".&mt("[_1]Select[_2] a CODE from the list of all CODEs and use it.",
6905: "<a target='_blank' href='$href'>","</a>")."
6906: </label>
1.558 bisitz 6907: ".&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 6908: $r->print("\n<br />");
6909: }
1.492 albertel 6910: $r->print("
6911: <label>
6912: <input type='radio' name='scantron_CODE_resolution' value='use_typed' />
6913: ".&mt("Use [_1] as the CODE.",
6914: "</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 6915: $r->print("\n<br /><br />");
1.157 albertel 6916: } elsif ($error eq 'doublebubble') {
1.503 raeburn 6917: $r->print("<p>".&mt("There have been multiple bubbles scanned for some question(s)")."</p>\n");
1.497 foxr 6918:
6919: # The form field scantron_questions is acutally a list of line numbers.
6920: # represented by this form so:
6921:
6922: my $line_list = &questions_to_line_list($arg);
6923:
1.157 albertel 6924: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 6925: $line_list.'" />');
1.242 albertel 6926: $r->print($message);
1.492 albertel 6927: $r->print("<p>".&mt("Please indicate which bubble should be used for grading")."</p>");
1.157 albertel 6928: foreach my $question (@{$arg}) {
1.503 raeburn 6929: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
6930: $scan_record, $error);
1.524 raeburn 6931: push(@lines_to_correct,@linenums);
1.157 albertel 6932: }
1.503 raeburn 6933: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 6934: } elsif ($error eq 'missingbubble') {
1.492 albertel 6935: $r->print("<p>".&mt("There have been <b>no</b> bubbles scanned for some question(s)")."</p>\n");
1.242 albertel 6936: $r->print($message);
1.492 albertel 6937: $r->print("<p>".&mt("Please indicate which bubble should be used for grading.")."</p>");
1.503 raeburn 6938: $r->print(&mt("Some questions have no scanned bubbles.")."\n");
1.497 foxr 6939:
1.503 raeburn 6940: # The form field scantron_questions is actually a list of line numbers not
1.497 foxr 6941: # a list of question numbers. Therefore:
6942: #
6943:
6944: my $line_list = &questions_to_line_list($arg);
6945:
1.157 albertel 6946: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 6947: $line_list.'" />');
1.157 albertel 6948: foreach my $question (@{$arg}) {
1.503 raeburn 6949: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
6950: $scan_record, $error);
1.524 raeburn 6951: push(@lines_to_correct,@linenums);
1.157 albertel 6952: }
1.503 raeburn 6953: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 6954: } else {
6955: $r->print("\n<ul>");
6956: }
6957: $r->print("\n</li></ul>");
1.497 foxr 6958: }
6959:
1.503 raeburn 6960: sub verify_bubbles_checked {
6961: my (@ansnums) = @_;
6962: my $ansnumstr = join('","',@ansnums);
6963: my $warning = &mt("A bubble or 'No bubble' selection has not been made for one or more lines.");
1.597 wenzelju 6964: my $output = &Apache::lonhtmlcommon::scripttag((<<ENDSCRIPT));
1.503 raeburn 6965: function verify_bubble_radio(form) {
6966: var ansnumArray = new Array ("$ansnumstr");
6967: var need_bubble_count = 0;
6968: for (var i=0; i<ansnumArray.length; i++) {
6969: if (form.elements["scantron_correct_Q_"+ansnumArray[i]].length > 1) {
6970: var bubble_picked = 0;
6971: for (var j=0; j<form.elements["scantron_correct_Q_"+ansnumArray[i]].length; j++) {
6972: if (form.elements["scantron_correct_Q_"+ansnumArray[i]][j].checked == true) {
6973: bubble_picked = 1;
6974: }
6975: }
6976: if (bubble_picked == 0) {
6977: need_bubble_count ++;
6978: }
6979: }
6980: }
6981: if (need_bubble_count) {
6982: alert("$warning");
6983: return;
6984: }
6985: form.submit();
6986: }
6987: ENDSCRIPT
6988: return $output;
6989: }
6990:
1.497 foxr 6991: =pod
6992:
6993: =item questions_to_line_list
1.157 albertel 6994:
1.497 foxr 6995: Converts a list of questions into a string of comma separated
6996: line numbers in the answer sheet used by the questions. This is
6997: used to fill in the scantron_questions form field.
6998:
6999: Arguments:
7000: questions - Reference to an array of questions.
7001:
7002: =cut
7003:
7004:
7005: sub questions_to_line_list {
7006: my ($questions) = @_;
7007: my @lines;
7008:
1.503 raeburn 7009: foreach my $item (@{$questions}) {
7010: my $question = $item;
7011: my ($first,$count,$last);
7012: if ($item =~ /^(\d+)\.(\d+)$/) {
7013: $question = $1;
7014: my $subquestion = $2;
7015: $first = $first_bubble_line{$question-1} + 1;
7016: my @subans = split(/,/,$subdivided_bubble_lines{$question-1});
7017: my $subcount = 1;
7018: while ($subcount<$subquestion) {
7019: $first += $subans[$subcount-1];
7020: $subcount ++;
7021: }
7022: $count = $subans[$subquestion-1];
7023: } else {
7024: $first = $first_bubble_line{$question-1} + 1;
7025: $count = $bubble_lines_per_response{$question-1};
7026: }
1.506 raeburn 7027: $last = $first+$count-1;
1.503 raeburn 7028: push(@lines, ($first..$last));
1.497 foxr 7029: }
7030: return join(',', @lines);
7031: }
7032:
7033: =pod
7034:
7035: =item prompt_for_corrections
7036:
7037: Prompts for a potentially multiline correction to the
7038: user's bubbling (factors out common code from scantron_get_correction
7039: for multi and missing bubble cases).
7040:
7041: Arguments:
7042: $r - Apache request object.
7043: $question - The question number to prompt for.
7044: $scan_config - The scantron file configuration hash.
7045: $scan_record - Reference to the hash that has the the parsed scanlines.
1.503 raeburn 7046: $error - Type of error
1.497 foxr 7047:
7048: Implicit inputs:
7049: %bubble_lines_per_response - Starting line numbers for each question.
7050: Numbered from 0 (but question numbers are from
7051: 1.
7052: %first_bubble_line - Starting bubble line for each question.
1.509 raeburn 7053: %subdivided_bubble_lines - optionresponse, matchresponse and rankresponse
7054: type problems render as separate sub-questions,
1.503 raeburn 7055: in exam mode. This hash contains a
7056: comma-separated list of the lines per
7057: sub-question.
1.510 raeburn 7058: %responsetype_per_response - essayresponse, formularesponse,
7059: stringresponse, imageresponse, reactionresponse,
7060: and organicresponse type problem parts can have
1.503 raeburn 7061: multiple lines per response if the weight
7062: assigned exceeds 10. In this case, only
7063: one bubble per line is permitted, but more
7064: than one line might contain bubbles, e.g.
7065: bubbling of: line 1 - J, line 2 - J,
7066: line 3 - B would assign 22 points.
1.497 foxr 7067:
7068: =cut
7069:
7070: sub prompt_for_corrections {
1.503 raeburn 7071: my ($r, $question, $scan_config, $scan_record, $error) = @_;
7072: my ($current_line,$lines);
7073: my @linenums;
7074: my $questionnum = $question;
7075: if ($question =~ /^(\d+)\.(\d+)$/) {
7076: $question = $1;
7077: $current_line = $first_bubble_line{$question-1} + 1 ;
7078: my $subquestion = $2;
7079: my @subans = split(/,/,$subdivided_bubble_lines{$question-1});
7080: my $subcount = 1;
7081: while ($subcount<$subquestion) {
7082: $current_line += $subans[$subcount-1];
7083: $subcount ++;
7084: }
7085: $lines = $subans[$subquestion-1];
7086: } else {
7087: $current_line = $first_bubble_line{$question-1} + 1 ;
7088: $lines = $bubble_lines_per_response{$question-1};
7089: }
1.497 foxr 7090: if ($lines > 1) {
1.503 raeburn 7091: $r->print(&mt('The group of bubble lines below responds to a single question.').'<br />');
7092: if (($responsetype_per_response{$question-1} eq 'essayresponse') ||
7093: ($responsetype_per_response{$question-1} eq 'formularesponse') ||
1.510 raeburn 7094: ($responsetype_per_response{$question-1} eq 'stringresponse') ||
7095: ($responsetype_per_response{$question-1} eq 'imageresponse') ||
7096: ($responsetype_per_response{$question-1} eq 'reactionresponse') ||
7097: ($responsetype_per_response{$question-1} eq 'organicresponse')) {
1.572 www 7098: $r->print(&mt("Although this particular question type requires handgrading, the instructions for this question in the exam directed students to leave [quant,_1,line] blank on their bubblesheets.",$lines).'<br /><br />'.&mt('A non-zero score can be assigned to the student during bubblesheet grading by selecting a bubble in at least one line.').'<br />'.&mt('The score for this question will be a sum of the numeric values for the selected bubbles from each line, where A=1 point, B=2 points etc.').'<br />'.&mt("To assign a score of zero for this question, mark all lines as 'No bubble'.").'<br /><br />');
1.503 raeburn 7099: } else {
7100: $r->print(&mt("Select at most one bubble in a single line and select 'No Bubble' in all the other lines. ")."<br />");
7101: }
1.497 foxr 7102: }
7103: for (my $i =0; $i < $lines; $i++) {
1.503 raeburn 7104: my $selected = $$scan_record{"scantron.$current_line.answer"};
7105: &scantron_bubble_selector($r,$scan_config,$current_line,
7106: $questionnum,$error,split('', $selected));
1.524 raeburn 7107: push(@linenums,$current_line);
1.497 foxr 7108: $current_line++;
7109: }
7110: if ($lines > 1) {
7111: $r->print("<hr /><br />");
7112: }
1.503 raeburn 7113: return @linenums;
1.157 albertel 7114: }
1.423 albertel 7115:
7116: =pod
7117:
7118: =item scantron_bubble_selector
7119:
7120: Generates the html radiobuttons to correct a single bubble line
1.424 albertel 7121: possibly showing the existing the selected bubbles if known
1.423 albertel 7122:
7123: Arguments:
7124: $r - Apache request object
7125: $scan_config - hash from &get_scantron_config()
1.497 foxr 7126: $line - Number of the line being displayed.
1.503 raeburn 7127: $questionnum - Question number (may include subquestion)
7128: $error - Type of error.
1.497 foxr 7129: @selected - Array of bubbles picked on this line.
1.423 albertel 7130:
7131: =cut
7132:
1.157 albertel 7133: sub scantron_bubble_selector {
1.503 raeburn 7134: my ($r,$scan_config,$line,$questionnum,$error,@selected)=@_;
1.157 albertel 7135: my $max=$$scan_config{'Qlength'};
1.274 albertel 7136:
7137: my $scmode=$$scan_config{'Qon'};
7138: if ($scmode eq 'number' || $scmode eq 'letter') { $max=10; }
7139:
1.157 albertel 7140: my @alphabet=('A'..'Z');
1.503 raeburn 7141: $r->print(&Apache::loncommon::start_data_table().
7142: &Apache::loncommon::start_data_table_row());
7143: $r->print('<td rowspan="2" class="LC_leftcol_header">'.$line.'</td>');
1.497 foxr 7144: for (my $i=0;$i<$max+1;$i++) {
7145: $r->print("\n".'<td align="center">');
7146: if ($selected[0] eq $alphabet[$i]) { $r->print('X'); shift(@selected) }
7147: else { $r->print(' '); }
7148: $r->print('</td>');
7149: }
1.503 raeburn 7150: $r->print(&Apache::loncommon::end_data_table_row().
7151: &Apache::loncommon::start_data_table_row());
1.497 foxr 7152: for (my $i=0;$i<$max;$i++) {
7153: $r->print("\n".
7154: '<td><label><input type="radio" name="scantron_correct_Q_'.
7155: $line.'" value="'.$i.'" />'.$alphabet[$i]."</label></td>");
7156: }
1.503 raeburn 7157: my $nobub_checked = ' ';
7158: if ($error eq 'missingbubble') {
7159: $nobub_checked = ' checked = "checked" ';
7160: }
7161: $r->print("\n".'<td><label><input type="radio" name="scantron_correct_Q_'.
7162: $line.'" value="none"'.$nobub_checked.'/>'.&mt('No bubble').
7163: '</label>'."\n".'<input type="hidden" name="scantron_questionnum_Q_'.
7164: $line.'" value="'.$questionnum.'" /></td>');
7165: $r->print(&Apache::loncommon::end_data_table_row().
7166: &Apache::loncommon::end_data_table());
1.157 albertel 7167: }
7168:
1.423 albertel 7169: =pod
7170:
7171: =item num_matches
7172:
1.424 albertel 7173: Counts the number of characters that are the same between the two arguments.
7174:
7175: Arguments:
7176: $orig - CODE from the scanline
7177: $code - CODE to match against
7178:
7179: Returns:
7180: $count - integer count of the number of same characters between the
7181: two arguments
7182:
1.423 albertel 7183: =cut
7184:
1.194 albertel 7185: sub num_matches {
7186: my ($orig,$code) = @_;
7187: my @code=split(//,$code);
7188: my @orig=split(//,$orig);
7189: my $same=0;
7190: for (my $i=0;$i<scalar(@code);$i++) {
7191: if ($code[$i] eq $orig[$i]) { $same++; }
7192: }
7193: return $same;
7194: }
7195:
1.423 albertel 7196: =pod
7197:
7198: =item scantron_get_closely_matching_CODEs
7199:
1.424 albertel 7200: Cycles through all CODEs and finds the set that has the greatest
7201: number of same characters as the provided CODE
7202:
7203: Arguments:
7204: $allcodes - hash ref returned by &get_codes()
7205: $CODE - CODE from the current scanline
7206:
7207: Returns:
7208: 2 element list
7209: - first elements is number of how closely matching the best fit is
7210: (5 means best set has 5 matching characters)
7211: - second element is an arrary ref containing the set of valid CODEs
7212: that best fit the passed in CODE
7213:
1.423 albertel 7214: =cut
7215:
1.194 albertel 7216: sub scantron_get_closely_matching_CODEs {
7217: my ($allcodes,$CODE)=@_;
7218: my @CODEs;
7219: foreach my $testcode (sort(keys(%{$allcodes}))) {
7220: push(@{$CODEs[&num_matches($CODE,$testcode)]},$testcode);
7221: }
7222:
7223: return ($#CODEs,$CODEs[-1]);
7224: }
7225:
1.423 albertel 7226: =pod
7227:
7228: =item get_codes
7229:
1.424 albertel 7230: Builds a hash which has keys of all of the valid CODEs from the selected
7231: set of remembered CODEs.
7232:
7233: Arguments:
7234: $old_name - name of the set of remembered CODEs
7235: $cdom - domain of the course
7236: $cnum - internal course name
7237:
7238: Returns:
7239: %allcodes - keys are the valid CODEs, values are all 1
7240:
1.423 albertel 7241: =cut
7242:
1.194 albertel 7243: sub get_codes {
1.280 foxr 7244: my ($old_name, $cdom, $cnum) = @_;
7245: if (!$old_name) {
7246: $old_name=$env{'form.scantron_CODElist'};
7247: }
7248: if (!$cdom) {
7249: $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
7250: }
7251: if (!$cnum) {
7252: $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
7253: }
1.278 albertel 7254: my %result=&Apache::lonnet::get('CODEs',[$old_name,"type\0$old_name"],
7255: $cdom,$cnum);
7256: my %allcodes;
7257: if ($result{"type\0$old_name"} eq 'number') {
7258: %allcodes=map {($_,1)} split(',',$result{$old_name});
7259: } else {
7260: %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
7261: }
1.194 albertel 7262: return %allcodes;
7263: }
7264:
1.423 albertel 7265: =pod
7266:
7267: =item scantron_validate_CODE
7268:
1.424 albertel 7269: Validates all scanlines in the selected file to not have any
7270: invalid or underspecified CODEs and that none of the codes are
7271: duplicated if this was requested.
7272:
1.423 albertel 7273: =cut
7274:
1.157 albertel 7275: sub scantron_validate_CODE {
7276: my ($r,$currentphase) = @_;
1.257 albertel 7277: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.186 albertel 7278: if ($scantron_config{'CODElocation'} &&
7279: $scantron_config{'CODEstart'} &&
7280: $scantron_config{'CODElength'}) {
1.257 albertel 7281: if (!defined($env{'form.scantron_CODElist'})) {
1.186 albertel 7282: &FIXME_blow_up()
7283: }
7284: } else {
7285: return (0,$currentphase+1);
7286: }
7287:
7288: my %usedCODEs;
7289:
1.194 albertel 7290: my %allcodes=&get_codes();
1.186 albertel 7291:
1.582 raeburn 7292: my $nav_error;
7293: &scantron_get_maxbubble(\$nav_error); # parse needs the lines per response array.
7294: if ($nav_error) {
7295: $r->print(&navmap_errormsg());
7296: return(1,$currentphase);
7297: }
1.447 foxr 7298:
1.186 albertel 7299: my ($scanlines,$scan_data)=&scantron_getfile();
7300: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7301: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.186 albertel 7302: if ($line=~/^[\s\cz]*$/) { next; }
7303: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7304: $scan_data);
7305: my $CODE=$$scan_record{'scantron.CODE'};
7306: my $error=0;
1.224 albertel 7307: if (!&Apache::lonnet::validCODE($CODE)) {
7308: &scantron_get_correction($r,$i,$scan_record,
7309: \%scantron_config,
7310: $line,'incorrectCODE',\%allcodes);
7311: return(1,$currentphase);
7312: }
1.221 albertel 7313: if (%allcodes && !exists($allcodes{$CODE})
7314: && !$$scan_record{'scantron.useCODE'}) {
1.186 albertel 7315: &scantron_get_correction($r,$i,$scan_record,
7316: \%scantron_config,
1.194 albertel 7317: $line,'incorrectCODE',\%allcodes);
7318: return(1,$currentphase);
1.186 albertel 7319: }
1.214 albertel 7320: if (exists($usedCODEs{$CODE})
1.257 albertel 7321: && $env{'form.scantron_CODEunique'} eq 'yes'
1.192 albertel 7322: && !$$scan_record{'scantron.CODE_ignore_dup'}) {
1.186 albertel 7323: &scantron_get_correction($r,$i,$scan_record,
7324: \%scantron_config,
1.194 albertel 7325: $line,'duplicateCODE',$usedCODEs{$CODE});
7326: return(1,$currentphase);
1.186 albertel 7327: }
1.524 raeburn 7328: push(@{$usedCODEs{$CODE}},$$scan_record{'scantron.PaperID'});
1.186 albertel 7329: }
1.157 albertel 7330: return (0,$currentphase+1);
7331: }
7332:
1.423 albertel 7333: =pod
7334:
7335: =item scantron_validate_doublebubble
7336:
1.424 albertel 7337: Validates all scanlines in the selected file to not have any
7338: bubble lines with multiple bubbles marked.
7339:
1.423 albertel 7340: =cut
7341:
1.157 albertel 7342: sub scantron_validate_doublebubble {
7343: my ($r,$currentphase) = @_;
7344: #get student info
7345: my $classlist=&Apache::loncoursedata::get_classlist();
7346: my %idmap=&username_to_idmap($classlist);
7347:
7348: #get scantron line setup
1.257 albertel 7349: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7350: my ($scanlines,$scan_data)=&scantron_getfile();
1.583 raeburn 7351: my $nav_error;
7352: &scantron_get_maxbubble(\$nav_error); # parse needs the bubble line array.
7353: if ($nav_error) {
7354: $r->print(&navmap_errormsg());
7355: return(1,$currentphase);
7356: }
1.447 foxr 7357:
1.157 albertel 7358: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7359: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7360: if ($line=~/^[\s\cz]*$/) { next; }
7361: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7362: $scan_data);
7363: if (!defined($$scan_record{'scantron.doubleerror'})) { next; }
7364: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,$line,
7365: 'doublebubble',
7366: $$scan_record{'scantron.doubleerror'});
7367: return (1,$currentphase);
7368: }
7369: return (0,$currentphase+1);
7370: }
7371:
1.423 albertel 7372:
1.503 raeburn 7373: sub scantron_get_maxbubble {
1.582 raeburn 7374: my ($nav_error) = @_;
1.257 albertel 7375: if (defined($env{'form.scantron_maxbubble'}) &&
7376: $env{'form.scantron_maxbubble'}) {
1.447 foxr 7377: &restore_bubble_lines();
1.257 albertel 7378: return $env{'form.scantron_maxbubble'};
1.191 albertel 7379: }
1.330 albertel 7380:
1.447 foxr 7381: my (undef, undef, $sequence) =
1.257 albertel 7382: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.330 albertel 7383:
1.447 foxr 7384: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 7385: unless (ref($navmap)) {
7386: if (ref($nav_error)) {
7387: $$nav_error = 1;
7388: }
1.591 raeburn 7389: return;
1.582 raeburn 7390: }
1.191 albertel 7391: my $map=$navmap->getResourceByUrl($sequence);
7392: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.330 albertel 7393:
7394: &Apache::lonxml::clear_problem_counter();
7395:
1.557 raeburn 7396: my $uname = $env{'user.name'};
7397: my $udom = $env{'user.domain'};
1.435 foxr 7398: my $cid = $env{'request.course.id'};
7399: my $total_lines = 0;
7400: %bubble_lines_per_response = ();
1.447 foxr 7401: %first_bubble_line = ();
1.503 raeburn 7402: %subdivided_bubble_lines = ();
7403: %responsetype_per_response = ();
1.554 raeburn 7404:
1.447 foxr 7405: my $response_number = 0;
7406: my $bubble_line = 0;
1.191 albertel 7407: foreach my $resource (@resources) {
1.542 raeburn 7408: my ($analysis,$parts) = &scantron_partids_tograde($resource,$cid,$uname,$udom);
7409: if ((ref($analysis) eq 'HASH') && (ref($parts) eq 'ARRAY')) {
7410: foreach my $part_id (@{$parts}) {
7411: my $lines;
7412:
7413: # TODO - make this a persistent hash not an array.
7414:
7415: # optionresponse, matchresponse and rankresponse type items
7416: # render as separate sub-questions in exam mode.
7417: if (($analysis->{$part_id.'.type'} eq 'optionresponse') ||
7418: ($analysis->{$part_id.'.type'} eq 'matchresponse') ||
7419: ($analysis->{$part_id.'.type'} eq 'rankresponse')) {
7420: my ($numbub,$numshown);
7421: if ($analysis->{$part_id.'.type'} eq 'optionresponse') {
7422: if (ref($analysis->{$part_id.'.options'}) eq 'ARRAY') {
7423: $numbub = scalar(@{$analysis->{$part_id.'.options'}});
7424: }
7425: } elsif ($analysis->{$part_id.'.type'} eq 'matchresponse') {
7426: if (ref($analysis->{$part_id.'.items'}) eq 'ARRAY') {
7427: $numbub = scalar(@{$analysis->{$part_id.'.items'}});
7428: }
7429: } elsif ($analysis->{$part_id.'.type'} eq 'rankresponse') {
7430: if (ref($analysis->{$part_id.'.foils'}) eq 'ARRAY') {
7431: $numbub = scalar(@{$analysis->{$part_id.'.foils'}});
7432: }
7433: }
7434: if (ref($analysis->{$part_id.'.shown'}) eq 'ARRAY') {
7435: $numshown = scalar(@{$analysis->{$part_id.'.shown'}});
7436: }
7437: my $bubbles_per_line = 10;
7438: my $inner_bubble_lines = int($numbub/$bubbles_per_line);
7439: if (($numbub % $bubbles_per_line) != 0) {
7440: $inner_bubble_lines++;
7441: }
7442: for (my $i=0; $i<$numshown; $i++) {
7443: $subdivided_bubble_lines{$response_number} .=
7444: $inner_bubble_lines.',';
7445: }
7446: $subdivided_bubble_lines{$response_number} =~ s/,$//;
7447: $lines = $numshown * $inner_bubble_lines;
7448: } else {
7449: $lines = $analysis->{"$part_id.bubble_lines"};
7450: }
7451:
7452: $first_bubble_line{$response_number} = $bubble_line;
7453: $bubble_lines_per_response{$response_number} = $lines;
7454: $responsetype_per_response{$response_number} =
7455: $analysis->{$part_id.'.type'};
7456: $response_number++;
7457:
7458: $bubble_line += $lines;
7459: $total_lines += $lines;
7460: }
7461: }
7462: }
1.552 raeburn 7463: &Apache::lonnet::delenv('scantron.');
1.542 raeburn 7464:
7465: &save_bubble_lines();
7466: $env{'form.scantron_maxbubble'} =
7467: $total_lines;
7468: return $env{'form.scantron_maxbubble'};
7469: }
1.523 raeburn 7470:
1.157 albertel 7471: sub scantron_validate_missingbubbles {
7472: my ($r,$currentphase) = @_;
7473: #get student info
7474: my $classlist=&Apache::loncoursedata::get_classlist();
7475: my %idmap=&username_to_idmap($classlist);
7476:
7477: #get scantron line setup
1.257 albertel 7478: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7479: my ($scanlines,$scan_data)=&scantron_getfile();
1.582 raeburn 7480: my $nav_error;
7481: my $max_bubble=&scantron_get_maxbubble(\$nav_error);
7482: if ($nav_error) {
7483: return(1,$currentphase);
7484: }
1.157 albertel 7485: if (!$max_bubble) { $max_bubble=2**31; }
7486: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7487: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7488: if ($line=~/^[\s\cz]*$/) { next; }
7489: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7490: $scan_data);
7491: if (!defined($$scan_record{'scantron.missingerror'})) { next; }
7492: my @to_correct;
1.470 foxr 7493:
7494: # Probably here's where the error is...
7495:
1.157 albertel 7496: foreach my $missing (@{$$scan_record{'scantron.missingerror'}}) {
1.505 raeburn 7497: my $lastbubble;
7498: if ($missing =~ /^(\d+)\.(\d+)$/) {
7499: my $question = $1;
7500: my $subquestion = $2;
7501: if (!defined($first_bubble_line{$question -1})) { next; }
7502: my $first = $first_bubble_line{$question-1};
7503: my @subans = split(/,/,$subdivided_bubble_lines{$question-1});
7504: my $subcount = 1;
7505: while ($subcount<$subquestion) {
7506: $first += $subans[$subcount-1];
7507: $subcount ++;
7508: }
7509: my $count = $subans[$subquestion-1];
7510: $lastbubble = $first + $count;
7511: } else {
7512: if (!defined($first_bubble_line{$missing - 1})) { next; }
7513: $lastbubble = $first_bubble_line{$missing - 1} + $bubble_lines_per_response{$missing - 1};
7514: }
7515: if ($lastbubble > $max_bubble) { next; }
1.157 albertel 7516: push(@to_correct,$missing);
7517: }
7518: if (@to_correct) {
7519: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
7520: $line,'missingbubble',\@to_correct);
7521: return (1,$currentphase);
7522: }
7523:
7524: }
7525: return (0,$currentphase+1);
7526: }
7527:
1.423 albertel 7528:
1.82 albertel 7529: sub scantron_process_students {
1.608 www 7530: my ($r,$symb) = @_;
1.513 foxr 7531:
1.257 albertel 7532: my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($env{'form.selectpage'});
1.513 foxr 7533: if (!$symb) {
7534: return '';
7535: }
1.324 albertel 7536: my $default_form_data=&defaultFormData($symb);
1.82 albertel 7537:
1.257 albertel 7538: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7539: my ($scanlines,$scan_data)=&scantron_getfile();
1.82 albertel 7540: my $classlist=&Apache::loncoursedata::get_classlist();
7541: my %idmap=&username_to_idmap($classlist);
1.132 bowersj2 7542: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 7543: unless (ref($navmap)) {
7544: $r->print(&navmap_errormsg());
7545: return '';
7546: }
1.83 albertel 7547: my $map=$navmap->getResourceByUrl($sequence);
7548: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.557 raeburn 7549: my (%grader_partids_by_symb,%grader_randomlists_by_symb);
7550: &graders_resources_pass(\@resources,\%grader_partids_by_symb,
7551: \%grader_randomlists_by_symb);
1.586 raeburn 7552: my $resource_error;
1.557 raeburn 7553: foreach my $resource (@resources) {
1.586 raeburn 7554: my $ressymb;
7555: if (ref($resource)) {
7556: $ressymb = $resource->symb();
7557: } else {
7558: $resource_error = 1;
7559: last;
7560: }
1.557 raeburn 7561: my ($analysis,$parts) =
7562: &scantron_partids_tograde($resource,$env{'request.course.id'},
7563: $env{'user.name'},$env{'user.domain'},1);
7564: $grader_partids_by_symb{$ressymb} = $parts;
7565: if (ref($analysis) eq 'HASH') {
7566: if (ref($analysis->{'parts_withrandomlist'}) eq 'ARRAY') {
7567: $grader_randomlists_by_symb{$ressymb} =
7568: $analysis->{'parts_withrandomlist'};
7569: }
7570: }
7571: }
1.586 raeburn 7572: if ($resource_error) {
7573: $r->print(&navmap_errormsg());
7574: return '';
7575: }
1.557 raeburn 7576:
1.554 raeburn 7577: my ($uname,$udom);
1.82 albertel 7578: my $result= <<SCANTRONFORM;
1.81 albertel 7579: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
7580: <input type="hidden" name="command" value="scantron_configphase" />
7581: $default_form_data
7582: SCANTRONFORM
1.82 albertel 7583: $r->print($result);
7584:
7585: my @delayqueue;
1.542 raeburn 7586: my (%completedstudents,%scandata);
1.140 albertel 7587:
1.520 www 7588: my $lock=&Apache::lonnet::set_lock(&mt('Grading bubblesheet exam'));
1.200 albertel 7589: my $count=&get_todo_count($scanlines,$scan_data);
1.575 www 7590: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Bubblesheet Status',
7591: 'Bubblesheet Progress',$count,
1.195 albertel 7592: 'inline',undef,'scantronupload');
1.140 albertel 7593: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
7594: 'Processing first student');
1.542 raeburn 7595: $r->print('<br />');
1.140 albertel 7596: my $start=&Time::HiRes::time();
1.158 albertel 7597: my $i=-1;
1.542 raeburn 7598: my $started;
1.447 foxr 7599:
1.582 raeburn 7600: my $nav_error;
7601: &scantron_get_maxbubble(\$nav_error); # Need the bubble lines array to parse.
7602: if ($nav_error) {
7603: $r->print(&navmap_errormsg());
7604: return '';
7605: }
7606:
1.513 foxr 7607: # If an ssi failed in scantron_get_maxbubble, put an error message out to
7608: # the user and return.
7609:
7610: if ($ssi_error) {
7611: $r->print("</form>");
7612: &ssi_print_error($r);
1.520 www 7613: &Apache::lonnet::remove_lock($lock);
1.513 foxr 7614: return ''; # Dunno why the other returns return '' rather than just returning.
7615: }
1.447 foxr 7616:
1.542 raeburn 7617: my %lettdig = &letter_to_digits();
7618: my $numletts = scalar(keys(%lettdig));
7619:
1.157 albertel 7620: while ($i<$scanlines->{'count'}) {
7621: ($uname,$udom)=('','');
7622: $i++;
1.200 albertel 7623: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7624: if ($line=~/^[\s\cz]*$/) { next; }
1.200 albertel 7625: if ($started) {
7626: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
7627: 'last student');
7628: }
7629: $started=1;
1.157 albertel 7630: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7631: $scan_data);
7632: unless ($uname=&scantron_find_student($scan_record,$scan_data,
7633: \%idmap,$i)) {
7634: &scantron_add_delay(\@delayqueue,$line,
7635: 'Unable to find a student that matches',1);
7636: next;
7637: }
7638: if (exists $completedstudents{$uname}) {
7639: &scantron_add_delay(\@delayqueue,$line,
7640: 'Student '.$uname.' has multiple sheets',2);
7641: next;
7642: }
7643: ($uname,$udom)=split(/:/,$uname);
1.330 albertel 7644:
1.586 raeburn 7645: my (%partids_by_symb,$res_error);
1.554 raeburn 7646: foreach my $resource (@resources) {
1.586 raeburn 7647: my $ressymb;
7648: if (ref($resource)) {
7649: $ressymb = $resource->symb();
7650: } else {
7651: $res_error = 1;
7652: last;
7653: }
1.557 raeburn 7654: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
7655: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
7656: my ($analysis,$parts) =
7657: &scantron_partids_tograde($resource,$env{'request.course.id'},$uname,$udom);
7658: $partids_by_symb{$ressymb} = $parts;
7659: } else {
7660: $partids_by_symb{$ressymb} = $grader_partids_by_symb{$ressymb};
7661: }
1.554 raeburn 7662: }
7663:
1.586 raeburn 7664: if ($res_error) {
7665: &scantron_add_delay(\@delayqueue,$line,
7666: 'An error occurred while grading student '.$uname,2);
7667: next;
7668: }
7669:
1.330 albertel 7670: &Apache::lonxml::clear_problem_counter();
1.514 raeburn 7671: &Apache::lonnet::appenv($scan_record);
1.376 albertel 7672:
7673: if (&scantron_clear_skip($scanlines,$scan_data,$i)) {
7674: &scantron_putfile($scanlines,$scan_data);
7675: }
1.161 albertel 7676:
1.542 raeburn 7677: my $scancode;
7678: if ((exists($scan_record->{'scantron.CODE'})) &&
7679: (&Apache::lonnet::validCODE($scan_record->{'scantron.CODE'}))) {
7680: $scancode = $scan_record->{'scantron.CODE'};
7681: } else {
7682: $scancode = '';
7683: }
7684:
7685: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
1.554 raeburn 7686: \@resources,\%partids_by_symb) eq 'ssi_error') {
1.542 raeburn 7687: $ssi_error = 0; # So end of handler error message does not trigger.
7688: $r->print("</form>");
7689: &ssi_print_error($r);
7690: &Apache::lonnet::remove_lock($lock);
7691: return ''; # Why return ''? Beats me.
7692: }
1.513 foxr 7693:
1.140 albertel 7694: $completedstudents{$uname}={'line'=>$line};
1.542 raeburn 7695: if ($env{'form.verifyrecord'}) {
7696: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
7697: my $studentdata = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
7698: chomp($studentdata);
7699: $studentdata =~ s/\r$//;
7700: my $studentrecord = '';
7701: my $counter = -1;
7702: foreach my $resource (@resources) {
1.554 raeburn 7703: my $ressymb = $resource->symb();
1.542 raeburn 7704: ($counter,my $recording) =
7705: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 7706: $counter,$studentdata,$partids_by_symb{$ressymb},
1.542 raeburn 7707: \%scantron_config,\%lettdig,$numletts);
7708: $studentrecord .= $recording;
7709: }
7710: if ($studentrecord ne $studentdata) {
1.554 raeburn 7711: &Apache::lonxml::clear_problem_counter();
7712: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
7713: \@resources,\%partids_by_symb) eq 'ssi_error') {
7714: $ssi_error = 0; # So end of handler error message does not trigger.
7715: $r->print("</form>");
7716: &ssi_print_error($r);
7717: &Apache::lonnet::remove_lock($lock);
7718: delete($completedstudents{$uname});
7719: return '';
7720: }
1.542 raeburn 7721: $counter = -1;
7722: $studentrecord = '';
7723: foreach my $resource (@resources) {
1.554 raeburn 7724: my $ressymb = $resource->symb();
1.542 raeburn 7725: ($counter,my $recording) =
7726: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 7727: $counter,$studentdata,$partids_by_symb{$ressymb},
1.542 raeburn 7728: \%scantron_config,\%lettdig,$numletts);
7729: $studentrecord .= $recording;
7730: }
7731: if ($studentrecord ne $studentdata) {
7732: $r->print('<p><span class="LC_error">');
7733: if ($scancode eq '') {
7734: $r->print(&mt('Mismatch grading bubble sheet for user: [_1] with ID: [_2].',
7735: $uname.':'.$udom,$scan_record->{'scantron.ID'}));
7736: } else {
7737: $r->print(&mt('Mismatch grading bubble sheet for user: [_1] with ID: [_2] and CODE: [_3].',
7738: $uname.':'.$udom,$scan_record->{'scantron.ID'},$scancode));
7739: }
7740: $r->print('</span><br />'.&Apache::loncommon::start_data_table()."\n".
7741: &Apache::loncommon::start_data_table_header_row()."\n".
7742: '<th>'.&mt('Source').'</th><th>'.&mt('Bubbled responses').'</th>'.
7743: &Apache::loncommon::end_data_table_header_row()."\n".
7744: &Apache::loncommon::start_data_table_row().
7745: '<td>'.&mt('Bubble Sheet').'</td>'.
7746: '<td><span class="LC_nobreak">'.$studentdata.'</span></td>'.
7747: &Apache::loncommon::end_data_table_row().
7748: &Apache::loncommon::start_data_table_row().
7749: '<td>Stored submissions</td>'.
7750: '<td><span class="LC_nobreak">'.$studentrecord.'</span></td>'."\n".
7751: &Apache::loncommon::end_data_table_row().
7752: &Apache::loncommon::end_data_table().'</p>');
7753: } else {
7754: $r->print('<br /><span class="LC_warning">'.
7755: &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 />'.
7756: &mt("As a consequence, this user's submission history records two tries.").
7757: '</span><br />');
7758: }
7759: }
7760: }
1.543 raeburn 7761: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.140 albertel 7762: } continue {
1.330 albertel 7763: &Apache::lonxml::clear_problem_counter();
1.552 raeburn 7764: &Apache::lonnet::delenv('scantron.');
1.82 albertel 7765: }
1.140 albertel 7766: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.520 www 7767: &Apache::lonnet::remove_lock($lock);
1.172 albertel 7768: # my $lasttime = &Time::HiRes::time()-$start;
7769: # $r->print("<p>took $lasttime</p>");
1.140 albertel 7770:
1.200 albertel 7771: $r->print("</form>");
1.157 albertel 7772: return '';
1.75 albertel 7773: }
1.157 albertel 7774:
1.557 raeburn 7775: sub graders_resources_pass {
7776: my ($resources,$grader_partids_by_symb,$grader_randomlists_by_symb) = @_;
7777: if ((ref($resources) eq 'ARRAY') && (ref($grader_partids_by_symb)) &&
7778: (ref($grader_randomlists_by_symb) eq 'HASH')) {
7779: foreach my $resource (@{$resources}) {
7780: my $ressymb = $resource->symb();
7781: my ($analysis,$parts) =
7782: &scantron_partids_tograde($resource,$env{'request.course.id'},
7783: $env{'user.name'},$env{'user.domain'},1);
7784: $grader_partids_by_symb->{$ressymb} = $parts;
7785: if (ref($analysis) eq 'HASH') {
7786: if (ref($analysis->{'parts_withrandomlist'}) eq 'ARRAY') {
7787: $grader_randomlists_by_symb->{$ressymb} =
7788: $analysis->{'parts_withrandomlist'};
7789: }
7790: }
7791: }
7792: }
7793: return;
7794: }
7795:
1.542 raeburn 7796: sub grade_student_bubbles {
1.554 raeburn 7797: my ($r,$uname,$udom,$scan_record,$scancode,$resources,$parts) = @_;
7798: if (ref($resources) eq 'ARRAY') {
7799: my $count = 0;
7800: foreach my $resource (@{$resources}) {
7801: my $ressymb = $resource->symb();
7802: my %form = ('submitted' => 'scantron',
7803: 'grade_target' => 'grade',
7804: 'grade_username' => $uname,
7805: 'grade_domain' => $udom,
7806: 'grade_courseid' => $env{'request.course.id'},
7807: 'grade_symb' => $ressymb,
7808: 'CODE' => $scancode
7809: );
7810: if (ref($parts) eq 'HASH') {
7811: if (ref($parts->{$ressymb}) eq 'ARRAY') {
7812: foreach my $part (@{$parts->{$ressymb}}) {
7813: $form{'scantron_questnum_start.'.$part} =
7814: 1+$env{'form.scantron.first_bubble_line.'.$count};
7815: $count++;
7816: }
7817: }
7818: }
7819: my $result=&ssi_with_retries($resource->src(),$ssi_retries,%form);
7820: return 'ssi_error' if ($ssi_error);
7821: last if (&Apache::loncommon::connection_aborted($r));
7822: }
1.542 raeburn 7823: }
7824: return;
7825: }
7826:
1.157 albertel 7827: sub scantron_upload_scantron_data {
1.608 www 7828: my ($r,$symb)=@_;
1.565 raeburn 7829: my $dom = $env{'request.role.domain'};
7830: my $domdesc = &Apache::lonnet::domain($dom,'description');
7831: $r->print(&Apache::loncommon::coursebrowser_javascript($dom));
1.157 albertel 7832: my $select_link=&Apache::loncommon::selectcourse_link('rules','courseid',
1.181 albertel 7833: 'domainid',
1.565 raeburn 7834: 'coursename',$dom);
7835: my $syllabuslink = '<a href="javascript:ToSyllabus();">'.&mt('Syllabus').'</a>'.
7836: (' 'x2).&mt('(shows course personnel)');
1.608 www 7837: my $default_form_data=&defaultFormData($symb);
1.579 raeburn 7838: my $nofile_alert = &mt('Please use the browse button to select a file from your local directory.');
7839: 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 7840: $r->print(&Apache::lonhtmlcommon::scripttag('
1.157 albertel 7841: function checkUpload(formname) {
7842: if (formname.upfile.value == "") {
1.579 raeburn 7843: alert("'.$nofile_alert.'");
1.157 albertel 7844: return false;
7845: }
1.565 raeburn 7846: if (formname.courseid.value == "") {
1.579 raeburn 7847: alert("'.$nocourseid_alert.'");
1.565 raeburn 7848: return false;
7849: }
1.157 albertel 7850: formname.submit();
7851: }
1.565 raeburn 7852:
7853: function ToSyllabus() {
7854: var cdom = '."'$dom'".';
7855: var cnum = document.rules.courseid.value;
7856: if (cdom == "" || cdom == null) {
7857: return;
7858: }
7859: if (cnum == "" || cnum == null) {
7860: return;
7861: }
7862: syllwin=window.open("/public/"+cdom+"/"+cnum+"/syllabus","LONCAPASyllabus",
7863: "height=350,width=350,scrollbars=yes,menubar=no");
7864: return;
7865: }
7866:
1.597 wenzelju 7867: '));
7868: $r->print('
1.566 raeburn 7869: <h3>'.&mt('Send scanned bubblesheet data to a course').'</h3>
7870:
1.492 albertel 7871: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
1.565 raeburn 7872: '.$default_form_data.
7873: &Apache::lonhtmlcommon::start_pick_box().
7874: &Apache::lonhtmlcommon::row_title(&mt('Course ID')).
7875: '<input name="courseid" type="text" size="30" />'.$select_link.
7876: &Apache::lonhtmlcommon::row_closure().
7877: &Apache::lonhtmlcommon::row_title(&mt('Course Name')).
7878: '<input name="coursename" type="text" size="30" />'.$syllabuslink.
7879: &Apache::lonhtmlcommon::row_closure().
7880: &Apache::lonhtmlcommon::row_title(&mt('Domain')).
7881: '<input name="domainid" type="hidden" />'.$domdesc.
7882: &Apache::lonhtmlcommon::row_closure().
7883: &Apache::lonhtmlcommon::row_title(&mt('File to upload')).
7884: '<input type="file" name="upfile" size="50" />'.
7885: &Apache::lonhtmlcommon::row_closure(1).
7886: &Apache::lonhtmlcommon::end_pick_box().'<br />
7887:
1.492 albertel 7888: <input name="command" value="scantronupload_save" type="hidden" />
1.589 bisitz 7889: <input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
1.157 albertel 7890: </form>
1.492 albertel 7891: ');
1.157 albertel 7892: return '';
7893: }
7894:
1.423 albertel 7895:
1.157 albertel 7896: sub scantron_upload_scantron_data_save {
1.608 www 7897: my($r,$symb)=@_;
1.182 albertel 7898: my $doanotherupload=
7899: '<br /><form action="/adm/grades" method="post">'."\n".
7900: '<input type="hidden" name="command" value="scantronupload" />'."\n".
1.492 albertel 7901: '<input type="submit" name="submit" value="'.&mt('Do Another Upload').'" />'."\n".
1.182 albertel 7902: '</form>'."\n";
1.257 albertel 7903: if (!&Apache::lonnet::allowed('usc',$env{'form.domainid'}) &&
1.162 albertel 7904: !&Apache::lonnet::allowed('usc',
1.257 albertel 7905: $env{'form.domainid'}.'_'.$env{'form.courseid'})) {
1.575 www 7906: $r->print(&mt("You are not allowed to upload bubblesheet data to the requested course.")."<br />");
1.614 www 7907: unless ($symb) {
1.182 albertel 7908: $r->print($doanotherupload);
7909: }
1.162 albertel 7910: return '';
7911: }
1.257 albertel 7912: my %coursedata=&Apache::lonnet::coursedescription($env{'form.domainid'}.'_'.$env{'form.courseid'});
1.568 raeburn 7913: my $uploadedfile;
1.567 raeburn 7914: $r->print('<h3>'.&mt("Uploading file to [_1]",$coursedata{'description'}).'</h3>');
1.257 albertel 7915: if (length($env{'form.upfile'}) < 2) {
1.568 raeburn 7916: $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 7917: } else {
1.568 raeburn 7918: my $result =
7919: &Apache::lonnet::userfileupload('upfile','','scantron','','','',
7920: $env{'form.courseid'},$env{'form.domainid'});
7921: if ($result =~ m{^/uploaded/}) {
1.567 raeburn 7922: $r->print(&mt('[_1]Success:[_2] Successfully uploaded [_3] bytes of data into location: [_4]',
7923: '<span class="LC_success">','</span>',(length($env{'form.upfile'})-1),
7924: '<span class="LC_filename">'.$result.'</span>'));
1.568 raeburn 7925: ($uploadedfile) = ($result =~ m{/([^/]+)$});
1.567 raeburn 7926: $r->print(&validate_uploaded_scantron_file($env{'form.domainid'},
1.568 raeburn 7927: $env{'form.courseid'},$uploadedfile));
1.210 albertel 7928: } else {
1.567 raeburn 7929: $r->print(&mt('[_1]Error:[_2] An error ([_3]) occurred when attempting to upload the file, [_4]',
7930: '<span class="LC_error">','</span>',$result,
1.568 raeburn 7931: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'));
1.183 albertel 7932: }
7933: }
1.174 albertel 7934: if ($symb) {
1.612 www 7935: $r->print(&scantron_selectphase($r,$uploadedfile,$symb));
1.174 albertel 7936: } else {
1.182 albertel 7937: $r->print($doanotherupload);
1.174 albertel 7938: }
1.157 albertel 7939: return '';
7940: }
7941:
1.567 raeburn 7942: sub validate_uploaded_scantron_file {
7943: my ($cdom,$cname,$fname) = @_;
7944: my $scanlines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.$fname);
7945: my @lines;
7946: if ($scanlines ne '-1') {
7947: @lines=split("\n",$scanlines,-1);
7948: }
7949: my $output;
7950: if (@lines) {
7951: my (%counts,$max_match_format);
7952: my ($max_match_count,$max_match_pct) = (0,0);
7953: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cname);
7954: my %idmap = &username_to_idmap($classlist);
7955: foreach my $key (keys(%idmap)) {
7956: my $lckey = lc($key);
7957: $idmap{$lckey} = $idmap{$key};
7958: }
7959: my %unique_formats;
7960: my @formatlines = &get_scantronformat_file();
7961: foreach my $line (@formatlines) {
7962: chomp($line);
7963: my @config = split(/:/,$line);
7964: my $idstart = $config[5];
7965: my $idlength = $config[6];
7966: if (($idstart ne '') && ($idlength > 0)) {
7967: if (ref($unique_formats{$idstart.':'.$idlength}) eq 'ARRAY') {
7968: push(@{$unique_formats{$idstart.':'.$idlength}},$config[0].':'.$config[1]);
7969: } else {
7970: $unique_formats{$idstart.':'.$idlength} = [$config[0].':'.$config[1]];
7971: }
7972: }
7973: }
7974: foreach my $key (keys(%unique_formats)) {
7975: my ($idstart,$idlength) = split(':',$key);
7976: %{$counts{$key}} = (
7977: 'found' => 0,
7978: 'total' => 0,
7979: );
7980: foreach my $line (@lines) {
7981: next if ($line =~ /^#/);
7982: next if ($line =~ /^[\s\cz]*$/);
7983: my $id = substr($line,$idstart-1,$idlength);
7984: $id = lc($id);
7985: if (exists($idmap{$id})) {
7986: $counts{$key}{'found'} ++;
7987: }
7988: $counts{$key}{'total'} ++;
7989: }
7990: if ($counts{$key}{'total'}) {
7991: my $percent_match = (100*$counts{$key}{'found'})/($counts{$key}{'total'});
7992: if (($max_match_format eq '') || ($percent_match > $max_match_pct)) {
7993: $max_match_pct = $percent_match;
7994: $max_match_format = $key;
7995: $max_match_count = $counts{$key}{'total'};
7996: }
7997: }
7998: }
7999: if (ref($unique_formats{$max_match_format}) eq 'ARRAY') {
8000: my $format_descs;
8001: my $numwithformat = @{$unique_formats{$max_match_format}};
8002: for (my $i=0; $i<$numwithformat; $i++) {
8003: my ($name,$desc) = split(':',$unique_formats{$max_match_format}[$i]);
8004: if ($i<$numwithformat-2) {
8005: $format_descs .= '"<i>'.$desc.'</i>", ';
8006: } elsif ($i==$numwithformat-2) {
8007: $format_descs .= '"<i>'.$desc.'</i>" '.&mt('and').' ';
8008: } elsif ($i==$numwithformat-1) {
8009: $format_descs .= '"<i>'.$desc.'</i>"';
8010: }
8011: }
8012: my $showpct = sprintf("%.0f",$max_match_pct).'%';
8013: $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).
8014: '<br />'.&mt('A low percentage of matches results from one of the following:').'<ul>'.
8015: '<li>'.&mt('The file was uploaded to the wrong course').'</li>'.
8016: '<li>'.&mt('The data are not in the format expected for the domain: [_1]',
8017: '<i>'.$cdom.'</i>').'</li>'.
8018: '<li>'.&mt('Students did not bubble their IDs, or mis-bubbled them').'</li>'.
8019: '<li>'.&mt('The course roster is not up to date').'</li>'.
8020: '</ul>';
8021: }
8022: } else {
8023: $output = '<span class="LC_warning">'.&mt('Uploaded file contained no data').'</span>';
8024: }
8025: return $output;
8026: }
8027:
1.202 albertel 8028: sub valid_file {
8029: my ($requested_file)=@_;
8030: foreach my $filename (sort(&scantron_filenames())) {
8031: if ($requested_file eq $filename) { return 1; }
8032: }
8033: return 0;
8034: }
8035:
8036: sub scantron_download_scantron_data {
1.608 www 8037: my ($r,$symb)=@_;
8038: my $default_form_data=&defaultFormData($symb);
1.257 albertel 8039: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
8040: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
8041: my $file=$env{'form.scantron_selectfile'};
1.202 albertel 8042: if (! &valid_file($file)) {
1.492 albertel 8043: $r->print('
1.202 albertel 8044: <p>
1.492 albertel 8045: '.&mt('The requested file name was invalid.').'
1.202 albertel 8046: </p>
1.492 albertel 8047: ');
1.202 albertel 8048: return;
8049: }
8050: my $orig='/uploaded/'.$cdom.'/'.$cname.'/scantron_orig_'.$file;
8051: my $corrected='/uploaded/'.$cdom.'/'.$cname.'/scantron_corrected_'.$file;
8052: my $skipped='/uploaded/'.$cdom.'/'.$cname.'/scantron_skipped_'.$file;
8053: &Apache::lonnet::allowuploaded('/adm/grades',$orig);
8054: &Apache::lonnet::allowuploaded('/adm/grades',$corrected);
8055: &Apache::lonnet::allowuploaded('/adm/grades',$skipped);
1.492 albertel 8056: $r->print('
1.202 albertel 8057: <p>
1.492 albertel 8058: '.&mt('[_1]Original[_2] file as uploaded by the scantron office.',
8059: '<a href="'.$orig.'">','</a>').'
1.202 albertel 8060: </p>
8061: <p>
1.492 albertel 8062: '.&mt('[_1]Corrections[_2], a file of corrected records that were used in grading.',
8063: '<a href="'.$corrected.'">','</a>').'
1.202 albertel 8064: </p>
8065: <p>
1.492 albertel 8066: '.&mt('[_1]Skipped[_2], a file of records that were skipped.',
8067: '<a href="'.$skipped.'">','</a>').'
1.202 albertel 8068: </p>
1.492 albertel 8069: ');
1.202 albertel 8070: return '';
8071: }
1.157 albertel 8072:
1.523 raeburn 8073: sub checkscantron_results {
1.608 www 8074: my ($r,$symb) = @_;
1.523 raeburn 8075: if (!$symb) {return '';}
8076: my $cid = $env{'request.course.id'};
1.542 raeburn 8077: my %lettdig = &letter_to_digits();
1.523 raeburn 8078: my $numletts = scalar(keys(%lettdig));
8079: my $cnum = $env{'course.'.$cid.'.num'};
8080: my $cdom = $env{'course.'.$cid.'.domain'};
8081: my (undef, undef, $sequence) = &Apache::lonnet::decode_symb($env{'form.selectpage'});
8082: my %record;
8083: my %scantron_config =
8084: &Apache::grades::get_scantron_config($env{'form.scantron_format'});
8085: my ($scanlines,$scan_data)=&Apache::grades::scantron_getfile();
8086: my $classlist=&Apache::loncoursedata::get_classlist();
8087: my %idmap=&Apache::grades::username_to_idmap($classlist);
8088: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 8089: unless (ref($navmap)) {
8090: $r->print(&navmap_errormsg());
8091: return '';
8092: }
1.523 raeburn 8093: my $map=$navmap->getResourceByUrl($sequence);
1.557 raeburn 8094: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
8095: my (%grader_partids_by_symb,%grader_randomlists_by_symb);
8096: &graders_resources_pass(\@resources,\%grader_partids_by_symb, \%grader_randomlists_by_symb);
8097:
1.554 raeburn 8098: my ($uname,$udom);
1.523 raeburn 8099: my (%scandata,%lastname,%bylast);
8100: $r->print('
8101: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="checkscantron">'."\n");
8102:
8103: my @delayqueue;
8104: my %completedstudents;
8105:
8106: my $count=&Apache::grades::get_todo_count($scanlines,$scan_data);
1.581 www 8107: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Bubblesheet/Submissions Comparison Status',
8108: 'Progress of Bubblesheet Data/Submission Records Comparison',$count,
1.523 raeburn 8109: 'inline',undef,'checkscantron');
1.546 raeburn 8110: my ($username,$domain,$started);
1.582 raeburn 8111: my $nav_error;
8112: &scantron_get_maxbubble(\$nav_error); # Need the bubble lines array to parse.
8113: if ($nav_error) {
8114: $r->print(&navmap_errormsg());
8115: return '';
8116: }
1.523 raeburn 8117:
8118: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
8119: 'Processing first student');
8120: my $start=&Time::HiRes::time();
8121: my $i=-1;
8122:
8123: while ($i<$scanlines->{'count'}) {
8124: ($username,$domain,$uname)=('','','');
8125: $i++;
8126: my $line=&Apache::grades::scantron_get_line($scanlines,$scan_data,$i);
8127: if ($line=~/^[\s\cz]*$/) { next; }
8128: if ($started) {
8129: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
8130: 'last student');
8131: }
8132: $started=1;
8133: my $scan_record=
8134: &Apache::grades::scantron_parse_scanline($line,$i,\%scantron_config,
8135: $scan_data);
8136: unless ($uname=&Apache::grades::scantron_find_student($scan_record,$scan_data,
8137: \%idmap,$i)) {
8138: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
8139: 'Unable to find a student that matches',1);
8140: next;
8141: }
8142: if (exists $completedstudents{$uname}) {
8143: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
8144: 'Student '.$uname.' has multiple sheets',2);
8145: next;
8146: }
8147: my $pid = $scan_record->{'scantron.ID'};
8148: $lastname{$pid} = $scan_record->{'scantron.LastName'};
8149: push(@{$bylast{$lastname{$pid}}},$pid);
8150: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
8151: $scandata{$pid} = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
8152: chomp($scandata{$pid});
8153: $scandata{$pid} =~ s/\r$//;
8154: ($username,$domain)=split(/:/,$uname);
8155: my $counter = -1;
8156: foreach my $resource (@resources) {
1.557 raeburn 8157: my $parts;
1.554 raeburn 8158: my $ressymb = $resource->symb();
1.557 raeburn 8159: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
8160: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
8161: (my $analysis,$parts) =
8162: &scantron_partids_tograde($resource,$env{'request.course.id'},$username,$domain);
8163: } else {
8164: $parts = $grader_partids_by_symb{$ressymb};
8165: }
1.542 raeburn 8166: ($counter,my $recording) =
8167: &verify_scantron_grading($resource,$domain,$username,$cid,$counter,
1.554 raeburn 8168: $scandata{$pid},$parts,
1.542 raeburn 8169: \%scantron_config,\%lettdig,$numletts);
8170: $record{$pid} .= $recording;
1.523 raeburn 8171: }
8172: }
8173: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
8174: $r->print('<br />');
8175: my ($okstudents,$badstudents,$numstudents,$passed,$failed);
8176: $passed = 0;
8177: $failed = 0;
8178: $numstudents = 0;
8179: foreach my $last (sort(keys(%bylast))) {
8180: if (ref($bylast{$last}) eq 'ARRAY') {
8181: foreach my $pid (sort(@{$bylast{$last}})) {
8182: my $showscandata = $scandata{$pid};
8183: my $showrecord = $record{$pid};
8184: $showscandata =~ s/\s/ /g;
8185: $showrecord =~ s/\s/ /g;
8186: if ($scandata{$pid} eq $record{$pid}) {
8187: my $css_class = ($passed % 2)?'LC_odd_row':'LC_even_row';
8188: $okstudents .= '<tr class="'.$css_class.'">'.
1.581 www 8189: '<td>'.&mt('Bubblesheet').'</td><td>'.$showscandata.'</td><td rowspan="2">'.$last.'</td><td rowspan="2">'.$pid.'</td>'."\n".
1.523 raeburn 8190: '</tr>'."\n".
8191: '<tr class="'.$css_class.'">'."\n".
8192: '<td>Submissions</td><td>'.$showrecord.'</td></tr>'."\n";
8193: $passed ++;
8194: } else {
8195: my $css_class = ($failed % 2)?'LC_odd_row':'LC_even_row';
1.581 www 8196: $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 8197: '</tr>'."\n".
8198: '<tr class="'.$css_class.'">'."\n".
8199: '<td>Submissions</td><td><span class="LC_nobreak">'.$record{$pid}.'</span></td>'."\n".
8200: '</tr>'."\n";
8201: $failed ++;
8202: }
8203: $numstudents ++;
8204: }
8205: }
8206: }
1.572 www 8207: $r->print('<p>'.&mt('Comparison of bubblesheet data (including corrections) with corresponding submission records (most recent submission) for <b>[quant,_1,student]</b> ([_2] scantron lines/student).',$numstudents,$env{'form.scantron_maxbubble'}).'</p>');
1.523 raeburn 8208: $r->print('<p>'.&mt('Exact matches for <b>[quant,_1,student]</b>.',$passed).'<br />'.&mt('Discrepancies detected for <b>[quant,_1,student]</b>.',$failed).'</p>');
8209: if ($passed) {
1.572 www 8210: $r->print(&mt('Students with exact correspondence between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 8211: $r->print(&Apache::loncommon::start_data_table()."\n".
8212: &Apache::loncommon::start_data_table_header_row()."\n".
8213: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
8214: &Apache::loncommon::end_data_table_header_row()."\n".
8215: $okstudents."\n".
8216: &Apache::loncommon::end_data_table().'<br />');
8217: }
8218: if ($failed) {
1.572 www 8219: $r->print(&mt('Students with differences between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 8220: $r->print(&Apache::loncommon::start_data_table()."\n".
8221: &Apache::loncommon::start_data_table_header_row()."\n".
8222: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
8223: &Apache::loncommon::end_data_table_header_row()."\n".
8224: $badstudents."\n".
8225: &Apache::loncommon::end_data_table()).'<br />'.
1.572 www 8226: &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 8227: }
1.614 www 8228: $r->print('</form><br />');
1.523 raeburn 8229: return;
8230: }
8231:
1.542 raeburn 8232: sub verify_scantron_grading {
1.554 raeburn 8233: my ($resource,$domain,$username,$cid,$counter,$scandata,$partids,
1.542 raeburn 8234: $scantron_config,$lettdig,$numletts) = @_;
8235: my ($record,%expected,%startpos);
8236: return ($counter,$record) if (!ref($resource));
8237: return ($counter,$record) if (!$resource->is_problem());
8238: my $symb = $resource->symb();
1.554 raeburn 8239: return ($counter,$record) if (ref($partids) ne 'ARRAY');
8240: foreach my $part_id (@{$partids}) {
1.542 raeburn 8241: $counter ++;
8242: $expected{$part_id} = 0;
8243: if ($env{"form.scantron.sub_bubblelines.$counter"}) {
8244: my @sub_lines = split(/,/,$env{"form.scantron.sub_bubblelines.$counter"});
8245: foreach my $item (@sub_lines) {
8246: $expected{$part_id} += $item;
8247: }
8248: } else {
8249: $expected{$part_id} = $env{"form.scantron.bubblelines.$counter"};
8250: }
8251: $startpos{$part_id} = $env{"form.scantron.first_bubble_line.$counter"};
8252: }
8253: if ($symb) {
8254: my %recorded;
8255: my (%returnhash) = &Apache::lonnet::restore($symb,$cid,$domain,$username);
8256: if ($returnhash{'version'}) {
8257: my %lasthash=();
8258: my $version;
8259: for ($version=1;$version<=$returnhash{'version'};$version++) {
8260: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
8261: $lasthash{$key}=$returnhash{$version.':'.$key};
8262: }
8263: }
8264: foreach my $key (keys(%lasthash)) {
8265: if ($key =~ /\.scantron$/) {
8266: my $value = &unescape($lasthash{$key});
8267: my ($part_id) = ($key =~ /^resource\.(.+)\.scantron$/);
8268: if ($value eq '') {
8269: for (my $i=0; $i<$expected{$part_id}; $i++) {
8270: for (my $j=0; $j<$scantron_config->{'length'}; $j++) {
8271: $recorded{$part_id} .= $scantron_config->{'Qoff'};
8272: }
8273: }
8274: } else {
8275: my @tocheck;
8276: my @items = split(//,$value);
8277: if (($scantron_config->{'Qon'} eq 'letter') ||
8278: ($scantron_config->{'Qon'} eq 'number')) {
8279: if (@items < $expected{$part_id}) {
8280: my $fragment = substr($scandata,$startpos{$part_id},$expected{$part_id});
8281: my @singles = split(//,$fragment);
8282: foreach my $pos (@singles) {
8283: if ($pos eq ' ') {
8284: push(@tocheck,$pos);
8285: } else {
8286: my $next = shift(@items);
8287: push(@tocheck,$next);
8288: }
8289: }
8290: } else {
8291: @tocheck = @items;
8292: }
8293: foreach my $letter (@tocheck) {
8294: if ($scantron_config->{'Qon'} eq 'letter') {
8295: if ($letter !~ /^[A-J]$/) {
8296: $letter = $scantron_config->{'Qoff'};
8297: }
8298: $recorded{$part_id} .= $letter;
8299: } elsif ($scantron_config->{'Qon'} eq 'number') {
8300: my $digit;
8301: if ($letter !~ /^[A-J]$/) {
8302: $digit = $scantron_config->{'Qoff'};
8303: } else {
8304: $digit = $lettdig->{$letter};
8305: }
8306: $recorded{$part_id} .= $digit;
8307: }
8308: }
8309: } else {
8310: @tocheck = @items;
8311: for (my $i=0; $i<$expected{$part_id}; $i++) {
8312: my $curr_sub = shift(@tocheck);
8313: my $digit;
8314: if ($curr_sub =~ /^[A-J]$/) {
8315: $digit = $lettdig->{$curr_sub}-1;
8316: }
8317: if ($curr_sub eq 'J') {
8318: $digit += scalar($numletts);
8319: }
8320: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
8321: if ($j == $digit) {
8322: $recorded{$part_id} .= $scantron_config->{'Qon'};
8323: } else {
8324: $recorded{$part_id} .= $scantron_config->{'Qoff'};
8325: }
8326: }
8327: }
8328: }
8329: }
8330: }
8331: }
8332: }
1.554 raeburn 8333: foreach my $part_id (@{$partids}) {
1.542 raeburn 8334: if ($recorded{$part_id} eq '') {
8335: for (my $i=0; $i<$expected{$part_id}; $i++) {
8336: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
8337: $recorded{$part_id} .= $scantron_config->{'Qoff'};
8338: }
8339: }
8340: }
8341: $record .= $recorded{$part_id};
8342: }
8343: }
8344: return ($counter,$record);
8345: }
8346:
8347: sub letter_to_digits {
8348: my %lettdig = (
8349: A => 1,
8350: B => 2,
8351: C => 3,
8352: D => 4,
8353: E => 5,
8354: F => 6,
8355: G => 7,
8356: H => 8,
8357: I => 9,
8358: J => 0,
8359: );
8360: return %lettdig;
8361: }
8362:
1.423 albertel 8363:
1.75 albertel 8364: #-------- end of section for handling grading scantron forms -------
8365: #
8366: #-------------------------------------------------------------------
8367:
1.72 ng 8368: #-------------------------- Menu interface -------------------------
8369: #
1.614 www 8370: #--- Href with symb and command ---
8371:
8372: sub href_symb_cmd {
8373: my ($symb,$cmd)=@_;
8374: return '/adm/grades?symb='.&HTML::Entities::encode(&Apache::lonenc::check_encrypt($symb),'<>&"').'&command='.$cmd;
1.72 ng 8375: }
8376:
1.443 banghart 8377: sub grading_menu {
1.608 www 8378: my ($request,$symb) = @_;
1.443 banghart 8379: if (!$symb) {return '';}
8380:
8381: my %fields = ('symb'=>&Apache::lonenc::check_encrypt($symb),
1.618 www 8382: 'command'=>'individual');
1.538 schulted 8383:
1.598 www 8384: my $url1a = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8385:
8386: $fields{'command'}='ungraded';
8387: my $url1b=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
8388:
8389: $fields{'command'}='table';
8390: my $url1c=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
8391:
8392: $fields{'command'}='all_for_one';
8393: my $url1d=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
8394:
1.621 www 8395: $fields{'command'}='downloadfilesselect';
8396: my $url1e=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
8397:
1.443 banghart 8398: $fields{'command'} = 'csvform';
1.538 schulted 8399: my $url2 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8400:
1.443 banghart 8401: $fields{'command'} = 'processclicker';
1.538 schulted 8402: my $url3 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8403:
1.443 banghart 8404: $fields{'command'} = 'scantron_selectphase';
1.538 schulted 8405: my $url4 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
1.602 www 8406:
8407: $fields{'command'} = 'initialverifyreceipt';
8408: my $url5 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
1.538 schulted 8409:
1.598 www 8410: my @menu = ({ categorytitle=>'Hand Grading',
1.538 schulted 8411: items =>[
1.598 www 8412: { linktext => 'Select individual students to grade',
8413: url => $url1a,
1.538 schulted 8414: permission => 'F',
8415: icon => 'edit-find-replace.png',
1.598 www 8416: linktitle => 'Grade current resource for a selection of students.'
8417: },
8418: { linktext => 'Grade ungraded submissions.',
8419: url => $url1b,
8420: permission => 'F',
8421: icon => 'edit-find-replace.png',
8422: linktitle => 'Grade all submissions that have not been graded yet.'
1.538 schulted 8423: },
1.598 www 8424:
8425: { linktext => 'Grading table',
8426: url => $url1c,
8427: permission => 'F',
8428: icon => 'edit-find-replace.png',
8429: linktitle => 'Grade current resource for all students.'
8430: },
1.615 www 8431: { linktext => 'Grade page/folder for one student',
1.598 www 8432: url => $url1d,
8433: permission => 'F',
8434: icon => 'edit-find-replace.png',
8435: linktitle => 'Grade all resources in current page/sequence/folder for one student.'
1.621 www 8436: },
8437: { linktext => 'Download submissions',
8438: url => $url1e,
8439: permission => 'F',
8440: icon => 'edit-find-replace.png',
8441: linktitle => 'Download all students submissions.'
1.598 www 8442: }]},
8443: { categorytitle=>'Automated Grading',
8444: items =>[
8445:
1.538 schulted 8446: { linktext => 'Upload Scores',
8447: url => $url2,
8448: permission => 'F',
8449: icon => 'uploadscores.png',
8450: linktitle => 'Specify a file containing the class scores for current resource.'
8451: },
8452: { linktext => 'Process Clicker',
8453: url => $url3,
8454: permission => 'F',
8455: icon => 'addClickerInfoFile.png',
8456: linktitle => 'Specify a file containing the clicker information for this resource.'
8457: },
1.587 raeburn 8458: { linktext => 'Grade/Manage/Review Bubblesheets',
1.538 schulted 8459: url => $url4,
8460: permission => 'F',
8461: icon => 'stat.png',
8462: linktitle => 'Grade scantron exams, upload/download scantron data files, and review previously graded scantron exams.'
1.602 www 8463: },
1.616 www 8464: { linktext => 'Verify Receipt Number',
1.602 www 8465: url => $url5,
8466: permission => 'F',
8467: icon => 'edit-find-replace.png',
8468: linktitle => 'Verify a system-generated receipt number for correct problem solution.'
8469: }
8470:
1.538 schulted 8471: ]
8472: });
8473:
1.443 banghart 8474: # Create the menu
8475: my $Str;
1.445 banghart 8476: $Str .= '<form method="post" action="" name="gradingMenu">';
8477: $Str .= '<input type="hidden" name="command" value="" />'.
1.618 www 8478: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.445 banghart 8479:
1.602 www 8480: $Str .= &Apache::lonhtmlcommon::generate_menu(@menu);
1.443 banghart 8481: return $Str;
8482: }
8483:
1.598 www 8484:
8485: sub ungraded {
8486: my ($request)=@_;
8487: &submit_options($request);
8488: }
8489:
1.599 www 8490: sub submit_options_sequence {
1.608 www 8491: my ($request,$symb) = @_;
1.599 www 8492: if (!$symb) {return '';}
1.600 www 8493: &commonJSfunctions($request);
8494: my $result;
1.599 www 8495:
1.600 www 8496: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.618 www 8497: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.600 www 8498: $result.='
8499: <h2>
1.615 www 8500: '.&mt('Grade page/folder for one student').'
1.601 www 8501: </h2>'.
8502: &selectfield(0).
8503: '<input type="hidden" name="command" value="pickStudentPage" />
1.600 www 8504: <div>
8505: <input type="submit" value="'.&mt('Next').' →" />
8506: </div>
8507: </div>
8508: </form>';
8509: return $result;
8510: }
8511:
8512: sub submit_options_table {
1.608 www 8513: my ($request,$symb) = @_;
1.600 www 8514: if (!$symb) {return '';}
1.599 www 8515: &commonJSfunctions($request);
8516: my $result;
8517:
8518: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.618 www 8519: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.599 www 8520:
8521: $result.='
8522: <h2>
1.600 www 8523: '.&mt('Grading table').'
1.601 www 8524: </h2>'.
8525: &selectfield(0).
8526: '<input type="hidden" name="command" value="viewgrades" />
1.599 www 8527: <div>
8528: <input type="submit" value="'.&mt('Next').' →" />
8529: </div>
8530: </div>
8531: </form>';
8532: return $result;
8533: }
1.443 banghart 8534:
1.621 www 8535: sub submit_options_download {
8536: my ($request,$symb) = @_;
8537: if (!$symb) {return '';}
8538:
8539: &commonJSfunctions($request);
8540:
8541: my $result='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
8542: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
8543: $result.='
8544: <h2>
8545: '.&mt('Select Students for Which to Download Submissions').'
8546: </h2>'.&selectfield(1).'
8547: <input type="hidden" name="command" value="downloadfileslink" />
8548: <input type="submit" value="'.&mt('Next').' →" />
8549: </div>
8550: </div>
1.600 www 8551:
8552:
1.621 www 8553: </form>';
8554: return $result;
8555: }
8556:
1.443 banghart 8557: #--- Displays the submissions first page -------
8558: sub submit_options {
1.608 www 8559: my ($request,$symb) = @_;
1.72 ng 8560: if (!$symb) {return '';}
8561:
1.118 ng 8562: &commonJSfunctions($request);
1.473 albertel 8563: my $result;
1.533 bisitz 8564:
1.72 ng 8565: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.618 www 8566: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.472 albertel 8567: $result.='
1.533 bisitz 8568: <h2>
1.600 www 8569: '.&mt('Select individual students to grade').'
1.601 www 8570: </h2>'.&selectfield(1).'
8571: <input type="hidden" name="command" value="submission" />
8572: <input type="submit" value="'.&mt('Next').' →" />
8573: </div>
8574: </div>
8575:
8576:
8577: </form>';
8578: return $result;
8579: }
1.533 bisitz 8580:
1.601 www 8581: sub selectfield {
8582: my ($full)=@_;
8583: my $result='<div class="LC_columnSection">
1.537 harmsja 8584:
1.533 bisitz 8585: <fieldset>
8586: <legend>
8587: '.&mt('Sections').'
8588: </legend>
1.601 www 8589: '.&Apache::lonstatistics::SectionSelect('section','multiple',5).'
1.533 bisitz 8590: </fieldset>
1.537 harmsja 8591:
1.533 bisitz 8592: <fieldset>
8593: <legend>
8594: '.&mt('Groups').'
8595: </legend>
8596: '.&Apache::lonstatistics::GroupSelect('group','multiple',5).'
8597: </fieldset>
1.537 harmsja 8598:
1.533 bisitz 8599: <fieldset>
8600: <legend>
8601: '.&mt('Access Status').'
8602: </legend>
1.601 www 8603: '.&Apache::lonhtmlcommon::StatusOptions(undef,undef,5,undef,'mult').'
8604: </fieldset>';
8605: if ($full) {
8606: $result.='
1.533 bisitz 8607: <fieldset>
8608: <legend>
8609: '.&mt('Submission Status').'
1.601 www 8610: </legend>'.
8611: &Apache::loncommon::select_form('all','submitonly',
8612: (&Apache::lonlocal::texthash(
8613: 'yes' => 'with submissions',
8614: 'queued' => 'in grading queue',
8615: 'graded' => 'with ungraded submissions',
8616: 'incorrect' => 'with incorrect submissions',
8617: 'all' => 'with any status'),
8618: 'select_form_order' => ['yes','queued','graded','incorrect','all'])).
8619: '</fieldset>';
8620: }
8621: $result.='</div><br />';
1.44 ng 8622: return $result;
1.2 albertel 8623: }
8624:
1.285 albertel 8625: sub reset_perm {
8626: undef(%perm);
8627: }
8628:
8629: sub init_perm {
8630: &reset_perm();
1.300 albertel 8631: foreach my $test_perm ('vgr','mgr','opa') {
8632:
8633: my $scope = $env{'request.course.id'};
8634: if (!($perm{$test_perm}=&Apache::lonnet::allowed($test_perm,$scope))) {
8635:
8636: $scope .= '/'.$env{'request.course.sec'};
8637: if ( $perm{$test_perm}=
8638: &Apache::lonnet::allowed($test_perm,$scope)) {
8639: $perm{$test_perm.'_section'}=$env{'request.course.sec'};
8640: } else {
8641: delete($perm{$test_perm});
8642: }
1.285 albertel 8643: }
8644: }
8645: }
8646:
1.400 www 8647: sub gather_clicker_ids {
1.408 albertel 8648: my %clicker_ids;
1.400 www 8649:
8650: my $classlist = &Apache::loncoursedata::get_classlist();
8651:
8652: # Set up a couple variables.
1.407 albertel 8653: my $username_idx = &Apache::loncoursedata::CL_SNAME();
8654: my $domain_idx = &Apache::loncoursedata::CL_SDOM();
1.438 www 8655: my $status_idx = &Apache::loncoursedata::CL_STATUS();
1.400 www 8656:
1.407 albertel 8657: foreach my $student (keys(%$classlist)) {
1.438 www 8658: if ($classlist->{$student}->[$status_idx] ne 'Active') { next; }
1.407 albertel 8659: my $username = $classlist->{$student}->[$username_idx];
8660: my $domain = $classlist->{$student}->[$domain_idx];
1.400 www 8661: my $clickers =
1.408 albertel 8662: (&Apache::lonnet::userenvironment($domain,$username,'clickers'))[1];
1.400 www 8663: foreach my $id (split(/\,/,$clickers)) {
1.414 www 8664: $id=~s/^[\#0]+//;
1.421 www 8665: $id=~s/[\-\:]//g;
1.407 albertel 8666: if (exists($clicker_ids{$id})) {
1.408 albertel 8667: $clicker_ids{$id}.=','.$username.':'.$domain;
1.400 www 8668: } else {
1.408 albertel 8669: $clicker_ids{$id}=$username.':'.$domain;
1.400 www 8670: }
8671: }
8672: }
1.407 albertel 8673: return %clicker_ids;
1.400 www 8674: }
8675:
1.402 www 8676: sub gather_adv_clicker_ids {
1.408 albertel 8677: my %clicker_ids;
1.402 www 8678: my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'};
8679: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
8680: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
1.409 albertel 8681: foreach my $element (sort(keys(%coursepersonnel))) {
1.402 www 8682: foreach my $person (split(/\,/,$coursepersonnel{$element})) {
8683: my ($puname,$pudom)=split(/\:/,$person);
8684: my $clickers =
1.408 albertel 8685: (&Apache::lonnet::userenvironment($pudom,$puname,'clickers'))[1];
1.405 www 8686: foreach my $id (split(/\,/,$clickers)) {
1.414 www 8687: $id=~s/^[\#0]+//;
1.421 www 8688: $id=~s/[\-\:]//g;
1.408 albertel 8689: if (exists($clicker_ids{$id})) {
8690: $clicker_ids{$id}.=','.$puname.':'.$pudom;
8691: } else {
8692: $clicker_ids{$id}=$puname.':'.$pudom;
8693: }
1.405 www 8694: }
1.402 www 8695: }
8696: }
1.407 albertel 8697: return %clicker_ids;
1.402 www 8698: }
8699:
1.413 www 8700: sub clicker_grading_parameters {
8701: return ('gradingmechanism' => 'scalar',
8702: 'upfiletype' => 'scalar',
8703: 'specificid' => 'scalar',
8704: 'pcorrect' => 'scalar',
8705: 'pincorrect' => 'scalar');
8706: }
8707:
1.400 www 8708: sub process_clicker {
1.608 www 8709: my ($r,$symb)=@_;
1.400 www 8710: if (!$symb) {return '';}
8711: my $result=&checkforfile_js();
8712: $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
8713: $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
1.538 schulted 8714: $result.=' <b>'.&mt('Specify a file containing the clicker information for this resource.').
8715: '</b></td></tr>'."\n";
1.601 www 8716: $result.='<tr bgcolor="#ffffe6"><td>'."\n";
1.413 www 8717: # Attempt to restore parameters from last session, set defaults if not present
8718: my %Saveable_Parameters=&clicker_grading_parameters();
8719: &Apache::loncommon::restore_course_settings('grades_clicker',
8720: \%Saveable_Parameters);
8721: if (!$env{'form.pcorrect'}) { $env{'form.pcorrect'}=100; }
8722: if (!$env{'form.pincorrect'}) { $env{'form.pincorrect'}=100; }
8723: if (!$env{'form.gradingmechanism'}) { $env{'form.gradingmechanism'}='attendance'; }
8724: if (!$env{'form.upfiletype'}) { $env{'form.upfiletype'}='iclicker'; }
8725:
8726: my %checked;
1.521 www 8727: foreach my $gradingmechanism ('attendance','personnel','specific','given') {
1.413 www 8728: if ($env{'form.gradingmechanism'} eq $gradingmechanism) {
1.569 bisitz 8729: $checked{$gradingmechanism}=' checked="checked"';
1.413 www 8730: }
8731: }
8732:
1.400 www 8733: my $upload=&mt("Upload File");
8734: my $type=&mt("Type");
1.402 www 8735: my $attendance=&mt("Award points just for participation");
8736: my $personnel=&mt("Correctness determined from response by course personnel");
1.414 www 8737: my $specific=&mt("Correctness determined from response with clicker ID(s)");
1.521 www 8738: my $given=&mt("Correctness determined from given list of answers").' '.
8739: '<font size="-2"><tt>('.&mt("Provide comma-separated list. Use '*' for any answer correct, '-' for skip").')</tt></font>';
1.402 www 8740: my $pcorrect=&mt("Percentage points for correct solution");
8741: my $pincorrect=&mt("Percentage points for incorrect solution");
1.413 www 8742: my $selectform=&Apache::loncommon::select_form($env{'form.upfiletype'},'upfiletype',
1.419 www 8743: ('iclicker' => 'i>clicker',
8744: 'interwrite' => 'interwrite PRS'));
1.418 albertel 8745: $symb = &Apache::lonenc::check_encrypt($symb);
1.597 wenzelju 8746: $result.= &Apache::lonhtmlcommon::scripttag(<<ENDUPFORM);
1.402 www 8747: function sanitycheck() {
8748: // Accept only integer percentages
8749: document.forms.gradesupload.pcorrect.value=Math.round(document.forms.gradesupload.pcorrect.value);
8750: document.forms.gradesupload.pincorrect.value=Math.round(document.forms.gradesupload.pincorrect.value);
8751: // Find out grading choice
8752: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
8753: if (document.forms.gradesupload.gradingmechanism[i].checked) {
8754: gradingchoice=document.forms.gradesupload.gradingmechanism[i].value;
8755: }
8756: }
8757: // By default, new choice equals user selection
8758: newgradingchoice=gradingchoice;
8759: // Not good to give more points for false answers than correct ones
8760: if (Math.round(document.forms.gradesupload.pcorrect.value)<Math.round(document.forms.gradesupload.pincorrect.value)) {
8761: document.forms.gradesupload.pcorrect.value=document.forms.gradesupload.pincorrect.value;
8762: }
8763: // If new choice is attendance only, and old choice was correctness-based, restore defaults
8764: if ((gradingchoice=='attendance') && (document.forms.gradesupload.waschecked.value!='attendance')) {
8765: document.forms.gradesupload.pcorrect.value=100;
8766: document.forms.gradesupload.pincorrect.value=100;
8767: }
8768: // If the values are different, cannot be attendance only
8769: if ((Math.round(document.forms.gradesupload.pcorrect.value)!=Math.round(document.forms.gradesupload.pincorrect.value)) &&
8770: (gradingchoice=='attendance')) {
8771: newgradingchoice='personnel';
8772: }
8773: // Change grading choice to new one
8774: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
8775: if (document.forms.gradesupload.gradingmechanism[i].value==newgradingchoice) {
8776: document.forms.gradesupload.gradingmechanism[i].checked=true;
8777: } else {
8778: document.forms.gradesupload.gradingmechanism[i].checked=false;
8779: }
8780: }
8781: // Remember the old state
8782: document.forms.gradesupload.waschecked.value=newgradingchoice;
8783: }
1.597 wenzelju 8784: ENDUPFORM
8785: $result.= <<ENDUPFORM;
1.400 www 8786: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
8787: <input type="hidden" name="symb" value="$symb" />
8788: <input type="hidden" name="command" value="processclickerfile" />
8789: <input type="file" name="upfile" size="50" />
8790: <br /><label>$type: $selectform</label>
1.589 bisitz 8791: <br /><label><input type="radio" name="gradingmechanism" value="attendance"$checked{'attendance'} onclick="sanitycheck()" />$attendance </label>
8792: <br /><label><input type="radio" name="gradingmechanism" value="personnel"$checked{'personnel'} onclick="sanitycheck()" />$personnel</label>
8793: <br /><label><input type="radio" name="gradingmechanism" value="specific"$checked{'specific'} onclick="sanitycheck()" />$specific </label>
1.414 www 8794: <input type="text" name="specificid" value="$env{'form.specificid'}" size="20" />
1.589 bisitz 8795: <br /><label><input type="radio" name="gradingmechanism" value="given"$checked{'given'} onclick="sanitycheck()" />$given </label>
1.521 www 8796: <br />
8797: <input type="text" name="givenanswer" size="50" />
1.413 www 8798: <input type="hidden" name="waschecked" value="$env{'form.gradingmechanism'}" />
1.589 bisitz 8799: <br /><label>$pcorrect: <input type="text" name="pcorrect" size="4" value="$env{'form.pcorrect'}" onchange="sanitycheck()" /></label>
8800: <br /><label>$pincorrect: <input type="text" name="pincorrect" size="4" value="$env{'form.pincorrect'}" onchange="sanitycheck()" /></label>
8801: <br /><input type="button" onclick="javascript:checkUpload(this.form);" value="$upload" />
1.597 wenzelju 8802: </form>'
1.400 www 8803: ENDUPFORM
8804: $result.='</td></tr></table>'."\n".
8805: '</td></tr></table><br /><br />'."\n";
8806: return $result;
8807: }
8808:
8809: sub process_clicker_file {
1.608 www 8810: my ($r,$symb)=@_;
1.400 www 8811: if (!$symb) {return '';}
1.413 www 8812:
8813: my %Saveable_Parameters=&clicker_grading_parameters();
8814: &Apache::loncommon::store_course_settings('grades_clicker',
8815: \%Saveable_Parameters);
1.598 www 8816: my $result='';
1.404 www 8817: if (($env{'form.gradingmechanism'} eq 'specific') && ($env{'form.specificid'}!~/\w/)) {
1.408 albertel 8818: $result.='<span class="LC_error">'.&mt('You need to specify a clicker ID for the correct answer').'</span>';
1.614 www 8819: return $result;
1.404 www 8820: }
1.522 www 8821: if (($env{'form.gradingmechanism'} eq 'given') && ($env{'form.givenanswer'}!~/\S/)) {
1.521 www 8822: $result.='<span class="LC_error">'.&mt('You need to specify the correct answer').'</span>';
1.614 www 8823: return $result;
1.521 www 8824: }
1.522 www 8825: my $foundgiven=0;
1.521 www 8826: if ($env{'form.gradingmechanism'} eq 'given') {
8827: $env{'form.givenanswer'}=~s/^\s*//gs;
8828: $env{'form.givenanswer'}=~s/\s*$//gs;
8829: $env{'form.givenanswer'}=~s/[^a-zA-Z0-9\.\*\-]+/\,/g;
8830: $env{'form.givenanswer'}=uc($env{'form.givenanswer'});
1.522 www 8831: my @answers=split(/\,/,$env{'form.givenanswer'});
8832: $foundgiven=$#answers+1;
1.521 www 8833: }
1.407 albertel 8834: my %clicker_ids=&gather_clicker_ids();
1.408 albertel 8835: my %correct_ids;
1.404 www 8836: if ($env{'form.gradingmechanism'} eq 'personnel') {
1.408 albertel 8837: %correct_ids=&gather_adv_clicker_ids();
1.404 www 8838: }
8839: if ($env{'form.gradingmechanism'} eq 'specific') {
1.414 www 8840: foreach my $correct_id (split(/[\s\,]/,$env{'form.specificid'})) {;
8841: $correct_id=~tr/a-z/A-Z/;
8842: $correct_id=~s/\s//gs;
8843: $correct_id=~s/^[\#0]+//;
1.421 www 8844: $correct_id=~s/[\-\:]//g;
1.414 www 8845: if ($correct_id) {
8846: $correct_ids{$correct_id}='specified';
8847: }
8848: }
1.400 www 8849: }
1.404 www 8850: if ($env{'form.gradingmechanism'} eq 'attendance') {
1.408 albertel 8851: $result.=&mt('Score based on attendance only');
1.521 www 8852: } elsif ($env{'form.gradingmechanism'} eq 'given') {
1.522 www 8853: $result.=&mt('Score based on [_1] ([_2] answers)','<tt>'.$env{'form.givenanswer'}.'</tt>',$foundgiven);
1.404 www 8854: } else {
1.408 albertel 8855: my $number=0;
1.411 www 8856: $result.='<p><b>'.&mt('Correctness determined by the following IDs').'</b>';
1.408 albertel 8857: foreach my $id (sort(keys(%correct_ids))) {
1.411 www 8858: $result.='<br /><tt>'.$id.'</tt> - ';
1.408 albertel 8859: if ($correct_ids{$id} eq 'specified') {
8860: $result.=&mt('specified');
8861: } else {
8862: my ($uname,$udom)=split(/\:/,$correct_ids{$id});
8863: $result.=&Apache::loncommon::plainname($uname,$udom);
8864: }
8865: $number++;
8866: }
1.411 www 8867: $result.="</p>\n";
1.408 albertel 8868: if ($number==0) {
8869: $result.='<span class="LC_error">'.&mt('No IDs found to determine correct answer').'</span>';
1.614 www 8870: return $result;
1.408 albertel 8871: }
1.404 www 8872: }
1.405 www 8873: if (length($env{'form.upfile'}) < 2) {
1.407 albertel 8874: $result.=&mt('[_1] Error: [_2] The file you attempted to upload, [_3] contained no information. Please check that you entered the correct filename.',
8875: '<span class="LC_error">',
8876: '</span>',
8877: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>');
1.614 www 8878: return $result;
1.405 www 8879: }
1.410 www 8880:
8881: # Were able to get all the info needed, now analyze the file
8882:
1.411 www 8883: $result.=&Apache::loncommon::studentbrowser_javascript();
1.418 albertel 8884: $symb = &Apache::lonenc::check_encrypt($symb);
1.410 www 8885: my $heading=&mt('Scanning clicker file');
8886: $result.=(<<ENDHEADER);
8887: <br /><table width="100%" border="0"><tr><td bgcolor="#777777">
8888: <table width="100%" border="0"><tr bgcolor="#e6ffff"><td>
8889: <b>$heading</b></td></tr><tr bgcolor=#ffffe6><td>
8890: <form method="post" action="/adm/grades" name="clickeranalysis">
8891: <input type="hidden" name="symb" value="$symb" />
8892: <input type="hidden" name="command" value="assignclickergrades" />
1.411 www 8893: <input type="hidden" name="gradingmechanism" value="$env{'form.gradingmechanism'}" />
8894: <input type="hidden" name="pcorrect" value="$env{'form.pcorrect'}" />
8895: <input type="hidden" name="pincorrect" value="$env{'form.pincorrect'}" />
1.410 www 8896: ENDHEADER
1.522 www 8897: if ($env{'form.gradingmechanism'} eq 'given') {
8898: $result.='<input type="hidden" name="correct:given" value="'.$env{'form.givenanswer'}.'" />';
8899: }
1.408 albertel 8900: my %responses;
8901: my @questiontitles;
1.405 www 8902: my $errormsg='';
8903: my $number=0;
8904: if ($env{'form.upfiletype'} eq 'iclicker') {
1.408 albertel 8905: ($errormsg,$number)=&iclicker_eval(\@questiontitles,\%responses);
1.406 www 8906: }
1.419 www 8907: if ($env{'form.upfiletype'} eq 'interwrite') {
8908: ($errormsg,$number)=&interwrite_eval(\@questiontitles,\%responses);
8909: }
1.411 www 8910: $result.='<br />'.&mt('Found [_1] question(s)',$number).'<br />'.
8911: '<input type="hidden" name="number" value="'.$number.'" />'.
8912: &mt('Awarding [_1] percent for correct and [_2] percent for incorrect responses',
8913: $env{'form.pcorrect'},$env{'form.pincorrect'}).
8914: '<br />';
1.522 www 8915: if (($env{'form.gradingmechanism'} eq 'given') && ($number!=$foundgiven)) {
8916: $result.='<span class="LC_error">'.&mt('Number of given answers does not agree with number of questions in file.').'</span>';
1.614 www 8917: return $result;
1.522 www 8918: }
1.414 www 8919: # Remember Question Titles
8920: # FIXME: Possibly need delimiter other than ":"
8921: for (my $i=0;$i<$number;$i++) {
8922: $result.='<input type="hidden" name="question:'.$i.'" value="'.
8923: &HTML::Entities::encode($questiontitles[$i],'"&<>').'" />';
8924: }
1.411 www 8925: my $correct_count=0;
8926: my $student_count=0;
8927: my $unknown_count=0;
1.414 www 8928: # Match answers with usernames
8929: # FIXME: Possibly need delimiter other than ":"
1.409 albertel 8930: foreach my $id (keys(%responses)) {
1.410 www 8931: if ($correct_ids{$id}) {
1.414 www 8932: $result.="\n".'<input type="hidden" name="correct:'.$correct_count.':'.$correct_ids{$id}.'" value="'.$responses{$id}.'" />';
1.411 www 8933: $correct_count++;
1.410 www 8934: } elsif ($clicker_ids{$id}) {
1.437 www 8935: if ($clicker_ids{$id}=~/\,/) {
8936: # More than one user with the same clicker!
8937: $result.="\n<hr />".&mt('Clicker registered more than once').": <tt>".$id."</tt><br />";
8938: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
8939: "<select name='multi".$id."'>";
8940: foreach my $reguser (sort(split(/\,/,$clicker_ids{$id}))) {
8941: $result.="<option value='".$reguser."'>".&Apache::loncommon::plainname(split(/\:/,$reguser)).' ('.$reguser.')</option>';
8942: }
8943: $result.='</select>';
8944: $unknown_count++;
8945: } else {
8946: # Good: found one and only one user with the right clicker
8947: $result.="\n".'<input type="hidden" name="student:'.$clicker_ids{$id}.'" value="'.$responses{$id}.'" />';
8948: $student_count++;
8949: }
1.410 www 8950: } else {
1.411 www 8951: $result.="\n<hr />".&mt('Unregistered Clicker')." <tt>".$id."</tt><br />";
8952: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
8953: "\n".&mt("Username").": <input type='text' name='uname".$id."' /> ".
8954: "\n".&mt("Domain").": ".
8955: &Apache::loncommon::select_dom_form($env{'course.'.$env{'request.course.id'}.'.domain'},'udom'.$id).' '.
8956: &Apache::loncommon::selectstudent_link('clickeranalysis','uname'.$id,'udom'.$id);
8957: $unknown_count++;
1.410 www 8958: }
1.405 www 8959: }
1.412 www 8960: $result.='<hr />'.
8961: &mt('Found [_1] registered and [_2] unregistered clickers.',$student_count,$unknown_count);
1.521 www 8962: if (($env{'form.gradingmechanism'} ne 'attendance') && ($env{'form.gradingmechanism'} ne 'given')) {
1.412 www 8963: if ($correct_count==0) {
8964: $errormsg.="Found no correct answers answers for grading!";
8965: } elsif ($correct_count>1) {
1.414 www 8966: $result.='<br /><span class="LC_warning">'.&mt("Found [_1] entries for grading!",$correct_count).'</span>';
1.412 www 8967: }
8968: }
1.428 www 8969: if ($number<1) {
8970: $errormsg.="Found no questions.";
8971: }
1.412 www 8972: if ($errormsg) {
8973: $result.='<br /><span class="LC_error">'.&mt($errormsg).'</span>';
8974: } else {
8975: $result.='<br /><input type="submit" name="finalize" value="'.&mt('Finalize Grading').'" />';
8976: }
8977: $result.='</form></td></tr></table>'."\n".
1.410 www 8978: '</td></tr></table><br /><br />'."\n";
1.614 www 8979: return $result;
1.400 www 8980: }
8981:
1.405 www 8982: sub iclicker_eval {
1.406 www 8983: my ($questiontitles,$responses)=@_;
1.405 www 8984: my $number=0;
8985: my $errormsg='';
8986: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
1.410 www 8987: my %components=&Apache::loncommon::record_sep($line);
8988: my @entries=map {$components{$_}} (sort(keys(%components)));
1.408 albertel 8989: if ($entries[0] eq 'Question') {
8990: for (my $i=3;$i<$#entries;$i+=6) {
8991: $$questiontitles[$number]=$entries[$i];
8992: $number++;
8993: }
8994: }
8995: if ($entries[0]=~/^\#/) {
8996: my $id=$entries[0];
8997: my @idresponses;
8998: $id=~s/^[\#0]+//;
8999: for (my $i=0;$i<$number;$i++) {
9000: my $idx=3+$i*6;
9001: push(@idresponses,$entries[$idx]);
9002: }
9003: $$responses{$id}=join(',',@idresponses);
9004: }
1.405 www 9005: }
9006: return ($errormsg,$number);
9007: }
9008:
1.419 www 9009: sub interwrite_eval {
9010: my ($questiontitles,$responses)=@_;
9011: my $number=0;
9012: my $errormsg='';
1.420 www 9013: my $skipline=1;
9014: my $questionnumber=0;
9015: my %idresponses=();
1.419 www 9016: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
9017: my %components=&Apache::loncommon::record_sep($line);
9018: my @entries=map {$components{$_}} (sort(keys(%components)));
1.420 www 9019: if ($entries[1] eq 'Time') { $skipline=0; next; }
9020: if ($entries[1] eq 'Response') { $skipline=1; }
9021: next if $skipline;
9022: if ($entries[0]!=$questionnumber) {
9023: $questionnumber=$entries[0];
9024: $$questiontitles[$number]=&mt('Question [_1]',$questionnumber);
9025: $number++;
1.419 www 9026: }
1.420 www 9027: my $id=$entries[4];
9028: $id=~s/^[\#0]+//;
1.421 www 9029: $id=~s/^v\d*\://i;
9030: $id=~s/[\-\:]//g;
1.420 www 9031: $idresponses{$id}[$number]=$entries[6];
9032: }
1.524 raeburn 9033: foreach my $id (keys(%idresponses)) {
1.420 www 9034: $$responses{$id}=join(',',@{$idresponses{$id}});
9035: $$responses{$id}=~s/^\s*\,//;
1.419 www 9036: }
9037: return ($errormsg,$number);
9038: }
9039:
1.414 www 9040: sub assign_clicker_grades {
1.608 www 9041: my ($r,$symb)=@_;
1.414 www 9042: if (!$symb) {return '';}
1.416 www 9043: # See which part we are saving to
1.582 raeburn 9044: my $res_error;
9045: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
9046: if ($res_error) {
9047: return &navmap_errormsg();
9048: }
1.416 www 9049: # FIXME: This should probably look for the first handgradeable part
9050: my $part=$$partlist[0];
9051: # Start screen output
1.598 www 9052: my $result='';
1.416 www 9053:
1.414 www 9054: my $heading=&mt('Assigning grades based on clicker file');
9055: $result.=(<<ENDHEADER);
9056: <br /><table width="100%" border="0"><tr><td bgcolor="#777777">
9057: <table width="100%" border="0"><tr bgcolor="#e6ffff"><td>
9058: <b>$heading</b></td></tr><tr bgcolor=#ffffe6><td>
9059: ENDHEADER
9060: # Get correct result
9061: # FIXME: Possibly need delimiter other than ":"
9062: my @correct=();
1.415 www 9063: my $gradingmechanism=$env{'form.gradingmechanism'};
9064: my $number=$env{'form.number'};
9065: if ($gradingmechanism ne 'attendance') {
1.414 www 9066: foreach my $key (keys(%env)) {
9067: if ($key=~/^form\.correct\:/) {
9068: my @input=split(/\,/,$env{$key});
9069: for (my $i=0;$i<=$#input;$i++) {
9070: if (($correct[$i]) && ($input[$i]) &&
9071: ($correct[$i] ne $input[$i])) {
9072: $result.='<br /><span class="LC_warning">'.
9073: &mt('More than one correct result given for question "[_1]": [_2] versus [_3].',
9074: $env{'form.question:'.$i},$correct[$i],$input[$i]).'</span>';
9075: } elsif ($input[$i]) {
9076: $correct[$i]=$input[$i];
9077: }
9078: }
9079: }
9080: }
1.415 www 9081: for (my $i=0;$i<$number;$i++) {
1.414 www 9082: if (!$correct[$i]) {
9083: $result.='<br /><span class="LC_error">'.
9084: &mt('No correct result given for question "[_1]"!',
9085: $env{'form.question:'.$i}).'</span>';
9086: }
9087: }
9088: $result.='<br />'.&mt("Correct answer: [_1]",join(', ',map { ($_?$_:'-') } @correct));
9089: }
9090: # Start grading
1.415 www 9091: my $pcorrect=$env{'form.pcorrect'};
9092: my $pincorrect=$env{'form.pincorrect'};
1.416 www 9093: my $storecount=0;
1.415 www 9094: foreach my $key (keys(%env)) {
1.420 www 9095: my $user='';
1.415 www 9096: if ($key=~/^form\.student\:(.*)$/) {
1.420 www 9097: $user=$1;
9098: }
9099: if ($key=~/^form\.unknown\:(.*)$/) {
9100: my $id=$1;
9101: if (($env{'form.uname'.$id}) && ($env{'form.udom'.$id})) {
9102: $user=$env{'form.uname'.$id}.':'.$env{'form.udom'.$id};
1.437 www 9103: } elsif ($env{'form.multi'.$id}) {
9104: $user=$env{'form.multi'.$id};
1.420 www 9105: }
9106: }
9107: if ($user) {
1.415 www 9108: my @answer=split(/\,/,$env{$key});
9109: my $sum=0;
1.522 www 9110: my $realnumber=$number;
1.415 www 9111: for (my $i=0;$i<$number;$i++) {
1.576 www 9112: if ($correct[$i] eq '-') {
9113: $realnumber--;
9114: } elsif ($answer[$i]) {
1.415 www 9115: if ($gradingmechanism eq 'attendance') {
9116: $sum+=$pcorrect;
1.576 www 9117: } elsif ($correct[$i] eq '*') {
1.522 www 9118: $sum+=$pcorrect;
1.415 www 9119: } else {
9120: if ($answer[$i] eq $correct[$i]) {
9121: $sum+=$pcorrect;
9122: } else {
9123: $sum+=$pincorrect;
9124: }
9125: }
9126: }
9127: }
1.522 www 9128: my $ave=$sum/(100*$realnumber);
1.416 www 9129: # Store
9130: my ($username,$domain)=split(/\:/,$user);
9131: my %grades=();
9132: $grades{"resource.$part.solved"}='correct_by_override';
9133: $grades{"resource.$part.awarded"}=$ave;
9134: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
9135: my $returncode=&Apache::lonnet::cstore(\%grades,$symb,
9136: $env{'request.course.id'},
9137: $domain,$username);
9138: if ($returncode ne 'ok') {
9139: $result.="<br /><span class=\"LC_error\">Failed to save student $username:$domain. Message when trying to save was ($returncode)</span>";
9140: } else {
9141: $storecount++;
9142: }
1.415 www 9143: }
9144: }
9145: # We are done
1.549 hauer 9146: $result.='<br />'.&mt('Successfully stored grades for [quant,_1,student].',$storecount).
1.416 www 9147: '</td></tr></table>'."\n".
1.414 www 9148: '</td></tr></table><br /><br />'."\n";
1.614 www 9149: return $result;
1.414 www 9150: }
9151:
1.582 raeburn 9152: sub navmap_errormsg {
9153: return '<div class="LC_error">'.
9154: &mt('An error occurred retrieving information about resources in the course.').'<br />'.
1.595 raeburn 9155: &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 9156: '</div>';
9157: }
1.607 droeschl 9158:
1.609 www 9159: sub startpage {
1.613 www 9160: my ($r,$symb,$crumbs,$onlyfolderflag,$nodisplayflag) = @_;
1.614 www 9161: unshift(@$crumbs,{href=>&href_symb_cmd($symb,'gradingmenu'),text=>"Grading"});
1.607 droeschl 9162: $r->print(&Apache::loncommon::start_page('Grading',undef,
1.610 www 9163: {'bread_crumbs' => $crumbs}));
1.613 www 9164: unless ($nodisplayflag) {
9165: $r->print(&Apache::lonhtmlcommon::resource_info_box($symb,$onlyfolderflag));
9166: }
1.607 droeschl 9167: }
1.582 raeburn 9168:
1.622 www 9169: sub select_problem {
9170: my ($r)=@_;
1.623 www 9171: $r->print('<h2>'.&mt('Select the problem or one of the problems you want to grade').'</h2><form action="/adm/grades">');
1.622 www 9172: $r->print(&Apache::lonstathelpers::problem_selector('.',undef,1));
9173: $r->print('<input type="hidden" name="command" value="gradingmenu" />');
9174: $r->print('<input type="submit" value="'.&mt('Next').' →" /></form>');
9175: }
9176:
1.1 albertel 9177: sub handler {
1.41 ng 9178: my $request=$_[0];
1.434 albertel 9179: &reset_caches();
1.257 albertel 9180: if ($env{'browser.mathml'}) {
1.141 www 9181: &Apache::loncommon::content_type($request,'text/xml');
1.41 ng 9182: } else {
1.141 www 9183: &Apache::loncommon::content_type($request,'text/html');
1.41 ng 9184: }
9185: $request->send_http_header;
1.44 ng 9186: return '' if $request->header_only;
1.41 ng 9187: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.608 www 9188:
9189: # see what command we need to execute
9190:
1.160 albertel 9191: my @commands=&Apache::loncommon::get_env_multiple('form.command');
9192: my $command=$commands[0];
1.447 foxr 9193:
1.160 albertel 9194: if ($#commands > 0) {
9195: &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands));
9196: }
1.608 www 9197:
9198: # see what the symb is
9199:
9200: my $symb=$env{'form.symb'};
9201: unless ($symb) {
9202: (my $url=$env{'form.url'}) =~ s-^https*://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
9203: $symb=&Apache::lonnet::symbread($url);
9204: }
9205: &Apache::lonenc::check_decrypt(\$symb);
9206:
1.513 foxr 9207: $ssi_error = 0;
1.622 www 9208: if ($symb eq '' || $command eq '') {
1.601 www 9209: #
9210: # Not called from a resource
9211: #
1.622 www 9212: &startpage($request,undef,[],1,1);
9213: &select_problem($request);
1.41 ng 9214: } else {
1.285 albertel 9215: &init_perm();
1.104 albertel 9216: if ($command eq 'submission' && $perm{'vgr'}) {
1.608 www 9217: &startpage($request,$symb,[{href=>"", text=>"Student Submissions"}]);
1.611 www 9218: ($env{'form.student'} eq '' ? &listStudents($request,$symb) : &submission($request,0,0,$symb));
1.103 albertel 9219: } elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) {
1.615 www 9220: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'all_for_one'),text=>'Grade page/folder for one student'},
9221: {href=>'',text=>'Select student'}],1,1);
1.608 www 9222: &pickStudentPage($request,$symb);
1.103 albertel 9223: } elsif ($command eq 'displayPage' && $perm{'vgr'}) {
1.615 www 9224: &startpage($request,$symb,
9225: [{href=>&href_symb_cmd($symb,'all_for_one'),text=>'Grade page/folder for one student'},
9226: {href=>'',text=>'Select student'},
9227: {href=>'',text=>'Grade student'}],1,1);
1.608 www 9228: &displayPage($request,$symb);
1.104 albertel 9229: } elsif ($command eq 'gradeByPage' && $perm{'mgr'}) {
1.616 www 9230: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'all_for_one'),text=>'Grade page/folder for one student'},
9231: {href=>'',text=>'Select student'},
9232: {href=>'',text=>'Grade student'},
9233: {href=>'',text=>'Store grades'}],1,1);
1.608 www 9234: &updateGradeByPage($request,$symb);
1.104 albertel 9235: } elsif ($command eq 'processGroup' && $perm{'vgr'}) {
1.619 www 9236: &startpage($request,$symb,[{href=>'',text=>'...'},
9237: {href=>'',text=>'Modify grades'}]);
1.608 www 9238: &processGroup($request,$symb);
1.104 albertel 9239: } elsif ($command eq 'gradingmenu' && $perm{'vgr'}) {
1.608 www 9240: &startpage($request,$symb);
9241: $request->print(&grading_menu($request,$symb));
1.598 www 9242: } elsif ($command eq 'individual' && $perm{'vgr'}) {
1.617 www 9243: &startpage($request,$symb,[{href=>'',text=>'Select individual students to grade'}]);
1.608 www 9244: $request->print(&submit_options($request,$symb));
1.598 www 9245: } elsif ($command eq 'ungraded' && $perm{'vgr'}) {
1.617 www 9246: &startpage($request,$symb,[{href=>'',text=>'Grade ungraded submissions'}]);
9247: $request->print(&listStudents($request,$symb,'graded'));
1.598 www 9248: } elsif ($command eq 'table' && $perm{'vgr'}) {
1.614 www 9249: &startpage($request,$symb,[{href=>"", text=>"Grading table"}]);
1.611 www 9250: $request->print(&submit_options_table($request,$symb));
1.598 www 9251: } elsif ($command eq 'all_for_one' && $perm{'vgr'}) {
1.615 www 9252: &startpage($request,$symb,[{href=>'',text=>'Grade page/folder for one student'}],1,1);
1.608 www 9253: $request->print(&submit_options_sequence($request,$symb));
1.104 albertel 9254: } elsif ($command eq 'viewgrades' && $perm{'vgr'}) {
1.614 www 9255: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,"table"), text=>"Grading table"},{href=>'', text=>"Modify grades"}]);
1.608 www 9256: $request->print(&viewgrades($request,$symb));
1.104 albertel 9257: } elsif ($command eq 'handgrade' && $perm{'mgr'}) {
1.620 www 9258: &startpage($request,$symb,[{href=>'',text=>'...'},
9259: {href=>'',text=>'Store grades'}]);
1.608 www 9260: $request->print(&processHandGrade($request,$symb));
1.106 albertel 9261: } elsif ($command eq 'editgrades' && $perm{'mgr'}) {
1.614 www 9262: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,"table"), text=>"Grading table"},
9263: {href=>&href_symb_cmd($symb,'viewgrades').'&group=all§ion=all&Status=Active',
9264: text=>"Modify grades"},
9265: {href=>'', text=>"Store grades"}]);
1.608 www 9266: $request->print(&editgrades($request,$symb));
1.602 www 9267: } elsif ($command eq 'initialverifyreceipt' && $perm{'vgr'}) {
1.616 www 9268: &startpage($request,$symb,[{href=>'',text=>'Verify Receipt Number'}]);
1.611 www 9269: $request->print(&initialverifyreceipt($request,$symb));
1.106 albertel 9270: } elsif ($command eq 'verify' && $perm{'vgr'}) {
1.616 www 9271: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,"initialverifyreceipt"),text=>'Verify Receipt Number'},
9272: {href=>'',text=>'Verification Result'}]);
1.608 www 9273: $request->print(&verifyreceipt($request,$symb));
1.400 www 9274: } elsif ($command eq 'processclicker' && $perm{'mgr'}) {
1.615 www 9275: &startpage($request,$symb,[{href=>'', text=>'Process clicker'}]);
1.608 www 9276: $request->print(&process_clicker($request,$symb));
1.400 www 9277: } elsif ($command eq 'processclickerfile' && $perm{'mgr'}) {
1.615 www 9278: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'processclicker'), text=>'Process clicker'},
9279: {href=>'', text=>'Process clicker file'}]);
1.608 www 9280: $request->print(&process_clicker_file($request,$symb));
1.414 www 9281: } elsif ($command eq 'assignclickergrades' && $perm{'mgr'}) {
1.615 www 9282: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'processclicker'), text=>'Process clicker'},
9283: {href=>'', text=>'Process clicker file'},
9284: {href=>'', text=>'Store grades'}]);
1.608 www 9285: $request->print(&assign_clicker_grades($request,$symb));
1.106 albertel 9286: } elsif ($command eq 'csvform' && $perm{'mgr'}) {
1.616 www 9287: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 9288: $request->print(&upcsvScores_form($request,$symb));
1.106 albertel 9289: } elsif ($command eq 'csvupload' && $perm{'mgr'}) {
1.616 www 9290: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 9291: $request->print(&csvupload($request,$symb));
1.106 albertel 9292: } elsif ($command eq 'csvuploadmap' && $perm{'mgr'} ) {
1.616 www 9293: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 9294: $request->print(&csvuploadmap($request,$symb));
1.246 albertel 9295: } elsif ($command eq 'csvuploadoptions' && $perm{'mgr'}) {
1.257 albertel 9296: if ($env{'form.associate'} ne 'Reverse Association') {
1.616 www 9297: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 9298: $request->print(&csvuploadoptions($request,$symb));
1.41 ng 9299: } else {
1.257 albertel 9300: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
9301: $env{'form.upfile_associate'} = 'reverse';
1.41 ng 9302: } else {
1.257 albertel 9303: $env{'form.upfile_associate'} = 'forward';
1.41 ng 9304: }
1.616 www 9305: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 9306: $request->print(&csvuploadmap($request,$symb));
1.41 ng 9307: }
1.246 albertel 9308: } elsif ($command eq 'csvuploadassign' && $perm{'mgr'} ) {
1.616 www 9309: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 9310: $request->print(&csvuploadassign($request,$symb));
1.106 albertel 9311: } elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
1.616 www 9312: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.612 www 9313: $request->print(&scantron_selectphase($request,undef,$symb));
1.203 albertel 9314: } elsif ($command eq 'scantron_warning' && $perm{'mgr'}) {
1.616 www 9315: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 9316: $request->print(&scantron_do_warning($request,$symb));
1.142 albertel 9317: } elsif ($command eq 'scantron_validate' && $perm{'mgr'}) {
1.616 www 9318: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 9319: $request->print(&scantron_validate_file($request,$symb));
1.106 albertel 9320: } elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
1.616 www 9321: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 9322: $request->print(&scantron_process_students($request,$symb));
1.157 albertel 9323: } elsif ($command eq 'scantronupload' &&
1.257 albertel 9324: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
9325: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.616 www 9326: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 9327: $request->print(&scantron_upload_scantron_data($request,$symb));
1.157 albertel 9328: } elsif ($command eq 'scantronupload_save' &&
1.257 albertel 9329: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
9330: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.616 www 9331: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 9332: $request->print(&scantron_upload_scantron_data_save($request,$symb));
1.202 albertel 9333: } elsif ($command eq 'scantron_download' &&
1.257 albertel 9334: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.616 www 9335: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 9336: $request->print(&scantron_download_scantron_data($request,$symb));
1.523 raeburn 9337: } elsif ($command eq 'checksubmissions' && $perm{'vgr'}) {
1.616 www 9338: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.621 www 9339: $request->print(&checkscantron_results($request,$symb));
9340: } elsif ($command eq 'downloadfilesselect' && $perm{'vgr'}) {
9341: &startpage($request,$symb,[{href=>'', text=>'Select which submissions to download'}]);
9342: $request->print(&submit_options_download($request,$symb));
9343: } elsif ($command eq 'downloadfileslink' && $perm{'vgr'}) {
9344: &startpage($request,$symb,
9345: [{href=>&href_symb_cmd($symb,'downloadfilesselect'), text=>'Select which submissions to download'},
9346: {href=>'', text=>'Download submissions'}]);
9347: &submit_download_link($request,$symb);
1.106 albertel 9348: } elsif ($command) {
1.620 www 9349: &startpage($request,$symb,[{href=>'', text=>'Access denied'}]);
1.562 bisitz 9350: $request->print('<p class="LC_error">'.&mt('Access Denied ([_1])',$command).'</p>');
1.26 albertel 9351: }
1.2 albertel 9352: }
1.513 foxr 9353: if ($ssi_error) {
9354: &ssi_print_error($request);
9355: }
1.353 albertel 9356: $request->print(&Apache::loncommon::end_page());
1.434 albertel 9357: &reset_caches();
1.44 ng 9358: return '';
9359: }
9360:
1.1 albertel 9361: 1;
9362:
1.13 albertel 9363: __END__;
1.531 jms 9364:
9365:
9366: =head1 NAME
9367:
9368: Apache::grades
9369:
9370: =head1 SYNOPSIS
9371:
9372: Handles the viewing of grades.
9373:
9374: This is part of the LearningOnline Network with CAPA project
9375: described at http://www.lon-capa.org.
9376:
9377: =head1 OVERVIEW
9378:
9379: Do an ssi with retries:
9380: While I'd love to factor out this with the vesrion in lonprintout,
9381: 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
9382: I'm not quite ready to invent (e.g. an ssi_with_retry object).
9383:
9384: At least the logic that drives this has been pulled out into loncommon.
9385:
9386:
9387:
9388: ssi_with_retries - Does the server side include of a resource.
9389: if the ssi call returns an error we'll retry it up to
9390: the number of times requested by the caller.
9391: If we still have a proble, no text is appended to the
9392: output and we set some global variables.
9393: to indicate to the caller an SSI error occurred.
9394: All of this is supposed to deal with the issues described
9395: in LonCAPA BZ 5631 see:
9396: http://bugs.lon-capa.org/show_bug.cgi?id=5631
9397: by informing the user that this happened.
9398:
9399: Parameters:
9400: resource - The resource to include. This is passed directly, without
9401: interpretation to lonnet::ssi.
9402: form - The form hash parameters that guide the interpretation of the resource
9403:
9404: retries - Number of retries allowed before giving up completely.
9405: Returns:
9406: On success, returns the rendered resource identified by the resource parameter.
9407: Side Effects:
9408: The following global variables can be set:
9409: ssi_error - If an unrecoverable error occurred this becomes true.
9410: It is up to the caller to initialize this to false
9411: if desired.
9412: ssi_error_resource - If an unrecoverable error occurred, this is the value
9413: of the resource that could not be rendered by the ssi
9414: call.
9415: ssi_error_message - The error string fetched from the ssi response
9416: in the event of an error.
9417:
9418:
9419: =head1 HANDLER SUBROUTINE
9420:
9421: ssi_with_retries()
9422:
9423: =head1 SUBROUTINES
9424:
9425: =over
9426:
9427: =item scantron_get_correction() :
9428:
9429: Builds the interface screen to interact with the operator to fix a
9430: specific error condition in a specific scanline
9431:
9432: Arguments:
9433: $r - Apache request object
9434: $i - number of the current scanline
9435: $scan_record - hash ref as returned from &scantron_parse_scanline()
9436: $scan_config - hash ref as returned from &get_scantron_config()
9437: $line - full contents of the current scanline
9438: $error - error condition, valid values are
9439: 'incorrectCODE', 'duplicateCODE',
9440: 'doublebubble', 'missingbubble',
9441: 'duplicateID', 'incorrectID'
9442: $arg - extra information needed
9443: For errors:
9444: - duplicateID - paper number that this studentID was seen before on
9445: - duplicateCODE - array ref of the paper numbers this CODE was
9446: seen on before
9447: - incorrectCODE - current incorrect CODE
9448: - doublebubble - array ref of the bubble lines that have double
9449: bubble errors
9450: - missingbubble - array ref of the bubble lines that have missing
9451: bubble errors
9452:
9453: =item scantron_get_maxbubble() :
9454:
1.582 raeburn 9455: Arguments:
9456: $nav_error - Reference to scalar which is a flag to indicate a
9457: failure to retrieve a navmap object.
9458: if $nav_error is set to 1 by scantron_get_maxbubble(), the
9459: calling routine should trap the error condition and display the warning
9460: found in &navmap_errormsg().
9461:
1.531 jms 9462: Returns the maximum number of bubble lines that are expected to
9463: occur. Does this by walking the selected sequence rendering the
9464: resource and then checking &Apache::lonxml::get_problem_counter()
9465: for what the current value of the problem counter is.
9466:
9467: Caches the results to $env{'form.scantron_maxbubble'},
9468: $env{'form.scantron.bubble_lines.n'},
9469: $env{'form.scantron.first_bubble_line.n'} and
9470: $env{"form.scantron.sub_bubblelines.n"}
9471: which are the total number of bubble, lines, the number of bubble
9472: lines for response n and number of the first bubble line for response n,
9473: and a comma separated list of numbers of bubble lines for sub-questions
9474: (for optionresponse, matchresponse, and rankresponse items), for response n.
9475:
9476:
9477: =item scantron_validate_missingbubbles() :
9478:
9479: Validates all scanlines in the selected file to not have any
9480: answers that don't have bubbles that have not been verified
9481: to be bubble free.
9482:
9483: =item scantron_process_students() :
9484:
9485: Routine that does the actual grading of the bubble sheet information.
9486:
9487: The parsed scanline hash is added to %env
9488:
9489: Then foreach unskipped scanline it does an &Apache::lonnet::ssi()
9490: foreach resource , with the form data of
9491:
9492: 'submitted' =>'scantron'
9493: 'grade_target' =>'grade',
9494: 'grade_username'=> username of student
9495: 'grade_domain' => domain of student
9496: 'grade_courseid'=> of course
9497: 'grade_symb' => symb of resource to grade
9498:
9499: This triggers a grading pass. The problem grading code takes care
9500: of converting the bubbled letter information (now in %env) into a
9501: valid submission.
9502:
9503: =item scantron_upload_scantron_data() :
9504:
9505: Creates the screen for adding a new bubble sheet data file to a course.
9506:
9507: =item scantron_upload_scantron_data_save() :
9508:
9509: Adds a provided bubble information data file to the course if user
9510: has the correct privileges to do so.
9511:
9512: =item valid_file() :
9513:
9514: Validates that the requested bubble data file exists in the course.
9515:
9516: =item scantron_download_scantron_data() :
9517:
9518: Shows a list of the three internal files (original, corrected,
9519: skipped) for a specific bubble sheet data file that exists in the
9520: course.
9521:
9522: =item scantron_validate_ID() :
9523:
9524: Validates all scanlines in the selected file to not have any
1.556 weissno 9525: invalid or underspecified student/employee IDs
1.531 jms 9526:
1.582 raeburn 9527: =item navmap_errormsg() :
9528:
9529: Returns HTML mark-up inside a <div></div> with a link to re-initialize the course.
9530: Should be called whenever the request to instantiate a navmap object fails.
9531:
1.531 jms 9532: =back
9533:
9534: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>