Annotation of loncom/homework/grades.pm, revision 1.574.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.574.2.5! raeburn 4: # $Id: grades.pm,v 1.574.2.4 2009/12/27 01:00:44 raeburn Exp $
1.17 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
1.529 jms 29:
30:
1.1 albertel 31: package Apache::grades;
32: use strict;
33: use Apache::style;
34: use Apache::lonxml;
35: use Apache::lonnet;
1.3 albertel 36: use Apache::loncommon;
1.112 ng 37: use Apache::lonhtmlcommon;
1.68 ng 38: use Apache::lonnavmaps;
1.1 albertel 39: use Apache::lonhomework;
1.456 banghart 40: use Apache::lonpickcode;
1.55 matthew 41: use Apache::loncoursedata;
1.362 albertel 42: use Apache::lonmsg();
1.1 albertel 43: use Apache::Constants qw(:common);
1.167 sakharuk 44: use Apache::lonlocal;
1.386 raeburn 45: use Apache::lonenc;
1.170 albertel 46: use String::Similarity;
1.359 www 47: use LONCAPA;
48:
1.315 bowersj2 49: use POSIX qw(floor);
1.87 www 50:
1.435 foxr 51:
1.513 foxr 52:
1.435 foxr 53: my %perm=();
1.447 foxr 54:
1.513 foxr 55: # These variables are used to recover from ssi errors
56:
57: my $ssi_retries = 5;
58: my $ssi_error;
59: my $ssi_error_resource;
60: my $ssi_error_message;
61:
62:
63: sub ssi_with_retries {
64: my ($resource, $retries, %form) = @_;
65: my ($content, $response) = &Apache::loncommon::ssi_with_retries($resource, $retries, %form);
66: if ($response->is_error) {
67: $ssi_error = 1;
68: $ssi_error_resource = $resource;
69: $ssi_error_message = $response->code . " " . $response->message;
70: }
71:
72: return $content;
73:
74: }
75: #
76: # Prodcuces an ssi retry failure error message to the user:
77: #
78:
79: sub ssi_print_error {
80: my ($r) = @_;
1.516 raeburn 81: my $helpurl = &Apache::loncommon::top_nav_help('Helpdesk');
82: $r->print('
83: <br />
84: <h2>'.&mt('An unrecoverable network error occurred:').'</h2>
85: <p>
86: '.&mt('Unable to retrieve a resource from a server:').'<br />
87: '.&mt('Resource:').' '.$ssi_error_resource.'<br />
88: '.&mt('Error:').' '.$ssi_error_message.'
89: </p>
90: <p>'.
91: &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 />'.
92: &mt('If the error persists, please contact the [_1] for assistance.',$helpurl).
93: '</p>');
94: return;
1.513 foxr 95: }
96:
1.44 ng 97: #
1.146 albertel 98: # --- Retrieve the parts from the metadata file.---
1.44 ng 99: sub getpartlist {
1.324 albertel 100: my ($symb) = @_;
1.439 albertel 101:
102: my $navmap = Apache::lonnavmaps::navmap->new();
103: my $res = $navmap->getBySymb($symb);
104: my $partlist = $res->parts();
105: my $url = $res->src();
106: my @metakeys = split(/,/,&Apache::lonnet::metadata($url,'keys'));
107:
1.146 albertel 108: my @stores;
1.439 albertel 109: foreach my $part (@{ $partlist }) {
1.146 albertel 110: foreach my $key (@metakeys) {
111: if ($key =~ m/^stores_\Q$part\E_/) { push(@stores,$key); }
112: }
113: }
114: return @stores;
1.2 albertel 115: }
116:
1.44 ng 117: # --- Get the symbolic name of a problem and the url
1.324 albertel 118: sub get_symb {
1.173 albertel 119: my ($request,$silent) = @_;
1.257 albertel 120: (my $url=$env{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
121: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
1.173 albertel 122: if ($symb eq '') {
123: if (!$silent) {
124: $request->print("Unable to handle ambiguous references:$url:.");
125: return ();
126: }
127: }
1.418 albertel 128: &Apache::lonenc::check_decrypt(\$symb);
1.324 albertel 129: return ($symb);
1.32 ng 130: }
131:
1.129 ng 132: #--- Format fullname, username:domain if different for display
133: #--- Use anywhere where the student names are listed
134: sub nameUserString {
135: my ($type,$fullname,$uname,$udom) = @_;
136: if ($type eq 'header') {
1.485 albertel 137: return '<b> '.&mt('Fullname').' </b><span class="LC_internal_info">('.&mt('Username').')</span>';
1.129 ng 138: } else {
1.398 albertel 139: return ' '.$fullname.'<span class="LC_internal_info"> ('.$uname.
140: ($env{'user.domain'} eq $udom ? '' : ' ('.$udom.')').')</span>';
1.129 ng 141: }
142: }
143:
1.44 ng 144: #--- Get the partlist and the response type for a given problem. ---
145: #--- Indicate if a response type is coded handgraded or not. ---
1.39 ng 146: sub response_type {
1.324 albertel 147: my ($symb) = shift;
1.377 albertel 148:
149: my $navmap = Apache::lonnavmaps::navmap->new();
150: my $res = $navmap->getBySymb($symb);
151: my $partlist = $res->parts();
1.392 albertel 152: my %vPart =
153: map { $_ => 1 } (&Apache::loncommon::get_env_multiple('form.vPart'));
1.377 albertel 154: my (%response_types,%handgrade);
155: foreach my $part (@{ $partlist }) {
1.392 albertel 156: next if (%vPart && !exists($vPart{$part}));
157:
1.377 albertel 158: my @types = $res->responseType($part);
159: my @ids = $res->responseIds($part);
160: for (my $i=0; $i < scalar(@ids); $i++) {
161: $response_types{$part}{$ids[$i]} = $types[$i];
162: $handgrade{$part.'_'.$ids[$i]} =
163: &Apache::lonnet::EXT('resource.'.$part.'_'.$ids[$i].
164: '.handgrade',$symb);
1.41 ng 165: }
166: }
1.377 albertel 167: return ($partlist,\%handgrade,\%response_types);
1.39 ng 168: }
169:
1.375 albertel 170: sub flatten_responseType {
171: my ($responseType) = @_;
172: my @part_response_id =
173: map {
174: my $part = $_;
175: map {
176: [$part,$_]
177: } sort(keys(%{ $responseType->{$part} }));
178: } sort(keys(%$responseType));
179: return @part_response_id;
180: }
181:
1.207 albertel 182: sub get_display_part {
1.324 albertel 183: my ($partID,$symb)=@_;
1.207 albertel 184: my $display=&Apache::lonnet::EXT('resource.'.$partID.'.display',$symb);
185: if (defined($display) and $display ne '') {
1.398 albertel 186: $display.= " (<span class=\"LC_internal_info\">id $partID</span>)";
1.207 albertel 187: } else {
188: $display=$partID;
189: }
190: return $display;
191: }
1.269 raeburn 192:
1.118 ng 193: #--- Show resource title
194: #--- and parts and response type
195: sub showResourceInfo {
1.324 albertel 196: my ($symb,$probTitle,$checkboxes) = @_;
1.154 albertel 197: my $col=3;
198: if ($checkboxes) { $col=4; }
1.398 albertel 199: my $result = '<h3>'.&mt('Current Resource').': '.$probTitle.'</h3>'."\n";
200: $result .='<table border="0">';
1.324 albertel 201: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.126 ng 202: my %resptype = ();
1.122 ng 203: my $hdgrade='no';
1.154 albertel 204: my %partsseen;
1.524 raeburn 205: foreach my $partID (sort(keys(%$responseType))) {
206: foreach my $resID (sort(keys(%{ $responseType->{$partID} }))) {
1.375 albertel 207: my $handgrade=$$handgrade{$partID.'_'.$resID};
208: my $responsetype = $responseType->{$partID}->{$resID};
209: $hdgrade = $handgrade if ($handgrade eq 'yes');
210: $result.='<tr>';
211: if ($checkboxes) {
212: if (exists($partsseen{$partID})) {
213: $result.="<td> </td>";
214: } else {
1.401 albertel 215: $result.="<td><input type='checkbox' name='vPart' value='$partID' checked='checked' /></td>";
1.375 albertel 216: }
217: $partsseen{$partID}=1;
1.154 albertel 218: }
1.375 albertel 219: my $display_part=&get_display_part($partID,$symb);
1.539 riegler 220: $result.='<td><b>'.&mt('Part').': </b>'.$display_part.
221: ' <span class="LC_internal_info">'.$resID.'</span></td>'.
222: '<td><b>'.&mt('Type').': </b>'.$responsetype.'</td></tr>';
1.485 albertel 223: # '<td>'.&mt('<b>Handgrade: </b>[_1]',$handgrade).'</td></tr>';
1.154 albertel 224: }
1.118 ng 225: }
226: $result.='</table>'."\n";
1.147 albertel 227: return $result,$responseType,$hdgrade,$partlist,$handgrade;
1.118 ng 228: }
229:
1.434 albertel 230: sub reset_caches {
231: &reset_analyze_cache();
232: &reset_perm();
233: }
234:
235: {
236: my %analyze_cache;
1.557 raeburn 237: my %analyze_cache_formkeys;
1.148 albertel 238:
1.434 albertel 239: sub reset_analyze_cache {
240: undef(%analyze_cache);
1.557 raeburn 241: undef(%analyze_cache_formkeys);
1.434 albertel 242: }
243:
244: sub get_analyze {
1.557 raeburn 245: my ($symb,$uname,$udom,$no_increment,$add_to_hash)=@_;
1.434 albertel 246: my $key = "$symb\0$uname\0$udom";
1.557 raeburn 247: if (exists($analyze_cache{$key})) {
248: my $getupdate = 0;
249: if (ref($add_to_hash) eq 'HASH') {
250: foreach my $item (keys(%{$add_to_hash})) {
251: if (ref($analyze_cache_formkeys{$key}) eq 'HASH') {
252: if (!exists($analyze_cache_formkeys{$key}{$item})) {
253: $getupdate = 1;
254: last;
255: }
256: } else {
257: $getupdate = 1;
258: }
259: }
260: }
261: if (!$getupdate) {
262: return $analyze_cache{$key};
263: }
264: }
1.434 albertel 265:
266: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
267: $url=&Apache::lonnet::clutter($url);
1.557 raeburn 268: my %form = ('grade_target' => 'analyze',
269: 'grade_domain' => $udom,
270: 'grade_symb' => $symb,
271: 'grade_courseid' => $env{'request.course.id'},
272: 'grade_username' => $uname,
273: 'grade_noincrement' => $no_increment);
274: if (ref($add_to_hash)) {
275: %form = (%form,%{$add_to_hash});
276: }
277: my $subresult=&ssi_with_retries($url, $ssi_retries,%form);
1.434 albertel 278: (undef,$subresult)=split(/_HASH_REF__/,$subresult,2);
279: my %analyze=&Apache::lonnet::str2hash($subresult);
1.557 raeburn 280: if (ref($add_to_hash) eq 'HASH') {
281: $analyze_cache_formkeys{$key} = $add_to_hash;
282: } else {
283: $analyze_cache_formkeys{$key} = {};
284: }
1.434 albertel 285: return $analyze_cache{$key} = \%analyze;
286: }
287:
288: sub get_order {
1.525 raeburn 289: my ($partid,$respid,$symb,$uname,$udom,$no_increment)=@_;
290: my $analyze = &get_analyze($symb,$uname,$udom,$no_increment);
1.434 albertel 291: return $analyze->{"$partid.$respid.shown"};
292: }
293:
294: sub get_radiobutton_correct_foil {
295: my ($partid,$respid,$symb,$uname,$udom)=@_;
296: my $analyze = &get_analyze($symb,$uname,$udom);
1.555 raeburn 297: my $foils = &get_order($partid,$respid,$symb,$uname,$udom);
298: if (ref($foils) eq 'ARRAY') {
299: foreach my $foil (@{$foils}) {
300: if ($analyze->{"$partid.$respid.foil.value.$foil"} eq 'true') {
301: return $foil;
302: }
1.434 albertel 303: }
304: }
305: }
1.554 raeburn 306:
307: sub scantron_partids_tograde {
1.557 raeburn 308: my ($resource,$cid,$uname,$udom,$check_for_randomlist) = @_;
1.554 raeburn 309: my (%analysis,@parts);
310: if (ref($resource)) {
311: my $symb = $resource->symb();
1.557 raeburn 312: my $add_to_form;
313: if ($check_for_randomlist) {
314: $add_to_form = { 'check_parts_withrandomlist' => 1,};
315: }
316: my $analyze = &get_analyze($symb,$uname,$udom,undef,$add_to_form);
1.554 raeburn 317: if (ref($analyze) eq 'HASH') {
318: %analysis = %{$analyze};
319: }
320: if (ref($analysis{'parts'}) eq 'ARRAY') {
321: foreach my $part (@{$analysis{'parts'}}) {
322: my ($id,$respid) = split(/\./,$part);
323: if (!&Apache::loncommon::check_if_partid_hidden($id,$symb,$udom,$uname)) {
324: push(@parts,$part);
325: }
326: }
327: }
328: }
329: return (\%analysis,\@parts);
330: }
331:
1.148 albertel 332: }
1.434 albertel 333:
1.118 ng 334: #--- Clean response type for display
1.335 albertel 335: #--- Currently filters option/rank/radiobutton/match/essay/Task
336: # response types only.
1.118 ng 337: sub cleanRecord {
1.336 albertel 338: my ($answer,$response,$symb,$partid,$respid,$record,$order,$version,
339: $uname,$udom) = @_;
1.398 albertel 340: my $grayFont = '<span class="LC_internal_info">';
1.148 albertel 341: if ($response =~ /^(option|rank)$/) {
342: my %answer=&Apache::lonnet::str2hash($answer);
343: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
344: my ($toprow,$bottomrow);
345: foreach my $foil (@$order) {
346: if ($grading{$foil} == 1) {
347: $toprow.='<td><b>'.$answer{$foil}.' </b></td>';
348: } else {
349: $toprow.='<td><i>'.$answer{$foil}.' </i></td>';
350: }
1.398 albertel 351: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.148 albertel 352: }
353: return '<blockquote><table border="1">'.
1.466 albertel 354: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
355: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.148 albertel 356: $grayFont.$bottomrow.'</tr>'.'</table></blockquote>';
357: } elsif ($response eq 'match') {
358: my %answer=&Apache::lonnet::str2hash($answer);
359: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
360: my @items=&Apache::lonnet::str2array($record->{$version."resource.$partid.$respid.submissionitems"});
361: my ($toprow,$middlerow,$bottomrow);
362: foreach my $foil (@$order) {
363: my $item=shift(@items);
364: if ($grading{$foil} == 1) {
365: $toprow.='<td><b>'.$item.' </b></td>';
1.398 albertel 366: $middlerow.='<td><b>'.$grayFont.$answer{$foil}.' </span></b></td>';
1.148 albertel 367: } else {
368: $toprow.='<td><i>'.$item.' </i></td>';
1.398 albertel 369: $middlerow.='<td><i>'.$grayFont.$answer{$foil}.' </span></i></td>';
1.148 albertel 370: }
1.398 albertel 371: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.118 ng 372: }
1.126 ng 373: return '<blockquote><table border="1">'.
1.466 albertel 374: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
375: '<tr valign="top"><td>'.$grayFont.&mt('Item ID').'</span></td>'.
1.148 albertel 376: $middlerow.'</tr>'.
1.466 albertel 377: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.148 albertel 378: $bottomrow.'</tr>'.'</table></blockquote>';
379: } elsif ($response eq 'radiobutton') {
380: my %answer=&Apache::lonnet::str2hash($answer);
381: my ($toprow,$bottomrow);
1.434 albertel 382: my $correct =
383: &get_radiobutton_correct_foil($partid,$respid,$symb,$uname,$udom);
384: foreach my $foil (@$order) {
1.148 albertel 385: if (exists($answer{$foil})) {
1.434 albertel 386: if ($foil eq $correct) {
1.466 albertel 387: $toprow.='<td><b>'.&mt('true').'</b></td>';
1.148 albertel 388: } else {
1.466 albertel 389: $toprow.='<td><i>'.&mt('true').'</i></td>';
1.148 albertel 390: }
391: } else {
1.466 albertel 392: $toprow.='<td>'.&mt('false').'</td>';
1.148 albertel 393: }
1.398 albertel 394: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.148 albertel 395: }
396: return '<blockquote><table border="1">'.
1.466 albertel 397: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
398: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.148 albertel 399: $grayFont.$bottomrow.'</tr>'.'</table></blockquote>';
400: } elsif ($response eq 'essay') {
1.257 albertel 401: if (! exists ($env{'form.'.$symb})) {
1.122 ng 402: my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 403: $env{'course.'.$env{'request.course.id'}.'.domain'},
404: $env{'course.'.$env{'request.course.id'}.'.num'});
1.122 ng 405:
1.257 albertel 406: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
407: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
408: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
409: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
410: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
411: $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 412: }
1.166 albertel 413: $answer =~ s-\n-<br />-g;
414: return '<br /><br /><blockquote><tt>'.&keywords_highlight($answer).'</tt></blockquote>';
1.268 albertel 415: } elsif ( $response eq 'organic') {
416: my $result='Smile representation: "<tt>'.$answer.'</tt>"';
417: my $jme=$record->{$version."resource.$partid.$respid.molecule"};
418: $result.=&Apache::chemresponse::jme_img($jme,$answer,400);
419: return $result;
1.335 albertel 420: } elsif ( $response eq 'Task') {
421: if ( $answer eq 'SUBMITTED') {
422: my $files = $record->{$version."resource.$respid.$partid.bridgetask.portfiles"};
1.336 albertel 423: my $result = &Apache::bridgetask::file_list($files,$uname,$udom);
1.335 albertel 424: return $result;
425: } elsif ( grep(/^\Q$version\E.*?\.instance$/, keys(%{$record})) ) {
426: my @matches = grep(/^\Q$version\E.*?\.instance$/,
427: keys(%{$record}));
428: return join('<br />',($version,@matches));
429:
430:
431: } else {
432: my $result =
433: '<p>'
434: .&mt('Overall result: [_1]',
435: $record->{$version."resource.$respid.$partid.status"})
436: .'</p>';
437:
438: $result .= '<ul>';
439: my @grade = grep(/^\Q${version}resource.$respid.$partid.\E[^.]*[.]status$/,
440: keys(%{$record}));
441: foreach my $grade (sort(@grade)) {
442: my ($dim) = ($grade =~/[.]([^.]+)[.]status$/);
443: $result.= '<li>'.&mt("Dimension: [_1], status [_2] ",
444: $dim, $record->{$grade}).
445: '</li>';
446: }
447: $result.='</ul>';
448: return $result;
449: }
1.440 albertel 450: } elsif ( $response =~ m/(?:numerical|formula)/) {
451: $answer =
452: &Apache::loncommon::format_previous_attempt_value('submission',
453: $answer);
1.122 ng 454: }
1.118 ng 455: return $answer;
456: }
457:
458: #-- A couple of common js functions
459: sub commonJSfunctions {
460: my $request = shift;
461: $request->print(<<COMMONJSFUNCTIONS);
462: <script type="text/javascript" language="javascript">
463: function radioSelection(radioButton) {
464: var selection=null;
465: if (radioButton.length > 1) {
466: for (var i=0; i<radioButton.length; i++) {
467: if (radioButton[i].checked) {
468: return radioButton[i].value;
469: }
470: }
471: } else {
472: if (radioButton.checked) return radioButton.value;
473: }
474: return selection;
475: }
476:
477: function pullDownSelection(selectOne) {
478: var selection="";
479: if (selectOne.length > 1) {
480: for (var i=0; i<selectOne.length; i++) {
481: if (selectOne[i].selected) {
482: return selectOne[i].value;
483: }
484: }
485: } else {
1.138 albertel 486: // only one value it must be the selected one
487: return selectOne.value;
1.118 ng 488: }
489: }
490: </script>
491: COMMONJSFUNCTIONS
492: }
493:
1.44 ng 494: #--- Dumps the class list with usernames,list of sections,
495: #--- section, ids and fullnames for each user.
496: sub getclasslist {
1.449 banghart 497: my ($getsec,$filterlist,$getgroup) = @_;
1.291 albertel 498: my @getsec;
1.450 banghart 499: my @getgroup;
1.442 banghart 500: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.291 albertel 501: if (!ref($getsec)) {
502: if ($getsec ne '' && $getsec ne 'all') {
503: @getsec=($getsec);
504: }
505: } else {
506: @getsec=@{$getsec};
507: }
508: if (grep(/^all$/,@getsec)) { undef(@getsec); }
1.450 banghart 509: if (!ref($getgroup)) {
510: if ($getgroup ne '' && $getgroup ne 'all') {
511: @getgroup=($getgroup);
512: }
513: } else {
514: @getgroup=@{$getgroup};
515: }
516: if (grep(/^all$/,@getgroup)) { undef(@getgroup); }
1.291 albertel 517:
1.449 banghart 518: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
1.49 albertel 519: # Bail out if we were unable to get the classlist
1.56 matthew 520: return if (! defined($classlist));
1.449 banghart 521: &Apache::loncoursedata::get_group_memberships($classlist,$keylist);
1.56 matthew 522: #
523: my %sections;
524: my %fullnames;
1.205 matthew 525: foreach my $student (keys(%$classlist)) {
526: my $end =
527: $classlist->{$student}->[&Apache::loncoursedata::CL_END()];
528: my $start =
529: $classlist->{$student}->[&Apache::loncoursedata::CL_START()];
530: my $id =
531: $classlist->{$student}->[&Apache::loncoursedata::CL_ID()];
532: my $section =
533: $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
534: my $fullname =
535: $classlist->{$student}->[&Apache::loncoursedata::CL_FULLNAME()];
536: my $status =
537: $classlist->{$student}->[&Apache::loncoursedata::CL_STATUS()];
1.449 banghart 538: my $group =
539: $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1.76 ng 540: # filter students according to status selected
1.442 banghart 541: if ($filterlist && (!($stu_status =~ /Any/))) {
542: if (!($stu_status =~ $status)) {
1.450 banghart 543: delete($classlist->{$student});
1.76 ng 544: next;
545: }
546: }
1.450 banghart 547: # filter students according to groups selected
1.453 banghart 548: my @stu_groups = split(/,/,$group);
1.450 banghart 549: if (@getgroup) {
550: my $exclude = 1;
1.454 banghart 551: foreach my $grp (@getgroup) {
552: foreach my $stu_group (@stu_groups) {
1.453 banghart 553: if ($stu_group eq $grp) {
554: $exclude = 0;
555: }
1.450 banghart 556: }
1.453 banghart 557: if (($grp eq 'none') && !$group) {
558: $exclude = 0;
559: }
1.450 banghart 560: }
561: if ($exclude) {
562: delete($classlist->{$student});
563: }
564: }
1.205 matthew 565: $section = ($section ne '' ? $section : 'none');
1.106 albertel 566: if (&canview($section)) {
1.291 albertel 567: if (!@getsec || grep(/^\Q$section\E$/,@getsec)) {
1.103 albertel 568: $sections{$section}++;
1.450 banghart 569: if ($classlist->{$student}) {
570: $fullnames{$student}=$fullname;
571: }
1.103 albertel 572: } else {
1.205 matthew 573: delete($classlist->{$student});
1.103 albertel 574: }
575: } else {
1.205 matthew 576: delete($classlist->{$student});
1.103 albertel 577: }
1.44 ng 578: }
579: my %seen = ();
1.56 matthew 580: my @sections = sort(keys(%sections));
581: return ($classlist,\@sections,\%fullnames);
1.44 ng 582: }
583:
1.103 albertel 584: sub canmodify {
585: my ($sec)=@_;
586: if ($perm{'mgr'}) {
587: if (!defined($perm{'mgr_section'})) {
588: # can modify whole class
589: return 1;
590: } else {
591: if ($sec eq $perm{'mgr_section'}) {
592: #can modify the requested section
593: return 1;
594: } else {
595: # can't modify the request section
596: return 0;
597: }
598: }
599: }
600: #can't modify
601: return 0;
602: }
603:
604: sub canview {
605: my ($sec)=@_;
606: if ($perm{'vgr'}) {
607: if (!defined($perm{'vgr_section'})) {
608: # can modify whole class
609: return 1;
610: } else {
611: if ($sec eq $perm{'vgr_section'}) {
612: #can modify the requested section
613: return 1;
614: } else {
615: # can't modify the request section
616: return 0;
617: }
618: }
619: }
620: #can't modify
621: return 0;
622: }
623:
1.44 ng 624: #--- Retrieve the grade status of a student for all the parts
625: sub student_gradeStatus {
1.324 albertel 626: my ($symb,$udom,$uname,$partlist) = @_;
1.257 albertel 627: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.44 ng 628: my %partstatus = ();
629: foreach (@$partlist) {
1.128 ng 630: my ($status,undef) = split(/_/,$record{"resource.$_.solved"},2);
1.44 ng 631: $status = 'nothing' if ($status eq '');
632: $partstatus{$_} = $status;
633: my $subkey = "resource.$_.submitted_by";
634: $partstatus{$subkey} = $record{$subkey} if ($record{$subkey} ne '');
635: }
636: return %partstatus;
637: }
638:
1.45 ng 639: # hidden form and javascript that calls the form
640: # Use by verifyscript and viewgrades
641: # Shows a student's view of problem and submission
642: sub jscriptNform {
1.324 albertel 643: my ($symb) = @_;
1.442 banghart 644: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.45 ng 645: my $jscript='<script type="text/javascript" language="javascript">'."\n".
646: ' function viewOneStudent(user,domain) {'."\n".
647: ' document.onestudent.student.value = user;'."\n".
648: ' document.onestudent.userdom.value = domain;'."\n".
649: ' document.onestudent.submit();'."\n".
650: ' }'."\n".
651: '</script>'."\n";
652: $jscript.= '<form action="/adm/grades" method="post" name="onestudent">'."\n".
1.418 albertel 653: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 654: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
655: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.442 banghart 656: '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.45 ng 657: '<input type="hidden" name="command" value="submission" />'."\n".
658: '<input type="hidden" name="student" value="" />'."\n".
659: '<input type="hidden" name="userdom" value="" />'."\n".
660: '</form>'."\n";
661: return $jscript;
662: }
1.39 ng 663:
1.447 foxr 664:
665:
1.315 bowersj2 666: # Given the score (as a number [0-1] and the weight) what is the final
667: # point value? This function will round to the nearest tenth, third,
668: # or quarter if one of those is within the tolerance of .00001.
1.316 albertel 669: sub compute_points {
1.315 bowersj2 670: my ($score, $weight) = @_;
671:
672: my $tolerance = .00001;
673: my $points = $score * $weight;
674:
675: # Check for nearness to 1/x.
676: my $check_for_nearness = sub {
677: my ($factor) = @_;
678: my $num = ($points * $factor) + $tolerance;
679: my $floored_num = floor($num);
1.316 albertel 680: if ($num - $floored_num < 2 * $tolerance * $factor) {
1.315 bowersj2 681: return $floored_num / $factor;
682: }
683: return $points;
684: };
685:
686: $points = $check_for_nearness->(10);
687: $points = $check_for_nearness->(3);
688: $points = $check_for_nearness->(4);
689:
690: return $points;
691: }
692:
1.44 ng 693: #------------------ End of general use routines --------------------
1.87 www 694:
695: #
696: # Find most similar essay
697: #
698:
699: sub most_similar {
1.426 albertel 700: my ($uname,$udom,$uessay,$old_essays)=@_;
1.87 www 701:
702: # ignore spaces and punctuation
703:
704: $uessay=~s/\W+/ /gs;
705:
1.282 www 706: # ignore empty submissions (occuring when only files are sent)
707:
708: unless ($uessay=~/\w+/) { return ''; }
709:
1.87 www 710: # these will be returned. Do not care if not at least 50 percent similar
1.88 www 711: my $limit=0.6;
1.87 www 712: my $sname='';
713: my $sdom='';
714: my $scrsid='';
715: my $sessay='';
716: # go through all essays ...
1.426 albertel 717: foreach my $tkey (keys(%$old_essays)) {
718: my ($tname,$tdom,$tcrsid)=map {&unescape($_)} (split(/\./,$tkey));
1.87 www 719: # ... except the same student
1.426 albertel 720: next if (($tname eq $uname) && ($tdom eq $udom));
721: my $tessay=$old_essays->{$tkey};
722: $tessay=~s/\W+/ /gs;
1.87 www 723: # String similarity gives up if not even limit
1.426 albertel 724: my $tsimilar=&String::Similarity::similarity($uessay,$tessay,$limit);
1.87 www 725: # Found one
1.426 albertel 726: if ($tsimilar>$limit) {
727: $limit=$tsimilar;
728: $sname=$tname;
729: $sdom=$tdom;
730: $scrsid=$tcrsid;
731: $sessay=$old_essays->{$tkey};
732: }
1.87 www 733: }
1.88 www 734: if ($limit>0.6) {
1.87 www 735: return ($sname,$sdom,$scrsid,$sessay,$limit);
736: } else {
737: return ('','','','',0);
738: }
739: }
740:
1.44 ng 741: #-------------------------------------------------------------------
742:
743: #------------------------------------ Receipt Verification Routines
1.45 ng 744: #
1.44 ng 745: #--- Check whether a receipt number is valid.---
746: sub verifyreceipt {
747: my $request = shift;
748:
1.257 albertel 749: my $courseid = $env{'request.course.id'};
1.184 www 750: my $receipt = &Apache::lonnet::recprefix($courseid).'-'.
1.257 albertel 751: $env{'form.receipt'};
1.44 ng 752: $receipt =~ s/[^\-\d]//g;
1.378 albertel 753: my ($symb) = &get_symb($request);
1.44 ng 754:
1.487 albertel 755: my $title.=
756: '<h3><span class="LC_info">'.
1.553 biermanm 757: &mt('Verifying Receipt No. [_1]',$receipt).
1.487 albertel 758: '</span></h3>'."\n".
759: '<h4>'.&mt('<b>Resource: </b>[_1]',$env{'form.probTitle'}).
760: '</h4>'."\n";
1.44 ng 761:
762: my ($string,$contents,$matches) = ('','',0);
1.56 matthew 763: my (undef,undef,$fullname) = &getclasslist('all','0');
1.177 albertel 764:
765: my $receiptparts=0;
1.390 albertel 766: if ($env{"course.$courseid.receiptalg"} eq 'receipt2' ||
767: $env{"course.$courseid.receiptalg"} eq 'receipt3') { $receiptparts=1; }
1.177 albertel 768: my $parts=['0'];
1.324 albertel 769: if ($receiptparts) { ($parts)=&response_type($symb); }
1.486 albertel 770:
771: my $header =
772: &Apache::loncommon::start_data_table().
773: &Apache::loncommon::start_data_table_header_row().
1.487 albertel 774: '<th> '.&mt('Fullname').' </th>'."\n".
775: '<th> '.&mt('Username').' </th>'."\n".
776: '<th> '.&mt('Domain').' </th>';
1.486 albertel 777: if ($receiptparts) {
1.487 albertel 778: $header.='<th> '.&mt('Problem Part').' </th>';
1.486 albertel 779: }
780: $header.=
781: &Apache::loncommon::end_data_table_header_row();
782:
1.294 albertel 783: foreach (sort
784: {
785: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
786: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
787: }
788: return $a cmp $b;
789: } (keys(%$fullname))) {
1.44 ng 790: my ($uname,$udom)=split(/\:/);
1.177 albertel 791: foreach my $part (@$parts) {
792: if ($receipt eq &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb,$part)) {
1.486 albertel 793: $contents.=
794: &Apache::loncommon::start_data_table_row().
795: '<td> '."\n".
1.177 albertel 796: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 797: '\');" target="_self">'.$$fullname{$_}.'</a> </td>'."\n".
1.177 albertel 798: '<td> '.$uname.' </td>'.
799: '<td> '.$udom.' </td>';
800: if ($receiptparts) {
801: $contents.='<td> '.$part.' </td>';
802: }
1.486 albertel 803: $contents.=
804: &Apache::loncommon::end_data_table_row()."\n";
1.177 albertel 805:
806: $matches++;
807: }
1.44 ng 808: }
809: }
810: if ($matches == 0) {
1.487 albertel 811: $string = $title.&mt('No match found for the above receipt.');
1.44 ng 812: } else {
1.324 albertel 813: $string = &jscriptNform($symb).$title.
1.487 albertel 814: '<p>'.
815: &mt('The above receipt matches the following [numerate,_1,student].',$matches).
816: '</p>'.
1.486 albertel 817: $header.
818: $contents.
819: &Apache::loncommon::end_data_table()."\n";
1.44 ng 820: }
1.324 albertel 821: return $string.&show_grading_menu_form($symb);
1.44 ng 822: }
823:
824: #--- This is called by a number of programs.
825: #--- Called from the Grading Menu - View/Grade an individual student
826: #--- Also called directly when one clicks on the subm button
827: # on the problem page.
1.30 ng 828: sub listStudents {
1.41 ng 829: my ($request) = shift;
1.49 albertel 830:
1.324 albertel 831: my ($symb) = &get_symb($request);
1.257 albertel 832: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
833: my $cnum = $env{"course.$env{'request.course.id'}.num"};
834: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.449 banghart 835: my $getgroup = $env{'form.group'} eq '' ? 'all' : $env{'form.group'};
1.257 albertel 836: my $submitonly= $env{'form.submitonly'} eq '' ? 'all' : $env{'form.submitonly'};
1.548 bisitz 837: my $viewgrade = $env{'form.showgrading'} eq 'yes' ? 'View/Grade/Regrade' : 'View';
1.257 albertel 838: $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
839: &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
1.49 albertel 840:
1.548 bisitz 841: my $result='<h3><span class="LC_info"> '
842: .&mt("$viewgrade Submissions for a Student or a Group of Students")
1.485 albertel 843: .'</span></h3>';
1.118 ng 844:
1.324 albertel 845: my ($table,undef,$hdgrade,$partlist,$handgrade) = &showResourceInfo($symb,$env{'form.probTitle'},($env{'form.showgrading'} eq 'yes'));
1.49 albertel 846:
1.559 raeburn 847: my %lt = &Apache::lonlocal::texthash (
848: 'multiple' => 'Please select a student or group of students before clicking on the Next button.',
849: 'single' => 'Please select the student before clicking on the Next button.',
850: );
1.45 ng 851: $request->print(<<LISTJAVASCRIPT);
852: <script type="text/javascript" language="javascript">
1.110 ng 853: function checkSelect(checkBox) {
854: var ctr=0;
855: var sense="";
856: if (checkBox.length > 1) {
857: for (var i=0; i<checkBox.length; i++) {
858: if (checkBox[i].checked) {
859: ctr++;
860: }
861: }
1.485 albertel 862: sense = '$lt{'multiple'}';
1.110 ng 863: } else {
864: if (checkBox.checked) {
865: ctr = 1;
866: }
1.485 albertel 867: sense = '$lt{'single'}';
1.110 ng 868: }
869: if (ctr == 0) {
1.485 albertel 870: alert(sense);
1.110 ng 871: return false;
872: }
873: document.gradesub.submit();
874: }
875:
876: function reLoadList(formname) {
1.112 ng 877: if (formname.saveStatusOld.value == pullDownSelection(formname.Status)) {return;}
1.110 ng 878: formname.command.value = 'submission';
879: formname.submit();
880: }
1.45 ng 881: </script>
882: LISTJAVASCRIPT
883:
1.118 ng 884: &commonJSfunctions($request);
1.41 ng 885: $request->print($result);
1.39 ng 886:
1.401 albertel 887: my $checkhdgrade = ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1 ) ? 'checked="checked"' : '';
888: my $checklastsub = $checkhdgrade eq '' ? 'checked="checked"' : '';
1.154 albertel 889: my $gradeTable='<form action="/adm/grades" method="post" name="gradesub">'.
1.485 albertel 890: "\n".$table;
891:
1.561 bisitz 892: $gradeTable .= &Apache::lonhtmlcommon::start_pick_box();
893: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Problem Text'))
894: .'<label><input type="radio" name="vProb" value="no" checked="checked" /> '.&mt('no').' </label>'."\n"
895: .'<label><input type="radio" name="vProb" value="yes" /> '.&mt('one student').' </label>'."\n"
896: .'<label><input type="radio" name="vProb" value="all" /> '.&mt('all students').' </label><br />'."\n"
897: .&Apache::lonhtmlcommon::row_closure();
898: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Answer'))
899: .'<label><input type="radio" name="vAns" value="no" /> '.&mt('no').' </label>'."\n"
900: .'<label><input type="radio" name="vAns" value="yes" /> '.&mt('one student').' </label>'."\n"
901: .'<label><input type="radio" name="vAns" value="all" checked="checked" /> '.&mt('all students').' </label><br />'."\n"
902: .&Apache::lonhtmlcommon::row_closure();
1.485 albertel 903:
904: my $submission_options;
1.257 albertel 905: if ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1) {
1.485 albertel 906: $submission_options.=
907: '<label><input type="radio" name="lastSub" value="hdgrade" '.$checkhdgrade.' /> '.&mt('essay part only').' </label>'."\n";
1.49 albertel 908: }
1.442 banghart 909: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
910: my $saveStatus = $stu_status eq '' ? 'Active' : $stu_status;
1.257 albertel 911: $env{'form.Status'} = $saveStatus;
1.485 albertel 912: $submission_options.=
913: '<label><input type="radio" name="lastSub" value="lastonly" '.$checklastsub.' /> '.&mt('last submission only').' </label>'."\n".
914: '<label><input type="radio" name="lastSub" value="last" /> '.&mt('last submission & parts info').' </label>'."\n".
915: '<label><input type="radio" name="lastSub" value="datesub" /> '.&mt('by dates and submissions').' </label>'."\n".
916: '<label><input type="radio" name="lastSub" value="all" /> '.&mt('all details').'</label>';
1.561 bisitz 917: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Submissions'))
918: .$submission_options
919: .&Apache::lonhtmlcommon::row_closure();
920:
921: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Grading Increments'))
922: .'<select name="increment">'
923: .'<option value="1">'.&mt('Whole Points').'</option>'
924: .'<option value=".5">'.&mt('Half Points').'</option>'
925: .'<option value=".25">'.&mt('Quarter Points').'</option>'
926: .'<option value=".1">'.&mt('Tenths of a Point').'</option>'
927: .'</select>'
928: .&Apache::lonhtmlcommon::row_closure();
1.485 albertel 929:
930: $gradeTable .=
1.432 banghart 931: &build_section_inputs().
1.45 ng 932: '<input type="hidden" name="submitonly" value="'.$submitonly.'" />'."\n".
1.257 albertel 933: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" /><br />'."\n".
934: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" /><br />'."\n".
935: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
936: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.418 albertel 937: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.110 ng 938: '<input type="hidden" name="saveStatusOld" value="'.$saveStatus.'" />'."\n";
939:
1.257 albertel 940: if (exists($env{'form.gradingMenu'}) && exists($env{'form.Status'})) {
1.561 bisitz 941: $gradeTable .= '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n";
1.124 ng 942: } else {
1.561 bisitz 943: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Student Status'))
944: .&Apache::lonhtmlcommon::StatusOptions(
945: $saveStatus,undef,1,'javascript:reLoadList(this.form);')
946: .&Apache::lonhtmlcommon::row_closure();
1.124 ng 947: }
1.112 ng 948:
1.561 bisitz 949: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Check For Plagiarism'))
950: .'<input type="checkbox" name="checkPlag" checked="checked" />'
951: .&Apache::lonhtmlcommon::row_closure(1)
952: .&Apache::lonhtmlcommon::end_pick_box();
953:
954: $gradeTable .= '<p>'
955: .&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"
956: .'<input type="hidden" name="command" value="processGroup" />'
957: .'</p>';
1.249 albertel 958:
959: # checkall buttons
960: $gradeTable.=&check_script('gradesub', 'stuinfo');
1.110 ng 961: $gradeTable.='<input type="button" '."\n".
1.45 ng 962: 'onClick="javascript:checkSelect(this.form.stuinfo);" '."\n".
1.539 riegler 963: 'value="'.&mt('Next').' →" /> <br />'."\n";
1.249 albertel 964: $gradeTable.=&check_buttons();
1.450 banghart 965: my ($classlist, undef, $fullname) = &getclasslist($getsec,'1',$getgroup);
1.474 albertel 966: $gradeTable.= &Apache::loncommon::start_data_table().
967: &Apache::loncommon::start_data_table_header_row();
1.110 ng 968: my $loop = 0;
969: while ($loop < 2) {
1.485 albertel 970: $gradeTable.='<th>'.&mt('No.').'</th><th>'.&mt('Select').'</th>'.
971: '<th>'.&nameUserString('header').' '.&mt('Section/Group').'</th>';
1.301 albertel 972: if ($env{'form.showgrading'} eq 'yes'
973: && $submitonly ne 'queued'
974: && $submitonly ne 'all') {
1.485 albertel 975: foreach my $part (sort(@$partlist)) {
976: my $display_part=
977: &get_display_part((split(/_/,$part))[0],$symb);
978: $gradeTable.=
979: '<th>'.&mt('Part: [_1] Status',$display_part).'</th>';
1.110 ng 980: }
1.301 albertel 981: } elsif ($submitonly eq 'queued') {
1.474 albertel 982: $gradeTable.='<th>'.&mt('Queue Status').' </th>';
1.110 ng 983: }
984: $loop++;
1.126 ng 985: # $gradeTable.='<td></td>' if ($loop%2 ==1);
1.41 ng 986: }
1.474 albertel 987: $gradeTable.=&Apache::loncommon::end_data_table_header_row()."\n";
1.41 ng 988:
1.45 ng 989: my $ctr = 0;
1.294 albertel 990: foreach my $student (sort
991: {
992: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
993: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
994: }
995: return $a cmp $b;
996: }
997: (keys(%$fullname))) {
1.41 ng 998: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 999:
1.110 ng 1000: my %status = ();
1.301 albertel 1001:
1002: if ($submitonly eq 'queued') {
1003: my %queue_status =
1004: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
1005: $udom,$uname);
1006: next if (!defined($queue_status{'gradingqueue'}));
1007: $status{'gradingqueue'} = $queue_status{'gradingqueue'};
1008: }
1009:
1010: if ($env{'form.showgrading'} eq 'yes'
1011: && $submitonly ne 'queued'
1012: && $submitonly ne 'all') {
1.324 albertel 1013: (%status) =&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 1014: my $submitted = 0;
1.164 albertel 1015: my $graded = 0;
1.248 albertel 1016: my $incorrect = 0;
1.110 ng 1017: foreach (keys(%status)) {
1.145 albertel 1018: $submitted = 1 if ($status{$_} ne 'nothing');
1.248 albertel 1019: $graded = 1 if ($status{$_} =~ /^ungraded/);
1020: $incorrect = 1 if ($status{$_} =~ /^incorrect/);
1021:
1.110 ng 1022: my ($foo,$partid,$foo1) = split(/\./,$_);
1023: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
1.145 albertel 1024: $submitted = 0;
1.150 albertel 1025: my ($part)=split(/\./,$partid);
1.110 ng 1026: $gradeTable.='<input type="hidden" name="'.
1.150 albertel 1027: $student.':'.$part.':submitted_by" value="'.
1.110 ng 1028: $status{'resource.'.$partid.'.submitted_by'}.'" />';
1029: }
1.41 ng 1030: }
1.248 albertel 1031:
1.156 albertel 1032: next if (!$submitted && ($submitonly eq 'yes' ||
1033: $submitonly eq 'incorrect' ||
1034: $submitonly eq 'graded'));
1.248 albertel 1035: next if (!$graded && ($submitonly eq 'graded'));
1036: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 1037: }
1.34 ng 1038:
1.45 ng 1039: $ctr++;
1.249 albertel 1040: my $section = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
1.452 banghart 1041: my $group = $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1.104 albertel 1042: if ( $perm{'vgr'} eq 'F' ) {
1.474 albertel 1043: if ($ctr%2 ==1) {
1044: $gradeTable.= &Apache::loncommon::start_data_table_row();
1045: }
1.126 ng 1046: $gradeTable.='<td align="right">'.$ctr.' </td>'.
1.563 bisitz 1047: '<td align="center"><label><input type="checkbox" name="stuinfo" value="'.
1.249 albertel 1048: $student.':'.$$fullname{$student}.':::SECTION'.$section.
1049: ') " /> </label></td>'."\n".'<td>'.
1050: &nameUserString(undef,$$fullname{$student},$uname,$udom).
1.474 albertel 1051: ' '.$section.($group ne '' ?'/'.$group:'').'</td>'."\n";
1.110 ng 1052:
1.257 albertel 1053: if ($env{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
1.524 raeburn 1054: foreach (sort(keys(%status))) {
1.485 albertel 1055: next if ($_ =~ /^resource.*?submitted_by$/);
1056: $gradeTable.='<td align="center"> '.&mt($status{$_}).' </td>'."\n";
1.110 ng 1057: }
1.41 ng 1058: }
1.126 ng 1059: # $gradeTable.='<td></td>' if ($ctr%2 ==1);
1.474 albertel 1060: if ($ctr%2 ==0) {
1061: $gradeTable.=&Apache::loncommon::end_data_table_row()."\n";
1062: }
1.41 ng 1063: }
1064: }
1.110 ng 1065: if ($ctr%2 ==1) {
1.126 ng 1066: $gradeTable.='<td> </td><td> </td><td> </td>';
1.301 albertel 1067: if ($env{'form.showgrading'} eq 'yes'
1068: && $submitonly ne 'queued'
1069: && $submitonly ne 'all') {
1.110 ng 1070: foreach (@$partlist) {
1071: $gradeTable.='<td> </td>';
1072: }
1.301 albertel 1073: } elsif ($submitonly eq 'queued') {
1074: $gradeTable.='<td> </td>';
1.110 ng 1075: }
1.474 albertel 1076: $gradeTable.=&Apache::loncommon::end_data_table_row();
1.110 ng 1077: }
1078:
1.474 albertel 1079: $gradeTable.=&Apache::loncommon::end_data_table()."\n".
1.45 ng 1080: '<input type="button" '.
1081: 'onClick="javascript:checkSelect(this.form.stuinfo);" '.
1.539 riegler 1082: 'value="'.&mt('Next').' →" /></form>'."\n";
1.45 ng 1083: if ($ctr == 0) {
1.96 albertel 1084: my $num_students=(scalar(keys(%$fullname)));
1085: if ($num_students eq 0) {
1.485 albertel 1086: $gradeTable='<br /> <span class="LC_warning">'.&mt('There are no students currently enrolled.').'</span>';
1.96 albertel 1087: } else {
1.171 albertel 1088: my $submissions='submissions';
1089: if ($submitonly eq 'incorrect') { $submissions = 'incorrect submissions'; }
1090: if ($submitonly eq 'graded' ) { $submissions = 'ungraded submissions'; }
1.301 albertel 1091: if ($submitonly eq 'queued' ) { $submissions = 'queued submissions'; }
1.398 albertel 1092: $gradeTable='<br /> <span class="LC_warning">'.
1.485 albertel 1093: &mt('No '.$submissions.' found for this resource for any students. ([_1] students checked for '.$submissions.')',
1094: $num_students).
1095: '</span><br />';
1.96 albertel 1096: }
1.46 ng 1097: } elsif ($ctr == 1) {
1.474 albertel 1098: $gradeTable =~ s/type="checkbox"/type="checkbox" checked="checked"/;
1.45 ng 1099: }
1.324 albertel 1100: $gradeTable.=&show_grading_menu_form($symb);
1.45 ng 1101: $request->print($gradeTable);
1.44 ng 1102: return '';
1.10 ng 1103: }
1104:
1.44 ng 1105: #---- Called from the listStudents routine
1.249 albertel 1106:
1107: sub check_script {
1108: my ($form, $type)=@_;
1109: my $chkallscript='<script type="text/javascript">
1110: function checkall() {
1111: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1112: ele = document.forms.'.$form.'.elements[i];
1113: if (ele.name == "'.$type.'") {
1114: document.forms.'.$form.'.elements[i].checked=true;
1115: }
1116: }
1117: }
1118:
1119: function checksec() {
1120: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1121: ele = document.forms.'.$form.'.elements[i];
1122: string = document.forms.'.$form.'.chksec.value;
1123: if
1124: (ele.value.indexOf(":::SECTION"+string)>0) {
1125: document.forms.'.$form.'.elements[i].checked=true;
1126: }
1127: }
1128: }
1129:
1130:
1131: function uncheckall() {
1132: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1133: ele = document.forms.'.$form.'.elements[i];
1134: if (ele.name == "'.$type.'") {
1135: document.forms.'.$form.'.elements[i].checked=false;
1136: }
1137: }
1138: }
1139:
1140: </script>'."\n";
1141: return $chkallscript;
1142: }
1143:
1144: sub check_buttons {
1.485 albertel 1145: my $buttons.='<input type="button" onclick="checkall()" value="'.&mt('Check All').'" />';
1146: $buttons.='<input type="button" onclick="uncheckall()" value="'.&mt('Uncheck All').'" /> ';
1147: $buttons.='<input type="button" onclick="checksec()" value="'.&mt('Check Section/Group').'" />';
1.249 albertel 1148: $buttons.='<input type="text" size="5" name="chksec" /> ';
1149: return $buttons;
1150: }
1151:
1.44 ng 1152: # Displays the submissions for one student or a group of students
1.34 ng 1153: sub processGroup {
1.41 ng 1154: my ($request) = shift;
1155: my $ctr = 0;
1.155 albertel 1156: my @stuchecked = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.41 ng 1157: my $total = scalar(@stuchecked)-1;
1.45 ng 1158:
1.396 banghart 1159: foreach my $student (@stuchecked) {
1160: my ($uname,$udom,$fullname) = split(/:/,$student);
1.257 albertel 1161: $env{'form.student'} = $uname;
1162: $env{'form.userdom'} = $udom;
1163: $env{'form.fullname'} = $fullname;
1.41 ng 1164: &submission($request,$ctr,$total);
1165: $ctr++;
1166: }
1167: return '';
1.35 ng 1168: }
1.34 ng 1169:
1.44 ng 1170: #------------------------------------------------------------------------------------
1171: #
1172: #-------------------------- Next few routines handles grading by student, essentially
1173: # handles essay response type problem/part
1174: #
1175: #--- Javascript to handle the submission page functionality ---
1176: sub sub_page_js {
1177: my $request = shift;
1.539 riegler 1178: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
1.44 ng 1179: $request->print(<<SUBJAVASCRIPT);
1180: <script type="text/javascript" language="javascript">
1.71 ng 1181: function updateRadio(formname,id,weight) {
1.125 ng 1182: var gradeBox = formname["GD_BOX"+id];
1183: var radioButton = formname["RADVAL"+id];
1184: var oldpts = formname["oldpts"+id].value;
1.72 ng 1185: var pts = checkSolved(formname,id) == 'update' ? gradeBox.value : oldpts;
1.71 ng 1186: gradeBox.value = pts;
1187: var resetbox = false;
1188: if (isNaN(pts) || pts < 0) {
1.539 riegler 1189: alert("$alertmsg"+pts);
1.71 ng 1190: for (var i=0; i<radioButton.length; i++) {
1191: if (radioButton[i].checked) {
1192: gradeBox.value = i;
1193: resetbox = true;
1194: }
1195: }
1196: if (!resetbox) {
1197: formtextbox.value = "";
1198: }
1199: return;
1.44 ng 1200: }
1.71 ng 1201:
1202: if (pts > weight) {
1203: var resp = confirm("You entered a value ("+pts+
1204: ") greater than the weight for the part. Accept?");
1205: if (resp == false) {
1.125 ng 1206: gradeBox.value = oldpts;
1.71 ng 1207: return;
1208: }
1.44 ng 1209: }
1.13 albertel 1210:
1.71 ng 1211: for (var i=0; i<radioButton.length; i++) {
1212: radioButton[i].checked=false;
1213: if (pts == i && pts != "") {
1214: radioButton[i].checked=true;
1215: }
1216: }
1217: updateSelect(formname,id);
1.125 ng 1218: formname["stores"+id].value = "0";
1.41 ng 1219: }
1.5 albertel 1220:
1.72 ng 1221: function writeBox(formname,id,pts) {
1.125 ng 1222: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1223: if (checkSolved(formname,id) == 'update') {
1224: gradeBox.value = pts;
1225: } else {
1.125 ng 1226: var oldpts = formname["oldpts"+id].value;
1.72 ng 1227: gradeBox.value = oldpts;
1.125 ng 1228: var radioButton = formname["RADVAL"+id];
1.71 ng 1229: for (var i=0; i<radioButton.length; i++) {
1230: radioButton[i].checked=false;
1.72 ng 1231: if (i == oldpts) {
1.71 ng 1232: radioButton[i].checked=true;
1233: }
1234: }
1.41 ng 1235: }
1.125 ng 1236: formname["stores"+id].value = "0";
1.71 ng 1237: updateSelect(formname,id);
1238: return;
1.41 ng 1239: }
1.44 ng 1240:
1.71 ng 1241: function clearRadBox(formname,id) {
1242: if (checkSolved(formname,id) == 'noupdate') {
1243: updateSelect(formname,id);
1244: return;
1245: }
1.125 ng 1246: gradeSelect = formname["GD_SEL"+id];
1.71 ng 1247: for (var i=0; i<gradeSelect.length; i++) {
1248: if (gradeSelect[i].selected) {
1249: var selectx=i;
1250: }
1251: }
1.125 ng 1252: var stores = formname["stores"+id];
1.71 ng 1253: if (selectx == stores.value) { return };
1.125 ng 1254: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1255: gradeBox.value = "";
1.125 ng 1256: var radioButton = formname["RADVAL"+id];
1.71 ng 1257: for (var i=0; i<radioButton.length; i++) {
1258: radioButton[i].checked=false;
1259: }
1260: stores.value = selectx;
1261: }
1.5 albertel 1262:
1.71 ng 1263: function checkSolved(formname,id) {
1.125 ng 1264: if (formname["solved"+id].value == "correct_by_student" && formname.overRideScore.value == 'no') {
1.118 ng 1265: var reply = confirm("This problem has been graded correct by the computer. Do you want to change the score?");
1266: if (!reply) {return "noupdate";}
1.120 ng 1267: formname.overRideScore.value = 'yes';
1.41 ng 1268: }
1.71 ng 1269: return "update";
1.13 albertel 1270: }
1.71 ng 1271:
1272: function updateSelect(formname,id) {
1.125 ng 1273: formname["GD_SEL"+id][0].selected = true;
1.71 ng 1274: return;
1.41 ng 1275: }
1.33 ng 1276:
1.121 ng 1277: //=========== Check that a point is assigned for all the parts ============
1.71 ng 1278: function checksubmit(formname,val,total,parttot) {
1.121 ng 1279: formname.gradeOpt.value = val;
1.71 ng 1280: if (val == "Save & Next") {
1281: for (i=0;i<=total;i++) {
1282: for (j=0;j<parttot;j++) {
1.125 ng 1283: var partid = formname["partid"+i+"_"+j].value;
1.127 ng 1284: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1285: var points = formname["GD_BOX"+i+"_"+partid].value;
1.71 ng 1286: if (points == "") {
1.125 ng 1287: var name = formname["name"+i].value;
1.129 ng 1288: var studentID = (name != '' ? name : formname["unamedom"+i].value);
1289: var resp = confirm("You did not assign a score for "+studentID+
1290: ", part "+partid+". Continue?");
1.71 ng 1291: if (resp == false) {
1.125 ng 1292: formname["GD_BOX"+i+"_"+partid].focus();
1.71 ng 1293: return false;
1294: }
1295: }
1296: }
1297:
1298: }
1299: }
1300:
1301: }
1.121 ng 1302: if (val == "Grade Student") {
1303: formname.showgrading.value = "yes";
1304: if (formname.Status.value == "") {
1305: formname.Status.value = "Active";
1306: }
1307: formname.studentNo.value = total;
1308: }
1.120 ng 1309: formname.submit();
1310: }
1311:
1.71 ng 1312: //======= Check that a score is assigned for all the problems (page/sequence grading only) =========
1313: function checkSubmitPage(formname,total) {
1314: noscore = new Array(100);
1315: var ptr = 0;
1316: for (i=1;i<total;i++) {
1.125 ng 1317: var partid = formname["q_"+i].value;
1.127 ng 1318: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1319: var points = formname["GD_BOX"+i+"_"+partid].value;
1320: var status = formname["solved"+i+"_"+partid].value;
1.71 ng 1321: if (points == "" && status != "correct_by_student") {
1322: noscore[ptr] = i;
1323: ptr++;
1324: }
1325: }
1326: }
1327: if (ptr != 0) {
1328: var sense = ptr == 1 ? ": " : "s: ";
1329: var prolist = "";
1330: if (ptr == 1) {
1331: prolist = noscore[0];
1332: } else {
1333: var i = 0;
1334: while (i < ptr-1) {
1335: prolist += noscore[i]+", ";
1336: i++;
1337: }
1338: prolist += "and "+noscore[i];
1339: }
1340: var resp = confirm("You did not assign any score for the following problem"+sense+prolist+". Continue?");
1341: if (resp == false) {
1342: return false;
1343: }
1344: }
1.45 ng 1345:
1.71 ng 1346: formname.submit();
1347: }
1348: </script>
1349: SUBJAVASCRIPT
1350: }
1.45 ng 1351:
1.71 ng 1352: #--- javascript for essay type problem --
1353: sub sub_page_kw_js {
1354: my $request = shift;
1.80 ng 1355: my $iconpath = $request->dir_config('lonIconsURL');
1.118 ng 1356: &commonJSfunctions($request);
1.350 albertel 1357:
1.351 albertel 1358: my $inner_js_msg_central=<<INNERJS;
1.350 albertel 1359: <script text="text/javascript">
1360: function checkInput() {
1361: opener.document.SCORE.msgsub.value = opener.checkEntities(document.msgcenter.msgsub.value);
1362: var nmsg = opener.document.SCORE.savemsgN.value;
1363: var usrctr = document.msgcenter.usrctr.value;
1364: var newval = opener.document.SCORE["newmsg"+usrctr];
1365: newval.value = opener.checkEntities(document.msgcenter.newmsg.value);
1366:
1367: var msgchk = "";
1368: if (document.msgcenter.subchk.checked) {
1369: msgchk = "msgsub,";
1370: }
1371: var includemsg = 0;
1372: for (var i=1; i<=nmsg; i++) {
1373: var opnmsg = opener.document.SCORE["savemsg"+i];
1374: var frmmsg = document.msgcenter["msg"+i];
1375: opnmsg.value = opener.checkEntities(frmmsg.value);
1376: var showflg = opener.document.SCORE["shownOnce"+i];
1377: showflg.value = "1";
1378: var chkbox = document.msgcenter["msgn"+i];
1379: if (chkbox.checked) {
1380: msgchk += "savemsg"+i+",";
1381: includemsg = 1;
1382: }
1383: }
1384: if (document.msgcenter.newmsgchk.checked) {
1385: msgchk += "newmsg"+usrctr;
1386: includemsg = 1;
1387: }
1388: imgformname = opener.document.SCORE["mailicon"+usrctr];
1389: imgformname.src = "$iconpath/"+((includemsg) ? "mailto.gif" : "mailbkgrd.gif");
1390: var includemsg = opener.document.SCORE["includemsg"+usrctr];
1391: includemsg.value = msgchk;
1392:
1393: self.close()
1394:
1395: }
1396: </script>
1397: INNERJS
1398:
1.351 albertel 1399: my $inner_js_highlight_central=<<INNERJS;
1400: <script type="text/javascript">
1401: function updateChoice(flag) {
1402: opener.document.SCORE.kwclr.value = opener.radioSelection(document.hlCenter.kwdclr);
1403: opener.document.SCORE.kwsize.value = opener.radioSelection(document.hlCenter.kwdsize);
1404: opener.document.SCORE.kwstyle.value = opener.radioSelection(document.hlCenter.kwdstyle);
1405: opener.document.SCORE.refresh.value = "on";
1406: if (opener.document.SCORE.keywords.value!=""){
1407: opener.document.SCORE.submit();
1408: }
1409: self.close()
1410: }
1411: </script>
1412: INNERJS
1413:
1414: my $start_page_msg_central =
1415: &Apache::loncommon::start_page('Message Central',$inner_js_msg_central,
1416: {'js_ready' => 1,
1417: 'only_body' => 1,
1418: 'bgcolor' =>'#FFFFFF',});
1419: my $end_page_msg_central =
1420: &Apache::loncommon::end_page({'js_ready' => 1});
1421:
1422:
1423: my $start_page_highlight_central =
1424: &Apache::loncommon::start_page('Highlight Central',
1425: $inner_js_highlight_central,
1.350 albertel 1426: {'js_ready' => 1,
1427: 'only_body' => 1,
1428: 'bgcolor' =>'#FFFFFF',});
1.351 albertel 1429: my $end_page_highlight_central =
1.350 albertel 1430: &Apache::loncommon::end_page({'js_ready' => 1});
1431:
1.219 www 1432: my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
1.236 albertel 1433: $docopen=~s/^document\.//;
1.539 riegler 1434: my $alertmsg = &mt('Please select a word or group of words from document and then click this link.');
1.71 ng 1435: $request->print(<<SUBJAVASCRIPT);
1436: <script type="text/javascript" language="javascript">
1.45 ng 1437:
1.44 ng 1438: //===================== Show list of keywords ====================
1.122 ng 1439: function keywords(formname) {
1440: var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",formname.keywords.value);
1.44 ng 1441: if (nret==null) return;
1.122 ng 1442: formname.keywords.value = nret;
1.44 ng 1443:
1.122 ng 1444: if (formname.keywords.value != "") {
1.128 ng 1445: formname.refresh.value = "on";
1.122 ng 1446: formname.submit();
1.44 ng 1447: }
1448: return;
1449: }
1450:
1451: //===================== Script to view submitted by ==================
1452: function viewSubmitter(submitter) {
1453: document.SCORE.refresh.value = "on";
1454: document.SCORE.NCT.value = "1";
1455: document.SCORE.unamedom0.value = submitter;
1456: document.SCORE.submit();
1457: return;
1458: }
1459:
1460: //===================== Script to add keyword(s) ==================
1461: function getSel() {
1462: if (document.getSelection) txt = document.getSelection();
1463: else if (document.selection) txt = document.selection.createRange().text;
1464: else return;
1465: var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
1466: if (cleantxt=="") {
1.539 riegler 1467: alert("$alertmsg");
1.44 ng 1468: return;
1469: }
1470: var nret = prompt("Add selection to keyword list? Edit if desired.",cleantxt);
1471: if (nret==null) return;
1.127 ng 1472: document.SCORE.keywords.value = document.SCORE.keywords.value+" "+nret;
1.44 ng 1473: if (document.SCORE.keywords.value != "") {
1.127 ng 1474: document.SCORE.refresh.value = "on";
1.44 ng 1475: document.SCORE.submit();
1476: }
1477: return;
1478: }
1479:
1480: //====================== Script for composing message ==============
1.80 ng 1481: // preload images
1482: img1 = new Image();
1483: img1.src = "$iconpath/mailbkgrd.gif";
1484: img2 = new Image();
1485: img2.src = "$iconpath/mailto.gif";
1486:
1.44 ng 1487: function msgCenter(msgform,usrctr,fullname) {
1488: var Nmsg = msgform.savemsgN.value;
1489: savedMsgHeader(Nmsg,usrctr,fullname);
1490: var subject = msgform.msgsub.value;
1.127 ng 1491: var msgchk = document.SCORE["includemsg"+usrctr].value;
1.44 ng 1492: re = /msgsub/;
1493: var shwsel = "";
1494: if (re.test(msgchk)) { shwsel = "checked" }
1.123 ng 1495: subject = (document.SCORE.shownSub.value == 0 ? checkEntities(subject) : subject);
1496: displaySubject(checkEntities(subject),shwsel);
1.44 ng 1497: for (var i=1; i<=Nmsg; i++) {
1.123 ng 1498: var testmsg = "savemsg"+i+",";
1499: re = new RegExp(testmsg,"g");
1.44 ng 1500: shwsel = "";
1501: if (re.test(msgchk)) { shwsel = "checked" }
1.125 ng 1502: var message = document.SCORE["savemsg"+i].value;
1.126 ng 1503: message = (document.SCORE["shownOnce"+i].value == 0 ? checkEntities(message) : message);
1.123 ng 1504: displaySavedMsg(i,message,shwsel); //I do not get it. w/o checkEntities on saved messages,
1505: //any < is already converted to <, etc. However, only once!!
1.44 ng 1506: }
1.125 ng 1507: newmsg = document.SCORE["newmsg"+usrctr].value;
1.44 ng 1508: shwsel = "";
1509: re = /newmsg/;
1510: if (re.test(msgchk)) { shwsel = "checked" }
1511: newMsg(newmsg,shwsel);
1512: msgTail();
1513: return;
1514: }
1515:
1.123 ng 1516: function checkEntities(strx) {
1517: if (strx.length == 0) return strx;
1518: var orgStr = ["&", "<", ">", '"'];
1519: var newStr = ["&", "<", ">", """];
1520: var counter = 0;
1521: while (counter < 4) {
1522: strx = strReplace(strx,orgStr[counter],newStr[counter]);
1523: counter++;
1524: }
1525: return strx;
1526: }
1527:
1528: function strReplace(strx, orgStr, newStr) {
1529: return strx.split(orgStr).join(newStr);
1530: }
1531:
1.44 ng 1532: function savedMsgHeader(Nmsg,usrctr,fullname) {
1.76 ng 1533: var height = 70*Nmsg+250;
1.44 ng 1534: var scrollbar = "no";
1535: if (height > 600) {
1536: height = 600;
1537: scrollbar = "yes";
1538: }
1.118 ng 1539: var xpos = (screen.width-600)/2;
1540: xpos = (xpos < 0) ? '0' : xpos;
1541: var ypos = (screen.height-height)/2-30;
1542: ypos = (ypos < 0) ? '0' : ypos;
1543:
1.206 albertel 1544: pWin = window.open('', 'MessageCenter', 'resizable=yes,toolbar=no,location=no,scrollbars='+scrollbar+',screenx='+xpos+',screeny='+ypos+',width=600,height='+height);
1.76 ng 1545: pWin.focus();
1546: pDoc = pWin.document;
1.219 www 1547: pDoc.$docopen;
1.351 albertel 1548: pDoc.write('$start_page_msg_central');
1.76 ng 1549:
1550: pDoc.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
1551: pDoc.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
1.465 albertel 1552: pDoc.write("<h3><span class=\\"LC_info\\"> Compose Message for \"+fullname+\"<\\/span><\\/h3><br /><br />");
1.76 ng 1553:
1.564 bisitz 1554: pDoc.write('<table border="0" width="100%"><tr><td bgcolor="#777777">');
1555: pDoc.write('<table border="0" width="100%"><tr bgcolor="#DDFFFF">');
1.465 albertel 1556: pDoc.write("<td><b>Type<\\/b><\\/td><td><b>Include<\\/b><\\/td><td><b>Message<\\/td><\\/tr>");
1.44 ng 1557: }
1558: function displaySubject(msg,shwsel) {
1.76 ng 1559: pDoc = pWin.document;
1560: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.465 albertel 1561: pDoc.write("<td>Subject<\\/td>");
1562: pDoc.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1563: pDoc.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+"\\"size=\\"60\\" maxlength=\\"80\\"><\\/td><\\/tr>");
1.44 ng 1564: }
1565:
1.72 ng 1566: function displaySavedMsg(ctr,msg,shwsel) {
1.76 ng 1567: pDoc = pWin.document;
1568: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.465 albertel 1569: pDoc.write("<td align=\\"center\\">"+ctr+"<\\/td>");
1570: pDoc.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1571: pDoc.write("<td><textarea name=\\"msg"+ctr+"\\" cols=\\"60\\" rows=\\"3\\">"+msg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 1572: }
1573:
1574: function newMsg(newmsg,shwsel) {
1.76 ng 1575: pDoc = pWin.document;
1576: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.465 albertel 1577: pDoc.write("<td align=\\"center\\">New<\\/td>");
1578: pDoc.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1579: pDoc.write("<td><textarea name=\\"newmsg\\" cols=\\"60\\" rows=\\"3\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" >"+newmsg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 1580: }
1581:
1582: function msgTail() {
1.76 ng 1583: pDoc = pWin.document;
1.465 albertel 1584: pDoc.write("<\\/table>");
1585: pDoc.write("<\\/td><\\/tr><\\/table> ");
1.76 ng 1586: pDoc.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:checkInput()\\"> ");
1.326 albertel 1587: pDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br /><br />");
1.465 albertel 1588: pDoc.write("<\\/form>");
1.351 albertel 1589: pDoc.write('$end_page_msg_central');
1.128 ng 1590: pDoc.close();
1.44 ng 1591: }
1592:
1593: //====================== Script for keyword highlight options ==============
1594: function kwhighlight() {
1595: var kwclr = document.SCORE.kwclr.value;
1596: var kwsize = document.SCORE.kwsize.value;
1597: var kwstyle = document.SCORE.kwstyle.value;
1598: var redsel = "";
1599: var grnsel = "";
1600: var blusel = "";
1601: if (kwclr=="red") {var redsel="checked"};
1602: if (kwclr=="green") {var grnsel="checked"};
1603: if (kwclr=="blue") {var blusel="checked"};
1604: var sznsel = "";
1605: var sz1sel = "";
1606: var sz2sel = "";
1607: if (kwsize=="0") {var sznsel="checked"};
1608: if (kwsize=="+1") {var sz1sel="checked"};
1609: if (kwsize=="+2") {var sz2sel="checked"};
1610: var synsel = "";
1611: var syisel = "";
1612: var sybsel = "";
1613: if (kwstyle=="") {var synsel="checked"};
1614: if (kwstyle=="<i>") {var syisel="checked"};
1615: if (kwstyle=="<b>") {var sybsel="checked"};
1616: highlightCentral();
1617: highlightbody('red','red',redsel,'0','normal',sznsel,'','normal',synsel);
1618: highlightbody('green','green',grnsel,'+1','+1',sz1sel,'<i>','italic',syisel);
1619: highlightbody('blue','blue',blusel,'+2','+2',sz2sel,'<b>','bold',sybsel);
1620: highlightend();
1621: return;
1622: }
1623:
1624: function highlightCentral() {
1.76 ng 1625: // if (window.hwdWin) window.hwdWin.close();
1.118 ng 1626: var xpos = (screen.width-400)/2;
1627: xpos = (xpos < 0) ? '0' : xpos;
1628: var ypos = (screen.height-330)/2-30;
1629: ypos = (ypos < 0) ? '0' : ypos;
1630:
1.206 albertel 1631: hwdWin = window.open('', 'KeywordHighlightCentral', 'resizeable=yes,toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx='+xpos+',screeny='+ypos);
1.76 ng 1632: hwdWin.focus();
1633: var hDoc = hwdWin.document;
1.219 www 1634: hDoc.$docopen;
1.351 albertel 1635: hDoc.write('$start_page_highlight_central');
1.76 ng 1636: hDoc.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
1.465 albertel 1637: hDoc.write("<h3><span class=\\"LC_info\\"> Keyword Highlight Options<\\/span><\\/h3><br /><br />");
1.76 ng 1638:
1.564 bisitz 1639: hDoc.write('<table border="0" width="100%"><tr><td bgcolor="#777777">');
1640: hDoc.write('<table border="0" width="100%"><tr bgcolor="#DDFFFF">');
1.465 albertel 1641: hDoc.write("<td><b>Text Color<\\/b><\\/td><td><b>Font Size<\\/b><\\/td><td><b>Font Style<\\/td><\\/tr>");
1.44 ng 1642: }
1643:
1644: function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) {
1.76 ng 1645: var hDoc = hwdWin.document;
1646: hDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1647: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1648: hDoc.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+"> "+clrtxt+"<\\/td>");
1.76 ng 1649: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1650: hDoc.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+"> "+sztxt+"<\\/td>");
1.76 ng 1651: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1652: hDoc.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+"> "+sytxt+"<\\/td>");
1653: hDoc.write("<\\/tr>");
1.44 ng 1654: }
1655:
1656: function highlightend() {
1.76 ng 1657: var hDoc = hwdWin.document;
1.465 albertel 1658: hDoc.write("<\\/table>");
1659: hDoc.write("<\\/td><\\/tr><\\/table> ");
1.76 ng 1660: hDoc.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:updateChoice(1)\\"> ");
1.326 albertel 1661: hDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br /><br />");
1.465 albertel 1662: hDoc.write("<\\/form>");
1.351 albertel 1663: hDoc.write('$end_page_highlight_central');
1.128 ng 1664: hDoc.close();
1.44 ng 1665: }
1666:
1667: </script>
1668: SUBJAVASCRIPT
1669: }
1670:
1.349 albertel 1671: sub get_increment {
1.348 bowersj2 1672: my $increment = $env{'form.increment'};
1673: if ($increment != 1 && $increment != .5 && $increment != .25 &&
1674: $increment != .1) {
1675: $increment = 1;
1676: }
1677: return $increment;
1678: }
1679:
1.71 ng 1680: #--- displays the grading box, used in essay type problem and grading by page/sequence
1681: sub gradeBox {
1.322 albertel 1682: my ($request,$symb,$uname,$udom,$counter,$partid,$record) = @_;
1.381 albertel 1683: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 1684: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 1685: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
1.466 albertel 1686: my $wgtmsg = ($wgt > 0) ? &mt('(problem weight)')
1687: : '<span class="LC_info">'.&mt('problem weight assigned by computer').'</span>';
1.71 ng 1688: $wgt = ($wgt > 0 ? $wgt : '1');
1689: my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
1.320 albertel 1690: '' : &compute_points($$record{'resource.'.$partid.'.awarded'},$wgt));
1.71 ng 1691: my $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />'."\n";
1.466 albertel 1692: my $display_part= &get_display_part($partid,$symb);
1.270 albertel 1693: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
1694: [$partid]);
1695: my $aggtries = $$record{'resource.'.$partid.'.tries'};
1.269 raeburn 1696: if ($last_resets{$partid}) {
1697: $aggtries = &get_num_tries($record,$last_resets{$partid},$partid);
1698: }
1.485 albertel 1699: $result.='<table border="0"><tr>';
1.71 ng 1700: my $ctr = 0;
1.348 bowersj2 1701: my $thisweight = 0;
1.349 albertel 1702: my $increment = &get_increment();
1.485 albertel 1703:
1704: my $radio.='<table border="0"><tr>'."\n"; # display radio buttons in a nice table 10 across
1.348 bowersj2 1705: while ($thisweight<=$wgt) {
1.532 bisitz 1706: $radio.= '<td><span class="LC_nobreak"><label><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
1.71 ng 1707: 'onclick="javascript:writeBox(this.form,\''.$counter.'_'.$partid.'\','.
1.348 bowersj2 1708: $thisweight.')" value="'.$thisweight.'" '.
1.401 albertel 1709: ($score eq $thisweight ? 'checked="checked"':'').' /> '.$thisweight."</label></span></td>\n";
1.485 albertel 1710: $radio.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1.348 bowersj2 1711: $thisweight += $increment;
1.71 ng 1712: $ctr++;
1713: }
1.485 albertel 1714: $radio.='</tr></table>';
1715:
1716: my $line.='<input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
1.71 ng 1717: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
1718: 'onChange="javascript:updateRadio(this.form,\''.$counter.'_'.$partid.'\','.
1719: $wgt.')" /></td>'."\n";
1.485 albertel 1720: $line.='<td>/'.$wgt.' '.$wgtmsg.
1.71 ng 1721: ($$record{'resource.'.$partid.'.solved'} eq 'correct_by_student' ? ' '.$checkIcon : '').
1.540 riegler 1722: ' </td><td><b>'.&mt('Grade Status').':</b>'."\n";
1.485 albertel 1723: $line.='<select name="GD_SEL'.$counter.'_'.$partid.'" '.
1.71 ng 1724: 'onChange="javascript:clearRadBox(this.form,\''.$counter.'_'.$partid.'\')" >'."\n";
1725: if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
1.485 albertel 1726: $line.='<option></option>'.
1727: '<option value="excused" selected="selected">'.&mt('excused').'</option>';
1.71 ng 1728: } else {
1.485 albertel 1729: $line.='<option selected="selected"></option>'.
1730: '<option value="excused" >'.&mt('excused').'</option>';
1.71 ng 1731: }
1.485 albertel 1732: $line.='<option value="reset status">'.&mt('reset status').'</option></select>'."\n";
1733:
1734:
1.540 riegler 1735: #&mt('<td><b>Part:</b></td><td>[_1]</td><td><b>Points:</b></td><td>[_2]</td><td>or</td><td>[_3]</td>',$display_part,$radio,$line);
1.485 albertel 1736: $result .=
1.574.2.4 raeburn 1737: '<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 1738: $result.='</tr></table>'."\n";
1.71 ng 1739: $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="" />'."\n".
1740: '<input type="hidden" name="oldpts'.$counter.'_'.$partid.'" value="'.$score.'" />'."\n".
1741: '<input type="hidden" name="solved'.$counter.'_'.$partid.'" value="'.
1.269 raeburn 1742: $$record{'resource.'.$partid.'.solved'}.'" />'."\n".
1743: '<input type="hidden" name="totaltries'.$counter.'_'.$partid.'" value="'.
1744: $$record{'resource.'.$partid.'.tries'}.'" />'."\n".
1745: '<input type="hidden" name="aggtries'.$counter.'_'.$partid.'" value="'.
1746: $aggtries.'" />'."\n";
1.323 banghart 1747: $result.=&handback_box($symb,$uname,$udom,$counter,$partid,$record);
1.318 banghart 1748: return $result;
1749: }
1.322 albertel 1750:
1751: sub handback_box {
1.323 banghart 1752: my ($symb,$uname,$udom,$counter,$partid,$record) = @_;
1.324 albertel 1753: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.323 banghart 1754: my (@respids);
1.375 albertel 1755: my @part_response_id = &flatten_responseType($responseType);
1756: foreach my $part_response_id (@part_response_id) {
1757: my ($part,$resp) = @{ $part_response_id };
1.323 banghart 1758: if ($part eq $partid) {
1.375 albertel 1759: push(@respids,$resp);
1.323 banghart 1760: }
1761: }
1.318 banghart 1762: my $result;
1.323 banghart 1763: foreach my $respid (@respids) {
1.322 albertel 1764: my $prefix = $counter.'_'.$partid.'_'.$respid.'_';
1765: my $files=&get_submitted_files($udom,$uname,$partid,$respid,$record);
1766: next if (!@$files);
1767: my $file_counter = 1;
1.313 banghart 1768: foreach my $file (@$files) {
1.368 banghart 1769: if ($file =~ /\/portfolio\//) {
1770: my ($file_path, $file_disp) = ($file =~ m|(.+/)(.+)$|);
1771: my ($name,$version,$ext) = &file_name_version_ext($file_disp);
1772: $file_disp = "$name.$ext";
1773: $file = $file_path.$file_disp;
1774: $result.=&mt('Return commented version of [_1] to student.',
1775: '<span class="LC_filename">'.$file_disp.'</span>');
1776: $result.='<input type="file" name="'.$prefix.'returndoc'.$file_counter.'" />'."\n";
1777: $result.='<input type="hidden" name="'.$prefix.'origdoc'.$file_counter.'" value="'.$file.'" /><br />';
1.485 albertel 1778: $result.='('.&mt('File will be uploaded when you click on Save & Next below.').')<br />';
1.368 banghart 1779: $file_counter++;
1780: }
1.322 albertel 1781: }
1.313 banghart 1782: }
1.318 banghart 1783: return $result;
1.71 ng 1784: }
1.44 ng 1785:
1.58 albertel 1786: sub show_problem {
1.382 albertel 1787: my ($request,$symb,$uname,$udom,$removeform,$viewon,$mode,$form) = @_;
1.144 albertel 1788: my $rendered;
1.382 albertel 1789: my %form = ((ref($form) eq 'HASH')? %{$form} : ());
1.329 albertel 1790: &Apache::lonxml::remember_problem_counter();
1.144 albertel 1791: if ($mode eq 'both' or $mode eq 'text') {
1792: $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
1.382 albertel 1793: $env{'request.course.id'},
1794: undef,\%form);
1.144 albertel 1795: }
1.58 albertel 1796: if ($removeform) {
1797: $rendered=~s|<form(.*?)>||g;
1798: $rendered=~s|</form>||g;
1.374 albertel 1799: $rendered=~s|(<input[^>]*name\s*=\s*"?)(\w+)("?)|$1would_have_been_$2$3|g;
1.58 albertel 1800: }
1.144 albertel 1801: my $companswer;
1802: if ($mode eq 'both' or $mode eq 'answer') {
1.329 albertel 1803: &Apache::lonxml::restore_problem_counter();
1.382 albertel 1804: $companswer=
1805: &Apache::loncommon::get_student_answers($symb,$uname,$udom,
1806: $env{'request.course.id'},
1807: %form);
1.144 albertel 1808: }
1.58 albertel 1809: if ($removeform) {
1810: $companswer=~s|<form(.*?)>||g;
1811: $companswer=~s|</form>||g;
1.144 albertel 1812: $companswer=~s|name="submit"|name="would_have_been_submit"|g;
1.58 albertel 1813: }
1.468 albertel 1814: $rendered=
1815: '<div class="LC_grade_show_problem_header">'.
1816: &mt('View of the problem').
1817: '</div><div class="LC_grade_show_problem_problem">'.
1818: $rendered.
1819: '</div>';
1820: $companswer=
1821: '<div class="LC_grade_show_problem_header">'.
1822: &mt('Correct answer').
1823: '</div><div class="LC_grade_show_problem_problem">'.
1824: $companswer.
1825: '</div>';
1826: my $result;
1.144 albertel 1827: if ($mode eq 'both') {
1.468 albertel 1828: $result=$rendered.$companswer;
1.144 albertel 1829: } elsif ($mode eq 'text') {
1.468 albertel 1830: $result=$rendered;
1.144 albertel 1831: } elsif ($mode eq 'answer') {
1.468 albertel 1832: $result=$companswer;
1.144 albertel 1833: }
1.468 albertel 1834: $result='<div class="LC_grade_show_problem">'.$result.'</div>';
1.71 ng 1835: return $result;
1.58 albertel 1836: }
1.397 albertel 1837:
1.396 banghart 1838: sub files_exist {
1839: my ($r, $symb) = @_;
1840: my @students = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.397 albertel 1841:
1.396 banghart 1842: foreach my $student (@students) {
1843: my ($uname,$udom,$fullname) = split(/:/,$student);
1.397 albertel 1844: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1845: $udom,$uname);
1.396 banghart 1846: my ($string,$timestamp)= &get_last_submission(\%record);
1.397 albertel 1847: foreach my $submission (@$string) {
1848: my ($partid,$respid) =
1849: ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
1850: my $files=&get_submitted_files($udom,$uname,$partid,$respid,
1851: \%record);
1852: return 1 if (@$files);
1.396 banghart 1853: }
1854: }
1.397 albertel 1855: return 0;
1.396 banghart 1856: }
1.397 albertel 1857:
1.394 banghart 1858: sub download_all_link {
1859: my ($r,$symb) = @_;
1.395 albertel 1860: my $all_students =
1861: join("\n", &Apache::loncommon::get_env_multiple('form.stuinfo'));
1862:
1863: my $parts =
1864: join("\n",&Apache::loncommon::get_env_multiple('form.vPart'));
1865:
1.394 banghart 1866: my $identifier = &Apache::loncommon::get_cgi_id();
1.514 raeburn 1867: &Apache::lonnet::appenv({'cgi.'.$identifier.'.students' => $all_students,
1868: 'cgi.'.$identifier.'.symb' => $symb,
1869: 'cgi.'.$identifier.'.parts' => $parts,});
1.395 albertel 1870: $r->print('<a href="/cgi-bin/multidownload.pl?'.$identifier.'">'.
1871: &mt('Download All Submitted Documents').'</a>');
1.394 banghart 1872: return
1873: }
1.395 albertel 1874:
1.432 banghart 1875: sub build_section_inputs {
1876: my $section_inputs;
1877: if ($env{'form.section'} eq '') {
1878: $section_inputs .= '<input type="hidden" name="section" value="all" />'."\n";
1879: } else {
1880: my @sections = &Apache::loncommon::get_env_multiple('form.section');
1.434 albertel 1881: foreach my $section (@sections) {
1.432 banghart 1882: $section_inputs .= '<input type="hidden" name="section" value="'.$section.'" />'."\n";
1883: }
1884: }
1885: return $section_inputs;
1886: }
1887:
1.44 ng 1888: # --------------------------- show submissions of a student, option to grade
1889: sub submission {
1890: my ($request,$counter,$total) = @_;
1.257 albertel 1891: my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
1892: $udom = ($udom eq '' ? $env{'user.domain'} : $udom); #has form.userdom changed for a student?
1893: my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
1894: $env{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $env{'form.fullname'} eq '';
1.324 albertel 1895: my $symb = &get_symb($request);
1896: if ($symb eq '') { $request->print("Unable to handle ambiguous references:."); return ''; }
1.104 albertel 1897:
1898: if (!&canview($usec)) {
1.398 albertel 1899: $request->print('<span class="LC_warning">Unable to view requested student.('.
1900: $uname.':'.$udom.' in section '.$usec.' in course id '.
1901: $env{'request.course.id'}.')</span>');
1.324 albertel 1902: $request->print(&show_grading_menu_form($symb));
1.104 albertel 1903: return;
1904: }
1905:
1.257 albertel 1906: if (!$env{'form.lastSub'}) { $env{'form.lastSub'} = 'datesub'; }
1907: if (!$env{'form.vProb'}) { $env{'form.vProb'} = 'yes'; }
1908: if (!$env{'form.vAns'}) { $env{'form.vAns'} = 'yes'; }
1909: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.381 albertel 1910: my $checkIcon = '<img alt="'.&mt('Check Mark').
1911: '" src="'.$request->dir_config('lonIconsURL').
1.122 ng 1912: '/check.gif" height="16" border="0" />';
1.41 ng 1913:
1.426 albertel 1914: my %old_essays;
1.41 ng 1915: # header info
1916: if ($counter == 0) {
1917: &sub_page_js($request);
1.257 albertel 1918: &sub_page_kw_js($request) if ($env{'form.handgrade'} eq 'yes');
1919: $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
1920: &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
1.397 albertel 1921: if ($env{'form.handgrade'} eq 'yes' && &files_exist($request, $symb)) {
1.396 banghart 1922: &download_all_link($request, $symb);
1923: }
1.485 albertel 1924: $request->print('<h3> <span class="LC_info">'.&mt('Submission Record').'</span></h3>'."\n".
1925: '<h4> '.&mt('<b>Resource: </b> [_1]',$env{'form.probTitle'}).'</h4>'."\n");
1.118 ng 1926:
1.44 ng 1927: # option to display problem, only once else it cause problems
1928: # with the form later since the problem has a form.
1.257 albertel 1929: if ($env{'form.vProb'} eq 'yes' or $env{'form.vAns'} eq 'yes') {
1.144 albertel 1930: my $mode;
1.257 albertel 1931: if ($env{'form.vProb'} eq 'yes' && $env{'form.vAns'} eq 'yes') {
1.144 albertel 1932: $mode='both';
1.257 albertel 1933: } elsif ($env{'form.vProb'} eq 'yes') {
1.144 albertel 1934: $mode='text';
1.257 albertel 1935: } elsif ($env{'form.vAns'} eq 'yes') {
1.144 albertel 1936: $mode='answer';
1937: }
1.329 albertel 1938: &Apache::lonxml::clear_problem_counter();
1.144 albertel 1939: $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
1.41 ng 1940: }
1.441 www 1941:
1.44 ng 1942: # kwclr is the only variable that is guaranteed to be non blank
1943: # if this subroutine has been called once.
1.41 ng 1944: my %keyhash = ();
1.257 albertel 1945: if ($env{'form.kwclr'} eq '' && $env{'form.handgrade'} eq 'yes') {
1.41 ng 1946: %keyhash = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 1947: $env{'course.'.$env{'request.course.id'}.'.domain'},
1948: $env{'course.'.$env{'request.course.id'}.'.num'});
1.41 ng 1949:
1.257 albertel 1950: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1951: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
1952: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
1953: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
1954: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
1955: $env{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
1956: $keyhash{$symb.'_subject'} : $env{'form.probTitle'};
1957: $env{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1.41 ng 1958: }
1.257 albertel 1959: my $overRideScore = $env{'form.overRideScore'} eq '' ? 'no' : $env{'form.overRideScore'};
1.442 banghart 1960: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.303 banghart 1961: $request->print('<form action="/adm/grades" method="post" name="SCORE" enctype="multipart/form-data">'."\n".
1.41 ng 1962: '<input type="hidden" name="command" value="handgrade" />'."\n".
1.257 albertel 1963: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.442 banghart 1964: '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.120 ng 1965: '<input type="hidden" name="overRideScore" value="'.$overRideScore.'" />'."\n".
1.257 albertel 1966: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.41 ng 1967: '<input type="hidden" name="refresh" value="off" />'."\n".
1.120 ng 1968: '<input type="hidden" name="studentNo" value="" />'."\n".
1969: '<input type="hidden" name="gradeOpt" value="" />'."\n".
1.418 albertel 1970: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 1971: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" />'."\n".
1972: '<input type="hidden" name="vProb" value="'.$env{'form.vProb'}.'" />'."\n".
1973: '<input type="hidden" name="vAns" value="'.$env{'form.vAns'}.'" />'."\n".
1974: '<input type="hidden" name="lastSub" value="'.$env{'form.lastSub'}.'" />'."\n".
1.432 banghart 1975: &build_section_inputs().
1.326 albertel 1976: '<input type="hidden" name="submitonly" value="'.$env{'form.submitonly'}.'" />'."\n".
1977: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" />'."\n".
1.41 ng 1978: '<input type="hidden" name="NCT"'.
1.257 albertel 1979: ' value="'.($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : $total+1).'" />'."\n");
1980: if ($env{'form.handgrade'} eq 'yes') {
1981: $request->print('<input type="hidden" name="keywords" value="'.$env{'form.keywords'}.'" />'."\n".
1982: '<input type="hidden" name="kwclr" value="'.$env{'form.kwclr'}.'" />'."\n".
1983: '<input type="hidden" name="kwsize" value="'.$env{'form.kwsize'}.'" />'."\n".
1984: '<input type="hidden" name="kwstyle" value="'.$env{'form.kwstyle'}.'" />'."\n".
1985: '<input type="hidden" name="msgsub" value="'.$env{'form.msgsub'}.'" />'."\n".
1.123 ng 1986: '<input type="hidden" name="shownSub" value="0" />'."\n".
1.257 albertel 1987: '<input type="hidden" name="savemsgN" value="'.$env{'form.savemsgN'}.'" />'."\n");
1.154 albertel 1988: foreach my $partid (&Apache::loncommon::get_env_multiple('form.vPart')) {
1989: $request->print('<input type="hidden" name="vPart" value="'.$partid.'" />'."\n");
1990: }
1.123 ng 1991: }
1.41 ng 1992:
1993: my ($cts,$prnmsg) = (1,'');
1.257 albertel 1994: while ($cts <= $env{'form.savemsgN'}) {
1.41 ng 1995: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
1.123 ng 1996: (!exists($keyhash{$symb.'_savemsg'.$cts}) ?
1.257 albertel 1997: &Apache::lonfeedback::clear_out_html($env{'form.savemsg'.$cts}) :
1.80 ng 1998: &Apache::lonfeedback::clear_out_html($keyhash{$symb.'_savemsg'.$cts})).
1.123 ng 1999: '" />'."\n".
2000: '<input type="hidden" name="shownOnce'.$cts.'" value="0" />'."\n";
1.41 ng 2001: $cts++;
2002: }
2003: $request->print($prnmsg);
1.32 ng 2004:
1.257 albertel 2005: if ($env{'form.handgrade'} eq 'yes' && $env{'form.showgrading'} eq 'yes') {
1.88 www 2006: #
2007: # Print out the keyword options line
2008: #
1.41 ng 2009: $request->print(<<KEYWORDS);
1.38 ng 2010: <b>Keyword Options:</b>
1.417 albertel 2011: <a href="javascript:keywords(document.SCORE);" target="_self">List</a>
1.38 ng 2012: <a href="#" onMouseDown="javascript:getSel(); return false"
2013: CLASS="page">Paste Selection to List</a>
1.417 albertel 2014: <a href="javascript:kwhighlight();" target="_self">Highlight Attribute</a><br /><br />
1.38 ng 2015: KEYWORDS
1.88 www 2016: #
2017: # Load the other essays for similarity check
2018: #
1.324 albertel 2019: my (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb);
1.384 albertel 2020: my ($adom,$aname,$apath)=($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
1.359 www 2021: $apath=&escape($apath);
1.88 www 2022: $apath=~s/\W/\_/gs;
1.426 albertel 2023: %old_essays=&Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
1.41 ng 2024: }
2025: }
1.44 ng 2026:
1.441 www 2027: # This is where output for one specific student would start
1.468 albertel 2028: my $add_class = ($counter%2) ? 'LC_grade_show_user_odd_row' : '';
1.441 www 2029: $request->print("\n\n".
1.468 albertel 2030: '<div class="LC_grade_show_user '.$add_class.'">'.
2031: '<div class="LC_grade_user_name">'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).'</div>'.
2032: '<div class="LC_grade_show_user_body">'."\n");
1.441 www 2033:
1.257 albertel 2034: if ($env{'form.vProb'} eq 'all' or $env{'form.vAns'} eq 'all') {
1.144 albertel 2035: my $mode;
1.257 albertel 2036: if ($env{'form.vProb'} eq 'all' && $env{'form.vAns'} eq 'all') {
1.144 albertel 2037: $mode='both';
1.257 albertel 2038: } elsif ($env{'form.vProb'} eq 'all' ) {
1.144 albertel 2039: $mode='text';
1.257 albertel 2040: } elsif ($env{'form.vAns'} eq 'all') {
1.144 albertel 2041: $mode='answer';
2042: }
1.329 albertel 2043: &Apache::lonxml::clear_problem_counter();
1.475 albertel 2044: $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode,{'request.prefix' => 'ctr'.$counter}));
1.58 albertel 2045: }
1.144 albertel 2046:
1.257 albertel 2047: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 2048: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.41 ng 2049:
1.44 ng 2050: # Display student info
1.41 ng 2051: $request->print(($counter == 0 ? '' : '<br />'));
1.468 albertel 2052: my $result='<div class="LC_grade_submissions">';
2053:
2054: $result.='<div class="LC_grade_submissions_header">';
2055: $result.= &mt('Submissions');
1.45 ng 2056: $result.='<input type="hidden" name="name'.$counter.
1.257 albertel 2057: '" value="'.$env{'form.fullname'}.'" />'."\n";
1.469 albertel 2058: if ($env{'form.handgrade'} eq 'no') {
2059: $result.='<span class="LC_grade_check_note">'.
2060: &mt('Part(s) graded correct by the computer is marked with a [_1] symbol.',$checkIcon)."</span>\n";
2061:
2062: }
2063:
2064:
1.41 ng 2065:
1.118 ng 2066: # If any part of the problem is an essay-response (handgraded), then check for collaborators
1.464 albertel 2067: my $fullname;
2068: my $col_fullnames = [];
1.257 albertel 2069: if ($env{'form.handgrade'} eq 'yes') {
1.464 albertel 2070: (my $sub_result,$fullname,$col_fullnames)=
2071: &check_collaborators($symb,$uname,$udom,\%record,$handgrade,
2072: $counter);
2073: $result.=$sub_result;
1.41 ng 2074: }
1.44 ng 2075: $request->print($result."\n");
1.468 albertel 2076: $request->print('</div>'."\n");
1.44 ng 2077: # print student answer/submission
2078: # Options are (1) Handgaded submission only
2079: # (2) Last submission, includes submission that is not handgraded
2080: # (for multi-response type part)
2081: # (3) Last submission plus the parts info
2082: # (4) The whole record for this student
1.257 albertel 2083: if ($env{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
1.151 albertel 2084: my ($string,$timestamp)= &get_last_submission(\%record);
1.468 albertel 2085:
2086: my $lastsubonly;
2087:
1.151 albertel 2088: if ($$timestamp eq '') {
1.468 albertel 2089: $lastsubonly.='<div class="LC_grade_submissions_body">'.$$string[0].'</div>';
1.151 albertel 2090: } else {
1.468 albertel 2091: $lastsubonly = '<div class="LC_grade_submissions_body"> <b>Date Submitted:</b> '.$$timestamp."\n";
2092:
1.151 albertel 2093: my %seenparts;
1.375 albertel 2094: my @part_response_id = &flatten_responseType($responseType);
2095: foreach my $part (@part_response_id) {
1.393 albertel 2096: next if ($env{'form.lastSub'} eq 'hdgrade'
2097: && $$handgrade{$$part[0].'_'.$$part[1]} ne 'yes');
2098:
1.375 albertel 2099: my ($partid,$respid) = @{ $part };
1.324 albertel 2100: my $display_part=&get_display_part($partid,$symb);
1.257 albertel 2101: if ($env{"form.$uname:$udom:$partid:submitted_by"}) {
1.151 albertel 2102: if (exists($seenparts{$partid})) { next; }
2103: $seenparts{$partid}=1;
1.207 albertel 2104: my $submitby='<b>Part:</b> '.$display_part.
2105: ' <b>Collaborative submission by:</b> '.
1.151 albertel 2106: '<a href="javascript:viewSubmitter(\''.
1.257 albertel 2107: $env{"form.$uname:$udom:$partid:submitted_by"}.
1.417 albertel 2108: '\');" target="_self">'.
1.257 albertel 2109: $$fullname{$env{"form.$uname:$udom:$partid:submitted_by"}}.'</a><br />';
1.151 albertel 2110: $request->print($submitby);
2111: next;
2112: }
2113: my $responsetype = $responseType->{$partid}->{$respid};
2114: if (!exists($record{"resource.$partid.$respid.submission"})) {
1.468 albertel 2115: $lastsubonly.="\n".'<div class="LC_grade_submission_part"><b>Part:</b> '.
1.398 albertel 2116: $display_part.' <span class="LC_internal_info">( ID '.$respid.
2117: ' )</span> '.
1.539 riegler 2118: '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br /><br /></div>';
1.151 albertel 2119: next;
2120: }
1.468 albertel 2121: foreach my $submission (@$string) {
2122: my ($partid,$respid) = ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
1.375 albertel 2123: if (join('_',@{$part}) ne ($partid.'_'.$respid)) { next; }
1.468 albertel 2124: my ($ressub,$subval) = split(/:/,$submission,2);
1.151 albertel 2125: # Similarity check
2126: my $similar='';
1.257 albertel 2127: if($env{'form.checkPlag'}){
1.151 albertel 2128: my ($oname,$odom,$ocrsid,$oessay,$osim)=
1.426 albertel 2129: &most_similar($uname,$udom,$subval,\%old_essays);
1.151 albertel 2130: if ($osim) {
2131: $osim=int($osim*100.0);
1.426 albertel 2132: my %old_course_desc =
2133: &Apache::lonnet::coursedescription($ocrsid,
2134: {'one_time' => 1});
2135:
2136: $similar="<hr /><h3><span class=\"LC_warning\">".
1.574 bisitz 2137: &mt('Essay is [_1]% similar to an essay by [_2] in course [_3] (course id [_4]:[_5])',
1.426 albertel 2138: $osim,
1.574 bisitz 2139: &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')',
1.426 albertel 2140: $old_course_desc{'description'},
1.427 albertel 2141: $old_course_desc{'num'},
1.426 albertel 2142: $old_course_desc{'domain'}).
1.398 albertel 2143: '</span></h3><blockquote><i>'.
1.151 albertel 2144: &keywords_highlight($oessay).
2145: '</i></blockquote><hr />';
2146: }
1.150 albertel 2147: }
1.151 albertel 2148: my $order=&get_order($partid,$respid,$symb,$uname,$udom);
1.257 albertel 2149: if ($env{'form.lastSub'} eq 'lastonly' ||
2150: ($env{'form.lastSub'} eq 'hdgrade' &&
1.377 albertel 2151: $$handgrade{$$part[0].'_'.$$part[1]} eq 'yes')) {
1.324 albertel 2152: my $display_part=&get_display_part($partid,$symb);
1.468 albertel 2153: $lastsubonly.='<div class="LC_grade_submission_part"><b>Part:</b> '.
1.403 albertel 2154: $display_part.' <span class="LC_internal_info">( ID '.$respid.
1.398 albertel 2155: ' )</span> ';
1.313 banghart 2156: my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record);
2157: if (@$files) {
1.544 raeburn 2158: $lastsubonly.='<br /><span class="LC_warning">'.&mt('Like all files provided by users, this file may contain viruses').'</span><br />';
1.303 banghart 2159: my $file_counter = 0;
1.313 banghart 2160: foreach my $file (@$files) {
1.468 albertel 2161: $file_counter++;
1.232 albertel 2162: &Apache::lonnet::allowuploaded('/adm/grades',$file);
1.564 bisitz 2163: $lastsubonly.='<br /><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.&Apache::loncommon::icon($file).'" border="0" /> '.$file.'</a>';
1.232 albertel 2164: }
1.236 albertel 2165: $lastsubonly.='<br />';
1.41 ng 2166: }
1.468 albertel 2167: $lastsubonly.='<b>'.&mt('Submitted Answer:').' </b>'.
1.151 albertel 2168: &cleanRecord($subval,$responsetype,$symb,$partid,
1.555 raeburn 2169: $respid,\%record,$order,undef,$uname,$udom);
1.151 albertel 2170: if ($similar) {$lastsubonly.="<br /><br />$similar\n";}
1.468 albertel 2171: $lastsubonly.='</div>';
1.41 ng 2172: }
2173: }
2174: }
1.468 albertel 2175: $lastsubonly.='</div>'."\n";
1.151 albertel 2176: }
2177: $request->print($lastsubonly);
1.468 albertel 2178: } elsif ($env{'form.lastSub'} eq 'datesub') {
1.324 albertel 2179: my (undef,$responseType,undef,$parts) = &showResourceInfo($symb);
1.148 albertel 2180: $request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
1.257 albertel 2181: } elsif ($env{'form.lastSub'} =~ /^(last|all)$/) {
1.41 ng 2182: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
1.257 albertel 2183: $env{'request.course.id'},
1.44 ng 2184: $last,'.submission',
2185: 'Apache::grades::keywords_highlight'));
1.41 ng 2186: }
1.120 ng 2187:
1.121 ng 2188: $request->print('<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
2189: .$udom.'" />'."\n");
1.44 ng 2190: # return if view submission with no grading option
1.257 albertel 2191: if ($env{'form.showgrading'} eq '' || (!&canmodify($usec))) {
1.120 ng 2192: my $toGrade.='<input type="button" value="Grade Student" '.
1.121 ng 2193: 'onClick="javascript:checksubmit(this.form,\'Grade Student\',\''
1.417 albertel 2194: .$counter.'\');" target="_self" /> '."\n" if (&canmodify($usec));
1.468 albertel 2195: $toGrade.='</div>'."\n";
1.257 albertel 2196: if (($env{'form.command'} eq 'submission') ||
2197: ($env{'form.command'} eq 'processGroup' && $counter == $total)) {
1.324 albertel 2198: $toGrade.='</form>'.&show_grading_menu_form($symb);
1.169 albertel 2199: }
1.180 albertel 2200: $request->print($toGrade);
1.41 ng 2201: return;
1.180 albertel 2202: } else {
1.468 albertel 2203: $request->print('</div>'."\n");
1.41 ng 2204: }
1.33 ng 2205:
1.121 ng 2206: # essay grading message center
1.257 albertel 2207: if ($env{'form.handgrade'} eq 'yes') {
1.468 albertel 2208: my $result='<div class="LC_grade_message_center">';
2209:
2210: $result.='<div class="LC_grade_message_center_header">'.
2211: &mt('Send Message').'</div><div class="LC_grade_message_center_body">';
1.257 albertel 2212: my ($lastname,$givenn) = split(/,/,$env{'form.fullname'});
1.118 ng 2213: my $msgfor = $givenn.' '.$lastname;
1.464 albertel 2214: if (scalar(@$col_fullnames) > 0) {
2215: my $lastone = pop(@$col_fullnames);
2216: $msgfor .= ', '.(join ', ',@$col_fullnames).' and '.$lastone.'.';
1.118 ng 2217: }
2218: $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
1.468 albertel 2219: $result.='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
1.121 ng 2220: '<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n";
2221: $result.=' <a href="javascript:msgCenter(document.SCORE,'.$counter.
1.417 albertel 2222: ',\''.$msgfor.'\');" target="_self">'.
1.464 albertel 2223: &mt('Compose message to student').(scalar(@$col_fullnames) >= 1 ? 's' : '').'</a><label> ('.
1.350 albertel 2224: &mt('incl. grades').' <input type="checkbox" name="withgrades'.$counter.'" /></label>)'.
1.118 ng 2225: '<img src="'.$request->dir_config('lonIconsURL').
2226: '/mailbkgrd.gif" width="14" height="10" name="mailicon'.$counter.'" />'."\n".
1.298 www 2227: '<br /> ('.
1.468 albertel 2228: &mt('Message will be sent when you click on Save & Next below.').")\n";
2229: $result.='</div></div>';
1.121 ng 2230: $request->print($result);
1.118 ng 2231: }
1.41 ng 2232:
2233: my %seen = ();
2234: my @partlist;
1.129 ng 2235: my @gradePartRespid;
1.375 albertel 2236: my @part_response_id = &flatten_responseType($responseType);
1.468 albertel 2237: $request->print('<div class="LC_grade_assign">'.
2238:
2239: '<div class="LC_grade_assign_header">'.
2240: &mt('Assign Grades').'</div>'.
2241: '<div class="LC_grade_assign_body">');
1.375 albertel 2242: foreach my $part_response_id (@part_response_id) {
2243: my ($partid,$respid) = @{ $part_response_id };
2244: my $part_resp = join('_',@{ $part_response_id });
1.322 albertel 2245: next if ($seen{$partid} > 0);
1.41 ng 2246: $seen{$partid}++;
1.393 albertel 2247: next if ($$handgrade{$part_resp} ne 'yes'
2248: && $env{'form.lastSub'} eq 'hdgrade');
1.524 raeburn 2249: push(@partlist,$partid);
2250: push(@gradePartRespid,$partid.'.'.$respid);
1.322 albertel 2251: $request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
1.41 ng 2252: }
1.468 albertel 2253: $request->print('</div></div>');
2254:
2255: $request->print('<div class="LC_grade_info_links">');
2256: if ($perm{'vgr'}) {
2257: $request->print(
2258: &Apache::loncommon::track_student_link(&mt('View recent activity'),
2259: $uname,$udom,'check'));
2260: }
2261: if ($perm{'opa'}) {
2262: $request->print(
2263: &Apache::loncommon::pprmlink(&mt('Set/Change parameters'),
2264: $uname,$udom,$symb,'check'));
2265: }
2266: $request->print('</div>');
2267:
1.45 ng 2268: $result='<input type="hidden" name="partlist'.$counter.
2269: '" value="'.(join ":",@partlist).'" />'."\n";
1.129 ng 2270: $result.='<input type="hidden" name="gradePartRespid'.
2271: '" value="'.(join ":",@gradePartRespid).'" />'."\n" if ($counter == 0);
1.45 ng 2272: my $ctr = 0;
2273: while ($ctr < scalar(@partlist)) {
2274: $result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
2275: $partlist[$ctr].'" />'."\n";
2276: $ctr++;
2277: }
1.468 albertel 2278: $request->print($result.''."\n");
1.41 ng 2279:
1.441 www 2280: # Done with printing info for one student
2281:
1.468 albertel 2282: $request->print('</div>');#LC_grade_show_user_body
2283: $request->print('</div>');#LC_grade_show_user
1.441 www 2284:
2285:
1.41 ng 2286: # print end of form
2287: if ($counter == $total) {
1.297 www 2288: my $endform='<table border="0"><tr><td>'."\n";
1.485 albertel 2289: $endform.='<input type="button" value="'.&mt('Save & Next').'" '.
1.119 ng 2290: 'onClick="javascript:checksubmit(this.form,\'Save & Next\','.
1.417 albertel 2291: $total.','.scalar(@partlist).');" target="_self" /> '."\n";
1.119 ng 2292: my $ntstu ='<select name="NTSTU">'.
2293: '<option>1</option><option>2</option>'.
2294: '<option>3</option><option>5</option>'.
2295: '<option>7</option><option>10</option></select>'."\n";
1.257 albertel 2296: my $nsel = ($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : '1');
1.401 albertel 2297: $ntstu =~ s/<option>$nsel</<option selected="selected">$nsel</;
1.574.2.2 raeburn 2298: $endform.=&mt('[_1]student(s)',$ntstu);
1.485 albertel 2299: $endform.=' <input type="button" value="'.&mt('Previous').'" '.
1.417 albertel 2300: 'onClick="javascript:checksubmit(this.form,\'Previous\');" target="_self" /> '."\n".
1.485 albertel 2301: '<input type="button" value="'.&mt('Next').'" '.
1.417 albertel 2302: 'onClick="javascript:checksubmit(this.form,\'Next\');" target="_self" /> ';
1.485 albertel 2303: $endform.=&mt('(Next and Previous (student) do not save the scores.)')."\n" ;
1.349 albertel 2304: $endform.="<input type='hidden' value='".&get_increment().
1.348 bowersj2 2305: "' name='increment' />";
1.485 albertel 2306: $endform.='</td></tr></table></form>';
1.324 albertel 2307: $endform.=&show_grading_menu_form($symb);
1.41 ng 2308: $request->print($endform);
2309: }
2310: return '';
1.38 ng 2311: }
2312:
1.464 albertel 2313: sub check_collaborators {
2314: my ($symb,$uname,$udom,$record,$handgrade,$counter) = @_;
2315: my ($result,@col_fullnames);
2316: my ($classlist,undef,$fullname) = &getclasslist('all','0');
2317: foreach my $part (keys(%$handgrade)) {
2318: my $ncol = &Apache::lonnet::EXT('resource.'.$part.
2319: '.maxcollaborators',
2320: $symb,$udom,$uname);
2321: next if ($ncol <= 0);
2322: $part =~ s/\_/\./g;
2323: next if ($record->{'resource.'.$part.'.collaborators'} eq '');
2324: my (@good_collaborators, @bad_collaborators);
2325: foreach my $possible_collaborator
2326: (split(/,?\s+/,$record->{'resource.'.$part.'.collaborators'})) {
2327: $possible_collaborator =~ s/[\$\^\(\)]//g;
2328: next if ($possible_collaborator eq '');
2329: my ($co_name,$co_dom) = split(/\@|:/,$possible_collaborator);
2330: $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
2331: next if ($co_name eq $uname && $co_dom eq $udom);
2332: # Doing this grep allows 'fuzzy' specification
2333: my @matches = grep(/^\Q$co_name\E:\Q$co_dom\E$/i,
2334: keys(%$classlist));
2335: if (! scalar(@matches)) {
2336: push(@bad_collaborators, $possible_collaborator);
2337: } else {
2338: push(@good_collaborators, @matches);
2339: }
2340: }
2341: if (scalar(@good_collaborators) != 0) {
1.466 albertel 2342: $result.='<br />'.&mt('Collaborators: ');
1.464 albertel 2343: foreach my $name (@good_collaborators) {
2344: my ($lastname,$givenn) = split(/,/,$$fullname{$name});
2345: push(@col_fullnames, $givenn.' '.$lastname);
2346: $result.=$fullname->{$name}.' ';
2347: }
2348: $result.='<br />'."\n";
1.466 albertel 2349: my ($part)=split(/\./,$part);
1.464 albertel 2350: $result.='<input type="hidden" name="collaborator'.$counter.
2351: '" value="'.$part.':'.(join ':',@good_collaborators).'" />'.
2352: "\n";
2353: }
2354: if (scalar(@bad_collaborators) > 0) {
1.466 albertel 2355: $result.='<div class="LC_warning">';
1.464 albertel 2356: $result.=&mt('This student has submitted [quant,_1,invalid collaborator]: [_2]',scalar(@bad_collaborators),join(', ',@bad_collaborators));
2357: $result .= '</div>';
2358: }
2359: if (scalar(@bad_collaborators > $ncol)) {
1.466 albertel 2360: $result .= '<div class="LC_warning">';
1.464 albertel 2361: $result .= &mt('This student has submitted too many '.
2362: 'collaborators. Maximum is [_1].',$ncol);
2363: $result .= '</div>';
2364: }
2365: }
2366: return ($result,$fullname,\@col_fullnames);
2367: }
2368:
1.44 ng 2369: #--- Retrieve the last submission for all the parts
1.38 ng 2370: sub get_last_submission {
1.119 ng 2371: my ($returnhash)=@_;
1.46 ng 2372: my (@string,$timestamp);
1.119 ng 2373: if ($$returnhash{'version'}) {
1.46 ng 2374: my %lasthash=();
2375: my ($version);
1.119 ng 2376: for ($version=1;$version<=$$returnhash{'version'};$version++) {
1.397 albertel 2377: foreach my $key (sort(split(/\:/,
2378: $$returnhash{$version.':keys'}))) {
2379: $lasthash{$key}=$$returnhash{$version.':'.$key};
2380: $timestamp =
1.545 raeburn 2381: &Apache::lonlocal::locallocaltime($$returnhash{$version.':timestamp'});
1.46 ng 2382: }
2383: }
1.397 albertel 2384: foreach my $key (keys(%lasthash)) {
2385: next if ($key !~ /\.submission$/);
2386:
2387: my ($partid,$foo) = split(/submission$/,$key);
2388: my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
1.398 albertel 2389: '<span class="LC_warning">Draft Copy</span> ' : '';
1.397 albertel 2390: push(@string, join(':', $key, $draft.$lasthash{$key}));
1.41 ng 2391: }
2392: }
1.397 albertel 2393: if (!@string) {
2394: $string[0] =
1.539 riegler 2395: '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span>';
1.397 albertel 2396: }
2397: return (\@string,\$timestamp);
1.38 ng 2398: }
1.35 ng 2399:
1.44 ng 2400: #--- High light keywords, with style choosen by user.
1.38 ng 2401: sub keywords_highlight {
1.44 ng 2402: my $string = shift;
1.257 albertel 2403: my $size = $env{'form.kwsize'} eq '0' ? '' : 'size='.$env{'form.kwsize'};
2404: my $styleon = $env{'form.kwstyle'} eq '' ? '' : $env{'form.kwstyle'};
1.41 ng 2405: (my $styleoff = $styleon) =~ s/\</\<\//;
1.257 albertel 2406: my @keylist = split(/[,\s+]/,$env{'form.keywords'});
1.398 albertel 2407: foreach my $keyword (@keylist) {
2408: $string =~ s/\b\Q$keyword\E(\b|\.)/<font color\=$env{'form.kwclr'} $size\>$styleon$keyword$styleoff<\/font>/gi;
1.41 ng 2409: }
2410: return $string;
1.38 ng 2411: }
1.36 ng 2412:
1.44 ng 2413: #--- Called from submission routine
1.38 ng 2414: sub processHandGrade {
1.41 ng 2415: my ($request) = shift;
1.324 albertel 2416: my $symb = &get_symb($request);
2417: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.257 albertel 2418: my $button = $env{'form.gradeOpt'};
2419: my $ngrade = $env{'form.NCT'};
2420: my $ntstu = $env{'form.NTSTU'};
1.301 albertel 2421: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2422: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2423:
1.44 ng 2424: if ($button eq 'Save & Next') {
2425: my $ctr = 0;
2426: while ($ctr < $ngrade) {
1.257 albertel 2427: my ($uname,$udom) = split(/:/,$env{'form.unamedom'.$ctr});
1.324 albertel 2428: my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$symb,$uname,$udom,$ctr);
1.71 ng 2429: if ($errorflag eq 'no_score') {
2430: $ctr++;
2431: next;
2432: }
1.104 albertel 2433: if ($errorflag eq 'not_allowed') {
1.398 albertel 2434: $request->print("<span class=\"LC_warning\">Not allowed to modify grades for $uname:$udom</span>");
1.104 albertel 2435: $ctr++;
2436: next;
2437: }
1.257 albertel 2438: my $includemsg = $env{'form.includemsg'.$ctr};
1.44 ng 2439: my ($subject,$message,$msgstatus) = ('','','');
1.418 albertel 2440: my $restitle = &Apache::lonnet::gettitle($symb);
2441: my ($feedurl,$showsymb) =
2442: &get_feedurl_and_symb($symb,$uname,$udom);
2443: my $messagetail;
1.62 albertel 2444: if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.298 www 2445: $subject = $env{'form.msgsub'} if ($includemsg =~ /msgsub/);
1.295 www 2446: unless ($subject=~/\w/) { $subject=&mt('Grading Feedback'); }
1.386 raeburn 2447: $subject.=' ['.$restitle.']';
1.44 ng 2448: my (@msgnum) = split(/,/,$includemsg);
2449: foreach (@msgnum) {
1.257 albertel 2450: $message.=$env{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
1.44 ng 2451: }
1.80 ng 2452: $message =&Apache::lonfeedback::clear_out_html($message);
1.298 www 2453: if ($env{'form.withgrades'.$ctr}) {
2454: $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
1.386 raeburn 2455: $messagetail = " for <a href=\"".
1.418 albertel 2456: $feedurl."?symb=$showsymb\">$env{'form.probTitle'}</a>";
1.386 raeburn 2457: }
2458: $msgstatus =
2459: &Apache::lonmsg::user_normal_msg($uname,$udom,$subject,
2460: $message.$messagetail,
1.418 albertel 2461: undef,$feedurl,undef,
1.386 raeburn 2462: undef,undef,$showsymb,
2463: $restitle);
1.574 bisitz 2464: $request->print('<br />'.&mt('Sending message to [_1]',$uname.':'.$udom).': '.
1.296 www 2465: $msgstatus);
1.44 ng 2466: }
1.257 albertel 2467: if ($env{'form.collaborator'.$ctr}) {
1.155 albertel 2468: my @collabstrs=&Apache::loncommon::get_env_multiple("form.collaborator$ctr");
1.150 albertel 2469: foreach my $collabstr (@collabstrs) {
2470: my ($part,@collaborators) = split(/:/,$collabstr);
1.310 banghart 2471: foreach my $collaborator (@collaborators) {
1.150 albertel 2472: my ($errorflag,$pts,$wgt) =
1.324 albertel 2473: &saveHandGrade($request,$symb,$collaborator,$udom,$ctr,
1.257 albertel 2474: $env{'form.unamedom'.$ctr},$part);
1.150 albertel 2475: if ($errorflag eq 'not_allowed') {
1.362 albertel 2476: $request->print("<span class=\"LC_error\">".&mt('Not allowed to modify grades for [_1]',"$collaborator:$udom")."</span>");
1.150 albertel 2477: next;
1.418 albertel 2478: } elsif ($message ne '') {
2479: my ($baseurl,$showsymb) =
2480: &get_feedurl_and_symb($symb,$collaborator,
2481: $udom);
2482: if ($env{'form.withgrades'.$ctr}) {
2483: $messagetail = " for <a href=\"".
1.386 raeburn 2484: $baseurl."?symb=$showsymb\">$env{'form.probTitle'}</a>";
1.150 albertel 2485: }
1.418 albertel 2486: $msgstatus =
2487: &Apache::lonmsg::user_normal_msg($collaborator,$udom,$subject,$message.$messagetail,undef,$baseurl,undef,undef,undef,$showsymb,$restitle);
1.104 albertel 2488: }
1.44 ng 2489: }
2490: }
2491: }
2492: $ctr++;
2493: }
2494: }
2495:
1.257 albertel 2496: if ($env{'form.handgrade'} eq 'yes') {
1.119 ng 2497: # Keywords sorted in alphabatical order
1.257 albertel 2498: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1.119 ng 2499: my %keyhash = ();
1.257 albertel 2500: $env{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
2501: $env{'form.keywords'} =~ s/^\s+|\s+$//;
2502: my (@keywords) = sort(split(/\s+/,$env{'form.keywords'}));
2503: $env{'form.keywords'} = join(' ',@keywords);
2504: $keyhash{$symb.'_keywords'} = $env{'form.keywords'};
2505: $keyhash{$symb.'_subject'} = $env{'form.msgsub'};
2506: $keyhash{$loginuser.'_kwclr'} = $env{'form.kwclr'};
2507: $keyhash{$loginuser.'_kwsize'} = $env{'form.kwsize'};
2508: $keyhash{$loginuser.'_kwstyle'} = $env{'form.kwstyle'};
1.119 ng 2509:
2510: # message center - Order of message gets changed. Blank line is eliminated.
1.257 albertel 2511: # New messages are saved in env for the next student.
1.119 ng 2512: # All messages are saved in nohist_handgrade.db
2513: my ($ctr,$idx) = (1,1);
1.257 albertel 2514: while ($ctr <= $env{'form.savemsgN'}) {
2515: if ($env{'form.savemsg'.$ctr} ne '') {
2516: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.savemsg'.$ctr};
1.119 ng 2517: $idx++;
2518: }
2519: $ctr++;
1.41 ng 2520: }
1.119 ng 2521: $ctr = 0;
2522: while ($ctr < $ngrade) {
1.257 albertel 2523: if ($env{'form.newmsg'.$ctr} ne '') {
2524: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.newmsg'.$ctr};
2525: $env{'form.savemsg'.$idx} = $env{'form.newmsg'.$ctr};
1.119 ng 2526: $idx++;
2527: }
2528: $ctr++;
1.41 ng 2529: }
1.257 albertel 2530: $env{'form.savemsgN'} = --$idx;
2531: $keyhash{$symb.'_savemsgN'} = $env{'form.savemsgN'};
1.119 ng 2532: my $putresult = &Apache::lonnet::put
1.301 albertel 2533: ('nohist_handgrade',\%keyhash,$cdom,$cnum);
1.41 ng 2534: }
1.44 ng 2535: # Called by Save & Refresh from Highlight Attribute Window
1.257 albertel 2536: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
2537: if ($env{'form.refresh'} eq 'on') {
1.86 ng 2538: my ($ctr,$total) = (0,0);
2539: while ($ctr < $ngrade) {
1.257 albertel 2540: $total++ if $env{'form.unamedom'.$ctr} ne '';
1.86 ng 2541: $ctr++;
2542: }
1.257 albertel 2543: $env{'form.NTSTU'}=$ngrade;
1.86 ng 2544: $ctr = 0;
2545: while ($ctr < $total) {
1.257 albertel 2546: my $processUser = $env{'form.unamedom'.$ctr};
2547: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2548: $env{'form.fullname'} = $$fullname{$processUser};
1.86 ng 2549: &submission($request,$ctr,$total-1);
1.41 ng 2550: $ctr++;
2551: }
2552: return '';
2553: }
1.36 ng 2554:
1.121 ng 2555: # Go directly to grade student - from submission or link from chart page
1.120 ng 2556: if ($button eq 'Grade Student') {
1.324 albertel 2557: (undef,undef,$env{'form.handgrade'},undef,undef) = &showResourceInfo($symb);
1.257 albertel 2558: my $processUser = $env{'form.unamedom'.$env{'form.studentNo'}};
2559: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2560: $env{'form.fullname'} = $$fullname{$processUser};
1.120 ng 2561: &submission($request,0,0);
2562: return '';
2563: }
2564:
1.44 ng 2565: # Get the next/previous one or group of students
1.257 albertel 2566: my $firststu = $env{'form.unamedom0'};
2567: my $laststu = $env{'form.unamedom'.($ngrade-1)};
1.119 ng 2568: my $ctr = 2;
1.41 ng 2569: while ($laststu eq '') {
1.257 albertel 2570: $laststu = $env{'form.unamedom'.($ngrade-$ctr)};
1.41 ng 2571: $ctr++;
2572: $laststu = $firststu if ($ctr > $ngrade);
2573: }
1.44 ng 2574:
1.41 ng 2575: my (@parsedlist,@nextlist);
2576: my ($nextflg) = 0;
1.524 raeburn 2577: foreach my $item (sort
1.294 albertel 2578: {
2579: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
2580: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
2581: }
2582: return $a cmp $b;
2583: } (keys(%$fullname))) {
1.41 ng 2584: if ($nextflg == 1 && $button =~ /Next$/) {
1.524 raeburn 2585: push(@parsedlist,$item);
1.41 ng 2586: }
1.524 raeburn 2587: $nextflg = 1 if ($item eq $laststu);
1.41 ng 2588: if ($button eq 'Previous') {
1.524 raeburn 2589: last if ($item eq $firststu);
2590: push(@parsedlist,$item);
1.41 ng 2591: }
2592: }
2593: $ctr = 0;
2594: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
1.324 albertel 2595: my ($partlist) = &response_type($symb);
1.41 ng 2596: foreach my $student (@parsedlist) {
1.257 albertel 2597: my $submitonly=$env{'form.submitonly'};
1.41 ng 2598: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 2599:
2600: if ($submitonly eq 'queued') {
2601: my %queue_status =
2602: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
2603: $udom,$uname);
2604: next if (!defined($queue_status{'gradingqueue'}));
2605: }
2606:
1.156 albertel 2607: if ($submitonly =~ /^(yes|graded|incorrect)$/) {
1.257 albertel 2608: # my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 2609: my %status=&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 2610: my $submitted = 0;
1.248 albertel 2611: my $ungraded = 0;
2612: my $incorrect = 0;
1.524 raeburn 2613: foreach my $item (keys(%status)) {
2614: $submitted = 1 if ($status{$item} ne 'nothing');
2615: $ungraded = 1 if ($status{$item} =~ /^ungraded/);
2616: $incorrect = 1 if ($status{$item} =~ /^incorrect/);
2617: my ($foo,$partid,$foo1) = split(/\./,$item);
1.145 albertel 2618: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
2619: $submitted = 0;
2620: }
1.41 ng 2621: }
1.156 albertel 2622: next if (!$submitted && ($submitonly eq 'yes' ||
2623: $submitonly eq 'incorrect' ||
2624: $submitonly eq 'graded'));
1.248 albertel 2625: next if (!$ungraded && ($submitonly eq 'graded'));
2626: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 2627: }
1.524 raeburn 2628: push(@nextlist,$student) if ($ctr < $ntstu);
1.129 ng 2629: last if ($ctr == $ntstu);
1.41 ng 2630: $ctr++;
2631: }
1.36 ng 2632:
1.41 ng 2633: $ctr = 0;
2634: my $total = scalar(@nextlist)-1;
1.39 ng 2635:
1.524 raeburn 2636: foreach (sort(@nextlist)) {
1.41 ng 2637: my ($uname,$udom,$submitter) = split(/:/);
1.257 albertel 2638: $env{'form.student'} = $uname;
2639: $env{'form.userdom'} = $udom;
2640: $env{'form.fullname'} = $$fullname{$_};
1.41 ng 2641: &submission($request,$ctr,$total);
2642: $ctr++;
2643: }
2644: if ($total < 0) {
1.485 albertel 2645: my $the_end = '<h3><span class="LC_info">'.&mt('LON-CAPA User Message').'</span></h3><br />'."\n";
2646: $the_end.=&mt('<b>Message: </b> No more students for this section or class.').'<br /><br />'."\n";
2647: $the_end.=&mt('Click on the button below to return to the grading menu.').'<br /><br />'."\n";
1.324 albertel 2648: $the_end.=&show_grading_menu_form($symb);
1.41 ng 2649: $request->print($the_end);
2650: }
2651: return '';
1.38 ng 2652: }
1.36 ng 2653:
1.44 ng 2654: #---- Save the score and award for each student, if changed
1.38 ng 2655: sub saveHandGrade {
1.324 albertel 2656: my ($request,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
1.342 banghart 2657: my @version_parts;
1.104 albertel 2658: my $usec = &Apache::lonnet::getsection($domain,$stuname,
1.257 albertel 2659: $env{'request.course.id'});
1.104 albertel 2660: if (!&canmodify($usec)) { return('not_allowed'); }
1.337 banghart 2661: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
1.251 banghart 2662: my @parts_graded;
1.77 ng 2663: my %newrecord = ();
2664: my ($pts,$wgt) = ('','');
1.269 raeburn 2665: my %aggregate = ();
2666: my $aggregateflag = 0;
1.301 albertel 2667: my @parts = split(/:/,$env{'form.partlist'.$newflg});
2668: foreach my $new_part (@parts) {
1.337 banghart 2669: #collaborator ($submi may vary for different parts
1.259 banghart 2670: if ($submitter && $new_part ne $part) { next; }
2671: my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
1.125 ng 2672: if ($dropMenu eq 'excused') {
1.259 banghart 2673: if ($record{'resource.'.$new_part.'.solved'} ne 'excused') {
2674: $newrecord{'resource.'.$new_part.'.solved'} = 'excused';
2675: if (exists($record{'resource.'.$new_part.'.awarded'})) {
2676: $newrecord{'resource.'.$new_part.'.awarded'} = '';
1.58 albertel 2677: }
1.364 banghart 2678: $newrecord{'resource.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.58 albertel 2679: }
1.125 ng 2680: } elsif ($dropMenu eq 'reset status'
1.259 banghart 2681: && exists($record{'resource.'.$new_part.'.solved'})) { #don't bother if no old records -> no attempts
1.524 raeburn 2682: foreach my $key (keys(%record)) {
1.259 banghart 2683: if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
1.197 albertel 2684: }
1.259 banghart 2685: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2686: "$env{'user.name'}:$env{'user.domain'}";
1.270 albertel 2687: my $totaltries = $record{'resource.'.$part.'.tries'};
2688:
2689: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
2690: [$new_part]);
2691: my $aggtries =$totaltries;
1.269 raeburn 2692: if ($last_resets{$new_part}) {
1.270 albertel 2693: $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
2694: $new_part);
1.269 raeburn 2695: }
1.270 albertel 2696:
2697: my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
1.269 raeburn 2698: if ($aggtries > 0) {
1.327 albertel 2699: &decrement_aggs($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
1.269 raeburn 2700: $aggregateflag = 1;
2701: }
1.125 ng 2702: } elsif ($dropMenu eq '') {
1.259 banghart 2703: $pts = ($env{'form.GD_BOX'.$newflg.'_'.$new_part} ne '' ?
2704: $env{'form.GD_BOX'.$newflg.'_'.$new_part} :
2705: $env{'form.RADVAL'.$newflg.'_'.$new_part});
2706: if ($pts eq '' && $env{'form.GD_SEL'.$newflg.'_'.$new_part} eq '') {
1.153 albertel 2707: next;
2708: }
1.259 banghart 2709: $wgt = $env{'form.WGT'.$newflg.'_'.$new_part} eq '' ? 1 :
2710: $env{'form.WGT'.$newflg.'_'.$new_part};
1.41 ng 2711: my $partial= $pts/$wgt;
1.259 banghart 2712: if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
1.153 albertel 2713: #do not update score for part if not changed.
1.346 banghart 2714: &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
1.153 albertel 2715: next;
1.251 banghart 2716: } else {
1.524 raeburn 2717: push(@parts_graded,$new_part);
1.153 albertel 2718: }
1.259 banghart 2719: if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
2720: $newrecord{'resource.'.$new_part.'.awarded'} = $partial;
1.153 albertel 2721: }
1.259 banghart 2722: my $reckey = 'resource.'.$new_part.'.solved';
1.41 ng 2723: if ($partial == 0) {
1.153 albertel 2724: if ($record{$reckey} ne 'incorrect_by_override') {
2725: $newrecord{$reckey} = 'incorrect_by_override';
2726: }
1.41 ng 2727: } else {
1.153 albertel 2728: if ($record{$reckey} ne 'correct_by_override') {
2729: $newrecord{$reckey} = 'correct_by_override';
2730: }
2731: }
2732: if ($submitter &&
1.259 banghart 2733: ($record{'resource.'.$new_part.'.submitted_by'} ne $submitter)) {
2734: $newrecord{'resource.'.$new_part.'.submitted_by'} = $submitter;
1.41 ng 2735: }
1.259 banghart 2736: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2737: "$env{'user.name'}:$env{'user.domain'}";
1.41 ng 2738: }
1.259 banghart 2739: # unless problem has been graded, set flag to version the submitted files
1.305 banghart 2740: unless ($record{'resource.'.$new_part.'.solved'} =~ /^correct_/ ||
2741: $record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override' ||
2742: $dropMenu eq 'reset status')
2743: {
1.524 raeburn 2744: push(@version_parts,$new_part);
1.259 banghart 2745: }
1.41 ng 2746: }
1.301 albertel 2747: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2748: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2749:
1.344 albertel 2750: if (%newrecord) {
2751: if (@version_parts) {
1.364 banghart 2752: my @changed_keys = &version_portfiles(\%record, \@parts_graded,
2753: $env{'request.course.id'}, $symb, $domain, $stuname, \@version_parts);
1.344 albertel 2754: @newrecord{@changed_keys} = @record{@changed_keys};
1.367 albertel 2755: foreach my $new_part (@version_parts) {
2756: &handback_files($request,$symb,$stuname,$domain,$newflg,
2757: $new_part,\%newrecord);
2758: }
1.259 banghart 2759: }
1.44 ng 2760: &Apache::lonnet::cstore(\%newrecord,$symb,
1.257 albertel 2761: $env{'request.course.id'},$domain,$stuname);
1.380 albertel 2762: &check_and_remove_from_queue(\@parts,\%record,\%newrecord,$symb,
2763: $cdom,$cnum,$domain,$stuname);
1.41 ng 2764: }
1.269 raeburn 2765: if ($aggregateflag) {
2766: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 2767: $cdom,$cnum);
1.269 raeburn 2768: }
1.301 albertel 2769: return ('',$pts,$wgt);
1.36 ng 2770: }
1.322 albertel 2771:
1.380 albertel 2772: sub check_and_remove_from_queue {
2773: my ($parts,$record,$newrecord,$symb,$cdom,$cnum,$domain,$stuname) = @_;
2774: my @ungraded_parts;
2775: foreach my $part (@{$parts}) {
2776: if ( $record->{ 'resource.'.$part.'.awarded'} eq ''
2777: && $record->{ 'resource.'.$part.'.solved' } ne 'excused'
2778: && $newrecord->{'resource.'.$part.'.awarded'} eq ''
2779: && $newrecord->{'resource.'.$part.'.solved' } ne 'excused'
2780: ) {
2781: push(@ungraded_parts, $part);
2782: }
2783: }
2784: if ( !@ungraded_parts ) {
2785: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,
2786: $cnum,$domain,$stuname);
2787: }
2788: }
2789:
1.337 banghart 2790: sub handback_files {
2791: my ($request,$symb,$stuname,$domain,$newflg,$new_part,$newrecord) = @_;
1.517 raeburn 2792: my $portfolio_root = '/userfiles/portfolio';
1.359 www 2793: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.375 albertel 2794:
2795: my @part_response_id = &flatten_responseType($responseType);
2796: foreach my $part_response_id (@part_response_id) {
2797: my ($part_id,$resp_id) = @{ $part_response_id };
2798: my $part_resp = join('_',@{ $part_response_id });
1.337 banghart 2799: if (($env{'form.'.$newflg.'_'.$part_resp.'_returndoc1'}) && ($new_part == $part_id)) {
2800: # if multiple files are uploaded names will be 'returndoc2','returndoc3'
2801: my $file_counter = 1;
1.367 albertel 2802: my $file_msg;
1.337 banghart 2803: while ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter}) {
2804: my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.'.filename'};
1.338 banghart 2805: my ($directory,$answer_file) =
2806: ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter} =~ /^(.*?)([^\/]*)$/);
2807: my ($answer_name,$answer_ver,$answer_ext) =
2808: &file_name_version_ext($answer_file);
1.355 banghart 2809: my ($portfolio_path) = ($directory =~ /^.+$stuname\/portfolio(.*)/);
1.517 raeburn 2810: my $getpropath = 1;
2811: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$portfolio_path,$domain,$stuname,$getpropath);
1.338 banghart 2812: my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
1.355 banghart 2813: # fix file name
2814: my ($save_file_name) = (($directory.$answer_name.".$version.".$answer_ext) =~ /^.+\/${stuname}\/(.*)/);
2815: my $result=&Apache::lonnet::finishuserfileupload($stuname,$domain,
2816: $newflg.'_'.$part_resp.'_returndoc'.$file_counter,
2817: $save_file_name);
1.337 banghart 2818: if ($result !~ m|^/uploaded/|) {
1.536 raeburn 2819: $request->print('<br /><span class="LC_error">'.
2820: &mt('An error occurred ([_1]) while trying to upload [_2].',
2821: $result,$newflg.'_'.$part_resp.'_returndoc'.$file_counter).
2822: '</span>');
1.356 banghart 2823: } else {
1.360 banghart 2824: # mark the file as read only
2825: my @files = ($save_file_name);
1.372 albertel 2826: my @what = ($symb,$env{'request.course.id'},'handback');
1.360 banghart 2827: &Apache::lonnet::mark_as_readonly($domain,$stuname,\@files,\@what);
1.367 albertel 2828: if (exists($$newrecord{"resource.$new_part.$resp_id.handback"})) {
2829: $$newrecord{"resource.$new_part.$resp_id.handback"}.=',';
2830: }
2831: $$newrecord{"resource.$new_part.$resp_id.handback"} .= $save_file_name;
2832: $file_msg.= "\n".'<br /><span class="LC_filename"><a href="/uploaded/'."$domain/$stuname/".$save_file_name.'">'.$save_file_name."</a></span><br />";
2833:
1.337 banghart 2834: }
2835: $request->print("<br />".$fname." will be the uploaded file name");
1.354 albertel 2836: $request->print(" ".$env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter});
1.337 banghart 2837: $file_counter++;
2838: }
1.367 albertel 2839: my $subject = "File Handed Back by Instructor ";
2840: my $message = "A file has been returned that was originally submitted in reponse to: <br />";
2841: $message .= "<strong>".&Apache::lonnet::gettitle($symb)."</strong><br />";
2842: $message .= ' The returned file(s) are named: '. $file_msg;
2843: $message .= " and can be found in your portfolio space.";
1.418 albertel 2844: my ($feedurl,$showsymb) =
2845: &get_feedurl_and_symb($symb,$domain,$stuname);
1.386 raeburn 2846: my $restitle = &Apache::lonnet::gettitle($symb);
2847: my $msgstatus =
2848: &Apache::lonmsg::user_normal_msg($stuname,$domain,$subject.
2849: ' (File Returned) ['.$restitle.']',$message,undef,
1.418 albertel 2850: $feedurl,undef,undef,undef,$showsymb,$restitle);
1.337 banghart 2851: }
2852: }
1.338 banghart 2853: return;
1.337 banghart 2854: }
2855:
1.418 albertel 2856: sub get_feedurl_and_symb {
2857: my ($symb,$uname,$udom) = @_;
2858: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
2859: $url = &Apache::lonnet::clutter($url);
2860: my $encrypturl=&Apache::lonnet::EXT('resource.0.encrypturl',
2861: $symb,$udom,$uname);
2862: if ($encrypturl =~ /^yes$/i) {
2863: &Apache::lonenc::encrypted(\$url,1);
2864: &Apache::lonenc::encrypted(\$symb,1);
2865: }
2866: return ($url,$symb);
2867: }
2868:
1.313 banghart 2869: sub get_submitted_files {
2870: my ($udom,$uname,$partid,$respid,$record) = @_;
2871: my @files;
2872: if ($$record{"resource.$partid.$respid.portfiles"}) {
2873: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
2874: foreach my $file (split(',',$$record{"resource.$partid.$respid.portfiles"})) {
2875: push(@files,$file_url.$file);
2876: }
2877: }
2878: if ($$record{"resource.$partid.$respid.uploadedurl"}) {
2879: push(@files,$$record{"resource.$partid.$respid.uploadedurl"});
2880: }
2881: return (\@files);
2882: }
1.322 albertel 2883:
1.269 raeburn 2884: # ----------- Provides number of tries since last reset.
2885: sub get_num_tries {
2886: my ($record,$last_reset,$part) = @_;
2887: my $timestamp = '';
2888: my $num_tries = 0;
2889: if ($$record{'version'}) {
2890: for (my $version=$$record{'version'};$version>=1;$version--) {
2891: if (exists($$record{$version.':resource.'.$part.'.solved'})) {
2892: $timestamp = $$record{$version.':timestamp'};
2893: if ($timestamp > $last_reset) {
2894: $num_tries ++;
2895: } else {
2896: last;
2897: }
2898: }
2899: }
2900: }
2901: return $num_tries;
2902: }
2903:
2904: # ----------- Determine decrements required in aggregate totals
2905: sub decrement_aggs {
2906: my ($symb,$part,$aggregate,$aggtries,$totaltries,$solvedstatus) = @_;
2907: my %decrement = (
2908: attempts => 0,
2909: users => 0,
2910: correct => 0
2911: );
2912: $decrement{'attempts'} = $aggtries;
2913: if ($solvedstatus =~ /^correct/) {
2914: $decrement{'correct'} = 1;
2915: }
2916: if ($aggtries == $totaltries) {
2917: $decrement{'users'} = 1;
2918: }
1.524 raeburn 2919: foreach my $type (keys(%decrement)) {
1.269 raeburn 2920: $$aggregate{$symb."\0".$part."\0".$type} = -$decrement{$type};
2921: }
2922: return;
2923: }
2924:
2925: # ----------- Determine timestamps for last reset of aggregate totals for parts
2926: sub get_last_resets {
1.270 albertel 2927: my ($symb,$courseid,$partids) =@_;
2928: my %last_resets;
1.269 raeburn 2929: my $cdom = $env{'course.'.$courseid.'.domain'};
2930: my $cname = $env{'course.'.$courseid.'.num'};
1.271 albertel 2931: my @keys;
2932: foreach my $part (@{$partids}) {
2933: push(@keys,"$symb\0$part\0resettime");
2934: }
2935: my %results=&Apache::lonnet::get('nohist_resourcetracker',\@keys,
2936: $cdom,$cname);
2937: foreach my $part (@{$partids}) {
2938: $last_resets{$part}=$results{"$symb\0$part\0resettime"};
1.269 raeburn 2939: }
1.270 albertel 2940: return %last_resets;
1.269 raeburn 2941: }
2942:
1.251 banghart 2943: # ----------- Handles creating versions for portfolio files as answers
2944: sub version_portfiles {
1.343 banghart 2945: my ($record, $parts_graded, $courseid, $symb, $domain, $stu_name, $v_flag) = @_;
1.263 banghart 2946: my $version_parts = join('|',@$v_flag);
1.343 banghart 2947: my @returned_keys;
1.255 banghart 2948: my $parts = join('|', @$parts_graded);
1.517 raeburn 2949: my $portfolio_root = '/userfiles/portfolio';
1.277 albertel 2950: foreach my $key (keys(%$record)) {
1.259 banghart 2951: my $new_portfiles;
1.263 banghart 2952: if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
1.342 banghart 2953: my @versioned_portfiles;
1.367 albertel 2954: my @portfiles = split(/\s*,\s*/,$$record{$key});
1.252 banghart 2955: foreach my $file (@portfiles) {
1.306 banghart 2956: &Apache::lonnet::unmark_as_readonly($domain,$stu_name,[$symb,$env{'request.course.id'}],$file);
1.304 albertel 2957: my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*)$/);
2958: my ($answer_name,$answer_ver,$answer_ext) =
2959: &file_name_version_ext($answer_file);
1.517 raeburn 2960: my $getpropath = 1;
2961: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$directory,$domain,$stu_name,$getpropath);
1.342 banghart 2962: my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
1.306 banghart 2963: my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version);
2964: if ($new_answer ne 'problem getting file') {
1.342 banghart 2965: push(@versioned_portfiles, $directory.$new_answer);
1.306 banghart 2966: &Apache::lonnet::mark_as_readonly($domain,$stu_name,
1.367 albertel 2967: [$directory.$new_answer],
1.306 banghart 2968: [$symb,$env{'request.course.id'},'graded']);
1.259 banghart 2969: }
1.252 banghart 2970: }
1.343 banghart 2971: $$record{$key} = join(',',@versioned_portfiles);
2972: push(@returned_keys,$key);
1.251 banghart 2973: }
2974: }
1.343 banghart 2975: return (@returned_keys);
1.305 banghart 2976: }
2977:
1.307 banghart 2978: sub get_next_version {
1.341 banghart 2979: my ($answer_name, $answer_ext, $dir_list) = @_;
1.307 banghart 2980: my $version;
2981: foreach my $row (@$dir_list) {
2982: my ($file) = split(/\&/,$row,2);
2983: my ($file_name,$file_version,$file_ext) =
2984: &file_name_version_ext($file);
2985: if (($file_name eq $answer_name) &&
2986: ($file_ext eq $answer_ext)) {
2987: # gets here if filename and extension match, regardless of version
2988: if ($file_version ne '') {
2989: # a versioned file is found so save it for later
2990: if ($file_version > $version) {
2991: $version = $file_version;
2992: }
2993: }
2994: }
2995: }
2996: $version ++;
2997: return($version);
2998: }
2999:
1.305 banghart 3000: sub version_selected_portfile {
1.306 banghart 3001: my ($domain,$stu_name,$directory,$file_name,$version) = @_;
3002: my ($answer_name,$answer_ver,$answer_ext) =
3003: &file_name_version_ext($file_name);
3004: my $new_answer;
3005: $env{'form.copy'} = &Apache::lonnet::getfile("/uploaded/$domain/$stu_name/portfolio$directory$file_name");
3006: if($env{'form.copy'} eq '-1') {
3007: $new_answer = 'problem getting file';
3008: } else {
3009: $new_answer = $answer_name.'.'.$version.'.'.$answer_ext;
3010: my $copy_result = &Apache::lonnet::finishuserfileupload(
3011: $stu_name,$domain,'copy',
3012: '/portfolio'.$directory.$new_answer);
3013: }
3014: return ($new_answer);
1.251 banghart 3015: }
3016:
1.304 albertel 3017: sub file_name_version_ext {
3018: my ($file)=@_;
3019: my @file_parts = split(/\./, $file);
3020: my ($name,$version,$ext);
3021: if (@file_parts > 1) {
3022: $ext=pop(@file_parts);
3023: if (@file_parts > 1 && $file_parts[-1] =~ /^\d+$/) {
3024: $version=pop(@file_parts);
3025: }
3026: $name=join('.',@file_parts);
3027: } else {
3028: $name=join('.',@file_parts);
3029: }
3030: return($name,$version,$ext);
3031: }
3032:
1.44 ng 3033: #--------------------------------------------------------------------------------------
3034: #
3035: #-------------------------- Next few routines handles grading by section or whole class
3036: #
3037: #--- Javascript to handle grading by section or whole class
1.42 ng 3038: sub viewgrades_js {
3039: my ($request) = shift;
3040:
1.539 riegler 3041: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
1.41 ng 3042: $request->print(<<VIEWJAVASCRIPT);
3043: <script type="text/javascript" language="javascript">
1.45 ng 3044: function writePoint(partid,weight,point) {
1.125 ng 3045: var radioButton = document.classgrade["RADVAL_"+partid];
3046: var textbox = document.classgrade["TEXTVAL_"+partid];
1.42 ng 3047: if (point == "textval") {
1.125 ng 3048: point = document.classgrade["TEXTVAL_"+partid].value;
1.109 matthew 3049: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 3050: alert("$alertmsg"+parseFloat(point));
1.42 ng 3051: var resetbox = false;
3052: for (var i=0; i<radioButton.length; i++) {
3053: if (radioButton[i].checked) {
3054: textbox.value = i;
3055: resetbox = true;
3056: }
3057: }
3058: if (!resetbox) {
3059: textbox.value = "";
3060: }
3061: return;
3062: }
1.109 matthew 3063: if (parseFloat(point) > parseFloat(weight)) {
3064: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 3065: ") greater than the weight for the part. Accept?");
3066: if (resp == false) {
3067: textbox.value = "";
3068: return;
3069: }
3070: }
1.42 ng 3071: for (var i=0; i<radioButton.length; i++) {
3072: radioButton[i].checked=false;
1.109 matthew 3073: if (parseFloat(point) == i) {
1.42 ng 3074: radioButton[i].checked=true;
3075: }
3076: }
1.41 ng 3077:
1.42 ng 3078: } else {
1.125 ng 3079: textbox.value = parseFloat(point);
1.42 ng 3080: }
1.41 ng 3081: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3082: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3083: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3084: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3085: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3086: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 3087: if (saveval != "correct") {
3088: scorename.value = point;
1.43 ng 3089: if (selname[0].selected != true) {
3090: selname[0].selected = true;
3091: }
1.42 ng 3092: }
3093: }
1.125 ng 3094: document.classgrade["SELVAL_"+partid][0].selected = true;
1.42 ng 3095: }
3096:
3097: function writeRadText(partid,weight) {
1.125 ng 3098: var selval = document.classgrade["SELVAL_"+partid];
3099: var radioButton = document.classgrade["RADVAL_"+partid];
1.265 www 3100: var override = document.classgrade["FORCE_"+partid].checked;
1.125 ng 3101: var textbox = document.classgrade["TEXTVAL_"+partid];
3102: if (selval[1].selected || selval[2].selected) {
1.42 ng 3103: for (var i=0; i<radioButton.length; i++) {
3104: radioButton[i].checked=false;
3105:
3106: }
3107: textbox.value = "";
3108:
3109: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3110: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3111: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3112: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3113: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3114: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 3115: if ((saveval != "correct") || override) {
1.42 ng 3116: scorename.value = "";
1.125 ng 3117: if (selval[1].selected) {
3118: selname[1].selected = true;
3119: } else {
3120: selname[2].selected = true;
3121: if (Number(document.classgrade["GD_"+user+"_"+partid+"_tries"].value))
3122: {document.classgrade["GD_"+user+"_"+partid+"_tries"].value = '0';}
3123: }
1.42 ng 3124: }
3125: }
1.43 ng 3126: } else {
3127: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3128: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3129: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3130: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3131: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3132: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 3133: if ((saveval != "correct") || override) {
1.125 ng 3134: scorename.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
1.43 ng 3135: selname[0].selected = true;
3136: }
3137: }
3138: }
1.42 ng 3139: }
3140:
3141: function changeSelect(partid,user) {
1.125 ng 3142: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
3143: var textbox = document.classgrade["GD_"+user+'_'+partid+"_awarded"];
1.44 ng 3144: var point = textbox.value;
1.125 ng 3145: var weight = document.classgrade["weight_"+partid].value;
1.44 ng 3146:
1.109 matthew 3147: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 3148: alert("$alertmsg"+parseFloat(point));
1.44 ng 3149: textbox.value = "";
3150: return;
3151: }
1.109 matthew 3152: if (parseFloat(point) > parseFloat(weight)) {
3153: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 3154: ") greater than the weight of the part. Accept?");
3155: if (resp == false) {
3156: textbox.value = "";
3157: return;
3158: }
3159: }
1.42 ng 3160: selval[0].selected = true;
3161: }
3162:
3163: function changeOneScore(partid,user) {
1.125 ng 3164: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
3165: if (selval[1].selected || selval[2].selected) {
3166: document.classgrade["GD_"+user+'_'+partid+"_awarded"].value = "";
3167: if (selval[2].selected) {
3168: document.classgrade["GD_"+user+'_'+partid+"_tries"].value = "0";
3169: }
1.269 raeburn 3170: }
1.42 ng 3171: }
3172:
3173: function resetEntry(numpart) {
3174: for (ctpart=0;ctpart<numpart;ctpart++) {
1.125 ng 3175: var partid = document.classgrade["partid_"+ctpart].value;
3176: var radioButton = document.classgrade["RADVAL_"+partid];
3177: var textbox = document.classgrade["TEXTVAL_"+partid];
3178: var selval = document.classgrade["SELVAL_"+partid];
1.42 ng 3179: for (var i=0; i<radioButton.length; i++) {
3180: radioButton[i].checked=false;
3181:
3182: }
3183: textbox.value = "";
3184: selval[0].selected = true;
3185:
3186: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3187: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3188: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3189: var resetscore = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3190: resetscore.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
3191: var resettries = document.classgrade["GD_"+user+"_"+partid+"_tries"];
3192: resettries.value = document.classgrade["GD_"+user+"_"+partid+"_tries_s"].value;
3193: var saveselval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3194: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 3195: if (saveselval == "excused") {
1.43 ng 3196: if (selname[1].selected == false) { selname[1].selected = true;}
1.42 ng 3197: } else {
1.43 ng 3198: if (selname[0].selected == false) {selname[0].selected = true};
1.42 ng 3199: }
3200: }
1.41 ng 3201: }
1.42 ng 3202: }
3203:
1.41 ng 3204: </script>
3205: VIEWJAVASCRIPT
1.42 ng 3206: }
3207:
1.44 ng 3208: #--- show scores for a section or whole class w/ option to change/update a score
1.42 ng 3209: sub viewgrades {
3210: my ($request) = shift;
3211: &viewgrades_js($request);
1.41 ng 3212:
1.324 albertel 3213: my ($symb) = &get_symb($request);
1.168 albertel 3214: #need to make sure we have the correct data for later EXT calls,
3215: #thus invalidate the cache
3216: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 3217: $env{'course.'.$env{'request.course.id'}.'.num'},
3218: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 3219: &Apache::lonnet::clear_EXT_cache_status();
3220:
1.398 albertel 3221: my $result='<h3><span class="LC_info">'.&mt('Manual Grading').'</span></h3>';
1.485 albertel 3222: $result.='<h4>'.&mt('<b>Current Resource: </b>[_1]',$env{'form.probTitle'}).'</h4>'."\n";
1.41 ng 3223:
3224: #view individual student submission form - called using Javascript viewOneStudent
1.324 albertel 3225: $result.=&jscriptNform($symb);
1.41 ng 3226:
1.44 ng 3227: #beginning of class grading form
1.442 banghart 3228: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.41 ng 3229: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1.418 albertel 3230: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.38 ng 3231: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.432 banghart 3232: &build_section_inputs().
1.257 albertel 3233: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.442 banghart 3234: '<input type="hidden" name="Status" value="'.$env{'stu_status'}.'" />'."\n".
1.257 albertel 3235: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.72 ng 3236:
1.560 raeburn 3237: my ($common_header,$specific_header);
1.257 albertel 3238: if ($env{'form.section'} eq 'all') {
1.560 raeburn 3239: $common_header = &mt('Assign Common Grade to Class');
3240: $specific_header = &mt('Assign Grade to Specific Students in Class');
1.257 albertel 3241: } elsif ($env{'form.section'} eq 'none') {
1.560 raeburn 3242: $common_header = &mt('Assign Common Grade to Students in no Section');
3243: $specific_header = &mt('Assign Grade to Specific Students in no Section');
1.52 albertel 3244: } else {
1.560 raeburn 3245: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
3246: $common_header = &mt('Assign Common Grade to Students in Section(s) [_1]',$section_display);
3247: $specific_header = &mt('Assign Grade to Specific Students in Section(s) [_1]',$section_display);
1.52 albertel 3248: }
1.560 raeburn 3249: $result.= '<h3>'.$common_header.'</h3>'.&Apache::loncommon::start_data_table();
1.44 ng 3250: #radio buttons/text box for assigning points for a section or class.
3251: #handles different parts of a problem
1.375 albertel 3252: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.42 ng 3253: my %weight = ();
3254: my $ctsparts = 0;
1.45 ng 3255: my %seen = ();
1.375 albertel 3256: my @part_response_id = &flatten_responseType($responseType);
3257: foreach my $part_response_id (@part_response_id) {
3258: my ($partid,$respid) = @{ $part_response_id };
3259: my $part_resp = join('_',@{ $part_response_id });
1.45 ng 3260: next if $seen{$partid};
3261: $seen{$partid}++;
1.375 albertel 3262: my $handgrade=$$handgrade{$part_resp};
1.42 ng 3263: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
3264: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
3265:
1.324 albertel 3266: my $display_part=&get_display_part($partid,$symb);
1.485 albertel 3267: my $radio.='<table border="0"><tr>';
1.41 ng 3268: my $ctr = 0;
1.42 ng 3269: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
1.485 albertel 3270: $radio.= '<td><label><input type="radio" name="RADVAL_'.$partid.'" '.
1.54 albertel 3271: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.288 albertel 3272: ','.$ctr.')" />'.$ctr."</label></td>\n";
1.41 ng 3273: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
3274: $ctr++;
3275: }
1.485 albertel 3276: $radio.='</tr></table>';
3277: my $line = '<input type="text" name="TEXTVAL_'.
1.54 albertel 3278: $partid.'" size="4" '.'onChange="javascript:writePoint(\''.
3279: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.539 riegler 3280: $weight{$partid}.' '.&mt('(problem weight)').'</td>'."\n";
3281: $line.= '<td><b>'.&mt('Grade Status').':</b><select name="SELVAL_'.$partid.'"'.
1.54 albertel 3282: 'onChange="javascript:writeRadText(\''.$partid.'\','.
1.59 albertel 3283: $weight{$partid}.')"> '.
1.401 albertel 3284: '<option selected="selected"> </option>'.
1.485 albertel 3285: '<option value="excused">'.&mt('excused').'</option>'.
3286: '<option value="reset status">'.&mt('reset status').'</option>'.
3287: '</select></td>'.
3288: '<td><label><input type="checkbox" name="FORCE_'.$partid.'" />'.&mt('Override "Correct"').'</label>';
3289: $line.='<input type="hidden" name="partid_'.
3290: $ctsparts.'" value="'.$partid.'" />'."\n";
3291: $line.='<input type="hidden" name="weight_'.
3292: $partid.'" value="'.$weight{$partid}.'" />'."\n";
3293:
3294: $result.=
3295: &Apache::loncommon::start_data_table_row()."\n".
1.539 riegler 3296: '<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 3297: &Apache::loncommon::end_data_table_row()."\n";
1.42 ng 3298: $ctsparts++;
1.41 ng 3299: }
1.474 albertel 3300: $result.=&Apache::loncommon::end_data_table()."\n".
1.52 albertel 3301: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.485 albertel 3302: $result.='<input type="button" value="'.&mt('Revert to Default').'" '.
1.474 albertel 3303: 'onClick="javascript:resetEntry('.$ctsparts.');" />';
1.41 ng 3304:
1.44 ng 3305: #table listing all the students in a section/class
3306: #header of table
1.560 raeburn 3307: $result.= '<h3>'.$specific_header.'</h3>'.
3308: &Apache::loncommon::start_data_table().
3309: &Apache::loncommon::start_data_table_header_row().
3310: '<th>'.&mt('No.').'</th>'.
3311: '<th>'.&nameUserString('header')."</th>\n";
1.324 albertel 3312: my (@parts) = sort(&getpartlist($symb));
3313: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.269 raeburn 3314: my @partids = ();
1.41 ng 3315: foreach my $part (@parts) {
3316: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1.539 riegler 3317: my $narrowtext = &mt('Tries');
3318: $display =~ s|^Number of Attempts|$narrowtext <br />|; # makes the column narrower
1.41 ng 3319: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
1.207 albertel 3320: my ($partid) = &split_part_type($part);
1.524 raeburn 3321: push(@partids,$partid);
1.324 albertel 3322: my $display_part=&get_display_part($partid,$symb);
1.41 ng 3323: if ($display =~ /^Partial Credit Factor/) {
1.485 albertel 3324: $result.='<th>'.
3325: &mt('Score Part: [_1]<br /> (weight = [_2])',
3326: $display_part,$weight{$partid}).'</th>'."\n";
1.41 ng 3327: next;
1.485 albertel 3328:
1.207 albertel 3329: } else {
1.485 albertel 3330: if ($display =~ /Problem Status/) {
3331: my $grade_status_mt = &mt('Grade Status');
3332: $display =~ s{Problem Status}{$grade_status_mt<br />};
3333: }
3334: my $part_mt = &mt('Part:');
3335: $display =~s{\[Part: \Q$partid\E\]}{$part_mt $display_part};
1.41 ng 3336: }
1.485 albertel 3337:
1.474 albertel 3338: $result.='<th>'.$display.'</th>'."\n";
1.41 ng 3339: }
1.474 albertel 3340: $result.=&Apache::loncommon::end_data_table_header_row();
1.44 ng 3341:
1.270 albertel 3342: my %last_resets =
3343: &get_last_resets($symb,$env{'request.course.id'},\@partids);
1.269 raeburn 3344:
1.41 ng 3345: #get info for each student
1.44 ng 3346: #list all the students - with points and grade status
1.257 albertel 3347: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
1.41 ng 3348: my $ctr = 0;
1.294 albertel 3349: foreach (sort
3350: {
3351: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
3352: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
3353: }
3354: return $a cmp $b;
3355: } (keys(%$fullname))) {
1.126 ng 3356: $ctr++;
1.324 albertel 3357: $result.=&viewstudentgrade($symb,$env{'request.course.id'},
1.269 raeburn 3358: $_,$$fullname{$_},\@parts,\%weight,$ctr,\%last_resets);
1.41 ng 3359: }
1.474 albertel 3360: $result.=&Apache::loncommon::end_data_table();
1.41 ng 3361: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.485 albertel 3362: $result.='<input type="button" value="'.&mt('Save').'" '.
1.417 albertel 3363: 'onClick="javascript:submit();" target="_self" /></form>'."\n";
1.96 albertel 3364: if (scalar(%$fullname) eq 0) {
3365: my $colspan=3+scalar(@parts);
1.433 banghart 3366: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.442 banghart 3367: my $stu_status = join(' or ',&Apache::loncommon::get_env_multiple('form.Status'));
1.433 banghart 3368: $result='<span class="LC_warning">'.
1.485 albertel 3369: &mt('There are no students in section(s) [_1] with enrollment status [_2] to modify or grade.',
1.442 banghart 3370: $section_display, $stu_status).
1.433 banghart 3371: '</span>';
1.96 albertel 3372: }
1.324 albertel 3373: $result.=&show_grading_menu_form($symb);
1.41 ng 3374: return $result;
3375: }
3376:
1.44 ng 3377: #--- call by previous routine to display each student
1.41 ng 3378: sub viewstudentgrade {
1.324 albertel 3379: my ($symb,$courseid,$student,$fullname,$parts,$weight,$ctr,$last_resets) = @_;
1.44 ng 3380: my ($uname,$udom) = split(/:/,$student);
3381: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.269 raeburn 3382: my %aggregates = ();
1.474 albertel 3383: my $result=&Apache::loncommon::start_data_table_row().'<td align="right">'.
1.233 albertel 3384: '<input type="hidden" name="ctr'.($ctr-1).'" value="'.$student.'" />'.
3385: "\n".$ctr.' </td><td> '.
1.44 ng 3386: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 3387: '\');" target="_self">'.$fullname.'</a> '.
1.398 albertel 3388: '<span class="LC_internal_info">('.$uname.($env{'user.domain'} eq $udom ? '' : ':'.$udom).')</span></td>'."\n";
1.281 albertel 3389: $student=~s/:/_/; # colon doen't work in javascript for names
1.63 albertel 3390: foreach my $apart (@$parts) {
3391: my ($part,$type) = &split_part_type($apart);
1.41 ng 3392: my $score=$record{"resource.$part.$type"};
1.276 albertel 3393: $result.='<td align="center">';
1.269 raeburn 3394: my ($aggtries,$totaltries);
3395: unless (exists($aggregates{$part})) {
1.270 albertel 3396: $totaltries = $record{'resource.'.$part.'.tries'};
3397:
3398: $aggtries = $totaltries;
1.269 raeburn 3399: if ($$last_resets{$part}) {
1.270 albertel 3400: $aggtries = &get_num_tries(\%record,$$last_resets{$part},
3401: $part);
3402: }
1.269 raeburn 3403: $result.='<input type="hidden" name="'.
3404: 'GD_'.$student.'_'.$part.'_aggtries" value="'.$aggtries.'" />'."\n";
3405: $result.='<input type="hidden" name="'.
3406: 'GD_'.$student.'_'.$part.'_totaltries" value="'.$totaltries.'" />'."\n";
3407: $aggregates{$part} = 1;
3408: }
1.41 ng 3409: if ($type eq 'awarded') {
1.320 albertel 3410: my $pts = $score eq '' ? '' : &compute_points($score,$$weight{$part});
1.42 ng 3411: $result.='<input type="hidden" name="'.
1.89 albertel 3412: 'GD_'.$student.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.233 albertel 3413: $result.='<input type="text" name="'.
1.89 albertel 3414: 'GD_'.$student.'_'.$part.'_awarded" '.
3415: 'onChange="javascript:changeSelect(\''.$part.'\',\''.$student.
1.44 ng 3416: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41 ng 3417: } elsif ($type eq 'solved') {
3418: my ($status,$foo)=split(/_/,$score,2);
3419: $status = 'nothing' if ($status eq '');
1.89 albertel 3420: $result.='<input type="hidden" name="'.'GD_'.$student.'_'.
1.54 albertel 3421: $part.'_solved_s" value="'.$status.'" />'."\n";
1.233 albertel 3422: $result.=' <select name="'.
1.89 albertel 3423: 'GD_'.$student.'_'.$part.'_solved" '.
3424: 'onChange="javascript:changeOneScore(\''.$part.'\',\''.$student.'\')" >'."\n";
1.485 albertel 3425: $result.= (($status eq 'excused') ? '<option> </option><option selected="selected" value="excused">'.&mt('excused').'</option>'
3426: : '<option selected="selected"> </option><option value="excused">'.&mt('excused').'</option>')."\n";
3427: $result.='<option value="reset status">'.&mt('reset status').'</option>';
1.126 ng 3428: $result.="</select> </td>\n";
1.122 ng 3429: } else {
3430: $result.='<input type="hidden" name="'.
3431: 'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
3432: "\n";
1.233 albertel 3433: $result.='<input type="text" name="'.
1.122 ng 3434: 'GD_'.$student.'_'.$part.'_'.$type.'" '.
3435: 'value="'.$score.'" size="4" /></td>'."\n";
1.41 ng 3436: }
3437: }
1.474 albertel 3438: $result.=&Apache::loncommon::end_data_table_row();
1.41 ng 3439: return $result;
1.38 ng 3440: }
3441:
1.44 ng 3442: #--- change scores for all the students in a section/class
3443: # record does not get update if unchanged
1.38 ng 3444: sub editgrades {
1.41 ng 3445: my ($request) = @_;
3446:
1.324 albertel 3447: my $symb=&get_symb($request);
1.433 banghart 3448: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.477 albertel 3449: my $title='<h2>'.&mt('Current Grade Status').'</h2>';
3450: $title.='<h4>'.&mt('<b>Current Resource: </b>[_1]',$env{'form.probTitle'}).'</h4>'."\n";
1.433 banghart 3451: $title.='<h4>'.&mt('<b>Section: </b>[_1]',$section_display).'</h4>'."\n";
1.126 ng 3452:
1.477 albertel 3453: my $result= &Apache::loncommon::start_data_table().
3454: &Apache::loncommon::start_data_table_header_row().
3455: '<th rowspan="2" valign="middle">'.&mt('No.').'</th>'.
3456: '<th rowspan="2" valign="middle">'.&nameUserString('header')."</th>\n";
1.43 ng 3457: my %scoreptr = (
3458: 'correct' =>'correct_by_override',
3459: 'incorrect'=>'incorrect_by_override',
3460: 'excused' =>'excused',
3461: 'ungraded' =>'ungraded_attempted',
3462: 'nothing' => '',
3463: );
1.257 albertel 3464: my ($classlist,undef,$fullname) = &getclasslist($env{'form.section'},'0');
1.34 ng 3465:
1.44 ng 3466: my (@partid);
3467: my %weight = ();
1.54 albertel 3468: my %columns = ();
1.44 ng 3469: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54 albertel 3470:
1.324 albertel 3471: my (@parts) = sort(&getpartlist($symb));
1.54 albertel 3472: my $header;
1.257 albertel 3473: while ($ctr < $env{'form.totalparts'}) {
3474: my $partid = $env{'form.partid_'.$ctr};
1.524 raeburn 3475: push(@partid,$partid);
1.257 albertel 3476: $weight{$partid} = $env{'form.weight_'.$partid};
1.44 ng 3477: $ctr++;
1.54 albertel 3478: }
1.324 albertel 3479: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.54 albertel 3480: foreach my $partid (@partid) {
1.478 albertel 3481: $header .= '<th align="center">'.&mt('Old Score').'</th>'.
3482: '<th align="center">'.&mt('New Score').'</th>';
1.54 albertel 3483: $columns{$partid}=2;
3484: foreach my $stores (@parts) {
3485: my ($part,$type) = &split_part_type($stores);
3486: if ($part !~ m/^\Q$partid\E/) { next;}
3487: if ($type eq 'awarded' || $type eq 'solved') { next; }
3488: my $display=&Apache::lonnet::metadata($url,$stores.'.display');
1.551 raeburn 3489: $display =~ s/\[Part: \Q$part\E\]//;
1.539 riegler 3490: my $narrowtext = &mt('Tries');
3491: $display =~ s/Number of Attempts/$narrowtext/;
3492: $header .= '<th align="center">'.&mt('Old').' '.$display.'</th>'.
3493: '<th align="center">'.&mt('New').' '.$display.'</th>';
1.54 albertel 3494: $columns{$partid}+=2;
3495: }
3496: }
3497: foreach my $partid (@partid) {
1.324 albertel 3498: my $display_part=&get_display_part($partid,$symb);
1.478 albertel 3499: $result .= '<th colspan="'.$columns{$partid}.'" align="center">'.
3500: &mt('Part: [_1] (Weight = [_2])',$display_part,$weight{$partid}).
3501: '</th>';
1.54 albertel 3502:
1.44 ng 3503: }
1.477 albertel 3504: $result .= &Apache::loncommon::end_data_table_header_row().
3505: &Apache::loncommon::start_data_table_header_row().
3506: $header.
3507: &Apache::loncommon::end_data_table_header_row();
3508: my @noupdate;
1.126 ng 3509: my ($updateCtr,$noupdateCtr) = (1,1);
1.257 albertel 3510: for ($i=0; $i<$env{'form.total'}; $i++) {
1.93 albertel 3511: my $line;
1.257 albertel 3512: my $user = $env{'form.ctr'.$i};
1.281 albertel 3513: my ($uname,$udom)=split(/:/,$user);
1.44 ng 3514: my %newrecord;
3515: my $updateflag = 0;
1.281 albertel 3516: $line .= '<td>'.&nameUserString(undef,$$fullname{$user},$uname,$udom).'</td>';
1.108 albertel 3517: my $usec=$classlist->{"$uname:$udom"}[5];
1.105 albertel 3518: if (!&canmodify($usec)) {
1.126 ng 3519: my $numcols=scalar(@partid)*4+2;
1.477 albertel 3520: push(@noupdate,
1.478 albertel 3521: $line."<td colspan=\"$numcols\"><span class=\"LC_warning\">".
3522: &mt('Not allowed to modify student')."</span></td></tr>");
1.105 albertel 3523: next;
3524: }
1.269 raeburn 3525: my %aggregate = ();
3526: my $aggregateflag = 0;
1.281 albertel 3527: $user=~s/:/_/; # colon doen't work in javascript for names
1.44 ng 3528: foreach (@partid) {
1.257 albertel 3529: my $old_aw = $env{'form.GD_'.$user.'_'.$_.'_awarded_s'};
1.54 albertel 3530: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
3531: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
1.257 albertel 3532: my $old_score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
3533: my $awarded = $env{'form.GD_'.$user.'_'.$_.'_awarded'};
1.54 albertel 3534: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
3535: my $partial = $awarded eq '' ? '' : $pcr;
1.44 ng 3536: my $score;
3537: if ($partial eq '') {
1.257 albertel 3538: $score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 3539: } elsif ($partial > 0) {
3540: $score = 'correct_by_override';
3541: } elsif ($partial == 0) {
3542: $score = 'incorrect_by_override';
3543: }
1.257 albertel 3544: my $dropMenu = $env{'form.GD_'.$user.'_'.$_.'_solved'};
1.125 ng 3545: $score = 'excused' if (($dropMenu eq 'excused') && ($score ne 'excused'));
3546:
1.292 albertel 3547: $newrecord{'resource.'.$_.'.regrader'}=
3548: "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 3549: if ($dropMenu eq 'reset status' &&
3550: $old_score ne '') { # ignore if no previous attempts => nothing to reset
1.299 albertel 3551: $newrecord{'resource.'.$_.'.tries'} = '';
1.125 ng 3552: $newrecord{'resource.'.$_.'.solved'} = '';
3553: $newrecord{'resource.'.$_.'.award'} = '';
1.299 albertel 3554: $newrecord{'resource.'.$_.'.awarded'} = '';
1.125 ng 3555: $updateflag = 1;
1.269 raeburn 3556: if ($env{'form.GD_'.$user.'_'.$_.'_aggtries'} > 0) {
3557: my $aggtries = $env{'form.GD_'.$user.'_'.$_.'_aggtries'};
3558: my $totaltries = $env{'form.GD_'.$user.'_'.$_.'_totaltries'};
3559: my $solvedstatus = $env{'form.GD_'.$user.'_'.$_.'_solved_s'};
3560: &decrement_aggs($symb,$_,\%aggregate,$aggtries,$totaltries,$solvedstatus);
3561: $aggregateflag = 1;
3562: }
1.139 albertel 3563: } elsif (!($old_part eq $partial && $old_score eq $score)) {
3564: $updateflag = 1;
3565: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
3566: $newrecord{'resource.'.$_.'.solved'} = $score;
3567: $rec_update++;
1.125 ng 3568: }
3569:
1.93 albertel 3570: $line .= '<td align="center">'.$old_aw.' </td>'.
1.44 ng 3571: '<td align="center">'.$awarded.
3572: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 3573:
1.54 albertel 3574:
3575: my $partid=$_;
3576: foreach my $stores (@parts) {
3577: my ($part,$type) = &split_part_type($stores);
3578: if ($part !~ m/^\Q$partid\E/) { next;}
3579: if ($type eq 'awarded' || $type eq 'solved') { next; }
1.257 albertel 3580: my $old_aw = $env{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
3581: my $awarded = $env{'form.GD_'.$user.'_'.$part.'_'.$type};
1.54 albertel 3582: if ($awarded ne '' && $awarded ne $old_aw) {
3583: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.257 albertel 3584: $newrecord{'resource.'.$part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.54 albertel 3585: $updateflag=1;
3586: }
1.93 albertel 3587: $line .= '<td align="center">'.$old_aw.' </td>'.
1.54 albertel 3588: '<td align="center">'.$awarded.' </td>';
3589: }
1.44 ng 3590: }
1.477 albertel 3591: $line.="\n";
1.301 albertel 3592:
3593: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3594: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3595:
1.44 ng 3596: if ($updateflag) {
3597: $count++;
1.257 albertel 3598: &Apache::lonnet::cstore(\%newrecord,$symb,$env{'request.course.id'},
1.89 albertel 3599: $udom,$uname);
1.301 albertel 3600:
3601: if (&Apache::bridgetask::in_queue('gradingqueue',$symb,$cdom,
3602: $cnum,$udom,$uname)) {
3603: # need to figure out if should be in queue.
3604: my %record =
3605: &Apache::lonnet::restore($symb,$env{'request.course.id'},
3606: $udom,$uname);
3607: my $all_graded = 1;
3608: my $none_graded = 1;
3609: foreach my $part (@parts) {
3610: if ( $record{'resource.'.$part.'.awarded'} eq '' ) {
3611: $all_graded = 0;
3612: } else {
3613: $none_graded = 0;
3614: }
3615: }
3616:
3617: if ($all_graded || $none_graded) {
3618: &Apache::bridgetask::remove_from_queue('gradingqueue',
3619: $symb,$cdom,$cnum,
3620: $udom,$uname);
3621: }
3622: }
3623:
1.477 albertel 3624: $result.=&Apache::loncommon::start_data_table_row().
3625: '<td align="right"> '.$updateCtr.' </td>'.$line.
3626: &Apache::loncommon::end_data_table_row();
1.126 ng 3627: $updateCtr++;
1.93 albertel 3628: } else {
1.477 albertel 3629: push(@noupdate,
3630: '<td align="right"> '.$noupdateCtr.' </td>'.$line);
1.126 ng 3631: $noupdateCtr++;
1.44 ng 3632: }
1.269 raeburn 3633: if ($aggregateflag) {
3634: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 3635: $cdom,$cnum);
1.269 raeburn 3636: }
1.93 albertel 3637: }
1.477 albertel 3638: if (@noupdate) {
1.126 ng 3639: # my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3;
3640: my $numcols=scalar(@partid)*4+2;
1.477 albertel 3641: $result .= &Apache::loncommon::start_data_table_row('LC_empty_row').
1.478 albertel 3642: '<td align="center" colspan="'.$numcols.'">'.
3643: &mt('No Changes Occurred For the Students Below').
3644: '</td>'.
1.477 albertel 3645: &Apache::loncommon::end_data_table_row();
3646: foreach my $line (@noupdate) {
3647: $result.=
3648: &Apache::loncommon::start_data_table_row().
3649: $line.
3650: &Apache::loncommon::end_data_table_row();
3651: }
1.44 ng 3652: }
1.477 albertel 3653: $result .= &Apache::loncommon::end_data_table().
3654: &show_grading_menu_form($symb);
1.478 albertel 3655: my $msg = '<p><b>'.
3656: &mt('Number of records updated = [_1] for [quant,_2,student].',
3657: $rec_update,$count).'</b><br />'.
3658: '<b>'.&mt('Total number of students = [_1]',$env{'form.total'}).
3659: '</b></p>';
1.44 ng 3660: return $title.$msg.$result;
1.5 albertel 3661: }
1.54 albertel 3662:
3663: sub split_part_type {
3664: my ($partstr) = @_;
3665: my ($temp,@allparts)=split(/_/,$partstr);
3666: my $type=pop(@allparts);
1.439 albertel 3667: my $part=join('_',@allparts);
1.54 albertel 3668: return ($part,$type);
3669: }
3670:
1.44 ng 3671: #------------- end of section for handling grading by section/class ---------
3672: #
3673: #----------------------------------------------------------------------------
3674:
1.5 albertel 3675:
1.44 ng 3676: #----------------------------------------------------------------------------
3677: #
3678: #-------------------------- Next few routines handles grading by csv upload
3679: #
3680: #--- Javascript to handle csv upload
1.27 albertel 3681: sub csvupload_javascript_reverse_associate {
1.573 bisitz 3682: my $error1=&mt('You need to specify the username or the student/employee ID');
1.246 albertel 3683: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3684: return(<<ENDPICK);
3685: function verify(vf) {
3686: var foundsomething=0;
3687: var founduname=0;
1.243 albertel 3688: var foundID=0;
1.27 albertel 3689: for (i=0;i<=vf.nfields.value;i++) {
3690: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3691: if (i==0 && tw!=0) { foundID=1; }
3692: if (i==1 && tw!=0) { founduname=1; }
3693: if (i!=0 && i!=1 && i!=2 && tw!=0) { foundsomething=1; }
1.27 albertel 3694: }
1.246 albertel 3695: if (founduname==0 && foundID==0) {
3696: alert('$error1');
3697: return;
1.27 albertel 3698: }
3699: if (foundsomething==0) {
1.246 albertel 3700: alert('$error2');
3701: return;
1.27 albertel 3702: }
3703: vf.submit();
3704: }
3705: function flip(vf,tf) {
3706: var nw=eval('vf.f'+tf+'.selectedIndex');
3707: var i;
3708: for (i=0;i<=vf.nfields.value;i++) {
3709: //can not pick the same destination field for both name and domain
3710: if (((i ==0)||(i ==1)) &&
3711: ((tf==0)||(tf==1)) &&
3712: (i!=tf) &&
3713: (eval('vf.f'+i+'.selectedIndex')==nw)) {
3714: eval('vf.f'+i+'.selectedIndex=0;')
3715: }
3716: }
3717: }
3718: ENDPICK
3719: }
3720:
3721: sub csvupload_javascript_forward_associate {
1.573 bisitz 3722: my $error1=&mt('You need to specify the username or the student/employee ID');
1.246 albertel 3723: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3724: return(<<ENDPICK);
3725: function verify(vf) {
3726: var foundsomething=0;
3727: var founduname=0;
1.243 albertel 3728: var foundID=0;
1.27 albertel 3729: for (i=0;i<=vf.nfields.value;i++) {
3730: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3731: if (tw==1) { foundID=1; }
3732: if (tw==2) { founduname=1; }
3733: if (tw>3) { foundsomething=1; }
1.27 albertel 3734: }
1.246 albertel 3735: if (founduname==0 && foundID==0) {
3736: alert('$error1');
3737: return;
1.27 albertel 3738: }
3739: if (foundsomething==0) {
1.246 albertel 3740: alert('$error2');
3741: return;
1.27 albertel 3742: }
3743: vf.submit();
3744: }
3745: function flip(vf,tf) {
3746: var nw=eval('vf.f'+tf+'.selectedIndex');
3747: var i;
3748: //can not pick the same destination field twice
3749: for (i=0;i<=vf.nfields.value;i++) {
3750: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
3751: eval('vf.f'+i+'.selectedIndex=0;')
3752: }
3753: }
3754: }
3755: ENDPICK
3756: }
3757:
1.26 albertel 3758: sub csvuploadmap_header {
1.324 albertel 3759: my ($request,$symb,$datatoken,$distotal)= @_;
1.41 ng 3760: my $javascript;
1.257 albertel 3761: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3762: $javascript=&csvupload_javascript_reverse_associate();
3763: } else {
3764: $javascript=&csvupload_javascript_forward_associate();
3765: }
1.45 ng 3766:
1.324 albertel 3767: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.257 albertel 3768: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1.245 albertel 3769: my $ignore=&mt('Ignore First Line');
1.418 albertel 3770: $symb = &Apache::lonenc::check_encrypt($symb);
1.41 ng 3771: $request->print(<<ENDPICK);
1.26 albertel 3772: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.398 albertel 3773: <h3><span class="LC_info">Uploading Class Grades</span></h3>
1.45 ng 3774: $result
1.326 albertel 3775: <hr />
1.26 albertel 3776: <h3>Identify fields</h3>
3777: Total number of records found in file: $distotal <hr />
3778: Enter as many fields as you can. The system will inform you and bring you back
3779: to this page if the data selected is insufficient to run your class.<hr />
3780: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1.245 albertel 3781: <label><input type="checkbox" name="noFirstLine" $checked />$ignore</label>
1.26 albertel 3782: <input type="hidden" name="associate" value="" />
3783: <input type="hidden" name="phase" value="three" />
3784: <input type="hidden" name="datatoken" value="$datatoken" />
1.257 albertel 3785: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
3786: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
1.26 albertel 3787: <input type="hidden" name="upfile_associate"
1.257 albertel 3788: value="$env{'form.upfile_associate'}" />
1.26 albertel 3789: <input type="hidden" name="symb" value="$symb" />
1.257 albertel 3790: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
3791: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
1.246 albertel 3792: <input type="hidden" name="command" value="csvuploadoptions" />
1.26 albertel 3793: <hr />
3794: <script type="text/javascript" language="Javascript">
3795: $javascript
3796: </script>
3797: ENDPICK
1.118 ng 3798: return '';
1.26 albertel 3799:
3800: }
3801:
3802: sub csvupload_fields {
1.324 albertel 3803: my ($symb) = @_;
3804: my (@parts) = &getpartlist($symb);
1.556 weissno 3805: my @fields=(['ID','Student/Employee ID'],
1.243 albertel 3806: ['username','Student Username'],
3807: ['domain','Student Domain']);
1.324 albertel 3808: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.41 ng 3809: foreach my $part (sort(@parts)) {
3810: my @datum;
3811: my $display=&Apache::lonnet::metadata($url,$part.'.display');
3812: my $name=$part;
3813: if (!$display) { $display = $name; }
3814: @datum=($name,$display);
1.244 albertel 3815: if ($name=~/^stores_(.*)_awarded/) {
3816: push(@fields,['stores_'.$1.'_points',"Points [Part: $1]"]);
3817: }
1.41 ng 3818: push(@fields,\@datum);
3819: }
3820: return (@fields);
1.26 albertel 3821: }
3822:
3823: sub csvuploadmap_footer {
1.41 ng 3824: my ($request,$i,$keyfields) =@_;
3825: $request->print(<<ENDPICK);
1.26 albertel 3826: </table>
3827: <input type="hidden" name="nfields" value="$i" />
3828: <input type="hidden" name="keyfields" value="$keyfields" />
3829: <input type="button" onClick="javascript:verify(this.form)" value="Assign Grades" /><br />
3830: </form>
3831: ENDPICK
3832: }
3833:
1.283 albertel 3834: sub checkforfile_js {
1.539 riegler 3835: my $alertmsg = &mt('Please use the browse button to select a file from your local directory.');
1.86 ng 3836: my $result =<<CSVFORMJS;
3837: <script type="text/javascript" language="javascript">
3838: function checkUpload(formname) {
3839: if (formname.upfile.value == "") {
1.539 riegler 3840: alert("$alertmsg");
1.86 ng 3841: return false;
3842: }
3843: formname.submit();
3844: }
3845: </script>
3846: CSVFORMJS
1.283 albertel 3847: return $result;
3848: }
3849:
3850: sub upcsvScores_form {
3851: my ($request) = shift;
1.324 albertel 3852: my ($symb)=&get_symb($request);
1.283 albertel 3853: if (!$symb) {return '';}
3854: my $result=&checkforfile_js();
1.257 albertel 3855: $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
1.324 albertel 3856: my ($table) = &showResourceInfo($symb,$env{'form.probTitle'});
1.118 ng 3857: $result.=$table;
1.326 albertel 3858: $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
3859: $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
1.538 schulted 3860: $result.=' <b>'.&mt('Specify a file containing the class scores for current resource.').
3861: '</b></td></tr>'."\n";
1.86 ng 3862: $result.='<tr bgcolor=#ffffe6><td>'."\n";
1.370 www 3863: my $upload=&mt("Upload Scores");
1.86 ng 3864: my $upfile_select=&Apache::loncommon::upfile_select_html();
1.245 albertel 3865: my $ignore=&mt('Ignore First Line');
1.418 albertel 3866: $symb = &Apache::lonenc::check_encrypt($symb);
1.86 ng 3867: $result.=<<ENDUPFORM;
1.106 albertel 3868: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.86 ng 3869: <input type="hidden" name="symb" value="$symb" />
3870: <input type="hidden" name="command" value="csvuploadmap" />
1.257 albertel 3871: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
3872: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
1.86 ng 3873: $upfile_select
1.370 www 3874: <br /><input type="button" onClick="javascript:checkUpload(this.form);" value="$upload" />
1.283 albertel 3875: <label><input type="checkbox" name="noFirstLine" />$ignore</label>
1.86 ng 3876: </form>
3877: ENDUPFORM
1.370 www 3878: $result.=&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
3879: &mt("How do I create a CSV file from a spreadsheet"))
3880: .'</td></tr></table>'."\n";
1.86 ng 3881: $result.='</td></tr></table><br /><br />'."\n";
1.324 albertel 3882: $result.=&show_grading_menu_form($symb);
1.86 ng 3883: return $result;
3884: }
3885:
3886:
1.26 albertel 3887: sub csvuploadmap {
1.41 ng 3888: my ($request)= @_;
1.324 albertel 3889: my ($symb)=&get_symb($request);
1.41 ng 3890: if (!$symb) {return '';}
1.72 ng 3891:
1.41 ng 3892: my $datatoken;
1.257 albertel 3893: if (!$env{'form.datatoken'}) {
1.41 ng 3894: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 3895: } else {
1.257 albertel 3896: $datatoken=$env{'form.datatoken'};
1.41 ng 3897: &Apache::loncommon::load_tmp_file($request);
1.26 albertel 3898: }
1.41 ng 3899: my @records=&Apache::loncommon::upfile_record_sep();
1.257 albertel 3900: if ($env{'form.noFirstLine'}) { shift(@records); }
1.324 albertel 3901: &csvuploadmap_header($request,$symb,$datatoken,$#records+1);
1.41 ng 3902: my ($i,$keyfields);
3903: if (@records) {
1.324 albertel 3904: my @fields=&csvupload_fields($symb);
1.45 ng 3905:
1.257 albertel 3906: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3907: &Apache::loncommon::csv_print_samples($request,\@records);
3908: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
3909: \@fields);
3910: foreach (@fields) { $keyfields.=$_->[0].','; }
3911: chop($keyfields);
3912: } else {
3913: unshift(@fields,['none','']);
3914: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
3915: \@fields);
1.311 banghart 3916: foreach my $rec (@records) {
3917: my %temp = &Apache::loncommon::record_sep($rec);
3918: if (%temp) {
3919: $keyfields=join(',',sort(keys(%temp)));
3920: last;
3921: }
3922: }
1.41 ng 3923: }
3924: }
3925: &csvuploadmap_footer($request,$i,$keyfields);
1.324 albertel 3926: $request->print(&show_grading_menu_form($symb));
1.72 ng 3927:
1.41 ng 3928: return '';
1.27 albertel 3929: }
3930:
1.246 albertel 3931: sub csvuploadoptions {
1.41 ng 3932: my ($request)= @_;
1.324 albertel 3933: my ($symb)=&get_symb($request);
1.257 albertel 3934: my $checked=(($env{'form.noFirstLine'})?'1':'0');
1.246 albertel 3935: my $ignore=&mt('Ignore First Line');
3936: $request->print(<<ENDPICK);
3937: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.398 albertel 3938: <h3><span class="LC_info">Uploading Class Grade Options</span></h3>
1.246 albertel 3939: <input type="hidden" name="command" value="csvuploadassign" />
1.302 albertel 3940: <!--
1.246 albertel 3941: <p>
3942: <label>
3943: <input type="checkbox" name="show_full_results" />
3944: Show a table of all changes
3945: </label>
3946: </p>
1.302 albertel 3947: -->
1.246 albertel 3948: <p>
3949: <label>
3950: <input type="checkbox" name="overwite_scores" checked="checked" />
3951: Overwrite any existing score
3952: </label>
3953: </p>
3954: ENDPICK
3955: my %fields=&get_fields();
3956: if (!defined($fields{'domain'})) {
1.257 albertel 3957: my $domform = &Apache::loncommon::select_dom_form($env{'request.role.domain'},'default_domain');
1.246 albertel 3958: $request->print("\n<p> Users are in domain: ".$domform."</p>\n");
3959: }
1.257 albertel 3960: foreach my $key (sort(keys(%env))) {
1.246 albertel 3961: if ($key !~ /^form\.(.*)$/) { next; }
3962: my $cleankey=$1;
3963: if ($cleankey eq 'command') { next; }
3964: $request->print('<input type="hidden" name="'.$cleankey.
1.257 albertel 3965: '" value="'.$env{$key}.'" />'."\n");
1.246 albertel 3966: }
3967: # FIXME do a check for any duplicated user ids...
3968: # FIXME do a check for any invalid user ids?...
1.290 albertel 3969: $request->print('<input type="submit" value="Assign Grades" /><br />
3970: <hr /></form>'."\n");
1.324 albertel 3971: $request->print(&show_grading_menu_form($symb));
1.246 albertel 3972: return '';
3973: }
3974:
3975: sub get_fields {
3976: my %fields;
1.257 albertel 3977: my @keyfields = split(/\,/,$env{'form.keyfields'});
3978: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
3979: if ($env{'form.upfile_associate'} eq 'reverse') {
3980: if ($env{'form.f'.$i} ne 'none') {
3981: $fields{$keyfields[$i]}=$env{'form.f'.$i};
1.41 ng 3982: }
3983: } else {
1.257 albertel 3984: if ($env{'form.f'.$i} ne 'none') {
3985: $fields{$env{'form.f'.$i}}=$keyfields[$i];
1.41 ng 3986: }
3987: }
1.27 albertel 3988: }
1.246 albertel 3989: return %fields;
3990: }
3991:
3992: sub csvuploadassign {
3993: my ($request)= @_;
1.324 albertel 3994: my ($symb)=&get_symb($request);
1.246 albertel 3995: if (!$symb) {return '';}
1.345 bowersj2 3996: my $error_msg = '';
1.246 albertel 3997: &Apache::loncommon::load_tmp_file($request);
3998: my @gradedata = &Apache::loncommon::upfile_record_sep();
1.257 albertel 3999: if ($env{'form.noFirstLine'}) { shift(@gradedata); }
1.246 albertel 4000: my %fields=&get_fields();
1.41 ng 4001: $request->print('<h3>Assigning Grades</h3>');
1.257 albertel 4002: my $courseid=$env{'request.course.id'};
1.97 albertel 4003: my ($classlist) = &getclasslist('all',0);
1.106 albertel 4004: my @notallowed;
1.41 ng 4005: my @skipped;
4006: my $countdone=0;
4007: foreach my $grade (@gradedata) {
4008: my %entries=&Apache::loncommon::record_sep($grade);
1.246 albertel 4009: my $domain;
4010: if ($entries{$fields{'domain'}}) {
4011: $domain=$entries{$fields{'domain'}};
4012: } else {
1.257 albertel 4013: $domain=$env{'form.default_domain'};
1.246 albertel 4014: }
1.243 albertel 4015: $domain=~s/\s//g;
1.41 ng 4016: my $username=$entries{$fields{'username'}};
1.160 albertel 4017: $username=~s/\s//g;
1.243 albertel 4018: if (!$username) {
4019: my $id=$entries{$fields{'ID'}};
1.247 albertel 4020: $id=~s/\s//g;
1.243 albertel 4021: my %ids=&Apache::lonnet::idget($domain,$id);
4022: $username=$ids{$id};
4023: }
1.41 ng 4024: if (!exists($$classlist{"$username:$domain"})) {
1.247 albertel 4025: my $id=$entries{$fields{'ID'}};
4026: $id=~s/\s//g;
4027: if ($id) {
4028: push(@skipped,"$id:$domain");
4029: } else {
4030: push(@skipped,"$username:$domain");
4031: }
1.41 ng 4032: next;
4033: }
1.108 albertel 4034: my $usec=$classlist->{"$username:$domain"}[5];
1.106 albertel 4035: if (!&canmodify($usec)) {
4036: push(@notallowed,"$username:$domain");
4037: next;
4038: }
1.244 albertel 4039: my %points;
1.41 ng 4040: my %grades;
4041: foreach my $dest (keys(%fields)) {
1.244 albertel 4042: if ($dest eq 'ID' || $dest eq 'username' ||
4043: $dest eq 'domain') { next; }
4044: if ($entries{$fields{$dest}} =~ /^\s*$/) { next; }
4045: if ($dest=~/stores_(.*)_points/) {
4046: my $part=$1;
4047: my $wgt =&Apache::lonnet::EXT('resource.'.$part.'.weight',
4048: $symb,$domain,$username);
1.345 bowersj2 4049: if ($wgt) {
4050: $entries{$fields{$dest}}=~s/\s//g;
4051: my $pcr=$entries{$fields{$dest}} / $wgt;
1.463 albertel 4052: my $award=($pcr == 0) ? 'incorrect_by_override'
4053: : 'correct_by_override';
1.345 bowersj2 4054: $grades{"resource.$part.awarded"}=$pcr;
4055: $grades{"resource.$part.solved"}=$award;
4056: $points{$part}=1;
4057: } else {
4058: $error_msg = "<br />" .
4059: &mt("Some point values were assigned"
4060: ." for problems with a weight "
4061: ."of zero. These values were "
4062: ."ignored.");
4063: }
1.244 albertel 4064: } else {
4065: if ($dest=~/stores_(.*)_awarded/) { if ($points{$1}) {next;} }
4066: if ($dest=~/stores_(.*)_solved/) { if ($points{$1}) {next;} }
4067: my $store_key=$dest;
4068: $store_key=~s/^stores/resource/;
4069: $store_key=~s/_/\./g;
4070: $grades{$store_key}=$entries{$fields{$dest}};
4071: }
1.41 ng 4072: }
1.508 www 4073: if (! %grades) {
4074: push(@skipped,&mt("[_1]: no data to save","$username:$domain"));
4075: } else {
4076: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
4077: my $result=&Apache::lonnet::cstore(\%grades,$symb,
1.302 albertel 4078: $env{'request.course.id'},
4079: $domain,$username);
1.508 www 4080: if ($result eq 'ok') {
4081: $request->print('.');
4082: } else {
4083: $request->print("<p><span class=\"LC_error\">".
4084: &mt("Failed to save data for student [_1]. Message when trying to save was: [_2]",
4085: "$username:$domain",$result)."</span></p>");
4086: }
4087: $request->rflush();
4088: $countdone++;
4089: }
1.41 ng 4090: }
1.570 www 4091: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt("Saved scores for [quant,_1,student]",$countdone),$countdone==0));
1.41 ng 4092: if (@skipped) {
1.571 www 4093: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('No scores stored for the following username(s):'),1).'<br />');
4094: $request->print(join(', ',@skipped));
1.106 albertel 4095: }
4096: if (@notallowed) {
1.571 www 4097: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('Modification of scores not allowed for the following username(s):'),1).'<br />');
4098: $request->print(join(', ',@notallowed));
1.41 ng 4099: }
1.106 albertel 4100: $request->print("<br />\n");
1.324 albertel 4101: $request->print(&show_grading_menu_form($symb));
1.345 bowersj2 4102: return $error_msg;
1.26 albertel 4103: }
1.44 ng 4104: #------------- end of section for handling csv file upload ---------
4105: #
4106: #-------------------------------------------------------------------
4107: #
1.122 ng 4108: #-------------- Next few routines handle grading by page/sequence
1.72 ng 4109: #
4110: #--- Select a page/sequence and a student to grade
1.68 ng 4111: sub pickStudentPage {
4112: my ($request) = shift;
4113:
1.539 riegler 4114: my $alertmsg = &mt('Please select the student you wish to grade.');
1.68 ng 4115: $request->print(<<LISTJAVASCRIPT);
4116: <script type="text/javascript" language="javascript">
4117:
4118: function checkPickOne(formname) {
1.76 ng 4119: if (radioSelection(formname.student) == null) {
1.539 riegler 4120: alert("$alertmsg");
1.68 ng 4121: return;
4122: }
1.125 ng 4123: ptr = pullDownSelection(formname.selectpage);
4124: formname.page.value = formname["page"+ptr].value;
4125: formname.title.value = formname["title"+ptr].value;
1.68 ng 4126: formname.submit();
4127: }
4128:
4129: </script>
4130: LISTJAVASCRIPT
1.118 ng 4131: &commonJSfunctions($request);
1.324 albertel 4132: my ($symb) = &get_symb($request);
1.257 albertel 4133: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4134: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4135: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.68 ng 4136:
1.398 albertel 4137: my $result='<h3><span class="LC_info"> '.
1.485 albertel 4138: &mt('Manual Grading by Page or Sequence').'</span></h3>';
1.68 ng 4139:
1.80 ng 4140: $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
1.423 albertel 4141: my ($titles,$symbx) = &getSymbMap();
1.137 albertel 4142: my ($curpage) =&Apache::lonnet::decode_symb($symb);
4143: # my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb);
4144: # my $type=($curpage =~ /\.(page|sequence)/);
1.485 albertel 4145: my $select = '<select name="selectpage">'."\n";
1.70 ng 4146: my $ctr=0;
1.68 ng 4147: foreach (@$titles) {
4148: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.485 albertel 4149: $select.='<option value="'.$ctr.'" '.
1.401 albertel 4150: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.71 ng 4151: '>'.$showtitle.'</option>'."\n";
1.70 ng 4152: $ctr++;
1.68 ng 4153: }
1.485 albertel 4154: $select.= '</select>';
1.539 riegler 4155: $result.=' <b>'.&mt('Problems from').':</b> '.$select."<br />\n";
1.485 albertel 4156:
1.70 ng 4157: $ctr=0;
4158: foreach (@$titles) {
4159: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
4160: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
4161: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
4162: $ctr++;
4163: }
1.72 ng 4164: $result.='<input type="hidden" name="page" />'."\n".
4165: '<input type="hidden" name="title" />'."\n";
1.68 ng 4166:
1.485 albertel 4167: my $options =
4168: '<label><input type="radio" name="vProb" value="no" checked="checked" /> '.&mt('no').' </label>'."\n".
4169: '<label><input type="radio" name="vProb" value="yes" /> '.&mt('yes').' </label>'."<br />\n";
1.539 riegler 4170: $result.=' <b>'.&mt('View Problem Text').': </b>'.$options;
1.485 albertel 4171:
4172: $options =
4173: '<label><input type="radio" name="lastSub" value="none" /> '.&mt('none').' </label>'."\n".
4174: '<label><input type="radio" name="lastSub" value="datesub" checked="checked" /> '.&mt('by dates and submissions').'</label>'."\n".
4175: '<label><input type="radio" name="lastSub" value="all" /> '.&mt('all details').' </label>'."\n";
1.539 riegler 4176: $result.=' <b>'.&mt('Submissions').': </b>'.$options;
1.432 banghart 4177:
4178: $result.=&build_section_inputs();
1.442 banghart 4179: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
4180: $result.='<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.72 ng 4181: '<input type="hidden" name="command" value="displayPage" />'."\n".
1.418 albertel 4182: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 4183: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."<br />\n";
1.72 ng 4184:
1.539 riegler 4185: $result.=' <b>'.&mt('Use CODE').': </b> <input type="text" name="CODE" value="" /> <br />'."\n";
1.382 albertel 4186:
1.80 ng 4187: $result.=' <input type="button" '.
1.539 riegler 4188: 'onClick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /><br />'."\n";
1.72 ng 4189:
1.68 ng 4190: $request->print($result);
4191:
1.485 albertel 4192: my $studentTable.=' <b>'.&mt('Select a student you wish to grade and then click on the Next button.').'</b><br />'.
1.484 albertel 4193: &Apache::loncommon::start_data_table().
4194: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 4195: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 4196: '<th>'.&nameUserString('header').'</th>'.
1.485 albertel 4197: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 4198: '<th>'.&nameUserString('header').'</th>'.
4199: &Apache::loncommon::end_data_table_header_row();
1.68 ng 4200:
1.76 ng 4201: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.68 ng 4202: my $ptr = 1;
1.294 albertel 4203: foreach my $student (sort
4204: {
4205: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
4206: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
4207: }
4208: return $a cmp $b;
4209: } (keys(%$fullname))) {
1.68 ng 4210: my ($uname,$udom) = split(/:/,$student);
1.484 albertel 4211: $studentTable.=($ptr%2==1 ? &Apache::loncommon::start_data_table_row()
4212: : '</td>');
1.126 ng 4213: $studentTable.='<td align="right">'.$ptr.' </td>';
1.288 albertel 4214: $studentTable.='<td> <label><input type="radio" name="student" value="'.$student.'" /> '
4215: .&nameUserString(undef,$$fullname{$student},$uname,$udom)."</label>\n";
1.484 albertel 4216: $studentTable.=
4217: ($ptr%2 == 0 ? '</td>'.&Apache::loncommon::end_data_table_row()
4218: : '');
1.68 ng 4219: $ptr++;
4220: }
1.484 albertel 4221: if ($ptr%2 == 0) {
4222: $studentTable.='</td><td> </td><td> </td>'.
4223: &Apache::loncommon::end_data_table_row();
4224: }
4225: $studentTable.=&Apache::loncommon::end_data_table()."\n";
1.126 ng 4226: $studentTable.='<input type="button" '.
1.539 riegler 4227: 'onClick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /></form>'."\n";
1.68 ng 4228:
1.324 albertel 4229: $studentTable.=&show_grading_menu_form($symb);
1.68 ng 4230: $request->print($studentTable);
4231:
4232: return '';
4233: }
4234:
4235: sub getSymbMap {
1.132 bowersj2 4236: my $navmap = Apache::lonnavmaps::navmap->new();
1.68 ng 4237:
4238: my %symbx = ();
4239: my @titles = ();
1.117 bowersj2 4240: my $minder = 0;
4241:
4242: # Gather every sequence that has problems.
1.240 albertel 4243: my @sequences = $navmap->retrieveResources(undef, sub { shift->is_map(); },
4244: 1,0,1);
1.117 bowersj2 4245: for my $sequence ($navmap->getById('0.0'), @sequences) {
1.241 albertel 4246: if ($navmap->hasResource($sequence, sub { shift->is_problem(); }, 0) ) {
1.381 albertel 4247: my $title = $minder.'.'.
4248: &HTML::Entities::encode($sequence->compTitle(),'"\'&');
4249: push(@titles, $title); # minder in case two titles are identical
4250: $symbx{$title} = &HTML::Entities::encode($sequence->symb(),'"\'&');
1.117 bowersj2 4251: $minder++;
1.241 albertel 4252: }
1.68 ng 4253: }
4254: return \@titles,\%symbx;
4255: }
4256:
1.72 ng 4257: #
4258: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68 ng 4259: sub displayPage {
4260: my ($request) = shift;
4261:
1.324 albertel 4262: my ($symb) = &get_symb($request);
1.257 albertel 4263: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4264: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4265: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
4266: my $pageTitle = $env{'form.page'};
1.103 albertel 4267: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 4268: my ($uname,$udom) = split(/:/,$env{'form.student'});
4269: my $usec=$classlist->{$env{'form.student'}}[5];
1.168 albertel 4270:
4271: #need to make sure we have the correct data for later EXT calls,
4272: #thus invalidate the cache
4273: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 4274: $env{'course.'.$env{'request.course.id'}.'.num'},
4275: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 4276: &Apache::lonnet::clear_EXT_cache_status();
4277:
1.103 albertel 4278: if (!&canview($usec)) {
1.485 albertel 4279: $request->print('<span class="LC_warning">'.&mt('Unable to view requested student. ([_1])',$env{'form.student'}).'</span>');
1.324 albertel 4280: $request->print(&show_grading_menu_form($symb));
1.103 albertel 4281: return;
4282: }
1.398 albertel 4283: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.485 albertel 4284: $result.='<h3> '.&mt('Student: [_1]',&nameUserString(undef,$$fullname{$env{'form.student'}},$uname,$udom)).
1.129 ng 4285: '</h3>'."\n";
1.500 albertel 4286: $env{'form.CODE'} = uc($env{'form.CODE'});
1.501 foxr 4287: if (&Apache::lonnet::validCODE(uc($env{'form.CODE'}))) {
1.485 albertel 4288: $result.='<h3> '.&mt('CODE: [_1]',$env{'form.CODE'}).'</h3>'."\n";
1.382 albertel 4289: } else {
4290: delete($env{'form.CODE'});
4291: }
1.71 ng 4292: &sub_page_js($request);
4293: $request->print($result);
4294:
1.132 bowersj2 4295: my $navmap = Apache::lonnavmaps::navmap->new();
1.257 albertel 4296: my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($env{'form.page'});
1.68 ng 4297: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 4298: if (!$map) {
1.485 albertel 4299: $request->print('<span class="LC_warning">'.&mt('Unable to view requested sequence. ([_1])',$resUrl).'</span>');
1.324 albertel 4300: $request->print(&show_grading_menu_form($symb));
1.288 albertel 4301: return;
4302: }
1.68 ng 4303: my $iterator = $navmap->getIterator($map->map_start(),
4304: $map->map_finish());
4305:
1.71 ng 4306: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72 ng 4307: '<input type="hidden" name="command" value="gradeByPage" />'."\n".
1.257 albertel 4308: '<input type="hidden" name="fullname" value="'.$$fullname{$env{'form.student'}}.'" />'."\n".
4309: '<input type="hidden" name="student" value="'.$env{'form.student'}.'" />'."\n".
1.72 ng 4310: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
1.257 albertel 4311: '<input type="hidden" name="title" value="'.$env{'form.title'}.'" />'."\n".
1.418 albertel 4312: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.125 ng 4313: '<input type="hidden" name="overRideScore" value="no" />'."\n".
1.257 albertel 4314: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n";
1.71 ng 4315:
1.382 albertel 4316: if (defined($env{'form.CODE'})) {
4317: $studentTable.=
4318: '<input type="hidden" name="CODE" value="'.$env{'form.CODE'}.'" />'."\n";
4319: }
1.381 albertel 4320: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 4321: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 4322:
1.485 albertel 4323: $studentTable.=' '.&mt('<b>Note:</b> Problems graded correct by the computer are marked with a [_1] symbol.',$checkIcon)."\n".
1.484 albertel 4324: &Apache::loncommon::start_data_table().
4325: &Apache::loncommon::start_data_table_header_row().
4326: '<th align="center"> Prob. </th>'.
1.485 albertel 4327: '<th> '.($env{'form.vProb'} eq 'no' ? &mt('Title') : &mt('Problem Text')).'/'.&mt('Grade').'</th>'.
1.484 albertel 4328: &Apache::loncommon::end_data_table_header_row();
1.71 ng 4329:
1.329 albertel 4330: &Apache::lonxml::clear_problem_counter();
1.196 albertel 4331: my ($depth,$question,$prob) = (1,1,1);
1.68 ng 4332: $iterator->next(); # skip the first BEGIN_MAP
4333: my $curRes = $iterator->next(); # for "current resource"
1.101 albertel 4334: while ($depth > 0) {
1.68 ng 4335: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4336: if($curRes == $iterator->END_MAP) { $depth--; }
1.68 ng 4337:
1.385 albertel 4338: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4339: my $parts = $curRes->parts();
1.68 ng 4340: my $title = $curRes->compTitle();
1.71 ng 4341: my $symbx = $curRes->symb();
1.484 albertel 4342: $studentTable.=
4343: &Apache::loncommon::start_data_table_row().
4344: '<td align="center" valign="top" >'.$prob.
1.485 albertel 4345: (scalar(@{$parts}) == 1 ? ''
4346: : '<br />('.&mt('[_1] parts)',
4347: scalar(@{$parts}))
4348: ).
4349: '</td>';
1.71 ng 4350: $studentTable.='<td valign="top">';
1.382 albertel 4351: my %form = ('CODE' => $env{'form.CODE'},);
1.257 albertel 4352: if ($env{'form.vProb'} eq 'yes' ) {
1.144 albertel 4353: $studentTable.=&show_problem($request,$symbx,$uname,$udom,1,
1.383 albertel 4354: undef,'both',\%form);
1.71 ng 4355: } else {
1.382 albertel 4356: my $companswer = &Apache::loncommon::get_student_answers($symbx,$uname,$udom,$env{'request.course.id'},%form);
1.80 ng 4357: $companswer =~ s|<form(.*?)>||g;
4358: $companswer =~ s|</form>||g;
1.71 ng 4359: # while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
1.116 ng 4360: # $companswer =~ s/$1/ /ms;
1.326 albertel 4361: # $request->print('match='.$1."<br />\n");
1.71 ng 4362: # }
1.116 ng 4363: # $companswer =~ s|<table border=\"1\">|<table border=\"0\">|g;
1.539 riegler 4364: $studentTable.=' <b>'.$title.'</b> <br /> <b>'.&mt('Correct answer').':</b><br />'.$companswer;
1.71 ng 4365: }
4366:
1.257 albertel 4367: my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
1.125 ng 4368:
1.257 albertel 4369: if ($env{'form.lastSub'} eq 'datesub') {
1.71 ng 4370: if ($record{'version'} eq '') {
1.485 albertel 4371: $studentTable.='<br /> <span class="LC_warning">'.&mt('No recorded submission for this problem.').'</span><br />';
1.71 ng 4372: } else {
1.116 ng 4373: my %responseType = ();
4374: foreach my $partid (@{$parts}) {
1.147 albertel 4375: my @responseIds =$curRes->responseIds($partid);
4376: my @responseType =$curRes->responseType($partid);
4377: my %responseIds;
4378: for (my $i=0;$i<=$#responseIds;$i++) {
4379: $responseIds{$responseIds[$i]}=$responseType[$i];
4380: }
4381: $responseType{$partid} = \%responseIds;
1.116 ng 4382: }
1.148 albertel 4383: $studentTable.= &displaySubByDates($symbx,\%record,$parts,\%responseType,$checkIcon,$uname,$udom);
1.147 albertel 4384:
1.71 ng 4385: }
1.257 albertel 4386: } elsif ($env{'form.lastSub'} eq 'all') {
4387: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.71 ng 4388: $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
1.257 albertel 4389: $env{'request.course.id'},
1.71 ng 4390: '','.submission');
4391:
4392: }
1.103 albertel 4393: if (&canmodify($usec)) {
4394: foreach my $partid (@{$parts}) {
4395: $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
4396: $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
4397: $question++;
4398: }
1.196 albertel 4399: $prob++;
1.71 ng 4400: }
4401: $studentTable.='</td></tr>';
1.68 ng 4402:
1.103 albertel 4403: }
1.68 ng 4404: $curRes = $iterator->next();
4405: }
4406:
1.485 albertel 4407: $studentTable.='</table>'."\n".
4408: '<input type="button" value="'.&mt('Save').'" '.
1.381 albertel 4409: 'onClick="javascript:checkSubmitPage(this.form,'.$question.');" />'.
1.71 ng 4410: '</form>'."\n";
1.324 albertel 4411: $studentTable.=&show_grading_menu_form($symb);
1.71 ng 4412: $request->print($studentTable);
4413:
4414: return '';
1.119 ng 4415: }
4416:
4417: sub displaySubByDates {
1.148 albertel 4418: my ($symb,$record,$parts,$responseType,$checkIcon,$uname,$udom) = @_;
1.224 albertel 4419: my $isCODE=0;
1.335 albertel 4420: my $isTask = ($symb =~/\.task$/);
1.224 albertel 4421: if (exists($record->{'resource.CODE'})) { $isCODE=1; }
1.467 albertel 4422: my $studentTable=&Apache::loncommon::start_data_table().
4423: &Apache::loncommon::start_data_table_header_row().
4424: '<th>'.&mt('Date/Time').'</th>'.
4425: ($isCODE?'<th>'.&mt('CODE').'</th>':'').
4426: '<th>'.&mt('Submission').'</th>'.
4427: '<th>'.&mt('Status').'</th>'.
4428: &Apache::loncommon::end_data_table_header_row();
1.119 ng 4429: my ($version);
4430: my %mark;
1.148 albertel 4431: my %orders;
1.119 ng 4432: $mark{'correct_by_student'} = $checkIcon;
1.147 albertel 4433: if (!exists($$record{'1:timestamp'})) {
1.539 riegler 4434: return '<br /> <span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br />';
1.147 albertel 4435: }
1.335 albertel 4436:
4437: my $interaction;
1.525 raeburn 4438: my $no_increment = 1;
1.119 ng 4439: for ($version=1;$version<=$$record{'version'};$version++) {
1.467 albertel 4440: my $timestamp =
4441: &Apache::lonlocal::locallocaltime($$record{$version.':timestamp'});
1.335 albertel 4442: if (exists($$record{$version.':resource.0.version'})) {
4443: $interaction = $$record{$version.':resource.0.version'};
4444: }
4445:
4446: my $where = ($isTask ? "$version:resource.$interaction"
4447: : "$version:resource");
1.467 albertel 4448: $studentTable.=&Apache::loncommon::start_data_table_row().
4449: '<td>'.$timestamp.'</td>';
1.224 albertel 4450: if ($isCODE) {
4451: $studentTable.='<td>'.$record->{$version.':resource.CODE'}.'</td>';
4452: }
1.119 ng 4453: my @versionKeys = split(/\:/,$$record{$version.':keys'});
4454: my @displaySub = ();
4455: foreach my $partid (@{$parts}) {
1.335 albertel 4456: my @matchKey = ($isTask ? sort(grep /^resource\.\d+\.\Q$partid\E\.award$/,@versionKeys)
4457: : sort(grep /^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys));
4458:
4459:
1.122 ng 4460: # next if ($$record{"$version:resource.$partid.solved"} eq '');
1.324 albertel 4461: my $display_part=&get_display_part($partid,$symb);
1.147 albertel 4462: foreach my $matchKey (@matchKey) {
1.198 albertel 4463: if (exists($$record{$version.':'.$matchKey}) &&
4464: $$record{$version.':'.$matchKey} ne '') {
1.335 albertel 4465:
4466: my ($responseId)= ($isTask ? ($matchKey=~ /^resource\.(.*?)\.\Q$partid\E\.award$/)
4467: : ($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/));
1.467 albertel 4468: $displaySub[0].='<b>'.&mt('Part:').'</b> '.$display_part.' ';
4469: $displaySub[0].='<span class="LC_internal_info">('.&mt('ID').' '.
1.398 albertel 4470: $responseId.')</span> <b>';
1.335 albertel 4471: if ($$record{"$where.$partid.tries"} eq '') {
1.467 albertel 4472: $displaySub[0].=&mt('Trial not counted');
1.147 albertel 4473: } else {
1.467 albertel 4474: $displaySub[0].=&mt('Trial [_1]',
4475: $$record{"$where.$partid.tries"});
1.147 albertel 4476: }
1.335 albertel 4477: my $responseType=($isTask ? 'Task'
4478: : $responseType->{$partid}->{$responseId});
1.148 albertel 4479: if (!exists($orders{$partid})) { $orders{$partid}={}; }
4480: if (!exists($orders{$partid}->{$responseId})) {
4481: $orders{$partid}->{$responseId}=
1.525 raeburn 4482: &get_order($partid,$responseId,$symb,$uname,$udom,
4483: $no_increment);
1.148 albertel 4484: }
1.147 albertel 4485: $displaySub[0].='</b> '.
1.336 albertel 4486: &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:",$uname,$udom).'<br />';
1.147 albertel 4487: }
4488: }
1.335 albertel 4489: if (exists($$record{"$where.$partid.checkedin"})) {
1.485 albertel 4490: $displaySub[1].=&mt('Checked in by [_1] into slot [_2]',
4491: $$record{"$where.$partid.checkedin"},
4492: $$record{"$where.$partid.checkedin.slot"}).
4493: '<br />';
1.335 albertel 4494: }
4495: if (exists $$record{"$where.$partid.award"}) {
1.485 albertel 4496: $displaySub[1].='<b>'.&mt('Part:').'</b> '.$display_part.' '.
1.335 albertel 4497: lc($$record{"$where.$partid.award"}).' '.
4498: $mark{$$record{"$where.$partid.solved"}}.
1.147 albertel 4499: '<br />';
4500: }
1.335 albertel 4501: if (exists $$record{"$where.$partid.regrader"}) {
4502: $displaySub[2].=$$record{"$where.$partid.regrader"}.
4503: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
4504: } elsif ($$record{"$version:resource.$partid.regrader"} =~ /\S/) {
4505: $displaySub[2].=
4506: $$record{"$version:resource.$partid.regrader"}.
1.207 albertel 4507: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
1.147 albertel 4508: }
4509: }
4510: # needed because old essay regrader has not parts info
4511: if (exists $$record{"$version:resource.regrader"}) {
4512: $displaySub[2].=$$record{"$version:resource.regrader"};
4513: }
4514: $studentTable.='<td>'.$displaySub[0].' </td><td>'.$displaySub[1];
4515: if ($displaySub[2]) {
1.467 albertel 4516: $studentTable.=&mt('Manually graded by [_1]',$displaySub[2]);
1.147 albertel 4517: }
1.467 albertel 4518: $studentTable.=' </td>'.
4519: &Apache::loncommon::end_data_table_row();
1.119 ng 4520: }
1.467 albertel 4521: $studentTable.=&Apache::loncommon::end_data_table();
1.119 ng 4522: return $studentTable;
1.71 ng 4523: }
4524:
4525: sub updateGradeByPage {
4526: my ($request) = shift;
4527:
1.257 albertel 4528: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4529: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4530: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
4531: my $pageTitle = $env{'form.page'};
1.103 albertel 4532: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 4533: my ($uname,$udom) = split(/:/,$env{'form.student'});
4534: my $usec=$classlist->{$env{'form.student'}}[5];
1.103 albertel 4535: if (!&canmodify($usec)) {
1.526 raeburn 4536: $request->print('<span class="LC_warning">'.&mt('Unable to modify requested student ([_1])',$env{'form.student'}).'</span>');
1.324 albertel 4537: $request->print(&show_grading_menu_form($env{'form.symb'}));
1.103 albertel 4538: return;
4539: }
1.398 albertel 4540: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.526 raeburn 4541: $result.='<h3> '.&mt('Student: ').&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
1.129 ng 4542: '</h3>'."\n";
1.70 ng 4543:
1.68 ng 4544: $request->print($result);
4545:
1.132 bowersj2 4546: my $navmap = Apache::lonnavmaps::navmap->new();
1.257 albertel 4547: my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $env{'form.page'});
1.71 ng 4548: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 4549: if (!$map) {
1.527 raeburn 4550: $request->print('<span class="LC_warning">'.&mt('Unable to grade requested sequence ([_1]).',$resUrl).'</span>');
1.324 albertel 4551: my ($symb)=&get_symb($request);
4552: $request->print(&show_grading_menu_form($symb));
1.288 albertel 4553: return;
4554: }
1.71 ng 4555: my $iterator = $navmap->getIterator($map->map_start(),
4556: $map->map_finish());
1.70 ng 4557:
1.484 albertel 4558: my $studentTable=
4559: &Apache::loncommon::start_data_table().
4560: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 4561: '<th align="center"> '.&mt('Prob.').' </th>'.
4562: '<th> '.&mt('Title').' </th>'.
4563: '<th> '.&mt('Previous Score').' </th>'.
4564: '<th> '.&mt('New Score').' </th>'.
1.484 albertel 4565: &Apache::loncommon::end_data_table_header_row();
1.71 ng 4566:
4567: $iterator->next(); # skip the first BEGIN_MAP
4568: my $curRes = $iterator->next(); # for "current resource"
1.196 albertel 4569: my ($depth,$question,$prob,$changeflag)= (1,1,1,0);
1.101 albertel 4570: while ($depth > 0) {
1.71 ng 4571: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4572: if($curRes == $iterator->END_MAP) { $depth--; }
1.71 ng 4573:
1.385 albertel 4574: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4575: my $parts = $curRes->parts();
1.71 ng 4576: my $title = $curRes->compTitle();
4577: my $symbx = $curRes->symb();
1.484 albertel 4578: $studentTable.=
4579: &Apache::loncommon::start_data_table_row().
4580: '<td align="center" valign="top" >'.$prob.
1.485 albertel 4581: (scalar(@{$parts}) == 1 ? ''
1.526 raeburn 4582: : '<br />('.&mt('[quant,_1, part]',scalar(@{$parts}))
4583: .')').'</td>';
1.71 ng 4584: $studentTable.='<td valign="top"> <b>'.$title.'</b> </td>';
4585:
4586: my %newrecord=();
4587: my @displayPts=();
1.269 raeburn 4588: my %aggregate = ();
4589: my $aggregateflag = 0;
1.71 ng 4590: foreach my $partid (@{$parts}) {
1.257 albertel 4591: my $newpts = $env{'form.GD_BOX'.$question.'_'.$partid};
4592: my $oldpts = $env{'form.oldpts'.$question.'_'.$partid};
1.71 ng 4593:
1.257 albertel 4594: my $wgt = $env{'form.WGT'.$question.'_'.$partid} != 0 ?
4595: $env{'form.WGT'.$question.'_'.$partid} : 1;
1.71 ng 4596: my $partial = $newpts/$wgt;
4597: my $score;
4598: if ($partial > 0) {
4599: $score = 'correct_by_override';
1.125 ng 4600: } elsif ($newpts ne '') { #empty is taken as 0
1.71 ng 4601: $score = 'incorrect_by_override';
4602: }
1.257 albertel 4603: my $dropMenu = $env{'form.GD_SEL'.$question.'_'.$partid};
1.125 ng 4604: if ($dropMenu eq 'excused') {
1.71 ng 4605: $partial = '';
4606: $score = 'excused';
1.125 ng 4607: } elsif ($dropMenu eq 'reset status'
1.257 albertel 4608: && $env{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
1.125 ng 4609: $newrecord{'resource.'.$partid.'.tries'} = 0;
4610: $newrecord{'resource.'.$partid.'.solved'} = '';
4611: $newrecord{'resource.'.$partid.'.award'} = '';
4612: $newrecord{'resource.'.$partid.'.awarded'} = 0;
1.257 albertel 4613: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 4614: $changeflag++;
4615: $newpts = '';
1.269 raeburn 4616:
4617: my $aggtries = $env{'form.aggtries'.$question.'_'.$partid};
4618: my $totaltries = $env{'form.totaltries'.$question.'_'.$partid};
4619: my $solvedstatus = $env{'form.solved'.$question.'_'.$partid};
4620: if ($aggtries > 0) {
4621: &decrement_aggs($symbx,$partid,\%aggregate,$aggtries,$totaltries,$solvedstatus);
4622: $aggregateflag = 1;
4623: }
1.71 ng 4624: }
1.324 albertel 4625: my $display_part=&get_display_part($partid,$curRes->symb());
1.257 albertel 4626: my $oldstatus = $env{'form.solved'.$question.'_'.$partid};
1.526 raeburn 4627: $displayPts[0].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.71 ng 4628: (($oldstatus eq 'excused') ? 'excused' : $oldpts).
1.326 albertel 4629: ' <br />';
1.526 raeburn 4630: $displayPts[1].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.125 ng 4631: (($score eq 'excused') ? 'excused' : $newpts).
1.326 albertel 4632: ' <br />';
1.71 ng 4633: $question++;
1.380 albertel 4634: next if ($dropMenu eq 'reset status' || ($newpts eq $oldpts && $score ne 'excused'));
1.125 ng 4635:
1.71 ng 4636: $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
1.125 ng 4637: $newrecord{'resource.'.$partid.'.solved'} = $score if $score ne '';
1.257 albertel 4638: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}"
1.125 ng 4639: if (scalar(keys(%newrecord)) > 0);
1.71 ng 4640:
4641: $changeflag++;
4642: }
4643: if (scalar(keys(%newrecord)) > 0) {
1.382 albertel 4644: my %record =
4645: &Apache::lonnet::restore($symbx,$env{'request.course.id'},
4646: $udom,$uname);
4647:
4648: if (&Apache::lonnet::validCODE($env{'form.CODE'})) {
4649: $newrecord{'resource.CODE'} = $env{'form.CODE'};
4650: } elsif (&Apache::lonnet::validCODE($record{'resource.CODE'})) {
4651: $newrecord{'resource.CODE'} = '';
4652: }
1.257 albertel 4653: &Apache::lonnet::cstore(\%newrecord,$symbx,$env{'request.course.id'},
1.71 ng 4654: $udom,$uname);
1.382 albertel 4655: %record = &Apache::lonnet::restore($symbx,
4656: $env{'request.course.id'},
4657: $udom,$uname);
1.380 albertel 4658: &check_and_remove_from_queue($parts,\%record,undef,$symbx,
4659: $cdom,$cnum,$udom,$uname);
1.71 ng 4660: }
1.380 albertel 4661:
1.269 raeburn 4662: if ($aggregateflag) {
4663: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
4664: $env{'course.'.$env{'request.course.id'}.'.domain'},
4665: $env{'course.'.$env{'request.course.id'}.'.num'});
4666: }
1.125 ng 4667:
1.71 ng 4668: $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
4669: '<td valign="top">'.$displayPts[1].'</td>'.
1.484 albertel 4670: &Apache::loncommon::end_data_table_row();
1.68 ng 4671:
1.196 albertel 4672: $prob++;
1.68 ng 4673: }
1.71 ng 4674: $curRes = $iterator->next();
1.68 ng 4675: }
1.98 albertel 4676:
1.484 albertel 4677: $studentTable.=&Apache::loncommon::end_data_table();
1.324 albertel 4678: $studentTable.=&show_grading_menu_form($env{'form.symb'});
1.526 raeburn 4679: my $grademsg=($changeflag == 0 ? &mt('No score was changed or updated.') :
4680: &mt('The scores were changed for [quant,_1,problem].',
4681: $changeflag));
1.76 ng 4682: $request->print($grademsg.$studentTable);
1.68 ng 4683:
1.70 ng 4684: return '';
4685: }
4686:
1.72 ng 4687: #-------- end of section for handling grading by page/sequence ---------
4688: #
4689: #-------------------------------------------------------------------
4690:
1.574.2.5! raeburn 4691: #--------------------Bubblesheet (Scantron) Grading-----------------------------------
1.75 albertel 4692: #
4693: #------ start of section for handling grading by page/sequence ---------
4694:
1.423 albertel 4695: =pod
4696:
4697: =head1 Bubble sheet grading routines
4698:
1.424 albertel 4699: For this documentation:
4700:
4701: 'scanline' refers to the full line of characters
4702: from the file that we are parsing that represents one entire sheet
4703:
4704: 'bubble line' refers to the data
4705: representing the line of bubbles that are on the physical bubble sheet
4706:
4707:
4708: The overall process is that a scanned in bubble sheet data is uploaded
4709: into a course. When a user wants to grade, they select a
4710: sequence/folder of resources, a file of bubble sheet info, and pick
4711: one of the predefined configurations for what each scanline looks
4712: like.
4713:
4714: Next each scanline is checked for any errors of either 'missing
1.435 foxr 4715: bubbles' (it's an error because it may have been mis-scanned
1.424 albertel 4716: because too light bubbling), 'double bubble' (each bubble line should
4717: have no more that one letter picked), invalid or duplicated CODE,
1.556 weissno 4718: invalid student/employee ID
1.424 albertel 4719:
4720: If the CODE option is used that determines the randomization of the
1.556 weissno 4721: homework problems, either way the student/employee ID is looked up into a
1.424 albertel 4722: username:domain.
4723:
4724: During the validation phase the instructor can choose to skip scanlines.
4725:
1.435 foxr 4726: After the validation phase, there are now 3 bubble sheet files
1.424 albertel 4727:
4728: scantron_original_filename (unmodified original file)
4729: scantron_corrected_filename (file where the corrected information has replaced the original information)
4730: scantron_skipped_filename (contains the exact text of scanlines that where skipped)
4731:
4732: Also there is a separate hash nohist_scantrondata that contains extra
4733: correction information that isn't representable in the bubble sheet
4734: file (see &scantron_getfile() for more information)
4735:
4736: After all scanlines are either valid, marked as valid or skipped, then
4737: foreach line foreach problem in the picked sequence, an ssi request is
4738: made that simulates a user submitting their selected letter(s) against
4739: the homework problem.
1.423 albertel 4740:
4741: =over 4
4742:
4743:
4744:
4745: =item defaultFormData
4746:
4747: Returns html hidden inputs used to hold context/default values.
4748:
4749: Arguments:
4750: $symb - $symb of the current resource
4751:
4752: =cut
1.422 foxr 4753:
1.81 albertel 4754: sub defaultFormData {
1.324 albertel 4755: my ($symb)=@_;
1.447 foxr 4756: return '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 4757: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
4758: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.81 albertel 4759: }
4760:
1.447 foxr 4761:
1.423 albertel 4762: =pod
4763:
4764: =item getSequenceDropDown
4765:
4766: Return html dropdown of possible sequences to grade
4767:
4768: Arguments:
4769: $symb - $symb of the current resource
4770:
4771: =cut
1.422 foxr 4772:
1.75 albertel 4773: sub getSequenceDropDown {
1.423 albertel 4774: my ($symb)=@_;
1.75 albertel 4775: my $result='<select name="selectpage">'."\n";
1.423 albertel 4776: my ($titles,$symbx) = &getSymbMap();
1.137 albertel 4777: my ($curpage)=&Apache::lonnet::decode_symb($symb);
1.75 albertel 4778: my $ctr=0;
4779: foreach (@$titles) {
4780: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
4781: $result.='<option value="'.$$symbx{$_}.'" '.
1.401 albertel 4782: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.75 albertel 4783: '>'.$showtitle.'</option>'."\n";
4784: $ctr++;
4785: }
4786: $result.= '</select>';
4787: return $result;
4788: }
4789:
1.495 albertel 4790: my %bubble_lines_per_response; # no. bubble lines for each response.
1.554 raeburn 4791: # key is zero-based index - 0, 1, 2 ...
1.495 albertel 4792:
4793: my %first_bubble_line; # First bubble line no. for each bubble.
4794:
1.509 raeburn 4795: my %subdivided_bubble_lines; # no. bubble lines for optionresponse,
4796: # matchresponse or rankresponse, where
4797: # an individual response can have multiple
4798: # lines
1.503 raeburn 4799:
4800: my %responsetype_per_response; # responsetype for each response
4801:
1.495 albertel 4802: # Save and restore the bubble lines array to the form env.
4803:
4804:
4805: sub save_bubble_lines {
4806: foreach my $line (keys(%bubble_lines_per_response)) {
4807: $env{"form.scantron.bubblelines.$line"} = $bubble_lines_per_response{$line};
4808: $env{"form.scantron.first_bubble_line.$line"} =
4809: $first_bubble_line{$line};
1.503 raeburn 4810: $env{"form.scantron.sub_bubblelines.$line"} =
4811: $subdivided_bubble_lines{$line};
4812: $env{"form.scantron.responsetype.$line"} =
4813: $responsetype_per_response{$line};
1.495 albertel 4814: }
4815: }
4816:
4817:
4818: sub restore_bubble_lines {
4819: my $line = 0;
4820: %bubble_lines_per_response = ();
4821: while ($env{"form.scantron.bubblelines.$line"}) {
4822: my $value = $env{"form.scantron.bubblelines.$line"};
4823: $bubble_lines_per_response{$line} = $value;
4824: $first_bubble_line{$line} =
4825: $env{"form.scantron.first_bubble_line.$line"};
1.503 raeburn 4826: $subdivided_bubble_lines{$line} =
4827: $env{"form.scantron.sub_bubblelines.$line"};
4828: $responsetype_per_response{$line} =
4829: $env{"form.scantron.responsetype.$line"};
1.495 albertel 4830: $line++;
4831: }
4832: }
4833:
4834: # Given the parsed scanline, get the response for
4835: # 'answer' number n:
4836:
4837: sub get_response_bubbles {
4838: my ($parsed_line, $response) = @_;
4839:
4840: my $bubble_line = $first_bubble_line{$response-1} +1;
4841: my $bubble_lines= $bubble_lines_per_response{$response-1};
4842:
4843: my $selected = "";
4844:
4845: for (my $bline = 0; $bline < $bubble_lines; $bline++) {
4846: $selected .= $$parsed_line{"scantron.$bubble_line.answer"}.":";
4847: $bubble_line++;
4848: }
4849: return $selected;
4850: }
1.423 albertel 4851:
4852: =pod
4853:
4854: =item scantron_filenames
4855:
4856: Returns a list of the scantron files in the current course
4857:
4858: =cut
1.422 foxr 4859:
1.202 albertel 4860: sub scantron_filenames {
1.257 albertel 4861: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4862: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
1.517 raeburn 4863: my $getpropath = 1;
1.157 albertel 4864: my @files=&Apache::lonnet::dirlist('userfiles',$cdom,$cname,
1.517 raeburn 4865: $getpropath);
1.202 albertel 4866: my @possiblenames;
1.201 albertel 4867: foreach my $filename (sort(@files)) {
1.157 albertel 4868: ($filename)=split(/&/,$filename);
4869: if ($filename!~/^scantron_orig_/) { next ; }
4870: $filename=~s/^scantron_orig_//;
1.202 albertel 4871: push(@possiblenames,$filename);
4872: }
4873: return @possiblenames;
4874: }
4875:
1.423 albertel 4876: =pod
4877:
4878: =item scantron_uploads
4879:
4880: Returns html drop-down list of scantron files in current course.
4881:
4882: Arguments:
4883: $file2grade - filename to set as selected in the dropdown
4884:
4885: =cut
1.422 foxr 4886:
1.202 albertel 4887: sub scantron_uploads {
1.209 ng 4888: my ($file2grade) = @_;
1.202 albertel 4889: my $result= '<select name="scantron_selectfile">';
4890: $result.="<option></option>";
4891: foreach my $filename (sort(&scantron_filenames())) {
1.401 albertel 4892: $result.="<option".($filename eq $file2grade ? ' selected="selected"':'').">$filename</option>\n";
1.81 albertel 4893: }
4894: $result.="</select>";
4895: return $result;
4896: }
4897:
1.423 albertel 4898: =pod
4899:
4900: =item scantron_scantab
4901:
4902: Returns html drop down of the scantron formats in the scantronformat.tab
4903: file.
4904:
4905: =cut
1.422 foxr 4906:
1.82 albertel 4907: sub scantron_scantab {
4908: my $result='<select name="scantron_format">'."\n";
1.191 albertel 4909: $result.='<option></option>'."\n";
1.518 raeburn 4910: my @lines = &get_scantronformat_file();
4911: if (@lines > 0) {
4912: foreach my $line (@lines) {
4913: next if (($line =~ /^\#/) || ($line eq ''));
4914: my ($name,$descrip)=split(/:/,$line);
4915: $result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
4916: }
1.82 albertel 4917: }
4918: $result.='</select>'."\n";
1.518 raeburn 4919: return $result;
4920: }
4921:
4922: =pod
4923:
4924: =item get_scantronformat_file
4925:
4926: Returns an array containing lines from the scantron format file for
4927: the domain of the course.
4928:
4929: If a url for a custom.tab file is listed in domain's configuration.db,
4930: lines are from this file.
4931:
4932: Otherwise, if a default.tab has been published in RES space by the
4933: domainconfig user, lines are from this file.
4934:
4935: Otherwise, fall back to getting lines from the legacy file on the
1.519 raeburn 4936: local server: /home/httpd/lonTabs/default_scantronformat.tab
1.82 albertel 4937:
1.518 raeburn 4938: =cut
4939:
4940: sub get_scantronformat_file {
4941: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
4942: my %domconfig = &Apache::lonnet::get_dom('configuration',['scantron'],$cdom);
4943: my $gottab = 0;
4944: my @lines;
4945: if (ref($domconfig{'scantron'}) eq 'HASH') {
4946: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
4947: my $formatfile = &Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.$domconfig{'scantron'}{'scantronformat'});
4948: if ($formatfile ne '-1') {
4949: @lines = split("\n",$formatfile,-1);
4950: $gottab = 1;
4951: }
4952: }
4953: }
4954: if (!$gottab) {
4955: my $confname = $cdom.'-domainconfig';
4956: my $default = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res/'.$cdom.'/'.$confname.'/default.tab';
4957: my $formatfile = &Apache::lonnet::getfile($default);
4958: if ($formatfile ne '-1') {
4959: @lines = split("\n",$formatfile,-1);
4960: $gottab = 1;
4961: }
4962: }
4963: if (!$gottab) {
1.519 raeburn 4964: my @domains = &Apache::lonnet::current_machine_domains();
4965: if (grep(/^\Q$cdom\E$/,@domains)) {
4966: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
4967: @lines = <$fh>;
4968: close($fh);
4969: } else {
4970: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab');
4971: @lines = <$fh>;
4972: close($fh);
4973: }
1.518 raeburn 4974: }
4975: return @lines;
1.82 albertel 4976: }
4977:
1.423 albertel 4978: =pod
4979:
4980: =item scantron_CODElist
4981:
4982: Returns html drop down of the saved CODE lists from current course,
4983: generated from earlier printings.
4984:
4985: =cut
1.422 foxr 4986:
1.186 albertel 4987: sub scantron_CODElist {
1.257 albertel 4988: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4989: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.186 albertel 4990: my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
4991: my $namechoice='<option></option>';
1.225 albertel 4992: foreach my $name (sort {uc($a) cmp uc($b)} @names) {
1.191 albertel 4993: if ($name =~ /^error: 2 /) { next; }
1.278 albertel 4994: if ($name =~ /^type\0/) { next; }
1.186 albertel 4995: $namechoice.='<option value="'.$name.'">'.$name.'</option>';
4996: }
4997: $namechoice='<select name="scantron_CODElist">'.$namechoice.'</select>';
4998: return $namechoice;
4999: }
5000:
1.423 albertel 5001: =pod
5002:
5003: =item scantron_CODEunique
5004:
5005: Returns the html for "Each CODE to be used once" radio.
5006:
5007: =cut
1.422 foxr 5008:
1.186 albertel 5009: sub scantron_CODEunique {
1.532 bisitz 5010: my $result='<span class="LC_nobreak">
1.272 albertel 5011: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 5012: value="yes" checked="checked" />'.&mt('Yes').' </label>
1.381 albertel 5013: </span>
1.532 bisitz 5014: <span class="LC_nobreak">
1.272 albertel 5015: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 5016: value="no" />'.&mt('No').' </label>
1.381 albertel 5017: </span>';
1.186 albertel 5018: return $result;
5019: }
1.423 albertel 5020:
5021: =pod
5022:
5023: =item scantron_selectphase
5024:
5025: Generates the initial screen to start the bubble sheet process.
5026: Allows for - starting a grading run.
1.424 albertel 5027: - downloading existing scan data (original, corrected
1.423 albertel 5028: or skipped info)
5029:
5030: - uploading new scan data
5031:
5032: Arguments:
5033: $r - The Apache request object
5034: $file2grade - name of the file that contain the scanned data to score
5035:
5036: =cut
1.186 albertel 5037:
1.75 albertel 5038: sub scantron_selectphase {
1.209 ng 5039: my ($r,$file2grade) = @_;
1.324 albertel 5040: my ($symb)=&get_symb($r);
1.75 albertel 5041: if (!$symb) {return '';}
1.423 albertel 5042: my $sequence_selector=&getSequenceDropDown($symb);
1.324 albertel 5043: my $default_form_data=&defaultFormData($symb);
5044: my $grading_menu_button=&show_grading_menu_form($symb);
1.209 ng 5045: my $file_selector=&scantron_uploads($file2grade);
1.82 albertel 5046: my $format_selector=&scantron_scantab();
1.186 albertel 5047: my $CODE_selector=&scantron_CODElist();
5048: my $CODE_unique=&scantron_CODEunique();
1.75 albertel 5049: my $result;
1.422 foxr 5050:
1.513 foxr 5051: $ssi_error = 0;
5052:
1.422 foxr 5053: # Chunk of form to prompt for a file to grade and how:
5054:
1.489 albertel 5055: $result.= '
5056: <br />
5057: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantron_process">
5058: <input type="hidden" name="command" value="scantron_warning" />
5059: '.$default_form_data.'
5060: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5061: '.&Apache::loncommon::start_data_table_header_row().'
5062: <th colspan="2">
1.492 albertel 5063: '.&mt('Specify file and which Folder/Sequence to grade').'
1.489 albertel 5064: </th>
5065: '.&Apache::loncommon::end_data_table_header_row().'
5066: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5067: <td> '.&mt('Sequence to grade:').' </td><td> '.$sequence_selector.' </td>
1.489 albertel 5068: '.&Apache::loncommon::end_data_table_row().'
5069: '.&Apache::loncommon::start_data_table_row().'
1.572 www 5070: <td> '.&mt('Filename of bubblesheet data file:').' </td><td> '.$file_selector.' </td>
1.489 albertel 5071: '.&Apache::loncommon::end_data_table_row().'
5072: '.&Apache::loncommon::start_data_table_row().'
1.572 www 5073: <td> '.&mt('Format of bubblesheet data file:').' </td><td> '.$format_selector.' </td>
1.489 albertel 5074: '.&Apache::loncommon::end_data_table_row().'
5075: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5076: <td> '.&mt('Saved CODEs to validate against:').' </td><td> '.$CODE_selector.' </td>
1.489 albertel 5077: '.&Apache::loncommon::end_data_table_row().'
5078: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5079: <td> '.&mt('Each CODE is only to be used once:').'</td><td> '.$CODE_unique.' </td>
1.489 albertel 5080: '.&Apache::loncommon::end_data_table_row().'
5081: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5082: <td> '.&mt('Options:').' </td>
1.187 albertel 5083: <td>
1.492 albertel 5084: <label><input type="checkbox" name="scantron_options_redo" value="redo_skipped"/> '.&mt('Do only previously skipped records').'</label> <br />
5085: <label><input type="checkbox" name="scantron_options_ignore" value="ignore_corrections"/> '.&mt('Remove all existing corrections').'</label> <br />
5086: <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources when grading').'</label>
1.187 albertel 5087: </td>
1.489 albertel 5088: '.&Apache::loncommon::end_data_table_row().'
5089: '.&Apache::loncommon::start_data_table_row().'
1.174 albertel 5090: <td colspan="2">
1.572 www 5091: <input type="submit" value="'.&mt('Grading: Validate Bubblesheet Records').'" />
1.162 albertel 5092: </td>
1.489 albertel 5093: '.&Apache::loncommon::end_data_table_row().'
5094: '.&Apache::loncommon::end_data_table().'
5095: </form>
5096: ';
1.162 albertel 5097:
5098: $r->print($result);
5099:
1.257 albertel 5100: if (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) ||
5101: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.162 albertel 5102:
1.422 foxr 5103: # Chunk of form to prompt for a scantron file upload.
5104:
1.489 albertel 5105: $r->print('
5106: <br />
5107: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5108: '.&Apache::loncommon::start_data_table_header_row().'
5109: <th>
1.572 www 5110: '.&mt('Specify a bubblesheet data file to upload.').'
1.489 albertel 5111: </th>
5112: '.&Apache::loncommon::end_data_table_header_row().'
5113: '.&Apache::loncommon::start_data_table_row().'
1.162 albertel 5114: <td>
1.489 albertel 5115: ');
1.324 albertel 5116: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.257 albertel 5117: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
5118: my $cnum= $env{'course.'.$env{'request.course.id'}.'.num'};
1.492 albertel 5119: $r->print('
1.174 albertel 5120: <script type="text/javascript" language="javascript">
5121: function checkUpload(formname) {
5122: if (formname.upfile.value == "") {
1.492 albertel 5123: alert("'.&mt('Please use the browse button to select a file from your local directory.').'");
1.174 albertel 5124: return false;
5125: }
5126: formname.submit();
5127: }
5128: </script>
5129:
1.492 albertel 5130: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
5131: '.$default_form_data.'
5132: <input name="courseid" type="hidden" value="'.$cnum.'" />
5133: <input name="domainid" type="hidden" value="'.$cdom.'" />
5134: <input name="command" value="scantronupload_save" type="hidden" />
5135: '.&mt('File to upload: [_1]','<input type="file" name="upfile" size="50" />').'
1.174 albertel 5136: <br />
1.572 www 5137: <input type="button" onClick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
1.174 albertel 5138: </form>
1.492 albertel 5139: ');
1.162 albertel 5140:
1.489 albertel 5141: $r->print('
1.162 albertel 5142: </td>
1.489 albertel 5143: '.&Apache::loncommon::end_data_table_row().'
5144: '.&Apache::loncommon::end_data_table().'
5145: ');
1.162 albertel 5146: }
1.422 foxr 5147:
5148: # Chunk of the form that prompts to view a scoring office file,
5149: # corrected file, skipped records in a file.
5150:
1.489 albertel 5151: $r->print('
5152: <br />
5153: <form action="/adm/grades" name="scantron_download">
5154: '.$default_form_data.'
5155: <input type="hidden" name="command" value="scantron_download" />
5156: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5157: '.&Apache::loncommon::start_data_table_header_row().'
5158: <th>
1.492 albertel 5159: '.&mt('Download a scoring office file').'
1.489 albertel 5160: </th>
5161: '.&Apache::loncommon::end_data_table_header_row().'
5162: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5163: <td> '.&mt('Filename of scoring office file: [_1]',$file_selector).'
1.489 albertel 5164: <br />
1.492 albertel 5165: <input type="submit" value="'.&mt('Download: Show List of Associated Files').'" />
1.489 albertel 5166: '.&Apache::loncommon::end_data_table_row().'
5167: '.&Apache::loncommon::end_data_table().'
5168: </form>
5169: <br />
5170: ');
1.162 albertel 5171:
1.457 banghart 5172: &Apache::lonpickcode::code_list($r,2);
1.523 raeburn 5173:
1.528 raeburn 5174: $r->print('<br /><form method="post" name="checkscantron">'.
1.523 raeburn 5175: $default_form_data."\n".
5176: &Apache::loncommon::start_data_table('LC_scantron_action')."\n".
5177: &Apache::loncommon::start_data_table_header_row()."\n".
5178: '<th colspan="2">
1.572 www 5179: '.&mt('Review bubblesheet data and submissions for a previously graded folder/sequence')."\n".
1.523 raeburn 5180: '</th>'."\n".
5181: &Apache::loncommon::end_data_table_header_row()."\n".
5182: &Apache::loncommon::start_data_table_row()."\n".
5183: '<td> '.&mt('Graded folder/sequence:').' </td>'."\n".
5184: '<td> '.$sequence_selector.' </td>'.
5185: &Apache::loncommon::end_data_table_row()."\n".
5186: &Apache::loncommon::start_data_table_row()."\n".
5187: '<td> '.&mt('Filename of scoring office file:').' </td>'."\n".
5188: '<td> '.$file_selector.' </td>'."\n".
5189: &Apache::loncommon::end_data_table_row()."\n".
5190: &Apache::loncommon::start_data_table_row()."\n".
5191: '<td> '.&mt('Format of data file:').' </td>'."\n".
5192: '<td> '.$format_selector.' </td>'."\n".
5193: &Apache::loncommon::end_data_table_row()."\n".
5194: &Apache::loncommon::start_data_table_row()."\n".
1.557 raeburn 5195: '<td> '.&mt('Options').' </td>'."\n".
5196: '<td> <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources').'</label></td>'.
5197: &Apache::loncommon::end_data_table_row()."\n".
5198: &Apache::loncommon::start_data_table_row()."\n".
1.523 raeburn 5199: '<td colspan="2">'."\n".
5200: '<input type="hidden" name="command" value="checksubmissions" />'."\n".
1.574.2.5! raeburn 5201: '<input type="submit" value="'.&mt('Review Bubblesheet Data and Submission Records').'" />'."\n".
1.523 raeburn 5202: '</td>'."\n".
5203: &Apache::loncommon::end_data_table_row()."\n".
5204: &Apache::loncommon::end_data_table()."\n".
5205: '</form><br />');
1.457 banghart 5206: $r->print($grading_menu_button);
1.523 raeburn 5207: return;
1.75 albertel 5208: }
5209:
1.423 albertel 5210: =pod
5211:
5212: =item get_scantron_config
5213:
5214: Parse and return the scantron configuration line selected as a
5215: hash of configuration file fields.
5216:
5217: Arguments:
5218: which - the name of the configuration to parse from the file.
5219:
5220:
5221: Returns:
5222: If the named configuration is not in the file, an empty
5223: hash is returned.
5224: a hash with the fields
5225: name - internal name for the this configuration setup
5226: description - text to display to operator that describes this config
5227: CODElocation - if 0 or the string 'none'
5228: - no CODE exists for this config
5229: if -1 || the string 'letter'
5230: - a CODE exists for this config and is
5231: a string of letters
5232: Unsupported value (but planned for future support)
5233: if a positive integer
5234: - The CODE exists as the first n items from
5235: the question section of the form
5236: if the string 'number'
5237: - The CODE exists for this config and is
5238: a string of numbers
5239: CODEstart - (only matter if a CODE exists) column in the line where
5240: the CODE starts
5241: CODElength - length of the CODE
1.573 bisitz 5242: IDstart - column where the student/employee ID starts
1.556 weissno 5243: IDlength - length of the student/employee ID info
1.423 albertel 5244: Qstart - column where the information from the bubbled
5245: 'questions' start
5246: Qlength - number of columns comprising a single bubble line from
5247: the sheet. (usually either 1 or 10)
1.424 albertel 5248: Qon - either a single character representing the character used
1.423 albertel 5249: to signal a bubble was chosen in the positional setup, or
5250: the string 'letter' if the letter of the chosen bubble is
5251: in the final, or 'number' if a number representing the
5252: chosen bubble is in the file (1->A 0->J)
1.424 albertel 5253: Qoff - the character used to represent that a bubble was
5254: left blank
1.423 albertel 5255: PaperID - if the scanning process generates a unique number for each
5256: sheet scanned the column that this ID number starts in
5257: PaperIDlength - number of columns that comprise the unique ID number
5258: for the sheet of paper
1.424 albertel 5259: FirstName - column that the first name starts in
1.423 albertel 5260: FirstNameLength - number of columns that the first name spans
5261:
5262: LastName - column that the last name starts in
5263: LastNameLength - number of columns that the last name spans
5264:
5265: =cut
1.422 foxr 5266:
1.82 albertel 5267: sub get_scantron_config {
5268: my ($which) = @_;
1.518 raeburn 5269: my @lines = &get_scantronformat_file();
1.82 albertel 5270: my %config;
1.157 albertel 5271: #FIXME probably should move to XML it has already gotten a bit much now
1.518 raeburn 5272: foreach my $line (@lines) {
1.82 albertel 5273: my ($name,$descrip)=split(/:/,$line);
5274: if ($name ne $which ) { next; }
5275: chomp($line);
5276: my @config=split(/:/,$line);
5277: $config{'name'}=$config[0];
5278: $config{'description'}=$config[1];
5279: $config{'CODElocation'}=$config[2];
5280: $config{'CODEstart'}=$config[3];
5281: $config{'CODElength'}=$config[4];
5282: $config{'IDstart'}=$config[5];
5283: $config{'IDlength'}=$config[6];
5284: $config{'Qstart'}=$config[7];
1.497 foxr 5285: $config{'Qlength'}=$config[8];
1.82 albertel 5286: $config{'Qoff'}=$config[9];
5287: $config{'Qon'}=$config[10];
1.157 albertel 5288: $config{'PaperID'}=$config[11];
5289: $config{'PaperIDlength'}=$config[12];
5290: $config{'FirstName'}=$config[13];
5291: $config{'FirstNamelength'}=$config[14];
5292: $config{'LastName'}=$config[15];
5293: $config{'LastNamelength'}=$config[16];
1.82 albertel 5294: last;
5295: }
5296: return %config;
5297: }
5298:
1.423 albertel 5299: =pod
5300:
5301: =item username_to_idmap
5302:
1.556 weissno 5303: creates a hash keyed by student/employee ID with values of the corresponding
1.423 albertel 5304: student username:domain.
5305:
5306: Arguments:
5307:
5308: $classlist - reference to the class list hash. This is a hash
5309: keyed by student name:domain whose elements are references
1.424 albertel 5310: to arrays containing various chunks of information
1.423 albertel 5311: about the student. (See loncoursedata for more info).
5312:
5313: Returns
5314: %idmap - the constructed hash
5315:
5316: =cut
5317:
1.82 albertel 5318: sub username_to_idmap {
5319: my ($classlist)= @_;
5320: my %idmap;
5321: foreach my $student (keys(%$classlist)) {
5322: $idmap{$classlist->{$student}->[&Apache::loncoursedata::CL_ID]}=
5323: $student;
5324: }
5325: return %idmap;
5326: }
1.423 albertel 5327:
5328: =pod
5329:
1.424 albertel 5330: =item scantron_fixup_scanline
1.423 albertel 5331:
5332: Process a requested correction to a scanline.
5333:
5334: Arguments:
5335: $scantron_config - hash from &get_scantron_config()
5336: $scan_data - hash of correction information
5337: (see &scantron_getfile())
5338: $line - existing scanline
5339: $whichline - line number of the passed in scanline
5340: $field - type of change to process
5341: (either
1.573 bisitz 5342: 'ID' -> correct the student/employee ID
1.423 albertel 5343: 'CODE' -> correct the CODE
5344: 'answer' -> fixup the submitted answers)
5345:
5346: $args - hash of additional info,
5347: - 'ID'
5348: 'newid' -> studentID to use in replacement
1.424 albertel 5349: of existing one
1.423 albertel 5350: - 'CODE'
5351: 'CODE_ignore_dup' - set to true if duplicates
5352: should be ignored.
5353: 'CODE' - is new code or 'use_unfound'
1.424 albertel 5354: if the existing unfound code should
1.423 albertel 5355: be used as is
5356: - 'answer'
5357: 'response' - new answer or 'none' if blank
5358: 'question' - the bubble line to change
1.503 raeburn 5359: 'questionnum' - the question identifier,
5360: may include subquestion.
1.423 albertel 5361:
5362: Returns:
5363: $line - the modified scanline
5364:
5365: Side effects:
5366: $scan_data - may be updated
5367:
5368: =cut
5369:
1.82 albertel 5370:
1.157 albertel 5371: sub scantron_fixup_scanline {
5372: my ($scantron_config,$scan_data,$line,$whichline,$field,$args)=@_;
5373: if ($field eq 'ID') {
5374: if (length($args->{'newid'}) > $$scantron_config{'IDlength'}) {
1.186 albertel 5375: return ($line,1,'New value too large');
1.157 albertel 5376: }
5377: if (length($args->{'newid'}) < $$scantron_config{'IDlength'}) {
5378: $args->{'newid'}=sprintf('%-'.$$scantron_config{'IDlength'}.'s',
5379: $args->{'newid'});
5380: }
5381: substr($line,$$scantron_config{'IDstart'}-1,
5382: $$scantron_config{'IDlength'})=$args->{'newid'};
5383: if ($args->{'newid'}=~/^\s*$/) {
5384: &scan_data($scan_data,"$whichline.user",
5385: $args->{'username'}.':'.$args->{'domain'});
5386: }
1.186 albertel 5387: } elsif ($field eq 'CODE') {
1.192 albertel 5388: if ($args->{'CODE_ignore_dup'}) {
5389: &scan_data($scan_data,"$whichline.CODE_ignore_dup",'1');
5390: }
5391: &scan_data($scan_data,"$whichline.useCODE",'1');
5392: if ($args->{'CODE'} ne 'use_unfound') {
1.191 albertel 5393: if (length($args->{'CODE'}) > $$scantron_config{'CODElength'}) {
5394: return ($line,1,'New CODE value too large');
5395: }
5396: if (length($args->{'CODE'}) < $$scantron_config{'CODElength'}) {
5397: $args->{'CODE'}=sprintf('%-'.$$scantron_config{'CODElength'}.'s',$args->{'CODE'});
5398: }
5399: substr($line,$$scantron_config{'CODEstart'}-1,
5400: $$scantron_config{'CODElength'})=$args->{'CODE'};
1.186 albertel 5401: }
1.157 albertel 5402: } elsif ($field eq 'answer') {
1.497 foxr 5403: my $length=$scantron_config->{'Qlength'};
1.157 albertel 5404: my $off=$scantron_config->{'Qoff'};
5405: my $on=$scantron_config->{'Qon'};
1.497 foxr 5406: my $answer=${off}x$length;
5407: if ($args->{'response'} eq 'none') {
5408: &scan_data($scan_data,
1.503 raeburn 5409: "$whichline.no_bubble.".$args->{'questionnum'},'1');
1.497 foxr 5410: } else {
5411: if ($on eq 'letter') {
5412: my @alphabet=('A'..'Z');
5413: $answer=$alphabet[$args->{'response'}];
5414: } elsif ($on eq 'number') {
5415: $answer=$args->{'response'}+1;
5416: if ($answer == 10) { $answer = '0'; }
1.274 albertel 5417: } else {
1.497 foxr 5418: substr($answer,$args->{'response'},1)=$on;
1.274 albertel 5419: }
1.497 foxr 5420: &scan_data($scan_data,
1.503 raeburn 5421: "$whichline.no_bubble.".$args->{'questionnum'},undef,'1');
1.157 albertel 5422: }
1.497 foxr 5423: my $where=$length*($args->{'question'}-1)+$scantron_config->{'Qstart'};
5424: substr($line,$where-1,$length)=$answer;
1.157 albertel 5425: }
5426: return $line;
5427: }
1.423 albertel 5428:
5429: =pod
5430:
5431: =item scan_data
5432:
5433: Edit or look up an item in the scan_data hash.
5434:
5435: Arguments:
5436: $scan_data - The hash (see scantron_getfile)
5437: $key - shorthand of the key to edit (actual key is
1.424 albertel 5438: scantronfilename_key).
1.423 albertel 5439: $data - New value of the hash entry.
5440: $delete - If true, the entry is removed from the hash.
5441:
5442: Returns:
5443: The new value of the hash table field (undefined if deleted).
5444:
5445: =cut
5446:
5447:
1.157 albertel 5448: sub scan_data {
5449: my ($scan_data,$key,$value,$delete)=@_;
1.257 albertel 5450: my $filename=$env{'form.scantron_selectfile'};
1.157 albertel 5451: if (defined($value)) {
5452: $scan_data->{$filename.'_'.$key} = $value;
5453: }
5454: if ($delete) { delete($scan_data->{$filename.'_'.$key}); }
5455: return $scan_data->{$filename.'_'.$key};
5456: }
1.423 albertel 5457:
1.495 albertel 5458: # ----- These first few routines are general use routines.----
5459:
5460: # Return the number of occurences of a pattern in a string.
5461:
5462: sub occurence_count {
5463: my ($string, $pattern) = @_;
5464:
5465: my @matches = ($string =~ /$pattern/g);
5466:
5467: return scalar(@matches);
5468: }
5469:
5470:
5471: # Take a string known to have digits and convert all the
5472: # digits into letters in the range J,A..I.
5473:
5474: sub digits_to_letters {
5475: my ($input) = @_;
5476:
5477: my @alphabet = ('J', 'A'..'I');
5478:
5479: my @input = split(//, $input);
5480: my $output ='';
5481: for (my $i = 0; $i < scalar(@input); $i++) {
5482: if ($input[$i] =~ /\d/) {
5483: $output .= $alphabet[$input[$i]];
5484: } else {
5485: $output .= $input[$i];
5486: }
5487: }
5488: return $output;
5489: }
5490:
1.423 albertel 5491: =pod
5492:
5493: =item scantron_parse_scanline
5494:
5495: Decodes a scanline from the selected scantron file
5496:
5497: Arguments:
5498: line - The text of the scantron file line to process
5499: whichline - Line number
5500: scantron_config - Hash describing the format of the scantron lines.
5501: scan_data - Hash of extra information about the scanline
5502: (see scantron_getfile for more information)
5503: just_header - True if should not process question answers but only
5504: the stuff to the left of the answers.
5505: Returns:
5506: Hash containing the result of parsing the scanline
5507:
5508: Keys are all proceeded by the string 'scantron.'
5509:
5510: CODE - the CODE in use for this scanline
5511: useCODE - 1 if the CODE is invalid but it usage has been forced
5512: by the operator
5513: CODE_ignore_dup - 1 if the CODE is a duplicated use when unique
5514: CODEs were selected, but the usage has been
5515: forced by the operator
1.556 weissno 5516: ID - student/employee ID
1.423 albertel 5517: PaperID - if used, the ID number printed on the sheet when the
5518: paper was scanned
5519: FirstName - first name from the sheet
5520: LastName - last name from the sheet
5521:
5522: if just_header was not true these key may also exist
5523:
1.447 foxr 5524: missingerror - a list of bubble ranges that are considered to be answers
5525: to a single question that don't have any bubbles filled in.
5526: Of the form questionnumber:firstbubblenumber:count.
5527: doubleerror - a list of bubble ranges that are considered to be answers
5528: to a single question that have more than one bubble filled in.
5529: Of the form questionnumber::firstbubblenumber:count
5530:
5531: In the above, count is the number of bubble responses in the
5532: input line needed to represent the possible answers to the question.
5533: e.g. a radioresponse with 15 choices in an answer sheet with 10 choices
5534: per line would have count = 2.
5535:
1.423 albertel 5536: maxquest - the number of the last bubble line that was parsed
5537:
5538: (<number> starts at 1)
5539: <number>.answer - zero or more letters representing the selected
5540: letters from the scanline for the bubble line
5541: <number>.
5542: if blank there was either no bubble or there where
5543: multiple bubbles, (consult the keys missingerror and
5544: doubleerror if this is an error condition)
5545:
5546: =cut
5547:
1.82 albertel 5548: sub scantron_parse_scanline {
1.423 albertel 5549: my ($line,$whichline,$scantron_config,$scan_data,$just_header)=@_;
1.470 foxr 5550:
1.82 albertel 5551: my %record;
1.550 raeburn 5552: my $lastpos = $env{'form.scantron_maxbubble'}*$$scantron_config{'Qlength'};
5553: my $questions=substr($line,$$scantron_config{'Qstart'}-1,$lastpos); # Answers
1.422 foxr 5554: my $data=substr($line,0,$$scantron_config{'Qstart'}-1); # earlier stuff
1.278 albertel 5555: if (!($$scantron_config{'CODElocation'} eq 0 ||
5556: $$scantron_config{'CODElocation'} eq 'none')) {
5557: if ($$scantron_config{'CODElocation'} < 0 ||
5558: $$scantron_config{'CODElocation'} eq 'letter' ||
5559: $$scantron_config{'CODElocation'} eq 'number') {
1.191 albertel 5560: $record{'scantron.CODE'}=substr($data,
5561: $$scantron_config{'CODEstart'}-1,
1.83 albertel 5562: $$scantron_config{'CODElength'});
1.191 albertel 5563: if (&scan_data($scan_data,"$whichline.useCODE")) {
5564: $record{'scantron.useCODE'}=1;
5565: }
1.192 albertel 5566: if (&scan_data($scan_data,"$whichline.CODE_ignore_dup")) {
5567: $record{'scantron.CODE_ignore_dup'}=1;
5568: }
1.82 albertel 5569: } else {
5570: #FIXME interpret first N questions
5571: }
5572: }
1.83 albertel 5573: $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
5574: $$scantron_config{'IDlength'});
1.157 albertel 5575: $record{'scantron.PaperID'}=
5576: substr($data,$$scantron_config{'PaperID'}-1,
5577: $$scantron_config{'PaperIDlength'});
5578: $record{'scantron.FirstName'}=
5579: substr($data,$$scantron_config{'FirstName'}-1,
5580: $$scantron_config{'FirstNamelength'});
5581: $record{'scantron.LastName'}=
5582: substr($data,$$scantron_config{'LastName'}-1,
5583: $$scantron_config{'LastNamelength'});
1.423 albertel 5584: if ($just_header) { return \%record; }
1.194 albertel 5585:
1.82 albertel 5586: my @alphabet=('A'..'Z');
5587: my $questnum=0;
1.447 foxr 5588: my $ansnum =1; # Multiple 'answer lines'/question.
5589:
1.470 foxr 5590: chomp($questions); # Get rid of any trailing \n.
5591: $questions =~ s/\r$//; # Get rid of trailing \r too (MAC or Win uploads).
5592: while (length($questions)) {
1.447 foxr 5593: my $answers_needed = $bubble_lines_per_response{$questnum};
1.503 raeburn 5594: my $answer_length = ($$scantron_config{'Qlength'} * $answers_needed)
5595: || 1;
5596: $questnum++;
5597: my $quest_id = $questnum;
5598: my $currentquest = substr($questions,0,$answer_length);
5599: $questions = substr($questions,$answer_length);
5600: if (length($currentquest) < $answer_length) { next; }
5601:
5602: if ($subdivided_bubble_lines{$questnum-1} =~ /,/) {
5603: my $subquestnum = 1;
5604: my $subquestions = $currentquest;
5605: my @subanswers_needed =
5606: split(/,/,$subdivided_bubble_lines{$questnum-1});
5607: foreach my $subans (@subanswers_needed) {
5608: my $subans_length =
5609: ($$scantron_config{'Qlength'} * $subans) || 1;
5610: my $currsubquest = substr($subquestions,0,$subans_length);
5611: $subquestions = substr($subquestions,$subans_length);
5612: $quest_id = "$questnum.$subquestnum";
5613: if (($$scantron_config{'Qon'} eq 'letter') ||
5614: ($$scantron_config{'Qon'} eq 'number')) {
5615: $ansnum = &scantron_validator_lettnum($ansnum,
5616: $questnum,$quest_id,$subans,$currsubquest,$whichline,
5617: \@alphabet,\%record,$scantron_config,$scan_data);
5618: } else {
5619: $ansnum = &scantron_validator_positional($ansnum,
5620: $questnum,$quest_id,$subans,$currsubquest,$whichline, \@alphabet,\%record,$scantron_config,$scan_data);
5621: }
5622: $subquestnum ++;
5623: }
5624: } else {
5625: if (($$scantron_config{'Qon'} eq 'letter') ||
5626: ($$scantron_config{'Qon'} eq 'number')) {
5627: $ansnum = &scantron_validator_lettnum($ansnum,$questnum,
5628: $quest_id,$answers_needed,$currentquest,$whichline,
5629: \@alphabet,\%record,$scantron_config,$scan_data);
5630: } else {
5631: $ansnum = &scantron_validator_positional($ansnum,$questnum,
5632: $quest_id,$answers_needed,$currentquest,$whichline,
5633: \@alphabet,\%record,$scantron_config,$scan_data);
5634: }
5635: }
5636: }
5637: $record{'scantron.maxquest'}=$questnum;
5638: return \%record;
5639: }
1.447 foxr 5640:
1.503 raeburn 5641: sub scantron_validator_lettnum {
5642: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,$whichline,
5643: $alphabet,$record,$scantron_config,$scan_data) = @_;
5644:
5645: # Qon 'letter' implies for each slot in currquest we have:
5646: # ? or * for doubles, a letter in A-Z for a bubble, and
5647: # about anything else (esp. a value of Qoff) for missing
5648: # bubbles.
5649: #
5650: # Qon 'number' implies each slot gives a digit that indexes the
5651: # bubbles filled, or Qoff, or a non-number for unbubbled lines,
5652: # and * or ? for double bubbles on a single line.
5653: #
1.447 foxr 5654:
1.503 raeburn 5655: my $matchon;
5656: if ($$scantron_config{'Qon'} eq 'letter') {
5657: $matchon = '[A-Z]';
5658: } elsif ($$scantron_config{'Qon'} eq 'number') {
5659: $matchon = '\d';
5660: }
5661: my $occurrences = 0;
5662: if (($responsetype_per_response{$questnum-1} eq 'essayresponse') ||
5663: ($responsetype_per_response{$questnum-1} eq 'formularesponse') ||
1.510 raeburn 5664: ($responsetype_per_response{$questnum-1} eq 'stringresponse') ||
5665: ($responsetype_per_response{$questnum-1} eq 'imageresponse') ||
5666: ($responsetype_per_response{$questnum-1} eq 'reactionresponse') ||
5667: ($responsetype_per_response{$questnum-1} eq 'organicresponse')) {
1.503 raeburn 5668: my @singlelines = split('',$currquest);
5669: foreach my $entry (@singlelines) {
5670: $occurrences = &occurence_count($entry,$matchon);
5671: if ($occurrences > 1) {
5672: last;
5673: }
5674: }
5675: } else {
5676: $occurrences = &occurence_count($currquest,$matchon);
5677: }
5678: if (($currquest =~ /\?/ || $currquest =~ /\*/) || ($occurrences > 1)) {
5679: push(@{$record->{'scantron.doubleerror'}},$quest_id);
5680: for (my $ans=0; $ans<$answers_needed; $ans++) {
5681: my $bubble = substr($currquest,$ans,1);
5682: if ($bubble =~ /$matchon/ ) {
5683: if ($$scantron_config{'Qon'} eq 'number') {
5684: if ($bubble == 0) {
5685: $bubble = 10;
5686: }
5687: $record->{"scantron.$ansnum.answer"} =
5688: $alphabet->[$bubble-1];
5689: } else {
5690: $record->{"scantron.$ansnum.answer"} = $bubble;
5691: }
5692: } else {
5693: $record->{"scantron.$ansnum.answer"}='';
5694: }
5695: $ansnum++;
5696: }
5697: } elsif (!defined($currquest)
5698: || (&occurence_count($currquest, $$scantron_config{'Qoff'}) == length($currquest))
5699: || (&occurence_count($currquest,$matchon) == 0)) {
5700: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
5701: $record->{"scantron.$ansnum.answer"}='';
5702: $ansnum++;
5703: }
5704: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
5705: push(@{$record->{'scantron.missingerror'}},$quest_id);
5706: }
5707: } else {
5708: if ($$scantron_config{'Qon'} eq 'number') {
5709: $currquest = &digits_to_letters($currquest);
5710: }
5711: for (my $ans=0; $ans<$answers_needed; $ans++) {
5712: my $bubble = substr($currquest,$ans,1);
5713: $record->{"scantron.$ansnum.answer"} = $bubble;
5714: $ansnum++;
5715: }
5716: }
5717: return $ansnum;
5718: }
1.447 foxr 5719:
1.503 raeburn 5720: sub scantron_validator_positional {
5721: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,
5722: $whichline,$alphabet,$record,$scantron_config,$scan_data) = @_;
1.447 foxr 5723:
1.503 raeburn 5724: # Otherwise there's a positional notation;
5725: # each bubble line requires Qlength items, and there are filled in
5726: # bubbles for each case where there 'Qon' characters.
5727: #
1.447 foxr 5728:
1.503 raeburn 5729: my @array=split($$scantron_config{'Qon'},$currquest,-1);
1.447 foxr 5730:
1.503 raeburn 5731: # If the split only gives us one element.. the full length of the
5732: # answer string, no bubbles are filled in:
1.447 foxr 5733:
1.507 raeburn 5734: if ($answers_needed eq '') {
5735: return;
5736: }
5737:
1.503 raeburn 5738: if (length($array[0]) eq $$scantron_config{'Qlength'}*$answers_needed) {
5739: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
5740: $record->{"scantron.$ansnum.answer"}='';
5741: $ansnum++;
5742: }
5743: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
5744: push(@{$record->{"scantron.missingerror"}},$quest_id);
5745: }
5746: } elsif (scalar(@array) == 2) {
5747: my $location = length($array[0]);
5748: my $line_num = int($location / $$scantron_config{'Qlength'});
5749: my $bubble = $alphabet->[$location % $$scantron_config{'Qlength'}];
5750: for (my $ans=0; $ans<$answers_needed; $ans++) {
5751: if ($ans eq $line_num) {
5752: $record->{"scantron.$ansnum.answer"} = $bubble;
5753: } else {
5754: $record->{"scantron.$ansnum.answer"} = ' ';
5755: }
5756: $ansnum++;
5757: }
5758: } else {
5759: # If there's more than one instance of a bubble character
5760: # That's a double bubble; with positional notation we can
5761: # record all the bubbles filled in as well as the
5762: # fact this response consists of multiple bubbles.
5763: #
5764: if (($responsetype_per_response{$questnum-1} eq 'essayresponse') ||
5765: ($responsetype_per_response{$questnum-1} eq 'formularesponse') ||
1.510 raeburn 5766: ($responsetype_per_response{$questnum-1} eq 'stringresponse') ||
5767: ($responsetype_per_response{$questnum-1} eq 'imageresponse') ||
5768: ($responsetype_per_response{$questnum-1} eq 'reactionresponse') ||
5769: ($responsetype_per_response{$questnum-1} eq 'organicresponse')) {
1.503 raeburn 5770: my $doubleerror = 0;
5771: while (($currquest >= $$scantron_config{'Qlength'}) &&
5772: (!$doubleerror)) {
5773: my $currline = substr($currquest,0,$$scantron_config{'Qlength'});
5774: $currquest = substr($currquest,$$scantron_config{'Qlength'});
5775: my @currarray = split($$scantron_config{'Qon'},$currline,-1);
5776: if (length(@currarray) > 2) {
5777: $doubleerror = 1;
5778: }
5779: }
5780: if ($doubleerror) {
5781: push(@{$record->{'scantron.doubleerror'}},$quest_id);
5782: }
5783: } else {
5784: push(@{$record->{'scantron.doubleerror'}},$quest_id);
5785: }
5786: my $item = $ansnum;
5787: for (my $ans=0; $ans<$answers_needed; $ans++) {
5788: $record->{"scantron.$item.answer"} = '';
5789: $item ++;
5790: }
1.447 foxr 5791:
1.503 raeburn 5792: my @ans=@array;
5793: my $i=0;
5794: my $increment = 0;
5795: while ($#ans) {
5796: $i+=length($ans[0]) + $increment;
5797: my $line = int($i/$$scantron_config{'Qlength'} + $ansnum);
5798: my $bubble = $i%$$scantron_config{'Qlength'};
5799: $record->{"scantron.$line.answer"}.=$alphabet->[$bubble];
5800: shift(@ans);
5801: $increment = 1;
5802: }
5803: $ansnum += $answers_needed;
1.82 albertel 5804: }
1.503 raeburn 5805: return $ansnum;
1.82 albertel 5806: }
5807:
1.423 albertel 5808: =pod
5809:
5810: =item scantron_add_delay
5811:
5812: Adds an error message that occurred during the grading phase to a
5813: queue of messages to be shown after grading pass is complete
5814:
5815: Arguments:
1.424 albertel 5816: $delayqueue - arrary ref of hash ref of error messages
1.423 albertel 5817: $scanline - the scanline that caused the error
5818: $errormesage - the error message
5819: $errorcode - a numeric code for the error
5820:
5821: Side Effects:
1.424 albertel 5822: updates the $delayqueue to have a new hash ref of the error
1.423 albertel 5823:
5824: =cut
5825:
1.82 albertel 5826: sub scantron_add_delay {
1.140 albertel 5827: my ($delayqueue,$scanline,$errormessage,$errorcode)=@_;
5828: push(@$delayqueue,
5829: {'line' => $scanline, 'emsg' => $errormessage,
5830: 'ecode' => $errorcode }
5831: );
1.82 albertel 5832: }
5833:
1.423 albertel 5834: =pod
5835:
5836: =item scantron_find_student
5837:
1.424 albertel 5838: Finds the username for the current scanline
5839:
5840: Arguments:
5841: $scantron_record - hash result from scantron_parse_scanline
5842: $scan_data - hash of correction information
5843: (see &scantron_getfile() form more information)
5844: $idmap - hash from &username_to_idmap()
5845: $line - number of current scanline
5846:
5847: Returns:
5848: Either 'username:domain' or undef if unknown
5849:
1.423 albertel 5850: =cut
5851:
1.82 albertel 5852: sub scantron_find_student {
1.157 albertel 5853: my ($scantron_record,$scan_data,$idmap,$line)=@_;
1.83 albertel 5854: my $scanID=$$scantron_record{'scantron.ID'};
1.157 albertel 5855: if ($scanID =~ /^\s*$/) {
5856: return &scan_data($scan_data,"$line.user");
5857: }
1.83 albertel 5858: foreach my $id (keys(%$idmap)) {
1.157 albertel 5859: if (lc($id) eq lc($scanID)) {
5860: return $$idmap{$id};
5861: }
1.83 albertel 5862: }
5863: return undef;
5864: }
5865:
1.423 albertel 5866: =pod
5867:
5868: =item scantron_filter
5869:
1.424 albertel 5870: Filter sub for lonnavmaps, filters out hidden resources if ignore
5871: hidden resources was selected
5872:
1.423 albertel 5873: =cut
5874:
1.83 albertel 5875: sub scantron_filter {
5876: my ($curres)=@_;
1.331 albertel 5877:
5878: if (ref($curres) && $curres->is_problem()) {
5879: # if the user has asked to not have either hidden
5880: # or 'randomout' controlled resources to be graded
5881: # don't include them
5882: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
5883: && $curres->randomout) {
5884: return 0;
5885: }
1.83 albertel 5886: return 1;
5887: }
5888: return 0;
1.82 albertel 5889: }
5890:
1.423 albertel 5891: =pod
5892:
5893: =item scantron_process_corrections
5894:
1.424 albertel 5895: Gets correction information out of submitted form data and corrects
5896: the scanline
5897:
1.423 albertel 5898: =cut
5899:
1.157 albertel 5900: sub scantron_process_corrections {
5901: my ($r) = @_;
1.257 albertel 5902: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5903: my ($scanlines,$scan_data)=&scantron_getfile();
5904: my $classlist=&Apache::loncoursedata::get_classlist();
1.257 albertel 5905: my $which=$env{'form.scantron_line'};
1.200 albertel 5906: my $line=&scantron_get_line($scanlines,$scan_data,$which);
1.157 albertel 5907: my ($skip,$err,$errmsg);
1.257 albertel 5908: if ($env{'form.scantron_skip_record'}) {
1.157 albertel 5909: $skip=1;
1.257 albertel 5910: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)ID$/) {
5911: my $newstudent=$env{'form.scantron_username'}.':'.
5912: $env{'form.scantron_domain'};
1.157 albertel 5913: my $newid=$classlist->{$newstudent}->[&Apache::loncoursedata::CL_ID];
5914: ($line,$err,$errmsg)=
5915: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
5916: 'ID',{'newid'=>$newid,
1.257 albertel 5917: 'username'=>$env{'form.scantron_username'},
5918: 'domain'=>$env{'form.scantron_domain'}});
5919: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)CODE$/) {
5920: my $resolution=$env{'form.scantron_CODE_resolution'};
1.190 albertel 5921: my $newCODE;
1.192 albertel 5922: my %args;
1.190 albertel 5923: if ($resolution eq 'use_unfound') {
1.191 albertel 5924: $newCODE='use_unfound';
1.190 albertel 5925: } elsif ($resolution eq 'use_found') {
1.257 albertel 5926: $newCODE=$env{'form.scantron_CODE_selectedvalue'};
1.190 albertel 5927: } elsif ($resolution eq 'use_typed') {
1.257 albertel 5928: $newCODE=$env{'form.scantron_CODE_newvalue'};
1.194 albertel 5929: } elsif ($resolution =~ /^use_closest_(\d+)/) {
1.257 albertel 5930: $newCODE=$env{"form.scantron_CODE_closest_$1"};
1.190 albertel 5931: }
1.257 albertel 5932: if ($env{'form.scantron_corrections'} eq 'duplicateCODE') {
1.192 albertel 5933: $args{'CODE_ignore_dup'}=1;
5934: }
5935: $args{'CODE'}=$newCODE;
1.186 albertel 5936: ($line,$err,$errmsg)=
5937: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
1.192 albertel 5938: 'CODE',\%args);
1.257 albertel 5939: } elsif ($env{'form.scantron_corrections'} =~ /^(missing|double)bubble$/) {
5940: foreach my $question (split(',',$env{'form.scantron_questions'})) {
1.157 albertel 5941: ($line,$err,$errmsg)=
5942: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,
5943: $which,'answer',
5944: { 'question'=>$question,
1.503 raeburn 5945: 'response'=>$env{"form.scantron_correct_Q_$question"},
5946: 'questionnum'=>$env{"form.scantron_questionnum_Q_$question"}});
1.157 albertel 5947: if ($err) { last; }
5948: }
5949: }
5950: if ($err) {
1.398 albertel 5951: $r->print("<span class=\"LC_warning\">Unable to accept last correction, an error occurred :$errmsg:</span>");
1.157 albertel 5952: } else {
1.200 albertel 5953: &scantron_put_line($scanlines,$scan_data,$which,$line,$skip);
1.157 albertel 5954: &scantron_putfile($scanlines,$scan_data);
5955: }
5956: }
5957:
1.423 albertel 5958: =pod
5959:
5960: =item reset_skipping_status
5961:
1.424 albertel 5962: Forgets the current set of remember skipped scanlines (and thus
5963: reverts back to considering all lines in the
5964: scantron_skipped_<filename> file)
5965:
1.423 albertel 5966: =cut
5967:
1.200 albertel 5968: sub reset_skipping_status {
5969: my ($scanlines,$scan_data)=&scantron_getfile();
5970: &scan_data($scan_data,'remember_skipping',undef,1);
5971: &scantron_putfile(undef,$scan_data);
5972: }
5973:
1.423 albertel 5974: =pod
5975:
5976: =item start_skipping
5977:
1.424 albertel 5978: Marks a scanline to be skipped.
5979:
1.423 albertel 5980: =cut
5981:
1.376 albertel 5982: sub start_skipping {
1.200 albertel 5983: my ($scan_data,$i)=@_;
5984: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 5985: if ($env{'form.scantron_options_redo'} =~ /^redo_/) {
5986: $remembered{$i}=2;
5987: } else {
5988: $remembered{$i}=1;
5989: }
1.200 albertel 5990: &scan_data($scan_data,'remember_skipping',join(':',%remembered));
5991: }
5992:
1.423 albertel 5993: =pod
5994:
5995: =item should_be_skipped
5996:
1.424 albertel 5997: Checks whether a scanline should be skipped.
5998:
1.423 albertel 5999: =cut
6000:
1.200 albertel 6001: sub should_be_skipped {
1.376 albertel 6002: my ($scanlines,$scan_data,$i)=@_;
1.257 albertel 6003: if ($env{'form.scantron_options_redo'} !~ /^redo_/) {
1.200 albertel 6004: # not redoing old skips
1.376 albertel 6005: if ($scanlines->{'skipped'}[$i]) { return 1; }
1.200 albertel 6006: return 0;
6007: }
6008: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 6009:
6010: if (exists($remembered{$i}) && $remembered{$i} != 2 ) {
6011: return 0;
6012: }
1.200 albertel 6013: return 1;
6014: }
6015:
1.423 albertel 6016: =pod
6017:
6018: =item remember_current_skipped
6019:
1.424 albertel 6020: Discovers what scanlines are in the scantron_skipped_<filename>
6021: file and remembers them into scan_data for later use.
6022:
1.423 albertel 6023: =cut
6024:
1.200 albertel 6025: sub remember_current_skipped {
6026: my ($scanlines,$scan_data)=&scantron_getfile();
6027: my %to_remember;
6028: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
6029: if ($scanlines->{'skipped'}[$i]) {
6030: $to_remember{$i}=1;
6031: }
6032: }
1.376 albertel 6033:
1.200 albertel 6034: &scan_data($scan_data,'remember_skipping',join(':',%to_remember));
6035: &scantron_putfile(undef,$scan_data);
6036: }
6037:
1.423 albertel 6038: =pod
6039:
6040: =item check_for_error
6041:
1.424 albertel 6042: Checks if there was an error when attempting to remove a specific
6043: scantron_.. bubble sheet data file. Prints out an error if
6044: something went wrong.
6045:
1.423 albertel 6046: =cut
6047:
1.200 albertel 6048: sub check_for_error {
6049: my ($r,$result)=@_;
6050: if ($result ne 'ok' && $result ne 'not_found' ) {
1.492 albertel 6051: $r->print(&mt("An error occurred ([_1]) when trying to remove the existing corrections.",$result));
1.200 albertel 6052: }
6053: }
1.157 albertel 6054:
1.423 albertel 6055: =pod
6056:
6057: =item scantron_warning_screen
6058:
1.424 albertel 6059: Interstitial screen to make sure the operator has selected the
6060: correct options before we start the validation phase.
6061:
1.423 albertel 6062: =cut
6063:
1.203 albertel 6064: sub scantron_warning_screen {
6065: my ($button_text)=@_;
1.257 albertel 6066: my $title=&Apache::lonnet::gettitle($env{'form.selectpage'});
1.284 albertel 6067: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.373 albertel 6068: my $CODElist;
1.284 albertel 6069: if ($scantron_config{'CODElocation'} &&
6070: $scantron_config{'CODEstart'} &&
6071: $scantron_config{'CODElength'}) {
6072: $CODElist=$env{'form.scantron_CODElist'};
1.398 albertel 6073: if ($env{'form.scantron_CODElist'} eq '') { $CODElist='<span class="LC_warning">None</span>'; }
1.284 albertel 6074: $CODElist=
1.492 albertel 6075: '<tr><td><b>'.&mt('List of CODES to validate against:').'</b></td><td><tt>'.
1.373 albertel 6076: $env{'form.scantron_CODElist'}.'</tt></td></tr>';
1.284 albertel 6077: }
1.492 albertel 6078: return ('
1.203 albertel 6079: <p>
1.492 albertel 6080: <span class="LC_warning">
6081: '.&mt('Please double check the information below before clicking on \'[_1]\'',&mt($button_text)).'</span>
1.203 albertel 6082: </p>
6083: <table>
1.492 albertel 6084: <tr><td><b>'.&mt('Sequence to be Graded:').'</b></td><td>'.$title.'</td></tr>
6085: <tr><td><b>'.&mt('Data File that will be used:').'</b></td><td><tt>'.$env{'form.scantron_selectfile'}.'</tt></td></tr>
6086: '.$CODElist.'
1.203 albertel 6087: </table>
6088: <br />
1.492 albertel 6089: <p> '.&mt('If this information is correct, please click on \'[_1]\'.',&mt($button_text)).'</p>
6090: <p> '.&mt('If something is incorrect, please click the \'Grading Menu\' button to start over.').'</p>
1.203 albertel 6091:
6092: <br />
1.492 albertel 6093: ');
1.203 albertel 6094: }
6095:
1.423 albertel 6096: =pod
6097:
6098: =item scantron_do_warning
6099:
1.424 albertel 6100: Check if the operator has picked something for all required
6101: fields. Error out if something is missing.
6102:
1.423 albertel 6103: =cut
6104:
1.203 albertel 6105: sub scantron_do_warning {
6106: my ($r)=@_;
1.324 albertel 6107: my ($symb)=&get_symb($r);
1.203 albertel 6108: if (!$symb) {return '';}
1.324 albertel 6109: my $default_form_data=&defaultFormData($symb);
1.203 albertel 6110: $r->print(&scantron_form_start().$default_form_data);
1.257 albertel 6111: if ( $env{'form.selectpage'} eq '' ||
6112: $env{'form.scantron_selectfile'} eq '' ||
6113: $env{'form.scantron_format'} eq '' ) {
1.492 albertel 6114: $r->print("<p>".&mt('You have forgetten to specify some information. Please go Back and try again.')."</p>");
1.257 albertel 6115: if ( $env{'form.selectpage'} eq '') {
1.492 albertel 6116: $r->print('<p><span class="LC_error">'.&mt('You have not selected a Sequence to grade').'</span></p>');
1.237 albertel 6117: }
1.257 albertel 6118: if ( $env{'form.scantron_selectfile'} eq '') {
1.492 albertel 6119: $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 6120: }
1.257 albertel 6121: if ( $env{'form.scantron_format'} eq '') {
1.492 albertel 6122: $r->print('<p><span class="LC_error">'.&mt('You have not selected a the format of the student\'s response data.').'</span></p>');
1.237 albertel 6123: }
6124: } else {
1.265 www 6125: my $warning=&scantron_warning_screen('Grading: Validate Records');
1.492 albertel 6126: $r->print('
6127: '.$warning.'
6128: <input type="submit" name="submit" value="'.&mt('Grading: Validate Records').'" />
1.203 albertel 6129: <input type="hidden" name="command" value="scantron_validate" />
1.492 albertel 6130: ');
1.237 albertel 6131: }
1.352 albertel 6132: $r->print("</form><br />".&show_grading_menu_form($symb));
1.203 albertel 6133: return '';
6134: }
6135:
1.423 albertel 6136: =pod
6137:
6138: =item scantron_form_start
6139:
1.424 albertel 6140: html hidden input for remembering all selected grading options
6141:
1.423 albertel 6142: =cut
6143:
1.203 albertel 6144: sub scantron_form_start {
6145: my ($max_bubble)=@_;
6146: my $result= <<SCANTRONFORM;
6147: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
1.257 albertel 6148: <input type="hidden" name="selectpage" value="$env{'form.selectpage'}" />
6149: <input type="hidden" name="scantron_format" value="$env{'form.scantron_format'}" />
6150: <input type="hidden" name="scantron_selectfile" value="$env{'form.scantron_selectfile'}" />
1.218 albertel 6151: <input type="hidden" name="scantron_maxbubble" value="$max_bubble" />
1.257 albertel 6152: <input type="hidden" name="scantron_CODElist" value="$env{'form.scantron_CODElist'}" />
6153: <input type="hidden" name="scantron_CODEunique" value="$env{'form.scantron_CODEunique'}" />
6154: <input type="hidden" name="scantron_options_redo" value="$env{'form.scantron_options_redo'}" />
6155: <input type="hidden" name="scantron_options_ignore" value="$env{'form.scantron_options_ignore'}" />
1.331 albertel 6156: <input type="hidden" name="scantron_options_hidden" value="$env{'form.scantron_options_hidden'}" />
1.203 albertel 6157: SCANTRONFORM
1.447 foxr 6158:
6159: my $line = 0;
6160: while (defined($env{"form.scantron.bubblelines.$line"})) {
6161: my $chunk =
6162: '<input type="hidden" name="scantron.bubblelines.'.$line.'" value="'.$env{"form.scantron.bubblelines.$line"}.'" />'."\n";
1.448 foxr 6163: $chunk .=
6164: '<input type="hidden" name="scantron.first_bubble_line.'.$line.'" value="'.$env{"form.scantron.first_bubble_line.$line"}.'" />'."\n";
1.503 raeburn 6165: $chunk .=
6166: '<input type="hidden" name="scantron.sub_bubblelines.'.$line.'" value="'.$env{"form.scantron.sub_bubblelines.$line"}.'" />'."\n";
1.504 raeburn 6167: $chunk .=
6168: '<input type="hidden" name="scantron.responsetype.'.$line.'" value="'.$env{"form.scantron.responsetype.$line"}.'" />'."\n";
1.447 foxr 6169: $result .= $chunk;
6170: $line++;
6171: }
1.203 albertel 6172: return $result;
6173: }
6174:
1.423 albertel 6175: =pod
6176:
6177: =item scantron_validate_file
6178:
1.424 albertel 6179: Dispatch routine for doing validation of a bubble sheet data file.
6180:
6181: Also processes any necessary information resets that need to
6182: occur before validation begins (ignore previous corrections,
6183: restarting the skipped records processing)
6184:
1.423 albertel 6185: =cut
6186:
1.157 albertel 6187: sub scantron_validate_file {
6188: my ($r) = @_;
1.324 albertel 6189: my ($symb)=&get_symb($r);
1.157 albertel 6190: if (!$symb) {return '';}
1.324 albertel 6191: my $default_form_data=&defaultFormData($symb);
1.200 albertel 6192:
6193: # do the detection of only doing skipped records first befroe we delete
1.424 albertel 6194: # them when doing the corrections reset
1.257 albertel 6195: if ($env{'form.scantron_options_redo'} ne 'redo_skipped_ready') {
1.200 albertel 6196: &reset_skipping_status();
6197: }
1.257 albertel 6198: if ($env{'form.scantron_options_redo'} eq 'redo_skipped') {
1.200 albertel 6199: &remember_current_skipped();
1.257 albertel 6200: $env{'form.scantron_options_redo'}='redo_skipped_ready';
1.200 albertel 6201: }
6202:
1.257 albertel 6203: if ($env{'form.scantron_options_ignore'} eq 'ignore_corrections') {
1.200 albertel 6204: &check_for_error($r,&scantron_remove_file('corrected'));
6205: &check_for_error($r,&scantron_remove_file('skipped'));
6206: &check_for_error($r,&scantron_remove_scan_data());
1.257 albertel 6207: $env{'form.scantron_options_ignore'}='done';
1.192 albertel 6208: }
1.200 albertel 6209:
1.257 albertel 6210: if ($env{'form.scantron_corrections'}) {
1.157 albertel 6211: &scantron_process_corrections($r);
6212: }
1.503 raeburn 6213: $r->print('<p>'.&mt('Gathering necessary information.').'</p>');$r->rflush();
1.157 albertel 6214: #get the student pick code ready
6215: $r->print(&Apache::loncommon::studentbrowser_javascript());
1.330 albertel 6216: my $max_bubble=&scantron_get_maxbubble();
1.203 albertel 6217: my $result=&scantron_form_start($max_bubble).$default_form_data;
1.157 albertel 6218: $r->print($result);
6219:
1.334 albertel 6220: my @validate_phases=( 'sequence',
6221: 'ID',
1.157 albertel 6222: 'CODE',
6223: 'doublebubble',
6224: 'missingbubbles');
1.257 albertel 6225: if (!$env{'form.validatepass'}) {
6226: $env{'form.validatepass'} = 0;
1.157 albertel 6227: }
1.257 albertel 6228: my $currentphase=$env{'form.validatepass'};
1.157 albertel 6229:
1.448 foxr 6230:
1.157 albertel 6231: my $stop=0;
6232: while (!$stop && $currentphase < scalar(@validate_phases)) {
1.503 raeburn 6233: $r->print(&mt('Validating '.$validate_phases[$currentphase]).'<br />');
1.157 albertel 6234: $r->rflush();
6235: my $which="scantron_validate_".$validate_phases[$currentphase];
6236: {
6237: no strict 'refs';
6238: ($stop,$currentphase)=&$which($r,$currentphase);
6239: }
6240: }
6241: if (!$stop) {
1.203 albertel 6242: my $warning=&scantron_warning_screen('Start Grading');
1.542 raeburn 6243: $r->print(&mt('Validation process complete.').'<br />'.
6244: $warning.
6245: &mt('Perform verification for each student after storage of submissions?').
6246: ' <span class="LC_nobreak"><label>'.
6247: '<input type="radio" name="verifyrecord" value="1" />'.&mt('Yes').'</label>'.
6248: (' 'x3).'<label>'.
6249: '<input type="radio" name="verifyrecord" value="0" checked="checked" />'.&mt('No').
6250: '</label></span><br />'.
6251: &mt('Grading will take longer if you use verification.').'<br />'.
1.572 www 6252: &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 6253: '<input type="submit" name="submit" value="'.&mt('Start Grading').'" />'.
6254: '<input type="hidden" name="command" value="scantron_process" />'."\n");
1.157 albertel 6255: } else {
6256: $r->print('<input type="hidden" name="command" value="scantron_validate" />');
6257: $r->print("<input type='hidden' name='validatepass' value='".$currentphase."' />");
6258: }
6259: if ($stop) {
1.334 albertel 6260: if ($validate_phases[$currentphase] eq 'sequence') {
1.539 riegler 6261: $r->print('<input type="submit" name="submit" value="'.&mt('Ignore').' → " />');
1.492 albertel 6262: $r->print(' '.&mt('this error').' <br />');
1.334 albertel 6263:
1.492 albertel 6264: $r->print(" <p>".&mt("Or click the 'Grading Menu' button to start over.")."</p>");
1.334 albertel 6265: } else {
1.503 raeburn 6266: if ($validate_phases[$currentphase] eq 'doublebubble' || $validate_phases[$currentphase] eq 'missingbubbles') {
1.539 riegler 6267: $r->print('<input type="button" name="submitbutton" value="'.&mt('Continue').' →" onclick="javascript:verify_bubble_radio(this.form)" />');
1.503 raeburn 6268: } else {
1.539 riegler 6269: $r->print('<input type="submit" name="submit" value="'.&mt('Continue').' →" />');
1.503 raeburn 6270: }
1.492 albertel 6271: $r->print(' '.&mt('using corrected info').' <br />');
6272: $r->print("<input type='submit' value='".&mt("Skip")."' name='scantron_skip_record' />");
6273: $r->print(" ".&mt("this scanline saving it for later."));
1.334 albertel 6274: }
1.157 albertel 6275: }
1.352 albertel 6276: $r->print(" </form><br />".&show_grading_menu_form($symb));
1.157 albertel 6277: return '';
6278: }
6279:
1.423 albertel 6280:
6281: =pod
6282:
6283: =item scantron_remove_file
6284:
1.424 albertel 6285: Removes the requested bubble sheet data file, makes sure that
6286: scantron_original_<filename> is never removed
6287:
6288:
1.423 albertel 6289: =cut
6290:
1.200 albertel 6291: sub scantron_remove_file {
1.192 albertel 6292: my ($which)=@_;
1.257 albertel 6293: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6294: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 6295: my $file='scantron_';
1.200 albertel 6296: if ($which eq 'corrected' || $which eq 'skipped') {
6297: $file.=$which.'_';
1.192 albertel 6298: } else {
6299: return 'refused';
6300: }
1.257 albertel 6301: $file.=$env{'form.scantron_selectfile'};
1.200 albertel 6302: return &Apache::lonnet::removeuserfile($cname,$cdom,$file);
6303: }
6304:
1.423 albertel 6305:
6306: =pod
6307:
6308: =item scantron_remove_scan_data
6309:
1.424 albertel 6310: Removes all scan_data correction for the requested bubble sheet
6311: data file. (In the case that both the are doing skipped records we need
6312: to remember the old skipped lines for the time being so that element
6313: persists for a while.)
6314:
1.423 albertel 6315: =cut
6316:
1.200 albertel 6317: sub scantron_remove_scan_data {
1.257 albertel 6318: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6319: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 6320: my @keys=&Apache::lonnet::getkeys('nohist_scantrondata',$cdom,$cname);
6321: my @todelete;
1.257 albertel 6322: my $filename=$env{'form.scantron_selectfile'};
1.192 albertel 6323: foreach my $key (@keys) {
6324: if ($key=~/^\Q$filename\E_/) {
1.257 albertel 6325: if ($env{'form.scantron_options_redo'} eq 'redo_skipped_ready' &&
1.200 albertel 6326: $key=~/remember_skipping/) {
6327: next;
6328: }
1.192 albertel 6329: push(@todelete,$key);
6330: }
6331: }
1.200 albertel 6332: my $result;
1.192 albertel 6333: if (@todelete) {
1.491 albertel 6334: $result = &Apache::lonnet::del('nohist_scantrondata',
6335: \@todelete,$cdom,$cname);
6336: } else {
6337: $result = 'ok';
1.192 albertel 6338: }
6339: return $result;
6340: }
6341:
1.423 albertel 6342:
6343: =pod
6344:
6345: =item scantron_getfile
6346:
1.424 albertel 6347: Fetches the requested bubble sheet data file (all 3 versions), and
6348: the scan_data hash
6349:
6350: Arguments:
6351: None
6352:
6353: Returns:
6354: 2 hash references
6355:
6356: - first one has
6357: orig -
6358: corrected -
6359: skipped - each of which points to an array ref of the specified
6360: file broken up into individual lines
6361: count - number of scanlines
6362:
6363: - second is the scan_data hash possible keys are
1.425 albertel 6364: ($number refers to scanline numbered $number and thus the key affects
6365: only that scanline
6366: $bubline refers to the specific bubble line element and the aspects
6367: refers to that specific bubble line element)
6368:
6369: $number.user - username:domain to use
6370: $number.CODE_ignore_dup
6371: - ignore the duplicate CODE error
6372: $number.useCODE
6373: - use the CODE in the scanline as is
6374: $number.no_bubble.$bubline
6375: - it is valid that there is no bubbled in bubble
6376: at $number $bubline
6377: remember_skipping
6378: - a frozen hash containing keys of $number and values
6379: of either
6380: 1 - we are on a 'do skipped records pass' and plan
6381: on processing this line
6382: 2 - we are on a 'do skipped records pass' and this
6383: scanline has been marked to skip yet again
1.424 albertel 6384:
1.423 albertel 6385: =cut
6386:
1.157 albertel 6387: sub scantron_getfile {
1.200 albertel 6388: #FIXME really would prefer a scantron directory
1.257 albertel 6389: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6390: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.157 albertel 6391: my $lines;
6392: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6393: 'scantron_orig_'.$env{'form.scantron_selectfile'});
1.157 albertel 6394: my %scanlines;
6395: $scanlines{'orig'}=[(split("\n",$lines,-1))];
6396: my $temp=$scanlines{'orig'};
6397: $scanlines{'count'}=$#$temp;
6398:
6399: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6400: 'scantron_corrected_'.$env{'form.scantron_selectfile'});
1.157 albertel 6401: if ($lines eq '-1') {
6402: $scanlines{'corrected'}=[];
6403: } else {
6404: $scanlines{'corrected'}=[(split("\n",$lines,-1))];
6405: }
6406: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6407: 'scantron_skipped_'.$env{'form.scantron_selectfile'});
1.157 albertel 6408: if ($lines eq '-1') {
6409: $scanlines{'skipped'}=[];
6410: } else {
6411: $scanlines{'skipped'}=[(split("\n",$lines,-1))];
6412: }
1.175 albertel 6413: my @tmp=&Apache::lonnet::dump('nohist_scantrondata',$cdom,$cname);
1.157 albertel 6414: if ($tmp[0] =~ /^(error:|no_such_host)/) { @tmp=(); }
6415: my %scan_data = @tmp;
6416: return (\%scanlines,\%scan_data);
6417: }
6418:
1.423 albertel 6419: =pod
6420:
6421: =item lonnet_putfile
6422:
1.424 albertel 6423: Wrapper routine to call &Apache::lonnet::finishuserfileupload
6424:
6425: Arguments:
6426: $contents - data to store
6427: $filename - filename to store $contents into
6428:
6429: Returns:
6430: result value from &Apache::lonnet::finishuserfileupload
6431:
1.423 albertel 6432: =cut
6433:
1.157 albertel 6434: sub lonnet_putfile {
6435: my ($contents,$filename)=@_;
1.257 albertel 6436: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6437: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6438: $env{'form.sillywaytopassafilearound'}=$contents;
1.275 albertel 6439: &Apache::lonnet::finishuserfileupload($docuname,$docudom,'sillywaytopassafilearound',$filename);
1.157 albertel 6440:
6441: }
6442:
1.423 albertel 6443: =pod
6444:
6445: =item scantron_putfile
6446:
1.424 albertel 6447: Stores the current version of the bubble sheet data files, and the
6448: scan_data hash. (Does not modify the original version only the
6449: corrected and skipped versions.
6450:
6451: Arguments:
6452: $scanlines - hash ref that looks like the first return value from
6453: &scantron_getfile()
6454: $scan_data - hash ref that looks like the second return value from
6455: &scantron_getfile()
6456:
1.423 albertel 6457: =cut
6458:
1.157 albertel 6459: sub scantron_putfile {
6460: my ($scanlines,$scan_data) = @_;
1.200 albertel 6461: #FIXME really would prefer a scantron directory
1.257 albertel 6462: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6463: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.200 albertel 6464: if ($scanlines) {
6465: my $prefix='scantron_';
1.157 albertel 6466: # no need to update orig, shouldn't change
6467: # &lonnet_putfile(join("\n",@{$scanlines->{'orig'}}),$prefix.'orig_'.
1.257 albertel 6468: # $env{'form.scantron_selectfile'});
1.200 albertel 6469: &lonnet_putfile(join("\n",@{$scanlines->{'corrected'}}),
6470: $prefix.'corrected_'.
1.257 albertel 6471: $env{'form.scantron_selectfile'});
1.200 albertel 6472: &lonnet_putfile(join("\n",@{$scanlines->{'skipped'}}),
6473: $prefix.'skipped_'.
1.257 albertel 6474: $env{'form.scantron_selectfile'});
1.200 albertel 6475: }
1.175 albertel 6476: &Apache::lonnet::put('nohist_scantrondata',$scan_data,$cdom,$cname);
1.157 albertel 6477: }
6478:
1.423 albertel 6479: =pod
6480:
6481: =item scantron_get_line
6482:
1.424 albertel 6483: Returns the correct version of the scanline
6484:
6485: Arguments:
6486: $scanlines - hash ref that looks like the first return value from
6487: &scantron_getfile()
6488: $scan_data - hash ref that looks like the second return value from
6489: &scantron_getfile()
6490: $i - number of the requested line (starts at 0)
6491:
6492: Returns:
6493: A scanline, (either the original or the corrected one if it
6494: exists), or undef if the requested scanline should be
6495: skipped. (Either because it's an skipped scanline, or it's an
6496: unskipped scanline and we are not doing a 'do skipped scanlines'
6497: pass.
6498:
1.423 albertel 6499: =cut
6500:
1.157 albertel 6501: sub scantron_get_line {
1.200 albertel 6502: my ($scanlines,$scan_data,$i)=@_;
1.376 albertel 6503: if (&should_be_skipped($scanlines,$scan_data,$i)) { return undef; }
6504: #if ($scanlines->{'skipped'}[$i]) { return undef; }
1.157 albertel 6505: if ($scanlines->{'corrected'}[$i]) {return $scanlines->{'corrected'}[$i];}
6506: return $scanlines->{'orig'}[$i];
6507: }
6508:
1.423 albertel 6509: =pod
6510:
6511: =item scantron_todo_count
6512:
1.424 albertel 6513: Counts the number of scanlines that need processing.
6514:
6515: Arguments:
6516: $scanlines - hash ref that looks like the first return value from
6517: &scantron_getfile()
6518: $scan_data - hash ref that looks like the second return value from
6519: &scantron_getfile()
6520:
6521: Returns:
6522: $count - number of scanlines to process
6523:
1.423 albertel 6524: =cut
6525:
1.200 albertel 6526: sub get_todo_count {
6527: my ($scanlines,$scan_data)=@_;
6528: my $count=0;
6529: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
6530: my $line=&scantron_get_line($scanlines,$scan_data,$i);
6531: if ($line=~/^[\s\cz]*$/) { next; }
6532: $count++;
6533: }
6534: return $count;
6535: }
6536:
1.423 albertel 6537: =pod
6538:
6539: =item scantron_put_line
6540:
1.424 albertel 6541: Updates the 'corrected' or 'skipped' versions of the bubble sheet
6542: data file.
6543:
6544: Arguments:
6545: $scanlines - hash ref that looks like the first return value from
6546: &scantron_getfile()
6547: $scan_data - hash ref that looks like the second return value from
6548: &scantron_getfile()
6549: $i - line number to update
6550: $newline - contents of the updated scanline
6551: $skip - if true make the line for skipping and update the
6552: 'skipped' file
6553:
1.423 albertel 6554: =cut
6555:
1.157 albertel 6556: sub scantron_put_line {
1.200 albertel 6557: my ($scanlines,$scan_data,$i,$newline,$skip)=@_;
1.157 albertel 6558: if ($skip) {
6559: $scanlines->{'skipped'}[$i]=$newline;
1.376 albertel 6560: &start_skipping($scan_data,$i);
1.157 albertel 6561: return;
6562: }
6563: $scanlines->{'corrected'}[$i]=$newline;
6564: }
6565:
1.423 albertel 6566: =pod
6567:
6568: =item scantron_clear_skip
6569:
1.424 albertel 6570: Remove a line from the 'skipped' file
6571:
6572: Arguments:
6573: $scanlines - hash ref that looks like the first return value from
6574: &scantron_getfile()
6575: $scan_data - hash ref that looks like the second return value from
6576: &scantron_getfile()
6577: $i - line number to update
6578:
1.423 albertel 6579: =cut
6580:
1.376 albertel 6581: sub scantron_clear_skip {
6582: my ($scanlines,$scan_data,$i)=@_;
6583: if (exists($scanlines->{'skipped'}[$i])) {
6584: undef($scanlines->{'skipped'}[$i]);
6585: return 1;
6586: }
6587: return 0;
6588: }
6589:
1.423 albertel 6590: =pod
6591:
6592: =item scantron_filter_not_exam
6593:
1.424 albertel 6594: Filter routine used by &Apache::lonnavmaps::retrieveResources(), to
6595: filter out resources that are not marked as 'exam' mode
6596:
1.423 albertel 6597: =cut
6598:
1.334 albertel 6599: sub scantron_filter_not_exam {
6600: my ($curres)=@_;
6601:
6602: if (ref($curres) && $curres->is_problem() && !$curres->is_exam()) {
6603: # if the user has asked to not have either hidden
6604: # or 'randomout' controlled resources to be graded
6605: # don't include them
6606: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
6607: && $curres->randomout) {
6608: return 0;
6609: }
6610: return 1;
6611: }
6612: return 0;
6613: }
6614:
1.423 albertel 6615: =pod
6616:
6617: =item scantron_validate_sequence
6618:
1.424 albertel 6619: Validates the selected sequence, checking for resource that are
6620: not set to exam mode.
6621:
1.423 albertel 6622: =cut
6623:
1.334 albertel 6624: sub scantron_validate_sequence {
6625: my ($r,$currentphase) = @_;
6626:
6627: my $navmap=Apache::lonnavmaps::navmap->new();
6628: my (undef,undef,$sequence)=
6629: &Apache::lonnet::decode_symb($env{'form.selectpage'});
6630:
6631: my $map=$navmap->getResourceByUrl($sequence);
6632:
6633: $r->print('<input type="hidden" name="validate_sequence_exam"
6634: value="ignore" />');
6635: if ($env{'form.validate_sequence_exam'} ne 'ignore') {
6636: my @resources=
6637: $navmap->retrieveResources($map,\&scantron_filter_not_exam,1,0);
6638: if (@resources) {
1.357 banghart 6639: $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 6640: return (1,$currentphase);
6641: }
6642: }
6643:
6644: return (0,$currentphase+1);
6645: }
6646:
1.423 albertel 6647:
6648:
1.157 albertel 6649: sub scantron_validate_ID {
6650: my ($r,$currentphase) = @_;
6651:
6652: #get student info
6653: my $classlist=&Apache::loncoursedata::get_classlist();
6654: my %idmap=&username_to_idmap($classlist);
6655:
6656: #get scantron line setup
1.257 albertel 6657: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 6658: my ($scanlines,$scan_data)=&scantron_getfile();
1.447 foxr 6659:
6660: &scantron_get_maxbubble(); # parse needs the bubble_lines.. array.
1.157 albertel 6661:
6662: my %found=('ids'=>{},'usernames'=>{});
6663: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 6664: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 6665: if ($line=~/^[\s\cz]*$/) { next; }
6666: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
6667: $scan_data);
6668: my $id=$$scan_record{'scantron.ID'};
6669: my $found;
6670: foreach my $checkid (keys(%idmap)) {
6671: if (lc($checkid) eq lc($id)) { $found=$checkid;last; }
6672: }
6673: if ($found) {
6674: my $username=$idmap{$found};
6675: if ($found{'ids'}{$found}) {
6676: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
6677: $line,'duplicateID',$found);
1.194 albertel 6678: return(1,$currentphase);
1.157 albertel 6679: } elsif ($found{'usernames'}{$username}) {
6680: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
6681: $line,'duplicateID',$username);
1.194 albertel 6682: return(1,$currentphase);
1.157 albertel 6683: }
1.186 albertel 6684: #FIXME store away line we previously saw the ID on to use above
1.157 albertel 6685: $found{'ids'}{$found}++;
6686: $found{'usernames'}{$username}++;
6687: } else {
6688: if ($id =~ /^\s*$/) {
1.158 albertel 6689: my $username=&scan_data($scan_data,"$i.user");
1.157 albertel 6690: if (defined($username) && $found{'usernames'}{$username}) {
6691: &scantron_get_correction($r,$i,$scan_record,
6692: \%scantron_config,
6693: $line,'duplicateID',$username);
1.194 albertel 6694: return(1,$currentphase);
1.157 albertel 6695: } elsif (!defined($username)) {
6696: &scantron_get_correction($r,$i,$scan_record,
6697: \%scantron_config,
6698: $line,'incorrectID');
1.194 albertel 6699: return(1,$currentphase);
1.157 albertel 6700: }
6701: $found{'usernames'}{$username}++;
6702: } else {
6703: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
6704: $line,'incorrectID');
1.194 albertel 6705: return(1,$currentphase);
1.157 albertel 6706: }
6707: }
6708: }
6709:
6710: return (0,$currentphase+1);
6711: }
6712:
1.423 albertel 6713:
1.157 albertel 6714: sub scantron_get_correction {
6715: my ($r,$i,$scan_record,$scan_config,$line,$error,$arg)=@_;
1.454 banghart 6716: #FIXME in the case of a duplicated ID the previous line, probably need
1.157 albertel 6717: #to show both the current line and the previous one and allow skipping
6718: #the previous one or the current one
6719:
1.333 albertel 6720: if ( $$scan_record{'scantron.PaperID'} =~ /\S/) {
1.492 albertel 6721: $r->print("<p>".&mt("<b>An error was detected ($error)</b>".
6722: " for PaperID <tt>[_1]</tt>",
6723: $$scan_record{'scantron.PaperID'})."</p> \n");
1.157 albertel 6724: } else {
1.492 albertel 6725: $r->print("<p>".&mt("<b>An error was detected ($error)</b>".
6726: " in scanline [_1] <pre>[_2]</pre>",
6727: $i,$line)."</p> \n");
6728: }
6729: my $message="<p>".&mt("The ID on the form is <tt>[_1]</tt><br />".
6730: "The name on the paper is [_2],[_3]",
6731: $$scan_record{'scantron.ID'},
6732: $$scan_record{'scantron.LastName'},
6733: $$scan_record{'scantron.FirstName'})."</p>";
1.242 albertel 6734:
1.157 albertel 6735: $r->print('<input type="hidden" name="scantron_corrections" value="'.$error.'" />'."\n");
6736: $r->print('<input type="hidden" name="scantron_line" value="'.$i.'" />'."\n");
1.503 raeburn 6737: # Array populated for doublebubble or
6738: my @lines_to_correct; # missingbubble errors to build javascript
6739: # to validate radio button checking
6740:
1.157 albertel 6741: if ($error =~ /ID$/) {
1.186 albertel 6742: if ($error eq 'incorrectID') {
1.492 albertel 6743: $r->print("<p>".&mt("The encoded ID is not in the classlist").
6744: "</p>\n");
1.157 albertel 6745: } elsif ($error eq 'duplicateID') {
1.492 albertel 6746: $r->print("<p>".&mt("The encoded ID has also been used by a previous paper [_1]",$arg)."</p>\n");
1.157 albertel 6747: }
1.242 albertel 6748: $r->print($message);
1.492 albertel 6749: $r->print("<p>".&mt("How should I handle this?")." <br /> \n");
1.157 albertel 6750: $r->print("\n<ul><li> ");
6751: #FIXME it would be nice if this sent back the user ID and
6752: #could do partial userID matches
6753: $r->print(&Apache::loncommon::selectstudent_link('scantronupload',
6754: 'scantron_username','scantron_domain'));
6755: $r->print(": <input type='text' name='scantron_username' value='' />");
6756: $r->print("\n@".
1.257 albertel 6757: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'scantron_domain'));
1.157 albertel 6758:
6759: $r->print('</li>');
1.186 albertel 6760: } elsif ($error =~ /CODE$/) {
6761: if ($error eq 'incorrectCODE') {
1.492 albertel 6762: $r->print("<p>".&mt("The encoded CODE is not in the list of possible CODEs.")."</p>\n");
1.186 albertel 6763: } elsif ($error eq 'duplicateCODE') {
1.492 albertel 6764: $r->print("<p>".&mt("The encoded CODE has also been used by a previous paper [_1], and CODEs are supposed to be unique.",join(', ',@{$arg}))."</p>\n");
1.186 albertel 6765: }
1.492 albertel 6766: $r->print("<p>".&mt("The CODE on the form is <tt>'[_1]'</tt>",
6767: $$scan_record{'scantron.CODE'})."<br />\n");
1.242 albertel 6768: $r->print($message);
1.492 albertel 6769: $r->print("<p>".&mt("How should I handle this?")." <br /> \n");
1.187 albertel 6770: $r->print("\n<br /> ");
1.194 albertel 6771: my $i=0;
1.273 albertel 6772: if ($error eq 'incorrectCODE'
6773: && $$scan_record{'scantron.CODE'}=~/\S/ ) {
1.194 albertel 6774: my ($max,$closest)=&scantron_get_closely_matching_CODEs($arg,$$scan_record{'scantron.CODE'});
1.278 albertel 6775: if ($closest > 0) {
6776: foreach my $testcode (@{$closest}) {
6777: my $checked='';
1.569 bisitz 6778: if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 6779: $r->print("
6780: <label>
1.569 bisitz 6781: <input type='radio' name='scantron_CODE_resolution' value='use_closest_$i'$checked />
1.492 albertel 6782: ".&mt("Use the similar CODE [_1] instead.",
6783: "<b><tt>".$testcode."</tt></b>")."
6784: </label>
6785: <input type='hidden' name='scantron_CODE_closest_$i' value='$testcode' />");
1.278 albertel 6786: $r->print("\n<br />");
6787: $i++;
6788: }
1.194 albertel 6789: }
6790: }
1.273 albertel 6791: if ($$scan_record{'scantron.CODE'}=~/\S/ ) {
1.569 bisitz 6792: my $checked; if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 6793: $r->print("
6794: <label>
1.569 bisitz 6795: <input type='radio' name='scantron_CODE_resolution' value='use_unfound'$checked />
1.492 albertel 6796: ".&mt("Use the CODE [_1] that is was on the paper, ignoring the error.",
6797: "<b><tt>".$$scan_record{'scantron.CODE'}."</tt></b>")."
6798: </label>");
1.273 albertel 6799: $r->print("\n<br />");
6800: }
1.194 albertel 6801:
1.188 albertel 6802: $r->print(<<ENDSCRIPT);
6803: <script type="text/javascript">
6804: function change_radio(field) {
1.190 albertel 6805: var slct=document.scantronupload.scantron_CODE_resolution;
1.188 albertel 6806: var i;
6807: for (i=0;i<slct.length;i++) {
6808: if (slct[i].value==field) { slct[i].checked=true; }
6809: }
6810: }
6811: </script>
6812: ENDSCRIPT
1.187 albertel 6813: my $href="/adm/pickcode?".
1.359 www 6814: "form=".&escape("scantronupload").
6815: "&scantron_format=".&escape($env{'form.scantron_format'}).
6816: "&scantron_CODElist=".&escape($env{'form.scantron_CODElist'}).
6817: "&curCODE=".&escape($$scan_record{'scantron.CODE'}).
6818: "&scantron_selectfile=".&escape($env{'form.scantron_selectfile'});
1.332 albertel 6819: if ($env{'form.scantron_CODElist'} =~ /\S/) {
1.492 albertel 6820: $r->print("
6821: <label>
6822: <input type='radio' name='scantron_CODE_resolution' value='use_found' />
6823: ".&mt("[_1]Select[_2] a CODE from the list of all CODEs and use it.",
6824: "<a target='_blank' href='$href'>","</a>")."
6825: </label>
1.558 bisitz 6826: ".&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 6827: $r->print("\n<br />");
6828: }
1.492 albertel 6829: $r->print("
6830: <label>
6831: <input type='radio' name='scantron_CODE_resolution' value='use_typed' />
6832: ".&mt("Use [_1] as the CODE.",
6833: "</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 6834: $r->print("\n<br /><br />");
1.157 albertel 6835: } elsif ($error eq 'doublebubble') {
1.503 raeburn 6836: $r->print("<p>".&mt("There have been multiple bubbles scanned for some question(s)")."</p>\n");
1.497 foxr 6837:
6838: # The form field scantron_questions is acutally a list of line numbers.
6839: # represented by this form so:
6840:
6841: my $line_list = &questions_to_line_list($arg);
6842:
1.157 albertel 6843: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 6844: $line_list.'" />');
1.242 albertel 6845: $r->print($message);
1.492 albertel 6846: $r->print("<p>".&mt("Please indicate which bubble should be used for grading")."</p>");
1.157 albertel 6847: foreach my $question (@{$arg}) {
1.503 raeburn 6848: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
6849: $scan_record, $error);
1.524 raeburn 6850: push(@lines_to_correct,@linenums);
1.157 albertel 6851: }
1.503 raeburn 6852: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 6853: } elsif ($error eq 'missingbubble') {
1.492 albertel 6854: $r->print("<p>".&mt("There have been <b>no</b> bubbles scanned for some question(s)")."</p>\n");
1.242 albertel 6855: $r->print($message);
1.492 albertel 6856: $r->print("<p>".&mt("Please indicate which bubble should be used for grading.")."</p>");
1.503 raeburn 6857: $r->print(&mt("Some questions have no scanned bubbles.")."\n");
1.497 foxr 6858:
1.503 raeburn 6859: # The form field scantron_questions is actually a list of line numbers not
1.497 foxr 6860: # a list of question numbers. Therefore:
6861: #
6862:
6863: my $line_list = &questions_to_line_list($arg);
6864:
1.157 albertel 6865: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 6866: $line_list.'" />');
1.157 albertel 6867: foreach my $question (@{$arg}) {
1.503 raeburn 6868: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
6869: $scan_record, $error);
1.524 raeburn 6870: push(@lines_to_correct,@linenums);
1.157 albertel 6871: }
1.503 raeburn 6872: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 6873: } else {
6874: $r->print("\n<ul>");
6875: }
6876: $r->print("\n</li></ul>");
1.497 foxr 6877: }
6878:
1.503 raeburn 6879: sub verify_bubbles_checked {
6880: my (@ansnums) = @_;
6881: my $ansnumstr = join('","',@ansnums);
6882: my $warning = &mt("A bubble or 'No bubble' selection has not been made for one or more lines.");
6883: my $output = (<<ENDSCRIPT);
6884: <script type="text/javascript">
6885: function verify_bubble_radio(form) {
6886: var ansnumArray = new Array ("$ansnumstr");
6887: var need_bubble_count = 0;
6888: for (var i=0; i<ansnumArray.length; i++) {
6889: if (form.elements["scantron_correct_Q_"+ansnumArray[i]].length > 1) {
6890: var bubble_picked = 0;
6891: for (var j=0; j<form.elements["scantron_correct_Q_"+ansnumArray[i]].length; j++) {
6892: if (form.elements["scantron_correct_Q_"+ansnumArray[i]][j].checked == true) {
6893: bubble_picked = 1;
6894: }
6895: }
6896: if (bubble_picked == 0) {
6897: need_bubble_count ++;
6898: }
6899: }
6900: }
6901: if (need_bubble_count) {
6902: alert("$warning");
6903: return;
6904: }
6905: form.submit();
6906: }
6907: </script>
6908: ENDSCRIPT
6909: return $output;
6910: }
6911:
1.497 foxr 6912: =pod
6913:
6914: =item questions_to_line_list
1.157 albertel 6915:
1.497 foxr 6916: Converts a list of questions into a string of comma separated
6917: line numbers in the answer sheet used by the questions. This is
6918: used to fill in the scantron_questions form field.
6919:
6920: Arguments:
6921: questions - Reference to an array of questions.
6922:
6923: =cut
6924:
6925:
6926: sub questions_to_line_list {
6927: my ($questions) = @_;
6928: my @lines;
6929:
1.503 raeburn 6930: foreach my $item (@{$questions}) {
6931: my $question = $item;
6932: my ($first,$count,$last);
6933: if ($item =~ /^(\d+)\.(\d+)$/) {
6934: $question = $1;
6935: my $subquestion = $2;
6936: $first = $first_bubble_line{$question-1} + 1;
6937: my @subans = split(/,/,$subdivided_bubble_lines{$question-1});
6938: my $subcount = 1;
6939: while ($subcount<$subquestion) {
6940: $first += $subans[$subcount-1];
6941: $subcount ++;
6942: }
6943: $count = $subans[$subquestion-1];
6944: } else {
6945: $first = $first_bubble_line{$question-1} + 1;
6946: $count = $bubble_lines_per_response{$question-1};
6947: }
1.506 raeburn 6948: $last = $first+$count-1;
1.503 raeburn 6949: push(@lines, ($first..$last));
1.497 foxr 6950: }
6951: return join(',', @lines);
6952: }
6953:
6954: =pod
6955:
6956: =item prompt_for_corrections
6957:
6958: Prompts for a potentially multiline correction to the
6959: user's bubbling (factors out common code from scantron_get_correction
6960: for multi and missing bubble cases).
6961:
6962: Arguments:
6963: $r - Apache request object.
6964: $question - The question number to prompt for.
6965: $scan_config - The scantron file configuration hash.
6966: $scan_record - Reference to the hash that has the the parsed scanlines.
1.503 raeburn 6967: $error - Type of error
1.497 foxr 6968:
6969: Implicit inputs:
6970: %bubble_lines_per_response - Starting line numbers for each question.
6971: Numbered from 0 (but question numbers are from
6972: 1.
6973: %first_bubble_line - Starting bubble line for each question.
1.509 raeburn 6974: %subdivided_bubble_lines - optionresponse, matchresponse and rankresponse
6975: type problems render as separate sub-questions,
1.503 raeburn 6976: in exam mode. This hash contains a
6977: comma-separated list of the lines per
6978: sub-question.
1.510 raeburn 6979: %responsetype_per_response - essayresponse, formularesponse,
6980: stringresponse, imageresponse, reactionresponse,
6981: and organicresponse type problem parts can have
1.503 raeburn 6982: multiple lines per response if the weight
6983: assigned exceeds 10. In this case, only
6984: one bubble per line is permitted, but more
6985: than one line might contain bubbles, e.g.
6986: bubbling of: line 1 - J, line 2 - J,
6987: line 3 - B would assign 22 points.
1.497 foxr 6988:
6989: =cut
6990:
6991: sub prompt_for_corrections {
1.503 raeburn 6992: my ($r, $question, $scan_config, $scan_record, $error) = @_;
6993: my ($current_line,$lines);
6994: my @linenums;
6995: my $questionnum = $question;
6996: if ($question =~ /^(\d+)\.(\d+)$/) {
6997: $question = $1;
6998: $current_line = $first_bubble_line{$question-1} + 1 ;
6999: my $subquestion = $2;
7000: my @subans = split(/,/,$subdivided_bubble_lines{$question-1});
7001: my $subcount = 1;
7002: while ($subcount<$subquestion) {
7003: $current_line += $subans[$subcount-1];
7004: $subcount ++;
7005: }
7006: $lines = $subans[$subquestion-1];
7007: } else {
7008: $current_line = $first_bubble_line{$question-1} + 1 ;
7009: $lines = $bubble_lines_per_response{$question-1};
7010: }
1.497 foxr 7011: if ($lines > 1) {
1.503 raeburn 7012: $r->print(&mt('The group of bubble lines below responds to a single question.').'<br />');
7013: if (($responsetype_per_response{$question-1} eq 'essayresponse') ||
7014: ($responsetype_per_response{$question-1} eq 'formularesponse') ||
1.510 raeburn 7015: ($responsetype_per_response{$question-1} eq 'stringresponse') ||
7016: ($responsetype_per_response{$question-1} eq 'imageresponse') ||
7017: ($responsetype_per_response{$question-1} eq 'reactionresponse') ||
7018: ($responsetype_per_response{$question-1} eq 'organicresponse')) {
1.572 www 7019: $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 7020: } else {
7021: $r->print(&mt("Select at most one bubble in a single line and select 'No Bubble' in all the other lines. ")."<br />");
7022: }
1.497 foxr 7023: }
7024: for (my $i =0; $i < $lines; $i++) {
1.503 raeburn 7025: my $selected = $$scan_record{"scantron.$current_line.answer"};
7026: &scantron_bubble_selector($r,$scan_config,$current_line,
7027: $questionnum,$error,split('', $selected));
1.524 raeburn 7028: push(@linenums,$current_line);
1.497 foxr 7029: $current_line++;
7030: }
7031: if ($lines > 1) {
7032: $r->print("<hr /><br />");
7033: }
1.503 raeburn 7034: return @linenums;
1.157 albertel 7035: }
1.423 albertel 7036:
7037: =pod
7038:
7039: =item scantron_bubble_selector
7040:
7041: Generates the html radiobuttons to correct a single bubble line
1.424 albertel 7042: possibly showing the existing the selected bubbles if known
1.423 albertel 7043:
7044: Arguments:
7045: $r - Apache request object
7046: $scan_config - hash from &get_scantron_config()
1.497 foxr 7047: $line - Number of the line being displayed.
1.503 raeburn 7048: $questionnum - Question number (may include subquestion)
7049: $error - Type of error.
1.497 foxr 7050: @selected - Array of bubbles picked on this line.
1.423 albertel 7051:
7052: =cut
7053:
1.157 albertel 7054: sub scantron_bubble_selector {
1.503 raeburn 7055: my ($r,$scan_config,$line,$questionnum,$error,@selected)=@_;
1.157 albertel 7056: my $max=$$scan_config{'Qlength'};
1.274 albertel 7057:
7058: my $scmode=$$scan_config{'Qon'};
7059: if ($scmode eq 'number' || $scmode eq 'letter') { $max=10; }
7060:
1.157 albertel 7061: my @alphabet=('A'..'Z');
1.503 raeburn 7062: $r->print(&Apache::loncommon::start_data_table().
7063: &Apache::loncommon::start_data_table_row());
7064: $r->print('<td rowspan="2" class="LC_leftcol_header">'.$line.'</td>');
1.497 foxr 7065: for (my $i=0;$i<$max+1;$i++) {
7066: $r->print("\n".'<td align="center">');
7067: if ($selected[0] eq $alphabet[$i]) { $r->print('X'); shift(@selected) }
7068: else { $r->print(' '); }
7069: $r->print('</td>');
7070: }
1.503 raeburn 7071: $r->print(&Apache::loncommon::end_data_table_row().
7072: &Apache::loncommon::start_data_table_row());
1.497 foxr 7073: for (my $i=0;$i<$max;$i++) {
7074: $r->print("\n".
7075: '<td><label><input type="radio" name="scantron_correct_Q_'.
7076: $line.'" value="'.$i.'" />'.$alphabet[$i]."</label></td>");
7077: }
1.503 raeburn 7078: my $nobub_checked = ' ';
7079: if ($error eq 'missingbubble') {
7080: $nobub_checked = ' checked = "checked" ';
7081: }
7082: $r->print("\n".'<td><label><input type="radio" name="scantron_correct_Q_'.
7083: $line.'" value="none"'.$nobub_checked.'/>'.&mt('No bubble').
7084: '</label>'."\n".'<input type="hidden" name="scantron_questionnum_Q_'.
7085: $line.'" value="'.$questionnum.'" /></td>');
7086: $r->print(&Apache::loncommon::end_data_table_row().
7087: &Apache::loncommon::end_data_table());
1.157 albertel 7088: }
7089:
1.423 albertel 7090: =pod
7091:
7092: =item num_matches
7093:
1.424 albertel 7094: Counts the number of characters that are the same between the two arguments.
7095:
7096: Arguments:
7097: $orig - CODE from the scanline
7098: $code - CODE to match against
7099:
7100: Returns:
7101: $count - integer count of the number of same characters between the
7102: two arguments
7103:
1.423 albertel 7104: =cut
7105:
1.194 albertel 7106: sub num_matches {
7107: my ($orig,$code) = @_;
7108: my @code=split(//,$code);
7109: my @orig=split(//,$orig);
7110: my $same=0;
7111: for (my $i=0;$i<scalar(@code);$i++) {
7112: if ($code[$i] eq $orig[$i]) { $same++; }
7113: }
7114: return $same;
7115: }
7116:
1.423 albertel 7117: =pod
7118:
7119: =item scantron_get_closely_matching_CODEs
7120:
1.424 albertel 7121: Cycles through all CODEs and finds the set that has the greatest
7122: number of same characters as the provided CODE
7123:
7124: Arguments:
7125: $allcodes - hash ref returned by &get_codes()
7126: $CODE - CODE from the current scanline
7127:
7128: Returns:
7129: 2 element list
7130: - first elements is number of how closely matching the best fit is
7131: (5 means best set has 5 matching characters)
7132: - second element is an arrary ref containing the set of valid CODEs
7133: that best fit the passed in CODE
7134:
1.423 albertel 7135: =cut
7136:
1.194 albertel 7137: sub scantron_get_closely_matching_CODEs {
7138: my ($allcodes,$CODE)=@_;
7139: my @CODEs;
7140: foreach my $testcode (sort(keys(%{$allcodes}))) {
7141: push(@{$CODEs[&num_matches($CODE,$testcode)]},$testcode);
7142: }
7143:
7144: return ($#CODEs,$CODEs[-1]);
7145: }
7146:
1.423 albertel 7147: =pod
7148:
7149: =item get_codes
7150:
1.424 albertel 7151: Builds a hash which has keys of all of the valid CODEs from the selected
7152: set of remembered CODEs.
7153:
7154: Arguments:
7155: $old_name - name of the set of remembered CODEs
7156: $cdom - domain of the course
7157: $cnum - internal course name
7158:
7159: Returns:
7160: %allcodes - keys are the valid CODEs, values are all 1
7161:
1.423 albertel 7162: =cut
7163:
1.194 albertel 7164: sub get_codes {
1.280 foxr 7165: my ($old_name, $cdom, $cnum) = @_;
7166: if (!$old_name) {
7167: $old_name=$env{'form.scantron_CODElist'};
7168: }
7169: if (!$cdom) {
7170: $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
7171: }
7172: if (!$cnum) {
7173: $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
7174: }
1.278 albertel 7175: my %result=&Apache::lonnet::get('CODEs',[$old_name,"type\0$old_name"],
7176: $cdom,$cnum);
7177: my %allcodes;
7178: if ($result{"type\0$old_name"} eq 'number') {
7179: %allcodes=map {($_,1)} split(',',$result{$old_name});
7180: } else {
7181: %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
7182: }
1.194 albertel 7183: return %allcodes;
7184: }
7185:
1.423 albertel 7186: =pod
7187:
7188: =item scantron_validate_CODE
7189:
1.424 albertel 7190: Validates all scanlines in the selected file to not have any
7191: invalid or underspecified CODEs and that none of the codes are
7192: duplicated if this was requested.
7193:
1.423 albertel 7194: =cut
7195:
1.157 albertel 7196: sub scantron_validate_CODE {
7197: my ($r,$currentphase) = @_;
1.257 albertel 7198: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.186 albertel 7199: if ($scantron_config{'CODElocation'} &&
7200: $scantron_config{'CODEstart'} &&
7201: $scantron_config{'CODElength'}) {
1.257 albertel 7202: if (!defined($env{'form.scantron_CODElist'})) {
1.186 albertel 7203: &FIXME_blow_up()
7204: }
7205: } else {
7206: return (0,$currentphase+1);
7207: }
7208:
7209: my %usedCODEs;
7210:
1.194 albertel 7211: my %allcodes=&get_codes();
1.186 albertel 7212:
1.447 foxr 7213: &scantron_get_maxbubble(); # parse needs the lines per response array.
7214:
1.186 albertel 7215: my ($scanlines,$scan_data)=&scantron_getfile();
7216: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7217: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.186 albertel 7218: if ($line=~/^[\s\cz]*$/) { next; }
7219: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7220: $scan_data);
7221: my $CODE=$$scan_record{'scantron.CODE'};
7222: my $error=0;
1.224 albertel 7223: if (!&Apache::lonnet::validCODE($CODE)) {
7224: &scantron_get_correction($r,$i,$scan_record,
7225: \%scantron_config,
7226: $line,'incorrectCODE',\%allcodes);
7227: return(1,$currentphase);
7228: }
1.221 albertel 7229: if (%allcodes && !exists($allcodes{$CODE})
7230: && !$$scan_record{'scantron.useCODE'}) {
1.186 albertel 7231: &scantron_get_correction($r,$i,$scan_record,
7232: \%scantron_config,
1.194 albertel 7233: $line,'incorrectCODE',\%allcodes);
7234: return(1,$currentphase);
1.186 albertel 7235: }
1.214 albertel 7236: if (exists($usedCODEs{$CODE})
1.257 albertel 7237: && $env{'form.scantron_CODEunique'} eq 'yes'
1.192 albertel 7238: && !$$scan_record{'scantron.CODE_ignore_dup'}) {
1.186 albertel 7239: &scantron_get_correction($r,$i,$scan_record,
7240: \%scantron_config,
1.194 albertel 7241: $line,'duplicateCODE',$usedCODEs{$CODE});
7242: return(1,$currentphase);
1.186 albertel 7243: }
1.524 raeburn 7244: push(@{$usedCODEs{$CODE}},$$scan_record{'scantron.PaperID'});
1.186 albertel 7245: }
1.157 albertel 7246: return (0,$currentphase+1);
7247: }
7248:
1.423 albertel 7249: =pod
7250:
7251: =item scantron_validate_doublebubble
7252:
1.424 albertel 7253: Validates all scanlines in the selected file to not have any
7254: bubble lines with multiple bubbles marked.
7255:
1.423 albertel 7256: =cut
7257:
1.157 albertel 7258: sub scantron_validate_doublebubble {
7259: my ($r,$currentphase) = @_;
7260: #get student info
7261: my $classlist=&Apache::loncoursedata::get_classlist();
7262: my %idmap=&username_to_idmap($classlist);
7263:
7264: #get scantron line setup
1.257 albertel 7265: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7266: my ($scanlines,$scan_data)=&scantron_getfile();
1.447 foxr 7267: &scantron_get_maxbubble(); # parse needs the bubble line array.
7268:
1.157 albertel 7269: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7270: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7271: if ($line=~/^[\s\cz]*$/) { next; }
7272: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7273: $scan_data);
7274: if (!defined($$scan_record{'scantron.doubleerror'})) { next; }
7275: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,$line,
7276: 'doublebubble',
7277: $$scan_record{'scantron.doubleerror'});
7278: return (1,$currentphase);
7279: }
7280: return (0,$currentphase+1);
7281: }
7282:
1.423 albertel 7283:
1.503 raeburn 7284: sub scantron_get_maxbubble {
1.257 albertel 7285: if (defined($env{'form.scantron_maxbubble'}) &&
7286: $env{'form.scantron_maxbubble'}) {
1.447 foxr 7287: &restore_bubble_lines();
1.257 albertel 7288: return $env{'form.scantron_maxbubble'};
1.191 albertel 7289: }
1.330 albertel 7290:
1.447 foxr 7291: my (undef, undef, $sequence) =
1.257 albertel 7292: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.330 albertel 7293:
1.447 foxr 7294: my $navmap=Apache::lonnavmaps::navmap->new();
1.191 albertel 7295: my $map=$navmap->getResourceByUrl($sequence);
7296: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.330 albertel 7297:
7298: &Apache::lonxml::clear_problem_counter();
7299:
1.557 raeburn 7300: my $uname = $env{'user.name'};
7301: my $udom = $env{'user.domain'};
1.435 foxr 7302: my $cid = $env{'request.course.id'};
7303: my $total_lines = 0;
7304: %bubble_lines_per_response = ();
1.447 foxr 7305: %first_bubble_line = ();
1.503 raeburn 7306: %subdivided_bubble_lines = ();
7307: %responsetype_per_response = ();
1.554 raeburn 7308:
1.447 foxr 7309: my $response_number = 0;
7310: my $bubble_line = 0;
1.191 albertel 7311: foreach my $resource (@resources) {
1.542 raeburn 7312: my ($analysis,$parts) = &scantron_partids_tograde($resource,$cid,$uname,$udom);
7313: if ((ref($analysis) eq 'HASH') && (ref($parts) eq 'ARRAY')) {
7314: foreach my $part_id (@{$parts}) {
7315: my $lines;
7316:
7317: # TODO - make this a persistent hash not an array.
7318:
7319: # optionresponse, matchresponse and rankresponse type items
7320: # render as separate sub-questions in exam mode.
7321: if (($analysis->{$part_id.'.type'} eq 'optionresponse') ||
7322: ($analysis->{$part_id.'.type'} eq 'matchresponse') ||
7323: ($analysis->{$part_id.'.type'} eq 'rankresponse')) {
7324: my ($numbub,$numshown);
7325: if ($analysis->{$part_id.'.type'} eq 'optionresponse') {
7326: if (ref($analysis->{$part_id.'.options'}) eq 'ARRAY') {
7327: $numbub = scalar(@{$analysis->{$part_id.'.options'}});
7328: }
7329: } elsif ($analysis->{$part_id.'.type'} eq 'matchresponse') {
7330: if (ref($analysis->{$part_id.'.items'}) eq 'ARRAY') {
7331: $numbub = scalar(@{$analysis->{$part_id.'.items'}});
7332: }
7333: } elsif ($analysis->{$part_id.'.type'} eq 'rankresponse') {
7334: if (ref($analysis->{$part_id.'.foils'}) eq 'ARRAY') {
7335: $numbub = scalar(@{$analysis->{$part_id.'.foils'}});
7336: }
7337: }
7338: if (ref($analysis->{$part_id.'.shown'}) eq 'ARRAY') {
7339: $numshown = scalar(@{$analysis->{$part_id.'.shown'}});
7340: }
7341: my $bubbles_per_line = 10;
7342: my $inner_bubble_lines = int($numbub/$bubbles_per_line);
7343: if (($numbub % $bubbles_per_line) != 0) {
7344: $inner_bubble_lines++;
7345: }
7346: for (my $i=0; $i<$numshown; $i++) {
7347: $subdivided_bubble_lines{$response_number} .=
7348: $inner_bubble_lines.',';
7349: }
7350: $subdivided_bubble_lines{$response_number} =~ s/,$//;
7351: $lines = $numshown * $inner_bubble_lines;
7352: } else {
7353: $lines = $analysis->{"$part_id.bubble_lines"};
7354: }
7355:
7356: $first_bubble_line{$response_number} = $bubble_line;
7357: $bubble_lines_per_response{$response_number} = $lines;
7358: $responsetype_per_response{$response_number} =
7359: $analysis->{$part_id.'.type'};
7360: $response_number++;
7361:
7362: $bubble_line += $lines;
7363: $total_lines += $lines;
7364: }
7365: }
7366: }
1.552 raeburn 7367: &Apache::lonnet::delenv('scantron.');
1.542 raeburn 7368:
7369: &save_bubble_lines();
7370: $env{'form.scantron_maxbubble'} =
7371: $total_lines;
7372: return $env{'form.scantron_maxbubble'};
7373: }
1.523 raeburn 7374:
1.157 albertel 7375: sub scantron_validate_missingbubbles {
7376: my ($r,$currentphase) = @_;
7377: #get student info
7378: my $classlist=&Apache::loncoursedata::get_classlist();
7379: my %idmap=&username_to_idmap($classlist);
7380:
7381: #get scantron line setup
1.257 albertel 7382: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7383: my ($scanlines,$scan_data)=&scantron_getfile();
1.191 albertel 7384: my $max_bubble=&scantron_get_maxbubble();
1.157 albertel 7385: if (!$max_bubble) { $max_bubble=2**31; }
7386: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7387: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7388: if ($line=~/^[\s\cz]*$/) { next; }
7389: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7390: $scan_data);
7391: if (!defined($$scan_record{'scantron.missingerror'})) { next; }
7392: my @to_correct;
1.470 foxr 7393:
7394: # Probably here's where the error is...
7395:
1.157 albertel 7396: foreach my $missing (@{$$scan_record{'scantron.missingerror'}}) {
1.505 raeburn 7397: my $lastbubble;
7398: if ($missing =~ /^(\d+)\.(\d+)$/) {
7399: my $question = $1;
7400: my $subquestion = $2;
7401: if (!defined($first_bubble_line{$question -1})) { next; }
7402: my $first = $first_bubble_line{$question-1};
7403: my @subans = split(/,/,$subdivided_bubble_lines{$question-1});
7404: my $subcount = 1;
7405: while ($subcount<$subquestion) {
7406: $first += $subans[$subcount-1];
7407: $subcount ++;
7408: }
7409: my $count = $subans[$subquestion-1];
7410: $lastbubble = $first + $count;
7411: } else {
7412: if (!defined($first_bubble_line{$missing - 1})) { next; }
7413: $lastbubble = $first_bubble_line{$missing - 1} + $bubble_lines_per_response{$missing - 1};
7414: }
7415: if ($lastbubble > $max_bubble) { next; }
1.157 albertel 7416: push(@to_correct,$missing);
7417: }
7418: if (@to_correct) {
7419: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
7420: $line,'missingbubble',\@to_correct);
7421: return (1,$currentphase);
7422: }
7423:
7424: }
7425: return (0,$currentphase+1);
7426: }
7427:
1.423 albertel 7428:
1.82 albertel 7429: sub scantron_process_students {
1.75 albertel 7430: my ($r) = @_;
1.513 foxr 7431:
1.257 albertel 7432: my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($env{'form.selectpage'});
1.324 albertel 7433: my ($symb)=&get_symb($r);
1.513 foxr 7434: if (!$symb) {
7435: return '';
7436: }
1.324 albertel 7437: my $default_form_data=&defaultFormData($symb);
1.82 albertel 7438:
1.257 albertel 7439: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7440: my ($scanlines,$scan_data)=&scantron_getfile();
1.82 albertel 7441: my $classlist=&Apache::loncoursedata::get_classlist();
7442: my %idmap=&username_to_idmap($classlist);
1.132 bowersj2 7443: my $navmap=Apache::lonnavmaps::navmap->new();
1.83 albertel 7444: my $map=$navmap->getResourceByUrl($sequence);
7445: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.557 raeburn 7446: my (%grader_partids_by_symb,%grader_randomlists_by_symb);
7447: &graders_resources_pass(\@resources,\%grader_partids_by_symb,
7448: \%grader_randomlists_by_symb);
7449: foreach my $resource (@resources) {
7450: my $ressymb = $resource->symb();
7451: my ($analysis,$parts) =
7452: &scantron_partids_tograde($resource,$env{'request.course.id'},
7453: $env{'user.name'},$env{'user.domain'},1);
7454: $grader_partids_by_symb{$ressymb} = $parts;
7455: if (ref($analysis) eq 'HASH') {
7456: if (ref($analysis->{'parts_withrandomlist'}) eq 'ARRAY') {
7457: $grader_randomlists_by_symb{$ressymb} =
7458: $analysis->{'parts_withrandomlist'};
7459: }
7460: }
7461: }
7462:
1.554 raeburn 7463: my ($uname,$udom);
1.82 albertel 7464: my $result= <<SCANTRONFORM;
1.81 albertel 7465: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
7466: <input type="hidden" name="command" value="scantron_configphase" />
7467: $default_form_data
7468: SCANTRONFORM
1.82 albertel 7469: $r->print($result);
7470:
7471: my @delayqueue;
1.542 raeburn 7472: my (%completedstudents,%scandata);
1.140 albertel 7473:
1.520 www 7474: my $lock=&Apache::lonnet::set_lock(&mt('Grading bubblesheet exam'));
1.200 albertel 7475: my $count=&get_todo_count($scanlines,$scan_data);
1.574.2.5! raeburn 7476: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Bubblesheet Status',
! 7477: 'Bubblesheet Progress',$count,
1.195 albertel 7478: 'inline',undef,'scantronupload');
1.140 albertel 7479: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
7480: 'Processing first student');
1.542 raeburn 7481: $r->print('<br />');
1.140 albertel 7482: my $start=&Time::HiRes::time();
1.158 albertel 7483: my $i=-1;
1.542 raeburn 7484: my $started;
1.447 foxr 7485:
7486: &scantron_get_maxbubble(); # Need the bubble lines array to parse.
1.513 foxr 7487:
7488: # If an ssi failed in scantron_get_maxbubble, put an error message out to
7489: # the user and return.
7490:
7491: if ($ssi_error) {
7492: $r->print("</form>");
7493: &ssi_print_error($r);
7494: $r->print(&show_grading_menu_form($symb));
1.520 www 7495: &Apache::lonnet::remove_lock($lock);
1.513 foxr 7496: return ''; # Dunno why the other returns return '' rather than just returning.
7497: }
1.447 foxr 7498:
1.542 raeburn 7499: my %lettdig = &letter_to_digits();
7500: my $numletts = scalar(keys(%lettdig));
7501:
1.157 albertel 7502: while ($i<$scanlines->{'count'}) {
7503: ($uname,$udom)=('','');
7504: $i++;
1.200 albertel 7505: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7506: if ($line=~/^[\s\cz]*$/) { next; }
1.200 albertel 7507: if ($started) {
7508: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
7509: 'last student');
7510: }
7511: $started=1;
1.157 albertel 7512: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7513: $scan_data);
7514: unless ($uname=&scantron_find_student($scan_record,$scan_data,
7515: \%idmap,$i)) {
7516: &scantron_add_delay(\@delayqueue,$line,
7517: 'Unable to find a student that matches',1);
7518: next;
7519: }
7520: if (exists $completedstudents{$uname}) {
7521: &scantron_add_delay(\@delayqueue,$line,
7522: 'Student '.$uname.' has multiple sheets',2);
7523: next;
7524: }
7525: ($uname,$udom)=split(/:/,$uname);
1.330 albertel 7526:
1.554 raeburn 7527: my %partids_by_symb;
7528: foreach my $resource (@resources) {
7529: my $ressymb = $resource->symb();
1.557 raeburn 7530: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
7531: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
7532: my ($analysis,$parts) =
7533: &scantron_partids_tograde($resource,$env{'request.course.id'},$uname,$udom);
7534: $partids_by_symb{$ressymb} = $parts;
7535: } else {
7536: $partids_by_symb{$ressymb} = $grader_partids_by_symb{$ressymb};
7537: }
1.554 raeburn 7538: }
7539:
1.330 albertel 7540: &Apache::lonxml::clear_problem_counter();
1.514 raeburn 7541: &Apache::lonnet::appenv($scan_record);
1.376 albertel 7542:
7543: if (&scantron_clear_skip($scanlines,$scan_data,$i)) {
7544: &scantron_putfile($scanlines,$scan_data);
7545: }
1.161 albertel 7546:
1.542 raeburn 7547: my $scancode;
7548: if ((exists($scan_record->{'scantron.CODE'})) &&
7549: (&Apache::lonnet::validCODE($scan_record->{'scantron.CODE'}))) {
7550: $scancode = $scan_record->{'scantron.CODE'};
7551: } else {
7552: $scancode = '';
7553: }
7554:
7555: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
1.554 raeburn 7556: \@resources,\%partids_by_symb) eq 'ssi_error') {
1.542 raeburn 7557: $ssi_error = 0; # So end of handler error message does not trigger.
7558: $r->print("</form>");
7559: &ssi_print_error($r);
7560: $r->print(&show_grading_menu_form($symb));
7561: &Apache::lonnet::remove_lock($lock);
7562: return ''; # Why return ''? Beats me.
7563: }
1.513 foxr 7564:
1.140 albertel 7565: $completedstudents{$uname}={'line'=>$line};
1.542 raeburn 7566: if ($env{'form.verifyrecord'}) {
7567: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
7568: my $studentdata = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
7569: chomp($studentdata);
7570: $studentdata =~ s/\r$//;
7571: my $studentrecord = '';
7572: my $counter = -1;
7573: foreach my $resource (@resources) {
1.554 raeburn 7574: my $ressymb = $resource->symb();
1.542 raeburn 7575: ($counter,my $recording) =
7576: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 7577: $counter,$studentdata,$partids_by_symb{$ressymb},
1.542 raeburn 7578: \%scantron_config,\%lettdig,$numletts);
7579: $studentrecord .= $recording;
7580: }
7581: if ($studentrecord ne $studentdata) {
1.554 raeburn 7582: &Apache::lonxml::clear_problem_counter();
7583: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
7584: \@resources,\%partids_by_symb) eq 'ssi_error') {
7585: $ssi_error = 0; # So end of handler error message does not trigger.
7586: $r->print("</form>");
7587: &ssi_print_error($r);
7588: $r->print(&show_grading_menu_form($symb));
7589: &Apache::lonnet::remove_lock($lock);
7590: delete($completedstudents{$uname});
7591: return '';
7592: }
1.542 raeburn 7593: $counter = -1;
7594: $studentrecord = '';
7595: foreach my $resource (@resources) {
1.554 raeburn 7596: my $ressymb = $resource->symb();
1.542 raeburn 7597: ($counter,my $recording) =
7598: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 7599: $counter,$studentdata,$partids_by_symb{$ressymb},
1.542 raeburn 7600: \%scantron_config,\%lettdig,$numletts);
7601: $studentrecord .= $recording;
7602: }
7603: if ($studentrecord ne $studentdata) {
7604: $r->print('<p><span class="LC_error">');
7605: if ($scancode eq '') {
7606: $r->print(&mt('Mismatch grading bubble sheet for user: [_1] with ID: [_2].',
7607: $uname.':'.$udom,$scan_record->{'scantron.ID'}));
7608: } else {
7609: $r->print(&mt('Mismatch grading bubble sheet for user: [_1] with ID: [_2] and CODE: [_3].',
7610: $uname.':'.$udom,$scan_record->{'scantron.ID'},$scancode));
7611: }
7612: $r->print('</span><br />'.&Apache::loncommon::start_data_table()."\n".
7613: &Apache::loncommon::start_data_table_header_row()."\n".
7614: '<th>'.&mt('Source').'</th><th>'.&mt('Bubbled responses').'</th>'.
7615: &Apache::loncommon::end_data_table_header_row()."\n".
7616: &Apache::loncommon::start_data_table_row().
7617: '<td>'.&mt('Bubble Sheet').'</td>'.
7618: '<td><span class="LC_nobreak">'.$studentdata.'</span></td>'.
7619: &Apache::loncommon::end_data_table_row().
7620: &Apache::loncommon::start_data_table_row().
7621: '<td>Stored submissions</td>'.
7622: '<td><span class="LC_nobreak">'.$studentrecord.'</span></td>'."\n".
7623: &Apache::loncommon::end_data_table_row().
7624: &Apache::loncommon::end_data_table().'</p>');
7625: } else {
7626: $r->print('<br /><span class="LC_warning">'.
7627: &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 />'.
7628: &mt("As a consequence, this user's submission history records two tries.").
7629: '</span><br />');
7630: }
7631: }
7632: }
1.543 raeburn 7633: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.140 albertel 7634: } continue {
1.330 albertel 7635: &Apache::lonxml::clear_problem_counter();
1.552 raeburn 7636: &Apache::lonnet::delenv('scantron.');
1.82 albertel 7637: }
1.140 albertel 7638: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.520 www 7639: &Apache::lonnet::remove_lock($lock);
1.172 albertel 7640: # my $lasttime = &Time::HiRes::time()-$start;
7641: # $r->print("<p>took $lasttime</p>");
1.140 albertel 7642:
1.200 albertel 7643: $r->print("</form>");
1.324 albertel 7644: $r->print(&show_grading_menu_form($symb));
1.157 albertel 7645: return '';
1.75 albertel 7646: }
1.157 albertel 7647:
1.557 raeburn 7648: sub graders_resources_pass {
7649: my ($resources,$grader_partids_by_symb,$grader_randomlists_by_symb) = @_;
7650: if ((ref($resources) eq 'ARRAY') && (ref($grader_partids_by_symb)) &&
7651: (ref($grader_randomlists_by_symb) eq 'HASH')) {
7652: foreach my $resource (@{$resources}) {
7653: my $ressymb = $resource->symb();
7654: my ($analysis,$parts) =
7655: &scantron_partids_tograde($resource,$env{'request.course.id'},
7656: $env{'user.name'},$env{'user.domain'},1);
7657: $grader_partids_by_symb->{$ressymb} = $parts;
7658: if (ref($analysis) eq 'HASH') {
7659: if (ref($analysis->{'parts_withrandomlist'}) eq 'ARRAY') {
7660: $grader_randomlists_by_symb->{$ressymb} =
7661: $analysis->{'parts_withrandomlist'};
7662: }
7663: }
7664: }
7665: }
7666: return;
7667: }
7668:
1.542 raeburn 7669: sub grade_student_bubbles {
1.554 raeburn 7670: my ($r,$uname,$udom,$scan_record,$scancode,$resources,$parts) = @_;
7671: if (ref($resources) eq 'ARRAY') {
7672: my $count = 0;
7673: foreach my $resource (@{$resources}) {
7674: my $ressymb = $resource->symb();
7675: my %form = ('submitted' => 'scantron',
7676: 'grade_target' => 'grade',
7677: 'grade_username' => $uname,
7678: 'grade_domain' => $udom,
7679: 'grade_courseid' => $env{'request.course.id'},
7680: 'grade_symb' => $ressymb,
7681: 'CODE' => $scancode
7682: );
7683: if (ref($parts) eq 'HASH') {
7684: if (ref($parts->{$ressymb}) eq 'ARRAY') {
7685: foreach my $part (@{$parts->{$ressymb}}) {
7686: $form{'scantron_questnum_start.'.$part} =
7687: 1+$env{'form.scantron.first_bubble_line.'.$count};
7688: $count++;
7689: }
7690: }
7691: }
7692: my $result=&ssi_with_retries($resource->src(),$ssi_retries,%form);
7693: return 'ssi_error' if ($ssi_error);
7694: last if (&Apache::loncommon::connection_aborted($r));
7695: }
1.542 raeburn 7696: }
7697: return;
7698: }
7699:
1.157 albertel 7700: sub scantron_upload_scantron_data {
7701: my ($r)=@_;
1.565 raeburn 7702: my $dom = $env{'request.role.domain'};
7703: my $domdesc = &Apache::lonnet::domain($dom,'description');
7704: $r->print(&Apache::loncommon::coursebrowser_javascript($dom));
1.157 albertel 7705: my $select_link=&Apache::loncommon::selectcourse_link('rules','courseid',
1.181 albertel 7706: 'domainid',
1.565 raeburn 7707: 'coursename',$dom);
7708: my $syllabuslink = '<a href="javascript:ToSyllabus();">'.&mt('Syllabus').'</a>'.
7709: (' 'x2).&mt('(shows course personnel)');
1.324 albertel 7710: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.574.2.3 raeburn 7711: my $nofile_alert = &mt('Please use the browse button to select a file from your local directory.');
7712: 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 7713: $r->print('
1.157 albertel 7714: <script type="text/javascript" language="javascript">
7715: function checkUpload(formname) {
7716: if (formname.upfile.value == "") {
1.574.2.3 raeburn 7717: alert("'.$nofile_alert.'");
1.157 albertel 7718: return false;
7719: }
1.565 raeburn 7720: if (formname.courseid.value == "") {
1.574.2.3 raeburn 7721: alert("'.$nocourseid_alert.'");
1.565 raeburn 7722: return false;
7723: }
1.157 albertel 7724: formname.submit();
7725: }
1.565 raeburn 7726:
7727: function ToSyllabus() {
7728: var cdom = '."'$dom'".';
7729: var cnum = document.rules.courseid.value;
7730: if (cdom == "" || cdom == null) {
7731: return;
7732: }
7733: if (cnum == "" || cnum == null) {
7734: return;
7735: }
7736: syllwin=window.open("/public/"+cdom+"/"+cnum+"/syllabus","LONCAPASyllabus",
7737: "height=350,width=350,scrollbars=yes,menubar=no");
7738: return;
7739: }
7740:
1.157 albertel 7741: </script>
7742:
1.566 raeburn 7743: <h3>'.&mt('Send scanned bubblesheet data to a course').'</h3>
7744:
1.492 albertel 7745: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
1.565 raeburn 7746: '.$default_form_data.
7747: &Apache::lonhtmlcommon::start_pick_box().
7748: &Apache::lonhtmlcommon::row_title(&mt('Course ID')).
7749: '<input name="courseid" type="text" size="30" />'.$select_link.
7750: &Apache::lonhtmlcommon::row_closure().
7751: &Apache::lonhtmlcommon::row_title(&mt('Course Name')).
7752: '<input name="coursename" type="text" size="30" />'.$syllabuslink.
7753: &Apache::lonhtmlcommon::row_closure().
7754: &Apache::lonhtmlcommon::row_title(&mt('Domain')).
7755: '<input name="domainid" type="hidden" />'.$domdesc.
7756: &Apache::lonhtmlcommon::row_closure().
7757: &Apache::lonhtmlcommon::row_title(&mt('File to upload')).
7758: '<input type="file" name="upfile" size="50" />'.
7759: &Apache::lonhtmlcommon::row_closure(1).
7760: &Apache::lonhtmlcommon::end_pick_box().'<br />
7761:
1.492 albertel 7762: <input name="command" value="scantronupload_save" type="hidden" />
1.574.2.5! raeburn 7763: <input type="button" onClick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
1.157 albertel 7764: </form>
1.492 albertel 7765: ');
1.157 albertel 7766: return '';
7767: }
7768:
1.423 albertel 7769:
1.157 albertel 7770: sub scantron_upload_scantron_data_save {
7771: my($r)=@_;
1.324 albertel 7772: my ($symb)=&get_symb($r,1);
1.182 albertel 7773: my $doanotherupload=
7774: '<br /><form action="/adm/grades" method="post">'."\n".
7775: '<input type="hidden" name="command" value="scantronupload" />'."\n".
1.492 albertel 7776: '<input type="submit" name="submit" value="'.&mt('Do Another Upload').'" />'."\n".
1.182 albertel 7777: '</form>'."\n";
1.257 albertel 7778: if (!&Apache::lonnet::allowed('usc',$env{'form.domainid'}) &&
1.162 albertel 7779: !&Apache::lonnet::allowed('usc',
1.257 albertel 7780: $env{'form.domainid'}.'_'.$env{'form.courseid'})) {
1.574.2.5! raeburn 7781: $r->print(&mt("You are not allowed to upload bubblesheet data to the requested course.")."<br />");
1.182 albertel 7782: if ($symb) {
1.324 albertel 7783: $r->print(&show_grading_menu_form($symb));
1.182 albertel 7784: } else {
7785: $r->print($doanotherupload);
7786: }
1.162 albertel 7787: return '';
7788: }
1.257 albertel 7789: my %coursedata=&Apache::lonnet::coursedescription($env{'form.domainid'}.'_'.$env{'form.courseid'});
1.568 raeburn 7790: my $uploadedfile;
1.567 raeburn 7791: $r->print('<h3>'.&mt("Uploading file to [_1]",$coursedata{'description'}).'</h3>');
1.257 albertel 7792: if (length($env{'form.upfile'}) < 2) {
1.568 raeburn 7793: $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 7794: } else {
1.568 raeburn 7795: my $result =
7796: &Apache::lonnet::userfileupload('upfile','','scantron','','','',
7797: $env{'form.courseid'},$env{'form.domainid'});
7798: if ($result =~ m{^/uploaded/}) {
1.567 raeburn 7799: $r->print(&mt('[_1]Success:[_2] Successfully uploaded [_3] bytes of data into location: [_4]',
7800: '<span class="LC_success">','</span>',(length($env{'form.upfile'})-1),
7801: '<span class="LC_filename">'.$result.'</span>'));
1.568 raeburn 7802: ($uploadedfile) = ($result =~ m{/([^/]+)$});
1.567 raeburn 7803: $r->print(&validate_uploaded_scantron_file($env{'form.domainid'},
1.568 raeburn 7804: $env{'form.courseid'},$uploadedfile));
1.210 albertel 7805: } else {
1.567 raeburn 7806: $r->print(&mt('[_1]Error:[_2] An error ([_3]) occurred when attempting to upload the file, [_4]',
7807: '<span class="LC_error">','</span>',$result,
1.568 raeburn 7808: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'));
1.183 albertel 7809: }
7810: }
1.174 albertel 7811: if ($symb) {
1.209 ng 7812: $r->print(&scantron_selectphase($r,$uploadedfile));
1.174 albertel 7813: } else {
1.182 albertel 7814: $r->print($doanotherupload);
1.174 albertel 7815: }
1.157 albertel 7816: return '';
7817: }
7818:
1.567 raeburn 7819: sub validate_uploaded_scantron_file {
7820: my ($cdom,$cname,$fname) = @_;
7821: my $scanlines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.$fname);
7822: my @lines;
7823: if ($scanlines ne '-1') {
7824: @lines=split("\n",$scanlines,-1);
7825: }
7826: my $output;
7827: if (@lines) {
7828: my (%counts,$max_match_format);
7829: my ($max_match_count,$max_match_pct) = (0,0);
7830: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cname);
7831: my %idmap = &username_to_idmap($classlist);
7832: foreach my $key (keys(%idmap)) {
7833: my $lckey = lc($key);
7834: $idmap{$lckey} = $idmap{$key};
7835: }
7836: my %unique_formats;
7837: my @formatlines = &get_scantronformat_file();
7838: foreach my $line (@formatlines) {
7839: chomp($line);
7840: my @config = split(/:/,$line);
7841: my $idstart = $config[5];
7842: my $idlength = $config[6];
7843: if (($idstart ne '') && ($idlength > 0)) {
7844: if (ref($unique_formats{$idstart.':'.$idlength}) eq 'ARRAY') {
7845: push(@{$unique_formats{$idstart.':'.$idlength}},$config[0].':'.$config[1]);
7846: } else {
7847: $unique_formats{$idstart.':'.$idlength} = [$config[0].':'.$config[1]];
7848: }
7849: }
7850: }
7851: foreach my $key (keys(%unique_formats)) {
7852: my ($idstart,$idlength) = split(':',$key);
7853: %{$counts{$key}} = (
7854: 'found' => 0,
7855: 'total' => 0,
7856: );
7857: foreach my $line (@lines) {
7858: next if ($line =~ /^#/);
7859: next if ($line =~ /^[\s\cz]*$/);
7860: my $id = substr($line,$idstart-1,$idlength);
7861: $id = lc($id);
7862: if (exists($idmap{$id})) {
7863: $counts{$key}{'found'} ++;
7864: }
7865: $counts{$key}{'total'} ++;
7866: }
7867: if ($counts{$key}{'total'}) {
7868: my $percent_match = (100*$counts{$key}{'found'})/($counts{$key}{'total'});
7869: if (($max_match_format eq '') || ($percent_match > $max_match_pct)) {
7870: $max_match_pct = $percent_match;
7871: $max_match_format = $key;
7872: $max_match_count = $counts{$key}{'total'};
7873: }
7874: }
7875: }
7876: if (ref($unique_formats{$max_match_format}) eq 'ARRAY') {
7877: my $format_descs;
7878: my $numwithformat = @{$unique_formats{$max_match_format}};
7879: for (my $i=0; $i<$numwithformat; $i++) {
7880: my ($name,$desc) = split(':',$unique_formats{$max_match_format}[$i]);
7881: if ($i<$numwithformat-2) {
7882: $format_descs .= '"<i>'.$desc.'</i>", ';
7883: } elsif ($i==$numwithformat-2) {
7884: $format_descs .= '"<i>'.$desc.'</i>" '.&mt('and').' ';
7885: } elsif ($i==$numwithformat-1) {
7886: $format_descs .= '"<i>'.$desc.'</i>"';
7887: }
7888: }
7889: my $showpct = sprintf("%.0f",$max_match_pct).'%';
7890: $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).
7891: '<br />'.&mt('A low percentage of matches results from one of the following:').'<ul>'.
7892: '<li>'.&mt('The file was uploaded to the wrong course').'</li>'.
7893: '<li>'.&mt('The data are not in the format expected for the domain: [_1]',
7894: '<i>'.$cdom.'</i>').'</li>'.
7895: '<li>'.&mt('Students did not bubble their IDs, or mis-bubbled them').'</li>'.
7896: '<li>'.&mt('The course roster is not up to date').'</li>'.
7897: '</ul>';
7898: }
7899: } else {
7900: $output = '<span class="LC_warning">'.&mt('Uploaded file contained no data').'</span>';
7901: }
7902: return $output;
7903: }
7904:
1.202 albertel 7905: sub valid_file {
7906: my ($requested_file)=@_;
7907: foreach my $filename (sort(&scantron_filenames())) {
7908: if ($requested_file eq $filename) { return 1; }
7909: }
7910: return 0;
7911: }
7912:
7913: sub scantron_download_scantron_data {
7914: my ($r)=@_;
1.324 albertel 7915: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.257 albertel 7916: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
7917: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7918: my $file=$env{'form.scantron_selectfile'};
1.202 albertel 7919: if (! &valid_file($file)) {
1.492 albertel 7920: $r->print('
1.202 albertel 7921: <p>
1.492 albertel 7922: '.&mt('The requested file name was invalid.').'
1.202 albertel 7923: </p>
1.492 albertel 7924: ');
1.324 albertel 7925: $r->print(&show_grading_menu_form(&get_symb($r,1)));
1.202 albertel 7926: return;
7927: }
7928: my $orig='/uploaded/'.$cdom.'/'.$cname.'/scantron_orig_'.$file;
7929: my $corrected='/uploaded/'.$cdom.'/'.$cname.'/scantron_corrected_'.$file;
7930: my $skipped='/uploaded/'.$cdom.'/'.$cname.'/scantron_skipped_'.$file;
7931: &Apache::lonnet::allowuploaded('/adm/grades',$orig);
7932: &Apache::lonnet::allowuploaded('/adm/grades',$corrected);
7933: &Apache::lonnet::allowuploaded('/adm/grades',$skipped);
1.492 albertel 7934: $r->print('
1.202 albertel 7935: <p>
1.492 albertel 7936: '.&mt('[_1]Original[_2] file as uploaded by the scantron office.',
7937: '<a href="'.$orig.'">','</a>').'
1.202 albertel 7938: </p>
7939: <p>
1.492 albertel 7940: '.&mt('[_1]Corrections[_2], a file of corrected records that were used in grading.',
7941: '<a href="'.$corrected.'">','</a>').'
1.202 albertel 7942: </p>
7943: <p>
1.492 albertel 7944: '.&mt('[_1]Skipped[_2], a file of records that were skipped.',
7945: '<a href="'.$skipped.'">','</a>').'
1.202 albertel 7946: </p>
1.492 albertel 7947: ');
1.324 albertel 7948: $r->print(&show_grading_menu_form(&get_symb($r,1)));
1.202 albertel 7949: return '';
7950: }
1.157 albertel 7951:
1.523 raeburn 7952: sub checkscantron_results {
7953: my ($r) = @_;
7954: my ($symb)=&get_symb($r);
7955: if (!$symb) {return '';}
7956: my $grading_menu_button=&show_grading_menu_form($symb);
7957: my $cid = $env{'request.course.id'};
1.542 raeburn 7958: my %lettdig = &letter_to_digits();
1.523 raeburn 7959: my $numletts = scalar(keys(%lettdig));
7960: my $cnum = $env{'course.'.$cid.'.num'};
7961: my $cdom = $env{'course.'.$cid.'.domain'};
7962: my (undef, undef, $sequence) = &Apache::lonnet::decode_symb($env{'form.selectpage'});
7963: my %record;
7964: my %scantron_config =
7965: &Apache::grades::get_scantron_config($env{'form.scantron_format'});
7966: my ($scanlines,$scan_data)=&Apache::grades::scantron_getfile();
7967: my $classlist=&Apache::loncoursedata::get_classlist();
7968: my %idmap=&Apache::grades::username_to_idmap($classlist);
7969: my $navmap=Apache::lonnavmaps::navmap->new();
7970: my $map=$navmap->getResourceByUrl($sequence);
1.557 raeburn 7971: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
7972: my (%grader_partids_by_symb,%grader_randomlists_by_symb);
7973: &graders_resources_pass(\@resources,\%grader_partids_by_symb, \%grader_randomlists_by_symb);
7974:
1.554 raeburn 7975: my ($uname,$udom);
1.523 raeburn 7976: my (%scandata,%lastname,%bylast);
7977: $r->print('
7978: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="checkscantron">'."\n");
7979:
7980: my @delayqueue;
7981: my %completedstudents;
7982:
7983: my $count=&Apache::grades::get_todo_count($scanlines,$scan_data);
1.574.2.5! raeburn 7984: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Bubblesheet/Submissions Comparison Status',
! 7985: 'Progress of Bubblesheet Data/Submission Records Comparison',$count,
1.523 raeburn 7986: 'inline',undef,'checkscantron');
1.546 raeburn 7987: my ($username,$domain,$started);
1.523 raeburn 7988:
1.557 raeburn 7989: &scantron_get_maxbubble(); # Need the bubble lines array to parse.
1.523 raeburn 7990:
7991: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
7992: 'Processing first student');
7993: my $start=&Time::HiRes::time();
7994: my $i=-1;
7995:
7996: while ($i<$scanlines->{'count'}) {
7997: ($username,$domain,$uname)=('','','');
7998: $i++;
7999: my $line=&Apache::grades::scantron_get_line($scanlines,$scan_data,$i);
8000: if ($line=~/^[\s\cz]*$/) { next; }
8001: if ($started) {
8002: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
8003: 'last student');
8004: }
8005: $started=1;
8006: my $scan_record=
8007: &Apache::grades::scantron_parse_scanline($line,$i,\%scantron_config,
8008: $scan_data);
8009: unless ($uname=&Apache::grades::scantron_find_student($scan_record,$scan_data,
8010: \%idmap,$i)) {
8011: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
8012: 'Unable to find a student that matches',1);
8013: next;
8014: }
8015: if (exists $completedstudents{$uname}) {
8016: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
8017: 'Student '.$uname.' has multiple sheets',2);
8018: next;
8019: }
8020: my $pid = $scan_record->{'scantron.ID'};
8021: $lastname{$pid} = $scan_record->{'scantron.LastName'};
8022: push(@{$bylast{$lastname{$pid}}},$pid);
8023: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
8024: $scandata{$pid} = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
8025: chomp($scandata{$pid});
8026: $scandata{$pid} =~ s/\r$//;
8027: ($username,$domain)=split(/:/,$uname);
8028: my $counter = -1;
8029: foreach my $resource (@resources) {
1.557 raeburn 8030: my $parts;
1.554 raeburn 8031: my $ressymb = $resource->symb();
1.557 raeburn 8032: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
8033: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
8034: (my $analysis,$parts) =
8035: &scantron_partids_tograde($resource,$env{'request.course.id'},$username,$domain);
8036: } else {
8037: $parts = $grader_partids_by_symb{$ressymb};
8038: }
1.542 raeburn 8039: ($counter,my $recording) =
8040: &verify_scantron_grading($resource,$domain,$username,$cid,$counter,
1.554 raeburn 8041: $scandata{$pid},$parts,
1.542 raeburn 8042: \%scantron_config,\%lettdig,$numletts);
8043: $record{$pid} .= $recording;
1.523 raeburn 8044: }
8045: }
8046: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
8047: $r->print('<br />');
8048: my ($okstudents,$badstudents,$numstudents,$passed,$failed);
8049: $passed = 0;
8050: $failed = 0;
8051: $numstudents = 0;
8052: foreach my $last (sort(keys(%bylast))) {
8053: if (ref($bylast{$last}) eq 'ARRAY') {
8054: foreach my $pid (sort(@{$bylast{$last}})) {
8055: my $showscandata = $scandata{$pid};
8056: my $showrecord = $record{$pid};
8057: $showscandata =~ s/\s/ /g;
8058: $showrecord =~ s/\s/ /g;
8059: if ($scandata{$pid} eq $record{$pid}) {
8060: my $css_class = ($passed % 2)?'LC_odd_row':'LC_even_row';
8061: $okstudents .= '<tr class="'.$css_class.'">'.
1.574.2.5! raeburn 8062: '<td>'.&mt('Bubblesheet').'</td><td>'.$showscandata.'</td><td rowspan="2">'.$last.'</td><td rowspan="2">'.$pid.'</td>'."\n".
1.523 raeburn 8063: '</tr>'."\n".
8064: '<tr class="'.$css_class.'">'."\n".
8065: '<td>Submissions</td><td>'.$showrecord.'</td></tr>'."\n";
8066: $passed ++;
8067: } else {
8068: my $css_class = ($failed % 2)?'LC_odd_row':'LC_even_row';
1.574.2.5! raeburn 8069: $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 8070: '</tr>'."\n".
8071: '<tr class="'.$css_class.'">'."\n".
8072: '<td>Submissions</td><td><span class="LC_nobreak">'.$record{$pid}.'</span></td>'."\n".
8073: '</tr>'."\n";
8074: $failed ++;
8075: }
8076: $numstudents ++;
8077: }
8078: }
8079: }
1.572 www 8080: $r->print('<p>'.&mt('Comparison of bubblesheet data (including corrections) with corresponding submission records (most recent submission) for <b>[quant,_1,student]</b> ([_2] scantron lines/student).',$numstudents,$env{'form.scantron_maxbubble'}).'</p>');
1.523 raeburn 8081: $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>');
8082: if ($passed) {
1.572 www 8083: $r->print(&mt('Students with exact correspondence between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 8084: $r->print(&Apache::loncommon::start_data_table()."\n".
8085: &Apache::loncommon::start_data_table_header_row()."\n".
8086: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
8087: &Apache::loncommon::end_data_table_header_row()."\n".
8088: $okstudents."\n".
8089: &Apache::loncommon::end_data_table().'<br />');
8090: }
8091: if ($failed) {
1.572 www 8092: $r->print(&mt('Students with differences between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 8093: $r->print(&Apache::loncommon::start_data_table()."\n".
8094: &Apache::loncommon::start_data_table_header_row()."\n".
8095: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
8096: &Apache::loncommon::end_data_table_header_row()."\n".
8097: $badstudents."\n".
8098: &Apache::loncommon::end_data_table()).'<br />'.
1.572 www 8099: &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 8100: }
8101: $r->print('</form><br />'.$grading_menu_button);
8102: return;
8103: }
8104:
1.542 raeburn 8105: sub verify_scantron_grading {
1.554 raeburn 8106: my ($resource,$domain,$username,$cid,$counter,$scandata,$partids,
1.542 raeburn 8107: $scantron_config,$lettdig,$numletts) = @_;
8108: my ($record,%expected,%startpos);
8109: return ($counter,$record) if (!ref($resource));
8110: return ($counter,$record) if (!$resource->is_problem());
8111: my $symb = $resource->symb();
1.554 raeburn 8112: return ($counter,$record) if (ref($partids) ne 'ARRAY');
8113: foreach my $part_id (@{$partids}) {
1.542 raeburn 8114: $counter ++;
8115: $expected{$part_id} = 0;
8116: if ($env{"form.scantron.sub_bubblelines.$counter"}) {
8117: my @sub_lines = split(/,/,$env{"form.scantron.sub_bubblelines.$counter"});
8118: foreach my $item (@sub_lines) {
8119: $expected{$part_id} += $item;
8120: }
8121: } else {
8122: $expected{$part_id} = $env{"form.scantron.bubblelines.$counter"};
8123: }
8124: $startpos{$part_id} = $env{"form.scantron.first_bubble_line.$counter"};
8125: }
8126: if ($symb) {
8127: my %recorded;
8128: my (%returnhash) = &Apache::lonnet::restore($symb,$cid,$domain,$username);
8129: if ($returnhash{'version'}) {
8130: my %lasthash=();
8131: my $version;
8132: for ($version=1;$version<=$returnhash{'version'};$version++) {
8133: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
8134: $lasthash{$key}=$returnhash{$version.':'.$key};
8135: }
8136: }
8137: foreach my $key (keys(%lasthash)) {
8138: if ($key =~ /\.scantron$/) {
8139: my $value = &unescape($lasthash{$key});
8140: my ($part_id) = ($key =~ /^resource\.(.+)\.scantron$/);
8141: if ($value eq '') {
8142: for (my $i=0; $i<$expected{$part_id}; $i++) {
8143: for (my $j=0; $j<$scantron_config->{'length'}; $j++) {
8144: $recorded{$part_id} .= $scantron_config->{'Qoff'};
8145: }
8146: }
8147: } else {
8148: my @tocheck;
8149: my @items = split(//,$value);
8150: if (($scantron_config->{'Qon'} eq 'letter') ||
8151: ($scantron_config->{'Qon'} eq 'number')) {
8152: if (@items < $expected{$part_id}) {
8153: my $fragment = substr($scandata,$startpos{$part_id},$expected{$part_id});
8154: my @singles = split(//,$fragment);
8155: foreach my $pos (@singles) {
8156: if ($pos eq ' ') {
8157: push(@tocheck,$pos);
8158: } else {
8159: my $next = shift(@items);
8160: push(@tocheck,$next);
8161: }
8162: }
8163: } else {
8164: @tocheck = @items;
8165: }
8166: foreach my $letter (@tocheck) {
8167: if ($scantron_config->{'Qon'} eq 'letter') {
8168: if ($letter !~ /^[A-J]$/) {
8169: $letter = $scantron_config->{'Qoff'};
8170: }
8171: $recorded{$part_id} .= $letter;
8172: } elsif ($scantron_config->{'Qon'} eq 'number') {
8173: my $digit;
8174: if ($letter !~ /^[A-J]$/) {
8175: $digit = $scantron_config->{'Qoff'};
8176: } else {
8177: $digit = $lettdig->{$letter};
8178: }
8179: $recorded{$part_id} .= $digit;
8180: }
8181: }
8182: } else {
8183: @tocheck = @items;
8184: for (my $i=0; $i<$expected{$part_id}; $i++) {
8185: my $curr_sub = shift(@tocheck);
8186: my $digit;
8187: if ($curr_sub =~ /^[A-J]$/) {
8188: $digit = $lettdig->{$curr_sub}-1;
8189: }
8190: if ($curr_sub eq 'J') {
8191: $digit += scalar($numletts);
8192: }
8193: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
8194: if ($j == $digit) {
8195: $recorded{$part_id} .= $scantron_config->{'Qon'};
8196: } else {
8197: $recorded{$part_id} .= $scantron_config->{'Qoff'};
8198: }
8199: }
8200: }
8201: }
8202: }
8203: }
8204: }
8205: }
1.554 raeburn 8206: foreach my $part_id (@{$partids}) {
1.542 raeburn 8207: if ($recorded{$part_id} eq '') {
8208: for (my $i=0; $i<$expected{$part_id}; $i++) {
8209: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
8210: $recorded{$part_id} .= $scantron_config->{'Qoff'};
8211: }
8212: }
8213: }
8214: $record .= $recorded{$part_id};
8215: }
8216: }
8217: return ($counter,$record);
8218: }
8219:
8220: sub letter_to_digits {
8221: my %lettdig = (
8222: A => 1,
8223: B => 2,
8224: C => 3,
8225: D => 4,
8226: E => 5,
8227: F => 6,
8228: G => 7,
8229: H => 8,
8230: I => 9,
8231: J => 0,
8232: );
8233: return %lettdig;
8234: }
8235:
1.423 albertel 8236:
1.75 albertel 8237: #-------- end of section for handling grading scantron forms -------
8238: #
8239: #-------------------------------------------------------------------
8240:
1.72 ng 8241: #-------------------------- Menu interface -------------------------
8242: #
8243: #--- Show a Grading Menu button - Calls the next routine ---
8244: sub show_grading_menu_form {
1.324 albertel 8245: my ($symb)=@_;
1.125 ng 8246: my $result.='<br /><form action="/adm/grades" method="post">'."\n".
1.418 albertel 8247: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 8248: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.72 ng 8249: '<input type="hidden" name="command" value="gradingmenu" />'."\n".
1.478 albertel 8250: '<input type="submit" name="submit" value="'.&mt('Grading Menu').'" />'."\n".
1.72 ng 8251: '</form>'."\n";
8252: return $result;
8253: }
8254:
1.77 ng 8255: # -- Retrieve choices for grading form
8256: sub savedState {
8257: my %savedState = ();
1.257 albertel 8258: if ($env{'form.saveState'}) {
8259: foreach (split(/:/,$env{'form.saveState'})) {
1.77 ng 8260: my ($key,$value) = split(/=/,$_,2);
8261: $savedState{$key} = $value;
8262: }
8263: }
8264: return \%savedState;
8265: }
1.76 ng 8266:
1.443 banghart 8267: sub grading_menu {
8268: my ($request) = @_;
8269: my ($symb)=&get_symb($request);
8270: if (!$symb) {return '';}
8271: my $probTitle = &Apache::lonnet::gettitle($symb);
8272: my ($table,undef,$hdgrade) = &showResourceInfo($symb,$probTitle);
8273:
1.444 banghart 8274: $request->print($table);
1.443 banghart 8275: my %fields = ('symb'=>&Apache::lonenc::check_encrypt($symb),
8276: 'handgrade'=>$hdgrade,
8277: 'probTitle'=>$probTitle,
8278: 'command'=>'submit_options',
8279: 'saveState'=>"",
8280: 'gradingMenu'=>1,
8281: 'showgrading'=>"yes");
1.574.2.1 raeburn 8282: my $url = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8283: my @menu = ({ url => $url,
8284: name => &mt('Manual Grading/View Submissions'),
8285: short_description =>
8286: &mt('Start the process of hand grading submissions.'),
8287: });
1.443 banghart 8288: $fields{'command'} = 'csvform';
1.574.2.1 raeburn 8289: $url = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8290: push(@menu, { url => $url,
8291: name => &mt('Upload Scores'),
8292: short_description =>
8293: &mt('Specify a file containing the class scores for current resource.')});
1.443 banghart 8294: $fields{'command'} = 'processclicker';
1.574.2.1 raeburn 8295: $url = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8296: push(@menu, { url => $url,
8297: name => &mt('Process Clicker'),
8298: short_description =>
8299: &mt('Specify a file containing the clicker information for this resource.')});
1.443 banghart 8300: $fields{'command'} = 'scantron_selectphase';
1.574.2.1 raeburn 8301: $url = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8302: push(@menu, { url => $url,
1.574.2.5! raeburn 8303: name => &mt('Grade/Manage/Review Bubblesheets'),
1.574.2.1 raeburn 8304: short_description =>
8305: &mt('Grade scantron exams, upload/download scantron data files, and review previously graded scantron exams.')});
8306: $fields{'command'} = 'verify';
8307: $url = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8308: push(@menu, { url => "",
8309: name => &mt('Verify Receipt'),
8310: short_description =>
8311: &mt('')});
1.443 banghart 8312: # Create the menu
8313: my $Str;
1.444 banghart 8314: # $Str .= '<h2>'.&mt('Please select a grading task').'</h2>';
1.445 banghart 8315: $Str .= '<form method="post" action="" name="gradingMenu">';
8316: $Str .= '<input type="hidden" name="command" value="" />'.
8317: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
8318: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
1.476 albertel 8319: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.445 banghart 8320: '<input type="hidden" name="saveState" value="" />'."\n".
8321: '<input type="hidden" name="gradingMenu" value="1" />'."\n".
8322: '<input type="hidden" name="showgrading" value="yes" />'."\n";
1.574.2.1 raeburn 8323: foreach my $menudata (@menu) {
8324: if ($menudata->{'name'} ne &mt('Verify Receipt')) {
8325: $Str .=' <h3><a '.
8326: $menudata->{'jscript'}.
8327: ' href="'.
8328: $menudata->{'url'}.'" >'.
8329: $menudata->{'name'}."</a></h3>\n";
8330: } else {
8331: $Str .='<hr /><input type="button" value="'.&mt('Verify Receipt').'" '.
8332: $menudata->{'jscript'}.
8333: ' onClick="javascript:checkChoice(document.forms.gradingMenu,\'5\',\'verify\')" '.
8334: ' /> '.
8335: &Apache::lonnet::recprefix($env{'request.course.id'}).
8336: '-<input type="text" name="receipt" size="4" onChange="javascript:checkReceiptNo(this.form,\'OK\')" />';
8337: }
8338: $Str .= ' '.(' 'x8).$menudata->{'short_description'}.
8339: "\n";
8340: }
1.444 banghart 8341: $Str .="</form>\n";
1.539 riegler 8342: my $receiptalert = &mt("Please enter a receipt number given by a student in the receipt box.");
1.443 banghart 8343: $request->print(<<GRADINGMENUJS);
8344: <script type="text/javascript" language="javascript">
8345: function checkChoice(formname,val,cmdx) {
8346: if (val <= 2) {
8347: var cmd = radioSelection(formname.radioChoice);
8348: var cmdsave = cmd;
8349: } else {
8350: cmd = cmdx;
8351: cmdsave = 'submission';
8352: }
8353: formname.command.value = cmd;
8354: if (val < 5) formname.submit();
8355: if (val == 5) {
1.458 banghart 8356: if (!checkReceiptNo(formname,'notOK')) {
8357: return false;
8358: } else {
8359: formname.submit();
8360: }
1.445 banghart 8361: }
8362: }
1.443 banghart 8363:
8364: function checkReceiptNo(formname,nospace) {
8365: var receiptNo = formname.receipt.value;
8366: var checkOpt = false;
8367: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
8368: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
8369: if (checkOpt) {
1.539 riegler 8370: alert("$receiptalert");
1.443 banghart 8371: formname.receipt.value = "";
8372: formname.receipt.focus();
8373: return false;
8374: }
8375: return true;
8376: }
8377: </script>
8378: GRADINGMENUJS
8379: &commonJSfunctions($request);
8380: return $Str;
8381: }
8382:
8383:
8384: #--- Displays the submissions first page -------
8385: sub submit_options {
1.72 ng 8386: my ($request) = @_;
1.324 albertel 8387: my ($symb)=&get_symb($request);
1.72 ng 8388: if (!$symb) {return '';}
1.76 ng 8389: my $probTitle = &Apache::lonnet::gettitle($symb);
1.72 ng 8390:
1.539 riegler 8391: my $receiptalert = &mt("Please enter a receipt number given by a student in the receipt box.");
1.72 ng 8392: $request->print(<<GRADINGMENUJS);
8393: <script type="text/javascript" language="javascript">
1.116 ng 8394: function checkChoice(formname,val,cmdx) {
8395: if (val <= 2) {
8396: var cmd = radioSelection(formname.radioChoice);
1.118 ng 8397: var cmdsave = cmd;
1.116 ng 8398: } else {
8399: cmd = cmdx;
1.118 ng 8400: cmdsave = 'submission';
1.116 ng 8401: }
8402: formname.command.value = cmd;
1.118 ng 8403: formname.saveState.value = "saveCmd="+cmdsave+":saveSec="+pullDownSelection(formname.section)+
1.145 albertel 8404: ":saveSub="+pullDownSelection(formname.submitonly)+":saveStatus="+pullDownSelection(formname.Status);
1.116 ng 8405: if (val < 5) formname.submit();
8406: if (val == 5) {
1.72 ng 8407: if (!checkReceiptNo(formname,'notOK')) { return false;}
8408: formname.submit();
8409: }
1.238 albertel 8410: if (val < 7) formname.submit();
1.72 ng 8411: }
8412:
8413: function checkReceiptNo(formname,nospace) {
8414: var receiptNo = formname.receipt.value;
8415: var checkOpt = false;
8416: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
8417: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
8418: if (checkOpt) {
1.539 riegler 8419: alert("$receiptalert");
1.72 ng 8420: formname.receipt.value = "";
8421: formname.receipt.focus();
8422: return false;
8423: }
8424: return true;
8425: }
8426: </script>
8427: GRADINGMENUJS
1.118 ng 8428: &commonJSfunctions($request);
1.324 albertel 8429: my ($table,undef,$hdgrade) = &showResourceInfo($symb,$probTitle);
1.473 albertel 8430: my $result;
1.76 ng 8431: my (undef,$sections) = &getclasslist('all','0');
1.77 ng 8432: my $savedState = &savedState();
1.118 ng 8433: my $saveCmd = ($$savedState{'saveCmd'} eq '' ? 'submission' : $$savedState{'saveCmd'});
1.77 ng 8434: my $saveSec = ($$savedState{'saveSec'} eq '' ? 'all' : $$savedState{'saveSec'});
1.118 ng 8435: my $saveSub = ($$savedState{'saveSub'} eq '' ? 'all' : $$savedState{'saveSub'});
1.77 ng 8436: my $saveStatus = ($$savedState{'saveStatus'} eq '' ? 'Active' : $$savedState{'saveStatus'});
1.72 ng 8437:
1.533 bisitz 8438: # Preselect sections
8439: my $selsec="";
8440: if (ref($sections)) {
8441: foreach my $section (sort(@$sections)) {
8442: $selsec.='<option value="'.$section.'" '.
8443: ($saveSec eq $section ? 'selected="selected"':'').'>'.$section.'</option>'."\n";
8444: }
8445: }
8446:
1.72 ng 8447: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.418 albertel 8448: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.72 ng 8449: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
8450: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.116 ng 8451: '<input type="hidden" name="command" value="" />'."\n".
1.77 ng 8452: '<input type="hidden" name="saveState" value="" />'."\n".
1.124 ng 8453: '<input type="hidden" name="gradingMenu" value="1" />'."\n".
1.72 ng 8454: '<input type="hidden" name="showgrading" value="yes" />'."\n";
8455:
1.472 albertel 8456: $result.='
1.574.2.1 raeburn 8457: <div class="LC_grade_select_mode">
8458: <div class="LC_grade_select_mode_current">
8459: <h2>
8460: '.&mt('Grade Current Resource').'
8461: </h2>
8462: <div class="LC_grade_select_mode_body">
8463: <div class="LC_grades_resource_info">
8464: '.$table.'
8465: </div>
8466: <div class="LC_grade_select_mode_selector">
8467: <div class="LC_grade_select_mode_selector_header">
8468: '.&mt('Sections').'
8469: </div>
8470: <div class="LC_grade_select_mode_selector_body">
8471: <select name="section" multiple="multiple" size="5">'."\n";
8472: if (ref($sections)) {
8473: foreach my $section (sort(@$sections)) {
8474: $result.='<option value="'.$section.'" '.
8475: ($saveSec eq $section ? 'selected="selected"':'').'>'.$section.'</option>'."\n";
8476: }
8477: }
1.401 albertel 8478: $result.= '<option value="all" '.($saveSec eq 'all' ? 'selected="selected"' : ''). '>all</option></select> ';
1.472 albertel 8479: $result.='
1.574.2.1 raeburn 8480: </div>
8481: </div>
8482: <div class="LC_grade_select_mode_selector">
8483: <div class="LC_grade_select_mode_selector_header">
8484: '.&mt('Groups').'
8485: </div>
8486: <div class="LC_grade_select_mode_selector_body">
8487: '.&Apache::lonstatistics::GroupSelect('group','multiple',5).'
8488: </div>
8489: </div>
8490: <div class="LC_grade_select_mode_selector">
8491: <div class="LC_grade_select_mode_selector_header">
8492: '.&mt('Access Status').'
8493: </div>
8494: <div class="LC_grade_select_mode_selector_body">
8495: '.&Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,5,undef,'mult').'
8496: </div>
8497: </div>
8498: <div class="LC_grade_select_mode_selector">
8499: <div class="LC_grade_select_mode_selector_header">
8500: '.&mt('Submission Status').'
8501: </div>
8502: <div class="LC_grade_select_mode_selector_body">
8503: <select name="submitonly" size="5">
8504: <option value="yes" '. ($saveSub eq 'yes' ? 'selected="selected"' : '').'>'.&mt('with submissions').'</option>
8505: <option value="queued" '. ($saveSub eq 'queued' ? 'selected="selected"' : '').'>'.&mt('in grading queue').'</option>
8506: <option value="graded" '. ($saveSub eq 'graded' ? 'selected="selected"' : '').'>'.&mt('with ungraded submissions').'</option>
8507: <option value="incorrect" '.($saveSub eq 'incorrect' ? 'selected="selected"' : '').'>'.&mt('with incorrect submissions').'</option>
1.473 albertel 8508: <option value="all" '. ($saveSub eq 'all' ? 'selected="selected"' : '').'>'.&mt('with any status').'</option>
1.574.2.1 raeburn 8509: </select>
8510: </div>
8511: </div>
8512: <div class="LC_grade_select_mode_type_body">
8513: <div class="LC_grade_select_mode_type">
1.473 albertel 8514: <label>
8515: <input type="radio" name="radioChoice" value="submission" '.
8516: ($saveCmd eq 'submission' ? 'checked="checked"' : '').' /> '.
8517: &mt('Select individual students to grade and view submissions.').'
1.574.2.1 raeburn 8518: </label>
1.473 albertel 8519: </div>
1.574.2.1 raeburn 8520: <div class="LC_grade_select_mode_type">
8521: <label>
1.473 albertel 8522: <input type="radio" name="radioChoice" value="viewgrades" '.
8523: ($saveCmd eq 'viewgrades' ? 'checked="checked"' : '').' /> '.
8524: &mt('Grade all selected students in a grading table.').'
8525: </label>
8526: </div>
1.574.2.1 raeburn 8527: <div class="LC_grade_select_mode_type">
8528: <input type="button" onClick="javascript:checkChoice(this.form,\'2\');" value="'.&mt('Next->').'" />
1.473 albertel 8529: </div>
1.472 albertel 8530: </div>
1.574.2.1 raeburn 8531: </div>
8532: </div>
8533: <div class="LC_grade_select_mode_page">
1.473 albertel 8534: <h2>
8535: '.&mt('Grade Complete Folder for One Student').'
8536: </h2>
1.574.2.1 raeburn 8537: <div class="LC_grades_select_mode_body">
8538: <div class="LC_grade_select_mode_type_body">
8539: <div class="LC_grade_select_mode_type">
1.473 albertel 8540: <label>
8541: <input type="radio" name="radioChoice" value="pickStudentPage" '.
1.574.2.1 raeburn 8542: ($saveCmd eq 'pickStudentPage' ? 'checked="checked"' : '').' /> '.
1.473 albertel 8543: &mt('The <b>complete</b> page/sequence/folder: For one student').'
8544: </label>
8545: </div>
1.574.2.1 raeburn 8546: <div class="LC_grade_select_mode_type">
8547: <input type="button" onClick="javascript:checkChoice(this.form,\'2\');" value="'.&mt('Next->').'" />
1.473 albertel 8548: </div>
1.574.2.1 raeburn 8549: </div>
1.472 albertel 8550: </div>
1.574.2.1 raeburn 8551: </div>
8552: </div>
1.472 albertel 8553: </form>';
1.499 albertel 8554: $result .= &show_grading_menu_form($symb);
1.44 ng 8555: return $result;
1.2 albertel 8556: }
8557:
1.285 albertel 8558: sub reset_perm {
8559: undef(%perm);
8560: }
8561:
8562: sub init_perm {
8563: &reset_perm();
1.300 albertel 8564: foreach my $test_perm ('vgr','mgr','opa') {
8565:
8566: my $scope = $env{'request.course.id'};
8567: if (!($perm{$test_perm}=&Apache::lonnet::allowed($test_perm,$scope))) {
8568:
8569: $scope .= '/'.$env{'request.course.sec'};
8570: if ( $perm{$test_perm}=
8571: &Apache::lonnet::allowed($test_perm,$scope)) {
8572: $perm{$test_perm.'_section'}=$env{'request.course.sec'};
8573: } else {
8574: delete($perm{$test_perm});
8575: }
1.285 albertel 8576: }
8577: }
8578: }
8579:
1.400 www 8580: sub gather_clicker_ids {
1.408 albertel 8581: my %clicker_ids;
1.400 www 8582:
8583: my $classlist = &Apache::loncoursedata::get_classlist();
8584:
8585: # Set up a couple variables.
1.407 albertel 8586: my $username_idx = &Apache::loncoursedata::CL_SNAME();
8587: my $domain_idx = &Apache::loncoursedata::CL_SDOM();
1.438 www 8588: my $status_idx = &Apache::loncoursedata::CL_STATUS();
1.400 www 8589:
1.407 albertel 8590: foreach my $student (keys(%$classlist)) {
1.438 www 8591: if ($classlist->{$student}->[$status_idx] ne 'Active') { next; }
1.407 albertel 8592: my $username = $classlist->{$student}->[$username_idx];
8593: my $domain = $classlist->{$student}->[$domain_idx];
1.400 www 8594: my $clickers =
1.408 albertel 8595: (&Apache::lonnet::userenvironment($domain,$username,'clickers'))[1];
1.400 www 8596: foreach my $id (split(/\,/,$clickers)) {
1.414 www 8597: $id=~s/^[\#0]+//;
1.421 www 8598: $id=~s/[\-\:]//g;
1.407 albertel 8599: if (exists($clicker_ids{$id})) {
1.408 albertel 8600: $clicker_ids{$id}.=','.$username.':'.$domain;
1.400 www 8601: } else {
1.408 albertel 8602: $clicker_ids{$id}=$username.':'.$domain;
1.400 www 8603: }
8604: }
8605: }
1.407 albertel 8606: return %clicker_ids;
1.400 www 8607: }
8608:
1.402 www 8609: sub gather_adv_clicker_ids {
1.408 albertel 8610: my %clicker_ids;
1.402 www 8611: my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'};
8612: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
8613: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
1.409 albertel 8614: foreach my $element (sort(keys(%coursepersonnel))) {
1.402 www 8615: foreach my $person (split(/\,/,$coursepersonnel{$element})) {
8616: my ($puname,$pudom)=split(/\:/,$person);
8617: my $clickers =
1.408 albertel 8618: (&Apache::lonnet::userenvironment($pudom,$puname,'clickers'))[1];
1.405 www 8619: foreach my $id (split(/\,/,$clickers)) {
1.414 www 8620: $id=~s/^[\#0]+//;
1.421 www 8621: $id=~s/[\-\:]//g;
1.408 albertel 8622: if (exists($clicker_ids{$id})) {
8623: $clicker_ids{$id}.=','.$puname.':'.$pudom;
8624: } else {
8625: $clicker_ids{$id}=$puname.':'.$pudom;
8626: }
1.405 www 8627: }
1.402 www 8628: }
8629: }
1.407 albertel 8630: return %clicker_ids;
1.402 www 8631: }
8632:
1.413 www 8633: sub clicker_grading_parameters {
8634: return ('gradingmechanism' => 'scalar',
8635: 'upfiletype' => 'scalar',
8636: 'specificid' => 'scalar',
8637: 'pcorrect' => 'scalar',
8638: 'pincorrect' => 'scalar');
8639: }
8640:
1.400 www 8641: sub process_clicker {
8642: my ($r)=@_;
8643: my ($symb)=&get_symb($r);
8644: if (!$symb) {return '';}
8645: my $result=&checkforfile_js();
8646: $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
8647: my ($table) = &showResourceInfo($symb,$env{'form.probTitle'});
8648: $result.=$table;
8649: $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
8650: $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
1.538 schulted 8651: $result.=' <b>'.&mt('Specify a file containing the clicker information for this resource.').
8652: '</b></td></tr>'."\n";
1.400 www 8653: $result.='<tr bgcolor=#ffffe6><td>'."\n";
1.413 www 8654: # Attempt to restore parameters from last session, set defaults if not present
8655: my %Saveable_Parameters=&clicker_grading_parameters();
8656: &Apache::loncommon::restore_course_settings('grades_clicker',
8657: \%Saveable_Parameters);
8658: if (!$env{'form.pcorrect'}) { $env{'form.pcorrect'}=100; }
8659: if (!$env{'form.pincorrect'}) { $env{'form.pincorrect'}=100; }
8660: if (!$env{'form.gradingmechanism'}) { $env{'form.gradingmechanism'}='attendance'; }
8661: if (!$env{'form.upfiletype'}) { $env{'form.upfiletype'}='iclicker'; }
8662:
8663: my %checked;
1.521 www 8664: foreach my $gradingmechanism ('attendance','personnel','specific','given') {
1.413 www 8665: if ($env{'form.gradingmechanism'} eq $gradingmechanism) {
1.569 bisitz 8666: $checked{$gradingmechanism}=' checked="checked"';
1.413 www 8667: }
8668: }
8669:
1.400 www 8670: my $upload=&mt("Upload File");
8671: my $type=&mt("Type");
1.402 www 8672: my $attendance=&mt("Award points just for participation");
8673: my $personnel=&mt("Correctness determined from response by course personnel");
1.414 www 8674: my $specific=&mt("Correctness determined from response with clicker ID(s)");
1.521 www 8675: my $given=&mt("Correctness determined from given list of answers").' '.
8676: '<font size="-2"><tt>('.&mt("Provide comma-separated list. Use '*' for any answer correct, '-' for skip").')</tt></font>';
1.402 www 8677: my $pcorrect=&mt("Percentage points for correct solution");
8678: my $pincorrect=&mt("Percentage points for incorrect solution");
1.413 www 8679: my $selectform=&Apache::loncommon::select_form($env{'form.upfiletype'},'upfiletype',
1.419 www 8680: ('iclicker' => 'i>clicker',
8681: 'interwrite' => 'interwrite PRS'));
1.418 albertel 8682: $symb = &Apache::lonenc::check_encrypt($symb);
1.400 www 8683: $result.=<<ENDUPFORM;
1.402 www 8684: <script type="text/javascript">
8685: function sanitycheck() {
8686: // Accept only integer percentages
8687: document.forms.gradesupload.pcorrect.value=Math.round(document.forms.gradesupload.pcorrect.value);
8688: document.forms.gradesupload.pincorrect.value=Math.round(document.forms.gradesupload.pincorrect.value);
8689: // Find out grading choice
8690: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
8691: if (document.forms.gradesupload.gradingmechanism[i].checked) {
8692: gradingchoice=document.forms.gradesupload.gradingmechanism[i].value;
8693: }
8694: }
8695: // By default, new choice equals user selection
8696: newgradingchoice=gradingchoice;
8697: // Not good to give more points for false answers than correct ones
8698: if (Math.round(document.forms.gradesupload.pcorrect.value)<Math.round(document.forms.gradesupload.pincorrect.value)) {
8699: document.forms.gradesupload.pcorrect.value=document.forms.gradesupload.pincorrect.value;
8700: }
8701: // If new choice is attendance only, and old choice was correctness-based, restore defaults
8702: if ((gradingchoice=='attendance') && (document.forms.gradesupload.waschecked.value!='attendance')) {
8703: document.forms.gradesupload.pcorrect.value=100;
8704: document.forms.gradesupload.pincorrect.value=100;
8705: }
8706: // If the values are different, cannot be attendance only
8707: if ((Math.round(document.forms.gradesupload.pcorrect.value)!=Math.round(document.forms.gradesupload.pincorrect.value)) &&
8708: (gradingchoice=='attendance')) {
8709: newgradingchoice='personnel';
8710: }
8711: // Change grading choice to new one
8712: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
8713: if (document.forms.gradesupload.gradingmechanism[i].value==newgradingchoice) {
8714: document.forms.gradesupload.gradingmechanism[i].checked=true;
8715: } else {
8716: document.forms.gradesupload.gradingmechanism[i].checked=false;
8717: }
8718: }
8719: // Remember the old state
8720: document.forms.gradesupload.waschecked.value=newgradingchoice;
8721: }
8722: </script>
1.400 www 8723: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
8724: <input type="hidden" name="symb" value="$symb" />
8725: <input type="hidden" name="command" value="processclickerfile" />
8726: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
8727: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
8728: <input type="file" name="upfile" size="50" />
8729: <br /><label>$type: $selectform</label>
1.569 bisitz 8730: <br /><label><input type="radio" name="gradingmechanism" value="attendance"$checked{'attendance'} onClick="sanitycheck()" />$attendance </label>
8731: <br /><label><input type="radio" name="gradingmechanism" value="personnel"$checked{'personnel'} onClick="sanitycheck()" />$personnel</label>
8732: <br /><label><input type="radio" name="gradingmechanism" value="specific"$checked{'specific'} onClick="sanitycheck()" />$specific </label>
1.414 www 8733: <input type="text" name="specificid" value="$env{'form.specificid'}" size="20" />
1.569 bisitz 8734: <br /><label><input type="radio" name="gradingmechanism" value="given"$checked{'given'} onClick="sanitycheck()" />$given </label>
1.521 www 8735: <br />
8736: <input type="text" name="givenanswer" size="50" />
1.413 www 8737: <input type="hidden" name="waschecked" value="$env{'form.gradingmechanism'}" />
8738: <br /><label>$pcorrect: <input type="text" name="pcorrect" size="4" value="$env{'form.pcorrect'}" onChange="sanitycheck()" /></label>
8739: <br /><label>$pincorrect: <input type="text" name="pincorrect" size="4" value="$env{'form.pincorrect'}" onChange="sanitycheck()" /></label>
1.400 www 8740: <br /><input type="button" onClick="javascript:checkUpload(this.form);" value="$upload" />
8741: </form>
8742: ENDUPFORM
8743: $result.='</td></tr></table>'."\n".
8744: '</td></tr></table><br /><br />'."\n";
8745: $result.=&show_grading_menu_form($symb);
8746: return $result;
8747: }
8748:
8749: sub process_clicker_file {
8750: my ($r)=@_;
8751: my ($symb)=&get_symb($r);
8752: if (!$symb) {return '';}
1.413 www 8753:
8754: my %Saveable_Parameters=&clicker_grading_parameters();
8755: &Apache::loncommon::store_course_settings('grades_clicker',
8756: \%Saveable_Parameters);
8757:
1.400 www 8758: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.404 www 8759: if (($env{'form.gradingmechanism'} eq 'specific') && ($env{'form.specificid'}!~/\w/)) {
1.408 albertel 8760: $result.='<span class="LC_error">'.&mt('You need to specify a clicker ID for the correct answer').'</span>';
8761: return $result.&show_grading_menu_form($symb);
1.404 www 8762: }
1.522 www 8763: if (($env{'form.gradingmechanism'} eq 'given') && ($env{'form.givenanswer'}!~/\S/)) {
1.521 www 8764: $result.='<span class="LC_error">'.&mt('You need to specify the correct answer').'</span>';
8765: return $result.&show_grading_menu_form($symb);
8766: }
1.522 www 8767: my $foundgiven=0;
1.521 www 8768: if ($env{'form.gradingmechanism'} eq 'given') {
8769: $env{'form.givenanswer'}=~s/^\s*//gs;
8770: $env{'form.givenanswer'}=~s/\s*$//gs;
8771: $env{'form.givenanswer'}=~s/[^a-zA-Z0-9\.\*\-]+/\,/g;
8772: $env{'form.givenanswer'}=uc($env{'form.givenanswer'});
1.522 www 8773: my @answers=split(/\,/,$env{'form.givenanswer'});
8774: $foundgiven=$#answers+1;
1.521 www 8775: }
1.407 albertel 8776: my %clicker_ids=&gather_clicker_ids();
1.408 albertel 8777: my %correct_ids;
1.404 www 8778: if ($env{'form.gradingmechanism'} eq 'personnel') {
1.408 albertel 8779: %correct_ids=&gather_adv_clicker_ids();
1.404 www 8780: }
8781: if ($env{'form.gradingmechanism'} eq 'specific') {
1.414 www 8782: foreach my $correct_id (split(/[\s\,]/,$env{'form.specificid'})) {;
8783: $correct_id=~tr/a-z/A-Z/;
8784: $correct_id=~s/\s//gs;
8785: $correct_id=~s/^[\#0]+//;
1.421 www 8786: $correct_id=~s/[\-\:]//g;
1.414 www 8787: if ($correct_id) {
8788: $correct_ids{$correct_id}='specified';
8789: }
8790: }
1.400 www 8791: }
1.404 www 8792: if ($env{'form.gradingmechanism'} eq 'attendance') {
1.408 albertel 8793: $result.=&mt('Score based on attendance only');
1.521 www 8794: } elsif ($env{'form.gradingmechanism'} eq 'given') {
1.522 www 8795: $result.=&mt('Score based on [_1] ([_2] answers)','<tt>'.$env{'form.givenanswer'}.'</tt>',$foundgiven);
1.404 www 8796: } else {
1.408 albertel 8797: my $number=0;
1.411 www 8798: $result.='<p><b>'.&mt('Correctness determined by the following IDs').'</b>';
1.408 albertel 8799: foreach my $id (sort(keys(%correct_ids))) {
1.411 www 8800: $result.='<br /><tt>'.$id.'</tt> - ';
1.408 albertel 8801: if ($correct_ids{$id} eq 'specified') {
8802: $result.=&mt('specified');
8803: } else {
8804: my ($uname,$udom)=split(/\:/,$correct_ids{$id});
8805: $result.=&Apache::loncommon::plainname($uname,$udom);
8806: }
8807: $number++;
8808: }
1.411 www 8809: $result.="</p>\n";
1.408 albertel 8810: if ($number==0) {
8811: $result.='<span class="LC_error">'.&mt('No IDs found to determine correct answer').'</span>';
8812: return $result.&show_grading_menu_form($symb);
8813: }
1.404 www 8814: }
1.405 www 8815: if (length($env{'form.upfile'}) < 2) {
1.407 albertel 8816: $result.=&mt('[_1] Error: [_2] The file you attempted to upload, [_3] contained no information. Please check that you entered the correct filename.',
8817: '<span class="LC_error">',
8818: '</span>',
8819: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>');
1.405 www 8820: return $result.&show_grading_menu_form($symb);
8821: }
1.410 www 8822:
8823: # Were able to get all the info needed, now analyze the file
8824:
1.411 www 8825: $result.=&Apache::loncommon::studentbrowser_javascript();
1.418 albertel 8826: $symb = &Apache::lonenc::check_encrypt($symb);
1.410 www 8827: my $heading=&mt('Scanning clicker file');
8828: $result.=(<<ENDHEADER);
8829: <br /><table width="100%" border="0"><tr><td bgcolor="#777777">
8830: <table width="100%" border="0"><tr bgcolor="#e6ffff"><td>
8831: <b>$heading</b></td></tr><tr bgcolor=#ffffe6><td>
8832: <form method="post" action="/adm/grades" name="clickeranalysis">
8833: <input type="hidden" name="symb" value="$symb" />
8834: <input type="hidden" name="command" value="assignclickergrades" />
8835: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
8836: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
1.411 www 8837: <input type="hidden" name="gradingmechanism" value="$env{'form.gradingmechanism'}" />
8838: <input type="hidden" name="pcorrect" value="$env{'form.pcorrect'}" />
8839: <input type="hidden" name="pincorrect" value="$env{'form.pincorrect'}" />
1.410 www 8840: ENDHEADER
1.522 www 8841: if ($env{'form.gradingmechanism'} eq 'given') {
8842: $result.='<input type="hidden" name="correct:given" value="'.$env{'form.givenanswer'}.'" />';
8843: }
1.408 albertel 8844: my %responses;
8845: my @questiontitles;
1.405 www 8846: my $errormsg='';
8847: my $number=0;
8848: if ($env{'form.upfiletype'} eq 'iclicker') {
1.408 albertel 8849: ($errormsg,$number)=&iclicker_eval(\@questiontitles,\%responses);
1.406 www 8850: }
1.419 www 8851: if ($env{'form.upfiletype'} eq 'interwrite') {
8852: ($errormsg,$number)=&interwrite_eval(\@questiontitles,\%responses);
8853: }
1.411 www 8854: $result.='<br />'.&mt('Found [_1] question(s)',$number).'<br />'.
8855: '<input type="hidden" name="number" value="'.$number.'" />'.
8856: &mt('Awarding [_1] percent for correct and [_2] percent for incorrect responses',
8857: $env{'form.pcorrect'},$env{'form.pincorrect'}).
8858: '<br />';
1.522 www 8859: if (($env{'form.gradingmechanism'} eq 'given') && ($number!=$foundgiven)) {
8860: $result.='<span class="LC_error">'.&mt('Number of given answers does not agree with number of questions in file.').'</span>';
8861: return $result.&show_grading_menu_form($symb);
8862: }
1.414 www 8863: # Remember Question Titles
8864: # FIXME: Possibly need delimiter other than ":"
8865: for (my $i=0;$i<$number;$i++) {
8866: $result.='<input type="hidden" name="question:'.$i.'" value="'.
8867: &HTML::Entities::encode($questiontitles[$i],'"&<>').'" />';
8868: }
1.411 www 8869: my $correct_count=0;
8870: my $student_count=0;
8871: my $unknown_count=0;
1.414 www 8872: # Match answers with usernames
8873: # FIXME: Possibly need delimiter other than ":"
1.409 albertel 8874: foreach my $id (keys(%responses)) {
1.410 www 8875: if ($correct_ids{$id}) {
1.414 www 8876: $result.="\n".'<input type="hidden" name="correct:'.$correct_count.':'.$correct_ids{$id}.'" value="'.$responses{$id}.'" />';
1.411 www 8877: $correct_count++;
1.410 www 8878: } elsif ($clicker_ids{$id}) {
1.437 www 8879: if ($clicker_ids{$id}=~/\,/) {
8880: # More than one user with the same clicker!
8881: $result.="\n<hr />".&mt('Clicker registered more than once').": <tt>".$id."</tt><br />";
8882: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
8883: "<select name='multi".$id."'>";
8884: foreach my $reguser (sort(split(/\,/,$clicker_ids{$id}))) {
8885: $result.="<option value='".$reguser."'>".&Apache::loncommon::plainname(split(/\:/,$reguser)).' ('.$reguser.')</option>';
8886: }
8887: $result.='</select>';
8888: $unknown_count++;
8889: } else {
8890: # Good: found one and only one user with the right clicker
8891: $result.="\n".'<input type="hidden" name="student:'.$clicker_ids{$id}.'" value="'.$responses{$id}.'" />';
8892: $student_count++;
8893: }
1.410 www 8894: } else {
1.411 www 8895: $result.="\n<hr />".&mt('Unregistered Clicker')." <tt>".$id."</tt><br />";
8896: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
8897: "\n".&mt("Username").": <input type='text' name='uname".$id."' /> ".
8898: "\n".&mt("Domain").": ".
8899: &Apache::loncommon::select_dom_form($env{'course.'.$env{'request.course.id'}.'.domain'},'udom'.$id).' '.
8900: &Apache::loncommon::selectstudent_link('clickeranalysis','uname'.$id,'udom'.$id);
8901: $unknown_count++;
1.410 www 8902: }
1.405 www 8903: }
1.412 www 8904: $result.='<hr />'.
8905: &mt('Found [_1] registered and [_2] unregistered clickers.',$student_count,$unknown_count);
1.521 www 8906: if (($env{'form.gradingmechanism'} ne 'attendance') && ($env{'form.gradingmechanism'} ne 'given')) {
1.412 www 8907: if ($correct_count==0) {
8908: $errormsg.="Found no correct answers answers for grading!";
8909: } elsif ($correct_count>1) {
1.414 www 8910: $result.='<br /><span class="LC_warning">'.&mt("Found [_1] entries for grading!",$correct_count).'</span>';
1.412 www 8911: }
8912: }
1.428 www 8913: if ($number<1) {
8914: $errormsg.="Found no questions.";
8915: }
1.412 www 8916: if ($errormsg) {
8917: $result.='<br /><span class="LC_error">'.&mt($errormsg).'</span>';
8918: } else {
8919: $result.='<br /><input type="submit" name="finalize" value="'.&mt('Finalize Grading').'" />';
8920: }
8921: $result.='</form></td></tr></table>'."\n".
1.410 www 8922: '</td></tr></table><br /><br />'."\n";
1.404 www 8923: return $result.&show_grading_menu_form($symb);
1.400 www 8924: }
8925:
1.405 www 8926: sub iclicker_eval {
1.406 www 8927: my ($questiontitles,$responses)=@_;
1.405 www 8928: my $number=0;
8929: my $errormsg='';
8930: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
1.410 www 8931: my %components=&Apache::loncommon::record_sep($line);
8932: my @entries=map {$components{$_}} (sort(keys(%components)));
1.408 albertel 8933: if ($entries[0] eq 'Question') {
8934: for (my $i=3;$i<$#entries;$i+=6) {
8935: $$questiontitles[$number]=$entries[$i];
8936: $number++;
8937: }
8938: }
8939: if ($entries[0]=~/^\#/) {
8940: my $id=$entries[0];
8941: my @idresponses;
8942: $id=~s/^[\#0]+//;
8943: for (my $i=0;$i<$number;$i++) {
8944: my $idx=3+$i*6;
8945: push(@idresponses,$entries[$idx]);
8946: }
8947: $$responses{$id}=join(',',@idresponses);
8948: }
1.405 www 8949: }
8950: return ($errormsg,$number);
8951: }
8952:
1.419 www 8953: sub interwrite_eval {
8954: my ($questiontitles,$responses)=@_;
8955: my $number=0;
8956: my $errormsg='';
1.420 www 8957: my $skipline=1;
8958: my $questionnumber=0;
8959: my %idresponses=();
1.419 www 8960: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
8961: my %components=&Apache::loncommon::record_sep($line);
8962: my @entries=map {$components{$_}} (sort(keys(%components)));
1.420 www 8963: if ($entries[1] eq 'Time') { $skipline=0; next; }
8964: if ($entries[1] eq 'Response') { $skipline=1; }
8965: next if $skipline;
8966: if ($entries[0]!=$questionnumber) {
8967: $questionnumber=$entries[0];
8968: $$questiontitles[$number]=&mt('Question [_1]',$questionnumber);
8969: $number++;
1.419 www 8970: }
1.420 www 8971: my $id=$entries[4];
8972: $id=~s/^[\#0]+//;
1.421 www 8973: $id=~s/^v\d*\://i;
8974: $id=~s/[\-\:]//g;
1.420 www 8975: $idresponses{$id}[$number]=$entries[6];
8976: }
1.524 raeburn 8977: foreach my $id (keys(%idresponses)) {
1.420 www 8978: $$responses{$id}=join(',',@{$idresponses{$id}});
8979: $$responses{$id}=~s/^\s*\,//;
1.419 www 8980: }
8981: return ($errormsg,$number);
8982: }
8983:
1.414 www 8984: sub assign_clicker_grades {
8985: my ($r)=@_;
8986: my ($symb)=&get_symb($r);
8987: if (!$symb) {return '';}
1.416 www 8988: # See which part we are saving to
8989: my ($partlist,$handgrade,$responseType) = &response_type($symb);
8990: # FIXME: This should probably look for the first handgradeable part
8991: my $part=$$partlist[0];
8992: # Start screen output
1.414 www 8993: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.416 www 8994:
1.414 www 8995: my $heading=&mt('Assigning grades based on clicker file');
8996: $result.=(<<ENDHEADER);
8997: <br /><table width="100%" border="0"><tr><td bgcolor="#777777">
8998: <table width="100%" border="0"><tr bgcolor="#e6ffff"><td>
8999: <b>$heading</b></td></tr><tr bgcolor=#ffffe6><td>
9000: ENDHEADER
9001: # Get correct result
9002: # FIXME: Possibly need delimiter other than ":"
9003: my @correct=();
1.415 www 9004: my $gradingmechanism=$env{'form.gradingmechanism'};
9005: my $number=$env{'form.number'};
9006: if ($gradingmechanism ne 'attendance') {
1.414 www 9007: foreach my $key (keys(%env)) {
9008: if ($key=~/^form\.correct\:/) {
9009: my @input=split(/\,/,$env{$key});
9010: for (my $i=0;$i<=$#input;$i++) {
9011: if (($correct[$i]) && ($input[$i]) &&
9012: ($correct[$i] ne $input[$i])) {
9013: $result.='<br /><span class="LC_warning">'.
9014: &mt('More than one correct result given for question "[_1]": [_2] versus [_3].',
9015: $env{'form.question:'.$i},$correct[$i],$input[$i]).'</span>';
9016: } elsif ($input[$i]) {
9017: $correct[$i]=$input[$i];
9018: }
9019: }
9020: }
9021: }
1.415 www 9022: for (my $i=0;$i<$number;$i++) {
1.414 www 9023: if (!$correct[$i]) {
9024: $result.='<br /><span class="LC_error">'.
9025: &mt('No correct result given for question "[_1]"!',
9026: $env{'form.question:'.$i}).'</span>';
9027: }
9028: }
9029: $result.='<br />'.&mt("Correct answer: [_1]",join(', ',map { ($_?$_:'-') } @correct));
9030: }
9031: # Start grading
1.415 www 9032: my $pcorrect=$env{'form.pcorrect'};
9033: my $pincorrect=$env{'form.pincorrect'};
1.416 www 9034: my $storecount=0;
1.415 www 9035: foreach my $key (keys(%env)) {
1.420 www 9036: my $user='';
1.415 www 9037: if ($key=~/^form\.student\:(.*)$/) {
1.420 www 9038: $user=$1;
9039: }
9040: if ($key=~/^form\.unknown\:(.*)$/) {
9041: my $id=$1;
9042: if (($env{'form.uname'.$id}) && ($env{'form.udom'.$id})) {
9043: $user=$env{'form.uname'.$id}.':'.$env{'form.udom'.$id};
1.437 www 9044: } elsif ($env{'form.multi'.$id}) {
9045: $user=$env{'form.multi'.$id};
1.420 www 9046: }
9047: }
9048: if ($user) {
1.415 www 9049: my @answer=split(/\,/,$env{$key});
9050: my $sum=0;
1.522 www 9051: my $realnumber=$number;
1.415 www 9052: for (my $i=0;$i<$number;$i++) {
9053: if ($answer[$i]) {
9054: if ($gradingmechanism eq 'attendance') {
9055: $sum+=$pcorrect;
1.522 www 9056: } elsif ($answer[$i] eq '*') {
9057: $sum+=$pcorrect;
9058: } elsif ($answer[$i] eq '-') {
9059: $realnumber--;
1.415 www 9060: } else {
9061: if ($answer[$i] eq $correct[$i]) {
9062: $sum+=$pcorrect;
9063: } else {
9064: $sum+=$pincorrect;
9065: }
9066: }
9067: }
9068: }
1.522 www 9069: my $ave=$sum/(100*$realnumber);
1.416 www 9070: # Store
9071: my ($username,$domain)=split(/\:/,$user);
9072: my %grades=();
9073: $grades{"resource.$part.solved"}='correct_by_override';
9074: $grades{"resource.$part.awarded"}=$ave;
9075: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
9076: my $returncode=&Apache::lonnet::cstore(\%grades,$symb,
9077: $env{'request.course.id'},
9078: $domain,$username);
9079: if ($returncode ne 'ok') {
9080: $result.="<br /><span class=\"LC_error\">Failed to save student $username:$domain. Message when trying to save was ($returncode)</span>";
9081: } else {
9082: $storecount++;
9083: }
1.415 www 9084: }
9085: }
9086: # We are done
1.549 hauer 9087: $result.='<br />'.&mt('Successfully stored grades for [quant,_1,student].',$storecount).
1.416 www 9088: '</td></tr></table>'."\n".
1.414 www 9089: '</td></tr></table><br /><br />'."\n";
9090: return $result.&show_grading_menu_form($symb);
9091: }
9092:
1.1 albertel 9093: sub handler {
1.41 ng 9094: my $request=$_[0];
1.434 albertel 9095: &reset_caches();
1.257 albertel 9096: if ($env{'browser.mathml'}) {
1.141 www 9097: &Apache::loncommon::content_type($request,'text/xml');
1.41 ng 9098: } else {
1.141 www 9099: &Apache::loncommon::content_type($request,'text/html');
1.41 ng 9100: }
9101: $request->send_http_header;
1.44 ng 9102: return '' if $request->header_only;
1.41 ng 9103: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.324 albertel 9104: my $symb=&get_symb($request,1);
1.160 albertel 9105: my @commands=&Apache::loncommon::get_env_multiple('form.command');
9106: my $command=$commands[0];
1.447 foxr 9107:
1.160 albertel 9108: if ($#commands > 0) {
9109: &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands));
9110: }
1.447 foxr 9111:
1.513 foxr 9112: $ssi_error = 0;
1.535 raeburn 9113: my $brcrum = [{href=>"/adm/grades",text=>"Grading"}];
9114: $request->print(&Apache::loncommon::start_page('Grading',undef,
9115: {'bread_crumbs' => $brcrum}));
1.324 albertel 9116: if ($symb eq '' && $command eq '') {
1.257 albertel 9117: if ($env{'user.adv'}) {
9118: if (($env{'form.codeone'}) && ($env{'form.codetwo'}) &&
9119: ($env{'form.codethree'})) {
9120: my $token=$env{'form.codeone'}.'*'.$env{'form.codetwo'}.'*'.
9121: $env{'form.codethree'};
1.41 ng 9122: my ($tsymb,$tuname,$tudom,$tcrsid)=
9123: &Apache::lonnet::checkin($token);
9124: if ($tsymb) {
1.137 albertel 9125: my ($map,$id,$url)=&Apache::lonnet::decode_symb($tsymb);
1.41 ng 9126: if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
1.513 foxr 9127: $request->print(&ssi_with_retries('/res/'.$url, $ssi_retries,
1.99 albertel 9128: ('grade_username' => $tuname,
9129: 'grade_domain' => $tudom,
9130: 'grade_courseid' => $tcrsid,
9131: 'grade_symb' => $tsymb)));
1.41 ng 9132: } else {
1.45 ng 9133: $request->print('<h3>Not authorized: '.$token.'</h3>');
1.99 albertel 9134: }
1.41 ng 9135: } else {
1.45 ng 9136: $request->print('<h3>Not a valid DocID: '.$token.'</h3>');
1.41 ng 9137: }
1.14 www 9138: } else {
1.41 ng 9139: $request->print(&Apache::lonxml::tokeninputfield());
9140: }
9141: }
9142: } else {
1.285 albertel 9143: &init_perm();
1.104 albertel 9144: if ($command eq 'submission' && $perm{'vgr'}) {
1.257 albertel 9145: ($env{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0));
1.103 albertel 9146: } elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) {
1.68 ng 9147: &pickStudentPage($request);
1.103 albertel 9148: } elsif ($command eq 'displayPage' && $perm{'vgr'}) {
1.68 ng 9149: &displayPage($request);
1.104 albertel 9150: } elsif ($command eq 'gradeByPage' && $perm{'mgr'}) {
1.71 ng 9151: &updateGradeByPage($request);
1.104 albertel 9152: } elsif ($command eq 'processGroup' && $perm{'vgr'}) {
1.41 ng 9153: &processGroup($request);
1.104 albertel 9154: } elsif ($command eq 'gradingmenu' && $perm{'vgr'}) {
1.443 banghart 9155: $request->print(&grading_menu($request));
9156: } elsif ($command eq 'submit_options' && $perm{'vgr'}) {
9157: $request->print(&submit_options($request));
1.104 albertel 9158: } elsif ($command eq 'viewgrades' && $perm{'vgr'}) {
1.41 ng 9159: $request->print(&viewgrades($request));
1.104 albertel 9160: } elsif ($command eq 'handgrade' && $perm{'mgr'}) {
1.41 ng 9161: $request->print(&processHandGrade($request));
1.106 albertel 9162: } elsif ($command eq 'editgrades' && $perm{'mgr'}) {
1.41 ng 9163: $request->print(&editgrades($request));
1.106 albertel 9164: } elsif ($command eq 'verify' && $perm{'vgr'}) {
1.41 ng 9165: $request->print(&verifyreceipt($request));
1.400 www 9166: } elsif ($command eq 'processclicker' && $perm{'mgr'}) {
9167: $request->print(&process_clicker($request));
9168: } elsif ($command eq 'processclickerfile' && $perm{'mgr'}) {
9169: $request->print(&process_clicker_file($request));
1.414 www 9170: } elsif ($command eq 'assignclickergrades' && $perm{'mgr'}) {
9171: $request->print(&assign_clicker_grades($request));
1.106 albertel 9172: } elsif ($command eq 'csvform' && $perm{'mgr'}) {
1.72 ng 9173: $request->print(&upcsvScores_form($request));
1.106 albertel 9174: } elsif ($command eq 'csvupload' && $perm{'mgr'}) {
1.41 ng 9175: $request->print(&csvupload($request));
1.106 albertel 9176: } elsif ($command eq 'csvuploadmap' && $perm{'mgr'} ) {
1.41 ng 9177: $request->print(&csvuploadmap($request));
1.246 albertel 9178: } elsif ($command eq 'csvuploadoptions' && $perm{'mgr'}) {
1.257 albertel 9179: if ($env{'form.associate'} ne 'Reverse Association') {
1.246 albertel 9180: $request->print(&csvuploadoptions($request));
1.41 ng 9181: } else {
1.257 albertel 9182: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
9183: $env{'form.upfile_associate'} = 'reverse';
1.41 ng 9184: } else {
1.257 albertel 9185: $env{'form.upfile_associate'} = 'forward';
1.41 ng 9186: }
9187: $request->print(&csvuploadmap($request));
9188: }
1.246 albertel 9189: } elsif ($command eq 'csvuploadassign' && $perm{'mgr'} ) {
9190: $request->print(&csvuploadassign($request));
1.106 albertel 9191: } elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
1.75 albertel 9192: $request->print(&scantron_selectphase($request));
1.203 albertel 9193: } elsif ($command eq 'scantron_warning' && $perm{'mgr'}) {
9194: $request->print(&scantron_do_warning($request));
1.142 albertel 9195: } elsif ($command eq 'scantron_validate' && $perm{'mgr'}) {
9196: $request->print(&scantron_validate_file($request));
1.106 albertel 9197: } elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
1.82 albertel 9198: $request->print(&scantron_process_students($request));
1.157 albertel 9199: } elsif ($command eq 'scantronupload' &&
1.257 albertel 9200: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
9201: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.162 albertel 9202: $request->print(&scantron_upload_scantron_data($request));
1.157 albertel 9203: } elsif ($command eq 'scantronupload_save' &&
1.257 albertel 9204: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
9205: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.157 albertel 9206: $request->print(&scantron_upload_scantron_data_save($request));
1.202 albertel 9207: } elsif ($command eq 'scantron_download' &&
1.257 albertel 9208: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.162 albertel 9209: $request->print(&scantron_download_scantron_data($request));
1.523 raeburn 9210: } elsif ($command eq 'checksubmissions' && $perm{'vgr'}) {
9211: $request->print(&checkscantron_results($request));
1.106 albertel 9212: } elsif ($command) {
1.562 bisitz 9213: $request->print('<p class="LC_error">'.&mt('Access Denied ([_1])',$command).'</p>');
1.26 albertel 9214: }
1.2 albertel 9215: }
1.513 foxr 9216: if ($ssi_error) {
9217: &ssi_print_error($request);
9218: }
1.353 albertel 9219: $request->print(&Apache::loncommon::end_page());
1.434 albertel 9220: &reset_caches();
1.44 ng 9221: return '';
9222: }
9223:
1.1 albertel 9224: 1;
9225:
1.13 albertel 9226: __END__;
1.531 jms 9227:
9228:
9229: =head1 NAME
9230:
9231: Apache::grades
9232:
9233: =head1 SYNOPSIS
9234:
9235: Handles the viewing of grades.
9236:
9237: This is part of the LearningOnline Network with CAPA project
9238: described at http://www.lon-capa.org.
9239:
9240: =head1 OVERVIEW
9241:
9242: Do an ssi with retries:
9243: While I'd love to factor out this with the vesrion in lonprintout,
9244: 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
9245: I'm not quite ready to invent (e.g. an ssi_with_retry object).
9246:
9247: At least the logic that drives this has been pulled out into loncommon.
9248:
9249:
9250:
9251: ssi_with_retries - Does the server side include of a resource.
9252: if the ssi call returns an error we'll retry it up to
9253: the number of times requested by the caller.
9254: If we still have a proble, no text is appended to the
9255: output and we set some global variables.
9256: to indicate to the caller an SSI error occurred.
9257: All of this is supposed to deal with the issues described
9258: in LonCAPA BZ 5631 see:
9259: http://bugs.lon-capa.org/show_bug.cgi?id=5631
9260: by informing the user that this happened.
9261:
9262: Parameters:
9263: resource - The resource to include. This is passed directly, without
9264: interpretation to lonnet::ssi.
9265: form - The form hash parameters that guide the interpretation of the resource
9266:
9267: retries - Number of retries allowed before giving up completely.
9268: Returns:
9269: On success, returns the rendered resource identified by the resource parameter.
9270: Side Effects:
9271: The following global variables can be set:
9272: ssi_error - If an unrecoverable error occurred this becomes true.
9273: It is up to the caller to initialize this to false
9274: if desired.
9275: ssi_error_resource - If an unrecoverable error occurred, this is the value
9276: of the resource that could not be rendered by the ssi
9277: call.
9278: ssi_error_message - The error string fetched from the ssi response
9279: in the event of an error.
9280:
9281:
9282: =head1 HANDLER SUBROUTINE
9283:
9284: ssi_with_retries()
9285:
9286: =head1 SUBROUTINES
9287:
9288: =over
9289:
9290: =item scantron_get_correction() :
9291:
9292: Builds the interface screen to interact with the operator to fix a
9293: specific error condition in a specific scanline
9294:
9295: Arguments:
9296: $r - Apache request object
9297: $i - number of the current scanline
9298: $scan_record - hash ref as returned from &scantron_parse_scanline()
9299: $scan_config - hash ref as returned from &get_scantron_config()
9300: $line - full contents of the current scanline
9301: $error - error condition, valid values are
9302: 'incorrectCODE', 'duplicateCODE',
9303: 'doublebubble', 'missingbubble',
9304: 'duplicateID', 'incorrectID'
9305: $arg - extra information needed
9306: For errors:
9307: - duplicateID - paper number that this studentID was seen before on
9308: - duplicateCODE - array ref of the paper numbers this CODE was
9309: seen on before
9310: - incorrectCODE - current incorrect CODE
9311: - doublebubble - array ref of the bubble lines that have double
9312: bubble errors
9313: - missingbubble - array ref of the bubble lines that have missing
9314: bubble errors
9315:
9316: =item scantron_get_maxbubble() :
9317:
9318: Returns the maximum number of bubble lines that are expected to
9319: occur. Does this by walking the selected sequence rendering the
9320: resource and then checking &Apache::lonxml::get_problem_counter()
9321: for what the current value of the problem counter is.
9322:
9323: Caches the results to $env{'form.scantron_maxbubble'},
9324: $env{'form.scantron.bubble_lines.n'},
9325: $env{'form.scantron.first_bubble_line.n'} and
9326: $env{"form.scantron.sub_bubblelines.n"}
9327: which are the total number of bubble, lines, the number of bubble
9328: lines for response n and number of the first bubble line for response n,
9329: and a comma separated list of numbers of bubble lines for sub-questions
9330: (for optionresponse, matchresponse, and rankresponse items), for response n.
9331:
9332:
9333: =item scantron_validate_missingbubbles() :
9334:
9335: Validates all scanlines in the selected file to not have any
9336: answers that don't have bubbles that have not been verified
9337: to be bubble free.
9338:
9339: =item scantron_process_students() :
9340:
9341: Routine that does the actual grading of the bubble sheet information.
9342:
9343: The parsed scanline hash is added to %env
9344:
9345: Then foreach unskipped scanline it does an &Apache::lonnet::ssi()
9346: foreach resource , with the form data of
9347:
9348: 'submitted' =>'scantron'
9349: 'grade_target' =>'grade',
9350: 'grade_username'=> username of student
9351: 'grade_domain' => domain of student
9352: 'grade_courseid'=> of course
9353: 'grade_symb' => symb of resource to grade
9354:
9355: This triggers a grading pass. The problem grading code takes care
9356: of converting the bubbled letter information (now in %env) into a
9357: valid submission.
9358:
9359: =item scantron_upload_scantron_data() :
9360:
9361: Creates the screen for adding a new bubble sheet data file to a course.
9362:
9363: =item scantron_upload_scantron_data_save() :
9364:
9365: Adds a provided bubble information data file to the course if user
9366: has the correct privileges to do so.
9367:
9368: =item valid_file() :
9369:
9370: Validates that the requested bubble data file exists in the course.
9371:
9372: =item scantron_download_scantron_data() :
9373:
9374: Shows a list of the three internal files (original, corrected,
9375: skipped) for a specific bubble sheet data file that exists in the
9376: course.
9377:
9378: =item scantron_validate_ID() :
9379:
9380: Validates all scanlines in the selected file to not have any
1.556 weissno 9381: invalid or underspecified student/employee IDs
1.531 jms 9382:
9383: =back
9384:
9385: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>