Annotation of loncom/homework/grades.pm, revision 1.590
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.590 ! bisitz 4: # $Id: grades.pm,v 1.589 2010/01/15 17:12:18 bisitz 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.582 raeburn 100: my ($symb,$errorref) = @_;
1.439 albertel 101:
102: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 103: unless (ref($navmap)) {
104: if (ref($errorref)) {
105: $$errorref = 'navmap';
106: return;
107: }
108: }
1.439 albertel 109: my $res = $navmap->getBySymb($symb);
110: my $partlist = $res->parts();
111: my $url = $res->src();
112: my @metakeys = split(/,/,&Apache::lonnet::metadata($url,'keys'));
113:
1.146 albertel 114: my @stores;
1.439 albertel 115: foreach my $part (@{ $partlist }) {
1.146 albertel 116: foreach my $key (@metakeys) {
117: if ($key =~ m/^stores_\Q$part\E_/) { push(@stores,$key); }
118: }
119: }
120: return @stores;
1.2 albertel 121: }
122:
1.44 ng 123: # --- Get the symbolic name of a problem and the url
1.324 albertel 124: sub get_symb {
1.173 albertel 125: my ($request,$silent) = @_;
1.257 albertel 126: (my $url=$env{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
127: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
1.173 albertel 128: if ($symb eq '') {
129: if (!$silent) {
130: $request->print("Unable to handle ambiguous references:$url:.");
131: return ();
132: }
133: }
1.418 albertel 134: &Apache::lonenc::check_decrypt(\$symb);
1.324 albertel 135: return ($symb);
1.32 ng 136: }
137:
1.129 ng 138: #--- Format fullname, username:domain if different for display
139: #--- Use anywhere where the student names are listed
140: sub nameUserString {
141: my ($type,$fullname,$uname,$udom) = @_;
142: if ($type eq 'header') {
1.485 albertel 143: return '<b> '.&mt('Fullname').' </b><span class="LC_internal_info">('.&mt('Username').')</span>';
1.129 ng 144: } else {
1.398 albertel 145: return ' '.$fullname.'<span class="LC_internal_info"> ('.$uname.
146: ($env{'user.domain'} eq $udom ? '' : ' ('.$udom.')').')</span>';
1.129 ng 147: }
148: }
149:
1.44 ng 150: #--- Get the partlist and the response type for a given problem. ---
151: #--- Indicate if a response type is coded handgraded or not. ---
1.39 ng 152: sub response_type {
1.582 raeburn 153: my ($symb,$response_error) = @_;
1.377 albertel 154:
155: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 156: unless (ref($navmap)) {
157: if (ref($response_error)) {
158: $$response_error = 1;
159: }
160: return;
161: }
1.377 albertel 162: my $res = $navmap->getBySymb($symb);
163: my $partlist = $res->parts();
1.392 albertel 164: my %vPart =
165: map { $_ => 1 } (&Apache::loncommon::get_env_multiple('form.vPart'));
1.377 albertel 166: my (%response_types,%handgrade);
167: foreach my $part (@{ $partlist }) {
1.392 albertel 168: next if (%vPart && !exists($vPart{$part}));
169:
1.377 albertel 170: my @types = $res->responseType($part);
171: my @ids = $res->responseIds($part);
172: for (my $i=0; $i < scalar(@ids); $i++) {
173: $response_types{$part}{$ids[$i]} = $types[$i];
174: $handgrade{$part.'_'.$ids[$i]} =
175: &Apache::lonnet::EXT('resource.'.$part.'_'.$ids[$i].
176: '.handgrade',$symb);
1.41 ng 177: }
178: }
1.377 albertel 179: return ($partlist,\%handgrade,\%response_types);
1.39 ng 180: }
181:
1.375 albertel 182: sub flatten_responseType {
183: my ($responseType) = @_;
184: my @part_response_id =
185: map {
186: my $part = $_;
187: map {
188: [$part,$_]
189: } sort(keys(%{ $responseType->{$part} }));
190: } sort(keys(%$responseType));
191: return @part_response_id;
192: }
193:
1.207 albertel 194: sub get_display_part {
1.324 albertel 195: my ($partID,$symb)=@_;
1.207 albertel 196: my $display=&Apache::lonnet::EXT('resource.'.$partID.'.display',$symb);
197: if (defined($display) and $display ne '') {
1.577 bisitz 198: $display.= ' (<span class="LC_internal_info">'
199: .&mt('Part ID: [_1]',$partID).'</span>)';
1.207 albertel 200: } else {
201: $display=$partID;
202: }
203: return $display;
204: }
1.269 raeburn 205:
1.118 ng 206: #--- Show resource title
207: #--- and parts and response type
208: sub showResourceInfo {
1.582 raeburn 209: my ($symb,$probTitle,$checkboxes,$res_error) = @_;
1.398 albertel 210: my $result = '<h3>'.&mt('Current Resource').': '.$probTitle.'</h3>'."\n";
1.582 raeburn 211: my ($partlist,$handgrade,$responseType) = &response_type($symb,$res_error);
212: if (ref($res_error)) {
213: if ($$res_error) {
214: return;
215: }
216: }
1.584 bisitz 217: $result.=&Apache::loncommon::start_data_table()
218: .&Apache::loncommon::start_data_table_header_row();
219: if ($checkboxes) {
220: $result.='<th> </th>';
221: }
222: $result.='<th>'.&mt('Problem Part').'</th>'
223: .'<th>'.&mt('Res. ID').'</th>'
224: .'<th>'.&mt('Type').'</th>'
225: .&Apache::loncommon::end_data_table_header_row();
1.126 ng 226: my %resptype = ();
1.122 ng 227: my $hdgrade='no';
1.154 albertel 228: my %partsseen;
1.524 raeburn 229: foreach my $partID (sort(keys(%$responseType))) {
1.584 bisitz 230: foreach my $resID (sort(keys(%{ $responseType->{$partID} }))) {
231: my $handgrade=$$handgrade{$partID.'_'.$resID};
232: my $responsetype = $responseType->{$partID}->{$resID};
233: $hdgrade = $handgrade if ($handgrade eq 'yes');
234: $result.=&Apache::loncommon::start_data_table_row();
235: if ($checkboxes) {
236: if (exists($partsseen{$partID})) {
237: $result.="<td> </td>";
238: } else {
239: $result.="<td><input type='checkbox' name='vPart' value='$partID' checked='checked' /></td>";
240: }
241: $partsseen{$partID}=1;
242: }
243: my $display_part=&get_display_part($partID,$symb);
244: $result.='<td>'.$display_part.'</td>'
245: .'<td>'.'<span class="LC_internal_info">'.$resID.'</span></td>'
246: .'<td>'.&mt($responsetype).'</td>'
247: # .'<td>'.&mt('<b>Handgrade: </b>[_1]',$handgrade).'</td>'
248: .&Apache::loncommon::end_data_table_row();
249: }
1.118 ng 250: }
1.584 bisitz 251: $result.=&Apache::loncommon::end_data_table();
1.147 albertel 252: return $result,$responseType,$hdgrade,$partlist,$handgrade;
1.118 ng 253: }
254:
1.434 albertel 255: sub reset_caches {
256: &reset_analyze_cache();
257: &reset_perm();
258: }
259:
260: {
261: my %analyze_cache;
1.557 raeburn 262: my %analyze_cache_formkeys;
1.148 albertel 263:
1.434 albertel 264: sub reset_analyze_cache {
265: undef(%analyze_cache);
1.557 raeburn 266: undef(%analyze_cache_formkeys);
1.434 albertel 267: }
268:
269: sub get_analyze {
1.557 raeburn 270: my ($symb,$uname,$udom,$no_increment,$add_to_hash)=@_;
1.434 albertel 271: my $key = "$symb\0$uname\0$udom";
1.557 raeburn 272: if (exists($analyze_cache{$key})) {
273: my $getupdate = 0;
274: if (ref($add_to_hash) eq 'HASH') {
275: foreach my $item (keys(%{$add_to_hash})) {
276: if (ref($analyze_cache_formkeys{$key}) eq 'HASH') {
277: if (!exists($analyze_cache_formkeys{$key}{$item})) {
278: $getupdate = 1;
279: last;
280: }
281: } else {
282: $getupdate = 1;
283: }
284: }
285: }
286: if (!$getupdate) {
287: return $analyze_cache{$key};
288: }
289: }
1.434 albertel 290:
291: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
292: $url=&Apache::lonnet::clutter($url);
1.557 raeburn 293: my %form = ('grade_target' => 'analyze',
294: 'grade_domain' => $udom,
295: 'grade_symb' => $symb,
296: 'grade_courseid' => $env{'request.course.id'},
297: 'grade_username' => $uname,
298: 'grade_noincrement' => $no_increment);
299: if (ref($add_to_hash)) {
300: %form = (%form,%{$add_to_hash});
301: }
302: my $subresult=&ssi_with_retries($url, $ssi_retries,%form);
1.434 albertel 303: (undef,$subresult)=split(/_HASH_REF__/,$subresult,2);
304: my %analyze=&Apache::lonnet::str2hash($subresult);
1.557 raeburn 305: if (ref($add_to_hash) eq 'HASH') {
306: $analyze_cache_formkeys{$key} = $add_to_hash;
307: } else {
308: $analyze_cache_formkeys{$key} = {};
309: }
1.434 albertel 310: return $analyze_cache{$key} = \%analyze;
311: }
312:
313: sub get_order {
1.525 raeburn 314: my ($partid,$respid,$symb,$uname,$udom,$no_increment)=@_;
315: my $analyze = &get_analyze($symb,$uname,$udom,$no_increment);
1.434 albertel 316: return $analyze->{"$partid.$respid.shown"};
317: }
318:
319: sub get_radiobutton_correct_foil {
320: my ($partid,$respid,$symb,$uname,$udom)=@_;
321: my $analyze = &get_analyze($symb,$uname,$udom);
1.555 raeburn 322: my $foils = &get_order($partid,$respid,$symb,$uname,$udom);
323: if (ref($foils) eq 'ARRAY') {
324: foreach my $foil (@{$foils}) {
325: if ($analyze->{"$partid.$respid.foil.value.$foil"} eq 'true') {
326: return $foil;
327: }
1.434 albertel 328: }
329: }
330: }
1.554 raeburn 331:
332: sub scantron_partids_tograde {
1.557 raeburn 333: my ($resource,$cid,$uname,$udom,$check_for_randomlist) = @_;
1.554 raeburn 334: my (%analysis,@parts);
335: if (ref($resource)) {
336: my $symb = $resource->symb();
1.557 raeburn 337: my $add_to_form;
338: if ($check_for_randomlist) {
339: $add_to_form = { 'check_parts_withrandomlist' => 1,};
340: }
341: my $analyze = &get_analyze($symb,$uname,$udom,undef,$add_to_form);
1.554 raeburn 342: if (ref($analyze) eq 'HASH') {
343: %analysis = %{$analyze};
344: }
345: if (ref($analysis{'parts'}) eq 'ARRAY') {
346: foreach my $part (@{$analysis{'parts'}}) {
347: my ($id,$respid) = split(/\./,$part);
348: if (!&Apache::loncommon::check_if_partid_hidden($id,$symb,$udom,$uname)) {
349: push(@parts,$part);
350: }
351: }
352: }
353: }
354: return (\%analysis,\@parts);
355: }
356:
1.148 albertel 357: }
1.434 albertel 358:
1.118 ng 359: #--- Clean response type for display
1.335 albertel 360: #--- Currently filters option/rank/radiobutton/match/essay/Task
361: # response types only.
1.118 ng 362: sub cleanRecord {
1.336 albertel 363: my ($answer,$response,$symb,$partid,$respid,$record,$order,$version,
364: $uname,$udom) = @_;
1.398 albertel 365: my $grayFont = '<span class="LC_internal_info">';
1.148 albertel 366: if ($response =~ /^(option|rank)$/) {
367: my %answer=&Apache::lonnet::str2hash($answer);
368: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
369: my ($toprow,$bottomrow);
370: foreach my $foil (@$order) {
371: if ($grading{$foil} == 1) {
372: $toprow.='<td><b>'.$answer{$foil}.' </b></td>';
373: } else {
374: $toprow.='<td><i>'.$answer{$foil}.' </i></td>';
375: }
1.398 albertel 376: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.148 albertel 377: }
378: return '<blockquote><table border="1">'.
1.466 albertel 379: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
380: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.148 albertel 381: $grayFont.$bottomrow.'</tr>'.'</table></blockquote>';
382: } elsif ($response eq 'match') {
383: my %answer=&Apache::lonnet::str2hash($answer);
384: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
385: my @items=&Apache::lonnet::str2array($record->{$version."resource.$partid.$respid.submissionitems"});
386: my ($toprow,$middlerow,$bottomrow);
387: foreach my $foil (@$order) {
388: my $item=shift(@items);
389: if ($grading{$foil} == 1) {
390: $toprow.='<td><b>'.$item.' </b></td>';
1.398 albertel 391: $middlerow.='<td><b>'.$grayFont.$answer{$foil}.' </span></b></td>';
1.148 albertel 392: } else {
393: $toprow.='<td><i>'.$item.' </i></td>';
1.398 albertel 394: $middlerow.='<td><i>'.$grayFont.$answer{$foil}.' </span></i></td>';
1.148 albertel 395: }
1.398 albertel 396: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.118 ng 397: }
1.126 ng 398: return '<blockquote><table border="1">'.
1.466 albertel 399: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
400: '<tr valign="top"><td>'.$grayFont.&mt('Item ID').'</span></td>'.
1.148 albertel 401: $middlerow.'</tr>'.
1.466 albertel 402: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.148 albertel 403: $bottomrow.'</tr>'.'</table></blockquote>';
404: } elsif ($response eq 'radiobutton') {
405: my %answer=&Apache::lonnet::str2hash($answer);
406: my ($toprow,$bottomrow);
1.434 albertel 407: my $correct =
408: &get_radiobutton_correct_foil($partid,$respid,$symb,$uname,$udom);
409: foreach my $foil (@$order) {
1.148 albertel 410: if (exists($answer{$foil})) {
1.434 albertel 411: if ($foil eq $correct) {
1.466 albertel 412: $toprow.='<td><b>'.&mt('true').'</b></td>';
1.148 albertel 413: } else {
1.466 albertel 414: $toprow.='<td><i>'.&mt('true').'</i></td>';
1.148 albertel 415: }
416: } else {
1.466 albertel 417: $toprow.='<td>'.&mt('false').'</td>';
1.148 albertel 418: }
1.398 albertel 419: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.148 albertel 420: }
421: return '<blockquote><table border="1">'.
1.466 albertel 422: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
423: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.148 albertel 424: $grayFont.$bottomrow.'</tr>'.'</table></blockquote>';
425: } elsif ($response eq 'essay') {
1.257 albertel 426: if (! exists ($env{'form.'.$symb})) {
1.122 ng 427: my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 428: $env{'course.'.$env{'request.course.id'}.'.domain'},
429: $env{'course.'.$env{'request.course.id'}.'.num'});
1.122 ng 430:
1.257 albertel 431: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
432: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
433: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
434: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
435: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
436: $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 437: }
1.166 albertel 438: $answer =~ s-\n-<br />-g;
439: return '<br /><br /><blockquote><tt>'.&keywords_highlight($answer).'</tt></blockquote>';
1.268 albertel 440: } elsif ( $response eq 'organic') {
441: my $result='Smile representation: "<tt>'.$answer.'</tt>"';
442: my $jme=$record->{$version."resource.$partid.$respid.molecule"};
443: $result.=&Apache::chemresponse::jme_img($jme,$answer,400);
444: return $result;
1.335 albertel 445: } elsif ( $response eq 'Task') {
446: if ( $answer eq 'SUBMITTED') {
447: my $files = $record->{$version."resource.$respid.$partid.bridgetask.portfiles"};
1.336 albertel 448: my $result = &Apache::bridgetask::file_list($files,$uname,$udom);
1.335 albertel 449: return $result;
450: } elsif ( grep(/^\Q$version\E.*?\.instance$/, keys(%{$record})) ) {
451: my @matches = grep(/^\Q$version\E.*?\.instance$/,
452: keys(%{$record}));
453: return join('<br />',($version,@matches));
454:
455:
456: } else {
457: my $result =
458: '<p>'
459: .&mt('Overall result: [_1]',
460: $record->{$version."resource.$respid.$partid.status"})
461: .'</p>';
462:
463: $result .= '<ul>';
464: my @grade = grep(/^\Q${version}resource.$respid.$partid.\E[^.]*[.]status$/,
465: keys(%{$record}));
466: foreach my $grade (sort(@grade)) {
467: my ($dim) = ($grade =~/[.]([^.]+)[.]status$/);
468: $result.= '<li>'.&mt("Dimension: [_1], status [_2] ",
469: $dim, $record->{$grade}).
470: '</li>';
471: }
472: $result.='</ul>';
473: return $result;
474: }
1.440 albertel 475: } elsif ( $response =~ m/(?:numerical|formula)/) {
476: $answer =
477: &Apache::loncommon::format_previous_attempt_value('submission',
478: $answer);
1.122 ng 479: }
1.118 ng 480: return $answer;
481: }
482:
483: #-- A couple of common js functions
484: sub commonJSfunctions {
485: my $request = shift;
486: $request->print(<<COMMONJSFUNCTIONS);
487: <script type="text/javascript" language="javascript">
488: function radioSelection(radioButton) {
489: var selection=null;
490: if (radioButton.length > 1) {
491: for (var i=0; i<radioButton.length; i++) {
492: if (radioButton[i].checked) {
493: return radioButton[i].value;
494: }
495: }
496: } else {
497: if (radioButton.checked) return radioButton.value;
498: }
499: return selection;
500: }
501:
502: function pullDownSelection(selectOne) {
503: var selection="";
504: if (selectOne.length > 1) {
505: for (var i=0; i<selectOne.length; i++) {
506: if (selectOne[i].selected) {
507: return selectOne[i].value;
508: }
509: }
510: } else {
1.138 albertel 511: // only one value it must be the selected one
512: return selectOne.value;
1.118 ng 513: }
514: }
515: </script>
516: COMMONJSFUNCTIONS
517: }
518:
1.44 ng 519: #--- Dumps the class list with usernames,list of sections,
520: #--- section, ids and fullnames for each user.
521: sub getclasslist {
1.449 banghart 522: my ($getsec,$filterlist,$getgroup) = @_;
1.291 albertel 523: my @getsec;
1.450 banghart 524: my @getgroup;
1.442 banghart 525: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.291 albertel 526: if (!ref($getsec)) {
527: if ($getsec ne '' && $getsec ne 'all') {
528: @getsec=($getsec);
529: }
530: } else {
531: @getsec=@{$getsec};
532: }
533: if (grep(/^all$/,@getsec)) { undef(@getsec); }
1.450 banghart 534: if (!ref($getgroup)) {
535: if ($getgroup ne '' && $getgroup ne 'all') {
536: @getgroup=($getgroup);
537: }
538: } else {
539: @getgroup=@{$getgroup};
540: }
541: if (grep(/^all$/,@getgroup)) { undef(@getgroup); }
1.291 albertel 542:
1.449 banghart 543: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
1.49 albertel 544: # Bail out if we were unable to get the classlist
1.56 matthew 545: return if (! defined($classlist));
1.449 banghart 546: &Apache::loncoursedata::get_group_memberships($classlist,$keylist);
1.56 matthew 547: #
548: my %sections;
549: my %fullnames;
1.205 matthew 550: foreach my $student (keys(%$classlist)) {
551: my $end =
552: $classlist->{$student}->[&Apache::loncoursedata::CL_END()];
553: my $start =
554: $classlist->{$student}->[&Apache::loncoursedata::CL_START()];
555: my $id =
556: $classlist->{$student}->[&Apache::loncoursedata::CL_ID()];
557: my $section =
558: $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
559: my $fullname =
560: $classlist->{$student}->[&Apache::loncoursedata::CL_FULLNAME()];
561: my $status =
562: $classlist->{$student}->[&Apache::loncoursedata::CL_STATUS()];
1.449 banghart 563: my $group =
564: $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1.76 ng 565: # filter students according to status selected
1.442 banghart 566: if ($filterlist && (!($stu_status =~ /Any/))) {
567: if (!($stu_status =~ $status)) {
1.450 banghart 568: delete($classlist->{$student});
1.76 ng 569: next;
570: }
571: }
1.450 banghart 572: # filter students according to groups selected
1.453 banghart 573: my @stu_groups = split(/,/,$group);
1.450 banghart 574: if (@getgroup) {
575: my $exclude = 1;
1.454 banghart 576: foreach my $grp (@getgroup) {
577: foreach my $stu_group (@stu_groups) {
1.453 banghart 578: if ($stu_group eq $grp) {
579: $exclude = 0;
580: }
1.450 banghart 581: }
1.453 banghart 582: if (($grp eq 'none') && !$group) {
583: $exclude = 0;
584: }
1.450 banghart 585: }
586: if ($exclude) {
587: delete($classlist->{$student});
588: }
589: }
1.205 matthew 590: $section = ($section ne '' ? $section : 'none');
1.106 albertel 591: if (&canview($section)) {
1.291 albertel 592: if (!@getsec || grep(/^\Q$section\E$/,@getsec)) {
1.103 albertel 593: $sections{$section}++;
1.450 banghart 594: if ($classlist->{$student}) {
595: $fullnames{$student}=$fullname;
596: }
1.103 albertel 597: } else {
1.205 matthew 598: delete($classlist->{$student});
1.103 albertel 599: }
600: } else {
1.205 matthew 601: delete($classlist->{$student});
1.103 albertel 602: }
1.44 ng 603: }
604: my %seen = ();
1.56 matthew 605: my @sections = sort(keys(%sections));
606: return ($classlist,\@sections,\%fullnames);
1.44 ng 607: }
608:
1.103 albertel 609: sub canmodify {
610: my ($sec)=@_;
611: if ($perm{'mgr'}) {
612: if (!defined($perm{'mgr_section'})) {
613: # can modify whole class
614: return 1;
615: } else {
616: if ($sec eq $perm{'mgr_section'}) {
617: #can modify the requested section
618: return 1;
619: } else {
620: # can't modify the request section
621: return 0;
622: }
623: }
624: }
625: #can't modify
626: return 0;
627: }
628:
629: sub canview {
630: my ($sec)=@_;
631: if ($perm{'vgr'}) {
632: if (!defined($perm{'vgr_section'})) {
633: # can modify whole class
634: return 1;
635: } else {
636: if ($sec eq $perm{'vgr_section'}) {
637: #can modify the requested section
638: return 1;
639: } else {
640: # can't modify the request section
641: return 0;
642: }
643: }
644: }
645: #can't modify
646: return 0;
647: }
648:
1.44 ng 649: #--- Retrieve the grade status of a student for all the parts
650: sub student_gradeStatus {
1.324 albertel 651: my ($symb,$udom,$uname,$partlist) = @_;
1.257 albertel 652: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.44 ng 653: my %partstatus = ();
654: foreach (@$partlist) {
1.128 ng 655: my ($status,undef) = split(/_/,$record{"resource.$_.solved"},2);
1.44 ng 656: $status = 'nothing' if ($status eq '');
657: $partstatus{$_} = $status;
658: my $subkey = "resource.$_.submitted_by";
659: $partstatus{$subkey} = $record{$subkey} if ($record{$subkey} ne '');
660: }
661: return %partstatus;
662: }
663:
1.45 ng 664: # hidden form and javascript that calls the form
665: # Use by verifyscript and viewgrades
666: # Shows a student's view of problem and submission
667: sub jscriptNform {
1.324 albertel 668: my ($symb) = @_;
1.442 banghart 669: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.45 ng 670: my $jscript='<script type="text/javascript" language="javascript">'."\n".
671: ' function viewOneStudent(user,domain) {'."\n".
672: ' document.onestudent.student.value = user;'."\n".
673: ' document.onestudent.userdom.value = domain;'."\n".
674: ' document.onestudent.submit();'."\n".
675: ' }'."\n".
676: '</script>'."\n";
677: $jscript.= '<form action="/adm/grades" method="post" name="onestudent">'."\n".
1.418 albertel 678: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 679: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
680: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.442 banghart 681: '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.45 ng 682: '<input type="hidden" name="command" value="submission" />'."\n".
683: '<input type="hidden" name="student" value="" />'."\n".
684: '<input type="hidden" name="userdom" value="" />'."\n".
685: '</form>'."\n";
686: return $jscript;
687: }
1.39 ng 688:
1.447 foxr 689:
690:
1.315 bowersj2 691: # Given the score (as a number [0-1] and the weight) what is the final
692: # point value? This function will round to the nearest tenth, third,
693: # or quarter if one of those is within the tolerance of .00001.
1.316 albertel 694: sub compute_points {
1.315 bowersj2 695: my ($score, $weight) = @_;
696:
697: my $tolerance = .00001;
698: my $points = $score * $weight;
699:
700: # Check for nearness to 1/x.
701: my $check_for_nearness = sub {
702: my ($factor) = @_;
703: my $num = ($points * $factor) + $tolerance;
704: my $floored_num = floor($num);
1.316 albertel 705: if ($num - $floored_num < 2 * $tolerance * $factor) {
1.315 bowersj2 706: return $floored_num / $factor;
707: }
708: return $points;
709: };
710:
711: $points = $check_for_nearness->(10);
712: $points = $check_for_nearness->(3);
713: $points = $check_for_nearness->(4);
714:
715: return $points;
716: }
717:
1.44 ng 718: #------------------ End of general use routines --------------------
1.87 www 719:
720: #
721: # Find most similar essay
722: #
723:
724: sub most_similar {
1.426 albertel 725: my ($uname,$udom,$uessay,$old_essays)=@_;
1.87 www 726:
727: # ignore spaces and punctuation
728:
729: $uessay=~s/\W+/ /gs;
730:
1.282 www 731: # ignore empty submissions (occuring when only files are sent)
732:
733: unless ($uessay=~/\w+/) { return ''; }
734:
1.87 www 735: # these will be returned. Do not care if not at least 50 percent similar
1.88 www 736: my $limit=0.6;
1.87 www 737: my $sname='';
738: my $sdom='';
739: my $scrsid='';
740: my $sessay='';
741: # go through all essays ...
1.426 albertel 742: foreach my $tkey (keys(%$old_essays)) {
743: my ($tname,$tdom,$tcrsid)=map {&unescape($_)} (split(/\./,$tkey));
1.87 www 744: # ... except the same student
1.426 albertel 745: next if (($tname eq $uname) && ($tdom eq $udom));
746: my $tessay=$old_essays->{$tkey};
747: $tessay=~s/\W+/ /gs;
1.87 www 748: # String similarity gives up if not even limit
1.426 albertel 749: my $tsimilar=&String::Similarity::similarity($uessay,$tessay,$limit);
1.87 www 750: # Found one
1.426 albertel 751: if ($tsimilar>$limit) {
752: $limit=$tsimilar;
753: $sname=$tname;
754: $sdom=$tdom;
755: $scrsid=$tcrsid;
756: $sessay=$old_essays->{$tkey};
757: }
1.87 www 758: }
1.88 www 759: if ($limit>0.6) {
1.87 www 760: return ($sname,$sdom,$scrsid,$sessay,$limit);
761: } else {
762: return ('','','','',0);
763: }
764: }
765:
1.44 ng 766: #-------------------------------------------------------------------
767:
768: #------------------------------------ Receipt Verification Routines
1.45 ng 769: #
1.44 ng 770: #--- Check whether a receipt number is valid.---
771: sub verifyreceipt {
772: my $request = shift;
773:
1.257 albertel 774: my $courseid = $env{'request.course.id'};
1.184 www 775: my $receipt = &Apache::lonnet::recprefix($courseid).'-'.
1.257 albertel 776: $env{'form.receipt'};
1.44 ng 777: $receipt =~ s/[^\-\d]//g;
1.378 albertel 778: my ($symb) = &get_symb($request);
1.44 ng 779:
1.487 albertel 780: my $title.=
781: '<h3><span class="LC_info">'.
1.584 bisitz 782: &mt('Verifying Receipt No. [_1]',$receipt).
1.487 albertel 783: '</span></h3>'."\n".
784: '<h4>'.&mt('<b>Resource: </b>[_1]',$env{'form.probTitle'}).
785: '</h4>'."\n";
1.44 ng 786:
787: my ($string,$contents,$matches) = ('','',0);
1.56 matthew 788: my (undef,undef,$fullname) = &getclasslist('all','0');
1.177 albertel 789:
790: my $receiptparts=0;
1.390 albertel 791: if ($env{"course.$courseid.receiptalg"} eq 'receipt2' ||
792: $env{"course.$courseid.receiptalg"} eq 'receipt3') { $receiptparts=1; }
1.177 albertel 793: my $parts=['0'];
1.582 raeburn 794: if ($receiptparts) {
795: my $res_error;
796: ($parts)=&response_type($symb,\$res_error);
797: if ($res_error) {
798: return &navmap_errormsg();
799: }
800: }
1.486 albertel 801:
802: my $header =
803: &Apache::loncommon::start_data_table().
804: &Apache::loncommon::start_data_table_header_row().
1.487 albertel 805: '<th> '.&mt('Fullname').' </th>'."\n".
806: '<th> '.&mt('Username').' </th>'."\n".
807: '<th> '.&mt('Domain').' </th>';
1.486 albertel 808: if ($receiptparts) {
1.487 albertel 809: $header.='<th> '.&mt('Problem Part').' </th>';
1.486 albertel 810: }
811: $header.=
812: &Apache::loncommon::end_data_table_header_row();
813:
1.294 albertel 814: foreach (sort
815: {
816: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
817: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
818: }
819: return $a cmp $b;
820: } (keys(%$fullname))) {
1.44 ng 821: my ($uname,$udom)=split(/\:/);
1.177 albertel 822: foreach my $part (@$parts) {
823: if ($receipt eq &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb,$part)) {
1.486 albertel 824: $contents.=
825: &Apache::loncommon::start_data_table_row().
826: '<td> '."\n".
1.177 albertel 827: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 828: '\');" target="_self">'.$$fullname{$_}.'</a> </td>'."\n".
1.177 albertel 829: '<td> '.$uname.' </td>'.
830: '<td> '.$udom.' </td>';
831: if ($receiptparts) {
832: $contents.='<td> '.$part.' </td>';
833: }
1.486 albertel 834: $contents.=
835: &Apache::loncommon::end_data_table_row()."\n";
1.177 albertel 836:
837: $matches++;
838: }
1.44 ng 839: }
840: }
841: if ($matches == 0) {
1.584 bisitz 842: $string = $title
843: .'<p class="LC_warning">'
844: .&mt('No match found for the above receipt number.')
845: .'</p>';
1.44 ng 846: } else {
1.324 albertel 847: $string = &jscriptNform($symb).$title.
1.487 albertel 848: '<p>'.
1.584 bisitz 849: &mt('The above receipt number matches the following [quant,_1,student].',$matches).
1.487 albertel 850: '</p>'.
1.486 albertel 851: $header.
852: $contents.
853: &Apache::loncommon::end_data_table()."\n";
1.44 ng 854: }
1.324 albertel 855: return $string.&show_grading_menu_form($symb);
1.44 ng 856: }
857:
858: #--- This is called by a number of programs.
859: #--- Called from the Grading Menu - View/Grade an individual student
860: #--- Also called directly when one clicks on the subm button
861: # on the problem page.
1.30 ng 862: sub listStudents {
1.41 ng 863: my ($request) = shift;
1.49 albertel 864:
1.324 albertel 865: my ($symb) = &get_symb($request);
1.257 albertel 866: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
867: my $cnum = $env{"course.$env{'request.course.id'}.num"};
868: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.449 banghart 869: my $getgroup = $env{'form.group'} eq '' ? 'all' : $env{'form.group'};
1.257 albertel 870: my $submitonly= $env{'form.submitonly'} eq '' ? 'all' : $env{'form.submitonly'};
1.548 bisitz 871: my $viewgrade = $env{'form.showgrading'} eq 'yes' ? 'View/Grade/Regrade' : 'View';
1.257 albertel 872: $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
873: &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
1.49 albertel 874:
1.548 bisitz 875: my $result='<h3><span class="LC_info"> '
876: .&mt("$viewgrade Submissions for a Student or a Group of Students")
1.485 albertel 877: .'</span></h3>';
1.118 ng 878:
1.324 albertel 879: my ($table,undef,$hdgrade,$partlist,$handgrade) = &showResourceInfo($symb,$env{'form.probTitle'},($env{'form.showgrading'} eq 'yes'));
1.49 albertel 880:
1.559 raeburn 881: my %lt = &Apache::lonlocal::texthash (
882: 'multiple' => 'Please select a student or group of students before clicking on the Next button.',
883: 'single' => 'Please select the student before clicking on the Next button.',
884: );
1.45 ng 885: $request->print(<<LISTJAVASCRIPT);
886: <script type="text/javascript" language="javascript">
1.110 ng 887: function checkSelect(checkBox) {
888: var ctr=0;
889: var sense="";
890: if (checkBox.length > 1) {
891: for (var i=0; i<checkBox.length; i++) {
892: if (checkBox[i].checked) {
893: ctr++;
894: }
895: }
1.485 albertel 896: sense = '$lt{'multiple'}';
1.110 ng 897: } else {
898: if (checkBox.checked) {
899: ctr = 1;
900: }
1.485 albertel 901: sense = '$lt{'single'}';
1.110 ng 902: }
903: if (ctr == 0) {
1.485 albertel 904: alert(sense);
1.110 ng 905: return false;
906: }
907: document.gradesub.submit();
908: }
909:
910: function reLoadList(formname) {
1.112 ng 911: if (formname.saveStatusOld.value == pullDownSelection(formname.Status)) {return;}
1.110 ng 912: formname.command.value = 'submission';
913: formname.submit();
914: }
1.45 ng 915: </script>
916: LISTJAVASCRIPT
917:
1.118 ng 918: &commonJSfunctions($request);
1.41 ng 919: $request->print($result);
1.39 ng 920:
1.401 albertel 921: my $checkhdgrade = ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1 ) ? 'checked="checked"' : '';
922: my $checklastsub = $checkhdgrade eq '' ? 'checked="checked"' : '';
1.154 albertel 923: my $gradeTable='<form action="/adm/grades" method="post" name="gradesub">'.
1.485 albertel 924: "\n".$table;
925:
1.561 bisitz 926: $gradeTable .= &Apache::lonhtmlcommon::start_pick_box();
927: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Problem Text'))
928: .'<label><input type="radio" name="vProb" value="no" checked="checked" /> '.&mt('no').' </label>'."\n"
929: .'<label><input type="radio" name="vProb" value="yes" /> '.&mt('one student').' </label>'."\n"
930: .'<label><input type="radio" name="vProb" value="all" /> '.&mt('all students').' </label><br />'."\n"
931: .&Apache::lonhtmlcommon::row_closure();
932: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Answer'))
933: .'<label><input type="radio" name="vAns" value="no" /> '.&mt('no').' </label>'."\n"
934: .'<label><input type="radio" name="vAns" value="yes" /> '.&mt('one student').' </label>'."\n"
935: .'<label><input type="radio" name="vAns" value="all" checked="checked" /> '.&mt('all students').' </label><br />'."\n"
936: .&Apache::lonhtmlcommon::row_closure();
1.485 albertel 937:
938: my $submission_options;
1.257 albertel 939: if ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1) {
1.485 albertel 940: $submission_options.=
941: '<label><input type="radio" name="lastSub" value="hdgrade" '.$checkhdgrade.' /> '.&mt('essay part only').' </label>'."\n";
1.49 albertel 942: }
1.442 banghart 943: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
944: my $saveStatus = $stu_status eq '' ? 'Active' : $stu_status;
1.257 albertel 945: $env{'form.Status'} = $saveStatus;
1.485 albertel 946: $submission_options.=
947: '<label><input type="radio" name="lastSub" value="lastonly" '.$checklastsub.' /> '.&mt('last submission only').' </label>'."\n".
948: '<label><input type="radio" name="lastSub" value="last" /> '.&mt('last submission & parts info').' </label>'."\n".
949: '<label><input type="radio" name="lastSub" value="datesub" /> '.&mt('by dates and submissions').' </label>'."\n".
950: '<label><input type="radio" name="lastSub" value="all" /> '.&mt('all details').'</label>';
1.561 bisitz 951: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Submissions'))
952: .$submission_options
953: .&Apache::lonhtmlcommon::row_closure();
954:
955: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Grading Increments'))
956: .'<select name="increment">'
957: .'<option value="1">'.&mt('Whole Points').'</option>'
958: .'<option value=".5">'.&mt('Half Points').'</option>'
959: .'<option value=".25">'.&mt('Quarter Points').'</option>'
960: .'<option value=".1">'.&mt('Tenths of a Point').'</option>'
961: .'</select>'
962: .&Apache::lonhtmlcommon::row_closure();
1.485 albertel 963:
964: $gradeTable .=
1.432 banghart 965: &build_section_inputs().
1.45 ng 966: '<input type="hidden" name="submitonly" value="'.$submitonly.'" />'."\n".
1.257 albertel 967: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" /><br />'."\n".
968: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" /><br />'."\n".
969: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
970: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.418 albertel 971: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.110 ng 972: '<input type="hidden" name="saveStatusOld" value="'.$saveStatus.'" />'."\n";
973:
1.257 albertel 974: if (exists($env{'form.gradingMenu'}) && exists($env{'form.Status'})) {
1.561 bisitz 975: $gradeTable .= '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n";
1.124 ng 976: } else {
1.561 bisitz 977: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Student Status'))
978: .&Apache::lonhtmlcommon::StatusOptions(
979: $saveStatus,undef,1,'javascript:reLoadList(this.form);')
980: .&Apache::lonhtmlcommon::row_closure();
1.124 ng 981: }
1.112 ng 982:
1.561 bisitz 983: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Check For Plagiarism'))
984: .'<input type="checkbox" name="checkPlag" checked="checked" />'
985: .&Apache::lonhtmlcommon::row_closure(1)
986: .&Apache::lonhtmlcommon::end_pick_box();
987:
988: $gradeTable .= '<p>'
989: .&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"
990: .'<input type="hidden" name="command" value="processGroup" />'
991: .'</p>';
1.249 albertel 992:
993: # checkall buttons
994: $gradeTable.=&check_script('gradesub', 'stuinfo');
1.110 ng 995: $gradeTable.='<input type="button" '."\n".
1.589 bisitz 996: 'onclick="javascript:checkSelect(this.form.stuinfo);" '."\n".
997: 'value="'.&mt('Next').' →" /> <br />'."\n";
1.249 albertel 998: $gradeTable.=&check_buttons();
1.450 banghart 999: my ($classlist, undef, $fullname) = &getclasslist($getsec,'1',$getgroup);
1.474 albertel 1000: $gradeTable.= &Apache::loncommon::start_data_table().
1001: &Apache::loncommon::start_data_table_header_row();
1.110 ng 1002: my $loop = 0;
1003: while ($loop < 2) {
1.485 albertel 1004: $gradeTable.='<th>'.&mt('No.').'</th><th>'.&mt('Select').'</th>'.
1005: '<th>'.&nameUserString('header').' '.&mt('Section/Group').'</th>';
1.301 albertel 1006: if ($env{'form.showgrading'} eq 'yes'
1007: && $submitonly ne 'queued'
1008: && $submitonly ne 'all') {
1.485 albertel 1009: foreach my $part (sort(@$partlist)) {
1010: my $display_part=
1011: &get_display_part((split(/_/,$part))[0],$symb);
1012: $gradeTable.=
1013: '<th>'.&mt('Part: [_1] Status',$display_part).'</th>';
1.110 ng 1014: }
1.301 albertel 1015: } elsif ($submitonly eq 'queued') {
1.474 albertel 1016: $gradeTable.='<th>'.&mt('Queue Status').' </th>';
1.110 ng 1017: }
1018: $loop++;
1.126 ng 1019: # $gradeTable.='<td></td>' if ($loop%2 ==1);
1.41 ng 1020: }
1.474 albertel 1021: $gradeTable.=&Apache::loncommon::end_data_table_header_row()."\n";
1.41 ng 1022:
1.45 ng 1023: my $ctr = 0;
1.294 albertel 1024: foreach my $student (sort
1025: {
1026: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
1027: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
1028: }
1029: return $a cmp $b;
1030: }
1031: (keys(%$fullname))) {
1.41 ng 1032: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 1033:
1.110 ng 1034: my %status = ();
1.301 albertel 1035:
1036: if ($submitonly eq 'queued') {
1037: my %queue_status =
1038: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
1039: $udom,$uname);
1040: next if (!defined($queue_status{'gradingqueue'}));
1041: $status{'gradingqueue'} = $queue_status{'gradingqueue'};
1042: }
1043:
1044: if ($env{'form.showgrading'} eq 'yes'
1045: && $submitonly ne 'queued'
1046: && $submitonly ne 'all') {
1.324 albertel 1047: (%status) =&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 1048: my $submitted = 0;
1.164 albertel 1049: my $graded = 0;
1.248 albertel 1050: my $incorrect = 0;
1.110 ng 1051: foreach (keys(%status)) {
1.145 albertel 1052: $submitted = 1 if ($status{$_} ne 'nothing');
1.248 albertel 1053: $graded = 1 if ($status{$_} =~ /^ungraded/);
1054: $incorrect = 1 if ($status{$_} =~ /^incorrect/);
1055:
1.110 ng 1056: my ($foo,$partid,$foo1) = split(/\./,$_);
1057: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
1.145 albertel 1058: $submitted = 0;
1.150 albertel 1059: my ($part)=split(/\./,$partid);
1.110 ng 1060: $gradeTable.='<input type="hidden" name="'.
1.150 albertel 1061: $student.':'.$part.':submitted_by" value="'.
1.110 ng 1062: $status{'resource.'.$partid.'.submitted_by'}.'" />';
1063: }
1.41 ng 1064: }
1.248 albertel 1065:
1.156 albertel 1066: next if (!$submitted && ($submitonly eq 'yes' ||
1067: $submitonly eq 'incorrect' ||
1068: $submitonly eq 'graded'));
1.248 albertel 1069: next if (!$graded && ($submitonly eq 'graded'));
1070: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 1071: }
1.34 ng 1072:
1.45 ng 1073: $ctr++;
1.249 albertel 1074: my $section = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
1.452 banghart 1075: my $group = $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1.104 albertel 1076: if ( $perm{'vgr'} eq 'F' ) {
1.474 albertel 1077: if ($ctr%2 ==1) {
1078: $gradeTable.= &Apache::loncommon::start_data_table_row();
1079: }
1.126 ng 1080: $gradeTable.='<td align="right">'.$ctr.' </td>'.
1.563 bisitz 1081: '<td align="center"><label><input type="checkbox" name="stuinfo" value="'.
1.249 albertel 1082: $student.':'.$$fullname{$student}.':::SECTION'.$section.
1083: ') " /> </label></td>'."\n".'<td>'.
1084: &nameUserString(undef,$$fullname{$student},$uname,$udom).
1.474 albertel 1085: ' '.$section.($group ne '' ?'/'.$group:'').'</td>'."\n";
1.110 ng 1086:
1.257 albertel 1087: if ($env{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
1.524 raeburn 1088: foreach (sort(keys(%status))) {
1.485 albertel 1089: next if ($_ =~ /^resource.*?submitted_by$/);
1090: $gradeTable.='<td align="center"> '.&mt($status{$_}).' </td>'."\n";
1.110 ng 1091: }
1.41 ng 1092: }
1.126 ng 1093: # $gradeTable.='<td></td>' if ($ctr%2 ==1);
1.474 albertel 1094: if ($ctr%2 ==0) {
1095: $gradeTable.=&Apache::loncommon::end_data_table_row()."\n";
1096: }
1.41 ng 1097: }
1098: }
1.110 ng 1099: if ($ctr%2 ==1) {
1.126 ng 1100: $gradeTable.='<td> </td><td> </td><td> </td>';
1.301 albertel 1101: if ($env{'form.showgrading'} eq 'yes'
1102: && $submitonly ne 'queued'
1103: && $submitonly ne 'all') {
1.110 ng 1104: foreach (@$partlist) {
1105: $gradeTable.='<td> </td>';
1106: }
1.301 albertel 1107: } elsif ($submitonly eq 'queued') {
1108: $gradeTable.='<td> </td>';
1.110 ng 1109: }
1.474 albertel 1110: $gradeTable.=&Apache::loncommon::end_data_table_row();
1.110 ng 1111: }
1112:
1.474 albertel 1113: $gradeTable.=&Apache::loncommon::end_data_table()."\n".
1.589 bisitz 1114: '<input type="button" '.
1115: 'onclick="javascript:checkSelect(this.form.stuinfo);" '.
1116: 'value="'.&mt('Next').' →" /></form>'."\n";
1.45 ng 1117: if ($ctr == 0) {
1.96 albertel 1118: my $num_students=(scalar(keys(%$fullname)));
1119: if ($num_students eq 0) {
1.485 albertel 1120: $gradeTable='<br /> <span class="LC_warning">'.&mt('There are no students currently enrolled.').'</span>';
1.96 albertel 1121: } else {
1.171 albertel 1122: my $submissions='submissions';
1123: if ($submitonly eq 'incorrect') { $submissions = 'incorrect submissions'; }
1124: if ($submitonly eq 'graded' ) { $submissions = 'ungraded submissions'; }
1.301 albertel 1125: if ($submitonly eq 'queued' ) { $submissions = 'queued submissions'; }
1.398 albertel 1126: $gradeTable='<br /> <span class="LC_warning">'.
1.485 albertel 1127: &mt('No '.$submissions.' found for this resource for any students. ([_1] students checked for '.$submissions.')',
1128: $num_students).
1129: '</span><br />';
1.96 albertel 1130: }
1.46 ng 1131: } elsif ($ctr == 1) {
1.474 albertel 1132: $gradeTable =~ s/type="checkbox"/type="checkbox" checked="checked"/;
1.45 ng 1133: }
1.324 albertel 1134: $gradeTable.=&show_grading_menu_form($symb);
1.45 ng 1135: $request->print($gradeTable);
1.44 ng 1136: return '';
1.10 ng 1137: }
1138:
1.44 ng 1139: #---- Called from the listStudents routine
1.249 albertel 1140:
1141: sub check_script {
1142: my ($form, $type)=@_;
1143: my $chkallscript='<script type="text/javascript">
1144: function checkall() {
1145: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1146: ele = document.forms.'.$form.'.elements[i];
1147: if (ele.name == "'.$type.'") {
1148: document.forms.'.$form.'.elements[i].checked=true;
1149: }
1150: }
1151: }
1152:
1153: function checksec() {
1154: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1155: ele = document.forms.'.$form.'.elements[i];
1156: string = document.forms.'.$form.'.chksec.value;
1157: if
1158: (ele.value.indexOf(":::SECTION"+string)>0) {
1159: document.forms.'.$form.'.elements[i].checked=true;
1160: }
1161: }
1162: }
1163:
1164:
1165: function uncheckall() {
1166: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1167: ele = document.forms.'.$form.'.elements[i];
1168: if (ele.name == "'.$type.'") {
1169: document.forms.'.$form.'.elements[i].checked=false;
1170: }
1171: }
1172: }
1173:
1174: </script>'."\n";
1175: return $chkallscript;
1176: }
1177:
1178: sub check_buttons {
1.485 albertel 1179: my $buttons.='<input type="button" onclick="checkall()" value="'.&mt('Check All').'" />';
1180: $buttons.='<input type="button" onclick="uncheckall()" value="'.&mt('Uncheck All').'" /> ';
1181: $buttons.='<input type="button" onclick="checksec()" value="'.&mt('Check Section/Group').'" />';
1.249 albertel 1182: $buttons.='<input type="text" size="5" name="chksec" /> ';
1183: return $buttons;
1184: }
1185:
1.44 ng 1186: # Displays the submissions for one student or a group of students
1.34 ng 1187: sub processGroup {
1.41 ng 1188: my ($request) = shift;
1189: my $ctr = 0;
1.155 albertel 1190: my @stuchecked = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.41 ng 1191: my $total = scalar(@stuchecked)-1;
1.45 ng 1192:
1.396 banghart 1193: foreach my $student (@stuchecked) {
1194: my ($uname,$udom,$fullname) = split(/:/,$student);
1.257 albertel 1195: $env{'form.student'} = $uname;
1196: $env{'form.userdom'} = $udom;
1197: $env{'form.fullname'} = $fullname;
1.41 ng 1198: &submission($request,$ctr,$total);
1199: $ctr++;
1200: }
1201: return '';
1.35 ng 1202: }
1.34 ng 1203:
1.44 ng 1204: #------------------------------------------------------------------------------------
1205: #
1206: #-------------------------- Next few routines handles grading by student, essentially
1207: # handles essay response type problem/part
1208: #
1209: #--- Javascript to handle the submission page functionality ---
1210: sub sub_page_js {
1211: my $request = shift;
1.539 riegler 1212: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
1.44 ng 1213: $request->print(<<SUBJAVASCRIPT);
1214: <script type="text/javascript" language="javascript">
1.71 ng 1215: function updateRadio(formname,id,weight) {
1.125 ng 1216: var gradeBox = formname["GD_BOX"+id];
1217: var radioButton = formname["RADVAL"+id];
1218: var oldpts = formname["oldpts"+id].value;
1.72 ng 1219: var pts = checkSolved(formname,id) == 'update' ? gradeBox.value : oldpts;
1.71 ng 1220: gradeBox.value = pts;
1221: var resetbox = false;
1222: if (isNaN(pts) || pts < 0) {
1.539 riegler 1223: alert("$alertmsg"+pts);
1.71 ng 1224: for (var i=0; i<radioButton.length; i++) {
1225: if (radioButton[i].checked) {
1226: gradeBox.value = i;
1227: resetbox = true;
1228: }
1229: }
1230: if (!resetbox) {
1231: formtextbox.value = "";
1232: }
1233: return;
1.44 ng 1234: }
1.71 ng 1235:
1236: if (pts > weight) {
1237: var resp = confirm("You entered a value ("+pts+
1238: ") greater than the weight for the part. Accept?");
1239: if (resp == false) {
1.125 ng 1240: gradeBox.value = oldpts;
1.71 ng 1241: return;
1242: }
1.44 ng 1243: }
1.13 albertel 1244:
1.71 ng 1245: for (var i=0; i<radioButton.length; i++) {
1246: radioButton[i].checked=false;
1247: if (pts == i && pts != "") {
1248: radioButton[i].checked=true;
1249: }
1250: }
1251: updateSelect(formname,id);
1.125 ng 1252: formname["stores"+id].value = "0";
1.41 ng 1253: }
1.5 albertel 1254:
1.72 ng 1255: function writeBox(formname,id,pts) {
1.125 ng 1256: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1257: if (checkSolved(formname,id) == 'update') {
1258: gradeBox.value = pts;
1259: } else {
1.125 ng 1260: var oldpts = formname["oldpts"+id].value;
1.72 ng 1261: gradeBox.value = oldpts;
1.125 ng 1262: var radioButton = formname["RADVAL"+id];
1.71 ng 1263: for (var i=0; i<radioButton.length; i++) {
1264: radioButton[i].checked=false;
1.72 ng 1265: if (i == oldpts) {
1.71 ng 1266: radioButton[i].checked=true;
1267: }
1268: }
1.41 ng 1269: }
1.125 ng 1270: formname["stores"+id].value = "0";
1.71 ng 1271: updateSelect(formname,id);
1272: return;
1.41 ng 1273: }
1.44 ng 1274:
1.71 ng 1275: function clearRadBox(formname,id) {
1276: if (checkSolved(formname,id) == 'noupdate') {
1277: updateSelect(formname,id);
1278: return;
1279: }
1.125 ng 1280: gradeSelect = formname["GD_SEL"+id];
1.71 ng 1281: for (var i=0; i<gradeSelect.length; i++) {
1282: if (gradeSelect[i].selected) {
1283: var selectx=i;
1284: }
1285: }
1.125 ng 1286: var stores = formname["stores"+id];
1.71 ng 1287: if (selectx == stores.value) { return };
1.125 ng 1288: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1289: gradeBox.value = "";
1.125 ng 1290: var radioButton = formname["RADVAL"+id];
1.71 ng 1291: for (var i=0; i<radioButton.length; i++) {
1292: radioButton[i].checked=false;
1293: }
1294: stores.value = selectx;
1295: }
1.5 albertel 1296:
1.71 ng 1297: function checkSolved(formname,id) {
1.125 ng 1298: if (formname["solved"+id].value == "correct_by_student" && formname.overRideScore.value == 'no') {
1.118 ng 1299: var reply = confirm("This problem has been graded correct by the computer. Do you want to change the score?");
1300: if (!reply) {return "noupdate";}
1.120 ng 1301: formname.overRideScore.value = 'yes';
1.41 ng 1302: }
1.71 ng 1303: return "update";
1.13 albertel 1304: }
1.71 ng 1305:
1306: function updateSelect(formname,id) {
1.125 ng 1307: formname["GD_SEL"+id][0].selected = true;
1.71 ng 1308: return;
1.41 ng 1309: }
1.33 ng 1310:
1.121 ng 1311: //=========== Check that a point is assigned for all the parts ============
1.71 ng 1312: function checksubmit(formname,val,total,parttot) {
1.121 ng 1313: formname.gradeOpt.value = val;
1.71 ng 1314: if (val == "Save & Next") {
1315: for (i=0;i<=total;i++) {
1316: for (j=0;j<parttot;j++) {
1.125 ng 1317: var partid = formname["partid"+i+"_"+j].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;
1.71 ng 1320: if (points == "") {
1.125 ng 1321: var name = formname["name"+i].value;
1.129 ng 1322: var studentID = (name != '' ? name : formname["unamedom"+i].value);
1323: var resp = confirm("You did not assign a score for "+studentID+
1324: ", part "+partid+". Continue?");
1.71 ng 1325: if (resp == false) {
1.125 ng 1326: formname["GD_BOX"+i+"_"+partid].focus();
1.71 ng 1327: return false;
1328: }
1329: }
1330: }
1331:
1332: }
1333: }
1334:
1335: }
1.121 ng 1336: if (val == "Grade Student") {
1337: formname.showgrading.value = "yes";
1338: if (formname.Status.value == "") {
1339: formname.Status.value = "Active";
1340: }
1341: formname.studentNo.value = total;
1342: }
1.120 ng 1343: formname.submit();
1344: }
1345:
1.71 ng 1346: //======= Check that a score is assigned for all the problems (page/sequence grading only) =========
1347: function checkSubmitPage(formname,total) {
1348: noscore = new Array(100);
1349: var ptr = 0;
1350: for (i=1;i<total;i++) {
1.125 ng 1351: var partid = formname["q_"+i].value;
1.127 ng 1352: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1353: var points = formname["GD_BOX"+i+"_"+partid].value;
1354: var status = formname["solved"+i+"_"+partid].value;
1.71 ng 1355: if (points == "" && status != "correct_by_student") {
1356: noscore[ptr] = i;
1357: ptr++;
1358: }
1359: }
1360: }
1361: if (ptr != 0) {
1362: var sense = ptr == 1 ? ": " : "s: ";
1363: var prolist = "";
1364: if (ptr == 1) {
1365: prolist = noscore[0];
1366: } else {
1367: var i = 0;
1368: while (i < ptr-1) {
1369: prolist += noscore[i]+", ";
1370: i++;
1371: }
1372: prolist += "and "+noscore[i];
1373: }
1374: var resp = confirm("You did not assign any score for the following problem"+sense+prolist+". Continue?");
1375: if (resp == false) {
1376: return false;
1377: }
1378: }
1.45 ng 1379:
1.71 ng 1380: formname.submit();
1381: }
1382: </script>
1383: SUBJAVASCRIPT
1384: }
1.45 ng 1385:
1.71 ng 1386: #--- javascript for essay type problem --
1387: sub sub_page_kw_js {
1388: my $request = shift;
1.80 ng 1389: my $iconpath = $request->dir_config('lonIconsURL');
1.118 ng 1390: &commonJSfunctions($request);
1.350 albertel 1391:
1.351 albertel 1392: my $inner_js_msg_central=<<INNERJS;
1.350 albertel 1393: <script text="text/javascript">
1394: function checkInput() {
1395: opener.document.SCORE.msgsub.value = opener.checkEntities(document.msgcenter.msgsub.value);
1396: var nmsg = opener.document.SCORE.savemsgN.value;
1397: var usrctr = document.msgcenter.usrctr.value;
1398: var newval = opener.document.SCORE["newmsg"+usrctr];
1399: newval.value = opener.checkEntities(document.msgcenter.newmsg.value);
1400:
1401: var msgchk = "";
1402: if (document.msgcenter.subchk.checked) {
1403: msgchk = "msgsub,";
1404: }
1405: var includemsg = 0;
1406: for (var i=1; i<=nmsg; i++) {
1407: var opnmsg = opener.document.SCORE["savemsg"+i];
1408: var frmmsg = document.msgcenter["msg"+i];
1409: opnmsg.value = opener.checkEntities(frmmsg.value);
1410: var showflg = opener.document.SCORE["shownOnce"+i];
1411: showflg.value = "1";
1412: var chkbox = document.msgcenter["msgn"+i];
1413: if (chkbox.checked) {
1414: msgchk += "savemsg"+i+",";
1415: includemsg = 1;
1416: }
1417: }
1418: if (document.msgcenter.newmsgchk.checked) {
1419: msgchk += "newmsg"+usrctr;
1420: includemsg = 1;
1421: }
1422: imgformname = opener.document.SCORE["mailicon"+usrctr];
1423: imgformname.src = "$iconpath/"+((includemsg) ? "mailto.gif" : "mailbkgrd.gif");
1424: var includemsg = opener.document.SCORE["includemsg"+usrctr];
1425: includemsg.value = msgchk;
1426:
1427: self.close()
1428:
1429: }
1430: </script>
1431: INNERJS
1432:
1.351 albertel 1433: my $inner_js_highlight_central=<<INNERJS;
1434: <script type="text/javascript">
1435: function updateChoice(flag) {
1436: opener.document.SCORE.kwclr.value = opener.radioSelection(document.hlCenter.kwdclr);
1437: opener.document.SCORE.kwsize.value = opener.radioSelection(document.hlCenter.kwdsize);
1438: opener.document.SCORE.kwstyle.value = opener.radioSelection(document.hlCenter.kwdstyle);
1439: opener.document.SCORE.refresh.value = "on";
1440: if (opener.document.SCORE.keywords.value!=""){
1441: opener.document.SCORE.submit();
1442: }
1443: self.close()
1444: }
1445: </script>
1446: INNERJS
1447:
1448: my $start_page_msg_central =
1449: &Apache::loncommon::start_page('Message Central',$inner_js_msg_central,
1450: {'js_ready' => 1,
1451: 'only_body' => 1,
1452: 'bgcolor' =>'#FFFFFF',});
1453: my $end_page_msg_central =
1454: &Apache::loncommon::end_page({'js_ready' => 1});
1455:
1456:
1457: my $start_page_highlight_central =
1458: &Apache::loncommon::start_page('Highlight Central',
1459: $inner_js_highlight_central,
1.350 albertel 1460: {'js_ready' => 1,
1461: 'only_body' => 1,
1462: 'bgcolor' =>'#FFFFFF',});
1.351 albertel 1463: my $end_page_highlight_central =
1.350 albertel 1464: &Apache::loncommon::end_page({'js_ready' => 1});
1465:
1.219 www 1466: my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
1.236 albertel 1467: $docopen=~s/^document\.//;
1.539 riegler 1468: my $alertmsg = &mt('Please select a word or group of words from document and then click this link.');
1.71 ng 1469: $request->print(<<SUBJAVASCRIPT);
1470: <script type="text/javascript" language="javascript">
1.45 ng 1471:
1.44 ng 1472: //===================== Show list of keywords ====================
1.122 ng 1473: function keywords(formname) {
1474: var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",formname.keywords.value);
1.44 ng 1475: if (nret==null) return;
1.122 ng 1476: formname.keywords.value = nret;
1.44 ng 1477:
1.122 ng 1478: if (formname.keywords.value != "") {
1.128 ng 1479: formname.refresh.value = "on";
1.122 ng 1480: formname.submit();
1.44 ng 1481: }
1482: return;
1483: }
1484:
1485: //===================== Script to view submitted by ==================
1486: function viewSubmitter(submitter) {
1487: document.SCORE.refresh.value = "on";
1488: document.SCORE.NCT.value = "1";
1489: document.SCORE.unamedom0.value = submitter;
1490: document.SCORE.submit();
1491: return;
1492: }
1493:
1494: //===================== Script to add keyword(s) ==================
1495: function getSel() {
1496: if (document.getSelection) txt = document.getSelection();
1497: else if (document.selection) txt = document.selection.createRange().text;
1498: else return;
1499: var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
1500: if (cleantxt=="") {
1.539 riegler 1501: alert("$alertmsg");
1.44 ng 1502: return;
1503: }
1504: var nret = prompt("Add selection to keyword list? Edit if desired.",cleantxt);
1505: if (nret==null) return;
1.127 ng 1506: document.SCORE.keywords.value = document.SCORE.keywords.value+" "+nret;
1.44 ng 1507: if (document.SCORE.keywords.value != "") {
1.127 ng 1508: document.SCORE.refresh.value = "on";
1.44 ng 1509: document.SCORE.submit();
1510: }
1511: return;
1512: }
1513:
1514: //====================== Script for composing message ==============
1.80 ng 1515: // preload images
1516: img1 = new Image();
1517: img1.src = "$iconpath/mailbkgrd.gif";
1518: img2 = new Image();
1519: img2.src = "$iconpath/mailto.gif";
1520:
1.44 ng 1521: function msgCenter(msgform,usrctr,fullname) {
1522: var Nmsg = msgform.savemsgN.value;
1523: savedMsgHeader(Nmsg,usrctr,fullname);
1524: var subject = msgform.msgsub.value;
1.127 ng 1525: var msgchk = document.SCORE["includemsg"+usrctr].value;
1.44 ng 1526: re = /msgsub/;
1527: var shwsel = "";
1528: if (re.test(msgchk)) { shwsel = "checked" }
1.123 ng 1529: subject = (document.SCORE.shownSub.value == 0 ? checkEntities(subject) : subject);
1530: displaySubject(checkEntities(subject),shwsel);
1.44 ng 1531: for (var i=1; i<=Nmsg; i++) {
1.123 ng 1532: var testmsg = "savemsg"+i+",";
1533: re = new RegExp(testmsg,"g");
1.44 ng 1534: shwsel = "";
1535: if (re.test(msgchk)) { shwsel = "checked" }
1.125 ng 1536: var message = document.SCORE["savemsg"+i].value;
1.126 ng 1537: message = (document.SCORE["shownOnce"+i].value == 0 ? checkEntities(message) : message);
1.123 ng 1538: displaySavedMsg(i,message,shwsel); //I do not get it. w/o checkEntities on saved messages,
1539: //any < is already converted to <, etc. However, only once!!
1.44 ng 1540: }
1.125 ng 1541: newmsg = document.SCORE["newmsg"+usrctr].value;
1.44 ng 1542: shwsel = "";
1543: re = /newmsg/;
1544: if (re.test(msgchk)) { shwsel = "checked" }
1545: newMsg(newmsg,shwsel);
1546: msgTail();
1547: return;
1548: }
1549:
1.123 ng 1550: function checkEntities(strx) {
1551: if (strx.length == 0) return strx;
1552: var orgStr = ["&", "<", ">", '"'];
1553: var newStr = ["&", "<", ">", """];
1554: var counter = 0;
1555: while (counter < 4) {
1556: strx = strReplace(strx,orgStr[counter],newStr[counter]);
1557: counter++;
1558: }
1559: return strx;
1560: }
1561:
1562: function strReplace(strx, orgStr, newStr) {
1563: return strx.split(orgStr).join(newStr);
1564: }
1565:
1.44 ng 1566: function savedMsgHeader(Nmsg,usrctr,fullname) {
1.76 ng 1567: var height = 70*Nmsg+250;
1.44 ng 1568: var scrollbar = "no";
1569: if (height > 600) {
1570: height = 600;
1571: scrollbar = "yes";
1572: }
1.118 ng 1573: var xpos = (screen.width-600)/2;
1574: xpos = (xpos < 0) ? '0' : xpos;
1575: var ypos = (screen.height-height)/2-30;
1576: ypos = (ypos < 0) ? '0' : ypos;
1577:
1.206 albertel 1578: pWin = window.open('', 'MessageCenter', 'resizable=yes,toolbar=no,location=no,scrollbars='+scrollbar+',screenx='+xpos+',screeny='+ypos+',width=600,height='+height);
1.76 ng 1579: pWin.focus();
1580: pDoc = pWin.document;
1.219 www 1581: pDoc.$docopen;
1.351 albertel 1582: pDoc.write('$start_page_msg_central');
1.76 ng 1583:
1584: pDoc.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
1585: pDoc.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
1.465 albertel 1586: pDoc.write("<h3><span class=\\"LC_info\\"> Compose Message for \"+fullname+\"<\\/span><\\/h3><br /><br />");
1.76 ng 1587:
1.564 bisitz 1588: pDoc.write('<table border="0" width="100%"><tr><td bgcolor="#777777">');
1589: pDoc.write('<table border="0" width="100%"><tr bgcolor="#DDFFFF">');
1.465 albertel 1590: pDoc.write("<td><b>Type<\\/b><\\/td><td><b>Include<\\/b><\\/td><td><b>Message<\\/td><\\/tr>");
1.44 ng 1591: }
1592: function displaySubject(msg,shwsel) {
1.76 ng 1593: pDoc = pWin.document;
1594: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.465 albertel 1595: pDoc.write("<td>Subject<\\/td>");
1596: pDoc.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1597: pDoc.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+"\\"size=\\"60\\" maxlength=\\"80\\"><\\/td><\\/tr>");
1.44 ng 1598: }
1599:
1.72 ng 1600: function displaySavedMsg(ctr,msg,shwsel) {
1.76 ng 1601: pDoc = pWin.document;
1602: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.465 albertel 1603: pDoc.write("<td align=\\"center\\">"+ctr+"<\\/td>");
1604: pDoc.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1605: pDoc.write("<td><textarea name=\\"msg"+ctr+"\\" cols=\\"60\\" rows=\\"3\\">"+msg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 1606: }
1607:
1608: function newMsg(newmsg,shwsel) {
1.76 ng 1609: pDoc = pWin.document;
1610: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.465 albertel 1611: pDoc.write("<td align=\\"center\\">New<\\/td>");
1612: pDoc.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1613: pDoc.write("<td><textarea name=\\"newmsg\\" cols=\\"60\\" rows=\\"3\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" >"+newmsg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 1614: }
1615:
1616: function msgTail() {
1.76 ng 1617: pDoc = pWin.document;
1.465 albertel 1618: pDoc.write("<\\/table>");
1619: pDoc.write("<\\/td><\\/tr><\\/table> ");
1.589 bisitz 1620: pDoc.write("<input type=\\"button\\" value=\\"Save\\" onclick=\\"javascript:checkInput()\\"> ");
1621: pDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onclick=\\"self.close()\\"><br /><br />");
1.465 albertel 1622: pDoc.write("<\\/form>");
1.351 albertel 1623: pDoc.write('$end_page_msg_central');
1.128 ng 1624: pDoc.close();
1.44 ng 1625: }
1626:
1627: //====================== Script for keyword highlight options ==============
1628: function kwhighlight() {
1629: var kwclr = document.SCORE.kwclr.value;
1630: var kwsize = document.SCORE.kwsize.value;
1631: var kwstyle = document.SCORE.kwstyle.value;
1632: var redsel = "";
1633: var grnsel = "";
1634: var blusel = "";
1635: if (kwclr=="red") {var redsel="checked"};
1636: if (kwclr=="green") {var grnsel="checked"};
1637: if (kwclr=="blue") {var blusel="checked"};
1638: var sznsel = "";
1639: var sz1sel = "";
1640: var sz2sel = "";
1641: if (kwsize=="0") {var sznsel="checked"};
1642: if (kwsize=="+1") {var sz1sel="checked"};
1643: if (kwsize=="+2") {var sz2sel="checked"};
1644: var synsel = "";
1645: var syisel = "";
1646: var sybsel = "";
1647: if (kwstyle=="") {var synsel="checked"};
1648: if (kwstyle=="<i>") {var syisel="checked"};
1649: if (kwstyle=="<b>") {var sybsel="checked"};
1650: highlightCentral();
1651: highlightbody('red','red',redsel,'0','normal',sznsel,'','normal',synsel);
1652: highlightbody('green','green',grnsel,'+1','+1',sz1sel,'<i>','italic',syisel);
1653: highlightbody('blue','blue',blusel,'+2','+2',sz2sel,'<b>','bold',sybsel);
1654: highlightend();
1655: return;
1656: }
1657:
1658: function highlightCentral() {
1.76 ng 1659: // if (window.hwdWin) window.hwdWin.close();
1.118 ng 1660: var xpos = (screen.width-400)/2;
1661: xpos = (xpos < 0) ? '0' : xpos;
1662: var ypos = (screen.height-330)/2-30;
1663: ypos = (ypos < 0) ? '0' : ypos;
1664:
1.206 albertel 1665: hwdWin = window.open('', 'KeywordHighlightCentral', 'resizeable=yes,toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx='+xpos+',screeny='+ypos);
1.76 ng 1666: hwdWin.focus();
1667: var hDoc = hwdWin.document;
1.219 www 1668: hDoc.$docopen;
1.351 albertel 1669: hDoc.write('$start_page_highlight_central');
1.76 ng 1670: hDoc.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
1.465 albertel 1671: hDoc.write("<h3><span class=\\"LC_info\\"> Keyword Highlight Options<\\/span><\\/h3><br /><br />");
1.76 ng 1672:
1.564 bisitz 1673: hDoc.write('<table border="0" width="100%"><tr><td bgcolor="#777777">');
1674: hDoc.write('<table border="0" width="100%"><tr bgcolor="#DDFFFF">');
1.465 albertel 1675: hDoc.write("<td><b>Text Color<\\/b><\\/td><td><b>Font Size<\\/b><\\/td><td><b>Font Style<\\/td><\\/tr>");
1.44 ng 1676: }
1677:
1678: function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) {
1.76 ng 1679: var hDoc = hwdWin.document;
1680: hDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1681: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1682: hDoc.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+"> "+clrtxt+"<\\/td>");
1.76 ng 1683: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1684: hDoc.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+"> "+sztxt+"<\\/td>");
1.76 ng 1685: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1686: hDoc.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+"> "+sytxt+"<\\/td>");
1687: hDoc.write("<\\/tr>");
1.44 ng 1688: }
1689:
1690: function highlightend() {
1.76 ng 1691: var hDoc = hwdWin.document;
1.465 albertel 1692: hDoc.write("<\\/table>");
1693: hDoc.write("<\\/td><\\/tr><\\/table> ");
1.589 bisitz 1694: hDoc.write("<input type=\\"button\\" value=\\"Save\\" onclick=\\"javascript:updateChoice(1)\\"> ");
1695: hDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onclick=\\"self.close()\\"><br /><br />");
1.465 albertel 1696: hDoc.write("<\\/form>");
1.351 albertel 1697: hDoc.write('$end_page_highlight_central');
1.128 ng 1698: hDoc.close();
1.44 ng 1699: }
1700:
1701: </script>
1702: SUBJAVASCRIPT
1703: }
1704:
1.349 albertel 1705: sub get_increment {
1.348 bowersj2 1706: my $increment = $env{'form.increment'};
1707: if ($increment != 1 && $increment != .5 && $increment != .25 &&
1708: $increment != .1) {
1709: $increment = 1;
1710: }
1711: return $increment;
1712: }
1713:
1.585 bisitz 1714: sub gradeBox_start {
1715: return (
1716: &Apache::loncommon::start_data_table()
1717: .&Apache::loncommon::start_data_table_header_row()
1718: .'<th>'.&mt('Part').'</th>'
1719: .'<th>'.&mt('Points').'</th>'
1720: .'<th> </th>'
1721: .'<th>'.&mt('Assign Grade').'</th>'
1722: .'<th>'.&mt('Weight').'</th>'
1723: .'<th>'.&mt('Grade Status').'</th>'
1724: .&Apache::loncommon::end_data_table_header_row()
1725: );
1726: }
1727:
1728: sub gradeBox_end {
1729: return (
1730: &Apache::loncommon::end_data_table()
1731: );
1732: }
1.71 ng 1733: #--- displays the grading box, used in essay type problem and grading by page/sequence
1734: sub gradeBox {
1.322 albertel 1735: my ($request,$symb,$uname,$udom,$counter,$partid,$record) = @_;
1.381 albertel 1736: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 1737: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 1738: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
1.466 albertel 1739: my $wgtmsg = ($wgt > 0) ? &mt('(problem weight)')
1740: : '<span class="LC_info">'.&mt('problem weight assigned by computer').'</span>';
1.71 ng 1741: $wgt = ($wgt > 0 ? $wgt : '1');
1742: my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
1.320 albertel 1743: '' : &compute_points($$record{'resource.'.$partid.'.awarded'},$wgt));
1.71 ng 1744: my $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />'."\n";
1.466 albertel 1745: my $display_part= &get_display_part($partid,$symb);
1.270 albertel 1746: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
1747: [$partid]);
1748: my $aggtries = $$record{'resource.'.$partid.'.tries'};
1.269 raeburn 1749: if ($last_resets{$partid}) {
1750: $aggtries = &get_num_tries($record,$last_resets{$partid},$partid);
1751: }
1.585 bisitz 1752: $result.=&Apache::loncommon::start_data_table_row();
1.71 ng 1753: my $ctr = 0;
1.348 bowersj2 1754: my $thisweight = 0;
1.349 albertel 1755: my $increment = &get_increment();
1.485 albertel 1756:
1757: my $radio.='<table border="0"><tr>'."\n"; # display radio buttons in a nice table 10 across
1.348 bowersj2 1758: while ($thisweight<=$wgt) {
1.532 bisitz 1759: $radio.= '<td><span class="LC_nobreak"><label><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
1.589 bisitz 1760: 'onclick="javascript:writeBox(this.form,\''.$counter.'_'.$partid.'\','.
1.348 bowersj2 1761: $thisweight.')" value="'.$thisweight.'" '.
1.401 albertel 1762: ($score eq $thisweight ? 'checked="checked"':'').' /> '.$thisweight."</label></span></td>\n";
1.485 albertel 1763: $radio.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1.348 bowersj2 1764: $thisweight += $increment;
1.71 ng 1765: $ctr++;
1766: }
1.485 albertel 1767: $radio.='</tr></table>';
1768:
1769: my $line.='<input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
1.71 ng 1770: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
1.589 bisitz 1771: 'onchange="javascript:updateRadio(this.form,\''.$counter.'_'.$partid.'\','.
1.71 ng 1772: $wgt.')" /></td>'."\n";
1.485 albertel 1773: $line.='<td>/'.$wgt.' '.$wgtmsg.
1.71 ng 1774: ($$record{'resource.'.$partid.'.solved'} eq 'correct_by_student' ? ' '.$checkIcon : '').
1.585 bisitz 1775: ' </td>'."\n";
1776: $line.='<td><select name="GD_SEL'.$counter.'_'.$partid.'" '.
1.589 bisitz 1777: 'onchange="javascript:clearRadBox(this.form,\''.$counter.'_'.$partid.'\')" >'."\n";
1.71 ng 1778: if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
1.485 albertel 1779: $line.='<option></option>'.
1780: '<option value="excused" selected="selected">'.&mt('excused').'</option>';
1.71 ng 1781: } else {
1.485 albertel 1782: $line.='<option selected="selected"></option>'.
1783: '<option value="excused" >'.&mt('excused').'</option>';
1.71 ng 1784: }
1.485 albertel 1785: $line.='<option value="reset status">'.&mt('reset status').'</option></select>'."\n";
1786:
1787:
1.540 riegler 1788: #&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 1789: $result .=
1.585 bisitz 1790: '<td>'.$display_part.'</td><td>'.$radio.'</td><td>'.&mt('or').'</td><td>'.$line.'</td>';
1791: $result.=&Apache::loncommon::end_data_table_row();
1.71 ng 1792: $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="" />'."\n".
1793: '<input type="hidden" name="oldpts'.$counter.'_'.$partid.'" value="'.$score.'" />'."\n".
1794: '<input type="hidden" name="solved'.$counter.'_'.$partid.'" value="'.
1.269 raeburn 1795: $$record{'resource.'.$partid.'.solved'}.'" />'."\n".
1796: '<input type="hidden" name="totaltries'.$counter.'_'.$partid.'" value="'.
1797: $$record{'resource.'.$partid.'.tries'}.'" />'."\n".
1798: '<input type="hidden" name="aggtries'.$counter.'_'.$partid.'" value="'.
1799: $aggtries.'" />'."\n";
1.582 raeburn 1800: my $res_error;
1801: $result.=&handback_box($symb,$uname,$udom,$counter,$partid,$record,\$res_error);
1802: if ($res_error) {
1803: return &navmap_errormsg();
1804: }
1.318 banghart 1805: return $result;
1806: }
1.322 albertel 1807:
1808: sub handback_box {
1.582 raeburn 1809: my ($symb,$uname,$udom,$counter,$partid,$record,$res_error) = @_;
1810: my ($partlist,$handgrade,$responseType) = &response_type($symb,$res_error);
1.323 banghart 1811: my (@respids);
1.375 albertel 1812: my @part_response_id = &flatten_responseType($responseType);
1813: foreach my $part_response_id (@part_response_id) {
1814: my ($part,$resp) = @{ $part_response_id };
1.323 banghart 1815: if ($part eq $partid) {
1.375 albertel 1816: push(@respids,$resp);
1.323 banghart 1817: }
1818: }
1.318 banghart 1819: my $result;
1.323 banghart 1820: foreach my $respid (@respids) {
1.322 albertel 1821: my $prefix = $counter.'_'.$partid.'_'.$respid.'_';
1822: my $files=&get_submitted_files($udom,$uname,$partid,$respid,$record);
1823: next if (!@$files);
1824: my $file_counter = 1;
1.313 banghart 1825: foreach my $file (@$files) {
1.368 banghart 1826: if ($file =~ /\/portfolio\//) {
1827: my ($file_path, $file_disp) = ($file =~ m|(.+/)(.+)$|);
1828: my ($name,$version,$ext) = &file_name_version_ext($file_disp);
1829: $file_disp = "$name.$ext";
1830: $file = $file_path.$file_disp;
1831: $result.=&mt('Return commented version of [_1] to student.',
1832: '<span class="LC_filename">'.$file_disp.'</span>');
1833: $result.='<input type="file" name="'.$prefix.'returndoc'.$file_counter.'" />'."\n";
1834: $result.='<input type="hidden" name="'.$prefix.'origdoc'.$file_counter.'" value="'.$file.'" /><br />';
1.485 albertel 1835: $result.='('.&mt('File will be uploaded when you click on Save & Next below.').')<br />';
1.368 banghart 1836: $file_counter++;
1837: }
1.322 albertel 1838: }
1.313 banghart 1839: }
1.318 banghart 1840: return $result;
1.71 ng 1841: }
1.44 ng 1842:
1.58 albertel 1843: sub show_problem {
1.382 albertel 1844: my ($request,$symb,$uname,$udom,$removeform,$viewon,$mode,$form) = @_;
1.144 albertel 1845: my $rendered;
1.382 albertel 1846: my %form = ((ref($form) eq 'HASH')? %{$form} : ());
1.329 albertel 1847: &Apache::lonxml::remember_problem_counter();
1.144 albertel 1848: if ($mode eq 'both' or $mode eq 'text') {
1849: $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
1.382 albertel 1850: $env{'request.course.id'},
1851: undef,\%form);
1.144 albertel 1852: }
1.58 albertel 1853: if ($removeform) {
1854: $rendered=~s|<form(.*?)>||g;
1855: $rendered=~s|</form>||g;
1.374 albertel 1856: $rendered=~s|(<input[^>]*name\s*=\s*"?)(\w+)("?)|$1would_have_been_$2$3|g;
1.58 albertel 1857: }
1.144 albertel 1858: my $companswer;
1859: if ($mode eq 'both' or $mode eq 'answer') {
1.329 albertel 1860: &Apache::lonxml::restore_problem_counter();
1.382 albertel 1861: $companswer=
1862: &Apache::loncommon::get_student_answers($symb,$uname,$udom,
1863: $env{'request.course.id'},
1864: %form);
1.144 albertel 1865: }
1.58 albertel 1866: if ($removeform) {
1867: $companswer=~s|<form(.*?)>||g;
1868: $companswer=~s|</form>||g;
1.144 albertel 1869: $companswer=~s|name="submit"|name="would_have_been_submit"|g;
1.58 albertel 1870: }
1.468 albertel 1871: $rendered=
1.588 bisitz 1872: '<div class="LC_Box">'
1873: .'<h3 class="LC_hcell">'.&mt('View of the problem').'</h3>'
1874: .$rendered
1875: .'</div>';
1.468 albertel 1876: $companswer=
1.588 bisitz 1877: '<div class="LC_Box">'
1878: .'<h3 class="LC_hcell">'.&mt('Correct answer').'</h3>'
1879: .$companswer
1880: .'</div>';
1.468 albertel 1881: my $result;
1.144 albertel 1882: if ($mode eq 'both') {
1.588 bisitz 1883: $result=$rendered.$companswer;
1.144 albertel 1884: } elsif ($mode eq 'text') {
1.588 bisitz 1885: $result=$rendered;
1.144 albertel 1886: } elsif ($mode eq 'answer') {
1.588 bisitz 1887: $result=$companswer;
1.144 albertel 1888: }
1.71 ng 1889: return $result;
1.58 albertel 1890: }
1.397 albertel 1891:
1.396 banghart 1892: sub files_exist {
1893: my ($r, $symb) = @_;
1894: my @students = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.397 albertel 1895:
1.396 banghart 1896: foreach my $student (@students) {
1897: my ($uname,$udom,$fullname) = split(/:/,$student);
1.397 albertel 1898: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1899: $udom,$uname);
1.396 banghart 1900: my ($string,$timestamp)= &get_last_submission(\%record);
1.397 albertel 1901: foreach my $submission (@$string) {
1902: my ($partid,$respid) =
1903: ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
1904: my $files=&get_submitted_files($udom,$uname,$partid,$respid,
1905: \%record);
1906: return 1 if (@$files);
1.396 banghart 1907: }
1908: }
1.397 albertel 1909: return 0;
1.396 banghart 1910: }
1.397 albertel 1911:
1.394 banghart 1912: sub download_all_link {
1913: my ($r,$symb) = @_;
1.395 albertel 1914: my $all_students =
1915: join("\n", &Apache::loncommon::get_env_multiple('form.stuinfo'));
1916:
1917: my $parts =
1918: join("\n",&Apache::loncommon::get_env_multiple('form.vPart'));
1919:
1.394 banghart 1920: my $identifier = &Apache::loncommon::get_cgi_id();
1.514 raeburn 1921: &Apache::lonnet::appenv({'cgi.'.$identifier.'.students' => $all_students,
1922: 'cgi.'.$identifier.'.symb' => $symb,
1923: 'cgi.'.$identifier.'.parts' => $parts,});
1.395 albertel 1924: $r->print('<a href="/cgi-bin/multidownload.pl?'.$identifier.'">'.
1925: &mt('Download All Submitted Documents').'</a>');
1.394 banghart 1926: return
1927: }
1.395 albertel 1928:
1.432 banghart 1929: sub build_section_inputs {
1930: my $section_inputs;
1931: if ($env{'form.section'} eq '') {
1932: $section_inputs .= '<input type="hidden" name="section" value="all" />'."\n";
1933: } else {
1934: my @sections = &Apache::loncommon::get_env_multiple('form.section');
1.434 albertel 1935: foreach my $section (@sections) {
1.432 banghart 1936: $section_inputs .= '<input type="hidden" name="section" value="'.$section.'" />'."\n";
1937: }
1938: }
1939: return $section_inputs;
1940: }
1941:
1.44 ng 1942: # --------------------------- show submissions of a student, option to grade
1943: sub submission {
1944: my ($request,$counter,$total) = @_;
1.257 albertel 1945: my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
1946: $udom = ($udom eq '' ? $env{'user.domain'} : $udom); #has form.userdom changed for a student?
1947: my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
1948: $env{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $env{'form.fullname'} eq '';
1.324 albertel 1949: my $symb = &get_symb($request);
1950: if ($symb eq '') { $request->print("Unable to handle ambiguous references:."); return ''; }
1.104 albertel 1951:
1952: if (!&canview($usec)) {
1.398 albertel 1953: $request->print('<span class="LC_warning">Unable to view requested student.('.
1954: $uname.':'.$udom.' in section '.$usec.' in course id '.
1955: $env{'request.course.id'}.')</span>');
1.324 albertel 1956: $request->print(&show_grading_menu_form($symb));
1.104 albertel 1957: return;
1958: }
1959:
1.257 albertel 1960: if (!$env{'form.lastSub'}) { $env{'form.lastSub'} = 'datesub'; }
1961: if (!$env{'form.vProb'}) { $env{'form.vProb'} = 'yes'; }
1962: if (!$env{'form.vAns'}) { $env{'form.vAns'} = 'yes'; }
1963: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.381 albertel 1964: my $checkIcon = '<img alt="'.&mt('Check Mark').
1965: '" src="'.$request->dir_config('lonIconsURL').
1.122 ng 1966: '/check.gif" height="16" border="0" />';
1.41 ng 1967:
1.426 albertel 1968: my %old_essays;
1.41 ng 1969: # header info
1970: if ($counter == 0) {
1971: &sub_page_js($request);
1.257 albertel 1972: &sub_page_kw_js($request) if ($env{'form.handgrade'} eq 'yes');
1973: $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
1974: &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
1.397 albertel 1975: if ($env{'form.handgrade'} eq 'yes' && &files_exist($request, $symb)) {
1.396 banghart 1976: &download_all_link($request, $symb);
1977: }
1.485 albertel 1978: $request->print('<h3> <span class="LC_info">'.&mt('Submission Record').'</span></h3>'."\n".
1979: '<h4> '.&mt('<b>Resource: </b> [_1]',$env{'form.probTitle'}).'</h4>'."\n");
1.118 ng 1980:
1.44 ng 1981: # option to display problem, only once else it cause problems
1982: # with the form later since the problem has a form.
1.257 albertel 1983: if ($env{'form.vProb'} eq 'yes' or $env{'form.vAns'} eq 'yes') {
1.144 albertel 1984: my $mode;
1.257 albertel 1985: if ($env{'form.vProb'} eq 'yes' && $env{'form.vAns'} eq 'yes') {
1.144 albertel 1986: $mode='both';
1.257 albertel 1987: } elsif ($env{'form.vProb'} eq 'yes') {
1.144 albertel 1988: $mode='text';
1.257 albertel 1989: } elsif ($env{'form.vAns'} eq 'yes') {
1.144 albertel 1990: $mode='answer';
1991: }
1.329 albertel 1992: &Apache::lonxml::clear_problem_counter();
1.144 albertel 1993: $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
1.41 ng 1994: }
1.441 www 1995:
1.44 ng 1996: # kwclr is the only variable that is guaranteed to be non blank
1997: # if this subroutine has been called once.
1.41 ng 1998: my %keyhash = ();
1.257 albertel 1999: if ($env{'form.kwclr'} eq '' && $env{'form.handgrade'} eq 'yes') {
1.41 ng 2000: %keyhash = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 2001: $env{'course.'.$env{'request.course.id'}.'.domain'},
2002: $env{'course.'.$env{'request.course.id'}.'.num'});
1.41 ng 2003:
1.257 albertel 2004: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
2005: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
2006: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
2007: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
2008: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
2009: $env{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
2010: $keyhash{$symb.'_subject'} : $env{'form.probTitle'};
2011: $env{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1.41 ng 2012: }
1.257 albertel 2013: my $overRideScore = $env{'form.overRideScore'} eq '' ? 'no' : $env{'form.overRideScore'};
1.442 banghart 2014: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.303 banghart 2015: $request->print('<form action="/adm/grades" method="post" name="SCORE" enctype="multipart/form-data">'."\n".
1.41 ng 2016: '<input type="hidden" name="command" value="handgrade" />'."\n".
1.257 albertel 2017: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.442 banghart 2018: '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.120 ng 2019: '<input type="hidden" name="overRideScore" value="'.$overRideScore.'" />'."\n".
1.257 albertel 2020: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.41 ng 2021: '<input type="hidden" name="refresh" value="off" />'."\n".
1.120 ng 2022: '<input type="hidden" name="studentNo" value="" />'."\n".
2023: '<input type="hidden" name="gradeOpt" value="" />'."\n".
1.418 albertel 2024: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 2025: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" />'."\n".
2026: '<input type="hidden" name="vProb" value="'.$env{'form.vProb'}.'" />'."\n".
2027: '<input type="hidden" name="vAns" value="'.$env{'form.vAns'}.'" />'."\n".
2028: '<input type="hidden" name="lastSub" value="'.$env{'form.lastSub'}.'" />'."\n".
1.432 banghart 2029: &build_section_inputs().
1.326 albertel 2030: '<input type="hidden" name="submitonly" value="'.$env{'form.submitonly'}.'" />'."\n".
2031: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" />'."\n".
1.41 ng 2032: '<input type="hidden" name="NCT"'.
1.257 albertel 2033: ' value="'.($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : $total+1).'" />'."\n");
2034: if ($env{'form.handgrade'} eq 'yes') {
2035: $request->print('<input type="hidden" name="keywords" value="'.$env{'form.keywords'}.'" />'."\n".
2036: '<input type="hidden" name="kwclr" value="'.$env{'form.kwclr'}.'" />'."\n".
2037: '<input type="hidden" name="kwsize" value="'.$env{'form.kwsize'}.'" />'."\n".
2038: '<input type="hidden" name="kwstyle" value="'.$env{'form.kwstyle'}.'" />'."\n".
2039: '<input type="hidden" name="msgsub" value="'.$env{'form.msgsub'}.'" />'."\n".
1.123 ng 2040: '<input type="hidden" name="shownSub" value="0" />'."\n".
1.257 albertel 2041: '<input type="hidden" name="savemsgN" value="'.$env{'form.savemsgN'}.'" />'."\n");
1.154 albertel 2042: foreach my $partid (&Apache::loncommon::get_env_multiple('form.vPart')) {
2043: $request->print('<input type="hidden" name="vPart" value="'.$partid.'" />'."\n");
2044: }
1.123 ng 2045: }
1.41 ng 2046:
2047: my ($cts,$prnmsg) = (1,'');
1.257 albertel 2048: while ($cts <= $env{'form.savemsgN'}) {
1.41 ng 2049: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
1.123 ng 2050: (!exists($keyhash{$symb.'_savemsg'.$cts}) ?
1.257 albertel 2051: &Apache::lonfeedback::clear_out_html($env{'form.savemsg'.$cts}) :
1.80 ng 2052: &Apache::lonfeedback::clear_out_html($keyhash{$symb.'_savemsg'.$cts})).
1.123 ng 2053: '" />'."\n".
2054: '<input type="hidden" name="shownOnce'.$cts.'" value="0" />'."\n";
1.41 ng 2055: $cts++;
2056: }
2057: $request->print($prnmsg);
1.32 ng 2058:
1.257 albertel 2059: if ($env{'form.handgrade'} eq 'yes' && $env{'form.showgrading'} eq 'yes') {
1.88 www 2060: #
2061: # Print out the keyword options line
2062: #
1.41 ng 2063: $request->print(<<KEYWORDS);
1.38 ng 2064: <b>Keyword Options:</b>
1.417 albertel 2065: <a href="javascript:keywords(document.SCORE);" target="_self">List</a>
1.589 bisitz 2066: <a href="#" onmousedown="javascript:getSel(); return false"
1.38 ng 2067: CLASS="page">Paste Selection to List</a>
1.417 albertel 2068: <a href="javascript:kwhighlight();" target="_self">Highlight Attribute</a><br /><br />
1.38 ng 2069: KEYWORDS
1.88 www 2070: #
2071: # Load the other essays for similarity check
2072: #
1.324 albertel 2073: my (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb);
1.384 albertel 2074: my ($adom,$aname,$apath)=($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
1.359 www 2075: $apath=&escape($apath);
1.88 www 2076: $apath=~s/\W/\_/gs;
1.426 albertel 2077: %old_essays=&Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
1.41 ng 2078: }
2079: }
1.44 ng 2080:
1.441 www 2081: # This is where output for one specific student would start
1.468 albertel 2082: my $add_class = ($counter%2) ? 'LC_grade_show_user_odd_row' : '';
1.441 www 2083: $request->print("\n\n".
1.468 albertel 2084: '<div class="LC_grade_show_user '.$add_class.'">'.
2085: '<div class="LC_grade_user_name">'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).'</div>'.
2086: '<div class="LC_grade_show_user_body">'."\n");
1.441 www 2087:
1.257 albertel 2088: if ($env{'form.vProb'} eq 'all' or $env{'form.vAns'} eq 'all') {
1.144 albertel 2089: my $mode;
1.257 albertel 2090: if ($env{'form.vProb'} eq 'all' && $env{'form.vAns'} eq 'all') {
1.144 albertel 2091: $mode='both';
1.257 albertel 2092: } elsif ($env{'form.vProb'} eq 'all' ) {
1.144 albertel 2093: $mode='text';
1.257 albertel 2094: } elsif ($env{'form.vAns'} eq 'all') {
1.144 albertel 2095: $mode='answer';
2096: }
1.329 albertel 2097: &Apache::lonxml::clear_problem_counter();
1.475 albertel 2098: $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode,{'request.prefix' => 'ctr'.$counter}));
1.58 albertel 2099: }
1.144 albertel 2100:
1.257 albertel 2101: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.582 raeburn 2102: my $res_error;
2103: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
2104: if ($res_error) {
2105: $request->print(&navmap_errormsg());
2106: return;
2107: }
1.41 ng 2108:
1.44 ng 2109: # Display student info
1.41 ng 2110: $request->print(($counter == 0 ? '' : '<br />'));
1.590 ! bisitz 2111:
! 2112: my $result='<div class="LC_Box">'
! 2113: .'<h3 class="LC_hcell">'.&mt('Submissions').'</h3>';
1.45 ng 2114: $result.='<input type="hidden" name="name'.$counter.
1.588 bisitz 2115: '" value="'.$env{'form.fullname'}.'" />'."\n";
1.469 albertel 2116: if ($env{'form.handgrade'} eq 'no') {
1.588 bisitz 2117: $result.='<p class="LC_info">'
2118: .&mt('Part(s) graded correct by the computer is marked with a [_1] symbol.',$checkIcon)
2119: ."</p>\n";
1.469 albertel 2120: }
2121:
1.118 ng 2122: # If any part of the problem is an essay-response (handgraded), then check for collaborators
1.464 albertel 2123: my $fullname;
2124: my $col_fullnames = [];
1.257 albertel 2125: if ($env{'form.handgrade'} eq 'yes') {
1.464 albertel 2126: (my $sub_result,$fullname,$col_fullnames)=
2127: &check_collaborators($symb,$uname,$udom,\%record,$handgrade,
2128: $counter);
2129: $result.=$sub_result;
1.41 ng 2130: }
1.44 ng 2131: $request->print($result."\n");
1.588 bisitz 2132:
1.44 ng 2133: # print student answer/submission
1.588 bisitz 2134: # Options are (1) Handgraded submission only
1.44 ng 2135: # (2) Last submission, includes submission that is not handgraded
2136: # (for multi-response type part)
2137: # (3) Last submission plus the parts info
2138: # (4) The whole record for this student
1.257 albertel 2139: if ($env{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
1.151 albertel 2140: my ($string,$timestamp)= &get_last_submission(\%record);
1.468 albertel 2141:
2142: my $lastsubonly;
2143:
1.588 bisitz 2144: if ($$timestamp eq '') {
2145: $lastsubonly.='<div class="LC_grade_submissions_body">'.$$string[0].'</div>';
2146: } else {
2147: $lastsubonly = '<div class="LC_grade_submissions_body"> <b>Date Submitted:</b> '.$$timestamp."\n";
1.468 albertel 2148:
1.151 albertel 2149: my %seenparts;
1.375 albertel 2150: my @part_response_id = &flatten_responseType($responseType);
2151: foreach my $part (@part_response_id) {
1.393 albertel 2152: next if ($env{'form.lastSub'} eq 'hdgrade'
2153: && $$handgrade{$$part[0].'_'.$$part[1]} ne 'yes');
2154:
1.375 albertel 2155: my ($partid,$respid) = @{ $part };
1.324 albertel 2156: my $display_part=&get_display_part($partid,$symb);
1.257 albertel 2157: if ($env{"form.$uname:$udom:$partid:submitted_by"}) {
1.151 albertel 2158: if (exists($seenparts{$partid})) { next; }
2159: $seenparts{$partid}=1;
1.207 albertel 2160: my $submitby='<b>Part:</b> '.$display_part.
2161: ' <b>Collaborative submission by:</b> '.
1.151 albertel 2162: '<a href="javascript:viewSubmitter(\''.
1.257 albertel 2163: $env{"form.$uname:$udom:$partid:submitted_by"}.
1.417 albertel 2164: '\');" target="_self">'.
1.257 albertel 2165: $$fullname{$env{"form.$uname:$udom:$partid:submitted_by"}}.'</a><br />';
1.151 albertel 2166: $request->print($submitby);
2167: next;
2168: }
2169: my $responsetype = $responseType->{$partid}->{$respid};
2170: if (!exists($record{"resource.$partid.$respid.submission"})) {
1.577 bisitz 2171: $lastsubonly.="\n".'<div class="LC_grade_submission_part">'.
2172: '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
2173: ' <span class="LC_internal_info">'.
2174: '('.&mt('Part ID: [_1]',$respid).')</b>'.
2175: '</span> '.
1.539 riegler 2176: '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br /><br /></div>';
1.151 albertel 2177: next;
2178: }
1.468 albertel 2179: foreach my $submission (@$string) {
2180: my ($partid,$respid) = ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
1.375 albertel 2181: if (join('_',@{$part}) ne ($partid.'_'.$respid)) { next; }
1.468 albertel 2182: my ($ressub,$subval) = split(/:/,$submission,2);
1.151 albertel 2183: # Similarity check
2184: my $similar='';
1.257 albertel 2185: if($env{'form.checkPlag'}){
1.151 albertel 2186: my ($oname,$odom,$ocrsid,$oessay,$osim)=
1.426 albertel 2187: &most_similar($uname,$udom,$subval,\%old_essays);
1.151 albertel 2188: if ($osim) {
2189: $osim=int($osim*100.0);
1.426 albertel 2190: my %old_course_desc =
2191: &Apache::lonnet::coursedescription($ocrsid,
2192: {'one_time' => 1});
2193:
2194: $similar="<hr /><h3><span class=\"LC_warning\">".
1.574 bisitz 2195: &mt('Essay is [_1]% similar to an essay by [_2] in course [_3] (course id [_4]:[_5])',
1.426 albertel 2196: $osim,
1.574 bisitz 2197: &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')',
1.426 albertel 2198: $old_course_desc{'description'},
1.427 albertel 2199: $old_course_desc{'num'},
1.426 albertel 2200: $old_course_desc{'domain'}).
1.398 albertel 2201: '</span></h3><blockquote><i>'.
1.151 albertel 2202: &keywords_highlight($oessay).
2203: '</i></blockquote><hr />';
2204: }
1.150 albertel 2205: }
1.151 albertel 2206: my $order=&get_order($partid,$respid,$symb,$uname,$udom);
1.257 albertel 2207: if ($env{'form.lastSub'} eq 'lastonly' ||
2208: ($env{'form.lastSub'} eq 'hdgrade' &&
1.377 albertel 2209: $$handgrade{$$part[0].'_'.$$part[1]} eq 'yes')) {
1.324 albertel 2210: my $display_part=&get_display_part($partid,$symb);
1.577 bisitz 2211: $lastsubonly.='<div class="LC_grade_submission_part">'.
2212: '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
2213: ' <span class="LC_internal_info">'.
2214: '('.&mt('Part ID: [_1]',$respid).')'.
2215: '</b></span> ';
1.313 banghart 2216: my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record);
2217: if (@$files) {
1.544 raeburn 2218: $lastsubonly.='<br /><span class="LC_warning">'.&mt('Like all files provided by users, this file may contain viruses').'</span><br />';
1.303 banghart 2219: my $file_counter = 0;
1.313 banghart 2220: foreach my $file (@$files) {
1.468 albertel 2221: $file_counter++;
1.232 albertel 2222: &Apache::lonnet::allowuploaded('/adm/grades',$file);
1.564 bisitz 2223: $lastsubonly.='<br /><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.&Apache::loncommon::icon($file).'" border="0" /> '.$file.'</a>';
1.232 albertel 2224: }
1.236 albertel 2225: $lastsubonly.='<br />';
1.41 ng 2226: }
1.468 albertel 2227: $lastsubonly.='<b>'.&mt('Submitted Answer:').' </b>'.
1.151 albertel 2228: &cleanRecord($subval,$responsetype,$symb,$partid,
1.555 raeburn 2229: $respid,\%record,$order,undef,$uname,$udom);
1.151 albertel 2230: if ($similar) {$lastsubonly.="<br /><br />$similar\n";}
1.468 albertel 2231: $lastsubonly.='</div>';
1.41 ng 2232: }
2233: }
2234: }
1.588 bisitz 2235: $lastsubonly.='</div>'."\n"; # End: LC_grade_submissions_body
1.151 albertel 2236: }
2237: $request->print($lastsubonly);
1.468 albertel 2238: } elsif ($env{'form.lastSub'} eq 'datesub') {
1.324 albertel 2239: my (undef,$responseType,undef,$parts) = &showResourceInfo($symb);
1.148 albertel 2240: $request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
1.257 albertel 2241: } elsif ($env{'form.lastSub'} =~ /^(last|all)$/) {
1.41 ng 2242: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
1.257 albertel 2243: $env{'request.course.id'},
1.44 ng 2244: $last,'.submission',
2245: 'Apache::grades::keywords_highlight'));
1.41 ng 2246: }
1.120 ng 2247:
1.121 ng 2248: $request->print('<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
2249: .$udom.'" />'."\n");
1.44 ng 2250: # return if view submission with no grading option
1.257 albertel 2251: if ($env{'form.showgrading'} eq '' || (!&canmodify($usec))) {
1.120 ng 2252: my $toGrade.='<input type="button" value="Grade Student" '.
1.589 bisitz 2253: 'onclick="javascript:checksubmit(this.form,\'Grade Student\',\''
1.417 albertel 2254: .$counter.'\');" target="_self" /> '."\n" if (&canmodify($usec));
1.468 albertel 2255: $toGrade.='</div>'."\n";
1.257 albertel 2256: if (($env{'form.command'} eq 'submission') ||
2257: ($env{'form.command'} eq 'processGroup' && $counter == $total)) {
1.324 albertel 2258: $toGrade.='</form>'.&show_grading_menu_form($symb);
1.169 albertel 2259: }
1.180 albertel 2260: $request->print($toGrade);
1.41 ng 2261: return;
1.180 albertel 2262: } else {
1.468 albertel 2263: $request->print('</div>'."\n");
1.41 ng 2264: }
1.33 ng 2265:
1.121 ng 2266: # essay grading message center
1.257 albertel 2267: if ($env{'form.handgrade'} eq 'yes') {
1.468 albertel 2268: my $result='<div class="LC_grade_message_center">';
2269:
2270: $result.='<div class="LC_grade_message_center_header">'.
2271: &mt('Send Message').'</div><div class="LC_grade_message_center_body">';
1.257 albertel 2272: my ($lastname,$givenn) = split(/,/,$env{'form.fullname'});
1.118 ng 2273: my $msgfor = $givenn.' '.$lastname;
1.464 albertel 2274: if (scalar(@$col_fullnames) > 0) {
2275: my $lastone = pop(@$col_fullnames);
2276: $msgfor .= ', '.(join ', ',@$col_fullnames).' and '.$lastone.'.';
1.118 ng 2277: }
2278: $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
1.468 albertel 2279: $result.='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
1.121 ng 2280: '<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n";
2281: $result.=' <a href="javascript:msgCenter(document.SCORE,'.$counter.
1.417 albertel 2282: ',\''.$msgfor.'\');" target="_self">'.
1.464 albertel 2283: &mt('Compose message to student').(scalar(@$col_fullnames) >= 1 ? 's' : '').'</a><label> ('.
1.350 albertel 2284: &mt('incl. grades').' <input type="checkbox" name="withgrades'.$counter.'" /></label>)'.
1.118 ng 2285: '<img src="'.$request->dir_config('lonIconsURL').
2286: '/mailbkgrd.gif" width="14" height="10" name="mailicon'.$counter.'" />'."\n".
1.298 www 2287: '<br /> ('.
1.468 albertel 2288: &mt('Message will be sent when you click on Save & Next below.').")\n";
2289: $result.='</div></div>';
1.121 ng 2290: $request->print($result);
1.118 ng 2291: }
1.41 ng 2292:
2293: my %seen = ();
2294: my @partlist;
1.129 ng 2295: my @gradePartRespid;
1.375 albertel 2296: my @part_response_id = &flatten_responseType($responseType);
1.585 bisitz 2297: $request->print(
1.588 bisitz 2298: '<div class="LC_Box">'
2299: .'<h3 class="LC_hcell">'.&mt('Assign Grades').'</h3>'
1.585 bisitz 2300: );
2301: $request->print(&gradeBox_start()); # <div class="LC_grade_assign_body">
1.375 albertel 2302: foreach my $part_response_id (@part_response_id) {
2303: my ($partid,$respid) = @{ $part_response_id };
2304: my $part_resp = join('_',@{ $part_response_id });
1.322 albertel 2305: next if ($seen{$partid} > 0);
1.41 ng 2306: $seen{$partid}++;
1.393 albertel 2307: next if ($$handgrade{$part_resp} ne 'yes'
2308: && $env{'form.lastSub'} eq 'hdgrade');
1.524 raeburn 2309: push(@partlist,$partid);
2310: push(@gradePartRespid,$partid.'.'.$respid);
1.322 albertel 2311: $request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
1.41 ng 2312: }
1.585 bisitz 2313: $request->print(&gradeBox_end()); # </div>
2314: $request->print('</div>');
1.468 albertel 2315:
2316: $request->print('<div class="LC_grade_info_links">');
2317: if ($perm{'vgr'}) {
2318: $request->print(
2319: &Apache::loncommon::track_student_link(&mt('View recent activity'),
2320: $uname,$udom,'check'));
2321: }
2322: if ($perm{'opa'}) {
2323: $request->print(
2324: &Apache::loncommon::pprmlink(&mt('Set/Change parameters'),
2325: $uname,$udom,$symb,'check'));
2326: }
2327: $request->print('</div>');
2328:
1.45 ng 2329: $result='<input type="hidden" name="partlist'.$counter.
2330: '" value="'.(join ":",@partlist).'" />'."\n";
1.129 ng 2331: $result.='<input type="hidden" name="gradePartRespid'.
2332: '" value="'.(join ":",@gradePartRespid).'" />'."\n" if ($counter == 0);
1.45 ng 2333: my $ctr = 0;
2334: while ($ctr < scalar(@partlist)) {
2335: $result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
2336: $partlist[$ctr].'" />'."\n";
2337: $ctr++;
2338: }
1.468 albertel 2339: $request->print($result.''."\n");
1.41 ng 2340:
1.441 www 2341: # Done with printing info for one student
2342:
1.468 albertel 2343: $request->print('</div>');#LC_grade_show_user_body
2344: $request->print('</div>');#LC_grade_show_user
1.441 www 2345:
2346:
1.41 ng 2347: # print end of form
2348: if ($counter == $total) {
1.297 www 2349: my $endform='<table border="0"><tr><td>'."\n";
1.485 albertel 2350: $endform.='<input type="button" value="'.&mt('Save & Next').'" '.
1.589 bisitz 2351: 'onclick="javascript:checksubmit(this.form,\'Save & Next\','.
1.417 albertel 2352: $total.','.scalar(@partlist).');" target="_self" /> '."\n";
1.119 ng 2353: my $ntstu ='<select name="NTSTU">'.
2354: '<option>1</option><option>2</option>'.
2355: '<option>3</option><option>5</option>'.
2356: '<option>7</option><option>10</option></select>'."\n";
1.257 albertel 2357: my $nsel = ($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : '1');
1.401 albertel 2358: $ntstu =~ s/<option>$nsel</<option selected="selected">$nsel</;
1.578 raeburn 2359: $endform.=&mt('[_1]student(s)',$ntstu);
1.485 albertel 2360: $endform.=' <input type="button" value="'.&mt('Previous').'" '.
1.589 bisitz 2361: 'onclick="javascript:checksubmit(this.form,\'Previous\');" target="_self" /> '."\n".
1.485 albertel 2362: '<input type="button" value="'.&mt('Next').'" '.
1.589 bisitz 2363: 'onclick="javascript:checksubmit(this.form,\'Next\');" target="_self" /> ';
1.485 albertel 2364: $endform.=&mt('(Next and Previous (student) do not save the scores.)')."\n" ;
1.349 albertel 2365: $endform.="<input type='hidden' value='".&get_increment().
1.348 bowersj2 2366: "' name='increment' />";
1.485 albertel 2367: $endform.='</td></tr></table></form>';
1.324 albertel 2368: $endform.=&show_grading_menu_form($symb);
1.41 ng 2369: $request->print($endform);
2370: }
2371: return '';
1.38 ng 2372: }
2373:
1.464 albertel 2374: sub check_collaborators {
2375: my ($symb,$uname,$udom,$record,$handgrade,$counter) = @_;
2376: my ($result,@col_fullnames);
2377: my ($classlist,undef,$fullname) = &getclasslist('all','0');
2378: foreach my $part (keys(%$handgrade)) {
2379: my $ncol = &Apache::lonnet::EXT('resource.'.$part.
2380: '.maxcollaborators',
2381: $symb,$udom,$uname);
2382: next if ($ncol <= 0);
2383: $part =~ s/\_/\./g;
2384: next if ($record->{'resource.'.$part.'.collaborators'} eq '');
2385: my (@good_collaborators, @bad_collaborators);
2386: foreach my $possible_collaborator
2387: (split(/,?\s+/,$record->{'resource.'.$part.'.collaborators'})) {
2388: $possible_collaborator =~ s/[\$\^\(\)]//g;
2389: next if ($possible_collaborator eq '');
2390: my ($co_name,$co_dom) = split(/\@|:/,$possible_collaborator);
2391: $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
2392: next if ($co_name eq $uname && $co_dom eq $udom);
2393: # Doing this grep allows 'fuzzy' specification
2394: my @matches = grep(/^\Q$co_name\E:\Q$co_dom\E$/i,
2395: keys(%$classlist));
2396: if (! scalar(@matches)) {
2397: push(@bad_collaborators, $possible_collaborator);
2398: } else {
2399: push(@good_collaborators, @matches);
2400: }
2401: }
2402: if (scalar(@good_collaborators) != 0) {
1.466 albertel 2403: $result.='<br />'.&mt('Collaborators: ');
1.464 albertel 2404: foreach my $name (@good_collaborators) {
2405: my ($lastname,$givenn) = split(/,/,$$fullname{$name});
2406: push(@col_fullnames, $givenn.' '.$lastname);
2407: $result.=$fullname->{$name}.' ';
2408: }
2409: $result.='<br />'."\n";
1.466 albertel 2410: my ($part)=split(/\./,$part);
1.464 albertel 2411: $result.='<input type="hidden" name="collaborator'.$counter.
2412: '" value="'.$part.':'.(join ':',@good_collaborators).'" />'.
2413: "\n";
2414: }
2415: if (scalar(@bad_collaborators) > 0) {
1.466 albertel 2416: $result.='<div class="LC_warning">';
1.464 albertel 2417: $result.=&mt('This student has submitted [quant,_1,invalid collaborator]: [_2]',scalar(@bad_collaborators),join(', ',@bad_collaborators));
2418: $result .= '</div>';
2419: }
2420: if (scalar(@bad_collaborators > $ncol)) {
1.466 albertel 2421: $result .= '<div class="LC_warning">';
1.464 albertel 2422: $result .= &mt('This student has submitted too many '.
2423: 'collaborators. Maximum is [_1].',$ncol);
2424: $result .= '</div>';
2425: }
2426: }
2427: return ($result,$fullname,\@col_fullnames);
2428: }
2429:
1.44 ng 2430: #--- Retrieve the last submission for all the parts
1.38 ng 2431: sub get_last_submission {
1.119 ng 2432: my ($returnhash)=@_;
1.46 ng 2433: my (@string,$timestamp);
1.119 ng 2434: if ($$returnhash{'version'}) {
1.46 ng 2435: my %lasthash=();
2436: my ($version);
1.119 ng 2437: for ($version=1;$version<=$$returnhash{'version'};$version++) {
1.397 albertel 2438: foreach my $key (sort(split(/\:/,
2439: $$returnhash{$version.':keys'}))) {
2440: $lasthash{$key}=$$returnhash{$version.':'.$key};
2441: $timestamp =
1.545 raeburn 2442: &Apache::lonlocal::locallocaltime($$returnhash{$version.':timestamp'});
1.46 ng 2443: }
2444: }
1.397 albertel 2445: foreach my $key (keys(%lasthash)) {
2446: next if ($key !~ /\.submission$/);
2447:
2448: my ($partid,$foo) = split(/submission$/,$key);
2449: my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
1.398 albertel 2450: '<span class="LC_warning">Draft Copy</span> ' : '';
1.397 albertel 2451: push(@string, join(':', $key, $draft.$lasthash{$key}));
1.41 ng 2452: }
2453: }
1.397 albertel 2454: if (!@string) {
2455: $string[0] =
1.539 riegler 2456: '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span>';
1.397 albertel 2457: }
2458: return (\@string,\$timestamp);
1.38 ng 2459: }
1.35 ng 2460:
1.44 ng 2461: #--- High light keywords, with style choosen by user.
1.38 ng 2462: sub keywords_highlight {
1.44 ng 2463: my $string = shift;
1.257 albertel 2464: my $size = $env{'form.kwsize'} eq '0' ? '' : 'size='.$env{'form.kwsize'};
2465: my $styleon = $env{'form.kwstyle'} eq '' ? '' : $env{'form.kwstyle'};
1.41 ng 2466: (my $styleoff = $styleon) =~ s/\</\<\//;
1.257 albertel 2467: my @keylist = split(/[,\s+]/,$env{'form.keywords'});
1.398 albertel 2468: foreach my $keyword (@keylist) {
2469: $string =~ s/\b\Q$keyword\E(\b|\.)/<font color\=$env{'form.kwclr'} $size\>$styleon$keyword$styleoff<\/font>/gi;
1.41 ng 2470: }
2471: return $string;
1.38 ng 2472: }
1.36 ng 2473:
1.44 ng 2474: #--- Called from submission routine
1.38 ng 2475: sub processHandGrade {
1.41 ng 2476: my ($request) = shift;
1.324 albertel 2477: my $symb = &get_symb($request);
2478: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.257 albertel 2479: my $button = $env{'form.gradeOpt'};
2480: my $ngrade = $env{'form.NCT'};
2481: my $ntstu = $env{'form.NTSTU'};
1.301 albertel 2482: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2483: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2484:
1.44 ng 2485: if ($button eq 'Save & Next') {
2486: my $ctr = 0;
2487: while ($ctr < $ngrade) {
1.257 albertel 2488: my ($uname,$udom) = split(/:/,$env{'form.unamedom'.$ctr});
1.324 albertel 2489: my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$symb,$uname,$udom,$ctr);
1.71 ng 2490: if ($errorflag eq 'no_score') {
2491: $ctr++;
2492: next;
2493: }
1.104 albertel 2494: if ($errorflag eq 'not_allowed') {
1.398 albertel 2495: $request->print("<span class=\"LC_warning\">Not allowed to modify grades for $uname:$udom</span>");
1.104 albertel 2496: $ctr++;
2497: next;
2498: }
1.257 albertel 2499: my $includemsg = $env{'form.includemsg'.$ctr};
1.44 ng 2500: my ($subject,$message,$msgstatus) = ('','','');
1.418 albertel 2501: my $restitle = &Apache::lonnet::gettitle($symb);
2502: my ($feedurl,$showsymb) =
2503: &get_feedurl_and_symb($symb,$uname,$udom);
2504: my $messagetail;
1.62 albertel 2505: if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.298 www 2506: $subject = $env{'form.msgsub'} if ($includemsg =~ /msgsub/);
1.295 www 2507: unless ($subject=~/\w/) { $subject=&mt('Grading Feedback'); }
1.386 raeburn 2508: $subject.=' ['.$restitle.']';
1.44 ng 2509: my (@msgnum) = split(/,/,$includemsg);
2510: foreach (@msgnum) {
1.257 albertel 2511: $message.=$env{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
1.44 ng 2512: }
1.80 ng 2513: $message =&Apache::lonfeedback::clear_out_html($message);
1.298 www 2514: if ($env{'form.withgrades'.$ctr}) {
2515: $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
1.386 raeburn 2516: $messagetail = " for <a href=\"".
1.418 albertel 2517: $feedurl."?symb=$showsymb\">$env{'form.probTitle'}</a>";
1.386 raeburn 2518: }
2519: $msgstatus =
2520: &Apache::lonmsg::user_normal_msg($uname,$udom,$subject,
2521: $message.$messagetail,
1.418 albertel 2522: undef,$feedurl,undef,
1.386 raeburn 2523: undef,undef,$showsymb,
2524: $restitle);
1.574 bisitz 2525: $request->print('<br />'.&mt('Sending message to [_1]',$uname.':'.$udom).': '.
1.296 www 2526: $msgstatus);
1.44 ng 2527: }
1.257 albertel 2528: if ($env{'form.collaborator'.$ctr}) {
1.155 albertel 2529: my @collabstrs=&Apache::loncommon::get_env_multiple("form.collaborator$ctr");
1.150 albertel 2530: foreach my $collabstr (@collabstrs) {
2531: my ($part,@collaborators) = split(/:/,$collabstr);
1.310 banghart 2532: foreach my $collaborator (@collaborators) {
1.150 albertel 2533: my ($errorflag,$pts,$wgt) =
1.324 albertel 2534: &saveHandGrade($request,$symb,$collaborator,$udom,$ctr,
1.257 albertel 2535: $env{'form.unamedom'.$ctr},$part);
1.150 albertel 2536: if ($errorflag eq 'not_allowed') {
1.362 albertel 2537: $request->print("<span class=\"LC_error\">".&mt('Not allowed to modify grades for [_1]',"$collaborator:$udom")."</span>");
1.150 albertel 2538: next;
1.418 albertel 2539: } elsif ($message ne '') {
2540: my ($baseurl,$showsymb) =
2541: &get_feedurl_and_symb($symb,$collaborator,
2542: $udom);
2543: if ($env{'form.withgrades'.$ctr}) {
2544: $messagetail = " for <a href=\"".
1.386 raeburn 2545: $baseurl."?symb=$showsymb\">$env{'form.probTitle'}</a>";
1.150 albertel 2546: }
1.418 albertel 2547: $msgstatus =
2548: &Apache::lonmsg::user_normal_msg($collaborator,$udom,$subject,$message.$messagetail,undef,$baseurl,undef,undef,undef,$showsymb,$restitle);
1.104 albertel 2549: }
1.44 ng 2550: }
2551: }
2552: }
2553: $ctr++;
2554: }
2555: }
2556:
1.257 albertel 2557: if ($env{'form.handgrade'} eq 'yes') {
1.119 ng 2558: # Keywords sorted in alphabatical order
1.257 albertel 2559: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1.119 ng 2560: my %keyhash = ();
1.257 albertel 2561: $env{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
2562: $env{'form.keywords'} =~ s/^\s+|\s+$//;
2563: my (@keywords) = sort(split(/\s+/,$env{'form.keywords'}));
2564: $env{'form.keywords'} = join(' ',@keywords);
2565: $keyhash{$symb.'_keywords'} = $env{'form.keywords'};
2566: $keyhash{$symb.'_subject'} = $env{'form.msgsub'};
2567: $keyhash{$loginuser.'_kwclr'} = $env{'form.kwclr'};
2568: $keyhash{$loginuser.'_kwsize'} = $env{'form.kwsize'};
2569: $keyhash{$loginuser.'_kwstyle'} = $env{'form.kwstyle'};
1.119 ng 2570:
2571: # message center - Order of message gets changed. Blank line is eliminated.
1.257 albertel 2572: # New messages are saved in env for the next student.
1.119 ng 2573: # All messages are saved in nohist_handgrade.db
2574: my ($ctr,$idx) = (1,1);
1.257 albertel 2575: while ($ctr <= $env{'form.savemsgN'}) {
2576: if ($env{'form.savemsg'.$ctr} ne '') {
2577: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.savemsg'.$ctr};
1.119 ng 2578: $idx++;
2579: }
2580: $ctr++;
1.41 ng 2581: }
1.119 ng 2582: $ctr = 0;
2583: while ($ctr < $ngrade) {
1.257 albertel 2584: if ($env{'form.newmsg'.$ctr} ne '') {
2585: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.newmsg'.$ctr};
2586: $env{'form.savemsg'.$idx} = $env{'form.newmsg'.$ctr};
1.119 ng 2587: $idx++;
2588: }
2589: $ctr++;
1.41 ng 2590: }
1.257 albertel 2591: $env{'form.savemsgN'} = --$idx;
2592: $keyhash{$symb.'_savemsgN'} = $env{'form.savemsgN'};
1.119 ng 2593: my $putresult = &Apache::lonnet::put
1.301 albertel 2594: ('nohist_handgrade',\%keyhash,$cdom,$cnum);
1.41 ng 2595: }
1.44 ng 2596: # Called by Save & Refresh from Highlight Attribute Window
1.257 albertel 2597: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
2598: if ($env{'form.refresh'} eq 'on') {
1.86 ng 2599: my ($ctr,$total) = (0,0);
2600: while ($ctr < $ngrade) {
1.257 albertel 2601: $total++ if $env{'form.unamedom'.$ctr} ne '';
1.86 ng 2602: $ctr++;
2603: }
1.257 albertel 2604: $env{'form.NTSTU'}=$ngrade;
1.86 ng 2605: $ctr = 0;
2606: while ($ctr < $total) {
1.257 albertel 2607: my $processUser = $env{'form.unamedom'.$ctr};
2608: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2609: $env{'form.fullname'} = $$fullname{$processUser};
1.86 ng 2610: &submission($request,$ctr,$total-1);
1.41 ng 2611: $ctr++;
2612: }
2613: return '';
2614: }
1.36 ng 2615:
1.121 ng 2616: # Go directly to grade student - from submission or link from chart page
1.120 ng 2617: if ($button eq 'Grade Student') {
1.324 albertel 2618: (undef,undef,$env{'form.handgrade'},undef,undef) = &showResourceInfo($symb);
1.257 albertel 2619: my $processUser = $env{'form.unamedom'.$env{'form.studentNo'}};
2620: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2621: $env{'form.fullname'} = $$fullname{$processUser};
1.120 ng 2622: &submission($request,0,0);
2623: return '';
2624: }
2625:
1.44 ng 2626: # Get the next/previous one or group of students
1.257 albertel 2627: my $firststu = $env{'form.unamedom0'};
2628: my $laststu = $env{'form.unamedom'.($ngrade-1)};
1.119 ng 2629: my $ctr = 2;
1.41 ng 2630: while ($laststu eq '') {
1.257 albertel 2631: $laststu = $env{'form.unamedom'.($ngrade-$ctr)};
1.41 ng 2632: $ctr++;
2633: $laststu = $firststu if ($ctr > $ngrade);
2634: }
1.44 ng 2635:
1.41 ng 2636: my (@parsedlist,@nextlist);
2637: my ($nextflg) = 0;
1.524 raeburn 2638: foreach my $item (sort
1.294 albertel 2639: {
2640: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
2641: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
2642: }
2643: return $a cmp $b;
2644: } (keys(%$fullname))) {
1.41 ng 2645: if ($nextflg == 1 && $button =~ /Next$/) {
1.524 raeburn 2646: push(@parsedlist,$item);
1.41 ng 2647: }
1.524 raeburn 2648: $nextflg = 1 if ($item eq $laststu);
1.41 ng 2649: if ($button eq 'Previous') {
1.524 raeburn 2650: last if ($item eq $firststu);
2651: push(@parsedlist,$item);
1.41 ng 2652: }
2653: }
2654: $ctr = 0;
2655: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
1.582 raeburn 2656: my $res_error;
2657: my ($partlist) = &response_type($symb,\$res_error);
2658: if ($res_error) {
2659: $request->print(&navmap_errormsg());
2660: return;
2661: }
1.41 ng 2662: foreach my $student (@parsedlist) {
1.257 albertel 2663: my $submitonly=$env{'form.submitonly'};
1.41 ng 2664: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 2665:
2666: if ($submitonly eq 'queued') {
2667: my %queue_status =
2668: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
2669: $udom,$uname);
2670: next if (!defined($queue_status{'gradingqueue'}));
2671: }
2672:
1.156 albertel 2673: if ($submitonly =~ /^(yes|graded|incorrect)$/) {
1.257 albertel 2674: # my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 2675: my %status=&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 2676: my $submitted = 0;
1.248 albertel 2677: my $ungraded = 0;
2678: my $incorrect = 0;
1.524 raeburn 2679: foreach my $item (keys(%status)) {
2680: $submitted = 1 if ($status{$item} ne 'nothing');
2681: $ungraded = 1 if ($status{$item} =~ /^ungraded/);
2682: $incorrect = 1 if ($status{$item} =~ /^incorrect/);
2683: my ($foo,$partid,$foo1) = split(/\./,$item);
1.145 albertel 2684: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
2685: $submitted = 0;
2686: }
1.41 ng 2687: }
1.156 albertel 2688: next if (!$submitted && ($submitonly eq 'yes' ||
2689: $submitonly eq 'incorrect' ||
2690: $submitonly eq 'graded'));
1.248 albertel 2691: next if (!$ungraded && ($submitonly eq 'graded'));
2692: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 2693: }
1.524 raeburn 2694: push(@nextlist,$student) if ($ctr < $ntstu);
1.129 ng 2695: last if ($ctr == $ntstu);
1.41 ng 2696: $ctr++;
2697: }
1.36 ng 2698:
1.41 ng 2699: $ctr = 0;
2700: my $total = scalar(@nextlist)-1;
1.39 ng 2701:
1.524 raeburn 2702: foreach (sort(@nextlist)) {
1.41 ng 2703: my ($uname,$udom,$submitter) = split(/:/);
1.257 albertel 2704: $env{'form.student'} = $uname;
2705: $env{'form.userdom'} = $udom;
2706: $env{'form.fullname'} = $$fullname{$_};
1.41 ng 2707: &submission($request,$ctr,$total);
2708: $ctr++;
2709: }
2710: if ($total < 0) {
1.485 albertel 2711: my $the_end = '<h3><span class="LC_info">'.&mt('LON-CAPA User Message').'</span></h3><br />'."\n";
2712: $the_end.=&mt('<b>Message: </b> No more students for this section or class.').'<br /><br />'."\n";
2713: $the_end.=&mt('Click on the button below to return to the grading menu.').'<br /><br />'."\n";
1.324 albertel 2714: $the_end.=&show_grading_menu_form($symb);
1.41 ng 2715: $request->print($the_end);
2716: }
2717: return '';
1.38 ng 2718: }
1.36 ng 2719:
1.44 ng 2720: #---- Save the score and award for each student, if changed
1.38 ng 2721: sub saveHandGrade {
1.324 albertel 2722: my ($request,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
1.342 banghart 2723: my @version_parts;
1.104 albertel 2724: my $usec = &Apache::lonnet::getsection($domain,$stuname,
1.257 albertel 2725: $env{'request.course.id'});
1.104 albertel 2726: if (!&canmodify($usec)) { return('not_allowed'); }
1.337 banghart 2727: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
1.251 banghart 2728: my @parts_graded;
1.77 ng 2729: my %newrecord = ();
2730: my ($pts,$wgt) = ('','');
1.269 raeburn 2731: my %aggregate = ();
2732: my $aggregateflag = 0;
1.301 albertel 2733: my @parts = split(/:/,$env{'form.partlist'.$newflg});
2734: foreach my $new_part (@parts) {
1.337 banghart 2735: #collaborator ($submi may vary for different parts
1.259 banghart 2736: if ($submitter && $new_part ne $part) { next; }
2737: my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
1.125 ng 2738: if ($dropMenu eq 'excused') {
1.259 banghart 2739: if ($record{'resource.'.$new_part.'.solved'} ne 'excused') {
2740: $newrecord{'resource.'.$new_part.'.solved'} = 'excused';
2741: if (exists($record{'resource.'.$new_part.'.awarded'})) {
2742: $newrecord{'resource.'.$new_part.'.awarded'} = '';
1.58 albertel 2743: }
1.364 banghart 2744: $newrecord{'resource.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.58 albertel 2745: }
1.125 ng 2746: } elsif ($dropMenu eq 'reset status'
1.259 banghart 2747: && exists($record{'resource.'.$new_part.'.solved'})) { #don't bother if no old records -> no attempts
1.524 raeburn 2748: foreach my $key (keys(%record)) {
1.259 banghart 2749: if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
1.197 albertel 2750: }
1.259 banghart 2751: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2752: "$env{'user.name'}:$env{'user.domain'}";
1.270 albertel 2753: my $totaltries = $record{'resource.'.$part.'.tries'};
2754:
2755: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
2756: [$new_part]);
2757: my $aggtries =$totaltries;
1.269 raeburn 2758: if ($last_resets{$new_part}) {
1.270 albertel 2759: $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
2760: $new_part);
1.269 raeburn 2761: }
1.270 albertel 2762:
2763: my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
1.269 raeburn 2764: if ($aggtries > 0) {
1.327 albertel 2765: &decrement_aggs($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
1.269 raeburn 2766: $aggregateflag = 1;
2767: }
1.125 ng 2768: } elsif ($dropMenu eq '') {
1.259 banghart 2769: $pts = ($env{'form.GD_BOX'.$newflg.'_'.$new_part} ne '' ?
2770: $env{'form.GD_BOX'.$newflg.'_'.$new_part} :
2771: $env{'form.RADVAL'.$newflg.'_'.$new_part});
2772: if ($pts eq '' && $env{'form.GD_SEL'.$newflg.'_'.$new_part} eq '') {
1.153 albertel 2773: next;
2774: }
1.259 banghart 2775: $wgt = $env{'form.WGT'.$newflg.'_'.$new_part} eq '' ? 1 :
2776: $env{'form.WGT'.$newflg.'_'.$new_part};
1.41 ng 2777: my $partial= $pts/$wgt;
1.259 banghart 2778: if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
1.153 albertel 2779: #do not update score for part if not changed.
1.346 banghart 2780: &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
1.153 albertel 2781: next;
1.251 banghart 2782: } else {
1.524 raeburn 2783: push(@parts_graded,$new_part);
1.153 albertel 2784: }
1.259 banghart 2785: if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
2786: $newrecord{'resource.'.$new_part.'.awarded'} = $partial;
1.153 albertel 2787: }
1.259 banghart 2788: my $reckey = 'resource.'.$new_part.'.solved';
1.41 ng 2789: if ($partial == 0) {
1.153 albertel 2790: if ($record{$reckey} ne 'incorrect_by_override') {
2791: $newrecord{$reckey} = 'incorrect_by_override';
2792: }
1.41 ng 2793: } else {
1.153 albertel 2794: if ($record{$reckey} ne 'correct_by_override') {
2795: $newrecord{$reckey} = 'correct_by_override';
2796: }
2797: }
2798: if ($submitter &&
1.259 banghart 2799: ($record{'resource.'.$new_part.'.submitted_by'} ne $submitter)) {
2800: $newrecord{'resource.'.$new_part.'.submitted_by'} = $submitter;
1.41 ng 2801: }
1.259 banghart 2802: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2803: "$env{'user.name'}:$env{'user.domain'}";
1.41 ng 2804: }
1.259 banghart 2805: # unless problem has been graded, set flag to version the submitted files
1.305 banghart 2806: unless ($record{'resource.'.$new_part.'.solved'} =~ /^correct_/ ||
2807: $record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override' ||
2808: $dropMenu eq 'reset status')
2809: {
1.524 raeburn 2810: push(@version_parts,$new_part);
1.259 banghart 2811: }
1.41 ng 2812: }
1.301 albertel 2813: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2814: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2815:
1.344 albertel 2816: if (%newrecord) {
2817: if (@version_parts) {
1.364 banghart 2818: my @changed_keys = &version_portfiles(\%record, \@parts_graded,
2819: $env{'request.course.id'}, $symb, $domain, $stuname, \@version_parts);
1.344 albertel 2820: @newrecord{@changed_keys} = @record{@changed_keys};
1.367 albertel 2821: foreach my $new_part (@version_parts) {
2822: &handback_files($request,$symb,$stuname,$domain,$newflg,
2823: $new_part,\%newrecord);
2824: }
1.259 banghart 2825: }
1.44 ng 2826: &Apache::lonnet::cstore(\%newrecord,$symb,
1.257 albertel 2827: $env{'request.course.id'},$domain,$stuname);
1.380 albertel 2828: &check_and_remove_from_queue(\@parts,\%record,\%newrecord,$symb,
2829: $cdom,$cnum,$domain,$stuname);
1.41 ng 2830: }
1.269 raeburn 2831: if ($aggregateflag) {
2832: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 2833: $cdom,$cnum);
1.269 raeburn 2834: }
1.301 albertel 2835: return ('',$pts,$wgt);
1.36 ng 2836: }
1.322 albertel 2837:
1.380 albertel 2838: sub check_and_remove_from_queue {
2839: my ($parts,$record,$newrecord,$symb,$cdom,$cnum,$domain,$stuname) = @_;
2840: my @ungraded_parts;
2841: foreach my $part (@{$parts}) {
2842: if ( $record->{ 'resource.'.$part.'.awarded'} eq ''
2843: && $record->{ 'resource.'.$part.'.solved' } ne 'excused'
2844: && $newrecord->{'resource.'.$part.'.awarded'} eq ''
2845: && $newrecord->{'resource.'.$part.'.solved' } ne 'excused'
2846: ) {
2847: push(@ungraded_parts, $part);
2848: }
2849: }
2850: if ( !@ungraded_parts ) {
2851: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,
2852: $cnum,$domain,$stuname);
2853: }
2854: }
2855:
1.337 banghart 2856: sub handback_files {
2857: my ($request,$symb,$stuname,$domain,$newflg,$new_part,$newrecord) = @_;
1.517 raeburn 2858: my $portfolio_root = '/userfiles/portfolio';
1.582 raeburn 2859: my $res_error;
2860: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
2861: if ($res_error) {
2862: $request->print('<br />'.&navmap_errormsg().'<br />');
2863: return;
2864: }
1.375 albertel 2865: my @part_response_id = &flatten_responseType($responseType);
2866: foreach my $part_response_id (@part_response_id) {
2867: my ($part_id,$resp_id) = @{ $part_response_id };
2868: my $part_resp = join('_',@{ $part_response_id });
1.337 banghart 2869: if (($env{'form.'.$newflg.'_'.$part_resp.'_returndoc1'}) && ($new_part == $part_id)) {
2870: # if multiple files are uploaded names will be 'returndoc2','returndoc3'
2871: my $file_counter = 1;
1.367 albertel 2872: my $file_msg;
1.337 banghart 2873: while ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter}) {
2874: my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.'.filename'};
1.338 banghart 2875: my ($directory,$answer_file) =
2876: ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter} =~ /^(.*?)([^\/]*)$/);
2877: my ($answer_name,$answer_ver,$answer_ext) =
2878: &file_name_version_ext($answer_file);
1.355 banghart 2879: my ($portfolio_path) = ($directory =~ /^.+$stuname\/portfolio(.*)/);
1.517 raeburn 2880: my $getpropath = 1;
2881: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$portfolio_path,$domain,$stuname,$getpropath);
1.338 banghart 2882: my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
1.355 banghart 2883: # fix file name
2884: my ($save_file_name) = (($directory.$answer_name.".$version.".$answer_ext) =~ /^.+\/${stuname}\/(.*)/);
2885: my $result=&Apache::lonnet::finishuserfileupload($stuname,$domain,
2886: $newflg.'_'.$part_resp.'_returndoc'.$file_counter,
2887: $save_file_name);
1.337 banghart 2888: if ($result !~ m|^/uploaded/|) {
1.536 raeburn 2889: $request->print('<br /><span class="LC_error">'.
2890: &mt('An error occurred ([_1]) while trying to upload [_2].',
2891: $result,$newflg.'_'.$part_resp.'_returndoc'.$file_counter).
2892: '</span>');
1.356 banghart 2893: } else {
1.360 banghart 2894: # mark the file as read only
2895: my @files = ($save_file_name);
1.372 albertel 2896: my @what = ($symb,$env{'request.course.id'},'handback');
1.360 banghart 2897: &Apache::lonnet::mark_as_readonly($domain,$stuname,\@files,\@what);
1.367 albertel 2898: if (exists($$newrecord{"resource.$new_part.$resp_id.handback"})) {
2899: $$newrecord{"resource.$new_part.$resp_id.handback"}.=',';
2900: }
2901: $$newrecord{"resource.$new_part.$resp_id.handback"} .= $save_file_name;
2902: $file_msg.= "\n".'<br /><span class="LC_filename"><a href="/uploaded/'."$domain/$stuname/".$save_file_name.'">'.$save_file_name."</a></span><br />";
2903:
1.337 banghart 2904: }
2905: $request->print("<br />".$fname." will be the uploaded file name");
1.354 albertel 2906: $request->print(" ".$env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter});
1.337 banghart 2907: $file_counter++;
2908: }
1.367 albertel 2909: my $subject = "File Handed Back by Instructor ";
2910: my $message = "A file has been returned that was originally submitted in reponse to: <br />";
2911: $message .= "<strong>".&Apache::lonnet::gettitle($symb)."</strong><br />";
2912: $message .= ' The returned file(s) are named: '. $file_msg;
2913: $message .= " and can be found in your portfolio space.";
1.418 albertel 2914: my ($feedurl,$showsymb) =
2915: &get_feedurl_and_symb($symb,$domain,$stuname);
1.386 raeburn 2916: my $restitle = &Apache::lonnet::gettitle($symb);
2917: my $msgstatus =
2918: &Apache::lonmsg::user_normal_msg($stuname,$domain,$subject.
2919: ' (File Returned) ['.$restitle.']',$message,undef,
1.418 albertel 2920: $feedurl,undef,undef,undef,$showsymb,$restitle);
1.337 banghart 2921: }
2922: }
1.338 banghart 2923: return;
1.337 banghart 2924: }
2925:
1.418 albertel 2926: sub get_feedurl_and_symb {
2927: my ($symb,$uname,$udom) = @_;
2928: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
2929: $url = &Apache::lonnet::clutter($url);
2930: my $encrypturl=&Apache::lonnet::EXT('resource.0.encrypturl',
2931: $symb,$udom,$uname);
2932: if ($encrypturl =~ /^yes$/i) {
2933: &Apache::lonenc::encrypted(\$url,1);
2934: &Apache::lonenc::encrypted(\$symb,1);
2935: }
2936: return ($url,$symb);
2937: }
2938:
1.313 banghart 2939: sub get_submitted_files {
2940: my ($udom,$uname,$partid,$respid,$record) = @_;
2941: my @files;
2942: if ($$record{"resource.$partid.$respid.portfiles"}) {
2943: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
2944: foreach my $file (split(',',$$record{"resource.$partid.$respid.portfiles"})) {
2945: push(@files,$file_url.$file);
2946: }
2947: }
2948: if ($$record{"resource.$partid.$respid.uploadedurl"}) {
2949: push(@files,$$record{"resource.$partid.$respid.uploadedurl"});
2950: }
2951: return (\@files);
2952: }
1.322 albertel 2953:
1.269 raeburn 2954: # ----------- Provides number of tries since last reset.
2955: sub get_num_tries {
2956: my ($record,$last_reset,$part) = @_;
2957: my $timestamp = '';
2958: my $num_tries = 0;
2959: if ($$record{'version'}) {
2960: for (my $version=$$record{'version'};$version>=1;$version--) {
2961: if (exists($$record{$version.':resource.'.$part.'.solved'})) {
2962: $timestamp = $$record{$version.':timestamp'};
2963: if ($timestamp > $last_reset) {
2964: $num_tries ++;
2965: } else {
2966: last;
2967: }
2968: }
2969: }
2970: }
2971: return $num_tries;
2972: }
2973:
2974: # ----------- Determine decrements required in aggregate totals
2975: sub decrement_aggs {
2976: my ($symb,$part,$aggregate,$aggtries,$totaltries,$solvedstatus) = @_;
2977: my %decrement = (
2978: attempts => 0,
2979: users => 0,
2980: correct => 0
2981: );
2982: $decrement{'attempts'} = $aggtries;
2983: if ($solvedstatus =~ /^correct/) {
2984: $decrement{'correct'} = 1;
2985: }
2986: if ($aggtries == $totaltries) {
2987: $decrement{'users'} = 1;
2988: }
1.524 raeburn 2989: foreach my $type (keys(%decrement)) {
1.269 raeburn 2990: $$aggregate{$symb."\0".$part."\0".$type} = -$decrement{$type};
2991: }
2992: return;
2993: }
2994:
2995: # ----------- Determine timestamps for last reset of aggregate totals for parts
2996: sub get_last_resets {
1.270 albertel 2997: my ($symb,$courseid,$partids) =@_;
2998: my %last_resets;
1.269 raeburn 2999: my $cdom = $env{'course.'.$courseid.'.domain'};
3000: my $cname = $env{'course.'.$courseid.'.num'};
1.271 albertel 3001: my @keys;
3002: foreach my $part (@{$partids}) {
3003: push(@keys,"$symb\0$part\0resettime");
3004: }
3005: my %results=&Apache::lonnet::get('nohist_resourcetracker',\@keys,
3006: $cdom,$cname);
3007: foreach my $part (@{$partids}) {
3008: $last_resets{$part}=$results{"$symb\0$part\0resettime"};
1.269 raeburn 3009: }
1.270 albertel 3010: return %last_resets;
1.269 raeburn 3011: }
3012:
1.251 banghart 3013: # ----------- Handles creating versions for portfolio files as answers
3014: sub version_portfiles {
1.343 banghart 3015: my ($record, $parts_graded, $courseid, $symb, $domain, $stu_name, $v_flag) = @_;
1.263 banghart 3016: my $version_parts = join('|',@$v_flag);
1.343 banghart 3017: my @returned_keys;
1.255 banghart 3018: my $parts = join('|', @$parts_graded);
1.517 raeburn 3019: my $portfolio_root = '/userfiles/portfolio';
1.277 albertel 3020: foreach my $key (keys(%$record)) {
1.259 banghart 3021: my $new_portfiles;
1.263 banghart 3022: if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
1.342 banghart 3023: my @versioned_portfiles;
1.367 albertel 3024: my @portfiles = split(/\s*,\s*/,$$record{$key});
1.252 banghart 3025: foreach my $file (@portfiles) {
1.306 banghart 3026: &Apache::lonnet::unmark_as_readonly($domain,$stu_name,[$symb,$env{'request.course.id'}],$file);
1.304 albertel 3027: my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*)$/);
3028: my ($answer_name,$answer_ver,$answer_ext) =
3029: &file_name_version_ext($answer_file);
1.517 raeburn 3030: my $getpropath = 1;
3031: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$directory,$domain,$stu_name,$getpropath);
1.342 banghart 3032: my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
1.306 banghart 3033: my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version);
3034: if ($new_answer ne 'problem getting file') {
1.342 banghart 3035: push(@versioned_portfiles, $directory.$new_answer);
1.306 banghart 3036: &Apache::lonnet::mark_as_readonly($domain,$stu_name,
1.367 albertel 3037: [$directory.$new_answer],
1.306 banghart 3038: [$symb,$env{'request.course.id'},'graded']);
1.259 banghart 3039: }
1.252 banghart 3040: }
1.343 banghart 3041: $$record{$key} = join(',',@versioned_portfiles);
3042: push(@returned_keys,$key);
1.251 banghart 3043: }
3044: }
1.343 banghart 3045: return (@returned_keys);
1.305 banghart 3046: }
3047:
1.307 banghart 3048: sub get_next_version {
1.341 banghart 3049: my ($answer_name, $answer_ext, $dir_list) = @_;
1.307 banghart 3050: my $version;
3051: foreach my $row (@$dir_list) {
3052: my ($file) = split(/\&/,$row,2);
3053: my ($file_name,$file_version,$file_ext) =
3054: &file_name_version_ext($file);
3055: if (($file_name eq $answer_name) &&
3056: ($file_ext eq $answer_ext)) {
3057: # gets here if filename and extension match, regardless of version
3058: if ($file_version ne '') {
3059: # a versioned file is found so save it for later
3060: if ($file_version > $version) {
3061: $version = $file_version;
3062: }
3063: }
3064: }
3065: }
3066: $version ++;
3067: return($version);
3068: }
3069:
1.305 banghart 3070: sub version_selected_portfile {
1.306 banghart 3071: my ($domain,$stu_name,$directory,$file_name,$version) = @_;
3072: my ($answer_name,$answer_ver,$answer_ext) =
3073: &file_name_version_ext($file_name);
3074: my $new_answer;
3075: $env{'form.copy'} = &Apache::lonnet::getfile("/uploaded/$domain/$stu_name/portfolio$directory$file_name");
3076: if($env{'form.copy'} eq '-1') {
3077: $new_answer = 'problem getting file';
3078: } else {
3079: $new_answer = $answer_name.'.'.$version.'.'.$answer_ext;
3080: my $copy_result = &Apache::lonnet::finishuserfileupload(
3081: $stu_name,$domain,'copy',
3082: '/portfolio'.$directory.$new_answer);
3083: }
3084: return ($new_answer);
1.251 banghart 3085: }
3086:
1.304 albertel 3087: sub file_name_version_ext {
3088: my ($file)=@_;
3089: my @file_parts = split(/\./, $file);
3090: my ($name,$version,$ext);
3091: if (@file_parts > 1) {
3092: $ext=pop(@file_parts);
3093: if (@file_parts > 1 && $file_parts[-1] =~ /^\d+$/) {
3094: $version=pop(@file_parts);
3095: }
3096: $name=join('.',@file_parts);
3097: } else {
3098: $name=join('.',@file_parts);
3099: }
3100: return($name,$version,$ext);
3101: }
3102:
1.44 ng 3103: #--------------------------------------------------------------------------------------
3104: #
3105: #-------------------------- Next few routines handles grading by section or whole class
3106: #
3107: #--- Javascript to handle grading by section or whole class
1.42 ng 3108: sub viewgrades_js {
3109: my ($request) = shift;
3110:
1.539 riegler 3111: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
1.41 ng 3112: $request->print(<<VIEWJAVASCRIPT);
3113: <script type="text/javascript" language="javascript">
1.45 ng 3114: function writePoint(partid,weight,point) {
1.125 ng 3115: var radioButton = document.classgrade["RADVAL_"+partid];
3116: var textbox = document.classgrade["TEXTVAL_"+partid];
1.42 ng 3117: if (point == "textval") {
1.125 ng 3118: point = document.classgrade["TEXTVAL_"+partid].value;
1.109 matthew 3119: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 3120: alert("$alertmsg"+parseFloat(point));
1.42 ng 3121: var resetbox = false;
3122: for (var i=0; i<radioButton.length; i++) {
3123: if (radioButton[i].checked) {
3124: textbox.value = i;
3125: resetbox = true;
3126: }
3127: }
3128: if (!resetbox) {
3129: textbox.value = "";
3130: }
3131: return;
3132: }
1.109 matthew 3133: if (parseFloat(point) > parseFloat(weight)) {
3134: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 3135: ") greater than the weight for the part. Accept?");
3136: if (resp == false) {
3137: textbox.value = "";
3138: return;
3139: }
3140: }
1.42 ng 3141: for (var i=0; i<radioButton.length; i++) {
3142: radioButton[i].checked=false;
1.109 matthew 3143: if (parseFloat(point) == i) {
1.42 ng 3144: radioButton[i].checked=true;
3145: }
3146: }
1.41 ng 3147:
1.42 ng 3148: } else {
1.125 ng 3149: textbox.value = parseFloat(point);
1.42 ng 3150: }
1.41 ng 3151: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3152: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3153: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3154: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3155: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3156: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 3157: if (saveval != "correct") {
3158: scorename.value = point;
1.43 ng 3159: if (selname[0].selected != true) {
3160: selname[0].selected = true;
3161: }
1.42 ng 3162: }
3163: }
1.125 ng 3164: document.classgrade["SELVAL_"+partid][0].selected = true;
1.42 ng 3165: }
3166:
3167: function writeRadText(partid,weight) {
1.125 ng 3168: var selval = document.classgrade["SELVAL_"+partid];
3169: var radioButton = document.classgrade["RADVAL_"+partid];
1.265 www 3170: var override = document.classgrade["FORCE_"+partid].checked;
1.125 ng 3171: var textbox = document.classgrade["TEXTVAL_"+partid];
3172: if (selval[1].selected || selval[2].selected) {
1.42 ng 3173: for (var i=0; i<radioButton.length; i++) {
3174: radioButton[i].checked=false;
3175:
3176: }
3177: textbox.value = "";
3178:
3179: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3180: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3181: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3182: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3183: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3184: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 3185: if ((saveval != "correct") || override) {
1.42 ng 3186: scorename.value = "";
1.125 ng 3187: if (selval[1].selected) {
3188: selname[1].selected = true;
3189: } else {
3190: selname[2].selected = true;
3191: if (Number(document.classgrade["GD_"+user+"_"+partid+"_tries"].value))
3192: {document.classgrade["GD_"+user+"_"+partid+"_tries"].value = '0';}
3193: }
1.42 ng 3194: }
3195: }
1.43 ng 3196: } else {
3197: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3198: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3199: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3200: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3201: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3202: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 3203: if ((saveval != "correct") || override) {
1.125 ng 3204: scorename.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
1.43 ng 3205: selname[0].selected = true;
3206: }
3207: }
3208: }
1.42 ng 3209: }
3210:
3211: function changeSelect(partid,user) {
1.125 ng 3212: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
3213: var textbox = document.classgrade["GD_"+user+'_'+partid+"_awarded"];
1.44 ng 3214: var point = textbox.value;
1.125 ng 3215: var weight = document.classgrade["weight_"+partid].value;
1.44 ng 3216:
1.109 matthew 3217: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 3218: alert("$alertmsg"+parseFloat(point));
1.44 ng 3219: textbox.value = "";
3220: return;
3221: }
1.109 matthew 3222: if (parseFloat(point) > parseFloat(weight)) {
3223: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 3224: ") greater than the weight of the part. Accept?");
3225: if (resp == false) {
3226: textbox.value = "";
3227: return;
3228: }
3229: }
1.42 ng 3230: selval[0].selected = true;
3231: }
3232:
3233: function changeOneScore(partid,user) {
1.125 ng 3234: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
3235: if (selval[1].selected || selval[2].selected) {
3236: document.classgrade["GD_"+user+'_'+partid+"_awarded"].value = "";
3237: if (selval[2].selected) {
3238: document.classgrade["GD_"+user+'_'+partid+"_tries"].value = "0";
3239: }
1.269 raeburn 3240: }
1.42 ng 3241: }
3242:
3243: function resetEntry(numpart) {
3244: for (ctpart=0;ctpart<numpart;ctpart++) {
1.125 ng 3245: var partid = document.classgrade["partid_"+ctpart].value;
3246: var radioButton = document.classgrade["RADVAL_"+partid];
3247: var textbox = document.classgrade["TEXTVAL_"+partid];
3248: var selval = document.classgrade["SELVAL_"+partid];
1.42 ng 3249: for (var i=0; i<radioButton.length; i++) {
3250: radioButton[i].checked=false;
3251:
3252: }
3253: textbox.value = "";
3254: selval[0].selected = true;
3255:
3256: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3257: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3258: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3259: var resetscore = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3260: resetscore.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
3261: var resettries = document.classgrade["GD_"+user+"_"+partid+"_tries"];
3262: resettries.value = document.classgrade["GD_"+user+"_"+partid+"_tries_s"].value;
3263: var saveselval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3264: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 3265: if (saveselval == "excused") {
1.43 ng 3266: if (selname[1].selected == false) { selname[1].selected = true;}
1.42 ng 3267: } else {
1.43 ng 3268: if (selname[0].selected == false) {selname[0].selected = true};
1.42 ng 3269: }
3270: }
1.41 ng 3271: }
1.42 ng 3272: }
3273:
1.41 ng 3274: </script>
3275: VIEWJAVASCRIPT
1.42 ng 3276: }
3277:
1.44 ng 3278: #--- show scores for a section or whole class w/ option to change/update a score
1.42 ng 3279: sub viewgrades {
3280: my ($request) = shift;
3281: &viewgrades_js($request);
1.41 ng 3282:
1.324 albertel 3283: my ($symb) = &get_symb($request);
1.168 albertel 3284: #need to make sure we have the correct data for later EXT calls,
3285: #thus invalidate the cache
3286: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 3287: $env{'course.'.$env{'request.course.id'}.'.num'},
3288: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 3289: &Apache::lonnet::clear_EXT_cache_status();
3290:
1.398 albertel 3291: my $result='<h3><span class="LC_info">'.&mt('Manual Grading').'</span></h3>';
1.485 albertel 3292: $result.='<h4>'.&mt('<b>Current Resource: </b>[_1]',$env{'form.probTitle'}).'</h4>'."\n";
1.41 ng 3293:
3294: #view individual student submission form - called using Javascript viewOneStudent
1.324 albertel 3295: $result.=&jscriptNform($symb);
1.41 ng 3296:
1.44 ng 3297: #beginning of class grading form
1.442 banghart 3298: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.41 ng 3299: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1.418 albertel 3300: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.38 ng 3301: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.432 banghart 3302: &build_section_inputs().
1.257 albertel 3303: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.442 banghart 3304: '<input type="hidden" name="Status" value="'.$env{'stu_status'}.'" />'."\n".
1.257 albertel 3305: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.72 ng 3306:
1.560 raeburn 3307: my ($common_header,$specific_header);
1.257 albertel 3308: if ($env{'form.section'} eq 'all') {
1.560 raeburn 3309: $common_header = &mt('Assign Common Grade to Class');
3310: $specific_header = &mt('Assign Grade to Specific Students in Class');
1.257 albertel 3311: } elsif ($env{'form.section'} eq 'none') {
1.560 raeburn 3312: $common_header = &mt('Assign Common Grade to Students in no Section');
3313: $specific_header = &mt('Assign Grade to Specific Students in no Section');
1.52 albertel 3314: } else {
1.560 raeburn 3315: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
3316: $common_header = &mt('Assign Common Grade to Students in Section(s) [_1]',$section_display);
3317: $specific_header = &mt('Assign Grade to Specific Students in Section(s) [_1]',$section_display);
1.52 albertel 3318: }
1.560 raeburn 3319: $result.= '<h3>'.$common_header.'</h3>'.&Apache::loncommon::start_data_table();
1.44 ng 3320: #radio buttons/text box for assigning points for a section or class.
3321: #handles different parts of a problem
1.582 raeburn 3322: my $res_error;
3323: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
3324: if ($res_error) {
3325: return &navmap_errormsg();
3326: }
1.42 ng 3327: my %weight = ();
3328: my $ctsparts = 0;
1.45 ng 3329: my %seen = ();
1.375 albertel 3330: my @part_response_id = &flatten_responseType($responseType);
3331: foreach my $part_response_id (@part_response_id) {
3332: my ($partid,$respid) = @{ $part_response_id };
3333: my $part_resp = join('_',@{ $part_response_id });
1.45 ng 3334: next if $seen{$partid};
3335: $seen{$partid}++;
1.375 albertel 3336: my $handgrade=$$handgrade{$part_resp};
1.42 ng 3337: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
3338: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
3339:
1.324 albertel 3340: my $display_part=&get_display_part($partid,$symb);
1.485 albertel 3341: my $radio.='<table border="0"><tr>';
1.41 ng 3342: my $ctr = 0;
1.42 ng 3343: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
1.485 albertel 3344: $radio.= '<td><label><input type="radio" name="RADVAL_'.$partid.'" '.
1.54 albertel 3345: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.288 albertel 3346: ','.$ctr.')" />'.$ctr."</label></td>\n";
1.41 ng 3347: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
3348: $ctr++;
3349: }
1.485 albertel 3350: $radio.='</tr></table>';
3351: my $line = '<input type="text" name="TEXTVAL_'.
1.589 bisitz 3352: $partid.'" size="4" '.'onchange="javascript:writePoint(\''.
1.54 albertel 3353: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.539 riegler 3354: $weight{$partid}.' '.&mt('(problem weight)').'</td>'."\n";
3355: $line.= '<td><b>'.&mt('Grade Status').':</b><select name="SELVAL_'.$partid.'"'.
1.589 bisitz 3356: 'onchange="javascript:writeRadText(\''.$partid.'\','.
1.59 albertel 3357: $weight{$partid}.')"> '.
1.401 albertel 3358: '<option selected="selected"> </option>'.
1.485 albertel 3359: '<option value="excused">'.&mt('excused').'</option>'.
3360: '<option value="reset status">'.&mt('reset status').'</option>'.
3361: '</select></td>'.
3362: '<td><label><input type="checkbox" name="FORCE_'.$partid.'" />'.&mt('Override "Correct"').'</label>';
3363: $line.='<input type="hidden" name="partid_'.
3364: $ctsparts.'" value="'.$partid.'" />'."\n";
3365: $line.='<input type="hidden" name="weight_'.
3366: $partid.'" value="'.$weight{$partid}.'" />'."\n";
3367:
3368: $result.=
3369: &Apache::loncommon::start_data_table_row()."\n".
1.577 bisitz 3370: '<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 3371: &Apache::loncommon::end_data_table_row()."\n";
1.42 ng 3372: $ctsparts++;
1.41 ng 3373: }
1.474 albertel 3374: $result.=&Apache::loncommon::end_data_table()."\n".
1.52 albertel 3375: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.485 albertel 3376: $result.='<input type="button" value="'.&mt('Revert to Default').'" '.
1.589 bisitz 3377: 'onclick="javascript:resetEntry('.$ctsparts.');" />';
1.41 ng 3378:
1.44 ng 3379: #table listing all the students in a section/class
3380: #header of table
1.560 raeburn 3381: $result.= '<h3>'.$specific_header.'</h3>'.
3382: &Apache::loncommon::start_data_table().
3383: &Apache::loncommon::start_data_table_header_row().
3384: '<th>'.&mt('No.').'</th>'.
3385: '<th>'.&nameUserString('header')."</th>\n";
1.582 raeburn 3386: my $partserror;
3387: my (@parts) = sort(&getpartlist($symb,\$partserror));
3388: if ($partserror) {
3389: return &navmap_errormsg();
3390: }
1.324 albertel 3391: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.269 raeburn 3392: my @partids = ();
1.41 ng 3393: foreach my $part (@parts) {
3394: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1.539 riegler 3395: my $narrowtext = &mt('Tries');
3396: $display =~ s|^Number of Attempts|$narrowtext <br />|; # makes the column narrower
1.41 ng 3397: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
1.207 albertel 3398: my ($partid) = &split_part_type($part);
1.524 raeburn 3399: push(@partids,$partid);
1.324 albertel 3400: my $display_part=&get_display_part($partid,$symb);
1.41 ng 3401: if ($display =~ /^Partial Credit Factor/) {
1.485 albertel 3402: $result.='<th>'.
3403: &mt('Score Part: [_1]<br /> (weight = [_2])',
3404: $display_part,$weight{$partid}).'</th>'."\n";
1.41 ng 3405: next;
1.485 albertel 3406:
1.207 albertel 3407: } else {
1.485 albertel 3408: if ($display =~ /Problem Status/) {
3409: my $grade_status_mt = &mt('Grade Status');
3410: $display =~ s{Problem Status}{$grade_status_mt<br />};
3411: }
3412: my $part_mt = &mt('Part:');
3413: $display =~s{\[Part: \Q$partid\E\]}{$part_mt $display_part};
1.41 ng 3414: }
1.485 albertel 3415:
1.474 albertel 3416: $result.='<th>'.$display.'</th>'."\n";
1.41 ng 3417: }
1.474 albertel 3418: $result.=&Apache::loncommon::end_data_table_header_row();
1.44 ng 3419:
1.270 albertel 3420: my %last_resets =
3421: &get_last_resets($symb,$env{'request.course.id'},\@partids);
1.269 raeburn 3422:
1.41 ng 3423: #get info for each student
1.44 ng 3424: #list all the students - with points and grade status
1.257 albertel 3425: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
1.41 ng 3426: my $ctr = 0;
1.294 albertel 3427: foreach (sort
3428: {
3429: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
3430: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
3431: }
3432: return $a cmp $b;
3433: } (keys(%$fullname))) {
1.126 ng 3434: $ctr++;
1.324 albertel 3435: $result.=&viewstudentgrade($symb,$env{'request.course.id'},
1.269 raeburn 3436: $_,$$fullname{$_},\@parts,\%weight,$ctr,\%last_resets);
1.41 ng 3437: }
1.474 albertel 3438: $result.=&Apache::loncommon::end_data_table();
1.41 ng 3439: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.485 albertel 3440: $result.='<input type="button" value="'.&mt('Save').'" '.
1.589 bisitz 3441: 'onclick="javascript:submit();" target="_self" /></form>'."\n";
1.96 albertel 3442: if (scalar(%$fullname) eq 0) {
3443: my $colspan=3+scalar(@parts);
1.433 banghart 3444: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.442 banghart 3445: my $stu_status = join(' or ',&Apache::loncommon::get_env_multiple('form.Status'));
1.433 banghart 3446: $result='<span class="LC_warning">'.
1.485 albertel 3447: &mt('There are no students in section(s) [_1] with enrollment status [_2] to modify or grade.',
1.442 banghart 3448: $section_display, $stu_status).
1.433 banghart 3449: '</span>';
1.96 albertel 3450: }
1.324 albertel 3451: $result.=&show_grading_menu_form($symb);
1.41 ng 3452: return $result;
3453: }
3454:
1.44 ng 3455: #--- call by previous routine to display each student
1.41 ng 3456: sub viewstudentgrade {
1.324 albertel 3457: my ($symb,$courseid,$student,$fullname,$parts,$weight,$ctr,$last_resets) = @_;
1.44 ng 3458: my ($uname,$udom) = split(/:/,$student);
3459: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.269 raeburn 3460: my %aggregates = ();
1.474 albertel 3461: my $result=&Apache::loncommon::start_data_table_row().'<td align="right">'.
1.233 albertel 3462: '<input type="hidden" name="ctr'.($ctr-1).'" value="'.$student.'" />'.
3463: "\n".$ctr.' </td><td> '.
1.44 ng 3464: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 3465: '\');" target="_self">'.$fullname.'</a> '.
1.398 albertel 3466: '<span class="LC_internal_info">('.$uname.($env{'user.domain'} eq $udom ? '' : ':'.$udom).')</span></td>'."\n";
1.281 albertel 3467: $student=~s/:/_/; # colon doen't work in javascript for names
1.63 albertel 3468: foreach my $apart (@$parts) {
3469: my ($part,$type) = &split_part_type($apart);
1.41 ng 3470: my $score=$record{"resource.$part.$type"};
1.276 albertel 3471: $result.='<td align="center">';
1.269 raeburn 3472: my ($aggtries,$totaltries);
3473: unless (exists($aggregates{$part})) {
1.270 albertel 3474: $totaltries = $record{'resource.'.$part.'.tries'};
3475:
3476: $aggtries = $totaltries;
1.269 raeburn 3477: if ($$last_resets{$part}) {
1.270 albertel 3478: $aggtries = &get_num_tries(\%record,$$last_resets{$part},
3479: $part);
3480: }
1.269 raeburn 3481: $result.='<input type="hidden" name="'.
3482: 'GD_'.$student.'_'.$part.'_aggtries" value="'.$aggtries.'" />'."\n";
3483: $result.='<input type="hidden" name="'.
3484: 'GD_'.$student.'_'.$part.'_totaltries" value="'.$totaltries.'" />'."\n";
3485: $aggregates{$part} = 1;
3486: }
1.41 ng 3487: if ($type eq 'awarded') {
1.320 albertel 3488: my $pts = $score eq '' ? '' : &compute_points($score,$$weight{$part});
1.42 ng 3489: $result.='<input type="hidden" name="'.
1.89 albertel 3490: 'GD_'.$student.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.233 albertel 3491: $result.='<input type="text" name="'.
1.89 albertel 3492: 'GD_'.$student.'_'.$part.'_awarded" '.
1.589 bisitz 3493: 'onchange="javascript:changeSelect(\''.$part.'\',\''.$student.
1.44 ng 3494: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41 ng 3495: } elsif ($type eq 'solved') {
3496: my ($status,$foo)=split(/_/,$score,2);
3497: $status = 'nothing' if ($status eq '');
1.89 albertel 3498: $result.='<input type="hidden" name="'.'GD_'.$student.'_'.
1.54 albertel 3499: $part.'_solved_s" value="'.$status.'" />'."\n";
1.233 albertel 3500: $result.=' <select name="'.
1.89 albertel 3501: 'GD_'.$student.'_'.$part.'_solved" '.
1.589 bisitz 3502: 'onchange="javascript:changeOneScore(\''.$part.'\',\''.$student.'\')" >'."\n";
1.485 albertel 3503: $result.= (($status eq 'excused') ? '<option> </option><option selected="selected" value="excused">'.&mt('excused').'</option>'
3504: : '<option selected="selected"> </option><option value="excused">'.&mt('excused').'</option>')."\n";
3505: $result.='<option value="reset status">'.&mt('reset status').'</option>';
1.126 ng 3506: $result.="</select> </td>\n";
1.122 ng 3507: } else {
3508: $result.='<input type="hidden" name="'.
3509: 'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
3510: "\n";
1.233 albertel 3511: $result.='<input type="text" name="'.
1.122 ng 3512: 'GD_'.$student.'_'.$part.'_'.$type.'" '.
3513: 'value="'.$score.'" size="4" /></td>'."\n";
1.41 ng 3514: }
3515: }
1.474 albertel 3516: $result.=&Apache::loncommon::end_data_table_row();
1.41 ng 3517: return $result;
1.38 ng 3518: }
3519:
1.44 ng 3520: #--- change scores for all the students in a section/class
3521: # record does not get update if unchanged
1.38 ng 3522: sub editgrades {
1.41 ng 3523: my ($request) = @_;
3524:
1.324 albertel 3525: my $symb=&get_symb($request);
1.433 banghart 3526: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.477 albertel 3527: my $title='<h2>'.&mt('Current Grade Status').'</h2>';
3528: $title.='<h4>'.&mt('<b>Current Resource: </b>[_1]',$env{'form.probTitle'}).'</h4>'."\n";
1.433 banghart 3529: $title.='<h4>'.&mt('<b>Section: </b>[_1]',$section_display).'</h4>'."\n";
1.126 ng 3530:
1.477 albertel 3531: my $result= &Apache::loncommon::start_data_table().
3532: &Apache::loncommon::start_data_table_header_row().
3533: '<th rowspan="2" valign="middle">'.&mt('No.').'</th>'.
3534: '<th rowspan="2" valign="middle">'.&nameUserString('header')."</th>\n";
1.43 ng 3535: my %scoreptr = (
3536: 'correct' =>'correct_by_override',
3537: 'incorrect'=>'incorrect_by_override',
3538: 'excused' =>'excused',
3539: 'ungraded' =>'ungraded_attempted',
3540: 'nothing' => '',
3541: );
1.257 albertel 3542: my ($classlist,undef,$fullname) = &getclasslist($env{'form.section'},'0');
1.34 ng 3543:
1.44 ng 3544: my (@partid);
3545: my %weight = ();
1.54 albertel 3546: my %columns = ();
1.44 ng 3547: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54 albertel 3548:
1.582 raeburn 3549: my $partserror;
3550: my (@parts) = sort(&getpartlist($symb,\$partserror));
3551: if ($partserror) {
3552: return &navmap_errormsg();
3553: }
1.54 albertel 3554: my $header;
1.257 albertel 3555: while ($ctr < $env{'form.totalparts'}) {
3556: my $partid = $env{'form.partid_'.$ctr};
1.524 raeburn 3557: push(@partid,$partid);
1.257 albertel 3558: $weight{$partid} = $env{'form.weight_'.$partid};
1.44 ng 3559: $ctr++;
1.54 albertel 3560: }
1.324 albertel 3561: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.54 albertel 3562: foreach my $partid (@partid) {
1.478 albertel 3563: $header .= '<th align="center">'.&mt('Old Score').'</th>'.
3564: '<th align="center">'.&mt('New Score').'</th>';
1.54 albertel 3565: $columns{$partid}=2;
3566: foreach my $stores (@parts) {
3567: my ($part,$type) = &split_part_type($stores);
3568: if ($part !~ m/^\Q$partid\E/) { next;}
3569: if ($type eq 'awarded' || $type eq 'solved') { next; }
3570: my $display=&Apache::lonnet::metadata($url,$stores.'.display');
1.551 raeburn 3571: $display =~ s/\[Part: \Q$part\E\]//;
1.539 riegler 3572: my $narrowtext = &mt('Tries');
3573: $display =~ s/Number of Attempts/$narrowtext/;
3574: $header .= '<th align="center">'.&mt('Old').' '.$display.'</th>'.
3575: '<th align="center">'.&mt('New').' '.$display.'</th>';
1.54 albertel 3576: $columns{$partid}+=2;
3577: }
3578: }
3579: foreach my $partid (@partid) {
1.324 albertel 3580: my $display_part=&get_display_part($partid,$symb);
1.478 albertel 3581: $result .= '<th colspan="'.$columns{$partid}.'" align="center">'.
3582: &mt('Part: [_1] (Weight = [_2])',$display_part,$weight{$partid}).
3583: '</th>';
1.54 albertel 3584:
1.44 ng 3585: }
1.477 albertel 3586: $result .= &Apache::loncommon::end_data_table_header_row().
3587: &Apache::loncommon::start_data_table_header_row().
3588: $header.
3589: &Apache::loncommon::end_data_table_header_row();
3590: my @noupdate;
1.126 ng 3591: my ($updateCtr,$noupdateCtr) = (1,1);
1.257 albertel 3592: for ($i=0; $i<$env{'form.total'}; $i++) {
1.93 albertel 3593: my $line;
1.257 albertel 3594: my $user = $env{'form.ctr'.$i};
1.281 albertel 3595: my ($uname,$udom)=split(/:/,$user);
1.44 ng 3596: my %newrecord;
3597: my $updateflag = 0;
1.281 albertel 3598: $line .= '<td>'.&nameUserString(undef,$$fullname{$user},$uname,$udom).'</td>';
1.108 albertel 3599: my $usec=$classlist->{"$uname:$udom"}[5];
1.105 albertel 3600: if (!&canmodify($usec)) {
1.126 ng 3601: my $numcols=scalar(@partid)*4+2;
1.477 albertel 3602: push(@noupdate,
1.478 albertel 3603: $line."<td colspan=\"$numcols\"><span class=\"LC_warning\">".
3604: &mt('Not allowed to modify student')."</span></td></tr>");
1.105 albertel 3605: next;
3606: }
1.269 raeburn 3607: my %aggregate = ();
3608: my $aggregateflag = 0;
1.281 albertel 3609: $user=~s/:/_/; # colon doen't work in javascript for names
1.44 ng 3610: foreach (@partid) {
1.257 albertel 3611: my $old_aw = $env{'form.GD_'.$user.'_'.$_.'_awarded_s'};
1.54 albertel 3612: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
3613: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
1.257 albertel 3614: my $old_score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
3615: my $awarded = $env{'form.GD_'.$user.'_'.$_.'_awarded'};
1.54 albertel 3616: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
3617: my $partial = $awarded eq '' ? '' : $pcr;
1.44 ng 3618: my $score;
3619: if ($partial eq '') {
1.257 albertel 3620: $score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 3621: } elsif ($partial > 0) {
3622: $score = 'correct_by_override';
3623: } elsif ($partial == 0) {
3624: $score = 'incorrect_by_override';
3625: }
1.257 albertel 3626: my $dropMenu = $env{'form.GD_'.$user.'_'.$_.'_solved'};
1.125 ng 3627: $score = 'excused' if (($dropMenu eq 'excused') && ($score ne 'excused'));
3628:
1.292 albertel 3629: $newrecord{'resource.'.$_.'.regrader'}=
3630: "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 3631: if ($dropMenu eq 'reset status' &&
3632: $old_score ne '') { # ignore if no previous attempts => nothing to reset
1.299 albertel 3633: $newrecord{'resource.'.$_.'.tries'} = '';
1.125 ng 3634: $newrecord{'resource.'.$_.'.solved'} = '';
3635: $newrecord{'resource.'.$_.'.award'} = '';
1.299 albertel 3636: $newrecord{'resource.'.$_.'.awarded'} = '';
1.125 ng 3637: $updateflag = 1;
1.269 raeburn 3638: if ($env{'form.GD_'.$user.'_'.$_.'_aggtries'} > 0) {
3639: my $aggtries = $env{'form.GD_'.$user.'_'.$_.'_aggtries'};
3640: my $totaltries = $env{'form.GD_'.$user.'_'.$_.'_totaltries'};
3641: my $solvedstatus = $env{'form.GD_'.$user.'_'.$_.'_solved_s'};
3642: &decrement_aggs($symb,$_,\%aggregate,$aggtries,$totaltries,$solvedstatus);
3643: $aggregateflag = 1;
3644: }
1.139 albertel 3645: } elsif (!($old_part eq $partial && $old_score eq $score)) {
3646: $updateflag = 1;
3647: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
3648: $newrecord{'resource.'.$_.'.solved'} = $score;
3649: $rec_update++;
1.125 ng 3650: }
3651:
1.93 albertel 3652: $line .= '<td align="center">'.$old_aw.' </td>'.
1.44 ng 3653: '<td align="center">'.$awarded.
3654: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 3655:
1.54 albertel 3656:
3657: my $partid=$_;
3658: foreach my $stores (@parts) {
3659: my ($part,$type) = &split_part_type($stores);
3660: if ($part !~ m/^\Q$partid\E/) { next;}
3661: if ($type eq 'awarded' || $type eq 'solved') { next; }
1.257 albertel 3662: my $old_aw = $env{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
3663: my $awarded = $env{'form.GD_'.$user.'_'.$part.'_'.$type};
1.54 albertel 3664: if ($awarded ne '' && $awarded ne $old_aw) {
3665: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.257 albertel 3666: $newrecord{'resource.'.$part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.54 albertel 3667: $updateflag=1;
3668: }
1.93 albertel 3669: $line .= '<td align="center">'.$old_aw.' </td>'.
1.54 albertel 3670: '<td align="center">'.$awarded.' </td>';
3671: }
1.44 ng 3672: }
1.477 albertel 3673: $line.="\n";
1.301 albertel 3674:
3675: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3676: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3677:
1.44 ng 3678: if ($updateflag) {
3679: $count++;
1.257 albertel 3680: &Apache::lonnet::cstore(\%newrecord,$symb,$env{'request.course.id'},
1.89 albertel 3681: $udom,$uname);
1.301 albertel 3682:
3683: if (&Apache::bridgetask::in_queue('gradingqueue',$symb,$cdom,
3684: $cnum,$udom,$uname)) {
3685: # need to figure out if should be in queue.
3686: my %record =
3687: &Apache::lonnet::restore($symb,$env{'request.course.id'},
3688: $udom,$uname);
3689: my $all_graded = 1;
3690: my $none_graded = 1;
3691: foreach my $part (@parts) {
3692: if ( $record{'resource.'.$part.'.awarded'} eq '' ) {
3693: $all_graded = 0;
3694: } else {
3695: $none_graded = 0;
3696: }
3697: }
3698:
3699: if ($all_graded || $none_graded) {
3700: &Apache::bridgetask::remove_from_queue('gradingqueue',
3701: $symb,$cdom,$cnum,
3702: $udom,$uname);
3703: }
3704: }
3705:
1.477 albertel 3706: $result.=&Apache::loncommon::start_data_table_row().
3707: '<td align="right"> '.$updateCtr.' </td>'.$line.
3708: &Apache::loncommon::end_data_table_row();
1.126 ng 3709: $updateCtr++;
1.93 albertel 3710: } else {
1.477 albertel 3711: push(@noupdate,
3712: '<td align="right"> '.$noupdateCtr.' </td>'.$line);
1.126 ng 3713: $noupdateCtr++;
1.44 ng 3714: }
1.269 raeburn 3715: if ($aggregateflag) {
3716: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 3717: $cdom,$cnum);
1.269 raeburn 3718: }
1.93 albertel 3719: }
1.477 albertel 3720: if (@noupdate) {
1.126 ng 3721: # my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3;
3722: my $numcols=scalar(@partid)*4+2;
1.477 albertel 3723: $result .= &Apache::loncommon::start_data_table_row('LC_empty_row').
1.478 albertel 3724: '<td align="center" colspan="'.$numcols.'">'.
3725: &mt('No Changes Occurred For the Students Below').
3726: '</td>'.
1.477 albertel 3727: &Apache::loncommon::end_data_table_row();
3728: foreach my $line (@noupdate) {
3729: $result.=
3730: &Apache::loncommon::start_data_table_row().
3731: $line.
3732: &Apache::loncommon::end_data_table_row();
3733: }
1.44 ng 3734: }
1.477 albertel 3735: $result .= &Apache::loncommon::end_data_table().
3736: &show_grading_menu_form($symb);
1.478 albertel 3737: my $msg = '<p><b>'.
3738: &mt('Number of records updated = [_1] for [quant,_2,student].',
3739: $rec_update,$count).'</b><br />'.
3740: '<b>'.&mt('Total number of students = [_1]',$env{'form.total'}).
3741: '</b></p>';
1.44 ng 3742: return $title.$msg.$result;
1.5 albertel 3743: }
1.54 albertel 3744:
3745: sub split_part_type {
3746: my ($partstr) = @_;
3747: my ($temp,@allparts)=split(/_/,$partstr);
3748: my $type=pop(@allparts);
1.439 albertel 3749: my $part=join('_',@allparts);
1.54 albertel 3750: return ($part,$type);
3751: }
3752:
1.44 ng 3753: #------------- end of section for handling grading by section/class ---------
3754: #
3755: #----------------------------------------------------------------------------
3756:
1.5 albertel 3757:
1.44 ng 3758: #----------------------------------------------------------------------------
3759: #
3760: #-------------------------- Next few routines handles grading by csv upload
3761: #
3762: #--- Javascript to handle csv upload
1.27 albertel 3763: sub csvupload_javascript_reverse_associate {
1.573 bisitz 3764: my $error1=&mt('You need to specify the username or the student/employee ID');
1.246 albertel 3765: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3766: return(<<ENDPICK);
3767: function verify(vf) {
3768: var foundsomething=0;
3769: var founduname=0;
1.243 albertel 3770: var foundID=0;
1.27 albertel 3771: for (i=0;i<=vf.nfields.value;i++) {
3772: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3773: if (i==0 && tw!=0) { foundID=1; }
3774: if (i==1 && tw!=0) { founduname=1; }
3775: if (i!=0 && i!=1 && i!=2 && tw!=0) { foundsomething=1; }
1.27 albertel 3776: }
1.246 albertel 3777: if (founduname==0 && foundID==0) {
3778: alert('$error1');
3779: return;
1.27 albertel 3780: }
3781: if (foundsomething==0) {
1.246 albertel 3782: alert('$error2');
3783: return;
1.27 albertel 3784: }
3785: vf.submit();
3786: }
3787: function flip(vf,tf) {
3788: var nw=eval('vf.f'+tf+'.selectedIndex');
3789: var i;
3790: for (i=0;i<=vf.nfields.value;i++) {
3791: //can not pick the same destination field for both name and domain
3792: if (((i ==0)||(i ==1)) &&
3793: ((tf==0)||(tf==1)) &&
3794: (i!=tf) &&
3795: (eval('vf.f'+i+'.selectedIndex')==nw)) {
3796: eval('vf.f'+i+'.selectedIndex=0;')
3797: }
3798: }
3799: }
3800: ENDPICK
3801: }
3802:
3803: sub csvupload_javascript_forward_associate {
1.573 bisitz 3804: my $error1=&mt('You need to specify the username or the student/employee ID');
1.246 albertel 3805: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3806: return(<<ENDPICK);
3807: function verify(vf) {
3808: var foundsomething=0;
3809: var founduname=0;
1.243 albertel 3810: var foundID=0;
1.27 albertel 3811: for (i=0;i<=vf.nfields.value;i++) {
3812: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3813: if (tw==1) { foundID=1; }
3814: if (tw==2) { founduname=1; }
3815: if (tw>3) { foundsomething=1; }
1.27 albertel 3816: }
1.246 albertel 3817: if (founduname==0 && foundID==0) {
3818: alert('$error1');
3819: return;
1.27 albertel 3820: }
3821: if (foundsomething==0) {
1.246 albertel 3822: alert('$error2');
3823: return;
1.27 albertel 3824: }
3825: vf.submit();
3826: }
3827: function flip(vf,tf) {
3828: var nw=eval('vf.f'+tf+'.selectedIndex');
3829: var i;
3830: //can not pick the same destination field twice
3831: for (i=0;i<=vf.nfields.value;i++) {
3832: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
3833: eval('vf.f'+i+'.selectedIndex=0;')
3834: }
3835: }
3836: }
3837: ENDPICK
3838: }
3839:
1.26 albertel 3840: sub csvuploadmap_header {
1.324 albertel 3841: my ($request,$symb,$datatoken,$distotal)= @_;
1.41 ng 3842: my $javascript;
1.257 albertel 3843: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3844: $javascript=&csvupload_javascript_reverse_associate();
3845: } else {
3846: $javascript=&csvupload_javascript_forward_associate();
3847: }
1.45 ng 3848:
1.324 albertel 3849: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.257 albertel 3850: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1.245 albertel 3851: my $ignore=&mt('Ignore First Line');
1.418 albertel 3852: $symb = &Apache::lonenc::check_encrypt($symb);
1.41 ng 3853: $request->print(<<ENDPICK);
1.26 albertel 3854: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.398 albertel 3855: <h3><span class="LC_info">Uploading Class Grades</span></h3>
1.45 ng 3856: $result
1.326 albertel 3857: <hr />
1.26 albertel 3858: <h3>Identify fields</h3>
3859: Total number of records found in file: $distotal <hr />
3860: Enter as many fields as you can. The system will inform you and bring you back
3861: to this page if the data selected is insufficient to run your class.<hr />
1.589 bisitz 3862: <input type="button" value="Reverse Association" onclick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1.245 albertel 3863: <label><input type="checkbox" name="noFirstLine" $checked />$ignore</label>
1.26 albertel 3864: <input type="hidden" name="associate" value="" />
3865: <input type="hidden" name="phase" value="three" />
3866: <input type="hidden" name="datatoken" value="$datatoken" />
1.257 albertel 3867: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
3868: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
1.26 albertel 3869: <input type="hidden" name="upfile_associate"
1.257 albertel 3870: value="$env{'form.upfile_associate'}" />
1.26 albertel 3871: <input type="hidden" name="symb" value="$symb" />
1.257 albertel 3872: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
3873: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
1.246 albertel 3874: <input type="hidden" name="command" value="csvuploadoptions" />
1.26 albertel 3875: <hr />
3876: <script type="text/javascript" language="Javascript">
3877: $javascript
3878: </script>
3879: ENDPICK
1.118 ng 3880: return '';
1.26 albertel 3881:
3882: }
3883:
3884: sub csvupload_fields {
1.582 raeburn 3885: my ($symb,$errorref) = @_;
3886: my (@parts) = &getpartlist($symb,$errorref);
3887: if (ref($errorref)) {
3888: if ($$errorref) {
3889: return;
3890: }
3891: }
3892:
1.556 weissno 3893: my @fields=(['ID','Student/Employee ID'],
1.243 albertel 3894: ['username','Student Username'],
3895: ['domain','Student Domain']);
1.324 albertel 3896: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.41 ng 3897: foreach my $part (sort(@parts)) {
3898: my @datum;
3899: my $display=&Apache::lonnet::metadata($url,$part.'.display');
3900: my $name=$part;
3901: if (!$display) { $display = $name; }
3902: @datum=($name,$display);
1.244 albertel 3903: if ($name=~/^stores_(.*)_awarded/) {
3904: push(@fields,['stores_'.$1.'_points',"Points [Part: $1]"]);
3905: }
1.41 ng 3906: push(@fields,\@datum);
3907: }
3908: return (@fields);
1.26 albertel 3909: }
3910:
3911: sub csvuploadmap_footer {
1.41 ng 3912: my ($request,$i,$keyfields) =@_;
3913: $request->print(<<ENDPICK);
1.26 albertel 3914: </table>
3915: <input type="hidden" name="nfields" value="$i" />
3916: <input type="hidden" name="keyfields" value="$keyfields" />
1.589 bisitz 3917: <input type="button" onclick="javascript:verify(this.form)" value="Assign Grades" /><br />
1.26 albertel 3918: </form>
3919: ENDPICK
3920: }
3921:
1.283 albertel 3922: sub checkforfile_js {
1.539 riegler 3923: my $alertmsg = &mt('Please use the browse button to select a file from your local directory.');
1.86 ng 3924: my $result =<<CSVFORMJS;
3925: <script type="text/javascript" language="javascript">
3926: function checkUpload(formname) {
3927: if (formname.upfile.value == "") {
1.539 riegler 3928: alert("$alertmsg");
1.86 ng 3929: return false;
3930: }
3931: formname.submit();
3932: }
3933: </script>
3934: CSVFORMJS
1.283 albertel 3935: return $result;
3936: }
3937:
3938: sub upcsvScores_form {
3939: my ($request) = shift;
1.324 albertel 3940: my ($symb)=&get_symb($request);
1.283 albertel 3941: if (!$symb) {return '';}
3942: my $result=&checkforfile_js();
1.257 albertel 3943: $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
1.324 albertel 3944: my ($table) = &showResourceInfo($symb,$env{'form.probTitle'});
1.118 ng 3945: $result.=$table;
1.326 albertel 3946: $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
3947: $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
1.538 schulted 3948: $result.=' <b>'.&mt('Specify a file containing the class scores for current resource.').
3949: '</b></td></tr>'."\n";
1.86 ng 3950: $result.='<tr bgcolor=#ffffe6><td>'."\n";
1.370 www 3951: my $upload=&mt("Upload Scores");
1.86 ng 3952: my $upfile_select=&Apache::loncommon::upfile_select_html();
1.245 albertel 3953: my $ignore=&mt('Ignore First Line');
1.418 albertel 3954: $symb = &Apache::lonenc::check_encrypt($symb);
1.86 ng 3955: $result.=<<ENDUPFORM;
1.106 albertel 3956: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.86 ng 3957: <input type="hidden" name="symb" value="$symb" />
3958: <input type="hidden" name="command" value="csvuploadmap" />
1.257 albertel 3959: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
3960: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
1.86 ng 3961: $upfile_select
1.589 bisitz 3962: <br /><input type="button" onclick="javascript:checkUpload(this.form);" value="$upload" />
1.283 albertel 3963: <label><input type="checkbox" name="noFirstLine" />$ignore</label>
1.86 ng 3964: </form>
3965: ENDUPFORM
1.370 www 3966: $result.=&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
3967: &mt("How do I create a CSV file from a spreadsheet"))
3968: .'</td></tr></table>'."\n";
1.86 ng 3969: $result.='</td></tr></table><br /><br />'."\n";
1.324 albertel 3970: $result.=&show_grading_menu_form($symb);
1.86 ng 3971: return $result;
3972: }
3973:
3974:
1.26 albertel 3975: sub csvuploadmap {
1.41 ng 3976: my ($request)= @_;
1.324 albertel 3977: my ($symb)=&get_symb($request);
1.41 ng 3978: if (!$symb) {return '';}
1.72 ng 3979:
1.41 ng 3980: my $datatoken;
1.257 albertel 3981: if (!$env{'form.datatoken'}) {
1.41 ng 3982: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 3983: } else {
1.257 albertel 3984: $datatoken=$env{'form.datatoken'};
1.41 ng 3985: &Apache::loncommon::load_tmp_file($request);
1.26 albertel 3986: }
1.41 ng 3987: my @records=&Apache::loncommon::upfile_record_sep();
1.257 albertel 3988: if ($env{'form.noFirstLine'}) { shift(@records); }
1.324 albertel 3989: &csvuploadmap_header($request,$symb,$datatoken,$#records+1);
1.41 ng 3990: my ($i,$keyfields);
3991: if (@records) {
1.582 raeburn 3992: my $fieldserror;
3993: my @fields=&csvupload_fields($symb,\$fieldserror);
3994: if ($fieldserror) {
3995: $request->print(&navmap_errormsg());
3996: return;
3997: }
1.257 albertel 3998: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3999: &Apache::loncommon::csv_print_samples($request,\@records);
4000: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
4001: \@fields);
4002: foreach (@fields) { $keyfields.=$_->[0].','; }
4003: chop($keyfields);
4004: } else {
4005: unshift(@fields,['none','']);
4006: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
4007: \@fields);
1.311 banghart 4008: foreach my $rec (@records) {
4009: my %temp = &Apache::loncommon::record_sep($rec);
4010: if (%temp) {
4011: $keyfields=join(',',sort(keys(%temp)));
4012: last;
4013: }
4014: }
1.41 ng 4015: }
4016: }
4017: &csvuploadmap_footer($request,$i,$keyfields);
1.324 albertel 4018: $request->print(&show_grading_menu_form($symb));
1.72 ng 4019:
1.41 ng 4020: return '';
1.27 albertel 4021: }
4022:
1.246 albertel 4023: sub csvuploadoptions {
1.41 ng 4024: my ($request)= @_;
1.324 albertel 4025: my ($symb)=&get_symb($request);
1.257 albertel 4026: my $checked=(($env{'form.noFirstLine'})?'1':'0');
1.246 albertel 4027: my $ignore=&mt('Ignore First Line');
4028: $request->print(<<ENDPICK);
4029: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.398 albertel 4030: <h3><span class="LC_info">Uploading Class Grade Options</span></h3>
1.246 albertel 4031: <input type="hidden" name="command" value="csvuploadassign" />
1.302 albertel 4032: <!--
1.246 albertel 4033: <p>
4034: <label>
4035: <input type="checkbox" name="show_full_results" />
4036: Show a table of all changes
4037: </label>
4038: </p>
1.302 albertel 4039: -->
1.246 albertel 4040: <p>
4041: <label>
4042: <input type="checkbox" name="overwite_scores" checked="checked" />
4043: Overwrite any existing score
4044: </label>
4045: </p>
4046: ENDPICK
4047: my %fields=&get_fields();
4048: if (!defined($fields{'domain'})) {
1.257 albertel 4049: my $domform = &Apache::loncommon::select_dom_form($env{'request.role.domain'},'default_domain');
1.246 albertel 4050: $request->print("\n<p> Users are in domain: ".$domform."</p>\n");
4051: }
1.257 albertel 4052: foreach my $key (sort(keys(%env))) {
1.246 albertel 4053: if ($key !~ /^form\.(.*)$/) { next; }
4054: my $cleankey=$1;
4055: if ($cleankey eq 'command') { next; }
4056: $request->print('<input type="hidden" name="'.$cleankey.
1.257 albertel 4057: '" value="'.$env{$key}.'" />'."\n");
1.246 albertel 4058: }
4059: # FIXME do a check for any duplicated user ids...
4060: # FIXME do a check for any invalid user ids?...
1.290 albertel 4061: $request->print('<input type="submit" value="Assign Grades" /><br />
4062: <hr /></form>'."\n");
1.324 albertel 4063: $request->print(&show_grading_menu_form($symb));
1.246 albertel 4064: return '';
4065: }
4066:
4067: sub get_fields {
4068: my %fields;
1.257 albertel 4069: my @keyfields = split(/\,/,$env{'form.keyfields'});
4070: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
4071: if ($env{'form.upfile_associate'} eq 'reverse') {
4072: if ($env{'form.f'.$i} ne 'none') {
4073: $fields{$keyfields[$i]}=$env{'form.f'.$i};
1.41 ng 4074: }
4075: } else {
1.257 albertel 4076: if ($env{'form.f'.$i} ne 'none') {
4077: $fields{$env{'form.f'.$i}}=$keyfields[$i];
1.41 ng 4078: }
4079: }
1.27 albertel 4080: }
1.246 albertel 4081: return %fields;
4082: }
4083:
4084: sub csvuploadassign {
4085: my ($request)= @_;
1.324 albertel 4086: my ($symb)=&get_symb($request);
1.246 albertel 4087: if (!$symb) {return '';}
1.345 bowersj2 4088: my $error_msg = '';
1.246 albertel 4089: &Apache::loncommon::load_tmp_file($request);
4090: my @gradedata = &Apache::loncommon::upfile_record_sep();
1.257 albertel 4091: if ($env{'form.noFirstLine'}) { shift(@gradedata); }
1.246 albertel 4092: my %fields=&get_fields();
1.41 ng 4093: $request->print('<h3>Assigning Grades</h3>');
1.257 albertel 4094: my $courseid=$env{'request.course.id'};
1.97 albertel 4095: my ($classlist) = &getclasslist('all',0);
1.106 albertel 4096: my @notallowed;
1.41 ng 4097: my @skipped;
4098: my $countdone=0;
4099: foreach my $grade (@gradedata) {
4100: my %entries=&Apache::loncommon::record_sep($grade);
1.246 albertel 4101: my $domain;
4102: if ($entries{$fields{'domain'}}) {
4103: $domain=$entries{$fields{'domain'}};
4104: } else {
1.257 albertel 4105: $domain=$env{'form.default_domain'};
1.246 albertel 4106: }
1.243 albertel 4107: $domain=~s/\s//g;
1.41 ng 4108: my $username=$entries{$fields{'username'}};
1.160 albertel 4109: $username=~s/\s//g;
1.243 albertel 4110: if (!$username) {
4111: my $id=$entries{$fields{'ID'}};
1.247 albertel 4112: $id=~s/\s//g;
1.243 albertel 4113: my %ids=&Apache::lonnet::idget($domain,$id);
4114: $username=$ids{$id};
4115: }
1.41 ng 4116: if (!exists($$classlist{"$username:$domain"})) {
1.247 albertel 4117: my $id=$entries{$fields{'ID'}};
4118: $id=~s/\s//g;
4119: if ($id) {
4120: push(@skipped,"$id:$domain");
4121: } else {
4122: push(@skipped,"$username:$domain");
4123: }
1.41 ng 4124: next;
4125: }
1.108 albertel 4126: my $usec=$classlist->{"$username:$domain"}[5];
1.106 albertel 4127: if (!&canmodify($usec)) {
4128: push(@notallowed,"$username:$domain");
4129: next;
4130: }
1.244 albertel 4131: my %points;
1.41 ng 4132: my %grades;
4133: foreach my $dest (keys(%fields)) {
1.244 albertel 4134: if ($dest eq 'ID' || $dest eq 'username' ||
4135: $dest eq 'domain') { next; }
4136: if ($entries{$fields{$dest}} =~ /^\s*$/) { next; }
4137: if ($dest=~/stores_(.*)_points/) {
4138: my $part=$1;
4139: my $wgt =&Apache::lonnet::EXT('resource.'.$part.'.weight',
4140: $symb,$domain,$username);
1.345 bowersj2 4141: if ($wgt) {
4142: $entries{$fields{$dest}}=~s/\s//g;
4143: my $pcr=$entries{$fields{$dest}} / $wgt;
1.463 albertel 4144: my $award=($pcr == 0) ? 'incorrect_by_override'
4145: : 'correct_by_override';
1.345 bowersj2 4146: $grades{"resource.$part.awarded"}=$pcr;
4147: $grades{"resource.$part.solved"}=$award;
4148: $points{$part}=1;
4149: } else {
4150: $error_msg = "<br />" .
4151: &mt("Some point values were assigned"
4152: ." for problems with a weight "
4153: ."of zero. These values were "
4154: ."ignored.");
4155: }
1.244 albertel 4156: } else {
4157: if ($dest=~/stores_(.*)_awarded/) { if ($points{$1}) {next;} }
4158: if ($dest=~/stores_(.*)_solved/) { if ($points{$1}) {next;} }
4159: my $store_key=$dest;
4160: $store_key=~s/^stores/resource/;
4161: $store_key=~s/_/\./g;
4162: $grades{$store_key}=$entries{$fields{$dest}};
4163: }
1.41 ng 4164: }
1.508 www 4165: if (! %grades) {
4166: push(@skipped,&mt("[_1]: no data to save","$username:$domain"));
4167: } else {
4168: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
4169: my $result=&Apache::lonnet::cstore(\%grades,$symb,
1.302 albertel 4170: $env{'request.course.id'},
4171: $domain,$username);
1.508 www 4172: if ($result eq 'ok') {
4173: $request->print('.');
4174: } else {
4175: $request->print("<p><span class=\"LC_error\">".
4176: &mt("Failed to save data for student [_1]. Message when trying to save was: [_2]",
4177: "$username:$domain",$result)."</span></p>");
4178: }
4179: $request->rflush();
4180: $countdone++;
4181: }
1.41 ng 4182: }
1.570 www 4183: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt("Saved scores for [quant,_1,student]",$countdone),$countdone==0));
1.41 ng 4184: if (@skipped) {
1.571 www 4185: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('No scores stored for the following username(s):'),1).'<br />');
4186: $request->print(join(', ',@skipped));
1.106 albertel 4187: }
4188: if (@notallowed) {
1.571 www 4189: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('Modification of scores not allowed for the following username(s):'),1).'<br />');
4190: $request->print(join(', ',@notallowed));
1.41 ng 4191: }
1.106 albertel 4192: $request->print("<br />\n");
1.324 albertel 4193: $request->print(&show_grading_menu_form($symb));
1.345 bowersj2 4194: return $error_msg;
1.26 albertel 4195: }
1.44 ng 4196: #------------- end of section for handling csv file upload ---------
4197: #
4198: #-------------------------------------------------------------------
4199: #
1.122 ng 4200: #-------------- Next few routines handle grading by page/sequence
1.72 ng 4201: #
4202: #--- Select a page/sequence and a student to grade
1.68 ng 4203: sub pickStudentPage {
4204: my ($request) = shift;
4205:
1.539 riegler 4206: my $alertmsg = &mt('Please select the student you wish to grade.');
1.68 ng 4207: $request->print(<<LISTJAVASCRIPT);
4208: <script type="text/javascript" language="javascript">
4209:
4210: function checkPickOne(formname) {
1.76 ng 4211: if (radioSelection(formname.student) == null) {
1.539 riegler 4212: alert("$alertmsg");
1.68 ng 4213: return;
4214: }
1.125 ng 4215: ptr = pullDownSelection(formname.selectpage);
4216: formname.page.value = formname["page"+ptr].value;
4217: formname.title.value = formname["title"+ptr].value;
1.68 ng 4218: formname.submit();
4219: }
4220:
4221: </script>
4222: LISTJAVASCRIPT
1.118 ng 4223: &commonJSfunctions($request);
1.324 albertel 4224: my ($symb) = &get_symb($request);
1.257 albertel 4225: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4226: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4227: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.68 ng 4228:
1.398 albertel 4229: my $result='<h3><span class="LC_info"> '.
1.485 albertel 4230: &mt('Manual Grading by Page or Sequence').'</span></h3>';
1.68 ng 4231:
1.80 ng 4232: $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
1.582 raeburn 4233: my $map_error;
4234: my ($titles,$symbx) = &getSymbMap($map_error);
4235: if ($map_error) {
4236: $request->print(&navmap_errormsg());
4237: return;
4238: }
1.137 albertel 4239: my ($curpage) =&Apache::lonnet::decode_symb($symb);
4240: # my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb);
4241: # my $type=($curpage =~ /\.(page|sequence)/);
1.485 albertel 4242: my $select = '<select name="selectpage">'."\n";
1.70 ng 4243: my $ctr=0;
1.68 ng 4244: foreach (@$titles) {
4245: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.485 albertel 4246: $select.='<option value="'.$ctr.'" '.
1.401 albertel 4247: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.71 ng 4248: '>'.$showtitle.'</option>'."\n";
1.70 ng 4249: $ctr++;
1.68 ng 4250: }
1.485 albertel 4251: $select.= '</select>';
1.539 riegler 4252: $result.=' <b>'.&mt('Problems from').':</b> '.$select."<br />\n";
1.485 albertel 4253:
1.70 ng 4254: $ctr=0;
4255: foreach (@$titles) {
4256: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
4257: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
4258: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
4259: $ctr++;
4260: }
1.72 ng 4261: $result.='<input type="hidden" name="page" />'."\n".
4262: '<input type="hidden" name="title" />'."\n";
1.68 ng 4263:
1.485 albertel 4264: my $options =
4265: '<label><input type="radio" name="vProb" value="no" checked="checked" /> '.&mt('no').' </label>'."\n".
4266: '<label><input type="radio" name="vProb" value="yes" /> '.&mt('yes').' </label>'."<br />\n";
1.539 riegler 4267: $result.=' <b>'.&mt('View Problem Text').': </b>'.$options;
1.485 albertel 4268:
4269: $options =
4270: '<label><input type="radio" name="lastSub" value="none" /> '.&mt('none').' </label>'."\n".
4271: '<label><input type="radio" name="lastSub" value="datesub" checked="checked" /> '.&mt('by dates and submissions').'</label>'."\n".
4272: '<label><input type="radio" name="lastSub" value="all" /> '.&mt('all details').' </label>'."\n";
1.539 riegler 4273: $result.=' <b>'.&mt('Submissions').': </b>'.$options;
1.432 banghart 4274:
4275: $result.=&build_section_inputs();
1.442 banghart 4276: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
4277: $result.='<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.72 ng 4278: '<input type="hidden" name="command" value="displayPage" />'."\n".
1.418 albertel 4279: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 4280: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."<br />\n";
1.72 ng 4281:
1.539 riegler 4282: $result.=' <b>'.&mt('Use CODE').': </b> <input type="text" name="CODE" value="" /> <br />'."\n";
1.382 albertel 4283:
1.80 ng 4284: $result.=' <input type="button" '.
1.589 bisitz 4285: 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /><br />'."\n";
1.72 ng 4286:
1.68 ng 4287: $request->print($result);
4288:
1.485 albertel 4289: my $studentTable.=' <b>'.&mt('Select a student you wish to grade and then click on the Next button.').'</b><br />'.
1.484 albertel 4290: &Apache::loncommon::start_data_table().
4291: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 4292: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 4293: '<th>'.&nameUserString('header').'</th>'.
1.485 albertel 4294: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 4295: '<th>'.&nameUserString('header').'</th>'.
4296: &Apache::loncommon::end_data_table_header_row();
1.68 ng 4297:
1.76 ng 4298: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.68 ng 4299: my $ptr = 1;
1.294 albertel 4300: foreach my $student (sort
4301: {
4302: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
4303: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
4304: }
4305: return $a cmp $b;
4306: } (keys(%$fullname))) {
1.68 ng 4307: my ($uname,$udom) = split(/:/,$student);
1.484 albertel 4308: $studentTable.=($ptr%2==1 ? &Apache::loncommon::start_data_table_row()
4309: : '</td>');
1.126 ng 4310: $studentTable.='<td align="right">'.$ptr.' </td>';
1.288 albertel 4311: $studentTable.='<td> <label><input type="radio" name="student" value="'.$student.'" /> '
4312: .&nameUserString(undef,$$fullname{$student},$uname,$udom)."</label>\n";
1.484 albertel 4313: $studentTable.=
4314: ($ptr%2 == 0 ? '</td>'.&Apache::loncommon::end_data_table_row()
4315: : '');
1.68 ng 4316: $ptr++;
4317: }
1.484 albertel 4318: if ($ptr%2 == 0) {
4319: $studentTable.='</td><td> </td><td> </td>'.
4320: &Apache::loncommon::end_data_table_row();
4321: }
4322: $studentTable.=&Apache::loncommon::end_data_table()."\n";
1.126 ng 4323: $studentTable.='<input type="button" '.
1.589 bisitz 4324: 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /></form>'."\n";
1.68 ng 4325:
1.324 albertel 4326: $studentTable.=&show_grading_menu_form($symb);
1.68 ng 4327: $request->print($studentTable);
4328:
4329: return '';
4330: }
4331:
4332: sub getSymbMap {
1.582 raeburn 4333: my ($map_error) = @_;
1.132 bowersj2 4334: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 4335: unless (ref($navmap)) {
4336: if (ref($map_error)) {
4337: $$map_error = 'navmap';
4338: }
4339: return;
4340: }
1.68 ng 4341: my %symbx = ();
4342: my @titles = ();
1.117 bowersj2 4343: my $minder = 0;
4344:
4345: # Gather every sequence that has problems.
1.240 albertel 4346: my @sequences = $navmap->retrieveResources(undef, sub { shift->is_map(); },
4347: 1,0,1);
1.117 bowersj2 4348: for my $sequence ($navmap->getById('0.0'), @sequences) {
1.241 albertel 4349: if ($navmap->hasResource($sequence, sub { shift->is_problem(); }, 0) ) {
1.381 albertel 4350: my $title = $minder.'.'.
4351: &HTML::Entities::encode($sequence->compTitle(),'"\'&');
4352: push(@titles, $title); # minder in case two titles are identical
4353: $symbx{$title} = &HTML::Entities::encode($sequence->symb(),'"\'&');
1.117 bowersj2 4354: $minder++;
1.241 albertel 4355: }
1.68 ng 4356: }
4357: return \@titles,\%symbx;
4358: }
4359:
1.72 ng 4360: #
4361: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68 ng 4362: sub displayPage {
4363: my ($request) = shift;
4364:
1.324 albertel 4365: my ($symb) = &get_symb($request);
1.257 albertel 4366: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4367: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4368: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
4369: my $pageTitle = $env{'form.page'};
1.103 albertel 4370: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 4371: my ($uname,$udom) = split(/:/,$env{'form.student'});
4372: my $usec=$classlist->{$env{'form.student'}}[5];
1.168 albertel 4373:
4374: #need to make sure we have the correct data for later EXT calls,
4375: #thus invalidate the cache
4376: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 4377: $env{'course.'.$env{'request.course.id'}.'.num'},
4378: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 4379: &Apache::lonnet::clear_EXT_cache_status();
4380:
1.103 albertel 4381: if (!&canview($usec)) {
1.485 albertel 4382: $request->print('<span class="LC_warning">'.&mt('Unable to view requested student. ([_1])',$env{'form.student'}).'</span>');
1.324 albertel 4383: $request->print(&show_grading_menu_form($symb));
1.103 albertel 4384: return;
4385: }
1.398 albertel 4386: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.485 albertel 4387: $result.='<h3> '.&mt('Student: [_1]',&nameUserString(undef,$$fullname{$env{'form.student'}},$uname,$udom)).
1.129 ng 4388: '</h3>'."\n";
1.500 albertel 4389: $env{'form.CODE'} = uc($env{'form.CODE'});
1.501 foxr 4390: if (&Apache::lonnet::validCODE(uc($env{'form.CODE'}))) {
1.485 albertel 4391: $result.='<h3> '.&mt('CODE: [_1]',$env{'form.CODE'}).'</h3>'."\n";
1.382 albertel 4392: } else {
4393: delete($env{'form.CODE'});
4394: }
1.71 ng 4395: &sub_page_js($request);
4396: $request->print($result);
4397:
1.132 bowersj2 4398: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 4399: unless (ref($navmap)) {
4400: $request->print(&navmap_errormsg());
4401: $request->print(&show_grading_menu_form($symb));
4402: return;
4403: }
1.257 albertel 4404: my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($env{'form.page'});
1.68 ng 4405: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 4406: if (!$map) {
1.485 albertel 4407: $request->print('<span class="LC_warning">'.&mt('Unable to view requested sequence. ([_1])',$resUrl).'</span>');
1.324 albertel 4408: $request->print(&show_grading_menu_form($symb));
1.288 albertel 4409: return;
4410: }
1.68 ng 4411: my $iterator = $navmap->getIterator($map->map_start(),
4412: $map->map_finish());
4413:
1.71 ng 4414: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72 ng 4415: '<input type="hidden" name="command" value="gradeByPage" />'."\n".
1.257 albertel 4416: '<input type="hidden" name="fullname" value="'.$$fullname{$env{'form.student'}}.'" />'."\n".
4417: '<input type="hidden" name="student" value="'.$env{'form.student'}.'" />'."\n".
1.72 ng 4418: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
1.257 albertel 4419: '<input type="hidden" name="title" value="'.$env{'form.title'}.'" />'."\n".
1.418 albertel 4420: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.125 ng 4421: '<input type="hidden" name="overRideScore" value="no" />'."\n".
1.257 albertel 4422: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n";
1.71 ng 4423:
1.382 albertel 4424: if (defined($env{'form.CODE'})) {
4425: $studentTable.=
4426: '<input type="hidden" name="CODE" value="'.$env{'form.CODE'}.'" />'."\n";
4427: }
1.381 albertel 4428: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 4429: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 4430:
1.485 albertel 4431: $studentTable.=' '.&mt('<b>Note:</b> Problems graded correct by the computer are marked with a [_1] symbol.',$checkIcon)."\n".
1.484 albertel 4432: &Apache::loncommon::start_data_table().
4433: &Apache::loncommon::start_data_table_header_row().
4434: '<th align="center"> Prob. </th>'.
1.485 albertel 4435: '<th> '.($env{'form.vProb'} eq 'no' ? &mt('Title') : &mt('Problem Text')).'/'.&mt('Grade').'</th>'.
1.484 albertel 4436: &Apache::loncommon::end_data_table_header_row();
1.71 ng 4437:
1.329 albertel 4438: &Apache::lonxml::clear_problem_counter();
1.196 albertel 4439: my ($depth,$question,$prob) = (1,1,1);
1.68 ng 4440: $iterator->next(); # skip the first BEGIN_MAP
4441: my $curRes = $iterator->next(); # for "current resource"
1.101 albertel 4442: while ($depth > 0) {
1.68 ng 4443: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4444: if($curRes == $iterator->END_MAP) { $depth--; }
1.68 ng 4445:
1.385 albertel 4446: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4447: my $parts = $curRes->parts();
1.68 ng 4448: my $title = $curRes->compTitle();
1.71 ng 4449: my $symbx = $curRes->symb();
1.484 albertel 4450: $studentTable.=
4451: &Apache::loncommon::start_data_table_row().
4452: '<td align="center" valign="top" >'.$prob.
1.485 albertel 4453: (scalar(@{$parts}) == 1 ? ''
4454: : '<br />('.&mt('[_1] parts)',
4455: scalar(@{$parts}))
4456: ).
4457: '</td>';
1.71 ng 4458: $studentTable.='<td valign="top">';
1.382 albertel 4459: my %form = ('CODE' => $env{'form.CODE'},);
1.257 albertel 4460: if ($env{'form.vProb'} eq 'yes' ) {
1.144 albertel 4461: $studentTable.=&show_problem($request,$symbx,$uname,$udom,1,
1.383 albertel 4462: undef,'both',\%form);
1.71 ng 4463: } else {
1.382 albertel 4464: my $companswer = &Apache::loncommon::get_student_answers($symbx,$uname,$udom,$env{'request.course.id'},%form);
1.80 ng 4465: $companswer =~ s|<form(.*?)>||g;
4466: $companswer =~ s|</form>||g;
1.71 ng 4467: # while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
1.116 ng 4468: # $companswer =~ s/$1/ /ms;
1.326 albertel 4469: # $request->print('match='.$1."<br />\n");
1.71 ng 4470: # }
1.116 ng 4471: # $companswer =~ s|<table border=\"1\">|<table border=\"0\">|g;
1.539 riegler 4472: $studentTable.=' <b>'.$title.'</b> <br /> <b>'.&mt('Correct answer').':</b><br />'.$companswer;
1.71 ng 4473: }
4474:
1.257 albertel 4475: my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
1.125 ng 4476:
1.257 albertel 4477: if ($env{'form.lastSub'} eq 'datesub') {
1.71 ng 4478: if ($record{'version'} eq '') {
1.485 albertel 4479: $studentTable.='<br /> <span class="LC_warning">'.&mt('No recorded submission for this problem.').'</span><br />';
1.71 ng 4480: } else {
1.116 ng 4481: my %responseType = ();
4482: foreach my $partid (@{$parts}) {
1.147 albertel 4483: my @responseIds =$curRes->responseIds($partid);
4484: my @responseType =$curRes->responseType($partid);
4485: my %responseIds;
4486: for (my $i=0;$i<=$#responseIds;$i++) {
4487: $responseIds{$responseIds[$i]}=$responseType[$i];
4488: }
4489: $responseType{$partid} = \%responseIds;
1.116 ng 4490: }
1.148 albertel 4491: $studentTable.= &displaySubByDates($symbx,\%record,$parts,\%responseType,$checkIcon,$uname,$udom);
1.147 albertel 4492:
1.71 ng 4493: }
1.257 albertel 4494: } elsif ($env{'form.lastSub'} eq 'all') {
4495: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.71 ng 4496: $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
1.257 albertel 4497: $env{'request.course.id'},
1.71 ng 4498: '','.submission');
4499:
4500: }
1.103 albertel 4501: if (&canmodify($usec)) {
1.585 bisitz 4502: $studentTable.=&gradeBox_start();
1.103 albertel 4503: foreach my $partid (@{$parts}) {
4504: $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
4505: $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
4506: $question++;
4507: }
1.585 bisitz 4508: $studentTable.=&gradeBox_end();
1.196 albertel 4509: $prob++;
1.71 ng 4510: }
4511: $studentTable.='</td></tr>';
1.68 ng 4512:
1.103 albertel 4513: }
1.68 ng 4514: $curRes = $iterator->next();
4515: }
4516:
1.589 bisitz 4517: $studentTable.=
4518: '</table>'."\n".
4519: '<input type="button" value="'.&mt('Save').'" '.
4520: 'onclick="javascript:checkSubmitPage(this.form,'.$question.');" />'.
4521: '</form>'."\n";
1.324 albertel 4522: $studentTable.=&show_grading_menu_form($symb);
1.71 ng 4523: $request->print($studentTable);
4524:
4525: return '';
1.119 ng 4526: }
4527:
4528: sub displaySubByDates {
1.148 albertel 4529: my ($symb,$record,$parts,$responseType,$checkIcon,$uname,$udom) = @_;
1.224 albertel 4530: my $isCODE=0;
1.335 albertel 4531: my $isTask = ($symb =~/\.task$/);
1.224 albertel 4532: if (exists($record->{'resource.CODE'})) { $isCODE=1; }
1.467 albertel 4533: my $studentTable=&Apache::loncommon::start_data_table().
4534: &Apache::loncommon::start_data_table_header_row().
4535: '<th>'.&mt('Date/Time').'</th>'.
4536: ($isCODE?'<th>'.&mt('CODE').'</th>':'').
4537: '<th>'.&mt('Submission').'</th>'.
4538: '<th>'.&mt('Status').'</th>'.
4539: &Apache::loncommon::end_data_table_header_row();
1.119 ng 4540: my ($version);
4541: my %mark;
1.148 albertel 4542: my %orders;
1.119 ng 4543: $mark{'correct_by_student'} = $checkIcon;
1.147 albertel 4544: if (!exists($$record{'1:timestamp'})) {
1.539 riegler 4545: return '<br /> <span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br />';
1.147 albertel 4546: }
1.335 albertel 4547:
4548: my $interaction;
1.525 raeburn 4549: my $no_increment = 1;
1.119 ng 4550: for ($version=1;$version<=$$record{'version'};$version++) {
1.467 albertel 4551: my $timestamp =
4552: &Apache::lonlocal::locallocaltime($$record{$version.':timestamp'});
1.335 albertel 4553: if (exists($$record{$version.':resource.0.version'})) {
4554: $interaction = $$record{$version.':resource.0.version'};
4555: }
4556:
4557: my $where = ($isTask ? "$version:resource.$interaction"
4558: : "$version:resource");
1.467 albertel 4559: $studentTable.=&Apache::loncommon::start_data_table_row().
4560: '<td>'.$timestamp.'</td>';
1.224 albertel 4561: if ($isCODE) {
4562: $studentTable.='<td>'.$record->{$version.':resource.CODE'}.'</td>';
4563: }
1.119 ng 4564: my @versionKeys = split(/\:/,$$record{$version.':keys'});
4565: my @displaySub = ();
4566: foreach my $partid (@{$parts}) {
1.335 albertel 4567: my @matchKey = ($isTask ? sort(grep /^resource\.\d+\.\Q$partid\E\.award$/,@versionKeys)
4568: : sort(grep /^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys));
4569:
4570:
1.122 ng 4571: # next if ($$record{"$version:resource.$partid.solved"} eq '');
1.324 albertel 4572: my $display_part=&get_display_part($partid,$symb);
1.147 albertel 4573: foreach my $matchKey (@matchKey) {
1.198 albertel 4574: if (exists($$record{$version.':'.$matchKey}) &&
4575: $$record{$version.':'.$matchKey} ne '') {
1.335 albertel 4576:
4577: my ($responseId)= ($isTask ? ($matchKey=~ /^resource\.(.*?)\.\Q$partid\E\.award$/)
4578: : ($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/));
1.577 bisitz 4579: $displaySub[0].='<span class="LC_nobreak"';
4580: $displaySub[0].='<b>'.&mt('Part: [_1]',$display_part).'</b>'
4581: .' <span class="LC_internal_info">'
4582: .'('.&mt('Part ID: [_1]',$responseId).')'
4583: .'</span>'
4584: .' <b>';
1.335 albertel 4585: if ($$record{"$where.$partid.tries"} eq '') {
1.577 bisitz 4586: $displaySub[0].=&mt('Trial not counted');
1.147 albertel 4587: } else {
1.577 bisitz 4588: $displaySub[0].=&mt('Trial: [_1]',
1.467 albertel 4589: $$record{"$where.$partid.tries"});
1.147 albertel 4590: }
1.335 albertel 4591: my $responseType=($isTask ? 'Task'
4592: : $responseType->{$partid}->{$responseId});
1.148 albertel 4593: if (!exists($orders{$partid})) { $orders{$partid}={}; }
4594: if (!exists($orders{$partid}->{$responseId})) {
4595: $orders{$partid}->{$responseId}=
1.525 raeburn 4596: &get_order($partid,$responseId,$symb,$uname,$udom,
4597: $no_increment);
1.148 albertel 4598: }
1.577 bisitz 4599: $displaySub[0].='</b></span>'; # /nobreak
4600: $displaySub[0].=' '.
1.336 albertel 4601: &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:",$uname,$udom).'<br />';
1.147 albertel 4602: }
4603: }
1.335 albertel 4604: if (exists($$record{"$where.$partid.checkedin"})) {
1.485 albertel 4605: $displaySub[1].=&mt('Checked in by [_1] into slot [_2]',
4606: $$record{"$where.$partid.checkedin"},
4607: $$record{"$where.$partid.checkedin.slot"}).
4608: '<br />';
1.335 albertel 4609: }
4610: if (exists $$record{"$where.$partid.award"}) {
1.485 albertel 4611: $displaySub[1].='<b>'.&mt('Part:').'</b> '.$display_part.' '.
1.335 albertel 4612: lc($$record{"$where.$partid.award"}).' '.
4613: $mark{$$record{"$where.$partid.solved"}}.
1.147 albertel 4614: '<br />';
4615: }
1.335 albertel 4616: if (exists $$record{"$where.$partid.regrader"}) {
4617: $displaySub[2].=$$record{"$where.$partid.regrader"}.
4618: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
4619: } elsif ($$record{"$version:resource.$partid.regrader"} =~ /\S/) {
4620: $displaySub[2].=
4621: $$record{"$version:resource.$partid.regrader"}.
1.207 albertel 4622: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
1.147 albertel 4623: }
4624: }
4625: # needed because old essay regrader has not parts info
4626: if (exists $$record{"$version:resource.regrader"}) {
4627: $displaySub[2].=$$record{"$version:resource.regrader"};
4628: }
4629: $studentTable.='<td>'.$displaySub[0].' </td><td>'.$displaySub[1];
4630: if ($displaySub[2]) {
1.467 albertel 4631: $studentTable.=&mt('Manually graded by [_1]',$displaySub[2]);
1.147 albertel 4632: }
1.467 albertel 4633: $studentTable.=' </td>'.
4634: &Apache::loncommon::end_data_table_row();
1.119 ng 4635: }
1.467 albertel 4636: $studentTable.=&Apache::loncommon::end_data_table();
1.119 ng 4637: return $studentTable;
1.71 ng 4638: }
4639:
4640: sub updateGradeByPage {
4641: my ($request) = shift;
4642:
1.257 albertel 4643: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4644: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4645: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
4646: my $pageTitle = $env{'form.page'};
1.103 albertel 4647: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 4648: my ($uname,$udom) = split(/:/,$env{'form.student'});
4649: my $usec=$classlist->{$env{'form.student'}}[5];
1.103 albertel 4650: if (!&canmodify($usec)) {
1.526 raeburn 4651: $request->print('<span class="LC_warning">'.&mt('Unable to modify requested student ([_1])',$env{'form.student'}).'</span>');
1.324 albertel 4652: $request->print(&show_grading_menu_form($env{'form.symb'}));
1.103 albertel 4653: return;
4654: }
1.398 albertel 4655: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.526 raeburn 4656: $result.='<h3> '.&mt('Student: ').&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
1.129 ng 4657: '</h3>'."\n";
1.70 ng 4658:
1.68 ng 4659: $request->print($result);
4660:
1.582 raeburn 4661:
1.132 bowersj2 4662: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 4663: unless (ref($navmap)) {
4664: $request->print(&navmap_errormsg());
4665: return;
4666: }
1.257 albertel 4667: my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $env{'form.page'});
1.71 ng 4668: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 4669: if (!$map) {
1.527 raeburn 4670: $request->print('<span class="LC_warning">'.&mt('Unable to grade requested sequence ([_1]).',$resUrl).'</span>');
1.324 albertel 4671: my ($symb)=&get_symb($request);
4672: $request->print(&show_grading_menu_form($symb));
1.288 albertel 4673: return;
4674: }
1.71 ng 4675: my $iterator = $navmap->getIterator($map->map_start(),
4676: $map->map_finish());
1.70 ng 4677:
1.484 albertel 4678: my $studentTable=
4679: &Apache::loncommon::start_data_table().
4680: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 4681: '<th align="center"> '.&mt('Prob.').' </th>'.
4682: '<th> '.&mt('Title').' </th>'.
4683: '<th> '.&mt('Previous Score').' </th>'.
4684: '<th> '.&mt('New Score').' </th>'.
1.484 albertel 4685: &Apache::loncommon::end_data_table_header_row();
1.71 ng 4686:
4687: $iterator->next(); # skip the first BEGIN_MAP
4688: my $curRes = $iterator->next(); # for "current resource"
1.196 albertel 4689: my ($depth,$question,$prob,$changeflag)= (1,1,1,0);
1.101 albertel 4690: while ($depth > 0) {
1.71 ng 4691: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4692: if($curRes == $iterator->END_MAP) { $depth--; }
1.71 ng 4693:
1.385 albertel 4694: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4695: my $parts = $curRes->parts();
1.71 ng 4696: my $title = $curRes->compTitle();
4697: my $symbx = $curRes->symb();
1.484 albertel 4698: $studentTable.=
4699: &Apache::loncommon::start_data_table_row().
4700: '<td align="center" valign="top" >'.$prob.
1.485 albertel 4701: (scalar(@{$parts}) == 1 ? ''
1.526 raeburn 4702: : '<br />('.&mt('[quant,_1, part]',scalar(@{$parts}))
4703: .')').'</td>';
1.71 ng 4704: $studentTable.='<td valign="top"> <b>'.$title.'</b> </td>';
4705:
4706: my %newrecord=();
4707: my @displayPts=();
1.269 raeburn 4708: my %aggregate = ();
4709: my $aggregateflag = 0;
1.71 ng 4710: foreach my $partid (@{$parts}) {
1.257 albertel 4711: my $newpts = $env{'form.GD_BOX'.$question.'_'.$partid};
4712: my $oldpts = $env{'form.oldpts'.$question.'_'.$partid};
1.71 ng 4713:
1.257 albertel 4714: my $wgt = $env{'form.WGT'.$question.'_'.$partid} != 0 ?
4715: $env{'form.WGT'.$question.'_'.$partid} : 1;
1.71 ng 4716: my $partial = $newpts/$wgt;
4717: my $score;
4718: if ($partial > 0) {
4719: $score = 'correct_by_override';
1.125 ng 4720: } elsif ($newpts ne '') { #empty is taken as 0
1.71 ng 4721: $score = 'incorrect_by_override';
4722: }
1.257 albertel 4723: my $dropMenu = $env{'form.GD_SEL'.$question.'_'.$partid};
1.125 ng 4724: if ($dropMenu eq 'excused') {
1.71 ng 4725: $partial = '';
4726: $score = 'excused';
1.125 ng 4727: } elsif ($dropMenu eq 'reset status'
1.257 albertel 4728: && $env{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
1.125 ng 4729: $newrecord{'resource.'.$partid.'.tries'} = 0;
4730: $newrecord{'resource.'.$partid.'.solved'} = '';
4731: $newrecord{'resource.'.$partid.'.award'} = '';
4732: $newrecord{'resource.'.$partid.'.awarded'} = 0;
1.257 albertel 4733: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 4734: $changeflag++;
4735: $newpts = '';
1.269 raeburn 4736:
4737: my $aggtries = $env{'form.aggtries'.$question.'_'.$partid};
4738: my $totaltries = $env{'form.totaltries'.$question.'_'.$partid};
4739: my $solvedstatus = $env{'form.solved'.$question.'_'.$partid};
4740: if ($aggtries > 0) {
4741: &decrement_aggs($symbx,$partid,\%aggregate,$aggtries,$totaltries,$solvedstatus);
4742: $aggregateflag = 1;
4743: }
1.71 ng 4744: }
1.324 albertel 4745: my $display_part=&get_display_part($partid,$curRes->symb());
1.257 albertel 4746: my $oldstatus = $env{'form.solved'.$question.'_'.$partid};
1.526 raeburn 4747: $displayPts[0].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.71 ng 4748: (($oldstatus eq 'excused') ? 'excused' : $oldpts).
1.326 albertel 4749: ' <br />';
1.526 raeburn 4750: $displayPts[1].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.125 ng 4751: (($score eq 'excused') ? 'excused' : $newpts).
1.326 albertel 4752: ' <br />';
1.71 ng 4753: $question++;
1.380 albertel 4754: next if ($dropMenu eq 'reset status' || ($newpts eq $oldpts && $score ne 'excused'));
1.125 ng 4755:
1.71 ng 4756: $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
1.125 ng 4757: $newrecord{'resource.'.$partid.'.solved'} = $score if $score ne '';
1.257 albertel 4758: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}"
1.125 ng 4759: if (scalar(keys(%newrecord)) > 0);
1.71 ng 4760:
4761: $changeflag++;
4762: }
4763: if (scalar(keys(%newrecord)) > 0) {
1.382 albertel 4764: my %record =
4765: &Apache::lonnet::restore($symbx,$env{'request.course.id'},
4766: $udom,$uname);
4767:
4768: if (&Apache::lonnet::validCODE($env{'form.CODE'})) {
4769: $newrecord{'resource.CODE'} = $env{'form.CODE'};
4770: } elsif (&Apache::lonnet::validCODE($record{'resource.CODE'})) {
4771: $newrecord{'resource.CODE'} = '';
4772: }
1.257 albertel 4773: &Apache::lonnet::cstore(\%newrecord,$symbx,$env{'request.course.id'},
1.71 ng 4774: $udom,$uname);
1.382 albertel 4775: %record = &Apache::lonnet::restore($symbx,
4776: $env{'request.course.id'},
4777: $udom,$uname);
1.380 albertel 4778: &check_and_remove_from_queue($parts,\%record,undef,$symbx,
4779: $cdom,$cnum,$udom,$uname);
1.71 ng 4780: }
1.380 albertel 4781:
1.269 raeburn 4782: if ($aggregateflag) {
4783: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
4784: $env{'course.'.$env{'request.course.id'}.'.domain'},
4785: $env{'course.'.$env{'request.course.id'}.'.num'});
4786: }
1.125 ng 4787:
1.71 ng 4788: $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
4789: '<td valign="top">'.$displayPts[1].'</td>'.
1.484 albertel 4790: &Apache::loncommon::end_data_table_row();
1.68 ng 4791:
1.196 albertel 4792: $prob++;
1.68 ng 4793: }
1.71 ng 4794: $curRes = $iterator->next();
1.68 ng 4795: }
1.98 albertel 4796:
1.484 albertel 4797: $studentTable.=&Apache::loncommon::end_data_table();
1.324 albertel 4798: $studentTable.=&show_grading_menu_form($env{'form.symb'});
1.526 raeburn 4799: my $grademsg=($changeflag == 0 ? &mt('No score was changed or updated.') :
4800: &mt('The scores were changed for [quant,_1,problem].',
4801: $changeflag));
1.76 ng 4802: $request->print($grademsg.$studentTable);
1.68 ng 4803:
1.70 ng 4804: return '';
4805: }
4806:
1.72 ng 4807: #-------- end of section for handling grading by page/sequence ---------
4808: #
4809: #-------------------------------------------------------------------
4810:
1.581 www 4811: #-------------------- Bubblesheet (Scantron) Grading -------------------
1.75 albertel 4812: #
4813: #------ start of section for handling grading by page/sequence ---------
4814:
1.423 albertel 4815: =pod
4816:
4817: =head1 Bubble sheet grading routines
4818:
1.424 albertel 4819: For this documentation:
4820:
4821: 'scanline' refers to the full line of characters
4822: from the file that we are parsing that represents one entire sheet
4823:
4824: 'bubble line' refers to the data
4825: representing the line of bubbles that are on the physical bubble sheet
4826:
4827:
4828: The overall process is that a scanned in bubble sheet data is uploaded
4829: into a course. When a user wants to grade, they select a
4830: sequence/folder of resources, a file of bubble sheet info, and pick
4831: one of the predefined configurations for what each scanline looks
4832: like.
4833:
4834: Next each scanline is checked for any errors of either 'missing
1.435 foxr 4835: bubbles' (it's an error because it may have been mis-scanned
1.424 albertel 4836: because too light bubbling), 'double bubble' (each bubble line should
4837: have no more that one letter picked), invalid or duplicated CODE,
1.556 weissno 4838: invalid student/employee ID
1.424 albertel 4839:
4840: If the CODE option is used that determines the randomization of the
1.556 weissno 4841: homework problems, either way the student/employee ID is looked up into a
1.424 albertel 4842: username:domain.
4843:
4844: During the validation phase the instructor can choose to skip scanlines.
4845:
1.435 foxr 4846: After the validation phase, there are now 3 bubble sheet files
1.424 albertel 4847:
4848: scantron_original_filename (unmodified original file)
4849: scantron_corrected_filename (file where the corrected information has replaced the original information)
4850: scantron_skipped_filename (contains the exact text of scanlines that where skipped)
4851:
4852: Also there is a separate hash nohist_scantrondata that contains extra
4853: correction information that isn't representable in the bubble sheet
4854: file (see &scantron_getfile() for more information)
4855:
4856: After all scanlines are either valid, marked as valid or skipped, then
4857: foreach line foreach problem in the picked sequence, an ssi request is
4858: made that simulates a user submitting their selected letter(s) against
4859: the homework problem.
1.423 albertel 4860:
4861: =over 4
4862:
4863:
4864:
4865: =item defaultFormData
4866:
4867: Returns html hidden inputs used to hold context/default values.
4868:
4869: Arguments:
4870: $symb - $symb of the current resource
4871:
4872: =cut
1.422 foxr 4873:
1.81 albertel 4874: sub defaultFormData {
1.324 albertel 4875: my ($symb)=@_;
1.447 foxr 4876: return '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 4877: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
4878: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.81 albertel 4879: }
4880:
1.447 foxr 4881:
1.423 albertel 4882: =pod
4883:
4884: =item getSequenceDropDown
4885:
4886: Return html dropdown of possible sequences to grade
4887:
4888: Arguments:
1.582 raeburn 4889: $symb - $symb of the current resource
4890: $map_error - ref to scalar which will container error if
4891: $navmap object is unavailable in &getSymbMap().
1.423 albertel 4892:
4893: =cut
1.422 foxr 4894:
1.75 albertel 4895: sub getSequenceDropDown {
1.582 raeburn 4896: my ($symb,$map_error)=@_;
1.75 albertel 4897: my $result='<select name="selectpage">'."\n";
1.582 raeburn 4898: my ($titles,$symbx) = &getSymbMap($map_error);
4899: if (ref($map_error)) {
4900: return if ($$map_error);
4901: }
1.137 albertel 4902: my ($curpage)=&Apache::lonnet::decode_symb($symb);
1.75 albertel 4903: my $ctr=0;
4904: foreach (@$titles) {
4905: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
4906: $result.='<option value="'.$$symbx{$_}.'" '.
1.401 albertel 4907: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.75 albertel 4908: '>'.$showtitle.'</option>'."\n";
4909: $ctr++;
4910: }
4911: $result.= '</select>';
4912: return $result;
4913: }
4914:
1.495 albertel 4915: my %bubble_lines_per_response; # no. bubble lines for each response.
1.554 raeburn 4916: # key is zero-based index - 0, 1, 2 ...
1.495 albertel 4917:
4918: my %first_bubble_line; # First bubble line no. for each bubble.
4919:
1.509 raeburn 4920: my %subdivided_bubble_lines; # no. bubble lines for optionresponse,
4921: # matchresponse or rankresponse, where
4922: # an individual response can have multiple
4923: # lines
1.503 raeburn 4924:
4925: my %responsetype_per_response; # responsetype for each response
4926:
1.495 albertel 4927: # Save and restore the bubble lines array to the form env.
4928:
4929:
4930: sub save_bubble_lines {
4931: foreach my $line (keys(%bubble_lines_per_response)) {
4932: $env{"form.scantron.bubblelines.$line"} = $bubble_lines_per_response{$line};
4933: $env{"form.scantron.first_bubble_line.$line"} =
4934: $first_bubble_line{$line};
1.503 raeburn 4935: $env{"form.scantron.sub_bubblelines.$line"} =
4936: $subdivided_bubble_lines{$line};
4937: $env{"form.scantron.responsetype.$line"} =
4938: $responsetype_per_response{$line};
1.495 albertel 4939: }
4940: }
4941:
4942:
4943: sub restore_bubble_lines {
4944: my $line = 0;
4945: %bubble_lines_per_response = ();
4946: while ($env{"form.scantron.bubblelines.$line"}) {
4947: my $value = $env{"form.scantron.bubblelines.$line"};
4948: $bubble_lines_per_response{$line} = $value;
4949: $first_bubble_line{$line} =
4950: $env{"form.scantron.first_bubble_line.$line"};
1.503 raeburn 4951: $subdivided_bubble_lines{$line} =
4952: $env{"form.scantron.sub_bubblelines.$line"};
4953: $responsetype_per_response{$line} =
4954: $env{"form.scantron.responsetype.$line"};
1.495 albertel 4955: $line++;
4956: }
4957: }
4958:
4959: # Given the parsed scanline, get the response for
4960: # 'answer' number n:
4961:
4962: sub get_response_bubbles {
4963: my ($parsed_line, $response) = @_;
4964:
4965: my $bubble_line = $first_bubble_line{$response-1} +1;
4966: my $bubble_lines= $bubble_lines_per_response{$response-1};
4967:
4968: my $selected = "";
4969:
4970: for (my $bline = 0; $bline < $bubble_lines; $bline++) {
4971: $selected .= $$parsed_line{"scantron.$bubble_line.answer"}.":";
4972: $bubble_line++;
4973: }
4974: return $selected;
4975: }
1.423 albertel 4976:
4977: =pod
4978:
4979: =item scantron_filenames
4980:
4981: Returns a list of the scantron files in the current course
4982:
4983: =cut
1.422 foxr 4984:
1.202 albertel 4985: sub scantron_filenames {
1.257 albertel 4986: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4987: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
1.517 raeburn 4988: my $getpropath = 1;
1.157 albertel 4989: my @files=&Apache::lonnet::dirlist('userfiles',$cdom,$cname,
1.517 raeburn 4990: $getpropath);
1.202 albertel 4991: my @possiblenames;
1.201 albertel 4992: foreach my $filename (sort(@files)) {
1.157 albertel 4993: ($filename)=split(/&/,$filename);
4994: if ($filename!~/^scantron_orig_/) { next ; }
4995: $filename=~s/^scantron_orig_//;
1.202 albertel 4996: push(@possiblenames,$filename);
4997: }
4998: return @possiblenames;
4999: }
5000:
1.423 albertel 5001: =pod
5002:
5003: =item scantron_uploads
5004:
5005: Returns html drop-down list of scantron files in current course.
5006:
5007: Arguments:
5008: $file2grade - filename to set as selected in the dropdown
5009:
5010: =cut
1.422 foxr 5011:
1.202 albertel 5012: sub scantron_uploads {
1.209 ng 5013: my ($file2grade) = @_;
1.202 albertel 5014: my $result= '<select name="scantron_selectfile">';
5015: $result.="<option></option>";
5016: foreach my $filename (sort(&scantron_filenames())) {
1.401 albertel 5017: $result.="<option".($filename eq $file2grade ? ' selected="selected"':'').">$filename</option>\n";
1.81 albertel 5018: }
5019: $result.="</select>";
5020: return $result;
5021: }
5022:
1.423 albertel 5023: =pod
5024:
5025: =item scantron_scantab
5026:
5027: Returns html drop down of the scantron formats in the scantronformat.tab
5028: file.
5029:
5030: =cut
1.422 foxr 5031:
1.82 albertel 5032: sub scantron_scantab {
5033: my $result='<select name="scantron_format">'."\n";
1.191 albertel 5034: $result.='<option></option>'."\n";
1.518 raeburn 5035: my @lines = &get_scantronformat_file();
5036: if (@lines > 0) {
5037: foreach my $line (@lines) {
5038: next if (($line =~ /^\#/) || ($line eq ''));
5039: my ($name,$descrip)=split(/:/,$line);
5040: $result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
5041: }
1.82 albertel 5042: }
5043: $result.='</select>'."\n";
1.518 raeburn 5044: return $result;
5045: }
5046:
5047: =pod
5048:
5049: =item get_scantronformat_file
5050:
5051: Returns an array containing lines from the scantron format file for
5052: the domain of the course.
5053:
5054: If a url for a custom.tab file is listed in domain's configuration.db,
5055: lines are from this file.
5056:
5057: Otherwise, if a default.tab has been published in RES space by the
5058: domainconfig user, lines are from this file.
5059:
5060: Otherwise, fall back to getting lines from the legacy file on the
1.519 raeburn 5061: local server: /home/httpd/lonTabs/default_scantronformat.tab
1.82 albertel 5062:
1.518 raeburn 5063: =cut
5064:
5065: sub get_scantronformat_file {
5066: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
5067: my %domconfig = &Apache::lonnet::get_dom('configuration',['scantron'],$cdom);
5068: my $gottab = 0;
5069: my @lines;
5070: if (ref($domconfig{'scantron'}) eq 'HASH') {
5071: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
5072: my $formatfile = &Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.$domconfig{'scantron'}{'scantronformat'});
5073: if ($formatfile ne '-1') {
5074: @lines = split("\n",$formatfile,-1);
5075: $gottab = 1;
5076: }
5077: }
5078: }
5079: if (!$gottab) {
5080: my $confname = $cdom.'-domainconfig';
5081: my $default = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res/'.$cdom.'/'.$confname.'/default.tab';
5082: my $formatfile = &Apache::lonnet::getfile($default);
5083: if ($formatfile ne '-1') {
5084: @lines = split("\n",$formatfile,-1);
5085: $gottab = 1;
5086: }
5087: }
5088: if (!$gottab) {
1.519 raeburn 5089: my @domains = &Apache::lonnet::current_machine_domains();
5090: if (grep(/^\Q$cdom\E$/,@domains)) {
5091: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
5092: @lines = <$fh>;
5093: close($fh);
5094: } else {
5095: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab');
5096: @lines = <$fh>;
5097: close($fh);
5098: }
1.518 raeburn 5099: }
5100: return @lines;
1.82 albertel 5101: }
5102:
1.423 albertel 5103: =pod
5104:
5105: =item scantron_CODElist
5106:
5107: Returns html drop down of the saved CODE lists from current course,
5108: generated from earlier printings.
5109:
5110: =cut
1.422 foxr 5111:
1.186 albertel 5112: sub scantron_CODElist {
1.257 albertel 5113: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5114: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.186 albertel 5115: my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
5116: my $namechoice='<option></option>';
1.225 albertel 5117: foreach my $name (sort {uc($a) cmp uc($b)} @names) {
1.191 albertel 5118: if ($name =~ /^error: 2 /) { next; }
1.278 albertel 5119: if ($name =~ /^type\0/) { next; }
1.186 albertel 5120: $namechoice.='<option value="'.$name.'">'.$name.'</option>';
5121: }
5122: $namechoice='<select name="scantron_CODElist">'.$namechoice.'</select>';
5123: return $namechoice;
5124: }
5125:
1.423 albertel 5126: =pod
5127:
5128: =item scantron_CODEunique
5129:
5130: Returns the html for "Each CODE to be used once" radio.
5131:
5132: =cut
1.422 foxr 5133:
1.186 albertel 5134: sub scantron_CODEunique {
1.532 bisitz 5135: my $result='<span class="LC_nobreak">
1.272 albertel 5136: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 5137: value="yes" checked="checked" />'.&mt('Yes').' </label>
1.381 albertel 5138: </span>
1.532 bisitz 5139: <span class="LC_nobreak">
1.272 albertel 5140: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 5141: value="no" />'.&mt('No').' </label>
1.381 albertel 5142: </span>';
1.186 albertel 5143: return $result;
5144: }
1.423 albertel 5145:
5146: =pod
5147:
5148: =item scantron_selectphase
5149:
5150: Generates the initial screen to start the bubble sheet process.
5151: Allows for - starting a grading run.
1.424 albertel 5152: - downloading existing scan data (original, corrected
1.423 albertel 5153: or skipped info)
5154:
5155: - uploading new scan data
5156:
5157: Arguments:
5158: $r - The Apache request object
5159: $file2grade - name of the file that contain the scanned data to score
5160:
5161: =cut
1.186 albertel 5162:
1.75 albertel 5163: sub scantron_selectphase {
1.209 ng 5164: my ($r,$file2grade) = @_;
1.324 albertel 5165: my ($symb)=&get_symb($r);
1.75 albertel 5166: if (!$symb) {return '';}
1.582 raeburn 5167: my $map_error;
5168: my $sequence_selector=&getSequenceDropDown($symb,\$map_error);
5169: if ($map_error) {
5170: $r->print('<br />'.&navmap_errormsg().'<br />');
5171: return;
5172: }
1.324 albertel 5173: my $default_form_data=&defaultFormData($symb);
5174: my $grading_menu_button=&show_grading_menu_form($symb);
1.209 ng 5175: my $file_selector=&scantron_uploads($file2grade);
1.82 albertel 5176: my $format_selector=&scantron_scantab();
1.186 albertel 5177: my $CODE_selector=&scantron_CODElist();
5178: my $CODE_unique=&scantron_CODEunique();
1.75 albertel 5179: my $result;
1.422 foxr 5180:
1.513 foxr 5181: $ssi_error = 0;
5182:
1.422 foxr 5183: # Chunk of form to prompt for a file to grade and how:
5184:
1.489 albertel 5185: $result.= '
5186: <br />
5187: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantron_process">
5188: <input type="hidden" name="command" value="scantron_warning" />
5189: '.$default_form_data.'
5190: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5191: '.&Apache::loncommon::start_data_table_header_row().'
5192: <th colspan="2">
1.492 albertel 5193: '.&mt('Specify file and which Folder/Sequence to grade').'
1.489 albertel 5194: </th>
5195: '.&Apache::loncommon::end_data_table_header_row().'
5196: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5197: <td> '.&mt('Sequence to grade:').' </td><td> '.$sequence_selector.' </td>
1.489 albertel 5198: '.&Apache::loncommon::end_data_table_row().'
5199: '.&Apache::loncommon::start_data_table_row().'
1.572 www 5200: <td> '.&mt('Filename of bubblesheet data file:').' </td><td> '.$file_selector.' </td>
1.489 albertel 5201: '.&Apache::loncommon::end_data_table_row().'
5202: '.&Apache::loncommon::start_data_table_row().'
1.572 www 5203: <td> '.&mt('Format of bubblesheet data file:').' </td><td> '.$format_selector.' </td>
1.489 albertel 5204: '.&Apache::loncommon::end_data_table_row().'
5205: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5206: <td> '.&mt('Saved CODEs to validate against:').' </td><td> '.$CODE_selector.' </td>
1.489 albertel 5207: '.&Apache::loncommon::end_data_table_row().'
5208: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5209: <td> '.&mt('Each CODE is only to be used once:').'</td><td> '.$CODE_unique.' </td>
1.489 albertel 5210: '.&Apache::loncommon::end_data_table_row().'
5211: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5212: <td> '.&mt('Options:').' </td>
1.187 albertel 5213: <td>
1.492 albertel 5214: <label><input type="checkbox" name="scantron_options_redo" value="redo_skipped"/> '.&mt('Do only previously skipped records').'</label> <br />
5215: <label><input type="checkbox" name="scantron_options_ignore" value="ignore_corrections"/> '.&mt('Remove all existing corrections').'</label> <br />
5216: <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources when grading').'</label>
1.187 albertel 5217: </td>
1.489 albertel 5218: '.&Apache::loncommon::end_data_table_row().'
5219: '.&Apache::loncommon::start_data_table_row().'
1.174 albertel 5220: <td colspan="2">
1.572 www 5221: <input type="submit" value="'.&mt('Grading: Validate Bubblesheet Records').'" />
1.162 albertel 5222: </td>
1.489 albertel 5223: '.&Apache::loncommon::end_data_table_row().'
5224: '.&Apache::loncommon::end_data_table().'
5225: </form>
5226: ';
1.162 albertel 5227:
5228: $r->print($result);
5229:
1.257 albertel 5230: if (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) ||
5231: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.162 albertel 5232:
1.422 foxr 5233: # Chunk of form to prompt for a scantron file upload.
5234:
1.489 albertel 5235: $r->print('
5236: <br />
5237: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5238: '.&Apache::loncommon::start_data_table_header_row().'
5239: <th>
1.572 www 5240: '.&mt('Specify a bubblesheet data file to upload.').'
1.489 albertel 5241: </th>
5242: '.&Apache::loncommon::end_data_table_header_row().'
5243: '.&Apache::loncommon::start_data_table_row().'
1.162 albertel 5244: <td>
1.489 albertel 5245: ');
1.324 albertel 5246: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.257 albertel 5247: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
5248: my $cnum= $env{'course.'.$env{'request.course.id'}.'.num'};
1.492 albertel 5249: $r->print('
1.174 albertel 5250: <script type="text/javascript" language="javascript">
5251: function checkUpload(formname) {
5252: if (formname.upfile.value == "") {
1.492 albertel 5253: alert("'.&mt('Please use the browse button to select a file from your local directory.').'");
1.174 albertel 5254: return false;
5255: }
5256: formname.submit();
5257: }
5258: </script>
5259:
1.492 albertel 5260: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
5261: '.$default_form_data.'
5262: <input name="courseid" type="hidden" value="'.$cnum.'" />
5263: <input name="domainid" type="hidden" value="'.$cdom.'" />
5264: <input name="command" value="scantronupload_save" type="hidden" />
5265: '.&mt('File to upload: [_1]','<input type="file" name="upfile" size="50" />').'
1.174 albertel 5266: <br />
1.589 bisitz 5267: <input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
1.174 albertel 5268: </form>
1.492 albertel 5269: ');
1.162 albertel 5270:
1.489 albertel 5271: $r->print('
1.162 albertel 5272: </td>
1.489 albertel 5273: '.&Apache::loncommon::end_data_table_row().'
5274: '.&Apache::loncommon::end_data_table().'
5275: ');
1.162 albertel 5276: }
1.422 foxr 5277:
5278: # Chunk of the form that prompts to view a scoring office file,
5279: # corrected file, skipped records in a file.
5280:
1.489 albertel 5281: $r->print('
5282: <br />
5283: <form action="/adm/grades" name="scantron_download">
5284: '.$default_form_data.'
5285: <input type="hidden" name="command" value="scantron_download" />
5286: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5287: '.&Apache::loncommon::start_data_table_header_row().'
5288: <th>
1.492 albertel 5289: '.&mt('Download a scoring office file').'
1.489 albertel 5290: </th>
5291: '.&Apache::loncommon::end_data_table_header_row().'
5292: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5293: <td> '.&mt('Filename of scoring office file: [_1]',$file_selector).'
1.489 albertel 5294: <br />
1.492 albertel 5295: <input type="submit" value="'.&mt('Download: Show List of Associated Files').'" />
1.489 albertel 5296: '.&Apache::loncommon::end_data_table_row().'
5297: '.&Apache::loncommon::end_data_table().'
5298: </form>
5299: <br />
5300: ');
1.162 albertel 5301:
1.457 banghart 5302: &Apache::lonpickcode::code_list($r,2);
1.523 raeburn 5303:
1.528 raeburn 5304: $r->print('<br /><form method="post" name="checkscantron">'.
1.523 raeburn 5305: $default_form_data."\n".
5306: &Apache::loncommon::start_data_table('LC_scantron_action')."\n".
5307: &Apache::loncommon::start_data_table_header_row()."\n".
5308: '<th colspan="2">
1.572 www 5309: '.&mt('Review bubblesheet data and submissions for a previously graded folder/sequence')."\n".
1.523 raeburn 5310: '</th>'."\n".
5311: &Apache::loncommon::end_data_table_header_row()."\n".
5312: &Apache::loncommon::start_data_table_row()."\n".
5313: '<td> '.&mt('Graded folder/sequence:').' </td>'."\n".
5314: '<td> '.$sequence_selector.' </td>'.
5315: &Apache::loncommon::end_data_table_row()."\n".
5316: &Apache::loncommon::start_data_table_row()."\n".
5317: '<td> '.&mt('Filename of scoring office file:').' </td>'."\n".
5318: '<td> '.$file_selector.' </td>'."\n".
5319: &Apache::loncommon::end_data_table_row()."\n".
5320: &Apache::loncommon::start_data_table_row()."\n".
5321: '<td> '.&mt('Format of data file:').' </td>'."\n".
5322: '<td> '.$format_selector.' </td>'."\n".
5323: &Apache::loncommon::end_data_table_row()."\n".
5324: &Apache::loncommon::start_data_table_row()."\n".
1.557 raeburn 5325: '<td> '.&mt('Options').' </td>'."\n".
5326: '<td> <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources').'</label></td>'.
5327: &Apache::loncommon::end_data_table_row()."\n".
5328: &Apache::loncommon::start_data_table_row()."\n".
1.523 raeburn 5329: '<td colspan="2">'."\n".
5330: '<input type="hidden" name="command" value="checksubmissions" />'."\n".
1.575 www 5331: '<input type="submit" value="'.&mt('Review Bubblesheet Data and Submission Records').'" />'."\n".
1.523 raeburn 5332: '</td>'."\n".
5333: &Apache::loncommon::end_data_table_row()."\n".
5334: &Apache::loncommon::end_data_table()."\n".
5335: '</form><br />');
1.457 banghart 5336: $r->print($grading_menu_button);
1.523 raeburn 5337: return;
1.75 albertel 5338: }
5339:
1.423 albertel 5340: =pod
5341:
5342: =item get_scantron_config
5343:
5344: Parse and return the scantron configuration line selected as a
5345: hash of configuration file fields.
5346:
5347: Arguments:
5348: which - the name of the configuration to parse from the file.
5349:
5350:
5351: Returns:
5352: If the named configuration is not in the file, an empty
5353: hash is returned.
5354: a hash with the fields
5355: name - internal name for the this configuration setup
5356: description - text to display to operator that describes this config
5357: CODElocation - if 0 or the string 'none'
5358: - no CODE exists for this config
5359: if -1 || the string 'letter'
5360: - a CODE exists for this config and is
5361: a string of letters
5362: Unsupported value (but planned for future support)
5363: if a positive integer
5364: - The CODE exists as the first n items from
5365: the question section of the form
5366: if the string 'number'
5367: - The CODE exists for this config and is
5368: a string of numbers
5369: CODEstart - (only matter if a CODE exists) column in the line where
5370: the CODE starts
5371: CODElength - length of the CODE
1.573 bisitz 5372: IDstart - column where the student/employee ID starts
1.556 weissno 5373: IDlength - length of the student/employee ID info
1.423 albertel 5374: Qstart - column where the information from the bubbled
5375: 'questions' start
5376: Qlength - number of columns comprising a single bubble line from
5377: the sheet. (usually either 1 or 10)
1.424 albertel 5378: Qon - either a single character representing the character used
1.423 albertel 5379: to signal a bubble was chosen in the positional setup, or
5380: the string 'letter' if the letter of the chosen bubble is
5381: in the final, or 'number' if a number representing the
5382: chosen bubble is in the file (1->A 0->J)
1.424 albertel 5383: Qoff - the character used to represent that a bubble was
5384: left blank
1.423 albertel 5385: PaperID - if the scanning process generates a unique number for each
5386: sheet scanned the column that this ID number starts in
5387: PaperIDlength - number of columns that comprise the unique ID number
5388: for the sheet of paper
1.424 albertel 5389: FirstName - column that the first name starts in
1.423 albertel 5390: FirstNameLength - number of columns that the first name spans
5391:
5392: LastName - column that the last name starts in
5393: LastNameLength - number of columns that the last name spans
5394:
5395: =cut
1.422 foxr 5396:
1.82 albertel 5397: sub get_scantron_config {
5398: my ($which) = @_;
1.518 raeburn 5399: my @lines = &get_scantronformat_file();
1.82 albertel 5400: my %config;
1.157 albertel 5401: #FIXME probably should move to XML it has already gotten a bit much now
1.518 raeburn 5402: foreach my $line (@lines) {
1.82 albertel 5403: my ($name,$descrip)=split(/:/,$line);
5404: if ($name ne $which ) { next; }
5405: chomp($line);
5406: my @config=split(/:/,$line);
5407: $config{'name'}=$config[0];
5408: $config{'description'}=$config[1];
5409: $config{'CODElocation'}=$config[2];
5410: $config{'CODEstart'}=$config[3];
5411: $config{'CODElength'}=$config[4];
5412: $config{'IDstart'}=$config[5];
5413: $config{'IDlength'}=$config[6];
5414: $config{'Qstart'}=$config[7];
1.497 foxr 5415: $config{'Qlength'}=$config[8];
1.82 albertel 5416: $config{'Qoff'}=$config[9];
5417: $config{'Qon'}=$config[10];
1.157 albertel 5418: $config{'PaperID'}=$config[11];
5419: $config{'PaperIDlength'}=$config[12];
5420: $config{'FirstName'}=$config[13];
5421: $config{'FirstNamelength'}=$config[14];
5422: $config{'LastName'}=$config[15];
5423: $config{'LastNamelength'}=$config[16];
1.82 albertel 5424: last;
5425: }
5426: return %config;
5427: }
5428:
1.423 albertel 5429: =pod
5430:
5431: =item username_to_idmap
5432:
1.556 weissno 5433: creates a hash keyed by student/employee ID with values of the corresponding
1.423 albertel 5434: student username:domain.
5435:
5436: Arguments:
5437:
5438: $classlist - reference to the class list hash. This is a hash
5439: keyed by student name:domain whose elements are references
1.424 albertel 5440: to arrays containing various chunks of information
1.423 albertel 5441: about the student. (See loncoursedata for more info).
5442:
5443: Returns
5444: %idmap - the constructed hash
5445:
5446: =cut
5447:
1.82 albertel 5448: sub username_to_idmap {
5449: my ($classlist)= @_;
5450: my %idmap;
5451: foreach my $student (keys(%$classlist)) {
5452: $idmap{$classlist->{$student}->[&Apache::loncoursedata::CL_ID]}=
5453: $student;
5454: }
5455: return %idmap;
5456: }
1.423 albertel 5457:
5458: =pod
5459:
1.424 albertel 5460: =item scantron_fixup_scanline
1.423 albertel 5461:
5462: Process a requested correction to a scanline.
5463:
5464: Arguments:
5465: $scantron_config - hash from &get_scantron_config()
5466: $scan_data - hash of correction information
5467: (see &scantron_getfile())
5468: $line - existing scanline
5469: $whichline - line number of the passed in scanline
5470: $field - type of change to process
5471: (either
1.573 bisitz 5472: 'ID' -> correct the student/employee ID
1.423 albertel 5473: 'CODE' -> correct the CODE
5474: 'answer' -> fixup the submitted answers)
5475:
5476: $args - hash of additional info,
5477: - 'ID'
5478: 'newid' -> studentID to use in replacement
1.424 albertel 5479: of existing one
1.423 albertel 5480: - 'CODE'
5481: 'CODE_ignore_dup' - set to true if duplicates
5482: should be ignored.
5483: 'CODE' - is new code or 'use_unfound'
1.424 albertel 5484: if the existing unfound code should
1.423 albertel 5485: be used as is
5486: - 'answer'
5487: 'response' - new answer or 'none' if blank
5488: 'question' - the bubble line to change
1.503 raeburn 5489: 'questionnum' - the question identifier,
5490: may include subquestion.
1.423 albertel 5491:
5492: Returns:
5493: $line - the modified scanline
5494:
5495: Side effects:
5496: $scan_data - may be updated
5497:
5498: =cut
5499:
1.82 albertel 5500:
1.157 albertel 5501: sub scantron_fixup_scanline {
5502: my ($scantron_config,$scan_data,$line,$whichline,$field,$args)=@_;
5503: if ($field eq 'ID') {
5504: if (length($args->{'newid'}) > $$scantron_config{'IDlength'}) {
1.186 albertel 5505: return ($line,1,'New value too large');
1.157 albertel 5506: }
5507: if (length($args->{'newid'}) < $$scantron_config{'IDlength'}) {
5508: $args->{'newid'}=sprintf('%-'.$$scantron_config{'IDlength'}.'s',
5509: $args->{'newid'});
5510: }
5511: substr($line,$$scantron_config{'IDstart'}-1,
5512: $$scantron_config{'IDlength'})=$args->{'newid'};
5513: if ($args->{'newid'}=~/^\s*$/) {
5514: &scan_data($scan_data,"$whichline.user",
5515: $args->{'username'}.':'.$args->{'domain'});
5516: }
1.186 albertel 5517: } elsif ($field eq 'CODE') {
1.192 albertel 5518: if ($args->{'CODE_ignore_dup'}) {
5519: &scan_data($scan_data,"$whichline.CODE_ignore_dup",'1');
5520: }
5521: &scan_data($scan_data,"$whichline.useCODE",'1');
5522: if ($args->{'CODE'} ne 'use_unfound') {
1.191 albertel 5523: if (length($args->{'CODE'}) > $$scantron_config{'CODElength'}) {
5524: return ($line,1,'New CODE value too large');
5525: }
5526: if (length($args->{'CODE'}) < $$scantron_config{'CODElength'}) {
5527: $args->{'CODE'}=sprintf('%-'.$$scantron_config{'CODElength'}.'s',$args->{'CODE'});
5528: }
5529: substr($line,$$scantron_config{'CODEstart'}-1,
5530: $$scantron_config{'CODElength'})=$args->{'CODE'};
1.186 albertel 5531: }
1.157 albertel 5532: } elsif ($field eq 'answer') {
1.497 foxr 5533: my $length=$scantron_config->{'Qlength'};
1.157 albertel 5534: my $off=$scantron_config->{'Qoff'};
5535: my $on=$scantron_config->{'Qon'};
1.497 foxr 5536: my $answer=${off}x$length;
5537: if ($args->{'response'} eq 'none') {
5538: &scan_data($scan_data,
1.503 raeburn 5539: "$whichline.no_bubble.".$args->{'questionnum'},'1');
1.497 foxr 5540: } else {
5541: if ($on eq 'letter') {
5542: my @alphabet=('A'..'Z');
5543: $answer=$alphabet[$args->{'response'}];
5544: } elsif ($on eq 'number') {
5545: $answer=$args->{'response'}+1;
5546: if ($answer == 10) { $answer = '0'; }
1.274 albertel 5547: } else {
1.497 foxr 5548: substr($answer,$args->{'response'},1)=$on;
1.274 albertel 5549: }
1.497 foxr 5550: &scan_data($scan_data,
1.503 raeburn 5551: "$whichline.no_bubble.".$args->{'questionnum'},undef,'1');
1.157 albertel 5552: }
1.497 foxr 5553: my $where=$length*($args->{'question'}-1)+$scantron_config->{'Qstart'};
5554: substr($line,$where-1,$length)=$answer;
1.157 albertel 5555: }
5556: return $line;
5557: }
1.423 albertel 5558:
5559: =pod
5560:
5561: =item scan_data
5562:
5563: Edit or look up an item in the scan_data hash.
5564:
5565: Arguments:
5566: $scan_data - The hash (see scantron_getfile)
5567: $key - shorthand of the key to edit (actual key is
1.424 albertel 5568: scantronfilename_key).
1.423 albertel 5569: $data - New value of the hash entry.
5570: $delete - If true, the entry is removed from the hash.
5571:
5572: Returns:
5573: The new value of the hash table field (undefined if deleted).
5574:
5575: =cut
5576:
5577:
1.157 albertel 5578: sub scan_data {
5579: my ($scan_data,$key,$value,$delete)=@_;
1.257 albertel 5580: my $filename=$env{'form.scantron_selectfile'};
1.157 albertel 5581: if (defined($value)) {
5582: $scan_data->{$filename.'_'.$key} = $value;
5583: }
5584: if ($delete) { delete($scan_data->{$filename.'_'.$key}); }
5585: return $scan_data->{$filename.'_'.$key};
5586: }
1.423 albertel 5587:
1.495 albertel 5588: # ----- These first few routines are general use routines.----
5589:
5590: # Return the number of occurences of a pattern in a string.
5591:
5592: sub occurence_count {
5593: my ($string, $pattern) = @_;
5594:
5595: my @matches = ($string =~ /$pattern/g);
5596:
5597: return scalar(@matches);
5598: }
5599:
5600:
5601: # Take a string known to have digits and convert all the
5602: # digits into letters in the range J,A..I.
5603:
5604: sub digits_to_letters {
5605: my ($input) = @_;
5606:
5607: my @alphabet = ('J', 'A'..'I');
5608:
5609: my @input = split(//, $input);
5610: my $output ='';
5611: for (my $i = 0; $i < scalar(@input); $i++) {
5612: if ($input[$i] =~ /\d/) {
5613: $output .= $alphabet[$input[$i]];
5614: } else {
5615: $output .= $input[$i];
5616: }
5617: }
5618: return $output;
5619: }
5620:
1.423 albertel 5621: =pod
5622:
5623: =item scantron_parse_scanline
5624:
5625: Decodes a scanline from the selected scantron file
5626:
5627: Arguments:
5628: line - The text of the scantron file line to process
5629: whichline - Line number
5630: scantron_config - Hash describing the format of the scantron lines.
5631: scan_data - Hash of extra information about the scanline
5632: (see scantron_getfile for more information)
5633: just_header - True if should not process question answers but only
5634: the stuff to the left of the answers.
5635: Returns:
5636: Hash containing the result of parsing the scanline
5637:
5638: Keys are all proceeded by the string 'scantron.'
5639:
5640: CODE - the CODE in use for this scanline
5641: useCODE - 1 if the CODE is invalid but it usage has been forced
5642: by the operator
5643: CODE_ignore_dup - 1 if the CODE is a duplicated use when unique
5644: CODEs were selected, but the usage has been
5645: forced by the operator
1.556 weissno 5646: ID - student/employee ID
1.423 albertel 5647: PaperID - if used, the ID number printed on the sheet when the
5648: paper was scanned
5649: FirstName - first name from the sheet
5650: LastName - last name from the sheet
5651:
5652: if just_header was not true these key may also exist
5653:
1.447 foxr 5654: missingerror - a list of bubble ranges that are considered to be answers
5655: to a single question that don't have any bubbles filled in.
5656: Of the form questionnumber:firstbubblenumber:count.
5657: doubleerror - a list of bubble ranges that are considered to be answers
5658: to a single question that have more than one bubble filled in.
5659: Of the form questionnumber::firstbubblenumber:count
5660:
5661: In the above, count is the number of bubble responses in the
5662: input line needed to represent the possible answers to the question.
5663: e.g. a radioresponse with 15 choices in an answer sheet with 10 choices
5664: per line would have count = 2.
5665:
1.423 albertel 5666: maxquest - the number of the last bubble line that was parsed
5667:
5668: (<number> starts at 1)
5669: <number>.answer - zero or more letters representing the selected
5670: letters from the scanline for the bubble line
5671: <number>.
5672: if blank there was either no bubble or there where
5673: multiple bubbles, (consult the keys missingerror and
5674: doubleerror if this is an error condition)
5675:
5676: =cut
5677:
1.82 albertel 5678: sub scantron_parse_scanline {
1.423 albertel 5679: my ($line,$whichline,$scantron_config,$scan_data,$just_header)=@_;
1.470 foxr 5680:
1.82 albertel 5681: my %record;
1.550 raeburn 5682: my $lastpos = $env{'form.scantron_maxbubble'}*$$scantron_config{'Qlength'};
5683: my $questions=substr($line,$$scantron_config{'Qstart'}-1,$lastpos); # Answers
1.422 foxr 5684: my $data=substr($line,0,$$scantron_config{'Qstart'}-1); # earlier stuff
1.278 albertel 5685: if (!($$scantron_config{'CODElocation'} eq 0 ||
5686: $$scantron_config{'CODElocation'} eq 'none')) {
5687: if ($$scantron_config{'CODElocation'} < 0 ||
5688: $$scantron_config{'CODElocation'} eq 'letter' ||
5689: $$scantron_config{'CODElocation'} eq 'number') {
1.191 albertel 5690: $record{'scantron.CODE'}=substr($data,
5691: $$scantron_config{'CODEstart'}-1,
1.83 albertel 5692: $$scantron_config{'CODElength'});
1.191 albertel 5693: if (&scan_data($scan_data,"$whichline.useCODE")) {
5694: $record{'scantron.useCODE'}=1;
5695: }
1.192 albertel 5696: if (&scan_data($scan_data,"$whichline.CODE_ignore_dup")) {
5697: $record{'scantron.CODE_ignore_dup'}=1;
5698: }
1.82 albertel 5699: } else {
5700: #FIXME interpret first N questions
5701: }
5702: }
1.83 albertel 5703: $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
5704: $$scantron_config{'IDlength'});
1.157 albertel 5705: $record{'scantron.PaperID'}=
5706: substr($data,$$scantron_config{'PaperID'}-1,
5707: $$scantron_config{'PaperIDlength'});
5708: $record{'scantron.FirstName'}=
5709: substr($data,$$scantron_config{'FirstName'}-1,
5710: $$scantron_config{'FirstNamelength'});
5711: $record{'scantron.LastName'}=
5712: substr($data,$$scantron_config{'LastName'}-1,
5713: $$scantron_config{'LastNamelength'});
1.423 albertel 5714: if ($just_header) { return \%record; }
1.194 albertel 5715:
1.82 albertel 5716: my @alphabet=('A'..'Z');
5717: my $questnum=0;
1.447 foxr 5718: my $ansnum =1; # Multiple 'answer lines'/question.
5719:
1.470 foxr 5720: chomp($questions); # Get rid of any trailing \n.
5721: $questions =~ s/\r$//; # Get rid of trailing \r too (MAC or Win uploads).
5722: while (length($questions)) {
1.447 foxr 5723: my $answers_needed = $bubble_lines_per_response{$questnum};
1.503 raeburn 5724: my $answer_length = ($$scantron_config{'Qlength'} * $answers_needed)
5725: || 1;
5726: $questnum++;
5727: my $quest_id = $questnum;
5728: my $currentquest = substr($questions,0,$answer_length);
5729: $questions = substr($questions,$answer_length);
5730: if (length($currentquest) < $answer_length) { next; }
5731:
5732: if ($subdivided_bubble_lines{$questnum-1} =~ /,/) {
5733: my $subquestnum = 1;
5734: my $subquestions = $currentquest;
5735: my @subanswers_needed =
5736: split(/,/,$subdivided_bubble_lines{$questnum-1});
5737: foreach my $subans (@subanswers_needed) {
5738: my $subans_length =
5739: ($$scantron_config{'Qlength'} * $subans) || 1;
5740: my $currsubquest = substr($subquestions,0,$subans_length);
5741: $subquestions = substr($subquestions,$subans_length);
5742: $quest_id = "$questnum.$subquestnum";
5743: if (($$scantron_config{'Qon'} eq 'letter') ||
5744: ($$scantron_config{'Qon'} eq 'number')) {
5745: $ansnum = &scantron_validator_lettnum($ansnum,
5746: $questnum,$quest_id,$subans,$currsubquest,$whichline,
5747: \@alphabet,\%record,$scantron_config,$scan_data);
5748: } else {
5749: $ansnum = &scantron_validator_positional($ansnum,
5750: $questnum,$quest_id,$subans,$currsubquest,$whichline, \@alphabet,\%record,$scantron_config,$scan_data);
5751: }
5752: $subquestnum ++;
5753: }
5754: } else {
5755: if (($$scantron_config{'Qon'} eq 'letter') ||
5756: ($$scantron_config{'Qon'} eq 'number')) {
5757: $ansnum = &scantron_validator_lettnum($ansnum,$questnum,
5758: $quest_id,$answers_needed,$currentquest,$whichline,
5759: \@alphabet,\%record,$scantron_config,$scan_data);
5760: } else {
5761: $ansnum = &scantron_validator_positional($ansnum,$questnum,
5762: $quest_id,$answers_needed,$currentquest,$whichline,
5763: \@alphabet,\%record,$scantron_config,$scan_data);
5764: }
5765: }
5766: }
5767: $record{'scantron.maxquest'}=$questnum;
5768: return \%record;
5769: }
1.447 foxr 5770:
1.503 raeburn 5771: sub scantron_validator_lettnum {
5772: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,$whichline,
5773: $alphabet,$record,$scantron_config,$scan_data) = @_;
5774:
5775: # Qon 'letter' implies for each slot in currquest we have:
5776: # ? or * for doubles, a letter in A-Z for a bubble, and
5777: # about anything else (esp. a value of Qoff) for missing
5778: # bubbles.
5779: #
5780: # Qon 'number' implies each slot gives a digit that indexes the
5781: # bubbles filled, or Qoff, or a non-number for unbubbled lines,
5782: # and * or ? for double bubbles on a single line.
5783: #
1.447 foxr 5784:
1.503 raeburn 5785: my $matchon;
5786: if ($$scantron_config{'Qon'} eq 'letter') {
5787: $matchon = '[A-Z]';
5788: } elsif ($$scantron_config{'Qon'} eq 'number') {
5789: $matchon = '\d';
5790: }
5791: my $occurrences = 0;
5792: if (($responsetype_per_response{$questnum-1} eq 'essayresponse') ||
5793: ($responsetype_per_response{$questnum-1} eq 'formularesponse') ||
1.510 raeburn 5794: ($responsetype_per_response{$questnum-1} eq 'stringresponse') ||
5795: ($responsetype_per_response{$questnum-1} eq 'imageresponse') ||
5796: ($responsetype_per_response{$questnum-1} eq 'reactionresponse') ||
5797: ($responsetype_per_response{$questnum-1} eq 'organicresponse')) {
1.503 raeburn 5798: my @singlelines = split('',$currquest);
5799: foreach my $entry (@singlelines) {
5800: $occurrences = &occurence_count($entry,$matchon);
5801: if ($occurrences > 1) {
5802: last;
5803: }
5804: }
5805: } else {
5806: $occurrences = &occurence_count($currquest,$matchon);
5807: }
5808: if (($currquest =~ /\?/ || $currquest =~ /\*/) || ($occurrences > 1)) {
5809: push(@{$record->{'scantron.doubleerror'}},$quest_id);
5810: for (my $ans=0; $ans<$answers_needed; $ans++) {
5811: my $bubble = substr($currquest,$ans,1);
5812: if ($bubble =~ /$matchon/ ) {
5813: if ($$scantron_config{'Qon'} eq 'number') {
5814: if ($bubble == 0) {
5815: $bubble = 10;
5816: }
5817: $record->{"scantron.$ansnum.answer"} =
5818: $alphabet->[$bubble-1];
5819: } else {
5820: $record->{"scantron.$ansnum.answer"} = $bubble;
5821: }
5822: } else {
5823: $record->{"scantron.$ansnum.answer"}='';
5824: }
5825: $ansnum++;
5826: }
5827: } elsif (!defined($currquest)
5828: || (&occurence_count($currquest, $$scantron_config{'Qoff'}) == length($currquest))
5829: || (&occurence_count($currquest,$matchon) == 0)) {
5830: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
5831: $record->{"scantron.$ansnum.answer"}='';
5832: $ansnum++;
5833: }
5834: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
5835: push(@{$record->{'scantron.missingerror'}},$quest_id);
5836: }
5837: } else {
5838: if ($$scantron_config{'Qon'} eq 'number') {
5839: $currquest = &digits_to_letters($currquest);
5840: }
5841: for (my $ans=0; $ans<$answers_needed; $ans++) {
5842: my $bubble = substr($currquest,$ans,1);
5843: $record->{"scantron.$ansnum.answer"} = $bubble;
5844: $ansnum++;
5845: }
5846: }
5847: return $ansnum;
5848: }
1.447 foxr 5849:
1.503 raeburn 5850: sub scantron_validator_positional {
5851: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,
5852: $whichline,$alphabet,$record,$scantron_config,$scan_data) = @_;
1.447 foxr 5853:
1.503 raeburn 5854: # Otherwise there's a positional notation;
5855: # each bubble line requires Qlength items, and there are filled in
5856: # bubbles for each case where there 'Qon' characters.
5857: #
1.447 foxr 5858:
1.503 raeburn 5859: my @array=split($$scantron_config{'Qon'},$currquest,-1);
1.447 foxr 5860:
1.503 raeburn 5861: # If the split only gives us one element.. the full length of the
5862: # answer string, no bubbles are filled in:
1.447 foxr 5863:
1.507 raeburn 5864: if ($answers_needed eq '') {
5865: return;
5866: }
5867:
1.503 raeburn 5868: if (length($array[0]) eq $$scantron_config{'Qlength'}*$answers_needed) {
5869: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
5870: $record->{"scantron.$ansnum.answer"}='';
5871: $ansnum++;
5872: }
5873: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
5874: push(@{$record->{"scantron.missingerror"}},$quest_id);
5875: }
5876: } elsif (scalar(@array) == 2) {
5877: my $location = length($array[0]);
5878: my $line_num = int($location / $$scantron_config{'Qlength'});
5879: my $bubble = $alphabet->[$location % $$scantron_config{'Qlength'}];
5880: for (my $ans=0; $ans<$answers_needed; $ans++) {
5881: if ($ans eq $line_num) {
5882: $record->{"scantron.$ansnum.answer"} = $bubble;
5883: } else {
5884: $record->{"scantron.$ansnum.answer"} = ' ';
5885: }
5886: $ansnum++;
5887: }
5888: } else {
5889: # If there's more than one instance of a bubble character
5890: # That's a double bubble; with positional notation we can
5891: # record all the bubbles filled in as well as the
5892: # fact this response consists of multiple bubbles.
5893: #
5894: if (($responsetype_per_response{$questnum-1} eq 'essayresponse') ||
5895: ($responsetype_per_response{$questnum-1} eq 'formularesponse') ||
1.510 raeburn 5896: ($responsetype_per_response{$questnum-1} eq 'stringresponse') ||
5897: ($responsetype_per_response{$questnum-1} eq 'imageresponse') ||
5898: ($responsetype_per_response{$questnum-1} eq 'reactionresponse') ||
5899: ($responsetype_per_response{$questnum-1} eq 'organicresponse')) {
1.503 raeburn 5900: my $doubleerror = 0;
5901: while (($currquest >= $$scantron_config{'Qlength'}) &&
5902: (!$doubleerror)) {
5903: my $currline = substr($currquest,0,$$scantron_config{'Qlength'});
5904: $currquest = substr($currquest,$$scantron_config{'Qlength'});
5905: my @currarray = split($$scantron_config{'Qon'},$currline,-1);
5906: if (length(@currarray) > 2) {
5907: $doubleerror = 1;
5908: }
5909: }
5910: if ($doubleerror) {
5911: push(@{$record->{'scantron.doubleerror'}},$quest_id);
5912: }
5913: } else {
5914: push(@{$record->{'scantron.doubleerror'}},$quest_id);
5915: }
5916: my $item = $ansnum;
5917: for (my $ans=0; $ans<$answers_needed; $ans++) {
5918: $record->{"scantron.$item.answer"} = '';
5919: $item ++;
5920: }
1.447 foxr 5921:
1.503 raeburn 5922: my @ans=@array;
5923: my $i=0;
5924: my $increment = 0;
5925: while ($#ans) {
5926: $i+=length($ans[0]) + $increment;
5927: my $line = int($i/$$scantron_config{'Qlength'} + $ansnum);
5928: my $bubble = $i%$$scantron_config{'Qlength'};
5929: $record->{"scantron.$line.answer"}.=$alphabet->[$bubble];
5930: shift(@ans);
5931: $increment = 1;
5932: }
5933: $ansnum += $answers_needed;
1.82 albertel 5934: }
1.503 raeburn 5935: return $ansnum;
1.82 albertel 5936: }
5937:
1.423 albertel 5938: =pod
5939:
5940: =item scantron_add_delay
5941:
5942: Adds an error message that occurred during the grading phase to a
5943: queue of messages to be shown after grading pass is complete
5944:
5945: Arguments:
1.424 albertel 5946: $delayqueue - arrary ref of hash ref of error messages
1.423 albertel 5947: $scanline - the scanline that caused the error
5948: $errormesage - the error message
5949: $errorcode - a numeric code for the error
5950:
5951: Side Effects:
1.424 albertel 5952: updates the $delayqueue to have a new hash ref of the error
1.423 albertel 5953:
5954: =cut
5955:
1.82 albertel 5956: sub scantron_add_delay {
1.140 albertel 5957: my ($delayqueue,$scanline,$errormessage,$errorcode)=@_;
5958: push(@$delayqueue,
5959: {'line' => $scanline, 'emsg' => $errormessage,
5960: 'ecode' => $errorcode }
5961: );
1.82 albertel 5962: }
5963:
1.423 albertel 5964: =pod
5965:
5966: =item scantron_find_student
5967:
1.424 albertel 5968: Finds the username for the current scanline
5969:
5970: Arguments:
5971: $scantron_record - hash result from scantron_parse_scanline
5972: $scan_data - hash of correction information
5973: (see &scantron_getfile() form more information)
5974: $idmap - hash from &username_to_idmap()
5975: $line - number of current scanline
5976:
5977: Returns:
5978: Either 'username:domain' or undef if unknown
5979:
1.423 albertel 5980: =cut
5981:
1.82 albertel 5982: sub scantron_find_student {
1.157 albertel 5983: my ($scantron_record,$scan_data,$idmap,$line)=@_;
1.83 albertel 5984: my $scanID=$$scantron_record{'scantron.ID'};
1.157 albertel 5985: if ($scanID =~ /^\s*$/) {
5986: return &scan_data($scan_data,"$line.user");
5987: }
1.83 albertel 5988: foreach my $id (keys(%$idmap)) {
1.157 albertel 5989: if (lc($id) eq lc($scanID)) {
5990: return $$idmap{$id};
5991: }
1.83 albertel 5992: }
5993: return undef;
5994: }
5995:
1.423 albertel 5996: =pod
5997:
5998: =item scantron_filter
5999:
1.424 albertel 6000: Filter sub for lonnavmaps, filters out hidden resources if ignore
6001: hidden resources was selected
6002:
1.423 albertel 6003: =cut
6004:
1.83 albertel 6005: sub scantron_filter {
6006: my ($curres)=@_;
1.331 albertel 6007:
6008: if (ref($curres) && $curres->is_problem()) {
6009: # if the user has asked to not have either hidden
6010: # or 'randomout' controlled resources to be graded
6011: # don't include them
6012: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
6013: && $curres->randomout) {
6014: return 0;
6015: }
1.83 albertel 6016: return 1;
6017: }
6018: return 0;
1.82 albertel 6019: }
6020:
1.423 albertel 6021: =pod
6022:
6023: =item scantron_process_corrections
6024:
1.424 albertel 6025: Gets correction information out of submitted form data and corrects
6026: the scanline
6027:
1.423 albertel 6028: =cut
6029:
1.157 albertel 6030: sub scantron_process_corrections {
6031: my ($r) = @_;
1.257 albertel 6032: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 6033: my ($scanlines,$scan_data)=&scantron_getfile();
6034: my $classlist=&Apache::loncoursedata::get_classlist();
1.257 albertel 6035: my $which=$env{'form.scantron_line'};
1.200 albertel 6036: my $line=&scantron_get_line($scanlines,$scan_data,$which);
1.157 albertel 6037: my ($skip,$err,$errmsg);
1.257 albertel 6038: if ($env{'form.scantron_skip_record'}) {
1.157 albertel 6039: $skip=1;
1.257 albertel 6040: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)ID$/) {
6041: my $newstudent=$env{'form.scantron_username'}.':'.
6042: $env{'form.scantron_domain'};
1.157 albertel 6043: my $newid=$classlist->{$newstudent}->[&Apache::loncoursedata::CL_ID];
6044: ($line,$err,$errmsg)=
6045: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
6046: 'ID',{'newid'=>$newid,
1.257 albertel 6047: 'username'=>$env{'form.scantron_username'},
6048: 'domain'=>$env{'form.scantron_domain'}});
6049: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)CODE$/) {
6050: my $resolution=$env{'form.scantron_CODE_resolution'};
1.190 albertel 6051: my $newCODE;
1.192 albertel 6052: my %args;
1.190 albertel 6053: if ($resolution eq 'use_unfound') {
1.191 albertel 6054: $newCODE='use_unfound';
1.190 albertel 6055: } elsif ($resolution eq 'use_found') {
1.257 albertel 6056: $newCODE=$env{'form.scantron_CODE_selectedvalue'};
1.190 albertel 6057: } elsif ($resolution eq 'use_typed') {
1.257 albertel 6058: $newCODE=$env{'form.scantron_CODE_newvalue'};
1.194 albertel 6059: } elsif ($resolution =~ /^use_closest_(\d+)/) {
1.257 albertel 6060: $newCODE=$env{"form.scantron_CODE_closest_$1"};
1.190 albertel 6061: }
1.257 albertel 6062: if ($env{'form.scantron_corrections'} eq 'duplicateCODE') {
1.192 albertel 6063: $args{'CODE_ignore_dup'}=1;
6064: }
6065: $args{'CODE'}=$newCODE;
1.186 albertel 6066: ($line,$err,$errmsg)=
6067: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
1.192 albertel 6068: 'CODE',\%args);
1.257 albertel 6069: } elsif ($env{'form.scantron_corrections'} =~ /^(missing|double)bubble$/) {
6070: foreach my $question (split(',',$env{'form.scantron_questions'})) {
1.157 albertel 6071: ($line,$err,$errmsg)=
6072: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,
6073: $which,'answer',
6074: { 'question'=>$question,
1.503 raeburn 6075: 'response'=>$env{"form.scantron_correct_Q_$question"},
6076: 'questionnum'=>$env{"form.scantron_questionnum_Q_$question"}});
1.157 albertel 6077: if ($err) { last; }
6078: }
6079: }
6080: if ($err) {
1.398 albertel 6081: $r->print("<span class=\"LC_warning\">Unable to accept last correction, an error occurred :$errmsg:</span>");
1.157 albertel 6082: } else {
1.200 albertel 6083: &scantron_put_line($scanlines,$scan_data,$which,$line,$skip);
1.157 albertel 6084: &scantron_putfile($scanlines,$scan_data);
6085: }
6086: }
6087:
1.423 albertel 6088: =pod
6089:
6090: =item reset_skipping_status
6091:
1.424 albertel 6092: Forgets the current set of remember skipped scanlines (and thus
6093: reverts back to considering all lines in the
6094: scantron_skipped_<filename> file)
6095:
1.423 albertel 6096: =cut
6097:
1.200 albertel 6098: sub reset_skipping_status {
6099: my ($scanlines,$scan_data)=&scantron_getfile();
6100: &scan_data($scan_data,'remember_skipping',undef,1);
6101: &scantron_putfile(undef,$scan_data);
6102: }
6103:
1.423 albertel 6104: =pod
6105:
6106: =item start_skipping
6107:
1.424 albertel 6108: Marks a scanline to be skipped.
6109:
1.423 albertel 6110: =cut
6111:
1.376 albertel 6112: sub start_skipping {
1.200 albertel 6113: my ($scan_data,$i)=@_;
6114: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 6115: if ($env{'form.scantron_options_redo'} =~ /^redo_/) {
6116: $remembered{$i}=2;
6117: } else {
6118: $remembered{$i}=1;
6119: }
1.200 albertel 6120: &scan_data($scan_data,'remember_skipping',join(':',%remembered));
6121: }
6122:
1.423 albertel 6123: =pod
6124:
6125: =item should_be_skipped
6126:
1.424 albertel 6127: Checks whether a scanline should be skipped.
6128:
1.423 albertel 6129: =cut
6130:
1.200 albertel 6131: sub should_be_skipped {
1.376 albertel 6132: my ($scanlines,$scan_data,$i)=@_;
1.257 albertel 6133: if ($env{'form.scantron_options_redo'} !~ /^redo_/) {
1.200 albertel 6134: # not redoing old skips
1.376 albertel 6135: if ($scanlines->{'skipped'}[$i]) { return 1; }
1.200 albertel 6136: return 0;
6137: }
6138: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 6139:
6140: if (exists($remembered{$i}) && $remembered{$i} != 2 ) {
6141: return 0;
6142: }
1.200 albertel 6143: return 1;
6144: }
6145:
1.423 albertel 6146: =pod
6147:
6148: =item remember_current_skipped
6149:
1.424 albertel 6150: Discovers what scanlines are in the scantron_skipped_<filename>
6151: file and remembers them into scan_data for later use.
6152:
1.423 albertel 6153: =cut
6154:
1.200 albertel 6155: sub remember_current_skipped {
6156: my ($scanlines,$scan_data)=&scantron_getfile();
6157: my %to_remember;
6158: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
6159: if ($scanlines->{'skipped'}[$i]) {
6160: $to_remember{$i}=1;
6161: }
6162: }
1.376 albertel 6163:
1.200 albertel 6164: &scan_data($scan_data,'remember_skipping',join(':',%to_remember));
6165: &scantron_putfile(undef,$scan_data);
6166: }
6167:
1.423 albertel 6168: =pod
6169:
6170: =item check_for_error
6171:
1.424 albertel 6172: Checks if there was an error when attempting to remove a specific
6173: scantron_.. bubble sheet data file. Prints out an error if
6174: something went wrong.
6175:
1.423 albertel 6176: =cut
6177:
1.200 albertel 6178: sub check_for_error {
6179: my ($r,$result)=@_;
6180: if ($result ne 'ok' && $result ne 'not_found' ) {
1.492 albertel 6181: $r->print(&mt("An error occurred ([_1]) when trying to remove the existing corrections.",$result));
1.200 albertel 6182: }
6183: }
1.157 albertel 6184:
1.423 albertel 6185: =pod
6186:
6187: =item scantron_warning_screen
6188:
1.424 albertel 6189: Interstitial screen to make sure the operator has selected the
6190: correct options before we start the validation phase.
6191:
1.423 albertel 6192: =cut
6193:
1.203 albertel 6194: sub scantron_warning_screen {
6195: my ($button_text)=@_;
1.257 albertel 6196: my $title=&Apache::lonnet::gettitle($env{'form.selectpage'});
1.284 albertel 6197: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.373 albertel 6198: my $CODElist;
1.284 albertel 6199: if ($scantron_config{'CODElocation'} &&
6200: $scantron_config{'CODEstart'} &&
6201: $scantron_config{'CODElength'}) {
6202: $CODElist=$env{'form.scantron_CODElist'};
1.398 albertel 6203: if ($env{'form.scantron_CODElist'} eq '') { $CODElist='<span class="LC_warning">None</span>'; }
1.284 albertel 6204: $CODElist=
1.492 albertel 6205: '<tr><td><b>'.&mt('List of CODES to validate against:').'</b></td><td><tt>'.
1.373 albertel 6206: $env{'form.scantron_CODElist'}.'</tt></td></tr>';
1.284 albertel 6207: }
1.492 albertel 6208: return ('
1.203 albertel 6209: <p>
1.492 albertel 6210: <span class="LC_warning">
6211: '.&mt('Please double check the information below before clicking on \'[_1]\'',&mt($button_text)).'</span>
1.203 albertel 6212: </p>
6213: <table>
1.492 albertel 6214: <tr><td><b>'.&mt('Sequence to be Graded:').'</b></td><td>'.$title.'</td></tr>
6215: <tr><td><b>'.&mt('Data File that will be used:').'</b></td><td><tt>'.$env{'form.scantron_selectfile'}.'</tt></td></tr>
6216: '.$CODElist.'
1.203 albertel 6217: </table>
6218: <br />
1.492 albertel 6219: <p> '.&mt('If this information is correct, please click on \'[_1]\'.',&mt($button_text)).'</p>
6220: <p> '.&mt('If something is incorrect, please click the \'Grading Menu\' button to start over.').'</p>
1.203 albertel 6221:
6222: <br />
1.492 albertel 6223: ');
1.203 albertel 6224: }
6225:
1.423 albertel 6226: =pod
6227:
6228: =item scantron_do_warning
6229:
1.424 albertel 6230: Check if the operator has picked something for all required
6231: fields. Error out if something is missing.
6232:
1.423 albertel 6233: =cut
6234:
1.203 albertel 6235: sub scantron_do_warning {
6236: my ($r)=@_;
1.324 albertel 6237: my ($symb)=&get_symb($r);
1.203 albertel 6238: if (!$symb) {return '';}
1.324 albertel 6239: my $default_form_data=&defaultFormData($symb);
1.203 albertel 6240: $r->print(&scantron_form_start().$default_form_data);
1.257 albertel 6241: if ( $env{'form.selectpage'} eq '' ||
6242: $env{'form.scantron_selectfile'} eq '' ||
6243: $env{'form.scantron_format'} eq '' ) {
1.492 albertel 6244: $r->print("<p>".&mt('You have forgetten to specify some information. Please go Back and try again.')."</p>");
1.257 albertel 6245: if ( $env{'form.selectpage'} eq '') {
1.492 albertel 6246: $r->print('<p><span class="LC_error">'.&mt('You have not selected a Sequence to grade').'</span></p>');
1.237 albertel 6247: }
1.257 albertel 6248: if ( $env{'form.scantron_selectfile'} eq '') {
1.492 albertel 6249: $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 6250: }
1.257 albertel 6251: if ( $env{'form.scantron_format'} eq '') {
1.492 albertel 6252: $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 6253: }
6254: } else {
1.265 www 6255: my $warning=&scantron_warning_screen('Grading: Validate Records');
1.492 albertel 6256: $r->print('
6257: '.$warning.'
6258: <input type="submit" name="submit" value="'.&mt('Grading: Validate Records').'" />
1.203 albertel 6259: <input type="hidden" name="command" value="scantron_validate" />
1.492 albertel 6260: ');
1.237 albertel 6261: }
1.352 albertel 6262: $r->print("</form><br />".&show_grading_menu_form($symb));
1.203 albertel 6263: return '';
6264: }
6265:
1.423 albertel 6266: =pod
6267:
6268: =item scantron_form_start
6269:
1.424 albertel 6270: html hidden input for remembering all selected grading options
6271:
1.423 albertel 6272: =cut
6273:
1.203 albertel 6274: sub scantron_form_start {
6275: my ($max_bubble)=@_;
6276: my $result= <<SCANTRONFORM;
6277: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
1.257 albertel 6278: <input type="hidden" name="selectpage" value="$env{'form.selectpage'}" />
6279: <input type="hidden" name="scantron_format" value="$env{'form.scantron_format'}" />
6280: <input type="hidden" name="scantron_selectfile" value="$env{'form.scantron_selectfile'}" />
1.218 albertel 6281: <input type="hidden" name="scantron_maxbubble" value="$max_bubble" />
1.257 albertel 6282: <input type="hidden" name="scantron_CODElist" value="$env{'form.scantron_CODElist'}" />
6283: <input type="hidden" name="scantron_CODEunique" value="$env{'form.scantron_CODEunique'}" />
6284: <input type="hidden" name="scantron_options_redo" value="$env{'form.scantron_options_redo'}" />
6285: <input type="hidden" name="scantron_options_ignore" value="$env{'form.scantron_options_ignore'}" />
1.331 albertel 6286: <input type="hidden" name="scantron_options_hidden" value="$env{'form.scantron_options_hidden'}" />
1.203 albertel 6287: SCANTRONFORM
1.447 foxr 6288:
6289: my $line = 0;
6290: while (defined($env{"form.scantron.bubblelines.$line"})) {
6291: my $chunk =
6292: '<input type="hidden" name="scantron.bubblelines.'.$line.'" value="'.$env{"form.scantron.bubblelines.$line"}.'" />'."\n";
1.448 foxr 6293: $chunk .=
6294: '<input type="hidden" name="scantron.first_bubble_line.'.$line.'" value="'.$env{"form.scantron.first_bubble_line.$line"}.'" />'."\n";
1.503 raeburn 6295: $chunk .=
6296: '<input type="hidden" name="scantron.sub_bubblelines.'.$line.'" value="'.$env{"form.scantron.sub_bubblelines.$line"}.'" />'."\n";
1.504 raeburn 6297: $chunk .=
6298: '<input type="hidden" name="scantron.responsetype.'.$line.'" value="'.$env{"form.scantron.responsetype.$line"}.'" />'."\n";
1.447 foxr 6299: $result .= $chunk;
6300: $line++;
6301: }
1.203 albertel 6302: return $result;
6303: }
6304:
1.423 albertel 6305: =pod
6306:
6307: =item scantron_validate_file
6308:
1.424 albertel 6309: Dispatch routine for doing validation of a bubble sheet data file.
6310:
6311: Also processes any necessary information resets that need to
6312: occur before validation begins (ignore previous corrections,
6313: restarting the skipped records processing)
6314:
1.423 albertel 6315: =cut
6316:
1.157 albertel 6317: sub scantron_validate_file {
6318: my ($r) = @_;
1.324 albertel 6319: my ($symb)=&get_symb($r);
1.157 albertel 6320: if (!$symb) {return '';}
1.324 albertel 6321: my $default_form_data=&defaultFormData($symb);
1.200 albertel 6322:
6323: # do the detection of only doing skipped records first befroe we delete
1.424 albertel 6324: # them when doing the corrections reset
1.257 albertel 6325: if ($env{'form.scantron_options_redo'} ne 'redo_skipped_ready') {
1.200 albertel 6326: &reset_skipping_status();
6327: }
1.257 albertel 6328: if ($env{'form.scantron_options_redo'} eq 'redo_skipped') {
1.200 albertel 6329: &remember_current_skipped();
1.257 albertel 6330: $env{'form.scantron_options_redo'}='redo_skipped_ready';
1.200 albertel 6331: }
6332:
1.257 albertel 6333: if ($env{'form.scantron_options_ignore'} eq 'ignore_corrections') {
1.200 albertel 6334: &check_for_error($r,&scantron_remove_file('corrected'));
6335: &check_for_error($r,&scantron_remove_file('skipped'));
6336: &check_for_error($r,&scantron_remove_scan_data());
1.257 albertel 6337: $env{'form.scantron_options_ignore'}='done';
1.192 albertel 6338: }
1.200 albertel 6339:
1.257 albertel 6340: if ($env{'form.scantron_corrections'}) {
1.157 albertel 6341: &scantron_process_corrections($r);
6342: }
1.503 raeburn 6343: $r->print('<p>'.&mt('Gathering necessary information.').'</p>');$r->rflush();
1.157 albertel 6344: #get the student pick code ready
6345: $r->print(&Apache::loncommon::studentbrowser_javascript());
1.582 raeburn 6346: my $nav_error;
6347: my $max_bubble=&scantron_get_maxbubble(\$nav_error);
6348: if ($nav_error) {
6349: $r->print(&navmap_errormsg());
6350: return '';
6351: }
1.203 albertel 6352: my $result=&scantron_form_start($max_bubble).$default_form_data;
1.157 albertel 6353: $r->print($result);
6354:
1.334 albertel 6355: my @validate_phases=( 'sequence',
6356: 'ID',
1.157 albertel 6357: 'CODE',
6358: 'doublebubble',
6359: 'missingbubbles');
1.257 albertel 6360: if (!$env{'form.validatepass'}) {
6361: $env{'form.validatepass'} = 0;
1.157 albertel 6362: }
1.257 albertel 6363: my $currentphase=$env{'form.validatepass'};
1.157 albertel 6364:
1.448 foxr 6365:
1.157 albertel 6366: my $stop=0;
6367: while (!$stop && $currentphase < scalar(@validate_phases)) {
1.503 raeburn 6368: $r->print(&mt('Validating '.$validate_phases[$currentphase]).'<br />');
1.157 albertel 6369: $r->rflush();
6370: my $which="scantron_validate_".$validate_phases[$currentphase];
6371: {
6372: no strict 'refs';
6373: ($stop,$currentphase)=&$which($r,$currentphase);
6374: }
6375: }
6376: if (!$stop) {
1.203 albertel 6377: my $warning=&scantron_warning_screen('Start Grading');
1.542 raeburn 6378: $r->print(&mt('Validation process complete.').'<br />'.
6379: $warning.
6380: &mt('Perform verification for each student after storage of submissions?').
6381: ' <span class="LC_nobreak"><label>'.
6382: '<input type="radio" name="verifyrecord" value="1" />'.&mt('Yes').'</label>'.
6383: (' 'x3).'<label>'.
6384: '<input type="radio" name="verifyrecord" value="0" checked="checked" />'.&mt('No').
6385: '</label></span><br />'.
6386: &mt('Grading will take longer if you use verification.').'<br />'.
1.572 www 6387: &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 6388: '<input type="submit" name="submit" value="'.&mt('Start Grading').'" />'.
6389: '<input type="hidden" name="command" value="scantron_process" />'."\n");
1.157 albertel 6390: } else {
6391: $r->print('<input type="hidden" name="command" value="scantron_validate" />');
6392: $r->print("<input type='hidden' name='validatepass' value='".$currentphase."' />");
6393: }
6394: if ($stop) {
1.334 albertel 6395: if ($validate_phases[$currentphase] eq 'sequence') {
1.539 riegler 6396: $r->print('<input type="submit" name="submit" value="'.&mt('Ignore').' → " />');
1.492 albertel 6397: $r->print(' '.&mt('this error').' <br />');
1.334 albertel 6398:
1.492 albertel 6399: $r->print(" <p>".&mt("Or click the 'Grading Menu' button to start over.")."</p>");
1.334 albertel 6400: } else {
1.503 raeburn 6401: if ($validate_phases[$currentphase] eq 'doublebubble' || $validate_phases[$currentphase] eq 'missingbubbles') {
1.539 riegler 6402: $r->print('<input type="button" name="submitbutton" value="'.&mt('Continue').' →" onclick="javascript:verify_bubble_radio(this.form)" />');
1.503 raeburn 6403: } else {
1.539 riegler 6404: $r->print('<input type="submit" name="submit" value="'.&mt('Continue').' →" />');
1.503 raeburn 6405: }
1.492 albertel 6406: $r->print(' '.&mt('using corrected info').' <br />');
6407: $r->print("<input type='submit' value='".&mt("Skip")."' name='scantron_skip_record' />");
6408: $r->print(" ".&mt("this scanline saving it for later."));
1.334 albertel 6409: }
1.157 albertel 6410: }
1.352 albertel 6411: $r->print(" </form><br />".&show_grading_menu_form($symb));
1.157 albertel 6412: return '';
6413: }
6414:
1.423 albertel 6415:
6416: =pod
6417:
6418: =item scantron_remove_file
6419:
1.424 albertel 6420: Removes the requested bubble sheet data file, makes sure that
6421: scantron_original_<filename> is never removed
6422:
6423:
1.423 albertel 6424: =cut
6425:
1.200 albertel 6426: sub scantron_remove_file {
1.192 albertel 6427: my ($which)=@_;
1.257 albertel 6428: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6429: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 6430: my $file='scantron_';
1.200 albertel 6431: if ($which eq 'corrected' || $which eq 'skipped') {
6432: $file.=$which.'_';
1.192 albertel 6433: } else {
6434: return 'refused';
6435: }
1.257 albertel 6436: $file.=$env{'form.scantron_selectfile'};
1.200 albertel 6437: return &Apache::lonnet::removeuserfile($cname,$cdom,$file);
6438: }
6439:
1.423 albertel 6440:
6441: =pod
6442:
6443: =item scantron_remove_scan_data
6444:
1.424 albertel 6445: Removes all scan_data correction for the requested bubble sheet
6446: data file. (In the case that both the are doing skipped records we need
6447: to remember the old skipped lines for the time being so that element
6448: persists for a while.)
6449:
1.423 albertel 6450: =cut
6451:
1.200 albertel 6452: sub scantron_remove_scan_data {
1.257 albertel 6453: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6454: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 6455: my @keys=&Apache::lonnet::getkeys('nohist_scantrondata',$cdom,$cname);
6456: my @todelete;
1.257 albertel 6457: my $filename=$env{'form.scantron_selectfile'};
1.192 albertel 6458: foreach my $key (@keys) {
6459: if ($key=~/^\Q$filename\E_/) {
1.257 albertel 6460: if ($env{'form.scantron_options_redo'} eq 'redo_skipped_ready' &&
1.200 albertel 6461: $key=~/remember_skipping/) {
6462: next;
6463: }
1.192 albertel 6464: push(@todelete,$key);
6465: }
6466: }
1.200 albertel 6467: my $result;
1.192 albertel 6468: if (@todelete) {
1.491 albertel 6469: $result = &Apache::lonnet::del('nohist_scantrondata',
6470: \@todelete,$cdom,$cname);
6471: } else {
6472: $result = 'ok';
1.192 albertel 6473: }
6474: return $result;
6475: }
6476:
1.423 albertel 6477:
6478: =pod
6479:
6480: =item scantron_getfile
6481:
1.424 albertel 6482: Fetches the requested bubble sheet data file (all 3 versions), and
6483: the scan_data hash
6484:
6485: Arguments:
6486: None
6487:
6488: Returns:
6489: 2 hash references
6490:
6491: - first one has
6492: orig -
6493: corrected -
6494: skipped - each of which points to an array ref of the specified
6495: file broken up into individual lines
6496: count - number of scanlines
6497:
6498: - second is the scan_data hash possible keys are
1.425 albertel 6499: ($number refers to scanline numbered $number and thus the key affects
6500: only that scanline
6501: $bubline refers to the specific bubble line element and the aspects
6502: refers to that specific bubble line element)
6503:
6504: $number.user - username:domain to use
6505: $number.CODE_ignore_dup
6506: - ignore the duplicate CODE error
6507: $number.useCODE
6508: - use the CODE in the scanline as is
6509: $number.no_bubble.$bubline
6510: - it is valid that there is no bubbled in bubble
6511: at $number $bubline
6512: remember_skipping
6513: - a frozen hash containing keys of $number and values
6514: of either
6515: 1 - we are on a 'do skipped records pass' and plan
6516: on processing this line
6517: 2 - we are on a 'do skipped records pass' and this
6518: scanline has been marked to skip yet again
1.424 albertel 6519:
1.423 albertel 6520: =cut
6521:
1.157 albertel 6522: sub scantron_getfile {
1.200 albertel 6523: #FIXME really would prefer a scantron directory
1.257 albertel 6524: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6525: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.157 albertel 6526: my $lines;
6527: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6528: 'scantron_orig_'.$env{'form.scantron_selectfile'});
1.157 albertel 6529: my %scanlines;
6530: $scanlines{'orig'}=[(split("\n",$lines,-1))];
6531: my $temp=$scanlines{'orig'};
6532: $scanlines{'count'}=$#$temp;
6533:
6534: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6535: 'scantron_corrected_'.$env{'form.scantron_selectfile'});
1.157 albertel 6536: if ($lines eq '-1') {
6537: $scanlines{'corrected'}=[];
6538: } else {
6539: $scanlines{'corrected'}=[(split("\n",$lines,-1))];
6540: }
6541: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6542: 'scantron_skipped_'.$env{'form.scantron_selectfile'});
1.157 albertel 6543: if ($lines eq '-1') {
6544: $scanlines{'skipped'}=[];
6545: } else {
6546: $scanlines{'skipped'}=[(split("\n",$lines,-1))];
6547: }
1.175 albertel 6548: my @tmp=&Apache::lonnet::dump('nohist_scantrondata',$cdom,$cname);
1.157 albertel 6549: if ($tmp[0] =~ /^(error:|no_such_host)/) { @tmp=(); }
6550: my %scan_data = @tmp;
6551: return (\%scanlines,\%scan_data);
6552: }
6553:
1.423 albertel 6554: =pod
6555:
6556: =item lonnet_putfile
6557:
1.424 albertel 6558: Wrapper routine to call &Apache::lonnet::finishuserfileupload
6559:
6560: Arguments:
6561: $contents - data to store
6562: $filename - filename to store $contents into
6563:
6564: Returns:
6565: result value from &Apache::lonnet::finishuserfileupload
6566:
1.423 albertel 6567: =cut
6568:
1.157 albertel 6569: sub lonnet_putfile {
6570: my ($contents,$filename)=@_;
1.257 albertel 6571: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6572: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6573: $env{'form.sillywaytopassafilearound'}=$contents;
1.275 albertel 6574: &Apache::lonnet::finishuserfileupload($docuname,$docudom,'sillywaytopassafilearound',$filename);
1.157 albertel 6575:
6576: }
6577:
1.423 albertel 6578: =pod
6579:
6580: =item scantron_putfile
6581:
1.424 albertel 6582: Stores the current version of the bubble sheet data files, and the
6583: scan_data hash. (Does not modify the original version only the
6584: corrected and skipped versions.
6585:
6586: Arguments:
6587: $scanlines - hash ref that looks like the first return value from
6588: &scantron_getfile()
6589: $scan_data - hash ref that looks like the second return value from
6590: &scantron_getfile()
6591:
1.423 albertel 6592: =cut
6593:
1.157 albertel 6594: sub scantron_putfile {
6595: my ($scanlines,$scan_data) = @_;
1.200 albertel 6596: #FIXME really would prefer a scantron directory
1.257 albertel 6597: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6598: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.200 albertel 6599: if ($scanlines) {
6600: my $prefix='scantron_';
1.157 albertel 6601: # no need to update orig, shouldn't change
6602: # &lonnet_putfile(join("\n",@{$scanlines->{'orig'}}),$prefix.'orig_'.
1.257 albertel 6603: # $env{'form.scantron_selectfile'});
1.200 albertel 6604: &lonnet_putfile(join("\n",@{$scanlines->{'corrected'}}),
6605: $prefix.'corrected_'.
1.257 albertel 6606: $env{'form.scantron_selectfile'});
1.200 albertel 6607: &lonnet_putfile(join("\n",@{$scanlines->{'skipped'}}),
6608: $prefix.'skipped_'.
1.257 albertel 6609: $env{'form.scantron_selectfile'});
1.200 albertel 6610: }
1.175 albertel 6611: &Apache::lonnet::put('nohist_scantrondata',$scan_data,$cdom,$cname);
1.157 albertel 6612: }
6613:
1.423 albertel 6614: =pod
6615:
6616: =item scantron_get_line
6617:
1.424 albertel 6618: Returns the correct version of the scanline
6619:
6620: Arguments:
6621: $scanlines - hash ref that looks like the first return value from
6622: &scantron_getfile()
6623: $scan_data - hash ref that looks like the second return value from
6624: &scantron_getfile()
6625: $i - number of the requested line (starts at 0)
6626:
6627: Returns:
6628: A scanline, (either the original or the corrected one if it
6629: exists), or undef if the requested scanline should be
6630: skipped. (Either because it's an skipped scanline, or it's an
6631: unskipped scanline and we are not doing a 'do skipped scanlines'
6632: pass.
6633:
1.423 albertel 6634: =cut
6635:
1.157 albertel 6636: sub scantron_get_line {
1.200 albertel 6637: my ($scanlines,$scan_data,$i)=@_;
1.376 albertel 6638: if (&should_be_skipped($scanlines,$scan_data,$i)) { return undef; }
6639: #if ($scanlines->{'skipped'}[$i]) { return undef; }
1.157 albertel 6640: if ($scanlines->{'corrected'}[$i]) {return $scanlines->{'corrected'}[$i];}
6641: return $scanlines->{'orig'}[$i];
6642: }
6643:
1.423 albertel 6644: =pod
6645:
6646: =item scantron_todo_count
6647:
1.424 albertel 6648: Counts the number of scanlines that need processing.
6649:
6650: Arguments:
6651: $scanlines - hash ref that looks like the first return value from
6652: &scantron_getfile()
6653: $scan_data - hash ref that looks like the second return value from
6654: &scantron_getfile()
6655:
6656: Returns:
6657: $count - number of scanlines to process
6658:
1.423 albertel 6659: =cut
6660:
1.200 albertel 6661: sub get_todo_count {
6662: my ($scanlines,$scan_data)=@_;
6663: my $count=0;
6664: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
6665: my $line=&scantron_get_line($scanlines,$scan_data,$i);
6666: if ($line=~/^[\s\cz]*$/) { next; }
6667: $count++;
6668: }
6669: return $count;
6670: }
6671:
1.423 albertel 6672: =pod
6673:
6674: =item scantron_put_line
6675:
1.424 albertel 6676: Updates the 'corrected' or 'skipped' versions of the bubble sheet
6677: data file.
6678:
6679: Arguments:
6680: $scanlines - hash ref that looks like the first return value from
6681: &scantron_getfile()
6682: $scan_data - hash ref that looks like the second return value from
6683: &scantron_getfile()
6684: $i - line number to update
6685: $newline - contents of the updated scanline
6686: $skip - if true make the line for skipping and update the
6687: 'skipped' file
6688:
1.423 albertel 6689: =cut
6690:
1.157 albertel 6691: sub scantron_put_line {
1.200 albertel 6692: my ($scanlines,$scan_data,$i,$newline,$skip)=@_;
1.157 albertel 6693: if ($skip) {
6694: $scanlines->{'skipped'}[$i]=$newline;
1.376 albertel 6695: &start_skipping($scan_data,$i);
1.157 albertel 6696: return;
6697: }
6698: $scanlines->{'corrected'}[$i]=$newline;
6699: }
6700:
1.423 albertel 6701: =pod
6702:
6703: =item scantron_clear_skip
6704:
1.424 albertel 6705: Remove a line from the 'skipped' file
6706:
6707: Arguments:
6708: $scanlines - hash ref that looks like the first return value from
6709: &scantron_getfile()
6710: $scan_data - hash ref that looks like the second return value from
6711: &scantron_getfile()
6712: $i - line number to update
6713:
1.423 albertel 6714: =cut
6715:
1.376 albertel 6716: sub scantron_clear_skip {
6717: my ($scanlines,$scan_data,$i)=@_;
6718: if (exists($scanlines->{'skipped'}[$i])) {
6719: undef($scanlines->{'skipped'}[$i]);
6720: return 1;
6721: }
6722: return 0;
6723: }
6724:
1.423 albertel 6725: =pod
6726:
6727: =item scantron_filter_not_exam
6728:
1.424 albertel 6729: Filter routine used by &Apache::lonnavmaps::retrieveResources(), to
6730: filter out resources that are not marked as 'exam' mode
6731:
1.423 albertel 6732: =cut
6733:
1.334 albertel 6734: sub scantron_filter_not_exam {
6735: my ($curres)=@_;
6736:
6737: if (ref($curres) && $curres->is_problem() && !$curres->is_exam()) {
6738: # if the user has asked to not have either hidden
6739: # or 'randomout' controlled resources to be graded
6740: # don't include them
6741: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
6742: && $curres->randomout) {
6743: return 0;
6744: }
6745: return 1;
6746: }
6747: return 0;
6748: }
6749:
1.423 albertel 6750: =pod
6751:
6752: =item scantron_validate_sequence
6753:
1.424 albertel 6754: Validates the selected sequence, checking for resource that are
6755: not set to exam mode.
6756:
1.423 albertel 6757: =cut
6758:
1.334 albertel 6759: sub scantron_validate_sequence {
6760: my ($r,$currentphase) = @_;
6761:
6762: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 6763: unless (ref($navmap)) {
6764: $r->print(&navmap_errormsg());
6765: return (1,$currentphase);
6766: }
1.334 albertel 6767: my (undef,undef,$sequence)=
6768: &Apache::lonnet::decode_symb($env{'form.selectpage'});
6769:
6770: my $map=$navmap->getResourceByUrl($sequence);
6771:
6772: $r->print('<input type="hidden" name="validate_sequence_exam"
6773: value="ignore" />');
6774: if ($env{'form.validate_sequence_exam'} ne 'ignore') {
6775: my @resources=
6776: $navmap->retrieveResources($map,\&scantron_filter_not_exam,1,0);
6777: if (@resources) {
1.357 banghart 6778: $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 6779: return (1,$currentphase);
6780: }
6781: }
6782:
6783: return (0,$currentphase+1);
6784: }
6785:
1.423 albertel 6786:
6787:
1.157 albertel 6788: sub scantron_validate_ID {
6789: my ($r,$currentphase) = @_;
6790:
6791: #get student info
6792: my $classlist=&Apache::loncoursedata::get_classlist();
6793: my %idmap=&username_to_idmap($classlist);
6794:
6795: #get scantron line setup
1.257 albertel 6796: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 6797: my ($scanlines,$scan_data)=&scantron_getfile();
1.582 raeburn 6798:
6799: my $nav_error;
6800: &scantron_get_maxbubble(\$nav_error); # parse needs the bubble_lines.. array.
6801: if ($nav_error) {
6802: $r->print(&navmap_errormsg());
6803: return(1,$currentphase);
6804: }
1.157 albertel 6805:
6806: my %found=('ids'=>{},'usernames'=>{});
6807: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 6808: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 6809: if ($line=~/^[\s\cz]*$/) { next; }
6810: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
6811: $scan_data);
6812: my $id=$$scan_record{'scantron.ID'};
6813: my $found;
6814: foreach my $checkid (keys(%idmap)) {
6815: if (lc($checkid) eq lc($id)) { $found=$checkid;last; }
6816: }
6817: if ($found) {
6818: my $username=$idmap{$found};
6819: if ($found{'ids'}{$found}) {
6820: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
6821: $line,'duplicateID',$found);
1.194 albertel 6822: return(1,$currentphase);
1.157 albertel 6823: } elsif ($found{'usernames'}{$username}) {
6824: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
6825: $line,'duplicateID',$username);
1.194 albertel 6826: return(1,$currentphase);
1.157 albertel 6827: }
1.186 albertel 6828: #FIXME store away line we previously saw the ID on to use above
1.157 albertel 6829: $found{'ids'}{$found}++;
6830: $found{'usernames'}{$username}++;
6831: } else {
6832: if ($id =~ /^\s*$/) {
1.158 albertel 6833: my $username=&scan_data($scan_data,"$i.user");
1.157 albertel 6834: if (defined($username) && $found{'usernames'}{$username}) {
6835: &scantron_get_correction($r,$i,$scan_record,
6836: \%scantron_config,
6837: $line,'duplicateID',$username);
1.194 albertel 6838: return(1,$currentphase);
1.157 albertel 6839: } elsif (!defined($username)) {
6840: &scantron_get_correction($r,$i,$scan_record,
6841: \%scantron_config,
6842: $line,'incorrectID');
1.194 albertel 6843: return(1,$currentphase);
1.157 albertel 6844: }
6845: $found{'usernames'}{$username}++;
6846: } else {
6847: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
6848: $line,'incorrectID');
1.194 albertel 6849: return(1,$currentphase);
1.157 albertel 6850: }
6851: }
6852: }
6853:
6854: return (0,$currentphase+1);
6855: }
6856:
1.423 albertel 6857:
1.157 albertel 6858: sub scantron_get_correction {
6859: my ($r,$i,$scan_record,$scan_config,$line,$error,$arg)=@_;
1.454 banghart 6860: #FIXME in the case of a duplicated ID the previous line, probably need
1.157 albertel 6861: #to show both the current line and the previous one and allow skipping
6862: #the previous one or the current one
6863:
1.333 albertel 6864: if ( $$scan_record{'scantron.PaperID'} =~ /\S/) {
1.492 albertel 6865: $r->print("<p>".&mt("<b>An error was detected ($error)</b>".
6866: " for PaperID <tt>[_1]</tt>",
6867: $$scan_record{'scantron.PaperID'})."</p> \n");
1.157 albertel 6868: } else {
1.492 albertel 6869: $r->print("<p>".&mt("<b>An error was detected ($error)</b>".
6870: " in scanline [_1] <pre>[_2]</pre>",
6871: $i,$line)."</p> \n");
6872: }
6873: my $message="<p>".&mt("The ID on the form is <tt>[_1]</tt><br />".
6874: "The name on the paper is [_2],[_3]",
6875: $$scan_record{'scantron.ID'},
6876: $$scan_record{'scantron.LastName'},
6877: $$scan_record{'scantron.FirstName'})."</p>";
1.242 albertel 6878:
1.157 albertel 6879: $r->print('<input type="hidden" name="scantron_corrections" value="'.$error.'" />'."\n");
6880: $r->print('<input type="hidden" name="scantron_line" value="'.$i.'" />'."\n");
1.503 raeburn 6881: # Array populated for doublebubble or
6882: my @lines_to_correct; # missingbubble errors to build javascript
6883: # to validate radio button checking
6884:
1.157 albertel 6885: if ($error =~ /ID$/) {
1.186 albertel 6886: if ($error eq 'incorrectID') {
1.492 albertel 6887: $r->print("<p>".&mt("The encoded ID is not in the classlist").
6888: "</p>\n");
1.157 albertel 6889: } elsif ($error eq 'duplicateID') {
1.492 albertel 6890: $r->print("<p>".&mt("The encoded ID has also been used by a previous paper [_1]",$arg)."</p>\n");
1.157 albertel 6891: }
1.242 albertel 6892: $r->print($message);
1.492 albertel 6893: $r->print("<p>".&mt("How should I handle this?")." <br /> \n");
1.157 albertel 6894: $r->print("\n<ul><li> ");
6895: #FIXME it would be nice if this sent back the user ID and
6896: #could do partial userID matches
6897: $r->print(&Apache::loncommon::selectstudent_link('scantronupload',
6898: 'scantron_username','scantron_domain'));
6899: $r->print(": <input type='text' name='scantron_username' value='' />");
6900: $r->print("\n@".
1.257 albertel 6901: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'scantron_domain'));
1.157 albertel 6902:
6903: $r->print('</li>');
1.186 albertel 6904: } elsif ($error =~ /CODE$/) {
6905: if ($error eq 'incorrectCODE') {
1.492 albertel 6906: $r->print("<p>".&mt("The encoded CODE is not in the list of possible CODEs.")."</p>\n");
1.186 albertel 6907: } elsif ($error eq 'duplicateCODE') {
1.492 albertel 6908: $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 6909: }
1.492 albertel 6910: $r->print("<p>".&mt("The CODE on the form is <tt>'[_1]'</tt>",
6911: $$scan_record{'scantron.CODE'})."<br />\n");
1.242 albertel 6912: $r->print($message);
1.492 albertel 6913: $r->print("<p>".&mt("How should I handle this?")." <br /> \n");
1.187 albertel 6914: $r->print("\n<br /> ");
1.194 albertel 6915: my $i=0;
1.273 albertel 6916: if ($error eq 'incorrectCODE'
6917: && $$scan_record{'scantron.CODE'}=~/\S/ ) {
1.194 albertel 6918: my ($max,$closest)=&scantron_get_closely_matching_CODEs($arg,$$scan_record{'scantron.CODE'});
1.278 albertel 6919: if ($closest > 0) {
6920: foreach my $testcode (@{$closest}) {
6921: my $checked='';
1.569 bisitz 6922: if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 6923: $r->print("
6924: <label>
1.569 bisitz 6925: <input type='radio' name='scantron_CODE_resolution' value='use_closest_$i'$checked />
1.492 albertel 6926: ".&mt("Use the similar CODE [_1] instead.",
6927: "<b><tt>".$testcode."</tt></b>")."
6928: </label>
6929: <input type='hidden' name='scantron_CODE_closest_$i' value='$testcode' />");
1.278 albertel 6930: $r->print("\n<br />");
6931: $i++;
6932: }
1.194 albertel 6933: }
6934: }
1.273 albertel 6935: if ($$scan_record{'scantron.CODE'}=~/\S/ ) {
1.569 bisitz 6936: my $checked; if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 6937: $r->print("
6938: <label>
1.569 bisitz 6939: <input type='radio' name='scantron_CODE_resolution' value='use_unfound'$checked />
1.492 albertel 6940: ".&mt("Use the CODE [_1] that is was on the paper, ignoring the error.",
6941: "<b><tt>".$$scan_record{'scantron.CODE'}."</tt></b>")."
6942: </label>");
1.273 albertel 6943: $r->print("\n<br />");
6944: }
1.194 albertel 6945:
1.188 albertel 6946: $r->print(<<ENDSCRIPT);
6947: <script type="text/javascript">
6948: function change_radio(field) {
1.190 albertel 6949: var slct=document.scantronupload.scantron_CODE_resolution;
1.188 albertel 6950: var i;
6951: for (i=0;i<slct.length;i++) {
6952: if (slct[i].value==field) { slct[i].checked=true; }
6953: }
6954: }
6955: </script>
6956: ENDSCRIPT
1.187 albertel 6957: my $href="/adm/pickcode?".
1.359 www 6958: "form=".&escape("scantronupload").
6959: "&scantron_format=".&escape($env{'form.scantron_format'}).
6960: "&scantron_CODElist=".&escape($env{'form.scantron_CODElist'}).
6961: "&curCODE=".&escape($$scan_record{'scantron.CODE'}).
6962: "&scantron_selectfile=".&escape($env{'form.scantron_selectfile'});
1.332 albertel 6963: if ($env{'form.scantron_CODElist'} =~ /\S/) {
1.492 albertel 6964: $r->print("
6965: <label>
6966: <input type='radio' name='scantron_CODE_resolution' value='use_found' />
6967: ".&mt("[_1]Select[_2] a CODE from the list of all CODEs and use it.",
6968: "<a target='_blank' href='$href'>","</a>")."
6969: </label>
1.558 bisitz 6970: ".&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 6971: $r->print("\n<br />");
6972: }
1.492 albertel 6973: $r->print("
6974: <label>
6975: <input type='radio' name='scantron_CODE_resolution' value='use_typed' />
6976: ".&mt("Use [_1] as the CODE.",
6977: "</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 6978: $r->print("\n<br /><br />");
1.157 albertel 6979: } elsif ($error eq 'doublebubble') {
1.503 raeburn 6980: $r->print("<p>".&mt("There have been multiple bubbles scanned for some question(s)")."</p>\n");
1.497 foxr 6981:
6982: # The form field scantron_questions is acutally a list of line numbers.
6983: # represented by this form so:
6984:
6985: my $line_list = &questions_to_line_list($arg);
6986:
1.157 albertel 6987: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 6988: $line_list.'" />');
1.242 albertel 6989: $r->print($message);
1.492 albertel 6990: $r->print("<p>".&mt("Please indicate which bubble should be used for grading")."</p>");
1.157 albertel 6991: foreach my $question (@{$arg}) {
1.503 raeburn 6992: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
6993: $scan_record, $error);
1.524 raeburn 6994: push(@lines_to_correct,@linenums);
1.157 albertel 6995: }
1.503 raeburn 6996: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 6997: } elsif ($error eq 'missingbubble') {
1.492 albertel 6998: $r->print("<p>".&mt("There have been <b>no</b> bubbles scanned for some question(s)")."</p>\n");
1.242 albertel 6999: $r->print($message);
1.492 albertel 7000: $r->print("<p>".&mt("Please indicate which bubble should be used for grading.")."</p>");
1.503 raeburn 7001: $r->print(&mt("Some questions have no scanned bubbles.")."\n");
1.497 foxr 7002:
1.503 raeburn 7003: # The form field scantron_questions is actually a list of line numbers not
1.497 foxr 7004: # a list of question numbers. Therefore:
7005: #
7006:
7007: my $line_list = &questions_to_line_list($arg);
7008:
1.157 albertel 7009: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 7010: $line_list.'" />');
1.157 albertel 7011: foreach my $question (@{$arg}) {
1.503 raeburn 7012: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
7013: $scan_record, $error);
1.524 raeburn 7014: push(@lines_to_correct,@linenums);
1.157 albertel 7015: }
1.503 raeburn 7016: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 7017: } else {
7018: $r->print("\n<ul>");
7019: }
7020: $r->print("\n</li></ul>");
1.497 foxr 7021: }
7022:
1.503 raeburn 7023: sub verify_bubbles_checked {
7024: my (@ansnums) = @_;
7025: my $ansnumstr = join('","',@ansnums);
7026: my $warning = &mt("A bubble or 'No bubble' selection has not been made for one or more lines.");
7027: my $output = (<<ENDSCRIPT);
7028: <script type="text/javascript">
7029: function verify_bubble_radio(form) {
7030: var ansnumArray = new Array ("$ansnumstr");
7031: var need_bubble_count = 0;
7032: for (var i=0; i<ansnumArray.length; i++) {
7033: if (form.elements["scantron_correct_Q_"+ansnumArray[i]].length > 1) {
7034: var bubble_picked = 0;
7035: for (var j=0; j<form.elements["scantron_correct_Q_"+ansnumArray[i]].length; j++) {
7036: if (form.elements["scantron_correct_Q_"+ansnumArray[i]][j].checked == true) {
7037: bubble_picked = 1;
7038: }
7039: }
7040: if (bubble_picked == 0) {
7041: need_bubble_count ++;
7042: }
7043: }
7044: }
7045: if (need_bubble_count) {
7046: alert("$warning");
7047: return;
7048: }
7049: form.submit();
7050: }
7051: </script>
7052: ENDSCRIPT
7053: return $output;
7054: }
7055:
1.497 foxr 7056: =pod
7057:
7058: =item questions_to_line_list
1.157 albertel 7059:
1.497 foxr 7060: Converts a list of questions into a string of comma separated
7061: line numbers in the answer sheet used by the questions. This is
7062: used to fill in the scantron_questions form field.
7063:
7064: Arguments:
7065: questions - Reference to an array of questions.
7066:
7067: =cut
7068:
7069:
7070: sub questions_to_line_list {
7071: my ($questions) = @_;
7072: my @lines;
7073:
1.503 raeburn 7074: foreach my $item (@{$questions}) {
7075: my $question = $item;
7076: my ($first,$count,$last);
7077: if ($item =~ /^(\d+)\.(\d+)$/) {
7078: $question = $1;
7079: my $subquestion = $2;
7080: $first = $first_bubble_line{$question-1} + 1;
7081: my @subans = split(/,/,$subdivided_bubble_lines{$question-1});
7082: my $subcount = 1;
7083: while ($subcount<$subquestion) {
7084: $first += $subans[$subcount-1];
7085: $subcount ++;
7086: }
7087: $count = $subans[$subquestion-1];
7088: } else {
7089: $first = $first_bubble_line{$question-1} + 1;
7090: $count = $bubble_lines_per_response{$question-1};
7091: }
1.506 raeburn 7092: $last = $first+$count-1;
1.503 raeburn 7093: push(@lines, ($first..$last));
1.497 foxr 7094: }
7095: return join(',', @lines);
7096: }
7097:
7098: =pod
7099:
7100: =item prompt_for_corrections
7101:
7102: Prompts for a potentially multiline correction to the
7103: user's bubbling (factors out common code from scantron_get_correction
7104: for multi and missing bubble cases).
7105:
7106: Arguments:
7107: $r - Apache request object.
7108: $question - The question number to prompt for.
7109: $scan_config - The scantron file configuration hash.
7110: $scan_record - Reference to the hash that has the the parsed scanlines.
1.503 raeburn 7111: $error - Type of error
1.497 foxr 7112:
7113: Implicit inputs:
7114: %bubble_lines_per_response - Starting line numbers for each question.
7115: Numbered from 0 (but question numbers are from
7116: 1.
7117: %first_bubble_line - Starting bubble line for each question.
1.509 raeburn 7118: %subdivided_bubble_lines - optionresponse, matchresponse and rankresponse
7119: type problems render as separate sub-questions,
1.503 raeburn 7120: in exam mode. This hash contains a
7121: comma-separated list of the lines per
7122: sub-question.
1.510 raeburn 7123: %responsetype_per_response - essayresponse, formularesponse,
7124: stringresponse, imageresponse, reactionresponse,
7125: and organicresponse type problem parts can have
1.503 raeburn 7126: multiple lines per response if the weight
7127: assigned exceeds 10. In this case, only
7128: one bubble per line is permitted, but more
7129: than one line might contain bubbles, e.g.
7130: bubbling of: line 1 - J, line 2 - J,
7131: line 3 - B would assign 22 points.
1.497 foxr 7132:
7133: =cut
7134:
7135: sub prompt_for_corrections {
1.503 raeburn 7136: my ($r, $question, $scan_config, $scan_record, $error) = @_;
7137: my ($current_line,$lines);
7138: my @linenums;
7139: my $questionnum = $question;
7140: if ($question =~ /^(\d+)\.(\d+)$/) {
7141: $question = $1;
7142: $current_line = $first_bubble_line{$question-1} + 1 ;
7143: my $subquestion = $2;
7144: my @subans = split(/,/,$subdivided_bubble_lines{$question-1});
7145: my $subcount = 1;
7146: while ($subcount<$subquestion) {
7147: $current_line += $subans[$subcount-1];
7148: $subcount ++;
7149: }
7150: $lines = $subans[$subquestion-1];
7151: } else {
7152: $current_line = $first_bubble_line{$question-1} + 1 ;
7153: $lines = $bubble_lines_per_response{$question-1};
7154: }
1.497 foxr 7155: if ($lines > 1) {
1.503 raeburn 7156: $r->print(&mt('The group of bubble lines below responds to a single question.').'<br />');
7157: if (($responsetype_per_response{$question-1} eq 'essayresponse') ||
7158: ($responsetype_per_response{$question-1} eq 'formularesponse') ||
1.510 raeburn 7159: ($responsetype_per_response{$question-1} eq 'stringresponse') ||
7160: ($responsetype_per_response{$question-1} eq 'imageresponse') ||
7161: ($responsetype_per_response{$question-1} eq 'reactionresponse') ||
7162: ($responsetype_per_response{$question-1} eq 'organicresponse')) {
1.572 www 7163: $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 7164: } else {
7165: $r->print(&mt("Select at most one bubble in a single line and select 'No Bubble' in all the other lines. ")."<br />");
7166: }
1.497 foxr 7167: }
7168: for (my $i =0; $i < $lines; $i++) {
1.503 raeburn 7169: my $selected = $$scan_record{"scantron.$current_line.answer"};
7170: &scantron_bubble_selector($r,$scan_config,$current_line,
7171: $questionnum,$error,split('', $selected));
1.524 raeburn 7172: push(@linenums,$current_line);
1.497 foxr 7173: $current_line++;
7174: }
7175: if ($lines > 1) {
7176: $r->print("<hr /><br />");
7177: }
1.503 raeburn 7178: return @linenums;
1.157 albertel 7179: }
1.423 albertel 7180:
7181: =pod
7182:
7183: =item scantron_bubble_selector
7184:
7185: Generates the html radiobuttons to correct a single bubble line
1.424 albertel 7186: possibly showing the existing the selected bubbles if known
1.423 albertel 7187:
7188: Arguments:
7189: $r - Apache request object
7190: $scan_config - hash from &get_scantron_config()
1.497 foxr 7191: $line - Number of the line being displayed.
1.503 raeburn 7192: $questionnum - Question number (may include subquestion)
7193: $error - Type of error.
1.497 foxr 7194: @selected - Array of bubbles picked on this line.
1.423 albertel 7195:
7196: =cut
7197:
1.157 albertel 7198: sub scantron_bubble_selector {
1.503 raeburn 7199: my ($r,$scan_config,$line,$questionnum,$error,@selected)=@_;
1.157 albertel 7200: my $max=$$scan_config{'Qlength'};
1.274 albertel 7201:
7202: my $scmode=$$scan_config{'Qon'};
7203: if ($scmode eq 'number' || $scmode eq 'letter') { $max=10; }
7204:
1.157 albertel 7205: my @alphabet=('A'..'Z');
1.503 raeburn 7206: $r->print(&Apache::loncommon::start_data_table().
7207: &Apache::loncommon::start_data_table_row());
7208: $r->print('<td rowspan="2" class="LC_leftcol_header">'.$line.'</td>');
1.497 foxr 7209: for (my $i=0;$i<$max+1;$i++) {
7210: $r->print("\n".'<td align="center">');
7211: if ($selected[0] eq $alphabet[$i]) { $r->print('X'); shift(@selected) }
7212: else { $r->print(' '); }
7213: $r->print('</td>');
7214: }
1.503 raeburn 7215: $r->print(&Apache::loncommon::end_data_table_row().
7216: &Apache::loncommon::start_data_table_row());
1.497 foxr 7217: for (my $i=0;$i<$max;$i++) {
7218: $r->print("\n".
7219: '<td><label><input type="radio" name="scantron_correct_Q_'.
7220: $line.'" value="'.$i.'" />'.$alphabet[$i]."</label></td>");
7221: }
1.503 raeburn 7222: my $nobub_checked = ' ';
7223: if ($error eq 'missingbubble') {
7224: $nobub_checked = ' checked = "checked" ';
7225: }
7226: $r->print("\n".'<td><label><input type="radio" name="scantron_correct_Q_'.
7227: $line.'" value="none"'.$nobub_checked.'/>'.&mt('No bubble').
7228: '</label>'."\n".'<input type="hidden" name="scantron_questionnum_Q_'.
7229: $line.'" value="'.$questionnum.'" /></td>');
7230: $r->print(&Apache::loncommon::end_data_table_row().
7231: &Apache::loncommon::end_data_table());
1.157 albertel 7232: }
7233:
1.423 albertel 7234: =pod
7235:
7236: =item num_matches
7237:
1.424 albertel 7238: Counts the number of characters that are the same between the two arguments.
7239:
7240: Arguments:
7241: $orig - CODE from the scanline
7242: $code - CODE to match against
7243:
7244: Returns:
7245: $count - integer count of the number of same characters between the
7246: two arguments
7247:
1.423 albertel 7248: =cut
7249:
1.194 albertel 7250: sub num_matches {
7251: my ($orig,$code) = @_;
7252: my @code=split(//,$code);
7253: my @orig=split(//,$orig);
7254: my $same=0;
7255: for (my $i=0;$i<scalar(@code);$i++) {
7256: if ($code[$i] eq $orig[$i]) { $same++; }
7257: }
7258: return $same;
7259: }
7260:
1.423 albertel 7261: =pod
7262:
7263: =item scantron_get_closely_matching_CODEs
7264:
1.424 albertel 7265: Cycles through all CODEs and finds the set that has the greatest
7266: number of same characters as the provided CODE
7267:
7268: Arguments:
7269: $allcodes - hash ref returned by &get_codes()
7270: $CODE - CODE from the current scanline
7271:
7272: Returns:
7273: 2 element list
7274: - first elements is number of how closely matching the best fit is
7275: (5 means best set has 5 matching characters)
7276: - second element is an arrary ref containing the set of valid CODEs
7277: that best fit the passed in CODE
7278:
1.423 albertel 7279: =cut
7280:
1.194 albertel 7281: sub scantron_get_closely_matching_CODEs {
7282: my ($allcodes,$CODE)=@_;
7283: my @CODEs;
7284: foreach my $testcode (sort(keys(%{$allcodes}))) {
7285: push(@{$CODEs[&num_matches($CODE,$testcode)]},$testcode);
7286: }
7287:
7288: return ($#CODEs,$CODEs[-1]);
7289: }
7290:
1.423 albertel 7291: =pod
7292:
7293: =item get_codes
7294:
1.424 albertel 7295: Builds a hash which has keys of all of the valid CODEs from the selected
7296: set of remembered CODEs.
7297:
7298: Arguments:
7299: $old_name - name of the set of remembered CODEs
7300: $cdom - domain of the course
7301: $cnum - internal course name
7302:
7303: Returns:
7304: %allcodes - keys are the valid CODEs, values are all 1
7305:
1.423 albertel 7306: =cut
7307:
1.194 albertel 7308: sub get_codes {
1.280 foxr 7309: my ($old_name, $cdom, $cnum) = @_;
7310: if (!$old_name) {
7311: $old_name=$env{'form.scantron_CODElist'};
7312: }
7313: if (!$cdom) {
7314: $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
7315: }
7316: if (!$cnum) {
7317: $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
7318: }
1.278 albertel 7319: my %result=&Apache::lonnet::get('CODEs',[$old_name,"type\0$old_name"],
7320: $cdom,$cnum);
7321: my %allcodes;
7322: if ($result{"type\0$old_name"} eq 'number') {
7323: %allcodes=map {($_,1)} split(',',$result{$old_name});
7324: } else {
7325: %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
7326: }
1.194 albertel 7327: return %allcodes;
7328: }
7329:
1.423 albertel 7330: =pod
7331:
7332: =item scantron_validate_CODE
7333:
1.424 albertel 7334: Validates all scanlines in the selected file to not have any
7335: invalid or underspecified CODEs and that none of the codes are
7336: duplicated if this was requested.
7337:
1.423 albertel 7338: =cut
7339:
1.157 albertel 7340: sub scantron_validate_CODE {
7341: my ($r,$currentphase) = @_;
1.257 albertel 7342: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.186 albertel 7343: if ($scantron_config{'CODElocation'} &&
7344: $scantron_config{'CODEstart'} &&
7345: $scantron_config{'CODElength'}) {
1.257 albertel 7346: if (!defined($env{'form.scantron_CODElist'})) {
1.186 albertel 7347: &FIXME_blow_up()
7348: }
7349: } else {
7350: return (0,$currentphase+1);
7351: }
7352:
7353: my %usedCODEs;
7354:
1.194 albertel 7355: my %allcodes=&get_codes();
1.186 albertel 7356:
1.582 raeburn 7357: my $nav_error;
7358: &scantron_get_maxbubble(\$nav_error); # parse needs the lines per response array.
7359: if ($nav_error) {
7360: $r->print(&navmap_errormsg());
7361: return(1,$currentphase);
7362: }
1.447 foxr 7363:
1.186 albertel 7364: my ($scanlines,$scan_data)=&scantron_getfile();
7365: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7366: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.186 albertel 7367: if ($line=~/^[\s\cz]*$/) { next; }
7368: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7369: $scan_data);
7370: my $CODE=$$scan_record{'scantron.CODE'};
7371: my $error=0;
1.224 albertel 7372: if (!&Apache::lonnet::validCODE($CODE)) {
7373: &scantron_get_correction($r,$i,$scan_record,
7374: \%scantron_config,
7375: $line,'incorrectCODE',\%allcodes);
7376: return(1,$currentphase);
7377: }
1.221 albertel 7378: if (%allcodes && !exists($allcodes{$CODE})
7379: && !$$scan_record{'scantron.useCODE'}) {
1.186 albertel 7380: &scantron_get_correction($r,$i,$scan_record,
7381: \%scantron_config,
1.194 albertel 7382: $line,'incorrectCODE',\%allcodes);
7383: return(1,$currentphase);
1.186 albertel 7384: }
1.214 albertel 7385: if (exists($usedCODEs{$CODE})
1.257 albertel 7386: && $env{'form.scantron_CODEunique'} eq 'yes'
1.192 albertel 7387: && !$$scan_record{'scantron.CODE_ignore_dup'}) {
1.186 albertel 7388: &scantron_get_correction($r,$i,$scan_record,
7389: \%scantron_config,
1.194 albertel 7390: $line,'duplicateCODE',$usedCODEs{$CODE});
7391: return(1,$currentphase);
1.186 albertel 7392: }
1.524 raeburn 7393: push(@{$usedCODEs{$CODE}},$$scan_record{'scantron.PaperID'});
1.186 albertel 7394: }
1.157 albertel 7395: return (0,$currentphase+1);
7396: }
7397:
1.423 albertel 7398: =pod
7399:
7400: =item scantron_validate_doublebubble
7401:
1.424 albertel 7402: Validates all scanlines in the selected file to not have any
7403: bubble lines with multiple bubbles marked.
7404:
1.423 albertel 7405: =cut
7406:
1.157 albertel 7407: sub scantron_validate_doublebubble {
7408: my ($r,$currentphase) = @_;
7409: #get student info
7410: my $classlist=&Apache::loncoursedata::get_classlist();
7411: my %idmap=&username_to_idmap($classlist);
7412:
7413: #get scantron line setup
1.257 albertel 7414: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7415: my ($scanlines,$scan_data)=&scantron_getfile();
1.583 raeburn 7416: my $nav_error;
7417: &scantron_get_maxbubble(\$nav_error); # parse needs the bubble line array.
7418: if ($nav_error) {
7419: $r->print(&navmap_errormsg());
7420: return(1,$currentphase);
7421: }
1.447 foxr 7422:
1.157 albertel 7423: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7424: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7425: if ($line=~/^[\s\cz]*$/) { next; }
7426: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7427: $scan_data);
7428: if (!defined($$scan_record{'scantron.doubleerror'})) { next; }
7429: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,$line,
7430: 'doublebubble',
7431: $$scan_record{'scantron.doubleerror'});
7432: return (1,$currentphase);
7433: }
7434: return (0,$currentphase+1);
7435: }
7436:
1.423 albertel 7437:
1.503 raeburn 7438: sub scantron_get_maxbubble {
1.582 raeburn 7439: my ($nav_error) = @_;
1.257 albertel 7440: if (defined($env{'form.scantron_maxbubble'}) &&
7441: $env{'form.scantron_maxbubble'}) {
1.447 foxr 7442: &restore_bubble_lines();
1.257 albertel 7443: return $env{'form.scantron_maxbubble'};
1.191 albertel 7444: }
1.330 albertel 7445:
1.447 foxr 7446: my (undef, undef, $sequence) =
1.257 albertel 7447: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.330 albertel 7448:
1.447 foxr 7449: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 7450: unless (ref($navmap)) {
7451: if (ref($nav_error)) {
7452: $$nav_error = 1;
7453: }
7454: }
1.191 albertel 7455: my $map=$navmap->getResourceByUrl($sequence);
7456: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.330 albertel 7457:
7458: &Apache::lonxml::clear_problem_counter();
7459:
1.557 raeburn 7460: my $uname = $env{'user.name'};
7461: my $udom = $env{'user.domain'};
1.435 foxr 7462: my $cid = $env{'request.course.id'};
7463: my $total_lines = 0;
7464: %bubble_lines_per_response = ();
1.447 foxr 7465: %first_bubble_line = ();
1.503 raeburn 7466: %subdivided_bubble_lines = ();
7467: %responsetype_per_response = ();
1.554 raeburn 7468:
1.447 foxr 7469: my $response_number = 0;
7470: my $bubble_line = 0;
1.191 albertel 7471: foreach my $resource (@resources) {
1.542 raeburn 7472: my ($analysis,$parts) = &scantron_partids_tograde($resource,$cid,$uname,$udom);
7473: if ((ref($analysis) eq 'HASH') && (ref($parts) eq 'ARRAY')) {
7474: foreach my $part_id (@{$parts}) {
7475: my $lines;
7476:
7477: # TODO - make this a persistent hash not an array.
7478:
7479: # optionresponse, matchresponse and rankresponse type items
7480: # render as separate sub-questions in exam mode.
7481: if (($analysis->{$part_id.'.type'} eq 'optionresponse') ||
7482: ($analysis->{$part_id.'.type'} eq 'matchresponse') ||
7483: ($analysis->{$part_id.'.type'} eq 'rankresponse')) {
7484: my ($numbub,$numshown);
7485: if ($analysis->{$part_id.'.type'} eq 'optionresponse') {
7486: if (ref($analysis->{$part_id.'.options'}) eq 'ARRAY') {
7487: $numbub = scalar(@{$analysis->{$part_id.'.options'}});
7488: }
7489: } elsif ($analysis->{$part_id.'.type'} eq 'matchresponse') {
7490: if (ref($analysis->{$part_id.'.items'}) eq 'ARRAY') {
7491: $numbub = scalar(@{$analysis->{$part_id.'.items'}});
7492: }
7493: } elsif ($analysis->{$part_id.'.type'} eq 'rankresponse') {
7494: if (ref($analysis->{$part_id.'.foils'}) eq 'ARRAY') {
7495: $numbub = scalar(@{$analysis->{$part_id.'.foils'}});
7496: }
7497: }
7498: if (ref($analysis->{$part_id.'.shown'}) eq 'ARRAY') {
7499: $numshown = scalar(@{$analysis->{$part_id.'.shown'}});
7500: }
7501: my $bubbles_per_line = 10;
7502: my $inner_bubble_lines = int($numbub/$bubbles_per_line);
7503: if (($numbub % $bubbles_per_line) != 0) {
7504: $inner_bubble_lines++;
7505: }
7506: for (my $i=0; $i<$numshown; $i++) {
7507: $subdivided_bubble_lines{$response_number} .=
7508: $inner_bubble_lines.',';
7509: }
7510: $subdivided_bubble_lines{$response_number} =~ s/,$//;
7511: $lines = $numshown * $inner_bubble_lines;
7512: } else {
7513: $lines = $analysis->{"$part_id.bubble_lines"};
7514: }
7515:
7516: $first_bubble_line{$response_number} = $bubble_line;
7517: $bubble_lines_per_response{$response_number} = $lines;
7518: $responsetype_per_response{$response_number} =
7519: $analysis->{$part_id.'.type'};
7520: $response_number++;
7521:
7522: $bubble_line += $lines;
7523: $total_lines += $lines;
7524: }
7525: }
7526: }
1.552 raeburn 7527: &Apache::lonnet::delenv('scantron.');
1.542 raeburn 7528:
7529: &save_bubble_lines();
7530: $env{'form.scantron_maxbubble'} =
7531: $total_lines;
7532: return $env{'form.scantron_maxbubble'};
7533: }
1.523 raeburn 7534:
1.157 albertel 7535: sub scantron_validate_missingbubbles {
7536: my ($r,$currentphase) = @_;
7537: #get student info
7538: my $classlist=&Apache::loncoursedata::get_classlist();
7539: my %idmap=&username_to_idmap($classlist);
7540:
7541: #get scantron line setup
1.257 albertel 7542: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7543: my ($scanlines,$scan_data)=&scantron_getfile();
1.582 raeburn 7544: my $nav_error;
7545: my $max_bubble=&scantron_get_maxbubble(\$nav_error);
7546: if ($nav_error) {
7547: return(1,$currentphase);
7548: }
1.157 albertel 7549: if (!$max_bubble) { $max_bubble=2**31; }
7550: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7551: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7552: if ($line=~/^[\s\cz]*$/) { next; }
7553: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7554: $scan_data);
7555: if (!defined($$scan_record{'scantron.missingerror'})) { next; }
7556: my @to_correct;
1.470 foxr 7557:
7558: # Probably here's where the error is...
7559:
1.157 albertel 7560: foreach my $missing (@{$$scan_record{'scantron.missingerror'}}) {
1.505 raeburn 7561: my $lastbubble;
7562: if ($missing =~ /^(\d+)\.(\d+)$/) {
7563: my $question = $1;
7564: my $subquestion = $2;
7565: if (!defined($first_bubble_line{$question -1})) { next; }
7566: my $first = $first_bubble_line{$question-1};
7567: my @subans = split(/,/,$subdivided_bubble_lines{$question-1});
7568: my $subcount = 1;
7569: while ($subcount<$subquestion) {
7570: $first += $subans[$subcount-1];
7571: $subcount ++;
7572: }
7573: my $count = $subans[$subquestion-1];
7574: $lastbubble = $first + $count;
7575: } else {
7576: if (!defined($first_bubble_line{$missing - 1})) { next; }
7577: $lastbubble = $first_bubble_line{$missing - 1} + $bubble_lines_per_response{$missing - 1};
7578: }
7579: if ($lastbubble > $max_bubble) { next; }
1.157 albertel 7580: push(@to_correct,$missing);
7581: }
7582: if (@to_correct) {
7583: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
7584: $line,'missingbubble',\@to_correct);
7585: return (1,$currentphase);
7586: }
7587:
7588: }
7589: return (0,$currentphase+1);
7590: }
7591:
1.423 albertel 7592:
1.82 albertel 7593: sub scantron_process_students {
1.75 albertel 7594: my ($r) = @_;
1.513 foxr 7595:
1.257 albertel 7596: my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($env{'form.selectpage'});
1.324 albertel 7597: my ($symb)=&get_symb($r);
1.513 foxr 7598: if (!$symb) {
7599: return '';
7600: }
1.324 albertel 7601: my $default_form_data=&defaultFormData($symb);
1.82 albertel 7602:
1.257 albertel 7603: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7604: my ($scanlines,$scan_data)=&scantron_getfile();
1.82 albertel 7605: my $classlist=&Apache::loncoursedata::get_classlist();
7606: my %idmap=&username_to_idmap($classlist);
1.132 bowersj2 7607: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 7608: unless (ref($navmap)) {
7609: $r->print(&navmap_errormsg());
7610: return '';
7611: }
1.83 albertel 7612: my $map=$navmap->getResourceByUrl($sequence);
7613: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.557 raeburn 7614: my (%grader_partids_by_symb,%grader_randomlists_by_symb);
7615: &graders_resources_pass(\@resources,\%grader_partids_by_symb,
7616: \%grader_randomlists_by_symb);
1.586 raeburn 7617: my $resource_error;
1.557 raeburn 7618: foreach my $resource (@resources) {
1.586 raeburn 7619: my $ressymb;
7620: if (ref($resource)) {
7621: $ressymb = $resource->symb();
7622: } else {
7623: $resource_error = 1;
7624: last;
7625: }
1.557 raeburn 7626: my ($analysis,$parts) =
7627: &scantron_partids_tograde($resource,$env{'request.course.id'},
7628: $env{'user.name'},$env{'user.domain'},1);
7629: $grader_partids_by_symb{$ressymb} = $parts;
7630: if (ref($analysis) eq 'HASH') {
7631: if (ref($analysis->{'parts_withrandomlist'}) eq 'ARRAY') {
7632: $grader_randomlists_by_symb{$ressymb} =
7633: $analysis->{'parts_withrandomlist'};
7634: }
7635: }
7636: }
1.586 raeburn 7637: if ($resource_error) {
7638: $r->print(&navmap_errormsg());
7639: return '';
7640: }
1.557 raeburn 7641:
1.554 raeburn 7642: my ($uname,$udom);
1.82 albertel 7643: my $result= <<SCANTRONFORM;
1.81 albertel 7644: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
7645: <input type="hidden" name="command" value="scantron_configphase" />
7646: $default_form_data
7647: SCANTRONFORM
1.82 albertel 7648: $r->print($result);
7649:
7650: my @delayqueue;
1.542 raeburn 7651: my (%completedstudents,%scandata);
1.140 albertel 7652:
1.520 www 7653: my $lock=&Apache::lonnet::set_lock(&mt('Grading bubblesheet exam'));
1.200 albertel 7654: my $count=&get_todo_count($scanlines,$scan_data);
1.575 www 7655: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Bubblesheet Status',
7656: 'Bubblesheet Progress',$count,
1.195 albertel 7657: 'inline',undef,'scantronupload');
1.140 albertel 7658: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
7659: 'Processing first student');
1.542 raeburn 7660: $r->print('<br />');
1.140 albertel 7661: my $start=&Time::HiRes::time();
1.158 albertel 7662: my $i=-1;
1.542 raeburn 7663: my $started;
1.447 foxr 7664:
1.582 raeburn 7665: my $nav_error;
7666: &scantron_get_maxbubble(\$nav_error); # Need the bubble lines array to parse.
7667: if ($nav_error) {
7668: $r->print(&navmap_errormsg());
7669: return '';
7670: }
7671:
1.513 foxr 7672: # If an ssi failed in scantron_get_maxbubble, put an error message out to
7673: # the user and return.
7674:
7675: if ($ssi_error) {
7676: $r->print("</form>");
7677: &ssi_print_error($r);
7678: $r->print(&show_grading_menu_form($symb));
1.520 www 7679: &Apache::lonnet::remove_lock($lock);
1.513 foxr 7680: return ''; # Dunno why the other returns return '' rather than just returning.
7681: }
1.447 foxr 7682:
1.542 raeburn 7683: my %lettdig = &letter_to_digits();
7684: my $numletts = scalar(keys(%lettdig));
7685:
1.157 albertel 7686: while ($i<$scanlines->{'count'}) {
7687: ($uname,$udom)=('','');
7688: $i++;
1.200 albertel 7689: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7690: if ($line=~/^[\s\cz]*$/) { next; }
1.200 albertel 7691: if ($started) {
7692: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
7693: 'last student');
7694: }
7695: $started=1;
1.157 albertel 7696: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7697: $scan_data);
7698: unless ($uname=&scantron_find_student($scan_record,$scan_data,
7699: \%idmap,$i)) {
7700: &scantron_add_delay(\@delayqueue,$line,
7701: 'Unable to find a student that matches',1);
7702: next;
7703: }
7704: if (exists $completedstudents{$uname}) {
7705: &scantron_add_delay(\@delayqueue,$line,
7706: 'Student '.$uname.' has multiple sheets',2);
7707: next;
7708: }
7709: ($uname,$udom)=split(/:/,$uname);
1.330 albertel 7710:
1.586 raeburn 7711: my (%partids_by_symb,$res_error);
1.554 raeburn 7712: foreach my $resource (@resources) {
1.586 raeburn 7713: my $ressymb;
7714: if (ref($resource)) {
7715: $ressymb = $resource->symb();
7716: } else {
7717: $res_error = 1;
7718: last;
7719: }
1.557 raeburn 7720: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
7721: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
7722: my ($analysis,$parts) =
7723: &scantron_partids_tograde($resource,$env{'request.course.id'},$uname,$udom);
7724: $partids_by_symb{$ressymb} = $parts;
7725: } else {
7726: $partids_by_symb{$ressymb} = $grader_partids_by_symb{$ressymb};
7727: }
1.554 raeburn 7728: }
7729:
1.586 raeburn 7730: if ($res_error) {
7731: &scantron_add_delay(\@delayqueue,$line,
7732: 'An error occurred while grading student '.$uname,2);
7733: next;
7734: }
7735:
1.330 albertel 7736: &Apache::lonxml::clear_problem_counter();
1.514 raeburn 7737: &Apache::lonnet::appenv($scan_record);
1.376 albertel 7738:
7739: if (&scantron_clear_skip($scanlines,$scan_data,$i)) {
7740: &scantron_putfile($scanlines,$scan_data);
7741: }
1.161 albertel 7742:
1.542 raeburn 7743: my $scancode;
7744: if ((exists($scan_record->{'scantron.CODE'})) &&
7745: (&Apache::lonnet::validCODE($scan_record->{'scantron.CODE'}))) {
7746: $scancode = $scan_record->{'scantron.CODE'};
7747: } else {
7748: $scancode = '';
7749: }
7750:
7751: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
1.554 raeburn 7752: \@resources,\%partids_by_symb) eq 'ssi_error') {
1.542 raeburn 7753: $ssi_error = 0; # So end of handler error message does not trigger.
7754: $r->print("</form>");
7755: &ssi_print_error($r);
7756: $r->print(&show_grading_menu_form($symb));
7757: &Apache::lonnet::remove_lock($lock);
7758: return ''; # Why return ''? Beats me.
7759: }
1.513 foxr 7760:
1.140 albertel 7761: $completedstudents{$uname}={'line'=>$line};
1.542 raeburn 7762: if ($env{'form.verifyrecord'}) {
7763: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
7764: my $studentdata = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
7765: chomp($studentdata);
7766: $studentdata =~ s/\r$//;
7767: my $studentrecord = '';
7768: my $counter = -1;
7769: foreach my $resource (@resources) {
1.554 raeburn 7770: my $ressymb = $resource->symb();
1.542 raeburn 7771: ($counter,my $recording) =
7772: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 7773: $counter,$studentdata,$partids_by_symb{$ressymb},
1.542 raeburn 7774: \%scantron_config,\%lettdig,$numletts);
7775: $studentrecord .= $recording;
7776: }
7777: if ($studentrecord ne $studentdata) {
1.554 raeburn 7778: &Apache::lonxml::clear_problem_counter();
7779: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
7780: \@resources,\%partids_by_symb) eq 'ssi_error') {
7781: $ssi_error = 0; # So end of handler error message does not trigger.
7782: $r->print("</form>");
7783: &ssi_print_error($r);
7784: $r->print(&show_grading_menu_form($symb));
7785: &Apache::lonnet::remove_lock($lock);
7786: delete($completedstudents{$uname});
7787: return '';
7788: }
1.542 raeburn 7789: $counter = -1;
7790: $studentrecord = '';
7791: foreach my $resource (@resources) {
1.554 raeburn 7792: my $ressymb = $resource->symb();
1.542 raeburn 7793: ($counter,my $recording) =
7794: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 7795: $counter,$studentdata,$partids_by_symb{$ressymb},
1.542 raeburn 7796: \%scantron_config,\%lettdig,$numletts);
7797: $studentrecord .= $recording;
7798: }
7799: if ($studentrecord ne $studentdata) {
7800: $r->print('<p><span class="LC_error">');
7801: if ($scancode eq '') {
7802: $r->print(&mt('Mismatch grading bubble sheet for user: [_1] with ID: [_2].',
7803: $uname.':'.$udom,$scan_record->{'scantron.ID'}));
7804: } else {
7805: $r->print(&mt('Mismatch grading bubble sheet for user: [_1] with ID: [_2] and CODE: [_3].',
7806: $uname.':'.$udom,$scan_record->{'scantron.ID'},$scancode));
7807: }
7808: $r->print('</span><br />'.&Apache::loncommon::start_data_table()."\n".
7809: &Apache::loncommon::start_data_table_header_row()."\n".
7810: '<th>'.&mt('Source').'</th><th>'.&mt('Bubbled responses').'</th>'.
7811: &Apache::loncommon::end_data_table_header_row()."\n".
7812: &Apache::loncommon::start_data_table_row().
7813: '<td>'.&mt('Bubble Sheet').'</td>'.
7814: '<td><span class="LC_nobreak">'.$studentdata.'</span></td>'.
7815: &Apache::loncommon::end_data_table_row().
7816: &Apache::loncommon::start_data_table_row().
7817: '<td>Stored submissions</td>'.
7818: '<td><span class="LC_nobreak">'.$studentrecord.'</span></td>'."\n".
7819: &Apache::loncommon::end_data_table_row().
7820: &Apache::loncommon::end_data_table().'</p>');
7821: } else {
7822: $r->print('<br /><span class="LC_warning">'.
7823: &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 />'.
7824: &mt("As a consequence, this user's submission history records two tries.").
7825: '</span><br />');
7826: }
7827: }
7828: }
1.543 raeburn 7829: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.140 albertel 7830: } continue {
1.330 albertel 7831: &Apache::lonxml::clear_problem_counter();
1.552 raeburn 7832: &Apache::lonnet::delenv('scantron.');
1.82 albertel 7833: }
1.140 albertel 7834: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.520 www 7835: &Apache::lonnet::remove_lock($lock);
1.172 albertel 7836: # my $lasttime = &Time::HiRes::time()-$start;
7837: # $r->print("<p>took $lasttime</p>");
1.140 albertel 7838:
1.200 albertel 7839: $r->print("</form>");
1.324 albertel 7840: $r->print(&show_grading_menu_form($symb));
1.157 albertel 7841: return '';
1.75 albertel 7842: }
1.157 albertel 7843:
1.557 raeburn 7844: sub graders_resources_pass {
7845: my ($resources,$grader_partids_by_symb,$grader_randomlists_by_symb) = @_;
7846: if ((ref($resources) eq 'ARRAY') && (ref($grader_partids_by_symb)) &&
7847: (ref($grader_randomlists_by_symb) eq 'HASH')) {
7848: foreach my $resource (@{$resources}) {
7849: my $ressymb = $resource->symb();
7850: my ($analysis,$parts) =
7851: &scantron_partids_tograde($resource,$env{'request.course.id'},
7852: $env{'user.name'},$env{'user.domain'},1);
7853: $grader_partids_by_symb->{$ressymb} = $parts;
7854: if (ref($analysis) eq 'HASH') {
7855: if (ref($analysis->{'parts_withrandomlist'}) eq 'ARRAY') {
7856: $grader_randomlists_by_symb->{$ressymb} =
7857: $analysis->{'parts_withrandomlist'};
7858: }
7859: }
7860: }
7861: }
7862: return;
7863: }
7864:
1.542 raeburn 7865: sub grade_student_bubbles {
1.554 raeburn 7866: my ($r,$uname,$udom,$scan_record,$scancode,$resources,$parts) = @_;
7867: if (ref($resources) eq 'ARRAY') {
7868: my $count = 0;
7869: foreach my $resource (@{$resources}) {
7870: my $ressymb = $resource->symb();
7871: my %form = ('submitted' => 'scantron',
7872: 'grade_target' => 'grade',
7873: 'grade_username' => $uname,
7874: 'grade_domain' => $udom,
7875: 'grade_courseid' => $env{'request.course.id'},
7876: 'grade_symb' => $ressymb,
7877: 'CODE' => $scancode
7878: );
7879: if (ref($parts) eq 'HASH') {
7880: if (ref($parts->{$ressymb}) eq 'ARRAY') {
7881: foreach my $part (@{$parts->{$ressymb}}) {
7882: $form{'scantron_questnum_start.'.$part} =
7883: 1+$env{'form.scantron.first_bubble_line.'.$count};
7884: $count++;
7885: }
7886: }
7887: }
7888: my $result=&ssi_with_retries($resource->src(),$ssi_retries,%form);
7889: return 'ssi_error' if ($ssi_error);
7890: last if (&Apache::loncommon::connection_aborted($r));
7891: }
1.542 raeburn 7892: }
7893: return;
7894: }
7895:
1.157 albertel 7896: sub scantron_upload_scantron_data {
7897: my ($r)=@_;
1.565 raeburn 7898: my $dom = $env{'request.role.domain'};
7899: my $domdesc = &Apache::lonnet::domain($dom,'description');
7900: $r->print(&Apache::loncommon::coursebrowser_javascript($dom));
1.157 albertel 7901: my $select_link=&Apache::loncommon::selectcourse_link('rules','courseid',
1.181 albertel 7902: 'domainid',
1.565 raeburn 7903: 'coursename',$dom);
7904: my $syllabuslink = '<a href="javascript:ToSyllabus();">'.&mt('Syllabus').'</a>'.
7905: (' 'x2).&mt('(shows course personnel)');
1.324 albertel 7906: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.579 raeburn 7907: my $nofile_alert = &mt('Please use the browse button to select a file from your local directory.');
7908: 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 7909: $r->print('
1.157 albertel 7910: <script type="text/javascript" language="javascript">
7911: function checkUpload(formname) {
7912: if (formname.upfile.value == "") {
1.579 raeburn 7913: alert("'.$nofile_alert.'");
1.157 albertel 7914: return false;
7915: }
1.565 raeburn 7916: if (formname.courseid.value == "") {
1.579 raeburn 7917: alert("'.$nocourseid_alert.'");
1.565 raeburn 7918: return false;
7919: }
1.157 albertel 7920: formname.submit();
7921: }
1.565 raeburn 7922:
7923: function ToSyllabus() {
7924: var cdom = '."'$dom'".';
7925: var cnum = document.rules.courseid.value;
7926: if (cdom == "" || cdom == null) {
7927: return;
7928: }
7929: if (cnum == "" || cnum == null) {
7930: return;
7931: }
7932: syllwin=window.open("/public/"+cdom+"/"+cnum+"/syllabus","LONCAPASyllabus",
7933: "height=350,width=350,scrollbars=yes,menubar=no");
7934: return;
7935: }
7936:
1.157 albertel 7937: </script>
7938:
1.566 raeburn 7939: <h3>'.&mt('Send scanned bubblesheet data to a course').'</h3>
7940:
1.492 albertel 7941: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
1.565 raeburn 7942: '.$default_form_data.
7943: &Apache::lonhtmlcommon::start_pick_box().
7944: &Apache::lonhtmlcommon::row_title(&mt('Course ID')).
7945: '<input name="courseid" type="text" size="30" />'.$select_link.
7946: &Apache::lonhtmlcommon::row_closure().
7947: &Apache::lonhtmlcommon::row_title(&mt('Course Name')).
7948: '<input name="coursename" type="text" size="30" />'.$syllabuslink.
7949: &Apache::lonhtmlcommon::row_closure().
7950: &Apache::lonhtmlcommon::row_title(&mt('Domain')).
7951: '<input name="domainid" type="hidden" />'.$domdesc.
7952: &Apache::lonhtmlcommon::row_closure().
7953: &Apache::lonhtmlcommon::row_title(&mt('File to upload')).
7954: '<input type="file" name="upfile" size="50" />'.
7955: &Apache::lonhtmlcommon::row_closure(1).
7956: &Apache::lonhtmlcommon::end_pick_box().'<br />
7957:
1.492 albertel 7958: <input name="command" value="scantronupload_save" type="hidden" />
1.589 bisitz 7959: <input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
1.157 albertel 7960: </form>
1.492 albertel 7961: ');
1.157 albertel 7962: return '';
7963: }
7964:
1.423 albertel 7965:
1.157 albertel 7966: sub scantron_upload_scantron_data_save {
7967: my($r)=@_;
1.324 albertel 7968: my ($symb)=&get_symb($r,1);
1.182 albertel 7969: my $doanotherupload=
7970: '<br /><form action="/adm/grades" method="post">'."\n".
7971: '<input type="hidden" name="command" value="scantronupload" />'."\n".
1.492 albertel 7972: '<input type="submit" name="submit" value="'.&mt('Do Another Upload').'" />'."\n".
1.182 albertel 7973: '</form>'."\n";
1.257 albertel 7974: if (!&Apache::lonnet::allowed('usc',$env{'form.domainid'}) &&
1.162 albertel 7975: !&Apache::lonnet::allowed('usc',
1.257 albertel 7976: $env{'form.domainid'}.'_'.$env{'form.courseid'})) {
1.575 www 7977: $r->print(&mt("You are not allowed to upload bubblesheet data to the requested course.")."<br />");
1.182 albertel 7978: if ($symb) {
1.324 albertel 7979: $r->print(&show_grading_menu_form($symb));
1.182 albertel 7980: } else {
7981: $r->print($doanotherupload);
7982: }
1.162 albertel 7983: return '';
7984: }
1.257 albertel 7985: my %coursedata=&Apache::lonnet::coursedescription($env{'form.domainid'}.'_'.$env{'form.courseid'});
1.568 raeburn 7986: my $uploadedfile;
1.567 raeburn 7987: $r->print('<h3>'.&mt("Uploading file to [_1]",$coursedata{'description'}).'</h3>');
1.257 albertel 7988: if (length($env{'form.upfile'}) < 2) {
1.568 raeburn 7989: $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 7990: } else {
1.568 raeburn 7991: my $result =
7992: &Apache::lonnet::userfileupload('upfile','','scantron','','','',
7993: $env{'form.courseid'},$env{'form.domainid'});
7994: if ($result =~ m{^/uploaded/}) {
1.567 raeburn 7995: $r->print(&mt('[_1]Success:[_2] Successfully uploaded [_3] bytes of data into location: [_4]',
7996: '<span class="LC_success">','</span>',(length($env{'form.upfile'})-1),
7997: '<span class="LC_filename">'.$result.'</span>'));
1.568 raeburn 7998: ($uploadedfile) = ($result =~ m{/([^/]+)$});
1.567 raeburn 7999: $r->print(&validate_uploaded_scantron_file($env{'form.domainid'},
1.568 raeburn 8000: $env{'form.courseid'},$uploadedfile));
1.210 albertel 8001: } else {
1.567 raeburn 8002: $r->print(&mt('[_1]Error:[_2] An error ([_3]) occurred when attempting to upload the file, [_4]',
8003: '<span class="LC_error">','</span>',$result,
1.568 raeburn 8004: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'));
1.183 albertel 8005: }
8006: }
1.174 albertel 8007: if ($symb) {
1.209 ng 8008: $r->print(&scantron_selectphase($r,$uploadedfile));
1.174 albertel 8009: } else {
1.182 albertel 8010: $r->print($doanotherupload);
1.174 albertel 8011: }
1.157 albertel 8012: return '';
8013: }
8014:
1.567 raeburn 8015: sub validate_uploaded_scantron_file {
8016: my ($cdom,$cname,$fname) = @_;
8017: my $scanlines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.$fname);
8018: my @lines;
8019: if ($scanlines ne '-1') {
8020: @lines=split("\n",$scanlines,-1);
8021: }
8022: my $output;
8023: if (@lines) {
8024: my (%counts,$max_match_format);
8025: my ($max_match_count,$max_match_pct) = (0,0);
8026: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cname);
8027: my %idmap = &username_to_idmap($classlist);
8028: foreach my $key (keys(%idmap)) {
8029: my $lckey = lc($key);
8030: $idmap{$lckey} = $idmap{$key};
8031: }
8032: my %unique_formats;
8033: my @formatlines = &get_scantronformat_file();
8034: foreach my $line (@formatlines) {
8035: chomp($line);
8036: my @config = split(/:/,$line);
8037: my $idstart = $config[5];
8038: my $idlength = $config[6];
8039: if (($idstart ne '') && ($idlength > 0)) {
8040: if (ref($unique_formats{$idstart.':'.$idlength}) eq 'ARRAY') {
8041: push(@{$unique_formats{$idstart.':'.$idlength}},$config[0].':'.$config[1]);
8042: } else {
8043: $unique_formats{$idstart.':'.$idlength} = [$config[0].':'.$config[1]];
8044: }
8045: }
8046: }
8047: foreach my $key (keys(%unique_formats)) {
8048: my ($idstart,$idlength) = split(':',$key);
8049: %{$counts{$key}} = (
8050: 'found' => 0,
8051: 'total' => 0,
8052: );
8053: foreach my $line (@lines) {
8054: next if ($line =~ /^#/);
8055: next if ($line =~ /^[\s\cz]*$/);
8056: my $id = substr($line,$idstart-1,$idlength);
8057: $id = lc($id);
8058: if (exists($idmap{$id})) {
8059: $counts{$key}{'found'} ++;
8060: }
8061: $counts{$key}{'total'} ++;
8062: }
8063: if ($counts{$key}{'total'}) {
8064: my $percent_match = (100*$counts{$key}{'found'})/($counts{$key}{'total'});
8065: if (($max_match_format eq '') || ($percent_match > $max_match_pct)) {
8066: $max_match_pct = $percent_match;
8067: $max_match_format = $key;
8068: $max_match_count = $counts{$key}{'total'};
8069: }
8070: }
8071: }
8072: if (ref($unique_formats{$max_match_format}) eq 'ARRAY') {
8073: my $format_descs;
8074: my $numwithformat = @{$unique_formats{$max_match_format}};
8075: for (my $i=0; $i<$numwithformat; $i++) {
8076: my ($name,$desc) = split(':',$unique_formats{$max_match_format}[$i]);
8077: if ($i<$numwithformat-2) {
8078: $format_descs .= '"<i>'.$desc.'</i>", ';
8079: } elsif ($i==$numwithformat-2) {
8080: $format_descs .= '"<i>'.$desc.'</i>" '.&mt('and').' ';
8081: } elsif ($i==$numwithformat-1) {
8082: $format_descs .= '"<i>'.$desc.'</i>"';
8083: }
8084: }
8085: my $showpct = sprintf("%.0f",$max_match_pct).'%';
8086: $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).
8087: '<br />'.&mt('A low percentage of matches results from one of the following:').'<ul>'.
8088: '<li>'.&mt('The file was uploaded to the wrong course').'</li>'.
8089: '<li>'.&mt('The data are not in the format expected for the domain: [_1]',
8090: '<i>'.$cdom.'</i>').'</li>'.
8091: '<li>'.&mt('Students did not bubble their IDs, or mis-bubbled them').'</li>'.
8092: '<li>'.&mt('The course roster is not up to date').'</li>'.
8093: '</ul>';
8094: }
8095: } else {
8096: $output = '<span class="LC_warning">'.&mt('Uploaded file contained no data').'</span>';
8097: }
8098: return $output;
8099: }
8100:
1.202 albertel 8101: sub valid_file {
8102: my ($requested_file)=@_;
8103: foreach my $filename (sort(&scantron_filenames())) {
8104: if ($requested_file eq $filename) { return 1; }
8105: }
8106: return 0;
8107: }
8108:
8109: sub scantron_download_scantron_data {
8110: my ($r)=@_;
1.324 albertel 8111: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.257 albertel 8112: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
8113: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
8114: my $file=$env{'form.scantron_selectfile'};
1.202 albertel 8115: if (! &valid_file($file)) {
1.492 albertel 8116: $r->print('
1.202 albertel 8117: <p>
1.492 albertel 8118: '.&mt('The requested file name was invalid.').'
1.202 albertel 8119: </p>
1.492 albertel 8120: ');
1.324 albertel 8121: $r->print(&show_grading_menu_form(&get_symb($r,1)));
1.202 albertel 8122: return;
8123: }
8124: my $orig='/uploaded/'.$cdom.'/'.$cname.'/scantron_orig_'.$file;
8125: my $corrected='/uploaded/'.$cdom.'/'.$cname.'/scantron_corrected_'.$file;
8126: my $skipped='/uploaded/'.$cdom.'/'.$cname.'/scantron_skipped_'.$file;
8127: &Apache::lonnet::allowuploaded('/adm/grades',$orig);
8128: &Apache::lonnet::allowuploaded('/adm/grades',$corrected);
8129: &Apache::lonnet::allowuploaded('/adm/grades',$skipped);
1.492 albertel 8130: $r->print('
1.202 albertel 8131: <p>
1.492 albertel 8132: '.&mt('[_1]Original[_2] file as uploaded by the scantron office.',
8133: '<a href="'.$orig.'">','</a>').'
1.202 albertel 8134: </p>
8135: <p>
1.492 albertel 8136: '.&mt('[_1]Corrections[_2], a file of corrected records that were used in grading.',
8137: '<a href="'.$corrected.'">','</a>').'
1.202 albertel 8138: </p>
8139: <p>
1.492 albertel 8140: '.&mt('[_1]Skipped[_2], a file of records that were skipped.',
8141: '<a href="'.$skipped.'">','</a>').'
1.202 albertel 8142: </p>
1.492 albertel 8143: ');
1.324 albertel 8144: $r->print(&show_grading_menu_form(&get_symb($r,1)));
1.202 albertel 8145: return '';
8146: }
1.157 albertel 8147:
1.523 raeburn 8148: sub checkscantron_results {
8149: my ($r) = @_;
8150: my ($symb)=&get_symb($r);
8151: if (!$symb) {return '';}
8152: my $grading_menu_button=&show_grading_menu_form($symb);
8153: my $cid = $env{'request.course.id'};
1.542 raeburn 8154: my %lettdig = &letter_to_digits();
1.523 raeburn 8155: my $numletts = scalar(keys(%lettdig));
8156: my $cnum = $env{'course.'.$cid.'.num'};
8157: my $cdom = $env{'course.'.$cid.'.domain'};
8158: my (undef, undef, $sequence) = &Apache::lonnet::decode_symb($env{'form.selectpage'});
8159: my %record;
8160: my %scantron_config =
8161: &Apache::grades::get_scantron_config($env{'form.scantron_format'});
8162: my ($scanlines,$scan_data)=&Apache::grades::scantron_getfile();
8163: my $classlist=&Apache::loncoursedata::get_classlist();
8164: my %idmap=&Apache::grades::username_to_idmap($classlist);
8165: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 8166: unless (ref($navmap)) {
8167: $r->print(&navmap_errormsg());
8168: return '';
8169: }
1.523 raeburn 8170: my $map=$navmap->getResourceByUrl($sequence);
1.557 raeburn 8171: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
8172: my (%grader_partids_by_symb,%grader_randomlists_by_symb);
8173: &graders_resources_pass(\@resources,\%grader_partids_by_symb, \%grader_randomlists_by_symb);
8174:
1.554 raeburn 8175: my ($uname,$udom);
1.523 raeburn 8176: my (%scandata,%lastname,%bylast);
8177: $r->print('
8178: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="checkscantron">'."\n");
8179:
8180: my @delayqueue;
8181: my %completedstudents;
8182:
8183: my $count=&Apache::grades::get_todo_count($scanlines,$scan_data);
1.581 www 8184: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Bubblesheet/Submissions Comparison Status',
8185: 'Progress of Bubblesheet Data/Submission Records Comparison',$count,
1.523 raeburn 8186: 'inline',undef,'checkscantron');
1.546 raeburn 8187: my ($username,$domain,$started);
1.582 raeburn 8188: my $nav_error;
8189: &scantron_get_maxbubble(\$nav_error); # Need the bubble lines array to parse.
8190: if ($nav_error) {
8191: $r->print(&navmap_errormsg());
8192: return '';
8193: }
1.523 raeburn 8194:
8195: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
8196: 'Processing first student');
8197: my $start=&Time::HiRes::time();
8198: my $i=-1;
8199:
8200: while ($i<$scanlines->{'count'}) {
8201: ($username,$domain,$uname)=('','','');
8202: $i++;
8203: my $line=&Apache::grades::scantron_get_line($scanlines,$scan_data,$i);
8204: if ($line=~/^[\s\cz]*$/) { next; }
8205: if ($started) {
8206: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
8207: 'last student');
8208: }
8209: $started=1;
8210: my $scan_record=
8211: &Apache::grades::scantron_parse_scanline($line,$i,\%scantron_config,
8212: $scan_data);
8213: unless ($uname=&Apache::grades::scantron_find_student($scan_record,$scan_data,
8214: \%idmap,$i)) {
8215: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
8216: 'Unable to find a student that matches',1);
8217: next;
8218: }
8219: if (exists $completedstudents{$uname}) {
8220: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
8221: 'Student '.$uname.' has multiple sheets',2);
8222: next;
8223: }
8224: my $pid = $scan_record->{'scantron.ID'};
8225: $lastname{$pid} = $scan_record->{'scantron.LastName'};
8226: push(@{$bylast{$lastname{$pid}}},$pid);
8227: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
8228: $scandata{$pid} = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
8229: chomp($scandata{$pid});
8230: $scandata{$pid} =~ s/\r$//;
8231: ($username,$domain)=split(/:/,$uname);
8232: my $counter = -1;
8233: foreach my $resource (@resources) {
1.557 raeburn 8234: my $parts;
1.554 raeburn 8235: my $ressymb = $resource->symb();
1.557 raeburn 8236: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
8237: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
8238: (my $analysis,$parts) =
8239: &scantron_partids_tograde($resource,$env{'request.course.id'},$username,$domain);
8240: } else {
8241: $parts = $grader_partids_by_symb{$ressymb};
8242: }
1.542 raeburn 8243: ($counter,my $recording) =
8244: &verify_scantron_grading($resource,$domain,$username,$cid,$counter,
1.554 raeburn 8245: $scandata{$pid},$parts,
1.542 raeburn 8246: \%scantron_config,\%lettdig,$numletts);
8247: $record{$pid} .= $recording;
1.523 raeburn 8248: }
8249: }
8250: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
8251: $r->print('<br />');
8252: my ($okstudents,$badstudents,$numstudents,$passed,$failed);
8253: $passed = 0;
8254: $failed = 0;
8255: $numstudents = 0;
8256: foreach my $last (sort(keys(%bylast))) {
8257: if (ref($bylast{$last}) eq 'ARRAY') {
8258: foreach my $pid (sort(@{$bylast{$last}})) {
8259: my $showscandata = $scandata{$pid};
8260: my $showrecord = $record{$pid};
8261: $showscandata =~ s/\s/ /g;
8262: $showrecord =~ s/\s/ /g;
8263: if ($scandata{$pid} eq $record{$pid}) {
8264: my $css_class = ($passed % 2)?'LC_odd_row':'LC_even_row';
8265: $okstudents .= '<tr class="'.$css_class.'">'.
1.581 www 8266: '<td>'.&mt('Bubblesheet').'</td><td>'.$showscandata.'</td><td rowspan="2">'.$last.'</td><td rowspan="2">'.$pid.'</td>'."\n".
1.523 raeburn 8267: '</tr>'."\n".
8268: '<tr class="'.$css_class.'">'."\n".
8269: '<td>Submissions</td><td>'.$showrecord.'</td></tr>'."\n";
8270: $passed ++;
8271: } else {
8272: my $css_class = ($failed % 2)?'LC_odd_row':'LC_even_row';
1.581 www 8273: $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 8274: '</tr>'."\n".
8275: '<tr class="'.$css_class.'">'."\n".
8276: '<td>Submissions</td><td><span class="LC_nobreak">'.$record{$pid}.'</span></td>'."\n".
8277: '</tr>'."\n";
8278: $failed ++;
8279: }
8280: $numstudents ++;
8281: }
8282: }
8283: }
1.572 www 8284: $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 8285: $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>');
8286: if ($passed) {
1.572 www 8287: $r->print(&mt('Students with exact correspondence between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 8288: $r->print(&Apache::loncommon::start_data_table()."\n".
8289: &Apache::loncommon::start_data_table_header_row()."\n".
8290: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
8291: &Apache::loncommon::end_data_table_header_row()."\n".
8292: $okstudents."\n".
8293: &Apache::loncommon::end_data_table().'<br />');
8294: }
8295: if ($failed) {
1.572 www 8296: $r->print(&mt('Students with differences between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 8297: $r->print(&Apache::loncommon::start_data_table()."\n".
8298: &Apache::loncommon::start_data_table_header_row()."\n".
8299: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
8300: &Apache::loncommon::end_data_table_header_row()."\n".
8301: $badstudents."\n".
8302: &Apache::loncommon::end_data_table()).'<br />'.
1.572 www 8303: &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 8304: }
8305: $r->print('</form><br />'.$grading_menu_button);
8306: return;
8307: }
8308:
1.542 raeburn 8309: sub verify_scantron_grading {
1.554 raeburn 8310: my ($resource,$domain,$username,$cid,$counter,$scandata,$partids,
1.542 raeburn 8311: $scantron_config,$lettdig,$numletts) = @_;
8312: my ($record,%expected,%startpos);
8313: return ($counter,$record) if (!ref($resource));
8314: return ($counter,$record) if (!$resource->is_problem());
8315: my $symb = $resource->symb();
1.554 raeburn 8316: return ($counter,$record) if (ref($partids) ne 'ARRAY');
8317: foreach my $part_id (@{$partids}) {
1.542 raeburn 8318: $counter ++;
8319: $expected{$part_id} = 0;
8320: if ($env{"form.scantron.sub_bubblelines.$counter"}) {
8321: my @sub_lines = split(/,/,$env{"form.scantron.sub_bubblelines.$counter"});
8322: foreach my $item (@sub_lines) {
8323: $expected{$part_id} += $item;
8324: }
8325: } else {
8326: $expected{$part_id} = $env{"form.scantron.bubblelines.$counter"};
8327: }
8328: $startpos{$part_id} = $env{"form.scantron.first_bubble_line.$counter"};
8329: }
8330: if ($symb) {
8331: my %recorded;
8332: my (%returnhash) = &Apache::lonnet::restore($symb,$cid,$domain,$username);
8333: if ($returnhash{'version'}) {
8334: my %lasthash=();
8335: my $version;
8336: for ($version=1;$version<=$returnhash{'version'};$version++) {
8337: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
8338: $lasthash{$key}=$returnhash{$version.':'.$key};
8339: }
8340: }
8341: foreach my $key (keys(%lasthash)) {
8342: if ($key =~ /\.scantron$/) {
8343: my $value = &unescape($lasthash{$key});
8344: my ($part_id) = ($key =~ /^resource\.(.+)\.scantron$/);
8345: if ($value eq '') {
8346: for (my $i=0; $i<$expected{$part_id}; $i++) {
8347: for (my $j=0; $j<$scantron_config->{'length'}; $j++) {
8348: $recorded{$part_id} .= $scantron_config->{'Qoff'};
8349: }
8350: }
8351: } else {
8352: my @tocheck;
8353: my @items = split(//,$value);
8354: if (($scantron_config->{'Qon'} eq 'letter') ||
8355: ($scantron_config->{'Qon'} eq 'number')) {
8356: if (@items < $expected{$part_id}) {
8357: my $fragment = substr($scandata,$startpos{$part_id},$expected{$part_id});
8358: my @singles = split(//,$fragment);
8359: foreach my $pos (@singles) {
8360: if ($pos eq ' ') {
8361: push(@tocheck,$pos);
8362: } else {
8363: my $next = shift(@items);
8364: push(@tocheck,$next);
8365: }
8366: }
8367: } else {
8368: @tocheck = @items;
8369: }
8370: foreach my $letter (@tocheck) {
8371: if ($scantron_config->{'Qon'} eq 'letter') {
8372: if ($letter !~ /^[A-J]$/) {
8373: $letter = $scantron_config->{'Qoff'};
8374: }
8375: $recorded{$part_id} .= $letter;
8376: } elsif ($scantron_config->{'Qon'} eq 'number') {
8377: my $digit;
8378: if ($letter !~ /^[A-J]$/) {
8379: $digit = $scantron_config->{'Qoff'};
8380: } else {
8381: $digit = $lettdig->{$letter};
8382: }
8383: $recorded{$part_id} .= $digit;
8384: }
8385: }
8386: } else {
8387: @tocheck = @items;
8388: for (my $i=0; $i<$expected{$part_id}; $i++) {
8389: my $curr_sub = shift(@tocheck);
8390: my $digit;
8391: if ($curr_sub =~ /^[A-J]$/) {
8392: $digit = $lettdig->{$curr_sub}-1;
8393: }
8394: if ($curr_sub eq 'J') {
8395: $digit += scalar($numletts);
8396: }
8397: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
8398: if ($j == $digit) {
8399: $recorded{$part_id} .= $scantron_config->{'Qon'};
8400: } else {
8401: $recorded{$part_id} .= $scantron_config->{'Qoff'};
8402: }
8403: }
8404: }
8405: }
8406: }
8407: }
8408: }
8409: }
1.554 raeburn 8410: foreach my $part_id (@{$partids}) {
1.542 raeburn 8411: if ($recorded{$part_id} eq '') {
8412: for (my $i=0; $i<$expected{$part_id}; $i++) {
8413: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
8414: $recorded{$part_id} .= $scantron_config->{'Qoff'};
8415: }
8416: }
8417: }
8418: $record .= $recorded{$part_id};
8419: }
8420: }
8421: return ($counter,$record);
8422: }
8423:
8424: sub letter_to_digits {
8425: my %lettdig = (
8426: A => 1,
8427: B => 2,
8428: C => 3,
8429: D => 4,
8430: E => 5,
8431: F => 6,
8432: G => 7,
8433: H => 8,
8434: I => 9,
8435: J => 0,
8436: );
8437: return %lettdig;
8438: }
8439:
1.423 albertel 8440:
1.75 albertel 8441: #-------- end of section for handling grading scantron forms -------
8442: #
8443: #-------------------------------------------------------------------
8444:
1.72 ng 8445: #-------------------------- Menu interface -------------------------
8446: #
8447: #--- Show a Grading Menu button - Calls the next routine ---
8448: sub show_grading_menu_form {
1.324 albertel 8449: my ($symb)=@_;
1.125 ng 8450: my $result.='<br /><form action="/adm/grades" method="post">'."\n".
1.418 albertel 8451: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 8452: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.72 ng 8453: '<input type="hidden" name="command" value="gradingmenu" />'."\n".
1.478 albertel 8454: '<input type="submit" name="submit" value="'.&mt('Grading Menu').'" />'."\n".
1.72 ng 8455: '</form>'."\n";
8456: return $result;
8457: }
8458:
1.77 ng 8459: # -- Retrieve choices for grading form
8460: sub savedState {
8461: my %savedState = ();
1.257 albertel 8462: if ($env{'form.saveState'}) {
8463: foreach (split(/:/,$env{'form.saveState'})) {
1.77 ng 8464: my ($key,$value) = split(/=/,$_,2);
8465: $savedState{$key} = $value;
8466: }
8467: }
8468: return \%savedState;
8469: }
1.76 ng 8470:
1.443 banghart 8471: sub grading_menu {
8472: my ($request) = @_;
8473: my ($symb)=&get_symb($request);
8474: if (!$symb) {return '';}
8475: my $probTitle = &Apache::lonnet::gettitle($symb);
8476: my ($table,undef,$hdgrade) = &showResourceInfo($symb,$probTitle);
8477:
1.444 banghart 8478: $request->print($table);
1.443 banghart 8479: my %fields = ('symb'=>&Apache::lonenc::check_encrypt($symb),
8480: 'handgrade'=>$hdgrade,
8481: 'probTitle'=>$probTitle,
8482: 'command'=>'submit_options',
8483: 'saveState'=>"",
8484: 'gradingMenu'=>1,
8485: 'showgrading'=>"yes");
1.538 schulted 8486:
8487: my $url1 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8488:
1.443 banghart 8489: $fields{'command'} = 'csvform';
1.538 schulted 8490: my $url2 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8491:
1.443 banghart 8492: $fields{'command'} = 'processclicker';
1.538 schulted 8493: my $url3 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8494:
1.443 banghart 8495: $fields{'command'} = 'scantron_selectphase';
1.538 schulted 8496: my $url4 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8497:
8498: my @menu = ({ categorytitle=>'Course Grading',
8499: items =>[
8500: { linktext => 'Manual Grading/View Submissions',
8501: url => $url1,
8502: permission => 'F',
8503: icon => 'edit-find-replace.png',
8504: linktitle => 'Start the process of hand grading submissions.'
8505: },
8506: { linktext => 'Upload Scores',
8507: url => $url2,
8508: permission => 'F',
8509: icon => 'uploadscores.png',
8510: linktitle => 'Specify a file containing the class scores for current resource.'
8511: },
8512: { linktext => 'Process Clicker',
8513: url => $url3,
8514: permission => 'F',
8515: icon => 'addClickerInfoFile.png',
8516: linktitle => 'Specify a file containing the clicker information for this resource.'
8517: },
1.587 raeburn 8518: { linktext => 'Grade/Manage/Review Bubblesheets',
1.538 schulted 8519: url => $url4,
8520: permission => 'F',
8521: icon => 'stat.png',
8522: linktitle => 'Grade scantron exams, upload/download scantron data files, and review previously graded scantron exams.'
8523: }
8524: ]
8525: });
8526:
8527: #$fields{'command'} = 'verify';
8528: #$url = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
1.443 banghart 8529: #
8530: # Create the menu
8531: my $Str;
1.444 banghart 8532: # $Str .= '<h2>'.&mt('Please select a grading task').'</h2>';
1.445 banghart 8533: $Str .= '<form method="post" action="" name="gradingMenu">';
8534: $Str .= '<input type="hidden" name="command" value="" />'.
8535: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
8536: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
1.476 albertel 8537: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.445 banghart 8538: '<input type="hidden" name="saveState" value="" />'."\n".
8539: '<input type="hidden" name="gradingMenu" value="1" />'."\n".
8540: '<input type="hidden" name="showgrading" value="yes" />'."\n";
8541:
1.538 schulted 8542: $Str .= Apache::lonhtmlcommon::generate_menu(@menu);
8543: #$menudata->{'jscript'}
1.584 bisitz 8544: $Str .='<hr /><input type="button" value="'.&mt('Verify Receipt No.').'" '.
1.589 bisitz 8545: ' onclick="javascript:checkChoice(document.forms.gradingMenu,\'5\',\'verify\')" '.
1.538 schulted 8546: ' /> '.
8547: &Apache::lonnet::recprefix($env{'request.course.id'}).
1.589 bisitz 8548: '-<input type="text" name="receipt" size="4" onchange="javascript:checkReceiptNo(this.form,\'OK\')" />';
1.538 schulted 8549:
1.444 banghart 8550: $Str .="</form>\n";
1.539 riegler 8551: my $receiptalert = &mt("Please enter a receipt number given by a student in the receipt box.");
1.443 banghart 8552: $request->print(<<GRADINGMENUJS);
8553: <script type="text/javascript" language="javascript">
8554: function checkChoice(formname,val,cmdx) {
8555: if (val <= 2) {
8556: var cmd = radioSelection(formname.radioChoice);
8557: var cmdsave = cmd;
8558: } else {
8559: cmd = cmdx;
8560: cmdsave = 'submission';
8561: }
8562: formname.command.value = cmd;
8563: if (val < 5) formname.submit();
8564: if (val == 5) {
1.458 banghart 8565: if (!checkReceiptNo(formname,'notOK')) {
8566: return false;
8567: } else {
8568: formname.submit();
8569: }
1.445 banghart 8570: }
8571: }
1.443 banghart 8572:
8573: function checkReceiptNo(formname,nospace) {
8574: var receiptNo = formname.receipt.value;
8575: var checkOpt = false;
8576: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
8577: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
8578: if (checkOpt) {
1.539 riegler 8579: alert("$receiptalert");
1.443 banghart 8580: formname.receipt.value = "";
8581: formname.receipt.focus();
8582: return false;
8583: }
8584: return true;
8585: }
8586: </script>
8587: GRADINGMENUJS
8588: &commonJSfunctions($request);
8589: return $Str;
8590: }
8591:
8592:
8593: #--- Displays the submissions first page -------
8594: sub submit_options {
1.72 ng 8595: my ($request) = @_;
1.324 albertel 8596: my ($symb)=&get_symb($request);
1.72 ng 8597: if (!$symb) {return '';}
1.76 ng 8598: my $probTitle = &Apache::lonnet::gettitle($symb);
1.72 ng 8599:
1.539 riegler 8600: my $receiptalert = &mt("Please enter a receipt number given by a student in the receipt box.");
1.72 ng 8601: $request->print(<<GRADINGMENUJS);
8602: <script type="text/javascript" language="javascript">
1.116 ng 8603: function checkChoice(formname,val,cmdx) {
8604: if (val <= 2) {
8605: var cmd = radioSelection(formname.radioChoice);
1.118 ng 8606: var cmdsave = cmd;
1.116 ng 8607: } else {
8608: cmd = cmdx;
1.118 ng 8609: cmdsave = 'submission';
1.116 ng 8610: }
8611: formname.command.value = cmd;
1.118 ng 8612: formname.saveState.value = "saveCmd="+cmdsave+":saveSec="+pullDownSelection(formname.section)+
1.145 albertel 8613: ":saveSub="+pullDownSelection(formname.submitonly)+":saveStatus="+pullDownSelection(formname.Status);
1.116 ng 8614: if (val < 5) formname.submit();
8615: if (val == 5) {
1.72 ng 8616: if (!checkReceiptNo(formname,'notOK')) { return false;}
8617: formname.submit();
8618: }
1.238 albertel 8619: if (val < 7) formname.submit();
1.72 ng 8620: }
8621:
8622: function checkReceiptNo(formname,nospace) {
8623: var receiptNo = formname.receipt.value;
8624: var checkOpt = false;
8625: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
8626: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
8627: if (checkOpt) {
1.539 riegler 8628: alert("$receiptalert");
1.72 ng 8629: formname.receipt.value = "";
8630: formname.receipt.focus();
8631: return false;
8632: }
8633: return true;
8634: }
8635: </script>
8636: GRADINGMENUJS
1.118 ng 8637: &commonJSfunctions($request);
1.324 albertel 8638: my ($table,undef,$hdgrade) = &showResourceInfo($symb,$probTitle);
1.473 albertel 8639: my $result;
1.76 ng 8640: my (undef,$sections) = &getclasslist('all','0');
1.77 ng 8641: my $savedState = &savedState();
1.118 ng 8642: my $saveCmd = ($$savedState{'saveCmd'} eq '' ? 'submission' : $$savedState{'saveCmd'});
1.77 ng 8643: my $saveSec = ($$savedState{'saveSec'} eq '' ? 'all' : $$savedState{'saveSec'});
1.118 ng 8644: my $saveSub = ($$savedState{'saveSub'} eq '' ? 'all' : $$savedState{'saveSub'});
1.77 ng 8645: my $saveStatus = ($$savedState{'saveStatus'} eq '' ? 'Active' : $$savedState{'saveStatus'});
1.72 ng 8646:
1.533 bisitz 8647: # Preselect sections
8648: my $selsec="";
8649: if (ref($sections)) {
8650: foreach my $section (sort(@$sections)) {
8651: $selsec.='<option value="'.$section.'" '.
8652: ($saveSec eq $section ? 'selected="selected"':'').'>'.$section.'</option>'."\n";
8653: }
8654: }
8655:
1.72 ng 8656: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.418 albertel 8657: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.72 ng 8658: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
8659: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.116 ng 8660: '<input type="hidden" name="command" value="" />'."\n".
1.77 ng 8661: '<input type="hidden" name="saveState" value="" />'."\n".
1.124 ng 8662: '<input type="hidden" name="gradingMenu" value="1" />'."\n".
1.72 ng 8663: '<input type="hidden" name="showgrading" value="yes" />'."\n";
8664:
1.472 albertel 8665: $result.='
1.533 bisitz 8666: <h2>
8667: '.&mt('Grade Current Resource').'
8668: </h2>
8669: <div>
8670: '.$table.'
8671: </div>
8672:
1.537 harmsja 8673: <div class="LC_columnSection">
8674:
1.533 bisitz 8675: <fieldset>
8676: <legend>
8677: '.&mt('Sections').'
8678: </legend>
8679: <select name="section" multiple="multiple" size="5">'."\n";
8680: $result.= $selsec;
1.401 albertel 8681: $result.= '<option value="all" '.($saveSec eq 'all' ? 'selected="selected"' : ''). '>all</option></select> ';
1.472 albertel 8682: $result.='
1.533 bisitz 8683: </fieldset>
1.537 harmsja 8684:
1.533 bisitz 8685: <fieldset>
8686: <legend>
8687: '.&mt('Groups').'
8688: </legend>
8689: '.&Apache::lonstatistics::GroupSelect('group','multiple',5).'
8690: </fieldset>
1.537 harmsja 8691:
1.533 bisitz 8692: <fieldset>
8693: <legend>
8694: '.&mt('Access Status').'
8695: </legend>
8696: '.&Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,5,undef,'mult').'
8697: </fieldset>
1.537 harmsja 8698:
1.533 bisitz 8699: <fieldset>
8700: <legend>
8701: '.&mt('Submission Status').'
8702: </legend>
8703: <select name="submitonly" size="5">
1.473 albertel 8704: <option value="yes" '. ($saveSub eq 'yes' ? 'selected="selected"' : '').'>'.&mt('with submissions').'</option>
8705: <option value="queued" '. ($saveSub eq 'queued' ? 'selected="selected"' : '').'>'.&mt('in grading queue').'</option>
8706: <option value="graded" '. ($saveSub eq 'graded' ? 'selected="selected"' : '').'>'.&mt('with ungraded submissions').'</option>
8707: <option value="incorrect" '.($saveSub eq 'incorrect' ? 'selected="selected"' : '').'>'.&mt('with incorrect submissions').'</option>
8708: <option value="all" '. ($saveSub eq 'all' ? 'selected="selected"' : '').'>'.&mt('with any status').'</option>
1.533 bisitz 8709: </select>
8710: </fieldset>
1.537 harmsja 8711:
1.533 bisitz 8712: </div>
8713:
8714: <br />
8715: <div>
8716: <div>
1.473 albertel 8717: <label>
8718: <input type="radio" name="radioChoice" value="submission" '.
8719: ($saveCmd eq 'submission' ? 'checked="checked"' : '').' /> '.
8720: &mt('Select individual students to grade and view submissions.').'
8721: </label>
8722: </div>
1.533 bisitz 8723: <div>
1.473 albertel 8724: <label>
8725: <input type="radio" name="radioChoice" value="viewgrades" '.
8726: ($saveCmd eq 'viewgrades' ? 'checked="checked"' : '').' /> '.
8727: &mt('Grade all selected students in a grading table.').'
8728: </label>
8729: </div>
1.533 bisitz 8730: <div>
1.589 bisitz 8731: <input type="button" onclick="javascript:checkChoice(this.form,\'2\');" value="'.&mt('Next').' →" />
1.473 albertel 8732: </div>
1.472 albertel 8733: </div>
1.533 bisitz 8734:
8735:
1.473 albertel 8736: <h2>
8737: '.&mt('Grade Complete Folder for One Student').'
8738: </h2>
1.533 bisitz 8739: <div>
8740: <div>
1.473 albertel 8741: <label>
8742: <input type="radio" name="radioChoice" value="pickStudentPage" '.
8743: ($saveCmd eq 'pickStudentPage' ? 'checked="checked"' : '').' /> '.
8744: &mt('The <b>complete</b> page/sequence/folder: For one student').'
8745: </label>
8746: </div>
1.533 bisitz 8747: <div>
1.589 bisitz 8748: <input type="button" onclick="javascript:checkChoice(this.form,\'2\');" value="'.&mt('Next').' →" />
1.473 albertel 8749: </div>
1.472 albertel 8750: </div>
8751: </form>';
1.499 albertel 8752: $result .= &show_grading_menu_form($symb);
1.44 ng 8753: return $result;
1.2 albertel 8754: }
8755:
1.285 albertel 8756: sub reset_perm {
8757: undef(%perm);
8758: }
8759:
8760: sub init_perm {
8761: &reset_perm();
1.300 albertel 8762: foreach my $test_perm ('vgr','mgr','opa') {
8763:
8764: my $scope = $env{'request.course.id'};
8765: if (!($perm{$test_perm}=&Apache::lonnet::allowed($test_perm,$scope))) {
8766:
8767: $scope .= '/'.$env{'request.course.sec'};
8768: if ( $perm{$test_perm}=
8769: &Apache::lonnet::allowed($test_perm,$scope)) {
8770: $perm{$test_perm.'_section'}=$env{'request.course.sec'};
8771: } else {
8772: delete($perm{$test_perm});
8773: }
1.285 albertel 8774: }
8775: }
8776: }
8777:
1.400 www 8778: sub gather_clicker_ids {
1.408 albertel 8779: my %clicker_ids;
1.400 www 8780:
8781: my $classlist = &Apache::loncoursedata::get_classlist();
8782:
8783: # Set up a couple variables.
1.407 albertel 8784: my $username_idx = &Apache::loncoursedata::CL_SNAME();
8785: my $domain_idx = &Apache::loncoursedata::CL_SDOM();
1.438 www 8786: my $status_idx = &Apache::loncoursedata::CL_STATUS();
1.400 www 8787:
1.407 albertel 8788: foreach my $student (keys(%$classlist)) {
1.438 www 8789: if ($classlist->{$student}->[$status_idx] ne 'Active') { next; }
1.407 albertel 8790: my $username = $classlist->{$student}->[$username_idx];
8791: my $domain = $classlist->{$student}->[$domain_idx];
1.400 www 8792: my $clickers =
1.408 albertel 8793: (&Apache::lonnet::userenvironment($domain,$username,'clickers'))[1];
1.400 www 8794: foreach my $id (split(/\,/,$clickers)) {
1.414 www 8795: $id=~s/^[\#0]+//;
1.421 www 8796: $id=~s/[\-\:]//g;
1.407 albertel 8797: if (exists($clicker_ids{$id})) {
1.408 albertel 8798: $clicker_ids{$id}.=','.$username.':'.$domain;
1.400 www 8799: } else {
1.408 albertel 8800: $clicker_ids{$id}=$username.':'.$domain;
1.400 www 8801: }
8802: }
8803: }
1.407 albertel 8804: return %clicker_ids;
1.400 www 8805: }
8806:
1.402 www 8807: sub gather_adv_clicker_ids {
1.408 albertel 8808: my %clicker_ids;
1.402 www 8809: my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'};
8810: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
8811: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
1.409 albertel 8812: foreach my $element (sort(keys(%coursepersonnel))) {
1.402 www 8813: foreach my $person (split(/\,/,$coursepersonnel{$element})) {
8814: my ($puname,$pudom)=split(/\:/,$person);
8815: my $clickers =
1.408 albertel 8816: (&Apache::lonnet::userenvironment($pudom,$puname,'clickers'))[1];
1.405 www 8817: foreach my $id (split(/\,/,$clickers)) {
1.414 www 8818: $id=~s/^[\#0]+//;
1.421 www 8819: $id=~s/[\-\:]//g;
1.408 albertel 8820: if (exists($clicker_ids{$id})) {
8821: $clicker_ids{$id}.=','.$puname.':'.$pudom;
8822: } else {
8823: $clicker_ids{$id}=$puname.':'.$pudom;
8824: }
1.405 www 8825: }
1.402 www 8826: }
8827: }
1.407 albertel 8828: return %clicker_ids;
1.402 www 8829: }
8830:
1.413 www 8831: sub clicker_grading_parameters {
8832: return ('gradingmechanism' => 'scalar',
8833: 'upfiletype' => 'scalar',
8834: 'specificid' => 'scalar',
8835: 'pcorrect' => 'scalar',
8836: 'pincorrect' => 'scalar');
8837: }
8838:
1.400 www 8839: sub process_clicker {
8840: my ($r)=@_;
8841: my ($symb)=&get_symb($r);
8842: if (!$symb) {return '';}
8843: my $result=&checkforfile_js();
8844: $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
8845: my ($table) = &showResourceInfo($symb,$env{'form.probTitle'});
8846: $result.=$table;
8847: $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
8848: $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
1.538 schulted 8849: $result.=' <b>'.&mt('Specify a file containing the clicker information for this resource.').
8850: '</b></td></tr>'."\n";
1.400 www 8851: $result.='<tr bgcolor=#ffffe6><td>'."\n";
1.413 www 8852: # Attempt to restore parameters from last session, set defaults if not present
8853: my %Saveable_Parameters=&clicker_grading_parameters();
8854: &Apache::loncommon::restore_course_settings('grades_clicker',
8855: \%Saveable_Parameters);
8856: if (!$env{'form.pcorrect'}) { $env{'form.pcorrect'}=100; }
8857: if (!$env{'form.pincorrect'}) { $env{'form.pincorrect'}=100; }
8858: if (!$env{'form.gradingmechanism'}) { $env{'form.gradingmechanism'}='attendance'; }
8859: if (!$env{'form.upfiletype'}) { $env{'form.upfiletype'}='iclicker'; }
8860:
8861: my %checked;
1.521 www 8862: foreach my $gradingmechanism ('attendance','personnel','specific','given') {
1.413 www 8863: if ($env{'form.gradingmechanism'} eq $gradingmechanism) {
1.569 bisitz 8864: $checked{$gradingmechanism}=' checked="checked"';
1.413 www 8865: }
8866: }
8867:
1.400 www 8868: my $upload=&mt("Upload File");
8869: my $type=&mt("Type");
1.402 www 8870: my $attendance=&mt("Award points just for participation");
8871: my $personnel=&mt("Correctness determined from response by course personnel");
1.414 www 8872: my $specific=&mt("Correctness determined from response with clicker ID(s)");
1.521 www 8873: my $given=&mt("Correctness determined from given list of answers").' '.
8874: '<font size="-2"><tt>('.&mt("Provide comma-separated list. Use '*' for any answer correct, '-' for skip").')</tt></font>';
1.402 www 8875: my $pcorrect=&mt("Percentage points for correct solution");
8876: my $pincorrect=&mt("Percentage points for incorrect solution");
1.413 www 8877: my $selectform=&Apache::loncommon::select_form($env{'form.upfiletype'},'upfiletype',
1.419 www 8878: ('iclicker' => 'i>clicker',
8879: 'interwrite' => 'interwrite PRS'));
1.418 albertel 8880: $symb = &Apache::lonenc::check_encrypt($symb);
1.400 www 8881: $result.=<<ENDUPFORM;
1.402 www 8882: <script type="text/javascript">
8883: function sanitycheck() {
8884: // Accept only integer percentages
8885: document.forms.gradesupload.pcorrect.value=Math.round(document.forms.gradesupload.pcorrect.value);
8886: document.forms.gradesupload.pincorrect.value=Math.round(document.forms.gradesupload.pincorrect.value);
8887: // Find out grading choice
8888: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
8889: if (document.forms.gradesupload.gradingmechanism[i].checked) {
8890: gradingchoice=document.forms.gradesupload.gradingmechanism[i].value;
8891: }
8892: }
8893: // By default, new choice equals user selection
8894: newgradingchoice=gradingchoice;
8895: // Not good to give more points for false answers than correct ones
8896: if (Math.round(document.forms.gradesupload.pcorrect.value)<Math.round(document.forms.gradesupload.pincorrect.value)) {
8897: document.forms.gradesupload.pcorrect.value=document.forms.gradesupload.pincorrect.value;
8898: }
8899: // If new choice is attendance only, and old choice was correctness-based, restore defaults
8900: if ((gradingchoice=='attendance') && (document.forms.gradesupload.waschecked.value!='attendance')) {
8901: document.forms.gradesupload.pcorrect.value=100;
8902: document.forms.gradesupload.pincorrect.value=100;
8903: }
8904: // If the values are different, cannot be attendance only
8905: if ((Math.round(document.forms.gradesupload.pcorrect.value)!=Math.round(document.forms.gradesupload.pincorrect.value)) &&
8906: (gradingchoice=='attendance')) {
8907: newgradingchoice='personnel';
8908: }
8909: // Change grading choice to new one
8910: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
8911: if (document.forms.gradesupload.gradingmechanism[i].value==newgradingchoice) {
8912: document.forms.gradesupload.gradingmechanism[i].checked=true;
8913: } else {
8914: document.forms.gradesupload.gradingmechanism[i].checked=false;
8915: }
8916: }
8917: // Remember the old state
8918: document.forms.gradesupload.waschecked.value=newgradingchoice;
8919: }
8920: </script>
1.400 www 8921: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
8922: <input type="hidden" name="symb" value="$symb" />
8923: <input type="hidden" name="command" value="processclickerfile" />
8924: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
8925: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
8926: <input type="file" name="upfile" size="50" />
8927: <br /><label>$type: $selectform</label>
1.589 bisitz 8928: <br /><label><input type="radio" name="gradingmechanism" value="attendance"$checked{'attendance'} onclick="sanitycheck()" />$attendance </label>
8929: <br /><label><input type="radio" name="gradingmechanism" value="personnel"$checked{'personnel'} onclick="sanitycheck()" />$personnel</label>
8930: <br /><label><input type="radio" name="gradingmechanism" value="specific"$checked{'specific'} onclick="sanitycheck()" />$specific </label>
1.414 www 8931: <input type="text" name="specificid" value="$env{'form.specificid'}" size="20" />
1.589 bisitz 8932: <br /><label><input type="radio" name="gradingmechanism" value="given"$checked{'given'} onclick="sanitycheck()" />$given </label>
1.521 www 8933: <br />
8934: <input type="text" name="givenanswer" size="50" />
1.413 www 8935: <input type="hidden" name="waschecked" value="$env{'form.gradingmechanism'}" />
1.589 bisitz 8936: <br /><label>$pcorrect: <input type="text" name="pcorrect" size="4" value="$env{'form.pcorrect'}" onchange="sanitycheck()" /></label>
8937: <br /><label>$pincorrect: <input type="text" name="pincorrect" size="4" value="$env{'form.pincorrect'}" onchange="sanitycheck()" /></label>
8938: <br /><input type="button" onclick="javascript:checkUpload(this.form);" value="$upload" />
1.400 www 8939: </form>
8940: ENDUPFORM
8941: $result.='</td></tr></table>'."\n".
8942: '</td></tr></table><br /><br />'."\n";
8943: $result.=&show_grading_menu_form($symb);
8944: return $result;
8945: }
8946:
8947: sub process_clicker_file {
8948: my ($r)=@_;
8949: my ($symb)=&get_symb($r);
8950: if (!$symb) {return '';}
1.413 www 8951:
8952: my %Saveable_Parameters=&clicker_grading_parameters();
8953: &Apache::loncommon::store_course_settings('grades_clicker',
8954: \%Saveable_Parameters);
8955:
1.400 www 8956: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.404 www 8957: if (($env{'form.gradingmechanism'} eq 'specific') && ($env{'form.specificid'}!~/\w/)) {
1.408 albertel 8958: $result.='<span class="LC_error">'.&mt('You need to specify a clicker ID for the correct answer').'</span>';
8959: return $result.&show_grading_menu_form($symb);
1.404 www 8960: }
1.522 www 8961: if (($env{'form.gradingmechanism'} eq 'given') && ($env{'form.givenanswer'}!~/\S/)) {
1.521 www 8962: $result.='<span class="LC_error">'.&mt('You need to specify the correct answer').'</span>';
8963: return $result.&show_grading_menu_form($symb);
8964: }
1.522 www 8965: my $foundgiven=0;
1.521 www 8966: if ($env{'form.gradingmechanism'} eq 'given') {
8967: $env{'form.givenanswer'}=~s/^\s*//gs;
8968: $env{'form.givenanswer'}=~s/\s*$//gs;
8969: $env{'form.givenanswer'}=~s/[^a-zA-Z0-9\.\*\-]+/\,/g;
8970: $env{'form.givenanswer'}=uc($env{'form.givenanswer'});
1.522 www 8971: my @answers=split(/\,/,$env{'form.givenanswer'});
8972: $foundgiven=$#answers+1;
1.521 www 8973: }
1.407 albertel 8974: my %clicker_ids=&gather_clicker_ids();
1.408 albertel 8975: my %correct_ids;
1.404 www 8976: if ($env{'form.gradingmechanism'} eq 'personnel') {
1.408 albertel 8977: %correct_ids=&gather_adv_clicker_ids();
1.404 www 8978: }
8979: if ($env{'form.gradingmechanism'} eq 'specific') {
1.414 www 8980: foreach my $correct_id (split(/[\s\,]/,$env{'form.specificid'})) {;
8981: $correct_id=~tr/a-z/A-Z/;
8982: $correct_id=~s/\s//gs;
8983: $correct_id=~s/^[\#0]+//;
1.421 www 8984: $correct_id=~s/[\-\:]//g;
1.414 www 8985: if ($correct_id) {
8986: $correct_ids{$correct_id}='specified';
8987: }
8988: }
1.400 www 8989: }
1.404 www 8990: if ($env{'form.gradingmechanism'} eq 'attendance') {
1.408 albertel 8991: $result.=&mt('Score based on attendance only');
1.521 www 8992: } elsif ($env{'form.gradingmechanism'} eq 'given') {
1.522 www 8993: $result.=&mt('Score based on [_1] ([_2] answers)','<tt>'.$env{'form.givenanswer'}.'</tt>',$foundgiven);
1.404 www 8994: } else {
1.408 albertel 8995: my $number=0;
1.411 www 8996: $result.='<p><b>'.&mt('Correctness determined by the following IDs').'</b>';
1.408 albertel 8997: foreach my $id (sort(keys(%correct_ids))) {
1.411 www 8998: $result.='<br /><tt>'.$id.'</tt> - ';
1.408 albertel 8999: if ($correct_ids{$id} eq 'specified') {
9000: $result.=&mt('specified');
9001: } else {
9002: my ($uname,$udom)=split(/\:/,$correct_ids{$id});
9003: $result.=&Apache::loncommon::plainname($uname,$udom);
9004: }
9005: $number++;
9006: }
1.411 www 9007: $result.="</p>\n";
1.408 albertel 9008: if ($number==0) {
9009: $result.='<span class="LC_error">'.&mt('No IDs found to determine correct answer').'</span>';
9010: return $result.&show_grading_menu_form($symb);
9011: }
1.404 www 9012: }
1.405 www 9013: if (length($env{'form.upfile'}) < 2) {
1.407 albertel 9014: $result.=&mt('[_1] Error: [_2] The file you attempted to upload, [_3] contained no information. Please check that you entered the correct filename.',
9015: '<span class="LC_error">',
9016: '</span>',
9017: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>');
1.405 www 9018: return $result.&show_grading_menu_form($symb);
9019: }
1.410 www 9020:
9021: # Were able to get all the info needed, now analyze the file
9022:
1.411 www 9023: $result.=&Apache::loncommon::studentbrowser_javascript();
1.418 albertel 9024: $symb = &Apache::lonenc::check_encrypt($symb);
1.410 www 9025: my $heading=&mt('Scanning clicker file');
9026: $result.=(<<ENDHEADER);
9027: <br /><table width="100%" border="0"><tr><td bgcolor="#777777">
9028: <table width="100%" border="0"><tr bgcolor="#e6ffff"><td>
9029: <b>$heading</b></td></tr><tr bgcolor=#ffffe6><td>
9030: <form method="post" action="/adm/grades" name="clickeranalysis">
9031: <input type="hidden" name="symb" value="$symb" />
9032: <input type="hidden" name="command" value="assignclickergrades" />
9033: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
9034: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
1.411 www 9035: <input type="hidden" name="gradingmechanism" value="$env{'form.gradingmechanism'}" />
9036: <input type="hidden" name="pcorrect" value="$env{'form.pcorrect'}" />
9037: <input type="hidden" name="pincorrect" value="$env{'form.pincorrect'}" />
1.410 www 9038: ENDHEADER
1.522 www 9039: if ($env{'form.gradingmechanism'} eq 'given') {
9040: $result.='<input type="hidden" name="correct:given" value="'.$env{'form.givenanswer'}.'" />';
9041: }
1.408 albertel 9042: my %responses;
9043: my @questiontitles;
1.405 www 9044: my $errormsg='';
9045: my $number=0;
9046: if ($env{'form.upfiletype'} eq 'iclicker') {
1.408 albertel 9047: ($errormsg,$number)=&iclicker_eval(\@questiontitles,\%responses);
1.406 www 9048: }
1.419 www 9049: if ($env{'form.upfiletype'} eq 'interwrite') {
9050: ($errormsg,$number)=&interwrite_eval(\@questiontitles,\%responses);
9051: }
1.411 www 9052: $result.='<br />'.&mt('Found [_1] question(s)',$number).'<br />'.
9053: '<input type="hidden" name="number" value="'.$number.'" />'.
9054: &mt('Awarding [_1] percent for correct and [_2] percent for incorrect responses',
9055: $env{'form.pcorrect'},$env{'form.pincorrect'}).
9056: '<br />';
1.522 www 9057: if (($env{'form.gradingmechanism'} eq 'given') && ($number!=$foundgiven)) {
9058: $result.='<span class="LC_error">'.&mt('Number of given answers does not agree with number of questions in file.').'</span>';
9059: return $result.&show_grading_menu_form($symb);
9060: }
1.414 www 9061: # Remember Question Titles
9062: # FIXME: Possibly need delimiter other than ":"
9063: for (my $i=0;$i<$number;$i++) {
9064: $result.='<input type="hidden" name="question:'.$i.'" value="'.
9065: &HTML::Entities::encode($questiontitles[$i],'"&<>').'" />';
9066: }
1.411 www 9067: my $correct_count=0;
9068: my $student_count=0;
9069: my $unknown_count=0;
1.414 www 9070: # Match answers with usernames
9071: # FIXME: Possibly need delimiter other than ":"
1.409 albertel 9072: foreach my $id (keys(%responses)) {
1.410 www 9073: if ($correct_ids{$id}) {
1.414 www 9074: $result.="\n".'<input type="hidden" name="correct:'.$correct_count.':'.$correct_ids{$id}.'" value="'.$responses{$id}.'" />';
1.411 www 9075: $correct_count++;
1.410 www 9076: } elsif ($clicker_ids{$id}) {
1.437 www 9077: if ($clicker_ids{$id}=~/\,/) {
9078: # More than one user with the same clicker!
9079: $result.="\n<hr />".&mt('Clicker registered more than once').": <tt>".$id."</tt><br />";
9080: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
9081: "<select name='multi".$id."'>";
9082: foreach my $reguser (sort(split(/\,/,$clicker_ids{$id}))) {
9083: $result.="<option value='".$reguser."'>".&Apache::loncommon::plainname(split(/\:/,$reguser)).' ('.$reguser.')</option>';
9084: }
9085: $result.='</select>';
9086: $unknown_count++;
9087: } else {
9088: # Good: found one and only one user with the right clicker
9089: $result.="\n".'<input type="hidden" name="student:'.$clicker_ids{$id}.'" value="'.$responses{$id}.'" />';
9090: $student_count++;
9091: }
1.410 www 9092: } else {
1.411 www 9093: $result.="\n<hr />".&mt('Unregistered Clicker')." <tt>".$id."</tt><br />";
9094: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
9095: "\n".&mt("Username").": <input type='text' name='uname".$id."' /> ".
9096: "\n".&mt("Domain").": ".
9097: &Apache::loncommon::select_dom_form($env{'course.'.$env{'request.course.id'}.'.domain'},'udom'.$id).' '.
9098: &Apache::loncommon::selectstudent_link('clickeranalysis','uname'.$id,'udom'.$id);
9099: $unknown_count++;
1.410 www 9100: }
1.405 www 9101: }
1.412 www 9102: $result.='<hr />'.
9103: &mt('Found [_1] registered and [_2] unregistered clickers.',$student_count,$unknown_count);
1.521 www 9104: if (($env{'form.gradingmechanism'} ne 'attendance') && ($env{'form.gradingmechanism'} ne 'given')) {
1.412 www 9105: if ($correct_count==0) {
9106: $errormsg.="Found no correct answers answers for grading!";
9107: } elsif ($correct_count>1) {
1.414 www 9108: $result.='<br /><span class="LC_warning">'.&mt("Found [_1] entries for grading!",$correct_count).'</span>';
1.412 www 9109: }
9110: }
1.428 www 9111: if ($number<1) {
9112: $errormsg.="Found no questions.";
9113: }
1.412 www 9114: if ($errormsg) {
9115: $result.='<br /><span class="LC_error">'.&mt($errormsg).'</span>';
9116: } else {
9117: $result.='<br /><input type="submit" name="finalize" value="'.&mt('Finalize Grading').'" />';
9118: }
9119: $result.='</form></td></tr></table>'."\n".
1.410 www 9120: '</td></tr></table><br /><br />'."\n";
1.404 www 9121: return $result.&show_grading_menu_form($symb);
1.400 www 9122: }
9123:
1.405 www 9124: sub iclicker_eval {
1.406 www 9125: my ($questiontitles,$responses)=@_;
1.405 www 9126: my $number=0;
9127: my $errormsg='';
9128: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
1.410 www 9129: my %components=&Apache::loncommon::record_sep($line);
9130: my @entries=map {$components{$_}} (sort(keys(%components)));
1.408 albertel 9131: if ($entries[0] eq 'Question') {
9132: for (my $i=3;$i<$#entries;$i+=6) {
9133: $$questiontitles[$number]=$entries[$i];
9134: $number++;
9135: }
9136: }
9137: if ($entries[0]=~/^\#/) {
9138: my $id=$entries[0];
9139: my @idresponses;
9140: $id=~s/^[\#0]+//;
9141: for (my $i=0;$i<$number;$i++) {
9142: my $idx=3+$i*6;
9143: push(@idresponses,$entries[$idx]);
9144: }
9145: $$responses{$id}=join(',',@idresponses);
9146: }
1.405 www 9147: }
9148: return ($errormsg,$number);
9149: }
9150:
1.419 www 9151: sub interwrite_eval {
9152: my ($questiontitles,$responses)=@_;
9153: my $number=0;
9154: my $errormsg='';
1.420 www 9155: my $skipline=1;
9156: my $questionnumber=0;
9157: my %idresponses=();
1.419 www 9158: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
9159: my %components=&Apache::loncommon::record_sep($line);
9160: my @entries=map {$components{$_}} (sort(keys(%components)));
1.420 www 9161: if ($entries[1] eq 'Time') { $skipline=0; next; }
9162: if ($entries[1] eq 'Response') { $skipline=1; }
9163: next if $skipline;
9164: if ($entries[0]!=$questionnumber) {
9165: $questionnumber=$entries[0];
9166: $$questiontitles[$number]=&mt('Question [_1]',$questionnumber);
9167: $number++;
1.419 www 9168: }
1.420 www 9169: my $id=$entries[4];
9170: $id=~s/^[\#0]+//;
1.421 www 9171: $id=~s/^v\d*\://i;
9172: $id=~s/[\-\:]//g;
1.420 www 9173: $idresponses{$id}[$number]=$entries[6];
9174: }
1.524 raeburn 9175: foreach my $id (keys(%idresponses)) {
1.420 www 9176: $$responses{$id}=join(',',@{$idresponses{$id}});
9177: $$responses{$id}=~s/^\s*\,//;
1.419 www 9178: }
9179: return ($errormsg,$number);
9180: }
9181:
1.414 www 9182: sub assign_clicker_grades {
9183: my ($r)=@_;
9184: my ($symb)=&get_symb($r);
9185: if (!$symb) {return '';}
1.416 www 9186: # See which part we are saving to
1.582 raeburn 9187: my $res_error;
9188: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
9189: if ($res_error) {
9190: return &navmap_errormsg();
9191: }
1.416 www 9192: # FIXME: This should probably look for the first handgradeable part
9193: my $part=$$partlist[0];
9194: # Start screen output
1.414 www 9195: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.416 www 9196:
1.414 www 9197: my $heading=&mt('Assigning grades based on clicker file');
9198: $result.=(<<ENDHEADER);
9199: <br /><table width="100%" border="0"><tr><td bgcolor="#777777">
9200: <table width="100%" border="0"><tr bgcolor="#e6ffff"><td>
9201: <b>$heading</b></td></tr><tr bgcolor=#ffffe6><td>
9202: ENDHEADER
9203: # Get correct result
9204: # FIXME: Possibly need delimiter other than ":"
9205: my @correct=();
1.415 www 9206: my $gradingmechanism=$env{'form.gradingmechanism'};
9207: my $number=$env{'form.number'};
9208: if ($gradingmechanism ne 'attendance') {
1.414 www 9209: foreach my $key (keys(%env)) {
9210: if ($key=~/^form\.correct\:/) {
9211: my @input=split(/\,/,$env{$key});
9212: for (my $i=0;$i<=$#input;$i++) {
9213: if (($correct[$i]) && ($input[$i]) &&
9214: ($correct[$i] ne $input[$i])) {
9215: $result.='<br /><span class="LC_warning">'.
9216: &mt('More than one correct result given for question "[_1]": [_2] versus [_3].',
9217: $env{'form.question:'.$i},$correct[$i],$input[$i]).'</span>';
9218: } elsif ($input[$i]) {
9219: $correct[$i]=$input[$i];
9220: }
9221: }
9222: }
9223: }
1.415 www 9224: for (my $i=0;$i<$number;$i++) {
1.414 www 9225: if (!$correct[$i]) {
9226: $result.='<br /><span class="LC_error">'.
9227: &mt('No correct result given for question "[_1]"!',
9228: $env{'form.question:'.$i}).'</span>';
9229: }
9230: }
9231: $result.='<br />'.&mt("Correct answer: [_1]",join(', ',map { ($_?$_:'-') } @correct));
9232: }
9233: # Start grading
1.415 www 9234: my $pcorrect=$env{'form.pcorrect'};
9235: my $pincorrect=$env{'form.pincorrect'};
1.416 www 9236: my $storecount=0;
1.415 www 9237: foreach my $key (keys(%env)) {
1.420 www 9238: my $user='';
1.415 www 9239: if ($key=~/^form\.student\:(.*)$/) {
1.420 www 9240: $user=$1;
9241: }
9242: if ($key=~/^form\.unknown\:(.*)$/) {
9243: my $id=$1;
9244: if (($env{'form.uname'.$id}) && ($env{'form.udom'.$id})) {
9245: $user=$env{'form.uname'.$id}.':'.$env{'form.udom'.$id};
1.437 www 9246: } elsif ($env{'form.multi'.$id}) {
9247: $user=$env{'form.multi'.$id};
1.420 www 9248: }
9249: }
9250: if ($user) {
1.415 www 9251: my @answer=split(/\,/,$env{$key});
9252: my $sum=0;
1.522 www 9253: my $realnumber=$number;
1.415 www 9254: for (my $i=0;$i<$number;$i++) {
1.576 www 9255: if ($correct[$i] eq '-') {
9256: $realnumber--;
9257: } elsif ($answer[$i]) {
1.415 www 9258: if ($gradingmechanism eq 'attendance') {
9259: $sum+=$pcorrect;
1.576 www 9260: } elsif ($correct[$i] eq '*') {
1.522 www 9261: $sum+=$pcorrect;
1.415 www 9262: } else {
9263: if ($answer[$i] eq $correct[$i]) {
9264: $sum+=$pcorrect;
9265: } else {
9266: $sum+=$pincorrect;
9267: }
9268: }
9269: }
9270: }
1.522 www 9271: my $ave=$sum/(100*$realnumber);
1.416 www 9272: # Store
9273: my ($username,$domain)=split(/\:/,$user);
9274: my %grades=();
9275: $grades{"resource.$part.solved"}='correct_by_override';
9276: $grades{"resource.$part.awarded"}=$ave;
9277: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
9278: my $returncode=&Apache::lonnet::cstore(\%grades,$symb,
9279: $env{'request.course.id'},
9280: $domain,$username);
9281: if ($returncode ne 'ok') {
9282: $result.="<br /><span class=\"LC_error\">Failed to save student $username:$domain. Message when trying to save was ($returncode)</span>";
9283: } else {
9284: $storecount++;
9285: }
1.415 www 9286: }
9287: }
9288: # We are done
1.549 hauer 9289: $result.='<br />'.&mt('Successfully stored grades for [quant,_1,student].',$storecount).
1.416 www 9290: '</td></tr></table>'."\n".
1.414 www 9291: '</td></tr></table><br /><br />'."\n";
9292: return $result.&show_grading_menu_form($symb);
9293: }
9294:
1.582 raeburn 9295: sub navmap_errormsg {
9296: return '<div class="LC_error">'.
9297: &mt('An error occurred retrieving information about resources in the course.').'<br />'.
9298: &mt('It is recommended that you [_1]re-initialize the course[_2] and then return to this grading page..','<a href="/adm/roles?selectrole=1&newrole='.$env{'request.role'}.'">','</a>').
9299: '</div>';
9300: }
9301:
1.1 albertel 9302: sub handler {
1.41 ng 9303: my $request=$_[0];
1.434 albertel 9304: &reset_caches();
1.257 albertel 9305: if ($env{'browser.mathml'}) {
1.141 www 9306: &Apache::loncommon::content_type($request,'text/xml');
1.41 ng 9307: } else {
1.141 www 9308: &Apache::loncommon::content_type($request,'text/html');
1.41 ng 9309: }
9310: $request->send_http_header;
1.44 ng 9311: return '' if $request->header_only;
1.41 ng 9312: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.324 albertel 9313: my $symb=&get_symb($request,1);
1.160 albertel 9314: my @commands=&Apache::loncommon::get_env_multiple('form.command');
9315: my $command=$commands[0];
1.447 foxr 9316:
1.160 albertel 9317: if ($#commands > 0) {
9318: &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands));
9319: }
1.447 foxr 9320:
1.513 foxr 9321: $ssi_error = 0;
1.535 raeburn 9322: my $brcrum = [{href=>"/adm/grades",text=>"Grading"}];
9323: $request->print(&Apache::loncommon::start_page('Grading',undef,
9324: {'bread_crumbs' => $brcrum}));
1.324 albertel 9325: if ($symb eq '' && $command eq '') {
1.257 albertel 9326: if ($env{'user.adv'}) {
9327: if (($env{'form.codeone'}) && ($env{'form.codetwo'}) &&
9328: ($env{'form.codethree'})) {
9329: my $token=$env{'form.codeone'}.'*'.$env{'form.codetwo'}.'*'.
9330: $env{'form.codethree'};
1.41 ng 9331: my ($tsymb,$tuname,$tudom,$tcrsid)=
9332: &Apache::lonnet::checkin($token);
9333: if ($tsymb) {
1.137 albertel 9334: my ($map,$id,$url)=&Apache::lonnet::decode_symb($tsymb);
1.41 ng 9335: if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
1.513 foxr 9336: $request->print(&ssi_with_retries('/res/'.$url, $ssi_retries,
1.99 albertel 9337: ('grade_username' => $tuname,
9338: 'grade_domain' => $tudom,
9339: 'grade_courseid' => $tcrsid,
9340: 'grade_symb' => $tsymb)));
1.41 ng 9341: } else {
1.45 ng 9342: $request->print('<h3>Not authorized: '.$token.'</h3>');
1.99 albertel 9343: }
1.41 ng 9344: } else {
1.45 ng 9345: $request->print('<h3>Not a valid DocID: '.$token.'</h3>');
1.41 ng 9346: }
1.14 www 9347: } else {
1.41 ng 9348: $request->print(&Apache::lonxml::tokeninputfield());
9349: }
9350: }
9351: } else {
1.285 albertel 9352: &init_perm();
1.104 albertel 9353: if ($command eq 'submission' && $perm{'vgr'}) {
1.257 albertel 9354: ($env{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0));
1.103 albertel 9355: } elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) {
1.68 ng 9356: &pickStudentPage($request);
1.103 albertel 9357: } elsif ($command eq 'displayPage' && $perm{'vgr'}) {
1.68 ng 9358: &displayPage($request);
1.104 albertel 9359: } elsif ($command eq 'gradeByPage' && $perm{'mgr'}) {
1.71 ng 9360: &updateGradeByPage($request);
1.104 albertel 9361: } elsif ($command eq 'processGroup' && $perm{'vgr'}) {
1.41 ng 9362: &processGroup($request);
1.104 albertel 9363: } elsif ($command eq 'gradingmenu' && $perm{'vgr'}) {
1.443 banghart 9364: $request->print(&grading_menu($request));
9365: } elsif ($command eq 'submit_options' && $perm{'vgr'}) {
9366: $request->print(&submit_options($request));
1.104 albertel 9367: } elsif ($command eq 'viewgrades' && $perm{'vgr'}) {
1.41 ng 9368: $request->print(&viewgrades($request));
1.104 albertel 9369: } elsif ($command eq 'handgrade' && $perm{'mgr'}) {
1.41 ng 9370: $request->print(&processHandGrade($request));
1.106 albertel 9371: } elsif ($command eq 'editgrades' && $perm{'mgr'}) {
1.41 ng 9372: $request->print(&editgrades($request));
1.106 albertel 9373: } elsif ($command eq 'verify' && $perm{'vgr'}) {
1.41 ng 9374: $request->print(&verifyreceipt($request));
1.400 www 9375: } elsif ($command eq 'processclicker' && $perm{'mgr'}) {
9376: $request->print(&process_clicker($request));
9377: } elsif ($command eq 'processclickerfile' && $perm{'mgr'}) {
9378: $request->print(&process_clicker_file($request));
1.414 www 9379: } elsif ($command eq 'assignclickergrades' && $perm{'mgr'}) {
9380: $request->print(&assign_clicker_grades($request));
1.106 albertel 9381: } elsif ($command eq 'csvform' && $perm{'mgr'}) {
1.72 ng 9382: $request->print(&upcsvScores_form($request));
1.106 albertel 9383: } elsif ($command eq 'csvupload' && $perm{'mgr'}) {
1.41 ng 9384: $request->print(&csvupload($request));
1.106 albertel 9385: } elsif ($command eq 'csvuploadmap' && $perm{'mgr'} ) {
1.41 ng 9386: $request->print(&csvuploadmap($request));
1.246 albertel 9387: } elsif ($command eq 'csvuploadoptions' && $perm{'mgr'}) {
1.257 albertel 9388: if ($env{'form.associate'} ne 'Reverse Association') {
1.246 albertel 9389: $request->print(&csvuploadoptions($request));
1.41 ng 9390: } else {
1.257 albertel 9391: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
9392: $env{'form.upfile_associate'} = 'reverse';
1.41 ng 9393: } else {
1.257 albertel 9394: $env{'form.upfile_associate'} = 'forward';
1.41 ng 9395: }
9396: $request->print(&csvuploadmap($request));
9397: }
1.246 albertel 9398: } elsif ($command eq 'csvuploadassign' && $perm{'mgr'} ) {
9399: $request->print(&csvuploadassign($request));
1.106 albertel 9400: } elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
1.75 albertel 9401: $request->print(&scantron_selectphase($request));
1.203 albertel 9402: } elsif ($command eq 'scantron_warning' && $perm{'mgr'}) {
9403: $request->print(&scantron_do_warning($request));
1.142 albertel 9404: } elsif ($command eq 'scantron_validate' && $perm{'mgr'}) {
9405: $request->print(&scantron_validate_file($request));
1.106 albertel 9406: } elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
1.82 albertel 9407: $request->print(&scantron_process_students($request));
1.157 albertel 9408: } elsif ($command eq 'scantronupload' &&
1.257 albertel 9409: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
9410: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.162 albertel 9411: $request->print(&scantron_upload_scantron_data($request));
1.157 albertel 9412: } elsif ($command eq 'scantronupload_save' &&
1.257 albertel 9413: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
9414: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.157 albertel 9415: $request->print(&scantron_upload_scantron_data_save($request));
1.202 albertel 9416: } elsif ($command eq 'scantron_download' &&
1.257 albertel 9417: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.162 albertel 9418: $request->print(&scantron_download_scantron_data($request));
1.523 raeburn 9419: } elsif ($command eq 'checksubmissions' && $perm{'vgr'}) {
9420: $request->print(&checkscantron_results($request));
1.106 albertel 9421: } elsif ($command) {
1.562 bisitz 9422: $request->print('<p class="LC_error">'.&mt('Access Denied ([_1])',$command).'</p>');
1.26 albertel 9423: }
1.2 albertel 9424: }
1.513 foxr 9425: if ($ssi_error) {
9426: &ssi_print_error($request);
9427: }
1.353 albertel 9428: $request->print(&Apache::loncommon::end_page());
1.434 albertel 9429: &reset_caches();
1.44 ng 9430: return '';
9431: }
9432:
1.1 albertel 9433: 1;
9434:
1.13 albertel 9435: __END__;
1.531 jms 9436:
9437:
9438: =head1 NAME
9439:
9440: Apache::grades
9441:
9442: =head1 SYNOPSIS
9443:
9444: Handles the viewing of grades.
9445:
9446: This is part of the LearningOnline Network with CAPA project
9447: described at http://www.lon-capa.org.
9448:
9449: =head1 OVERVIEW
9450:
9451: Do an ssi with retries:
9452: While I'd love to factor out this with the vesrion in lonprintout,
9453: 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
9454: I'm not quite ready to invent (e.g. an ssi_with_retry object).
9455:
9456: At least the logic that drives this has been pulled out into loncommon.
9457:
9458:
9459:
9460: ssi_with_retries - Does the server side include of a resource.
9461: if the ssi call returns an error we'll retry it up to
9462: the number of times requested by the caller.
9463: If we still have a proble, no text is appended to the
9464: output and we set some global variables.
9465: to indicate to the caller an SSI error occurred.
9466: All of this is supposed to deal with the issues described
9467: in LonCAPA BZ 5631 see:
9468: http://bugs.lon-capa.org/show_bug.cgi?id=5631
9469: by informing the user that this happened.
9470:
9471: Parameters:
9472: resource - The resource to include. This is passed directly, without
9473: interpretation to lonnet::ssi.
9474: form - The form hash parameters that guide the interpretation of the resource
9475:
9476: retries - Number of retries allowed before giving up completely.
9477: Returns:
9478: On success, returns the rendered resource identified by the resource parameter.
9479: Side Effects:
9480: The following global variables can be set:
9481: ssi_error - If an unrecoverable error occurred this becomes true.
9482: It is up to the caller to initialize this to false
9483: if desired.
9484: ssi_error_resource - If an unrecoverable error occurred, this is the value
9485: of the resource that could not be rendered by the ssi
9486: call.
9487: ssi_error_message - The error string fetched from the ssi response
9488: in the event of an error.
9489:
9490:
9491: =head1 HANDLER SUBROUTINE
9492:
9493: ssi_with_retries()
9494:
9495: =head1 SUBROUTINES
9496:
9497: =over
9498:
9499: =item scantron_get_correction() :
9500:
9501: Builds the interface screen to interact with the operator to fix a
9502: specific error condition in a specific scanline
9503:
9504: Arguments:
9505: $r - Apache request object
9506: $i - number of the current scanline
9507: $scan_record - hash ref as returned from &scantron_parse_scanline()
9508: $scan_config - hash ref as returned from &get_scantron_config()
9509: $line - full contents of the current scanline
9510: $error - error condition, valid values are
9511: 'incorrectCODE', 'duplicateCODE',
9512: 'doublebubble', 'missingbubble',
9513: 'duplicateID', 'incorrectID'
9514: $arg - extra information needed
9515: For errors:
9516: - duplicateID - paper number that this studentID was seen before on
9517: - duplicateCODE - array ref of the paper numbers this CODE was
9518: seen on before
9519: - incorrectCODE - current incorrect CODE
9520: - doublebubble - array ref of the bubble lines that have double
9521: bubble errors
9522: - missingbubble - array ref of the bubble lines that have missing
9523: bubble errors
9524:
9525: =item scantron_get_maxbubble() :
9526:
1.582 raeburn 9527: Arguments:
9528: $nav_error - Reference to scalar which is a flag to indicate a
9529: failure to retrieve a navmap object.
9530: if $nav_error is set to 1 by scantron_get_maxbubble(), the
9531: calling routine should trap the error condition and display the warning
9532: found in &navmap_errormsg().
9533:
1.531 jms 9534: Returns the maximum number of bubble lines that are expected to
9535: occur. Does this by walking the selected sequence rendering the
9536: resource and then checking &Apache::lonxml::get_problem_counter()
9537: for what the current value of the problem counter is.
9538:
9539: Caches the results to $env{'form.scantron_maxbubble'},
9540: $env{'form.scantron.bubble_lines.n'},
9541: $env{'form.scantron.first_bubble_line.n'} and
9542: $env{"form.scantron.sub_bubblelines.n"}
9543: which are the total number of bubble, lines, the number of bubble
9544: lines for response n and number of the first bubble line for response n,
9545: and a comma separated list of numbers of bubble lines for sub-questions
9546: (for optionresponse, matchresponse, and rankresponse items), for response n.
9547:
9548:
9549: =item scantron_validate_missingbubbles() :
9550:
9551: Validates all scanlines in the selected file to not have any
9552: answers that don't have bubbles that have not been verified
9553: to be bubble free.
9554:
9555: =item scantron_process_students() :
9556:
9557: Routine that does the actual grading of the bubble sheet information.
9558:
9559: The parsed scanline hash is added to %env
9560:
9561: Then foreach unskipped scanline it does an &Apache::lonnet::ssi()
9562: foreach resource , with the form data of
9563:
9564: 'submitted' =>'scantron'
9565: 'grade_target' =>'grade',
9566: 'grade_username'=> username of student
9567: 'grade_domain' => domain of student
9568: 'grade_courseid'=> of course
9569: 'grade_symb' => symb of resource to grade
9570:
9571: This triggers a grading pass. The problem grading code takes care
9572: of converting the bubbled letter information (now in %env) into a
9573: valid submission.
9574:
9575: =item scantron_upload_scantron_data() :
9576:
9577: Creates the screen for adding a new bubble sheet data file to a course.
9578:
9579: =item scantron_upload_scantron_data_save() :
9580:
9581: Adds a provided bubble information data file to the course if user
9582: has the correct privileges to do so.
9583:
9584: =item valid_file() :
9585:
9586: Validates that the requested bubble data file exists in the course.
9587:
9588: =item scantron_download_scantron_data() :
9589:
9590: Shows a list of the three internal files (original, corrected,
9591: skipped) for a specific bubble sheet data file that exists in the
9592: course.
9593:
9594: =item scantron_validate_ID() :
9595:
9596: Validates all scanlines in the selected file to not have any
1.556 weissno 9597: invalid or underspecified student/employee IDs
1.531 jms 9598:
1.582 raeburn 9599: =item navmap_errormsg() :
9600:
9601: Returns HTML mark-up inside a <div></div> with a link to re-initialize the course.
9602: Should be called whenever the request to instantiate a navmap object fails.
9603:
1.531 jms 9604: =back
9605:
9606: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>