Annotation of loncom/homework/grades.pm, revision 1.592
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.592 ! bisitz 4: # $Id: grades.pm,v 1.591 2010/01/27 06:26:55 raeburn Exp $
1.17 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
1.529 jms 29:
30:
1.1 albertel 31: package Apache::grades;
32: use strict;
33: use Apache::style;
34: use Apache::lonxml;
35: use Apache::lonnet;
1.3 albertel 36: use Apache::loncommon;
1.112 ng 37: use Apache::lonhtmlcommon;
1.68 ng 38: use Apache::lonnavmaps;
1.1 albertel 39: use Apache::lonhomework;
1.456 banghart 40: use Apache::lonpickcode;
1.55 matthew 41: use Apache::loncoursedata;
1.362 albertel 42: use Apache::lonmsg();
1.1 albertel 43: use Apache::Constants qw(:common);
1.167 sakharuk 44: use Apache::lonlocal;
1.386 raeburn 45: use Apache::lonenc;
1.170 albertel 46: use String::Similarity;
1.359 www 47: use LONCAPA;
48:
1.315 bowersj2 49: use POSIX qw(floor);
1.87 www 50:
1.435 foxr 51:
1.513 foxr 52:
1.435 foxr 53: my %perm=();
1.447 foxr 54:
1.513 foxr 55: # These variables are used to recover from ssi errors
56:
57: my $ssi_retries = 5;
58: my $ssi_error;
59: my $ssi_error_resource;
60: my $ssi_error_message;
61:
62:
63: sub ssi_with_retries {
64: my ($resource, $retries, %form) = @_;
65: my ($content, $response) = &Apache::loncommon::ssi_with_retries($resource, $retries, %form);
66: if ($response->is_error) {
67: $ssi_error = 1;
68: $ssi_error_resource = $resource;
69: $ssi_error_message = $response->code . " " . $response->message;
70: }
71:
72: return $content;
73:
74: }
75: #
76: # Prodcuces an ssi retry failure error message to the user:
77: #
78:
79: sub ssi_print_error {
80: my ($r) = @_;
1.516 raeburn 81: my $helpurl = &Apache::loncommon::top_nav_help('Helpdesk');
82: $r->print('
83: <br />
84: <h2>'.&mt('An unrecoverable network error occurred:').'</h2>
85: <p>
86: '.&mt('Unable to retrieve a resource from a server:').'<br />
87: '.&mt('Resource:').' '.$ssi_error_resource.'<br />
88: '.&mt('Error:').' '.$ssi_error_message.'
89: </p>
90: <p>'.
91: &mt('It is recommended that you try again later, as this error may mean the server was just temporarily unavailable, or is down for maintenance.').'<br />'.
92: &mt('If the error persists, please contact the [_1] for assistance.',$helpurl).
93: '</p>');
94: return;
1.513 foxr 95: }
96:
1.44 ng 97: #
1.146 albertel 98: # --- Retrieve the parts from the metadata file.---
1.44 ng 99: sub getpartlist {
1.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.=
1.592 ! bisitz 947: '<span class="LC_nobreak">'.
! 948: '<label><input type="radio" name="lastSub" value="lastonly" '.$checklastsub.' /> '.
! 949: &mt('last submission only').' </label></span>'."\n".
! 950: '<span class="LC_nobreak">'.
! 951: '<label><input type="radio" name="lastSub" value="last" /> '.
! 952: &mt('last submission & parts info').' </label></span>'."\n".
! 953: '<span class="LC_nobreak">'.
! 954: '<label><input type="radio" name="lastSub" value="datesub" /> '.
! 955: &mt('by dates and submissions').'</label></span>'."\n".
! 956: '<span class="LC_nobreak">'.
! 957: '<label><input type="radio" name="lastSub" value="all" /> '.
! 958: &mt('all details').'</label></span>';
1.561 bisitz 959: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Submissions'))
960: .$submission_options
961: .&Apache::lonhtmlcommon::row_closure();
962:
963: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Grading Increments'))
964: .'<select name="increment">'
965: .'<option value="1">'.&mt('Whole Points').'</option>'
966: .'<option value=".5">'.&mt('Half Points').'</option>'
967: .'<option value=".25">'.&mt('Quarter Points').'</option>'
968: .'<option value=".1">'.&mt('Tenths of a Point').'</option>'
969: .'</select>'
970: .&Apache::lonhtmlcommon::row_closure();
1.485 albertel 971:
972: $gradeTable .=
1.432 banghart 973: &build_section_inputs().
1.45 ng 974: '<input type="hidden" name="submitonly" value="'.$submitonly.'" />'."\n".
1.257 albertel 975: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" /><br />'."\n".
976: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" /><br />'."\n".
977: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
978: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.418 albertel 979: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.110 ng 980: '<input type="hidden" name="saveStatusOld" value="'.$saveStatus.'" />'."\n";
981:
1.257 albertel 982: if (exists($env{'form.gradingMenu'}) && exists($env{'form.Status'})) {
1.561 bisitz 983: $gradeTable .= '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n";
1.124 ng 984: } else {
1.561 bisitz 985: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Student Status'))
986: .&Apache::lonhtmlcommon::StatusOptions(
987: $saveStatus,undef,1,'javascript:reLoadList(this.form);')
988: .&Apache::lonhtmlcommon::row_closure();
1.124 ng 989: }
1.112 ng 990:
1.561 bisitz 991: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Check For Plagiarism'))
992: .'<input type="checkbox" name="checkPlag" checked="checked" />'
993: .&Apache::lonhtmlcommon::row_closure(1)
994: .&Apache::lonhtmlcommon::end_pick_box();
995:
996: $gradeTable .= '<p>'
997: .&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"
998: .'<input type="hidden" name="command" value="processGroup" />'
999: .'</p>';
1.249 albertel 1000:
1001: # checkall buttons
1002: $gradeTable.=&check_script('gradesub', 'stuinfo');
1.110 ng 1003: $gradeTable.='<input type="button" '."\n".
1.589 bisitz 1004: 'onclick="javascript:checkSelect(this.form.stuinfo);" '."\n".
1005: 'value="'.&mt('Next').' →" /> <br />'."\n";
1.249 albertel 1006: $gradeTable.=&check_buttons();
1.450 banghart 1007: my ($classlist, undef, $fullname) = &getclasslist($getsec,'1',$getgroup);
1.474 albertel 1008: $gradeTable.= &Apache::loncommon::start_data_table().
1009: &Apache::loncommon::start_data_table_header_row();
1.110 ng 1010: my $loop = 0;
1011: while ($loop < 2) {
1.485 albertel 1012: $gradeTable.='<th>'.&mt('No.').'</th><th>'.&mt('Select').'</th>'.
1013: '<th>'.&nameUserString('header').' '.&mt('Section/Group').'</th>';
1.301 albertel 1014: if ($env{'form.showgrading'} eq 'yes'
1015: && $submitonly ne 'queued'
1016: && $submitonly ne 'all') {
1.485 albertel 1017: foreach my $part (sort(@$partlist)) {
1018: my $display_part=
1019: &get_display_part((split(/_/,$part))[0],$symb);
1020: $gradeTable.=
1021: '<th>'.&mt('Part: [_1] Status',$display_part).'</th>';
1.110 ng 1022: }
1.301 albertel 1023: } elsif ($submitonly eq 'queued') {
1.474 albertel 1024: $gradeTable.='<th>'.&mt('Queue Status').' </th>';
1.110 ng 1025: }
1026: $loop++;
1.126 ng 1027: # $gradeTable.='<td></td>' if ($loop%2 ==1);
1.41 ng 1028: }
1.474 albertel 1029: $gradeTable.=&Apache::loncommon::end_data_table_header_row()."\n";
1.41 ng 1030:
1.45 ng 1031: my $ctr = 0;
1.294 albertel 1032: foreach my $student (sort
1033: {
1034: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
1035: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
1036: }
1037: return $a cmp $b;
1038: }
1039: (keys(%$fullname))) {
1.41 ng 1040: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 1041:
1.110 ng 1042: my %status = ();
1.301 albertel 1043:
1044: if ($submitonly eq 'queued') {
1045: my %queue_status =
1046: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
1047: $udom,$uname);
1048: next if (!defined($queue_status{'gradingqueue'}));
1049: $status{'gradingqueue'} = $queue_status{'gradingqueue'};
1050: }
1051:
1052: if ($env{'form.showgrading'} eq 'yes'
1053: && $submitonly ne 'queued'
1054: && $submitonly ne 'all') {
1.324 albertel 1055: (%status) =&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 1056: my $submitted = 0;
1.164 albertel 1057: my $graded = 0;
1.248 albertel 1058: my $incorrect = 0;
1.110 ng 1059: foreach (keys(%status)) {
1.145 albertel 1060: $submitted = 1 if ($status{$_} ne 'nothing');
1.248 albertel 1061: $graded = 1 if ($status{$_} =~ /^ungraded/);
1062: $incorrect = 1 if ($status{$_} =~ /^incorrect/);
1063:
1.110 ng 1064: my ($foo,$partid,$foo1) = split(/\./,$_);
1065: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
1.145 albertel 1066: $submitted = 0;
1.150 albertel 1067: my ($part)=split(/\./,$partid);
1.110 ng 1068: $gradeTable.='<input type="hidden" name="'.
1.150 albertel 1069: $student.':'.$part.':submitted_by" value="'.
1.110 ng 1070: $status{'resource.'.$partid.'.submitted_by'}.'" />';
1071: }
1.41 ng 1072: }
1.248 albertel 1073:
1.156 albertel 1074: next if (!$submitted && ($submitonly eq 'yes' ||
1075: $submitonly eq 'incorrect' ||
1076: $submitonly eq 'graded'));
1.248 albertel 1077: next if (!$graded && ($submitonly eq 'graded'));
1078: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 1079: }
1.34 ng 1080:
1.45 ng 1081: $ctr++;
1.249 albertel 1082: my $section = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
1.452 banghart 1083: my $group = $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1.104 albertel 1084: if ( $perm{'vgr'} eq 'F' ) {
1.474 albertel 1085: if ($ctr%2 ==1) {
1086: $gradeTable.= &Apache::loncommon::start_data_table_row();
1087: }
1.126 ng 1088: $gradeTable.='<td align="right">'.$ctr.' </td>'.
1.563 bisitz 1089: '<td align="center"><label><input type="checkbox" name="stuinfo" value="'.
1.249 albertel 1090: $student.':'.$$fullname{$student}.':::SECTION'.$section.
1091: ') " /> </label></td>'."\n".'<td>'.
1092: &nameUserString(undef,$$fullname{$student},$uname,$udom).
1.474 albertel 1093: ' '.$section.($group ne '' ?'/'.$group:'').'</td>'."\n";
1.110 ng 1094:
1.257 albertel 1095: if ($env{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
1.524 raeburn 1096: foreach (sort(keys(%status))) {
1.485 albertel 1097: next if ($_ =~ /^resource.*?submitted_by$/);
1098: $gradeTable.='<td align="center"> '.&mt($status{$_}).' </td>'."\n";
1.110 ng 1099: }
1.41 ng 1100: }
1.126 ng 1101: # $gradeTable.='<td></td>' if ($ctr%2 ==1);
1.474 albertel 1102: if ($ctr%2 ==0) {
1103: $gradeTable.=&Apache::loncommon::end_data_table_row()."\n";
1104: }
1.41 ng 1105: }
1106: }
1.110 ng 1107: if ($ctr%2 ==1) {
1.126 ng 1108: $gradeTable.='<td> </td><td> </td><td> </td>';
1.301 albertel 1109: if ($env{'form.showgrading'} eq 'yes'
1110: && $submitonly ne 'queued'
1111: && $submitonly ne 'all') {
1.110 ng 1112: foreach (@$partlist) {
1113: $gradeTable.='<td> </td>';
1114: }
1.301 albertel 1115: } elsif ($submitonly eq 'queued') {
1116: $gradeTable.='<td> </td>';
1.110 ng 1117: }
1.474 albertel 1118: $gradeTable.=&Apache::loncommon::end_data_table_row();
1.110 ng 1119: }
1120:
1.474 albertel 1121: $gradeTable.=&Apache::loncommon::end_data_table()."\n".
1.589 bisitz 1122: '<input type="button" '.
1123: 'onclick="javascript:checkSelect(this.form.stuinfo);" '.
1124: 'value="'.&mt('Next').' →" /></form>'."\n";
1.45 ng 1125: if ($ctr == 0) {
1.96 albertel 1126: my $num_students=(scalar(keys(%$fullname)));
1127: if ($num_students eq 0) {
1.485 albertel 1128: $gradeTable='<br /> <span class="LC_warning">'.&mt('There are no students currently enrolled.').'</span>';
1.96 albertel 1129: } else {
1.171 albertel 1130: my $submissions='submissions';
1131: if ($submitonly eq 'incorrect') { $submissions = 'incorrect submissions'; }
1132: if ($submitonly eq 'graded' ) { $submissions = 'ungraded submissions'; }
1.301 albertel 1133: if ($submitonly eq 'queued' ) { $submissions = 'queued submissions'; }
1.398 albertel 1134: $gradeTable='<br /> <span class="LC_warning">'.
1.485 albertel 1135: &mt('No '.$submissions.' found for this resource for any students. ([_1] students checked for '.$submissions.')',
1136: $num_students).
1137: '</span><br />';
1.96 albertel 1138: }
1.46 ng 1139: } elsif ($ctr == 1) {
1.474 albertel 1140: $gradeTable =~ s/type="checkbox"/type="checkbox" checked="checked"/;
1.45 ng 1141: }
1.324 albertel 1142: $gradeTable.=&show_grading_menu_form($symb);
1.45 ng 1143: $request->print($gradeTable);
1.44 ng 1144: return '';
1.10 ng 1145: }
1146:
1.44 ng 1147: #---- Called from the listStudents routine
1.249 albertel 1148:
1149: sub check_script {
1150: my ($form, $type)=@_;
1151: my $chkallscript='<script type="text/javascript">
1152: function checkall() {
1153: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1154: ele = document.forms.'.$form.'.elements[i];
1155: if (ele.name == "'.$type.'") {
1156: document.forms.'.$form.'.elements[i].checked=true;
1157: }
1158: }
1159: }
1160:
1161: function checksec() {
1162: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1163: ele = document.forms.'.$form.'.elements[i];
1164: string = document.forms.'.$form.'.chksec.value;
1165: if
1166: (ele.value.indexOf(":::SECTION"+string)>0) {
1167: document.forms.'.$form.'.elements[i].checked=true;
1168: }
1169: }
1170: }
1171:
1172:
1173: function uncheckall() {
1174: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1175: ele = document.forms.'.$form.'.elements[i];
1176: if (ele.name == "'.$type.'") {
1177: document.forms.'.$form.'.elements[i].checked=false;
1178: }
1179: }
1180: }
1181:
1182: </script>'."\n";
1183: return $chkallscript;
1184: }
1185:
1186: sub check_buttons {
1.485 albertel 1187: my $buttons.='<input type="button" onclick="checkall()" value="'.&mt('Check All').'" />';
1188: $buttons.='<input type="button" onclick="uncheckall()" value="'.&mt('Uncheck All').'" /> ';
1189: $buttons.='<input type="button" onclick="checksec()" value="'.&mt('Check Section/Group').'" />';
1.249 albertel 1190: $buttons.='<input type="text" size="5" name="chksec" /> ';
1191: return $buttons;
1192: }
1193:
1.44 ng 1194: # Displays the submissions for one student or a group of students
1.34 ng 1195: sub processGroup {
1.41 ng 1196: my ($request) = shift;
1197: my $ctr = 0;
1.155 albertel 1198: my @stuchecked = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.41 ng 1199: my $total = scalar(@stuchecked)-1;
1.45 ng 1200:
1.396 banghart 1201: foreach my $student (@stuchecked) {
1202: my ($uname,$udom,$fullname) = split(/:/,$student);
1.257 albertel 1203: $env{'form.student'} = $uname;
1204: $env{'form.userdom'} = $udom;
1205: $env{'form.fullname'} = $fullname;
1.41 ng 1206: &submission($request,$ctr,$total);
1207: $ctr++;
1208: }
1209: return '';
1.35 ng 1210: }
1.34 ng 1211:
1.44 ng 1212: #------------------------------------------------------------------------------------
1213: #
1214: #-------------------------- Next few routines handles grading by student, essentially
1215: # handles essay response type problem/part
1216: #
1217: #--- Javascript to handle the submission page functionality ---
1218: sub sub_page_js {
1219: my $request = shift;
1.539 riegler 1220: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
1.44 ng 1221: $request->print(<<SUBJAVASCRIPT);
1222: <script type="text/javascript" language="javascript">
1.71 ng 1223: function updateRadio(formname,id,weight) {
1.125 ng 1224: var gradeBox = formname["GD_BOX"+id];
1225: var radioButton = formname["RADVAL"+id];
1226: var oldpts = formname["oldpts"+id].value;
1.72 ng 1227: var pts = checkSolved(formname,id) == 'update' ? gradeBox.value : oldpts;
1.71 ng 1228: gradeBox.value = pts;
1229: var resetbox = false;
1230: if (isNaN(pts) || pts < 0) {
1.539 riegler 1231: alert("$alertmsg"+pts);
1.71 ng 1232: for (var i=0; i<radioButton.length; i++) {
1233: if (radioButton[i].checked) {
1234: gradeBox.value = i;
1235: resetbox = true;
1236: }
1237: }
1238: if (!resetbox) {
1239: formtextbox.value = "";
1240: }
1241: return;
1.44 ng 1242: }
1.71 ng 1243:
1244: if (pts > weight) {
1245: var resp = confirm("You entered a value ("+pts+
1246: ") greater than the weight for the part. Accept?");
1247: if (resp == false) {
1.125 ng 1248: gradeBox.value = oldpts;
1.71 ng 1249: return;
1250: }
1.44 ng 1251: }
1.13 albertel 1252:
1.71 ng 1253: for (var i=0; i<radioButton.length; i++) {
1254: radioButton[i].checked=false;
1255: if (pts == i && pts != "") {
1256: radioButton[i].checked=true;
1257: }
1258: }
1259: updateSelect(formname,id);
1.125 ng 1260: formname["stores"+id].value = "0";
1.41 ng 1261: }
1.5 albertel 1262:
1.72 ng 1263: function writeBox(formname,id,pts) {
1.125 ng 1264: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1265: if (checkSolved(formname,id) == 'update') {
1266: gradeBox.value = pts;
1267: } else {
1.125 ng 1268: var oldpts = formname["oldpts"+id].value;
1.72 ng 1269: gradeBox.value = oldpts;
1.125 ng 1270: var radioButton = formname["RADVAL"+id];
1.71 ng 1271: for (var i=0; i<radioButton.length; i++) {
1272: radioButton[i].checked=false;
1.72 ng 1273: if (i == oldpts) {
1.71 ng 1274: radioButton[i].checked=true;
1275: }
1276: }
1.41 ng 1277: }
1.125 ng 1278: formname["stores"+id].value = "0";
1.71 ng 1279: updateSelect(formname,id);
1280: return;
1.41 ng 1281: }
1.44 ng 1282:
1.71 ng 1283: function clearRadBox(formname,id) {
1284: if (checkSolved(formname,id) == 'noupdate') {
1285: updateSelect(formname,id);
1286: return;
1287: }
1.125 ng 1288: gradeSelect = formname["GD_SEL"+id];
1.71 ng 1289: for (var i=0; i<gradeSelect.length; i++) {
1290: if (gradeSelect[i].selected) {
1291: var selectx=i;
1292: }
1293: }
1.125 ng 1294: var stores = formname["stores"+id];
1.71 ng 1295: if (selectx == stores.value) { return };
1.125 ng 1296: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1297: gradeBox.value = "";
1.125 ng 1298: var radioButton = formname["RADVAL"+id];
1.71 ng 1299: for (var i=0; i<radioButton.length; i++) {
1300: radioButton[i].checked=false;
1301: }
1302: stores.value = selectx;
1303: }
1.5 albertel 1304:
1.71 ng 1305: function checkSolved(formname,id) {
1.125 ng 1306: if (formname["solved"+id].value == "correct_by_student" && formname.overRideScore.value == 'no') {
1.118 ng 1307: var reply = confirm("This problem has been graded correct by the computer. Do you want to change the score?");
1308: if (!reply) {return "noupdate";}
1.120 ng 1309: formname.overRideScore.value = 'yes';
1.41 ng 1310: }
1.71 ng 1311: return "update";
1.13 albertel 1312: }
1.71 ng 1313:
1314: function updateSelect(formname,id) {
1.125 ng 1315: formname["GD_SEL"+id][0].selected = true;
1.71 ng 1316: return;
1.41 ng 1317: }
1.33 ng 1318:
1.121 ng 1319: //=========== Check that a point is assigned for all the parts ============
1.71 ng 1320: function checksubmit(formname,val,total,parttot) {
1.121 ng 1321: formname.gradeOpt.value = val;
1.71 ng 1322: if (val == "Save & Next") {
1323: for (i=0;i<=total;i++) {
1324: for (j=0;j<parttot;j++) {
1.125 ng 1325: var partid = formname["partid"+i+"_"+j].value;
1.127 ng 1326: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1327: var points = formname["GD_BOX"+i+"_"+partid].value;
1.71 ng 1328: if (points == "") {
1.125 ng 1329: var name = formname["name"+i].value;
1.129 ng 1330: var studentID = (name != '' ? name : formname["unamedom"+i].value);
1331: var resp = confirm("You did not assign a score for "+studentID+
1332: ", part "+partid+". Continue?");
1.71 ng 1333: if (resp == false) {
1.125 ng 1334: formname["GD_BOX"+i+"_"+partid].focus();
1.71 ng 1335: return false;
1336: }
1337: }
1338: }
1339:
1340: }
1341: }
1342:
1343: }
1.121 ng 1344: if (val == "Grade Student") {
1345: formname.showgrading.value = "yes";
1346: if (formname.Status.value == "") {
1347: formname.Status.value = "Active";
1348: }
1349: formname.studentNo.value = total;
1350: }
1.120 ng 1351: formname.submit();
1352: }
1353:
1.71 ng 1354: //======= Check that a score is assigned for all the problems (page/sequence grading only) =========
1355: function checkSubmitPage(formname,total) {
1356: noscore = new Array(100);
1357: var ptr = 0;
1358: for (i=1;i<total;i++) {
1.125 ng 1359: var partid = formname["q_"+i].value;
1.127 ng 1360: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1361: var points = formname["GD_BOX"+i+"_"+partid].value;
1362: var status = formname["solved"+i+"_"+partid].value;
1.71 ng 1363: if (points == "" && status != "correct_by_student") {
1364: noscore[ptr] = i;
1365: ptr++;
1366: }
1367: }
1368: }
1369: if (ptr != 0) {
1370: var sense = ptr == 1 ? ": " : "s: ";
1371: var prolist = "";
1372: if (ptr == 1) {
1373: prolist = noscore[0];
1374: } else {
1375: var i = 0;
1376: while (i < ptr-1) {
1377: prolist += noscore[i]+", ";
1378: i++;
1379: }
1380: prolist += "and "+noscore[i];
1381: }
1382: var resp = confirm("You did not assign any score for the following problem"+sense+prolist+". Continue?");
1383: if (resp == false) {
1384: return false;
1385: }
1386: }
1.45 ng 1387:
1.71 ng 1388: formname.submit();
1389: }
1390: </script>
1391: SUBJAVASCRIPT
1392: }
1.45 ng 1393:
1.71 ng 1394: #--- javascript for essay type problem --
1395: sub sub_page_kw_js {
1396: my $request = shift;
1.80 ng 1397: my $iconpath = $request->dir_config('lonIconsURL');
1.118 ng 1398: &commonJSfunctions($request);
1.350 albertel 1399:
1.351 albertel 1400: my $inner_js_msg_central=<<INNERJS;
1.350 albertel 1401: <script text="text/javascript">
1402: function checkInput() {
1403: opener.document.SCORE.msgsub.value = opener.checkEntities(document.msgcenter.msgsub.value);
1404: var nmsg = opener.document.SCORE.savemsgN.value;
1405: var usrctr = document.msgcenter.usrctr.value;
1406: var newval = opener.document.SCORE["newmsg"+usrctr];
1407: newval.value = opener.checkEntities(document.msgcenter.newmsg.value);
1408:
1409: var msgchk = "";
1410: if (document.msgcenter.subchk.checked) {
1411: msgchk = "msgsub,";
1412: }
1413: var includemsg = 0;
1414: for (var i=1; i<=nmsg; i++) {
1415: var opnmsg = opener.document.SCORE["savemsg"+i];
1416: var frmmsg = document.msgcenter["msg"+i];
1417: opnmsg.value = opener.checkEntities(frmmsg.value);
1418: var showflg = opener.document.SCORE["shownOnce"+i];
1419: showflg.value = "1";
1420: var chkbox = document.msgcenter["msgn"+i];
1421: if (chkbox.checked) {
1422: msgchk += "savemsg"+i+",";
1423: includemsg = 1;
1424: }
1425: }
1426: if (document.msgcenter.newmsgchk.checked) {
1427: msgchk += "newmsg"+usrctr;
1428: includemsg = 1;
1429: }
1430: imgformname = opener.document.SCORE["mailicon"+usrctr];
1431: imgformname.src = "$iconpath/"+((includemsg) ? "mailto.gif" : "mailbkgrd.gif");
1432: var includemsg = opener.document.SCORE["includemsg"+usrctr];
1433: includemsg.value = msgchk;
1434:
1435: self.close()
1436:
1437: }
1438: </script>
1439: INNERJS
1440:
1.351 albertel 1441: my $inner_js_highlight_central=<<INNERJS;
1442: <script type="text/javascript">
1443: function updateChoice(flag) {
1444: opener.document.SCORE.kwclr.value = opener.radioSelection(document.hlCenter.kwdclr);
1445: opener.document.SCORE.kwsize.value = opener.radioSelection(document.hlCenter.kwdsize);
1446: opener.document.SCORE.kwstyle.value = opener.radioSelection(document.hlCenter.kwdstyle);
1447: opener.document.SCORE.refresh.value = "on";
1448: if (opener.document.SCORE.keywords.value!=""){
1449: opener.document.SCORE.submit();
1450: }
1451: self.close()
1452: }
1453: </script>
1454: INNERJS
1455:
1456: my $start_page_msg_central =
1457: &Apache::loncommon::start_page('Message Central',$inner_js_msg_central,
1458: {'js_ready' => 1,
1459: 'only_body' => 1,
1460: 'bgcolor' =>'#FFFFFF',});
1461: my $end_page_msg_central =
1462: &Apache::loncommon::end_page({'js_ready' => 1});
1463:
1464:
1465: my $start_page_highlight_central =
1466: &Apache::loncommon::start_page('Highlight Central',
1467: $inner_js_highlight_central,
1.350 albertel 1468: {'js_ready' => 1,
1469: 'only_body' => 1,
1470: 'bgcolor' =>'#FFFFFF',});
1.351 albertel 1471: my $end_page_highlight_central =
1.350 albertel 1472: &Apache::loncommon::end_page({'js_ready' => 1});
1473:
1.219 www 1474: my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
1.236 albertel 1475: $docopen=~s/^document\.//;
1.539 riegler 1476: my $alertmsg = &mt('Please select a word or group of words from document and then click this link.');
1.71 ng 1477: $request->print(<<SUBJAVASCRIPT);
1478: <script type="text/javascript" language="javascript">
1.45 ng 1479:
1.44 ng 1480: //===================== Show list of keywords ====================
1.122 ng 1481: function keywords(formname) {
1482: var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",formname.keywords.value);
1.44 ng 1483: if (nret==null) return;
1.122 ng 1484: formname.keywords.value = nret;
1.44 ng 1485:
1.122 ng 1486: if (formname.keywords.value != "") {
1.128 ng 1487: formname.refresh.value = "on";
1.122 ng 1488: formname.submit();
1.44 ng 1489: }
1490: return;
1491: }
1492:
1493: //===================== Script to view submitted by ==================
1494: function viewSubmitter(submitter) {
1495: document.SCORE.refresh.value = "on";
1496: document.SCORE.NCT.value = "1";
1497: document.SCORE.unamedom0.value = submitter;
1498: document.SCORE.submit();
1499: return;
1500: }
1501:
1502: //===================== Script to add keyword(s) ==================
1503: function getSel() {
1504: if (document.getSelection) txt = document.getSelection();
1505: else if (document.selection) txt = document.selection.createRange().text;
1506: else return;
1507: var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
1508: if (cleantxt=="") {
1.539 riegler 1509: alert("$alertmsg");
1.44 ng 1510: return;
1511: }
1512: var nret = prompt("Add selection to keyword list? Edit if desired.",cleantxt);
1513: if (nret==null) return;
1.127 ng 1514: document.SCORE.keywords.value = document.SCORE.keywords.value+" "+nret;
1.44 ng 1515: if (document.SCORE.keywords.value != "") {
1.127 ng 1516: document.SCORE.refresh.value = "on";
1.44 ng 1517: document.SCORE.submit();
1518: }
1519: return;
1520: }
1521:
1522: //====================== Script for composing message ==============
1.80 ng 1523: // preload images
1524: img1 = new Image();
1525: img1.src = "$iconpath/mailbkgrd.gif";
1526: img2 = new Image();
1527: img2.src = "$iconpath/mailto.gif";
1528:
1.44 ng 1529: function msgCenter(msgform,usrctr,fullname) {
1530: var Nmsg = msgform.savemsgN.value;
1531: savedMsgHeader(Nmsg,usrctr,fullname);
1532: var subject = msgform.msgsub.value;
1.127 ng 1533: var msgchk = document.SCORE["includemsg"+usrctr].value;
1.44 ng 1534: re = /msgsub/;
1535: var shwsel = "";
1536: if (re.test(msgchk)) { shwsel = "checked" }
1.123 ng 1537: subject = (document.SCORE.shownSub.value == 0 ? checkEntities(subject) : subject);
1538: displaySubject(checkEntities(subject),shwsel);
1.44 ng 1539: for (var i=1; i<=Nmsg; i++) {
1.123 ng 1540: var testmsg = "savemsg"+i+",";
1541: re = new RegExp(testmsg,"g");
1.44 ng 1542: shwsel = "";
1543: if (re.test(msgchk)) { shwsel = "checked" }
1.125 ng 1544: var message = document.SCORE["savemsg"+i].value;
1.126 ng 1545: message = (document.SCORE["shownOnce"+i].value == 0 ? checkEntities(message) : message);
1.123 ng 1546: displaySavedMsg(i,message,shwsel); //I do not get it. w/o checkEntities on saved messages,
1547: //any < is already converted to <, etc. However, only once!!
1.44 ng 1548: }
1.125 ng 1549: newmsg = document.SCORE["newmsg"+usrctr].value;
1.44 ng 1550: shwsel = "";
1551: re = /newmsg/;
1552: if (re.test(msgchk)) { shwsel = "checked" }
1553: newMsg(newmsg,shwsel);
1554: msgTail();
1555: return;
1556: }
1557:
1.123 ng 1558: function checkEntities(strx) {
1559: if (strx.length == 0) return strx;
1560: var orgStr = ["&", "<", ">", '"'];
1561: var newStr = ["&", "<", ">", """];
1562: var counter = 0;
1563: while (counter < 4) {
1564: strx = strReplace(strx,orgStr[counter],newStr[counter]);
1565: counter++;
1566: }
1567: return strx;
1568: }
1569:
1570: function strReplace(strx, orgStr, newStr) {
1571: return strx.split(orgStr).join(newStr);
1572: }
1573:
1.44 ng 1574: function savedMsgHeader(Nmsg,usrctr,fullname) {
1.76 ng 1575: var height = 70*Nmsg+250;
1.44 ng 1576: var scrollbar = "no";
1577: if (height > 600) {
1578: height = 600;
1579: scrollbar = "yes";
1580: }
1.118 ng 1581: var xpos = (screen.width-600)/2;
1582: xpos = (xpos < 0) ? '0' : xpos;
1583: var ypos = (screen.height-height)/2-30;
1584: ypos = (ypos < 0) ? '0' : ypos;
1585:
1.206 albertel 1586: pWin = window.open('', 'MessageCenter', 'resizable=yes,toolbar=no,location=no,scrollbars='+scrollbar+',screenx='+xpos+',screeny='+ypos+',width=600,height='+height);
1.76 ng 1587: pWin.focus();
1588: pDoc = pWin.document;
1.219 www 1589: pDoc.$docopen;
1.351 albertel 1590: pDoc.write('$start_page_msg_central');
1.76 ng 1591:
1592: pDoc.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
1593: pDoc.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
1.465 albertel 1594: pDoc.write("<h3><span class=\\"LC_info\\"> Compose Message for \"+fullname+\"<\\/span><\\/h3><br /><br />");
1.76 ng 1595:
1.564 bisitz 1596: pDoc.write('<table border="0" width="100%"><tr><td bgcolor="#777777">');
1597: pDoc.write('<table border="0" width="100%"><tr bgcolor="#DDFFFF">');
1.465 albertel 1598: pDoc.write("<td><b>Type<\\/b><\\/td><td><b>Include<\\/b><\\/td><td><b>Message<\\/td><\\/tr>");
1.44 ng 1599: }
1600: function displaySubject(msg,shwsel) {
1.76 ng 1601: pDoc = pWin.document;
1602: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.465 albertel 1603: pDoc.write("<td>Subject<\\/td>");
1604: pDoc.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1605: pDoc.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+"\\"size=\\"60\\" maxlength=\\"80\\"><\\/td><\\/tr>");
1.44 ng 1606: }
1607:
1.72 ng 1608: function displaySavedMsg(ctr,msg,shwsel) {
1.76 ng 1609: pDoc = pWin.document;
1610: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.465 albertel 1611: pDoc.write("<td align=\\"center\\">"+ctr+"<\\/td>");
1612: pDoc.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1613: pDoc.write("<td><textarea name=\\"msg"+ctr+"\\" cols=\\"60\\" rows=\\"3\\">"+msg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 1614: }
1615:
1616: function newMsg(newmsg,shwsel) {
1.76 ng 1617: pDoc = pWin.document;
1618: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.465 albertel 1619: pDoc.write("<td align=\\"center\\">New<\\/td>");
1620: pDoc.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1621: pDoc.write("<td><textarea name=\\"newmsg\\" cols=\\"60\\" rows=\\"3\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" >"+newmsg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 1622: }
1623:
1624: function msgTail() {
1.76 ng 1625: pDoc = pWin.document;
1.465 albertel 1626: pDoc.write("<\\/table>");
1627: pDoc.write("<\\/td><\\/tr><\\/table> ");
1.589 bisitz 1628: pDoc.write("<input type=\\"button\\" value=\\"Save\\" onclick=\\"javascript:checkInput()\\"> ");
1629: pDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onclick=\\"self.close()\\"><br /><br />");
1.465 albertel 1630: pDoc.write("<\\/form>");
1.351 albertel 1631: pDoc.write('$end_page_msg_central');
1.128 ng 1632: pDoc.close();
1.44 ng 1633: }
1634:
1635: //====================== Script for keyword highlight options ==============
1636: function kwhighlight() {
1637: var kwclr = document.SCORE.kwclr.value;
1638: var kwsize = document.SCORE.kwsize.value;
1639: var kwstyle = document.SCORE.kwstyle.value;
1640: var redsel = "";
1641: var grnsel = "";
1642: var blusel = "";
1643: if (kwclr=="red") {var redsel="checked"};
1644: if (kwclr=="green") {var grnsel="checked"};
1645: if (kwclr=="blue") {var blusel="checked"};
1646: var sznsel = "";
1647: var sz1sel = "";
1648: var sz2sel = "";
1649: if (kwsize=="0") {var sznsel="checked"};
1650: if (kwsize=="+1") {var sz1sel="checked"};
1651: if (kwsize=="+2") {var sz2sel="checked"};
1652: var synsel = "";
1653: var syisel = "";
1654: var sybsel = "";
1655: if (kwstyle=="") {var synsel="checked"};
1656: if (kwstyle=="<i>") {var syisel="checked"};
1657: if (kwstyle=="<b>") {var sybsel="checked"};
1658: highlightCentral();
1659: highlightbody('red','red',redsel,'0','normal',sznsel,'','normal',synsel);
1660: highlightbody('green','green',grnsel,'+1','+1',sz1sel,'<i>','italic',syisel);
1661: highlightbody('blue','blue',blusel,'+2','+2',sz2sel,'<b>','bold',sybsel);
1662: highlightend();
1663: return;
1664: }
1665:
1666: function highlightCentral() {
1.76 ng 1667: // if (window.hwdWin) window.hwdWin.close();
1.118 ng 1668: var xpos = (screen.width-400)/2;
1669: xpos = (xpos < 0) ? '0' : xpos;
1670: var ypos = (screen.height-330)/2-30;
1671: ypos = (ypos < 0) ? '0' : ypos;
1672:
1.206 albertel 1673: hwdWin = window.open('', 'KeywordHighlightCentral', 'resizeable=yes,toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx='+xpos+',screeny='+ypos);
1.76 ng 1674: hwdWin.focus();
1675: var hDoc = hwdWin.document;
1.219 www 1676: hDoc.$docopen;
1.351 albertel 1677: hDoc.write('$start_page_highlight_central');
1.76 ng 1678: hDoc.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
1.465 albertel 1679: hDoc.write("<h3><span class=\\"LC_info\\"> Keyword Highlight Options<\\/span><\\/h3><br /><br />");
1.76 ng 1680:
1.564 bisitz 1681: hDoc.write('<table border="0" width="100%"><tr><td bgcolor="#777777">');
1682: hDoc.write('<table border="0" width="100%"><tr bgcolor="#DDFFFF">');
1.465 albertel 1683: hDoc.write("<td><b>Text Color<\\/b><\\/td><td><b>Font Size<\\/b><\\/td><td><b>Font Style<\\/td><\\/tr>");
1.44 ng 1684: }
1685:
1686: function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) {
1.76 ng 1687: var hDoc = hwdWin.document;
1688: hDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1689: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1690: hDoc.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+"> "+clrtxt+"<\\/td>");
1.76 ng 1691: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1692: hDoc.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+"> "+sztxt+"<\\/td>");
1.76 ng 1693: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1694: hDoc.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+"> "+sytxt+"<\\/td>");
1695: hDoc.write("<\\/tr>");
1.44 ng 1696: }
1697:
1698: function highlightend() {
1.76 ng 1699: var hDoc = hwdWin.document;
1.465 albertel 1700: hDoc.write("<\\/table>");
1701: hDoc.write("<\\/td><\\/tr><\\/table> ");
1.589 bisitz 1702: hDoc.write("<input type=\\"button\\" value=\\"Save\\" onclick=\\"javascript:updateChoice(1)\\"> ");
1703: hDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onclick=\\"self.close()\\"><br /><br />");
1.465 albertel 1704: hDoc.write("<\\/form>");
1.351 albertel 1705: hDoc.write('$end_page_highlight_central');
1.128 ng 1706: hDoc.close();
1.44 ng 1707: }
1708:
1709: </script>
1710: SUBJAVASCRIPT
1711: }
1712:
1.349 albertel 1713: sub get_increment {
1.348 bowersj2 1714: my $increment = $env{'form.increment'};
1715: if ($increment != 1 && $increment != .5 && $increment != .25 &&
1716: $increment != .1) {
1717: $increment = 1;
1718: }
1719: return $increment;
1720: }
1721:
1.585 bisitz 1722: sub gradeBox_start {
1723: return (
1724: &Apache::loncommon::start_data_table()
1725: .&Apache::loncommon::start_data_table_header_row()
1726: .'<th>'.&mt('Part').'</th>'
1727: .'<th>'.&mt('Points').'</th>'
1728: .'<th> </th>'
1729: .'<th>'.&mt('Assign Grade').'</th>'
1730: .'<th>'.&mt('Weight').'</th>'
1731: .'<th>'.&mt('Grade Status').'</th>'
1732: .&Apache::loncommon::end_data_table_header_row()
1733: );
1734: }
1735:
1736: sub gradeBox_end {
1737: return (
1738: &Apache::loncommon::end_data_table()
1739: );
1740: }
1.71 ng 1741: #--- displays the grading box, used in essay type problem and grading by page/sequence
1742: sub gradeBox {
1.322 albertel 1743: my ($request,$symb,$uname,$udom,$counter,$partid,$record) = @_;
1.381 albertel 1744: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 1745: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 1746: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
1.466 albertel 1747: my $wgtmsg = ($wgt > 0) ? &mt('(problem weight)')
1748: : '<span class="LC_info">'.&mt('problem weight assigned by computer').'</span>';
1.71 ng 1749: $wgt = ($wgt > 0 ? $wgt : '1');
1750: my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
1.320 albertel 1751: '' : &compute_points($$record{'resource.'.$partid.'.awarded'},$wgt));
1.71 ng 1752: my $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />'."\n";
1.466 albertel 1753: my $display_part= &get_display_part($partid,$symb);
1.270 albertel 1754: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
1755: [$partid]);
1756: my $aggtries = $$record{'resource.'.$partid.'.tries'};
1.269 raeburn 1757: if ($last_resets{$partid}) {
1758: $aggtries = &get_num_tries($record,$last_resets{$partid},$partid);
1759: }
1.585 bisitz 1760: $result.=&Apache::loncommon::start_data_table_row();
1.71 ng 1761: my $ctr = 0;
1.348 bowersj2 1762: my $thisweight = 0;
1.349 albertel 1763: my $increment = &get_increment();
1.485 albertel 1764:
1765: my $radio.='<table border="0"><tr>'."\n"; # display radio buttons in a nice table 10 across
1.348 bowersj2 1766: while ($thisweight<=$wgt) {
1.532 bisitz 1767: $radio.= '<td><span class="LC_nobreak"><label><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
1.589 bisitz 1768: 'onclick="javascript:writeBox(this.form,\''.$counter.'_'.$partid.'\','.
1.348 bowersj2 1769: $thisweight.')" value="'.$thisweight.'" '.
1.401 albertel 1770: ($score eq $thisweight ? 'checked="checked"':'').' /> '.$thisweight."</label></span></td>\n";
1.485 albertel 1771: $radio.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1.348 bowersj2 1772: $thisweight += $increment;
1.71 ng 1773: $ctr++;
1774: }
1.485 albertel 1775: $radio.='</tr></table>';
1776:
1777: my $line.='<input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
1.71 ng 1778: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
1.589 bisitz 1779: 'onchange="javascript:updateRadio(this.form,\''.$counter.'_'.$partid.'\','.
1.71 ng 1780: $wgt.')" /></td>'."\n";
1.485 albertel 1781: $line.='<td>/'.$wgt.' '.$wgtmsg.
1.71 ng 1782: ($$record{'resource.'.$partid.'.solved'} eq 'correct_by_student' ? ' '.$checkIcon : '').
1.585 bisitz 1783: ' </td>'."\n";
1784: $line.='<td><select name="GD_SEL'.$counter.'_'.$partid.'" '.
1.589 bisitz 1785: 'onchange="javascript:clearRadBox(this.form,\''.$counter.'_'.$partid.'\')" >'."\n";
1.71 ng 1786: if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
1.485 albertel 1787: $line.='<option></option>'.
1788: '<option value="excused" selected="selected">'.&mt('excused').'</option>';
1.71 ng 1789: } else {
1.485 albertel 1790: $line.='<option selected="selected"></option>'.
1791: '<option value="excused" >'.&mt('excused').'</option>';
1.71 ng 1792: }
1.485 albertel 1793: $line.='<option value="reset status">'.&mt('reset status').'</option></select>'."\n";
1794:
1795:
1.540 riegler 1796: #&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 1797: $result .=
1.585 bisitz 1798: '<td>'.$display_part.'</td><td>'.$radio.'</td><td>'.&mt('or').'</td><td>'.$line.'</td>';
1799: $result.=&Apache::loncommon::end_data_table_row();
1.71 ng 1800: $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="" />'."\n".
1801: '<input type="hidden" name="oldpts'.$counter.'_'.$partid.'" value="'.$score.'" />'."\n".
1802: '<input type="hidden" name="solved'.$counter.'_'.$partid.'" value="'.
1.269 raeburn 1803: $$record{'resource.'.$partid.'.solved'}.'" />'."\n".
1804: '<input type="hidden" name="totaltries'.$counter.'_'.$partid.'" value="'.
1805: $$record{'resource.'.$partid.'.tries'}.'" />'."\n".
1806: '<input type="hidden" name="aggtries'.$counter.'_'.$partid.'" value="'.
1807: $aggtries.'" />'."\n";
1.582 raeburn 1808: my $res_error;
1809: $result.=&handback_box($symb,$uname,$udom,$counter,$partid,$record,\$res_error);
1810: if ($res_error) {
1811: return &navmap_errormsg();
1812: }
1.318 banghart 1813: return $result;
1814: }
1.322 albertel 1815:
1816: sub handback_box {
1.582 raeburn 1817: my ($symb,$uname,$udom,$counter,$partid,$record,$res_error) = @_;
1818: my ($partlist,$handgrade,$responseType) = &response_type($symb,$res_error);
1.323 banghart 1819: my (@respids);
1.375 albertel 1820: my @part_response_id = &flatten_responseType($responseType);
1821: foreach my $part_response_id (@part_response_id) {
1822: my ($part,$resp) = @{ $part_response_id };
1.323 banghart 1823: if ($part eq $partid) {
1.375 albertel 1824: push(@respids,$resp);
1.323 banghart 1825: }
1826: }
1.318 banghart 1827: my $result;
1.323 banghart 1828: foreach my $respid (@respids) {
1.322 albertel 1829: my $prefix = $counter.'_'.$partid.'_'.$respid.'_';
1830: my $files=&get_submitted_files($udom,$uname,$partid,$respid,$record);
1831: next if (!@$files);
1832: my $file_counter = 1;
1.313 banghart 1833: foreach my $file (@$files) {
1.368 banghart 1834: if ($file =~ /\/portfolio\//) {
1835: my ($file_path, $file_disp) = ($file =~ m|(.+/)(.+)$|);
1836: my ($name,$version,$ext) = &file_name_version_ext($file_disp);
1837: $file_disp = "$name.$ext";
1838: $file = $file_path.$file_disp;
1839: $result.=&mt('Return commented version of [_1] to student.',
1840: '<span class="LC_filename">'.$file_disp.'</span>');
1841: $result.='<input type="file" name="'.$prefix.'returndoc'.$file_counter.'" />'."\n";
1842: $result.='<input type="hidden" name="'.$prefix.'origdoc'.$file_counter.'" value="'.$file.'" /><br />';
1.485 albertel 1843: $result.='('.&mt('File will be uploaded when you click on Save & Next below.').')<br />';
1.368 banghart 1844: $file_counter++;
1845: }
1.322 albertel 1846: }
1.313 banghart 1847: }
1.318 banghart 1848: return $result;
1.71 ng 1849: }
1.44 ng 1850:
1.58 albertel 1851: sub show_problem {
1.382 albertel 1852: my ($request,$symb,$uname,$udom,$removeform,$viewon,$mode,$form) = @_;
1.144 albertel 1853: my $rendered;
1.382 albertel 1854: my %form = ((ref($form) eq 'HASH')? %{$form} : ());
1.329 albertel 1855: &Apache::lonxml::remember_problem_counter();
1.144 albertel 1856: if ($mode eq 'both' or $mode eq 'text') {
1857: $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
1.382 albertel 1858: $env{'request.course.id'},
1859: undef,\%form);
1.144 albertel 1860: }
1.58 albertel 1861: if ($removeform) {
1862: $rendered=~s|<form(.*?)>||g;
1863: $rendered=~s|</form>||g;
1.374 albertel 1864: $rendered=~s|(<input[^>]*name\s*=\s*"?)(\w+)("?)|$1would_have_been_$2$3|g;
1.58 albertel 1865: }
1.144 albertel 1866: my $companswer;
1867: if ($mode eq 'both' or $mode eq 'answer') {
1.329 albertel 1868: &Apache::lonxml::restore_problem_counter();
1.382 albertel 1869: $companswer=
1870: &Apache::loncommon::get_student_answers($symb,$uname,$udom,
1871: $env{'request.course.id'},
1872: %form);
1.144 albertel 1873: }
1.58 albertel 1874: if ($removeform) {
1875: $companswer=~s|<form(.*?)>||g;
1876: $companswer=~s|</form>||g;
1.144 albertel 1877: $companswer=~s|name="submit"|name="would_have_been_submit"|g;
1.58 albertel 1878: }
1.468 albertel 1879: $rendered=
1.588 bisitz 1880: '<div class="LC_Box">'
1881: .'<h3 class="LC_hcell">'.&mt('View of the problem').'</h3>'
1882: .$rendered
1883: .'</div>';
1.468 albertel 1884: $companswer=
1.588 bisitz 1885: '<div class="LC_Box">'
1886: .'<h3 class="LC_hcell">'.&mt('Correct answer').'</h3>'
1887: .$companswer
1888: .'</div>';
1.468 albertel 1889: my $result;
1.144 albertel 1890: if ($mode eq 'both') {
1.588 bisitz 1891: $result=$rendered.$companswer;
1.144 albertel 1892: } elsif ($mode eq 'text') {
1.588 bisitz 1893: $result=$rendered;
1.144 albertel 1894: } elsif ($mode eq 'answer') {
1.588 bisitz 1895: $result=$companswer;
1.144 albertel 1896: }
1.71 ng 1897: return $result;
1.58 albertel 1898: }
1.397 albertel 1899:
1.396 banghart 1900: sub files_exist {
1901: my ($r, $symb) = @_;
1902: my @students = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.397 albertel 1903:
1.396 banghart 1904: foreach my $student (@students) {
1905: my ($uname,$udom,$fullname) = split(/:/,$student);
1.397 albertel 1906: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1907: $udom,$uname);
1.396 banghart 1908: my ($string,$timestamp)= &get_last_submission(\%record);
1.397 albertel 1909: foreach my $submission (@$string) {
1910: my ($partid,$respid) =
1911: ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
1912: my $files=&get_submitted_files($udom,$uname,$partid,$respid,
1913: \%record);
1914: return 1 if (@$files);
1.396 banghart 1915: }
1916: }
1.397 albertel 1917: return 0;
1.396 banghart 1918: }
1.397 albertel 1919:
1.394 banghart 1920: sub download_all_link {
1921: my ($r,$symb) = @_;
1.395 albertel 1922: my $all_students =
1923: join("\n", &Apache::loncommon::get_env_multiple('form.stuinfo'));
1924:
1925: my $parts =
1926: join("\n",&Apache::loncommon::get_env_multiple('form.vPart'));
1927:
1.394 banghart 1928: my $identifier = &Apache::loncommon::get_cgi_id();
1.514 raeburn 1929: &Apache::lonnet::appenv({'cgi.'.$identifier.'.students' => $all_students,
1930: 'cgi.'.$identifier.'.symb' => $symb,
1931: 'cgi.'.$identifier.'.parts' => $parts,});
1.395 albertel 1932: $r->print('<a href="/cgi-bin/multidownload.pl?'.$identifier.'">'.
1933: &mt('Download All Submitted Documents').'</a>');
1.394 banghart 1934: return
1935: }
1.395 albertel 1936:
1.432 banghart 1937: sub build_section_inputs {
1938: my $section_inputs;
1939: if ($env{'form.section'} eq '') {
1940: $section_inputs .= '<input type="hidden" name="section" value="all" />'."\n";
1941: } else {
1942: my @sections = &Apache::loncommon::get_env_multiple('form.section');
1.434 albertel 1943: foreach my $section (@sections) {
1.432 banghart 1944: $section_inputs .= '<input type="hidden" name="section" value="'.$section.'" />'."\n";
1945: }
1946: }
1947: return $section_inputs;
1948: }
1949:
1.44 ng 1950: # --------------------------- show submissions of a student, option to grade
1951: sub submission {
1952: my ($request,$counter,$total) = @_;
1.257 albertel 1953: my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
1954: $udom = ($udom eq '' ? $env{'user.domain'} : $udom); #has form.userdom changed for a student?
1955: my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
1956: $env{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $env{'form.fullname'} eq '';
1.324 albertel 1957: my $symb = &get_symb($request);
1958: if ($symb eq '') { $request->print("Unable to handle ambiguous references:."); return ''; }
1.104 albertel 1959:
1960: if (!&canview($usec)) {
1.398 albertel 1961: $request->print('<span class="LC_warning">Unable to view requested student.('.
1962: $uname.':'.$udom.' in section '.$usec.' in course id '.
1963: $env{'request.course.id'}.')</span>');
1.324 albertel 1964: $request->print(&show_grading_menu_form($symb));
1.104 albertel 1965: return;
1966: }
1967:
1.257 albertel 1968: if (!$env{'form.lastSub'}) { $env{'form.lastSub'} = 'datesub'; }
1969: if (!$env{'form.vProb'}) { $env{'form.vProb'} = 'yes'; }
1970: if (!$env{'form.vAns'}) { $env{'form.vAns'} = 'yes'; }
1971: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.381 albertel 1972: my $checkIcon = '<img alt="'.&mt('Check Mark').
1973: '" src="'.$request->dir_config('lonIconsURL').
1.122 ng 1974: '/check.gif" height="16" border="0" />';
1.41 ng 1975:
1.426 albertel 1976: my %old_essays;
1.41 ng 1977: # header info
1978: if ($counter == 0) {
1979: &sub_page_js($request);
1.257 albertel 1980: &sub_page_kw_js($request) if ($env{'form.handgrade'} eq 'yes');
1981: $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
1982: &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
1.397 albertel 1983: if ($env{'form.handgrade'} eq 'yes' && &files_exist($request, $symb)) {
1.396 banghart 1984: &download_all_link($request, $symb);
1985: }
1.485 albertel 1986: $request->print('<h3> <span class="LC_info">'.&mt('Submission Record').'</span></h3>'."\n".
1987: '<h4> '.&mt('<b>Resource: </b> [_1]',$env{'form.probTitle'}).'</h4>'."\n");
1.118 ng 1988:
1.44 ng 1989: # option to display problem, only once else it cause problems
1990: # with the form later since the problem has a form.
1.257 albertel 1991: if ($env{'form.vProb'} eq 'yes' or $env{'form.vAns'} eq 'yes') {
1.144 albertel 1992: my $mode;
1.257 albertel 1993: if ($env{'form.vProb'} eq 'yes' && $env{'form.vAns'} eq 'yes') {
1.144 albertel 1994: $mode='both';
1.257 albertel 1995: } elsif ($env{'form.vProb'} eq 'yes') {
1.144 albertel 1996: $mode='text';
1.257 albertel 1997: } elsif ($env{'form.vAns'} eq 'yes') {
1.144 albertel 1998: $mode='answer';
1999: }
1.329 albertel 2000: &Apache::lonxml::clear_problem_counter();
1.144 albertel 2001: $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
1.41 ng 2002: }
1.441 www 2003:
1.44 ng 2004: # kwclr is the only variable that is guaranteed to be non blank
2005: # if this subroutine has been called once.
1.41 ng 2006: my %keyhash = ();
1.257 albertel 2007: if ($env{'form.kwclr'} eq '' && $env{'form.handgrade'} eq 'yes') {
1.41 ng 2008: %keyhash = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 2009: $env{'course.'.$env{'request.course.id'}.'.domain'},
2010: $env{'course.'.$env{'request.course.id'}.'.num'});
1.41 ng 2011:
1.257 albertel 2012: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
2013: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
2014: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
2015: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
2016: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
2017: $env{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
2018: $keyhash{$symb.'_subject'} : $env{'form.probTitle'};
2019: $env{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1.41 ng 2020: }
1.257 albertel 2021: my $overRideScore = $env{'form.overRideScore'} eq '' ? 'no' : $env{'form.overRideScore'};
1.442 banghart 2022: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.303 banghart 2023: $request->print('<form action="/adm/grades" method="post" name="SCORE" enctype="multipart/form-data">'."\n".
1.41 ng 2024: '<input type="hidden" name="command" value="handgrade" />'."\n".
1.257 albertel 2025: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.442 banghart 2026: '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.120 ng 2027: '<input type="hidden" name="overRideScore" value="'.$overRideScore.'" />'."\n".
1.257 albertel 2028: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.41 ng 2029: '<input type="hidden" name="refresh" value="off" />'."\n".
1.120 ng 2030: '<input type="hidden" name="studentNo" value="" />'."\n".
2031: '<input type="hidden" name="gradeOpt" value="" />'."\n".
1.418 albertel 2032: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 2033: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" />'."\n".
2034: '<input type="hidden" name="vProb" value="'.$env{'form.vProb'}.'" />'."\n".
2035: '<input type="hidden" name="vAns" value="'.$env{'form.vAns'}.'" />'."\n".
2036: '<input type="hidden" name="lastSub" value="'.$env{'form.lastSub'}.'" />'."\n".
1.432 banghart 2037: &build_section_inputs().
1.326 albertel 2038: '<input type="hidden" name="submitonly" value="'.$env{'form.submitonly'}.'" />'."\n".
2039: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" />'."\n".
1.41 ng 2040: '<input type="hidden" name="NCT"'.
1.257 albertel 2041: ' value="'.($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : $total+1).'" />'."\n");
2042: if ($env{'form.handgrade'} eq 'yes') {
2043: $request->print('<input type="hidden" name="keywords" value="'.$env{'form.keywords'}.'" />'."\n".
2044: '<input type="hidden" name="kwclr" value="'.$env{'form.kwclr'}.'" />'."\n".
2045: '<input type="hidden" name="kwsize" value="'.$env{'form.kwsize'}.'" />'."\n".
2046: '<input type="hidden" name="kwstyle" value="'.$env{'form.kwstyle'}.'" />'."\n".
2047: '<input type="hidden" name="msgsub" value="'.$env{'form.msgsub'}.'" />'."\n".
1.123 ng 2048: '<input type="hidden" name="shownSub" value="0" />'."\n".
1.257 albertel 2049: '<input type="hidden" name="savemsgN" value="'.$env{'form.savemsgN'}.'" />'."\n");
1.154 albertel 2050: foreach my $partid (&Apache::loncommon::get_env_multiple('form.vPart')) {
2051: $request->print('<input type="hidden" name="vPart" value="'.$partid.'" />'."\n");
2052: }
1.123 ng 2053: }
1.41 ng 2054:
2055: my ($cts,$prnmsg) = (1,'');
1.257 albertel 2056: while ($cts <= $env{'form.savemsgN'}) {
1.41 ng 2057: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
1.123 ng 2058: (!exists($keyhash{$symb.'_savemsg'.$cts}) ?
1.257 albertel 2059: &Apache::lonfeedback::clear_out_html($env{'form.savemsg'.$cts}) :
1.80 ng 2060: &Apache::lonfeedback::clear_out_html($keyhash{$symb.'_savemsg'.$cts})).
1.123 ng 2061: '" />'."\n".
2062: '<input type="hidden" name="shownOnce'.$cts.'" value="0" />'."\n";
1.41 ng 2063: $cts++;
2064: }
2065: $request->print($prnmsg);
1.32 ng 2066:
1.257 albertel 2067: if ($env{'form.handgrade'} eq 'yes' && $env{'form.showgrading'} eq 'yes') {
1.88 www 2068: #
2069: # Print out the keyword options line
2070: #
1.41 ng 2071: $request->print(<<KEYWORDS);
1.38 ng 2072: <b>Keyword Options:</b>
1.417 albertel 2073: <a href="javascript:keywords(document.SCORE);" target="_self">List</a>
1.589 bisitz 2074: <a href="#" onmousedown="javascript:getSel(); return false"
1.38 ng 2075: CLASS="page">Paste Selection to List</a>
1.417 albertel 2076: <a href="javascript:kwhighlight();" target="_self">Highlight Attribute</a><br /><br />
1.38 ng 2077: KEYWORDS
1.88 www 2078: #
2079: # Load the other essays for similarity check
2080: #
1.324 albertel 2081: my (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb);
1.384 albertel 2082: my ($adom,$aname,$apath)=($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
1.359 www 2083: $apath=&escape($apath);
1.88 www 2084: $apath=~s/\W/\_/gs;
1.426 albertel 2085: %old_essays=&Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
1.41 ng 2086: }
2087: }
1.44 ng 2088:
1.441 www 2089: # This is where output for one specific student would start
1.592 ! bisitz 2090: my $add_class = ($counter%2) ? ' LC_grade_show_user_odd_row' : '';
! 2091: $request->print(
! 2092: "\n\n"
! 2093: .'<div class="LC_grade_show_user'.$add_class.'">'
! 2094: .'<h2>'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).'</h2>'
! 2095: ."\n"
! 2096: );
1.441 www 2097:
1.592 ! bisitz 2098: # Show additional functions if allowed
! 2099: if ($perm{'vgr'}) {
! 2100: $request->print(
! 2101: &Apache::loncommon::track_student_link(
! 2102: &mt('View recent activity'),
! 2103: $uname,$udom,'check')
! 2104: .' '
! 2105: );
! 2106: }
! 2107: if ($perm{'opa'}) {
! 2108: $request->print(
! 2109: &Apache::loncommon::pprmlink(
! 2110: &mt('Set/Change parameters'),
! 2111: $uname,$udom,$symb,'check'));
! 2112: }
! 2113:
! 2114: # Show Problem
1.257 albertel 2115: if ($env{'form.vProb'} eq 'all' or $env{'form.vAns'} eq 'all') {
1.144 albertel 2116: my $mode;
1.257 albertel 2117: if ($env{'form.vProb'} eq 'all' && $env{'form.vAns'} eq 'all') {
1.144 albertel 2118: $mode='both';
1.257 albertel 2119: } elsif ($env{'form.vProb'} eq 'all' ) {
1.144 albertel 2120: $mode='text';
1.257 albertel 2121: } elsif ($env{'form.vAns'} eq 'all') {
1.144 albertel 2122: $mode='answer';
2123: }
1.329 albertel 2124: &Apache::lonxml::clear_problem_counter();
1.475 albertel 2125: $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode,{'request.prefix' => 'ctr'.$counter}));
1.58 albertel 2126: }
1.144 albertel 2127:
1.257 albertel 2128: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.582 raeburn 2129: my $res_error;
2130: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
2131: if ($res_error) {
2132: $request->print(&navmap_errormsg());
2133: return;
2134: }
1.41 ng 2135:
1.44 ng 2136: # Display student info
1.41 ng 2137: $request->print(($counter == 0 ? '' : '<br />'));
1.590 bisitz 2138:
2139: my $result='<div class="LC_Box">'
2140: .'<h3 class="LC_hcell">'.&mt('Submissions').'</h3>';
1.45 ng 2141: $result.='<input type="hidden" name="name'.$counter.
1.588 bisitz 2142: '" value="'.$env{'form.fullname'}.'" />'."\n";
1.469 albertel 2143: if ($env{'form.handgrade'} eq 'no') {
1.588 bisitz 2144: $result.='<p class="LC_info">'
2145: .&mt('Part(s) graded correct by the computer is marked with a [_1] symbol.',$checkIcon)
2146: ."</p>\n";
1.469 albertel 2147: }
2148:
1.118 ng 2149: # If any part of the problem is an essay-response (handgraded), then check for collaborators
1.464 albertel 2150: my $fullname;
2151: my $col_fullnames = [];
1.257 albertel 2152: if ($env{'form.handgrade'} eq 'yes') {
1.464 albertel 2153: (my $sub_result,$fullname,$col_fullnames)=
2154: &check_collaborators($symb,$uname,$udom,\%record,$handgrade,
2155: $counter);
2156: $result.=$sub_result;
1.41 ng 2157: }
1.44 ng 2158: $request->print($result."\n");
1.588 bisitz 2159:
1.44 ng 2160: # print student answer/submission
1.588 bisitz 2161: # Options are (1) Handgraded submission only
1.44 ng 2162: # (2) Last submission, includes submission that is not handgraded
2163: # (for multi-response type part)
2164: # (3) Last submission plus the parts info
2165: # (4) The whole record for this student
1.257 albertel 2166: if ($env{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
1.151 albertel 2167: my ($string,$timestamp)= &get_last_submission(\%record);
1.468 albertel 2168:
2169: my $lastsubonly;
2170:
1.588 bisitz 2171: if ($$timestamp eq '') {
2172: $lastsubonly.='<div class="LC_grade_submissions_body">'.$$string[0].'</div>';
2173: } else {
1.592 ! bisitz 2174: $lastsubonly =
! 2175: '<div class="LC_grade_submissions_body">'
! 2176: .'<b>'.&mt('Date Submitted:').'</b> '.$$timestamp."\n";
1.468 albertel 2177:
1.151 albertel 2178: my %seenparts;
1.375 albertel 2179: my @part_response_id = &flatten_responseType($responseType);
2180: foreach my $part (@part_response_id) {
1.393 albertel 2181: next if ($env{'form.lastSub'} eq 'hdgrade'
2182: && $$handgrade{$$part[0].'_'.$$part[1]} ne 'yes');
2183:
1.375 albertel 2184: my ($partid,$respid) = @{ $part };
1.324 albertel 2185: my $display_part=&get_display_part($partid,$symb);
1.257 albertel 2186: if ($env{"form.$uname:$udom:$partid:submitted_by"}) {
1.151 albertel 2187: if (exists($seenparts{$partid})) { next; }
2188: $seenparts{$partid}=1;
1.207 albertel 2189: my $submitby='<b>Part:</b> '.$display_part.
2190: ' <b>Collaborative submission by:</b> '.
1.151 albertel 2191: '<a href="javascript:viewSubmitter(\''.
1.257 albertel 2192: $env{"form.$uname:$udom:$partid:submitted_by"}.
1.417 albertel 2193: '\');" target="_self">'.
1.257 albertel 2194: $$fullname{$env{"form.$uname:$udom:$partid:submitted_by"}}.'</a><br />';
1.151 albertel 2195: $request->print($submitby);
2196: next;
2197: }
2198: my $responsetype = $responseType->{$partid}->{$respid};
2199: if (!exists($record{"resource.$partid.$respid.submission"})) {
1.577 bisitz 2200: $lastsubonly.="\n".'<div class="LC_grade_submission_part">'.
2201: '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
2202: ' <span class="LC_internal_info">'.
2203: '('.&mt('Part ID: [_1]',$respid).')</b>'.
2204: '</span> '.
1.539 riegler 2205: '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br /><br /></div>';
1.151 albertel 2206: next;
2207: }
1.468 albertel 2208: foreach my $submission (@$string) {
2209: my ($partid,$respid) = ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
1.375 albertel 2210: if (join('_',@{$part}) ne ($partid.'_'.$respid)) { next; }
1.468 albertel 2211: my ($ressub,$subval) = split(/:/,$submission,2);
1.151 albertel 2212: # Similarity check
2213: my $similar='';
1.257 albertel 2214: if($env{'form.checkPlag'}){
1.151 albertel 2215: my ($oname,$odom,$ocrsid,$oessay,$osim)=
1.426 albertel 2216: &most_similar($uname,$udom,$subval,\%old_essays);
1.151 albertel 2217: if ($osim) {
2218: $osim=int($osim*100.0);
1.426 albertel 2219: my %old_course_desc =
2220: &Apache::lonnet::coursedescription($ocrsid,
2221: {'one_time' => 1});
2222:
2223: $similar="<hr /><h3><span class=\"LC_warning\">".
1.574 bisitz 2224: &mt('Essay is [_1]% similar to an essay by [_2] in course [_3] (course id [_4]:[_5])',
1.426 albertel 2225: $osim,
1.574 bisitz 2226: &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')',
1.426 albertel 2227: $old_course_desc{'description'},
1.427 albertel 2228: $old_course_desc{'num'},
1.426 albertel 2229: $old_course_desc{'domain'}).
1.398 albertel 2230: '</span></h3><blockquote><i>'.
1.151 albertel 2231: &keywords_highlight($oessay).
2232: '</i></blockquote><hr />';
2233: }
1.150 albertel 2234: }
1.151 albertel 2235: my $order=&get_order($partid,$respid,$symb,$uname,$udom);
1.257 albertel 2236: if ($env{'form.lastSub'} eq 'lastonly' ||
2237: ($env{'form.lastSub'} eq 'hdgrade' &&
1.377 albertel 2238: $$handgrade{$$part[0].'_'.$$part[1]} eq 'yes')) {
1.324 albertel 2239: my $display_part=&get_display_part($partid,$symb);
1.577 bisitz 2240: $lastsubonly.='<div class="LC_grade_submission_part">'.
2241: '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
2242: ' <span class="LC_internal_info">'.
2243: '('.&mt('Part ID: [_1]',$respid).')'.
2244: '</b></span> ';
1.313 banghart 2245: my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record);
2246: if (@$files) {
1.544 raeburn 2247: $lastsubonly.='<br /><span class="LC_warning">'.&mt('Like all files provided by users, this file may contain viruses').'</span><br />';
1.303 banghart 2248: my $file_counter = 0;
1.313 banghart 2249: foreach my $file (@$files) {
1.468 albertel 2250: $file_counter++;
1.232 albertel 2251: &Apache::lonnet::allowuploaded('/adm/grades',$file);
1.564 bisitz 2252: $lastsubonly.='<br /><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.&Apache::loncommon::icon($file).'" border="0" /> '.$file.'</a>';
1.232 albertel 2253: }
1.236 albertel 2254: $lastsubonly.='<br />';
1.41 ng 2255: }
1.468 albertel 2256: $lastsubonly.='<b>'.&mt('Submitted Answer:').' </b>'.
1.151 albertel 2257: &cleanRecord($subval,$responsetype,$symb,$partid,
1.555 raeburn 2258: $respid,\%record,$order,undef,$uname,$udom);
1.151 albertel 2259: if ($similar) {$lastsubonly.="<br /><br />$similar\n";}
1.468 albertel 2260: $lastsubonly.='</div>';
1.41 ng 2261: }
2262: }
2263: }
1.588 bisitz 2264: $lastsubonly.='</div>'."\n"; # End: LC_grade_submissions_body
1.151 albertel 2265: }
2266: $request->print($lastsubonly);
1.468 albertel 2267: } elsif ($env{'form.lastSub'} eq 'datesub') {
1.324 albertel 2268: my (undef,$responseType,undef,$parts) = &showResourceInfo($symb);
1.148 albertel 2269: $request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
1.257 albertel 2270: } elsif ($env{'form.lastSub'} =~ /^(last|all)$/) {
1.41 ng 2271: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
1.257 albertel 2272: $env{'request.course.id'},
1.44 ng 2273: $last,'.submission',
2274: 'Apache::grades::keywords_highlight'));
1.41 ng 2275: }
1.120 ng 2276:
1.121 ng 2277: $request->print('<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
2278: .$udom.'" />'."\n");
1.44 ng 2279: # return if view submission with no grading option
1.257 albertel 2280: if ($env{'form.showgrading'} eq '' || (!&canmodify($usec))) {
1.120 ng 2281: my $toGrade.='<input type="button" value="Grade Student" '.
1.589 bisitz 2282: 'onclick="javascript:checksubmit(this.form,\'Grade Student\',\''
1.417 albertel 2283: .$counter.'\');" target="_self" /> '."\n" if (&canmodify($usec));
1.468 albertel 2284: $toGrade.='</div>'."\n";
1.257 albertel 2285: if (($env{'form.command'} eq 'submission') ||
2286: ($env{'form.command'} eq 'processGroup' && $counter == $total)) {
1.324 albertel 2287: $toGrade.='</form>'.&show_grading_menu_form($symb);
1.169 albertel 2288: }
1.180 albertel 2289: $request->print($toGrade);
1.41 ng 2290: return;
1.180 albertel 2291: } else {
1.468 albertel 2292: $request->print('</div>'."\n");
1.41 ng 2293: }
1.33 ng 2294:
1.121 ng 2295: # essay grading message center
1.257 albertel 2296: if ($env{'form.handgrade'} eq 'yes') {
1.468 albertel 2297: my $result='<div class="LC_grade_message_center">';
2298:
2299: $result.='<div class="LC_grade_message_center_header">'.
2300: &mt('Send Message').'</div><div class="LC_grade_message_center_body">';
1.257 albertel 2301: my ($lastname,$givenn) = split(/,/,$env{'form.fullname'});
1.118 ng 2302: my $msgfor = $givenn.' '.$lastname;
1.464 albertel 2303: if (scalar(@$col_fullnames) > 0) {
2304: my $lastone = pop(@$col_fullnames);
2305: $msgfor .= ', '.(join ', ',@$col_fullnames).' and '.$lastone.'.';
1.118 ng 2306: }
2307: $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
1.468 albertel 2308: $result.='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
1.121 ng 2309: '<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n";
2310: $result.=' <a href="javascript:msgCenter(document.SCORE,'.$counter.
1.417 albertel 2311: ',\''.$msgfor.'\');" target="_self">'.
1.464 albertel 2312: &mt('Compose message to student').(scalar(@$col_fullnames) >= 1 ? 's' : '').'</a><label> ('.
1.350 albertel 2313: &mt('incl. grades').' <input type="checkbox" name="withgrades'.$counter.'" /></label>)'.
1.118 ng 2314: '<img src="'.$request->dir_config('lonIconsURL').
2315: '/mailbkgrd.gif" width="14" height="10" name="mailicon'.$counter.'" />'."\n".
1.298 www 2316: '<br /> ('.
1.468 albertel 2317: &mt('Message will be sent when you click on Save & Next below.').")\n";
2318: $result.='</div></div>';
1.121 ng 2319: $request->print($result);
1.118 ng 2320: }
1.41 ng 2321:
2322: my %seen = ();
2323: my @partlist;
1.129 ng 2324: my @gradePartRespid;
1.375 albertel 2325: my @part_response_id = &flatten_responseType($responseType);
1.585 bisitz 2326: $request->print(
1.588 bisitz 2327: '<div class="LC_Box">'
2328: .'<h3 class="LC_hcell">'.&mt('Assign Grades').'</h3>'
1.585 bisitz 2329: );
1.592 ! bisitz 2330: $request->print(&gradeBox_start());
1.375 albertel 2331: foreach my $part_response_id (@part_response_id) {
2332: my ($partid,$respid) = @{ $part_response_id };
2333: my $part_resp = join('_',@{ $part_response_id });
1.322 albertel 2334: next if ($seen{$partid} > 0);
1.41 ng 2335: $seen{$partid}++;
1.393 albertel 2336: next if ($$handgrade{$part_resp} ne 'yes'
2337: && $env{'form.lastSub'} eq 'hdgrade');
1.524 raeburn 2338: push(@partlist,$partid);
2339: push(@gradePartRespid,$partid.'.'.$respid);
1.322 albertel 2340: $request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
1.41 ng 2341: }
1.585 bisitz 2342: $request->print(&gradeBox_end()); # </div>
2343: $request->print('</div>');
1.468 albertel 2344:
2345: $request->print('<div class="LC_grade_info_links">');
2346: $request->print('</div>');
2347:
1.45 ng 2348: $result='<input type="hidden" name="partlist'.$counter.
2349: '" value="'.(join ":",@partlist).'" />'."\n";
1.129 ng 2350: $result.='<input type="hidden" name="gradePartRespid'.
2351: '" value="'.(join ":",@gradePartRespid).'" />'."\n" if ($counter == 0);
1.45 ng 2352: my $ctr = 0;
2353: while ($ctr < scalar(@partlist)) {
2354: $result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
2355: $partlist[$ctr].'" />'."\n";
2356: $ctr++;
2357: }
1.468 albertel 2358: $request->print($result.''."\n");
1.41 ng 2359:
1.441 www 2360: # Done with printing info for one student
2361:
1.468 albertel 2362: $request->print('</div>');#LC_grade_show_user
1.441 www 2363:
2364:
1.41 ng 2365: # print end of form
2366: if ($counter == $total) {
1.592 ! bisitz 2367: my $endform='<br /><hr /><table border="0"><tr><td>'."\n";
1.485 albertel 2368: $endform.='<input type="button" value="'.&mt('Save & Next').'" '.
1.589 bisitz 2369: 'onclick="javascript:checksubmit(this.form,\'Save & Next\','.
1.417 albertel 2370: $total.','.scalar(@partlist).');" target="_self" /> '."\n";
1.119 ng 2371: my $ntstu ='<select name="NTSTU">'.
2372: '<option>1</option><option>2</option>'.
2373: '<option>3</option><option>5</option>'.
2374: '<option>7</option><option>10</option></select>'."\n";
1.257 albertel 2375: my $nsel = ($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : '1');
1.401 albertel 2376: $ntstu =~ s/<option>$nsel</<option selected="selected">$nsel</;
1.578 raeburn 2377: $endform.=&mt('[_1]student(s)',$ntstu);
1.485 albertel 2378: $endform.=' <input type="button" value="'.&mt('Previous').'" '.
1.589 bisitz 2379: 'onclick="javascript:checksubmit(this.form,\'Previous\');" target="_self" /> '."\n".
1.485 albertel 2380: '<input type="button" value="'.&mt('Next').'" '.
1.589 bisitz 2381: 'onclick="javascript:checksubmit(this.form,\'Next\');" target="_self" /> ';
1.592 ! bisitz 2382: $endform.='<span class="LC_warning">'.
! 2383: &mt('(Next and Previous (student) do not save the scores.)').
! 2384: '</span>'."\n" ;
1.349 albertel 2385: $endform.="<input type='hidden' value='".&get_increment().
1.348 bowersj2 2386: "' name='increment' />";
1.485 albertel 2387: $endform.='</td></tr></table></form>';
1.324 albertel 2388: $endform.=&show_grading_menu_form($symb);
1.41 ng 2389: $request->print($endform);
2390: }
2391: return '';
1.38 ng 2392: }
2393:
1.464 albertel 2394: sub check_collaborators {
2395: my ($symb,$uname,$udom,$record,$handgrade,$counter) = @_;
2396: my ($result,@col_fullnames);
2397: my ($classlist,undef,$fullname) = &getclasslist('all','0');
2398: foreach my $part (keys(%$handgrade)) {
2399: my $ncol = &Apache::lonnet::EXT('resource.'.$part.
2400: '.maxcollaborators',
2401: $symb,$udom,$uname);
2402: next if ($ncol <= 0);
2403: $part =~ s/\_/\./g;
2404: next if ($record->{'resource.'.$part.'.collaborators'} eq '');
2405: my (@good_collaborators, @bad_collaborators);
2406: foreach my $possible_collaborator
2407: (split(/,?\s+/,$record->{'resource.'.$part.'.collaborators'})) {
2408: $possible_collaborator =~ s/[\$\^\(\)]//g;
2409: next if ($possible_collaborator eq '');
2410: my ($co_name,$co_dom) = split(/\@|:/,$possible_collaborator);
2411: $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
2412: next if ($co_name eq $uname && $co_dom eq $udom);
2413: # Doing this grep allows 'fuzzy' specification
2414: my @matches = grep(/^\Q$co_name\E:\Q$co_dom\E$/i,
2415: keys(%$classlist));
2416: if (! scalar(@matches)) {
2417: push(@bad_collaborators, $possible_collaborator);
2418: } else {
2419: push(@good_collaborators, @matches);
2420: }
2421: }
2422: if (scalar(@good_collaborators) != 0) {
1.466 albertel 2423: $result.='<br />'.&mt('Collaborators: ');
1.464 albertel 2424: foreach my $name (@good_collaborators) {
2425: my ($lastname,$givenn) = split(/,/,$$fullname{$name});
2426: push(@col_fullnames, $givenn.' '.$lastname);
2427: $result.=$fullname->{$name}.' ';
2428: }
2429: $result.='<br />'."\n";
1.466 albertel 2430: my ($part)=split(/\./,$part);
1.464 albertel 2431: $result.='<input type="hidden" name="collaborator'.$counter.
2432: '" value="'.$part.':'.(join ':',@good_collaborators).'" />'.
2433: "\n";
2434: }
2435: if (scalar(@bad_collaborators) > 0) {
1.466 albertel 2436: $result.='<div class="LC_warning">';
1.464 albertel 2437: $result.=&mt('This student has submitted [quant,_1,invalid collaborator]: [_2]',scalar(@bad_collaborators),join(', ',@bad_collaborators));
2438: $result .= '</div>';
2439: }
2440: if (scalar(@bad_collaborators > $ncol)) {
1.466 albertel 2441: $result .= '<div class="LC_warning">';
1.464 albertel 2442: $result .= &mt('This student has submitted too many '.
2443: 'collaborators. Maximum is [_1].',$ncol);
2444: $result .= '</div>';
2445: }
2446: }
2447: return ($result,$fullname,\@col_fullnames);
2448: }
2449:
1.44 ng 2450: #--- Retrieve the last submission for all the parts
1.38 ng 2451: sub get_last_submission {
1.119 ng 2452: my ($returnhash)=@_;
1.46 ng 2453: my (@string,$timestamp);
1.119 ng 2454: if ($$returnhash{'version'}) {
1.46 ng 2455: my %lasthash=();
2456: my ($version);
1.119 ng 2457: for ($version=1;$version<=$$returnhash{'version'};$version++) {
1.397 albertel 2458: foreach my $key (sort(split(/\:/,
2459: $$returnhash{$version.':keys'}))) {
2460: $lasthash{$key}=$$returnhash{$version.':'.$key};
2461: $timestamp =
1.545 raeburn 2462: &Apache::lonlocal::locallocaltime($$returnhash{$version.':timestamp'});
1.46 ng 2463: }
2464: }
1.397 albertel 2465: foreach my $key (keys(%lasthash)) {
2466: next if ($key !~ /\.submission$/);
2467:
2468: my ($partid,$foo) = split(/submission$/,$key);
2469: my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
1.398 albertel 2470: '<span class="LC_warning">Draft Copy</span> ' : '';
1.397 albertel 2471: push(@string, join(':', $key, $draft.$lasthash{$key}));
1.41 ng 2472: }
2473: }
1.397 albertel 2474: if (!@string) {
2475: $string[0] =
1.539 riegler 2476: '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span>';
1.397 albertel 2477: }
2478: return (\@string,\$timestamp);
1.38 ng 2479: }
1.35 ng 2480:
1.44 ng 2481: #--- High light keywords, with style choosen by user.
1.38 ng 2482: sub keywords_highlight {
1.44 ng 2483: my $string = shift;
1.257 albertel 2484: my $size = $env{'form.kwsize'} eq '0' ? '' : 'size='.$env{'form.kwsize'};
2485: my $styleon = $env{'form.kwstyle'} eq '' ? '' : $env{'form.kwstyle'};
1.41 ng 2486: (my $styleoff = $styleon) =~ s/\</\<\//;
1.257 albertel 2487: my @keylist = split(/[,\s+]/,$env{'form.keywords'});
1.398 albertel 2488: foreach my $keyword (@keylist) {
2489: $string =~ s/\b\Q$keyword\E(\b|\.)/<font color\=$env{'form.kwclr'} $size\>$styleon$keyword$styleoff<\/font>/gi;
1.41 ng 2490: }
2491: return $string;
1.38 ng 2492: }
1.36 ng 2493:
1.44 ng 2494: #--- Called from submission routine
1.38 ng 2495: sub processHandGrade {
1.41 ng 2496: my ($request) = shift;
1.324 albertel 2497: my $symb = &get_symb($request);
2498: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.257 albertel 2499: my $button = $env{'form.gradeOpt'};
2500: my $ngrade = $env{'form.NCT'};
2501: my $ntstu = $env{'form.NTSTU'};
1.301 albertel 2502: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2503: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2504:
1.44 ng 2505: if ($button eq 'Save & Next') {
2506: my $ctr = 0;
2507: while ($ctr < $ngrade) {
1.257 albertel 2508: my ($uname,$udom) = split(/:/,$env{'form.unamedom'.$ctr});
1.324 albertel 2509: my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$symb,$uname,$udom,$ctr);
1.71 ng 2510: if ($errorflag eq 'no_score') {
2511: $ctr++;
2512: next;
2513: }
1.104 albertel 2514: if ($errorflag eq 'not_allowed') {
1.398 albertel 2515: $request->print("<span class=\"LC_warning\">Not allowed to modify grades for $uname:$udom</span>");
1.104 albertel 2516: $ctr++;
2517: next;
2518: }
1.257 albertel 2519: my $includemsg = $env{'form.includemsg'.$ctr};
1.44 ng 2520: my ($subject,$message,$msgstatus) = ('','','');
1.418 albertel 2521: my $restitle = &Apache::lonnet::gettitle($symb);
2522: my ($feedurl,$showsymb) =
2523: &get_feedurl_and_symb($symb,$uname,$udom);
2524: my $messagetail;
1.62 albertel 2525: if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.298 www 2526: $subject = $env{'form.msgsub'} if ($includemsg =~ /msgsub/);
1.295 www 2527: unless ($subject=~/\w/) { $subject=&mt('Grading Feedback'); }
1.386 raeburn 2528: $subject.=' ['.$restitle.']';
1.44 ng 2529: my (@msgnum) = split(/,/,$includemsg);
2530: foreach (@msgnum) {
1.257 albertel 2531: $message.=$env{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
1.44 ng 2532: }
1.80 ng 2533: $message =&Apache::lonfeedback::clear_out_html($message);
1.298 www 2534: if ($env{'form.withgrades'.$ctr}) {
2535: $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
1.386 raeburn 2536: $messagetail = " for <a href=\"".
1.418 albertel 2537: $feedurl."?symb=$showsymb\">$env{'form.probTitle'}</a>";
1.386 raeburn 2538: }
2539: $msgstatus =
2540: &Apache::lonmsg::user_normal_msg($uname,$udom,$subject,
2541: $message.$messagetail,
1.418 albertel 2542: undef,$feedurl,undef,
1.386 raeburn 2543: undef,undef,$showsymb,
2544: $restitle);
1.574 bisitz 2545: $request->print('<br />'.&mt('Sending message to [_1]',$uname.':'.$udom).': '.
1.296 www 2546: $msgstatus);
1.44 ng 2547: }
1.257 albertel 2548: if ($env{'form.collaborator'.$ctr}) {
1.155 albertel 2549: my @collabstrs=&Apache::loncommon::get_env_multiple("form.collaborator$ctr");
1.150 albertel 2550: foreach my $collabstr (@collabstrs) {
2551: my ($part,@collaborators) = split(/:/,$collabstr);
1.310 banghart 2552: foreach my $collaborator (@collaborators) {
1.150 albertel 2553: my ($errorflag,$pts,$wgt) =
1.324 albertel 2554: &saveHandGrade($request,$symb,$collaborator,$udom,$ctr,
1.257 albertel 2555: $env{'form.unamedom'.$ctr},$part);
1.150 albertel 2556: if ($errorflag eq 'not_allowed') {
1.362 albertel 2557: $request->print("<span class=\"LC_error\">".&mt('Not allowed to modify grades for [_1]',"$collaborator:$udom")."</span>");
1.150 albertel 2558: next;
1.418 albertel 2559: } elsif ($message ne '') {
2560: my ($baseurl,$showsymb) =
2561: &get_feedurl_and_symb($symb,$collaborator,
2562: $udom);
2563: if ($env{'form.withgrades'.$ctr}) {
2564: $messagetail = " for <a href=\"".
1.386 raeburn 2565: $baseurl."?symb=$showsymb\">$env{'form.probTitle'}</a>";
1.150 albertel 2566: }
1.418 albertel 2567: $msgstatus =
2568: &Apache::lonmsg::user_normal_msg($collaborator,$udom,$subject,$message.$messagetail,undef,$baseurl,undef,undef,undef,$showsymb,$restitle);
1.104 albertel 2569: }
1.44 ng 2570: }
2571: }
2572: }
2573: $ctr++;
2574: }
2575: }
2576:
1.257 albertel 2577: if ($env{'form.handgrade'} eq 'yes') {
1.119 ng 2578: # Keywords sorted in alphabatical order
1.257 albertel 2579: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1.119 ng 2580: my %keyhash = ();
1.257 albertel 2581: $env{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
2582: $env{'form.keywords'} =~ s/^\s+|\s+$//;
2583: my (@keywords) = sort(split(/\s+/,$env{'form.keywords'}));
2584: $env{'form.keywords'} = join(' ',@keywords);
2585: $keyhash{$symb.'_keywords'} = $env{'form.keywords'};
2586: $keyhash{$symb.'_subject'} = $env{'form.msgsub'};
2587: $keyhash{$loginuser.'_kwclr'} = $env{'form.kwclr'};
2588: $keyhash{$loginuser.'_kwsize'} = $env{'form.kwsize'};
2589: $keyhash{$loginuser.'_kwstyle'} = $env{'form.kwstyle'};
1.119 ng 2590:
2591: # message center - Order of message gets changed. Blank line is eliminated.
1.257 albertel 2592: # New messages are saved in env for the next student.
1.119 ng 2593: # All messages are saved in nohist_handgrade.db
2594: my ($ctr,$idx) = (1,1);
1.257 albertel 2595: while ($ctr <= $env{'form.savemsgN'}) {
2596: if ($env{'form.savemsg'.$ctr} ne '') {
2597: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.savemsg'.$ctr};
1.119 ng 2598: $idx++;
2599: }
2600: $ctr++;
1.41 ng 2601: }
1.119 ng 2602: $ctr = 0;
2603: while ($ctr < $ngrade) {
1.257 albertel 2604: if ($env{'form.newmsg'.$ctr} ne '') {
2605: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.newmsg'.$ctr};
2606: $env{'form.savemsg'.$idx} = $env{'form.newmsg'.$ctr};
1.119 ng 2607: $idx++;
2608: }
2609: $ctr++;
1.41 ng 2610: }
1.257 albertel 2611: $env{'form.savemsgN'} = --$idx;
2612: $keyhash{$symb.'_savemsgN'} = $env{'form.savemsgN'};
1.119 ng 2613: my $putresult = &Apache::lonnet::put
1.301 albertel 2614: ('nohist_handgrade',\%keyhash,$cdom,$cnum);
1.41 ng 2615: }
1.44 ng 2616: # Called by Save & Refresh from Highlight Attribute Window
1.257 albertel 2617: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
2618: if ($env{'form.refresh'} eq 'on') {
1.86 ng 2619: my ($ctr,$total) = (0,0);
2620: while ($ctr < $ngrade) {
1.257 albertel 2621: $total++ if $env{'form.unamedom'.$ctr} ne '';
1.86 ng 2622: $ctr++;
2623: }
1.257 albertel 2624: $env{'form.NTSTU'}=$ngrade;
1.86 ng 2625: $ctr = 0;
2626: while ($ctr < $total) {
1.257 albertel 2627: my $processUser = $env{'form.unamedom'.$ctr};
2628: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2629: $env{'form.fullname'} = $$fullname{$processUser};
1.86 ng 2630: &submission($request,$ctr,$total-1);
1.41 ng 2631: $ctr++;
2632: }
2633: return '';
2634: }
1.36 ng 2635:
1.121 ng 2636: # Go directly to grade student - from submission or link from chart page
1.120 ng 2637: if ($button eq 'Grade Student') {
1.324 albertel 2638: (undef,undef,$env{'form.handgrade'},undef,undef) = &showResourceInfo($symb);
1.257 albertel 2639: my $processUser = $env{'form.unamedom'.$env{'form.studentNo'}};
2640: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2641: $env{'form.fullname'} = $$fullname{$processUser};
1.120 ng 2642: &submission($request,0,0);
2643: return '';
2644: }
2645:
1.44 ng 2646: # Get the next/previous one or group of students
1.257 albertel 2647: my $firststu = $env{'form.unamedom0'};
2648: my $laststu = $env{'form.unamedom'.($ngrade-1)};
1.119 ng 2649: my $ctr = 2;
1.41 ng 2650: while ($laststu eq '') {
1.257 albertel 2651: $laststu = $env{'form.unamedom'.($ngrade-$ctr)};
1.41 ng 2652: $ctr++;
2653: $laststu = $firststu if ($ctr > $ngrade);
2654: }
1.44 ng 2655:
1.41 ng 2656: my (@parsedlist,@nextlist);
2657: my ($nextflg) = 0;
1.524 raeburn 2658: foreach my $item (sort
1.294 albertel 2659: {
2660: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
2661: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
2662: }
2663: return $a cmp $b;
2664: } (keys(%$fullname))) {
1.41 ng 2665: if ($nextflg == 1 && $button =~ /Next$/) {
1.524 raeburn 2666: push(@parsedlist,$item);
1.41 ng 2667: }
1.524 raeburn 2668: $nextflg = 1 if ($item eq $laststu);
1.41 ng 2669: if ($button eq 'Previous') {
1.524 raeburn 2670: last if ($item eq $firststu);
2671: push(@parsedlist,$item);
1.41 ng 2672: }
2673: }
2674: $ctr = 0;
2675: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
1.582 raeburn 2676: my $res_error;
2677: my ($partlist) = &response_type($symb,\$res_error);
2678: if ($res_error) {
2679: $request->print(&navmap_errormsg());
2680: return;
2681: }
1.41 ng 2682: foreach my $student (@parsedlist) {
1.257 albertel 2683: my $submitonly=$env{'form.submitonly'};
1.41 ng 2684: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 2685:
2686: if ($submitonly eq 'queued') {
2687: my %queue_status =
2688: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
2689: $udom,$uname);
2690: next if (!defined($queue_status{'gradingqueue'}));
2691: }
2692:
1.156 albertel 2693: if ($submitonly =~ /^(yes|graded|incorrect)$/) {
1.257 albertel 2694: # my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 2695: my %status=&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 2696: my $submitted = 0;
1.248 albertel 2697: my $ungraded = 0;
2698: my $incorrect = 0;
1.524 raeburn 2699: foreach my $item (keys(%status)) {
2700: $submitted = 1 if ($status{$item} ne 'nothing');
2701: $ungraded = 1 if ($status{$item} =~ /^ungraded/);
2702: $incorrect = 1 if ($status{$item} =~ /^incorrect/);
2703: my ($foo,$partid,$foo1) = split(/\./,$item);
1.145 albertel 2704: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
2705: $submitted = 0;
2706: }
1.41 ng 2707: }
1.156 albertel 2708: next if (!$submitted && ($submitonly eq 'yes' ||
2709: $submitonly eq 'incorrect' ||
2710: $submitonly eq 'graded'));
1.248 albertel 2711: next if (!$ungraded && ($submitonly eq 'graded'));
2712: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 2713: }
1.524 raeburn 2714: push(@nextlist,$student) if ($ctr < $ntstu);
1.129 ng 2715: last if ($ctr == $ntstu);
1.41 ng 2716: $ctr++;
2717: }
1.36 ng 2718:
1.41 ng 2719: $ctr = 0;
2720: my $total = scalar(@nextlist)-1;
1.39 ng 2721:
1.524 raeburn 2722: foreach (sort(@nextlist)) {
1.41 ng 2723: my ($uname,$udom,$submitter) = split(/:/);
1.257 albertel 2724: $env{'form.student'} = $uname;
2725: $env{'form.userdom'} = $udom;
2726: $env{'form.fullname'} = $$fullname{$_};
1.41 ng 2727: &submission($request,$ctr,$total);
2728: $ctr++;
2729: }
2730: if ($total < 0) {
1.485 albertel 2731: my $the_end = '<h3><span class="LC_info">'.&mt('LON-CAPA User Message').'</span></h3><br />'."\n";
2732: $the_end.=&mt('<b>Message: </b> No more students for this section or class.').'<br /><br />'."\n";
2733: $the_end.=&mt('Click on the button below to return to the grading menu.').'<br /><br />'."\n";
1.324 albertel 2734: $the_end.=&show_grading_menu_form($symb);
1.41 ng 2735: $request->print($the_end);
2736: }
2737: return '';
1.38 ng 2738: }
1.36 ng 2739:
1.44 ng 2740: #---- Save the score and award for each student, if changed
1.38 ng 2741: sub saveHandGrade {
1.324 albertel 2742: my ($request,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
1.342 banghart 2743: my @version_parts;
1.104 albertel 2744: my $usec = &Apache::lonnet::getsection($domain,$stuname,
1.257 albertel 2745: $env{'request.course.id'});
1.104 albertel 2746: if (!&canmodify($usec)) { return('not_allowed'); }
1.337 banghart 2747: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
1.251 banghart 2748: my @parts_graded;
1.77 ng 2749: my %newrecord = ();
2750: my ($pts,$wgt) = ('','');
1.269 raeburn 2751: my %aggregate = ();
2752: my $aggregateflag = 0;
1.301 albertel 2753: my @parts = split(/:/,$env{'form.partlist'.$newflg});
2754: foreach my $new_part (@parts) {
1.337 banghart 2755: #collaborator ($submi may vary for different parts
1.259 banghart 2756: if ($submitter && $new_part ne $part) { next; }
2757: my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
1.125 ng 2758: if ($dropMenu eq 'excused') {
1.259 banghart 2759: if ($record{'resource.'.$new_part.'.solved'} ne 'excused') {
2760: $newrecord{'resource.'.$new_part.'.solved'} = 'excused';
2761: if (exists($record{'resource.'.$new_part.'.awarded'})) {
2762: $newrecord{'resource.'.$new_part.'.awarded'} = '';
1.58 albertel 2763: }
1.364 banghart 2764: $newrecord{'resource.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.58 albertel 2765: }
1.125 ng 2766: } elsif ($dropMenu eq 'reset status'
1.259 banghart 2767: && exists($record{'resource.'.$new_part.'.solved'})) { #don't bother if no old records -> no attempts
1.524 raeburn 2768: foreach my $key (keys(%record)) {
1.259 banghart 2769: if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
1.197 albertel 2770: }
1.259 banghart 2771: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2772: "$env{'user.name'}:$env{'user.domain'}";
1.270 albertel 2773: my $totaltries = $record{'resource.'.$part.'.tries'};
2774:
2775: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
2776: [$new_part]);
2777: my $aggtries =$totaltries;
1.269 raeburn 2778: if ($last_resets{$new_part}) {
1.270 albertel 2779: $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
2780: $new_part);
1.269 raeburn 2781: }
1.270 albertel 2782:
2783: my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
1.269 raeburn 2784: if ($aggtries > 0) {
1.327 albertel 2785: &decrement_aggs($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
1.269 raeburn 2786: $aggregateflag = 1;
2787: }
1.125 ng 2788: } elsif ($dropMenu eq '') {
1.259 banghart 2789: $pts = ($env{'form.GD_BOX'.$newflg.'_'.$new_part} ne '' ?
2790: $env{'form.GD_BOX'.$newflg.'_'.$new_part} :
2791: $env{'form.RADVAL'.$newflg.'_'.$new_part});
2792: if ($pts eq '' && $env{'form.GD_SEL'.$newflg.'_'.$new_part} eq '') {
1.153 albertel 2793: next;
2794: }
1.259 banghart 2795: $wgt = $env{'form.WGT'.$newflg.'_'.$new_part} eq '' ? 1 :
2796: $env{'form.WGT'.$newflg.'_'.$new_part};
1.41 ng 2797: my $partial= $pts/$wgt;
1.259 banghart 2798: if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
1.153 albertel 2799: #do not update score for part if not changed.
1.346 banghart 2800: &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
1.153 albertel 2801: next;
1.251 banghart 2802: } else {
1.524 raeburn 2803: push(@parts_graded,$new_part);
1.153 albertel 2804: }
1.259 banghart 2805: if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
2806: $newrecord{'resource.'.$new_part.'.awarded'} = $partial;
1.153 albertel 2807: }
1.259 banghart 2808: my $reckey = 'resource.'.$new_part.'.solved';
1.41 ng 2809: if ($partial == 0) {
1.153 albertel 2810: if ($record{$reckey} ne 'incorrect_by_override') {
2811: $newrecord{$reckey} = 'incorrect_by_override';
2812: }
1.41 ng 2813: } else {
1.153 albertel 2814: if ($record{$reckey} ne 'correct_by_override') {
2815: $newrecord{$reckey} = 'correct_by_override';
2816: }
2817: }
2818: if ($submitter &&
1.259 banghart 2819: ($record{'resource.'.$new_part.'.submitted_by'} ne $submitter)) {
2820: $newrecord{'resource.'.$new_part.'.submitted_by'} = $submitter;
1.41 ng 2821: }
1.259 banghart 2822: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2823: "$env{'user.name'}:$env{'user.domain'}";
1.41 ng 2824: }
1.259 banghart 2825: # unless problem has been graded, set flag to version the submitted files
1.305 banghart 2826: unless ($record{'resource.'.$new_part.'.solved'} =~ /^correct_/ ||
2827: $record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override' ||
2828: $dropMenu eq 'reset status')
2829: {
1.524 raeburn 2830: push(@version_parts,$new_part);
1.259 banghart 2831: }
1.41 ng 2832: }
1.301 albertel 2833: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2834: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2835:
1.344 albertel 2836: if (%newrecord) {
2837: if (@version_parts) {
1.364 banghart 2838: my @changed_keys = &version_portfiles(\%record, \@parts_graded,
2839: $env{'request.course.id'}, $symb, $domain, $stuname, \@version_parts);
1.344 albertel 2840: @newrecord{@changed_keys} = @record{@changed_keys};
1.367 albertel 2841: foreach my $new_part (@version_parts) {
2842: &handback_files($request,$symb,$stuname,$domain,$newflg,
2843: $new_part,\%newrecord);
2844: }
1.259 banghart 2845: }
1.44 ng 2846: &Apache::lonnet::cstore(\%newrecord,$symb,
1.257 albertel 2847: $env{'request.course.id'},$domain,$stuname);
1.380 albertel 2848: &check_and_remove_from_queue(\@parts,\%record,\%newrecord,$symb,
2849: $cdom,$cnum,$domain,$stuname);
1.41 ng 2850: }
1.269 raeburn 2851: if ($aggregateflag) {
2852: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 2853: $cdom,$cnum);
1.269 raeburn 2854: }
1.301 albertel 2855: return ('',$pts,$wgt);
1.36 ng 2856: }
1.322 albertel 2857:
1.380 albertel 2858: sub check_and_remove_from_queue {
2859: my ($parts,$record,$newrecord,$symb,$cdom,$cnum,$domain,$stuname) = @_;
2860: my @ungraded_parts;
2861: foreach my $part (@{$parts}) {
2862: if ( $record->{ 'resource.'.$part.'.awarded'} eq ''
2863: && $record->{ 'resource.'.$part.'.solved' } ne 'excused'
2864: && $newrecord->{'resource.'.$part.'.awarded'} eq ''
2865: && $newrecord->{'resource.'.$part.'.solved' } ne 'excused'
2866: ) {
2867: push(@ungraded_parts, $part);
2868: }
2869: }
2870: if ( !@ungraded_parts ) {
2871: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,
2872: $cnum,$domain,$stuname);
2873: }
2874: }
2875:
1.337 banghart 2876: sub handback_files {
2877: my ($request,$symb,$stuname,$domain,$newflg,$new_part,$newrecord) = @_;
1.517 raeburn 2878: my $portfolio_root = '/userfiles/portfolio';
1.582 raeburn 2879: my $res_error;
2880: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
2881: if ($res_error) {
2882: $request->print('<br />'.&navmap_errormsg().'<br />');
2883: return;
2884: }
1.375 albertel 2885: my @part_response_id = &flatten_responseType($responseType);
2886: foreach my $part_response_id (@part_response_id) {
2887: my ($part_id,$resp_id) = @{ $part_response_id };
2888: my $part_resp = join('_',@{ $part_response_id });
1.337 banghart 2889: if (($env{'form.'.$newflg.'_'.$part_resp.'_returndoc1'}) && ($new_part == $part_id)) {
2890: # if multiple files are uploaded names will be 'returndoc2','returndoc3'
2891: my $file_counter = 1;
1.367 albertel 2892: my $file_msg;
1.337 banghart 2893: while ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter}) {
2894: my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.'.filename'};
1.338 banghart 2895: my ($directory,$answer_file) =
2896: ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter} =~ /^(.*?)([^\/]*)$/);
2897: my ($answer_name,$answer_ver,$answer_ext) =
2898: &file_name_version_ext($answer_file);
1.355 banghart 2899: my ($portfolio_path) = ($directory =~ /^.+$stuname\/portfolio(.*)/);
1.517 raeburn 2900: my $getpropath = 1;
2901: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$portfolio_path,$domain,$stuname,$getpropath);
1.338 banghart 2902: my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
1.355 banghart 2903: # fix file name
2904: my ($save_file_name) = (($directory.$answer_name.".$version.".$answer_ext) =~ /^.+\/${stuname}\/(.*)/);
2905: my $result=&Apache::lonnet::finishuserfileupload($stuname,$domain,
2906: $newflg.'_'.$part_resp.'_returndoc'.$file_counter,
2907: $save_file_name);
1.337 banghart 2908: if ($result !~ m|^/uploaded/|) {
1.536 raeburn 2909: $request->print('<br /><span class="LC_error">'.
2910: &mt('An error occurred ([_1]) while trying to upload [_2].',
2911: $result,$newflg.'_'.$part_resp.'_returndoc'.$file_counter).
2912: '</span>');
1.356 banghart 2913: } else {
1.360 banghart 2914: # mark the file as read only
2915: my @files = ($save_file_name);
1.372 albertel 2916: my @what = ($symb,$env{'request.course.id'},'handback');
1.360 banghart 2917: &Apache::lonnet::mark_as_readonly($domain,$stuname,\@files,\@what);
1.367 albertel 2918: if (exists($$newrecord{"resource.$new_part.$resp_id.handback"})) {
2919: $$newrecord{"resource.$new_part.$resp_id.handback"}.=',';
2920: }
2921: $$newrecord{"resource.$new_part.$resp_id.handback"} .= $save_file_name;
2922: $file_msg.= "\n".'<br /><span class="LC_filename"><a href="/uploaded/'."$domain/$stuname/".$save_file_name.'">'.$save_file_name."</a></span><br />";
2923:
1.337 banghart 2924: }
2925: $request->print("<br />".$fname." will be the uploaded file name");
1.354 albertel 2926: $request->print(" ".$env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter});
1.337 banghart 2927: $file_counter++;
2928: }
1.367 albertel 2929: my $subject = "File Handed Back by Instructor ";
2930: my $message = "A file has been returned that was originally submitted in reponse to: <br />";
2931: $message .= "<strong>".&Apache::lonnet::gettitle($symb)."</strong><br />";
2932: $message .= ' The returned file(s) are named: '. $file_msg;
2933: $message .= " and can be found in your portfolio space.";
1.418 albertel 2934: my ($feedurl,$showsymb) =
2935: &get_feedurl_and_symb($symb,$domain,$stuname);
1.386 raeburn 2936: my $restitle = &Apache::lonnet::gettitle($symb);
2937: my $msgstatus =
2938: &Apache::lonmsg::user_normal_msg($stuname,$domain,$subject.
2939: ' (File Returned) ['.$restitle.']',$message,undef,
1.418 albertel 2940: $feedurl,undef,undef,undef,$showsymb,$restitle);
1.337 banghart 2941: }
2942: }
1.338 banghart 2943: return;
1.337 banghart 2944: }
2945:
1.418 albertel 2946: sub get_feedurl_and_symb {
2947: my ($symb,$uname,$udom) = @_;
2948: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
2949: $url = &Apache::lonnet::clutter($url);
2950: my $encrypturl=&Apache::lonnet::EXT('resource.0.encrypturl',
2951: $symb,$udom,$uname);
2952: if ($encrypturl =~ /^yes$/i) {
2953: &Apache::lonenc::encrypted(\$url,1);
2954: &Apache::lonenc::encrypted(\$symb,1);
2955: }
2956: return ($url,$symb);
2957: }
2958:
1.313 banghart 2959: sub get_submitted_files {
2960: my ($udom,$uname,$partid,$respid,$record) = @_;
2961: my @files;
2962: if ($$record{"resource.$partid.$respid.portfiles"}) {
2963: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
2964: foreach my $file (split(',',$$record{"resource.$partid.$respid.portfiles"})) {
2965: push(@files,$file_url.$file);
2966: }
2967: }
2968: if ($$record{"resource.$partid.$respid.uploadedurl"}) {
2969: push(@files,$$record{"resource.$partid.$respid.uploadedurl"});
2970: }
2971: return (\@files);
2972: }
1.322 albertel 2973:
1.269 raeburn 2974: # ----------- Provides number of tries since last reset.
2975: sub get_num_tries {
2976: my ($record,$last_reset,$part) = @_;
2977: my $timestamp = '';
2978: my $num_tries = 0;
2979: if ($$record{'version'}) {
2980: for (my $version=$$record{'version'};$version>=1;$version--) {
2981: if (exists($$record{$version.':resource.'.$part.'.solved'})) {
2982: $timestamp = $$record{$version.':timestamp'};
2983: if ($timestamp > $last_reset) {
2984: $num_tries ++;
2985: } else {
2986: last;
2987: }
2988: }
2989: }
2990: }
2991: return $num_tries;
2992: }
2993:
2994: # ----------- Determine decrements required in aggregate totals
2995: sub decrement_aggs {
2996: my ($symb,$part,$aggregate,$aggtries,$totaltries,$solvedstatus) = @_;
2997: my %decrement = (
2998: attempts => 0,
2999: users => 0,
3000: correct => 0
3001: );
3002: $decrement{'attempts'} = $aggtries;
3003: if ($solvedstatus =~ /^correct/) {
3004: $decrement{'correct'} = 1;
3005: }
3006: if ($aggtries == $totaltries) {
3007: $decrement{'users'} = 1;
3008: }
1.524 raeburn 3009: foreach my $type (keys(%decrement)) {
1.269 raeburn 3010: $$aggregate{$symb."\0".$part."\0".$type} = -$decrement{$type};
3011: }
3012: return;
3013: }
3014:
3015: # ----------- Determine timestamps for last reset of aggregate totals for parts
3016: sub get_last_resets {
1.270 albertel 3017: my ($symb,$courseid,$partids) =@_;
3018: my %last_resets;
1.269 raeburn 3019: my $cdom = $env{'course.'.$courseid.'.domain'};
3020: my $cname = $env{'course.'.$courseid.'.num'};
1.271 albertel 3021: my @keys;
3022: foreach my $part (@{$partids}) {
3023: push(@keys,"$symb\0$part\0resettime");
3024: }
3025: my %results=&Apache::lonnet::get('nohist_resourcetracker',\@keys,
3026: $cdom,$cname);
3027: foreach my $part (@{$partids}) {
3028: $last_resets{$part}=$results{"$symb\0$part\0resettime"};
1.269 raeburn 3029: }
1.270 albertel 3030: return %last_resets;
1.269 raeburn 3031: }
3032:
1.251 banghart 3033: # ----------- Handles creating versions for portfolio files as answers
3034: sub version_portfiles {
1.343 banghart 3035: my ($record, $parts_graded, $courseid, $symb, $domain, $stu_name, $v_flag) = @_;
1.263 banghart 3036: my $version_parts = join('|',@$v_flag);
1.343 banghart 3037: my @returned_keys;
1.255 banghart 3038: my $parts = join('|', @$parts_graded);
1.517 raeburn 3039: my $portfolio_root = '/userfiles/portfolio';
1.277 albertel 3040: foreach my $key (keys(%$record)) {
1.259 banghart 3041: my $new_portfiles;
1.263 banghart 3042: if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
1.342 banghart 3043: my @versioned_portfiles;
1.367 albertel 3044: my @portfiles = split(/\s*,\s*/,$$record{$key});
1.252 banghart 3045: foreach my $file (@portfiles) {
1.306 banghart 3046: &Apache::lonnet::unmark_as_readonly($domain,$stu_name,[$symb,$env{'request.course.id'}],$file);
1.304 albertel 3047: my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*)$/);
3048: my ($answer_name,$answer_ver,$answer_ext) =
3049: &file_name_version_ext($answer_file);
1.517 raeburn 3050: my $getpropath = 1;
3051: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$directory,$domain,$stu_name,$getpropath);
1.342 banghart 3052: my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
1.306 banghart 3053: my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version);
3054: if ($new_answer ne 'problem getting file') {
1.342 banghart 3055: push(@versioned_portfiles, $directory.$new_answer);
1.306 banghart 3056: &Apache::lonnet::mark_as_readonly($domain,$stu_name,
1.367 albertel 3057: [$directory.$new_answer],
1.306 banghart 3058: [$symb,$env{'request.course.id'},'graded']);
1.259 banghart 3059: }
1.252 banghart 3060: }
1.343 banghart 3061: $$record{$key} = join(',',@versioned_portfiles);
3062: push(@returned_keys,$key);
1.251 banghart 3063: }
3064: }
1.343 banghart 3065: return (@returned_keys);
1.305 banghart 3066: }
3067:
1.307 banghart 3068: sub get_next_version {
1.341 banghart 3069: my ($answer_name, $answer_ext, $dir_list) = @_;
1.307 banghart 3070: my $version;
3071: foreach my $row (@$dir_list) {
3072: my ($file) = split(/\&/,$row,2);
3073: my ($file_name,$file_version,$file_ext) =
3074: &file_name_version_ext($file);
3075: if (($file_name eq $answer_name) &&
3076: ($file_ext eq $answer_ext)) {
3077: # gets here if filename and extension match, regardless of version
3078: if ($file_version ne '') {
3079: # a versioned file is found so save it for later
3080: if ($file_version > $version) {
3081: $version = $file_version;
3082: }
3083: }
3084: }
3085: }
3086: $version ++;
3087: return($version);
3088: }
3089:
1.305 banghart 3090: sub version_selected_portfile {
1.306 banghart 3091: my ($domain,$stu_name,$directory,$file_name,$version) = @_;
3092: my ($answer_name,$answer_ver,$answer_ext) =
3093: &file_name_version_ext($file_name);
3094: my $new_answer;
3095: $env{'form.copy'} = &Apache::lonnet::getfile("/uploaded/$domain/$stu_name/portfolio$directory$file_name");
3096: if($env{'form.copy'} eq '-1') {
3097: $new_answer = 'problem getting file';
3098: } else {
3099: $new_answer = $answer_name.'.'.$version.'.'.$answer_ext;
3100: my $copy_result = &Apache::lonnet::finishuserfileupload(
3101: $stu_name,$domain,'copy',
3102: '/portfolio'.$directory.$new_answer);
3103: }
3104: return ($new_answer);
1.251 banghart 3105: }
3106:
1.304 albertel 3107: sub file_name_version_ext {
3108: my ($file)=@_;
3109: my @file_parts = split(/\./, $file);
3110: my ($name,$version,$ext);
3111: if (@file_parts > 1) {
3112: $ext=pop(@file_parts);
3113: if (@file_parts > 1 && $file_parts[-1] =~ /^\d+$/) {
3114: $version=pop(@file_parts);
3115: }
3116: $name=join('.',@file_parts);
3117: } else {
3118: $name=join('.',@file_parts);
3119: }
3120: return($name,$version,$ext);
3121: }
3122:
1.44 ng 3123: #--------------------------------------------------------------------------------------
3124: #
3125: #-------------------------- Next few routines handles grading by section or whole class
3126: #
3127: #--- Javascript to handle grading by section or whole class
1.42 ng 3128: sub viewgrades_js {
3129: my ($request) = shift;
3130:
1.539 riegler 3131: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
1.41 ng 3132: $request->print(<<VIEWJAVASCRIPT);
3133: <script type="text/javascript" language="javascript">
1.45 ng 3134: function writePoint(partid,weight,point) {
1.125 ng 3135: var radioButton = document.classgrade["RADVAL_"+partid];
3136: var textbox = document.classgrade["TEXTVAL_"+partid];
1.42 ng 3137: if (point == "textval") {
1.125 ng 3138: point = document.classgrade["TEXTVAL_"+partid].value;
1.109 matthew 3139: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 3140: alert("$alertmsg"+parseFloat(point));
1.42 ng 3141: var resetbox = false;
3142: for (var i=0; i<radioButton.length; i++) {
3143: if (radioButton[i].checked) {
3144: textbox.value = i;
3145: resetbox = true;
3146: }
3147: }
3148: if (!resetbox) {
3149: textbox.value = "";
3150: }
3151: return;
3152: }
1.109 matthew 3153: if (parseFloat(point) > parseFloat(weight)) {
3154: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 3155: ") greater than the weight for the part. Accept?");
3156: if (resp == false) {
3157: textbox.value = "";
3158: return;
3159: }
3160: }
1.42 ng 3161: for (var i=0; i<radioButton.length; i++) {
3162: radioButton[i].checked=false;
1.109 matthew 3163: if (parseFloat(point) == i) {
1.42 ng 3164: radioButton[i].checked=true;
3165: }
3166: }
1.41 ng 3167:
1.42 ng 3168: } else {
1.125 ng 3169: textbox.value = parseFloat(point);
1.42 ng 3170: }
1.41 ng 3171: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3172: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3173: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3174: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3175: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3176: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 3177: if (saveval != "correct") {
3178: scorename.value = point;
1.43 ng 3179: if (selname[0].selected != true) {
3180: selname[0].selected = true;
3181: }
1.42 ng 3182: }
3183: }
1.125 ng 3184: document.classgrade["SELVAL_"+partid][0].selected = true;
1.42 ng 3185: }
3186:
3187: function writeRadText(partid,weight) {
1.125 ng 3188: var selval = document.classgrade["SELVAL_"+partid];
3189: var radioButton = document.classgrade["RADVAL_"+partid];
1.265 www 3190: var override = document.classgrade["FORCE_"+partid].checked;
1.125 ng 3191: var textbox = document.classgrade["TEXTVAL_"+partid];
3192: if (selval[1].selected || selval[2].selected) {
1.42 ng 3193: for (var i=0; i<radioButton.length; i++) {
3194: radioButton[i].checked=false;
3195:
3196: }
3197: textbox.value = "";
3198:
3199: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3200: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3201: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3202: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3203: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3204: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 3205: if ((saveval != "correct") || override) {
1.42 ng 3206: scorename.value = "";
1.125 ng 3207: if (selval[1].selected) {
3208: selname[1].selected = true;
3209: } else {
3210: selname[2].selected = true;
3211: if (Number(document.classgrade["GD_"+user+"_"+partid+"_tries"].value))
3212: {document.classgrade["GD_"+user+"_"+partid+"_tries"].value = '0';}
3213: }
1.42 ng 3214: }
3215: }
1.43 ng 3216: } else {
3217: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3218: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3219: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3220: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3221: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3222: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 3223: if ((saveval != "correct") || override) {
1.125 ng 3224: scorename.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
1.43 ng 3225: selname[0].selected = true;
3226: }
3227: }
3228: }
1.42 ng 3229: }
3230:
3231: function changeSelect(partid,user) {
1.125 ng 3232: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
3233: var textbox = document.classgrade["GD_"+user+'_'+partid+"_awarded"];
1.44 ng 3234: var point = textbox.value;
1.125 ng 3235: var weight = document.classgrade["weight_"+partid].value;
1.44 ng 3236:
1.109 matthew 3237: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 3238: alert("$alertmsg"+parseFloat(point));
1.44 ng 3239: textbox.value = "";
3240: return;
3241: }
1.109 matthew 3242: if (parseFloat(point) > parseFloat(weight)) {
3243: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 3244: ") greater than the weight of the part. Accept?");
3245: if (resp == false) {
3246: textbox.value = "";
3247: return;
3248: }
3249: }
1.42 ng 3250: selval[0].selected = true;
3251: }
3252:
3253: function changeOneScore(partid,user) {
1.125 ng 3254: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
3255: if (selval[1].selected || selval[2].selected) {
3256: document.classgrade["GD_"+user+'_'+partid+"_awarded"].value = "";
3257: if (selval[2].selected) {
3258: document.classgrade["GD_"+user+'_'+partid+"_tries"].value = "0";
3259: }
1.269 raeburn 3260: }
1.42 ng 3261: }
3262:
3263: function resetEntry(numpart) {
3264: for (ctpart=0;ctpart<numpart;ctpart++) {
1.125 ng 3265: var partid = document.classgrade["partid_"+ctpart].value;
3266: var radioButton = document.classgrade["RADVAL_"+partid];
3267: var textbox = document.classgrade["TEXTVAL_"+partid];
3268: var selval = document.classgrade["SELVAL_"+partid];
1.42 ng 3269: for (var i=0; i<radioButton.length; i++) {
3270: radioButton[i].checked=false;
3271:
3272: }
3273: textbox.value = "";
3274: selval[0].selected = true;
3275:
3276: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3277: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3278: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3279: var resetscore = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3280: resetscore.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
3281: var resettries = document.classgrade["GD_"+user+"_"+partid+"_tries"];
3282: resettries.value = document.classgrade["GD_"+user+"_"+partid+"_tries_s"].value;
3283: var saveselval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3284: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 3285: if (saveselval == "excused") {
1.43 ng 3286: if (selname[1].selected == false) { selname[1].selected = true;}
1.42 ng 3287: } else {
1.43 ng 3288: if (selname[0].selected == false) {selname[0].selected = true};
1.42 ng 3289: }
3290: }
1.41 ng 3291: }
1.42 ng 3292: }
3293:
1.41 ng 3294: </script>
3295: VIEWJAVASCRIPT
1.42 ng 3296: }
3297:
1.44 ng 3298: #--- show scores for a section or whole class w/ option to change/update a score
1.42 ng 3299: sub viewgrades {
3300: my ($request) = shift;
3301: &viewgrades_js($request);
1.41 ng 3302:
1.324 albertel 3303: my ($symb) = &get_symb($request);
1.168 albertel 3304: #need to make sure we have the correct data for later EXT calls,
3305: #thus invalidate the cache
3306: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 3307: $env{'course.'.$env{'request.course.id'}.'.num'},
3308: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 3309: &Apache::lonnet::clear_EXT_cache_status();
3310:
1.398 albertel 3311: my $result='<h3><span class="LC_info">'.&mt('Manual Grading').'</span></h3>';
1.485 albertel 3312: $result.='<h4>'.&mt('<b>Current Resource: </b>[_1]',$env{'form.probTitle'}).'</h4>'."\n";
1.41 ng 3313:
3314: #view individual student submission form - called using Javascript viewOneStudent
1.324 albertel 3315: $result.=&jscriptNform($symb);
1.41 ng 3316:
1.44 ng 3317: #beginning of class grading form
1.442 banghart 3318: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.41 ng 3319: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1.418 albertel 3320: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.38 ng 3321: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.432 banghart 3322: &build_section_inputs().
1.257 albertel 3323: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.442 banghart 3324: '<input type="hidden" name="Status" value="'.$env{'stu_status'}.'" />'."\n".
1.257 albertel 3325: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.72 ng 3326:
1.560 raeburn 3327: my ($common_header,$specific_header);
1.257 albertel 3328: if ($env{'form.section'} eq 'all') {
1.560 raeburn 3329: $common_header = &mt('Assign Common Grade to Class');
3330: $specific_header = &mt('Assign Grade to Specific Students in Class');
1.257 albertel 3331: } elsif ($env{'form.section'} eq 'none') {
1.560 raeburn 3332: $common_header = &mt('Assign Common Grade to Students in no Section');
3333: $specific_header = &mt('Assign Grade to Specific Students in no Section');
1.52 albertel 3334: } else {
1.560 raeburn 3335: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
3336: $common_header = &mt('Assign Common Grade to Students in Section(s) [_1]',$section_display);
3337: $specific_header = &mt('Assign Grade to Specific Students in Section(s) [_1]',$section_display);
1.52 albertel 3338: }
1.560 raeburn 3339: $result.= '<h3>'.$common_header.'</h3>'.&Apache::loncommon::start_data_table();
1.44 ng 3340: #radio buttons/text box for assigning points for a section or class.
3341: #handles different parts of a problem
1.582 raeburn 3342: my $res_error;
3343: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
3344: if ($res_error) {
3345: return &navmap_errormsg();
3346: }
1.42 ng 3347: my %weight = ();
3348: my $ctsparts = 0;
1.45 ng 3349: my %seen = ();
1.375 albertel 3350: my @part_response_id = &flatten_responseType($responseType);
3351: foreach my $part_response_id (@part_response_id) {
3352: my ($partid,$respid) = @{ $part_response_id };
3353: my $part_resp = join('_',@{ $part_response_id });
1.45 ng 3354: next if $seen{$partid};
3355: $seen{$partid}++;
1.375 albertel 3356: my $handgrade=$$handgrade{$part_resp};
1.42 ng 3357: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
3358: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
3359:
1.324 albertel 3360: my $display_part=&get_display_part($partid,$symb);
1.485 albertel 3361: my $radio.='<table border="0"><tr>';
1.41 ng 3362: my $ctr = 0;
1.42 ng 3363: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
1.485 albertel 3364: $radio.= '<td><label><input type="radio" name="RADVAL_'.$partid.'" '.
1.54 albertel 3365: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.288 albertel 3366: ','.$ctr.')" />'.$ctr."</label></td>\n";
1.41 ng 3367: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
3368: $ctr++;
3369: }
1.485 albertel 3370: $radio.='</tr></table>';
3371: my $line = '<input type="text" name="TEXTVAL_'.
1.589 bisitz 3372: $partid.'" size="4" '.'onchange="javascript:writePoint(\''.
1.54 albertel 3373: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.539 riegler 3374: $weight{$partid}.' '.&mt('(problem weight)').'</td>'."\n";
3375: $line.= '<td><b>'.&mt('Grade Status').':</b><select name="SELVAL_'.$partid.'"'.
1.589 bisitz 3376: 'onchange="javascript:writeRadText(\''.$partid.'\','.
1.59 albertel 3377: $weight{$partid}.')"> '.
1.401 albertel 3378: '<option selected="selected"> </option>'.
1.485 albertel 3379: '<option value="excused">'.&mt('excused').'</option>'.
3380: '<option value="reset status">'.&mt('reset status').'</option>'.
3381: '</select></td>'.
3382: '<td><label><input type="checkbox" name="FORCE_'.$partid.'" />'.&mt('Override "Correct"').'</label>';
3383: $line.='<input type="hidden" name="partid_'.
3384: $ctsparts.'" value="'.$partid.'" />'."\n";
3385: $line.='<input type="hidden" name="weight_'.
3386: $partid.'" value="'.$weight{$partid}.'" />'."\n";
3387:
3388: $result.=
3389: &Apache::loncommon::start_data_table_row()."\n".
1.577 bisitz 3390: '<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 3391: &Apache::loncommon::end_data_table_row()."\n";
1.42 ng 3392: $ctsparts++;
1.41 ng 3393: }
1.474 albertel 3394: $result.=&Apache::loncommon::end_data_table()."\n".
1.52 albertel 3395: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.485 albertel 3396: $result.='<input type="button" value="'.&mt('Revert to Default').'" '.
1.589 bisitz 3397: 'onclick="javascript:resetEntry('.$ctsparts.');" />';
1.41 ng 3398:
1.44 ng 3399: #table listing all the students in a section/class
3400: #header of table
1.560 raeburn 3401: $result.= '<h3>'.$specific_header.'</h3>'.
3402: &Apache::loncommon::start_data_table().
3403: &Apache::loncommon::start_data_table_header_row().
3404: '<th>'.&mt('No.').'</th>'.
3405: '<th>'.&nameUserString('header')."</th>\n";
1.582 raeburn 3406: my $partserror;
3407: my (@parts) = sort(&getpartlist($symb,\$partserror));
3408: if ($partserror) {
3409: return &navmap_errormsg();
3410: }
1.324 albertel 3411: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.269 raeburn 3412: my @partids = ();
1.41 ng 3413: foreach my $part (@parts) {
3414: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1.539 riegler 3415: my $narrowtext = &mt('Tries');
3416: $display =~ s|^Number of Attempts|$narrowtext <br />|; # makes the column narrower
1.41 ng 3417: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
1.207 albertel 3418: my ($partid) = &split_part_type($part);
1.524 raeburn 3419: push(@partids,$partid);
1.324 albertel 3420: my $display_part=&get_display_part($partid,$symb);
1.41 ng 3421: if ($display =~ /^Partial Credit Factor/) {
1.485 albertel 3422: $result.='<th>'.
3423: &mt('Score Part: [_1]<br /> (weight = [_2])',
3424: $display_part,$weight{$partid}).'</th>'."\n";
1.41 ng 3425: next;
1.485 albertel 3426:
1.207 albertel 3427: } else {
1.485 albertel 3428: if ($display =~ /Problem Status/) {
3429: my $grade_status_mt = &mt('Grade Status');
3430: $display =~ s{Problem Status}{$grade_status_mt<br />};
3431: }
3432: my $part_mt = &mt('Part:');
3433: $display =~s{\[Part: \Q$partid\E\]}{$part_mt $display_part};
1.41 ng 3434: }
1.485 albertel 3435:
1.474 albertel 3436: $result.='<th>'.$display.'</th>'."\n";
1.41 ng 3437: }
1.474 albertel 3438: $result.=&Apache::loncommon::end_data_table_header_row();
1.44 ng 3439:
1.270 albertel 3440: my %last_resets =
3441: &get_last_resets($symb,$env{'request.course.id'},\@partids);
1.269 raeburn 3442:
1.41 ng 3443: #get info for each student
1.44 ng 3444: #list all the students - with points and grade status
1.257 albertel 3445: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
1.41 ng 3446: my $ctr = 0;
1.294 albertel 3447: foreach (sort
3448: {
3449: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
3450: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
3451: }
3452: return $a cmp $b;
3453: } (keys(%$fullname))) {
1.126 ng 3454: $ctr++;
1.324 albertel 3455: $result.=&viewstudentgrade($symb,$env{'request.course.id'},
1.269 raeburn 3456: $_,$$fullname{$_},\@parts,\%weight,$ctr,\%last_resets);
1.41 ng 3457: }
1.474 albertel 3458: $result.=&Apache::loncommon::end_data_table();
1.41 ng 3459: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.485 albertel 3460: $result.='<input type="button" value="'.&mt('Save').'" '.
1.589 bisitz 3461: 'onclick="javascript:submit();" target="_self" /></form>'."\n";
1.96 albertel 3462: if (scalar(%$fullname) eq 0) {
3463: my $colspan=3+scalar(@parts);
1.433 banghart 3464: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.442 banghart 3465: my $stu_status = join(' or ',&Apache::loncommon::get_env_multiple('form.Status'));
1.433 banghart 3466: $result='<span class="LC_warning">'.
1.485 albertel 3467: &mt('There are no students in section(s) [_1] with enrollment status [_2] to modify or grade.',
1.442 banghart 3468: $section_display, $stu_status).
1.433 banghart 3469: '</span>';
1.96 albertel 3470: }
1.324 albertel 3471: $result.=&show_grading_menu_form($symb);
1.41 ng 3472: return $result;
3473: }
3474:
1.44 ng 3475: #--- call by previous routine to display each student
1.41 ng 3476: sub viewstudentgrade {
1.324 albertel 3477: my ($symb,$courseid,$student,$fullname,$parts,$weight,$ctr,$last_resets) = @_;
1.44 ng 3478: my ($uname,$udom) = split(/:/,$student);
3479: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.269 raeburn 3480: my %aggregates = ();
1.474 albertel 3481: my $result=&Apache::loncommon::start_data_table_row().'<td align="right">'.
1.233 albertel 3482: '<input type="hidden" name="ctr'.($ctr-1).'" value="'.$student.'" />'.
3483: "\n".$ctr.' </td><td> '.
1.44 ng 3484: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 3485: '\');" target="_self">'.$fullname.'</a> '.
1.398 albertel 3486: '<span class="LC_internal_info">('.$uname.($env{'user.domain'} eq $udom ? '' : ':'.$udom).')</span></td>'."\n";
1.281 albertel 3487: $student=~s/:/_/; # colon doen't work in javascript for names
1.63 albertel 3488: foreach my $apart (@$parts) {
3489: my ($part,$type) = &split_part_type($apart);
1.41 ng 3490: my $score=$record{"resource.$part.$type"};
1.276 albertel 3491: $result.='<td align="center">';
1.269 raeburn 3492: my ($aggtries,$totaltries);
3493: unless (exists($aggregates{$part})) {
1.270 albertel 3494: $totaltries = $record{'resource.'.$part.'.tries'};
3495:
3496: $aggtries = $totaltries;
1.269 raeburn 3497: if ($$last_resets{$part}) {
1.270 albertel 3498: $aggtries = &get_num_tries(\%record,$$last_resets{$part},
3499: $part);
3500: }
1.269 raeburn 3501: $result.='<input type="hidden" name="'.
3502: 'GD_'.$student.'_'.$part.'_aggtries" value="'.$aggtries.'" />'."\n";
3503: $result.='<input type="hidden" name="'.
3504: 'GD_'.$student.'_'.$part.'_totaltries" value="'.$totaltries.'" />'."\n";
3505: $aggregates{$part} = 1;
3506: }
1.41 ng 3507: if ($type eq 'awarded') {
1.320 albertel 3508: my $pts = $score eq '' ? '' : &compute_points($score,$$weight{$part});
1.42 ng 3509: $result.='<input type="hidden" name="'.
1.89 albertel 3510: 'GD_'.$student.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.233 albertel 3511: $result.='<input type="text" name="'.
1.89 albertel 3512: 'GD_'.$student.'_'.$part.'_awarded" '.
1.589 bisitz 3513: 'onchange="javascript:changeSelect(\''.$part.'\',\''.$student.
1.44 ng 3514: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41 ng 3515: } elsif ($type eq 'solved') {
3516: my ($status,$foo)=split(/_/,$score,2);
3517: $status = 'nothing' if ($status eq '');
1.89 albertel 3518: $result.='<input type="hidden" name="'.'GD_'.$student.'_'.
1.54 albertel 3519: $part.'_solved_s" value="'.$status.'" />'."\n";
1.233 albertel 3520: $result.=' <select name="'.
1.89 albertel 3521: 'GD_'.$student.'_'.$part.'_solved" '.
1.589 bisitz 3522: 'onchange="javascript:changeOneScore(\''.$part.'\',\''.$student.'\')" >'."\n";
1.485 albertel 3523: $result.= (($status eq 'excused') ? '<option> </option><option selected="selected" value="excused">'.&mt('excused').'</option>'
3524: : '<option selected="selected"> </option><option value="excused">'.&mt('excused').'</option>')."\n";
3525: $result.='<option value="reset status">'.&mt('reset status').'</option>';
1.126 ng 3526: $result.="</select> </td>\n";
1.122 ng 3527: } else {
3528: $result.='<input type="hidden" name="'.
3529: 'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
3530: "\n";
1.233 albertel 3531: $result.='<input type="text" name="'.
1.122 ng 3532: 'GD_'.$student.'_'.$part.'_'.$type.'" '.
3533: 'value="'.$score.'" size="4" /></td>'."\n";
1.41 ng 3534: }
3535: }
1.474 albertel 3536: $result.=&Apache::loncommon::end_data_table_row();
1.41 ng 3537: return $result;
1.38 ng 3538: }
3539:
1.44 ng 3540: #--- change scores for all the students in a section/class
3541: # record does not get update if unchanged
1.38 ng 3542: sub editgrades {
1.41 ng 3543: my ($request) = @_;
3544:
1.324 albertel 3545: my $symb=&get_symb($request);
1.433 banghart 3546: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.477 albertel 3547: my $title='<h2>'.&mt('Current Grade Status').'</h2>';
3548: $title.='<h4>'.&mt('<b>Current Resource: </b>[_1]',$env{'form.probTitle'}).'</h4>'."\n";
1.433 banghart 3549: $title.='<h4>'.&mt('<b>Section: </b>[_1]',$section_display).'</h4>'."\n";
1.126 ng 3550:
1.477 albertel 3551: my $result= &Apache::loncommon::start_data_table().
3552: &Apache::loncommon::start_data_table_header_row().
3553: '<th rowspan="2" valign="middle">'.&mt('No.').'</th>'.
3554: '<th rowspan="2" valign="middle">'.&nameUserString('header')."</th>\n";
1.43 ng 3555: my %scoreptr = (
3556: 'correct' =>'correct_by_override',
3557: 'incorrect'=>'incorrect_by_override',
3558: 'excused' =>'excused',
3559: 'ungraded' =>'ungraded_attempted',
3560: 'nothing' => '',
3561: );
1.257 albertel 3562: my ($classlist,undef,$fullname) = &getclasslist($env{'form.section'},'0');
1.34 ng 3563:
1.44 ng 3564: my (@partid);
3565: my %weight = ();
1.54 albertel 3566: my %columns = ();
1.44 ng 3567: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54 albertel 3568:
1.582 raeburn 3569: my $partserror;
3570: my (@parts) = sort(&getpartlist($symb,\$partserror));
3571: if ($partserror) {
3572: return &navmap_errormsg();
3573: }
1.54 albertel 3574: my $header;
1.257 albertel 3575: while ($ctr < $env{'form.totalparts'}) {
3576: my $partid = $env{'form.partid_'.$ctr};
1.524 raeburn 3577: push(@partid,$partid);
1.257 albertel 3578: $weight{$partid} = $env{'form.weight_'.$partid};
1.44 ng 3579: $ctr++;
1.54 albertel 3580: }
1.324 albertel 3581: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.54 albertel 3582: foreach my $partid (@partid) {
1.478 albertel 3583: $header .= '<th align="center">'.&mt('Old Score').'</th>'.
3584: '<th align="center">'.&mt('New Score').'</th>';
1.54 albertel 3585: $columns{$partid}=2;
3586: foreach my $stores (@parts) {
3587: my ($part,$type) = &split_part_type($stores);
3588: if ($part !~ m/^\Q$partid\E/) { next;}
3589: if ($type eq 'awarded' || $type eq 'solved') { next; }
3590: my $display=&Apache::lonnet::metadata($url,$stores.'.display');
1.551 raeburn 3591: $display =~ s/\[Part: \Q$part\E\]//;
1.539 riegler 3592: my $narrowtext = &mt('Tries');
3593: $display =~ s/Number of Attempts/$narrowtext/;
3594: $header .= '<th align="center">'.&mt('Old').' '.$display.'</th>'.
3595: '<th align="center">'.&mt('New').' '.$display.'</th>';
1.54 albertel 3596: $columns{$partid}+=2;
3597: }
3598: }
3599: foreach my $partid (@partid) {
1.324 albertel 3600: my $display_part=&get_display_part($partid,$symb);
1.478 albertel 3601: $result .= '<th colspan="'.$columns{$partid}.'" align="center">'.
3602: &mt('Part: [_1] (Weight = [_2])',$display_part,$weight{$partid}).
3603: '</th>';
1.54 albertel 3604:
1.44 ng 3605: }
1.477 albertel 3606: $result .= &Apache::loncommon::end_data_table_header_row().
3607: &Apache::loncommon::start_data_table_header_row().
3608: $header.
3609: &Apache::loncommon::end_data_table_header_row();
3610: my @noupdate;
1.126 ng 3611: my ($updateCtr,$noupdateCtr) = (1,1);
1.257 albertel 3612: for ($i=0; $i<$env{'form.total'}; $i++) {
1.93 albertel 3613: my $line;
1.257 albertel 3614: my $user = $env{'form.ctr'.$i};
1.281 albertel 3615: my ($uname,$udom)=split(/:/,$user);
1.44 ng 3616: my %newrecord;
3617: my $updateflag = 0;
1.281 albertel 3618: $line .= '<td>'.&nameUserString(undef,$$fullname{$user},$uname,$udom).'</td>';
1.108 albertel 3619: my $usec=$classlist->{"$uname:$udom"}[5];
1.105 albertel 3620: if (!&canmodify($usec)) {
1.126 ng 3621: my $numcols=scalar(@partid)*4+2;
1.477 albertel 3622: push(@noupdate,
1.478 albertel 3623: $line."<td colspan=\"$numcols\"><span class=\"LC_warning\">".
3624: &mt('Not allowed to modify student')."</span></td></tr>");
1.105 albertel 3625: next;
3626: }
1.269 raeburn 3627: my %aggregate = ();
3628: my $aggregateflag = 0;
1.281 albertel 3629: $user=~s/:/_/; # colon doen't work in javascript for names
1.44 ng 3630: foreach (@partid) {
1.257 albertel 3631: my $old_aw = $env{'form.GD_'.$user.'_'.$_.'_awarded_s'};
1.54 albertel 3632: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
3633: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
1.257 albertel 3634: my $old_score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
3635: my $awarded = $env{'form.GD_'.$user.'_'.$_.'_awarded'};
1.54 albertel 3636: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
3637: my $partial = $awarded eq '' ? '' : $pcr;
1.44 ng 3638: my $score;
3639: if ($partial eq '') {
1.257 albertel 3640: $score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 3641: } elsif ($partial > 0) {
3642: $score = 'correct_by_override';
3643: } elsif ($partial == 0) {
3644: $score = 'incorrect_by_override';
3645: }
1.257 albertel 3646: my $dropMenu = $env{'form.GD_'.$user.'_'.$_.'_solved'};
1.125 ng 3647: $score = 'excused' if (($dropMenu eq 'excused') && ($score ne 'excused'));
3648:
1.292 albertel 3649: $newrecord{'resource.'.$_.'.regrader'}=
3650: "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 3651: if ($dropMenu eq 'reset status' &&
3652: $old_score ne '') { # ignore if no previous attempts => nothing to reset
1.299 albertel 3653: $newrecord{'resource.'.$_.'.tries'} = '';
1.125 ng 3654: $newrecord{'resource.'.$_.'.solved'} = '';
3655: $newrecord{'resource.'.$_.'.award'} = '';
1.299 albertel 3656: $newrecord{'resource.'.$_.'.awarded'} = '';
1.125 ng 3657: $updateflag = 1;
1.269 raeburn 3658: if ($env{'form.GD_'.$user.'_'.$_.'_aggtries'} > 0) {
3659: my $aggtries = $env{'form.GD_'.$user.'_'.$_.'_aggtries'};
3660: my $totaltries = $env{'form.GD_'.$user.'_'.$_.'_totaltries'};
3661: my $solvedstatus = $env{'form.GD_'.$user.'_'.$_.'_solved_s'};
3662: &decrement_aggs($symb,$_,\%aggregate,$aggtries,$totaltries,$solvedstatus);
3663: $aggregateflag = 1;
3664: }
1.139 albertel 3665: } elsif (!($old_part eq $partial && $old_score eq $score)) {
3666: $updateflag = 1;
3667: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
3668: $newrecord{'resource.'.$_.'.solved'} = $score;
3669: $rec_update++;
1.125 ng 3670: }
3671:
1.93 albertel 3672: $line .= '<td align="center">'.$old_aw.' </td>'.
1.44 ng 3673: '<td align="center">'.$awarded.
3674: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 3675:
1.54 albertel 3676:
3677: my $partid=$_;
3678: foreach my $stores (@parts) {
3679: my ($part,$type) = &split_part_type($stores);
3680: if ($part !~ m/^\Q$partid\E/) { next;}
3681: if ($type eq 'awarded' || $type eq 'solved') { next; }
1.257 albertel 3682: my $old_aw = $env{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
3683: my $awarded = $env{'form.GD_'.$user.'_'.$part.'_'.$type};
1.54 albertel 3684: if ($awarded ne '' && $awarded ne $old_aw) {
3685: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.257 albertel 3686: $newrecord{'resource.'.$part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.54 albertel 3687: $updateflag=1;
3688: }
1.93 albertel 3689: $line .= '<td align="center">'.$old_aw.' </td>'.
1.54 albertel 3690: '<td align="center">'.$awarded.' </td>';
3691: }
1.44 ng 3692: }
1.477 albertel 3693: $line.="\n";
1.301 albertel 3694:
3695: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3696: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3697:
1.44 ng 3698: if ($updateflag) {
3699: $count++;
1.257 albertel 3700: &Apache::lonnet::cstore(\%newrecord,$symb,$env{'request.course.id'},
1.89 albertel 3701: $udom,$uname);
1.301 albertel 3702:
3703: if (&Apache::bridgetask::in_queue('gradingqueue',$symb,$cdom,
3704: $cnum,$udom,$uname)) {
3705: # need to figure out if should be in queue.
3706: my %record =
3707: &Apache::lonnet::restore($symb,$env{'request.course.id'},
3708: $udom,$uname);
3709: my $all_graded = 1;
3710: my $none_graded = 1;
3711: foreach my $part (@parts) {
3712: if ( $record{'resource.'.$part.'.awarded'} eq '' ) {
3713: $all_graded = 0;
3714: } else {
3715: $none_graded = 0;
3716: }
3717: }
3718:
3719: if ($all_graded || $none_graded) {
3720: &Apache::bridgetask::remove_from_queue('gradingqueue',
3721: $symb,$cdom,$cnum,
3722: $udom,$uname);
3723: }
3724: }
3725:
1.477 albertel 3726: $result.=&Apache::loncommon::start_data_table_row().
3727: '<td align="right"> '.$updateCtr.' </td>'.$line.
3728: &Apache::loncommon::end_data_table_row();
1.126 ng 3729: $updateCtr++;
1.93 albertel 3730: } else {
1.477 albertel 3731: push(@noupdate,
3732: '<td align="right"> '.$noupdateCtr.' </td>'.$line);
1.126 ng 3733: $noupdateCtr++;
1.44 ng 3734: }
1.269 raeburn 3735: if ($aggregateflag) {
3736: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 3737: $cdom,$cnum);
1.269 raeburn 3738: }
1.93 albertel 3739: }
1.477 albertel 3740: if (@noupdate) {
1.126 ng 3741: # my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3;
3742: my $numcols=scalar(@partid)*4+2;
1.477 albertel 3743: $result .= &Apache::loncommon::start_data_table_row('LC_empty_row').
1.478 albertel 3744: '<td align="center" colspan="'.$numcols.'">'.
3745: &mt('No Changes Occurred For the Students Below').
3746: '</td>'.
1.477 albertel 3747: &Apache::loncommon::end_data_table_row();
3748: foreach my $line (@noupdate) {
3749: $result.=
3750: &Apache::loncommon::start_data_table_row().
3751: $line.
3752: &Apache::loncommon::end_data_table_row();
3753: }
1.44 ng 3754: }
1.477 albertel 3755: $result .= &Apache::loncommon::end_data_table().
3756: &show_grading_menu_form($symb);
1.478 albertel 3757: my $msg = '<p><b>'.
3758: &mt('Number of records updated = [_1] for [quant,_2,student].',
3759: $rec_update,$count).'</b><br />'.
3760: '<b>'.&mt('Total number of students = [_1]',$env{'form.total'}).
3761: '</b></p>';
1.44 ng 3762: return $title.$msg.$result;
1.5 albertel 3763: }
1.54 albertel 3764:
3765: sub split_part_type {
3766: my ($partstr) = @_;
3767: my ($temp,@allparts)=split(/_/,$partstr);
3768: my $type=pop(@allparts);
1.439 albertel 3769: my $part=join('_',@allparts);
1.54 albertel 3770: return ($part,$type);
3771: }
3772:
1.44 ng 3773: #------------- end of section for handling grading by section/class ---------
3774: #
3775: #----------------------------------------------------------------------------
3776:
1.5 albertel 3777:
1.44 ng 3778: #----------------------------------------------------------------------------
3779: #
3780: #-------------------------- Next few routines handles grading by csv upload
3781: #
3782: #--- Javascript to handle csv upload
1.27 albertel 3783: sub csvupload_javascript_reverse_associate {
1.573 bisitz 3784: my $error1=&mt('You need to specify the username or the student/employee ID');
1.246 albertel 3785: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3786: return(<<ENDPICK);
3787: function verify(vf) {
3788: var foundsomething=0;
3789: var founduname=0;
1.243 albertel 3790: var foundID=0;
1.27 albertel 3791: for (i=0;i<=vf.nfields.value;i++) {
3792: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3793: if (i==0 && tw!=0) { foundID=1; }
3794: if (i==1 && tw!=0) { founduname=1; }
3795: if (i!=0 && i!=1 && i!=2 && tw!=0) { foundsomething=1; }
1.27 albertel 3796: }
1.246 albertel 3797: if (founduname==0 && foundID==0) {
3798: alert('$error1');
3799: return;
1.27 albertel 3800: }
3801: if (foundsomething==0) {
1.246 albertel 3802: alert('$error2');
3803: return;
1.27 albertel 3804: }
3805: vf.submit();
3806: }
3807: function flip(vf,tf) {
3808: var nw=eval('vf.f'+tf+'.selectedIndex');
3809: var i;
3810: for (i=0;i<=vf.nfields.value;i++) {
3811: //can not pick the same destination field for both name and domain
3812: if (((i ==0)||(i ==1)) &&
3813: ((tf==0)||(tf==1)) &&
3814: (i!=tf) &&
3815: (eval('vf.f'+i+'.selectedIndex')==nw)) {
3816: eval('vf.f'+i+'.selectedIndex=0;')
3817: }
3818: }
3819: }
3820: ENDPICK
3821: }
3822:
3823: sub csvupload_javascript_forward_associate {
1.573 bisitz 3824: my $error1=&mt('You need to specify the username or the student/employee ID');
1.246 albertel 3825: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3826: return(<<ENDPICK);
3827: function verify(vf) {
3828: var foundsomething=0;
3829: var founduname=0;
1.243 albertel 3830: var foundID=0;
1.27 albertel 3831: for (i=0;i<=vf.nfields.value;i++) {
3832: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3833: if (tw==1) { foundID=1; }
3834: if (tw==2) { founduname=1; }
3835: if (tw>3) { foundsomething=1; }
1.27 albertel 3836: }
1.246 albertel 3837: if (founduname==0 && foundID==0) {
3838: alert('$error1');
3839: return;
1.27 albertel 3840: }
3841: if (foundsomething==0) {
1.246 albertel 3842: alert('$error2');
3843: return;
1.27 albertel 3844: }
3845: vf.submit();
3846: }
3847: function flip(vf,tf) {
3848: var nw=eval('vf.f'+tf+'.selectedIndex');
3849: var i;
3850: //can not pick the same destination field twice
3851: for (i=0;i<=vf.nfields.value;i++) {
3852: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
3853: eval('vf.f'+i+'.selectedIndex=0;')
3854: }
3855: }
3856: }
3857: ENDPICK
3858: }
3859:
1.26 albertel 3860: sub csvuploadmap_header {
1.324 albertel 3861: my ($request,$symb,$datatoken,$distotal)= @_;
1.41 ng 3862: my $javascript;
1.257 albertel 3863: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3864: $javascript=&csvupload_javascript_reverse_associate();
3865: } else {
3866: $javascript=&csvupload_javascript_forward_associate();
3867: }
1.45 ng 3868:
1.324 albertel 3869: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.257 albertel 3870: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1.245 albertel 3871: my $ignore=&mt('Ignore First Line');
1.418 albertel 3872: $symb = &Apache::lonenc::check_encrypt($symb);
1.41 ng 3873: $request->print(<<ENDPICK);
1.26 albertel 3874: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.398 albertel 3875: <h3><span class="LC_info">Uploading Class Grades</span></h3>
1.45 ng 3876: $result
1.326 albertel 3877: <hr />
1.26 albertel 3878: <h3>Identify fields</h3>
3879: Total number of records found in file: $distotal <hr />
3880: Enter as many fields as you can. The system will inform you and bring you back
3881: to this page if the data selected is insufficient to run your class.<hr />
1.589 bisitz 3882: <input type="button" value="Reverse Association" onclick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1.245 albertel 3883: <label><input type="checkbox" name="noFirstLine" $checked />$ignore</label>
1.26 albertel 3884: <input type="hidden" name="associate" value="" />
3885: <input type="hidden" name="phase" value="three" />
3886: <input type="hidden" name="datatoken" value="$datatoken" />
1.257 albertel 3887: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
3888: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
1.26 albertel 3889: <input type="hidden" name="upfile_associate"
1.257 albertel 3890: value="$env{'form.upfile_associate'}" />
1.26 albertel 3891: <input type="hidden" name="symb" value="$symb" />
1.257 albertel 3892: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
3893: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
1.246 albertel 3894: <input type="hidden" name="command" value="csvuploadoptions" />
1.26 albertel 3895: <hr />
3896: <script type="text/javascript" language="Javascript">
3897: $javascript
3898: </script>
3899: ENDPICK
1.118 ng 3900: return '';
1.26 albertel 3901:
3902: }
3903:
3904: sub csvupload_fields {
1.582 raeburn 3905: my ($symb,$errorref) = @_;
3906: my (@parts) = &getpartlist($symb,$errorref);
3907: if (ref($errorref)) {
3908: if ($$errorref) {
3909: return;
3910: }
3911: }
3912:
1.556 weissno 3913: my @fields=(['ID','Student/Employee ID'],
1.243 albertel 3914: ['username','Student Username'],
3915: ['domain','Student Domain']);
1.324 albertel 3916: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.41 ng 3917: foreach my $part (sort(@parts)) {
3918: my @datum;
3919: my $display=&Apache::lonnet::metadata($url,$part.'.display');
3920: my $name=$part;
3921: if (!$display) { $display = $name; }
3922: @datum=($name,$display);
1.244 albertel 3923: if ($name=~/^stores_(.*)_awarded/) {
3924: push(@fields,['stores_'.$1.'_points',"Points [Part: $1]"]);
3925: }
1.41 ng 3926: push(@fields,\@datum);
3927: }
3928: return (@fields);
1.26 albertel 3929: }
3930:
3931: sub csvuploadmap_footer {
1.41 ng 3932: my ($request,$i,$keyfields) =@_;
3933: $request->print(<<ENDPICK);
1.26 albertel 3934: </table>
3935: <input type="hidden" name="nfields" value="$i" />
3936: <input type="hidden" name="keyfields" value="$keyfields" />
1.589 bisitz 3937: <input type="button" onclick="javascript:verify(this.form)" value="Assign Grades" /><br />
1.26 albertel 3938: </form>
3939: ENDPICK
3940: }
3941:
1.283 albertel 3942: sub checkforfile_js {
1.539 riegler 3943: my $alertmsg = &mt('Please use the browse button to select a file from your local directory.');
1.86 ng 3944: my $result =<<CSVFORMJS;
3945: <script type="text/javascript" language="javascript">
3946: function checkUpload(formname) {
3947: if (formname.upfile.value == "") {
1.539 riegler 3948: alert("$alertmsg");
1.86 ng 3949: return false;
3950: }
3951: formname.submit();
3952: }
3953: </script>
3954: CSVFORMJS
1.283 albertel 3955: return $result;
3956: }
3957:
3958: sub upcsvScores_form {
3959: my ($request) = shift;
1.324 albertel 3960: my ($symb)=&get_symb($request);
1.283 albertel 3961: if (!$symb) {return '';}
3962: my $result=&checkforfile_js();
1.257 albertel 3963: $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
1.324 albertel 3964: my ($table) = &showResourceInfo($symb,$env{'form.probTitle'});
1.118 ng 3965: $result.=$table;
1.326 albertel 3966: $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
3967: $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
1.538 schulted 3968: $result.=' <b>'.&mt('Specify a file containing the class scores for current resource.').
3969: '</b></td></tr>'."\n";
1.86 ng 3970: $result.='<tr bgcolor=#ffffe6><td>'."\n";
1.370 www 3971: my $upload=&mt("Upload Scores");
1.86 ng 3972: my $upfile_select=&Apache::loncommon::upfile_select_html();
1.245 albertel 3973: my $ignore=&mt('Ignore First Line');
1.418 albertel 3974: $symb = &Apache::lonenc::check_encrypt($symb);
1.86 ng 3975: $result.=<<ENDUPFORM;
1.106 albertel 3976: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.86 ng 3977: <input type="hidden" name="symb" value="$symb" />
3978: <input type="hidden" name="command" value="csvuploadmap" />
1.257 albertel 3979: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
3980: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
1.86 ng 3981: $upfile_select
1.589 bisitz 3982: <br /><input type="button" onclick="javascript:checkUpload(this.form);" value="$upload" />
1.283 albertel 3983: <label><input type="checkbox" name="noFirstLine" />$ignore</label>
1.86 ng 3984: </form>
3985: ENDUPFORM
1.370 www 3986: $result.=&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
3987: &mt("How do I create a CSV file from a spreadsheet"))
3988: .'</td></tr></table>'."\n";
1.86 ng 3989: $result.='</td></tr></table><br /><br />'."\n";
1.324 albertel 3990: $result.=&show_grading_menu_form($symb);
1.86 ng 3991: return $result;
3992: }
3993:
3994:
1.26 albertel 3995: sub csvuploadmap {
1.41 ng 3996: my ($request)= @_;
1.324 albertel 3997: my ($symb)=&get_symb($request);
1.41 ng 3998: if (!$symb) {return '';}
1.72 ng 3999:
1.41 ng 4000: my $datatoken;
1.257 albertel 4001: if (!$env{'form.datatoken'}) {
1.41 ng 4002: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 4003: } else {
1.257 albertel 4004: $datatoken=$env{'form.datatoken'};
1.41 ng 4005: &Apache::loncommon::load_tmp_file($request);
1.26 albertel 4006: }
1.41 ng 4007: my @records=&Apache::loncommon::upfile_record_sep();
1.257 albertel 4008: if ($env{'form.noFirstLine'}) { shift(@records); }
1.324 albertel 4009: &csvuploadmap_header($request,$symb,$datatoken,$#records+1);
1.41 ng 4010: my ($i,$keyfields);
4011: if (@records) {
1.582 raeburn 4012: my $fieldserror;
4013: my @fields=&csvupload_fields($symb,\$fieldserror);
4014: if ($fieldserror) {
4015: $request->print(&navmap_errormsg());
4016: return;
4017: }
1.257 albertel 4018: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 4019: &Apache::loncommon::csv_print_samples($request,\@records);
4020: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
4021: \@fields);
4022: foreach (@fields) { $keyfields.=$_->[0].','; }
4023: chop($keyfields);
4024: } else {
4025: unshift(@fields,['none','']);
4026: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
4027: \@fields);
1.311 banghart 4028: foreach my $rec (@records) {
4029: my %temp = &Apache::loncommon::record_sep($rec);
4030: if (%temp) {
4031: $keyfields=join(',',sort(keys(%temp)));
4032: last;
4033: }
4034: }
1.41 ng 4035: }
4036: }
4037: &csvuploadmap_footer($request,$i,$keyfields);
1.324 albertel 4038: $request->print(&show_grading_menu_form($symb));
1.72 ng 4039:
1.41 ng 4040: return '';
1.27 albertel 4041: }
4042:
1.246 albertel 4043: sub csvuploadoptions {
1.41 ng 4044: my ($request)= @_;
1.324 albertel 4045: my ($symb)=&get_symb($request);
1.257 albertel 4046: my $checked=(($env{'form.noFirstLine'})?'1':'0');
1.246 albertel 4047: my $ignore=&mt('Ignore First Line');
4048: $request->print(<<ENDPICK);
4049: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.398 albertel 4050: <h3><span class="LC_info">Uploading Class Grade Options</span></h3>
1.246 albertel 4051: <input type="hidden" name="command" value="csvuploadassign" />
1.302 albertel 4052: <!--
1.246 albertel 4053: <p>
4054: <label>
4055: <input type="checkbox" name="show_full_results" />
4056: Show a table of all changes
4057: </label>
4058: </p>
1.302 albertel 4059: -->
1.246 albertel 4060: <p>
4061: <label>
4062: <input type="checkbox" name="overwite_scores" checked="checked" />
4063: Overwrite any existing score
4064: </label>
4065: </p>
4066: ENDPICK
4067: my %fields=&get_fields();
4068: if (!defined($fields{'domain'})) {
1.257 albertel 4069: my $domform = &Apache::loncommon::select_dom_form($env{'request.role.domain'},'default_domain');
1.246 albertel 4070: $request->print("\n<p> Users are in domain: ".$domform."</p>\n");
4071: }
1.257 albertel 4072: foreach my $key (sort(keys(%env))) {
1.246 albertel 4073: if ($key !~ /^form\.(.*)$/) { next; }
4074: my $cleankey=$1;
4075: if ($cleankey eq 'command') { next; }
4076: $request->print('<input type="hidden" name="'.$cleankey.
1.257 albertel 4077: '" value="'.$env{$key}.'" />'."\n");
1.246 albertel 4078: }
4079: # FIXME do a check for any duplicated user ids...
4080: # FIXME do a check for any invalid user ids?...
1.290 albertel 4081: $request->print('<input type="submit" value="Assign Grades" /><br />
4082: <hr /></form>'."\n");
1.324 albertel 4083: $request->print(&show_grading_menu_form($symb));
1.246 albertel 4084: return '';
4085: }
4086:
4087: sub get_fields {
4088: my %fields;
1.257 albertel 4089: my @keyfields = split(/\,/,$env{'form.keyfields'});
4090: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
4091: if ($env{'form.upfile_associate'} eq 'reverse') {
4092: if ($env{'form.f'.$i} ne 'none') {
4093: $fields{$keyfields[$i]}=$env{'form.f'.$i};
1.41 ng 4094: }
4095: } else {
1.257 albertel 4096: if ($env{'form.f'.$i} ne 'none') {
4097: $fields{$env{'form.f'.$i}}=$keyfields[$i];
1.41 ng 4098: }
4099: }
1.27 albertel 4100: }
1.246 albertel 4101: return %fields;
4102: }
4103:
4104: sub csvuploadassign {
4105: my ($request)= @_;
1.324 albertel 4106: my ($symb)=&get_symb($request);
1.246 albertel 4107: if (!$symb) {return '';}
1.345 bowersj2 4108: my $error_msg = '';
1.246 albertel 4109: &Apache::loncommon::load_tmp_file($request);
4110: my @gradedata = &Apache::loncommon::upfile_record_sep();
1.257 albertel 4111: if ($env{'form.noFirstLine'}) { shift(@gradedata); }
1.246 albertel 4112: my %fields=&get_fields();
1.41 ng 4113: $request->print('<h3>Assigning Grades</h3>');
1.257 albertel 4114: my $courseid=$env{'request.course.id'};
1.97 albertel 4115: my ($classlist) = &getclasslist('all',0);
1.106 albertel 4116: my @notallowed;
1.41 ng 4117: my @skipped;
4118: my $countdone=0;
4119: foreach my $grade (@gradedata) {
4120: my %entries=&Apache::loncommon::record_sep($grade);
1.246 albertel 4121: my $domain;
4122: if ($entries{$fields{'domain'}}) {
4123: $domain=$entries{$fields{'domain'}};
4124: } else {
1.257 albertel 4125: $domain=$env{'form.default_domain'};
1.246 albertel 4126: }
1.243 albertel 4127: $domain=~s/\s//g;
1.41 ng 4128: my $username=$entries{$fields{'username'}};
1.160 albertel 4129: $username=~s/\s//g;
1.243 albertel 4130: if (!$username) {
4131: my $id=$entries{$fields{'ID'}};
1.247 albertel 4132: $id=~s/\s//g;
1.243 albertel 4133: my %ids=&Apache::lonnet::idget($domain,$id);
4134: $username=$ids{$id};
4135: }
1.41 ng 4136: if (!exists($$classlist{"$username:$domain"})) {
1.247 albertel 4137: my $id=$entries{$fields{'ID'}};
4138: $id=~s/\s//g;
4139: if ($id) {
4140: push(@skipped,"$id:$domain");
4141: } else {
4142: push(@skipped,"$username:$domain");
4143: }
1.41 ng 4144: next;
4145: }
1.108 albertel 4146: my $usec=$classlist->{"$username:$domain"}[5];
1.106 albertel 4147: if (!&canmodify($usec)) {
4148: push(@notallowed,"$username:$domain");
4149: next;
4150: }
1.244 albertel 4151: my %points;
1.41 ng 4152: my %grades;
4153: foreach my $dest (keys(%fields)) {
1.244 albertel 4154: if ($dest eq 'ID' || $dest eq 'username' ||
4155: $dest eq 'domain') { next; }
4156: if ($entries{$fields{$dest}} =~ /^\s*$/) { next; }
4157: if ($dest=~/stores_(.*)_points/) {
4158: my $part=$1;
4159: my $wgt =&Apache::lonnet::EXT('resource.'.$part.'.weight',
4160: $symb,$domain,$username);
1.345 bowersj2 4161: if ($wgt) {
4162: $entries{$fields{$dest}}=~s/\s//g;
4163: my $pcr=$entries{$fields{$dest}} / $wgt;
1.463 albertel 4164: my $award=($pcr == 0) ? 'incorrect_by_override'
4165: : 'correct_by_override';
1.345 bowersj2 4166: $grades{"resource.$part.awarded"}=$pcr;
4167: $grades{"resource.$part.solved"}=$award;
4168: $points{$part}=1;
4169: } else {
4170: $error_msg = "<br />" .
4171: &mt("Some point values were assigned"
4172: ." for problems with a weight "
4173: ."of zero. These values were "
4174: ."ignored.");
4175: }
1.244 albertel 4176: } else {
4177: if ($dest=~/stores_(.*)_awarded/) { if ($points{$1}) {next;} }
4178: if ($dest=~/stores_(.*)_solved/) { if ($points{$1}) {next;} }
4179: my $store_key=$dest;
4180: $store_key=~s/^stores/resource/;
4181: $store_key=~s/_/\./g;
4182: $grades{$store_key}=$entries{$fields{$dest}};
4183: }
1.41 ng 4184: }
1.508 www 4185: if (! %grades) {
4186: push(@skipped,&mt("[_1]: no data to save","$username:$domain"));
4187: } else {
4188: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
4189: my $result=&Apache::lonnet::cstore(\%grades,$symb,
1.302 albertel 4190: $env{'request.course.id'},
4191: $domain,$username);
1.508 www 4192: if ($result eq 'ok') {
4193: $request->print('.');
4194: } else {
4195: $request->print("<p><span class=\"LC_error\">".
4196: &mt("Failed to save data for student [_1]. Message when trying to save was: [_2]",
4197: "$username:$domain",$result)."</span></p>");
4198: }
4199: $request->rflush();
4200: $countdone++;
4201: }
1.41 ng 4202: }
1.570 www 4203: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt("Saved scores for [quant,_1,student]",$countdone),$countdone==0));
1.41 ng 4204: if (@skipped) {
1.571 www 4205: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('No scores stored for the following username(s):'),1).'<br />');
4206: $request->print(join(', ',@skipped));
1.106 albertel 4207: }
4208: if (@notallowed) {
1.571 www 4209: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('Modification of scores not allowed for the following username(s):'),1).'<br />');
4210: $request->print(join(', ',@notallowed));
1.41 ng 4211: }
1.106 albertel 4212: $request->print("<br />\n");
1.324 albertel 4213: $request->print(&show_grading_menu_form($symb));
1.345 bowersj2 4214: return $error_msg;
1.26 albertel 4215: }
1.44 ng 4216: #------------- end of section for handling csv file upload ---------
4217: #
4218: #-------------------------------------------------------------------
4219: #
1.122 ng 4220: #-------------- Next few routines handle grading by page/sequence
1.72 ng 4221: #
4222: #--- Select a page/sequence and a student to grade
1.68 ng 4223: sub pickStudentPage {
4224: my ($request) = shift;
4225:
1.539 riegler 4226: my $alertmsg = &mt('Please select the student you wish to grade.');
1.68 ng 4227: $request->print(<<LISTJAVASCRIPT);
4228: <script type="text/javascript" language="javascript">
4229:
4230: function checkPickOne(formname) {
1.76 ng 4231: if (radioSelection(formname.student) == null) {
1.539 riegler 4232: alert("$alertmsg");
1.68 ng 4233: return;
4234: }
1.125 ng 4235: ptr = pullDownSelection(formname.selectpage);
4236: formname.page.value = formname["page"+ptr].value;
4237: formname.title.value = formname["title"+ptr].value;
1.68 ng 4238: formname.submit();
4239: }
4240:
4241: </script>
4242: LISTJAVASCRIPT
1.118 ng 4243: &commonJSfunctions($request);
1.324 albertel 4244: my ($symb) = &get_symb($request);
1.257 albertel 4245: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4246: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4247: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.68 ng 4248:
1.398 albertel 4249: my $result='<h3><span class="LC_info"> '.
1.485 albertel 4250: &mt('Manual Grading by Page or Sequence').'</span></h3>';
1.68 ng 4251:
1.80 ng 4252: $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
1.582 raeburn 4253: my $map_error;
4254: my ($titles,$symbx) = &getSymbMap($map_error);
4255: if ($map_error) {
4256: $request->print(&navmap_errormsg());
4257: return;
4258: }
1.137 albertel 4259: my ($curpage) =&Apache::lonnet::decode_symb($symb);
4260: # my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb);
4261: # my $type=($curpage =~ /\.(page|sequence)/);
1.485 albertel 4262: my $select = '<select name="selectpage">'."\n";
1.70 ng 4263: my $ctr=0;
1.68 ng 4264: foreach (@$titles) {
4265: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.485 albertel 4266: $select.='<option value="'.$ctr.'" '.
1.401 albertel 4267: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.71 ng 4268: '>'.$showtitle.'</option>'."\n";
1.70 ng 4269: $ctr++;
1.68 ng 4270: }
1.485 albertel 4271: $select.= '</select>';
1.539 riegler 4272: $result.=' <b>'.&mt('Problems from').':</b> '.$select."<br />\n";
1.485 albertel 4273:
1.70 ng 4274: $ctr=0;
4275: foreach (@$titles) {
4276: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
4277: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
4278: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
4279: $ctr++;
4280: }
1.72 ng 4281: $result.='<input type="hidden" name="page" />'."\n".
4282: '<input type="hidden" name="title" />'."\n";
1.68 ng 4283:
1.485 albertel 4284: my $options =
4285: '<label><input type="radio" name="vProb" value="no" checked="checked" /> '.&mt('no').' </label>'."\n".
4286: '<label><input type="radio" name="vProb" value="yes" /> '.&mt('yes').' </label>'."<br />\n";
1.539 riegler 4287: $result.=' <b>'.&mt('View Problem Text').': </b>'.$options;
1.485 albertel 4288:
4289: $options =
4290: '<label><input type="radio" name="lastSub" value="none" /> '.&mt('none').' </label>'."\n".
4291: '<label><input type="radio" name="lastSub" value="datesub" checked="checked" /> '.&mt('by dates and submissions').'</label>'."\n".
4292: '<label><input type="radio" name="lastSub" value="all" /> '.&mt('all details').' </label>'."\n";
1.539 riegler 4293: $result.=' <b>'.&mt('Submissions').': </b>'.$options;
1.432 banghart 4294:
4295: $result.=&build_section_inputs();
1.442 banghart 4296: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
4297: $result.='<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.72 ng 4298: '<input type="hidden" name="command" value="displayPage" />'."\n".
1.418 albertel 4299: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 4300: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."<br />\n";
1.72 ng 4301:
1.539 riegler 4302: $result.=' <b>'.&mt('Use CODE').': </b> <input type="text" name="CODE" value="" /> <br />'."\n";
1.382 albertel 4303:
1.80 ng 4304: $result.=' <input type="button" '.
1.589 bisitz 4305: 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /><br />'."\n";
1.72 ng 4306:
1.68 ng 4307: $request->print($result);
4308:
1.485 albertel 4309: my $studentTable.=' <b>'.&mt('Select a student you wish to grade and then click on the Next button.').'</b><br />'.
1.484 albertel 4310: &Apache::loncommon::start_data_table().
4311: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 4312: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 4313: '<th>'.&nameUserString('header').'</th>'.
1.485 albertel 4314: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 4315: '<th>'.&nameUserString('header').'</th>'.
4316: &Apache::loncommon::end_data_table_header_row();
1.68 ng 4317:
1.76 ng 4318: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.68 ng 4319: my $ptr = 1;
1.294 albertel 4320: foreach my $student (sort
4321: {
4322: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
4323: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
4324: }
4325: return $a cmp $b;
4326: } (keys(%$fullname))) {
1.68 ng 4327: my ($uname,$udom) = split(/:/,$student);
1.484 albertel 4328: $studentTable.=($ptr%2==1 ? &Apache::loncommon::start_data_table_row()
4329: : '</td>');
1.126 ng 4330: $studentTable.='<td align="right">'.$ptr.' </td>';
1.288 albertel 4331: $studentTable.='<td> <label><input type="radio" name="student" value="'.$student.'" /> '
4332: .&nameUserString(undef,$$fullname{$student},$uname,$udom)."</label>\n";
1.484 albertel 4333: $studentTable.=
4334: ($ptr%2 == 0 ? '</td>'.&Apache::loncommon::end_data_table_row()
4335: : '');
1.68 ng 4336: $ptr++;
4337: }
1.484 albertel 4338: if ($ptr%2 == 0) {
4339: $studentTable.='</td><td> </td><td> </td>'.
4340: &Apache::loncommon::end_data_table_row();
4341: }
4342: $studentTable.=&Apache::loncommon::end_data_table()."\n";
1.126 ng 4343: $studentTable.='<input type="button" '.
1.589 bisitz 4344: 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /></form>'."\n";
1.68 ng 4345:
1.324 albertel 4346: $studentTable.=&show_grading_menu_form($symb);
1.68 ng 4347: $request->print($studentTable);
4348:
4349: return '';
4350: }
4351:
4352: sub getSymbMap {
1.582 raeburn 4353: my ($map_error) = @_;
1.132 bowersj2 4354: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 4355: unless (ref($navmap)) {
4356: if (ref($map_error)) {
4357: $$map_error = 'navmap';
4358: }
4359: return;
4360: }
1.68 ng 4361: my %symbx = ();
4362: my @titles = ();
1.117 bowersj2 4363: my $minder = 0;
4364:
4365: # Gather every sequence that has problems.
1.240 albertel 4366: my @sequences = $navmap->retrieveResources(undef, sub { shift->is_map(); },
4367: 1,0,1);
1.117 bowersj2 4368: for my $sequence ($navmap->getById('0.0'), @sequences) {
1.241 albertel 4369: if ($navmap->hasResource($sequence, sub { shift->is_problem(); }, 0) ) {
1.381 albertel 4370: my $title = $minder.'.'.
4371: &HTML::Entities::encode($sequence->compTitle(),'"\'&');
4372: push(@titles, $title); # minder in case two titles are identical
4373: $symbx{$title} = &HTML::Entities::encode($sequence->symb(),'"\'&');
1.117 bowersj2 4374: $minder++;
1.241 albertel 4375: }
1.68 ng 4376: }
4377: return \@titles,\%symbx;
4378: }
4379:
1.72 ng 4380: #
4381: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68 ng 4382: sub displayPage {
4383: my ($request) = shift;
4384:
1.324 albertel 4385: my ($symb) = &get_symb($request);
1.257 albertel 4386: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4387: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4388: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
4389: my $pageTitle = $env{'form.page'};
1.103 albertel 4390: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 4391: my ($uname,$udom) = split(/:/,$env{'form.student'});
4392: my $usec=$classlist->{$env{'form.student'}}[5];
1.168 albertel 4393:
4394: #need to make sure we have the correct data for later EXT calls,
4395: #thus invalidate the cache
4396: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 4397: $env{'course.'.$env{'request.course.id'}.'.num'},
4398: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 4399: &Apache::lonnet::clear_EXT_cache_status();
4400:
1.103 albertel 4401: if (!&canview($usec)) {
1.485 albertel 4402: $request->print('<span class="LC_warning">'.&mt('Unable to view requested student. ([_1])',$env{'form.student'}).'</span>');
1.324 albertel 4403: $request->print(&show_grading_menu_form($symb));
1.103 albertel 4404: return;
4405: }
1.398 albertel 4406: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.485 albertel 4407: $result.='<h3> '.&mt('Student: [_1]',&nameUserString(undef,$$fullname{$env{'form.student'}},$uname,$udom)).
1.129 ng 4408: '</h3>'."\n";
1.500 albertel 4409: $env{'form.CODE'} = uc($env{'form.CODE'});
1.501 foxr 4410: if (&Apache::lonnet::validCODE(uc($env{'form.CODE'}))) {
1.485 albertel 4411: $result.='<h3> '.&mt('CODE: [_1]',$env{'form.CODE'}).'</h3>'."\n";
1.382 albertel 4412: } else {
4413: delete($env{'form.CODE'});
4414: }
1.71 ng 4415: &sub_page_js($request);
4416: $request->print($result);
4417:
1.132 bowersj2 4418: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 4419: unless (ref($navmap)) {
4420: $request->print(&navmap_errormsg());
4421: $request->print(&show_grading_menu_form($symb));
4422: return;
4423: }
1.257 albertel 4424: my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($env{'form.page'});
1.68 ng 4425: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 4426: if (!$map) {
1.485 albertel 4427: $request->print('<span class="LC_warning">'.&mt('Unable to view requested sequence. ([_1])',$resUrl).'</span>');
1.324 albertel 4428: $request->print(&show_grading_menu_form($symb));
1.288 albertel 4429: return;
4430: }
1.68 ng 4431: my $iterator = $navmap->getIterator($map->map_start(),
4432: $map->map_finish());
4433:
1.71 ng 4434: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72 ng 4435: '<input type="hidden" name="command" value="gradeByPage" />'."\n".
1.257 albertel 4436: '<input type="hidden" name="fullname" value="'.$$fullname{$env{'form.student'}}.'" />'."\n".
4437: '<input type="hidden" name="student" value="'.$env{'form.student'}.'" />'."\n".
1.72 ng 4438: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
1.257 albertel 4439: '<input type="hidden" name="title" value="'.$env{'form.title'}.'" />'."\n".
1.418 albertel 4440: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.125 ng 4441: '<input type="hidden" name="overRideScore" value="no" />'."\n".
1.257 albertel 4442: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n";
1.71 ng 4443:
1.382 albertel 4444: if (defined($env{'form.CODE'})) {
4445: $studentTable.=
4446: '<input type="hidden" name="CODE" value="'.$env{'form.CODE'}.'" />'."\n";
4447: }
1.381 albertel 4448: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 4449: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 4450:
1.485 albertel 4451: $studentTable.=' '.&mt('<b>Note:</b> Problems graded correct by the computer are marked with a [_1] symbol.',$checkIcon)."\n".
1.484 albertel 4452: &Apache::loncommon::start_data_table().
4453: &Apache::loncommon::start_data_table_header_row().
4454: '<th align="center"> Prob. </th>'.
1.485 albertel 4455: '<th> '.($env{'form.vProb'} eq 'no' ? &mt('Title') : &mt('Problem Text')).'/'.&mt('Grade').'</th>'.
1.484 albertel 4456: &Apache::loncommon::end_data_table_header_row();
1.71 ng 4457:
1.329 albertel 4458: &Apache::lonxml::clear_problem_counter();
1.196 albertel 4459: my ($depth,$question,$prob) = (1,1,1);
1.68 ng 4460: $iterator->next(); # skip the first BEGIN_MAP
4461: my $curRes = $iterator->next(); # for "current resource"
1.101 albertel 4462: while ($depth > 0) {
1.68 ng 4463: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4464: if($curRes == $iterator->END_MAP) { $depth--; }
1.68 ng 4465:
1.385 albertel 4466: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4467: my $parts = $curRes->parts();
1.68 ng 4468: my $title = $curRes->compTitle();
1.71 ng 4469: my $symbx = $curRes->symb();
1.484 albertel 4470: $studentTable.=
4471: &Apache::loncommon::start_data_table_row().
4472: '<td align="center" valign="top" >'.$prob.
1.485 albertel 4473: (scalar(@{$parts}) == 1 ? ''
4474: : '<br />('.&mt('[_1] parts)',
4475: scalar(@{$parts}))
4476: ).
4477: '</td>';
1.71 ng 4478: $studentTable.='<td valign="top">';
1.382 albertel 4479: my %form = ('CODE' => $env{'form.CODE'},);
1.257 albertel 4480: if ($env{'form.vProb'} eq 'yes' ) {
1.144 albertel 4481: $studentTable.=&show_problem($request,$symbx,$uname,$udom,1,
1.383 albertel 4482: undef,'both',\%form);
1.71 ng 4483: } else {
1.382 albertel 4484: my $companswer = &Apache::loncommon::get_student_answers($symbx,$uname,$udom,$env{'request.course.id'},%form);
1.80 ng 4485: $companswer =~ s|<form(.*?)>||g;
4486: $companswer =~ s|</form>||g;
1.71 ng 4487: # while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
1.116 ng 4488: # $companswer =~ s/$1/ /ms;
1.326 albertel 4489: # $request->print('match='.$1."<br />\n");
1.71 ng 4490: # }
1.116 ng 4491: # $companswer =~ s|<table border=\"1\">|<table border=\"0\">|g;
1.539 riegler 4492: $studentTable.=' <b>'.$title.'</b> <br /> <b>'.&mt('Correct answer').':</b><br />'.$companswer;
1.71 ng 4493: }
4494:
1.257 albertel 4495: my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
1.125 ng 4496:
1.257 albertel 4497: if ($env{'form.lastSub'} eq 'datesub') {
1.71 ng 4498: if ($record{'version'} eq '') {
1.485 albertel 4499: $studentTable.='<br /> <span class="LC_warning">'.&mt('No recorded submission for this problem.').'</span><br />';
1.71 ng 4500: } else {
1.116 ng 4501: my %responseType = ();
4502: foreach my $partid (@{$parts}) {
1.147 albertel 4503: my @responseIds =$curRes->responseIds($partid);
4504: my @responseType =$curRes->responseType($partid);
4505: my %responseIds;
4506: for (my $i=0;$i<=$#responseIds;$i++) {
4507: $responseIds{$responseIds[$i]}=$responseType[$i];
4508: }
4509: $responseType{$partid} = \%responseIds;
1.116 ng 4510: }
1.148 albertel 4511: $studentTable.= &displaySubByDates($symbx,\%record,$parts,\%responseType,$checkIcon,$uname,$udom);
1.147 albertel 4512:
1.71 ng 4513: }
1.257 albertel 4514: } elsif ($env{'form.lastSub'} eq 'all') {
4515: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.71 ng 4516: $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
1.257 albertel 4517: $env{'request.course.id'},
1.71 ng 4518: '','.submission');
4519:
4520: }
1.103 albertel 4521: if (&canmodify($usec)) {
1.585 bisitz 4522: $studentTable.=&gradeBox_start();
1.103 albertel 4523: foreach my $partid (@{$parts}) {
4524: $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
4525: $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
4526: $question++;
4527: }
1.585 bisitz 4528: $studentTable.=&gradeBox_end();
1.196 albertel 4529: $prob++;
1.71 ng 4530: }
4531: $studentTable.='</td></tr>';
1.68 ng 4532:
1.103 albertel 4533: }
1.68 ng 4534: $curRes = $iterator->next();
4535: }
4536:
1.589 bisitz 4537: $studentTable.=
4538: '</table>'."\n".
4539: '<input type="button" value="'.&mt('Save').'" '.
4540: 'onclick="javascript:checkSubmitPage(this.form,'.$question.');" />'.
4541: '</form>'."\n";
1.324 albertel 4542: $studentTable.=&show_grading_menu_form($symb);
1.71 ng 4543: $request->print($studentTable);
4544:
4545: return '';
1.119 ng 4546: }
4547:
4548: sub displaySubByDates {
1.148 albertel 4549: my ($symb,$record,$parts,$responseType,$checkIcon,$uname,$udom) = @_;
1.224 albertel 4550: my $isCODE=0;
1.335 albertel 4551: my $isTask = ($symb =~/\.task$/);
1.224 albertel 4552: if (exists($record->{'resource.CODE'})) { $isCODE=1; }
1.467 albertel 4553: my $studentTable=&Apache::loncommon::start_data_table().
4554: &Apache::loncommon::start_data_table_header_row().
4555: '<th>'.&mt('Date/Time').'</th>'.
4556: ($isCODE?'<th>'.&mt('CODE').'</th>':'').
4557: '<th>'.&mt('Submission').'</th>'.
4558: '<th>'.&mt('Status').'</th>'.
4559: &Apache::loncommon::end_data_table_header_row();
1.119 ng 4560: my ($version);
4561: my %mark;
1.148 albertel 4562: my %orders;
1.119 ng 4563: $mark{'correct_by_student'} = $checkIcon;
1.147 albertel 4564: if (!exists($$record{'1:timestamp'})) {
1.539 riegler 4565: return '<br /> <span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br />';
1.147 albertel 4566: }
1.335 albertel 4567:
4568: my $interaction;
1.525 raeburn 4569: my $no_increment = 1;
1.119 ng 4570: for ($version=1;$version<=$$record{'version'};$version++) {
1.467 albertel 4571: my $timestamp =
4572: &Apache::lonlocal::locallocaltime($$record{$version.':timestamp'});
1.335 albertel 4573: if (exists($$record{$version.':resource.0.version'})) {
4574: $interaction = $$record{$version.':resource.0.version'};
4575: }
4576:
4577: my $where = ($isTask ? "$version:resource.$interaction"
4578: : "$version:resource");
1.467 albertel 4579: $studentTable.=&Apache::loncommon::start_data_table_row().
4580: '<td>'.$timestamp.'</td>';
1.224 albertel 4581: if ($isCODE) {
4582: $studentTable.='<td>'.$record->{$version.':resource.CODE'}.'</td>';
4583: }
1.119 ng 4584: my @versionKeys = split(/\:/,$$record{$version.':keys'});
4585: my @displaySub = ();
4586: foreach my $partid (@{$parts}) {
1.335 albertel 4587: my @matchKey = ($isTask ? sort(grep /^resource\.\d+\.\Q$partid\E\.award$/,@versionKeys)
4588: : sort(grep /^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys));
4589:
4590:
1.122 ng 4591: # next if ($$record{"$version:resource.$partid.solved"} eq '');
1.324 albertel 4592: my $display_part=&get_display_part($partid,$symb);
1.147 albertel 4593: foreach my $matchKey (@matchKey) {
1.198 albertel 4594: if (exists($$record{$version.':'.$matchKey}) &&
4595: $$record{$version.':'.$matchKey} ne '') {
1.335 albertel 4596:
4597: my ($responseId)= ($isTask ? ($matchKey=~ /^resource\.(.*?)\.\Q$partid\E\.award$/)
4598: : ($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/));
1.577 bisitz 4599: $displaySub[0].='<span class="LC_nobreak"';
4600: $displaySub[0].='<b>'.&mt('Part: [_1]',$display_part).'</b>'
4601: .' <span class="LC_internal_info">'
4602: .'('.&mt('Part ID: [_1]',$responseId).')'
4603: .'</span>'
4604: .' <b>';
1.335 albertel 4605: if ($$record{"$where.$partid.tries"} eq '') {
1.577 bisitz 4606: $displaySub[0].=&mt('Trial not counted');
1.147 albertel 4607: } else {
1.577 bisitz 4608: $displaySub[0].=&mt('Trial: [_1]',
1.467 albertel 4609: $$record{"$where.$partid.tries"});
1.147 albertel 4610: }
1.335 albertel 4611: my $responseType=($isTask ? 'Task'
4612: : $responseType->{$partid}->{$responseId});
1.148 albertel 4613: if (!exists($orders{$partid})) { $orders{$partid}={}; }
4614: if (!exists($orders{$partid}->{$responseId})) {
4615: $orders{$partid}->{$responseId}=
1.525 raeburn 4616: &get_order($partid,$responseId,$symb,$uname,$udom,
4617: $no_increment);
1.148 albertel 4618: }
1.577 bisitz 4619: $displaySub[0].='</b></span>'; # /nobreak
4620: $displaySub[0].=' '.
1.336 albertel 4621: &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:",$uname,$udom).'<br />';
1.147 albertel 4622: }
4623: }
1.335 albertel 4624: if (exists($$record{"$where.$partid.checkedin"})) {
1.485 albertel 4625: $displaySub[1].=&mt('Checked in by [_1] into slot [_2]',
4626: $$record{"$where.$partid.checkedin"},
4627: $$record{"$where.$partid.checkedin.slot"}).
4628: '<br />';
1.335 albertel 4629: }
4630: if (exists $$record{"$where.$partid.award"}) {
1.485 albertel 4631: $displaySub[1].='<b>'.&mt('Part:').'</b> '.$display_part.' '.
1.335 albertel 4632: lc($$record{"$where.$partid.award"}).' '.
4633: $mark{$$record{"$where.$partid.solved"}}.
1.147 albertel 4634: '<br />';
4635: }
1.335 albertel 4636: if (exists $$record{"$where.$partid.regrader"}) {
4637: $displaySub[2].=$$record{"$where.$partid.regrader"}.
4638: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
4639: } elsif ($$record{"$version:resource.$partid.regrader"} =~ /\S/) {
4640: $displaySub[2].=
4641: $$record{"$version:resource.$partid.regrader"}.
1.207 albertel 4642: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
1.147 albertel 4643: }
4644: }
4645: # needed because old essay regrader has not parts info
4646: if (exists $$record{"$version:resource.regrader"}) {
4647: $displaySub[2].=$$record{"$version:resource.regrader"};
4648: }
4649: $studentTable.='<td>'.$displaySub[0].' </td><td>'.$displaySub[1];
4650: if ($displaySub[2]) {
1.467 albertel 4651: $studentTable.=&mt('Manually graded by [_1]',$displaySub[2]);
1.147 albertel 4652: }
1.467 albertel 4653: $studentTable.=' </td>'.
4654: &Apache::loncommon::end_data_table_row();
1.119 ng 4655: }
1.467 albertel 4656: $studentTable.=&Apache::loncommon::end_data_table();
1.119 ng 4657: return $studentTable;
1.71 ng 4658: }
4659:
4660: sub updateGradeByPage {
4661: my ($request) = shift;
4662:
1.257 albertel 4663: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4664: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4665: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
4666: my $pageTitle = $env{'form.page'};
1.103 albertel 4667: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 4668: my ($uname,$udom) = split(/:/,$env{'form.student'});
4669: my $usec=$classlist->{$env{'form.student'}}[5];
1.103 albertel 4670: if (!&canmodify($usec)) {
1.526 raeburn 4671: $request->print('<span class="LC_warning">'.&mt('Unable to modify requested student ([_1])',$env{'form.student'}).'</span>');
1.324 albertel 4672: $request->print(&show_grading_menu_form($env{'form.symb'}));
1.103 albertel 4673: return;
4674: }
1.398 albertel 4675: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.526 raeburn 4676: $result.='<h3> '.&mt('Student: ').&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
1.129 ng 4677: '</h3>'."\n";
1.70 ng 4678:
1.68 ng 4679: $request->print($result);
4680:
1.582 raeburn 4681:
1.132 bowersj2 4682: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 4683: unless (ref($navmap)) {
4684: $request->print(&navmap_errormsg());
4685: return;
4686: }
1.257 albertel 4687: my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $env{'form.page'});
1.71 ng 4688: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 4689: if (!$map) {
1.527 raeburn 4690: $request->print('<span class="LC_warning">'.&mt('Unable to grade requested sequence ([_1]).',$resUrl).'</span>');
1.324 albertel 4691: my ($symb)=&get_symb($request);
4692: $request->print(&show_grading_menu_form($symb));
1.288 albertel 4693: return;
4694: }
1.71 ng 4695: my $iterator = $navmap->getIterator($map->map_start(),
4696: $map->map_finish());
1.70 ng 4697:
1.484 albertel 4698: my $studentTable=
4699: &Apache::loncommon::start_data_table().
4700: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 4701: '<th align="center"> '.&mt('Prob.').' </th>'.
4702: '<th> '.&mt('Title').' </th>'.
4703: '<th> '.&mt('Previous Score').' </th>'.
4704: '<th> '.&mt('New Score').' </th>'.
1.484 albertel 4705: &Apache::loncommon::end_data_table_header_row();
1.71 ng 4706:
4707: $iterator->next(); # skip the first BEGIN_MAP
4708: my $curRes = $iterator->next(); # for "current resource"
1.196 albertel 4709: my ($depth,$question,$prob,$changeflag)= (1,1,1,0);
1.101 albertel 4710: while ($depth > 0) {
1.71 ng 4711: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4712: if($curRes == $iterator->END_MAP) { $depth--; }
1.71 ng 4713:
1.385 albertel 4714: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4715: my $parts = $curRes->parts();
1.71 ng 4716: my $title = $curRes->compTitle();
4717: my $symbx = $curRes->symb();
1.484 albertel 4718: $studentTable.=
4719: &Apache::loncommon::start_data_table_row().
4720: '<td align="center" valign="top" >'.$prob.
1.485 albertel 4721: (scalar(@{$parts}) == 1 ? ''
1.526 raeburn 4722: : '<br />('.&mt('[quant,_1, part]',scalar(@{$parts}))
4723: .')').'</td>';
1.71 ng 4724: $studentTable.='<td valign="top"> <b>'.$title.'</b> </td>';
4725:
4726: my %newrecord=();
4727: my @displayPts=();
1.269 raeburn 4728: my %aggregate = ();
4729: my $aggregateflag = 0;
1.71 ng 4730: foreach my $partid (@{$parts}) {
1.257 albertel 4731: my $newpts = $env{'form.GD_BOX'.$question.'_'.$partid};
4732: my $oldpts = $env{'form.oldpts'.$question.'_'.$partid};
1.71 ng 4733:
1.257 albertel 4734: my $wgt = $env{'form.WGT'.$question.'_'.$partid} != 0 ?
4735: $env{'form.WGT'.$question.'_'.$partid} : 1;
1.71 ng 4736: my $partial = $newpts/$wgt;
4737: my $score;
4738: if ($partial > 0) {
4739: $score = 'correct_by_override';
1.125 ng 4740: } elsif ($newpts ne '') { #empty is taken as 0
1.71 ng 4741: $score = 'incorrect_by_override';
4742: }
1.257 albertel 4743: my $dropMenu = $env{'form.GD_SEL'.$question.'_'.$partid};
1.125 ng 4744: if ($dropMenu eq 'excused') {
1.71 ng 4745: $partial = '';
4746: $score = 'excused';
1.125 ng 4747: } elsif ($dropMenu eq 'reset status'
1.257 albertel 4748: && $env{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
1.125 ng 4749: $newrecord{'resource.'.$partid.'.tries'} = 0;
4750: $newrecord{'resource.'.$partid.'.solved'} = '';
4751: $newrecord{'resource.'.$partid.'.award'} = '';
4752: $newrecord{'resource.'.$partid.'.awarded'} = 0;
1.257 albertel 4753: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 4754: $changeflag++;
4755: $newpts = '';
1.269 raeburn 4756:
4757: my $aggtries = $env{'form.aggtries'.$question.'_'.$partid};
4758: my $totaltries = $env{'form.totaltries'.$question.'_'.$partid};
4759: my $solvedstatus = $env{'form.solved'.$question.'_'.$partid};
4760: if ($aggtries > 0) {
4761: &decrement_aggs($symbx,$partid,\%aggregate,$aggtries,$totaltries,$solvedstatus);
4762: $aggregateflag = 1;
4763: }
1.71 ng 4764: }
1.324 albertel 4765: my $display_part=&get_display_part($partid,$curRes->symb());
1.257 albertel 4766: my $oldstatus = $env{'form.solved'.$question.'_'.$partid};
1.526 raeburn 4767: $displayPts[0].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.71 ng 4768: (($oldstatus eq 'excused') ? 'excused' : $oldpts).
1.326 albertel 4769: ' <br />';
1.526 raeburn 4770: $displayPts[1].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.125 ng 4771: (($score eq 'excused') ? 'excused' : $newpts).
1.326 albertel 4772: ' <br />';
1.71 ng 4773: $question++;
1.380 albertel 4774: next if ($dropMenu eq 'reset status' || ($newpts eq $oldpts && $score ne 'excused'));
1.125 ng 4775:
1.71 ng 4776: $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
1.125 ng 4777: $newrecord{'resource.'.$partid.'.solved'} = $score if $score ne '';
1.257 albertel 4778: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}"
1.125 ng 4779: if (scalar(keys(%newrecord)) > 0);
1.71 ng 4780:
4781: $changeflag++;
4782: }
4783: if (scalar(keys(%newrecord)) > 0) {
1.382 albertel 4784: my %record =
4785: &Apache::lonnet::restore($symbx,$env{'request.course.id'},
4786: $udom,$uname);
4787:
4788: if (&Apache::lonnet::validCODE($env{'form.CODE'})) {
4789: $newrecord{'resource.CODE'} = $env{'form.CODE'};
4790: } elsif (&Apache::lonnet::validCODE($record{'resource.CODE'})) {
4791: $newrecord{'resource.CODE'} = '';
4792: }
1.257 albertel 4793: &Apache::lonnet::cstore(\%newrecord,$symbx,$env{'request.course.id'},
1.71 ng 4794: $udom,$uname);
1.382 albertel 4795: %record = &Apache::lonnet::restore($symbx,
4796: $env{'request.course.id'},
4797: $udom,$uname);
1.380 albertel 4798: &check_and_remove_from_queue($parts,\%record,undef,$symbx,
4799: $cdom,$cnum,$udom,$uname);
1.71 ng 4800: }
1.380 albertel 4801:
1.269 raeburn 4802: if ($aggregateflag) {
4803: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
4804: $env{'course.'.$env{'request.course.id'}.'.domain'},
4805: $env{'course.'.$env{'request.course.id'}.'.num'});
4806: }
1.125 ng 4807:
1.71 ng 4808: $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
4809: '<td valign="top">'.$displayPts[1].'</td>'.
1.484 albertel 4810: &Apache::loncommon::end_data_table_row();
1.68 ng 4811:
1.196 albertel 4812: $prob++;
1.68 ng 4813: }
1.71 ng 4814: $curRes = $iterator->next();
1.68 ng 4815: }
1.98 albertel 4816:
1.484 albertel 4817: $studentTable.=&Apache::loncommon::end_data_table();
1.324 albertel 4818: $studentTable.=&show_grading_menu_form($env{'form.symb'});
1.526 raeburn 4819: my $grademsg=($changeflag == 0 ? &mt('No score was changed or updated.') :
4820: &mt('The scores were changed for [quant,_1,problem].',
4821: $changeflag));
1.76 ng 4822: $request->print($grademsg.$studentTable);
1.68 ng 4823:
1.70 ng 4824: return '';
4825: }
4826:
1.72 ng 4827: #-------- end of section for handling grading by page/sequence ---------
4828: #
4829: #-------------------------------------------------------------------
4830:
1.581 www 4831: #-------------------- Bubblesheet (Scantron) Grading -------------------
1.75 albertel 4832: #
4833: #------ start of section for handling grading by page/sequence ---------
4834:
1.423 albertel 4835: =pod
4836:
4837: =head1 Bubble sheet grading routines
4838:
1.424 albertel 4839: For this documentation:
4840:
4841: 'scanline' refers to the full line of characters
4842: from the file that we are parsing that represents one entire sheet
4843:
4844: 'bubble line' refers to the data
4845: representing the line of bubbles that are on the physical bubble sheet
4846:
4847:
4848: The overall process is that a scanned in bubble sheet data is uploaded
4849: into a course. When a user wants to grade, they select a
4850: sequence/folder of resources, a file of bubble sheet info, and pick
4851: one of the predefined configurations for what each scanline looks
4852: like.
4853:
4854: Next each scanline is checked for any errors of either 'missing
1.435 foxr 4855: bubbles' (it's an error because it may have been mis-scanned
1.424 albertel 4856: because too light bubbling), 'double bubble' (each bubble line should
4857: have no more that one letter picked), invalid or duplicated CODE,
1.556 weissno 4858: invalid student/employee ID
1.424 albertel 4859:
4860: If the CODE option is used that determines the randomization of the
1.556 weissno 4861: homework problems, either way the student/employee ID is looked up into a
1.424 albertel 4862: username:domain.
4863:
4864: During the validation phase the instructor can choose to skip scanlines.
4865:
1.435 foxr 4866: After the validation phase, there are now 3 bubble sheet files
1.424 albertel 4867:
4868: scantron_original_filename (unmodified original file)
4869: scantron_corrected_filename (file where the corrected information has replaced the original information)
4870: scantron_skipped_filename (contains the exact text of scanlines that where skipped)
4871:
4872: Also there is a separate hash nohist_scantrondata that contains extra
4873: correction information that isn't representable in the bubble sheet
4874: file (see &scantron_getfile() for more information)
4875:
4876: After all scanlines are either valid, marked as valid or skipped, then
4877: foreach line foreach problem in the picked sequence, an ssi request is
4878: made that simulates a user submitting their selected letter(s) against
4879: the homework problem.
1.423 albertel 4880:
4881: =over 4
4882:
4883:
4884:
4885: =item defaultFormData
4886:
4887: Returns html hidden inputs used to hold context/default values.
4888:
4889: Arguments:
4890: $symb - $symb of the current resource
4891:
4892: =cut
1.422 foxr 4893:
1.81 albertel 4894: sub defaultFormData {
1.324 albertel 4895: my ($symb)=@_;
1.447 foxr 4896: return '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 4897: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
4898: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.81 albertel 4899: }
4900:
1.447 foxr 4901:
1.423 albertel 4902: =pod
4903:
4904: =item getSequenceDropDown
4905:
4906: Return html dropdown of possible sequences to grade
4907:
4908: Arguments:
1.582 raeburn 4909: $symb - $symb of the current resource
4910: $map_error - ref to scalar which will container error if
4911: $navmap object is unavailable in &getSymbMap().
1.423 albertel 4912:
4913: =cut
1.422 foxr 4914:
1.75 albertel 4915: sub getSequenceDropDown {
1.582 raeburn 4916: my ($symb,$map_error)=@_;
1.75 albertel 4917: my $result='<select name="selectpage">'."\n";
1.582 raeburn 4918: my ($titles,$symbx) = &getSymbMap($map_error);
4919: if (ref($map_error)) {
4920: return if ($$map_error);
4921: }
1.137 albertel 4922: my ($curpage)=&Apache::lonnet::decode_symb($symb);
1.75 albertel 4923: my $ctr=0;
4924: foreach (@$titles) {
4925: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
4926: $result.='<option value="'.$$symbx{$_}.'" '.
1.401 albertel 4927: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.75 albertel 4928: '>'.$showtitle.'</option>'."\n";
4929: $ctr++;
4930: }
4931: $result.= '</select>';
4932: return $result;
4933: }
4934:
1.495 albertel 4935: my %bubble_lines_per_response; # no. bubble lines for each response.
1.554 raeburn 4936: # key is zero-based index - 0, 1, 2 ...
1.495 albertel 4937:
4938: my %first_bubble_line; # First bubble line no. for each bubble.
4939:
1.509 raeburn 4940: my %subdivided_bubble_lines; # no. bubble lines for optionresponse,
4941: # matchresponse or rankresponse, where
4942: # an individual response can have multiple
4943: # lines
1.503 raeburn 4944:
4945: my %responsetype_per_response; # responsetype for each response
4946:
1.495 albertel 4947: # Save and restore the bubble lines array to the form env.
4948:
4949:
4950: sub save_bubble_lines {
4951: foreach my $line (keys(%bubble_lines_per_response)) {
4952: $env{"form.scantron.bubblelines.$line"} = $bubble_lines_per_response{$line};
4953: $env{"form.scantron.first_bubble_line.$line"} =
4954: $first_bubble_line{$line};
1.503 raeburn 4955: $env{"form.scantron.sub_bubblelines.$line"} =
4956: $subdivided_bubble_lines{$line};
4957: $env{"form.scantron.responsetype.$line"} =
4958: $responsetype_per_response{$line};
1.495 albertel 4959: }
4960: }
4961:
4962:
4963: sub restore_bubble_lines {
4964: my $line = 0;
4965: %bubble_lines_per_response = ();
4966: while ($env{"form.scantron.bubblelines.$line"}) {
4967: my $value = $env{"form.scantron.bubblelines.$line"};
4968: $bubble_lines_per_response{$line} = $value;
4969: $first_bubble_line{$line} =
4970: $env{"form.scantron.first_bubble_line.$line"};
1.503 raeburn 4971: $subdivided_bubble_lines{$line} =
4972: $env{"form.scantron.sub_bubblelines.$line"};
4973: $responsetype_per_response{$line} =
4974: $env{"form.scantron.responsetype.$line"};
1.495 albertel 4975: $line++;
4976: }
4977: }
4978:
4979: # Given the parsed scanline, get the response for
4980: # 'answer' number n:
4981:
4982: sub get_response_bubbles {
4983: my ($parsed_line, $response) = @_;
4984:
4985: my $bubble_line = $first_bubble_line{$response-1} +1;
4986: my $bubble_lines= $bubble_lines_per_response{$response-1};
4987:
4988: my $selected = "";
4989:
4990: for (my $bline = 0; $bline < $bubble_lines; $bline++) {
4991: $selected .= $$parsed_line{"scantron.$bubble_line.answer"}.":";
4992: $bubble_line++;
4993: }
4994: return $selected;
4995: }
1.423 albertel 4996:
4997: =pod
4998:
4999: =item scantron_filenames
5000:
5001: Returns a list of the scantron files in the current course
5002:
5003: =cut
1.422 foxr 5004:
1.202 albertel 5005: sub scantron_filenames {
1.257 albertel 5006: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5007: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
1.517 raeburn 5008: my $getpropath = 1;
1.157 albertel 5009: my @files=&Apache::lonnet::dirlist('userfiles',$cdom,$cname,
1.517 raeburn 5010: $getpropath);
1.202 albertel 5011: my @possiblenames;
1.201 albertel 5012: foreach my $filename (sort(@files)) {
1.157 albertel 5013: ($filename)=split(/&/,$filename);
5014: if ($filename!~/^scantron_orig_/) { next ; }
5015: $filename=~s/^scantron_orig_//;
1.202 albertel 5016: push(@possiblenames,$filename);
5017: }
5018: return @possiblenames;
5019: }
5020:
1.423 albertel 5021: =pod
5022:
5023: =item scantron_uploads
5024:
5025: Returns html drop-down list of scantron files in current course.
5026:
5027: Arguments:
5028: $file2grade - filename to set as selected in the dropdown
5029:
5030: =cut
1.422 foxr 5031:
1.202 albertel 5032: sub scantron_uploads {
1.209 ng 5033: my ($file2grade) = @_;
1.202 albertel 5034: my $result= '<select name="scantron_selectfile">';
5035: $result.="<option></option>";
5036: foreach my $filename (sort(&scantron_filenames())) {
1.401 albertel 5037: $result.="<option".($filename eq $file2grade ? ' selected="selected"':'').">$filename</option>\n";
1.81 albertel 5038: }
5039: $result.="</select>";
5040: return $result;
5041: }
5042:
1.423 albertel 5043: =pod
5044:
5045: =item scantron_scantab
5046:
5047: Returns html drop down of the scantron formats in the scantronformat.tab
5048: file.
5049:
5050: =cut
1.422 foxr 5051:
1.82 albertel 5052: sub scantron_scantab {
5053: my $result='<select name="scantron_format">'."\n";
1.191 albertel 5054: $result.='<option></option>'."\n";
1.518 raeburn 5055: my @lines = &get_scantronformat_file();
5056: if (@lines > 0) {
5057: foreach my $line (@lines) {
5058: next if (($line =~ /^\#/) || ($line eq ''));
5059: my ($name,$descrip)=split(/:/,$line);
5060: $result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
5061: }
1.82 albertel 5062: }
5063: $result.='</select>'."\n";
1.518 raeburn 5064: return $result;
5065: }
5066:
5067: =pod
5068:
5069: =item get_scantronformat_file
5070:
5071: Returns an array containing lines from the scantron format file for
5072: the domain of the course.
5073:
5074: If a url for a custom.tab file is listed in domain's configuration.db,
5075: lines are from this file.
5076:
5077: Otherwise, if a default.tab has been published in RES space by the
5078: domainconfig user, lines are from this file.
5079:
5080: Otherwise, fall back to getting lines from the legacy file on the
1.519 raeburn 5081: local server: /home/httpd/lonTabs/default_scantronformat.tab
1.82 albertel 5082:
1.518 raeburn 5083: =cut
5084:
5085: sub get_scantronformat_file {
5086: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
5087: my %domconfig = &Apache::lonnet::get_dom('configuration',['scantron'],$cdom);
5088: my $gottab = 0;
5089: my @lines;
5090: if (ref($domconfig{'scantron'}) eq 'HASH') {
5091: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
5092: my $formatfile = &Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.$domconfig{'scantron'}{'scantronformat'});
5093: if ($formatfile ne '-1') {
5094: @lines = split("\n",$formatfile,-1);
5095: $gottab = 1;
5096: }
5097: }
5098: }
5099: if (!$gottab) {
5100: my $confname = $cdom.'-domainconfig';
5101: my $default = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res/'.$cdom.'/'.$confname.'/default.tab';
5102: my $formatfile = &Apache::lonnet::getfile($default);
5103: if ($formatfile ne '-1') {
5104: @lines = split("\n",$formatfile,-1);
5105: $gottab = 1;
5106: }
5107: }
5108: if (!$gottab) {
1.519 raeburn 5109: my @domains = &Apache::lonnet::current_machine_domains();
5110: if (grep(/^\Q$cdom\E$/,@domains)) {
5111: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
5112: @lines = <$fh>;
5113: close($fh);
5114: } else {
5115: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab');
5116: @lines = <$fh>;
5117: close($fh);
5118: }
1.518 raeburn 5119: }
5120: return @lines;
1.82 albertel 5121: }
5122:
1.423 albertel 5123: =pod
5124:
5125: =item scantron_CODElist
5126:
5127: Returns html drop down of the saved CODE lists from current course,
5128: generated from earlier printings.
5129:
5130: =cut
1.422 foxr 5131:
1.186 albertel 5132: sub scantron_CODElist {
1.257 albertel 5133: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5134: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.186 albertel 5135: my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
5136: my $namechoice='<option></option>';
1.225 albertel 5137: foreach my $name (sort {uc($a) cmp uc($b)} @names) {
1.191 albertel 5138: if ($name =~ /^error: 2 /) { next; }
1.278 albertel 5139: if ($name =~ /^type\0/) { next; }
1.186 albertel 5140: $namechoice.='<option value="'.$name.'">'.$name.'</option>';
5141: }
5142: $namechoice='<select name="scantron_CODElist">'.$namechoice.'</select>';
5143: return $namechoice;
5144: }
5145:
1.423 albertel 5146: =pod
5147:
5148: =item scantron_CODEunique
5149:
5150: Returns the html for "Each CODE to be used once" radio.
5151:
5152: =cut
1.422 foxr 5153:
1.186 albertel 5154: sub scantron_CODEunique {
1.532 bisitz 5155: my $result='<span class="LC_nobreak">
1.272 albertel 5156: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 5157: value="yes" checked="checked" />'.&mt('Yes').' </label>
1.381 albertel 5158: </span>
1.532 bisitz 5159: <span class="LC_nobreak">
1.272 albertel 5160: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 5161: value="no" />'.&mt('No').' </label>
1.381 albertel 5162: </span>';
1.186 albertel 5163: return $result;
5164: }
1.423 albertel 5165:
5166: =pod
5167:
5168: =item scantron_selectphase
5169:
5170: Generates the initial screen to start the bubble sheet process.
5171: Allows for - starting a grading run.
1.424 albertel 5172: - downloading existing scan data (original, corrected
1.423 albertel 5173: or skipped info)
5174:
5175: - uploading new scan data
5176:
5177: Arguments:
5178: $r - The Apache request object
5179: $file2grade - name of the file that contain the scanned data to score
5180:
5181: =cut
1.186 albertel 5182:
1.75 albertel 5183: sub scantron_selectphase {
1.209 ng 5184: my ($r,$file2grade) = @_;
1.324 albertel 5185: my ($symb)=&get_symb($r);
1.75 albertel 5186: if (!$symb) {return '';}
1.582 raeburn 5187: my $map_error;
5188: my $sequence_selector=&getSequenceDropDown($symb,\$map_error);
5189: if ($map_error) {
5190: $r->print('<br />'.&navmap_errormsg().'<br />');
5191: return;
5192: }
1.324 albertel 5193: my $default_form_data=&defaultFormData($symb);
5194: my $grading_menu_button=&show_grading_menu_form($symb);
1.209 ng 5195: my $file_selector=&scantron_uploads($file2grade);
1.82 albertel 5196: my $format_selector=&scantron_scantab();
1.186 albertel 5197: my $CODE_selector=&scantron_CODElist();
5198: my $CODE_unique=&scantron_CODEunique();
1.75 albertel 5199: my $result;
1.422 foxr 5200:
1.513 foxr 5201: $ssi_error = 0;
5202:
1.422 foxr 5203: # Chunk of form to prompt for a file to grade and how:
5204:
1.489 albertel 5205: $result.= '
5206: <br />
5207: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantron_process">
5208: <input type="hidden" name="command" value="scantron_warning" />
5209: '.$default_form_data.'
5210: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5211: '.&Apache::loncommon::start_data_table_header_row().'
5212: <th colspan="2">
1.492 albertel 5213: '.&mt('Specify file and which Folder/Sequence to grade').'
1.489 albertel 5214: </th>
5215: '.&Apache::loncommon::end_data_table_header_row().'
5216: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5217: <td> '.&mt('Sequence to grade:').' </td><td> '.$sequence_selector.' </td>
1.489 albertel 5218: '.&Apache::loncommon::end_data_table_row().'
5219: '.&Apache::loncommon::start_data_table_row().'
1.572 www 5220: <td> '.&mt('Filename of bubblesheet data file:').' </td><td> '.$file_selector.' </td>
1.489 albertel 5221: '.&Apache::loncommon::end_data_table_row().'
5222: '.&Apache::loncommon::start_data_table_row().'
1.572 www 5223: <td> '.&mt('Format of bubblesheet data file:').' </td><td> '.$format_selector.' </td>
1.489 albertel 5224: '.&Apache::loncommon::end_data_table_row().'
5225: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5226: <td> '.&mt('Saved CODEs to validate against:').' </td><td> '.$CODE_selector.' </td>
1.489 albertel 5227: '.&Apache::loncommon::end_data_table_row().'
5228: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5229: <td> '.&mt('Each CODE is only to be used once:').'</td><td> '.$CODE_unique.' </td>
1.489 albertel 5230: '.&Apache::loncommon::end_data_table_row().'
5231: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5232: <td> '.&mt('Options:').' </td>
1.187 albertel 5233: <td>
1.492 albertel 5234: <label><input type="checkbox" name="scantron_options_redo" value="redo_skipped"/> '.&mt('Do only previously skipped records').'</label> <br />
5235: <label><input type="checkbox" name="scantron_options_ignore" value="ignore_corrections"/> '.&mt('Remove all existing corrections').'</label> <br />
5236: <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources when grading').'</label>
1.187 albertel 5237: </td>
1.489 albertel 5238: '.&Apache::loncommon::end_data_table_row().'
5239: '.&Apache::loncommon::start_data_table_row().'
1.174 albertel 5240: <td colspan="2">
1.572 www 5241: <input type="submit" value="'.&mt('Grading: Validate Bubblesheet Records').'" />
1.162 albertel 5242: </td>
1.489 albertel 5243: '.&Apache::loncommon::end_data_table_row().'
5244: '.&Apache::loncommon::end_data_table().'
5245: </form>
5246: ';
1.162 albertel 5247:
5248: $r->print($result);
5249:
1.257 albertel 5250: if (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) ||
5251: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.162 albertel 5252:
1.422 foxr 5253: # Chunk of form to prompt for a scantron file upload.
5254:
1.489 albertel 5255: $r->print('
5256: <br />
5257: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5258: '.&Apache::loncommon::start_data_table_header_row().'
5259: <th>
1.572 www 5260: '.&mt('Specify a bubblesheet data file to upload.').'
1.489 albertel 5261: </th>
5262: '.&Apache::loncommon::end_data_table_header_row().'
5263: '.&Apache::loncommon::start_data_table_row().'
1.162 albertel 5264: <td>
1.489 albertel 5265: ');
1.324 albertel 5266: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.257 albertel 5267: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
5268: my $cnum= $env{'course.'.$env{'request.course.id'}.'.num'};
1.492 albertel 5269: $r->print('
1.174 albertel 5270: <script type="text/javascript" language="javascript">
5271: function checkUpload(formname) {
5272: if (formname.upfile.value == "") {
1.492 albertel 5273: alert("'.&mt('Please use the browse button to select a file from your local directory.').'");
1.174 albertel 5274: return false;
5275: }
5276: formname.submit();
5277: }
5278: </script>
5279:
1.492 albertel 5280: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
5281: '.$default_form_data.'
5282: <input name="courseid" type="hidden" value="'.$cnum.'" />
5283: <input name="domainid" type="hidden" value="'.$cdom.'" />
5284: <input name="command" value="scantronupload_save" type="hidden" />
5285: '.&mt('File to upload: [_1]','<input type="file" name="upfile" size="50" />').'
1.174 albertel 5286: <br />
1.589 bisitz 5287: <input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
1.174 albertel 5288: </form>
1.492 albertel 5289: ');
1.162 albertel 5290:
1.489 albertel 5291: $r->print('
1.162 albertel 5292: </td>
1.489 albertel 5293: '.&Apache::loncommon::end_data_table_row().'
5294: '.&Apache::loncommon::end_data_table().'
5295: ');
1.162 albertel 5296: }
1.422 foxr 5297:
5298: # Chunk of the form that prompts to view a scoring office file,
5299: # corrected file, skipped records in a file.
5300:
1.489 albertel 5301: $r->print('
5302: <br />
5303: <form action="/adm/grades" name="scantron_download">
5304: '.$default_form_data.'
5305: <input type="hidden" name="command" value="scantron_download" />
5306: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5307: '.&Apache::loncommon::start_data_table_header_row().'
5308: <th>
1.492 albertel 5309: '.&mt('Download a scoring office file').'
1.489 albertel 5310: </th>
5311: '.&Apache::loncommon::end_data_table_header_row().'
5312: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5313: <td> '.&mt('Filename of scoring office file: [_1]',$file_selector).'
1.489 albertel 5314: <br />
1.492 albertel 5315: <input type="submit" value="'.&mt('Download: Show List of Associated Files').'" />
1.489 albertel 5316: '.&Apache::loncommon::end_data_table_row().'
5317: '.&Apache::loncommon::end_data_table().'
5318: </form>
5319: <br />
5320: ');
1.162 albertel 5321:
1.457 banghart 5322: &Apache::lonpickcode::code_list($r,2);
1.523 raeburn 5323:
1.528 raeburn 5324: $r->print('<br /><form method="post" name="checkscantron">'.
1.523 raeburn 5325: $default_form_data."\n".
5326: &Apache::loncommon::start_data_table('LC_scantron_action')."\n".
5327: &Apache::loncommon::start_data_table_header_row()."\n".
5328: '<th colspan="2">
1.572 www 5329: '.&mt('Review bubblesheet data and submissions for a previously graded folder/sequence')."\n".
1.523 raeburn 5330: '</th>'."\n".
5331: &Apache::loncommon::end_data_table_header_row()."\n".
5332: &Apache::loncommon::start_data_table_row()."\n".
5333: '<td> '.&mt('Graded folder/sequence:').' </td>'."\n".
5334: '<td> '.$sequence_selector.' </td>'.
5335: &Apache::loncommon::end_data_table_row()."\n".
5336: &Apache::loncommon::start_data_table_row()."\n".
5337: '<td> '.&mt('Filename of scoring office file:').' </td>'."\n".
5338: '<td> '.$file_selector.' </td>'."\n".
5339: &Apache::loncommon::end_data_table_row()."\n".
5340: &Apache::loncommon::start_data_table_row()."\n".
5341: '<td> '.&mt('Format of data file:').' </td>'."\n".
5342: '<td> '.$format_selector.' </td>'."\n".
5343: &Apache::loncommon::end_data_table_row()."\n".
5344: &Apache::loncommon::start_data_table_row()."\n".
1.557 raeburn 5345: '<td> '.&mt('Options').' </td>'."\n".
5346: '<td> <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources').'</label></td>'.
5347: &Apache::loncommon::end_data_table_row()."\n".
5348: &Apache::loncommon::start_data_table_row()."\n".
1.523 raeburn 5349: '<td colspan="2">'."\n".
5350: '<input type="hidden" name="command" value="checksubmissions" />'."\n".
1.575 www 5351: '<input type="submit" value="'.&mt('Review Bubblesheet Data and Submission Records').'" />'."\n".
1.523 raeburn 5352: '</td>'."\n".
5353: &Apache::loncommon::end_data_table_row()."\n".
5354: &Apache::loncommon::end_data_table()."\n".
5355: '</form><br />');
1.457 banghart 5356: $r->print($grading_menu_button);
1.523 raeburn 5357: return;
1.75 albertel 5358: }
5359:
1.423 albertel 5360: =pod
5361:
5362: =item get_scantron_config
5363:
5364: Parse and return the scantron configuration line selected as a
5365: hash of configuration file fields.
5366:
5367: Arguments:
5368: which - the name of the configuration to parse from the file.
5369:
5370:
5371: Returns:
5372: If the named configuration is not in the file, an empty
5373: hash is returned.
5374: a hash with the fields
5375: name - internal name for the this configuration setup
5376: description - text to display to operator that describes this config
5377: CODElocation - if 0 or the string 'none'
5378: - no CODE exists for this config
5379: if -1 || the string 'letter'
5380: - a CODE exists for this config and is
5381: a string of letters
5382: Unsupported value (but planned for future support)
5383: if a positive integer
5384: - The CODE exists as the first n items from
5385: the question section of the form
5386: if the string 'number'
5387: - The CODE exists for this config and is
5388: a string of numbers
5389: CODEstart - (only matter if a CODE exists) column in the line where
5390: the CODE starts
5391: CODElength - length of the CODE
1.573 bisitz 5392: IDstart - column where the student/employee ID starts
1.556 weissno 5393: IDlength - length of the student/employee ID info
1.423 albertel 5394: Qstart - column where the information from the bubbled
5395: 'questions' start
5396: Qlength - number of columns comprising a single bubble line from
5397: the sheet. (usually either 1 or 10)
1.424 albertel 5398: Qon - either a single character representing the character used
1.423 albertel 5399: to signal a bubble was chosen in the positional setup, or
5400: the string 'letter' if the letter of the chosen bubble is
5401: in the final, or 'number' if a number representing the
5402: chosen bubble is in the file (1->A 0->J)
1.424 albertel 5403: Qoff - the character used to represent that a bubble was
5404: left blank
1.423 albertel 5405: PaperID - if the scanning process generates a unique number for each
5406: sheet scanned the column that this ID number starts in
5407: PaperIDlength - number of columns that comprise the unique ID number
5408: for the sheet of paper
1.424 albertel 5409: FirstName - column that the first name starts in
1.423 albertel 5410: FirstNameLength - number of columns that the first name spans
5411:
5412: LastName - column that the last name starts in
5413: LastNameLength - number of columns that the last name spans
5414:
5415: =cut
1.422 foxr 5416:
1.82 albertel 5417: sub get_scantron_config {
5418: my ($which) = @_;
1.518 raeburn 5419: my @lines = &get_scantronformat_file();
1.82 albertel 5420: my %config;
1.157 albertel 5421: #FIXME probably should move to XML it has already gotten a bit much now
1.518 raeburn 5422: foreach my $line (@lines) {
1.82 albertel 5423: my ($name,$descrip)=split(/:/,$line);
5424: if ($name ne $which ) { next; }
5425: chomp($line);
5426: my @config=split(/:/,$line);
5427: $config{'name'}=$config[0];
5428: $config{'description'}=$config[1];
5429: $config{'CODElocation'}=$config[2];
5430: $config{'CODEstart'}=$config[3];
5431: $config{'CODElength'}=$config[4];
5432: $config{'IDstart'}=$config[5];
5433: $config{'IDlength'}=$config[6];
5434: $config{'Qstart'}=$config[7];
1.497 foxr 5435: $config{'Qlength'}=$config[8];
1.82 albertel 5436: $config{'Qoff'}=$config[9];
5437: $config{'Qon'}=$config[10];
1.157 albertel 5438: $config{'PaperID'}=$config[11];
5439: $config{'PaperIDlength'}=$config[12];
5440: $config{'FirstName'}=$config[13];
5441: $config{'FirstNamelength'}=$config[14];
5442: $config{'LastName'}=$config[15];
5443: $config{'LastNamelength'}=$config[16];
1.82 albertel 5444: last;
5445: }
5446: return %config;
5447: }
5448:
1.423 albertel 5449: =pod
5450:
5451: =item username_to_idmap
5452:
1.556 weissno 5453: creates a hash keyed by student/employee ID with values of the corresponding
1.423 albertel 5454: student username:domain.
5455:
5456: Arguments:
5457:
5458: $classlist - reference to the class list hash. This is a hash
5459: keyed by student name:domain whose elements are references
1.424 albertel 5460: to arrays containing various chunks of information
1.423 albertel 5461: about the student. (See loncoursedata for more info).
5462:
5463: Returns
5464: %idmap - the constructed hash
5465:
5466: =cut
5467:
1.82 albertel 5468: sub username_to_idmap {
5469: my ($classlist)= @_;
5470: my %idmap;
5471: foreach my $student (keys(%$classlist)) {
5472: $idmap{$classlist->{$student}->[&Apache::loncoursedata::CL_ID]}=
5473: $student;
5474: }
5475: return %idmap;
5476: }
1.423 albertel 5477:
5478: =pod
5479:
1.424 albertel 5480: =item scantron_fixup_scanline
1.423 albertel 5481:
5482: Process a requested correction to a scanline.
5483:
5484: Arguments:
5485: $scantron_config - hash from &get_scantron_config()
5486: $scan_data - hash of correction information
5487: (see &scantron_getfile())
5488: $line - existing scanline
5489: $whichline - line number of the passed in scanline
5490: $field - type of change to process
5491: (either
1.573 bisitz 5492: 'ID' -> correct the student/employee ID
1.423 albertel 5493: 'CODE' -> correct the CODE
5494: 'answer' -> fixup the submitted answers)
5495:
5496: $args - hash of additional info,
5497: - 'ID'
5498: 'newid' -> studentID to use in replacement
1.424 albertel 5499: of existing one
1.423 albertel 5500: - 'CODE'
5501: 'CODE_ignore_dup' - set to true if duplicates
5502: should be ignored.
5503: 'CODE' - is new code or 'use_unfound'
1.424 albertel 5504: if the existing unfound code should
1.423 albertel 5505: be used as is
5506: - 'answer'
5507: 'response' - new answer or 'none' if blank
5508: 'question' - the bubble line to change
1.503 raeburn 5509: 'questionnum' - the question identifier,
5510: may include subquestion.
1.423 albertel 5511:
5512: Returns:
5513: $line - the modified scanline
5514:
5515: Side effects:
5516: $scan_data - may be updated
5517:
5518: =cut
5519:
1.82 albertel 5520:
1.157 albertel 5521: sub scantron_fixup_scanline {
5522: my ($scantron_config,$scan_data,$line,$whichline,$field,$args)=@_;
5523: if ($field eq 'ID') {
5524: if (length($args->{'newid'}) > $$scantron_config{'IDlength'}) {
1.186 albertel 5525: return ($line,1,'New value too large');
1.157 albertel 5526: }
5527: if (length($args->{'newid'}) < $$scantron_config{'IDlength'}) {
5528: $args->{'newid'}=sprintf('%-'.$$scantron_config{'IDlength'}.'s',
5529: $args->{'newid'});
5530: }
5531: substr($line,$$scantron_config{'IDstart'}-1,
5532: $$scantron_config{'IDlength'})=$args->{'newid'};
5533: if ($args->{'newid'}=~/^\s*$/) {
5534: &scan_data($scan_data,"$whichline.user",
5535: $args->{'username'}.':'.$args->{'domain'});
5536: }
1.186 albertel 5537: } elsif ($field eq 'CODE') {
1.192 albertel 5538: if ($args->{'CODE_ignore_dup'}) {
5539: &scan_data($scan_data,"$whichline.CODE_ignore_dup",'1');
5540: }
5541: &scan_data($scan_data,"$whichline.useCODE",'1');
5542: if ($args->{'CODE'} ne 'use_unfound') {
1.191 albertel 5543: if (length($args->{'CODE'}) > $$scantron_config{'CODElength'}) {
5544: return ($line,1,'New CODE value too large');
5545: }
5546: if (length($args->{'CODE'}) < $$scantron_config{'CODElength'}) {
5547: $args->{'CODE'}=sprintf('%-'.$$scantron_config{'CODElength'}.'s',$args->{'CODE'});
5548: }
5549: substr($line,$$scantron_config{'CODEstart'}-1,
5550: $$scantron_config{'CODElength'})=$args->{'CODE'};
1.186 albertel 5551: }
1.157 albertel 5552: } elsif ($field eq 'answer') {
1.497 foxr 5553: my $length=$scantron_config->{'Qlength'};
1.157 albertel 5554: my $off=$scantron_config->{'Qoff'};
5555: my $on=$scantron_config->{'Qon'};
1.497 foxr 5556: my $answer=${off}x$length;
5557: if ($args->{'response'} eq 'none') {
5558: &scan_data($scan_data,
1.503 raeburn 5559: "$whichline.no_bubble.".$args->{'questionnum'},'1');
1.497 foxr 5560: } else {
5561: if ($on eq 'letter') {
5562: my @alphabet=('A'..'Z');
5563: $answer=$alphabet[$args->{'response'}];
5564: } elsif ($on eq 'number') {
5565: $answer=$args->{'response'}+1;
5566: if ($answer == 10) { $answer = '0'; }
1.274 albertel 5567: } else {
1.497 foxr 5568: substr($answer,$args->{'response'},1)=$on;
1.274 albertel 5569: }
1.497 foxr 5570: &scan_data($scan_data,
1.503 raeburn 5571: "$whichline.no_bubble.".$args->{'questionnum'},undef,'1');
1.157 albertel 5572: }
1.497 foxr 5573: my $where=$length*($args->{'question'}-1)+$scantron_config->{'Qstart'};
5574: substr($line,$where-1,$length)=$answer;
1.157 albertel 5575: }
5576: return $line;
5577: }
1.423 albertel 5578:
5579: =pod
5580:
5581: =item scan_data
5582:
5583: Edit or look up an item in the scan_data hash.
5584:
5585: Arguments:
5586: $scan_data - The hash (see scantron_getfile)
5587: $key - shorthand of the key to edit (actual key is
1.424 albertel 5588: scantronfilename_key).
1.423 albertel 5589: $data - New value of the hash entry.
5590: $delete - If true, the entry is removed from the hash.
5591:
5592: Returns:
5593: The new value of the hash table field (undefined if deleted).
5594:
5595: =cut
5596:
5597:
1.157 albertel 5598: sub scan_data {
5599: my ($scan_data,$key,$value,$delete)=@_;
1.257 albertel 5600: my $filename=$env{'form.scantron_selectfile'};
1.157 albertel 5601: if (defined($value)) {
5602: $scan_data->{$filename.'_'.$key} = $value;
5603: }
5604: if ($delete) { delete($scan_data->{$filename.'_'.$key}); }
5605: return $scan_data->{$filename.'_'.$key};
5606: }
1.423 albertel 5607:
1.495 albertel 5608: # ----- These first few routines are general use routines.----
5609:
5610: # Return the number of occurences of a pattern in a string.
5611:
5612: sub occurence_count {
5613: my ($string, $pattern) = @_;
5614:
5615: my @matches = ($string =~ /$pattern/g);
5616:
5617: return scalar(@matches);
5618: }
5619:
5620:
5621: # Take a string known to have digits and convert all the
5622: # digits into letters in the range J,A..I.
5623:
5624: sub digits_to_letters {
5625: my ($input) = @_;
5626:
5627: my @alphabet = ('J', 'A'..'I');
5628:
5629: my @input = split(//, $input);
5630: my $output ='';
5631: for (my $i = 0; $i < scalar(@input); $i++) {
5632: if ($input[$i] =~ /\d/) {
5633: $output .= $alphabet[$input[$i]];
5634: } else {
5635: $output .= $input[$i];
5636: }
5637: }
5638: return $output;
5639: }
5640:
1.423 albertel 5641: =pod
5642:
5643: =item scantron_parse_scanline
5644:
5645: Decodes a scanline from the selected scantron file
5646:
5647: Arguments:
5648: line - The text of the scantron file line to process
5649: whichline - Line number
5650: scantron_config - Hash describing the format of the scantron lines.
5651: scan_data - Hash of extra information about the scanline
5652: (see scantron_getfile for more information)
5653: just_header - True if should not process question answers but only
5654: the stuff to the left of the answers.
5655: Returns:
5656: Hash containing the result of parsing the scanline
5657:
5658: Keys are all proceeded by the string 'scantron.'
5659:
5660: CODE - the CODE in use for this scanline
5661: useCODE - 1 if the CODE is invalid but it usage has been forced
5662: by the operator
5663: CODE_ignore_dup - 1 if the CODE is a duplicated use when unique
5664: CODEs were selected, but the usage has been
5665: forced by the operator
1.556 weissno 5666: ID - student/employee ID
1.423 albertel 5667: PaperID - if used, the ID number printed on the sheet when the
5668: paper was scanned
5669: FirstName - first name from the sheet
5670: LastName - last name from the sheet
5671:
5672: if just_header was not true these key may also exist
5673:
1.447 foxr 5674: missingerror - a list of bubble ranges that are considered to be answers
5675: to a single question that don't have any bubbles filled in.
5676: Of the form questionnumber:firstbubblenumber:count.
5677: doubleerror - a list of bubble ranges that are considered to be answers
5678: to a single question that have more than one bubble filled in.
5679: Of the form questionnumber::firstbubblenumber:count
5680:
5681: In the above, count is the number of bubble responses in the
5682: input line needed to represent the possible answers to the question.
5683: e.g. a radioresponse with 15 choices in an answer sheet with 10 choices
5684: per line would have count = 2.
5685:
1.423 albertel 5686: maxquest - the number of the last bubble line that was parsed
5687:
5688: (<number> starts at 1)
5689: <number>.answer - zero or more letters representing the selected
5690: letters from the scanline for the bubble line
5691: <number>.
5692: if blank there was either no bubble or there where
5693: multiple bubbles, (consult the keys missingerror and
5694: doubleerror if this is an error condition)
5695:
5696: =cut
5697:
1.82 albertel 5698: sub scantron_parse_scanline {
1.423 albertel 5699: my ($line,$whichline,$scantron_config,$scan_data,$just_header)=@_;
1.470 foxr 5700:
1.82 albertel 5701: my %record;
1.550 raeburn 5702: my $lastpos = $env{'form.scantron_maxbubble'}*$$scantron_config{'Qlength'};
5703: my $questions=substr($line,$$scantron_config{'Qstart'}-1,$lastpos); # Answers
1.422 foxr 5704: my $data=substr($line,0,$$scantron_config{'Qstart'}-1); # earlier stuff
1.278 albertel 5705: if (!($$scantron_config{'CODElocation'} eq 0 ||
5706: $$scantron_config{'CODElocation'} eq 'none')) {
5707: if ($$scantron_config{'CODElocation'} < 0 ||
5708: $$scantron_config{'CODElocation'} eq 'letter' ||
5709: $$scantron_config{'CODElocation'} eq 'number') {
1.191 albertel 5710: $record{'scantron.CODE'}=substr($data,
5711: $$scantron_config{'CODEstart'}-1,
1.83 albertel 5712: $$scantron_config{'CODElength'});
1.191 albertel 5713: if (&scan_data($scan_data,"$whichline.useCODE")) {
5714: $record{'scantron.useCODE'}=1;
5715: }
1.192 albertel 5716: if (&scan_data($scan_data,"$whichline.CODE_ignore_dup")) {
5717: $record{'scantron.CODE_ignore_dup'}=1;
5718: }
1.82 albertel 5719: } else {
5720: #FIXME interpret first N questions
5721: }
5722: }
1.83 albertel 5723: $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
5724: $$scantron_config{'IDlength'});
1.157 albertel 5725: $record{'scantron.PaperID'}=
5726: substr($data,$$scantron_config{'PaperID'}-1,
5727: $$scantron_config{'PaperIDlength'});
5728: $record{'scantron.FirstName'}=
5729: substr($data,$$scantron_config{'FirstName'}-1,
5730: $$scantron_config{'FirstNamelength'});
5731: $record{'scantron.LastName'}=
5732: substr($data,$$scantron_config{'LastName'}-1,
5733: $$scantron_config{'LastNamelength'});
1.423 albertel 5734: if ($just_header) { return \%record; }
1.194 albertel 5735:
1.82 albertel 5736: my @alphabet=('A'..'Z');
5737: my $questnum=0;
1.447 foxr 5738: my $ansnum =1; # Multiple 'answer lines'/question.
5739:
1.470 foxr 5740: chomp($questions); # Get rid of any trailing \n.
5741: $questions =~ s/\r$//; # Get rid of trailing \r too (MAC or Win uploads).
5742: while (length($questions)) {
1.447 foxr 5743: my $answers_needed = $bubble_lines_per_response{$questnum};
1.503 raeburn 5744: my $answer_length = ($$scantron_config{'Qlength'} * $answers_needed)
5745: || 1;
5746: $questnum++;
5747: my $quest_id = $questnum;
5748: my $currentquest = substr($questions,0,$answer_length);
5749: $questions = substr($questions,$answer_length);
5750: if (length($currentquest) < $answer_length) { next; }
5751:
5752: if ($subdivided_bubble_lines{$questnum-1} =~ /,/) {
5753: my $subquestnum = 1;
5754: my $subquestions = $currentquest;
5755: my @subanswers_needed =
5756: split(/,/,$subdivided_bubble_lines{$questnum-1});
5757: foreach my $subans (@subanswers_needed) {
5758: my $subans_length =
5759: ($$scantron_config{'Qlength'} * $subans) || 1;
5760: my $currsubquest = substr($subquestions,0,$subans_length);
5761: $subquestions = substr($subquestions,$subans_length);
5762: $quest_id = "$questnum.$subquestnum";
5763: if (($$scantron_config{'Qon'} eq 'letter') ||
5764: ($$scantron_config{'Qon'} eq 'number')) {
5765: $ansnum = &scantron_validator_lettnum($ansnum,
5766: $questnum,$quest_id,$subans,$currsubquest,$whichline,
5767: \@alphabet,\%record,$scantron_config,$scan_data);
5768: } else {
5769: $ansnum = &scantron_validator_positional($ansnum,
5770: $questnum,$quest_id,$subans,$currsubquest,$whichline, \@alphabet,\%record,$scantron_config,$scan_data);
5771: }
5772: $subquestnum ++;
5773: }
5774: } else {
5775: if (($$scantron_config{'Qon'} eq 'letter') ||
5776: ($$scantron_config{'Qon'} eq 'number')) {
5777: $ansnum = &scantron_validator_lettnum($ansnum,$questnum,
5778: $quest_id,$answers_needed,$currentquest,$whichline,
5779: \@alphabet,\%record,$scantron_config,$scan_data);
5780: } else {
5781: $ansnum = &scantron_validator_positional($ansnum,$questnum,
5782: $quest_id,$answers_needed,$currentquest,$whichline,
5783: \@alphabet,\%record,$scantron_config,$scan_data);
5784: }
5785: }
5786: }
5787: $record{'scantron.maxquest'}=$questnum;
5788: return \%record;
5789: }
1.447 foxr 5790:
1.503 raeburn 5791: sub scantron_validator_lettnum {
5792: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,$whichline,
5793: $alphabet,$record,$scantron_config,$scan_data) = @_;
5794:
5795: # Qon 'letter' implies for each slot in currquest we have:
5796: # ? or * for doubles, a letter in A-Z for a bubble, and
5797: # about anything else (esp. a value of Qoff) for missing
5798: # bubbles.
5799: #
5800: # Qon 'number' implies each slot gives a digit that indexes the
5801: # bubbles filled, or Qoff, or a non-number for unbubbled lines,
5802: # and * or ? for double bubbles on a single line.
5803: #
1.447 foxr 5804:
1.503 raeburn 5805: my $matchon;
5806: if ($$scantron_config{'Qon'} eq 'letter') {
5807: $matchon = '[A-Z]';
5808: } elsif ($$scantron_config{'Qon'} eq 'number') {
5809: $matchon = '\d';
5810: }
5811: my $occurrences = 0;
5812: if (($responsetype_per_response{$questnum-1} eq 'essayresponse') ||
5813: ($responsetype_per_response{$questnum-1} eq 'formularesponse') ||
1.510 raeburn 5814: ($responsetype_per_response{$questnum-1} eq 'stringresponse') ||
5815: ($responsetype_per_response{$questnum-1} eq 'imageresponse') ||
5816: ($responsetype_per_response{$questnum-1} eq 'reactionresponse') ||
5817: ($responsetype_per_response{$questnum-1} eq 'organicresponse')) {
1.503 raeburn 5818: my @singlelines = split('',$currquest);
5819: foreach my $entry (@singlelines) {
5820: $occurrences = &occurence_count($entry,$matchon);
5821: if ($occurrences > 1) {
5822: last;
5823: }
5824: }
5825: } else {
5826: $occurrences = &occurence_count($currquest,$matchon);
5827: }
5828: if (($currquest =~ /\?/ || $currquest =~ /\*/) || ($occurrences > 1)) {
5829: push(@{$record->{'scantron.doubleerror'}},$quest_id);
5830: for (my $ans=0; $ans<$answers_needed; $ans++) {
5831: my $bubble = substr($currquest,$ans,1);
5832: if ($bubble =~ /$matchon/ ) {
5833: if ($$scantron_config{'Qon'} eq 'number') {
5834: if ($bubble == 0) {
5835: $bubble = 10;
5836: }
5837: $record->{"scantron.$ansnum.answer"} =
5838: $alphabet->[$bubble-1];
5839: } else {
5840: $record->{"scantron.$ansnum.answer"} = $bubble;
5841: }
5842: } else {
5843: $record->{"scantron.$ansnum.answer"}='';
5844: }
5845: $ansnum++;
5846: }
5847: } elsif (!defined($currquest)
5848: || (&occurence_count($currquest, $$scantron_config{'Qoff'}) == length($currquest))
5849: || (&occurence_count($currquest,$matchon) == 0)) {
5850: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
5851: $record->{"scantron.$ansnum.answer"}='';
5852: $ansnum++;
5853: }
5854: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
5855: push(@{$record->{'scantron.missingerror'}},$quest_id);
5856: }
5857: } else {
5858: if ($$scantron_config{'Qon'} eq 'number') {
5859: $currquest = &digits_to_letters($currquest);
5860: }
5861: for (my $ans=0; $ans<$answers_needed; $ans++) {
5862: my $bubble = substr($currquest,$ans,1);
5863: $record->{"scantron.$ansnum.answer"} = $bubble;
5864: $ansnum++;
5865: }
5866: }
5867: return $ansnum;
5868: }
1.447 foxr 5869:
1.503 raeburn 5870: sub scantron_validator_positional {
5871: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,
5872: $whichline,$alphabet,$record,$scantron_config,$scan_data) = @_;
1.447 foxr 5873:
1.503 raeburn 5874: # Otherwise there's a positional notation;
5875: # each bubble line requires Qlength items, and there are filled in
5876: # bubbles for each case where there 'Qon' characters.
5877: #
1.447 foxr 5878:
1.503 raeburn 5879: my @array=split($$scantron_config{'Qon'},$currquest,-1);
1.447 foxr 5880:
1.503 raeburn 5881: # If the split only gives us one element.. the full length of the
5882: # answer string, no bubbles are filled in:
1.447 foxr 5883:
1.507 raeburn 5884: if ($answers_needed eq '') {
5885: return;
5886: }
5887:
1.503 raeburn 5888: if (length($array[0]) eq $$scantron_config{'Qlength'}*$answers_needed) {
5889: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
5890: $record->{"scantron.$ansnum.answer"}='';
5891: $ansnum++;
5892: }
5893: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
5894: push(@{$record->{"scantron.missingerror"}},$quest_id);
5895: }
5896: } elsif (scalar(@array) == 2) {
5897: my $location = length($array[0]);
5898: my $line_num = int($location / $$scantron_config{'Qlength'});
5899: my $bubble = $alphabet->[$location % $$scantron_config{'Qlength'}];
5900: for (my $ans=0; $ans<$answers_needed; $ans++) {
5901: if ($ans eq $line_num) {
5902: $record->{"scantron.$ansnum.answer"} = $bubble;
5903: } else {
5904: $record->{"scantron.$ansnum.answer"} = ' ';
5905: }
5906: $ansnum++;
5907: }
5908: } else {
5909: # If there's more than one instance of a bubble character
5910: # That's a double bubble; with positional notation we can
5911: # record all the bubbles filled in as well as the
5912: # fact this response consists of multiple bubbles.
5913: #
5914: if (($responsetype_per_response{$questnum-1} eq 'essayresponse') ||
5915: ($responsetype_per_response{$questnum-1} eq 'formularesponse') ||
1.510 raeburn 5916: ($responsetype_per_response{$questnum-1} eq 'stringresponse') ||
5917: ($responsetype_per_response{$questnum-1} eq 'imageresponse') ||
5918: ($responsetype_per_response{$questnum-1} eq 'reactionresponse') ||
5919: ($responsetype_per_response{$questnum-1} eq 'organicresponse')) {
1.503 raeburn 5920: my $doubleerror = 0;
5921: while (($currquest >= $$scantron_config{'Qlength'}) &&
5922: (!$doubleerror)) {
5923: my $currline = substr($currquest,0,$$scantron_config{'Qlength'});
5924: $currquest = substr($currquest,$$scantron_config{'Qlength'});
5925: my @currarray = split($$scantron_config{'Qon'},$currline,-1);
5926: if (length(@currarray) > 2) {
5927: $doubleerror = 1;
5928: }
5929: }
5930: if ($doubleerror) {
5931: push(@{$record->{'scantron.doubleerror'}},$quest_id);
5932: }
5933: } else {
5934: push(@{$record->{'scantron.doubleerror'}},$quest_id);
5935: }
5936: my $item = $ansnum;
5937: for (my $ans=0; $ans<$answers_needed; $ans++) {
5938: $record->{"scantron.$item.answer"} = '';
5939: $item ++;
5940: }
1.447 foxr 5941:
1.503 raeburn 5942: my @ans=@array;
5943: my $i=0;
5944: my $increment = 0;
5945: while ($#ans) {
5946: $i+=length($ans[0]) + $increment;
5947: my $line = int($i/$$scantron_config{'Qlength'} + $ansnum);
5948: my $bubble = $i%$$scantron_config{'Qlength'};
5949: $record->{"scantron.$line.answer"}.=$alphabet->[$bubble];
5950: shift(@ans);
5951: $increment = 1;
5952: }
5953: $ansnum += $answers_needed;
1.82 albertel 5954: }
1.503 raeburn 5955: return $ansnum;
1.82 albertel 5956: }
5957:
1.423 albertel 5958: =pod
5959:
5960: =item scantron_add_delay
5961:
5962: Adds an error message that occurred during the grading phase to a
5963: queue of messages to be shown after grading pass is complete
5964:
5965: Arguments:
1.424 albertel 5966: $delayqueue - arrary ref of hash ref of error messages
1.423 albertel 5967: $scanline - the scanline that caused the error
5968: $errormesage - the error message
5969: $errorcode - a numeric code for the error
5970:
5971: Side Effects:
1.424 albertel 5972: updates the $delayqueue to have a new hash ref of the error
1.423 albertel 5973:
5974: =cut
5975:
1.82 albertel 5976: sub scantron_add_delay {
1.140 albertel 5977: my ($delayqueue,$scanline,$errormessage,$errorcode)=@_;
5978: push(@$delayqueue,
5979: {'line' => $scanline, 'emsg' => $errormessage,
5980: 'ecode' => $errorcode }
5981: );
1.82 albertel 5982: }
5983:
1.423 albertel 5984: =pod
5985:
5986: =item scantron_find_student
5987:
1.424 albertel 5988: Finds the username for the current scanline
5989:
5990: Arguments:
5991: $scantron_record - hash result from scantron_parse_scanline
5992: $scan_data - hash of correction information
5993: (see &scantron_getfile() form more information)
5994: $idmap - hash from &username_to_idmap()
5995: $line - number of current scanline
5996:
5997: Returns:
5998: Either 'username:domain' or undef if unknown
5999:
1.423 albertel 6000: =cut
6001:
1.82 albertel 6002: sub scantron_find_student {
1.157 albertel 6003: my ($scantron_record,$scan_data,$idmap,$line)=@_;
1.83 albertel 6004: my $scanID=$$scantron_record{'scantron.ID'};
1.157 albertel 6005: if ($scanID =~ /^\s*$/) {
6006: return &scan_data($scan_data,"$line.user");
6007: }
1.83 albertel 6008: foreach my $id (keys(%$idmap)) {
1.157 albertel 6009: if (lc($id) eq lc($scanID)) {
6010: return $$idmap{$id};
6011: }
1.83 albertel 6012: }
6013: return undef;
6014: }
6015:
1.423 albertel 6016: =pod
6017:
6018: =item scantron_filter
6019:
1.424 albertel 6020: Filter sub for lonnavmaps, filters out hidden resources if ignore
6021: hidden resources was selected
6022:
1.423 albertel 6023: =cut
6024:
1.83 albertel 6025: sub scantron_filter {
6026: my ($curres)=@_;
1.331 albertel 6027:
6028: if (ref($curres) && $curres->is_problem()) {
6029: # if the user has asked to not have either hidden
6030: # or 'randomout' controlled resources to be graded
6031: # don't include them
6032: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
6033: && $curres->randomout) {
6034: return 0;
6035: }
1.83 albertel 6036: return 1;
6037: }
6038: return 0;
1.82 albertel 6039: }
6040:
1.423 albertel 6041: =pod
6042:
6043: =item scantron_process_corrections
6044:
1.424 albertel 6045: Gets correction information out of submitted form data and corrects
6046: the scanline
6047:
1.423 albertel 6048: =cut
6049:
1.157 albertel 6050: sub scantron_process_corrections {
6051: my ($r) = @_;
1.257 albertel 6052: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 6053: my ($scanlines,$scan_data)=&scantron_getfile();
6054: my $classlist=&Apache::loncoursedata::get_classlist();
1.257 albertel 6055: my $which=$env{'form.scantron_line'};
1.200 albertel 6056: my $line=&scantron_get_line($scanlines,$scan_data,$which);
1.157 albertel 6057: my ($skip,$err,$errmsg);
1.257 albertel 6058: if ($env{'form.scantron_skip_record'}) {
1.157 albertel 6059: $skip=1;
1.257 albertel 6060: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)ID$/) {
6061: my $newstudent=$env{'form.scantron_username'}.':'.
6062: $env{'form.scantron_domain'};
1.157 albertel 6063: my $newid=$classlist->{$newstudent}->[&Apache::loncoursedata::CL_ID];
6064: ($line,$err,$errmsg)=
6065: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
6066: 'ID',{'newid'=>$newid,
1.257 albertel 6067: 'username'=>$env{'form.scantron_username'},
6068: 'domain'=>$env{'form.scantron_domain'}});
6069: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)CODE$/) {
6070: my $resolution=$env{'form.scantron_CODE_resolution'};
1.190 albertel 6071: my $newCODE;
1.192 albertel 6072: my %args;
1.190 albertel 6073: if ($resolution eq 'use_unfound') {
1.191 albertel 6074: $newCODE='use_unfound';
1.190 albertel 6075: } elsif ($resolution eq 'use_found') {
1.257 albertel 6076: $newCODE=$env{'form.scantron_CODE_selectedvalue'};
1.190 albertel 6077: } elsif ($resolution eq 'use_typed') {
1.257 albertel 6078: $newCODE=$env{'form.scantron_CODE_newvalue'};
1.194 albertel 6079: } elsif ($resolution =~ /^use_closest_(\d+)/) {
1.257 albertel 6080: $newCODE=$env{"form.scantron_CODE_closest_$1"};
1.190 albertel 6081: }
1.257 albertel 6082: if ($env{'form.scantron_corrections'} eq 'duplicateCODE') {
1.192 albertel 6083: $args{'CODE_ignore_dup'}=1;
6084: }
6085: $args{'CODE'}=$newCODE;
1.186 albertel 6086: ($line,$err,$errmsg)=
6087: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
1.192 albertel 6088: 'CODE',\%args);
1.257 albertel 6089: } elsif ($env{'form.scantron_corrections'} =~ /^(missing|double)bubble$/) {
6090: foreach my $question (split(',',$env{'form.scantron_questions'})) {
1.157 albertel 6091: ($line,$err,$errmsg)=
6092: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,
6093: $which,'answer',
6094: { 'question'=>$question,
1.503 raeburn 6095: 'response'=>$env{"form.scantron_correct_Q_$question"},
6096: 'questionnum'=>$env{"form.scantron_questionnum_Q_$question"}});
1.157 albertel 6097: if ($err) { last; }
6098: }
6099: }
6100: if ($err) {
1.398 albertel 6101: $r->print("<span class=\"LC_warning\">Unable to accept last correction, an error occurred :$errmsg:</span>");
1.157 albertel 6102: } else {
1.200 albertel 6103: &scantron_put_line($scanlines,$scan_data,$which,$line,$skip);
1.157 albertel 6104: &scantron_putfile($scanlines,$scan_data);
6105: }
6106: }
6107:
1.423 albertel 6108: =pod
6109:
6110: =item reset_skipping_status
6111:
1.424 albertel 6112: Forgets the current set of remember skipped scanlines (and thus
6113: reverts back to considering all lines in the
6114: scantron_skipped_<filename> file)
6115:
1.423 albertel 6116: =cut
6117:
1.200 albertel 6118: sub reset_skipping_status {
6119: my ($scanlines,$scan_data)=&scantron_getfile();
6120: &scan_data($scan_data,'remember_skipping',undef,1);
6121: &scantron_putfile(undef,$scan_data);
6122: }
6123:
1.423 albertel 6124: =pod
6125:
6126: =item start_skipping
6127:
1.424 albertel 6128: Marks a scanline to be skipped.
6129:
1.423 albertel 6130: =cut
6131:
1.376 albertel 6132: sub start_skipping {
1.200 albertel 6133: my ($scan_data,$i)=@_;
6134: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 6135: if ($env{'form.scantron_options_redo'} =~ /^redo_/) {
6136: $remembered{$i}=2;
6137: } else {
6138: $remembered{$i}=1;
6139: }
1.200 albertel 6140: &scan_data($scan_data,'remember_skipping',join(':',%remembered));
6141: }
6142:
1.423 albertel 6143: =pod
6144:
6145: =item should_be_skipped
6146:
1.424 albertel 6147: Checks whether a scanline should be skipped.
6148:
1.423 albertel 6149: =cut
6150:
1.200 albertel 6151: sub should_be_skipped {
1.376 albertel 6152: my ($scanlines,$scan_data,$i)=@_;
1.257 albertel 6153: if ($env{'form.scantron_options_redo'} !~ /^redo_/) {
1.200 albertel 6154: # not redoing old skips
1.376 albertel 6155: if ($scanlines->{'skipped'}[$i]) { return 1; }
1.200 albertel 6156: return 0;
6157: }
6158: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 6159:
6160: if (exists($remembered{$i}) && $remembered{$i} != 2 ) {
6161: return 0;
6162: }
1.200 albertel 6163: return 1;
6164: }
6165:
1.423 albertel 6166: =pod
6167:
6168: =item remember_current_skipped
6169:
1.424 albertel 6170: Discovers what scanlines are in the scantron_skipped_<filename>
6171: file and remembers them into scan_data for later use.
6172:
1.423 albertel 6173: =cut
6174:
1.200 albertel 6175: sub remember_current_skipped {
6176: my ($scanlines,$scan_data)=&scantron_getfile();
6177: my %to_remember;
6178: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
6179: if ($scanlines->{'skipped'}[$i]) {
6180: $to_remember{$i}=1;
6181: }
6182: }
1.376 albertel 6183:
1.200 albertel 6184: &scan_data($scan_data,'remember_skipping',join(':',%to_remember));
6185: &scantron_putfile(undef,$scan_data);
6186: }
6187:
1.423 albertel 6188: =pod
6189:
6190: =item check_for_error
6191:
1.424 albertel 6192: Checks if there was an error when attempting to remove a specific
6193: scantron_.. bubble sheet data file. Prints out an error if
6194: something went wrong.
6195:
1.423 albertel 6196: =cut
6197:
1.200 albertel 6198: sub check_for_error {
6199: my ($r,$result)=@_;
6200: if ($result ne 'ok' && $result ne 'not_found' ) {
1.492 albertel 6201: $r->print(&mt("An error occurred ([_1]) when trying to remove the existing corrections.",$result));
1.200 albertel 6202: }
6203: }
1.157 albertel 6204:
1.423 albertel 6205: =pod
6206:
6207: =item scantron_warning_screen
6208:
1.424 albertel 6209: Interstitial screen to make sure the operator has selected the
6210: correct options before we start the validation phase.
6211:
1.423 albertel 6212: =cut
6213:
1.203 albertel 6214: sub scantron_warning_screen {
6215: my ($button_text)=@_;
1.257 albertel 6216: my $title=&Apache::lonnet::gettitle($env{'form.selectpage'});
1.284 albertel 6217: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.373 albertel 6218: my $CODElist;
1.284 albertel 6219: if ($scantron_config{'CODElocation'} &&
6220: $scantron_config{'CODEstart'} &&
6221: $scantron_config{'CODElength'}) {
6222: $CODElist=$env{'form.scantron_CODElist'};
1.398 albertel 6223: if ($env{'form.scantron_CODElist'} eq '') { $CODElist='<span class="LC_warning">None</span>'; }
1.284 albertel 6224: $CODElist=
1.492 albertel 6225: '<tr><td><b>'.&mt('List of CODES to validate against:').'</b></td><td><tt>'.
1.373 albertel 6226: $env{'form.scantron_CODElist'}.'</tt></td></tr>';
1.284 albertel 6227: }
1.492 albertel 6228: return ('
1.203 albertel 6229: <p>
1.492 albertel 6230: <span class="LC_warning">
6231: '.&mt('Please double check the information below before clicking on \'[_1]\'',&mt($button_text)).'</span>
1.203 albertel 6232: </p>
6233: <table>
1.492 albertel 6234: <tr><td><b>'.&mt('Sequence to be Graded:').'</b></td><td>'.$title.'</td></tr>
6235: <tr><td><b>'.&mt('Data File that will be used:').'</b></td><td><tt>'.$env{'form.scantron_selectfile'}.'</tt></td></tr>
6236: '.$CODElist.'
1.203 albertel 6237: </table>
6238: <br />
1.492 albertel 6239: <p> '.&mt('If this information is correct, please click on \'[_1]\'.',&mt($button_text)).'</p>
6240: <p> '.&mt('If something is incorrect, please click the \'Grading Menu\' button to start over.').'</p>
1.203 albertel 6241:
6242: <br />
1.492 albertel 6243: ');
1.203 albertel 6244: }
6245:
1.423 albertel 6246: =pod
6247:
6248: =item scantron_do_warning
6249:
1.424 albertel 6250: Check if the operator has picked something for all required
6251: fields. Error out if something is missing.
6252:
1.423 albertel 6253: =cut
6254:
1.203 albertel 6255: sub scantron_do_warning {
6256: my ($r)=@_;
1.324 albertel 6257: my ($symb)=&get_symb($r);
1.203 albertel 6258: if (!$symb) {return '';}
1.324 albertel 6259: my $default_form_data=&defaultFormData($symb);
1.203 albertel 6260: $r->print(&scantron_form_start().$default_form_data);
1.257 albertel 6261: if ( $env{'form.selectpage'} eq '' ||
6262: $env{'form.scantron_selectfile'} eq '' ||
6263: $env{'form.scantron_format'} eq '' ) {
1.492 albertel 6264: $r->print("<p>".&mt('You have forgetten to specify some information. Please go Back and try again.')."</p>");
1.257 albertel 6265: if ( $env{'form.selectpage'} eq '') {
1.492 albertel 6266: $r->print('<p><span class="LC_error">'.&mt('You have not selected a Sequence to grade').'</span></p>');
1.237 albertel 6267: }
1.257 albertel 6268: if ( $env{'form.scantron_selectfile'} eq '') {
1.492 albertel 6269: $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 6270: }
1.257 albertel 6271: if ( $env{'form.scantron_format'} eq '') {
1.492 albertel 6272: $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 6273: }
6274: } else {
1.265 www 6275: my $warning=&scantron_warning_screen('Grading: Validate Records');
1.492 albertel 6276: $r->print('
6277: '.$warning.'
6278: <input type="submit" name="submit" value="'.&mt('Grading: Validate Records').'" />
1.203 albertel 6279: <input type="hidden" name="command" value="scantron_validate" />
1.492 albertel 6280: ');
1.237 albertel 6281: }
1.352 albertel 6282: $r->print("</form><br />".&show_grading_menu_form($symb));
1.203 albertel 6283: return '';
6284: }
6285:
1.423 albertel 6286: =pod
6287:
6288: =item scantron_form_start
6289:
1.424 albertel 6290: html hidden input for remembering all selected grading options
6291:
1.423 albertel 6292: =cut
6293:
1.203 albertel 6294: sub scantron_form_start {
6295: my ($max_bubble)=@_;
6296: my $result= <<SCANTRONFORM;
6297: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
1.257 albertel 6298: <input type="hidden" name="selectpage" value="$env{'form.selectpage'}" />
6299: <input type="hidden" name="scantron_format" value="$env{'form.scantron_format'}" />
6300: <input type="hidden" name="scantron_selectfile" value="$env{'form.scantron_selectfile'}" />
1.218 albertel 6301: <input type="hidden" name="scantron_maxbubble" value="$max_bubble" />
1.257 albertel 6302: <input type="hidden" name="scantron_CODElist" value="$env{'form.scantron_CODElist'}" />
6303: <input type="hidden" name="scantron_CODEunique" value="$env{'form.scantron_CODEunique'}" />
6304: <input type="hidden" name="scantron_options_redo" value="$env{'form.scantron_options_redo'}" />
6305: <input type="hidden" name="scantron_options_ignore" value="$env{'form.scantron_options_ignore'}" />
1.331 albertel 6306: <input type="hidden" name="scantron_options_hidden" value="$env{'form.scantron_options_hidden'}" />
1.203 albertel 6307: SCANTRONFORM
1.447 foxr 6308:
6309: my $line = 0;
6310: while (defined($env{"form.scantron.bubblelines.$line"})) {
6311: my $chunk =
6312: '<input type="hidden" name="scantron.bubblelines.'.$line.'" value="'.$env{"form.scantron.bubblelines.$line"}.'" />'."\n";
1.448 foxr 6313: $chunk .=
6314: '<input type="hidden" name="scantron.first_bubble_line.'.$line.'" value="'.$env{"form.scantron.first_bubble_line.$line"}.'" />'."\n";
1.503 raeburn 6315: $chunk .=
6316: '<input type="hidden" name="scantron.sub_bubblelines.'.$line.'" value="'.$env{"form.scantron.sub_bubblelines.$line"}.'" />'."\n";
1.504 raeburn 6317: $chunk .=
6318: '<input type="hidden" name="scantron.responsetype.'.$line.'" value="'.$env{"form.scantron.responsetype.$line"}.'" />'."\n";
1.447 foxr 6319: $result .= $chunk;
6320: $line++;
6321: }
1.203 albertel 6322: return $result;
6323: }
6324:
1.423 albertel 6325: =pod
6326:
6327: =item scantron_validate_file
6328:
1.424 albertel 6329: Dispatch routine for doing validation of a bubble sheet data file.
6330:
6331: Also processes any necessary information resets that need to
6332: occur before validation begins (ignore previous corrections,
6333: restarting the skipped records processing)
6334:
1.423 albertel 6335: =cut
6336:
1.157 albertel 6337: sub scantron_validate_file {
6338: my ($r) = @_;
1.324 albertel 6339: my ($symb)=&get_symb($r);
1.157 albertel 6340: if (!$symb) {return '';}
1.324 albertel 6341: my $default_form_data=&defaultFormData($symb);
1.200 albertel 6342:
6343: # do the detection of only doing skipped records first befroe we delete
1.424 albertel 6344: # them when doing the corrections reset
1.257 albertel 6345: if ($env{'form.scantron_options_redo'} ne 'redo_skipped_ready') {
1.200 albertel 6346: &reset_skipping_status();
6347: }
1.257 albertel 6348: if ($env{'form.scantron_options_redo'} eq 'redo_skipped') {
1.200 albertel 6349: &remember_current_skipped();
1.257 albertel 6350: $env{'form.scantron_options_redo'}='redo_skipped_ready';
1.200 albertel 6351: }
6352:
1.257 albertel 6353: if ($env{'form.scantron_options_ignore'} eq 'ignore_corrections') {
1.200 albertel 6354: &check_for_error($r,&scantron_remove_file('corrected'));
6355: &check_for_error($r,&scantron_remove_file('skipped'));
6356: &check_for_error($r,&scantron_remove_scan_data());
1.257 albertel 6357: $env{'form.scantron_options_ignore'}='done';
1.192 albertel 6358: }
1.200 albertel 6359:
1.257 albertel 6360: if ($env{'form.scantron_corrections'}) {
1.157 albertel 6361: &scantron_process_corrections($r);
6362: }
1.503 raeburn 6363: $r->print('<p>'.&mt('Gathering necessary information.').'</p>');$r->rflush();
1.157 albertel 6364: #get the student pick code ready
6365: $r->print(&Apache::loncommon::studentbrowser_javascript());
1.582 raeburn 6366: my $nav_error;
6367: my $max_bubble=&scantron_get_maxbubble(\$nav_error);
6368: if ($nav_error) {
6369: $r->print(&navmap_errormsg());
6370: return '';
6371: }
1.203 albertel 6372: my $result=&scantron_form_start($max_bubble).$default_form_data;
1.157 albertel 6373: $r->print($result);
6374:
1.334 albertel 6375: my @validate_phases=( 'sequence',
6376: 'ID',
1.157 albertel 6377: 'CODE',
6378: 'doublebubble',
6379: 'missingbubbles');
1.257 albertel 6380: if (!$env{'form.validatepass'}) {
6381: $env{'form.validatepass'} = 0;
1.157 albertel 6382: }
1.257 albertel 6383: my $currentphase=$env{'form.validatepass'};
1.157 albertel 6384:
1.448 foxr 6385:
1.157 albertel 6386: my $stop=0;
6387: while (!$stop && $currentphase < scalar(@validate_phases)) {
1.503 raeburn 6388: $r->print(&mt('Validating '.$validate_phases[$currentphase]).'<br />');
1.157 albertel 6389: $r->rflush();
6390: my $which="scantron_validate_".$validate_phases[$currentphase];
6391: {
6392: no strict 'refs';
6393: ($stop,$currentphase)=&$which($r,$currentphase);
6394: }
6395: }
6396: if (!$stop) {
1.203 albertel 6397: my $warning=&scantron_warning_screen('Start Grading');
1.542 raeburn 6398: $r->print(&mt('Validation process complete.').'<br />'.
6399: $warning.
6400: &mt('Perform verification for each student after storage of submissions?').
6401: ' <span class="LC_nobreak"><label>'.
6402: '<input type="radio" name="verifyrecord" value="1" />'.&mt('Yes').'</label>'.
6403: (' 'x3).'<label>'.
6404: '<input type="radio" name="verifyrecord" value="0" checked="checked" />'.&mt('No').
6405: '</label></span><br />'.
6406: &mt('Grading will take longer if you use verification.').'<br />'.
1.572 www 6407: &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 6408: '<input type="submit" name="submit" value="'.&mt('Start Grading').'" />'.
6409: '<input type="hidden" name="command" value="scantron_process" />'."\n");
1.157 albertel 6410: } else {
6411: $r->print('<input type="hidden" name="command" value="scantron_validate" />');
6412: $r->print("<input type='hidden' name='validatepass' value='".$currentphase."' />");
6413: }
6414: if ($stop) {
1.334 albertel 6415: if ($validate_phases[$currentphase] eq 'sequence') {
1.539 riegler 6416: $r->print('<input type="submit" name="submit" value="'.&mt('Ignore').' → " />');
1.492 albertel 6417: $r->print(' '.&mt('this error').' <br />');
1.334 albertel 6418:
1.492 albertel 6419: $r->print(" <p>".&mt("Or click the 'Grading Menu' button to start over.")."</p>");
1.334 albertel 6420: } else {
1.503 raeburn 6421: if ($validate_phases[$currentphase] eq 'doublebubble' || $validate_phases[$currentphase] eq 'missingbubbles') {
1.539 riegler 6422: $r->print('<input type="button" name="submitbutton" value="'.&mt('Continue').' →" onclick="javascript:verify_bubble_radio(this.form)" />');
1.503 raeburn 6423: } else {
1.539 riegler 6424: $r->print('<input type="submit" name="submit" value="'.&mt('Continue').' →" />');
1.503 raeburn 6425: }
1.492 albertel 6426: $r->print(' '.&mt('using corrected info').' <br />');
6427: $r->print("<input type='submit' value='".&mt("Skip")."' name='scantron_skip_record' />");
6428: $r->print(" ".&mt("this scanline saving it for later."));
1.334 albertel 6429: }
1.157 albertel 6430: }
1.352 albertel 6431: $r->print(" </form><br />".&show_grading_menu_form($symb));
1.157 albertel 6432: return '';
6433: }
6434:
1.423 albertel 6435:
6436: =pod
6437:
6438: =item scantron_remove_file
6439:
1.424 albertel 6440: Removes the requested bubble sheet data file, makes sure that
6441: scantron_original_<filename> is never removed
6442:
6443:
1.423 albertel 6444: =cut
6445:
1.200 albertel 6446: sub scantron_remove_file {
1.192 albertel 6447: my ($which)=@_;
1.257 albertel 6448: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6449: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 6450: my $file='scantron_';
1.200 albertel 6451: if ($which eq 'corrected' || $which eq 'skipped') {
6452: $file.=$which.'_';
1.192 albertel 6453: } else {
6454: return 'refused';
6455: }
1.257 albertel 6456: $file.=$env{'form.scantron_selectfile'};
1.200 albertel 6457: return &Apache::lonnet::removeuserfile($cname,$cdom,$file);
6458: }
6459:
1.423 albertel 6460:
6461: =pod
6462:
6463: =item scantron_remove_scan_data
6464:
1.424 albertel 6465: Removes all scan_data correction for the requested bubble sheet
6466: data file. (In the case that both the are doing skipped records we need
6467: to remember the old skipped lines for the time being so that element
6468: persists for a while.)
6469:
1.423 albertel 6470: =cut
6471:
1.200 albertel 6472: sub scantron_remove_scan_data {
1.257 albertel 6473: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6474: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 6475: my @keys=&Apache::lonnet::getkeys('nohist_scantrondata',$cdom,$cname);
6476: my @todelete;
1.257 albertel 6477: my $filename=$env{'form.scantron_selectfile'};
1.192 albertel 6478: foreach my $key (@keys) {
6479: if ($key=~/^\Q$filename\E_/) {
1.257 albertel 6480: if ($env{'form.scantron_options_redo'} eq 'redo_skipped_ready' &&
1.200 albertel 6481: $key=~/remember_skipping/) {
6482: next;
6483: }
1.192 albertel 6484: push(@todelete,$key);
6485: }
6486: }
1.200 albertel 6487: my $result;
1.192 albertel 6488: if (@todelete) {
1.491 albertel 6489: $result = &Apache::lonnet::del('nohist_scantrondata',
6490: \@todelete,$cdom,$cname);
6491: } else {
6492: $result = 'ok';
1.192 albertel 6493: }
6494: return $result;
6495: }
6496:
1.423 albertel 6497:
6498: =pod
6499:
6500: =item scantron_getfile
6501:
1.424 albertel 6502: Fetches the requested bubble sheet data file (all 3 versions), and
6503: the scan_data hash
6504:
6505: Arguments:
6506: None
6507:
6508: Returns:
6509: 2 hash references
6510:
6511: - first one has
6512: orig -
6513: corrected -
6514: skipped - each of which points to an array ref of the specified
6515: file broken up into individual lines
6516: count - number of scanlines
6517:
6518: - second is the scan_data hash possible keys are
1.425 albertel 6519: ($number refers to scanline numbered $number and thus the key affects
6520: only that scanline
6521: $bubline refers to the specific bubble line element and the aspects
6522: refers to that specific bubble line element)
6523:
6524: $number.user - username:domain to use
6525: $number.CODE_ignore_dup
6526: - ignore the duplicate CODE error
6527: $number.useCODE
6528: - use the CODE in the scanline as is
6529: $number.no_bubble.$bubline
6530: - it is valid that there is no bubbled in bubble
6531: at $number $bubline
6532: remember_skipping
6533: - a frozen hash containing keys of $number and values
6534: of either
6535: 1 - we are on a 'do skipped records pass' and plan
6536: on processing this line
6537: 2 - we are on a 'do skipped records pass' and this
6538: scanline has been marked to skip yet again
1.424 albertel 6539:
1.423 albertel 6540: =cut
6541:
1.157 albertel 6542: sub scantron_getfile {
1.200 albertel 6543: #FIXME really would prefer a scantron directory
1.257 albertel 6544: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6545: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.157 albertel 6546: my $lines;
6547: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6548: 'scantron_orig_'.$env{'form.scantron_selectfile'});
1.157 albertel 6549: my %scanlines;
6550: $scanlines{'orig'}=[(split("\n",$lines,-1))];
6551: my $temp=$scanlines{'orig'};
6552: $scanlines{'count'}=$#$temp;
6553:
6554: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6555: 'scantron_corrected_'.$env{'form.scantron_selectfile'});
1.157 albertel 6556: if ($lines eq '-1') {
6557: $scanlines{'corrected'}=[];
6558: } else {
6559: $scanlines{'corrected'}=[(split("\n",$lines,-1))];
6560: }
6561: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6562: 'scantron_skipped_'.$env{'form.scantron_selectfile'});
1.157 albertel 6563: if ($lines eq '-1') {
6564: $scanlines{'skipped'}=[];
6565: } else {
6566: $scanlines{'skipped'}=[(split("\n",$lines,-1))];
6567: }
1.175 albertel 6568: my @tmp=&Apache::lonnet::dump('nohist_scantrondata',$cdom,$cname);
1.157 albertel 6569: if ($tmp[0] =~ /^(error:|no_such_host)/) { @tmp=(); }
6570: my %scan_data = @tmp;
6571: return (\%scanlines,\%scan_data);
6572: }
6573:
1.423 albertel 6574: =pod
6575:
6576: =item lonnet_putfile
6577:
1.424 albertel 6578: Wrapper routine to call &Apache::lonnet::finishuserfileupload
6579:
6580: Arguments:
6581: $contents - data to store
6582: $filename - filename to store $contents into
6583:
6584: Returns:
6585: result value from &Apache::lonnet::finishuserfileupload
6586:
1.423 albertel 6587: =cut
6588:
1.157 albertel 6589: sub lonnet_putfile {
6590: my ($contents,$filename)=@_;
1.257 albertel 6591: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6592: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6593: $env{'form.sillywaytopassafilearound'}=$contents;
1.275 albertel 6594: &Apache::lonnet::finishuserfileupload($docuname,$docudom,'sillywaytopassafilearound',$filename);
1.157 albertel 6595:
6596: }
6597:
1.423 albertel 6598: =pod
6599:
6600: =item scantron_putfile
6601:
1.424 albertel 6602: Stores the current version of the bubble sheet data files, and the
6603: scan_data hash. (Does not modify the original version only the
6604: corrected and skipped versions.
6605:
6606: Arguments:
6607: $scanlines - hash ref that looks like the first return value from
6608: &scantron_getfile()
6609: $scan_data - hash ref that looks like the second return value from
6610: &scantron_getfile()
6611:
1.423 albertel 6612: =cut
6613:
1.157 albertel 6614: sub scantron_putfile {
6615: my ($scanlines,$scan_data) = @_;
1.200 albertel 6616: #FIXME really would prefer a scantron directory
1.257 albertel 6617: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6618: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.200 albertel 6619: if ($scanlines) {
6620: my $prefix='scantron_';
1.157 albertel 6621: # no need to update orig, shouldn't change
6622: # &lonnet_putfile(join("\n",@{$scanlines->{'orig'}}),$prefix.'orig_'.
1.257 albertel 6623: # $env{'form.scantron_selectfile'});
1.200 albertel 6624: &lonnet_putfile(join("\n",@{$scanlines->{'corrected'}}),
6625: $prefix.'corrected_'.
1.257 albertel 6626: $env{'form.scantron_selectfile'});
1.200 albertel 6627: &lonnet_putfile(join("\n",@{$scanlines->{'skipped'}}),
6628: $prefix.'skipped_'.
1.257 albertel 6629: $env{'form.scantron_selectfile'});
1.200 albertel 6630: }
1.175 albertel 6631: &Apache::lonnet::put('nohist_scantrondata',$scan_data,$cdom,$cname);
1.157 albertel 6632: }
6633:
1.423 albertel 6634: =pod
6635:
6636: =item scantron_get_line
6637:
1.424 albertel 6638: Returns the correct version of the scanline
6639:
6640: Arguments:
6641: $scanlines - hash ref that looks like the first return value from
6642: &scantron_getfile()
6643: $scan_data - hash ref that looks like the second return value from
6644: &scantron_getfile()
6645: $i - number of the requested line (starts at 0)
6646:
6647: Returns:
6648: A scanline, (either the original or the corrected one if it
6649: exists), or undef if the requested scanline should be
6650: skipped. (Either because it's an skipped scanline, or it's an
6651: unskipped scanline and we are not doing a 'do skipped scanlines'
6652: pass.
6653:
1.423 albertel 6654: =cut
6655:
1.157 albertel 6656: sub scantron_get_line {
1.200 albertel 6657: my ($scanlines,$scan_data,$i)=@_;
1.376 albertel 6658: if (&should_be_skipped($scanlines,$scan_data,$i)) { return undef; }
6659: #if ($scanlines->{'skipped'}[$i]) { return undef; }
1.157 albertel 6660: if ($scanlines->{'corrected'}[$i]) {return $scanlines->{'corrected'}[$i];}
6661: return $scanlines->{'orig'}[$i];
6662: }
6663:
1.423 albertel 6664: =pod
6665:
6666: =item scantron_todo_count
6667:
1.424 albertel 6668: Counts the number of scanlines that need processing.
6669:
6670: Arguments:
6671: $scanlines - hash ref that looks like the first return value from
6672: &scantron_getfile()
6673: $scan_data - hash ref that looks like the second return value from
6674: &scantron_getfile()
6675:
6676: Returns:
6677: $count - number of scanlines to process
6678:
1.423 albertel 6679: =cut
6680:
1.200 albertel 6681: sub get_todo_count {
6682: my ($scanlines,$scan_data)=@_;
6683: my $count=0;
6684: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
6685: my $line=&scantron_get_line($scanlines,$scan_data,$i);
6686: if ($line=~/^[\s\cz]*$/) { next; }
6687: $count++;
6688: }
6689: return $count;
6690: }
6691:
1.423 albertel 6692: =pod
6693:
6694: =item scantron_put_line
6695:
1.424 albertel 6696: Updates the 'corrected' or 'skipped' versions of the bubble sheet
6697: data file.
6698:
6699: Arguments:
6700: $scanlines - hash ref that looks like the first return value from
6701: &scantron_getfile()
6702: $scan_data - hash ref that looks like the second return value from
6703: &scantron_getfile()
6704: $i - line number to update
6705: $newline - contents of the updated scanline
6706: $skip - if true make the line for skipping and update the
6707: 'skipped' file
6708:
1.423 albertel 6709: =cut
6710:
1.157 albertel 6711: sub scantron_put_line {
1.200 albertel 6712: my ($scanlines,$scan_data,$i,$newline,$skip)=@_;
1.157 albertel 6713: if ($skip) {
6714: $scanlines->{'skipped'}[$i]=$newline;
1.376 albertel 6715: &start_skipping($scan_data,$i);
1.157 albertel 6716: return;
6717: }
6718: $scanlines->{'corrected'}[$i]=$newline;
6719: }
6720:
1.423 albertel 6721: =pod
6722:
6723: =item scantron_clear_skip
6724:
1.424 albertel 6725: Remove a line from the 'skipped' file
6726:
6727: Arguments:
6728: $scanlines - hash ref that looks like the first return value from
6729: &scantron_getfile()
6730: $scan_data - hash ref that looks like the second return value from
6731: &scantron_getfile()
6732: $i - line number to update
6733:
1.423 albertel 6734: =cut
6735:
1.376 albertel 6736: sub scantron_clear_skip {
6737: my ($scanlines,$scan_data,$i)=@_;
6738: if (exists($scanlines->{'skipped'}[$i])) {
6739: undef($scanlines->{'skipped'}[$i]);
6740: return 1;
6741: }
6742: return 0;
6743: }
6744:
1.423 albertel 6745: =pod
6746:
6747: =item scantron_filter_not_exam
6748:
1.424 albertel 6749: Filter routine used by &Apache::lonnavmaps::retrieveResources(), to
6750: filter out resources that are not marked as 'exam' mode
6751:
1.423 albertel 6752: =cut
6753:
1.334 albertel 6754: sub scantron_filter_not_exam {
6755: my ($curres)=@_;
6756:
6757: if (ref($curres) && $curres->is_problem() && !$curres->is_exam()) {
6758: # if the user has asked to not have either hidden
6759: # or 'randomout' controlled resources to be graded
6760: # don't include them
6761: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
6762: && $curres->randomout) {
6763: return 0;
6764: }
6765: return 1;
6766: }
6767: return 0;
6768: }
6769:
1.423 albertel 6770: =pod
6771:
6772: =item scantron_validate_sequence
6773:
1.424 albertel 6774: Validates the selected sequence, checking for resource that are
6775: not set to exam mode.
6776:
1.423 albertel 6777: =cut
6778:
1.334 albertel 6779: sub scantron_validate_sequence {
6780: my ($r,$currentphase) = @_;
6781:
6782: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 6783: unless (ref($navmap)) {
6784: $r->print(&navmap_errormsg());
6785: return (1,$currentphase);
6786: }
1.334 albertel 6787: my (undef,undef,$sequence)=
6788: &Apache::lonnet::decode_symb($env{'form.selectpage'});
6789:
6790: my $map=$navmap->getResourceByUrl($sequence);
6791:
6792: $r->print('<input type="hidden" name="validate_sequence_exam"
6793: value="ignore" />');
6794: if ($env{'form.validate_sequence_exam'} ne 'ignore') {
6795: my @resources=
6796: $navmap->retrieveResources($map,\&scantron_filter_not_exam,1,0);
6797: if (@resources) {
1.357 banghart 6798: $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 6799: return (1,$currentphase);
6800: }
6801: }
6802:
6803: return (0,$currentphase+1);
6804: }
6805:
1.423 albertel 6806:
6807:
1.157 albertel 6808: sub scantron_validate_ID {
6809: my ($r,$currentphase) = @_;
6810:
6811: #get student info
6812: my $classlist=&Apache::loncoursedata::get_classlist();
6813: my %idmap=&username_to_idmap($classlist);
6814:
6815: #get scantron line setup
1.257 albertel 6816: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 6817: my ($scanlines,$scan_data)=&scantron_getfile();
1.582 raeburn 6818:
6819: my $nav_error;
6820: &scantron_get_maxbubble(\$nav_error); # parse needs the bubble_lines.. array.
6821: if ($nav_error) {
6822: $r->print(&navmap_errormsg());
6823: return(1,$currentphase);
6824: }
1.157 albertel 6825:
6826: my %found=('ids'=>{},'usernames'=>{});
6827: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 6828: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 6829: if ($line=~/^[\s\cz]*$/) { next; }
6830: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
6831: $scan_data);
6832: my $id=$$scan_record{'scantron.ID'};
6833: my $found;
6834: foreach my $checkid (keys(%idmap)) {
6835: if (lc($checkid) eq lc($id)) { $found=$checkid;last; }
6836: }
6837: if ($found) {
6838: my $username=$idmap{$found};
6839: if ($found{'ids'}{$found}) {
6840: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
6841: $line,'duplicateID',$found);
1.194 albertel 6842: return(1,$currentphase);
1.157 albertel 6843: } elsif ($found{'usernames'}{$username}) {
6844: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
6845: $line,'duplicateID',$username);
1.194 albertel 6846: return(1,$currentphase);
1.157 albertel 6847: }
1.186 albertel 6848: #FIXME store away line we previously saw the ID on to use above
1.157 albertel 6849: $found{'ids'}{$found}++;
6850: $found{'usernames'}{$username}++;
6851: } else {
6852: if ($id =~ /^\s*$/) {
1.158 albertel 6853: my $username=&scan_data($scan_data,"$i.user");
1.157 albertel 6854: if (defined($username) && $found{'usernames'}{$username}) {
6855: &scantron_get_correction($r,$i,$scan_record,
6856: \%scantron_config,
6857: $line,'duplicateID',$username);
1.194 albertel 6858: return(1,$currentphase);
1.157 albertel 6859: } elsif (!defined($username)) {
6860: &scantron_get_correction($r,$i,$scan_record,
6861: \%scantron_config,
6862: $line,'incorrectID');
1.194 albertel 6863: return(1,$currentphase);
1.157 albertel 6864: }
6865: $found{'usernames'}{$username}++;
6866: } else {
6867: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
6868: $line,'incorrectID');
1.194 albertel 6869: return(1,$currentphase);
1.157 albertel 6870: }
6871: }
6872: }
6873:
6874: return (0,$currentphase+1);
6875: }
6876:
1.423 albertel 6877:
1.157 albertel 6878: sub scantron_get_correction {
6879: my ($r,$i,$scan_record,$scan_config,$line,$error,$arg)=@_;
1.454 banghart 6880: #FIXME in the case of a duplicated ID the previous line, probably need
1.157 albertel 6881: #to show both the current line and the previous one and allow skipping
6882: #the previous one or the current one
6883:
1.333 albertel 6884: if ( $$scan_record{'scantron.PaperID'} =~ /\S/) {
1.492 albertel 6885: $r->print("<p>".&mt("<b>An error was detected ($error)</b>".
6886: " for PaperID <tt>[_1]</tt>",
6887: $$scan_record{'scantron.PaperID'})."</p> \n");
1.157 albertel 6888: } else {
1.492 albertel 6889: $r->print("<p>".&mt("<b>An error was detected ($error)</b>".
6890: " in scanline [_1] <pre>[_2]</pre>",
6891: $i,$line)."</p> \n");
6892: }
6893: my $message="<p>".&mt("The ID on the form is <tt>[_1]</tt><br />".
6894: "The name on the paper is [_2],[_3]",
6895: $$scan_record{'scantron.ID'},
6896: $$scan_record{'scantron.LastName'},
6897: $$scan_record{'scantron.FirstName'})."</p>";
1.242 albertel 6898:
1.157 albertel 6899: $r->print('<input type="hidden" name="scantron_corrections" value="'.$error.'" />'."\n");
6900: $r->print('<input type="hidden" name="scantron_line" value="'.$i.'" />'."\n");
1.503 raeburn 6901: # Array populated for doublebubble or
6902: my @lines_to_correct; # missingbubble errors to build javascript
6903: # to validate radio button checking
6904:
1.157 albertel 6905: if ($error =~ /ID$/) {
1.186 albertel 6906: if ($error eq 'incorrectID') {
1.492 albertel 6907: $r->print("<p>".&mt("The encoded ID is not in the classlist").
6908: "</p>\n");
1.157 albertel 6909: } elsif ($error eq 'duplicateID') {
1.492 albertel 6910: $r->print("<p>".&mt("The encoded ID has also been used by a previous paper [_1]",$arg)."</p>\n");
1.157 albertel 6911: }
1.242 albertel 6912: $r->print($message);
1.492 albertel 6913: $r->print("<p>".&mt("How should I handle this?")." <br /> \n");
1.157 albertel 6914: $r->print("\n<ul><li> ");
6915: #FIXME it would be nice if this sent back the user ID and
6916: #could do partial userID matches
6917: $r->print(&Apache::loncommon::selectstudent_link('scantronupload',
6918: 'scantron_username','scantron_domain'));
6919: $r->print(": <input type='text' name='scantron_username' value='' />");
6920: $r->print("\n@".
1.257 albertel 6921: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'scantron_domain'));
1.157 albertel 6922:
6923: $r->print('</li>');
1.186 albertel 6924: } elsif ($error =~ /CODE$/) {
6925: if ($error eq 'incorrectCODE') {
1.492 albertel 6926: $r->print("<p>".&mt("The encoded CODE is not in the list of possible CODEs.")."</p>\n");
1.186 albertel 6927: } elsif ($error eq 'duplicateCODE') {
1.492 albertel 6928: $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 6929: }
1.492 albertel 6930: $r->print("<p>".&mt("The CODE on the form is <tt>'[_1]'</tt>",
6931: $$scan_record{'scantron.CODE'})."<br />\n");
1.242 albertel 6932: $r->print($message);
1.492 albertel 6933: $r->print("<p>".&mt("How should I handle this?")." <br /> \n");
1.187 albertel 6934: $r->print("\n<br /> ");
1.194 albertel 6935: my $i=0;
1.273 albertel 6936: if ($error eq 'incorrectCODE'
6937: && $$scan_record{'scantron.CODE'}=~/\S/ ) {
1.194 albertel 6938: my ($max,$closest)=&scantron_get_closely_matching_CODEs($arg,$$scan_record{'scantron.CODE'});
1.278 albertel 6939: if ($closest > 0) {
6940: foreach my $testcode (@{$closest}) {
6941: my $checked='';
1.569 bisitz 6942: if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 6943: $r->print("
6944: <label>
1.569 bisitz 6945: <input type='radio' name='scantron_CODE_resolution' value='use_closest_$i'$checked />
1.492 albertel 6946: ".&mt("Use the similar CODE [_1] instead.",
6947: "<b><tt>".$testcode."</tt></b>")."
6948: </label>
6949: <input type='hidden' name='scantron_CODE_closest_$i' value='$testcode' />");
1.278 albertel 6950: $r->print("\n<br />");
6951: $i++;
6952: }
1.194 albertel 6953: }
6954: }
1.273 albertel 6955: if ($$scan_record{'scantron.CODE'}=~/\S/ ) {
1.569 bisitz 6956: my $checked; if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 6957: $r->print("
6958: <label>
1.569 bisitz 6959: <input type='radio' name='scantron_CODE_resolution' value='use_unfound'$checked />
1.492 albertel 6960: ".&mt("Use the CODE [_1] that is was on the paper, ignoring the error.",
6961: "<b><tt>".$$scan_record{'scantron.CODE'}."</tt></b>")."
6962: </label>");
1.273 albertel 6963: $r->print("\n<br />");
6964: }
1.194 albertel 6965:
1.188 albertel 6966: $r->print(<<ENDSCRIPT);
6967: <script type="text/javascript">
6968: function change_radio(field) {
1.190 albertel 6969: var slct=document.scantronupload.scantron_CODE_resolution;
1.188 albertel 6970: var i;
6971: for (i=0;i<slct.length;i++) {
6972: if (slct[i].value==field) { slct[i].checked=true; }
6973: }
6974: }
6975: </script>
6976: ENDSCRIPT
1.187 albertel 6977: my $href="/adm/pickcode?".
1.359 www 6978: "form=".&escape("scantronupload").
6979: "&scantron_format=".&escape($env{'form.scantron_format'}).
6980: "&scantron_CODElist=".&escape($env{'form.scantron_CODElist'}).
6981: "&curCODE=".&escape($$scan_record{'scantron.CODE'}).
6982: "&scantron_selectfile=".&escape($env{'form.scantron_selectfile'});
1.332 albertel 6983: if ($env{'form.scantron_CODElist'} =~ /\S/) {
1.492 albertel 6984: $r->print("
6985: <label>
6986: <input type='radio' name='scantron_CODE_resolution' value='use_found' />
6987: ".&mt("[_1]Select[_2] a CODE from the list of all CODEs and use it.",
6988: "<a target='_blank' href='$href'>","</a>")."
6989: </label>
1.558 bisitz 6990: ".&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 6991: $r->print("\n<br />");
6992: }
1.492 albertel 6993: $r->print("
6994: <label>
6995: <input type='radio' name='scantron_CODE_resolution' value='use_typed' />
6996: ".&mt("Use [_1] as the CODE.",
6997: "</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 6998: $r->print("\n<br /><br />");
1.157 albertel 6999: } elsif ($error eq 'doublebubble') {
1.503 raeburn 7000: $r->print("<p>".&mt("There have been multiple bubbles scanned for some question(s)")."</p>\n");
1.497 foxr 7001:
7002: # The form field scantron_questions is acutally a list of line numbers.
7003: # represented by this form so:
7004:
7005: my $line_list = &questions_to_line_list($arg);
7006:
1.157 albertel 7007: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 7008: $line_list.'" />');
1.242 albertel 7009: $r->print($message);
1.492 albertel 7010: $r->print("<p>".&mt("Please indicate which bubble should be used for grading")."</p>");
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: } elsif ($error eq 'missingbubble') {
1.492 albertel 7018: $r->print("<p>".&mt("There have been <b>no</b> bubbles scanned for some question(s)")."</p>\n");
1.242 albertel 7019: $r->print($message);
1.492 albertel 7020: $r->print("<p>".&mt("Please indicate which bubble should be used for grading.")."</p>");
1.503 raeburn 7021: $r->print(&mt("Some questions have no scanned bubbles.")."\n");
1.497 foxr 7022:
1.503 raeburn 7023: # The form field scantron_questions is actually a list of line numbers not
1.497 foxr 7024: # a list of question numbers. Therefore:
7025: #
7026:
7027: my $line_list = &questions_to_line_list($arg);
7028:
1.157 albertel 7029: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 7030: $line_list.'" />');
1.157 albertel 7031: foreach my $question (@{$arg}) {
1.503 raeburn 7032: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
7033: $scan_record, $error);
1.524 raeburn 7034: push(@lines_to_correct,@linenums);
1.157 albertel 7035: }
1.503 raeburn 7036: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 7037: } else {
7038: $r->print("\n<ul>");
7039: }
7040: $r->print("\n</li></ul>");
1.497 foxr 7041: }
7042:
1.503 raeburn 7043: sub verify_bubbles_checked {
7044: my (@ansnums) = @_;
7045: my $ansnumstr = join('","',@ansnums);
7046: my $warning = &mt("A bubble or 'No bubble' selection has not been made for one or more lines.");
7047: my $output = (<<ENDSCRIPT);
7048: <script type="text/javascript">
7049: function verify_bubble_radio(form) {
7050: var ansnumArray = new Array ("$ansnumstr");
7051: var need_bubble_count = 0;
7052: for (var i=0; i<ansnumArray.length; i++) {
7053: if (form.elements["scantron_correct_Q_"+ansnumArray[i]].length > 1) {
7054: var bubble_picked = 0;
7055: for (var j=0; j<form.elements["scantron_correct_Q_"+ansnumArray[i]].length; j++) {
7056: if (form.elements["scantron_correct_Q_"+ansnumArray[i]][j].checked == true) {
7057: bubble_picked = 1;
7058: }
7059: }
7060: if (bubble_picked == 0) {
7061: need_bubble_count ++;
7062: }
7063: }
7064: }
7065: if (need_bubble_count) {
7066: alert("$warning");
7067: return;
7068: }
7069: form.submit();
7070: }
7071: </script>
7072: ENDSCRIPT
7073: return $output;
7074: }
7075:
1.497 foxr 7076: =pod
7077:
7078: =item questions_to_line_list
1.157 albertel 7079:
1.497 foxr 7080: Converts a list of questions into a string of comma separated
7081: line numbers in the answer sheet used by the questions. This is
7082: used to fill in the scantron_questions form field.
7083:
7084: Arguments:
7085: questions - Reference to an array of questions.
7086:
7087: =cut
7088:
7089:
7090: sub questions_to_line_list {
7091: my ($questions) = @_;
7092: my @lines;
7093:
1.503 raeburn 7094: foreach my $item (@{$questions}) {
7095: my $question = $item;
7096: my ($first,$count,$last);
7097: if ($item =~ /^(\d+)\.(\d+)$/) {
7098: $question = $1;
7099: my $subquestion = $2;
7100: $first = $first_bubble_line{$question-1} + 1;
7101: my @subans = split(/,/,$subdivided_bubble_lines{$question-1});
7102: my $subcount = 1;
7103: while ($subcount<$subquestion) {
7104: $first += $subans[$subcount-1];
7105: $subcount ++;
7106: }
7107: $count = $subans[$subquestion-1];
7108: } else {
7109: $first = $first_bubble_line{$question-1} + 1;
7110: $count = $bubble_lines_per_response{$question-1};
7111: }
1.506 raeburn 7112: $last = $first+$count-1;
1.503 raeburn 7113: push(@lines, ($first..$last));
1.497 foxr 7114: }
7115: return join(',', @lines);
7116: }
7117:
7118: =pod
7119:
7120: =item prompt_for_corrections
7121:
7122: Prompts for a potentially multiline correction to the
7123: user's bubbling (factors out common code from scantron_get_correction
7124: for multi and missing bubble cases).
7125:
7126: Arguments:
7127: $r - Apache request object.
7128: $question - The question number to prompt for.
7129: $scan_config - The scantron file configuration hash.
7130: $scan_record - Reference to the hash that has the the parsed scanlines.
1.503 raeburn 7131: $error - Type of error
1.497 foxr 7132:
7133: Implicit inputs:
7134: %bubble_lines_per_response - Starting line numbers for each question.
7135: Numbered from 0 (but question numbers are from
7136: 1.
7137: %first_bubble_line - Starting bubble line for each question.
1.509 raeburn 7138: %subdivided_bubble_lines - optionresponse, matchresponse and rankresponse
7139: type problems render as separate sub-questions,
1.503 raeburn 7140: in exam mode. This hash contains a
7141: comma-separated list of the lines per
7142: sub-question.
1.510 raeburn 7143: %responsetype_per_response - essayresponse, formularesponse,
7144: stringresponse, imageresponse, reactionresponse,
7145: and organicresponse type problem parts can have
1.503 raeburn 7146: multiple lines per response if the weight
7147: assigned exceeds 10. In this case, only
7148: one bubble per line is permitted, but more
7149: than one line might contain bubbles, e.g.
7150: bubbling of: line 1 - J, line 2 - J,
7151: line 3 - B would assign 22 points.
1.497 foxr 7152:
7153: =cut
7154:
7155: sub prompt_for_corrections {
1.503 raeburn 7156: my ($r, $question, $scan_config, $scan_record, $error) = @_;
7157: my ($current_line,$lines);
7158: my @linenums;
7159: my $questionnum = $question;
7160: if ($question =~ /^(\d+)\.(\d+)$/) {
7161: $question = $1;
7162: $current_line = $first_bubble_line{$question-1} + 1 ;
7163: my $subquestion = $2;
7164: my @subans = split(/,/,$subdivided_bubble_lines{$question-1});
7165: my $subcount = 1;
7166: while ($subcount<$subquestion) {
7167: $current_line += $subans[$subcount-1];
7168: $subcount ++;
7169: }
7170: $lines = $subans[$subquestion-1];
7171: } else {
7172: $current_line = $first_bubble_line{$question-1} + 1 ;
7173: $lines = $bubble_lines_per_response{$question-1};
7174: }
1.497 foxr 7175: if ($lines > 1) {
1.503 raeburn 7176: $r->print(&mt('The group of bubble lines below responds to a single question.').'<br />');
7177: if (($responsetype_per_response{$question-1} eq 'essayresponse') ||
7178: ($responsetype_per_response{$question-1} eq 'formularesponse') ||
1.510 raeburn 7179: ($responsetype_per_response{$question-1} eq 'stringresponse') ||
7180: ($responsetype_per_response{$question-1} eq 'imageresponse') ||
7181: ($responsetype_per_response{$question-1} eq 'reactionresponse') ||
7182: ($responsetype_per_response{$question-1} eq 'organicresponse')) {
1.572 www 7183: $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 7184: } else {
7185: $r->print(&mt("Select at most one bubble in a single line and select 'No Bubble' in all the other lines. ")."<br />");
7186: }
1.497 foxr 7187: }
7188: for (my $i =0; $i < $lines; $i++) {
1.503 raeburn 7189: my $selected = $$scan_record{"scantron.$current_line.answer"};
7190: &scantron_bubble_selector($r,$scan_config,$current_line,
7191: $questionnum,$error,split('', $selected));
1.524 raeburn 7192: push(@linenums,$current_line);
1.497 foxr 7193: $current_line++;
7194: }
7195: if ($lines > 1) {
7196: $r->print("<hr /><br />");
7197: }
1.503 raeburn 7198: return @linenums;
1.157 albertel 7199: }
1.423 albertel 7200:
7201: =pod
7202:
7203: =item scantron_bubble_selector
7204:
7205: Generates the html radiobuttons to correct a single bubble line
1.424 albertel 7206: possibly showing the existing the selected bubbles if known
1.423 albertel 7207:
7208: Arguments:
7209: $r - Apache request object
7210: $scan_config - hash from &get_scantron_config()
1.497 foxr 7211: $line - Number of the line being displayed.
1.503 raeburn 7212: $questionnum - Question number (may include subquestion)
7213: $error - Type of error.
1.497 foxr 7214: @selected - Array of bubbles picked on this line.
1.423 albertel 7215:
7216: =cut
7217:
1.157 albertel 7218: sub scantron_bubble_selector {
1.503 raeburn 7219: my ($r,$scan_config,$line,$questionnum,$error,@selected)=@_;
1.157 albertel 7220: my $max=$$scan_config{'Qlength'};
1.274 albertel 7221:
7222: my $scmode=$$scan_config{'Qon'};
7223: if ($scmode eq 'number' || $scmode eq 'letter') { $max=10; }
7224:
1.157 albertel 7225: my @alphabet=('A'..'Z');
1.503 raeburn 7226: $r->print(&Apache::loncommon::start_data_table().
7227: &Apache::loncommon::start_data_table_row());
7228: $r->print('<td rowspan="2" class="LC_leftcol_header">'.$line.'</td>');
1.497 foxr 7229: for (my $i=0;$i<$max+1;$i++) {
7230: $r->print("\n".'<td align="center">');
7231: if ($selected[0] eq $alphabet[$i]) { $r->print('X'); shift(@selected) }
7232: else { $r->print(' '); }
7233: $r->print('</td>');
7234: }
1.503 raeburn 7235: $r->print(&Apache::loncommon::end_data_table_row().
7236: &Apache::loncommon::start_data_table_row());
1.497 foxr 7237: for (my $i=0;$i<$max;$i++) {
7238: $r->print("\n".
7239: '<td><label><input type="radio" name="scantron_correct_Q_'.
7240: $line.'" value="'.$i.'" />'.$alphabet[$i]."</label></td>");
7241: }
1.503 raeburn 7242: my $nobub_checked = ' ';
7243: if ($error eq 'missingbubble') {
7244: $nobub_checked = ' checked = "checked" ';
7245: }
7246: $r->print("\n".'<td><label><input type="radio" name="scantron_correct_Q_'.
7247: $line.'" value="none"'.$nobub_checked.'/>'.&mt('No bubble').
7248: '</label>'."\n".'<input type="hidden" name="scantron_questionnum_Q_'.
7249: $line.'" value="'.$questionnum.'" /></td>');
7250: $r->print(&Apache::loncommon::end_data_table_row().
7251: &Apache::loncommon::end_data_table());
1.157 albertel 7252: }
7253:
1.423 albertel 7254: =pod
7255:
7256: =item num_matches
7257:
1.424 albertel 7258: Counts the number of characters that are the same between the two arguments.
7259:
7260: Arguments:
7261: $orig - CODE from the scanline
7262: $code - CODE to match against
7263:
7264: Returns:
7265: $count - integer count of the number of same characters between the
7266: two arguments
7267:
1.423 albertel 7268: =cut
7269:
1.194 albertel 7270: sub num_matches {
7271: my ($orig,$code) = @_;
7272: my @code=split(//,$code);
7273: my @orig=split(//,$orig);
7274: my $same=0;
7275: for (my $i=0;$i<scalar(@code);$i++) {
7276: if ($code[$i] eq $orig[$i]) { $same++; }
7277: }
7278: return $same;
7279: }
7280:
1.423 albertel 7281: =pod
7282:
7283: =item scantron_get_closely_matching_CODEs
7284:
1.424 albertel 7285: Cycles through all CODEs and finds the set that has the greatest
7286: number of same characters as the provided CODE
7287:
7288: Arguments:
7289: $allcodes - hash ref returned by &get_codes()
7290: $CODE - CODE from the current scanline
7291:
7292: Returns:
7293: 2 element list
7294: - first elements is number of how closely matching the best fit is
7295: (5 means best set has 5 matching characters)
7296: - second element is an arrary ref containing the set of valid CODEs
7297: that best fit the passed in CODE
7298:
1.423 albertel 7299: =cut
7300:
1.194 albertel 7301: sub scantron_get_closely_matching_CODEs {
7302: my ($allcodes,$CODE)=@_;
7303: my @CODEs;
7304: foreach my $testcode (sort(keys(%{$allcodes}))) {
7305: push(@{$CODEs[&num_matches($CODE,$testcode)]},$testcode);
7306: }
7307:
7308: return ($#CODEs,$CODEs[-1]);
7309: }
7310:
1.423 albertel 7311: =pod
7312:
7313: =item get_codes
7314:
1.424 albertel 7315: Builds a hash which has keys of all of the valid CODEs from the selected
7316: set of remembered CODEs.
7317:
7318: Arguments:
7319: $old_name - name of the set of remembered CODEs
7320: $cdom - domain of the course
7321: $cnum - internal course name
7322:
7323: Returns:
7324: %allcodes - keys are the valid CODEs, values are all 1
7325:
1.423 albertel 7326: =cut
7327:
1.194 albertel 7328: sub get_codes {
1.280 foxr 7329: my ($old_name, $cdom, $cnum) = @_;
7330: if (!$old_name) {
7331: $old_name=$env{'form.scantron_CODElist'};
7332: }
7333: if (!$cdom) {
7334: $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
7335: }
7336: if (!$cnum) {
7337: $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
7338: }
1.278 albertel 7339: my %result=&Apache::lonnet::get('CODEs',[$old_name,"type\0$old_name"],
7340: $cdom,$cnum);
7341: my %allcodes;
7342: if ($result{"type\0$old_name"} eq 'number') {
7343: %allcodes=map {($_,1)} split(',',$result{$old_name});
7344: } else {
7345: %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
7346: }
1.194 albertel 7347: return %allcodes;
7348: }
7349:
1.423 albertel 7350: =pod
7351:
7352: =item scantron_validate_CODE
7353:
1.424 albertel 7354: Validates all scanlines in the selected file to not have any
7355: invalid or underspecified CODEs and that none of the codes are
7356: duplicated if this was requested.
7357:
1.423 albertel 7358: =cut
7359:
1.157 albertel 7360: sub scantron_validate_CODE {
7361: my ($r,$currentphase) = @_;
1.257 albertel 7362: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.186 albertel 7363: if ($scantron_config{'CODElocation'} &&
7364: $scantron_config{'CODEstart'} &&
7365: $scantron_config{'CODElength'}) {
1.257 albertel 7366: if (!defined($env{'form.scantron_CODElist'})) {
1.186 albertel 7367: &FIXME_blow_up()
7368: }
7369: } else {
7370: return (0,$currentphase+1);
7371: }
7372:
7373: my %usedCODEs;
7374:
1.194 albertel 7375: my %allcodes=&get_codes();
1.186 albertel 7376:
1.582 raeburn 7377: my $nav_error;
7378: &scantron_get_maxbubble(\$nav_error); # parse needs the lines per response array.
7379: if ($nav_error) {
7380: $r->print(&navmap_errormsg());
7381: return(1,$currentphase);
7382: }
1.447 foxr 7383:
1.186 albertel 7384: my ($scanlines,$scan_data)=&scantron_getfile();
7385: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7386: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.186 albertel 7387: if ($line=~/^[\s\cz]*$/) { next; }
7388: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7389: $scan_data);
7390: my $CODE=$$scan_record{'scantron.CODE'};
7391: my $error=0;
1.224 albertel 7392: if (!&Apache::lonnet::validCODE($CODE)) {
7393: &scantron_get_correction($r,$i,$scan_record,
7394: \%scantron_config,
7395: $line,'incorrectCODE',\%allcodes);
7396: return(1,$currentphase);
7397: }
1.221 albertel 7398: if (%allcodes && !exists($allcodes{$CODE})
7399: && !$$scan_record{'scantron.useCODE'}) {
1.186 albertel 7400: &scantron_get_correction($r,$i,$scan_record,
7401: \%scantron_config,
1.194 albertel 7402: $line,'incorrectCODE',\%allcodes);
7403: return(1,$currentphase);
1.186 albertel 7404: }
1.214 albertel 7405: if (exists($usedCODEs{$CODE})
1.257 albertel 7406: && $env{'form.scantron_CODEunique'} eq 'yes'
1.192 albertel 7407: && !$$scan_record{'scantron.CODE_ignore_dup'}) {
1.186 albertel 7408: &scantron_get_correction($r,$i,$scan_record,
7409: \%scantron_config,
1.194 albertel 7410: $line,'duplicateCODE',$usedCODEs{$CODE});
7411: return(1,$currentphase);
1.186 albertel 7412: }
1.524 raeburn 7413: push(@{$usedCODEs{$CODE}},$$scan_record{'scantron.PaperID'});
1.186 albertel 7414: }
1.157 albertel 7415: return (0,$currentphase+1);
7416: }
7417:
1.423 albertel 7418: =pod
7419:
7420: =item scantron_validate_doublebubble
7421:
1.424 albertel 7422: Validates all scanlines in the selected file to not have any
7423: bubble lines with multiple bubbles marked.
7424:
1.423 albertel 7425: =cut
7426:
1.157 albertel 7427: sub scantron_validate_doublebubble {
7428: my ($r,$currentphase) = @_;
7429: #get student info
7430: my $classlist=&Apache::loncoursedata::get_classlist();
7431: my %idmap=&username_to_idmap($classlist);
7432:
7433: #get scantron line setup
1.257 albertel 7434: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7435: my ($scanlines,$scan_data)=&scantron_getfile();
1.583 raeburn 7436: my $nav_error;
7437: &scantron_get_maxbubble(\$nav_error); # parse needs the bubble line array.
7438: if ($nav_error) {
7439: $r->print(&navmap_errormsg());
7440: return(1,$currentphase);
7441: }
1.447 foxr 7442:
1.157 albertel 7443: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7444: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7445: if ($line=~/^[\s\cz]*$/) { next; }
7446: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7447: $scan_data);
7448: if (!defined($$scan_record{'scantron.doubleerror'})) { next; }
7449: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,$line,
7450: 'doublebubble',
7451: $$scan_record{'scantron.doubleerror'});
7452: return (1,$currentphase);
7453: }
7454: return (0,$currentphase+1);
7455: }
7456:
1.423 albertel 7457:
1.503 raeburn 7458: sub scantron_get_maxbubble {
1.582 raeburn 7459: my ($nav_error) = @_;
1.257 albertel 7460: if (defined($env{'form.scantron_maxbubble'}) &&
7461: $env{'form.scantron_maxbubble'}) {
1.447 foxr 7462: &restore_bubble_lines();
1.257 albertel 7463: return $env{'form.scantron_maxbubble'};
1.191 albertel 7464: }
1.330 albertel 7465:
1.447 foxr 7466: my (undef, undef, $sequence) =
1.257 albertel 7467: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.330 albertel 7468:
1.447 foxr 7469: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 7470: unless (ref($navmap)) {
7471: if (ref($nav_error)) {
7472: $$nav_error = 1;
7473: }
1.591 raeburn 7474: return;
1.582 raeburn 7475: }
1.191 albertel 7476: my $map=$navmap->getResourceByUrl($sequence);
7477: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.330 albertel 7478:
7479: &Apache::lonxml::clear_problem_counter();
7480:
1.557 raeburn 7481: my $uname = $env{'user.name'};
7482: my $udom = $env{'user.domain'};
1.435 foxr 7483: my $cid = $env{'request.course.id'};
7484: my $total_lines = 0;
7485: %bubble_lines_per_response = ();
1.447 foxr 7486: %first_bubble_line = ();
1.503 raeburn 7487: %subdivided_bubble_lines = ();
7488: %responsetype_per_response = ();
1.554 raeburn 7489:
1.447 foxr 7490: my $response_number = 0;
7491: my $bubble_line = 0;
1.191 albertel 7492: foreach my $resource (@resources) {
1.542 raeburn 7493: my ($analysis,$parts) = &scantron_partids_tograde($resource,$cid,$uname,$udom);
7494: if ((ref($analysis) eq 'HASH') && (ref($parts) eq 'ARRAY')) {
7495: foreach my $part_id (@{$parts}) {
7496: my $lines;
7497:
7498: # TODO - make this a persistent hash not an array.
7499:
7500: # optionresponse, matchresponse and rankresponse type items
7501: # render as separate sub-questions in exam mode.
7502: if (($analysis->{$part_id.'.type'} eq 'optionresponse') ||
7503: ($analysis->{$part_id.'.type'} eq 'matchresponse') ||
7504: ($analysis->{$part_id.'.type'} eq 'rankresponse')) {
7505: my ($numbub,$numshown);
7506: if ($analysis->{$part_id.'.type'} eq 'optionresponse') {
7507: if (ref($analysis->{$part_id.'.options'}) eq 'ARRAY') {
7508: $numbub = scalar(@{$analysis->{$part_id.'.options'}});
7509: }
7510: } elsif ($analysis->{$part_id.'.type'} eq 'matchresponse') {
7511: if (ref($analysis->{$part_id.'.items'}) eq 'ARRAY') {
7512: $numbub = scalar(@{$analysis->{$part_id.'.items'}});
7513: }
7514: } elsif ($analysis->{$part_id.'.type'} eq 'rankresponse') {
7515: if (ref($analysis->{$part_id.'.foils'}) eq 'ARRAY') {
7516: $numbub = scalar(@{$analysis->{$part_id.'.foils'}});
7517: }
7518: }
7519: if (ref($analysis->{$part_id.'.shown'}) eq 'ARRAY') {
7520: $numshown = scalar(@{$analysis->{$part_id.'.shown'}});
7521: }
7522: my $bubbles_per_line = 10;
7523: my $inner_bubble_lines = int($numbub/$bubbles_per_line);
7524: if (($numbub % $bubbles_per_line) != 0) {
7525: $inner_bubble_lines++;
7526: }
7527: for (my $i=0; $i<$numshown; $i++) {
7528: $subdivided_bubble_lines{$response_number} .=
7529: $inner_bubble_lines.',';
7530: }
7531: $subdivided_bubble_lines{$response_number} =~ s/,$//;
7532: $lines = $numshown * $inner_bubble_lines;
7533: } else {
7534: $lines = $analysis->{"$part_id.bubble_lines"};
7535: }
7536:
7537: $first_bubble_line{$response_number} = $bubble_line;
7538: $bubble_lines_per_response{$response_number} = $lines;
7539: $responsetype_per_response{$response_number} =
7540: $analysis->{$part_id.'.type'};
7541: $response_number++;
7542:
7543: $bubble_line += $lines;
7544: $total_lines += $lines;
7545: }
7546: }
7547: }
1.552 raeburn 7548: &Apache::lonnet::delenv('scantron.');
1.542 raeburn 7549:
7550: &save_bubble_lines();
7551: $env{'form.scantron_maxbubble'} =
7552: $total_lines;
7553: return $env{'form.scantron_maxbubble'};
7554: }
1.523 raeburn 7555:
1.157 albertel 7556: sub scantron_validate_missingbubbles {
7557: my ($r,$currentphase) = @_;
7558: #get student info
7559: my $classlist=&Apache::loncoursedata::get_classlist();
7560: my %idmap=&username_to_idmap($classlist);
7561:
7562: #get scantron line setup
1.257 albertel 7563: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7564: my ($scanlines,$scan_data)=&scantron_getfile();
1.582 raeburn 7565: my $nav_error;
7566: my $max_bubble=&scantron_get_maxbubble(\$nav_error);
7567: if ($nav_error) {
7568: return(1,$currentphase);
7569: }
1.157 albertel 7570: if (!$max_bubble) { $max_bubble=2**31; }
7571: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7572: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7573: if ($line=~/^[\s\cz]*$/) { next; }
7574: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7575: $scan_data);
7576: if (!defined($$scan_record{'scantron.missingerror'})) { next; }
7577: my @to_correct;
1.470 foxr 7578:
7579: # Probably here's where the error is...
7580:
1.157 albertel 7581: foreach my $missing (@{$$scan_record{'scantron.missingerror'}}) {
1.505 raeburn 7582: my $lastbubble;
7583: if ($missing =~ /^(\d+)\.(\d+)$/) {
7584: my $question = $1;
7585: my $subquestion = $2;
7586: if (!defined($first_bubble_line{$question -1})) { next; }
7587: my $first = $first_bubble_line{$question-1};
7588: my @subans = split(/,/,$subdivided_bubble_lines{$question-1});
7589: my $subcount = 1;
7590: while ($subcount<$subquestion) {
7591: $first += $subans[$subcount-1];
7592: $subcount ++;
7593: }
7594: my $count = $subans[$subquestion-1];
7595: $lastbubble = $first + $count;
7596: } else {
7597: if (!defined($first_bubble_line{$missing - 1})) { next; }
7598: $lastbubble = $first_bubble_line{$missing - 1} + $bubble_lines_per_response{$missing - 1};
7599: }
7600: if ($lastbubble > $max_bubble) { next; }
1.157 albertel 7601: push(@to_correct,$missing);
7602: }
7603: if (@to_correct) {
7604: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
7605: $line,'missingbubble',\@to_correct);
7606: return (1,$currentphase);
7607: }
7608:
7609: }
7610: return (0,$currentphase+1);
7611: }
7612:
1.423 albertel 7613:
1.82 albertel 7614: sub scantron_process_students {
1.75 albertel 7615: my ($r) = @_;
1.513 foxr 7616:
1.257 albertel 7617: my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($env{'form.selectpage'});
1.324 albertel 7618: my ($symb)=&get_symb($r);
1.513 foxr 7619: if (!$symb) {
7620: return '';
7621: }
1.324 albertel 7622: my $default_form_data=&defaultFormData($symb);
1.82 albertel 7623:
1.257 albertel 7624: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7625: my ($scanlines,$scan_data)=&scantron_getfile();
1.82 albertel 7626: my $classlist=&Apache::loncoursedata::get_classlist();
7627: my %idmap=&username_to_idmap($classlist);
1.132 bowersj2 7628: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 7629: unless (ref($navmap)) {
7630: $r->print(&navmap_errormsg());
7631: return '';
7632: }
1.83 albertel 7633: my $map=$navmap->getResourceByUrl($sequence);
7634: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.557 raeburn 7635: my (%grader_partids_by_symb,%grader_randomlists_by_symb);
7636: &graders_resources_pass(\@resources,\%grader_partids_by_symb,
7637: \%grader_randomlists_by_symb);
1.586 raeburn 7638: my $resource_error;
1.557 raeburn 7639: foreach my $resource (@resources) {
1.586 raeburn 7640: my $ressymb;
7641: if (ref($resource)) {
7642: $ressymb = $resource->symb();
7643: } else {
7644: $resource_error = 1;
7645: last;
7646: }
1.557 raeburn 7647: my ($analysis,$parts) =
7648: &scantron_partids_tograde($resource,$env{'request.course.id'},
7649: $env{'user.name'},$env{'user.domain'},1);
7650: $grader_partids_by_symb{$ressymb} = $parts;
7651: if (ref($analysis) eq 'HASH') {
7652: if (ref($analysis->{'parts_withrandomlist'}) eq 'ARRAY') {
7653: $grader_randomlists_by_symb{$ressymb} =
7654: $analysis->{'parts_withrandomlist'};
7655: }
7656: }
7657: }
1.586 raeburn 7658: if ($resource_error) {
7659: $r->print(&navmap_errormsg());
7660: return '';
7661: }
1.557 raeburn 7662:
1.554 raeburn 7663: my ($uname,$udom);
1.82 albertel 7664: my $result= <<SCANTRONFORM;
1.81 albertel 7665: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
7666: <input type="hidden" name="command" value="scantron_configphase" />
7667: $default_form_data
7668: SCANTRONFORM
1.82 albertel 7669: $r->print($result);
7670:
7671: my @delayqueue;
1.542 raeburn 7672: my (%completedstudents,%scandata);
1.140 albertel 7673:
1.520 www 7674: my $lock=&Apache::lonnet::set_lock(&mt('Grading bubblesheet exam'));
1.200 albertel 7675: my $count=&get_todo_count($scanlines,$scan_data);
1.575 www 7676: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Bubblesheet Status',
7677: 'Bubblesheet Progress',$count,
1.195 albertel 7678: 'inline',undef,'scantronupload');
1.140 albertel 7679: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
7680: 'Processing first student');
1.542 raeburn 7681: $r->print('<br />');
1.140 albertel 7682: my $start=&Time::HiRes::time();
1.158 albertel 7683: my $i=-1;
1.542 raeburn 7684: my $started;
1.447 foxr 7685:
1.582 raeburn 7686: my $nav_error;
7687: &scantron_get_maxbubble(\$nav_error); # Need the bubble lines array to parse.
7688: if ($nav_error) {
7689: $r->print(&navmap_errormsg());
7690: return '';
7691: }
7692:
1.513 foxr 7693: # If an ssi failed in scantron_get_maxbubble, put an error message out to
7694: # the user and return.
7695:
7696: if ($ssi_error) {
7697: $r->print("</form>");
7698: &ssi_print_error($r);
7699: $r->print(&show_grading_menu_form($symb));
1.520 www 7700: &Apache::lonnet::remove_lock($lock);
1.513 foxr 7701: return ''; # Dunno why the other returns return '' rather than just returning.
7702: }
1.447 foxr 7703:
1.542 raeburn 7704: my %lettdig = &letter_to_digits();
7705: my $numletts = scalar(keys(%lettdig));
7706:
1.157 albertel 7707: while ($i<$scanlines->{'count'}) {
7708: ($uname,$udom)=('','');
7709: $i++;
1.200 albertel 7710: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7711: if ($line=~/^[\s\cz]*$/) { next; }
1.200 albertel 7712: if ($started) {
7713: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
7714: 'last student');
7715: }
7716: $started=1;
1.157 albertel 7717: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7718: $scan_data);
7719: unless ($uname=&scantron_find_student($scan_record,$scan_data,
7720: \%idmap,$i)) {
7721: &scantron_add_delay(\@delayqueue,$line,
7722: 'Unable to find a student that matches',1);
7723: next;
7724: }
7725: if (exists $completedstudents{$uname}) {
7726: &scantron_add_delay(\@delayqueue,$line,
7727: 'Student '.$uname.' has multiple sheets',2);
7728: next;
7729: }
7730: ($uname,$udom)=split(/:/,$uname);
1.330 albertel 7731:
1.586 raeburn 7732: my (%partids_by_symb,$res_error);
1.554 raeburn 7733: foreach my $resource (@resources) {
1.586 raeburn 7734: my $ressymb;
7735: if (ref($resource)) {
7736: $ressymb = $resource->symb();
7737: } else {
7738: $res_error = 1;
7739: last;
7740: }
1.557 raeburn 7741: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
7742: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
7743: my ($analysis,$parts) =
7744: &scantron_partids_tograde($resource,$env{'request.course.id'},$uname,$udom);
7745: $partids_by_symb{$ressymb} = $parts;
7746: } else {
7747: $partids_by_symb{$ressymb} = $grader_partids_by_symb{$ressymb};
7748: }
1.554 raeburn 7749: }
7750:
1.586 raeburn 7751: if ($res_error) {
7752: &scantron_add_delay(\@delayqueue,$line,
7753: 'An error occurred while grading student '.$uname,2);
7754: next;
7755: }
7756:
1.330 albertel 7757: &Apache::lonxml::clear_problem_counter();
1.514 raeburn 7758: &Apache::lonnet::appenv($scan_record);
1.376 albertel 7759:
7760: if (&scantron_clear_skip($scanlines,$scan_data,$i)) {
7761: &scantron_putfile($scanlines,$scan_data);
7762: }
1.161 albertel 7763:
1.542 raeburn 7764: my $scancode;
7765: if ((exists($scan_record->{'scantron.CODE'})) &&
7766: (&Apache::lonnet::validCODE($scan_record->{'scantron.CODE'}))) {
7767: $scancode = $scan_record->{'scantron.CODE'};
7768: } else {
7769: $scancode = '';
7770: }
7771:
7772: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
1.554 raeburn 7773: \@resources,\%partids_by_symb) eq 'ssi_error') {
1.542 raeburn 7774: $ssi_error = 0; # So end of handler error message does not trigger.
7775: $r->print("</form>");
7776: &ssi_print_error($r);
7777: $r->print(&show_grading_menu_form($symb));
7778: &Apache::lonnet::remove_lock($lock);
7779: return ''; # Why return ''? Beats me.
7780: }
1.513 foxr 7781:
1.140 albertel 7782: $completedstudents{$uname}={'line'=>$line};
1.542 raeburn 7783: if ($env{'form.verifyrecord'}) {
7784: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
7785: my $studentdata = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
7786: chomp($studentdata);
7787: $studentdata =~ s/\r$//;
7788: my $studentrecord = '';
7789: my $counter = -1;
7790: foreach my $resource (@resources) {
1.554 raeburn 7791: my $ressymb = $resource->symb();
1.542 raeburn 7792: ($counter,my $recording) =
7793: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 7794: $counter,$studentdata,$partids_by_symb{$ressymb},
1.542 raeburn 7795: \%scantron_config,\%lettdig,$numletts);
7796: $studentrecord .= $recording;
7797: }
7798: if ($studentrecord ne $studentdata) {
1.554 raeburn 7799: &Apache::lonxml::clear_problem_counter();
7800: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
7801: \@resources,\%partids_by_symb) eq 'ssi_error') {
7802: $ssi_error = 0; # So end of handler error message does not trigger.
7803: $r->print("</form>");
7804: &ssi_print_error($r);
7805: $r->print(&show_grading_menu_form($symb));
7806: &Apache::lonnet::remove_lock($lock);
7807: delete($completedstudents{$uname});
7808: return '';
7809: }
1.542 raeburn 7810: $counter = -1;
7811: $studentrecord = '';
7812: foreach my $resource (@resources) {
1.554 raeburn 7813: my $ressymb = $resource->symb();
1.542 raeburn 7814: ($counter,my $recording) =
7815: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 7816: $counter,$studentdata,$partids_by_symb{$ressymb},
1.542 raeburn 7817: \%scantron_config,\%lettdig,$numletts);
7818: $studentrecord .= $recording;
7819: }
7820: if ($studentrecord ne $studentdata) {
7821: $r->print('<p><span class="LC_error">');
7822: if ($scancode eq '') {
7823: $r->print(&mt('Mismatch grading bubble sheet for user: [_1] with ID: [_2].',
7824: $uname.':'.$udom,$scan_record->{'scantron.ID'}));
7825: } else {
7826: $r->print(&mt('Mismatch grading bubble sheet for user: [_1] with ID: [_2] and CODE: [_3].',
7827: $uname.':'.$udom,$scan_record->{'scantron.ID'},$scancode));
7828: }
7829: $r->print('</span><br />'.&Apache::loncommon::start_data_table()."\n".
7830: &Apache::loncommon::start_data_table_header_row()."\n".
7831: '<th>'.&mt('Source').'</th><th>'.&mt('Bubbled responses').'</th>'.
7832: &Apache::loncommon::end_data_table_header_row()."\n".
7833: &Apache::loncommon::start_data_table_row().
7834: '<td>'.&mt('Bubble Sheet').'</td>'.
7835: '<td><span class="LC_nobreak">'.$studentdata.'</span></td>'.
7836: &Apache::loncommon::end_data_table_row().
7837: &Apache::loncommon::start_data_table_row().
7838: '<td>Stored submissions</td>'.
7839: '<td><span class="LC_nobreak">'.$studentrecord.'</span></td>'."\n".
7840: &Apache::loncommon::end_data_table_row().
7841: &Apache::loncommon::end_data_table().'</p>');
7842: } else {
7843: $r->print('<br /><span class="LC_warning">'.
7844: &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 />'.
7845: &mt("As a consequence, this user's submission history records two tries.").
7846: '</span><br />');
7847: }
7848: }
7849: }
1.543 raeburn 7850: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.140 albertel 7851: } continue {
1.330 albertel 7852: &Apache::lonxml::clear_problem_counter();
1.552 raeburn 7853: &Apache::lonnet::delenv('scantron.');
1.82 albertel 7854: }
1.140 albertel 7855: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.520 www 7856: &Apache::lonnet::remove_lock($lock);
1.172 albertel 7857: # my $lasttime = &Time::HiRes::time()-$start;
7858: # $r->print("<p>took $lasttime</p>");
1.140 albertel 7859:
1.200 albertel 7860: $r->print("</form>");
1.324 albertel 7861: $r->print(&show_grading_menu_form($symb));
1.157 albertel 7862: return '';
1.75 albertel 7863: }
1.157 albertel 7864:
1.557 raeburn 7865: sub graders_resources_pass {
7866: my ($resources,$grader_partids_by_symb,$grader_randomlists_by_symb) = @_;
7867: if ((ref($resources) eq 'ARRAY') && (ref($grader_partids_by_symb)) &&
7868: (ref($grader_randomlists_by_symb) eq 'HASH')) {
7869: foreach my $resource (@{$resources}) {
7870: my $ressymb = $resource->symb();
7871: my ($analysis,$parts) =
7872: &scantron_partids_tograde($resource,$env{'request.course.id'},
7873: $env{'user.name'},$env{'user.domain'},1);
7874: $grader_partids_by_symb->{$ressymb} = $parts;
7875: if (ref($analysis) eq 'HASH') {
7876: if (ref($analysis->{'parts_withrandomlist'}) eq 'ARRAY') {
7877: $grader_randomlists_by_symb->{$ressymb} =
7878: $analysis->{'parts_withrandomlist'};
7879: }
7880: }
7881: }
7882: }
7883: return;
7884: }
7885:
1.542 raeburn 7886: sub grade_student_bubbles {
1.554 raeburn 7887: my ($r,$uname,$udom,$scan_record,$scancode,$resources,$parts) = @_;
7888: if (ref($resources) eq 'ARRAY') {
7889: my $count = 0;
7890: foreach my $resource (@{$resources}) {
7891: my $ressymb = $resource->symb();
7892: my %form = ('submitted' => 'scantron',
7893: 'grade_target' => 'grade',
7894: 'grade_username' => $uname,
7895: 'grade_domain' => $udom,
7896: 'grade_courseid' => $env{'request.course.id'},
7897: 'grade_symb' => $ressymb,
7898: 'CODE' => $scancode
7899: );
7900: if (ref($parts) eq 'HASH') {
7901: if (ref($parts->{$ressymb}) eq 'ARRAY') {
7902: foreach my $part (@{$parts->{$ressymb}}) {
7903: $form{'scantron_questnum_start.'.$part} =
7904: 1+$env{'form.scantron.first_bubble_line.'.$count};
7905: $count++;
7906: }
7907: }
7908: }
7909: my $result=&ssi_with_retries($resource->src(),$ssi_retries,%form);
7910: return 'ssi_error' if ($ssi_error);
7911: last if (&Apache::loncommon::connection_aborted($r));
7912: }
1.542 raeburn 7913: }
7914: return;
7915: }
7916:
1.157 albertel 7917: sub scantron_upload_scantron_data {
7918: my ($r)=@_;
1.565 raeburn 7919: my $dom = $env{'request.role.domain'};
7920: my $domdesc = &Apache::lonnet::domain($dom,'description');
7921: $r->print(&Apache::loncommon::coursebrowser_javascript($dom));
1.157 albertel 7922: my $select_link=&Apache::loncommon::selectcourse_link('rules','courseid',
1.181 albertel 7923: 'domainid',
1.565 raeburn 7924: 'coursename',$dom);
7925: my $syllabuslink = '<a href="javascript:ToSyllabus();">'.&mt('Syllabus').'</a>'.
7926: (' 'x2).&mt('(shows course personnel)');
1.324 albertel 7927: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.579 raeburn 7928: my $nofile_alert = &mt('Please use the browse button to select a file from your local directory.');
7929: 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 7930: $r->print('
1.157 albertel 7931: <script type="text/javascript" language="javascript">
7932: function checkUpload(formname) {
7933: if (formname.upfile.value == "") {
1.579 raeburn 7934: alert("'.$nofile_alert.'");
1.157 albertel 7935: return false;
7936: }
1.565 raeburn 7937: if (formname.courseid.value == "") {
1.579 raeburn 7938: alert("'.$nocourseid_alert.'");
1.565 raeburn 7939: return false;
7940: }
1.157 albertel 7941: formname.submit();
7942: }
1.565 raeburn 7943:
7944: function ToSyllabus() {
7945: var cdom = '."'$dom'".';
7946: var cnum = document.rules.courseid.value;
7947: if (cdom == "" || cdom == null) {
7948: return;
7949: }
7950: if (cnum == "" || cnum == null) {
7951: return;
7952: }
7953: syllwin=window.open("/public/"+cdom+"/"+cnum+"/syllabus","LONCAPASyllabus",
7954: "height=350,width=350,scrollbars=yes,menubar=no");
7955: return;
7956: }
7957:
1.157 albertel 7958: </script>
7959:
1.566 raeburn 7960: <h3>'.&mt('Send scanned bubblesheet data to a course').'</h3>
7961:
1.492 albertel 7962: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
1.565 raeburn 7963: '.$default_form_data.
7964: &Apache::lonhtmlcommon::start_pick_box().
7965: &Apache::lonhtmlcommon::row_title(&mt('Course ID')).
7966: '<input name="courseid" type="text" size="30" />'.$select_link.
7967: &Apache::lonhtmlcommon::row_closure().
7968: &Apache::lonhtmlcommon::row_title(&mt('Course Name')).
7969: '<input name="coursename" type="text" size="30" />'.$syllabuslink.
7970: &Apache::lonhtmlcommon::row_closure().
7971: &Apache::lonhtmlcommon::row_title(&mt('Domain')).
7972: '<input name="domainid" type="hidden" />'.$domdesc.
7973: &Apache::lonhtmlcommon::row_closure().
7974: &Apache::lonhtmlcommon::row_title(&mt('File to upload')).
7975: '<input type="file" name="upfile" size="50" />'.
7976: &Apache::lonhtmlcommon::row_closure(1).
7977: &Apache::lonhtmlcommon::end_pick_box().'<br />
7978:
1.492 albertel 7979: <input name="command" value="scantronupload_save" type="hidden" />
1.589 bisitz 7980: <input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
1.157 albertel 7981: </form>
1.492 albertel 7982: ');
1.157 albertel 7983: return '';
7984: }
7985:
1.423 albertel 7986:
1.157 albertel 7987: sub scantron_upload_scantron_data_save {
7988: my($r)=@_;
1.324 albertel 7989: my ($symb)=&get_symb($r,1);
1.182 albertel 7990: my $doanotherupload=
7991: '<br /><form action="/adm/grades" method="post">'."\n".
7992: '<input type="hidden" name="command" value="scantronupload" />'."\n".
1.492 albertel 7993: '<input type="submit" name="submit" value="'.&mt('Do Another Upload').'" />'."\n".
1.182 albertel 7994: '</form>'."\n";
1.257 albertel 7995: if (!&Apache::lonnet::allowed('usc',$env{'form.domainid'}) &&
1.162 albertel 7996: !&Apache::lonnet::allowed('usc',
1.257 albertel 7997: $env{'form.domainid'}.'_'.$env{'form.courseid'})) {
1.575 www 7998: $r->print(&mt("You are not allowed to upload bubblesheet data to the requested course.")."<br />");
1.182 albertel 7999: if ($symb) {
1.324 albertel 8000: $r->print(&show_grading_menu_form($symb));
1.182 albertel 8001: } else {
8002: $r->print($doanotherupload);
8003: }
1.162 albertel 8004: return '';
8005: }
1.257 albertel 8006: my %coursedata=&Apache::lonnet::coursedescription($env{'form.domainid'}.'_'.$env{'form.courseid'});
1.568 raeburn 8007: my $uploadedfile;
1.567 raeburn 8008: $r->print('<h3>'.&mt("Uploading file to [_1]",$coursedata{'description'}).'</h3>');
1.257 albertel 8009: if (length($env{'form.upfile'}) < 2) {
1.568 raeburn 8010: $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 8011: } else {
1.568 raeburn 8012: my $result =
8013: &Apache::lonnet::userfileupload('upfile','','scantron','','','',
8014: $env{'form.courseid'},$env{'form.domainid'});
8015: if ($result =~ m{^/uploaded/}) {
1.567 raeburn 8016: $r->print(&mt('[_1]Success:[_2] Successfully uploaded [_3] bytes of data into location: [_4]',
8017: '<span class="LC_success">','</span>',(length($env{'form.upfile'})-1),
8018: '<span class="LC_filename">'.$result.'</span>'));
1.568 raeburn 8019: ($uploadedfile) = ($result =~ m{/([^/]+)$});
1.567 raeburn 8020: $r->print(&validate_uploaded_scantron_file($env{'form.domainid'},
1.568 raeburn 8021: $env{'form.courseid'},$uploadedfile));
1.210 albertel 8022: } else {
1.567 raeburn 8023: $r->print(&mt('[_1]Error:[_2] An error ([_3]) occurred when attempting to upload the file, [_4]',
8024: '<span class="LC_error">','</span>',$result,
1.568 raeburn 8025: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'));
1.183 albertel 8026: }
8027: }
1.174 albertel 8028: if ($symb) {
1.209 ng 8029: $r->print(&scantron_selectphase($r,$uploadedfile));
1.174 albertel 8030: } else {
1.182 albertel 8031: $r->print($doanotherupload);
1.174 albertel 8032: }
1.157 albertel 8033: return '';
8034: }
8035:
1.567 raeburn 8036: sub validate_uploaded_scantron_file {
8037: my ($cdom,$cname,$fname) = @_;
8038: my $scanlines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.$fname);
8039: my @lines;
8040: if ($scanlines ne '-1') {
8041: @lines=split("\n",$scanlines,-1);
8042: }
8043: my $output;
8044: if (@lines) {
8045: my (%counts,$max_match_format);
8046: my ($max_match_count,$max_match_pct) = (0,0);
8047: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cname);
8048: my %idmap = &username_to_idmap($classlist);
8049: foreach my $key (keys(%idmap)) {
8050: my $lckey = lc($key);
8051: $idmap{$lckey} = $idmap{$key};
8052: }
8053: my %unique_formats;
8054: my @formatlines = &get_scantronformat_file();
8055: foreach my $line (@formatlines) {
8056: chomp($line);
8057: my @config = split(/:/,$line);
8058: my $idstart = $config[5];
8059: my $idlength = $config[6];
8060: if (($idstart ne '') && ($idlength > 0)) {
8061: if (ref($unique_formats{$idstart.':'.$idlength}) eq 'ARRAY') {
8062: push(@{$unique_formats{$idstart.':'.$idlength}},$config[0].':'.$config[1]);
8063: } else {
8064: $unique_formats{$idstart.':'.$idlength} = [$config[0].':'.$config[1]];
8065: }
8066: }
8067: }
8068: foreach my $key (keys(%unique_formats)) {
8069: my ($idstart,$idlength) = split(':',$key);
8070: %{$counts{$key}} = (
8071: 'found' => 0,
8072: 'total' => 0,
8073: );
8074: foreach my $line (@lines) {
8075: next if ($line =~ /^#/);
8076: next if ($line =~ /^[\s\cz]*$/);
8077: my $id = substr($line,$idstart-1,$idlength);
8078: $id = lc($id);
8079: if (exists($idmap{$id})) {
8080: $counts{$key}{'found'} ++;
8081: }
8082: $counts{$key}{'total'} ++;
8083: }
8084: if ($counts{$key}{'total'}) {
8085: my $percent_match = (100*$counts{$key}{'found'})/($counts{$key}{'total'});
8086: if (($max_match_format eq '') || ($percent_match > $max_match_pct)) {
8087: $max_match_pct = $percent_match;
8088: $max_match_format = $key;
8089: $max_match_count = $counts{$key}{'total'};
8090: }
8091: }
8092: }
8093: if (ref($unique_formats{$max_match_format}) eq 'ARRAY') {
8094: my $format_descs;
8095: my $numwithformat = @{$unique_formats{$max_match_format}};
8096: for (my $i=0; $i<$numwithformat; $i++) {
8097: my ($name,$desc) = split(':',$unique_formats{$max_match_format}[$i]);
8098: if ($i<$numwithformat-2) {
8099: $format_descs .= '"<i>'.$desc.'</i>", ';
8100: } elsif ($i==$numwithformat-2) {
8101: $format_descs .= '"<i>'.$desc.'</i>" '.&mt('and').' ';
8102: } elsif ($i==$numwithformat-1) {
8103: $format_descs .= '"<i>'.$desc.'</i>"';
8104: }
8105: }
8106: my $showpct = sprintf("%.0f",$max_match_pct).'%';
8107: $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).
8108: '<br />'.&mt('A low percentage of matches results from one of the following:').'<ul>'.
8109: '<li>'.&mt('The file was uploaded to the wrong course').'</li>'.
8110: '<li>'.&mt('The data are not in the format expected for the domain: [_1]',
8111: '<i>'.$cdom.'</i>').'</li>'.
8112: '<li>'.&mt('Students did not bubble their IDs, or mis-bubbled them').'</li>'.
8113: '<li>'.&mt('The course roster is not up to date').'</li>'.
8114: '</ul>';
8115: }
8116: } else {
8117: $output = '<span class="LC_warning">'.&mt('Uploaded file contained no data').'</span>';
8118: }
8119: return $output;
8120: }
8121:
1.202 albertel 8122: sub valid_file {
8123: my ($requested_file)=@_;
8124: foreach my $filename (sort(&scantron_filenames())) {
8125: if ($requested_file eq $filename) { return 1; }
8126: }
8127: return 0;
8128: }
8129:
8130: sub scantron_download_scantron_data {
8131: my ($r)=@_;
1.324 albertel 8132: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.257 albertel 8133: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
8134: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
8135: my $file=$env{'form.scantron_selectfile'};
1.202 albertel 8136: if (! &valid_file($file)) {
1.492 albertel 8137: $r->print('
1.202 albertel 8138: <p>
1.492 albertel 8139: '.&mt('The requested file name was invalid.').'
1.202 albertel 8140: </p>
1.492 albertel 8141: ');
1.324 albertel 8142: $r->print(&show_grading_menu_form(&get_symb($r,1)));
1.202 albertel 8143: return;
8144: }
8145: my $orig='/uploaded/'.$cdom.'/'.$cname.'/scantron_orig_'.$file;
8146: my $corrected='/uploaded/'.$cdom.'/'.$cname.'/scantron_corrected_'.$file;
8147: my $skipped='/uploaded/'.$cdom.'/'.$cname.'/scantron_skipped_'.$file;
8148: &Apache::lonnet::allowuploaded('/adm/grades',$orig);
8149: &Apache::lonnet::allowuploaded('/adm/grades',$corrected);
8150: &Apache::lonnet::allowuploaded('/adm/grades',$skipped);
1.492 albertel 8151: $r->print('
1.202 albertel 8152: <p>
1.492 albertel 8153: '.&mt('[_1]Original[_2] file as uploaded by the scantron office.',
8154: '<a href="'.$orig.'">','</a>').'
1.202 albertel 8155: </p>
8156: <p>
1.492 albertel 8157: '.&mt('[_1]Corrections[_2], a file of corrected records that were used in grading.',
8158: '<a href="'.$corrected.'">','</a>').'
1.202 albertel 8159: </p>
8160: <p>
1.492 albertel 8161: '.&mt('[_1]Skipped[_2], a file of records that were skipped.',
8162: '<a href="'.$skipped.'">','</a>').'
1.202 albertel 8163: </p>
1.492 albertel 8164: ');
1.324 albertel 8165: $r->print(&show_grading_menu_form(&get_symb($r,1)));
1.202 albertel 8166: return '';
8167: }
1.157 albertel 8168:
1.523 raeburn 8169: sub checkscantron_results {
8170: my ($r) = @_;
8171: my ($symb)=&get_symb($r);
8172: if (!$symb) {return '';}
8173: my $grading_menu_button=&show_grading_menu_form($symb);
8174: my $cid = $env{'request.course.id'};
1.542 raeburn 8175: my %lettdig = &letter_to_digits();
1.523 raeburn 8176: my $numletts = scalar(keys(%lettdig));
8177: my $cnum = $env{'course.'.$cid.'.num'};
8178: my $cdom = $env{'course.'.$cid.'.domain'};
8179: my (undef, undef, $sequence) = &Apache::lonnet::decode_symb($env{'form.selectpage'});
8180: my %record;
8181: my %scantron_config =
8182: &Apache::grades::get_scantron_config($env{'form.scantron_format'});
8183: my ($scanlines,$scan_data)=&Apache::grades::scantron_getfile();
8184: my $classlist=&Apache::loncoursedata::get_classlist();
8185: my %idmap=&Apache::grades::username_to_idmap($classlist);
8186: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 8187: unless (ref($navmap)) {
8188: $r->print(&navmap_errormsg());
8189: return '';
8190: }
1.523 raeburn 8191: my $map=$navmap->getResourceByUrl($sequence);
1.557 raeburn 8192: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
8193: my (%grader_partids_by_symb,%grader_randomlists_by_symb);
8194: &graders_resources_pass(\@resources,\%grader_partids_by_symb, \%grader_randomlists_by_symb);
8195:
1.554 raeburn 8196: my ($uname,$udom);
1.523 raeburn 8197: my (%scandata,%lastname,%bylast);
8198: $r->print('
8199: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="checkscantron">'."\n");
8200:
8201: my @delayqueue;
8202: my %completedstudents;
8203:
8204: my $count=&Apache::grades::get_todo_count($scanlines,$scan_data);
1.581 www 8205: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Bubblesheet/Submissions Comparison Status',
8206: 'Progress of Bubblesheet Data/Submission Records Comparison',$count,
1.523 raeburn 8207: 'inline',undef,'checkscantron');
1.546 raeburn 8208: my ($username,$domain,$started);
1.582 raeburn 8209: my $nav_error;
8210: &scantron_get_maxbubble(\$nav_error); # Need the bubble lines array to parse.
8211: if ($nav_error) {
8212: $r->print(&navmap_errormsg());
8213: return '';
8214: }
1.523 raeburn 8215:
8216: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
8217: 'Processing first student');
8218: my $start=&Time::HiRes::time();
8219: my $i=-1;
8220:
8221: while ($i<$scanlines->{'count'}) {
8222: ($username,$domain,$uname)=('','','');
8223: $i++;
8224: my $line=&Apache::grades::scantron_get_line($scanlines,$scan_data,$i);
8225: if ($line=~/^[\s\cz]*$/) { next; }
8226: if ($started) {
8227: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
8228: 'last student');
8229: }
8230: $started=1;
8231: my $scan_record=
8232: &Apache::grades::scantron_parse_scanline($line,$i,\%scantron_config,
8233: $scan_data);
8234: unless ($uname=&Apache::grades::scantron_find_student($scan_record,$scan_data,
8235: \%idmap,$i)) {
8236: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
8237: 'Unable to find a student that matches',1);
8238: next;
8239: }
8240: if (exists $completedstudents{$uname}) {
8241: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
8242: 'Student '.$uname.' has multiple sheets',2);
8243: next;
8244: }
8245: my $pid = $scan_record->{'scantron.ID'};
8246: $lastname{$pid} = $scan_record->{'scantron.LastName'};
8247: push(@{$bylast{$lastname{$pid}}},$pid);
8248: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
8249: $scandata{$pid} = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
8250: chomp($scandata{$pid});
8251: $scandata{$pid} =~ s/\r$//;
8252: ($username,$domain)=split(/:/,$uname);
8253: my $counter = -1;
8254: foreach my $resource (@resources) {
1.557 raeburn 8255: my $parts;
1.554 raeburn 8256: my $ressymb = $resource->symb();
1.557 raeburn 8257: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
8258: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
8259: (my $analysis,$parts) =
8260: &scantron_partids_tograde($resource,$env{'request.course.id'},$username,$domain);
8261: } else {
8262: $parts = $grader_partids_by_symb{$ressymb};
8263: }
1.542 raeburn 8264: ($counter,my $recording) =
8265: &verify_scantron_grading($resource,$domain,$username,$cid,$counter,
1.554 raeburn 8266: $scandata{$pid},$parts,
1.542 raeburn 8267: \%scantron_config,\%lettdig,$numletts);
8268: $record{$pid} .= $recording;
1.523 raeburn 8269: }
8270: }
8271: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
8272: $r->print('<br />');
8273: my ($okstudents,$badstudents,$numstudents,$passed,$failed);
8274: $passed = 0;
8275: $failed = 0;
8276: $numstudents = 0;
8277: foreach my $last (sort(keys(%bylast))) {
8278: if (ref($bylast{$last}) eq 'ARRAY') {
8279: foreach my $pid (sort(@{$bylast{$last}})) {
8280: my $showscandata = $scandata{$pid};
8281: my $showrecord = $record{$pid};
8282: $showscandata =~ s/\s/ /g;
8283: $showrecord =~ s/\s/ /g;
8284: if ($scandata{$pid} eq $record{$pid}) {
8285: my $css_class = ($passed % 2)?'LC_odd_row':'LC_even_row';
8286: $okstudents .= '<tr class="'.$css_class.'">'.
1.581 www 8287: '<td>'.&mt('Bubblesheet').'</td><td>'.$showscandata.'</td><td rowspan="2">'.$last.'</td><td rowspan="2">'.$pid.'</td>'."\n".
1.523 raeburn 8288: '</tr>'."\n".
8289: '<tr class="'.$css_class.'">'."\n".
8290: '<td>Submissions</td><td>'.$showrecord.'</td></tr>'."\n";
8291: $passed ++;
8292: } else {
8293: my $css_class = ($failed % 2)?'LC_odd_row':'LC_even_row';
1.581 www 8294: $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 8295: '</tr>'."\n".
8296: '<tr class="'.$css_class.'">'."\n".
8297: '<td>Submissions</td><td><span class="LC_nobreak">'.$record{$pid}.'</span></td>'."\n".
8298: '</tr>'."\n";
8299: $failed ++;
8300: }
8301: $numstudents ++;
8302: }
8303: }
8304: }
1.572 www 8305: $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 8306: $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>');
8307: if ($passed) {
1.572 www 8308: $r->print(&mt('Students with exact correspondence between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 8309: $r->print(&Apache::loncommon::start_data_table()."\n".
8310: &Apache::loncommon::start_data_table_header_row()."\n".
8311: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
8312: &Apache::loncommon::end_data_table_header_row()."\n".
8313: $okstudents."\n".
8314: &Apache::loncommon::end_data_table().'<br />');
8315: }
8316: if ($failed) {
1.572 www 8317: $r->print(&mt('Students with differences between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 8318: $r->print(&Apache::loncommon::start_data_table()."\n".
8319: &Apache::loncommon::start_data_table_header_row()."\n".
8320: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
8321: &Apache::loncommon::end_data_table_header_row()."\n".
8322: $badstudents."\n".
8323: &Apache::loncommon::end_data_table()).'<br />'.
1.572 www 8324: &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 8325: }
8326: $r->print('</form><br />'.$grading_menu_button);
8327: return;
8328: }
8329:
1.542 raeburn 8330: sub verify_scantron_grading {
1.554 raeburn 8331: my ($resource,$domain,$username,$cid,$counter,$scandata,$partids,
1.542 raeburn 8332: $scantron_config,$lettdig,$numletts) = @_;
8333: my ($record,%expected,%startpos);
8334: return ($counter,$record) if (!ref($resource));
8335: return ($counter,$record) if (!$resource->is_problem());
8336: my $symb = $resource->symb();
1.554 raeburn 8337: return ($counter,$record) if (ref($partids) ne 'ARRAY');
8338: foreach my $part_id (@{$partids}) {
1.542 raeburn 8339: $counter ++;
8340: $expected{$part_id} = 0;
8341: if ($env{"form.scantron.sub_bubblelines.$counter"}) {
8342: my @sub_lines = split(/,/,$env{"form.scantron.sub_bubblelines.$counter"});
8343: foreach my $item (@sub_lines) {
8344: $expected{$part_id} += $item;
8345: }
8346: } else {
8347: $expected{$part_id} = $env{"form.scantron.bubblelines.$counter"};
8348: }
8349: $startpos{$part_id} = $env{"form.scantron.first_bubble_line.$counter"};
8350: }
8351: if ($symb) {
8352: my %recorded;
8353: my (%returnhash) = &Apache::lonnet::restore($symb,$cid,$domain,$username);
8354: if ($returnhash{'version'}) {
8355: my %lasthash=();
8356: my $version;
8357: for ($version=1;$version<=$returnhash{'version'};$version++) {
8358: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
8359: $lasthash{$key}=$returnhash{$version.':'.$key};
8360: }
8361: }
8362: foreach my $key (keys(%lasthash)) {
8363: if ($key =~ /\.scantron$/) {
8364: my $value = &unescape($lasthash{$key});
8365: my ($part_id) = ($key =~ /^resource\.(.+)\.scantron$/);
8366: if ($value eq '') {
8367: for (my $i=0; $i<$expected{$part_id}; $i++) {
8368: for (my $j=0; $j<$scantron_config->{'length'}; $j++) {
8369: $recorded{$part_id} .= $scantron_config->{'Qoff'};
8370: }
8371: }
8372: } else {
8373: my @tocheck;
8374: my @items = split(//,$value);
8375: if (($scantron_config->{'Qon'} eq 'letter') ||
8376: ($scantron_config->{'Qon'} eq 'number')) {
8377: if (@items < $expected{$part_id}) {
8378: my $fragment = substr($scandata,$startpos{$part_id},$expected{$part_id});
8379: my @singles = split(//,$fragment);
8380: foreach my $pos (@singles) {
8381: if ($pos eq ' ') {
8382: push(@tocheck,$pos);
8383: } else {
8384: my $next = shift(@items);
8385: push(@tocheck,$next);
8386: }
8387: }
8388: } else {
8389: @tocheck = @items;
8390: }
8391: foreach my $letter (@tocheck) {
8392: if ($scantron_config->{'Qon'} eq 'letter') {
8393: if ($letter !~ /^[A-J]$/) {
8394: $letter = $scantron_config->{'Qoff'};
8395: }
8396: $recorded{$part_id} .= $letter;
8397: } elsif ($scantron_config->{'Qon'} eq 'number') {
8398: my $digit;
8399: if ($letter !~ /^[A-J]$/) {
8400: $digit = $scantron_config->{'Qoff'};
8401: } else {
8402: $digit = $lettdig->{$letter};
8403: }
8404: $recorded{$part_id} .= $digit;
8405: }
8406: }
8407: } else {
8408: @tocheck = @items;
8409: for (my $i=0; $i<$expected{$part_id}; $i++) {
8410: my $curr_sub = shift(@tocheck);
8411: my $digit;
8412: if ($curr_sub =~ /^[A-J]$/) {
8413: $digit = $lettdig->{$curr_sub}-1;
8414: }
8415: if ($curr_sub eq 'J') {
8416: $digit += scalar($numletts);
8417: }
8418: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
8419: if ($j == $digit) {
8420: $recorded{$part_id} .= $scantron_config->{'Qon'};
8421: } else {
8422: $recorded{$part_id} .= $scantron_config->{'Qoff'};
8423: }
8424: }
8425: }
8426: }
8427: }
8428: }
8429: }
8430: }
1.554 raeburn 8431: foreach my $part_id (@{$partids}) {
1.542 raeburn 8432: if ($recorded{$part_id} eq '') {
8433: for (my $i=0; $i<$expected{$part_id}; $i++) {
8434: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
8435: $recorded{$part_id} .= $scantron_config->{'Qoff'};
8436: }
8437: }
8438: }
8439: $record .= $recorded{$part_id};
8440: }
8441: }
8442: return ($counter,$record);
8443: }
8444:
8445: sub letter_to_digits {
8446: my %lettdig = (
8447: A => 1,
8448: B => 2,
8449: C => 3,
8450: D => 4,
8451: E => 5,
8452: F => 6,
8453: G => 7,
8454: H => 8,
8455: I => 9,
8456: J => 0,
8457: );
8458: return %lettdig;
8459: }
8460:
1.423 albertel 8461:
1.75 albertel 8462: #-------- end of section for handling grading scantron forms -------
8463: #
8464: #-------------------------------------------------------------------
8465:
1.72 ng 8466: #-------------------------- Menu interface -------------------------
8467: #
8468: #--- Show a Grading Menu button - Calls the next routine ---
8469: sub show_grading_menu_form {
1.324 albertel 8470: my ($symb)=@_;
1.125 ng 8471: my $result.='<br /><form action="/adm/grades" method="post">'."\n".
1.418 albertel 8472: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 8473: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.72 ng 8474: '<input type="hidden" name="command" value="gradingmenu" />'."\n".
1.478 albertel 8475: '<input type="submit" name="submit" value="'.&mt('Grading Menu').'" />'."\n".
1.72 ng 8476: '</form>'."\n";
8477: return $result;
8478: }
8479:
1.77 ng 8480: # -- Retrieve choices for grading form
8481: sub savedState {
8482: my %savedState = ();
1.257 albertel 8483: if ($env{'form.saveState'}) {
8484: foreach (split(/:/,$env{'form.saveState'})) {
1.77 ng 8485: my ($key,$value) = split(/=/,$_,2);
8486: $savedState{$key} = $value;
8487: }
8488: }
8489: return \%savedState;
8490: }
1.76 ng 8491:
1.443 banghart 8492: sub grading_menu {
8493: my ($request) = @_;
8494: my ($symb)=&get_symb($request);
8495: if (!$symb) {return '';}
8496: my $probTitle = &Apache::lonnet::gettitle($symb);
8497: my ($table,undef,$hdgrade) = &showResourceInfo($symb,$probTitle);
8498:
1.444 banghart 8499: $request->print($table);
1.443 banghart 8500: my %fields = ('symb'=>&Apache::lonenc::check_encrypt($symb),
8501: 'handgrade'=>$hdgrade,
8502: 'probTitle'=>$probTitle,
8503: 'command'=>'submit_options',
8504: 'saveState'=>"",
8505: 'gradingMenu'=>1,
8506: 'showgrading'=>"yes");
1.538 schulted 8507:
8508: my $url1 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8509:
1.443 banghart 8510: $fields{'command'} = 'csvform';
1.538 schulted 8511: my $url2 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8512:
1.443 banghart 8513: $fields{'command'} = 'processclicker';
1.538 schulted 8514: my $url3 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8515:
1.443 banghart 8516: $fields{'command'} = 'scantron_selectphase';
1.538 schulted 8517: my $url4 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8518:
8519: my @menu = ({ categorytitle=>'Course Grading',
8520: items =>[
8521: { linktext => 'Manual Grading/View Submissions',
8522: url => $url1,
8523: permission => 'F',
8524: icon => 'edit-find-replace.png',
8525: linktitle => 'Start the process of hand grading submissions.'
8526: },
8527: { linktext => 'Upload Scores',
8528: url => $url2,
8529: permission => 'F',
8530: icon => 'uploadscores.png',
8531: linktitle => 'Specify a file containing the class scores for current resource.'
8532: },
8533: { linktext => 'Process Clicker',
8534: url => $url3,
8535: permission => 'F',
8536: icon => 'addClickerInfoFile.png',
8537: linktitle => 'Specify a file containing the clicker information for this resource.'
8538: },
1.587 raeburn 8539: { linktext => 'Grade/Manage/Review Bubblesheets',
1.538 schulted 8540: url => $url4,
8541: permission => 'F',
8542: icon => 'stat.png',
8543: linktitle => 'Grade scantron exams, upload/download scantron data files, and review previously graded scantron exams.'
8544: }
8545: ]
8546: });
8547:
8548: #$fields{'command'} = 'verify';
8549: #$url = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
1.443 banghart 8550: #
8551: # Create the menu
8552: my $Str;
1.444 banghart 8553: # $Str .= '<h2>'.&mt('Please select a grading task').'</h2>';
1.445 banghart 8554: $Str .= '<form method="post" action="" name="gradingMenu">';
8555: $Str .= '<input type="hidden" name="command" value="" />'.
8556: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
8557: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
1.476 albertel 8558: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.445 banghart 8559: '<input type="hidden" name="saveState" value="" />'."\n".
8560: '<input type="hidden" name="gradingMenu" value="1" />'."\n".
8561: '<input type="hidden" name="showgrading" value="yes" />'."\n";
8562:
1.538 schulted 8563: $Str .= Apache::lonhtmlcommon::generate_menu(@menu);
8564: #$menudata->{'jscript'}
1.584 bisitz 8565: $Str .='<hr /><input type="button" value="'.&mt('Verify Receipt No.').'" '.
1.589 bisitz 8566: ' onclick="javascript:checkChoice(document.forms.gradingMenu,\'5\',\'verify\')" '.
1.538 schulted 8567: ' /> '.
8568: &Apache::lonnet::recprefix($env{'request.course.id'}).
1.589 bisitz 8569: '-<input type="text" name="receipt" size="4" onchange="javascript:checkReceiptNo(this.form,\'OK\')" />';
1.538 schulted 8570:
1.444 banghart 8571: $Str .="</form>\n";
1.539 riegler 8572: my $receiptalert = &mt("Please enter a receipt number given by a student in the receipt box.");
1.443 banghart 8573: $request->print(<<GRADINGMENUJS);
8574: <script type="text/javascript" language="javascript">
8575: function checkChoice(formname,val,cmdx) {
8576: if (val <= 2) {
8577: var cmd = radioSelection(formname.radioChoice);
8578: var cmdsave = cmd;
8579: } else {
8580: cmd = cmdx;
8581: cmdsave = 'submission';
8582: }
8583: formname.command.value = cmd;
8584: if (val < 5) formname.submit();
8585: if (val == 5) {
1.458 banghart 8586: if (!checkReceiptNo(formname,'notOK')) {
8587: return false;
8588: } else {
8589: formname.submit();
8590: }
1.445 banghart 8591: }
8592: }
1.443 banghart 8593:
8594: function checkReceiptNo(formname,nospace) {
8595: var receiptNo = formname.receipt.value;
8596: var checkOpt = false;
8597: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
8598: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
8599: if (checkOpt) {
1.539 riegler 8600: alert("$receiptalert");
1.443 banghart 8601: formname.receipt.value = "";
8602: formname.receipt.focus();
8603: return false;
8604: }
8605: return true;
8606: }
8607: </script>
8608: GRADINGMENUJS
8609: &commonJSfunctions($request);
8610: return $Str;
8611: }
8612:
8613:
8614: #--- Displays the submissions first page -------
8615: sub submit_options {
1.72 ng 8616: my ($request) = @_;
1.324 albertel 8617: my ($symb)=&get_symb($request);
1.72 ng 8618: if (!$symb) {return '';}
1.76 ng 8619: my $probTitle = &Apache::lonnet::gettitle($symb);
1.72 ng 8620:
1.539 riegler 8621: my $receiptalert = &mt("Please enter a receipt number given by a student in the receipt box.");
1.72 ng 8622: $request->print(<<GRADINGMENUJS);
8623: <script type="text/javascript" language="javascript">
1.116 ng 8624: function checkChoice(formname,val,cmdx) {
8625: if (val <= 2) {
8626: var cmd = radioSelection(formname.radioChoice);
1.118 ng 8627: var cmdsave = cmd;
1.116 ng 8628: } else {
8629: cmd = cmdx;
1.118 ng 8630: cmdsave = 'submission';
1.116 ng 8631: }
8632: formname.command.value = cmd;
1.118 ng 8633: formname.saveState.value = "saveCmd="+cmdsave+":saveSec="+pullDownSelection(formname.section)+
1.145 albertel 8634: ":saveSub="+pullDownSelection(formname.submitonly)+":saveStatus="+pullDownSelection(formname.Status);
1.116 ng 8635: if (val < 5) formname.submit();
8636: if (val == 5) {
1.72 ng 8637: if (!checkReceiptNo(formname,'notOK')) { return false;}
8638: formname.submit();
8639: }
1.238 albertel 8640: if (val < 7) formname.submit();
1.72 ng 8641: }
8642:
8643: function checkReceiptNo(formname,nospace) {
8644: var receiptNo = formname.receipt.value;
8645: var checkOpt = false;
8646: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
8647: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
8648: if (checkOpt) {
1.539 riegler 8649: alert("$receiptalert");
1.72 ng 8650: formname.receipt.value = "";
8651: formname.receipt.focus();
8652: return false;
8653: }
8654: return true;
8655: }
8656: </script>
8657: GRADINGMENUJS
1.118 ng 8658: &commonJSfunctions($request);
1.324 albertel 8659: my ($table,undef,$hdgrade) = &showResourceInfo($symb,$probTitle);
1.473 albertel 8660: my $result;
1.76 ng 8661: my (undef,$sections) = &getclasslist('all','0');
1.77 ng 8662: my $savedState = &savedState();
1.118 ng 8663: my $saveCmd = ($$savedState{'saveCmd'} eq '' ? 'submission' : $$savedState{'saveCmd'});
1.77 ng 8664: my $saveSec = ($$savedState{'saveSec'} eq '' ? 'all' : $$savedState{'saveSec'});
1.118 ng 8665: my $saveSub = ($$savedState{'saveSub'} eq '' ? 'all' : $$savedState{'saveSub'});
1.77 ng 8666: my $saveStatus = ($$savedState{'saveStatus'} eq '' ? 'Active' : $$savedState{'saveStatus'});
1.72 ng 8667:
1.533 bisitz 8668: # Preselect sections
8669: my $selsec="";
8670: if (ref($sections)) {
8671: foreach my $section (sort(@$sections)) {
8672: $selsec.='<option value="'.$section.'" '.
8673: ($saveSec eq $section ? 'selected="selected"':'').'>'.$section.'</option>'."\n";
8674: }
8675: }
8676:
1.72 ng 8677: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.418 albertel 8678: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.72 ng 8679: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
8680: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.116 ng 8681: '<input type="hidden" name="command" value="" />'."\n".
1.77 ng 8682: '<input type="hidden" name="saveState" value="" />'."\n".
1.124 ng 8683: '<input type="hidden" name="gradingMenu" value="1" />'."\n".
1.72 ng 8684: '<input type="hidden" name="showgrading" value="yes" />'."\n";
8685:
1.472 albertel 8686: $result.='
1.533 bisitz 8687: <h2>
8688: '.&mt('Grade Current Resource').'
8689: </h2>
8690: <div>
8691: '.$table.'
8692: </div>
8693:
1.537 harmsja 8694: <div class="LC_columnSection">
8695:
1.533 bisitz 8696: <fieldset>
8697: <legend>
8698: '.&mt('Sections').'
8699: </legend>
8700: <select name="section" multiple="multiple" size="5">'."\n";
8701: $result.= $selsec;
1.401 albertel 8702: $result.= '<option value="all" '.($saveSec eq 'all' ? 'selected="selected"' : ''). '>all</option></select> ';
1.472 albertel 8703: $result.='
1.533 bisitz 8704: </fieldset>
1.537 harmsja 8705:
1.533 bisitz 8706: <fieldset>
8707: <legend>
8708: '.&mt('Groups').'
8709: </legend>
8710: '.&Apache::lonstatistics::GroupSelect('group','multiple',5).'
8711: </fieldset>
1.537 harmsja 8712:
1.533 bisitz 8713: <fieldset>
8714: <legend>
8715: '.&mt('Access Status').'
8716: </legend>
8717: '.&Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,5,undef,'mult').'
8718: </fieldset>
1.537 harmsja 8719:
1.533 bisitz 8720: <fieldset>
8721: <legend>
8722: '.&mt('Submission Status').'
8723: </legend>
8724: <select name="submitonly" size="5">
1.473 albertel 8725: <option value="yes" '. ($saveSub eq 'yes' ? 'selected="selected"' : '').'>'.&mt('with submissions').'</option>
8726: <option value="queued" '. ($saveSub eq 'queued' ? 'selected="selected"' : '').'>'.&mt('in grading queue').'</option>
8727: <option value="graded" '. ($saveSub eq 'graded' ? 'selected="selected"' : '').'>'.&mt('with ungraded submissions').'</option>
8728: <option value="incorrect" '.($saveSub eq 'incorrect' ? 'selected="selected"' : '').'>'.&mt('with incorrect submissions').'</option>
8729: <option value="all" '. ($saveSub eq 'all' ? 'selected="selected"' : '').'>'.&mt('with any status').'</option>
1.533 bisitz 8730: </select>
8731: </fieldset>
1.537 harmsja 8732:
1.533 bisitz 8733: </div>
8734:
8735: <br />
8736: <div>
8737: <div>
1.473 albertel 8738: <label>
8739: <input type="radio" name="radioChoice" value="submission" '.
8740: ($saveCmd eq 'submission' ? 'checked="checked"' : '').' /> '.
8741: &mt('Select individual students to grade and view submissions.').'
8742: </label>
8743: </div>
1.533 bisitz 8744: <div>
1.473 albertel 8745: <label>
8746: <input type="radio" name="radioChoice" value="viewgrades" '.
8747: ($saveCmd eq 'viewgrades' ? 'checked="checked"' : '').' /> '.
8748: &mt('Grade all selected students in a grading table.').'
8749: </label>
8750: </div>
1.533 bisitz 8751: <div>
1.589 bisitz 8752: <input type="button" onclick="javascript:checkChoice(this.form,\'2\');" value="'.&mt('Next').' →" />
1.473 albertel 8753: </div>
1.472 albertel 8754: </div>
1.533 bisitz 8755:
8756:
1.473 albertel 8757: <h2>
8758: '.&mt('Grade Complete Folder for One Student').'
8759: </h2>
1.533 bisitz 8760: <div>
8761: <div>
1.473 albertel 8762: <label>
8763: <input type="radio" name="radioChoice" value="pickStudentPage" '.
8764: ($saveCmd eq 'pickStudentPage' ? 'checked="checked"' : '').' /> '.
8765: &mt('The <b>complete</b> page/sequence/folder: For one student').'
8766: </label>
8767: </div>
1.533 bisitz 8768: <div>
1.589 bisitz 8769: <input type="button" onclick="javascript:checkChoice(this.form,\'2\');" value="'.&mt('Next').' →" />
1.473 albertel 8770: </div>
1.472 albertel 8771: </div>
8772: </form>';
1.499 albertel 8773: $result .= &show_grading_menu_form($symb);
1.44 ng 8774: return $result;
1.2 albertel 8775: }
8776:
1.285 albertel 8777: sub reset_perm {
8778: undef(%perm);
8779: }
8780:
8781: sub init_perm {
8782: &reset_perm();
1.300 albertel 8783: foreach my $test_perm ('vgr','mgr','opa') {
8784:
8785: my $scope = $env{'request.course.id'};
8786: if (!($perm{$test_perm}=&Apache::lonnet::allowed($test_perm,$scope))) {
8787:
8788: $scope .= '/'.$env{'request.course.sec'};
8789: if ( $perm{$test_perm}=
8790: &Apache::lonnet::allowed($test_perm,$scope)) {
8791: $perm{$test_perm.'_section'}=$env{'request.course.sec'};
8792: } else {
8793: delete($perm{$test_perm});
8794: }
1.285 albertel 8795: }
8796: }
8797: }
8798:
1.400 www 8799: sub gather_clicker_ids {
1.408 albertel 8800: my %clicker_ids;
1.400 www 8801:
8802: my $classlist = &Apache::loncoursedata::get_classlist();
8803:
8804: # Set up a couple variables.
1.407 albertel 8805: my $username_idx = &Apache::loncoursedata::CL_SNAME();
8806: my $domain_idx = &Apache::loncoursedata::CL_SDOM();
1.438 www 8807: my $status_idx = &Apache::loncoursedata::CL_STATUS();
1.400 www 8808:
1.407 albertel 8809: foreach my $student (keys(%$classlist)) {
1.438 www 8810: if ($classlist->{$student}->[$status_idx] ne 'Active') { next; }
1.407 albertel 8811: my $username = $classlist->{$student}->[$username_idx];
8812: my $domain = $classlist->{$student}->[$domain_idx];
1.400 www 8813: my $clickers =
1.408 albertel 8814: (&Apache::lonnet::userenvironment($domain,$username,'clickers'))[1];
1.400 www 8815: foreach my $id (split(/\,/,$clickers)) {
1.414 www 8816: $id=~s/^[\#0]+//;
1.421 www 8817: $id=~s/[\-\:]//g;
1.407 albertel 8818: if (exists($clicker_ids{$id})) {
1.408 albertel 8819: $clicker_ids{$id}.=','.$username.':'.$domain;
1.400 www 8820: } else {
1.408 albertel 8821: $clicker_ids{$id}=$username.':'.$domain;
1.400 www 8822: }
8823: }
8824: }
1.407 albertel 8825: return %clicker_ids;
1.400 www 8826: }
8827:
1.402 www 8828: sub gather_adv_clicker_ids {
1.408 albertel 8829: my %clicker_ids;
1.402 www 8830: my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'};
8831: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
8832: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
1.409 albertel 8833: foreach my $element (sort(keys(%coursepersonnel))) {
1.402 www 8834: foreach my $person (split(/\,/,$coursepersonnel{$element})) {
8835: my ($puname,$pudom)=split(/\:/,$person);
8836: my $clickers =
1.408 albertel 8837: (&Apache::lonnet::userenvironment($pudom,$puname,'clickers'))[1];
1.405 www 8838: foreach my $id (split(/\,/,$clickers)) {
1.414 www 8839: $id=~s/^[\#0]+//;
1.421 www 8840: $id=~s/[\-\:]//g;
1.408 albertel 8841: if (exists($clicker_ids{$id})) {
8842: $clicker_ids{$id}.=','.$puname.':'.$pudom;
8843: } else {
8844: $clicker_ids{$id}=$puname.':'.$pudom;
8845: }
1.405 www 8846: }
1.402 www 8847: }
8848: }
1.407 albertel 8849: return %clicker_ids;
1.402 www 8850: }
8851:
1.413 www 8852: sub clicker_grading_parameters {
8853: return ('gradingmechanism' => 'scalar',
8854: 'upfiletype' => 'scalar',
8855: 'specificid' => 'scalar',
8856: 'pcorrect' => 'scalar',
8857: 'pincorrect' => 'scalar');
8858: }
8859:
1.400 www 8860: sub process_clicker {
8861: my ($r)=@_;
8862: my ($symb)=&get_symb($r);
8863: if (!$symb) {return '';}
8864: my $result=&checkforfile_js();
8865: $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
8866: my ($table) = &showResourceInfo($symb,$env{'form.probTitle'});
8867: $result.=$table;
8868: $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
8869: $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
1.538 schulted 8870: $result.=' <b>'.&mt('Specify a file containing the clicker information for this resource.').
8871: '</b></td></tr>'."\n";
1.400 www 8872: $result.='<tr bgcolor=#ffffe6><td>'."\n";
1.413 www 8873: # Attempt to restore parameters from last session, set defaults if not present
8874: my %Saveable_Parameters=&clicker_grading_parameters();
8875: &Apache::loncommon::restore_course_settings('grades_clicker',
8876: \%Saveable_Parameters);
8877: if (!$env{'form.pcorrect'}) { $env{'form.pcorrect'}=100; }
8878: if (!$env{'form.pincorrect'}) { $env{'form.pincorrect'}=100; }
8879: if (!$env{'form.gradingmechanism'}) { $env{'form.gradingmechanism'}='attendance'; }
8880: if (!$env{'form.upfiletype'}) { $env{'form.upfiletype'}='iclicker'; }
8881:
8882: my %checked;
1.521 www 8883: foreach my $gradingmechanism ('attendance','personnel','specific','given') {
1.413 www 8884: if ($env{'form.gradingmechanism'} eq $gradingmechanism) {
1.569 bisitz 8885: $checked{$gradingmechanism}=' checked="checked"';
1.413 www 8886: }
8887: }
8888:
1.400 www 8889: my $upload=&mt("Upload File");
8890: my $type=&mt("Type");
1.402 www 8891: my $attendance=&mt("Award points just for participation");
8892: my $personnel=&mt("Correctness determined from response by course personnel");
1.414 www 8893: my $specific=&mt("Correctness determined from response with clicker ID(s)");
1.521 www 8894: my $given=&mt("Correctness determined from given list of answers").' '.
8895: '<font size="-2"><tt>('.&mt("Provide comma-separated list. Use '*' for any answer correct, '-' for skip").')</tt></font>';
1.402 www 8896: my $pcorrect=&mt("Percentage points for correct solution");
8897: my $pincorrect=&mt("Percentage points for incorrect solution");
1.413 www 8898: my $selectform=&Apache::loncommon::select_form($env{'form.upfiletype'},'upfiletype',
1.419 www 8899: ('iclicker' => 'i>clicker',
8900: 'interwrite' => 'interwrite PRS'));
1.418 albertel 8901: $symb = &Apache::lonenc::check_encrypt($symb);
1.400 www 8902: $result.=<<ENDUPFORM;
1.402 www 8903: <script type="text/javascript">
8904: function sanitycheck() {
8905: // Accept only integer percentages
8906: document.forms.gradesupload.pcorrect.value=Math.round(document.forms.gradesupload.pcorrect.value);
8907: document.forms.gradesupload.pincorrect.value=Math.round(document.forms.gradesupload.pincorrect.value);
8908: // Find out grading choice
8909: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
8910: if (document.forms.gradesupload.gradingmechanism[i].checked) {
8911: gradingchoice=document.forms.gradesupload.gradingmechanism[i].value;
8912: }
8913: }
8914: // By default, new choice equals user selection
8915: newgradingchoice=gradingchoice;
8916: // Not good to give more points for false answers than correct ones
8917: if (Math.round(document.forms.gradesupload.pcorrect.value)<Math.round(document.forms.gradesupload.pincorrect.value)) {
8918: document.forms.gradesupload.pcorrect.value=document.forms.gradesupload.pincorrect.value;
8919: }
8920: // If new choice is attendance only, and old choice was correctness-based, restore defaults
8921: if ((gradingchoice=='attendance') && (document.forms.gradesupload.waschecked.value!='attendance')) {
8922: document.forms.gradesupload.pcorrect.value=100;
8923: document.forms.gradesupload.pincorrect.value=100;
8924: }
8925: // If the values are different, cannot be attendance only
8926: if ((Math.round(document.forms.gradesupload.pcorrect.value)!=Math.round(document.forms.gradesupload.pincorrect.value)) &&
8927: (gradingchoice=='attendance')) {
8928: newgradingchoice='personnel';
8929: }
8930: // Change grading choice to new one
8931: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
8932: if (document.forms.gradesupload.gradingmechanism[i].value==newgradingchoice) {
8933: document.forms.gradesupload.gradingmechanism[i].checked=true;
8934: } else {
8935: document.forms.gradesupload.gradingmechanism[i].checked=false;
8936: }
8937: }
8938: // Remember the old state
8939: document.forms.gradesupload.waschecked.value=newgradingchoice;
8940: }
8941: </script>
1.400 www 8942: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
8943: <input type="hidden" name="symb" value="$symb" />
8944: <input type="hidden" name="command" value="processclickerfile" />
8945: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
8946: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
8947: <input type="file" name="upfile" size="50" />
8948: <br /><label>$type: $selectform</label>
1.589 bisitz 8949: <br /><label><input type="radio" name="gradingmechanism" value="attendance"$checked{'attendance'} onclick="sanitycheck()" />$attendance </label>
8950: <br /><label><input type="radio" name="gradingmechanism" value="personnel"$checked{'personnel'} onclick="sanitycheck()" />$personnel</label>
8951: <br /><label><input type="radio" name="gradingmechanism" value="specific"$checked{'specific'} onclick="sanitycheck()" />$specific </label>
1.414 www 8952: <input type="text" name="specificid" value="$env{'form.specificid'}" size="20" />
1.589 bisitz 8953: <br /><label><input type="radio" name="gradingmechanism" value="given"$checked{'given'} onclick="sanitycheck()" />$given </label>
1.521 www 8954: <br />
8955: <input type="text" name="givenanswer" size="50" />
1.413 www 8956: <input type="hidden" name="waschecked" value="$env{'form.gradingmechanism'}" />
1.589 bisitz 8957: <br /><label>$pcorrect: <input type="text" name="pcorrect" size="4" value="$env{'form.pcorrect'}" onchange="sanitycheck()" /></label>
8958: <br /><label>$pincorrect: <input type="text" name="pincorrect" size="4" value="$env{'form.pincorrect'}" onchange="sanitycheck()" /></label>
8959: <br /><input type="button" onclick="javascript:checkUpload(this.form);" value="$upload" />
1.400 www 8960: </form>
8961: ENDUPFORM
8962: $result.='</td></tr></table>'."\n".
8963: '</td></tr></table><br /><br />'."\n";
8964: $result.=&show_grading_menu_form($symb);
8965: return $result;
8966: }
8967:
8968: sub process_clicker_file {
8969: my ($r)=@_;
8970: my ($symb)=&get_symb($r);
8971: if (!$symb) {return '';}
1.413 www 8972:
8973: my %Saveable_Parameters=&clicker_grading_parameters();
8974: &Apache::loncommon::store_course_settings('grades_clicker',
8975: \%Saveable_Parameters);
8976:
1.400 www 8977: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.404 www 8978: if (($env{'form.gradingmechanism'} eq 'specific') && ($env{'form.specificid'}!~/\w/)) {
1.408 albertel 8979: $result.='<span class="LC_error">'.&mt('You need to specify a clicker ID for the correct answer').'</span>';
8980: return $result.&show_grading_menu_form($symb);
1.404 www 8981: }
1.522 www 8982: if (($env{'form.gradingmechanism'} eq 'given') && ($env{'form.givenanswer'}!~/\S/)) {
1.521 www 8983: $result.='<span class="LC_error">'.&mt('You need to specify the correct answer').'</span>';
8984: return $result.&show_grading_menu_form($symb);
8985: }
1.522 www 8986: my $foundgiven=0;
1.521 www 8987: if ($env{'form.gradingmechanism'} eq 'given') {
8988: $env{'form.givenanswer'}=~s/^\s*//gs;
8989: $env{'form.givenanswer'}=~s/\s*$//gs;
8990: $env{'form.givenanswer'}=~s/[^a-zA-Z0-9\.\*\-]+/\,/g;
8991: $env{'form.givenanswer'}=uc($env{'form.givenanswer'});
1.522 www 8992: my @answers=split(/\,/,$env{'form.givenanswer'});
8993: $foundgiven=$#answers+1;
1.521 www 8994: }
1.407 albertel 8995: my %clicker_ids=&gather_clicker_ids();
1.408 albertel 8996: my %correct_ids;
1.404 www 8997: if ($env{'form.gradingmechanism'} eq 'personnel') {
1.408 albertel 8998: %correct_ids=&gather_adv_clicker_ids();
1.404 www 8999: }
9000: if ($env{'form.gradingmechanism'} eq 'specific') {
1.414 www 9001: foreach my $correct_id (split(/[\s\,]/,$env{'form.specificid'})) {;
9002: $correct_id=~tr/a-z/A-Z/;
9003: $correct_id=~s/\s//gs;
9004: $correct_id=~s/^[\#0]+//;
1.421 www 9005: $correct_id=~s/[\-\:]//g;
1.414 www 9006: if ($correct_id) {
9007: $correct_ids{$correct_id}='specified';
9008: }
9009: }
1.400 www 9010: }
1.404 www 9011: if ($env{'form.gradingmechanism'} eq 'attendance') {
1.408 albertel 9012: $result.=&mt('Score based on attendance only');
1.521 www 9013: } elsif ($env{'form.gradingmechanism'} eq 'given') {
1.522 www 9014: $result.=&mt('Score based on [_1] ([_2] answers)','<tt>'.$env{'form.givenanswer'}.'</tt>',$foundgiven);
1.404 www 9015: } else {
1.408 albertel 9016: my $number=0;
1.411 www 9017: $result.='<p><b>'.&mt('Correctness determined by the following IDs').'</b>';
1.408 albertel 9018: foreach my $id (sort(keys(%correct_ids))) {
1.411 www 9019: $result.='<br /><tt>'.$id.'</tt> - ';
1.408 albertel 9020: if ($correct_ids{$id} eq 'specified') {
9021: $result.=&mt('specified');
9022: } else {
9023: my ($uname,$udom)=split(/\:/,$correct_ids{$id});
9024: $result.=&Apache::loncommon::plainname($uname,$udom);
9025: }
9026: $number++;
9027: }
1.411 www 9028: $result.="</p>\n";
1.408 albertel 9029: if ($number==0) {
9030: $result.='<span class="LC_error">'.&mt('No IDs found to determine correct answer').'</span>';
9031: return $result.&show_grading_menu_form($symb);
9032: }
1.404 www 9033: }
1.405 www 9034: if (length($env{'form.upfile'}) < 2) {
1.407 albertel 9035: $result.=&mt('[_1] Error: [_2] The file you attempted to upload, [_3] contained no information. Please check that you entered the correct filename.',
9036: '<span class="LC_error">',
9037: '</span>',
9038: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>');
1.405 www 9039: return $result.&show_grading_menu_form($symb);
9040: }
1.410 www 9041:
9042: # Were able to get all the info needed, now analyze the file
9043:
1.411 www 9044: $result.=&Apache::loncommon::studentbrowser_javascript();
1.418 albertel 9045: $symb = &Apache::lonenc::check_encrypt($symb);
1.410 www 9046: my $heading=&mt('Scanning clicker file');
9047: $result.=(<<ENDHEADER);
9048: <br /><table width="100%" border="0"><tr><td bgcolor="#777777">
9049: <table width="100%" border="0"><tr bgcolor="#e6ffff"><td>
9050: <b>$heading</b></td></tr><tr bgcolor=#ffffe6><td>
9051: <form method="post" action="/adm/grades" name="clickeranalysis">
9052: <input type="hidden" name="symb" value="$symb" />
9053: <input type="hidden" name="command" value="assignclickergrades" />
9054: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
9055: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
1.411 www 9056: <input type="hidden" name="gradingmechanism" value="$env{'form.gradingmechanism'}" />
9057: <input type="hidden" name="pcorrect" value="$env{'form.pcorrect'}" />
9058: <input type="hidden" name="pincorrect" value="$env{'form.pincorrect'}" />
1.410 www 9059: ENDHEADER
1.522 www 9060: if ($env{'form.gradingmechanism'} eq 'given') {
9061: $result.='<input type="hidden" name="correct:given" value="'.$env{'form.givenanswer'}.'" />';
9062: }
1.408 albertel 9063: my %responses;
9064: my @questiontitles;
1.405 www 9065: my $errormsg='';
9066: my $number=0;
9067: if ($env{'form.upfiletype'} eq 'iclicker') {
1.408 albertel 9068: ($errormsg,$number)=&iclicker_eval(\@questiontitles,\%responses);
1.406 www 9069: }
1.419 www 9070: if ($env{'form.upfiletype'} eq 'interwrite') {
9071: ($errormsg,$number)=&interwrite_eval(\@questiontitles,\%responses);
9072: }
1.411 www 9073: $result.='<br />'.&mt('Found [_1] question(s)',$number).'<br />'.
9074: '<input type="hidden" name="number" value="'.$number.'" />'.
9075: &mt('Awarding [_1] percent for correct and [_2] percent for incorrect responses',
9076: $env{'form.pcorrect'},$env{'form.pincorrect'}).
9077: '<br />';
1.522 www 9078: if (($env{'form.gradingmechanism'} eq 'given') && ($number!=$foundgiven)) {
9079: $result.='<span class="LC_error">'.&mt('Number of given answers does not agree with number of questions in file.').'</span>';
9080: return $result.&show_grading_menu_form($symb);
9081: }
1.414 www 9082: # Remember Question Titles
9083: # FIXME: Possibly need delimiter other than ":"
9084: for (my $i=0;$i<$number;$i++) {
9085: $result.='<input type="hidden" name="question:'.$i.'" value="'.
9086: &HTML::Entities::encode($questiontitles[$i],'"&<>').'" />';
9087: }
1.411 www 9088: my $correct_count=0;
9089: my $student_count=0;
9090: my $unknown_count=0;
1.414 www 9091: # Match answers with usernames
9092: # FIXME: Possibly need delimiter other than ":"
1.409 albertel 9093: foreach my $id (keys(%responses)) {
1.410 www 9094: if ($correct_ids{$id}) {
1.414 www 9095: $result.="\n".'<input type="hidden" name="correct:'.$correct_count.':'.$correct_ids{$id}.'" value="'.$responses{$id}.'" />';
1.411 www 9096: $correct_count++;
1.410 www 9097: } elsif ($clicker_ids{$id}) {
1.437 www 9098: if ($clicker_ids{$id}=~/\,/) {
9099: # More than one user with the same clicker!
9100: $result.="\n<hr />".&mt('Clicker registered more than once').": <tt>".$id."</tt><br />";
9101: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
9102: "<select name='multi".$id."'>";
9103: foreach my $reguser (sort(split(/\,/,$clicker_ids{$id}))) {
9104: $result.="<option value='".$reguser."'>".&Apache::loncommon::plainname(split(/\:/,$reguser)).' ('.$reguser.')</option>';
9105: }
9106: $result.='</select>';
9107: $unknown_count++;
9108: } else {
9109: # Good: found one and only one user with the right clicker
9110: $result.="\n".'<input type="hidden" name="student:'.$clicker_ids{$id}.'" value="'.$responses{$id}.'" />';
9111: $student_count++;
9112: }
1.410 www 9113: } else {
1.411 www 9114: $result.="\n<hr />".&mt('Unregistered Clicker')." <tt>".$id."</tt><br />";
9115: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
9116: "\n".&mt("Username").": <input type='text' name='uname".$id."' /> ".
9117: "\n".&mt("Domain").": ".
9118: &Apache::loncommon::select_dom_form($env{'course.'.$env{'request.course.id'}.'.domain'},'udom'.$id).' '.
9119: &Apache::loncommon::selectstudent_link('clickeranalysis','uname'.$id,'udom'.$id);
9120: $unknown_count++;
1.410 www 9121: }
1.405 www 9122: }
1.412 www 9123: $result.='<hr />'.
9124: &mt('Found [_1] registered and [_2] unregistered clickers.',$student_count,$unknown_count);
1.521 www 9125: if (($env{'form.gradingmechanism'} ne 'attendance') && ($env{'form.gradingmechanism'} ne 'given')) {
1.412 www 9126: if ($correct_count==0) {
9127: $errormsg.="Found no correct answers answers for grading!";
9128: } elsif ($correct_count>1) {
1.414 www 9129: $result.='<br /><span class="LC_warning">'.&mt("Found [_1] entries for grading!",$correct_count).'</span>';
1.412 www 9130: }
9131: }
1.428 www 9132: if ($number<1) {
9133: $errormsg.="Found no questions.";
9134: }
1.412 www 9135: if ($errormsg) {
9136: $result.='<br /><span class="LC_error">'.&mt($errormsg).'</span>';
9137: } else {
9138: $result.='<br /><input type="submit" name="finalize" value="'.&mt('Finalize Grading').'" />';
9139: }
9140: $result.='</form></td></tr></table>'."\n".
1.410 www 9141: '</td></tr></table><br /><br />'."\n";
1.404 www 9142: return $result.&show_grading_menu_form($symb);
1.400 www 9143: }
9144:
1.405 www 9145: sub iclicker_eval {
1.406 www 9146: my ($questiontitles,$responses)=@_;
1.405 www 9147: my $number=0;
9148: my $errormsg='';
9149: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
1.410 www 9150: my %components=&Apache::loncommon::record_sep($line);
9151: my @entries=map {$components{$_}} (sort(keys(%components)));
1.408 albertel 9152: if ($entries[0] eq 'Question') {
9153: for (my $i=3;$i<$#entries;$i+=6) {
9154: $$questiontitles[$number]=$entries[$i];
9155: $number++;
9156: }
9157: }
9158: if ($entries[0]=~/^\#/) {
9159: my $id=$entries[0];
9160: my @idresponses;
9161: $id=~s/^[\#0]+//;
9162: for (my $i=0;$i<$number;$i++) {
9163: my $idx=3+$i*6;
9164: push(@idresponses,$entries[$idx]);
9165: }
9166: $$responses{$id}=join(',',@idresponses);
9167: }
1.405 www 9168: }
9169: return ($errormsg,$number);
9170: }
9171:
1.419 www 9172: sub interwrite_eval {
9173: my ($questiontitles,$responses)=@_;
9174: my $number=0;
9175: my $errormsg='';
1.420 www 9176: my $skipline=1;
9177: my $questionnumber=0;
9178: my %idresponses=();
1.419 www 9179: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
9180: my %components=&Apache::loncommon::record_sep($line);
9181: my @entries=map {$components{$_}} (sort(keys(%components)));
1.420 www 9182: if ($entries[1] eq 'Time') { $skipline=0; next; }
9183: if ($entries[1] eq 'Response') { $skipline=1; }
9184: next if $skipline;
9185: if ($entries[0]!=$questionnumber) {
9186: $questionnumber=$entries[0];
9187: $$questiontitles[$number]=&mt('Question [_1]',$questionnumber);
9188: $number++;
1.419 www 9189: }
1.420 www 9190: my $id=$entries[4];
9191: $id=~s/^[\#0]+//;
1.421 www 9192: $id=~s/^v\d*\://i;
9193: $id=~s/[\-\:]//g;
1.420 www 9194: $idresponses{$id}[$number]=$entries[6];
9195: }
1.524 raeburn 9196: foreach my $id (keys(%idresponses)) {
1.420 www 9197: $$responses{$id}=join(',',@{$idresponses{$id}});
9198: $$responses{$id}=~s/^\s*\,//;
1.419 www 9199: }
9200: return ($errormsg,$number);
9201: }
9202:
1.414 www 9203: sub assign_clicker_grades {
9204: my ($r)=@_;
9205: my ($symb)=&get_symb($r);
9206: if (!$symb) {return '';}
1.416 www 9207: # See which part we are saving to
1.582 raeburn 9208: my $res_error;
9209: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
9210: if ($res_error) {
9211: return &navmap_errormsg();
9212: }
1.416 www 9213: # FIXME: This should probably look for the first handgradeable part
9214: my $part=$$partlist[0];
9215: # Start screen output
1.414 www 9216: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.416 www 9217:
1.414 www 9218: my $heading=&mt('Assigning grades based on clicker file');
9219: $result.=(<<ENDHEADER);
9220: <br /><table width="100%" border="0"><tr><td bgcolor="#777777">
9221: <table width="100%" border="0"><tr bgcolor="#e6ffff"><td>
9222: <b>$heading</b></td></tr><tr bgcolor=#ffffe6><td>
9223: ENDHEADER
9224: # Get correct result
9225: # FIXME: Possibly need delimiter other than ":"
9226: my @correct=();
1.415 www 9227: my $gradingmechanism=$env{'form.gradingmechanism'};
9228: my $number=$env{'form.number'};
9229: if ($gradingmechanism ne 'attendance') {
1.414 www 9230: foreach my $key (keys(%env)) {
9231: if ($key=~/^form\.correct\:/) {
9232: my @input=split(/\,/,$env{$key});
9233: for (my $i=0;$i<=$#input;$i++) {
9234: if (($correct[$i]) && ($input[$i]) &&
9235: ($correct[$i] ne $input[$i])) {
9236: $result.='<br /><span class="LC_warning">'.
9237: &mt('More than one correct result given for question "[_1]": [_2] versus [_3].',
9238: $env{'form.question:'.$i},$correct[$i],$input[$i]).'</span>';
9239: } elsif ($input[$i]) {
9240: $correct[$i]=$input[$i];
9241: }
9242: }
9243: }
9244: }
1.415 www 9245: for (my $i=0;$i<$number;$i++) {
1.414 www 9246: if (!$correct[$i]) {
9247: $result.='<br /><span class="LC_error">'.
9248: &mt('No correct result given for question "[_1]"!',
9249: $env{'form.question:'.$i}).'</span>';
9250: }
9251: }
9252: $result.='<br />'.&mt("Correct answer: [_1]",join(', ',map { ($_?$_:'-') } @correct));
9253: }
9254: # Start grading
1.415 www 9255: my $pcorrect=$env{'form.pcorrect'};
9256: my $pincorrect=$env{'form.pincorrect'};
1.416 www 9257: my $storecount=0;
1.415 www 9258: foreach my $key (keys(%env)) {
1.420 www 9259: my $user='';
1.415 www 9260: if ($key=~/^form\.student\:(.*)$/) {
1.420 www 9261: $user=$1;
9262: }
9263: if ($key=~/^form\.unknown\:(.*)$/) {
9264: my $id=$1;
9265: if (($env{'form.uname'.$id}) && ($env{'form.udom'.$id})) {
9266: $user=$env{'form.uname'.$id}.':'.$env{'form.udom'.$id};
1.437 www 9267: } elsif ($env{'form.multi'.$id}) {
9268: $user=$env{'form.multi'.$id};
1.420 www 9269: }
9270: }
9271: if ($user) {
1.415 www 9272: my @answer=split(/\,/,$env{$key});
9273: my $sum=0;
1.522 www 9274: my $realnumber=$number;
1.415 www 9275: for (my $i=0;$i<$number;$i++) {
1.576 www 9276: if ($correct[$i] eq '-') {
9277: $realnumber--;
9278: } elsif ($answer[$i]) {
1.415 www 9279: if ($gradingmechanism eq 'attendance') {
9280: $sum+=$pcorrect;
1.576 www 9281: } elsif ($correct[$i] eq '*') {
1.522 www 9282: $sum+=$pcorrect;
1.415 www 9283: } else {
9284: if ($answer[$i] eq $correct[$i]) {
9285: $sum+=$pcorrect;
9286: } else {
9287: $sum+=$pincorrect;
9288: }
9289: }
9290: }
9291: }
1.522 www 9292: my $ave=$sum/(100*$realnumber);
1.416 www 9293: # Store
9294: my ($username,$domain)=split(/\:/,$user);
9295: my %grades=();
9296: $grades{"resource.$part.solved"}='correct_by_override';
9297: $grades{"resource.$part.awarded"}=$ave;
9298: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
9299: my $returncode=&Apache::lonnet::cstore(\%grades,$symb,
9300: $env{'request.course.id'},
9301: $domain,$username);
9302: if ($returncode ne 'ok') {
9303: $result.="<br /><span class=\"LC_error\">Failed to save student $username:$domain. Message when trying to save was ($returncode)</span>";
9304: } else {
9305: $storecount++;
9306: }
1.415 www 9307: }
9308: }
9309: # We are done
1.549 hauer 9310: $result.='<br />'.&mt('Successfully stored grades for [quant,_1,student].',$storecount).
1.416 www 9311: '</td></tr></table>'."\n".
1.414 www 9312: '</td></tr></table><br /><br />'."\n";
9313: return $result.&show_grading_menu_form($symb);
9314: }
9315:
1.582 raeburn 9316: sub navmap_errormsg {
9317: return '<div class="LC_error">'.
9318: &mt('An error occurred retrieving information about resources in the course.').'<br />'.
9319: &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>').
9320: '</div>';
9321: }
9322:
1.1 albertel 9323: sub handler {
1.41 ng 9324: my $request=$_[0];
1.434 albertel 9325: &reset_caches();
1.257 albertel 9326: if ($env{'browser.mathml'}) {
1.141 www 9327: &Apache::loncommon::content_type($request,'text/xml');
1.41 ng 9328: } else {
1.141 www 9329: &Apache::loncommon::content_type($request,'text/html');
1.41 ng 9330: }
9331: $request->send_http_header;
1.44 ng 9332: return '' if $request->header_only;
1.41 ng 9333: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.324 albertel 9334: my $symb=&get_symb($request,1);
1.160 albertel 9335: my @commands=&Apache::loncommon::get_env_multiple('form.command');
9336: my $command=$commands[0];
1.447 foxr 9337:
1.160 albertel 9338: if ($#commands > 0) {
9339: &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands));
9340: }
1.447 foxr 9341:
1.513 foxr 9342: $ssi_error = 0;
1.535 raeburn 9343: my $brcrum = [{href=>"/adm/grades",text=>"Grading"}];
9344: $request->print(&Apache::loncommon::start_page('Grading',undef,
9345: {'bread_crumbs' => $brcrum}));
1.324 albertel 9346: if ($symb eq '' && $command eq '') {
1.257 albertel 9347: if ($env{'user.adv'}) {
9348: if (($env{'form.codeone'}) && ($env{'form.codetwo'}) &&
9349: ($env{'form.codethree'})) {
9350: my $token=$env{'form.codeone'}.'*'.$env{'form.codetwo'}.'*'.
9351: $env{'form.codethree'};
1.41 ng 9352: my ($tsymb,$tuname,$tudom,$tcrsid)=
9353: &Apache::lonnet::checkin($token);
9354: if ($tsymb) {
1.137 albertel 9355: my ($map,$id,$url)=&Apache::lonnet::decode_symb($tsymb);
1.41 ng 9356: if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
1.513 foxr 9357: $request->print(&ssi_with_retries('/res/'.$url, $ssi_retries,
1.99 albertel 9358: ('grade_username' => $tuname,
9359: 'grade_domain' => $tudom,
9360: 'grade_courseid' => $tcrsid,
9361: 'grade_symb' => $tsymb)));
1.41 ng 9362: } else {
1.45 ng 9363: $request->print('<h3>Not authorized: '.$token.'</h3>');
1.99 albertel 9364: }
1.41 ng 9365: } else {
1.45 ng 9366: $request->print('<h3>Not a valid DocID: '.$token.'</h3>');
1.41 ng 9367: }
1.14 www 9368: } else {
1.41 ng 9369: $request->print(&Apache::lonxml::tokeninputfield());
9370: }
9371: }
9372: } else {
1.285 albertel 9373: &init_perm();
1.104 albertel 9374: if ($command eq 'submission' && $perm{'vgr'}) {
1.257 albertel 9375: ($env{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0));
1.103 albertel 9376: } elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) {
1.68 ng 9377: &pickStudentPage($request);
1.103 albertel 9378: } elsif ($command eq 'displayPage' && $perm{'vgr'}) {
1.68 ng 9379: &displayPage($request);
1.104 albertel 9380: } elsif ($command eq 'gradeByPage' && $perm{'mgr'}) {
1.71 ng 9381: &updateGradeByPage($request);
1.104 albertel 9382: } elsif ($command eq 'processGroup' && $perm{'vgr'}) {
1.41 ng 9383: &processGroup($request);
1.104 albertel 9384: } elsif ($command eq 'gradingmenu' && $perm{'vgr'}) {
1.443 banghart 9385: $request->print(&grading_menu($request));
9386: } elsif ($command eq 'submit_options' && $perm{'vgr'}) {
9387: $request->print(&submit_options($request));
1.104 albertel 9388: } elsif ($command eq 'viewgrades' && $perm{'vgr'}) {
1.41 ng 9389: $request->print(&viewgrades($request));
1.104 albertel 9390: } elsif ($command eq 'handgrade' && $perm{'mgr'}) {
1.41 ng 9391: $request->print(&processHandGrade($request));
1.106 albertel 9392: } elsif ($command eq 'editgrades' && $perm{'mgr'}) {
1.41 ng 9393: $request->print(&editgrades($request));
1.106 albertel 9394: } elsif ($command eq 'verify' && $perm{'vgr'}) {
1.41 ng 9395: $request->print(&verifyreceipt($request));
1.400 www 9396: } elsif ($command eq 'processclicker' && $perm{'mgr'}) {
9397: $request->print(&process_clicker($request));
9398: } elsif ($command eq 'processclickerfile' && $perm{'mgr'}) {
9399: $request->print(&process_clicker_file($request));
1.414 www 9400: } elsif ($command eq 'assignclickergrades' && $perm{'mgr'}) {
9401: $request->print(&assign_clicker_grades($request));
1.106 albertel 9402: } elsif ($command eq 'csvform' && $perm{'mgr'}) {
1.72 ng 9403: $request->print(&upcsvScores_form($request));
1.106 albertel 9404: } elsif ($command eq 'csvupload' && $perm{'mgr'}) {
1.41 ng 9405: $request->print(&csvupload($request));
1.106 albertel 9406: } elsif ($command eq 'csvuploadmap' && $perm{'mgr'} ) {
1.41 ng 9407: $request->print(&csvuploadmap($request));
1.246 albertel 9408: } elsif ($command eq 'csvuploadoptions' && $perm{'mgr'}) {
1.257 albertel 9409: if ($env{'form.associate'} ne 'Reverse Association') {
1.246 albertel 9410: $request->print(&csvuploadoptions($request));
1.41 ng 9411: } else {
1.257 albertel 9412: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
9413: $env{'form.upfile_associate'} = 'reverse';
1.41 ng 9414: } else {
1.257 albertel 9415: $env{'form.upfile_associate'} = 'forward';
1.41 ng 9416: }
9417: $request->print(&csvuploadmap($request));
9418: }
1.246 albertel 9419: } elsif ($command eq 'csvuploadassign' && $perm{'mgr'} ) {
9420: $request->print(&csvuploadassign($request));
1.106 albertel 9421: } elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
1.75 albertel 9422: $request->print(&scantron_selectphase($request));
1.203 albertel 9423: } elsif ($command eq 'scantron_warning' && $perm{'mgr'}) {
9424: $request->print(&scantron_do_warning($request));
1.142 albertel 9425: } elsif ($command eq 'scantron_validate' && $perm{'mgr'}) {
9426: $request->print(&scantron_validate_file($request));
1.106 albertel 9427: } elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
1.82 albertel 9428: $request->print(&scantron_process_students($request));
1.157 albertel 9429: } elsif ($command eq 'scantronupload' &&
1.257 albertel 9430: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
9431: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.162 albertel 9432: $request->print(&scantron_upload_scantron_data($request));
1.157 albertel 9433: } elsif ($command eq 'scantronupload_save' &&
1.257 albertel 9434: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
9435: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.157 albertel 9436: $request->print(&scantron_upload_scantron_data_save($request));
1.202 albertel 9437: } elsif ($command eq 'scantron_download' &&
1.257 albertel 9438: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.162 albertel 9439: $request->print(&scantron_download_scantron_data($request));
1.523 raeburn 9440: } elsif ($command eq 'checksubmissions' && $perm{'vgr'}) {
9441: $request->print(&checkscantron_results($request));
1.106 albertel 9442: } elsif ($command) {
1.562 bisitz 9443: $request->print('<p class="LC_error">'.&mt('Access Denied ([_1])',$command).'</p>');
1.26 albertel 9444: }
1.2 albertel 9445: }
1.513 foxr 9446: if ($ssi_error) {
9447: &ssi_print_error($request);
9448: }
1.353 albertel 9449: $request->print(&Apache::loncommon::end_page());
1.434 albertel 9450: &reset_caches();
1.44 ng 9451: return '';
9452: }
9453:
1.1 albertel 9454: 1;
9455:
1.13 albertel 9456: __END__;
1.531 jms 9457:
9458:
9459: =head1 NAME
9460:
9461: Apache::grades
9462:
9463: =head1 SYNOPSIS
9464:
9465: Handles the viewing of grades.
9466:
9467: This is part of the LearningOnline Network with CAPA project
9468: described at http://www.lon-capa.org.
9469:
9470: =head1 OVERVIEW
9471:
9472: Do an ssi with retries:
9473: While I'd love to factor out this with the vesrion in lonprintout,
9474: 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
9475: I'm not quite ready to invent (e.g. an ssi_with_retry object).
9476:
9477: At least the logic that drives this has been pulled out into loncommon.
9478:
9479:
9480:
9481: ssi_with_retries - Does the server side include of a resource.
9482: if the ssi call returns an error we'll retry it up to
9483: the number of times requested by the caller.
9484: If we still have a proble, no text is appended to the
9485: output and we set some global variables.
9486: to indicate to the caller an SSI error occurred.
9487: All of this is supposed to deal with the issues described
9488: in LonCAPA BZ 5631 see:
9489: http://bugs.lon-capa.org/show_bug.cgi?id=5631
9490: by informing the user that this happened.
9491:
9492: Parameters:
9493: resource - The resource to include. This is passed directly, without
9494: interpretation to lonnet::ssi.
9495: form - The form hash parameters that guide the interpretation of the resource
9496:
9497: retries - Number of retries allowed before giving up completely.
9498: Returns:
9499: On success, returns the rendered resource identified by the resource parameter.
9500: Side Effects:
9501: The following global variables can be set:
9502: ssi_error - If an unrecoverable error occurred this becomes true.
9503: It is up to the caller to initialize this to false
9504: if desired.
9505: ssi_error_resource - If an unrecoverable error occurred, this is the value
9506: of the resource that could not be rendered by the ssi
9507: call.
9508: ssi_error_message - The error string fetched from the ssi response
9509: in the event of an error.
9510:
9511:
9512: =head1 HANDLER SUBROUTINE
9513:
9514: ssi_with_retries()
9515:
9516: =head1 SUBROUTINES
9517:
9518: =over
9519:
9520: =item scantron_get_correction() :
9521:
9522: Builds the interface screen to interact with the operator to fix a
9523: specific error condition in a specific scanline
9524:
9525: Arguments:
9526: $r - Apache request object
9527: $i - number of the current scanline
9528: $scan_record - hash ref as returned from &scantron_parse_scanline()
9529: $scan_config - hash ref as returned from &get_scantron_config()
9530: $line - full contents of the current scanline
9531: $error - error condition, valid values are
9532: 'incorrectCODE', 'duplicateCODE',
9533: 'doublebubble', 'missingbubble',
9534: 'duplicateID', 'incorrectID'
9535: $arg - extra information needed
9536: For errors:
9537: - duplicateID - paper number that this studentID was seen before on
9538: - duplicateCODE - array ref of the paper numbers this CODE was
9539: seen on before
9540: - incorrectCODE - current incorrect CODE
9541: - doublebubble - array ref of the bubble lines that have double
9542: bubble errors
9543: - missingbubble - array ref of the bubble lines that have missing
9544: bubble errors
9545:
9546: =item scantron_get_maxbubble() :
9547:
1.582 raeburn 9548: Arguments:
9549: $nav_error - Reference to scalar which is a flag to indicate a
9550: failure to retrieve a navmap object.
9551: if $nav_error is set to 1 by scantron_get_maxbubble(), the
9552: calling routine should trap the error condition and display the warning
9553: found in &navmap_errormsg().
9554:
1.531 jms 9555: Returns the maximum number of bubble lines that are expected to
9556: occur. Does this by walking the selected sequence rendering the
9557: resource and then checking &Apache::lonxml::get_problem_counter()
9558: for what the current value of the problem counter is.
9559:
9560: Caches the results to $env{'form.scantron_maxbubble'},
9561: $env{'form.scantron.bubble_lines.n'},
9562: $env{'form.scantron.first_bubble_line.n'} and
9563: $env{"form.scantron.sub_bubblelines.n"}
9564: which are the total number of bubble, lines, the number of bubble
9565: lines for response n and number of the first bubble line for response n,
9566: and a comma separated list of numbers of bubble lines for sub-questions
9567: (for optionresponse, matchresponse, and rankresponse items), for response n.
9568:
9569:
9570: =item scantron_validate_missingbubbles() :
9571:
9572: Validates all scanlines in the selected file to not have any
9573: answers that don't have bubbles that have not been verified
9574: to be bubble free.
9575:
9576: =item scantron_process_students() :
9577:
9578: Routine that does the actual grading of the bubble sheet information.
9579:
9580: The parsed scanline hash is added to %env
9581:
9582: Then foreach unskipped scanline it does an &Apache::lonnet::ssi()
9583: foreach resource , with the form data of
9584:
9585: 'submitted' =>'scantron'
9586: 'grade_target' =>'grade',
9587: 'grade_username'=> username of student
9588: 'grade_domain' => domain of student
9589: 'grade_courseid'=> of course
9590: 'grade_symb' => symb of resource to grade
9591:
9592: This triggers a grading pass. The problem grading code takes care
9593: of converting the bubbled letter information (now in %env) into a
9594: valid submission.
9595:
9596: =item scantron_upload_scantron_data() :
9597:
9598: Creates the screen for adding a new bubble sheet data file to a course.
9599:
9600: =item scantron_upload_scantron_data_save() :
9601:
9602: Adds a provided bubble information data file to the course if user
9603: has the correct privileges to do so.
9604:
9605: =item valid_file() :
9606:
9607: Validates that the requested bubble data file exists in the course.
9608:
9609: =item scantron_download_scantron_data() :
9610:
9611: Shows a list of the three internal files (original, corrected,
9612: skipped) for a specific bubble sheet data file that exists in the
9613: course.
9614:
9615: =item scantron_validate_ID() :
9616:
9617: Validates all scanlines in the selected file to not have any
1.556 weissno 9618: invalid or underspecified student/employee IDs
1.531 jms 9619:
1.582 raeburn 9620: =item navmap_errormsg() :
9621:
9622: Returns HTML mark-up inside a <div></div> with a link to re-initialize the course.
9623: Should be called whenever the request to instantiate a navmap object fails.
9624:
1.531 jms 9625: =back
9626:
9627: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>