Annotation of loncom/homework/grades.pm, revision 1.623
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.623 ! www 4: # $Id: grades.pm,v 1.622 2010/04/17 22:48:52 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.401 albertel 867: my $checkhdgrade = ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1 ) ? 'checked="checked"' : '';
868: my $checklastsub = $checkhdgrade eq '' ? 'checked="checked"' : '';
1.154 albertel 869: my $gradeTable='<form action="/adm/grades" method="post" name="gradesub">'.
1.598 www 870: "\n";
1.485 albertel 871:
1.561 bisitz 872: $gradeTable .= &Apache::lonhtmlcommon::start_pick_box();
873: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Problem Text'))
874: .'<label><input type="radio" name="vProb" value="no" checked="checked" /> '.&mt('no').' </label>'."\n"
875: .'<label><input type="radio" name="vProb" value="yes" /> '.&mt('one student').' </label>'."\n"
876: .'<label><input type="radio" name="vProb" value="all" /> '.&mt('all students').' </label><br />'."\n"
877: .&Apache::lonhtmlcommon::row_closure();
878: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Answer'))
879: .'<label><input type="radio" name="vAns" value="no" /> '.&mt('no').' </label>'."\n"
880: .'<label><input type="radio" name="vAns" value="yes" /> '.&mt('one student').' </label>'."\n"
881: .'<label><input type="radio" name="vAns" value="all" checked="checked" /> '.&mt('all students').' </label><br />'."\n"
882: .&Apache::lonhtmlcommon::row_closure();
1.485 albertel 883:
884: my $submission_options;
1.257 albertel 885: if ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1) {
1.485 albertel 886: $submission_options.=
887: '<label><input type="radio" name="lastSub" value="hdgrade" '.$checkhdgrade.' /> '.&mt('essay part only').' </label>'."\n";
1.49 albertel 888: }
1.442 banghart 889: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
890: my $saveStatus = $stu_status eq '' ? 'Active' : $stu_status;
1.257 albertel 891: $env{'form.Status'} = $saveStatus;
1.485 albertel 892: $submission_options.=
1.592 bisitz 893: '<span class="LC_nobreak">'.
894: '<label><input type="radio" name="lastSub" value="lastonly" '.$checklastsub.' /> '.
895: &mt('last submission only').' </label></span>'."\n".
896: '<span class="LC_nobreak">'.
897: '<label><input type="radio" name="lastSub" value="last" /> '.
898: &mt('last submission & parts info').' </label></span>'."\n".
899: '<span class="LC_nobreak">'.
900: '<label><input type="radio" name="lastSub" value="datesub" /> '.
901: &mt('by dates and submissions').'</label></span>'."\n".
902: '<span class="LC_nobreak">'.
903: '<label><input type="radio" name="lastSub" value="all" /> '.
904: &mt('all details').'</label></span>';
1.561 bisitz 905: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Submissions'))
906: .$submission_options
907: .&Apache::lonhtmlcommon::row_closure();
908:
909: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Grading Increments'))
910: .'<select name="increment">'
911: .'<option value="1">'.&mt('Whole Points').'</option>'
912: .'<option value=".5">'.&mt('Half Points').'</option>'
913: .'<option value=".25">'.&mt('Quarter Points').'</option>'
914: .'<option value=".1">'.&mt('Tenths of a Point').'</option>'
915: .'</select>'
916: .&Apache::lonhtmlcommon::row_closure();
1.485 albertel 917:
918: $gradeTable .=
1.432 banghart 919: &build_section_inputs().
1.45 ng 920: '<input type="hidden" name="submitonly" value="'.$submitonly.'" />'."\n".
1.257 albertel 921: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" /><br />'."\n".
1.418 albertel 922: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.110 ng 923: '<input type="hidden" name="saveStatusOld" value="'.$saveStatus.'" />'."\n";
924:
1.618 www 925: if (exists($env{'form.Status'})) {
1.561 bisitz 926: $gradeTable .= '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n";
1.124 ng 927: } else {
1.561 bisitz 928: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Student Status'))
929: .&Apache::lonhtmlcommon::StatusOptions(
930: $saveStatus,undef,1,'javascript:reLoadList(this.form);')
931: .&Apache::lonhtmlcommon::row_closure();
1.124 ng 932: }
1.112 ng 933:
1.561 bisitz 934: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Check For Plagiarism'))
935: .'<input type="checkbox" name="checkPlag" checked="checked" />'
936: .&Apache::lonhtmlcommon::row_closure(1)
937: .&Apache::lonhtmlcommon::end_pick_box();
938:
939: $gradeTable .= '<p>'
1.618 www 940: .&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 941: .'<input type="hidden" name="command" value="processGroup" />'
942: .'</p>';
1.249 albertel 943:
944: # checkall buttons
945: $gradeTable.=&check_script('gradesub', 'stuinfo');
1.110 ng 946: $gradeTable.='<input type="button" '."\n".
1.589 bisitz 947: 'onclick="javascript:checkSelect(this.form.stuinfo);" '."\n".
948: 'value="'.&mt('Next').' →" /> <br />'."\n";
1.249 albertel 949: $gradeTable.=&check_buttons();
1.450 banghart 950: my ($classlist, undef, $fullname) = &getclasslist($getsec,'1',$getgroup);
1.474 albertel 951: $gradeTable.= &Apache::loncommon::start_data_table().
952: &Apache::loncommon::start_data_table_header_row();
1.110 ng 953: my $loop = 0;
954: while ($loop < 2) {
1.485 albertel 955: $gradeTable.='<th>'.&mt('No.').'</th><th>'.&mt('Select').'</th>'.
956: '<th>'.&nameUserString('header').' '.&mt('Section/Group').'</th>';
1.618 www 957: if (($submitonly ne 'queued') && ($submitonly ne 'all')) {
1.485 albertel 958: foreach my $part (sort(@$partlist)) {
959: my $display_part=
960: &get_display_part((split(/_/,$part))[0],$symb);
961: $gradeTable.=
962: '<th>'.&mt('Part: [_1] Status',$display_part).'</th>';
1.110 ng 963: }
1.301 albertel 964: } elsif ($submitonly eq 'queued') {
1.474 albertel 965: $gradeTable.='<th>'.&mt('Queue Status').' </th>';
1.110 ng 966: }
967: $loop++;
1.126 ng 968: # $gradeTable.='<td></td>' if ($loop%2 ==1);
1.41 ng 969: }
1.474 albertel 970: $gradeTable.=&Apache::loncommon::end_data_table_header_row()."\n";
1.41 ng 971:
1.45 ng 972: my $ctr = 0;
1.294 albertel 973: foreach my $student (sort
974: {
975: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
976: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
977: }
978: return $a cmp $b;
979: }
980: (keys(%$fullname))) {
1.41 ng 981: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 982:
1.110 ng 983: my %status = ();
1.301 albertel 984:
985: if ($submitonly eq 'queued') {
986: my %queue_status =
987: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
988: $udom,$uname);
989: next if (!defined($queue_status{'gradingqueue'}));
990: $status{'gradingqueue'} = $queue_status{'gradingqueue'};
991: }
992:
1.618 www 993: if (($submitonly ne 'queued') && ($submitonly ne 'all')) {
1.324 albertel 994: (%status) =&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 995: my $submitted = 0;
1.164 albertel 996: my $graded = 0;
1.248 albertel 997: my $incorrect = 0;
1.110 ng 998: foreach (keys(%status)) {
1.145 albertel 999: $submitted = 1 if ($status{$_} ne 'nothing');
1.248 albertel 1000: $graded = 1 if ($status{$_} =~ /^ungraded/);
1001: $incorrect = 1 if ($status{$_} =~ /^incorrect/);
1002:
1.110 ng 1003: my ($foo,$partid,$foo1) = split(/\./,$_);
1004: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
1.145 albertel 1005: $submitted = 0;
1.150 albertel 1006: my ($part)=split(/\./,$partid);
1.110 ng 1007: $gradeTable.='<input type="hidden" name="'.
1.150 albertel 1008: $student.':'.$part.':submitted_by" value="'.
1.110 ng 1009: $status{'resource.'.$partid.'.submitted_by'}.'" />';
1010: }
1.41 ng 1011: }
1.248 albertel 1012:
1.156 albertel 1013: next if (!$submitted && ($submitonly eq 'yes' ||
1014: $submitonly eq 'incorrect' ||
1015: $submitonly eq 'graded'));
1.248 albertel 1016: next if (!$graded && ($submitonly eq 'graded'));
1017: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 1018: }
1.34 ng 1019:
1.45 ng 1020: $ctr++;
1.249 albertel 1021: my $section = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
1.452 banghart 1022: my $group = $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1.104 albertel 1023: if ( $perm{'vgr'} eq 'F' ) {
1.474 albertel 1024: if ($ctr%2 ==1) {
1025: $gradeTable.= &Apache::loncommon::start_data_table_row();
1026: }
1.126 ng 1027: $gradeTable.='<td align="right">'.$ctr.' </td>'.
1.563 bisitz 1028: '<td align="center"><label><input type="checkbox" name="stuinfo" value="'.
1.249 albertel 1029: $student.':'.$$fullname{$student}.':::SECTION'.$section.
1030: ') " /> </label></td>'."\n".'<td>'.
1031: &nameUserString(undef,$$fullname{$student},$uname,$udom).
1.474 albertel 1032: ' '.$section.($group ne '' ?'/'.$group:'').'</td>'."\n";
1.110 ng 1033:
1.618 www 1034: if ($submitonly ne 'all') {
1.524 raeburn 1035: foreach (sort(keys(%status))) {
1.485 albertel 1036: next if ($_ =~ /^resource.*?submitted_by$/);
1037: $gradeTable.='<td align="center"> '.&mt($status{$_}).' </td>'."\n";
1.110 ng 1038: }
1.41 ng 1039: }
1.126 ng 1040: # $gradeTable.='<td></td>' if ($ctr%2 ==1);
1.474 albertel 1041: if ($ctr%2 ==0) {
1042: $gradeTable.=&Apache::loncommon::end_data_table_row()."\n";
1043: }
1.41 ng 1044: }
1045: }
1.110 ng 1046: if ($ctr%2 ==1) {
1.126 ng 1047: $gradeTable.='<td> </td><td> </td><td> </td>';
1.618 www 1048: if (($submitonly ne 'queued') && ($submitonly ne 'all')) {
1.110 ng 1049: foreach (@$partlist) {
1050: $gradeTable.='<td> </td>';
1051: }
1.301 albertel 1052: } elsif ($submitonly eq 'queued') {
1053: $gradeTable.='<td> </td>';
1.110 ng 1054: }
1.474 albertel 1055: $gradeTable.=&Apache::loncommon::end_data_table_row();
1.110 ng 1056: }
1057:
1.474 albertel 1058: $gradeTable.=&Apache::loncommon::end_data_table()."\n".
1.589 bisitz 1059: '<input type="button" '.
1060: 'onclick="javascript:checkSelect(this.form.stuinfo);" '.
1061: 'value="'.&mt('Next').' →" /></form>'."\n";
1.45 ng 1062: if ($ctr == 0) {
1.96 albertel 1063: my $num_students=(scalar(keys(%$fullname)));
1064: if ($num_students eq 0) {
1.485 albertel 1065: $gradeTable='<br /> <span class="LC_warning">'.&mt('There are no students currently enrolled.').'</span>';
1.96 albertel 1066: } else {
1.171 albertel 1067: my $submissions='submissions';
1068: if ($submitonly eq 'incorrect') { $submissions = 'incorrect submissions'; }
1069: if ($submitonly eq 'graded' ) { $submissions = 'ungraded submissions'; }
1.301 albertel 1070: if ($submitonly eq 'queued' ) { $submissions = 'queued submissions'; }
1.398 albertel 1071: $gradeTable='<br /> <span class="LC_warning">'.
1.485 albertel 1072: &mt('No '.$submissions.' found for this resource for any students. ([_1] students checked for '.$submissions.')',
1073: $num_students).
1074: '</span><br />';
1.96 albertel 1075: }
1.46 ng 1076: } elsif ($ctr == 1) {
1.474 albertel 1077: $gradeTable =~ s/type="checkbox"/type="checkbox" checked="checked"/;
1.45 ng 1078: }
1079: $request->print($gradeTable);
1.44 ng 1080: return '';
1.10 ng 1081: }
1082:
1.44 ng 1083: #---- Called from the listStudents routine
1.249 albertel 1084:
1085: sub check_script {
1086: my ($form, $type)=@_;
1.597 wenzelju 1087: my $chkallscript= &Apache::lonhtmlcommon::scripttag('
1.249 albertel 1088: function checkall() {
1089: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1090: ele = document.forms.'.$form.'.elements[i];
1091: if (ele.name == "'.$type.'") {
1092: document.forms.'.$form.'.elements[i].checked=true;
1093: }
1094: }
1095: }
1096:
1097: function checksec() {
1098: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1099: ele = document.forms.'.$form.'.elements[i];
1100: string = document.forms.'.$form.'.chksec.value;
1101: if
1102: (ele.value.indexOf(":::SECTION"+string)>0) {
1103: document.forms.'.$form.'.elements[i].checked=true;
1104: }
1105: }
1106: }
1107:
1108:
1109: function uncheckall() {
1110: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1111: ele = document.forms.'.$form.'.elements[i];
1112: if (ele.name == "'.$type.'") {
1113: document.forms.'.$form.'.elements[i].checked=false;
1114: }
1115: }
1116: }
1117:
1.597 wenzelju 1118: '."\n");
1.249 albertel 1119: return $chkallscript;
1120: }
1121:
1122: sub check_buttons {
1.485 albertel 1123: my $buttons.='<input type="button" onclick="checkall()" value="'.&mt('Check All').'" />';
1124: $buttons.='<input type="button" onclick="uncheckall()" value="'.&mt('Uncheck All').'" /> ';
1125: $buttons.='<input type="button" onclick="checksec()" value="'.&mt('Check Section/Group').'" />';
1.249 albertel 1126: $buttons.='<input type="text" size="5" name="chksec" /> ';
1127: return $buttons;
1128: }
1129:
1.44 ng 1130: # Displays the submissions for one student or a group of students
1.34 ng 1131: sub processGroup {
1.619 www 1132: my ($request,$symb) = @_;
1.41 ng 1133: my $ctr = 0;
1.155 albertel 1134: my @stuchecked = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.41 ng 1135: my $total = scalar(@stuchecked)-1;
1.45 ng 1136:
1.396 banghart 1137: foreach my $student (@stuchecked) {
1138: my ($uname,$udom,$fullname) = split(/:/,$student);
1.257 albertel 1139: $env{'form.student'} = $uname;
1140: $env{'form.userdom'} = $udom;
1141: $env{'form.fullname'} = $fullname;
1.619 www 1142: &submission($request,$ctr,$total,$symb);
1.41 ng 1143: $ctr++;
1144: }
1145: return '';
1.35 ng 1146: }
1.34 ng 1147:
1.44 ng 1148: #------------------------------------------------------------------------------------
1149: #
1150: #-------------------------- Next few routines handles grading by student, essentially
1151: # handles essay response type problem/part
1152: #
1153: #--- Javascript to handle the submission page functionality ---
1154: sub sub_page_js {
1155: my $request = shift;
1.539 riegler 1156: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
1.597 wenzelju 1157: $request->print(&Apache::lonhtmlcommon::scripttag(<<SUBJAVASCRIPT));
1.71 ng 1158: function updateRadio(formname,id,weight) {
1.125 ng 1159: var gradeBox = formname["GD_BOX"+id];
1160: var radioButton = formname["RADVAL"+id];
1161: var oldpts = formname["oldpts"+id].value;
1.72 ng 1162: var pts = checkSolved(formname,id) == 'update' ? gradeBox.value : oldpts;
1.71 ng 1163: gradeBox.value = pts;
1164: var resetbox = false;
1165: if (isNaN(pts) || pts < 0) {
1.539 riegler 1166: alert("$alertmsg"+pts);
1.71 ng 1167: for (var i=0; i<radioButton.length; i++) {
1168: if (radioButton[i].checked) {
1169: gradeBox.value = i;
1170: resetbox = true;
1171: }
1172: }
1173: if (!resetbox) {
1174: formtextbox.value = "";
1175: }
1176: return;
1.44 ng 1177: }
1.71 ng 1178:
1179: if (pts > weight) {
1180: var resp = confirm("You entered a value ("+pts+
1181: ") greater than the weight for the part. Accept?");
1182: if (resp == false) {
1.125 ng 1183: gradeBox.value = oldpts;
1.71 ng 1184: return;
1185: }
1.44 ng 1186: }
1.13 albertel 1187:
1.71 ng 1188: for (var i=0; i<radioButton.length; i++) {
1189: radioButton[i].checked=false;
1190: if (pts == i && pts != "") {
1191: radioButton[i].checked=true;
1192: }
1193: }
1194: updateSelect(formname,id);
1.125 ng 1195: formname["stores"+id].value = "0";
1.41 ng 1196: }
1.5 albertel 1197:
1.72 ng 1198: function writeBox(formname,id,pts) {
1.125 ng 1199: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1200: if (checkSolved(formname,id) == 'update') {
1201: gradeBox.value = pts;
1202: } else {
1.125 ng 1203: var oldpts = formname["oldpts"+id].value;
1.72 ng 1204: gradeBox.value = oldpts;
1.125 ng 1205: var radioButton = formname["RADVAL"+id];
1.71 ng 1206: for (var i=0; i<radioButton.length; i++) {
1207: radioButton[i].checked=false;
1.72 ng 1208: if (i == oldpts) {
1.71 ng 1209: radioButton[i].checked=true;
1210: }
1211: }
1.41 ng 1212: }
1.125 ng 1213: formname["stores"+id].value = "0";
1.71 ng 1214: updateSelect(formname,id);
1215: return;
1.41 ng 1216: }
1.44 ng 1217:
1.71 ng 1218: function clearRadBox(formname,id) {
1219: if (checkSolved(formname,id) == 'noupdate') {
1220: updateSelect(formname,id);
1221: return;
1222: }
1.125 ng 1223: gradeSelect = formname["GD_SEL"+id];
1.71 ng 1224: for (var i=0; i<gradeSelect.length; i++) {
1225: if (gradeSelect[i].selected) {
1226: var selectx=i;
1227: }
1228: }
1.125 ng 1229: var stores = formname["stores"+id];
1.71 ng 1230: if (selectx == stores.value) { return };
1.125 ng 1231: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1232: gradeBox.value = "";
1.125 ng 1233: var radioButton = formname["RADVAL"+id];
1.71 ng 1234: for (var i=0; i<radioButton.length; i++) {
1235: radioButton[i].checked=false;
1236: }
1237: stores.value = selectx;
1238: }
1.5 albertel 1239:
1.71 ng 1240: function checkSolved(formname,id) {
1.125 ng 1241: if (formname["solved"+id].value == "correct_by_student" && formname.overRideScore.value == 'no') {
1.118 ng 1242: var reply = confirm("This problem has been graded correct by the computer. Do you want to change the score?");
1243: if (!reply) {return "noupdate";}
1.120 ng 1244: formname.overRideScore.value = 'yes';
1.41 ng 1245: }
1.71 ng 1246: return "update";
1.13 albertel 1247: }
1.71 ng 1248:
1249: function updateSelect(formname,id) {
1.125 ng 1250: formname["GD_SEL"+id][0].selected = true;
1.71 ng 1251: return;
1.41 ng 1252: }
1.33 ng 1253:
1.121 ng 1254: //=========== Check that a point is assigned for all the parts ============
1.71 ng 1255: function checksubmit(formname,val,total,parttot) {
1.121 ng 1256: formname.gradeOpt.value = val;
1.71 ng 1257: if (val == "Save & Next") {
1258: for (i=0;i<=total;i++) {
1259: for (j=0;j<parttot;j++) {
1.125 ng 1260: var partid = formname["partid"+i+"_"+j].value;
1.127 ng 1261: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1262: var points = formname["GD_BOX"+i+"_"+partid].value;
1.71 ng 1263: if (points == "") {
1.125 ng 1264: var name = formname["name"+i].value;
1.129 ng 1265: var studentID = (name != '' ? name : formname["unamedom"+i].value);
1266: var resp = confirm("You did not assign a score for "+studentID+
1267: ", part "+partid+". Continue?");
1.71 ng 1268: if (resp == false) {
1.125 ng 1269: formname["GD_BOX"+i+"_"+partid].focus();
1.71 ng 1270: return false;
1271: }
1272: }
1273: }
1274:
1275: }
1276: }
1277:
1278: }
1.121 ng 1279: if (val == "Grade Student") {
1280: if (formname.Status.value == "") {
1281: formname.Status.value = "Active";
1282: }
1283: formname.studentNo.value = total;
1284: }
1.120 ng 1285: formname.submit();
1286: }
1287:
1.71 ng 1288: //======= Check that a score is assigned for all the problems (page/sequence grading only) =========
1289: function checkSubmitPage(formname,total) {
1290: noscore = new Array(100);
1291: var ptr = 0;
1292: for (i=1;i<total;i++) {
1.125 ng 1293: var partid = formname["q_"+i].value;
1.127 ng 1294: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1295: var points = formname["GD_BOX"+i+"_"+partid].value;
1296: var status = formname["solved"+i+"_"+partid].value;
1.71 ng 1297: if (points == "" && status != "correct_by_student") {
1298: noscore[ptr] = i;
1299: ptr++;
1300: }
1301: }
1302: }
1303: if (ptr != 0) {
1304: var sense = ptr == 1 ? ": " : "s: ";
1305: var prolist = "";
1306: if (ptr == 1) {
1307: prolist = noscore[0];
1308: } else {
1309: var i = 0;
1310: while (i < ptr-1) {
1311: prolist += noscore[i]+", ";
1312: i++;
1313: }
1314: prolist += "and "+noscore[i];
1315: }
1316: var resp = confirm("You did not assign any score for the following problem"+sense+prolist+". Continue?");
1317: if (resp == false) {
1318: return false;
1319: }
1320: }
1.45 ng 1321:
1.71 ng 1322: formname.submit();
1323: }
1324: SUBJAVASCRIPT
1325: }
1.45 ng 1326:
1.71 ng 1327: #--- javascript for essay type problem --
1328: sub sub_page_kw_js {
1329: my $request = shift;
1.80 ng 1330: my $iconpath = $request->dir_config('lonIconsURL');
1.118 ng 1331: &commonJSfunctions($request);
1.350 albertel 1332:
1.597 wenzelju 1333: my $inner_js_msg_central= &Apache::lonhtmlcommon::scripttag(<<INNERJS);
1.350 albertel 1334: function checkInput() {
1335: opener.document.SCORE.msgsub.value = opener.checkEntities(document.msgcenter.msgsub.value);
1336: var nmsg = opener.document.SCORE.savemsgN.value;
1337: var usrctr = document.msgcenter.usrctr.value;
1338: var newval = opener.document.SCORE["newmsg"+usrctr];
1339: newval.value = opener.checkEntities(document.msgcenter.newmsg.value);
1340:
1341: var msgchk = "";
1342: if (document.msgcenter.subchk.checked) {
1343: msgchk = "msgsub,";
1344: }
1345: var includemsg = 0;
1346: for (var i=1; i<=nmsg; i++) {
1347: var opnmsg = opener.document.SCORE["savemsg"+i];
1348: var frmmsg = document.msgcenter["msg"+i];
1349: opnmsg.value = opener.checkEntities(frmmsg.value);
1350: var showflg = opener.document.SCORE["shownOnce"+i];
1351: showflg.value = "1";
1352: var chkbox = document.msgcenter["msgn"+i];
1353: if (chkbox.checked) {
1354: msgchk += "savemsg"+i+",";
1355: includemsg = 1;
1356: }
1357: }
1358: if (document.msgcenter.newmsgchk.checked) {
1359: msgchk += "newmsg"+usrctr;
1360: includemsg = 1;
1361: }
1362: imgformname = opener.document.SCORE["mailicon"+usrctr];
1363: imgformname.src = "$iconpath/"+((includemsg) ? "mailto.gif" : "mailbkgrd.gif");
1364: var includemsg = opener.document.SCORE["includemsg"+usrctr];
1365: includemsg.value = msgchk;
1366:
1367: self.close()
1368:
1369: }
1370: INNERJS
1371:
1.597 wenzelju 1372: my $inner_js_highlight_central= &Apache::lonhtmlcommon::scripttag(<<INNERJS);
1.351 albertel 1373: function updateChoice(flag) {
1374: opener.document.SCORE.kwclr.value = opener.radioSelection(document.hlCenter.kwdclr);
1375: opener.document.SCORE.kwsize.value = opener.radioSelection(document.hlCenter.kwdsize);
1376: opener.document.SCORE.kwstyle.value = opener.radioSelection(document.hlCenter.kwdstyle);
1377: opener.document.SCORE.refresh.value = "on";
1378: if (opener.document.SCORE.keywords.value!=""){
1379: opener.document.SCORE.submit();
1380: }
1381: self.close()
1382: }
1383: INNERJS
1384:
1385: my $start_page_msg_central =
1386: &Apache::loncommon::start_page('Message Central',$inner_js_msg_central,
1387: {'js_ready' => 1,
1388: 'only_body' => 1,
1389: 'bgcolor' =>'#FFFFFF',});
1390: my $end_page_msg_central =
1391: &Apache::loncommon::end_page({'js_ready' => 1});
1392:
1393:
1394: my $start_page_highlight_central =
1395: &Apache::loncommon::start_page('Highlight Central',
1396: $inner_js_highlight_central,
1.350 albertel 1397: {'js_ready' => 1,
1398: 'only_body' => 1,
1399: 'bgcolor' =>'#FFFFFF',});
1.351 albertel 1400: my $end_page_highlight_central =
1.350 albertel 1401: &Apache::loncommon::end_page({'js_ready' => 1});
1402:
1.219 www 1403: my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
1.236 albertel 1404: $docopen=~s/^document\.//;
1.539 riegler 1405: my $alertmsg = &mt('Please select a word or group of words from document and then click this link.');
1.597 wenzelju 1406: $request->print(&Apache::lonhtmlcommon::scripttag(<<SUBJAVASCRIPT));
1.45 ng 1407:
1.44 ng 1408: //===================== Show list of keywords ====================
1.122 ng 1409: function keywords(formname) {
1410: var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",formname.keywords.value);
1.44 ng 1411: if (nret==null) return;
1.122 ng 1412: formname.keywords.value = nret;
1.44 ng 1413:
1.122 ng 1414: if (formname.keywords.value != "") {
1.128 ng 1415: formname.refresh.value = "on";
1.122 ng 1416: formname.submit();
1.44 ng 1417: }
1418: return;
1419: }
1420:
1421: //===================== Script to view submitted by ==================
1422: function viewSubmitter(submitter) {
1423: document.SCORE.refresh.value = "on";
1424: document.SCORE.NCT.value = "1";
1425: document.SCORE.unamedom0.value = submitter;
1426: document.SCORE.submit();
1427: return;
1428: }
1429:
1430: //===================== Script to add keyword(s) ==================
1431: function getSel() {
1432: if (document.getSelection) txt = document.getSelection();
1433: else if (document.selection) txt = document.selection.createRange().text;
1434: else return;
1435: var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
1436: if (cleantxt=="") {
1.539 riegler 1437: alert("$alertmsg");
1.44 ng 1438: return;
1439: }
1440: var nret = prompt("Add selection to keyword list? Edit if desired.",cleantxt);
1441: if (nret==null) return;
1.127 ng 1442: document.SCORE.keywords.value = document.SCORE.keywords.value+" "+nret;
1.44 ng 1443: if (document.SCORE.keywords.value != "") {
1.127 ng 1444: document.SCORE.refresh.value = "on";
1.44 ng 1445: document.SCORE.submit();
1446: }
1447: return;
1448: }
1449:
1450: //====================== Script for composing message ==============
1.80 ng 1451: // preload images
1452: img1 = new Image();
1453: img1.src = "$iconpath/mailbkgrd.gif";
1454: img2 = new Image();
1455: img2.src = "$iconpath/mailto.gif";
1456:
1.44 ng 1457: function msgCenter(msgform,usrctr,fullname) {
1458: var Nmsg = msgform.savemsgN.value;
1459: savedMsgHeader(Nmsg,usrctr,fullname);
1460: var subject = msgform.msgsub.value;
1.127 ng 1461: var msgchk = document.SCORE["includemsg"+usrctr].value;
1.44 ng 1462: re = /msgsub/;
1463: var shwsel = "";
1464: if (re.test(msgchk)) { shwsel = "checked" }
1.123 ng 1465: subject = (document.SCORE.shownSub.value == 0 ? checkEntities(subject) : subject);
1466: displaySubject(checkEntities(subject),shwsel);
1.44 ng 1467: for (var i=1; i<=Nmsg; i++) {
1.123 ng 1468: var testmsg = "savemsg"+i+",";
1469: re = new RegExp(testmsg,"g");
1.44 ng 1470: shwsel = "";
1471: if (re.test(msgchk)) { shwsel = "checked" }
1.125 ng 1472: var message = document.SCORE["savemsg"+i].value;
1.126 ng 1473: message = (document.SCORE["shownOnce"+i].value == 0 ? checkEntities(message) : message);
1.123 ng 1474: displaySavedMsg(i,message,shwsel); //I do not get it. w/o checkEntities on saved messages,
1475: //any < is already converted to <, etc. However, only once!!
1.44 ng 1476: }
1.125 ng 1477: newmsg = document.SCORE["newmsg"+usrctr].value;
1.44 ng 1478: shwsel = "";
1479: re = /newmsg/;
1480: if (re.test(msgchk)) { shwsel = "checked" }
1481: newMsg(newmsg,shwsel);
1482: msgTail();
1483: return;
1484: }
1485:
1.123 ng 1486: function checkEntities(strx) {
1487: if (strx.length == 0) return strx;
1488: var orgStr = ["&", "<", ">", '"'];
1489: var newStr = ["&", "<", ">", """];
1490: var counter = 0;
1491: while (counter < 4) {
1492: strx = strReplace(strx,orgStr[counter],newStr[counter]);
1493: counter++;
1494: }
1495: return strx;
1496: }
1497:
1498: function strReplace(strx, orgStr, newStr) {
1499: return strx.split(orgStr).join(newStr);
1500: }
1501:
1.44 ng 1502: function savedMsgHeader(Nmsg,usrctr,fullname) {
1.76 ng 1503: var height = 70*Nmsg+250;
1.44 ng 1504: var scrollbar = "no";
1505: if (height > 600) {
1506: height = 600;
1507: scrollbar = "yes";
1508: }
1.118 ng 1509: var xpos = (screen.width-600)/2;
1510: xpos = (xpos < 0) ? '0' : xpos;
1511: var ypos = (screen.height-height)/2-30;
1512: ypos = (ypos < 0) ? '0' : ypos;
1513:
1.206 albertel 1514: pWin = window.open('', 'MessageCenter', 'resizable=yes,toolbar=no,location=no,scrollbars='+scrollbar+',screenx='+xpos+',screeny='+ypos+',width=600,height='+height);
1.76 ng 1515: pWin.focus();
1516: pDoc = pWin.document;
1.219 www 1517: pDoc.$docopen;
1.351 albertel 1518: pDoc.write('$start_page_msg_central');
1.76 ng 1519:
1520: pDoc.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
1521: pDoc.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
1.465 albertel 1522: pDoc.write("<h3><span class=\\"LC_info\\"> Compose Message for \"+fullname+\"<\\/span><\\/h3><br /><br />");
1.76 ng 1523:
1.564 bisitz 1524: pDoc.write('<table border="0" width="100%"><tr><td bgcolor="#777777">');
1525: pDoc.write('<table border="0" width="100%"><tr bgcolor="#DDFFFF">');
1.465 albertel 1526: pDoc.write("<td><b>Type<\\/b><\\/td><td><b>Include<\\/b><\\/td><td><b>Message<\\/td><\\/tr>");
1.44 ng 1527: }
1528: function displaySubject(msg,shwsel) {
1.76 ng 1529: pDoc = pWin.document;
1530: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.465 albertel 1531: pDoc.write("<td>Subject<\\/td>");
1532: pDoc.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1533: pDoc.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+"\\"size=\\"60\\" maxlength=\\"80\\"><\\/td><\\/tr>");
1.44 ng 1534: }
1535:
1.72 ng 1536: function displaySavedMsg(ctr,msg,shwsel) {
1.76 ng 1537: pDoc = pWin.document;
1538: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.465 albertel 1539: pDoc.write("<td align=\\"center\\">"+ctr+"<\\/td>");
1540: pDoc.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1541: pDoc.write("<td><textarea name=\\"msg"+ctr+"\\" cols=\\"60\\" rows=\\"3\\">"+msg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 1542: }
1543:
1544: function newMsg(newmsg,shwsel) {
1.76 ng 1545: pDoc = pWin.document;
1546: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.465 albertel 1547: pDoc.write("<td align=\\"center\\">New<\\/td>");
1548: pDoc.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1549: pDoc.write("<td><textarea name=\\"newmsg\\" cols=\\"60\\" rows=\\"3\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" >"+newmsg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 1550: }
1551:
1552: function msgTail() {
1.76 ng 1553: pDoc = pWin.document;
1.465 albertel 1554: pDoc.write("<\\/table>");
1555: pDoc.write("<\\/td><\\/tr><\\/table> ");
1.589 bisitz 1556: pDoc.write("<input type=\\"button\\" value=\\"Save\\" onclick=\\"javascript:checkInput()\\"> ");
1557: pDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onclick=\\"self.close()\\"><br /><br />");
1.465 albertel 1558: pDoc.write("<\\/form>");
1.351 albertel 1559: pDoc.write('$end_page_msg_central');
1.128 ng 1560: pDoc.close();
1.44 ng 1561: }
1562:
1563: //====================== Script for keyword highlight options ==============
1564: function kwhighlight() {
1565: var kwclr = document.SCORE.kwclr.value;
1566: var kwsize = document.SCORE.kwsize.value;
1567: var kwstyle = document.SCORE.kwstyle.value;
1568: var redsel = "";
1569: var grnsel = "";
1570: var blusel = "";
1571: if (kwclr=="red") {var redsel="checked"};
1572: if (kwclr=="green") {var grnsel="checked"};
1573: if (kwclr=="blue") {var blusel="checked"};
1574: var sznsel = "";
1575: var sz1sel = "";
1576: var sz2sel = "";
1577: if (kwsize=="0") {var sznsel="checked"};
1578: if (kwsize=="+1") {var sz1sel="checked"};
1579: if (kwsize=="+2") {var sz2sel="checked"};
1580: var synsel = "";
1581: var syisel = "";
1582: var sybsel = "";
1583: if (kwstyle=="") {var synsel="checked"};
1584: if (kwstyle=="<i>") {var syisel="checked"};
1585: if (kwstyle=="<b>") {var sybsel="checked"};
1586: highlightCentral();
1587: highlightbody('red','red',redsel,'0','normal',sznsel,'','normal',synsel);
1588: highlightbody('green','green',grnsel,'+1','+1',sz1sel,'<i>','italic',syisel);
1589: highlightbody('blue','blue',blusel,'+2','+2',sz2sel,'<b>','bold',sybsel);
1590: highlightend();
1591: return;
1592: }
1593:
1594: function highlightCentral() {
1.76 ng 1595: // if (window.hwdWin) window.hwdWin.close();
1.118 ng 1596: var xpos = (screen.width-400)/2;
1597: xpos = (xpos < 0) ? '0' : xpos;
1598: var ypos = (screen.height-330)/2-30;
1599: ypos = (ypos < 0) ? '0' : ypos;
1600:
1.206 albertel 1601: hwdWin = window.open('', 'KeywordHighlightCentral', 'resizeable=yes,toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx='+xpos+',screeny='+ypos);
1.76 ng 1602: hwdWin.focus();
1603: var hDoc = hwdWin.document;
1.219 www 1604: hDoc.$docopen;
1.351 albertel 1605: hDoc.write('$start_page_highlight_central');
1.76 ng 1606: hDoc.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
1.465 albertel 1607: hDoc.write("<h3><span class=\\"LC_info\\"> Keyword Highlight Options<\\/span><\\/h3><br /><br />");
1.76 ng 1608:
1.564 bisitz 1609: hDoc.write('<table border="0" width="100%"><tr><td bgcolor="#777777">');
1610: hDoc.write('<table border="0" width="100%"><tr bgcolor="#DDFFFF">');
1.465 albertel 1611: hDoc.write("<td><b>Text Color<\\/b><\\/td><td><b>Font Size<\\/b><\\/td><td><b>Font Style<\\/td><\\/tr>");
1.44 ng 1612: }
1613:
1614: function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) {
1.76 ng 1615: var hDoc = hwdWin.document;
1616: hDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1617: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1618: hDoc.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+"> "+clrtxt+"<\\/td>");
1.76 ng 1619: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1620: hDoc.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+"> "+sztxt+"<\\/td>");
1.76 ng 1621: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1622: hDoc.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+"> "+sytxt+"<\\/td>");
1623: hDoc.write("<\\/tr>");
1.44 ng 1624: }
1625:
1626: function highlightend() {
1.76 ng 1627: var hDoc = hwdWin.document;
1.465 albertel 1628: hDoc.write("<\\/table>");
1629: hDoc.write("<\\/td><\\/tr><\\/table> ");
1.589 bisitz 1630: hDoc.write("<input type=\\"button\\" value=\\"Save\\" onclick=\\"javascript:updateChoice(1)\\"> ");
1631: hDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onclick=\\"self.close()\\"><br /><br />");
1.465 albertel 1632: hDoc.write("<\\/form>");
1.351 albertel 1633: hDoc.write('$end_page_highlight_central');
1.128 ng 1634: hDoc.close();
1.44 ng 1635: }
1636:
1637: SUBJAVASCRIPT
1638: }
1639:
1.349 albertel 1640: sub get_increment {
1.348 bowersj2 1641: my $increment = $env{'form.increment'};
1642: if ($increment != 1 && $increment != .5 && $increment != .25 &&
1643: $increment != .1) {
1644: $increment = 1;
1645: }
1646: return $increment;
1647: }
1648:
1.585 bisitz 1649: sub gradeBox_start {
1650: return (
1651: &Apache::loncommon::start_data_table()
1652: .&Apache::loncommon::start_data_table_header_row()
1653: .'<th>'.&mt('Part').'</th>'
1654: .'<th>'.&mt('Points').'</th>'
1655: .'<th> </th>'
1656: .'<th>'.&mt('Assign Grade').'</th>'
1657: .'<th>'.&mt('Weight').'</th>'
1658: .'<th>'.&mt('Grade Status').'</th>'
1659: .&Apache::loncommon::end_data_table_header_row()
1660: );
1661: }
1662:
1663: sub gradeBox_end {
1664: return (
1665: &Apache::loncommon::end_data_table()
1666: );
1667: }
1.71 ng 1668: #--- displays the grading box, used in essay type problem and grading by page/sequence
1669: sub gradeBox {
1.322 albertel 1670: my ($request,$symb,$uname,$udom,$counter,$partid,$record) = @_;
1.381 albertel 1671: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 1672: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 1673: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
1.466 albertel 1674: my $wgtmsg = ($wgt > 0) ? &mt('(problem weight)')
1675: : '<span class="LC_info">'.&mt('problem weight assigned by computer').'</span>';
1.71 ng 1676: $wgt = ($wgt > 0 ? $wgt : '1');
1677: my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
1.320 albertel 1678: '' : &compute_points($$record{'resource.'.$partid.'.awarded'},$wgt));
1.71 ng 1679: my $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />'."\n";
1.466 albertel 1680: my $display_part= &get_display_part($partid,$symb);
1.270 albertel 1681: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
1682: [$partid]);
1683: my $aggtries = $$record{'resource.'.$partid.'.tries'};
1.269 raeburn 1684: if ($last_resets{$partid}) {
1685: $aggtries = &get_num_tries($record,$last_resets{$partid},$partid);
1686: }
1.585 bisitz 1687: $result.=&Apache::loncommon::start_data_table_row();
1.71 ng 1688: my $ctr = 0;
1.348 bowersj2 1689: my $thisweight = 0;
1.349 albertel 1690: my $increment = &get_increment();
1.485 albertel 1691:
1692: my $radio.='<table border="0"><tr>'."\n"; # display radio buttons in a nice table 10 across
1.348 bowersj2 1693: while ($thisweight<=$wgt) {
1.532 bisitz 1694: $radio.= '<td><span class="LC_nobreak"><label><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
1.589 bisitz 1695: 'onclick="javascript:writeBox(this.form,\''.$counter.'_'.$partid.'\','.
1.348 bowersj2 1696: $thisweight.')" value="'.$thisweight.'" '.
1.401 albertel 1697: ($score eq $thisweight ? 'checked="checked"':'').' /> '.$thisweight."</label></span></td>\n";
1.485 albertel 1698: $radio.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1.348 bowersj2 1699: $thisweight += $increment;
1.71 ng 1700: $ctr++;
1701: }
1.485 albertel 1702: $radio.='</tr></table>';
1703:
1704: my $line.='<input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
1.71 ng 1705: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
1.589 bisitz 1706: 'onchange="javascript:updateRadio(this.form,\''.$counter.'_'.$partid.'\','.
1.71 ng 1707: $wgt.')" /></td>'."\n";
1.485 albertel 1708: $line.='<td>/'.$wgt.' '.$wgtmsg.
1.71 ng 1709: ($$record{'resource.'.$partid.'.solved'} eq 'correct_by_student' ? ' '.$checkIcon : '').
1.585 bisitz 1710: ' </td>'."\n";
1711: $line.='<td><select name="GD_SEL'.$counter.'_'.$partid.'" '.
1.589 bisitz 1712: 'onchange="javascript:clearRadBox(this.form,\''.$counter.'_'.$partid.'\')" >'."\n";
1.71 ng 1713: if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
1.485 albertel 1714: $line.='<option></option>'.
1715: '<option value="excused" selected="selected">'.&mt('excused').'</option>';
1.71 ng 1716: } else {
1.485 albertel 1717: $line.='<option selected="selected"></option>'.
1718: '<option value="excused" >'.&mt('excused').'</option>';
1.71 ng 1719: }
1.485 albertel 1720: $line.='<option value="reset status">'.&mt('reset status').'</option></select>'."\n";
1721:
1722:
1723: $result .=
1.585 bisitz 1724: '<td>'.$display_part.'</td><td>'.$radio.'</td><td>'.&mt('or').'</td><td>'.$line.'</td>';
1725: $result.=&Apache::loncommon::end_data_table_row();
1.71 ng 1726: $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="" />'."\n".
1727: '<input type="hidden" name="oldpts'.$counter.'_'.$partid.'" value="'.$score.'" />'."\n".
1728: '<input type="hidden" name="solved'.$counter.'_'.$partid.'" value="'.
1.269 raeburn 1729: $$record{'resource.'.$partid.'.solved'}.'" />'."\n".
1730: '<input type="hidden" name="totaltries'.$counter.'_'.$partid.'" value="'.
1731: $$record{'resource.'.$partid.'.tries'}.'" />'."\n".
1732: '<input type="hidden" name="aggtries'.$counter.'_'.$partid.'" value="'.
1733: $aggtries.'" />'."\n";
1.582 raeburn 1734: my $res_error;
1735: $result.=&handback_box($symb,$uname,$udom,$counter,$partid,$record,\$res_error);
1736: if ($res_error) {
1737: return &navmap_errormsg();
1738: }
1.318 banghart 1739: return $result;
1740: }
1.322 albertel 1741:
1742: sub handback_box {
1.623 ! www 1743: my ($symb,$uname,$udom,$counter,$partid,$record,$res_error_pointer) = @_;
! 1744: my ($partlist,$handgrade,$responseType) = &response_type($symb,$res_error_pointer);
1.323 banghart 1745: my (@respids);
1.375 albertel 1746: my @part_response_id = &flatten_responseType($responseType);
1747: foreach my $part_response_id (@part_response_id) {
1748: my ($part,$resp) = @{ $part_response_id };
1.323 banghart 1749: if ($part eq $partid) {
1.375 albertel 1750: push(@respids,$resp);
1.323 banghart 1751: }
1752: }
1.318 banghart 1753: my $result;
1.323 banghart 1754: foreach my $respid (@respids) {
1.322 albertel 1755: my $prefix = $counter.'_'.$partid.'_'.$respid.'_';
1756: my $files=&get_submitted_files($udom,$uname,$partid,$respid,$record);
1757: next if (!@$files);
1758: my $file_counter = 1;
1.313 banghart 1759: foreach my $file (@$files) {
1.368 banghart 1760: if ($file =~ /\/portfolio\//) {
1761: my ($file_path, $file_disp) = ($file =~ m|(.+/)(.+)$|);
1762: my ($name,$version,$ext) = &file_name_version_ext($file_disp);
1763: $file_disp = "$name.$ext";
1764: $file = $file_path.$file_disp;
1765: $result.=&mt('Return commented version of [_1] to student.',
1766: '<span class="LC_filename">'.$file_disp.'</span>');
1767: $result.='<input type="file" name="'.$prefix.'returndoc'.$file_counter.'" />'."\n";
1768: $result.='<input type="hidden" name="'.$prefix.'origdoc'.$file_counter.'" value="'.$file.'" /><br />';
1.485 albertel 1769: $result.='('.&mt('File will be uploaded when you click on Save & Next below.').')<br />';
1.368 banghart 1770: $file_counter++;
1771: }
1.322 albertel 1772: }
1.313 banghart 1773: }
1.318 banghart 1774: return $result;
1.71 ng 1775: }
1.44 ng 1776:
1.58 albertel 1777: sub show_problem {
1.382 albertel 1778: my ($request,$symb,$uname,$udom,$removeform,$viewon,$mode,$form) = @_;
1.144 albertel 1779: my $rendered;
1.382 albertel 1780: my %form = ((ref($form) eq 'HASH')? %{$form} : ());
1.329 albertel 1781: &Apache::lonxml::remember_problem_counter();
1.144 albertel 1782: if ($mode eq 'both' or $mode eq 'text') {
1783: $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
1.382 albertel 1784: $env{'request.course.id'},
1785: undef,\%form);
1.144 albertel 1786: }
1.58 albertel 1787: if ($removeform) {
1788: $rendered=~s|<form(.*?)>||g;
1789: $rendered=~s|</form>||g;
1.374 albertel 1790: $rendered=~s|(<input[^>]*name\s*=\s*"?)(\w+)("?)|$1would_have_been_$2$3|g;
1.58 albertel 1791: }
1.144 albertel 1792: my $companswer;
1793: if ($mode eq 'both' or $mode eq 'answer') {
1.329 albertel 1794: &Apache::lonxml::restore_problem_counter();
1.382 albertel 1795: $companswer=
1796: &Apache::loncommon::get_student_answers($symb,$uname,$udom,
1797: $env{'request.course.id'},
1798: %form);
1.144 albertel 1799: }
1.58 albertel 1800: if ($removeform) {
1801: $companswer=~s|<form(.*?)>||g;
1802: $companswer=~s|</form>||g;
1.144 albertel 1803: $companswer=~s|name="submit"|name="would_have_been_submit"|g;
1.58 albertel 1804: }
1.468 albertel 1805: $rendered=
1.588 bisitz 1806: '<div class="LC_Box">'
1807: .'<h3 class="LC_hcell">'.&mt('View of the problem').'</h3>'
1808: .$rendered
1809: .'</div>';
1.468 albertel 1810: $companswer=
1.588 bisitz 1811: '<div class="LC_Box">'
1812: .'<h3 class="LC_hcell">'.&mt('Correct answer').'</h3>'
1813: .$companswer
1814: .'</div>';
1.468 albertel 1815: my $result;
1.144 albertel 1816: if ($mode eq 'both') {
1.588 bisitz 1817: $result=$rendered.$companswer;
1.144 albertel 1818: } elsif ($mode eq 'text') {
1.588 bisitz 1819: $result=$rendered;
1.144 albertel 1820: } elsif ($mode eq 'answer') {
1.588 bisitz 1821: $result=$companswer;
1.144 albertel 1822: }
1.71 ng 1823: return $result;
1.58 albertel 1824: }
1.397 albertel 1825:
1.396 banghart 1826: sub files_exist {
1827: my ($r, $symb) = @_;
1828: my @students = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.397 albertel 1829:
1.396 banghart 1830: foreach my $student (@students) {
1831: my ($uname,$udom,$fullname) = split(/:/,$student);
1.397 albertel 1832: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1833: $udom,$uname);
1.396 banghart 1834: my ($string,$timestamp)= &get_last_submission(\%record);
1.397 albertel 1835: foreach my $submission (@$string) {
1836: my ($partid,$respid) =
1837: ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
1838: my $files=&get_submitted_files($udom,$uname,$partid,$respid,
1839: \%record);
1840: return 1 if (@$files);
1.396 banghart 1841: }
1842: }
1.397 albertel 1843: return 0;
1.396 banghart 1844: }
1.397 albertel 1845:
1.394 banghart 1846: sub download_all_link {
1847: my ($r,$symb) = @_;
1.621 www 1848: unless (&files_exist($r, $symb)) {
1849: $r->print(&mt('There are currently no submitted documents.'));
1850: return;
1851: }
1852:
1.395 albertel 1853: my $all_students =
1854: join("\n", &Apache::loncommon::get_env_multiple('form.stuinfo'));
1855:
1856: my $parts =
1857: join("\n",&Apache::loncommon::get_env_multiple('form.vPart'));
1858:
1.394 banghart 1859: my $identifier = &Apache::loncommon::get_cgi_id();
1.514 raeburn 1860: &Apache::lonnet::appenv({'cgi.'.$identifier.'.students' => $all_students,
1861: 'cgi.'.$identifier.'.symb' => $symb,
1862: 'cgi.'.$identifier.'.parts' => $parts,});
1.395 albertel 1863: $r->print('<a href="/cgi-bin/multidownload.pl?'.$identifier.'">'.
1864: &mt('Download All Submitted Documents').'</a>');
1.621 www 1865: return;
1866: }
1867:
1868: sub submit_download_link {
1869: my ($request,$symb) = @_;
1870: if (!$symb) { return ''; }
1871: #FIXME: Figure out which type of problem this is and provide appropriate download
1872: &download_all_link($request,$symb);
1.394 banghart 1873: }
1.395 albertel 1874:
1.432 banghart 1875: sub build_section_inputs {
1876: my $section_inputs;
1877: if ($env{'form.section'} eq '') {
1878: $section_inputs .= '<input type="hidden" name="section" value="all" />'."\n";
1879: } else {
1880: my @sections = &Apache::loncommon::get_env_multiple('form.section');
1.434 albertel 1881: foreach my $section (@sections) {
1.432 banghart 1882: $section_inputs .= '<input type="hidden" name="section" value="'.$section.'" />'."\n";
1883: }
1884: }
1885: return $section_inputs;
1886: }
1887:
1.44 ng 1888: # --------------------------- show submissions of a student, option to grade
1889: sub submission {
1.608 www 1890: my ($request,$counter,$total,$symb) = @_;
1.257 albertel 1891: my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
1892: $udom = ($udom eq '' ? $env{'user.domain'} : $udom); #has form.userdom changed for a student?
1893: my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
1894: $env{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $env{'form.fullname'} eq '';
1.608 www 1895:
1.605 www 1896: my $probtitle=&Apache::lonnet::gettitle($symb);
1.324 albertel 1897: if ($symb eq '') { $request->print("Unable to handle ambiguous references:."); return ''; }
1.104 albertel 1898:
1899: if (!&canview($usec)) {
1.398 albertel 1900: $request->print('<span class="LC_warning">Unable to view requested student.('.
1901: $uname.':'.$udom.' in section '.$usec.' in course id '.
1902: $env{'request.course.id'}.')</span>');
1.104 albertel 1903: return;
1904: }
1905:
1.257 albertel 1906: if (!$env{'form.lastSub'}) { $env{'form.lastSub'} = 'datesub'; }
1907: if (!$env{'form.vProb'}) { $env{'form.vProb'} = 'yes'; }
1908: if (!$env{'form.vAns'}) { $env{'form.vAns'} = 'yes'; }
1909: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.381 albertel 1910: my $checkIcon = '<img alt="'.&mt('Check Mark').
1911: '" src="'.$request->dir_config('lonIconsURL').
1.122 ng 1912: '/check.gif" height="16" border="0" />';
1.41 ng 1913:
1.426 albertel 1914: my %old_essays;
1.41 ng 1915: # header info
1916: if ($counter == 0) {
1917: &sub_page_js($request);
1.621 www 1918: &sub_page_kw_js($request);
1.605 www 1919: $request->print('<h3> <span class="LC_info">'.&mt('Submission Record').'</span></h3>');
1.118 ng 1920:
1.44 ng 1921: # option to display problem, only once else it cause problems
1922: # with the form later since the problem has a form.
1.257 albertel 1923: if ($env{'form.vProb'} eq 'yes' or $env{'form.vAns'} eq 'yes') {
1.144 albertel 1924: my $mode;
1.257 albertel 1925: if ($env{'form.vProb'} eq 'yes' && $env{'form.vAns'} eq 'yes') {
1.144 albertel 1926: $mode='both';
1.257 albertel 1927: } elsif ($env{'form.vProb'} eq 'yes') {
1.144 albertel 1928: $mode='text';
1.257 albertel 1929: } elsif ($env{'form.vAns'} eq 'yes') {
1.144 albertel 1930: $mode='answer';
1931: }
1.329 albertel 1932: &Apache::lonxml::clear_problem_counter();
1.144 albertel 1933: $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
1.41 ng 1934: }
1.441 www 1935:
1.44 ng 1936: # kwclr is the only variable that is guaranteed to be non blank
1937: # if this subroutine has been called once.
1.41 ng 1938: my %keyhash = ();
1.257 albertel 1939: if ($env{'form.kwclr'} eq '' && $env{'form.handgrade'} eq 'yes') {
1.41 ng 1940: %keyhash = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 1941: $env{'course.'.$env{'request.course.id'}.'.domain'},
1942: $env{'course.'.$env{'request.course.id'}.'.num'});
1.41 ng 1943:
1.257 albertel 1944: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1945: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
1946: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
1947: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
1948: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
1949: $env{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
1.605 www 1950: $keyhash{$symb.'_subject'} : $probtitle;
1.257 albertel 1951: $env{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1.41 ng 1952: }
1.257 albertel 1953: my $overRideScore = $env{'form.overRideScore'} eq '' ? 'no' : $env{'form.overRideScore'};
1.442 banghart 1954: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.303 banghart 1955: $request->print('<form action="/adm/grades" method="post" name="SCORE" enctype="multipart/form-data">'."\n".
1.41 ng 1956: '<input type="hidden" name="command" value="handgrade" />'."\n".
1.442 banghart 1957: '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.120 ng 1958: '<input type="hidden" name="overRideScore" value="'.$overRideScore.'" />'."\n".
1.41 ng 1959: '<input type="hidden" name="refresh" value="off" />'."\n".
1.120 ng 1960: '<input type="hidden" name="studentNo" value="" />'."\n".
1961: '<input type="hidden" name="gradeOpt" value="" />'."\n".
1.418 albertel 1962: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 1963: '<input type="hidden" name="vProb" value="'.$env{'form.vProb'}.'" />'."\n".
1964: '<input type="hidden" name="vAns" value="'.$env{'form.vAns'}.'" />'."\n".
1965: '<input type="hidden" name="lastSub" value="'.$env{'form.lastSub'}.'" />'."\n".
1.432 banghart 1966: &build_section_inputs().
1.326 albertel 1967: '<input type="hidden" name="submitonly" value="'.$env{'form.submitonly'}.'" />'."\n".
1968: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" />'."\n".
1.41 ng 1969: '<input type="hidden" name="NCT"'.
1.257 albertel 1970: ' value="'.($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : $total+1).'" />'."\n");
1971: if ($env{'form.handgrade'} eq 'yes') {
1972: $request->print('<input type="hidden" name="keywords" value="'.$env{'form.keywords'}.'" />'."\n".
1973: '<input type="hidden" name="kwclr" value="'.$env{'form.kwclr'}.'" />'."\n".
1974: '<input type="hidden" name="kwsize" value="'.$env{'form.kwsize'}.'" />'."\n".
1975: '<input type="hidden" name="kwstyle" value="'.$env{'form.kwstyle'}.'" />'."\n".
1976: '<input type="hidden" name="msgsub" value="'.$env{'form.msgsub'}.'" />'."\n".
1.123 ng 1977: '<input type="hidden" name="shownSub" value="0" />'."\n".
1.257 albertel 1978: '<input type="hidden" name="savemsgN" value="'.$env{'form.savemsgN'}.'" />'."\n");
1.154 albertel 1979: foreach my $partid (&Apache::loncommon::get_env_multiple('form.vPart')) {
1980: $request->print('<input type="hidden" name="vPart" value="'.$partid.'" />'."\n");
1981: }
1.123 ng 1982: }
1.41 ng 1983:
1984: my ($cts,$prnmsg) = (1,'');
1.257 albertel 1985: while ($cts <= $env{'form.savemsgN'}) {
1.41 ng 1986: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
1.123 ng 1987: (!exists($keyhash{$symb.'_savemsg'.$cts}) ?
1.257 albertel 1988: &Apache::lonfeedback::clear_out_html($env{'form.savemsg'.$cts}) :
1.80 ng 1989: &Apache::lonfeedback::clear_out_html($keyhash{$symb.'_savemsg'.$cts})).
1.123 ng 1990: '" />'."\n".
1991: '<input type="hidden" name="shownOnce'.$cts.'" value="0" />'."\n";
1.41 ng 1992: $cts++;
1993: }
1994: $request->print($prnmsg);
1.32 ng 1995:
1.618 www 1996: if ($env{'form.handgrade'} eq 'yes') {
1.88 www 1997: #
1998: # Print out the keyword options line
1999: #
1.41 ng 2000: $request->print(<<KEYWORDS);
1.38 ng 2001: <b>Keyword Options:</b>
1.417 albertel 2002: <a href="javascript:keywords(document.SCORE);" target="_self">List</a>
1.589 bisitz 2003: <a href="#" onmousedown="javascript:getSel(); return false"
1.38 ng 2004: CLASS="page">Paste Selection to List</a>
1.417 albertel 2005: <a href="javascript:kwhighlight();" target="_self">Highlight Attribute</a><br /><br />
1.38 ng 2006: KEYWORDS
1.88 www 2007: #
2008: # Load the other essays for similarity check
2009: #
1.324 albertel 2010: my (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb);
1.384 albertel 2011: my ($adom,$aname,$apath)=($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
1.359 www 2012: $apath=&escape($apath);
1.88 www 2013: $apath=~s/\W/\_/gs;
1.426 albertel 2014: %old_essays=&Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
1.41 ng 2015: }
2016: }
1.44 ng 2017:
1.441 www 2018: # This is where output for one specific student would start
1.592 bisitz 2019: my $add_class = ($counter%2) ? ' LC_grade_show_user_odd_row' : '';
2020: $request->print(
2021: "\n\n"
2022: .'<div class="LC_grade_show_user'.$add_class.'">'
2023: .'<h2>'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).'</h2>'
2024: ."\n"
2025: );
1.441 www 2026:
1.592 bisitz 2027: # Show additional functions if allowed
2028: if ($perm{'vgr'}) {
2029: $request->print(
2030: &Apache::loncommon::track_student_link(
2031: &mt('View recent activity'),
2032: $uname,$udom,'check')
2033: .' '
2034: );
2035: }
2036: if ($perm{'opa'}) {
2037: $request->print(
2038: &Apache::loncommon::pprmlink(
2039: &mt('Set/Change parameters'),
2040: $uname,$udom,$symb,'check'));
2041: }
2042:
2043: # Show Problem
1.257 albertel 2044: if ($env{'form.vProb'} eq 'all' or $env{'form.vAns'} eq 'all') {
1.144 albertel 2045: my $mode;
1.257 albertel 2046: if ($env{'form.vProb'} eq 'all' && $env{'form.vAns'} eq 'all') {
1.144 albertel 2047: $mode='both';
1.257 albertel 2048: } elsif ($env{'form.vProb'} eq 'all' ) {
1.144 albertel 2049: $mode='text';
1.257 albertel 2050: } elsif ($env{'form.vAns'} eq 'all') {
1.144 albertel 2051: $mode='answer';
2052: }
1.329 albertel 2053: &Apache::lonxml::clear_problem_counter();
1.475 albertel 2054: $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode,{'request.prefix' => 'ctr'.$counter}));
1.58 albertel 2055: }
1.144 albertel 2056:
1.257 albertel 2057: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.582 raeburn 2058: my $res_error;
2059: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
2060: if ($res_error) {
2061: $request->print(&navmap_errormsg());
2062: return;
2063: }
1.41 ng 2064:
1.44 ng 2065: # Display student info
1.41 ng 2066: $request->print(($counter == 0 ? '' : '<br />'));
1.590 bisitz 2067:
2068: my $result='<div class="LC_Box">'
2069: .'<h3 class="LC_hcell">'.&mt('Submissions').'</h3>';
1.45 ng 2070: $result.='<input type="hidden" name="name'.$counter.
1.588 bisitz 2071: '" value="'.$env{'form.fullname'}.'" />'."\n";
1.469 albertel 2072: if ($env{'form.handgrade'} eq 'no') {
1.588 bisitz 2073: $result.='<p class="LC_info">'
2074: .&mt('Part(s) graded correct by the computer is marked with a [_1] symbol.',$checkIcon)
2075: ."</p>\n";
1.469 albertel 2076: }
2077:
1.118 ng 2078: # If any part of the problem is an essay-response (handgraded), then check for collaborators
1.464 albertel 2079: my $fullname;
2080: my $col_fullnames = [];
1.257 albertel 2081: if ($env{'form.handgrade'} eq 'yes') {
1.464 albertel 2082: (my $sub_result,$fullname,$col_fullnames)=
2083: &check_collaborators($symb,$uname,$udom,\%record,$handgrade,
2084: $counter);
2085: $result.=$sub_result;
1.41 ng 2086: }
1.44 ng 2087: $request->print($result."\n");
1.588 bisitz 2088:
1.44 ng 2089: # print student answer/submission
1.588 bisitz 2090: # Options are (1) Handgraded submission only
1.44 ng 2091: # (2) Last submission, includes submission that is not handgraded
2092: # (for multi-response type part)
2093: # (3) Last submission plus the parts info
2094: # (4) The whole record for this student
1.257 albertel 2095: if ($env{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
1.151 albertel 2096: my ($string,$timestamp)= &get_last_submission(\%record);
1.468 albertel 2097:
2098: my $lastsubonly;
2099:
1.588 bisitz 2100: if ($$timestamp eq '') {
2101: $lastsubonly.='<div class="LC_grade_submissions_body">'.$$string[0].'</div>';
2102: } else {
1.592 bisitz 2103: $lastsubonly =
2104: '<div class="LC_grade_submissions_body">'
2105: .'<b>'.&mt('Date Submitted:').'</b> '.$$timestamp."\n";
1.468 albertel 2106:
1.151 albertel 2107: my %seenparts;
1.375 albertel 2108: my @part_response_id = &flatten_responseType($responseType);
2109: foreach my $part (@part_response_id) {
1.393 albertel 2110: next if ($env{'form.lastSub'} eq 'hdgrade'
2111: && $$handgrade{$$part[0].'_'.$$part[1]} ne 'yes');
2112:
1.375 albertel 2113: my ($partid,$respid) = @{ $part };
1.324 albertel 2114: my $display_part=&get_display_part($partid,$symb);
1.257 albertel 2115: if ($env{"form.$uname:$udom:$partid:submitted_by"}) {
1.151 albertel 2116: if (exists($seenparts{$partid})) { next; }
2117: $seenparts{$partid}=1;
1.207 albertel 2118: my $submitby='<b>Part:</b> '.$display_part.
2119: ' <b>Collaborative submission by:</b> '.
1.151 albertel 2120: '<a href="javascript:viewSubmitter(\''.
1.257 albertel 2121: $env{"form.$uname:$udom:$partid:submitted_by"}.
1.417 albertel 2122: '\');" target="_self">'.
1.257 albertel 2123: $$fullname{$env{"form.$uname:$udom:$partid:submitted_by"}}.'</a><br />';
1.151 albertel 2124: $request->print($submitby);
2125: next;
2126: }
2127: my $responsetype = $responseType->{$partid}->{$respid};
2128: if (!exists($record{"resource.$partid.$respid.submission"})) {
1.577 bisitz 2129: $lastsubonly.="\n".'<div class="LC_grade_submission_part">'.
2130: '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
2131: ' <span class="LC_internal_info">'.
1.623 ! www 2132: '('.&mt('Response ID: [_1]',$respid).')'.
1.577 bisitz 2133: '</span> '.
1.539 riegler 2134: '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br /><br /></div>';
1.151 albertel 2135: next;
2136: }
1.468 albertel 2137: foreach my $submission (@$string) {
2138: my ($partid,$respid) = ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
1.375 albertel 2139: if (join('_',@{$part}) ne ($partid.'_'.$respid)) { next; }
1.596 raeburn 2140: my ($ressub,$hide,$subval) = split(/:/,$submission,3);
1.151 albertel 2141: # Similarity check
2142: my $similar='';
1.257 albertel 2143: if($env{'form.checkPlag'}){
1.151 albertel 2144: my ($oname,$odom,$ocrsid,$oessay,$osim)=
1.426 albertel 2145: &most_similar($uname,$udom,$subval,\%old_essays);
1.151 albertel 2146: if ($osim) {
2147: $osim=int($osim*100.0);
1.426 albertel 2148: my %old_course_desc =
2149: &Apache::lonnet::coursedescription($ocrsid,
2150: {'one_time' => 1});
2151:
1.596 raeburn 2152: if ($hide) {
2153: $similar='<hr /><span class="LC_warning">'.&mt("Essay was found to be similar to another essay submitted for this assignment.").'<br />'.
2154: &mt('As the current submission is for an anonymous survey, no other details are available.').'</span><hr />';
2155: } else {
2156: $similar="<hr /><h3><span class=\"LC_warning\">".
2157: &mt('Essay is [_1]% similar to an essay by [_2] in course [_3] (course id [_4]:[_5])',
2158: $osim,
2159: &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')',
2160: $old_course_desc{'description'},
2161: $old_course_desc{'num'},
2162: $old_course_desc{'domain'}).
2163: '</span></h3><blockquote><i>'.
2164: &keywords_highlight($oessay).
2165: '</i></blockquote><hr />';
2166: }
1.151 albertel 2167: }
1.150 albertel 2168: }
1.151 albertel 2169: my $order=&get_order($partid,$respid,$symb,$uname,$udom);
1.257 albertel 2170: if ($env{'form.lastSub'} eq 'lastonly' ||
2171: ($env{'form.lastSub'} eq 'hdgrade' &&
1.377 albertel 2172: $$handgrade{$$part[0].'_'.$$part[1]} eq 'yes')) {
1.324 albertel 2173: my $display_part=&get_display_part($partid,$symb);
1.577 bisitz 2174: $lastsubonly.='<div class="LC_grade_submission_part">'.
2175: '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
2176: ' <span class="LC_internal_info">'.
1.623 ! www 2177: '('.&mt('Response ID: [_1]',$respid).')'.
1.597 wenzelju 2178: '</span> ';
1.313 banghart 2179: my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record);
2180: if (@$files) {
1.596 raeburn 2181: if ($hide) {
2182: $lastsubonly.='<br />'.&mt('[quant,_1,file] uploaded to this anonymous survey',scalar(@{$files}));
2183: } else {
2184: $lastsubonly.='<br /><span class="LC_warning">'.&mt('Like all files provided by users, this file may contain viruses').'</span><br />';
2185: foreach my $file (@$files) {
2186: &Apache::lonnet::allowuploaded('/adm/grades',$file);
2187: $lastsubonly.='<br /><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.&Apache::loncommon::icon($file).'" border="0" /> '.$file.'</a>';
2188: }
2189: }
1.236 albertel 2190: $lastsubonly.='<br />';
1.41 ng 2191: }
1.596 raeburn 2192: if ($hide) {
2193: $lastsubonly.='<b>'.&mt('Anonymous Survey').'</b>';
2194: } else {
2195: $lastsubonly.='<b>'.&mt('Submitted Answer:').' </b>'.
2196: &cleanRecord($subval,$responsetype,$symb,$partid,
2197: $respid,\%record,$order,undef,$uname,$udom);
2198: }
1.151 albertel 2199: if ($similar) {$lastsubonly.="<br /><br />$similar\n";}
1.468 albertel 2200: $lastsubonly.='</div>';
1.41 ng 2201: }
2202: }
2203: }
1.588 bisitz 2204: $lastsubonly.='</div>'."\n"; # End: LC_grade_submissions_body
1.151 albertel 2205: }
2206: $request->print($lastsubonly);
1.468 albertel 2207: } elsif ($env{'form.lastSub'} eq 'datesub') {
1.623 ! www 2208: my ($parts,$handgrade,$responseType) = &response_type($symb,\$res_error);
1.148 albertel 2209: $request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
1.257 albertel 2210: } elsif ($env{'form.lastSub'} =~ /^(last|all)$/) {
1.41 ng 2211: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
1.257 albertel 2212: $env{'request.course.id'},
1.44 ng 2213: $last,'.submission',
2214: 'Apache::grades::keywords_highlight'));
1.41 ng 2215: }
1.121 ng 2216: $request->print('<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
2217: .$udom.'" />'."\n");
1.44 ng 2218: # return if view submission with no grading option
1.619 www 2219: # FIXME: the logic seems off here. Why show the grade button if you cannot grade?
1.618 www 2220: if (!&canmodify($usec)) {
1.120 ng 2221: my $toGrade.='<input type="button" value="Grade Student" '.
1.589 bisitz 2222: 'onclick="javascript:checksubmit(this.form,\'Grade Student\',\''
1.417 albertel 2223: .$counter.'\');" target="_self" /> '."\n" if (&canmodify($usec));
1.468 albertel 2224: $toGrade.='</div>'."\n";
1.180 albertel 2225: $request->print($toGrade);
1.41 ng 2226: return;
1.180 albertel 2227: } else {
1.468 albertel 2228: $request->print('</div>'."\n");
1.41 ng 2229: }
1.33 ng 2230:
1.121 ng 2231: # essay grading message center
1.257 albertel 2232: if ($env{'form.handgrade'} eq 'yes') {
1.468 albertel 2233: my $result='<div class="LC_grade_message_center">';
2234:
2235: $result.='<div class="LC_grade_message_center_header">'.
2236: &mt('Send Message').'</div><div class="LC_grade_message_center_body">';
1.257 albertel 2237: my ($lastname,$givenn) = split(/,/,$env{'form.fullname'});
1.118 ng 2238: my $msgfor = $givenn.' '.$lastname;
1.464 albertel 2239: if (scalar(@$col_fullnames) > 0) {
2240: my $lastone = pop(@$col_fullnames);
2241: $msgfor .= ', '.(join ', ',@$col_fullnames).' and '.$lastone.'.';
1.118 ng 2242: }
2243: $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
1.468 albertel 2244: $result.='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
1.121 ng 2245: '<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n";
2246: $result.=' <a href="javascript:msgCenter(document.SCORE,'.$counter.
1.417 albertel 2247: ',\''.$msgfor.'\');" target="_self">'.
1.464 albertel 2248: &mt('Compose message to student').(scalar(@$col_fullnames) >= 1 ? 's' : '').'</a><label> ('.
1.350 albertel 2249: &mt('incl. grades').' <input type="checkbox" name="withgrades'.$counter.'" /></label>)'.
1.118 ng 2250: '<img src="'.$request->dir_config('lonIconsURL').
2251: '/mailbkgrd.gif" width="14" height="10" name="mailicon'.$counter.'" />'."\n".
1.298 www 2252: '<br /> ('.
1.468 albertel 2253: &mt('Message will be sent when you click on Save & Next below.').")\n";
2254: $result.='</div></div>';
1.121 ng 2255: $request->print($result);
1.118 ng 2256: }
1.41 ng 2257:
2258: my %seen = ();
2259: my @partlist;
1.129 ng 2260: my @gradePartRespid;
1.375 albertel 2261: my @part_response_id = &flatten_responseType($responseType);
1.585 bisitz 2262: $request->print(
1.588 bisitz 2263: '<div class="LC_Box">'
2264: .'<h3 class="LC_hcell">'.&mt('Assign Grades').'</h3>'
1.585 bisitz 2265: );
1.592 bisitz 2266: $request->print(&gradeBox_start());
1.375 albertel 2267: foreach my $part_response_id (@part_response_id) {
2268: my ($partid,$respid) = @{ $part_response_id };
2269: my $part_resp = join('_',@{ $part_response_id });
1.322 albertel 2270: next if ($seen{$partid} > 0);
1.41 ng 2271: $seen{$partid}++;
1.393 albertel 2272: next if ($$handgrade{$part_resp} ne 'yes'
2273: && $env{'form.lastSub'} eq 'hdgrade');
1.524 raeburn 2274: push(@partlist,$partid);
2275: push(@gradePartRespid,$partid.'.'.$respid);
1.322 albertel 2276: $request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
1.41 ng 2277: }
1.585 bisitz 2278: $request->print(&gradeBox_end()); # </div>
2279: $request->print('</div>');
1.468 albertel 2280:
2281: $request->print('<div class="LC_grade_info_links">');
2282: $request->print('</div>');
2283:
1.45 ng 2284: $result='<input type="hidden" name="partlist'.$counter.
2285: '" value="'.(join ":",@partlist).'" />'."\n";
1.129 ng 2286: $result.='<input type="hidden" name="gradePartRespid'.
2287: '" value="'.(join ":",@gradePartRespid).'" />'."\n" if ($counter == 0);
1.45 ng 2288: my $ctr = 0;
2289: while ($ctr < scalar(@partlist)) {
2290: $result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
2291: $partlist[$ctr].'" />'."\n";
2292: $ctr++;
2293: }
1.468 albertel 2294: $request->print($result.''."\n");
1.41 ng 2295:
1.441 www 2296: # Done with printing info for one student
2297:
1.468 albertel 2298: $request->print('</div>');#LC_grade_show_user
1.441 www 2299:
2300:
1.41 ng 2301: # print end of form
2302: if ($counter == $total) {
1.592 bisitz 2303: my $endform='<br /><hr /><table border="0"><tr><td>'."\n";
1.485 albertel 2304: $endform.='<input type="button" value="'.&mt('Save & Next').'" '.
1.589 bisitz 2305: 'onclick="javascript:checksubmit(this.form,\'Save & Next\','.
1.417 albertel 2306: $total.','.scalar(@partlist).');" target="_self" /> '."\n";
1.119 ng 2307: my $ntstu ='<select name="NTSTU">'.
2308: '<option>1</option><option>2</option>'.
2309: '<option>3</option><option>5</option>'.
2310: '<option>7</option><option>10</option></select>'."\n";
1.257 albertel 2311: my $nsel = ($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : '1');
1.401 albertel 2312: $ntstu =~ s/<option>$nsel</<option selected="selected">$nsel</;
1.578 raeburn 2313: $endform.=&mt('[_1]student(s)',$ntstu);
1.485 albertel 2314: $endform.=' <input type="button" value="'.&mt('Previous').'" '.
1.589 bisitz 2315: 'onclick="javascript:checksubmit(this.form,\'Previous\');" target="_self" /> '."\n".
1.485 albertel 2316: '<input type="button" value="'.&mt('Next').'" '.
1.589 bisitz 2317: 'onclick="javascript:checksubmit(this.form,\'Next\');" target="_self" /> ';
1.592 bisitz 2318: $endform.='<span class="LC_warning">'.
2319: &mt('(Next and Previous (student) do not save the scores.)').
2320: '</span>'."\n" ;
1.349 albertel 2321: $endform.="<input type='hidden' value='".&get_increment().
1.348 bowersj2 2322: "' name='increment' />";
1.485 albertel 2323: $endform.='</td></tr></table></form>';
1.41 ng 2324: $request->print($endform);
2325: }
2326: return '';
1.38 ng 2327: }
2328:
1.464 albertel 2329: sub check_collaborators {
2330: my ($symb,$uname,$udom,$record,$handgrade,$counter) = @_;
2331: my ($result,@col_fullnames);
2332: my ($classlist,undef,$fullname) = &getclasslist('all','0');
2333: foreach my $part (keys(%$handgrade)) {
2334: my $ncol = &Apache::lonnet::EXT('resource.'.$part.
2335: '.maxcollaborators',
2336: $symb,$udom,$uname);
2337: next if ($ncol <= 0);
2338: $part =~ s/\_/\./g;
2339: next if ($record->{'resource.'.$part.'.collaborators'} eq '');
2340: my (@good_collaborators, @bad_collaborators);
2341: foreach my $possible_collaborator
2342: (split(/,?\s+/,$record->{'resource.'.$part.'.collaborators'})) {
2343: $possible_collaborator =~ s/[\$\^\(\)]//g;
2344: next if ($possible_collaborator eq '');
2345: my ($co_name,$co_dom) = split(/\@|:/,$possible_collaborator);
2346: $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
2347: next if ($co_name eq $uname && $co_dom eq $udom);
2348: # Doing this grep allows 'fuzzy' specification
2349: my @matches = grep(/^\Q$co_name\E:\Q$co_dom\E$/i,
2350: keys(%$classlist));
2351: if (! scalar(@matches)) {
2352: push(@bad_collaborators, $possible_collaborator);
2353: } else {
2354: push(@good_collaborators, @matches);
2355: }
2356: }
2357: if (scalar(@good_collaborators) != 0) {
1.466 albertel 2358: $result.='<br />'.&mt('Collaborators: ');
1.464 albertel 2359: foreach my $name (@good_collaborators) {
2360: my ($lastname,$givenn) = split(/,/,$$fullname{$name});
2361: push(@col_fullnames, $givenn.' '.$lastname);
2362: $result.=$fullname->{$name}.' ';
2363: }
2364: $result.='<br />'."\n";
1.466 albertel 2365: my ($part)=split(/\./,$part);
1.464 albertel 2366: $result.='<input type="hidden" name="collaborator'.$counter.
2367: '" value="'.$part.':'.(join ':',@good_collaborators).'" />'.
2368: "\n";
2369: }
2370: if (scalar(@bad_collaborators) > 0) {
1.466 albertel 2371: $result.='<div class="LC_warning">';
1.464 albertel 2372: $result.=&mt('This student has submitted [quant,_1,invalid collaborator]: [_2]',scalar(@bad_collaborators),join(', ',@bad_collaborators));
2373: $result .= '</div>';
2374: }
2375: if (scalar(@bad_collaborators > $ncol)) {
1.466 albertel 2376: $result .= '<div class="LC_warning">';
1.464 albertel 2377: $result .= &mt('This student has submitted too many '.
2378: 'collaborators. Maximum is [_1].',$ncol);
2379: $result .= '</div>';
2380: }
2381: }
2382: return ($result,$fullname,\@col_fullnames);
2383: }
2384:
1.44 ng 2385: #--- Retrieve the last submission for all the parts
1.38 ng 2386: sub get_last_submission {
1.119 ng 2387: my ($returnhash)=@_;
1.596 raeburn 2388: my (@string,$timestamp,%lasthidden);
1.119 ng 2389: if ($$returnhash{'version'}) {
1.46 ng 2390: my %lasthash=();
2391: my ($version);
1.119 ng 2392: for ($version=1;$version<=$$returnhash{'version'};$version++) {
1.397 albertel 2393: foreach my $key (sort(split(/\:/,
2394: $$returnhash{$version.':keys'}))) {
2395: $lasthash{$key}=$$returnhash{$version.':'.$key};
2396: $timestamp =
1.545 raeburn 2397: &Apache::lonlocal::locallocaltime($$returnhash{$version.':timestamp'});
1.46 ng 2398: }
2399: }
1.596 raeburn 2400: my %typeparts;
2401: my $showsurv =
2402: &Apache::lonnet::allowed('vas',$env{'request.course.id'});
2403: foreach my $key (sort(keys(%lasthash))) {
2404: if ($key =~ /\.type$/) {
2405: if (($lasthash{$key} eq 'anonsurvey') ||
2406: ($lasthash{$key} eq 'anonsurveycred')) {
2407: my ($ign,@parts) = split(/\./,$key);
2408: pop(@parts);
2409: unless ($showsurv) {
2410: my $id = join(',',@parts);
2411: $typeparts{$ign.'.'.$id} = $lasthash{$key};
2412: }
2413: delete($lasthash{$key});
2414: }
2415: }
2416: }
2417: my @hidden = keys(%typeparts);
1.397 albertel 2418: foreach my $key (keys(%lasthash)) {
2419: next if ($key !~ /\.submission$/);
1.596 raeburn 2420: my $hide;
2421: if (@hidden) {
2422: foreach my $id (@hidden) {
2423: if ($key =~ /^\Q$id\E/) {
2424: $hide = 1;
2425: last;
2426: }
2427: }
2428: }
1.397 albertel 2429: my ($partid,$foo) = split(/submission$/,$key);
2430: my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
1.398 albertel 2431: '<span class="LC_warning">Draft Copy</span> ' : '';
1.596 raeburn 2432: push(@string, join(':', $key, $hide, $draft.$lasthash{$key}));
1.41 ng 2433: }
2434: }
1.397 albertel 2435: if (!@string) {
2436: $string[0] =
1.539 riegler 2437: '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span>';
1.397 albertel 2438: }
2439: return (\@string,\$timestamp);
1.38 ng 2440: }
1.35 ng 2441:
1.44 ng 2442: #--- High light keywords, with style choosen by user.
1.38 ng 2443: sub keywords_highlight {
1.44 ng 2444: my $string = shift;
1.257 albertel 2445: my $size = $env{'form.kwsize'} eq '0' ? '' : 'size='.$env{'form.kwsize'};
2446: my $styleon = $env{'form.kwstyle'} eq '' ? '' : $env{'form.kwstyle'};
1.41 ng 2447: (my $styleoff = $styleon) =~ s/\</\<\//;
1.257 albertel 2448: my @keylist = split(/[,\s+]/,$env{'form.keywords'});
1.398 albertel 2449: foreach my $keyword (@keylist) {
2450: $string =~ s/\b\Q$keyword\E(\b|\.)/<font color\=$env{'form.kwclr'} $size\>$styleon$keyword$styleoff<\/font>/gi;
1.41 ng 2451: }
2452: return $string;
1.38 ng 2453: }
1.36 ng 2454:
1.44 ng 2455: #--- Called from submission routine
1.38 ng 2456: sub processHandGrade {
1.608 www 2457: my ($request,$symb) = @_;
1.324 albertel 2458: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.257 albertel 2459: my $button = $env{'form.gradeOpt'};
2460: my $ngrade = $env{'form.NCT'};
2461: my $ntstu = $env{'form.NTSTU'};
1.301 albertel 2462: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2463: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2464:
1.44 ng 2465: if ($button eq 'Save & Next') {
2466: my $ctr = 0;
2467: while ($ctr < $ngrade) {
1.257 albertel 2468: my ($uname,$udom) = split(/:/,$env{'form.unamedom'.$ctr});
1.324 albertel 2469: my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$symb,$uname,$udom,$ctr);
1.71 ng 2470: if ($errorflag eq 'no_score') {
2471: $ctr++;
2472: next;
2473: }
1.104 albertel 2474: if ($errorflag eq 'not_allowed') {
1.398 albertel 2475: $request->print("<span class=\"LC_warning\">Not allowed to modify grades for $uname:$udom</span>");
1.104 albertel 2476: $ctr++;
2477: next;
2478: }
1.257 albertel 2479: my $includemsg = $env{'form.includemsg'.$ctr};
1.44 ng 2480: my ($subject,$message,$msgstatus) = ('','','');
1.418 albertel 2481: my $restitle = &Apache::lonnet::gettitle($symb);
2482: my ($feedurl,$showsymb) =
2483: &get_feedurl_and_symb($symb,$uname,$udom);
2484: my $messagetail;
1.62 albertel 2485: if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.298 www 2486: $subject = $env{'form.msgsub'} if ($includemsg =~ /msgsub/);
1.295 www 2487: unless ($subject=~/\w/) { $subject=&mt('Grading Feedback'); }
1.386 raeburn 2488: $subject.=' ['.$restitle.']';
1.44 ng 2489: my (@msgnum) = split(/,/,$includemsg);
2490: foreach (@msgnum) {
1.257 albertel 2491: $message.=$env{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
1.44 ng 2492: }
1.80 ng 2493: $message =&Apache::lonfeedback::clear_out_html($message);
1.298 www 2494: if ($env{'form.withgrades'.$ctr}) {
2495: $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
1.386 raeburn 2496: $messagetail = " for <a href=\"".
1.605 www 2497: $feedurl."?symb=$showsymb\">$restitle</a>";
1.386 raeburn 2498: }
2499: $msgstatus =
2500: &Apache::lonmsg::user_normal_msg($uname,$udom,$subject,
2501: $message.$messagetail,
1.418 albertel 2502: undef,$feedurl,undef,
1.386 raeburn 2503: undef,undef,$showsymb,
2504: $restitle);
1.574 bisitz 2505: $request->print('<br />'.&mt('Sending message to [_1]',$uname.':'.$udom).': '.
1.296 www 2506: $msgstatus);
1.44 ng 2507: }
1.257 albertel 2508: if ($env{'form.collaborator'.$ctr}) {
1.155 albertel 2509: my @collabstrs=&Apache::loncommon::get_env_multiple("form.collaborator$ctr");
1.150 albertel 2510: foreach my $collabstr (@collabstrs) {
2511: my ($part,@collaborators) = split(/:/,$collabstr);
1.310 banghart 2512: foreach my $collaborator (@collaborators) {
1.150 albertel 2513: my ($errorflag,$pts,$wgt) =
1.324 albertel 2514: &saveHandGrade($request,$symb,$collaborator,$udom,$ctr,
1.257 albertel 2515: $env{'form.unamedom'.$ctr},$part);
1.150 albertel 2516: if ($errorflag eq 'not_allowed') {
1.362 albertel 2517: $request->print("<span class=\"LC_error\">".&mt('Not allowed to modify grades for [_1]',"$collaborator:$udom")."</span>");
1.150 albertel 2518: next;
1.418 albertel 2519: } elsif ($message ne '') {
2520: my ($baseurl,$showsymb) =
2521: &get_feedurl_and_symb($symb,$collaborator,
2522: $udom);
2523: if ($env{'form.withgrades'.$ctr}) {
2524: $messagetail = " for <a href=\"".
1.605 www 2525: $baseurl."?symb=$showsymb\">$restitle</a>";
1.150 albertel 2526: }
1.418 albertel 2527: $msgstatus =
2528: &Apache::lonmsg::user_normal_msg($collaborator,$udom,$subject,$message.$messagetail,undef,$baseurl,undef,undef,undef,$showsymb,$restitle);
1.104 albertel 2529: }
1.44 ng 2530: }
2531: }
2532: }
2533: $ctr++;
2534: }
2535: }
2536:
1.257 albertel 2537: if ($env{'form.handgrade'} eq 'yes') {
1.119 ng 2538: # Keywords sorted in alphabatical order
1.257 albertel 2539: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1.119 ng 2540: my %keyhash = ();
1.257 albertel 2541: $env{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
2542: $env{'form.keywords'} =~ s/^\s+|\s+$//;
2543: my (@keywords) = sort(split(/\s+/,$env{'form.keywords'}));
2544: $env{'form.keywords'} = join(' ',@keywords);
2545: $keyhash{$symb.'_keywords'} = $env{'form.keywords'};
2546: $keyhash{$symb.'_subject'} = $env{'form.msgsub'};
2547: $keyhash{$loginuser.'_kwclr'} = $env{'form.kwclr'};
2548: $keyhash{$loginuser.'_kwsize'} = $env{'form.kwsize'};
2549: $keyhash{$loginuser.'_kwstyle'} = $env{'form.kwstyle'};
1.119 ng 2550:
2551: # message center - Order of message gets changed. Blank line is eliminated.
1.257 albertel 2552: # New messages are saved in env for the next student.
1.119 ng 2553: # All messages are saved in nohist_handgrade.db
2554: my ($ctr,$idx) = (1,1);
1.257 albertel 2555: while ($ctr <= $env{'form.savemsgN'}) {
2556: if ($env{'form.savemsg'.$ctr} ne '') {
2557: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.savemsg'.$ctr};
1.119 ng 2558: $idx++;
2559: }
2560: $ctr++;
1.41 ng 2561: }
1.119 ng 2562: $ctr = 0;
2563: while ($ctr < $ngrade) {
1.257 albertel 2564: if ($env{'form.newmsg'.$ctr} ne '') {
2565: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.newmsg'.$ctr};
2566: $env{'form.savemsg'.$idx} = $env{'form.newmsg'.$ctr};
1.119 ng 2567: $idx++;
2568: }
2569: $ctr++;
1.41 ng 2570: }
1.257 albertel 2571: $env{'form.savemsgN'} = --$idx;
2572: $keyhash{$symb.'_savemsgN'} = $env{'form.savemsgN'};
1.119 ng 2573: my $putresult = &Apache::lonnet::put
1.301 albertel 2574: ('nohist_handgrade',\%keyhash,$cdom,$cnum);
1.41 ng 2575: }
1.44 ng 2576: # Called by Save & Refresh from Highlight Attribute Window
1.257 albertel 2577: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
2578: if ($env{'form.refresh'} eq 'on') {
1.86 ng 2579: my ($ctr,$total) = (0,0);
2580: while ($ctr < $ngrade) {
1.257 albertel 2581: $total++ if $env{'form.unamedom'.$ctr} ne '';
1.86 ng 2582: $ctr++;
2583: }
1.257 albertel 2584: $env{'form.NTSTU'}=$ngrade;
1.86 ng 2585: $ctr = 0;
2586: while ($ctr < $total) {
1.257 albertel 2587: my $processUser = $env{'form.unamedom'.$ctr};
2588: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2589: $env{'form.fullname'} = $$fullname{$processUser};
1.86 ng 2590: &submission($request,$ctr,$total-1);
1.41 ng 2591: $ctr++;
2592: }
2593: return '';
2594: }
1.36 ng 2595:
1.121 ng 2596: # Go directly to grade student - from submission or link from chart page
1.120 ng 2597: if ($button eq 'Grade Student') {
1.598 www 2598: # (undef,undef,$env{'form.handgrade'},undef,undef) = &showResourceInfo($symb);
1.257 albertel 2599: my $processUser = $env{'form.unamedom'.$env{'form.studentNo'}};
2600: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2601: $env{'form.fullname'} = $$fullname{$processUser};
1.120 ng 2602: &submission($request,0,0);
2603: return '';
2604: }
2605:
1.44 ng 2606: # Get the next/previous one or group of students
1.257 albertel 2607: my $firststu = $env{'form.unamedom0'};
2608: my $laststu = $env{'form.unamedom'.($ngrade-1)};
1.119 ng 2609: my $ctr = 2;
1.41 ng 2610: while ($laststu eq '') {
1.257 albertel 2611: $laststu = $env{'form.unamedom'.($ngrade-$ctr)};
1.41 ng 2612: $ctr++;
2613: $laststu = $firststu if ($ctr > $ngrade);
2614: }
1.44 ng 2615:
1.41 ng 2616: my (@parsedlist,@nextlist);
2617: my ($nextflg) = 0;
1.524 raeburn 2618: foreach my $item (sort
1.294 albertel 2619: {
2620: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
2621: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
2622: }
2623: return $a cmp $b;
2624: } (keys(%$fullname))) {
1.605 www 2625: # FIXME: this is fishy, looks like the button label
1.41 ng 2626: if ($nextflg == 1 && $button =~ /Next$/) {
1.524 raeburn 2627: push(@parsedlist,$item);
1.41 ng 2628: }
1.524 raeburn 2629: $nextflg = 1 if ($item eq $laststu);
1.41 ng 2630: if ($button eq 'Previous') {
1.524 raeburn 2631: last if ($item eq $firststu);
2632: push(@parsedlist,$item);
1.41 ng 2633: }
2634: }
2635: $ctr = 0;
1.605 www 2636: # FIXME: this is fishy, looks like the button label
1.41 ng 2637: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
1.582 raeburn 2638: my $res_error;
2639: my ($partlist) = &response_type($symb,\$res_error);
2640: if ($res_error) {
2641: $request->print(&navmap_errormsg());
2642: return;
2643: }
1.41 ng 2644: foreach my $student (@parsedlist) {
1.257 albertel 2645: my $submitonly=$env{'form.submitonly'};
1.41 ng 2646: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 2647:
2648: if ($submitonly eq 'queued') {
2649: my %queue_status =
2650: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
2651: $udom,$uname);
2652: next if (!defined($queue_status{'gradingqueue'}));
2653: }
2654:
1.156 albertel 2655: if ($submitonly =~ /^(yes|graded|incorrect)$/) {
1.257 albertel 2656: # my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 2657: my %status=&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 2658: my $submitted = 0;
1.248 albertel 2659: my $ungraded = 0;
2660: my $incorrect = 0;
1.524 raeburn 2661: foreach my $item (keys(%status)) {
2662: $submitted = 1 if ($status{$item} ne 'nothing');
2663: $ungraded = 1 if ($status{$item} =~ /^ungraded/);
2664: $incorrect = 1 if ($status{$item} =~ /^incorrect/);
2665: my ($foo,$partid,$foo1) = split(/\./,$item);
1.145 albertel 2666: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
2667: $submitted = 0;
2668: }
1.41 ng 2669: }
1.156 albertel 2670: next if (!$submitted && ($submitonly eq 'yes' ||
2671: $submitonly eq 'incorrect' ||
2672: $submitonly eq 'graded'));
1.248 albertel 2673: next if (!$ungraded && ($submitonly eq 'graded'));
2674: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 2675: }
1.524 raeburn 2676: push(@nextlist,$student) if ($ctr < $ntstu);
1.129 ng 2677: last if ($ctr == $ntstu);
1.41 ng 2678: $ctr++;
2679: }
1.36 ng 2680:
1.41 ng 2681: $ctr = 0;
2682: my $total = scalar(@nextlist)-1;
1.39 ng 2683:
1.524 raeburn 2684: foreach (sort(@nextlist)) {
1.41 ng 2685: my ($uname,$udom,$submitter) = split(/:/);
1.257 albertel 2686: $env{'form.student'} = $uname;
2687: $env{'form.userdom'} = $udom;
2688: $env{'form.fullname'} = $$fullname{$_};
1.41 ng 2689: &submission($request,$ctr,$total);
2690: $ctr++;
2691: }
2692: if ($total < 0) {
1.485 albertel 2693: my $the_end = '<h3><span class="LC_info">'.&mt('LON-CAPA User Message').'</span></h3><br />'."\n";
2694: $the_end.=&mt('<b>Message: </b> No more students for this section or class.').'<br /><br />'."\n";
2695: $the_end.=&mt('Click on the button below to return to the grading menu.').'<br /><br />'."\n";
1.41 ng 2696: $request->print($the_end);
2697: }
2698: return '';
1.38 ng 2699: }
1.36 ng 2700:
1.44 ng 2701: #---- Save the score and award for each student, if changed
1.38 ng 2702: sub saveHandGrade {
1.324 albertel 2703: my ($request,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
1.342 banghart 2704: my @version_parts;
1.104 albertel 2705: my $usec = &Apache::lonnet::getsection($domain,$stuname,
1.257 albertel 2706: $env{'request.course.id'});
1.104 albertel 2707: if (!&canmodify($usec)) { return('not_allowed'); }
1.337 banghart 2708: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
1.251 banghart 2709: my @parts_graded;
1.77 ng 2710: my %newrecord = ();
2711: my ($pts,$wgt) = ('','');
1.269 raeburn 2712: my %aggregate = ();
2713: my $aggregateflag = 0;
1.301 albertel 2714: my @parts = split(/:/,$env{'form.partlist'.$newflg});
2715: foreach my $new_part (@parts) {
1.337 banghart 2716: #collaborator ($submi may vary for different parts
1.259 banghart 2717: if ($submitter && $new_part ne $part) { next; }
2718: my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
1.125 ng 2719: if ($dropMenu eq 'excused') {
1.259 banghart 2720: if ($record{'resource.'.$new_part.'.solved'} ne 'excused') {
2721: $newrecord{'resource.'.$new_part.'.solved'} = 'excused';
2722: if (exists($record{'resource.'.$new_part.'.awarded'})) {
2723: $newrecord{'resource.'.$new_part.'.awarded'} = '';
1.58 albertel 2724: }
1.364 banghart 2725: $newrecord{'resource.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.58 albertel 2726: }
1.125 ng 2727: } elsif ($dropMenu eq 'reset status'
1.259 banghart 2728: && exists($record{'resource.'.$new_part.'.solved'})) { #don't bother if no old records -> no attempts
1.524 raeburn 2729: foreach my $key (keys(%record)) {
1.259 banghart 2730: if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
1.197 albertel 2731: }
1.259 banghart 2732: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2733: "$env{'user.name'}:$env{'user.domain'}";
1.270 albertel 2734: my $totaltries = $record{'resource.'.$part.'.tries'};
2735:
2736: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
2737: [$new_part]);
2738: my $aggtries =$totaltries;
1.269 raeburn 2739: if ($last_resets{$new_part}) {
1.270 albertel 2740: $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
2741: $new_part);
1.269 raeburn 2742: }
1.270 albertel 2743:
2744: my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
1.269 raeburn 2745: if ($aggtries > 0) {
1.327 albertel 2746: &decrement_aggs($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
1.269 raeburn 2747: $aggregateflag = 1;
2748: }
1.125 ng 2749: } elsif ($dropMenu eq '') {
1.259 banghart 2750: $pts = ($env{'form.GD_BOX'.$newflg.'_'.$new_part} ne '' ?
2751: $env{'form.GD_BOX'.$newflg.'_'.$new_part} :
2752: $env{'form.RADVAL'.$newflg.'_'.$new_part});
2753: if ($pts eq '' && $env{'form.GD_SEL'.$newflg.'_'.$new_part} eq '') {
1.153 albertel 2754: next;
2755: }
1.259 banghart 2756: $wgt = $env{'form.WGT'.$newflg.'_'.$new_part} eq '' ? 1 :
2757: $env{'form.WGT'.$newflg.'_'.$new_part};
1.41 ng 2758: my $partial= $pts/$wgt;
1.259 banghart 2759: if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
1.153 albertel 2760: #do not update score for part if not changed.
1.346 banghart 2761: &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
1.153 albertel 2762: next;
1.251 banghart 2763: } else {
1.524 raeburn 2764: push(@parts_graded,$new_part);
1.153 albertel 2765: }
1.259 banghart 2766: if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
2767: $newrecord{'resource.'.$new_part.'.awarded'} = $partial;
1.153 albertel 2768: }
1.259 banghart 2769: my $reckey = 'resource.'.$new_part.'.solved';
1.41 ng 2770: if ($partial == 0) {
1.153 albertel 2771: if ($record{$reckey} ne 'incorrect_by_override') {
2772: $newrecord{$reckey} = 'incorrect_by_override';
2773: }
1.41 ng 2774: } else {
1.153 albertel 2775: if ($record{$reckey} ne 'correct_by_override') {
2776: $newrecord{$reckey} = 'correct_by_override';
2777: }
2778: }
2779: if ($submitter &&
1.259 banghart 2780: ($record{'resource.'.$new_part.'.submitted_by'} ne $submitter)) {
2781: $newrecord{'resource.'.$new_part.'.submitted_by'} = $submitter;
1.41 ng 2782: }
1.259 banghart 2783: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2784: "$env{'user.name'}:$env{'user.domain'}";
1.41 ng 2785: }
1.259 banghart 2786: # unless problem has been graded, set flag to version the submitted files
1.305 banghart 2787: unless ($record{'resource.'.$new_part.'.solved'} =~ /^correct_/ ||
2788: $record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override' ||
2789: $dropMenu eq 'reset status')
2790: {
1.524 raeburn 2791: push(@version_parts,$new_part);
1.259 banghart 2792: }
1.41 ng 2793: }
1.301 albertel 2794: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2795: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2796:
1.344 albertel 2797: if (%newrecord) {
2798: if (@version_parts) {
1.364 banghart 2799: my @changed_keys = &version_portfiles(\%record, \@parts_graded,
2800: $env{'request.course.id'}, $symb, $domain, $stuname, \@version_parts);
1.344 albertel 2801: @newrecord{@changed_keys} = @record{@changed_keys};
1.367 albertel 2802: foreach my $new_part (@version_parts) {
2803: &handback_files($request,$symb,$stuname,$domain,$newflg,
2804: $new_part,\%newrecord);
2805: }
1.259 banghart 2806: }
1.44 ng 2807: &Apache::lonnet::cstore(\%newrecord,$symb,
1.257 albertel 2808: $env{'request.course.id'},$domain,$stuname);
1.380 albertel 2809: &check_and_remove_from_queue(\@parts,\%record,\%newrecord,$symb,
2810: $cdom,$cnum,$domain,$stuname);
1.41 ng 2811: }
1.269 raeburn 2812: if ($aggregateflag) {
2813: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 2814: $cdom,$cnum);
1.269 raeburn 2815: }
1.301 albertel 2816: return ('',$pts,$wgt);
1.36 ng 2817: }
1.322 albertel 2818:
1.380 albertel 2819: sub check_and_remove_from_queue {
2820: my ($parts,$record,$newrecord,$symb,$cdom,$cnum,$domain,$stuname) = @_;
2821: my @ungraded_parts;
2822: foreach my $part (@{$parts}) {
2823: if ( $record->{ 'resource.'.$part.'.awarded'} eq ''
2824: && $record->{ 'resource.'.$part.'.solved' } ne 'excused'
2825: && $newrecord->{'resource.'.$part.'.awarded'} eq ''
2826: && $newrecord->{'resource.'.$part.'.solved' } ne 'excused'
2827: ) {
2828: push(@ungraded_parts, $part);
2829: }
2830: }
2831: if ( !@ungraded_parts ) {
2832: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,
2833: $cnum,$domain,$stuname);
2834: }
2835: }
2836:
1.337 banghart 2837: sub handback_files {
2838: my ($request,$symb,$stuname,$domain,$newflg,$new_part,$newrecord) = @_;
1.517 raeburn 2839: my $portfolio_root = '/userfiles/portfolio';
1.582 raeburn 2840: my $res_error;
2841: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
2842: if ($res_error) {
2843: $request->print('<br />'.&navmap_errormsg().'<br />');
2844: return;
2845: }
1.375 albertel 2846: my @part_response_id = &flatten_responseType($responseType);
2847: foreach my $part_response_id (@part_response_id) {
2848: my ($part_id,$resp_id) = @{ $part_response_id };
2849: my $part_resp = join('_',@{ $part_response_id });
1.337 banghart 2850: if (($env{'form.'.$newflg.'_'.$part_resp.'_returndoc1'}) && ($new_part == $part_id)) {
2851: # if multiple files are uploaded names will be 'returndoc2','returndoc3'
2852: my $file_counter = 1;
1.367 albertel 2853: my $file_msg;
1.337 banghart 2854: while ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter}) {
2855: my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.'.filename'};
1.338 banghart 2856: my ($directory,$answer_file) =
2857: ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter} =~ /^(.*?)([^\/]*)$/);
2858: my ($answer_name,$answer_ver,$answer_ext) =
2859: &file_name_version_ext($answer_file);
1.355 banghart 2860: my ($portfolio_path) = ($directory =~ /^.+$stuname\/portfolio(.*)/);
1.517 raeburn 2861: my $getpropath = 1;
2862: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$portfolio_path,$domain,$stuname,$getpropath);
1.338 banghart 2863: my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
1.355 banghart 2864: # fix file name
2865: my ($save_file_name) = (($directory.$answer_name.".$version.".$answer_ext) =~ /^.+\/${stuname}\/(.*)/);
2866: my $result=&Apache::lonnet::finishuserfileupload($stuname,$domain,
2867: $newflg.'_'.$part_resp.'_returndoc'.$file_counter,
2868: $save_file_name);
1.337 banghart 2869: if ($result !~ m|^/uploaded/|) {
1.536 raeburn 2870: $request->print('<br /><span class="LC_error">'.
2871: &mt('An error occurred ([_1]) while trying to upload [_2].',
2872: $result,$newflg.'_'.$part_resp.'_returndoc'.$file_counter).
2873: '</span>');
1.356 banghart 2874: } else {
1.360 banghart 2875: # mark the file as read only
2876: my @files = ($save_file_name);
1.372 albertel 2877: my @what = ($symb,$env{'request.course.id'},'handback');
1.360 banghart 2878: &Apache::lonnet::mark_as_readonly($domain,$stuname,\@files,\@what);
1.367 albertel 2879: if (exists($$newrecord{"resource.$new_part.$resp_id.handback"})) {
2880: $$newrecord{"resource.$new_part.$resp_id.handback"}.=',';
2881: }
2882: $$newrecord{"resource.$new_part.$resp_id.handback"} .= $save_file_name;
2883: $file_msg.= "\n".'<br /><span class="LC_filename"><a href="/uploaded/'."$domain/$stuname/".$save_file_name.'">'.$save_file_name."</a></span><br />";
2884:
1.337 banghart 2885: }
2886: $request->print("<br />".$fname." will be the uploaded file name");
1.354 albertel 2887: $request->print(" ".$env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter});
1.337 banghart 2888: $file_counter++;
2889: }
1.367 albertel 2890: my $subject = "File Handed Back by Instructor ";
2891: my $message = "A file has been returned that was originally submitted in reponse to: <br />";
2892: $message .= "<strong>".&Apache::lonnet::gettitle($symb)."</strong><br />";
2893: $message .= ' The returned file(s) are named: '. $file_msg;
2894: $message .= " and can be found in your portfolio space.";
1.418 albertel 2895: my ($feedurl,$showsymb) =
2896: &get_feedurl_and_symb($symb,$domain,$stuname);
1.386 raeburn 2897: my $restitle = &Apache::lonnet::gettitle($symb);
2898: my $msgstatus =
2899: &Apache::lonmsg::user_normal_msg($stuname,$domain,$subject.
2900: ' (File Returned) ['.$restitle.']',$message,undef,
1.418 albertel 2901: $feedurl,undef,undef,undef,$showsymb,$restitle);
1.337 banghart 2902: }
2903: }
1.338 banghart 2904: return;
1.337 banghart 2905: }
2906:
1.418 albertel 2907: sub get_feedurl_and_symb {
2908: my ($symb,$uname,$udom) = @_;
2909: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
2910: $url = &Apache::lonnet::clutter($url);
2911: my $encrypturl=&Apache::lonnet::EXT('resource.0.encrypturl',
2912: $symb,$udom,$uname);
2913: if ($encrypturl =~ /^yes$/i) {
2914: &Apache::lonenc::encrypted(\$url,1);
2915: &Apache::lonenc::encrypted(\$symb,1);
2916: }
2917: return ($url,$symb);
2918: }
2919:
1.313 banghart 2920: sub get_submitted_files {
2921: my ($udom,$uname,$partid,$respid,$record) = @_;
2922: my @files;
2923: if ($$record{"resource.$partid.$respid.portfiles"}) {
2924: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
2925: foreach my $file (split(',',$$record{"resource.$partid.$respid.portfiles"})) {
2926: push(@files,$file_url.$file);
2927: }
2928: }
2929: if ($$record{"resource.$partid.$respid.uploadedurl"}) {
2930: push(@files,$$record{"resource.$partid.$respid.uploadedurl"});
2931: }
2932: return (\@files);
2933: }
1.322 albertel 2934:
1.269 raeburn 2935: # ----------- Provides number of tries since last reset.
2936: sub get_num_tries {
2937: my ($record,$last_reset,$part) = @_;
2938: my $timestamp = '';
2939: my $num_tries = 0;
2940: if ($$record{'version'}) {
2941: for (my $version=$$record{'version'};$version>=1;$version--) {
2942: if (exists($$record{$version.':resource.'.$part.'.solved'})) {
2943: $timestamp = $$record{$version.':timestamp'};
2944: if ($timestamp > $last_reset) {
2945: $num_tries ++;
2946: } else {
2947: last;
2948: }
2949: }
2950: }
2951: }
2952: return $num_tries;
2953: }
2954:
2955: # ----------- Determine decrements required in aggregate totals
2956: sub decrement_aggs {
2957: my ($symb,$part,$aggregate,$aggtries,$totaltries,$solvedstatus) = @_;
2958: my %decrement = (
2959: attempts => 0,
2960: users => 0,
2961: correct => 0
2962: );
2963: $decrement{'attempts'} = $aggtries;
2964: if ($solvedstatus =~ /^correct/) {
2965: $decrement{'correct'} = 1;
2966: }
2967: if ($aggtries == $totaltries) {
2968: $decrement{'users'} = 1;
2969: }
1.524 raeburn 2970: foreach my $type (keys(%decrement)) {
1.269 raeburn 2971: $$aggregate{$symb."\0".$part."\0".$type} = -$decrement{$type};
2972: }
2973: return;
2974: }
2975:
2976: # ----------- Determine timestamps for last reset of aggregate totals for parts
2977: sub get_last_resets {
1.270 albertel 2978: my ($symb,$courseid,$partids) =@_;
2979: my %last_resets;
1.269 raeburn 2980: my $cdom = $env{'course.'.$courseid.'.domain'};
2981: my $cname = $env{'course.'.$courseid.'.num'};
1.271 albertel 2982: my @keys;
2983: foreach my $part (@{$partids}) {
2984: push(@keys,"$symb\0$part\0resettime");
2985: }
2986: my %results=&Apache::lonnet::get('nohist_resourcetracker',\@keys,
2987: $cdom,$cname);
2988: foreach my $part (@{$partids}) {
2989: $last_resets{$part}=$results{"$symb\0$part\0resettime"};
1.269 raeburn 2990: }
1.270 albertel 2991: return %last_resets;
1.269 raeburn 2992: }
2993:
1.251 banghart 2994: # ----------- Handles creating versions for portfolio files as answers
2995: sub version_portfiles {
1.343 banghart 2996: my ($record, $parts_graded, $courseid, $symb, $domain, $stu_name, $v_flag) = @_;
1.263 banghart 2997: my $version_parts = join('|',@$v_flag);
1.343 banghart 2998: my @returned_keys;
1.255 banghart 2999: my $parts = join('|', @$parts_graded);
1.517 raeburn 3000: my $portfolio_root = '/userfiles/portfolio';
1.277 albertel 3001: foreach my $key (keys(%$record)) {
1.259 banghart 3002: my $new_portfiles;
1.263 banghart 3003: if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
1.342 banghart 3004: my @versioned_portfiles;
1.367 albertel 3005: my @portfiles = split(/\s*,\s*/,$$record{$key});
1.252 banghart 3006: foreach my $file (@portfiles) {
1.306 banghart 3007: &Apache::lonnet::unmark_as_readonly($domain,$stu_name,[$symb,$env{'request.course.id'}],$file);
1.304 albertel 3008: my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*)$/);
3009: my ($answer_name,$answer_ver,$answer_ext) =
3010: &file_name_version_ext($answer_file);
1.517 raeburn 3011: my $getpropath = 1;
3012: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$directory,$domain,$stu_name,$getpropath);
1.342 banghart 3013: my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
1.306 banghart 3014: my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version);
3015: if ($new_answer ne 'problem getting file') {
1.342 banghart 3016: push(@versioned_portfiles, $directory.$new_answer);
1.306 banghart 3017: &Apache::lonnet::mark_as_readonly($domain,$stu_name,
1.367 albertel 3018: [$directory.$new_answer],
1.306 banghart 3019: [$symb,$env{'request.course.id'},'graded']);
1.259 banghart 3020: }
1.252 banghart 3021: }
1.343 banghart 3022: $$record{$key} = join(',',@versioned_portfiles);
3023: push(@returned_keys,$key);
1.251 banghart 3024: }
3025: }
1.343 banghart 3026: return (@returned_keys);
1.305 banghart 3027: }
3028:
1.307 banghart 3029: sub get_next_version {
1.341 banghart 3030: my ($answer_name, $answer_ext, $dir_list) = @_;
1.307 banghart 3031: my $version;
3032: foreach my $row (@$dir_list) {
3033: my ($file) = split(/\&/,$row,2);
3034: my ($file_name,$file_version,$file_ext) =
3035: &file_name_version_ext($file);
3036: if (($file_name eq $answer_name) &&
3037: ($file_ext eq $answer_ext)) {
3038: # gets here if filename and extension match, regardless of version
3039: if ($file_version ne '') {
3040: # a versioned file is found so save it for later
3041: if ($file_version > $version) {
3042: $version = $file_version;
3043: }
3044: }
3045: }
3046: }
3047: $version ++;
3048: return($version);
3049: }
3050:
1.305 banghart 3051: sub version_selected_portfile {
1.306 banghart 3052: my ($domain,$stu_name,$directory,$file_name,$version) = @_;
3053: my ($answer_name,$answer_ver,$answer_ext) =
3054: &file_name_version_ext($file_name);
3055: my $new_answer;
3056: $env{'form.copy'} = &Apache::lonnet::getfile("/uploaded/$domain/$stu_name/portfolio$directory$file_name");
3057: if($env{'form.copy'} eq '-1') {
3058: $new_answer = 'problem getting file';
3059: } else {
3060: $new_answer = $answer_name.'.'.$version.'.'.$answer_ext;
3061: my $copy_result = &Apache::lonnet::finishuserfileupload(
3062: $stu_name,$domain,'copy',
3063: '/portfolio'.$directory.$new_answer);
3064: }
3065: return ($new_answer);
1.251 banghart 3066: }
3067:
1.304 albertel 3068: sub file_name_version_ext {
3069: my ($file)=@_;
3070: my @file_parts = split(/\./, $file);
3071: my ($name,$version,$ext);
3072: if (@file_parts > 1) {
3073: $ext=pop(@file_parts);
3074: if (@file_parts > 1 && $file_parts[-1] =~ /^\d+$/) {
3075: $version=pop(@file_parts);
3076: }
3077: $name=join('.',@file_parts);
3078: } else {
3079: $name=join('.',@file_parts);
3080: }
3081: return($name,$version,$ext);
3082: }
3083:
1.44 ng 3084: #--------------------------------------------------------------------------------------
3085: #
3086: #-------------------------- Next few routines handles grading by section or whole class
3087: #
3088: #--- Javascript to handle grading by section or whole class
1.42 ng 3089: sub viewgrades_js {
3090: my ($request) = shift;
3091:
1.539 riegler 3092: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
1.597 wenzelju 3093: $request->print(&Apache::lonhtmlcommon::scripttag(<<VIEWJAVASCRIPT));
1.45 ng 3094: function writePoint(partid,weight,point) {
1.125 ng 3095: var radioButton = document.classgrade["RADVAL_"+partid];
3096: var textbox = document.classgrade["TEXTVAL_"+partid];
1.42 ng 3097: if (point == "textval") {
1.125 ng 3098: point = document.classgrade["TEXTVAL_"+partid].value;
1.109 matthew 3099: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 3100: alert("$alertmsg"+parseFloat(point));
1.42 ng 3101: var resetbox = false;
3102: for (var i=0; i<radioButton.length; i++) {
3103: if (radioButton[i].checked) {
3104: textbox.value = i;
3105: resetbox = true;
3106: }
3107: }
3108: if (!resetbox) {
3109: textbox.value = "";
3110: }
3111: return;
3112: }
1.109 matthew 3113: if (parseFloat(point) > parseFloat(weight)) {
3114: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 3115: ") greater than the weight for the part. Accept?");
3116: if (resp == false) {
3117: textbox.value = "";
3118: return;
3119: }
3120: }
1.42 ng 3121: for (var i=0; i<radioButton.length; i++) {
3122: radioButton[i].checked=false;
1.109 matthew 3123: if (parseFloat(point) == i) {
1.42 ng 3124: radioButton[i].checked=true;
3125: }
3126: }
1.41 ng 3127:
1.42 ng 3128: } else {
1.125 ng 3129: textbox.value = parseFloat(point);
1.42 ng 3130: }
1.41 ng 3131: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3132: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3133: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3134: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3135: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3136: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 3137: if (saveval != "correct") {
3138: scorename.value = point;
1.43 ng 3139: if (selname[0].selected != true) {
3140: selname[0].selected = true;
3141: }
1.42 ng 3142: }
3143: }
1.125 ng 3144: document.classgrade["SELVAL_"+partid][0].selected = true;
1.42 ng 3145: }
3146:
3147: function writeRadText(partid,weight) {
1.125 ng 3148: var selval = document.classgrade["SELVAL_"+partid];
3149: var radioButton = document.classgrade["RADVAL_"+partid];
1.265 www 3150: var override = document.classgrade["FORCE_"+partid].checked;
1.125 ng 3151: var textbox = document.classgrade["TEXTVAL_"+partid];
3152: if (selval[1].selected || selval[2].selected) {
1.42 ng 3153: for (var i=0; i<radioButton.length; i++) {
3154: radioButton[i].checked=false;
3155:
3156: }
3157: textbox.value = "";
3158:
3159: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3160: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3161: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3162: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3163: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3164: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 3165: if ((saveval != "correct") || override) {
1.42 ng 3166: scorename.value = "";
1.125 ng 3167: if (selval[1].selected) {
3168: selname[1].selected = true;
3169: } else {
3170: selname[2].selected = true;
3171: if (Number(document.classgrade["GD_"+user+"_"+partid+"_tries"].value))
3172: {document.classgrade["GD_"+user+"_"+partid+"_tries"].value = '0';}
3173: }
1.42 ng 3174: }
3175: }
1.43 ng 3176: } else {
3177: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3178: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3179: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3180: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3181: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3182: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 3183: if ((saveval != "correct") || override) {
1.125 ng 3184: scorename.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
1.43 ng 3185: selname[0].selected = true;
3186: }
3187: }
3188: }
1.42 ng 3189: }
3190:
3191: function changeSelect(partid,user) {
1.125 ng 3192: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
3193: var textbox = document.classgrade["GD_"+user+'_'+partid+"_awarded"];
1.44 ng 3194: var point = textbox.value;
1.125 ng 3195: var weight = document.classgrade["weight_"+partid].value;
1.44 ng 3196:
1.109 matthew 3197: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 3198: alert("$alertmsg"+parseFloat(point));
1.44 ng 3199: textbox.value = "";
3200: return;
3201: }
1.109 matthew 3202: if (parseFloat(point) > parseFloat(weight)) {
3203: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 3204: ") greater than the weight of the part. Accept?");
3205: if (resp == false) {
3206: textbox.value = "";
3207: return;
3208: }
3209: }
1.42 ng 3210: selval[0].selected = true;
3211: }
3212:
3213: function changeOneScore(partid,user) {
1.125 ng 3214: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
3215: if (selval[1].selected || selval[2].selected) {
3216: document.classgrade["GD_"+user+'_'+partid+"_awarded"].value = "";
3217: if (selval[2].selected) {
3218: document.classgrade["GD_"+user+'_'+partid+"_tries"].value = "0";
3219: }
1.269 raeburn 3220: }
1.42 ng 3221: }
3222:
3223: function resetEntry(numpart) {
3224: for (ctpart=0;ctpart<numpart;ctpart++) {
1.125 ng 3225: var partid = document.classgrade["partid_"+ctpart].value;
3226: var radioButton = document.classgrade["RADVAL_"+partid];
3227: var textbox = document.classgrade["TEXTVAL_"+partid];
3228: var selval = document.classgrade["SELVAL_"+partid];
1.42 ng 3229: for (var i=0; i<radioButton.length; i++) {
3230: radioButton[i].checked=false;
3231:
3232: }
3233: textbox.value = "";
3234: selval[0].selected = true;
3235:
3236: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3237: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3238: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3239: var resetscore = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3240: resetscore.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
3241: var resettries = document.classgrade["GD_"+user+"_"+partid+"_tries"];
3242: resettries.value = document.classgrade["GD_"+user+"_"+partid+"_tries_s"].value;
3243: var saveselval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3244: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 3245: if (saveselval == "excused") {
1.43 ng 3246: if (selname[1].selected == false) { selname[1].selected = true;}
1.42 ng 3247: } else {
1.43 ng 3248: if (selname[0].selected == false) {selname[0].selected = true};
1.42 ng 3249: }
3250: }
1.41 ng 3251: }
1.42 ng 3252: }
3253:
1.41 ng 3254: VIEWJAVASCRIPT
1.42 ng 3255: }
3256:
1.44 ng 3257: #--- show scores for a section or whole class w/ option to change/update a score
1.42 ng 3258: sub viewgrades {
1.608 www 3259: my ($request,$symb) = @_;
1.42 ng 3260: &viewgrades_js($request);
1.41 ng 3261:
1.168 albertel 3262: #need to make sure we have the correct data for later EXT calls,
3263: #thus invalidate the cache
3264: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 3265: $env{'course.'.$env{'request.course.id'}.'.num'},
3266: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 3267: &Apache::lonnet::clear_EXT_cache_status();
3268:
1.398 albertel 3269: my $result='<h3><span class="LC_info">'.&mt('Manual Grading').'</span></h3>';
1.41 ng 3270:
3271: #view individual student submission form - called using Javascript viewOneStudent
1.324 albertel 3272: $result.=&jscriptNform($symb);
1.41 ng 3273:
1.44 ng 3274: #beginning of class grading form
1.442 banghart 3275: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.41 ng 3276: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1.418 albertel 3277: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.38 ng 3278: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.432 banghart 3279: &build_section_inputs().
1.442 banghart 3280: '<input type="hidden" name="Status" value="'.$env{'stu_status'}.'" />'."\n".
1.72 ng 3281:
1.560 raeburn 3282: my ($common_header,$specific_header);
1.257 albertel 3283: if ($env{'form.section'} eq 'all') {
1.560 raeburn 3284: $common_header = &mt('Assign Common Grade to Class');
3285: $specific_header = &mt('Assign Grade to Specific Students in Class');
1.257 albertel 3286: } elsif ($env{'form.section'} eq 'none') {
1.560 raeburn 3287: $common_header = &mt('Assign Common Grade to Students in no Section');
3288: $specific_header = &mt('Assign Grade to Specific Students in no Section');
1.52 albertel 3289: } else {
1.560 raeburn 3290: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
3291: $common_header = &mt('Assign Common Grade to Students in Section(s) [_1]',$section_display);
3292: $specific_header = &mt('Assign Grade to Specific Students in Section(s) [_1]',$section_display);
1.52 albertel 3293: }
1.560 raeburn 3294: $result.= '<h3>'.$common_header.'</h3>'.&Apache::loncommon::start_data_table();
1.44 ng 3295: #radio buttons/text box for assigning points for a section or class.
3296: #handles different parts of a problem
1.582 raeburn 3297: my $res_error;
3298: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
3299: if ($res_error) {
3300: return &navmap_errormsg();
3301: }
1.42 ng 3302: my %weight = ();
3303: my $ctsparts = 0;
1.45 ng 3304: my %seen = ();
1.375 albertel 3305: my @part_response_id = &flatten_responseType($responseType);
3306: foreach my $part_response_id (@part_response_id) {
3307: my ($partid,$respid) = @{ $part_response_id };
3308: my $part_resp = join('_',@{ $part_response_id });
1.45 ng 3309: next if $seen{$partid};
3310: $seen{$partid}++;
1.375 albertel 3311: my $handgrade=$$handgrade{$part_resp};
1.42 ng 3312: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
3313: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
3314:
1.324 albertel 3315: my $display_part=&get_display_part($partid,$symb);
1.485 albertel 3316: my $radio.='<table border="0"><tr>';
1.41 ng 3317: my $ctr = 0;
1.42 ng 3318: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
1.485 albertel 3319: $radio.= '<td><label><input type="radio" name="RADVAL_'.$partid.'" '.
1.54 albertel 3320: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.288 albertel 3321: ','.$ctr.')" />'.$ctr."</label></td>\n";
1.41 ng 3322: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
3323: $ctr++;
3324: }
1.485 albertel 3325: $radio.='</tr></table>';
3326: my $line = '<input type="text" name="TEXTVAL_'.
1.589 bisitz 3327: $partid.'" size="4" '.'onchange="javascript:writePoint(\''.
1.54 albertel 3328: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.539 riegler 3329: $weight{$partid}.' '.&mt('(problem weight)').'</td>'."\n";
3330: $line.= '<td><b>'.&mt('Grade Status').':</b><select name="SELVAL_'.$partid.'"'.
1.589 bisitz 3331: 'onchange="javascript:writeRadText(\''.$partid.'\','.
1.59 albertel 3332: $weight{$partid}.')"> '.
1.401 albertel 3333: '<option selected="selected"> </option>'.
1.485 albertel 3334: '<option value="excused">'.&mt('excused').'</option>'.
3335: '<option value="reset status">'.&mt('reset status').'</option>'.
3336: '</select></td>'.
3337: '<td><label><input type="checkbox" name="FORCE_'.$partid.'" />'.&mt('Override "Correct"').'</label>';
3338: $line.='<input type="hidden" name="partid_'.
3339: $ctsparts.'" value="'.$partid.'" />'."\n";
3340: $line.='<input type="hidden" name="weight_'.
3341: $partid.'" value="'.$weight{$partid}.'" />'."\n";
3342:
3343: $result.=
3344: &Apache::loncommon::start_data_table_row()."\n".
1.577 bisitz 3345: '<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 3346: &Apache::loncommon::end_data_table_row()."\n";
1.42 ng 3347: $ctsparts++;
1.41 ng 3348: }
1.474 albertel 3349: $result.=&Apache::loncommon::end_data_table()."\n".
1.52 albertel 3350: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.485 albertel 3351: $result.='<input type="button" value="'.&mt('Revert to Default').'" '.
1.589 bisitz 3352: 'onclick="javascript:resetEntry('.$ctsparts.');" />';
1.41 ng 3353:
1.44 ng 3354: #table listing all the students in a section/class
3355: #header of table
1.560 raeburn 3356: $result.= '<h3>'.$specific_header.'</h3>'.
3357: &Apache::loncommon::start_data_table().
3358: &Apache::loncommon::start_data_table_header_row().
3359: '<th>'.&mt('No.').'</th>'.
3360: '<th>'.&nameUserString('header')."</th>\n";
1.582 raeburn 3361: my $partserror;
3362: my (@parts) = sort(&getpartlist($symb,\$partserror));
3363: if ($partserror) {
3364: return &navmap_errormsg();
3365: }
1.324 albertel 3366: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.269 raeburn 3367: my @partids = ();
1.41 ng 3368: foreach my $part (@parts) {
3369: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1.539 riegler 3370: my $narrowtext = &mt('Tries');
3371: $display =~ s|^Number of Attempts|$narrowtext <br />|; # makes the column narrower
1.41 ng 3372: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
1.207 albertel 3373: my ($partid) = &split_part_type($part);
1.524 raeburn 3374: push(@partids,$partid);
1.324 albertel 3375: my $display_part=&get_display_part($partid,$symb);
1.41 ng 3376: if ($display =~ /^Partial Credit Factor/) {
1.485 albertel 3377: $result.='<th>'.
3378: &mt('Score Part: [_1]<br /> (weight = [_2])',
3379: $display_part,$weight{$partid}).'</th>'."\n";
1.41 ng 3380: next;
1.485 albertel 3381:
1.207 albertel 3382: } else {
1.485 albertel 3383: if ($display =~ /Problem Status/) {
3384: my $grade_status_mt = &mt('Grade Status');
3385: $display =~ s{Problem Status}{$grade_status_mt<br />};
3386: }
3387: my $part_mt = &mt('Part:');
3388: $display =~s{\[Part: \Q$partid\E\]}{$part_mt $display_part};
1.41 ng 3389: }
1.485 albertel 3390:
1.474 albertel 3391: $result.='<th>'.$display.'</th>'."\n";
1.41 ng 3392: }
1.474 albertel 3393: $result.=&Apache::loncommon::end_data_table_header_row();
1.44 ng 3394:
1.270 albertel 3395: my %last_resets =
3396: &get_last_resets($symb,$env{'request.course.id'},\@partids);
1.269 raeburn 3397:
1.41 ng 3398: #get info for each student
1.44 ng 3399: #list all the students - with points and grade status
1.257 albertel 3400: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
1.41 ng 3401: my $ctr = 0;
1.294 albertel 3402: foreach (sort
3403: {
3404: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
3405: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
3406: }
3407: return $a cmp $b;
3408: } (keys(%$fullname))) {
1.126 ng 3409: $ctr++;
1.324 albertel 3410: $result.=&viewstudentgrade($symb,$env{'request.course.id'},
1.269 raeburn 3411: $_,$$fullname{$_},\@parts,\%weight,$ctr,\%last_resets);
1.41 ng 3412: }
1.474 albertel 3413: $result.=&Apache::loncommon::end_data_table();
1.41 ng 3414: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.485 albertel 3415: $result.='<input type="button" value="'.&mt('Save').'" '.
1.589 bisitz 3416: 'onclick="javascript:submit();" target="_self" /></form>'."\n";
1.96 albertel 3417: if (scalar(%$fullname) eq 0) {
3418: my $colspan=3+scalar(@parts);
1.433 banghart 3419: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.442 banghart 3420: my $stu_status = join(' or ',&Apache::loncommon::get_env_multiple('form.Status'));
1.433 banghart 3421: $result='<span class="LC_warning">'.
1.485 albertel 3422: &mt('There are no students in section(s) [_1] with enrollment status [_2] to modify or grade.',
1.442 banghart 3423: $section_display, $stu_status).
1.433 banghart 3424: '</span>';
1.96 albertel 3425: }
1.41 ng 3426: return $result;
3427: }
3428:
1.44 ng 3429: #--- call by previous routine to display each student
1.41 ng 3430: sub viewstudentgrade {
1.324 albertel 3431: my ($symb,$courseid,$student,$fullname,$parts,$weight,$ctr,$last_resets) = @_;
1.44 ng 3432: my ($uname,$udom) = split(/:/,$student);
3433: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.269 raeburn 3434: my %aggregates = ();
1.474 albertel 3435: my $result=&Apache::loncommon::start_data_table_row().'<td align="right">'.
1.233 albertel 3436: '<input type="hidden" name="ctr'.($ctr-1).'" value="'.$student.'" />'.
3437: "\n".$ctr.' </td><td> '.
1.44 ng 3438: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 3439: '\');" target="_self">'.$fullname.'</a> '.
1.398 albertel 3440: '<span class="LC_internal_info">('.$uname.($env{'user.domain'} eq $udom ? '' : ':'.$udom).')</span></td>'."\n";
1.281 albertel 3441: $student=~s/:/_/; # colon doen't work in javascript for names
1.63 albertel 3442: foreach my $apart (@$parts) {
3443: my ($part,$type) = &split_part_type($apart);
1.41 ng 3444: my $score=$record{"resource.$part.$type"};
1.276 albertel 3445: $result.='<td align="center">';
1.269 raeburn 3446: my ($aggtries,$totaltries);
3447: unless (exists($aggregates{$part})) {
1.270 albertel 3448: $totaltries = $record{'resource.'.$part.'.tries'};
3449:
3450: $aggtries = $totaltries;
1.269 raeburn 3451: if ($$last_resets{$part}) {
1.270 albertel 3452: $aggtries = &get_num_tries(\%record,$$last_resets{$part},
3453: $part);
3454: }
1.269 raeburn 3455: $result.='<input type="hidden" name="'.
3456: 'GD_'.$student.'_'.$part.'_aggtries" value="'.$aggtries.'" />'."\n";
3457: $result.='<input type="hidden" name="'.
3458: 'GD_'.$student.'_'.$part.'_totaltries" value="'.$totaltries.'" />'."\n";
3459: $aggregates{$part} = 1;
3460: }
1.41 ng 3461: if ($type eq 'awarded') {
1.320 albertel 3462: my $pts = $score eq '' ? '' : &compute_points($score,$$weight{$part});
1.42 ng 3463: $result.='<input type="hidden" name="'.
1.89 albertel 3464: 'GD_'.$student.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.233 albertel 3465: $result.='<input type="text" name="'.
1.89 albertel 3466: 'GD_'.$student.'_'.$part.'_awarded" '.
1.589 bisitz 3467: 'onchange="javascript:changeSelect(\''.$part.'\',\''.$student.
1.44 ng 3468: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41 ng 3469: } elsif ($type eq 'solved') {
3470: my ($status,$foo)=split(/_/,$score,2);
3471: $status = 'nothing' if ($status eq '');
1.89 albertel 3472: $result.='<input type="hidden" name="'.'GD_'.$student.'_'.
1.54 albertel 3473: $part.'_solved_s" value="'.$status.'" />'."\n";
1.233 albertel 3474: $result.=' <select name="'.
1.89 albertel 3475: 'GD_'.$student.'_'.$part.'_solved" '.
1.589 bisitz 3476: 'onchange="javascript:changeOneScore(\''.$part.'\',\''.$student.'\')" >'."\n";
1.485 albertel 3477: $result.= (($status eq 'excused') ? '<option> </option><option selected="selected" value="excused">'.&mt('excused').'</option>'
3478: : '<option selected="selected"> </option><option value="excused">'.&mt('excused').'</option>')."\n";
3479: $result.='<option value="reset status">'.&mt('reset status').'</option>';
1.126 ng 3480: $result.="</select> </td>\n";
1.122 ng 3481: } else {
3482: $result.='<input type="hidden" name="'.
3483: 'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
3484: "\n";
1.233 albertel 3485: $result.='<input type="text" name="'.
1.122 ng 3486: 'GD_'.$student.'_'.$part.'_'.$type.'" '.
3487: 'value="'.$score.'" size="4" /></td>'."\n";
1.41 ng 3488: }
3489: }
1.474 albertel 3490: $result.=&Apache::loncommon::end_data_table_row();
1.41 ng 3491: return $result;
1.38 ng 3492: }
3493:
1.44 ng 3494: #--- change scores for all the students in a section/class
3495: # record does not get update if unchanged
1.38 ng 3496: sub editgrades {
1.608 www 3497: my ($request,$symb) = @_;
1.41 ng 3498:
1.433 banghart 3499: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.477 albertel 3500: my $title='<h2>'.&mt('Current Grade Status').'</h2>';
1.433 banghart 3501: $title.='<h4>'.&mt('<b>Section: </b>[_1]',$section_display).'</h4>'."\n";
1.126 ng 3502:
1.477 albertel 3503: my $result= &Apache::loncommon::start_data_table().
3504: &Apache::loncommon::start_data_table_header_row().
3505: '<th rowspan="2" valign="middle">'.&mt('No.').'</th>'.
3506: '<th rowspan="2" valign="middle">'.&nameUserString('header')."</th>\n";
1.43 ng 3507: my %scoreptr = (
3508: 'correct' =>'correct_by_override',
3509: 'incorrect'=>'incorrect_by_override',
3510: 'excused' =>'excused',
3511: 'ungraded' =>'ungraded_attempted',
1.596 raeburn 3512: 'credited' =>'credit_attempted',
1.43 ng 3513: 'nothing' => '',
3514: );
1.257 albertel 3515: my ($classlist,undef,$fullname) = &getclasslist($env{'form.section'},'0');
1.34 ng 3516:
1.44 ng 3517: my (@partid);
3518: my %weight = ();
1.54 albertel 3519: my %columns = ();
1.44 ng 3520: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54 albertel 3521:
1.582 raeburn 3522: my $partserror;
3523: my (@parts) = sort(&getpartlist($symb,\$partserror));
3524: if ($partserror) {
3525: return &navmap_errormsg();
3526: }
1.54 albertel 3527: my $header;
1.257 albertel 3528: while ($ctr < $env{'form.totalparts'}) {
3529: my $partid = $env{'form.partid_'.$ctr};
1.524 raeburn 3530: push(@partid,$partid);
1.257 albertel 3531: $weight{$partid} = $env{'form.weight_'.$partid};
1.44 ng 3532: $ctr++;
1.54 albertel 3533: }
1.324 albertel 3534: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.54 albertel 3535: foreach my $partid (@partid) {
1.478 albertel 3536: $header .= '<th align="center">'.&mt('Old Score').'</th>'.
3537: '<th align="center">'.&mt('New Score').'</th>';
1.54 albertel 3538: $columns{$partid}=2;
3539: foreach my $stores (@parts) {
3540: my ($part,$type) = &split_part_type($stores);
3541: if ($part !~ m/^\Q$partid\E/) { next;}
3542: if ($type eq 'awarded' || $type eq 'solved') { next; }
3543: my $display=&Apache::lonnet::metadata($url,$stores.'.display');
1.551 raeburn 3544: $display =~ s/\[Part: \Q$part\E\]//;
1.539 riegler 3545: my $narrowtext = &mt('Tries');
3546: $display =~ s/Number of Attempts/$narrowtext/;
3547: $header .= '<th align="center">'.&mt('Old').' '.$display.'</th>'.
3548: '<th align="center">'.&mt('New').' '.$display.'</th>';
1.54 albertel 3549: $columns{$partid}+=2;
3550: }
3551: }
3552: foreach my $partid (@partid) {
1.324 albertel 3553: my $display_part=&get_display_part($partid,$symb);
1.478 albertel 3554: $result .= '<th colspan="'.$columns{$partid}.'" align="center">'.
3555: &mt('Part: [_1] (Weight = [_2])',$display_part,$weight{$partid}).
3556: '</th>';
1.54 albertel 3557:
1.44 ng 3558: }
1.477 albertel 3559: $result .= &Apache::loncommon::end_data_table_header_row().
3560: &Apache::loncommon::start_data_table_header_row().
3561: $header.
3562: &Apache::loncommon::end_data_table_header_row();
3563: my @noupdate;
1.126 ng 3564: my ($updateCtr,$noupdateCtr) = (1,1);
1.257 albertel 3565: for ($i=0; $i<$env{'form.total'}; $i++) {
1.93 albertel 3566: my $line;
1.257 albertel 3567: my $user = $env{'form.ctr'.$i};
1.281 albertel 3568: my ($uname,$udom)=split(/:/,$user);
1.44 ng 3569: my %newrecord;
3570: my $updateflag = 0;
1.281 albertel 3571: $line .= '<td>'.&nameUserString(undef,$$fullname{$user},$uname,$udom).'</td>';
1.108 albertel 3572: my $usec=$classlist->{"$uname:$udom"}[5];
1.105 albertel 3573: if (!&canmodify($usec)) {
1.126 ng 3574: my $numcols=scalar(@partid)*4+2;
1.477 albertel 3575: push(@noupdate,
1.478 albertel 3576: $line."<td colspan=\"$numcols\"><span class=\"LC_warning\">".
3577: &mt('Not allowed to modify student')."</span></td></tr>");
1.105 albertel 3578: next;
3579: }
1.269 raeburn 3580: my %aggregate = ();
3581: my $aggregateflag = 0;
1.281 albertel 3582: $user=~s/:/_/; # colon doen't work in javascript for names
1.44 ng 3583: foreach (@partid) {
1.257 albertel 3584: my $old_aw = $env{'form.GD_'.$user.'_'.$_.'_awarded_s'};
1.54 albertel 3585: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
3586: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
1.257 albertel 3587: my $old_score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
3588: my $awarded = $env{'form.GD_'.$user.'_'.$_.'_awarded'};
1.54 albertel 3589: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
3590: my $partial = $awarded eq '' ? '' : $pcr;
1.44 ng 3591: my $score;
3592: if ($partial eq '') {
1.257 albertel 3593: $score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 3594: } elsif ($partial > 0) {
3595: $score = 'correct_by_override';
3596: } elsif ($partial == 0) {
3597: $score = 'incorrect_by_override';
3598: }
1.257 albertel 3599: my $dropMenu = $env{'form.GD_'.$user.'_'.$_.'_solved'};
1.125 ng 3600: $score = 'excused' if (($dropMenu eq 'excused') && ($score ne 'excused'));
3601:
1.292 albertel 3602: $newrecord{'resource.'.$_.'.regrader'}=
3603: "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 3604: if ($dropMenu eq 'reset status' &&
3605: $old_score ne '') { # ignore if no previous attempts => nothing to reset
1.299 albertel 3606: $newrecord{'resource.'.$_.'.tries'} = '';
1.125 ng 3607: $newrecord{'resource.'.$_.'.solved'} = '';
3608: $newrecord{'resource.'.$_.'.award'} = '';
1.299 albertel 3609: $newrecord{'resource.'.$_.'.awarded'} = '';
1.125 ng 3610: $updateflag = 1;
1.269 raeburn 3611: if ($env{'form.GD_'.$user.'_'.$_.'_aggtries'} > 0) {
3612: my $aggtries = $env{'form.GD_'.$user.'_'.$_.'_aggtries'};
3613: my $totaltries = $env{'form.GD_'.$user.'_'.$_.'_totaltries'};
3614: my $solvedstatus = $env{'form.GD_'.$user.'_'.$_.'_solved_s'};
3615: &decrement_aggs($symb,$_,\%aggregate,$aggtries,$totaltries,$solvedstatus);
3616: $aggregateflag = 1;
3617: }
1.139 albertel 3618: } elsif (!($old_part eq $partial && $old_score eq $score)) {
3619: $updateflag = 1;
3620: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
3621: $newrecord{'resource.'.$_.'.solved'} = $score;
3622: $rec_update++;
1.125 ng 3623: }
3624:
1.93 albertel 3625: $line .= '<td align="center">'.$old_aw.' </td>'.
1.44 ng 3626: '<td align="center">'.$awarded.
3627: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 3628:
1.54 albertel 3629:
3630: my $partid=$_;
3631: foreach my $stores (@parts) {
3632: my ($part,$type) = &split_part_type($stores);
3633: if ($part !~ m/^\Q$partid\E/) { next;}
3634: if ($type eq 'awarded' || $type eq 'solved') { next; }
1.257 albertel 3635: my $old_aw = $env{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
3636: my $awarded = $env{'form.GD_'.$user.'_'.$part.'_'.$type};
1.54 albertel 3637: if ($awarded ne '' && $awarded ne $old_aw) {
3638: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.257 albertel 3639: $newrecord{'resource.'.$part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.54 albertel 3640: $updateflag=1;
3641: }
1.93 albertel 3642: $line .= '<td align="center">'.$old_aw.' </td>'.
1.54 albertel 3643: '<td align="center">'.$awarded.' </td>';
3644: }
1.44 ng 3645: }
1.477 albertel 3646: $line.="\n";
1.301 albertel 3647:
3648: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3649: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3650:
1.44 ng 3651: if ($updateflag) {
3652: $count++;
1.257 albertel 3653: &Apache::lonnet::cstore(\%newrecord,$symb,$env{'request.course.id'},
1.89 albertel 3654: $udom,$uname);
1.301 albertel 3655:
3656: if (&Apache::bridgetask::in_queue('gradingqueue',$symb,$cdom,
3657: $cnum,$udom,$uname)) {
3658: # need to figure out if should be in queue.
3659: my %record =
3660: &Apache::lonnet::restore($symb,$env{'request.course.id'},
3661: $udom,$uname);
3662: my $all_graded = 1;
3663: my $none_graded = 1;
3664: foreach my $part (@parts) {
3665: if ( $record{'resource.'.$part.'.awarded'} eq '' ) {
3666: $all_graded = 0;
3667: } else {
3668: $none_graded = 0;
3669: }
3670: }
3671:
3672: if ($all_graded || $none_graded) {
3673: &Apache::bridgetask::remove_from_queue('gradingqueue',
3674: $symb,$cdom,$cnum,
3675: $udom,$uname);
3676: }
3677: }
3678:
1.477 albertel 3679: $result.=&Apache::loncommon::start_data_table_row().
3680: '<td align="right"> '.$updateCtr.' </td>'.$line.
3681: &Apache::loncommon::end_data_table_row();
1.126 ng 3682: $updateCtr++;
1.93 albertel 3683: } else {
1.477 albertel 3684: push(@noupdate,
3685: '<td align="right"> '.$noupdateCtr.' </td>'.$line);
1.126 ng 3686: $noupdateCtr++;
1.44 ng 3687: }
1.269 raeburn 3688: if ($aggregateflag) {
3689: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 3690: $cdom,$cnum);
1.269 raeburn 3691: }
1.93 albertel 3692: }
1.477 albertel 3693: if (@noupdate) {
1.126 ng 3694: # my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3;
3695: my $numcols=scalar(@partid)*4+2;
1.477 albertel 3696: $result .= &Apache::loncommon::start_data_table_row('LC_empty_row').
1.478 albertel 3697: '<td align="center" colspan="'.$numcols.'">'.
3698: &mt('No Changes Occurred For the Students Below').
3699: '</td>'.
1.477 albertel 3700: &Apache::loncommon::end_data_table_row();
3701: foreach my $line (@noupdate) {
3702: $result.=
3703: &Apache::loncommon::start_data_table_row().
3704: $line.
3705: &Apache::loncommon::end_data_table_row();
3706: }
1.44 ng 3707: }
1.614 www 3708: $result .= &Apache::loncommon::end_data_table();
1.478 albertel 3709: my $msg = '<p><b>'.
3710: &mt('Number of records updated = [_1] for [quant,_2,student].',
3711: $rec_update,$count).'</b><br />'.
3712: '<b>'.&mt('Total number of students = [_1]',$env{'form.total'}).
3713: '</b></p>';
1.44 ng 3714: return $title.$msg.$result;
1.5 albertel 3715: }
1.54 albertel 3716:
3717: sub split_part_type {
3718: my ($partstr) = @_;
3719: my ($temp,@allparts)=split(/_/,$partstr);
3720: my $type=pop(@allparts);
1.439 albertel 3721: my $part=join('_',@allparts);
1.54 albertel 3722: return ($part,$type);
3723: }
3724:
1.44 ng 3725: #------------- end of section for handling grading by section/class ---------
3726: #
3727: #----------------------------------------------------------------------------
3728:
1.5 albertel 3729:
1.44 ng 3730: #----------------------------------------------------------------------------
3731: #
3732: #-------------------------- Next few routines handles grading by csv upload
3733: #
3734: #--- Javascript to handle csv upload
1.27 albertel 3735: sub csvupload_javascript_reverse_associate {
1.573 bisitz 3736: my $error1=&mt('You need to specify the username or the student/employee ID');
1.246 albertel 3737: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3738: return(<<ENDPICK);
3739: function verify(vf) {
3740: var foundsomething=0;
3741: var founduname=0;
1.243 albertel 3742: var foundID=0;
1.27 albertel 3743: for (i=0;i<=vf.nfields.value;i++) {
3744: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3745: if (i==0 && tw!=0) { foundID=1; }
3746: if (i==1 && tw!=0) { founduname=1; }
3747: if (i!=0 && i!=1 && i!=2 && tw!=0) { foundsomething=1; }
1.27 albertel 3748: }
1.246 albertel 3749: if (founduname==0 && foundID==0) {
3750: alert('$error1');
3751: return;
1.27 albertel 3752: }
3753: if (foundsomething==0) {
1.246 albertel 3754: alert('$error2');
3755: return;
1.27 albertel 3756: }
3757: vf.submit();
3758: }
3759: function flip(vf,tf) {
3760: var nw=eval('vf.f'+tf+'.selectedIndex');
3761: var i;
3762: for (i=0;i<=vf.nfields.value;i++) {
3763: //can not pick the same destination field for both name and domain
3764: if (((i ==0)||(i ==1)) &&
3765: ((tf==0)||(tf==1)) &&
3766: (i!=tf) &&
3767: (eval('vf.f'+i+'.selectedIndex')==nw)) {
3768: eval('vf.f'+i+'.selectedIndex=0;')
3769: }
3770: }
3771: }
3772: ENDPICK
3773: }
3774:
3775: sub csvupload_javascript_forward_associate {
1.573 bisitz 3776: my $error1=&mt('You need to specify the username or the student/employee ID');
1.246 albertel 3777: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3778: return(<<ENDPICK);
3779: function verify(vf) {
3780: var foundsomething=0;
3781: var founduname=0;
1.243 albertel 3782: var foundID=0;
1.27 albertel 3783: for (i=0;i<=vf.nfields.value;i++) {
3784: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3785: if (tw==1) { foundID=1; }
3786: if (tw==2) { founduname=1; }
3787: if (tw>3) { foundsomething=1; }
1.27 albertel 3788: }
1.246 albertel 3789: if (founduname==0 && foundID==0) {
3790: alert('$error1');
3791: return;
1.27 albertel 3792: }
3793: if (foundsomething==0) {
1.246 albertel 3794: alert('$error2');
3795: return;
1.27 albertel 3796: }
3797: vf.submit();
3798: }
3799: function flip(vf,tf) {
3800: var nw=eval('vf.f'+tf+'.selectedIndex');
3801: var i;
3802: //can not pick the same destination field twice
3803: for (i=0;i<=vf.nfields.value;i++) {
3804: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
3805: eval('vf.f'+i+'.selectedIndex=0;')
3806: }
3807: }
3808: }
3809: ENDPICK
3810: }
3811:
1.26 albertel 3812: sub csvuploadmap_header {
1.324 albertel 3813: my ($request,$symb,$datatoken,$distotal)= @_;
1.41 ng 3814: my $javascript;
1.257 albertel 3815: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3816: $javascript=&csvupload_javascript_reverse_associate();
3817: } else {
3818: $javascript=&csvupload_javascript_forward_associate();
3819: }
1.45 ng 3820:
1.598 www 3821: my $result='';
1.257 albertel 3822: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1.245 albertel 3823: my $ignore=&mt('Ignore First Line');
1.418 albertel 3824: $symb = &Apache::lonenc::check_encrypt($symb);
1.41 ng 3825: $request->print(<<ENDPICK);
1.26 albertel 3826: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.398 albertel 3827: <h3><span class="LC_info">Uploading Class Grades</span></h3>
1.45 ng 3828: $result
1.326 albertel 3829: <hr />
1.26 albertel 3830: <h3>Identify fields</h3>
3831: Total number of records found in file: $distotal <hr />
3832: Enter as many fields as you can. The system will inform you and bring you back
3833: to this page if the data selected is insufficient to run your class.<hr />
1.589 bisitz 3834: <input type="button" value="Reverse Association" onclick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1.245 albertel 3835: <label><input type="checkbox" name="noFirstLine" $checked />$ignore</label>
1.26 albertel 3836: <input type="hidden" name="associate" value="" />
3837: <input type="hidden" name="phase" value="three" />
3838: <input type="hidden" name="datatoken" value="$datatoken" />
1.257 albertel 3839: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
3840: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
1.26 albertel 3841: <input type="hidden" name="upfile_associate"
1.257 albertel 3842: value="$env{'form.upfile_associate'}" />
1.26 albertel 3843: <input type="hidden" name="symb" value="$symb" />
1.246 albertel 3844: <input type="hidden" name="command" value="csvuploadoptions" />
1.26 albertel 3845: <hr />
3846: ENDPICK
1.597 wenzelju 3847: $request->print(&Apache::lonhtmlcommon::scripttag($javascript));
1.118 ng 3848: return '';
1.26 albertel 3849:
3850: }
3851:
3852: sub csvupload_fields {
1.582 raeburn 3853: my ($symb,$errorref) = @_;
3854: my (@parts) = &getpartlist($symb,$errorref);
3855: if (ref($errorref)) {
3856: if ($$errorref) {
3857: return;
3858: }
3859: }
3860:
1.556 weissno 3861: my @fields=(['ID','Student/Employee ID'],
1.243 albertel 3862: ['username','Student Username'],
3863: ['domain','Student Domain']);
1.324 albertel 3864: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.41 ng 3865: foreach my $part (sort(@parts)) {
3866: my @datum;
3867: my $display=&Apache::lonnet::metadata($url,$part.'.display');
3868: my $name=$part;
3869: if (!$display) { $display = $name; }
3870: @datum=($name,$display);
1.244 albertel 3871: if ($name=~/^stores_(.*)_awarded/) {
3872: push(@fields,['stores_'.$1.'_points',"Points [Part: $1]"]);
3873: }
1.41 ng 3874: push(@fields,\@datum);
3875: }
3876: return (@fields);
1.26 albertel 3877: }
3878:
3879: sub csvuploadmap_footer {
1.41 ng 3880: my ($request,$i,$keyfields) =@_;
3881: $request->print(<<ENDPICK);
1.26 albertel 3882: </table>
3883: <input type="hidden" name="nfields" value="$i" />
3884: <input type="hidden" name="keyfields" value="$keyfields" />
1.589 bisitz 3885: <input type="button" onclick="javascript:verify(this.form)" value="Assign Grades" /><br />
1.26 albertel 3886: </form>
3887: ENDPICK
3888: }
3889:
1.283 albertel 3890: sub checkforfile_js {
1.539 riegler 3891: my $alertmsg = &mt('Please use the browse button to select a file from your local directory.');
1.597 wenzelju 3892: my $result = &Apache::lonhtmlcommon::scripttag(<<CSVFORMJS);
1.86 ng 3893: function checkUpload(formname) {
3894: if (formname.upfile.value == "") {
1.539 riegler 3895: alert("$alertmsg");
1.86 ng 3896: return false;
3897: }
3898: formname.submit();
3899: }
3900: CSVFORMJS
1.283 albertel 3901: return $result;
3902: }
3903:
3904: sub upcsvScores_form {
1.608 www 3905: my ($request,$symb) = @_;
1.283 albertel 3906: if (!$symb) {return '';}
3907: my $result=&checkforfile_js();
1.326 albertel 3908: $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
3909: $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
1.538 schulted 3910: $result.=' <b>'.&mt('Specify a file containing the class scores for current resource.').
3911: '</b></td></tr>'."\n";
1.86 ng 3912: $result.='<tr bgcolor=#ffffe6><td>'."\n";
1.370 www 3913: my $upload=&mt("Upload Scores");
1.86 ng 3914: my $upfile_select=&Apache::loncommon::upfile_select_html();
1.245 albertel 3915: my $ignore=&mt('Ignore First Line');
1.418 albertel 3916: $symb = &Apache::lonenc::check_encrypt($symb);
1.86 ng 3917: $result.=<<ENDUPFORM;
1.106 albertel 3918: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.86 ng 3919: <input type="hidden" name="symb" value="$symb" />
3920: <input type="hidden" name="command" value="csvuploadmap" />
3921: $upfile_select
1.589 bisitz 3922: <br /><input type="button" onclick="javascript:checkUpload(this.form);" value="$upload" />
1.283 albertel 3923: <label><input type="checkbox" name="noFirstLine" />$ignore</label>
1.86 ng 3924: </form>
3925: ENDUPFORM
1.370 www 3926: $result.=&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
3927: &mt("How do I create a CSV file from a spreadsheet"))
3928: .'</td></tr></table>'."\n";
1.86 ng 3929: $result.='</td></tr></table><br /><br />'."\n";
3930: return $result;
3931: }
3932:
3933:
1.26 albertel 3934: sub csvuploadmap {
1.608 www 3935: my ($request,$symb)= @_;
1.41 ng 3936: if (!$symb) {return '';}
1.72 ng 3937:
1.41 ng 3938: my $datatoken;
1.257 albertel 3939: if (!$env{'form.datatoken'}) {
1.41 ng 3940: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 3941: } else {
1.257 albertel 3942: $datatoken=$env{'form.datatoken'};
1.41 ng 3943: &Apache::loncommon::load_tmp_file($request);
1.26 albertel 3944: }
1.41 ng 3945: my @records=&Apache::loncommon::upfile_record_sep();
1.257 albertel 3946: if ($env{'form.noFirstLine'}) { shift(@records); }
1.324 albertel 3947: &csvuploadmap_header($request,$symb,$datatoken,$#records+1);
1.41 ng 3948: my ($i,$keyfields);
3949: if (@records) {
1.582 raeburn 3950: my $fieldserror;
3951: my @fields=&csvupload_fields($symb,\$fieldserror);
3952: if ($fieldserror) {
3953: $request->print(&navmap_errormsg());
3954: return;
3955: }
1.257 albertel 3956: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3957: &Apache::loncommon::csv_print_samples($request,\@records);
3958: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
3959: \@fields);
3960: foreach (@fields) { $keyfields.=$_->[0].','; }
3961: chop($keyfields);
3962: } else {
3963: unshift(@fields,['none','']);
3964: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
3965: \@fields);
1.311 banghart 3966: foreach my $rec (@records) {
3967: my %temp = &Apache::loncommon::record_sep($rec);
3968: if (%temp) {
3969: $keyfields=join(',',sort(keys(%temp)));
3970: last;
3971: }
3972: }
1.41 ng 3973: }
3974: }
3975: &csvuploadmap_footer($request,$i,$keyfields);
1.72 ng 3976:
1.41 ng 3977: return '';
1.27 albertel 3978: }
3979:
1.246 albertel 3980: sub csvuploadoptions {
1.608 www 3981: my ($request,$symb)= @_;
1.257 albertel 3982: my $checked=(($env{'form.noFirstLine'})?'1':'0');
1.246 albertel 3983: my $ignore=&mt('Ignore First Line');
3984: $request->print(<<ENDPICK);
3985: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.398 albertel 3986: <h3><span class="LC_info">Uploading Class Grade Options</span></h3>
1.246 albertel 3987: <input type="hidden" name="command" value="csvuploadassign" />
1.302 albertel 3988: <!--
1.246 albertel 3989: <p>
3990: <label>
3991: <input type="checkbox" name="show_full_results" />
3992: Show a table of all changes
3993: </label>
3994: </p>
1.302 albertel 3995: -->
1.246 albertel 3996: <p>
3997: <label>
3998: <input type="checkbox" name="overwite_scores" checked="checked" />
3999: Overwrite any existing score
4000: </label>
4001: </p>
4002: ENDPICK
4003: my %fields=&get_fields();
4004: if (!defined($fields{'domain'})) {
1.257 albertel 4005: my $domform = &Apache::loncommon::select_dom_form($env{'request.role.domain'},'default_domain');
1.246 albertel 4006: $request->print("\n<p> Users are in domain: ".$domform."</p>\n");
4007: }
1.257 albertel 4008: foreach my $key (sort(keys(%env))) {
1.246 albertel 4009: if ($key !~ /^form\.(.*)$/) { next; }
4010: my $cleankey=$1;
4011: if ($cleankey eq 'command') { next; }
4012: $request->print('<input type="hidden" name="'.$cleankey.
1.257 albertel 4013: '" value="'.$env{$key}.'" />'."\n");
1.246 albertel 4014: }
4015: # FIXME do a check for any duplicated user ids...
4016: # FIXME do a check for any invalid user ids?...
1.290 albertel 4017: $request->print('<input type="submit" value="Assign Grades" /><br />
4018: <hr /></form>'."\n");
1.246 albertel 4019: return '';
4020: }
4021:
4022: sub get_fields {
4023: my %fields;
1.257 albertel 4024: my @keyfields = split(/\,/,$env{'form.keyfields'});
4025: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
4026: if ($env{'form.upfile_associate'} eq 'reverse') {
4027: if ($env{'form.f'.$i} ne 'none') {
4028: $fields{$keyfields[$i]}=$env{'form.f'.$i};
1.41 ng 4029: }
4030: } else {
1.257 albertel 4031: if ($env{'form.f'.$i} ne 'none') {
4032: $fields{$env{'form.f'.$i}}=$keyfields[$i];
1.41 ng 4033: }
4034: }
1.27 albertel 4035: }
1.246 albertel 4036: return %fields;
4037: }
4038:
4039: sub csvuploadassign {
1.608 www 4040: my ($request,$symb)= @_;
1.246 albertel 4041: if (!$symb) {return '';}
1.345 bowersj2 4042: my $error_msg = '';
1.246 albertel 4043: &Apache::loncommon::load_tmp_file($request);
4044: my @gradedata = &Apache::loncommon::upfile_record_sep();
1.257 albertel 4045: if ($env{'form.noFirstLine'}) { shift(@gradedata); }
1.246 albertel 4046: my %fields=&get_fields();
1.41 ng 4047: $request->print('<h3>Assigning Grades</h3>');
1.257 albertel 4048: my $courseid=$env{'request.course.id'};
1.97 albertel 4049: my ($classlist) = &getclasslist('all',0);
1.106 albertel 4050: my @notallowed;
1.41 ng 4051: my @skipped;
4052: my $countdone=0;
4053: foreach my $grade (@gradedata) {
4054: my %entries=&Apache::loncommon::record_sep($grade);
1.246 albertel 4055: my $domain;
4056: if ($entries{$fields{'domain'}}) {
4057: $domain=$entries{$fields{'domain'}};
4058: } else {
1.257 albertel 4059: $domain=$env{'form.default_domain'};
1.246 albertel 4060: }
1.243 albertel 4061: $domain=~s/\s//g;
1.41 ng 4062: my $username=$entries{$fields{'username'}};
1.160 albertel 4063: $username=~s/\s//g;
1.243 albertel 4064: if (!$username) {
4065: my $id=$entries{$fields{'ID'}};
1.247 albertel 4066: $id=~s/\s//g;
1.243 albertel 4067: my %ids=&Apache::lonnet::idget($domain,$id);
4068: $username=$ids{$id};
4069: }
1.41 ng 4070: if (!exists($$classlist{"$username:$domain"})) {
1.247 albertel 4071: my $id=$entries{$fields{'ID'}};
4072: $id=~s/\s//g;
4073: if ($id) {
4074: push(@skipped,"$id:$domain");
4075: } else {
4076: push(@skipped,"$username:$domain");
4077: }
1.41 ng 4078: next;
4079: }
1.108 albertel 4080: my $usec=$classlist->{"$username:$domain"}[5];
1.106 albertel 4081: if (!&canmodify($usec)) {
4082: push(@notallowed,"$username:$domain");
4083: next;
4084: }
1.244 albertel 4085: my %points;
1.41 ng 4086: my %grades;
4087: foreach my $dest (keys(%fields)) {
1.244 albertel 4088: if ($dest eq 'ID' || $dest eq 'username' ||
4089: $dest eq 'domain') { next; }
4090: if ($entries{$fields{$dest}} =~ /^\s*$/) { next; }
4091: if ($dest=~/stores_(.*)_points/) {
4092: my $part=$1;
4093: my $wgt =&Apache::lonnet::EXT('resource.'.$part.'.weight',
4094: $symb,$domain,$username);
1.345 bowersj2 4095: if ($wgt) {
4096: $entries{$fields{$dest}}=~s/\s//g;
4097: my $pcr=$entries{$fields{$dest}} / $wgt;
1.463 albertel 4098: my $award=($pcr == 0) ? 'incorrect_by_override'
4099: : 'correct_by_override';
1.345 bowersj2 4100: $grades{"resource.$part.awarded"}=$pcr;
4101: $grades{"resource.$part.solved"}=$award;
4102: $points{$part}=1;
4103: } else {
4104: $error_msg = "<br />" .
4105: &mt("Some point values were assigned"
4106: ." for problems with a weight "
4107: ."of zero. These values were "
4108: ."ignored.");
4109: }
1.244 albertel 4110: } else {
4111: if ($dest=~/stores_(.*)_awarded/) { if ($points{$1}) {next;} }
4112: if ($dest=~/stores_(.*)_solved/) { if ($points{$1}) {next;} }
4113: my $store_key=$dest;
4114: $store_key=~s/^stores/resource/;
4115: $store_key=~s/_/\./g;
4116: $grades{$store_key}=$entries{$fields{$dest}};
4117: }
1.41 ng 4118: }
1.508 www 4119: if (! %grades) {
4120: push(@skipped,&mt("[_1]: no data to save","$username:$domain"));
4121: } else {
4122: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
4123: my $result=&Apache::lonnet::cstore(\%grades,$symb,
1.302 albertel 4124: $env{'request.course.id'},
4125: $domain,$username);
1.508 www 4126: if ($result eq 'ok') {
4127: $request->print('.');
4128: } else {
4129: $request->print("<p><span class=\"LC_error\">".
4130: &mt("Failed to save data for student [_1]. Message when trying to save was: [_2]",
4131: "$username:$domain",$result)."</span></p>");
4132: }
4133: $request->rflush();
4134: $countdone++;
4135: }
1.41 ng 4136: }
1.570 www 4137: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt("Saved scores for [quant,_1,student]",$countdone),$countdone==0));
1.41 ng 4138: if (@skipped) {
1.571 www 4139: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('No scores stored for the following username(s):'),1).'<br />');
4140: $request->print(join(', ',@skipped));
1.106 albertel 4141: }
4142: if (@notallowed) {
1.571 www 4143: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('Modification of scores not allowed for the following username(s):'),1).'<br />');
4144: $request->print(join(', ',@notallowed));
1.41 ng 4145: }
1.106 albertel 4146: $request->print("<br />\n");
1.345 bowersj2 4147: return $error_msg;
1.26 albertel 4148: }
1.44 ng 4149: #------------- end of section for handling csv file upload ---------
4150: #
4151: #-------------------------------------------------------------------
4152: #
1.122 ng 4153: #-------------- Next few routines handle grading by page/sequence
1.72 ng 4154: #
4155: #--- Select a page/sequence and a student to grade
1.68 ng 4156: sub pickStudentPage {
1.608 www 4157: my ($request,$symb) = @_;
1.68 ng 4158:
1.539 riegler 4159: my $alertmsg = &mt('Please select the student you wish to grade.');
1.597 wenzelju 4160: $request->print(&Apache::lonhtmlcommon::scripttag(<<LISTJAVASCRIPT));
1.68 ng 4161:
4162: function checkPickOne(formname) {
1.76 ng 4163: if (radioSelection(formname.student) == null) {
1.539 riegler 4164: alert("$alertmsg");
1.68 ng 4165: return;
4166: }
1.125 ng 4167: ptr = pullDownSelection(formname.selectpage);
4168: formname.page.value = formname["page"+ptr].value;
4169: formname.title.value = formname["title"+ptr].value;
1.68 ng 4170: formname.submit();
4171: }
4172:
4173: LISTJAVASCRIPT
1.118 ng 4174: &commonJSfunctions($request);
1.608 www 4175:
1.257 albertel 4176: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4177: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4178: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.68 ng 4179:
1.398 albertel 4180: my $result='<h3><span class="LC_info"> '.
1.485 albertel 4181: &mt('Manual Grading by Page or Sequence').'</span></h3>';
1.68 ng 4182:
1.80 ng 4183: $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
1.582 raeburn 4184: my $map_error;
4185: my ($titles,$symbx) = &getSymbMap($map_error);
4186: if ($map_error) {
4187: $request->print(&navmap_errormsg());
4188: return;
4189: }
1.137 albertel 4190: my ($curpage) =&Apache::lonnet::decode_symb($symb);
4191: # my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb);
4192: # my $type=($curpage =~ /\.(page|sequence)/);
1.485 albertel 4193: my $select = '<select name="selectpage">'."\n";
1.70 ng 4194: my $ctr=0;
1.68 ng 4195: foreach (@$titles) {
4196: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.485 albertel 4197: $select.='<option value="'.$ctr.'" '.
1.401 albertel 4198: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.71 ng 4199: '>'.$showtitle.'</option>'."\n";
1.70 ng 4200: $ctr++;
1.68 ng 4201: }
1.485 albertel 4202: $select.= '</select>';
1.539 riegler 4203: $result.=' <b>'.&mt('Problems from').':</b> '.$select."<br />\n";
1.485 albertel 4204:
1.70 ng 4205: $ctr=0;
4206: foreach (@$titles) {
4207: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
4208: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
4209: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
4210: $ctr++;
4211: }
1.72 ng 4212: $result.='<input type="hidden" name="page" />'."\n".
4213: '<input type="hidden" name="title" />'."\n";
1.68 ng 4214:
1.485 albertel 4215: my $options =
4216: '<label><input type="radio" name="vProb" value="no" checked="checked" /> '.&mt('no').' </label>'."\n".
4217: '<label><input type="radio" name="vProb" value="yes" /> '.&mt('yes').' </label>'."<br />\n";
1.539 riegler 4218: $result.=' <b>'.&mt('View Problem Text').': </b>'.$options;
1.485 albertel 4219:
4220: $options =
4221: '<label><input type="radio" name="lastSub" value="none" /> '.&mt('none').' </label>'."\n".
4222: '<label><input type="radio" name="lastSub" value="datesub" checked="checked" /> '.&mt('by dates and submissions').'</label>'."\n".
4223: '<label><input type="radio" name="lastSub" value="all" /> '.&mt('all details').' </label>'."\n";
1.539 riegler 4224: $result.=' <b>'.&mt('Submissions').': </b>'.$options;
1.432 banghart 4225:
4226: $result.=&build_section_inputs();
1.442 banghart 4227: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
4228: $result.='<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.72 ng 4229: '<input type="hidden" name="command" value="displayPage" />'."\n".
1.613 www 4230: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."<br />\n";
1.72 ng 4231:
1.539 riegler 4232: $result.=' <b>'.&mt('Use CODE').': </b> <input type="text" name="CODE" value="" /> <br />'."\n";
1.382 albertel 4233:
1.80 ng 4234: $result.=' <input type="button" '.
1.589 bisitz 4235: 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /><br />'."\n";
1.72 ng 4236:
1.68 ng 4237: $request->print($result);
4238:
1.485 albertel 4239: my $studentTable.=' <b>'.&mt('Select a student you wish to grade and then click on the Next button.').'</b><br />'.
1.484 albertel 4240: &Apache::loncommon::start_data_table().
4241: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 4242: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 4243: '<th>'.&nameUserString('header').'</th>'.
1.485 albertel 4244: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 4245: '<th>'.&nameUserString('header').'</th>'.
4246: &Apache::loncommon::end_data_table_header_row();
1.68 ng 4247:
1.76 ng 4248: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.68 ng 4249: my $ptr = 1;
1.294 albertel 4250: foreach my $student (sort
4251: {
4252: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
4253: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
4254: }
4255: return $a cmp $b;
4256: } (keys(%$fullname))) {
1.68 ng 4257: my ($uname,$udom) = split(/:/,$student);
1.484 albertel 4258: $studentTable.=($ptr%2==1 ? &Apache::loncommon::start_data_table_row()
4259: : '</td>');
1.126 ng 4260: $studentTable.='<td align="right">'.$ptr.' </td>';
1.288 albertel 4261: $studentTable.='<td> <label><input type="radio" name="student" value="'.$student.'" /> '
4262: .&nameUserString(undef,$$fullname{$student},$uname,$udom)."</label>\n";
1.484 albertel 4263: $studentTable.=
4264: ($ptr%2 == 0 ? '</td>'.&Apache::loncommon::end_data_table_row()
4265: : '');
1.68 ng 4266: $ptr++;
4267: }
1.484 albertel 4268: if ($ptr%2 == 0) {
4269: $studentTable.='</td><td> </td><td> </td>'.
4270: &Apache::loncommon::end_data_table_row();
4271: }
4272: $studentTable.=&Apache::loncommon::end_data_table()."\n";
1.126 ng 4273: $studentTable.='<input type="button" '.
1.589 bisitz 4274: 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /></form>'."\n";
1.68 ng 4275:
4276: $request->print($studentTable);
4277:
4278: return '';
4279: }
4280:
4281: sub getSymbMap {
1.582 raeburn 4282: my ($map_error) = @_;
1.132 bowersj2 4283: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 4284: unless (ref($navmap)) {
4285: if (ref($map_error)) {
4286: $$map_error = 'navmap';
4287: }
4288: return;
4289: }
1.68 ng 4290: my %symbx = ();
4291: my @titles = ();
1.117 bowersj2 4292: my $minder = 0;
4293:
4294: # Gather every sequence that has problems.
1.240 albertel 4295: my @sequences = $navmap->retrieveResources(undef, sub { shift->is_map(); },
4296: 1,0,1);
1.117 bowersj2 4297: for my $sequence ($navmap->getById('0.0'), @sequences) {
1.241 albertel 4298: if ($navmap->hasResource($sequence, sub { shift->is_problem(); }, 0) ) {
1.381 albertel 4299: my $title = $minder.'.'.
4300: &HTML::Entities::encode($sequence->compTitle(),'"\'&');
4301: push(@titles, $title); # minder in case two titles are identical
4302: $symbx{$title} = &HTML::Entities::encode($sequence->symb(),'"\'&');
1.117 bowersj2 4303: $minder++;
1.241 albertel 4304: }
1.68 ng 4305: }
4306: return \@titles,\%symbx;
4307: }
4308:
1.72 ng 4309: #
4310: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68 ng 4311: sub displayPage {
1.608 www 4312: my ($request,$symb) = @_;
1.257 albertel 4313: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4314: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4315: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
4316: my $pageTitle = $env{'form.page'};
1.103 albertel 4317: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 4318: my ($uname,$udom) = split(/:/,$env{'form.student'});
4319: my $usec=$classlist->{$env{'form.student'}}[5];
1.168 albertel 4320:
4321: #need to make sure we have the correct data for later EXT calls,
4322: #thus invalidate the cache
4323: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 4324: $env{'course.'.$env{'request.course.id'}.'.num'},
4325: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 4326: &Apache::lonnet::clear_EXT_cache_status();
4327:
1.103 albertel 4328: if (!&canview($usec)) {
1.485 albertel 4329: $request->print('<span class="LC_warning">'.&mt('Unable to view requested student. ([_1])',$env{'form.student'}).'</span>');
1.103 albertel 4330: return;
4331: }
1.398 albertel 4332: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.485 albertel 4333: $result.='<h3> '.&mt('Student: [_1]',&nameUserString(undef,$$fullname{$env{'form.student'}},$uname,$udom)).
1.129 ng 4334: '</h3>'."\n";
1.500 albertel 4335: $env{'form.CODE'} = uc($env{'form.CODE'});
1.501 foxr 4336: if (&Apache::lonnet::validCODE(uc($env{'form.CODE'}))) {
1.485 albertel 4337: $result.='<h3> '.&mt('CODE: [_1]',$env{'form.CODE'}).'</h3>'."\n";
1.382 albertel 4338: } else {
4339: delete($env{'form.CODE'});
4340: }
1.71 ng 4341: &sub_page_js($request);
4342: $request->print($result);
4343:
1.132 bowersj2 4344: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 4345: unless (ref($navmap)) {
4346: $request->print(&navmap_errormsg());
4347: return;
4348: }
1.257 albertel 4349: my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($env{'form.page'});
1.68 ng 4350: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 4351: if (!$map) {
1.485 albertel 4352: $request->print('<span class="LC_warning">'.&mt('Unable to view requested sequence. ([_1])',$resUrl).'</span>');
1.288 albertel 4353: return;
4354: }
1.68 ng 4355: my $iterator = $navmap->getIterator($map->map_start(),
4356: $map->map_finish());
4357:
1.71 ng 4358: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72 ng 4359: '<input type="hidden" name="command" value="gradeByPage" />'."\n".
1.257 albertel 4360: '<input type="hidden" name="fullname" value="'.$$fullname{$env{'form.student'}}.'" />'."\n".
4361: '<input type="hidden" name="student" value="'.$env{'form.student'}.'" />'."\n".
1.72 ng 4362: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
1.257 albertel 4363: '<input type="hidden" name="title" value="'.$env{'form.title'}.'" />'."\n".
1.418 albertel 4364: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.613 www 4365: '<input type="hidden" name="overRideScore" value="no" />'."\n";
1.71 ng 4366:
1.382 albertel 4367: if (defined($env{'form.CODE'})) {
4368: $studentTable.=
4369: '<input type="hidden" name="CODE" value="'.$env{'form.CODE'}.'" />'."\n";
4370: }
1.381 albertel 4371: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 4372: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 4373:
1.594 bisitz 4374: $studentTable.=' <span class="LC_info">'.
4375: &mt('Problems graded correct by the computer are marked with a [_1] symbol.',$checkIcon).
4376: '</span>'."\n".
1.484 albertel 4377: &Apache::loncommon::start_data_table().
4378: &Apache::loncommon::start_data_table_header_row().
4379: '<th align="center"> Prob. </th>'.
1.485 albertel 4380: '<th> '.($env{'form.vProb'} eq 'no' ? &mt('Title') : &mt('Problem Text')).'/'.&mt('Grade').'</th>'.
1.484 albertel 4381: &Apache::loncommon::end_data_table_header_row();
1.71 ng 4382:
1.329 albertel 4383: &Apache::lonxml::clear_problem_counter();
1.196 albertel 4384: my ($depth,$question,$prob) = (1,1,1);
1.68 ng 4385: $iterator->next(); # skip the first BEGIN_MAP
4386: my $curRes = $iterator->next(); # for "current resource"
1.101 albertel 4387: while ($depth > 0) {
1.68 ng 4388: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4389: if($curRes == $iterator->END_MAP) { $depth--; }
1.68 ng 4390:
1.385 albertel 4391: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4392: my $parts = $curRes->parts();
1.68 ng 4393: my $title = $curRes->compTitle();
1.71 ng 4394: my $symbx = $curRes->symb();
1.484 albertel 4395: $studentTable.=
4396: &Apache::loncommon::start_data_table_row().
4397: '<td align="center" valign="top" >'.$prob.
1.485 albertel 4398: (scalar(@{$parts}) == 1 ? ''
4399: : '<br />('.&mt('[_1] parts)',
4400: scalar(@{$parts}))
4401: ).
4402: '</td>';
1.71 ng 4403: $studentTable.='<td valign="top">';
1.382 albertel 4404: my %form = ('CODE' => $env{'form.CODE'},);
1.257 albertel 4405: if ($env{'form.vProb'} eq 'yes' ) {
1.144 albertel 4406: $studentTable.=&show_problem($request,$symbx,$uname,$udom,1,
1.383 albertel 4407: undef,'both',\%form);
1.71 ng 4408: } else {
1.382 albertel 4409: my $companswer = &Apache::loncommon::get_student_answers($symbx,$uname,$udom,$env{'request.course.id'},%form);
1.80 ng 4410: $companswer =~ s|<form(.*?)>||g;
4411: $companswer =~ s|</form>||g;
1.71 ng 4412: # while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
1.116 ng 4413: # $companswer =~ s/$1/ /ms;
1.326 albertel 4414: # $request->print('match='.$1."<br />\n");
1.71 ng 4415: # }
1.116 ng 4416: # $companswer =~ s|<table border=\"1\">|<table border=\"0\">|g;
1.539 riegler 4417: $studentTable.=' <b>'.$title.'</b> <br /> <b>'.&mt('Correct answer').':</b><br />'.$companswer;
1.71 ng 4418: }
4419:
1.257 albertel 4420: my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
1.125 ng 4421:
1.257 albertel 4422: if ($env{'form.lastSub'} eq 'datesub') {
1.71 ng 4423: if ($record{'version'} eq '') {
1.485 albertel 4424: $studentTable.='<br /> <span class="LC_warning">'.&mt('No recorded submission for this problem.').'</span><br />';
1.71 ng 4425: } else {
1.116 ng 4426: my %responseType = ();
4427: foreach my $partid (@{$parts}) {
1.147 albertel 4428: my @responseIds =$curRes->responseIds($partid);
4429: my @responseType =$curRes->responseType($partid);
4430: my %responseIds;
4431: for (my $i=0;$i<=$#responseIds;$i++) {
4432: $responseIds{$responseIds[$i]}=$responseType[$i];
4433: }
4434: $responseType{$partid} = \%responseIds;
1.116 ng 4435: }
1.148 albertel 4436: $studentTable.= &displaySubByDates($symbx,\%record,$parts,\%responseType,$checkIcon,$uname,$udom);
1.147 albertel 4437:
1.71 ng 4438: }
1.257 albertel 4439: } elsif ($env{'form.lastSub'} eq 'all') {
4440: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.71 ng 4441: $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
1.257 albertel 4442: $env{'request.course.id'},
1.71 ng 4443: '','.submission');
4444:
4445: }
1.103 albertel 4446: if (&canmodify($usec)) {
1.585 bisitz 4447: $studentTable.=&gradeBox_start();
1.103 albertel 4448: foreach my $partid (@{$parts}) {
4449: $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
4450: $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
4451: $question++;
4452: }
1.585 bisitz 4453: $studentTable.=&gradeBox_end();
1.196 albertel 4454: $prob++;
1.71 ng 4455: }
4456: $studentTable.='</td></tr>';
1.68 ng 4457:
1.103 albertel 4458: }
1.68 ng 4459: $curRes = $iterator->next();
4460: }
4461:
1.589 bisitz 4462: $studentTable.=
4463: '</table>'."\n".
4464: '<input type="button" value="'.&mt('Save').'" '.
4465: 'onclick="javascript:checkSubmitPage(this.form,'.$question.');" />'.
4466: '</form>'."\n";
1.71 ng 4467: $request->print($studentTable);
4468:
4469: return '';
1.119 ng 4470: }
4471:
4472: sub displaySubByDates {
1.148 albertel 4473: my ($symb,$record,$parts,$responseType,$checkIcon,$uname,$udom) = @_;
1.224 albertel 4474: my $isCODE=0;
1.335 albertel 4475: my $isTask = ($symb =~/\.task$/);
1.224 albertel 4476: if (exists($record->{'resource.CODE'})) { $isCODE=1; }
1.467 albertel 4477: my $studentTable=&Apache::loncommon::start_data_table().
4478: &Apache::loncommon::start_data_table_header_row().
4479: '<th>'.&mt('Date/Time').'</th>'.
4480: ($isCODE?'<th>'.&mt('CODE').'</th>':'').
4481: '<th>'.&mt('Submission').'</th>'.
4482: '<th>'.&mt('Status').'</th>'.
4483: &Apache::loncommon::end_data_table_header_row();
1.119 ng 4484: my ($version);
4485: my %mark;
1.148 albertel 4486: my %orders;
1.119 ng 4487: $mark{'correct_by_student'} = $checkIcon;
1.147 albertel 4488: if (!exists($$record{'1:timestamp'})) {
1.539 riegler 4489: return '<br /> <span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br />';
1.147 albertel 4490: }
1.335 albertel 4491:
4492: my $interaction;
1.525 raeburn 4493: my $no_increment = 1;
1.119 ng 4494: for ($version=1;$version<=$$record{'version'};$version++) {
1.467 albertel 4495: my $timestamp =
4496: &Apache::lonlocal::locallocaltime($$record{$version.':timestamp'});
1.335 albertel 4497: if (exists($$record{$version.':resource.0.version'})) {
4498: $interaction = $$record{$version.':resource.0.version'};
4499: }
4500:
4501: my $where = ($isTask ? "$version:resource.$interaction"
4502: : "$version:resource");
1.467 albertel 4503: $studentTable.=&Apache::loncommon::start_data_table_row().
4504: '<td>'.$timestamp.'</td>';
1.224 albertel 4505: if ($isCODE) {
4506: $studentTable.='<td>'.$record->{$version.':resource.CODE'}.'</td>';
4507: }
1.119 ng 4508: my @versionKeys = split(/\:/,$$record{$version.':keys'});
4509: my @displaySub = ();
4510: foreach my $partid (@{$parts}) {
1.596 raeburn 4511: my $hidden;
4512: if (($$record{$version.':resource.'.$partid.'.type'} eq 'anonsurvey') ||
4513: ($$record{$version.':resource.'.$partid.'.type'} eq 'anonsurveycred')) {
4514: $hidden = 1;
4515: }
1.335 albertel 4516: my @matchKey = ($isTask ? sort(grep /^resource\.\d+\.\Q$partid\E\.award$/,@versionKeys)
4517: : sort(grep /^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys));
4518:
1.122 ng 4519: # next if ($$record{"$version:resource.$partid.solved"} eq '');
1.324 albertel 4520: my $display_part=&get_display_part($partid,$symb);
1.147 albertel 4521: foreach my $matchKey (@matchKey) {
1.198 albertel 4522: if (exists($$record{$version.':'.$matchKey}) &&
4523: $$record{$version.':'.$matchKey} ne '') {
1.596 raeburn 4524:
1.335 albertel 4525: my ($responseId)= ($isTask ? ($matchKey=~ /^resource\.(.*?)\.\Q$partid\E\.award$/)
4526: : ($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/));
1.577 bisitz 4527: $displaySub[0].='<span class="LC_nobreak"';
4528: $displaySub[0].='<b>'.&mt('Part: [_1]',$display_part).'</b>'
4529: .' <span class="LC_internal_info">'
4530: .'('.&mt('Part ID: [_1]',$responseId).')'
4531: .'</span>'
4532: .' <b>';
1.596 raeburn 4533: if ($hidden) {
4534: $displaySub[0].= &mt('Anonymous Survey').'</b>';
4535: } else {
4536: if ($$record{"$where.$partid.tries"} eq '') {
4537: $displaySub[0].=&mt('Trial not counted');
4538: } else {
4539: $displaySub[0].=&mt('Trial: [_1]',
1.467 albertel 4540: $$record{"$where.$partid.tries"});
1.596 raeburn 4541: }
4542: my $responseType=($isTask ? 'Task'
1.335 albertel 4543: : $responseType->{$partid}->{$responseId});
1.596 raeburn 4544: if (!exists($orders{$partid})) { $orders{$partid}={}; }
4545: if (!exists($orders{$partid}->{$responseId})) {
4546: $orders{$partid}->{$responseId}=
4547: &get_order($partid,$responseId,$symb,$uname,$udom,
4548: $no_increment);
4549: }
4550: $displaySub[0].='</b></span>'; # /nobreak
4551: $displaySub[0].=' '.
4552: &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:",$uname,$udom).'<br />';
4553: }
1.147 albertel 4554: }
4555: }
1.335 albertel 4556: if (exists($$record{"$where.$partid.checkedin"})) {
1.485 albertel 4557: $displaySub[1].=&mt('Checked in by [_1] into slot [_2]',
4558: $$record{"$where.$partid.checkedin"},
4559: $$record{"$where.$partid.checkedin.slot"}).
4560: '<br />';
1.335 albertel 4561: }
4562: if (exists $$record{"$where.$partid.award"}) {
1.485 albertel 4563: $displaySub[1].='<b>'.&mt('Part:').'</b> '.$display_part.' '.
1.335 albertel 4564: lc($$record{"$where.$partid.award"}).' '.
4565: $mark{$$record{"$where.$partid.solved"}}.
1.147 albertel 4566: '<br />';
4567: }
1.335 albertel 4568: if (exists $$record{"$where.$partid.regrader"}) {
4569: $displaySub[2].=$$record{"$where.$partid.regrader"}.
4570: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
4571: } elsif ($$record{"$version:resource.$partid.regrader"} =~ /\S/) {
4572: $displaySub[2].=
4573: $$record{"$version:resource.$partid.regrader"}.
1.207 albertel 4574: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
1.147 albertel 4575: }
4576: }
4577: # needed because old essay regrader has not parts info
4578: if (exists $$record{"$version:resource.regrader"}) {
4579: $displaySub[2].=$$record{"$version:resource.regrader"};
4580: }
4581: $studentTable.='<td>'.$displaySub[0].' </td><td>'.$displaySub[1];
4582: if ($displaySub[2]) {
1.467 albertel 4583: $studentTable.=&mt('Manually graded by [_1]',$displaySub[2]);
1.147 albertel 4584: }
1.467 albertel 4585: $studentTable.=' </td>'.
4586: &Apache::loncommon::end_data_table_row();
1.119 ng 4587: }
1.467 albertel 4588: $studentTable.=&Apache::loncommon::end_data_table();
1.119 ng 4589: return $studentTable;
1.71 ng 4590: }
4591:
4592: sub updateGradeByPage {
1.608 www 4593: my ($request,$symb) = @_;
1.71 ng 4594:
1.257 albertel 4595: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4596: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4597: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
4598: my $pageTitle = $env{'form.page'};
1.103 albertel 4599: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 4600: my ($uname,$udom) = split(/:/,$env{'form.student'});
4601: my $usec=$classlist->{$env{'form.student'}}[5];
1.103 albertel 4602: if (!&canmodify($usec)) {
1.526 raeburn 4603: $request->print('<span class="LC_warning">'.&mt('Unable to modify requested student ([_1])',$env{'form.student'}).'</span>');
1.103 albertel 4604: return;
4605: }
1.398 albertel 4606: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.526 raeburn 4607: $result.='<h3> '.&mt('Student: ').&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
1.129 ng 4608: '</h3>'."\n";
1.70 ng 4609:
1.68 ng 4610: $request->print($result);
4611:
1.582 raeburn 4612:
1.132 bowersj2 4613: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 4614: unless (ref($navmap)) {
4615: $request->print(&navmap_errormsg());
4616: return;
4617: }
1.257 albertel 4618: my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $env{'form.page'});
1.71 ng 4619: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 4620: if (!$map) {
1.527 raeburn 4621: $request->print('<span class="LC_warning">'.&mt('Unable to grade requested sequence ([_1]).',$resUrl).'</span>');
1.288 albertel 4622: return;
4623: }
1.71 ng 4624: my $iterator = $navmap->getIterator($map->map_start(),
4625: $map->map_finish());
1.70 ng 4626:
1.484 albertel 4627: my $studentTable=
4628: &Apache::loncommon::start_data_table().
4629: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 4630: '<th align="center"> '.&mt('Prob.').' </th>'.
4631: '<th> '.&mt('Title').' </th>'.
4632: '<th> '.&mt('Previous Score').' </th>'.
4633: '<th> '.&mt('New Score').' </th>'.
1.484 albertel 4634: &Apache::loncommon::end_data_table_header_row();
1.71 ng 4635:
4636: $iterator->next(); # skip the first BEGIN_MAP
4637: my $curRes = $iterator->next(); # for "current resource"
1.196 albertel 4638: my ($depth,$question,$prob,$changeflag)= (1,1,1,0);
1.101 albertel 4639: while ($depth > 0) {
1.71 ng 4640: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4641: if($curRes == $iterator->END_MAP) { $depth--; }
1.71 ng 4642:
1.385 albertel 4643: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4644: my $parts = $curRes->parts();
1.71 ng 4645: my $title = $curRes->compTitle();
4646: my $symbx = $curRes->symb();
1.484 albertel 4647: $studentTable.=
4648: &Apache::loncommon::start_data_table_row().
4649: '<td align="center" valign="top" >'.$prob.
1.485 albertel 4650: (scalar(@{$parts}) == 1 ? ''
1.526 raeburn 4651: : '<br />('.&mt('[quant,_1, part]',scalar(@{$parts}))
4652: .')').'</td>';
1.71 ng 4653: $studentTable.='<td valign="top"> <b>'.$title.'</b> </td>';
4654:
4655: my %newrecord=();
4656: my @displayPts=();
1.269 raeburn 4657: my %aggregate = ();
4658: my $aggregateflag = 0;
1.71 ng 4659: foreach my $partid (@{$parts}) {
1.257 albertel 4660: my $newpts = $env{'form.GD_BOX'.$question.'_'.$partid};
4661: my $oldpts = $env{'form.oldpts'.$question.'_'.$partid};
1.71 ng 4662:
1.257 albertel 4663: my $wgt = $env{'form.WGT'.$question.'_'.$partid} != 0 ?
4664: $env{'form.WGT'.$question.'_'.$partid} : 1;
1.71 ng 4665: my $partial = $newpts/$wgt;
4666: my $score;
4667: if ($partial > 0) {
4668: $score = 'correct_by_override';
1.125 ng 4669: } elsif ($newpts ne '') { #empty is taken as 0
1.71 ng 4670: $score = 'incorrect_by_override';
4671: }
1.257 albertel 4672: my $dropMenu = $env{'form.GD_SEL'.$question.'_'.$partid};
1.125 ng 4673: if ($dropMenu eq 'excused') {
1.71 ng 4674: $partial = '';
4675: $score = 'excused';
1.125 ng 4676: } elsif ($dropMenu eq 'reset status'
1.257 albertel 4677: && $env{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
1.125 ng 4678: $newrecord{'resource.'.$partid.'.tries'} = 0;
4679: $newrecord{'resource.'.$partid.'.solved'} = '';
4680: $newrecord{'resource.'.$partid.'.award'} = '';
4681: $newrecord{'resource.'.$partid.'.awarded'} = 0;
1.257 albertel 4682: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 4683: $changeflag++;
4684: $newpts = '';
1.269 raeburn 4685:
4686: my $aggtries = $env{'form.aggtries'.$question.'_'.$partid};
4687: my $totaltries = $env{'form.totaltries'.$question.'_'.$partid};
4688: my $solvedstatus = $env{'form.solved'.$question.'_'.$partid};
4689: if ($aggtries > 0) {
4690: &decrement_aggs($symbx,$partid,\%aggregate,$aggtries,$totaltries,$solvedstatus);
4691: $aggregateflag = 1;
4692: }
1.71 ng 4693: }
1.324 albertel 4694: my $display_part=&get_display_part($partid,$curRes->symb());
1.257 albertel 4695: my $oldstatus = $env{'form.solved'.$question.'_'.$partid};
1.526 raeburn 4696: $displayPts[0].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.71 ng 4697: (($oldstatus eq 'excused') ? 'excused' : $oldpts).
1.326 albertel 4698: ' <br />';
1.526 raeburn 4699: $displayPts[1].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.125 ng 4700: (($score eq 'excused') ? 'excused' : $newpts).
1.326 albertel 4701: ' <br />';
1.71 ng 4702: $question++;
1.380 albertel 4703: next if ($dropMenu eq 'reset status' || ($newpts eq $oldpts && $score ne 'excused'));
1.125 ng 4704:
1.71 ng 4705: $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
1.125 ng 4706: $newrecord{'resource.'.$partid.'.solved'} = $score if $score ne '';
1.257 albertel 4707: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}"
1.125 ng 4708: if (scalar(keys(%newrecord)) > 0);
1.71 ng 4709:
4710: $changeflag++;
4711: }
4712: if (scalar(keys(%newrecord)) > 0) {
1.382 albertel 4713: my %record =
4714: &Apache::lonnet::restore($symbx,$env{'request.course.id'},
4715: $udom,$uname);
4716:
4717: if (&Apache::lonnet::validCODE($env{'form.CODE'})) {
4718: $newrecord{'resource.CODE'} = $env{'form.CODE'};
4719: } elsif (&Apache::lonnet::validCODE($record{'resource.CODE'})) {
4720: $newrecord{'resource.CODE'} = '';
4721: }
1.257 albertel 4722: &Apache::lonnet::cstore(\%newrecord,$symbx,$env{'request.course.id'},
1.71 ng 4723: $udom,$uname);
1.382 albertel 4724: %record = &Apache::lonnet::restore($symbx,
4725: $env{'request.course.id'},
4726: $udom,$uname);
1.380 albertel 4727: &check_and_remove_from_queue($parts,\%record,undef,$symbx,
4728: $cdom,$cnum,$udom,$uname);
1.71 ng 4729: }
1.380 albertel 4730:
1.269 raeburn 4731: if ($aggregateflag) {
4732: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
4733: $env{'course.'.$env{'request.course.id'}.'.domain'},
4734: $env{'course.'.$env{'request.course.id'}.'.num'});
4735: }
1.125 ng 4736:
1.71 ng 4737: $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
4738: '<td valign="top">'.$displayPts[1].'</td>'.
1.484 albertel 4739: &Apache::loncommon::end_data_table_row();
1.68 ng 4740:
1.196 albertel 4741: $prob++;
1.68 ng 4742: }
1.71 ng 4743: $curRes = $iterator->next();
1.68 ng 4744: }
1.98 albertel 4745:
1.484 albertel 4746: $studentTable.=&Apache::loncommon::end_data_table();
1.526 raeburn 4747: my $grademsg=($changeflag == 0 ? &mt('No score was changed or updated.') :
4748: &mt('The scores were changed for [quant,_1,problem].',
4749: $changeflag));
1.76 ng 4750: $request->print($grademsg.$studentTable);
1.68 ng 4751:
1.70 ng 4752: return '';
4753: }
4754:
1.72 ng 4755: #-------- end of section for handling grading by page/sequence ---------
4756: #
4757: #-------------------------------------------------------------------
4758:
1.581 www 4759: #-------------------- Bubblesheet (Scantron) Grading -------------------
1.75 albertel 4760: #
4761: #------ start of section for handling grading by page/sequence ---------
4762:
1.423 albertel 4763: =pod
4764:
4765: =head1 Bubble sheet grading routines
4766:
1.424 albertel 4767: For this documentation:
4768:
4769: 'scanline' refers to the full line of characters
4770: from the file that we are parsing that represents one entire sheet
4771:
4772: 'bubble line' refers to the data
4773: representing the line of bubbles that are on the physical bubble sheet
4774:
4775:
4776: The overall process is that a scanned in bubble sheet data is uploaded
4777: into a course. When a user wants to grade, they select a
4778: sequence/folder of resources, a file of bubble sheet info, and pick
4779: one of the predefined configurations for what each scanline looks
4780: like.
4781:
4782: Next each scanline is checked for any errors of either 'missing
1.435 foxr 4783: bubbles' (it's an error because it may have been mis-scanned
1.424 albertel 4784: because too light bubbling), 'double bubble' (each bubble line should
4785: have no more that one letter picked), invalid or duplicated CODE,
1.556 weissno 4786: invalid student/employee ID
1.424 albertel 4787:
4788: If the CODE option is used that determines the randomization of the
1.556 weissno 4789: homework problems, either way the student/employee ID is looked up into a
1.424 albertel 4790: username:domain.
4791:
4792: During the validation phase the instructor can choose to skip scanlines.
4793:
1.435 foxr 4794: After the validation phase, there are now 3 bubble sheet files
1.424 albertel 4795:
4796: scantron_original_filename (unmodified original file)
4797: scantron_corrected_filename (file where the corrected information has replaced the original information)
4798: scantron_skipped_filename (contains the exact text of scanlines that where skipped)
4799:
4800: Also there is a separate hash nohist_scantrondata that contains extra
4801: correction information that isn't representable in the bubble sheet
4802: file (see &scantron_getfile() for more information)
4803:
4804: After all scanlines are either valid, marked as valid or skipped, then
4805: foreach line foreach problem in the picked sequence, an ssi request is
4806: made that simulates a user submitting their selected letter(s) against
4807: the homework problem.
1.423 albertel 4808:
4809: =over 4
4810:
4811:
4812:
4813: =item defaultFormData
4814:
4815: Returns html hidden inputs used to hold context/default values.
4816:
4817: Arguments:
4818: $symb - $symb of the current resource
4819:
4820: =cut
1.422 foxr 4821:
1.81 albertel 4822: sub defaultFormData {
1.324 albertel 4823: my ($symb)=@_;
1.613 www 4824: return '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />';
1.81 albertel 4825: }
4826:
1.447 foxr 4827:
1.423 albertel 4828: =pod
4829:
4830: =item getSequenceDropDown
4831:
4832: Return html dropdown of possible sequences to grade
4833:
4834: Arguments:
1.582 raeburn 4835: $symb - $symb of the current resource
4836: $map_error - ref to scalar which will container error if
4837: $navmap object is unavailable in &getSymbMap().
1.423 albertel 4838:
4839: =cut
1.422 foxr 4840:
1.75 albertel 4841: sub getSequenceDropDown {
1.582 raeburn 4842: my ($symb,$map_error)=@_;
1.75 albertel 4843: my $result='<select name="selectpage">'."\n";
1.582 raeburn 4844: my ($titles,$symbx) = &getSymbMap($map_error);
4845: if (ref($map_error)) {
4846: return if ($$map_error);
4847: }
1.137 albertel 4848: my ($curpage)=&Apache::lonnet::decode_symb($symb);
1.75 albertel 4849: my $ctr=0;
4850: foreach (@$titles) {
4851: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
4852: $result.='<option value="'.$$symbx{$_}.'" '.
1.401 albertel 4853: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.75 albertel 4854: '>'.$showtitle.'</option>'."\n";
4855: $ctr++;
4856: }
4857: $result.= '</select>';
4858: return $result;
4859: }
4860:
1.495 albertel 4861: my %bubble_lines_per_response; # no. bubble lines for each response.
1.554 raeburn 4862: # key is zero-based index - 0, 1, 2 ...
1.495 albertel 4863:
4864: my %first_bubble_line; # First bubble line no. for each bubble.
4865:
1.509 raeburn 4866: my %subdivided_bubble_lines; # no. bubble lines for optionresponse,
4867: # matchresponse or rankresponse, where
4868: # an individual response can have multiple
4869: # lines
1.503 raeburn 4870:
4871: my %responsetype_per_response; # responsetype for each response
4872:
1.495 albertel 4873: # Save and restore the bubble lines array to the form env.
4874:
4875:
4876: sub save_bubble_lines {
4877: foreach my $line (keys(%bubble_lines_per_response)) {
4878: $env{"form.scantron.bubblelines.$line"} = $bubble_lines_per_response{$line};
4879: $env{"form.scantron.first_bubble_line.$line"} =
4880: $first_bubble_line{$line};
1.503 raeburn 4881: $env{"form.scantron.sub_bubblelines.$line"} =
4882: $subdivided_bubble_lines{$line};
4883: $env{"form.scantron.responsetype.$line"} =
4884: $responsetype_per_response{$line};
1.495 albertel 4885: }
4886: }
4887:
4888:
4889: sub restore_bubble_lines {
4890: my $line = 0;
4891: %bubble_lines_per_response = ();
4892: while ($env{"form.scantron.bubblelines.$line"}) {
4893: my $value = $env{"form.scantron.bubblelines.$line"};
4894: $bubble_lines_per_response{$line} = $value;
4895: $first_bubble_line{$line} =
4896: $env{"form.scantron.first_bubble_line.$line"};
1.503 raeburn 4897: $subdivided_bubble_lines{$line} =
4898: $env{"form.scantron.sub_bubblelines.$line"};
4899: $responsetype_per_response{$line} =
4900: $env{"form.scantron.responsetype.$line"};
1.495 albertel 4901: $line++;
4902: }
4903: }
4904:
4905: # Given the parsed scanline, get the response for
4906: # 'answer' number n:
4907:
4908: sub get_response_bubbles {
4909: my ($parsed_line, $response) = @_;
4910:
4911: my $bubble_line = $first_bubble_line{$response-1} +1;
4912: my $bubble_lines= $bubble_lines_per_response{$response-1};
4913:
4914: my $selected = "";
4915:
4916: for (my $bline = 0; $bline < $bubble_lines; $bline++) {
4917: $selected .= $$parsed_line{"scantron.$bubble_line.answer"}.":";
4918: $bubble_line++;
4919: }
4920: return $selected;
4921: }
1.423 albertel 4922:
4923: =pod
4924:
4925: =item scantron_filenames
4926:
4927: Returns a list of the scantron files in the current course
4928:
4929: =cut
1.422 foxr 4930:
1.202 albertel 4931: sub scantron_filenames {
1.257 albertel 4932: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4933: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
1.517 raeburn 4934: my $getpropath = 1;
1.157 albertel 4935: my @files=&Apache::lonnet::dirlist('userfiles',$cdom,$cname,
1.517 raeburn 4936: $getpropath);
1.202 albertel 4937: my @possiblenames;
1.201 albertel 4938: foreach my $filename (sort(@files)) {
1.157 albertel 4939: ($filename)=split(/&/,$filename);
4940: if ($filename!~/^scantron_orig_/) { next ; }
4941: $filename=~s/^scantron_orig_//;
1.202 albertel 4942: push(@possiblenames,$filename);
4943: }
4944: return @possiblenames;
4945: }
4946:
1.423 albertel 4947: =pod
4948:
4949: =item scantron_uploads
4950:
4951: Returns html drop-down list of scantron files in current course.
4952:
4953: Arguments:
4954: $file2grade - filename to set as selected in the dropdown
4955:
4956: =cut
1.422 foxr 4957:
1.202 albertel 4958: sub scantron_uploads {
1.209 ng 4959: my ($file2grade) = @_;
1.202 albertel 4960: my $result= '<select name="scantron_selectfile">';
4961: $result.="<option></option>";
4962: foreach my $filename (sort(&scantron_filenames())) {
1.401 albertel 4963: $result.="<option".($filename eq $file2grade ? ' selected="selected"':'').">$filename</option>\n";
1.81 albertel 4964: }
4965: $result.="</select>";
4966: return $result;
4967: }
4968:
1.423 albertel 4969: =pod
4970:
4971: =item scantron_scantab
4972:
4973: Returns html drop down of the scantron formats in the scantronformat.tab
4974: file.
4975:
4976: =cut
1.422 foxr 4977:
1.82 albertel 4978: sub scantron_scantab {
4979: my $result='<select name="scantron_format">'."\n";
1.191 albertel 4980: $result.='<option></option>'."\n";
1.518 raeburn 4981: my @lines = &get_scantronformat_file();
4982: if (@lines > 0) {
4983: foreach my $line (@lines) {
4984: next if (($line =~ /^\#/) || ($line eq ''));
4985: my ($name,$descrip)=split(/:/,$line);
4986: $result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
4987: }
1.82 albertel 4988: }
4989: $result.='</select>'."\n";
1.518 raeburn 4990: return $result;
4991: }
4992:
4993: =pod
4994:
4995: =item get_scantronformat_file
4996:
4997: Returns an array containing lines from the scantron format file for
4998: the domain of the course.
4999:
5000: If a url for a custom.tab file is listed in domain's configuration.db,
5001: lines are from this file.
5002:
5003: Otherwise, if a default.tab has been published in RES space by the
5004: domainconfig user, lines are from this file.
5005:
5006: Otherwise, fall back to getting lines from the legacy file on the
1.519 raeburn 5007: local server: /home/httpd/lonTabs/default_scantronformat.tab
1.82 albertel 5008:
1.518 raeburn 5009: =cut
5010:
5011: sub get_scantronformat_file {
5012: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
5013: my %domconfig = &Apache::lonnet::get_dom('configuration',['scantron'],$cdom);
5014: my $gottab = 0;
5015: my @lines;
5016: if (ref($domconfig{'scantron'}) eq 'HASH') {
5017: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
5018: my $formatfile = &Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.$domconfig{'scantron'}{'scantronformat'});
5019: if ($formatfile ne '-1') {
5020: @lines = split("\n",$formatfile,-1);
5021: $gottab = 1;
5022: }
5023: }
5024: }
5025: if (!$gottab) {
5026: my $confname = $cdom.'-domainconfig';
5027: my $default = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res/'.$cdom.'/'.$confname.'/default.tab';
5028: my $formatfile = &Apache::lonnet::getfile($default);
5029: if ($formatfile ne '-1') {
5030: @lines = split("\n",$formatfile,-1);
5031: $gottab = 1;
5032: }
5033: }
5034: if (!$gottab) {
1.519 raeburn 5035: my @domains = &Apache::lonnet::current_machine_domains();
5036: if (grep(/^\Q$cdom\E$/,@domains)) {
5037: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
5038: @lines = <$fh>;
5039: close($fh);
5040: } else {
5041: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab');
5042: @lines = <$fh>;
5043: close($fh);
5044: }
1.518 raeburn 5045: }
5046: return @lines;
1.82 albertel 5047: }
5048:
1.423 albertel 5049: =pod
5050:
5051: =item scantron_CODElist
5052:
5053: Returns html drop down of the saved CODE lists from current course,
5054: generated from earlier printings.
5055:
5056: =cut
1.422 foxr 5057:
1.186 albertel 5058: sub scantron_CODElist {
1.257 albertel 5059: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5060: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.186 albertel 5061: my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
5062: my $namechoice='<option></option>';
1.225 albertel 5063: foreach my $name (sort {uc($a) cmp uc($b)} @names) {
1.191 albertel 5064: if ($name =~ /^error: 2 /) { next; }
1.278 albertel 5065: if ($name =~ /^type\0/) { next; }
1.186 albertel 5066: $namechoice.='<option value="'.$name.'">'.$name.'</option>';
5067: }
5068: $namechoice='<select name="scantron_CODElist">'.$namechoice.'</select>';
5069: return $namechoice;
5070: }
5071:
1.423 albertel 5072: =pod
5073:
5074: =item scantron_CODEunique
5075:
5076: Returns the html for "Each CODE to be used once" radio.
5077:
5078: =cut
1.422 foxr 5079:
1.186 albertel 5080: sub scantron_CODEunique {
1.532 bisitz 5081: my $result='<span class="LC_nobreak">
1.272 albertel 5082: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 5083: value="yes" checked="checked" />'.&mt('Yes').' </label>
1.381 albertel 5084: </span>
1.532 bisitz 5085: <span class="LC_nobreak">
1.272 albertel 5086: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 5087: value="no" />'.&mt('No').' </label>
1.381 albertel 5088: </span>';
1.186 albertel 5089: return $result;
5090: }
1.423 albertel 5091:
5092: =pod
5093:
5094: =item scantron_selectphase
5095:
5096: Generates the initial screen to start the bubble sheet process.
5097: Allows for - starting a grading run.
1.424 albertel 5098: - downloading existing scan data (original, corrected
1.423 albertel 5099: or skipped info)
5100:
5101: - uploading new scan data
5102:
5103: Arguments:
5104: $r - The Apache request object
5105: $file2grade - name of the file that contain the scanned data to score
5106:
5107: =cut
1.186 albertel 5108:
1.75 albertel 5109: sub scantron_selectphase {
1.608 www 5110: my ($r,$file2grade,$symb) = @_;
1.75 albertel 5111: if (!$symb) {return '';}
1.582 raeburn 5112: my $map_error;
5113: my $sequence_selector=&getSequenceDropDown($symb,\$map_error);
5114: if ($map_error) {
5115: $r->print('<br />'.&navmap_errormsg().'<br />');
5116: return;
5117: }
1.324 albertel 5118: my $default_form_data=&defaultFormData($symb);
1.209 ng 5119: my $file_selector=&scantron_uploads($file2grade);
1.82 albertel 5120: my $format_selector=&scantron_scantab();
1.186 albertel 5121: my $CODE_selector=&scantron_CODElist();
5122: my $CODE_unique=&scantron_CODEunique();
1.75 albertel 5123: my $result;
1.422 foxr 5124:
1.513 foxr 5125: $ssi_error = 0;
5126:
1.606 wenzelju 5127: if (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) ||
5128: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
5129:
5130: # Chunk of form to prompt for a scantron file upload.
5131:
5132: $r->print('
5133: <br />
5134: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5135: '.&Apache::loncommon::start_data_table_header_row().'
5136: <th>
5137: '.&mt('Specify a bubblesheet data file to upload.').'
5138: </th>
5139: '.&Apache::loncommon::end_data_table_header_row().'
5140: '.&Apache::loncommon::start_data_table_row().'
5141: <td>
5142: ');
1.608 www 5143: my $default_form_data=&defaultFormData($symb);
1.606 wenzelju 5144: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
5145: my $cnum= $env{'course.'.$env{'request.course.id'}.'.num'};
5146: $r->print(&Apache::lonhtmlcommon::scripttag('
5147: function checkUpload(formname) {
5148: if (formname.upfile.value == "") {
5149: alert("'.&mt('Please use the browse button to select a file from your local directory.').'");
5150: return false;
5151: }
5152: formname.submit();
5153: }'));
5154: $r->print('
5155: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
5156: '.$default_form_data.'
5157: <input name="courseid" type="hidden" value="'.$cnum.'" />
5158: <input name="domainid" type="hidden" value="'.$cdom.'" />
5159: <input name="command" value="scantronupload_save" type="hidden" />
5160: '.&mt('File to upload: [_1]','<input type="file" name="upfile" size="50" />').'
5161: <br />
5162: <input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
5163: </form>
5164: ');
5165:
5166: $r->print('
5167: </td>
5168: '.&Apache::loncommon::end_data_table_row().'
5169: '.&Apache::loncommon::end_data_table().'
5170: ');
5171: }
5172:
1.422 foxr 5173: # Chunk of form to prompt for a file to grade and how:
5174:
1.489 albertel 5175: $result.= '
5176: <br />
5177: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantron_process">
5178: <input type="hidden" name="command" value="scantron_warning" />
5179: '.$default_form_data.'
5180: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5181: '.&Apache::loncommon::start_data_table_header_row().'
5182: <th colspan="2">
1.492 albertel 5183: '.&mt('Specify file and which Folder/Sequence to grade').'
1.489 albertel 5184: </th>
5185: '.&Apache::loncommon::end_data_table_header_row().'
5186: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5187: <td> '.&mt('Sequence to grade:').' </td><td> '.$sequence_selector.' </td>
1.489 albertel 5188: '.&Apache::loncommon::end_data_table_row().'
5189: '.&Apache::loncommon::start_data_table_row().'
1.572 www 5190: <td> '.&mt('Filename of bubblesheet data file:').' </td><td> '.$file_selector.' </td>
1.489 albertel 5191: '.&Apache::loncommon::end_data_table_row().'
5192: '.&Apache::loncommon::start_data_table_row().'
1.572 www 5193: <td> '.&mt('Format of bubblesheet data file:').' </td><td> '.$format_selector.' </td>
1.489 albertel 5194: '.&Apache::loncommon::end_data_table_row().'
5195: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5196: <td> '.&mt('Saved CODEs to validate against:').' </td><td> '.$CODE_selector.' </td>
1.489 albertel 5197: '.&Apache::loncommon::end_data_table_row().'
5198: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5199: <td> '.&mt('Each CODE is only to be used once:').'</td><td> '.$CODE_unique.' </td>
1.489 albertel 5200: '.&Apache::loncommon::end_data_table_row().'
5201: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5202: <td> '.&mt('Options:').' </td>
1.187 albertel 5203: <td>
1.492 albertel 5204: <label><input type="checkbox" name="scantron_options_redo" value="redo_skipped"/> '.&mt('Do only previously skipped records').'</label> <br />
5205: <label><input type="checkbox" name="scantron_options_ignore" value="ignore_corrections"/> '.&mt('Remove all existing corrections').'</label> <br />
5206: <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources when grading').'</label>
1.187 albertel 5207: </td>
1.489 albertel 5208: '.&Apache::loncommon::end_data_table_row().'
5209: '.&Apache::loncommon::start_data_table_row().'
1.174 albertel 5210: <td colspan="2">
1.572 www 5211: <input type="submit" value="'.&mt('Grading: Validate Bubblesheet Records').'" />
1.162 albertel 5212: </td>
1.489 albertel 5213: '.&Apache::loncommon::end_data_table_row().'
5214: '.&Apache::loncommon::end_data_table().'
5215: </form>
5216: ';
1.162 albertel 5217:
5218: $r->print($result);
5219:
1.422 foxr 5220:
5221:
5222: # Chunk of the form that prompts to view a scoring office file,
5223: # corrected file, skipped records in a file.
5224:
1.489 albertel 5225: $r->print('
5226: <br />
5227: <form action="/adm/grades" name="scantron_download">
5228: '.$default_form_data.'
5229: <input type="hidden" name="command" value="scantron_download" />
5230: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5231: '.&Apache::loncommon::start_data_table_header_row().'
5232: <th>
1.492 albertel 5233: '.&mt('Download a scoring office file').'
1.489 albertel 5234: </th>
5235: '.&Apache::loncommon::end_data_table_header_row().'
5236: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5237: <td> '.&mt('Filename of scoring office file: [_1]',$file_selector).'
1.489 albertel 5238: <br />
1.492 albertel 5239: <input type="submit" value="'.&mt('Download: Show List of Associated Files').'" />
1.489 albertel 5240: '.&Apache::loncommon::end_data_table_row().'
5241: '.&Apache::loncommon::end_data_table().'
5242: </form>
5243: <br />
5244: ');
1.162 albertel 5245:
1.457 banghart 5246: &Apache::lonpickcode::code_list($r,2);
1.523 raeburn 5247:
1.528 raeburn 5248: $r->print('<br /><form method="post" name="checkscantron">'.
1.523 raeburn 5249: $default_form_data."\n".
5250: &Apache::loncommon::start_data_table('LC_scantron_action')."\n".
5251: &Apache::loncommon::start_data_table_header_row()."\n".
5252: '<th colspan="2">
1.572 www 5253: '.&mt('Review bubblesheet data and submissions for a previously graded folder/sequence')."\n".
1.523 raeburn 5254: '</th>'."\n".
5255: &Apache::loncommon::end_data_table_header_row()."\n".
5256: &Apache::loncommon::start_data_table_row()."\n".
5257: '<td> '.&mt('Graded folder/sequence:').' </td>'."\n".
5258: '<td> '.$sequence_selector.' </td>'.
5259: &Apache::loncommon::end_data_table_row()."\n".
5260: &Apache::loncommon::start_data_table_row()."\n".
5261: '<td> '.&mt('Filename of scoring office file:').' </td>'."\n".
5262: '<td> '.$file_selector.' </td>'."\n".
5263: &Apache::loncommon::end_data_table_row()."\n".
5264: &Apache::loncommon::start_data_table_row()."\n".
5265: '<td> '.&mt('Format of data file:').' </td>'."\n".
5266: '<td> '.$format_selector.' </td>'."\n".
5267: &Apache::loncommon::end_data_table_row()."\n".
5268: &Apache::loncommon::start_data_table_row()."\n".
1.557 raeburn 5269: '<td> '.&mt('Options').' </td>'."\n".
5270: '<td> <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources').'</label></td>'.
5271: &Apache::loncommon::end_data_table_row()."\n".
5272: &Apache::loncommon::start_data_table_row()."\n".
1.523 raeburn 5273: '<td colspan="2">'."\n".
5274: '<input type="hidden" name="command" value="checksubmissions" />'."\n".
1.575 www 5275: '<input type="submit" value="'.&mt('Review Bubblesheet Data and Submission Records').'" />'."\n".
1.523 raeburn 5276: '</td>'."\n".
5277: &Apache::loncommon::end_data_table_row()."\n".
5278: &Apache::loncommon::end_data_table()."\n".
5279: '</form><br />');
5280: return;
1.75 albertel 5281: }
5282:
1.423 albertel 5283: =pod
5284:
5285: =item get_scantron_config
5286:
5287: Parse and return the scantron configuration line selected as a
5288: hash of configuration file fields.
5289:
5290: Arguments:
5291: which - the name of the configuration to parse from the file.
5292:
5293:
5294: Returns:
5295: If the named configuration is not in the file, an empty
5296: hash is returned.
5297: a hash with the fields
5298: name - internal name for the this configuration setup
5299: description - text to display to operator that describes this config
5300: CODElocation - if 0 or the string 'none'
5301: - no CODE exists for this config
5302: if -1 || the string 'letter'
5303: - a CODE exists for this config and is
5304: a string of letters
5305: Unsupported value (but planned for future support)
5306: if a positive integer
5307: - The CODE exists as the first n items from
5308: the question section of the form
5309: if the string 'number'
5310: - The CODE exists for this config and is
5311: a string of numbers
5312: CODEstart - (only matter if a CODE exists) column in the line where
5313: the CODE starts
5314: CODElength - length of the CODE
1.573 bisitz 5315: IDstart - column where the student/employee ID starts
1.556 weissno 5316: IDlength - length of the student/employee ID info
1.423 albertel 5317: Qstart - column where the information from the bubbled
5318: 'questions' start
5319: Qlength - number of columns comprising a single bubble line from
5320: the sheet. (usually either 1 or 10)
1.424 albertel 5321: Qon - either a single character representing the character used
1.423 albertel 5322: to signal a bubble was chosen in the positional setup, or
5323: the string 'letter' if the letter of the chosen bubble is
5324: in the final, or 'number' if a number representing the
5325: chosen bubble is in the file (1->A 0->J)
1.424 albertel 5326: Qoff - the character used to represent that a bubble was
5327: left blank
1.423 albertel 5328: PaperID - if the scanning process generates a unique number for each
5329: sheet scanned the column that this ID number starts in
5330: PaperIDlength - number of columns that comprise the unique ID number
5331: for the sheet of paper
1.424 albertel 5332: FirstName - column that the first name starts in
1.423 albertel 5333: FirstNameLength - number of columns that the first name spans
5334:
5335: LastName - column that the last name starts in
5336: LastNameLength - number of columns that the last name spans
5337:
5338: =cut
1.422 foxr 5339:
1.82 albertel 5340: sub get_scantron_config {
5341: my ($which) = @_;
1.518 raeburn 5342: my @lines = &get_scantronformat_file();
1.82 albertel 5343: my %config;
1.157 albertel 5344: #FIXME probably should move to XML it has already gotten a bit much now
1.518 raeburn 5345: foreach my $line (@lines) {
1.82 albertel 5346: my ($name,$descrip)=split(/:/,$line);
5347: if ($name ne $which ) { next; }
5348: chomp($line);
5349: my @config=split(/:/,$line);
5350: $config{'name'}=$config[0];
5351: $config{'description'}=$config[1];
5352: $config{'CODElocation'}=$config[2];
5353: $config{'CODEstart'}=$config[3];
5354: $config{'CODElength'}=$config[4];
5355: $config{'IDstart'}=$config[5];
5356: $config{'IDlength'}=$config[6];
5357: $config{'Qstart'}=$config[7];
1.497 foxr 5358: $config{'Qlength'}=$config[8];
1.82 albertel 5359: $config{'Qoff'}=$config[9];
5360: $config{'Qon'}=$config[10];
1.157 albertel 5361: $config{'PaperID'}=$config[11];
5362: $config{'PaperIDlength'}=$config[12];
5363: $config{'FirstName'}=$config[13];
5364: $config{'FirstNamelength'}=$config[14];
5365: $config{'LastName'}=$config[15];
5366: $config{'LastNamelength'}=$config[16];
1.82 albertel 5367: last;
5368: }
5369: return %config;
5370: }
5371:
1.423 albertel 5372: =pod
5373:
5374: =item username_to_idmap
5375:
1.556 weissno 5376: creates a hash keyed by student/employee ID with values of the corresponding
1.423 albertel 5377: student username:domain.
5378:
5379: Arguments:
5380:
5381: $classlist - reference to the class list hash. This is a hash
5382: keyed by student name:domain whose elements are references
1.424 albertel 5383: to arrays containing various chunks of information
1.423 albertel 5384: about the student. (See loncoursedata for more info).
5385:
5386: Returns
5387: %idmap - the constructed hash
5388:
5389: =cut
5390:
1.82 albertel 5391: sub username_to_idmap {
5392: my ($classlist)= @_;
5393: my %idmap;
5394: foreach my $student (keys(%$classlist)) {
5395: $idmap{$classlist->{$student}->[&Apache::loncoursedata::CL_ID]}=
5396: $student;
5397: }
5398: return %idmap;
5399: }
1.423 albertel 5400:
5401: =pod
5402:
1.424 albertel 5403: =item scantron_fixup_scanline
1.423 albertel 5404:
5405: Process a requested correction to a scanline.
5406:
5407: Arguments:
5408: $scantron_config - hash from &get_scantron_config()
5409: $scan_data - hash of correction information
5410: (see &scantron_getfile())
5411: $line - existing scanline
5412: $whichline - line number of the passed in scanline
5413: $field - type of change to process
5414: (either
1.573 bisitz 5415: 'ID' -> correct the student/employee ID
1.423 albertel 5416: 'CODE' -> correct the CODE
5417: 'answer' -> fixup the submitted answers)
5418:
5419: $args - hash of additional info,
5420: - 'ID'
5421: 'newid' -> studentID to use in replacement
1.424 albertel 5422: of existing one
1.423 albertel 5423: - 'CODE'
5424: 'CODE_ignore_dup' - set to true if duplicates
5425: should be ignored.
5426: 'CODE' - is new code or 'use_unfound'
1.424 albertel 5427: if the existing unfound code should
1.423 albertel 5428: be used as is
5429: - 'answer'
5430: 'response' - new answer or 'none' if blank
5431: 'question' - the bubble line to change
1.503 raeburn 5432: 'questionnum' - the question identifier,
5433: may include subquestion.
1.423 albertel 5434:
5435: Returns:
5436: $line - the modified scanline
5437:
5438: Side effects:
5439: $scan_data - may be updated
5440:
5441: =cut
5442:
1.82 albertel 5443:
1.157 albertel 5444: sub scantron_fixup_scanline {
5445: my ($scantron_config,$scan_data,$line,$whichline,$field,$args)=@_;
5446: if ($field eq 'ID') {
5447: if (length($args->{'newid'}) > $$scantron_config{'IDlength'}) {
1.186 albertel 5448: return ($line,1,'New value too large');
1.157 albertel 5449: }
5450: if (length($args->{'newid'}) < $$scantron_config{'IDlength'}) {
5451: $args->{'newid'}=sprintf('%-'.$$scantron_config{'IDlength'}.'s',
5452: $args->{'newid'});
5453: }
5454: substr($line,$$scantron_config{'IDstart'}-1,
5455: $$scantron_config{'IDlength'})=$args->{'newid'};
5456: if ($args->{'newid'}=~/^\s*$/) {
5457: &scan_data($scan_data,"$whichline.user",
5458: $args->{'username'}.':'.$args->{'domain'});
5459: }
1.186 albertel 5460: } elsif ($field eq 'CODE') {
1.192 albertel 5461: if ($args->{'CODE_ignore_dup'}) {
5462: &scan_data($scan_data,"$whichline.CODE_ignore_dup",'1');
5463: }
5464: &scan_data($scan_data,"$whichline.useCODE",'1');
5465: if ($args->{'CODE'} ne 'use_unfound') {
1.191 albertel 5466: if (length($args->{'CODE'}) > $$scantron_config{'CODElength'}) {
5467: return ($line,1,'New CODE value too large');
5468: }
5469: if (length($args->{'CODE'}) < $$scantron_config{'CODElength'}) {
5470: $args->{'CODE'}=sprintf('%-'.$$scantron_config{'CODElength'}.'s',$args->{'CODE'});
5471: }
5472: substr($line,$$scantron_config{'CODEstart'}-1,
5473: $$scantron_config{'CODElength'})=$args->{'CODE'};
1.186 albertel 5474: }
1.157 albertel 5475: } elsif ($field eq 'answer') {
1.497 foxr 5476: my $length=$scantron_config->{'Qlength'};
1.157 albertel 5477: my $off=$scantron_config->{'Qoff'};
5478: my $on=$scantron_config->{'Qon'};
1.497 foxr 5479: my $answer=${off}x$length;
5480: if ($args->{'response'} eq 'none') {
5481: &scan_data($scan_data,
1.503 raeburn 5482: "$whichline.no_bubble.".$args->{'questionnum'},'1');
1.497 foxr 5483: } else {
5484: if ($on eq 'letter') {
5485: my @alphabet=('A'..'Z');
5486: $answer=$alphabet[$args->{'response'}];
5487: } elsif ($on eq 'number') {
5488: $answer=$args->{'response'}+1;
5489: if ($answer == 10) { $answer = '0'; }
1.274 albertel 5490: } else {
1.497 foxr 5491: substr($answer,$args->{'response'},1)=$on;
1.274 albertel 5492: }
1.497 foxr 5493: &scan_data($scan_data,
1.503 raeburn 5494: "$whichline.no_bubble.".$args->{'questionnum'},undef,'1');
1.157 albertel 5495: }
1.497 foxr 5496: my $where=$length*($args->{'question'}-1)+$scantron_config->{'Qstart'};
5497: substr($line,$where-1,$length)=$answer;
1.157 albertel 5498: }
5499: return $line;
5500: }
1.423 albertel 5501:
5502: =pod
5503:
5504: =item scan_data
5505:
5506: Edit or look up an item in the scan_data hash.
5507:
5508: Arguments:
5509: $scan_data - The hash (see scantron_getfile)
5510: $key - shorthand of the key to edit (actual key is
1.424 albertel 5511: scantronfilename_key).
1.423 albertel 5512: $data - New value of the hash entry.
5513: $delete - If true, the entry is removed from the hash.
5514:
5515: Returns:
5516: The new value of the hash table field (undefined if deleted).
5517:
5518: =cut
5519:
5520:
1.157 albertel 5521: sub scan_data {
5522: my ($scan_data,$key,$value,$delete)=@_;
1.257 albertel 5523: my $filename=$env{'form.scantron_selectfile'};
1.157 albertel 5524: if (defined($value)) {
5525: $scan_data->{$filename.'_'.$key} = $value;
5526: }
5527: if ($delete) { delete($scan_data->{$filename.'_'.$key}); }
5528: return $scan_data->{$filename.'_'.$key};
5529: }
1.423 albertel 5530:
1.495 albertel 5531: # ----- These first few routines are general use routines.----
5532:
5533: # Return the number of occurences of a pattern in a string.
5534:
5535: sub occurence_count {
5536: my ($string, $pattern) = @_;
5537:
5538: my @matches = ($string =~ /$pattern/g);
5539:
5540: return scalar(@matches);
5541: }
5542:
5543:
5544: # Take a string known to have digits and convert all the
5545: # digits into letters in the range J,A..I.
5546:
5547: sub digits_to_letters {
5548: my ($input) = @_;
5549:
5550: my @alphabet = ('J', 'A'..'I');
5551:
5552: my @input = split(//, $input);
5553: my $output ='';
5554: for (my $i = 0; $i < scalar(@input); $i++) {
5555: if ($input[$i] =~ /\d/) {
5556: $output .= $alphabet[$input[$i]];
5557: } else {
5558: $output .= $input[$i];
5559: }
5560: }
5561: return $output;
5562: }
5563:
1.423 albertel 5564: =pod
5565:
5566: =item scantron_parse_scanline
5567:
5568: Decodes a scanline from the selected scantron file
5569:
5570: Arguments:
5571: line - The text of the scantron file line to process
5572: whichline - Line number
5573: scantron_config - Hash describing the format of the scantron lines.
5574: scan_data - Hash of extra information about the scanline
5575: (see scantron_getfile for more information)
5576: just_header - True if should not process question answers but only
5577: the stuff to the left of the answers.
5578: Returns:
5579: Hash containing the result of parsing the scanline
5580:
5581: Keys are all proceeded by the string 'scantron.'
5582:
5583: CODE - the CODE in use for this scanline
5584: useCODE - 1 if the CODE is invalid but it usage has been forced
5585: by the operator
5586: CODE_ignore_dup - 1 if the CODE is a duplicated use when unique
5587: CODEs were selected, but the usage has been
5588: forced by the operator
1.556 weissno 5589: ID - student/employee ID
1.423 albertel 5590: PaperID - if used, the ID number printed on the sheet when the
5591: paper was scanned
5592: FirstName - first name from the sheet
5593: LastName - last name from the sheet
5594:
5595: if just_header was not true these key may also exist
5596:
1.447 foxr 5597: missingerror - a list of bubble ranges that are considered to be answers
5598: to a single question that don't have any bubbles filled in.
5599: Of the form questionnumber:firstbubblenumber:count.
5600: doubleerror - a list of bubble ranges that are considered to be answers
5601: to a single question that have more than one bubble filled in.
5602: Of the form questionnumber::firstbubblenumber:count
5603:
5604: In the above, count is the number of bubble responses in the
5605: input line needed to represent the possible answers to the question.
5606: e.g. a radioresponse with 15 choices in an answer sheet with 10 choices
5607: per line would have count = 2.
5608:
1.423 albertel 5609: maxquest - the number of the last bubble line that was parsed
5610:
5611: (<number> starts at 1)
5612: <number>.answer - zero or more letters representing the selected
5613: letters from the scanline for the bubble line
5614: <number>.
5615: if blank there was either no bubble or there where
5616: multiple bubbles, (consult the keys missingerror and
5617: doubleerror if this is an error condition)
5618:
5619: =cut
5620:
1.82 albertel 5621: sub scantron_parse_scanline {
1.423 albertel 5622: my ($line,$whichline,$scantron_config,$scan_data,$just_header)=@_;
1.470 foxr 5623:
1.82 albertel 5624: my %record;
1.550 raeburn 5625: my $lastpos = $env{'form.scantron_maxbubble'}*$$scantron_config{'Qlength'};
5626: my $questions=substr($line,$$scantron_config{'Qstart'}-1,$lastpos); # Answers
1.422 foxr 5627: my $data=substr($line,0,$$scantron_config{'Qstart'}-1); # earlier stuff
1.278 albertel 5628: if (!($$scantron_config{'CODElocation'} eq 0 ||
5629: $$scantron_config{'CODElocation'} eq 'none')) {
5630: if ($$scantron_config{'CODElocation'} < 0 ||
5631: $$scantron_config{'CODElocation'} eq 'letter' ||
5632: $$scantron_config{'CODElocation'} eq 'number') {
1.191 albertel 5633: $record{'scantron.CODE'}=substr($data,
5634: $$scantron_config{'CODEstart'}-1,
1.83 albertel 5635: $$scantron_config{'CODElength'});
1.191 albertel 5636: if (&scan_data($scan_data,"$whichline.useCODE")) {
5637: $record{'scantron.useCODE'}=1;
5638: }
1.192 albertel 5639: if (&scan_data($scan_data,"$whichline.CODE_ignore_dup")) {
5640: $record{'scantron.CODE_ignore_dup'}=1;
5641: }
1.82 albertel 5642: } else {
5643: #FIXME interpret first N questions
5644: }
5645: }
1.83 albertel 5646: $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
5647: $$scantron_config{'IDlength'});
1.157 albertel 5648: $record{'scantron.PaperID'}=
5649: substr($data,$$scantron_config{'PaperID'}-1,
5650: $$scantron_config{'PaperIDlength'});
5651: $record{'scantron.FirstName'}=
5652: substr($data,$$scantron_config{'FirstName'}-1,
5653: $$scantron_config{'FirstNamelength'});
5654: $record{'scantron.LastName'}=
5655: substr($data,$$scantron_config{'LastName'}-1,
5656: $$scantron_config{'LastNamelength'});
1.423 albertel 5657: if ($just_header) { return \%record; }
1.194 albertel 5658:
1.82 albertel 5659: my @alphabet=('A'..'Z');
5660: my $questnum=0;
1.447 foxr 5661: my $ansnum =1; # Multiple 'answer lines'/question.
5662:
1.470 foxr 5663: chomp($questions); # Get rid of any trailing \n.
5664: $questions =~ s/\r$//; # Get rid of trailing \r too (MAC or Win uploads).
5665: while (length($questions)) {
1.447 foxr 5666: my $answers_needed = $bubble_lines_per_response{$questnum};
1.503 raeburn 5667: my $answer_length = ($$scantron_config{'Qlength'} * $answers_needed)
5668: || 1;
5669: $questnum++;
5670: my $quest_id = $questnum;
5671: my $currentquest = substr($questions,0,$answer_length);
5672: $questions = substr($questions,$answer_length);
5673: if (length($currentquest) < $answer_length) { next; }
5674:
5675: if ($subdivided_bubble_lines{$questnum-1} =~ /,/) {
5676: my $subquestnum = 1;
5677: my $subquestions = $currentquest;
5678: my @subanswers_needed =
5679: split(/,/,$subdivided_bubble_lines{$questnum-1});
5680: foreach my $subans (@subanswers_needed) {
5681: my $subans_length =
5682: ($$scantron_config{'Qlength'} * $subans) || 1;
5683: my $currsubquest = substr($subquestions,0,$subans_length);
5684: $subquestions = substr($subquestions,$subans_length);
5685: $quest_id = "$questnum.$subquestnum";
5686: if (($$scantron_config{'Qon'} eq 'letter') ||
5687: ($$scantron_config{'Qon'} eq 'number')) {
5688: $ansnum = &scantron_validator_lettnum($ansnum,
5689: $questnum,$quest_id,$subans,$currsubquest,$whichline,
5690: \@alphabet,\%record,$scantron_config,$scan_data);
5691: } else {
5692: $ansnum = &scantron_validator_positional($ansnum,
5693: $questnum,$quest_id,$subans,$currsubquest,$whichline, \@alphabet,\%record,$scantron_config,$scan_data);
5694: }
5695: $subquestnum ++;
5696: }
5697: } else {
5698: if (($$scantron_config{'Qon'} eq 'letter') ||
5699: ($$scantron_config{'Qon'} eq 'number')) {
5700: $ansnum = &scantron_validator_lettnum($ansnum,$questnum,
5701: $quest_id,$answers_needed,$currentquest,$whichline,
5702: \@alphabet,\%record,$scantron_config,$scan_data);
5703: } else {
5704: $ansnum = &scantron_validator_positional($ansnum,$questnum,
5705: $quest_id,$answers_needed,$currentquest,$whichline,
5706: \@alphabet,\%record,$scantron_config,$scan_data);
5707: }
5708: }
5709: }
5710: $record{'scantron.maxquest'}=$questnum;
5711: return \%record;
5712: }
1.447 foxr 5713:
1.503 raeburn 5714: sub scantron_validator_lettnum {
5715: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,$whichline,
5716: $alphabet,$record,$scantron_config,$scan_data) = @_;
5717:
5718: # Qon 'letter' implies for each slot in currquest we have:
5719: # ? or * for doubles, a letter in A-Z for a bubble, and
5720: # about anything else (esp. a value of Qoff) for missing
5721: # bubbles.
5722: #
5723: # Qon 'number' implies each slot gives a digit that indexes the
5724: # bubbles filled, or Qoff, or a non-number for unbubbled lines,
5725: # and * or ? for double bubbles on a single line.
5726: #
1.447 foxr 5727:
1.503 raeburn 5728: my $matchon;
5729: if ($$scantron_config{'Qon'} eq 'letter') {
5730: $matchon = '[A-Z]';
5731: } elsif ($$scantron_config{'Qon'} eq 'number') {
5732: $matchon = '\d';
5733: }
5734: my $occurrences = 0;
5735: if (($responsetype_per_response{$questnum-1} eq 'essayresponse') ||
5736: ($responsetype_per_response{$questnum-1} eq 'formularesponse') ||
1.510 raeburn 5737: ($responsetype_per_response{$questnum-1} eq 'stringresponse') ||
5738: ($responsetype_per_response{$questnum-1} eq 'imageresponse') ||
5739: ($responsetype_per_response{$questnum-1} eq 'reactionresponse') ||
5740: ($responsetype_per_response{$questnum-1} eq 'organicresponse')) {
1.503 raeburn 5741: my @singlelines = split('',$currquest);
5742: foreach my $entry (@singlelines) {
5743: $occurrences = &occurence_count($entry,$matchon);
5744: if ($occurrences > 1) {
5745: last;
5746: }
5747: }
5748: } else {
5749: $occurrences = &occurence_count($currquest,$matchon);
5750: }
5751: if (($currquest =~ /\?/ || $currquest =~ /\*/) || ($occurrences > 1)) {
5752: push(@{$record->{'scantron.doubleerror'}},$quest_id);
5753: for (my $ans=0; $ans<$answers_needed; $ans++) {
5754: my $bubble = substr($currquest,$ans,1);
5755: if ($bubble =~ /$matchon/ ) {
5756: if ($$scantron_config{'Qon'} eq 'number') {
5757: if ($bubble == 0) {
5758: $bubble = 10;
5759: }
5760: $record->{"scantron.$ansnum.answer"} =
5761: $alphabet->[$bubble-1];
5762: } else {
5763: $record->{"scantron.$ansnum.answer"} = $bubble;
5764: }
5765: } else {
5766: $record->{"scantron.$ansnum.answer"}='';
5767: }
5768: $ansnum++;
5769: }
5770: } elsif (!defined($currquest)
5771: || (&occurence_count($currquest, $$scantron_config{'Qoff'}) == length($currquest))
5772: || (&occurence_count($currquest,$matchon) == 0)) {
5773: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
5774: $record->{"scantron.$ansnum.answer"}='';
5775: $ansnum++;
5776: }
5777: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
5778: push(@{$record->{'scantron.missingerror'}},$quest_id);
5779: }
5780: } else {
5781: if ($$scantron_config{'Qon'} eq 'number') {
5782: $currquest = &digits_to_letters($currquest);
5783: }
5784: for (my $ans=0; $ans<$answers_needed; $ans++) {
5785: my $bubble = substr($currquest,$ans,1);
5786: $record->{"scantron.$ansnum.answer"} = $bubble;
5787: $ansnum++;
5788: }
5789: }
5790: return $ansnum;
5791: }
1.447 foxr 5792:
1.503 raeburn 5793: sub scantron_validator_positional {
5794: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,
5795: $whichline,$alphabet,$record,$scantron_config,$scan_data) = @_;
1.447 foxr 5796:
1.503 raeburn 5797: # Otherwise there's a positional notation;
5798: # each bubble line requires Qlength items, and there are filled in
5799: # bubbles for each case where there 'Qon' characters.
5800: #
1.447 foxr 5801:
1.503 raeburn 5802: my @array=split($$scantron_config{'Qon'},$currquest,-1);
1.447 foxr 5803:
1.503 raeburn 5804: # If the split only gives us one element.. the full length of the
5805: # answer string, no bubbles are filled in:
1.447 foxr 5806:
1.507 raeburn 5807: if ($answers_needed eq '') {
5808: return;
5809: }
5810:
1.503 raeburn 5811: if (length($array[0]) eq $$scantron_config{'Qlength'}*$answers_needed) {
5812: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
5813: $record->{"scantron.$ansnum.answer"}='';
5814: $ansnum++;
5815: }
5816: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
5817: push(@{$record->{"scantron.missingerror"}},$quest_id);
5818: }
5819: } elsif (scalar(@array) == 2) {
5820: my $location = length($array[0]);
5821: my $line_num = int($location / $$scantron_config{'Qlength'});
5822: my $bubble = $alphabet->[$location % $$scantron_config{'Qlength'}];
5823: for (my $ans=0; $ans<$answers_needed; $ans++) {
5824: if ($ans eq $line_num) {
5825: $record->{"scantron.$ansnum.answer"} = $bubble;
5826: } else {
5827: $record->{"scantron.$ansnum.answer"} = ' ';
5828: }
5829: $ansnum++;
5830: }
5831: } else {
5832: # If there's more than one instance of a bubble character
5833: # That's a double bubble; with positional notation we can
5834: # record all the bubbles filled in as well as the
5835: # fact this response consists of multiple bubbles.
5836: #
5837: if (($responsetype_per_response{$questnum-1} eq 'essayresponse') ||
5838: ($responsetype_per_response{$questnum-1} eq 'formularesponse') ||
1.510 raeburn 5839: ($responsetype_per_response{$questnum-1} eq 'stringresponse') ||
5840: ($responsetype_per_response{$questnum-1} eq 'imageresponse') ||
5841: ($responsetype_per_response{$questnum-1} eq 'reactionresponse') ||
5842: ($responsetype_per_response{$questnum-1} eq 'organicresponse')) {
1.503 raeburn 5843: my $doubleerror = 0;
5844: while (($currquest >= $$scantron_config{'Qlength'}) &&
5845: (!$doubleerror)) {
5846: my $currline = substr($currquest,0,$$scantron_config{'Qlength'});
5847: $currquest = substr($currquest,$$scantron_config{'Qlength'});
5848: my @currarray = split($$scantron_config{'Qon'},$currline,-1);
5849: if (length(@currarray) > 2) {
5850: $doubleerror = 1;
5851: }
5852: }
5853: if ($doubleerror) {
5854: push(@{$record->{'scantron.doubleerror'}},$quest_id);
5855: }
5856: } else {
5857: push(@{$record->{'scantron.doubleerror'}},$quest_id);
5858: }
5859: my $item = $ansnum;
5860: for (my $ans=0; $ans<$answers_needed; $ans++) {
5861: $record->{"scantron.$item.answer"} = '';
5862: $item ++;
5863: }
1.447 foxr 5864:
1.503 raeburn 5865: my @ans=@array;
5866: my $i=0;
5867: my $increment = 0;
5868: while ($#ans) {
5869: $i+=length($ans[0]) + $increment;
5870: my $line = int($i/$$scantron_config{'Qlength'} + $ansnum);
5871: my $bubble = $i%$$scantron_config{'Qlength'};
5872: $record->{"scantron.$line.answer"}.=$alphabet->[$bubble];
5873: shift(@ans);
5874: $increment = 1;
5875: }
5876: $ansnum += $answers_needed;
1.82 albertel 5877: }
1.503 raeburn 5878: return $ansnum;
1.82 albertel 5879: }
5880:
1.423 albertel 5881: =pod
5882:
5883: =item scantron_add_delay
5884:
5885: Adds an error message that occurred during the grading phase to a
5886: queue of messages to be shown after grading pass is complete
5887:
5888: Arguments:
1.424 albertel 5889: $delayqueue - arrary ref of hash ref of error messages
1.423 albertel 5890: $scanline - the scanline that caused the error
5891: $errormesage - the error message
5892: $errorcode - a numeric code for the error
5893:
5894: Side Effects:
1.424 albertel 5895: updates the $delayqueue to have a new hash ref of the error
1.423 albertel 5896:
5897: =cut
5898:
1.82 albertel 5899: sub scantron_add_delay {
1.140 albertel 5900: my ($delayqueue,$scanline,$errormessage,$errorcode)=@_;
5901: push(@$delayqueue,
5902: {'line' => $scanline, 'emsg' => $errormessage,
5903: 'ecode' => $errorcode }
5904: );
1.82 albertel 5905: }
5906:
1.423 albertel 5907: =pod
5908:
5909: =item scantron_find_student
5910:
1.424 albertel 5911: Finds the username for the current scanline
5912:
5913: Arguments:
5914: $scantron_record - hash result from scantron_parse_scanline
5915: $scan_data - hash of correction information
5916: (see &scantron_getfile() form more information)
5917: $idmap - hash from &username_to_idmap()
5918: $line - number of current scanline
5919:
5920: Returns:
5921: Either 'username:domain' or undef if unknown
5922:
1.423 albertel 5923: =cut
5924:
1.82 albertel 5925: sub scantron_find_student {
1.157 albertel 5926: my ($scantron_record,$scan_data,$idmap,$line)=@_;
1.83 albertel 5927: my $scanID=$$scantron_record{'scantron.ID'};
1.157 albertel 5928: if ($scanID =~ /^\s*$/) {
5929: return &scan_data($scan_data,"$line.user");
5930: }
1.83 albertel 5931: foreach my $id (keys(%$idmap)) {
1.157 albertel 5932: if (lc($id) eq lc($scanID)) {
5933: return $$idmap{$id};
5934: }
1.83 albertel 5935: }
5936: return undef;
5937: }
5938:
1.423 albertel 5939: =pod
5940:
5941: =item scantron_filter
5942:
1.424 albertel 5943: Filter sub for lonnavmaps, filters out hidden resources if ignore
5944: hidden resources was selected
5945:
1.423 albertel 5946: =cut
5947:
1.83 albertel 5948: sub scantron_filter {
5949: my ($curres)=@_;
1.331 albertel 5950:
5951: if (ref($curres) && $curres->is_problem()) {
5952: # if the user has asked to not have either hidden
5953: # or 'randomout' controlled resources to be graded
5954: # don't include them
5955: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
5956: && $curres->randomout) {
5957: return 0;
5958: }
1.83 albertel 5959: return 1;
5960: }
5961: return 0;
1.82 albertel 5962: }
5963:
1.423 albertel 5964: =pod
5965:
5966: =item scantron_process_corrections
5967:
1.424 albertel 5968: Gets correction information out of submitted form data and corrects
5969: the scanline
5970:
1.423 albertel 5971: =cut
5972:
1.157 albertel 5973: sub scantron_process_corrections {
5974: my ($r) = @_;
1.257 albertel 5975: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5976: my ($scanlines,$scan_data)=&scantron_getfile();
5977: my $classlist=&Apache::loncoursedata::get_classlist();
1.257 albertel 5978: my $which=$env{'form.scantron_line'};
1.200 albertel 5979: my $line=&scantron_get_line($scanlines,$scan_data,$which);
1.157 albertel 5980: my ($skip,$err,$errmsg);
1.257 albertel 5981: if ($env{'form.scantron_skip_record'}) {
1.157 albertel 5982: $skip=1;
1.257 albertel 5983: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)ID$/) {
5984: my $newstudent=$env{'form.scantron_username'}.':'.
5985: $env{'form.scantron_domain'};
1.157 albertel 5986: my $newid=$classlist->{$newstudent}->[&Apache::loncoursedata::CL_ID];
5987: ($line,$err,$errmsg)=
5988: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
5989: 'ID',{'newid'=>$newid,
1.257 albertel 5990: 'username'=>$env{'form.scantron_username'},
5991: 'domain'=>$env{'form.scantron_domain'}});
5992: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)CODE$/) {
5993: my $resolution=$env{'form.scantron_CODE_resolution'};
1.190 albertel 5994: my $newCODE;
1.192 albertel 5995: my %args;
1.190 albertel 5996: if ($resolution eq 'use_unfound') {
1.191 albertel 5997: $newCODE='use_unfound';
1.190 albertel 5998: } elsif ($resolution eq 'use_found') {
1.257 albertel 5999: $newCODE=$env{'form.scantron_CODE_selectedvalue'};
1.190 albertel 6000: } elsif ($resolution eq 'use_typed') {
1.257 albertel 6001: $newCODE=$env{'form.scantron_CODE_newvalue'};
1.194 albertel 6002: } elsif ($resolution =~ /^use_closest_(\d+)/) {
1.257 albertel 6003: $newCODE=$env{"form.scantron_CODE_closest_$1"};
1.190 albertel 6004: }
1.257 albertel 6005: if ($env{'form.scantron_corrections'} eq 'duplicateCODE') {
1.192 albertel 6006: $args{'CODE_ignore_dup'}=1;
6007: }
6008: $args{'CODE'}=$newCODE;
1.186 albertel 6009: ($line,$err,$errmsg)=
6010: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
1.192 albertel 6011: 'CODE',\%args);
1.257 albertel 6012: } elsif ($env{'form.scantron_corrections'} =~ /^(missing|double)bubble$/) {
6013: foreach my $question (split(',',$env{'form.scantron_questions'})) {
1.157 albertel 6014: ($line,$err,$errmsg)=
6015: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,
6016: $which,'answer',
6017: { 'question'=>$question,
1.503 raeburn 6018: 'response'=>$env{"form.scantron_correct_Q_$question"},
6019: 'questionnum'=>$env{"form.scantron_questionnum_Q_$question"}});
1.157 albertel 6020: if ($err) { last; }
6021: }
6022: }
6023: if ($err) {
1.398 albertel 6024: $r->print("<span class=\"LC_warning\">Unable to accept last correction, an error occurred :$errmsg:</span>");
1.157 albertel 6025: } else {
1.200 albertel 6026: &scantron_put_line($scanlines,$scan_data,$which,$line,$skip);
1.157 albertel 6027: &scantron_putfile($scanlines,$scan_data);
6028: }
6029: }
6030:
1.423 albertel 6031: =pod
6032:
6033: =item reset_skipping_status
6034:
1.424 albertel 6035: Forgets the current set of remember skipped scanlines (and thus
6036: reverts back to considering all lines in the
6037: scantron_skipped_<filename> file)
6038:
1.423 albertel 6039: =cut
6040:
1.200 albertel 6041: sub reset_skipping_status {
6042: my ($scanlines,$scan_data)=&scantron_getfile();
6043: &scan_data($scan_data,'remember_skipping',undef,1);
6044: &scantron_putfile(undef,$scan_data);
6045: }
6046:
1.423 albertel 6047: =pod
6048:
6049: =item start_skipping
6050:
1.424 albertel 6051: Marks a scanline to be skipped.
6052:
1.423 albertel 6053: =cut
6054:
1.376 albertel 6055: sub start_skipping {
1.200 albertel 6056: my ($scan_data,$i)=@_;
6057: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 6058: if ($env{'form.scantron_options_redo'} =~ /^redo_/) {
6059: $remembered{$i}=2;
6060: } else {
6061: $remembered{$i}=1;
6062: }
1.200 albertel 6063: &scan_data($scan_data,'remember_skipping',join(':',%remembered));
6064: }
6065:
1.423 albertel 6066: =pod
6067:
6068: =item should_be_skipped
6069:
1.424 albertel 6070: Checks whether a scanline should be skipped.
6071:
1.423 albertel 6072: =cut
6073:
1.200 albertel 6074: sub should_be_skipped {
1.376 albertel 6075: my ($scanlines,$scan_data,$i)=@_;
1.257 albertel 6076: if ($env{'form.scantron_options_redo'} !~ /^redo_/) {
1.200 albertel 6077: # not redoing old skips
1.376 albertel 6078: if ($scanlines->{'skipped'}[$i]) { return 1; }
1.200 albertel 6079: return 0;
6080: }
6081: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 6082:
6083: if (exists($remembered{$i}) && $remembered{$i} != 2 ) {
6084: return 0;
6085: }
1.200 albertel 6086: return 1;
6087: }
6088:
1.423 albertel 6089: =pod
6090:
6091: =item remember_current_skipped
6092:
1.424 albertel 6093: Discovers what scanlines are in the scantron_skipped_<filename>
6094: file and remembers them into scan_data for later use.
6095:
1.423 albertel 6096: =cut
6097:
1.200 albertel 6098: sub remember_current_skipped {
6099: my ($scanlines,$scan_data)=&scantron_getfile();
6100: my %to_remember;
6101: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
6102: if ($scanlines->{'skipped'}[$i]) {
6103: $to_remember{$i}=1;
6104: }
6105: }
1.376 albertel 6106:
1.200 albertel 6107: &scan_data($scan_data,'remember_skipping',join(':',%to_remember));
6108: &scantron_putfile(undef,$scan_data);
6109: }
6110:
1.423 albertel 6111: =pod
6112:
6113: =item check_for_error
6114:
1.424 albertel 6115: Checks if there was an error when attempting to remove a specific
6116: scantron_.. bubble sheet data file. Prints out an error if
6117: something went wrong.
6118:
1.423 albertel 6119: =cut
6120:
1.200 albertel 6121: sub check_for_error {
6122: my ($r,$result)=@_;
6123: if ($result ne 'ok' && $result ne 'not_found' ) {
1.492 albertel 6124: $r->print(&mt("An error occurred ([_1]) when trying to remove the existing corrections.",$result));
1.200 albertel 6125: }
6126: }
1.157 albertel 6127:
1.423 albertel 6128: =pod
6129:
6130: =item scantron_warning_screen
6131:
1.424 albertel 6132: Interstitial screen to make sure the operator has selected the
6133: correct options before we start the validation phase.
6134:
1.423 albertel 6135: =cut
6136:
1.203 albertel 6137: sub scantron_warning_screen {
6138: my ($button_text)=@_;
1.257 albertel 6139: my $title=&Apache::lonnet::gettitle($env{'form.selectpage'});
1.284 albertel 6140: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.373 albertel 6141: my $CODElist;
1.284 albertel 6142: if ($scantron_config{'CODElocation'} &&
6143: $scantron_config{'CODEstart'} &&
6144: $scantron_config{'CODElength'}) {
6145: $CODElist=$env{'form.scantron_CODElist'};
1.398 albertel 6146: if ($env{'form.scantron_CODElist'} eq '') { $CODElist='<span class="LC_warning">None</span>'; }
1.284 albertel 6147: $CODElist=
1.492 albertel 6148: '<tr><td><b>'.&mt('List of CODES to validate against:').'</b></td><td><tt>'.
1.373 albertel 6149: $env{'form.scantron_CODElist'}.'</tt></td></tr>';
1.284 albertel 6150: }
1.492 albertel 6151: return ('
1.203 albertel 6152: <p>
1.492 albertel 6153: <span class="LC_warning">
6154: '.&mt('Please double check the information below before clicking on \'[_1]\'',&mt($button_text)).'</span>
1.203 albertel 6155: </p>
6156: <table>
1.492 albertel 6157: <tr><td><b>'.&mt('Sequence to be Graded:').'</b></td><td>'.$title.'</td></tr>
6158: <tr><td><b>'.&mt('Data File that will be used:').'</b></td><td><tt>'.$env{'form.scantron_selectfile'}.'</tt></td></tr>
6159: '.$CODElist.'
1.203 albertel 6160: </table>
6161: <br />
1.492 albertel 6162: <p> '.&mt('If this information is correct, please click on \'[_1]\'.',&mt($button_text)).'</p>
6163: <p> '.&mt('If something is incorrect, please click the \'Grading Menu\' button to start over.').'</p>
1.203 albertel 6164:
6165: <br />
1.492 albertel 6166: ');
1.203 albertel 6167: }
6168:
1.423 albertel 6169: =pod
6170:
6171: =item scantron_do_warning
6172:
1.424 albertel 6173: Check if the operator has picked something for all required
6174: fields. Error out if something is missing.
6175:
1.423 albertel 6176: =cut
6177:
1.203 albertel 6178: sub scantron_do_warning {
1.608 www 6179: my ($r,$symb)=@_;
1.203 albertel 6180: if (!$symb) {return '';}
1.324 albertel 6181: my $default_form_data=&defaultFormData($symb);
1.203 albertel 6182: $r->print(&scantron_form_start().$default_form_data);
1.257 albertel 6183: if ( $env{'form.selectpage'} eq '' ||
6184: $env{'form.scantron_selectfile'} eq '' ||
6185: $env{'form.scantron_format'} eq '' ) {
1.492 albertel 6186: $r->print("<p>".&mt('You have forgetten to specify some information. Please go Back and try again.')."</p>");
1.257 albertel 6187: if ( $env{'form.selectpage'} eq '') {
1.492 albertel 6188: $r->print('<p><span class="LC_error">'.&mt('You have not selected a Sequence to grade').'</span></p>');
1.237 albertel 6189: }
1.257 albertel 6190: if ( $env{'form.scantron_selectfile'} eq '') {
1.492 albertel 6191: $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 6192: }
1.257 albertel 6193: if ( $env{'form.scantron_format'} eq '') {
1.492 albertel 6194: $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 6195: }
6196: } else {
1.265 www 6197: my $warning=&scantron_warning_screen('Grading: Validate Records');
1.492 albertel 6198: $r->print('
6199: '.$warning.'
6200: <input type="submit" name="submit" value="'.&mt('Grading: Validate Records').'" />
1.203 albertel 6201: <input type="hidden" name="command" value="scantron_validate" />
1.492 albertel 6202: ');
1.237 albertel 6203: }
1.614 www 6204: $r->print("</form><br />");
1.203 albertel 6205: return '';
6206: }
6207:
1.423 albertel 6208: =pod
6209:
6210: =item scantron_form_start
6211:
1.424 albertel 6212: html hidden input for remembering all selected grading options
6213:
1.423 albertel 6214: =cut
6215:
1.203 albertel 6216: sub scantron_form_start {
6217: my ($max_bubble)=@_;
6218: my $result= <<SCANTRONFORM;
6219: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
1.257 albertel 6220: <input type="hidden" name="selectpage" value="$env{'form.selectpage'}" />
6221: <input type="hidden" name="scantron_format" value="$env{'form.scantron_format'}" />
6222: <input type="hidden" name="scantron_selectfile" value="$env{'form.scantron_selectfile'}" />
1.218 albertel 6223: <input type="hidden" name="scantron_maxbubble" value="$max_bubble" />
1.257 albertel 6224: <input type="hidden" name="scantron_CODElist" value="$env{'form.scantron_CODElist'}" />
6225: <input type="hidden" name="scantron_CODEunique" value="$env{'form.scantron_CODEunique'}" />
6226: <input type="hidden" name="scantron_options_redo" value="$env{'form.scantron_options_redo'}" />
6227: <input type="hidden" name="scantron_options_ignore" value="$env{'form.scantron_options_ignore'}" />
1.331 albertel 6228: <input type="hidden" name="scantron_options_hidden" value="$env{'form.scantron_options_hidden'}" />
1.203 albertel 6229: SCANTRONFORM
1.447 foxr 6230:
6231: my $line = 0;
6232: while (defined($env{"form.scantron.bubblelines.$line"})) {
6233: my $chunk =
6234: '<input type="hidden" name="scantron.bubblelines.'.$line.'" value="'.$env{"form.scantron.bubblelines.$line"}.'" />'."\n";
1.448 foxr 6235: $chunk .=
6236: '<input type="hidden" name="scantron.first_bubble_line.'.$line.'" value="'.$env{"form.scantron.first_bubble_line.$line"}.'" />'."\n";
1.503 raeburn 6237: $chunk .=
6238: '<input type="hidden" name="scantron.sub_bubblelines.'.$line.'" value="'.$env{"form.scantron.sub_bubblelines.$line"}.'" />'."\n";
1.504 raeburn 6239: $chunk .=
6240: '<input type="hidden" name="scantron.responsetype.'.$line.'" value="'.$env{"form.scantron.responsetype.$line"}.'" />'."\n";
1.447 foxr 6241: $result .= $chunk;
6242: $line++;
6243: }
1.203 albertel 6244: return $result;
6245: }
6246:
1.423 albertel 6247: =pod
6248:
6249: =item scantron_validate_file
6250:
1.424 albertel 6251: Dispatch routine for doing validation of a bubble sheet data file.
6252:
6253: Also processes any necessary information resets that need to
6254: occur before validation begins (ignore previous corrections,
6255: restarting the skipped records processing)
6256:
1.423 albertel 6257: =cut
6258:
1.157 albertel 6259: sub scantron_validate_file {
1.608 www 6260: my ($r,$symb) = @_;
1.157 albertel 6261: if (!$symb) {return '';}
1.324 albertel 6262: my $default_form_data=&defaultFormData($symb);
1.200 albertel 6263:
6264: # do the detection of only doing skipped records first befroe we delete
1.424 albertel 6265: # them when doing the corrections reset
1.257 albertel 6266: if ($env{'form.scantron_options_redo'} ne 'redo_skipped_ready') {
1.200 albertel 6267: &reset_skipping_status();
6268: }
1.257 albertel 6269: if ($env{'form.scantron_options_redo'} eq 'redo_skipped') {
1.200 albertel 6270: &remember_current_skipped();
1.257 albertel 6271: $env{'form.scantron_options_redo'}='redo_skipped_ready';
1.200 albertel 6272: }
6273:
1.257 albertel 6274: if ($env{'form.scantron_options_ignore'} eq 'ignore_corrections') {
1.200 albertel 6275: &check_for_error($r,&scantron_remove_file('corrected'));
6276: &check_for_error($r,&scantron_remove_file('skipped'));
6277: &check_for_error($r,&scantron_remove_scan_data());
1.257 albertel 6278: $env{'form.scantron_options_ignore'}='done';
1.192 albertel 6279: }
1.200 albertel 6280:
1.257 albertel 6281: if ($env{'form.scantron_corrections'}) {
1.157 albertel 6282: &scantron_process_corrections($r);
6283: }
1.503 raeburn 6284: $r->print('<p>'.&mt('Gathering necessary information.').'</p>');$r->rflush();
1.157 albertel 6285: #get the student pick code ready
6286: $r->print(&Apache::loncommon::studentbrowser_javascript());
1.582 raeburn 6287: my $nav_error;
6288: my $max_bubble=&scantron_get_maxbubble(\$nav_error);
6289: if ($nav_error) {
6290: $r->print(&navmap_errormsg());
6291: return '';
6292: }
1.203 albertel 6293: my $result=&scantron_form_start($max_bubble).$default_form_data;
1.157 albertel 6294: $r->print($result);
6295:
1.334 albertel 6296: my @validate_phases=( 'sequence',
6297: 'ID',
1.157 albertel 6298: 'CODE',
6299: 'doublebubble',
6300: 'missingbubbles');
1.257 albertel 6301: if (!$env{'form.validatepass'}) {
6302: $env{'form.validatepass'} = 0;
1.157 albertel 6303: }
1.257 albertel 6304: my $currentphase=$env{'form.validatepass'};
1.157 albertel 6305:
1.448 foxr 6306:
1.157 albertel 6307: my $stop=0;
6308: while (!$stop && $currentphase < scalar(@validate_phases)) {
1.503 raeburn 6309: $r->print(&mt('Validating '.$validate_phases[$currentphase]).'<br />');
1.157 albertel 6310: $r->rflush();
6311: my $which="scantron_validate_".$validate_phases[$currentphase];
6312: {
6313: no strict 'refs';
6314: ($stop,$currentphase)=&$which($r,$currentphase);
6315: }
6316: }
6317: if (!$stop) {
1.203 albertel 6318: my $warning=&scantron_warning_screen('Start Grading');
1.542 raeburn 6319: $r->print(&mt('Validation process complete.').'<br />'.
6320: $warning.
6321: &mt('Perform verification for each student after storage of submissions?').
6322: ' <span class="LC_nobreak"><label>'.
6323: '<input type="radio" name="verifyrecord" value="1" />'.&mt('Yes').'</label>'.
6324: (' 'x3).'<label>'.
6325: '<input type="radio" name="verifyrecord" value="0" checked="checked" />'.&mt('No').
6326: '</label></span><br />'.
6327: &mt('Grading will take longer if you use verification.').'<br />'.
1.572 www 6328: &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 6329: '<input type="submit" name="submit" value="'.&mt('Start Grading').'" />'.
6330: '<input type="hidden" name="command" value="scantron_process" />'."\n");
1.157 albertel 6331: } else {
6332: $r->print('<input type="hidden" name="command" value="scantron_validate" />');
6333: $r->print("<input type='hidden' name='validatepass' value='".$currentphase."' />");
6334: }
6335: if ($stop) {
1.334 albertel 6336: if ($validate_phases[$currentphase] eq 'sequence') {
1.539 riegler 6337: $r->print('<input type="submit" name="submit" value="'.&mt('Ignore').' → " />');
1.492 albertel 6338: $r->print(' '.&mt('this error').' <br />');
1.334 albertel 6339:
1.492 albertel 6340: $r->print(" <p>".&mt("Or click the 'Grading Menu' button to start over.")."</p>");
1.334 albertel 6341: } else {
1.503 raeburn 6342: if ($validate_phases[$currentphase] eq 'doublebubble' || $validate_phases[$currentphase] eq 'missingbubbles') {
1.539 riegler 6343: $r->print('<input type="button" name="submitbutton" value="'.&mt('Continue').' →" onclick="javascript:verify_bubble_radio(this.form)" />');
1.503 raeburn 6344: } else {
1.539 riegler 6345: $r->print('<input type="submit" name="submit" value="'.&mt('Continue').' →" />');
1.503 raeburn 6346: }
1.492 albertel 6347: $r->print(' '.&mt('using corrected info').' <br />');
6348: $r->print("<input type='submit' value='".&mt("Skip")."' name='scantron_skip_record' />");
6349: $r->print(" ".&mt("this scanline saving it for later."));
1.334 albertel 6350: }
1.157 albertel 6351: }
1.614 www 6352: $r->print(" </form><br />");
1.157 albertel 6353: return '';
6354: }
6355:
1.423 albertel 6356:
6357: =pod
6358:
6359: =item scantron_remove_file
6360:
1.424 albertel 6361: Removes the requested bubble sheet data file, makes sure that
6362: scantron_original_<filename> is never removed
6363:
6364:
1.423 albertel 6365: =cut
6366:
1.200 albertel 6367: sub scantron_remove_file {
1.192 albertel 6368: my ($which)=@_;
1.257 albertel 6369: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6370: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 6371: my $file='scantron_';
1.200 albertel 6372: if ($which eq 'corrected' || $which eq 'skipped') {
6373: $file.=$which.'_';
1.192 albertel 6374: } else {
6375: return 'refused';
6376: }
1.257 albertel 6377: $file.=$env{'form.scantron_selectfile'};
1.200 albertel 6378: return &Apache::lonnet::removeuserfile($cname,$cdom,$file);
6379: }
6380:
1.423 albertel 6381:
6382: =pod
6383:
6384: =item scantron_remove_scan_data
6385:
1.424 albertel 6386: Removes all scan_data correction for the requested bubble sheet
6387: data file. (In the case that both the are doing skipped records we need
6388: to remember the old skipped lines for the time being so that element
6389: persists for a while.)
6390:
1.423 albertel 6391: =cut
6392:
1.200 albertel 6393: sub scantron_remove_scan_data {
1.257 albertel 6394: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6395: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 6396: my @keys=&Apache::lonnet::getkeys('nohist_scantrondata',$cdom,$cname);
6397: my @todelete;
1.257 albertel 6398: my $filename=$env{'form.scantron_selectfile'};
1.192 albertel 6399: foreach my $key (@keys) {
6400: if ($key=~/^\Q$filename\E_/) {
1.257 albertel 6401: if ($env{'form.scantron_options_redo'} eq 'redo_skipped_ready' &&
1.200 albertel 6402: $key=~/remember_skipping/) {
6403: next;
6404: }
1.192 albertel 6405: push(@todelete,$key);
6406: }
6407: }
1.200 albertel 6408: my $result;
1.192 albertel 6409: if (@todelete) {
1.491 albertel 6410: $result = &Apache::lonnet::del('nohist_scantrondata',
6411: \@todelete,$cdom,$cname);
6412: } else {
6413: $result = 'ok';
1.192 albertel 6414: }
6415: return $result;
6416: }
6417:
1.423 albertel 6418:
6419: =pod
6420:
6421: =item scantron_getfile
6422:
1.424 albertel 6423: Fetches the requested bubble sheet data file (all 3 versions), and
6424: the scan_data hash
6425:
6426: Arguments:
6427: None
6428:
6429: Returns:
6430: 2 hash references
6431:
6432: - first one has
6433: orig -
6434: corrected -
6435: skipped - each of which points to an array ref of the specified
6436: file broken up into individual lines
6437: count - number of scanlines
6438:
6439: - second is the scan_data hash possible keys are
1.425 albertel 6440: ($number refers to scanline numbered $number and thus the key affects
6441: only that scanline
6442: $bubline refers to the specific bubble line element and the aspects
6443: refers to that specific bubble line element)
6444:
6445: $number.user - username:domain to use
6446: $number.CODE_ignore_dup
6447: - ignore the duplicate CODE error
6448: $number.useCODE
6449: - use the CODE in the scanline as is
6450: $number.no_bubble.$bubline
6451: - it is valid that there is no bubbled in bubble
6452: at $number $bubline
6453: remember_skipping
6454: - a frozen hash containing keys of $number and values
6455: of either
6456: 1 - we are on a 'do skipped records pass' and plan
6457: on processing this line
6458: 2 - we are on a 'do skipped records pass' and this
6459: scanline has been marked to skip yet again
1.424 albertel 6460:
1.423 albertel 6461: =cut
6462:
1.157 albertel 6463: sub scantron_getfile {
1.200 albertel 6464: #FIXME really would prefer a scantron directory
1.257 albertel 6465: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6466: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.157 albertel 6467: my $lines;
6468: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6469: 'scantron_orig_'.$env{'form.scantron_selectfile'});
1.157 albertel 6470: my %scanlines;
6471: $scanlines{'orig'}=[(split("\n",$lines,-1))];
6472: my $temp=$scanlines{'orig'};
6473: $scanlines{'count'}=$#$temp;
6474:
6475: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6476: 'scantron_corrected_'.$env{'form.scantron_selectfile'});
1.157 albertel 6477: if ($lines eq '-1') {
6478: $scanlines{'corrected'}=[];
6479: } else {
6480: $scanlines{'corrected'}=[(split("\n",$lines,-1))];
6481: }
6482: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6483: 'scantron_skipped_'.$env{'form.scantron_selectfile'});
1.157 albertel 6484: if ($lines eq '-1') {
6485: $scanlines{'skipped'}=[];
6486: } else {
6487: $scanlines{'skipped'}=[(split("\n",$lines,-1))];
6488: }
1.175 albertel 6489: my @tmp=&Apache::lonnet::dump('nohist_scantrondata',$cdom,$cname);
1.157 albertel 6490: if ($tmp[0] =~ /^(error:|no_such_host)/) { @tmp=(); }
6491: my %scan_data = @tmp;
6492: return (\%scanlines,\%scan_data);
6493: }
6494:
1.423 albertel 6495: =pod
6496:
6497: =item lonnet_putfile
6498:
1.424 albertel 6499: Wrapper routine to call &Apache::lonnet::finishuserfileupload
6500:
6501: Arguments:
6502: $contents - data to store
6503: $filename - filename to store $contents into
6504:
6505: Returns:
6506: result value from &Apache::lonnet::finishuserfileupload
6507:
1.423 albertel 6508: =cut
6509:
1.157 albertel 6510: sub lonnet_putfile {
6511: my ($contents,$filename)=@_;
1.257 albertel 6512: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6513: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6514: $env{'form.sillywaytopassafilearound'}=$contents;
1.275 albertel 6515: &Apache::lonnet::finishuserfileupload($docuname,$docudom,'sillywaytopassafilearound',$filename);
1.157 albertel 6516:
6517: }
6518:
1.423 albertel 6519: =pod
6520:
6521: =item scantron_putfile
6522:
1.424 albertel 6523: Stores the current version of the bubble sheet data files, and the
6524: scan_data hash. (Does not modify the original version only the
6525: corrected and skipped versions.
6526:
6527: Arguments:
6528: $scanlines - hash ref that looks like the first return value from
6529: &scantron_getfile()
6530: $scan_data - hash ref that looks like the second return value from
6531: &scantron_getfile()
6532:
1.423 albertel 6533: =cut
6534:
1.157 albertel 6535: sub scantron_putfile {
6536: my ($scanlines,$scan_data) = @_;
1.200 albertel 6537: #FIXME really would prefer a scantron directory
1.257 albertel 6538: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6539: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.200 albertel 6540: if ($scanlines) {
6541: my $prefix='scantron_';
1.157 albertel 6542: # no need to update orig, shouldn't change
6543: # &lonnet_putfile(join("\n",@{$scanlines->{'orig'}}),$prefix.'orig_'.
1.257 albertel 6544: # $env{'form.scantron_selectfile'});
1.200 albertel 6545: &lonnet_putfile(join("\n",@{$scanlines->{'corrected'}}),
6546: $prefix.'corrected_'.
1.257 albertel 6547: $env{'form.scantron_selectfile'});
1.200 albertel 6548: &lonnet_putfile(join("\n",@{$scanlines->{'skipped'}}),
6549: $prefix.'skipped_'.
1.257 albertel 6550: $env{'form.scantron_selectfile'});
1.200 albertel 6551: }
1.175 albertel 6552: &Apache::lonnet::put('nohist_scantrondata',$scan_data,$cdom,$cname);
1.157 albertel 6553: }
6554:
1.423 albertel 6555: =pod
6556:
6557: =item scantron_get_line
6558:
1.424 albertel 6559: Returns the correct version of the scanline
6560:
6561: Arguments:
6562: $scanlines - hash ref that looks like the first return value from
6563: &scantron_getfile()
6564: $scan_data - hash ref that looks like the second return value from
6565: &scantron_getfile()
6566: $i - number of the requested line (starts at 0)
6567:
6568: Returns:
6569: A scanline, (either the original or the corrected one if it
6570: exists), or undef if the requested scanline should be
6571: skipped. (Either because it's an skipped scanline, or it's an
6572: unskipped scanline and we are not doing a 'do skipped scanlines'
6573: pass.
6574:
1.423 albertel 6575: =cut
6576:
1.157 albertel 6577: sub scantron_get_line {
1.200 albertel 6578: my ($scanlines,$scan_data,$i)=@_;
1.376 albertel 6579: if (&should_be_skipped($scanlines,$scan_data,$i)) { return undef; }
6580: #if ($scanlines->{'skipped'}[$i]) { return undef; }
1.157 albertel 6581: if ($scanlines->{'corrected'}[$i]) {return $scanlines->{'corrected'}[$i];}
6582: return $scanlines->{'orig'}[$i];
6583: }
6584:
1.423 albertel 6585: =pod
6586:
6587: =item scantron_todo_count
6588:
1.424 albertel 6589: Counts the number of scanlines that need processing.
6590:
6591: Arguments:
6592: $scanlines - hash ref that looks like the first return value from
6593: &scantron_getfile()
6594: $scan_data - hash ref that looks like the second return value from
6595: &scantron_getfile()
6596:
6597: Returns:
6598: $count - number of scanlines to process
6599:
1.423 albertel 6600: =cut
6601:
1.200 albertel 6602: sub get_todo_count {
6603: my ($scanlines,$scan_data)=@_;
6604: my $count=0;
6605: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
6606: my $line=&scantron_get_line($scanlines,$scan_data,$i);
6607: if ($line=~/^[\s\cz]*$/) { next; }
6608: $count++;
6609: }
6610: return $count;
6611: }
6612:
1.423 albertel 6613: =pod
6614:
6615: =item scantron_put_line
6616:
1.424 albertel 6617: Updates the 'corrected' or 'skipped' versions of the bubble sheet
6618: data file.
6619:
6620: Arguments:
6621: $scanlines - hash ref that looks like the first return value from
6622: &scantron_getfile()
6623: $scan_data - hash ref that looks like the second return value from
6624: &scantron_getfile()
6625: $i - line number to update
6626: $newline - contents of the updated scanline
6627: $skip - if true make the line for skipping and update the
6628: 'skipped' file
6629:
1.423 albertel 6630: =cut
6631:
1.157 albertel 6632: sub scantron_put_line {
1.200 albertel 6633: my ($scanlines,$scan_data,$i,$newline,$skip)=@_;
1.157 albertel 6634: if ($skip) {
6635: $scanlines->{'skipped'}[$i]=$newline;
1.376 albertel 6636: &start_skipping($scan_data,$i);
1.157 albertel 6637: return;
6638: }
6639: $scanlines->{'corrected'}[$i]=$newline;
6640: }
6641:
1.423 albertel 6642: =pod
6643:
6644: =item scantron_clear_skip
6645:
1.424 albertel 6646: Remove a line from the 'skipped' file
6647:
6648: Arguments:
6649: $scanlines - hash ref that looks like the first return value from
6650: &scantron_getfile()
6651: $scan_data - hash ref that looks like the second return value from
6652: &scantron_getfile()
6653: $i - line number to update
6654:
1.423 albertel 6655: =cut
6656:
1.376 albertel 6657: sub scantron_clear_skip {
6658: my ($scanlines,$scan_data,$i)=@_;
6659: if (exists($scanlines->{'skipped'}[$i])) {
6660: undef($scanlines->{'skipped'}[$i]);
6661: return 1;
6662: }
6663: return 0;
6664: }
6665:
1.423 albertel 6666: =pod
6667:
6668: =item scantron_filter_not_exam
6669:
1.424 albertel 6670: Filter routine used by &Apache::lonnavmaps::retrieveResources(), to
6671: filter out resources that are not marked as 'exam' mode
6672:
1.423 albertel 6673: =cut
6674:
1.334 albertel 6675: sub scantron_filter_not_exam {
6676: my ($curres)=@_;
6677:
6678: if (ref($curres) && $curres->is_problem() && !$curres->is_exam()) {
6679: # if the user has asked to not have either hidden
6680: # or 'randomout' controlled resources to be graded
6681: # don't include them
6682: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
6683: && $curres->randomout) {
6684: return 0;
6685: }
6686: return 1;
6687: }
6688: return 0;
6689: }
6690:
1.423 albertel 6691: =pod
6692:
6693: =item scantron_validate_sequence
6694:
1.424 albertel 6695: Validates the selected sequence, checking for resource that are
6696: not set to exam mode.
6697:
1.423 albertel 6698: =cut
6699:
1.334 albertel 6700: sub scantron_validate_sequence {
6701: my ($r,$currentphase) = @_;
6702:
6703: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 6704: unless (ref($navmap)) {
6705: $r->print(&navmap_errormsg());
6706: return (1,$currentphase);
6707: }
1.334 albertel 6708: my (undef,undef,$sequence)=
6709: &Apache::lonnet::decode_symb($env{'form.selectpage'});
6710:
6711: my $map=$navmap->getResourceByUrl($sequence);
6712:
6713: $r->print('<input type="hidden" name="validate_sequence_exam"
6714: value="ignore" />');
6715: if ($env{'form.validate_sequence_exam'} ne 'ignore') {
6716: my @resources=
6717: $navmap->retrieveResources($map,\&scantron_filter_not_exam,1,0);
6718: if (@resources) {
1.357 banghart 6719: $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 6720: return (1,$currentphase);
6721: }
6722: }
6723:
6724: return (0,$currentphase+1);
6725: }
6726:
1.423 albertel 6727:
6728:
1.157 albertel 6729: sub scantron_validate_ID {
6730: my ($r,$currentphase) = @_;
6731:
6732: #get student info
6733: my $classlist=&Apache::loncoursedata::get_classlist();
6734: my %idmap=&username_to_idmap($classlist);
6735:
6736: #get scantron line setup
1.257 albertel 6737: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 6738: my ($scanlines,$scan_data)=&scantron_getfile();
1.582 raeburn 6739:
6740: my $nav_error;
6741: &scantron_get_maxbubble(\$nav_error); # parse needs the bubble_lines.. array.
6742: if ($nav_error) {
6743: $r->print(&navmap_errormsg());
6744: return(1,$currentphase);
6745: }
1.157 albertel 6746:
6747: my %found=('ids'=>{},'usernames'=>{});
6748: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 6749: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 6750: if ($line=~/^[\s\cz]*$/) { next; }
6751: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
6752: $scan_data);
6753: my $id=$$scan_record{'scantron.ID'};
6754: my $found;
6755: foreach my $checkid (keys(%idmap)) {
6756: if (lc($checkid) eq lc($id)) { $found=$checkid;last; }
6757: }
6758: if ($found) {
6759: my $username=$idmap{$found};
6760: if ($found{'ids'}{$found}) {
6761: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
6762: $line,'duplicateID',$found);
1.194 albertel 6763: return(1,$currentphase);
1.157 albertel 6764: } elsif ($found{'usernames'}{$username}) {
6765: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
6766: $line,'duplicateID',$username);
1.194 albertel 6767: return(1,$currentphase);
1.157 albertel 6768: }
1.186 albertel 6769: #FIXME store away line we previously saw the ID on to use above
1.157 albertel 6770: $found{'ids'}{$found}++;
6771: $found{'usernames'}{$username}++;
6772: } else {
6773: if ($id =~ /^\s*$/) {
1.158 albertel 6774: my $username=&scan_data($scan_data,"$i.user");
1.157 albertel 6775: if (defined($username) && $found{'usernames'}{$username}) {
6776: &scantron_get_correction($r,$i,$scan_record,
6777: \%scantron_config,
6778: $line,'duplicateID',$username);
1.194 albertel 6779: return(1,$currentphase);
1.157 albertel 6780: } elsif (!defined($username)) {
6781: &scantron_get_correction($r,$i,$scan_record,
6782: \%scantron_config,
6783: $line,'incorrectID');
1.194 albertel 6784: return(1,$currentphase);
1.157 albertel 6785: }
6786: $found{'usernames'}{$username}++;
6787: } else {
6788: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
6789: $line,'incorrectID');
1.194 albertel 6790: return(1,$currentphase);
1.157 albertel 6791: }
6792: }
6793: }
6794:
6795: return (0,$currentphase+1);
6796: }
6797:
1.423 albertel 6798:
1.157 albertel 6799: sub scantron_get_correction {
6800: my ($r,$i,$scan_record,$scan_config,$line,$error,$arg)=@_;
1.454 banghart 6801: #FIXME in the case of a duplicated ID the previous line, probably need
1.157 albertel 6802: #to show both the current line and the previous one and allow skipping
6803: #the previous one or the current one
6804:
1.333 albertel 6805: if ( $$scan_record{'scantron.PaperID'} =~ /\S/) {
1.492 albertel 6806: $r->print("<p>".&mt("<b>An error was detected ($error)</b>".
6807: " for PaperID <tt>[_1]</tt>",
6808: $$scan_record{'scantron.PaperID'})."</p> \n");
1.157 albertel 6809: } else {
1.492 albertel 6810: $r->print("<p>".&mt("<b>An error was detected ($error)</b>".
6811: " in scanline [_1] <pre>[_2]</pre>",
6812: $i,$line)."</p> \n");
6813: }
6814: my $message="<p>".&mt("The ID on the form is <tt>[_1]</tt><br />".
6815: "The name on the paper is [_2],[_3]",
6816: $$scan_record{'scantron.ID'},
6817: $$scan_record{'scantron.LastName'},
6818: $$scan_record{'scantron.FirstName'})."</p>";
1.242 albertel 6819:
1.157 albertel 6820: $r->print('<input type="hidden" name="scantron_corrections" value="'.$error.'" />'."\n");
6821: $r->print('<input type="hidden" name="scantron_line" value="'.$i.'" />'."\n");
1.503 raeburn 6822: # Array populated for doublebubble or
6823: my @lines_to_correct; # missingbubble errors to build javascript
6824: # to validate radio button checking
6825:
1.157 albertel 6826: if ($error =~ /ID$/) {
1.186 albertel 6827: if ($error eq 'incorrectID') {
1.492 albertel 6828: $r->print("<p>".&mt("The encoded ID is not in the classlist").
6829: "</p>\n");
1.157 albertel 6830: } elsif ($error eq 'duplicateID') {
1.492 albertel 6831: $r->print("<p>".&mt("The encoded ID has also been used by a previous paper [_1]",$arg)."</p>\n");
1.157 albertel 6832: }
1.242 albertel 6833: $r->print($message);
1.492 albertel 6834: $r->print("<p>".&mt("How should I handle this?")." <br /> \n");
1.157 albertel 6835: $r->print("\n<ul><li> ");
6836: #FIXME it would be nice if this sent back the user ID and
6837: #could do partial userID matches
6838: $r->print(&Apache::loncommon::selectstudent_link('scantronupload',
6839: 'scantron_username','scantron_domain'));
6840: $r->print(": <input type='text' name='scantron_username' value='' />");
6841: $r->print("\n@".
1.257 albertel 6842: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'scantron_domain'));
1.157 albertel 6843:
6844: $r->print('</li>');
1.186 albertel 6845: } elsif ($error =~ /CODE$/) {
6846: if ($error eq 'incorrectCODE') {
1.492 albertel 6847: $r->print("<p>".&mt("The encoded CODE is not in the list of possible CODEs.")."</p>\n");
1.186 albertel 6848: } elsif ($error eq 'duplicateCODE') {
1.492 albertel 6849: $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 6850: }
1.492 albertel 6851: $r->print("<p>".&mt("The CODE on the form is <tt>'[_1]'</tt>",
6852: $$scan_record{'scantron.CODE'})."<br />\n");
1.242 albertel 6853: $r->print($message);
1.492 albertel 6854: $r->print("<p>".&mt("How should I handle this?")." <br /> \n");
1.187 albertel 6855: $r->print("\n<br /> ");
1.194 albertel 6856: my $i=0;
1.273 albertel 6857: if ($error eq 'incorrectCODE'
6858: && $$scan_record{'scantron.CODE'}=~/\S/ ) {
1.194 albertel 6859: my ($max,$closest)=&scantron_get_closely_matching_CODEs($arg,$$scan_record{'scantron.CODE'});
1.278 albertel 6860: if ($closest > 0) {
6861: foreach my $testcode (@{$closest}) {
6862: my $checked='';
1.569 bisitz 6863: if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 6864: $r->print("
6865: <label>
1.569 bisitz 6866: <input type='radio' name='scantron_CODE_resolution' value='use_closest_$i'$checked />
1.492 albertel 6867: ".&mt("Use the similar CODE [_1] instead.",
6868: "<b><tt>".$testcode."</tt></b>")."
6869: </label>
6870: <input type='hidden' name='scantron_CODE_closest_$i' value='$testcode' />");
1.278 albertel 6871: $r->print("\n<br />");
6872: $i++;
6873: }
1.194 albertel 6874: }
6875: }
1.273 albertel 6876: if ($$scan_record{'scantron.CODE'}=~/\S/ ) {
1.569 bisitz 6877: my $checked; if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 6878: $r->print("
6879: <label>
1.569 bisitz 6880: <input type='radio' name='scantron_CODE_resolution' value='use_unfound'$checked />
1.492 albertel 6881: ".&mt("Use the CODE [_1] that is was on the paper, ignoring the error.",
6882: "<b><tt>".$$scan_record{'scantron.CODE'}."</tt></b>")."
6883: </label>");
1.273 albertel 6884: $r->print("\n<br />");
6885: }
1.194 albertel 6886:
1.597 wenzelju 6887: $r->print(&Apache::lonhtmlcommon::scripttag(<<ENDSCRIPT));
1.188 albertel 6888: function change_radio(field) {
1.190 albertel 6889: var slct=document.scantronupload.scantron_CODE_resolution;
1.188 albertel 6890: var i;
6891: for (i=0;i<slct.length;i++) {
6892: if (slct[i].value==field) { slct[i].checked=true; }
6893: }
6894: }
6895: ENDSCRIPT
1.187 albertel 6896: my $href="/adm/pickcode?".
1.359 www 6897: "form=".&escape("scantronupload").
6898: "&scantron_format=".&escape($env{'form.scantron_format'}).
6899: "&scantron_CODElist=".&escape($env{'form.scantron_CODElist'}).
6900: "&curCODE=".&escape($$scan_record{'scantron.CODE'}).
6901: "&scantron_selectfile=".&escape($env{'form.scantron_selectfile'});
1.332 albertel 6902: if ($env{'form.scantron_CODElist'} =~ /\S/) {
1.492 albertel 6903: $r->print("
6904: <label>
6905: <input type='radio' name='scantron_CODE_resolution' value='use_found' />
6906: ".&mt("[_1]Select[_2] a CODE from the list of all CODEs and use it.",
6907: "<a target='_blank' href='$href'>","</a>")."
6908: </label>
1.558 bisitz 6909: ".&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 6910: $r->print("\n<br />");
6911: }
1.492 albertel 6912: $r->print("
6913: <label>
6914: <input type='radio' name='scantron_CODE_resolution' value='use_typed' />
6915: ".&mt("Use [_1] as the CODE.",
6916: "</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 6917: $r->print("\n<br /><br />");
1.157 albertel 6918: } elsif ($error eq 'doublebubble') {
1.503 raeburn 6919: $r->print("<p>".&mt("There have been multiple bubbles scanned for some question(s)")."</p>\n");
1.497 foxr 6920:
6921: # The form field scantron_questions is acutally a list of line numbers.
6922: # represented by this form so:
6923:
6924: my $line_list = &questions_to_line_list($arg);
6925:
1.157 albertel 6926: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 6927: $line_list.'" />');
1.242 albertel 6928: $r->print($message);
1.492 albertel 6929: $r->print("<p>".&mt("Please indicate which bubble should be used for grading")."</p>");
1.157 albertel 6930: foreach my $question (@{$arg}) {
1.503 raeburn 6931: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
6932: $scan_record, $error);
1.524 raeburn 6933: push(@lines_to_correct,@linenums);
1.157 albertel 6934: }
1.503 raeburn 6935: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 6936: } elsif ($error eq 'missingbubble') {
1.492 albertel 6937: $r->print("<p>".&mt("There have been <b>no</b> bubbles scanned for some question(s)")."</p>\n");
1.242 albertel 6938: $r->print($message);
1.492 albertel 6939: $r->print("<p>".&mt("Please indicate which bubble should be used for grading.")."</p>");
1.503 raeburn 6940: $r->print(&mt("Some questions have no scanned bubbles.")."\n");
1.497 foxr 6941:
1.503 raeburn 6942: # The form field scantron_questions is actually a list of line numbers not
1.497 foxr 6943: # a list of question numbers. Therefore:
6944: #
6945:
6946: my $line_list = &questions_to_line_list($arg);
6947:
1.157 albertel 6948: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 6949: $line_list.'" />');
1.157 albertel 6950: foreach my $question (@{$arg}) {
1.503 raeburn 6951: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
6952: $scan_record, $error);
1.524 raeburn 6953: push(@lines_to_correct,@linenums);
1.157 albertel 6954: }
1.503 raeburn 6955: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 6956: } else {
6957: $r->print("\n<ul>");
6958: }
6959: $r->print("\n</li></ul>");
1.497 foxr 6960: }
6961:
1.503 raeburn 6962: sub verify_bubbles_checked {
6963: my (@ansnums) = @_;
6964: my $ansnumstr = join('","',@ansnums);
6965: my $warning = &mt("A bubble or 'No bubble' selection has not been made for one or more lines.");
1.597 wenzelju 6966: my $output = &Apache::lonhtmlcommon::scripttag((<<ENDSCRIPT));
1.503 raeburn 6967: function verify_bubble_radio(form) {
6968: var ansnumArray = new Array ("$ansnumstr");
6969: var need_bubble_count = 0;
6970: for (var i=0; i<ansnumArray.length; i++) {
6971: if (form.elements["scantron_correct_Q_"+ansnumArray[i]].length > 1) {
6972: var bubble_picked = 0;
6973: for (var j=0; j<form.elements["scantron_correct_Q_"+ansnumArray[i]].length; j++) {
6974: if (form.elements["scantron_correct_Q_"+ansnumArray[i]][j].checked == true) {
6975: bubble_picked = 1;
6976: }
6977: }
6978: if (bubble_picked == 0) {
6979: need_bubble_count ++;
6980: }
6981: }
6982: }
6983: if (need_bubble_count) {
6984: alert("$warning");
6985: return;
6986: }
6987: form.submit();
6988: }
6989: ENDSCRIPT
6990: return $output;
6991: }
6992:
1.497 foxr 6993: =pod
6994:
6995: =item questions_to_line_list
1.157 albertel 6996:
1.497 foxr 6997: Converts a list of questions into a string of comma separated
6998: line numbers in the answer sheet used by the questions. This is
6999: used to fill in the scantron_questions form field.
7000:
7001: Arguments:
7002: questions - Reference to an array of questions.
7003:
7004: =cut
7005:
7006:
7007: sub questions_to_line_list {
7008: my ($questions) = @_;
7009: my @lines;
7010:
1.503 raeburn 7011: foreach my $item (@{$questions}) {
7012: my $question = $item;
7013: my ($first,$count,$last);
7014: if ($item =~ /^(\d+)\.(\d+)$/) {
7015: $question = $1;
7016: my $subquestion = $2;
7017: $first = $first_bubble_line{$question-1} + 1;
7018: my @subans = split(/,/,$subdivided_bubble_lines{$question-1});
7019: my $subcount = 1;
7020: while ($subcount<$subquestion) {
7021: $first += $subans[$subcount-1];
7022: $subcount ++;
7023: }
7024: $count = $subans[$subquestion-1];
7025: } else {
7026: $first = $first_bubble_line{$question-1} + 1;
7027: $count = $bubble_lines_per_response{$question-1};
7028: }
1.506 raeburn 7029: $last = $first+$count-1;
1.503 raeburn 7030: push(@lines, ($first..$last));
1.497 foxr 7031: }
7032: return join(',', @lines);
7033: }
7034:
7035: =pod
7036:
7037: =item prompt_for_corrections
7038:
7039: Prompts for a potentially multiline correction to the
7040: user's bubbling (factors out common code from scantron_get_correction
7041: for multi and missing bubble cases).
7042:
7043: Arguments:
7044: $r - Apache request object.
7045: $question - The question number to prompt for.
7046: $scan_config - The scantron file configuration hash.
7047: $scan_record - Reference to the hash that has the the parsed scanlines.
1.503 raeburn 7048: $error - Type of error
1.497 foxr 7049:
7050: Implicit inputs:
7051: %bubble_lines_per_response - Starting line numbers for each question.
7052: Numbered from 0 (but question numbers are from
7053: 1.
7054: %first_bubble_line - Starting bubble line for each question.
1.509 raeburn 7055: %subdivided_bubble_lines - optionresponse, matchresponse and rankresponse
7056: type problems render as separate sub-questions,
1.503 raeburn 7057: in exam mode. This hash contains a
7058: comma-separated list of the lines per
7059: sub-question.
1.510 raeburn 7060: %responsetype_per_response - essayresponse, formularesponse,
7061: stringresponse, imageresponse, reactionresponse,
7062: and organicresponse type problem parts can have
1.503 raeburn 7063: multiple lines per response if the weight
7064: assigned exceeds 10. In this case, only
7065: one bubble per line is permitted, but more
7066: than one line might contain bubbles, e.g.
7067: bubbling of: line 1 - J, line 2 - J,
7068: line 3 - B would assign 22 points.
1.497 foxr 7069:
7070: =cut
7071:
7072: sub prompt_for_corrections {
1.503 raeburn 7073: my ($r, $question, $scan_config, $scan_record, $error) = @_;
7074: my ($current_line,$lines);
7075: my @linenums;
7076: my $questionnum = $question;
7077: if ($question =~ /^(\d+)\.(\d+)$/) {
7078: $question = $1;
7079: $current_line = $first_bubble_line{$question-1} + 1 ;
7080: my $subquestion = $2;
7081: my @subans = split(/,/,$subdivided_bubble_lines{$question-1});
7082: my $subcount = 1;
7083: while ($subcount<$subquestion) {
7084: $current_line += $subans[$subcount-1];
7085: $subcount ++;
7086: }
7087: $lines = $subans[$subquestion-1];
7088: } else {
7089: $current_line = $first_bubble_line{$question-1} + 1 ;
7090: $lines = $bubble_lines_per_response{$question-1};
7091: }
1.497 foxr 7092: if ($lines > 1) {
1.503 raeburn 7093: $r->print(&mt('The group of bubble lines below responds to a single question.').'<br />');
7094: if (($responsetype_per_response{$question-1} eq 'essayresponse') ||
7095: ($responsetype_per_response{$question-1} eq 'formularesponse') ||
1.510 raeburn 7096: ($responsetype_per_response{$question-1} eq 'stringresponse') ||
7097: ($responsetype_per_response{$question-1} eq 'imageresponse') ||
7098: ($responsetype_per_response{$question-1} eq 'reactionresponse') ||
7099: ($responsetype_per_response{$question-1} eq 'organicresponse')) {
1.572 www 7100: $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 7101: } else {
7102: $r->print(&mt("Select at most one bubble in a single line and select 'No Bubble' in all the other lines. ")."<br />");
7103: }
1.497 foxr 7104: }
7105: for (my $i =0; $i < $lines; $i++) {
1.503 raeburn 7106: my $selected = $$scan_record{"scantron.$current_line.answer"};
7107: &scantron_bubble_selector($r,$scan_config,$current_line,
7108: $questionnum,$error,split('', $selected));
1.524 raeburn 7109: push(@linenums,$current_line);
1.497 foxr 7110: $current_line++;
7111: }
7112: if ($lines > 1) {
7113: $r->print("<hr /><br />");
7114: }
1.503 raeburn 7115: return @linenums;
1.157 albertel 7116: }
1.423 albertel 7117:
7118: =pod
7119:
7120: =item scantron_bubble_selector
7121:
7122: Generates the html radiobuttons to correct a single bubble line
1.424 albertel 7123: possibly showing the existing the selected bubbles if known
1.423 albertel 7124:
7125: Arguments:
7126: $r - Apache request object
7127: $scan_config - hash from &get_scantron_config()
1.497 foxr 7128: $line - Number of the line being displayed.
1.503 raeburn 7129: $questionnum - Question number (may include subquestion)
7130: $error - Type of error.
1.497 foxr 7131: @selected - Array of bubbles picked on this line.
1.423 albertel 7132:
7133: =cut
7134:
1.157 albertel 7135: sub scantron_bubble_selector {
1.503 raeburn 7136: my ($r,$scan_config,$line,$questionnum,$error,@selected)=@_;
1.157 albertel 7137: my $max=$$scan_config{'Qlength'};
1.274 albertel 7138:
7139: my $scmode=$$scan_config{'Qon'};
7140: if ($scmode eq 'number' || $scmode eq 'letter') { $max=10; }
7141:
1.157 albertel 7142: my @alphabet=('A'..'Z');
1.503 raeburn 7143: $r->print(&Apache::loncommon::start_data_table().
7144: &Apache::loncommon::start_data_table_row());
7145: $r->print('<td rowspan="2" class="LC_leftcol_header">'.$line.'</td>');
1.497 foxr 7146: for (my $i=0;$i<$max+1;$i++) {
7147: $r->print("\n".'<td align="center">');
7148: if ($selected[0] eq $alphabet[$i]) { $r->print('X'); shift(@selected) }
7149: else { $r->print(' '); }
7150: $r->print('</td>');
7151: }
1.503 raeburn 7152: $r->print(&Apache::loncommon::end_data_table_row().
7153: &Apache::loncommon::start_data_table_row());
1.497 foxr 7154: for (my $i=0;$i<$max;$i++) {
7155: $r->print("\n".
7156: '<td><label><input type="radio" name="scantron_correct_Q_'.
7157: $line.'" value="'.$i.'" />'.$alphabet[$i]."</label></td>");
7158: }
1.503 raeburn 7159: my $nobub_checked = ' ';
7160: if ($error eq 'missingbubble') {
7161: $nobub_checked = ' checked = "checked" ';
7162: }
7163: $r->print("\n".'<td><label><input type="radio" name="scantron_correct_Q_'.
7164: $line.'" value="none"'.$nobub_checked.'/>'.&mt('No bubble').
7165: '</label>'."\n".'<input type="hidden" name="scantron_questionnum_Q_'.
7166: $line.'" value="'.$questionnum.'" /></td>');
7167: $r->print(&Apache::loncommon::end_data_table_row().
7168: &Apache::loncommon::end_data_table());
1.157 albertel 7169: }
7170:
1.423 albertel 7171: =pod
7172:
7173: =item num_matches
7174:
1.424 albertel 7175: Counts the number of characters that are the same between the two arguments.
7176:
7177: Arguments:
7178: $orig - CODE from the scanline
7179: $code - CODE to match against
7180:
7181: Returns:
7182: $count - integer count of the number of same characters between the
7183: two arguments
7184:
1.423 albertel 7185: =cut
7186:
1.194 albertel 7187: sub num_matches {
7188: my ($orig,$code) = @_;
7189: my @code=split(//,$code);
7190: my @orig=split(//,$orig);
7191: my $same=0;
7192: for (my $i=0;$i<scalar(@code);$i++) {
7193: if ($code[$i] eq $orig[$i]) { $same++; }
7194: }
7195: return $same;
7196: }
7197:
1.423 albertel 7198: =pod
7199:
7200: =item scantron_get_closely_matching_CODEs
7201:
1.424 albertel 7202: Cycles through all CODEs and finds the set that has the greatest
7203: number of same characters as the provided CODE
7204:
7205: Arguments:
7206: $allcodes - hash ref returned by &get_codes()
7207: $CODE - CODE from the current scanline
7208:
7209: Returns:
7210: 2 element list
7211: - first elements is number of how closely matching the best fit is
7212: (5 means best set has 5 matching characters)
7213: - second element is an arrary ref containing the set of valid CODEs
7214: that best fit the passed in CODE
7215:
1.423 albertel 7216: =cut
7217:
1.194 albertel 7218: sub scantron_get_closely_matching_CODEs {
7219: my ($allcodes,$CODE)=@_;
7220: my @CODEs;
7221: foreach my $testcode (sort(keys(%{$allcodes}))) {
7222: push(@{$CODEs[&num_matches($CODE,$testcode)]},$testcode);
7223: }
7224:
7225: return ($#CODEs,$CODEs[-1]);
7226: }
7227:
1.423 albertel 7228: =pod
7229:
7230: =item get_codes
7231:
1.424 albertel 7232: Builds a hash which has keys of all of the valid CODEs from the selected
7233: set of remembered CODEs.
7234:
7235: Arguments:
7236: $old_name - name of the set of remembered CODEs
7237: $cdom - domain of the course
7238: $cnum - internal course name
7239:
7240: Returns:
7241: %allcodes - keys are the valid CODEs, values are all 1
7242:
1.423 albertel 7243: =cut
7244:
1.194 albertel 7245: sub get_codes {
1.280 foxr 7246: my ($old_name, $cdom, $cnum) = @_;
7247: if (!$old_name) {
7248: $old_name=$env{'form.scantron_CODElist'};
7249: }
7250: if (!$cdom) {
7251: $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
7252: }
7253: if (!$cnum) {
7254: $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
7255: }
1.278 albertel 7256: my %result=&Apache::lonnet::get('CODEs',[$old_name,"type\0$old_name"],
7257: $cdom,$cnum);
7258: my %allcodes;
7259: if ($result{"type\0$old_name"} eq 'number') {
7260: %allcodes=map {($_,1)} split(',',$result{$old_name});
7261: } else {
7262: %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
7263: }
1.194 albertel 7264: return %allcodes;
7265: }
7266:
1.423 albertel 7267: =pod
7268:
7269: =item scantron_validate_CODE
7270:
1.424 albertel 7271: Validates all scanlines in the selected file to not have any
7272: invalid or underspecified CODEs and that none of the codes are
7273: duplicated if this was requested.
7274:
1.423 albertel 7275: =cut
7276:
1.157 albertel 7277: sub scantron_validate_CODE {
7278: my ($r,$currentphase) = @_;
1.257 albertel 7279: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.186 albertel 7280: if ($scantron_config{'CODElocation'} &&
7281: $scantron_config{'CODEstart'} &&
7282: $scantron_config{'CODElength'}) {
1.257 albertel 7283: if (!defined($env{'form.scantron_CODElist'})) {
1.186 albertel 7284: &FIXME_blow_up()
7285: }
7286: } else {
7287: return (0,$currentphase+1);
7288: }
7289:
7290: my %usedCODEs;
7291:
1.194 albertel 7292: my %allcodes=&get_codes();
1.186 albertel 7293:
1.582 raeburn 7294: my $nav_error;
7295: &scantron_get_maxbubble(\$nav_error); # parse needs the lines per response array.
7296: if ($nav_error) {
7297: $r->print(&navmap_errormsg());
7298: return(1,$currentphase);
7299: }
1.447 foxr 7300:
1.186 albertel 7301: my ($scanlines,$scan_data)=&scantron_getfile();
7302: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7303: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.186 albertel 7304: if ($line=~/^[\s\cz]*$/) { next; }
7305: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7306: $scan_data);
7307: my $CODE=$$scan_record{'scantron.CODE'};
7308: my $error=0;
1.224 albertel 7309: if (!&Apache::lonnet::validCODE($CODE)) {
7310: &scantron_get_correction($r,$i,$scan_record,
7311: \%scantron_config,
7312: $line,'incorrectCODE',\%allcodes);
7313: return(1,$currentphase);
7314: }
1.221 albertel 7315: if (%allcodes && !exists($allcodes{$CODE})
7316: && !$$scan_record{'scantron.useCODE'}) {
1.186 albertel 7317: &scantron_get_correction($r,$i,$scan_record,
7318: \%scantron_config,
1.194 albertel 7319: $line,'incorrectCODE',\%allcodes);
7320: return(1,$currentphase);
1.186 albertel 7321: }
1.214 albertel 7322: if (exists($usedCODEs{$CODE})
1.257 albertel 7323: && $env{'form.scantron_CODEunique'} eq 'yes'
1.192 albertel 7324: && !$$scan_record{'scantron.CODE_ignore_dup'}) {
1.186 albertel 7325: &scantron_get_correction($r,$i,$scan_record,
7326: \%scantron_config,
1.194 albertel 7327: $line,'duplicateCODE',$usedCODEs{$CODE});
7328: return(1,$currentphase);
1.186 albertel 7329: }
1.524 raeburn 7330: push(@{$usedCODEs{$CODE}},$$scan_record{'scantron.PaperID'});
1.186 albertel 7331: }
1.157 albertel 7332: return (0,$currentphase+1);
7333: }
7334:
1.423 albertel 7335: =pod
7336:
7337: =item scantron_validate_doublebubble
7338:
1.424 albertel 7339: Validates all scanlines in the selected file to not have any
7340: bubble lines with multiple bubbles marked.
7341:
1.423 albertel 7342: =cut
7343:
1.157 albertel 7344: sub scantron_validate_doublebubble {
7345: my ($r,$currentphase) = @_;
7346: #get student info
7347: my $classlist=&Apache::loncoursedata::get_classlist();
7348: my %idmap=&username_to_idmap($classlist);
7349:
7350: #get scantron line setup
1.257 albertel 7351: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7352: my ($scanlines,$scan_data)=&scantron_getfile();
1.583 raeburn 7353: my $nav_error;
7354: &scantron_get_maxbubble(\$nav_error); # parse needs the bubble line array.
7355: if ($nav_error) {
7356: $r->print(&navmap_errormsg());
7357: return(1,$currentphase);
7358: }
1.447 foxr 7359:
1.157 albertel 7360: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7361: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7362: if ($line=~/^[\s\cz]*$/) { next; }
7363: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7364: $scan_data);
7365: if (!defined($$scan_record{'scantron.doubleerror'})) { next; }
7366: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,$line,
7367: 'doublebubble',
7368: $$scan_record{'scantron.doubleerror'});
7369: return (1,$currentphase);
7370: }
7371: return (0,$currentphase+1);
7372: }
7373:
1.423 albertel 7374:
1.503 raeburn 7375: sub scantron_get_maxbubble {
1.582 raeburn 7376: my ($nav_error) = @_;
1.257 albertel 7377: if (defined($env{'form.scantron_maxbubble'}) &&
7378: $env{'form.scantron_maxbubble'}) {
1.447 foxr 7379: &restore_bubble_lines();
1.257 albertel 7380: return $env{'form.scantron_maxbubble'};
1.191 albertel 7381: }
1.330 albertel 7382:
1.447 foxr 7383: my (undef, undef, $sequence) =
1.257 albertel 7384: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.330 albertel 7385:
1.447 foxr 7386: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 7387: unless (ref($navmap)) {
7388: if (ref($nav_error)) {
7389: $$nav_error = 1;
7390: }
1.591 raeburn 7391: return;
1.582 raeburn 7392: }
1.191 albertel 7393: my $map=$navmap->getResourceByUrl($sequence);
7394: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.330 albertel 7395:
7396: &Apache::lonxml::clear_problem_counter();
7397:
1.557 raeburn 7398: my $uname = $env{'user.name'};
7399: my $udom = $env{'user.domain'};
1.435 foxr 7400: my $cid = $env{'request.course.id'};
7401: my $total_lines = 0;
7402: %bubble_lines_per_response = ();
1.447 foxr 7403: %first_bubble_line = ();
1.503 raeburn 7404: %subdivided_bubble_lines = ();
7405: %responsetype_per_response = ();
1.554 raeburn 7406:
1.447 foxr 7407: my $response_number = 0;
7408: my $bubble_line = 0;
1.191 albertel 7409: foreach my $resource (@resources) {
1.542 raeburn 7410: my ($analysis,$parts) = &scantron_partids_tograde($resource,$cid,$uname,$udom);
7411: if ((ref($analysis) eq 'HASH') && (ref($parts) eq 'ARRAY')) {
7412: foreach my $part_id (@{$parts}) {
7413: my $lines;
7414:
7415: # TODO - make this a persistent hash not an array.
7416:
7417: # optionresponse, matchresponse and rankresponse type items
7418: # render as separate sub-questions in exam mode.
7419: if (($analysis->{$part_id.'.type'} eq 'optionresponse') ||
7420: ($analysis->{$part_id.'.type'} eq 'matchresponse') ||
7421: ($analysis->{$part_id.'.type'} eq 'rankresponse')) {
7422: my ($numbub,$numshown);
7423: if ($analysis->{$part_id.'.type'} eq 'optionresponse') {
7424: if (ref($analysis->{$part_id.'.options'}) eq 'ARRAY') {
7425: $numbub = scalar(@{$analysis->{$part_id.'.options'}});
7426: }
7427: } elsif ($analysis->{$part_id.'.type'} eq 'matchresponse') {
7428: if (ref($analysis->{$part_id.'.items'}) eq 'ARRAY') {
7429: $numbub = scalar(@{$analysis->{$part_id.'.items'}});
7430: }
7431: } elsif ($analysis->{$part_id.'.type'} eq 'rankresponse') {
7432: if (ref($analysis->{$part_id.'.foils'}) eq 'ARRAY') {
7433: $numbub = scalar(@{$analysis->{$part_id.'.foils'}});
7434: }
7435: }
7436: if (ref($analysis->{$part_id.'.shown'}) eq 'ARRAY') {
7437: $numshown = scalar(@{$analysis->{$part_id.'.shown'}});
7438: }
7439: my $bubbles_per_line = 10;
7440: my $inner_bubble_lines = int($numbub/$bubbles_per_line);
7441: if (($numbub % $bubbles_per_line) != 0) {
7442: $inner_bubble_lines++;
7443: }
7444: for (my $i=0; $i<$numshown; $i++) {
7445: $subdivided_bubble_lines{$response_number} .=
7446: $inner_bubble_lines.',';
7447: }
7448: $subdivided_bubble_lines{$response_number} =~ s/,$//;
7449: $lines = $numshown * $inner_bubble_lines;
7450: } else {
7451: $lines = $analysis->{"$part_id.bubble_lines"};
7452: }
7453:
7454: $first_bubble_line{$response_number} = $bubble_line;
7455: $bubble_lines_per_response{$response_number} = $lines;
7456: $responsetype_per_response{$response_number} =
7457: $analysis->{$part_id.'.type'};
7458: $response_number++;
7459:
7460: $bubble_line += $lines;
7461: $total_lines += $lines;
7462: }
7463: }
7464: }
1.552 raeburn 7465: &Apache::lonnet::delenv('scantron.');
1.542 raeburn 7466:
7467: &save_bubble_lines();
7468: $env{'form.scantron_maxbubble'} =
7469: $total_lines;
7470: return $env{'form.scantron_maxbubble'};
7471: }
1.523 raeburn 7472:
1.157 albertel 7473: sub scantron_validate_missingbubbles {
7474: my ($r,$currentphase) = @_;
7475: #get student info
7476: my $classlist=&Apache::loncoursedata::get_classlist();
7477: my %idmap=&username_to_idmap($classlist);
7478:
7479: #get scantron line setup
1.257 albertel 7480: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7481: my ($scanlines,$scan_data)=&scantron_getfile();
1.582 raeburn 7482: my $nav_error;
7483: my $max_bubble=&scantron_get_maxbubble(\$nav_error);
7484: if ($nav_error) {
7485: return(1,$currentphase);
7486: }
1.157 albertel 7487: if (!$max_bubble) { $max_bubble=2**31; }
7488: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7489: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7490: if ($line=~/^[\s\cz]*$/) { next; }
7491: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7492: $scan_data);
7493: if (!defined($$scan_record{'scantron.missingerror'})) { next; }
7494: my @to_correct;
1.470 foxr 7495:
7496: # Probably here's where the error is...
7497:
1.157 albertel 7498: foreach my $missing (@{$$scan_record{'scantron.missingerror'}}) {
1.505 raeburn 7499: my $lastbubble;
7500: if ($missing =~ /^(\d+)\.(\d+)$/) {
7501: my $question = $1;
7502: my $subquestion = $2;
7503: if (!defined($first_bubble_line{$question -1})) { next; }
7504: my $first = $first_bubble_line{$question-1};
7505: my @subans = split(/,/,$subdivided_bubble_lines{$question-1});
7506: my $subcount = 1;
7507: while ($subcount<$subquestion) {
7508: $first += $subans[$subcount-1];
7509: $subcount ++;
7510: }
7511: my $count = $subans[$subquestion-1];
7512: $lastbubble = $first + $count;
7513: } else {
7514: if (!defined($first_bubble_line{$missing - 1})) { next; }
7515: $lastbubble = $first_bubble_line{$missing - 1} + $bubble_lines_per_response{$missing - 1};
7516: }
7517: if ($lastbubble > $max_bubble) { next; }
1.157 albertel 7518: push(@to_correct,$missing);
7519: }
7520: if (@to_correct) {
7521: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
7522: $line,'missingbubble',\@to_correct);
7523: return (1,$currentphase);
7524: }
7525:
7526: }
7527: return (0,$currentphase+1);
7528: }
7529:
1.423 albertel 7530:
1.82 albertel 7531: sub scantron_process_students {
1.608 www 7532: my ($r,$symb) = @_;
1.513 foxr 7533:
1.257 albertel 7534: my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($env{'form.selectpage'});
1.513 foxr 7535: if (!$symb) {
7536: return '';
7537: }
1.324 albertel 7538: my $default_form_data=&defaultFormData($symb);
1.82 albertel 7539:
1.257 albertel 7540: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7541: my ($scanlines,$scan_data)=&scantron_getfile();
1.82 albertel 7542: my $classlist=&Apache::loncoursedata::get_classlist();
7543: my %idmap=&username_to_idmap($classlist);
1.132 bowersj2 7544: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 7545: unless (ref($navmap)) {
7546: $r->print(&navmap_errormsg());
7547: return '';
7548: }
1.83 albertel 7549: my $map=$navmap->getResourceByUrl($sequence);
7550: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.557 raeburn 7551: my (%grader_partids_by_symb,%grader_randomlists_by_symb);
7552: &graders_resources_pass(\@resources,\%grader_partids_by_symb,
7553: \%grader_randomlists_by_symb);
1.586 raeburn 7554: my $resource_error;
1.557 raeburn 7555: foreach my $resource (@resources) {
1.586 raeburn 7556: my $ressymb;
7557: if (ref($resource)) {
7558: $ressymb = $resource->symb();
7559: } else {
7560: $resource_error = 1;
7561: last;
7562: }
1.557 raeburn 7563: my ($analysis,$parts) =
7564: &scantron_partids_tograde($resource,$env{'request.course.id'},
7565: $env{'user.name'},$env{'user.domain'},1);
7566: $grader_partids_by_symb{$ressymb} = $parts;
7567: if (ref($analysis) eq 'HASH') {
7568: if (ref($analysis->{'parts_withrandomlist'}) eq 'ARRAY') {
7569: $grader_randomlists_by_symb{$ressymb} =
7570: $analysis->{'parts_withrandomlist'};
7571: }
7572: }
7573: }
1.586 raeburn 7574: if ($resource_error) {
7575: $r->print(&navmap_errormsg());
7576: return '';
7577: }
1.557 raeburn 7578:
1.554 raeburn 7579: my ($uname,$udom);
1.82 albertel 7580: my $result= <<SCANTRONFORM;
1.81 albertel 7581: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
7582: <input type="hidden" name="command" value="scantron_configphase" />
7583: $default_form_data
7584: SCANTRONFORM
1.82 albertel 7585: $r->print($result);
7586:
7587: my @delayqueue;
1.542 raeburn 7588: my (%completedstudents,%scandata);
1.140 albertel 7589:
1.520 www 7590: my $lock=&Apache::lonnet::set_lock(&mt('Grading bubblesheet exam'));
1.200 albertel 7591: my $count=&get_todo_count($scanlines,$scan_data);
1.575 www 7592: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Bubblesheet Status',
7593: 'Bubblesheet Progress',$count,
1.195 albertel 7594: 'inline',undef,'scantronupload');
1.140 albertel 7595: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
7596: 'Processing first student');
1.542 raeburn 7597: $r->print('<br />');
1.140 albertel 7598: my $start=&Time::HiRes::time();
1.158 albertel 7599: my $i=-1;
1.542 raeburn 7600: my $started;
1.447 foxr 7601:
1.582 raeburn 7602: my $nav_error;
7603: &scantron_get_maxbubble(\$nav_error); # Need the bubble lines array to parse.
7604: if ($nav_error) {
7605: $r->print(&navmap_errormsg());
7606: return '';
7607: }
7608:
1.513 foxr 7609: # If an ssi failed in scantron_get_maxbubble, put an error message out to
7610: # the user and return.
7611:
7612: if ($ssi_error) {
7613: $r->print("</form>");
7614: &ssi_print_error($r);
1.520 www 7615: &Apache::lonnet::remove_lock($lock);
1.513 foxr 7616: return ''; # Dunno why the other returns return '' rather than just returning.
7617: }
1.447 foxr 7618:
1.542 raeburn 7619: my %lettdig = &letter_to_digits();
7620: my $numletts = scalar(keys(%lettdig));
7621:
1.157 albertel 7622: while ($i<$scanlines->{'count'}) {
7623: ($uname,$udom)=('','');
7624: $i++;
1.200 albertel 7625: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7626: if ($line=~/^[\s\cz]*$/) { next; }
1.200 albertel 7627: if ($started) {
7628: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
7629: 'last student');
7630: }
7631: $started=1;
1.157 albertel 7632: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7633: $scan_data);
7634: unless ($uname=&scantron_find_student($scan_record,$scan_data,
7635: \%idmap,$i)) {
7636: &scantron_add_delay(\@delayqueue,$line,
7637: 'Unable to find a student that matches',1);
7638: next;
7639: }
7640: if (exists $completedstudents{$uname}) {
7641: &scantron_add_delay(\@delayqueue,$line,
7642: 'Student '.$uname.' has multiple sheets',2);
7643: next;
7644: }
7645: ($uname,$udom)=split(/:/,$uname);
1.330 albertel 7646:
1.586 raeburn 7647: my (%partids_by_symb,$res_error);
1.554 raeburn 7648: foreach my $resource (@resources) {
1.586 raeburn 7649: my $ressymb;
7650: if (ref($resource)) {
7651: $ressymb = $resource->symb();
7652: } else {
7653: $res_error = 1;
7654: last;
7655: }
1.557 raeburn 7656: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
7657: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
7658: my ($analysis,$parts) =
7659: &scantron_partids_tograde($resource,$env{'request.course.id'},$uname,$udom);
7660: $partids_by_symb{$ressymb} = $parts;
7661: } else {
7662: $partids_by_symb{$ressymb} = $grader_partids_by_symb{$ressymb};
7663: }
1.554 raeburn 7664: }
7665:
1.586 raeburn 7666: if ($res_error) {
7667: &scantron_add_delay(\@delayqueue,$line,
7668: 'An error occurred while grading student '.$uname,2);
7669: next;
7670: }
7671:
1.330 albertel 7672: &Apache::lonxml::clear_problem_counter();
1.514 raeburn 7673: &Apache::lonnet::appenv($scan_record);
1.376 albertel 7674:
7675: if (&scantron_clear_skip($scanlines,$scan_data,$i)) {
7676: &scantron_putfile($scanlines,$scan_data);
7677: }
1.161 albertel 7678:
1.542 raeburn 7679: my $scancode;
7680: if ((exists($scan_record->{'scantron.CODE'})) &&
7681: (&Apache::lonnet::validCODE($scan_record->{'scantron.CODE'}))) {
7682: $scancode = $scan_record->{'scantron.CODE'};
7683: } else {
7684: $scancode = '';
7685: }
7686:
7687: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
1.554 raeburn 7688: \@resources,\%partids_by_symb) eq 'ssi_error') {
1.542 raeburn 7689: $ssi_error = 0; # So end of handler error message does not trigger.
7690: $r->print("</form>");
7691: &ssi_print_error($r);
7692: &Apache::lonnet::remove_lock($lock);
7693: return ''; # Why return ''? Beats me.
7694: }
1.513 foxr 7695:
1.140 albertel 7696: $completedstudents{$uname}={'line'=>$line};
1.542 raeburn 7697: if ($env{'form.verifyrecord'}) {
7698: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
7699: my $studentdata = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
7700: chomp($studentdata);
7701: $studentdata =~ s/\r$//;
7702: my $studentrecord = '';
7703: my $counter = -1;
7704: foreach my $resource (@resources) {
1.554 raeburn 7705: my $ressymb = $resource->symb();
1.542 raeburn 7706: ($counter,my $recording) =
7707: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 7708: $counter,$studentdata,$partids_by_symb{$ressymb},
1.542 raeburn 7709: \%scantron_config,\%lettdig,$numletts);
7710: $studentrecord .= $recording;
7711: }
7712: if ($studentrecord ne $studentdata) {
1.554 raeburn 7713: &Apache::lonxml::clear_problem_counter();
7714: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
7715: \@resources,\%partids_by_symb) eq 'ssi_error') {
7716: $ssi_error = 0; # So end of handler error message does not trigger.
7717: $r->print("</form>");
7718: &ssi_print_error($r);
7719: &Apache::lonnet::remove_lock($lock);
7720: delete($completedstudents{$uname});
7721: return '';
7722: }
1.542 raeburn 7723: $counter = -1;
7724: $studentrecord = '';
7725: foreach my $resource (@resources) {
1.554 raeburn 7726: my $ressymb = $resource->symb();
1.542 raeburn 7727: ($counter,my $recording) =
7728: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 7729: $counter,$studentdata,$partids_by_symb{$ressymb},
1.542 raeburn 7730: \%scantron_config,\%lettdig,$numletts);
7731: $studentrecord .= $recording;
7732: }
7733: if ($studentrecord ne $studentdata) {
7734: $r->print('<p><span class="LC_error">');
7735: if ($scancode eq '') {
7736: $r->print(&mt('Mismatch grading bubble sheet for user: [_1] with ID: [_2].',
7737: $uname.':'.$udom,$scan_record->{'scantron.ID'}));
7738: } else {
7739: $r->print(&mt('Mismatch grading bubble sheet for user: [_1] with ID: [_2] and CODE: [_3].',
7740: $uname.':'.$udom,$scan_record->{'scantron.ID'},$scancode));
7741: }
7742: $r->print('</span><br />'.&Apache::loncommon::start_data_table()."\n".
7743: &Apache::loncommon::start_data_table_header_row()."\n".
7744: '<th>'.&mt('Source').'</th><th>'.&mt('Bubbled responses').'</th>'.
7745: &Apache::loncommon::end_data_table_header_row()."\n".
7746: &Apache::loncommon::start_data_table_row().
7747: '<td>'.&mt('Bubble Sheet').'</td>'.
7748: '<td><span class="LC_nobreak">'.$studentdata.'</span></td>'.
7749: &Apache::loncommon::end_data_table_row().
7750: &Apache::loncommon::start_data_table_row().
7751: '<td>Stored submissions</td>'.
7752: '<td><span class="LC_nobreak">'.$studentrecord.'</span></td>'."\n".
7753: &Apache::loncommon::end_data_table_row().
7754: &Apache::loncommon::end_data_table().'</p>');
7755: } else {
7756: $r->print('<br /><span class="LC_warning">'.
7757: &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 />'.
7758: &mt("As a consequence, this user's submission history records two tries.").
7759: '</span><br />');
7760: }
7761: }
7762: }
1.543 raeburn 7763: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.140 albertel 7764: } continue {
1.330 albertel 7765: &Apache::lonxml::clear_problem_counter();
1.552 raeburn 7766: &Apache::lonnet::delenv('scantron.');
1.82 albertel 7767: }
1.140 albertel 7768: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.520 www 7769: &Apache::lonnet::remove_lock($lock);
1.172 albertel 7770: # my $lasttime = &Time::HiRes::time()-$start;
7771: # $r->print("<p>took $lasttime</p>");
1.140 albertel 7772:
1.200 albertel 7773: $r->print("</form>");
1.157 albertel 7774: return '';
1.75 albertel 7775: }
1.157 albertel 7776:
1.557 raeburn 7777: sub graders_resources_pass {
7778: my ($resources,$grader_partids_by_symb,$grader_randomlists_by_symb) = @_;
7779: if ((ref($resources) eq 'ARRAY') && (ref($grader_partids_by_symb)) &&
7780: (ref($grader_randomlists_by_symb) eq 'HASH')) {
7781: foreach my $resource (@{$resources}) {
7782: my $ressymb = $resource->symb();
7783: my ($analysis,$parts) =
7784: &scantron_partids_tograde($resource,$env{'request.course.id'},
7785: $env{'user.name'},$env{'user.domain'},1);
7786: $grader_partids_by_symb->{$ressymb} = $parts;
7787: if (ref($analysis) eq 'HASH') {
7788: if (ref($analysis->{'parts_withrandomlist'}) eq 'ARRAY') {
7789: $grader_randomlists_by_symb->{$ressymb} =
7790: $analysis->{'parts_withrandomlist'};
7791: }
7792: }
7793: }
7794: }
7795: return;
7796: }
7797:
1.542 raeburn 7798: sub grade_student_bubbles {
1.554 raeburn 7799: my ($r,$uname,$udom,$scan_record,$scancode,$resources,$parts) = @_;
7800: if (ref($resources) eq 'ARRAY') {
7801: my $count = 0;
7802: foreach my $resource (@{$resources}) {
7803: my $ressymb = $resource->symb();
7804: my %form = ('submitted' => 'scantron',
7805: 'grade_target' => 'grade',
7806: 'grade_username' => $uname,
7807: 'grade_domain' => $udom,
7808: 'grade_courseid' => $env{'request.course.id'},
7809: 'grade_symb' => $ressymb,
7810: 'CODE' => $scancode
7811: );
7812: if (ref($parts) eq 'HASH') {
7813: if (ref($parts->{$ressymb}) eq 'ARRAY') {
7814: foreach my $part (@{$parts->{$ressymb}}) {
7815: $form{'scantron_questnum_start.'.$part} =
7816: 1+$env{'form.scantron.first_bubble_line.'.$count};
7817: $count++;
7818: }
7819: }
7820: }
7821: my $result=&ssi_with_retries($resource->src(),$ssi_retries,%form);
7822: return 'ssi_error' if ($ssi_error);
7823: last if (&Apache::loncommon::connection_aborted($r));
7824: }
1.542 raeburn 7825: }
7826: return;
7827: }
7828:
1.157 albertel 7829: sub scantron_upload_scantron_data {
1.608 www 7830: my ($r,$symb)=@_;
1.565 raeburn 7831: my $dom = $env{'request.role.domain'};
7832: my $domdesc = &Apache::lonnet::domain($dom,'description');
7833: $r->print(&Apache::loncommon::coursebrowser_javascript($dom));
1.157 albertel 7834: my $select_link=&Apache::loncommon::selectcourse_link('rules','courseid',
1.181 albertel 7835: 'domainid',
1.565 raeburn 7836: 'coursename',$dom);
7837: my $syllabuslink = '<a href="javascript:ToSyllabus();">'.&mt('Syllabus').'</a>'.
7838: (' 'x2).&mt('(shows course personnel)');
1.608 www 7839: my $default_form_data=&defaultFormData($symb);
1.579 raeburn 7840: my $nofile_alert = &mt('Please use the browse button to select a file from your local directory.');
7841: 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 7842: $r->print(&Apache::lonhtmlcommon::scripttag('
1.157 albertel 7843: function checkUpload(formname) {
7844: if (formname.upfile.value == "") {
1.579 raeburn 7845: alert("'.$nofile_alert.'");
1.157 albertel 7846: return false;
7847: }
1.565 raeburn 7848: if (formname.courseid.value == "") {
1.579 raeburn 7849: alert("'.$nocourseid_alert.'");
1.565 raeburn 7850: return false;
7851: }
1.157 albertel 7852: formname.submit();
7853: }
1.565 raeburn 7854:
7855: function ToSyllabus() {
7856: var cdom = '."'$dom'".';
7857: var cnum = document.rules.courseid.value;
7858: if (cdom == "" || cdom == null) {
7859: return;
7860: }
7861: if (cnum == "" || cnum == null) {
7862: return;
7863: }
7864: syllwin=window.open("/public/"+cdom+"/"+cnum+"/syllabus","LONCAPASyllabus",
7865: "height=350,width=350,scrollbars=yes,menubar=no");
7866: return;
7867: }
7868:
1.597 wenzelju 7869: '));
7870: $r->print('
1.566 raeburn 7871: <h3>'.&mt('Send scanned bubblesheet data to a course').'</h3>
7872:
1.492 albertel 7873: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
1.565 raeburn 7874: '.$default_form_data.
7875: &Apache::lonhtmlcommon::start_pick_box().
7876: &Apache::lonhtmlcommon::row_title(&mt('Course ID')).
7877: '<input name="courseid" type="text" size="30" />'.$select_link.
7878: &Apache::lonhtmlcommon::row_closure().
7879: &Apache::lonhtmlcommon::row_title(&mt('Course Name')).
7880: '<input name="coursename" type="text" size="30" />'.$syllabuslink.
7881: &Apache::lonhtmlcommon::row_closure().
7882: &Apache::lonhtmlcommon::row_title(&mt('Domain')).
7883: '<input name="domainid" type="hidden" />'.$domdesc.
7884: &Apache::lonhtmlcommon::row_closure().
7885: &Apache::lonhtmlcommon::row_title(&mt('File to upload')).
7886: '<input type="file" name="upfile" size="50" />'.
7887: &Apache::lonhtmlcommon::row_closure(1).
7888: &Apache::lonhtmlcommon::end_pick_box().'<br />
7889:
1.492 albertel 7890: <input name="command" value="scantronupload_save" type="hidden" />
1.589 bisitz 7891: <input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
1.157 albertel 7892: </form>
1.492 albertel 7893: ');
1.157 albertel 7894: return '';
7895: }
7896:
1.423 albertel 7897:
1.157 albertel 7898: sub scantron_upload_scantron_data_save {
1.608 www 7899: my($r,$symb)=@_;
1.182 albertel 7900: my $doanotherupload=
7901: '<br /><form action="/adm/grades" method="post">'."\n".
7902: '<input type="hidden" name="command" value="scantronupload" />'."\n".
1.492 albertel 7903: '<input type="submit" name="submit" value="'.&mt('Do Another Upload').'" />'."\n".
1.182 albertel 7904: '</form>'."\n";
1.257 albertel 7905: if (!&Apache::lonnet::allowed('usc',$env{'form.domainid'}) &&
1.162 albertel 7906: !&Apache::lonnet::allowed('usc',
1.257 albertel 7907: $env{'form.domainid'}.'_'.$env{'form.courseid'})) {
1.575 www 7908: $r->print(&mt("You are not allowed to upload bubblesheet data to the requested course.")."<br />");
1.614 www 7909: unless ($symb) {
1.182 albertel 7910: $r->print($doanotherupload);
7911: }
1.162 albertel 7912: return '';
7913: }
1.257 albertel 7914: my %coursedata=&Apache::lonnet::coursedescription($env{'form.domainid'}.'_'.$env{'form.courseid'});
1.568 raeburn 7915: my $uploadedfile;
1.567 raeburn 7916: $r->print('<h3>'.&mt("Uploading file to [_1]",$coursedata{'description'}).'</h3>');
1.257 albertel 7917: if (length($env{'form.upfile'}) < 2) {
1.568 raeburn 7918: $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 7919: } else {
1.568 raeburn 7920: my $result =
7921: &Apache::lonnet::userfileupload('upfile','','scantron','','','',
7922: $env{'form.courseid'},$env{'form.domainid'});
7923: if ($result =~ m{^/uploaded/}) {
1.567 raeburn 7924: $r->print(&mt('[_1]Success:[_2] Successfully uploaded [_3] bytes of data into location: [_4]',
7925: '<span class="LC_success">','</span>',(length($env{'form.upfile'})-1),
7926: '<span class="LC_filename">'.$result.'</span>'));
1.568 raeburn 7927: ($uploadedfile) = ($result =~ m{/([^/]+)$});
1.567 raeburn 7928: $r->print(&validate_uploaded_scantron_file($env{'form.domainid'},
1.568 raeburn 7929: $env{'form.courseid'},$uploadedfile));
1.210 albertel 7930: } else {
1.567 raeburn 7931: $r->print(&mt('[_1]Error:[_2] An error ([_3]) occurred when attempting to upload the file, [_4]',
7932: '<span class="LC_error">','</span>',$result,
1.568 raeburn 7933: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'));
1.183 albertel 7934: }
7935: }
1.174 albertel 7936: if ($symb) {
1.612 www 7937: $r->print(&scantron_selectphase($r,$uploadedfile,$symb));
1.174 albertel 7938: } else {
1.182 albertel 7939: $r->print($doanotherupload);
1.174 albertel 7940: }
1.157 albertel 7941: return '';
7942: }
7943:
1.567 raeburn 7944: sub validate_uploaded_scantron_file {
7945: my ($cdom,$cname,$fname) = @_;
7946: my $scanlines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.$fname);
7947: my @lines;
7948: if ($scanlines ne '-1') {
7949: @lines=split("\n",$scanlines,-1);
7950: }
7951: my $output;
7952: if (@lines) {
7953: my (%counts,$max_match_format);
7954: my ($max_match_count,$max_match_pct) = (0,0);
7955: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cname);
7956: my %idmap = &username_to_idmap($classlist);
7957: foreach my $key (keys(%idmap)) {
7958: my $lckey = lc($key);
7959: $idmap{$lckey} = $idmap{$key};
7960: }
7961: my %unique_formats;
7962: my @formatlines = &get_scantronformat_file();
7963: foreach my $line (@formatlines) {
7964: chomp($line);
7965: my @config = split(/:/,$line);
7966: my $idstart = $config[5];
7967: my $idlength = $config[6];
7968: if (($idstart ne '') && ($idlength > 0)) {
7969: if (ref($unique_formats{$idstart.':'.$idlength}) eq 'ARRAY') {
7970: push(@{$unique_formats{$idstart.':'.$idlength}},$config[0].':'.$config[1]);
7971: } else {
7972: $unique_formats{$idstart.':'.$idlength} = [$config[0].':'.$config[1]];
7973: }
7974: }
7975: }
7976: foreach my $key (keys(%unique_formats)) {
7977: my ($idstart,$idlength) = split(':',$key);
7978: %{$counts{$key}} = (
7979: 'found' => 0,
7980: 'total' => 0,
7981: );
7982: foreach my $line (@lines) {
7983: next if ($line =~ /^#/);
7984: next if ($line =~ /^[\s\cz]*$/);
7985: my $id = substr($line,$idstart-1,$idlength);
7986: $id = lc($id);
7987: if (exists($idmap{$id})) {
7988: $counts{$key}{'found'} ++;
7989: }
7990: $counts{$key}{'total'} ++;
7991: }
7992: if ($counts{$key}{'total'}) {
7993: my $percent_match = (100*$counts{$key}{'found'})/($counts{$key}{'total'});
7994: if (($max_match_format eq '') || ($percent_match > $max_match_pct)) {
7995: $max_match_pct = $percent_match;
7996: $max_match_format = $key;
7997: $max_match_count = $counts{$key}{'total'};
7998: }
7999: }
8000: }
8001: if (ref($unique_formats{$max_match_format}) eq 'ARRAY') {
8002: my $format_descs;
8003: my $numwithformat = @{$unique_formats{$max_match_format}};
8004: for (my $i=0; $i<$numwithformat; $i++) {
8005: my ($name,$desc) = split(':',$unique_formats{$max_match_format}[$i]);
8006: if ($i<$numwithformat-2) {
8007: $format_descs .= '"<i>'.$desc.'</i>", ';
8008: } elsif ($i==$numwithformat-2) {
8009: $format_descs .= '"<i>'.$desc.'</i>" '.&mt('and').' ';
8010: } elsif ($i==$numwithformat-1) {
8011: $format_descs .= '"<i>'.$desc.'</i>"';
8012: }
8013: }
8014: my $showpct = sprintf("%.0f",$max_match_pct).'%';
8015: $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).
8016: '<br />'.&mt('A low percentage of matches results from one of the following:').'<ul>'.
8017: '<li>'.&mt('The file was uploaded to the wrong course').'</li>'.
8018: '<li>'.&mt('The data are not in the format expected for the domain: [_1]',
8019: '<i>'.$cdom.'</i>').'</li>'.
8020: '<li>'.&mt('Students did not bubble their IDs, or mis-bubbled them').'</li>'.
8021: '<li>'.&mt('The course roster is not up to date').'</li>'.
8022: '</ul>';
8023: }
8024: } else {
8025: $output = '<span class="LC_warning">'.&mt('Uploaded file contained no data').'</span>';
8026: }
8027: return $output;
8028: }
8029:
1.202 albertel 8030: sub valid_file {
8031: my ($requested_file)=@_;
8032: foreach my $filename (sort(&scantron_filenames())) {
8033: if ($requested_file eq $filename) { return 1; }
8034: }
8035: return 0;
8036: }
8037:
8038: sub scantron_download_scantron_data {
1.608 www 8039: my ($r,$symb)=@_;
8040: my $default_form_data=&defaultFormData($symb);
1.257 albertel 8041: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
8042: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
8043: my $file=$env{'form.scantron_selectfile'};
1.202 albertel 8044: if (! &valid_file($file)) {
1.492 albertel 8045: $r->print('
1.202 albertel 8046: <p>
1.492 albertel 8047: '.&mt('The requested file name was invalid.').'
1.202 albertel 8048: </p>
1.492 albertel 8049: ');
1.202 albertel 8050: return;
8051: }
8052: my $orig='/uploaded/'.$cdom.'/'.$cname.'/scantron_orig_'.$file;
8053: my $corrected='/uploaded/'.$cdom.'/'.$cname.'/scantron_corrected_'.$file;
8054: my $skipped='/uploaded/'.$cdom.'/'.$cname.'/scantron_skipped_'.$file;
8055: &Apache::lonnet::allowuploaded('/adm/grades',$orig);
8056: &Apache::lonnet::allowuploaded('/adm/grades',$corrected);
8057: &Apache::lonnet::allowuploaded('/adm/grades',$skipped);
1.492 albertel 8058: $r->print('
1.202 albertel 8059: <p>
1.492 albertel 8060: '.&mt('[_1]Original[_2] file as uploaded by the scantron office.',
8061: '<a href="'.$orig.'">','</a>').'
1.202 albertel 8062: </p>
8063: <p>
1.492 albertel 8064: '.&mt('[_1]Corrections[_2], a file of corrected records that were used in grading.',
8065: '<a href="'.$corrected.'">','</a>').'
1.202 albertel 8066: </p>
8067: <p>
1.492 albertel 8068: '.&mt('[_1]Skipped[_2], a file of records that were skipped.',
8069: '<a href="'.$skipped.'">','</a>').'
1.202 albertel 8070: </p>
1.492 albertel 8071: ');
1.202 albertel 8072: return '';
8073: }
1.157 albertel 8074:
1.523 raeburn 8075: sub checkscantron_results {
1.608 www 8076: my ($r,$symb) = @_;
1.523 raeburn 8077: if (!$symb) {return '';}
8078: my $cid = $env{'request.course.id'};
1.542 raeburn 8079: my %lettdig = &letter_to_digits();
1.523 raeburn 8080: my $numletts = scalar(keys(%lettdig));
8081: my $cnum = $env{'course.'.$cid.'.num'};
8082: my $cdom = $env{'course.'.$cid.'.domain'};
8083: my (undef, undef, $sequence) = &Apache::lonnet::decode_symb($env{'form.selectpage'});
8084: my %record;
8085: my %scantron_config =
8086: &Apache::grades::get_scantron_config($env{'form.scantron_format'});
8087: my ($scanlines,$scan_data)=&Apache::grades::scantron_getfile();
8088: my $classlist=&Apache::loncoursedata::get_classlist();
8089: my %idmap=&Apache::grades::username_to_idmap($classlist);
8090: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 8091: unless (ref($navmap)) {
8092: $r->print(&navmap_errormsg());
8093: return '';
8094: }
1.523 raeburn 8095: my $map=$navmap->getResourceByUrl($sequence);
1.557 raeburn 8096: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
8097: my (%grader_partids_by_symb,%grader_randomlists_by_symb);
8098: &graders_resources_pass(\@resources,\%grader_partids_by_symb, \%grader_randomlists_by_symb);
8099:
1.554 raeburn 8100: my ($uname,$udom);
1.523 raeburn 8101: my (%scandata,%lastname,%bylast);
8102: $r->print('
8103: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="checkscantron">'."\n");
8104:
8105: my @delayqueue;
8106: my %completedstudents;
8107:
8108: my $count=&Apache::grades::get_todo_count($scanlines,$scan_data);
1.581 www 8109: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Bubblesheet/Submissions Comparison Status',
8110: 'Progress of Bubblesheet Data/Submission Records Comparison',$count,
1.523 raeburn 8111: 'inline',undef,'checkscantron');
1.546 raeburn 8112: my ($username,$domain,$started);
1.582 raeburn 8113: my $nav_error;
8114: &scantron_get_maxbubble(\$nav_error); # Need the bubble lines array to parse.
8115: if ($nav_error) {
8116: $r->print(&navmap_errormsg());
8117: return '';
8118: }
1.523 raeburn 8119:
8120: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
8121: 'Processing first student');
8122: my $start=&Time::HiRes::time();
8123: my $i=-1;
8124:
8125: while ($i<$scanlines->{'count'}) {
8126: ($username,$domain,$uname)=('','','');
8127: $i++;
8128: my $line=&Apache::grades::scantron_get_line($scanlines,$scan_data,$i);
8129: if ($line=~/^[\s\cz]*$/) { next; }
8130: if ($started) {
8131: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
8132: 'last student');
8133: }
8134: $started=1;
8135: my $scan_record=
8136: &Apache::grades::scantron_parse_scanline($line,$i,\%scantron_config,
8137: $scan_data);
8138: unless ($uname=&Apache::grades::scantron_find_student($scan_record,$scan_data,
8139: \%idmap,$i)) {
8140: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
8141: 'Unable to find a student that matches',1);
8142: next;
8143: }
8144: if (exists $completedstudents{$uname}) {
8145: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
8146: 'Student '.$uname.' has multiple sheets',2);
8147: next;
8148: }
8149: my $pid = $scan_record->{'scantron.ID'};
8150: $lastname{$pid} = $scan_record->{'scantron.LastName'};
8151: push(@{$bylast{$lastname{$pid}}},$pid);
8152: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
8153: $scandata{$pid} = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
8154: chomp($scandata{$pid});
8155: $scandata{$pid} =~ s/\r$//;
8156: ($username,$domain)=split(/:/,$uname);
8157: my $counter = -1;
8158: foreach my $resource (@resources) {
1.557 raeburn 8159: my $parts;
1.554 raeburn 8160: my $ressymb = $resource->symb();
1.557 raeburn 8161: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
8162: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
8163: (my $analysis,$parts) =
8164: &scantron_partids_tograde($resource,$env{'request.course.id'},$username,$domain);
8165: } else {
8166: $parts = $grader_partids_by_symb{$ressymb};
8167: }
1.542 raeburn 8168: ($counter,my $recording) =
8169: &verify_scantron_grading($resource,$domain,$username,$cid,$counter,
1.554 raeburn 8170: $scandata{$pid},$parts,
1.542 raeburn 8171: \%scantron_config,\%lettdig,$numletts);
8172: $record{$pid} .= $recording;
1.523 raeburn 8173: }
8174: }
8175: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
8176: $r->print('<br />');
8177: my ($okstudents,$badstudents,$numstudents,$passed,$failed);
8178: $passed = 0;
8179: $failed = 0;
8180: $numstudents = 0;
8181: foreach my $last (sort(keys(%bylast))) {
8182: if (ref($bylast{$last}) eq 'ARRAY') {
8183: foreach my $pid (sort(@{$bylast{$last}})) {
8184: my $showscandata = $scandata{$pid};
8185: my $showrecord = $record{$pid};
8186: $showscandata =~ s/\s/ /g;
8187: $showrecord =~ s/\s/ /g;
8188: if ($scandata{$pid} eq $record{$pid}) {
8189: my $css_class = ($passed % 2)?'LC_odd_row':'LC_even_row';
8190: $okstudents .= '<tr class="'.$css_class.'">'.
1.581 www 8191: '<td>'.&mt('Bubblesheet').'</td><td>'.$showscandata.'</td><td rowspan="2">'.$last.'</td><td rowspan="2">'.$pid.'</td>'."\n".
1.523 raeburn 8192: '</tr>'."\n".
8193: '<tr class="'.$css_class.'">'."\n".
8194: '<td>Submissions</td><td>'.$showrecord.'</td></tr>'."\n";
8195: $passed ++;
8196: } else {
8197: my $css_class = ($failed % 2)?'LC_odd_row':'LC_even_row';
1.581 www 8198: $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 8199: '</tr>'."\n".
8200: '<tr class="'.$css_class.'">'."\n".
8201: '<td>Submissions</td><td><span class="LC_nobreak">'.$record{$pid}.'</span></td>'."\n".
8202: '</tr>'."\n";
8203: $failed ++;
8204: }
8205: $numstudents ++;
8206: }
8207: }
8208: }
1.572 www 8209: $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 8210: $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>');
8211: if ($passed) {
1.572 www 8212: $r->print(&mt('Students with exact correspondence between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 8213: $r->print(&Apache::loncommon::start_data_table()."\n".
8214: &Apache::loncommon::start_data_table_header_row()."\n".
8215: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
8216: &Apache::loncommon::end_data_table_header_row()."\n".
8217: $okstudents."\n".
8218: &Apache::loncommon::end_data_table().'<br />');
8219: }
8220: if ($failed) {
1.572 www 8221: $r->print(&mt('Students with differences between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 8222: $r->print(&Apache::loncommon::start_data_table()."\n".
8223: &Apache::loncommon::start_data_table_header_row()."\n".
8224: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
8225: &Apache::loncommon::end_data_table_header_row()."\n".
8226: $badstudents."\n".
8227: &Apache::loncommon::end_data_table()).'<br />'.
1.572 www 8228: &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 8229: }
1.614 www 8230: $r->print('</form><br />');
1.523 raeburn 8231: return;
8232: }
8233:
1.542 raeburn 8234: sub verify_scantron_grading {
1.554 raeburn 8235: my ($resource,$domain,$username,$cid,$counter,$scandata,$partids,
1.542 raeburn 8236: $scantron_config,$lettdig,$numletts) = @_;
8237: my ($record,%expected,%startpos);
8238: return ($counter,$record) if (!ref($resource));
8239: return ($counter,$record) if (!$resource->is_problem());
8240: my $symb = $resource->symb();
1.554 raeburn 8241: return ($counter,$record) if (ref($partids) ne 'ARRAY');
8242: foreach my $part_id (@{$partids}) {
1.542 raeburn 8243: $counter ++;
8244: $expected{$part_id} = 0;
8245: if ($env{"form.scantron.sub_bubblelines.$counter"}) {
8246: my @sub_lines = split(/,/,$env{"form.scantron.sub_bubblelines.$counter"});
8247: foreach my $item (@sub_lines) {
8248: $expected{$part_id} += $item;
8249: }
8250: } else {
8251: $expected{$part_id} = $env{"form.scantron.bubblelines.$counter"};
8252: }
8253: $startpos{$part_id} = $env{"form.scantron.first_bubble_line.$counter"};
8254: }
8255: if ($symb) {
8256: my %recorded;
8257: my (%returnhash) = &Apache::lonnet::restore($symb,$cid,$domain,$username);
8258: if ($returnhash{'version'}) {
8259: my %lasthash=();
8260: my $version;
8261: for ($version=1;$version<=$returnhash{'version'};$version++) {
8262: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
8263: $lasthash{$key}=$returnhash{$version.':'.$key};
8264: }
8265: }
8266: foreach my $key (keys(%lasthash)) {
8267: if ($key =~ /\.scantron$/) {
8268: my $value = &unescape($lasthash{$key});
8269: my ($part_id) = ($key =~ /^resource\.(.+)\.scantron$/);
8270: if ($value eq '') {
8271: for (my $i=0; $i<$expected{$part_id}; $i++) {
8272: for (my $j=0; $j<$scantron_config->{'length'}; $j++) {
8273: $recorded{$part_id} .= $scantron_config->{'Qoff'};
8274: }
8275: }
8276: } else {
8277: my @tocheck;
8278: my @items = split(//,$value);
8279: if (($scantron_config->{'Qon'} eq 'letter') ||
8280: ($scantron_config->{'Qon'} eq 'number')) {
8281: if (@items < $expected{$part_id}) {
8282: my $fragment = substr($scandata,$startpos{$part_id},$expected{$part_id});
8283: my @singles = split(//,$fragment);
8284: foreach my $pos (@singles) {
8285: if ($pos eq ' ') {
8286: push(@tocheck,$pos);
8287: } else {
8288: my $next = shift(@items);
8289: push(@tocheck,$next);
8290: }
8291: }
8292: } else {
8293: @tocheck = @items;
8294: }
8295: foreach my $letter (@tocheck) {
8296: if ($scantron_config->{'Qon'} eq 'letter') {
8297: if ($letter !~ /^[A-J]$/) {
8298: $letter = $scantron_config->{'Qoff'};
8299: }
8300: $recorded{$part_id} .= $letter;
8301: } elsif ($scantron_config->{'Qon'} eq 'number') {
8302: my $digit;
8303: if ($letter !~ /^[A-J]$/) {
8304: $digit = $scantron_config->{'Qoff'};
8305: } else {
8306: $digit = $lettdig->{$letter};
8307: }
8308: $recorded{$part_id} .= $digit;
8309: }
8310: }
8311: } else {
8312: @tocheck = @items;
8313: for (my $i=0; $i<$expected{$part_id}; $i++) {
8314: my $curr_sub = shift(@tocheck);
8315: my $digit;
8316: if ($curr_sub =~ /^[A-J]$/) {
8317: $digit = $lettdig->{$curr_sub}-1;
8318: }
8319: if ($curr_sub eq 'J') {
8320: $digit += scalar($numletts);
8321: }
8322: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
8323: if ($j == $digit) {
8324: $recorded{$part_id} .= $scantron_config->{'Qon'};
8325: } else {
8326: $recorded{$part_id} .= $scantron_config->{'Qoff'};
8327: }
8328: }
8329: }
8330: }
8331: }
8332: }
8333: }
8334: }
1.554 raeburn 8335: foreach my $part_id (@{$partids}) {
1.542 raeburn 8336: if ($recorded{$part_id} eq '') {
8337: for (my $i=0; $i<$expected{$part_id}; $i++) {
8338: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
8339: $recorded{$part_id} .= $scantron_config->{'Qoff'};
8340: }
8341: }
8342: }
8343: $record .= $recorded{$part_id};
8344: }
8345: }
8346: return ($counter,$record);
8347: }
8348:
8349: sub letter_to_digits {
8350: my %lettdig = (
8351: A => 1,
8352: B => 2,
8353: C => 3,
8354: D => 4,
8355: E => 5,
8356: F => 6,
8357: G => 7,
8358: H => 8,
8359: I => 9,
8360: J => 0,
8361: );
8362: return %lettdig;
8363: }
8364:
1.423 albertel 8365:
1.75 albertel 8366: #-------- end of section for handling grading scantron forms -------
8367: #
8368: #-------------------------------------------------------------------
8369:
1.72 ng 8370: #-------------------------- Menu interface -------------------------
8371: #
1.614 www 8372: #--- Href with symb and command ---
8373:
8374: sub href_symb_cmd {
8375: my ($symb,$cmd)=@_;
8376: return '/adm/grades?symb='.&HTML::Entities::encode(&Apache::lonenc::check_encrypt($symb),'<>&"').'&command='.$cmd;
1.72 ng 8377: }
8378:
1.443 banghart 8379: sub grading_menu {
1.608 www 8380: my ($request,$symb) = @_;
1.443 banghart 8381: if (!$symb) {return '';}
8382:
8383: my %fields = ('symb'=>&Apache::lonenc::check_encrypt($symb),
1.618 www 8384: 'command'=>'individual');
1.538 schulted 8385:
1.598 www 8386: my $url1a = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8387:
8388: $fields{'command'}='ungraded';
8389: my $url1b=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
8390:
8391: $fields{'command'}='table';
8392: my $url1c=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
8393:
8394: $fields{'command'}='all_for_one';
8395: my $url1d=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
8396:
1.621 www 8397: $fields{'command'}='downloadfilesselect';
8398: my $url1e=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
8399:
1.443 banghart 8400: $fields{'command'} = 'csvform';
1.538 schulted 8401: my $url2 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8402:
1.443 banghart 8403: $fields{'command'} = 'processclicker';
1.538 schulted 8404: my $url3 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8405:
1.443 banghart 8406: $fields{'command'} = 'scantron_selectphase';
1.538 schulted 8407: my $url4 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
1.602 www 8408:
8409: $fields{'command'} = 'initialverifyreceipt';
8410: my $url5 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
1.538 schulted 8411:
1.598 www 8412: my @menu = ({ categorytitle=>'Hand Grading',
1.538 schulted 8413: items =>[
1.598 www 8414: { linktext => 'Select individual students to grade',
8415: url => $url1a,
1.538 schulted 8416: permission => 'F',
8417: icon => 'edit-find-replace.png',
1.598 www 8418: linktitle => 'Grade current resource for a selection of students.'
8419: },
8420: { linktext => 'Grade ungraded submissions.',
8421: url => $url1b,
8422: permission => 'F',
8423: icon => 'edit-find-replace.png',
8424: linktitle => 'Grade all submissions that have not been graded yet.'
1.538 schulted 8425: },
1.598 www 8426:
8427: { linktext => 'Grading table',
8428: url => $url1c,
8429: permission => 'F',
8430: icon => 'edit-find-replace.png',
8431: linktitle => 'Grade current resource for all students.'
8432: },
1.615 www 8433: { linktext => 'Grade page/folder for one student',
1.598 www 8434: url => $url1d,
8435: permission => 'F',
8436: icon => 'edit-find-replace.png',
8437: linktitle => 'Grade all resources in current page/sequence/folder for one student.'
1.621 www 8438: },
8439: { linktext => 'Download submissions',
8440: url => $url1e,
8441: permission => 'F',
8442: icon => 'edit-find-replace.png',
8443: linktitle => 'Download all students submissions.'
1.598 www 8444: }]},
8445: { categorytitle=>'Automated Grading',
8446: items =>[
8447:
1.538 schulted 8448: { linktext => 'Upload Scores',
8449: url => $url2,
8450: permission => 'F',
8451: icon => 'uploadscores.png',
8452: linktitle => 'Specify a file containing the class scores for current resource.'
8453: },
8454: { linktext => 'Process Clicker',
8455: url => $url3,
8456: permission => 'F',
8457: icon => 'addClickerInfoFile.png',
8458: linktitle => 'Specify a file containing the clicker information for this resource.'
8459: },
1.587 raeburn 8460: { linktext => 'Grade/Manage/Review Bubblesheets',
1.538 schulted 8461: url => $url4,
8462: permission => 'F',
8463: icon => 'stat.png',
8464: linktitle => 'Grade scantron exams, upload/download scantron data files, and review previously graded scantron exams.'
1.602 www 8465: },
1.616 www 8466: { linktext => 'Verify Receipt Number',
1.602 www 8467: url => $url5,
8468: permission => 'F',
8469: icon => 'edit-find-replace.png',
8470: linktitle => 'Verify a system-generated receipt number for correct problem solution.'
8471: }
8472:
1.538 schulted 8473: ]
8474: });
8475:
1.443 banghart 8476: # Create the menu
8477: my $Str;
1.445 banghart 8478: $Str .= '<form method="post" action="" name="gradingMenu">';
8479: $Str .= '<input type="hidden" name="command" value="" />'.
1.618 www 8480: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.445 banghart 8481:
1.602 www 8482: $Str .= &Apache::lonhtmlcommon::generate_menu(@menu);
1.443 banghart 8483: return $Str;
8484: }
8485:
1.598 www 8486:
8487: sub ungraded {
8488: my ($request)=@_;
8489: &submit_options($request);
8490: }
8491:
1.599 www 8492: sub submit_options_sequence {
1.608 www 8493: my ($request,$symb) = @_;
1.599 www 8494: if (!$symb) {return '';}
1.600 www 8495: &commonJSfunctions($request);
8496: my $result;
1.599 www 8497:
1.600 www 8498: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.618 www 8499: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.600 www 8500: $result.='
8501: <h2>
1.615 www 8502: '.&mt('Grade page/folder for one student').'
1.601 www 8503: </h2>'.
8504: &selectfield(0).
8505: '<input type="hidden" name="command" value="pickStudentPage" />
1.600 www 8506: <div>
8507: <input type="submit" value="'.&mt('Next').' →" />
8508: </div>
8509: </div>
8510: </form>';
8511: return $result;
8512: }
8513:
8514: sub submit_options_table {
1.608 www 8515: my ($request,$symb) = @_;
1.600 www 8516: if (!$symb) {return '';}
1.599 www 8517: &commonJSfunctions($request);
8518: my $result;
8519:
8520: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.618 www 8521: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.599 www 8522:
8523: $result.='
8524: <h2>
1.600 www 8525: '.&mt('Grading table').'
1.601 www 8526: </h2>'.
8527: &selectfield(0).
8528: '<input type="hidden" name="command" value="viewgrades" />
1.599 www 8529: <div>
8530: <input type="submit" value="'.&mt('Next').' →" />
8531: </div>
8532: </div>
8533: </form>';
8534: return $result;
8535: }
1.443 banghart 8536:
1.621 www 8537: sub submit_options_download {
8538: my ($request,$symb) = @_;
8539: if (!$symb) {return '';}
8540:
8541: &commonJSfunctions($request);
8542:
8543: my $result='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
8544: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
8545: $result.='
8546: <h2>
8547: '.&mt('Select Students for Which to Download Submissions').'
8548: </h2>'.&selectfield(1).'
8549: <input type="hidden" name="command" value="downloadfileslink" />
8550: <input type="submit" value="'.&mt('Next').' →" />
8551: </div>
8552: </div>
1.600 www 8553:
8554:
1.621 www 8555: </form>';
8556: return $result;
8557: }
8558:
1.443 banghart 8559: #--- Displays the submissions first page -------
8560: sub submit_options {
1.608 www 8561: my ($request,$symb) = @_;
1.72 ng 8562: if (!$symb) {return '';}
8563:
1.118 ng 8564: &commonJSfunctions($request);
1.473 albertel 8565: my $result;
1.533 bisitz 8566:
1.72 ng 8567: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.618 www 8568: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.472 albertel 8569: $result.='
1.533 bisitz 8570: <h2>
1.600 www 8571: '.&mt('Select individual students to grade').'
1.601 www 8572: </h2>'.&selectfield(1).'
8573: <input type="hidden" name="command" value="submission" />
8574: <input type="submit" value="'.&mt('Next').' →" />
8575: </div>
8576: </div>
8577:
8578:
8579: </form>';
8580: return $result;
8581: }
1.533 bisitz 8582:
1.601 www 8583: sub selectfield {
8584: my ($full)=@_;
8585: my $result='<div class="LC_columnSection">
1.537 harmsja 8586:
1.533 bisitz 8587: <fieldset>
8588: <legend>
8589: '.&mt('Sections').'
8590: </legend>
1.601 www 8591: '.&Apache::lonstatistics::SectionSelect('section','multiple',5).'
1.533 bisitz 8592: </fieldset>
1.537 harmsja 8593:
1.533 bisitz 8594: <fieldset>
8595: <legend>
8596: '.&mt('Groups').'
8597: </legend>
8598: '.&Apache::lonstatistics::GroupSelect('group','multiple',5).'
8599: </fieldset>
1.537 harmsja 8600:
1.533 bisitz 8601: <fieldset>
8602: <legend>
8603: '.&mt('Access Status').'
8604: </legend>
1.601 www 8605: '.&Apache::lonhtmlcommon::StatusOptions(undef,undef,5,undef,'mult').'
8606: </fieldset>';
8607: if ($full) {
8608: $result.='
1.533 bisitz 8609: <fieldset>
8610: <legend>
8611: '.&mt('Submission Status').'
1.601 www 8612: </legend>'.
8613: &Apache::loncommon::select_form('all','submitonly',
8614: (&Apache::lonlocal::texthash(
8615: 'yes' => 'with submissions',
8616: 'queued' => 'in grading queue',
8617: 'graded' => 'with ungraded submissions',
8618: 'incorrect' => 'with incorrect submissions',
8619: 'all' => 'with any status'),
8620: 'select_form_order' => ['yes','queued','graded','incorrect','all'])).
8621: '</fieldset>';
8622: }
8623: $result.='</div><br />';
1.44 ng 8624: return $result;
1.2 albertel 8625: }
8626:
1.285 albertel 8627: sub reset_perm {
8628: undef(%perm);
8629: }
8630:
8631: sub init_perm {
8632: &reset_perm();
1.300 albertel 8633: foreach my $test_perm ('vgr','mgr','opa') {
8634:
8635: my $scope = $env{'request.course.id'};
8636: if (!($perm{$test_perm}=&Apache::lonnet::allowed($test_perm,$scope))) {
8637:
8638: $scope .= '/'.$env{'request.course.sec'};
8639: if ( $perm{$test_perm}=
8640: &Apache::lonnet::allowed($test_perm,$scope)) {
8641: $perm{$test_perm.'_section'}=$env{'request.course.sec'};
8642: } else {
8643: delete($perm{$test_perm});
8644: }
1.285 albertel 8645: }
8646: }
8647: }
8648:
1.400 www 8649: sub gather_clicker_ids {
1.408 albertel 8650: my %clicker_ids;
1.400 www 8651:
8652: my $classlist = &Apache::loncoursedata::get_classlist();
8653:
8654: # Set up a couple variables.
1.407 albertel 8655: my $username_idx = &Apache::loncoursedata::CL_SNAME();
8656: my $domain_idx = &Apache::loncoursedata::CL_SDOM();
1.438 www 8657: my $status_idx = &Apache::loncoursedata::CL_STATUS();
1.400 www 8658:
1.407 albertel 8659: foreach my $student (keys(%$classlist)) {
1.438 www 8660: if ($classlist->{$student}->[$status_idx] ne 'Active') { next; }
1.407 albertel 8661: my $username = $classlist->{$student}->[$username_idx];
8662: my $domain = $classlist->{$student}->[$domain_idx];
1.400 www 8663: my $clickers =
1.408 albertel 8664: (&Apache::lonnet::userenvironment($domain,$username,'clickers'))[1];
1.400 www 8665: foreach my $id (split(/\,/,$clickers)) {
1.414 www 8666: $id=~s/^[\#0]+//;
1.421 www 8667: $id=~s/[\-\:]//g;
1.407 albertel 8668: if (exists($clicker_ids{$id})) {
1.408 albertel 8669: $clicker_ids{$id}.=','.$username.':'.$domain;
1.400 www 8670: } else {
1.408 albertel 8671: $clicker_ids{$id}=$username.':'.$domain;
1.400 www 8672: }
8673: }
8674: }
1.407 albertel 8675: return %clicker_ids;
1.400 www 8676: }
8677:
1.402 www 8678: sub gather_adv_clicker_ids {
1.408 albertel 8679: my %clicker_ids;
1.402 www 8680: my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'};
8681: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
8682: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
1.409 albertel 8683: foreach my $element (sort(keys(%coursepersonnel))) {
1.402 www 8684: foreach my $person (split(/\,/,$coursepersonnel{$element})) {
8685: my ($puname,$pudom)=split(/\:/,$person);
8686: my $clickers =
1.408 albertel 8687: (&Apache::lonnet::userenvironment($pudom,$puname,'clickers'))[1];
1.405 www 8688: foreach my $id (split(/\,/,$clickers)) {
1.414 www 8689: $id=~s/^[\#0]+//;
1.421 www 8690: $id=~s/[\-\:]//g;
1.408 albertel 8691: if (exists($clicker_ids{$id})) {
8692: $clicker_ids{$id}.=','.$puname.':'.$pudom;
8693: } else {
8694: $clicker_ids{$id}=$puname.':'.$pudom;
8695: }
1.405 www 8696: }
1.402 www 8697: }
8698: }
1.407 albertel 8699: return %clicker_ids;
1.402 www 8700: }
8701:
1.413 www 8702: sub clicker_grading_parameters {
8703: return ('gradingmechanism' => 'scalar',
8704: 'upfiletype' => 'scalar',
8705: 'specificid' => 'scalar',
8706: 'pcorrect' => 'scalar',
8707: 'pincorrect' => 'scalar');
8708: }
8709:
1.400 www 8710: sub process_clicker {
1.608 www 8711: my ($r,$symb)=@_;
1.400 www 8712: if (!$symb) {return '';}
8713: my $result=&checkforfile_js();
8714: $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
8715: $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
1.538 schulted 8716: $result.=' <b>'.&mt('Specify a file containing the clicker information for this resource.').
8717: '</b></td></tr>'."\n";
1.601 www 8718: $result.='<tr bgcolor="#ffffe6"><td>'."\n";
1.413 www 8719: # Attempt to restore parameters from last session, set defaults if not present
8720: my %Saveable_Parameters=&clicker_grading_parameters();
8721: &Apache::loncommon::restore_course_settings('grades_clicker',
8722: \%Saveable_Parameters);
8723: if (!$env{'form.pcorrect'}) { $env{'form.pcorrect'}=100; }
8724: if (!$env{'form.pincorrect'}) { $env{'form.pincorrect'}=100; }
8725: if (!$env{'form.gradingmechanism'}) { $env{'form.gradingmechanism'}='attendance'; }
8726: if (!$env{'form.upfiletype'}) { $env{'form.upfiletype'}='iclicker'; }
8727:
8728: my %checked;
1.521 www 8729: foreach my $gradingmechanism ('attendance','personnel','specific','given') {
1.413 www 8730: if ($env{'form.gradingmechanism'} eq $gradingmechanism) {
1.569 bisitz 8731: $checked{$gradingmechanism}=' checked="checked"';
1.413 www 8732: }
8733: }
8734:
1.400 www 8735: my $upload=&mt("Upload File");
8736: my $type=&mt("Type");
1.402 www 8737: my $attendance=&mt("Award points just for participation");
8738: my $personnel=&mt("Correctness determined from response by course personnel");
1.414 www 8739: my $specific=&mt("Correctness determined from response with clicker ID(s)");
1.521 www 8740: my $given=&mt("Correctness determined from given list of answers").' '.
8741: '<font size="-2"><tt>('.&mt("Provide comma-separated list. Use '*' for any answer correct, '-' for skip").')</tt></font>';
1.402 www 8742: my $pcorrect=&mt("Percentage points for correct solution");
8743: my $pincorrect=&mt("Percentage points for incorrect solution");
1.413 www 8744: my $selectform=&Apache::loncommon::select_form($env{'form.upfiletype'},'upfiletype',
1.419 www 8745: ('iclicker' => 'i>clicker',
8746: 'interwrite' => 'interwrite PRS'));
1.418 albertel 8747: $symb = &Apache::lonenc::check_encrypt($symb);
1.597 wenzelju 8748: $result.= &Apache::lonhtmlcommon::scripttag(<<ENDUPFORM);
1.402 www 8749: function sanitycheck() {
8750: // Accept only integer percentages
8751: document.forms.gradesupload.pcorrect.value=Math.round(document.forms.gradesupload.pcorrect.value);
8752: document.forms.gradesupload.pincorrect.value=Math.round(document.forms.gradesupload.pincorrect.value);
8753: // Find out grading choice
8754: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
8755: if (document.forms.gradesupload.gradingmechanism[i].checked) {
8756: gradingchoice=document.forms.gradesupload.gradingmechanism[i].value;
8757: }
8758: }
8759: // By default, new choice equals user selection
8760: newgradingchoice=gradingchoice;
8761: // Not good to give more points for false answers than correct ones
8762: if (Math.round(document.forms.gradesupload.pcorrect.value)<Math.round(document.forms.gradesupload.pincorrect.value)) {
8763: document.forms.gradesupload.pcorrect.value=document.forms.gradesupload.pincorrect.value;
8764: }
8765: // If new choice is attendance only, and old choice was correctness-based, restore defaults
8766: if ((gradingchoice=='attendance') && (document.forms.gradesupload.waschecked.value!='attendance')) {
8767: document.forms.gradesupload.pcorrect.value=100;
8768: document.forms.gradesupload.pincorrect.value=100;
8769: }
8770: // If the values are different, cannot be attendance only
8771: if ((Math.round(document.forms.gradesupload.pcorrect.value)!=Math.round(document.forms.gradesupload.pincorrect.value)) &&
8772: (gradingchoice=='attendance')) {
8773: newgradingchoice='personnel';
8774: }
8775: // Change grading choice to new one
8776: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
8777: if (document.forms.gradesupload.gradingmechanism[i].value==newgradingchoice) {
8778: document.forms.gradesupload.gradingmechanism[i].checked=true;
8779: } else {
8780: document.forms.gradesupload.gradingmechanism[i].checked=false;
8781: }
8782: }
8783: // Remember the old state
8784: document.forms.gradesupload.waschecked.value=newgradingchoice;
8785: }
1.597 wenzelju 8786: ENDUPFORM
8787: $result.= <<ENDUPFORM;
1.400 www 8788: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
8789: <input type="hidden" name="symb" value="$symb" />
8790: <input type="hidden" name="command" value="processclickerfile" />
8791: <input type="file" name="upfile" size="50" />
8792: <br /><label>$type: $selectform</label>
1.589 bisitz 8793: <br /><label><input type="radio" name="gradingmechanism" value="attendance"$checked{'attendance'} onclick="sanitycheck()" />$attendance </label>
8794: <br /><label><input type="radio" name="gradingmechanism" value="personnel"$checked{'personnel'} onclick="sanitycheck()" />$personnel</label>
8795: <br /><label><input type="radio" name="gradingmechanism" value="specific"$checked{'specific'} onclick="sanitycheck()" />$specific </label>
1.414 www 8796: <input type="text" name="specificid" value="$env{'form.specificid'}" size="20" />
1.589 bisitz 8797: <br /><label><input type="radio" name="gradingmechanism" value="given"$checked{'given'} onclick="sanitycheck()" />$given </label>
1.521 www 8798: <br />
8799: <input type="text" name="givenanswer" size="50" />
1.413 www 8800: <input type="hidden" name="waschecked" value="$env{'form.gradingmechanism'}" />
1.589 bisitz 8801: <br /><label>$pcorrect: <input type="text" name="pcorrect" size="4" value="$env{'form.pcorrect'}" onchange="sanitycheck()" /></label>
8802: <br /><label>$pincorrect: <input type="text" name="pincorrect" size="4" value="$env{'form.pincorrect'}" onchange="sanitycheck()" /></label>
8803: <br /><input type="button" onclick="javascript:checkUpload(this.form);" value="$upload" />
1.597 wenzelju 8804: </form>'
1.400 www 8805: ENDUPFORM
8806: $result.='</td></tr></table>'."\n".
8807: '</td></tr></table><br /><br />'."\n";
8808: return $result;
8809: }
8810:
8811: sub process_clicker_file {
1.608 www 8812: my ($r,$symb)=@_;
1.400 www 8813: if (!$symb) {return '';}
1.413 www 8814:
8815: my %Saveable_Parameters=&clicker_grading_parameters();
8816: &Apache::loncommon::store_course_settings('grades_clicker',
8817: \%Saveable_Parameters);
1.598 www 8818: my $result='';
1.404 www 8819: if (($env{'form.gradingmechanism'} eq 'specific') && ($env{'form.specificid'}!~/\w/)) {
1.408 albertel 8820: $result.='<span class="LC_error">'.&mt('You need to specify a clicker ID for the correct answer').'</span>';
1.614 www 8821: return $result;
1.404 www 8822: }
1.522 www 8823: if (($env{'form.gradingmechanism'} eq 'given') && ($env{'form.givenanswer'}!~/\S/)) {
1.521 www 8824: $result.='<span class="LC_error">'.&mt('You need to specify the correct answer').'</span>';
1.614 www 8825: return $result;
1.521 www 8826: }
1.522 www 8827: my $foundgiven=0;
1.521 www 8828: if ($env{'form.gradingmechanism'} eq 'given') {
8829: $env{'form.givenanswer'}=~s/^\s*//gs;
8830: $env{'form.givenanswer'}=~s/\s*$//gs;
8831: $env{'form.givenanswer'}=~s/[^a-zA-Z0-9\.\*\-]+/\,/g;
8832: $env{'form.givenanswer'}=uc($env{'form.givenanswer'});
1.522 www 8833: my @answers=split(/\,/,$env{'form.givenanswer'});
8834: $foundgiven=$#answers+1;
1.521 www 8835: }
1.407 albertel 8836: my %clicker_ids=&gather_clicker_ids();
1.408 albertel 8837: my %correct_ids;
1.404 www 8838: if ($env{'form.gradingmechanism'} eq 'personnel') {
1.408 albertel 8839: %correct_ids=&gather_adv_clicker_ids();
1.404 www 8840: }
8841: if ($env{'form.gradingmechanism'} eq 'specific') {
1.414 www 8842: foreach my $correct_id (split(/[\s\,]/,$env{'form.specificid'})) {;
8843: $correct_id=~tr/a-z/A-Z/;
8844: $correct_id=~s/\s//gs;
8845: $correct_id=~s/^[\#0]+//;
1.421 www 8846: $correct_id=~s/[\-\:]//g;
1.414 www 8847: if ($correct_id) {
8848: $correct_ids{$correct_id}='specified';
8849: }
8850: }
1.400 www 8851: }
1.404 www 8852: if ($env{'form.gradingmechanism'} eq 'attendance') {
1.408 albertel 8853: $result.=&mt('Score based on attendance only');
1.521 www 8854: } elsif ($env{'form.gradingmechanism'} eq 'given') {
1.522 www 8855: $result.=&mt('Score based on [_1] ([_2] answers)','<tt>'.$env{'form.givenanswer'}.'</tt>',$foundgiven);
1.404 www 8856: } else {
1.408 albertel 8857: my $number=0;
1.411 www 8858: $result.='<p><b>'.&mt('Correctness determined by the following IDs').'</b>';
1.408 albertel 8859: foreach my $id (sort(keys(%correct_ids))) {
1.411 www 8860: $result.='<br /><tt>'.$id.'</tt> - ';
1.408 albertel 8861: if ($correct_ids{$id} eq 'specified') {
8862: $result.=&mt('specified');
8863: } else {
8864: my ($uname,$udom)=split(/\:/,$correct_ids{$id});
8865: $result.=&Apache::loncommon::plainname($uname,$udom);
8866: }
8867: $number++;
8868: }
1.411 www 8869: $result.="</p>\n";
1.408 albertel 8870: if ($number==0) {
8871: $result.='<span class="LC_error">'.&mt('No IDs found to determine correct answer').'</span>';
1.614 www 8872: return $result;
1.408 albertel 8873: }
1.404 www 8874: }
1.405 www 8875: if (length($env{'form.upfile'}) < 2) {
1.407 albertel 8876: $result.=&mt('[_1] Error: [_2] The file you attempted to upload, [_3] contained no information. Please check that you entered the correct filename.',
8877: '<span class="LC_error">',
8878: '</span>',
8879: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>');
1.614 www 8880: return $result;
1.405 www 8881: }
1.410 www 8882:
8883: # Were able to get all the info needed, now analyze the file
8884:
1.411 www 8885: $result.=&Apache::loncommon::studentbrowser_javascript();
1.418 albertel 8886: $symb = &Apache::lonenc::check_encrypt($symb);
1.410 www 8887: my $heading=&mt('Scanning clicker file');
8888: $result.=(<<ENDHEADER);
8889: <br /><table width="100%" border="0"><tr><td bgcolor="#777777">
8890: <table width="100%" border="0"><tr bgcolor="#e6ffff"><td>
8891: <b>$heading</b></td></tr><tr bgcolor=#ffffe6><td>
8892: <form method="post" action="/adm/grades" name="clickeranalysis">
8893: <input type="hidden" name="symb" value="$symb" />
8894: <input type="hidden" name="command" value="assignclickergrades" />
1.411 www 8895: <input type="hidden" name="gradingmechanism" value="$env{'form.gradingmechanism'}" />
8896: <input type="hidden" name="pcorrect" value="$env{'form.pcorrect'}" />
8897: <input type="hidden" name="pincorrect" value="$env{'form.pincorrect'}" />
1.410 www 8898: ENDHEADER
1.522 www 8899: if ($env{'form.gradingmechanism'} eq 'given') {
8900: $result.='<input type="hidden" name="correct:given" value="'.$env{'form.givenanswer'}.'" />';
8901: }
1.408 albertel 8902: my %responses;
8903: my @questiontitles;
1.405 www 8904: my $errormsg='';
8905: my $number=0;
8906: if ($env{'form.upfiletype'} eq 'iclicker') {
1.408 albertel 8907: ($errormsg,$number)=&iclicker_eval(\@questiontitles,\%responses);
1.406 www 8908: }
1.419 www 8909: if ($env{'form.upfiletype'} eq 'interwrite') {
8910: ($errormsg,$number)=&interwrite_eval(\@questiontitles,\%responses);
8911: }
1.411 www 8912: $result.='<br />'.&mt('Found [_1] question(s)',$number).'<br />'.
8913: '<input type="hidden" name="number" value="'.$number.'" />'.
8914: &mt('Awarding [_1] percent for correct and [_2] percent for incorrect responses',
8915: $env{'form.pcorrect'},$env{'form.pincorrect'}).
8916: '<br />';
1.522 www 8917: if (($env{'form.gradingmechanism'} eq 'given') && ($number!=$foundgiven)) {
8918: $result.='<span class="LC_error">'.&mt('Number of given answers does not agree with number of questions in file.').'</span>';
1.614 www 8919: return $result;
1.522 www 8920: }
1.414 www 8921: # Remember Question Titles
8922: # FIXME: Possibly need delimiter other than ":"
8923: for (my $i=0;$i<$number;$i++) {
8924: $result.='<input type="hidden" name="question:'.$i.'" value="'.
8925: &HTML::Entities::encode($questiontitles[$i],'"&<>').'" />';
8926: }
1.411 www 8927: my $correct_count=0;
8928: my $student_count=0;
8929: my $unknown_count=0;
1.414 www 8930: # Match answers with usernames
8931: # FIXME: Possibly need delimiter other than ":"
1.409 albertel 8932: foreach my $id (keys(%responses)) {
1.410 www 8933: if ($correct_ids{$id}) {
1.414 www 8934: $result.="\n".'<input type="hidden" name="correct:'.$correct_count.':'.$correct_ids{$id}.'" value="'.$responses{$id}.'" />';
1.411 www 8935: $correct_count++;
1.410 www 8936: } elsif ($clicker_ids{$id}) {
1.437 www 8937: if ($clicker_ids{$id}=~/\,/) {
8938: # More than one user with the same clicker!
8939: $result.="\n<hr />".&mt('Clicker registered more than once').": <tt>".$id."</tt><br />";
8940: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
8941: "<select name='multi".$id."'>";
8942: foreach my $reguser (sort(split(/\,/,$clicker_ids{$id}))) {
8943: $result.="<option value='".$reguser."'>".&Apache::loncommon::plainname(split(/\:/,$reguser)).' ('.$reguser.')</option>';
8944: }
8945: $result.='</select>';
8946: $unknown_count++;
8947: } else {
8948: # Good: found one and only one user with the right clicker
8949: $result.="\n".'<input type="hidden" name="student:'.$clicker_ids{$id}.'" value="'.$responses{$id}.'" />';
8950: $student_count++;
8951: }
1.410 www 8952: } else {
1.411 www 8953: $result.="\n<hr />".&mt('Unregistered Clicker')." <tt>".$id."</tt><br />";
8954: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
8955: "\n".&mt("Username").": <input type='text' name='uname".$id."' /> ".
8956: "\n".&mt("Domain").": ".
8957: &Apache::loncommon::select_dom_form($env{'course.'.$env{'request.course.id'}.'.domain'},'udom'.$id).' '.
8958: &Apache::loncommon::selectstudent_link('clickeranalysis','uname'.$id,'udom'.$id);
8959: $unknown_count++;
1.410 www 8960: }
1.405 www 8961: }
1.412 www 8962: $result.='<hr />'.
8963: &mt('Found [_1] registered and [_2] unregistered clickers.',$student_count,$unknown_count);
1.521 www 8964: if (($env{'form.gradingmechanism'} ne 'attendance') && ($env{'form.gradingmechanism'} ne 'given')) {
1.412 www 8965: if ($correct_count==0) {
8966: $errormsg.="Found no correct answers answers for grading!";
8967: } elsif ($correct_count>1) {
1.414 www 8968: $result.='<br /><span class="LC_warning">'.&mt("Found [_1] entries for grading!",$correct_count).'</span>';
1.412 www 8969: }
8970: }
1.428 www 8971: if ($number<1) {
8972: $errormsg.="Found no questions.";
8973: }
1.412 www 8974: if ($errormsg) {
8975: $result.='<br /><span class="LC_error">'.&mt($errormsg).'</span>';
8976: } else {
8977: $result.='<br /><input type="submit" name="finalize" value="'.&mt('Finalize Grading').'" />';
8978: }
8979: $result.='</form></td></tr></table>'."\n".
1.410 www 8980: '</td></tr></table><br /><br />'."\n";
1.614 www 8981: return $result;
1.400 www 8982: }
8983:
1.405 www 8984: sub iclicker_eval {
1.406 www 8985: my ($questiontitles,$responses)=@_;
1.405 www 8986: my $number=0;
8987: my $errormsg='';
8988: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
1.410 www 8989: my %components=&Apache::loncommon::record_sep($line);
8990: my @entries=map {$components{$_}} (sort(keys(%components)));
1.408 albertel 8991: if ($entries[0] eq 'Question') {
8992: for (my $i=3;$i<$#entries;$i+=6) {
8993: $$questiontitles[$number]=$entries[$i];
8994: $number++;
8995: }
8996: }
8997: if ($entries[0]=~/^\#/) {
8998: my $id=$entries[0];
8999: my @idresponses;
9000: $id=~s/^[\#0]+//;
9001: for (my $i=0;$i<$number;$i++) {
9002: my $idx=3+$i*6;
9003: push(@idresponses,$entries[$idx]);
9004: }
9005: $$responses{$id}=join(',',@idresponses);
9006: }
1.405 www 9007: }
9008: return ($errormsg,$number);
9009: }
9010:
1.419 www 9011: sub interwrite_eval {
9012: my ($questiontitles,$responses)=@_;
9013: my $number=0;
9014: my $errormsg='';
1.420 www 9015: my $skipline=1;
9016: my $questionnumber=0;
9017: my %idresponses=();
1.419 www 9018: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
9019: my %components=&Apache::loncommon::record_sep($line);
9020: my @entries=map {$components{$_}} (sort(keys(%components)));
1.420 www 9021: if ($entries[1] eq 'Time') { $skipline=0; next; }
9022: if ($entries[1] eq 'Response') { $skipline=1; }
9023: next if $skipline;
9024: if ($entries[0]!=$questionnumber) {
9025: $questionnumber=$entries[0];
9026: $$questiontitles[$number]=&mt('Question [_1]',$questionnumber);
9027: $number++;
1.419 www 9028: }
1.420 www 9029: my $id=$entries[4];
9030: $id=~s/^[\#0]+//;
1.421 www 9031: $id=~s/^v\d*\://i;
9032: $id=~s/[\-\:]//g;
1.420 www 9033: $idresponses{$id}[$number]=$entries[6];
9034: }
1.524 raeburn 9035: foreach my $id (keys(%idresponses)) {
1.420 www 9036: $$responses{$id}=join(',',@{$idresponses{$id}});
9037: $$responses{$id}=~s/^\s*\,//;
1.419 www 9038: }
9039: return ($errormsg,$number);
9040: }
9041:
1.414 www 9042: sub assign_clicker_grades {
1.608 www 9043: my ($r,$symb)=@_;
1.414 www 9044: if (!$symb) {return '';}
1.416 www 9045: # See which part we are saving to
1.582 raeburn 9046: my $res_error;
9047: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
9048: if ($res_error) {
9049: return &navmap_errormsg();
9050: }
1.416 www 9051: # FIXME: This should probably look for the first handgradeable part
9052: my $part=$$partlist[0];
9053: # Start screen output
1.598 www 9054: my $result='';
1.416 www 9055:
1.414 www 9056: my $heading=&mt('Assigning grades based on clicker file');
9057: $result.=(<<ENDHEADER);
9058: <br /><table width="100%" border="0"><tr><td bgcolor="#777777">
9059: <table width="100%" border="0"><tr bgcolor="#e6ffff"><td>
9060: <b>$heading</b></td></tr><tr bgcolor=#ffffe6><td>
9061: ENDHEADER
9062: # Get correct result
9063: # FIXME: Possibly need delimiter other than ":"
9064: my @correct=();
1.415 www 9065: my $gradingmechanism=$env{'form.gradingmechanism'};
9066: my $number=$env{'form.number'};
9067: if ($gradingmechanism ne 'attendance') {
1.414 www 9068: foreach my $key (keys(%env)) {
9069: if ($key=~/^form\.correct\:/) {
9070: my @input=split(/\,/,$env{$key});
9071: for (my $i=0;$i<=$#input;$i++) {
9072: if (($correct[$i]) && ($input[$i]) &&
9073: ($correct[$i] ne $input[$i])) {
9074: $result.='<br /><span class="LC_warning">'.
9075: &mt('More than one correct result given for question "[_1]": [_2] versus [_3].',
9076: $env{'form.question:'.$i},$correct[$i],$input[$i]).'</span>';
9077: } elsif ($input[$i]) {
9078: $correct[$i]=$input[$i];
9079: }
9080: }
9081: }
9082: }
1.415 www 9083: for (my $i=0;$i<$number;$i++) {
1.414 www 9084: if (!$correct[$i]) {
9085: $result.='<br /><span class="LC_error">'.
9086: &mt('No correct result given for question "[_1]"!',
9087: $env{'form.question:'.$i}).'</span>';
9088: }
9089: }
9090: $result.='<br />'.&mt("Correct answer: [_1]",join(', ',map { ($_?$_:'-') } @correct));
9091: }
9092: # Start grading
1.415 www 9093: my $pcorrect=$env{'form.pcorrect'};
9094: my $pincorrect=$env{'form.pincorrect'};
1.416 www 9095: my $storecount=0;
1.415 www 9096: foreach my $key (keys(%env)) {
1.420 www 9097: my $user='';
1.415 www 9098: if ($key=~/^form\.student\:(.*)$/) {
1.420 www 9099: $user=$1;
9100: }
9101: if ($key=~/^form\.unknown\:(.*)$/) {
9102: my $id=$1;
9103: if (($env{'form.uname'.$id}) && ($env{'form.udom'.$id})) {
9104: $user=$env{'form.uname'.$id}.':'.$env{'form.udom'.$id};
1.437 www 9105: } elsif ($env{'form.multi'.$id}) {
9106: $user=$env{'form.multi'.$id};
1.420 www 9107: }
9108: }
9109: if ($user) {
1.415 www 9110: my @answer=split(/\,/,$env{$key});
9111: my $sum=0;
1.522 www 9112: my $realnumber=$number;
1.415 www 9113: for (my $i=0;$i<$number;$i++) {
1.576 www 9114: if ($correct[$i] eq '-') {
9115: $realnumber--;
9116: } elsif ($answer[$i]) {
1.415 www 9117: if ($gradingmechanism eq 'attendance') {
9118: $sum+=$pcorrect;
1.576 www 9119: } elsif ($correct[$i] eq '*') {
1.522 www 9120: $sum+=$pcorrect;
1.415 www 9121: } else {
9122: if ($answer[$i] eq $correct[$i]) {
9123: $sum+=$pcorrect;
9124: } else {
9125: $sum+=$pincorrect;
9126: }
9127: }
9128: }
9129: }
1.522 www 9130: my $ave=$sum/(100*$realnumber);
1.416 www 9131: # Store
9132: my ($username,$domain)=split(/\:/,$user);
9133: my %grades=();
9134: $grades{"resource.$part.solved"}='correct_by_override';
9135: $grades{"resource.$part.awarded"}=$ave;
9136: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
9137: my $returncode=&Apache::lonnet::cstore(\%grades,$symb,
9138: $env{'request.course.id'},
9139: $domain,$username);
9140: if ($returncode ne 'ok') {
9141: $result.="<br /><span class=\"LC_error\">Failed to save student $username:$domain. Message when trying to save was ($returncode)</span>";
9142: } else {
9143: $storecount++;
9144: }
1.415 www 9145: }
9146: }
9147: # We are done
1.549 hauer 9148: $result.='<br />'.&mt('Successfully stored grades for [quant,_1,student].',$storecount).
1.416 www 9149: '</td></tr></table>'."\n".
1.414 www 9150: '</td></tr></table><br /><br />'."\n";
1.614 www 9151: return $result;
1.414 www 9152: }
9153:
1.582 raeburn 9154: sub navmap_errormsg {
9155: return '<div class="LC_error">'.
9156: &mt('An error occurred retrieving information about resources in the course.').'<br />'.
1.595 raeburn 9157: &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 9158: '</div>';
9159: }
1.607 droeschl 9160:
1.609 www 9161: sub startpage {
1.613 www 9162: my ($r,$symb,$crumbs,$onlyfolderflag,$nodisplayflag) = @_;
1.614 www 9163: unshift(@$crumbs,{href=>&href_symb_cmd($symb,'gradingmenu'),text=>"Grading"});
1.607 droeschl 9164: $r->print(&Apache::loncommon::start_page('Grading',undef,
1.610 www 9165: {'bread_crumbs' => $crumbs}));
1.613 www 9166: unless ($nodisplayflag) {
9167: $r->print(&Apache::lonhtmlcommon::resource_info_box($symb,$onlyfolderflag));
9168: }
1.607 droeschl 9169: }
1.582 raeburn 9170:
1.622 www 9171: sub select_problem {
9172: my ($r)=@_;
1.623 ! www 9173: $r->print('<h2>'.&mt('Select the problem or one of the problems you want to grade').'</h2><form action="/adm/grades">');
1.622 www 9174: $r->print(&Apache::lonstathelpers::problem_selector('.',undef,1));
9175: $r->print('<input type="hidden" name="command" value="gradingmenu" />');
9176: $r->print('<input type="submit" value="'.&mt('Next').' →" /></form>');
9177: }
9178:
1.1 albertel 9179: sub handler {
1.41 ng 9180: my $request=$_[0];
1.434 albertel 9181: &reset_caches();
1.257 albertel 9182: if ($env{'browser.mathml'}) {
1.141 www 9183: &Apache::loncommon::content_type($request,'text/xml');
1.41 ng 9184: } else {
1.141 www 9185: &Apache::loncommon::content_type($request,'text/html');
1.41 ng 9186: }
9187: $request->send_http_header;
1.44 ng 9188: return '' if $request->header_only;
1.41 ng 9189: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.608 www 9190:
9191: # see what command we need to execute
9192:
1.160 albertel 9193: my @commands=&Apache::loncommon::get_env_multiple('form.command');
9194: my $command=$commands[0];
1.447 foxr 9195:
1.160 albertel 9196: if ($#commands > 0) {
9197: &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands));
9198: }
1.608 www 9199:
9200: # see what the symb is
9201:
9202: my $symb=$env{'form.symb'};
9203: unless ($symb) {
9204: (my $url=$env{'form.url'}) =~ s-^https*://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
9205: $symb=&Apache::lonnet::symbread($url);
9206: }
9207: &Apache::lonenc::check_decrypt(\$symb);
9208:
1.513 foxr 9209: $ssi_error = 0;
1.622 www 9210: if ($symb eq '' || $command eq '') {
1.601 www 9211: #
9212: # Not called from a resource
9213: #
1.622 www 9214: &startpage($request,undef,[],1,1);
9215: &select_problem($request);
1.41 ng 9216: } else {
1.285 albertel 9217: &init_perm();
1.104 albertel 9218: if ($command eq 'submission' && $perm{'vgr'}) {
1.608 www 9219: &startpage($request,$symb,[{href=>"", text=>"Student Submissions"}]);
1.611 www 9220: ($env{'form.student'} eq '' ? &listStudents($request,$symb) : &submission($request,0,0,$symb));
1.103 albertel 9221: } elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) {
1.615 www 9222: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'all_for_one'),text=>'Grade page/folder for one student'},
9223: {href=>'',text=>'Select student'}],1,1);
1.608 www 9224: &pickStudentPage($request,$symb);
1.103 albertel 9225: } elsif ($command eq 'displayPage' && $perm{'vgr'}) {
1.615 www 9226: &startpage($request,$symb,
9227: [{href=>&href_symb_cmd($symb,'all_for_one'),text=>'Grade page/folder for one student'},
9228: {href=>'',text=>'Select student'},
9229: {href=>'',text=>'Grade student'}],1,1);
1.608 www 9230: &displayPage($request,$symb);
1.104 albertel 9231: } elsif ($command eq 'gradeByPage' && $perm{'mgr'}) {
1.616 www 9232: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'all_for_one'),text=>'Grade page/folder for one student'},
9233: {href=>'',text=>'Select student'},
9234: {href=>'',text=>'Grade student'},
9235: {href=>'',text=>'Store grades'}],1,1);
1.608 www 9236: &updateGradeByPage($request,$symb);
1.104 albertel 9237: } elsif ($command eq 'processGroup' && $perm{'vgr'}) {
1.619 www 9238: &startpage($request,$symb,[{href=>'',text=>'...'},
9239: {href=>'',text=>'Modify grades'}]);
1.608 www 9240: &processGroup($request,$symb);
1.104 albertel 9241: } elsif ($command eq 'gradingmenu' && $perm{'vgr'}) {
1.608 www 9242: &startpage($request,$symb);
9243: $request->print(&grading_menu($request,$symb));
1.598 www 9244: } elsif ($command eq 'individual' && $perm{'vgr'}) {
1.617 www 9245: &startpage($request,$symb,[{href=>'',text=>'Select individual students to grade'}]);
1.608 www 9246: $request->print(&submit_options($request,$symb));
1.598 www 9247: } elsif ($command eq 'ungraded' && $perm{'vgr'}) {
1.617 www 9248: &startpage($request,$symb,[{href=>'',text=>'Grade ungraded submissions'}]);
9249: $request->print(&listStudents($request,$symb,'graded'));
1.598 www 9250: } elsif ($command eq 'table' && $perm{'vgr'}) {
1.614 www 9251: &startpage($request,$symb,[{href=>"", text=>"Grading table"}]);
1.611 www 9252: $request->print(&submit_options_table($request,$symb));
1.598 www 9253: } elsif ($command eq 'all_for_one' && $perm{'vgr'}) {
1.615 www 9254: &startpage($request,$symb,[{href=>'',text=>'Grade page/folder for one student'}],1,1);
1.608 www 9255: $request->print(&submit_options_sequence($request,$symb));
1.104 albertel 9256: } elsif ($command eq 'viewgrades' && $perm{'vgr'}) {
1.614 www 9257: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,"table"), text=>"Grading table"},{href=>'', text=>"Modify grades"}]);
1.608 www 9258: $request->print(&viewgrades($request,$symb));
1.104 albertel 9259: } elsif ($command eq 'handgrade' && $perm{'mgr'}) {
1.620 www 9260: &startpage($request,$symb,[{href=>'',text=>'...'},
9261: {href=>'',text=>'Store grades'}]);
1.608 www 9262: $request->print(&processHandGrade($request,$symb));
1.106 albertel 9263: } elsif ($command eq 'editgrades' && $perm{'mgr'}) {
1.614 www 9264: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,"table"), text=>"Grading table"},
9265: {href=>&href_symb_cmd($symb,'viewgrades').'&group=all§ion=all&Status=Active',
9266: text=>"Modify grades"},
9267: {href=>'', text=>"Store grades"}]);
1.608 www 9268: $request->print(&editgrades($request,$symb));
1.602 www 9269: } elsif ($command eq 'initialverifyreceipt' && $perm{'vgr'}) {
1.616 www 9270: &startpage($request,$symb,[{href=>'',text=>'Verify Receipt Number'}]);
1.611 www 9271: $request->print(&initialverifyreceipt($request,$symb));
1.106 albertel 9272: } elsif ($command eq 'verify' && $perm{'vgr'}) {
1.616 www 9273: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,"initialverifyreceipt"),text=>'Verify Receipt Number'},
9274: {href=>'',text=>'Verification Result'}]);
1.608 www 9275: $request->print(&verifyreceipt($request,$symb));
1.400 www 9276: } elsif ($command eq 'processclicker' && $perm{'mgr'}) {
1.615 www 9277: &startpage($request,$symb,[{href=>'', text=>'Process clicker'}]);
1.608 www 9278: $request->print(&process_clicker($request,$symb));
1.400 www 9279: } elsif ($command eq 'processclickerfile' && $perm{'mgr'}) {
1.615 www 9280: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'processclicker'), text=>'Process clicker'},
9281: {href=>'', text=>'Process clicker file'}]);
1.608 www 9282: $request->print(&process_clicker_file($request,$symb));
1.414 www 9283: } elsif ($command eq 'assignclickergrades' && $perm{'mgr'}) {
1.615 www 9284: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'processclicker'), text=>'Process clicker'},
9285: {href=>'', text=>'Process clicker file'},
9286: {href=>'', text=>'Store grades'}]);
1.608 www 9287: $request->print(&assign_clicker_grades($request,$symb));
1.106 albertel 9288: } elsif ($command eq 'csvform' && $perm{'mgr'}) {
1.616 www 9289: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 9290: $request->print(&upcsvScores_form($request,$symb));
1.106 albertel 9291: } elsif ($command eq 'csvupload' && $perm{'mgr'}) {
1.616 www 9292: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 9293: $request->print(&csvupload($request,$symb));
1.106 albertel 9294: } elsif ($command eq 'csvuploadmap' && $perm{'mgr'} ) {
1.616 www 9295: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 9296: $request->print(&csvuploadmap($request,$symb));
1.246 albertel 9297: } elsif ($command eq 'csvuploadoptions' && $perm{'mgr'}) {
1.257 albertel 9298: if ($env{'form.associate'} ne 'Reverse Association') {
1.616 www 9299: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 9300: $request->print(&csvuploadoptions($request,$symb));
1.41 ng 9301: } else {
1.257 albertel 9302: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
9303: $env{'form.upfile_associate'} = 'reverse';
1.41 ng 9304: } else {
1.257 albertel 9305: $env{'form.upfile_associate'} = 'forward';
1.41 ng 9306: }
1.616 www 9307: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 9308: $request->print(&csvuploadmap($request,$symb));
1.41 ng 9309: }
1.246 albertel 9310: } elsif ($command eq 'csvuploadassign' && $perm{'mgr'} ) {
1.616 www 9311: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 9312: $request->print(&csvuploadassign($request,$symb));
1.106 albertel 9313: } elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
1.616 www 9314: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.612 www 9315: $request->print(&scantron_selectphase($request,undef,$symb));
1.203 albertel 9316: } elsif ($command eq 'scantron_warning' && $perm{'mgr'}) {
1.616 www 9317: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 9318: $request->print(&scantron_do_warning($request,$symb));
1.142 albertel 9319: } elsif ($command eq 'scantron_validate' && $perm{'mgr'}) {
1.616 www 9320: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 9321: $request->print(&scantron_validate_file($request,$symb));
1.106 albertel 9322: } elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
1.616 www 9323: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 9324: $request->print(&scantron_process_students($request,$symb));
1.157 albertel 9325: } elsif ($command eq 'scantronupload' &&
1.257 albertel 9326: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
9327: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.616 www 9328: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 9329: $request->print(&scantron_upload_scantron_data($request,$symb));
1.157 albertel 9330: } elsif ($command eq 'scantronupload_save' &&
1.257 albertel 9331: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
9332: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.616 www 9333: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 9334: $request->print(&scantron_upload_scantron_data_save($request,$symb));
1.202 albertel 9335: } elsif ($command eq 'scantron_download' &&
1.257 albertel 9336: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.616 www 9337: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 9338: $request->print(&scantron_download_scantron_data($request,$symb));
1.523 raeburn 9339: } elsif ($command eq 'checksubmissions' && $perm{'vgr'}) {
1.616 www 9340: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.621 www 9341: $request->print(&checkscantron_results($request,$symb));
9342: } elsif ($command eq 'downloadfilesselect' && $perm{'vgr'}) {
9343: &startpage($request,$symb,[{href=>'', text=>'Select which submissions to download'}]);
9344: $request->print(&submit_options_download($request,$symb));
9345: } elsif ($command eq 'downloadfileslink' && $perm{'vgr'}) {
9346: &startpage($request,$symb,
9347: [{href=>&href_symb_cmd($symb,'downloadfilesselect'), text=>'Select which submissions to download'},
9348: {href=>'', text=>'Download submissions'}]);
9349: &submit_download_link($request,$symb);
1.106 albertel 9350: } elsif ($command) {
1.620 www 9351: &startpage($request,$symb,[{href=>'', text=>'Access denied'}]);
1.562 bisitz 9352: $request->print('<p class="LC_error">'.&mt('Access Denied ([_1])',$command).'</p>');
1.26 albertel 9353: }
1.2 albertel 9354: }
1.513 foxr 9355: if ($ssi_error) {
9356: &ssi_print_error($request);
9357: }
1.353 albertel 9358: $request->print(&Apache::loncommon::end_page());
1.434 albertel 9359: &reset_caches();
1.44 ng 9360: return '';
9361: }
9362:
1.1 albertel 9363: 1;
9364:
1.13 albertel 9365: __END__;
1.531 jms 9366:
9367:
9368: =head1 NAME
9369:
9370: Apache::grades
9371:
9372: =head1 SYNOPSIS
9373:
9374: Handles the viewing of grades.
9375:
9376: This is part of the LearningOnline Network with CAPA project
9377: described at http://www.lon-capa.org.
9378:
9379: =head1 OVERVIEW
9380:
9381: Do an ssi with retries:
9382: While I'd love to factor out this with the vesrion in lonprintout,
9383: 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
9384: I'm not quite ready to invent (e.g. an ssi_with_retry object).
9385:
9386: At least the logic that drives this has been pulled out into loncommon.
9387:
9388:
9389:
9390: ssi_with_retries - Does the server side include of a resource.
9391: if the ssi call returns an error we'll retry it up to
9392: the number of times requested by the caller.
9393: If we still have a proble, no text is appended to the
9394: output and we set some global variables.
9395: to indicate to the caller an SSI error occurred.
9396: All of this is supposed to deal with the issues described
9397: in LonCAPA BZ 5631 see:
9398: http://bugs.lon-capa.org/show_bug.cgi?id=5631
9399: by informing the user that this happened.
9400:
9401: Parameters:
9402: resource - The resource to include. This is passed directly, without
9403: interpretation to lonnet::ssi.
9404: form - The form hash parameters that guide the interpretation of the resource
9405:
9406: retries - Number of retries allowed before giving up completely.
9407: Returns:
9408: On success, returns the rendered resource identified by the resource parameter.
9409: Side Effects:
9410: The following global variables can be set:
9411: ssi_error - If an unrecoverable error occurred this becomes true.
9412: It is up to the caller to initialize this to false
9413: if desired.
9414: ssi_error_resource - If an unrecoverable error occurred, this is the value
9415: of the resource that could not be rendered by the ssi
9416: call.
9417: ssi_error_message - The error string fetched from the ssi response
9418: in the event of an error.
9419:
9420:
9421: =head1 HANDLER SUBROUTINE
9422:
9423: ssi_with_retries()
9424:
9425: =head1 SUBROUTINES
9426:
9427: =over
9428:
9429: =item scantron_get_correction() :
9430:
9431: Builds the interface screen to interact with the operator to fix a
9432: specific error condition in a specific scanline
9433:
9434: Arguments:
9435: $r - Apache request object
9436: $i - number of the current scanline
9437: $scan_record - hash ref as returned from &scantron_parse_scanline()
9438: $scan_config - hash ref as returned from &get_scantron_config()
9439: $line - full contents of the current scanline
9440: $error - error condition, valid values are
9441: 'incorrectCODE', 'duplicateCODE',
9442: 'doublebubble', 'missingbubble',
9443: 'duplicateID', 'incorrectID'
9444: $arg - extra information needed
9445: For errors:
9446: - duplicateID - paper number that this studentID was seen before on
9447: - duplicateCODE - array ref of the paper numbers this CODE was
9448: seen on before
9449: - incorrectCODE - current incorrect CODE
9450: - doublebubble - array ref of the bubble lines that have double
9451: bubble errors
9452: - missingbubble - array ref of the bubble lines that have missing
9453: bubble errors
9454:
9455: =item scantron_get_maxbubble() :
9456:
1.582 raeburn 9457: Arguments:
9458: $nav_error - Reference to scalar which is a flag to indicate a
9459: failure to retrieve a navmap object.
9460: if $nav_error is set to 1 by scantron_get_maxbubble(), the
9461: calling routine should trap the error condition and display the warning
9462: found in &navmap_errormsg().
9463:
1.531 jms 9464: Returns the maximum number of bubble lines that are expected to
9465: occur. Does this by walking the selected sequence rendering the
9466: resource and then checking &Apache::lonxml::get_problem_counter()
9467: for what the current value of the problem counter is.
9468:
9469: Caches the results to $env{'form.scantron_maxbubble'},
9470: $env{'form.scantron.bubble_lines.n'},
9471: $env{'form.scantron.first_bubble_line.n'} and
9472: $env{"form.scantron.sub_bubblelines.n"}
9473: which are the total number of bubble, lines, the number of bubble
9474: lines for response n and number of the first bubble line for response n,
9475: and a comma separated list of numbers of bubble lines for sub-questions
9476: (for optionresponse, matchresponse, and rankresponse items), for response n.
9477:
9478:
9479: =item scantron_validate_missingbubbles() :
9480:
9481: Validates all scanlines in the selected file to not have any
9482: answers that don't have bubbles that have not been verified
9483: to be bubble free.
9484:
9485: =item scantron_process_students() :
9486:
9487: Routine that does the actual grading of the bubble sheet information.
9488:
9489: The parsed scanline hash is added to %env
9490:
9491: Then foreach unskipped scanline it does an &Apache::lonnet::ssi()
9492: foreach resource , with the form data of
9493:
9494: 'submitted' =>'scantron'
9495: 'grade_target' =>'grade',
9496: 'grade_username'=> username of student
9497: 'grade_domain' => domain of student
9498: 'grade_courseid'=> of course
9499: 'grade_symb' => symb of resource to grade
9500:
9501: This triggers a grading pass. The problem grading code takes care
9502: of converting the bubbled letter information (now in %env) into a
9503: valid submission.
9504:
9505: =item scantron_upload_scantron_data() :
9506:
9507: Creates the screen for adding a new bubble sheet data file to a course.
9508:
9509: =item scantron_upload_scantron_data_save() :
9510:
9511: Adds a provided bubble information data file to the course if user
9512: has the correct privileges to do so.
9513:
9514: =item valid_file() :
9515:
9516: Validates that the requested bubble data file exists in the course.
9517:
9518: =item scantron_download_scantron_data() :
9519:
9520: Shows a list of the three internal files (original, corrected,
9521: skipped) for a specific bubble sheet data file that exists in the
9522: course.
9523:
9524: =item scantron_validate_ID() :
9525:
9526: Validates all scanlines in the selected file to not have any
1.556 weissno 9527: invalid or underspecified student/employee IDs
1.531 jms 9528:
1.582 raeburn 9529: =item navmap_errormsg() :
9530:
9531: Returns HTML mark-up inside a <div></div> with a link to re-initialize the course.
9532: Should be called whenever the request to instantiate a navmap object fails.
9533:
1.531 jms 9534: =back
9535:
9536: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>