Annotation of loncom/homework/grades.pm, revision 1.596.2.12.2.5
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. (raeburn 4:): # $Id: grades.pm,v 1.596.2.12.2.4 2012/05/02 15:28:09 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.170 albertel 47: use String::Similarity;
1.359 www 48: use LONCAPA;
49:
1.315 bowersj2 50: use POSIX qw(floor);
1.87 www 51:
1.435 foxr 52:
1.513 foxr 53:
1.435 foxr 54: my %perm=();
1.447 foxr 55:
1.513 foxr 56: # These variables are used to recover from ssi errors
57:
58: my $ssi_retries = 5;
59: my $ssi_error;
60: my $ssi_error_resource;
61: my $ssi_error_message;
62:
63:
64: sub ssi_with_retries {
65: my ($resource, $retries, %form) = @_;
66: my ($content, $response) = &Apache::loncommon::ssi_with_retries($resource, $retries, %form);
67: if ($response->is_error) {
68: $ssi_error = 1;
69: $ssi_error_resource = $resource;
70: $ssi_error_message = $response->code . " " . $response->message;
71: }
72:
73: return $content;
74:
75: }
76: #
77: # Prodcuces an ssi retry failure error message to the user:
78: #
79:
80: sub ssi_print_error {
81: my ($r) = @_;
1.516 raeburn 82: my $helpurl = &Apache::loncommon::top_nav_help('Helpdesk');
83: $r->print('
84: <br />
85: <h2>'.&mt('An unrecoverable network error occurred:').'</h2>
86: <p>
87: '.&mt('Unable to retrieve a resource from a server:').'<br />
88: '.&mt('Resource:').' '.$ssi_error_resource.'<br />
89: '.&mt('Error:').' '.$ssi_error_message.'
90: </p>
91: <p>'.
92: &mt('It is recommended that you try again later, as this error may mean the server was just temporarily unavailable, or is down for maintenance.').'<br />'.
93: &mt('If the error persists, please contact the [_1] for assistance.',$helpurl).
94: '</p>');
95: return;
1.513 foxr 96: }
97:
1.44 ng 98: #
1.146 albertel 99: # --- Retrieve the parts from the metadata file.---
1.44 ng 100: sub getpartlist {
1.582 raeburn 101: my ($symb,$errorref) = @_;
1.439 albertel 102:
103: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 104: unless (ref($navmap)) {
105: if (ref($errorref)) {
106: $$errorref = 'navmap';
107: return;
108: }
109: }
1.439 albertel 110: my $res = $navmap->getBySymb($symb);
111: my $partlist = $res->parts();
112: my $url = $res->src();
113: my @metakeys = split(/,/,&Apache::lonnet::metadata($url,'keys'));
114:
1.146 albertel 115: my @stores;
1.439 albertel 116: foreach my $part (@{ $partlist }) {
1.146 albertel 117: foreach my $key (@metakeys) {
118: if ($key =~ m/^stores_\Q$part\E_/) { push(@stores,$key); }
119: }
120: }
121: return @stores;
1.2 albertel 122: }
123:
1.44 ng 124: # --- Get the symbolic name of a problem and the url
1.324 albertel 125: sub get_symb {
1.173 albertel 126: my ($request,$silent) = @_;
1.257 albertel 127: (my $url=$env{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
128: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
1.173 albertel 129: if ($symb eq '') {
130: if (!$silent) {
1.596.2.4 raeburn 131: $request->print(&mt("Unable to handle ambiguous references: [_1].",$url));
1.173 albertel 132: return ();
133: }
134: }
1.418 albertel 135: &Apache::lonenc::check_decrypt(\$symb);
1.324 albertel 136: return ($symb);
1.32 ng 137: }
138:
1.129 ng 139: #--- Format fullname, username:domain if different for display
140: #--- Use anywhere where the student names are listed
141: sub nameUserString {
142: my ($type,$fullname,$uname,$udom) = @_;
143: if ($type eq 'header') {
1.485 albertel 144: return '<b> '.&mt('Fullname').' </b><span class="LC_internal_info">('.&mt('Username').')</span>';
1.129 ng 145: } else {
1.398 albertel 146: return ' '.$fullname.'<span class="LC_internal_info"> ('.$uname.
147: ($env{'user.domain'} eq $udom ? '' : ' ('.$udom.')').')</span>';
1.129 ng 148: }
149: }
150:
1.44 ng 151: #--- Get the partlist and the response type for a given problem. ---
152: #--- Indicate if a response type is coded handgraded or not. ---
1.39 ng 153: sub response_type {
1.582 raeburn 154: my ($symb,$response_error) = @_;
1.377 albertel 155:
156: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 157: unless (ref($navmap)) {
158: if (ref($response_error)) {
159: $$response_error = 1;
160: }
161: return;
162: }
1.377 albertel 163: my $res = $navmap->getBySymb($symb);
1.593 raeburn 164: unless (ref($res)) {
165: $$response_error = 1;
166: return;
167: }
1.377 albertel 168: my $partlist = $res->parts();
1.392 albertel 169: my %vPart =
170: map { $_ => 1 } (&Apache::loncommon::get_env_multiple('form.vPart'));
1.377 albertel 171: my (%response_types,%handgrade);
172: foreach my $part (@{ $partlist }) {
1.392 albertel 173: next if (%vPart && !exists($vPart{$part}));
174:
1.377 albertel 175: my @types = $res->responseType($part);
176: my @ids = $res->responseIds($part);
177: for (my $i=0; $i < scalar(@ids); $i++) {
178: $response_types{$part}{$ids[$i]} = $types[$i];
179: $handgrade{$part.'_'.$ids[$i]} =
180: &Apache::lonnet::EXT('resource.'.$part.'_'.$ids[$i].
181: '.handgrade',$symb);
1.41 ng 182: }
183: }
1.377 albertel 184: return ($partlist,\%handgrade,\%response_types);
1.39 ng 185: }
186:
1.375 albertel 187: sub flatten_responseType {
188: my ($responseType) = @_;
189: my @part_response_id =
190: map {
191: my $part = $_;
192: map {
193: [$part,$_]
194: } sort(keys(%{ $responseType->{$part} }));
195: } sort(keys(%$responseType));
196: return @part_response_id;
197: }
198:
1.207 albertel 199: sub get_display_part {
1.324 albertel 200: my ($partID,$symb)=@_;
1.207 albertel 201: my $display=&Apache::lonnet::EXT('resource.'.$partID.'.display',$symb);
202: if (defined($display) and $display ne '') {
1.577 bisitz 203: $display.= ' (<span class="LC_internal_info">'
204: .&mt('Part ID: [_1]',$partID).'</span>)';
1.207 albertel 205: } else {
206: $display=$partID;
207: }
208: return $display;
209: }
1.269 raeburn 210:
1.118 ng 211: #--- Show resource title
212: #--- and parts and response type
213: sub showResourceInfo {
1.582 raeburn 214: my ($symb,$probTitle,$checkboxes,$res_error) = @_;
1.398 albertel 215: my $result = '<h3>'.&mt('Current Resource').': '.$probTitle.'</h3>'."\n";
1.582 raeburn 216: my ($partlist,$handgrade,$responseType) = &response_type($symb,$res_error);
217: if (ref($res_error)) {
218: if ($$res_error) {
219: return;
220: }
221: }
1.584 bisitz 222: $result.=&Apache::loncommon::start_data_table()
223: .&Apache::loncommon::start_data_table_header_row();
224: if ($checkboxes) {
225: $result.='<th> </th>';
226: }
227: $result.='<th>'.&mt('Problem Part').'</th>'
228: .'<th>'.&mt('Res. ID').'</th>'
229: .'<th>'.&mt('Type').'</th>'
230: .&Apache::loncommon::end_data_table_header_row();
1.126 ng 231: my %resptype = ();
1.122 ng 232: my $hdgrade='no';
1.154 albertel 233: my %partsseen;
1.524 raeburn 234: foreach my $partID (sort(keys(%$responseType))) {
1.584 bisitz 235: foreach my $resID (sort(keys(%{ $responseType->{$partID} }))) {
236: my $handgrade=$$handgrade{$partID.'_'.$resID};
237: my $responsetype = $responseType->{$partID}->{$resID};
238: $hdgrade = $handgrade if ($handgrade eq 'yes');
239: $result.=&Apache::loncommon::start_data_table_row();
240: if ($checkboxes) {
241: if (exists($partsseen{$partID})) {
242: $result.="<td> </td>";
243: } else {
244: $result.="<td><input type='checkbox' name='vPart' value='$partID' checked='checked' /></td>";
245: }
246: $partsseen{$partID}=1;
247: }
248: my $display_part=&get_display_part($partID,$symb);
249: $result.='<td>'.$display_part.'</td>'
250: .'<td>'.'<span class="LC_internal_info">'.$resID.'</span></td>'
251: .'<td>'.&mt($responsetype).'</td>'
252: # .'<td>'.&mt('<b>Handgrade: </b>[_1]',$handgrade).'</td>'
253: .&Apache::loncommon::end_data_table_row();
254: }
1.118 ng 255: }
1.584 bisitz 256: $result.=&Apache::loncommon::end_data_table();
1.147 albertel 257: return $result,$responseType,$hdgrade,$partlist,$handgrade;
1.118 ng 258: }
259:
1.434 albertel 260: sub reset_caches {
261: &reset_analyze_cache();
262: &reset_perm();
263: }
264:
265: {
266: my %analyze_cache;
1.557 raeburn 267: my %analyze_cache_formkeys;
1.148 albertel 268:
1.434 albertel 269: sub reset_analyze_cache {
270: undef(%analyze_cache);
1.557 raeburn 271: undef(%analyze_cache_formkeys);
1.434 albertel 272: }
273:
274: sub get_analyze {
1.596.2.12.2. (raeburn 275:): my ($symb,$uname,$udom,$no_increment,$add_to_hash,$type,$trial,$rndseed,$bubbles_per_row)=@_;
1.434 albertel 276: my $key = "$symb\0$uname\0$udom";
1.596.2.2 raeburn 277: if ($type eq 'randomizetry') {
278: if ($trial ne '') {
279: $key .= "\0".$trial;
280: }
281: }
1.557 raeburn 282: if (exists($analyze_cache{$key})) {
283: my $getupdate = 0;
284: if (ref($add_to_hash) eq 'HASH') {
285: foreach my $item (keys(%{$add_to_hash})) {
286: if (ref($analyze_cache_formkeys{$key}) eq 'HASH') {
287: if (!exists($analyze_cache_formkeys{$key}{$item})) {
288: $getupdate = 1;
289: last;
290: }
291: } else {
292: $getupdate = 1;
293: }
294: }
295: }
296: if (!$getupdate) {
297: return $analyze_cache{$key};
298: }
299: }
1.434 albertel 300:
301: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
302: $url=&Apache::lonnet::clutter($url);
1.557 raeburn 303: my %form = ('grade_target' => 'analyze',
304: 'grade_domain' => $udom,
305: 'grade_symb' => $symb,
306: 'grade_courseid' => $env{'request.course.id'},
307: 'grade_username' => $uname,
308: 'grade_noincrement' => $no_increment);
1.596.2.12.2. (raeburn 309:): if ($bubbles_per_row ne '') {
310:): $form{'bubbles_per_row'} = $bubbles_per_row;
311:): }
1.596.2.2 raeburn 312: if ($type eq 'randomizetry') {
313: $form{'grade_questiontype'} = $type;
314: if ($rndseed ne '') {
315: $form{'grade_rndseed'} = $rndseed;
316: }
317: }
1.557 raeburn 318: if (ref($add_to_hash)) {
319: %form = (%form,%{$add_to_hash});
1.596.2.2 raeburn 320: }
1.557 raeburn 321: my $subresult=&ssi_with_retries($url, $ssi_retries,%form);
1.434 albertel 322: (undef,$subresult)=split(/_HASH_REF__/,$subresult,2);
323: my %analyze=&Apache::lonnet::str2hash($subresult);
1.557 raeburn 324: if (ref($add_to_hash) eq 'HASH') {
325: $analyze_cache_formkeys{$key} = $add_to_hash;
326: } else {
327: $analyze_cache_formkeys{$key} = {};
328: }
1.434 albertel 329: return $analyze_cache{$key} = \%analyze;
330: }
331:
332: sub get_order {
1.596.2.2 raeburn 333: my ($partid,$respid,$symb,$uname,$udom,$no_increment,$type,$trial,$rndseed)=@_;
334: my $analyze = &get_analyze($symb,$uname,$udom,$no_increment,undef,$type,$trial,$rndseed);
1.434 albertel 335: return $analyze->{"$partid.$respid.shown"};
336: }
337:
338: sub get_radiobutton_correct_foil {
1.596.2.2 raeburn 339: my ($partid,$respid,$symb,$uname,$udom,$type,$trial,$rndseed)=@_;
340: my $analyze = &get_analyze($symb,$uname,$udom,undef,undef,$type,$trial,$rndseed);
341: my $foils = &get_order($partid,$respid,$symb,$uname,$udom,undef,$type,$trial,$rndseed);
1.555 raeburn 342: if (ref($foils) eq 'ARRAY') {
343: foreach my $foil (@{$foils}) {
344: if ($analyze->{"$partid.$respid.foil.value.$foil"} eq 'true') {
345: return $foil;
346: }
1.434 albertel 347: }
348: }
349: }
1.554 raeburn 350:
351: sub scantron_partids_tograde {
1.596.2.12.2. (raeburn 352:): my ($resource,$cid,$uname,$udom,$check_for_randomlist,$bubbles_per_row) = @_;
1.554 raeburn 353: my (%analysis,@parts);
354: if (ref($resource)) {
355: my $symb = $resource->symb();
1.557 raeburn 356: my $add_to_form;
357: if ($check_for_randomlist) {
358: $add_to_form = { 'check_parts_withrandomlist' => 1,};
359: }
1.596.2.12.2. (raeburn 360:): my $analyze =
361:): &get_analyze($symb,$uname,$udom,undef,$add_to_form,
362:): undef,undef,undef,$bubbles_per_row);
1.554 raeburn 363: if (ref($analyze) eq 'HASH') {
364: %analysis = %{$analyze};
365: }
366: if (ref($analysis{'parts'}) eq 'ARRAY') {
367: foreach my $part (@{$analysis{'parts'}}) {
368: my ($id,$respid) = split(/\./,$part);
369: if (!&Apache::loncommon::check_if_partid_hidden($id,$symb,$udom,$uname)) {
370: push(@parts,$part);
371: }
372: }
373: }
374: }
375: return (\%analysis,\@parts);
376: }
377:
1.148 albertel 378: }
1.434 albertel 379:
1.118 ng 380: #--- Clean response type for display
1.335 albertel 381: #--- Currently filters option/rank/radiobutton/match/essay/Task
382: # response types only.
1.118 ng 383: sub cleanRecord {
1.336 albertel 384: my ($answer,$response,$symb,$partid,$respid,$record,$order,$version,
1.596.2.2 raeburn 385: $uname,$udom,$type,$trial,$rndseed) = @_;
1.398 albertel 386: my $grayFont = '<span class="LC_internal_info">';
1.148 albertel 387: if ($response =~ /^(option|rank)$/) {
388: my %answer=&Apache::lonnet::str2hash($answer);
389: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
390: my ($toprow,$bottomrow);
391: foreach my $foil (@$order) {
392: if ($grading{$foil} == 1) {
393: $toprow.='<td><b>'.$answer{$foil}.' </b></td>';
394: } else {
395: $toprow.='<td><i>'.$answer{$foil}.' </i></td>';
396: }
1.398 albertel 397: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.148 albertel 398: }
399: return '<blockquote><table border="1">'.
1.466 albertel 400: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
401: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.596.2.1 raeburn 402: $bottomrow.'</tr></table></blockquote>';
1.148 albertel 403: } elsif ($response eq 'match') {
404: my %answer=&Apache::lonnet::str2hash($answer);
405: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
406: my @items=&Apache::lonnet::str2array($record->{$version."resource.$partid.$respid.submissionitems"});
407: my ($toprow,$middlerow,$bottomrow);
408: foreach my $foil (@$order) {
409: my $item=shift(@items);
410: if ($grading{$foil} == 1) {
411: $toprow.='<td><b>'.$item.' </b></td>';
1.398 albertel 412: $middlerow.='<td><b>'.$grayFont.$answer{$foil}.' </span></b></td>';
1.148 albertel 413: } else {
414: $toprow.='<td><i>'.$item.' </i></td>';
1.398 albertel 415: $middlerow.='<td><i>'.$grayFont.$answer{$foil}.' </span></i></td>';
1.148 albertel 416: }
1.398 albertel 417: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.118 ng 418: }
1.126 ng 419: return '<blockquote><table border="1">'.
1.466 albertel 420: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
421: '<tr valign="top"><td>'.$grayFont.&mt('Item ID').'</span></td>'.
1.148 albertel 422: $middlerow.'</tr>'.
1.466 albertel 423: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.596.2.8 raeburn 424: $bottomrow.'</tr></table></blockquote>';
1.148 albertel 425: } elsif ($response eq 'radiobutton') {
426: my %answer=&Apache::lonnet::str2hash($answer);
427: my ($toprow,$bottomrow);
1.434 albertel 428: my $correct =
1.596.2.2 raeburn 429: &get_radiobutton_correct_foil($partid,$respid,$symb,$uname,$udom,$type,$trial,$rndseed);
1.434 albertel 430: foreach my $foil (@$order) {
1.148 albertel 431: if (exists($answer{$foil})) {
1.434 albertel 432: if ($foil eq $correct) {
1.466 albertel 433: $toprow.='<td><b>'.&mt('true').'</b></td>';
1.148 albertel 434: } else {
1.466 albertel 435: $toprow.='<td><i>'.&mt('true').'</i></td>';
1.148 albertel 436: }
437: } else {
1.466 albertel 438: $toprow.='<td>'.&mt('false').'</td>';
1.148 albertel 439: }
1.398 albertel 440: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.148 albertel 441: }
442: return '<blockquote><table border="1">'.
1.466 albertel 443: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
444: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.596.2.4 raeburn 445: $bottomrow.'</tr></table></blockquote>';
1.148 albertel 446: } elsif ($response eq 'essay') {
1.257 albertel 447: if (! exists ($env{'form.'.$symb})) {
1.122 ng 448: my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 449: $env{'course.'.$env{'request.course.id'}.'.domain'},
450: $env{'course.'.$env{'request.course.id'}.'.num'});
1.122 ng 451:
1.257 albertel 452: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
453: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
454: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
455: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
456: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
457: $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 458: }
1.166 albertel 459: $answer =~ s-\n-<br />-g;
460: return '<br /><br /><blockquote><tt>'.&keywords_highlight($answer).'</tt></blockquote>';
1.268 albertel 461: } elsif ( $response eq 'organic') {
462: my $result='Smile representation: "<tt>'.$answer.'</tt>"';
463: my $jme=$record->{$version."resource.$partid.$respid.molecule"};
464: $result.=&Apache::chemresponse::jme_img($jme,$answer,400);
465: return $result;
1.335 albertel 466: } elsif ( $response eq 'Task') {
467: if ( $answer eq 'SUBMITTED') {
468: my $files = $record->{$version."resource.$respid.$partid.bridgetask.portfiles"};
1.336 albertel 469: my $result = &Apache::bridgetask::file_list($files,$uname,$udom);
1.335 albertel 470: return $result;
471: } elsif ( grep(/^\Q$version\E.*?\.instance$/, keys(%{$record})) ) {
472: my @matches = grep(/^\Q$version\E.*?\.instance$/,
473: keys(%{$record}));
474: return join('<br />',($version,@matches));
475:
476:
477: } else {
478: my $result =
479: '<p>'
480: .&mt('Overall result: [_1]',
481: $record->{$version."resource.$respid.$partid.status"})
482: .'</p>';
483:
484: $result .= '<ul>';
485: my @grade = grep(/^\Q${version}resource.$respid.$partid.\E[^.]*[.]status$/,
486: keys(%{$record}));
487: foreach my $grade (sort(@grade)) {
488: my ($dim) = ($grade =~/[.]([^.]+)[.]status$/);
489: $result.= '<li>'.&mt("Dimension: [_1], status [_2] ",
490: $dim, $record->{$grade}).
491: '</li>';
492: }
493: $result.='</ul>';
494: return $result;
495: }
1.440 albertel 496: } elsif ( $response =~ m/(?:numerical|formula)/) {
497: $answer =
498: &Apache::loncommon::format_previous_attempt_value('submission',
499: $answer);
1.122 ng 500: }
1.118 ng 501: return $answer;
502: }
503:
504: #-- A couple of common js functions
505: sub commonJSfunctions {
506: my $request = shift;
507: $request->print(<<COMMONJSFUNCTIONS);
508: <script type="text/javascript" language="javascript">
509: function radioSelection(radioButton) {
510: var selection=null;
511: if (radioButton.length > 1) {
512: for (var i=0; i<radioButton.length; i++) {
513: if (radioButton[i].checked) {
514: return radioButton[i].value;
515: }
516: }
517: } else {
518: if (radioButton.checked) return radioButton.value;
519: }
520: return selection;
521: }
522:
523: function pullDownSelection(selectOne) {
524: var selection="";
525: if (selectOne.length > 1) {
526: for (var i=0; i<selectOne.length; i++) {
527: if (selectOne[i].selected) {
528: return selectOne[i].value;
529: }
530: }
531: } else {
1.138 albertel 532: // only one value it must be the selected one
533: return selectOne.value;
1.118 ng 534: }
535: }
536: </script>
537: COMMONJSFUNCTIONS
538: }
539:
1.44 ng 540: #--- Dumps the class list with usernames,list of sections,
541: #--- section, ids and fullnames for each user.
542: sub getclasslist {
1.449 banghart 543: my ($getsec,$filterlist,$getgroup) = @_;
1.291 albertel 544: my @getsec;
1.450 banghart 545: my @getgroup;
1.442 banghart 546: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.291 albertel 547: if (!ref($getsec)) {
548: if ($getsec ne '' && $getsec ne 'all') {
549: @getsec=($getsec);
550: }
551: } else {
552: @getsec=@{$getsec};
553: }
554: if (grep(/^all$/,@getsec)) { undef(@getsec); }
1.450 banghart 555: if (!ref($getgroup)) {
556: if ($getgroup ne '' && $getgroup ne 'all') {
557: @getgroup=($getgroup);
558: }
559: } else {
560: @getgroup=@{$getgroup};
561: }
562: if (grep(/^all$/,@getgroup)) { undef(@getgroup); }
1.291 albertel 563:
1.449 banghart 564: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
1.49 albertel 565: # Bail out if we were unable to get the classlist
1.56 matthew 566: return if (! defined($classlist));
1.449 banghart 567: &Apache::loncoursedata::get_group_memberships($classlist,$keylist);
1.56 matthew 568: #
569: my %sections;
570: my %fullnames;
1.205 matthew 571: foreach my $student (keys(%$classlist)) {
572: my $end =
573: $classlist->{$student}->[&Apache::loncoursedata::CL_END()];
574: my $start =
575: $classlist->{$student}->[&Apache::loncoursedata::CL_START()];
576: my $id =
577: $classlist->{$student}->[&Apache::loncoursedata::CL_ID()];
578: my $section =
579: $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
580: my $fullname =
581: $classlist->{$student}->[&Apache::loncoursedata::CL_FULLNAME()];
582: my $status =
583: $classlist->{$student}->[&Apache::loncoursedata::CL_STATUS()];
1.449 banghart 584: my $group =
585: $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1.76 ng 586: # filter students according to status selected
1.442 banghart 587: if ($filterlist && (!($stu_status =~ /Any/))) {
588: if (!($stu_status =~ $status)) {
1.450 banghart 589: delete($classlist->{$student});
1.76 ng 590: next;
591: }
592: }
1.450 banghart 593: # filter students according to groups selected
1.453 banghart 594: my @stu_groups = split(/,/,$group);
1.450 banghart 595: if (@getgroup) {
596: my $exclude = 1;
1.454 banghart 597: foreach my $grp (@getgroup) {
598: foreach my $stu_group (@stu_groups) {
1.453 banghart 599: if ($stu_group eq $grp) {
600: $exclude = 0;
601: }
1.450 banghart 602: }
1.453 banghart 603: if (($grp eq 'none') && !$group) {
604: $exclude = 0;
605: }
1.450 banghart 606: }
607: if ($exclude) {
608: delete($classlist->{$student});
609: }
610: }
1.205 matthew 611: $section = ($section ne '' ? $section : 'none');
1.106 albertel 612: if (&canview($section)) {
1.291 albertel 613: if (!@getsec || grep(/^\Q$section\E$/,@getsec)) {
1.103 albertel 614: $sections{$section}++;
1.450 banghart 615: if ($classlist->{$student}) {
616: $fullnames{$student}=$fullname;
617: }
1.103 albertel 618: } else {
1.205 matthew 619: delete($classlist->{$student});
1.103 albertel 620: }
621: } else {
1.205 matthew 622: delete($classlist->{$student});
1.103 albertel 623: }
1.44 ng 624: }
625: my %seen = ();
1.56 matthew 626: my @sections = sort(keys(%sections));
627: return ($classlist,\@sections,\%fullnames);
1.44 ng 628: }
629:
1.103 albertel 630: sub canmodify {
631: my ($sec)=@_;
632: if ($perm{'mgr'}) {
633: if (!defined($perm{'mgr_section'})) {
634: # can modify whole class
635: return 1;
636: } else {
637: if ($sec eq $perm{'mgr_section'}) {
638: #can modify the requested section
639: return 1;
640: } else {
641: # can't modify the request section
642: return 0;
643: }
644: }
645: }
646: #can't modify
647: return 0;
648: }
649:
650: sub canview {
651: my ($sec)=@_;
652: if ($perm{'vgr'}) {
653: if (!defined($perm{'vgr_section'})) {
654: # can modify whole class
655: return 1;
656: } else {
657: if ($sec eq $perm{'vgr_section'}) {
658: #can modify the requested section
659: return 1;
660: } else {
661: # can't modify the request section
662: return 0;
663: }
664: }
665: }
666: #can't modify
667: return 0;
668: }
669:
1.44 ng 670: #--- Retrieve the grade status of a student for all the parts
671: sub student_gradeStatus {
1.324 albertel 672: my ($symb,$udom,$uname,$partlist) = @_;
1.257 albertel 673: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.44 ng 674: my %partstatus = ();
675: foreach (@$partlist) {
1.128 ng 676: my ($status,undef) = split(/_/,$record{"resource.$_.solved"},2);
1.44 ng 677: $status = 'nothing' if ($status eq '');
678: $partstatus{$_} = $status;
679: my $subkey = "resource.$_.submitted_by";
680: $partstatus{$subkey} = $record{$subkey} if ($record{$subkey} ne '');
681: }
682: return %partstatus;
683: }
684:
1.45 ng 685: # hidden form and javascript that calls the form
686: # Use by verifyscript and viewgrades
687: # Shows a student's view of problem and submission
688: sub jscriptNform {
1.324 albertel 689: my ($symb) = @_;
1.442 banghart 690: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.45 ng 691: my $jscript='<script type="text/javascript" language="javascript">'."\n".
692: ' function viewOneStudent(user,domain) {'."\n".
693: ' document.onestudent.student.value = user;'."\n".
694: ' document.onestudent.userdom.value = domain;'."\n".
695: ' document.onestudent.submit();'."\n".
696: ' }'."\n".
697: '</script>'."\n";
698: $jscript.= '<form action="/adm/grades" method="post" name="onestudent">'."\n".
1.418 albertel 699: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 700: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
701: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.442 banghart 702: '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.45 ng 703: '<input type="hidden" name="command" value="submission" />'."\n".
704: '<input type="hidden" name="student" value="" />'."\n".
705: '<input type="hidden" name="userdom" value="" />'."\n".
706: '</form>'."\n";
707: return $jscript;
708: }
1.39 ng 709:
1.447 foxr 710:
711:
1.315 bowersj2 712: # Given the score (as a number [0-1] and the weight) what is the final
713: # point value? This function will round to the nearest tenth, third,
714: # or quarter if one of those is within the tolerance of .00001.
1.316 albertel 715: sub compute_points {
1.315 bowersj2 716: my ($score, $weight) = @_;
717:
718: my $tolerance = .00001;
719: my $points = $score * $weight;
720:
721: # Check for nearness to 1/x.
722: my $check_for_nearness = sub {
723: my ($factor) = @_;
724: my $num = ($points * $factor) + $tolerance;
725: my $floored_num = floor($num);
1.316 albertel 726: if ($num - $floored_num < 2 * $tolerance * $factor) {
1.315 bowersj2 727: return $floored_num / $factor;
728: }
729: return $points;
730: };
731:
732: $points = $check_for_nearness->(10);
733: $points = $check_for_nearness->(3);
734: $points = $check_for_nearness->(4);
735:
736: return $points;
737: }
738:
1.44 ng 739: #------------------ End of general use routines --------------------
1.87 www 740:
741: #
742: # Find most similar essay
743: #
744:
745: sub most_similar {
1.426 albertel 746: my ($uname,$udom,$uessay,$old_essays)=@_;
1.87 www 747:
748: # ignore spaces and punctuation
749:
750: $uessay=~s/\W+/ /gs;
751:
1.282 www 752: # ignore empty submissions (occuring when only files are sent)
753:
1.596.2.4 raeburn 754: unless ($uessay=~/\w+/s) { return ''; }
1.282 www 755:
1.87 www 756: # these will be returned. Do not care if not at least 50 percent similar
1.88 www 757: my $limit=0.6;
1.87 www 758: my $sname='';
759: my $sdom='';
760: my $scrsid='';
761: my $sessay='';
762: # go through all essays ...
1.426 albertel 763: foreach my $tkey (keys(%$old_essays)) {
764: my ($tname,$tdom,$tcrsid)=map {&unescape($_)} (split(/\./,$tkey));
1.87 www 765: # ... except the same student
1.426 albertel 766: next if (($tname eq $uname) && ($tdom eq $udom));
767: my $tessay=$old_essays->{$tkey};
768: $tessay=~s/\W+/ /gs;
1.87 www 769: # String similarity gives up if not even limit
1.426 albertel 770: my $tsimilar=&String::Similarity::similarity($uessay,$tessay,$limit);
1.87 www 771: # Found one
1.426 albertel 772: if ($tsimilar>$limit) {
773: $limit=$tsimilar;
774: $sname=$tname;
775: $sdom=$tdom;
776: $scrsid=$tcrsid;
777: $sessay=$old_essays->{$tkey};
778: }
1.87 www 779: }
1.88 www 780: if ($limit>0.6) {
1.87 www 781: return ($sname,$sdom,$scrsid,$sessay,$limit);
782: } else {
783: return ('','','','',0);
784: }
785: }
786:
1.44 ng 787: #-------------------------------------------------------------------
788:
789: #------------------------------------ Receipt Verification Routines
1.45 ng 790: #
1.44 ng 791: #--- Check whether a receipt number is valid.---
792: sub verifyreceipt {
793: my $request = shift;
794:
1.257 albertel 795: my $courseid = $env{'request.course.id'};
1.184 www 796: my $receipt = &Apache::lonnet::recprefix($courseid).'-'.
1.257 albertel 797: $env{'form.receipt'};
1.44 ng 798: $receipt =~ s/[^\-\d]//g;
1.378 albertel 799: my ($symb) = &get_symb($request);
1.44 ng 800:
1.487 albertel 801: my $title.=
802: '<h3><span class="LC_info">'.
1.584 bisitz 803: &mt('Verifying Receipt No. [_1]',$receipt).
1.487 albertel 804: '</span></h3>'."\n".
805: '<h4>'.&mt('<b>Resource: </b>[_1]',$env{'form.probTitle'}).
806: '</h4>'."\n";
1.44 ng 807:
808: my ($string,$contents,$matches) = ('','',0);
1.56 matthew 809: my (undef,undef,$fullname) = &getclasslist('all','0');
1.177 albertel 810:
811: my $receiptparts=0;
1.390 albertel 812: if ($env{"course.$courseid.receiptalg"} eq 'receipt2' ||
813: $env{"course.$courseid.receiptalg"} eq 'receipt3') { $receiptparts=1; }
1.177 albertel 814: my $parts=['0'];
1.582 raeburn 815: if ($receiptparts) {
816: my $res_error;
817: ($parts)=&response_type($symb,\$res_error);
818: if ($res_error) {
819: return &navmap_errormsg();
820: }
821: }
1.486 albertel 822:
823: my $header =
824: &Apache::loncommon::start_data_table().
825: &Apache::loncommon::start_data_table_header_row().
1.487 albertel 826: '<th> '.&mt('Fullname').' </th>'."\n".
827: '<th> '.&mt('Username').' </th>'."\n".
828: '<th> '.&mt('Domain').' </th>';
1.486 albertel 829: if ($receiptparts) {
1.487 albertel 830: $header.='<th> '.&mt('Problem Part').' </th>';
1.486 albertel 831: }
832: $header.=
833: &Apache::loncommon::end_data_table_header_row();
834:
1.294 albertel 835: foreach (sort
836: {
837: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
838: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
839: }
840: return $a cmp $b;
841: } (keys(%$fullname))) {
1.44 ng 842: my ($uname,$udom)=split(/\:/);
1.177 albertel 843: foreach my $part (@$parts) {
844: if ($receipt eq &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb,$part)) {
1.486 albertel 845: $contents.=
846: &Apache::loncommon::start_data_table_row().
847: '<td> '."\n".
1.177 albertel 848: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 849: '\');" target="_self">'.$$fullname{$_}.'</a> </td>'."\n".
1.177 albertel 850: '<td> '.$uname.' </td>'.
851: '<td> '.$udom.' </td>';
852: if ($receiptparts) {
853: $contents.='<td> '.$part.' </td>';
854: }
1.486 albertel 855: $contents.=
856: &Apache::loncommon::end_data_table_row()."\n";
1.177 albertel 857:
858: $matches++;
859: }
1.44 ng 860: }
861: }
862: if ($matches == 0) {
1.584 bisitz 863: $string = $title
864: .'<p class="LC_warning">'
865: .&mt('No match found for the above receipt number.')
866: .'</p>';
1.44 ng 867: } else {
1.324 albertel 868: $string = &jscriptNform($symb).$title.
1.487 albertel 869: '<p>'.
1.584 bisitz 870: &mt('The above receipt number matches the following [quant,_1,student].',$matches).
1.487 albertel 871: '</p>'.
1.486 albertel 872: $header.
873: $contents.
874: &Apache::loncommon::end_data_table()."\n";
1.44 ng 875: }
1.324 albertel 876: return $string.&show_grading_menu_form($symb);
1.44 ng 877: }
878:
879: #--- This is called by a number of programs.
880: #--- Called from the Grading Menu - View/Grade an individual student
881: #--- Also called directly when one clicks on the subm button
882: # on the problem page.
1.30 ng 883: sub listStudents {
1.41 ng 884: my ($request) = shift;
1.49 albertel 885:
1.324 albertel 886: my ($symb) = &get_symb($request);
1.257 albertel 887: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
888: my $cnum = $env{"course.$env{'request.course.id'}.num"};
889: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.449 banghart 890: my $getgroup = $env{'form.group'} eq '' ? 'all' : $env{'form.group'};
1.257 albertel 891: my $submitonly= $env{'form.submitonly'} eq '' ? 'all' : $env{'form.submitonly'};
1.548 bisitz 892: my $viewgrade = $env{'form.showgrading'} eq 'yes' ? 'View/Grade/Regrade' : 'View';
1.257 albertel 893: $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
894: &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
1.49 albertel 895:
1.548 bisitz 896: my $result='<h3><span class="LC_info"> '
897: .&mt("$viewgrade Submissions for a Student or a Group of Students")
1.485 albertel 898: .'</span></h3>';
1.118 ng 899:
1.324 albertel 900: my ($table,undef,$hdgrade,$partlist,$handgrade) = &showResourceInfo($symb,$env{'form.probTitle'},($env{'form.showgrading'} eq 'yes'));
1.49 albertel 901:
1.559 raeburn 902: my %lt = &Apache::lonlocal::texthash (
903: 'multiple' => 'Please select a student or group of students before clicking on the Next button.',
904: 'single' => 'Please select the student before clicking on the Next button.',
905: );
1.45 ng 906: $request->print(<<LISTJAVASCRIPT);
907: <script type="text/javascript" language="javascript">
1.110 ng 908: function checkSelect(checkBox) {
909: var ctr=0;
910: var sense="";
911: if (checkBox.length > 1) {
912: for (var i=0; i<checkBox.length; i++) {
913: if (checkBox[i].checked) {
914: ctr++;
915: }
916: }
1.485 albertel 917: sense = '$lt{'multiple'}';
1.110 ng 918: } else {
919: if (checkBox.checked) {
920: ctr = 1;
921: }
1.485 albertel 922: sense = '$lt{'single'}';
1.110 ng 923: }
924: if (ctr == 0) {
1.485 albertel 925: alert(sense);
1.110 ng 926: return false;
927: }
928: document.gradesub.submit();
929: }
930:
931: function reLoadList(formname) {
1.112 ng 932: if (formname.saveStatusOld.value == pullDownSelection(formname.Status)) {return;}
1.110 ng 933: formname.command.value = 'submission';
934: formname.submit();
935: }
1.45 ng 936: </script>
937: LISTJAVASCRIPT
938:
1.118 ng 939: &commonJSfunctions($request);
1.41 ng 940: $request->print($result);
1.39 ng 941:
1.401 albertel 942: my $checkhdgrade = ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1 ) ? 'checked="checked"' : '';
943: my $checklastsub = $checkhdgrade eq '' ? 'checked="checked"' : '';
1.154 albertel 944: my $gradeTable='<form action="/adm/grades" method="post" name="gradesub">'.
1.485 albertel 945: "\n".$table;
946:
1.561 bisitz 947: $gradeTable .= &Apache::lonhtmlcommon::start_pick_box();
948: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Problem Text'))
949: .'<label><input type="radio" name="vProb" value="no" checked="checked" /> '.&mt('no').' </label>'."\n"
950: .'<label><input type="radio" name="vProb" value="yes" /> '.&mt('one student').' </label>'."\n"
951: .'<label><input type="radio" name="vProb" value="all" /> '.&mt('all students').' </label><br />'."\n"
952: .&Apache::lonhtmlcommon::row_closure();
953: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Answer'))
954: .'<label><input type="radio" name="vAns" value="no" /> '.&mt('no').' </label>'."\n"
955: .'<label><input type="radio" name="vAns" value="yes" /> '.&mt('one student').' </label>'."\n"
956: .'<label><input type="radio" name="vAns" value="all" checked="checked" /> '.&mt('all students').' </label><br />'."\n"
957: .&Apache::lonhtmlcommon::row_closure();
1.485 albertel 958:
959: my $submission_options;
1.257 albertel 960: if ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1) {
1.485 albertel 961: $submission_options.=
962: '<label><input type="radio" name="lastSub" value="hdgrade" '.$checkhdgrade.' /> '.&mt('essay part only').' </label>'."\n";
1.49 albertel 963: }
1.442 banghart 964: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
965: my $saveStatus = $stu_status eq '' ? 'Active' : $stu_status;
1.257 albertel 966: $env{'form.Status'} = $saveStatus;
1.485 albertel 967: $submission_options.=
1.592 bisitz 968: '<span class="LC_nobreak">'.
969: '<label><input type="radio" name="lastSub" value="lastonly" '.$checklastsub.' /> '.
970: &mt('last submission only').' </label></span>'."\n".
971: '<span class="LC_nobreak">'.
972: '<label><input type="radio" name="lastSub" value="last" /> '.
973: &mt('last submission & parts info').' </label></span>'."\n".
974: '<span class="LC_nobreak">'.
975: '<label><input type="radio" name="lastSub" value="datesub" /> '.
976: &mt('by dates and submissions').'</label></span>'."\n".
977: '<span class="LC_nobreak">'.
978: '<label><input type="radio" name="lastSub" value="all" /> '.
979: &mt('all details').'</label></span>';
1.561 bisitz 980: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Submissions'))
981: .$submission_options
982: .&Apache::lonhtmlcommon::row_closure();
983:
984: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Grading Increments'))
985: .'<select name="increment">'
986: .'<option value="1">'.&mt('Whole Points').'</option>'
987: .'<option value=".5">'.&mt('Half Points').'</option>'
988: .'<option value=".25">'.&mt('Quarter Points').'</option>'
989: .'<option value=".1">'.&mt('Tenths of a Point').'</option>'
990: .'</select>'
991: .&Apache::lonhtmlcommon::row_closure();
1.485 albertel 992:
993: $gradeTable .=
1.432 banghart 994: &build_section_inputs().
1.45 ng 995: '<input type="hidden" name="submitonly" value="'.$submitonly.'" />'."\n".
1.257 albertel 996: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" /><br />'."\n".
997: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" /><br />'."\n".
998: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
999: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.418 albertel 1000: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.110 ng 1001: '<input type="hidden" name="saveStatusOld" value="'.$saveStatus.'" />'."\n";
1002:
1.257 albertel 1003: if (exists($env{'form.gradingMenu'}) && exists($env{'form.Status'})) {
1.561 bisitz 1004: $gradeTable .= '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n";
1.124 ng 1005: } else {
1.561 bisitz 1006: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Student Status'))
1007: .&Apache::lonhtmlcommon::StatusOptions(
1008: $saveStatus,undef,1,'javascript:reLoadList(this.form);')
1009: .&Apache::lonhtmlcommon::row_closure();
1.124 ng 1010: }
1.112 ng 1011:
1.561 bisitz 1012: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Check For Plagiarism'))
1013: .'<input type="checkbox" name="checkPlag" checked="checked" />'
1014: .&Apache::lonhtmlcommon::row_closure(1)
1015: .&Apache::lonhtmlcommon::end_pick_box();
1016:
1017: $gradeTable .= '<p>'
1018: .&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"
1019: .'<input type="hidden" name="command" value="processGroup" />'
1020: .'</p>';
1.249 albertel 1021:
1022: # checkall buttons
1023: $gradeTable.=&check_script('gradesub', 'stuinfo');
1.110 ng 1024: $gradeTable.='<input type="button" '."\n".
1.589 bisitz 1025: 'onclick="javascript:checkSelect(this.form.stuinfo);" '."\n".
1026: 'value="'.&mt('Next').' →" /> <br />'."\n";
1.249 albertel 1027: $gradeTable.=&check_buttons();
1.450 banghart 1028: my ($classlist, undef, $fullname) = &getclasslist($getsec,'1',$getgroup);
1.474 albertel 1029: $gradeTable.= &Apache::loncommon::start_data_table().
1030: &Apache::loncommon::start_data_table_header_row();
1.110 ng 1031: my $loop = 0;
1032: while ($loop < 2) {
1.485 albertel 1033: $gradeTable.='<th>'.&mt('No.').'</th><th>'.&mt('Select').'</th>'.
1034: '<th>'.&nameUserString('header').' '.&mt('Section/Group').'</th>';
1.301 albertel 1035: if ($env{'form.showgrading'} eq 'yes'
1036: && $submitonly ne 'queued'
1037: && $submitonly ne 'all') {
1.485 albertel 1038: foreach my $part (sort(@$partlist)) {
1039: my $display_part=
1040: &get_display_part((split(/_/,$part))[0],$symb);
1041: $gradeTable.=
1042: '<th>'.&mt('Part: [_1] Status',$display_part).'</th>';
1.110 ng 1043: }
1.301 albertel 1044: } elsif ($submitonly eq 'queued') {
1.474 albertel 1045: $gradeTable.='<th>'.&mt('Queue Status').' </th>';
1.110 ng 1046: }
1047: $loop++;
1.126 ng 1048: # $gradeTable.='<td></td>' if ($loop%2 ==1);
1.41 ng 1049: }
1.474 albertel 1050: $gradeTable.=&Apache::loncommon::end_data_table_header_row()."\n";
1.41 ng 1051:
1.45 ng 1052: my $ctr = 0;
1.294 albertel 1053: foreach my $student (sort
1054: {
1055: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
1056: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
1057: }
1058: return $a cmp $b;
1059: }
1060: (keys(%$fullname))) {
1.41 ng 1061: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 1062:
1.110 ng 1063: my %status = ();
1.301 albertel 1064:
1065: if ($submitonly eq 'queued') {
1066: my %queue_status =
1067: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
1068: $udom,$uname);
1069: next if (!defined($queue_status{'gradingqueue'}));
1070: $status{'gradingqueue'} = $queue_status{'gradingqueue'};
1071: }
1072:
1073: if ($env{'form.showgrading'} eq 'yes'
1074: && $submitonly ne 'queued'
1075: && $submitonly ne 'all') {
1.324 albertel 1076: (%status) =&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 1077: my $submitted = 0;
1.164 albertel 1078: my $graded = 0;
1.248 albertel 1079: my $incorrect = 0;
1.110 ng 1080: foreach (keys(%status)) {
1.145 albertel 1081: $submitted = 1 if ($status{$_} ne 'nothing');
1.248 albertel 1082: $graded = 1 if ($status{$_} =~ /^ungraded/);
1083: $incorrect = 1 if ($status{$_} =~ /^incorrect/);
1084:
1.110 ng 1085: my ($foo,$partid,$foo1) = split(/\./,$_);
1086: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
1.145 albertel 1087: $submitted = 0;
1.150 albertel 1088: my ($part)=split(/\./,$partid);
1.110 ng 1089: $gradeTable.='<input type="hidden" name="'.
1.150 albertel 1090: $student.':'.$part.':submitted_by" value="'.
1.110 ng 1091: $status{'resource.'.$partid.'.submitted_by'}.'" />';
1092: }
1.41 ng 1093: }
1.248 albertel 1094:
1.156 albertel 1095: next if (!$submitted && ($submitonly eq 'yes' ||
1096: $submitonly eq 'incorrect' ||
1097: $submitonly eq 'graded'));
1.248 albertel 1098: next if (!$graded && ($submitonly eq 'graded'));
1099: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 1100: }
1.34 ng 1101:
1.45 ng 1102: $ctr++;
1.249 albertel 1103: my $section = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
1.452 banghart 1104: my $group = $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1.104 albertel 1105: if ( $perm{'vgr'} eq 'F' ) {
1.474 albertel 1106: if ($ctr%2 ==1) {
1107: $gradeTable.= &Apache::loncommon::start_data_table_row();
1108: }
1.126 ng 1109: $gradeTable.='<td align="right">'.$ctr.' </td>'.
1.563 bisitz 1110: '<td align="center"><label><input type="checkbox" name="stuinfo" value="'.
1.249 albertel 1111: $student.':'.$$fullname{$student}.':::SECTION'.$section.
1112: ') " /> </label></td>'."\n".'<td>'.
1113: &nameUserString(undef,$$fullname{$student},$uname,$udom).
1.474 albertel 1114: ' '.$section.($group ne '' ?'/'.$group:'').'</td>'."\n";
1.110 ng 1115:
1.257 albertel 1116: if ($env{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
1.524 raeburn 1117: foreach (sort(keys(%status))) {
1.485 albertel 1118: next if ($_ =~ /^resource.*?submitted_by$/);
1119: $gradeTable.='<td align="center"> '.&mt($status{$_}).' </td>'."\n";
1.110 ng 1120: }
1.41 ng 1121: }
1.126 ng 1122: # $gradeTable.='<td></td>' if ($ctr%2 ==1);
1.474 albertel 1123: if ($ctr%2 ==0) {
1124: $gradeTable.=&Apache::loncommon::end_data_table_row()."\n";
1125: }
1.41 ng 1126: }
1127: }
1.110 ng 1128: if ($ctr%2 ==1) {
1.126 ng 1129: $gradeTable.='<td> </td><td> </td><td> </td>';
1.301 albertel 1130: if ($env{'form.showgrading'} eq 'yes'
1131: && $submitonly ne 'queued'
1132: && $submitonly ne 'all') {
1.110 ng 1133: foreach (@$partlist) {
1134: $gradeTable.='<td> </td>';
1135: }
1.301 albertel 1136: } elsif ($submitonly eq 'queued') {
1137: $gradeTable.='<td> </td>';
1.110 ng 1138: }
1.474 albertel 1139: $gradeTable.=&Apache::loncommon::end_data_table_row();
1.110 ng 1140: }
1141:
1.474 albertel 1142: $gradeTable.=&Apache::loncommon::end_data_table()."\n".
1.589 bisitz 1143: '<input type="button" '.
1144: 'onclick="javascript:checkSelect(this.form.stuinfo);" '.
1145: 'value="'.&mt('Next').' →" /></form>'."\n";
1.45 ng 1146: if ($ctr == 0) {
1.96 albertel 1147: my $num_students=(scalar(keys(%$fullname)));
1148: if ($num_students eq 0) {
1.485 albertel 1149: $gradeTable='<br /> <span class="LC_warning">'.&mt('There are no students currently enrolled.').'</span>';
1.96 albertel 1150: } else {
1.171 albertel 1151: my $submissions='submissions';
1152: if ($submitonly eq 'incorrect') { $submissions = 'incorrect submissions'; }
1153: if ($submitonly eq 'graded' ) { $submissions = 'ungraded submissions'; }
1.301 albertel 1154: if ($submitonly eq 'queued' ) { $submissions = 'queued submissions'; }
1.398 albertel 1155: $gradeTable='<br /> <span class="LC_warning">'.
1.485 albertel 1156: &mt('No '.$submissions.' found for this resource for any students. ([_1] students checked for '.$submissions.')',
1157: $num_students).
1158: '</span><br />';
1.96 albertel 1159: }
1.46 ng 1160: } elsif ($ctr == 1) {
1.474 albertel 1161: $gradeTable =~ s/type="checkbox"/type="checkbox" checked="checked"/;
1.45 ng 1162: }
1.324 albertel 1163: $gradeTable.=&show_grading_menu_form($symb);
1.45 ng 1164: $request->print($gradeTable);
1.44 ng 1165: return '';
1.10 ng 1166: }
1167:
1.44 ng 1168: #---- Called from the listStudents routine
1.249 albertel 1169:
1170: sub check_script {
1171: my ($form, $type)=@_;
1172: my $chkallscript='<script type="text/javascript">
1173: function checkall() {
1174: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1175: ele = document.forms.'.$form.'.elements[i];
1176: if (ele.name == "'.$type.'") {
1177: document.forms.'.$form.'.elements[i].checked=true;
1178: }
1179: }
1180: }
1181:
1182: function checksec() {
1183: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1184: ele = document.forms.'.$form.'.elements[i];
1185: string = document.forms.'.$form.'.chksec.value;
1186: if
1187: (ele.value.indexOf(":::SECTION"+string)>0) {
1188: document.forms.'.$form.'.elements[i].checked=true;
1189: }
1190: }
1191: }
1192:
1193:
1194: function uncheckall() {
1195: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1196: ele = document.forms.'.$form.'.elements[i];
1197: if (ele.name == "'.$type.'") {
1198: document.forms.'.$form.'.elements[i].checked=false;
1199: }
1200: }
1201: }
1202:
1203: </script>'."\n";
1204: return $chkallscript;
1205: }
1206:
1207: sub check_buttons {
1.485 albertel 1208: my $buttons.='<input type="button" onclick="checkall()" value="'.&mt('Check All').'" />';
1209: $buttons.='<input type="button" onclick="uncheckall()" value="'.&mt('Uncheck All').'" /> ';
1210: $buttons.='<input type="button" onclick="checksec()" value="'.&mt('Check Section/Group').'" />';
1.249 albertel 1211: $buttons.='<input type="text" size="5" name="chksec" /> ';
1212: return $buttons;
1213: }
1214:
1.44 ng 1215: # Displays the submissions for one student or a group of students
1.34 ng 1216: sub processGroup {
1.41 ng 1217: my ($request) = shift;
1218: my $ctr = 0;
1.155 albertel 1219: my @stuchecked = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.41 ng 1220: my $total = scalar(@stuchecked)-1;
1.45 ng 1221:
1.396 banghart 1222: foreach my $student (@stuchecked) {
1223: my ($uname,$udom,$fullname) = split(/:/,$student);
1.257 albertel 1224: $env{'form.student'} = $uname;
1225: $env{'form.userdom'} = $udom;
1226: $env{'form.fullname'} = $fullname;
1.41 ng 1227: &submission($request,$ctr,$total);
1228: $ctr++;
1229: }
1230: return '';
1.35 ng 1231: }
1.34 ng 1232:
1.44 ng 1233: #------------------------------------------------------------------------------------
1234: #
1235: #-------------------------- Next few routines handles grading by student, essentially
1236: # handles essay response type problem/part
1237: #
1238: #--- Javascript to handle the submission page functionality ---
1239: sub sub_page_js {
1240: my $request = shift;
1.539 riegler 1241: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
1.44 ng 1242: $request->print(<<SUBJAVASCRIPT);
1243: <script type="text/javascript" language="javascript">
1.71 ng 1244: function updateRadio(formname,id,weight) {
1.125 ng 1245: var gradeBox = formname["GD_BOX"+id];
1246: var radioButton = formname["RADVAL"+id];
1247: var oldpts = formname["oldpts"+id].value;
1.72 ng 1248: var pts = checkSolved(formname,id) == 'update' ? gradeBox.value : oldpts;
1.71 ng 1249: gradeBox.value = pts;
1250: var resetbox = false;
1251: if (isNaN(pts) || pts < 0) {
1.539 riegler 1252: alert("$alertmsg"+pts);
1.71 ng 1253: for (var i=0; i<radioButton.length; i++) {
1254: if (radioButton[i].checked) {
1255: gradeBox.value = i;
1256: resetbox = true;
1257: }
1258: }
1259: if (!resetbox) {
1260: formtextbox.value = "";
1261: }
1262: return;
1.44 ng 1263: }
1.71 ng 1264:
1265: if (pts > weight) {
1266: var resp = confirm("You entered a value ("+pts+
1267: ") greater than the weight for the part. Accept?");
1268: if (resp == false) {
1.125 ng 1269: gradeBox.value = oldpts;
1.71 ng 1270: return;
1271: }
1.44 ng 1272: }
1.13 albertel 1273:
1.71 ng 1274: for (var i=0; i<radioButton.length; i++) {
1275: radioButton[i].checked=false;
1276: if (pts == i && pts != "") {
1277: radioButton[i].checked=true;
1278: }
1279: }
1280: updateSelect(formname,id);
1.125 ng 1281: formname["stores"+id].value = "0";
1.41 ng 1282: }
1.5 albertel 1283:
1.72 ng 1284: function writeBox(formname,id,pts) {
1.125 ng 1285: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1286: if (checkSolved(formname,id) == 'update') {
1287: gradeBox.value = pts;
1288: } else {
1.125 ng 1289: var oldpts = formname["oldpts"+id].value;
1.72 ng 1290: gradeBox.value = oldpts;
1.125 ng 1291: var radioButton = formname["RADVAL"+id];
1.71 ng 1292: for (var i=0; i<radioButton.length; i++) {
1293: radioButton[i].checked=false;
1.72 ng 1294: if (i == oldpts) {
1.71 ng 1295: radioButton[i].checked=true;
1296: }
1297: }
1.41 ng 1298: }
1.125 ng 1299: formname["stores"+id].value = "0";
1.71 ng 1300: updateSelect(formname,id);
1301: return;
1.41 ng 1302: }
1.44 ng 1303:
1.71 ng 1304: function clearRadBox(formname,id) {
1305: if (checkSolved(formname,id) == 'noupdate') {
1306: updateSelect(formname,id);
1307: return;
1308: }
1.125 ng 1309: gradeSelect = formname["GD_SEL"+id];
1.71 ng 1310: for (var i=0; i<gradeSelect.length; i++) {
1311: if (gradeSelect[i].selected) {
1312: var selectx=i;
1313: }
1314: }
1.125 ng 1315: var stores = formname["stores"+id];
1.71 ng 1316: if (selectx == stores.value) { return };
1.125 ng 1317: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1318: gradeBox.value = "";
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;
1322: }
1323: stores.value = selectx;
1324: }
1.5 albertel 1325:
1.71 ng 1326: function checkSolved(formname,id) {
1.125 ng 1327: if (formname["solved"+id].value == "correct_by_student" && formname.overRideScore.value == 'no') {
1.118 ng 1328: var reply = confirm("This problem has been graded correct by the computer. Do you want to change the score?");
1329: if (!reply) {return "noupdate";}
1.120 ng 1330: formname.overRideScore.value = 'yes';
1.41 ng 1331: }
1.71 ng 1332: return "update";
1.13 albertel 1333: }
1.71 ng 1334:
1335: function updateSelect(formname,id) {
1.125 ng 1336: formname["GD_SEL"+id][0].selected = true;
1.71 ng 1337: return;
1.41 ng 1338: }
1.33 ng 1339:
1.121 ng 1340: //=========== Check that a point is assigned for all the parts ============
1.71 ng 1341: function checksubmit(formname,val,total,parttot) {
1.121 ng 1342: formname.gradeOpt.value = val;
1.71 ng 1343: if (val == "Save & Next") {
1344: for (i=0;i<=total;i++) {
1345: for (j=0;j<parttot;j++) {
1.125 ng 1346: var partid = formname["partid"+i+"_"+j].value;
1.127 ng 1347: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1348: var points = formname["GD_BOX"+i+"_"+partid].value;
1.71 ng 1349: if (points == "") {
1.125 ng 1350: var name = formname["name"+i].value;
1.129 ng 1351: var studentID = (name != '' ? name : formname["unamedom"+i].value);
1352: var resp = confirm("You did not assign a score for "+studentID+
1353: ", part "+partid+". Continue?");
1.71 ng 1354: if (resp == false) {
1.125 ng 1355: formname["GD_BOX"+i+"_"+partid].focus();
1.71 ng 1356: return false;
1357: }
1358: }
1359: }
1360:
1361: }
1362: }
1363:
1364: }
1.121 ng 1365: if (val == "Grade Student") {
1366: formname.showgrading.value = "yes";
1367: if (formname.Status.value == "") {
1368: formname.Status.value = "Active";
1369: }
1370: formname.studentNo.value = total;
1371: }
1.120 ng 1372: formname.submit();
1373: }
1374:
1.71 ng 1375: //======= Check that a score is assigned for all the problems (page/sequence grading only) =========
1376: function checkSubmitPage(formname,total) {
1377: noscore = new Array(100);
1378: var ptr = 0;
1379: for (i=1;i<total;i++) {
1.125 ng 1380: var partid = formname["q_"+i].value;
1.127 ng 1381: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1382: var points = formname["GD_BOX"+i+"_"+partid].value;
1383: var status = formname["solved"+i+"_"+partid].value;
1.71 ng 1384: if (points == "" && status != "correct_by_student") {
1385: noscore[ptr] = i;
1386: ptr++;
1387: }
1388: }
1389: }
1390: if (ptr != 0) {
1391: var sense = ptr == 1 ? ": " : "s: ";
1392: var prolist = "";
1393: if (ptr == 1) {
1394: prolist = noscore[0];
1395: } else {
1396: var i = 0;
1397: while (i < ptr-1) {
1398: prolist += noscore[i]+", ";
1399: i++;
1400: }
1401: prolist += "and "+noscore[i];
1402: }
1403: var resp = confirm("You did not assign any score for the following problem"+sense+prolist+". Continue?");
1404: if (resp == false) {
1405: return false;
1406: }
1407: }
1.45 ng 1408:
1.71 ng 1409: formname.submit();
1410: }
1411: </script>
1412: SUBJAVASCRIPT
1413: }
1.45 ng 1414:
1.71 ng 1415: #--- javascript for essay type problem --
1416: sub sub_page_kw_js {
1417: my $request = shift;
1.80 ng 1418: my $iconpath = $request->dir_config('lonIconsURL');
1.118 ng 1419: &commonJSfunctions($request);
1.350 albertel 1420:
1.351 albertel 1421: my $inner_js_msg_central=<<INNERJS;
1.350 albertel 1422: <script text="text/javascript">
1423: function checkInput() {
1424: opener.document.SCORE.msgsub.value = opener.checkEntities(document.msgcenter.msgsub.value);
1425: var nmsg = opener.document.SCORE.savemsgN.value;
1426: var usrctr = document.msgcenter.usrctr.value;
1427: var newval = opener.document.SCORE["newmsg"+usrctr];
1428: newval.value = opener.checkEntities(document.msgcenter.newmsg.value);
1429:
1430: var msgchk = "";
1431: if (document.msgcenter.subchk.checked) {
1432: msgchk = "msgsub,";
1433: }
1434: var includemsg = 0;
1435: for (var i=1; i<=nmsg; i++) {
1436: var opnmsg = opener.document.SCORE["savemsg"+i];
1437: var frmmsg = document.msgcenter["msg"+i];
1438: opnmsg.value = opener.checkEntities(frmmsg.value);
1439: var showflg = opener.document.SCORE["shownOnce"+i];
1440: showflg.value = "1";
1441: var chkbox = document.msgcenter["msgn"+i];
1442: if (chkbox.checked) {
1443: msgchk += "savemsg"+i+",";
1444: includemsg = 1;
1445: }
1446: }
1447: if (document.msgcenter.newmsgchk.checked) {
1448: msgchk += "newmsg"+usrctr;
1449: includemsg = 1;
1450: }
1451: imgformname = opener.document.SCORE["mailicon"+usrctr];
1452: imgformname.src = "$iconpath/"+((includemsg) ? "mailto.gif" : "mailbkgrd.gif");
1453: var includemsg = opener.document.SCORE["includemsg"+usrctr];
1454: includemsg.value = msgchk;
1455:
1456: self.close()
1457:
1458: }
1459: </script>
1460: INNERJS
1461:
1.351 albertel 1462: my $inner_js_highlight_central=<<INNERJS;
1463: <script type="text/javascript">
1464: function updateChoice(flag) {
1465: opener.document.SCORE.kwclr.value = opener.radioSelection(document.hlCenter.kwdclr);
1466: opener.document.SCORE.kwsize.value = opener.radioSelection(document.hlCenter.kwdsize);
1467: opener.document.SCORE.kwstyle.value = opener.radioSelection(document.hlCenter.kwdstyle);
1468: opener.document.SCORE.refresh.value = "on";
1469: if (opener.document.SCORE.keywords.value!=""){
1470: opener.document.SCORE.submit();
1471: }
1472: self.close()
1473: }
1474: </script>
1475: INNERJS
1476:
1477: my $start_page_msg_central =
1478: &Apache::loncommon::start_page('Message Central',$inner_js_msg_central,
1479: {'js_ready' => 1,
1480: 'only_body' => 1,
1481: 'bgcolor' =>'#FFFFFF',});
1482: my $end_page_msg_central =
1483: &Apache::loncommon::end_page({'js_ready' => 1});
1484:
1485:
1486: my $start_page_highlight_central =
1487: &Apache::loncommon::start_page('Highlight Central',
1488: $inner_js_highlight_central,
1.350 albertel 1489: {'js_ready' => 1,
1490: 'only_body' => 1,
1491: 'bgcolor' =>'#FFFFFF',});
1.351 albertel 1492: my $end_page_highlight_central =
1.350 albertel 1493: &Apache::loncommon::end_page({'js_ready' => 1});
1494:
1.219 www 1495: my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
1.236 albertel 1496: $docopen=~s/^document\.//;
1.596.2.4 raeburn 1497: my %lt = &Apache::lonlocal::texthash(
1498: keyw => 'Keywords list, separated by a space. Add/delete to list if desired.',
1499: plse => 'Please select a word or group of words from document and then click this link.',
1500: adds => 'Add selection to keyword list? Edit if desired.',
1501: comp => 'Compose Message for: ',
1502: incl => 'Include',
1503: type => 'Type',
1504: subj => 'Subject',
1505: mesa => 'Message',
1506: new => 'New',
1507: save => 'Save',
1508: canc => 'Cancel',
1509: kehi => 'Keyword Highlight Options',
1510: txtc => 'Text Color',
1511: font => 'Font Size',
1512: fnst => 'Font Style',
1513: );
1.71 ng 1514: $request->print(<<SUBJAVASCRIPT);
1515: <script type="text/javascript" language="javascript">
1.45 ng 1516:
1.44 ng 1517: //===================== Show list of keywords ====================
1.122 ng 1518: function keywords(formname) {
1.596.2.4 raeburn 1519: var nret = prompt("$lt{'keyw'}",formname.keywords.value);
1.44 ng 1520: if (nret==null) return;
1.122 ng 1521: formname.keywords.value = nret;
1.44 ng 1522:
1.122 ng 1523: if (formname.keywords.value != "") {
1.128 ng 1524: formname.refresh.value = "on";
1.122 ng 1525: formname.submit();
1.44 ng 1526: }
1527: return;
1528: }
1529:
1530: //===================== Script to view submitted by ==================
1531: function viewSubmitter(submitter) {
1532: document.SCORE.refresh.value = "on";
1533: document.SCORE.NCT.value = "1";
1534: document.SCORE.unamedom0.value = submitter;
1535: document.SCORE.submit();
1536: return;
1537: }
1538:
1539: //===================== Script to add keyword(s) ==================
1540: function getSel() {
1541: if (document.getSelection) txt = document.getSelection();
1542: else if (document.selection) txt = document.selection.createRange().text;
1543: else return;
1544: var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
1545: if (cleantxt=="") {
1.596.2.4 raeburn 1546: alert("$lt{'plse'}");
1.44 ng 1547: return;
1548: }
1.596.2.4 raeburn 1549: var nret = prompt("$lt{'adds'}",cleantxt);
1.44 ng 1550: if (nret==null) return;
1.127 ng 1551: document.SCORE.keywords.value = document.SCORE.keywords.value+" "+nret;
1.44 ng 1552: if (document.SCORE.keywords.value != "") {
1.127 ng 1553: document.SCORE.refresh.value = "on";
1.44 ng 1554: document.SCORE.submit();
1555: }
1556: return;
1557: }
1558:
1559: //====================== Script for composing message ==============
1.80 ng 1560: // preload images
1561: img1 = new Image();
1562: img1.src = "$iconpath/mailbkgrd.gif";
1563: img2 = new Image();
1564: img2.src = "$iconpath/mailto.gif";
1565:
1.44 ng 1566: function msgCenter(msgform,usrctr,fullname) {
1567: var Nmsg = msgform.savemsgN.value;
1568: savedMsgHeader(Nmsg,usrctr,fullname);
1569: var subject = msgform.msgsub.value;
1.127 ng 1570: var msgchk = document.SCORE["includemsg"+usrctr].value;
1.44 ng 1571: re = /msgsub/;
1572: var shwsel = "";
1573: if (re.test(msgchk)) { shwsel = "checked" }
1.123 ng 1574: subject = (document.SCORE.shownSub.value == 0 ? checkEntities(subject) : subject);
1575: displaySubject(checkEntities(subject),shwsel);
1.44 ng 1576: for (var i=1; i<=Nmsg; i++) {
1.123 ng 1577: var testmsg = "savemsg"+i+",";
1578: re = new RegExp(testmsg,"g");
1.44 ng 1579: shwsel = "";
1580: if (re.test(msgchk)) { shwsel = "checked" }
1.125 ng 1581: var message = document.SCORE["savemsg"+i].value;
1.126 ng 1582: message = (document.SCORE["shownOnce"+i].value == 0 ? checkEntities(message) : message);
1.123 ng 1583: displaySavedMsg(i,message,shwsel); //I do not get it. w/o checkEntities on saved messages,
1584: //any < is already converted to <, etc. However, only once!!
1.44 ng 1585: }
1.125 ng 1586: newmsg = document.SCORE["newmsg"+usrctr].value;
1.44 ng 1587: shwsel = "";
1588: re = /newmsg/;
1589: if (re.test(msgchk)) { shwsel = "checked" }
1590: newMsg(newmsg,shwsel);
1591: msgTail();
1592: return;
1593: }
1594:
1.123 ng 1595: function checkEntities(strx) {
1596: if (strx.length == 0) return strx;
1597: var orgStr = ["&", "<", ">", '"'];
1598: var newStr = ["&", "<", ">", """];
1599: var counter = 0;
1600: while (counter < 4) {
1601: strx = strReplace(strx,orgStr[counter],newStr[counter]);
1602: counter++;
1603: }
1604: return strx;
1605: }
1606:
1607: function strReplace(strx, orgStr, newStr) {
1608: return strx.split(orgStr).join(newStr);
1609: }
1610:
1.44 ng 1611: function savedMsgHeader(Nmsg,usrctr,fullname) {
1.76 ng 1612: var height = 70*Nmsg+250;
1.44 ng 1613: if (height > 600) {
1614: height = 600;
1615: }
1.118 ng 1616: var xpos = (screen.width-600)/2;
1617: xpos = (xpos < 0) ? '0' : xpos;
1618: var ypos = (screen.height-height)/2-30;
1619: ypos = (ypos < 0) ? '0' : ypos;
1620:
1.596.2.12.2. (raeburn 1621:): pWin = window.open('', 'MessageCenter', 'resizable=yes,toolbar=no,location=no,scrollbars=yes,screenx='+xpos+',screeny='+ypos+',width=700,height='+height);
1.76 ng 1622: pWin.focus();
1623: pDoc = pWin.document;
1.219 www 1624: pDoc.$docopen;
1.351 albertel 1625: pDoc.write('$start_page_msg_central');
1.76 ng 1626:
1627: pDoc.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
1628: pDoc.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
1.596.2.4 raeburn 1629: pDoc.write("<h3><span class=\\"LC_info\\"> $lt{'comp'}\"+fullname+\"<\\/span><\\/h3><br /><br />");
1.76 ng 1630:
1.564 bisitz 1631: pDoc.write('<table border="0" width="100%"><tr><td bgcolor="#777777">');
1632: pDoc.write('<table border="0" width="100%"><tr bgcolor="#DDFFFF">');
1.596.2.4 raeburn 1633: pDoc.write("<td><b>$lt{'type'}<\\/b><\\/td><td><b>$lt{'incl'}<\\/b><\\/td><td><b>$lt{'mesa'}<\\/td><\\/tr>");
1.44 ng 1634: }
1635: function displaySubject(msg,shwsel) {
1.76 ng 1636: pDoc = pWin.document;
1637: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.596.2.4 raeburn 1638: pDoc.write("<td>$lt{'subj'}<\\/td>");
1.465 albertel 1639: pDoc.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1640: pDoc.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+"\\"size=\\"60\\" maxlength=\\"80\\"><\\/td><\\/tr>");
1.44 ng 1641: }
1642:
1.72 ng 1643: function displaySavedMsg(ctr,msg,shwsel) {
1.76 ng 1644: pDoc = pWin.document;
1645: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.465 albertel 1646: pDoc.write("<td align=\\"center\\">"+ctr+"<\\/td>");
1647: pDoc.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1648: pDoc.write("<td><textarea name=\\"msg"+ctr+"\\" cols=\\"60\\" rows=\\"3\\">"+msg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 1649: }
1650:
1651: function newMsg(newmsg,shwsel) {
1.76 ng 1652: pDoc = pWin.document;
1653: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.596.2.4 raeburn 1654: pDoc.write("<td align=\\"center\\">$lt{'new'}<\\/td>");
1.465 albertel 1655: pDoc.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1656: pDoc.write("<td><textarea name=\\"newmsg\\" cols=\\"60\\" rows=\\"3\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" >"+newmsg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 1657: }
1658:
1659: function msgTail() {
1.76 ng 1660: pDoc = pWin.document;
1.465 albertel 1661: pDoc.write("<\\/table>");
1662: pDoc.write("<\\/td><\\/tr><\\/table> ");
1.596.2.4 raeburn 1663: pDoc.write("<input type=\\"button\\" value=\\"$lt{'save'}\\" onclick=\\"javascript:checkInput()\\"> ");
1664: pDoc.write("<input type=\\"button\\" value=\\"$lt{'canc'}\\" onclick=\\"self.close()\\"><br /><br />");
1.465 albertel 1665: pDoc.write("<\\/form>");
1.351 albertel 1666: pDoc.write('$end_page_msg_central');
1.128 ng 1667: pDoc.close();
1.44 ng 1668: }
1669:
1670: //====================== Script for keyword highlight options ==============
1671: function kwhighlight() {
1672: var kwclr = document.SCORE.kwclr.value;
1673: var kwsize = document.SCORE.kwsize.value;
1674: var kwstyle = document.SCORE.kwstyle.value;
1675: var redsel = "";
1676: var grnsel = "";
1677: var blusel = "";
1678: if (kwclr=="red") {var redsel="checked"};
1679: if (kwclr=="green") {var grnsel="checked"};
1680: if (kwclr=="blue") {var blusel="checked"};
1681: var sznsel = "";
1682: var sz1sel = "";
1683: var sz2sel = "";
1684: if (kwsize=="0") {var sznsel="checked"};
1685: if (kwsize=="+1") {var sz1sel="checked"};
1686: if (kwsize=="+2") {var sz2sel="checked"};
1687: var synsel = "";
1688: var syisel = "";
1689: var sybsel = "";
1690: if (kwstyle=="") {var synsel="checked"};
1691: if (kwstyle=="<i>") {var syisel="checked"};
1692: if (kwstyle=="<b>") {var sybsel="checked"};
1693: highlightCentral();
1694: highlightbody('red','red',redsel,'0','normal',sznsel,'','normal',synsel);
1695: highlightbody('green','green',grnsel,'+1','+1',sz1sel,'<i>','italic',syisel);
1696: highlightbody('blue','blue',blusel,'+2','+2',sz2sel,'<b>','bold',sybsel);
1697: highlightend();
1698: return;
1699: }
1700:
1701: function highlightCentral() {
1.76 ng 1702: // if (window.hwdWin) window.hwdWin.close();
1.118 ng 1703: var xpos = (screen.width-400)/2;
1704: xpos = (xpos < 0) ? '0' : xpos;
1705: var ypos = (screen.height-330)/2-30;
1706: ypos = (ypos < 0) ? '0' : ypos;
1707:
1.206 albertel 1708: hwdWin = window.open('', 'KeywordHighlightCentral', 'resizeable=yes,toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx='+xpos+',screeny='+ypos);
1.76 ng 1709: hwdWin.focus();
1710: var hDoc = hwdWin.document;
1.219 www 1711: hDoc.$docopen;
1.351 albertel 1712: hDoc.write('$start_page_highlight_central');
1.76 ng 1713: hDoc.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
1.596.2.4 raeburn 1714: hDoc.write("<h3><span class=\\"LC_info\\"> $lt{'kehi'}<\\/span><\\/h3><br /><br />");
1.76 ng 1715:
1.564 bisitz 1716: hDoc.write('<table border="0" width="100%"><tr><td bgcolor="#777777">');
1717: hDoc.write('<table border="0" width="100%"><tr bgcolor="#DDFFFF">');
1.596.2.4 raeburn 1718: hDoc.write("<td><b>$lt{'txtc'}<\\/b><\\/td><td><b>$lt{'font'}<\\/b><\\/td><td><b>$lt{'fnst'}<\\/td><\\/tr>");
1.44 ng 1719: }
1720:
1721: function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) {
1.76 ng 1722: var hDoc = hwdWin.document;
1723: hDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1724: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1725: hDoc.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+"> "+clrtxt+"<\\/td>");
1.76 ng 1726: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1727: hDoc.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+"> "+sztxt+"<\\/td>");
1.76 ng 1728: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1729: hDoc.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+"> "+sytxt+"<\\/td>");
1730: hDoc.write("<\\/tr>");
1.44 ng 1731: }
1732:
1733: function highlightend() {
1.76 ng 1734: var hDoc = hwdWin.document;
1.465 albertel 1735: hDoc.write("<\\/table>");
1736: hDoc.write("<\\/td><\\/tr><\\/table> ");
1.596.2.4 raeburn 1737: hDoc.write("<input type=\\"button\\" value=\\"$lt{'save'}\\" onclick=\\"javascript:updateChoice(1)\\"> ");
1738: hDoc.write("<input type=\\"button\\" value=\\"$lt{'canc'}\\" onclick=\\"self.close()\\"><br /><br />");
1.465 albertel 1739: hDoc.write("<\\/form>");
1.351 albertel 1740: hDoc.write('$end_page_highlight_central');
1.128 ng 1741: hDoc.close();
1.44 ng 1742: }
1743:
1744: </script>
1745: SUBJAVASCRIPT
1746: }
1747:
1.349 albertel 1748: sub get_increment {
1.348 bowersj2 1749: my $increment = $env{'form.increment'};
1750: if ($increment != 1 && $increment != .5 && $increment != .25 &&
1751: $increment != .1) {
1752: $increment = 1;
1753: }
1754: return $increment;
1755: }
1756:
1.585 bisitz 1757: sub gradeBox_start {
1758: return (
1759: &Apache::loncommon::start_data_table()
1760: .&Apache::loncommon::start_data_table_header_row()
1761: .'<th>'.&mt('Part').'</th>'
1762: .'<th>'.&mt('Points').'</th>'
1763: .'<th> </th>'
1764: .'<th>'.&mt('Assign Grade').'</th>'
1765: .'<th>'.&mt('Weight').'</th>'
1766: .'<th>'.&mt('Grade Status').'</th>'
1767: .&Apache::loncommon::end_data_table_header_row()
1768: );
1769: }
1770:
1771: sub gradeBox_end {
1772: return (
1773: &Apache::loncommon::end_data_table()
1774: );
1775: }
1.71 ng 1776: #--- displays the grading box, used in essay type problem and grading by page/sequence
1777: sub gradeBox {
1.322 albertel 1778: my ($request,$symb,$uname,$udom,$counter,$partid,$record) = @_;
1.381 albertel 1779: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 1780: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 1781: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
1.466 albertel 1782: my $wgtmsg = ($wgt > 0) ? &mt('(problem weight)')
1783: : '<span class="LC_info">'.&mt('problem weight assigned by computer').'</span>';
1.71 ng 1784: $wgt = ($wgt > 0 ? $wgt : '1');
1785: my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
1.320 albertel 1786: '' : &compute_points($$record{'resource.'.$partid.'.awarded'},$wgt));
1.71 ng 1787: my $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />'."\n";
1.466 albertel 1788: my $display_part= &get_display_part($partid,$symb);
1.270 albertel 1789: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
1790: [$partid]);
1791: my $aggtries = $$record{'resource.'.$partid.'.tries'};
1.269 raeburn 1792: if ($last_resets{$partid}) {
1793: $aggtries = &get_num_tries($record,$last_resets{$partid},$partid);
1794: }
1.585 bisitz 1795: $result.=&Apache::loncommon::start_data_table_row();
1.71 ng 1796: my $ctr = 0;
1.348 bowersj2 1797: my $thisweight = 0;
1.349 albertel 1798: my $increment = &get_increment();
1.485 albertel 1799:
1800: my $radio.='<table border="0"><tr>'."\n"; # display radio buttons in a nice table 10 across
1.348 bowersj2 1801: while ($thisweight<=$wgt) {
1.532 bisitz 1802: $radio.= '<td><span class="LC_nobreak"><label><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
1.589 bisitz 1803: 'onclick="javascript:writeBox(this.form,\''.$counter.'_'.$partid.'\','.
1.348 bowersj2 1804: $thisweight.')" value="'.$thisweight.'" '.
1.401 albertel 1805: ($score eq $thisweight ? 'checked="checked"':'').' /> '.$thisweight."</label></span></td>\n";
1.485 albertel 1806: $radio.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1.348 bowersj2 1807: $thisweight += $increment;
1.71 ng 1808: $ctr++;
1809: }
1.485 albertel 1810: $radio.='</tr></table>';
1811:
1812: my $line.='<input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
1.71 ng 1813: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
1.589 bisitz 1814: 'onchange="javascript:updateRadio(this.form,\''.$counter.'_'.$partid.'\','.
1.71 ng 1815: $wgt.')" /></td>'."\n";
1.485 albertel 1816: $line.='<td>/'.$wgt.' '.$wgtmsg.
1.71 ng 1817: ($$record{'resource.'.$partid.'.solved'} eq 'correct_by_student' ? ' '.$checkIcon : '').
1.585 bisitz 1818: ' </td>'."\n";
1819: $line.='<td><select name="GD_SEL'.$counter.'_'.$partid.'" '.
1.589 bisitz 1820: 'onchange="javascript:clearRadBox(this.form,\''.$counter.'_'.$partid.'\')" >'."\n";
1.71 ng 1821: if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
1.485 albertel 1822: $line.='<option></option>'.
1823: '<option value="excused" selected="selected">'.&mt('excused').'</option>';
1.71 ng 1824: } else {
1.485 albertel 1825: $line.='<option selected="selected"></option>'.
1826: '<option value="excused" >'.&mt('excused').'</option>';
1.71 ng 1827: }
1.485 albertel 1828: $line.='<option value="reset status">'.&mt('reset status').'</option></select>'."\n";
1829:
1830:
1831: $result .=
1.585 bisitz 1832: '<td>'.$display_part.'</td><td>'.$radio.'</td><td>'.&mt('or').'</td><td>'.$line.'</td>';
1833: $result.=&Apache::loncommon::end_data_table_row();
1.71 ng 1834: $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="" />'."\n".
1835: '<input type="hidden" name="oldpts'.$counter.'_'.$partid.'" value="'.$score.'" />'."\n".
1836: '<input type="hidden" name="solved'.$counter.'_'.$partid.'" value="'.
1.269 raeburn 1837: $$record{'resource.'.$partid.'.solved'}.'" />'."\n".
1838: '<input type="hidden" name="totaltries'.$counter.'_'.$partid.'" value="'.
1839: $$record{'resource.'.$partid.'.tries'}.'" />'."\n".
1840: '<input type="hidden" name="aggtries'.$counter.'_'.$partid.'" value="'.
1841: $aggtries.'" />'."\n";
1.582 raeburn 1842: my $res_error;
1843: $result.=&handback_box($symb,$uname,$udom,$counter,$partid,$record,\$res_error);
1844: if ($res_error) {
1845: return &navmap_errormsg();
1846: }
1.318 banghart 1847: return $result;
1848: }
1.322 albertel 1849:
1850: sub handback_box {
1.582 raeburn 1851: my ($symb,$uname,$udom,$counter,$partid,$record,$res_error) = @_;
1852: my ($partlist,$handgrade,$responseType) = &response_type($symb,$res_error);
1.323 banghart 1853: my (@respids);
1.596.2.4 raeburn 1854: my @part_response_id = &flatten_responseType($responseType);
1.375 albertel 1855: foreach my $part_response_id (@part_response_id) {
1856: my ($part,$resp) = @{ $part_response_id };
1.323 banghart 1857: if ($part eq $partid) {
1.375 albertel 1858: push(@respids,$resp);
1.323 banghart 1859: }
1860: }
1.318 banghart 1861: my $result;
1.323 banghart 1862: foreach my $respid (@respids) {
1.322 albertel 1863: my $prefix = $counter.'_'.$partid.'_'.$respid.'_';
1864: my $files=&get_submitted_files($udom,$uname,$partid,$respid,$record);
1865: next if (!@$files);
1.596.2.4 raeburn 1866: my $file_counter = 0;
1.313 banghart 1867: foreach my $file (@$files) {
1.368 banghart 1868: if ($file =~ /\/portfolio\//) {
1.596.2.4 raeburn 1869: $file_counter++;
1.368 banghart 1870: my ($file_path, $file_disp) = ($file =~ m|(.+/)(.+)$|);
1871: my ($name,$version,$ext) = &file_name_version_ext($file_disp);
1872: $file_disp = "$name.$ext";
1873: $file = $file_path.$file_disp;
1874: $result.=&mt('Return commented version of [_1] to student.',
1875: '<span class="LC_filename">'.$file_disp.'</span>');
1876: $result.='<input type="file" name="'.$prefix.'returndoc'.$file_counter.'" />'."\n";
1.596.2.4 raeburn 1877: $result.='<input type="hidden" name="'.$prefix.'origdoc'.$file_counter.'" value="'.$file.'" /><br />'."\n";
1.368 banghart 1878: }
1.322 albertel 1879: }
1.596.2.4 raeburn 1880: if ($file_counter) {
1881: $result .= '<input type="hidden" name="'.$prefix.'countreturndoc" value="'.$file_counter.'" />'."\n".
1882: '<span class="LC_info">'.
1883: '('.&mt('File(s) will be uploaded when you click on Save & Next below.',$file_counter).')</span><br /><br />';
1884: }
1.313 banghart 1885: }
1.318 banghart 1886: return $result;
1.71 ng 1887: }
1.44 ng 1888:
1.58 albertel 1889: sub show_problem {
1.382 albertel 1890: my ($request,$symb,$uname,$udom,$removeform,$viewon,$mode,$form) = @_;
1.144 albertel 1891: my $rendered;
1.382 albertel 1892: my %form = ((ref($form) eq 'HASH')? %{$form} : ());
1.329 albertel 1893: &Apache::lonxml::remember_problem_counter();
1.144 albertel 1894: if ($mode eq 'both' or $mode eq 'text') {
1895: $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
1.382 albertel 1896: $env{'request.course.id'},
1897: undef,\%form);
1.144 albertel 1898: }
1.58 albertel 1899: if ($removeform) {
1900: $rendered=~s|<form(.*?)>||g;
1901: $rendered=~s|</form>||g;
1.374 albertel 1902: $rendered=~s|(<input[^>]*name\s*=\s*"?)(\w+)("?)|$1would_have_been_$2$3|g;
1.58 albertel 1903: }
1.144 albertel 1904: my $companswer;
1905: if ($mode eq 'both' or $mode eq 'answer') {
1.329 albertel 1906: &Apache::lonxml::restore_problem_counter();
1.382 albertel 1907: $companswer=
1908: &Apache::loncommon::get_student_answers($symb,$uname,$udom,
1909: $env{'request.course.id'},
1910: %form);
1.144 albertel 1911: }
1.58 albertel 1912: if ($removeform) {
1913: $companswer=~s|<form(.*?)>||g;
1914: $companswer=~s|</form>||g;
1.144 albertel 1915: $companswer=~s|name="submit"|name="would_have_been_submit"|g;
1.58 albertel 1916: }
1.468 albertel 1917: $rendered=
1.588 bisitz 1918: '<div class="LC_Box">'
1919: .'<h3 class="LC_hcell">'.&mt('View of the problem').'</h3>'
1920: .$rendered
1921: .'</div>';
1.468 albertel 1922: $companswer=
1.588 bisitz 1923: '<div class="LC_Box">'
1924: .'<h3 class="LC_hcell">'.&mt('Correct answer').'</h3>'
1925: .$companswer
1926: .'</div>';
1.468 albertel 1927: my $result;
1.144 albertel 1928: if ($mode eq 'both') {
1.588 bisitz 1929: $result=$rendered.$companswer;
1.144 albertel 1930: } elsif ($mode eq 'text') {
1.588 bisitz 1931: $result=$rendered;
1.144 albertel 1932: } elsif ($mode eq 'answer') {
1.588 bisitz 1933: $result=$companswer;
1.144 albertel 1934: }
1.71 ng 1935: return $result;
1.58 albertel 1936: }
1.397 albertel 1937:
1.396 banghart 1938: sub files_exist {
1939: my ($r, $symb) = @_;
1940: my @students = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.397 albertel 1941:
1.396 banghart 1942: foreach my $student (@students) {
1943: my ($uname,$udom,$fullname) = split(/:/,$student);
1.397 albertel 1944: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1945: $udom,$uname);
1.396 banghart 1946: my ($string,$timestamp)= &get_last_submission(\%record);
1.397 albertel 1947: foreach my $submission (@$string) {
1948: my ($partid,$respid) =
1949: ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
1950: my $files=&get_submitted_files($udom,$uname,$partid,$respid,
1951: \%record);
1952: return 1 if (@$files);
1.396 banghart 1953: }
1954: }
1.397 albertel 1955: return 0;
1.396 banghart 1956: }
1.397 albertel 1957:
1.394 banghart 1958: sub download_all_link {
1959: my ($r,$symb) = @_;
1.395 albertel 1960: my $all_students =
1961: join("\n", &Apache::loncommon::get_env_multiple('form.stuinfo'));
1962:
1963: my $parts =
1964: join("\n",&Apache::loncommon::get_env_multiple('form.vPart'));
1965:
1.394 banghart 1966: my $identifier = &Apache::loncommon::get_cgi_id();
1.514 raeburn 1967: &Apache::lonnet::appenv({'cgi.'.$identifier.'.students' => $all_students,
1968: 'cgi.'.$identifier.'.symb' => $symb,
1969: 'cgi.'.$identifier.'.parts' => $parts,});
1.395 albertel 1970: $r->print('<a href="/cgi-bin/multidownload.pl?'.$identifier.'">'.
1971: &mt('Download All Submitted Documents').'</a>');
1.394 banghart 1972: return
1973: }
1.395 albertel 1974:
1.432 banghart 1975: sub build_section_inputs {
1976: my $section_inputs;
1977: if ($env{'form.section'} eq '') {
1978: $section_inputs .= '<input type="hidden" name="section" value="all" />'."\n";
1979: } else {
1980: my @sections = &Apache::loncommon::get_env_multiple('form.section');
1.434 albertel 1981: foreach my $section (@sections) {
1.432 banghart 1982: $section_inputs .= '<input type="hidden" name="section" value="'.$section.'" />'."\n";
1983: }
1984: }
1985: return $section_inputs;
1986: }
1987:
1.44 ng 1988: # --------------------------- show submissions of a student, option to grade
1989: sub submission {
1990: my ($request,$counter,$total) = @_;
1.257 albertel 1991: my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
1992: $udom = ($udom eq '' ? $env{'user.domain'} : $udom); #has form.userdom changed for a student?
1993: my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
1994: $env{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $env{'form.fullname'} eq '';
1.324 albertel 1995: my $symb = &get_symb($request);
1996: if ($symb eq '') { $request->print("Unable to handle ambiguous references:."); return ''; }
1.104 albertel 1997:
1998: if (!&canview($usec)) {
1.398 albertel 1999: $request->print('<span class="LC_warning">Unable to view requested student.('.
2000: $uname.':'.$udom.' in section '.$usec.' in course id '.
2001: $env{'request.course.id'}.')</span>');
1.324 albertel 2002: $request->print(&show_grading_menu_form($symb));
1.104 albertel 2003: return;
2004: }
2005:
1.257 albertel 2006: if (!$env{'form.lastSub'}) { $env{'form.lastSub'} = 'datesub'; }
2007: if (!$env{'form.vProb'}) { $env{'form.vProb'} = 'yes'; }
2008: if (!$env{'form.vAns'}) { $env{'form.vAns'} = 'yes'; }
2009: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.381 albertel 2010: my $checkIcon = '<img alt="'.&mt('Check Mark').
2011: '" src="'.$request->dir_config('lonIconsURL').
1.122 ng 2012: '/check.gif" height="16" border="0" />';
1.41 ng 2013:
1.426 albertel 2014: my %old_essays;
1.41 ng 2015: # header info
2016: if ($counter == 0) {
2017: &sub_page_js($request);
1.257 albertel 2018: &sub_page_kw_js($request) if ($env{'form.handgrade'} eq 'yes');
2019: $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
2020: &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
1.397 albertel 2021: if ($env{'form.handgrade'} eq 'yes' && &files_exist($request, $symb)) {
1.396 banghart 2022: &download_all_link($request, $symb);
2023: }
1.485 albertel 2024: $request->print('<h3> <span class="LC_info">'.&mt('Submission Record').'</span></h3>'."\n".
2025: '<h4> '.&mt('<b>Resource: </b> [_1]',$env{'form.probTitle'}).'</h4>'."\n");
1.118 ng 2026:
1.44 ng 2027: # option to display problem, only once else it cause problems
2028: # with the form later since the problem has a form.
1.257 albertel 2029: if ($env{'form.vProb'} eq 'yes' or $env{'form.vAns'} eq 'yes') {
1.144 albertel 2030: my $mode;
1.257 albertel 2031: if ($env{'form.vProb'} eq 'yes' && $env{'form.vAns'} eq 'yes') {
1.144 albertel 2032: $mode='both';
1.257 albertel 2033: } elsif ($env{'form.vProb'} eq 'yes') {
1.144 albertel 2034: $mode='text';
1.257 albertel 2035: } elsif ($env{'form.vAns'} eq 'yes') {
1.144 albertel 2036: $mode='answer';
2037: }
1.329 albertel 2038: &Apache::lonxml::clear_problem_counter();
1.144 albertel 2039: $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
1.41 ng 2040: }
1.441 www 2041:
1.44 ng 2042: # kwclr is the only variable that is guaranteed to be non blank
2043: # if this subroutine has been called once.
1.41 ng 2044: my %keyhash = ();
1.257 albertel 2045: if ($env{'form.kwclr'} eq '' && $env{'form.handgrade'} eq 'yes') {
1.41 ng 2046: %keyhash = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 2047: $env{'course.'.$env{'request.course.id'}.'.domain'},
2048: $env{'course.'.$env{'request.course.id'}.'.num'});
1.41 ng 2049:
1.257 albertel 2050: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
2051: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
2052: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
2053: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
2054: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
2055: $env{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
2056: $keyhash{$symb.'_subject'} : $env{'form.probTitle'};
2057: $env{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1.41 ng 2058: }
1.257 albertel 2059: my $overRideScore = $env{'form.overRideScore'} eq '' ? 'no' : $env{'form.overRideScore'};
1.442 banghart 2060: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.303 banghart 2061: $request->print('<form action="/adm/grades" method="post" name="SCORE" enctype="multipart/form-data">'."\n".
1.41 ng 2062: '<input type="hidden" name="command" value="handgrade" />'."\n".
1.257 albertel 2063: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.442 banghart 2064: '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.120 ng 2065: '<input type="hidden" name="overRideScore" value="'.$overRideScore.'" />'."\n".
1.257 albertel 2066: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.41 ng 2067: '<input type="hidden" name="refresh" value="off" />'."\n".
1.120 ng 2068: '<input type="hidden" name="studentNo" value="" />'."\n".
2069: '<input type="hidden" name="gradeOpt" value="" />'."\n".
1.418 albertel 2070: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 2071: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" />'."\n".
2072: '<input type="hidden" name="vProb" value="'.$env{'form.vProb'}.'" />'."\n".
2073: '<input type="hidden" name="vAns" value="'.$env{'form.vAns'}.'" />'."\n".
2074: '<input type="hidden" name="lastSub" value="'.$env{'form.lastSub'}.'" />'."\n".
1.432 banghart 2075: &build_section_inputs().
1.326 albertel 2076: '<input type="hidden" name="submitonly" value="'.$env{'form.submitonly'}.'" />'."\n".
2077: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" />'."\n".
1.41 ng 2078: '<input type="hidden" name="NCT"'.
1.257 albertel 2079: ' value="'.($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : $total+1).'" />'."\n");
2080: if ($env{'form.handgrade'} eq 'yes') {
2081: $request->print('<input type="hidden" name="keywords" value="'.$env{'form.keywords'}.'" />'."\n".
2082: '<input type="hidden" name="kwclr" value="'.$env{'form.kwclr'}.'" />'."\n".
2083: '<input type="hidden" name="kwsize" value="'.$env{'form.kwsize'}.'" />'."\n".
2084: '<input type="hidden" name="kwstyle" value="'.$env{'form.kwstyle'}.'" />'."\n".
2085: '<input type="hidden" name="msgsub" value="'.$env{'form.msgsub'}.'" />'."\n".
1.123 ng 2086: '<input type="hidden" name="shownSub" value="0" />'."\n".
1.257 albertel 2087: '<input type="hidden" name="savemsgN" value="'.$env{'form.savemsgN'}.'" />'."\n");
1.154 albertel 2088: foreach my $partid (&Apache::loncommon::get_env_multiple('form.vPart')) {
2089: $request->print('<input type="hidden" name="vPart" value="'.$partid.'" />'."\n");
2090: }
1.123 ng 2091: }
1.41 ng 2092:
2093: my ($cts,$prnmsg) = (1,'');
1.257 albertel 2094: while ($cts <= $env{'form.savemsgN'}) {
1.41 ng 2095: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
1.123 ng 2096: (!exists($keyhash{$symb.'_savemsg'.$cts}) ?
1.257 albertel 2097: &Apache::lonfeedback::clear_out_html($env{'form.savemsg'.$cts}) :
1.80 ng 2098: &Apache::lonfeedback::clear_out_html($keyhash{$symb.'_savemsg'.$cts})).
1.123 ng 2099: '" />'."\n".
2100: '<input type="hidden" name="shownOnce'.$cts.'" value="0" />'."\n";
1.41 ng 2101: $cts++;
2102: }
2103: $request->print($prnmsg);
1.32 ng 2104:
1.257 albertel 2105: if ($env{'form.handgrade'} eq 'yes' && $env{'form.showgrading'} eq 'yes') {
1.596.2.4 raeburn 2106:
2107: my %lt = &Apache::lonlocal::texthash(
2108: keyw => 'Keyword Options',
2109: list => 'List',
2110: past => 'Paste Selection to List',
1.596.2.9 raeburn 2111: high => 'Highlight Attribute',
1.596.2.4 raeburn 2112: );
1.88 www 2113: #
2114: # Print out the keyword options line
2115: #
1.41 ng 2116: $request->print(<<KEYWORDS);
1.596.2.4 raeburn 2117: <b>$lt{'keyw'}:</b>
2118: <a href="javascript:keywords(document.SCORE);" target="_self">$lt{'list'}</a>
1.589 bisitz 2119: <a href="#" onmousedown="javascript:getSel(); return false"
1.596.2.4 raeburn 2120: CLASS="page">$lt{'past'}</a>
2121: <a href="javascript:kwhighlight();" target="_self">$lt{'high'}</a><br /><br />
1.38 ng 2122: KEYWORDS
1.88 www 2123: #
2124: # Load the other essays for similarity check
2125: #
1.324 albertel 2126: my (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb);
1.384 albertel 2127: my ($adom,$aname,$apath)=($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
1.359 www 2128: $apath=&escape($apath);
1.88 www 2129: $apath=~s/\W/\_/gs;
1.426 albertel 2130: %old_essays=&Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
1.41 ng 2131: }
2132: }
1.44 ng 2133:
1.441 www 2134: # This is where output for one specific student would start
1.592 bisitz 2135: my $add_class = ($counter%2) ? ' LC_grade_show_user_odd_row' : '';
2136: $request->print(
2137: "\n\n"
2138: .'<div class="LC_grade_show_user'.$add_class.'">'
2139: .'<h2>'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).'</h2>'
2140: ."\n"
2141: );
1.441 www 2142:
1.592 bisitz 2143: # Show additional functions if allowed
2144: if ($perm{'vgr'}) {
2145: $request->print(
2146: &Apache::loncommon::track_student_link(
2147: &mt('View recent activity'),
2148: $uname,$udom,'check')
2149: .' '
2150: );
2151: }
2152: if ($perm{'opa'}) {
2153: $request->print(
2154: &Apache::loncommon::pprmlink(
2155: &mt('Set/Change parameters'),
2156: $uname,$udom,$symb,'check'));
2157: }
2158:
2159: # Show Problem
1.257 albertel 2160: if ($env{'form.vProb'} eq 'all' or $env{'form.vAns'} eq 'all') {
1.144 albertel 2161: my $mode;
1.257 albertel 2162: if ($env{'form.vProb'} eq 'all' && $env{'form.vAns'} eq 'all') {
1.144 albertel 2163: $mode='both';
1.257 albertel 2164: } elsif ($env{'form.vProb'} eq 'all' ) {
1.144 albertel 2165: $mode='text';
1.257 albertel 2166: } elsif ($env{'form.vAns'} eq 'all') {
1.144 albertel 2167: $mode='answer';
2168: }
1.329 albertel 2169: &Apache::lonxml::clear_problem_counter();
1.475 albertel 2170: $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode,{'request.prefix' => 'ctr'.$counter}));
1.58 albertel 2171: }
1.144 albertel 2172:
1.257 albertel 2173: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.582 raeburn 2174: my $res_error;
2175: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
2176: if ($res_error) {
2177: $request->print(&navmap_errormsg());
2178: return;
2179: }
1.41 ng 2180:
1.44 ng 2181: # Display student info
1.41 ng 2182: $request->print(($counter == 0 ? '' : '<br />'));
1.590 bisitz 2183:
2184: my $result='<div class="LC_Box">'
2185: .'<h3 class="LC_hcell">'.&mt('Submissions').'</h3>';
1.45 ng 2186: $result.='<input type="hidden" name="name'.$counter.
1.588 bisitz 2187: '" value="'.$env{'form.fullname'}.'" />'."\n";
1.469 albertel 2188: if ($env{'form.handgrade'} eq 'no') {
1.588 bisitz 2189: $result.='<p class="LC_info">'
2190: .&mt('Part(s) graded correct by the computer is marked with a [_1] symbol.',$checkIcon)
2191: ."</p>\n";
1.469 albertel 2192: }
2193:
1.118 ng 2194: # If any part of the problem is an essay-response (handgraded), then check for collaborators
1.464 albertel 2195: my $fullname;
2196: my $col_fullnames = [];
1.257 albertel 2197: if ($env{'form.handgrade'} eq 'yes') {
1.464 albertel 2198: (my $sub_result,$fullname,$col_fullnames)=
2199: &check_collaborators($symb,$uname,$udom,\%record,$handgrade,
2200: $counter);
2201: $result.=$sub_result;
1.41 ng 2202: }
1.44 ng 2203: $request->print($result."\n");
1.588 bisitz 2204:
1.44 ng 2205: # print student answer/submission
1.588 bisitz 2206: # Options are (1) Handgraded submission only
1.44 ng 2207: # (2) Last submission, includes submission that is not handgraded
2208: # (for multi-response type part)
2209: # (3) Last submission plus the parts info
2210: # (4) The whole record for this student
1.257 albertel 2211: if ($env{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
1.151 albertel 2212: my ($string,$timestamp)= &get_last_submission(\%record);
1.468 albertel 2213:
2214: my $lastsubonly;
2215:
1.588 bisitz 2216: if ($$timestamp eq '') {
2217: $lastsubonly.='<div class="LC_grade_submissions_body">'.$$string[0].'</div>';
2218: } else {
1.592 bisitz 2219: $lastsubonly =
2220: '<div class="LC_grade_submissions_body">'
2221: .'<b>'.&mt('Date Submitted:').'</b> '.$$timestamp."\n";
1.468 albertel 2222:
1.151 albertel 2223: my %seenparts;
1.375 albertel 2224: my @part_response_id = &flatten_responseType($responseType);
2225: foreach my $part (@part_response_id) {
1.393 albertel 2226: next if ($env{'form.lastSub'} eq 'hdgrade'
2227: && $$handgrade{$$part[0].'_'.$$part[1]} ne 'yes');
2228:
1.375 albertel 2229: my ($partid,$respid) = @{ $part };
1.324 albertel 2230: my $display_part=&get_display_part($partid,$symb);
1.257 albertel 2231: if ($env{"form.$uname:$udom:$partid:submitted_by"}) {
1.151 albertel 2232: if (exists($seenparts{$partid})) { next; }
2233: $seenparts{$partid}=1;
1.207 albertel 2234: my $submitby='<b>Part:</b> '.$display_part.
2235: ' <b>Collaborative submission by:</b> '.
1.151 albertel 2236: '<a href="javascript:viewSubmitter(\''.
1.257 albertel 2237: $env{"form.$uname:$udom:$partid:submitted_by"}.
1.417 albertel 2238: '\');" target="_self">'.
1.257 albertel 2239: $$fullname{$env{"form.$uname:$udom:$partid:submitted_by"}}.'</a><br />';
1.151 albertel 2240: $request->print($submitby);
2241: next;
2242: }
2243: my $responsetype = $responseType->{$partid}->{$respid};
2244: if (!exists($record{"resource.$partid.$respid.submission"})) {
1.577 bisitz 2245: $lastsubonly.="\n".'<div class="LC_grade_submission_part">'.
2246: '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
2247: ' <span class="LC_internal_info">'.
1.596.2.4 raeburn 2248: '('.&mt('Response ID: [_1]',$respid).')'.
1.577 bisitz 2249: '</span> '.
1.539 riegler 2250: '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br /><br /></div>';
1.151 albertel 2251: next;
2252: }
1.468 albertel 2253: foreach my $submission (@$string) {
2254: my ($partid,$respid) = ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
1.375 albertel 2255: if (join('_',@{$part}) ne ($partid.'_'.$respid)) { next; }
1.596 raeburn 2256: my ($ressub,$hide,$subval) = split(/:/,$submission,3);
1.151 albertel 2257: # Similarity check
2258: my $similar='';
1.596.2.2 raeburn 2259: my ($type,$trial,$rndseed);
2260: if ($hide eq 'rand') {
2261: $type = 'randomizetry';
2262: $trial = $record{"resource.$partid.tries"};
2263: $rndseed = $record{"resource.$partid.rndseed"};
2264: }
1.257 albertel 2265: if($env{'form.checkPlag'}){
1.151 albertel 2266: my ($oname,$odom,$ocrsid,$oessay,$osim)=
1.426 albertel 2267: &most_similar($uname,$udom,$subval,\%old_essays);
1.151 albertel 2268: if ($osim) {
2269: $osim=int($osim*100.0);
1.426 albertel 2270: my %old_course_desc =
2271: &Apache::lonnet::coursedescription($ocrsid,
2272: {'one_time' => 1});
2273:
1.596.2.2 raeburn 2274: if ($hide eq 'anon') {
1.596 raeburn 2275: $similar='<hr /><span class="LC_warning">'.&mt("Essay was found to be similar to another essay submitted for this assignment.").'<br />'.
2276: &mt('As the current submission is for an anonymous survey, no other details are available.').'</span><hr />';
2277: } else {
2278: $similar="<hr /><h3><span class=\"LC_warning\">".
2279: &mt('Essay is [_1]% similar to an essay by [_2] in course [_3] (course id [_4]:[_5])',
2280: $osim,
2281: &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')',
2282: $old_course_desc{'description'},
2283: $old_course_desc{'num'},
2284: $old_course_desc{'domain'}).
2285: '</span></h3><blockquote><i>'.
2286: &keywords_highlight($oessay).
2287: '</i></blockquote><hr />';
2288: }
1.151 albertel 2289: }
1.150 albertel 2290: }
1.596.2.2 raeburn 2291: my $order=&get_order($partid,$respid,$symb,$uname,$udom,
2292: undef,$type,$trial,$rndseed);
1.257 albertel 2293: if ($env{'form.lastSub'} eq 'lastonly' ||
2294: ($env{'form.lastSub'} eq 'hdgrade' &&
1.377 albertel 2295: $$handgrade{$$part[0].'_'.$$part[1]} eq 'yes')) {
1.324 albertel 2296: my $display_part=&get_display_part($partid,$symb);
1.577 bisitz 2297: $lastsubonly.='<div class="LC_grade_submission_part">'.
2298: '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
2299: ' <span class="LC_internal_info">'.
1.596.2.4 raeburn 2300: '('.&mt('Response ID: [_1]',$respid).')'.
2301: '</span> ';
1.313 banghart 2302: my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record);
2303: if (@$files) {
1.596.2.2 raeburn 2304: if ($hide eq 'anon') {
1.596 raeburn 2305: $lastsubonly.='<br />'.&mt('[quant,_1,file] uploaded to this anonymous survey',scalar(@{$files}));
2306: } else {
2307: $lastsubonly.='<br /><span class="LC_warning">'.&mt('Like all files provided by users, this file may contain viruses').'</span><br />';
2308: foreach my $file (@$files) {
2309: &Apache::lonnet::allowuploaded('/adm/grades',$file);
2310: $lastsubonly.='<br /><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.&Apache::loncommon::icon($file).'" border="0" /> '.$file.'</a>';
2311: }
2312: }
1.236 albertel 2313: $lastsubonly.='<br />';
1.41 ng 2314: }
1.596.2.2 raeburn 2315: if ($hide eq 'anon') {
1.596 raeburn 2316: $lastsubonly.='<b>'.&mt('Anonymous Survey').'</b>';
2317: } else {
2318: $lastsubonly.='<b>'.&mt('Submitted Answer:').' </b>'.
2319: &cleanRecord($subval,$responsetype,$symb,$partid,
1.596.2.2 raeburn 2320: $respid,\%record,$order,undef,$uname,$udom,$type,$trial,$rndseed);
1.596 raeburn 2321: }
1.151 albertel 2322: if ($similar) {$lastsubonly.="<br /><br />$similar\n";}
1.468 albertel 2323: $lastsubonly.='</div>';
1.41 ng 2324: }
2325: }
2326: }
1.588 bisitz 2327: $lastsubonly.='</div>'."\n"; # End: LC_grade_submissions_body
1.151 albertel 2328: }
2329: $request->print($lastsubonly);
1.468 albertel 2330: } elsif ($env{'form.lastSub'} eq 'datesub') {
1.324 albertel 2331: my (undef,$responseType,undef,$parts) = &showResourceInfo($symb);
1.148 albertel 2332: $request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
1.257 albertel 2333: } elsif ($env{'form.lastSub'} =~ /^(last|all)$/) {
1.41 ng 2334: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
1.257 albertel 2335: $env{'request.course.id'},
1.44 ng 2336: $last,'.submission',
2337: 'Apache::grades::keywords_highlight'));
1.41 ng 2338: }
1.120 ng 2339:
1.121 ng 2340: $request->print('<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
2341: .$udom.'" />'."\n");
1.44 ng 2342: # return if view submission with no grading option
1.257 albertel 2343: if ($env{'form.showgrading'} eq '' || (!&canmodify($usec))) {
1.120 ng 2344: my $toGrade.='<input type="button" value="Grade Student" '.
1.589 bisitz 2345: 'onclick="javascript:checksubmit(this.form,\'Grade Student\',\''
1.417 albertel 2346: .$counter.'\');" target="_self" /> '."\n" if (&canmodify($usec));
1.468 albertel 2347: $toGrade.='</div>'."\n";
1.257 albertel 2348: if (($env{'form.command'} eq 'submission') ||
2349: ($env{'form.command'} eq 'processGroup' && $counter == $total)) {
1.324 albertel 2350: $toGrade.='</form>'.&show_grading_menu_form($symb);
1.169 albertel 2351: }
1.180 albertel 2352: $request->print($toGrade);
1.41 ng 2353: return;
1.180 albertel 2354: } else {
1.468 albertel 2355: $request->print('</div>'."\n");
1.41 ng 2356: }
1.33 ng 2357:
1.121 ng 2358: # essay grading message center
1.257 albertel 2359: if ($env{'form.handgrade'} eq 'yes') {
1.468 albertel 2360: my $result='<div class="LC_grade_message_center">';
2361:
2362: $result.='<div class="LC_grade_message_center_header">'.
2363: &mt('Send Message').'</div><div class="LC_grade_message_center_body">';
1.257 albertel 2364: my ($lastname,$givenn) = split(/,/,$env{'form.fullname'});
1.118 ng 2365: my $msgfor = $givenn.' '.$lastname;
1.464 albertel 2366: if (scalar(@$col_fullnames) > 0) {
2367: my $lastone = pop(@$col_fullnames);
2368: $msgfor .= ', '.(join ', ',@$col_fullnames).' and '.$lastone.'.';
1.118 ng 2369: }
2370: $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
1.468 albertel 2371: $result.='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
1.121 ng 2372: '<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n";
2373: $result.=' <a href="javascript:msgCenter(document.SCORE,'.$counter.
1.417 albertel 2374: ',\''.$msgfor.'\');" target="_self">'.
1.464 albertel 2375: &mt('Compose message to student').(scalar(@$col_fullnames) >= 1 ? 's' : '').'</a><label> ('.
1.350 albertel 2376: &mt('incl. grades').' <input type="checkbox" name="withgrades'.$counter.'" /></label>)'.
1.118 ng 2377: '<img src="'.$request->dir_config('lonIconsURL').
2378: '/mailbkgrd.gif" width="14" height="10" name="mailicon'.$counter.'" />'."\n".
1.298 www 2379: '<br /> ('.
1.468 albertel 2380: &mt('Message will be sent when you click on Save & Next below.').")\n";
2381: $result.='</div></div>';
1.121 ng 2382: $request->print($result);
1.118 ng 2383: }
1.41 ng 2384:
2385: my %seen = ();
2386: my @partlist;
1.129 ng 2387: my @gradePartRespid;
1.375 albertel 2388: my @part_response_id = &flatten_responseType($responseType);
1.585 bisitz 2389: $request->print(
1.588 bisitz 2390: '<div class="LC_Box">'
2391: .'<h3 class="LC_hcell">'.&mt('Assign Grades').'</h3>'
1.585 bisitz 2392: );
1.592 bisitz 2393: $request->print(&gradeBox_start());
1.375 albertel 2394: foreach my $part_response_id (@part_response_id) {
2395: my ($partid,$respid) = @{ $part_response_id };
2396: my $part_resp = join('_',@{ $part_response_id });
1.322 albertel 2397: next if ($seen{$partid} > 0);
1.41 ng 2398: $seen{$partid}++;
1.393 albertel 2399: next if ($$handgrade{$part_resp} ne 'yes'
2400: && $env{'form.lastSub'} eq 'hdgrade');
1.524 raeburn 2401: push(@partlist,$partid);
2402: push(@gradePartRespid,$partid.'.'.$respid);
1.322 albertel 2403: $request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
1.41 ng 2404: }
1.585 bisitz 2405: $request->print(&gradeBox_end()); # </div>
2406: $request->print('</div>');
1.468 albertel 2407:
2408: $request->print('<div class="LC_grade_info_links">');
2409: $request->print('</div>');
2410:
1.45 ng 2411: $result='<input type="hidden" name="partlist'.$counter.
2412: '" value="'.(join ":",@partlist).'" />'."\n";
1.129 ng 2413: $result.='<input type="hidden" name="gradePartRespid'.
2414: '" value="'.(join ":",@gradePartRespid).'" />'."\n" if ($counter == 0);
1.45 ng 2415: my $ctr = 0;
2416: while ($ctr < scalar(@partlist)) {
2417: $result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
2418: $partlist[$ctr].'" />'."\n";
2419: $ctr++;
2420: }
1.468 albertel 2421: $request->print($result.''."\n");
1.41 ng 2422:
1.441 www 2423: # Done with printing info for one student
2424:
1.468 albertel 2425: $request->print('</div>');#LC_grade_show_user
1.441 www 2426:
2427:
1.41 ng 2428: # print end of form
2429: if ($counter == $total) {
1.592 bisitz 2430: my $endform='<br /><hr /><table border="0"><tr><td>'."\n";
1.485 albertel 2431: $endform.='<input type="button" value="'.&mt('Save & Next').'" '.
1.589 bisitz 2432: 'onclick="javascript:checksubmit(this.form,\'Save & Next\','.
1.417 albertel 2433: $total.','.scalar(@partlist).');" target="_self" /> '."\n";
1.119 ng 2434: my $ntstu ='<select name="NTSTU">'.
2435: '<option>1</option><option>2</option>'.
2436: '<option>3</option><option>5</option>'.
2437: '<option>7</option><option>10</option></select>'."\n";
1.257 albertel 2438: my $nsel = ($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : '1');
1.401 albertel 2439: $ntstu =~ s/<option>$nsel</<option selected="selected">$nsel</;
1.578 raeburn 2440: $endform.=&mt('[_1]student(s)',$ntstu);
1.485 albertel 2441: $endform.=' <input type="button" value="'.&mt('Previous').'" '.
1.589 bisitz 2442: 'onclick="javascript:checksubmit(this.form,\'Previous\');" target="_self" /> '."\n".
1.485 albertel 2443: '<input type="button" value="'.&mt('Next').'" '.
1.589 bisitz 2444: 'onclick="javascript:checksubmit(this.form,\'Next\');" target="_self" /> ';
1.592 bisitz 2445: $endform.='<span class="LC_warning">'.
2446: &mt('(Next and Previous (student) do not save the scores.)').
2447: '</span>'."\n" ;
1.349 albertel 2448: $endform.="<input type='hidden' value='".&get_increment().
1.348 bowersj2 2449: "' name='increment' />";
1.485 albertel 2450: $endform.='</td></tr></table></form>';
1.324 albertel 2451: $endform.=&show_grading_menu_form($symb);
1.41 ng 2452: $request->print($endform);
2453: }
2454: return '';
1.38 ng 2455: }
2456:
1.464 albertel 2457: sub check_collaborators {
2458: my ($symb,$uname,$udom,$record,$handgrade,$counter) = @_;
2459: my ($result,@col_fullnames);
2460: my ($classlist,undef,$fullname) = &getclasslist('all','0');
2461: foreach my $part (keys(%$handgrade)) {
2462: my $ncol = &Apache::lonnet::EXT('resource.'.$part.
2463: '.maxcollaborators',
2464: $symb,$udom,$uname);
2465: next if ($ncol <= 0);
2466: $part =~ s/\_/\./g;
2467: next if ($record->{'resource.'.$part.'.collaborators'} eq '');
2468: my (@good_collaborators, @bad_collaborators);
2469: foreach my $possible_collaborator
1.596.2.4 raeburn 2470: (split(/[,;\s]+/,$record->{'resource.'.$part.'.collaborators'})) {
1.464 albertel 2471: $possible_collaborator =~ s/[\$\^\(\)]//g;
2472: next if ($possible_collaborator eq '');
1.596.2.8 raeburn 2473: my ($co_name,$co_dom) = split(/:/,$possible_collaborator);
1.464 albertel 2474: $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
2475: next if ($co_name eq $uname && $co_dom eq $udom);
2476: # Doing this grep allows 'fuzzy' specification
2477: my @matches = grep(/^\Q$co_name\E:\Q$co_dom\E$/i,
2478: keys(%$classlist));
2479: if (! scalar(@matches)) {
2480: push(@bad_collaborators, $possible_collaborator);
2481: } else {
2482: push(@good_collaborators, @matches);
2483: }
2484: }
2485: if (scalar(@good_collaborators) != 0) {
1.596.2.8 raeburn 2486: $result.='<br />'.&mt('Collaborators:').'<ol>';
1.464 albertel 2487: foreach my $name (@good_collaborators) {
2488: my ($lastname,$givenn) = split(/,/,$$fullname{$name});
2489: push(@col_fullnames, $givenn.' '.$lastname);
1.596.2.4 raeburn 2490: $result.='<li>'.$fullname->{$name}.'</li>';
1.464 albertel 2491: }
1.596.2.4 raeburn 2492: $result.='</ol><br />'."\n";
1.466 albertel 2493: my ($part)=split(/\./,$part);
1.464 albertel 2494: $result.='<input type="hidden" name="collaborator'.$counter.
2495: '" value="'.$part.':'.(join ':',@good_collaborators).'" />'.
2496: "\n";
2497: }
2498: if (scalar(@bad_collaborators) > 0) {
1.466 albertel 2499: $result.='<div class="LC_warning">';
1.464 albertel 2500: $result.=&mt('This student has submitted [quant,_1,invalid collaborator]: [_2]',scalar(@bad_collaborators),join(', ',@bad_collaborators));
2501: $result .= '</div>';
2502: }
2503: if (scalar(@bad_collaborators > $ncol)) {
1.466 albertel 2504: $result .= '<div class="LC_warning">';
1.464 albertel 2505: $result .= &mt('This student has submitted too many '.
2506: 'collaborators. Maximum is [_1].',$ncol);
2507: $result .= '</div>';
2508: }
2509: }
2510: return ($result,$fullname,\@col_fullnames);
2511: }
2512:
1.44 ng 2513: #--- Retrieve the last submission for all the parts
1.38 ng 2514: sub get_last_submission {
1.119 ng 2515: my ($returnhash)=@_;
1.596 raeburn 2516: my (@string,$timestamp,%lasthidden);
1.119 ng 2517: if ($$returnhash{'version'}) {
1.46 ng 2518: my %lasthash=();
2519: my ($version);
1.119 ng 2520: for ($version=1;$version<=$$returnhash{'version'};$version++) {
1.397 albertel 2521: foreach my $key (sort(split(/\:/,
2522: $$returnhash{$version.':keys'}))) {
2523: $lasthash{$key}=$$returnhash{$version.':'.$key};
2524: $timestamp =
1.545 raeburn 2525: &Apache::lonlocal::locallocaltime($$returnhash{$version.':timestamp'});
1.46 ng 2526: }
2527: }
1.596.2.2 raeburn 2528: my (%typeparts,%randombytry);
1.596 raeburn 2529: my $showsurv =
2530: &Apache::lonnet::allowed('vas',$env{'request.course.id'});
2531: foreach my $key (sort(keys(%lasthash))) {
2532: if ($key =~ /\.type$/) {
2533: if (($lasthash{$key} eq 'anonsurvey') ||
1.596.2.2 raeburn 2534: ($lasthash{$key} eq 'anonsurveycred') ||
2535: ($lasthash{$key} eq 'randomizetry')) {
1.596 raeburn 2536: my ($ign,@parts) = split(/\./,$key);
2537: pop(@parts);
1.596.2.3 raeburn 2538: my $id = join('.',@parts);
1.596.2.2 raeburn 2539: if ($lasthash{$key} eq 'randomizetry') {
2540: $randombytry{$ign.'.'.$id} = $lasthash{$key};
2541: } else {
2542: unless ($showsurv) {
2543: $typeparts{$ign.'.'.$id} = $lasthash{$key};
2544: }
1.596 raeburn 2545: }
2546: delete($lasthash{$key});
2547: }
2548: }
2549: }
2550: my @hidden = keys(%typeparts);
1.596.2.2 raeburn 2551: my @randomize = keys(%randombytry);
1.397 albertel 2552: foreach my $key (keys(%lasthash)) {
2553: next if ($key !~ /\.submission$/);
1.596 raeburn 2554: my $hide;
2555: if (@hidden) {
2556: foreach my $id (@hidden) {
2557: if ($key =~ /^\Q$id\E/) {
1.596.2.2 raeburn 2558: $hide = 'anon';
1.596 raeburn 2559: last;
2560: }
2561: }
2562: }
1.596.2.2 raeburn 2563: unless ($hide) {
2564: if (@randomize) {
2565: foreach my $id (@hidden) {
2566: if ($key =~ /^\Q$id\E/) {
2567: $hide = 'rand';
2568: last;
2569: }
2570: }
2571: }
2572: }
1.397 albertel 2573: my ($partid,$foo) = split(/submission$/,$key);
2574: my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
1.398 albertel 2575: '<span class="LC_warning">Draft Copy</span> ' : '';
1.596 raeburn 2576: push(@string, join(':', $key, $hide, $draft.$lasthash{$key}));
1.41 ng 2577: }
2578: }
1.397 albertel 2579: if (!@string) {
2580: $string[0] =
1.539 riegler 2581: '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span>';
1.397 albertel 2582: }
2583: return (\@string,\$timestamp);
1.38 ng 2584: }
1.35 ng 2585:
1.44 ng 2586: #--- High light keywords, with style choosen by user.
1.38 ng 2587: sub keywords_highlight {
1.44 ng 2588: my $string = shift;
1.257 albertel 2589: my $size = $env{'form.kwsize'} eq '0' ? '' : 'size='.$env{'form.kwsize'};
2590: my $styleon = $env{'form.kwstyle'} eq '' ? '' : $env{'form.kwstyle'};
1.41 ng 2591: (my $styleoff = $styleon) =~ s/\</\<\//;
1.257 albertel 2592: my @keylist = split(/[,\s+]/,$env{'form.keywords'});
1.398 albertel 2593: foreach my $keyword (@keylist) {
2594: $string =~ s/\b\Q$keyword\E(\b|\.)/<font color\=$env{'form.kwclr'} $size\>$styleon$keyword$styleoff<\/font>/gi;
1.41 ng 2595: }
2596: return $string;
1.38 ng 2597: }
1.36 ng 2598:
1.44 ng 2599: #--- Called from submission routine
1.38 ng 2600: sub processHandGrade {
1.41 ng 2601: my ($request) = shift;
1.324 albertel 2602: my $symb = &get_symb($request);
2603: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.257 albertel 2604: my $button = $env{'form.gradeOpt'};
2605: my $ngrade = $env{'form.NCT'};
2606: my $ntstu = $env{'form.NTSTU'};
1.301 albertel 2607: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2608: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2609:
1.44 ng 2610: if ($button eq 'Save & Next') {
2611: my $ctr = 0;
2612: while ($ctr < $ngrade) {
1.257 albertel 2613: my ($uname,$udom) = split(/:/,$env{'form.unamedom'.$ctr});
1.324 albertel 2614: my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$symb,$uname,$udom,$ctr);
1.71 ng 2615: if ($errorflag eq 'no_score') {
2616: $ctr++;
2617: next;
2618: }
1.104 albertel 2619: if ($errorflag eq 'not_allowed') {
1.398 albertel 2620: $request->print("<span class=\"LC_warning\">Not allowed to modify grades for $uname:$udom</span>");
1.104 albertel 2621: $ctr++;
2622: next;
2623: }
1.257 albertel 2624: my $includemsg = $env{'form.includemsg'.$ctr};
1.44 ng 2625: my ($subject,$message,$msgstatus) = ('','','');
1.418 albertel 2626: my $restitle = &Apache::lonnet::gettitle($symb);
2627: my ($feedurl,$showsymb) =
2628: &get_feedurl_and_symb($symb,$uname,$udom);
2629: my $messagetail;
1.62 albertel 2630: if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.298 www 2631: $subject = $env{'form.msgsub'} if ($includemsg =~ /msgsub/);
1.295 www 2632: unless ($subject=~/\w/) { $subject=&mt('Grading Feedback'); }
1.386 raeburn 2633: $subject.=' ['.$restitle.']';
1.44 ng 2634: my (@msgnum) = split(/,/,$includemsg);
2635: foreach (@msgnum) {
1.257 albertel 2636: $message.=$env{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
1.44 ng 2637: }
1.80 ng 2638: $message =&Apache::lonfeedback::clear_out_html($message);
1.298 www 2639: if ($env{'form.withgrades'.$ctr}) {
2640: $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
1.386 raeburn 2641: $messagetail = " for <a href=\"".
1.418 albertel 2642: $feedurl."?symb=$showsymb\">$env{'form.probTitle'}</a>";
1.386 raeburn 2643: }
2644: $msgstatus =
2645: &Apache::lonmsg::user_normal_msg($uname,$udom,$subject,
2646: $message.$messagetail,
1.418 albertel 2647: undef,$feedurl,undef,
1.386 raeburn 2648: undef,undef,$showsymb,
2649: $restitle);
1.574 bisitz 2650: $request->print('<br />'.&mt('Sending message to [_1]',$uname.':'.$udom).': '.
1.596.2.4 raeburn 2651: $msgstatus.'<br />');
1.44 ng 2652: }
1.257 albertel 2653: if ($env{'form.collaborator'.$ctr}) {
1.155 albertel 2654: my @collabstrs=&Apache::loncommon::get_env_multiple("form.collaborator$ctr");
1.150 albertel 2655: foreach my $collabstr (@collabstrs) {
2656: my ($part,@collaborators) = split(/:/,$collabstr);
1.310 banghart 2657: foreach my $collaborator (@collaborators) {
1.150 albertel 2658: my ($errorflag,$pts,$wgt) =
1.324 albertel 2659: &saveHandGrade($request,$symb,$collaborator,$udom,$ctr,
1.257 albertel 2660: $env{'form.unamedom'.$ctr},$part);
1.150 albertel 2661: if ($errorflag eq 'not_allowed') {
1.362 albertel 2662: $request->print("<span class=\"LC_error\">".&mt('Not allowed to modify grades for [_1]',"$collaborator:$udom")."</span>");
1.150 albertel 2663: next;
1.418 albertel 2664: } elsif ($message ne '') {
2665: my ($baseurl,$showsymb) =
2666: &get_feedurl_and_symb($symb,$collaborator,
2667: $udom);
2668: if ($env{'form.withgrades'.$ctr}) {
2669: $messagetail = " for <a href=\"".
1.386 raeburn 2670: $baseurl."?symb=$showsymb\">$env{'form.probTitle'}</a>";
1.150 albertel 2671: }
1.418 albertel 2672: $msgstatus =
2673: &Apache::lonmsg::user_normal_msg($collaborator,$udom,$subject,$message.$messagetail,undef,$baseurl,undef,undef,undef,$showsymb,$restitle);
1.104 albertel 2674: }
1.44 ng 2675: }
2676: }
2677: }
2678: $ctr++;
2679: }
2680: }
2681:
1.257 albertel 2682: if ($env{'form.handgrade'} eq 'yes') {
1.119 ng 2683: # Keywords sorted in alphabatical order
1.257 albertel 2684: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1.119 ng 2685: my %keyhash = ();
1.257 albertel 2686: $env{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
2687: $env{'form.keywords'} =~ s/^\s+|\s+$//;
2688: my (@keywords) = sort(split(/\s+/,$env{'form.keywords'}));
2689: $env{'form.keywords'} = join(' ',@keywords);
2690: $keyhash{$symb.'_keywords'} = $env{'form.keywords'};
2691: $keyhash{$symb.'_subject'} = $env{'form.msgsub'};
2692: $keyhash{$loginuser.'_kwclr'} = $env{'form.kwclr'};
2693: $keyhash{$loginuser.'_kwsize'} = $env{'form.kwsize'};
2694: $keyhash{$loginuser.'_kwstyle'} = $env{'form.kwstyle'};
1.119 ng 2695:
2696: # message center - Order of message gets changed. Blank line is eliminated.
1.257 albertel 2697: # New messages are saved in env for the next student.
1.119 ng 2698: # All messages are saved in nohist_handgrade.db
2699: my ($ctr,$idx) = (1,1);
1.257 albertel 2700: while ($ctr <= $env{'form.savemsgN'}) {
2701: if ($env{'form.savemsg'.$ctr} ne '') {
2702: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.savemsg'.$ctr};
1.119 ng 2703: $idx++;
2704: }
2705: $ctr++;
1.41 ng 2706: }
1.119 ng 2707: $ctr = 0;
2708: while ($ctr < $ngrade) {
1.257 albertel 2709: if ($env{'form.newmsg'.$ctr} ne '') {
2710: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.newmsg'.$ctr};
2711: $env{'form.savemsg'.$idx} = $env{'form.newmsg'.$ctr};
1.119 ng 2712: $idx++;
2713: }
2714: $ctr++;
1.41 ng 2715: }
1.257 albertel 2716: $env{'form.savemsgN'} = --$idx;
2717: $keyhash{$symb.'_savemsgN'} = $env{'form.savemsgN'};
1.119 ng 2718: my $putresult = &Apache::lonnet::put
1.301 albertel 2719: ('nohist_handgrade',\%keyhash,$cdom,$cnum);
1.41 ng 2720: }
1.44 ng 2721: # Called by Save & Refresh from Highlight Attribute Window
1.257 albertel 2722: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
2723: if ($env{'form.refresh'} eq 'on') {
1.86 ng 2724: my ($ctr,$total) = (0,0);
2725: while ($ctr < $ngrade) {
1.257 albertel 2726: $total++ if $env{'form.unamedom'.$ctr} ne '';
1.86 ng 2727: $ctr++;
2728: }
1.257 albertel 2729: $env{'form.NTSTU'}=$ngrade;
1.86 ng 2730: $ctr = 0;
2731: while ($ctr < $total) {
1.257 albertel 2732: my $processUser = $env{'form.unamedom'.$ctr};
2733: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2734: $env{'form.fullname'} = $$fullname{$processUser};
1.86 ng 2735: &submission($request,$ctr,$total-1);
1.41 ng 2736: $ctr++;
2737: }
2738: return '';
2739: }
1.36 ng 2740:
1.121 ng 2741: # Go directly to grade student - from submission or link from chart page
1.120 ng 2742: if ($button eq 'Grade Student') {
1.324 albertel 2743: (undef,undef,$env{'form.handgrade'},undef,undef) = &showResourceInfo($symb);
1.257 albertel 2744: my $processUser = $env{'form.unamedom'.$env{'form.studentNo'}};
2745: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2746: $env{'form.fullname'} = $$fullname{$processUser};
1.120 ng 2747: &submission($request,0,0);
2748: return '';
2749: }
2750:
1.44 ng 2751: # Get the next/previous one or group of students
1.257 albertel 2752: my $firststu = $env{'form.unamedom0'};
2753: my $laststu = $env{'form.unamedom'.($ngrade-1)};
1.119 ng 2754: my $ctr = 2;
1.41 ng 2755: while ($laststu eq '') {
1.257 albertel 2756: $laststu = $env{'form.unamedom'.($ngrade-$ctr)};
1.41 ng 2757: $ctr++;
2758: $laststu = $firststu if ($ctr > $ngrade);
2759: }
1.44 ng 2760:
1.41 ng 2761: my (@parsedlist,@nextlist);
2762: my ($nextflg) = 0;
1.524 raeburn 2763: foreach my $item (sort
1.294 albertel 2764: {
2765: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
2766: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
2767: }
2768: return $a cmp $b;
2769: } (keys(%$fullname))) {
1.41 ng 2770: if ($nextflg == 1 && $button =~ /Next$/) {
1.524 raeburn 2771: push(@parsedlist,$item);
1.41 ng 2772: }
1.524 raeburn 2773: $nextflg = 1 if ($item eq $laststu);
1.41 ng 2774: if ($button eq 'Previous') {
1.524 raeburn 2775: last if ($item eq $firststu);
2776: push(@parsedlist,$item);
1.41 ng 2777: }
2778: }
2779: $ctr = 0;
2780: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
1.582 raeburn 2781: my $res_error;
2782: my ($partlist) = &response_type($symb,\$res_error);
2783: if ($res_error) {
2784: $request->print(&navmap_errormsg());
2785: return;
2786: }
1.41 ng 2787: foreach my $student (@parsedlist) {
1.257 albertel 2788: my $submitonly=$env{'form.submitonly'};
1.41 ng 2789: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 2790:
2791: if ($submitonly eq 'queued') {
2792: my %queue_status =
2793: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
2794: $udom,$uname);
2795: next if (!defined($queue_status{'gradingqueue'}));
2796: }
2797:
1.156 albertel 2798: if ($submitonly =~ /^(yes|graded|incorrect)$/) {
1.257 albertel 2799: # my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 2800: my %status=&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 2801: my $submitted = 0;
1.248 albertel 2802: my $ungraded = 0;
2803: my $incorrect = 0;
1.524 raeburn 2804: foreach my $item (keys(%status)) {
2805: $submitted = 1 if ($status{$item} ne 'nothing');
2806: $ungraded = 1 if ($status{$item} =~ /^ungraded/);
2807: $incorrect = 1 if ($status{$item} =~ /^incorrect/);
2808: my ($foo,$partid,$foo1) = split(/\./,$item);
1.145 albertel 2809: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
2810: $submitted = 0;
2811: }
1.41 ng 2812: }
1.156 albertel 2813: next if (!$submitted && ($submitonly eq 'yes' ||
2814: $submitonly eq 'incorrect' ||
2815: $submitonly eq 'graded'));
1.248 albertel 2816: next if (!$ungraded && ($submitonly eq 'graded'));
2817: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 2818: }
1.524 raeburn 2819: push(@nextlist,$student) if ($ctr < $ntstu);
1.129 ng 2820: last if ($ctr == $ntstu);
1.41 ng 2821: $ctr++;
2822: }
1.36 ng 2823:
1.41 ng 2824: $ctr = 0;
2825: my $total = scalar(@nextlist)-1;
1.39 ng 2826:
1.524 raeburn 2827: foreach (sort(@nextlist)) {
1.41 ng 2828: my ($uname,$udom,$submitter) = split(/:/);
1.257 albertel 2829: $env{'form.student'} = $uname;
2830: $env{'form.userdom'} = $udom;
2831: $env{'form.fullname'} = $$fullname{$_};
1.41 ng 2832: &submission($request,$ctr,$total);
2833: $ctr++;
2834: }
2835: if ($total < 0) {
1.485 albertel 2836: my $the_end = '<h3><span class="LC_info">'.&mt('LON-CAPA User Message').'</span></h3><br />'."\n";
1.596.2.4 raeburn 2837: $the_end.='<p>'.&mt('[_1]Message:[_2] No more students for this section or class.','<b>','</b>').'</p>'."\n";
1.485 albertel 2838: $the_end.=&mt('Click on the button below to return to the grading menu.').'<br /><br />'."\n";
1.324 albertel 2839: $the_end.=&show_grading_menu_form($symb);
1.41 ng 2840: $request->print($the_end);
2841: }
2842: return '';
1.38 ng 2843: }
1.36 ng 2844:
1.44 ng 2845: #---- Save the score and award for each student, if changed
1.38 ng 2846: sub saveHandGrade {
1.324 albertel 2847: my ($request,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
1.342 banghart 2848: my @version_parts;
1.104 albertel 2849: my $usec = &Apache::lonnet::getsection($domain,$stuname,
1.257 albertel 2850: $env{'request.course.id'});
1.104 albertel 2851: if (!&canmodify($usec)) { return('not_allowed'); }
1.337 banghart 2852: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
1.251 banghart 2853: my @parts_graded;
1.77 ng 2854: my %newrecord = ();
2855: my ($pts,$wgt) = ('','');
1.269 raeburn 2856: my %aggregate = ();
2857: my $aggregateflag = 0;
1.301 albertel 2858: my @parts = split(/:/,$env{'form.partlist'.$newflg});
2859: foreach my $new_part (@parts) {
1.337 banghart 2860: #collaborator ($submi may vary for different parts
1.259 banghart 2861: if ($submitter && $new_part ne $part) { next; }
2862: my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
1.125 ng 2863: if ($dropMenu eq 'excused') {
1.259 banghart 2864: if ($record{'resource.'.$new_part.'.solved'} ne 'excused') {
2865: $newrecord{'resource.'.$new_part.'.solved'} = 'excused';
2866: if (exists($record{'resource.'.$new_part.'.awarded'})) {
2867: $newrecord{'resource.'.$new_part.'.awarded'} = '';
1.58 albertel 2868: }
1.364 banghart 2869: $newrecord{'resource.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.58 albertel 2870: }
1.125 ng 2871: } elsif ($dropMenu eq 'reset status'
1.259 banghart 2872: && exists($record{'resource.'.$new_part.'.solved'})) { #don't bother if no old records -> no attempts
1.524 raeburn 2873: foreach my $key (keys(%record)) {
1.259 banghart 2874: if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
1.197 albertel 2875: }
1.259 banghart 2876: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2877: "$env{'user.name'}:$env{'user.domain'}";
1.270 albertel 2878: my $totaltries = $record{'resource.'.$part.'.tries'};
2879:
2880: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
2881: [$new_part]);
2882: my $aggtries =$totaltries;
1.269 raeburn 2883: if ($last_resets{$new_part}) {
1.270 albertel 2884: $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
2885: $new_part);
1.269 raeburn 2886: }
1.270 albertel 2887:
2888: my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
1.269 raeburn 2889: if ($aggtries > 0) {
1.327 albertel 2890: &decrement_aggs($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
1.269 raeburn 2891: $aggregateflag = 1;
2892: }
1.125 ng 2893: } elsif ($dropMenu eq '') {
1.259 banghart 2894: $pts = ($env{'form.GD_BOX'.$newflg.'_'.$new_part} ne '' ?
2895: $env{'form.GD_BOX'.$newflg.'_'.$new_part} :
2896: $env{'form.RADVAL'.$newflg.'_'.$new_part});
2897: if ($pts eq '' && $env{'form.GD_SEL'.$newflg.'_'.$new_part} eq '') {
1.153 albertel 2898: next;
2899: }
1.259 banghart 2900: $wgt = $env{'form.WGT'.$newflg.'_'.$new_part} eq '' ? 1 :
2901: $env{'form.WGT'.$newflg.'_'.$new_part};
1.41 ng 2902: my $partial= $pts/$wgt;
1.259 banghart 2903: if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
1.153 albertel 2904: #do not update score for part if not changed.
1.346 banghart 2905: &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
1.153 albertel 2906: next;
1.251 banghart 2907: } else {
1.524 raeburn 2908: push(@parts_graded,$new_part);
1.153 albertel 2909: }
1.259 banghart 2910: if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
2911: $newrecord{'resource.'.$new_part.'.awarded'} = $partial;
1.153 albertel 2912: }
1.259 banghart 2913: my $reckey = 'resource.'.$new_part.'.solved';
1.41 ng 2914: if ($partial == 0) {
1.153 albertel 2915: if ($record{$reckey} ne 'incorrect_by_override') {
2916: $newrecord{$reckey} = 'incorrect_by_override';
2917: }
1.41 ng 2918: } else {
1.153 albertel 2919: if ($record{$reckey} ne 'correct_by_override') {
2920: $newrecord{$reckey} = 'correct_by_override';
2921: }
2922: }
2923: if ($submitter &&
1.259 banghart 2924: ($record{'resource.'.$new_part.'.submitted_by'} ne $submitter)) {
2925: $newrecord{'resource.'.$new_part.'.submitted_by'} = $submitter;
1.41 ng 2926: }
1.259 banghart 2927: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2928: "$env{'user.name'}:$env{'user.domain'}";
1.41 ng 2929: }
1.259 banghart 2930: # unless problem has been graded, set flag to version the submitted files
1.305 banghart 2931: unless ($record{'resource.'.$new_part.'.solved'} =~ /^correct_/ ||
2932: $record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override' ||
2933: $dropMenu eq 'reset status')
2934: {
1.524 raeburn 2935: push(@version_parts,$new_part);
1.259 banghart 2936: }
1.41 ng 2937: }
1.301 albertel 2938: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2939: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2940:
1.344 albertel 2941: if (%newrecord) {
2942: if (@version_parts) {
1.364 banghart 2943: my @changed_keys = &version_portfiles(\%record, \@parts_graded,
2944: $env{'request.course.id'}, $symb, $domain, $stuname, \@version_parts);
1.344 albertel 2945: @newrecord{@changed_keys} = @record{@changed_keys};
1.367 albertel 2946: foreach my $new_part (@version_parts) {
2947: &handback_files($request,$symb,$stuname,$domain,$newflg,
2948: $new_part,\%newrecord);
2949: }
1.259 banghart 2950: }
1.44 ng 2951: &Apache::lonnet::cstore(\%newrecord,$symb,
1.257 albertel 2952: $env{'request.course.id'},$domain,$stuname);
1.380 albertel 2953: &check_and_remove_from_queue(\@parts,\%record,\%newrecord,$symb,
2954: $cdom,$cnum,$domain,$stuname);
1.41 ng 2955: }
1.269 raeburn 2956: if ($aggregateflag) {
2957: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 2958: $cdom,$cnum);
1.269 raeburn 2959: }
1.301 albertel 2960: return ('',$pts,$wgt);
1.36 ng 2961: }
1.322 albertel 2962:
1.380 albertel 2963: sub check_and_remove_from_queue {
2964: my ($parts,$record,$newrecord,$symb,$cdom,$cnum,$domain,$stuname) = @_;
2965: my @ungraded_parts;
2966: foreach my $part (@{$parts}) {
2967: if ( $record->{ 'resource.'.$part.'.awarded'} eq ''
2968: && $record->{ 'resource.'.$part.'.solved' } ne 'excused'
2969: && $newrecord->{'resource.'.$part.'.awarded'} eq ''
2970: && $newrecord->{'resource.'.$part.'.solved' } ne 'excused'
2971: ) {
2972: push(@ungraded_parts, $part);
2973: }
2974: }
2975: if ( !@ungraded_parts ) {
2976: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,
2977: $cnum,$domain,$stuname);
2978: }
2979: }
2980:
1.337 banghart 2981: sub handback_files {
2982: my ($request,$symb,$stuname,$domain,$newflg,$new_part,$newrecord) = @_;
1.517 raeburn 2983: my $portfolio_root = '/userfiles/portfolio';
1.582 raeburn 2984: my $res_error;
2985: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
2986: if ($res_error) {
2987: $request->print('<br />'.&navmap_errormsg().'<br />');
2988: return;
2989: }
1.596.2.4 raeburn 2990: my @handedback;
2991: my $file_msg;
1.375 albertel 2992: my @part_response_id = &flatten_responseType($responseType);
2993: foreach my $part_response_id (@part_response_id) {
2994: my ($part_id,$resp_id) = @{ $part_response_id };
2995: my $part_resp = join('_',@{ $part_response_id });
1.596.2.4 raeburn 2996: if (($env{'form.'.$newflg.'_'.$part_resp.'_countreturndoc'} =~ /^\d+$/) & ($new_part eq $part_id)) {
2997: for (my $counter=1; $counter<=$env{'form.'.$newflg.'_'.$part_resp.'_countreturndoc'}; $counter++) {
1.337 banghart 2998: # if multiple files are uploaded names will be 'returndoc2','returndoc3'
1.596.2.4 raeburn 2999: if ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$counter}) {
3000: my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$counter.'.filename'};
1.338 banghart 3001: my ($directory,$answer_file) =
1.596.2.4 raeburn 3002: ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$counter} =~ /^(.*?)([^\/]*)$/);
1.338 banghart 3003: my ($answer_name,$answer_ver,$answer_ext) =
3004: &file_name_version_ext($answer_file);
1.355 banghart 3005: my ($portfolio_path) = ($directory =~ /^.+$stuname\/portfolio(.*)/);
1.517 raeburn 3006: my $getpropath = 1;
1.596.2.12.2. (raeburn 3007:): my ($dir_list,$listerror) =
3008:): &Apache::lonnet::dirlist($portfolio_root.$portfolio_path,
3009:): $domain,$stuname,$getpropath);
3010:): my $version = &get_next_version($answer_name,$answer_ext,$dir_list);
1.355 banghart 3011: # fix file name
3012: my ($save_file_name) = (($directory.$answer_name.".$version.".$answer_ext) =~ /^.+\/${stuname}\/(.*)/);
3013: my $result=&Apache::lonnet::finishuserfileupload($stuname,$domain,
1.596.2.4 raeburn 3014: $newflg.'_'.$part_resp.'_returndoc'.$counter,
1.355 banghart 3015: $save_file_name);
1.337 banghart 3016: if ($result !~ m|^/uploaded/|) {
1.536 raeburn 3017: $request->print('<br /><span class="LC_error">'.
3018: &mt('An error occurred ([_1]) while trying to upload [_2].',
1.596.2.4 raeburn 3019: $result,$newflg.'_'.$part_resp.'_returndoc'.$counter).
1.536 raeburn 3020: '</span>');
1.356 banghart 3021: } else {
1.360 banghart 3022: # mark the file as read only
1.596.2.4 raeburn 3023: push(@handedback,$save_file_name);
1.367 albertel 3024: if (exists($$newrecord{"resource.$new_part.$resp_id.handback"})) {
3025: $$newrecord{"resource.$new_part.$resp_id.handback"}.=',';
3026: }
3027: $$newrecord{"resource.$new_part.$resp_id.handback"} .= $save_file_name;
1.596.2.4 raeburn 3028: $file_msg.='<span class="LC_filename"><a href="/uploaded/'."$domain/$stuname/".$save_file_name.'">'.$save_file_name."</a></span> <br />";
1.367 albertel 3029:
1.337 banghart 3030: }
1.596.2.4 raeburn 3031: $request->print('<br />'.&mt('[_1] will be the uploaded file name [_2]','<span class="LC_info">'.$fname.'</span>','<span class="LC_filename">'.$env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$counter}.'</span>'));
1.337 banghart 3032: }
3033: }
3034: }
1.596.2.4 raeburn 3035: }
3036: if (@handedback > 0) {
3037: $request->print('<br />');
3038: my @what = ($symb,$env{'request.course.id'},'handback');
3039: &Apache::lonnet::mark_as_readonly($domain,$stuname,\@handedback,\@what);
3040: my $user_lh = &Apache::loncommon::user_lang($stuname,$domain,$env{'request.course.id'});
3041: my ($subject,$message);
3042: if (scalar(@handedback) == 1) {
3043: $subject = &mt_user($user_lh,'File Handed Back by Instructor');
3044: } else {
3045: $subject = &mt_user($user_lh,'Files Handed Back by Instructor');
3046: $message = &mt_user($user_lh,'Files have been returned that were originally submitted in response to: ');
3047: }
3048: $message .= "<p><strong>".&Apache::lonnet::gettitle($symb)." </strong></p>";
3049: $message .= &mt_user($user_lh,'The returned file(s) are named: [_1]',"<br />$file_msg <br />").
3050: &mt_user($user_lh,'The file(s) can be found in your [_1]portfolio[_2].','<a href="/adm/portfolio">','</a>');
3051: my ($feedurl,$showsymb) =
3052: &get_feedurl_and_symb($symb,$domain,$stuname);
3053: my $restitle = &Apache::lonnet::gettitle($symb);
3054: $subject .= ' '.&mt_user($user_lh,'(File Returned)').' ['.$restitle.']';
3055: my $msgstatus =
3056: &Apache::lonmsg::user_normal_msg($stuname,$domain,$subject,
3057: $message,undef,$feedurl,undef,undef,undef,$showsymb,
3058: $restitle);
3059: if ($msgstatus) {
3060: $request->print(&mt('Notification message status: [_1]','<span class="LC_info">'.$msgstatus.'</span>').'<br />');
3061: }
3062: }
1.338 banghart 3063: return;
1.337 banghart 3064: }
3065:
1.418 albertel 3066: sub get_feedurl_and_symb {
3067: my ($symb,$uname,$udom) = @_;
3068: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
3069: $url = &Apache::lonnet::clutter($url);
3070: my $encrypturl=&Apache::lonnet::EXT('resource.0.encrypturl',
3071: $symb,$udom,$uname);
3072: if ($encrypturl =~ /^yes$/i) {
3073: &Apache::lonenc::encrypted(\$url,1);
3074: &Apache::lonenc::encrypted(\$symb,1);
3075: }
3076: return ($url,$symb);
3077: }
3078:
1.313 banghart 3079: sub get_submitted_files {
3080: my ($udom,$uname,$partid,$respid,$record) = @_;
3081: my @files;
3082: if ($$record{"resource.$partid.$respid.portfiles"}) {
3083: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
3084: foreach my $file (split(',',$$record{"resource.$partid.$respid.portfiles"})) {
3085: push(@files,$file_url.$file);
3086: }
3087: }
3088: if ($$record{"resource.$partid.$respid.uploadedurl"}) {
3089: push(@files,$$record{"resource.$partid.$respid.uploadedurl"});
3090: }
3091: return (\@files);
3092: }
1.322 albertel 3093:
1.269 raeburn 3094: # ----------- Provides number of tries since last reset.
3095: sub get_num_tries {
3096: my ($record,$last_reset,$part) = @_;
3097: my $timestamp = '';
3098: my $num_tries = 0;
3099: if ($$record{'version'}) {
3100: for (my $version=$$record{'version'};$version>=1;$version--) {
3101: if (exists($$record{$version.':resource.'.$part.'.solved'})) {
3102: $timestamp = $$record{$version.':timestamp'};
3103: if ($timestamp > $last_reset) {
3104: $num_tries ++;
3105: } else {
3106: last;
3107: }
3108: }
3109: }
3110: }
3111: return $num_tries;
3112: }
3113:
3114: # ----------- Determine decrements required in aggregate totals
3115: sub decrement_aggs {
3116: my ($symb,$part,$aggregate,$aggtries,$totaltries,$solvedstatus) = @_;
3117: my %decrement = (
3118: attempts => 0,
3119: users => 0,
3120: correct => 0
3121: );
3122: $decrement{'attempts'} = $aggtries;
3123: if ($solvedstatus =~ /^correct/) {
3124: $decrement{'correct'} = 1;
3125: }
3126: if ($aggtries == $totaltries) {
3127: $decrement{'users'} = 1;
3128: }
1.524 raeburn 3129: foreach my $type (keys(%decrement)) {
1.269 raeburn 3130: $$aggregate{$symb."\0".$part."\0".$type} = -$decrement{$type};
3131: }
3132: return;
3133: }
3134:
3135: # ----------- Determine timestamps for last reset of aggregate totals for parts
3136: sub get_last_resets {
1.270 albertel 3137: my ($symb,$courseid,$partids) =@_;
3138: my %last_resets;
1.269 raeburn 3139: my $cdom = $env{'course.'.$courseid.'.domain'};
3140: my $cname = $env{'course.'.$courseid.'.num'};
1.271 albertel 3141: my @keys;
3142: foreach my $part (@{$partids}) {
3143: push(@keys,"$symb\0$part\0resettime");
3144: }
3145: my %results=&Apache::lonnet::get('nohist_resourcetracker',\@keys,
3146: $cdom,$cname);
3147: foreach my $part (@{$partids}) {
3148: $last_resets{$part}=$results{"$symb\0$part\0resettime"};
1.269 raeburn 3149: }
1.270 albertel 3150: return %last_resets;
1.269 raeburn 3151: }
3152:
1.251 banghart 3153: # ----------- Handles creating versions for portfolio files as answers
3154: sub version_portfiles {
1.343 banghart 3155: my ($record, $parts_graded, $courseid, $symb, $domain, $stu_name, $v_flag) = @_;
1.263 banghart 3156: my $version_parts = join('|',@$v_flag);
1.343 banghart 3157: my @returned_keys;
1.255 banghart 3158: my $parts = join('|', @$parts_graded);
1.517 raeburn 3159: my $portfolio_root = '/userfiles/portfolio';
1.277 albertel 3160: foreach my $key (keys(%$record)) {
1.259 banghart 3161: my $new_portfiles;
1.263 banghart 3162: if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
1.342 banghart 3163: my @versioned_portfiles;
1.367 albertel 3164: my @portfiles = split(/\s*,\s*/,$$record{$key});
1.252 banghart 3165: foreach my $file (@portfiles) {
1.306 banghart 3166: &Apache::lonnet::unmark_as_readonly($domain,$stu_name,[$symb,$env{'request.course.id'}],$file);
1.304 albertel 3167: my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*)$/);
3168: my ($answer_name,$answer_ver,$answer_ext) =
3169: &file_name_version_ext($answer_file);
1.596.2.12.2. (raeburn 3170:): my $getpropath = 1;
3171:): my ($dir_list,$listerror) =
3172:): &Apache::lonnet::dirlist($portfolio_root.$directory,$domain,
3173:): $stu_name,$getpropath);
3174:): my $version = &get_next_version($answer_name,$answer_ext,$dir_list);
1.306 banghart 3175: my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version);
3176: if ($new_answer ne 'problem getting file') {
1.342 banghart 3177: push(@versioned_portfiles, $directory.$new_answer);
1.306 banghart 3178: &Apache::lonnet::mark_as_readonly($domain,$stu_name,
1.367 albertel 3179: [$directory.$new_answer],
1.306 banghart 3180: [$symb,$env{'request.course.id'},'graded']);
1.259 banghart 3181: }
1.252 banghart 3182: }
1.343 banghart 3183: $$record{$key} = join(',',@versioned_portfiles);
3184: push(@returned_keys,$key);
1.251 banghart 3185: }
3186: }
1.343 banghart 3187: return (@returned_keys);
1.305 banghart 3188: }
3189:
1.307 banghart 3190: sub get_next_version {
1.341 banghart 3191: my ($answer_name, $answer_ext, $dir_list) = @_;
1.307 banghart 3192: my $version;
1.596.2.12.2. (raeburn 3193:): if (ref($dir_list) eq 'ARRAY') {
3194:): foreach my $row (@{$dir_list}) {
3195:): my ($file) = split(/\&/,$row,2);
3196:): my ($file_name,$file_version,$file_ext) =
3197:): &file_name_version_ext($file);
3198:): if (($file_name eq $answer_name) &&
3199:): ($file_ext eq $answer_ext)) {
3200:): # gets here if filename and extension match,
3201:): # regardless of version
1.307 banghart 3202: if ($file_version ne '') {
1.596.2.12.2. (raeburn 3203:): # a versioned file is found so save it for later
3204:): if ($file_version > $version) {
3205:): $version = $file_version;
3206:): }
1.307 banghart 3207: }
3208: }
3209: }
1.596.2.12.2. (raeburn 3210:): }
1.307 banghart 3211: $version ++;
3212: return($version);
3213: }
3214:
1.305 banghart 3215: sub version_selected_portfile {
1.306 banghart 3216: my ($domain,$stu_name,$directory,$file_name,$version) = @_;
3217: my ($answer_name,$answer_ver,$answer_ext) =
3218: &file_name_version_ext($file_name);
3219: my $new_answer;
3220: $env{'form.copy'} = &Apache::lonnet::getfile("/uploaded/$domain/$stu_name/portfolio$directory$file_name");
3221: if($env{'form.copy'} eq '-1') {
3222: $new_answer = 'problem getting file';
3223: } else {
3224: $new_answer = $answer_name.'.'.$version.'.'.$answer_ext;
3225: my $copy_result = &Apache::lonnet::finishuserfileupload(
3226: $stu_name,$domain,'copy',
3227: '/portfolio'.$directory.$new_answer);
3228: }
3229: return ($new_answer);
1.251 banghart 3230: }
3231:
1.304 albertel 3232: sub file_name_version_ext {
3233: my ($file)=@_;
3234: my @file_parts = split(/\./, $file);
3235: my ($name,$version,$ext);
3236: if (@file_parts > 1) {
3237: $ext=pop(@file_parts);
3238: if (@file_parts > 1 && $file_parts[-1] =~ /^\d+$/) {
3239: $version=pop(@file_parts);
3240: }
3241: $name=join('.',@file_parts);
3242: } else {
3243: $name=join('.',@file_parts);
3244: }
3245: return($name,$version,$ext);
3246: }
3247:
1.44 ng 3248: #--------------------------------------------------------------------------------------
3249: #
3250: #-------------------------- Next few routines handles grading by section or whole class
3251: #
3252: #--- Javascript to handle grading by section or whole class
1.42 ng 3253: sub viewgrades_js {
3254: my ($request) = shift;
3255:
1.539 riegler 3256: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
1.41 ng 3257: $request->print(<<VIEWJAVASCRIPT);
3258: <script type="text/javascript" language="javascript">
1.45 ng 3259: function writePoint(partid,weight,point) {
1.125 ng 3260: var radioButton = document.classgrade["RADVAL_"+partid];
3261: var textbox = document.classgrade["TEXTVAL_"+partid];
1.42 ng 3262: if (point == "textval") {
1.125 ng 3263: point = document.classgrade["TEXTVAL_"+partid].value;
1.109 matthew 3264: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 3265: alert("$alertmsg"+parseFloat(point));
1.42 ng 3266: var resetbox = false;
3267: for (var i=0; i<radioButton.length; i++) {
3268: if (radioButton[i].checked) {
3269: textbox.value = i;
3270: resetbox = true;
3271: }
3272: }
3273: if (!resetbox) {
3274: textbox.value = "";
3275: }
3276: return;
3277: }
1.109 matthew 3278: if (parseFloat(point) > parseFloat(weight)) {
3279: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 3280: ") greater than the weight for the part. Accept?");
3281: if (resp == false) {
3282: textbox.value = "";
3283: return;
3284: }
3285: }
1.42 ng 3286: for (var i=0; i<radioButton.length; i++) {
3287: radioButton[i].checked=false;
1.109 matthew 3288: if (parseFloat(point) == i) {
1.42 ng 3289: radioButton[i].checked=true;
3290: }
3291: }
1.41 ng 3292:
1.42 ng 3293: } else {
1.125 ng 3294: textbox.value = parseFloat(point);
1.42 ng 3295: }
1.41 ng 3296: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3297: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3298: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3299: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3300: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3301: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 3302: if (saveval != "correct") {
3303: scorename.value = point;
1.43 ng 3304: if (selname[0].selected != true) {
3305: selname[0].selected = true;
3306: }
1.42 ng 3307: }
3308: }
1.125 ng 3309: document.classgrade["SELVAL_"+partid][0].selected = true;
1.42 ng 3310: }
3311:
3312: function writeRadText(partid,weight) {
1.125 ng 3313: var selval = document.classgrade["SELVAL_"+partid];
3314: var radioButton = document.classgrade["RADVAL_"+partid];
1.265 www 3315: var override = document.classgrade["FORCE_"+partid].checked;
1.125 ng 3316: var textbox = document.classgrade["TEXTVAL_"+partid];
3317: if (selval[1].selected || selval[2].selected) {
1.42 ng 3318: for (var i=0; i<radioButton.length; i++) {
3319: radioButton[i].checked=false;
3320:
3321: }
3322: textbox.value = "";
3323:
3324: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3325: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3326: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3327: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3328: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3329: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 3330: if ((saveval != "correct") || override) {
1.42 ng 3331: scorename.value = "";
1.125 ng 3332: if (selval[1].selected) {
3333: selname[1].selected = true;
3334: } else {
3335: selname[2].selected = true;
3336: if (Number(document.classgrade["GD_"+user+"_"+partid+"_tries"].value))
3337: {document.classgrade["GD_"+user+"_"+partid+"_tries"].value = '0';}
3338: }
1.42 ng 3339: }
3340: }
1.43 ng 3341: } else {
3342: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3343: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3344: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3345: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3346: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3347: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 3348: if ((saveval != "correct") || override) {
1.125 ng 3349: scorename.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
1.43 ng 3350: selname[0].selected = true;
3351: }
3352: }
3353: }
1.42 ng 3354: }
3355:
3356: function changeSelect(partid,user) {
1.125 ng 3357: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
3358: var textbox = document.classgrade["GD_"+user+'_'+partid+"_awarded"];
1.44 ng 3359: var point = textbox.value;
1.125 ng 3360: var weight = document.classgrade["weight_"+partid].value;
1.44 ng 3361:
1.109 matthew 3362: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 3363: alert("$alertmsg"+parseFloat(point));
1.44 ng 3364: textbox.value = "";
3365: return;
3366: }
1.109 matthew 3367: if (parseFloat(point) > parseFloat(weight)) {
3368: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 3369: ") greater than the weight of the part. Accept?");
3370: if (resp == false) {
3371: textbox.value = "";
3372: return;
3373: }
3374: }
1.42 ng 3375: selval[0].selected = true;
3376: }
3377:
3378: function changeOneScore(partid,user) {
1.125 ng 3379: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
3380: if (selval[1].selected || selval[2].selected) {
3381: document.classgrade["GD_"+user+'_'+partid+"_awarded"].value = "";
3382: if (selval[2].selected) {
3383: document.classgrade["GD_"+user+'_'+partid+"_tries"].value = "0";
3384: }
1.269 raeburn 3385: }
1.42 ng 3386: }
3387:
3388: function resetEntry(numpart) {
3389: for (ctpart=0;ctpart<numpart;ctpart++) {
1.125 ng 3390: var partid = document.classgrade["partid_"+ctpart].value;
3391: var radioButton = document.classgrade["RADVAL_"+partid];
3392: var textbox = document.classgrade["TEXTVAL_"+partid];
3393: var selval = document.classgrade["SELVAL_"+partid];
1.42 ng 3394: for (var i=0; i<radioButton.length; i++) {
3395: radioButton[i].checked=false;
3396:
3397: }
3398: textbox.value = "";
3399: selval[0].selected = true;
3400:
3401: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3402: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3403: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3404: var resetscore = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3405: resetscore.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
3406: var resettries = document.classgrade["GD_"+user+"_"+partid+"_tries"];
3407: resettries.value = document.classgrade["GD_"+user+"_"+partid+"_tries_s"].value;
3408: var saveselval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3409: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 3410: if (saveselval == "excused") {
1.43 ng 3411: if (selname[1].selected == false) { selname[1].selected = true;}
1.42 ng 3412: } else {
1.43 ng 3413: if (selname[0].selected == false) {selname[0].selected = true};
1.42 ng 3414: }
3415: }
1.41 ng 3416: }
1.42 ng 3417: }
3418:
1.41 ng 3419: </script>
3420: VIEWJAVASCRIPT
1.42 ng 3421: }
3422:
1.44 ng 3423: #--- show scores for a section or whole class w/ option to change/update a score
1.42 ng 3424: sub viewgrades {
3425: my ($request) = shift;
3426: &viewgrades_js($request);
1.41 ng 3427:
1.324 albertel 3428: my ($symb) = &get_symb($request);
1.168 albertel 3429: #need to make sure we have the correct data for later EXT calls,
3430: #thus invalidate the cache
3431: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 3432: $env{'course.'.$env{'request.course.id'}.'.num'},
3433: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 3434: &Apache::lonnet::clear_EXT_cache_status();
3435:
1.398 albertel 3436: my $result='<h3><span class="LC_info">'.&mt('Manual Grading').'</span></h3>';
1.485 albertel 3437: $result.='<h4>'.&mt('<b>Current Resource: </b>[_1]',$env{'form.probTitle'}).'</h4>'."\n";
1.41 ng 3438:
3439: #view individual student submission form - called using Javascript viewOneStudent
1.324 albertel 3440: $result.=&jscriptNform($symb);
1.41 ng 3441:
1.44 ng 3442: #beginning of class grading form
1.442 banghart 3443: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.41 ng 3444: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1.418 albertel 3445: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.38 ng 3446: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.432 banghart 3447: &build_section_inputs().
1.257 albertel 3448: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.442 banghart 3449: '<input type="hidden" name="Status" value="'.$env{'stu_status'}.'" />'."\n".
1.257 albertel 3450: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.72 ng 3451:
1.560 raeburn 3452: my ($common_header,$specific_header);
1.257 albertel 3453: if ($env{'form.section'} eq 'all') {
1.560 raeburn 3454: $common_header = &mt('Assign Common Grade to Class');
3455: $specific_header = &mt('Assign Grade to Specific Students in Class');
1.257 albertel 3456: } elsif ($env{'form.section'} eq 'none') {
1.560 raeburn 3457: $common_header = &mt('Assign Common Grade to Students in no Section');
3458: $specific_header = &mt('Assign Grade to Specific Students in no Section');
1.52 albertel 3459: } else {
1.560 raeburn 3460: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
3461: $common_header = &mt('Assign Common Grade to Students in Section(s) [_1]',$section_display);
3462: $specific_header = &mt('Assign Grade to Specific Students in Section(s) [_1]',$section_display);
1.52 albertel 3463: }
1.560 raeburn 3464: $result.= '<h3>'.$common_header.'</h3>'.&Apache::loncommon::start_data_table();
1.44 ng 3465: #radio buttons/text box for assigning points for a section or class.
3466: #handles different parts of a problem
1.582 raeburn 3467: my $res_error;
3468: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
3469: if ($res_error) {
3470: return &navmap_errormsg();
3471: }
1.42 ng 3472: my %weight = ();
3473: my $ctsparts = 0;
1.45 ng 3474: my %seen = ();
1.375 albertel 3475: my @part_response_id = &flatten_responseType($responseType);
3476: foreach my $part_response_id (@part_response_id) {
3477: my ($partid,$respid) = @{ $part_response_id };
3478: my $part_resp = join('_',@{ $part_response_id });
1.45 ng 3479: next if $seen{$partid};
3480: $seen{$partid}++;
1.375 albertel 3481: my $handgrade=$$handgrade{$part_resp};
1.42 ng 3482: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
3483: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
3484:
1.324 albertel 3485: my $display_part=&get_display_part($partid,$symb);
1.485 albertel 3486: my $radio.='<table border="0"><tr>';
1.41 ng 3487: my $ctr = 0;
1.42 ng 3488: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
1.485 albertel 3489: $radio.= '<td><label><input type="radio" name="RADVAL_'.$partid.'" '.
1.54 albertel 3490: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.288 albertel 3491: ','.$ctr.')" />'.$ctr."</label></td>\n";
1.41 ng 3492: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
3493: $ctr++;
3494: }
1.485 albertel 3495: $radio.='</tr></table>';
3496: my $line = '<input type="text" name="TEXTVAL_'.
1.589 bisitz 3497: $partid.'" size="4" '.'onchange="javascript:writePoint(\''.
1.54 albertel 3498: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.539 riegler 3499: $weight{$partid}.' '.&mt('(problem weight)').'</td>'."\n";
3500: $line.= '<td><b>'.&mt('Grade Status').':</b><select name="SELVAL_'.$partid.'"'.
1.589 bisitz 3501: 'onchange="javascript:writeRadText(\''.$partid.'\','.
1.59 albertel 3502: $weight{$partid}.')"> '.
1.401 albertel 3503: '<option selected="selected"> </option>'.
1.485 albertel 3504: '<option value="excused">'.&mt('excused').'</option>'.
3505: '<option value="reset status">'.&mt('reset status').'</option>'.
3506: '</select></td>'.
3507: '<td><label><input type="checkbox" name="FORCE_'.$partid.'" />'.&mt('Override "Correct"').'</label>';
3508: $line.='<input type="hidden" name="partid_'.
3509: $ctsparts.'" value="'.$partid.'" />'."\n";
3510: $line.='<input type="hidden" name="weight_'.
3511: $partid.'" value="'.$weight{$partid}.'" />'."\n";
3512:
3513: $result.=
3514: &Apache::loncommon::start_data_table_row()."\n".
1.577 bisitz 3515: '<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 3516: &Apache::loncommon::end_data_table_row()."\n";
1.42 ng 3517: $ctsparts++;
1.41 ng 3518: }
1.474 albertel 3519: $result.=&Apache::loncommon::end_data_table()."\n".
1.52 albertel 3520: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.485 albertel 3521: $result.='<input type="button" value="'.&mt('Revert to Default').'" '.
1.589 bisitz 3522: 'onclick="javascript:resetEntry('.$ctsparts.');" />';
1.41 ng 3523:
1.44 ng 3524: #table listing all the students in a section/class
3525: #header of table
1.560 raeburn 3526: $result.= '<h3>'.$specific_header.'</h3>'.
3527: &Apache::loncommon::start_data_table().
3528: &Apache::loncommon::start_data_table_header_row().
3529: '<th>'.&mt('No.').'</th>'.
3530: '<th>'.&nameUserString('header')."</th>\n";
1.582 raeburn 3531: my $partserror;
3532: my (@parts) = sort(&getpartlist($symb,\$partserror));
3533: if ($partserror) {
3534: return &navmap_errormsg();
3535: }
1.324 albertel 3536: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.269 raeburn 3537: my @partids = ();
1.41 ng 3538: foreach my $part (@parts) {
3539: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1.539 riegler 3540: my $narrowtext = &mt('Tries');
3541: $display =~ s|^Number of Attempts|$narrowtext <br />|; # makes the column narrower
1.41 ng 3542: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
1.207 albertel 3543: my ($partid) = &split_part_type($part);
1.524 raeburn 3544: push(@partids,$partid);
1.324 albertel 3545: my $display_part=&get_display_part($partid,$symb);
1.41 ng 3546: if ($display =~ /^Partial Credit Factor/) {
1.485 albertel 3547: $result.='<th>'.
3548: &mt('Score Part: [_1]<br /> (weight = [_2])',
3549: $display_part,$weight{$partid}).'</th>'."\n";
1.41 ng 3550: next;
1.485 albertel 3551:
1.207 albertel 3552: } else {
1.485 albertel 3553: if ($display =~ /Problem Status/) {
3554: my $grade_status_mt = &mt('Grade Status');
3555: $display =~ s{Problem Status}{$grade_status_mt<br />};
3556: }
3557: my $part_mt = &mt('Part:');
3558: $display =~s{\[Part: \Q$partid\E\]}{$part_mt $display_part};
1.41 ng 3559: }
1.485 albertel 3560:
1.474 albertel 3561: $result.='<th>'.$display.'</th>'."\n";
1.41 ng 3562: }
1.474 albertel 3563: $result.=&Apache::loncommon::end_data_table_header_row();
1.44 ng 3564:
1.270 albertel 3565: my %last_resets =
3566: &get_last_resets($symb,$env{'request.course.id'},\@partids);
1.269 raeburn 3567:
1.41 ng 3568: #get info for each student
1.44 ng 3569: #list all the students - with points and grade status
1.257 albertel 3570: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
1.41 ng 3571: my $ctr = 0;
1.294 albertel 3572: foreach (sort
3573: {
3574: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
3575: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
3576: }
3577: return $a cmp $b;
3578: } (keys(%$fullname))) {
1.126 ng 3579: $ctr++;
1.324 albertel 3580: $result.=&viewstudentgrade($symb,$env{'request.course.id'},
1.269 raeburn 3581: $_,$$fullname{$_},\@parts,\%weight,$ctr,\%last_resets);
1.41 ng 3582: }
1.474 albertel 3583: $result.=&Apache::loncommon::end_data_table();
1.41 ng 3584: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.485 albertel 3585: $result.='<input type="button" value="'.&mt('Save').'" '.
1.589 bisitz 3586: 'onclick="javascript:submit();" target="_self" /></form>'."\n";
1.96 albertel 3587: if (scalar(%$fullname) eq 0) {
3588: my $colspan=3+scalar(@parts);
1.433 banghart 3589: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.442 banghart 3590: my $stu_status = join(' or ',&Apache::loncommon::get_env_multiple('form.Status'));
1.433 banghart 3591: $result='<span class="LC_warning">'.
1.485 albertel 3592: &mt('There are no students in section(s) [_1] with enrollment status [_2] to modify or grade.',
1.442 banghart 3593: $section_display, $stu_status).
1.433 banghart 3594: '</span>';
1.96 albertel 3595: }
1.324 albertel 3596: $result.=&show_grading_menu_form($symb);
1.41 ng 3597: return $result;
3598: }
3599:
1.44 ng 3600: #--- call by previous routine to display each student
1.41 ng 3601: sub viewstudentgrade {
1.324 albertel 3602: my ($symb,$courseid,$student,$fullname,$parts,$weight,$ctr,$last_resets) = @_;
1.44 ng 3603: my ($uname,$udom) = split(/:/,$student);
3604: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.269 raeburn 3605: my %aggregates = ();
1.474 albertel 3606: my $result=&Apache::loncommon::start_data_table_row().'<td align="right">'.
1.233 albertel 3607: '<input type="hidden" name="ctr'.($ctr-1).'" value="'.$student.'" />'.
3608: "\n".$ctr.' </td><td> '.
1.44 ng 3609: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 3610: '\');" target="_self">'.$fullname.'</a> '.
1.398 albertel 3611: '<span class="LC_internal_info">('.$uname.($env{'user.domain'} eq $udom ? '' : ':'.$udom).')</span></td>'."\n";
1.281 albertel 3612: $student=~s/:/_/; # colon doen't work in javascript for names
1.63 albertel 3613: foreach my $apart (@$parts) {
3614: my ($part,$type) = &split_part_type($apart);
1.41 ng 3615: my $score=$record{"resource.$part.$type"};
1.276 albertel 3616: $result.='<td align="center">';
1.269 raeburn 3617: my ($aggtries,$totaltries);
3618: unless (exists($aggregates{$part})) {
1.270 albertel 3619: $totaltries = $record{'resource.'.$part.'.tries'};
3620:
3621: $aggtries = $totaltries;
1.269 raeburn 3622: if ($$last_resets{$part}) {
1.270 albertel 3623: $aggtries = &get_num_tries(\%record,$$last_resets{$part},
3624: $part);
3625: }
1.269 raeburn 3626: $result.='<input type="hidden" name="'.
3627: 'GD_'.$student.'_'.$part.'_aggtries" value="'.$aggtries.'" />'."\n";
3628: $result.='<input type="hidden" name="'.
3629: 'GD_'.$student.'_'.$part.'_totaltries" value="'.$totaltries.'" />'."\n";
3630: $aggregates{$part} = 1;
3631: }
1.41 ng 3632: if ($type eq 'awarded') {
1.320 albertel 3633: my $pts = $score eq '' ? '' : &compute_points($score,$$weight{$part});
1.42 ng 3634: $result.='<input type="hidden" name="'.
1.89 albertel 3635: 'GD_'.$student.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.233 albertel 3636: $result.='<input type="text" name="'.
1.89 albertel 3637: 'GD_'.$student.'_'.$part.'_awarded" '.
1.589 bisitz 3638: 'onchange="javascript:changeSelect(\''.$part.'\',\''.$student.
1.44 ng 3639: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41 ng 3640: } elsif ($type eq 'solved') {
3641: my ($status,$foo)=split(/_/,$score,2);
3642: $status = 'nothing' if ($status eq '');
1.89 albertel 3643: $result.='<input type="hidden" name="'.'GD_'.$student.'_'.
1.54 albertel 3644: $part.'_solved_s" value="'.$status.'" />'."\n";
1.233 albertel 3645: $result.=' <select name="'.
1.89 albertel 3646: 'GD_'.$student.'_'.$part.'_solved" '.
1.589 bisitz 3647: 'onchange="javascript:changeOneScore(\''.$part.'\',\''.$student.'\')" >'."\n";
1.485 albertel 3648: $result.= (($status eq 'excused') ? '<option> </option><option selected="selected" value="excused">'.&mt('excused').'</option>'
3649: : '<option selected="selected"> </option><option value="excused">'.&mt('excused').'</option>')."\n";
3650: $result.='<option value="reset status">'.&mt('reset status').'</option>';
1.126 ng 3651: $result.="</select> </td>\n";
1.122 ng 3652: } else {
3653: $result.='<input type="hidden" name="'.
3654: 'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
3655: "\n";
1.233 albertel 3656: $result.='<input type="text" name="'.
1.122 ng 3657: 'GD_'.$student.'_'.$part.'_'.$type.'" '.
3658: 'value="'.$score.'" size="4" /></td>'."\n";
1.41 ng 3659: }
3660: }
1.474 albertel 3661: $result.=&Apache::loncommon::end_data_table_row();
1.41 ng 3662: return $result;
1.38 ng 3663: }
3664:
1.44 ng 3665: #--- change scores for all the students in a section/class
3666: # record does not get update if unchanged
1.38 ng 3667: sub editgrades {
1.41 ng 3668: my ($request) = @_;
3669:
1.324 albertel 3670: my $symb=&get_symb($request);
1.433 banghart 3671: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.477 albertel 3672: my $title='<h2>'.&mt('Current Grade Status').'</h2>';
3673: $title.='<h4>'.&mt('<b>Current Resource: </b>[_1]',$env{'form.probTitle'}).'</h4>'."\n";
1.433 banghart 3674: $title.='<h4>'.&mt('<b>Section: </b>[_1]',$section_display).'</h4>'."\n";
1.126 ng 3675:
1.477 albertel 3676: my $result= &Apache::loncommon::start_data_table().
3677: &Apache::loncommon::start_data_table_header_row().
3678: '<th rowspan="2" valign="middle">'.&mt('No.').'</th>'.
3679: '<th rowspan="2" valign="middle">'.&nameUserString('header')."</th>\n";
1.43 ng 3680: my %scoreptr = (
3681: 'correct' =>'correct_by_override',
3682: 'incorrect'=>'incorrect_by_override',
3683: 'excused' =>'excused',
3684: 'ungraded' =>'ungraded_attempted',
1.596 raeburn 3685: 'credited' =>'credit_attempted',
1.43 ng 3686: 'nothing' => '',
3687: );
1.257 albertel 3688: my ($classlist,undef,$fullname) = &getclasslist($env{'form.section'},'0');
1.34 ng 3689:
1.44 ng 3690: my (@partid);
3691: my %weight = ();
1.54 albertel 3692: my %columns = ();
1.44 ng 3693: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54 albertel 3694:
1.582 raeburn 3695: my $partserror;
3696: my (@parts) = sort(&getpartlist($symb,\$partserror));
3697: if ($partserror) {
3698: return &navmap_errormsg();
3699: }
1.54 albertel 3700: my $header;
1.257 albertel 3701: while ($ctr < $env{'form.totalparts'}) {
3702: my $partid = $env{'form.partid_'.$ctr};
1.524 raeburn 3703: push(@partid,$partid);
1.257 albertel 3704: $weight{$partid} = $env{'form.weight_'.$partid};
1.44 ng 3705: $ctr++;
1.54 albertel 3706: }
1.324 albertel 3707: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.54 albertel 3708: foreach my $partid (@partid) {
1.478 albertel 3709: $header .= '<th align="center">'.&mt('Old Score').'</th>'.
3710: '<th align="center">'.&mt('New Score').'</th>';
1.54 albertel 3711: $columns{$partid}=2;
3712: foreach my $stores (@parts) {
3713: my ($part,$type) = &split_part_type($stores);
3714: if ($part !~ m/^\Q$partid\E/) { next;}
3715: if ($type eq 'awarded' || $type eq 'solved') { next; }
3716: my $display=&Apache::lonnet::metadata($url,$stores.'.display');
1.551 raeburn 3717: $display =~ s/\[Part: \Q$part\E\]//;
1.539 riegler 3718: my $narrowtext = &mt('Tries');
3719: $display =~ s/Number of Attempts/$narrowtext/;
3720: $header .= '<th align="center">'.&mt('Old').' '.$display.'</th>'.
3721: '<th align="center">'.&mt('New').' '.$display.'</th>';
1.54 albertel 3722: $columns{$partid}+=2;
3723: }
3724: }
3725: foreach my $partid (@partid) {
1.324 albertel 3726: my $display_part=&get_display_part($partid,$symb);
1.478 albertel 3727: $result .= '<th colspan="'.$columns{$partid}.'" align="center">'.
3728: &mt('Part: [_1] (Weight = [_2])',$display_part,$weight{$partid}).
3729: '</th>';
1.54 albertel 3730:
1.44 ng 3731: }
1.477 albertel 3732: $result .= &Apache::loncommon::end_data_table_header_row().
3733: &Apache::loncommon::start_data_table_header_row().
3734: $header.
3735: &Apache::loncommon::end_data_table_header_row();
3736: my @noupdate;
1.126 ng 3737: my ($updateCtr,$noupdateCtr) = (1,1);
1.257 albertel 3738: for ($i=0; $i<$env{'form.total'}; $i++) {
1.93 albertel 3739: my $line;
1.257 albertel 3740: my $user = $env{'form.ctr'.$i};
1.281 albertel 3741: my ($uname,$udom)=split(/:/,$user);
1.44 ng 3742: my %newrecord;
3743: my $updateflag = 0;
1.281 albertel 3744: $line .= '<td>'.&nameUserString(undef,$$fullname{$user},$uname,$udom).'</td>';
1.108 albertel 3745: my $usec=$classlist->{"$uname:$udom"}[5];
1.105 albertel 3746: if (!&canmodify($usec)) {
1.126 ng 3747: my $numcols=scalar(@partid)*4+2;
1.477 albertel 3748: push(@noupdate,
1.478 albertel 3749: $line."<td colspan=\"$numcols\"><span class=\"LC_warning\">".
3750: &mt('Not allowed to modify student')."</span></td></tr>");
1.105 albertel 3751: next;
3752: }
1.269 raeburn 3753: my %aggregate = ();
3754: my $aggregateflag = 0;
1.281 albertel 3755: $user=~s/:/_/; # colon doen't work in javascript for names
1.44 ng 3756: foreach (@partid) {
1.257 albertel 3757: my $old_aw = $env{'form.GD_'.$user.'_'.$_.'_awarded_s'};
1.54 albertel 3758: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
3759: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
1.257 albertel 3760: my $old_score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
3761: my $awarded = $env{'form.GD_'.$user.'_'.$_.'_awarded'};
1.54 albertel 3762: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
3763: my $partial = $awarded eq '' ? '' : $pcr;
1.44 ng 3764: my $score;
3765: if ($partial eq '') {
1.257 albertel 3766: $score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 3767: } elsif ($partial > 0) {
3768: $score = 'correct_by_override';
3769: } elsif ($partial == 0) {
3770: $score = 'incorrect_by_override';
3771: }
1.257 albertel 3772: my $dropMenu = $env{'form.GD_'.$user.'_'.$_.'_solved'};
1.125 ng 3773: $score = 'excused' if (($dropMenu eq 'excused') && ($score ne 'excused'));
3774:
1.292 albertel 3775: $newrecord{'resource.'.$_.'.regrader'}=
3776: "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 3777: if ($dropMenu eq 'reset status' &&
3778: $old_score ne '') { # ignore if no previous attempts => nothing to reset
1.299 albertel 3779: $newrecord{'resource.'.$_.'.tries'} = '';
1.125 ng 3780: $newrecord{'resource.'.$_.'.solved'} = '';
3781: $newrecord{'resource.'.$_.'.award'} = '';
1.299 albertel 3782: $newrecord{'resource.'.$_.'.awarded'} = '';
1.125 ng 3783: $updateflag = 1;
1.269 raeburn 3784: if ($env{'form.GD_'.$user.'_'.$_.'_aggtries'} > 0) {
3785: my $aggtries = $env{'form.GD_'.$user.'_'.$_.'_aggtries'};
3786: my $totaltries = $env{'form.GD_'.$user.'_'.$_.'_totaltries'};
3787: my $solvedstatus = $env{'form.GD_'.$user.'_'.$_.'_solved_s'};
3788: &decrement_aggs($symb,$_,\%aggregate,$aggtries,$totaltries,$solvedstatus);
3789: $aggregateflag = 1;
3790: }
1.139 albertel 3791: } elsif (!($old_part eq $partial && $old_score eq $score)) {
3792: $updateflag = 1;
3793: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
3794: $newrecord{'resource.'.$_.'.solved'} = $score;
3795: $rec_update++;
1.125 ng 3796: }
3797:
1.93 albertel 3798: $line .= '<td align="center">'.$old_aw.' </td>'.
1.44 ng 3799: '<td align="center">'.$awarded.
3800: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 3801:
1.54 albertel 3802:
3803: my $partid=$_;
3804: foreach my $stores (@parts) {
3805: my ($part,$type) = &split_part_type($stores);
3806: if ($part !~ m/^\Q$partid\E/) { next;}
3807: if ($type eq 'awarded' || $type eq 'solved') { next; }
1.257 albertel 3808: my $old_aw = $env{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
3809: my $awarded = $env{'form.GD_'.$user.'_'.$part.'_'.$type};
1.54 albertel 3810: if ($awarded ne '' && $awarded ne $old_aw) {
3811: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.257 albertel 3812: $newrecord{'resource.'.$part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.54 albertel 3813: $updateflag=1;
3814: }
1.93 albertel 3815: $line .= '<td align="center">'.$old_aw.' </td>'.
1.54 albertel 3816: '<td align="center">'.$awarded.' </td>';
3817: }
1.44 ng 3818: }
1.477 albertel 3819: $line.="\n";
1.301 albertel 3820:
3821: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3822: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3823:
1.44 ng 3824: if ($updateflag) {
3825: $count++;
1.257 albertel 3826: &Apache::lonnet::cstore(\%newrecord,$symb,$env{'request.course.id'},
1.89 albertel 3827: $udom,$uname);
1.301 albertel 3828:
3829: if (&Apache::bridgetask::in_queue('gradingqueue',$symb,$cdom,
3830: $cnum,$udom,$uname)) {
3831: # need to figure out if should be in queue.
3832: my %record =
3833: &Apache::lonnet::restore($symb,$env{'request.course.id'},
3834: $udom,$uname);
3835: my $all_graded = 1;
3836: my $none_graded = 1;
3837: foreach my $part (@parts) {
3838: if ( $record{'resource.'.$part.'.awarded'} eq '' ) {
3839: $all_graded = 0;
3840: } else {
3841: $none_graded = 0;
3842: }
3843: }
3844:
3845: if ($all_graded || $none_graded) {
3846: &Apache::bridgetask::remove_from_queue('gradingqueue',
3847: $symb,$cdom,$cnum,
3848: $udom,$uname);
3849: }
3850: }
3851:
1.477 albertel 3852: $result.=&Apache::loncommon::start_data_table_row().
3853: '<td align="right"> '.$updateCtr.' </td>'.$line.
3854: &Apache::loncommon::end_data_table_row();
1.126 ng 3855: $updateCtr++;
1.93 albertel 3856: } else {
1.477 albertel 3857: push(@noupdate,
3858: '<td align="right"> '.$noupdateCtr.' </td>'.$line);
1.126 ng 3859: $noupdateCtr++;
1.44 ng 3860: }
1.269 raeburn 3861: if ($aggregateflag) {
3862: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 3863: $cdom,$cnum);
1.269 raeburn 3864: }
1.93 albertel 3865: }
1.477 albertel 3866: if (@noupdate) {
1.126 ng 3867: # my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3;
3868: my $numcols=scalar(@partid)*4+2;
1.477 albertel 3869: $result .= &Apache::loncommon::start_data_table_row('LC_empty_row').
1.478 albertel 3870: '<td align="center" colspan="'.$numcols.'">'.
3871: &mt('No Changes Occurred For the Students Below').
3872: '</td>'.
1.477 albertel 3873: &Apache::loncommon::end_data_table_row();
3874: foreach my $line (@noupdate) {
3875: $result.=
3876: &Apache::loncommon::start_data_table_row().
3877: $line.
3878: &Apache::loncommon::end_data_table_row();
3879: }
1.44 ng 3880: }
1.477 albertel 3881: $result .= &Apache::loncommon::end_data_table().
3882: &show_grading_menu_form($symb);
1.478 albertel 3883: my $msg = '<p><b>'.
3884: &mt('Number of records updated = [_1] for [quant,_2,student].',
3885: $rec_update,$count).'</b><br />'.
3886: '<b>'.&mt('Total number of students = [_1]',$env{'form.total'}).
3887: '</b></p>';
1.44 ng 3888: return $title.$msg.$result;
1.5 albertel 3889: }
1.54 albertel 3890:
3891: sub split_part_type {
3892: my ($partstr) = @_;
3893: my ($temp,@allparts)=split(/_/,$partstr);
3894: my $type=pop(@allparts);
1.439 albertel 3895: my $part=join('_',@allparts);
1.54 albertel 3896: return ($part,$type);
3897: }
3898:
1.44 ng 3899: #------------- end of section for handling grading by section/class ---------
3900: #
3901: #----------------------------------------------------------------------------
3902:
1.5 albertel 3903:
1.44 ng 3904: #----------------------------------------------------------------------------
3905: #
3906: #-------------------------- Next few routines handles grading by csv upload
3907: #
3908: #--- Javascript to handle csv upload
1.27 albertel 3909: sub csvupload_javascript_reverse_associate {
1.573 bisitz 3910: my $error1=&mt('You need to specify the username or the student/employee ID');
1.246 albertel 3911: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3912: return(<<ENDPICK);
3913: function verify(vf) {
3914: var foundsomething=0;
3915: var founduname=0;
1.243 albertel 3916: var foundID=0;
1.27 albertel 3917: for (i=0;i<=vf.nfields.value;i++) {
3918: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3919: if (i==0 && tw!=0) { foundID=1; }
3920: if (i==1 && tw!=0) { founduname=1; }
3921: if (i!=0 && i!=1 && i!=2 && tw!=0) { foundsomething=1; }
1.27 albertel 3922: }
1.246 albertel 3923: if (founduname==0 && foundID==0) {
3924: alert('$error1');
3925: return;
1.27 albertel 3926: }
3927: if (foundsomething==0) {
1.246 albertel 3928: alert('$error2');
3929: return;
1.27 albertel 3930: }
3931: vf.submit();
3932: }
3933: function flip(vf,tf) {
3934: var nw=eval('vf.f'+tf+'.selectedIndex');
3935: var i;
3936: for (i=0;i<=vf.nfields.value;i++) {
3937: //can not pick the same destination field for both name and domain
3938: if (((i ==0)||(i ==1)) &&
3939: ((tf==0)||(tf==1)) &&
3940: (i!=tf) &&
3941: (eval('vf.f'+i+'.selectedIndex')==nw)) {
3942: eval('vf.f'+i+'.selectedIndex=0;')
3943: }
3944: }
3945: }
3946: ENDPICK
3947: }
3948:
3949: sub csvupload_javascript_forward_associate {
1.573 bisitz 3950: my $error1=&mt('You need to specify the username or the student/employee ID');
1.246 albertel 3951: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3952: return(<<ENDPICK);
3953: function verify(vf) {
3954: var foundsomething=0;
3955: var founduname=0;
1.243 albertel 3956: var foundID=0;
1.27 albertel 3957: for (i=0;i<=vf.nfields.value;i++) {
3958: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3959: if (tw==1) { foundID=1; }
3960: if (tw==2) { founduname=1; }
3961: if (tw>3) { foundsomething=1; }
1.27 albertel 3962: }
1.246 albertel 3963: if (founduname==0 && foundID==0) {
3964: alert('$error1');
3965: return;
1.27 albertel 3966: }
3967: if (foundsomething==0) {
1.246 albertel 3968: alert('$error2');
3969: return;
1.27 albertel 3970: }
3971: vf.submit();
3972: }
3973: function flip(vf,tf) {
3974: var nw=eval('vf.f'+tf+'.selectedIndex');
3975: var i;
3976: //can not pick the same destination field twice
3977: for (i=0;i<=vf.nfields.value;i++) {
3978: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
3979: eval('vf.f'+i+'.selectedIndex=0;')
3980: }
3981: }
3982: }
3983: ENDPICK
3984: }
3985:
1.26 albertel 3986: sub csvuploadmap_header {
1.324 albertel 3987: my ($request,$symb,$datatoken,$distotal)= @_;
1.41 ng 3988: my $javascript;
1.257 albertel 3989: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3990: $javascript=&csvupload_javascript_reverse_associate();
3991: } else {
3992: $javascript=&csvupload_javascript_forward_associate();
3993: }
1.45 ng 3994:
1.324 albertel 3995: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.257 albertel 3996: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1.245 albertel 3997: my $ignore=&mt('Ignore First Line');
1.418 albertel 3998: $symb = &Apache::lonenc::check_encrypt($symb);
1.41 ng 3999: $request->print(<<ENDPICK);
1.26 albertel 4000: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.398 albertel 4001: <h3><span class="LC_info">Uploading Class Grades</span></h3>
1.45 ng 4002: $result
1.326 albertel 4003: <hr />
1.26 albertel 4004: <h3>Identify fields</h3>
4005: Total number of records found in file: $distotal <hr />
4006: Enter as many fields as you can. The system will inform you and bring you back
4007: to this page if the data selected is insufficient to run your class.<hr />
1.589 bisitz 4008: <input type="button" value="Reverse Association" onclick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1.245 albertel 4009: <label><input type="checkbox" name="noFirstLine" $checked />$ignore</label>
1.26 albertel 4010: <input type="hidden" name="associate" value="" />
4011: <input type="hidden" name="phase" value="three" />
4012: <input type="hidden" name="datatoken" value="$datatoken" />
1.257 albertel 4013: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
4014: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
1.26 albertel 4015: <input type="hidden" name="upfile_associate"
1.257 albertel 4016: value="$env{'form.upfile_associate'}" />
1.26 albertel 4017: <input type="hidden" name="symb" value="$symb" />
1.257 albertel 4018: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
4019: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
1.246 albertel 4020: <input type="hidden" name="command" value="csvuploadoptions" />
1.26 albertel 4021: <hr />
4022: <script type="text/javascript" language="Javascript">
4023: $javascript
4024: </script>
4025: ENDPICK
1.118 ng 4026: return '';
1.26 albertel 4027:
4028: }
4029:
4030: sub csvupload_fields {
1.582 raeburn 4031: my ($symb,$errorref) = @_;
4032: my (@parts) = &getpartlist($symb,$errorref);
4033: if (ref($errorref)) {
4034: if ($$errorref) {
4035: return;
4036: }
4037: }
4038:
1.556 weissno 4039: my @fields=(['ID','Student/Employee ID'],
1.243 albertel 4040: ['username','Student Username'],
4041: ['domain','Student Domain']);
1.324 albertel 4042: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.41 ng 4043: foreach my $part (sort(@parts)) {
4044: my @datum;
4045: my $display=&Apache::lonnet::metadata($url,$part.'.display');
4046: my $name=$part;
4047: if (!$display) { $display = $name; }
4048: @datum=($name,$display);
1.244 albertel 4049: if ($name=~/^stores_(.*)_awarded/) {
4050: push(@fields,['stores_'.$1.'_points',"Points [Part: $1]"]);
4051: }
1.41 ng 4052: push(@fields,\@datum);
4053: }
4054: return (@fields);
1.26 albertel 4055: }
4056:
4057: sub csvuploadmap_footer {
1.41 ng 4058: my ($request,$i,$keyfields) =@_;
4059: $request->print(<<ENDPICK);
1.26 albertel 4060: </table>
4061: <input type="hidden" name="nfields" value="$i" />
4062: <input type="hidden" name="keyfields" value="$keyfields" />
1.589 bisitz 4063: <input type="button" onclick="javascript:verify(this.form)" value="Assign Grades" /><br />
1.26 albertel 4064: </form>
4065: ENDPICK
4066: }
4067:
1.283 albertel 4068: sub checkforfile_js {
1.539 riegler 4069: my $alertmsg = &mt('Please use the browse button to select a file from your local directory.');
1.86 ng 4070: my $result =<<CSVFORMJS;
4071: <script type="text/javascript" language="javascript">
4072: function checkUpload(formname) {
4073: if (formname.upfile.value == "") {
1.539 riegler 4074: alert("$alertmsg");
1.86 ng 4075: return false;
4076: }
4077: formname.submit();
4078: }
4079: </script>
4080: CSVFORMJS
1.283 albertel 4081: return $result;
4082: }
4083:
4084: sub upcsvScores_form {
4085: my ($request) = shift;
1.324 albertel 4086: my ($symb)=&get_symb($request);
1.283 albertel 4087: if (!$symb) {return '';}
4088: my $result=&checkforfile_js();
1.257 albertel 4089: $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
1.324 albertel 4090: my ($table) = &showResourceInfo($symb,$env{'form.probTitle'});
1.118 ng 4091: $result.=$table;
1.326 albertel 4092: $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
4093: $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
1.538 schulted 4094: $result.=' <b>'.&mt('Specify a file containing the class scores for current resource.').
4095: '</b></td></tr>'."\n";
1.596.2.4 raeburn 4096: $result.='<tr bgcolor="#ffffe6"><td>'."\n";
1.370 www 4097: my $upload=&mt("Upload Scores");
1.86 ng 4098: my $upfile_select=&Apache::loncommon::upfile_select_html();
1.245 albertel 4099: my $ignore=&mt('Ignore First Line');
1.418 albertel 4100: $symb = &Apache::lonenc::check_encrypt($symb);
1.86 ng 4101: $result.=<<ENDUPFORM;
1.106 albertel 4102: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.86 ng 4103: <input type="hidden" name="symb" value="$symb" />
4104: <input type="hidden" name="command" value="csvuploadmap" />
1.257 albertel 4105: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
4106: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
1.86 ng 4107: $upfile_select
1.589 bisitz 4108: <br /><input type="button" onclick="javascript:checkUpload(this.form);" value="$upload" />
1.283 albertel 4109: <label><input type="checkbox" name="noFirstLine" />$ignore</label>
1.86 ng 4110: </form>
4111: ENDUPFORM
1.370 www 4112: $result.=&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
4113: &mt("How do I create a CSV file from a spreadsheet"))
4114: .'</td></tr></table>'."\n";
1.86 ng 4115: $result.='</td></tr></table><br /><br />'."\n";
1.324 albertel 4116: $result.=&show_grading_menu_form($symb);
1.86 ng 4117: return $result;
4118: }
4119:
4120:
1.26 albertel 4121: sub csvuploadmap {
1.41 ng 4122: my ($request)= @_;
1.324 albertel 4123: my ($symb)=&get_symb($request);
1.41 ng 4124: if (!$symb) {return '';}
1.72 ng 4125:
1.41 ng 4126: my $datatoken;
1.257 albertel 4127: if (!$env{'form.datatoken'}) {
1.41 ng 4128: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 4129: } else {
1.257 albertel 4130: $datatoken=$env{'form.datatoken'};
1.41 ng 4131: &Apache::loncommon::load_tmp_file($request);
1.26 albertel 4132: }
1.41 ng 4133: my @records=&Apache::loncommon::upfile_record_sep();
1.257 albertel 4134: if ($env{'form.noFirstLine'}) { shift(@records); }
1.324 albertel 4135: &csvuploadmap_header($request,$symb,$datatoken,$#records+1);
1.41 ng 4136: my ($i,$keyfields);
4137: if (@records) {
1.582 raeburn 4138: my $fieldserror;
4139: my @fields=&csvupload_fields($symb,\$fieldserror);
4140: if ($fieldserror) {
4141: $request->print(&navmap_errormsg());
4142: return;
4143: }
1.257 albertel 4144: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 4145: &Apache::loncommon::csv_print_samples($request,\@records);
4146: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
4147: \@fields);
4148: foreach (@fields) { $keyfields.=$_->[0].','; }
4149: chop($keyfields);
4150: } else {
4151: unshift(@fields,['none','']);
4152: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
4153: \@fields);
1.311 banghart 4154: foreach my $rec (@records) {
4155: my %temp = &Apache::loncommon::record_sep($rec);
4156: if (%temp) {
4157: $keyfields=join(',',sort(keys(%temp)));
4158: last;
4159: }
4160: }
1.41 ng 4161: }
4162: }
4163: &csvuploadmap_footer($request,$i,$keyfields);
1.324 albertel 4164: $request->print(&show_grading_menu_form($symb));
1.72 ng 4165:
1.41 ng 4166: return '';
1.27 albertel 4167: }
4168:
1.246 albertel 4169: sub csvuploadoptions {
1.41 ng 4170: my ($request)= @_;
1.324 albertel 4171: my ($symb)=&get_symb($request);
1.257 albertel 4172: my $checked=(($env{'form.noFirstLine'})?'1':'0');
1.246 albertel 4173: my $ignore=&mt('Ignore First Line');
4174: $request->print(<<ENDPICK);
4175: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.398 albertel 4176: <h3><span class="LC_info">Uploading Class Grade Options</span></h3>
1.246 albertel 4177: <input type="hidden" name="command" value="csvuploadassign" />
1.302 albertel 4178: <!--
1.246 albertel 4179: <p>
4180: <label>
4181: <input type="checkbox" name="show_full_results" />
4182: Show a table of all changes
4183: </label>
4184: </p>
1.302 albertel 4185: -->
1.246 albertel 4186: <p>
4187: <label>
4188: <input type="checkbox" name="overwite_scores" checked="checked" />
4189: Overwrite any existing score
4190: </label>
4191: </p>
4192: ENDPICK
4193: my %fields=&get_fields();
4194: if (!defined($fields{'domain'})) {
1.257 albertel 4195: my $domform = &Apache::loncommon::select_dom_form($env{'request.role.domain'},'default_domain');
1.246 albertel 4196: $request->print("\n<p> Users are in domain: ".$domform."</p>\n");
4197: }
1.257 albertel 4198: foreach my $key (sort(keys(%env))) {
1.246 albertel 4199: if ($key !~ /^form\.(.*)$/) { next; }
4200: my $cleankey=$1;
4201: if ($cleankey eq 'command') { next; }
4202: $request->print('<input type="hidden" name="'.$cleankey.
1.257 albertel 4203: '" value="'.$env{$key}.'" />'."\n");
1.246 albertel 4204: }
4205: # FIXME do a check for any duplicated user ids...
4206: # FIXME do a check for any invalid user ids?...
1.290 albertel 4207: $request->print('<input type="submit" value="Assign Grades" /><br />
4208: <hr /></form>'."\n");
1.324 albertel 4209: $request->print(&show_grading_menu_form($symb));
1.246 albertel 4210: return '';
4211: }
4212:
4213: sub get_fields {
4214: my %fields;
1.257 albertel 4215: my @keyfields = split(/\,/,$env{'form.keyfields'});
4216: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
4217: if ($env{'form.upfile_associate'} eq 'reverse') {
4218: if ($env{'form.f'.$i} ne 'none') {
4219: $fields{$keyfields[$i]}=$env{'form.f'.$i};
1.41 ng 4220: }
4221: } else {
1.257 albertel 4222: if ($env{'form.f'.$i} ne 'none') {
4223: $fields{$env{'form.f'.$i}}=$keyfields[$i];
1.41 ng 4224: }
4225: }
1.27 albertel 4226: }
1.246 albertel 4227: return %fields;
4228: }
4229:
4230: sub csvuploadassign {
4231: my ($request)= @_;
1.324 albertel 4232: my ($symb)=&get_symb($request);
1.246 albertel 4233: if (!$symb) {return '';}
1.345 bowersj2 4234: my $error_msg = '';
1.246 albertel 4235: &Apache::loncommon::load_tmp_file($request);
4236: my @gradedata = &Apache::loncommon::upfile_record_sep();
1.257 albertel 4237: if ($env{'form.noFirstLine'}) { shift(@gradedata); }
1.246 albertel 4238: my %fields=&get_fields();
1.41 ng 4239: $request->print('<h3>Assigning Grades</h3>');
1.257 albertel 4240: my $courseid=$env{'request.course.id'};
1.97 albertel 4241: my ($classlist) = &getclasslist('all',0);
1.106 albertel 4242: my @notallowed;
1.41 ng 4243: my @skipped;
1.596.2.4 raeburn 4244: my @warnings;
1.41 ng 4245: my $countdone=0;
4246: foreach my $grade (@gradedata) {
4247: my %entries=&Apache::loncommon::record_sep($grade);
1.246 albertel 4248: my $domain;
4249: if ($entries{$fields{'domain'}}) {
4250: $domain=$entries{$fields{'domain'}};
4251: } else {
1.257 albertel 4252: $domain=$env{'form.default_domain'};
1.246 albertel 4253: }
1.243 albertel 4254: $domain=~s/\s//g;
1.41 ng 4255: my $username=$entries{$fields{'username'}};
1.160 albertel 4256: $username=~s/\s//g;
1.243 albertel 4257: if (!$username) {
4258: my $id=$entries{$fields{'ID'}};
1.247 albertel 4259: $id=~s/\s//g;
1.243 albertel 4260: my %ids=&Apache::lonnet::idget($domain,$id);
4261: $username=$ids{$id};
4262: }
1.41 ng 4263: if (!exists($$classlist{"$username:$domain"})) {
1.247 albertel 4264: my $id=$entries{$fields{'ID'}};
4265: $id=~s/\s//g;
4266: if ($id) {
4267: push(@skipped,"$id:$domain");
4268: } else {
4269: push(@skipped,"$username:$domain");
4270: }
1.41 ng 4271: next;
4272: }
1.108 albertel 4273: my $usec=$classlist->{"$username:$domain"}[5];
1.106 albertel 4274: if (!&canmodify($usec)) {
4275: push(@notallowed,"$username:$domain");
4276: next;
4277: }
1.244 albertel 4278: my %points;
1.41 ng 4279: my %grades;
4280: foreach my $dest (keys(%fields)) {
1.244 albertel 4281: if ($dest eq 'ID' || $dest eq 'username' ||
4282: $dest eq 'domain') { next; }
4283: if ($entries{$fields{$dest}} =~ /^\s*$/) { next; }
4284: if ($dest=~/stores_(.*)_points/) {
4285: my $part=$1;
4286: my $wgt =&Apache::lonnet::EXT('resource.'.$part.'.weight',
4287: $symb,$domain,$username);
1.345 bowersj2 4288: if ($wgt) {
4289: $entries{$fields{$dest}}=~s/\s//g;
4290: my $pcr=$entries{$fields{$dest}} / $wgt;
1.463 albertel 4291: my $award=($pcr == 0) ? 'incorrect_by_override'
4292: : 'correct_by_override';
1.596.2.4 raeburn 4293: if ($pcr>1) {
4294: push(@warnings,&mt("[_1]: point value larger than weight","$username:$domain"));
4295: }
1.345 bowersj2 4296: $grades{"resource.$part.awarded"}=$pcr;
4297: $grades{"resource.$part.solved"}=$award;
4298: $points{$part}=1;
4299: } else {
4300: $error_msg = "<br />" .
4301: &mt("Some point values were assigned"
4302: ." for problems with a weight "
4303: ."of zero. These values were "
4304: ."ignored.");
4305: }
1.244 albertel 4306: } else {
4307: if ($dest=~/stores_(.*)_awarded/) { if ($points{$1}) {next;} }
4308: if ($dest=~/stores_(.*)_solved/) { if ($points{$1}) {next;} }
4309: my $store_key=$dest;
4310: $store_key=~s/^stores/resource/;
4311: $store_key=~s/_/\./g;
4312: $grades{$store_key}=$entries{$fields{$dest}};
4313: }
1.41 ng 4314: }
1.508 www 4315: if (! %grades) {
4316: push(@skipped,&mt("[_1]: no data to save","$username:$domain"));
4317: } else {
4318: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
4319: my $result=&Apache::lonnet::cstore(\%grades,$symb,
1.302 albertel 4320: $env{'request.course.id'},
4321: $domain,$username);
1.508 www 4322: if ($result eq 'ok') {
4323: $request->print('.');
1.596.2.4 raeburn 4324: # Remove from grading queue
4325: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,
4326: $env{'course.'.$env{'request.course.id'}.'.domain'},
4327: $env{'course.'.$env{'request.course.id'}.'.num'},
4328: $domain,$username);
1.508 www 4329: } else {
4330: $request->print("<p><span class=\"LC_error\">".
4331: &mt("Failed to save data for student [_1]. Message when trying to save was: [_2]",
4332: "$username:$domain",$result)."</span></p>");
4333: }
4334: $request->rflush();
4335: $countdone++;
4336: }
1.41 ng 4337: }
1.570 www 4338: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt("Saved scores for [quant,_1,student]",$countdone),$countdone==0));
1.596.2.4 raeburn 4339: if (@warnings) {
4340: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('Warnings generated for the following saved scores:'),1).'<br />');
4341: $request->print(join(', ',@warnings));
4342: }
1.41 ng 4343: if (@skipped) {
1.571 www 4344: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('No scores stored for the following username(s):'),1).'<br />');
4345: $request->print(join(', ',@skipped));
1.106 albertel 4346: }
4347: if (@notallowed) {
1.571 www 4348: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('Modification of scores not allowed for the following username(s):'),1).'<br />');
4349: $request->print(join(', ',@notallowed));
1.41 ng 4350: }
1.106 albertel 4351: $request->print("<br />\n");
1.324 albertel 4352: $request->print(&show_grading_menu_form($symb));
1.345 bowersj2 4353: return $error_msg;
1.26 albertel 4354: }
1.44 ng 4355: #------------- end of section for handling csv file upload ---------
4356: #
4357: #-------------------------------------------------------------------
4358: #
1.122 ng 4359: #-------------- Next few routines handle grading by page/sequence
1.72 ng 4360: #
4361: #--- Select a page/sequence and a student to grade
1.68 ng 4362: sub pickStudentPage {
4363: my ($request) = shift;
4364:
1.539 riegler 4365: my $alertmsg = &mt('Please select the student you wish to grade.');
1.68 ng 4366: $request->print(<<LISTJAVASCRIPT);
4367: <script type="text/javascript" language="javascript">
4368:
4369: function checkPickOne(formname) {
1.76 ng 4370: if (radioSelection(formname.student) == null) {
1.539 riegler 4371: alert("$alertmsg");
1.68 ng 4372: return;
4373: }
1.125 ng 4374: ptr = pullDownSelection(formname.selectpage);
4375: formname.page.value = formname["page"+ptr].value;
4376: formname.title.value = formname["title"+ptr].value;
1.68 ng 4377: formname.submit();
4378: }
4379:
4380: </script>
4381: LISTJAVASCRIPT
1.118 ng 4382: &commonJSfunctions($request);
1.324 albertel 4383: my ($symb) = &get_symb($request);
1.257 albertel 4384: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4385: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4386: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.68 ng 4387:
1.398 albertel 4388: my $result='<h3><span class="LC_info"> '.
1.485 albertel 4389: &mt('Manual Grading by Page or Sequence').'</span></h3>';
1.68 ng 4390:
1.80 ng 4391: $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
1.582 raeburn 4392: my $map_error;
4393: my ($titles,$symbx) = &getSymbMap($map_error);
4394: if ($map_error) {
4395: $request->print(&navmap_errormsg());
4396: return;
4397: }
1.137 albertel 4398: my ($curpage) =&Apache::lonnet::decode_symb($symb);
4399: # my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb);
4400: # my $type=($curpage =~ /\.(page|sequence)/);
1.485 albertel 4401: my $select = '<select name="selectpage">'."\n";
1.70 ng 4402: my $ctr=0;
1.68 ng 4403: foreach (@$titles) {
4404: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.485 albertel 4405: $select.='<option value="'.$ctr.'" '.
1.401 albertel 4406: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.71 ng 4407: '>'.$showtitle.'</option>'."\n";
1.70 ng 4408: $ctr++;
1.68 ng 4409: }
1.485 albertel 4410: $select.= '</select>';
1.539 riegler 4411: $result.=' <b>'.&mt('Problems from').':</b> '.$select."<br />\n";
1.485 albertel 4412:
1.70 ng 4413: $ctr=0;
4414: foreach (@$titles) {
4415: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
4416: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
4417: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
4418: $ctr++;
4419: }
1.72 ng 4420: $result.='<input type="hidden" name="page" />'."\n".
4421: '<input type="hidden" name="title" />'."\n";
1.68 ng 4422:
1.485 albertel 4423: my $options =
4424: '<label><input type="radio" name="vProb" value="no" checked="checked" /> '.&mt('no').' </label>'."\n".
4425: '<label><input type="radio" name="vProb" value="yes" /> '.&mt('yes').' </label>'."<br />\n";
1.539 riegler 4426: $result.=' <b>'.&mt('View Problem Text').': </b>'.$options;
1.485 albertel 4427:
4428: $options =
4429: '<label><input type="radio" name="lastSub" value="none" /> '.&mt('none').' </label>'."\n".
4430: '<label><input type="radio" name="lastSub" value="datesub" checked="checked" /> '.&mt('by dates and submissions').'</label>'."\n".
4431: '<label><input type="radio" name="lastSub" value="all" /> '.&mt('all details').' </label>'."\n";
1.539 riegler 4432: $result.=' <b>'.&mt('Submissions').': </b>'.$options;
1.432 banghart 4433:
4434: $result.=&build_section_inputs();
1.442 banghart 4435: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
4436: $result.='<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.72 ng 4437: '<input type="hidden" name="command" value="displayPage" />'."\n".
1.418 albertel 4438: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 4439: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."<br />\n";
1.72 ng 4440:
1.539 riegler 4441: $result.=' <b>'.&mt('Use CODE').': </b> <input type="text" name="CODE" value="" /> <br />'."\n";
1.382 albertel 4442:
1.80 ng 4443: $result.=' <input type="button" '.
1.589 bisitz 4444: 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /><br />'."\n";
1.72 ng 4445:
1.68 ng 4446: $request->print($result);
4447:
1.485 albertel 4448: my $studentTable.=' <b>'.&mt('Select a student you wish to grade and then click on the Next button.').'</b><br />'.
1.484 albertel 4449: &Apache::loncommon::start_data_table().
4450: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 4451: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 4452: '<th>'.&nameUserString('header').'</th>'.
1.485 albertel 4453: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 4454: '<th>'.&nameUserString('header').'</th>'.
4455: &Apache::loncommon::end_data_table_header_row();
1.68 ng 4456:
1.76 ng 4457: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.68 ng 4458: my $ptr = 1;
1.294 albertel 4459: foreach my $student (sort
4460: {
4461: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
4462: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
4463: }
4464: return $a cmp $b;
4465: } (keys(%$fullname))) {
1.68 ng 4466: my ($uname,$udom) = split(/:/,$student);
1.484 albertel 4467: $studentTable.=($ptr%2==1 ? &Apache::loncommon::start_data_table_row()
4468: : '</td>');
1.126 ng 4469: $studentTable.='<td align="right">'.$ptr.' </td>';
1.288 albertel 4470: $studentTable.='<td> <label><input type="radio" name="student" value="'.$student.'" /> '
4471: .&nameUserString(undef,$$fullname{$student},$uname,$udom)."</label>\n";
1.484 albertel 4472: $studentTable.=
4473: ($ptr%2 == 0 ? '</td>'.&Apache::loncommon::end_data_table_row()
4474: : '');
1.68 ng 4475: $ptr++;
4476: }
1.484 albertel 4477: if ($ptr%2 == 0) {
4478: $studentTable.='</td><td> </td><td> </td>'.
4479: &Apache::loncommon::end_data_table_row();
4480: }
4481: $studentTable.=&Apache::loncommon::end_data_table()."\n";
1.126 ng 4482: $studentTable.='<input type="button" '.
1.589 bisitz 4483: 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /></form>'."\n";
1.68 ng 4484:
1.324 albertel 4485: $studentTable.=&show_grading_menu_form($symb);
1.68 ng 4486: $request->print($studentTable);
4487:
4488: return '';
4489: }
4490:
4491: sub getSymbMap {
1.582 raeburn 4492: my ($map_error) = @_;
1.132 bowersj2 4493: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 4494: unless (ref($navmap)) {
4495: if (ref($map_error)) {
4496: $$map_error = 'navmap';
4497: }
4498: return;
4499: }
1.68 ng 4500: my %symbx = ();
4501: my @titles = ();
1.117 bowersj2 4502: my $minder = 0;
4503:
4504: # Gather every sequence that has problems.
1.240 albertel 4505: my @sequences = $navmap->retrieveResources(undef, sub { shift->is_map(); },
4506: 1,0,1);
1.117 bowersj2 4507: for my $sequence ($navmap->getById('0.0'), @sequences) {
1.241 albertel 4508: if ($navmap->hasResource($sequence, sub { shift->is_problem(); }, 0) ) {
1.381 albertel 4509: my $title = $minder.'.'.
4510: &HTML::Entities::encode($sequence->compTitle(),'"\'&');
4511: push(@titles, $title); # minder in case two titles are identical
4512: $symbx{$title} = &HTML::Entities::encode($sequence->symb(),'"\'&');
1.117 bowersj2 4513: $minder++;
1.241 albertel 4514: }
1.68 ng 4515: }
4516: return \@titles,\%symbx;
4517: }
4518:
1.72 ng 4519: #
4520: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68 ng 4521: sub displayPage {
4522: my ($request) = shift;
4523:
1.324 albertel 4524: my ($symb) = &get_symb($request);
1.257 albertel 4525: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4526: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4527: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
4528: my $pageTitle = $env{'form.page'};
1.103 albertel 4529: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 4530: my ($uname,$udom) = split(/:/,$env{'form.student'});
4531: my $usec=$classlist->{$env{'form.student'}}[5];
1.168 albertel 4532:
4533: #need to make sure we have the correct data for later EXT calls,
4534: #thus invalidate the cache
4535: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 4536: $env{'course.'.$env{'request.course.id'}.'.num'},
4537: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 4538: &Apache::lonnet::clear_EXT_cache_status();
4539:
1.103 albertel 4540: if (!&canview($usec)) {
1.485 albertel 4541: $request->print('<span class="LC_warning">'.&mt('Unable to view requested student. ([_1])',$env{'form.student'}).'</span>');
1.324 albertel 4542: $request->print(&show_grading_menu_form($symb));
1.103 albertel 4543: return;
4544: }
1.398 albertel 4545: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.485 albertel 4546: $result.='<h3> '.&mt('Student: [_1]',&nameUserString(undef,$$fullname{$env{'form.student'}},$uname,$udom)).
1.129 ng 4547: '</h3>'."\n";
1.500 albertel 4548: $env{'form.CODE'} = uc($env{'form.CODE'});
1.501 foxr 4549: if (&Apache::lonnet::validCODE(uc($env{'form.CODE'}))) {
1.485 albertel 4550: $result.='<h3> '.&mt('CODE: [_1]',$env{'form.CODE'}).'</h3>'."\n";
1.382 albertel 4551: } else {
4552: delete($env{'form.CODE'});
4553: }
1.71 ng 4554: &sub_page_js($request);
4555: $request->print($result);
4556:
1.132 bowersj2 4557: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 4558: unless (ref($navmap)) {
4559: $request->print(&navmap_errormsg());
4560: $request->print(&show_grading_menu_form($symb));
4561: return;
4562: }
1.257 albertel 4563: my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($env{'form.page'});
1.68 ng 4564: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 4565: if (!$map) {
1.485 albertel 4566: $request->print('<span class="LC_warning">'.&mt('Unable to view requested sequence. ([_1])',$resUrl).'</span>');
1.324 albertel 4567: $request->print(&show_grading_menu_form($symb));
1.288 albertel 4568: return;
4569: }
1.68 ng 4570: my $iterator = $navmap->getIterator($map->map_start(),
4571: $map->map_finish());
4572:
1.71 ng 4573: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72 ng 4574: '<input type="hidden" name="command" value="gradeByPage" />'."\n".
1.257 albertel 4575: '<input type="hidden" name="fullname" value="'.$$fullname{$env{'form.student'}}.'" />'."\n".
4576: '<input type="hidden" name="student" value="'.$env{'form.student'}.'" />'."\n".
1.72 ng 4577: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
1.257 albertel 4578: '<input type="hidden" name="title" value="'.$env{'form.title'}.'" />'."\n".
1.418 albertel 4579: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.125 ng 4580: '<input type="hidden" name="overRideScore" value="no" />'."\n".
1.257 albertel 4581: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n";
1.71 ng 4582:
1.382 albertel 4583: if (defined($env{'form.CODE'})) {
4584: $studentTable.=
4585: '<input type="hidden" name="CODE" value="'.$env{'form.CODE'}.'" />'."\n";
4586: }
1.381 albertel 4587: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 4588: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 4589:
1.594 bisitz 4590: $studentTable.=' <span class="LC_info">'.
4591: &mt('Problems graded correct by the computer are marked with a [_1] symbol.',$checkIcon).
4592: '</span>'."\n".
1.484 albertel 4593: &Apache::loncommon::start_data_table().
4594: &Apache::loncommon::start_data_table_header_row().
4595: '<th align="center"> Prob. </th>'.
1.485 albertel 4596: '<th> '.($env{'form.vProb'} eq 'no' ? &mt('Title') : &mt('Problem Text')).'/'.&mt('Grade').'</th>'.
1.484 albertel 4597: &Apache::loncommon::end_data_table_header_row();
1.71 ng 4598:
1.329 albertel 4599: &Apache::lonxml::clear_problem_counter();
1.196 albertel 4600: my ($depth,$question,$prob) = (1,1,1);
1.68 ng 4601: $iterator->next(); # skip the first BEGIN_MAP
4602: my $curRes = $iterator->next(); # for "current resource"
1.101 albertel 4603: while ($depth > 0) {
1.68 ng 4604: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4605: if($curRes == $iterator->END_MAP) { $depth--; }
1.68 ng 4606:
1.385 albertel 4607: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4608: my $parts = $curRes->parts();
1.68 ng 4609: my $title = $curRes->compTitle();
1.71 ng 4610: my $symbx = $curRes->symb();
1.484 albertel 4611: $studentTable.=
4612: &Apache::loncommon::start_data_table_row().
4613: '<td align="center" valign="top" >'.$prob.
1.485 albertel 4614: (scalar(@{$parts}) == 1 ? ''
1.596.2.2 raeburn 4615: : '<br />('.&mt('[_1]parts)',
4616: scalar(@{$parts}).' ')
1.485 albertel 4617: ).
4618: '</td>';
1.71 ng 4619: $studentTable.='<td valign="top">';
1.382 albertel 4620: my %form = ('CODE' => $env{'form.CODE'},);
1.257 albertel 4621: if ($env{'form.vProb'} eq 'yes' ) {
1.144 albertel 4622: $studentTable.=&show_problem($request,$symbx,$uname,$udom,1,
1.383 albertel 4623: undef,'both',\%form);
1.71 ng 4624: } else {
1.382 albertel 4625: my $companswer = &Apache::loncommon::get_student_answers($symbx,$uname,$udom,$env{'request.course.id'},%form);
1.80 ng 4626: $companswer =~ s|<form(.*?)>||g;
4627: $companswer =~ s|</form>||g;
1.71 ng 4628: # while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
1.116 ng 4629: # $companswer =~ s/$1/ /ms;
1.326 albertel 4630: # $request->print('match='.$1."<br />\n");
1.71 ng 4631: # }
1.116 ng 4632: # $companswer =~ s|<table border=\"1\">|<table border=\"0\">|g;
1.539 riegler 4633: $studentTable.=' <b>'.$title.'</b> <br /> <b>'.&mt('Correct answer').':</b><br />'.$companswer;
1.71 ng 4634: }
4635:
1.257 albertel 4636: my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
1.125 ng 4637:
1.257 albertel 4638: if ($env{'form.lastSub'} eq 'datesub') {
1.71 ng 4639: if ($record{'version'} eq '') {
1.485 albertel 4640: $studentTable.='<br /> <span class="LC_warning">'.&mt('No recorded submission for this problem.').'</span><br />';
1.71 ng 4641: } else {
1.116 ng 4642: my %responseType = ();
4643: foreach my $partid (@{$parts}) {
1.147 albertel 4644: my @responseIds =$curRes->responseIds($partid);
4645: my @responseType =$curRes->responseType($partid);
4646: my %responseIds;
4647: for (my $i=0;$i<=$#responseIds;$i++) {
4648: $responseIds{$responseIds[$i]}=$responseType[$i];
4649: }
4650: $responseType{$partid} = \%responseIds;
1.116 ng 4651: }
1.148 albertel 4652: $studentTable.= &displaySubByDates($symbx,\%record,$parts,\%responseType,$checkIcon,$uname,$udom);
1.147 albertel 4653:
1.71 ng 4654: }
1.257 albertel 4655: } elsif ($env{'form.lastSub'} eq 'all') {
4656: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.71 ng 4657: $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
1.257 albertel 4658: $env{'request.course.id'},
1.71 ng 4659: '','.submission');
4660:
4661: }
1.103 albertel 4662: if (&canmodify($usec)) {
1.585 bisitz 4663: $studentTable.=&gradeBox_start();
1.103 albertel 4664: foreach my $partid (@{$parts}) {
4665: $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
4666: $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
4667: $question++;
4668: }
1.585 bisitz 4669: $studentTable.=&gradeBox_end();
1.196 albertel 4670: $prob++;
1.71 ng 4671: }
4672: $studentTable.='</td></tr>';
1.68 ng 4673:
1.103 albertel 4674: }
1.68 ng 4675: $curRes = $iterator->next();
4676: }
4677:
1.589 bisitz 4678: $studentTable.=
4679: '</table>'."\n".
4680: '<input type="button" value="'.&mt('Save').'" '.
4681: 'onclick="javascript:checkSubmitPage(this.form,'.$question.');" />'.
4682: '</form>'."\n";
1.324 albertel 4683: $studentTable.=&show_grading_menu_form($symb);
1.71 ng 4684: $request->print($studentTable);
4685:
4686: return '';
1.119 ng 4687: }
4688:
4689: sub displaySubByDates {
1.148 albertel 4690: my ($symb,$record,$parts,$responseType,$checkIcon,$uname,$udom) = @_;
1.224 albertel 4691: my $isCODE=0;
1.335 albertel 4692: my $isTask = ($symb =~/\.task$/);
1.224 albertel 4693: if (exists($record->{'resource.CODE'})) { $isCODE=1; }
1.467 albertel 4694: my $studentTable=&Apache::loncommon::start_data_table().
4695: &Apache::loncommon::start_data_table_header_row().
4696: '<th>'.&mt('Date/Time').'</th>'.
4697: ($isCODE?'<th>'.&mt('CODE').'</th>':'').
4698: '<th>'.&mt('Submission').'</th>'.
4699: '<th>'.&mt('Status').'</th>'.
4700: &Apache::loncommon::end_data_table_header_row();
1.119 ng 4701: my ($version);
4702: my %mark;
1.148 albertel 4703: my %orders;
1.119 ng 4704: $mark{'correct_by_student'} = $checkIcon;
1.147 albertel 4705: if (!exists($$record{'1:timestamp'})) {
1.539 riegler 4706: return '<br /> <span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br />';
1.147 albertel 4707: }
1.335 albertel 4708:
4709: my $interaction;
1.525 raeburn 4710: my $no_increment = 1;
1.596.2.2 raeburn 4711: my %lastrndseed;
1.119 ng 4712: for ($version=1;$version<=$$record{'version'};$version++) {
1.467 albertel 4713: my $timestamp =
4714: &Apache::lonlocal::locallocaltime($$record{$version.':timestamp'});
1.335 albertel 4715: if (exists($$record{$version.':resource.0.version'})) {
4716: $interaction = $$record{$version.':resource.0.version'};
4717: }
4718:
4719: my $where = ($isTask ? "$version:resource.$interaction"
4720: : "$version:resource");
1.467 albertel 4721: $studentTable.=&Apache::loncommon::start_data_table_row().
4722: '<td>'.$timestamp.'</td>';
1.224 albertel 4723: if ($isCODE) {
4724: $studentTable.='<td>'.$record->{$version.':resource.CODE'}.'</td>';
4725: }
1.119 ng 4726: my @versionKeys = split(/\:/,$$record{$version.':keys'});
4727: my @displaySub = ();
4728: foreach my $partid (@{$parts}) {
1.596.2.2 raeburn 4729: my ($hidden,$type);
4730: $type = $$record{$version.':resource.'.$partid.'.type'};
4731: if (($type eq 'anonsurvey') || ($type eq 'anonsurveycred')) {
1.596 raeburn 4732: $hidden = 1;
4733: }
1.335 albertel 4734: my @matchKey = ($isTask ? sort(grep /^resource\.\d+\.\Q$partid\E\.award$/,@versionKeys)
4735: : sort(grep /^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys));
4736:
1.122 ng 4737: # next if ($$record{"$version:resource.$partid.solved"} eq '');
1.324 albertel 4738: my $display_part=&get_display_part($partid,$symb);
1.147 albertel 4739: foreach my $matchKey (@matchKey) {
1.198 albertel 4740: if (exists($$record{$version.':'.$matchKey}) &&
4741: $$record{$version.':'.$matchKey} ne '') {
1.596 raeburn 4742:
1.335 albertel 4743: my ($responseId)= ($isTask ? ($matchKey=~ /^resource\.(.*?)\.\Q$partid\E\.award$/)
4744: : ($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/));
1.596.2.12.2. (raeburn 4745:): $displaySub[0].='<span class="LC_nobreak">';
1.577 bisitz 4746: $displaySub[0].='<b>'.&mt('Part: [_1]',$display_part).'</b>'
4747: .' <span class="LC_internal_info">'
1.596.2.4 raeburn 4748: .'('.&mt('Response ID: [_1]',$responseId).')'
1.577 bisitz 4749: .'</span>'
4750: .' <b>';
1.596 raeburn 4751: if ($hidden) {
4752: $displaySub[0].= &mt('Anonymous Survey').'</b>';
4753: } else {
1.596.2.2 raeburn 4754: my ($trial,$rndseed,$newvariation);
4755: if ($type eq 'randomizetry') {
4756: $trial = $$record{"$where.$partid.tries"};
4757: $rndseed = $$record{"$where.$partid.rndseed"};
4758: }
1.596 raeburn 4759: if ($$record{"$where.$partid.tries"} eq '') {
4760: $displaySub[0].=&mt('Trial not counted');
4761: } else {
4762: $displaySub[0].=&mt('Trial: [_1]',
1.467 albertel 4763: $$record{"$where.$partid.tries"});
1.596.2.2 raeburn 4764: if ($rndseed || $lastrndseed{$partid}) {
4765: if ($rndseed ne $lastrndseed{$partid}) {
4766: $newvariation = ' ('.&mt('New variation this try').')';
4767: }
4768: }
1.596 raeburn 4769: }
4770: my $responseType=($isTask ? 'Task'
1.335 albertel 4771: : $responseType->{$partid}->{$responseId});
1.596 raeburn 4772: if (!exists($orders{$partid})) { $orders{$partid}={}; }
1.596.2.2 raeburn 4773: if ((!exists($orders{$partid}->{$responseId})) || ($trial)) {
1.596 raeburn 4774: $orders{$partid}->{$responseId}=
4775: &get_order($partid,$responseId,$symb,$uname,$udom,
1.596.2.2 raeburn 4776: $no_increment,$type,$trial,$rndseed);
1.596 raeburn 4777: }
1.596.2.2 raeburn 4778: $displaySub[0].='</b>'.$newvariation.'</span>'; # /nobreak
1.596 raeburn 4779: $displaySub[0].=' '.
1.596.2.2 raeburn 4780: &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:",$uname,$udom,$type,$trial,$rndseed).'<br />';
1.596 raeburn 4781: }
1.147 albertel 4782: }
4783: }
1.335 albertel 4784: if (exists($$record{"$where.$partid.checkedin"})) {
1.485 albertel 4785: $displaySub[1].=&mt('Checked in by [_1] into slot [_2]',
4786: $$record{"$where.$partid.checkedin"},
4787: $$record{"$where.$partid.checkedin.slot"}).
4788: '<br />';
1.335 albertel 4789: }
4790: if (exists $$record{"$where.$partid.award"}) {
1.485 albertel 4791: $displaySub[1].='<b>'.&mt('Part:').'</b> '.$display_part.' '.
1.335 albertel 4792: lc($$record{"$where.$partid.award"}).' '.
4793: $mark{$$record{"$where.$partid.solved"}}.
1.147 albertel 4794: '<br />';
4795: }
1.335 albertel 4796: if (exists $$record{"$where.$partid.regrader"}) {
4797: $displaySub[2].=$$record{"$where.$partid.regrader"}.
4798: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
4799: } elsif ($$record{"$version:resource.$partid.regrader"} =~ /\S/) {
4800: $displaySub[2].=
4801: $$record{"$version:resource.$partid.regrader"}.
1.207 albertel 4802: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
1.147 albertel 4803: }
4804: }
4805: # needed because old essay regrader has not parts info
4806: if (exists $$record{"$version:resource.regrader"}) {
4807: $displaySub[2].=$$record{"$version:resource.regrader"};
4808: }
4809: $studentTable.='<td>'.$displaySub[0].' </td><td>'.$displaySub[1];
4810: if ($displaySub[2]) {
1.467 albertel 4811: $studentTable.=&mt('Manually graded by [_1]',$displaySub[2]);
1.147 albertel 4812: }
1.467 albertel 4813: $studentTable.=' </td>'.
4814: &Apache::loncommon::end_data_table_row();
1.119 ng 4815: }
1.467 albertel 4816: $studentTable.=&Apache::loncommon::end_data_table();
1.119 ng 4817: return $studentTable;
1.71 ng 4818: }
4819:
4820: sub updateGradeByPage {
4821: my ($request) = shift;
4822:
1.257 albertel 4823: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4824: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4825: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
4826: my $pageTitle = $env{'form.page'};
1.103 albertel 4827: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 4828: my ($uname,$udom) = split(/:/,$env{'form.student'});
4829: my $usec=$classlist->{$env{'form.student'}}[5];
1.103 albertel 4830: if (!&canmodify($usec)) {
1.526 raeburn 4831: $request->print('<span class="LC_warning">'.&mt('Unable to modify requested student ([_1])',$env{'form.student'}).'</span>');
1.324 albertel 4832: $request->print(&show_grading_menu_form($env{'form.symb'}));
1.103 albertel 4833: return;
4834: }
1.398 albertel 4835: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.526 raeburn 4836: $result.='<h3> '.&mt('Student: ').&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
1.129 ng 4837: '</h3>'."\n";
1.70 ng 4838:
1.68 ng 4839: $request->print($result);
4840:
1.582 raeburn 4841:
1.132 bowersj2 4842: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 4843: unless (ref($navmap)) {
4844: $request->print(&navmap_errormsg());
4845: return;
4846: }
1.257 albertel 4847: my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $env{'form.page'});
1.71 ng 4848: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 4849: if (!$map) {
1.527 raeburn 4850: $request->print('<span class="LC_warning">'.&mt('Unable to grade requested sequence ([_1]).',$resUrl).'</span>');
1.324 albertel 4851: my ($symb)=&get_symb($request);
4852: $request->print(&show_grading_menu_form($symb));
1.288 albertel 4853: return;
4854: }
1.71 ng 4855: my $iterator = $navmap->getIterator($map->map_start(),
4856: $map->map_finish());
1.70 ng 4857:
1.484 albertel 4858: my $studentTable=
4859: &Apache::loncommon::start_data_table().
4860: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 4861: '<th align="center"> '.&mt('Prob.').' </th>'.
4862: '<th> '.&mt('Title').' </th>'.
4863: '<th> '.&mt('Previous Score').' </th>'.
4864: '<th> '.&mt('New Score').' </th>'.
1.484 albertel 4865: &Apache::loncommon::end_data_table_header_row();
1.71 ng 4866:
4867: $iterator->next(); # skip the first BEGIN_MAP
4868: my $curRes = $iterator->next(); # for "current resource"
1.196 albertel 4869: my ($depth,$question,$prob,$changeflag)= (1,1,1,0);
1.101 albertel 4870: while ($depth > 0) {
1.71 ng 4871: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4872: if($curRes == $iterator->END_MAP) { $depth--; }
1.71 ng 4873:
1.385 albertel 4874: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4875: my $parts = $curRes->parts();
1.71 ng 4876: my $title = $curRes->compTitle();
4877: my $symbx = $curRes->symb();
1.484 albertel 4878: $studentTable.=
4879: &Apache::loncommon::start_data_table_row().
4880: '<td align="center" valign="top" >'.$prob.
1.485 albertel 4881: (scalar(@{$parts}) == 1 ? ''
1.596.2.2 raeburn 4882: : '<br />('.&mt('[quant,_1,part]',scalar(@{$parts}))
1.526 raeburn 4883: .')').'</td>';
1.71 ng 4884: $studentTable.='<td valign="top"> <b>'.$title.'</b> </td>';
4885:
4886: my %newrecord=();
4887: my @displayPts=();
1.269 raeburn 4888: my %aggregate = ();
4889: my $aggregateflag = 0;
1.71 ng 4890: foreach my $partid (@{$parts}) {
1.257 albertel 4891: my $newpts = $env{'form.GD_BOX'.$question.'_'.$partid};
4892: my $oldpts = $env{'form.oldpts'.$question.'_'.$partid};
1.71 ng 4893:
1.257 albertel 4894: my $wgt = $env{'form.WGT'.$question.'_'.$partid} != 0 ?
4895: $env{'form.WGT'.$question.'_'.$partid} : 1;
1.71 ng 4896: my $partial = $newpts/$wgt;
4897: my $score;
4898: if ($partial > 0) {
4899: $score = 'correct_by_override';
1.125 ng 4900: } elsif ($newpts ne '') { #empty is taken as 0
1.71 ng 4901: $score = 'incorrect_by_override';
4902: }
1.257 albertel 4903: my $dropMenu = $env{'form.GD_SEL'.$question.'_'.$partid};
1.125 ng 4904: if ($dropMenu eq 'excused') {
1.71 ng 4905: $partial = '';
4906: $score = 'excused';
1.125 ng 4907: } elsif ($dropMenu eq 'reset status'
1.257 albertel 4908: && $env{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
1.125 ng 4909: $newrecord{'resource.'.$partid.'.tries'} = 0;
4910: $newrecord{'resource.'.$partid.'.solved'} = '';
4911: $newrecord{'resource.'.$partid.'.award'} = '';
4912: $newrecord{'resource.'.$partid.'.awarded'} = 0;
1.257 albertel 4913: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 4914: $changeflag++;
4915: $newpts = '';
1.269 raeburn 4916:
4917: my $aggtries = $env{'form.aggtries'.$question.'_'.$partid};
4918: my $totaltries = $env{'form.totaltries'.$question.'_'.$partid};
4919: my $solvedstatus = $env{'form.solved'.$question.'_'.$partid};
4920: if ($aggtries > 0) {
4921: &decrement_aggs($symbx,$partid,\%aggregate,$aggtries,$totaltries,$solvedstatus);
4922: $aggregateflag = 1;
4923: }
1.71 ng 4924: }
1.324 albertel 4925: my $display_part=&get_display_part($partid,$curRes->symb());
1.257 albertel 4926: my $oldstatus = $env{'form.solved'.$question.'_'.$partid};
1.526 raeburn 4927: $displayPts[0].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.71 ng 4928: (($oldstatus eq 'excused') ? 'excused' : $oldpts).
1.326 albertel 4929: ' <br />';
1.526 raeburn 4930: $displayPts[1].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.125 ng 4931: (($score eq 'excused') ? 'excused' : $newpts).
1.326 albertel 4932: ' <br />';
1.71 ng 4933: $question++;
1.380 albertel 4934: next if ($dropMenu eq 'reset status' || ($newpts eq $oldpts && $score ne 'excused'));
1.125 ng 4935:
1.71 ng 4936: $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
1.125 ng 4937: $newrecord{'resource.'.$partid.'.solved'} = $score if $score ne '';
1.257 albertel 4938: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}"
1.125 ng 4939: if (scalar(keys(%newrecord)) > 0);
1.71 ng 4940:
4941: $changeflag++;
4942: }
4943: if (scalar(keys(%newrecord)) > 0) {
1.382 albertel 4944: my %record =
4945: &Apache::lonnet::restore($symbx,$env{'request.course.id'},
4946: $udom,$uname);
4947:
4948: if (&Apache::lonnet::validCODE($env{'form.CODE'})) {
4949: $newrecord{'resource.CODE'} = $env{'form.CODE'};
4950: } elsif (&Apache::lonnet::validCODE($record{'resource.CODE'})) {
4951: $newrecord{'resource.CODE'} = '';
4952: }
1.257 albertel 4953: &Apache::lonnet::cstore(\%newrecord,$symbx,$env{'request.course.id'},
1.71 ng 4954: $udom,$uname);
1.382 albertel 4955: %record = &Apache::lonnet::restore($symbx,
4956: $env{'request.course.id'},
4957: $udom,$uname);
1.380 albertel 4958: &check_and_remove_from_queue($parts,\%record,undef,$symbx,
4959: $cdom,$cnum,$udom,$uname);
1.71 ng 4960: }
1.380 albertel 4961:
1.269 raeburn 4962: if ($aggregateflag) {
4963: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
4964: $env{'course.'.$env{'request.course.id'}.'.domain'},
4965: $env{'course.'.$env{'request.course.id'}.'.num'});
4966: }
1.125 ng 4967:
1.71 ng 4968: $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
4969: '<td valign="top">'.$displayPts[1].'</td>'.
1.484 albertel 4970: &Apache::loncommon::end_data_table_row();
1.68 ng 4971:
1.196 albertel 4972: $prob++;
1.68 ng 4973: }
1.71 ng 4974: $curRes = $iterator->next();
1.68 ng 4975: }
1.98 albertel 4976:
1.484 albertel 4977: $studentTable.=&Apache::loncommon::end_data_table();
1.324 albertel 4978: $studentTable.=&show_grading_menu_form($env{'form.symb'});
1.526 raeburn 4979: my $grademsg=($changeflag == 0 ? &mt('No score was changed or updated.') :
4980: &mt('The scores were changed for [quant,_1,problem].',
4981: $changeflag));
1.76 ng 4982: $request->print($grademsg.$studentTable);
1.68 ng 4983:
1.70 ng 4984: return '';
4985: }
4986:
1.72 ng 4987: #-------- end of section for handling grading by page/sequence ---------
4988: #
4989: #-------------------------------------------------------------------
4990:
1.581 www 4991: #-------------------- Bubblesheet (Scantron) Grading -------------------
1.75 albertel 4992: #
4993: #------ start of section for handling grading by page/sequence ---------
4994:
1.423 albertel 4995: =pod
4996:
4997: =head1 Bubble sheet grading routines
4998:
1.424 albertel 4999: For this documentation:
5000:
5001: 'scanline' refers to the full line of characters
5002: from the file that we are parsing that represents one entire sheet
5003:
5004: 'bubble line' refers to the data
1.596.2.6 raeburn 5005: representing the line of bubbles that are on the physical bubblesheet
1.424 albertel 5006:
5007:
1.596.2.6 raeburn 5008: The overall process is that a scanned in bubblesheet data is uploaded
1.424 albertel 5009: into a course. When a user wants to grade, they select a
1.596.2.6 raeburn 5010: sequence/folder of resources, a file of bubblesheet info, and pick
1.424 albertel 5011: one of the predefined configurations for what each scanline looks
5012: like.
5013:
5014: Next each scanline is checked for any errors of either 'missing
1.435 foxr 5015: bubbles' (it's an error because it may have been mis-scanned
1.424 albertel 5016: because too light bubbling), 'double bubble' (each bubble line should
5017: have no more that one letter picked), invalid or duplicated CODE,
1.556 weissno 5018: invalid student/employee ID
1.424 albertel 5019:
5020: If the CODE option is used that determines the randomization of the
1.556 weissno 5021: homework problems, either way the student/employee ID is looked up into a
1.424 albertel 5022: username:domain.
5023:
5024: During the validation phase the instructor can choose to skip scanlines.
5025:
1.596.2.6 raeburn 5026: After the validation phase, there are now 3 bubblesheet files
1.424 albertel 5027:
5028: scantron_original_filename (unmodified original file)
5029: scantron_corrected_filename (file where the corrected information has replaced the original information)
5030: scantron_skipped_filename (contains the exact text of scanlines that where skipped)
5031:
5032: Also there is a separate hash nohist_scantrondata that contains extra
1.596.2.6 raeburn 5033: correction information that isn't representable in the bubblesheet
1.424 albertel 5034: file (see &scantron_getfile() for more information)
5035:
5036: After all scanlines are either valid, marked as valid or skipped, then
5037: foreach line foreach problem in the picked sequence, an ssi request is
5038: made that simulates a user submitting their selected letter(s) against
5039: the homework problem.
1.423 albertel 5040:
5041: =over 4
5042:
5043:
5044:
5045: =item defaultFormData
5046:
5047: Returns html hidden inputs used to hold context/default values.
5048:
5049: Arguments:
5050: $symb - $symb of the current resource
5051:
5052: =cut
1.422 foxr 5053:
1.81 albertel 5054: sub defaultFormData {
1.324 albertel 5055: my ($symb)=@_;
1.447 foxr 5056: return '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 5057: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
5058: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.81 albertel 5059: }
5060:
1.447 foxr 5061:
1.423 albertel 5062: =pod
5063:
5064: =item getSequenceDropDown
5065:
5066: Return html dropdown of possible sequences to grade
5067:
5068: Arguments:
1.582 raeburn 5069: $symb - $symb of the current resource
5070: $map_error - ref to scalar which will container error if
5071: $navmap object is unavailable in &getSymbMap().
1.423 albertel 5072:
5073: =cut
1.422 foxr 5074:
1.75 albertel 5075: sub getSequenceDropDown {
1.582 raeburn 5076: my ($symb,$map_error)=@_;
1.75 albertel 5077: my $result='<select name="selectpage">'."\n";
1.582 raeburn 5078: my ($titles,$symbx) = &getSymbMap($map_error);
5079: if (ref($map_error)) {
5080: return if ($$map_error);
5081: }
1.137 albertel 5082: my ($curpage)=&Apache::lonnet::decode_symb($symb);
1.75 albertel 5083: my $ctr=0;
5084: foreach (@$titles) {
5085: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
5086: $result.='<option value="'.$$symbx{$_}.'" '.
1.401 albertel 5087: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.75 albertel 5088: '>'.$showtitle.'</option>'."\n";
5089: $ctr++;
5090: }
5091: $result.= '</select>';
5092: return $result;
5093: }
5094:
1.495 albertel 5095: my %bubble_lines_per_response; # no. bubble lines for each response.
1.554 raeburn 5096: # key is zero-based index - 0, 1, 2 ...
1.495 albertel 5097:
5098: my %first_bubble_line; # First bubble line no. for each bubble.
5099:
1.509 raeburn 5100: my %subdivided_bubble_lines; # no. bubble lines for optionresponse,
5101: # matchresponse or rankresponse, where
5102: # an individual response can have multiple
5103: # lines
1.503 raeburn 5104:
5105: my %responsetype_per_response; # responsetype for each response
5106:
1.495 albertel 5107: # Save and restore the bubble lines array to the form env.
5108:
5109:
5110: sub save_bubble_lines {
5111: foreach my $line (keys(%bubble_lines_per_response)) {
5112: $env{"form.scantron.bubblelines.$line"} = $bubble_lines_per_response{$line};
5113: $env{"form.scantron.first_bubble_line.$line"} =
5114: $first_bubble_line{$line};
1.503 raeburn 5115: $env{"form.scantron.sub_bubblelines.$line"} =
5116: $subdivided_bubble_lines{$line};
5117: $env{"form.scantron.responsetype.$line"} =
5118: $responsetype_per_response{$line};
1.495 albertel 5119: }
5120: }
5121:
5122:
5123: sub restore_bubble_lines {
5124: my $line = 0;
5125: %bubble_lines_per_response = ();
5126: while ($env{"form.scantron.bubblelines.$line"}) {
5127: my $value = $env{"form.scantron.bubblelines.$line"};
5128: $bubble_lines_per_response{$line} = $value;
5129: $first_bubble_line{$line} =
5130: $env{"form.scantron.first_bubble_line.$line"};
1.503 raeburn 5131: $subdivided_bubble_lines{$line} =
5132: $env{"form.scantron.sub_bubblelines.$line"};
5133: $responsetype_per_response{$line} =
5134: $env{"form.scantron.responsetype.$line"};
1.495 albertel 5135: $line++;
5136: }
5137: }
5138:
5139: # Given the parsed scanline, get the response for
5140: # 'answer' number n:
5141:
5142: sub get_response_bubbles {
5143: my ($parsed_line, $response) = @_;
5144:
5145: my $bubble_line = $first_bubble_line{$response-1} +1;
5146: my $bubble_lines= $bubble_lines_per_response{$response-1};
5147:
5148: my $selected = "";
5149:
5150: for (my $bline = 0; $bline < $bubble_lines; $bline++) {
5151: $selected .= $$parsed_line{"scantron.$bubble_line.answer"}.":";
5152: $bubble_line++;
5153: }
5154: return $selected;
5155: }
1.423 albertel 5156:
5157: =pod
5158:
5159: =item scantron_filenames
5160:
5161: Returns a list of the scantron files in the current course
5162:
5163: =cut
1.422 foxr 5164:
1.202 albertel 5165: sub scantron_filenames {
1.257 albertel 5166: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5167: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
1.517 raeburn 5168: my $getpropath = 1;
1.596.2.12.2. (raeburn 5169:): my ($dirlist,$listerror) = &Apache::lonnet::dirlist('userfiles',$cdom,
5170:): $cname,$getpropath);
1.202 albertel 5171: my @possiblenames;
1.596.2.12.2. (raeburn 5172:): if (ref($dirlist) eq 'ARRAY') {
5173:): foreach my $filename (sort(@{$dirlist})) {
5174:): ($filename)=split(/&/,$filename);
5175:): if ($filename!~/^scantron_orig_/) { next ; }
5176:): $filename=~s/^scantron_orig_//;
5177:): push(@possiblenames,$filename);
5178:): }
1.202 albertel 5179: }
5180: return @possiblenames;
5181: }
5182:
1.423 albertel 5183: =pod
5184:
5185: =item scantron_uploads
5186:
5187: Returns html drop-down list of scantron files in current course.
5188:
5189: Arguments:
5190: $file2grade - filename to set as selected in the dropdown
5191:
5192: =cut
1.422 foxr 5193:
1.202 albertel 5194: sub scantron_uploads {
1.209 ng 5195: my ($file2grade) = @_;
1.202 albertel 5196: my $result= '<select name="scantron_selectfile">';
5197: $result.="<option></option>";
5198: foreach my $filename (sort(&scantron_filenames())) {
1.401 albertel 5199: $result.="<option".($filename eq $file2grade ? ' selected="selected"':'').">$filename</option>\n";
1.81 albertel 5200: }
5201: $result.="</select>";
5202: return $result;
5203: }
5204:
1.423 albertel 5205: =pod
5206:
5207: =item scantron_scantab
5208:
5209: Returns html drop down of the scantron formats in the scantronformat.tab
5210: file.
5211:
5212: =cut
1.422 foxr 5213:
1.82 albertel 5214: sub scantron_scantab {
5215: my $result='<select name="scantron_format">'."\n";
1.191 albertel 5216: $result.='<option></option>'."\n";
1.518 raeburn 5217: my @lines = &get_scantronformat_file();
5218: if (@lines > 0) {
5219: foreach my $line (@lines) {
5220: next if (($line =~ /^\#/) || ($line eq ''));
5221: my ($name,$descrip)=split(/:/,$line);
5222: $result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
5223: }
1.82 albertel 5224: }
5225: $result.='</select>'."\n";
1.518 raeburn 5226: return $result;
5227: }
5228:
5229: =pod
5230:
5231: =item get_scantronformat_file
5232:
5233: Returns an array containing lines from the scantron format file for
5234: the domain of the course.
5235:
5236: If a url for a custom.tab file is listed in domain's configuration.db,
5237: lines are from this file.
5238:
5239: Otherwise, if a default.tab has been published in RES space by the
5240: domainconfig user, lines are from this file.
5241:
5242: Otherwise, fall back to getting lines from the legacy file on the
1.519 raeburn 5243: local server: /home/httpd/lonTabs/default_scantronformat.tab
1.82 albertel 5244:
1.518 raeburn 5245: =cut
5246:
5247: sub get_scantronformat_file {
5248: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
5249: my %domconfig = &Apache::lonnet::get_dom('configuration',['scantron'],$cdom);
5250: my $gottab = 0;
5251: my @lines;
5252: if (ref($domconfig{'scantron'}) eq 'HASH') {
5253: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
5254: my $formatfile = &Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.$domconfig{'scantron'}{'scantronformat'});
5255: if ($formatfile ne '-1') {
5256: @lines = split("\n",$formatfile,-1);
5257: $gottab = 1;
5258: }
5259: }
5260: }
5261: if (!$gottab) {
5262: my $confname = $cdom.'-domainconfig';
5263: my $default = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res/'.$cdom.'/'.$confname.'/default.tab';
5264: my $formatfile = &Apache::lonnet::getfile($default);
5265: if ($formatfile ne '-1') {
5266: @lines = split("\n",$formatfile,-1);
5267: $gottab = 1;
5268: }
5269: }
5270: if (!$gottab) {
1.519 raeburn 5271: my @domains = &Apache::lonnet::current_machine_domains();
5272: if (grep(/^\Q$cdom\E$/,@domains)) {
5273: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
5274: @lines = <$fh>;
5275: close($fh);
5276: } else {
5277: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab');
5278: @lines = <$fh>;
5279: close($fh);
5280: }
1.518 raeburn 5281: }
5282: return @lines;
1.82 albertel 5283: }
5284:
1.423 albertel 5285: =pod
5286:
5287: =item scantron_CODElist
5288:
5289: Returns html drop down of the saved CODE lists from current course,
5290: generated from earlier printings.
5291:
5292: =cut
1.422 foxr 5293:
1.186 albertel 5294: sub scantron_CODElist {
1.257 albertel 5295: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5296: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.186 albertel 5297: my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
5298: my $namechoice='<option></option>';
1.225 albertel 5299: foreach my $name (sort {uc($a) cmp uc($b)} @names) {
1.191 albertel 5300: if ($name =~ /^error: 2 /) { next; }
1.278 albertel 5301: if ($name =~ /^type\0/) { next; }
1.186 albertel 5302: $namechoice.='<option value="'.$name.'">'.$name.'</option>';
5303: }
5304: $namechoice='<select name="scantron_CODElist">'.$namechoice.'</select>';
5305: return $namechoice;
5306: }
5307:
1.423 albertel 5308: =pod
5309:
5310: =item scantron_CODEunique
5311:
5312: Returns the html for "Each CODE to be used once" radio.
5313:
5314: =cut
1.422 foxr 5315:
1.186 albertel 5316: sub scantron_CODEunique {
1.532 bisitz 5317: my $result='<span class="LC_nobreak">
1.272 albertel 5318: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 5319: value="yes" checked="checked" />'.&mt('Yes').' </label>
1.381 albertel 5320: </span>
1.532 bisitz 5321: <span class="LC_nobreak">
1.272 albertel 5322: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 5323: value="no" />'.&mt('No').' </label>
1.381 albertel 5324: </span>';
1.186 albertel 5325: return $result;
5326: }
1.423 albertel 5327:
5328: =pod
5329:
5330: =item scantron_selectphase
5331:
1.596.2.6 raeburn 5332: Generates the initial screen to start the bubblesheet process.
1.423 albertel 5333: Allows for - starting a grading run.
1.424 albertel 5334: - downloading existing scan data (original, corrected
1.423 albertel 5335: or skipped info)
5336:
5337: - uploading new scan data
5338:
5339: Arguments:
5340: $r - The Apache request object
5341: $file2grade - name of the file that contain the scanned data to score
5342:
5343: =cut
1.186 albertel 5344:
1.75 albertel 5345: sub scantron_selectphase {
1.209 ng 5346: my ($r,$file2grade) = @_;
1.324 albertel 5347: my ($symb)=&get_symb($r);
1.75 albertel 5348: if (!$symb) {return '';}
1.582 raeburn 5349: my $map_error;
5350: my $sequence_selector=&getSequenceDropDown($symb,\$map_error);
5351: if ($map_error) {
5352: $r->print('<br />'.&navmap_errormsg().'<br />');
5353: return;
5354: }
1.324 albertel 5355: my $default_form_data=&defaultFormData($symb);
5356: my $grading_menu_button=&show_grading_menu_form($symb);
1.209 ng 5357: my $file_selector=&scantron_uploads($file2grade);
1.82 albertel 5358: my $format_selector=&scantron_scantab();
1.186 albertel 5359: my $CODE_selector=&scantron_CODElist();
5360: my $CODE_unique=&scantron_CODEunique();
1.75 albertel 5361: my $result;
1.422 foxr 5362:
1.513 foxr 5363: $ssi_error = 0;
5364:
1.596.2.4 raeburn 5365: if (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) ||
5366: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
5367:
5368: # Chunk of form to prompt for a scantron file upload.
5369:
5370: $r->print('
5371: <br />
5372: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5373: '.&Apache::loncommon::start_data_table_header_row().'
5374: <th>
5375: '.&mt('Specify a bubblesheet data file to upload.').'
5376: </th>
5377: '.&Apache::loncommon::end_data_table_header_row().'
5378: '.&Apache::loncommon::start_data_table_row().'
5379: <td>
5380: ');
5381: my $default_form_data=&defaultFormData(&get_symb($r,1));
5382: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
5383: my $cnum= $env{'course.'.$env{'request.course.id'}.'.num'};
5384: $r->print('
5385: <script type="text/javascript" language="javascript">
5386: function checkUpload(formname) {
5387: if (formname.upfile.value == "") {
5388: alert("'.&mt('Please use the browse button to select a file from your local directory.').'");
5389: return false;
5390: }
5391: formname.submit();
5392: }
5393: </script>
5394:
5395: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
5396: '.$default_form_data.'
5397: <input name="courseid" type="hidden" value="'.$cnum.'" />
5398: <input name="domainid" type="hidden" value="'.$cdom.'" />
5399: <input name="command" value="scantronupload_save" type="hidden" />
5400: '.&mt('File to upload: [_1]','<input type="file" name="upfile" size="50" />').'
5401: <br />
5402: <input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
5403: </form>
5404: ');
5405:
5406: $r->print('
5407: </td>
5408: '.&Apache::loncommon::end_data_table_row().'
5409: '.&Apache::loncommon::end_data_table().'
5410: ');
5411: }
5412:
1.422 foxr 5413: # Chunk of form to prompt for a file to grade and how:
5414:
1.489 albertel 5415: $result.= '
5416: <br />
5417: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantron_process">
5418: <input type="hidden" name="command" value="scantron_warning" />
5419: '.$default_form_data.'
5420: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5421: '.&Apache::loncommon::start_data_table_header_row().'
5422: <th colspan="2">
1.492 albertel 5423: '.&mt('Specify file and which Folder/Sequence to grade').'
1.489 albertel 5424: </th>
5425: '.&Apache::loncommon::end_data_table_header_row().'
5426: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5427: <td> '.&mt('Sequence to grade:').' </td><td> '.$sequence_selector.' </td>
1.489 albertel 5428: '.&Apache::loncommon::end_data_table_row().'
5429: '.&Apache::loncommon::start_data_table_row().'
1.572 www 5430: <td> '.&mt('Filename of bubblesheet data file:').' </td><td> '.$file_selector.' </td>
1.489 albertel 5431: '.&Apache::loncommon::end_data_table_row().'
5432: '.&Apache::loncommon::start_data_table_row().'
1.572 www 5433: <td> '.&mt('Format of bubblesheet data file:').' </td><td> '.$format_selector.' </td>
1.489 albertel 5434: '.&Apache::loncommon::end_data_table_row().'
5435: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5436: <td> '.&mt('Saved CODEs to validate against:').' </td><td> '.$CODE_selector.' </td>
1.489 albertel 5437: '.&Apache::loncommon::end_data_table_row().'
5438: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5439: <td> '.&mt('Each CODE is only to be used once:').'</td><td> '.$CODE_unique.' </td>
1.489 albertel 5440: '.&Apache::loncommon::end_data_table_row().'
5441: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5442: <td> '.&mt('Options:').' </td>
1.187 albertel 5443: <td>
1.492 albertel 5444: <label><input type="checkbox" name="scantron_options_redo" value="redo_skipped"/> '.&mt('Do only previously skipped records').'</label> <br />
5445: <label><input type="checkbox" name="scantron_options_ignore" value="ignore_corrections"/> '.&mt('Remove all existing corrections').'</label> <br />
5446: <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources when grading').'</label>
1.187 albertel 5447: </td>
1.489 albertel 5448: '.&Apache::loncommon::end_data_table_row().'
5449: '.&Apache::loncommon::start_data_table_row().'
1.174 albertel 5450: <td colspan="2">
1.572 www 5451: <input type="submit" value="'.&mt('Grading: Validate Bubblesheet Records').'" />
1.162 albertel 5452: </td>
1.489 albertel 5453: '.&Apache::loncommon::end_data_table_row().'
5454: '.&Apache::loncommon::end_data_table().'
5455: </form>
5456: ';
1.162 albertel 5457:
5458: $r->print($result);
5459:
1.422 foxr 5460: # Chunk of the form that prompts to view a scoring office file,
5461: # corrected file, skipped records in a file.
5462:
1.489 albertel 5463: $r->print('
5464: <br />
5465: <form action="/adm/grades" name="scantron_download">
5466: '.$default_form_data.'
5467: <input type="hidden" name="command" value="scantron_download" />
5468: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5469: '.&Apache::loncommon::start_data_table_header_row().'
5470: <th>
1.492 albertel 5471: '.&mt('Download a scoring office file').'
1.489 albertel 5472: </th>
5473: '.&Apache::loncommon::end_data_table_header_row().'
5474: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5475: <td> '.&mt('Filename of scoring office file: [_1]',$file_selector).'
1.489 albertel 5476: <br />
1.492 albertel 5477: <input type="submit" value="'.&mt('Download: Show List of Associated Files').'" />
1.489 albertel 5478: '.&Apache::loncommon::end_data_table_row().'
5479: '.&Apache::loncommon::end_data_table().'
5480: </form>
5481: <br />
5482: ');
1.162 albertel 5483:
1.457 banghart 5484: &Apache::lonpickcode::code_list($r,2);
1.523 raeburn 5485:
1.528 raeburn 5486: $r->print('<br /><form method="post" name="checkscantron">'.
1.523 raeburn 5487: $default_form_data."\n".
5488: &Apache::loncommon::start_data_table('LC_scantron_action')."\n".
5489: &Apache::loncommon::start_data_table_header_row()."\n".
5490: '<th colspan="2">
1.572 www 5491: '.&mt('Review bubblesheet data and submissions for a previously graded folder/sequence')."\n".
1.523 raeburn 5492: '</th>'."\n".
5493: &Apache::loncommon::end_data_table_header_row()."\n".
5494: &Apache::loncommon::start_data_table_row()."\n".
5495: '<td> '.&mt('Graded folder/sequence:').' </td>'."\n".
5496: '<td> '.$sequence_selector.' </td>'.
5497: &Apache::loncommon::end_data_table_row()."\n".
5498: &Apache::loncommon::start_data_table_row()."\n".
5499: '<td> '.&mt('Filename of scoring office file:').' </td>'."\n".
5500: '<td> '.$file_selector.' </td>'."\n".
5501: &Apache::loncommon::end_data_table_row()."\n".
5502: &Apache::loncommon::start_data_table_row()."\n".
5503: '<td> '.&mt('Format of data file:').' </td>'."\n".
5504: '<td> '.$format_selector.' </td>'."\n".
5505: &Apache::loncommon::end_data_table_row()."\n".
5506: &Apache::loncommon::start_data_table_row()."\n".
1.557 raeburn 5507: '<td> '.&mt('Options').' </td>'."\n".
5508: '<td> <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources').'</label></td>'.
5509: &Apache::loncommon::end_data_table_row()."\n".
5510: &Apache::loncommon::start_data_table_row()."\n".
1.523 raeburn 5511: '<td colspan="2">'."\n".
5512: '<input type="hidden" name="command" value="checksubmissions" />'."\n".
1.575 www 5513: '<input type="submit" value="'.&mt('Review Bubblesheet Data and Submission Records').'" />'."\n".
1.523 raeburn 5514: '</td>'."\n".
5515: &Apache::loncommon::end_data_table_row()."\n".
5516: &Apache::loncommon::end_data_table()."\n".
5517: '</form><br />');
1.457 banghart 5518: $r->print($grading_menu_button);
1.523 raeburn 5519: return;
1.75 albertel 5520: }
5521:
1.423 albertel 5522: =pod
5523:
5524: =item get_scantron_config
5525:
5526: Parse and return the scantron configuration line selected as a
5527: hash of configuration file fields.
5528:
5529: Arguments:
5530: which - the name of the configuration to parse from the file.
5531:
5532:
5533: Returns:
5534: If the named configuration is not in the file, an empty
5535: hash is returned.
5536: a hash with the fields
5537: name - internal name for the this configuration setup
5538: description - text to display to operator that describes this config
5539: CODElocation - if 0 or the string 'none'
5540: - no CODE exists for this config
5541: if -1 || the string 'letter'
5542: - a CODE exists for this config and is
5543: a string of letters
5544: Unsupported value (but planned for future support)
5545: if a positive integer
5546: - The CODE exists as the first n items from
5547: the question section of the form
5548: if the string 'number'
5549: - The CODE exists for this config and is
5550: a string of numbers
5551: CODEstart - (only matter if a CODE exists) column in the line where
5552: the CODE starts
5553: CODElength - length of the CODE
1.573 bisitz 5554: IDstart - column where the student/employee ID starts
1.556 weissno 5555: IDlength - length of the student/employee ID info
1.423 albertel 5556: Qstart - column where the information from the bubbled
5557: 'questions' start
5558: Qlength - number of columns comprising a single bubble line from
5559: the sheet. (usually either 1 or 10)
1.424 albertel 5560: Qon - either a single character representing the character used
1.423 albertel 5561: to signal a bubble was chosen in the positional setup, or
5562: the string 'letter' if the letter of the chosen bubble is
5563: in the final, or 'number' if a number representing the
5564: chosen bubble is in the file (1->A 0->J)
1.424 albertel 5565: Qoff - the character used to represent that a bubble was
5566: left blank
1.423 albertel 5567: PaperID - if the scanning process generates a unique number for each
5568: sheet scanned the column that this ID number starts in
5569: PaperIDlength - number of columns that comprise the unique ID number
5570: for the sheet of paper
1.424 albertel 5571: FirstName - column that the first name starts in
1.423 albertel 5572: FirstNameLength - number of columns that the first name spans
5573:
5574: LastName - column that the last name starts in
5575: LastNameLength - number of columns that the last name spans
1.596.2.12.2. (raeburn 5576:): BubblesPerRow - number of bubbles available in each row used to
5577:): bubble an answer. (If not specified, 10 assumed).
1.423 albertel 5578:
5579: =cut
1.422 foxr 5580:
1.82 albertel 5581: sub get_scantron_config {
5582: my ($which) = @_;
1.518 raeburn 5583: my @lines = &get_scantronformat_file();
1.82 albertel 5584: my %config;
1.157 albertel 5585: #FIXME probably should move to XML it has already gotten a bit much now
1.518 raeburn 5586: foreach my $line (@lines) {
1.82 albertel 5587: my ($name,$descrip)=split(/:/,$line);
5588: if ($name ne $which ) { next; }
5589: chomp($line);
5590: my @config=split(/:/,$line);
5591: $config{'name'}=$config[0];
5592: $config{'description'}=$config[1];
5593: $config{'CODElocation'}=$config[2];
5594: $config{'CODEstart'}=$config[3];
5595: $config{'CODElength'}=$config[4];
5596: $config{'IDstart'}=$config[5];
5597: $config{'IDlength'}=$config[6];
5598: $config{'Qstart'}=$config[7];
1.497 foxr 5599: $config{'Qlength'}=$config[8];
1.82 albertel 5600: $config{'Qoff'}=$config[9];
5601: $config{'Qon'}=$config[10];
1.157 albertel 5602: $config{'PaperID'}=$config[11];
5603: $config{'PaperIDlength'}=$config[12];
5604: $config{'FirstName'}=$config[13];
5605: $config{'FirstNamelength'}=$config[14];
5606: $config{'LastName'}=$config[15];
5607: $config{'LastNamelength'}=$config[16];
1.596.2.12.2. (raeburn 5608:): $config{'BubblesPerRow'}=$config[17];
1.82 albertel 5609: last;
5610: }
5611: return %config;
5612: }
5613:
1.423 albertel 5614: =pod
5615:
5616: =item username_to_idmap
5617:
1.556 weissno 5618: creates a hash keyed by student/employee ID with values of the corresponding
1.423 albertel 5619: student username:domain.
5620:
5621: Arguments:
5622:
5623: $classlist - reference to the class list hash. This is a hash
5624: keyed by student name:domain whose elements are references
1.424 albertel 5625: to arrays containing various chunks of information
1.423 albertel 5626: about the student. (See loncoursedata for more info).
5627:
5628: Returns
5629: %idmap - the constructed hash
5630:
5631: =cut
5632:
1.82 albertel 5633: sub username_to_idmap {
5634: my ($classlist)= @_;
5635: my %idmap;
5636: foreach my $student (keys(%$classlist)) {
5637: $idmap{$classlist->{$student}->[&Apache::loncoursedata::CL_ID]}=
5638: $student;
5639: }
5640: return %idmap;
5641: }
1.423 albertel 5642:
5643: =pod
5644:
1.424 albertel 5645: =item scantron_fixup_scanline
1.423 albertel 5646:
5647: Process a requested correction to a scanline.
5648:
5649: Arguments:
5650: $scantron_config - hash from &get_scantron_config()
5651: $scan_data - hash of correction information
5652: (see &scantron_getfile())
5653: $line - existing scanline
5654: $whichline - line number of the passed in scanline
5655: $field - type of change to process
5656: (either
1.573 bisitz 5657: 'ID' -> correct the student/employee ID
1.423 albertel 5658: 'CODE' -> correct the CODE
5659: 'answer' -> fixup the submitted answers)
5660:
5661: $args - hash of additional info,
5662: - 'ID'
5663: 'newid' -> studentID to use in replacement
1.424 albertel 5664: of existing one
1.423 albertel 5665: - 'CODE'
5666: 'CODE_ignore_dup' - set to true if duplicates
5667: should be ignored.
5668: 'CODE' - is new code or 'use_unfound'
1.424 albertel 5669: if the existing unfound code should
1.423 albertel 5670: be used as is
5671: - 'answer'
5672: 'response' - new answer or 'none' if blank
5673: 'question' - the bubble line to change
1.503 raeburn 5674: 'questionnum' - the question identifier,
5675: may include subquestion.
1.423 albertel 5676:
5677: Returns:
5678: $line - the modified scanline
5679:
5680: Side effects:
5681: $scan_data - may be updated
5682:
5683: =cut
5684:
1.82 albertel 5685:
1.157 albertel 5686: sub scantron_fixup_scanline {
5687: my ($scantron_config,$scan_data,$line,$whichline,$field,$args)=@_;
5688: if ($field eq 'ID') {
5689: if (length($args->{'newid'}) > $$scantron_config{'IDlength'}) {
1.186 albertel 5690: return ($line,1,'New value too large');
1.157 albertel 5691: }
5692: if (length($args->{'newid'}) < $$scantron_config{'IDlength'}) {
5693: $args->{'newid'}=sprintf('%-'.$$scantron_config{'IDlength'}.'s',
5694: $args->{'newid'});
5695: }
5696: substr($line,$$scantron_config{'IDstart'}-1,
5697: $$scantron_config{'IDlength'})=$args->{'newid'};
5698: if ($args->{'newid'}=~/^\s*$/) {
5699: &scan_data($scan_data,"$whichline.user",
5700: $args->{'username'}.':'.$args->{'domain'});
5701: }
1.186 albertel 5702: } elsif ($field eq 'CODE') {
1.192 albertel 5703: if ($args->{'CODE_ignore_dup'}) {
5704: &scan_data($scan_data,"$whichline.CODE_ignore_dup",'1');
5705: }
5706: &scan_data($scan_data,"$whichline.useCODE",'1');
5707: if ($args->{'CODE'} ne 'use_unfound') {
1.191 albertel 5708: if (length($args->{'CODE'}) > $$scantron_config{'CODElength'}) {
5709: return ($line,1,'New CODE value too large');
5710: }
5711: if (length($args->{'CODE'}) < $$scantron_config{'CODElength'}) {
5712: $args->{'CODE'}=sprintf('%-'.$$scantron_config{'CODElength'}.'s',$args->{'CODE'});
5713: }
5714: substr($line,$$scantron_config{'CODEstart'}-1,
5715: $$scantron_config{'CODElength'})=$args->{'CODE'};
1.186 albertel 5716: }
1.157 albertel 5717: } elsif ($field eq 'answer') {
1.497 foxr 5718: my $length=$scantron_config->{'Qlength'};
1.157 albertel 5719: my $off=$scantron_config->{'Qoff'};
5720: my $on=$scantron_config->{'Qon'};
1.497 foxr 5721: my $answer=${off}x$length;
5722: if ($args->{'response'} eq 'none') {
5723: &scan_data($scan_data,
1.503 raeburn 5724: "$whichline.no_bubble.".$args->{'questionnum'},'1');
1.497 foxr 5725: } else {
5726: if ($on eq 'letter') {
5727: my @alphabet=('A'..'Z');
5728: $answer=$alphabet[$args->{'response'}];
5729: } elsif ($on eq 'number') {
5730: $answer=$args->{'response'}+1;
5731: if ($answer == 10) { $answer = '0'; }
1.274 albertel 5732: } else {
1.497 foxr 5733: substr($answer,$args->{'response'},1)=$on;
1.274 albertel 5734: }
1.497 foxr 5735: &scan_data($scan_data,
1.503 raeburn 5736: "$whichline.no_bubble.".$args->{'questionnum'},undef,'1');
1.157 albertel 5737: }
1.497 foxr 5738: my $where=$length*($args->{'question'}-1)+$scantron_config->{'Qstart'};
5739: substr($line,$where-1,$length)=$answer;
1.157 albertel 5740: }
5741: return $line;
5742: }
1.423 albertel 5743:
5744: =pod
5745:
5746: =item scan_data
5747:
5748: Edit or look up an item in the scan_data hash.
5749:
5750: Arguments:
5751: $scan_data - The hash (see scantron_getfile)
5752: $key - shorthand of the key to edit (actual key is
1.424 albertel 5753: scantronfilename_key).
1.423 albertel 5754: $data - New value of the hash entry.
5755: $delete - If true, the entry is removed from the hash.
5756:
5757: Returns:
5758: The new value of the hash table field (undefined if deleted).
5759:
5760: =cut
5761:
5762:
1.157 albertel 5763: sub scan_data {
5764: my ($scan_data,$key,$value,$delete)=@_;
1.257 albertel 5765: my $filename=$env{'form.scantron_selectfile'};
1.157 albertel 5766: if (defined($value)) {
5767: $scan_data->{$filename.'_'.$key} = $value;
5768: }
5769: if ($delete) { delete($scan_data->{$filename.'_'.$key}); }
5770: return $scan_data->{$filename.'_'.$key};
5771: }
1.423 albertel 5772:
1.495 albertel 5773: # ----- These first few routines are general use routines.----
5774:
5775: # Return the number of occurences of a pattern in a string.
5776:
5777: sub occurence_count {
5778: my ($string, $pattern) = @_;
5779:
5780: my @matches = ($string =~ /$pattern/g);
5781:
5782: return scalar(@matches);
5783: }
5784:
5785:
5786: # Take a string known to have digits and convert all the
5787: # digits into letters in the range J,A..I.
5788:
5789: sub digits_to_letters {
5790: my ($input) = @_;
5791:
5792: my @alphabet = ('J', 'A'..'I');
5793:
5794: my @input = split(//, $input);
5795: my $output ='';
5796: for (my $i = 0; $i < scalar(@input); $i++) {
5797: if ($input[$i] =~ /\d/) {
5798: $output .= $alphabet[$input[$i]];
5799: } else {
5800: $output .= $input[$i];
5801: }
5802: }
5803: return $output;
5804: }
5805:
1.423 albertel 5806: =pod
5807:
5808: =item scantron_parse_scanline
5809:
5810: Decodes a scanline from the selected scantron file
5811:
5812: Arguments:
5813: line - The text of the scantron file line to process
5814: whichline - Line number
5815: scantron_config - Hash describing the format of the scantron lines.
5816: scan_data - Hash of extra information about the scanline
5817: (see scantron_getfile for more information)
5818: just_header - True if should not process question answers but only
5819: the stuff to the left of the answers.
5820: Returns:
5821: Hash containing the result of parsing the scanline
5822:
5823: Keys are all proceeded by the string 'scantron.'
5824:
5825: CODE - the CODE in use for this scanline
5826: useCODE - 1 if the CODE is invalid but it usage has been forced
5827: by the operator
5828: CODE_ignore_dup - 1 if the CODE is a duplicated use when unique
5829: CODEs were selected, but the usage has been
5830: forced by the operator
1.556 weissno 5831: ID - student/employee ID
1.423 albertel 5832: PaperID - if used, the ID number printed on the sheet when the
5833: paper was scanned
5834: FirstName - first name from the sheet
5835: LastName - last name from the sheet
5836:
5837: if just_header was not true these key may also exist
5838:
1.447 foxr 5839: missingerror - a list of bubble ranges that are considered to be answers
5840: to a single question that don't have any bubbles filled in.
5841: Of the form questionnumber:firstbubblenumber:count.
5842: doubleerror - a list of bubble ranges that are considered to be answers
5843: to a single question that have more than one bubble filled in.
5844: Of the form questionnumber::firstbubblenumber:count
5845:
5846: In the above, count is the number of bubble responses in the
5847: input line needed to represent the possible answers to the question.
5848: e.g. a radioresponse with 15 choices in an answer sheet with 10 choices
5849: per line would have count = 2.
5850:
1.423 albertel 5851: maxquest - the number of the last bubble line that was parsed
5852:
5853: (<number> starts at 1)
5854: <number>.answer - zero or more letters representing the selected
5855: letters from the scanline for the bubble line
5856: <number>.
5857: if blank there was either no bubble or there where
5858: multiple bubbles, (consult the keys missingerror and
5859: doubleerror if this is an error condition)
5860:
5861: =cut
5862:
1.82 albertel 5863: sub scantron_parse_scanline {
1.423 albertel 5864: my ($line,$whichline,$scantron_config,$scan_data,$just_header)=@_;
1.470 foxr 5865:
1.82 albertel 5866: my %record;
1.550 raeburn 5867: my $lastpos = $env{'form.scantron_maxbubble'}*$$scantron_config{'Qlength'};
5868: my $questions=substr($line,$$scantron_config{'Qstart'}-1,$lastpos); # Answers
1.422 foxr 5869: my $data=substr($line,0,$$scantron_config{'Qstart'}-1); # earlier stuff
1.278 albertel 5870: if (!($$scantron_config{'CODElocation'} eq 0 ||
5871: $$scantron_config{'CODElocation'} eq 'none')) {
5872: if ($$scantron_config{'CODElocation'} < 0 ||
5873: $$scantron_config{'CODElocation'} eq 'letter' ||
5874: $$scantron_config{'CODElocation'} eq 'number') {
1.191 albertel 5875: $record{'scantron.CODE'}=substr($data,
5876: $$scantron_config{'CODEstart'}-1,
1.83 albertel 5877: $$scantron_config{'CODElength'});
1.191 albertel 5878: if (&scan_data($scan_data,"$whichline.useCODE")) {
5879: $record{'scantron.useCODE'}=1;
5880: }
1.192 albertel 5881: if (&scan_data($scan_data,"$whichline.CODE_ignore_dup")) {
5882: $record{'scantron.CODE_ignore_dup'}=1;
5883: }
1.82 albertel 5884: } else {
5885: #FIXME interpret first N questions
5886: }
5887: }
1.83 albertel 5888: $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
5889: $$scantron_config{'IDlength'});
1.157 albertel 5890: $record{'scantron.PaperID'}=
5891: substr($data,$$scantron_config{'PaperID'}-1,
5892: $$scantron_config{'PaperIDlength'});
5893: $record{'scantron.FirstName'}=
5894: substr($data,$$scantron_config{'FirstName'}-1,
5895: $$scantron_config{'FirstNamelength'});
5896: $record{'scantron.LastName'}=
5897: substr($data,$$scantron_config{'LastName'}-1,
5898: $$scantron_config{'LastNamelength'});
1.423 albertel 5899: if ($just_header) { return \%record; }
1.194 albertel 5900:
1.82 albertel 5901: my @alphabet=('A'..'Z');
5902: my $questnum=0;
1.447 foxr 5903: my $ansnum =1; # Multiple 'answer lines'/question.
5904:
1.470 foxr 5905: chomp($questions); # Get rid of any trailing \n.
5906: $questions =~ s/\r$//; # Get rid of trailing \r too (MAC or Win uploads).
5907: while (length($questions)) {
1.447 foxr 5908: my $answers_needed = $bubble_lines_per_response{$questnum};
1.503 raeburn 5909: my $answer_length = ($$scantron_config{'Qlength'} * $answers_needed)
5910: || 1;
5911: $questnum++;
5912: my $quest_id = $questnum;
5913: my $currentquest = substr($questions,0,$answer_length);
5914: $questions = substr($questions,$answer_length);
5915: if (length($currentquest) < $answer_length) { next; }
5916:
5917: if ($subdivided_bubble_lines{$questnum-1} =~ /,/) {
5918: my $subquestnum = 1;
5919: my $subquestions = $currentquest;
5920: my @subanswers_needed =
5921: split(/,/,$subdivided_bubble_lines{$questnum-1});
5922: foreach my $subans (@subanswers_needed) {
5923: my $subans_length =
5924: ($$scantron_config{'Qlength'} * $subans) || 1;
5925: my $currsubquest = substr($subquestions,0,$subans_length);
5926: $subquestions = substr($subquestions,$subans_length);
5927: $quest_id = "$questnum.$subquestnum";
5928: if (($$scantron_config{'Qon'} eq 'letter') ||
5929: ($$scantron_config{'Qon'} eq 'number')) {
5930: $ansnum = &scantron_validator_lettnum($ansnum,
5931: $questnum,$quest_id,$subans,$currsubquest,$whichline,
5932: \@alphabet,\%record,$scantron_config,$scan_data);
5933: } else {
5934: $ansnum = &scantron_validator_positional($ansnum,
5935: $questnum,$quest_id,$subans,$currsubquest,$whichline, \@alphabet,\%record,$scantron_config,$scan_data);
5936: }
5937: $subquestnum ++;
5938: }
5939: } else {
5940: if (($$scantron_config{'Qon'} eq 'letter') ||
5941: ($$scantron_config{'Qon'} eq 'number')) {
5942: $ansnum = &scantron_validator_lettnum($ansnum,$questnum,
5943: $quest_id,$answers_needed,$currentquest,$whichline,
5944: \@alphabet,\%record,$scantron_config,$scan_data);
5945: } else {
5946: $ansnum = &scantron_validator_positional($ansnum,$questnum,
5947: $quest_id,$answers_needed,$currentquest,$whichline,
5948: \@alphabet,\%record,$scantron_config,$scan_data);
5949: }
5950: }
5951: }
5952: $record{'scantron.maxquest'}=$questnum;
5953: return \%record;
5954: }
1.447 foxr 5955:
1.503 raeburn 5956: sub scantron_validator_lettnum {
5957: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,$whichline,
5958: $alphabet,$record,$scantron_config,$scan_data) = @_;
5959:
5960: # Qon 'letter' implies for each slot in currquest we have:
5961: # ? or * for doubles, a letter in A-Z for a bubble, and
5962: # about anything else (esp. a value of Qoff) for missing
5963: # bubbles.
5964: #
5965: # Qon 'number' implies each slot gives a digit that indexes the
5966: # bubbles filled, or Qoff, or a non-number for unbubbled lines,
5967: # and * or ? for double bubbles on a single line.
5968: #
1.447 foxr 5969:
1.503 raeburn 5970: my $matchon;
5971: if ($$scantron_config{'Qon'} eq 'letter') {
5972: $matchon = '[A-Z]';
5973: } elsif ($$scantron_config{'Qon'} eq 'number') {
5974: $matchon = '\d';
5975: }
5976: my $occurrences = 0;
5977: if (($responsetype_per_response{$questnum-1} eq 'essayresponse') ||
5978: ($responsetype_per_response{$questnum-1} eq 'formularesponse') ||
1.510 raeburn 5979: ($responsetype_per_response{$questnum-1} eq 'stringresponse') ||
5980: ($responsetype_per_response{$questnum-1} eq 'imageresponse') ||
5981: ($responsetype_per_response{$questnum-1} eq 'reactionresponse') ||
5982: ($responsetype_per_response{$questnum-1} eq 'organicresponse')) {
1.503 raeburn 5983: my @singlelines = split('',$currquest);
5984: foreach my $entry (@singlelines) {
5985: $occurrences = &occurence_count($entry,$matchon);
5986: if ($occurrences > 1) {
5987: last;
5988: }
5989: }
5990: } else {
5991: $occurrences = &occurence_count($currquest,$matchon);
5992: }
5993: if (($currquest =~ /\?/ || $currquest =~ /\*/) || ($occurrences > 1)) {
5994: push(@{$record->{'scantron.doubleerror'}},$quest_id);
5995: for (my $ans=0; $ans<$answers_needed; $ans++) {
5996: my $bubble = substr($currquest,$ans,1);
5997: if ($bubble =~ /$matchon/ ) {
5998: if ($$scantron_config{'Qon'} eq 'number') {
5999: if ($bubble == 0) {
6000: $bubble = 10;
6001: }
6002: $record->{"scantron.$ansnum.answer"} =
6003: $alphabet->[$bubble-1];
6004: } else {
6005: $record->{"scantron.$ansnum.answer"} = $bubble;
6006: }
6007: } else {
6008: $record->{"scantron.$ansnum.answer"}='';
6009: }
6010: $ansnum++;
6011: }
6012: } elsif (!defined($currquest)
6013: || (&occurence_count($currquest, $$scantron_config{'Qoff'}) == length($currquest))
6014: || (&occurence_count($currquest,$matchon) == 0)) {
6015: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
6016: $record->{"scantron.$ansnum.answer"}='';
6017: $ansnum++;
6018: }
6019: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
6020: push(@{$record->{'scantron.missingerror'}},$quest_id);
6021: }
6022: } else {
6023: if ($$scantron_config{'Qon'} eq 'number') {
6024: $currquest = &digits_to_letters($currquest);
6025: }
6026: for (my $ans=0; $ans<$answers_needed; $ans++) {
6027: my $bubble = substr($currquest,$ans,1);
6028: $record->{"scantron.$ansnum.answer"} = $bubble;
6029: $ansnum++;
6030: }
6031: }
6032: return $ansnum;
6033: }
1.447 foxr 6034:
1.503 raeburn 6035: sub scantron_validator_positional {
6036: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,
6037: $whichline,$alphabet,$record,$scantron_config,$scan_data) = @_;
1.447 foxr 6038:
1.503 raeburn 6039: # Otherwise there's a positional notation;
6040: # each bubble line requires Qlength items, and there are filled in
6041: # bubbles for each case where there 'Qon' characters.
6042: #
1.447 foxr 6043:
1.503 raeburn 6044: my @array=split($$scantron_config{'Qon'},$currquest,-1);
1.447 foxr 6045:
1.503 raeburn 6046: # If the split only gives us one element.. the full length of the
6047: # answer string, no bubbles are filled in:
1.447 foxr 6048:
1.507 raeburn 6049: if ($answers_needed eq '') {
6050: return;
6051: }
6052:
1.503 raeburn 6053: if (length($array[0]) eq $$scantron_config{'Qlength'}*$answers_needed) {
6054: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
6055: $record->{"scantron.$ansnum.answer"}='';
6056: $ansnum++;
6057: }
6058: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
6059: push(@{$record->{"scantron.missingerror"}},$quest_id);
6060: }
6061: } elsif (scalar(@array) == 2) {
6062: my $location = length($array[0]);
6063: my $line_num = int($location / $$scantron_config{'Qlength'});
6064: my $bubble = $alphabet->[$location % $$scantron_config{'Qlength'}];
6065: for (my $ans=0; $ans<$answers_needed; $ans++) {
6066: if ($ans eq $line_num) {
6067: $record->{"scantron.$ansnum.answer"} = $bubble;
6068: } else {
6069: $record->{"scantron.$ansnum.answer"} = ' ';
6070: }
6071: $ansnum++;
6072: }
6073: } else {
6074: # If there's more than one instance of a bubble character
6075: # That's a double bubble; with positional notation we can
6076: # record all the bubbles filled in as well as the
6077: # fact this response consists of multiple bubbles.
6078: #
6079: if (($responsetype_per_response{$questnum-1} eq 'essayresponse') ||
6080: ($responsetype_per_response{$questnum-1} eq 'formularesponse') ||
1.510 raeburn 6081: ($responsetype_per_response{$questnum-1} eq 'stringresponse') ||
6082: ($responsetype_per_response{$questnum-1} eq 'imageresponse') ||
6083: ($responsetype_per_response{$questnum-1} eq 'reactionresponse') ||
6084: ($responsetype_per_response{$questnum-1} eq 'organicresponse')) {
1.503 raeburn 6085: my $doubleerror = 0;
6086: while (($currquest >= $$scantron_config{'Qlength'}) &&
6087: (!$doubleerror)) {
6088: my $currline = substr($currquest,0,$$scantron_config{'Qlength'});
6089: $currquest = substr($currquest,$$scantron_config{'Qlength'});
6090: my @currarray = split($$scantron_config{'Qon'},$currline,-1);
6091: if (length(@currarray) > 2) {
6092: $doubleerror = 1;
6093: }
6094: }
6095: if ($doubleerror) {
6096: push(@{$record->{'scantron.doubleerror'}},$quest_id);
6097: }
6098: } else {
6099: push(@{$record->{'scantron.doubleerror'}},$quest_id);
6100: }
6101: my $item = $ansnum;
6102: for (my $ans=0; $ans<$answers_needed; $ans++) {
6103: $record->{"scantron.$item.answer"} = '';
6104: $item ++;
6105: }
1.447 foxr 6106:
1.503 raeburn 6107: my @ans=@array;
6108: my $i=0;
6109: my $increment = 0;
6110: while ($#ans) {
6111: $i+=length($ans[0]) + $increment;
6112: my $line = int($i/$$scantron_config{'Qlength'} + $ansnum);
6113: my $bubble = $i%$$scantron_config{'Qlength'};
6114: $record->{"scantron.$line.answer"}.=$alphabet->[$bubble];
6115: shift(@ans);
6116: $increment = 1;
6117: }
6118: $ansnum += $answers_needed;
1.82 albertel 6119: }
1.503 raeburn 6120: return $ansnum;
1.82 albertel 6121: }
6122:
1.423 albertel 6123: =pod
6124:
6125: =item scantron_add_delay
6126:
6127: Adds an error message that occurred during the grading phase to a
6128: queue of messages to be shown after grading pass is complete
6129:
6130: Arguments:
1.424 albertel 6131: $delayqueue - arrary ref of hash ref of error messages
1.423 albertel 6132: $scanline - the scanline that caused the error
6133: $errormesage - the error message
6134: $errorcode - a numeric code for the error
6135:
6136: Side Effects:
1.424 albertel 6137: updates the $delayqueue to have a new hash ref of the error
1.423 albertel 6138:
6139: =cut
6140:
1.82 albertel 6141: sub scantron_add_delay {
1.140 albertel 6142: my ($delayqueue,$scanline,$errormessage,$errorcode)=@_;
6143: push(@$delayqueue,
6144: {'line' => $scanline, 'emsg' => $errormessage,
6145: 'ecode' => $errorcode }
6146: );
1.82 albertel 6147: }
6148:
1.423 albertel 6149: =pod
6150:
6151: =item scantron_find_student
6152:
1.424 albertel 6153: Finds the username for the current scanline
6154:
6155: Arguments:
6156: $scantron_record - hash result from scantron_parse_scanline
6157: $scan_data - hash of correction information
6158: (see &scantron_getfile() form more information)
6159: $idmap - hash from &username_to_idmap()
6160: $line - number of current scanline
6161:
6162: Returns:
6163: Either 'username:domain' or undef if unknown
6164:
1.423 albertel 6165: =cut
6166:
1.82 albertel 6167: sub scantron_find_student {
1.157 albertel 6168: my ($scantron_record,$scan_data,$idmap,$line)=@_;
1.83 albertel 6169: my $scanID=$$scantron_record{'scantron.ID'};
1.157 albertel 6170: if ($scanID =~ /^\s*$/) {
6171: return &scan_data($scan_data,"$line.user");
6172: }
1.83 albertel 6173: foreach my $id (keys(%$idmap)) {
1.157 albertel 6174: if (lc($id) eq lc($scanID)) {
6175: return $$idmap{$id};
6176: }
1.83 albertel 6177: }
6178: return undef;
6179: }
6180:
1.423 albertel 6181: =pod
6182:
6183: =item scantron_filter
6184:
1.424 albertel 6185: Filter sub for lonnavmaps, filters out hidden resources if ignore
6186: hidden resources was selected
6187:
1.423 albertel 6188: =cut
6189:
1.83 albertel 6190: sub scantron_filter {
6191: my ($curres)=@_;
1.331 albertel 6192:
6193: if (ref($curres) && $curres->is_problem()) {
6194: # if the user has asked to not have either hidden
6195: # or 'randomout' controlled resources to be graded
6196: # don't include them
6197: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
6198: && $curres->randomout) {
6199: return 0;
6200: }
1.83 albertel 6201: return 1;
6202: }
6203: return 0;
1.82 albertel 6204: }
6205:
1.423 albertel 6206: =pod
6207:
6208: =item scantron_process_corrections
6209:
1.424 albertel 6210: Gets correction information out of submitted form data and corrects
6211: the scanline
6212:
1.423 albertel 6213: =cut
6214:
1.157 albertel 6215: sub scantron_process_corrections {
6216: my ($r) = @_;
1.257 albertel 6217: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 6218: my ($scanlines,$scan_data)=&scantron_getfile();
6219: my $classlist=&Apache::loncoursedata::get_classlist();
1.257 albertel 6220: my $which=$env{'form.scantron_line'};
1.200 albertel 6221: my $line=&scantron_get_line($scanlines,$scan_data,$which);
1.157 albertel 6222: my ($skip,$err,$errmsg);
1.257 albertel 6223: if ($env{'form.scantron_skip_record'}) {
1.157 albertel 6224: $skip=1;
1.257 albertel 6225: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)ID$/) {
6226: my $newstudent=$env{'form.scantron_username'}.':'.
6227: $env{'form.scantron_domain'};
1.157 albertel 6228: my $newid=$classlist->{$newstudent}->[&Apache::loncoursedata::CL_ID];
6229: ($line,$err,$errmsg)=
6230: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
6231: 'ID',{'newid'=>$newid,
1.257 albertel 6232: 'username'=>$env{'form.scantron_username'},
6233: 'domain'=>$env{'form.scantron_domain'}});
6234: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)CODE$/) {
6235: my $resolution=$env{'form.scantron_CODE_resolution'};
1.190 albertel 6236: my $newCODE;
1.192 albertel 6237: my %args;
1.190 albertel 6238: if ($resolution eq 'use_unfound') {
1.191 albertel 6239: $newCODE='use_unfound';
1.190 albertel 6240: } elsif ($resolution eq 'use_found') {
1.257 albertel 6241: $newCODE=$env{'form.scantron_CODE_selectedvalue'};
1.190 albertel 6242: } elsif ($resolution eq 'use_typed') {
1.257 albertel 6243: $newCODE=$env{'form.scantron_CODE_newvalue'};
1.194 albertel 6244: } elsif ($resolution =~ /^use_closest_(\d+)/) {
1.257 albertel 6245: $newCODE=$env{"form.scantron_CODE_closest_$1"};
1.190 albertel 6246: }
1.257 albertel 6247: if ($env{'form.scantron_corrections'} eq 'duplicateCODE') {
1.192 albertel 6248: $args{'CODE_ignore_dup'}=1;
6249: }
6250: $args{'CODE'}=$newCODE;
1.186 albertel 6251: ($line,$err,$errmsg)=
6252: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
1.192 albertel 6253: 'CODE',\%args);
1.257 albertel 6254: } elsif ($env{'form.scantron_corrections'} =~ /^(missing|double)bubble$/) {
6255: foreach my $question (split(',',$env{'form.scantron_questions'})) {
1.157 albertel 6256: ($line,$err,$errmsg)=
6257: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,
6258: $which,'answer',
6259: { 'question'=>$question,
1.503 raeburn 6260: 'response'=>$env{"form.scantron_correct_Q_$question"},
6261: 'questionnum'=>$env{"form.scantron_questionnum_Q_$question"}});
1.157 albertel 6262: if ($err) { last; }
6263: }
6264: }
6265: if ($err) {
1.398 albertel 6266: $r->print("<span class=\"LC_warning\">Unable to accept last correction, an error occurred :$errmsg:</span>");
1.157 albertel 6267: } else {
1.200 albertel 6268: &scantron_put_line($scanlines,$scan_data,$which,$line,$skip);
1.157 albertel 6269: &scantron_putfile($scanlines,$scan_data);
6270: }
6271: }
6272:
1.423 albertel 6273: =pod
6274:
6275: =item reset_skipping_status
6276:
1.424 albertel 6277: Forgets the current set of remember skipped scanlines (and thus
6278: reverts back to considering all lines in the
6279: scantron_skipped_<filename> file)
6280:
1.423 albertel 6281: =cut
6282:
1.200 albertel 6283: sub reset_skipping_status {
6284: my ($scanlines,$scan_data)=&scantron_getfile();
6285: &scan_data($scan_data,'remember_skipping',undef,1);
6286: &scantron_putfile(undef,$scan_data);
6287: }
6288:
1.423 albertel 6289: =pod
6290:
6291: =item start_skipping
6292:
1.424 albertel 6293: Marks a scanline to be skipped.
6294:
1.423 albertel 6295: =cut
6296:
1.376 albertel 6297: sub start_skipping {
1.200 albertel 6298: my ($scan_data,$i)=@_;
6299: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 6300: if ($env{'form.scantron_options_redo'} =~ /^redo_/) {
6301: $remembered{$i}=2;
6302: } else {
6303: $remembered{$i}=1;
6304: }
1.200 albertel 6305: &scan_data($scan_data,'remember_skipping',join(':',%remembered));
6306: }
6307:
1.423 albertel 6308: =pod
6309:
6310: =item should_be_skipped
6311:
1.424 albertel 6312: Checks whether a scanline should be skipped.
6313:
1.423 albertel 6314: =cut
6315:
1.200 albertel 6316: sub should_be_skipped {
1.376 albertel 6317: my ($scanlines,$scan_data,$i)=@_;
1.257 albertel 6318: if ($env{'form.scantron_options_redo'} !~ /^redo_/) {
1.200 albertel 6319: # not redoing old skips
1.376 albertel 6320: if ($scanlines->{'skipped'}[$i]) { return 1; }
1.200 albertel 6321: return 0;
6322: }
6323: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 6324:
6325: if (exists($remembered{$i}) && $remembered{$i} != 2 ) {
6326: return 0;
6327: }
1.200 albertel 6328: return 1;
6329: }
6330:
1.423 albertel 6331: =pod
6332:
6333: =item remember_current_skipped
6334:
1.424 albertel 6335: Discovers what scanlines are in the scantron_skipped_<filename>
6336: file and remembers them into scan_data for later use.
6337:
1.423 albertel 6338: =cut
6339:
1.200 albertel 6340: sub remember_current_skipped {
6341: my ($scanlines,$scan_data)=&scantron_getfile();
6342: my %to_remember;
6343: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
6344: if ($scanlines->{'skipped'}[$i]) {
6345: $to_remember{$i}=1;
6346: }
6347: }
1.376 albertel 6348:
1.200 albertel 6349: &scan_data($scan_data,'remember_skipping',join(':',%to_remember));
6350: &scantron_putfile(undef,$scan_data);
6351: }
6352:
1.423 albertel 6353: =pod
6354:
6355: =item check_for_error
6356:
1.424 albertel 6357: Checks if there was an error when attempting to remove a specific
1.596.2.6 raeburn 6358: scantron_.. bubblesheet data file. Prints out an error if
1.424 albertel 6359: something went wrong.
6360:
1.423 albertel 6361: =cut
6362:
1.200 albertel 6363: sub check_for_error {
6364: my ($r,$result)=@_;
6365: if ($result ne 'ok' && $result ne 'not_found' ) {
1.492 albertel 6366: $r->print(&mt("An error occurred ([_1]) when trying to remove the existing corrections.",$result));
1.200 albertel 6367: }
6368: }
1.157 albertel 6369:
1.423 albertel 6370: =pod
6371:
6372: =item scantron_warning_screen
6373:
1.424 albertel 6374: Interstitial screen to make sure the operator has selected the
6375: correct options before we start the validation phase.
6376:
1.423 albertel 6377: =cut
6378:
1.203 albertel 6379: sub scantron_warning_screen {
6380: my ($button_text)=@_;
1.257 albertel 6381: my $title=&Apache::lonnet::gettitle($env{'form.selectpage'});
1.284 albertel 6382: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.373 albertel 6383: my $CODElist;
1.284 albertel 6384: if ($scantron_config{'CODElocation'} &&
6385: $scantron_config{'CODEstart'} &&
6386: $scantron_config{'CODElength'}) {
6387: $CODElist=$env{'form.scantron_CODElist'};
1.398 albertel 6388: if ($env{'form.scantron_CODElist'} eq '') { $CODElist='<span class="LC_warning">None</span>'; }
1.284 albertel 6389: $CODElist=
1.492 albertel 6390: '<tr><td><b>'.&mt('List of CODES to validate against:').'</b></td><td><tt>'.
1.373 albertel 6391: $env{'form.scantron_CODElist'}.'</tt></td></tr>';
1.284 albertel 6392: }
1.596.2.12.2. (raeburn 6393:): my $lastbubblepoints;
6394:): if ($env{'form.scantron_lastbubblepoints'} ne '') {
6395:): $lastbubblepoints =
6396:): '<tr><td><b>'.&mt('Hand-graded items: points from last bubble in row').'</b></td><td><tt>'.
6397:): $env{'form.scantron_lastbubblepoints'}.'</tt></td></tr>';
6398:): }
1.492 albertel 6399: return ('
1.203 albertel 6400: <p>
1.492 albertel 6401: <span class="LC_warning">
6402: '.&mt('Please double check the information below before clicking on \'[_1]\'',&mt($button_text)).'</span>
1.203 albertel 6403: </p>
6404: <table>
1.492 albertel 6405: <tr><td><b>'.&mt('Sequence to be Graded:').'</b></td><td>'.$title.'</td></tr>
6406: <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 6407:): '.$CODElist.$lastbubblepoints.'
1.203 albertel 6408: </table>
6409: <br />
1.492 albertel 6410: <p> '.&mt('If this information is correct, please click on \'[_1]\'.',&mt($button_text)).'</p>
6411: <p> '.&mt('If something is incorrect, please click the \'Grading Menu\' button to start over.').'</p>
1.203 albertel 6412:
6413: <br />
1.492 albertel 6414: ');
1.203 albertel 6415: }
6416:
1.423 albertel 6417: =pod
6418:
6419: =item scantron_do_warning
6420:
1.424 albertel 6421: Check if the operator has picked something for all required
6422: fields. Error out if something is missing.
6423:
1.423 albertel 6424: =cut
6425:
1.203 albertel 6426: sub scantron_do_warning {
6427: my ($r)=@_;
1.324 albertel 6428: my ($symb)=&get_symb($r);
1.203 albertel 6429: if (!$symb) {return '';}
1.324 albertel 6430: my $default_form_data=&defaultFormData($symb);
1.203 albertel 6431: $r->print(&scantron_form_start().$default_form_data);
1.257 albertel 6432: if ( $env{'form.selectpage'} eq '' ||
6433: $env{'form.scantron_selectfile'} eq '' ||
6434: $env{'form.scantron_format'} eq '' ) {
1.596.2.4 raeburn 6435: $r->print("<p>".&mt('You have forgotten to specify some information. Please go Back and try again.')."</p>");
1.257 albertel 6436: if ( $env{'form.selectpage'} eq '') {
1.492 albertel 6437: $r->print('<p><span class="LC_error">'.&mt('You have not selected a Sequence to grade').'</span></p>');
1.237 albertel 6438: }
1.257 albertel 6439: if ( $env{'form.scantron_selectfile'} eq '') {
1.596.2.4 raeburn 6440: $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 6441: }
1.257 albertel 6442: if ( $env{'form.scantron_format'} eq '') {
1.596.2.5 raeburn 6443: $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 6444: }
6445: } else {
1.265 www 6446: my $warning=&scantron_warning_screen('Grading: Validate Records');
1.596.2.12.2. (raeburn 6447:): my $bubbledbyhand=&hand_bubble_option();
1.492 albertel 6448: $r->print('
1.596.2.12.2. (raeburn 6449:): '.$warning.$bubbledbyhand.'
1.492 albertel 6450: <input type="submit" name="submit" value="'.&mt('Grading: Validate Records').'" />
1.203 albertel 6451: <input type="hidden" name="command" value="scantron_validate" />
1.492 albertel 6452: ');
1.237 albertel 6453: }
1.352 albertel 6454: $r->print("</form><br />".&show_grading_menu_form($symb));
1.203 albertel 6455: return '';
6456: }
6457:
1.423 albertel 6458: =pod
6459:
6460: =item scantron_form_start
6461:
1.424 albertel 6462: html hidden input for remembering all selected grading options
6463:
1.423 albertel 6464: =cut
6465:
1.203 albertel 6466: sub scantron_form_start {
6467: my ($max_bubble)=@_;
6468: my $result= <<SCANTRONFORM;
6469: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
1.257 albertel 6470: <input type="hidden" name="selectpage" value="$env{'form.selectpage'}" />
6471: <input type="hidden" name="scantron_format" value="$env{'form.scantron_format'}" />
6472: <input type="hidden" name="scantron_selectfile" value="$env{'form.scantron_selectfile'}" />
1.218 albertel 6473: <input type="hidden" name="scantron_maxbubble" value="$max_bubble" />
1.257 albertel 6474: <input type="hidden" name="scantron_CODElist" value="$env{'form.scantron_CODElist'}" />
6475: <input type="hidden" name="scantron_CODEunique" value="$env{'form.scantron_CODEunique'}" />
6476: <input type="hidden" name="scantron_options_redo" value="$env{'form.scantron_options_redo'}" />
6477: <input type="hidden" name="scantron_options_ignore" value="$env{'form.scantron_options_ignore'}" />
1.331 albertel 6478: <input type="hidden" name="scantron_options_hidden" value="$env{'form.scantron_options_hidden'}" />
1.203 albertel 6479: SCANTRONFORM
1.447 foxr 6480:
6481: my $line = 0;
6482: while (defined($env{"form.scantron.bubblelines.$line"})) {
6483: my $chunk =
6484: '<input type="hidden" name="scantron.bubblelines.'.$line.'" value="'.$env{"form.scantron.bubblelines.$line"}.'" />'."\n";
1.448 foxr 6485: $chunk .=
6486: '<input type="hidden" name="scantron.first_bubble_line.'.$line.'" value="'.$env{"form.scantron.first_bubble_line.$line"}.'" />'."\n";
1.503 raeburn 6487: $chunk .=
6488: '<input type="hidden" name="scantron.sub_bubblelines.'.$line.'" value="'.$env{"form.scantron.sub_bubblelines.$line"}.'" />'."\n";
1.504 raeburn 6489: $chunk .=
6490: '<input type="hidden" name="scantron.responsetype.'.$line.'" value="'.$env{"form.scantron.responsetype.$line"}.'" />'."\n";
1.447 foxr 6491: $result .= $chunk;
6492: $line++;
6493: }
1.203 albertel 6494: return $result;
6495: }
6496:
1.423 albertel 6497: =pod
6498:
6499: =item scantron_validate_file
6500:
1.596.2.6 raeburn 6501: Dispatch routine for doing validation of a bubblesheet data file.
1.424 albertel 6502:
6503: Also processes any necessary information resets that need to
6504: occur before validation begins (ignore previous corrections,
6505: restarting the skipped records processing)
6506:
1.423 albertel 6507: =cut
6508:
1.157 albertel 6509: sub scantron_validate_file {
6510: my ($r) = @_;
1.324 albertel 6511: my ($symb)=&get_symb($r);
1.157 albertel 6512: if (!$symb) {return '';}
1.324 albertel 6513: my $default_form_data=&defaultFormData($symb);
1.200 albertel 6514:
6515: # do the detection of only doing skipped records first befroe we delete
1.424 albertel 6516: # them when doing the corrections reset
1.257 albertel 6517: if ($env{'form.scantron_options_redo'} ne 'redo_skipped_ready') {
1.200 albertel 6518: &reset_skipping_status();
6519: }
1.257 albertel 6520: if ($env{'form.scantron_options_redo'} eq 'redo_skipped') {
1.200 albertel 6521: &remember_current_skipped();
1.257 albertel 6522: $env{'form.scantron_options_redo'}='redo_skipped_ready';
1.200 albertel 6523: }
6524:
1.257 albertel 6525: if ($env{'form.scantron_options_ignore'} eq 'ignore_corrections') {
1.200 albertel 6526: &check_for_error($r,&scantron_remove_file('corrected'));
6527: &check_for_error($r,&scantron_remove_file('skipped'));
6528: &check_for_error($r,&scantron_remove_scan_data());
1.257 albertel 6529: $env{'form.scantron_options_ignore'}='done';
1.192 albertel 6530: }
1.200 albertel 6531:
1.257 albertel 6532: if ($env{'form.scantron_corrections'}) {
1.157 albertel 6533: &scantron_process_corrections($r);
6534: }
1.503 raeburn 6535: $r->print('<p>'.&mt('Gathering necessary information.').'</p>');$r->rflush();
1.157 albertel 6536: #get the student pick code ready
6537: $r->print(&Apache::loncommon::studentbrowser_javascript());
1.582 raeburn 6538: my $nav_error;
1.596.2.12.2. (raeburn 6539:): my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
6540:): my $max_bubble=&scantron_get_maxbubble(\$nav_error,\%scantron_config);
1.582 raeburn 6541: if ($nav_error) {
6542: $r->print(&navmap_errormsg());
6543: return '';
6544: }
1.203 albertel 6545: my $result=&scantron_form_start($max_bubble).$default_form_data;
1.596.2.12.2. (raeburn 6546:): if ($env{'form.scantron_lastbubblepoints'} ne '') {
6547:): $result .= '<input type="hidden" name="scantron_lastbubblepoints" value="'.$env{'form.scantron_lastbubblepoints'}.'" />';
6548:): }
1.157 albertel 6549: $r->print($result);
6550:
1.334 albertel 6551: my @validate_phases=( 'sequence',
6552: 'ID',
1.157 albertel 6553: 'CODE',
6554: 'doublebubble',
6555: 'missingbubbles');
1.257 albertel 6556: if (!$env{'form.validatepass'}) {
6557: $env{'form.validatepass'} = 0;
1.157 albertel 6558: }
1.257 albertel 6559: my $currentphase=$env{'form.validatepass'};
1.157 albertel 6560:
1.448 foxr 6561:
1.157 albertel 6562: my $stop=0;
6563: while (!$stop && $currentphase < scalar(@validate_phases)) {
1.503 raeburn 6564: $r->print(&mt('Validating '.$validate_phases[$currentphase]).'<br />');
1.157 albertel 6565: $r->rflush();
6566: my $which="scantron_validate_".$validate_phases[$currentphase];
6567: {
6568: no strict 'refs';
6569: ($stop,$currentphase)=&$which($r,$currentphase);
6570: }
6571: }
6572: if (!$stop) {
1.203 albertel 6573: my $warning=&scantron_warning_screen('Start Grading');
1.542 raeburn 6574: $r->print(&mt('Validation process complete.').'<br />'.
6575: $warning.
6576: &mt('Perform verification for each student after storage of submissions?').
6577: ' <span class="LC_nobreak"><label>'.
6578: '<input type="radio" name="verifyrecord" value="1" />'.&mt('Yes').'</label>'.
6579: (' 'x3).'<label>'.
6580: '<input type="radio" name="verifyrecord" value="0" checked="checked" />'.&mt('No').
6581: '</label></span><br />'.
6582: &mt('Grading will take longer if you use verification.').'<br />'.
1.572 www 6583: &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 6584: '<input type="submit" name="submit" value="'.&mt('Start Grading').'" />'.
6585: '<input type="hidden" name="command" value="scantron_process" />'."\n");
1.157 albertel 6586: } else {
6587: $r->print('<input type="hidden" name="command" value="scantron_validate" />');
6588: $r->print("<input type='hidden' name='validatepass' value='".$currentphase."' />");
6589: }
6590: if ($stop) {
1.334 albertel 6591: if ($validate_phases[$currentphase] eq 'sequence') {
1.539 riegler 6592: $r->print('<input type="submit" name="submit" value="'.&mt('Ignore').' → " />');
1.492 albertel 6593: $r->print(' '.&mt('this error').' <br />');
1.334 albertel 6594:
1.492 albertel 6595: $r->print(" <p>".&mt("Or click the 'Grading Menu' button to start over.")."</p>");
1.334 albertel 6596: } else {
1.503 raeburn 6597: if ($validate_phases[$currentphase] eq 'doublebubble' || $validate_phases[$currentphase] eq 'missingbubbles') {
1.539 riegler 6598: $r->print('<input type="button" name="submitbutton" value="'.&mt('Continue').' →" onclick="javascript:verify_bubble_radio(this.form)" />');
1.503 raeburn 6599: } else {
1.539 riegler 6600: $r->print('<input type="submit" name="submit" value="'.&mt('Continue').' →" />');
1.503 raeburn 6601: }
1.492 albertel 6602: $r->print(' '.&mt('using corrected info').' <br />');
6603: $r->print("<input type='submit' value='".&mt("Skip")."' name='scantron_skip_record' />");
6604: $r->print(" ".&mt("this scanline saving it for later."));
1.334 albertel 6605: }
1.157 albertel 6606: }
1.352 albertel 6607: $r->print(" </form><br />".&show_grading_menu_form($symb));
1.157 albertel 6608: return '';
6609: }
6610:
1.423 albertel 6611:
6612: =pod
6613:
6614: =item scantron_remove_file
6615:
1.596.2.6 raeburn 6616: Removes the requested bubblesheet data file, makes sure that
1.424 albertel 6617: scantron_original_<filename> is never removed
6618:
6619:
1.423 albertel 6620: =cut
6621:
1.200 albertel 6622: sub scantron_remove_file {
1.192 albertel 6623: my ($which)=@_;
1.257 albertel 6624: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6625: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 6626: my $file='scantron_';
1.200 albertel 6627: if ($which eq 'corrected' || $which eq 'skipped') {
6628: $file.=$which.'_';
1.192 albertel 6629: } else {
6630: return 'refused';
6631: }
1.257 albertel 6632: $file.=$env{'form.scantron_selectfile'};
1.200 albertel 6633: return &Apache::lonnet::removeuserfile($cname,$cdom,$file);
6634: }
6635:
1.423 albertel 6636:
6637: =pod
6638:
6639: =item scantron_remove_scan_data
6640:
1.596.2.6 raeburn 6641: Removes all scan_data correction for the requested bubblesheet
1.424 albertel 6642: data file. (In the case that both the are doing skipped records we need
6643: to remember the old skipped lines for the time being so that element
6644: persists for a while.)
6645:
1.423 albertel 6646: =cut
6647:
1.200 albertel 6648: sub scantron_remove_scan_data {
1.257 albertel 6649: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6650: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 6651: my @keys=&Apache::lonnet::getkeys('nohist_scantrondata',$cdom,$cname);
6652: my @todelete;
1.257 albertel 6653: my $filename=$env{'form.scantron_selectfile'};
1.192 albertel 6654: foreach my $key (@keys) {
6655: if ($key=~/^\Q$filename\E_/) {
1.257 albertel 6656: if ($env{'form.scantron_options_redo'} eq 'redo_skipped_ready' &&
1.200 albertel 6657: $key=~/remember_skipping/) {
6658: next;
6659: }
1.192 albertel 6660: push(@todelete,$key);
6661: }
6662: }
1.200 albertel 6663: my $result;
1.192 albertel 6664: if (@todelete) {
1.491 albertel 6665: $result = &Apache::lonnet::del('nohist_scantrondata',
6666: \@todelete,$cdom,$cname);
6667: } else {
6668: $result = 'ok';
1.192 albertel 6669: }
6670: return $result;
6671: }
6672:
1.423 albertel 6673:
6674: =pod
6675:
6676: =item scantron_getfile
6677:
1.596.2.6 raeburn 6678: Fetches the requested bubblesheet data file (all 3 versions), and
1.424 albertel 6679: the scan_data hash
6680:
6681: Arguments:
6682: None
6683:
6684: Returns:
6685: 2 hash references
6686:
6687: - first one has
6688: orig -
6689: corrected -
6690: skipped - each of which points to an array ref of the specified
6691: file broken up into individual lines
6692: count - number of scanlines
6693:
6694: - second is the scan_data hash possible keys are
1.425 albertel 6695: ($number refers to scanline numbered $number and thus the key affects
6696: only that scanline
6697: $bubline refers to the specific bubble line element and the aspects
6698: refers to that specific bubble line element)
6699:
6700: $number.user - username:domain to use
6701: $number.CODE_ignore_dup
6702: - ignore the duplicate CODE error
6703: $number.useCODE
6704: - use the CODE in the scanline as is
6705: $number.no_bubble.$bubline
6706: - it is valid that there is no bubbled in bubble
6707: at $number $bubline
6708: remember_skipping
6709: - a frozen hash containing keys of $number and values
6710: of either
6711: 1 - we are on a 'do skipped records pass' and plan
6712: on processing this line
6713: 2 - we are on a 'do skipped records pass' and this
6714: scanline has been marked to skip yet again
1.424 albertel 6715:
1.423 albertel 6716: =cut
6717:
1.157 albertel 6718: sub scantron_getfile {
1.200 albertel 6719: #FIXME really would prefer a scantron directory
1.257 albertel 6720: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6721: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.157 albertel 6722: my $lines;
6723: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6724: 'scantron_orig_'.$env{'form.scantron_selectfile'});
1.157 albertel 6725: my %scanlines;
6726: $scanlines{'orig'}=[(split("\n",$lines,-1))];
6727: my $temp=$scanlines{'orig'};
6728: $scanlines{'count'}=$#$temp;
6729:
6730: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6731: 'scantron_corrected_'.$env{'form.scantron_selectfile'});
1.157 albertel 6732: if ($lines eq '-1') {
6733: $scanlines{'corrected'}=[];
6734: } else {
6735: $scanlines{'corrected'}=[(split("\n",$lines,-1))];
6736: }
6737: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6738: 'scantron_skipped_'.$env{'form.scantron_selectfile'});
1.157 albertel 6739: if ($lines eq '-1') {
6740: $scanlines{'skipped'}=[];
6741: } else {
6742: $scanlines{'skipped'}=[(split("\n",$lines,-1))];
6743: }
1.175 albertel 6744: my @tmp=&Apache::lonnet::dump('nohist_scantrondata',$cdom,$cname);
1.157 albertel 6745: if ($tmp[0] =~ /^(error:|no_such_host)/) { @tmp=(); }
6746: my %scan_data = @tmp;
6747: return (\%scanlines,\%scan_data);
6748: }
6749:
1.423 albertel 6750: =pod
6751:
6752: =item lonnet_putfile
6753:
1.424 albertel 6754: Wrapper routine to call &Apache::lonnet::finishuserfileupload
6755:
6756: Arguments:
6757: $contents - data to store
6758: $filename - filename to store $contents into
6759:
6760: Returns:
6761: result value from &Apache::lonnet::finishuserfileupload
6762:
1.423 albertel 6763: =cut
6764:
1.157 albertel 6765: sub lonnet_putfile {
6766: my ($contents,$filename)=@_;
1.257 albertel 6767: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6768: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6769: $env{'form.sillywaytopassafilearound'}=$contents;
1.275 albertel 6770: &Apache::lonnet::finishuserfileupload($docuname,$docudom,'sillywaytopassafilearound',$filename);
1.157 albertel 6771:
6772: }
6773:
1.423 albertel 6774: =pod
6775:
6776: =item scantron_putfile
6777:
1.596.2.6 raeburn 6778: Stores the current version of the bubblesheet data files, and the
1.424 albertel 6779: scan_data hash. (Does not modify the original version only the
6780: corrected and skipped versions.
6781:
6782: Arguments:
6783: $scanlines - hash ref that looks like the first return value from
6784: &scantron_getfile()
6785: $scan_data - hash ref that looks like the second return value from
6786: &scantron_getfile()
6787:
1.423 albertel 6788: =cut
6789:
1.157 albertel 6790: sub scantron_putfile {
6791: my ($scanlines,$scan_data) = @_;
1.200 albertel 6792: #FIXME really would prefer a scantron directory
1.257 albertel 6793: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6794: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.200 albertel 6795: if ($scanlines) {
6796: my $prefix='scantron_';
1.157 albertel 6797: # no need to update orig, shouldn't change
6798: # &lonnet_putfile(join("\n",@{$scanlines->{'orig'}}),$prefix.'orig_'.
1.257 albertel 6799: # $env{'form.scantron_selectfile'});
1.200 albertel 6800: &lonnet_putfile(join("\n",@{$scanlines->{'corrected'}}),
6801: $prefix.'corrected_'.
1.257 albertel 6802: $env{'form.scantron_selectfile'});
1.200 albertel 6803: &lonnet_putfile(join("\n",@{$scanlines->{'skipped'}}),
6804: $prefix.'skipped_'.
1.257 albertel 6805: $env{'form.scantron_selectfile'});
1.200 albertel 6806: }
1.175 albertel 6807: &Apache::lonnet::put('nohist_scantrondata',$scan_data,$cdom,$cname);
1.157 albertel 6808: }
6809:
1.423 albertel 6810: =pod
6811:
6812: =item scantron_get_line
6813:
1.424 albertel 6814: Returns the correct version of the scanline
6815:
6816: Arguments:
6817: $scanlines - hash ref that looks like the first return value from
6818: &scantron_getfile()
6819: $scan_data - hash ref that looks like the second return value from
6820: &scantron_getfile()
6821: $i - number of the requested line (starts at 0)
6822:
6823: Returns:
6824: A scanline, (either the original or the corrected one if it
6825: exists), or undef if the requested scanline should be
6826: skipped. (Either because it's an skipped scanline, or it's an
6827: unskipped scanline and we are not doing a 'do skipped scanlines'
6828: pass.
6829:
1.423 albertel 6830: =cut
6831:
1.157 albertel 6832: sub scantron_get_line {
1.200 albertel 6833: my ($scanlines,$scan_data,$i)=@_;
1.376 albertel 6834: if (&should_be_skipped($scanlines,$scan_data,$i)) { return undef; }
6835: #if ($scanlines->{'skipped'}[$i]) { return undef; }
1.157 albertel 6836: if ($scanlines->{'corrected'}[$i]) {return $scanlines->{'corrected'}[$i];}
6837: return $scanlines->{'orig'}[$i];
6838: }
6839:
1.423 albertel 6840: =pod
6841:
6842: =item scantron_todo_count
6843:
1.424 albertel 6844: Counts the number of scanlines that need processing.
6845:
6846: Arguments:
6847: $scanlines - hash ref that looks like the first return value from
6848: &scantron_getfile()
6849: $scan_data - hash ref that looks like the second return value from
6850: &scantron_getfile()
6851:
6852: Returns:
6853: $count - number of scanlines to process
6854:
1.423 albertel 6855: =cut
6856:
1.200 albertel 6857: sub get_todo_count {
6858: my ($scanlines,$scan_data)=@_;
6859: my $count=0;
6860: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
6861: my $line=&scantron_get_line($scanlines,$scan_data,$i);
6862: if ($line=~/^[\s\cz]*$/) { next; }
6863: $count++;
6864: }
6865: return $count;
6866: }
6867:
1.423 albertel 6868: =pod
6869:
6870: =item scantron_put_line
6871:
1.596.2.6 raeburn 6872: Updates the 'corrected' or 'skipped' versions of the bubblesheet
1.424 albertel 6873: data file.
6874:
6875: Arguments:
6876: $scanlines - hash ref that looks like the first return value from
6877: &scantron_getfile()
6878: $scan_data - hash ref that looks like the second return value from
6879: &scantron_getfile()
6880: $i - line number to update
6881: $newline - contents of the updated scanline
6882: $skip - if true make the line for skipping and update the
6883: 'skipped' file
6884:
1.423 albertel 6885: =cut
6886:
1.157 albertel 6887: sub scantron_put_line {
1.200 albertel 6888: my ($scanlines,$scan_data,$i,$newline,$skip)=@_;
1.157 albertel 6889: if ($skip) {
6890: $scanlines->{'skipped'}[$i]=$newline;
1.376 albertel 6891: &start_skipping($scan_data,$i);
1.157 albertel 6892: return;
6893: }
6894: $scanlines->{'corrected'}[$i]=$newline;
6895: }
6896:
1.423 albertel 6897: =pod
6898:
6899: =item scantron_clear_skip
6900:
1.424 albertel 6901: Remove a line from the 'skipped' file
6902:
6903: Arguments:
6904: $scanlines - hash ref that looks like the first return value from
6905: &scantron_getfile()
6906: $scan_data - hash ref that looks like the second return value from
6907: &scantron_getfile()
6908: $i - line number to update
6909:
1.423 albertel 6910: =cut
6911:
1.376 albertel 6912: sub scantron_clear_skip {
6913: my ($scanlines,$scan_data,$i)=@_;
6914: if (exists($scanlines->{'skipped'}[$i])) {
6915: undef($scanlines->{'skipped'}[$i]);
6916: return 1;
6917: }
6918: return 0;
6919: }
6920:
1.423 albertel 6921: =pod
6922:
6923: =item scantron_filter_not_exam
6924:
1.424 albertel 6925: Filter routine used by &Apache::lonnavmaps::retrieveResources(), to
6926: filter out resources that are not marked as 'exam' mode
6927:
1.423 albertel 6928: =cut
6929:
1.334 albertel 6930: sub scantron_filter_not_exam {
6931: my ($curres)=@_;
6932:
6933: if (ref($curres) && $curres->is_problem() && !$curres->is_exam()) {
6934: # if the user has asked to not have either hidden
6935: # or 'randomout' controlled resources to be graded
6936: # don't include them
6937: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
6938: && $curres->randomout) {
6939: return 0;
6940: }
6941: return 1;
6942: }
6943: return 0;
6944: }
6945:
1.423 albertel 6946: =pod
6947:
6948: =item scantron_validate_sequence
6949:
1.424 albertel 6950: Validates the selected sequence, checking for resource that are
6951: not set to exam mode.
6952:
1.423 albertel 6953: =cut
6954:
1.334 albertel 6955: sub scantron_validate_sequence {
6956: my ($r,$currentphase) = @_;
6957:
6958: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 6959: unless (ref($navmap)) {
6960: $r->print(&navmap_errormsg());
6961: return (1,$currentphase);
6962: }
1.334 albertel 6963: my (undef,undef,$sequence)=
6964: &Apache::lonnet::decode_symb($env{'form.selectpage'});
6965:
6966: my $map=$navmap->getResourceByUrl($sequence);
6967:
6968: $r->print('<input type="hidden" name="validate_sequence_exam"
6969: value="ignore" />');
6970: if ($env{'form.validate_sequence_exam'} ne 'ignore') {
6971: my @resources=
6972: $navmap->retrieveResources($map,\&scantron_filter_not_exam,1,0);
6973: if (@resources) {
1.357 banghart 6974: $r->print("<p>".&mt('Some resources in the sequence currently are not set to exam mode. Grading these resources currently may not work correctly.')."</p>");
1.334 albertel 6975: return (1,$currentphase);
6976: }
6977: }
6978:
6979: return (0,$currentphase+1);
6980: }
6981:
1.423 albertel 6982:
6983:
1.157 albertel 6984: sub scantron_validate_ID {
6985: my ($r,$currentphase) = @_;
6986:
6987: #get student info
6988: my $classlist=&Apache::loncoursedata::get_classlist();
6989: my %idmap=&username_to_idmap($classlist);
6990:
6991: #get scantron line setup
1.257 albertel 6992: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 6993: my ($scanlines,$scan_data)=&scantron_getfile();
1.582 raeburn 6994:
6995: my $nav_error;
1.596.2.12.2. (raeburn 6996:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the bubble_lines.. array.
1.582 raeburn 6997: if ($nav_error) {
6998: $r->print(&navmap_errormsg());
6999: return(1,$currentphase);
7000: }
1.157 albertel 7001:
7002: my %found=('ids'=>{},'usernames'=>{});
7003: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7004: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7005: if ($line=~/^[\s\cz]*$/) { next; }
7006: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7007: $scan_data);
7008: my $id=$$scan_record{'scantron.ID'};
7009: my $found;
7010: foreach my $checkid (keys(%idmap)) {
7011: if (lc($checkid) eq lc($id)) { $found=$checkid;last; }
7012: }
7013: if ($found) {
7014: my $username=$idmap{$found};
7015: if ($found{'ids'}{$found}) {
7016: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
7017: $line,'duplicateID',$found);
1.194 albertel 7018: return(1,$currentphase);
1.157 albertel 7019: } elsif ($found{'usernames'}{$username}) {
7020: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
7021: $line,'duplicateID',$username);
1.194 albertel 7022: return(1,$currentphase);
1.157 albertel 7023: }
1.186 albertel 7024: #FIXME store away line we previously saw the ID on to use above
1.157 albertel 7025: $found{'ids'}{$found}++;
7026: $found{'usernames'}{$username}++;
7027: } else {
7028: if ($id =~ /^\s*$/) {
1.158 albertel 7029: my $username=&scan_data($scan_data,"$i.user");
1.157 albertel 7030: if (defined($username) && $found{'usernames'}{$username}) {
7031: &scantron_get_correction($r,$i,$scan_record,
7032: \%scantron_config,
7033: $line,'duplicateID',$username);
1.194 albertel 7034: return(1,$currentphase);
1.157 albertel 7035: } elsif (!defined($username)) {
7036: &scantron_get_correction($r,$i,$scan_record,
7037: \%scantron_config,
7038: $line,'incorrectID');
1.194 albertel 7039: return(1,$currentphase);
1.157 albertel 7040: }
7041: $found{'usernames'}{$username}++;
7042: } else {
7043: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
7044: $line,'incorrectID');
1.194 albertel 7045: return(1,$currentphase);
1.157 albertel 7046: }
7047: }
7048: }
7049:
7050: return (0,$currentphase+1);
7051: }
7052:
1.423 albertel 7053:
1.157 albertel 7054: sub scantron_get_correction {
7055: my ($r,$i,$scan_record,$scan_config,$line,$error,$arg)=@_;
1.454 banghart 7056: #FIXME in the case of a duplicated ID the previous line, probably need
1.157 albertel 7057: #to show both the current line and the previous one and allow skipping
7058: #the previous one or the current one
7059:
1.333 albertel 7060: if ( $$scan_record{'scantron.PaperID'} =~ /\S/) {
1.596.2.6 raeburn 7061: $r->print(
7062: '<p class="LC_warning">'
7063: .&mt('An error was detected ([_1]) for PaperID [_2]',
7064: "<b>$error</b>",
7065: '<tt>'.$$scan_record{'scantron.PaperID'}.'</tt>')
7066: ."</p> \n");
1.157 albertel 7067: } else {
1.596.2.6 raeburn 7068: $r->print(
7069: '<p class="LC_warning">'
7070: .&mt('An error was detected ([_1]) in scanline [_2] [_3]',
7071: "<b>$error</b>", $i, "<pre>$line</pre>")
7072: ."</p> \n");
7073: }
7074: my $message =
7075: '<p>'
7076: .&mt('The ID on the form is [_1]',
7077: "<tt>$$scan_record{'scantron.ID'}</tt>")
7078: .'<br />'
1.596.2.12 raeburn 7079: .&mt('The name on the paper is [_1], [_2]',
1.596.2.6 raeburn 7080: $$scan_record{'scantron.LastName'},
7081: $$scan_record{'scantron.FirstName'})
7082: .'</p>';
1.242 albertel 7083:
1.157 albertel 7084: $r->print('<input type="hidden" name="scantron_corrections" value="'.$error.'" />'."\n");
7085: $r->print('<input type="hidden" name="scantron_line" value="'.$i.'" />'."\n");
1.503 raeburn 7086: # Array populated for doublebubble or
7087: my @lines_to_correct; # missingbubble errors to build javascript
7088: # to validate radio button checking
7089:
1.157 albertel 7090: if ($error =~ /ID$/) {
1.186 albertel 7091: if ($error eq 'incorrectID') {
1.596.2.6 raeburn 7092: $r->print('<p class="LC_warning">'.&mt("The encoded ID is not in the classlist").
1.492 albertel 7093: "</p>\n");
1.157 albertel 7094: } elsif ($error eq 'duplicateID') {
1.596.2.6 raeburn 7095: $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 7096: }
1.242 albertel 7097: $r->print($message);
1.492 albertel 7098: $r->print("<p>".&mt("How should I handle this?")." <br /> \n");
1.157 albertel 7099: $r->print("\n<ul><li> ");
7100: #FIXME it would be nice if this sent back the user ID and
7101: #could do partial userID matches
7102: $r->print(&Apache::loncommon::selectstudent_link('scantronupload',
7103: 'scantron_username','scantron_domain'));
7104: $r->print(": <input type='text' name='scantron_username' value='' />");
7105: $r->print("\n@".
1.257 albertel 7106: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'scantron_domain'));
1.157 albertel 7107:
7108: $r->print('</li>');
1.186 albertel 7109: } elsif ($error =~ /CODE$/) {
7110: if ($error eq 'incorrectCODE') {
1.596.2.6 raeburn 7111: $r->print('<p class="LC_warning">'.&mt("The encoded CODE is not in the list of possible CODEs.")."</p>\n");
1.186 albertel 7112: } elsif ($error eq 'duplicateCODE') {
1.596.2.6 raeburn 7113: $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 7114: }
1.596.2.6 raeburn 7115: $r->print("<p>".&mt('The CODE on the form is [_1]',
7116: "<tt>'$$scan_record{'scantron.CODE'}'</tt>")
7117: ."</p>\n");
1.242 albertel 7118: $r->print($message);
1.596.2.6 raeburn 7119: $r->print("<p>".&mt("How should I handle this?")."</p>\n");
1.187 albertel 7120: $r->print("\n<br /> ");
1.194 albertel 7121: my $i=0;
1.273 albertel 7122: if ($error eq 'incorrectCODE'
7123: && $$scan_record{'scantron.CODE'}=~/\S/ ) {
1.194 albertel 7124: my ($max,$closest)=&scantron_get_closely_matching_CODEs($arg,$$scan_record{'scantron.CODE'});
1.278 albertel 7125: if ($closest > 0) {
7126: foreach my $testcode (@{$closest}) {
7127: my $checked='';
1.569 bisitz 7128: if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 7129: $r->print("
7130: <label>
1.569 bisitz 7131: <input type='radio' name='scantron_CODE_resolution' value='use_closest_$i'$checked />
1.492 albertel 7132: ".&mt("Use the similar CODE [_1] instead.",
7133: "<b><tt>".$testcode."</tt></b>")."
7134: </label>
7135: <input type='hidden' name='scantron_CODE_closest_$i' value='$testcode' />");
1.278 albertel 7136: $r->print("\n<br />");
7137: $i++;
7138: }
1.194 albertel 7139: }
7140: }
1.273 albertel 7141: if ($$scan_record{'scantron.CODE'}=~/\S/ ) {
1.569 bisitz 7142: my $checked; if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 7143: $r->print("
7144: <label>
1.569 bisitz 7145: <input type='radio' name='scantron_CODE_resolution' value='use_unfound'$checked />
1.596.2.6 raeburn 7146: ".&mt("Use the CODE [_1] that was on the paper, ignoring the error.",
1.492 albertel 7147: "<b><tt>".$$scan_record{'scantron.CODE'}."</tt></b>")."
7148: </label>");
1.273 albertel 7149: $r->print("\n<br />");
7150: }
1.194 albertel 7151:
1.188 albertel 7152: $r->print(<<ENDSCRIPT);
7153: <script type="text/javascript">
7154: function change_radio(field) {
1.190 albertel 7155: var slct=document.scantronupload.scantron_CODE_resolution;
1.188 albertel 7156: var i;
7157: for (i=0;i<slct.length;i++) {
7158: if (slct[i].value==field) { slct[i].checked=true; }
7159: }
7160: }
7161: </script>
7162: ENDSCRIPT
1.187 albertel 7163: my $href="/adm/pickcode?".
1.359 www 7164: "form=".&escape("scantronupload").
7165: "&scantron_format=".&escape($env{'form.scantron_format'}).
7166: "&scantron_CODElist=".&escape($env{'form.scantron_CODElist'}).
7167: "&curCODE=".&escape($$scan_record{'scantron.CODE'}).
7168: "&scantron_selectfile=".&escape($env{'form.scantron_selectfile'});
1.332 albertel 7169: if ($env{'form.scantron_CODElist'} =~ /\S/) {
1.492 albertel 7170: $r->print("
7171: <label>
7172: <input type='radio' name='scantron_CODE_resolution' value='use_found' />
7173: ".&mt("[_1]Select[_2] a CODE from the list of all CODEs and use it.",
7174: "<a target='_blank' href='$href'>","</a>")."
7175: </label>
1.558 bisitz 7176: ".&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 7177: $r->print("\n<br />");
7178: }
1.492 albertel 7179: $r->print("
7180: <label>
7181: <input type='radio' name='scantron_CODE_resolution' value='use_typed' />
7182: ".&mt("Use [_1] as the CODE.",
7183: "</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 7184: $r->print("\n<br /><br />");
1.157 albertel 7185: } elsif ($error eq 'doublebubble') {
1.596.2.6 raeburn 7186: $r->print('<p class="LC_warning">'.&mt("There have been multiple bubbles scanned for some question(s)")."</p>\n");
1.497 foxr 7187:
7188: # The form field scantron_questions is acutally a list of line numbers.
7189: # represented by this form so:
7190:
7191: my $line_list = &questions_to_line_list($arg);
7192:
1.157 albertel 7193: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 7194: $line_list.'" />');
1.242 albertel 7195: $r->print($message);
1.492 albertel 7196: $r->print("<p>".&mt("Please indicate which bubble should be used for grading")."</p>");
1.157 albertel 7197: foreach my $question (@{$arg}) {
1.503 raeburn 7198: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
7199: $scan_record, $error);
1.524 raeburn 7200: push(@lines_to_correct,@linenums);
1.157 albertel 7201: }
1.503 raeburn 7202: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 7203: } elsif ($error eq 'missingbubble') {
1.596.2.9 raeburn 7204: $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 7205: $r->print($message);
1.492 albertel 7206: $r->print("<p>".&mt("Please indicate which bubble should be used for grading.")."</p>");
1.503 raeburn 7207: $r->print(&mt("Some questions have no scanned bubbles.")."\n");
1.497 foxr 7208:
1.503 raeburn 7209: # The form field scantron_questions is actually a list of line numbers not
1.497 foxr 7210: # a list of question numbers. Therefore:
7211: #
7212:
7213: my $line_list = &questions_to_line_list($arg);
7214:
1.157 albertel 7215: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 7216: $line_list.'" />');
1.157 albertel 7217: foreach my $question (@{$arg}) {
1.503 raeburn 7218: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
7219: $scan_record, $error);
1.524 raeburn 7220: push(@lines_to_correct,@linenums);
1.157 albertel 7221: }
1.503 raeburn 7222: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 7223: } else {
7224: $r->print("\n<ul>");
7225: }
7226: $r->print("\n</li></ul>");
1.497 foxr 7227: }
7228:
1.503 raeburn 7229: sub verify_bubbles_checked {
7230: my (@ansnums) = @_;
7231: my $ansnumstr = join('","',@ansnums);
7232: my $warning = &mt("A bubble or 'No bubble' selection has not been made for one or more lines.");
7233: my $output = (<<ENDSCRIPT);
7234: <script type="text/javascript">
7235: function verify_bubble_radio(form) {
7236: var ansnumArray = new Array ("$ansnumstr");
7237: var need_bubble_count = 0;
7238: for (var i=0; i<ansnumArray.length; i++) {
7239: if (form.elements["scantron_correct_Q_"+ansnumArray[i]].length > 1) {
7240: var bubble_picked = 0;
7241: for (var j=0; j<form.elements["scantron_correct_Q_"+ansnumArray[i]].length; j++) {
7242: if (form.elements["scantron_correct_Q_"+ansnumArray[i]][j].checked == true) {
7243: bubble_picked = 1;
7244: }
7245: }
7246: if (bubble_picked == 0) {
7247: need_bubble_count ++;
7248: }
7249: }
7250: }
7251: if (need_bubble_count) {
7252: alert("$warning");
7253: return;
7254: }
7255: form.submit();
7256: }
7257: </script>
7258: ENDSCRIPT
7259: return $output;
7260: }
7261:
1.497 foxr 7262: =pod
7263:
7264: =item questions_to_line_list
1.157 albertel 7265:
1.497 foxr 7266: Converts a list of questions into a string of comma separated
7267: line numbers in the answer sheet used by the questions. This is
7268: used to fill in the scantron_questions form field.
7269:
7270: Arguments:
7271: questions - Reference to an array of questions.
7272:
7273: =cut
7274:
7275:
7276: sub questions_to_line_list {
7277: my ($questions) = @_;
7278: my @lines;
7279:
1.503 raeburn 7280: foreach my $item (@{$questions}) {
7281: my $question = $item;
7282: my ($first,$count,$last);
7283: if ($item =~ /^(\d+)\.(\d+)$/) {
7284: $question = $1;
7285: my $subquestion = $2;
7286: $first = $first_bubble_line{$question-1} + 1;
7287: my @subans = split(/,/,$subdivided_bubble_lines{$question-1});
7288: my $subcount = 1;
7289: while ($subcount<$subquestion) {
7290: $first += $subans[$subcount-1];
7291: $subcount ++;
7292: }
7293: $count = $subans[$subquestion-1];
7294: } else {
7295: $first = $first_bubble_line{$question-1} + 1;
7296: $count = $bubble_lines_per_response{$question-1};
7297: }
1.506 raeburn 7298: $last = $first+$count-1;
1.503 raeburn 7299: push(@lines, ($first..$last));
1.497 foxr 7300: }
7301: return join(',', @lines);
7302: }
7303:
7304: =pod
7305:
7306: =item prompt_for_corrections
7307:
7308: Prompts for a potentially multiline correction to the
7309: user's bubbling (factors out common code from scantron_get_correction
7310: for multi and missing bubble cases).
7311:
7312: Arguments:
7313: $r - Apache request object.
7314: $question - The question number to prompt for.
7315: $scan_config - The scantron file configuration hash.
7316: $scan_record - Reference to the hash that has the the parsed scanlines.
1.503 raeburn 7317: $error - Type of error
1.497 foxr 7318:
7319: Implicit inputs:
7320: %bubble_lines_per_response - Starting line numbers for each question.
7321: Numbered from 0 (but question numbers are from
7322: 1.
7323: %first_bubble_line - Starting bubble line for each question.
1.509 raeburn 7324: %subdivided_bubble_lines - optionresponse, matchresponse and rankresponse
7325: type problems render as separate sub-questions,
1.503 raeburn 7326: in exam mode. This hash contains a
7327: comma-separated list of the lines per
7328: sub-question.
1.510 raeburn 7329: %responsetype_per_response - essayresponse, formularesponse,
7330: stringresponse, imageresponse, reactionresponse,
7331: and organicresponse type problem parts can have
1.503 raeburn 7332: multiple lines per response if the weight
7333: assigned exceeds 10. In this case, only
7334: one bubble per line is permitted, but more
7335: than one line might contain bubbles, e.g.
7336: bubbling of: line 1 - J, line 2 - J,
7337: line 3 - B would assign 22 points.
1.497 foxr 7338:
7339: =cut
7340:
7341: sub prompt_for_corrections {
1.503 raeburn 7342: my ($r, $question, $scan_config, $scan_record, $error) = @_;
7343: my ($current_line,$lines);
7344: my @linenums;
7345: my $questionnum = $question;
7346: if ($question =~ /^(\d+)\.(\d+)$/) {
7347: $question = $1;
7348: $current_line = $first_bubble_line{$question-1} + 1 ;
7349: my $subquestion = $2;
7350: my @subans = split(/,/,$subdivided_bubble_lines{$question-1});
7351: my $subcount = 1;
7352: while ($subcount<$subquestion) {
7353: $current_line += $subans[$subcount-1];
7354: $subcount ++;
7355: }
7356: $lines = $subans[$subquestion-1];
7357: } else {
7358: $current_line = $first_bubble_line{$question-1} + 1 ;
7359: $lines = $bubble_lines_per_response{$question-1};
7360: }
1.497 foxr 7361: if ($lines > 1) {
1.503 raeburn 7362: $r->print(&mt('The group of bubble lines below responds to a single question.').'<br />');
7363: if (($responsetype_per_response{$question-1} eq 'essayresponse') ||
7364: ($responsetype_per_response{$question-1} eq 'formularesponse') ||
1.510 raeburn 7365: ($responsetype_per_response{$question-1} eq 'stringresponse') ||
7366: ($responsetype_per_response{$question-1} eq 'imageresponse') ||
7367: ($responsetype_per_response{$question-1} eq 'reactionresponse') ||
7368: ($responsetype_per_response{$question-1} eq 'organicresponse')) {
1.572 www 7369: $r->print(&mt("Although this particular question type requires handgrading, the instructions for this question in the exam directed students to leave [quant,_1,line] blank on their bubblesheets.",$lines).'<br /><br />'.&mt('A non-zero score can be assigned to the student during bubblesheet grading by selecting a bubble in at least one line.').'<br />'.&mt('The score for this question will be a sum of the numeric values for the selected bubbles from each line, where A=1 point, B=2 points etc.').'<br />'.&mt("To assign a score of zero for this question, mark all lines as 'No bubble'.").'<br /><br />');
1.503 raeburn 7370: } else {
7371: $r->print(&mt("Select at most one bubble in a single line and select 'No Bubble' in all the other lines. ")."<br />");
7372: }
1.497 foxr 7373: }
7374: for (my $i =0; $i < $lines; $i++) {
1.503 raeburn 7375: my $selected = $$scan_record{"scantron.$current_line.answer"};
7376: &scantron_bubble_selector($r,$scan_config,$current_line,
7377: $questionnum,$error,split('', $selected));
1.524 raeburn 7378: push(@linenums,$current_line);
1.497 foxr 7379: $current_line++;
7380: }
7381: if ($lines > 1) {
7382: $r->print("<hr /><br />");
7383: }
1.503 raeburn 7384: return @linenums;
1.157 albertel 7385: }
1.423 albertel 7386:
7387: =pod
7388:
7389: =item scantron_bubble_selector
7390:
7391: Generates the html radiobuttons to correct a single bubble line
1.424 albertel 7392: possibly showing the existing the selected bubbles if known
1.423 albertel 7393:
7394: Arguments:
7395: $r - Apache request object
7396: $scan_config - hash from &get_scantron_config()
1.497 foxr 7397: $line - Number of the line being displayed.
1.503 raeburn 7398: $questionnum - Question number (may include subquestion)
7399: $error - Type of error.
1.497 foxr 7400: @selected - Array of bubbles picked on this line.
1.423 albertel 7401:
7402: =cut
7403:
1.157 albertel 7404: sub scantron_bubble_selector {
1.503 raeburn 7405: my ($r,$scan_config,$line,$questionnum,$error,@selected)=@_;
1.157 albertel 7406: my $max=$$scan_config{'Qlength'};
1.274 albertel 7407:
7408: my $scmode=$$scan_config{'Qon'};
1.596.2.12.2. (raeburn 7409:): if ($scmode eq 'number' || $scmode eq 'letter') {
7410:): if (($$scan_config{'BubblesPerRow'} =~ /^\d+$/) &&
7411:): ($$scan_config{'BubblesPerRow'} > 0)) {
7412:): $max=$$scan_config{'BubblesPerRow'};
7413:): if (($scmode eq 'number') && ($max > 10)) {
7414:): $max = 10;
7415:): } elsif (($scmode eq 'letter') && $max > 26) {
7416:): $max = 26;
7417:): }
7418:): } else {
7419:): $max = 10;
7420:): }
7421:): }
1.274 albertel 7422:
1.157 albertel 7423: my @alphabet=('A'..'Z');
1.503 raeburn 7424: $r->print(&Apache::loncommon::start_data_table().
7425: &Apache::loncommon::start_data_table_row());
7426: $r->print('<td rowspan="2" class="LC_leftcol_header">'.$line.'</td>');
1.497 foxr 7427: for (my $i=0;$i<$max+1;$i++) {
7428: $r->print("\n".'<td align="center">');
7429: if ($selected[0] eq $alphabet[$i]) { $r->print('X'); shift(@selected) }
7430: else { $r->print(' '); }
7431: $r->print('</td>');
7432: }
1.503 raeburn 7433: $r->print(&Apache::loncommon::end_data_table_row().
7434: &Apache::loncommon::start_data_table_row());
1.497 foxr 7435: for (my $i=0;$i<$max;$i++) {
7436: $r->print("\n".
7437: '<td><label><input type="radio" name="scantron_correct_Q_'.
7438: $line.'" value="'.$i.'" />'.$alphabet[$i]."</label></td>");
7439: }
1.503 raeburn 7440: my $nobub_checked = ' ';
7441: if ($error eq 'missingbubble') {
7442: $nobub_checked = ' checked = "checked" ';
7443: }
7444: $r->print("\n".'<td><label><input type="radio" name="scantron_correct_Q_'.
7445: $line.'" value="none"'.$nobub_checked.'/>'.&mt('No bubble').
7446: '</label>'."\n".'<input type="hidden" name="scantron_questionnum_Q_'.
7447: $line.'" value="'.$questionnum.'" /></td>');
7448: $r->print(&Apache::loncommon::end_data_table_row().
7449: &Apache::loncommon::end_data_table());
1.157 albertel 7450: }
7451:
1.423 albertel 7452: =pod
7453:
7454: =item num_matches
7455:
1.424 albertel 7456: Counts the number of characters that are the same between the two arguments.
7457:
7458: Arguments:
7459: $orig - CODE from the scanline
7460: $code - CODE to match against
7461:
7462: Returns:
7463: $count - integer count of the number of same characters between the
7464: two arguments
7465:
1.423 albertel 7466: =cut
7467:
1.194 albertel 7468: sub num_matches {
7469: my ($orig,$code) = @_;
7470: my @code=split(//,$code);
7471: my @orig=split(//,$orig);
7472: my $same=0;
7473: for (my $i=0;$i<scalar(@code);$i++) {
7474: if ($code[$i] eq $orig[$i]) { $same++; }
7475: }
7476: return $same;
7477: }
7478:
1.423 albertel 7479: =pod
7480:
7481: =item scantron_get_closely_matching_CODEs
7482:
1.424 albertel 7483: Cycles through all CODEs and finds the set that has the greatest
7484: number of same characters as the provided CODE
7485:
7486: Arguments:
7487: $allcodes - hash ref returned by &get_codes()
7488: $CODE - CODE from the current scanline
7489:
7490: Returns:
7491: 2 element list
7492: - first elements is number of how closely matching the best fit is
7493: (5 means best set has 5 matching characters)
7494: - second element is an arrary ref containing the set of valid CODEs
7495: that best fit the passed in CODE
7496:
1.423 albertel 7497: =cut
7498:
1.194 albertel 7499: sub scantron_get_closely_matching_CODEs {
7500: my ($allcodes,$CODE)=@_;
7501: my @CODEs;
7502: foreach my $testcode (sort(keys(%{$allcodes}))) {
7503: push(@{$CODEs[&num_matches($CODE,$testcode)]},$testcode);
7504: }
7505:
7506: return ($#CODEs,$CODEs[-1]);
7507: }
7508:
1.423 albertel 7509: =pod
7510:
7511: =item get_codes
7512:
1.424 albertel 7513: Builds a hash which has keys of all of the valid CODEs from the selected
7514: set of remembered CODEs.
7515:
7516: Arguments:
7517: $old_name - name of the set of remembered CODEs
7518: $cdom - domain of the course
7519: $cnum - internal course name
7520:
7521: Returns:
7522: %allcodes - keys are the valid CODEs, values are all 1
7523:
1.423 albertel 7524: =cut
7525:
1.194 albertel 7526: sub get_codes {
1.280 foxr 7527: my ($old_name, $cdom, $cnum) = @_;
7528: if (!$old_name) {
7529: $old_name=$env{'form.scantron_CODElist'};
7530: }
7531: if (!$cdom) {
7532: $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
7533: }
7534: if (!$cnum) {
7535: $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
7536: }
1.278 albertel 7537: my %result=&Apache::lonnet::get('CODEs',[$old_name,"type\0$old_name"],
7538: $cdom,$cnum);
7539: my %allcodes;
7540: if ($result{"type\0$old_name"} eq 'number') {
7541: %allcodes=map {($_,1)} split(',',$result{$old_name});
7542: } else {
7543: %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
7544: }
1.194 albertel 7545: return %allcodes;
7546: }
7547:
1.423 albertel 7548: =pod
7549:
7550: =item scantron_validate_CODE
7551:
1.424 albertel 7552: Validates all scanlines in the selected file to not have any
7553: invalid or underspecified CODEs and that none of the codes are
7554: duplicated if this was requested.
7555:
1.423 albertel 7556: =cut
7557:
1.157 albertel 7558: sub scantron_validate_CODE {
7559: my ($r,$currentphase) = @_;
1.257 albertel 7560: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.186 albertel 7561: if ($scantron_config{'CODElocation'} &&
7562: $scantron_config{'CODEstart'} &&
7563: $scantron_config{'CODElength'}) {
1.257 albertel 7564: if (!defined($env{'form.scantron_CODElist'})) {
1.186 albertel 7565: &FIXME_blow_up()
7566: }
7567: } else {
7568: return (0,$currentphase+1);
7569: }
7570:
7571: my %usedCODEs;
7572:
1.194 albertel 7573: my %allcodes=&get_codes();
1.186 albertel 7574:
1.582 raeburn 7575: my $nav_error;
1.596.2.12.2. (raeburn 7576:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the lines per response array.
1.582 raeburn 7577: if ($nav_error) {
7578: $r->print(&navmap_errormsg());
7579: return(1,$currentphase);
7580: }
1.447 foxr 7581:
1.186 albertel 7582: my ($scanlines,$scan_data)=&scantron_getfile();
7583: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7584: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.186 albertel 7585: if ($line=~/^[\s\cz]*$/) { next; }
7586: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7587: $scan_data);
7588: my $CODE=$$scan_record{'scantron.CODE'};
7589: my $error=0;
1.224 albertel 7590: if (!&Apache::lonnet::validCODE($CODE)) {
7591: &scantron_get_correction($r,$i,$scan_record,
7592: \%scantron_config,
7593: $line,'incorrectCODE',\%allcodes);
7594: return(1,$currentphase);
7595: }
1.221 albertel 7596: if (%allcodes && !exists($allcodes{$CODE})
7597: && !$$scan_record{'scantron.useCODE'}) {
1.186 albertel 7598: &scantron_get_correction($r,$i,$scan_record,
7599: \%scantron_config,
1.194 albertel 7600: $line,'incorrectCODE',\%allcodes);
7601: return(1,$currentphase);
1.186 albertel 7602: }
1.214 albertel 7603: if (exists($usedCODEs{$CODE})
1.257 albertel 7604: && $env{'form.scantron_CODEunique'} eq 'yes'
1.192 albertel 7605: && !$$scan_record{'scantron.CODE_ignore_dup'}) {
1.186 albertel 7606: &scantron_get_correction($r,$i,$scan_record,
7607: \%scantron_config,
1.194 albertel 7608: $line,'duplicateCODE',$usedCODEs{$CODE});
7609: return(1,$currentphase);
1.186 albertel 7610: }
1.524 raeburn 7611: push(@{$usedCODEs{$CODE}},$$scan_record{'scantron.PaperID'});
1.186 albertel 7612: }
1.157 albertel 7613: return (0,$currentphase+1);
7614: }
7615:
1.423 albertel 7616: =pod
7617:
7618: =item scantron_validate_doublebubble
7619:
1.424 albertel 7620: Validates all scanlines in the selected file to not have any
7621: bubble lines with multiple bubbles marked.
7622:
1.423 albertel 7623: =cut
7624:
1.157 albertel 7625: sub scantron_validate_doublebubble {
7626: my ($r,$currentphase) = @_;
7627: #get student info
7628: my $classlist=&Apache::loncoursedata::get_classlist();
7629: my %idmap=&username_to_idmap($classlist);
7630:
7631: #get scantron line setup
1.257 albertel 7632: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7633: my ($scanlines,$scan_data)=&scantron_getfile();
1.583 raeburn 7634: my $nav_error;
1.596.2.12.2. (raeburn 7635:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the bubble line array.
1.583 raeburn 7636: if ($nav_error) {
7637: $r->print(&navmap_errormsg());
7638: return(1,$currentphase);
7639: }
1.447 foxr 7640:
1.157 albertel 7641: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7642: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7643: if ($line=~/^[\s\cz]*$/) { next; }
7644: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7645: $scan_data);
7646: if (!defined($$scan_record{'scantron.doubleerror'})) { next; }
7647: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,$line,
7648: 'doublebubble',
7649: $$scan_record{'scantron.doubleerror'});
7650: return (1,$currentphase);
7651: }
7652: return (0,$currentphase+1);
7653: }
7654:
1.423 albertel 7655:
1.503 raeburn 7656: sub scantron_get_maxbubble {
1.596.2.12.2. (raeburn 7657:): my ($nav_error,$scantron_config) = @_;
1.257 albertel 7658: if (defined($env{'form.scantron_maxbubble'}) &&
7659: $env{'form.scantron_maxbubble'}) {
1.447 foxr 7660: &restore_bubble_lines();
1.257 albertel 7661: return $env{'form.scantron_maxbubble'};
1.191 albertel 7662: }
1.330 albertel 7663:
1.447 foxr 7664: my (undef, undef, $sequence) =
1.257 albertel 7665: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.330 albertel 7666:
1.447 foxr 7667: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 7668: unless (ref($navmap)) {
7669: if (ref($nav_error)) {
7670: $$nav_error = 1;
7671: }
1.591 raeburn 7672: return;
1.582 raeburn 7673: }
1.191 albertel 7674: my $map=$navmap->getResourceByUrl($sequence);
7675: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.596.2.12.2. (raeburn 7676:): my $bubbles_per_row = &bubblesheet_bubbles_per_row($scantron_config);
1.330 albertel 7677:
7678: &Apache::lonxml::clear_problem_counter();
7679:
1.557 raeburn 7680: my $uname = $env{'user.name'};
7681: my $udom = $env{'user.domain'};
1.435 foxr 7682: my $cid = $env{'request.course.id'};
7683: my $total_lines = 0;
7684: %bubble_lines_per_response = ();
1.447 foxr 7685: %first_bubble_line = ();
1.503 raeburn 7686: %subdivided_bubble_lines = ();
7687: %responsetype_per_response = ();
1.554 raeburn 7688:
1.447 foxr 7689: my $response_number = 0;
7690: my $bubble_line = 0;
1.191 albertel 7691: foreach my $resource (@resources) {
1.596.2.12.2. (raeburn 7692:): my ($analysis,$parts) = &scantron_partids_tograde($resource,$cid,$uname,
7693:): $udom,$bubbles_per_row);
1.542 raeburn 7694: if ((ref($analysis) eq 'HASH') && (ref($parts) eq 'ARRAY')) {
7695: foreach my $part_id (@{$parts}) {
7696: my $lines;
7697:
7698: # TODO - make this a persistent hash not an array.
7699:
7700: # optionresponse, matchresponse and rankresponse type items
7701: # render as separate sub-questions in exam mode.
7702: if (($analysis->{$part_id.'.type'} eq 'optionresponse') ||
7703: ($analysis->{$part_id.'.type'} eq 'matchresponse') ||
7704: ($analysis->{$part_id.'.type'} eq 'rankresponse')) {
7705: my ($numbub,$numshown);
7706: if ($analysis->{$part_id.'.type'} eq 'optionresponse') {
7707: if (ref($analysis->{$part_id.'.options'}) eq 'ARRAY') {
7708: $numbub = scalar(@{$analysis->{$part_id.'.options'}});
7709: }
7710: } elsif ($analysis->{$part_id.'.type'} eq 'matchresponse') {
7711: if (ref($analysis->{$part_id.'.items'}) eq 'ARRAY') {
7712: $numbub = scalar(@{$analysis->{$part_id.'.items'}});
7713: }
7714: } elsif ($analysis->{$part_id.'.type'} eq 'rankresponse') {
7715: if (ref($analysis->{$part_id.'.foils'}) eq 'ARRAY') {
7716: $numbub = scalar(@{$analysis->{$part_id.'.foils'}});
7717: }
7718: }
7719: if (ref($analysis->{$part_id.'.shown'}) eq 'ARRAY') {
7720: $numshown = scalar(@{$analysis->{$part_id.'.shown'}});
7721: }
1.596.2.12.2. (raeburn 7722:): my $bubbles_per_row =
7723:): &bubblesheet_bubbles_per_row($scantron_config);
7724:): my $inner_bubble_lines = int($numbub/$bubbles_per_row);
7725:): if (($numbub % $bubbles_per_row) != 0) {
1.542 raeburn 7726: $inner_bubble_lines++;
7727: }
7728: for (my $i=0; $i<$numshown; $i++) {
7729: $subdivided_bubble_lines{$response_number} .=
7730: $inner_bubble_lines.',';
7731: }
7732: $subdivided_bubble_lines{$response_number} =~ s/,$//;
7733: $lines = $numshown * $inner_bubble_lines;
7734: } else {
7735: $lines = $analysis->{"$part_id.bubble_lines"};
1.596.2.12.2. (raeburn 7736:): }
1.542 raeburn 7737:
7738: $first_bubble_line{$response_number} = $bubble_line;
7739: $bubble_lines_per_response{$response_number} = $lines;
7740: $responsetype_per_response{$response_number} =
7741: $analysis->{$part_id.'.type'};
7742: $response_number++;
7743:
7744: $bubble_line += $lines;
7745: $total_lines += $lines;
7746: }
7747: }
7748: }
1.552 raeburn 7749: &Apache::lonnet::delenv('scantron.');
1.542 raeburn 7750:
7751: &save_bubble_lines();
7752: $env{'form.scantron_maxbubble'} =
7753: $total_lines;
7754: return $env{'form.scantron_maxbubble'};
7755: }
1.523 raeburn 7756:
1.596.2.12.2. (raeburn 7757:): sub bubblesheet_bubbles_per_row {
7758:): my ($scantron_config) = @_;
7759:): my $bubbles_per_row;
7760:): if (ref($scantron_config) eq 'HASH') {
7761:): $bubbles_per_row = $scantron_config->{'BubblesPerRow'};
7762:): }
7763:): if ((!$bubbles_per_row) || ($bubbles_per_row < 1)) {
7764:): $bubbles_per_row = 10;
7765:): }
7766:): return $bubbles_per_row;
7767:): }
7768:):
1.157 albertel 7769: sub scantron_validate_missingbubbles {
7770: my ($r,$currentphase) = @_;
7771: #get student info
7772: my $classlist=&Apache::loncoursedata::get_classlist();
7773: my %idmap=&username_to_idmap($classlist);
7774:
7775: #get scantron line setup
1.257 albertel 7776: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7777: my ($scanlines,$scan_data)=&scantron_getfile();
1.582 raeburn 7778: my $nav_error;
1.596.2.12.2. (raeburn 7779:): my $max_bubble=&scantron_get_maxbubble(\$nav_error,\%scantron_config);
1.582 raeburn 7780: if ($nav_error) {
7781: return(1,$currentphase);
7782: }
1.157 albertel 7783: if (!$max_bubble) { $max_bubble=2**31; }
7784: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7785: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7786: if ($line=~/^[\s\cz]*$/) { next; }
7787: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7788: $scan_data);
7789: if (!defined($$scan_record{'scantron.missingerror'})) { next; }
7790: my @to_correct;
1.470 foxr 7791:
7792: # Probably here's where the error is...
7793:
1.157 albertel 7794: foreach my $missing (@{$$scan_record{'scantron.missingerror'}}) {
1.505 raeburn 7795: my $lastbubble;
7796: if ($missing =~ /^(\d+)\.(\d+)$/) {
7797: my $question = $1;
7798: my $subquestion = $2;
7799: if (!defined($first_bubble_line{$question -1})) { next; }
7800: my $first = $first_bubble_line{$question-1};
7801: my @subans = split(/,/,$subdivided_bubble_lines{$question-1});
7802: my $subcount = 1;
7803: while ($subcount<$subquestion) {
7804: $first += $subans[$subcount-1];
7805: $subcount ++;
7806: }
7807: my $count = $subans[$subquestion-1];
7808: $lastbubble = $first + $count;
7809: } else {
7810: if (!defined($first_bubble_line{$missing - 1})) { next; }
7811: $lastbubble = $first_bubble_line{$missing - 1} + $bubble_lines_per_response{$missing - 1};
7812: }
7813: if ($lastbubble > $max_bubble) { next; }
1.157 albertel 7814: push(@to_correct,$missing);
7815: }
7816: if (@to_correct) {
7817: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
7818: $line,'missingbubble',\@to_correct);
7819: return (1,$currentphase);
7820: }
7821:
7822: }
7823: return (0,$currentphase+1);
7824: }
7825:
1.596.2.12.2. (raeburn 7826:): sub hand_bubble_option {
7827:): my (undef, undef, $sequence) =
7828:): &Apache::lonnet::decode_symb($env{'form.selectpage'});
7829:): return if ($sequence eq '');
7830:): my $navmap = Apache::lonnavmaps::navmap->new();
7831:): unless (ref($navmap)) {
7832:): return;
7833:): }
7834:): my $needs_hand_bubbles;
7835:): my $map=$navmap->getResourceByUrl($sequence);
7836:): my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
7837:): foreach my $res (@resources) {
7838:): if (ref($res)) {
7839:): if ($res->is_problem()) {
7840:): my $partlist = $res->parts();
7841:): foreach my $part (@{ $partlist }) {
7842:): my @types = $res->responseType($part);
7843:): if (grep(/^(chem|essay|image|formula|math|string|functionplot)$/,@types)) {
7844:): $needs_hand_bubbles = 1;
7845:): last;
7846:): }
7847:): }
7848:): }
7849:): }
7850:): }
7851:): if ($needs_hand_bubbles) {
7852:): my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
7853:): my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
7854:): return &mt('The sequence to be graded contains response types which are handgraded.').'<p>'.
7855:): &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 />').
7856:): '<label><input type="radio" name="scantron_lastbubblepoints" value="'.$bubbles_per_row.'" checked="checked" />'.&mt('[quant,_1,point]',$bubbles_per_row).'</label> '.&mt('or').' '.
7857:): '<label><input type="radio" name="scantron_lastbubblepoints" value="0"/>0 points</label></p>';
7858:): }
7859:): return;
7860:): }
1.423 albertel 7861:
1.82 albertel 7862: sub scantron_process_students {
1.75 albertel 7863: my ($r) = @_;
1.513 foxr 7864:
1.257 albertel 7865: my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($env{'form.selectpage'});
1.324 albertel 7866: my ($symb)=&get_symb($r);
1.513 foxr 7867: if (!$symb) {
7868: return '';
7869: }
1.324 albertel 7870: my $default_form_data=&defaultFormData($symb);
1.82 albertel 7871:
1.257 albertel 7872: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7873: my ($scanlines,$scan_data)=&scantron_getfile();
1.82 albertel 7874: my $classlist=&Apache::loncoursedata::get_classlist();
7875: my %idmap=&username_to_idmap($classlist);
1.132 bowersj2 7876: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 7877: unless (ref($navmap)) {
7878: $r->print(&navmap_errormsg());
7879: return '';
7880: }
1.83 albertel 7881: my $map=$navmap->getResourceByUrl($sequence);
7882: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.557 raeburn 7883: my (%grader_partids_by_symb,%grader_randomlists_by_symb);
7884: &graders_resources_pass(\@resources,\%grader_partids_by_symb,
7885: \%grader_randomlists_by_symb);
1.586 raeburn 7886: my $resource_error;
1.557 raeburn 7887: foreach my $resource (@resources) {
1.586 raeburn 7888: my $ressymb;
7889: if (ref($resource)) {
7890: $ressymb = $resource->symb();
7891: } else {
7892: $resource_error = 1;
7893: last;
7894: }
1.557 raeburn 7895: my ($analysis,$parts) =
7896: &scantron_partids_tograde($resource,$env{'request.course.id'},
1.596.2.12.2. (raeburn 7897:): $env{'user.name'},$env{'user.domain'},
7898:): 1,$bubbles_per_row);
1.557 raeburn 7899: $grader_partids_by_symb{$ressymb} = $parts;
7900: if (ref($analysis) eq 'HASH') {
7901: if (ref($analysis->{'parts_withrandomlist'}) eq 'ARRAY') {
7902: $grader_randomlists_by_symb{$ressymb} =
7903: $analysis->{'parts_withrandomlist'};
7904: }
7905: }
7906: }
1.586 raeburn 7907: if ($resource_error) {
7908: $r->print(&navmap_errormsg());
7909: return '';
7910: }
1.557 raeburn 7911:
1.554 raeburn 7912: my ($uname,$udom);
1.82 albertel 7913: my $result= <<SCANTRONFORM;
1.81 albertel 7914: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
7915: <input type="hidden" name="command" value="scantron_configphase" />
7916: $default_form_data
7917: SCANTRONFORM
1.82 albertel 7918: $r->print($result);
7919:
7920: my @delayqueue;
1.542 raeburn 7921: my (%completedstudents,%scandata);
1.140 albertel 7922:
1.520 www 7923: my $lock=&Apache::lonnet::set_lock(&mt('Grading bubblesheet exam'));
1.200 albertel 7924: my $count=&get_todo_count($scanlines,$scan_data);
1.575 www 7925: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Bubblesheet Status',
7926: 'Bubblesheet Progress',$count,
1.195 albertel 7927: 'inline',undef,'scantronupload');
1.140 albertel 7928: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
7929: 'Processing first student');
1.542 raeburn 7930: $r->print('<br />');
1.140 albertel 7931: my $start=&Time::HiRes::time();
1.158 albertel 7932: my $i=-1;
1.542 raeburn 7933: my $started;
1.447 foxr 7934:
1.582 raeburn 7935: my $nav_error;
1.596.2.12.2. (raeburn 7936:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # Need the bubble lines array to parse.
1.582 raeburn 7937: if ($nav_error) {
7938: $r->print(&navmap_errormsg());
7939: return '';
7940: }
7941:
1.513 foxr 7942: # If an ssi failed in scantron_get_maxbubble, put an error message out to
7943: # the user and return.
7944:
7945: if ($ssi_error) {
7946: $r->print("</form>");
7947: &ssi_print_error($r);
7948: $r->print(&show_grading_menu_form($symb));
1.520 www 7949: &Apache::lonnet::remove_lock($lock);
1.513 foxr 7950: return ''; # Dunno why the other returns return '' rather than just returning.
7951: }
1.447 foxr 7952:
1.542 raeburn 7953: my %lettdig = &letter_to_digits();
7954: my $numletts = scalar(keys(%lettdig));
7955:
1.157 albertel 7956: while ($i<$scanlines->{'count'}) {
7957: ($uname,$udom)=('','');
7958: $i++;
1.200 albertel 7959: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7960: if ($line=~/^[\s\cz]*$/) { next; }
1.200 albertel 7961: if ($started) {
7962: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
7963: 'last student');
7964: }
7965: $started=1;
1.157 albertel 7966: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7967: $scan_data);
7968: unless ($uname=&scantron_find_student($scan_record,$scan_data,
7969: \%idmap,$i)) {
7970: &scantron_add_delay(\@delayqueue,$line,
7971: 'Unable to find a student that matches',1);
7972: next;
7973: }
7974: if (exists $completedstudents{$uname}) {
7975: &scantron_add_delay(\@delayqueue,$line,
7976: 'Student '.$uname.' has multiple sheets',2);
7977: next;
7978: }
7979: ($uname,$udom)=split(/:/,$uname);
1.330 albertel 7980:
1.586 raeburn 7981: my (%partids_by_symb,$res_error);
1.554 raeburn 7982: foreach my $resource (@resources) {
1.586 raeburn 7983: my $ressymb;
7984: if (ref($resource)) {
7985: $ressymb = $resource->symb();
7986: } else {
7987: $res_error = 1;
7988: last;
7989: }
1.557 raeburn 7990: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
7991: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
7992: my ($analysis,$parts) =
1.596.2.12.2. (raeburn 7993:): &scantron_partids_tograde($resource,$env{'request.course.id'},
7994:): $uname,$udom,undef,$bubbles_per_row);
1.557 raeburn 7995: $partids_by_symb{$ressymb} = $parts;
7996: } else {
7997: $partids_by_symb{$ressymb} = $grader_partids_by_symb{$ressymb};
7998: }
1.554 raeburn 7999: }
8000:
1.586 raeburn 8001: if ($res_error) {
8002: &scantron_add_delay(\@delayqueue,$line,
8003: 'An error occurred while grading student '.$uname,2);
8004: next;
8005: }
8006:
1.330 albertel 8007: &Apache::lonxml::clear_problem_counter();
1.514 raeburn 8008: &Apache::lonnet::appenv($scan_record);
1.376 albertel 8009:
8010: if (&scantron_clear_skip($scanlines,$scan_data,$i)) {
8011: &scantron_putfile($scanlines,$scan_data);
8012: }
1.161 albertel 8013:
1.542 raeburn 8014: my $scancode;
8015: if ((exists($scan_record->{'scantron.CODE'})) &&
8016: (&Apache::lonnet::validCODE($scan_record->{'scantron.CODE'}))) {
8017: $scancode = $scan_record->{'scantron.CODE'};
8018: } else {
8019: $scancode = '';
8020: }
8021:
8022: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
1.596.2.12.2. (raeburn 8023:): \@resources,\%partids_by_symb,
8024:): $bubbles_per_row) eq 'ssi_error') {
1.542 raeburn 8025: $ssi_error = 0; # So end of handler error message does not trigger.
8026: $r->print("</form>");
8027: &ssi_print_error($r);
8028: $r->print(&show_grading_menu_form($symb));
8029: &Apache::lonnet::remove_lock($lock);
8030: return ''; # Why return ''? Beats me.
8031: }
1.513 foxr 8032:
1.140 albertel 8033: $completedstudents{$uname}={'line'=>$line};
1.542 raeburn 8034: if ($env{'form.verifyrecord'}) {
8035: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
8036: my $studentdata = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
8037: chomp($studentdata);
8038: $studentdata =~ s/\r$//;
8039: my $studentrecord = '';
8040: my $counter = -1;
8041: foreach my $resource (@resources) {
1.554 raeburn 8042: my $ressymb = $resource->symb();
1.542 raeburn 8043: ($counter,my $recording) =
8044: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 8045: $counter,$studentdata,$partids_by_symb{$ressymb},
1.542 raeburn 8046: \%scantron_config,\%lettdig,$numletts);
8047: $studentrecord .= $recording;
8048: }
8049: if ($studentrecord ne $studentdata) {
1.554 raeburn 8050: &Apache::lonxml::clear_problem_counter();
8051: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
1.596.2.12.2. (raeburn 8052:): \@resources,\%partids_by_symb,
8053:): $bubbles_per_row) eq 'ssi_error') {
1.554 raeburn 8054: $ssi_error = 0; # So end of handler error message does not trigger.
8055: $r->print("</form>");
8056: &ssi_print_error($r);
8057: $r->print(&show_grading_menu_form($symb));
8058: &Apache::lonnet::remove_lock($lock);
8059: delete($completedstudents{$uname});
8060: return '';
8061: }
1.542 raeburn 8062: $counter = -1;
8063: $studentrecord = '';
8064: foreach my $resource (@resources) {
1.554 raeburn 8065: my $ressymb = $resource->symb();
1.542 raeburn 8066: ($counter,my $recording) =
8067: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 8068: $counter,$studentdata,$partids_by_symb{$ressymb},
1.542 raeburn 8069: \%scantron_config,\%lettdig,$numletts);
8070: $studentrecord .= $recording;
8071: }
8072: if ($studentrecord ne $studentdata) {
1.596.2.6 raeburn 8073: $r->print('<p><span class="LC_warning">');
1.542 raeburn 8074: if ($scancode eq '') {
1.596.2.6 raeburn 8075: $r->print(&mt('Mismatch grading bubblesheet for user: [_1] with ID: [_2].',
1.542 raeburn 8076: $uname.':'.$udom,$scan_record->{'scantron.ID'}));
8077: } else {
1.596.2.6 raeburn 8078: $r->print(&mt('Mismatch grading bubblesheet for user: [_1] with ID: [_2] and CODE: [_3].',
1.542 raeburn 8079: $uname.':'.$udom,$scan_record->{'scantron.ID'},$scancode));
8080: }
8081: $r->print('</span><br />'.&Apache::loncommon::start_data_table()."\n".
8082: &Apache::loncommon::start_data_table_header_row()."\n".
8083: '<th>'.&mt('Source').'</th><th>'.&mt('Bubbled responses').'</th>'.
8084: &Apache::loncommon::end_data_table_header_row()."\n".
8085: &Apache::loncommon::start_data_table_row().
1.596.2.6 raeburn 8086: '<td>'.&mt('Bubblesheet').'</td>'.
1.542 raeburn 8087: '<td><span class="LC_nobreak">'.$studentdata.'</span></td>'.
8088: &Apache::loncommon::end_data_table_row().
8089: &Apache::loncommon::start_data_table_row().
1.596.2.6 raeburn 8090: '<td>'.&mt('Stored submissions').'</td>'.
1.542 raeburn 8091: '<td><span class="LC_nobreak">'.$studentrecord.'</span></td>'."\n".
8092: &Apache::loncommon::end_data_table_row().
8093: &Apache::loncommon::end_data_table().'</p>');
8094: } else {
8095: $r->print('<br /><span class="LC_warning">'.
8096: &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 />'.
8097: &mt("As a consequence, this user's submission history records two tries.").
8098: '</span><br />');
8099: }
8100: }
8101: }
1.543 raeburn 8102: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.140 albertel 8103: } continue {
1.330 albertel 8104: &Apache::lonxml::clear_problem_counter();
1.552 raeburn 8105: &Apache::lonnet::delenv('scantron.');
1.82 albertel 8106: }
1.140 albertel 8107: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.520 www 8108: &Apache::lonnet::remove_lock($lock);
1.172 albertel 8109: # my $lasttime = &Time::HiRes::time()-$start;
8110: # $r->print("<p>took $lasttime</p>");
1.140 albertel 8111:
1.200 albertel 8112: $r->print("</form>");
1.324 albertel 8113: $r->print(&show_grading_menu_form($symb));
1.157 albertel 8114: return '';
1.75 albertel 8115: }
1.157 albertel 8116:
1.557 raeburn 8117: sub graders_resources_pass {
8118: my ($resources,$grader_partids_by_symb,$grader_randomlists_by_symb) = @_;
8119: if ((ref($resources) eq 'ARRAY') && (ref($grader_partids_by_symb)) &&
8120: (ref($grader_randomlists_by_symb) eq 'HASH')) {
8121: foreach my $resource (@{$resources}) {
8122: my $ressymb = $resource->symb();
8123: my ($analysis,$parts) =
8124: &scantron_partids_tograde($resource,$env{'request.course.id'},
1.596.2.12.2. (raeburn 8125:): $env{'user.name'},$env{'user.domain'},
8126:): 1,$bubbles_per_row);
1.557 raeburn 8127: $grader_partids_by_symb->{$ressymb} = $parts;
8128: if (ref($analysis) eq 'HASH') {
8129: if (ref($analysis->{'parts_withrandomlist'}) eq 'ARRAY') {
8130: $grader_randomlists_by_symb->{$ressymb} =
8131: $analysis->{'parts_withrandomlist'};
8132: }
8133: }
8134: }
8135: }
8136: return;
8137: }
8138:
1.542 raeburn 8139: sub grade_student_bubbles {
1.596.2.12.2. (raeburn 8140:): my ($r,$uname,$udom,$scan_record,$scancode,$resources,$parts,$bubbles_per_row) = @_;
1.554 raeburn 8141: if (ref($resources) eq 'ARRAY') {
8142: my $count = 0;
8143: foreach my $resource (@{$resources}) {
8144: my $ressymb = $resource->symb();
8145: my %form = ('submitted' => 'scantron',
8146: 'grade_target' => 'grade',
8147: 'grade_username' => $uname,
8148: 'grade_domain' => $udom,
8149: 'grade_courseid' => $env{'request.course.id'},
8150: 'grade_symb' => $ressymb,
8151: 'CODE' => $scancode
8152: );
1.596.2.12.2. (raeburn 8153:): if ($bubbles_per_row ne '') {
8154:): $form{'bubbles_per_row'} = $bubbles_per_row;
8155:): }
8156:): if ($env{'form.scantron_lastbubblepoints'} ne '') {
8157:): $form{'scantron_lastbubblepoints'} = $env{'form.scantron_lastbubblepoints'};
8158:): }
1.554 raeburn 8159: if (ref($parts) eq 'HASH') {
8160: if (ref($parts->{$ressymb}) eq 'ARRAY') {
8161: foreach my $part (@{$parts->{$ressymb}}) {
8162: $form{'scantron_questnum_start.'.$part} =
8163: 1+$env{'form.scantron.first_bubble_line.'.$count};
8164: $count++;
8165: }
8166: }
8167: }
8168: my $result=&ssi_with_retries($resource->src(),$ssi_retries,%form);
8169: return 'ssi_error' if ($ssi_error);
8170: last if (&Apache::loncommon::connection_aborted($r));
8171: }
1.542 raeburn 8172: }
8173: return;
8174: }
8175:
1.157 albertel 8176: sub scantron_upload_scantron_data {
8177: my ($r)=@_;
1.565 raeburn 8178: my $dom = $env{'request.role.domain'};
8179: my $domdesc = &Apache::lonnet::domain($dom,'description');
8180: $r->print(&Apache::loncommon::coursebrowser_javascript($dom));
1.157 albertel 8181: my $select_link=&Apache::loncommon::selectcourse_link('rules','courseid',
1.181 albertel 8182: 'domainid',
1.565 raeburn 8183: 'coursename',$dom);
8184: my $syllabuslink = '<a href="javascript:ToSyllabus();">'.&mt('Syllabus').'</a>'.
8185: (' 'x2).&mt('(shows course personnel)');
1.324 albertel 8186: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.579 raeburn 8187: my $nofile_alert = &mt('Please use the browse button to select a file from your local directory.');
8188: 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.492 albertel 8189: $r->print('
1.157 albertel 8190: <script type="text/javascript" language="javascript">
8191: function checkUpload(formname) {
8192: if (formname.upfile.value == "") {
1.579 raeburn 8193: alert("'.$nofile_alert.'");
1.157 albertel 8194: return false;
8195: }
1.565 raeburn 8196: if (formname.courseid.value == "") {
1.579 raeburn 8197: alert("'.$nocourseid_alert.'");
1.565 raeburn 8198: return false;
8199: }
1.157 albertel 8200: formname.submit();
8201: }
1.565 raeburn 8202:
8203: function ToSyllabus() {
8204: var cdom = '."'$dom'".';
8205: var cnum = document.rules.courseid.value;
8206: if (cdom == "" || cdom == null) {
8207: return;
8208: }
8209: if (cnum == "" || cnum == null) {
8210: return;
8211: }
8212: syllwin=window.open("/public/"+cdom+"/"+cnum+"/syllabus","LONCAPASyllabus",
8213: "height=350,width=350,scrollbars=yes,menubar=no");
8214: return;
8215: }
8216:
1.157 albertel 8217: </script>
8218:
1.596.2.4 raeburn 8219: <h3>'.&mt('Send bubblesheet data to a course').'</h3>
1.566 raeburn 8220:
1.492 albertel 8221: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
1.565 raeburn 8222: '.$default_form_data.
8223: &Apache::lonhtmlcommon::start_pick_box().
8224: &Apache::lonhtmlcommon::row_title(&mt('Course ID')).
8225: '<input name="courseid" type="text" size="30" />'.$select_link.
8226: &Apache::lonhtmlcommon::row_closure().
8227: &Apache::lonhtmlcommon::row_title(&mt('Course Name')).
8228: '<input name="coursename" type="text" size="30" />'.$syllabuslink.
8229: &Apache::lonhtmlcommon::row_closure().
8230: &Apache::lonhtmlcommon::row_title(&mt('Domain')).
8231: '<input name="domainid" type="hidden" />'.$domdesc.
8232: &Apache::lonhtmlcommon::row_closure().
8233: &Apache::lonhtmlcommon::row_title(&mt('File to upload')).
8234: '<input type="file" name="upfile" size="50" />'.
8235: &Apache::lonhtmlcommon::row_closure(1).
8236: &Apache::lonhtmlcommon::end_pick_box().'<br />
8237:
1.492 albertel 8238: <input name="command" value="scantronupload_save" type="hidden" />
1.589 bisitz 8239: <input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
1.157 albertel 8240: </form>
1.492 albertel 8241: ');
1.157 albertel 8242: return '';
8243: }
8244:
1.423 albertel 8245:
1.157 albertel 8246: sub scantron_upload_scantron_data_save {
8247: my($r)=@_;
1.324 albertel 8248: my ($symb)=&get_symb($r,1);
1.182 albertel 8249: my $doanotherupload=
8250: '<br /><form action="/adm/grades" method="post">'."\n".
8251: '<input type="hidden" name="command" value="scantronupload" />'."\n".
1.492 albertel 8252: '<input type="submit" name="submit" value="'.&mt('Do Another Upload').'" />'."\n".
1.182 albertel 8253: '</form>'."\n";
1.257 albertel 8254: if (!&Apache::lonnet::allowed('usc',$env{'form.domainid'}) &&
1.162 albertel 8255: !&Apache::lonnet::allowed('usc',
1.257 albertel 8256: $env{'form.domainid'}.'_'.$env{'form.courseid'})) {
1.575 www 8257: $r->print(&mt("You are not allowed to upload bubblesheet data to the requested course.")."<br />");
1.182 albertel 8258: if ($symb) {
1.324 albertel 8259: $r->print(&show_grading_menu_form($symb));
1.182 albertel 8260: } else {
8261: $r->print($doanotherupload);
8262: }
1.162 albertel 8263: return '';
8264: }
1.257 albertel 8265: my %coursedata=&Apache::lonnet::coursedescription($env{'form.domainid'}.'_'.$env{'form.courseid'});
1.568 raeburn 8266: my $uploadedfile;
1.567 raeburn 8267: $r->print('<h3>'.&mt("Uploading file to [_1]",$coursedata{'description'}).'</h3>');
1.257 albertel 8268: if (length($env{'form.upfile'}) < 2) {
1.568 raeburn 8269: $r->print(&mt('[_1]Error:[_2] The file you attempted to upload, [_3] contained no information. Please check that you entered the correct filename.','<span class="LC_error">','</span>','<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'));
1.183 albertel 8270: } else {
1.568 raeburn 8271: my $result =
8272: &Apache::lonnet::userfileupload('upfile','','scantron','','','',
8273: $env{'form.courseid'},$env{'form.domainid'});
8274: if ($result =~ m{^/uploaded/}) {
1.567 raeburn 8275: $r->print(&mt('[_1]Success:[_2] Successfully uploaded [_3] bytes of data into location: [_4]',
8276: '<span class="LC_success">','</span>',(length($env{'form.upfile'})-1),
8277: '<span class="LC_filename">'.$result.'</span>'));
1.568 raeburn 8278: ($uploadedfile) = ($result =~ m{/([^/]+)$});
1.567 raeburn 8279: $r->print(&validate_uploaded_scantron_file($env{'form.domainid'},
1.568 raeburn 8280: $env{'form.courseid'},$uploadedfile));
1.210 albertel 8281: } else {
1.567 raeburn 8282: $r->print(&mt('[_1]Error:[_2] An error ([_3]) occurred when attempting to upload the file, [_4]',
8283: '<span class="LC_error">','</span>',$result,
1.568 raeburn 8284: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'));
1.183 albertel 8285: }
8286: }
1.174 albertel 8287: if ($symb) {
1.209 ng 8288: $r->print(&scantron_selectphase($r,$uploadedfile));
1.174 albertel 8289: } else {
1.182 albertel 8290: $r->print($doanotherupload);
1.174 albertel 8291: }
1.157 albertel 8292: return '';
8293: }
8294:
1.567 raeburn 8295: sub validate_uploaded_scantron_file {
8296: my ($cdom,$cname,$fname) = @_;
8297: my $scanlines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.$fname);
8298: my @lines;
8299: if ($scanlines ne '-1') {
8300: @lines=split("\n",$scanlines,-1);
8301: }
8302: my $output;
8303: if (@lines) {
8304: my (%counts,$max_match_format);
8305: my ($max_match_count,$max_match_pct) = (0,0);
8306: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cname);
8307: my %idmap = &username_to_idmap($classlist);
8308: foreach my $key (keys(%idmap)) {
8309: my $lckey = lc($key);
8310: $idmap{$lckey} = $idmap{$key};
8311: }
8312: my %unique_formats;
8313: my @formatlines = &get_scantronformat_file();
8314: foreach my $line (@formatlines) {
8315: chomp($line);
8316: my @config = split(/:/,$line);
8317: my $idstart = $config[5];
8318: my $idlength = $config[6];
8319: if (($idstart ne '') && ($idlength > 0)) {
8320: if (ref($unique_formats{$idstart.':'.$idlength}) eq 'ARRAY') {
8321: push(@{$unique_formats{$idstart.':'.$idlength}},$config[0].':'.$config[1]);
8322: } else {
8323: $unique_formats{$idstart.':'.$idlength} = [$config[0].':'.$config[1]];
8324: }
8325: }
8326: }
8327: foreach my $key (keys(%unique_formats)) {
8328: my ($idstart,$idlength) = split(':',$key);
8329: %{$counts{$key}} = (
8330: 'found' => 0,
8331: 'total' => 0,
8332: );
8333: foreach my $line (@lines) {
8334: next if ($line =~ /^#/);
8335: next if ($line =~ /^[\s\cz]*$/);
8336: my $id = substr($line,$idstart-1,$idlength);
8337: $id = lc($id);
8338: if (exists($idmap{$id})) {
8339: $counts{$key}{'found'} ++;
8340: }
8341: $counts{$key}{'total'} ++;
8342: }
8343: if ($counts{$key}{'total'}) {
8344: my $percent_match = (100*$counts{$key}{'found'})/($counts{$key}{'total'});
8345: if (($max_match_format eq '') || ($percent_match > $max_match_pct)) {
8346: $max_match_pct = $percent_match;
8347: $max_match_format = $key;
8348: $max_match_count = $counts{$key}{'total'};
8349: }
8350: }
8351: }
8352: if (ref($unique_formats{$max_match_format}) eq 'ARRAY') {
8353: my $format_descs;
8354: my $numwithformat = @{$unique_formats{$max_match_format}};
8355: for (my $i=0; $i<$numwithformat; $i++) {
8356: my ($name,$desc) = split(':',$unique_formats{$max_match_format}[$i]);
8357: if ($i<$numwithformat-2) {
8358: $format_descs .= '"<i>'.$desc.'</i>", ';
8359: } elsif ($i==$numwithformat-2) {
8360: $format_descs .= '"<i>'.$desc.'</i>" '.&mt('and').' ';
8361: } elsif ($i==$numwithformat-1) {
8362: $format_descs .= '"<i>'.$desc.'</i>"';
8363: }
8364: }
8365: my $showpct = sprintf("%.0f",$max_match_pct).'%';
8366: $output .= '<br />'.&mt('Comparison of student IDs in the uploaded file with the course roster found matches for [_1] of the [_2] entries in the file (for the format defined for [_3]).','<b>'.$showpct.'</b>','<b>'.$max_match_count.'</b>',$format_descs).
8367: '<br />'.&mt('A low percentage of matches results from one of the following:').'<ul>'.
8368: '<li>'.&mt('The file was uploaded to the wrong course').'</li>'.
8369: '<li>'.&mt('The data are not in the format expected for the domain: [_1]',
8370: '<i>'.$cdom.'</i>').'</li>'.
8371: '<li>'.&mt('Students did not bubble their IDs, or mis-bubbled them').'</li>'.
8372: '<li>'.&mt('The course roster is not up to date').'</li>'.
8373: '</ul>';
8374: }
8375: } else {
8376: $output = '<span class="LC_warning">'.&mt('Uploaded file contained no data').'</span>';
8377: }
8378: return $output;
8379: }
8380:
1.202 albertel 8381: sub valid_file {
8382: my ($requested_file)=@_;
8383: foreach my $filename (sort(&scantron_filenames())) {
8384: if ($requested_file eq $filename) { return 1; }
8385: }
8386: return 0;
8387: }
8388:
8389: sub scantron_download_scantron_data {
8390: my ($r)=@_;
1.324 albertel 8391: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.257 albertel 8392: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
8393: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
8394: my $file=$env{'form.scantron_selectfile'};
1.202 albertel 8395: if (! &valid_file($file)) {
1.492 albertel 8396: $r->print('
1.202 albertel 8397: <p>
1.492 albertel 8398: '.&mt('The requested file name was invalid.').'
1.202 albertel 8399: </p>
1.492 albertel 8400: ');
1.324 albertel 8401: $r->print(&show_grading_menu_form(&get_symb($r,1)));
1.202 albertel 8402: return;
8403: }
8404: my $orig='/uploaded/'.$cdom.'/'.$cname.'/scantron_orig_'.$file;
8405: my $corrected='/uploaded/'.$cdom.'/'.$cname.'/scantron_corrected_'.$file;
8406: my $skipped='/uploaded/'.$cdom.'/'.$cname.'/scantron_skipped_'.$file;
8407: &Apache::lonnet::allowuploaded('/adm/grades',$orig);
8408: &Apache::lonnet::allowuploaded('/adm/grades',$corrected);
8409: &Apache::lonnet::allowuploaded('/adm/grades',$skipped);
1.492 albertel 8410: $r->print('
1.202 albertel 8411: <p>
1.492 albertel 8412: '.&mt('[_1]Original[_2] file as uploaded by the scantron office.',
8413: '<a href="'.$orig.'">','</a>').'
1.202 albertel 8414: </p>
8415: <p>
1.492 albertel 8416: '.&mt('[_1]Corrections[_2], a file of corrected records that were used in grading.',
8417: '<a href="'.$corrected.'">','</a>').'
1.202 albertel 8418: </p>
8419: <p>
1.492 albertel 8420: '.&mt('[_1]Skipped[_2], a file of records that were skipped.',
8421: '<a href="'.$skipped.'">','</a>').'
1.202 albertel 8422: </p>
1.492 albertel 8423: ');
1.324 albertel 8424: $r->print(&show_grading_menu_form(&get_symb($r,1)));
1.202 albertel 8425: return '';
8426: }
1.157 albertel 8427:
1.523 raeburn 8428: sub checkscantron_results {
8429: my ($r) = @_;
8430: my ($symb)=&get_symb($r);
8431: if (!$symb) {return '';}
8432: my $grading_menu_button=&show_grading_menu_form($symb);
8433: my $cid = $env{'request.course.id'};
1.542 raeburn 8434: my %lettdig = &letter_to_digits();
1.523 raeburn 8435: my $numletts = scalar(keys(%lettdig));
8436: my $cnum = $env{'course.'.$cid.'.num'};
8437: my $cdom = $env{'course.'.$cid.'.domain'};
8438: my (undef, undef, $sequence) = &Apache::lonnet::decode_symb($env{'form.selectpage'});
8439: my %record;
8440: my %scantron_config =
8441: &Apache::grades::get_scantron_config($env{'form.scantron_format'});
8442: my ($scanlines,$scan_data)=&Apache::grades::scantron_getfile();
8443: my $classlist=&Apache::loncoursedata::get_classlist();
8444: my %idmap=&Apache::grades::username_to_idmap($classlist);
8445: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 8446: unless (ref($navmap)) {
8447: $r->print(&navmap_errormsg());
8448: return '';
8449: }
1.523 raeburn 8450: my $map=$navmap->getResourceByUrl($sequence);
1.557 raeburn 8451: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
8452: my (%grader_partids_by_symb,%grader_randomlists_by_symb);
8453: &graders_resources_pass(\@resources,\%grader_partids_by_symb, \%grader_randomlists_by_symb);
8454:
1.554 raeburn 8455: my ($uname,$udom);
1.523 raeburn 8456: my (%scandata,%lastname,%bylast);
8457: $r->print('
8458: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="checkscantron">'."\n");
8459:
8460: my @delayqueue;
8461: my %completedstudents;
8462:
8463: my $count=&Apache::grades::get_todo_count($scanlines,$scan_data);
1.581 www 8464: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Bubblesheet/Submissions Comparison Status',
8465: 'Progress of Bubblesheet Data/Submission Records Comparison',$count,
1.523 raeburn 8466: 'inline',undef,'checkscantron');
1.546 raeburn 8467: my ($username,$domain,$started);
1.582 raeburn 8468: my $nav_error;
1.596.2.12.2. (raeburn 8469:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # Need the bubble lines array to parse.
1.582 raeburn 8470: if ($nav_error) {
8471: $r->print(&navmap_errormsg());
8472: return '';
8473: }
1.523 raeburn 8474:
8475: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
8476: 'Processing first student');
8477: my $start=&Time::HiRes::time();
8478: my $i=-1;
8479:
8480: while ($i<$scanlines->{'count'}) {
8481: ($username,$domain,$uname)=('','','');
8482: $i++;
8483: my $line=&Apache::grades::scantron_get_line($scanlines,$scan_data,$i);
8484: if ($line=~/^[\s\cz]*$/) { next; }
8485: if ($started) {
8486: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
8487: 'last student');
8488: }
8489: $started=1;
8490: my $scan_record=
8491: &Apache::grades::scantron_parse_scanline($line,$i,\%scantron_config,
8492: $scan_data);
8493: unless ($uname=&Apache::grades::scantron_find_student($scan_record,$scan_data,
8494: \%idmap,$i)) {
8495: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
8496: 'Unable to find a student that matches',1);
8497: next;
8498: }
8499: if (exists $completedstudents{$uname}) {
8500: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
8501: 'Student '.$uname.' has multiple sheets',2);
8502: next;
8503: }
8504: my $pid = $scan_record->{'scantron.ID'};
8505: $lastname{$pid} = $scan_record->{'scantron.LastName'};
8506: push(@{$bylast{$lastname{$pid}}},$pid);
8507: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
8508: $scandata{$pid} = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
8509: chomp($scandata{$pid});
8510: $scandata{$pid} =~ s/\r$//;
8511: ($username,$domain)=split(/:/,$uname);
8512: my $counter = -1;
8513: foreach my $resource (@resources) {
1.557 raeburn 8514: my $parts;
1.554 raeburn 8515: my $ressymb = $resource->symb();
1.557 raeburn 8516: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
8517: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
8518: (my $analysis,$parts) =
1.596.2.12.2. (raeburn 8519:): &scantron_partids_tograde($resource,$env{'request.course.id'},
8520:): $username,$domain,undef,
8521:): $bubbles_per_row);
1.557 raeburn 8522: } else {
8523: $parts = $grader_partids_by_symb{$ressymb};
8524: }
1.542 raeburn 8525: ($counter,my $recording) =
8526: &verify_scantron_grading($resource,$domain,$username,$cid,$counter,
1.554 raeburn 8527: $scandata{$pid},$parts,
1.542 raeburn 8528: \%scantron_config,\%lettdig,$numletts);
8529: $record{$pid} .= $recording;
1.523 raeburn 8530: }
8531: }
8532: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
8533: $r->print('<br />');
8534: my ($okstudents,$badstudents,$numstudents,$passed,$failed);
8535: $passed = 0;
8536: $failed = 0;
8537: $numstudents = 0;
8538: foreach my $last (sort(keys(%bylast))) {
8539: if (ref($bylast{$last}) eq 'ARRAY') {
8540: foreach my $pid (sort(@{$bylast{$last}})) {
8541: my $showscandata = $scandata{$pid};
8542: my $showrecord = $record{$pid};
8543: $showscandata =~ s/\s/ /g;
8544: $showrecord =~ s/\s/ /g;
8545: if ($scandata{$pid} eq $record{$pid}) {
8546: my $css_class = ($passed % 2)?'LC_odd_row':'LC_even_row';
8547: $okstudents .= '<tr class="'.$css_class.'">'.
1.581 www 8548: '<td>'.&mt('Bubblesheet').'</td><td>'.$showscandata.'</td><td rowspan="2">'.$last.'</td><td rowspan="2">'.$pid.'</td>'."\n".
1.523 raeburn 8549: '</tr>'."\n".
8550: '<tr class="'.$css_class.'">'."\n".
8551: '<td>Submissions</td><td>'.$showrecord.'</td></tr>'."\n";
8552: $passed ++;
8553: } else {
8554: my $css_class = ($failed % 2)?'LC_odd_row':'LC_even_row';
1.581 www 8555: $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 8556: '</tr>'."\n".
8557: '<tr class="'.$css_class.'">'."\n".
8558: '<td>Submissions</td><td><span class="LC_nobreak">'.$record{$pid}.'</span></td>'."\n".
8559: '</tr>'."\n";
8560: $failed ++;
8561: }
8562: $numstudents ++;
8563: }
8564: }
8565: }
1.596.2.4 raeburn 8566: $r->print('<p>'.
1.596.2.8 raeburn 8567: &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 8568: '<b>',
8569: $numstudents,
8570: '</b>',
8571: $env{'form.scantron_maxbubble'}).
8572: '</p>'
8573: );
1.523 raeburn 8574: $r->print('<p>'.&mt('Exact matches for <b>[quant,_1,student]</b>.',$passed).'<br />'.&mt('Discrepancies detected for <b>[quant,_1,student]</b>.',$failed).'</p>');
8575: if ($passed) {
1.572 www 8576: $r->print(&mt('Students with exact correspondence between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 8577: $r->print(&Apache::loncommon::start_data_table()."\n".
8578: &Apache::loncommon::start_data_table_header_row()."\n".
8579: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
8580: &Apache::loncommon::end_data_table_header_row()."\n".
8581: $okstudents."\n".
8582: &Apache::loncommon::end_data_table().'<br />');
8583: }
8584: if ($failed) {
1.572 www 8585: $r->print(&mt('Students with differences between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 8586: $r->print(&Apache::loncommon::start_data_table()."\n".
8587: &Apache::loncommon::start_data_table_header_row()."\n".
8588: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
8589: &Apache::loncommon::end_data_table_header_row()."\n".
8590: $badstudents."\n".
8591: &Apache::loncommon::end_data_table()).'<br />'.
1.572 www 8592: &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 8593: }
8594: $r->print('</form><br />'.$grading_menu_button);
8595: return;
8596: }
8597:
1.542 raeburn 8598: sub verify_scantron_grading {
1.554 raeburn 8599: my ($resource,$domain,$username,$cid,$counter,$scandata,$partids,
1.542 raeburn 8600: $scantron_config,$lettdig,$numletts) = @_;
8601: my ($record,%expected,%startpos);
8602: return ($counter,$record) if (!ref($resource));
8603: return ($counter,$record) if (!$resource->is_problem());
8604: my $symb = $resource->symb();
1.554 raeburn 8605: return ($counter,$record) if (ref($partids) ne 'ARRAY');
8606: foreach my $part_id (@{$partids}) {
1.542 raeburn 8607: $counter ++;
8608: $expected{$part_id} = 0;
8609: if ($env{"form.scantron.sub_bubblelines.$counter"}) {
8610: my @sub_lines = split(/,/,$env{"form.scantron.sub_bubblelines.$counter"});
8611: foreach my $item (@sub_lines) {
8612: $expected{$part_id} += $item;
8613: }
8614: } else {
8615: $expected{$part_id} = $env{"form.scantron.bubblelines.$counter"};
8616: }
8617: $startpos{$part_id} = $env{"form.scantron.first_bubble_line.$counter"};
8618: }
8619: if ($symb) {
8620: my %recorded;
8621: my (%returnhash) = &Apache::lonnet::restore($symb,$cid,$domain,$username);
8622: if ($returnhash{'version'}) {
8623: my %lasthash=();
8624: my $version;
8625: for ($version=1;$version<=$returnhash{'version'};$version++) {
8626: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
8627: $lasthash{$key}=$returnhash{$version.':'.$key};
8628: }
8629: }
8630: foreach my $key (keys(%lasthash)) {
8631: if ($key =~ /\.scantron$/) {
8632: my $value = &unescape($lasthash{$key});
8633: my ($part_id) = ($key =~ /^resource\.(.+)\.scantron$/);
8634: if ($value eq '') {
8635: for (my $i=0; $i<$expected{$part_id}; $i++) {
8636: for (my $j=0; $j<$scantron_config->{'length'}; $j++) {
8637: $recorded{$part_id} .= $scantron_config->{'Qoff'};
8638: }
8639: }
8640: } else {
8641: my @tocheck;
8642: my @items = split(//,$value);
8643: if (($scantron_config->{'Qon'} eq 'letter') ||
8644: ($scantron_config->{'Qon'} eq 'number')) {
8645: if (@items < $expected{$part_id}) {
8646: my $fragment = substr($scandata,$startpos{$part_id},$expected{$part_id});
8647: my @singles = split(//,$fragment);
8648: foreach my $pos (@singles) {
8649: if ($pos eq ' ') {
8650: push(@tocheck,$pos);
8651: } else {
8652: my $next = shift(@items);
8653: push(@tocheck,$next);
8654: }
8655: }
8656: } else {
8657: @tocheck = @items;
8658: }
8659: foreach my $letter (@tocheck) {
8660: if ($scantron_config->{'Qon'} eq 'letter') {
8661: if ($letter !~ /^[A-J]$/) {
8662: $letter = $scantron_config->{'Qoff'};
8663: }
8664: $recorded{$part_id} .= $letter;
8665: } elsif ($scantron_config->{'Qon'} eq 'number') {
8666: my $digit;
8667: if ($letter !~ /^[A-J]$/) {
8668: $digit = $scantron_config->{'Qoff'};
8669: } else {
8670: $digit = $lettdig->{$letter};
8671: }
8672: $recorded{$part_id} .= $digit;
8673: }
8674: }
8675: } else {
8676: @tocheck = @items;
8677: for (my $i=0; $i<$expected{$part_id}; $i++) {
8678: my $curr_sub = shift(@tocheck);
8679: my $digit;
8680: if ($curr_sub =~ /^[A-J]$/) {
8681: $digit = $lettdig->{$curr_sub}-1;
8682: }
8683: if ($curr_sub eq 'J') {
8684: $digit += scalar($numletts);
8685: }
8686: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
8687: if ($j == $digit) {
8688: $recorded{$part_id} .= $scantron_config->{'Qon'};
8689: } else {
8690: $recorded{$part_id} .= $scantron_config->{'Qoff'};
8691: }
8692: }
8693: }
8694: }
8695: }
8696: }
8697: }
8698: }
1.554 raeburn 8699: foreach my $part_id (@{$partids}) {
1.542 raeburn 8700: if ($recorded{$part_id} eq '') {
8701: for (my $i=0; $i<$expected{$part_id}; $i++) {
8702: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
8703: $recorded{$part_id} .= $scantron_config->{'Qoff'};
8704: }
8705: }
8706: }
8707: $record .= $recorded{$part_id};
8708: }
8709: }
8710: return ($counter,$record);
8711: }
8712:
8713: sub letter_to_digits {
8714: my %lettdig = (
8715: A => 1,
8716: B => 2,
8717: C => 3,
8718: D => 4,
8719: E => 5,
8720: F => 6,
8721: G => 7,
8722: H => 8,
8723: I => 9,
8724: J => 0,
8725: );
8726: return %lettdig;
8727: }
8728:
1.423 albertel 8729:
1.75 albertel 8730: #-------- end of section for handling grading scantron forms -------
8731: #
8732: #-------------------------------------------------------------------
8733:
1.72 ng 8734: #-------------------------- Menu interface -------------------------
8735: #
8736: #--- Show a Grading Menu button - Calls the next routine ---
8737: sub show_grading_menu_form {
1.324 albertel 8738: my ($symb)=@_;
1.125 ng 8739: my $result.='<br /><form action="/adm/grades" method="post">'."\n".
1.418 albertel 8740: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 8741: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.72 ng 8742: '<input type="hidden" name="command" value="gradingmenu" />'."\n".
1.478 albertel 8743: '<input type="submit" name="submit" value="'.&mt('Grading Menu').'" />'."\n".
1.72 ng 8744: '</form>'."\n";
8745: return $result;
8746: }
8747:
1.77 ng 8748: # -- Retrieve choices for grading form
8749: sub savedState {
8750: my %savedState = ();
1.257 albertel 8751: if ($env{'form.saveState'}) {
8752: foreach (split(/:/,$env{'form.saveState'})) {
1.77 ng 8753: my ($key,$value) = split(/=/,$_,2);
8754: $savedState{$key} = $value;
8755: }
8756: }
8757: return \%savedState;
8758: }
1.76 ng 8759:
1.443 banghart 8760: sub grading_menu {
8761: my ($request) = @_;
8762: my ($symb)=&get_symb($request);
8763: if (!$symb) {return '';}
8764: my $probTitle = &Apache::lonnet::gettitle($symb);
8765: my ($table,undef,$hdgrade) = &showResourceInfo($symb,$probTitle);
8766:
1.444 banghart 8767: $request->print($table);
1.443 banghart 8768: my %fields = ('symb'=>&Apache::lonenc::check_encrypt($symb),
8769: 'handgrade'=>$hdgrade,
8770: 'probTitle'=>$probTitle,
8771: 'command'=>'submit_options',
8772: 'saveState'=>"",
8773: 'gradingMenu'=>1,
8774: 'showgrading'=>"yes");
1.538 schulted 8775:
8776: my $url1 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8777:
1.443 banghart 8778: $fields{'command'} = 'csvform';
1.538 schulted 8779: my $url2 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8780:
1.443 banghart 8781: $fields{'command'} = 'processclicker';
1.538 schulted 8782: my $url3 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8783:
1.443 banghart 8784: $fields{'command'} = 'scantron_selectphase';
1.538 schulted 8785: my $url4 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8786:
8787: my @menu = ({ categorytitle=>'Course Grading',
8788: items =>[
8789: { linktext => 'Manual Grading/View Submissions',
8790: url => $url1,
8791: permission => 'F',
8792: icon => 'edit-find-replace.png',
8793: linktitle => 'Start the process of hand grading submissions.'
8794: },
8795: { linktext => 'Upload Scores',
8796: url => $url2,
8797: permission => 'F',
8798: icon => 'uploadscores.png',
8799: linktitle => 'Specify a file containing the class scores for current resource.'
8800: },
8801: { linktext => 'Process Clicker',
8802: url => $url3,
8803: permission => 'F',
8804: icon => 'addClickerInfoFile.png',
8805: linktitle => 'Specify a file containing the clicker information for this resource.'
8806: },
1.587 raeburn 8807: { linktext => 'Grade/Manage/Review Bubblesheets',
1.538 schulted 8808: url => $url4,
8809: permission => 'F',
8810: icon => 'stat.png',
1.596.2.4 raeburn 8811: linktitle => 'Grade bubblesheet exams, upload/download bubblesheet data files, and review previously graded bubblesheet exams.'
1.538 schulted 8812: }
8813: ]
8814: });
8815:
8816: #$fields{'command'} = 'verify';
8817: #$url = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
1.443 banghart 8818: #
8819: # Create the menu
8820: my $Str;
1.444 banghart 8821: # $Str .= '<h2>'.&mt('Please select a grading task').'</h2>';
1.445 banghart 8822: $Str .= '<form method="post" action="" name="gradingMenu">';
8823: $Str .= '<input type="hidden" name="command" value="" />'.
8824: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
8825: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
1.476 albertel 8826: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.445 banghart 8827: '<input type="hidden" name="saveState" value="" />'."\n".
8828: '<input type="hidden" name="gradingMenu" value="1" />'."\n".
8829: '<input type="hidden" name="showgrading" value="yes" />'."\n";
8830:
1.538 schulted 8831: $Str .= Apache::lonhtmlcommon::generate_menu(@menu);
8832: #$menudata->{'jscript'}
1.584 bisitz 8833: $Str .='<hr /><input type="button" value="'.&mt('Verify Receipt No.').'" '.
1.589 bisitz 8834: ' onclick="javascript:checkChoice(document.forms.gradingMenu,\'5\',\'verify\')" '.
1.538 schulted 8835: ' /> '.
8836: &Apache::lonnet::recprefix($env{'request.course.id'}).
1.589 bisitz 8837: '-<input type="text" name="receipt" size="4" onchange="javascript:checkReceiptNo(this.form,\'OK\')" />';
1.538 schulted 8838:
1.444 banghart 8839: $Str .="</form>\n";
1.539 riegler 8840: my $receiptalert = &mt("Please enter a receipt number given by a student in the receipt box.");
1.443 banghart 8841: $request->print(<<GRADINGMENUJS);
8842: <script type="text/javascript" language="javascript">
8843: function checkChoice(formname,val,cmdx) {
8844: if (val <= 2) {
8845: var cmd = radioSelection(formname.radioChoice);
8846: var cmdsave = cmd;
8847: } else {
8848: cmd = cmdx;
8849: cmdsave = 'submission';
8850: }
8851: formname.command.value = cmd;
8852: if (val < 5) formname.submit();
8853: if (val == 5) {
1.458 banghart 8854: if (!checkReceiptNo(formname,'notOK')) {
8855: return false;
8856: } else {
8857: formname.submit();
8858: }
1.445 banghart 8859: }
8860: }
1.443 banghart 8861:
8862: function checkReceiptNo(formname,nospace) {
8863: var receiptNo = formname.receipt.value;
8864: var checkOpt = false;
8865: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
8866: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
8867: if (checkOpt) {
1.539 riegler 8868: alert("$receiptalert");
1.443 banghart 8869: formname.receipt.value = "";
8870: formname.receipt.focus();
8871: return false;
8872: }
8873: return true;
8874: }
8875: </script>
8876: GRADINGMENUJS
8877: &commonJSfunctions($request);
8878: return $Str;
8879: }
8880:
8881:
8882: #--- Displays the submissions first page -------
8883: sub submit_options {
1.72 ng 8884: my ($request) = @_;
1.324 albertel 8885: my ($symb)=&get_symb($request);
1.72 ng 8886: if (!$symb) {return '';}
1.76 ng 8887: my $probTitle = &Apache::lonnet::gettitle($symb);
1.72 ng 8888:
1.539 riegler 8889: my $receiptalert = &mt("Please enter a receipt number given by a student in the receipt box.");
1.72 ng 8890: $request->print(<<GRADINGMENUJS);
8891: <script type="text/javascript" language="javascript">
1.116 ng 8892: function checkChoice(formname,val,cmdx) {
8893: if (val <= 2) {
8894: var cmd = radioSelection(formname.radioChoice);
1.118 ng 8895: var cmdsave = cmd;
1.116 ng 8896: } else {
8897: cmd = cmdx;
1.118 ng 8898: cmdsave = 'submission';
1.116 ng 8899: }
8900: formname.command.value = cmd;
1.118 ng 8901: formname.saveState.value = "saveCmd="+cmdsave+":saveSec="+pullDownSelection(formname.section)+
1.145 albertel 8902: ":saveSub="+pullDownSelection(formname.submitonly)+":saveStatus="+pullDownSelection(formname.Status);
1.116 ng 8903: if (val < 5) formname.submit();
8904: if (val == 5) {
1.72 ng 8905: if (!checkReceiptNo(formname,'notOK')) { return false;}
8906: formname.submit();
8907: }
1.238 albertel 8908: if (val < 7) formname.submit();
1.72 ng 8909: }
8910:
8911: function checkReceiptNo(formname,nospace) {
8912: var receiptNo = formname.receipt.value;
8913: var checkOpt = false;
8914: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
8915: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
8916: if (checkOpt) {
1.539 riegler 8917: alert("$receiptalert");
1.72 ng 8918: formname.receipt.value = "";
8919: formname.receipt.focus();
8920: return false;
8921: }
8922: return true;
8923: }
8924: </script>
8925: GRADINGMENUJS
1.118 ng 8926: &commonJSfunctions($request);
1.324 albertel 8927: my ($table,undef,$hdgrade) = &showResourceInfo($symb,$probTitle);
1.473 albertel 8928: my $result;
1.76 ng 8929: my (undef,$sections) = &getclasslist('all','0');
1.77 ng 8930: my $savedState = &savedState();
1.118 ng 8931: my $saveCmd = ($$savedState{'saveCmd'} eq '' ? 'submission' : $$savedState{'saveCmd'});
1.77 ng 8932: my $saveSec = ($$savedState{'saveSec'} eq '' ? 'all' : $$savedState{'saveSec'});
1.118 ng 8933: my $saveSub = ($$savedState{'saveSub'} eq '' ? 'all' : $$savedState{'saveSub'});
1.77 ng 8934: my $saveStatus = ($$savedState{'saveStatus'} eq '' ? 'Active' : $$savedState{'saveStatus'});
1.72 ng 8935:
1.533 bisitz 8936: # Preselect sections
8937: my $selsec="";
8938: if (ref($sections)) {
8939: foreach my $section (sort(@$sections)) {
8940: $selsec.='<option value="'.$section.'" '.
8941: ($saveSec eq $section ? 'selected="selected"':'').'>'.$section.'</option>'."\n";
8942: }
8943: }
8944:
1.72 ng 8945: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.418 albertel 8946: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.72 ng 8947: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
8948: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.116 ng 8949: '<input type="hidden" name="command" value="" />'."\n".
1.77 ng 8950: '<input type="hidden" name="saveState" value="" />'."\n".
1.124 ng 8951: '<input type="hidden" name="gradingMenu" value="1" />'."\n".
1.72 ng 8952: '<input type="hidden" name="showgrading" value="yes" />'."\n";
8953:
1.472 albertel 8954: $result.='
1.533 bisitz 8955: <h2>
8956: '.&mt('Grade Current Resource').'
8957: </h2>
8958: <div>
8959: '.$table.'
8960: </div>
8961:
1.537 harmsja 8962: <div class="LC_columnSection">
8963:
1.533 bisitz 8964: <fieldset>
8965: <legend>
8966: '.&mt('Sections').'
8967: </legend>
8968: <select name="section" multiple="multiple" size="5">'."\n";
8969: $result.= $selsec;
1.401 albertel 8970: $result.= '<option value="all" '.($saveSec eq 'all' ? 'selected="selected"' : ''). '>all</option></select> ';
1.472 albertel 8971: $result.='
1.533 bisitz 8972: </fieldset>
1.537 harmsja 8973:
1.533 bisitz 8974: <fieldset>
8975: <legend>
8976: '.&mt('Groups').'
8977: </legend>
8978: '.&Apache::lonstatistics::GroupSelect('group','multiple',5).'
8979: </fieldset>
1.537 harmsja 8980:
1.533 bisitz 8981: <fieldset>
8982: <legend>
8983: '.&mt('Access Status').'
8984: </legend>
8985: '.&Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,5,undef,'mult').'
8986: </fieldset>
1.537 harmsja 8987:
1.533 bisitz 8988: <fieldset>
8989: <legend>
8990: '.&mt('Submission Status').'
8991: </legend>
8992: <select name="submitonly" size="5">
1.473 albertel 8993: <option value="yes" '. ($saveSub eq 'yes' ? 'selected="selected"' : '').'>'.&mt('with submissions').'</option>
8994: <option value="queued" '. ($saveSub eq 'queued' ? 'selected="selected"' : '').'>'.&mt('in grading queue').'</option>
8995: <option value="graded" '. ($saveSub eq 'graded' ? 'selected="selected"' : '').'>'.&mt('with ungraded submissions').'</option>
8996: <option value="incorrect" '.($saveSub eq 'incorrect' ? 'selected="selected"' : '').'>'.&mt('with incorrect submissions').'</option>
8997: <option value="all" '. ($saveSub eq 'all' ? 'selected="selected"' : '').'>'.&mt('with any status').'</option>
1.533 bisitz 8998: </select>
8999: </fieldset>
1.537 harmsja 9000:
1.533 bisitz 9001: </div>
9002:
9003: <br />
9004: <div>
9005: <div>
1.473 albertel 9006: <label>
9007: <input type="radio" name="radioChoice" value="submission" '.
9008: ($saveCmd eq 'submission' ? 'checked="checked"' : '').' /> '.
9009: &mt('Select individual students to grade and view submissions.').'
9010: </label>
9011: </div>
1.533 bisitz 9012: <div>
1.473 albertel 9013: <label>
9014: <input type="radio" name="radioChoice" value="viewgrades" '.
9015: ($saveCmd eq 'viewgrades' ? 'checked="checked"' : '').' /> '.
9016: &mt('Grade all selected students in a grading table.').'
9017: </label>
9018: </div>
1.533 bisitz 9019: <div>
1.589 bisitz 9020: <input type="button" onclick="javascript:checkChoice(this.form,\'2\');" value="'.&mt('Next').' →" />
1.473 albertel 9021: </div>
1.472 albertel 9022: </div>
1.533 bisitz 9023:
9024:
1.473 albertel 9025: <h2>
9026: '.&mt('Grade Complete Folder for One Student').'
9027: </h2>
1.533 bisitz 9028: <div>
9029: <div>
1.473 albertel 9030: <label>
9031: <input type="radio" name="radioChoice" value="pickStudentPage" '.
9032: ($saveCmd eq 'pickStudentPage' ? 'checked="checked"' : '').' /> '.
9033: &mt('The <b>complete</b> page/sequence/folder: For one student').'
9034: </label>
9035: </div>
1.533 bisitz 9036: <div>
1.589 bisitz 9037: <input type="button" onclick="javascript:checkChoice(this.form,\'2\');" value="'.&mt('Next').' →" />
1.473 albertel 9038: </div>
1.472 albertel 9039: </div>
9040: </form>';
1.499 albertel 9041: $result .= &show_grading_menu_form($symb);
1.44 ng 9042: return $result;
1.2 albertel 9043: }
9044:
1.285 albertel 9045: sub reset_perm {
9046: undef(%perm);
9047: }
9048:
9049: sub init_perm {
9050: &reset_perm();
1.300 albertel 9051: foreach my $test_perm ('vgr','mgr','opa') {
9052:
9053: my $scope = $env{'request.course.id'};
9054: if (!($perm{$test_perm}=&Apache::lonnet::allowed($test_perm,$scope))) {
9055:
9056: $scope .= '/'.$env{'request.course.sec'};
9057: if ( $perm{$test_perm}=
9058: &Apache::lonnet::allowed($test_perm,$scope)) {
9059: $perm{$test_perm.'_section'}=$env{'request.course.sec'};
9060: } else {
9061: delete($perm{$test_perm});
9062: }
1.285 albertel 9063: }
9064: }
9065: }
9066:
1.400 www 9067: sub gather_clicker_ids {
1.408 albertel 9068: my %clicker_ids;
1.400 www 9069:
9070: my $classlist = &Apache::loncoursedata::get_classlist();
9071:
9072: # Set up a couple variables.
1.407 albertel 9073: my $username_idx = &Apache::loncoursedata::CL_SNAME();
9074: my $domain_idx = &Apache::loncoursedata::CL_SDOM();
1.438 www 9075: my $status_idx = &Apache::loncoursedata::CL_STATUS();
1.400 www 9076:
1.407 albertel 9077: foreach my $student (keys(%$classlist)) {
1.438 www 9078: if ($classlist->{$student}->[$status_idx] ne 'Active') { next; }
1.407 albertel 9079: my $username = $classlist->{$student}->[$username_idx];
9080: my $domain = $classlist->{$student}->[$domain_idx];
1.400 www 9081: my $clickers =
1.408 albertel 9082: (&Apache::lonnet::userenvironment($domain,$username,'clickers'))[1];
1.400 www 9083: foreach my $id (split(/\,/,$clickers)) {
1.414 www 9084: $id=~s/^[\#0]+//;
1.421 www 9085: $id=~s/[\-\:]//g;
1.407 albertel 9086: if (exists($clicker_ids{$id})) {
1.408 albertel 9087: $clicker_ids{$id}.=','.$username.':'.$domain;
1.400 www 9088: } else {
1.408 albertel 9089: $clicker_ids{$id}=$username.':'.$domain;
1.400 www 9090: }
9091: }
9092: }
1.407 albertel 9093: return %clicker_ids;
1.400 www 9094: }
9095:
1.402 www 9096: sub gather_adv_clicker_ids {
1.408 albertel 9097: my %clicker_ids;
1.402 www 9098: my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'};
9099: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
9100: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
1.409 albertel 9101: foreach my $element (sort(keys(%coursepersonnel))) {
1.402 www 9102: foreach my $person (split(/\,/,$coursepersonnel{$element})) {
9103: my ($puname,$pudom)=split(/\:/,$person);
9104: my $clickers =
1.408 albertel 9105: (&Apache::lonnet::userenvironment($pudom,$puname,'clickers'))[1];
1.405 www 9106: foreach my $id (split(/\,/,$clickers)) {
1.414 www 9107: $id=~s/^[\#0]+//;
1.421 www 9108: $id=~s/[\-\:]//g;
1.408 albertel 9109: if (exists($clicker_ids{$id})) {
9110: $clicker_ids{$id}.=','.$puname.':'.$pudom;
9111: } else {
9112: $clicker_ids{$id}=$puname.':'.$pudom;
9113: }
1.405 www 9114: }
1.402 www 9115: }
9116: }
1.407 albertel 9117: return %clicker_ids;
1.402 www 9118: }
9119:
1.413 www 9120: sub clicker_grading_parameters {
9121: return ('gradingmechanism' => 'scalar',
9122: 'upfiletype' => 'scalar',
9123: 'specificid' => 'scalar',
9124: 'pcorrect' => 'scalar',
9125: 'pincorrect' => 'scalar');
9126: }
9127:
1.400 www 9128: sub process_clicker {
9129: my ($r)=@_;
9130: my ($symb)=&get_symb($r);
9131: if (!$symb) {return '';}
9132: my $result=&checkforfile_js();
9133: $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
9134: my ($table) = &showResourceInfo($symb,$env{'form.probTitle'});
9135: $result.=$table;
9136: $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
9137: $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
1.538 schulted 9138: $result.=' <b>'.&mt('Specify a file containing the clicker information for this resource.').
9139: '</b></td></tr>'."\n";
1.596.2.4 raeburn 9140: $result.='<tr bgcolor="#ffffe6"><td>'."\n";
1.413 www 9141: # Attempt to restore parameters from last session, set defaults if not present
9142: my %Saveable_Parameters=&clicker_grading_parameters();
9143: &Apache::loncommon::restore_course_settings('grades_clicker',
9144: \%Saveable_Parameters);
9145: if (!$env{'form.pcorrect'}) { $env{'form.pcorrect'}=100; }
9146: if (!$env{'form.pincorrect'}) { $env{'form.pincorrect'}=100; }
9147: if (!$env{'form.gradingmechanism'}) { $env{'form.gradingmechanism'}='attendance'; }
9148: if (!$env{'form.upfiletype'}) { $env{'form.upfiletype'}='iclicker'; }
9149:
9150: my %checked;
1.521 www 9151: foreach my $gradingmechanism ('attendance','personnel','specific','given') {
1.413 www 9152: if ($env{'form.gradingmechanism'} eq $gradingmechanism) {
1.569 bisitz 9153: $checked{$gradingmechanism}=' checked="checked"';
1.413 www 9154: }
9155: }
9156:
1.400 www 9157: my $upload=&mt("Upload File");
9158: my $type=&mt("Type");
1.402 www 9159: my $attendance=&mt("Award points just for participation");
9160: my $personnel=&mt("Correctness determined from response by course personnel");
1.414 www 9161: my $specific=&mt("Correctness determined from response with clicker ID(s)");
1.521 www 9162: my $given=&mt("Correctness determined from given list of answers").' '.
9163: '<font size="-2"><tt>('.&mt("Provide comma-separated list. Use '*' for any answer correct, '-' for skip").')</tt></font>';
1.402 www 9164: my $pcorrect=&mt("Percentage points for correct solution");
9165: my $pincorrect=&mt("Percentage points for incorrect solution");
1.413 www 9166: my $selectform=&Apache::loncommon::select_form($env{'form.upfiletype'},'upfiletype',
1.596.2.1 raeburn 9167: {'iclicker' => 'i>clicker',
1.596.2.12.2. (raeburn 9168:): 'interwrite' => 'interwrite PRS',
9169:): 'turning' => 'Turning Technologies'});
1.418 albertel 9170: $symb = &Apache::lonenc::check_encrypt($symb);
1.400 www 9171: $result.=<<ENDUPFORM;
1.402 www 9172: <script type="text/javascript">
9173: function sanitycheck() {
9174: // Accept only integer percentages
9175: document.forms.gradesupload.pcorrect.value=Math.round(document.forms.gradesupload.pcorrect.value);
9176: document.forms.gradesupload.pincorrect.value=Math.round(document.forms.gradesupload.pincorrect.value);
9177: // Find out grading choice
9178: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
9179: if (document.forms.gradesupload.gradingmechanism[i].checked) {
9180: gradingchoice=document.forms.gradesupload.gradingmechanism[i].value;
9181: }
9182: }
9183: // By default, new choice equals user selection
9184: newgradingchoice=gradingchoice;
9185: // Not good to give more points for false answers than correct ones
9186: if (Math.round(document.forms.gradesupload.pcorrect.value)<Math.round(document.forms.gradesupload.pincorrect.value)) {
9187: document.forms.gradesupload.pcorrect.value=document.forms.gradesupload.pincorrect.value;
9188: }
9189: // If new choice is attendance only, and old choice was correctness-based, restore defaults
9190: if ((gradingchoice=='attendance') && (document.forms.gradesupload.waschecked.value!='attendance')) {
9191: document.forms.gradesupload.pcorrect.value=100;
9192: document.forms.gradesupload.pincorrect.value=100;
9193: }
9194: // If the values are different, cannot be attendance only
9195: if ((Math.round(document.forms.gradesupload.pcorrect.value)!=Math.round(document.forms.gradesupload.pincorrect.value)) &&
9196: (gradingchoice=='attendance')) {
9197: newgradingchoice='personnel';
9198: }
9199: // Change grading choice to new one
9200: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
9201: if (document.forms.gradesupload.gradingmechanism[i].value==newgradingchoice) {
9202: document.forms.gradesupload.gradingmechanism[i].checked=true;
9203: } else {
9204: document.forms.gradesupload.gradingmechanism[i].checked=false;
9205: }
9206: }
9207: // Remember the old state
9208: document.forms.gradesupload.waschecked.value=newgradingchoice;
9209: }
9210: </script>
1.400 www 9211: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
9212: <input type="hidden" name="symb" value="$symb" />
9213: <input type="hidden" name="command" value="processclickerfile" />
9214: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
9215: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
9216: <input type="file" name="upfile" size="50" />
9217: <br /><label>$type: $selectform</label>
1.589 bisitz 9218: <br /><label><input type="radio" name="gradingmechanism" value="attendance"$checked{'attendance'} onclick="sanitycheck()" />$attendance </label>
9219: <br /><label><input type="radio" name="gradingmechanism" value="personnel"$checked{'personnel'} onclick="sanitycheck()" />$personnel</label>
9220: <br /><label><input type="radio" name="gradingmechanism" value="specific"$checked{'specific'} onclick="sanitycheck()" />$specific </label>
1.414 www 9221: <input type="text" name="specificid" value="$env{'form.specificid'}" size="20" />
1.589 bisitz 9222: <br /><label><input type="radio" name="gradingmechanism" value="given"$checked{'given'} onclick="sanitycheck()" />$given </label>
1.521 www 9223: <br />
9224: <input type="text" name="givenanswer" size="50" />
1.413 www 9225: <input type="hidden" name="waschecked" value="$env{'form.gradingmechanism'}" />
1.589 bisitz 9226: <br /><label>$pcorrect: <input type="text" name="pcorrect" size="4" value="$env{'form.pcorrect'}" onchange="sanitycheck()" /></label>
9227: <br /><label>$pincorrect: <input type="text" name="pincorrect" size="4" value="$env{'form.pincorrect'}" onchange="sanitycheck()" /></label>
9228: <br /><input type="button" onclick="javascript:checkUpload(this.form);" value="$upload" />
1.400 www 9229: </form>
9230: ENDUPFORM
9231: $result.='</td></tr></table>'."\n".
9232: '</td></tr></table><br /><br />'."\n";
9233: $result.=&show_grading_menu_form($symb);
9234: return $result;
9235: }
9236:
9237: sub process_clicker_file {
9238: my ($r)=@_;
9239: my ($symb)=&get_symb($r);
9240: if (!$symb) {return '';}
1.413 www 9241:
9242: my %Saveable_Parameters=&clicker_grading_parameters();
9243: &Apache::loncommon::store_course_settings('grades_clicker',
9244: \%Saveable_Parameters);
9245:
1.400 www 9246: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.404 www 9247: if (($env{'form.gradingmechanism'} eq 'specific') && ($env{'form.specificid'}!~/\w/)) {
1.408 albertel 9248: $result.='<span class="LC_error">'.&mt('You need to specify a clicker ID for the correct answer').'</span>';
9249: return $result.&show_grading_menu_form($symb);
1.404 www 9250: }
1.522 www 9251: if (($env{'form.gradingmechanism'} eq 'given') && ($env{'form.givenanswer'}!~/\S/)) {
1.521 www 9252: $result.='<span class="LC_error">'.&mt('You need to specify the correct answer').'</span>';
9253: return $result.&show_grading_menu_form($symb);
9254: }
1.522 www 9255: my $foundgiven=0;
1.521 www 9256: if ($env{'form.gradingmechanism'} eq 'given') {
9257: $env{'form.givenanswer'}=~s/^\s*//gs;
9258: $env{'form.givenanswer'}=~s/\s*$//gs;
1.596.2.4 raeburn 9259: $env{'form.givenanswer'}=~s/[^a-zA-Z0-9\.\*\-\+]+/\,/g;
1.521 www 9260: $env{'form.givenanswer'}=uc($env{'form.givenanswer'});
1.522 www 9261: my @answers=split(/\,/,$env{'form.givenanswer'});
9262: $foundgiven=$#answers+1;
1.521 www 9263: }
1.407 albertel 9264: my %clicker_ids=&gather_clicker_ids();
1.408 albertel 9265: my %correct_ids;
1.404 www 9266: if ($env{'form.gradingmechanism'} eq 'personnel') {
1.408 albertel 9267: %correct_ids=&gather_adv_clicker_ids();
1.404 www 9268: }
9269: if ($env{'form.gradingmechanism'} eq 'specific') {
1.414 www 9270: foreach my $correct_id (split(/[\s\,]/,$env{'form.specificid'})) {;
9271: $correct_id=~tr/a-z/A-Z/;
9272: $correct_id=~s/\s//gs;
9273: $correct_id=~s/^[\#0]+//;
1.421 www 9274: $correct_id=~s/[\-\:]//g;
1.414 www 9275: if ($correct_id) {
9276: $correct_ids{$correct_id}='specified';
9277: }
9278: }
1.400 www 9279: }
1.404 www 9280: if ($env{'form.gradingmechanism'} eq 'attendance') {
1.408 albertel 9281: $result.=&mt('Score based on attendance only');
1.521 www 9282: } elsif ($env{'form.gradingmechanism'} eq 'given') {
1.522 www 9283: $result.=&mt('Score based on [_1] ([_2] answers)','<tt>'.$env{'form.givenanswer'}.'</tt>',$foundgiven);
1.404 www 9284: } else {
1.408 albertel 9285: my $number=0;
1.411 www 9286: $result.='<p><b>'.&mt('Correctness determined by the following IDs').'</b>';
1.408 albertel 9287: foreach my $id (sort(keys(%correct_ids))) {
1.411 www 9288: $result.='<br /><tt>'.$id.'</tt> - ';
1.408 albertel 9289: if ($correct_ids{$id} eq 'specified') {
9290: $result.=&mt('specified');
9291: } else {
9292: my ($uname,$udom)=split(/\:/,$correct_ids{$id});
9293: $result.=&Apache::loncommon::plainname($uname,$udom);
9294: }
9295: $number++;
9296: }
1.411 www 9297: $result.="</p>\n";
1.408 albertel 9298: if ($number==0) {
9299: $result.='<span class="LC_error">'.&mt('No IDs found to determine correct answer').'</span>';
9300: return $result.&show_grading_menu_form($symb);
9301: }
1.404 www 9302: }
1.405 www 9303: if (length($env{'form.upfile'}) < 2) {
1.407 albertel 9304: $result.=&mt('[_1] Error: [_2] The file you attempted to upload, [_3] contained no information. Please check that you entered the correct filename.',
9305: '<span class="LC_error">',
9306: '</span>',
9307: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>');
1.405 www 9308: return $result.&show_grading_menu_form($symb);
9309: }
1.410 www 9310:
9311: # Were able to get all the info needed, now analyze the file
9312:
1.411 www 9313: $result.=&Apache::loncommon::studentbrowser_javascript();
1.418 albertel 9314: $symb = &Apache::lonenc::check_encrypt($symb);
1.410 www 9315: my $heading=&mt('Scanning clicker file');
9316: $result.=(<<ENDHEADER);
9317: <br /><table width="100%" border="0"><tr><td bgcolor="#777777">
9318: <table width="100%" border="0"><tr bgcolor="#e6ffff"><td>
1.596.2.4 raeburn 9319: <b>$heading</b></td></tr><tr bgcolor="#ffffe6"><td>
1.410 www 9320: <form method="post" action="/adm/grades" name="clickeranalysis">
9321: <input type="hidden" name="symb" value="$symb" />
9322: <input type="hidden" name="command" value="assignclickergrades" />
9323: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
9324: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
1.411 www 9325: <input type="hidden" name="gradingmechanism" value="$env{'form.gradingmechanism'}" />
9326: <input type="hidden" name="pcorrect" value="$env{'form.pcorrect'}" />
9327: <input type="hidden" name="pincorrect" value="$env{'form.pincorrect'}" />
1.410 www 9328: ENDHEADER
1.522 www 9329: if ($env{'form.gradingmechanism'} eq 'given') {
9330: $result.='<input type="hidden" name="correct:given" value="'.$env{'form.givenanswer'}.'" />';
9331: }
1.408 albertel 9332: my %responses;
9333: my @questiontitles;
1.405 www 9334: my $errormsg='';
9335: my $number=0;
9336: if ($env{'form.upfiletype'} eq 'iclicker') {
1.408 albertel 9337: ($errormsg,$number)=&iclicker_eval(\@questiontitles,\%responses);
1.406 www 9338: }
1.419 www 9339: if ($env{'form.upfiletype'} eq 'interwrite') {
9340: ($errormsg,$number)=&interwrite_eval(\@questiontitles,\%responses);
9341: }
1.596.2.12.2. (raeburn 9342:): if ($env{'form.upfiletype'} eq 'turning') {
9343:): ($errormsg,$number)=&turning_eval(\@questiontitles,\%responses);
9344:): }
1.411 www 9345: $result.='<br />'.&mt('Found [_1] question(s)',$number).'<br />'.
9346: '<input type="hidden" name="number" value="'.$number.'" />'.
9347: &mt('Awarding [_1] percent for correct and [_2] percent for incorrect responses',
9348: $env{'form.pcorrect'},$env{'form.pincorrect'}).
9349: '<br />';
1.522 www 9350: if (($env{'form.gradingmechanism'} eq 'given') && ($number!=$foundgiven)) {
9351: $result.='<span class="LC_error">'.&mt('Number of given answers does not agree with number of questions in file.').'</span>';
9352: return $result.&show_grading_menu_form($symb);
9353: }
1.414 www 9354: # Remember Question Titles
9355: # FIXME: Possibly need delimiter other than ":"
9356: for (my $i=0;$i<$number;$i++) {
9357: $result.='<input type="hidden" name="question:'.$i.'" value="'.
9358: &HTML::Entities::encode($questiontitles[$i],'"&<>').'" />';
9359: }
1.411 www 9360: my $correct_count=0;
9361: my $student_count=0;
9362: my $unknown_count=0;
1.414 www 9363: # Match answers with usernames
9364: # FIXME: Possibly need delimiter other than ":"
1.409 albertel 9365: foreach my $id (keys(%responses)) {
1.410 www 9366: if ($correct_ids{$id}) {
1.414 www 9367: $result.="\n".'<input type="hidden" name="correct:'.$correct_count.':'.$correct_ids{$id}.'" value="'.$responses{$id}.'" />';
1.411 www 9368: $correct_count++;
1.410 www 9369: } elsif ($clicker_ids{$id}) {
1.437 www 9370: if ($clicker_ids{$id}=~/\,/) {
9371: # More than one user with the same clicker!
9372: $result.="\n<hr />".&mt('Clicker registered more than once').": <tt>".$id."</tt><br />";
9373: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
9374: "<select name='multi".$id."'>";
9375: foreach my $reguser (sort(split(/\,/,$clicker_ids{$id}))) {
9376: $result.="<option value='".$reguser."'>".&Apache::loncommon::plainname(split(/\:/,$reguser)).' ('.$reguser.')</option>';
9377: }
9378: $result.='</select>';
9379: $unknown_count++;
9380: } else {
9381: # Good: found one and only one user with the right clicker
9382: $result.="\n".'<input type="hidden" name="student:'.$clicker_ids{$id}.'" value="'.$responses{$id}.'" />';
9383: $student_count++;
9384: }
1.410 www 9385: } else {
1.411 www 9386: $result.="\n<hr />".&mt('Unregistered Clicker')." <tt>".$id."</tt><br />";
9387: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
9388: "\n".&mt("Username").": <input type='text' name='uname".$id."' /> ".
9389: "\n".&mt("Domain").": ".
9390: &Apache::loncommon::select_dom_form($env{'course.'.$env{'request.course.id'}.'.domain'},'udom'.$id).' '.
1.596.2.4 raeburn 9391: &Apache::loncommon::selectstudent_link('clickeranalysis','uname'.$id,'udom'.$id,0,$id);
1.411 www 9392: $unknown_count++;
1.410 www 9393: }
1.405 www 9394: }
1.412 www 9395: $result.='<hr />'.
9396: &mt('Found [_1] registered and [_2] unregistered clickers.',$student_count,$unknown_count);
1.521 www 9397: if (($env{'form.gradingmechanism'} ne 'attendance') && ($env{'form.gradingmechanism'} ne 'given')) {
1.412 www 9398: if ($correct_count==0) {
9399: $errormsg.="Found no correct answers answers for grading!";
9400: } elsif ($correct_count>1) {
1.414 www 9401: $result.='<br /><span class="LC_warning">'.&mt("Found [_1] entries for grading!",$correct_count).'</span>';
1.412 www 9402: }
9403: }
1.428 www 9404: if ($number<1) {
9405: $errormsg.="Found no questions.";
9406: }
1.412 www 9407: if ($errormsg) {
9408: $result.='<br /><span class="LC_error">'.&mt($errormsg).'</span>';
9409: } else {
9410: $result.='<br /><input type="submit" name="finalize" value="'.&mt('Finalize Grading').'" />';
9411: }
9412: $result.='</form></td></tr></table>'."\n".
1.410 www 9413: '</td></tr></table><br /><br />'."\n";
1.404 www 9414: return $result.&show_grading_menu_form($symb);
1.400 www 9415: }
9416:
1.405 www 9417: sub iclicker_eval {
1.406 www 9418: my ($questiontitles,$responses)=@_;
1.405 www 9419: my $number=0;
9420: my $errormsg='';
9421: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
1.410 www 9422: my %components=&Apache::loncommon::record_sep($line);
9423: my @entries=map {$components{$_}} (sort(keys(%components)));
1.408 albertel 9424: if ($entries[0] eq 'Question') {
9425: for (my $i=3;$i<$#entries;$i+=6) {
9426: $$questiontitles[$number]=$entries[$i];
9427: $number++;
9428: }
9429: }
9430: if ($entries[0]=~/^\#/) {
9431: my $id=$entries[0];
9432: my @idresponses;
9433: $id=~s/^[\#0]+//;
9434: for (my $i=0;$i<$number;$i++) {
9435: my $idx=3+$i*6;
1.596.2.4 raeburn 9436: $entries[$idx]=~s/[^a-zA-Z0-9\.\*\-\+]+//g;
1.408 albertel 9437: push(@idresponses,$entries[$idx]);
9438: }
9439: $$responses{$id}=join(',',@idresponses);
9440: }
1.405 www 9441: }
9442: return ($errormsg,$number);
9443: }
9444:
1.419 www 9445: sub interwrite_eval {
9446: my ($questiontitles,$responses)=@_;
9447: my $number=0;
9448: my $errormsg='';
1.420 www 9449: my $skipline=1;
9450: my $questionnumber=0;
9451: my %idresponses=();
1.419 www 9452: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
9453: my %components=&Apache::loncommon::record_sep($line);
9454: my @entries=map {$components{$_}} (sort(keys(%components)));
1.420 www 9455: if ($entries[1] eq 'Time') { $skipline=0; next; }
9456: if ($entries[1] eq 'Response') { $skipline=1; }
9457: next if $skipline;
9458: if ($entries[0]!=$questionnumber) {
9459: $questionnumber=$entries[0];
9460: $$questiontitles[$number]=&mt('Question [_1]',$questionnumber);
9461: $number++;
1.419 www 9462: }
1.420 www 9463: my $id=$entries[4];
9464: $id=~s/^[\#0]+//;
1.421 www 9465: $id=~s/^v\d*\://i;
9466: $id=~s/[\-\:]//g;
1.420 www 9467: $idresponses{$id}[$number]=$entries[6];
9468: }
1.524 raeburn 9469: foreach my $id (keys(%idresponses)) {
1.420 www 9470: $$responses{$id}=join(',',@{$idresponses{$id}});
9471: $$responses{$id}=~s/^\s*\,//;
1.419 www 9472: }
9473: return ($errormsg,$number);
9474: }
9475:
1.596.2.12.2. (raeburn 9476:): sub turning_eval {
9477:): my ($questiontitles,$responses)=@_;
9478:): my $number=0;
9479:): my $errormsg='';
9480:): foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
9481:): my %components=&Apache::loncommon::record_sep($line);
9482:): my @entries=map {$components{$_}} (sort(keys(%components)));
9483:): if ($#entries>$number) { $number=$#entries; }
9484:): my $id=$entries[0];
9485:): my @idresponses;
9486:): $id=~s/^[\#0]+//;
9487:): unless ($id) { next; }
9488:): for (my $idx=1;$idx<=$#entries;$idx++) {
9489:): $entries[$idx]=~s/\,/\;/g;
9490:): $entries[$idx]=~s/[^a-zA-Z0-9\.\*\-\+\;]+//g;
9491:): push(@idresponses,$entries[$idx]);
9492:): }
9493:): $$responses{$id}=join(',',@idresponses);
9494:): }
9495:): for (my $i=1; $i<=$number; $i++) {
9496:): $$questiontitles[$i]=&mt('Question [_1]',$i);
9497:): }
9498:): return ($errormsg,$number);
9499:): }
9500:):
1.414 www 9501: sub assign_clicker_grades {
9502: my ($r)=@_;
9503: my ($symb)=&get_symb($r);
9504: if (!$symb) {return '';}
1.416 www 9505: # See which part we are saving to
1.582 raeburn 9506: my $res_error;
9507: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
9508: if ($res_error) {
9509: return &navmap_errormsg();
9510: }
1.416 www 9511: # FIXME: This should probably look for the first handgradeable part
9512: my $part=$$partlist[0];
9513: # Start screen output
1.596.2.10 raeburn 9514: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.596.2.4 raeburn 9515:
1.596.2.10 raeburn 9516: $result .= '<br />'.
9517: &Apache::loncommon::start_data_table().
1.596.2.4 raeburn 9518: &Apache::loncommon::start_data_table_header_row().
9519: '<th>'.&mt('Assigning grades based on clicker file').'</th>'.
9520: &Apache::loncommon::end_data_table_header_row().
9521: &Apache::loncommon::start_data_table_row().'<td>';
1.416 www 9522:
1.414 www 9523: # Get correct result
9524: # FIXME: Possibly need delimiter other than ":"
9525: my @correct=();
1.415 www 9526: my $gradingmechanism=$env{'form.gradingmechanism'};
9527: my $number=$env{'form.number'};
9528: if ($gradingmechanism ne 'attendance') {
1.414 www 9529: foreach my $key (keys(%env)) {
9530: if ($key=~/^form\.correct\:/) {
9531: my @input=split(/\,/,$env{$key});
9532: for (my $i=0;$i<=$#input;$i++) {
9533: if (($correct[$i]) && ($input[$i]) &&
9534: ($correct[$i] ne $input[$i])) {
9535: $result.='<br /><span class="LC_warning">'.
9536: &mt('More than one correct result given for question "[_1]": [_2] versus [_3].',
9537: $env{'form.question:'.$i},$correct[$i],$input[$i]).'</span>';
1.596.2.4 raeburn 9538: } elsif (($input[$i]) || ($input[$i] eq '0')) {
1.414 www 9539: $correct[$i]=$input[$i];
9540: }
9541: }
9542: }
9543: }
1.415 www 9544: for (my $i=0;$i<$number;$i++) {
1.596.2.4 raeburn 9545: if ((!$correct[$i]) && ($correct[$i] ne '0')) {
1.414 www 9546: $result.='<br /><span class="LC_error">'.
9547: &mt('No correct result given for question "[_1]"!',
9548: $env{'form.question:'.$i}).'</span>';
9549: }
9550: }
1.596.2.4 raeburn 9551: $result.='<br />'.&mt("Correct answer: [_1]",join(', ',map { ((($_) || ($_ eq '0'))?$_:'-') } @correct));
1.414 www 9552: }
9553: # Start grading
1.415 www 9554: my $pcorrect=$env{'form.pcorrect'};
9555: my $pincorrect=$env{'form.pincorrect'};
1.416 www 9556: my $storecount=0;
1.596.2.4 raeburn 9557: my %users=();
1.415 www 9558: foreach my $key (keys(%env)) {
1.420 www 9559: my $user='';
1.415 www 9560: if ($key=~/^form\.student\:(.*)$/) {
1.420 www 9561: $user=$1;
9562: }
9563: if ($key=~/^form\.unknown\:(.*)$/) {
9564: my $id=$1;
9565: if (($env{'form.uname'.$id}) && ($env{'form.udom'.$id})) {
9566: $user=$env{'form.uname'.$id}.':'.$env{'form.udom'.$id};
1.437 www 9567: } elsif ($env{'form.multi'.$id}) {
9568: $user=$env{'form.multi'.$id};
1.420 www 9569: }
9570: }
1.596.2.4 raeburn 9571: if ($user) {
9572: if ($users{$user}) {
9573: $result.='<br /><span class="LC_warning">'.
9574: &mt("More than one entry found for <tt>[_1]</tt>!",$user).
9575: '</span><br />';
9576: }
9577: $users{$user}=1;
1.415 www 9578: my @answer=split(/\,/,$env{$key});
9579: my $sum=0;
1.522 www 9580: my $realnumber=$number;
1.415 www 9581: for (my $i=0;$i<$number;$i++) {
1.576 www 9582: if ($correct[$i] eq '-') {
9583: $realnumber--;
9584: } elsif ($answer[$i]) {
1.415 www 9585: if ($gradingmechanism eq 'attendance') {
9586: $sum+=$pcorrect;
1.576 www 9587: } elsif ($correct[$i] eq '*') {
1.522 www 9588: $sum+=$pcorrect;
1.415 www 9589: } else {
1.596.2.4 raeburn 9590: # We actually grade if correct or not
9591: my $increment=$pincorrect;
9592: # Special case: numerical answer "0"
9593: if ($correct[$i] eq '0') {
9594: if ($answer[$i]=~/^[0\.]+$/) {
9595: $increment=$pcorrect;
9596: }
9597: # General numerical answer, both evaluate to something non-zero
9598: } elsif ((1.0*$correct[$i]!=0) && (1.0*$answer[$i]!=0)) {
9599: if (1.0*$correct[$i]==1.0*$answer[$i]) {
9600: $increment=$pcorrect;
9601: }
9602: # Must be just alphanumeric
9603: } elsif ($answer[$i] eq $correct[$i]) {
9604: $increment=$pcorrect;
1.415 www 9605: }
1.596.2.4 raeburn 9606: $sum+=$increment;
1.415 www 9607: }
9608: }
9609: }
1.522 www 9610: my $ave=$sum/(100*$realnumber);
1.416 www 9611: # Store
9612: my ($username,$domain)=split(/\:/,$user);
9613: my %grades=();
9614: $grades{"resource.$part.solved"}='correct_by_override';
9615: $grades{"resource.$part.awarded"}=$ave;
9616: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
9617: my $returncode=&Apache::lonnet::cstore(\%grades,$symb,
9618: $env{'request.course.id'},
9619: $domain,$username);
9620: if ($returncode ne 'ok') {
9621: $result.="<br /><span class=\"LC_error\">Failed to save student $username:$domain. Message when trying to save was ($returncode)</span>";
9622: } else {
9623: $storecount++;
9624: }
1.415 www 9625: }
9626: }
9627: # We are done
1.549 hauer 9628: $result.='<br />'.&mt('Successfully stored grades for [quant,_1,student].',$storecount).
1.596.2.4 raeburn 9629: '</td>'.
9630: &Apache::loncommon::end_data_table_row().
9631: &Apache::loncommon::end_data_table()."<br /><br />\n";
1.414 www 9632: return $result.&show_grading_menu_form($symb);
9633: }
9634:
1.582 raeburn 9635: sub navmap_errormsg {
9636: return '<div class="LC_error">'.
9637: &mt('An error occurred retrieving information about resources in the course.').'<br />'.
1.595 raeburn 9638: &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 9639: '</div>';
9640: }
9641:
1.1 albertel 9642: sub handler {
1.41 ng 9643: my $request=$_[0];
1.434 albertel 9644: &reset_caches();
1.596.2.4 raeburn 9645: if ($request->header_only) {
9646: &Apache::loncommon::content_type($request,'text/html');
9647: $request->send_http_header;
9648: return OK;
1.41 ng 9649: }
9650: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.596.2.4 raeburn 9651:
1.324 albertel 9652: my $symb=&get_symb($request,1);
1.160 albertel 9653: my @commands=&Apache::loncommon::get_env_multiple('form.command');
9654: my $command=$commands[0];
1.447 foxr 9655:
1.160 albertel 9656: if ($#commands > 0) {
9657: &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands));
9658: }
1.447 foxr 9659:
1.513 foxr 9660: $ssi_error = 0;
1.535 raeburn 9661: my $brcrum = [{href=>"/adm/grades",text=>"Grading"}];
1.596.2.4 raeburn 9662: my $start_page = &Apache::loncommon::start_page('Grading',undef,
1.596.2.5 raeburn 9663: {'bread_crumbs' => $brcrum});
1.324 albertel 9664: if ($symb eq '' && $command eq '') {
1.257 albertel 9665: if ($env{'user.adv'}) {
1.596.2.4 raeburn 9666: &Apache::loncommon::content_type($request,'text/html');
9667: $request->send_http_header;
9668: $request->print($start_page);
1.257 albertel 9669: if (($env{'form.codeone'}) && ($env{'form.codetwo'}) &&
9670: ($env{'form.codethree'})) {
9671: my $token=$env{'form.codeone'}.'*'.$env{'form.codetwo'}.'*'.
9672: $env{'form.codethree'};
1.41 ng 9673: my ($tsymb,$tuname,$tudom,$tcrsid)=
9674: &Apache::lonnet::checkin($token);
9675: if ($tsymb) {
1.137 albertel 9676: my ($map,$id,$url)=&Apache::lonnet::decode_symb($tsymb);
1.41 ng 9677: if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
1.513 foxr 9678: $request->print(&ssi_with_retries('/res/'.$url, $ssi_retries,
1.99 albertel 9679: ('grade_username' => $tuname,
9680: 'grade_domain' => $tudom,
9681: 'grade_courseid' => $tcrsid,
9682: 'grade_symb' => $tsymb)));
1.41 ng 9683: } else {
1.45 ng 9684: $request->print('<h3>Not authorized: '.$token.'</h3>');
1.99 albertel 9685: }
1.41 ng 9686: } else {
1.45 ng 9687: $request->print('<h3>Not a valid DocID: '.$token.'</h3>');
1.41 ng 9688: }
1.14 www 9689: } else {
1.41 ng 9690: $request->print(&Apache::lonxml::tokeninputfield());
9691: }
1.596.2.4 raeburn 9692: } elsif ($env{'request.course.id'}) {
9693: &init_perm();
9694: if (!%perm) {
9695: $request->internal_redirect('/adm/quickgrades');
9696: } else {
9697: &Apache::loncommon::content_type($request,'text/html');
9698: $request->send_http_header;
9699: $request->print($start_page);
9700: }
9701: }
1.41 ng 9702: } else {
1.596.2.4 raeburn 9703: &init_perm();
9704: if (!$env{'request.course.id'}) {
1.596.2.11 raeburn 9705: unless ((&Apache::lonnet::allowed('usc',$env{'request.role.domain'})) &&
9706: ($command =~ /^scantronupload/)) {
9707: # Not in a course.
9708: $env{'user.error.msg'}="/adm/grades::vgr:0:0:Cannot display grades page outside course context";
9709: return HTTP_NOT_ACCEPTABLE;
9710: }
1.596.2.4 raeburn 9711: } elsif (!%perm) {
9712: $request->internal_redirect('/adm/quickgrades');
9713: }
9714: &Apache::loncommon::content_type($request,'text/html');
9715: $request->send_http_header;
9716: $request->print($start_page);
1.104 albertel 9717: if ($command eq 'submission' && $perm{'vgr'}) {
1.257 albertel 9718: ($env{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0));
1.103 albertel 9719: } elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) {
1.68 ng 9720: &pickStudentPage($request);
1.103 albertel 9721: } elsif ($command eq 'displayPage' && $perm{'vgr'}) {
1.68 ng 9722: &displayPage($request);
1.104 albertel 9723: } elsif ($command eq 'gradeByPage' && $perm{'mgr'}) {
1.71 ng 9724: &updateGradeByPage($request);
1.104 albertel 9725: } elsif ($command eq 'processGroup' && $perm{'vgr'}) {
1.41 ng 9726: &processGroup($request);
1.104 albertel 9727: } elsif ($command eq 'gradingmenu' && $perm{'vgr'}) {
1.443 banghart 9728: $request->print(&grading_menu($request));
9729: } elsif ($command eq 'submit_options' && $perm{'vgr'}) {
9730: $request->print(&submit_options($request));
1.104 albertel 9731: } elsif ($command eq 'viewgrades' && $perm{'vgr'}) {
1.41 ng 9732: $request->print(&viewgrades($request));
1.104 albertel 9733: } elsif ($command eq 'handgrade' && $perm{'mgr'}) {
1.41 ng 9734: $request->print(&processHandGrade($request));
1.106 albertel 9735: } elsif ($command eq 'editgrades' && $perm{'mgr'}) {
1.41 ng 9736: $request->print(&editgrades($request));
1.106 albertel 9737: } elsif ($command eq 'verify' && $perm{'vgr'}) {
1.41 ng 9738: $request->print(&verifyreceipt($request));
1.400 www 9739: } elsif ($command eq 'processclicker' && $perm{'mgr'}) {
9740: $request->print(&process_clicker($request));
9741: } elsif ($command eq 'processclickerfile' && $perm{'mgr'}) {
9742: $request->print(&process_clicker_file($request));
1.414 www 9743: } elsif ($command eq 'assignclickergrades' && $perm{'mgr'}) {
9744: $request->print(&assign_clicker_grades($request));
1.106 albertel 9745: } elsif ($command eq 'csvform' && $perm{'mgr'}) {
1.72 ng 9746: $request->print(&upcsvScores_form($request));
1.106 albertel 9747: } elsif ($command eq 'csvupload' && $perm{'mgr'}) {
1.41 ng 9748: $request->print(&csvupload($request));
1.106 albertel 9749: } elsif ($command eq 'csvuploadmap' && $perm{'mgr'} ) {
1.41 ng 9750: $request->print(&csvuploadmap($request));
1.246 albertel 9751: } elsif ($command eq 'csvuploadoptions' && $perm{'mgr'}) {
1.257 albertel 9752: if ($env{'form.associate'} ne 'Reverse Association') {
1.246 albertel 9753: $request->print(&csvuploadoptions($request));
1.41 ng 9754: } else {
1.257 albertel 9755: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
9756: $env{'form.upfile_associate'} = 'reverse';
1.41 ng 9757: } else {
1.257 albertel 9758: $env{'form.upfile_associate'} = 'forward';
1.41 ng 9759: }
9760: $request->print(&csvuploadmap($request));
9761: }
1.246 albertel 9762: } elsif ($command eq 'csvuploadassign' && $perm{'mgr'} ) {
9763: $request->print(&csvuploadassign($request));
1.106 albertel 9764: } elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
1.75 albertel 9765: $request->print(&scantron_selectphase($request));
1.203 albertel 9766: } elsif ($command eq 'scantron_warning' && $perm{'mgr'}) {
9767: $request->print(&scantron_do_warning($request));
1.142 albertel 9768: } elsif ($command eq 'scantron_validate' && $perm{'mgr'}) {
9769: $request->print(&scantron_validate_file($request));
1.106 albertel 9770: } elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
1.82 albertel 9771: $request->print(&scantron_process_students($request));
1.157 albertel 9772: } elsif ($command eq 'scantronupload' &&
1.257 albertel 9773: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
9774: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.162 albertel 9775: $request->print(&scantron_upload_scantron_data($request));
1.157 albertel 9776: } elsif ($command eq 'scantronupload_save' &&
1.257 albertel 9777: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
9778: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.157 albertel 9779: $request->print(&scantron_upload_scantron_data_save($request));
1.202 albertel 9780: } elsif ($command eq 'scantron_download' &&
1.257 albertel 9781: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.162 albertel 9782: $request->print(&scantron_download_scantron_data($request));
1.523 raeburn 9783: } elsif ($command eq 'checksubmissions' && $perm{'vgr'}) {
9784: $request->print(&checkscantron_results($request));
1.106 albertel 9785: } elsif ($command) {
1.562 bisitz 9786: $request->print('<p class="LC_error">'.&mt('Access Denied ([_1])',$command).'</p>');
1.26 albertel 9787: }
1.2 albertel 9788: }
1.513 foxr 9789: if ($ssi_error) {
9790: &ssi_print_error($request);
9791: }
1.353 albertel 9792: $request->print(&Apache::loncommon::end_page());
1.434 albertel 9793: &reset_caches();
1.596.2.4 raeburn 9794: return OK;
1.44 ng 9795: }
9796:
1.1 albertel 9797: 1;
9798:
1.13 albertel 9799: __END__;
1.531 jms 9800:
9801:
9802: =head1 NAME
9803:
9804: Apache::grades
9805:
9806: =head1 SYNOPSIS
9807:
9808: Handles the viewing of grades.
9809:
9810: This is part of the LearningOnline Network with CAPA project
9811: described at http://www.lon-capa.org.
9812:
9813: =head1 OVERVIEW
9814:
9815: Do an ssi with retries:
9816: While I'd love to factor out this with the vesrion in lonprintout,
9817: 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
9818: I'm not quite ready to invent (e.g. an ssi_with_retry object).
9819:
9820: At least the logic that drives this has been pulled out into loncommon.
9821:
9822:
9823:
9824: ssi_with_retries - Does the server side include of a resource.
9825: if the ssi call returns an error we'll retry it up to
9826: the number of times requested by the caller.
9827: If we still have a proble, no text is appended to the
9828: output and we set some global variables.
9829: to indicate to the caller an SSI error occurred.
9830: All of this is supposed to deal with the issues described
9831: in LonCAPA BZ 5631 see:
9832: http://bugs.lon-capa.org/show_bug.cgi?id=5631
9833: by informing the user that this happened.
9834:
9835: Parameters:
9836: resource - The resource to include. This is passed directly, without
9837: interpretation to lonnet::ssi.
9838: form - The form hash parameters that guide the interpretation of the resource
9839:
9840: retries - Number of retries allowed before giving up completely.
9841: Returns:
9842: On success, returns the rendered resource identified by the resource parameter.
9843: Side Effects:
9844: The following global variables can be set:
9845: ssi_error - If an unrecoverable error occurred this becomes true.
9846: It is up to the caller to initialize this to false
9847: if desired.
9848: ssi_error_resource - If an unrecoverable error occurred, this is the value
9849: of the resource that could not be rendered by the ssi
9850: call.
9851: ssi_error_message - The error string fetched from the ssi response
9852: in the event of an error.
9853:
9854:
9855: =head1 HANDLER SUBROUTINE
9856:
9857: ssi_with_retries()
9858:
9859: =head1 SUBROUTINES
9860:
9861: =over
9862:
9863: =item scantron_get_correction() :
9864:
9865: Builds the interface screen to interact with the operator to fix a
9866: specific error condition in a specific scanline
9867:
9868: Arguments:
9869: $r - Apache request object
9870: $i - number of the current scanline
9871: $scan_record - hash ref as returned from &scantron_parse_scanline()
9872: $scan_config - hash ref as returned from &get_scantron_config()
9873: $line - full contents of the current scanline
9874: $error - error condition, valid values are
9875: 'incorrectCODE', 'duplicateCODE',
9876: 'doublebubble', 'missingbubble',
9877: 'duplicateID', 'incorrectID'
9878: $arg - extra information needed
9879: For errors:
9880: - duplicateID - paper number that this studentID was seen before on
9881: - duplicateCODE - array ref of the paper numbers this CODE was
9882: seen on before
9883: - incorrectCODE - current incorrect CODE
9884: - doublebubble - array ref of the bubble lines that have double
9885: bubble errors
9886: - missingbubble - array ref of the bubble lines that have missing
9887: bubble errors
9888:
9889: =item scantron_get_maxbubble() :
9890:
1.582 raeburn 9891: Arguments:
9892: $nav_error - Reference to scalar which is a flag to indicate a
9893: failure to retrieve a navmap object.
9894: if $nav_error is set to 1 by scantron_get_maxbubble(), the
9895: calling routine should trap the error condition and display the warning
9896: found in &navmap_errormsg().
9897:
1.596.2.12.2. (raeburn 9898:): $scantron_config - Reference to bubblesheet format configuration hash.
9899:):
1.531 jms 9900: Returns the maximum number of bubble lines that are expected to
9901: occur. Does this by walking the selected sequence rendering the
9902: resource and then checking &Apache::lonxml::get_problem_counter()
9903: for what the current value of the problem counter is.
9904:
9905: Caches the results to $env{'form.scantron_maxbubble'},
9906: $env{'form.scantron.bubble_lines.n'},
9907: $env{'form.scantron.first_bubble_line.n'} and
9908: $env{"form.scantron.sub_bubblelines.n"}
9909: which are the total number of bubble, lines, the number of bubble
9910: lines for response n and number of the first bubble line for response n,
9911: and a comma separated list of numbers of bubble lines for sub-questions
9912: (for optionresponse, matchresponse, and rankresponse items), for response n.
9913:
9914:
9915: =item scantron_validate_missingbubbles() :
9916:
9917: Validates all scanlines in the selected file to not have any
9918: answers that don't have bubbles that have not been verified
9919: to be bubble free.
9920:
9921: =item scantron_process_students() :
9922:
1.596.2.6 raeburn 9923: Routine that does the actual grading of the bubblesheet information.
1.531 jms 9924:
9925: The parsed scanline hash is added to %env
9926:
9927: Then foreach unskipped scanline it does an &Apache::lonnet::ssi()
9928: foreach resource , with the form data of
9929:
9930: 'submitted' =>'scantron'
9931: 'grade_target' =>'grade',
9932: 'grade_username'=> username of student
9933: 'grade_domain' => domain of student
9934: 'grade_courseid'=> of course
9935: 'grade_symb' => symb of resource to grade
9936:
9937: This triggers a grading pass. The problem grading code takes care
9938: of converting the bubbled letter information (now in %env) into a
9939: valid submission.
9940:
9941: =item scantron_upload_scantron_data() :
9942:
1.596.2.6 raeburn 9943: Creates the screen for adding a new bubblesheet data file to a course.
1.531 jms 9944:
9945: =item scantron_upload_scantron_data_save() :
9946:
9947: Adds a provided bubble information data file to the course if user
9948: has the correct privileges to do so.
9949:
9950: =item valid_file() :
9951:
9952: Validates that the requested bubble data file exists in the course.
9953:
9954: =item scantron_download_scantron_data() :
9955:
9956: Shows a list of the three internal files (original, corrected,
1.596.2.6 raeburn 9957: skipped) for a specific bubblesheet data file that exists in the
1.531 jms 9958: course.
9959:
9960: =item scantron_validate_ID() :
9961:
9962: Validates all scanlines in the selected file to not have any
1.556 weissno 9963: invalid or underspecified student/employee IDs
1.531 jms 9964:
1.582 raeburn 9965: =item navmap_errormsg() :
9966:
9967: Returns HTML mark-up inside a <div></div> with a link to re-initialize the course.
9968: Should be called whenever the request to instantiate a navmap object fails.
9969:
1.531 jms 9970: =back
9971:
9972: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>