Annotation of loncom/homework/grades.pm, revision 1.596.2.12.2.48
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.596.2.12.2. 8(raebur 4:9): # $Id: grades.pm,v 1.596.2.12.2.47 2019/02/23 15:50:44 raeburn Exp $
1.17 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
1.529 jms 29:
30:
1.1 albertel 31: package Apache::grades;
32: use strict;
33: use Apache::style;
34: use Apache::lonxml;
35: use Apache::lonnet;
1.3 albertel 36: use Apache::loncommon;
1.112 ng 37: use Apache::lonhtmlcommon;
1.68 ng 38: use Apache::lonnavmaps;
1.1 albertel 39: use Apache::lonhomework;
1.456 banghart 40: use Apache::lonpickcode;
1.55 matthew 41: use Apache::loncoursedata;
1.362 albertel 42: use Apache::lonmsg();
1.596.2.4 raeburn 43: use Apache::Constants qw(:common :http);
1.167 sakharuk 44: use Apache::lonlocal;
1.386 raeburn 45: use Apache::lonenc;
1.596.2.4 raeburn 46: use Apache::bridgetask();
1.596.2.12.2. 4(raebur 47:8): use Apache::lontexconvert();
7(raebur 48:9): use HTML::Parser();
49:9): use File::MMagic;
1.170 albertel 50: use String::Similarity;
1.359 www 51: use LONCAPA;
52:
1.315 bowersj2 53: use POSIX qw(floor);
1.87 www 54:
1.435 foxr 55:
1.513 foxr 56:
1.435 foxr 57: my %perm=();
1.596.2.12.2. (raeburn 58:): my %old_essays=();
1.447 foxr 59:
1.513 foxr 60: # These variables are used to recover from ssi errors
61:
62: my $ssi_retries = 5;
63: my $ssi_error;
64: my $ssi_error_resource;
65: my $ssi_error_message;
66:
67:
68: sub ssi_with_retries {
69: my ($resource, $retries, %form) = @_;
70: my ($content, $response) = &Apache::loncommon::ssi_with_retries($resource, $retries, %form);
71: if ($response->is_error) {
72: $ssi_error = 1;
73: $ssi_error_resource = $resource;
74: $ssi_error_message = $response->code . " " . $response->message;
75: }
76:
77: return $content;
78:
79: }
80: #
81: # Prodcuces an ssi retry failure error message to the user:
82: #
83:
84: sub ssi_print_error {
85: my ($r) = @_;
1.516 raeburn 86: my $helpurl = &Apache::loncommon::top_nav_help('Helpdesk');
87: $r->print('
88: <br />
89: <h2>'.&mt('An unrecoverable network error occurred:').'</h2>
90: <p>
91: '.&mt('Unable to retrieve a resource from a server:').'<br />
92: '.&mt('Resource:').' '.$ssi_error_resource.'<br />
93: '.&mt('Error:').' '.$ssi_error_message.'
94: </p>
95: <p>'.
96: &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 />'.
97: &mt('If the error persists, please contact the [_1] for assistance.',$helpurl).
98: '</p>');
99: return;
1.513 foxr 100: }
101:
1.44 ng 102: #
1.146 albertel 103: # --- Retrieve the parts from the metadata file.---
1.44 ng 104: sub getpartlist {
1.582 raeburn 105: my ($symb,$errorref) = @_;
1.439 albertel 106:
107: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 108: unless (ref($navmap)) {
109: if (ref($errorref)) {
110: $$errorref = 'navmap';
111: return;
112: }
113: }
1.439 albertel 114: my $res = $navmap->getBySymb($symb);
115: my $partlist = $res->parts();
116: my $url = $res->src();
117: my @metakeys = split(/,/,&Apache::lonnet::metadata($url,'keys'));
118:
1.146 albertel 119: my @stores;
1.439 albertel 120: foreach my $part (@{ $partlist }) {
1.146 albertel 121: foreach my $key (@metakeys) {
122: if ($key =~ m/^stores_\Q$part\E_/) { push(@stores,$key); }
123: }
124: }
125: return @stores;
1.2 albertel 126: }
127:
1.44 ng 128: # --- Get the symbolic name of a problem and the url
1.324 albertel 129: sub get_symb {
1.173 albertel 130: my ($request,$silent) = @_;
1.596.2.12.2. (raeburn 131:): my $symb=$env{'form.symb'};
132:): unless ($symb) {
133:): (my $url=$env{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
134:): $symb = &Apache::lonnet::symbread($url);
135:): if ($symb eq '') {
136:): if (!$silent) {
137:): $request->print(&mt("Unable to handle ambiguous references: [_1].",$url));
138:): return ();
139:): }
140:): }
1.173 albertel 141: }
1.418 albertel 142: &Apache::lonenc::check_decrypt(\$symb);
1.324 albertel 143: return ($symb);
1.32 ng 144: }
145:
1.129 ng 146: #--- Format fullname, username:domain if different for display
147: #--- Use anywhere where the student names are listed
148: sub nameUserString {
149: my ($type,$fullname,$uname,$udom) = @_;
150: if ($type eq 'header') {
1.485 albertel 151: return '<b> '.&mt('Fullname').' </b><span class="LC_internal_info">('.&mt('Username').')</span>';
1.129 ng 152: } else {
1.398 albertel 153: return ' '.$fullname.'<span class="LC_internal_info"> ('.$uname.
154: ($env{'user.domain'} eq $udom ? '' : ' ('.$udom.')').')</span>';
1.129 ng 155: }
156: }
157:
1.44 ng 158: #--- Get the partlist and the response type for a given problem. ---
159: #--- Indicate if a response type is coded handgraded or not. ---
1.39 ng 160: sub response_type {
1.582 raeburn 161: my ($symb,$response_error) = @_;
1.377 albertel 162:
163: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 164: unless (ref($navmap)) {
165: if (ref($response_error)) {
166: $$response_error = 1;
167: }
168: return;
169: }
1.377 albertel 170: my $res = $navmap->getBySymb($symb);
1.593 raeburn 171: unless (ref($res)) {
172: $$response_error = 1;
173: return;
174: }
1.377 albertel 175: my $partlist = $res->parts();
1.392 albertel 176: my %vPart =
177: map { $_ => 1 } (&Apache::loncommon::get_env_multiple('form.vPart'));
1.377 albertel 178: my (%response_types,%handgrade);
179: foreach my $part (@{ $partlist }) {
1.392 albertel 180: next if (%vPart && !exists($vPart{$part}));
181:
1.377 albertel 182: my @types = $res->responseType($part);
183: my @ids = $res->responseIds($part);
184: for (my $i=0; $i < scalar(@ids); $i++) {
185: $response_types{$part}{$ids[$i]} = $types[$i];
186: $handgrade{$part.'_'.$ids[$i]} =
187: &Apache::lonnet::EXT('resource.'.$part.'_'.$ids[$i].
188: '.handgrade',$symb);
1.41 ng 189: }
190: }
1.377 albertel 191: return ($partlist,\%handgrade,\%response_types);
1.39 ng 192: }
193:
1.375 albertel 194: sub flatten_responseType {
195: my ($responseType) = @_;
196: my @part_response_id =
197: map {
198: my $part = $_;
199: map {
200: [$part,$_]
201: } sort(keys(%{ $responseType->{$part} }));
202: } sort(keys(%$responseType));
203: return @part_response_id;
204: }
205:
1.207 albertel 206: sub get_display_part {
1.324 albertel 207: my ($partID,$symb)=@_;
1.207 albertel 208: my $display=&Apache::lonnet::EXT('resource.'.$partID.'.display',$symb);
209: if (defined($display) and $display ne '') {
1.577 bisitz 210: $display.= ' (<span class="LC_internal_info">'
211: .&mt('Part ID: [_1]',$partID).'</span>)';
1.207 albertel 212: } else {
213: $display=$partID;
214: }
215: return $display;
216: }
1.269 raeburn 217:
1.118 ng 218: #--- Show resource title
219: #--- and parts and response type
220: sub showResourceInfo {
1.582 raeburn 221: my ($symb,$probTitle,$checkboxes,$res_error) = @_;
1.398 albertel 222: my $result = '<h3>'.&mt('Current Resource').': '.$probTitle.'</h3>'."\n";
1.582 raeburn 223: my ($partlist,$handgrade,$responseType) = &response_type($symb,$res_error);
224: if (ref($res_error)) {
225: if ($$res_error) {
226: return;
227: }
228: }
1.584 bisitz 229: $result.=&Apache::loncommon::start_data_table()
230: .&Apache::loncommon::start_data_table_header_row();
231: if ($checkboxes) {
232: $result.='<th> </th>';
233: }
234: $result.='<th>'.&mt('Problem Part').'</th>'
235: .'<th>'.&mt('Res. ID').'</th>'
236: .'<th>'.&mt('Type').'</th>'
237: .&Apache::loncommon::end_data_table_header_row();
1.126 ng 238: my %resptype = ();
1.122 ng 239: my $hdgrade='no';
1.154 albertel 240: my %partsseen;
1.524 raeburn 241: foreach my $partID (sort(keys(%$responseType))) {
1.584 bisitz 242: foreach my $resID (sort(keys(%{ $responseType->{$partID} }))) {
243: my $handgrade=$$handgrade{$partID.'_'.$resID};
244: my $responsetype = $responseType->{$partID}->{$resID};
245: $hdgrade = $handgrade if ($handgrade eq 'yes');
246: $result.=&Apache::loncommon::start_data_table_row();
247: if ($checkboxes) {
248: if (exists($partsseen{$partID})) {
249: $result.="<td> </td>";
250: } else {
251: $result.="<td><input type='checkbox' name='vPart' value='$partID' checked='checked' /></td>";
252: }
253: $partsseen{$partID}=1;
254: }
255: my $display_part=&get_display_part($partID,$symb);
256: $result.='<td>'.$display_part.'</td>'
257: .'<td>'.'<span class="LC_internal_info">'.$resID.'</span></td>'
258: .'<td>'.&mt($responsetype).'</td>'
1.596.2.12.2. 2(raebur 259:2): # .'<td><b>'.&mt('Handgrade: [_1]',$handgrade).'</b></td>'
1.584 bisitz 260: .&Apache::loncommon::end_data_table_row();
261: }
1.118 ng 262: }
1.584 bisitz 263: $result.=&Apache::loncommon::end_data_table();
1.147 albertel 264: return $result,$responseType,$hdgrade,$partlist,$handgrade;
1.118 ng 265: }
266:
1.434 albertel 267: sub reset_caches {
268: &reset_analyze_cache();
269: &reset_perm();
1.596.2.12.2. (raeburn 270:): &reset_old_essays();
1.434 albertel 271: }
272:
273: {
274: my %analyze_cache;
1.557 raeburn 275: my %analyze_cache_formkeys;
1.148 albertel 276:
1.434 albertel 277: sub reset_analyze_cache {
278: undef(%analyze_cache);
1.557 raeburn 279: undef(%analyze_cache_formkeys);
1.434 albertel 280: }
281:
282: sub get_analyze {
1.596.2.12.2. (raeburn 283:): my ($symb,$uname,$udom,$no_increment,$add_to_hash,$type,$trial,$rndseed,$bubbles_per_row)=@_;
1.434 albertel 284: my $key = "$symb\0$uname\0$udom";
1.596.2.2 raeburn 285: if ($type eq 'randomizetry') {
286: if ($trial ne '') {
287: $key .= "\0".$trial;
288: }
289: }
1.557 raeburn 290: if (exists($analyze_cache{$key})) {
291: my $getupdate = 0;
292: if (ref($add_to_hash) eq 'HASH') {
293: foreach my $item (keys(%{$add_to_hash})) {
294: if (ref($analyze_cache_formkeys{$key}) eq 'HASH') {
295: if (!exists($analyze_cache_formkeys{$key}{$item})) {
296: $getupdate = 1;
297: last;
298: }
299: } else {
300: $getupdate = 1;
301: }
302: }
303: }
304: if (!$getupdate) {
305: return $analyze_cache{$key};
306: }
307: }
1.434 albertel 308:
309: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
310: $url=&Apache::lonnet::clutter($url);
1.557 raeburn 311: my %form = ('grade_target' => 'analyze',
312: 'grade_domain' => $udom,
313: 'grade_symb' => $symb,
314: 'grade_courseid' => $env{'request.course.id'},
315: 'grade_username' => $uname,
316: 'grade_noincrement' => $no_increment);
1.596.2.12.2. (raeburn 317:): if ($bubbles_per_row ne '') {
318:): $form{'bubbles_per_row'} = $bubbles_per_row;
319:): }
1.596.2.2 raeburn 320: if ($type eq 'randomizetry') {
321: $form{'grade_questiontype'} = $type;
322: if ($rndseed ne '') {
323: $form{'grade_rndseed'} = $rndseed;
324: }
325: }
1.557 raeburn 326: if (ref($add_to_hash)) {
327: %form = (%form,%{$add_to_hash});
1.596.2.2 raeburn 328: }
1.557 raeburn 329: my $subresult=&ssi_with_retries($url, $ssi_retries,%form);
1.434 albertel 330: (undef,$subresult)=split(/_HASH_REF__/,$subresult,2);
331: my %analyze=&Apache::lonnet::str2hash($subresult);
1.557 raeburn 332: if (ref($add_to_hash) eq 'HASH') {
333: $analyze_cache_formkeys{$key} = $add_to_hash;
334: } else {
335: $analyze_cache_formkeys{$key} = {};
336: }
1.434 albertel 337: return $analyze_cache{$key} = \%analyze;
338: }
339:
340: sub get_order {
1.596.2.2 raeburn 341: my ($partid,$respid,$symb,$uname,$udom,$no_increment,$type,$trial,$rndseed)=@_;
342: my $analyze = &get_analyze($symb,$uname,$udom,$no_increment,undef,$type,$trial,$rndseed);
1.434 albertel 343: return $analyze->{"$partid.$respid.shown"};
344: }
345:
346: sub get_radiobutton_correct_foil {
1.596.2.2 raeburn 347: my ($partid,$respid,$symb,$uname,$udom,$type,$trial,$rndseed)=@_;
348: my $analyze = &get_analyze($symb,$uname,$udom,undef,undef,$type,$trial,$rndseed);
349: my $foils = &get_order($partid,$respid,$symb,$uname,$udom,undef,$type,$trial,$rndseed);
1.555 raeburn 350: if (ref($foils) eq 'ARRAY') {
351: foreach my $foil (@{$foils}) {
352: if ($analyze->{"$partid.$respid.foil.value.$foil"} eq 'true') {
353: return $foil;
354: }
1.434 albertel 355: }
356: }
357: }
1.554 raeburn 358:
359: sub scantron_partids_tograde {
1.596.2.12.2. 1(raebur 360:7): my ($resource,$cid,$uname,$udom,$check_for_randomlist,$bubbles_per_row,$scancode) = @_;
1.554 raeburn 361: my (%analysis,@parts);
362: if (ref($resource)) {
363: my $symb = $resource->symb();
1.557 raeburn 364: my $add_to_form;
365: if ($check_for_randomlist) {
366: $add_to_form = { 'check_parts_withrandomlist' => 1,};
367: }
1.596.2.12.2. 1(raebur 368:7): if ($scancode) {
369:7): if (ref($add_to_form) eq 'HASH') {
370:7): $add_to_form->{'code_for_randomlist'} = $scancode;
371:7): } else {
372:7): $add_to_form = { 'code_for_randomlist' => $scancode,};
373:7): }
374:7): }
(raeburn 375:): my $analyze =
376:): &get_analyze($symb,$uname,$udom,undef,$add_to_form,
377:): undef,undef,undef,$bubbles_per_row);
1.554 raeburn 378: if (ref($analyze) eq 'HASH') {
379: %analysis = %{$analyze};
380: }
381: if (ref($analysis{'parts'}) eq 'ARRAY') {
382: foreach my $part (@{$analysis{'parts'}}) {
383: my ($id,$respid) = split(/\./,$part);
384: if (!&Apache::loncommon::check_if_partid_hidden($id,$symb,$udom,$uname)) {
385: push(@parts,$part);
386: }
387: }
388: }
389: }
390: return (\%analysis,\@parts);
391: }
392:
1.148 albertel 393: }
1.434 albertel 394:
1.118 ng 395: #--- Clean response type for display
1.335 albertel 396: #--- Currently filters option/rank/radiobutton/match/essay/Task
397: # response types only.
1.118 ng 398: sub cleanRecord {
1.336 albertel 399: my ($answer,$response,$symb,$partid,$respid,$record,$order,$version,
1.596.2.2 raeburn 400: $uname,$udom,$type,$trial,$rndseed) = @_;
1.398 albertel 401: my $grayFont = '<span class="LC_internal_info">';
1.148 albertel 402: if ($response =~ /^(option|rank)$/) {
403: my %answer=&Apache::lonnet::str2hash($answer);
1.596.2.12.2. 8(raebur 404:4): my @answer = %answer;
405:4): %answer = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.148 albertel 406: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
407: my ($toprow,$bottomrow);
408: foreach my $foil (@$order) {
409: if ($grading{$foil} == 1) {
410: $toprow.='<td><b>'.$answer{$foil}.' </b></td>';
411: } else {
412: $toprow.='<td><i>'.$answer{$foil}.' </i></td>';
413: }
1.398 albertel 414: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.148 albertel 415: }
416: return '<blockquote><table border="1">'.
1.466 albertel 417: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
418: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.596.2.1 raeburn 419: $bottomrow.'</tr></table></blockquote>';
1.148 albertel 420: } elsif ($response eq 'match') {
421: my %answer=&Apache::lonnet::str2hash($answer);
1.596.2.12.2. 8(raebur 422:4): my @answer = %answer;
423:4): %answer = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.148 albertel 424: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
425: my @items=&Apache::lonnet::str2array($record->{$version."resource.$partid.$respid.submissionitems"});
426: my ($toprow,$middlerow,$bottomrow);
427: foreach my $foil (@$order) {
428: my $item=shift(@items);
429: if ($grading{$foil} == 1) {
430: $toprow.='<td><b>'.$item.' </b></td>';
1.398 albertel 431: $middlerow.='<td><b>'.$grayFont.$answer{$foil}.' </span></b></td>';
1.148 albertel 432: } else {
433: $toprow.='<td><i>'.$item.' </i></td>';
1.398 albertel 434: $middlerow.='<td><i>'.$grayFont.$answer{$foil}.' </span></i></td>';
1.148 albertel 435: }
1.398 albertel 436: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.118 ng 437: }
1.126 ng 438: return '<blockquote><table border="1">'.
1.466 albertel 439: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
440: '<tr valign="top"><td>'.$grayFont.&mt('Item ID').'</span></td>'.
1.148 albertel 441: $middlerow.'</tr>'.
1.466 albertel 442: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.596.2.8 raeburn 443: $bottomrow.'</tr></table></blockquote>';
1.148 albertel 444: } elsif ($response eq 'radiobutton') {
445: my %answer=&Apache::lonnet::str2hash($answer);
446: my ($toprow,$bottomrow);
1.434 albertel 447: my $correct =
1.596.2.2 raeburn 448: &get_radiobutton_correct_foil($partid,$respid,$symb,$uname,$udom,$type,$trial,$rndseed);
1.434 albertel 449: foreach my $foil (@$order) {
1.148 albertel 450: if (exists($answer{$foil})) {
1.434 albertel 451: if ($foil eq $correct) {
1.466 albertel 452: $toprow.='<td><b>'.&mt('true').'</b></td>';
1.148 albertel 453: } else {
1.466 albertel 454: $toprow.='<td><i>'.&mt('true').'</i></td>';
1.148 albertel 455: }
456: } else {
1.466 albertel 457: $toprow.='<td>'.&mt('false').'</td>';
1.148 albertel 458: }
1.398 albertel 459: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.148 albertel 460: }
461: return '<blockquote><table border="1">'.
1.466 albertel 462: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
463: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.596.2.4 raeburn 464: $bottomrow.'</tr></table></blockquote>';
1.148 albertel 465: } elsif ($response eq 'essay') {
1.257 albertel 466: if (! exists ($env{'form.'.$symb})) {
1.122 ng 467: my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 468: $env{'course.'.$env{'request.course.id'}.'.domain'},
469: $env{'course.'.$env{'request.course.id'}.'.num'});
1.122 ng 470:
1.257 albertel 471: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
472: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
473: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
474: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
475: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
476: $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 477: }
1.596.2.12.2. 4(raebur 478:8): $answer = &Apache::lontexconvert::msgtexconverted($answer);
2(raebur 479:5): return '<br /><br /><blockquote><tt>'.&keywords_highlight($answer).'</tt></blockquote>';
1.268 albertel 480: } elsif ( $response eq 'organic') {
1.596.2.12.2. 8(raebur 481:4): my $result=&mt('Smile representation: [_1]',
482:4): '"<tt>'.&HTML::Entities::encode($answer, '"<>&').'</tt>"');
1.268 albertel 483: my $jme=$record->{$version."resource.$partid.$respid.molecule"};
484: $result.=&Apache::chemresponse::jme_img($jme,$answer,400);
485: return $result;
1.335 albertel 486: } elsif ( $response eq 'Task') {
487: if ( $answer eq 'SUBMITTED') {
488: my $files = $record->{$version."resource.$respid.$partid.bridgetask.portfiles"};
1.336 albertel 489: my $result = &Apache::bridgetask::file_list($files,$uname,$udom);
1.335 albertel 490: return $result;
491: } elsif ( grep(/^\Q$version\E.*?\.instance$/, keys(%{$record})) ) {
492: my @matches = grep(/^\Q$version\E.*?\.instance$/,
493: keys(%{$record}));
494: return join('<br />',($version,@matches));
495:
496:
497: } else {
498: my $result =
499: '<p>'
500: .&mt('Overall result: [_1]',
501: $record->{$version."resource.$respid.$partid.status"})
502: .'</p>';
503:
504: $result .= '<ul>';
505: my @grade = grep(/^\Q${version}resource.$respid.$partid.\E[^.]*[.]status$/,
506: keys(%{$record}));
507: foreach my $grade (sort(@grade)) {
508: my ($dim) = ($grade =~/[.]([^.]+)[.]status$/);
509: $result.= '<li>'.&mt("Dimension: [_1], status [_2] ",
510: $dim, $record->{$grade}).
511: '</li>';
512: }
513: $result.='</ul>';
514: return $result;
515: }
1.596.2.12.2. 8(raebur 516:4): } elsif ( $response =~ m/(?:numerical|formula|custom)/) {
517:4): # Respect multiple input fields, see Bug #5409
1.440 albertel 518: $answer =
519: &Apache::loncommon::format_previous_attempt_value('submission',
520: $answer);
1.596.2.12.2. 8(raebur 521:4): return $answer;
1.122 ng 522: }
1.596.2.12.2. 8(raebur 523:4): return &HTML::Entities::encode($answer, '"<>&');
1.118 ng 524: }
525:
526: #-- A couple of common js functions
527: sub commonJSfunctions {
528: my $request = shift;
529: $request->print(<<COMMONJSFUNCTIONS);
530: <script type="text/javascript" language="javascript">
531: function radioSelection(radioButton) {
532: var selection=null;
533: if (radioButton.length > 1) {
534: for (var i=0; i<radioButton.length; i++) {
535: if (radioButton[i].checked) {
536: return radioButton[i].value;
537: }
538: }
539: } else {
540: if (radioButton.checked) return radioButton.value;
541: }
542: return selection;
543: }
544:
545: function pullDownSelection(selectOne) {
546: var selection="";
547: if (selectOne.length > 1) {
548: for (var i=0; i<selectOne.length; i++) {
549: if (selectOne[i].selected) {
550: return selectOne[i].value;
551: }
552: }
553: } else {
1.138 albertel 554: // only one value it must be the selected one
555: return selectOne.value;
1.118 ng 556: }
557: }
558: </script>
559: COMMONJSFUNCTIONS
560: }
561:
1.44 ng 562: #--- Dumps the class list with usernames,list of sections,
563: #--- section, ids and fullnames for each user.
564: sub getclasslist {
1.449 banghart 565: my ($getsec,$filterlist,$getgroup) = @_;
1.291 albertel 566: my @getsec;
1.450 banghart 567: my @getgroup;
1.442 banghart 568: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.291 albertel 569: if (!ref($getsec)) {
570: if ($getsec ne '' && $getsec ne 'all') {
571: @getsec=($getsec);
572: }
573: } else {
574: @getsec=@{$getsec};
575: }
576: if (grep(/^all$/,@getsec)) { undef(@getsec); }
1.450 banghart 577: if (!ref($getgroup)) {
578: if ($getgroup ne '' && $getgroup ne 'all') {
579: @getgroup=($getgroup);
580: }
581: } else {
582: @getgroup=@{$getgroup};
583: }
584: if (grep(/^all$/,@getgroup)) { undef(@getgroup); }
1.291 albertel 585:
1.449 banghart 586: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
1.49 albertel 587: # Bail out if we were unable to get the classlist
1.56 matthew 588: return if (! defined($classlist));
1.449 banghart 589: &Apache::loncoursedata::get_group_memberships($classlist,$keylist);
1.56 matthew 590: #
591: my %sections;
592: my %fullnames;
1.205 matthew 593: foreach my $student (keys(%$classlist)) {
594: my $end =
595: $classlist->{$student}->[&Apache::loncoursedata::CL_END()];
596: my $start =
597: $classlist->{$student}->[&Apache::loncoursedata::CL_START()];
598: my $id =
599: $classlist->{$student}->[&Apache::loncoursedata::CL_ID()];
600: my $section =
601: $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
602: my $fullname =
603: $classlist->{$student}->[&Apache::loncoursedata::CL_FULLNAME()];
604: my $status =
605: $classlist->{$student}->[&Apache::loncoursedata::CL_STATUS()];
1.449 banghart 606: my $group =
607: $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1.76 ng 608: # filter students according to status selected
1.442 banghart 609: if ($filterlist && (!($stu_status =~ /Any/))) {
610: if (!($stu_status =~ $status)) {
1.450 banghart 611: delete($classlist->{$student});
1.76 ng 612: next;
613: }
614: }
1.450 banghart 615: # filter students according to groups selected
1.453 banghart 616: my @stu_groups = split(/,/,$group);
1.450 banghart 617: if (@getgroup) {
618: my $exclude = 1;
1.454 banghart 619: foreach my $grp (@getgroup) {
620: foreach my $stu_group (@stu_groups) {
1.453 banghart 621: if ($stu_group eq $grp) {
622: $exclude = 0;
623: }
1.450 banghart 624: }
1.453 banghart 625: if (($grp eq 'none') && !$group) {
626: $exclude = 0;
627: }
1.450 banghart 628: }
629: if ($exclude) {
630: delete($classlist->{$student});
631: }
632: }
1.205 matthew 633: $section = ($section ne '' ? $section : 'none');
1.106 albertel 634: if (&canview($section)) {
1.291 albertel 635: if (!@getsec || grep(/^\Q$section\E$/,@getsec)) {
1.103 albertel 636: $sections{$section}++;
1.450 banghart 637: if ($classlist->{$student}) {
638: $fullnames{$student}=$fullname;
639: }
1.103 albertel 640: } else {
1.205 matthew 641: delete($classlist->{$student});
1.103 albertel 642: }
643: } else {
1.205 matthew 644: delete($classlist->{$student});
1.103 albertel 645: }
1.44 ng 646: }
647: my %seen = ();
1.56 matthew 648: my @sections = sort(keys(%sections));
649: return ($classlist,\@sections,\%fullnames);
1.44 ng 650: }
651:
1.103 albertel 652: sub canmodify {
653: my ($sec)=@_;
654: if ($perm{'mgr'}) {
655: if (!defined($perm{'mgr_section'})) {
656: # can modify whole class
657: return 1;
658: } else {
659: if ($sec eq $perm{'mgr_section'}) {
660: #can modify the requested section
661: return 1;
662: } else {
663: # can't modify the request section
664: return 0;
665: }
666: }
667: }
668: #can't modify
669: return 0;
670: }
671:
672: sub canview {
673: my ($sec)=@_;
674: if ($perm{'vgr'}) {
675: if (!defined($perm{'vgr_section'})) {
676: # can modify whole class
677: return 1;
678: } else {
679: if ($sec eq $perm{'vgr_section'}) {
680: #can modify the requested section
681: return 1;
682: } else {
683: # can't modify the request section
684: return 0;
685: }
686: }
687: }
688: #can't modify
689: return 0;
690: }
691:
1.44 ng 692: #--- Retrieve the grade status of a student for all the parts
693: sub student_gradeStatus {
1.324 albertel 694: my ($symb,$udom,$uname,$partlist) = @_;
1.257 albertel 695: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.44 ng 696: my %partstatus = ();
697: foreach (@$partlist) {
1.128 ng 698: my ($status,undef) = split(/_/,$record{"resource.$_.solved"},2);
1.44 ng 699: $status = 'nothing' if ($status eq '');
700: $partstatus{$_} = $status;
701: my $subkey = "resource.$_.submitted_by";
702: $partstatus{$subkey} = $record{$subkey} if ($record{$subkey} ne '');
703: }
704: return %partstatus;
705: }
706:
1.45 ng 707: # hidden form and javascript that calls the form
708: # Use by verifyscript and viewgrades
709: # Shows a student's view of problem and submission
710: sub jscriptNform {
1.324 albertel 711: my ($symb) = @_;
1.442 banghart 712: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.45 ng 713: my $jscript='<script type="text/javascript" language="javascript">'."\n".
714: ' function viewOneStudent(user,domain) {'."\n".
715: ' document.onestudent.student.value = user;'."\n".
716: ' document.onestudent.userdom.value = domain;'."\n".
717: ' document.onestudent.submit();'."\n".
718: ' }'."\n".
719: '</script>'."\n";
720: $jscript.= '<form action="/adm/grades" method="post" name="onestudent">'."\n".
1.418 albertel 721: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 722: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
723: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.442 banghart 724: '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.45 ng 725: '<input type="hidden" name="command" value="submission" />'."\n".
726: '<input type="hidden" name="student" value="" />'."\n".
727: '<input type="hidden" name="userdom" value="" />'."\n".
728: '</form>'."\n";
729: return $jscript;
730: }
1.39 ng 731:
1.447 foxr 732:
733:
1.315 bowersj2 734: # Given the score (as a number [0-1] and the weight) what is the final
735: # point value? This function will round to the nearest tenth, third,
736: # or quarter if one of those is within the tolerance of .00001.
1.316 albertel 737: sub compute_points {
1.315 bowersj2 738: my ($score, $weight) = @_;
739:
740: my $tolerance = .00001;
741: my $points = $score * $weight;
742:
743: # Check for nearness to 1/x.
744: my $check_for_nearness = sub {
745: my ($factor) = @_;
746: my $num = ($points * $factor) + $tolerance;
747: my $floored_num = floor($num);
1.316 albertel 748: if ($num - $floored_num < 2 * $tolerance * $factor) {
1.315 bowersj2 749: return $floored_num / $factor;
750: }
751: return $points;
752: };
753:
754: $points = $check_for_nearness->(10);
755: $points = $check_for_nearness->(3);
756: $points = $check_for_nearness->(4);
757:
758: return $points;
759: }
760:
1.44 ng 761: #------------------ End of general use routines --------------------
1.87 www 762:
763: #
764: # Find most similar essay
765: #
766:
767: sub most_similar {
1.596.2.12.2. (raeburn 768:): my ($uname,$udom,$symb,$uessay)=@_;
769:):
770:): unless ($symb) { return ''; }
771:):
772:): unless (ref($old_essays{$symb}) eq 'HASH') { return ''; }
1.87 www 773:
774: # ignore spaces and punctuation
775:
776: $uessay=~s/\W+/ /gs;
777:
1.282 www 778: # ignore empty submissions (occuring when only files are sent)
779:
1.596.2.4 raeburn 780: unless ($uessay=~/\w+/s) { return ''; }
1.282 www 781:
1.87 www 782: # these will be returned. Do not care if not at least 50 percent similar
1.88 www 783: my $limit=0.6;
1.87 www 784: my $sname='';
785: my $sdom='';
786: my $scrsid='';
787: my $sessay='';
788: # go through all essays ...
1.596.2.12.2. (raeburn 789:): foreach my $tkey (keys(%{$old_essays{$symb}})) {
1.426 albertel 790: my ($tname,$tdom,$tcrsid)=map {&unescape($_)} (split(/\./,$tkey));
1.87 www 791: # ... except the same student
1.426 albertel 792: next if (($tname eq $uname) && ($tdom eq $udom));
1.596.2.12.2. (raeburn 793:): my $tessay=$old_essays{$symb}{$tkey};
1.426 albertel 794: $tessay=~s/\W+/ /gs;
1.87 www 795: # String similarity gives up if not even limit
1.426 albertel 796: my $tsimilar=&String::Similarity::similarity($uessay,$tessay,$limit);
1.87 www 797: # Found one
1.426 albertel 798: if ($tsimilar>$limit) {
799: $limit=$tsimilar;
800: $sname=$tname;
801: $sdom=$tdom;
802: $scrsid=$tcrsid;
1.596.2.12.2. (raeburn 803:): $sessay=$old_essays{$symb}{$tkey};
1.426 albertel 804: }
1.87 www 805: }
1.88 www 806: if ($limit>0.6) {
1.87 www 807: return ($sname,$sdom,$scrsid,$sessay,$limit);
808: } else {
809: return ('','','','',0);
810: }
811: }
812:
1.44 ng 813: #-------------------------------------------------------------------
814:
815: #------------------------------------ Receipt Verification Routines
1.45 ng 816: #
1.44 ng 817: #--- Check whether a receipt number is valid.---
818: sub verifyreceipt {
819: my $request = shift;
820:
1.257 albertel 821: my $courseid = $env{'request.course.id'};
1.184 www 822: my $receipt = &Apache::lonnet::recprefix($courseid).'-'.
1.257 albertel 823: $env{'form.receipt'};
1.44 ng 824: $receipt =~ s/[^\-\d]//g;
1.378 albertel 825: my ($symb) = &get_symb($request);
1.44 ng 826:
1.487 albertel 827: my $title.=
828: '<h3><span class="LC_info">'.
1.584 bisitz 829: &mt('Verifying Receipt No. [_1]',$receipt).
1.487 albertel 830: '</span></h3>'."\n".
1.596.2.12.2. 2(raebur 831:3): '<h4>'.&mt('[_1]Resource: [_2]','<b>','</b>'.$env{'form.probTitle'}).
1.487 albertel 832: '</h4>'."\n";
1.44 ng 833:
834: my ($string,$contents,$matches) = ('','',0);
1.56 matthew 835: my (undef,undef,$fullname) = &getclasslist('all','0');
1.177 albertel 836:
837: my $receiptparts=0;
1.390 albertel 838: if ($env{"course.$courseid.receiptalg"} eq 'receipt2' ||
839: $env{"course.$courseid.receiptalg"} eq 'receipt3') { $receiptparts=1; }
1.177 albertel 840: my $parts=['0'];
1.582 raeburn 841: if ($receiptparts) {
842: my $res_error;
843: ($parts)=&response_type($symb,\$res_error);
844: if ($res_error) {
845: return &navmap_errormsg();
846: }
847: }
1.486 albertel 848:
849: my $header =
850: &Apache::loncommon::start_data_table().
851: &Apache::loncommon::start_data_table_header_row().
1.487 albertel 852: '<th> '.&mt('Fullname').' </th>'."\n".
853: '<th> '.&mt('Username').' </th>'."\n".
854: '<th> '.&mt('Domain').' </th>';
1.486 albertel 855: if ($receiptparts) {
1.487 albertel 856: $header.='<th> '.&mt('Problem Part').' </th>';
1.486 albertel 857: }
858: $header.=
859: &Apache::loncommon::end_data_table_header_row();
860:
1.294 albertel 861: foreach (sort
862: {
863: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
864: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
865: }
866: return $a cmp $b;
867: } (keys(%$fullname))) {
1.44 ng 868: my ($uname,$udom)=split(/\:/);
1.177 albertel 869: foreach my $part (@$parts) {
870: if ($receipt eq &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb,$part)) {
1.486 albertel 871: $contents.=
872: &Apache::loncommon::start_data_table_row().
873: '<td> '."\n".
1.177 albertel 874: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 875: '\');" target="_self">'.$$fullname{$_}.'</a> </td>'."\n".
1.177 albertel 876: '<td> '.$uname.' </td>'.
877: '<td> '.$udom.' </td>';
878: if ($receiptparts) {
879: $contents.='<td> '.$part.' </td>';
880: }
1.486 albertel 881: $contents.=
882: &Apache::loncommon::end_data_table_row()."\n";
1.177 albertel 883:
884: $matches++;
885: }
1.44 ng 886: }
887: }
888: if ($matches == 0) {
1.584 bisitz 889: $string = $title
890: .'<p class="LC_warning">'
891: .&mt('No match found for the above receipt number.')
892: .'</p>';
1.44 ng 893: } else {
1.324 albertel 894: $string = &jscriptNform($symb).$title.
1.487 albertel 895: '<p>'.
1.584 bisitz 896: &mt('The above receipt number matches the following [quant,_1,student].',$matches).
1.487 albertel 897: '</p>'.
1.486 albertel 898: $header.
899: $contents.
900: &Apache::loncommon::end_data_table()."\n";
1.44 ng 901: }
1.324 albertel 902: return $string.&show_grading_menu_form($symb);
1.44 ng 903: }
904:
905: #--- This is called by a number of programs.
906: #--- Called from the Grading Menu - View/Grade an individual student
907: #--- Also called directly when one clicks on the subm button
908: # on the problem page.
1.30 ng 909: sub listStudents {
1.41 ng 910: my ($request) = shift;
1.49 albertel 911:
1.324 albertel 912: my ($symb) = &get_symb($request);
1.257 albertel 913: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
914: my $cnum = $env{"course.$env{'request.course.id'}.num"};
915: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.449 banghart 916: my $getgroup = $env{'form.group'} eq '' ? 'all' : $env{'form.group'};
1.257 albertel 917: my $submitonly= $env{'form.submitonly'} eq '' ? 'all' : $env{'form.submitonly'};
1.548 bisitz 918: my $viewgrade = $env{'form.showgrading'} eq 'yes' ? 'View/Grade/Regrade' : 'View';
1.257 albertel 919: $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
920: &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
1.49 albertel 921:
1.548 bisitz 922: my $result='<h3><span class="LC_info"> '
923: .&mt("$viewgrade Submissions for a Student or a Group of Students")
1.485 albertel 924: .'</span></h3>';
1.118 ng 925:
1.324 albertel 926: my ($table,undef,$hdgrade,$partlist,$handgrade) = &showResourceInfo($symb,$env{'form.probTitle'},($env{'form.showgrading'} eq 'yes'));
1.49 albertel 927:
1.596.2.12.2. 6(raebur 928:6): my %js_lt = &Apache::lonlocal::texthash (
1.559 raeburn 929: 'multiple' => 'Please select a student or group of students before clicking on the Next button.',
930: 'single' => 'Please select the student before clicking on the Next button.',
931: );
1.596.2.12.2. 6(raebur 932:6): &js_escape(\%js_lt);
1.45 ng 933: $request->print(<<LISTJAVASCRIPT);
934: <script type="text/javascript" language="javascript">
1.110 ng 935: function checkSelect(checkBox) {
936: var ctr=0;
937: var sense="";
938: if (checkBox.length > 1) {
939: for (var i=0; i<checkBox.length; i++) {
940: if (checkBox[i].checked) {
941: ctr++;
942: }
943: }
1.596.2.12.2. 6(raebur 944:6): sense = '$js_lt{'multiple'}';
1.110 ng 945: } else {
946: if (checkBox.checked) {
947: ctr = 1;
948: }
1.596.2.12.2. 6(raebur 949:6): sense = '$js_lt{'single'}';
1.110 ng 950: }
951: if (ctr == 0) {
1.485 albertel 952: alert(sense);
1.110 ng 953: return false;
954: }
955: document.gradesub.submit();
956: }
957:
958: function reLoadList(formname) {
1.112 ng 959: if (formname.saveStatusOld.value == pullDownSelection(formname.Status)) {return;}
1.110 ng 960: formname.command.value = 'submission';
961: formname.submit();
962: }
1.45 ng 963: </script>
964: LISTJAVASCRIPT
965:
1.118 ng 966: &commonJSfunctions($request);
1.41 ng 967: $request->print($result);
1.39 ng 968:
1.401 albertel 969: my $checkhdgrade = ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1 ) ? 'checked="checked"' : '';
970: my $checklastsub = $checkhdgrade eq '' ? 'checked="checked"' : '';
1.154 albertel 971: my $gradeTable='<form action="/adm/grades" method="post" name="gradesub">'.
1.485 albertel 972: "\n".$table;
973:
1.561 bisitz 974: $gradeTable .= &Apache::lonhtmlcommon::start_pick_box();
975: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Problem Text'))
976: .'<label><input type="radio" name="vProb" value="no" checked="checked" /> '.&mt('no').' </label>'."\n"
977: .'<label><input type="radio" name="vProb" value="yes" /> '.&mt('one student').' </label>'."\n"
978: .'<label><input type="radio" name="vProb" value="all" /> '.&mt('all students').' </label><br />'."\n"
979: .&Apache::lonhtmlcommon::row_closure();
980: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Answer'))
981: .'<label><input type="radio" name="vAns" value="no" /> '.&mt('no').' </label>'."\n"
982: .'<label><input type="radio" name="vAns" value="yes" /> '.&mt('one student').' </label>'."\n"
983: .'<label><input type="radio" name="vAns" value="all" checked="checked" /> '.&mt('all students').' </label><br />'."\n"
984: .&Apache::lonhtmlcommon::row_closure();
1.485 albertel 985:
986: my $submission_options;
1.257 albertel 987: if ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1) {
1.485 albertel 988: $submission_options.=
989: '<label><input type="radio" name="lastSub" value="hdgrade" '.$checkhdgrade.' /> '.&mt('essay part only').' </label>'."\n";
1.49 albertel 990: }
1.442 banghart 991: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
992: my $saveStatus = $stu_status eq '' ? 'Active' : $stu_status;
1.257 albertel 993: $env{'form.Status'} = $saveStatus;
1.485 albertel 994: $submission_options.=
1.592 bisitz 995: '<span class="LC_nobreak">'.
996: '<label><input type="radio" name="lastSub" value="lastonly" '.$checklastsub.' /> '.
997: &mt('last submission only').' </label></span>'."\n".
998: '<span class="LC_nobreak">'.
999: '<label><input type="radio" name="lastSub" value="last" /> '.
1000: &mt('last submission & parts info').' </label></span>'."\n".
1001: '<span class="LC_nobreak">'.
1002: '<label><input type="radio" name="lastSub" value="datesub" /> '.
1003: &mt('by dates and submissions').'</label></span>'."\n".
1004: '<span class="LC_nobreak">'.
1005: '<label><input type="radio" name="lastSub" value="all" /> '.
1006: &mt('all details').'</label></span>';
1.561 bisitz 1007: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Submissions'))
1008: .$submission_options
1009: .&Apache::lonhtmlcommon::row_closure();
1010:
1011: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Grading Increments'))
1012: .'<select name="increment">'
1013: .'<option value="1">'.&mt('Whole Points').'</option>'
1014: .'<option value=".5">'.&mt('Half Points').'</option>'
1015: .'<option value=".25">'.&mt('Quarter Points').'</option>'
1016: .'<option value=".1">'.&mt('Tenths of a Point').'</option>'
1017: .'</select>'
1018: .&Apache::lonhtmlcommon::row_closure();
1.485 albertel 1019:
1020: $gradeTable .=
1.432 banghart 1021: &build_section_inputs().
1.45 ng 1022: '<input type="hidden" name="submitonly" value="'.$submitonly.'" />'."\n".
1.257 albertel 1023: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" /><br />'."\n".
1024: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" /><br />'."\n".
1025: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1026: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.418 albertel 1027: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.110 ng 1028: '<input type="hidden" name="saveStatusOld" value="'.$saveStatus.'" />'."\n";
1029:
1.257 albertel 1030: if (exists($env{'form.gradingMenu'}) && exists($env{'form.Status'})) {
1.561 bisitz 1031: $gradeTable .= '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n";
1.124 ng 1032: } else {
1.561 bisitz 1033: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Student Status'))
1034: .&Apache::lonhtmlcommon::StatusOptions(
1035: $saveStatus,undef,1,'javascript:reLoadList(this.form);')
1036: .&Apache::lonhtmlcommon::row_closure();
1.124 ng 1037: }
1.112 ng 1038:
1.561 bisitz 1039: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Check For Plagiarism'))
1040: .'<input type="checkbox" name="checkPlag" checked="checked" />'
1041: .&Apache::lonhtmlcommon::row_closure(1)
1042: .&Apache::lonhtmlcommon::end_pick_box();
1043:
1044: $gradeTable .= '<p>'
1045: .&mt('To '.lc($viewgrade)." a submission or a group of submissions, click on the check box(es) next to the student's name(s). Then click on the Next button.")."\n"
1046: .'<input type="hidden" name="command" value="processGroup" />'
1047: .'</p>';
1.249 albertel 1048:
1049: # checkall buttons
1050: $gradeTable.=&check_script('gradesub', 'stuinfo');
1.110 ng 1051: $gradeTable.='<input type="button" '."\n".
1.589 bisitz 1052: 'onclick="javascript:checkSelect(this.form.stuinfo);" '."\n".
1053: 'value="'.&mt('Next').' →" /> <br />'."\n";
1.249 albertel 1054: $gradeTable.=&check_buttons();
1.450 banghart 1055: my ($classlist, undef, $fullname) = &getclasslist($getsec,'1',$getgroup);
1.474 albertel 1056: $gradeTable.= &Apache::loncommon::start_data_table().
1057: &Apache::loncommon::start_data_table_header_row();
1.110 ng 1058: my $loop = 0;
1059: while ($loop < 2) {
1.485 albertel 1060: $gradeTable.='<th>'.&mt('No.').'</th><th>'.&mt('Select').'</th>'.
1061: '<th>'.&nameUserString('header').' '.&mt('Section/Group').'</th>';
1.301 albertel 1062: if ($env{'form.showgrading'} eq 'yes'
1063: && $submitonly ne 'queued'
1064: && $submitonly ne 'all') {
1.485 albertel 1065: foreach my $part (sort(@$partlist)) {
1066: my $display_part=
1067: &get_display_part((split(/_/,$part))[0],$symb);
1068: $gradeTable.=
1069: '<th>'.&mt('Part: [_1] Status',$display_part).'</th>';
1.110 ng 1070: }
1.301 albertel 1071: } elsif ($submitonly eq 'queued') {
1.474 albertel 1072: $gradeTable.='<th>'.&mt('Queue Status').' </th>';
1.110 ng 1073: }
1074: $loop++;
1.126 ng 1075: # $gradeTable.='<td></td>' if ($loop%2 ==1);
1.41 ng 1076: }
1.474 albertel 1077: $gradeTable.=&Apache::loncommon::end_data_table_header_row()."\n";
1.41 ng 1078:
1.45 ng 1079: my $ctr = 0;
1.294 albertel 1080: foreach my $student (sort
1081: {
1082: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
1083: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
1084: }
1085: return $a cmp $b;
1086: }
1087: (keys(%$fullname))) {
1.41 ng 1088: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 1089:
1.110 ng 1090: my %status = ();
1.301 albertel 1091:
1092: if ($submitonly eq 'queued') {
1093: my %queue_status =
1094: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
1095: $udom,$uname);
1096: next if (!defined($queue_status{'gradingqueue'}));
1097: $status{'gradingqueue'} = $queue_status{'gradingqueue'};
1098: }
1099:
1100: if ($env{'form.showgrading'} eq 'yes'
1101: && $submitonly ne 'queued'
1102: && $submitonly ne 'all') {
1.324 albertel 1103: (%status) =&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 1104: my $submitted = 0;
1.164 albertel 1105: my $graded = 0;
1.248 albertel 1106: my $incorrect = 0;
1.110 ng 1107: foreach (keys(%status)) {
1.145 albertel 1108: $submitted = 1 if ($status{$_} ne 'nothing');
1.248 albertel 1109: $graded = 1 if ($status{$_} =~ /^ungraded/);
1110: $incorrect = 1 if ($status{$_} =~ /^incorrect/);
1111:
1.110 ng 1112: my ($foo,$partid,$foo1) = split(/\./,$_);
1113: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
1.145 albertel 1114: $submitted = 0;
1.150 albertel 1115: my ($part)=split(/\./,$partid);
1.110 ng 1116: $gradeTable.='<input type="hidden" name="'.
1.150 albertel 1117: $student.':'.$part.':submitted_by" value="'.
1.110 ng 1118: $status{'resource.'.$partid.'.submitted_by'}.'" />';
1119: }
1.41 ng 1120: }
1.248 albertel 1121:
1.156 albertel 1122: next if (!$submitted && ($submitonly eq 'yes' ||
1123: $submitonly eq 'incorrect' ||
1124: $submitonly eq 'graded'));
1.248 albertel 1125: next if (!$graded && ($submitonly eq 'graded'));
1126: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 1127: }
1.34 ng 1128:
1.45 ng 1129: $ctr++;
1.249 albertel 1130: my $section = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
1.452 banghart 1131: my $group = $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1.104 albertel 1132: if ( $perm{'vgr'} eq 'F' ) {
1.474 albertel 1133: if ($ctr%2 ==1) {
1134: $gradeTable.= &Apache::loncommon::start_data_table_row();
1135: }
1.126 ng 1136: $gradeTable.='<td align="right">'.$ctr.' </td>'.
1.563 bisitz 1137: '<td align="center"><label><input type="checkbox" name="stuinfo" value="'.
1.249 albertel 1138: $student.':'.$$fullname{$student}.':::SECTION'.$section.
1139: ') " /> </label></td>'."\n".'<td>'.
1140: &nameUserString(undef,$$fullname{$student},$uname,$udom).
1.474 albertel 1141: ' '.$section.($group ne '' ?'/'.$group:'').'</td>'."\n";
1.110 ng 1142:
1.257 albertel 1143: if ($env{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
1.524 raeburn 1144: foreach (sort(keys(%status))) {
1.485 albertel 1145: next if ($_ =~ /^resource.*?submitted_by$/);
1146: $gradeTable.='<td align="center"> '.&mt($status{$_}).' </td>'."\n";
1.110 ng 1147: }
1.41 ng 1148: }
1.126 ng 1149: # $gradeTable.='<td></td>' if ($ctr%2 ==1);
1.474 albertel 1150: if ($ctr%2 ==0) {
1151: $gradeTable.=&Apache::loncommon::end_data_table_row()."\n";
1152: }
1.41 ng 1153: }
1154: }
1.110 ng 1155: if ($ctr%2 ==1) {
1.126 ng 1156: $gradeTable.='<td> </td><td> </td><td> </td>';
1.301 albertel 1157: if ($env{'form.showgrading'} eq 'yes'
1158: && $submitonly ne 'queued'
1159: && $submitonly ne 'all') {
1.110 ng 1160: foreach (@$partlist) {
1161: $gradeTable.='<td> </td>';
1162: }
1.301 albertel 1163: } elsif ($submitonly eq 'queued') {
1164: $gradeTable.='<td> </td>';
1.110 ng 1165: }
1.474 albertel 1166: $gradeTable.=&Apache::loncommon::end_data_table_row();
1.110 ng 1167: }
1168:
1.474 albertel 1169: $gradeTable.=&Apache::loncommon::end_data_table()."\n".
1.589 bisitz 1170: '<input type="button" '.
1171: 'onclick="javascript:checkSelect(this.form.stuinfo);" '.
1172: 'value="'.&mt('Next').' →" /></form>'."\n";
1.45 ng 1173: if ($ctr == 0) {
1.96 albertel 1174: my $num_students=(scalar(keys(%$fullname)));
1175: if ($num_students eq 0) {
1.485 albertel 1176: $gradeTable='<br /> <span class="LC_warning">'.&mt('There are no students currently enrolled.').'</span>';
1.96 albertel 1177: } else {
1.171 albertel 1178: my $submissions='submissions';
1179: if ($submitonly eq 'incorrect') { $submissions = 'incorrect submissions'; }
1180: if ($submitonly eq 'graded' ) { $submissions = 'ungraded submissions'; }
1.301 albertel 1181: if ($submitonly eq 'queued' ) { $submissions = 'queued submissions'; }
1.398 albertel 1182: $gradeTable='<br /> <span class="LC_warning">'.
1.596.2.12.2. 4(raebur 1183:3): &mt('No '.$submissions.' found for this resource for any students. ([quant,_1,student] checked for '.$submissions.')',
1.485 albertel 1184: $num_students).
1185: '</span><br />';
1.96 albertel 1186: }
1.46 ng 1187: } elsif ($ctr == 1) {
1.474 albertel 1188: $gradeTable =~ s/type="checkbox"/type="checkbox" checked="checked"/;
1.45 ng 1189: }
1.324 albertel 1190: $gradeTable.=&show_grading_menu_form($symb);
1.45 ng 1191: $request->print($gradeTable);
1.44 ng 1192: return '';
1.10 ng 1193: }
1194:
1.44 ng 1195: #---- Called from the listStudents routine
1.249 albertel 1196:
1197: sub check_script {
1198: my ($form, $type)=@_;
1199: my $chkallscript='<script type="text/javascript">
1200: function checkall() {
1201: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1202: ele = document.forms.'.$form.'.elements[i];
1203: if (ele.name == "'.$type.'") {
1204: document.forms.'.$form.'.elements[i].checked=true;
1205: }
1206: }
1207: }
1208:
1209: function checksec() {
1210: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1211: ele = document.forms.'.$form.'.elements[i];
1212: string = document.forms.'.$form.'.chksec.value;
1213: if
1214: (ele.value.indexOf(":::SECTION"+string)>0) {
1215: document.forms.'.$form.'.elements[i].checked=true;
1216: }
1217: }
1218: }
1219:
1220:
1221: function uncheckall() {
1222: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1223: ele = document.forms.'.$form.'.elements[i];
1224: if (ele.name == "'.$type.'") {
1225: document.forms.'.$form.'.elements[i].checked=false;
1226: }
1227: }
1228: }
1229:
1230: </script>'."\n";
1231: return $chkallscript;
1232: }
1233:
1234: sub check_buttons {
1.485 albertel 1235: my $buttons.='<input type="button" onclick="checkall()" value="'.&mt('Check All').'" />';
1236: $buttons.='<input type="button" onclick="uncheckall()" value="'.&mt('Uncheck All').'" /> ';
1237: $buttons.='<input type="button" onclick="checksec()" value="'.&mt('Check Section/Group').'" />';
1.249 albertel 1238: $buttons.='<input type="text" size="5" name="chksec" /> ';
1239: return $buttons;
1240: }
1241:
1.44 ng 1242: # Displays the submissions for one student or a group of students
1.34 ng 1243: sub processGroup {
1.41 ng 1244: my ($request) = shift;
1245: my $ctr = 0;
1.155 albertel 1246: my @stuchecked = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.41 ng 1247: my $total = scalar(@stuchecked)-1;
1.45 ng 1248:
1.396 banghart 1249: foreach my $student (@stuchecked) {
1250: my ($uname,$udom,$fullname) = split(/:/,$student);
1.257 albertel 1251: $env{'form.student'} = $uname;
1252: $env{'form.userdom'} = $udom;
1253: $env{'form.fullname'} = $fullname;
1.41 ng 1254: &submission($request,$ctr,$total);
1255: $ctr++;
1256: }
1257: return '';
1.35 ng 1258: }
1.34 ng 1259:
1.44 ng 1260: #------------------------------------------------------------------------------------
1261: #
1262: #-------------------------- Next few routines handles grading by student, essentially
1263: # handles essay response type problem/part
1264: #
1265: #--- Javascript to handle the submission page functionality ---
1266: sub sub_page_js {
1267: my $request = shift;
1.596.2.12.2. 6(raebur 1268:6): my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
7(raebur 1269:6): &js_escape(\$alertmsg);
1.44 ng 1270: $request->print(<<SUBJAVASCRIPT);
1271: <script type="text/javascript" language="javascript">
1.71 ng 1272: function updateRadio(formname,id,weight) {
1.125 ng 1273: var gradeBox = formname["GD_BOX"+id];
1274: var radioButton = formname["RADVAL"+id];
1275: var oldpts = formname["oldpts"+id].value;
1.72 ng 1276: var pts = checkSolved(formname,id) == 'update' ? gradeBox.value : oldpts;
1.71 ng 1277: gradeBox.value = pts;
1278: var resetbox = false;
1279: if (isNaN(pts) || pts < 0) {
1.539 riegler 1280: alert("$alertmsg"+pts);
1.71 ng 1281: for (var i=0; i<radioButton.length; i++) {
1282: if (radioButton[i].checked) {
1283: gradeBox.value = i;
1284: resetbox = true;
1285: }
1286: }
1287: if (!resetbox) {
1288: formtextbox.value = "";
1289: }
1290: return;
1.44 ng 1291: }
1.71 ng 1292:
1293: if (pts > weight) {
1294: var resp = confirm("You entered a value ("+pts+
1295: ") greater than the weight for the part. Accept?");
1296: if (resp == false) {
1.125 ng 1297: gradeBox.value = oldpts;
1.71 ng 1298: return;
1299: }
1.44 ng 1300: }
1.13 albertel 1301:
1.71 ng 1302: for (var i=0; i<radioButton.length; i++) {
1303: radioButton[i].checked=false;
1304: if (pts == i && pts != "") {
1305: radioButton[i].checked=true;
1306: }
1307: }
1308: updateSelect(formname,id);
1.125 ng 1309: formname["stores"+id].value = "0";
1.41 ng 1310: }
1.5 albertel 1311:
1.72 ng 1312: function writeBox(formname,id,pts) {
1.125 ng 1313: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1314: if (checkSolved(formname,id) == 'update') {
1315: gradeBox.value = pts;
1316: } else {
1.125 ng 1317: var oldpts = formname["oldpts"+id].value;
1.72 ng 1318: gradeBox.value = oldpts;
1.125 ng 1319: var radioButton = formname["RADVAL"+id];
1.71 ng 1320: for (var i=0; i<radioButton.length; i++) {
1321: radioButton[i].checked=false;
1.72 ng 1322: if (i == oldpts) {
1.71 ng 1323: radioButton[i].checked=true;
1324: }
1325: }
1.41 ng 1326: }
1.125 ng 1327: formname["stores"+id].value = "0";
1.71 ng 1328: updateSelect(formname,id);
1329: return;
1.41 ng 1330: }
1.44 ng 1331:
1.71 ng 1332: function clearRadBox(formname,id) {
1333: if (checkSolved(formname,id) == 'noupdate') {
1334: updateSelect(formname,id);
1335: return;
1336: }
1.125 ng 1337: gradeSelect = formname["GD_SEL"+id];
1.71 ng 1338: for (var i=0; i<gradeSelect.length; i++) {
1339: if (gradeSelect[i].selected) {
1340: var selectx=i;
1341: }
1342: }
1.125 ng 1343: var stores = formname["stores"+id];
1.71 ng 1344: if (selectx == stores.value) { return };
1.125 ng 1345: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1346: gradeBox.value = "";
1.125 ng 1347: var radioButton = formname["RADVAL"+id];
1.71 ng 1348: for (var i=0; i<radioButton.length; i++) {
1349: radioButton[i].checked=false;
1350: }
1351: stores.value = selectx;
1352: }
1.5 albertel 1353:
1.71 ng 1354: function checkSolved(formname,id) {
1.125 ng 1355: if (formname["solved"+id].value == "correct_by_student" && formname.overRideScore.value == 'no') {
1.118 ng 1356: var reply = confirm("This problem has been graded correct by the computer. Do you want to change the score?");
1357: if (!reply) {return "noupdate";}
1.120 ng 1358: formname.overRideScore.value = 'yes';
1.41 ng 1359: }
1.71 ng 1360: return "update";
1.13 albertel 1361: }
1.71 ng 1362:
1363: function updateSelect(formname,id) {
1.125 ng 1364: formname["GD_SEL"+id][0].selected = true;
1.71 ng 1365: return;
1.41 ng 1366: }
1.33 ng 1367:
1.121 ng 1368: //=========== Check that a point is assigned for all the parts ============
1.71 ng 1369: function checksubmit(formname,val,total,parttot) {
1.121 ng 1370: formname.gradeOpt.value = val;
1.71 ng 1371: if (val == "Save & Next") {
1372: for (i=0;i<=total;i++) {
1373: for (j=0;j<parttot;j++) {
1.125 ng 1374: var partid = formname["partid"+i+"_"+j].value;
1.127 ng 1375: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1376: var points = formname["GD_BOX"+i+"_"+partid].value;
1.71 ng 1377: if (points == "") {
1.125 ng 1378: var name = formname["name"+i].value;
1.129 ng 1379: var studentID = (name != '' ? name : formname["unamedom"+i].value);
1380: var resp = confirm("You did not assign a score for "+studentID+
1381: ", part "+partid+". Continue?");
1.71 ng 1382: if (resp == false) {
1.125 ng 1383: formname["GD_BOX"+i+"_"+partid].focus();
1.71 ng 1384: return false;
1385: }
1386: }
1387: }
1388: }
1389: }
1390: }
1.121 ng 1391: if (val == "Grade Student") {
1392: formname.showgrading.value = "yes";
1393: if (formname.Status.value == "") {
1394: formname.Status.value = "Active";
1395: }
1396: formname.studentNo.value = total;
1397: }
1.120 ng 1398: formname.submit();
1399: }
1400:
1.71 ng 1401: //======= Check that a score is assigned for all the problems (page/sequence grading only) =========
1402: function checkSubmitPage(formname,total) {
1403: noscore = new Array(100);
1404: var ptr = 0;
1405: for (i=1;i<total;i++) {
1.125 ng 1406: var partid = formname["q_"+i].value;
1.127 ng 1407: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1408: var points = formname["GD_BOX"+i+"_"+partid].value;
1409: var status = formname["solved"+i+"_"+partid].value;
1.71 ng 1410: if (points == "" && status != "correct_by_student") {
1411: noscore[ptr] = i;
1412: ptr++;
1413: }
1414: }
1415: }
1416: if (ptr != 0) {
1417: var sense = ptr == 1 ? ": " : "s: ";
1418: var prolist = "";
1419: if (ptr == 1) {
1420: prolist = noscore[0];
1421: } else {
1422: var i = 0;
1423: while (i < ptr-1) {
1424: prolist += noscore[i]+", ";
1425: i++;
1426: }
1427: prolist += "and "+noscore[i];
1428: }
1429: var resp = confirm("You did not assign any score for the following problem"+sense+prolist+". Continue?");
1430: if (resp == false) {
1431: return false;
1432: }
1433: }
1.45 ng 1434:
1.71 ng 1435: formname.submit();
1436: }
1437: </script>
1438: SUBJAVASCRIPT
1439: }
1.45 ng 1440:
1.71 ng 1441: #--- javascript for essay type problem --
1442: sub sub_page_kw_js {
1443: my $request = shift;
1.80 ng 1444: my $iconpath = $request->dir_config('lonIconsURL');
1.118 ng 1445: &commonJSfunctions($request);
1.350 albertel 1446:
1.351 albertel 1447: my $inner_js_msg_central=<<INNERJS;
1.350 albertel 1448: <script text="text/javascript">
1449: function checkInput() {
1450: opener.document.SCORE.msgsub.value = opener.checkEntities(document.msgcenter.msgsub.value);
1451: var nmsg = opener.document.SCORE.savemsgN.value;
1452: var usrctr = document.msgcenter.usrctr.value;
1453: var newval = opener.document.SCORE["newmsg"+usrctr];
1454: newval.value = opener.checkEntities(document.msgcenter.newmsg.value);
1455:
1456: var msgchk = "";
1457: if (document.msgcenter.subchk.checked) {
1458: msgchk = "msgsub,";
1459: }
1460: var includemsg = 0;
1461: for (var i=1; i<=nmsg; i++) {
1462: var opnmsg = opener.document.SCORE["savemsg"+i];
1463: var frmmsg = document.msgcenter["msg"+i];
1464: opnmsg.value = opener.checkEntities(frmmsg.value);
1465: var showflg = opener.document.SCORE["shownOnce"+i];
1466: showflg.value = "1";
1467: var chkbox = document.msgcenter["msgn"+i];
1468: if (chkbox.checked) {
1469: msgchk += "savemsg"+i+",";
1470: includemsg = 1;
1471: }
1472: }
1473: if (document.msgcenter.newmsgchk.checked) {
1474: msgchk += "newmsg"+usrctr;
1475: includemsg = 1;
1476: }
1477: imgformname = opener.document.SCORE["mailicon"+usrctr];
1478: imgformname.src = "$iconpath/"+((includemsg) ? "mailto.gif" : "mailbkgrd.gif");
1479: var includemsg = opener.document.SCORE["includemsg"+usrctr];
1480: includemsg.value = msgchk;
1481:
1482: self.close()
1483:
1484: }
1485: </script>
1486: INNERJS
1487:
1.351 albertel 1488: my $inner_js_highlight_central=<<INNERJS;
1489: <script type="text/javascript">
1490: function updateChoice(flag) {
1491: opener.document.SCORE.kwclr.value = opener.radioSelection(document.hlCenter.kwdclr);
1492: opener.document.SCORE.kwsize.value = opener.radioSelection(document.hlCenter.kwdsize);
1493: opener.document.SCORE.kwstyle.value = opener.radioSelection(document.hlCenter.kwdstyle);
1494: opener.document.SCORE.refresh.value = "on";
1495: if (opener.document.SCORE.keywords.value!=""){
1496: opener.document.SCORE.submit();
1497: }
1498: self.close()
1499: }
1500: </script>
1501: INNERJS
1502:
1503: my $start_page_msg_central =
1504: &Apache::loncommon::start_page('Message Central',$inner_js_msg_central,
1505: {'js_ready' => 1,
1506: 'only_body' => 1,
1507: 'bgcolor' =>'#FFFFFF',});
1508: my $end_page_msg_central =
1509: &Apache::loncommon::end_page({'js_ready' => 1});
1510:
1511:
1512: my $start_page_highlight_central =
1513: &Apache::loncommon::start_page('Highlight Central',
1514: $inner_js_highlight_central,
1.350 albertel 1515: {'js_ready' => 1,
1516: 'only_body' => 1,
1517: 'bgcolor' =>'#FFFFFF',});
1.351 albertel 1518: my $end_page_highlight_central =
1.350 albertel 1519: &Apache::loncommon::end_page({'js_ready' => 1});
1520:
1.219 www 1521: my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
1.236 albertel 1522: $docopen=~s/^document\.//;
1.596.2.12.2. 6(raebur 1523:6): my %js_lt = &Apache::lonlocal::texthash(
1.596.2.4 raeburn 1524: keyw => 'Keywords list, separated by a space. Add/delete to list if desired.',
1525: plse => 'Please select a word or group of words from document and then click this link.',
1526: adds => 'Add selection to keyword list? Edit if desired.',
1.596.2.12.2. 6(raebur 1527:6): col1 => 'red',
1528:6): col2 => 'green',
1529:6): col3 => 'blue',
1530:6): siz1 => 'normal',
1531:6): siz2 => '+1',
1532:6): siz3 => '+2',
1533:6): sty1 => 'normal',
1534:6): sty2 => 'italic',
1535:6): sty3 => 'bold',
1536:6): );
1537:6): my %html_js_lt = &Apache::lonlocal::texthash(
1.596.2.4 raeburn 1538: comp => 'Compose Message for: ',
1539: incl => 'Include',
1540: type => 'Type',
1541: subj => 'Subject',
1542: mesa => 'Message',
1543: new => 'New',
1544: save => 'Save',
1545: canc => 'Cancel',
1546: kehi => 'Keyword Highlight Options',
1547: txtc => 'Text Color',
1548: font => 'Font Size',
1549: fnst => 'Font Style',
1550: );
1.596.2.12.2. 6(raebur 1551:6): &js_escape(\%js_lt);
1552:6): &html_escape(\%html_js_lt);
1553:6): &js_escape(\%html_js_lt);
1.71 ng 1554: $request->print(<<SUBJAVASCRIPT);
1555: <script type="text/javascript" language="javascript">
1.45 ng 1556:
1.44 ng 1557: //===================== Show list of keywords ====================
1.122 ng 1558: function keywords(formname) {
1.596.2.12.2. 6(raebur 1559:6): var nret = prompt("$js_lt{'keyw'}",formname.keywords.value);
1.44 ng 1560: if (nret==null) return;
1.122 ng 1561: formname.keywords.value = nret;
1.44 ng 1562:
1.122 ng 1563: if (formname.keywords.value != "") {
1.128 ng 1564: formname.refresh.value = "on";
1.122 ng 1565: formname.submit();
1.44 ng 1566: }
1567: return;
1568: }
1569:
1570: //===================== Script to view submitted by ==================
1571: function viewSubmitter(submitter) {
1572: document.SCORE.refresh.value = "on";
1573: document.SCORE.NCT.value = "1";
1574: document.SCORE.unamedom0.value = submitter;
1575: document.SCORE.submit();
1576: return;
1577: }
1578:
1579: //===================== Script to add keyword(s) ==================
1580: function getSel() {
1581: if (document.getSelection) txt = document.getSelection();
1582: else if (document.selection) txt = document.selection.createRange().text;
1583: else return;
1584: var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
1585: if (cleantxt=="") {
1.596.2.12.2. 6(raebur 1586:6): alert("$js_lt{'plse'}");
1.44 ng 1587: return;
1588: }
1.596.2.12.2. 6(raebur 1589:6): var nret = prompt("$js_lt{'adds'}",cleantxt);
1.44 ng 1590: if (nret==null) return;
1.127 ng 1591: document.SCORE.keywords.value = document.SCORE.keywords.value+" "+nret;
1.44 ng 1592: if (document.SCORE.keywords.value != "") {
1.127 ng 1593: document.SCORE.refresh.value = "on";
1.44 ng 1594: document.SCORE.submit();
1595: }
1596: return;
1597: }
1598:
1599: //====================== Script for composing message ==============
1.80 ng 1600: // preload images
1601: img1 = new Image();
1602: img1.src = "$iconpath/mailbkgrd.gif";
1603: img2 = new Image();
1604: img2.src = "$iconpath/mailto.gif";
1605:
1.44 ng 1606: function msgCenter(msgform,usrctr,fullname) {
1607: var Nmsg = msgform.savemsgN.value;
1608: savedMsgHeader(Nmsg,usrctr,fullname);
1609: var subject = msgform.msgsub.value;
1.127 ng 1610: var msgchk = document.SCORE["includemsg"+usrctr].value;
1.44 ng 1611: re = /msgsub/;
1612: var shwsel = "";
1613: if (re.test(msgchk)) { shwsel = "checked" }
1.123 ng 1614: subject = (document.SCORE.shownSub.value == 0 ? checkEntities(subject) : subject);
1615: displaySubject(checkEntities(subject),shwsel);
1.44 ng 1616: for (var i=1; i<=Nmsg; i++) {
1.123 ng 1617: var testmsg = "savemsg"+i+",";
1618: re = new RegExp(testmsg,"g");
1.44 ng 1619: shwsel = "";
1620: if (re.test(msgchk)) { shwsel = "checked" }
1.125 ng 1621: var message = document.SCORE["savemsg"+i].value;
1.126 ng 1622: message = (document.SCORE["shownOnce"+i].value == 0 ? checkEntities(message) : message);
1.123 ng 1623: displaySavedMsg(i,message,shwsel); //I do not get it. w/o checkEntities on saved messages,
1624: //any < is already converted to <, etc. However, only once!!
1.44 ng 1625: }
1.125 ng 1626: newmsg = document.SCORE["newmsg"+usrctr].value;
1.44 ng 1627: shwsel = "";
1628: re = /newmsg/;
1629: if (re.test(msgchk)) { shwsel = "checked" }
1630: newMsg(newmsg,shwsel);
1631: msgTail();
1632: return;
1633: }
1634:
1.123 ng 1635: function checkEntities(strx) {
1636: if (strx.length == 0) return strx;
1637: var orgStr = ["&", "<", ">", '"'];
1638: var newStr = ["&", "<", ">", """];
1639: var counter = 0;
1640: while (counter < 4) {
1641: strx = strReplace(strx,orgStr[counter],newStr[counter]);
1642: counter++;
1643: }
1644: return strx;
1645: }
1646:
1647: function strReplace(strx, orgStr, newStr) {
1648: return strx.split(orgStr).join(newStr);
1649: }
1650:
1.44 ng 1651: function savedMsgHeader(Nmsg,usrctr,fullname) {
1.76 ng 1652: var height = 70*Nmsg+250;
1.44 ng 1653: if (height > 600) {
1654: height = 600;
1655: }
1.118 ng 1656: var xpos = (screen.width-600)/2;
1657: xpos = (xpos < 0) ? '0' : xpos;
1658: var ypos = (screen.height-height)/2-30;
1659: ypos = (ypos < 0) ? '0' : ypos;
1660:
1.596.2.12.2. (raeburn 1661:): pWin = window.open('', 'MessageCenter', 'resizable=yes,toolbar=no,location=no,scrollbars=yes,screenx='+xpos+',screeny='+ypos+',width=700,height='+height);
1.76 ng 1662: pWin.focus();
1663: pDoc = pWin.document;
1.219 www 1664: pDoc.$docopen;
1.351 albertel 1665: pDoc.write('$start_page_msg_central');
1.76 ng 1666:
1667: pDoc.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
1668: pDoc.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
1.596.2.12.2. 6(raebur 1669:6): pDoc.write("<h3><span class=\\"LC_info\\"> $html_js_lt{'comp'}\"+fullname+\"<\\/span><\\/h3><br /><br />");
1.76 ng 1670:
1.564 bisitz 1671: pDoc.write('<table border="0" width="100%"><tr><td bgcolor="#777777">');
1672: pDoc.write('<table border="0" width="100%"><tr bgcolor="#DDFFFF">');
1.596.2.12.2. 6(raebur 1673:6): pDoc.write("<td><b>$html_js_lt{'type'}<\\/b><\\/td><td><b>$html_js_lt{'incl'}<\\/b><\\/td><td><b>$html_js_lt{'mesa'}<\\/td><\\/tr>");
1.44 ng 1674: }
1675: function displaySubject(msg,shwsel) {
1.76 ng 1676: pDoc = pWin.document;
1677: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.596.2.12.2. 6(raebur 1678:6): pDoc.write("<td>$html_js_lt{'subj'}<\\/td>");
1.465 albertel 1679: pDoc.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1680: pDoc.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+"\\"size=\\"60\\" maxlength=\\"80\\"><\\/td><\\/tr>");
1.44 ng 1681: }
1682:
1.72 ng 1683: function displaySavedMsg(ctr,msg,shwsel) {
1.76 ng 1684: pDoc = pWin.document;
1685: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.465 albertel 1686: pDoc.write("<td align=\\"center\\">"+ctr+"<\\/td>");
1687: pDoc.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1688: pDoc.write("<td><textarea name=\\"msg"+ctr+"\\" cols=\\"60\\" rows=\\"3\\">"+msg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 1689: }
1690:
1691: function newMsg(newmsg,shwsel) {
1.76 ng 1692: pDoc = pWin.document;
1693: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.596.2.12.2. 6(raebur 1694:6): pDoc.write("<td align=\\"center\\">$html_js_lt{'new'}<\\/td>");
1.465 albertel 1695: pDoc.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1696: pDoc.write("<td><textarea name=\\"newmsg\\" cols=\\"60\\" rows=\\"3\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" >"+newmsg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 1697: }
1698:
1699: function msgTail() {
1.76 ng 1700: pDoc = pWin.document;
1.465 albertel 1701: pDoc.write("<\\/table>");
1702: pDoc.write("<\\/td><\\/tr><\\/table> ");
1.596.2.12.2. 6(raebur 1703:6): pDoc.write("<input type=\\"button\\" value=\\"$html_js_lt{'save'}\\" onclick=\\"javascript:checkInput()\\"> ");
1704:6): pDoc.write("<input type=\\"button\\" value=\\"$html_js_lt{'canc'}\\" onclick=\\"self.close()\\"><br /><br />");
1.465 albertel 1705: pDoc.write("<\\/form>");
1.351 albertel 1706: pDoc.write('$end_page_msg_central');
1.128 ng 1707: pDoc.close();
1.44 ng 1708: }
1709:
1710: //====================== Script for keyword highlight options ==============
1711: function kwhighlight() {
1712: var kwclr = document.SCORE.kwclr.value;
1713: var kwsize = document.SCORE.kwsize.value;
1714: var kwstyle = document.SCORE.kwstyle.value;
1715: var redsel = "";
1716: var grnsel = "";
1717: var blusel = "";
1.596.2.12.2. 6(raebur 1718:6): var txtcol1 = "$js_lt{'col1'}";
1719:6): var txtcol2 = "$js_lt{'col2'}";
1720:6): var txtcol3 = "$js_lt{'col3'}";
1721:6): var txtsiz1 = "$js_lt{'siz1'}";
1722:6): var txtsiz2 = "$js_lt{'siz2'}";
1723:6): var txtsiz3 = "$js_lt{'siz3'}";
1724:6): var txtsty1 = "$js_lt{'sty1'}";
1725:6): var txtsty2 = "$js_lt{'sty2'}";
1726:6): var txtsty3 = "$js_lt{'sty3'}";
8(raebur 1727:4): if (kwclr=="red") {var redsel="checked='checked'"};
1728:4): if (kwclr=="green") {var grnsel="checked='checked'"};
1729:4): if (kwclr=="blue") {var blusel="checked='checked'"};
1.44 ng 1730: var sznsel = "";
1731: var sz1sel = "";
1732: var sz2sel = "";
1.596.2.12.2. 8(raebur 1733:4): if (kwsize=="0") {var sznsel="checked='checked'"};
1734:4): if (kwsize=="+1") {var sz1sel="checked='checked'"};
1735:4): if (kwsize=="+2") {var sz2sel="checked='checked'"};
1.44 ng 1736: var synsel = "";
1737: var syisel = "";
1738: var sybsel = "";
1.596.2.12.2. 8(raebur 1739:4): if (kwstyle=="") {var synsel="checked='checked'"};
1740:4): if (kwstyle=="<i>") {var syisel="checked='checked'"};
1741:4): if (kwstyle=="<b>") {var sybsel="checked='checked'"};
1.44 ng 1742: highlightCentral();
1.596.2.12.2. 8(raebur 1743:4): highlightbody('red',txtcol1,redsel,'0',txtsiz1,sznsel,'',txtsty1,synsel);
1744:4): highlightbody('green',txtcol2,grnsel,'+1',txtsiz2,sz1sel,'<i>',txtsty2,syisel);
1745:4): highlightbody('blue',txtcol3,blusel,'+2',txtsiz3,sz2sel,'<b>',txtsty3,sybsel);
1.44 ng 1746: highlightend();
1747: return;
1748: }
1749:
1750: function highlightCentral() {
1.76 ng 1751: // if (window.hwdWin) window.hwdWin.close();
1.118 ng 1752: var xpos = (screen.width-400)/2;
1753: xpos = (xpos < 0) ? '0' : xpos;
1754: var ypos = (screen.height-330)/2-30;
1755: ypos = (ypos < 0) ? '0' : ypos;
1756:
1.206 albertel 1757: hwdWin = window.open('', 'KeywordHighlightCentral', 'resizeable=yes,toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx='+xpos+',screeny='+ypos);
1.76 ng 1758: hwdWin.focus();
1759: var hDoc = hwdWin.document;
1.219 www 1760: hDoc.$docopen;
1.351 albertel 1761: hDoc.write('$start_page_highlight_central');
1.76 ng 1762: hDoc.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
1.596.2.12.2. 6(raebur 1763:6): hDoc.write("<h1>$html_js_lt{'kehi'}<\\/h1>");
1.76 ng 1764:
1.596.2.12.2. 8(raebur 1765:4): hDoc.write('<table border="0" width="100%"><tr style="background-color:#A1D676">');
6(raebur 1766:6): hDoc.write("<th>$html_js_lt{'txtc'}<\\/th><th>$html_js_lt{'font'}<\\/th><th>$html_js_lt{'fnst'}<\\/th><\\/tr>");
1.44 ng 1767: }
1768:
1769: function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) {
1.76 ng 1770: var hDoc = hwdWin.document;
1.596.2.12.2. 8(raebur 1771:4): hDoc.write("<tr>");
1.76 ng 1772: hDoc.write("<td align=\\"left\\">");
1.596.2.12.2. 8(raebur 1773:4): hDoc.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+" \\/> "+clrtxt+"<\\/td>");
1.76 ng 1774: hDoc.write("<td align=\\"left\\">");
1.596.2.12.2. 8(raebur 1775:4): hDoc.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+" \\/> "+sztxt+"<\\/td>");
1.76 ng 1776: hDoc.write("<td align=\\"left\\">");
1.596.2.12.2. 8(raebur 1777:4): hDoc.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+" \\/> "+sytxt+"<\\/td>");
1.465 albertel 1778: hDoc.write("<\\/tr>");
1.44 ng 1779: }
1780:
1781: function highlightend() {
1.76 ng 1782: var hDoc = hwdWin.document;
1.596.2.12.2. 8(raebur 1783:4): hDoc.write("<\\/table><br \\/>");
6(raebur 1784:6): hDoc.write("<input type=\\"button\\" value=\\"$html_js_lt{'save'}\\" onclick=\\"javascript:updateChoice(1)\\" \\/> ");
1785:6): hDoc.write("<input type=\\"button\\" value=\\"$html_js_lt{'canc'}\\" onclick=\\"self.close()\\" \\/><br /><br />");
1.465 albertel 1786: hDoc.write("<\\/form>");
1.351 albertel 1787: hDoc.write('$end_page_highlight_central');
1.128 ng 1788: hDoc.close();
1.44 ng 1789: }
1790:
1791: </script>
1792: SUBJAVASCRIPT
1793: }
1794:
1.349 albertel 1795: sub get_increment {
1.348 bowersj2 1796: my $increment = $env{'form.increment'};
1797: if ($increment != 1 && $increment != .5 && $increment != .25 &&
1798: $increment != .1) {
1799: $increment = 1;
1800: }
1801: return $increment;
1802: }
1803:
1.585 bisitz 1804: sub gradeBox_start {
1805: return (
1806: &Apache::loncommon::start_data_table()
1807: .&Apache::loncommon::start_data_table_header_row()
1808: .'<th>'.&mt('Part').'</th>'
1809: .'<th>'.&mt('Points').'</th>'
1810: .'<th> </th>'
1811: .'<th>'.&mt('Assign Grade').'</th>'
1812: .'<th>'.&mt('Weight').'</th>'
1813: .'<th>'.&mt('Grade Status').'</th>'
1814: .&Apache::loncommon::end_data_table_header_row()
1815: );
1816: }
1817:
1818: sub gradeBox_end {
1819: return (
1820: &Apache::loncommon::end_data_table()
1821: );
1822: }
1.71 ng 1823: #--- displays the grading box, used in essay type problem and grading by page/sequence
1824: sub gradeBox {
1.322 albertel 1825: my ($request,$symb,$uname,$udom,$counter,$partid,$record) = @_;
1.381 albertel 1826: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 1827: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 1828: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
1.466 albertel 1829: my $wgtmsg = ($wgt > 0) ? &mt('(problem weight)')
1830: : '<span class="LC_info">'.&mt('problem weight assigned by computer').'</span>';
1.71 ng 1831: $wgt = ($wgt > 0 ? $wgt : '1');
1832: my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
1.320 albertel 1833: '' : &compute_points($$record{'resource.'.$partid.'.awarded'},$wgt));
1.596.2.12.2. 8(raebur 1834:3): my $data_WGT='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />'."\n";
1.466 albertel 1835: my $display_part= &get_display_part($partid,$symb);
1.270 albertel 1836: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
1837: [$partid]);
1838: my $aggtries = $$record{'resource.'.$partid.'.tries'};
1.269 raeburn 1839: if ($last_resets{$partid}) {
1840: $aggtries = &get_num_tries($record,$last_resets{$partid},$partid);
1841: }
1.596.2.12.2. 8(raebur 1842:3): my $result=&Apache::loncommon::start_data_table_row();
1.71 ng 1843: my $ctr = 0;
1.348 bowersj2 1844: my $thisweight = 0;
1.349 albertel 1845: my $increment = &get_increment();
1.485 albertel 1846:
1847: my $radio.='<table border="0"><tr>'."\n"; # display radio buttons in a nice table 10 across
1.348 bowersj2 1848: while ($thisweight<=$wgt) {
1.532 bisitz 1849: $radio.= '<td><span class="LC_nobreak"><label><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
1.589 bisitz 1850: 'onclick="javascript:writeBox(this.form,\''.$counter.'_'.$partid.'\','.
1.348 bowersj2 1851: $thisweight.')" value="'.$thisweight.'" '.
1.401 albertel 1852: ($score eq $thisweight ? 'checked="checked"':'').' /> '.$thisweight."</label></span></td>\n";
1.485 albertel 1853: $radio.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1.348 bowersj2 1854: $thisweight += $increment;
1.71 ng 1855: $ctr++;
1856: }
1.485 albertel 1857: $radio.='</tr></table>';
1858:
1859: my $line.='<input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
1.71 ng 1860: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
1.589 bisitz 1861: 'onchange="javascript:updateRadio(this.form,\''.$counter.'_'.$partid.'\','.
1.71 ng 1862: $wgt.')" /></td>'."\n";
1.485 albertel 1863: $line.='<td>/'.$wgt.' '.$wgtmsg.
1.71 ng 1864: ($$record{'resource.'.$partid.'.solved'} eq 'correct_by_student' ? ' '.$checkIcon : '').
1.585 bisitz 1865: ' </td>'."\n";
1866: $line.='<td><select name="GD_SEL'.$counter.'_'.$partid.'" '.
1.589 bisitz 1867: 'onchange="javascript:clearRadBox(this.form,\''.$counter.'_'.$partid.'\')" >'."\n";
1.71 ng 1868: if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
1.485 albertel 1869: $line.='<option></option>'.
1870: '<option value="excused" selected="selected">'.&mt('excused').'</option>';
1.71 ng 1871: } else {
1.485 albertel 1872: $line.='<option selected="selected"></option>'.
1873: '<option value="excused" >'.&mt('excused').'</option>';
1.71 ng 1874: }
1.485 albertel 1875: $line.='<option value="reset status">'.&mt('reset status').'</option></select>'."\n";
1876:
1877:
1878: $result .=
1.596.2.12.2. 8(raebur 1879:3): '<td>'.$data_WGT.$display_part.'</td><td>'.$radio.'</td><td>'.&mt('or').'</td><td>'.$line.'</td>';
1880:3): $result.=&Apache::loncommon::end_data_table_row().'<td colspan="6">';
1.71 ng 1881: $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="" />'."\n".
1882: '<input type="hidden" name="oldpts'.$counter.'_'.$partid.'" value="'.$score.'" />'."\n".
1883: '<input type="hidden" name="solved'.$counter.'_'.$partid.'" value="'.
1.269 raeburn 1884: $$record{'resource.'.$partid.'.solved'}.'" />'."\n".
1885: '<input type="hidden" name="totaltries'.$counter.'_'.$partid.'" value="'.
1886: $$record{'resource.'.$partid.'.tries'}.'" />'."\n".
1887: '<input type="hidden" name="aggtries'.$counter.'_'.$partid.'" value="'.
1888: $aggtries.'" />'."\n";
1.582 raeburn 1889: my $res_error;
1890: $result.=&handback_box($symb,$uname,$udom,$counter,$partid,$record,\$res_error);
1.596.2.12.2. 8(raebur 1891:3): $result.='</td>'.&Apache::loncommon::end_data_table_row();
1.582 raeburn 1892: if ($res_error) {
1893: return &navmap_errormsg();
1894: }
1.318 banghart 1895: return $result;
1896: }
1.322 albertel 1897:
1898: sub handback_box {
1.582 raeburn 1899: my ($symb,$uname,$udom,$counter,$partid,$record,$res_error) = @_;
1900: my ($partlist,$handgrade,$responseType) = &response_type($symb,$res_error);
1.323 banghart 1901: my (@respids);
1.596.2.4 raeburn 1902: my @part_response_id = &flatten_responseType($responseType);
1.375 albertel 1903: foreach my $part_response_id (@part_response_id) {
1904: my ($part,$resp) = @{ $part_response_id };
1.323 banghart 1905: if ($part eq $partid) {
1.375 albertel 1906: push(@respids,$resp);
1.323 banghart 1907: }
1908: }
1.318 banghart 1909: my $result;
1.323 banghart 1910: foreach my $respid (@respids) {
1.322 albertel 1911: my $prefix = $counter.'_'.$partid.'_'.$respid.'_';
1912: my $files=&get_submitted_files($udom,$uname,$partid,$respid,$record);
1913: next if (!@$files);
1.596.2.4 raeburn 1914: my $file_counter = 0;
1.313 banghart 1915: foreach my $file (@$files) {
1.368 banghart 1916: if ($file =~ /\/portfolio\//) {
1.596.2.4 raeburn 1917: $file_counter++;
1.368 banghart 1918: my ($file_path, $file_disp) = ($file =~ m|(.+/)(.+)$|);
1919: my ($name,$version,$ext) = &file_name_version_ext($file_disp);
1920: $file_disp = "$name.$ext";
1921: $file = $file_path.$file_disp;
1922: $result.=&mt('Return commented version of [_1] to student.',
1923: '<span class="LC_filename">'.$file_disp.'</span>');
1924: $result.='<input type="file" name="'.$prefix.'returndoc'.$file_counter.'" />'."\n";
1.596.2.4 raeburn 1925: $result.='<input type="hidden" name="'.$prefix.'origdoc'.$file_counter.'" value="'.$file.'" /><br />'."\n";
1.368 banghart 1926: }
1.322 albertel 1927: }
1.596.2.4 raeburn 1928: if ($file_counter) {
1929: $result .= '<input type="hidden" name="'.$prefix.'countreturndoc" value="'.$file_counter.'" />'."\n".
1930: '<span class="LC_info">'.
1931: '('.&mt('File(s) will be uploaded when you click on Save & Next below.',$file_counter).')</span><br /><br />';
1932: }
1.313 banghart 1933: }
1.318 banghart 1934: return $result;
1.71 ng 1935: }
1.44 ng 1936:
1.58 albertel 1937: sub show_problem {
1.382 albertel 1938: my ($request,$symb,$uname,$udom,$removeform,$viewon,$mode,$form) = @_;
1.144 albertel 1939: my $rendered;
1.382 albertel 1940: my %form = ((ref($form) eq 'HASH')? %{$form} : ());
1.329 albertel 1941: &Apache::lonxml::remember_problem_counter();
1.144 albertel 1942: if ($mode eq 'both' or $mode eq 'text') {
1943: $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
1.382 albertel 1944: $env{'request.course.id'},
1945: undef,\%form);
1.144 albertel 1946: }
1.58 albertel 1947: if ($removeform) {
1948: $rendered=~s|<form(.*?)>||g;
1949: $rendered=~s|</form>||g;
1.374 albertel 1950: $rendered=~s|(<input[^>]*name\s*=\s*"?)(\w+)("?)|$1would_have_been_$2$3|g;
1.58 albertel 1951: }
1.144 albertel 1952: my $companswer;
1953: if ($mode eq 'both' or $mode eq 'answer') {
1.329 albertel 1954: &Apache::lonxml::restore_problem_counter();
1.382 albertel 1955: $companswer=
1956: &Apache::loncommon::get_student_answers($symb,$uname,$udom,
1957: $env{'request.course.id'},
1958: %form);
1.144 albertel 1959: }
1.58 albertel 1960: if ($removeform) {
1961: $companswer=~s|<form(.*?)>||g;
1962: $companswer=~s|</form>||g;
1.144 albertel 1963: $companswer=~s|name="submit"|name="would_have_been_submit"|g;
1.58 albertel 1964: }
1.596.2.12.2. (raeburn 1965:): my $renderheading = &mt('View of the problem');
1966:): my $answerheading = &mt('Correct answer');
1967:): if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1968:): my $stu_fullname = $env{'form.fullname'};
1969:): if ($stu_fullname eq '') {
1970:): $stu_fullname = &Apache::loncommon::plainname($uname,$udom,'lastname');
1971:): }
1972:): my $forwhom = &nameUserString(undef,$stu_fullname,$uname,$udom);
1973:): if ($forwhom ne '') {
1974:): $renderheading = &mt('View of the problem for[_1]',$forwhom);
1975:): $answerheading = &mt('Correct answer for[_1]',$forwhom);
1976:): }
1977:): }
1.468 albertel 1978: $rendered=
1.588 bisitz 1979: '<div class="LC_Box">'
1.596.2.12.2. (raeburn 1980:): .'<h3 class="LC_hcell">'.$renderheading.'</h3>'
1.588 bisitz 1981: .$rendered
1982: .'</div>';
1.468 albertel 1983: $companswer=
1.588 bisitz 1984: '<div class="LC_Box">'
1.596.2.12.2. (raeburn 1985:): .'<h3 class="LC_hcell">'.$answerheading.'</h3>'
1.588 bisitz 1986: .$companswer
1987: .'</div>';
1.468 albertel 1988: my $result;
1.144 albertel 1989: if ($mode eq 'both') {
1.588 bisitz 1990: $result=$rendered.$companswer;
1.144 albertel 1991: } elsif ($mode eq 'text') {
1.588 bisitz 1992: $result=$rendered;
1.144 albertel 1993: } elsif ($mode eq 'answer') {
1.588 bisitz 1994: $result=$companswer;
1.144 albertel 1995: }
1.71 ng 1996: return $result;
1.58 albertel 1997: }
1.397 albertel 1998:
1.396 banghart 1999: sub files_exist {
2000: my ($r, $symb) = @_;
2001: my @students = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.397 albertel 2002:
1.396 banghart 2003: foreach my $student (@students) {
2004: my ($uname,$udom,$fullname) = split(/:/,$student);
1.397 albertel 2005: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
2006: $udom,$uname);
1.396 banghart 2007: my ($string,$timestamp)= &get_last_submission(\%record);
1.397 albertel 2008: foreach my $submission (@$string) {
2009: my ($partid,$respid) =
2010: ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
2011: my $files=&get_submitted_files($udom,$uname,$partid,$respid,
2012: \%record);
2013: return 1 if (@$files);
1.396 banghart 2014: }
2015: }
1.397 albertel 2016: return 0;
1.396 banghart 2017: }
1.397 albertel 2018:
1.394 banghart 2019: sub download_all_link {
2020: my ($r,$symb) = @_;
1.395 albertel 2021: my $all_students =
2022: join("\n", &Apache::loncommon::get_env_multiple('form.stuinfo'));
2023:
2024: my $parts =
2025: join("\n",&Apache::loncommon::get_env_multiple('form.vPart'));
2026:
1.394 banghart 2027: my $identifier = &Apache::loncommon::get_cgi_id();
1.514 raeburn 2028: &Apache::lonnet::appenv({'cgi.'.$identifier.'.students' => $all_students,
2029: 'cgi.'.$identifier.'.symb' => $symb,
2030: 'cgi.'.$identifier.'.parts' => $parts,});
1.395 albertel 2031: $r->print('<a href="/cgi-bin/multidownload.pl?'.$identifier.'">'.
2032: &mt('Download All Submitted Documents').'</a>');
1.394 banghart 2033: return
2034: }
1.395 albertel 2035:
1.432 banghart 2036: sub build_section_inputs {
2037: my $section_inputs;
2038: if ($env{'form.section'} eq '') {
2039: $section_inputs .= '<input type="hidden" name="section" value="all" />'."\n";
2040: } else {
2041: my @sections = &Apache::loncommon::get_env_multiple('form.section');
1.434 albertel 2042: foreach my $section (@sections) {
1.432 banghart 2043: $section_inputs .= '<input type="hidden" name="section" value="'.$section.'" />'."\n";
2044: }
2045: }
2046: return $section_inputs;
2047: }
2048:
1.44 ng 2049: # --------------------------- show submissions of a student, option to grade
2050: sub submission {
2051: my ($request,$counter,$total) = @_;
1.257 albertel 2052: my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
2053: $udom = ($udom eq '' ? $env{'user.domain'} : $udom); #has form.userdom changed for a student?
2054: my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
2055: $env{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $env{'form.fullname'} eq '';
1.596.2.12.2. (raeburn 2056:): my ($symb) = &get_symb($request);
1.324 albertel 2057: if ($symb eq '') { $request->print("Unable to handle ambiguous references:."); return ''; }
1.596.2.12.2. 5(raebur 2058:9): my ($essayurl,%coursedesc_by_cid);
1.104 albertel 2059:
2060: if (!&canview($usec)) {
1.596.2.12.2. 8(raebur 2061:4): $request->print(
2062:4): '<span class="LC_warning">'.
2063:4): &mt('Unable to view requested student.').
2064:4): ' '.&mt('([_1] in section [_2] in course id [_3])',
2065:4): $uname.':'.$udom,$usec,$env{'request.course.id'}).
2066:4): '</span>');
1.324 albertel 2067: $request->print(&show_grading_menu_form($symb));
1.104 albertel 2068: return;
2069: }
2070:
1.257 albertel 2071: if (!$env{'form.lastSub'}) { $env{'form.lastSub'} = 'datesub'; }
2072: if (!$env{'form.vProb'}) { $env{'form.vProb'} = 'yes'; }
2073: if (!$env{'form.vAns'}) { $env{'form.vAns'} = 'yes'; }
2074: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.381 albertel 2075: my $checkIcon = '<img alt="'.&mt('Check Mark').
2076: '" src="'.$request->dir_config('lonIconsURL').
1.122 ng 2077: '/check.gif" height="16" border="0" />';
1.41 ng 2078:
2079: # header info
2080: if ($counter == 0) {
2081: &sub_page_js($request);
1.257 albertel 2082: &sub_page_kw_js($request) if ($env{'form.handgrade'} eq 'yes');
2083: $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
2084: &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
1.397 albertel 2085: if ($env{'form.handgrade'} eq 'yes' && &files_exist($request, $symb)) {
1.396 banghart 2086: &download_all_link($request, $symb);
2087: }
1.485 albertel 2088: $request->print('<h3> <span class="LC_info">'.&mt('Submission Record').'</span></h3>'."\n".
1.596.2.12.2. 2(raebur 2089:3): '<h4> '.&mt('[_1]Resource: [_2]','<b>','</b>'.$env{'form.probTitle'}).'</h4>'."\n");
1.118 ng 2090:
1.44 ng 2091: # option to display problem, only once else it cause problems
2092: # with the form later since the problem has a form.
1.257 albertel 2093: if ($env{'form.vProb'} eq 'yes' or $env{'form.vAns'} eq 'yes') {
1.144 albertel 2094: my $mode;
1.257 albertel 2095: if ($env{'form.vProb'} eq 'yes' && $env{'form.vAns'} eq 'yes') {
1.144 albertel 2096: $mode='both';
1.257 albertel 2097: } elsif ($env{'form.vProb'} eq 'yes') {
1.144 albertel 2098: $mode='text';
1.257 albertel 2099: } elsif ($env{'form.vAns'} eq 'yes') {
1.144 albertel 2100: $mode='answer';
2101: }
1.329 albertel 2102: &Apache::lonxml::clear_problem_counter();
1.144 albertel 2103: $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
1.41 ng 2104: }
1.441 www 2105:
1.596.2.12.2. 0(raebur 2106:3): # kwclr is the only variable that is guaranteed not to be blank
1.44 ng 2107: # if this subroutine has been called once.
1.41 ng 2108: my %keyhash = ();
1.257 albertel 2109: if ($env{'form.kwclr'} eq '' && $env{'form.handgrade'} eq 'yes') {
1.41 ng 2110: %keyhash = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 2111: $env{'course.'.$env{'request.course.id'}.'.domain'},
2112: $env{'course.'.$env{'request.course.id'}.'.num'});
1.41 ng 2113:
1.257 albertel 2114: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
2115: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
2116: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
2117: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
2118: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
2119: $env{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
2120: $keyhash{$symb.'_subject'} : $env{'form.probTitle'};
2121: $env{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1.41 ng 2122: }
1.257 albertel 2123: my $overRideScore = $env{'form.overRideScore'} eq '' ? 'no' : $env{'form.overRideScore'};
1.442 banghart 2124: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.303 banghart 2125: $request->print('<form action="/adm/grades" method="post" name="SCORE" enctype="multipart/form-data">'."\n".
1.41 ng 2126: '<input type="hidden" name="command" value="handgrade" />'."\n".
1.257 albertel 2127: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.442 banghart 2128: '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.120 ng 2129: '<input type="hidden" name="overRideScore" value="'.$overRideScore.'" />'."\n".
1.257 albertel 2130: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.41 ng 2131: '<input type="hidden" name="refresh" value="off" />'."\n".
1.120 ng 2132: '<input type="hidden" name="studentNo" value="" />'."\n".
2133: '<input type="hidden" name="gradeOpt" value="" />'."\n".
1.418 albertel 2134: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 2135: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" />'."\n".
2136: '<input type="hidden" name="vProb" value="'.$env{'form.vProb'}.'" />'."\n".
2137: '<input type="hidden" name="vAns" value="'.$env{'form.vAns'}.'" />'."\n".
2138: '<input type="hidden" name="lastSub" value="'.$env{'form.lastSub'}.'" />'."\n".
1.432 banghart 2139: &build_section_inputs().
1.326 albertel 2140: '<input type="hidden" name="submitonly" value="'.$env{'form.submitonly'}.'" />'."\n".
2141: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" />'."\n".
1.41 ng 2142: '<input type="hidden" name="NCT"'.
1.257 albertel 2143: ' value="'.($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : $total+1).'" />'."\n");
2144: if ($env{'form.handgrade'} eq 'yes') {
2145: $request->print('<input type="hidden" name="keywords" value="'.$env{'form.keywords'}.'" />'."\n".
2146: '<input type="hidden" name="kwclr" value="'.$env{'form.kwclr'}.'" />'."\n".
2147: '<input type="hidden" name="kwsize" value="'.$env{'form.kwsize'}.'" />'."\n".
2148: '<input type="hidden" name="kwstyle" value="'.$env{'form.kwstyle'}.'" />'."\n".
2149: '<input type="hidden" name="msgsub" value="'.$env{'form.msgsub'}.'" />'."\n".
1.123 ng 2150: '<input type="hidden" name="shownSub" value="0" />'."\n".
1.257 albertel 2151: '<input type="hidden" name="savemsgN" value="'.$env{'form.savemsgN'}.'" />'."\n");
1.154 albertel 2152: foreach my $partid (&Apache::loncommon::get_env_multiple('form.vPart')) {
2153: $request->print('<input type="hidden" name="vPart" value="'.$partid.'" />'."\n");
2154: }
1.123 ng 2155: }
1.41 ng 2156:
2157: my ($cts,$prnmsg) = (1,'');
1.257 albertel 2158: while ($cts <= $env{'form.savemsgN'}) {
1.41 ng 2159: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
1.123 ng 2160: (!exists($keyhash{$symb.'_savemsg'.$cts}) ?
1.257 albertel 2161: &Apache::lonfeedback::clear_out_html($env{'form.savemsg'.$cts}) :
1.80 ng 2162: &Apache::lonfeedback::clear_out_html($keyhash{$symb.'_savemsg'.$cts})).
1.123 ng 2163: '" />'."\n".
2164: '<input type="hidden" name="shownOnce'.$cts.'" value="0" />'."\n";
1.41 ng 2165: $cts++;
2166: }
2167: $request->print($prnmsg);
1.32 ng 2168:
1.257 albertel 2169: if ($env{'form.handgrade'} eq 'yes' && $env{'form.showgrading'} eq 'yes') {
1.596.2.4 raeburn 2170:
2171: my %lt = &Apache::lonlocal::texthash(
1.596.2.12.2. 8(raebur 2172:4): keyh => 'Keyword Highlighting for Essays',
1.596.2.4 raeburn 2173: keyw => 'Keyword Options',
2174: list => 'List',
2175: past => 'Paste Selection to List',
1.596.2.9 raeburn 2176: high => 'Highlight Attribute',
1.596.2.4 raeburn 2177: );
1.88 www 2178: #
2179: # Print out the keyword options line
2180: #
1.596.2.12.2. 8(raebur 2181:4): $request->print(
2182:4): '<div class="LC_columnSection">'
2183:4): .'<fieldset><legend>'.$lt{'keyh'}.'</legend>'
2184:4): .&Apache::lonhtmlcommon::funclist_from_array(
2185:4): ['<a href="javascript:keywords(document.SCORE);" target="_self">'.$lt{'list'}.'</a>',
2186:4): '<a href="#" onmousedown="javascript:getSel(); return false"
2187:4): class="page">'.$lt{'past'}.'</a>',
2188:4): '<a href="javascript:kwhighlight();" target="_self">'.$lt{'high'}.'</a>'],
2189:4): {legend => $lt{'keyw'}})
2190:4): .'</fieldset></div>'
2191:4): );
2192:4):
1.88 www 2193: #
2194: # Load the other essays for similarity check
2195: #
1.596.2.12.2. 5(raebur 2196:9): (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb);
2197:9): if ($essayurl eq 'lib/templates/simpleproblem.problem') {
2198:9): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2199:9): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2200:9): if ($cdom ne '' && $cnum ne '') {
2201:9): my ($map,$id,$res) = &Apache::lonnet::decode_symb($symb);
2202:9): if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(default(?:|_\d+)\.(?:sequence|page))$}) {
2203:9): my $apath = $1.'_'.$id;
2204:9): $apath=~s/\W/\_/gs;
2205:9): &init_old_essays($symb,$apath,$cdom,$cnum);
2206:9): }
2207:9): }
2208:9): } else {
2209:9): my ($adom,$aname,$apath)=($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
2210:9): $apath=&escape($apath);
2211:9): $apath=~s/\W/\_/gs;
2212:9): &init_old_essays($symb,$apath,$adom,$aname);
2213:9): }
1.41 ng 2214: }
2215: }
1.44 ng 2216:
1.441 www 2217: # This is where output for one specific student would start
1.592 bisitz 2218: my $add_class = ($counter%2) ? ' LC_grade_show_user_odd_row' : '';
2219: $request->print(
2220: "\n\n"
2221: .'<div class="LC_grade_show_user'.$add_class.'">'
2222: .'<h2>'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).'</h2>'
2223: ."\n"
2224: );
1.441 www 2225:
1.592 bisitz 2226: # Show additional functions if allowed
2227: if ($perm{'vgr'}) {
2228: $request->print(
2229: &Apache::loncommon::track_student_link(
1.596.2.12.2. 4(raebur 2230:3): 'View recent activity',
1.592 bisitz 2231: $uname,$udom,'check')
2232: .' '
2233: );
2234: }
2235: if ($perm{'opa'}) {
2236: $request->print(
2237: &Apache::loncommon::pprmlink(
2238: &mt('Set/Change parameters'),
2239: $uname,$udom,$symb,'check'));
2240: }
2241:
2242: # Show Problem
1.257 albertel 2243: if ($env{'form.vProb'} eq 'all' or $env{'form.vAns'} eq 'all') {
1.144 albertel 2244: my $mode;
1.257 albertel 2245: if ($env{'form.vProb'} eq 'all' && $env{'form.vAns'} eq 'all') {
1.144 albertel 2246: $mode='both';
1.257 albertel 2247: } elsif ($env{'form.vProb'} eq 'all' ) {
1.144 albertel 2248: $mode='text';
1.257 albertel 2249: } elsif ($env{'form.vAns'} eq 'all') {
1.144 albertel 2250: $mode='answer';
2251: }
1.329 albertel 2252: &Apache::lonxml::clear_problem_counter();
1.475 albertel 2253: $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode,{'request.prefix' => 'ctr'.$counter}));
1.58 albertel 2254: }
1.144 albertel 2255:
1.257 albertel 2256: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.582 raeburn 2257: my $res_error;
2258: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
2259: if ($res_error) {
2260: $request->print(&navmap_errormsg());
2261: return;
2262: }
1.41 ng 2263:
1.44 ng 2264: # Display student info
1.41 ng 2265: $request->print(($counter == 0 ? '' : '<br />'));
1.590 bisitz 2266:
2267: my $result='<div class="LC_Box">'
2268: .'<h3 class="LC_hcell">'.&mt('Submissions').'</h3>';
1.45 ng 2269: $result.='<input type="hidden" name="name'.$counter.
1.588 bisitz 2270: '" value="'.$env{'form.fullname'}.'" />'."\n";
1.469 albertel 2271: if ($env{'form.handgrade'} eq 'no') {
1.588 bisitz 2272: $result.='<p class="LC_info">'
2273: .&mt('Part(s) graded correct by the computer is marked with a [_1] symbol.',$checkIcon)
2274: ."</p>\n";
1.469 albertel 2275: }
2276:
1.118 ng 2277: # If any part of the problem is an essay-response (handgraded), then check for collaborators
1.464 albertel 2278: my $fullname;
2279: my $col_fullnames = [];
1.257 albertel 2280: if ($env{'form.handgrade'} eq 'yes') {
1.464 albertel 2281: (my $sub_result,$fullname,$col_fullnames)=
2282: &check_collaborators($symb,$uname,$udom,\%record,$handgrade,
2283: $counter);
2284: $result.=$sub_result;
1.41 ng 2285: }
1.44 ng 2286: $request->print($result."\n");
1.588 bisitz 2287:
1.44 ng 2288: # print student answer/submission
1.588 bisitz 2289: # Options are (1) Handgraded submission only
1.44 ng 2290: # (2) Last submission, includes submission that is not handgraded
2291: # (for multi-response type part)
2292: # (3) Last submission plus the parts info
2293: # (4) The whole record for this student
1.596.2.12.2. 1(raebur 2294:3):
1.151 albertel 2295: my ($string,$timestamp)= &get_last_submission(\%record);
1.468 albertel 2296:
2297: my $lastsubonly;
2298:
1.588 bisitz 2299: if ($$timestamp eq '') {
2300: $lastsubonly.='<div class="LC_grade_submissions_body">'.$$string[0].'</div>';
2301: } else {
1.592 bisitz 2302: $lastsubonly =
2303: '<div class="LC_grade_submissions_body">'
2304: .'<b>'.&mt('Date Submitted:').'</b> '.$$timestamp."\n";
1.468 albertel 2305:
1.151 albertel 2306: my %seenparts;
1.375 albertel 2307: my @part_response_id = &flatten_responseType($responseType);
2308: foreach my $part (@part_response_id) {
1.393 albertel 2309: next if ($env{'form.lastSub'} eq 'hdgrade'
2310: && $$handgrade{$$part[0].'_'.$$part[1]} ne 'yes');
2311:
1.375 albertel 2312: my ($partid,$respid) = @{ $part };
1.324 albertel 2313: my $display_part=&get_display_part($partid,$symb);
1.257 albertel 2314: if ($env{"form.$uname:$udom:$partid:submitted_by"}) {
1.151 albertel 2315: if (exists($seenparts{$partid})) { next; }
2316: $seenparts{$partid}=1;
1.596.2.12.2. 8(raebur 2317:3): $request->print(
2318:3): '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
2319:3): ' <b>'.&mt('Collaborative submission by: [_1]',
2320:3): '<a href="javascript:viewSubmitter(\''.
2321:3): $env{"form.$uname:$udom:$partid:submitted_by"}.
2322:3): '\');" target="_self">'.
2323:3): $$fullname{$env{"form.$uname:$udom:$partid:submitted_by"}}.'</a>').
2324:3): '<br />');
1.151 albertel 2325: next;
2326: }
2327: my $responsetype = $responseType->{$partid}->{$respid};
2328: if (!exists($record{"resource.$partid.$respid.submission"})) {
1.577 bisitz 2329: $lastsubonly.="\n".'<div class="LC_grade_submission_part">'.
2330: '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
2331: ' <span class="LC_internal_info">'.
1.596.2.4 raeburn 2332: '('.&mt('Response ID: [_1]',$respid).')'.
1.577 bisitz 2333: '</span> '.
1.539 riegler 2334: '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br /><br /></div>';
1.151 albertel 2335: next;
2336: }
1.468 albertel 2337: foreach my $submission (@$string) {
2338: my ($partid,$respid) = ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
1.375 albertel 2339: if (join('_',@{$part}) ne ($partid.'_'.$respid)) { next; }
1.596.2.12.2. 0(raebur 2340:4): my ($ressub,$hide,$draft,$subval) = split(/:/,$submission,4);
1.151 albertel 2341: # Similarity check
2342: my $similar='';
1.596.2.2 raeburn 2343: my ($type,$trial,$rndseed);
2344: if ($hide eq 'rand') {
2345: $type = 'randomizetry';
2346: $trial = $record{"resource.$partid.tries"};
2347: $rndseed = $record{"resource.$partid.rndseed"};
2348: }
1.596.2.12.2. 1(raebur 2349:3): if ($env{'form.checkPlag'}) {
1.151 albertel 2350: my ($oname,$odom,$ocrsid,$oessay,$osim)=
1.596.2.12.2. (raeburn 2351:): &most_similar($uname,$udom,$symb,$subval);
1.151 albertel 2352: if ($osim) {
2353: $osim=int($osim*100.0);
1.596.2.2 raeburn 2354: if ($hide eq 'anon') {
1.596 raeburn 2355: $similar='<hr /><span class="LC_warning">'.&mt("Essay was found to be similar to another essay submitted for this assignment.").'<br />'.
2356: &mt('As the current submission is for an anonymous survey, no other details are available.').'</span><hr />';
2357: } else {
1.596.2.12.2. 5(raebur 2358:9): $similar='<hr />';
2359:9): if ($essayurl eq 'lib/templates/simpleproblem.problem') {
2360:9): $similar .= '<h3><span class="LC_warning">'.
2361:9): &mt('Essay is [_1]% similar to an essay by [_2]',
2362:9): $osim,
2363:9): &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')').
2364:9): '</span></h3>';
2365:9): } elsif ($ocrsid ne '') {
6(raebur 2366:9): my %old_course_desc;
5(raebur 2367:9): if (ref($coursedesc_by_cid{$ocrsid}) eq 'HASH') {
2368:9): %old_course_desc = %{$coursedesc_by_cid{$ocrsid}};
2369:9): } else {
2370:9): my $args;
2371:9): if ($ocrsid ne $env{'request.course.id'}) {
2372:9): $args = {'one_time' => 1};
2373:9): }
2374:9): %old_course_desc =
2375:9): &Apache::lonnet::coursedescription($ocrsid,$args);
2376:9): $coursedesc_by_cid{$ocrsid} = \%old_course_desc;
2377:9): }
2378:9): $similar .=
2379:9): &mt('Essay is [_1]% similar to an essay by [_2] in course [_3] (course id [_4]:[_5])',
2380:9): $osim,
2381:9): &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')',
2382:9): $old_course_desc{'description'},
2383:9): $old_course_desc{'num'},
2384:9): $old_course_desc{'domain'}).
2385:9): '</span></h3>';
2386:9): } else {
2387:9): $similar .=
2388:9): '<h3><span class="LC_warning">'.
2389:9): &mt('Essay is [_1]% similar to an essay by [_2] in an unknown course',
2390:9): $osim,
2391:9): &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')').
2392:9): '</span></h3>';
2393:9): }
2394:9): $similar .= '<blockquote><i>'.
2395:9): &keywords_highlight($oessay).
2396:9): '</i></blockquote><hr />';
2397:9): }
2398:9): }
2399:9): }
1.596.2.2 raeburn 2400: my $order=&get_order($partid,$respid,$symb,$uname,$udom,
2401: undef,$type,$trial,$rndseed);
1.596.2.12.2. 1(raebur 2402:3): if ($env{'form.lastSub'} eq 'lastonly' || $env{'form.lastSub'} eq 'datesub' || $env{'form.lastSub'} =~ /^(last|all)$/ || ($env{'form.lastSub'} eq 'hdgrade' &&
2403:3): $$handgrade{$$part[0].'_'.$$part[1]} eq 'yes')) {
1.324 albertel 2404: my $display_part=&get_display_part($partid,$symb);
1.577 bisitz 2405: $lastsubonly.='<div class="LC_grade_submission_part">'.
2406: '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
2407: ' <span class="LC_internal_info">'.
1.596.2.4 raeburn 2408: '('.&mt('Response ID: [_1]',$respid).')'.
2409: '</span> ';
1.313 banghart 2410: my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record);
2411: if (@$files) {
1.596.2.2 raeburn 2412: if ($hide eq 'anon') {
1.596 raeburn 2413: $lastsubonly.='<br />'.&mt('[quant,_1,file] uploaded to this anonymous survey',scalar(@{$files}));
2414: } else {
1.596.2.12.2. 8(raebur 2415:3): $lastsubonly.='<br /><br />'.'<b>'.&mt('Submitted Files:').'</b>'
2416:3): .'<br /><span class="LC_warning">';
2417:3): if(@$files == 1) {
2418:3): $lastsubonly .= &mt('Like all files provided by users, this file may contain viruses!');
2419:3): } else {
2420:3): $lastsubonly .= &mt('Like all files provided by users, these files may contain viruses!');
2421:3): }
2422:3): $lastsubonly .= '</span>';
2423:3):
1.596 raeburn 2424: foreach my $file (@$files) {
2425: &Apache::lonnet::allowuploaded('/adm/grades',$file);
1.596.2.12.2. 8(raebur 2426:3): $lastsubonly.='<br /><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.&Apache::loncommon::icon($file).'" border="0" alt="" /> '.$file.'</a>';
1.596 raeburn 2427: }
2428: }
1.236 albertel 2429: $lastsubonly.='<br />';
1.41 ng 2430: }
1.596.2.2 raeburn 2431: if ($hide eq 'anon') {
1.596.2.12.2. 8(raebur 2432:3): $lastsubonly.='<br /><b>'.&mt('Anonymous Survey').'</b>';
1.596 raeburn 2433: } else {
1.596.2.12.2. 0(raebur 2434:4): $lastsubonly.='<br /><b>'.&mt('Submitted Answer:').' </b>';
2435:4): if ($draft) {
2436:4): $lastsubonly.= ' <span class="LC_warning">'.&mt('Draft Copy').'</span>';
2437:4): }
2438:4): $subval =
1.596 raeburn 2439: &cleanRecord($subval,$responsetype,$symb,$partid,
1.596.2.2 raeburn 2440: $respid,\%record,$order,undef,$uname,$udom,$type,$trial,$rndseed);
1.596.2.12.2. 0(raebur 2441:4): if ($responsetype eq 'essay') {
2442:4): $subval =~ s{\n}{<br />}g;
2443:4): }
2444:4): $lastsubonly.=$subval."\n";
1.596 raeburn 2445: }
1.151 albertel 2446: if ($similar) {$lastsubonly.="<br /><br />$similar\n";}
1.468 albertel 2447: $lastsubonly.='</div>';
1.41 ng 2448: }
2449: }
2450: }
1.588 bisitz 2451: $lastsubonly.='</div>'."\n"; # End: LC_grade_submissions_body
1.151 albertel 2452: }
2453: $request->print($lastsubonly);
1.596.2.12.2. 1(raebur 2454:3): if ($env{'form.lastSub'} eq 'datesub') {
1.324 albertel 2455: my (undef,$responseType,undef,$parts) = &showResourceInfo($symb);
1.148 albertel 2456: $request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
1.596.2.12.2. 1(raebur 2457:3): }
2458:3): if ($env{'form.lastSub'} =~ /^(last|all)$/) {
2459:5): my $identifier = (&canmodify($usec)? $counter : '');
1.41 ng 2460: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
1.257 albertel 2461: $env{'request.course.id'},
1.44 ng 2462: $last,'.submission',
1.596.2.12.2. 1(raebur 2463:5): 'Apache::grades::keywords_highlight',
2464:5): $usec,$identifier));
1.41 ng 2465: }
1.120 ng 2466:
1.121 ng 2467: $request->print('<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
2468: .$udom.'" />'."\n");
1.44 ng 2469: # return if view submission with no grading option
1.257 albertel 2470: if ($env{'form.showgrading'} eq '' || (!&canmodify($usec))) {
1.120 ng 2471: my $toGrade.='<input type="button" value="Grade Student" '.
1.589 bisitz 2472: 'onclick="javascript:checksubmit(this.form,\'Grade Student\',\''
1.417 albertel 2473: .$counter.'\');" target="_self" /> '."\n" if (&canmodify($usec));
1.468 albertel 2474: $toGrade.='</div>'."\n";
1.257 albertel 2475: if (($env{'form.command'} eq 'submission') ||
2476: ($env{'form.command'} eq 'processGroup' && $counter == $total)) {
1.324 albertel 2477: $toGrade.='</form>'.&show_grading_menu_form($symb);
1.169 albertel 2478: }
1.180 albertel 2479: $request->print($toGrade);
1.41 ng 2480: return;
1.180 albertel 2481: } else {
1.468 albertel 2482: $request->print('</div>'."\n");
1.41 ng 2483: }
1.33 ng 2484:
1.121 ng 2485: # essay grading message center
1.257 albertel 2486: if ($env{'form.handgrade'} eq 'yes') {
1.468 albertel 2487: my $result='<div class="LC_grade_message_center">';
2488:
2489: $result.='<div class="LC_grade_message_center_header">'.
2490: &mt('Send Message').'</div><div class="LC_grade_message_center_body">';
1.257 albertel 2491: my ($lastname,$givenn) = split(/,/,$env{'form.fullname'});
1.118 ng 2492: my $msgfor = $givenn.' '.$lastname;
1.464 albertel 2493: if (scalar(@$col_fullnames) > 0) {
2494: my $lastone = pop(@$col_fullnames);
2495: $msgfor .= ', '.(join ', ',@$col_fullnames).' and '.$lastone.'.';
1.118 ng 2496: }
2497: $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
1.468 albertel 2498: $result.='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
1.121 ng 2499: '<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n";
2500: $result.=' <a href="javascript:msgCenter(document.SCORE,'.$counter.
1.417 albertel 2501: ',\''.$msgfor.'\');" target="_self">'.
1.596.2.12.2. 8(raebur 2502:3): &mt('Compose message to student'.(scalar(@$col_fullnames) >= 1 ? 's' : '')).'</a><label> ('.
1.350 albertel 2503: &mt('incl. grades').' <input type="checkbox" name="withgrades'.$counter.'" /></label>)'.
1.596.2.12.2. 8(raebur 2504:3): ' <img src="'.$request->dir_config('lonIconsURL').
1.118 ng 2505: '/mailbkgrd.gif" width="14" height="10" name="mailicon'.$counter.'" />'."\n".
1.298 www 2506: '<br /> ('.
1.468 albertel 2507: &mt('Message will be sent when you click on Save & Next below.').")\n";
2508: $result.='</div></div>';
1.121 ng 2509: $request->print($result);
1.118 ng 2510: }
1.41 ng 2511:
2512: my %seen = ();
2513: my @partlist;
1.129 ng 2514: my @gradePartRespid;
1.375 albertel 2515: my @part_response_id = &flatten_responseType($responseType);
1.585 bisitz 2516: $request->print(
1.588 bisitz 2517: '<div class="LC_Box">'
2518: .'<h3 class="LC_hcell">'.&mt('Assign Grades').'</h3>'
1.585 bisitz 2519: );
1.592 bisitz 2520: $request->print(&gradeBox_start());
1.375 albertel 2521: foreach my $part_response_id (@part_response_id) {
2522: my ($partid,$respid) = @{ $part_response_id };
2523: my $part_resp = join('_',@{ $part_response_id });
1.322 albertel 2524: next if ($seen{$partid} > 0);
1.41 ng 2525: $seen{$partid}++;
1.393 albertel 2526: next if ($$handgrade{$part_resp} ne 'yes'
2527: && $env{'form.lastSub'} eq 'hdgrade');
1.524 raeburn 2528: push(@partlist,$partid);
2529: push(@gradePartRespid,$partid.'.'.$respid);
1.322 albertel 2530: $request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
1.41 ng 2531: }
1.585 bisitz 2532: $request->print(&gradeBox_end()); # </div>
2533: $request->print('</div>');
1.468 albertel 2534:
2535: $request->print('<div class="LC_grade_info_links">');
2536: $request->print('</div>');
2537:
1.45 ng 2538: $result='<input type="hidden" name="partlist'.$counter.
2539: '" value="'.(join ":",@partlist).'" />'."\n";
1.129 ng 2540: $result.='<input type="hidden" name="gradePartRespid'.
2541: '" value="'.(join ":",@gradePartRespid).'" />'."\n" if ($counter == 0);
1.45 ng 2542: my $ctr = 0;
2543: while ($ctr < scalar(@partlist)) {
2544: $result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
2545: $partlist[$ctr].'" />'."\n";
2546: $ctr++;
2547: }
1.468 albertel 2548: $request->print($result.''."\n");
1.41 ng 2549:
1.441 www 2550: # Done with printing info for one student
2551:
1.468 albertel 2552: $request->print('</div>');#LC_grade_show_user
1.441 www 2553:
2554:
1.41 ng 2555: # print end of form
2556: if ($counter == $total) {
1.592 bisitz 2557: my $endform='<br /><hr /><table border="0"><tr><td>'."\n";
1.485 albertel 2558: $endform.='<input type="button" value="'.&mt('Save & Next').'" '.
1.589 bisitz 2559: 'onclick="javascript:checksubmit(this.form,\'Save & Next\','.
1.417 albertel 2560: $total.','.scalar(@partlist).');" target="_self" /> '."\n";
1.119 ng 2561: my $ntstu ='<select name="NTSTU">'.
2562: '<option>1</option><option>2</option>'.
2563: '<option>3</option><option>5</option>'.
2564: '<option>7</option><option>10</option></select>'."\n";
1.257 albertel 2565: my $nsel = ($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : '1');
1.401 albertel 2566: $ntstu =~ s/<option>$nsel</<option selected="selected">$nsel</;
1.578 raeburn 2567: $endform.=&mt('[_1]student(s)',$ntstu);
1.485 albertel 2568: $endform.=' <input type="button" value="'.&mt('Previous').'" '.
1.589 bisitz 2569: 'onclick="javascript:checksubmit(this.form,\'Previous\');" target="_self" /> '."\n".
1.485 albertel 2570: '<input type="button" value="'.&mt('Next').'" '.
1.589 bisitz 2571: 'onclick="javascript:checksubmit(this.form,\'Next\');" target="_self" /> ';
1.592 bisitz 2572: $endform.='<span class="LC_warning">'.
2573: &mt('(Next and Previous (student) do not save the scores.)').
2574: '</span>'."\n" ;
1.349 albertel 2575: $endform.="<input type='hidden' value='".&get_increment().
1.348 bowersj2 2576: "' name='increment' />";
1.485 albertel 2577: $endform.='</td></tr></table></form>';
1.324 albertel 2578: $endform.=&show_grading_menu_form($symb);
1.41 ng 2579: $request->print($endform);
2580: }
2581: return '';
1.38 ng 2582: }
2583:
1.464 albertel 2584: sub check_collaborators {
2585: my ($symb,$uname,$udom,$record,$handgrade,$counter) = @_;
2586: my ($result,@col_fullnames);
2587: my ($classlist,undef,$fullname) = &getclasslist('all','0');
2588: foreach my $part (keys(%$handgrade)) {
2589: my $ncol = &Apache::lonnet::EXT('resource.'.$part.
2590: '.maxcollaborators',
2591: $symb,$udom,$uname);
2592: next if ($ncol <= 0);
2593: $part =~ s/\_/\./g;
2594: next if ($record->{'resource.'.$part.'.collaborators'} eq '');
2595: my (@good_collaborators, @bad_collaborators);
2596: foreach my $possible_collaborator
1.596.2.4 raeburn 2597: (split(/[,;\s]+/,$record->{'resource.'.$part.'.collaborators'})) {
1.464 albertel 2598: $possible_collaborator =~ s/[\$\^\(\)]//g;
2599: next if ($possible_collaborator eq '');
1.596.2.8 raeburn 2600: my ($co_name,$co_dom) = split(/:/,$possible_collaborator);
1.464 albertel 2601: $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
2602: next if ($co_name eq $uname && $co_dom eq $udom);
2603: # Doing this grep allows 'fuzzy' specification
2604: my @matches = grep(/^\Q$co_name\E:\Q$co_dom\E$/i,
2605: keys(%$classlist));
2606: if (! scalar(@matches)) {
2607: push(@bad_collaborators, $possible_collaborator);
2608: } else {
2609: push(@good_collaborators, @matches);
2610: }
2611: }
2612: if (scalar(@good_collaborators) != 0) {
1.596.2.8 raeburn 2613: $result.='<br />'.&mt('Collaborators:').'<ol>';
1.464 albertel 2614: foreach my $name (@good_collaborators) {
2615: my ($lastname,$givenn) = split(/,/,$$fullname{$name});
2616: push(@col_fullnames, $givenn.' '.$lastname);
1.596.2.4 raeburn 2617: $result.='<li>'.$fullname->{$name}.'</li>';
1.464 albertel 2618: }
1.596.2.4 raeburn 2619: $result.='</ol><br />'."\n";
1.466 albertel 2620: my ($part)=split(/\./,$part);
1.464 albertel 2621: $result.='<input type="hidden" name="collaborator'.$counter.
2622: '" value="'.$part.':'.(join ':',@good_collaborators).'" />'.
2623: "\n";
2624: }
2625: if (scalar(@bad_collaborators) > 0) {
1.466 albertel 2626: $result.='<div class="LC_warning">';
1.464 albertel 2627: $result.=&mt('This student has submitted [quant,_1,invalid collaborator]: [_2]',scalar(@bad_collaborators),join(', ',@bad_collaborators));
2628: $result .= '</div>';
2629: }
2630: if (scalar(@bad_collaborators > $ncol)) {
1.466 albertel 2631: $result .= '<div class="LC_warning">';
1.464 albertel 2632: $result .= &mt('This student has submitted too many '.
2633: 'collaborators. Maximum is [_1].',$ncol);
2634: $result .= '</div>';
2635: }
2636: }
2637: return ($result,$fullname,\@col_fullnames);
2638: }
2639:
1.44 ng 2640: #--- Retrieve the last submission for all the parts
1.38 ng 2641: sub get_last_submission {
1.119 ng 2642: my ($returnhash)=@_;
1.596 raeburn 2643: my (@string,$timestamp,%lasthidden);
1.119 ng 2644: if ($$returnhash{'version'}) {
1.46 ng 2645: my %lasthash=();
2646: my ($version);
1.119 ng 2647: for ($version=1;$version<=$$returnhash{'version'};$version++) {
1.397 albertel 2648: foreach my $key (sort(split(/\:/,
2649: $$returnhash{$version.':keys'}))) {
2650: $lasthash{$key}=$$returnhash{$version.':'.$key};
2651: $timestamp =
1.545 raeburn 2652: &Apache::lonlocal::locallocaltime($$returnhash{$version.':timestamp'});
1.46 ng 2653: }
2654: }
1.596.2.2 raeburn 2655: my (%typeparts,%randombytry);
1.596 raeburn 2656: my $showsurv =
2657: &Apache::lonnet::allowed('vas',$env{'request.course.id'});
2658: foreach my $key (sort(keys(%lasthash))) {
2659: if ($key =~ /\.type$/) {
2660: if (($lasthash{$key} eq 'anonsurvey') ||
1.596.2.2 raeburn 2661: ($lasthash{$key} eq 'anonsurveycred') ||
2662: ($lasthash{$key} eq 'randomizetry')) {
1.596 raeburn 2663: my ($ign,@parts) = split(/\./,$key);
2664: pop(@parts);
1.596.2.3 raeburn 2665: my $id = join('.',@parts);
1.596.2.2 raeburn 2666: if ($lasthash{$key} eq 'randomizetry') {
2667: $randombytry{$ign.'.'.$id} = $lasthash{$key};
2668: } else {
2669: unless ($showsurv) {
2670: $typeparts{$ign.'.'.$id} = $lasthash{$key};
2671: }
1.596 raeburn 2672: }
2673: delete($lasthash{$key});
2674: }
2675: }
2676: }
2677: my @hidden = keys(%typeparts);
1.596.2.2 raeburn 2678: my @randomize = keys(%randombytry);
1.397 albertel 2679: foreach my $key (keys(%lasthash)) {
2680: next if ($key !~ /\.submission$/);
1.596 raeburn 2681: my $hide;
2682: if (@hidden) {
2683: foreach my $id (@hidden) {
2684: if ($key =~ /^\Q$id\E/) {
1.596.2.2 raeburn 2685: $hide = 'anon';
1.596 raeburn 2686: last;
2687: }
2688: }
2689: }
1.596.2.2 raeburn 2690: unless ($hide) {
2691: if (@randomize) {
1.596.2.12.2. 3(raebur 2692:5): foreach my $id (@randomize) {
1.596.2.2 raeburn 2693: if ($key =~ /^\Q$id\E/) {
2694: $hide = 'rand';
2695: last;
2696: }
2697: }
2698: }
2699: }
1.397 albertel 2700: my ($partid,$foo) = split(/submission$/,$key);
1.596.2.12.2. 0(raebur 2701:4): my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ? 1: 0;
2702:4): push(@string, join(':', $key, $hide, $draft, (
8(raebur 2703:4): ref($lasthash{$key}) eq 'ARRAY' ?
2704:4): join(',', @{$lasthash{$key}}) : $lasthash{$key}) ));
1.41 ng 2705: }
2706: }
1.397 albertel 2707: if (!@string) {
2708: $string[0] =
1.539 riegler 2709: '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span>';
1.397 albertel 2710: }
2711: return (\@string,\$timestamp);
1.38 ng 2712: }
1.35 ng 2713:
1.44 ng 2714: #--- High light keywords, with style choosen by user.
1.38 ng 2715: sub keywords_highlight {
1.44 ng 2716: my $string = shift;
1.257 albertel 2717: my $size = $env{'form.kwsize'} eq '0' ? '' : 'size='.$env{'form.kwsize'};
2718: my $styleon = $env{'form.kwstyle'} eq '' ? '' : $env{'form.kwstyle'};
1.41 ng 2719: (my $styleoff = $styleon) =~ s/\</\<\//;
1.257 albertel 2720: my @keylist = split(/[,\s+]/,$env{'form.keywords'});
1.398 albertel 2721: foreach my $keyword (@keylist) {
2722: $string =~ s/\b\Q$keyword\E(\b|\.)/<font color\=$env{'form.kwclr'} $size\>$styleon$keyword$styleoff<\/font>/gi;
1.41 ng 2723: }
2724: return $string;
1.38 ng 2725: }
1.36 ng 2726:
1.596.2.12.2. (raeburn 2727:): # For Tasks provide a mechanism to display previous version for one specific student
2728:):
2729:): sub show_previous_task_version {
2730:): my ($request,$symb) = @_;
2731:): if ($symb eq '') {
8(raebur 2732:4): $request->print(
2733:4): '<span class="LC_error">'.
2734:4): &mt('Unable to handle ambiguous references.').
2735:4): '</span>');
(raeburn 2736:): return '';
2737:): }
2738:): my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
2739:): my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
2740:): if (!&canview($usec)) {
8(raebur 2741:4): $request->print('<span class="LC_warning">'.
2742:4): &mt('Unable to view previous version for requested student.').
2743:4): ' '.&mt('([_1] in section [_2] in course id [_3])',
9(raebur 2744:4): $uname.':'.$udom,$usec,$env{'request.course.id'}).
8(raebur 2745:4): '</span>');
(raeburn 2746:): return;
2747:): }
2748:): my $mode = 'both';
2749:): my $isTask = ($symb =~/\.task$/);
2750:): if ($isTask) {
2751:): if ($env{'form.previousversion'} =~ /^\d+$/) {
2752:): if ($env{'form.fullname'} eq '') {
2753:): $env{'form.fullname'} =
2754:): &Apache::loncommon::plainname($uname,$udom,'lastname');
2755:): }
2756:): my $probtitle=&Apache::lonnet::gettitle($symb);
2757:): $request->print("\n\n".
2758:): '<div class="LC_grade_show_user">'.
2759:): '<h2>'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
2760:): '</h2>'."\n");
2761:): &Apache::lonxml::clear_problem_counter();
2762:): $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode,
2763:): {'previousversion' => $env{'form.previousversion'} }));
2764:): $request->print("\n</div>");
2765:): }
2766:): }
2767:): return;
2768:): }
2769:):
2770:): sub choose_task_version_form {
2771:): my ($symb,$uname,$udom,$nomenu) = @_;
2772:): my $isTask = ($symb =~/\.task$/);
2773:): my ($current,$version,$result,$js,$displayed,$rowtitle);
2774:): if ($isTask) {
2775:): my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
2776:): $udom,$uname);
2777:): if (($record{'resource.0.version'} eq '') ||
2778:): ($record{'resource.0.version'} < 2)) {
2779:): return ($record{'resource.0.version'},
2780:): $record{'resource.0.version'},$result,$js);
2781:): } else {
2782:): $current = $record{'resource.0.version'};
2783:): }
2784:): if ($env{'form.previousversion'}) {
2785:): $displayed = $env{'form.previousversion'};
2786:): $rowtitle = &mt('Choose another version:')
2787:): } else {
2788:): $displayed = $current;
2789:): $rowtitle = &mt('Show earlier version:');
2790:): }
2791:): $result = '<div class="LC_left_float">';
2792:): my $list;
2793:): my $numversions = 0;
2794:): for (my $i=1; $i<=$record{'resource.0.version'}; $i++) {
2795:): if ($i == $current) {
2796:): if (!$env{'form.previousversion'} || $nomenu) {
2797:): next;
2798:): } else {
2799:): $list .= '<option value="'.$i.'">'.&mt('Current').'</option>'."\n";
2800:): $numversions ++;
2801:): }
2802:): } elsif (defined($record{'resource.'.$i.'.0.status'})) {
2803:): unless ($i == $env{'form.previousversion'}) {
2804:): $numversions ++;
2805:): }
2806:): $list .= '<option value="'.$i.'">'.$i.'</option>'."\n";
2807:): }
2808:): }
2809:): if ($numversions) {
2810:): $symb = &HTML::Entities::encode($symb,'<>"&');
2811:): $result .=
2812:): '<form name="getprev" method="post" action=""'.
2813:): ' onsubmit="return previousVersion('."'$uname','$udom','$symb','$displayed'".');">'.
2814:): &Apache::loncommon::start_data_table().
2815:): &Apache::loncommon::start_data_table_row().
2816:): '<th align="left">'.$rowtitle.'</th>'.
2817:): '<td><select name="version">'.
2818:): '<option>'.&mt('Select').'</option>'.
2819:): $list.
2820:): '</select></td>'.
2821:): &Apache::loncommon::end_data_table_row();
2822:): unless ($nomenu) {
2823:): $result .= &Apache::loncommon::start_data_table_row().
2824:): '<th align="left">'.&mt('Open in new window').'</th>'.
2825:): '<td><span class="LC_nobreak">'.
2826:): '<label><input type="radio" name="prevwin" value="1" />'.
2827:): &mt('Yes').'</label>'.
2828:): '<label><input type="radio" name="prevwin" value="0" checked="checked" />'.&mt('No').'</label>'.
2829:): '</span></td>'.
2830:): &Apache::loncommon::end_data_table_row();
2831:): }
2832:): $result .=
2833:): &Apache::loncommon::start_data_table_row().
2834:): '<th align="left"> </th>'.
2835:): '<td>'.
2836:): '<input type="submit" name="prevsub" value="'.&mt('Display').'" />'.
2837:): '</td>'.
2838:): &Apache::loncommon::end_data_table_row().
2839:): &Apache::loncommon::end_data_table().
2840:): '</form>';
2841:): $js = &previous_display_javascript($nomenu,$current);
2842:): } elsif ($displayed && $nomenu) {
2843:): $result .= '<a href="javascript:window.close()">'.&mt('Close window').'</a>';
2844:): } else {
2845:): $result .= &mt('No previous versions to show for this student');
2846:): }
2847:): $result .= '</div>';
2848:): }
2849:): return ($current,$displayed,$result,$js);
2850:): }
2851:):
2852:): sub previous_display_javascript {
2853:): my ($nomenu,$current) = @_;
2854:): my $js = <<"JSONE";
2855:): <script type="text/javascript">
2856:): // <![CDATA[
2857:): function previousVersion(uname,udom,symb) {
2858:): var current = '$current';
2859:): var version = document.getprev.version.options[document.getprev.version.selectedIndex].value;
2860:): var prevstr = new RegExp("^\\\\d+\$");
2861:): if (!prevstr.test(version)) {
2862:): return false;
2863:): }
2864:): var url = '';
2865:): if (version == current) {
2866:): url = '/adm/grades?student='+uname+'&userdom='+udom+'&symb='+symb+'&command=submission';
2867:): } else {
2868:): url = '/adm/grades?student='+uname+'&userdom='+udom+'&symb='+symb+'&command=versionsub&previousversion='+version;
2869:): }
2870:): JSONE
2871:): if ($nomenu) {
2872:): $js .= <<"JSTWO";
2873:): document.location.href = url;
2874:): JSTWO
2875:): } else {
2876:): $js .= <<"JSTHREE";
2877:): var newwin = 0;
2878:): for (var i=0; i<document.getprev.prevwin.length; i++) {
2879:): if (document.getprev.prevwin[i].checked == true) {
2880:): newwin = document.getprev.prevwin[i].value;
2881:): }
2882:): }
2883:): if (newwin == 1) {
2884:): var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
2885:): url = url+'&inhibitmenu=yes';
2886:): if (typeof(previousWin) == 'undefined' || previousWin.closed) {
2887:): previousWin = window.open(url,'',options,1);
2888:): } else {
2889:): previousWin.location.href = url;
2890:): }
2891:): previousWin.focus();
2892:): return false;
2893:): } else {
2894:): document.location.href = url;
2895:): return false;
2896:): }
2897:): JSTHREE
2898:): }
2899:): $js .= <<"ENDJS";
2900:): return false;
2901:): }
2902:): // ]]>
2903:): </script>
2904:): ENDJS
2905:):
2906:): }
2907:):
1.44 ng 2908: #--- Called from submission routine
1.38 ng 2909: sub processHandGrade {
1.41 ng 2910: my ($request) = shift;
1.596.2.12.2. (raeburn 2911:): my ($symb) = &get_symb($request);
1.324 albertel 2912: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.257 albertel 2913: my $button = $env{'form.gradeOpt'};
2914: my $ngrade = $env{'form.NCT'};
2915: my $ntstu = $env{'form.NTSTU'};
1.301 albertel 2916: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2917: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2918:
1.44 ng 2919: if ($button eq 'Save & Next') {
2920: my $ctr = 0;
2921: while ($ctr < $ngrade) {
1.257 albertel 2922: my ($uname,$udom) = split(/:/,$env{'form.unamedom'.$ctr});
1.596.2.12.2. 1(raebur 2923:5): my ($errorflag,$pts,$wgt,$numhidden) =
2924:5): &saveHandGrade($request,$symb,$uname,$udom,$ctr);
1.71 ng 2925: if ($errorflag eq 'no_score') {
2926: $ctr++;
2927: next;
2928: }
1.104 albertel 2929: if ($errorflag eq 'not_allowed') {
1.596.2.12.2. 8(raebur 2930:4): $request->print(
2931:4): '<span class="LC_error">'
2932:4): .&mt('Not allowed to modify grades for [_1]',"$uname:$udom")
2933:4): .'</span>');
1.104 albertel 2934: $ctr++;
2935: next;
2936: }
1.596.2.12.2. 1(raebur 2937:5): if ($numhidden) {
2938:5): $request->print(
2939:5): '<span class="LC_info">'
2940:5): .&mt('For [_1]: [quant,_2,transaction] hidden',"$uname:$udom",$numhidden)
2941:5): .'</span><br />');
2942:5): }
1.257 albertel 2943: my $includemsg = $env{'form.includemsg'.$ctr};
1.44 ng 2944: my ($subject,$message,$msgstatus) = ('','','');
1.418 albertel 2945: my $restitle = &Apache::lonnet::gettitle($symb);
2946: my ($feedurl,$showsymb) =
2947: &get_feedurl_and_symb($symb,$uname,$udom);
2948: my $messagetail;
1.62 albertel 2949: if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.298 www 2950: $subject = $env{'form.msgsub'} if ($includemsg =~ /msgsub/);
1.295 www 2951: unless ($subject=~/\w/) { $subject=&mt('Grading Feedback'); }
1.386 raeburn 2952: $subject.=' ['.$restitle.']';
1.44 ng 2953: my (@msgnum) = split(/,/,$includemsg);
2954: foreach (@msgnum) {
1.257 albertel 2955: $message.=$env{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
1.44 ng 2956: }
1.80 ng 2957: $message =&Apache::lonfeedback::clear_out_html($message);
1.298 www 2958: if ($env{'form.withgrades'.$ctr}) {
2959: $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
1.386 raeburn 2960: $messagetail = " for <a href=\"".
1.418 albertel 2961: $feedurl."?symb=$showsymb\">$env{'form.probTitle'}</a>";
1.386 raeburn 2962: }
2963: $msgstatus =
2964: &Apache::lonmsg::user_normal_msg($uname,$udom,$subject,
2965: $message.$messagetail,
1.418 albertel 2966: undef,$feedurl,undef,
1.386 raeburn 2967: undef,undef,$showsymb,
2968: $restitle);
1.574 bisitz 2969: $request->print('<br />'.&mt('Sending message to [_1]',$uname.':'.$udom).': '.
1.596.2.4 raeburn 2970: $msgstatus.'<br />');
1.44 ng 2971: }
1.257 albertel 2972: if ($env{'form.collaborator'.$ctr}) {
1.155 albertel 2973: my @collabstrs=&Apache::loncommon::get_env_multiple("form.collaborator$ctr");
1.150 albertel 2974: foreach my $collabstr (@collabstrs) {
2975: my ($part,@collaborators) = split(/:/,$collabstr);
1.310 banghart 2976: foreach my $collaborator (@collaborators) {
1.150 albertel 2977: my ($errorflag,$pts,$wgt) =
1.324 albertel 2978: &saveHandGrade($request,$symb,$collaborator,$udom,$ctr,
1.257 albertel 2979: $env{'form.unamedom'.$ctr},$part);
1.150 albertel 2980: if ($errorflag eq 'not_allowed') {
1.362 albertel 2981: $request->print("<span class=\"LC_error\">".&mt('Not allowed to modify grades for [_1]',"$collaborator:$udom")."</span>");
1.150 albertel 2982: next;
1.418 albertel 2983: } elsif ($message ne '') {
2984: my ($baseurl,$showsymb) =
2985: &get_feedurl_and_symb($symb,$collaborator,
2986: $udom);
2987: if ($env{'form.withgrades'.$ctr}) {
2988: $messagetail = " for <a href=\"".
1.386 raeburn 2989: $baseurl."?symb=$showsymb\">$env{'form.probTitle'}</a>";
1.150 albertel 2990: }
1.418 albertel 2991: $msgstatus =
2992: &Apache::lonmsg::user_normal_msg($collaborator,$udom,$subject,$message.$messagetail,undef,$baseurl,undef,undef,undef,$showsymb,$restitle);
1.104 albertel 2993: }
1.44 ng 2994: }
2995: }
2996: }
2997: $ctr++;
2998: }
2999: }
3000:
1.257 albertel 3001: if ($env{'form.handgrade'} eq 'yes') {
1.119 ng 3002: # Keywords sorted in alphabatical order
1.257 albertel 3003: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1.119 ng 3004: my %keyhash = ();
1.257 albertel 3005: $env{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
3006: $env{'form.keywords'} =~ s/^\s+|\s+$//;
3007: my (@keywords) = sort(split(/\s+/,$env{'form.keywords'}));
3008: $env{'form.keywords'} = join(' ',@keywords);
3009: $keyhash{$symb.'_keywords'} = $env{'form.keywords'};
3010: $keyhash{$symb.'_subject'} = $env{'form.msgsub'};
3011: $keyhash{$loginuser.'_kwclr'} = $env{'form.kwclr'};
3012: $keyhash{$loginuser.'_kwsize'} = $env{'form.kwsize'};
3013: $keyhash{$loginuser.'_kwstyle'} = $env{'form.kwstyle'};
1.119 ng 3014:
3015: # message center - Order of message gets changed. Blank line is eliminated.
1.257 albertel 3016: # New messages are saved in env for the next student.
1.119 ng 3017: # All messages are saved in nohist_handgrade.db
3018: my ($ctr,$idx) = (1,1);
1.257 albertel 3019: while ($ctr <= $env{'form.savemsgN'}) {
3020: if ($env{'form.savemsg'.$ctr} ne '') {
3021: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.savemsg'.$ctr};
1.119 ng 3022: $idx++;
3023: }
3024: $ctr++;
1.41 ng 3025: }
1.119 ng 3026: $ctr = 0;
3027: while ($ctr < $ngrade) {
1.257 albertel 3028: if ($env{'form.newmsg'.$ctr} ne '') {
3029: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.newmsg'.$ctr};
3030: $env{'form.savemsg'.$idx} = $env{'form.newmsg'.$ctr};
1.119 ng 3031: $idx++;
3032: }
3033: $ctr++;
1.41 ng 3034: }
1.257 albertel 3035: $env{'form.savemsgN'} = --$idx;
3036: $keyhash{$symb.'_savemsgN'} = $env{'form.savemsgN'};
1.119 ng 3037: my $putresult = &Apache::lonnet::put
1.301 albertel 3038: ('nohist_handgrade',\%keyhash,$cdom,$cnum);
1.41 ng 3039: }
1.44 ng 3040: # Called by Save & Refresh from Highlight Attribute Window
1.257 albertel 3041: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
3042: if ($env{'form.refresh'} eq 'on') {
1.86 ng 3043: my ($ctr,$total) = (0,0);
3044: while ($ctr < $ngrade) {
1.257 albertel 3045: $total++ if $env{'form.unamedom'.$ctr} ne '';
1.86 ng 3046: $ctr++;
3047: }
1.257 albertel 3048: $env{'form.NTSTU'}=$ngrade;
1.86 ng 3049: $ctr = 0;
3050: while ($ctr < $total) {
1.257 albertel 3051: my $processUser = $env{'form.unamedom'.$ctr};
3052: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
3053: $env{'form.fullname'} = $$fullname{$processUser};
1.86 ng 3054: &submission($request,$ctr,$total-1);
1.41 ng 3055: $ctr++;
3056: }
3057: return '';
3058: }
1.36 ng 3059:
1.121 ng 3060: # Go directly to grade student - from submission or link from chart page
1.120 ng 3061: if ($button eq 'Grade Student') {
1.324 albertel 3062: (undef,undef,$env{'form.handgrade'},undef,undef) = &showResourceInfo($symb);
1.257 albertel 3063: my $processUser = $env{'form.unamedom'.$env{'form.studentNo'}};
3064: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
3065: $env{'form.fullname'} = $$fullname{$processUser};
1.120 ng 3066: &submission($request,0,0);
3067: return '';
3068: }
3069:
1.44 ng 3070: # Get the next/previous one or group of students
1.257 albertel 3071: my $firststu = $env{'form.unamedom0'};
3072: my $laststu = $env{'form.unamedom'.($ngrade-1)};
1.119 ng 3073: my $ctr = 2;
1.41 ng 3074: while ($laststu eq '') {
1.257 albertel 3075: $laststu = $env{'form.unamedom'.($ngrade-$ctr)};
1.41 ng 3076: $ctr++;
3077: $laststu = $firststu if ($ctr > $ngrade);
3078: }
1.44 ng 3079:
1.41 ng 3080: my (@parsedlist,@nextlist);
3081: my ($nextflg) = 0;
1.524 raeburn 3082: foreach my $item (sort
1.294 albertel 3083: {
3084: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
3085: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
3086: }
3087: return $a cmp $b;
3088: } (keys(%$fullname))) {
1.41 ng 3089: if ($nextflg == 1 && $button =~ /Next$/) {
1.524 raeburn 3090: push(@parsedlist,$item);
1.41 ng 3091: }
1.524 raeburn 3092: $nextflg = 1 if ($item eq $laststu);
1.41 ng 3093: if ($button eq 'Previous') {
1.524 raeburn 3094: last if ($item eq $firststu);
3095: push(@parsedlist,$item);
1.41 ng 3096: }
3097: }
3098: $ctr = 0;
3099: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
1.582 raeburn 3100: my $res_error;
3101: my ($partlist) = &response_type($symb,\$res_error);
3102: if ($res_error) {
3103: $request->print(&navmap_errormsg());
3104: return;
3105: }
1.41 ng 3106: foreach my $student (@parsedlist) {
1.257 albertel 3107: my $submitonly=$env{'form.submitonly'};
1.41 ng 3108: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 3109:
3110: if ($submitonly eq 'queued') {
3111: my %queue_status =
3112: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
3113: $udom,$uname);
3114: next if (!defined($queue_status{'gradingqueue'}));
3115: }
3116:
1.156 albertel 3117: if ($submitonly =~ /^(yes|graded|incorrect)$/) {
1.257 albertel 3118: # my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 3119: my %status=&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 3120: my $submitted = 0;
1.248 albertel 3121: my $ungraded = 0;
3122: my $incorrect = 0;
1.524 raeburn 3123: foreach my $item (keys(%status)) {
3124: $submitted = 1 if ($status{$item} ne 'nothing');
3125: $ungraded = 1 if ($status{$item} =~ /^ungraded/);
3126: $incorrect = 1 if ($status{$item} =~ /^incorrect/);
3127: my ($foo,$partid,$foo1) = split(/\./,$item);
1.145 albertel 3128: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
3129: $submitted = 0;
3130: }
1.41 ng 3131: }
1.156 albertel 3132: next if (!$submitted && ($submitonly eq 'yes' ||
3133: $submitonly eq 'incorrect' ||
3134: $submitonly eq 'graded'));
1.248 albertel 3135: next if (!$ungraded && ($submitonly eq 'graded'));
3136: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 3137: }
1.524 raeburn 3138: push(@nextlist,$student) if ($ctr < $ntstu);
1.129 ng 3139: last if ($ctr == $ntstu);
1.41 ng 3140: $ctr++;
3141: }
1.36 ng 3142:
1.41 ng 3143: $ctr = 0;
3144: my $total = scalar(@nextlist)-1;
1.39 ng 3145:
1.524 raeburn 3146: foreach (sort(@nextlist)) {
1.41 ng 3147: my ($uname,$udom,$submitter) = split(/:/);
1.257 albertel 3148: $env{'form.student'} = $uname;
3149: $env{'form.userdom'} = $udom;
3150: $env{'form.fullname'} = $$fullname{$_};
1.41 ng 3151: &submission($request,$ctr,$total);
3152: $ctr++;
3153: }
3154: if ($total < 0) {
1.485 albertel 3155: my $the_end = '<h3><span class="LC_info">'.&mt('LON-CAPA User Message').'</span></h3><br />'."\n";
1.596.2.4 raeburn 3156: $the_end.='<p>'.&mt('[_1]Message:[_2] No more students for this section or class.','<b>','</b>').'</p>'."\n";
1.485 albertel 3157: $the_end.=&mt('Click on the button below to return to the grading menu.').'<br /><br />'."\n";
1.324 albertel 3158: $the_end.=&show_grading_menu_form($symb);
1.41 ng 3159: $request->print($the_end);
3160: }
3161: return '';
1.38 ng 3162: }
1.36 ng 3163:
1.44 ng 3164: #---- Save the score and award for each student, if changed
1.38 ng 3165: sub saveHandGrade {
1.324 albertel 3166: my ($request,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
1.342 banghart 3167: my @version_parts;
1.104 albertel 3168: my $usec = &Apache::lonnet::getsection($domain,$stuname,
1.257 albertel 3169: $env{'request.course.id'});
1.104 albertel 3170: if (!&canmodify($usec)) { return('not_allowed'); }
1.337 banghart 3171: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
1.251 banghart 3172: my @parts_graded;
1.77 ng 3173: my %newrecord = ();
1.596.2.12.2. 1(raebur 3174:5): my ($pts,$wgt,$totchg) = ('','',0);
1.269 raeburn 3175: my %aggregate = ();
3176: my $aggregateflag = 0;
1.596.2.12.2. 1(raebur 3177:5): if ($env{'form.HIDE'.$newflg}) {
3178:5): my ($version,$parts) = split(/:/,$env{'form.HIDE'.$newflg},2);
3179:5): my $numchgs = &makehidden($version,$parts,\%record,$symb,$domain,$stuname,1);
3180:5): $totchg += $numchgs;
3181:5): }
1.301 albertel 3182: my @parts = split(/:/,$env{'form.partlist'.$newflg});
3183: foreach my $new_part (@parts) {
1.337 banghart 3184: #collaborator ($submi may vary for different parts
1.259 banghart 3185: if ($submitter && $new_part ne $part) { next; }
3186: my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
1.125 ng 3187: if ($dropMenu eq 'excused') {
1.259 banghart 3188: if ($record{'resource.'.$new_part.'.solved'} ne 'excused') {
3189: $newrecord{'resource.'.$new_part.'.solved'} = 'excused';
3190: if (exists($record{'resource.'.$new_part.'.awarded'})) {
3191: $newrecord{'resource.'.$new_part.'.awarded'} = '';
1.58 albertel 3192: }
1.364 banghart 3193: $newrecord{'resource.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.58 albertel 3194: }
1.125 ng 3195: } elsif ($dropMenu eq 'reset status'
1.259 banghart 3196: && exists($record{'resource.'.$new_part.'.solved'})) { #don't bother if no old records -> no attempts
1.524 raeburn 3197: foreach my $key (keys(%record)) {
1.259 banghart 3198: if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
1.197 albertel 3199: }
1.259 banghart 3200: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 3201: "$env{'user.name'}:$env{'user.domain'}";
1.270 albertel 3202: my $totaltries = $record{'resource.'.$part.'.tries'};
3203:
3204: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
3205: [$new_part]);
3206: my $aggtries =$totaltries;
1.269 raeburn 3207: if ($last_resets{$new_part}) {
1.270 albertel 3208: $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
3209: $new_part);
1.269 raeburn 3210: }
1.270 albertel 3211:
3212: my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
1.269 raeburn 3213: if ($aggtries > 0) {
1.327 albertel 3214: &decrement_aggs($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
1.269 raeburn 3215: $aggregateflag = 1;
3216: }
1.125 ng 3217: } elsif ($dropMenu eq '') {
1.259 banghart 3218: $pts = ($env{'form.GD_BOX'.$newflg.'_'.$new_part} ne '' ?
3219: $env{'form.GD_BOX'.$newflg.'_'.$new_part} :
3220: $env{'form.RADVAL'.$newflg.'_'.$new_part});
3221: if ($pts eq '' && $env{'form.GD_SEL'.$newflg.'_'.$new_part} eq '') {
1.153 albertel 3222: next;
3223: }
1.259 banghart 3224: $wgt = $env{'form.WGT'.$newflg.'_'.$new_part} eq '' ? 1 :
3225: $env{'form.WGT'.$newflg.'_'.$new_part};
1.41 ng 3226: my $partial= $pts/$wgt;
1.259 banghart 3227: if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
1.153 albertel 3228: #do not update score for part if not changed.
1.346 banghart 3229: &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
1.153 albertel 3230: next;
1.251 banghart 3231: } else {
1.524 raeburn 3232: push(@parts_graded,$new_part);
1.153 albertel 3233: }
1.259 banghart 3234: if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
3235: $newrecord{'resource.'.$new_part.'.awarded'} = $partial;
1.153 albertel 3236: }
1.259 banghart 3237: my $reckey = 'resource.'.$new_part.'.solved';
1.41 ng 3238: if ($partial == 0) {
1.153 albertel 3239: if ($record{$reckey} ne 'incorrect_by_override') {
3240: $newrecord{$reckey} = 'incorrect_by_override';
3241: }
1.41 ng 3242: } else {
1.153 albertel 3243: if ($record{$reckey} ne 'correct_by_override') {
3244: $newrecord{$reckey} = 'correct_by_override';
3245: }
3246: }
3247: if ($submitter &&
1.259 banghart 3248: ($record{'resource.'.$new_part.'.submitted_by'} ne $submitter)) {
3249: $newrecord{'resource.'.$new_part.'.submitted_by'} = $submitter;
1.41 ng 3250: }
1.259 banghart 3251: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 3252: "$env{'user.name'}:$env{'user.domain'}";
1.41 ng 3253: }
1.259 banghart 3254: # unless problem has been graded, set flag to version the submitted files
1.305 banghart 3255: unless ($record{'resource.'.$new_part.'.solved'} =~ /^correct_/ ||
3256: $record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override' ||
3257: $dropMenu eq 'reset status')
3258: {
1.524 raeburn 3259: push(@version_parts,$new_part);
1.259 banghart 3260: }
1.41 ng 3261: }
1.301 albertel 3262: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3263: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3264:
1.344 albertel 3265: if (%newrecord) {
3266: if (@version_parts) {
1.364 banghart 3267: my @changed_keys = &version_portfiles(\%record, \@parts_graded,
3268: $env{'request.course.id'}, $symb, $domain, $stuname, \@version_parts);
1.344 albertel 3269: @newrecord{@changed_keys} = @record{@changed_keys};
1.367 albertel 3270: foreach my $new_part (@version_parts) {
3271: &handback_files($request,$symb,$stuname,$domain,$newflg,
3272: $new_part,\%newrecord);
3273: }
1.259 banghart 3274: }
1.44 ng 3275: &Apache::lonnet::cstore(\%newrecord,$symb,
1.257 albertel 3276: $env{'request.course.id'},$domain,$stuname);
1.380 albertel 3277: &check_and_remove_from_queue(\@parts,\%record,\%newrecord,$symb,
3278: $cdom,$cnum,$domain,$stuname);
1.41 ng 3279: }
1.269 raeburn 3280: if ($aggregateflag) {
3281: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 3282: $cdom,$cnum);
1.269 raeburn 3283: }
1.596.2.12.2. 1(raebur 3284:5): return ('',$pts,$wgt,$totchg);
3285:5): }
3286:5):
3287:5): sub makehidden {
3288:5): my ($version,$parts,$record,$symb,$domain,$stuname,$tolog) = @_;
3289:5): return unless (ref($record) eq 'HASH');
3290:5): my %modified;
3291:5): my $numchanged = 0;
3292:5): if (exists($record->{$version.':keys'})) {
3293:5): my $partsregexp = $parts;
3294:5): $partsregexp =~ s/,/|/g;
3295:5): foreach my $key (split(/\:/,$record->{$version.':keys'})) {
3296:5): if ($key =~ /^resource\.(?:$partsregexp)\.([^\.]+)$/) {
3297:5): my $item = $1;
3298:5): unless (($item eq 'solved') || ($item =~ /^award(|msg|ed)$/)) {
3299:5): $modified{$key} = $record->{$version.':'.$key};
3300:5): }
3301:5): } elsif ($key =~ m{^(resource\.(?:$partsregexp)\.[^\.]+\.)(.+)$}) {
3302:5): $modified{$1.'hidden'.$2} = $record->{$version.':'.$key};
3303:5): } elsif ($key =~ /^(ip|timestamp|host)$/) {
3304:5): $modified{$key} = $record->{$version.':'.$key};
3305:5): }
3306:5): }
3307:5): if (keys(%modified)) {
3308:5): if (&Apache::lonnet::putstore($env{'request.course.id'},$symb,$version,\%modified,
3309:5): $domain,$stuname,$tolog) eq 'ok') {
3310:5): $numchanged ++;
3311:5): }
3312:5): }
3313:5): }
3314:5): return $numchanged;
1.36 ng 3315: }
1.322 albertel 3316:
1.380 albertel 3317: sub check_and_remove_from_queue {
3318: my ($parts,$record,$newrecord,$symb,$cdom,$cnum,$domain,$stuname) = @_;
3319: my @ungraded_parts;
3320: foreach my $part (@{$parts}) {
3321: if ( $record->{ 'resource.'.$part.'.awarded'} eq ''
3322: && $record->{ 'resource.'.$part.'.solved' } ne 'excused'
3323: && $newrecord->{'resource.'.$part.'.awarded'} eq ''
3324: && $newrecord->{'resource.'.$part.'.solved' } ne 'excused'
3325: ) {
3326: push(@ungraded_parts, $part);
3327: }
3328: }
3329: if ( !@ungraded_parts ) {
3330: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,
3331: $cnum,$domain,$stuname);
3332: }
3333: }
3334:
1.337 banghart 3335: sub handback_files {
3336: my ($request,$symb,$stuname,$domain,$newflg,$new_part,$newrecord) = @_;
1.517 raeburn 3337: my $portfolio_root = '/userfiles/portfolio';
1.582 raeburn 3338: my $res_error;
3339: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
3340: if ($res_error) {
3341: $request->print('<br />'.&navmap_errormsg().'<br />');
3342: return;
3343: }
1.596.2.4 raeburn 3344: my @handedback;
3345: my $file_msg;
1.375 albertel 3346: my @part_response_id = &flatten_responseType($responseType);
3347: foreach my $part_response_id (@part_response_id) {
3348: my ($part_id,$resp_id) = @{ $part_response_id };
3349: my $part_resp = join('_',@{ $part_response_id });
1.596.2.4 raeburn 3350: if (($env{'form.'.$newflg.'_'.$part_resp.'_countreturndoc'} =~ /^\d+$/) & ($new_part eq $part_id)) {
3351: for (my $counter=1; $counter<=$env{'form.'.$newflg.'_'.$part_resp.'_countreturndoc'}; $counter++) {
1.337 banghart 3352: # if multiple files are uploaded names will be 'returndoc2','returndoc3'
1.596.2.4 raeburn 3353: if ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$counter}) {
3354: my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$counter.'.filename'};
1.338 banghart 3355: my ($directory,$answer_file) =
1.596.2.4 raeburn 3356: ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$counter} =~ /^(.*?)([^\/]*)$/);
1.338 banghart 3357: my ($answer_name,$answer_ver,$answer_ext) =
3358: &file_name_version_ext($answer_file);
1.355 banghart 3359: my ($portfolio_path) = ($directory =~ /^.+$stuname\/portfolio(.*)/);
1.517 raeburn 3360: my $getpropath = 1;
1.596.2.12.2. (raeburn 3361:): my ($dir_list,$listerror) =
3362:): &Apache::lonnet::dirlist($portfolio_root.$portfolio_path,
3363:): $domain,$stuname,$getpropath);
3364:): my $version = &get_next_version($answer_name,$answer_ext,$dir_list);
3(raebur 3365:3): # fix filename
1.355 banghart 3366: my ($save_file_name) = (($directory.$answer_name.".$version.".$answer_ext) =~ /^.+\/${stuname}\/(.*)/);
3367: my $result=&Apache::lonnet::finishuserfileupload($stuname,$domain,
1.596.2.4 raeburn 3368: $newflg.'_'.$part_resp.'_returndoc'.$counter,
1.355 banghart 3369: $save_file_name);
1.337 banghart 3370: if ($result !~ m|^/uploaded/|) {
1.536 raeburn 3371: $request->print('<br /><span class="LC_error">'.
3372: &mt('An error occurred ([_1]) while trying to upload [_2].',
1.596.2.4 raeburn 3373: $result,$newflg.'_'.$part_resp.'_returndoc'.$counter).
1.536 raeburn 3374: '</span>');
1.356 banghart 3375: } else {
1.360 banghart 3376: # mark the file as read only
1.596.2.4 raeburn 3377: push(@handedback,$save_file_name);
1.367 albertel 3378: if (exists($$newrecord{"resource.$new_part.$resp_id.handback"})) {
3379: $$newrecord{"resource.$new_part.$resp_id.handback"}.=',';
3380: }
3381: $$newrecord{"resource.$new_part.$resp_id.handback"} .= $save_file_name;
1.596.2.4 raeburn 3382: $file_msg.='<span class="LC_filename"><a href="/uploaded/'."$domain/$stuname/".$save_file_name.'">'.$save_file_name."</a></span> <br />";
1.367 albertel 3383:
1.337 banghart 3384: }
1.596.2.12.2. 3(raebur 3385:3): $request->print('<br />'.&mt('[_1] will be the uploaded filename [_2]','<span class="LC_info">'.$fname.'</span>','<span class="LC_filename">'.$env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$counter}.'</span>'));
1.337 banghart 3386: }
3387: }
3388: }
1.596.2.4 raeburn 3389: }
3390: if (@handedback > 0) {
3391: $request->print('<br />');
3392: my @what = ($symb,$env{'request.course.id'},'handback');
3393: &Apache::lonnet::mark_as_readonly($domain,$stuname,\@handedback,\@what);
3394: my $user_lh = &Apache::loncommon::user_lang($stuname,$domain,$env{'request.course.id'});
3395: my ($subject,$message);
3396: if (scalar(@handedback) == 1) {
3397: $subject = &mt_user($user_lh,'File Handed Back by Instructor');
3398: } else {
3399: $subject = &mt_user($user_lh,'Files Handed Back by Instructor');
3400: $message = &mt_user($user_lh,'Files have been returned that were originally submitted in response to: ');
3401: }
3402: $message .= "<p><strong>".&Apache::lonnet::gettitle($symb)." </strong></p>";
3403: $message .= &mt_user($user_lh,'The returned file(s) are named: [_1]',"<br />$file_msg <br />").
3404: &mt_user($user_lh,'The file(s) can be found in your [_1]portfolio[_2].','<a href="/adm/portfolio">','</a>');
3405: my ($feedurl,$showsymb) =
3406: &get_feedurl_and_symb($symb,$domain,$stuname);
3407: my $restitle = &Apache::lonnet::gettitle($symb);
3408: $subject .= ' '.&mt_user($user_lh,'(File Returned)').' ['.$restitle.']';
3409: my $msgstatus =
3410: &Apache::lonmsg::user_normal_msg($stuname,$domain,$subject,
3411: $message,undef,$feedurl,undef,undef,undef,$showsymb,
3412: $restitle);
3413: if ($msgstatus) {
3414: $request->print(&mt('Notification message status: [_1]','<span class="LC_info">'.$msgstatus.'</span>').'<br />');
3415: }
3416: }
1.338 banghart 3417: return;
1.337 banghart 3418: }
3419:
1.418 albertel 3420: sub get_feedurl_and_symb {
3421: my ($symb,$uname,$udom) = @_;
3422: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
3423: $url = &Apache::lonnet::clutter($url);
3424: my $encrypturl=&Apache::lonnet::EXT('resource.0.encrypturl',
3425: $symb,$udom,$uname);
3426: if ($encrypturl =~ /^yes$/i) {
3427: &Apache::lonenc::encrypted(\$url,1);
3428: &Apache::lonenc::encrypted(\$symb,1);
3429: }
3430: return ($url,$symb);
3431: }
3432:
1.313 banghart 3433: sub get_submitted_files {
3434: my ($udom,$uname,$partid,$respid,$record) = @_;
3435: my @files;
3436: if ($$record{"resource.$partid.$respid.portfiles"}) {
3437: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
3438: foreach my $file (split(',',$$record{"resource.$partid.$respid.portfiles"})) {
3439: push(@files,$file_url.$file);
3440: }
3441: }
3442: if ($$record{"resource.$partid.$respid.uploadedurl"}) {
3443: push(@files,$$record{"resource.$partid.$respid.uploadedurl"});
3444: }
3445: return (\@files);
3446: }
1.322 albertel 3447:
1.269 raeburn 3448: # ----------- Provides number of tries since last reset.
3449: sub get_num_tries {
3450: my ($record,$last_reset,$part) = @_;
3451: my $timestamp = '';
3452: my $num_tries = 0;
3453: if ($$record{'version'}) {
3454: for (my $version=$$record{'version'};$version>=1;$version--) {
3455: if (exists($$record{$version.':resource.'.$part.'.solved'})) {
3456: $timestamp = $$record{$version.':timestamp'};
3457: if ($timestamp > $last_reset) {
3458: $num_tries ++;
3459: } else {
3460: last;
3461: }
3462: }
3463: }
3464: }
3465: return $num_tries;
3466: }
3467:
3468: # ----------- Determine decrements required in aggregate totals
3469: sub decrement_aggs {
3470: my ($symb,$part,$aggregate,$aggtries,$totaltries,$solvedstatus) = @_;
3471: my %decrement = (
3472: attempts => 0,
3473: users => 0,
3474: correct => 0
3475: );
3476: $decrement{'attempts'} = $aggtries;
3477: if ($solvedstatus =~ /^correct/) {
3478: $decrement{'correct'} = 1;
3479: }
3480: if ($aggtries == $totaltries) {
3481: $decrement{'users'} = 1;
3482: }
1.524 raeburn 3483: foreach my $type (keys(%decrement)) {
1.269 raeburn 3484: $$aggregate{$symb."\0".$part."\0".$type} = -$decrement{$type};
3485: }
3486: return;
3487: }
3488:
3489: # ----------- Determine timestamps for last reset of aggregate totals for parts
3490: sub get_last_resets {
1.270 albertel 3491: my ($symb,$courseid,$partids) =@_;
3492: my %last_resets;
1.269 raeburn 3493: my $cdom = $env{'course.'.$courseid.'.domain'};
3494: my $cname = $env{'course.'.$courseid.'.num'};
1.271 albertel 3495: my @keys;
3496: foreach my $part (@{$partids}) {
3497: push(@keys,"$symb\0$part\0resettime");
3498: }
3499: my %results=&Apache::lonnet::get('nohist_resourcetracker',\@keys,
3500: $cdom,$cname);
3501: foreach my $part (@{$partids}) {
3502: $last_resets{$part}=$results{"$symb\0$part\0resettime"};
1.269 raeburn 3503: }
1.270 albertel 3504: return %last_resets;
1.269 raeburn 3505: }
3506:
1.251 banghart 3507: # ----------- Handles creating versions for portfolio files as answers
3508: sub version_portfiles {
1.343 banghart 3509: my ($record, $parts_graded, $courseid, $symb, $domain, $stu_name, $v_flag) = @_;
1.263 banghart 3510: my $version_parts = join('|',@$v_flag);
1.343 banghart 3511: my @returned_keys;
1.255 banghart 3512: my $parts = join('|', @$parts_graded);
1.517 raeburn 3513: my $portfolio_root = '/userfiles/portfolio';
1.277 albertel 3514: foreach my $key (keys(%$record)) {
1.259 banghart 3515: my $new_portfiles;
1.263 banghart 3516: if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
1.342 banghart 3517: my @versioned_portfiles;
1.367 albertel 3518: my @portfiles = split(/\s*,\s*/,$$record{$key});
1.252 banghart 3519: foreach my $file (@portfiles) {
1.306 banghart 3520: &Apache::lonnet::unmark_as_readonly($domain,$stu_name,[$symb,$env{'request.course.id'}],$file);
1.304 albertel 3521: my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*)$/);
3522: my ($answer_name,$answer_ver,$answer_ext) =
3523: &file_name_version_ext($answer_file);
1.596.2.12.2. (raeburn 3524:): my $getpropath = 1;
3525:): my ($dir_list,$listerror) =
3526:): &Apache::lonnet::dirlist($portfolio_root.$directory,$domain,
3527:): $stu_name,$getpropath);
3528:): my $version = &get_next_version($answer_name,$answer_ext,$dir_list);
1.306 banghart 3529: my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version);
3530: if ($new_answer ne 'problem getting file') {
1.342 banghart 3531: push(@versioned_portfiles, $directory.$new_answer);
1.306 banghart 3532: &Apache::lonnet::mark_as_readonly($domain,$stu_name,
1.367 albertel 3533: [$directory.$new_answer],
1.306 banghart 3534: [$symb,$env{'request.course.id'},'graded']);
1.259 banghart 3535: }
1.252 banghart 3536: }
1.343 banghart 3537: $$record{$key} = join(',',@versioned_portfiles);
3538: push(@returned_keys,$key);
1.251 banghart 3539: }
3540: }
1.343 banghart 3541: return (@returned_keys);
1.305 banghart 3542: }
3543:
1.307 banghart 3544: sub get_next_version {
1.341 banghart 3545: my ($answer_name, $answer_ext, $dir_list) = @_;
1.307 banghart 3546: my $version;
1.596.2.12.2. (raeburn 3547:): if (ref($dir_list) eq 'ARRAY') {
3548:): foreach my $row (@{$dir_list}) {
3549:): my ($file) = split(/\&/,$row,2);
3550:): my ($file_name,$file_version,$file_ext) =
3551:): &file_name_version_ext($file);
3552:): if (($file_name eq $answer_name) &&
3553:): ($file_ext eq $answer_ext)) {
3554:): # gets here if filename and extension match,
3555:): # regardless of version
1.307 banghart 3556: if ($file_version ne '') {
1.596.2.12.2. (raeburn 3557:): # a versioned file is found so save it for later
3558:): if ($file_version > $version) {
3559:): $version = $file_version;
3560:): }
1.307 banghart 3561: }
3562: }
3563: }
1.596.2.12.2. (raeburn 3564:): }
1.307 banghart 3565: $version ++;
3566: return($version);
3567: }
3568:
1.305 banghart 3569: sub version_selected_portfile {
1.306 banghart 3570: my ($domain,$stu_name,$directory,$file_name,$version) = @_;
3571: my ($answer_name,$answer_ver,$answer_ext) =
3572: &file_name_version_ext($file_name);
3573: my $new_answer;
3574: $env{'form.copy'} = &Apache::lonnet::getfile("/uploaded/$domain/$stu_name/portfolio$directory$file_name");
3575: if($env{'form.copy'} eq '-1') {
3576: $new_answer = 'problem getting file';
3577: } else {
3578: $new_answer = $answer_name.'.'.$version.'.'.$answer_ext;
3579: my $copy_result = &Apache::lonnet::finishuserfileupload(
3580: $stu_name,$domain,'copy',
3581: '/portfolio'.$directory.$new_answer);
3582: }
3583: return ($new_answer);
1.251 banghart 3584: }
3585:
1.304 albertel 3586: sub file_name_version_ext {
3587: my ($file)=@_;
3588: my @file_parts = split(/\./, $file);
3589: my ($name,$version,$ext);
3590: if (@file_parts > 1) {
3591: $ext=pop(@file_parts);
3592: if (@file_parts > 1 && $file_parts[-1] =~ /^\d+$/) {
3593: $version=pop(@file_parts);
3594: }
3595: $name=join('.',@file_parts);
3596: } else {
3597: $name=join('.',@file_parts);
3598: }
3599: return($name,$version,$ext);
3600: }
3601:
1.44 ng 3602: #--------------------------------------------------------------------------------------
3603: #
3604: #-------------------------- Next few routines handles grading by section or whole class
3605: #
3606: #--- Javascript to handle grading by section or whole class
1.42 ng 3607: sub viewgrades_js {
3608: my ($request) = shift;
3609:
1.539 riegler 3610: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
1.596.2.12.2. 6(raebur 3611:6): &js_escape(\$alertmsg);
1.41 ng 3612: $request->print(<<VIEWJAVASCRIPT);
3613: <script type="text/javascript" language="javascript">
1.45 ng 3614: function writePoint(partid,weight,point) {
1.125 ng 3615: var radioButton = document.classgrade["RADVAL_"+partid];
3616: var textbox = document.classgrade["TEXTVAL_"+partid];
1.42 ng 3617: if (point == "textval") {
1.125 ng 3618: point = document.classgrade["TEXTVAL_"+partid].value;
1.109 matthew 3619: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 3620: alert("$alertmsg"+parseFloat(point));
1.42 ng 3621: var resetbox = false;
3622: for (var i=0; i<radioButton.length; i++) {
3623: if (radioButton[i].checked) {
3624: textbox.value = i;
3625: resetbox = true;
3626: }
3627: }
3628: if (!resetbox) {
3629: textbox.value = "";
3630: }
3631: return;
3632: }
1.109 matthew 3633: if (parseFloat(point) > parseFloat(weight)) {
3634: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 3635: ") greater than the weight for the part. Accept?");
3636: if (resp == false) {
3637: textbox.value = "";
3638: return;
3639: }
3640: }
1.42 ng 3641: for (var i=0; i<radioButton.length; i++) {
3642: radioButton[i].checked=false;
1.109 matthew 3643: if (parseFloat(point) == i) {
1.42 ng 3644: radioButton[i].checked=true;
3645: }
3646: }
1.41 ng 3647:
1.42 ng 3648: } else {
1.125 ng 3649: textbox.value = parseFloat(point);
1.42 ng 3650: }
1.41 ng 3651: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3652: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3653: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3654: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3655: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3656: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 3657: if (saveval != "correct") {
3658: scorename.value = point;
1.43 ng 3659: if (selname[0].selected != true) {
3660: selname[0].selected = true;
3661: }
1.42 ng 3662: }
3663: }
1.125 ng 3664: document.classgrade["SELVAL_"+partid][0].selected = true;
1.42 ng 3665: }
3666:
3667: function writeRadText(partid,weight) {
1.125 ng 3668: var selval = document.classgrade["SELVAL_"+partid];
3669: var radioButton = document.classgrade["RADVAL_"+partid];
1.265 www 3670: var override = document.classgrade["FORCE_"+partid].checked;
1.125 ng 3671: var textbox = document.classgrade["TEXTVAL_"+partid];
3672: if (selval[1].selected || selval[2].selected) {
1.42 ng 3673: for (var i=0; i<radioButton.length; i++) {
3674: radioButton[i].checked=false;
3675:
3676: }
3677: textbox.value = "";
3678:
3679: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3680: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3681: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3682: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3683: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3684: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 3685: if ((saveval != "correct") || override) {
1.42 ng 3686: scorename.value = "";
1.125 ng 3687: if (selval[1].selected) {
3688: selname[1].selected = true;
3689: } else {
3690: selname[2].selected = true;
3691: if (Number(document.classgrade["GD_"+user+"_"+partid+"_tries"].value))
3692: {document.classgrade["GD_"+user+"_"+partid+"_tries"].value = '0';}
3693: }
1.42 ng 3694: }
3695: }
1.43 ng 3696: } else {
3697: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3698: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3699: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3700: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3701: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3702: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 3703: if ((saveval != "correct") || override) {
1.125 ng 3704: scorename.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
1.43 ng 3705: selname[0].selected = true;
3706: }
3707: }
3708: }
1.42 ng 3709: }
3710:
3711: function changeSelect(partid,user) {
1.125 ng 3712: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
3713: var textbox = document.classgrade["GD_"+user+'_'+partid+"_awarded"];
1.44 ng 3714: var point = textbox.value;
1.125 ng 3715: var weight = document.classgrade["weight_"+partid].value;
1.44 ng 3716:
1.109 matthew 3717: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 3718: alert("$alertmsg"+parseFloat(point));
1.44 ng 3719: textbox.value = "";
3720: return;
3721: }
1.109 matthew 3722: if (parseFloat(point) > parseFloat(weight)) {
3723: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 3724: ") greater than the weight of the part. Accept?");
3725: if (resp == false) {
3726: textbox.value = "";
3727: return;
3728: }
3729: }
1.42 ng 3730: selval[0].selected = true;
3731: }
3732:
3733: function changeOneScore(partid,user) {
1.125 ng 3734: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
3735: if (selval[1].selected || selval[2].selected) {
3736: document.classgrade["GD_"+user+'_'+partid+"_awarded"].value = "";
3737: if (selval[2].selected) {
3738: document.classgrade["GD_"+user+'_'+partid+"_tries"].value = "0";
3739: }
1.269 raeburn 3740: }
1.42 ng 3741: }
3742:
3743: function resetEntry(numpart) {
3744: for (ctpart=0;ctpart<numpart;ctpart++) {
1.125 ng 3745: var partid = document.classgrade["partid_"+ctpart].value;
3746: var radioButton = document.classgrade["RADVAL_"+partid];
3747: var textbox = document.classgrade["TEXTVAL_"+partid];
3748: var selval = document.classgrade["SELVAL_"+partid];
1.42 ng 3749: for (var i=0; i<radioButton.length; i++) {
3750: radioButton[i].checked=false;
3751:
3752: }
3753: textbox.value = "";
3754: selval[0].selected = true;
3755:
3756: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3757: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3758: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3759: var resetscore = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3760: resetscore.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
3761: var resettries = document.classgrade["GD_"+user+"_"+partid+"_tries"];
3762: resettries.value = document.classgrade["GD_"+user+"_"+partid+"_tries_s"].value;
3763: var saveselval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3764: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 3765: if (saveselval == "excused") {
1.43 ng 3766: if (selname[1].selected == false) { selname[1].selected = true;}
1.42 ng 3767: } else {
1.43 ng 3768: if (selname[0].selected == false) {selname[0].selected = true};
1.42 ng 3769: }
3770: }
1.41 ng 3771: }
1.42 ng 3772: }
3773:
1.41 ng 3774: </script>
3775: VIEWJAVASCRIPT
1.42 ng 3776: }
3777:
1.44 ng 3778: #--- show scores for a section or whole class w/ option to change/update a score
1.42 ng 3779: sub viewgrades {
3780: my ($request) = shift;
3781: &viewgrades_js($request);
1.41 ng 3782:
1.324 albertel 3783: my ($symb) = &get_symb($request);
1.168 albertel 3784: #need to make sure we have the correct data for later EXT calls,
3785: #thus invalidate the cache
3786: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 3787: $env{'course.'.$env{'request.course.id'}.'.num'},
3788: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 3789: &Apache::lonnet::clear_EXT_cache_status();
3790:
1.398 albertel 3791: my $result='<h3><span class="LC_info">'.&mt('Manual Grading').'</span></h3>';
1.596.2.12.2. 9(raebur 3792:3): $result.='<h4><b>'.&mt('Current Resource').':</b> '.$env{'form.probTitle'}.'</h4>'."\n";
1.41 ng 3793:
3794: #view individual student submission form - called using Javascript viewOneStudent
1.324 albertel 3795: $result.=&jscriptNform($symb);
1.41 ng 3796:
1.44 ng 3797: #beginning of class grading form
1.442 banghart 3798: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.41 ng 3799: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1.418 albertel 3800: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.38 ng 3801: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.432 banghart 3802: &build_section_inputs().
1.257 albertel 3803: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.442 banghart 3804: '<input type="hidden" name="Status" value="'.$env{'stu_status'}.'" />'."\n".
1.257 albertel 3805: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.72 ng 3806:
1.596.2.12.2. 7(raebur 3807:6): #retrieve selected groups
3808:6): my (@groups,$group_display);
8(raebur 3809:6): @groups = &Apache::loncommon::get_env_multiple('form.group');
7(raebur 3810:6): if (grep(/^all$/,@groups)) {
3811:6): @groups = ('all');
3812:6): } elsif (grep(/^none$/,@groups)) {
3813:6): @groups = ('none');
3814:6): } elsif (@groups > 0) {
3815:6): $group_display = join(', ',@groups);
3816:6): }
3817:6):
3818:6): my ($common_header,$specific_header,@sections,$section_display);
3819:6): @sections = &Apache::loncommon::get_env_multiple('form.section');
3820:6): if (grep(/^all$/,@sections)) {
3821:6): @sections = ('all');
3822:6): if ($group_display) {
3823:6): $common_header = &mt('Assign Common Grade to Students in Group(s) [_1]',$group_display);
3824:6): $specific_header = &mt('Assign Grade to Specific Students in Group(s) [_1]',$group_display);
3825:6): } elsif (grep(/^none$/,@groups)) {
3826:6): $common_header = &mt('Assign Common Grade to Students not assigned to any groups');
3827:6): $specific_header = &mt('Assign Grade to Specific Students not assigned to any groups');
3828:6): } else {
3829:6): $common_header = &mt('Assign Common Grade to Class');
3830:6): $specific_header = &mt('Assign Grade to Specific Students in Class');
3831:6): }
3832:6): } elsif (grep(/^none$/,@sections)) {
3833:6): @sections = ('none');
3834:6): if ($group_display) {
3835:6): $common_header = &mt('Assign Common Grade to Students in no Section and in Group(s) [_1]',$group_display);
3836:6): $specific_header = &mt('Assign Grade to Specific Students in no Section and in Group(s)',$group_display);
3837:6): } elsif (grep(/^none$/,@groups)) {
3838:6): $common_header = &mt('Assign Common Grade to Students in no Section and in no Group');
3839:6): $specific_header = &mt('Assign Grade to Specific Students in no Section and in no Group');
3840:6): } else {
3841:6): $common_header = &mt('Assign Common Grade to Students in no Section');
3842:6): $specific_header = &mt('Assign Grade to Specific Students in no Section');
3843:6): }
3844:6): } else {
3845:6): $section_display = join (", ",@sections);
3846:6): if ($group_display) {
3847:6): $common_header = &mt('Assign Common Grade to Students in Section(s) [_1], and in Group(s) [_2]',
3848:6): $section_display,$group_display);
3849:6): $specific_header = &mt('Assign Grade to Specific Students in Section(s) [_1], and in Group(s) [_2]',
3850:6): $section_display,$group_display);
3851:6): } elsif (grep(/^none$/,@groups)) {
3852:6): $common_header = &mt('Assign Common Grade to Students in Section(s) [_1] and no Group',$section_display);
3853:6): $specific_header = &mt('Assign Grade to Specific Students in Section(s) [_1] and no Group',$section_display);
3854:6): } else {
3855:6): $common_header = &mt('Assign Common Grade to Students in Section(s) [_1]',$section_display);
3856:6): $specific_header = &mt('Assign Grade to Specific Students in Section(s) [_1]',$section_display);
3857:6): }
1.52 albertel 3858: }
1.596.2.12.2. 7(raebur 3859:6): my %submit_types = &substatus_options();
3860:6): my $submission_status = $submit_types{$env{'form.submitonly'}};
3861:6):
3862:6): if ($env{'form.submitonly'} eq 'all') {
3863:6): $result.= '<h3>'.$common_header.'</h3>';
3864:6): } else {
3865:6): $result.= '<h3>'.$common_header.' '.&mt('(submission status: "[_1]")',$submission_status).'</h3>';
3866:6): }
3867:6): $result .= &Apache::loncommon::start_data_table();
1.44 ng 3868: #radio buttons/text box for assigning points for a section or class.
3869: #handles different parts of a problem
1.582 raeburn 3870: my $res_error;
3871: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
3872: if ($res_error) {
3873: return &navmap_errormsg();
3874: }
1.42 ng 3875: my %weight = ();
3876: my $ctsparts = 0;
1.45 ng 3877: my %seen = ();
1.375 albertel 3878: my @part_response_id = &flatten_responseType($responseType);
3879: foreach my $part_response_id (@part_response_id) {
3880: my ($partid,$respid) = @{ $part_response_id };
3881: my $part_resp = join('_',@{ $part_response_id });
1.45 ng 3882: next if $seen{$partid};
3883: $seen{$partid}++;
1.375 albertel 3884: my $handgrade=$$handgrade{$part_resp};
1.42 ng 3885: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
3886: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
3887:
1.324 albertel 3888: my $display_part=&get_display_part($partid,$symb);
1.485 albertel 3889: my $radio.='<table border="0"><tr>';
1.41 ng 3890: my $ctr = 0;
1.42 ng 3891: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
1.485 albertel 3892: $radio.= '<td><label><input type="radio" name="RADVAL_'.$partid.'" '.
1.54 albertel 3893: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.288 albertel 3894: ','.$ctr.')" />'.$ctr."</label></td>\n";
1.41 ng 3895: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
3896: $ctr++;
3897: }
1.485 albertel 3898: $radio.='</tr></table>';
3899: my $line = '<input type="text" name="TEXTVAL_'.
1.589 bisitz 3900: $partid.'" size="4" '.'onchange="javascript:writePoint(\''.
1.54 albertel 3901: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.539 riegler 3902: $weight{$partid}.' '.&mt('(problem weight)').'</td>'."\n";
1.596.2.12.2. 9(raebur 3903:3): $line.= '<td><b>'.&mt('Grade Status').':</b>'.
3904:3): '<select name="SELVAL_'.$partid.'" '.
3905:3): 'onchange="javascript:writeRadText(\''.$partid.'\','.
1.59 albertel 3906: $weight{$partid}.')"> '.
1.401 albertel 3907: '<option selected="selected"> </option>'.
1.485 albertel 3908: '<option value="excused">'.&mt('excused').'</option>'.
3909: '<option value="reset status">'.&mt('reset status').'</option>'.
3910: '</select></td>'.
3911: '<td><label><input type="checkbox" name="FORCE_'.$partid.'" />'.&mt('Override "Correct"').'</label>';
3912: $line.='<input type="hidden" name="partid_'.
3913: $ctsparts.'" value="'.$partid.'" />'."\n";
3914: $line.='<input type="hidden" name="weight_'.
3915: $partid.'" value="'.$weight{$partid}.'" />'."\n";
3916:
3917: $result.=
3918: &Apache::loncommon::start_data_table_row()."\n".
1.577 bisitz 3919: '<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 3920: &Apache::loncommon::end_data_table_row()."\n";
1.42 ng 3921: $ctsparts++;
1.41 ng 3922: }
1.474 albertel 3923: $result.=&Apache::loncommon::end_data_table()."\n".
1.52 albertel 3924: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.485 albertel 3925: $result.='<input type="button" value="'.&mt('Revert to Default').'" '.
1.589 bisitz 3926: 'onclick="javascript:resetEntry('.$ctsparts.');" />';
1.41 ng 3927:
1.44 ng 3928: #table listing all the students in a section/class
3929: #header of table
1.596.2.12.2. 7(raebur 3930:6): if ($env{'form.submitonly'} eq 'all') {
3931:6): $result.= '<h3>'.$specific_header.'</h3>';
3932:6): } else {
3933:6): $result.= '<h3>'.$specific_header.' '.&mt('(submission status: "[_1]")',$submission_status).'</h3>';
3934:6): }
3935:6): $result.= &Apache::loncommon::start_data_table().
1.560 raeburn 3936: &Apache::loncommon::start_data_table_header_row().
3937: '<th>'.&mt('No.').'</th>'.
3938: '<th>'.&nameUserString('header')."</th>\n";
1.582 raeburn 3939: my $partserror;
3940: my (@parts) = sort(&getpartlist($symb,\$partserror));
3941: if ($partserror) {
3942: return &navmap_errormsg();
3943: }
1.324 albertel 3944: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.269 raeburn 3945: my @partids = ();
1.41 ng 3946: foreach my $part (@parts) {
3947: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1.539 riegler 3948: my $narrowtext = &mt('Tries');
3949: $display =~ s|^Number of Attempts|$narrowtext <br />|; # makes the column narrower
1.41 ng 3950: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
1.207 albertel 3951: my ($partid) = &split_part_type($part);
1.524 raeburn 3952: push(@partids,$partid);
1.324 albertel 3953: my $display_part=&get_display_part($partid,$symb);
1.41 ng 3954: if ($display =~ /^Partial Credit Factor/) {
1.485 albertel 3955: $result.='<th>'.
1.596.2.12.2. 8(raebur 3956:3): &mt('Score Part: [_1][_2](weight = [_3])',
3957:3): $display_part,'<br />',$weight{$partid}).'</th>'."\n";
1.41 ng 3958: next;
1.485 albertel 3959:
1.207 albertel 3960: } else {
1.485 albertel 3961: if ($display =~ /Problem Status/) {
3962: my $grade_status_mt = &mt('Grade Status');
3963: $display =~ s{Problem Status}{$grade_status_mt<br />};
3964: }
3965: my $part_mt = &mt('Part:');
3966: $display =~s{\[Part: \Q$partid\E\]}{$part_mt $display_part};
1.41 ng 3967: }
1.485 albertel 3968:
1.474 albertel 3969: $result.='<th>'.$display.'</th>'."\n";
1.41 ng 3970: }
1.474 albertel 3971: $result.=&Apache::loncommon::end_data_table_header_row();
1.44 ng 3972:
1.270 albertel 3973: my %last_resets =
3974: &get_last_resets($symb,$env{'request.course.id'},\@partids);
1.269 raeburn 3975:
1.41 ng 3976: #get info for each student
1.44 ng 3977: #list all the students - with points and grade status
1.596.2.12.2. 7(raebur 3978:6): my (undef,undef,$fullname) = &getclasslist(\@sections,'1',\@groups);
1.41 ng 3979: my $ctr = 0;
1.294 albertel 3980: foreach (sort
3981: {
3982: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
3983: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
3984: }
3985: return $a cmp $b;
3986: } (keys(%$fullname))) {
1.324 albertel 3987: $result.=&viewstudentgrade($symb,$env{'request.course.id'},
1.596.2.12.2. 7(raebur 3988:6): $_,$$fullname{$_},\@parts,\%weight,\$ctr,\%last_resets);
1.41 ng 3989: }
1.474 albertel 3990: $result.=&Apache::loncommon::end_data_table();
1.41 ng 3991: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.485 albertel 3992: $result.='<input type="button" value="'.&mt('Save').'" '.
1.589 bisitz 3993: 'onclick="javascript:submit();" target="_self" /></form>'."\n";
1.596.2.12.2. 7(raebur 3994:6): if ($ctr == 0) {
1.442 banghart 3995: my $stu_status = join(' or ',&Apache::loncommon::get_env_multiple('form.Status'));
1.596.2.12.2. 7(raebur 3996:6): $result='<h3><span class="LC_info">'.&mt('Manual Grading').'</span></h3>'.
3997:6): '<span class="LC_warning">';
3998:6): if ($env{'form.submitonly'} eq 'all') {
3999:6): if (grep(/^all$/,@sections)) {
4000:6): if (grep(/^all$/,@groups)) {
4001:6): $result .= &mt('There are no students with enrollment status [_1] to modify or grade.',
4002:6): $stu_status);
4003:6): } elsif (grep(/^none$/,@groups)) {
4004:6): $result .= &mt('There are no students with no group assigned and with enrollment status [_1] to modify or grade.',
4005:6): $stu_status);
4006:6): } else {
4007:6): $result .= &mt('There are no students in group(s) [_1] with enrollment status [_2] to modify or grade.',
4008:6): $group_display,$stu_status);
4009:6): }
4010:6): } elsif (grep(/^none$/,@sections)) {
4011:6): if (grep(/^all$/,@groups)) {
4012:6): $result .= &mt('There are no students in no section with enrollment status [_1] to modify or grade.',
4013:6): $stu_status);
4014:6): } elsif (grep(/^none$/,@groups)) {
4015:6): $result .= &mt('There are no students in no section and no group with enrollment status [_1] to modify or grade.',
4016:6): $stu_status);
4017:6): } else {
4018:6): $result .= &mt('There are no students in no section in group(s) [_1] with enrollment status [_2] to modify or grade.',
4019:6): $group_display,$stu_status);
4020:6): }
4021:6): } else {
4022:6): if (grep(/^all$/,@groups)) {
4023:6): $result .= &mt('There are no students in section(s) [_1] with enrollment status [_2] to modify or grade.',
4024:6): $section_display,$stu_status);
4025:6): } elsif (grep(/^none$/,@groups)) {
9(raebur 4026:7): $result .= &mt('There are no students in section(s) [_1] and no group with enrollment status [_2] to modify or grade.',
7(raebur 4027:6): $section_display,$stu_status);
4028:6): } else {
4029:6): $result .= &mt('There are no students in section(s) [_1] and group(s) [_2] with enrollment status [_3] to modify or grade.',
4030:6): $section_display,$group_display,$stu_status);
4031:6): }
4032:6): }
4033:6): } else {
4034:6): if (grep(/^all$/,@sections)) {
4035:6): if (grep(/^all$/,@groups)) {
4036:6): $result .= &mt('There are no students with enrollment status [_1] and submission status "[_2]" to modify or grade.',
4037:6): $stu_status,$submission_status);
4038:6): } elsif (grep(/^none$/,@groups)) {
4039:6): $result .= &mt('There are no students with no group assigned with enrollment status [_1] and submission status "[_2]" to modify or grade.',
4040:6): $stu_status,$submission_status);
4041:6): } else {
4042:6): $result .= &mt('There are no students in group(s) [_1] with enrollment status [_2] and submission status "[_3]" to modify or grade.',
4043:6): $group_display,$stu_status,$submission_status);
4044:6): }
4045:6): } elsif (grep(/^none$/,@sections)) {
4046:6): if (grep(/^all$/,@groups)) {
4047:6): $result .= &mt('There are no students in no section with enrollment status [_1] and submission status "[_2]" to modify or grade.',
4048:6): $stu_status,$submission_status);
4049:6): } elsif (grep(/^none$/,@groups)) {
4050:6): $result .= &mt('There are no students in no section and no group with enrollment status [_1] and submission status "[_2]" to modify or grade.',
4051:6): $stu_status,$submission_status);
4052:6): } else {
4053:6): $result .= &mt('There are no students in no section in group(s) [_1] with enrollment status [_2] and submission status "[_3]" to modify or grade.',
4054:6): $group_display,$stu_status,$submission_status);
4055:6): }
4056:6): } else {
4057:6): if (grep(/^all$/,@groups)) {
4058:6): $result .= &mt('There are no students in section(s) [_1] with enrollment status [_2] and submission status "[_3]" to modify or grade.',
4059:6): $section_display,$stu_status,$submission_status);
4060:6): } elsif (grep(/^none$/,@groups)) {
4061:6): $result .= &mt('There are no students in section(s) [_1] and no group with enrollment status [_2] and submission status "[_3]" to modify or grade.',
4062:6): $section_display,$stu_status,$submission_status);
4063:6): } else {
4064:6): $result .= &mt('There are no students in section(s) [_1] and group(s) [_2] with enrollment status [_3] and submission status "[_4]" to modify or grade.',
4065:6): $section_display,$group_display,$stu_status,$submission_status);
4066:6): }
4067:6): }
4068:6): }
4069:6): $result .= '</span><br />';
1.96 albertel 4070: }
1.324 albertel 4071: $result.=&show_grading_menu_form($symb);
1.41 ng 4072: return $result;
4073: }
4074:
1.596.2.12.2. 7(raebur 4075:6): #--- call by previous routine to display each student who satisfies submission filter.
1.41 ng 4076: sub viewstudentgrade {
1.324 albertel 4077: my ($symb,$courseid,$student,$fullname,$parts,$weight,$ctr,$last_resets) = @_;
1.44 ng 4078: my ($uname,$udom) = split(/:/,$student);
4079: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.596.2.12.2. 7(raebur 4080:6): my $submitonly = $env{'form.submitonly'};
4081:6): unless (($submitonly eq 'all') || ($submitonly eq 'queued')) {
4082:6): my %partstatus = ();
4083:6): if (ref($parts) eq 'ARRAY') {
4084:6): foreach my $apart (@{$parts}) {
4085:6): my ($part,$type) = &split_part_type($apart);
4086:6): my ($status,undef) = split(/_/,$record{"resource.$part.solved"},2);
4087:6): $status = 'nothing' if ($status eq '');
4088:6): $partstatus{$part} = $status;
4089:6): my $subkey = "resource.$part.submitted_by";
4090:6): $partstatus{$subkey} = $record{$subkey} if ($record{$subkey} ne '');
4091:6): }
4092:6): my $submitted = 0;
4093:6): my $graded = 0;
4094:6): my $incorrect = 0;
4095:6): foreach my $key (keys(%partstatus)) {
4096:6): $submitted = 1 if ($partstatus{$key} ne 'nothing');
4097:6): $graded = 1 if ($partstatus{$key} =~ /^ungraded/);
4098:6): $incorrect = 1 if ($partstatus{$key} =~ /^incorrect/);
4099:6):
4100:6): my $partid = (split(/\./,$key))[1];
4101:6): if ($partstatus{'resource.'.$partid.'.'.$key.'.submitted_by'} ne '') {
4102:6): $submitted = 0;
4103:6): }
4104:6): }
4105:6): return if (!$submitted && ($submitonly eq 'yes' ||
4106:6): $submitonly eq 'incorrect' ||
4107:6): $submitonly eq 'graded'));
4108:6): return if (!$graded && ($submitonly eq 'graded'));
4109:6): return if (!$incorrect && $submitonly eq 'incorrect');
4110:6): }
4111:6): }
4112:6): if ($submitonly eq 'queued') {
4113:6): my ($cdom,$cnum) = split(/_/,$courseid);
4114:6): my %queue_status =
4115:6): &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
4116:6): $udom,$uname);
4117:6): return if (!defined($queue_status{'gradingqueue'}));
4118:6): }
4119:6): $$ctr++;
4120:6): my %aggregates = ();
1.474 albertel 4121: my $result=&Apache::loncommon::start_data_table_row().'<td align="right">'.
1.596.2.12.2. 7(raebur 4122:6): '<input type="hidden" name="ctr'.($$ctr-1).'" value="'.$student.'" />'.
4123:6): "\n".$$ctr.' </td><td> '.
1.44 ng 4124: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 4125: '\');" target="_self">'.$fullname.'</a> '.
1.398 albertel 4126: '<span class="LC_internal_info">('.$uname.($env{'user.domain'} eq $udom ? '' : ':'.$udom).')</span></td>'."\n";
1.281 albertel 4127: $student=~s/:/_/; # colon doen't work in javascript for names
1.63 albertel 4128: foreach my $apart (@$parts) {
4129: my ($part,$type) = &split_part_type($apart);
1.41 ng 4130: my $score=$record{"resource.$part.$type"};
1.276 albertel 4131: $result.='<td align="center">';
1.269 raeburn 4132: my ($aggtries,$totaltries);
4133: unless (exists($aggregates{$part})) {
1.270 albertel 4134: $totaltries = $record{'resource.'.$part.'.tries'};
4135:
4136: $aggtries = $totaltries;
1.269 raeburn 4137: if ($$last_resets{$part}) {
1.270 albertel 4138: $aggtries = &get_num_tries(\%record,$$last_resets{$part},
4139: $part);
4140: }
1.269 raeburn 4141: $result.='<input type="hidden" name="'.
4142: 'GD_'.$student.'_'.$part.'_aggtries" value="'.$aggtries.'" />'."\n";
4143: $result.='<input type="hidden" name="'.
4144: 'GD_'.$student.'_'.$part.'_totaltries" value="'.$totaltries.'" />'."\n";
4145: $aggregates{$part} = 1;
4146: }
1.41 ng 4147: if ($type eq 'awarded') {
1.320 albertel 4148: my $pts = $score eq '' ? '' : &compute_points($score,$$weight{$part});
1.42 ng 4149: $result.='<input type="hidden" name="'.
1.89 albertel 4150: 'GD_'.$student.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.233 albertel 4151: $result.='<input type="text" name="'.
1.89 albertel 4152: 'GD_'.$student.'_'.$part.'_awarded" '.
1.589 bisitz 4153: 'onchange="javascript:changeSelect(\''.$part.'\',\''.$student.
1.44 ng 4154: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41 ng 4155: } elsif ($type eq 'solved') {
4156: my ($status,$foo)=split(/_/,$score,2);
4157: $status = 'nothing' if ($status eq '');
1.89 albertel 4158: $result.='<input type="hidden" name="'.'GD_'.$student.'_'.
1.54 albertel 4159: $part.'_solved_s" value="'.$status.'" />'."\n";
1.233 albertel 4160: $result.=' <select name="'.
1.89 albertel 4161: 'GD_'.$student.'_'.$part.'_solved" '.
1.589 bisitz 4162: 'onchange="javascript:changeOneScore(\''.$part.'\',\''.$student.'\')" >'."\n";
1.485 albertel 4163: $result.= (($status eq 'excused') ? '<option> </option><option selected="selected" value="excused">'.&mt('excused').'</option>'
4164: : '<option selected="selected"> </option><option value="excused">'.&mt('excused').'</option>')."\n";
4165: $result.='<option value="reset status">'.&mt('reset status').'</option>';
1.126 ng 4166: $result.="</select> </td>\n";
1.122 ng 4167: } else {
4168: $result.='<input type="hidden" name="'.
4169: 'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
4170: "\n";
1.233 albertel 4171: $result.='<input type="text" name="'.
1.122 ng 4172: 'GD_'.$student.'_'.$part.'_'.$type.'" '.
4173: 'value="'.$score.'" size="4" /></td>'."\n";
1.41 ng 4174: }
4175: }
1.474 albertel 4176: $result.=&Apache::loncommon::end_data_table_row();
1.41 ng 4177: return $result;
1.38 ng 4178: }
4179:
1.44 ng 4180: #--- change scores for all the students in a section/class
4181: # record does not get update if unchanged
1.38 ng 4182: sub editgrades {
1.41 ng 4183: my ($request) = @_;
4184:
1.596.2.12.2. (raeburn 4185:): my ($symb)=&get_symb($request);
1.433 banghart 4186: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.477 albertel 4187: my $title='<h2>'.&mt('Current Grade Status').'</h2>';
1.596.2.12.2. 9(raebur 4188:3): $title.='<h4><b>'.&mt('Current Resource').':</b> '.$env{'form.probTitle'}.'</h4>'."\n";
4189:3): $title.='<h4><b>'.&mt('Section:').'</b> '.$section_display.'</h4>'."\n";
1.126 ng 4190:
1.477 albertel 4191: my $result= &Apache::loncommon::start_data_table().
4192: &Apache::loncommon::start_data_table_header_row().
4193: '<th rowspan="2" valign="middle">'.&mt('No.').'</th>'.
4194: '<th rowspan="2" valign="middle">'.&nameUserString('header')."</th>\n";
1.43 ng 4195: my %scoreptr = (
4196: 'correct' =>'correct_by_override',
4197: 'incorrect'=>'incorrect_by_override',
4198: 'excused' =>'excused',
4199: 'ungraded' =>'ungraded_attempted',
1.596 raeburn 4200: 'credited' =>'credit_attempted',
1.43 ng 4201: 'nothing' => '',
4202: );
1.257 albertel 4203: my ($classlist,undef,$fullname) = &getclasslist($env{'form.section'},'0');
1.34 ng 4204:
1.44 ng 4205: my (@partid);
4206: my %weight = ();
1.54 albertel 4207: my %columns = ();
1.44 ng 4208: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54 albertel 4209:
1.582 raeburn 4210: my $partserror;
4211: my (@parts) = sort(&getpartlist($symb,\$partserror));
4212: if ($partserror) {
4213: return &navmap_errormsg();
4214: }
1.54 albertel 4215: my $header;
1.257 albertel 4216: while ($ctr < $env{'form.totalparts'}) {
4217: my $partid = $env{'form.partid_'.$ctr};
1.524 raeburn 4218: push(@partid,$partid);
1.257 albertel 4219: $weight{$partid} = $env{'form.weight_'.$partid};
1.44 ng 4220: $ctr++;
1.54 albertel 4221: }
1.324 albertel 4222: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.596.2.12.2. 2(raebur 4223:8): my $totcolspan = 0;
1.54 albertel 4224: foreach my $partid (@partid) {
1.478 albertel 4225: $header .= '<th align="center">'.&mt('Old Score').'</th>'.
4226: '<th align="center">'.&mt('New Score').'</th>';
1.54 albertel 4227: $columns{$partid}=2;
4228: foreach my $stores (@parts) {
4229: my ($part,$type) = &split_part_type($stores);
4230: if ($part !~ m/^\Q$partid\E/) { next;}
4231: if ($type eq 'awarded' || $type eq 'solved') { next; }
4232: my $display=&Apache::lonnet::metadata($url,$stores.'.display');
1.551 raeburn 4233: $display =~ s/\[Part: \Q$part\E\]//;
1.539 riegler 4234: my $narrowtext = &mt('Tries');
4235: $display =~ s/Number of Attempts/$narrowtext/;
4236: $header .= '<th align="center">'.&mt('Old').' '.$display.'</th>'.
4237: '<th align="center">'.&mt('New').' '.$display.'</th>';
1.54 albertel 4238: $columns{$partid}+=2;
4239: }
1.596.2.12.2. 2(raebur 4240:8): $totcolspan += $columns{$partid};
1.54 albertel 4241: }
4242: foreach my $partid (@partid) {
1.324 albertel 4243: my $display_part=&get_display_part($partid,$symb);
1.478 albertel 4244: $result .= '<th colspan="'.$columns{$partid}.'" align="center">'.
4245: &mt('Part: [_1] (Weight = [_2])',$display_part,$weight{$partid}).
4246: '</th>';
1.54 albertel 4247:
1.44 ng 4248: }
1.477 albertel 4249: $result .= &Apache::loncommon::end_data_table_header_row().
4250: &Apache::loncommon::start_data_table_header_row().
4251: $header.
4252: &Apache::loncommon::end_data_table_header_row();
4253: my @noupdate;
1.126 ng 4254: my ($updateCtr,$noupdateCtr) = (1,1);
1.257 albertel 4255: for ($i=0; $i<$env{'form.total'}; $i++) {
4256: my $user = $env{'form.ctr'.$i};
1.281 albertel 4257: my ($uname,$udom)=split(/:/,$user);
1.44 ng 4258: my %newrecord;
4259: my $updateflag = 0;
1.596.2.12.2. 2(raebur 4260:8): my $usec=$classlist->{"$uname:$udom"}[5];
4261:8): my $canmodify = &canmodify($usec);
4262:8): my $line = '<td'.($canmodify?'':' colspan="2"').'>'.
4263:8): &nameUserString(undef,$$fullname{$user},$uname,$udom).'</td>';
4264:8): if (!$canmodify) {
4265:8): push(@noupdate,
4266:8): $line."<td colspan=\"$totcolspan\"><span class=\"LC_warning\">".
4267:8): &mt('Not allowed to modify student')."</span></td>");
4268:8): next;
4269:8): }
1.269 raeburn 4270: my %aggregate = ();
4271: my $aggregateflag = 0;
1.281 albertel 4272: $user=~s/:/_/; # colon doen't work in javascript for names
1.44 ng 4273: foreach (@partid) {
1.257 albertel 4274: my $old_aw = $env{'form.GD_'.$user.'_'.$_.'_awarded_s'};
1.54 albertel 4275: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
4276: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
1.257 albertel 4277: my $old_score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
4278: my $awarded = $env{'form.GD_'.$user.'_'.$_.'_awarded'};
1.54 albertel 4279: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
4280: my $partial = $awarded eq '' ? '' : $pcr;
1.44 ng 4281: my $score;
4282: if ($partial eq '') {
1.257 albertel 4283: $score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 4284: } elsif ($partial > 0) {
4285: $score = 'correct_by_override';
4286: } elsif ($partial == 0) {
4287: $score = 'incorrect_by_override';
4288: }
1.257 albertel 4289: my $dropMenu = $env{'form.GD_'.$user.'_'.$_.'_solved'};
1.125 ng 4290: $score = 'excused' if (($dropMenu eq 'excused') && ($score ne 'excused'));
4291:
1.292 albertel 4292: $newrecord{'resource.'.$_.'.regrader'}=
4293: "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 4294: if ($dropMenu eq 'reset status' &&
4295: $old_score ne '') { # ignore if no previous attempts => nothing to reset
1.299 albertel 4296: $newrecord{'resource.'.$_.'.tries'} = '';
1.125 ng 4297: $newrecord{'resource.'.$_.'.solved'} = '';
4298: $newrecord{'resource.'.$_.'.award'} = '';
1.299 albertel 4299: $newrecord{'resource.'.$_.'.awarded'} = '';
1.125 ng 4300: $updateflag = 1;
1.269 raeburn 4301: if ($env{'form.GD_'.$user.'_'.$_.'_aggtries'} > 0) {
4302: my $aggtries = $env{'form.GD_'.$user.'_'.$_.'_aggtries'};
4303: my $totaltries = $env{'form.GD_'.$user.'_'.$_.'_totaltries'};
4304: my $solvedstatus = $env{'form.GD_'.$user.'_'.$_.'_solved_s'};
4305: &decrement_aggs($symb,$_,\%aggregate,$aggtries,$totaltries,$solvedstatus);
4306: $aggregateflag = 1;
4307: }
1.139 albertel 4308: } elsif (!($old_part eq $partial && $old_score eq $score)) {
4309: $updateflag = 1;
4310: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
4311: $newrecord{'resource.'.$_.'.solved'} = $score;
4312: $rec_update++;
1.125 ng 4313: }
4314:
1.93 albertel 4315: $line .= '<td align="center">'.$old_aw.' </td>'.
1.44 ng 4316: '<td align="center">'.$awarded.
4317: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 4318:
1.54 albertel 4319:
4320: my $partid=$_;
4321: foreach my $stores (@parts) {
4322: my ($part,$type) = &split_part_type($stores);
4323: if ($part !~ m/^\Q$partid\E/) { next;}
4324: if ($type eq 'awarded' || $type eq 'solved') { next; }
1.257 albertel 4325: my $old_aw = $env{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
4326: my $awarded = $env{'form.GD_'.$user.'_'.$part.'_'.$type};
1.54 albertel 4327: if ($awarded ne '' && $awarded ne $old_aw) {
4328: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.257 albertel 4329: $newrecord{'resource.'.$part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.54 albertel 4330: $updateflag=1;
4331: }
1.93 albertel 4332: $line .= '<td align="center">'.$old_aw.' </td>'.
1.54 albertel 4333: '<td align="center">'.$awarded.' </td>';
4334: }
1.44 ng 4335: }
1.477 albertel 4336: $line.="\n";
1.301 albertel 4337:
4338: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4339: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4340:
1.44 ng 4341: if ($updateflag) {
4342: $count++;
1.257 albertel 4343: &Apache::lonnet::cstore(\%newrecord,$symb,$env{'request.course.id'},
1.89 albertel 4344: $udom,$uname);
1.301 albertel 4345:
4346: if (&Apache::bridgetask::in_queue('gradingqueue',$symb,$cdom,
4347: $cnum,$udom,$uname)) {
4348: # need to figure out if should be in queue.
4349: my %record =
4350: &Apache::lonnet::restore($symb,$env{'request.course.id'},
4351: $udom,$uname);
4352: my $all_graded = 1;
4353: my $none_graded = 1;
4354: foreach my $part (@parts) {
4355: if ( $record{'resource.'.$part.'.awarded'} eq '' ) {
4356: $all_graded = 0;
4357: } else {
4358: $none_graded = 0;
4359: }
4360: }
4361:
4362: if ($all_graded || $none_graded) {
4363: &Apache::bridgetask::remove_from_queue('gradingqueue',
4364: $symb,$cdom,$cnum,
4365: $udom,$uname);
4366: }
4367: }
4368:
1.477 albertel 4369: $result.=&Apache::loncommon::start_data_table_row().
4370: '<td align="right"> '.$updateCtr.' </td>'.$line.
4371: &Apache::loncommon::end_data_table_row();
1.126 ng 4372: $updateCtr++;
1.93 albertel 4373: } else {
1.477 albertel 4374: push(@noupdate,
4375: '<td align="right"> '.$noupdateCtr.' </td>'.$line);
1.126 ng 4376: $noupdateCtr++;
1.44 ng 4377: }
1.269 raeburn 4378: if ($aggregateflag) {
4379: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 4380: $cdom,$cnum);
1.269 raeburn 4381: }
1.93 albertel 4382: }
1.477 albertel 4383: if (@noupdate) {
1.596.2.12.2. 2(raebur 4384:8): my $numcols=$totcolspan+2;
1.477 albertel 4385: $result .= &Apache::loncommon::start_data_table_row('LC_empty_row').
1.478 albertel 4386: '<td align="center" colspan="'.$numcols.'">'.
4387: &mt('No Changes Occurred For the Students Below').
4388: '</td>'.
1.477 albertel 4389: &Apache::loncommon::end_data_table_row();
4390: foreach my $line (@noupdate) {
4391: $result.=
4392: &Apache::loncommon::start_data_table_row().
4393: $line.
4394: &Apache::loncommon::end_data_table_row();
4395: }
1.44 ng 4396: }
1.477 albertel 4397: $result .= &Apache::loncommon::end_data_table().
4398: &show_grading_menu_form($symb);
1.478 albertel 4399: my $msg = '<p><b>'.
4400: &mt('Number of records updated = [_1] for [quant,_2,student].',
4401: $rec_update,$count).'</b><br />'.
4402: '<b>'.&mt('Total number of students = [_1]',$env{'form.total'}).
4403: '</b></p>';
1.44 ng 4404: return $title.$msg.$result;
1.5 albertel 4405: }
1.54 albertel 4406:
4407: sub split_part_type {
4408: my ($partstr) = @_;
4409: my ($temp,@allparts)=split(/_/,$partstr);
4410: my $type=pop(@allparts);
1.439 albertel 4411: my $part=join('_',@allparts);
1.54 albertel 4412: return ($part,$type);
4413: }
4414:
1.44 ng 4415: #------------- end of section for handling grading by section/class ---------
4416: #
4417: #----------------------------------------------------------------------------
4418:
1.5 albertel 4419:
1.44 ng 4420: #----------------------------------------------------------------------------
4421: #
4422: #-------------------------- Next few routines handles grading by csv upload
4423: #
4424: #--- Javascript to handle csv upload
1.27 albertel 4425: sub csvupload_javascript_reverse_associate {
1.573 bisitz 4426: my $error1=&mt('You need to specify the username or the student/employee ID');
1.246 albertel 4427: my $error2=&mt('You need to specify at least one grading field');
1.596.2.12.2. 6(raebur 4428:6): &js_escape(\$error1);
4429:6): &js_escape(\$error2);
1.27 albertel 4430: return(<<ENDPICK);
4431: function verify(vf) {
4432: var foundsomething=0;
4433: var founduname=0;
1.243 albertel 4434: var foundID=0;
1.27 albertel 4435: for (i=0;i<=vf.nfields.value;i++) {
4436: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 4437: if (i==0 && tw!=0) { foundID=1; }
4438: if (i==1 && tw!=0) { founduname=1; }
4439: if (i!=0 && i!=1 && i!=2 && tw!=0) { foundsomething=1; }
1.27 albertel 4440: }
1.246 albertel 4441: if (founduname==0 && foundID==0) {
4442: alert('$error1');
4443: return;
1.27 albertel 4444: }
4445: if (foundsomething==0) {
1.246 albertel 4446: alert('$error2');
4447: return;
1.27 albertel 4448: }
4449: vf.submit();
4450: }
4451: function flip(vf,tf) {
4452: var nw=eval('vf.f'+tf+'.selectedIndex');
4453: var i;
4454: for (i=0;i<=vf.nfields.value;i++) {
4455: //can not pick the same destination field for both name and domain
4456: if (((i ==0)||(i ==1)) &&
4457: ((tf==0)||(tf==1)) &&
4458: (i!=tf) &&
4459: (eval('vf.f'+i+'.selectedIndex')==nw)) {
4460: eval('vf.f'+i+'.selectedIndex=0;')
4461: }
4462: }
4463: }
4464: ENDPICK
4465: }
4466:
4467: sub csvupload_javascript_forward_associate {
1.573 bisitz 4468: my $error1=&mt('You need to specify the username or the student/employee ID');
1.246 albertel 4469: my $error2=&mt('You need to specify at least one grading field');
1.596.2.12.2. 6(raebur 4470:6): &js_escape(\$error1);
4471:6): &js_escape(\$error2);
1.27 albertel 4472: return(<<ENDPICK);
4473: function verify(vf) {
4474: var foundsomething=0;
4475: var founduname=0;
1.243 albertel 4476: var foundID=0;
1.27 albertel 4477: for (i=0;i<=vf.nfields.value;i++) {
4478: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 4479: if (tw==1) { foundID=1; }
4480: if (tw==2) { founduname=1; }
4481: if (tw>3) { foundsomething=1; }
1.27 albertel 4482: }
1.246 albertel 4483: if (founduname==0 && foundID==0) {
4484: alert('$error1');
4485: return;
1.27 albertel 4486: }
4487: if (foundsomething==0) {
1.246 albertel 4488: alert('$error2');
4489: return;
1.27 albertel 4490: }
4491: vf.submit();
4492: }
4493: function flip(vf,tf) {
4494: var nw=eval('vf.f'+tf+'.selectedIndex');
4495: var i;
4496: //can not pick the same destination field twice
4497: for (i=0;i<=vf.nfields.value;i++) {
4498: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
4499: eval('vf.f'+i+'.selectedIndex=0;')
4500: }
4501: }
4502: }
4503: ENDPICK
4504: }
4505:
1.26 albertel 4506: sub csvuploadmap_header {
1.324 albertel 4507: my ($request,$symb,$datatoken,$distotal)= @_;
1.41 ng 4508: my $javascript;
1.257 albertel 4509: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 4510: $javascript=&csvupload_javascript_reverse_associate();
4511: } else {
4512: $javascript=&csvupload_javascript_forward_associate();
4513: }
1.45 ng 4514:
1.324 albertel 4515: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.257 albertel 4516: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1.245 albertel 4517: my $ignore=&mt('Ignore First Line');
1.418 albertel 4518: $symb = &Apache::lonenc::check_encrypt($symb);
1.41 ng 4519: $request->print(<<ENDPICK);
1.26 albertel 4520: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.398 albertel 4521: <h3><span class="LC_info">Uploading Class Grades</span></h3>
1.45 ng 4522: $result
1.326 albertel 4523: <hr />
1.26 albertel 4524: <h3>Identify fields</h3>
4525: Total number of records found in file: $distotal <hr />
4526: Enter as many fields as you can. The system will inform you and bring you back
4527: to this page if the data selected is insufficient to run your class.<hr />
1.589 bisitz 4528: <input type="button" value="Reverse Association" onclick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1.245 albertel 4529: <label><input type="checkbox" name="noFirstLine" $checked />$ignore</label>
1.26 albertel 4530: <input type="hidden" name="associate" value="" />
4531: <input type="hidden" name="phase" value="three" />
4532: <input type="hidden" name="datatoken" value="$datatoken" />
1.257 albertel 4533: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
4534: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
1.26 albertel 4535: <input type="hidden" name="upfile_associate"
1.257 albertel 4536: value="$env{'form.upfile_associate'}" />
1.26 albertel 4537: <input type="hidden" name="symb" value="$symb" />
1.257 albertel 4538: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
4539: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
1.246 albertel 4540: <input type="hidden" name="command" value="csvuploadoptions" />
1.26 albertel 4541: <hr />
4542: <script type="text/javascript" language="Javascript">
4543: $javascript
4544: </script>
4545: ENDPICK
1.118 ng 4546: return '';
1.26 albertel 4547:
4548: }
4549:
4550: sub csvupload_fields {
1.582 raeburn 4551: my ($symb,$errorref) = @_;
4552: my (@parts) = &getpartlist($symb,$errorref);
4553: if (ref($errorref)) {
4554: if ($$errorref) {
4555: return;
4556: }
4557: }
4558:
1.556 weissno 4559: my @fields=(['ID','Student/Employee ID'],
1.243 albertel 4560: ['username','Student Username'],
4561: ['domain','Student Domain']);
1.324 albertel 4562: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.41 ng 4563: foreach my $part (sort(@parts)) {
4564: my @datum;
4565: my $display=&Apache::lonnet::metadata($url,$part.'.display');
4566: my $name=$part;
4567: if (!$display) { $display = $name; }
4568: @datum=($name,$display);
1.244 albertel 4569: if ($name=~/^stores_(.*)_awarded/) {
4570: push(@fields,['stores_'.$1.'_points',"Points [Part: $1]"]);
4571: }
1.41 ng 4572: push(@fields,\@datum);
4573: }
4574: return (@fields);
1.26 albertel 4575: }
4576:
4577: sub csvuploadmap_footer {
1.41 ng 4578: my ($request,$i,$keyfields) =@_;
1.596.2.12.2. 0(raebur 4579:3): my $buttontext = &mt('Assign Grades');
1.41 ng 4580: $request->print(<<ENDPICK);
1.26 albertel 4581: </table>
4582: <input type="hidden" name="nfields" value="$i" />
4583: <input type="hidden" name="keyfields" value="$keyfields" />
1.596.2.12.2. 0(raebur 4584:3): <input type="button" onclick="javascript:verify(this.form)" value="$buttontext" /><br />
1.26 albertel 4585: </form>
4586: ENDPICK
4587: }
4588:
1.283 albertel 4589: sub checkforfile_js {
1.539 riegler 4590: my $alertmsg = &mt('Please use the browse button to select a file from your local directory.');
1.596.2.12.2. 6(raebur 4591:6): &js_escape(\$alertmsg);
1.86 ng 4592: my $result =<<CSVFORMJS;
4593: <script type="text/javascript" language="javascript">
4594: function checkUpload(formname) {
4595: if (formname.upfile.value == "") {
1.539 riegler 4596: alert("$alertmsg");
1.86 ng 4597: return false;
4598: }
4599: formname.submit();
4600: }
4601: </script>
4602: CSVFORMJS
1.283 albertel 4603: return $result;
4604: }
4605:
4606: sub upcsvScores_form {
4607: my ($request) = shift;
1.324 albertel 4608: my ($symb)=&get_symb($request);
1.283 albertel 4609: if (!$symb) {return '';}
4610: my $result=&checkforfile_js();
1.257 albertel 4611: $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
1.324 albertel 4612: my ($table) = &showResourceInfo($symb,$env{'form.probTitle'});
1.118 ng 4613: $result.=$table;
1.326 albertel 4614: $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
4615: $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
1.538 schulted 4616: $result.=' <b>'.&mt('Specify a file containing the class scores for current resource.').
4617: '</b></td></tr>'."\n";
1.596.2.4 raeburn 4618: $result.='<tr bgcolor="#ffffe6"><td>'."\n";
1.370 www 4619: my $upload=&mt("Upload Scores");
1.86 ng 4620: my $upfile_select=&Apache::loncommon::upfile_select_html();
1.245 albertel 4621: my $ignore=&mt('Ignore First Line');
1.418 albertel 4622: $symb = &Apache::lonenc::check_encrypt($symb);
1.86 ng 4623: $result.=<<ENDUPFORM;
1.106 albertel 4624: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.86 ng 4625: <input type="hidden" name="symb" value="$symb" />
4626: <input type="hidden" name="command" value="csvuploadmap" />
1.257 albertel 4627: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
4628: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
1.86 ng 4629: $upfile_select
1.589 bisitz 4630: <br /><input type="button" onclick="javascript:checkUpload(this.form);" value="$upload" />
1.283 albertel 4631: <label><input type="checkbox" name="noFirstLine" />$ignore</label>
1.86 ng 4632: </form>
4633: ENDUPFORM
1.370 www 4634: $result.=&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
4635: &mt("How do I create a CSV file from a spreadsheet"))
4636: .'</td></tr></table>'."\n";
1.86 ng 4637: $result.='</td></tr></table><br /><br />'."\n";
1.324 albertel 4638: $result.=&show_grading_menu_form($symb);
1.86 ng 4639: return $result;
4640: }
4641:
4642:
1.26 albertel 4643: sub csvuploadmap {
1.41 ng 4644: my ($request)= @_;
1.324 albertel 4645: my ($symb)=&get_symb($request);
1.41 ng 4646: if (!$symb) {return '';}
1.72 ng 4647:
1.41 ng 4648: my $datatoken;
1.257 albertel 4649: if (!$env{'form.datatoken'}) {
1.41 ng 4650: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 4651: } else {
1.596.2.12.2. 3(raebur 4652:8): $datatoken=&Apache::loncommon::valid_datatoken($env{'form.datatoken'});
4653:8): if ($datatoken ne '') {
4654:8): &Apache::loncommon::load_tmp_file($request,$datatoken);
4655:8): }
1.26 albertel 4656: }
1.41 ng 4657: my @records=&Apache::loncommon::upfile_record_sep();
1.257 albertel 4658: if ($env{'form.noFirstLine'}) { shift(@records); }
1.324 albertel 4659: &csvuploadmap_header($request,$symb,$datatoken,$#records+1);
1.41 ng 4660: my ($i,$keyfields);
4661: if (@records) {
1.582 raeburn 4662: my $fieldserror;
4663: my @fields=&csvupload_fields($symb,\$fieldserror);
4664: if ($fieldserror) {
4665: $request->print(&navmap_errormsg());
4666: return;
4667: }
1.257 albertel 4668: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 4669: &Apache::loncommon::csv_print_samples($request,\@records);
4670: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
4671: \@fields);
4672: foreach (@fields) { $keyfields.=$_->[0].','; }
4673: chop($keyfields);
4674: } else {
4675: unshift(@fields,['none','']);
4676: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
4677: \@fields);
1.311 banghart 4678: foreach my $rec (@records) {
4679: my %temp = &Apache::loncommon::record_sep($rec);
4680: if (%temp) {
4681: $keyfields=join(',',sort(keys(%temp)));
4682: last;
4683: }
4684: }
1.41 ng 4685: }
4686: }
4687: &csvuploadmap_footer($request,$i,$keyfields);
1.324 albertel 4688: $request->print(&show_grading_menu_form($symb));
1.72 ng 4689:
1.41 ng 4690: return '';
1.27 albertel 4691: }
4692:
1.246 albertel 4693: sub csvuploadoptions {
1.41 ng 4694: my ($request)= @_;
1.324 albertel 4695: my ($symb)=&get_symb($request);
1.257 albertel 4696: my $checked=(($env{'form.noFirstLine'})?'1':'0');
1.246 albertel 4697: my $ignore=&mt('Ignore First Line');
4698: $request->print(<<ENDPICK);
4699: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.398 albertel 4700: <h3><span class="LC_info">Uploading Class Grade Options</span></h3>
1.246 albertel 4701: <input type="hidden" name="command" value="csvuploadassign" />
1.302 albertel 4702: <!--
1.246 albertel 4703: <p>
4704: <label>
4705: <input type="checkbox" name="show_full_results" />
4706: Show a table of all changes
4707: </label>
4708: </p>
1.302 albertel 4709: -->
1.246 albertel 4710: <p>
4711: <label>
4712: <input type="checkbox" name="overwite_scores" checked="checked" />
4713: Overwrite any existing score
4714: </label>
4715: </p>
4716: ENDPICK
4717: my %fields=&get_fields();
4718: if (!defined($fields{'domain'})) {
1.257 albertel 4719: my $domform = &Apache::loncommon::select_dom_form($env{'request.role.domain'},'default_domain');
1.246 albertel 4720: $request->print("\n<p> Users are in domain: ".$domform."</p>\n");
4721: }
1.257 albertel 4722: foreach my $key (sort(keys(%env))) {
1.246 albertel 4723: if ($key !~ /^form\.(.*)$/) { next; }
4724: my $cleankey=$1;
4725: if ($cleankey eq 'command') { next; }
4726: $request->print('<input type="hidden" name="'.$cleankey.
1.257 albertel 4727: '" value="'.$env{$key}.'" />'."\n");
1.246 albertel 4728: }
4729: # FIXME do a check for any duplicated user ids...
4730: # FIXME do a check for any invalid user ids?...
1.596.2.12.2. 0(raebur 4731:3): $request->print('<input type="submit" value="'.&mt('Assign Grades').'" /><br />
1.290 albertel 4732: <hr /></form>'."\n");
1.324 albertel 4733: $request->print(&show_grading_menu_form($symb));
1.246 albertel 4734: return '';
4735: }
4736:
4737: sub get_fields {
4738: my %fields;
1.257 albertel 4739: my @keyfields = split(/\,/,$env{'form.keyfields'});
4740: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
4741: if ($env{'form.upfile_associate'} eq 'reverse') {
4742: if ($env{'form.f'.$i} ne 'none') {
4743: $fields{$keyfields[$i]}=$env{'form.f'.$i};
1.41 ng 4744: }
4745: } else {
1.257 albertel 4746: if ($env{'form.f'.$i} ne 'none') {
4747: $fields{$env{'form.f'.$i}}=$keyfields[$i];
1.41 ng 4748: }
4749: }
1.27 albertel 4750: }
1.246 albertel 4751: return %fields;
4752: }
4753:
4754: sub csvuploadassign {
4755: my ($request)= @_;
1.324 albertel 4756: my ($symb)=&get_symb($request);
1.246 albertel 4757: if (!$symb) {return '';}
1.345 bowersj2 4758: my $error_msg = '';
1.596.2.12.2. 3(raebur 4759:8): my $datatoken = &Apache::loncommon::valid_datatoken($env{'form.datatoken'});
4760:8): if ($datatoken ne '') {
4761:8): &Apache::loncommon::load_tmp_file($request,$datatoken);
4762:8): }
1.246 albertel 4763: my @gradedata = &Apache::loncommon::upfile_record_sep();
1.257 albertel 4764: if ($env{'form.noFirstLine'}) { shift(@gradedata); }
1.246 albertel 4765: my %fields=&get_fields();
1.41 ng 4766: $request->print('<h3>Assigning Grades</h3>');
1.257 albertel 4767: my $courseid=$env{'request.course.id'};
1.97 albertel 4768: my ($classlist) = &getclasslist('all',0);
1.106 albertel 4769: my @notallowed;
1.41 ng 4770: my @skipped;
1.596.2.4 raeburn 4771: my @warnings;
1.41 ng 4772: my $countdone=0;
4773: foreach my $grade (@gradedata) {
4774: my %entries=&Apache::loncommon::record_sep($grade);
1.246 albertel 4775: my $domain;
4776: if ($entries{$fields{'domain'}}) {
4777: $domain=$entries{$fields{'domain'}};
4778: } else {
1.257 albertel 4779: $domain=$env{'form.default_domain'};
1.246 albertel 4780: }
1.243 albertel 4781: $domain=~s/\s//g;
1.41 ng 4782: my $username=$entries{$fields{'username'}};
1.160 albertel 4783: $username=~s/\s//g;
1.243 albertel 4784: if (!$username) {
4785: my $id=$entries{$fields{'ID'}};
1.247 albertel 4786: $id=~s/\s//g;
1.243 albertel 4787: my %ids=&Apache::lonnet::idget($domain,$id);
4788: $username=$ids{$id};
4789: }
1.41 ng 4790: if (!exists($$classlist{"$username:$domain"})) {
1.247 albertel 4791: my $id=$entries{$fields{'ID'}};
4792: $id=~s/\s//g;
4793: if ($id) {
4794: push(@skipped,"$id:$domain");
4795: } else {
4796: push(@skipped,"$username:$domain");
4797: }
1.41 ng 4798: next;
4799: }
1.108 albertel 4800: my $usec=$classlist->{"$username:$domain"}[5];
1.106 albertel 4801: if (!&canmodify($usec)) {
4802: push(@notallowed,"$username:$domain");
4803: next;
4804: }
1.244 albertel 4805: my %points;
1.41 ng 4806: my %grades;
4807: foreach my $dest (keys(%fields)) {
1.244 albertel 4808: if ($dest eq 'ID' || $dest eq 'username' ||
4809: $dest eq 'domain') { next; }
4810: if ($entries{$fields{$dest}} =~ /^\s*$/) { next; }
4811: if ($dest=~/stores_(.*)_points/) {
4812: my $part=$1;
4813: my $wgt =&Apache::lonnet::EXT('resource.'.$part.'.weight',
4814: $symb,$domain,$username);
1.345 bowersj2 4815: if ($wgt) {
4816: $entries{$fields{$dest}}=~s/\s//g;
4817: my $pcr=$entries{$fields{$dest}} / $wgt;
1.463 albertel 4818: my $award=($pcr == 0) ? 'incorrect_by_override'
4819: : 'correct_by_override';
1.596.2.4 raeburn 4820: if ($pcr>1) {
4821: push(@warnings,&mt("[_1]: point value larger than weight","$username:$domain"));
4822: }
1.345 bowersj2 4823: $grades{"resource.$part.awarded"}=$pcr;
4824: $grades{"resource.$part.solved"}=$award;
4825: $points{$part}=1;
4826: } else {
4827: $error_msg = "<br />" .
4828: &mt("Some point values were assigned"
4829: ." for problems with a weight "
4830: ."of zero. These values were "
4831: ."ignored.");
4832: }
1.244 albertel 4833: } else {
4834: if ($dest=~/stores_(.*)_awarded/) { if ($points{$1}) {next;} }
4835: if ($dest=~/stores_(.*)_solved/) { if ($points{$1}) {next;} }
4836: my $store_key=$dest;
4837: $store_key=~s/^stores/resource/;
4838: $store_key=~s/_/\./g;
4839: $grades{$store_key}=$entries{$fields{$dest}};
4840: }
1.41 ng 4841: }
1.508 www 4842: if (! %grades) {
4843: push(@skipped,&mt("[_1]: no data to save","$username:$domain"));
4844: } else {
4845: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
4846: my $result=&Apache::lonnet::cstore(\%grades,$symb,
1.302 albertel 4847: $env{'request.course.id'},
4848: $domain,$username);
1.508 www 4849: if ($result eq 'ok') {
4850: $request->print('.');
1.596.2.4 raeburn 4851: # Remove from grading queue
4852: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,
4853: $env{'course.'.$env{'request.course.id'}.'.domain'},
4854: $env{'course.'.$env{'request.course.id'}.'.num'},
4855: $domain,$username);
1.508 www 4856: } else {
4857: $request->print("<p><span class=\"LC_error\">".
4858: &mt("Failed to save data for student [_1]. Message when trying to save was: [_2]",
4859: "$username:$domain",$result)."</span></p>");
4860: }
4861: $request->rflush();
4862: $countdone++;
4863: }
1.41 ng 4864: }
1.570 www 4865: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt("Saved scores for [quant,_1,student]",$countdone),$countdone==0));
1.596.2.4 raeburn 4866: if (@warnings) {
4867: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('Warnings generated for the following saved scores:'),1).'<br />');
4868: $request->print(join(', ',@warnings));
4869: }
1.41 ng 4870: if (@skipped) {
1.571 www 4871: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('No scores stored for the following username(s):'),1).'<br />');
4872: $request->print(join(', ',@skipped));
1.106 albertel 4873: }
4874: if (@notallowed) {
1.571 www 4875: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('Modification of scores not allowed for the following username(s):'),1).'<br />');
4876: $request->print(join(', ',@notallowed));
1.41 ng 4877: }
1.106 albertel 4878: $request->print("<br />\n");
1.324 albertel 4879: $request->print(&show_grading_menu_form($symb));
1.345 bowersj2 4880: return $error_msg;
1.26 albertel 4881: }
1.44 ng 4882: #------------- end of section for handling csv file upload ---------
4883: #
4884: #-------------------------------------------------------------------
4885: #
1.122 ng 4886: #-------------- Next few routines handle grading by page/sequence
1.72 ng 4887: #
4888: #--- Select a page/sequence and a student to grade
1.68 ng 4889: sub pickStudentPage {
4890: my ($request) = shift;
4891:
1.539 riegler 4892: my $alertmsg = &mt('Please select the student you wish to grade.');
1.596.2.12.2. 6(raebur 4893:6): &js_escape(\$alertmsg);
1.68 ng 4894: $request->print(<<LISTJAVASCRIPT);
4895: <script type="text/javascript" language="javascript">
4896:
4897: function checkPickOne(formname) {
1.76 ng 4898: if (radioSelection(formname.student) == null) {
1.539 riegler 4899: alert("$alertmsg");
1.68 ng 4900: return;
4901: }
1.125 ng 4902: ptr = pullDownSelection(formname.selectpage);
4903: formname.page.value = formname["page"+ptr].value;
4904: formname.title.value = formname["title"+ptr].value;
1.68 ng 4905: formname.submit();
4906: }
4907:
4908: </script>
4909: LISTJAVASCRIPT
1.118 ng 4910: &commonJSfunctions($request);
1.324 albertel 4911: my ($symb) = &get_symb($request);
1.257 albertel 4912: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4913: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4914: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.596.2.12.2. 8(raebur 4915:9): my $getgroup = $env{'form.group'} eq '' ? 'all' : $env{'form.group'};
1.68 ng 4916:
1.398 albertel 4917: my $result='<h3><span class="LC_info"> '.
1.485 albertel 4918: &mt('Manual Grading by Page or Sequence').'</span></h3>';
1.68 ng 4919:
1.80 ng 4920: $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
1.582 raeburn 4921: my $map_error;
4922: my ($titles,$symbx) = &getSymbMap($map_error);
4923: if ($map_error) {
4924: $request->print(&navmap_errormsg());
4925: return;
4926: }
1.137 albertel 4927: my ($curpage) =&Apache::lonnet::decode_symb($symb);
4928: # my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb);
4929: # my $type=($curpage =~ /\.(page|sequence)/);
1.485 albertel 4930: my $select = '<select name="selectpage">'."\n";
1.70 ng 4931: my $ctr=0;
1.68 ng 4932: foreach (@$titles) {
4933: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.485 albertel 4934: $select.='<option value="'.$ctr.'" '.
1.401 albertel 4935: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.71 ng 4936: '>'.$showtitle.'</option>'."\n";
1.70 ng 4937: $ctr++;
1.68 ng 4938: }
1.485 albertel 4939: $select.= '</select>';
1.539 riegler 4940: $result.=' <b>'.&mt('Problems from').':</b> '.$select."<br />\n";
1.485 albertel 4941:
1.70 ng 4942: $ctr=0;
4943: foreach (@$titles) {
4944: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
4945: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
4946: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
4947: $ctr++;
4948: }
1.72 ng 4949: $result.='<input type="hidden" name="page" />'."\n".
4950: '<input type="hidden" name="title" />'."\n";
1.68 ng 4951:
1.485 albertel 4952: my $options =
4953: '<label><input type="radio" name="vProb" value="no" checked="checked" /> '.&mt('no').' </label>'."\n".
4954: '<label><input type="radio" name="vProb" value="yes" /> '.&mt('yes').' </label>'."<br />\n";
1.539 riegler 4955: $result.=' <b>'.&mt('View Problem Text').': </b>'.$options;
1.485 albertel 4956:
4957: $options =
4958: '<label><input type="radio" name="lastSub" value="none" /> '.&mt('none').' </label>'."\n".
4959: '<label><input type="radio" name="lastSub" value="datesub" checked="checked" /> '.&mt('by dates and submissions').'</label>'."\n".
4960: '<label><input type="radio" name="lastSub" value="all" /> '.&mt('all details').' </label>'."\n";
1.539 riegler 4961: $result.=' <b>'.&mt('Submissions').': </b>'.$options;
1.432 banghart 4962:
4963: $result.=&build_section_inputs();
1.442 banghart 4964: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
4965: $result.='<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.72 ng 4966: '<input type="hidden" name="command" value="displayPage" />'."\n".
1.418 albertel 4967: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 4968: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."<br />\n";
1.72 ng 4969:
1.539 riegler 4970: $result.=' <b>'.&mt('Use CODE').': </b> <input type="text" name="CODE" value="" /> <br />'."\n";
1.382 albertel 4971:
1.80 ng 4972: $result.=' <input type="button" '.
1.589 bisitz 4973: 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /><br />'."\n";
1.72 ng 4974:
1.68 ng 4975: $request->print($result);
4976:
1.485 albertel 4977: my $studentTable.=' <b>'.&mt('Select a student you wish to grade and then click on the Next button.').'</b><br />'.
1.484 albertel 4978: &Apache::loncommon::start_data_table().
4979: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 4980: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 4981: '<th>'.&nameUserString('header').'</th>'.
1.485 albertel 4982: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 4983: '<th>'.&nameUserString('header').'</th>'.
4984: &Apache::loncommon::end_data_table_header_row();
1.68 ng 4985:
1.596.2.12.2. 8(raebur 4986:9): my (undef,undef,$fullname) = &getclasslist($getsec,'1',$getgroup);
1.68 ng 4987: my $ptr = 1;
1.294 albertel 4988: foreach my $student (sort
4989: {
4990: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
4991: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
4992: }
4993: return $a cmp $b;
4994: } (keys(%$fullname))) {
1.68 ng 4995: my ($uname,$udom) = split(/:/,$student);
1.484 albertel 4996: $studentTable.=($ptr%2==1 ? &Apache::loncommon::start_data_table_row()
4997: : '</td>');
1.126 ng 4998: $studentTable.='<td align="right">'.$ptr.' </td>';
1.288 albertel 4999: $studentTable.='<td> <label><input type="radio" name="student" value="'.$student.'" /> '
5000: .&nameUserString(undef,$$fullname{$student},$uname,$udom)."</label>\n";
1.484 albertel 5001: $studentTable.=
5002: ($ptr%2 == 0 ? '</td>'.&Apache::loncommon::end_data_table_row()
5003: : '');
1.68 ng 5004: $ptr++;
5005: }
1.484 albertel 5006: if ($ptr%2 == 0) {
5007: $studentTable.='</td><td> </td><td> </td>'.
5008: &Apache::loncommon::end_data_table_row();
5009: }
5010: $studentTable.=&Apache::loncommon::end_data_table()."\n";
1.126 ng 5011: $studentTable.='<input type="button" '.
1.589 bisitz 5012: 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /></form>'."\n";
1.68 ng 5013:
1.324 albertel 5014: $studentTable.=&show_grading_menu_form($symb);
1.68 ng 5015: $request->print($studentTable);
5016:
5017: return '';
5018: }
5019:
5020: sub getSymbMap {
1.582 raeburn 5021: my ($map_error) = @_;
1.132 bowersj2 5022: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 5023: unless (ref($navmap)) {
5024: if (ref($map_error)) {
5025: $$map_error = 'navmap';
5026: }
5027: return;
5028: }
1.68 ng 5029: my %symbx = ();
5030: my @titles = ();
1.117 bowersj2 5031: my $minder = 0;
5032:
5033: # Gather every sequence that has problems.
1.240 albertel 5034: my @sequences = $navmap->retrieveResources(undef, sub { shift->is_map(); },
5035: 1,0,1);
1.117 bowersj2 5036: for my $sequence ($navmap->getById('0.0'), @sequences) {
1.241 albertel 5037: if ($navmap->hasResource($sequence, sub { shift->is_problem(); }, 0) ) {
1.381 albertel 5038: my $title = $minder.'.'.
5039: &HTML::Entities::encode($sequence->compTitle(),'"\'&');
5040: push(@titles, $title); # minder in case two titles are identical
5041: $symbx{$title} = &HTML::Entities::encode($sequence->symb(),'"\'&');
1.117 bowersj2 5042: $minder++;
1.241 albertel 5043: }
1.68 ng 5044: }
5045: return \@titles,\%symbx;
5046: }
5047:
1.72 ng 5048: #
5049: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68 ng 5050: sub displayPage {
5051: my ($request) = shift;
5052:
1.324 albertel 5053: my ($symb) = &get_symb($request);
1.257 albertel 5054: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
5055: my $cnum = $env{"course.$env{'request.course.id'}.num"};
5056: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
5057: my $pageTitle = $env{'form.page'};
1.103 albertel 5058: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 5059: my ($uname,$udom) = split(/:/,$env{'form.student'});
5060: my $usec=$classlist->{$env{'form.student'}}[5];
1.168 albertel 5061:
5062: #need to make sure we have the correct data for later EXT calls,
5063: #thus invalidate the cache
5064: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 5065: $env{'course.'.$env{'request.course.id'}.'.num'},
5066: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 5067: &Apache::lonnet::clear_EXT_cache_status();
5068:
1.103 albertel 5069: if (!&canview($usec)) {
1.596.2.12.2. 8(raebur 5070:4): $request->print('<span class="LC_warning">'.
5071:4): &mt('Unable to view requested student. ([_1])',
5072:4): $env{'form.student'}).
5073:4): '</span>');
5074:4): $request->print(&show_grading_menu_form($symb));
5075:4): return;
1.103 albertel 5076: }
1.398 albertel 5077: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.485 albertel 5078: $result.='<h3> '.&mt('Student: [_1]',&nameUserString(undef,$$fullname{$env{'form.student'}},$uname,$udom)).
1.129 ng 5079: '</h3>'."\n";
1.500 albertel 5080: $env{'form.CODE'} = uc($env{'form.CODE'});
1.501 foxr 5081: if (&Apache::lonnet::validCODE(uc($env{'form.CODE'}))) {
1.485 albertel 5082: $result.='<h3> '.&mt('CODE: [_1]',$env{'form.CODE'}).'</h3>'."\n";
1.382 albertel 5083: } else {
5084: delete($env{'form.CODE'});
5085: }
1.71 ng 5086: &sub_page_js($request);
5087: $request->print($result);
5088:
1.132 bowersj2 5089: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 5090: unless (ref($navmap)) {
5091: $request->print(&navmap_errormsg());
5092: $request->print(&show_grading_menu_form($symb));
5093: return;
5094: }
1.257 albertel 5095: my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($env{'form.page'});
1.68 ng 5096: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 5097: if (!$map) {
1.485 albertel 5098: $request->print('<span class="LC_warning">'.&mt('Unable to view requested sequence. ([_1])',$resUrl).'</span>');
1.324 albertel 5099: $request->print(&show_grading_menu_form($symb));
1.288 albertel 5100: return;
5101: }
1.68 ng 5102: my $iterator = $navmap->getIterator($map->map_start(),
5103: $map->map_finish());
5104:
1.71 ng 5105: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72 ng 5106: '<input type="hidden" name="command" value="gradeByPage" />'."\n".
1.257 albertel 5107: '<input type="hidden" name="fullname" value="'.$$fullname{$env{'form.student'}}.'" />'."\n".
5108: '<input type="hidden" name="student" value="'.$env{'form.student'}.'" />'."\n".
1.72 ng 5109: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
1.257 albertel 5110: '<input type="hidden" name="title" value="'.$env{'form.title'}.'" />'."\n".
1.418 albertel 5111: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.125 ng 5112: '<input type="hidden" name="overRideScore" value="no" />'."\n".
1.257 albertel 5113: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n";
1.71 ng 5114:
1.382 albertel 5115: if (defined($env{'form.CODE'})) {
5116: $studentTable.=
5117: '<input type="hidden" name="CODE" value="'.$env{'form.CODE'}.'" />'."\n";
5118: }
1.381 albertel 5119: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 5120: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 5121:
1.594 bisitz 5122: $studentTable.=' <span class="LC_info">'.
5123: &mt('Problems graded correct by the computer are marked with a [_1] symbol.',$checkIcon).
5124: '</span>'."\n".
1.484 albertel 5125: &Apache::loncommon::start_data_table().
5126: &Apache::loncommon::start_data_table_header_row().
5127: '<th align="center"> Prob. </th>'.
1.485 albertel 5128: '<th> '.($env{'form.vProb'} eq 'no' ? &mt('Title') : &mt('Problem Text')).'/'.&mt('Grade').'</th>'.
1.484 albertel 5129: &Apache::loncommon::end_data_table_header_row();
1.71 ng 5130:
1.329 albertel 5131: &Apache::lonxml::clear_problem_counter();
1.196 albertel 5132: my ($depth,$question,$prob) = (1,1,1);
1.68 ng 5133: $iterator->next(); # skip the first BEGIN_MAP
5134: my $curRes = $iterator->next(); # for "current resource"
1.101 albertel 5135: while ($depth > 0) {
1.68 ng 5136: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 5137: if($curRes == $iterator->END_MAP) { $depth--; }
1.68 ng 5138:
1.385 albertel 5139: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 5140: my $parts = $curRes->parts();
1.68 ng 5141: my $title = $curRes->compTitle();
1.71 ng 5142: my $symbx = $curRes->symb();
1.484 albertel 5143: $studentTable.=
5144: &Apache::loncommon::start_data_table_row().
5145: '<td align="center" valign="top" >'.$prob.
1.485 albertel 5146: (scalar(@{$parts}) == 1 ? ''
1.596.2.12.2. 2(raebur 5147:2): : '<br />('.&mt('[_1]parts',
5148:2): scalar(@{$parts}).' ').')'
1.485 albertel 5149: ).
5150: '</td>';
1.71 ng 5151: $studentTable.='<td valign="top">';
1.382 albertel 5152: my %form = ('CODE' => $env{'form.CODE'},);
1.257 albertel 5153: if ($env{'form.vProb'} eq 'yes' ) {
1.144 albertel 5154: $studentTable.=&show_problem($request,$symbx,$uname,$udom,1,
1.383 albertel 5155: undef,'both',\%form);
1.71 ng 5156: } else {
1.382 albertel 5157: my $companswer = &Apache::loncommon::get_student_answers($symbx,$uname,$udom,$env{'request.course.id'},%form);
1.80 ng 5158: $companswer =~ s|<form(.*?)>||g;
5159: $companswer =~ s|</form>||g;
1.71 ng 5160: # while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
1.116 ng 5161: # $companswer =~ s/$1/ /ms;
1.326 albertel 5162: # $request->print('match='.$1."<br />\n");
1.71 ng 5163: # }
1.116 ng 5164: # $companswer =~ s|<table border=\"1\">|<table border=\"0\">|g;
1.539 riegler 5165: $studentTable.=' <b>'.$title.'</b> <br /> <b>'.&mt('Correct answer').':</b><br />'.$companswer;
1.71 ng 5166: }
5167:
1.257 albertel 5168: my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
1.125 ng 5169:
1.257 albertel 5170: if ($env{'form.lastSub'} eq 'datesub') {
1.71 ng 5171: if ($record{'version'} eq '') {
1.485 albertel 5172: $studentTable.='<br /> <span class="LC_warning">'.&mt('No recorded submission for this problem.').'</span><br />';
1.71 ng 5173: } else {
1.116 ng 5174: my %responseType = ();
5175: foreach my $partid (@{$parts}) {
1.147 albertel 5176: my @responseIds =$curRes->responseIds($partid);
5177: my @responseType =$curRes->responseType($partid);
5178: my %responseIds;
5179: for (my $i=0;$i<=$#responseIds;$i++) {
5180: $responseIds{$responseIds[$i]}=$responseType[$i];
5181: }
5182: $responseType{$partid} = \%responseIds;
1.116 ng 5183: }
1.148 albertel 5184: $studentTable.= &displaySubByDates($symbx,\%record,$parts,\%responseType,$checkIcon,$uname,$udom);
1.147 albertel 5185:
1.71 ng 5186: }
1.257 albertel 5187: } elsif ($env{'form.lastSub'} eq 'all') {
5188: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.596.2.12.2. 1(raebur 5189:5): my $identifier = (&canmodify($usec)? $prob : '');
1.71 ng 5190: $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
1.257 albertel 5191: $env{'request.course.id'},
1.596.2.12.2. 1(raebur 5192:5): '','.submission',undef,
5193:5): $usec,$identifier);
1.71 ng 5194:
5195: }
1.103 albertel 5196: if (&canmodify($usec)) {
1.585 bisitz 5197: $studentTable.=&gradeBox_start();
1.103 albertel 5198: foreach my $partid (@{$parts}) {
5199: $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
5200: $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
5201: $question++;
5202: }
1.585 bisitz 5203: $studentTable.=&gradeBox_end();
1.196 albertel 5204: $prob++;
1.71 ng 5205: }
5206: $studentTable.='</td></tr>';
1.68 ng 5207:
1.103 albertel 5208: }
1.68 ng 5209: $curRes = $iterator->next();
5210: }
5211:
1.589 bisitz 5212: $studentTable.=
5213: '</table>'."\n".
5214: '<input type="button" value="'.&mt('Save').'" '.
5215: 'onclick="javascript:checkSubmitPage(this.form,'.$question.');" />'.
5216: '</form>'."\n";
1.324 albertel 5217: $studentTable.=&show_grading_menu_form($symb);
1.71 ng 5218: $request->print($studentTable);
5219:
5220: return '';
1.119 ng 5221: }
5222:
5223: sub displaySubByDates {
1.148 albertel 5224: my ($symb,$record,$parts,$responseType,$checkIcon,$uname,$udom) = @_;
1.224 albertel 5225: my $isCODE=0;
1.335 albertel 5226: my $isTask = ($symb =~/\.task$/);
1.224 albertel 5227: if (exists($record->{'resource.CODE'})) { $isCODE=1; }
1.467 albertel 5228: my $studentTable=&Apache::loncommon::start_data_table().
5229: &Apache::loncommon::start_data_table_header_row().
5230: '<th>'.&mt('Date/Time').'</th>'.
5231: ($isCODE?'<th>'.&mt('CODE').'</th>':'').
1.596.2.12.2. (raeburn 5232:): ($isTask?'<th>'.&mt('Version').'</th>':'').
1.467 albertel 5233: '<th>'.&mt('Submission').'</th>'.
5234: '<th>'.&mt('Status').'</th>'.
5235: &Apache::loncommon::end_data_table_header_row();
1.119 ng 5236: my ($version);
5237: my %mark;
1.148 albertel 5238: my %orders;
1.119 ng 5239: $mark{'correct_by_student'} = $checkIcon;
1.147 albertel 5240: if (!exists($$record{'1:timestamp'})) {
1.539 riegler 5241: return '<br /> <span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br />';
1.147 albertel 5242: }
1.335 albertel 5243:
5244: my $interaction;
1.525 raeburn 5245: my $no_increment = 1;
1.596.2.12.2. 5(raebur 5246:5): my (%lastrndseed,%lasttype);
1.119 ng 5247: for ($version=1;$version<=$$record{'version'};$version++) {
1.467 albertel 5248: my $timestamp =
5249: &Apache::lonlocal::locallocaltime($$record{$version.':timestamp'});
1.335 albertel 5250: if (exists($$record{$version.':resource.0.version'})) {
5251: $interaction = $$record{$version.':resource.0.version'};
5252: }
1.596.2.12.2. (raeburn 5253:): if ($isTask && $env{'form.previousversion'}) {
5254:): next unless ($interaction == $env{'form.previousversion'});
5255:): }
1.335 albertel 5256: my $where = ($isTask ? "$version:resource.$interaction"
5257: : "$version:resource");
1.467 albertel 5258: $studentTable.=&Apache::loncommon::start_data_table_row().
5259: '<td>'.$timestamp.'</td>';
1.224 albertel 5260: if ($isCODE) {
5261: $studentTable.='<td>'.$record->{$version.':resource.CODE'}.'</td>';
5262: }
1.596.2.12.2. (raeburn 5263:): if ($isTask) {
5264:): $studentTable.='<td>'.$interaction.'</td>';
5265:): }
1.119 ng 5266: my @versionKeys = split(/\:/,$$record{$version.':keys'});
5267: my @displaySub = ();
5268: foreach my $partid (@{$parts}) {
1.596.2.2 raeburn 5269: my ($hidden,$type);
5270: $type = $$record{$version.':resource.'.$partid.'.type'};
5271: if (($type eq 'anonsurvey') || ($type eq 'anonsurveycred')) {
1.596 raeburn 5272: $hidden = 1;
5273: }
1.335 albertel 5274: my @matchKey = ($isTask ? sort(grep /^resource\.\d+\.\Q$partid\E\.award$/,@versionKeys)
5275: : sort(grep /^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys));
5276:
1.122 ng 5277: # next if ($$record{"$version:resource.$partid.solved"} eq '');
1.324 albertel 5278: my $display_part=&get_display_part($partid,$symb);
1.147 albertel 5279: foreach my $matchKey (@matchKey) {
1.198 albertel 5280: if (exists($$record{$version.':'.$matchKey}) &&
5281: $$record{$version.':'.$matchKey} ne '') {
1.596 raeburn 5282:
1.335 albertel 5283: my ($responseId)= ($isTask ? ($matchKey=~ /^resource\.(.*?)\.\Q$partid\E\.award$/)
5284: : ($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/));
1.596.2.12.2. (raeburn 5285:): $displaySub[0].='<span class="LC_nobreak">';
1.577 bisitz 5286: $displaySub[0].='<b>'.&mt('Part: [_1]',$display_part).'</b>'
5287: .' <span class="LC_internal_info">'
1.596.2.4 raeburn 5288: .'('.&mt('Response ID: [_1]',$responseId).')'
1.577 bisitz 5289: .'</span>'
5290: .' <b>';
1.596 raeburn 5291: if ($hidden) {
5292: $displaySub[0].= &mt('Anonymous Survey').'</b>';
5293: } else {
1.596.2.2 raeburn 5294: my ($trial,$rndseed,$newvariation);
5295: if ($type eq 'randomizetry') {
5296: $trial = $$record{"$where.$partid.tries"};
5297: $rndseed = $$record{"$where.$partid.rndseed"};
5298: }
1.596 raeburn 5299: if ($$record{"$where.$partid.tries"} eq '') {
5300: $displaySub[0].=&mt('Trial not counted');
5301: } else {
5302: $displaySub[0].=&mt('Trial: [_1]',
1.467 albertel 5303: $$record{"$where.$partid.tries"});
1.596.2.12.2. 4(raebur 5304:5): if (($rndseed ne '') && ($lastrndseed{$partid} ne '')) {
5(raebur 5305:5): if (($rndseed ne $lastrndseed{$partid}) &&
5306:5): (($type eq 'randomizetry') || ($lasttype{$partid} eq 'randomizetry'))) {
1.596.2.2 raeburn 5307: $newvariation = ' ('.&mt('New variation this try').')';
5308: }
5309: }
1.596.2.12.2. 4(raebur 5310:5): $lastrndseed{$partid} = $rndseed;
5(raebur 5311:5): $lasttype{$partid} = $type;
1.596 raeburn 5312: }
5313: my $responseType=($isTask ? 'Task'
1.335 albertel 5314: : $responseType->{$partid}->{$responseId});
1.596 raeburn 5315: if (!exists($orders{$partid})) { $orders{$partid}={}; }
1.596.2.2 raeburn 5316: if ((!exists($orders{$partid}->{$responseId})) || ($trial)) {
1.596 raeburn 5317: $orders{$partid}->{$responseId}=
5318: &get_order($partid,$responseId,$symb,$uname,$udom,
1.596.2.2 raeburn 5319: $no_increment,$type,$trial,$rndseed);
1.596 raeburn 5320: }
1.596.2.2 raeburn 5321: $displaySub[0].='</b>'.$newvariation.'</span>'; # /nobreak
1.596 raeburn 5322: $displaySub[0].=' '.
1.596.2.2 raeburn 5323: &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:",$uname,$udom,$type,$trial,$rndseed).'<br />';
1.596 raeburn 5324: }
1.147 albertel 5325: }
5326: }
1.335 albertel 5327: if (exists($$record{"$where.$partid.checkedin"})) {
1.485 albertel 5328: $displaySub[1].=&mt('Checked in by [_1] into slot [_2]',
5329: $$record{"$where.$partid.checkedin"},
5330: $$record{"$where.$partid.checkedin.slot"}).
5331: '<br />';
1.335 albertel 5332: }
5333: if (exists $$record{"$where.$partid.award"}) {
1.485 albertel 5334: $displaySub[1].='<b>'.&mt('Part:').'</b> '.$display_part.' '.
1.335 albertel 5335: lc($$record{"$where.$partid.award"}).' '.
5336: $mark{$$record{"$where.$partid.solved"}}.
1.147 albertel 5337: '<br />';
5338: }
1.335 albertel 5339: if (exists $$record{"$where.$partid.regrader"}) {
5340: $displaySub[2].=$$record{"$where.$partid.regrader"}.
5341: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
5342: } elsif ($$record{"$version:resource.$partid.regrader"} =~ /\S/) {
5343: $displaySub[2].=
5344: $$record{"$version:resource.$partid.regrader"}.
1.207 albertel 5345: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
1.147 albertel 5346: }
5347: }
5348: # needed because old essay regrader has not parts info
5349: if (exists $$record{"$version:resource.regrader"}) {
5350: $displaySub[2].=$$record{"$version:resource.regrader"};
5351: }
5352: $studentTable.='<td>'.$displaySub[0].' </td><td>'.$displaySub[1];
5353: if ($displaySub[2]) {
1.467 albertel 5354: $studentTable.=&mt('Manually graded by [_1]',$displaySub[2]);
1.147 albertel 5355: }
1.467 albertel 5356: $studentTable.=' </td>'.
5357: &Apache::loncommon::end_data_table_row();
1.119 ng 5358: }
1.467 albertel 5359: $studentTable.=&Apache::loncommon::end_data_table();
1.119 ng 5360: return $studentTable;
1.71 ng 5361: }
5362:
5363: sub updateGradeByPage {
5364: my ($request) = shift;
5365:
1.257 albertel 5366: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
5367: my $cnum = $env{"course.$env{'request.course.id'}.num"};
5368: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
5369: my $pageTitle = $env{'form.page'};
1.103 albertel 5370: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 5371: my ($uname,$udom) = split(/:/,$env{'form.student'});
5372: my $usec=$classlist->{$env{'form.student'}}[5];
1.103 albertel 5373: if (!&canmodify($usec)) {
1.526 raeburn 5374: $request->print('<span class="LC_warning">'.&mt('Unable to modify requested student ([_1])',$env{'form.student'}).'</span>');
1.324 albertel 5375: $request->print(&show_grading_menu_form($env{'form.symb'}));
1.103 albertel 5376: return;
5377: }
1.398 albertel 5378: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.526 raeburn 5379: $result.='<h3> '.&mt('Student: ').&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
1.129 ng 5380: '</h3>'."\n";
1.70 ng 5381:
1.68 ng 5382: $request->print($result);
5383:
1.582 raeburn 5384:
1.132 bowersj2 5385: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 5386: unless (ref($navmap)) {
5387: $request->print(&navmap_errormsg());
5388: return;
5389: }
1.257 albertel 5390: my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $env{'form.page'});
1.71 ng 5391: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 5392: if (!$map) {
1.527 raeburn 5393: $request->print('<span class="LC_warning">'.&mt('Unable to grade requested sequence ([_1]).',$resUrl).'</span>');
1.324 albertel 5394: my ($symb)=&get_symb($request);
5395: $request->print(&show_grading_menu_form($symb));
1.288 albertel 5396: return;
5397: }
1.71 ng 5398: my $iterator = $navmap->getIterator($map->map_start(),
5399: $map->map_finish());
1.70 ng 5400:
1.484 albertel 5401: my $studentTable=
5402: &Apache::loncommon::start_data_table().
5403: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 5404: '<th align="center"> '.&mt('Prob.').' </th>'.
5405: '<th> '.&mt('Title').' </th>'.
5406: '<th> '.&mt('Previous Score').' </th>'.
5407: '<th> '.&mt('New Score').' </th>'.
1.484 albertel 5408: &Apache::loncommon::end_data_table_header_row();
1.71 ng 5409:
5410: $iterator->next(); # skip the first BEGIN_MAP
5411: my $curRes = $iterator->next(); # for "current resource"
1.596.2.12.2. 1(raebur 5412:5): my ($depth,$question,$prob,$changeflag,$hideflag)= (1,1,1,0,0);
1.101 albertel 5413: while ($depth > 0) {
1.71 ng 5414: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 5415: if($curRes == $iterator->END_MAP) { $depth--; }
1.71 ng 5416:
1.385 albertel 5417: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 5418: my $parts = $curRes->parts();
1.71 ng 5419: my $title = $curRes->compTitle();
5420: my $symbx = $curRes->symb();
1.484 albertel 5421: $studentTable.=
5422: &Apache::loncommon::start_data_table_row().
5423: '<td align="center" valign="top" >'.$prob.
1.485 albertel 5424: (scalar(@{$parts}) == 1 ? ''
1.596.2.2 raeburn 5425: : '<br />('.&mt('[quant,_1,part]',scalar(@{$parts}))
1.526 raeburn 5426: .')').'</td>';
1.71 ng 5427: $studentTable.='<td valign="top"> <b>'.$title.'</b> </td>';
5428:
5429: my %newrecord=();
5430: my @displayPts=();
1.269 raeburn 5431: my %aggregate = ();
5432: my $aggregateflag = 0;
1.596.2.12.2. 1(raebur 5433:5): if ($env{'form.HIDE'.$prob}) {
5434:5): my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
5435:5): my ($version,$parts) = split(/:/,$env{'form.HIDE'.$prob},2);
5436:5): my $numchgs = &makehidden($version,$parts,\%record,$symbx,$udom,$uname,1);
5437:5): $hideflag += $numchgs;
5438:5): }
1.71 ng 5439: foreach my $partid (@{$parts}) {
1.257 albertel 5440: my $newpts = $env{'form.GD_BOX'.$question.'_'.$partid};
5441: my $oldpts = $env{'form.oldpts'.$question.'_'.$partid};
1.71 ng 5442:
1.257 albertel 5443: my $wgt = $env{'form.WGT'.$question.'_'.$partid} != 0 ?
5444: $env{'form.WGT'.$question.'_'.$partid} : 1;
1.71 ng 5445: my $partial = $newpts/$wgt;
5446: my $score;
5447: if ($partial > 0) {
5448: $score = 'correct_by_override';
1.125 ng 5449: } elsif ($newpts ne '') { #empty is taken as 0
1.71 ng 5450: $score = 'incorrect_by_override';
5451: }
1.257 albertel 5452: my $dropMenu = $env{'form.GD_SEL'.$question.'_'.$partid};
1.125 ng 5453: if ($dropMenu eq 'excused') {
1.71 ng 5454: $partial = '';
5455: $score = 'excused';
1.125 ng 5456: } elsif ($dropMenu eq 'reset status'
1.257 albertel 5457: && $env{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
1.125 ng 5458: $newrecord{'resource.'.$partid.'.tries'} = 0;
5459: $newrecord{'resource.'.$partid.'.solved'} = '';
5460: $newrecord{'resource.'.$partid.'.award'} = '';
5461: $newrecord{'resource.'.$partid.'.awarded'} = 0;
1.257 albertel 5462: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 5463: $changeflag++;
5464: $newpts = '';
1.269 raeburn 5465:
5466: my $aggtries = $env{'form.aggtries'.$question.'_'.$partid};
5467: my $totaltries = $env{'form.totaltries'.$question.'_'.$partid};
5468: my $solvedstatus = $env{'form.solved'.$question.'_'.$partid};
5469: if ($aggtries > 0) {
5470: &decrement_aggs($symbx,$partid,\%aggregate,$aggtries,$totaltries,$solvedstatus);
5471: $aggregateflag = 1;
5472: }
1.71 ng 5473: }
1.324 albertel 5474: my $display_part=&get_display_part($partid,$curRes->symb());
1.257 albertel 5475: my $oldstatus = $env{'form.solved'.$question.'_'.$partid};
1.526 raeburn 5476: $displayPts[0].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.71 ng 5477: (($oldstatus eq 'excused') ? 'excused' : $oldpts).
1.326 albertel 5478: ' <br />';
1.526 raeburn 5479: $displayPts[1].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.125 ng 5480: (($score eq 'excused') ? 'excused' : $newpts).
1.326 albertel 5481: ' <br />';
1.71 ng 5482: $question++;
1.380 albertel 5483: next if ($dropMenu eq 'reset status' || ($newpts eq $oldpts && $score ne 'excused'));
1.125 ng 5484:
1.71 ng 5485: $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
1.125 ng 5486: $newrecord{'resource.'.$partid.'.solved'} = $score if $score ne '';
1.257 albertel 5487: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}"
1.125 ng 5488: if (scalar(keys(%newrecord)) > 0);
1.71 ng 5489:
5490: $changeflag++;
5491: }
5492: if (scalar(keys(%newrecord)) > 0) {
1.382 albertel 5493: my %record =
5494: &Apache::lonnet::restore($symbx,$env{'request.course.id'},
5495: $udom,$uname);
5496:
5497: if (&Apache::lonnet::validCODE($env{'form.CODE'})) {
5498: $newrecord{'resource.CODE'} = $env{'form.CODE'};
5499: } elsif (&Apache::lonnet::validCODE($record{'resource.CODE'})) {
5500: $newrecord{'resource.CODE'} = '';
5501: }
1.257 albertel 5502: &Apache::lonnet::cstore(\%newrecord,$symbx,$env{'request.course.id'},
1.71 ng 5503: $udom,$uname);
1.382 albertel 5504: %record = &Apache::lonnet::restore($symbx,
5505: $env{'request.course.id'},
5506: $udom,$uname);
1.380 albertel 5507: &check_and_remove_from_queue($parts,\%record,undef,$symbx,
5508: $cdom,$cnum,$udom,$uname);
1.71 ng 5509: }
1.380 albertel 5510:
1.269 raeburn 5511: if ($aggregateflag) {
5512: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
5513: $env{'course.'.$env{'request.course.id'}.'.domain'},
5514: $env{'course.'.$env{'request.course.id'}.'.num'});
5515: }
1.125 ng 5516:
1.71 ng 5517: $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
5518: '<td valign="top">'.$displayPts[1].'</td>'.
1.484 albertel 5519: &Apache::loncommon::end_data_table_row();
1.68 ng 5520:
1.196 albertel 5521: $prob++;
1.68 ng 5522: }
1.71 ng 5523: $curRes = $iterator->next();
1.68 ng 5524: }
1.98 albertel 5525:
1.484 albertel 5526: $studentTable.=&Apache::loncommon::end_data_table();
1.324 albertel 5527: $studentTable.=&show_grading_menu_form($env{'form.symb'});
1.526 raeburn 5528: my $grademsg=($changeflag == 0 ? &mt('No score was changed or updated.') :
5529: &mt('The scores were changed for [quant,_1,problem].',
1.596.2.12.2. 1(raebur 5530:5): $changeflag).'<br />');
5531:5): my $hidemsg=($hideflag == 0 ? '' :
5532:5): &mt('Submissions were marked "hidden" for [quant,_1,transaction].',
5533:5): $hideflag).'<br />');
5534:5): $request->print($hidemsg.$grademsg.$studentTable);
1.68 ng 5535:
1.70 ng 5536: return '';
5537: }
5538:
1.72 ng 5539: #-------- end of section for handling grading by page/sequence ---------
5540: #
5541: #-------------------------------------------------------------------
5542:
1.581 www 5543: #-------------------- Bubblesheet (Scantron) Grading -------------------
1.75 albertel 5544: #
5545: #------ start of section for handling grading by page/sequence ---------
5546:
1.423 albertel 5547: =pod
5548:
5549: =head1 Bubble sheet grading routines
5550:
1.424 albertel 5551: For this documentation:
5552:
5553: 'scanline' refers to the full line of characters
5554: from the file that we are parsing that represents one entire sheet
5555:
5556: 'bubble line' refers to the data
1.596.2.6 raeburn 5557: representing the line of bubbles that are on the physical bubblesheet
1.424 albertel 5558:
5559:
1.596.2.6 raeburn 5560: The overall process is that a scanned in bubblesheet data is uploaded
1.424 albertel 5561: into a course. When a user wants to grade, they select a
1.596.2.6 raeburn 5562: sequence/folder of resources, a file of bubblesheet info, and pick
1.424 albertel 5563: one of the predefined configurations for what each scanline looks
5564: like.
5565:
5566: Next each scanline is checked for any errors of either 'missing
1.435 foxr 5567: bubbles' (it's an error because it may have been mis-scanned
1.424 albertel 5568: because too light bubbling), 'double bubble' (each bubble line should
1.596.2.12.2. 0(raebur 5569:3): have no more than one letter picked), invalid or duplicated CODE,
1.556 weissno 5570: invalid student/employee ID
1.424 albertel 5571:
5572: If the CODE option is used that determines the randomization of the
1.556 weissno 5573: homework problems, either way the student/employee ID is looked up into a
1.424 albertel 5574: username:domain.
5575:
5576: During the validation phase the instructor can choose to skip scanlines.
5577:
1.596.2.6 raeburn 5578: After the validation phase, there are now 3 bubblesheet files
1.424 albertel 5579:
5580: scantron_original_filename (unmodified original file)
5581: scantron_corrected_filename (file where the corrected information has replaced the original information)
5582: scantron_skipped_filename (contains the exact text of scanlines that where skipped)
5583:
5584: Also there is a separate hash nohist_scantrondata that contains extra
1.596.2.6 raeburn 5585: correction information that isn't representable in the bubblesheet
1.424 albertel 5586: file (see &scantron_getfile() for more information)
5587:
5588: After all scanlines are either valid, marked as valid or skipped, then
5589: foreach line foreach problem in the picked sequence, an ssi request is
5590: made that simulates a user submitting their selected letter(s) against
5591: the homework problem.
1.423 albertel 5592:
5593: =over 4
5594:
5595:
5596:
5597: =item defaultFormData
5598:
5599: Returns html hidden inputs used to hold context/default values.
5600:
5601: Arguments:
5602: $symb - $symb of the current resource
5603:
5604: =cut
1.422 foxr 5605:
1.81 albertel 5606: sub defaultFormData {
1.324 albertel 5607: my ($symb)=@_;
1.447 foxr 5608: return '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 5609: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
5610: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.81 albertel 5611: }
5612:
1.447 foxr 5613:
1.423 albertel 5614: =pod
5615:
5616: =item getSequenceDropDown
5617:
5618: Return html dropdown of possible sequences to grade
5619:
5620: Arguments:
1.582 raeburn 5621: $symb - $symb of the current resource
5622: $map_error - ref to scalar which will container error if
5623: $navmap object is unavailable in &getSymbMap().
1.423 albertel 5624:
5625: =cut
1.422 foxr 5626:
1.75 albertel 5627: sub getSequenceDropDown {
1.582 raeburn 5628: my ($symb,$map_error)=@_;
1.75 albertel 5629: my $result='<select name="selectpage">'."\n";
1.582 raeburn 5630: my ($titles,$symbx) = &getSymbMap($map_error);
5631: if (ref($map_error)) {
5632: return if ($$map_error);
5633: }
1.137 albertel 5634: my ($curpage)=&Apache::lonnet::decode_symb($symb);
1.75 albertel 5635: my $ctr=0;
5636: foreach (@$titles) {
5637: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
5638: $result.='<option value="'.$$symbx{$_}.'" '.
1.401 albertel 5639: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.75 albertel 5640: '>'.$showtitle.'</option>'."\n";
5641: $ctr++;
5642: }
5643: $result.= '</select>';
5644: return $result;
5645: }
5646:
1.495 albertel 5647: my %bubble_lines_per_response; # no. bubble lines for each response.
1.554 raeburn 5648: # key is zero-based index - 0, 1, 2 ...
1.495 albertel 5649:
5650: my %first_bubble_line; # First bubble line no. for each bubble.
5651:
1.509 raeburn 5652: my %subdivided_bubble_lines; # no. bubble lines for optionresponse,
5653: # matchresponse or rankresponse, where
5654: # an individual response can have multiple
5655: # lines
1.503 raeburn 5656:
5657: my %responsetype_per_response; # responsetype for each response
5658:
1.596.2.12.2. 6(raebur 5659:3): my %masterseq_id_responsenum; # src_id (e.g., 12.3_0.11 etc.) for each
5660:3): # numbered response. Needed when randomorder
5661:3): # or randompick are in use. Key is ID, value
5662:3): # is response number.
5663:3):
1.495 albertel 5664: # Save and restore the bubble lines array to the form env.
5665:
5666:
5667: sub save_bubble_lines {
5668: foreach my $line (keys(%bubble_lines_per_response)) {
5669: $env{"form.scantron.bubblelines.$line"} = $bubble_lines_per_response{$line};
5670: $env{"form.scantron.first_bubble_line.$line"} =
5671: $first_bubble_line{$line};
1.503 raeburn 5672: $env{"form.scantron.sub_bubblelines.$line"} =
5673: $subdivided_bubble_lines{$line};
5674: $env{"form.scantron.responsetype.$line"} =
5675: $responsetype_per_response{$line};
1.495 albertel 5676: }
1.596.2.12.2. 6(raebur 5677:3): foreach my $resid (keys(%masterseq_id_responsenum)) {
5678:3): my $line = $masterseq_id_responsenum{$resid};
5679:3): $env{"form.scantron.residpart.$line"} = $resid;
5680:3): }
1.495 albertel 5681: }
5682:
5683:
5684: sub restore_bubble_lines {
5685: my $line = 0;
5686: %bubble_lines_per_response = ();
1.596.2.12.2. 6(raebur 5687:3): %masterseq_id_responsenum = ();
1.495 albertel 5688: while ($env{"form.scantron.bubblelines.$line"}) {
5689: my $value = $env{"form.scantron.bubblelines.$line"};
5690: $bubble_lines_per_response{$line} = $value;
5691: $first_bubble_line{$line} =
5692: $env{"form.scantron.first_bubble_line.$line"};
1.503 raeburn 5693: $subdivided_bubble_lines{$line} =
5694: $env{"form.scantron.sub_bubblelines.$line"};
5695: $responsetype_per_response{$line} =
5696: $env{"form.scantron.responsetype.$line"};
1.596.2.12.2. 6(raebur 5697:3): my $id = $env{"form.scantron.residpart.$line"};
5698:3): $masterseq_id_responsenum{$id} = $line;
1.495 albertel 5699: $line++;
5700: }
5701: }
5702:
1.423 albertel 5703: =pod
5704:
5705: =item scantron_filenames
5706:
5707: Returns a list of the scantron files in the current course
5708:
5709: =cut
1.422 foxr 5710:
1.202 albertel 5711: sub scantron_filenames {
1.257 albertel 5712: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5713: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
1.517 raeburn 5714: my $getpropath = 1;
1.596.2.12.2. (raeburn 5715:): my ($dirlist,$listerror) = &Apache::lonnet::dirlist('userfiles',$cdom,
5716:): $cname,$getpropath);
1.202 albertel 5717: my @possiblenames;
1.596.2.12.2. (raeburn 5718:): if (ref($dirlist) eq 'ARRAY') {
5719:): foreach my $filename (sort(@{$dirlist})) {
5720:): ($filename)=split(/&/,$filename);
5721:): if ($filename!~/^scantron_orig_/) { next ; }
5722:): $filename=~s/^scantron_orig_//;
5723:): push(@possiblenames,$filename);
5724:): }
1.202 albertel 5725: }
5726: return @possiblenames;
5727: }
5728:
1.423 albertel 5729: =pod
5730:
5731: =item scantron_uploads
5732:
5733: Returns html drop-down list of scantron files in current course.
5734:
5735: Arguments:
5736: $file2grade - filename to set as selected in the dropdown
5737:
5738: =cut
1.422 foxr 5739:
1.202 albertel 5740: sub scantron_uploads {
1.209 ng 5741: my ($file2grade) = @_;
1.202 albertel 5742: my $result= '<select name="scantron_selectfile">';
5743: $result.="<option></option>";
5744: foreach my $filename (sort(&scantron_filenames())) {
1.401 albertel 5745: $result.="<option".($filename eq $file2grade ? ' selected="selected"':'').">$filename</option>\n";
1.81 albertel 5746: }
5747: $result.="</select>";
5748: return $result;
5749: }
5750:
1.423 albertel 5751: =pod
5752:
5753: =item scantron_scantab
5754:
5755: Returns html drop down of the scantron formats in the scantronformat.tab
5756: file.
5757:
5758: =cut
1.422 foxr 5759:
1.82 albertel 5760: sub scantron_scantab {
5761: my $result='<select name="scantron_format">'."\n";
1.191 albertel 5762: $result.='<option></option>'."\n";
1.518 raeburn 5763: my @lines = &get_scantronformat_file();
5764: if (@lines > 0) {
5765: foreach my $line (@lines) {
5766: next if (($line =~ /^\#/) || ($line eq ''));
5767: my ($name,$descrip)=split(/:/,$line);
5768: $result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
5769: }
1.82 albertel 5770: }
5771: $result.='</select>'."\n";
1.518 raeburn 5772: return $result;
5773: }
5774:
5775: =pod
5776:
5777: =item get_scantronformat_file
5778:
5779: Returns an array containing lines from the scantron format file for
5780: the domain of the course.
5781:
5782: If a url for a custom.tab file is listed in domain's configuration.db,
5783: lines are from this file.
5784:
5785: Otherwise, if a default.tab has been published in RES space by the
5786: domainconfig user, lines are from this file.
5787:
5788: Otherwise, fall back to getting lines from the legacy file on the
1.519 raeburn 5789: local server: /home/httpd/lonTabs/default_scantronformat.tab
1.82 albertel 5790:
1.518 raeburn 5791: =cut
5792:
5793: sub get_scantronformat_file {
5794: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
5795: my %domconfig = &Apache::lonnet::get_dom('configuration',['scantron'],$cdom);
5796: my $gottab = 0;
5797: my @lines;
5798: if (ref($domconfig{'scantron'}) eq 'HASH') {
5799: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
5800: my $formatfile = &Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.$domconfig{'scantron'}{'scantronformat'});
5801: if ($formatfile ne '-1') {
5802: @lines = split("\n",$formatfile,-1);
5803: $gottab = 1;
5804: }
5805: }
5806: }
5807: if (!$gottab) {
5808: my $confname = $cdom.'-domainconfig';
5809: my $default = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res/'.$cdom.'/'.$confname.'/default.tab';
5810: my $formatfile = &Apache::lonnet::getfile($default);
5811: if ($formatfile ne '-1') {
5812: @lines = split("\n",$formatfile,-1);
5813: $gottab = 1;
5814: }
5815: }
5816: if (!$gottab) {
1.519 raeburn 5817: my @domains = &Apache::lonnet::current_machine_domains();
5818: if (grep(/^\Q$cdom\E$/,@domains)) {
5819: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
5820: @lines = <$fh>;
5821: close($fh);
5822: } else {
5823: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab');
5824: @lines = <$fh>;
5825: close($fh);
5826: }
1.518 raeburn 5827: }
5828: return @lines;
1.82 albertel 5829: }
5830:
1.423 albertel 5831: =pod
5832:
5833: =item scantron_CODElist
5834:
5835: Returns html drop down of the saved CODE lists from current course,
5836: generated from earlier printings.
5837:
5838: =cut
1.422 foxr 5839:
1.186 albertel 5840: sub scantron_CODElist {
1.257 albertel 5841: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5842: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.186 albertel 5843: my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
5844: my $namechoice='<option></option>';
1.225 albertel 5845: foreach my $name (sort {uc($a) cmp uc($b)} @names) {
1.191 albertel 5846: if ($name =~ /^error: 2 /) { next; }
1.278 albertel 5847: if ($name =~ /^type\0/) { next; }
1.186 albertel 5848: $namechoice.='<option value="'.$name.'">'.$name.'</option>';
5849: }
5850: $namechoice='<select name="scantron_CODElist">'.$namechoice.'</select>';
5851: return $namechoice;
5852: }
5853:
1.423 albertel 5854: =pod
5855:
5856: =item scantron_CODEunique
5857:
5858: Returns the html for "Each CODE to be used once" radio.
5859:
5860: =cut
1.422 foxr 5861:
1.186 albertel 5862: sub scantron_CODEunique {
1.532 bisitz 5863: my $result='<span class="LC_nobreak">
1.272 albertel 5864: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 5865: value="yes" checked="checked" />'.&mt('Yes').' </label>
1.381 albertel 5866: </span>
1.532 bisitz 5867: <span class="LC_nobreak">
1.272 albertel 5868: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 5869: value="no" />'.&mt('No').' </label>
1.381 albertel 5870: </span>';
1.186 albertel 5871: return $result;
5872: }
1.423 albertel 5873:
5874: =pod
5875:
5876: =item scantron_selectphase
5877:
1.596.2.6 raeburn 5878: Generates the initial screen to start the bubblesheet process.
1.423 albertel 5879: Allows for - starting a grading run.
1.424 albertel 5880: - downloading existing scan data (original, corrected
1.423 albertel 5881: or skipped info)
5882:
5883: - uploading new scan data
5884:
5885: Arguments:
5886: $r - The Apache request object
5887: $file2grade - name of the file that contain the scanned data to score
5888:
5889: =cut
1.186 albertel 5890:
1.75 albertel 5891: sub scantron_selectphase {
1.209 ng 5892: my ($r,$file2grade) = @_;
1.324 albertel 5893: my ($symb)=&get_symb($r);
1.75 albertel 5894: if (!$symb) {return '';}
1.582 raeburn 5895: my $map_error;
5896: my $sequence_selector=&getSequenceDropDown($symb,\$map_error);
5897: if ($map_error) {
5898: $r->print('<br />'.&navmap_errormsg().'<br />');
5899: return;
5900: }
1.324 albertel 5901: my $default_form_data=&defaultFormData($symb);
5902: my $grading_menu_button=&show_grading_menu_form($symb);
1.209 ng 5903: my $file_selector=&scantron_uploads($file2grade);
1.82 albertel 5904: my $format_selector=&scantron_scantab();
1.186 albertel 5905: my $CODE_selector=&scantron_CODElist();
5906: my $CODE_unique=&scantron_CODEunique();
1.75 albertel 5907: my $result;
1.422 foxr 5908:
1.513 foxr 5909: $ssi_error = 0;
5910:
1.596.2.4 raeburn 5911: if (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) ||
5912: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
5913:
5914: # Chunk of form to prompt for a scantron file upload.
5915:
5916: $r->print('
5917: <br />
5918: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5919: '.&Apache::loncommon::start_data_table_header_row().'
5920: <th>
5921: '.&mt('Specify a bubblesheet data file to upload.').'
5922: </th>
5923: '.&Apache::loncommon::end_data_table_header_row().'
5924: '.&Apache::loncommon::start_data_table_row().'
5925: <td>
5926: ');
5927: my $default_form_data=&defaultFormData(&get_symb($r,1));
5928: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
5929: my $cnum= $env{'course.'.$env{'request.course.id'}.'.num'};
1.596.2.12.2. 6(raebur 5930:6): my $alertmsg = &mt('Please use the browse button to select a file from your local directory.');
5931:6): &js_escape(\$alertmsg);
1.596.2.4 raeburn 5932: $r->print('
5933: <script type="text/javascript" language="javascript">
5934: function checkUpload(formname) {
5935: if (formname.upfile.value == "") {
1.596.2.12.2. 6(raebur 5936:6): alert("'.$alertmsg.'");
1.596.2.4 raeburn 5937: return false;
5938: }
5939: formname.submit();
5940: }
5941: </script>
5942:
5943: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
5944: '.$default_form_data.'
5945: <input name="courseid" type="hidden" value="'.$cnum.'" />
5946: <input name="domainid" type="hidden" value="'.$cdom.'" />
5947: <input name="command" value="scantronupload_save" type="hidden" />
5948: '.&mt('File to upload: [_1]','<input type="file" name="upfile" size="50" />').'
5949: <br />
5950: <input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
5951: </form>
5952: ');
5953:
5954: $r->print('
5955: </td>
5956: '.&Apache::loncommon::end_data_table_row().'
5957: '.&Apache::loncommon::end_data_table().'
5958: ');
5959: }
5960:
1.422 foxr 5961: # Chunk of form to prompt for a file to grade and how:
5962:
1.489 albertel 5963: $result.= '
5964: <br />
5965: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantron_process">
5966: <input type="hidden" name="command" value="scantron_warning" />
5967: '.$default_form_data.'
5968: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5969: '.&Apache::loncommon::start_data_table_header_row().'
5970: <th colspan="2">
1.492 albertel 5971: '.&mt('Specify file and which Folder/Sequence to grade').'
1.489 albertel 5972: </th>
5973: '.&Apache::loncommon::end_data_table_header_row().'
5974: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5975: <td> '.&mt('Sequence to grade:').' </td><td> '.$sequence_selector.' </td>
1.489 albertel 5976: '.&Apache::loncommon::end_data_table_row().'
5977: '.&Apache::loncommon::start_data_table_row().'
1.572 www 5978: <td> '.&mt('Filename of bubblesheet data file:').' </td><td> '.$file_selector.' </td>
1.489 albertel 5979: '.&Apache::loncommon::end_data_table_row().'
5980: '.&Apache::loncommon::start_data_table_row().'
1.572 www 5981: <td> '.&mt('Format of bubblesheet data file:').' </td><td> '.$format_selector.' </td>
1.489 albertel 5982: '.&Apache::loncommon::end_data_table_row().'
5983: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5984: <td> '.&mt('Saved CODEs to validate against:').' </td><td> '.$CODE_selector.' </td>
1.489 albertel 5985: '.&Apache::loncommon::end_data_table_row().'
5986: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5987: <td> '.&mt('Each CODE is only to be used once:').'</td><td> '.$CODE_unique.' </td>
1.489 albertel 5988: '.&Apache::loncommon::end_data_table_row().'
5989: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5990: <td> '.&mt('Options:').' </td>
1.187 albertel 5991: <td>
1.492 albertel 5992: <label><input type="checkbox" name="scantron_options_redo" value="redo_skipped"/> '.&mt('Do only previously skipped records').'</label> <br />
5993: <label><input type="checkbox" name="scantron_options_ignore" value="ignore_corrections"/> '.&mt('Remove all existing corrections').'</label> <br />
5994: <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources when grading').'</label>
1.187 albertel 5995: </td>
1.489 albertel 5996: '.&Apache::loncommon::end_data_table_row().'
5997: '.&Apache::loncommon::start_data_table_row().'
1.174 albertel 5998: <td colspan="2">
1.572 www 5999: <input type="submit" value="'.&mt('Grading: Validate Bubblesheet Records').'" />
1.162 albertel 6000: </td>
1.489 albertel 6001: '.&Apache::loncommon::end_data_table_row().'
6002: '.&Apache::loncommon::end_data_table().'
6003: </form>
6004: ';
1.162 albertel 6005:
6006: $r->print($result);
6007:
1.422 foxr 6008: # Chunk of the form that prompts to view a scoring office file,
6009: # corrected file, skipped records in a file.
6010:
1.489 albertel 6011: $r->print('
6012: <br />
6013: <form action="/adm/grades" name="scantron_download">
6014: '.$default_form_data.'
6015: <input type="hidden" name="command" value="scantron_download" />
6016: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
6017: '.&Apache::loncommon::start_data_table_header_row().'
6018: <th>
1.492 albertel 6019: '.&mt('Download a scoring office file').'
1.489 albertel 6020: </th>
6021: '.&Apache::loncommon::end_data_table_header_row().'
6022: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 6023: <td> '.&mt('Filename of scoring office file: [_1]',$file_selector).'
1.489 albertel 6024: <br />
1.492 albertel 6025: <input type="submit" value="'.&mt('Download: Show List of Associated Files').'" />
1.489 albertel 6026: '.&Apache::loncommon::end_data_table_row().'
6027: '.&Apache::loncommon::end_data_table().'
6028: </form>
6029: <br />
6030: ');
1.162 albertel 6031:
1.457 banghart 6032: &Apache::lonpickcode::code_list($r,2);
1.523 raeburn 6033:
1.596.2.12.2. 8(raebur 6034:3): $r->print('<br /><form method="post" name="checkscantron" action="">'.
1.523 raeburn 6035: $default_form_data."\n".
6036: &Apache::loncommon::start_data_table('LC_scantron_action')."\n".
6037: &Apache::loncommon::start_data_table_header_row()."\n".
6038: '<th colspan="2">
1.572 www 6039: '.&mt('Review bubblesheet data and submissions for a previously graded folder/sequence')."\n".
1.523 raeburn 6040: '</th>'."\n".
6041: &Apache::loncommon::end_data_table_header_row()."\n".
6042: &Apache::loncommon::start_data_table_row()."\n".
6043: '<td> '.&mt('Graded folder/sequence:').' </td>'."\n".
6044: '<td> '.$sequence_selector.' </td>'.
6045: &Apache::loncommon::end_data_table_row()."\n".
6046: &Apache::loncommon::start_data_table_row()."\n".
6047: '<td> '.&mt('Filename of scoring office file:').' </td>'."\n".
6048: '<td> '.$file_selector.' </td>'."\n".
6049: &Apache::loncommon::end_data_table_row()."\n".
6050: &Apache::loncommon::start_data_table_row()."\n".
6051: '<td> '.&mt('Format of data file:').' </td>'."\n".
6052: '<td> '.$format_selector.' </td>'."\n".
6053: &Apache::loncommon::end_data_table_row()."\n".
6054: &Apache::loncommon::start_data_table_row()."\n".
1.557 raeburn 6055: '<td> '.&mt('Options').' </td>'."\n".
6056: '<td> <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources').'</label></td>'.
6057: &Apache::loncommon::end_data_table_row()."\n".
6058: &Apache::loncommon::start_data_table_row()."\n".
1.523 raeburn 6059: '<td colspan="2">'."\n".
6060: '<input type="hidden" name="command" value="checksubmissions" />'."\n".
1.575 www 6061: '<input type="submit" value="'.&mt('Review Bubblesheet Data and Submission Records').'" />'."\n".
1.523 raeburn 6062: '</td>'."\n".
6063: &Apache::loncommon::end_data_table_row()."\n".
6064: &Apache::loncommon::end_data_table()."\n".
6065: '</form><br />');
1.457 banghart 6066: $r->print($grading_menu_button);
1.523 raeburn 6067: return;
1.75 albertel 6068: }
6069:
1.423 albertel 6070: =pod
6071:
6072: =item get_scantron_config
6073:
6074: Parse and return the scantron configuration line selected as a
6075: hash of configuration file fields.
6076:
6077: Arguments:
6078: which - the name of the configuration to parse from the file.
6079:
6080:
6081: Returns:
6082: If the named configuration is not in the file, an empty
6083: hash is returned.
6084: a hash with the fields
6085: name - internal name for the this configuration setup
6086: description - text to display to operator that describes this config
6087: CODElocation - if 0 or the string 'none'
6088: - no CODE exists for this config
6089: if -1 || the string 'letter'
6090: - a CODE exists for this config and is
6091: a string of letters
6092: Unsupported value (but planned for future support)
6093: if a positive integer
6094: - The CODE exists as the first n items from
6095: the question section of the form
6096: if the string 'number'
6097: - The CODE exists for this config and is
6098: a string of numbers
6099: CODEstart - (only matter if a CODE exists) column in the line where
6100: the CODE starts
6101: CODElength - length of the CODE
1.573 bisitz 6102: IDstart - column where the student/employee ID starts
1.556 weissno 6103: IDlength - length of the student/employee ID info
1.423 albertel 6104: Qstart - column where the information from the bubbled
6105: 'questions' start
6106: Qlength - number of columns comprising a single bubble line from
6107: the sheet. (usually either 1 or 10)
1.424 albertel 6108: Qon - either a single character representing the character used
1.423 albertel 6109: to signal a bubble was chosen in the positional setup, or
6110: the string 'letter' if the letter of the chosen bubble is
6111: in the final, or 'number' if a number representing the
6112: chosen bubble is in the file (1->A 0->J)
1.424 albertel 6113: Qoff - the character used to represent that a bubble was
6114: left blank
1.423 albertel 6115: PaperID - if the scanning process generates a unique number for each
6116: sheet scanned the column that this ID number starts in
6117: PaperIDlength - number of columns that comprise the unique ID number
6118: for the sheet of paper
1.424 albertel 6119: FirstName - column that the first name starts in
1.423 albertel 6120: FirstNameLength - number of columns that the first name spans
6121:
6122: LastName - column that the last name starts in
6123: LastNameLength - number of columns that the last name spans
1.596.2.12.2. (raeburn 6124:): BubblesPerRow - number of bubbles available in each row used to
6125:): bubble an answer. (If not specified, 10 assumed).
1.423 albertel 6126:
6127: =cut
1.422 foxr 6128:
1.82 albertel 6129: sub get_scantron_config {
6130: my ($which) = @_;
1.518 raeburn 6131: my @lines = &get_scantronformat_file();
1.82 albertel 6132: my %config;
1.157 albertel 6133: #FIXME probably should move to XML it has already gotten a bit much now
1.518 raeburn 6134: foreach my $line (@lines) {
1.82 albertel 6135: my ($name,$descrip)=split(/:/,$line);
6136: if ($name ne $which ) { next; }
6137: chomp($line);
6138: my @config=split(/:/,$line);
6139: $config{'name'}=$config[0];
6140: $config{'description'}=$config[1];
6141: $config{'CODElocation'}=$config[2];
6142: $config{'CODEstart'}=$config[3];
6143: $config{'CODElength'}=$config[4];
6144: $config{'IDstart'}=$config[5];
6145: $config{'IDlength'}=$config[6];
6146: $config{'Qstart'}=$config[7];
1.497 foxr 6147: $config{'Qlength'}=$config[8];
1.82 albertel 6148: $config{'Qoff'}=$config[9];
6149: $config{'Qon'}=$config[10];
1.157 albertel 6150: $config{'PaperID'}=$config[11];
6151: $config{'PaperIDlength'}=$config[12];
6152: $config{'FirstName'}=$config[13];
6153: $config{'FirstNamelength'}=$config[14];
6154: $config{'LastName'}=$config[15];
6155: $config{'LastNamelength'}=$config[16];
1.596.2.12.2. (raeburn 6156:): $config{'BubblesPerRow'}=$config[17];
1.82 albertel 6157: last;
6158: }
6159: return %config;
6160: }
6161:
1.423 albertel 6162: =pod
6163:
6164: =item username_to_idmap
6165:
1.556 weissno 6166: creates a hash keyed by student/employee ID with values of the corresponding
1.423 albertel 6167: student username:domain.
6168:
6169: Arguments:
6170:
6171: $classlist - reference to the class list hash. This is a hash
6172: keyed by student name:domain whose elements are references
1.424 albertel 6173: to arrays containing various chunks of information
1.423 albertel 6174: about the student. (See loncoursedata for more info).
6175:
6176: Returns
6177: %idmap - the constructed hash
6178:
6179: =cut
6180:
1.82 albertel 6181: sub username_to_idmap {
6182: my ($classlist)= @_;
6183: my %idmap;
6184: foreach my $student (keys(%$classlist)) {
1.596.2.12.2. 3(raebur 6185:5): my $id = $classlist->{$student}->[&Apache::loncoursedata::CL_ID];
6186:5): unless ($id eq '') {
6187:5): if (!exists($idmap{$id})) {
6188:5): $idmap{$id} = $student;
6189:5): } else {
6190:5): my $status = $classlist->{$student}->[&Apache::loncoursedata::CL_STATUS];
6191:5): if ($status eq 'Active') {
6192:5): $idmap{$id} = $student;
6193:5): }
6194:5): }
6195:5): }
1.82 albertel 6196: }
6197: return %idmap;
6198: }
1.423 albertel 6199:
6200: =pod
6201:
1.424 albertel 6202: =item scantron_fixup_scanline
1.423 albertel 6203:
6204: Process a requested correction to a scanline.
6205:
6206: Arguments:
6207: $scantron_config - hash from &get_scantron_config()
6208: $scan_data - hash of correction information
6209: (see &scantron_getfile())
6210: $line - existing scanline
6211: $whichline - line number of the passed in scanline
6212: $field - type of change to process
6213: (either
1.573 bisitz 6214: 'ID' -> correct the student/employee ID
1.423 albertel 6215: 'CODE' -> correct the CODE
6216: 'answer' -> fixup the submitted answers)
6217:
6218: $args - hash of additional info,
6219: - 'ID'
6220: 'newid' -> studentID to use in replacement
1.424 albertel 6221: of existing one
1.423 albertel 6222: - 'CODE'
6223: 'CODE_ignore_dup' - set to true if duplicates
6224: should be ignored.
6225: 'CODE' - is new code or 'use_unfound'
1.424 albertel 6226: if the existing unfound code should
1.423 albertel 6227: be used as is
6228: - 'answer'
6229: 'response' - new answer or 'none' if blank
6230: 'question' - the bubble line to change
1.503 raeburn 6231: 'questionnum' - the question identifier,
6232: may include subquestion.
1.423 albertel 6233:
6234: Returns:
6235: $line - the modified scanline
6236:
6237: Side effects:
6238: $scan_data - may be updated
6239:
6240: =cut
6241:
1.82 albertel 6242:
1.157 albertel 6243: sub scantron_fixup_scanline {
6244: my ($scantron_config,$scan_data,$line,$whichline,$field,$args)=@_;
6245: if ($field eq 'ID') {
6246: if (length($args->{'newid'}) > $$scantron_config{'IDlength'}) {
1.186 albertel 6247: return ($line,1,'New value too large');
1.157 albertel 6248: }
6249: if (length($args->{'newid'}) < $$scantron_config{'IDlength'}) {
6250: $args->{'newid'}=sprintf('%-'.$$scantron_config{'IDlength'}.'s',
6251: $args->{'newid'});
6252: }
6253: substr($line,$$scantron_config{'IDstart'}-1,
6254: $$scantron_config{'IDlength'})=$args->{'newid'};
6255: if ($args->{'newid'}=~/^\s*$/) {
6256: &scan_data($scan_data,"$whichline.user",
6257: $args->{'username'}.':'.$args->{'domain'});
6258: }
1.186 albertel 6259: } elsif ($field eq 'CODE') {
1.192 albertel 6260: if ($args->{'CODE_ignore_dup'}) {
6261: &scan_data($scan_data,"$whichline.CODE_ignore_dup",'1');
6262: }
6263: &scan_data($scan_data,"$whichline.useCODE",'1');
6264: if ($args->{'CODE'} ne 'use_unfound') {
1.191 albertel 6265: if (length($args->{'CODE'}) > $$scantron_config{'CODElength'}) {
6266: return ($line,1,'New CODE value too large');
6267: }
6268: if (length($args->{'CODE'}) < $$scantron_config{'CODElength'}) {
6269: $args->{'CODE'}=sprintf('%-'.$$scantron_config{'CODElength'}.'s',$args->{'CODE'});
6270: }
6271: substr($line,$$scantron_config{'CODEstart'}-1,
6272: $$scantron_config{'CODElength'})=$args->{'CODE'};
1.186 albertel 6273: }
1.157 albertel 6274: } elsif ($field eq 'answer') {
1.497 foxr 6275: my $length=$scantron_config->{'Qlength'};
1.157 albertel 6276: my $off=$scantron_config->{'Qoff'};
6277: my $on=$scantron_config->{'Qon'};
1.497 foxr 6278: my $answer=${off}x$length;
6279: if ($args->{'response'} eq 'none') {
6280: &scan_data($scan_data,
1.503 raeburn 6281: "$whichline.no_bubble.".$args->{'questionnum'},'1');
1.497 foxr 6282: } else {
6283: if ($on eq 'letter') {
6284: my @alphabet=('A'..'Z');
6285: $answer=$alphabet[$args->{'response'}];
6286: } elsif ($on eq 'number') {
6287: $answer=$args->{'response'}+1;
6288: if ($answer == 10) { $answer = '0'; }
1.274 albertel 6289: } else {
1.497 foxr 6290: substr($answer,$args->{'response'},1)=$on;
1.274 albertel 6291: }
1.497 foxr 6292: &scan_data($scan_data,
1.503 raeburn 6293: "$whichline.no_bubble.".$args->{'questionnum'},undef,'1');
1.157 albertel 6294: }
1.497 foxr 6295: my $where=$length*($args->{'question'}-1)+$scantron_config->{'Qstart'};
6296: substr($line,$where-1,$length)=$answer;
1.157 albertel 6297: }
6298: return $line;
6299: }
1.423 albertel 6300:
6301: =pod
6302:
6303: =item scan_data
6304:
6305: Edit or look up an item in the scan_data hash.
6306:
6307: Arguments:
6308: $scan_data - The hash (see scantron_getfile)
6309: $key - shorthand of the key to edit (actual key is
1.424 albertel 6310: scantronfilename_key).
1.423 albertel 6311: $data - New value of the hash entry.
6312: $delete - If true, the entry is removed from the hash.
6313:
6314: Returns:
6315: The new value of the hash table field (undefined if deleted).
6316:
6317: =cut
6318:
6319:
1.157 albertel 6320: sub scan_data {
6321: my ($scan_data,$key,$value,$delete)=@_;
1.257 albertel 6322: my $filename=$env{'form.scantron_selectfile'};
1.157 albertel 6323: if (defined($value)) {
6324: $scan_data->{$filename.'_'.$key} = $value;
6325: }
6326: if ($delete) { delete($scan_data->{$filename.'_'.$key}); }
6327: return $scan_data->{$filename.'_'.$key};
6328: }
1.423 albertel 6329:
1.495 albertel 6330: # ----- These first few routines are general use routines.----
6331:
6332: # Return the number of occurences of a pattern in a string.
6333:
6334: sub occurence_count {
6335: my ($string, $pattern) = @_;
6336:
6337: my @matches = ($string =~ /$pattern/g);
6338:
6339: return scalar(@matches);
6340: }
6341:
6342:
6343: # Take a string known to have digits and convert all the
6344: # digits into letters in the range J,A..I.
6345:
6346: sub digits_to_letters {
6347: my ($input) = @_;
6348:
6349: my @alphabet = ('J', 'A'..'I');
6350:
6351: my @input = split(//, $input);
6352: my $output ='';
6353: for (my $i = 0; $i < scalar(@input); $i++) {
6354: if ($input[$i] =~ /\d/) {
6355: $output .= $alphabet[$input[$i]];
6356: } else {
6357: $output .= $input[$i];
6358: }
6359: }
6360: return $output;
6361: }
6362:
1.423 albertel 6363: =pod
6364:
6365: =item scantron_parse_scanline
6366:
6367: Decodes a scanline from the selected scantron file
6368:
6369: Arguments:
6370: line - The text of the scantron file line to process
6371: whichline - Line number
6372: scantron_config - Hash describing the format of the scantron lines.
6373: scan_data - Hash of extra information about the scanline
6374: (see scantron_getfile for more information)
6375: just_header - True if should not process question answers but only
6376: the stuff to the left of the answers.
1.596.2.12.2. 6(raebur 6377:3): randomorder - True if randomorder in use
6378:3): randompick - True if randompick in use
6379:3): sequence - Exam folder URL
6380:3): master_seq - Ref to array containing symbs in exam folder
6381:3): symb_to_resource - Ref to hash of symbs for resources in exam folder
6382:3): (corresponding values are resource objects)
6383:3): partids_by_symb - Ref to hash of symb -> array ref of partIDs
6384:3): orderedforcode - Ref to hash of arrays. keys are CODEs and values
6385:3): are refs to an array of resource objects, ordered
6386:3): according to order used for CODE, when randomorder
6387:3): and or randompick are in use.
6388:3): respnumlookup - Ref to hash mapping question numbers in bubble lines
6389:3): for current line to question number used for same question
6390:3): in "Master Sequence" (as seen by Course Coordinator).
6391:3): startline - Ref to hash where key is question number (0 is first)
6392:3): and value is number of first bubble line for current
6393:3): student or code-based randompick and/or randomorder.
6394:3): totalref - Ref of scalar used to score total number of bubble
6395:3): lines needed for responses in a scan line (used when
6396:3): randompick in use.
6397:3):
1.423 albertel 6398: Returns:
6399: Hash containing the result of parsing the scanline
6400:
6401: Keys are all proceeded by the string 'scantron.'
6402:
6403: CODE - the CODE in use for this scanline
6404: useCODE - 1 if the CODE is invalid but it usage has been forced
6405: by the operator
6406: CODE_ignore_dup - 1 if the CODE is a duplicated use when unique
6407: CODEs were selected, but the usage has been
6408: forced by the operator
1.556 weissno 6409: ID - student/employee ID
1.423 albertel 6410: PaperID - if used, the ID number printed on the sheet when the
6411: paper was scanned
6412: FirstName - first name from the sheet
6413: LastName - last name from the sheet
6414:
6415: if just_header was not true these key may also exist
6416:
1.447 foxr 6417: missingerror - a list of bubble ranges that are considered to be answers
6418: to a single question that don't have any bubbles filled in.
6419: Of the form questionnumber:firstbubblenumber:count.
6420: doubleerror - a list of bubble ranges that are considered to be answers
6421: to a single question that have more than one bubble filled in.
6422: Of the form questionnumber::firstbubblenumber:count
6423:
6424: In the above, count is the number of bubble responses in the
6425: input line needed to represent the possible answers to the question.
6426: e.g. a radioresponse with 15 choices in an answer sheet with 10 choices
6427: per line would have count = 2.
6428:
1.423 albertel 6429: maxquest - the number of the last bubble line that was parsed
6430:
6431: (<number> starts at 1)
6432: <number>.answer - zero or more letters representing the selected
6433: letters from the scanline for the bubble line
6434: <number>.
6435: if blank there was either no bubble or there where
6436: multiple bubbles, (consult the keys missingerror and
6437: doubleerror if this is an error condition)
6438:
6439: =cut
6440:
1.82 albertel 6441: sub scantron_parse_scanline {
1.596.2.12.2. 6(raebur 6442:3): my ($line,$whichline,$scantron_config,$scan_data,$just_header,$idmap,
6443:3): $randomorder,$randompick,$sequence,$master_seq,$symb_to_resource,
6444:3): $partids_by_symb,$orderedforcode,$respnumlookup,$startline,$totalref)=@_;
1.470 foxr 6445:
1.82 albertel 6446: my %record;
1.596.2.12.2. 6(raebur 6447:3): my $data=substr($line,0,$$scantron_config{'Qstart'}-1); # stuff before answers
1.278 albertel 6448: if (!($$scantron_config{'CODElocation'} eq 0 ||
6449: $$scantron_config{'CODElocation'} eq 'none')) {
6450: if ($$scantron_config{'CODElocation'} < 0 ||
6451: $$scantron_config{'CODElocation'} eq 'letter' ||
6452: $$scantron_config{'CODElocation'} eq 'number') {
1.191 albertel 6453: $record{'scantron.CODE'}=substr($data,
6454: $$scantron_config{'CODEstart'}-1,
1.83 albertel 6455: $$scantron_config{'CODElength'});
1.191 albertel 6456: if (&scan_data($scan_data,"$whichline.useCODE")) {
6457: $record{'scantron.useCODE'}=1;
6458: }
1.192 albertel 6459: if (&scan_data($scan_data,"$whichline.CODE_ignore_dup")) {
6460: $record{'scantron.CODE_ignore_dup'}=1;
6461: }
1.82 albertel 6462: } else {
6463: #FIXME interpret first N questions
6464: }
6465: }
1.83 albertel 6466: $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
6467: $$scantron_config{'IDlength'});
1.157 albertel 6468: $record{'scantron.PaperID'}=
6469: substr($data,$$scantron_config{'PaperID'}-1,
6470: $$scantron_config{'PaperIDlength'});
6471: $record{'scantron.FirstName'}=
6472: substr($data,$$scantron_config{'FirstName'}-1,
6473: $$scantron_config{'FirstNamelength'});
6474: $record{'scantron.LastName'}=
6475: substr($data,$$scantron_config{'LastName'}-1,
6476: $$scantron_config{'LastNamelength'});
1.423 albertel 6477: if ($just_header) { return \%record; }
1.194 albertel 6478:
1.82 albertel 6479: my @alphabet=('A'..'Z');
6480: my $questnum=0;
1.447 foxr 6481: my $ansnum =1; # Multiple 'answer lines'/question.
6482:
1.596.2.12.2. 6(raebur 6483:3): my $lastpos = $env{'form.scantron_maxbubble'}*$$scantron_config{'Qlength'};
6484:3): if ($randompick || $randomorder) {
6485:3): my $total = &get_respnum_lookups($sequence,$scan_data,$idmap,$line,\%record,
6486:3): $master_seq,$symb_to_resource,
6487:3): $partids_by_symb,$orderedforcode,
6488:3): $respnumlookup,$startline);
6489:3): if ($total) {
6490:3): $lastpos = $total*$$scantron_config{'Qlength'};
6491:3): }
6492:3): if (ref($totalref)) {
6493:3): $$totalref = $total;
6494:3): }
6495:3): }
6496:3): my $questions=substr($line,$$scantron_config{'Qstart'}-1,$lastpos); # Answers
1.470 foxr 6497: chomp($questions); # Get rid of any trailing \n.
6498: $questions =~ s/\r$//; # Get rid of trailing \r too (MAC or Win uploads).
6499: while (length($questions)) {
1.596.2.12.2. 6(raebur 6500:3): my $answers_needed;
6501:3): if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
6502:3): $answers_needed = $bubble_lines_per_response{$respnumlookup->{$questnum}};
6503:3): } else {
6504:3): $answers_needed = $bubble_lines_per_response{$questnum};
6505:3): }
1.503 raeburn 6506: my $answer_length = ($$scantron_config{'Qlength'} * $answers_needed)
6507: || 1;
6508: $questnum++;
6509: my $quest_id = $questnum;
6510: my $currentquest = substr($questions,0,$answer_length);
6511: $questions = substr($questions,$answer_length);
6512: if (length($currentquest) < $answer_length) { next; }
6513:
1.596.2.12.2. 6(raebur 6514:3): my $subdivided;
6515:3): if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
6516:3): $subdivided = $subdivided_bubble_lines{$respnumlookup->{$questnum-1}};
6517:3): } else {
6518:3): $subdivided = $subdivided_bubble_lines{$questnum-1};
6519:3): }
6520:3): if ($subdivided =~ /,/) {
1.503 raeburn 6521: my $subquestnum = 1;
6522: my $subquestions = $currentquest;
1.596.2.12.2. 6(raebur 6523:3): my @subanswers_needed = split(/,/,$subdivided);
1.503 raeburn 6524: foreach my $subans (@subanswers_needed) {
6525: my $subans_length =
6526: ($$scantron_config{'Qlength'} * $subans) || 1;
6527: my $currsubquest = substr($subquestions,0,$subans_length);
6528: $subquestions = substr($subquestions,$subans_length);
6529: $quest_id = "$questnum.$subquestnum";
6530: if (($$scantron_config{'Qon'} eq 'letter') ||
6531: ($$scantron_config{'Qon'} eq 'number')) {
6532: $ansnum = &scantron_validator_lettnum($ansnum,
6533: $questnum,$quest_id,$subans,$currsubquest,$whichline,
1.596.2.12.2. 6(raebur 6534:3): \@alphabet,\%record,$scantron_config,$scan_data,
6535:3): $randomorder,$randompick,$respnumlookup);
1.503 raeburn 6536: } else {
6537: $ansnum = &scantron_validator_positional($ansnum,
1.596.2.12.2. 6(raebur 6538:3): $questnum,$quest_id,$subans,$currsubquest,$whichline,
6539:3): \@alphabet,\%record,$scantron_config,$scan_data,
6540:3): $randomorder,$randompick,$respnumlookup);
1.503 raeburn 6541: }
6542: $subquestnum ++;
6543: }
6544: } else {
6545: if (($$scantron_config{'Qon'} eq 'letter') ||
6546: ($$scantron_config{'Qon'} eq 'number')) {
6547: $ansnum = &scantron_validator_lettnum($ansnum,$questnum,
6548: $quest_id,$answers_needed,$currentquest,$whichline,
1.596.2.12.2. 6(raebur 6549:3): \@alphabet,\%record,$scantron_config,$scan_data,
6550:3): $randomorder,$randompick,$respnumlookup);
1.503 raeburn 6551: } else {
6552: $ansnum = &scantron_validator_positional($ansnum,$questnum,
6553: $quest_id,$answers_needed,$currentquest,$whichline,
1.596.2.12.2. 6(raebur 6554:3): \@alphabet,\%record,$scantron_config,$scan_data,
6555:3): $randomorder,$randompick,$respnumlookup);
1.503 raeburn 6556: }
6557: }
6558: }
6559: $record{'scantron.maxquest'}=$questnum;
6560: return \%record;
6561: }
1.447 foxr 6562:
1.596.2.12.2. 6(raebur 6563:3): sub get_master_seq {
6564:3): my ($resources,$master_seq,$symb_to_resource) = @_;
6565:3): return unless ((ref($resources) eq 'ARRAY') && (ref($master_seq) eq 'ARRAY') &&
6566:3): (ref($symb_to_resource) eq 'HASH'));
6567:3): my $resource_error;
6568:3): foreach my $resource (@{$resources}) {
6569:3): my $ressymb;
6570:3): if (ref($resource)) {
6571:3): $ressymb = $resource->symb();
6572:3): push(@{$master_seq},$ressymb);
6573:3): $symb_to_resource->{$ressymb} = $resource;
6574:3): } else {
6575:3): $resource_error = 1;
6576:3): last;
6577:3): }
6578:3): }
6579:3): return $resource_error;
6580:3): }
6581:3):
6582:3): sub get_respnum_lookups {
6583:3): my ($sequence,$scan_data,$idmap,$line,$record,$master_seq,$symb_to_resource,
6584:3): $partids_by_symb,$orderedforcode,$respnumlookup,$startline) = @_;
6585:3): return unless ((ref($record) eq 'HASH') && (ref($master_seq) eq 'ARRAY') &&
6586:3): (ref($symb_to_resource) eq 'HASH') && (ref($partids_by_symb) eq 'HASH') &&
6587:3): (ref($orderedforcode) eq 'HASH') && (ref($respnumlookup) eq 'HASH') &&
6588:3): (ref($startline) eq 'HASH'));
6589:3): my ($user,$scancode);
6590:3): if ((exists($record->{'scantron.CODE'})) &&
6591:3): (&Apache::lonnet::validCODE($record->{'scantron.CODE'}))) {
6592:3): $scancode = $record->{'scantron.CODE'};
6593:3): } else {
6594:3): $user = &scantron_find_student($record,$scan_data,$idmap,$line);
6595:3): }
6596:3): my @mapresources =
6597:3): &users_order($user,$scancode,$sequence,$master_seq,$symb_to_resource,
6598:3): $orderedforcode);
6599:3): my $total = 0;
6600:3): my $count = 0;
6601:3): foreach my $resource (@mapresources) {
6602:3): my $id = $resource->id();
6603:3): my $symb = $resource->symb();
6604:3): if (ref($partids_by_symb->{$symb}) eq 'ARRAY') {
6605:3): foreach my $partid (@{$partids_by_symb->{$symb}}) {
6606:3): my $respnum = $masterseq_id_responsenum{$id.'_'.$partid};
6607:3): if ($respnum ne '') {
6608:3): $respnumlookup->{$count} = $respnum;
6609:3): $startline->{$count} = $total;
6610:3): $total += $bubble_lines_per_response{$respnum};
6611:3): $count ++;
6612:3): }
6613:3): }
6614:3): }
6615:3): }
6616:3): return $total;
6617:3): }
6618:3):
1.503 raeburn 6619: sub scantron_validator_lettnum {
6620: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,$whichline,
1.596.2.12.2. 6(raebur 6621:3): $alphabet,$record,$scantron_config,$scan_data,$randomorder,
6622:3): $randompick,$respnumlookup) = @_;
1.503 raeburn 6623:
6624: # Qon 'letter' implies for each slot in currquest we have:
6625: # ? or * for doubles, a letter in A-Z for a bubble, and
6626: # about anything else (esp. a value of Qoff) for missing
6627: # bubbles.
6628: #
6629: # Qon 'number' implies each slot gives a digit that indexes the
6630: # bubbles filled, or Qoff, or a non-number for unbubbled lines,
6631: # and * or ? for double bubbles on a single line.
6632: #
1.447 foxr 6633:
1.503 raeburn 6634: my $matchon;
6635: if ($$scantron_config{'Qon'} eq 'letter') {
6636: $matchon = '[A-Z]';
6637: } elsif ($$scantron_config{'Qon'} eq 'number') {
6638: $matchon = '\d';
6639: }
6640: my $occurrences = 0;
1.596.2.12.2. 6(raebur 6641:3): my $responsenum = $questnum-1;
6642:3): if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
6643:3): $responsenum = $respnumlookup->{$questnum-1}
6644:3): }
6645:3): if (($responsetype_per_response{$responsenum} eq 'essayresponse') ||
6646:3): ($responsetype_per_response{$responsenum} eq 'formularesponse') ||
6647:3): ($responsetype_per_response{$responsenum} eq 'stringresponse') ||
6648:3): ($responsetype_per_response{$responsenum} eq 'imageresponse') ||
6649:3): ($responsetype_per_response{$responsenum} eq 'reactionresponse') ||
6650:3): ($responsetype_per_response{$responsenum} eq 'organicresponse')) {
1.503 raeburn 6651: my @singlelines = split('',$currquest);
6652: foreach my $entry (@singlelines) {
6653: $occurrences = &occurence_count($entry,$matchon);
6654: if ($occurrences > 1) {
6655: last;
6656: }
1.596.2.12.2. 6(raebur 6657:3): }
1.503 raeburn 6658: } else {
6659: $occurrences = &occurence_count($currquest,$matchon);
6660: }
6661: if (($currquest =~ /\?/ || $currquest =~ /\*/) || ($occurrences > 1)) {
6662: push(@{$record->{'scantron.doubleerror'}},$quest_id);
6663: for (my $ans=0; $ans<$answers_needed; $ans++) {
6664: my $bubble = substr($currquest,$ans,1);
6665: if ($bubble =~ /$matchon/ ) {
6666: if ($$scantron_config{'Qon'} eq 'number') {
6667: if ($bubble == 0) {
6668: $bubble = 10;
6669: }
6670: $record->{"scantron.$ansnum.answer"} =
6671: $alphabet->[$bubble-1];
6672: } else {
6673: $record->{"scantron.$ansnum.answer"} = $bubble;
6674: }
6675: } else {
6676: $record->{"scantron.$ansnum.answer"}='';
6677: }
6678: $ansnum++;
6679: }
6680: } elsif (!defined($currquest)
6681: || (&occurence_count($currquest, $$scantron_config{'Qoff'}) == length($currquest))
6682: || (&occurence_count($currquest,$matchon) == 0)) {
6683: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
6684: $record->{"scantron.$ansnum.answer"}='';
6685: $ansnum++;
6686: }
6687: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
6688: push(@{$record->{'scantron.missingerror'}},$quest_id);
6689: }
6690: } else {
6691: if ($$scantron_config{'Qon'} eq 'number') {
6692: $currquest = &digits_to_letters($currquest);
6693: }
6694: for (my $ans=0; $ans<$answers_needed; $ans++) {
6695: my $bubble = substr($currquest,$ans,1);
6696: $record->{"scantron.$ansnum.answer"} = $bubble;
6697: $ansnum++;
6698: }
6699: }
6700: return $ansnum;
6701: }
1.447 foxr 6702:
1.503 raeburn 6703: sub scantron_validator_positional {
6704: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,
1.596.2.12.2. 6(raebur 6705:3): $whichline,$alphabet,$record,$scantron_config,$scan_data,
6706:3): $randomorder,$randompick,$respnumlookup) = @_;
1.447 foxr 6707:
1.503 raeburn 6708: # Otherwise there's a positional notation;
6709: # each bubble line requires Qlength items, and there are filled in
6710: # bubbles for each case where there 'Qon' characters.
6711: #
1.447 foxr 6712:
1.503 raeburn 6713: my @array=split($$scantron_config{'Qon'},$currquest,-1);
1.447 foxr 6714:
1.503 raeburn 6715: # If the split only gives us one element.. the full length of the
6716: # answer string, no bubbles are filled in:
1.447 foxr 6717:
1.507 raeburn 6718: if ($answers_needed eq '') {
6719: return;
6720: }
6721:
1.503 raeburn 6722: if (length($array[0]) eq $$scantron_config{'Qlength'}*$answers_needed) {
6723: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
6724: $record->{"scantron.$ansnum.answer"}='';
6725: $ansnum++;
6726: }
6727: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
6728: push(@{$record->{"scantron.missingerror"}},$quest_id);
6729: }
6730: } elsif (scalar(@array) == 2) {
6731: my $location = length($array[0]);
6732: my $line_num = int($location / $$scantron_config{'Qlength'});
6733: my $bubble = $alphabet->[$location % $$scantron_config{'Qlength'}];
6734: for (my $ans=0; $ans<$answers_needed; $ans++) {
6735: if ($ans eq $line_num) {
6736: $record->{"scantron.$ansnum.answer"} = $bubble;
6737: } else {
6738: $record->{"scantron.$ansnum.answer"} = ' ';
6739: }
6740: $ansnum++;
6741: }
6742: } else {
6743: # If there's more than one instance of a bubble character
6744: # That's a double bubble; with positional notation we can
6745: # record all the bubbles filled in as well as the
6746: # fact this response consists of multiple bubbles.
6747: #
1.596.2.12.2. 6(raebur 6748:3): my $responsenum = $questnum-1;
6749:3): if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
6750:3): $responsenum = $respnumlookup->{$questnum-1}
6751:3): }
6752:3): if (($responsetype_per_response{$responsenum} eq 'essayresponse') ||
6753:3): ($responsetype_per_response{$responsenum} eq 'formularesponse') ||
6754:3): ($responsetype_per_response{$responsenum} eq 'stringresponse') ||
6755:3): ($responsetype_per_response{$responsenum} eq 'imageresponse') ||
6756:3): ($responsetype_per_response{$responsenum} eq 'reactionresponse') ||
6757:3): ($responsetype_per_response{$responsenum} eq 'organicresponse')) {
1.503 raeburn 6758: my $doubleerror = 0;
6759: while (($currquest >= $$scantron_config{'Qlength'}) &&
6760: (!$doubleerror)) {
6761: my $currline = substr($currquest,0,$$scantron_config{'Qlength'});
6762: $currquest = substr($currquest,$$scantron_config{'Qlength'});
6763: my @currarray = split($$scantron_config{'Qon'},$currline,-1);
6764: if (length(@currarray) > 2) {
6765: $doubleerror = 1;
6766: }
6767: }
6768: if ($doubleerror) {
6769: push(@{$record->{'scantron.doubleerror'}},$quest_id);
6770: }
6771: } else {
6772: push(@{$record->{'scantron.doubleerror'}},$quest_id);
6773: }
6774: my $item = $ansnum;
6775: for (my $ans=0; $ans<$answers_needed; $ans++) {
6776: $record->{"scantron.$item.answer"} = '';
6777: $item ++;
6778: }
1.447 foxr 6779:
1.503 raeburn 6780: my @ans=@array;
6781: my $i=0;
6782: my $increment = 0;
6783: while ($#ans) {
6784: $i+=length($ans[0]) + $increment;
6785: my $line = int($i/$$scantron_config{'Qlength'} + $ansnum);
6786: my $bubble = $i%$$scantron_config{'Qlength'};
6787: $record->{"scantron.$line.answer"}.=$alphabet->[$bubble];
6788: shift(@ans);
6789: $increment = 1;
6790: }
6791: $ansnum += $answers_needed;
1.82 albertel 6792: }
1.503 raeburn 6793: return $ansnum;
1.82 albertel 6794: }
6795:
1.423 albertel 6796: =pod
6797:
6798: =item scantron_add_delay
6799:
6800: Adds an error message that occurred during the grading phase to a
6801: queue of messages to be shown after grading pass is complete
6802:
6803: Arguments:
1.424 albertel 6804: $delayqueue - arrary ref of hash ref of error messages
1.423 albertel 6805: $scanline - the scanline that caused the error
6806: $errormesage - the error message
6807: $errorcode - a numeric code for the error
6808:
6809: Side Effects:
1.424 albertel 6810: updates the $delayqueue to have a new hash ref of the error
1.423 albertel 6811:
6812: =cut
6813:
1.82 albertel 6814: sub scantron_add_delay {
1.140 albertel 6815: my ($delayqueue,$scanline,$errormessage,$errorcode)=@_;
6816: push(@$delayqueue,
6817: {'line' => $scanline, 'emsg' => $errormessage,
6818: 'ecode' => $errorcode }
6819: );
1.82 albertel 6820: }
6821:
1.423 albertel 6822: =pod
6823:
6824: =item scantron_find_student
6825:
1.424 albertel 6826: Finds the username for the current scanline
6827:
6828: Arguments:
6829: $scantron_record - hash result from scantron_parse_scanline
6830: $scan_data - hash of correction information
6831: (see &scantron_getfile() form more information)
6832: $idmap - hash from &username_to_idmap()
6833: $line - number of current scanline
6834:
6835: Returns:
6836: Either 'username:domain' or undef if unknown
6837:
1.423 albertel 6838: =cut
6839:
1.82 albertel 6840: sub scantron_find_student {
1.157 albertel 6841: my ($scantron_record,$scan_data,$idmap,$line)=@_;
1.83 albertel 6842: my $scanID=$$scantron_record{'scantron.ID'};
1.157 albertel 6843: if ($scanID =~ /^\s*$/) {
6844: return &scan_data($scan_data,"$line.user");
6845: }
1.83 albertel 6846: foreach my $id (keys(%$idmap)) {
1.157 albertel 6847: if (lc($id) eq lc($scanID)) {
6848: return $$idmap{$id};
6849: }
1.83 albertel 6850: }
6851: return undef;
6852: }
6853:
1.423 albertel 6854: =pod
6855:
6856: =item scantron_filter
6857:
1.424 albertel 6858: Filter sub for lonnavmaps, filters out hidden resources if ignore
6859: hidden resources was selected
6860:
1.423 albertel 6861: =cut
6862:
1.83 albertel 6863: sub scantron_filter {
6864: my ($curres)=@_;
1.331 albertel 6865:
6866: if (ref($curres) && $curres->is_problem()) {
6867: # if the user has asked to not have either hidden
6868: # or 'randomout' controlled resources to be graded
6869: # don't include them
6870: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
6871: && $curres->randomout) {
6872: return 0;
6873: }
1.83 albertel 6874: return 1;
6875: }
6876: return 0;
1.82 albertel 6877: }
6878:
1.423 albertel 6879: =pod
6880:
6881: =item scantron_process_corrections
6882:
1.424 albertel 6883: Gets correction information out of submitted form data and corrects
6884: the scanline
6885:
1.423 albertel 6886: =cut
6887:
1.157 albertel 6888: sub scantron_process_corrections {
6889: my ($r) = @_;
1.257 albertel 6890: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 6891: my ($scanlines,$scan_data)=&scantron_getfile();
6892: my $classlist=&Apache::loncoursedata::get_classlist();
1.257 albertel 6893: my $which=$env{'form.scantron_line'};
1.200 albertel 6894: my $line=&scantron_get_line($scanlines,$scan_data,$which);
1.157 albertel 6895: my ($skip,$err,$errmsg);
1.257 albertel 6896: if ($env{'form.scantron_skip_record'}) {
1.157 albertel 6897: $skip=1;
1.257 albertel 6898: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)ID$/) {
6899: my $newstudent=$env{'form.scantron_username'}.':'.
6900: $env{'form.scantron_domain'};
1.157 albertel 6901: my $newid=$classlist->{$newstudent}->[&Apache::loncoursedata::CL_ID];
6902: ($line,$err,$errmsg)=
6903: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
6904: 'ID',{'newid'=>$newid,
1.257 albertel 6905: 'username'=>$env{'form.scantron_username'},
6906: 'domain'=>$env{'form.scantron_domain'}});
6907: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)CODE$/) {
6908: my $resolution=$env{'form.scantron_CODE_resolution'};
1.190 albertel 6909: my $newCODE;
1.192 albertel 6910: my %args;
1.190 albertel 6911: if ($resolution eq 'use_unfound') {
1.191 albertel 6912: $newCODE='use_unfound';
1.190 albertel 6913: } elsif ($resolution eq 'use_found') {
1.257 albertel 6914: $newCODE=$env{'form.scantron_CODE_selectedvalue'};
1.190 albertel 6915: } elsif ($resolution eq 'use_typed') {
1.257 albertel 6916: $newCODE=$env{'form.scantron_CODE_newvalue'};
1.194 albertel 6917: } elsif ($resolution =~ /^use_closest_(\d+)/) {
1.257 albertel 6918: $newCODE=$env{"form.scantron_CODE_closest_$1"};
1.190 albertel 6919: }
1.257 albertel 6920: if ($env{'form.scantron_corrections'} eq 'duplicateCODE') {
1.192 albertel 6921: $args{'CODE_ignore_dup'}=1;
6922: }
6923: $args{'CODE'}=$newCODE;
1.186 albertel 6924: ($line,$err,$errmsg)=
6925: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
1.192 albertel 6926: 'CODE',\%args);
1.257 albertel 6927: } elsif ($env{'form.scantron_corrections'} =~ /^(missing|double)bubble$/) {
6928: foreach my $question (split(',',$env{'form.scantron_questions'})) {
1.157 albertel 6929: ($line,$err,$errmsg)=
6930: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,
6931: $which,'answer',
6932: { 'question'=>$question,
1.503 raeburn 6933: 'response'=>$env{"form.scantron_correct_Q_$question"},
6934: 'questionnum'=>$env{"form.scantron_questionnum_Q_$question"}});
1.157 albertel 6935: if ($err) { last; }
6936: }
6937: }
6938: if ($err) {
1.596.2.12.2. 0(raebur 6939:3): $r->print(
6940:3): '<p class="LC_error">'
6941:3): .&mt('Unable to accept last correction, an error occurred: [_1]',
6942:3): $errmsg)
1(raebur 6943:3): .'</p>');
1.157 albertel 6944: } else {
1.200 albertel 6945: &scantron_put_line($scanlines,$scan_data,$which,$line,$skip);
1.157 albertel 6946: &scantron_putfile($scanlines,$scan_data);
6947: }
6948: }
6949:
1.423 albertel 6950: =pod
6951:
6952: =item reset_skipping_status
6953:
1.424 albertel 6954: Forgets the current set of remember skipped scanlines (and thus
6955: reverts back to considering all lines in the
6956: scantron_skipped_<filename> file)
6957:
1.423 albertel 6958: =cut
6959:
1.200 albertel 6960: sub reset_skipping_status {
6961: my ($scanlines,$scan_data)=&scantron_getfile();
6962: &scan_data($scan_data,'remember_skipping',undef,1);
6963: &scantron_putfile(undef,$scan_data);
6964: }
6965:
1.423 albertel 6966: =pod
6967:
6968: =item start_skipping
6969:
1.424 albertel 6970: Marks a scanline to be skipped.
6971:
1.423 albertel 6972: =cut
6973:
1.376 albertel 6974: sub start_skipping {
1.200 albertel 6975: my ($scan_data,$i)=@_;
6976: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 6977: if ($env{'form.scantron_options_redo'} =~ /^redo_/) {
6978: $remembered{$i}=2;
6979: } else {
6980: $remembered{$i}=1;
6981: }
1.200 albertel 6982: &scan_data($scan_data,'remember_skipping',join(':',%remembered));
6983: }
6984:
1.423 albertel 6985: =pod
6986:
6987: =item should_be_skipped
6988:
1.424 albertel 6989: Checks whether a scanline should be skipped.
6990:
1.423 albertel 6991: =cut
6992:
1.200 albertel 6993: sub should_be_skipped {
1.376 albertel 6994: my ($scanlines,$scan_data,$i)=@_;
1.257 albertel 6995: if ($env{'form.scantron_options_redo'} !~ /^redo_/) {
1.200 albertel 6996: # not redoing old skips
1.376 albertel 6997: if ($scanlines->{'skipped'}[$i]) { return 1; }
1.200 albertel 6998: return 0;
6999: }
7000: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 7001:
7002: if (exists($remembered{$i}) && $remembered{$i} != 2 ) {
7003: return 0;
7004: }
1.200 albertel 7005: return 1;
7006: }
7007:
1.423 albertel 7008: =pod
7009:
7010: =item remember_current_skipped
7011:
1.424 albertel 7012: Discovers what scanlines are in the scantron_skipped_<filename>
7013: file and remembers them into scan_data for later use.
7014:
1.423 albertel 7015: =cut
7016:
1.200 albertel 7017: sub remember_current_skipped {
7018: my ($scanlines,$scan_data)=&scantron_getfile();
7019: my %to_remember;
7020: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
7021: if ($scanlines->{'skipped'}[$i]) {
7022: $to_remember{$i}=1;
7023: }
7024: }
1.376 albertel 7025:
1.200 albertel 7026: &scan_data($scan_data,'remember_skipping',join(':',%to_remember));
7027: &scantron_putfile(undef,$scan_data);
7028: }
7029:
1.423 albertel 7030: =pod
7031:
7032: =item check_for_error
7033:
1.424 albertel 7034: Checks if there was an error when attempting to remove a specific
1.596.2.6 raeburn 7035: scantron_.. bubblesheet data file. Prints out an error if
1.424 albertel 7036: something went wrong.
7037:
1.423 albertel 7038: =cut
7039:
1.200 albertel 7040: sub check_for_error {
7041: my ($r,$result)=@_;
7042: if ($result ne 'ok' && $result ne 'not_found' ) {
1.492 albertel 7043: $r->print(&mt("An error occurred ([_1]) when trying to remove the existing corrections.",$result));
1.200 albertel 7044: }
7045: }
1.157 albertel 7046:
1.423 albertel 7047: =pod
7048:
7049: =item scantron_warning_screen
7050:
1.424 albertel 7051: Interstitial screen to make sure the operator has selected the
7052: correct options before we start the validation phase.
7053:
1.423 albertel 7054: =cut
7055:
1.203 albertel 7056: sub scantron_warning_screen {
7057: my ($button_text)=@_;
1.257 albertel 7058: my $title=&Apache::lonnet::gettitle($env{'form.selectpage'});
1.284 albertel 7059: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.373 albertel 7060: my $CODElist;
1.284 albertel 7061: if ($scantron_config{'CODElocation'} &&
7062: $scantron_config{'CODEstart'} &&
7063: $scantron_config{'CODElength'}) {
7064: $CODElist=$env{'form.scantron_CODElist'};
1.596.2.12.2. 8(raebur 7065:4): if ($env{'form.scantron_CODElist'} eq '') { $CODElist='<span class="LC_warning">'.&mt('None').'</span>'; }
1.284 albertel 7066: $CODElist=
1.492 albertel 7067: '<tr><td><b>'.&mt('List of CODES to validate against:').'</b></td><td><tt>'.
1.373 albertel 7068: $env{'form.scantron_CODElist'}.'</tt></td></tr>';
1.284 albertel 7069: }
1.596.2.12.2. (raeburn 7070:): my $lastbubblepoints;
7071:): if ($env{'form.scantron_lastbubblepoints'} ne '') {
7072:): $lastbubblepoints =
7073:): '<tr><td><b>'.&mt('Hand-graded items: points from last bubble in row').'</b></td><td><tt>'.
7074:): $env{'form.scantron_lastbubblepoints'}.'</tt></td></tr>';
7075:): }
1.492 albertel 7076: return ('
1.203 albertel 7077: <p>
1.492 albertel 7078: <span class="LC_warning">
1.596.2.12.2. 6(raebur 7079:3): '.&mt("Please double check the information below before clicking on '[_1]'",&mt($button_text)).'</span>
1.203 albertel 7080: </p>
7081: <table>
1.492 albertel 7082: <tr><td><b>'.&mt('Sequence to be Graded:').'</b></td><td>'.$title.'</td></tr>
7083: <tr><td><b>'.&mt('Data File that will be used:').'</b></td><td><tt>'.$env{'form.scantron_selectfile'}.'</tt></td></tr>
1.596.2.12.2. (raeburn 7084:): '.$CODElist.$lastbubblepoints.'
1.203 albertel 7085: </table>
7086: <br />
1.596.2.12.2. 2(raebur 7087:2): <p> '.&mt("If this information is correct, please click on '[_1]'.",&mt($button_text)).'</p>
7088:2): <p> '.&mt("If something is incorrect, please click the 'Grading Menu' button to start over.").'</p>
1.203 albertel 7089:
7090: <br />
1.492 albertel 7091: ');
1.203 albertel 7092: }
7093:
1.423 albertel 7094: =pod
7095:
7096: =item scantron_do_warning
7097:
1.424 albertel 7098: Check if the operator has picked something for all required
7099: fields. Error out if something is missing.
7100:
1.423 albertel 7101: =cut
7102:
1.203 albertel 7103: sub scantron_do_warning {
7104: my ($r)=@_;
1.324 albertel 7105: my ($symb)=&get_symb($r);
1.203 albertel 7106: if (!$symb) {return '';}
1.324 albertel 7107: my $default_form_data=&defaultFormData($symb);
1.203 albertel 7108: $r->print(&scantron_form_start().$default_form_data);
1.257 albertel 7109: if ( $env{'form.selectpage'} eq '' ||
7110: $env{'form.scantron_selectfile'} eq '' ||
7111: $env{'form.scantron_format'} eq '' ) {
1.596.2.4 raeburn 7112: $r->print("<p>".&mt('You have forgotten to specify some information. Please go Back and try again.')."</p>");
1.257 albertel 7113: if ( $env{'form.selectpage'} eq '') {
1.492 albertel 7114: $r->print('<p><span class="LC_error">'.&mt('You have not selected a Sequence to grade').'</span></p>');
1.237 albertel 7115: }
1.257 albertel 7116: if ( $env{'form.scantron_selectfile'} eq '') {
1.596.2.4 raeburn 7117: $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 7118: }
1.257 albertel 7119: if ( $env{'form.scantron_format'} eq '') {
1.596.2.5 raeburn 7120: $r->print('<p><span class="LC_error">'.&mt("You have not selected the format of the student's response data.").'</span></p>');
1.237 albertel 7121: }
7122: } else {
1.265 www 7123: my $warning=&scantron_warning_screen('Grading: Validate Records');
1.596.2.12.2. (raeburn 7124:): my $bubbledbyhand=&hand_bubble_option();
1.492 albertel 7125: $r->print('
1.596.2.12.2. (raeburn 7126:): '.$warning.$bubbledbyhand.'
1.492 albertel 7127: <input type="submit" name="submit" value="'.&mt('Grading: Validate Records').'" />
1.203 albertel 7128: <input type="hidden" name="command" value="scantron_validate" />
1.492 albertel 7129: ');
1.237 albertel 7130: }
1.352 albertel 7131: $r->print("</form><br />".&show_grading_menu_form($symb));
1.203 albertel 7132: return '';
7133: }
7134:
1.423 albertel 7135: =pod
7136:
7137: =item scantron_form_start
7138:
1.424 albertel 7139: html hidden input for remembering all selected grading options
7140:
1.423 albertel 7141: =cut
7142:
1.203 albertel 7143: sub scantron_form_start {
7144: my ($max_bubble)=@_;
7145: my $result= <<SCANTRONFORM;
7146: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
1.257 albertel 7147: <input type="hidden" name="selectpage" value="$env{'form.selectpage'}" />
7148: <input type="hidden" name="scantron_format" value="$env{'form.scantron_format'}" />
7149: <input type="hidden" name="scantron_selectfile" value="$env{'form.scantron_selectfile'}" />
1.218 albertel 7150: <input type="hidden" name="scantron_maxbubble" value="$max_bubble" />
1.257 albertel 7151: <input type="hidden" name="scantron_CODElist" value="$env{'form.scantron_CODElist'}" />
7152: <input type="hidden" name="scantron_CODEunique" value="$env{'form.scantron_CODEunique'}" />
7153: <input type="hidden" name="scantron_options_redo" value="$env{'form.scantron_options_redo'}" />
7154: <input type="hidden" name="scantron_options_ignore" value="$env{'form.scantron_options_ignore'}" />
1.331 albertel 7155: <input type="hidden" name="scantron_options_hidden" value="$env{'form.scantron_options_hidden'}" />
1.203 albertel 7156: SCANTRONFORM
1.447 foxr 7157:
7158: my $line = 0;
7159: while (defined($env{"form.scantron.bubblelines.$line"})) {
7160: my $chunk =
7161: '<input type="hidden" name="scantron.bubblelines.'.$line.'" value="'.$env{"form.scantron.bubblelines.$line"}.'" />'."\n";
1.448 foxr 7162: $chunk .=
7163: '<input type="hidden" name="scantron.first_bubble_line.'.$line.'" value="'.$env{"form.scantron.first_bubble_line.$line"}.'" />'."\n";
1.503 raeburn 7164: $chunk .=
7165: '<input type="hidden" name="scantron.sub_bubblelines.'.$line.'" value="'.$env{"form.scantron.sub_bubblelines.$line"}.'" />'."\n";
1.504 raeburn 7166: $chunk .=
7167: '<input type="hidden" name="scantron.responsetype.'.$line.'" value="'.$env{"form.scantron.responsetype.$line"}.'" />'."\n";
1.596.2.12.2. 6(raebur 7168:3): $chunk .=
7169:3): '<input type="hidden" name="scantron.residpart.'.$line.'" value="'.$env{"form.scantron.residpart.$line"}.'" />'."\n";
1.447 foxr 7170: $result .= $chunk;
7171: $line++;
1.596.2.12.2. 6(raebur 7172:3): }
1.203 albertel 7173: return $result;
7174: }
7175:
1.423 albertel 7176: =pod
7177:
7178: =item scantron_validate_file
7179:
1.596.2.6 raeburn 7180: Dispatch routine for doing validation of a bubblesheet data file.
1.424 albertel 7181:
7182: Also processes any necessary information resets that need to
7183: occur before validation begins (ignore previous corrections,
7184: restarting the skipped records processing)
7185:
1.423 albertel 7186: =cut
7187:
1.157 albertel 7188: sub scantron_validate_file {
7189: my ($r) = @_;
1.324 albertel 7190: my ($symb)=&get_symb($r);
1.157 albertel 7191: if (!$symb) {return '';}
1.324 albertel 7192: my $default_form_data=&defaultFormData($symb);
1.200 albertel 7193:
1.596.2.12.2. 0(raebur 7194:3): # do the detection of only doing skipped records first before we delete
1.424 albertel 7195: # them when doing the corrections reset
1.257 albertel 7196: if ($env{'form.scantron_options_redo'} ne 'redo_skipped_ready') {
1.200 albertel 7197: &reset_skipping_status();
7198: }
1.257 albertel 7199: if ($env{'form.scantron_options_redo'} eq 'redo_skipped') {
1.200 albertel 7200: &remember_current_skipped();
1.257 albertel 7201: $env{'form.scantron_options_redo'}='redo_skipped_ready';
1.200 albertel 7202: }
7203:
1.257 albertel 7204: if ($env{'form.scantron_options_ignore'} eq 'ignore_corrections') {
1.200 albertel 7205: &check_for_error($r,&scantron_remove_file('corrected'));
7206: &check_for_error($r,&scantron_remove_file('skipped'));
7207: &check_for_error($r,&scantron_remove_scan_data());
1.257 albertel 7208: $env{'form.scantron_options_ignore'}='done';
1.192 albertel 7209: }
1.200 albertel 7210:
1.257 albertel 7211: if ($env{'form.scantron_corrections'}) {
1.157 albertel 7212: &scantron_process_corrections($r);
7213: }
1.503 raeburn 7214: $r->print('<p>'.&mt('Gathering necessary information.').'</p>');$r->rflush();
1.157 albertel 7215: #get the student pick code ready
7216: $r->print(&Apache::loncommon::studentbrowser_javascript());
1.582 raeburn 7217: my $nav_error;
1.596.2.12.2. (raeburn 7218:): my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
7219:): my $max_bubble=&scantron_get_maxbubble(\$nav_error,\%scantron_config);
1.582 raeburn 7220: if ($nav_error) {
7221: $r->print(&navmap_errormsg());
7222: return '';
7223: }
1.203 albertel 7224: my $result=&scantron_form_start($max_bubble).$default_form_data;
1.596.2.12.2. (raeburn 7225:): if ($env{'form.scantron_lastbubblepoints'} ne '') {
7226:): $result .= '<input type="hidden" name="scantron_lastbubblepoints" value="'.$env{'form.scantron_lastbubblepoints'}.'" />';
7227:): }
1.157 albertel 7228: $r->print($result);
7229:
1.334 albertel 7230: my @validate_phases=( 'sequence',
7231: 'ID',
1.157 albertel 7232: 'CODE',
7233: 'doublebubble',
7234: 'missingbubbles');
1.257 albertel 7235: if (!$env{'form.validatepass'}) {
7236: $env{'form.validatepass'} = 0;
1.157 albertel 7237: }
1.257 albertel 7238: my $currentphase=$env{'form.validatepass'};
1.157 albertel 7239:
1.448 foxr 7240:
1.157 albertel 7241: my $stop=0;
7242: while (!$stop && $currentphase < scalar(@validate_phases)) {
1.503 raeburn 7243: $r->print(&mt('Validating '.$validate_phases[$currentphase]).'<br />');
1.157 albertel 7244: $r->rflush();
1.596.2.12.2. 6(raebur 7245:3):
1.157 albertel 7246: my $which="scantron_validate_".$validate_phases[$currentphase];
7247: {
7248: no strict 'refs';
7249: ($stop,$currentphase)=&$which($r,$currentphase);
7250: }
7251: }
7252: if (!$stop) {
1.203 albertel 7253: my $warning=&scantron_warning_screen('Start Grading');
1.542 raeburn 7254: $r->print(&mt('Validation process complete.').'<br />'.
7255: $warning.
7256: &mt('Perform verification for each student after storage of submissions?').
7257: ' <span class="LC_nobreak"><label>'.
7258: '<input type="radio" name="verifyrecord" value="1" />'.&mt('Yes').'</label>'.
7259: (' 'x3).'<label>'.
7260: '<input type="radio" name="verifyrecord" value="0" checked="checked" />'.&mt('No').
7261: '</label></span><br />'.
7262: &mt('Grading will take longer if you use verification.').'<br />'.
1.572 www 7263: &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 7264: '<input type="submit" name="submit" value="'.&mt('Start Grading').'" />'.
7265: '<input type="hidden" name="command" value="scantron_process" />'."\n");
1.157 albertel 7266: } else {
7267: $r->print('<input type="hidden" name="command" value="scantron_validate" />');
7268: $r->print("<input type='hidden' name='validatepass' value='".$currentphase."' />");
7269: }
7270: if ($stop) {
1.334 albertel 7271: if ($validate_phases[$currentphase] eq 'sequence') {
1.539 riegler 7272: $r->print('<input type="submit" name="submit" value="'.&mt('Ignore').' → " />');
1.492 albertel 7273: $r->print(' '.&mt('this error').' <br />');
1.334 albertel 7274:
1.492 albertel 7275: $r->print(" <p>".&mt("Or click the 'Grading Menu' button to start over.")."</p>");
1.334 albertel 7276: } else {
1.503 raeburn 7277: if ($validate_phases[$currentphase] eq 'doublebubble' || $validate_phases[$currentphase] eq 'missingbubbles') {
1.539 riegler 7278: $r->print('<input type="button" name="submitbutton" value="'.&mt('Continue').' →" onclick="javascript:verify_bubble_radio(this.form)" />');
1.503 raeburn 7279: } else {
1.539 riegler 7280: $r->print('<input type="submit" name="submit" value="'.&mt('Continue').' →" />');
1.503 raeburn 7281: }
1.492 albertel 7282: $r->print(' '.&mt('using corrected info').' <br />');
7283: $r->print("<input type='submit' value='".&mt("Skip")."' name='scantron_skip_record' />");
7284: $r->print(" ".&mt("this scanline saving it for later."));
1.334 albertel 7285: }
1.157 albertel 7286: }
1.352 albertel 7287: $r->print(" </form><br />".&show_grading_menu_form($symb));
1.157 albertel 7288: return '';
7289: }
7290:
1.423 albertel 7291:
7292: =pod
7293:
7294: =item scantron_remove_file
7295:
1.596.2.6 raeburn 7296: Removes the requested bubblesheet data file, makes sure that
1.424 albertel 7297: scantron_original_<filename> is never removed
7298:
7299:
1.423 albertel 7300: =cut
7301:
1.200 albertel 7302: sub scantron_remove_file {
1.192 albertel 7303: my ($which)=@_;
1.257 albertel 7304: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
7305: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 7306: my $file='scantron_';
1.200 albertel 7307: if ($which eq 'corrected' || $which eq 'skipped') {
7308: $file.=$which.'_';
1.192 albertel 7309: } else {
7310: return 'refused';
7311: }
1.257 albertel 7312: $file.=$env{'form.scantron_selectfile'};
1.200 albertel 7313: return &Apache::lonnet::removeuserfile($cname,$cdom,$file);
7314: }
7315:
1.423 albertel 7316:
7317: =pod
7318:
7319: =item scantron_remove_scan_data
7320:
1.596.2.6 raeburn 7321: Removes all scan_data correction for the requested bubblesheet
1.424 albertel 7322: data file. (In the case that both the are doing skipped records we need
7323: to remember the old skipped lines for the time being so that element
7324: persists for a while.)
7325:
1.423 albertel 7326: =cut
7327:
1.200 albertel 7328: sub scantron_remove_scan_data {
1.257 albertel 7329: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
7330: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 7331: my @keys=&Apache::lonnet::getkeys('nohist_scantrondata',$cdom,$cname);
7332: my @todelete;
1.257 albertel 7333: my $filename=$env{'form.scantron_selectfile'};
1.192 albertel 7334: foreach my $key (@keys) {
7335: if ($key=~/^\Q$filename\E_/) {
1.257 albertel 7336: if ($env{'form.scantron_options_redo'} eq 'redo_skipped_ready' &&
1.200 albertel 7337: $key=~/remember_skipping/) {
7338: next;
7339: }
1.192 albertel 7340: push(@todelete,$key);
7341: }
7342: }
1.200 albertel 7343: my $result;
1.192 albertel 7344: if (@todelete) {
1.491 albertel 7345: $result = &Apache::lonnet::del('nohist_scantrondata',
7346: \@todelete,$cdom,$cname);
7347: } else {
7348: $result = 'ok';
1.192 albertel 7349: }
7350: return $result;
7351: }
7352:
1.423 albertel 7353:
7354: =pod
7355:
7356: =item scantron_getfile
7357:
1.596.2.6 raeburn 7358: Fetches the requested bubblesheet data file (all 3 versions), and
1.424 albertel 7359: the scan_data hash
7360:
7361: Arguments:
7362: None
7363:
7364: Returns:
7365: 2 hash references
7366:
7367: - first one has
7368: orig -
7369: corrected -
7370: skipped - each of which points to an array ref of the specified
7371: file broken up into individual lines
7372: count - number of scanlines
7373:
7374: - second is the scan_data hash possible keys are
1.425 albertel 7375: ($number refers to scanline numbered $number and thus the key affects
7376: only that scanline
7377: $bubline refers to the specific bubble line element and the aspects
7378: refers to that specific bubble line element)
7379:
7380: $number.user - username:domain to use
7381: $number.CODE_ignore_dup
7382: - ignore the duplicate CODE error
7383: $number.useCODE
7384: - use the CODE in the scanline as is
7385: $number.no_bubble.$bubline
7386: - it is valid that there is no bubbled in bubble
7387: at $number $bubline
7388: remember_skipping
7389: - a frozen hash containing keys of $number and values
7390: of either
7391: 1 - we are on a 'do skipped records pass' and plan
7392: on processing this line
7393: 2 - we are on a 'do skipped records pass' and this
7394: scanline has been marked to skip yet again
1.424 albertel 7395:
1.423 albertel 7396: =cut
7397:
1.157 albertel 7398: sub scantron_getfile {
1.200 albertel 7399: #FIXME really would prefer a scantron directory
1.257 albertel 7400: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
7401: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.157 albertel 7402: my $lines;
7403: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 7404: 'scantron_orig_'.$env{'form.scantron_selectfile'});
1.157 albertel 7405: my %scanlines;
7406: $scanlines{'orig'}=[(split("\n",$lines,-1))];
7407: my $temp=$scanlines{'orig'};
7408: $scanlines{'count'}=$#$temp;
7409:
7410: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 7411: 'scantron_corrected_'.$env{'form.scantron_selectfile'});
1.157 albertel 7412: if ($lines eq '-1') {
7413: $scanlines{'corrected'}=[];
7414: } else {
7415: $scanlines{'corrected'}=[(split("\n",$lines,-1))];
7416: }
7417: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 7418: 'scantron_skipped_'.$env{'form.scantron_selectfile'});
1.157 albertel 7419: if ($lines eq '-1') {
7420: $scanlines{'skipped'}=[];
7421: } else {
7422: $scanlines{'skipped'}=[(split("\n",$lines,-1))];
7423: }
1.175 albertel 7424: my @tmp=&Apache::lonnet::dump('nohist_scantrondata',$cdom,$cname);
1.157 albertel 7425: if ($tmp[0] =~ /^(error:|no_such_host)/) { @tmp=(); }
7426: my %scan_data = @tmp;
7427: return (\%scanlines,\%scan_data);
7428: }
7429:
1.423 albertel 7430: =pod
7431:
7432: =item lonnet_putfile
7433:
1.424 albertel 7434: Wrapper routine to call &Apache::lonnet::finishuserfileupload
7435:
7436: Arguments:
7437: $contents - data to store
7438: $filename - filename to store $contents into
7439:
7440: Returns:
7441: result value from &Apache::lonnet::finishuserfileupload
7442:
1.423 albertel 7443: =cut
7444:
1.157 albertel 7445: sub lonnet_putfile {
7446: my ($contents,$filename)=@_;
1.257 albertel 7447: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7448: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7449: $env{'form.sillywaytopassafilearound'}=$contents;
1.275 albertel 7450: &Apache::lonnet::finishuserfileupload($docuname,$docudom,'sillywaytopassafilearound',$filename);
1.157 albertel 7451:
7452: }
7453:
1.423 albertel 7454: =pod
7455:
7456: =item scantron_putfile
7457:
1.596.2.6 raeburn 7458: Stores the current version of the bubblesheet data files, and the
1.424 albertel 7459: scan_data hash. (Does not modify the original version only the
7460: corrected and skipped versions.
7461:
7462: Arguments:
7463: $scanlines - hash ref that looks like the first return value from
7464: &scantron_getfile()
7465: $scan_data - hash ref that looks like the second return value from
7466: &scantron_getfile()
7467:
1.423 albertel 7468: =cut
7469:
1.157 albertel 7470: sub scantron_putfile {
7471: my ($scanlines,$scan_data) = @_;
1.200 albertel 7472: #FIXME really would prefer a scantron directory
1.257 albertel 7473: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
7474: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.200 albertel 7475: if ($scanlines) {
7476: my $prefix='scantron_';
1.157 albertel 7477: # no need to update orig, shouldn't change
7478: # &lonnet_putfile(join("\n",@{$scanlines->{'orig'}}),$prefix.'orig_'.
1.257 albertel 7479: # $env{'form.scantron_selectfile'});
1.200 albertel 7480: &lonnet_putfile(join("\n",@{$scanlines->{'corrected'}}),
7481: $prefix.'corrected_'.
1.257 albertel 7482: $env{'form.scantron_selectfile'});
1.200 albertel 7483: &lonnet_putfile(join("\n",@{$scanlines->{'skipped'}}),
7484: $prefix.'skipped_'.
1.257 albertel 7485: $env{'form.scantron_selectfile'});
1.200 albertel 7486: }
1.175 albertel 7487: &Apache::lonnet::put('nohist_scantrondata',$scan_data,$cdom,$cname);
1.157 albertel 7488: }
7489:
1.423 albertel 7490: =pod
7491:
7492: =item scantron_get_line
7493:
1.424 albertel 7494: Returns the correct version of the scanline
7495:
7496: Arguments:
7497: $scanlines - hash ref that looks like the first return value from
7498: &scantron_getfile()
7499: $scan_data - hash ref that looks like the second return value from
7500: &scantron_getfile()
7501: $i - number of the requested line (starts at 0)
7502:
7503: Returns:
7504: A scanline, (either the original or the corrected one if it
7505: exists), or undef if the requested scanline should be
7506: skipped. (Either because it's an skipped scanline, or it's an
7507: unskipped scanline and we are not doing a 'do skipped scanlines'
7508: pass.
7509:
1.423 albertel 7510: =cut
7511:
1.157 albertel 7512: sub scantron_get_line {
1.200 albertel 7513: my ($scanlines,$scan_data,$i)=@_;
1.376 albertel 7514: if (&should_be_skipped($scanlines,$scan_data,$i)) { return undef; }
7515: #if ($scanlines->{'skipped'}[$i]) { return undef; }
1.157 albertel 7516: if ($scanlines->{'corrected'}[$i]) {return $scanlines->{'corrected'}[$i];}
7517: return $scanlines->{'orig'}[$i];
7518: }
7519:
1.423 albertel 7520: =pod
7521:
7522: =item scantron_todo_count
7523:
1.424 albertel 7524: Counts the number of scanlines that need processing.
7525:
7526: Arguments:
7527: $scanlines - hash ref that looks like the first return value from
7528: &scantron_getfile()
7529: $scan_data - hash ref that looks like the second return value from
7530: &scantron_getfile()
7531:
7532: Returns:
7533: $count - number of scanlines to process
7534:
1.423 albertel 7535: =cut
7536:
1.200 albertel 7537: sub get_todo_count {
7538: my ($scanlines,$scan_data)=@_;
7539: my $count=0;
7540: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
7541: my $line=&scantron_get_line($scanlines,$scan_data,$i);
7542: if ($line=~/^[\s\cz]*$/) { next; }
7543: $count++;
7544: }
7545: return $count;
7546: }
7547:
1.423 albertel 7548: =pod
7549:
7550: =item scantron_put_line
7551:
1.596.2.6 raeburn 7552: Updates the 'corrected' or 'skipped' versions of the bubblesheet
1.424 albertel 7553: data file.
7554:
7555: Arguments:
7556: $scanlines - hash ref that looks like the first return value from
7557: &scantron_getfile()
7558: $scan_data - hash ref that looks like the second return value from
7559: &scantron_getfile()
7560: $i - line number to update
7561: $newline - contents of the updated scanline
7562: $skip - if true make the line for skipping and update the
7563: 'skipped' file
7564:
1.423 albertel 7565: =cut
7566:
1.157 albertel 7567: sub scantron_put_line {
1.200 albertel 7568: my ($scanlines,$scan_data,$i,$newline,$skip)=@_;
1.157 albertel 7569: if ($skip) {
7570: $scanlines->{'skipped'}[$i]=$newline;
1.376 albertel 7571: &start_skipping($scan_data,$i);
1.157 albertel 7572: return;
7573: }
7574: $scanlines->{'corrected'}[$i]=$newline;
7575: }
7576:
1.423 albertel 7577: =pod
7578:
7579: =item scantron_clear_skip
7580:
1.424 albertel 7581: Remove a line from the 'skipped' file
7582:
7583: Arguments:
7584: $scanlines - hash ref that looks like the first return value from
7585: &scantron_getfile()
7586: $scan_data - hash ref that looks like the second return value from
7587: &scantron_getfile()
7588: $i - line number to update
7589:
1.423 albertel 7590: =cut
7591:
1.376 albertel 7592: sub scantron_clear_skip {
7593: my ($scanlines,$scan_data,$i)=@_;
7594: if (exists($scanlines->{'skipped'}[$i])) {
7595: undef($scanlines->{'skipped'}[$i]);
7596: return 1;
7597: }
7598: return 0;
7599: }
7600:
1.423 albertel 7601: =pod
7602:
7603: =item scantron_filter_not_exam
7604:
1.424 albertel 7605: Filter routine used by &Apache::lonnavmaps::retrieveResources(), to
7606: filter out resources that are not marked as 'exam' mode
7607:
1.423 albertel 7608: =cut
7609:
1.334 albertel 7610: sub scantron_filter_not_exam {
7611: my ($curres)=@_;
7612:
7613: if (ref($curres) && $curres->is_problem() && !$curres->is_exam()) {
7614: # if the user has asked to not have either hidden
7615: # or 'randomout' controlled resources to be graded
7616: # don't include them
7617: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
7618: && $curres->randomout) {
7619: return 0;
7620: }
7621: return 1;
7622: }
7623: return 0;
7624: }
7625:
1.423 albertel 7626: =pod
7627:
7628: =item scantron_validate_sequence
7629:
1.424 albertel 7630: Validates the selected sequence, checking for resource that are
7631: not set to exam mode.
7632:
1.423 albertel 7633: =cut
7634:
1.334 albertel 7635: sub scantron_validate_sequence {
7636: my ($r,$currentphase) = @_;
7637:
7638: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 7639: unless (ref($navmap)) {
7640: $r->print(&navmap_errormsg());
7641: return (1,$currentphase);
7642: }
1.334 albertel 7643: my (undef,undef,$sequence)=
7644: &Apache::lonnet::decode_symb($env{'form.selectpage'});
7645:
7646: my $map=$navmap->getResourceByUrl($sequence);
7647:
7648: $r->print('<input type="hidden" name="validate_sequence_exam"
7649: value="ignore" />');
7650: if ($env{'form.validate_sequence_exam'} ne 'ignore') {
7651: my @resources=
7652: $navmap->retrieveResources($map,\&scantron_filter_not_exam,1,0);
7653: if (@resources) {
1.596.2.12.2. 0(raebur 7654:2): $r->print('<p class="LC_warning">'
7655:2): .&mt('Some resources in the sequence currently are not set to'
7656:2): .' exam mode. Grading these resources currently may not'
7657:2): .' work correctly.')
7658:2): .'</p>'
7659:2): );
1.334 albertel 7660: return (1,$currentphase);
7661: }
7662: }
7663:
7664: return (0,$currentphase+1);
7665: }
7666:
1.423 albertel 7667:
7668:
1.157 albertel 7669: sub scantron_validate_ID {
7670: my ($r,$currentphase) = @_;
7671:
7672: #get student info
7673: my $classlist=&Apache::loncoursedata::get_classlist();
7674: my %idmap=&username_to_idmap($classlist);
7675:
7676: #get scantron line setup
1.257 albertel 7677: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7678: my ($scanlines,$scan_data)=&scantron_getfile();
1.582 raeburn 7679:
7680: my $nav_error;
1.596.2.12.2. (raeburn 7681:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the bubble_lines.. array.
1.582 raeburn 7682: if ($nav_error) {
7683: $r->print(&navmap_errormsg());
7684: return(1,$currentphase);
7685: }
1.157 albertel 7686:
7687: my %found=('ids'=>{},'usernames'=>{});
7688: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7689: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7690: if ($line=~/^[\s\cz]*$/) { next; }
7691: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7692: $scan_data);
7693: my $id=$$scan_record{'scantron.ID'};
7694: my $found;
7695: foreach my $checkid (keys(%idmap)) {
7696: if (lc($checkid) eq lc($id)) { $found=$checkid;last; }
7697: }
7698: if ($found) {
7699: my $username=$idmap{$found};
7700: if ($found{'ids'}{$found}) {
7701: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
7702: $line,'duplicateID',$found);
1.194 albertel 7703: return(1,$currentphase);
1.157 albertel 7704: } elsif ($found{'usernames'}{$username}) {
7705: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
7706: $line,'duplicateID',$username);
1.194 albertel 7707: return(1,$currentphase);
1.157 albertel 7708: }
1.186 albertel 7709: #FIXME store away line we previously saw the ID on to use above
1.157 albertel 7710: $found{'ids'}{$found}++;
7711: $found{'usernames'}{$username}++;
7712: } else {
7713: if ($id =~ /^\s*$/) {
1.158 albertel 7714: my $username=&scan_data($scan_data,"$i.user");
1.157 albertel 7715: if (defined($username) && $found{'usernames'}{$username}) {
7716: &scantron_get_correction($r,$i,$scan_record,
7717: \%scantron_config,
7718: $line,'duplicateID',$username);
1.194 albertel 7719: return(1,$currentphase);
1.157 albertel 7720: } elsif (!defined($username)) {
7721: &scantron_get_correction($r,$i,$scan_record,
7722: \%scantron_config,
7723: $line,'incorrectID');
1.194 albertel 7724: return(1,$currentphase);
1.157 albertel 7725: }
7726: $found{'usernames'}{$username}++;
7727: } else {
7728: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
7729: $line,'incorrectID');
1.194 albertel 7730: return(1,$currentphase);
1.157 albertel 7731: }
7732: }
7733: }
7734:
7735: return (0,$currentphase+1);
7736: }
7737:
1.423 albertel 7738:
1.157 albertel 7739: sub scantron_get_correction {
1.596.2.12.2. 6(raebur 7740:3): my ($r,$i,$scan_record,$scan_config,$line,$error,$arg,
7741:3): $randomorder,$randompick,$respnumlookup,$startline)=@_;
1.454 banghart 7742: #FIXME in the case of a duplicated ID the previous line, probably need
1.157 albertel 7743: #to show both the current line and the previous one and allow skipping
7744: #the previous one or the current one
7745:
1.333 albertel 7746: if ( $$scan_record{'scantron.PaperID'} =~ /\S/) {
1.596.2.6 raeburn 7747: $r->print(
7748: '<p class="LC_warning">'
7749: .&mt('An error was detected ([_1]) for PaperID [_2]',
7750: "<b>$error</b>",
7751: '<tt>'.$$scan_record{'scantron.PaperID'}.'</tt>')
7752: ."</p> \n");
1.157 albertel 7753: } else {
1.596.2.6 raeburn 7754: $r->print(
7755: '<p class="LC_warning">'
7756: .&mt('An error was detected ([_1]) in scanline [_2] [_3]',
7757: "<b>$error</b>", $i, "<pre>$line</pre>")
7758: ."</p> \n");
7759: }
7760: my $message =
7761: '<p>'
7762: .&mt('The ID on the form is [_1]',
7763: "<tt>$$scan_record{'scantron.ID'}</tt>")
7764: .'<br />'
1.596.2.12 raeburn 7765: .&mt('The name on the paper is [_1], [_2]',
1.596.2.6 raeburn 7766: $$scan_record{'scantron.LastName'},
7767: $$scan_record{'scantron.FirstName'})
7768: .'</p>';
1.242 albertel 7769:
1.157 albertel 7770: $r->print('<input type="hidden" name="scantron_corrections" value="'.$error.'" />'."\n");
7771: $r->print('<input type="hidden" name="scantron_line" value="'.$i.'" />'."\n");
1.503 raeburn 7772: # Array populated for doublebubble or
7773: my @lines_to_correct; # missingbubble errors to build javascript
7774: # to validate radio button checking
7775:
1.157 albertel 7776: if ($error =~ /ID$/) {
1.186 albertel 7777: if ($error eq 'incorrectID') {
1.596.2.6 raeburn 7778: $r->print('<p class="LC_warning">'.&mt("The encoded ID is not in the classlist").
1.492 albertel 7779: "</p>\n");
1.157 albertel 7780: } elsif ($error eq 'duplicateID') {
1.596.2.6 raeburn 7781: $r->print('<p class="LC_warning">'.&mt("The encoded ID has also been used by a previous paper [_1]",$arg)."</p>\n");
1.157 albertel 7782: }
1.242 albertel 7783: $r->print($message);
1.492 albertel 7784: $r->print("<p>".&mt("How should I handle this?")." <br /> \n");
1.157 albertel 7785: $r->print("\n<ul><li> ");
7786: #FIXME it would be nice if this sent back the user ID and
7787: #could do partial userID matches
7788: $r->print(&Apache::loncommon::selectstudent_link('scantronupload',
7789: 'scantron_username','scantron_domain'));
7790: $r->print(": <input type='text' name='scantron_username' value='' />");
1.596.2.12.2. 3(raebur 7791:3): $r->print("\n:\n".
1.257 albertel 7792: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'scantron_domain'));
1.157 albertel 7793:
7794: $r->print('</li>');
1.186 albertel 7795: } elsif ($error =~ /CODE$/) {
7796: if ($error eq 'incorrectCODE') {
1.596.2.6 raeburn 7797: $r->print('<p class="LC_warning">'.&mt("The encoded CODE is not in the list of possible CODEs.")."</p>\n");
1.186 albertel 7798: } elsif ($error eq 'duplicateCODE') {
1.596.2.6 raeburn 7799: $r->print('<p class="LC_warning">'.&mt("The encoded CODE has also been used by a previous paper [_1], and CODEs are supposed to be unique.",join(', ',@{$arg}))."</p>\n");
1.186 albertel 7800: }
1.596.2.6 raeburn 7801: $r->print("<p>".&mt('The CODE on the form is [_1]',
7802: "<tt>'$$scan_record{'scantron.CODE'}'</tt>")
7803: ."</p>\n");
1.242 albertel 7804: $r->print($message);
1.596.2.6 raeburn 7805: $r->print("<p>".&mt("How should I handle this?")."</p>\n");
1.187 albertel 7806: $r->print("\n<br /> ");
1.194 albertel 7807: my $i=0;
1.273 albertel 7808: if ($error eq 'incorrectCODE'
7809: && $$scan_record{'scantron.CODE'}=~/\S/ ) {
1.194 albertel 7810: my ($max,$closest)=&scantron_get_closely_matching_CODEs($arg,$$scan_record{'scantron.CODE'});
1.278 albertel 7811: if ($closest > 0) {
7812: foreach my $testcode (@{$closest}) {
7813: my $checked='';
1.569 bisitz 7814: if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 7815: $r->print("
7816: <label>
1.569 bisitz 7817: <input type='radio' name='scantron_CODE_resolution' value='use_closest_$i'$checked />
1.492 albertel 7818: ".&mt("Use the similar CODE [_1] instead.",
7819: "<b><tt>".$testcode."</tt></b>")."
7820: </label>
7821: <input type='hidden' name='scantron_CODE_closest_$i' value='$testcode' />");
1.278 albertel 7822: $r->print("\n<br />");
7823: $i++;
7824: }
1.194 albertel 7825: }
7826: }
1.273 albertel 7827: if ($$scan_record{'scantron.CODE'}=~/\S/ ) {
1.569 bisitz 7828: my $checked; if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 7829: $r->print("
7830: <label>
1.569 bisitz 7831: <input type='radio' name='scantron_CODE_resolution' value='use_unfound'$checked />
1.596.2.6 raeburn 7832: ".&mt("Use the CODE [_1] that was on the paper, ignoring the error.",
1.492 albertel 7833: "<b><tt>".$$scan_record{'scantron.CODE'}."</tt></b>")."
7834: </label>");
1.273 albertel 7835: $r->print("\n<br />");
7836: }
1.194 albertel 7837:
1.188 albertel 7838: $r->print(<<ENDSCRIPT);
7839: <script type="text/javascript">
7840: function change_radio(field) {
1.190 albertel 7841: var slct=document.scantronupload.scantron_CODE_resolution;
1.188 albertel 7842: var i;
7843: for (i=0;i<slct.length;i++) {
7844: if (slct[i].value==field) { slct[i].checked=true; }
7845: }
7846: }
7847: </script>
7848: ENDSCRIPT
1.187 albertel 7849: my $href="/adm/pickcode?".
1.359 www 7850: "form=".&escape("scantronupload").
7851: "&scantron_format=".&escape($env{'form.scantron_format'}).
7852: "&scantron_CODElist=".&escape($env{'form.scantron_CODElist'}).
7853: "&curCODE=".&escape($$scan_record{'scantron.CODE'}).
7854: "&scantron_selectfile=".&escape($env{'form.scantron_selectfile'});
1.332 albertel 7855: if ($env{'form.scantron_CODElist'} =~ /\S/) {
1.492 albertel 7856: $r->print("
7857: <label>
7858: <input type='radio' name='scantron_CODE_resolution' value='use_found' />
7859: ".&mt("[_1]Select[_2] a CODE from the list of all CODEs and use it.",
7860: "<a target='_blank' href='$href'>","</a>")."
7861: </label>
1.558 bisitz 7862: ".&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 7863: $r->print("\n<br />");
7864: }
1.492 albertel 7865: $r->print("
7866: <label>
7867: <input type='radio' name='scantron_CODE_resolution' value='use_typed' />
7868: ".&mt("Use [_1] as the CODE.",
7869: "</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 7870: $r->print("\n<br /><br />");
1.157 albertel 7871: } elsif ($error eq 'doublebubble') {
1.596.2.6 raeburn 7872: $r->print('<p class="LC_warning">'.&mt("There have been multiple bubbles scanned for some question(s)")."</p>\n");
1.497 foxr 7873:
7874: # The form field scantron_questions is acutally a list of line numbers.
7875: # represented by this form so:
7876:
1.596.2.12.2. 6(raebur 7877:3): my $line_list = &questions_to_line_list($arg,$randomorder,$randompick,
7878:3): $respnumlookup,$startline);
1.497 foxr 7879:
1.157 albertel 7880: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 7881: $line_list.'" />');
1.242 albertel 7882: $r->print($message);
1.492 albertel 7883: $r->print("<p>".&mt("Please indicate which bubble should be used for grading")."</p>");
1.157 albertel 7884: foreach my $question (@{$arg}) {
1.503 raeburn 7885: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
1.596.2.12.2. 6(raebur 7886:3): $scan_record, $error,
7887:3): $randomorder,$randompick,
7888:3): $respnumlookup,$startline);
1.524 raeburn 7889: push(@lines_to_correct,@linenums);
1.157 albertel 7890: }
1.503 raeburn 7891: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 7892: } elsif ($error eq 'missingbubble') {
1.596.2.9 raeburn 7893: $r->print('<p class="LC_warning">'.&mt("There have been [_1]no[_2] bubbles scanned for some question(s)",'<b>','</b>')."</p>\n");
1.242 albertel 7894: $r->print($message);
1.492 albertel 7895: $r->print("<p>".&mt("Please indicate which bubble should be used for grading.")."</p>");
1.503 raeburn 7896: $r->print(&mt("Some questions have no scanned bubbles.")."\n");
1.497 foxr 7897:
1.503 raeburn 7898: # The form field scantron_questions is actually a list of line numbers not
1.497 foxr 7899: # a list of question numbers. Therefore:
7900: #
7901:
1.596.2.12.2. 6(raebur 7902:3): my $line_list = &questions_to_line_list($arg,$randomorder,$randompick,
7903:3): $respnumlookup,$startline);
1.497 foxr 7904:
1.157 albertel 7905: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 7906: $line_list.'" />');
1.157 albertel 7907: foreach my $question (@{$arg}) {
1.503 raeburn 7908: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
1.596.2.12.2. 6(raebur 7909:3): $scan_record, $error,
7910:3): $randomorder,$randompick,
7911:3): $respnumlookup,$startline);
1.524 raeburn 7912: push(@lines_to_correct,@linenums);
1.157 albertel 7913: }
1.503 raeburn 7914: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 7915: } else {
7916: $r->print("\n<ul>");
7917: }
7918: $r->print("\n</li></ul>");
1.497 foxr 7919: }
7920:
1.503 raeburn 7921: sub verify_bubbles_checked {
7922: my (@ansnums) = @_;
7923: my $ansnumstr = join('","',@ansnums);
7924: my $warning = &mt("A bubble or 'No bubble' selection has not been made for one or more lines.");
1.596.2.12.2. 6(raebur 7925:6): &js_escape(\$warning);
1.503 raeburn 7926: my $output = (<<ENDSCRIPT);
7927: <script type="text/javascript">
7928: function verify_bubble_radio(form) {
7929: var ansnumArray = new Array ("$ansnumstr");
7930: var need_bubble_count = 0;
7931: for (var i=0; i<ansnumArray.length; i++) {
7932: if (form.elements["scantron_correct_Q_"+ansnumArray[i]].length > 1) {
7933: var bubble_picked = 0;
7934: for (var j=0; j<form.elements["scantron_correct_Q_"+ansnumArray[i]].length; j++) {
7935: if (form.elements["scantron_correct_Q_"+ansnumArray[i]][j].checked == true) {
7936: bubble_picked = 1;
7937: }
7938: }
7939: if (bubble_picked == 0) {
7940: need_bubble_count ++;
7941: }
7942: }
7943: }
7944: if (need_bubble_count) {
7945: alert("$warning");
7946: return;
7947: }
7948: form.submit();
7949: }
7950: </script>
7951: ENDSCRIPT
7952: return $output;
7953: }
7954:
1.497 foxr 7955: =pod
7956:
7957: =item questions_to_line_list
1.157 albertel 7958:
1.497 foxr 7959: Converts a list of questions into a string of comma separated
7960: line numbers in the answer sheet used by the questions. This is
7961: used to fill in the scantron_questions form field.
7962:
7963: Arguments:
7964: questions - Reference to an array of questions.
1.596.2.12.2. 6(raebur 7965:3): randomorder - True if randomorder in use.
7966:3): randompick - True if randompick in use.
7967:3): respnumlookup - Reference to HASH mapping question numbers in bubble lines
7968:3): for current line to question number used for same question
7969:3): in "Master Seqence" (as seen by Course Coordinator).
7970:3): startline - Reference to hash where key is question number (0 is first)
7971:3): and key is number of first bubble line for current student
7972:3): or code-based randompick and/or randomorder.
1.497 foxr 7973:
7974: =cut
7975:
7976:
7977: sub questions_to_line_list {
1.596.2.12.2. 6(raebur 7978:3): my ($questions,$randomorder,$randompick,$respnumlookup,$startline) = @_;
1.497 foxr 7979: my @lines;
7980:
1.503 raeburn 7981: foreach my $item (@{$questions}) {
7982: my $question = $item;
7983: my ($first,$count,$last);
7984: if ($item =~ /^(\d+)\.(\d+)$/) {
7985: $question = $1;
7986: my $subquestion = $2;
1.596.2.12.2. 6(raebur 7987:3): my $responsenum = $question-1;
7988:3): if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
7989:3): $responsenum = $respnumlookup->{$question-1};
7990:3): if (ref($startline) eq 'HASH') {
7991:3): $first = $startline->{$question-1} + 1;
7992:3): }
7993:3): } else {
7994:3): $first = $first_bubble_line{$responsenum} + 1;
7995:3): }
7(raebur 7996:3): my @subans = split(/,/,$subdivided_bubble_lines{$responsenum});
1.503 raeburn 7997: my $subcount = 1;
7998: while ($subcount<$subquestion) {
7999: $first += $subans[$subcount-1];
8000: $subcount ++;
8001: }
8002: $count = $subans[$subquestion-1];
8003: } else {
1.596.2.12.2. 7(raebur 8004:3): my $responsenum = $question-1;
8005:3): if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
8006:3): $responsenum = $respnumlookup->{$question-1};
8007:3): if (ref($startline) eq 'HASH') {
8008:3): $first = $startline->{$question-1} + 1;
8009:3): }
8010:3): } else {
8011:3): $first = $first_bubble_line{$responsenum} + 1;
8012:3): }
8013:3): $count = $bubble_lines_per_response{$responsenum};
1.503 raeburn 8014: }
1.506 raeburn 8015: $last = $first+$count-1;
1.503 raeburn 8016: push(@lines, ($first..$last));
1.497 foxr 8017: }
8018: return join(',', @lines);
8019: }
8020:
8021: =pod
8022:
8023: =item prompt_for_corrections
8024:
8025: Prompts for a potentially multiline correction to the
8026: user's bubbling (factors out common code from scantron_get_correction
8027: for multi and missing bubble cases).
8028:
8029: Arguments:
8030: $r - Apache request object.
8031: $question - The question number to prompt for.
8032: $scan_config - The scantron file configuration hash.
8033: $scan_record - Reference to the hash that has the the parsed scanlines.
1.503 raeburn 8034: $error - Type of error
1.596.2.12.2. 7(raebur 8035:3): $randomorder - True if randomorder in use.
8036:3): $randompick - True if randompick in use.
8037:3): $respnumlookup - Reference to HASH mapping question numbers in bubble lines
8038:3): for current line to question number used for same question
8039:3): in "Master Seqence" (as seen by Course Coordinator).
8040:3): $startline - Reference to hash where key is question number (0 is first)
8041:3): and value is number of first bubble line for current student
8042:3): or code-based randompick and/or randomorder.
1.497 foxr 8043:
8044: Implicit inputs:
8045: %bubble_lines_per_response - Starting line numbers for each question.
8046: Numbered from 0 (but question numbers are from
8047: 1.
8048: %first_bubble_line - Starting bubble line for each question.
1.509 raeburn 8049: %subdivided_bubble_lines - optionresponse, matchresponse and rankresponse
8050: type problems render as separate sub-questions,
1.503 raeburn 8051: in exam mode. This hash contains a
8052: comma-separated list of the lines per
8053: sub-question.
1.510 raeburn 8054: %responsetype_per_response - essayresponse, formularesponse,
8055: stringresponse, imageresponse, reactionresponse,
8056: and organicresponse type problem parts can have
1.503 raeburn 8057: multiple lines per response if the weight
8058: assigned exceeds 10. In this case, only
8059: one bubble per line is permitted, but more
8060: than one line might contain bubbles, e.g.
8061: bubbling of: line 1 - J, line 2 - J,
8062: line 3 - B would assign 22 points.
1.497 foxr 8063:
8064: =cut
8065:
8066: sub prompt_for_corrections {
1.596.2.12.2. 6(raebur 8067:3): my ($r, $question, $scan_config, $scan_record, $error, $randomorder,
8068:3): $randompick, $respnumlookup, $startline) = @_;
1.503 raeburn 8069: my ($current_line,$lines);
8070: my @linenums;
8071: my $questionnum = $question;
1.596.2.12.2. 6(raebur 8072:3): my ($first,$responsenum);
1.503 raeburn 8073: if ($question =~ /^(\d+)\.(\d+)$/) {
8074: $question = $1;
8075: my $subquestion = $2;
1.596.2.12.2. 6(raebur 8076:3): if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
8077:3): $responsenum = $respnumlookup->{$question-1};
8078:3): if (ref($startline) eq 'HASH') {
8079:3): $first = $startline->{$question-1};
8080:3): }
8081:3): } else {
8082:3): $responsenum = $question-1;
7(raebur 8083:4): $first = $first_bubble_line{$responsenum};
6(raebur 8084:3): }
8085:3): $current_line = $first + 1 ;
8086:3): my @subans = split(/,/,$subdivided_bubble_lines{$responsenum});
1.503 raeburn 8087: my $subcount = 1;
8088: while ($subcount<$subquestion) {
8089: $current_line += $subans[$subcount-1];
8090: $subcount ++;
8091: }
8092: $lines = $subans[$subquestion-1];
8093: } else {
1.596.2.12.2. 6(raebur 8094:3): if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
8095:3): $responsenum = $respnumlookup->{$question-1};
8096:3): if (ref($startline) eq 'HASH') {
8097:3): $first = $startline->{$question-1};
8098:3): }
8099:3): } else {
8100:3): $responsenum = $question-1;
8101:3): $first = $first_bubble_line{$responsenum};
8102:3): }
8103:3): $current_line = $first + 1;
8104:3): $lines = $bubble_lines_per_response{$responsenum};
1.503 raeburn 8105: }
1.497 foxr 8106: if ($lines > 1) {
1.503 raeburn 8107: $r->print(&mt('The group of bubble lines below responds to a single question.').'<br />');
1.596.2.12.2. 6(raebur 8108:3): if (($responsetype_per_response{$responsenum} eq 'essayresponse') ||
8109:3): ($responsetype_per_response{$responsenum} eq 'formularesponse') ||
8110:3): ($responsetype_per_response{$responsenum} eq 'stringresponse') ||
8111:3): ($responsetype_per_response{$responsenum} eq 'imageresponse') ||
8112:3): ($responsetype_per_response{$responsenum} eq 'reactionresponse') ||
8113:3): ($responsetype_per_response{$responsenum} eq 'organicresponse')) {
4(raebur 8114:3): $r->print(&mt("Although this particular question type requires handgrading, the instructions for this question in the bubblesheet exam directed students to leave [quant,_1,line] blank on their bubblesheets.",$lines).'<br /><br />'.&mt('A non-zero score can be assigned to the student during bubblesheet grading by selecting a bubble in at least one line.').'<br />'.&mt('The score for this question will be a sum of the numeric values for the selected bubbles from each line, where A=1 point, B=2 points etc.').'<br />'.&mt("To assign a score of zero for this question, mark all lines as 'No bubble'.").'<br /><br />');
1.503 raeburn 8115: } else {
8116: $r->print(&mt("Select at most one bubble in a single line and select 'No Bubble' in all the other lines. ")."<br />");
8117: }
1.497 foxr 8118: }
8119: for (my $i =0; $i < $lines; $i++) {
1.503 raeburn 8120: my $selected = $$scan_record{"scantron.$current_line.answer"};
1.596.2.12.2. 6(raebur 8121:3): &scantron_bubble_selector($r,$scan_config,$current_line,
1.503 raeburn 8122: $questionnum,$error,split('', $selected));
1.524 raeburn 8123: push(@linenums,$current_line);
1.497 foxr 8124: $current_line++;
8125: }
8126: if ($lines > 1) {
8127: $r->print("<hr /><br />");
8128: }
1.503 raeburn 8129: return @linenums;
1.157 albertel 8130: }
1.423 albertel 8131:
8132: =pod
8133:
8134: =item scantron_bubble_selector
8135:
8136: Generates the html radiobuttons to correct a single bubble line
1.424 albertel 8137: possibly showing the existing the selected bubbles if known
1.423 albertel 8138:
8139: Arguments:
8140: $r - Apache request object
8141: $scan_config - hash from &get_scantron_config()
1.497 foxr 8142: $line - Number of the line being displayed.
1.503 raeburn 8143: $questionnum - Question number (may include subquestion)
8144: $error - Type of error.
1.497 foxr 8145: @selected - Array of bubbles picked on this line.
1.423 albertel 8146:
8147: =cut
8148:
1.157 albertel 8149: sub scantron_bubble_selector {
1.503 raeburn 8150: my ($r,$scan_config,$line,$questionnum,$error,@selected)=@_;
1.157 albertel 8151: my $max=$$scan_config{'Qlength'};
1.274 albertel 8152:
8153: my $scmode=$$scan_config{'Qon'};
1.596.2.12.2. (raeburn 8154:): if ($scmode eq 'number' || $scmode eq 'letter') {
8155:): if (($$scan_config{'BubblesPerRow'} =~ /^\d+$/) &&
8156:): ($$scan_config{'BubblesPerRow'} > 0)) {
8157:): $max=$$scan_config{'BubblesPerRow'};
8158:): if (($scmode eq 'number') && ($max > 10)) {
8159:): $max = 10;
8160:): } elsif (($scmode eq 'letter') && $max > 26) {
8161:): $max = 26;
8162:): }
8163:): } else {
8164:): $max = 10;
8165:): }
8166:): }
1.274 albertel 8167:
1.157 albertel 8168: my @alphabet=('A'..'Z');
1.503 raeburn 8169: $r->print(&Apache::loncommon::start_data_table().
8170: &Apache::loncommon::start_data_table_row());
8171: $r->print('<td rowspan="2" class="LC_leftcol_header">'.$line.'</td>');
1.497 foxr 8172: for (my $i=0;$i<$max+1;$i++) {
8173: $r->print("\n".'<td align="center">');
8174: if ($selected[0] eq $alphabet[$i]) { $r->print('X'); shift(@selected) }
8175: else { $r->print(' '); }
8176: $r->print('</td>');
8177: }
1.503 raeburn 8178: $r->print(&Apache::loncommon::end_data_table_row().
8179: &Apache::loncommon::start_data_table_row());
1.497 foxr 8180: for (my $i=0;$i<$max;$i++) {
8181: $r->print("\n".
8182: '<td><label><input type="radio" name="scantron_correct_Q_'.
8183: $line.'" value="'.$i.'" />'.$alphabet[$i]."</label></td>");
8184: }
1.503 raeburn 8185: my $nobub_checked = ' ';
8186: if ($error eq 'missingbubble') {
8187: $nobub_checked = ' checked = "checked" ';
8188: }
8189: $r->print("\n".'<td><label><input type="radio" name="scantron_correct_Q_'.
8190: $line.'" value="none"'.$nobub_checked.'/>'.&mt('No bubble').
8191: '</label>'."\n".'<input type="hidden" name="scantron_questionnum_Q_'.
8192: $line.'" value="'.$questionnum.'" /></td>');
8193: $r->print(&Apache::loncommon::end_data_table_row().
8194: &Apache::loncommon::end_data_table());
1.157 albertel 8195: }
8196:
1.423 albertel 8197: =pod
8198:
8199: =item num_matches
8200:
1.424 albertel 8201: Counts the number of characters that are the same between the two arguments.
8202:
8203: Arguments:
8204: $orig - CODE from the scanline
8205: $code - CODE to match against
8206:
8207: Returns:
8208: $count - integer count of the number of same characters between the
8209: two arguments
8210:
1.423 albertel 8211: =cut
8212:
1.194 albertel 8213: sub num_matches {
8214: my ($orig,$code) = @_;
8215: my @code=split(//,$code);
8216: my @orig=split(//,$orig);
8217: my $same=0;
8218: for (my $i=0;$i<scalar(@code);$i++) {
8219: if ($code[$i] eq $orig[$i]) { $same++; }
8220: }
8221: return $same;
8222: }
8223:
1.423 albertel 8224: =pod
8225:
8226: =item scantron_get_closely_matching_CODEs
8227:
1.424 albertel 8228: Cycles through all CODEs and finds the set that has the greatest
8229: number of same characters as the provided CODE
8230:
8231: Arguments:
8232: $allcodes - hash ref returned by &get_codes()
8233: $CODE - CODE from the current scanline
8234:
8235: Returns:
8236: 2 element list
8237: - first elements is number of how closely matching the best fit is
8238: (5 means best set has 5 matching characters)
8239: - second element is an arrary ref containing the set of valid CODEs
8240: that best fit the passed in CODE
8241:
1.423 albertel 8242: =cut
8243:
1.194 albertel 8244: sub scantron_get_closely_matching_CODEs {
8245: my ($allcodes,$CODE)=@_;
8246: my @CODEs;
8247: foreach my $testcode (sort(keys(%{$allcodes}))) {
8248: push(@{$CODEs[&num_matches($CODE,$testcode)]},$testcode);
8249: }
8250:
8251: return ($#CODEs,$CODEs[-1]);
8252: }
8253:
1.423 albertel 8254: =pod
8255:
8256: =item get_codes
8257:
1.424 albertel 8258: Builds a hash which has keys of all of the valid CODEs from the selected
8259: set of remembered CODEs.
8260:
8261: Arguments:
8262: $old_name - name of the set of remembered CODEs
8263: $cdom - domain of the course
8264: $cnum - internal course name
8265:
8266: Returns:
8267: %allcodes - keys are the valid CODEs, values are all 1
8268:
1.423 albertel 8269: =cut
8270:
1.194 albertel 8271: sub get_codes {
1.280 foxr 8272: my ($old_name, $cdom, $cnum) = @_;
8273: if (!$old_name) {
8274: $old_name=$env{'form.scantron_CODElist'};
8275: }
8276: if (!$cdom) {
8277: $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
8278: }
8279: if (!$cnum) {
8280: $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
8281: }
1.278 albertel 8282: my %result=&Apache::lonnet::get('CODEs',[$old_name,"type\0$old_name"],
8283: $cdom,$cnum);
8284: my %allcodes;
8285: if ($result{"type\0$old_name"} eq 'number') {
8286: %allcodes=map {($_,1)} split(',',$result{$old_name});
8287: } else {
8288: %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
8289: }
1.194 albertel 8290: return %allcodes;
8291: }
8292:
1.423 albertel 8293: =pod
8294:
8295: =item scantron_validate_CODE
8296:
1.424 albertel 8297: Validates all scanlines in the selected file to not have any
8298: invalid or underspecified CODEs and that none of the codes are
8299: duplicated if this was requested.
8300:
1.423 albertel 8301: =cut
8302:
1.157 albertel 8303: sub scantron_validate_CODE {
8304: my ($r,$currentphase) = @_;
1.257 albertel 8305: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.186 albertel 8306: if ($scantron_config{'CODElocation'} &&
8307: $scantron_config{'CODEstart'} &&
8308: $scantron_config{'CODElength'}) {
1.257 albertel 8309: if (!defined($env{'form.scantron_CODElist'})) {
1.186 albertel 8310: &FIXME_blow_up()
8311: }
8312: } else {
8313: return (0,$currentphase+1);
8314: }
8315:
8316: my %usedCODEs;
8317:
1.194 albertel 8318: my %allcodes=&get_codes();
1.186 albertel 8319:
1.582 raeburn 8320: my $nav_error;
1.596.2.12.2. (raeburn 8321:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the lines per response array.
1.582 raeburn 8322: if ($nav_error) {
8323: $r->print(&navmap_errormsg());
8324: return(1,$currentphase);
8325: }
1.447 foxr 8326:
1.186 albertel 8327: my ($scanlines,$scan_data)=&scantron_getfile();
8328: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 8329: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.186 albertel 8330: if ($line=~/^[\s\cz]*$/) { next; }
8331: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
8332: $scan_data);
8333: my $CODE=$$scan_record{'scantron.CODE'};
8334: my $error=0;
1.224 albertel 8335: if (!&Apache::lonnet::validCODE($CODE)) {
8336: &scantron_get_correction($r,$i,$scan_record,
8337: \%scantron_config,
8338: $line,'incorrectCODE',\%allcodes);
8339: return(1,$currentphase);
8340: }
1.221 albertel 8341: if (%allcodes && !exists($allcodes{$CODE})
8342: && !$$scan_record{'scantron.useCODE'}) {
1.186 albertel 8343: &scantron_get_correction($r,$i,$scan_record,
8344: \%scantron_config,
1.194 albertel 8345: $line,'incorrectCODE',\%allcodes);
8346: return(1,$currentphase);
1.186 albertel 8347: }
1.214 albertel 8348: if (exists($usedCODEs{$CODE})
1.257 albertel 8349: && $env{'form.scantron_CODEunique'} eq 'yes'
1.192 albertel 8350: && !$$scan_record{'scantron.CODE_ignore_dup'}) {
1.186 albertel 8351: &scantron_get_correction($r,$i,$scan_record,
8352: \%scantron_config,
1.194 albertel 8353: $line,'duplicateCODE',$usedCODEs{$CODE});
8354: return(1,$currentphase);
1.186 albertel 8355: }
1.524 raeburn 8356: push(@{$usedCODEs{$CODE}},$$scan_record{'scantron.PaperID'});
1.186 albertel 8357: }
1.157 albertel 8358: return (0,$currentphase+1);
8359: }
8360:
1.423 albertel 8361: =pod
8362:
8363: =item scantron_validate_doublebubble
8364:
1.424 albertel 8365: Validates all scanlines in the selected file to not have any
8366: bubble lines with multiple bubbles marked.
8367:
1.423 albertel 8368: =cut
8369:
1.157 albertel 8370: sub scantron_validate_doublebubble {
8371: my ($r,$currentphase) = @_;
8372: #get student info
8373: my $classlist=&Apache::loncoursedata::get_classlist();
8374: my %idmap=&username_to_idmap($classlist);
1.596.2.12.2. 6(raebur 8375:3): my (undef,undef,$sequence)=
8376:3): &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.157 albertel 8377:
8378: #get scantron line setup
1.257 albertel 8379: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 8380: my ($scanlines,$scan_data)=&scantron_getfile();
1.596.2.12.2. 6(raebur 8381:3):
8382:3): my $navmap = Apache::lonnavmaps::navmap->new();
8383:3): unless (ref($navmap)) {
8384:3): $r->print(&navmap_errormsg());
8385:3): return(1,$currentphase);
8386:3): }
8387:3): my $map=$navmap->getResourceByUrl($sequence);
8388:3): my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
8389:3): my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
8390:3): %grader_randomlists_by_symb,%orderedforcode,%respnumlookup,%startline);
8391:3): my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
8392:3):
1.583 raeburn 8393: my $nav_error;
1.596.2.12.2. 6(raebur 8394:3): if (ref($map)) {
8395:3): $randomorder = $map->randomorder();
8396:3): $randompick = $map->randompick();
8397:3): if ($randomorder || $randompick) {
8398:3): $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource);
8399:3): if ($nav_error) {
8400:3): $r->print(&navmap_errormsg());
8401:3): return(1,$currentphase);
8402:3): }
8403:3): &graders_resources_pass(\@resources,\%grader_partids_by_symb,
8404:3): \%grader_randomlists_by_symb,$bubbles_per_row);
8405:3): }
8406:3): } else {
8407:3): $r->print(&navmap_errormsg());
8408:3): return(1,$currentphase);
8409:3): }
8410:3):
(raeburn 8411:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the bubble line array.
1.583 raeburn 8412: if ($nav_error) {
8413: $r->print(&navmap_errormsg());
8414: return(1,$currentphase);
8415: }
1.447 foxr 8416:
1.157 albertel 8417: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 8418: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 8419: if ($line=~/^[\s\cz]*$/) { next; }
8420: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
1.596.2.12.2. 6(raebur 8421:3): $scan_data,undef,\%idmap,$randomorder,
8422:3): $randompick,$sequence,\@master_seq,
8423:3): \%symb_to_resource,\%grader_partids_by_symb,
8424:3): \%orderedforcode,\%respnumlookup,\%startline);
1.157 albertel 8425: if (!defined($$scan_record{'scantron.doubleerror'})) { next; }
8426: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,$line,
8427: 'doublebubble',
1.596.2.12.2. 6(raebur 8428:3): $$scan_record{'scantron.doubleerror'},
8429:3): $randomorder,$randompick,\%respnumlookup,\%startline);
1.157 albertel 8430: return (1,$currentphase);
8431: }
8432: return (0,$currentphase+1);
8433: }
8434:
1.423 albertel 8435:
1.503 raeburn 8436: sub scantron_get_maxbubble {
1.596.2.12.2. (raeburn 8437:): my ($nav_error,$scantron_config) = @_;
1.257 albertel 8438: if (defined($env{'form.scantron_maxbubble'}) &&
8439: $env{'form.scantron_maxbubble'}) {
1.447 foxr 8440: &restore_bubble_lines();
1.257 albertel 8441: return $env{'form.scantron_maxbubble'};
1.191 albertel 8442: }
1.330 albertel 8443:
1.447 foxr 8444: my (undef, undef, $sequence) =
1.257 albertel 8445: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.330 albertel 8446:
1.447 foxr 8447: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 8448: unless (ref($navmap)) {
8449: if (ref($nav_error)) {
8450: $$nav_error = 1;
8451: }
1.591 raeburn 8452: return;
1.582 raeburn 8453: }
1.191 albertel 8454: my $map=$navmap->getResourceByUrl($sequence);
8455: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.596.2.12.2. (raeburn 8456:): my $bubbles_per_row = &bubblesheet_bubbles_per_row($scantron_config);
1.330 albertel 8457:
8458: &Apache::lonxml::clear_problem_counter();
8459:
1.557 raeburn 8460: my $uname = $env{'user.name'};
8461: my $udom = $env{'user.domain'};
1.435 foxr 8462: my $cid = $env{'request.course.id'};
8463: my $total_lines = 0;
8464: %bubble_lines_per_response = ();
1.447 foxr 8465: %first_bubble_line = ();
1.503 raeburn 8466: %subdivided_bubble_lines = ();
8467: %responsetype_per_response = ();
1.596.2.12.2. 6(raebur 8468:3): %masterseq_id_responsenum = ();
1.554 raeburn 8469:
1.447 foxr 8470: my $response_number = 0;
8471: my $bubble_line = 0;
1.191 albertel 8472: foreach my $resource (@resources) {
1.596.2.12.2. 6(raebur 8473:3): my $resid = $resource->id();
(raeburn 8474:): my ($analysis,$parts) = &scantron_partids_tograde($resource,$cid,$uname,
7(raebur 8475:3): $udom,undef,$bubbles_per_row);
1.542 raeburn 8476: if ((ref($analysis) eq 'HASH') && (ref($parts) eq 'ARRAY')) {
8477: foreach my $part_id (@{$parts}) {
8478: my $lines;
8479:
8480: # TODO - make this a persistent hash not an array.
8481:
8482: # optionresponse, matchresponse and rankresponse type items
8483: # render as separate sub-questions in exam mode.
8484: if (($analysis->{$part_id.'.type'} eq 'optionresponse') ||
8485: ($analysis->{$part_id.'.type'} eq 'matchresponse') ||
8486: ($analysis->{$part_id.'.type'} eq 'rankresponse')) {
8487: my ($numbub,$numshown);
8488: if ($analysis->{$part_id.'.type'} eq 'optionresponse') {
8489: if (ref($analysis->{$part_id.'.options'}) eq 'ARRAY') {
8490: $numbub = scalar(@{$analysis->{$part_id.'.options'}});
8491: }
8492: } elsif ($analysis->{$part_id.'.type'} eq 'matchresponse') {
8493: if (ref($analysis->{$part_id.'.items'}) eq 'ARRAY') {
8494: $numbub = scalar(@{$analysis->{$part_id.'.items'}});
8495: }
8496: } elsif ($analysis->{$part_id.'.type'} eq 'rankresponse') {
8497: if (ref($analysis->{$part_id.'.foils'}) eq 'ARRAY') {
8498: $numbub = scalar(@{$analysis->{$part_id.'.foils'}});
8499: }
8500: }
8501: if (ref($analysis->{$part_id.'.shown'}) eq 'ARRAY') {
8502: $numshown = scalar(@{$analysis->{$part_id.'.shown'}});
8503: }
1.596.2.12.2. (raeburn 8504:): my $bubbles_per_row =
8505:): &bubblesheet_bubbles_per_row($scantron_config);
8506:): my $inner_bubble_lines = int($numbub/$bubbles_per_row);
8507:): if (($numbub % $bubbles_per_row) != 0) {
1.542 raeburn 8508: $inner_bubble_lines++;
8509: }
8510: for (my $i=0; $i<$numshown; $i++) {
8511: $subdivided_bubble_lines{$response_number} .=
8512: $inner_bubble_lines.',';
8513: }
8514: $subdivided_bubble_lines{$response_number} =~ s/,$//;
8515: $lines = $numshown * $inner_bubble_lines;
8516: } else {
8517: $lines = $analysis->{"$part_id.bubble_lines"};
1.596.2.12.2. (raeburn 8518:): }
1.542 raeburn 8519:
8520: $first_bubble_line{$response_number} = $bubble_line;
8521: $bubble_lines_per_response{$response_number} = $lines;
8522: $responsetype_per_response{$response_number} =
8523: $analysis->{$part_id.'.type'};
1.596.2.12.2. 6(raebur 8524:3): $masterseq_id_responsenum{$resid.'_'.$part_id} = $response_number;
1.542 raeburn 8525: $response_number++;
8526:
8527: $bubble_line += $lines;
8528: $total_lines += $lines;
8529: }
8530: }
8531: }
1.552 raeburn 8532: &Apache::lonnet::delenv('scantron.');
1.542 raeburn 8533:
8534: &save_bubble_lines();
8535: $env{'form.scantron_maxbubble'} =
8536: $total_lines;
8537: return $env{'form.scantron_maxbubble'};
8538: }
1.523 raeburn 8539:
1.596.2.12.2. (raeburn 8540:): sub bubblesheet_bubbles_per_row {
8541:): my ($scantron_config) = @_;
8542:): my $bubbles_per_row;
8543:): if (ref($scantron_config) eq 'HASH') {
8544:): $bubbles_per_row = $scantron_config->{'BubblesPerRow'};
8545:): }
8546:): if ((!$bubbles_per_row) || ($bubbles_per_row < 1)) {
8547:): $bubbles_per_row = 10;
8548:): }
8549:): return $bubbles_per_row;
8550:): }
8551:):
1.157 albertel 8552: sub scantron_validate_missingbubbles {
8553: my ($r,$currentphase) = @_;
8554: #get student info
8555: my $classlist=&Apache::loncoursedata::get_classlist();
8556: my %idmap=&username_to_idmap($classlist);
1.596.2.12.2. 6(raebur 8557:3): my (undef,undef,$sequence)=
8558:3): &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.157 albertel 8559:
8560: #get scantron line setup
1.257 albertel 8561: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 8562: my ($scanlines,$scan_data)=&scantron_getfile();
1.596.2.12.2. 6(raebur 8563:3):
8564:3): my $navmap = Apache::lonnavmaps::navmap->new();
8565:3): unless (ref($navmap)) {
8566:3): $r->print(&navmap_errormsg());
8567:3): return(1,$currentphase);
8568:3): }
8569:3):
8570:3): my $map=$navmap->getResourceByUrl($sequence);
8571:3): my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
8572:3): my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
8573:3): %grader_randomlists_by_symb,%orderedforcode,%respnumlookup,%startline);
8574:3): my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
8575:3):
1.582 raeburn 8576: my $nav_error;
1.596.2.12.2. 6(raebur 8577:3): if (ref($map)) {
8578:3): $randomorder = $map->randomorder();
8579:3): $randompick = $map->randompick();
7(raebur 8580:3): if ($randomorder || $randompick) {
8581:3): $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource);
8582:3): if ($nav_error) {
8583:3): $r->print(&navmap_errormsg());
8584:3): return(1,$currentphase);
8585:3): }
8586:3): &graders_resources_pass(\@resources,\%grader_partids_by_symb,
8587:3): \%grader_randomlists_by_symb,$bubbles_per_row);
8588:3): }
6(raebur 8589:3): } else {
8590:3): $r->print(&navmap_errormsg());
7(raebur 8591:3): return(1,$currentphase);
6(raebur 8592:3): }
8593:3):
8594:3):
(raeburn 8595:): my $max_bubble=&scantron_get_maxbubble(\$nav_error,\%scantron_config);
1.582 raeburn 8596: if ($nav_error) {
1.596.2.12.2. 6(raebur 8597:3): $r->print(&navmap_errormsg());
1.582 raeburn 8598: return(1,$currentphase);
8599: }
1.596.2.12.2. 6(raebur 8600:3):
1.157 albertel 8601: if (!$max_bubble) { $max_bubble=2**31; }
8602: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 8603: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 8604: if ($line=~/^[\s\cz]*$/) { next; }
1.596.2.12.2. 6(raebur 8605:3): my $scan_record =
8606:3): &scantron_parse_scanline($line,$i,\%scantron_config,$scan_data,undef,\%idmap,
8607:3): $randomorder,$randompick,$sequence,\@master_seq,
8608:3): \%symb_to_resource,\%grader_partids_by_symb,
8609:3): \%orderedforcode,\%respnumlookup,\%startline);
1.157 albertel 8610: if (!defined($$scan_record{'scantron.missingerror'})) { next; }
8611: my @to_correct;
1.470 foxr 8612:
8613: # Probably here's where the error is...
8614:
1.157 albertel 8615: foreach my $missing (@{$$scan_record{'scantron.missingerror'}}) {
1.505 raeburn 8616: my $lastbubble;
8617: if ($missing =~ /^(\d+)\.(\d+)$/) {
1.596.2.12.2. 6(raebur 8618:3): my $question = $1;
8619:3): my $subquestion = $2;
8620:3): my ($first,$responsenum);
8621:3): if ($randomorder || $randompick) {
8622:3): $responsenum = $respnumlookup{$question-1};
8623:3): $first = $startline{$question-1};
8624:3): } else {
8625:3): $responsenum = $question-1;
8626:3): $first = $first_bubble_line{$responsenum};
8627:3): }
8628:3): if (!defined($first)) { next; }
7(raebur 8629:3): my @subans = split(/,/,$subdivided_bubble_lines{$responsenum});
6(raebur 8630:3): my $subcount = 1;
8631:3): while ($subcount<$subquestion) {
8632:3): $first += $subans[$subcount-1];
8633:3): $subcount ++;
8634:3): }
8635:3): my $count = $subans[$subquestion-1];
8636:3): $lastbubble = $first + $count;
1.505 raeburn 8637: } else {
1.596.2.12.2. 6(raebur 8638:3): my ($first,$responsenum);
8639:3): if ($randomorder || $randompick) {
8640:3): $responsenum = $respnumlookup{$missing-1};
8641:3): $first = $startline{$missing-1};
8642:3): } else {
8643:3): $responsenum = $missing-1;
8644:3): $first = $first_bubble_line{$responsenum};
8645:3): }
8646:3): if (!defined($first)) { next; }
8647:3): $lastbubble = $first + $bubble_lines_per_response{$responsenum};
1.505 raeburn 8648: }
8649: if ($lastbubble > $max_bubble) { next; }
1.157 albertel 8650: push(@to_correct,$missing);
8651: }
8652: if (@to_correct) {
8653: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
1.596.2.12.2. 6(raebur 8654:3): $line,'missingbubble',\@to_correct,
8655:3): $randomorder,$randompick,\%respnumlookup,
8656:3): \%startline);
1.157 albertel 8657: return (1,$currentphase);
8658: }
8659:
8660: }
8661: return (0,$currentphase+1);
8662: }
8663:
1.596.2.12.2. (raeburn 8664:): sub hand_bubble_option {
8665:): my (undef, undef, $sequence) =
8666:): &Apache::lonnet::decode_symb($env{'form.selectpage'});
8667:): return if ($sequence eq '');
8668:): my $navmap = Apache::lonnavmaps::navmap->new();
8669:): unless (ref($navmap)) {
8670:): return;
8671:): }
8672:): my $needs_hand_bubbles;
8673:): my $map=$navmap->getResourceByUrl($sequence);
8674:): my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
8675:): foreach my $res (@resources) {
8676:): if (ref($res)) {
8677:): if ($res->is_problem()) {
8678:): my $partlist = $res->parts();
8679:): foreach my $part (@{ $partlist }) {
8680:): my @types = $res->responseType($part);
8681:): if (grep(/^(chem|essay|image|formula|math|string|functionplot)$/,@types)) {
8682:): $needs_hand_bubbles = 1;
8683:): last;
8684:): }
8685:): }
8686:): }
8687:): }
8688:): }
8689:): if ($needs_hand_bubbles) {
8690:): my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
8691:): my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
8692:): return &mt('The sequence to be graded contains response types which are handgraded.').'<p>'.
8693:): &mt('If you have already graded these by bubbling sheets to indicate points awarded, [_1]what point value is assigned to a filled last bubble in each row?','<br />').
8694:): '<label><input type="radio" name="scantron_lastbubblepoints" value="'.$bubbles_per_row.'" checked="checked" />'.&mt('[quant,_1,point]',$bubbles_per_row).'</label> '.&mt('or').' '.
8(raebur 8695:4): '<label><input type="radio" name="scantron_lastbubblepoints" value="0" />'.&mt('0 points').'</label></p>';
(raeburn 8696:): }
8697:): return;
8698:): }
1.423 albertel 8699:
1.82 albertel 8700: sub scantron_process_students {
1.75 albertel 8701: my ($r) = @_;
1.513 foxr 8702:
1.257 albertel 8703: my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($env{'form.selectpage'});
1.324 albertel 8704: my ($symb)=&get_symb($r);
1.513 foxr 8705: if (!$symb) {
8706: return '';
8707: }
1.324 albertel 8708: my $default_form_data=&defaultFormData($symb);
1.82 albertel 8709:
1.257 albertel 8710: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.596.2.12.2. 6(raebur 8711:3): my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
1.157 albertel 8712: my ($scanlines,$scan_data)=&scantron_getfile();
1.82 albertel 8713: my $classlist=&Apache::loncoursedata::get_classlist();
8714: my %idmap=&username_to_idmap($classlist);
1.132 bowersj2 8715: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 8716: unless (ref($navmap)) {
8717: $r->print(&navmap_errormsg());
8718: return '';
1.596.2.12.2. 6(raebur 8719:3): }
1.83 albertel 8720: my $map=$navmap->getResourceByUrl($sequence);
1.596.2.12.2. 6(raebur 8721:3): my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
8722:3): %grader_randomlists_by_symb);
1(raebur 8723:2): if (ref($map)) {
8724:2): $randomorder = $map->randomorder();
6(raebur 8725:3): $randompick = $map->randompick();
8726:3): } else {
8727:3): $r->print(&navmap_errormsg());
8728:3): return '';
1(raebur 8729:2): }
6(raebur 8730:3): my $nav_error;
1.83 albertel 8731: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.596.2.12.2. 6(raebur 8732:3): if ($randomorder || $randompick) {
8733:3): $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource);
8734:3): if ($nav_error) {
8735:3): $r->print(&navmap_errormsg());
8736:3): return '';
1.586 raeburn 8737: }
8738: }
1.596.2.12.2. 6(raebur 8739:3): &graders_resources_pass(\@resources,\%grader_partids_by_symb,
8740:3): \%grader_randomlists_by_symb,$bubbles_per_row);
1.557 raeburn 8741:
1.554 raeburn 8742: my ($uname,$udom);
1.82 albertel 8743: my $result= <<SCANTRONFORM;
1.81 albertel 8744: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
8745: <input type="hidden" name="command" value="scantron_configphase" />
8746: $default_form_data
8747: SCANTRONFORM
1.82 albertel 8748: $r->print($result);
8749:
8750: my @delayqueue;
1.542 raeburn 8751: my (%completedstudents,%scandata);
1.140 albertel 8752:
1.520 www 8753: my $lock=&Apache::lonnet::set_lock(&mt('Grading bubblesheet exam'));
1.200 albertel 8754: my $count=&get_todo_count($scanlines,$scan_data);
1.596.2.12.2. (raeburn 8755:): my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$count);
1.140 albertel 8756: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
8757: 'Processing first student');
1.542 raeburn 8758: $r->print('<br />');
1.140 albertel 8759: my $start=&Time::HiRes::time();
1.158 albertel 8760: my $i=-1;
1.542 raeburn 8761: my $started;
1.447 foxr 8762:
1.596.2.12.2. (raeburn 8763:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # Need the bubble lines array to parse.
1.582 raeburn 8764: if ($nav_error) {
8765: $r->print(&navmap_errormsg());
8766: return '';
8767: }
8768:
1.513 foxr 8769: # If an ssi failed in scantron_get_maxbubble, put an error message out to
8770: # the user and return.
8771:
8772: if ($ssi_error) {
8773: $r->print("</form>");
8774: &ssi_print_error($r);
8775: $r->print(&show_grading_menu_form($symb));
1.520 www 8776: &Apache::lonnet::remove_lock($lock);
1.513 foxr 8777: return ''; # Dunno why the other returns return '' rather than just returning.
8778: }
1.447 foxr 8779:
1.542 raeburn 8780: my %lettdig = &letter_to_digits();
8781: my $numletts = scalar(keys(%lettdig));
1.596.2.12.2. 6(raebur 8782:3): my %orderedforcode;
1.542 raeburn 8783:
1.157 albertel 8784: while ($i<$scanlines->{'count'}) {
8785: ($uname,$udom)=('','');
8786: $i++;
1.200 albertel 8787: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 8788: if ($line=~/^[\s\cz]*$/) { next; }
1.200 albertel 8789: if ($started) {
8790: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
8791: 'last student');
8792: }
8793: $started=1;
1.596.2.12.2. 6(raebur 8794:3): my %respnumlookup = ();
8795:3): my %startline = ();
8796:3): my $total;
1.157 albertel 8797: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
1.596.2.12.2. 6(raebur 8798:3): $scan_data,undef,\%idmap,$randomorder,
8799:3): $randompick,$sequence,\@master_seq,
8800:3): \%symb_to_resource,\%grader_partids_by_symb,
8801:3): \%orderedforcode,\%respnumlookup,\%startline,
8802:3): \$total);
1.157 albertel 8803: unless ($uname=&scantron_find_student($scan_record,$scan_data,
8804: \%idmap,$i)) {
8805: &scantron_add_delay(\@delayqueue,$line,
8806: 'Unable to find a student that matches',1);
8807: next;
8808: }
8809: if (exists $completedstudents{$uname}) {
8810: &scantron_add_delay(\@delayqueue,$line,
8811: 'Student '.$uname.' has multiple sheets',2);
8812: next;
8813: }
1.596.2.12.2. 1(raebur 8814:2): my $usec = $classlist->{$uname}->[&Apache::loncoursedata::CL_SECTION];
8815:2): my $user = $uname.':'.$usec;
1.157 albertel 8816: ($uname,$udom)=split(/:/,$uname);
1.330 albertel 8817:
1.596.2.12.2. 1(raebur 8818:2): my $scancode;
8819:2): if ((exists($scan_record->{'scantron.CODE'})) &&
8820:2): (&Apache::lonnet::validCODE($scan_record->{'scantron.CODE'}))) {
8821:2): $scancode = $scan_record->{'scantron.CODE'};
8822:2): } else {
8823:2): $scancode = '';
8824:2): }
8825:2):
8826:2): my @mapresources = @resources;
6(raebur 8827:3): if ($randomorder || $randompick) {
1(raebur 8828:2): @mapresources =
6(raebur 8829:3): &users_order($user,$scancode,$sequence,\@master_seq,\%symb_to_resource,
8830:3): \%orderedforcode);
1(raebur 8831:2): }
1.586 raeburn 8832: my (%partids_by_symb,$res_error);
1.596.2.12.2. 1(raebur 8833:2): foreach my $resource (@mapresources) {
1.586 raeburn 8834: my $ressymb;
8835: if (ref($resource)) {
8836: $ressymb = $resource->symb();
8837: } else {
8838: $res_error = 1;
8839: last;
8840: }
1.557 raeburn 8841: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
8842: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
1.596.2.12.2. 1(raebur 8843:7): my $currcode;
8844:7): if (exists($grader_randomlists_by_symb{$ressymb})) {
8845:7): $currcode = $scancode;
8846:7): }
1.557 raeburn 8847: my ($analysis,$parts) =
1.596.2.12.2. (raeburn 8848:): &scantron_partids_tograde($resource,$env{'request.course.id'},
1(raebur 8849:7): $uname,$udom,undef,$bubbles_per_row,
8850:7): $currcode);
1.557 raeburn 8851: $partids_by_symb{$ressymb} = $parts;
8852: } else {
8853: $partids_by_symb{$ressymb} = $grader_partids_by_symb{$ressymb};
8854: }
1.554 raeburn 8855: }
8856:
1.586 raeburn 8857: if ($res_error) {
8858: &scantron_add_delay(\@delayqueue,$line,
8859: 'An error occurred while grading student '.$uname,2);
8860: next;
8861: }
8862:
1.330 albertel 8863: &Apache::lonxml::clear_problem_counter();
1.514 raeburn 8864: &Apache::lonnet::appenv($scan_record);
1.376 albertel 8865:
8866: if (&scantron_clear_skip($scanlines,$scan_data,$i)) {
8867: &scantron_putfile($scanlines,$scan_data);
8868: }
1.161 albertel 8869:
1.542 raeburn 8870: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
1.596.2.12.2. 1(raebur 8871:2): \@mapresources,\%partids_by_symb,
6(raebur 8872:3): $bubbles_per_row,$randomorder,$randompick,
8873:3): \%respnumlookup,\%startline)
8874:3): eq 'ssi_error') {
1.542 raeburn 8875: $ssi_error = 0; # So end of handler error message does not trigger.
8876: $r->print("</form>");
8877: &ssi_print_error($r);
8878: $r->print(&show_grading_menu_form($symb));
8879: &Apache::lonnet::remove_lock($lock);
8880: return ''; # Why return ''? Beats me.
8881: }
1.513 foxr 8882:
1.596.2.12.2. 6(raebur 8883:3): if (($scancode) && ($randomorder || $randompick)) {
8884:3): my $parmresult =
8885:3): &Apache::lonparmset::storeparm_by_symb($symb,
8886:3): '0_examcode',2,$scancode,
8887:3): 'string_examcode',$uname,
8888:3): $udom);
8889:3): }
1.140 albertel 8890: $completedstudents{$uname}={'line'=>$line};
1.542 raeburn 8891: if ($env{'form.verifyrecord'}) {
8892: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
1.596.2.12.2. 6(raebur 8893:3): if ($randompick) {
8894:3): if ($total) {
8895:3): $lastpos = $total*$scantron_config{'Qlength'};
8896:3): }
8897:3): }
8898:3):
1.542 raeburn 8899: my $studentdata = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
8900: chomp($studentdata);
8901: $studentdata =~ s/\r$//;
8902: my $studentrecord = '';
8903: my $counter = -1;
1.596.2.12.2. 1(raebur 8904:2): foreach my $resource (@mapresources) {
1.554 raeburn 8905: my $ressymb = $resource->symb();
1.542 raeburn 8906: ($counter,my $recording) =
8907: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 8908: $counter,$studentdata,$partids_by_symb{$ressymb},
1.596.2.12.2. 6(raebur 8909:3): \%scantron_config,\%lettdig,$numletts,$randomorder,
8910:3): $randompick,\%respnumlookup,\%startline);
1.542 raeburn 8911: $studentrecord .= $recording;
8912: }
8913: if ($studentrecord ne $studentdata) {
1.554 raeburn 8914: &Apache::lonxml::clear_problem_counter();
8915: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
1.596.2.12.2. 1(raebur 8916:2): \@mapresources,\%partids_by_symb,
6(raebur 8917:3): $bubbles_per_row,$randomorder,$randompick,
8918:3): \%respnumlookup,\%startline)
8919:3): eq 'ssi_error') {
1.554 raeburn 8920: $ssi_error = 0; # So end of handler error message does not trigger.
8921: $r->print("</form>");
8922: &ssi_print_error($r);
8923: $r->print(&show_grading_menu_form($symb));
8924: &Apache::lonnet::remove_lock($lock);
8925: delete($completedstudents{$uname});
8926: return '';
8927: }
1.542 raeburn 8928: $counter = -1;
8929: $studentrecord = '';
1.596.2.12.2. 1(raebur 8930:2): foreach my $resource (@mapresources) {
1.554 raeburn 8931: my $ressymb = $resource->symb();
1.542 raeburn 8932: ($counter,my $recording) =
8933: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 8934: $counter,$studentdata,$partids_by_symb{$ressymb},
1.596.2.12.2. 6(raebur 8935:3): \%scantron_config,\%lettdig,$numletts,
8936:3): $randomorder,$randompick,\%respnumlookup,
8937:3): \%startline);
1.542 raeburn 8938: $studentrecord .= $recording;
8939: }
8940: if ($studentrecord ne $studentdata) {
1.596.2.6 raeburn 8941: $r->print('<p><span class="LC_warning">');
1.542 raeburn 8942: if ($scancode eq '') {
1.596.2.6 raeburn 8943: $r->print(&mt('Mismatch grading bubblesheet for user: [_1] with ID: [_2].',
1.542 raeburn 8944: $uname.':'.$udom,$scan_record->{'scantron.ID'}));
8945: } else {
1.596.2.6 raeburn 8946: $r->print(&mt('Mismatch grading bubblesheet for user: [_1] with ID: [_2] and CODE: [_3].',
1.542 raeburn 8947: $uname.':'.$udom,$scan_record->{'scantron.ID'},$scancode));
8948: }
8949: $r->print('</span><br />'.&Apache::loncommon::start_data_table()."\n".
8950: &Apache::loncommon::start_data_table_header_row()."\n".
8951: '<th>'.&mt('Source').'</th><th>'.&mt('Bubbled responses').'</th>'.
8952: &Apache::loncommon::end_data_table_header_row()."\n".
8953: &Apache::loncommon::start_data_table_row().
1.596.2.6 raeburn 8954: '<td>'.&mt('Bubblesheet').'</td>'.
1.596.2.12.2. 4(raebur 8955:3): '<td><span class="LC_nobreak" style="white-space: pre;"><tt>'.$studentdata.'</tt></span></td>'.
1.542 raeburn 8956: &Apache::loncommon::end_data_table_row().
8957: &Apache::loncommon::start_data_table_row().
1.596.2.6 raeburn 8958: '<td>'.&mt('Stored submissions').'</td>'.
1.596.2.12.2. 4(raebur 8959:3): '<td><span class="LC_nobreak" style="white-space: pre;"><tt>'.$studentrecord.'</tt></span></td>'."\n".
1.542 raeburn 8960: &Apache::loncommon::end_data_table_row().
8961: &Apache::loncommon::end_data_table().'</p>');
8962: } else {
8963: $r->print('<br /><span class="LC_warning">'.
8964: &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 />'.
8965: &mt("As a consequence, this user's submission history records two tries.").
8966: '</span><br />');
8967: }
8968: }
8969: }
1.543 raeburn 8970: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.140 albertel 8971: } continue {
1.330 albertel 8972: &Apache::lonxml::clear_problem_counter();
1.552 raeburn 8973: &Apache::lonnet::delenv('scantron.');
1.82 albertel 8974: }
1.140 albertel 8975: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.520 www 8976: &Apache::lonnet::remove_lock($lock);
1.172 albertel 8977: # my $lasttime = &Time::HiRes::time()-$start;
8978: # $r->print("<p>took $lasttime</p>");
1.140 albertel 8979:
1.200 albertel 8980: $r->print("</form>");
1.324 albertel 8981: $r->print(&show_grading_menu_form($symb));
1.157 albertel 8982: return '';
1.75 albertel 8983: }
1.157 albertel 8984:
1.557 raeburn 8985: sub graders_resources_pass {
1.596.2.12.2. (raeburn 8986:): my ($resources,$grader_partids_by_symb,$grader_randomlists_by_symb,
8987:): $bubbles_per_row) = @_;
1.557 raeburn 8988: if ((ref($resources) eq 'ARRAY') && (ref($grader_partids_by_symb)) &&
8989: (ref($grader_randomlists_by_symb) eq 'HASH')) {
8990: foreach my $resource (@{$resources}) {
8991: my $ressymb = $resource->symb();
8992: my ($analysis,$parts) =
8993: &scantron_partids_tograde($resource,$env{'request.course.id'},
1.596.2.12.2. (raeburn 8994:): $env{'user.name'},$env{'user.domain'},
8995:): 1,$bubbles_per_row);
1.557 raeburn 8996: $grader_partids_by_symb->{$ressymb} = $parts;
8997: if (ref($analysis) eq 'HASH') {
8998: if (ref($analysis->{'parts_withrandomlist'}) eq 'ARRAY') {
8999: $grader_randomlists_by_symb->{$ressymb} =
9000: $analysis->{'parts_withrandomlist'};
9001: }
9002: }
9003: }
9004: }
9005: return;
9006: }
9007:
1.596.2.12.2. 1(raebur 9008:2): =pod
9009:2):
9010:2): =item users_order
9011:2):
9012:2): Returns array of resources in current map, ordered based on either CODE,
9013:2): if this is a CODEd exam, or based on student's identity if this is a
9014:2): "NAMEd" exam.
9015:2):
6(raebur 9016:3): Should be used when randomorder and/or randompick applied when the
9017:3): corresponding exam was printed, prior to students completing bubblesheets
9018:3): for the version of the exam the student received.
1(raebur 9019:2):
9020:2): =cut
9021:2):
9022:2): sub users_order {
6(raebur 9023:3): my ($user,$scancode,$mapurl,$master_seq,$symb_to_resource,$orderedforcode) = @_;
1(raebur 9024:2): my @mapresources;
6(raebur 9025:3): unless ((ref($master_seq) eq 'ARRAY') && (ref($symb_to_resource) eq 'HASH')) {
1(raebur 9026:2): return @mapresources;
9027:2): }
6(raebur 9028:3): if ($scancode) {
9029:3): if ((ref($orderedforcode) eq 'HASH') && (ref($orderedforcode->{$scancode}) eq 'ARRAY')) {
9030:3): @mapresources = @{$orderedforcode->{$scancode}};
9031:3): } else {
9032:3): $env{'form.CODE'} = $scancode;
9033:3): my $actual_seq =
9034:3): &Apache::lonprintout::master_seq_to_person_seq($mapurl,
9035:3): $master_seq,
9036:3): $user,$scancode,1);
9037:3): if (ref($actual_seq) eq 'ARRAY') {
9038:3): @mapresources = map { $symb_to_resource->{$_}; } @{$actual_seq};
9039:3): if (ref($orderedforcode) eq 'HASH') {
9040:3): if (@mapresources > 0) {
9041:3): $orderedforcode->{$scancode} = \@mapresources;
9042:3): }
9043:3): }
9044:3): }
9045:3): delete($env{'form.CODE'});
1(raebur 9046:2): }
9047:2): } else {
9048:2): my $actual_seq =
9049:2): &Apache::lonprintout::master_seq_to_person_seq($mapurl,
9050:2): $master_seq,
5(raebur 9051:3): $user,undef,1);
1(raebur 9052:2): if (ref($actual_seq) eq 'ARRAY') {
9053:2): @mapresources =
9054:2): map { $symb_to_resource->{$_}; } @{$actual_seq};
9055:2): }
6(raebur 9056:3): }
9057:3): return @mapresources;
1(raebur 9058:2): }
9059:2):
1.542 raeburn 9060: sub grade_student_bubbles {
1.596.2.12.2. 6(raebur 9061:3): my ($r,$uname,$udom,$scan_record,$scancode,$resources,$parts,$bubbles_per_row,
9062:3): $randomorder,$randompick,$respnumlookup,$startline) = @_;
9063:3): my $uselookup = 0;
9064:3): if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH') &&
9065:3): (ref($startline) eq 'HASH')) {
9066:3): $uselookup = 1;
9067:3): }
9068:3):
1.554 raeburn 9069: if (ref($resources) eq 'ARRAY') {
9070: my $count = 0;
9071: foreach my $resource (@{$resources}) {
9072: my $ressymb = $resource->symb();
9073: my %form = ('submitted' => 'scantron',
9074: 'grade_target' => 'grade',
9075: 'grade_username' => $uname,
9076: 'grade_domain' => $udom,
9077: 'grade_courseid' => $env{'request.course.id'},
9078: 'grade_symb' => $ressymb,
9079: 'CODE' => $scancode
9080: );
1.596.2.12.2. (raeburn 9081:): if ($bubbles_per_row ne '') {
9082:): $form{'bubbles_per_row'} = $bubbles_per_row;
9083:): }
9084:): if ($env{'form.scantron_lastbubblepoints'} ne '') {
9085:): $form{'scantron_lastbubblepoints'} = $env{'form.scantron_lastbubblepoints'};
9086:): }
1.554 raeburn 9087: if (ref($parts) eq 'HASH') {
9088: if (ref($parts->{$ressymb}) eq 'ARRAY') {
9089: foreach my $part (@{$parts->{$ressymb}}) {
1.596.2.12.2. 6(raebur 9090:3): if ($uselookup) {
9091:3): $form{'scantron_questnum_start.'.$part} = $startline->{$count} + 1;
9092:3): } else {
9093:3): $form{'scantron_questnum_start.'.$part} =
9094:3): 1+$env{'form.scantron.first_bubble_line.'.$count};
9095:3): }
1.554 raeburn 9096: $count++;
9097: }
9098: }
9099: }
9100: my $result=&ssi_with_retries($resource->src(),$ssi_retries,%form);
9101: return 'ssi_error' if ($ssi_error);
9102: last if (&Apache::loncommon::connection_aborted($r));
9103: }
1.542 raeburn 9104: }
9105: return;
9106: }
9107:
1.157 albertel 9108: sub scantron_upload_scantron_data {
9109: my ($r)=@_;
1.565 raeburn 9110: my $dom = $env{'request.role.domain'};
9111: my $domdesc = &Apache::lonnet::domain($dom,'description');
9112: $r->print(&Apache::loncommon::coursebrowser_javascript($dom));
1.157 albertel 9113: my $select_link=&Apache::loncommon::selectcourse_link('rules','courseid',
1.181 albertel 9114: 'domainid',
1.565 raeburn 9115: 'coursename',$dom);
9116: my $syllabuslink = '<a href="javascript:ToSyllabus();">'.&mt('Syllabus').'</a>'.
1.596.2.12.2. (raeburn 9117:): (' 'x2).&mt('(shows course personnel)');
9118:): my ($symb) = &get_symb($r,1);
9119:): my $default_form_data=&defaultFormData($symb);
1.579 raeburn 9120: my $nofile_alert = &mt('Please use the browse button to select a file from your local directory.');
1.596.2.12.2. 7(raebur 9121:6): &js_escape(\$nofile_alert);
1.579 raeburn 9122: 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.596.2.12.2. 6(raebur 9123:6): &js_escape(\$nocourseid_alert);
1.492 albertel 9124: $r->print('
1.157 albertel 9125: <script type="text/javascript" language="javascript">
9126: function checkUpload(formname) {
9127: if (formname.upfile.value == "") {
1.579 raeburn 9128: alert("'.$nofile_alert.'");
1.157 albertel 9129: return false;
9130: }
1.565 raeburn 9131: if (formname.courseid.value == "") {
1.579 raeburn 9132: alert("'.$nocourseid_alert.'");
1.565 raeburn 9133: return false;
9134: }
1.157 albertel 9135: formname.submit();
9136: }
1.565 raeburn 9137:
9138: function ToSyllabus() {
9139: var cdom = '."'$dom'".';
9140: var cnum = document.rules.courseid.value;
9141: if (cdom == "" || cdom == null) {
9142: return;
9143: }
9144: if (cnum == "" || cnum == null) {
9145: return;
9146: }
9147: syllwin=window.open("/public/"+cdom+"/"+cnum+"/syllabus","LONCAPASyllabus",
9148: "height=350,width=350,scrollbars=yes,menubar=no");
9149: return;
9150: }
9151:
1.157 albertel 9152: </script>
9153:
1.596.2.4 raeburn 9154: <h3>'.&mt('Send bubblesheet data to a course').'</h3>
1.566 raeburn 9155:
1.492 albertel 9156: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
1.565 raeburn 9157: '.$default_form_data.
9158: &Apache::lonhtmlcommon::start_pick_box().
9159: &Apache::lonhtmlcommon::row_title(&mt('Course ID')).
9160: '<input name="courseid" type="text" size="30" />'.$select_link.
9161: &Apache::lonhtmlcommon::row_closure().
9162: &Apache::lonhtmlcommon::row_title(&mt('Course Name')).
9163: '<input name="coursename" type="text" size="30" />'.$syllabuslink.
9164: &Apache::lonhtmlcommon::row_closure().
9165: &Apache::lonhtmlcommon::row_title(&mt('Domain')).
9166: '<input name="domainid" type="hidden" />'.$domdesc.
9167: &Apache::lonhtmlcommon::row_closure().
9168: &Apache::lonhtmlcommon::row_title(&mt('File to upload')).
9169: '<input type="file" name="upfile" size="50" />'.
9170: &Apache::lonhtmlcommon::row_closure(1).
9171: &Apache::lonhtmlcommon::end_pick_box().'<br />
9172:
1.492 albertel 9173: <input name="command" value="scantronupload_save" type="hidden" />
1.589 bisitz 9174: <input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
1.157 albertel 9175: </form>
1.492 albertel 9176: ');
1.157 albertel 9177: return '';
9178: }
9179:
1.423 albertel 9180:
1.157 albertel 9181: sub scantron_upload_scantron_data_save {
9182: my($r)=@_;
1.324 albertel 9183: my ($symb)=&get_symb($r,1);
1.182 albertel 9184: my $doanotherupload=
9185: '<br /><form action="/adm/grades" method="post">'."\n".
9186: '<input type="hidden" name="command" value="scantronupload" />'."\n".
1.492 albertel 9187: '<input type="submit" name="submit" value="'.&mt('Do Another Upload').'" />'."\n".
1.182 albertel 9188: '</form>'."\n";
1.257 albertel 9189: if (!&Apache::lonnet::allowed('usc',$env{'form.domainid'}) &&
1.162 albertel 9190: !&Apache::lonnet::allowed('usc',
1.257 albertel 9191: $env{'form.domainid'}.'_'.$env{'form.courseid'})) {
1.575 www 9192: $r->print(&mt("You are not allowed to upload bubblesheet data to the requested course.")."<br />");
1.182 albertel 9193: if ($symb) {
1.324 albertel 9194: $r->print(&show_grading_menu_form($symb));
1.182 albertel 9195: } else {
9196: $r->print($doanotherupload);
9197: }
1.162 albertel 9198: return '';
9199: }
1.257 albertel 9200: my %coursedata=&Apache::lonnet::coursedescription($env{'form.domainid'}.'_'.$env{'form.courseid'});
1.568 raeburn 9201: my $uploadedfile;
1.596.2.12.2. 5(raebur 9202:3): $r->print('<p>'.&mt("Uploading file to [_1]",$coursedata{'description'}).'</p>');
1.257 albertel 9203: if (length($env{'form.upfile'}) < 2) {
1.596.2.12.2. 5(raebur 9204:3): $r->print(
9205:3): &Apache::lonhtmlcommon::confirm_success(
9206:3): &mt('The file: [_1] you attempted to upload contained no information. Please check that you entered the correct filename.',
9207:3): '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'),1));
1.183 albertel 9208: } else {
1.568 raeburn 9209: my $result =
9210: &Apache::lonnet::userfileupload('upfile','','scantron','','','',
9211: $env{'form.courseid'},$env{'form.domainid'});
9212: if ($result =~ m{^/uploaded/}) {
1.596.2.12.2. 5(raebur 9213:3): $r->print(
9214:3): &Apache::lonhtmlcommon::confirm_success(&mt('Upload successful')).'<br />'.
9215:3): &mt('Uploaded [_1] bytes of data into location: [_2]',
9216:3): (length($env{'form.upfile'})-1),
9217:3): '<span class="LC_filename">'.$result.'</span>'));
1.568 raeburn 9218: ($uploadedfile) = ($result =~ m{/([^/]+)$});
1.567 raeburn 9219: $r->print(&validate_uploaded_scantron_file($env{'form.domainid'},
1.568 raeburn 9220: $env{'form.courseid'},$uploadedfile));
1.210 albertel 9221: } else {
1.596.2.12.2. 5(raebur 9222:3): $r->print(
9223:3): &Apache::lonhtmlcommon::confirm_success(&mt('Upload failed'),1).'<br />'.
9224:3): &mt('An error ([_1]) occurred when attempting to upload the file: [_2]',
9225:3): $result,
1.568 raeburn 9226: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'));
1.183 albertel 9227: }
9228: }
1.174 albertel 9229: if ($symb) {
1.209 ng 9230: $r->print(&scantron_selectphase($r,$uploadedfile));
1.174 albertel 9231: } else {
1.182 albertel 9232: $r->print($doanotherupload);
1.174 albertel 9233: }
1.157 albertel 9234: return '';
9235: }
9236:
1.567 raeburn 9237: sub validate_uploaded_scantron_file {
9238: my ($cdom,$cname,$fname) = @_;
9239: my $scanlines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.$fname);
9240: my @lines;
9241: if ($scanlines ne '-1') {
9242: @lines=split("\n",$scanlines,-1);
9243: }
9244: my $output;
9245: if (@lines) {
9246: my (%counts,$max_match_format);
1.596.2.12.2. 5(raebur 9247:3): my ($found_match_count,$max_match_count,$max_match_pct) = (0,0,0);
1.567 raeburn 9248: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cname);
9249: my %idmap = &username_to_idmap($classlist);
9250: foreach my $key (keys(%idmap)) {
9251: my $lckey = lc($key);
9252: $idmap{$lckey} = $idmap{$key};
9253: }
9254: my %unique_formats;
9255: my @formatlines = &get_scantronformat_file();
9256: foreach my $line (@formatlines) {
9257: chomp($line);
9258: my @config = split(/:/,$line);
9259: my $idstart = $config[5];
9260: my $idlength = $config[6];
9261: if (($idstart ne '') && ($idlength > 0)) {
9262: if (ref($unique_formats{$idstart.':'.$idlength}) eq 'ARRAY') {
9263: push(@{$unique_formats{$idstart.':'.$idlength}},$config[0].':'.$config[1]);
9264: } else {
9265: $unique_formats{$idstart.':'.$idlength} = [$config[0].':'.$config[1]];
9266: }
9267: }
9268: }
9269: foreach my $key (keys(%unique_formats)) {
9270: my ($idstart,$idlength) = split(':',$key);
9271: %{$counts{$key}} = (
9272: 'found' => 0,
9273: 'total' => 0,
9274: );
9275: foreach my $line (@lines) {
9276: next if ($line =~ /^#/);
9277: next if ($line =~ /^[\s\cz]*$/);
9278: my $id = substr($line,$idstart-1,$idlength);
9279: $id = lc($id);
9280: if (exists($idmap{$id})) {
9281: $counts{$key}{'found'} ++;
9282: }
9283: $counts{$key}{'total'} ++;
9284: }
9285: if ($counts{$key}{'total'}) {
9286: my $percent_match = (100*$counts{$key}{'found'})/($counts{$key}{'total'});
9287: if (($max_match_format eq '') || ($percent_match > $max_match_pct)) {
9288: $max_match_pct = $percent_match;
9289: $max_match_format = $key;
1.596.2.12.2. 5(raebur 9290:3): $found_match_count = $counts{$key}{'found'};
1.567 raeburn 9291: $max_match_count = $counts{$key}{'total'};
9292: }
9293: }
9294: }
9295: if (ref($unique_formats{$max_match_format}) eq 'ARRAY') {
9296: my $format_descs;
9297: my $numwithformat = @{$unique_formats{$max_match_format}};
9298: for (my $i=0; $i<$numwithformat; $i++) {
9299: my ($name,$desc) = split(':',$unique_formats{$max_match_format}[$i]);
9300: if ($i<$numwithformat-2) {
9301: $format_descs .= '"<i>'.$desc.'</i>", ';
9302: } elsif ($i==$numwithformat-2) {
9303: $format_descs .= '"<i>'.$desc.'</i>" '.&mt('and').' ';
9304: } elsif ($i==$numwithformat-1) {
9305: $format_descs .= '"<i>'.$desc.'</i>"';
9306: }
9307: }
9308: my $showpct = sprintf("%.0f",$max_match_pct).'%';
1.596.2.12.2. 5(raebur 9309:3): $output .= '<br />';
9310:3): if ($found_match_count == $max_match_count) {
9311:3): # 100% matching entries
9312:3): $output .= &Apache::lonhtmlcommon::confirm_success(
9313:3): &mt('Comparison of student IDs: [_1] matching ([quant,_2,entry,entries])',
9314:3): '<b>'.$showpct.'</b>',$found_match_count)).'<br />'.
9315:3): &mt('Comparison of student IDs in the uploaded file with'.
9316:3): ' the course roster found matches for [_1] of the [_2] entries'.
9317:3): ' in the file (for the format defined for [_3]).',
9318:3): '<b>'.$showpct.'</b>','<b>'.$max_match_count.'</b>',$format_descs);
9319:3): } else {
9320:3): # Not all entries matching? -> Show warning and additional info
9321:3): $output .=
9322:3): &Apache::lonhtmlcommon::confirm_success(
9323:3): &mt('Comparison of student IDs: [_1] matching ([_2]/[quant,_3,entry,entries])',
9324:3): '<b>'.$showpct.'</b>',$found_match_count,$max_match_count).'<br />'.
9325:3): &mt('Not all entries could be matched!'),1).'<br />'.
9326:3): &mt('Comparison of student IDs in the uploaded file with'.
9327:3): ' the course roster found matches for [_1] of the [_2] entries'.
9328:3): ' in the file (for the format defined for [_3]).',
9329:3): '<b>'.$showpct.'</b>','<b>'.$max_match_count.'</b>',$format_descs).
9330:3): '<p class="LC_info">'.
9331:3): &mt('A low percentage of matches results from one of the following:').
9332:3): '</p><ul>'.
9333:3): '<li>'.&mt('The file was uploaded to the wrong course.').'</li>'.
9334:3): '<li>'.&mt('The data is not in the format expected for the domain: [_1]',
9335:3): '<i>'.$cdom.'</i>').'</li>'.
9336:3): '<li>'.&mt('Students did not bubble their IDs, or mis-bubbled them').'</li>'.
9337:3): '<li>'.&mt('The course roster is not up to date.').'</li>'.
9338:3): '</ul>';
9339:3): }
1.567 raeburn 9340: }
9341: } else {
1.596.2.12.2. 5(raebur 9342:3): $output = '<p class="LC_warning">'.&mt('Uploaded file contained no data').'</p>';
1.567 raeburn 9343: }
9344: return $output;
9345: }
9346:
1.202 albertel 9347: sub valid_file {
9348: my ($requested_file)=@_;
9349: foreach my $filename (sort(&scantron_filenames())) {
9350: if ($requested_file eq $filename) { return 1; }
9351: }
9352: return 0;
9353: }
9354:
9355: sub scantron_download_scantron_data {
9356: my ($r)=@_;
1.596.2.12.2. (raeburn 9357:): my ($symb) = &get_symb($r,1);
9358:): my $default_form_data=&defaultFormData($symb);
1.257 albertel 9359: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
9360: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
9361: my $file=$env{'form.scantron_selectfile'};
1.202 albertel 9362: if (! &valid_file($file)) {
1.492 albertel 9363: $r->print('
1.202 albertel 9364: <p>
1.596.2.12.2. 3(raebur 9365:3): '.&mt('The requested filename was invalid.').'
1.202 albertel 9366: </p>
1.492 albertel 9367: ');
1.596.2.12.2. (raeburn 9368:): $r->print(&show_grading_menu_form($symb));
1.202 albertel 9369: return;
9370: }
9371: my $orig='/uploaded/'.$cdom.'/'.$cname.'/scantron_orig_'.$file;
9372: my $corrected='/uploaded/'.$cdom.'/'.$cname.'/scantron_corrected_'.$file;
9373: my $skipped='/uploaded/'.$cdom.'/'.$cname.'/scantron_skipped_'.$file;
9374: &Apache::lonnet::allowuploaded('/adm/grades',$orig);
9375: &Apache::lonnet::allowuploaded('/adm/grades',$corrected);
9376: &Apache::lonnet::allowuploaded('/adm/grades',$skipped);
1.492 albertel 9377: $r->print('
1.202 albertel 9378: <p>
1.596.2.12.2. 8(raebur 9379:4): '.&mt('[_1]Original[_2] file as uploaded by bubblesheet scanning office.',
1.492 albertel 9380: '<a href="'.$orig.'">','</a>').'
1.202 albertel 9381: </p>
9382: <p>
1.492 albertel 9383: '.&mt('[_1]Corrections[_2], a file of corrected records that were used in grading.',
9384: '<a href="'.$corrected.'">','</a>').'
1.202 albertel 9385: </p>
9386: <p>
1.492 albertel 9387: '.&mt('[_1]Skipped[_2], a file of records that were skipped.',
9388: '<a href="'.$skipped.'">','</a>').'
1.202 albertel 9389: </p>
1.492 albertel 9390: ');
1.596.2.12.2. (raeburn 9391:): $r->print(&show_grading_menu_form($symb));
1.202 albertel 9392: return '';
9393: }
1.157 albertel 9394:
1.523 raeburn 9395: sub checkscantron_results {
9396: my ($r) = @_;
9397: my ($symb)=&get_symb($r);
9398: if (!$symb) {return '';}
9399: my $grading_menu_button=&show_grading_menu_form($symb);
9400: my $cid = $env{'request.course.id'};
1.542 raeburn 9401: my %lettdig = &letter_to_digits();
1.523 raeburn 9402: my $numletts = scalar(keys(%lettdig));
9403: my $cnum = $env{'course.'.$cid.'.num'};
9404: my $cdom = $env{'course.'.$cid.'.domain'};
9405: my (undef, undef, $sequence) = &Apache::lonnet::decode_symb($env{'form.selectpage'});
9406: my %record;
9407: my %scantron_config =
9408: &Apache::grades::get_scantron_config($env{'form.scantron_format'});
1.596.2.12.2. (raeburn 9409:): my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
1.523 raeburn 9410: my ($scanlines,$scan_data)=&Apache::grades::scantron_getfile();
9411: my $classlist=&Apache::loncoursedata::get_classlist();
9412: my %idmap=&Apache::grades::username_to_idmap($classlist);
9413: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 9414: unless (ref($navmap)) {
9415: $r->print(&navmap_errormsg());
9416: return '';
9417: }
1.523 raeburn 9418: my $map=$navmap->getResourceByUrl($sequence);
1.596.2.12.2. 6(raebur 9419:3): my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
9420:3): %grader_randomlists_by_symb,%orderedforcode);
1(raebur 9421:2): if (ref($map)) {
9422:2): $randomorder=$map->randomorder();
7(raebur 9423:3): $randompick=$map->randompick();
1(raebur 9424:2): }
1.557 raeburn 9425: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.596.2.12.2. 6(raebur 9426:3): my $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource);
9427:3): if ($nav_error) {
9428:3): $r->print(&navmap_errormsg());
9429:3): return '';
1(raebur 9430:2): }
(raeburn 9431:): &graders_resources_pass(\@resources,\%grader_partids_by_symb,
9432:): \%grader_randomlists_by_symb,$bubbles_per_row);
1.554 raeburn 9433: my ($uname,$udom);
1.523 raeburn 9434: my (%scandata,%lastname,%bylast);
9435: $r->print('
9436: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="checkscantron">'."\n");
9437:
9438: my @delayqueue;
9439: my %completedstudents;
9440:
1.596.2.12.2. 6(raebur 9441:3): my $count=&get_todo_count($scanlines,$scan_data);
(raeburn 9442:): my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$count);
6(raebur 9443:3): my ($username,$domain,$started);
(raeburn 9444:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # Need the bubble lines array to parse.
1.582 raeburn 9445: if ($nav_error) {
9446: $r->print(&navmap_errormsg());
9447: return '';
9448: }
1.523 raeburn 9449:
9450: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
9451: 'Processing first student');
9452: my $start=&Time::HiRes::time();
9453: my $i=-1;
9454:
9455: while ($i<$scanlines->{'count'}) {
9456: ($username,$domain,$uname)=('','','');
9457: $i++;
9458: my $line=&Apache::grades::scantron_get_line($scanlines,$scan_data,$i);
9459: if ($line=~/^[\s\cz]*$/) { next; }
9460: if ($started) {
9461: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
9462: 'last student');
9463: }
9464: $started=1;
9465: my $scan_record=
9466: &Apache::grades::scantron_parse_scanline($line,$i,\%scantron_config,
9467: $scan_data);
1.596.2.12.2. 6(raebur 9468:3): unless ($uname=&scantron_find_student($scan_record,$scan_data,
9469:3): \%idmap,$i)) {
1.523 raeburn 9470: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
9471: 'Unable to find a student that matches',1);
9472: next;
9473: }
9474: if (exists $completedstudents{$uname}) {
9475: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
9476: 'Student '.$uname.' has multiple sheets',2);
9477: next;
9478: }
9479: my $pid = $scan_record->{'scantron.ID'};
9480: $lastname{$pid} = $scan_record->{'scantron.LastName'};
9481: push(@{$bylast{$lastname{$pid}}},$pid);
1.596.2.12.2. 1(raebur 9482:2): my $usec = $classlist->{$uname}->[&Apache::loncoursedata::CL_SECTION];
9483:2): my $user = $uname.':'.$usec;
1.523 raeburn 9484: ($username,$domain)=split(/:/,$uname);
1.596.2.12.2. 1(raebur 9485:2):
9486:2): my $scancode;
9487:2): if ((exists($scan_record->{'scantron.CODE'})) &&
9488:2): (&Apache::lonnet::validCODE($scan_record->{'scantron.CODE'}))) {
9489:2): $scancode = $scan_record->{'scantron.CODE'};
9490:2): } else {
9491:2): $scancode = '';
9492:2): }
9493:2):
9494:2): my @mapresources = @resources;
6(raebur 9495:3): my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
9496:3): my %respnumlookup=();
9497:3): my %startline=();
9498:3): if ($randomorder || $randompick) {
1(raebur 9499:2): @mapresources =
6(raebur 9500:3): &users_order($user,$scancode,$sequence,\@master_seq,\%symb_to_resource,
9501:3): \%orderedforcode);
9502:3): my $total = &get_respnum_lookups($sequence,$scan_data,\%idmap,$line,
9503:3): $scan_record,\@master_seq,\%symb_to_resource,
9504:3): \%grader_partids_by_symb,\%orderedforcode,
9505:3): \%respnumlookup,\%startline);
9506:3): if ($randompick && $total) {
9507:3): $lastpos = $total*$scantron_config{'Qlength'};
9508:3): }
1(raebur 9509:2): }
6(raebur 9510:3): $scandata{$pid} = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
9511:3): chomp($scandata{$pid});
9512:3): $scandata{$pid} =~ s/\r$//;
9513:3):
1.523 raeburn 9514: my $counter = -1;
1.596.2.12.2. 1(raebur 9515:2): foreach my $resource (@mapresources) {
1.557 raeburn 9516: my $parts;
1.554 raeburn 9517: my $ressymb = $resource->symb();
1.557 raeburn 9518: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
9519: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
1.596.2.12.2. 1(raebur 9520:7): my $currcode;
9521:7): if (exists($grader_randomlists_by_symb{$ressymb})) {
9522:7): $currcode = $scancode;
9523:7): }
1.557 raeburn 9524: (my $analysis,$parts) =
1.596.2.12.2. (raeburn 9525:): &scantron_partids_tograde($resource,$env{'request.course.id'},
9526:): $username,$domain,undef,
1(raebur 9527:7): $bubbles_per_row,$currcode);
1.557 raeburn 9528: } else {
9529: $parts = $grader_partids_by_symb{$ressymb};
9530: }
1.542 raeburn 9531: ($counter,my $recording) =
9532: &verify_scantron_grading($resource,$domain,$username,$cid,$counter,
1.554 raeburn 9533: $scandata{$pid},$parts,
1.596.2.12.2. 6(raebur 9534:3): \%scantron_config,\%lettdig,$numletts,
9535:3): $randomorder,$randompick,
9536:3): \%respnumlookup,\%startline);
1.542 raeburn 9537: $record{$pid} .= $recording;
1.523 raeburn 9538: }
9539: }
9540: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
9541: $r->print('<br />');
9542: my ($okstudents,$badstudents,$numstudents,$passed,$failed);
9543: $passed = 0;
9544: $failed = 0;
9545: $numstudents = 0;
9546: foreach my $last (sort(keys(%bylast))) {
9547: if (ref($bylast{$last}) eq 'ARRAY') {
9548: foreach my $pid (sort(@{$bylast{$last}})) {
9549: my $showscandata = $scandata{$pid};
9550: my $showrecord = $record{$pid};
9551: $showscandata =~ s/\s/ /g;
9552: $showrecord =~ s/\s/ /g;
9553: if ($scandata{$pid} eq $record{$pid}) {
9554: my $css_class = ($passed % 2)?'LC_odd_row':'LC_even_row';
9555: $okstudents .= '<tr class="'.$css_class.'">'.
1.581 www 9556: '<td>'.&mt('Bubblesheet').'</td><td>'.$showscandata.'</td><td rowspan="2">'.$last.'</td><td rowspan="2">'.$pid.'</td>'."\n".
1.523 raeburn 9557: '</tr>'."\n".
9558: '<tr class="'.$css_class.'">'."\n".
1.596.2.12.2. 8(raebur 9559:4): '<td>'.&mt('Submissions').'</td><td>'.$showrecord.'</td></tr>'."\n";
1.523 raeburn 9560: $passed ++;
9561: } else {
9562: my $css_class = ($failed % 2)?'LC_odd_row':'LC_even_row';
1.581 www 9563: $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 9564: '</tr>'."\n".
9565: '<tr class="'.$css_class.'">'."\n".
1.596.2.12.2. 8(raebur 9566:4): '<td>'.&mt('Submissions').'</td><td><span class="LC_nobreak">'.$record{$pid}.'</span></td>'."\n".
1.523 raeburn 9567: '</tr>'."\n";
9568: $failed ++;
9569: }
9570: $numstudents ++;
9571: }
9572: }
9573: }
1.596.2.4 raeburn 9574: $r->print('<p>'.
1.596.2.8 raeburn 9575: &mt('Comparison of bubblesheet data (including corrections) with corresponding submission records (most recent submission) for [_1][quant,_2,student][_3] ([quant,_4,bubblesheet line] per student).',
1.596.2.4 raeburn 9576: '<b>',
9577: $numstudents,
9578: '</b>',
9579: $env{'form.scantron_maxbubble'}).
9580: '</p>'
9581: );
1.596.2.12.2. 2(raebur 9582:2): $r->print('<p>'
9583:2): .&mt('Exact matches for [_1][quant,_2,student][_3].','<b>',$passed,'</b>')
9584:2): .'<br />'
9585:2): .&mt('Discrepancies detected for [_1][quant,_2,student][_3].','<b>',$failed,'</b>')
9586:2): .'</p>');
1.523 raeburn 9587: if ($passed) {
1.572 www 9588: $r->print(&mt('Students with exact correspondence between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 9589: $r->print(&Apache::loncommon::start_data_table()."\n".
9590: &Apache::loncommon::start_data_table_header_row()."\n".
9591: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
9592: &Apache::loncommon::end_data_table_header_row()."\n".
9593: $okstudents."\n".
9594: &Apache::loncommon::end_data_table().'<br />');
9595: }
9596: if ($failed) {
1.572 www 9597: $r->print(&mt('Students with differences between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 9598: $r->print(&Apache::loncommon::start_data_table()."\n".
9599: &Apache::loncommon::start_data_table_header_row()."\n".
9600: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
9601: &Apache::loncommon::end_data_table_header_row()."\n".
9602: $badstudents."\n".
9603: &Apache::loncommon::end_data_table()).'<br />'.
1.572 www 9604: &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 9605: }
9606: $r->print('</form><br />'.$grading_menu_button);
9607: return;
9608: }
9609:
1.542 raeburn 9610: sub verify_scantron_grading {
1.554 raeburn 9611: my ($resource,$domain,$username,$cid,$counter,$scandata,$partids,
1.596.2.12.2. 6(raebur 9612:3): $scantron_config,$lettdig,$numletts,$randomorder,$randompick,
9613:3): $respnumlookup,$startline) = @_;
1.542 raeburn 9614: my ($record,%expected,%startpos);
9615: return ($counter,$record) if (!ref($resource));
9616: return ($counter,$record) if (!$resource->is_problem());
9617: my $symb = $resource->symb();
1.554 raeburn 9618: return ($counter,$record) if (ref($partids) ne 'ARRAY');
9619: foreach my $part_id (@{$partids}) {
1.542 raeburn 9620: $counter ++;
9621: $expected{$part_id} = 0;
1.596.2.12.2. 6(raebur 9622:3): my $respnum = $counter;
9623:3): if ($randomorder || $randompick) {
9624:3): $respnum = $respnumlookup->{$counter};
9625:3): $startpos{$part_id} = $startline->{$counter} + 1;
9626:3): } else {
9627:3): $startpos{$part_id} = $env{"form.scantron.first_bubble_line.$counter"};
9628:3): }
9629:3): if ($env{"form.scantron.sub_bubblelines.$respnum"}) {
9630:3): my @sub_lines = split(/,/,$env{"form.scantron.sub_bubblelines.$respnum"});
1.542 raeburn 9631: foreach my $item (@sub_lines) {
9632: $expected{$part_id} += $item;
9633: }
9634: } else {
1.596.2.12.2. 6(raebur 9635:3): $expected{$part_id} = $env{"form.scantron.bubblelines.$respnum"};
1.542 raeburn 9636: }
9637: }
9638: if ($symb) {
9639: my %recorded;
9640: my (%returnhash) = &Apache::lonnet::restore($symb,$cid,$domain,$username);
9641: if ($returnhash{'version'}) {
9642: my %lasthash=();
9643: my $version;
9644: for ($version=1;$version<=$returnhash{'version'};$version++) {
9645: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
9646: $lasthash{$key}=$returnhash{$version.':'.$key};
9647: }
9648: }
9649: foreach my $key (keys(%lasthash)) {
9650: if ($key =~ /\.scantron$/) {
9651: my $value = &unescape($lasthash{$key});
9652: my ($part_id) = ($key =~ /^resource\.(.+)\.scantron$/);
9653: if ($value eq '') {
9654: for (my $i=0; $i<$expected{$part_id}; $i++) {
9655: for (my $j=0; $j<$scantron_config->{'length'}; $j++) {
9656: $recorded{$part_id} .= $scantron_config->{'Qoff'};
9657: }
9658: }
9659: } else {
9660: my @tocheck;
9661: my @items = split(//,$value);
9662: if (($scantron_config->{'Qon'} eq 'letter') ||
9663: ($scantron_config->{'Qon'} eq 'number')) {
9664: if (@items < $expected{$part_id}) {
9665: my $fragment = substr($scandata,$startpos{$part_id},$expected{$part_id});
9666: my @singles = split(//,$fragment);
9667: foreach my $pos (@singles) {
9668: if ($pos eq ' ') {
9669: push(@tocheck,$pos);
9670: } else {
9671: my $next = shift(@items);
9672: push(@tocheck,$next);
9673: }
9674: }
9675: } else {
9676: @tocheck = @items;
9677: }
9678: foreach my $letter (@tocheck) {
9679: if ($scantron_config->{'Qon'} eq 'letter') {
9680: if ($letter !~ /^[A-J]$/) {
9681: $letter = $scantron_config->{'Qoff'};
9682: }
9683: $recorded{$part_id} .= $letter;
9684: } elsif ($scantron_config->{'Qon'} eq 'number') {
9685: my $digit;
9686: if ($letter !~ /^[A-J]$/) {
9687: $digit = $scantron_config->{'Qoff'};
9688: } else {
9689: $digit = $lettdig->{$letter};
9690: }
9691: $recorded{$part_id} .= $digit;
9692: }
9693: }
9694: } else {
9695: @tocheck = @items;
9696: for (my $i=0; $i<$expected{$part_id}; $i++) {
9697: my $curr_sub = shift(@tocheck);
9698: my $digit;
9699: if ($curr_sub =~ /^[A-J]$/) {
9700: $digit = $lettdig->{$curr_sub}-1;
9701: }
9702: if ($curr_sub eq 'J') {
9703: $digit += scalar($numletts);
9704: }
9705: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
9706: if ($j == $digit) {
9707: $recorded{$part_id} .= $scantron_config->{'Qon'};
9708: } else {
9709: $recorded{$part_id} .= $scantron_config->{'Qoff'};
9710: }
9711: }
9712: }
9713: }
9714: }
9715: }
9716: }
9717: }
1.554 raeburn 9718: foreach my $part_id (@{$partids}) {
1.542 raeburn 9719: if ($recorded{$part_id} eq '') {
9720: for (my $i=0; $i<$expected{$part_id}; $i++) {
9721: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
9722: $recorded{$part_id} .= $scantron_config->{'Qoff'};
9723: }
9724: }
9725: }
9726: $record .= $recorded{$part_id};
9727: }
9728: }
9729: return ($counter,$record);
9730: }
9731:
1.596.2.12.2. 6(raebur 9732:3): sub letter_to_digits {
1.542 raeburn 9733: my %lettdig = (
9734: A => 1,
9735: B => 2,
9736: C => 3,
9737: D => 4,
9738: E => 5,
9739: F => 6,
9740: G => 7,
9741: H => 8,
9742: I => 9,
9743: J => 0,
9744: );
9745: return %lettdig;
9746: }
9747:
1.423 albertel 9748:
1.75 albertel 9749: #-------- end of section for handling grading scantron forms -------
9750: #
9751: #-------------------------------------------------------------------
9752:
1.72 ng 9753: #-------------------------- Menu interface -------------------------
9754: #
9755: #--- Show a Grading Menu button - Calls the next routine ---
9756: sub show_grading_menu_form {
1.324 albertel 9757: my ($symb)=@_;
1.125 ng 9758: my $result.='<br /><form action="/adm/grades" method="post">'."\n".
1.418 albertel 9759: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 9760: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.72 ng 9761: '<input type="hidden" name="command" value="gradingmenu" />'."\n".
1.478 albertel 9762: '<input type="submit" name="submit" value="'.&mt('Grading Menu').'" />'."\n".
1.72 ng 9763: '</form>'."\n";
9764: return $result;
9765: }
9766:
1.77 ng 9767: # -- Retrieve choices for grading form
9768: sub savedState {
9769: my %savedState = ();
1.257 albertel 9770: if ($env{'form.saveState'}) {
9771: foreach (split(/:/,$env{'form.saveState'})) {
1.77 ng 9772: my ($key,$value) = split(/=/,$_,2);
9773: $savedState{$key} = $value;
9774: }
9775: }
9776: return \%savedState;
9777: }
1.76 ng 9778:
1.596.2.12.2. (raeburn 9779:): #--- Href with symb and command ---
9780:):
9781:): sub href_symb_cmd {
9782:): my ($symb,$cmd)=@_;
9783:): return '/adm/grades?symb='.&HTML::Entities::encode(&Apache::lonenc::check_encrypt($symb),'<>&"').'&command='.$cmd;
9784:): }
9785:):
1.443 banghart 9786: sub grading_menu {
9787: my ($request) = @_;
9788: my ($symb)=&get_symb($request);
9789: if (!$symb) {return '';}
9790: my $probTitle = &Apache::lonnet::gettitle($symb);
9791: my ($table,undef,$hdgrade) = &showResourceInfo($symb,$probTitle);
9792:
1.444 banghart 9793: $request->print($table);
1.443 banghart 9794: my %fields = ('symb'=>&Apache::lonenc::check_encrypt($symb),
9795: 'handgrade'=>$hdgrade,
9796: 'probTitle'=>$probTitle,
9797: 'command'=>'submit_options',
9798: 'saveState'=>"",
9799: 'gradingMenu'=>1,
9800: 'showgrading'=>"yes");
1.538 schulted 9801:
9802: my $url1 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
9803:
1.443 banghart 9804: $fields{'command'} = 'csvform';
1.538 schulted 9805: my $url2 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
9806:
1.443 banghart 9807: $fields{'command'} = 'processclicker';
1.538 schulted 9808: my $url3 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
9809:
1.443 banghart 9810: $fields{'command'} = 'scantron_selectphase';
1.538 schulted 9811: my $url4 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
9812:
9813: my @menu = ({ categorytitle=>'Course Grading',
9814: items =>[
9815: { linktext => 'Manual Grading/View Submissions',
9816: url => $url1,
9817: permission => 'F',
9818: icon => 'edit-find-replace.png',
9819: linktitle => 'Start the process of hand grading submissions.'
9820: },
9821: { linktext => 'Upload Scores',
9822: url => $url2,
9823: permission => 'F',
9824: icon => 'uploadscores.png',
9825: linktitle => 'Specify a file containing the class scores for current resource.'
9826: },
9827: { linktext => 'Process Clicker',
9828: url => $url3,
9829: permission => 'F',
9830: icon => 'addClickerInfoFile.png',
9831: linktitle => 'Specify a file containing the clicker information for this resource.'
9832: },
1.587 raeburn 9833: { linktext => 'Grade/Manage/Review Bubblesheets',
1.538 schulted 9834: url => $url4,
9835: permission => 'F',
9836: icon => 'stat.png',
1.596.2.4 raeburn 9837: linktitle => 'Grade bubblesheet exams, upload/download bubblesheet data files, and review previously graded bubblesheet exams.'
1.538 schulted 9838: }
9839: ]
9840: });
9841:
9842: #$fields{'command'} = 'verify';
9843: #$url = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
1.443 banghart 9844: #
9845: # Create the menu
9846: my $Str;
1.444 banghart 9847: # $Str .= '<h2>'.&mt('Please select a grading task').'</h2>';
1.445 banghart 9848: $Str .= '<form method="post" action="" name="gradingMenu">';
9849: $Str .= '<input type="hidden" name="command" value="" />'.
9850: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
9851: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
1.476 albertel 9852: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.445 banghart 9853: '<input type="hidden" name="saveState" value="" />'."\n".
9854: '<input type="hidden" name="gradingMenu" value="1" />'."\n".
9855: '<input type="hidden" name="showgrading" value="yes" />'."\n";
9856:
1.538 schulted 9857: $Str .= Apache::lonhtmlcommon::generate_menu(@menu);
9858: #$menudata->{'jscript'}
1.584 bisitz 9859: $Str .='<hr /><input type="button" value="'.&mt('Verify Receipt No.').'" '.
1.589 bisitz 9860: ' onclick="javascript:checkChoice(document.forms.gradingMenu,\'5\',\'verify\')" '.
1.538 schulted 9861: ' /> '.
9862: &Apache::lonnet::recprefix($env{'request.course.id'}).
1.589 bisitz 9863: '-<input type="text" name="receipt" size="4" onchange="javascript:checkReceiptNo(this.form,\'OK\')" />';
1.538 schulted 9864:
1.444 banghart 9865: $Str .="</form>\n";
1.539 riegler 9866: my $receiptalert = &mt("Please enter a receipt number given by a student in the receipt box.");
1.443 banghart 9867: $request->print(<<GRADINGMENUJS);
9868: <script type="text/javascript" language="javascript">
9869: function checkChoice(formname,val,cmdx) {
9870: if (val <= 2) {
9871: var cmd = radioSelection(formname.radioChoice);
9872: var cmdsave = cmd;
9873: } else {
9874: cmd = cmdx;
9875: cmdsave = 'submission';
9876: }
9877: formname.command.value = cmd;
9878: if (val < 5) formname.submit();
9879: if (val == 5) {
1.458 banghart 9880: if (!checkReceiptNo(formname,'notOK')) {
9881: return false;
9882: } else {
9883: formname.submit();
9884: }
1.445 banghart 9885: }
9886: }
1.443 banghart 9887:
9888: function checkReceiptNo(formname,nospace) {
9889: var receiptNo = formname.receipt.value;
9890: var checkOpt = false;
9891: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
9892: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
9893: if (checkOpt) {
1.539 riegler 9894: alert("$receiptalert");
1.443 banghart 9895: formname.receipt.value = "";
9896: formname.receipt.focus();
9897: return false;
9898: }
9899: return true;
9900: }
9901: </script>
9902: GRADINGMENUJS
9903: &commonJSfunctions($request);
9904: return $Str;
9905: }
9906:
9907:
9908: #--- Displays the submissions first page -------
9909: sub submit_options {
1.72 ng 9910: my ($request) = @_;
1.324 albertel 9911: my ($symb)=&get_symb($request);
1.72 ng 9912: if (!$symb) {return '';}
1.76 ng 9913: my $probTitle = &Apache::lonnet::gettitle($symb);
1.72 ng 9914:
1.539 riegler 9915: my $receiptalert = &mt("Please enter a receipt number given by a student in the receipt box.");
1.72 ng 9916: $request->print(<<GRADINGMENUJS);
9917: <script type="text/javascript" language="javascript">
1.116 ng 9918: function checkChoice(formname,val,cmdx) {
9919: if (val <= 2) {
9920: var cmd = radioSelection(formname.radioChoice);
1.118 ng 9921: var cmdsave = cmd;
1.116 ng 9922: } else {
9923: cmd = cmdx;
1.118 ng 9924: cmdsave = 'submission';
1.116 ng 9925: }
9926: formname.command.value = cmd;
1.118 ng 9927: formname.saveState.value = "saveCmd="+cmdsave+":saveSec="+pullDownSelection(formname.section)+
1.145 albertel 9928: ":saveSub="+pullDownSelection(formname.submitonly)+":saveStatus="+pullDownSelection(formname.Status);
1.116 ng 9929: if (val < 5) formname.submit();
9930: if (val == 5) {
1.72 ng 9931: if (!checkReceiptNo(formname,'notOK')) { return false;}
9932: formname.submit();
9933: }
1.238 albertel 9934: if (val < 7) formname.submit();
1.72 ng 9935: }
9936:
9937: function checkReceiptNo(formname,nospace) {
9938: var receiptNo = formname.receipt.value;
9939: var checkOpt = false;
9940: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
9941: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
9942: if (checkOpt) {
1.539 riegler 9943: alert("$receiptalert");
1.72 ng 9944: formname.receipt.value = "";
9945: formname.receipt.focus();
9946: return false;
9947: }
9948: return true;
9949: }
9950: </script>
9951: GRADINGMENUJS
1.118 ng 9952: &commonJSfunctions($request);
1.324 albertel 9953: my ($table,undef,$hdgrade) = &showResourceInfo($symb,$probTitle);
1.473 albertel 9954: my $result;
1.76 ng 9955: my (undef,$sections) = &getclasslist('all','0');
1.77 ng 9956: my $savedState = &savedState();
1.118 ng 9957: my $saveCmd = ($$savedState{'saveCmd'} eq '' ? 'submission' : $$savedState{'saveCmd'});
1.77 ng 9958: my $saveSec = ($$savedState{'saveSec'} eq '' ? 'all' : $$savedState{'saveSec'});
1.118 ng 9959: my $saveSub = ($$savedState{'saveSub'} eq '' ? 'all' : $$savedState{'saveSub'});
1.77 ng 9960: my $saveStatus = ($$savedState{'saveStatus'} eq '' ? 'Active' : $$savedState{'saveStatus'});
1.72 ng 9961:
1.533 bisitz 9962: # Preselect sections
9963: my $selsec="";
9964: if (ref($sections)) {
9965: foreach my $section (sort(@$sections)) {
9966: $selsec.='<option value="'.$section.'" '.
9967: ($saveSec eq $section ? 'selected="selected"':'').'>'.$section.'</option>'."\n";
9968: }
9969: }
9970:
1.72 ng 9971: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.418 albertel 9972: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.72 ng 9973: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
9974: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.116 ng 9975: '<input type="hidden" name="command" value="" />'."\n".
1.77 ng 9976: '<input type="hidden" name="saveState" value="" />'."\n".
1.124 ng 9977: '<input type="hidden" name="gradingMenu" value="1" />'."\n".
1.72 ng 9978: '<input type="hidden" name="showgrading" value="yes" />'."\n";
9979:
1.472 albertel 9980: $result.='
1.533 bisitz 9981: <h2>
9982: '.&mt('Grade Current Resource').'
9983: </h2>
9984: <div>
9985: '.$table.'
9986: </div>
9987:
1.537 harmsja 9988: <div class="LC_columnSection">
9989:
1.533 bisitz 9990: <fieldset>
9991: <legend>
9992: '.&mt('Sections').'
9993: </legend>
9994: <select name="section" multiple="multiple" size="5">'."\n";
9995: $result.= $selsec;
1.401 albertel 9996: $result.= '<option value="all" '.($saveSec eq 'all' ? 'selected="selected"' : ''). '>all</option></select> ';
1.472 albertel 9997: $result.='
1.533 bisitz 9998: </fieldset>
1.537 harmsja 9999:
1.533 bisitz 10000: <fieldset>
10001: <legend>
10002: '.&mt('Groups').'
10003: </legend>
10004: '.&Apache::lonstatistics::GroupSelect('group','multiple',5).'
10005: </fieldset>
1.537 harmsja 10006:
1.533 bisitz 10007: <fieldset>
10008: <legend>
10009: '.&mt('Access Status').'
10010: </legend>
10011: '.&Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,5,undef,'mult').'
10012: </fieldset>
1.537 harmsja 10013:
1.533 bisitz 10014: <fieldset>
10015: <legend>
10016: '.&mt('Submission Status').'
10017: </legend>
10018: <select name="submitonly" size="5">
1.473 albertel 10019: <option value="yes" '. ($saveSub eq 'yes' ? 'selected="selected"' : '').'>'.&mt('with submissions').'</option>
10020: <option value="queued" '. ($saveSub eq 'queued' ? 'selected="selected"' : '').'>'.&mt('in grading queue').'</option>
10021: <option value="graded" '. ($saveSub eq 'graded' ? 'selected="selected"' : '').'>'.&mt('with ungraded submissions').'</option>
10022: <option value="incorrect" '.($saveSub eq 'incorrect' ? 'selected="selected"' : '').'>'.&mt('with incorrect submissions').'</option>
10023: <option value="all" '. ($saveSub eq 'all' ? 'selected="selected"' : '').'>'.&mt('with any status').'</option>
1.533 bisitz 10024: </select>
10025: </fieldset>
1.537 harmsja 10026:
1.533 bisitz 10027: </div>
10028:
10029: <br />
10030: <div>
10031: <div>
1.473 albertel 10032: <label>
10033: <input type="radio" name="radioChoice" value="submission" '.
10034: ($saveCmd eq 'submission' ? 'checked="checked"' : '').' /> '.
10035: &mt('Select individual students to grade and view submissions.').'
10036: </label>
10037: </div>
1.533 bisitz 10038: <div>
1.473 albertel 10039: <label>
10040: <input type="radio" name="radioChoice" value="viewgrades" '.
10041: ($saveCmd eq 'viewgrades' ? 'checked="checked"' : '').' /> '.
10042: &mt('Grade all selected students in a grading table.').'
10043: </label>
10044: </div>
1.533 bisitz 10045: <div>
1.589 bisitz 10046: <input type="button" onclick="javascript:checkChoice(this.form,\'2\');" value="'.&mt('Next').' →" />
1.473 albertel 10047: </div>
1.472 albertel 10048: </div>
1.533 bisitz 10049:
10050:
1.473 albertel 10051: <h2>
10052: '.&mt('Grade Complete Folder for One Student').'
10053: </h2>
1.533 bisitz 10054: <div>
10055: <div>
1.473 albertel 10056: <label>
10057: <input type="radio" name="radioChoice" value="pickStudentPage" '.
10058: ($saveCmd eq 'pickStudentPage' ? 'checked="checked"' : '').' /> '.
10059: &mt('The <b>complete</b> page/sequence/folder: For one student').'
10060: </label>
10061: </div>
1.533 bisitz 10062: <div>
1.589 bisitz 10063: <input type="button" onclick="javascript:checkChoice(this.form,\'2\');" value="'.&mt('Next').' →" />
1.473 albertel 10064: </div>
1.472 albertel 10065: </div>
10066: </form>';
1.499 albertel 10067: $result .= &show_grading_menu_form($symb);
1.44 ng 10068: return $result;
1.2 albertel 10069: }
10070:
1.596.2.12.2. 7(raebur 10071:6): sub substatus_options {
10072:6): return &Apache::lonlocal::texthash(
10073:6): 'yes' => 'with submissions',
10074:6): 'queued' => 'in grading queue',
10075:6): 'graded' => 'with ungraded submissions',
10076:6): 'incorrect' => 'with incorrect submissions',
0(raebur 10077:7): 'all' => 'with any status',
10078:7): );
7(raebur 10079:6): }
10080:6):
1.285 albertel 10081: sub reset_perm {
10082: undef(%perm);
10083: }
10084:
10085: sub init_perm {
10086: &reset_perm();
1.300 albertel 10087: foreach my $test_perm ('vgr','mgr','opa') {
10088:
10089: my $scope = $env{'request.course.id'};
10090: if (!($perm{$test_perm}=&Apache::lonnet::allowed($test_perm,$scope))) {
10091:
10092: $scope .= '/'.$env{'request.course.sec'};
10093: if ( $perm{$test_perm}=
10094: &Apache::lonnet::allowed($test_perm,$scope)) {
10095: $perm{$test_perm.'_section'}=$env{'request.course.sec'};
10096: } else {
10097: delete($perm{$test_perm});
10098: }
1.285 albertel 10099: }
10100: }
10101: }
10102:
1.596.2.12.2. (raeburn 10103:): sub init_old_essays {
10104:): my ($symb,$apath,$adom,$aname) = @_;
10105:): if ($symb ne '') {
10106:): my %essays = &Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
10107:): if (keys(%essays) > 0) {
10108:): $old_essays{$symb} = \%essays;
10109:): }
10110:): }
10111:): return;
10112:): }
10113:):
10114:): sub reset_old_essays {
10115:): undef(%old_essays);
10116:): }
10117:):
1.400 www 10118: sub gather_clicker_ids {
1.408 albertel 10119: my %clicker_ids;
1.400 www 10120:
10121: my $classlist = &Apache::loncoursedata::get_classlist();
10122:
10123: # Set up a couple variables.
1.407 albertel 10124: my $username_idx = &Apache::loncoursedata::CL_SNAME();
10125: my $domain_idx = &Apache::loncoursedata::CL_SDOM();
1.438 www 10126: my $status_idx = &Apache::loncoursedata::CL_STATUS();
1.400 www 10127:
1.407 albertel 10128: foreach my $student (keys(%$classlist)) {
1.438 www 10129: if ($classlist->{$student}->[$status_idx] ne 'Active') { next; }
1.407 albertel 10130: my $username = $classlist->{$student}->[$username_idx];
10131: my $domain = $classlist->{$student}->[$domain_idx];
1.400 www 10132: my $clickers =
1.408 albertel 10133: (&Apache::lonnet::userenvironment($domain,$username,'clickers'))[1];
1.400 www 10134: foreach my $id (split(/\,/,$clickers)) {
1.414 www 10135: $id=~s/^[\#0]+//;
1.421 www 10136: $id=~s/[\-\:]//g;
1.407 albertel 10137: if (exists($clicker_ids{$id})) {
1.408 albertel 10138: $clicker_ids{$id}.=','.$username.':'.$domain;
1.400 www 10139: } else {
1.408 albertel 10140: $clicker_ids{$id}=$username.':'.$domain;
1.400 www 10141: }
10142: }
10143: }
1.407 albertel 10144: return %clicker_ids;
1.400 www 10145: }
10146:
1.402 www 10147: sub gather_adv_clicker_ids {
1.408 albertel 10148: my %clicker_ids;
1.402 www 10149: my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'};
10150: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
10151: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
1.409 albertel 10152: foreach my $element (sort(keys(%coursepersonnel))) {
1.402 www 10153: foreach my $person (split(/\,/,$coursepersonnel{$element})) {
10154: my ($puname,$pudom)=split(/\:/,$person);
10155: my $clickers =
1.408 albertel 10156: (&Apache::lonnet::userenvironment($pudom,$puname,'clickers'))[1];
1.405 www 10157: foreach my $id (split(/\,/,$clickers)) {
1.414 www 10158: $id=~s/^[\#0]+//;
1.421 www 10159: $id=~s/[\-\:]//g;
1.408 albertel 10160: if (exists($clicker_ids{$id})) {
10161: $clicker_ids{$id}.=','.$puname.':'.$pudom;
10162: } else {
10163: $clicker_ids{$id}=$puname.':'.$pudom;
10164: }
1.405 www 10165: }
1.402 www 10166: }
10167: }
1.407 albertel 10168: return %clicker_ids;
1.402 www 10169: }
10170:
1.413 www 10171: sub clicker_grading_parameters {
10172: return ('gradingmechanism' => 'scalar',
10173: 'upfiletype' => 'scalar',
10174: 'specificid' => 'scalar',
10175: 'pcorrect' => 'scalar',
10176: 'pincorrect' => 'scalar');
10177: }
10178:
1.400 www 10179: sub process_clicker {
10180: my ($r)=@_;
10181: my ($symb)=&get_symb($r);
10182: if (!$symb) {return '';}
10183: my $result=&checkforfile_js();
10184: $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
10185: my ($table) = &showResourceInfo($symb,$env{'form.probTitle'});
10186: $result.=$table;
10187: $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
10188: $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
1.538 schulted 10189: $result.=' <b>'.&mt('Specify a file containing the clicker information for this resource.').
10190: '</b></td></tr>'."\n";
1.596.2.4 raeburn 10191: $result.='<tr bgcolor="#ffffe6"><td>'."\n";
1.413 www 10192: # Attempt to restore parameters from last session, set defaults if not present
10193: my %Saveable_Parameters=&clicker_grading_parameters();
10194: &Apache::loncommon::restore_course_settings('grades_clicker',
10195: \%Saveable_Parameters);
10196: if (!$env{'form.pcorrect'}) { $env{'form.pcorrect'}=100; }
10197: if (!$env{'form.pincorrect'}) { $env{'form.pincorrect'}=100; }
10198: if (!$env{'form.gradingmechanism'}) { $env{'form.gradingmechanism'}='attendance'; }
10199: if (!$env{'form.upfiletype'}) { $env{'form.upfiletype'}='iclicker'; }
10200:
10201: my %checked;
1.521 www 10202: foreach my $gradingmechanism ('attendance','personnel','specific','given') {
1.413 www 10203: if ($env{'form.gradingmechanism'} eq $gradingmechanism) {
1.569 bisitz 10204: $checked{$gradingmechanism}=' checked="checked"';
1.413 www 10205: }
10206: }
10207:
1.400 www 10208: my $upload=&mt("Upload File");
10209: my $type=&mt("Type");
1.402 www 10210: my $attendance=&mt("Award points just for participation");
10211: my $personnel=&mt("Correctness determined from response by course personnel");
1.414 www 10212: my $specific=&mt("Correctness determined from response with clicker ID(s)");
1.521 www 10213: my $given=&mt("Correctness determined from given list of answers").' '.
10214: '<font size="-2"><tt>('.&mt("Provide comma-separated list. Use '*' for any answer correct, '-' for skip").')</tt></font>';
1.402 www 10215: my $pcorrect=&mt("Percentage points for correct solution");
10216: my $pincorrect=&mt("Percentage points for incorrect solution");
1.413 www 10217: my $selectform=&Apache::loncommon::select_form($env{'form.upfiletype'},'upfiletype',
1.596.2.1 raeburn 10218: {'iclicker' => 'i>clicker',
1.596.2.12.2. (raeburn 10219:): 'interwrite' => 'interwrite PRS',
10220:): 'turning' => 'Turning Technologies'});
1.418 albertel 10221: $symb = &Apache::lonenc::check_encrypt($symb);
1.400 www 10222: $result.=<<ENDUPFORM;
1.402 www 10223: <script type="text/javascript">
10224: function sanitycheck() {
10225: // Accept only integer percentages
10226: document.forms.gradesupload.pcorrect.value=Math.round(document.forms.gradesupload.pcorrect.value);
10227: document.forms.gradesupload.pincorrect.value=Math.round(document.forms.gradesupload.pincorrect.value);
10228: // Find out grading choice
10229: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
10230: if (document.forms.gradesupload.gradingmechanism[i].checked) {
10231: gradingchoice=document.forms.gradesupload.gradingmechanism[i].value;
10232: }
10233: }
10234: // By default, new choice equals user selection
10235: newgradingchoice=gradingchoice;
10236: // Not good to give more points for false answers than correct ones
10237: if (Math.round(document.forms.gradesupload.pcorrect.value)<Math.round(document.forms.gradesupload.pincorrect.value)) {
10238: document.forms.gradesupload.pcorrect.value=document.forms.gradesupload.pincorrect.value;
10239: }
10240: // If new choice is attendance only, and old choice was correctness-based, restore defaults
10241: if ((gradingchoice=='attendance') && (document.forms.gradesupload.waschecked.value!='attendance')) {
10242: document.forms.gradesupload.pcorrect.value=100;
10243: document.forms.gradesupload.pincorrect.value=100;
10244: }
10245: // If the values are different, cannot be attendance only
10246: if ((Math.round(document.forms.gradesupload.pcorrect.value)!=Math.round(document.forms.gradesupload.pincorrect.value)) &&
10247: (gradingchoice=='attendance')) {
10248: newgradingchoice='personnel';
10249: }
10250: // Change grading choice to new one
10251: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
10252: if (document.forms.gradesupload.gradingmechanism[i].value==newgradingchoice) {
10253: document.forms.gradesupload.gradingmechanism[i].checked=true;
10254: } else {
10255: document.forms.gradesupload.gradingmechanism[i].checked=false;
10256: }
10257: }
10258: // Remember the old state
10259: document.forms.gradesupload.waschecked.value=newgradingchoice;
10260: }
10261: </script>
1.400 www 10262: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
10263: <input type="hidden" name="symb" value="$symb" />
10264: <input type="hidden" name="command" value="processclickerfile" />
10265: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
10266: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
10267: <input type="file" name="upfile" size="50" />
10268: <br /><label>$type: $selectform</label>
1.589 bisitz 10269: <br /><label><input type="radio" name="gradingmechanism" value="attendance"$checked{'attendance'} onclick="sanitycheck()" />$attendance </label>
10270: <br /><label><input type="radio" name="gradingmechanism" value="personnel"$checked{'personnel'} onclick="sanitycheck()" />$personnel</label>
10271: <br /><label><input type="radio" name="gradingmechanism" value="specific"$checked{'specific'} onclick="sanitycheck()" />$specific </label>
1.414 www 10272: <input type="text" name="specificid" value="$env{'form.specificid'}" size="20" />
1.589 bisitz 10273: <br /><label><input type="radio" name="gradingmechanism" value="given"$checked{'given'} onclick="sanitycheck()" />$given </label>
1.521 www 10274: <br />
10275: <input type="text" name="givenanswer" size="50" />
1.413 www 10276: <input type="hidden" name="waschecked" value="$env{'form.gradingmechanism'}" />
1.589 bisitz 10277: <br /><label>$pcorrect: <input type="text" name="pcorrect" size="4" value="$env{'form.pcorrect'}" onchange="sanitycheck()" /></label>
10278: <br /><label>$pincorrect: <input type="text" name="pincorrect" size="4" value="$env{'form.pincorrect'}" onchange="sanitycheck()" /></label>
10279: <br /><input type="button" onclick="javascript:checkUpload(this.form);" value="$upload" />
1.400 www 10280: </form>
10281: ENDUPFORM
10282: $result.='</td></tr></table>'."\n".
10283: '</td></tr></table><br /><br />'."\n";
10284: $result.=&show_grading_menu_form($symb);
10285: return $result;
10286: }
10287:
10288: sub process_clicker_file {
10289: my ($r)=@_;
10290: my ($symb)=&get_symb($r);
10291: if (!$symb) {return '';}
1.413 www 10292:
10293: my %Saveable_Parameters=&clicker_grading_parameters();
10294: &Apache::loncommon::store_course_settings('grades_clicker',
10295: \%Saveable_Parameters);
10296:
1.400 www 10297: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.404 www 10298: if (($env{'form.gradingmechanism'} eq 'specific') && ($env{'form.specificid'}!~/\w/)) {
1.408 albertel 10299: $result.='<span class="LC_error">'.&mt('You need to specify a clicker ID for the correct answer').'</span>';
10300: return $result.&show_grading_menu_form($symb);
1.404 www 10301: }
1.522 www 10302: if (($env{'form.gradingmechanism'} eq 'given') && ($env{'form.givenanswer'}!~/\S/)) {
1.521 www 10303: $result.='<span class="LC_error">'.&mt('You need to specify the correct answer').'</span>';
10304: return $result.&show_grading_menu_form($symb);
10305: }
1.522 www 10306: my $foundgiven=0;
1.521 www 10307: if ($env{'form.gradingmechanism'} eq 'given') {
10308: $env{'form.givenanswer'}=~s/^\s*//gs;
10309: $env{'form.givenanswer'}=~s/\s*$//gs;
1.596.2.4 raeburn 10310: $env{'form.givenanswer'}=~s/[^a-zA-Z0-9\.\*\-\+]+/\,/g;
1.521 www 10311: $env{'form.givenanswer'}=uc($env{'form.givenanswer'});
1.522 www 10312: my @answers=split(/\,/,$env{'form.givenanswer'});
10313: $foundgiven=$#answers+1;
1.521 www 10314: }
1.407 albertel 10315: my %clicker_ids=&gather_clicker_ids();
1.408 albertel 10316: my %correct_ids;
1.404 www 10317: if ($env{'form.gradingmechanism'} eq 'personnel') {
1.408 albertel 10318: %correct_ids=&gather_adv_clicker_ids();
1.404 www 10319: }
10320: if ($env{'form.gradingmechanism'} eq 'specific') {
1.414 www 10321: foreach my $correct_id (split(/[\s\,]/,$env{'form.specificid'})) {;
10322: $correct_id=~tr/a-z/A-Z/;
10323: $correct_id=~s/\s//gs;
10324: $correct_id=~s/^[\#0]+//;
1.421 www 10325: $correct_id=~s/[\-\:]//g;
1.414 www 10326: if ($correct_id) {
10327: $correct_ids{$correct_id}='specified';
10328: }
10329: }
1.400 www 10330: }
1.404 www 10331: if ($env{'form.gradingmechanism'} eq 'attendance') {
1.408 albertel 10332: $result.=&mt('Score based on attendance only');
1.521 www 10333: } elsif ($env{'form.gradingmechanism'} eq 'given') {
1.522 www 10334: $result.=&mt('Score based on [_1] ([_2] answers)','<tt>'.$env{'form.givenanswer'}.'</tt>',$foundgiven);
1.404 www 10335: } else {
1.408 albertel 10336: my $number=0;
1.411 www 10337: $result.='<p><b>'.&mt('Correctness determined by the following IDs').'</b>';
1.408 albertel 10338: foreach my $id (sort(keys(%correct_ids))) {
1.411 www 10339: $result.='<br /><tt>'.$id.'</tt> - ';
1.408 albertel 10340: if ($correct_ids{$id} eq 'specified') {
10341: $result.=&mt('specified');
10342: } else {
10343: my ($uname,$udom)=split(/\:/,$correct_ids{$id});
10344: $result.=&Apache::loncommon::plainname($uname,$udom);
10345: }
10346: $number++;
10347: }
1.411 www 10348: $result.="</p>\n";
1.596.2.12.2. 5(raebur 10349:3): if ($number==0) {
10350:3): $result .=
10351:3): &Apache::lonhtmlcommon::confirm_success(
10352:3): &mt('No IDs found to determine correct answer'),1);
7(raebur 10353:9): return $result.&show_grading_menu_form($symb);
5(raebur 10354:3): }
1.404 www 10355: }
1.405 www 10356: if (length($env{'form.upfile'}) < 2) {
1.596.2.12.2. 5(raebur 10357:3): $result .=
10358:3): &Apache::lonhtmlcommon::confirm_success(
10359:3): &mt('The file: [_1] you attempted to upload contained no information. Please check that you entered the correct filename.',
10360:3): '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'),1);
1.405 www 10361: return $result.&show_grading_menu_form($symb);
10362: }
1.596.2.12.2. 7(raebur 10363:9): my $mimetype;
10364:9): if ($env{'form.upfiletype'} eq 'iclicker') {
10365:9): my $mm = new File::MMagic;
10366:9): $mimetype = $mm->checktype_contents($env{'form.upfile'});
10367:9): unless (($mimetype eq 'text/plain') || ($mimetype eq 'text/html')) {
10368:9): $result.= '<p>'.
10369:9): &Apache::lonhtmlcommon::confirm_success(
10370:9): &mt('File format is neither csv (iclicker 6) nor xml (iclicker 7)'),1).'</p>';
10371:9): return $result.&show_grading_menu_form($symb);
10372:9): }
10373:9): } elsif (($env{'form.upfiletype'} ne 'interwrite') && ($env{'form.upfiletype'} ne 'turning')) {
10374:9): $result .= '<p>'.
10375:9): &Apache::lonhtmlcommon::confirm_success(
10376:9): &mt('Invalid clicker type: choose one of: i>clicker, Interwrite PRS, or Turning Technologies.'),1).'</p>';
10377:9): return $result.&show_grading_menu_form($symb);
10378:9): }
1.410 www 10379:
10380: # Were able to get all the info needed, now analyze the file
10381:
1.411 www 10382: $result.=&Apache::loncommon::studentbrowser_javascript();
1.418 albertel 10383: $symb = &Apache::lonenc::check_encrypt($symb);
1.410 www 10384: my $heading=&mt('Scanning clicker file');
10385: $result.=(<<ENDHEADER);
10386: <br /><table width="100%" border="0"><tr><td bgcolor="#777777">
10387: <table width="100%" border="0"><tr bgcolor="#e6ffff"><td>
1.596.2.4 raeburn 10388: <b>$heading</b></td></tr><tr bgcolor="#ffffe6"><td>
1.410 www 10389: <form method="post" action="/adm/grades" name="clickeranalysis">
10390: <input type="hidden" name="symb" value="$symb" />
10391: <input type="hidden" name="command" value="assignclickergrades" />
10392: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
10393: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
1.411 www 10394: <input type="hidden" name="gradingmechanism" value="$env{'form.gradingmechanism'}" />
10395: <input type="hidden" name="pcorrect" value="$env{'form.pcorrect'}" />
10396: <input type="hidden" name="pincorrect" value="$env{'form.pincorrect'}" />
1.410 www 10397: ENDHEADER
1.522 www 10398: if ($env{'form.gradingmechanism'} eq 'given') {
10399: $result.='<input type="hidden" name="correct:given" value="'.$env{'form.givenanswer'}.'" />';
10400: }
1.408 albertel 10401: my %responses;
10402: my @questiontitles;
1.405 www 10403: my $errormsg='';
10404: my $number=0;
10405: if ($env{'form.upfiletype'} eq 'iclicker') {
1.596.2.12.2. 7(raebur 10406:9): if ($mimetype eq 'text/plain') {
10407:9): ($errormsg,$number)=&iclicker_eval(\@questiontitles,\%responses);
10408:9): } elsif ($mimetype eq 'text/html') {
10409:9): ($errormsg,$number)=&iclickerxml_eval(\@questiontitles,\%responses);
10410:9): }
10411:9): } elsif ($env{'form.upfiletype'} eq 'interwrite') {
1.419 www 10412: ($errormsg,$number)=&interwrite_eval(\@questiontitles,\%responses);
1.596.2.12.2. 7(raebur 10413:9): } elsif ($env{'form.upfiletype'} eq 'turning') {
(raeburn 10414:): ($errormsg,$number)=&turning_eval(\@questiontitles,\%responses);
10415:): }
1.411 www 10416: $result.='<br />'.&mt('Found [_1] question(s)',$number).'<br />'.
10417: '<input type="hidden" name="number" value="'.$number.'" />'.
10418: &mt('Awarding [_1] percent for correct and [_2] percent for incorrect responses',
10419: $env{'form.pcorrect'},$env{'form.pincorrect'}).
10420: '<br />';
1.522 www 10421: if (($env{'form.gradingmechanism'} eq 'given') && ($number!=$foundgiven)) {
10422: $result.='<span class="LC_error">'.&mt('Number of given answers does not agree with number of questions in file.').'</span>';
10423: return $result.&show_grading_menu_form($symb);
10424: }
1.414 www 10425: # Remember Question Titles
10426: # FIXME: Possibly need delimiter other than ":"
10427: for (my $i=0;$i<$number;$i++) {
10428: $result.='<input type="hidden" name="question:'.$i.'" value="'.
10429: &HTML::Entities::encode($questiontitles[$i],'"&<>').'" />';
10430: }
1.411 www 10431: my $correct_count=0;
10432: my $student_count=0;
10433: my $unknown_count=0;
1.414 www 10434: # Match answers with usernames
10435: # FIXME: Possibly need delimiter other than ":"
1.409 albertel 10436: foreach my $id (keys(%responses)) {
1.410 www 10437: if ($correct_ids{$id}) {
1.414 www 10438: $result.="\n".'<input type="hidden" name="correct:'.$correct_count.':'.$correct_ids{$id}.'" value="'.$responses{$id}.'" />';
1.411 www 10439: $correct_count++;
1.410 www 10440: } elsif ($clicker_ids{$id}) {
1.437 www 10441: if ($clicker_ids{$id}=~/\,/) {
10442: # More than one user with the same clicker!
10443: $result.="\n<hr />".&mt('Clicker registered more than once').": <tt>".$id."</tt><br />";
10444: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
10445: "<select name='multi".$id."'>";
10446: foreach my $reguser (sort(split(/\,/,$clicker_ids{$id}))) {
10447: $result.="<option value='".$reguser."'>".&Apache::loncommon::plainname(split(/\:/,$reguser)).' ('.$reguser.')</option>';
10448: }
10449: $result.='</select>';
10450: $unknown_count++;
10451: } else {
10452: # Good: found one and only one user with the right clicker
10453: $result.="\n".'<input type="hidden" name="student:'.$clicker_ids{$id}.'" value="'.$responses{$id}.'" />';
10454: $student_count++;
10455: }
1.410 www 10456: } else {
1.411 www 10457: $result.="\n<hr />".&mt('Unregistered Clicker')." <tt>".$id."</tt><br />";
10458: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
10459: "\n".&mt("Username").": <input type='text' name='uname".$id."' /> ".
10460: "\n".&mt("Domain").": ".
10461: &Apache::loncommon::select_dom_form($env{'course.'.$env{'request.course.id'}.'.domain'},'udom'.$id).' '.
1.596.2.4 raeburn 10462: &Apache::loncommon::selectstudent_link('clickeranalysis','uname'.$id,'udom'.$id,0,$id);
1.411 www 10463: $unknown_count++;
1.410 www 10464: }
1.405 www 10465: }
1.412 www 10466: $result.='<hr />'.
10467: &mt('Found [_1] registered and [_2] unregistered clickers.',$student_count,$unknown_count);
1.521 www 10468: if (($env{'form.gradingmechanism'} ne 'attendance') && ($env{'form.gradingmechanism'} ne 'given')) {
1.412 www 10469: if ($correct_count==0) {
1.596.2.12.2. 8(raebur 10470:3): $errormsg.="Found no correct answers for grading!";
1.412 www 10471: } elsif ($correct_count>1) {
1.414 www 10472: $result.='<br /><span class="LC_warning">'.&mt("Found [_1] entries for grading!",$correct_count).'</span>';
1.412 www 10473: }
10474: }
1.428 www 10475: if ($number<1) {
10476: $errormsg.="Found no questions.";
10477: }
1.412 www 10478: if ($errormsg) {
10479: $result.='<br /><span class="LC_error">'.&mt($errormsg).'</span>';
10480: } else {
10481: $result.='<br /><input type="submit" name="finalize" value="'.&mt('Finalize Grading').'" />';
10482: }
10483: $result.='</form></td></tr></table>'."\n".
1.410 www 10484: '</td></tr></table><br /><br />'."\n";
1.404 www 10485: return $result.&show_grading_menu_form($symb);
1.400 www 10486: }
10487:
1.405 www 10488: sub iclicker_eval {
1.406 www 10489: my ($questiontitles,$responses)=@_;
1.405 www 10490: my $number=0;
10491: my $errormsg='';
10492: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
1.410 www 10493: my %components=&Apache::loncommon::record_sep($line);
10494: my @entries=map {$components{$_}} (sort(keys(%components)));
1.408 albertel 10495: if ($entries[0] eq 'Question') {
10496: for (my $i=3;$i<$#entries;$i+=6) {
10497: $$questiontitles[$number]=$entries[$i];
10498: $number++;
10499: }
10500: }
10501: if ($entries[0]=~/^\#/) {
10502: my $id=$entries[0];
10503: my @idresponses;
10504: $id=~s/^[\#0]+//;
10505: for (my $i=0;$i<$number;$i++) {
10506: my $idx=3+$i*6;
1.596.2.4 raeburn 10507: $entries[$idx]=~s/[^a-zA-Z0-9\.\*\-\+]+//g;
1.408 albertel 10508: push(@idresponses,$entries[$idx]);
10509: }
10510: $$responses{$id}=join(',',@idresponses);
10511: }
1.405 www 10512: }
10513: return ($errormsg,$number);
10514: }
10515:
1.596.2.12.2. 7(raebur 10516:9): sub iclickerxml_eval {
10517:9): my ($questiontitles,$responses)=@_;
10518:9): my $number=0;
10519:9): my $errormsg='';
10520:9): my @state;
10521:9): my %respbyid;
10522:9): my $p = HTML::Parser->new
10523:9): (
10524:9): xml_mode => 1,
10525:9): start_h =>
10526:9): [sub {
10527:9): my ($tagname,$attr) = @_;
10528:9): push(@state,$tagname);
10529:9): if ("@state" eq "ssn p") {
10530:9): my $title = $attr->{qn};
10531:9): $title =~ s/(^\s+|\s+$)//g;
10532:9): $questiontitles->[$number]=$title;
10533:9): } elsif ("@state" eq "ssn p v") {
10534:9): my $id = $attr->{id};
10535:9): my $entry = $attr->{ans};
10536:9): $id=~s/^[\#0]+//;
10537:9): $entry =~s/[^a-zA-Z0-9\.\*\-\+]+//g;
10538:9): $respbyid{$id}[$number] = $entry;
10539:9): }
10540:9): }, "tagname, attr"],
10541:9): end_h =>
10542:9): [sub {
10543:9): my ($tagname) = @_;
10544:9): if ("@state" eq "ssn p") {
10545:9): $number++;
10546:9): }
10547:9): pop(@state);
10548:9): }, "tagname"],
10549:9): );
10550:9):
10551:9): $p->parse($env{'form.upfile'});
10552:9): $p->eof;
10553:9): foreach my $id (keys(%respbyid)) {
10554:9): $responses->{$id}=join(',',@{$respbyid{$id}});
10555:9): }
10556:9): return ($errormsg,$number);
10557:9): }
10558:9):
1.419 www 10559: sub interwrite_eval {
10560: my ($questiontitles,$responses)=@_;
10561: my $number=0;
10562: my $errormsg='';
1.420 www 10563: my $skipline=1;
10564: my $questionnumber=0;
10565: my %idresponses=();
1.419 www 10566: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
10567: my %components=&Apache::loncommon::record_sep($line);
10568: my @entries=map {$components{$_}} (sort(keys(%components)));
1.420 www 10569: if ($entries[1] eq 'Time') { $skipline=0; next; }
10570: if ($entries[1] eq 'Response') { $skipline=1; }
10571: next if $skipline;
10572: if ($entries[0]!=$questionnumber) {
10573: $questionnumber=$entries[0];
10574: $$questiontitles[$number]=&mt('Question [_1]',$questionnumber);
10575: $number++;
1.419 www 10576: }
1.420 www 10577: my $id=$entries[4];
10578: $id=~s/^[\#0]+//;
1.421 www 10579: $id=~s/^v\d*\://i;
10580: $id=~s/[\-\:]//g;
1.420 www 10581: $idresponses{$id}[$number]=$entries[6];
10582: }
1.524 raeburn 10583: foreach my $id (keys(%idresponses)) {
1.420 www 10584: $$responses{$id}=join(',',@{$idresponses{$id}});
10585: $$responses{$id}=~s/^\s*\,//;
1.419 www 10586: }
10587: return ($errormsg,$number);
10588: }
10589:
1.596.2.12.2. (raeburn 10590:): sub turning_eval {
10591:): my ($questiontitles,$responses)=@_;
10592:): my $number=0;
10593:): my $errormsg='';
10594:): foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
10595:): my %components=&Apache::loncommon::record_sep($line);
10596:): my @entries=map {$components{$_}} (sort(keys(%components)));
10597:): if ($#entries>$number) { $number=$#entries; }
10598:): my $id=$entries[0];
10599:): my @idresponses;
10600:): $id=~s/^[\#0]+//;
10601:): unless ($id) { next; }
10602:): for (my $idx=1;$idx<=$#entries;$idx++) {
10603:): $entries[$idx]=~s/\,/\;/g;
10604:): $entries[$idx]=~s/[^a-zA-Z0-9\.\*\-\+\;]+//g;
10605:): push(@idresponses,$entries[$idx]);
10606:): }
10607:): $$responses{$id}=join(',',@idresponses);
10608:): }
10609:): for (my $i=1; $i<=$number; $i++) {
10610:): $$questiontitles[$i]=&mt('Question [_1]',$i);
10611:): }
10612:): return ($errormsg,$number);
10613:): }
10614:):
1.414 www 10615: sub assign_clicker_grades {
10616: my ($r)=@_;
10617: my ($symb)=&get_symb($r);
10618: if (!$symb) {return '';}
1.416 www 10619: # See which part we are saving to
1.582 raeburn 10620: my $res_error;
10621: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
10622: if ($res_error) {
10623: return &navmap_errormsg();
10624: }
1.416 www 10625: # FIXME: This should probably look for the first handgradeable part
10626: my $part=$$partlist[0];
10627: # Start screen output
1.596.2.10 raeburn 10628: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.596.2.4 raeburn 10629:
1.596.2.10 raeburn 10630: $result .= '<br />'.
10631: &Apache::loncommon::start_data_table().
1.596.2.4 raeburn 10632: &Apache::loncommon::start_data_table_header_row().
10633: '<th>'.&mt('Assigning grades based on clicker file').'</th>'.
10634: &Apache::loncommon::end_data_table_header_row().
10635: &Apache::loncommon::start_data_table_row().'<td>';
1.416 www 10636:
1.414 www 10637: # Get correct result
10638: # FIXME: Possibly need delimiter other than ":"
10639: my @correct=();
1.415 www 10640: my $gradingmechanism=$env{'form.gradingmechanism'};
10641: my $number=$env{'form.number'};
10642: if ($gradingmechanism ne 'attendance') {
1.414 www 10643: foreach my $key (keys(%env)) {
10644: if ($key=~/^form\.correct\:/) {
10645: my @input=split(/\,/,$env{$key});
10646: for (my $i=0;$i<=$#input;$i++) {
10647: if (($correct[$i]) && ($input[$i]) &&
10648: ($correct[$i] ne $input[$i])) {
10649: $result.='<br /><span class="LC_warning">'.
10650: &mt('More than one correct result given for question "[_1]": [_2] versus [_3].',
10651: $env{'form.question:'.$i},$correct[$i],$input[$i]).'</span>';
1.596.2.4 raeburn 10652: } elsif (($input[$i]) || ($input[$i] eq '0')) {
1.414 www 10653: $correct[$i]=$input[$i];
10654: }
10655: }
10656: }
10657: }
1.415 www 10658: for (my $i=0;$i<$number;$i++) {
1.596.2.4 raeburn 10659: if ((!$correct[$i]) && ($correct[$i] ne '0')) {
1.414 www 10660: $result.='<br /><span class="LC_error">'.
10661: &mt('No correct result given for question "[_1]"!',
10662: $env{'form.question:'.$i}).'</span>';
10663: }
10664: }
1.596.2.4 raeburn 10665: $result.='<br />'.&mt("Correct answer: [_1]",join(', ',map { ((($_) || ($_ eq '0'))?$_:'-') } @correct));
1.414 www 10666: }
10667: # Start grading
1.415 www 10668: my $pcorrect=$env{'form.pcorrect'};
10669: my $pincorrect=$env{'form.pincorrect'};
1.416 www 10670: my $storecount=0;
1.596.2.4 raeburn 10671: my %users=();
1.415 www 10672: foreach my $key (keys(%env)) {
1.420 www 10673: my $user='';
1.415 www 10674: if ($key=~/^form\.student\:(.*)$/) {
1.420 www 10675: $user=$1;
10676: }
10677: if ($key=~/^form\.unknown\:(.*)$/) {
10678: my $id=$1;
10679: if (($env{'form.uname'.$id}) && ($env{'form.udom'.$id})) {
10680: $user=$env{'form.uname'.$id}.':'.$env{'form.udom'.$id};
1.437 www 10681: } elsif ($env{'form.multi'.$id}) {
10682: $user=$env{'form.multi'.$id};
1.420 www 10683: }
10684: }
1.596.2.4 raeburn 10685: if ($user) {
10686: if ($users{$user}) {
10687: $result.='<br /><span class="LC_warning">'.
1.596.2.12.2. 8(raebur 10688:3): &mt('More than one entry found for [_1]!','<tt>'.$user.'</tt>').
1.596.2.4 raeburn 10689: '</span><br />';
10690: }
10691: $users{$user}=1;
1.415 www 10692: my @answer=split(/\,/,$env{$key});
10693: my $sum=0;
1.522 www 10694: my $realnumber=$number;
1.415 www 10695: for (my $i=0;$i<$number;$i++) {
1.576 www 10696: if ($correct[$i] eq '-') {
10697: $realnumber--;
10698: } elsif ($answer[$i]) {
1.415 www 10699: if ($gradingmechanism eq 'attendance') {
10700: $sum+=$pcorrect;
1.576 www 10701: } elsif ($correct[$i] eq '*') {
1.522 www 10702: $sum+=$pcorrect;
1.415 www 10703: } else {
1.596.2.4 raeburn 10704: # We actually grade if correct or not
10705: my $increment=$pincorrect;
10706: # Special case: numerical answer "0"
10707: if ($correct[$i] eq '0') {
10708: if ($answer[$i]=~/^[0\.]+$/) {
10709: $increment=$pcorrect;
10710: }
10711: # General numerical answer, both evaluate to something non-zero
10712: } elsif ((1.0*$correct[$i]!=0) && (1.0*$answer[$i]!=0)) {
10713: if (1.0*$correct[$i]==1.0*$answer[$i]) {
10714: $increment=$pcorrect;
10715: }
10716: # Must be just alphanumeric
10717: } elsif ($answer[$i] eq $correct[$i]) {
10718: $increment=$pcorrect;
1.415 www 10719: }
1.596.2.4 raeburn 10720: $sum+=$increment;
1.415 www 10721: }
10722: }
10723: }
1.522 www 10724: my $ave=$sum/(100*$realnumber);
1.416 www 10725: # Store
10726: my ($username,$domain)=split(/\:/,$user);
10727: my %grades=();
10728: $grades{"resource.$part.solved"}='correct_by_override';
10729: $grades{"resource.$part.awarded"}=$ave;
10730: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
10731: my $returncode=&Apache::lonnet::cstore(\%grades,$symb,
10732: $env{'request.course.id'},
10733: $domain,$username);
10734: if ($returncode ne 'ok') {
10735: $result.="<br /><span class=\"LC_error\">Failed to save student $username:$domain. Message when trying to save was ($returncode)</span>";
10736: } else {
10737: $storecount++;
10738: }
1.415 www 10739: }
10740: }
10741: # We are done
1.549 hauer 10742: $result.='<br />'.&mt('Successfully stored grades for [quant,_1,student].',$storecount).
1.596.2.4 raeburn 10743: '</td>'.
10744: &Apache::loncommon::end_data_table_row().
10745: &Apache::loncommon::end_data_table()."<br /><br />\n";
1.414 www 10746: return $result.&show_grading_menu_form($symb);
10747: }
10748:
1.582 raeburn 10749: sub navmap_errormsg {
10750: return '<div class="LC_error">'.
10751: &mt('An error occurred retrieving information about resources in the course.').'<br />'.
1.595 raeburn 10752: &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 10753: '</div>';
10754: }
10755:
1.596.2.12.2. (raeburn 10756:): sub startpage {
10757:): my ($r,$symb,$crumbs,$onlyfolderflag,$nodisplayflag,$stuvcurrent,$stuvdisp,$nomenu,$js) = @_;
10758:): if ($nomenu) {
10759:): $r->print(&Apache::loncommon::start_page("Student's Version",$js,{'only_body' => '1'}));
10760:): } else {
10761:): $r->print(&Apache::loncommon::start_page('Grading',$js,
10762:): {'bread_crumbs' => $crumbs}));
10763:): }
10764:): unless ($nodisplayflag) {
10765:): $r->print(&Apache::lonhtmlcommon::resource_info_box($symb,$onlyfolderflag,$stuvcurrent,$stuvdisp));
10766:): }
10767:): }
10768:):
1.1 albertel 10769: sub handler {
1.41 ng 10770: my $request=$_[0];
1.434 albertel 10771: &reset_caches();
1.596.2.4 raeburn 10772: if ($request->header_only) {
10773: &Apache::loncommon::content_type($request,'text/html');
10774: $request->send_http_header;
10775: return OK;
1.41 ng 10776: }
10777: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.596.2.4 raeburn 10778:
1.324 albertel 10779: my $symb=&get_symb($request,1);
1.160 albertel 10780: my @commands=&Apache::loncommon::get_env_multiple('form.command');
10781: my $command=$commands[0];
1.447 foxr 10782:
1.160 albertel 10783: if ($#commands > 0) {
10784: &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands));
10785: }
1.447 foxr 10786:
1.513 foxr 10787: $ssi_error = 0;
1.535 raeburn 10788: my $brcrum = [{href=>"/adm/grades",text=>"Grading"}];
1.596.2.4 raeburn 10789: my $start_page = &Apache::loncommon::start_page('Grading',undef,
1.596.2.12.2. (raeburn 10790:): {'bread_crumbs' => $brcrum});
1.324 albertel 10791: if ($symb eq '' && $command eq '') {
1.257 albertel 10792: if ($env{'user.adv'}) {
1.596.2.4 raeburn 10793: &Apache::loncommon::content_type($request,'text/html');
10794: $request->send_http_header;
10795: $request->print($start_page);
1.257 albertel 10796: if (($env{'form.codeone'}) && ($env{'form.codetwo'}) &&
10797: ($env{'form.codethree'})) {
10798: my $token=$env{'form.codeone'}.'*'.$env{'form.codetwo'}.'*'.
10799: $env{'form.codethree'};
1.41 ng 10800: my ($tsymb,$tuname,$tudom,$tcrsid)=
10801: &Apache::lonnet::checkin($token);
10802: if ($tsymb) {
1.137 albertel 10803: my ($map,$id,$url)=&Apache::lonnet::decode_symb($tsymb);
1.41 ng 10804: if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
1.513 foxr 10805: $request->print(&ssi_with_retries('/res/'.$url, $ssi_retries,
1.99 albertel 10806: ('grade_username' => $tuname,
10807: 'grade_domain' => $tudom,
10808: 'grade_courseid' => $tcrsid,
10809: 'grade_symb' => $tsymb)));
1.41 ng 10810: } else {
1.45 ng 10811: $request->print('<h3>Not authorized: '.$token.'</h3>');
1.99 albertel 10812: }
1.41 ng 10813: } else {
1.45 ng 10814: $request->print('<h3>Not a valid DocID: '.$token.'</h3>');
1.41 ng 10815: }
1.14 www 10816: } else {
1.41 ng 10817: $request->print(&Apache::lonxml::tokeninputfield());
10818: }
1.596.2.4 raeburn 10819: } elsif ($env{'request.course.id'}) {
10820: &init_perm();
10821: if (!%perm) {
10822: $request->internal_redirect('/adm/quickgrades');
1.596.2.12.2. 3(raebur 10823:3): return OK;
1.596.2.4 raeburn 10824: } else {
10825: &Apache::loncommon::content_type($request,'text/html');
10826: $request->send_http_header;
10827: $request->print($start_page);
10828: }
10829: }
1.41 ng 10830: } else {
1.596.2.4 raeburn 10831: &init_perm();
10832: if (!$env{'request.course.id'}) {
1.596.2.11 raeburn 10833: unless ((&Apache::lonnet::allowed('usc',$env{'request.role.domain'})) &&
10834: ($command =~ /^scantronupload/)) {
10835: # Not in a course.
10836: $env{'user.error.msg'}="/adm/grades::vgr:0:0:Cannot display grades page outside course context";
10837: return HTTP_NOT_ACCEPTABLE;
10838: }
1.596.2.4 raeburn 10839: } elsif (!%perm) {
10840: $request->internal_redirect('/adm/quickgrades');
10841: }
10842: &Apache::loncommon::content_type($request,'text/html');
10843: $request->send_http_header;
1.596.2.12.2. (raeburn 10844:): unless ((($command eq 'submission' || $command eq 'versionsub')) && ($perm{'vgr'})) {
10845:): $request->print($start_page);
10846:): }
1.104 albertel 10847: if ($command eq 'submission' && $perm{'vgr'}) {
1.596.2.12.2. (raeburn 10848:): my ($stuvcurrent,$stuvdisp,$versionform,$js);
10849:): if (($env{'form.student'} ne '') && ($env{'form.userdom'} ne '')) {
10850:): ($stuvcurrent,$stuvdisp,$versionform,$js) =
10851:): &choose_task_version_form($symb,$env{'form.student'},
10852:): $env{'form.userdom'});
10853:): }
10854:): &startpage($request,$symb,[{href=>"", text=>"Student Submissions"}],undef,undef,$stuvcurrent,$stuvdisp,undef,$js);
10855:): if ($versionform) {
10856:): $request->print($versionform);
10857:): }
10858:): $request->print('<br clear="all" />');
1.257 albertel 10859: ($env{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0));
1.596.2.12.2. (raeburn 10860:): } elsif ($command eq 'versionsub' && $perm{'vgr'}) {
10861:): my ($stuvcurrent,$stuvdisp,$versionform,$js) =
10862:): &choose_task_version_form($symb,$env{'form.student'},
10863:): $env{'form.userdom'},
10864:): $env{'form.inhibitmenu'});
10865:): &startpage($request,$symb,[{href=>"", text=>"Previous Student Version"}],undef,undef,$stuvcurrent,$stuvdisp,$env{'form.inhibitmenu'},$js);
10866:): if ($versionform) {
10867:): $request->print($versionform);
10868:): }
10869:): $request->print('<br clear="all" />');
10870:): $request->print(&show_previous_task_version($request,$symb));
1.103 albertel 10871: } elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) {
1.68 ng 10872: &pickStudentPage($request);
1.103 albertel 10873: } elsif ($command eq 'displayPage' && $perm{'vgr'}) {
1.68 ng 10874: &displayPage($request);
1.104 albertel 10875: } elsif ($command eq 'gradeByPage' && $perm{'mgr'}) {
1.71 ng 10876: &updateGradeByPage($request);
1.104 albertel 10877: } elsif ($command eq 'processGroup' && $perm{'vgr'}) {
1.41 ng 10878: &processGroup($request);
1.104 albertel 10879: } elsif ($command eq 'gradingmenu' && $perm{'vgr'}) {
1.443 banghart 10880: $request->print(&grading_menu($request));
10881: } elsif ($command eq 'submit_options' && $perm{'vgr'}) {
10882: $request->print(&submit_options($request));
1.104 albertel 10883: } elsif ($command eq 'viewgrades' && $perm{'vgr'}) {
1.41 ng 10884: $request->print(&viewgrades($request));
1.104 albertel 10885: } elsif ($command eq 'handgrade' && $perm{'mgr'}) {
1.41 ng 10886: $request->print(&processHandGrade($request));
1.106 albertel 10887: } elsif ($command eq 'editgrades' && $perm{'mgr'}) {
1.41 ng 10888: $request->print(&editgrades($request));
1.106 albertel 10889: } elsif ($command eq 'verify' && $perm{'vgr'}) {
1.41 ng 10890: $request->print(&verifyreceipt($request));
1.400 www 10891: } elsif ($command eq 'processclicker' && $perm{'mgr'}) {
10892: $request->print(&process_clicker($request));
10893: } elsif ($command eq 'processclickerfile' && $perm{'mgr'}) {
10894: $request->print(&process_clicker_file($request));
1.414 www 10895: } elsif ($command eq 'assignclickergrades' && $perm{'mgr'}) {
10896: $request->print(&assign_clicker_grades($request));
1.106 albertel 10897: } elsif ($command eq 'csvform' && $perm{'mgr'}) {
1.72 ng 10898: $request->print(&upcsvScores_form($request));
1.106 albertel 10899: } elsif ($command eq 'csvupload' && $perm{'mgr'}) {
1.41 ng 10900: $request->print(&csvupload($request));
1.106 albertel 10901: } elsif ($command eq 'csvuploadmap' && $perm{'mgr'} ) {
1.41 ng 10902: $request->print(&csvuploadmap($request));
1.246 albertel 10903: } elsif ($command eq 'csvuploadoptions' && $perm{'mgr'}) {
1.257 albertel 10904: if ($env{'form.associate'} ne 'Reverse Association') {
1.246 albertel 10905: $request->print(&csvuploadoptions($request));
1.41 ng 10906: } else {
1.257 albertel 10907: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
10908: $env{'form.upfile_associate'} = 'reverse';
1.41 ng 10909: } else {
1.257 albertel 10910: $env{'form.upfile_associate'} = 'forward';
1.41 ng 10911: }
10912: $request->print(&csvuploadmap($request));
10913: }
1.246 albertel 10914: } elsif ($command eq 'csvuploadassign' && $perm{'mgr'} ) {
10915: $request->print(&csvuploadassign($request));
1.106 albertel 10916: } elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
1.75 albertel 10917: $request->print(&scantron_selectphase($request));
1.203 albertel 10918: } elsif ($command eq 'scantron_warning' && $perm{'mgr'}) {
10919: $request->print(&scantron_do_warning($request));
1.142 albertel 10920: } elsif ($command eq 'scantron_validate' && $perm{'mgr'}) {
10921: $request->print(&scantron_validate_file($request));
1.106 albertel 10922: } elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
1.82 albertel 10923: $request->print(&scantron_process_students($request));
1.157 albertel 10924: } elsif ($command eq 'scantronupload' &&
1.257 albertel 10925: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
10926: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.162 albertel 10927: $request->print(&scantron_upload_scantron_data($request));
1.157 albertel 10928: } elsif ($command eq 'scantronupload_save' &&
1.257 albertel 10929: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
10930: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.157 albertel 10931: $request->print(&scantron_upload_scantron_data_save($request));
1.202 albertel 10932: } elsif ($command eq 'scantron_download' &&
1.257 albertel 10933: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.162 albertel 10934: $request->print(&scantron_download_scantron_data($request));
1.523 raeburn 10935: } elsif ($command eq 'checksubmissions' && $perm{'vgr'}) {
10936: $request->print(&checkscantron_results($request));
1.106 albertel 10937: } elsif ($command) {
1.562 bisitz 10938: $request->print('<p class="LC_error">'.&mt('Access Denied ([_1])',$command).'</p>');
1.26 albertel 10939: }
1.2 albertel 10940: }
1.513 foxr 10941: if ($ssi_error) {
10942: &ssi_print_error($request);
10943: }
1.353 albertel 10944: $request->print(&Apache::loncommon::end_page());
1.434 albertel 10945: &reset_caches();
1.596.2.4 raeburn 10946: return OK;
1.44 ng 10947: }
10948:
1.1 albertel 10949: 1;
10950:
1.13 albertel 10951: __END__;
1.531 jms 10952:
10953:
10954: =head1 NAME
10955:
10956: Apache::grades
10957:
10958: =head1 SYNOPSIS
10959:
10960: Handles the viewing of grades.
10961:
10962: This is part of the LearningOnline Network with CAPA project
10963: described at http://www.lon-capa.org.
10964:
10965: =head1 OVERVIEW
10966:
10967: Do an ssi with retries:
10968: While I'd love to factor out this with the vesrion in lonprintout,
10969: 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
10970: I'm not quite ready to invent (e.g. an ssi_with_retry object).
10971:
10972: At least the logic that drives this has been pulled out into loncommon.
10973:
10974:
10975:
10976: ssi_with_retries - Does the server side include of a resource.
10977: if the ssi call returns an error we'll retry it up to
10978: the number of times requested by the caller.
1.596.2.12.2. 8(raebur 10979:4): If we still have a problem, no text is appended to the
1.531 jms 10980: output and we set some global variables.
10981: to indicate to the caller an SSI error occurred.
10982: All of this is supposed to deal with the issues described
1.596.2.12.2. 8(raebur 10983:4): in LON-CAPA BZ 5631 see:
1.531 jms 10984: http://bugs.lon-capa.org/show_bug.cgi?id=5631
10985: by informing the user that this happened.
10986:
10987: Parameters:
10988: resource - The resource to include. This is passed directly, without
10989: interpretation to lonnet::ssi.
10990: form - The form hash parameters that guide the interpretation of the resource
10991:
10992: retries - Number of retries allowed before giving up completely.
10993: Returns:
10994: On success, returns the rendered resource identified by the resource parameter.
10995: Side Effects:
10996: The following global variables can be set:
10997: ssi_error - If an unrecoverable error occurred this becomes true.
10998: It is up to the caller to initialize this to false
10999: if desired.
11000: ssi_error_resource - If an unrecoverable error occurred, this is the value
11001: of the resource that could not be rendered by the ssi
11002: call.
11003: ssi_error_message - The error string fetched from the ssi response
11004: in the event of an error.
11005:
11006:
11007: =head1 HANDLER SUBROUTINE
11008:
11009: ssi_with_retries()
11010:
11011: =head1 SUBROUTINES
11012:
11013: =over
11014:
11015: =item scantron_get_correction() :
11016:
11017: Builds the interface screen to interact with the operator to fix a
11018: specific error condition in a specific scanline
11019:
11020: Arguments:
11021: $r - Apache request object
11022: $i - number of the current scanline
11023: $scan_record - hash ref as returned from &scantron_parse_scanline()
11024: $scan_config - hash ref as returned from &get_scantron_config()
11025: $line - full contents of the current scanline
11026: $error - error condition, valid values are
11027: 'incorrectCODE', 'duplicateCODE',
11028: 'doublebubble', 'missingbubble',
11029: 'duplicateID', 'incorrectID'
11030: $arg - extra information needed
11031: For errors:
11032: - duplicateID - paper number that this studentID was seen before on
11033: - duplicateCODE - array ref of the paper numbers this CODE was
11034: seen on before
11035: - incorrectCODE - current incorrect CODE
11036: - doublebubble - array ref of the bubble lines that have double
11037: bubble errors
11038: - missingbubble - array ref of the bubble lines that have missing
11039: bubble errors
11040:
1.596.2.12.2. 6(raebur 11041:3): $randomorder - True if exam folder has randomorder set
11042:3): $randompick - True if exam folder has randompick set
11043:3): $respnumlookup - Reference to HASH mapping question numbers in bubble lines
11044:3): for current line to question number used for same question
11045:3): in "Master Seqence" (as seen by Course Coordinator).
11046:3): $startline - Reference to hash where key is question number (0 is first)
11047:3): and value is number of first bubble line for current student
11048:3): or code-based randompick and/or randomorder.
11049:3):
11050:3):
1.531 jms 11051: =item scantron_get_maxbubble() :
11052:
1.582 raeburn 11053: Arguments:
11054: $nav_error - Reference to scalar which is a flag to indicate a
11055: failure to retrieve a navmap object.
11056: if $nav_error is set to 1 by scantron_get_maxbubble(), the
11057: calling routine should trap the error condition and display the warning
11058: found in &navmap_errormsg().
11059:
1.596.2.12.2. (raeburn 11060:): $scantron_config - Reference to bubblesheet format configuration hash.
11061:):
1.531 jms 11062: Returns the maximum number of bubble lines that are expected to
11063: occur. Does this by walking the selected sequence rendering the
11064: resource and then checking &Apache::lonxml::get_problem_counter()
11065: for what the current value of the problem counter is.
11066:
11067: Caches the results to $env{'form.scantron_maxbubble'},
11068: $env{'form.scantron.bubble_lines.n'},
11069: $env{'form.scantron.first_bubble_line.n'} and
11070: $env{"form.scantron.sub_bubblelines.n"}
1.596.2.12.2. 6(raebur 11071:3): which are the total number of bubble lines, the number of bubble
1.531 jms 11072: lines for response n and number of the first bubble line for response n,
11073: and a comma separated list of numbers of bubble lines for sub-questions
11074: (for optionresponse, matchresponse, and rankresponse items), for response n.
11075:
11076:
11077: =item scantron_validate_missingbubbles() :
11078:
11079: Validates all scanlines in the selected file to not have any
11080: answers that don't have bubbles that have not been verified
11081: to be bubble free.
11082:
11083: =item scantron_process_students() :
11084:
1.596.2.6 raeburn 11085: Routine that does the actual grading of the bubblesheet information.
1.531 jms 11086:
11087: The parsed scanline hash is added to %env
11088:
11089: Then foreach unskipped scanline it does an &Apache::lonnet::ssi()
11090: foreach resource , with the form data of
11091:
11092: 'submitted' =>'scantron'
11093: 'grade_target' =>'grade',
11094: 'grade_username'=> username of student
11095: 'grade_domain' => domain of student
11096: 'grade_courseid'=> of course
11097: 'grade_symb' => symb of resource to grade
11098:
11099: This triggers a grading pass. The problem grading code takes care
11100: of converting the bubbled letter information (now in %env) into a
11101: valid submission.
11102:
11103: =item scantron_upload_scantron_data() :
11104:
1.596.2.6 raeburn 11105: Creates the screen for adding a new bubblesheet data file to a course.
1.531 jms 11106:
11107: =item scantron_upload_scantron_data_save() :
11108:
11109: Adds a provided bubble information data file to the course if user
11110: has the correct privileges to do so.
11111:
11112: =item valid_file() :
11113:
11114: Validates that the requested bubble data file exists in the course.
11115:
11116: =item scantron_download_scantron_data() :
11117:
11118: Shows a list of the three internal files (original, corrected,
1.596.2.6 raeburn 11119: skipped) for a specific bubblesheet data file that exists in the
1.531 jms 11120: course.
11121:
11122: =item scantron_validate_ID() :
11123:
11124: Validates all scanlines in the selected file to not have any
1.556 weissno 11125: invalid or underspecified student/employee IDs
1.531 jms 11126:
1.582 raeburn 11127: =item navmap_errormsg() :
11128:
11129: Returns HTML mark-up inside a <div></div> with a link to re-initialize the course.
11130: Should be called whenever the request to instantiate a navmap object fails.
11131:
1.531 jms 11132: =back
11133:
11134: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>