Annotation of loncom/homework/grades.pm, revision 1.810
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.810 ! raeburn 4: # $Id: grades.pm,v 1.809 2025/01/18 21:17:09 raeburn Exp $
1.17 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
1.529 jms 29:
30:
1.1 albertel 31: package Apache::grades;
32: use strict;
33: use Apache::style;
34: use Apache::lonxml;
35: use Apache::lonnet;
1.3 albertel 36: use Apache::loncommon;
1.112 ng 37: use Apache::lonhtmlcommon;
1.68 ng 38: use Apache::lonnavmaps;
1.1 albertel 39: use Apache::lonhomework;
1.456 banghart 40: use Apache::lonpickcode;
1.55 matthew 41: use Apache::loncoursedata;
1.362 albertel 42: use Apache::lonmsg();
1.646 raeburn 43: use Apache::Constants qw(:common :http);
1.167 sakharuk 44: use Apache::lonlocal;
1.386 raeburn 45: use Apache::lonenc;
1.622 www 46: use Apache::lonstathelpers;
1.639 www 47: use Apache::lonquickgrades;
1.657 raeburn 48: use Apache::bridgetask();
1.752 raeburn 49: use Apache::lontexconvert();
1.796 raeburn 50: use Apache::loncourserespicker;
1.170 albertel 51: use String::Similarity;
1.760 raeburn 52: use HTML::Parser();
53: use File::MMagic;
1.359 www 54: use LONCAPA;
1.796 raeburn 55: use LONCAPA::ltiutils();
1.359 www 56:
1.315 bowersj2 57: use POSIX qw(floor);
1.87 www 58:
1.435 foxr 59:
1.513 foxr 60:
1.435 foxr 61: my %perm=();
1.674 raeburn 62: my %old_essays=();
1.447 foxr 63:
1.513 foxr 64: # These variables are used to recover from ssi errors
65:
66: my $ssi_retries = 5;
67: my $ssi_error;
68: my $ssi_error_resource;
69: my $ssi_error_message;
1.798 raeburn 70: my $registered_cleanup;
1.513 foxr 71:
72: sub ssi_with_retries {
73: my ($resource, $retries, %form) = @_;
74: my ($content, $response) = &Apache::loncommon::ssi_with_retries($resource, $retries, %form);
75: if ($response->is_error) {
76: $ssi_error = 1;
77: $ssi_error_resource = $resource;
78: $ssi_error_message = $response->code . " " . $response->message;
79: }
80:
81: return $content;
82:
83: }
84: #
85: # Prodcuces an ssi retry failure error message to the user:
86: #
87:
88: sub ssi_print_error {
89: my ($r) = @_;
1.516 raeburn 90: my $helpurl = &Apache::loncommon::top_nav_help('Helpdesk');
91: $r->print('
92: <br />
93: <h2>'.&mt('An unrecoverable network error occurred:').'</h2>
94: <p>
95: '.&mt('Unable to retrieve a resource from a server:').'<br />
96: '.&mt('Resource:').' '.$ssi_error_resource.'<br />
97: '.&mt('Error:').' '.$ssi_error_message.'
98: </p>
99: <p>'.
100: &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 />'.
101: &mt('If the error persists, please contact the [_1] for assistance.',$helpurl).
102: '</p>');
103: return;
1.513 foxr 104: }
105:
1.44 ng 106: #
1.146 albertel 107: # --- Retrieve the parts from the metadata file.---
1.598 www 108: # Returns an array of everything that the resources stores away
109: #
110:
1.44 ng 111: sub getpartlist {
1.582 raeburn 112: my ($symb,$errorref) = @_;
1.439 albertel 113:
114: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 115: unless (ref($navmap)) {
116: if (ref($errorref)) {
117: $$errorref = 'navmap';
118: return;
119: }
120: }
1.439 albertel 121: my $res = $navmap->getBySymb($symb);
122: my $partlist = $res->parts();
123: my $url = $res->src();
1.745 raeburn 124: my $toolsymb;
125: if ($url =~ /ext\.tool$/) {
126: $toolsymb = $symb;
127: }
128: my @metakeys = split(/,/,&Apache::lonnet::metadata($url,'keys',$toolsymb));
1.439 albertel 129:
1.146 albertel 130: my @stores;
1.439 albertel 131: foreach my $part (@{ $partlist }) {
1.146 albertel 132: foreach my $key (@metakeys) {
133: if ($key =~ m/^stores_\Q$part\E_/) { push(@stores,$key); }
134: }
135: }
136: return @stores;
1.2 albertel 137: }
138:
1.129 ng 139: #--- Format fullname, username:domain if different for display
140: #--- Use anywhere where the student names are listed
141: sub nameUserString {
142: my ($type,$fullname,$uname,$udom) = @_;
143: if ($type eq 'header') {
1.485 albertel 144: return '<b> '.&mt('Fullname').' </b><span class="LC_internal_info">('.&mt('Username').')</span>';
1.129 ng 145: } else {
1.398 albertel 146: return ' '.$fullname.'<span class="LC_internal_info"> ('.$uname.
147: ($env{'user.domain'} eq $udom ? '' : ' ('.$udom.')').')</span>';
1.129 ng 148: }
149: }
150:
1.44 ng 151: #--- Get the partlist and the response type for a given problem. ---
1.773 raeburn 152: #--- Count responseIDs, essayresponse items, and dropbox items ---
1.623 www 153: #--- Sets response_error pointer to "1" if navmaps object broken ---
1.39 ng 154: sub response_type {
1.582 raeburn 155: my ($symb,$response_error) = @_;
1.377 albertel 156:
157: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 158: unless (ref($navmap)) {
159: if (ref($response_error)) {
160: $$response_error = 1;
161: }
162: return;
163: }
1.377 albertel 164: my $res = $navmap->getBySymb($symb);
1.593 raeburn 165: unless (ref($res)) {
166: $$response_error = 1;
167: return;
168: }
1.377 albertel 169: my $partlist = $res->parts();
1.773 raeburn 170: my ($numresp,$numessay,$numdropbox) = (0,0,0);
1.392 albertel 171: my %vPart =
172: map { $_ => 1 } (&Apache::loncommon::get_env_multiple('form.vPart'));
1.377 albertel 173: my (%response_types,%handgrade);
174: foreach my $part (@{ $partlist }) {
1.392 albertel 175: next if (%vPart && !exists($vPart{$part}));
176:
1.377 albertel 177: my @types = $res->responseType($part);
178: my @ids = $res->responseIds($part);
179: for (my $i=0; $i < scalar(@ids); $i++) {
1.773 raeburn 180: $numresp ++;
1.377 albertel 181: $response_types{$part}{$ids[$i]} = $types[$i];
1.773 raeburn 182: if ($types[$i] eq 'essay') {
183: $numessay ++;
184: if (&Apache::lonnet::EXT("resource.$part".'_'.$ids[$i].".uploadedfiletypes",$symb)) {
185: $numdropbox ++;
186: }
187: }
1.377 albertel 188: $handgrade{$part.'_'.$ids[$i]} =
189: &Apache::lonnet::EXT('resource.'.$part.'_'.$ids[$i].
190: '.handgrade',$symb);
1.41 ng 191: }
192: }
1.773 raeburn 193: return ($partlist,\%handgrade,\%response_types,$numresp,$numessay,$numdropbox);
1.39 ng 194: }
195:
1.375 albertel 196: sub flatten_responseType {
197: my ($responseType) = @_;
198: my @part_response_id =
199: map {
200: my $part = $_;
201: map {
202: [$part,$_]
203: } sort(keys(%{ $responseType->{$part} }));
204: } sort(keys(%$responseType));
205: return @part_response_id;
206: }
207:
1.207 albertel 208: sub get_display_part {
1.324 albertel 209: my ($partID,$symb)=@_;
1.207 albertel 210: my $display=&Apache::lonnet::EXT('resource.'.$partID.'.display',$symb);
211: if (defined($display) and $display ne '') {
1.577 bisitz 212: $display.= ' (<span class="LC_internal_info">'
213: .&mt('Part ID: [_1]',$partID).'</span>)';
1.207 albertel 214: } else {
215: $display=$partID;
216: }
217: return $display;
218: }
1.269 raeburn 219:
1.773 raeburn 220: #--- Show parts and response type
221: sub showResourceInfo {
222: my ($symb,$partlist,$responseType,$formname,$checkboxes,$uploads) = @_;
223: unless ((ref($partlist) eq 'ARRAY') && (ref($responseType) eq 'HASH')) {
224: return '<br clear="all">';
225: }
226: my $coltitle = &mt('Problem Part Shown');
227: if ($checkboxes) {
228: $coltitle = &mt('Problem Part');
229: } else {
230: my $checkedparts = 0;
231: foreach my $partid (&Apache::loncommon::get_env_multiple('form.vPart')) {
232: if (grep(/^\Q$partid\E$/,@{$partlist})) {
233: $checkedparts ++;
234: }
235: }
236: if ($checkedparts == scalar(@{$partlist})) {
237: return '<br clear="all">';
238: }
239: if ($uploads) {
240: $coltitle = &mt('Problem Part Selected');
241: }
242: }
243: my $result = '<div class="LC_left_float" style="display:inline-block;">';
244: if ($checkboxes) {
245: my $legend = &mt('Parts to display');
246: if ($uploads) {
247: $legend = &mt('Part(s) with dropbox');
248: }
249: $result .= '<fieldset style="display:inline-block;"><legend>'.$legend.'</legend>'.
250: '<span class="LC_nobreak">'.
251: '<label><input type="radio" name="chooseparts" value="0" onclick="toggleParts('."'$formname'".');" checked="checked" />'.
252: &mt('All parts').'</label>'.(' 'x2).
253: '<label><input type="radio" name="chooseparts" value="1" onclick="toggleParts('."'$formname'".');" />'.
254: &mt('Selected parts').'</label></span>'.
255: '<div id="LC_partselector" style="display:none">';
256: }
257: $result .= &Apache::loncommon::start_data_table()
258: .&Apache::loncommon::start_data_table_header_row();
259: if ($checkboxes) {
260: $result .= '<th>'.&mt('Display?').'</th>';
261: }
262: $result .= '<th>'.$coltitle.'</th>'
263: .'<th>'.&mt('Res. ID').'</th>'
264: .'<th>'.&mt('Type').'</th>'
265: .&Apache::loncommon::end_data_table_header_row();
266: my %partsseen;
267: foreach my $partID (sort(keys(%$responseType))) {
268: foreach my $resID (sort(keys(%{ $responseType->{$partID} }))) {
269: my $responsetype = $responseType->{$partID}->{$resID};
270: if ($uploads) {
271: next unless ($responsetype eq 'essay');
272: next unless (&Apache::lonnet::EXT("resource.$partID".'_'."$resID.uploadedfiletypes",$symb));
273: }
274: my $display_part=&get_display_part($partID,$symb);
275: if (exists($partsseen{$partID})) {
276: $result.=&Apache::loncommon::continue_data_table_row();
277: } else {
278: $partsseen{$partID}=scalar(keys(%{$responseType->{$partID}}));
279: $result.=&Apache::loncommon::start_data_table_row().
280: '<td rowspan="'.$partsseen{$partID}.'" style="vertical-align:middle">';
281: if ($checkboxes) {
282: $result.='<input type="checkbox" name="vPart" checked="checked" value="'.$partID.'" /></td>'.
283: '<td rowspan="'.$partsseen{$partID}.'" style="vertical-align:middle">'.$display_part.'</td>';
284: } else {
285: $result.=$display_part.'</td>';
286: }
287: }
288: $result.='<td>'.'<span class="LC_internal_info">'.$resID.'</span></td>'
289: .'<td>'.&mt($responsetype).'</td>'
290: .&Apache::loncommon::end_data_table_row();
291: }
292: }
293: $result.=&Apache::loncommon::end_data_table();
294: if ($checkboxes) {
295: $result .= '</div></fieldset>';
296: }
297: $result .= '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.775 raeburn 298: if (!keys(%partsseen)) {
299: $result = '';
300: if ($uploads) {
301: return '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
302: '<p class="LC_info">'.
303: &mt('No dropbox items or essayresponse items with uploadedfiletypes set.').
304: '</p>';
305: } else {
306: return '<br clear="all" />';
307: }
308: }
1.773 raeburn 309: return $result;
310: }
311:
312: sub part_selector_js {
313: my $js = <<"END";
314: function toggleParts(formname) {
315: if (document.getElementById('LC_partselector')) {
316: var index = '';
317: if (document.forms.length) {
318: for (var i=0; i<document.forms.length; i++) {
319: if (document.forms[i].name == formname) {
320: index = i;
321: break;
322: }
323: }
324: }
325: if ((index != '') && (document.forms[index].elements['chooseparts'].length > 1)) {
326: for (var i=0; i<document.forms[index].elements['chooseparts'].length; i++) {
327: if (document.forms[index].elements['chooseparts'][i].checked) {
328: var val = document.forms[index].elements['chooseparts'][i].value;
329: if (document.forms[index].elements['chooseparts'][i].value == 1) {
330: document.getElementById('LC_partselector').style.display = 'block';
331: } else {
332: document.getElementById('LC_partselector').style.display = 'none';
333: }
334: }
335: }
336: }
337: }
338: }
339: END
340: return &Apache::lonhtmlcommon::scripttag($js);
341: }
342:
1.434 albertel 343: sub reset_caches {
344: &reset_analyze_cache();
345: &reset_perm();
1.674 raeburn 346: &reset_old_essays();
1.434 albertel 347: }
348:
349: {
350: my %analyze_cache;
1.557 raeburn 351: my %analyze_cache_formkeys;
1.148 albertel 352:
1.434 albertel 353: sub reset_analyze_cache {
354: undef(%analyze_cache);
1.557 raeburn 355: undef(%analyze_cache_formkeys);
1.434 albertel 356: }
357:
358: sub get_analyze {
1.649 raeburn 359: my ($symb,$uname,$udom,$no_increment,$add_to_hash,$type,$trial,$rndseed,$bubbles_per_row)=@_;
1.434 albertel 360: my $key = "$symb\0$uname\0$udom";
1.640 raeburn 361: if ($type eq 'randomizetry') {
362: if ($trial ne '') {
363: $key .= "\0".$trial;
364: }
365: }
1.557 raeburn 366: if (exists($analyze_cache{$key})) {
367: my $getupdate = 0;
368: if (ref($add_to_hash) eq 'HASH') {
369: foreach my $item (keys(%{$add_to_hash})) {
370: if (ref($analyze_cache_formkeys{$key}) eq 'HASH') {
371: if (!exists($analyze_cache_formkeys{$key}{$item})) {
372: $getupdate = 1;
373: last;
374: }
375: } else {
376: $getupdate = 1;
377: }
378: }
379: }
380: if (!$getupdate) {
381: return $analyze_cache{$key};
382: }
383: }
1.434 albertel 384:
385: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
386: $url=&Apache::lonnet::clutter($url);
1.557 raeburn 387: my %form = ('grade_target' => 'analyze',
388: 'grade_domain' => $udom,
389: 'grade_symb' => $symb,
390: 'grade_courseid' => $env{'request.course.id'},
391: 'grade_username' => $uname,
392: 'grade_noincrement' => $no_increment);
1.649 raeburn 393: if ($bubbles_per_row ne '') {
394: $form{'bubbles_per_row'} = $bubbles_per_row;
395: }
1.640 raeburn 396: if ($type eq 'randomizetry') {
397: $form{'grade_questiontype'} = $type;
398: if ($rndseed ne '') {
399: $form{'grade_rndseed'} = $rndseed;
400: }
401: }
1.557 raeburn 402: if (ref($add_to_hash)) {
403: %form = (%form,%{$add_to_hash});
1.640 raeburn 404: }
1.557 raeburn 405: my $subresult=&ssi_with_retries($url, $ssi_retries,%form);
1.434 albertel 406: (undef,$subresult)=split(/_HASH_REF__/,$subresult,2);
407: my %analyze=&Apache::lonnet::str2hash($subresult);
1.557 raeburn 408: if (ref($add_to_hash) eq 'HASH') {
409: $analyze_cache_formkeys{$key} = $add_to_hash;
410: } else {
411: $analyze_cache_formkeys{$key} = {};
412: }
1.434 albertel 413: return $analyze_cache{$key} = \%analyze;
414: }
415:
416: sub get_order {
1.640 raeburn 417: my ($partid,$respid,$symb,$uname,$udom,$no_increment,$type,$trial,$rndseed)=@_;
418: my $analyze = &get_analyze($symb,$uname,$udom,$no_increment,undef,$type,$trial,$rndseed);
1.434 albertel 419: return $analyze->{"$partid.$respid.shown"};
420: }
421:
422: sub get_radiobutton_correct_foil {
1.640 raeburn 423: my ($partid,$respid,$symb,$uname,$udom,$type,$trial,$rndseed)=@_;
424: my $analyze = &get_analyze($symb,$uname,$udom,undef,undef,$type,$trial,$rndseed);
425: my $foils = &get_order($partid,$respid,$symb,$uname,$udom,undef,$type,$trial,$rndseed);
1.555 raeburn 426: if (ref($foils) eq 'ARRAY') {
427: foreach my $foil (@{$foils}) {
428: if ($analyze->{"$partid.$respid.foil.value.$foil"} eq 'true') {
429: return $foil;
430: }
1.434 albertel 431: }
432: }
433: }
1.554 raeburn 434:
435: sub scantron_partids_tograde {
1.741 raeburn 436: my ($resource,$cid,$uname,$udom,$check_for_randomlist,$bubbles_per_row,$scancode) = @_;
1.554 raeburn 437: my (%analysis,@parts);
438: if (ref($resource)) {
439: my $symb = $resource->symb();
1.557 raeburn 440: my $add_to_form;
441: if ($check_for_randomlist) {
442: $add_to_form = { 'check_parts_withrandomlist' => 1,};
443: }
1.741 raeburn 444: if ($scancode) {
445: if (ref($add_to_form) eq 'HASH') {
446: $add_to_form->{'code_for_randomlist'} = $scancode;
447: } else {
448: $add_to_form = { 'code_for_randomlist' => $scancode,};
449: }
450: }
1.767 raeburn 451: my $analyze =
1.649 raeburn 452: &get_analyze($symb,$uname,$udom,undef,$add_to_form,
453: undef,undef,undef,$bubbles_per_row);
1.554 raeburn 454: if (ref($analyze) eq 'HASH') {
455: %analysis = %{$analyze};
456: }
457: if (ref($analysis{'parts'}) eq 'ARRAY') {
458: foreach my $part (@{$analysis{'parts'}}) {
459: my ($id,$respid) = split(/\./,$part);
460: if (!&Apache::loncommon::check_if_partid_hidden($id,$symb,$udom,$uname)) {
461: push(@parts,$part);
462: }
463: }
464: }
465: }
466: return (\%analysis,\@parts);
467: }
468:
1.148 albertel 469: }
1.434 albertel 470:
1.118 ng 471: #--- Clean response type for display
1.335 albertel 472: #--- Currently filters option/rank/radiobutton/match/essay/Task
473: # response types only.
1.118 ng 474: sub cleanRecord {
1.336 albertel 475: my ($answer,$response,$symb,$partid,$respid,$record,$order,$version,
1.640 raeburn 476: $uname,$udom,$type,$trial,$rndseed) = @_;
1.398 albertel 477: my $grayFont = '<span class="LC_internal_info">';
1.148 albertel 478: if ($response =~ /^(option|rank)$/) {
479: my %answer=&Apache::lonnet::str2hash($answer);
1.720 kruse 480: my @answer = %answer;
1.767 raeburn 481: %answer = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.148 albertel 482: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
483: my ($toprow,$bottomrow);
484: foreach my $foil (@$order) {
485: if ($grading{$foil} == 1) {
486: $toprow.='<td><b>'.$answer{$foil}.' </b></td>';
487: } else {
488: $toprow.='<td><i>'.$answer{$foil}.' </i></td>';
489: }
1.398 albertel 490: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.148 albertel 491: }
492: return '<blockquote><table border="1">'.
1.466 albertel 493: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
494: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.660 raeburn 495: $bottomrow.'</tr></table></blockquote>';
1.148 albertel 496: } elsif ($response eq 'match') {
497: my %answer=&Apache::lonnet::str2hash($answer);
1.720 kruse 498: my @answer = %answer;
1.767 raeburn 499: %answer = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.148 albertel 500: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
501: my @items=&Apache::lonnet::str2array($record->{$version."resource.$partid.$respid.submissionitems"});
502: my ($toprow,$middlerow,$bottomrow);
503: foreach my $foil (@$order) {
504: my $item=shift(@items);
505: if ($grading{$foil} == 1) {
506: $toprow.='<td><b>'.$item.' </b></td>';
1.398 albertel 507: $middlerow.='<td><b>'.$grayFont.$answer{$foil}.' </span></b></td>';
1.148 albertel 508: } else {
509: $toprow.='<td><i>'.$item.' </i></td>';
1.398 albertel 510: $middlerow.='<td><i>'.$grayFont.$answer{$foil}.' </span></i></td>';
1.148 albertel 511: }
1.398 albertel 512: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.118 ng 513: }
1.126 ng 514: return '<blockquote><table border="1">'.
1.466 albertel 515: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
516: '<tr valign="top"><td>'.$grayFont.&mt('Item ID').'</span></td>'.
1.148 albertel 517: $middlerow.'</tr>'.
1.466 albertel 518: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.660 raeburn 519: $bottomrow.'</tr></table></blockquote>';
1.148 albertel 520: } elsif ($response eq 'radiobutton') {
521: my %answer=&Apache::lonnet::str2hash($answer);
1.720 kruse 522: my @answer = %answer;
523: %answer = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.148 albertel 524: my ($toprow,$bottomrow);
1.434 albertel 525: my $correct =
1.640 raeburn 526: &get_radiobutton_correct_foil($partid,$respid,$symb,$uname,$udom,$type,$trial,$rndseed);
1.434 albertel 527: foreach my $foil (@$order) {
1.148 albertel 528: if (exists($answer{$foil})) {
1.434 albertel 529: if ($foil eq $correct) {
1.466 albertel 530: $toprow.='<td><b>'.&mt('true').'</b></td>';
1.148 albertel 531: } else {
1.466 albertel 532: $toprow.='<td><i>'.&mt('true').'</i></td>';
1.148 albertel 533: }
534: } else {
1.466 albertel 535: $toprow.='<td>'.&mt('false').'</td>';
1.148 albertel 536: }
1.398 albertel 537: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.148 albertel 538: }
539: return '<blockquote><table border="1">'.
1.466 albertel 540: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
541: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.660 raeburn 542: $bottomrow.'</tr></table></blockquote>';
1.148 albertel 543: } elsif ($response eq 'essay') {
1.257 albertel 544: if (! exists ($env{'form.'.$symb})) {
1.122 ng 545: my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 546: $env{'course.'.$env{'request.course.id'}.'.domain'},
547: $env{'course.'.$env{'request.course.id'}.'.num'});
1.122 ng 548:
1.257 albertel 549: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
550: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
551: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
552: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
553: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
554: $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 555: }
1.751 raeburn 556: $answer = &Apache::lontexconvert::msgtexconverted($answer);
1.730 kruse 557: return '<br /><br /><blockquote><tt>'.&keywords_highlight($answer).'</tt></blockquote>';
1.268 albertel 558: } elsif ( $response eq 'organic') {
1.721 bisitz 559: my $result=&mt('Smile representation: [_1]',
560: '"<tt>'.&HTML::Entities::encode($answer, '"<>&').'</tt>"');
1.268 albertel 561: my $jme=$record->{$version."resource.$partid.$respid.molecule"};
562: $result.=&Apache::chemresponse::jme_img($jme,$answer,400);
563: return $result;
1.335 albertel 564: } elsif ( $response eq 'Task') {
565: if ( $answer eq 'SUBMITTED') {
566: my $files = $record->{$version."resource.$respid.$partid.bridgetask.portfiles"};
1.336 albertel 567: my $result = &Apache::bridgetask::file_list($files,$uname,$udom);
1.335 albertel 568: return $result;
569: } elsif ( grep(/^\Q$version\E.*?\.instance$/, keys(%{$record})) ) {
570: my @matches = grep(/^\Q$version\E.*?\.instance$/,
571: keys(%{$record}));
572: return join('<br />',($version,@matches));
573:
574:
575: } else {
576: my $result =
577: '<p>'
578: .&mt('Overall result: [_1]',
579: $record->{$version."resource.$respid.$partid.status"})
580: .'</p>';
581:
582: $result .= '<ul>';
583: my @grade = grep(/^\Q${version}resource.$respid.$partid.\E[^.]*[.]status$/,
584: keys(%{$record}));
585: foreach my $grade (sort(@grade)) {
586: my ($dim) = ($grade =~/[.]([^.]+)[.]status$/);
587: $result.= '<li>'.&mt("Dimension: [_1], status [_2] ",
588: $dim, $record->{$grade}).
589: '</li>';
590: }
591: $result.='</ul>';
592: return $result;
593: }
1.716 bisitz 594: } elsif ( $response =~ m/(?:numerical|formula|custom)/) {
595: # Respect multiple input fields, see Bug #5409
1.440 albertel 596: $answer =
597: &Apache::loncommon::format_previous_attempt_value('submission',
598: $answer);
1.720 kruse 599: return $answer;
1.122 ng 600: }
1.720 kruse 601: return &HTML::Entities::encode($answer, '"<>&');
1.118 ng 602: }
603:
604: #-- A couple of common js functions
605: sub commonJSfunctions {
606: my $request = shift;
1.597 wenzelju 607: $request->print(&Apache::lonhtmlcommon::scripttag(<<COMMONJSFUNCTIONS));
1.118 ng 608: function radioSelection(radioButton) {
609: var selection=null;
610: if (radioButton.length > 1) {
611: for (var i=0; i<radioButton.length; i++) {
612: if (radioButton[i].checked) {
613: return radioButton[i].value;
614: }
615: }
616: } else {
617: if (radioButton.checked) return radioButton.value;
618: }
619: return selection;
620: }
621:
622: function pullDownSelection(selectOne) {
623: var selection="";
624: if (selectOne.length > 1) {
625: for (var i=0; i<selectOne.length; i++) {
626: if (selectOne[i].selected) {
627: return selectOne[i].value;
628: }
629: }
630: } else {
1.138 albertel 631: // only one value it must be the selected one
632: return selectOne.value;
1.118 ng 633: }
634: }
635: COMMONJSFUNCTIONS
636: }
637:
1.44 ng 638: #--- Dumps the class list with usernames,list of sections,
639: #--- section, ids and fullnames for each user.
640: sub getclasslist {
1.796 raeburn 641: my ($getsec,$filterbyaccstatus,$getgroup,$symb,$submitonly,$filterbysubmstatus,$filterbypbid,$possibles) = @_;
1.291 albertel 642: my @getsec;
1.450 banghart 643: my @getgroup;
1.442 banghart 644: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.291 albertel 645: if (!ref($getsec)) {
646: if ($getsec ne '' && $getsec ne 'all') {
647: @getsec=($getsec);
648: }
649: } else {
650: @getsec=@{$getsec};
651: }
652: if (grep(/^all$/,@getsec)) { undef(@getsec); }
1.450 banghart 653: if (!ref($getgroup)) {
654: if ($getgroup ne '' && $getgroup ne 'all') {
655: @getgroup=($getgroup);
656: }
657: } else {
658: @getgroup=@{$getgroup};
659: }
660: if (grep(/^all$/,@getgroup)) { undef(@getgroup); }
1.291 albertel 661:
1.449 banghart 662: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
1.49 albertel 663: # Bail out if we were unable to get the classlist
1.56 matthew 664: return if (! defined($classlist));
1.449 banghart 665: &Apache::loncoursedata::get_group_memberships($classlist,$keylist);
1.56 matthew 666: #
667: my %sections;
668: my %fullnames;
1.796 raeburn 669: my %passback;
1.750 raeburn 670: my ($cdom,$cnum,$partlist);
671: if (($filterbysubmstatus) && ($submitonly ne 'all') && ($symb ne '')) {
672: $cdom = $env{"course.$env{'request.course.id'}.domain"};
673: $cnum = $env{"course.$env{'request.course.id'}.num"};
674: my $res_error;
1.773 raeburn 675: ($partlist) = &response_type($symb,\$res_error);
1.796 raeburn 676: } elsif ($filterbypbid) {
677: $cdom = $env{"course.$env{'request.course.id'}.domain"};
678: $cnum = $env{"course.$env{'request.course.id'}.num"};
1.750 raeburn 679: }
1.205 matthew 680: foreach my $student (keys(%$classlist)) {
681: my $end =
682: $classlist->{$student}->[&Apache::loncoursedata::CL_END()];
683: my $start =
684: $classlist->{$student}->[&Apache::loncoursedata::CL_START()];
685: my $id =
686: $classlist->{$student}->[&Apache::loncoursedata::CL_ID()];
687: my $section =
688: $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
689: my $fullname =
690: $classlist->{$student}->[&Apache::loncoursedata::CL_FULLNAME()];
691: my $status =
692: $classlist->{$student}->[&Apache::loncoursedata::CL_STATUS()];
1.449 banghart 693: my $group =
694: $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1.76 ng 695: # filter students according to status selected
1.750 raeburn 696: if ($filterbyaccstatus && (!($stu_status =~ /Any/))) {
1.442 banghart 697: if (!($stu_status =~ $status)) {
1.450 banghart 698: delete($classlist->{$student});
1.76 ng 699: next;
700: }
701: }
1.450 banghart 702: # filter students according to groups selected
1.453 banghart 703: my @stu_groups = split(/,/,$group);
1.450 banghart 704: if (@getgroup) {
705: my $exclude = 1;
1.454 banghart 706: foreach my $grp (@getgroup) {
707: foreach my $stu_group (@stu_groups) {
1.453 banghart 708: if ($stu_group eq $grp) {
709: $exclude = 0;
710: }
1.450 banghart 711: }
1.453 banghart 712: if (($grp eq 'none') && !$group) {
1.750 raeburn 713: $exclude = 0;
1.453 banghart 714: }
1.450 banghart 715: }
716: if ($exclude) {
717: delete($classlist->{$student});
1.750 raeburn 718: next;
1.450 banghart 719: }
720: }
1.750 raeburn 721: if (($filterbysubmstatus) && ($submitonly ne 'all') && ($symb ne '')) {
722: my $udom =
723: $classlist->{$student}->[&Apache::loncoursedata::CL_SDOM()];
724: my $uname =
725: $classlist->{$student}->[&Apache::loncoursedata::CL_SNAME()];
726: if (($symb ne '') && ($udom ne '') && ($uname ne '')) {
727: if ($submitonly eq 'queued') {
728: my %queue_status =
729: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
730: $udom,$uname);
731: if (!defined($queue_status{'gradingqueue'})) {
732: delete($classlist->{$student});
733: next;
734: }
735: } else {
736: my (%status) =&student_gradeStatus($symb,$udom,$uname,$partlist);
737: my $submitted = 0;
738: my $graded = 0;
739: my $incorrect = 0;
740: foreach (keys(%status)) {
741: $submitted = 1 if ($status{$_} ne 'nothing');
742: $graded = 1 if ($status{$_} =~ /^ungraded/);
743: $incorrect = 1 if ($status{$_} =~ /^incorrect/);
744:
745: my ($foo,$partid,$foo1) = split(/\./,$_);
746: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
747: $submitted = 0;
748: }
749: }
750: if (!$submitted && ($submitonly eq 'yes' ||
751: $submitonly eq 'incorrect' ||
752: $submitonly eq 'graded')) {
753: delete($classlist->{$student});
754: next;
755: } elsif (!$graded && ($submitonly eq 'graded')) {
756: delete($classlist->{$student});
757: next;
758: } elsif (!$incorrect && $submitonly eq 'incorrect') {
759: delete($classlist->{$student});
760: next;
761: }
762: }
763: }
764: }
1.796 raeburn 765: if ($filterbypbid) {
766: if (ref($possibles) eq 'HASH') {
767: unless (exists($possibles->{$student})) {
768: delete($classlist->{$student});
769: next;
770: }
771: }
772: my $udom =
773: $classlist->{$student}->[&Apache::loncoursedata::CL_SDOM()];
774: my $uname =
775: $classlist->{$student}->[&Apache::loncoursedata::CL_SNAME()];
776: if (($udom ne '') && ($uname ne '')) {
777: my %pbinfo = &Apache::lonnet::get('nohist_'.$cdom.'_'.$cnum.'_linkprot_pb',[$filterbypbid],$udom,$uname);
778: if (ref($pbinfo{$filterbypbid}) eq 'ARRAY') {
1.798 raeburn 779: $passback{$student} = $pbinfo{$filterbypbid};
1.796 raeburn 780: } else {
781: delete($classlist->{$student});
782: next;
783: }
784: }
785: }
1.205 matthew 786: $section = ($section ne '' ? $section : 'none');
1.106 albertel 787: if (&canview($section)) {
1.291 albertel 788: if (!@getsec || grep(/^\Q$section\E$/,@getsec)) {
1.103 albertel 789: $sections{$section}++;
1.450 banghart 790: if ($classlist->{$student}) {
791: $fullnames{$student}=$fullname;
792: }
1.103 albertel 793: } else {
1.205 matthew 794: delete($classlist->{$student});
1.103 albertel 795: }
796: } else {
1.205 matthew 797: delete($classlist->{$student});
1.103 albertel 798: }
1.44 ng 799: }
1.56 matthew 800: my @sections = sort(keys(%sections));
1.796 raeburn 801: return ($classlist,\@sections,\%fullnames,\%passback);
1.44 ng 802: }
803:
1.103 albertel 804: sub canmodify {
805: my ($sec)=@_;
806: if ($perm{'mgr'}) {
807: if (!defined($perm{'mgr_section'})) {
808: # can modify whole class
809: return 1;
810: } else {
811: if ($sec eq $perm{'mgr_section'}) {
812: #can modify the requested section
813: return 1;
814: } else {
1.763 raeburn 815: # can't modify the requested section
1.103 albertel 816: return 0;
817: }
818: }
819: }
820: #can't modify
821: return 0;
822: }
823:
824: sub canview {
825: my ($sec)=@_;
826: if ($perm{'vgr'}) {
827: if (!defined($perm{'vgr_section'})) {
1.763 raeburn 828: # can view whole class
1.103 albertel 829: return 1;
830: } else {
831: if ($sec eq $perm{'vgr_section'}) {
1.763 raeburn 832: #can view the requested section
1.103 albertel 833: return 1;
834: } else {
1.763 raeburn 835: # can't view the requested section
1.103 albertel 836: return 0;
837: }
838: }
839: }
1.763 raeburn 840: #can't view
1.103 albertel 841: return 0;
842: }
843:
1.44 ng 844: #--- Retrieve the grade status of a student for all the parts
845: sub student_gradeStatus {
1.324 albertel 846: my ($symb,$udom,$uname,$partlist) = @_;
1.257 albertel 847: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.44 ng 848: my %partstatus = ();
849: foreach (@$partlist) {
1.128 ng 850: my ($status,undef) = split(/_/,$record{"resource.$_.solved"},2);
1.44 ng 851: $status = 'nothing' if ($status eq '');
852: $partstatus{$_} = $status;
853: my $subkey = "resource.$_.submitted_by";
854: $partstatus{$subkey} = $record{$subkey} if ($record{$subkey} ne '');
855: }
856: return %partstatus;
857: }
858:
1.45 ng 859: # hidden form and javascript that calls the form
860: # Use by verifyscript and viewgrades
861: # Shows a student's view of problem and submission
862: sub jscriptNform {
1.324 albertel 863: my ($symb) = @_;
1.442 banghart 864: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.597 wenzelju 865: my $jscript= &Apache::lonhtmlcommon::scripttag(
1.45 ng 866: ' function viewOneStudent(user,domain) {'."\n".
867: ' document.onestudent.student.value = user;'."\n".
868: ' document.onestudent.userdom.value = domain;'."\n".
869: ' document.onestudent.submit();'."\n".
870: ' }'."\n".
1.597 wenzelju 871: "\n");
1.45 ng 872: $jscript.= '<form action="/adm/grades" method="post" name="onestudent">'."\n".
1.418 albertel 873: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.442 banghart 874: '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.45 ng 875: '<input type="hidden" name="command" value="submission" />'."\n".
876: '<input type="hidden" name="student" value="" />'."\n".
877: '<input type="hidden" name="userdom" value="" />'."\n".
878: '</form>'."\n";
879: return $jscript;
880: }
1.39 ng 881:
1.447 foxr 882:
883:
1.315 bowersj2 884: # Given the score (as a number [0-1] and the weight) what is the final
885: # point value? This function will round to the nearest tenth, third,
886: # or quarter if one of those is within the tolerance of .00001.
1.316 albertel 887: sub compute_points {
1.315 bowersj2 888: my ($score, $weight) = @_;
889:
890: my $tolerance = .00001;
891: my $points = $score * $weight;
892:
893: # Check for nearness to 1/x.
894: my $check_for_nearness = sub {
895: my ($factor) = @_;
896: my $num = ($points * $factor) + $tolerance;
897: my $floored_num = floor($num);
1.316 albertel 898: if ($num - $floored_num < 2 * $tolerance * $factor) {
1.315 bowersj2 899: return $floored_num / $factor;
900: }
901: return $points;
902: };
903:
904: $points = $check_for_nearness->(10);
905: $points = $check_for_nearness->(3);
906: $points = $check_for_nearness->(4);
907:
908: return $points;
909: }
910:
1.44 ng 911: #------------------ End of general use routines --------------------
1.87 www 912:
913: #
914: # Find most similar essay
915: #
916:
917: sub most_similar {
1.674 raeburn 918: my ($uname,$udom,$symb,$uessay)=@_;
919:
920: unless ($symb) { return ''; }
921:
922: unless (ref($old_essays{$symb}) eq 'HASH') { return ''; }
1.87 www 923:
924: # ignore spaces and punctuation
925:
926: $uessay=~s/\W+/ /gs;
927:
1.282 www 928: # ignore empty submissions (occuring when only files are sent)
929:
1.598 www 930: unless ($uessay=~/\w+/s) { return ''; }
1.282 www 931:
1.87 www 932: # these will be returned. Do not care if not at least 50 percent similar
1.88 www 933: my $limit=0.6;
1.87 www 934: my $sname='';
935: my $sdom='';
936: my $scrsid='';
937: my $sessay='';
938: # go through all essays ...
1.674 raeburn 939: foreach my $tkey (keys(%{$old_essays{$symb}})) {
1.426 albertel 940: my ($tname,$tdom,$tcrsid)=map {&unescape($_)} (split(/\./,$tkey));
1.87 www 941: # ... except the same student
1.426 albertel 942: next if (($tname eq $uname) && ($tdom eq $udom));
1.674 raeburn 943: my $tessay=$old_essays{$symb}{$tkey};
1.426 albertel 944: $tessay=~s/\W+/ /gs;
1.87 www 945: # String similarity gives up if not even limit
1.426 albertel 946: my $tsimilar=&String::Similarity::similarity($uessay,$tessay,$limit);
1.87 www 947: # Found one
1.426 albertel 948: if ($tsimilar>$limit) {
949: $limit=$tsimilar;
950: $sname=$tname;
951: $sdom=$tdom;
952: $scrsid=$tcrsid;
1.674 raeburn 953: $sessay=$old_essays{$symb}{$tkey};
1.426 albertel 954: }
1.87 www 955: }
1.88 www 956: if ($limit>0.6) {
1.87 www 957: return ($sname,$sdom,$scrsid,$sessay,$limit);
958: } else {
959: return ('','','','',0);
960: }
961: }
962:
1.44 ng 963: #-------------------------------------------------------------------
964:
965: #------------------------------------ Receipt Verification Routines
1.45 ng 966: #
1.602 www 967:
968: sub initialverifyreceipt {
1.608 www 969: my ($request,$symb) = @_;
1.602 www 970: &commonJSfunctions($request);
1.694 bisitz 971: return '<form name="gradingMenu" action=""><input type="submit" value="'.&mt('Verify Receipt Number.').'" />'.
1.602 www 972: &Apache::lonnet::recprefix($env{'request.course.id'}).
973: '-<input type="text" name="receipt" size="4" />'.
1.603 www 974: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
975: '<input type="hidden" name="command" value="verify" />'.
976: "</form>\n";
1.602 www 977: }
978:
1.44 ng 979: #--- Check whether a receipt number is valid.---
980: sub verifyreceipt {
1.766 raeburn 981: my ($request,$symb) = @_;
1.44 ng 982:
1.257 albertel 983: my $courseid = $env{'request.course.id'};
1.184 www 984: my $receipt = &Apache::lonnet::recprefix($courseid).'-'.
1.257 albertel 985: $env{'form.receipt'};
1.44 ng 986: $receipt =~ s/[^\-\d]//g;
987:
1.766 raeburn 988: my $title =
1.487 albertel 989: '<h3><span class="LC_info">'.
1.605 www 990: &mt('Verifying Receipt Number [_1]',$receipt).
991: '</span></h3>'."\n";
1.44 ng 992:
993: my ($string,$contents,$matches) = ('','',0);
1.56 matthew 994: my (undef,undef,$fullname) = &getclasslist('all','0');
1.177 albertel 995:
996: my $receiptparts=0;
1.390 albertel 997: if ($env{"course.$courseid.receiptalg"} eq 'receipt2' ||
998: $env{"course.$courseid.receiptalg"} eq 'receipt3') { $receiptparts=1; }
1.177 albertel 999: my $parts=['0'];
1.582 raeburn 1000: if ($receiptparts) {
1001: my $res_error;
1002: ($parts)=&response_type($symb,\$res_error);
1003: if ($res_error) {
1004: return &navmap_errormsg();
1005: }
1006: }
1.486 albertel 1007:
1008: my $header =
1009: &Apache::loncommon::start_data_table().
1010: &Apache::loncommon::start_data_table_header_row().
1.487 albertel 1011: '<th> '.&mt('Fullname').' </th>'."\n".
1012: '<th> '.&mt('Username').' </th>'."\n".
1013: '<th> '.&mt('Domain').' </th>';
1.486 albertel 1014: if ($receiptparts) {
1.487 albertel 1015: $header.='<th> '.&mt('Problem Part').' </th>';
1.486 albertel 1016: }
1017: $header.=
1018: &Apache::loncommon::end_data_table_header_row();
1019:
1.294 albertel 1020: foreach (sort
1021: {
1022: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
1023: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
1024: }
1025: return $a cmp $b;
1026: } (keys(%$fullname))) {
1.44 ng 1027: my ($uname,$udom)=split(/\:/);
1.177 albertel 1028: foreach my $part (@$parts) {
1029: if ($receipt eq &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb,$part)) {
1.486 albertel 1030: $contents.=
1031: &Apache::loncommon::start_data_table_row().
1032: '<td> '."\n".
1.177 albertel 1033: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 1034: '\');" target="_self">'.$$fullname{$_}.'</a> </td>'."\n".
1.177 albertel 1035: '<td> '.$uname.' </td>'.
1036: '<td> '.$udom.' </td>';
1037: if ($receiptparts) {
1038: $contents.='<td> '.$part.' </td>';
1039: }
1.486 albertel 1040: $contents.=
1041: &Apache::loncommon::end_data_table_row()."\n";
1.177 albertel 1042:
1043: $matches++;
1044: }
1.44 ng 1045: }
1046: }
1047: if ($matches == 0) {
1.584 bisitz 1048: $string = $title
1049: .'<p class="LC_warning">'
1050: .&mt('No match found for the above receipt number.')
1051: .'</p>';
1.44 ng 1052: } else {
1.324 albertel 1053: $string = &jscriptNform($symb).$title.
1.487 albertel 1054: '<p>'.
1.584 bisitz 1055: &mt('The above receipt number matches the following [quant,_1,student].',$matches).
1.487 albertel 1056: '</p>'.
1.486 albertel 1057: $header.
1058: $contents.
1059: &Apache::loncommon::end_data_table()."\n";
1.44 ng 1060: }
1.614 www 1061: return $string;
1.44 ng 1062: }
1063:
1.798 raeburn 1064: #-------------------------------------------------------------------
1065:
1066: #------------------------------------------- Grade Passback Routines
1067: #
1068:
1.796 raeburn 1069: sub initialpassback {
1070: my ($request,$symb) = @_;
1071: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
1072: my $cnum = $env{"course.$env{'request.course.id'}.num"};
1073: my $crstype = &Apache::loncommon::course_type();
1074: my %passback = &Apache::lonnet::dump('nohist_linkprot_passback',$cdom,$cnum);
1075: my $readonly;
1076: unless ($perm{'mgr'}) {
1077: $readonly = 1;
1078: }
1079: my $formname = 'initialpassback';
1080: my $navmap = Apache::lonnavmaps::navmap->new();
1081: my $output;
1082: if (!defined($navmap)) {
1083: if ($crstype eq 'Community') {
1084: $output = &mt('Unable to retrieve information about community contents');
1085: } else {
1086: $output = &mt('Unable to retrieve information about course contents');
1087: }
1088: return '<p>'.$output.'</p>';
1089: }
1090: return &Apache::loncourserespicker::create_picker($navmap,'passback',$formname,$crstype,undef,
1091: undef,undef,undef,undef,undef,undef,
1092: \%passback,$readonly);
1093: }
1094:
1095: sub passback_filters {
1096: my ($request,$symb) = @_;
1097: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
1098: my $cnum = $env{"course.$env{'request.course.id'}.num"};
1099: my $crstype = &Apache::loncommon::course_type();
1100: my ($launcher,$appname,$setter,$linkuri,$linkprotector,$scope,$chosen);
1101: if ($env{'form.passback'} ne '') {
1102: $chosen = &unescape($env{'form.passback'});
1103: ($linkuri,$linkprotector,$scope) = split("\0",$chosen);
1104: ($launcher,$appname,$setter) = &get_passback_launcher($cdom,$cnum,$chosen);
1105: }
1106: my $result;
1107: if ($launcher ne '') {
1108: $result = &launcher_info_box($launcher,$appname,$setter,$linkuri,$scope).
1109: '<p><br />'.&mt('Set criteria to use to list students for possible passback of scores, then push Next [_1]',
1110: '→').
1111: '</p>';
1112: }
1113: $result .= '<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1114: '<input type="hidden" name="passback" value="'.&escape($chosen).'" />'."\n".
1115: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1116: my ($submittext,$newcommand);
1117: if ($launcher ne '') {
1118: $submittext = &mt('Next').' →';
1119: $newcommand = 'passbacknames';
1120: $result .= &selectfield(0)."\n";
1121: } else {
1122: $submittext = '← '.&mt('Previous');
1123: $newcommand = 'initialpassback';
1124: if ($env{'form.passback'}) {
1125: $result .= '<span class="LC_warning">'.&mt('Invalid launcher').'</span>'."\n";
1126: } else {
1127: $result .= '<span class="LC_warning">'.&mt('No launcher selected').'</span>'."\n";
1128: }
1129: }
1130: $result .= '<input type="hidden" name="command" value="'.$newcommand.'" />'."\n".
1131: '<div>'."\n".
1132: '<input type="submit" value="'.$submittext.'" />'."\n".
1133: '</div>'."\n".
1134: '</form>'."\n";
1135: return $result;
1136: }
1137:
1138: sub names_for_passback {
1139: my ($request,$symb) = @_;
1140: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
1141: my $cnum = $env{"course.$env{'request.course.id'}.num"};
1142: my $crstype = &Apache::loncommon::course_type();
1143: my ($launcher,$appname,$setter,$linkuri,$linkprotector,$scope,$chosen);
1144: if ($env{'form.passback'} ne '') {
1145: $chosen = &unescape($env{'form.passback'});
1146: ($linkuri,$linkprotector,$scope) = split("\0",$chosen);
1147: ($launcher,$appname,$setter) = &get_passback_launcher($cdom,$cnum,$chosen);
1148: }
1149: my ($result,$ctr,$newcommand,$submittext);
1150: if ($launcher ne '') {
1151: $result = &launcher_info_box($launcher,$appname,$setter,$linkuri,$scope);
1152: }
1153: $ctr = 0;
1154: my @statuses = &Apache::loncommon::get_env_multiple('form.Status');
1155: my $stu_status = join(':',@statuses);
1156: $result .= '<form action="/adm/grades" method="post" name="passbackusers">'."\n".
1157: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1158: if ($launcher ne '') {
1159: $result .= '<input type="hidden" name="passback" value="'.&escape($chosen).'" />'."\n".
1160: '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n";
1161: my ($sections,$groups,$group_display,$disabled) = §ions_and_groups();
1162: my $section_display = join(' ',@{$sections});
1163: my $status_display;
1164: if ((grep(/^Any$/,@statuses)) ||
1165: (@statuses == 3)) {
1166: $status_display = &mt('Any');
1167: } else {
1168: $status_display = join(' '.&mt('or').' ',map { &mt($_); } @statuses);
1169: }
1170: $result .= '<p>'.&mt('Student(s) with stored passback credentials for [_1], and also satisfy:',
1171: '<span class="LC_cusr_emph">'.$linkuri.'</span>').
1172: '<ul>'.
1173: '<li>'.&mt('Section(s)').": $section_display</li>\n".
1174: '<li>'.&mt('Group(s)').": $group_display</li>\n".
1175: '<li>'.&mt('Status').": $status_display</li>\n".
1176: '</ul>';
1177: my ($classlist,undef,$fullname) = &getclasslist($sections,'1',$groups,'','','',$chosen);
1178: if (keys(%$fullname)) {
1179: $newcommand = 'passbackscores';
1180: $result .= &build_section_inputs().
1181: &checkselect_js('passbackusers').
1182: '<p><br />'.
1183: &mt("To send scores, check box(es) next to the student's name(s), then push 'Send Scores'.").
1184: '</p>'.
1185: &check_script('passbackusers', 'stuinfo')."\n".
1186: '<input type="button" '."\n".
1187: 'onclick="javascript:checkSelect(this.form.stuinfo);" '."\n".
1188: 'value="'.&mt('Send Scores').'" /> <br />'."\n".
1189: &check_buttons()."\n".
1190: &Apache::loncommon::start_data_table().
1191: &Apache::loncommon::start_data_table_header_row();
1192: my $loop = 0;
1193: while ($loop < 2) {
1194: $result .= '<th>'.&mt('No.').'</th><th>'.&mt('Select').'</th>'.
1195: '<th>'.&nameUserString('header').' '.&mt('Section/Group').'</th>';
1196: $loop++;
1197: }
1198: $result .= &Apache::loncommon::end_data_table_header_row()."\n";
1199: foreach my $student (sort
1200: {
1201: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
1202: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
1203: }
1204: return $a cmp $b;
1205: }
1206: (keys(%$fullname))) {
1207: $ctr++;
1208: my $section = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
1209: my $group = $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1210: my $udom = $classlist->{$student}->[&Apache::loncoursedata::CL_SDOM()];
1211: my $uname = $classlist->{$student}->[&Apache::loncoursedata::CL_SNAME()];
1212: if ( $perm{'vgr'} eq 'F' ) {
1213: if ($ctr%2 ==1) {
1214: $result.= &Apache::loncommon::start_data_table_row();
1215: }
1216: $result .= '<td align="right">'.$ctr.' </td>'.
1217: '<td align="center"><label><input type="checkbox" name="stuinfo" value="'.
1218: $student.':'.$$fullname{$student}.':::SECTION'.$section.
1219: ') " /> </label></td>'."\n".'<td>'.
1220: &nameUserString(undef,$$fullname{$student},$uname,$udom).
1221: ' '.$section.($group ne '' ?'/'.$group:'').'</td>'."\n";
1222:
1223: if ($ctr%2 ==0) {
1224: $result .= &Apache::loncommon::end_data_table_row()."\n";
1225: }
1226: }
1227: }
1228: if ($ctr%2 ==1) {
1229: $result .= &Apache::loncommon::end_data_table_row();
1230: }
1231: $result .= &Apache::loncommon::end_data_table()."\n";
1232: if ($ctr) {
1233: $result .= '<input type="button" '.
1234: 'onclick="javascript:checkSelect(this.form.stuinfo);" '.
1235: 'value="'.&mt('Send Scores').'" />'."\n";
1236: }
1237: } else {
1238: $submittext = '← '.&mt('Previous');
1239: $newcommand = 'passback';
1240: $result .= '<span class="LC_warning">'.&mt('No students match the selection criteria').'</p>';
1241: }
1242: } else {
1243: $newcommand = 'initialpassback';
1244: $submittext = &mt('Start over');
1245: if ($env{'form.passback'}) {
1246: $result .= '<span class="LC_warning">'.&mt('Invalid launcher').'</span>'."\n";
1247: } else {
1248: $result .= '<span class="LC_warning">'.&mt('No launcher selected').'</span>'."\n";
1249: }
1250: }
1251: $result .= '<input type="hidden" name="command" value="'.$newcommand.'" />'."\n";
1252: if (!$ctr) {
1253: $result .= '<div>'."\n".
1254: '<input type="submit" value="'.$submittext.'" />'."\n".
1255: '</div>'."\n";
1256: }
1257: $result .= '</form>'."\n";
1258: return $result;
1259: }
1260:
1261: sub do_passback {
1262: my ($request,$symb) = @_;
1263: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
1264: my $cnum = $env{"course.$env{'request.course.id'}.num"};
1265: my $crstype = &Apache::loncommon::course_type();
1.806 raeburn 1266: my ($launchsymb,$appname,$setter,$linkuri,$linkprotector,$scope,$chosen);
1.796 raeburn 1267: if ($env{'form.passback'} ne '') {
1268: $chosen = &unescape($env{'form.passback'});
1269: ($linkuri,$linkprotector,$scope) = split("\0",$chosen);
1.806 raeburn 1270: ($launchsymb,$appname,$setter) = &get_passback_launcher($cdom,$cnum,$chosen);
1.796 raeburn 1271: }
1.806 raeburn 1272: if ($launchsymb ne '') {
1273: $request->print(&launcher_info_box($launchsymb,$appname,$setter,$linkuri,$scope));
1.796 raeburn 1274: }
1275: my $error;
1276: if ($perm{'mgr'}) {
1.806 raeburn 1277: if ($launchsymb ne '') {
1.796 raeburn 1278: my @poss_students = &Apache::loncommon::get_env_multiple('form.stuinfo');
1279: if (@poss_students) {
1280: my %possibles;
1281: foreach my $item (@poss_students) {
1282: my ($stuname,$studom) = split(/:/,$item,3);
1283: $possibles{$stuname.':'.$studom} = 1;
1284: }
1285: my ($sections,$groups,$group_display,$disabled) = §ions_and_groups();
1286: my ($classlist,undef,$fullname,$pbinfo) =
1287: &getclasslist($sections,'1',$groups,'','','',$chosen,\%possibles);
1288: if ((ref($classlist) eq 'HASH') && (ref($pbinfo) eq 'HASH')) {
1289: my %passback = %{$pbinfo};
1290: my (%tosend,%remotenotok,%scorenotok,%zeroposs,%nopbinfo);
1291: foreach my $possible (keys(%possibles)) {
1292: if ((exists($classlist->{$possible})) &&
1293: (exists($passback{$possible})) && (ref($passback{$possible}) eq 'ARRAY')) {
1294: $tosend{$possible} = 1;
1295: }
1296: }
1297: if (keys(%tosend)) {
1298: my ($lti_in_use,$crsdef);
1299: my ($ltinum,$ltitype) = ($linkprotector =~ /^(\d+)(c|d)$/);
1300: if ($ltitype eq 'c') {
1301: my %crslti = &Apache::lonnet::get_course_lti($cnum,$cdom,'provider');
1302: $lti_in_use = $crslti{$ltinum};
1303: $crsdef = 1;
1304: } else {
1305: my %domlti = &Apache::lonnet::get_domain_lti($cdom,'linkprot');
1306: $lti_in_use = $domlti{$ltinum};
1307: }
1308: if (ref($lti_in_use) eq 'HASH') {
1309: my $msgformat = $lti_in_use->{'passbackformat'};
1310: my $keynum = $lti_in_use->{'cipher'};
1311: my $scoretype = 'decimal';
1312: if ($lti_in_use->{'scoreformat'} =~ /^(decimal|ratio|percentage)$/) {
1313: $scoretype = $1;
1314: }
1315: my $pbmap;
1.806 raeburn 1316: if ($launchsymb =~ /\.(page|sequence)$/) {
1317: $pbmap = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($launchsymb))[2]);
1.796 raeburn 1318: } else {
1.806 raeburn 1319: $pbmap = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($launchsymb))[0]);
1.796 raeburn 1320: }
1321: $pbmap = &Apache::lonnet::clutter($pbmap);
1322: my $pbscope;
1323: if ($scope eq 'res') {
1324: $pbscope = 'resource';
1325: } elsif ($scope eq 'map') {
1326: $pbscope = 'nonrec';
1327: } elsif ($scope eq 'rec') {
1328: $pbscope = 'map';
1329: }
1.798 raeburn 1330: my %pb = &common_passback_info();
1.796 raeburn 1331: my $numstudents = scalar(keys(%tosend));
1332: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($request,$numstudents);
1333: my $outcome = &Apache::loncommon::start_data_table().
1.806 raeburn 1334: &Apache::loncommon::start_data_table_header_row();
1.796 raeburn 1335: my $loop = 0;
1336: while ($loop < 2) {
1337: $outcome .= '<th>'.&mt('No.').'</th>'.
1.806 raeburn 1338: '<th>'.&nameUserString('header').' '.&mt('Section/Group').'</th>'.
1339: '<th>'.&mt('Score').'</th>';
1340: $loop++;
1.796 raeburn 1341: }
1342: $outcome .= &Apache::loncommon::end_data_table_header_row()."\n";
1343: my $ctr=0;
1344: foreach my $student (sort
1345: {
1346: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
1347: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
1348: }
1349: return $a cmp $b;
1350: } (keys(%$fullname))) {
1351: next unless ($tosend{$student});
1352: my ($uname,$udom) = split(/:/,$student);
1353: &Apache::lonhtmlcommon::Increment_PrgWin($request,\%prog_state,'last student');
1354: my ($uname,$udom) = split(/:/,$student);
1355: my $uhome = &Apache::lonnet::homeserver($uname,$udom),
1356: my $id = $passback{$student}[0],
1357: my $url = $passback{$student}[1],
1358: my ($total,$possible,$usec);
1359: if (ref($classlist->{$student}) eq 'ARRAY') {
1360: $usec = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION];
1361: }
1362: if ($pbscope eq 'resource') {
1363: $total = 0;
1364: $possible = 0;
1365: my $navmap = Apache::lonnavmaps::navmap->new($uname,$udom);
1366: if (ref($navmap)) {
1.806 raeburn 1367: my $res = $navmap->getBySymb($launchsymb);
1.796 raeburn 1368: if (ref($res)) {
1369: my $partlist = $res->parts();
1370: if (ref($partlist) eq 'ARRAY') {
1.806 raeburn 1371: my %record = &Apache::lonnet::restore($launchsymb,$env{'request.course.id'},$udom,$uname);
1.796 raeburn 1372: foreach my $part (@{$partlist}) {
1373: next if ($record{"resource.$part.solved"} =~/^excused/);
1.806 raeburn 1374: my $weight = &Apache::lonnet::EXT("resource.$part.weight",$launchsymb,$udom,$uname,$usec);
1.796 raeburn 1375: $possible += $weight;
1376: if (($record{'version'}) && (exists($record{"resource.$part.awarded"}))) {
1377: my $awarded = $record{"resource.$part.awarded"};
1378: if ($awarded) {
1379: $total += $weight * $awarded;
1380: }
1381: }
1382: }
1383: }
1384: }
1385: }
1386: } elsif (($pbscope eq 'map') || ($pbscope eq 'nonrec')) {
1387: ($total,$possible) =
1.806 raeburn 1388: &Apache::lonhomework::get_lti_score($uname,$udom,$usec,$pbmap,$pbscope);
1.796 raeburn 1389: }
1390: if (($id ne '') && ($url ne '') && ($possible)) {
1391: my ($sent,$score,$code,$result) =
1.798 raeburn 1392: &LONCAPA::ltiutils::send_grade($cdom,$cnum,$crsdef,$pb{'type'},$ltinum,$keynum,$id,
1393: $url,$scoretype,$pb{'sigmethod'},$msgformat,$total,$possible);
1.796 raeburn 1394: my $no_passback;
1395: if ($sent) {
1396: if ($code == 200) {
1397: delete($tosend{$student});
1398: my $namespace = $cdom.'_'.$cnum.'_lp_passback';
1399: my $store = {
1400: 'score' => $score,
1.798 raeburn 1401: 'ip' => $pb{'ip'},
1402: 'host' => $pb{'lonhost'},
1.796 raeburn 1403: 'protector' => $linkprotector,
1404: 'deeplink' => $linkuri,
1405: 'scope' => $scope,
1406: 'url' => $url,
1407: 'id' => $id,
1.798 raeburn 1408: 'clientip' => $pb{'clientip'},
1.796 raeburn 1409: 'whodoneit' => $env{'user.name'}.':'.$env{'user.domain'},
1.806 raeburn 1410: };
1.796 raeburn 1411: my $value='';
1412: foreach my $key (keys(%{$store})) {
1413: $value.=&escape($key).'='.&Apache::lonnet::freeze_escape($store->{$key}).'&';
1414: }
1415: $value=~s/\&$//;
1416: &Apache::lonnet::courselog(&escape($linkuri).':'.$uname.':'.$udom.':EXPORT:'.$value);
1.807 raeburn 1417: &Apache::lonnet::store_userdata({'score' => $score},$chosen,$namespace,$udom,$uname,$pb{'ip'});
1.796 raeburn 1418: $ctr++;
1419: if ($ctr%2 ==1) {
1420: $outcome .= &Apache::loncommon::start_data_table_row();
1421: }
1422: my $group = $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1423: $outcome .= '<td align="right">'.$ctr.' </td>'.
1.806 raeburn 1424: '<td>'.&nameUserString(undef,$$fullname{$student},$uname,$udom).
1425: ' '.$usec.($group ne '' ?'/'.$group:'').'</td>'.
1426: '<td>'.$score.'</td>'."\n";
1.796 raeburn 1427: if ($ctr%2 ==0) {
1428: $outcome .= &Apache::loncommon::end_data_table_row()."\n";
1429: }
1430: } else {
1431: $remotenotok{$student} = 1;
1432: $no_passback = "Passback response for ".$linkprotector." was $code ($result)";
1433: &Apache::lonnet::logthis($no_passback." for $uname:$udom in ${cdom}_${cnum}");
1434: }
1435: } else {
1436: $scorenotok{$student} = 1;
1437: $no_passback = "Passback of grades not sent for ".$linkprotector;
1438: &Apache::lonnet::logthis($no_passback." for $uname:$udom in ${cdom}_${cnum}");
1439: }
1440: if ($no_passback) {
1441: &Apache::lonnet::log($udom,$uname,$uhome,$no_passback." score: $score; total: $total; possible: $possible");
1.805 raeburn 1442: my $key = &Time::HiRes::time().':'.$uname.':'.$udom.':'.
1443: "$linkuri\0$linkprotector\0$scope";
1.796 raeburn 1444: my $ltigrade = {
1.805 raeburn 1445: $key => {
1446: 'ltinum' => $ltinum,
1447: 'lti' => $lti_in_use,
1448: 'crsdef' => $crsdef,
1449: 'cid' => $cdom.'_'.$cnum,
1450: 'uname' => $uname,
1451: 'udom' => $udom,
1452: 'uhome' => $uhome,
1453: 'pbid' => $id,
1454: 'pburl' => $url,
1455: 'pbtype' => $pb{'type'},
1456: 'pbscope' => $pbscope,
1457: 'pbmap' => $pbmap,
1.806 raeburn 1458: 'pbsymb' => $launchsymb,
1.805 raeburn 1459: 'format' => $scoretype,
1460: 'scope' => $scope,
1461: 'clientip' => $pb{'clientip'},
1462: 'linkprot' => $linkprotector.':'.$linkuri,
1463: 'total' => $total,
1464: 'possible' => $possible,
1465: 'score' => $score,
1466: },
1.796 raeburn 1467: };
1468: &Apache::lonnet::put('linkprot_passback_pending',$ltigrade,$cdom,$cnum);
1469: }
1470: } else {
1471: if (($id ne '') && ($url ne '')) {
1472: $zeroposs{$student} = 1;
1473: } else {
1474: $nopbinfo{$student} = 1;
1475: }
1476: }
1477: }
1478: &Apache::lonhtmlcommon::Close_PrgWin($request,\%prog_state);
1479: if ($ctr%2 ==1) {
1480: $outcome .= &Apache::loncommon::end_data_table_row();
1481: }
1482: $outcome .= &Apache::loncommon::end_data_table();
1483: if ($ctr) {
1484: $request->print('<p><br />'.&mt('Scores sent to launcher CMS').'</p>'.
1485: '<p>'.$outcome.'</p>');
1486: } else {
1487: $request->print('<p>'.&mt('No scores sent to launcher CMS').'</p>');
1488: }
1489: if (keys(%tosend)) {
1490: $request->print('<p>'.&mt('No scores sent for following'));
1491: my ($zeros,$nopbcreds,$noconfirm,$noscore);
1492: foreach my $student (sort
1493: {
1494: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
1495: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
1496: }
1497: return $a cmp $b;
1498: } (keys(%$fullname))) {
1499: next unless ($tosend{$student});
1500: my ($uname,$udom) = split(/:/,$student);
1501: my $line = '<li>'.&nameUserString(undef,$$fullname{$student},$uname,$udom).'</li>'."\n";
1502: if ($zeroposs{$student}) {
1503: $zeros .= $line;
1504: } elsif ($nopbinfo{$student}) {
1505: $nopbcreds .= $line;
1506: } elsif ($remotenotok{$student}) {
1507: $noconfirm .= $line;
1508: } elsif ($scorenotok{$student}) {
1509: $noscore .= $line;
1510: }
1511: }
1512: if ($zeros) {
1513: $request->print('<br />'.&mt('Total points possible was 0').':'.
1514: '<ul>'.$zeros.'</ul><br />');
1515: }
1516: if ($nopbcreds) {
1517: $request->print('<br />'.&mt('Missing unique identifier and/or passback location').':'.
1518: '<ul>'.$nopbcreds.'</ul><br />');
1519: }
1520: if ($noconfirm) {
1521: $request->print('<br />'.&mt('Score receipt not confirmed by receiving CMS').':'.
1522: '<ul>'.$noconfirm.'</ul><br />');
1523: }
1524: if ($noscore) {
1525: $request->print('<br />'.&mt('Score computation or transmission failed').':'.
1526: '<ul>'.$noscore.'</ul><br />');
1527: }
1528: $request->print('</p>');
1529: }
1530: } else {
1531: $error = &mt('Settings for deep-link launch target unavailable, so no scores were sent');
1532: }
1533: } else {
1534: $error = &mt('No available students for whom scores can be sent.');
1535: }
1536: } else {
1537: $error = &mt('Classlist could not be retrieved so no scores were sent.');
1538: }
1539: } else {
1540: $error = &mt('No students selected to receive scores so none were sent.');
1541: }
1542: } else {
1543: if ($env{'form.passback'}) {
1544: $error = &mt('Deep-link launch target was invalid so no scores were sent.');
1545: } else {
1546: $error = &mt('Deep-link launch target was missing so no scores were sent.');
1547: }
1548: }
1549: } else {
1550: $error = &mt('You do not have permission to manage grades, so no scores were sent');
1551: }
1552: if ($error) {
1553: $request->print('<p class="LC_info">'.$error.'</p>');
1554: }
1555: return;
1556: }
1557:
1558: sub get_passback_launcher {
1559: my ($cdom,$cnum,$chosen) = @_;
1560: my ($linkuri,$linkprotector,$scope) = split("\0",$chosen);
1561: my ($ltinum,$ltitype) = ($linkprotector =~ /^(\d+)(c|d)$/);
1562: my ($appname,$setter);
1563: if ($ltitype eq 'c') {
1564: my %lti = &Apache::lonnet::get_course_lti($cnum,$cdom,'provider');
1565: if (ref($lti{$ltinum}) eq 'HASH') {
1566: $appname = $lti{$ltinum}{'name'};
1567: if ($appname) {
1568: $setter = ' (defined in course)';
1569: }
1570: }
1571: } elsif ($ltitype eq 'd') {
1572: my %lti = &Apache::lonnet::get_domain_lti($cdom,'linkprot');
1573: if (ref($lti{$ltinum}) eq 'HASH') {
1574: $appname = $lti{$ltinum}{'name'};
1575: if ($appname) {
1576: $setter = ' (defined in domain)';
1577: }
1578: }
1579: }
1.806 raeburn 1580: my $launchsymb = &Apache::loncommon::symb_from_tinyurl($linkuri,$cnum,$cdom);
1581: if ($launchsymb eq '') {
1582: my %passback = &Apache::lonnet::dump('nohist_linkprot_passback',$cdom,$cnum);
1583: foreach my $poss_symb (keys(%passback)) {
1584: if (ref($passback{$poss_symb}) eq 'HASH') {
1585: if (exists($passback{$poss_symb}{$chosen})) {
1586: $launchsymb = $poss_symb;
1587: last;
1.796 raeburn 1588: }
1589: }
1590: }
1.806 raeburn 1591: if ($launchsymb ne '') {
1592: return ($launchsymb,$appname,$setter);
1593: }
1594: } else {
1595: my %passback = &Apache::lonnet::get('nohist_linkprot_passback',[$launchsymb],$cdom,$cnum);
1596: if (ref($passback{$launchsymb}) eq 'HASH') {
1597: if (exists($passback{$launchsymb}{$chosen})) {
1598: return ($launchsymb,$appname,$setter);
1599: }
1600: }
1.796 raeburn 1601: }
1602: return ();
1603: }
1604:
1605: sub sections_and_groups {
1606: my (@sections,@groups,$group_display);
1607: @groups = &Apache::loncommon::get_env_multiple('form.group');
1608: if (grep(/^all$/,@groups)) {
1609: @groups = ('all');
1610: $group_display = 'all';
1611: } elsif (grep(/^none$/,@groups)) {
1612: @groups = ('none');
1613: $group_display = 'none';
1614: } elsif (@groups > 0) {
1615: $group_display = join(', ',@groups);
1616: }
1617: if ($env{'request.course.sec'} ne '') {
1618: @sections = ($env{'request.course.sec'});
1619: } else {
1620: @sections = &Apache::loncommon::get_env_multiple('form.section');
1621: }
1622: my $disabled = ' disabled="disabled"';
1623: if ($perm{'mgr'}) {
1624: if (grep(/^all$/,@sections)) {
1625: undef($disabled);
1626: } else {
1627: foreach my $sec (@sections) {
1628: if (&canmodify($sec)) {
1629: undef($disabled);
1630: last;
1631: }
1632: }
1633: }
1634: }
1635: if (grep(/^all$/,@sections)) {
1636: @sections = ('all');
1637: }
1638: return(\@sections,\@groups,$group_display,$disabled);
1639: }
1640:
1641: sub launcher_info_box {
1642: my ($launcher,$appname,$setter,$linkuri,$scope) = @_;
1643: my $shownscope;
1644: if ($scope eq 'res') {
1645: $shownscope = &mt('Resource');
1646: } elsif ($scope eq 'map') {
1647: $shownscope = &mt('Folder');
1648: } elsif ($scope eq 'rec') {
1649: $shownscope = &mt('Folder + sub-folders');
1650: }
1651: return '<p>'.
1652: &Apache::lonhtmlcommon::start_pick_box().
1653: &Apache::lonhtmlcommon::row_title(&mt('Launch Item Title')).
1.797 raeburn 1654: &Apache::lonnet::gettitle($launcher).
1.796 raeburn 1655: &Apache::lonhtmlcommon::row_closure().
1656: &Apache::lonhtmlcommon::row_title(&mt('Deep-link')).
1657: $linkuri.
1658: &Apache::lonhtmlcommon::row_closure().
1659: &Apache::lonhtmlcommon::row_title(&mt('Launcher')).
1660: $appname.' '.$setter.
1661: &Apache::lonhtmlcommon::row_closure().
1662: &Apache::lonhtmlcommon::row_title(&mt('Score Type')).
1663: $shownscope.
1664: &Apache::lonhtmlcommon::row_closure(1).
1665: &Apache::lonhtmlcommon::end_pick_box().'</p>'."\n";
1666: }
1667:
1.798 raeburn 1668: sub passbacks_for_symb {
1669: my ($cdom,$cnum,$symb) = @_;
1670: my %passback = &Apache::lonnet::dump('nohist_linkprot_passback',$cdom,$cnum);
1671: my %needpb;
1672: if (keys(%passback)) {
1673: my $checkpb = 1;
1674: if (exists($passback{$symb})) {
1675: if (keys(%passback) == 1) {
1676: undef($checkpb);
1677: }
1678: if (ref($passback{$symb}) eq 'HASH') {
1679: foreach my $launcher (keys(%{$passback{$symb}})) {
1.806 raeburn 1680: $needpb{$launcher} = $symb;
1.798 raeburn 1681: }
1682: }
1683: }
1684: if ($checkpb) {
1685: my ($map,$id,$url) = &Apache::lonnet::decode_symb($symb);
1686: my $navmap = Apache::lonnavmaps::navmap->new();
1687: if (ref($navmap)) {
1688: my $mapres = $navmap->getResourceByUrl($map);
1689: if (ref($mapres)) {
1690: my $mapsymb = $mapres->symb();
1691: if (exists($passback{$mapsymb})) {
1692: if (keys(%passback) == 1) {
1693: undef($checkpb);
1694: }
1695: if (ref($passback{$mapsymb}) eq 'HASH') {
1696: foreach my $launcher (keys(%{$passback{$mapsymb}})) {
1.806 raeburn 1697: $needpb{$launcher} = $mapsymb;
1.798 raeburn 1698: }
1699: }
1700: }
1701: my %posspb;
1702: if ($checkpb) {
1703: my @recurseup = $navmap->recurseup_maps($map,1);
1704: if (@recurseup) {
1705: map { $posspb{$_} = 1; } @recurseup;
1706: }
1707: }
1708: foreach my $key (keys(%passback)) {
1709: if (exists($posspb{$key})) {
1710: if (ref($passback{$key}) eq 'HASH') {
1711: foreach my $launcher (keys(%{$passback{$key}})) {
1712: my ($linkuri,$linkprotector,$scope) = split("\0",$launcher);
1713: next unless ($scope eq 'rec');
1.806 raeburn 1714: $needpb{$launcher} = $key;
1.798 raeburn 1715: }
1716: }
1717: }
1718: }
1719: }
1720: }
1721: }
1722: }
1723: return %needpb;
1724: }
1725:
1726: sub process_passbacks {
1.802 raeburn 1727: my ($context,$symbs,$cdom,$cnum,$udom,$uname,$usec,$weights,$awardeds,$excuseds,$needpb,
1.798 raeburn 1728: $skip_passback,$pbsave,$pbids) = @_;
1729: if ((ref($needpb) eq 'HASH') && (ref($skip_passback) eq 'HASH') && (ref($pbsave) eq 'HASH')) {
1730: my (%weight,%awarded,%excused);
1731: if ((ref($symbs) eq 'ARRAY') && (ref($weights) eq 'HASH') && (ref($awardeds) eq 'HASH') &&
1732: (ref($excuseds) eq 'HASH')) {
1733: %weight = %{$weights};
1734: %awarded = %{$awardeds};
1735: %excused = %{$excuseds};
1736: }
1737: my $uhome = &Apache::lonnet::homeserver($uname,$udom);
1738: my @launchers = keys(%{$needpb});
1739: my %pbinfo;
1740: if (ref($pbids) eq 'HASH') {
1741: %pbinfo = %{$pbids};
1742: } else {
1743: %pbinfo = &Apache::lonnet::get('nohist_'.$cdom.'_'.$cnum.'_linkprot_pb',\@launchers,$udom,$uname);
1744: }
1745: my %pbc = &common_passback_info();
1746: foreach my $launcher (@launchers) {
1747: if (ref($pbinfo{$launcher}) eq 'ARRAY') {
1748: my $pbid = $pbinfo{$launcher}[0];
1749: my $pburl = $pbinfo{$launcher}[1];
1750: my (%total_by_symb,%possible_by_symb);
1751: if (($pbid ne '') && ($pburl ne '')) {
1752: next if ($skip_passback->{$launcher});
1753: my %pb = %pbc;
1754: if ((exists($pbsave->{$launcher})) &&
1755: (ref($pbsave->{$launcher}) eq 'HASH')) {
1756: foreach my $item ('lti_in_use','crsdef','ltinum','keynum','scoretype','msgformat',
1757: 'symb','map','pbscope','linkuri','linkprotector','scope') {
1758: $pb{$item} = $pbsave->{$launcher}{$item};
1759: }
1760: } else {
1761: my $ltitype;
1762: ($pb{'linkuri'},$pb{'linkprotector'},$pb{'scope'}) = split("\0",$launcher);
1763: ($pb{'ltinum'},$ltitype) = ($pb{'linkprotector'} =~ /^(\d+)(c|d)$/);
1764: if ($ltitype eq 'c') {
1765: my %crslti = &Apache::lonnet::get_course_lti($cnum,$cdom,'provider');
1766: $pb{'lti_in_use'} = $crslti{$pb{'ltinum'}};
1767: $pb{'crsdef'} = 1;
1768: } else {
1769: my %domlti = &Apache::lonnet::get_domain_lti($cdom,'linkprot');
1770: $pb{'lti_in_use'} = $domlti{$pb{'ltinum'}};
1771: }
1772: if (ref($pb{'lti_in_use'}) eq 'HASH') {
1773: $pb{'msgformat'} = $pb{'lti_in_use'}->{'passbackformat'};
1774: $pb{'keynum'} = $pb{'lti_in_use'}->{'cipher'};
1775: $pb{'scoretype'} = 'decimal';
1776: if ($pb{'lti_in_use'}->{'scoreformat'} =~ /^(decimal|ratio|percentage)$/) {
1777: $pb{'scoretype'} = $1;
1778: }
1.806 raeburn 1779: $pb{'symb'} = $needpb->{$launcher};
1.798 raeburn 1780: if ($pb{'symb'} =~ /\.(page|sequence)$/) {
1781: $pb{'map'} = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($pb{'symb'}))[2]);
1782: } else {
1783: $pb{'map'} = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($pb{'symb'}))[0]);
1784: }
1785: $pb{'map'} = &Apache::lonnet::clutter($pb{'map'});
1786: if ($pb{'scope'} eq 'res') {
1787: $pb{'pbscope'} = 'resource';
1788: } elsif ($pb{'scope'} eq 'map') {
1789: $pb{'pbscope'} = 'nonrec';
1790: } elsif ($pb{'scope'} eq 'rec') {
1791: $pb{'pbscope'} = 'map';
1792: }
1793: foreach my $item ('lti_in_use','crsdef','ltinum','keynum','scoretype','msgformat',
1794: 'symb','map','pbscope','linkuri','linkprotector','scope') {
1795: $pbsave->{$launcher}{$item} = $pb{$item};
1796: }
1797: } else {
1798: $skip_passback->{$launcher} = 1;
1799: }
1800: }
1801: if (ref($symbs) eq 'ARRAY') {
1802: foreach my $symb (@{$symbs}) {
1803: if ((ref($weight{$symb}) eq 'HASH') && (ref($awarded{$symb}) eq 'HASH') &&
1804: (ref($excused{$symb}) eq 'HASH')) {
1805: foreach my $part (keys(%{$weight{$symb}})) {
1806: if ($excused{$symb}{$part}) {
1807: next;
1808: }
1809: my $partweight = $weight{$symb}{$part} eq '' ? 1 :
1810: $weight{$symb}{$part};
1811: if ($awarded{$symb}{$part}) {
1812: $total_by_symb{$symb} += $partweight * $awarded{$symb}{$part};
1813: }
1814: $possible_by_symb{$symb} += $partweight;
1815: }
1816: }
1817: }
1818: }
1819: if ($context eq 'updatebypage') {
1820: my $ltigrade = {
1821: 'ltinum' => $pb{'ltinum'},
1822: 'lti' => $pb{'lti_in_use'},
1823: 'crsdef' => $pb{'crsdef'},
1824: 'cid' => $cdom.'_'.$cnum,
1825: 'uname' => $uname,
1826: 'udom' => $udom,
1827: 'uhome' => $uhome,
1.802 raeburn 1828: 'usec' => $usec,
1.798 raeburn 1829: 'pbid' => $pbid,
1830: 'pburl' => $pburl,
1831: 'pbtype' => $pb{'type'},
1832: 'pbscope' => $pb{'pbscope'},
1833: 'pbmap' => $pb{'map'},
1834: 'pbsymb' => $pb{'symb'},
1835: 'format' => $pb{'scoretype'},
1836: 'scope' => $pb{'scope'},
1837: 'clientip' => $pb{'clientip'},
1.799 raeburn 1838: 'linkprot' => $pb{'linkprotector'}.':'.$pb{'linkuri'},
1.798 raeburn 1839: 'total_s' => \%total_by_symb,
1840: 'possible_s' => \%possible_by_symb,
1841: };
1.801 raeburn 1842: push(@Apache::grades::ltipassback,$ltigrade);
1.798 raeburn 1843: next;
1844: }
1845: my ($total,$possible);
1846: if ($pb{'pbscope'} eq 'resource') {
1847: $total = $total_by_symb{$pb{'symb'}};
1848: $possible = $possible_by_symb{$pb{'symb'}};
1849: } elsif (($pb{'pbscope'} eq 'map') || ($pb{'pbscope'} eq 'nonrec')) {
1850: ($total,$possible) =
1.806 raeburn 1851: &Apache::lonhomework::get_lti_score($uname,$udom,$usec,$pb{'map'},$pb{'pbscope'},
1.798 raeburn 1852: \%total_by_symb,\%possible_by_symb);
1853: }
1854: if (!$possible) {
1855: $total = 0;
1856: $possible = 1;
1857: }
1858: my ($sent,$score,$code,$result) =
1859: &LONCAPA::ltiutils::send_grade($cdom,$cnum,$pb{'crsdef'},$pb{'type'},$pb{'ltinum'},
1860: $pb{'keynum'},$pbid,$pburl,$pb{'scoretype'},$pb{'sigmethod'},
1861: $pb{'msgformat'},$total,$possible);
1862: my $no_passback;
1863: if ($sent) {
1864: if ($code == 200) {
1865: my $namespace = $cdom.'_'.$cnum.'_lp_passback';
1866: my $store = {
1867: 'score' => $score,
1868: 'ip' => $pb{'ip'},
1869: 'host' => $pb{'lonhost'},
1870: 'protector' => $pb{'linkprotector'},
1871: 'deeplink' => $pb{'linkuri'},
1872: 'scope' => $pb{'scope'},
1873: 'url' => $pburl,
1874: 'id' => $pbid,
1875: 'clientip' => $pb{'clientip'},
1876: 'whodoneit' => $env{'user.name'}.':'.$env{'user.domain'},
1877: };
1878: my $value='';
1879: foreach my $key (keys(%{$store})) {
1880: $value.=&escape($key).'='.&Apache::lonnet::freeze_escape($store->{$key}).'&';
1881: }
1882: $value=~s/\&$//;
1883: &Apache::lonnet::courselog(&escape($pb{'linkuri'}).':'.$uname.':'.$udom.':EXPORT:'.$value);
1.807 raeburn 1884: &Apache::lonnet::store_userdata({'score' => $score},$launcher,$namespace,$udom,$uname,$pb{'ip'});
1.798 raeburn 1885: } else {
1886: $no_passback = 1;
1887: }
1888: } else {
1889: $no_passback = 1;
1890: }
1891: if ($no_passback) {
1892: &Apache::lonnet::log($udom,$uname,$uhome,$no_passback." score: $score; total: $total; possible: $possible");
1893: my $ltigrade = {
1894: 'ltinum' => $pb{'ltinum'},
1895: 'lti' => $pb{'lti_in_use'},
1896: 'crsdef' => $pb{'crsdef'},
1897: 'cid' => $cdom.'_'.$cnum,
1898: 'uname' => $uname,
1899: 'udom' => $udom,
1900: 'uhome' => $uhome,
1901: 'pbid' => $pbid,
1902: 'pburl' => $pburl,
1903: 'pbtype' => $pb{'type'},
1904: 'pbscope' => $pb{'pbscope'},
1905: 'pbmap' => $pb{'map'},
1906: 'pbsymb' => $pb{'symb'},
1907: 'format' => $pb{'scoretype'},
1908: 'scope' => $pb{'scope'},
1909: 'clientip' => $pb{'clientip'},
1.799 raeburn 1910: 'linkprot' => $pb{'linkprotector'}.':'.$pb{'linkuri'},
1.798 raeburn 1911: 'total' => $total,
1912: 'possible' => $possible,
1913: 'score' => $score,
1914: };
1915: &Apache::lonnet::put('linkprot_passback_pending',$ltigrade,$cdom,$cnum);
1916: }
1917: }
1918: }
1919: }
1920: }
1921: return;
1922: }
1923:
1924: sub common_passback_info {
1925: my %pbc = (
1926: sigmethod => 'HMAC-SHA1',
1927: type => 'linkprot',
1928: clientip => &Apache::lonnet::get_requestor_ip(),
1929: lonhost => $Apache::lonnet::perlvar{'lonHostID'},
1930: ip => &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}),
1931: );
1932: return %pbc;
1933: }
1934:
1.44 ng 1935: #--- This is called by a number of programs.
1936: #--- Called from the Grading Menu - View/Grade an individual student
1937: #--- Also called directly when one clicks on the subm button
1938: # on the problem page.
1.30 ng 1939: sub listStudents {
1.773 raeburn 1940: my ($request,$symb,$submitonly,$divforres) = @_;
1.49 albertel 1941:
1.747 raeburn 1942: my $is_tool = ($symb =~ /ext\.tool$/);
1.257 albertel 1943: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
1944: my $cnum = $env{"course.$env{'request.course.id'}.num"};
1945: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.449 banghart 1946: my $getgroup = $env{'form.group'} eq '' ? 'all' : $env{'form.group'};
1.617 www 1947: unless ($submitonly) {
1.766 raeburn 1948: $submitonly = $env{'form.submitonly'} eq '' ? 'all' : $env{'form.submitonly'};
1.617 www 1949: }
1.49 albertel 1950:
1.632 www 1951: my $result='';
1.623 www 1952: my $res_error;
1.773 raeburn 1953: my ($partlist,$handgrade,$responseType,$numresp,$numessay) = &response_type($symb,\$res_error);
1954:
1955: my $table;
1956: if (ref($partlist) eq 'ARRAY') {
1957: if (scalar(@$partlist) > 1 ) {
1958: $table = &showResourceInfo($symb,$partlist,$responseType,'gradesub',1);
1959: } elsif ($divforres) {
1960: $table = '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1961: } else {
1962: $table = '<br clear="all" />';
1963: }
1964: }
1.49 albertel 1965:
1.796 raeburn 1966: $request->print(&checkselect_js());
1.597 wenzelju 1967: $request->print(&Apache::lonhtmlcommon::scripttag(<<LISTJAVASCRIPT));
1.110 ng 1968:
1969: function reLoadList(formname) {
1.112 ng 1970: if (formname.saveStatusOld.value == pullDownSelection(formname.Status)) {return;}
1.110 ng 1971: formname.command.value = 'submission';
1972: formname.submit();
1973: }
1.45 ng 1974: LISTJAVASCRIPT
1975:
1.118 ng 1976: &commonJSfunctions($request);
1.41 ng 1977: $request->print($result);
1.39 ng 1978:
1.154 albertel 1979: my $gradeTable='<form action="/adm/grades" method="post" name="gradesub">'.
1.773 raeburn 1980: "\n".$table;
1981:
1.561 bisitz 1982: $gradeTable .= &Apache::lonhtmlcommon::start_pick_box();
1.745 raeburn 1983: unless ($is_tool) {
1984: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Problem Text'))
1985: .'<label><input type="radio" name="vProb" value="no" checked="checked" /> '.&mt('no').' </label>'."\n"
1986: .'<label><input type="radio" name="vProb" value="yes" /> '.&mt('one student').' </label>'."\n"
1987: .'<label><input type="radio" name="vProb" value="all" /> '.&mt('all students').' </label><br />'."\n"
1988: .&Apache::lonhtmlcommon::row_closure();
1989: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Answer'))
1990: .'<label><input type="radio" name="vAns" value="no" /> '.&mt('no').' </label>'."\n"
1991: .'<label><input type="radio" name="vAns" value="yes" /> '.&mt('one student').' </label>'."\n"
1992: .'<label><input type="radio" name="vAns" value="all" checked="checked" /> '.&mt('all students').' </label><br />'."\n"
1993: .&Apache::lonhtmlcommon::row_closure();
1994: }
1.485 albertel 1995:
1.442 banghart 1996: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1997: my $saveStatus = $stu_status eq '' ? 'Active' : $stu_status;
1.257 albertel 1998: $env{'form.Status'} = $saveStatus;
1.745 raeburn 1999: my %optiontext;
2000: if ($is_tool) {
2001: %optiontext = &Apache::lonlocal::texthash (
2002: lastonly => 'last transaction',
2003: last => 'last transaction with details',
2004: datesub => 'all transactions',
2005: all => 'all transactions with details',
2006: );
2007: } else {
2008: %optiontext = &Apache::lonlocal::texthash (
2009: lastonly => 'last submission',
2010: last => 'last submission with details',
2011: datesub => 'all submissions',
2012: all => 'all submissions with details',
2013: );
2014: }
1.773 raeburn 2015: my $submission_options =
1.592 bisitz 2016: '<span class="LC_nobreak">'.
1.624 www 2017: '<label><input type="radio" name="lastSub" value="lastonly" /> '.
1.745 raeburn 2018: $optiontext{'lastonly'}.' </label></span>'."\n".
1.592 bisitz 2019: '<span class="LC_nobreak">'.
2020: '<label><input type="radio" name="lastSub" value="last" /> '.
1.745 raeburn 2021: $optiontext{'last'}.' </label></span>'."\n".
1.592 bisitz 2022: '<span class="LC_nobreak">'.
1.628 www 2023: '<label><input type="radio" name="lastSub" value="datesub" checked="checked" /> '.
1.745 raeburn 2024: $optiontext{'datesub'}.'</label></span>'."\n".
1.592 bisitz 2025: '<span class="LC_nobreak">'.
2026: '<label><input type="radio" name="lastSub" value="all" /> '.
1.745 raeburn 2027: $optiontext{'all'}.'</label></span>';
2028: my $viewtitle;
2029: if ($is_tool) {
2030: $viewtitle = &mt('View Transactions');
2031: } else {
2032: $viewtitle = &mt('View Submissions');
2033: }
1.773 raeburn 2034: my ($compmsg,$nocompmsg);
2035: $nocompmsg = ' checked="checked"';
2036: if ($numessay) {
2037: $compmsg = $nocompmsg;
2038: $nocompmsg = '';
2039: }
1.745 raeburn 2040: $gradeTable .= &Apache::lonhtmlcommon::row_title($viewtitle)
1.780 raeburn 2041: .$submission_options;
2042: # Check if any gradable
2043: my $showmore;
2044: if ($perm{'mgr'}) {
2045: my @sections;
2046: if ($env{'request.course.sec'} ne '') {
2047: @sections = ($env{'request.course.sec'});
1.783 raeburn 2048: } elsif ($env{'form.section'} eq '') {
2049: @sections = ('all');
1.780 raeburn 2050: } else {
2051: @sections = &Apache::loncommon::get_env_multiple('form.section');
2052: }
2053: if (grep(/^all$/,@sections)) {
2054: $showmore = 1;
2055: } else {
2056: foreach my $sec (@sections) {
2057: if (&canmodify($sec)) {
2058: $showmore = 1;
2059: last;
2060: }
2061: }
2062: }
2063: }
2064:
2065: if ($showmore) {
2066: $gradeTable .=
2067: &Apache::lonhtmlcommon::row_closure()
1.773 raeburn 2068: .&Apache::lonhtmlcommon::row_title(&mt('Send Messages'))
2069: .'<span class="LC_nobreak">'
2070: .'<label><input type="radio" name="compmsg" value="0"'.$nocompmsg.' />'
2071: .&mt('No').(' 'x2).'</label>'
2072: .'<label><input type="radio" name="compmsg" value="1"'.$compmsg.' />'
2073: .&mt('Yes').(' 'x2).'</label>'
1.561 bisitz 2074: .&Apache::lonhtmlcommon::row_closure();
2075:
1.780 raeburn 2076: $gradeTable .=
2077: &Apache::lonhtmlcommon::row_title(&mt('Grading Increments'))
1.561 bisitz 2078: .'<select name="increment">'
2079: .'<option value="1">'.&mt('Whole Points').'</option>'
2080: .'<option value=".5">'.&mt('Half Points').'</option>'
2081: .'<option value=".25">'.&mt('Quarter Points').'</option>'
2082: .'<option value=".1">'.&mt('Tenths of a Point').'</option>'
1.773 raeburn 2083: .'</select>';
1.780 raeburn 2084: }
1.485 albertel 2085: $gradeTable .=
1.432 banghart 2086: &build_section_inputs().
1.45 ng 2087: '<input type="hidden" name="submitonly" value="'.$submitonly.'" />'."\n".
1.418 albertel 2088: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.110 ng 2089: '<input type="hidden" name="saveStatusOld" value="'.$saveStatus.'" />'."\n";
1.618 www 2090: if (exists($env{'form.Status'})) {
1.784 raeburn 2091: $gradeTable .= '<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n";
1.124 ng 2092: } else {
1.773 raeburn 2093: $gradeTable .= &Apache::lonhtmlcommon::row_closure()
2094: .&Apache::lonhtmlcommon::row_title(&mt('Student Status'))
1.561 bisitz 2095: .&Apache::lonhtmlcommon::StatusOptions(
1.773 raeburn 2096: $saveStatus,undef,1,'javascript:reLoadList(this.form);');
1.124 ng 2097: }
1.773 raeburn 2098: if ($numessay) {
2099: $gradeTable .= &Apache::lonhtmlcommon::row_closure()
2100: .&Apache::lonhtmlcommon::row_title(&mt('Check For Plagiarism'))
2101: .'<input type="checkbox" name="checkPlag" checked="checked" />';
1.745 raeburn 2102: }
1.773 raeburn 2103: $gradeTable .= &Apache::lonhtmlcommon::row_closure(1)
2104: .&Apache::lonhtmlcommon::end_pick_box();
1.745 raeburn 2105: my $regrademsg;
2106: if ($is_tool) {
2107: $regrademsg =&mt("To view/grade/regrade, click on the check box(es) next to the student's name(s). Then click on the Next button.");
2108: } else {
2109: $regrademsg = &mt("To view/grade/regrade 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.");
2110: }
1.561 bisitz 2111: $gradeTable .= '<p>'
1.745 raeburn 2112: .$regrademsg."\n"
1.561 bisitz 2113: .'<input type="hidden" name="command" value="processGroup" />'
2114: .'</p>';
1.249 albertel 2115:
2116: # checkall buttons
2117: $gradeTable.=&check_script('gradesub', 'stuinfo');
1.110 ng 2118: $gradeTable.='<input type="button" '."\n".
1.589 bisitz 2119: 'onclick="javascript:checkSelect(this.form.stuinfo);" '."\n".
2120: 'value="'.&mt('Next').' →" /> <br />'."\n";
1.249 albertel 2121: $gradeTable.=&check_buttons();
1.450 banghart 2122: my ($classlist, undef, $fullname) = &getclasslist($getsec,'1',$getgroup);
1.474 albertel 2123: $gradeTable.= &Apache::loncommon::start_data_table().
2124: &Apache::loncommon::start_data_table_header_row();
1.110 ng 2125: my $loop = 0;
2126: while ($loop < 2) {
1.485 albertel 2127: $gradeTable.='<th>'.&mt('No.').'</th><th>'.&mt('Select').'</th>'.
2128: '<th>'.&nameUserString('header').' '.&mt('Section/Group').'</th>';
1.618 www 2129: if (($submitonly ne 'queued') && ($submitonly ne 'all')) {
1.485 albertel 2130: foreach my $part (sort(@$partlist)) {
2131: my $display_part=
2132: &get_display_part((split(/_/,$part))[0],$symb);
2133: $gradeTable.=
2134: '<th>'.&mt('Part: [_1] Status',$display_part).'</th>';
1.110 ng 2135: }
1.301 albertel 2136: } elsif ($submitonly eq 'queued') {
1.474 albertel 2137: $gradeTable.='<th>'.&mt('Queue Status').' </th>';
1.110 ng 2138: }
2139: $loop++;
1.126 ng 2140: # $gradeTable.='<td></td>' if ($loop%2 ==1);
1.41 ng 2141: }
1.474 albertel 2142: $gradeTable.=&Apache::loncommon::end_data_table_header_row()."\n";
1.41 ng 2143:
1.45 ng 2144: my $ctr = 0;
1.294 albertel 2145: foreach my $student (sort
2146: {
2147: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
2148: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
2149: }
2150: return $a cmp $b;
2151: }
2152: (keys(%$fullname))) {
1.41 ng 2153: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 2154:
1.110 ng 2155: my %status = ();
1.301 albertel 2156:
2157: if ($submitonly eq 'queued') {
2158: my %queue_status =
2159: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
2160: $udom,$uname);
2161: next if (!defined($queue_status{'gradingqueue'}));
2162: $status{'gradingqueue'} = $queue_status{'gradingqueue'};
2163: }
2164:
1.618 www 2165: if (($submitonly ne 'queued') && ($submitonly ne 'all')) {
1.324 albertel 2166: (%status) =&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 2167: my $submitted = 0;
1.164 albertel 2168: my $graded = 0;
1.248 albertel 2169: my $incorrect = 0;
1.110 ng 2170: foreach (keys(%status)) {
1.145 albertel 2171: $submitted = 1 if ($status{$_} ne 'nothing');
1.248 albertel 2172: $graded = 1 if ($status{$_} =~ /^ungraded/);
2173: $incorrect = 1 if ($status{$_} =~ /^incorrect/);
2174:
1.110 ng 2175: my ($foo,$partid,$foo1) = split(/\./,$_);
2176: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
1.145 albertel 2177: $submitted = 0;
1.150 albertel 2178: my ($part)=split(/\./,$partid);
1.110 ng 2179: $gradeTable.='<input type="hidden" name="'.
1.150 albertel 2180: $student.':'.$part.':submitted_by" value="'.
1.110 ng 2181: $status{'resource.'.$partid.'.submitted_by'}.'" />';
2182: }
1.41 ng 2183: }
1.248 albertel 2184:
1.156 albertel 2185: next if (!$submitted && ($submitonly eq 'yes' ||
2186: $submitonly eq 'incorrect' ||
2187: $submitonly eq 'graded'));
1.248 albertel 2188: next if (!$graded && ($submitonly eq 'graded'));
2189: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 2190: }
1.34 ng 2191:
1.45 ng 2192: $ctr++;
1.249 albertel 2193: my $section = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
1.452 banghart 2194: my $group = $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1.104 albertel 2195: if ( $perm{'vgr'} eq 'F' ) {
1.474 albertel 2196: if ($ctr%2 ==1) {
2197: $gradeTable.= &Apache::loncommon::start_data_table_row();
2198: }
1.126 ng 2199: $gradeTable.='<td align="right">'.$ctr.' </td>'.
1.563 bisitz 2200: '<td align="center"><label><input type="checkbox" name="stuinfo" value="'.
1.249 albertel 2201: $student.':'.$$fullname{$student}.':::SECTION'.$section.
2202: ') " /> </label></td>'."\n".'<td>'.
2203: &nameUserString(undef,$$fullname{$student},$uname,$udom).
1.474 albertel 2204: ' '.$section.($group ne '' ?'/'.$group:'').'</td>'."\n";
1.110 ng 2205:
1.618 www 2206: if ($submitonly ne 'all') {
1.524 raeburn 2207: foreach (sort(keys(%status))) {
1.485 albertel 2208: next if ($_ =~ /^resource.*?submitted_by$/);
2209: $gradeTable.='<td align="center"> '.&mt($status{$_}).' </td>'."\n";
1.110 ng 2210: }
1.41 ng 2211: }
1.126 ng 2212: # $gradeTable.='<td></td>' if ($ctr%2 ==1);
1.474 albertel 2213: if ($ctr%2 ==0) {
2214: $gradeTable.=&Apache::loncommon::end_data_table_row()."\n";
2215: }
1.41 ng 2216: }
2217: }
1.110 ng 2218: if ($ctr%2 ==1) {
1.126 ng 2219: $gradeTable.='<td> </td><td> </td><td> </td>';
1.618 www 2220: if (($submitonly ne 'queued') && ($submitonly ne 'all')) {
1.110 ng 2221: foreach (@$partlist) {
2222: $gradeTable.='<td> </td>';
2223: }
1.301 albertel 2224: } elsif ($submitonly eq 'queued') {
2225: $gradeTable.='<td> </td>';
1.110 ng 2226: }
1.474 albertel 2227: $gradeTable.=&Apache::loncommon::end_data_table_row();
1.110 ng 2228: }
2229:
1.474 albertel 2230: $gradeTable.=&Apache::loncommon::end_data_table()."\n".
1.589 bisitz 2231: '<input type="button" '.
2232: 'onclick="javascript:checkSelect(this.form.stuinfo);" '.
2233: 'value="'.&mt('Next').' →" /></form>'."\n";
1.45 ng 2234: if ($ctr == 0) {
1.96 albertel 2235: my $num_students=(scalar(keys(%$fullname)));
2236: if ($num_students eq 0) {
1.485 albertel 2237: $gradeTable='<br /> <span class="LC_warning">'.&mt('There are no students currently enrolled.').'</span>';
1.96 albertel 2238: } else {
1.171 albertel 2239: my $submissions='submissions';
2240: if ($submitonly eq 'incorrect') { $submissions = 'incorrect submissions'; }
2241: if ($submitonly eq 'graded' ) { $submissions = 'ungraded submissions'; }
1.301 albertel 2242: if ($submitonly eq 'queued' ) { $submissions = 'queued submissions'; }
1.398 albertel 2243: $gradeTable='<br /> <span class="LC_warning">'.
1.709 bisitz 2244: &mt('No '.$submissions.' found for this resource for any students. ([quant,_1,student] checked for '.$submissions.')',
1.485 albertel 2245: $num_students).
2246: '</span><br />';
1.96 albertel 2247: }
1.46 ng 2248: } elsif ($ctr == 1) {
1.474 albertel 2249: $gradeTable =~ s/type="checkbox"/type="checkbox" checked="checked"/;
1.45 ng 2250: }
2251: $request->print($gradeTable);
1.44 ng 2252: return '';
1.10 ng 2253: }
2254:
1.796 raeburn 2255: #---- Called from the listStudents and the names_for_passback routines.
2256:
2257: sub checkselect_js {
2258: my ($formname) = @_;
2259: if ($formname eq '') {
2260: $formname = 'gradesub';
2261: }
2262: my %js_lt;
2263: if ($formname eq 'passbackusers') {
2264: %js_lt = &Apache::lonlocal::texthash (
2265: 'multiple' => 'Please select a student or group of students before pushing the Save Scores button.',
2266: 'single' => 'Please select the student before pushing the Save Scores button.',
2267: );
2268: } else {
2269: %js_lt = &Apache::lonlocal::texthash (
2270: 'multiple' => 'Please select a student or group of students before clicking on the Next button.',
2271: 'single' => 'Please select the student before clicking on the Next button.',
2272: );
2273: }
2274: &js_escape(\%js_lt);
2275: return &Apache::lonhtmlcommon::scripttag(<<LISTJAVASCRIPT);
2276:
2277: function checkSelect(checkBox) {
2278: var ctr=0;
2279: var sense="";
2280: var len = checkBox.length;
2281: if (len == undefined) len = 1;
2282: if (len > 1) {
2283: for (var i=0; i<len; i++) {
2284: if (checkBox[i].checked) {
2285: ctr++;
2286: }
2287: }
2288: sense = '$js_lt{'multiple'}';
2289: } else {
2290: if (checkBox.checked) {
2291: ctr = 1;
2292: }
2293: sense = '$js_lt{'single'}';
2294: }
2295: if (ctr == 0) {
2296: alert(sense);
2297: return false;
2298: }
2299: document.$formname.submit();
2300: }
2301: LISTJAVASCRIPT
2302:
2303: }
1.249 albertel 2304:
2305: sub check_script {
1.766 raeburn 2306: my ($form,$type) = @_;
2307: my $chkallscript = &Apache::lonhtmlcommon::scripttag('
1.249 albertel 2308: function checkall() {
2309: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
2310: ele = document.forms.'.$form.'.elements[i];
2311: if (ele.name == "'.$type.'") {
2312: document.forms.'.$form.'.elements[i].checked=true;
2313: }
2314: }
2315: }
2316:
2317: function checksec() {
2318: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
2319: ele = document.forms.'.$form.'.elements[i];
2320: string = document.forms.'.$form.'.chksec.value;
2321: if
2322: (ele.value.indexOf(":::SECTION"+string)>0) {
2323: document.forms.'.$form.'.elements[i].checked=true;
2324: }
2325: }
2326: }
2327:
2328:
2329: function uncheckall() {
2330: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
2331: ele = document.forms.'.$form.'.elements[i];
2332: if (ele.name == "'.$type.'") {
2333: document.forms.'.$form.'.elements[i].checked=false;
2334: }
2335: }
2336: }
2337:
1.597 wenzelju 2338: '."\n");
1.249 albertel 2339: return $chkallscript;
2340: }
2341:
2342: sub check_buttons {
1.485 albertel 2343: my $buttons.='<input type="button" onclick="checkall()" value="'.&mt('Check All').'" />';
2344: $buttons.='<input type="button" onclick="uncheckall()" value="'.&mt('Uncheck All').'" /> ';
2345: $buttons.='<input type="button" onclick="checksec()" value="'.&mt('Check Section/Group').'" />';
1.249 albertel 2346: $buttons.='<input type="text" size="5" name="chksec" /> ';
2347: return $buttons;
2348: }
2349:
1.44 ng 2350: # Displays the submissions for one student or a group of students
1.34 ng 2351: sub processGroup {
1.766 raeburn 2352: my ($request,$symb) = @_;
1.41 ng 2353: my $ctr = 0;
1.155 albertel 2354: my @stuchecked = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.41 ng 2355: my $total = scalar(@stuchecked)-1;
1.45 ng 2356:
1.396 banghart 2357: foreach my $student (@stuchecked) {
2358: my ($uname,$udom,$fullname) = split(/:/,$student);
1.257 albertel 2359: $env{'form.student'} = $uname;
2360: $env{'form.userdom'} = $udom;
2361: $env{'form.fullname'} = $fullname;
1.619 www 2362: &submission($request,$ctr,$total,$symb);
1.41 ng 2363: $ctr++;
2364: }
2365: return '';
1.35 ng 2366: }
1.34 ng 2367:
1.44 ng 2368: #------------------------------------------------------------------------------------
2369: #
2370: #-------------------------- Next few routines handles grading by student, essentially
2371: # handles essay response type problem/part
2372: #
2373: #--- Javascript to handle the submission page functionality ---
2374: sub sub_page_js {
2375: my $request = shift;
1.736 damieng 2376: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
2377: &js_escape(\$alertmsg);
1.597 wenzelju 2378: $request->print(&Apache::lonhtmlcommon::scripttag(<<SUBJAVASCRIPT));
1.71 ng 2379: function updateRadio(formname,id,weight) {
1.125 ng 2380: var gradeBox = formname["GD_BOX"+id];
2381: var radioButton = formname["RADVAL"+id];
2382: var oldpts = formname["oldpts"+id].value;
1.72 ng 2383: var pts = checkSolved(formname,id) == 'update' ? gradeBox.value : oldpts;
1.71 ng 2384: gradeBox.value = pts;
2385: var resetbox = false;
2386: if (isNaN(pts) || pts < 0) {
1.539 riegler 2387: alert("$alertmsg"+pts);
1.71 ng 2388: for (var i=0; i<radioButton.length; i++) {
2389: if (radioButton[i].checked) {
2390: gradeBox.value = i;
2391: resetbox = true;
2392: }
2393: }
2394: if (!resetbox) {
2395: formtextbox.value = "";
2396: }
2397: return;
1.44 ng 2398: }
1.71 ng 2399:
2400: if (pts > weight) {
2401: var resp = confirm("You entered a value ("+pts+
2402: ") greater than the weight for the part. Accept?");
2403: if (resp == false) {
1.125 ng 2404: gradeBox.value = oldpts;
1.71 ng 2405: return;
2406: }
1.44 ng 2407: }
1.13 albertel 2408:
1.71 ng 2409: for (var i=0; i<radioButton.length; i++) {
2410: radioButton[i].checked=false;
2411: if (pts == i && pts != "") {
2412: radioButton[i].checked=true;
2413: }
2414: }
2415: updateSelect(formname,id);
1.125 ng 2416: formname["stores"+id].value = "0";
1.41 ng 2417: }
1.5 albertel 2418:
1.72 ng 2419: function writeBox(formname,id,pts) {
1.125 ng 2420: var gradeBox = formname["GD_BOX"+id];
1.71 ng 2421: if (checkSolved(formname,id) == 'update') {
2422: gradeBox.value = pts;
2423: } else {
1.125 ng 2424: var oldpts = formname["oldpts"+id].value;
1.72 ng 2425: gradeBox.value = oldpts;
1.125 ng 2426: var radioButton = formname["RADVAL"+id];
1.71 ng 2427: for (var i=0; i<radioButton.length; i++) {
2428: radioButton[i].checked=false;
1.72 ng 2429: if (i == oldpts) {
1.71 ng 2430: radioButton[i].checked=true;
2431: }
2432: }
1.41 ng 2433: }
1.125 ng 2434: formname["stores"+id].value = "0";
1.71 ng 2435: updateSelect(formname,id);
2436: return;
1.41 ng 2437: }
1.44 ng 2438:
1.71 ng 2439: function clearRadBox(formname,id) {
2440: if (checkSolved(formname,id) == 'noupdate') {
2441: updateSelect(formname,id);
2442: return;
2443: }
1.125 ng 2444: gradeSelect = formname["GD_SEL"+id];
1.71 ng 2445: for (var i=0; i<gradeSelect.length; i++) {
2446: if (gradeSelect[i].selected) {
2447: var selectx=i;
2448: }
2449: }
1.125 ng 2450: var stores = formname["stores"+id];
1.71 ng 2451: if (selectx == stores.value) { return };
1.125 ng 2452: var gradeBox = formname["GD_BOX"+id];
1.71 ng 2453: gradeBox.value = "";
1.125 ng 2454: var radioButton = formname["RADVAL"+id];
1.71 ng 2455: for (var i=0; i<radioButton.length; i++) {
2456: radioButton[i].checked=false;
2457: }
2458: stores.value = selectx;
2459: }
1.5 albertel 2460:
1.71 ng 2461: function checkSolved(formname,id) {
1.125 ng 2462: if (formname["solved"+id].value == "correct_by_student" && formname.overRideScore.value == 'no') {
1.118 ng 2463: var reply = confirm("This problem has been graded correct by the computer. Do you want to change the score?");
2464: if (!reply) {return "noupdate";}
1.120 ng 2465: formname.overRideScore.value = 'yes';
1.41 ng 2466: }
1.71 ng 2467: return "update";
1.13 albertel 2468: }
1.71 ng 2469:
2470: function updateSelect(formname,id) {
1.125 ng 2471: formname["GD_SEL"+id][0].selected = true;
1.71 ng 2472: return;
1.41 ng 2473: }
1.33 ng 2474:
1.121 ng 2475: //=========== Check that a point is assigned for all the parts ============
1.71 ng 2476: function checksubmit(formname,val,total,parttot) {
1.121 ng 2477: formname.gradeOpt.value = val;
1.71 ng 2478: if (val == "Save & Next") {
2479: for (i=0;i<=total;i++) {
2480: for (j=0;j<parttot;j++) {
1.125 ng 2481: var partid = formname["partid"+i+"_"+j].value;
1.127 ng 2482: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 2483: var points = formname["GD_BOX"+i+"_"+partid].value;
1.71 ng 2484: if (points == "") {
1.125 ng 2485: var name = formname["name"+i].value;
1.129 ng 2486: var studentID = (name != '' ? name : formname["unamedom"+i].value);
2487: var resp = confirm("You did not assign a score for "+studentID+
2488: ", part "+partid+". Continue?");
1.71 ng 2489: if (resp == false) {
1.125 ng 2490: formname["GD_BOX"+i+"_"+partid].focus();
1.71 ng 2491: return false;
2492: }
2493: }
2494: }
2495: }
2496: }
2497: }
1.120 ng 2498: formname.submit();
2499: }
2500:
1.71 ng 2501: //======= Check that a score is assigned for all the problems (page/sequence grading only) =========
2502: function checkSubmitPage(formname,total) {
2503: noscore = new Array(100);
2504: var ptr = 0;
2505: for (i=1;i<total;i++) {
1.125 ng 2506: var partid = formname["q_"+i].value;
1.127 ng 2507: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 2508: var points = formname["GD_BOX"+i+"_"+partid].value;
2509: var status = formname["solved"+i+"_"+partid].value;
1.71 ng 2510: if (points == "" && status != "correct_by_student") {
2511: noscore[ptr] = i;
2512: ptr++;
2513: }
2514: }
2515: }
2516: if (ptr != 0) {
2517: var sense = ptr == 1 ? ": " : "s: ";
2518: var prolist = "";
2519: if (ptr == 1) {
2520: prolist = noscore[0];
2521: } else {
2522: var i = 0;
2523: while (i < ptr-1) {
2524: prolist += noscore[i]+", ";
2525: i++;
2526: }
2527: prolist += "and "+noscore[i];
2528: }
2529: var resp = confirm("You did not assign any score for the following problem"+sense+prolist+". Continue?");
2530: if (resp == false) {
2531: return false;
2532: }
2533: }
1.45 ng 2534:
1.71 ng 2535: formname.submit();
2536: }
2537: SUBJAVASCRIPT
2538: }
1.45 ng 2539:
1.773 raeburn 2540: #--- javascript for grading message center
2541: sub sub_grademessage_js {
1.71 ng 2542: my $request = shift;
1.80 ng 2543: my $iconpath = $request->dir_config('lonIconsURL');
1.118 ng 2544: &commonJSfunctions($request);
1.350 albertel 2545:
1.629 www 2546: my $inner_js_msg_central= (<<INNERJS);
2547: <script type="text/javascript">
1.350 albertel 2548: function checkInput() {
2549: opener.document.SCORE.msgsub.value = opener.checkEntities(document.msgcenter.msgsub.value);
2550: var nmsg = opener.document.SCORE.savemsgN.value;
2551: var usrctr = document.msgcenter.usrctr.value;
2552: var newval = opener.document.SCORE["newmsg"+usrctr];
2553: newval.value = opener.checkEntities(document.msgcenter.newmsg.value);
2554:
2555: var msgchk = "";
2556: if (document.msgcenter.subchk.checked) {
2557: msgchk = "msgsub,";
2558: }
2559: var includemsg = 0;
2560: for (var i=1; i<=nmsg; i++) {
2561: var opnmsg = opener.document.SCORE["savemsg"+i];
2562: var frmmsg = document.msgcenter["msg"+i];
2563: opnmsg.value = opener.checkEntities(frmmsg.value);
2564: var showflg = opener.document.SCORE["shownOnce"+i];
2565: showflg.value = "1";
2566: var chkbox = document.msgcenter["msgn"+i];
2567: if (chkbox.checked) {
2568: msgchk += "savemsg"+i+",";
2569: includemsg = 1;
2570: }
2571: }
2572: if (document.msgcenter.newmsgchk.checked) {
2573: msgchk += "newmsg"+usrctr;
2574: includemsg = 1;
2575: }
2576: imgformname = opener.document.SCORE["mailicon"+usrctr];
2577: imgformname.src = "$iconpath/"+((includemsg) ? "mailto.gif" : "mailbkgrd.gif");
2578: var includemsg = opener.document.SCORE["includemsg"+usrctr];
2579: includemsg.value = msgchk;
2580:
2581: self.close()
2582:
2583: }
1.629 www 2584: </script>
1.350 albertel 2585: INNERJS
2586:
1.773 raeburn 2587: my $start_page_msg_central =
1.351 albertel 2588: &Apache::loncommon::start_page('Message Central',$inner_js_msg_central,
2589: {'js_ready' => 1,
2590: 'only_body' => 1,
2591: 'bgcolor' =>'#FFFFFF',});
1.773 raeburn 2592: my $end_page_msg_central =
1.350 albertel 2593: &Apache::loncommon::end_page({'js_ready' => 1});
2594:
1.219 www 2595: my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
1.236 albertel 2596: $docopen=~s/^document\.//;
1.773 raeburn 2597:
1.736 damieng 2598: my %html_js_lt = &Apache::lonlocal::texthash(
1.652 raeburn 2599: comp => 'Compose Message for: ',
2600: incl => 'Include',
1.656 raeburn 2601: type => 'Type',
1.652 raeburn 2602: subj => 'Subject',
2603: mesa => 'Message',
2604: new => 'New',
2605: save => 'Save',
2606: canc => 'Cancel',
2607: );
1.736 damieng 2608: &html_escape(\%html_js_lt);
2609: &js_escape(\%html_js_lt);
1.597 wenzelju 2610: $request->print(&Apache::lonhtmlcommon::scripttag(<<SUBJAVASCRIPT));
1.45 ng 2611:
1.44 ng 2612: //===================== Script to view submitted by ==================
2613: function viewSubmitter(submitter) {
2614: document.SCORE.refresh.value = "on";
2615: document.SCORE.NCT.value = "1";
2616: document.SCORE.unamedom0.value = submitter;
2617: document.SCORE.submit();
2618: return;
2619: }
2620:
2621: //====================== Script for composing message ==============
1.80 ng 2622: // preload images
2623: img1 = new Image();
2624: img1.src = "$iconpath/mailbkgrd.gif";
2625: img2 = new Image();
2626: img2.src = "$iconpath/mailto.gif";
2627:
1.44 ng 2628: function msgCenter(msgform,usrctr,fullname) {
2629: var Nmsg = msgform.savemsgN.value;
2630: savedMsgHeader(Nmsg,usrctr,fullname);
2631: var subject = msgform.msgsub.value;
1.127 ng 2632: var msgchk = document.SCORE["includemsg"+usrctr].value;
1.44 ng 2633: re = /msgsub/;
2634: var shwsel = "";
2635: if (re.test(msgchk)) { shwsel = "checked" }
1.123 ng 2636: subject = (document.SCORE.shownSub.value == 0 ? checkEntities(subject) : subject);
2637: displaySubject(checkEntities(subject),shwsel);
1.44 ng 2638: for (var i=1; i<=Nmsg; i++) {
1.123 ng 2639: var testmsg = "savemsg"+i+",";
2640: re = new RegExp(testmsg,"g");
1.44 ng 2641: shwsel = "";
2642: if (re.test(msgchk)) { shwsel = "checked" }
1.125 ng 2643: var message = document.SCORE["savemsg"+i].value;
1.126 ng 2644: message = (document.SCORE["shownOnce"+i].value == 0 ? checkEntities(message) : message);
1.123 ng 2645: displaySavedMsg(i,message,shwsel); //I do not get it. w/o checkEntities on saved messages,
2646: //any < is already converted to <, etc. However, only once!!
1.44 ng 2647: }
1.125 ng 2648: newmsg = document.SCORE["newmsg"+usrctr].value;
1.44 ng 2649: shwsel = "";
2650: re = /newmsg/;
2651: if (re.test(msgchk)) { shwsel = "checked" }
2652: newMsg(newmsg,shwsel);
2653: msgTail();
2654: return;
2655: }
2656:
1.123 ng 2657: function checkEntities(strx) {
2658: if (strx.length == 0) return strx;
2659: var orgStr = ["&", "<", ">", '"'];
2660: var newStr = ["&", "<", ">", """];
2661: var counter = 0;
2662: while (counter < 4) {
2663: strx = strReplace(strx,orgStr[counter],newStr[counter]);
2664: counter++;
2665: }
2666: return strx;
2667: }
2668:
2669: function strReplace(strx, orgStr, newStr) {
2670: return strx.split(orgStr).join(newStr);
2671: }
2672:
1.44 ng 2673: function savedMsgHeader(Nmsg,usrctr,fullname) {
1.76 ng 2674: var height = 70*Nmsg+250;
1.44 ng 2675: if (height > 600) {
2676: height = 600;
2677: }
1.118 ng 2678: var xpos = (screen.width-600)/2;
2679: xpos = (xpos < 0) ? '0' : xpos;
2680: var ypos = (screen.height-height)/2-30;
2681: ypos = (ypos < 0) ? '0' : ypos;
2682:
1.668 www 2683: pWin = window.open('', 'MessageCenter', 'resizable=yes,toolbar=no,location=no,scrollbars=yes,screenx='+xpos+',screeny='+ypos+',width=700,height='+height);
1.76 ng 2684: pWin.focus();
2685: pDoc = pWin.document;
1.219 www 2686: pDoc.$docopen;
1.351 albertel 2687: pDoc.write('$start_page_msg_central');
1.76 ng 2688:
2689: pDoc.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
2690: pDoc.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
1.736 damieng 2691: pDoc.write("<h1> $html_js_lt{'comp'}\"+fullname+\"<\\/h1>");
1.76 ng 2692:
1.676 golterma 2693: pDoc.write('<table style="border:1px solid black;"><tr>');
1.736 damieng 2694: pDoc.write("<td><b>$html_js_lt{'incl'}<\\/b><\\/td><td><b>$html_js_lt{'type'}<\\/b><\\/td><td><b>$html_js_lt{'mesa'}<\\/td><\\/tr>");
1.44 ng 2695: }
2696: function displaySubject(msg,shwsel) {
1.76 ng 2697: pDoc = pWin.document;
1.676 golterma 2698: pDoc.write("<tr>");
2699: pDoc.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1.736 damieng 2700: pDoc.write("<td>$html_js_lt{'subj'}<\\/td>");
1.676 golterma 2701: pDoc.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+"\\"size=\\"40\\" maxlength=\\"80\\"><\\/td><\\/tr>");
1.44 ng 2702: }
2703:
1.72 ng 2704: function displaySavedMsg(ctr,msg,shwsel) {
1.76 ng 2705: pDoc = pWin.document;
1.676 golterma 2706: pDoc.write("<tr>");
2707: pDoc.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1.465 albertel 2708: pDoc.write("<td align=\\"center\\">"+ctr+"<\\/td>");
2709: pDoc.write("<td><textarea name=\\"msg"+ctr+"\\" cols=\\"60\\" rows=\\"3\\">"+msg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 2710: }
2711:
2712: function newMsg(newmsg,shwsel) {
1.76 ng 2713: pDoc = pWin.document;
1.676 golterma 2714: pDoc.write("<tr>");
2715: pDoc.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1.736 damieng 2716: pDoc.write("<td align=\\"center\\">$html_js_lt{'new'}<\\/td>");
1.465 albertel 2717: pDoc.write("<td><textarea name=\\"newmsg\\" cols=\\"60\\" rows=\\"3\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" >"+newmsg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 2718: }
2719:
2720: function msgTail() {
1.76 ng 2721: pDoc = pWin.document;
1.676 golterma 2722: //pDoc.write("<\\/table>");
1.465 albertel 2723: pDoc.write("<\\/td><\\/tr><\\/table> ");
1.736 damieng 2724: pDoc.write("<input type=\\"button\\" value=\\"$html_js_lt{'save'}\\" onclick=\\"javascript:checkInput()\\"> ");
2725: pDoc.write("<input type=\\"button\\" value=\\"$html_js_lt{'canc'}\\" onclick=\\"self.close()\\"><br /><br />");
1.465 albertel 2726: pDoc.write("<\\/form>");
1.351 albertel 2727: pDoc.write('$end_page_msg_central');
1.128 ng 2728: pDoc.close();
1.44 ng 2729: }
2730:
1.773 raeburn 2731: SUBJAVASCRIPT
2732: }
2733:
2734: #--- javascript for essay type problem --
2735: sub sub_page_kw_js {
2736: my $request = shift;
2737:
2738: unless ($env{'form.compmsg'}) {
2739: &commonJSfunctions($request);
2740: }
2741:
2742: my $inner_js_highlight_central= (<<INNERJS);
2743: <script type="text/javascript">
2744: function updateChoice(flag) {
2745: opener.document.SCORE.kwclr.value = opener.radioSelection(document.hlCenter.kwdclr);
2746: opener.document.SCORE.kwsize.value = opener.radioSelection(document.hlCenter.kwdsize);
2747: opener.document.SCORE.kwstyle.value = opener.radioSelection(document.hlCenter.kwdstyle);
2748: opener.document.SCORE.refresh.value = "on";
2749: if (opener.document.SCORE.keywords.value!=""){
2750: opener.document.SCORE.submit();
2751: }
2752: self.close()
2753: }
2754: </script>
2755: INNERJS
2756:
2757: my $start_page_highlight_central =
2758: &Apache::loncommon::start_page('Highlight Central',
2759: $inner_js_highlight_central,
2760: {'js_ready' => 1,
2761: 'only_body' => 1,
2762: 'bgcolor' =>'#FFFFFF',});
2763: my $end_page_highlight_central =
2764: &Apache::loncommon::end_page({'js_ready' => 1});
2765:
2766: my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
2767: $docopen=~s/^document\.//;
2768:
2769: my %js_lt = &Apache::lonlocal::texthash(
2770: keyw => 'Keywords list, separated by a space. Add/delete to list if desired.',
2771: plse => 'Please select a word or group of words from document and then click this link.',
2772: adds => 'Add selection to keyword list? Edit if desired.',
2773: col1 => 'red',
2774: col2 => 'green',
2775: col3 => 'blue',
2776: siz1 => 'normal',
2777: siz2 => '+1',
2778: siz3 => '+2',
2779: sty1 => 'normal',
2780: sty2 => 'italic',
2781: sty3 => 'bold',
2782: );
2783: my %html_js_lt = &Apache::lonlocal::texthash(
2784: save => 'Save',
2785: canc => 'Cancel',
2786: kehi => 'Keyword Highlight Options',
2787: txtc => 'Text Color',
2788: font => 'Font Size',
2789: fnst => 'Font Style',
2790: );
2791: &js_escape(\%js_lt);
2792: &html_escape(\%html_js_lt);
2793: &js_escape(\%html_js_lt);
2794: $request->print(&Apache::lonhtmlcommon::scripttag(<<SUBJAVASCRIPT));
2795:
2796: //===================== Show list of keywords ====================
2797: function keywords(formname) {
2798: var nret = prompt("$js_lt{'keyw'}",formname.keywords.value);
2799: if (nret==null) return;
2800: formname.keywords.value = nret;
2801:
2802: if (formname.keywords.value != "") {
2803: formname.refresh.value = "on";
2804: formname.submit();
2805: }
2806: return;
2807: }
2808:
2809: //===================== Script to add keyword(s) ==================
2810: function getSel() {
2811: if (document.getSelection) txt = document.getSelection();
2812: else if (document.selection) txt = document.selection.createRange().text;
2813: else return;
2814: if (typeof(txt) != 'string') {
2815: txt = String(txt);
2816: }
2817: var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
2818: if (cleantxt=="") {
2819: alert("$js_lt{'plse'}");
2820: return;
2821: }
2822: var nret = prompt("$js_lt{'adds'}",cleantxt);
2823: if (nret==null) return;
2824: document.SCORE.keywords.value = document.SCORE.keywords.value+" "+nret;
2825: if (document.SCORE.keywords.value != "") {
2826: document.SCORE.refresh.value = "on";
2827: document.SCORE.submit();
2828: }
2829: return;
2830: }
2831:
1.44 ng 2832: //====================== Script for keyword highlight options ==============
2833: function kwhighlight() {
2834: var kwclr = document.SCORE.kwclr.value;
2835: var kwsize = document.SCORE.kwsize.value;
2836: var kwstyle = document.SCORE.kwstyle.value;
2837: var redsel = "";
2838: var grnsel = "";
2839: var blusel = "";
1.736 damieng 2840: var txtcol1 = "$js_lt{'col1'}";
2841: var txtcol2 = "$js_lt{'col2'}";
2842: var txtcol3 = "$js_lt{'col3'}";
2843: var txtsiz1 = "$js_lt{'siz1'}";
2844: var txtsiz2 = "$js_lt{'siz2'}";
2845: var txtsiz3 = "$js_lt{'siz3'}";
2846: var txtsty1 = "$js_lt{'sty1'}";
2847: var txtsty2 = "$js_lt{'sty2'}";
2848: var txtsty3 = "$js_lt{'sty3'}";
1.718 bisitz 2849: if (kwclr=="red") {var redsel="checked='checked'"};
2850: if (kwclr=="green") {var grnsel="checked='checked'"};
2851: if (kwclr=="blue") {var blusel="checked='checked'"};
1.44 ng 2852: var sznsel = "";
2853: var sz1sel = "";
2854: var sz2sel = "";
1.718 bisitz 2855: if (kwsize=="0") {var sznsel="checked='checked'"};
2856: if (kwsize=="+1") {var sz1sel="checked='checked'"};
2857: if (kwsize=="+2") {var sz2sel="checked='checked'"};
1.44 ng 2858: var synsel = "";
2859: var syisel = "";
2860: var sybsel = "";
1.718 bisitz 2861: if (kwstyle=="") {var synsel="checked='checked'"};
2862: if (kwstyle=="<i>") {var syisel="checked='checked'"};
2863: if (kwstyle=="<b>") {var sybsel="checked='checked'"};
1.44 ng 2864: highlightCentral();
1.718 bisitz 2865: highlightbody('red',txtcol1,redsel,'0',txtsiz1,sznsel,'',txtsty1,synsel);
2866: highlightbody('green',txtcol2,grnsel,'+1',txtsiz2,sz1sel,'<i>',txtsty2,syisel);
2867: highlightbody('blue',txtcol3,blusel,'+2',txtsiz3,sz2sel,'<b>',txtsty3,sybsel);
1.44 ng 2868: highlightend();
2869: return;
2870: }
2871:
2872: function highlightCentral() {
1.76 ng 2873: // if (window.hwdWin) window.hwdWin.close();
1.118 ng 2874: var xpos = (screen.width-400)/2;
2875: xpos = (xpos < 0) ? '0' : xpos;
2876: var ypos = (screen.height-330)/2-30;
2877: ypos = (ypos < 0) ? '0' : ypos;
2878:
1.206 albertel 2879: hwdWin = window.open('', 'KeywordHighlightCentral', 'resizeable=yes,toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx='+xpos+',screeny='+ypos);
1.76 ng 2880: hwdWin.focus();
2881: var hDoc = hwdWin.document;
1.219 www 2882: hDoc.$docopen;
1.351 albertel 2883: hDoc.write('$start_page_highlight_central');
1.76 ng 2884: hDoc.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
1.736 damieng 2885: hDoc.write("<h1>$html_js_lt{'kehi'}<\\/h1>");
1.76 ng 2886:
1.718 bisitz 2887: hDoc.write('<table border="0" width="100%"><tr style="background-color:#A1D676">');
1.736 damieng 2888: hDoc.write("<th>$html_js_lt{'txtc'}<\\/th><th>$html_js_lt{'font'}<\\/th><th>$html_js_lt{'fnst'}<\\/th><\\/tr>");
1.44 ng 2889: }
2890:
2891: function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) {
1.76 ng 2892: var hDoc = hwdWin.document;
1.718 bisitz 2893: hDoc.write("<tr>");
1.76 ng 2894: hDoc.write("<td align=\\"left\\">");
1.718 bisitz 2895: hDoc.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+" \\/> "+clrtxt+"<\\/td>");
1.76 ng 2896: hDoc.write("<td align=\\"left\\">");
1.718 bisitz 2897: hDoc.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+" \\/> "+sztxt+"<\\/td>");
1.76 ng 2898: hDoc.write("<td align=\\"left\\">");
1.718 bisitz 2899: hDoc.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+" \\/> "+sytxt+"<\\/td>");
1.465 albertel 2900: hDoc.write("<\\/tr>");
1.44 ng 2901: }
2902:
2903: function highlightend() {
1.76 ng 2904: var hDoc = hwdWin.document;
1.718 bisitz 2905: hDoc.write("<\\/table><br \\/>");
1.736 damieng 2906: hDoc.write("<input type=\\"button\\" value=\\"$html_js_lt{'save'}\\" onclick=\\"javascript:updateChoice(1)\\" \\/> ");
2907: hDoc.write("<input type=\\"button\\" value=\\"$html_js_lt{'canc'}\\" onclick=\\"self.close()\\" \\/><br /><br />");
1.465 albertel 2908: hDoc.write("<\\/form>");
1.351 albertel 2909: hDoc.write('$end_page_highlight_central');
1.128 ng 2910: hDoc.close();
1.44 ng 2911: }
2912:
2913: SUBJAVASCRIPT
2914: }
2915:
1.349 albertel 2916: sub get_increment {
1.348 bowersj2 2917: my $increment = $env{'form.increment'};
2918: if ($increment != 1 && $increment != .5 && $increment != .25 &&
2919: $increment != .1) {
2920: $increment = 1;
2921: }
2922: return $increment;
2923: }
2924:
1.585 bisitz 2925: sub gradeBox_start {
2926: return (
2927: &Apache::loncommon::start_data_table()
2928: .&Apache::loncommon::start_data_table_header_row()
2929: .'<th>'.&mt('Part').'</th>'
2930: .'<th>'.&mt('Points').'</th>'
2931: .'<th> </th>'
2932: .'<th>'.&mt('Assign Grade').'</th>'
2933: .'<th>'.&mt('Weight').'</th>'
2934: .'<th>'.&mt('Grade Status').'</th>'
2935: .&Apache::loncommon::end_data_table_header_row()
2936: );
2937: }
2938:
2939: sub gradeBox_end {
2940: return (
2941: &Apache::loncommon::end_data_table()
2942: );
2943: }
1.71 ng 2944: #--- displays the grading box, used in essay type problem and grading by page/sequence
2945: sub gradeBox {
1.322 albertel 2946: my ($request,$symb,$uname,$udom,$counter,$partid,$record) = @_;
1.381 albertel 2947: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 2948: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 2949: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
1.466 albertel 2950: my $wgtmsg = ($wgt > 0) ? &mt('(problem weight)')
2951: : '<span class="LC_info">'.&mt('problem weight assigned by computer').'</span>';
1.71 ng 2952: $wgt = ($wgt > 0 ? $wgt : '1');
2953: my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
1.320 albertel 2954: '' : &compute_points($$record{'resource.'.$partid.'.awarded'},$wgt));
1.695 bisitz 2955: my $data_WGT='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />'."\n";
1.466 albertel 2956: my $display_part= &get_display_part($partid,$symb);
1.270 albertel 2957: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
2958: [$partid]);
2959: my $aggtries = $$record{'resource.'.$partid.'.tries'};
1.269 raeburn 2960: if ($last_resets{$partid}) {
2961: $aggtries = &get_num_tries($record,$last_resets{$partid},$partid);
2962: }
1.695 bisitz 2963: my $result=&Apache::loncommon::start_data_table_row();
1.71 ng 2964: my $ctr = 0;
1.348 bowersj2 2965: my $thisweight = 0;
1.349 albertel 2966: my $increment = &get_increment();
1.485 albertel 2967:
2968: my $radio.='<table border="0"><tr>'."\n"; # display radio buttons in a nice table 10 across
1.348 bowersj2 2969: while ($thisweight<=$wgt) {
1.532 bisitz 2970: $radio.= '<td><span class="LC_nobreak"><label><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
1.589 bisitz 2971: 'onclick="javascript:writeBox(this.form,\''.$counter.'_'.$partid.'\','.
1.348 bowersj2 2972: $thisweight.')" value="'.$thisweight.'" '.
1.401 albertel 2973: ($score eq $thisweight ? 'checked="checked"':'').' /> '.$thisweight."</label></span></td>\n";
1.485 albertel 2974: $radio.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1.348 bowersj2 2975: $thisweight += $increment;
1.71 ng 2976: $ctr++;
2977: }
1.485 albertel 2978: $radio.='</tr></table>';
2979:
2980: my $line.='<input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
1.71 ng 2981: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
1.589 bisitz 2982: 'onchange="javascript:updateRadio(this.form,\''.$counter.'_'.$partid.'\','.
1.71 ng 2983: $wgt.')" /></td>'."\n";
1.485 albertel 2984: $line.='<td>/'.$wgt.' '.$wgtmsg.
1.71 ng 2985: ($$record{'resource.'.$partid.'.solved'} eq 'correct_by_student' ? ' '.$checkIcon : '').
1.585 bisitz 2986: ' </td>'."\n";
2987: $line.='<td><select name="GD_SEL'.$counter.'_'.$partid.'" '.
1.589 bisitz 2988: 'onchange="javascript:clearRadBox(this.form,\''.$counter.'_'.$partid.'\')" >'."\n";
1.71 ng 2989: if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
1.485 albertel 2990: $line.='<option></option>'.
2991: '<option value="excused" selected="selected">'.&mt('excused').'</option>';
1.71 ng 2992: } else {
1.485 albertel 2993: $line.='<option selected="selected"></option>'.
2994: '<option value="excused" >'.&mt('excused').'</option>';
1.71 ng 2995: }
1.485 albertel 2996: $line.='<option value="reset status">'.&mt('reset status').'</option></select>'."\n";
2997:
2998:
2999: $result .=
1.695 bisitz 3000: '<td>'.$data_WGT.$display_part.'</td><td>'.$radio.'</td><td>'.&mt('or').'</td><td>'.$line.'</td>';
1.585 bisitz 3001: $result.=&Apache::loncommon::end_data_table_row();
1.695 bisitz 3002: $result.=&Apache::loncommon::start_data_table_row().'<td colspan="6">';
1.71 ng 3003: $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="" />'."\n".
3004: '<input type="hidden" name="oldpts'.$counter.'_'.$partid.'" value="'.$score.'" />'."\n".
3005: '<input type="hidden" name="solved'.$counter.'_'.$partid.'" value="'.
1.269 raeburn 3006: $$record{'resource.'.$partid.'.solved'}.'" />'."\n".
3007: '<input type="hidden" name="totaltries'.$counter.'_'.$partid.'" value="'.
3008: $$record{'resource.'.$partid.'.tries'}.'" />'."\n".
3009: '<input type="hidden" name="aggtries'.$counter.'_'.$partid.'" value="'.
3010: $aggtries.'" />'."\n";
1.582 raeburn 3011: my $res_error;
3012: $result.=&handback_box($symb,$uname,$udom,$counter,$partid,$record,\$res_error);
1.695 bisitz 3013: $result.='</td>'.&Apache::loncommon::end_data_table_row();
1.582 raeburn 3014: if ($res_error) {
3015: return &navmap_errormsg();
3016: }
1.318 banghart 3017: return $result;
3018: }
1.322 albertel 3019:
3020: sub handback_box {
1.623 www 3021: my ($symb,$uname,$udom,$counter,$partid,$record,$res_error_pointer) = @_;
1.773 raeburn 3022: my ($partlist,$handgrade,$responseType,$numresp,$numessay) = &response_type($symb,$res_error_pointer);
3023: return unless ($numessay);
1.323 banghart 3024: my (@respids);
1.652 raeburn 3025: my @part_response_id = &flatten_responseType($responseType);
1.375 albertel 3026: foreach my $part_response_id (@part_response_id) {
3027: my ($part,$resp) = @{ $part_response_id };
1.323 banghart 3028: if ($part eq $partid) {
1.375 albertel 3029: push(@respids,$resp);
1.323 banghart 3030: }
3031: }
1.318 banghart 3032: my $result;
1.323 banghart 3033: foreach my $respid (@respids) {
1.322 albertel 3034: my $prefix = $counter.'_'.$partid.'_'.$respid.'_';
3035: my $files=&get_submitted_files($udom,$uname,$partid,$respid,$record);
3036: next if (!@$files);
1.654 raeburn 3037: my $file_counter = 0;
1.313 banghart 3038: foreach my $file (@$files) {
1.368 banghart 3039: if ($file =~ /\/portfolio\//) {
1.654 raeburn 3040: $file_counter++;
1.368 banghart 3041: my ($file_path, $file_disp) = ($file =~ m|(.+/)(.+)$|);
1.729 raeburn 3042: my ($name,$version,$ext) = &Apache::lonnet::file_name_version_ext($file_disp);
1.368 banghart 3043: $file_disp = "$name.$ext";
3044: $file = $file_path.$file_disp;
3045: $result.=&mt('Return commented version of [_1] to student.',
3046: '<span class="LC_filename">'.$file_disp.'</span>');
3047: $result.='<input type="file" name="'.$prefix.'returndoc'.$file_counter.'" />'."\n";
1.654 raeburn 3048: $result.='<input type="hidden" name="'.$prefix.'origdoc'.$file_counter.'" value="'.$file.'" /><br />'."\n";
1.368 banghart 3049: }
1.322 albertel 3050: }
1.654 raeburn 3051: if ($file_counter) {
3052: $result .= '<input type="hidden" name="'.$prefix.'countreturndoc" value="'.$file_counter.'" />'."\n".
3053: '<span class="LC_info">'.
3054: '('.&mt('File(s) will be uploaded when you click on Save & Next below.',$file_counter).')</span><br /><br />';
3055: }
1.313 banghart 3056: }
1.318 banghart 3057: return $result;
1.71 ng 3058: }
1.44 ng 3059:
1.58 albertel 3060: sub show_problem {
1.382 albertel 3061: my ($request,$symb,$uname,$udom,$removeform,$viewon,$mode,$form) = @_;
1.144 albertel 3062: my $rendered;
1.382 albertel 3063: my %form = ((ref($form) eq 'HASH')? %{$form} : ());
1.329 albertel 3064: &Apache::lonxml::remember_problem_counter();
1.144 albertel 3065: if ($mode eq 'both' or $mode eq 'text') {
3066: $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
1.382 albertel 3067: $env{'request.course.id'},
3068: undef,\%form);
1.144 albertel 3069: }
1.58 albertel 3070: if ($removeform) {
3071: $rendered=~s|<form(.*?)>||g;
3072: $rendered=~s|</form>||g;
1.374 albertel 3073: $rendered=~s|(<input[^>]*name\s*=\s*"?)(\w+)("?)|$1would_have_been_$2$3|g;
1.58 albertel 3074: }
1.144 albertel 3075: my $companswer;
3076: if ($mode eq 'both' or $mode eq 'answer') {
1.329 albertel 3077: &Apache::lonxml::restore_problem_counter();
1.382 albertel 3078: $companswer=
3079: &Apache::loncommon::get_student_answers($symb,$uname,$udom,
3080: $env{'request.course.id'},
3081: %form);
1.144 albertel 3082: }
1.58 albertel 3083: if ($removeform) {
3084: $companswer=~s|<form(.*?)>||g;
3085: $companswer=~s|</form>||g;
1.144 albertel 3086: $companswer=~s|name="submit"|name="would_have_been_submit"|g;
1.58 albertel 3087: }
1.671 raeburn 3088: my $renderheading = &mt('View of the problem');
3089: my $answerheading = &mt('Correct answer');
3090: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3091: my $stu_fullname = $env{'form.fullname'};
3092: if ($stu_fullname eq '') {
3093: $stu_fullname = &Apache::loncommon::plainname($uname,$udom,'lastname');
3094: }
3095: my $forwhom = &nameUserString(undef,$stu_fullname,$uname,$udom);
3096: if ($forwhom ne '') {
3097: $renderheading = &mt('View of the problem for[_1]',$forwhom);
3098: $answerheading = &mt('Correct answer for[_1]',$forwhom);
3099: }
3100: }
1.468 albertel 3101: $rendered=
1.588 bisitz 3102: '<div class="LC_Box">'
1.671 raeburn 3103: .'<h3 class="LC_hcell">'.$renderheading.'</h3>'
1.588 bisitz 3104: .$rendered
3105: .'</div>';
1.468 albertel 3106: $companswer=
1.588 bisitz 3107: '<div class="LC_Box">'
1.671 raeburn 3108: .'<h3 class="LC_hcell">'.$answerheading.'</h3>'
1.588 bisitz 3109: .$companswer
3110: .'</div>';
1.468 albertel 3111: my $result;
1.144 albertel 3112: if ($mode eq 'both') {
1.588 bisitz 3113: $result=$rendered.$companswer;
1.144 albertel 3114: } elsif ($mode eq 'text') {
1.588 bisitz 3115: $result=$rendered;
1.144 albertel 3116: } elsif ($mode eq 'answer') {
1.588 bisitz 3117: $result=$companswer;
1.144 albertel 3118: }
1.71 ng 3119: return $result;
1.58 albertel 3120: }
1.397 albertel 3121:
1.396 banghart 3122: sub files_exist {
3123: my ($r, $symb) = @_;
3124: my @students = &Apache::loncommon::get_env_multiple('form.stuinfo');
3125: foreach my $student (@students) {
3126: my ($uname,$udom,$fullname) = split(/:/,$student);
1.397 albertel 3127: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
3128: $udom,$uname);
1.792 raeburn 3129: my ($string)= &get_last_submission(\%record);
1.397 albertel 3130: foreach my $submission (@$string) {
3131: my ($partid,$respid) =
3132: ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
3133: my $files=&get_submitted_files($udom,$uname,$partid,$respid,
3134: \%record);
3135: return 1 if (@$files);
1.396 banghart 3136: }
3137: }
1.397 albertel 3138: return 0;
1.396 banghart 3139: }
1.397 albertel 3140:
1.394 banghart 3141: sub download_all_link {
3142: my ($r,$symb) = @_;
1.621 www 3143: unless (&files_exist($r, $symb)) {
1.766 raeburn 3144: $r->print(&mt('There are currently no submitted documents.'));
3145: return;
1.621 www 3146: }
1.395 albertel 3147: my $all_students =
3148: join("\n", &Apache::loncommon::get_env_multiple('form.stuinfo'));
3149:
3150: my $parts =
3151: join("\n",&Apache::loncommon::get_env_multiple('form.vPart'));
3152:
1.394 banghart 3153: my $identifier = &Apache::loncommon::get_cgi_id();
1.514 raeburn 3154: &Apache::lonnet::appenv({'cgi.'.$identifier.'.students' => $all_students,
3155: 'cgi.'.$identifier.'.symb' => $symb,
3156: 'cgi.'.$identifier.'.parts' => $parts,});
1.395 albertel 3157: $r->print('<a href="/cgi-bin/multidownload.pl?'.$identifier.'">'.
3158: &mt('Download All Submitted Documents').'</a>');
1.621 www 3159: return;
3160: }
3161:
3162: sub submit_download_link {
3163: my ($request,$symb) = @_;
3164: if (!$symb) { return ''; }
1.750 raeburn 3165: my $res_error;
1.773 raeburn 3166: my ($partlist,$handgrade,$responseType,$numresp,$numessay,$numdropbox) =
3167: &response_type($symb,\$res_error);
3168: if ($res_error) {
3169: $request->print(&mt('An error occurred retrieving response types'));
3170: return;
3171: }
3172: unless ($numessay) {
3173: $request->print(&mt('No essayresponse items found'));
3174: return;
1.750 raeburn 3175: }
1.773 raeburn 3176: my @chosenparts = &Apache::loncommon::get_env_multiple('form.vPart');
3177: if (@chosenparts) {
3178: $request->print(&showResourceInfo($symb,$partlist,$responseType,
3179: undef,undef,1));
1.750 raeburn 3180: }
1.773 raeburn 3181: if ($numessay) {
1.750 raeburn 3182: my $submitonly= $env{'form.submitonly'} eq '' ? 'all' : $env{'form.submitonly'};
3183: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
3184: my $getgroup = $env{'form.group'} eq '' ? 'all' : $env{'form.group'};
3185: (undef,undef,my $fullname) = &getclasslist($getsec,1,$getgroup,$symb,$submitonly,1);
3186: if (ref($fullname) eq 'HASH') {
3187: my @students = map { $_.':'.$fullname->{$_} } (keys(%{$fullname}));
3188: if (@students) {
3189: @{$env{'form.stuinfo'}} = @students;
1.773 raeburn 3190: if ($numdropbox) {
1.750 raeburn 3191: &download_all_link($request,$symb);
1.773 raeburn 3192: } else {
3193: $request->print(&mt('No essayrespose items with dropbox found'));
1.750 raeburn 3194: }
1.773 raeburn 3195: # FIXME Need a mechanism to download essays, i.e., if $numessay > $numdropbox
1.750 raeburn 3196: # Needs to omit user's identity if resource instance is for an anonymous survey.
3197: } else {
3198: $request->print(&mt('No students match the criteria you selected'));
3199: }
3200: } else {
3201: $request->print(&mt('Could not retrieve student information'));
3202: }
3203: } else {
3204: $request->print(&mt('No essayresponse items found'));
3205: }
3206: return;
1.394 banghart 3207: }
1.395 albertel 3208:
1.432 banghart 3209: sub build_section_inputs {
3210: my $section_inputs;
3211: if ($env{'form.section'} eq '') {
3212: $section_inputs .= '<input type="hidden" name="section" value="all" />'."\n";
3213: } else {
3214: my @sections = &Apache::loncommon::get_env_multiple('form.section');
1.434 albertel 3215: foreach my $section (@sections) {
1.432 banghart 3216: $section_inputs .= '<input type="hidden" name="section" value="'.$section.'" />'."\n";
3217: }
3218: }
3219: return $section_inputs;
3220: }
3221:
1.44 ng 3222: # --------------------------- show submissions of a student, option to grade
3223: sub submission {
1.773 raeburn 3224: my ($request,$counter,$total,$symb,$divforres,$calledby) = @_;
1.257 albertel 3225: my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
3226: $udom = ($udom eq '' ? $env{'user.domain'} : $udom); #has form.userdom changed for a student?
3227: my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
3228: $env{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $env{'form.fullname'} eq '';
1.608 www 3229:
1.324 albertel 3230: if ($symb eq '') { $request->print("Unable to handle ambiguous references:."); return ''; }
1.773 raeburn 3231: my $probtitle=&Apache::lonnet::gettitle($symb);
1.746 raeburn 3232: my $is_tool = ($symb =~ /ext\.tool$/);
1.753 raeburn 3233: my ($essayurl,%coursedesc_by_cid);
1.104 albertel 3234:
3235: if (!&canview($usec)) {
1.712 bisitz 3236: $request->print(
3237: '<span class="LC_warning">'.
1.713 bisitz 3238: &mt('Unable to view requested student.').
1.712 bisitz 3239: ' '.&mt('([_1] in section [_2] in course id [_3])',
3240: $uname.':'.$udom,$usec,$env{'request.course.id'}).
3241: '</span>');
1.104 albertel 3242: return;
3243: }
3244:
1.773 raeburn 3245: my $res_error;
3246: my ($partlist,$handgrade,$responseType,$numresp,$numessay) =
3247: &response_type($symb,\$res_error);
3248: if ($res_error) {
3249: $request->print(&navmap_errormsg());
3250: return;
3251: }
3252:
1.257 albertel 3253: if (!$env{'form.lastSub'}) { $env{'form.lastSub'} = 'datesub'; }
1.745 raeburn 3254: unless ($is_tool) {
3255: if (!$env{'form.vProb'}) { $env{'form.vProb'} = 'yes'; }
3256: if (!$env{'form.vAns'}) { $env{'form.vAns'} = 'yes'; }
3257: }
1.773 raeburn 3258: if (($numessay) && ($calledby eq 'submission') && (!exists($env{'form.compmsg'}))) {
3259: $env{'form.compmsg'} = 1;
3260: }
1.257 albertel 3261: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.381 albertel 3262: my $checkIcon = '<img alt="'.&mt('Check Mark').
3263: '" src="'.$request->dir_config('lonIconsURL').
1.122 ng 3264: '/check.gif" height="16" border="0" />';
1.41 ng 3265:
3266: # header info
3267: if ($counter == 0) {
1.773 raeburn 3268: my @chosenparts = &Apache::loncommon::get_env_multiple('form.vPart');
3269: if (@chosenparts) {
3270: $request->print(&showResourceInfo($symb,$partlist,$responseType,'gradesub'));
3271: } elsif ($divforres) {
3272: $request->print('<div style="padding:0;clear:both;margin:0;border:0"></div>');
3273: } else {
3274: $request->print('<br clear="all" />');
3275: }
1.41 ng 3276: &sub_page_js($request);
1.773 raeburn 3277: &sub_grademessage_js($request) if ($env{'form.compmsg'});
3278: &sub_page_kw_js($request) if ($numessay);
1.118 ng 3279:
1.44 ng 3280: # option to display problem, only once else it cause problems
3281: # with the form later since the problem has a form.
1.257 albertel 3282: if ($env{'form.vProb'} eq 'yes' or $env{'form.vAns'} eq 'yes') {
1.144 albertel 3283: my $mode;
1.257 albertel 3284: if ($env{'form.vProb'} eq 'yes' && $env{'form.vAns'} eq 'yes') {
1.144 albertel 3285: $mode='both';
1.257 albertel 3286: } elsif ($env{'form.vProb'} eq 'yes') {
1.144 albertel 3287: $mode='text';
1.257 albertel 3288: } elsif ($env{'form.vAns'} eq 'yes') {
1.144 albertel 3289: $mode='answer';
3290: }
1.329 albertel 3291: &Apache::lonxml::clear_problem_counter();
1.144 albertel 3292: $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
1.41 ng 3293: }
1.441 www 3294:
1.41 ng 3295: my %keyhash = ();
1.773 raeburn 3296: if (($env{'form.kwclr'} eq '' && $numessay) || ($env{'form.compmsg'})) {
1.41 ng 3297: %keyhash = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 3298: $env{'course.'.$env{'request.course.id'}.'.domain'},
3299: $env{'course.'.$env{'request.course.id'}.'.num'});
1.773 raeburn 3300: }
3301: # kwclr is the only variable that is guaranteed not to be blank
3302: # if this subroutine has been called once.
3303: if ($env{'form.kwclr'} eq '' && $numessay) {
1.257 albertel 3304: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
3305: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
3306: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
3307: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
3308: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
1.773 raeburn 3309: }
3310: if ($env{'form.compmsg'}) {
3311: $env{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
1.605 www 3312: $keyhash{$symb.'_subject'} : $probtitle;
1.257 albertel 3313: $env{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1.41 ng 3314: }
1.773 raeburn 3315:
1.257 albertel 3316: my $overRideScore = $env{'form.overRideScore'} eq '' ? 'no' : $env{'form.overRideScore'};
1.442 banghart 3317: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.303 banghart 3318: $request->print('<form action="/adm/grades" method="post" name="SCORE" enctype="multipart/form-data">'."\n".
1.41 ng 3319: '<input type="hidden" name="command" value="handgrade" />'."\n".
1.442 banghart 3320: '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.120 ng 3321: '<input type="hidden" name="overRideScore" value="'.$overRideScore.'" />'."\n".
1.41 ng 3322: '<input type="hidden" name="refresh" value="off" />'."\n".
1.120 ng 3323: '<input type="hidden" name="studentNo" value="" />'."\n".
3324: '<input type="hidden" name="gradeOpt" value="" />'."\n".
1.418 albertel 3325: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 3326: '<input type="hidden" name="vProb" value="'.$env{'form.vProb'}.'" />'."\n".
3327: '<input type="hidden" name="vAns" value="'.$env{'form.vAns'}.'" />'."\n".
3328: '<input type="hidden" name="lastSub" value="'.$env{'form.lastSub'}.'" />'."\n".
1.773 raeburn 3329: '<input type="hidden" name="compmsg" value="'.$env{'form.compmsg'}.'" />'."\n".
1.432 banghart 3330: &build_section_inputs().
1.326 albertel 3331: '<input type="hidden" name="submitonly" value="'.$env{'form.submitonly'}.'" />'."\n".
1.41 ng 3332: '<input type="hidden" name="NCT"'.
1.257 albertel 3333: ' value="'.($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : $total+1).'" />'."\n");
1.773 raeburn 3334: if ($env{'form.compmsg'}) {
3335: $request->print('<input type="hidden" name="msgsub" value="'.$env{'form.msgsub'}.'" />'."\n".
3336: '<input type="hidden" name="shownSub" value="0" />'."\n".
3337: '<input type="hidden" name="savemsgN" value="'.$env{'form.savemsgN'}.'" />'."\n");
3338: }
3339: if ($numessay) {
1.257 albertel 3340: $request->print('<input type="hidden" name="keywords" value="'.$env{'form.keywords'}.'" />'."\n".
3341: '<input type="hidden" name="kwclr" value="'.$env{'form.kwclr'}.'" />'."\n".
3342: '<input type="hidden" name="kwsize" value="'.$env{'form.kwsize'}.'" />'."\n".
1.773 raeburn 3343: '<input type="hidden" name="kwstyle" value="'.$env{'form.kwstyle'}.'" />'."\n");
1.123 ng 3344: }
1.773 raeburn 3345:
1.41 ng 3346: my ($cts,$prnmsg) = (1,'');
1.257 albertel 3347: while ($cts <= $env{'form.savemsgN'}) {
1.41 ng 3348: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
1.123 ng 3349: (!exists($keyhash{$symb.'_savemsg'.$cts}) ?
1.257 albertel 3350: &Apache::lonfeedback::clear_out_html($env{'form.savemsg'.$cts}) :
1.80 ng 3351: &Apache::lonfeedback::clear_out_html($keyhash{$symb.'_savemsg'.$cts})).
1.123 ng 3352: '" />'."\n".
3353: '<input type="hidden" name="shownOnce'.$cts.'" value="0" />'."\n";
1.41 ng 3354: $cts++;
3355: }
3356: $request->print($prnmsg);
1.32 ng 3357:
1.773 raeburn 3358: if ($numessay) {
1.652 raeburn 3359:
3360: my %lt = &Apache::lonlocal::texthash(
1.719 bisitz 3361: keyh => 'Keyword Highlighting for Essays',
1.652 raeburn 3362: keyw => 'Keyword Options',
1.655 raeburn 3363: list => 'List',
1.652 raeburn 3364: past => 'Paste Selection to List',
1.661 www 3365: high => 'Highlight Attribute',
1.773 raeburn 3366: );
1.88 www 3367: #
3368: # Print out the keyword options line
3369: #
1.718 bisitz 3370: $request->print(
3371: '<div class="LC_columnSection">'
3372: .'<fieldset><legend>'.$lt{'keyh'}.'</legend>'
3373: .&Apache::lonhtmlcommon::funclist_from_array(
3374: ['<a href="javascript:keywords(document.SCORE);" target="_self">'.$lt{'list'}.'</a>',
3375: '<a href="#" onmousedown="javascript:getSel(); return false"
3376: class="page">'.$lt{'past'}.'</a>',
3377: '<a href="javascript:kwhighlight();" target="_self">'.$lt{'high'}.'</a>'],
3378: {legend => $lt{'keyw'}})
3379: .'</fieldset></div>'
3380: );
3381:
1.88 www 3382: #
3383: # Load the other essays for similarity check
3384: #
1.753 raeburn 3385: (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb);
3386: if ($essayurl eq 'lib/templates/simpleproblem.problem') {
3387: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3388: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3389: if ($cdom ne '' && $cnum ne '') {
3390: my ($map,$id,$res) = &Apache::lonnet::decode_symb($symb);
3391: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(default(?:|_\d+)\.(?:sequence|page))$}) {
3392: my $apath = $1.'_'.$id;
3393: $apath=~s/\W/\_/gs;
3394: &init_old_essays($symb,$apath,$cdom,$cnum);
3395: }
3396: }
3397: } else {
3398: my ($adom,$aname,$apath)=($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
3399: $apath=&escape($apath);
3400: $apath=~s/\W/\_/gs;
3401: &init_old_essays($symb,$apath,$adom,$aname);
3402: }
1.41 ng 3403: }
3404: }
1.44 ng 3405:
1.441 www 3406: # This is where output for one specific student would start
1.592 bisitz 3407: my $add_class = ($counter%2) ? ' LC_grade_show_user_odd_row' : '';
3408: $request->print(
3409: "\n\n"
3410: .'<div class="LC_grade_show_user'.$add_class.'">'
3411: .'<h2>'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).'</h2>'
3412: ."\n"
3413: );
1.441 www 3414:
1.592 bisitz 3415: # Show additional functions if allowed
3416: if ($perm{'vgr'}) {
3417: $request->print(
3418: &Apache::loncommon::track_student_link(
1.708 bisitz 3419: 'View recent activity',
1.592 bisitz 3420: $uname,$udom,'check')
3421: .' '
3422: );
3423: }
3424: if ($perm{'opa'}) {
3425: $request->print(
3426: &Apache::loncommon::pprmlink(
3427: &mt('Set/Change parameters'),
3428: $uname,$udom,$symb,'check'));
3429: }
3430:
3431: # Show Problem
1.257 albertel 3432: if ($env{'form.vProb'} eq 'all' or $env{'form.vAns'} eq 'all') {
1.144 albertel 3433: my $mode;
1.257 albertel 3434: if ($env{'form.vProb'} eq 'all' && $env{'form.vAns'} eq 'all') {
1.144 albertel 3435: $mode='both';
1.257 albertel 3436: } elsif ($env{'form.vProb'} eq 'all' ) {
1.144 albertel 3437: $mode='text';
1.257 albertel 3438: } elsif ($env{'form.vAns'} eq 'all') {
1.144 albertel 3439: $mode='answer';
3440: }
1.329 albertel 3441: &Apache::lonxml::clear_problem_counter();
1.475 albertel 3442: $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode,{'request.prefix' => 'ctr'.$counter}));
1.58 albertel 3443: }
1.144 albertel 3444:
1.257 albertel 3445: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.41 ng 3446:
1.44 ng 3447: # Display student info
1.41 ng 3448: $request->print(($counter == 0 ? '' : '<br />'));
1.590 bisitz 3449:
1.745 raeburn 3450: my $boxtitle = &mt('Submissions');
3451: if ($is_tool) {
3452: $boxtitle = &mt('Transactions')
3453: }
1.590 bisitz 3454: my $result='<div class="LC_Box">'
1.745 raeburn 3455: .'<h3 class="LC_hcell">'.$boxtitle.'</h3>';
1.45 ng 3456: $result.='<input type="hidden" name="name'.$counter.
1.588 bisitz 3457: '" value="'.$env{'form.fullname'}.'" />'."\n";
1.773 raeburn 3458: if (($numresp > $numessay) && !$is_tool) {
1.588 bisitz 3459: $result.='<p class="LC_info">'
3460: .&mt('Part(s) graded correct by the computer is marked with a [_1] symbol.',$checkIcon)
3461: ."</p>\n";
1.469 albertel 3462: }
3463:
1.773 raeburn 3464: # If any part of the problem is an essayresponse, then check for collaborators
1.464 albertel 3465: my $fullname;
3466: my $col_fullnames = [];
1.773 raeburn 3467: if ($numessay) {
1.464 albertel 3468: (my $sub_result,$fullname,$col_fullnames)=
3469: &check_collaborators($symb,$uname,$udom,\%record,$handgrade,
3470: $counter);
3471: $result.=$sub_result;
1.41 ng 3472: }
1.44 ng 3473: $request->print($result."\n");
1.773 raeburn 3474:
1.44 ng 3475: # print student answer/submission
1.773 raeburn 3476: # Options are (1) Last submission only
3477: # (2) Last submission (with detailed information for that submission)
3478: # (3) All transactions (by date)
3479: # (4) The whole record (with detailed information for all transactions)
3480:
1.793 raeburn 3481: my ($lastsubonly,$partinfo) =
3482: &show_last_submission($uname,$udom,$symb,$essayurl,$responseType,$env{'form.lastSub'},
3483: $is_tool,$fullname,\%record,\%coursedesc_by_cid);
3484: $request->print($partinfo);
3485: $request->print($lastsubonly);
3486:
3487: if ($env{'form.lastSub'} eq 'datesub') {
3488: my ($parts,$handgrade,$responseType) = &response_type($symb,\$res_error);
3489: $request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
3490: }
3491: if ($env{'form.lastSub'} =~ /^(last|all)$/) {
3492: my $identifier = (&canmodify($usec)? $counter : '');
3493: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
3494: $env{'request.course.id'},
3495: $last,'.submission',
3496: 'Apache::grades::keywords_highlight',
3497: $usec,$identifier));
3498: }
3499: $request->print('<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
3500: .$udom.'" />'."\n");
3501: # return if view submission with no grading option
3502: if (!&canmodify($usec)) {
3503: $request->print('<p><span class="LC_warning">'.&mt('No grading privileges').'</span></p></div>');
3504: return;
3505: } else {
3506: $request->print('</div>'."\n");
3507: }
3508:
3509: # grading message center
3510:
3511: if ($env{'form.compmsg'}) {
3512: my $result='<div class="LC_Box">'.
3513: '<h3 class="LC_hcell">'.&mt('Send Message').'</h3>'.
3514: '<div class="LC_grade_message_center_body">';
3515: my ($lastname,$givenn) = split(/,/,$env{'form.fullname'});
3516: my $msgfor = $givenn.' '.$lastname;
3517: if (scalar(@$col_fullnames) > 0) {
3518: my $lastone = pop(@$col_fullnames);
3519: $msgfor .= ', '.(join ', ',@$col_fullnames).' and '.$lastone.'.';
3520: }
3521: $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
3522: $result.='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
3523: '<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n".
3524: ' <a href="javascript:msgCenter(document.SCORE,'.$counter.
3525: ',\''.$msgfor.'\');" target="_self">'.
3526: &mt('Compose message to student'.(scalar(@$col_fullnames) >= 1 ? 's' : '')).'</a><label> ('.
3527: &mt('incl. grades').' <input type="checkbox" name="withgrades'.$counter.'" /></label>)'.
3528: ' <img src="'.$request->dir_config('lonIconsURL').
3529: '/mailbkgrd.gif" width="14" height="10" alt="" name="mailicon'.$counter.'" />'."\n".
3530: '<br /> ('.
3531: &mt('Message will be sent when you click on Save & Next below.').")\n".
3532: '</div></div>';
3533: $request->print($result);
3534: }
3535:
3536: my %seen = ();
3537: my @partlist;
3538: my @gradePartRespid;
3539: my @part_response_id;
3540: if ($is_tool) {
3541: @part_response_id = ([0,'']);
3542: } else {
3543: @part_response_id = &flatten_responseType($responseType);
3544: }
3545: $request->print(
3546: '<div class="LC_Box">'
3547: .'<h3 class="LC_hcell">'.&mt('Assign Grades').'</h3>'
3548: );
3549: $request->print(&gradeBox_start());
3550: foreach my $part_response_id (@part_response_id) {
3551: my ($partid,$respid) = @{ $part_response_id };
3552: my $part_resp = join('_',@{ $part_response_id });
3553: next if ($seen{$partid} > 0);
3554: $seen{$partid}++;
3555: push(@partlist,$partid);
3556: push(@gradePartRespid,$partid.'.'.$respid);
3557: $request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
3558: }
3559: $request->print(&gradeBox_end()); # </div>
3560: $request->print('</div>');
3561:
3562: $request->print('<div class="LC_grade_info_links">');
3563: $request->print('</div>');
3564:
3565: $result='<input type="hidden" name="partlist'.$counter.
3566: '" value="'.(join ":",@partlist).'" />'."\n";
3567: $result.='<input type="hidden" name="gradePartRespid'.
3568: '" value="'.(join ":",@gradePartRespid).'" />'."\n" if ($counter == 0);
3569: my $ctr = 0;
3570: while ($ctr < scalar(@partlist)) {
3571: $result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
3572: $partlist[$ctr].'" />'."\n";
3573: $ctr++;
3574: }
3575: $request->print($result.''."\n");
3576:
3577: # Done with printing info for one student
3578:
3579: $request->print('</div>');#LC_grade_show_user
3580:
3581:
3582: # print end of form
3583: if ($counter == $total) {
3584: my $endform='<br /><hr /><table border="0"><tr><td>'."\n";
3585: $endform.='<input type="button" value="'.&mt('Save & Next').'" '.
3586: 'onclick="javascript:checksubmit(this.form,\'Save & Next\','.
3587: $total.','.scalar(@partlist).');" target="_self" /> '."\n";
3588: my $ntstu ='<select name="NTSTU">'.
3589: '<option>1</option><option>2</option>'.
3590: '<option>3</option><option>5</option>'.
3591: '<option>7</option><option>10</option></select>'."\n";
3592: my $nsel = ($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : '1');
3593: $ntstu =~ s/<option>$nsel</<option selected="selected">$nsel</;
3594: $endform.=&mt('[_1]student(s)',$ntstu);
3595: $endform.=' <input type="button" value="'.&mt('Previous').'" '.
3596: 'onclick="javascript:checksubmit(this.form,\'Previous\');" target="_self" /> '."\n".
3597: '<input type="button" value="'.&mt('Next').'" '.
3598: 'onclick="javascript:checksubmit(this.form,\'Next\');" target="_self" /> ';
3599: $endform.='<span class="LC_warning">'.
3600: &mt('(Next and Previous (student) do not save the scores.)').
3601: '</span>'."\n" ;
3602: $endform.="<input type='hidden' value='".&get_increment().
3603: "' name='increment' />";
3604: $endform.='</td></tr></table></form>';
3605: $request->print($endform);
3606: }
3607: return '';
3608: }
3609:
3610: sub show_last_submission {
3611: my ($uname,$udom,$symb,$essayurl,$responseType,$viewtype,$is_tool,$fullname,
3612: $record,$coursedesc_by_cid) = @_;
1.792 raeburn 3613: my ($string,$timestamp,$lastgradetime,$lastsubmittime) =
1.793 raeburn 3614: &get_last_submission($record,$is_tool);
1.468 albertel 3615:
1.793 raeburn 3616: my ($lastsubonly,$partinfo);
1.792 raeburn 3617: if ($timestamp eq '') {
1.793 raeburn 3618: $lastsubonly.='<div class="LC_grade_submissions_body">'.$string->[0].'</div>';
1.745 raeburn 3619: } elsif ($is_tool) {
3620: $lastsubonly =
3621: '<div class="LC_grade_submissions_body">'
1.792 raeburn 3622: .'<b>'.&mt('Date Grade Passed Back:').'</b> '.$timestamp."</div>\n";
1.702 kruse 3623: } else {
1.792 raeburn 3624: my ($shownsubmdate,$showngradedate);
3625: if ($lastsubmittime && $lastgradetime) {
3626: $shownsubmdate = &Apache::lonlocal::locallocaltime($lastsubmittime);
3627: if ($lastgradetime > $lastsubmittime) {
3628: $showngradedate = &Apache::lonlocal::locallocaltime($lastgradetime);
3629: }
3630: } else {
3631: $shownsubmdate = $timestamp;
3632: }
1.702 kruse 3633: $lastsubonly =
3634: '<div class="LC_grade_submissions_body">'
1.792 raeburn 3635: .'<b>'.&mt('Date Submitted:').'</b> '.$shownsubmdate."\n";
3636: if ($showngradedate) {
3637: $lastsubonly .= '<br /><b>'.&mt('Date Graded:').'</b> '.$showngradedate."\n";
3638: }
1.702 kruse 3639:
1.793 raeburn 3640: my %seenparts;
3641: my @part_response_id = &flatten_responseType($responseType);
3642: foreach my $part (@part_response_id) {
3643: my ($partid,$respid) = @{ $part };
3644: my $display_part=&get_display_part($partid,$symb);
3645: if ($env{"form.$uname:$udom:$partid:submitted_by"}) {
3646: if (exists($seenparts{$partid})) { next; }
3647: $seenparts{$partid}=1;
3648: $partinfo .=
1.702 kruse 3649: '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
3650: ' <b>'.&mt('Collaborative submission by: [_1]',
3651: '<a href="javascript:viewSubmitter(\''.
3652: $env{"form.$uname:$udom:$partid:submitted_by"}.
3653: '\');" target="_self">'.
3654: $$fullname{$env{"form.$uname:$udom:$partid:submitted_by"}}.'</a>').
1.793 raeburn 3655: '<br />';
3656: next;
3657: }
3658: my $responsetype = $responseType->{$partid}->{$respid};
3659: if (!exists($record->{"resource.$partid.$respid.submission"})) {
1.702 kruse 3660: $lastsubonly.="\n".'<div class="LC_grade_submission_part">'.
3661: '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
3662: ' <span class="LC_internal_info">'.
3663: '('.&mt('Response ID: [_1]',$respid).')'.
3664: '</span> '.
1.793 raeburn 3665: '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br /><br /></div>';
3666: next;
3667: }
3668: foreach my $submission (@$string) {
3669: my ($partid,$respid) = ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
3670: if (join('_',@{$part}) ne ($partid.'_'.$respid)) { next; }
3671: my ($ressub,$hide,$draft,$subval) = split(/:/,$submission,4);
3672: # Similarity check
1.702 kruse 3673: my $similar='';
3674: my ($type,$trial,$rndseed);
3675: if ($hide eq 'rand') {
3676: $type = 'randomizetry';
1.793 raeburn 3677: $trial = $record->{"resource.$partid.tries"};
3678: $rndseed = $record->{"resource.$partid.rndseed"};
1.702 kruse 3679: }
1.793 raeburn 3680: if ($env{'form.checkPlag'}) {
3681: my ($oname,$odom,$ocrsid,$oessay,$osim)=
3682: &most_similar($uname,$udom,$symb,$subval);
3683: if ($osim) {
3684: $osim=int($osim*100.0);
1.702 kruse 3685: if ($hide eq 'anon') {
3686: $similar='<hr /><span class="LC_warning">'.&mt("Essay was found to be similar to another essay submitted for this assignment.").'<br />'.
3687: &mt('As the current submission is for an anonymous survey, no other details are available.').'</span><hr />';
3688: } else {
1.793 raeburn 3689: $similar='<hr />';
1.753 raeburn 3690: if ($essayurl eq 'lib/templates/simpleproblem.problem') {
3691: $similar .= '<h3><span class="LC_warning">'.
3692: &mt('Essay is [_1]% similar to an essay by [_2]',
3693: $osim,
3694: &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')').
3695: '</span></h3>';
3696: } else {
3697: my %old_course_desc;
3698: if ($ocrsid ne '') {
1.793 raeburn 3699: if (ref($coursedesc_by_cid->{$ocrsid}) eq 'HASH') {
3700: %old_course_desc = %{$coursedesc_by_cid->{$ocrsid}};
1.753 raeburn 3701: } else {
3702: my $args;
3703: if ($ocrsid ne $env{'request.course.id'}) {
3704: $args = {'one_time' => 1};
3705: }
3706: %old_course_desc =
3707: &Apache::lonnet::coursedescription($ocrsid,$args);
1.793 raeburn 3708: $coursedesc_by_cid->{$ocrsid} = \%old_course_desc;
1.753 raeburn 3709: }
3710: $similar .=
3711: '<h3><span class="LC_warning">'.
3712: &mt('Essay is [_1]% similar to an essay by [_2] in course [_3] (course id [_4]:[_5])',
3713: $osim,
3714: &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')',
3715: $old_course_desc{'description'},
3716: $old_course_desc{'num'},
3717: $old_course_desc{'domain'}).
3718: '</span></h3>';
3719: } else {
3720: $similar .=
3721: '<h3><span class="LC_warning">'.
3722: &mt('Essay is [_1]% similar to an essay by [_2] in an unknown course',
3723: $osim,
3724: &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')').
3725: '</span></h3>';
3726: }
3727: }
3728: $similar .= '<blockquote><i>'.
3729: &keywords_highlight($oessay).
3730: '</i></blockquote><hr />';
1.702 kruse 3731: }
1.793 raeburn 3732: }
3733: }
3734: my $order=&get_order($partid,$respid,$symb,$uname,$udom,
1.702 kruse 3735: undef,$type,$trial,$rndseed);
1.793 raeburn 3736: if (($viewtype eq 'lastonly') ||
3737: ($viewtype eq 'datesub') ||
3738: ($viewtype =~ /^(last|all)$/)) {
3739: my $display_part=&get_display_part($partid,$symb);
1.702 kruse 3740: $lastsubonly.='<div class="LC_grade_submission_part">'.
3741: '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
3742: ' <span class="LC_internal_info">'.
3743: '('.&mt('Response ID: [_1]',$respid).')'.
3744: '</span> ';
1.793 raeburn 3745: my $files=&get_submitted_files($udom,$uname,$partid,$respid,$record);
3746: if (@$files) {
1.702 kruse 3747: if ($hide eq 'anon') {
3748: $lastsubonly.='<br />'.&mt('[quant,_1,file] uploaded to this anonymous survey',scalar(@{$files}));
3749: } else {
3750: $lastsubonly.='<br /><br />'.'<b>'.&mt('Submitted Files:').'</b>'
3751: .'<br /><span class="LC_warning">';
3752: if(@$files == 1) {
3753: $lastsubonly .= &mt('Like all files provided by users, this file may contain viruses!');
1.596 raeburn 3754: } else {
1.702 kruse 3755: $lastsubonly .= &mt('Like all files provided by users, these files may contain viruses!');
3756: }
1.774 raeburn 3757: $lastsubonly .= '</span>';
1.702 kruse 3758: foreach my $file (@$files) {
3759: &Apache::lonnet::allowuploaded('/adm/grades',$file);
3760: $lastsubonly.='<br /><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.&Apache::loncommon::icon($file).'" border="0" alt="" /> '.$file.'</a>';
1.596 raeburn 3761: }
3762: }
1.793 raeburn 3763: $lastsubonly.='<br />';
1.702 kruse 3764: }
3765: if ($hide eq 'anon') {
1.793 raeburn 3766: $lastsubonly.='<br /><b>'.&mt('Anonymous Survey').'</b>';
1.702 kruse 3767: } else {
1.774 raeburn 3768: $lastsubonly.='<br /><b>'.&mt('Submitted Answer:').' </b>';
1.724 raeburn 3769: if ($draft) {
3770: $lastsubonly.= ' <span class="LC_warning">'.&mt('Draft Copy').'</span>';
3771: }
3772: $subval =
1.793 raeburn 3773: &cleanRecord($subval,$responsetype,$symb,$partid,
3774: $respid,$record,$order,undef,$uname,$udom,$type,$trial,$rndseed);
1.724 raeburn 3775: if ($responsetype eq 'essay') {
3776: $subval =~ s{\n}{<br />}g;
3777: }
3778: $lastsubonly.=$subval."\n";
1.702 kruse 3779: }
1.774 raeburn 3780: if ($similar) {$lastsubonly.="<br /><br />$similar\n";}
1.793 raeburn 3781: $lastsubonly.='</div>';
3782: }
1.702 kruse 3783: }
1.773 raeburn 3784: }
1.793 raeburn 3785: $lastsubonly.='</div>'."\n"; # End: LC_grade_submissions_body
1.118 ng 3786: }
1.793 raeburn 3787: return ($lastsubonly,$partinfo);
1.38 ng 3788: }
3789:
1.464 albertel 3790: sub check_collaborators {
3791: my ($symb,$uname,$udom,$record,$handgrade,$counter) = @_;
3792: my ($result,@col_fullnames);
3793: my ($classlist,undef,$fullname) = &getclasslist('all','0');
3794: foreach my $part (keys(%$handgrade)) {
3795: my $ncol = &Apache::lonnet::EXT('resource.'.$part.
3796: '.maxcollaborators',
3797: $symb,$udom,$uname);
3798: next if ($ncol <= 0);
3799: $part =~ s/\_/\./g;
3800: next if ($record->{'resource.'.$part.'.collaborators'} eq '');
3801: my (@good_collaborators, @bad_collaborators);
3802: foreach my $possible_collaborator
1.630 www 3803: (split(/[,;\s]+/,$record->{'resource.'.$part.'.collaborators'})) {
1.464 albertel 3804: $possible_collaborator =~ s/[\$\^\(\)]//g;
3805: next if ($possible_collaborator eq '');
1.631 www 3806: my ($co_name,$co_dom) = split(/:/,$possible_collaborator);
1.464 albertel 3807: $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
3808: next if ($co_name eq $uname && $co_dom eq $udom);
3809: # Doing this grep allows 'fuzzy' specification
3810: my @matches = grep(/^\Q$co_name\E:\Q$co_dom\E$/i,
3811: keys(%$classlist));
3812: if (! scalar(@matches)) {
3813: push(@bad_collaborators, $possible_collaborator);
3814: } else {
3815: push(@good_collaborators, @matches);
3816: }
3817: }
3818: if (scalar(@good_collaborators) != 0) {
1.630 www 3819: $result.='<br />'.&mt('Collaborators:').'<ol>';
1.464 albertel 3820: foreach my $name (@good_collaborators) {
3821: my ($lastname,$givenn) = split(/,/,$$fullname{$name});
3822: push(@col_fullnames, $givenn.' '.$lastname);
1.630 www 3823: $result.='<li>'.$fullname->{$name}.'</li>';
1.464 albertel 3824: }
1.630 www 3825: $result.='</ol><br />'."\n";
1.466 albertel 3826: my ($part)=split(/\./,$part);
1.464 albertel 3827: $result.='<input type="hidden" name="collaborator'.$counter.
3828: '" value="'.$part.':'.(join ':',@good_collaborators).'" />'.
3829: "\n";
3830: }
3831: if (scalar(@bad_collaborators) > 0) {
1.466 albertel 3832: $result.='<div class="LC_warning">';
1.464 albertel 3833: $result.=&mt('This student has submitted [quant,_1,invalid collaborator]: [_2]',scalar(@bad_collaborators),join(', ',@bad_collaborators));
3834: $result .= '</div>';
3835: }
3836: if (scalar(@bad_collaborators > $ncol)) {
1.466 albertel 3837: $result .= '<div class="LC_warning">';
1.464 albertel 3838: $result .= &mt('This student has submitted too many '.
3839: 'collaborators. Maximum is [_1].',$ncol);
3840: $result .= '</div>';
3841: }
3842: }
3843: return ($result,$fullname,\@col_fullnames);
3844: }
3845:
1.44 ng 3846: #--- Retrieve the last submission for all the parts
1.38 ng 3847: sub get_last_submission {
1.745 raeburn 3848: my ($returnhash,$is_tool)=@_;
1.792 raeburn 3849: my (@string,$timestamp,$lastgradetime,$lastsubmittime);
1.119 ng 3850: if ($$returnhash{'version'}) {
1.46 ng 3851: my %lasthash=();
1.792 raeburn 3852: my %prevsolved=();
3853: my %solved=();
3854: my $version;
1.119 ng 3855: for ($version=1;$version<=$$returnhash{'version'};$version++) {
1.792 raeburn 3856: my %handgraded = ();
1.397 albertel 3857: foreach my $key (sort(split(/\:/,
3858: $$returnhash{$version.':keys'}))) {
3859: $lasthash{$key}=$$returnhash{$version.':'.$key};
1.792 raeburn 3860: if ($key =~ /\.([^.]+)\.regrader$/) {
3861: $handgraded{$1} = 1;
3862: } elsif ($key =~ /\.portfiles$/) {
3863: if (($$returnhash{$version.':'.$key} ne '') &&
3864: ($$returnhash{$version.':'.$key} !~ /\.\d+\.\w+$/)) {
3865: $lastsubmittime = $$returnhash{$version.':timestamp'};
3866: }
3867: } elsif ($key =~ /\.submission$/) {
3868: if ($$returnhash{$version.':'.$key} ne '') {
3869: $lastsubmittime = $$returnhash{$version.':timestamp'};
3870: }
3871: } elsif ($key =~ /\.([^.]+)\.solved$/) {
3872: $prevsolved{$1} = $solved{$1};
3873: $solved{$1} = $lasthash{$key};
3874: }
3875: }
3876: foreach my $partid (keys(%handgraded)) {
3877: if (($prevsolved{$partid} eq 'ungraded_attempted') &&
3878: (($solved{$partid} eq 'incorrect_by_override') ||
3879: ($solved{$partid} eq 'correct_by_override'))) {
3880: $lastgradetime = $$returnhash{$version.':timestamp'};
3881: }
3882: if ($solved{$partid} ne '') {
3883: $prevsolved{$partid} = $solved{$partid};
3884: }
1.46 ng 3885: }
3886: }
1.795 raeburn 3887: #
3888: # Timestamp is for last transaction for this resource, which does not
3889: # necessarily correspond to the time of last submission for problem (or part).
3890: #
3891: if ($lasthash{'timestamp'} ne '') {
3892: $timestamp = &Apache::lonlocal::locallocaltime($lasthash{'timestamp'});
3893: }
1.640 raeburn 3894: my (%typeparts,%randombytry);
1.596 raeburn 3895: my $showsurv =
3896: &Apache::lonnet::allowed('vas',$env{'request.course.id'});
3897: foreach my $key (sort(keys(%lasthash))) {
3898: if ($key =~ /\.type$/) {
3899: if (($lasthash{$key} eq 'anonsurvey') ||
1.640 raeburn 3900: ($lasthash{$key} eq 'anonsurveycred') ||
3901: ($lasthash{$key} eq 'randomizetry')) {
1.596 raeburn 3902: my ($ign,@parts) = split(/\./,$key);
3903: pop(@parts);
1.641 raeburn 3904: my $id = join('.',@parts);
1.640 raeburn 3905: if ($lasthash{$key} eq 'randomizetry') {
3906: $randombytry{$ign.'.'.$id} = $lasthash{$key};
3907: } else {
3908: unless ($showsurv) {
3909: $typeparts{$ign.'.'.$id} = $lasthash{$key};
3910: }
1.596 raeburn 3911: }
3912: delete($lasthash{$key});
3913: }
3914: }
3915: }
3916: my @hidden = keys(%typeparts);
1.640 raeburn 3917: my @randomize = keys(%randombytry);
1.397 albertel 3918: foreach my $key (keys(%lasthash)) {
3919: next if ($key !~ /\.submission$/);
1.596 raeburn 3920: my $hide;
3921: if (@hidden) {
3922: foreach my $id (@hidden) {
3923: if ($key =~ /^\Q$id\E/) {
1.640 raeburn 3924: $hide = 'anon';
1.596 raeburn 3925: last;
3926: }
3927: }
3928: }
1.640 raeburn 3929: unless ($hide) {
3930: if (@randomize) {
1.732 raeburn 3931: foreach my $id (@randomize) {
1.640 raeburn 3932: if ($key =~ /^\Q$id\E/) {
3933: $hide = 'rand';
3934: last;
3935: }
3936: }
3937: }
3938: }
1.397 albertel 3939: my ($partid,$foo) = split(/submission$/,$key);
1.724 raeburn 3940: my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ? 1 : 0;
3941: push(@string, join(':', $key, $hide, $draft, (
1.716 bisitz 3942: ref($lasthash{$key}) eq 'ARRAY' ?
3943: join(',', @{$lasthash{$key}}) : $lasthash{$key}) ));
1.41 ng 3944: }
3945: }
1.397 albertel 3946: if (!@string) {
1.745 raeburn 3947: my $msg;
3948: if ($is_tool) {
1.747 raeburn 3949: $msg = &mt('No grade passed back.');
1.745 raeburn 3950: } else {
3951: $msg = &mt('Nothing submitted - no attempts.');
3952: }
1.397 albertel 3953: $string[0] =
1.745 raeburn 3954: '<span class="LC_warning">'.$msg.'</span>';
1.397 albertel 3955: }
1.792 raeburn 3956: return (\@string,$timestamp,$lastgradetime,$lastsubmittime);
1.38 ng 3957: }
1.35 ng 3958:
1.44 ng 3959: #--- High light keywords, with style choosen by user.
1.38 ng 3960: sub keywords_highlight {
1.44 ng 3961: my $string = shift;
1.257 albertel 3962: my $size = $env{'form.kwsize'} eq '0' ? '' : 'size='.$env{'form.kwsize'};
3963: my $styleon = $env{'form.kwstyle'} eq '' ? '' : $env{'form.kwstyle'};
1.41 ng 3964: (my $styleoff = $styleon) =~ s/\</\<\//;
1.257 albertel 3965: my @keylist = split(/[,\s+]/,$env{'form.keywords'});
1.398 albertel 3966: foreach my $keyword (@keylist) {
3967: $string =~ s/\b\Q$keyword\E(\b|\.)/<font color\=$env{'form.kwclr'} $size\>$styleon$keyword$styleoff<\/font>/gi;
1.41 ng 3968: }
3969: return $string;
1.38 ng 3970: }
1.36 ng 3971:
1.671 raeburn 3972: # For Tasks provide a mechanism to display previous version for one specific student
3973:
3974: sub show_previous_task_version {
3975: my ($request,$symb) = @_;
3976: if ($symb eq '') {
1.717 bisitz 3977: $request->print(
3978: '<span class="LC_error">'.
3979: &mt('Unable to handle ambiguous references.').
3980: '</span>');
1.671 raeburn 3981: return '';
3982: }
3983: my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
3984: my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
3985: if (!&canview($usec)) {
1.712 bisitz 3986: $request->print(
3987: '<span class="LC_warning">'.
1.713 bisitz 3988: &mt('Unable to view previous version for requested student.').
1.712 bisitz 3989: ' '.&mt('([_1] in section [_2] in course id [_3])',
3990: $uname.':'.$udom,$usec,$env{'request.course.id'}).
3991: '</span>');
1.671 raeburn 3992: return;
3993: }
3994: my $mode = 'both';
3995: my $isTask = ($symb =~/\.task$/);
3996: if ($isTask) {
3997: if ($env{'form.previousversion'} =~ /^\d+$/) {
3998: if ($env{'form.fullname'} eq '') {
3999: $env{'form.fullname'} =
4000: &Apache::loncommon::plainname($uname,$udom,'lastname');
4001: }
4002: my $probtitle=&Apache::lonnet::gettitle($symb);
4003: $request->print("\n\n".
4004: '<div class="LC_grade_show_user">'.
4005: '<h2>'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
4006: '</h2>'."\n");
4007: &Apache::lonxml::clear_problem_counter();
4008: $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode,
4009: {'previousversion' => $env{'form.previousversion'} }));
4010: $request->print("\n</div>");
4011: }
4012: }
4013: return;
4014: }
4015:
4016: sub choose_task_version_form {
4017: my ($symb,$uname,$udom,$nomenu) = @_;
4018: my $isTask = ($symb =~/\.task$/);
4019: my ($current,$version,$result,$js,$displayed,$rowtitle);
4020: if ($isTask) {
4021: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
4022: $udom,$uname);
4023: if (($record{'resource.0.version'} eq '') ||
4024: ($record{'resource.0.version'} < 2)) {
4025: return ($record{'resource.0.version'},
4026: $record{'resource.0.version'},$result,$js);
4027: } else {
4028: $current = $record{'resource.0.version'};
4029: }
4030: if ($env{'form.previousversion'}) {
4031: $displayed = $env{'form.previousversion'};
4032: $rowtitle = &mt('Choose another version:')
4033: } else {
4034: $displayed = $current;
4035: $rowtitle = &mt('Show earlier version:');
4036: }
4037: $result = '<div class="LC_left_float">';
4038: my $list;
4039: my $numversions = 0;
4040: for (my $i=1; $i<=$record{'resource.0.version'}; $i++) {
4041: if ($i == $current) {
4042: if (!$env{'form.previousversion'} || $nomenu) {
4043: next;
4044: } else {
4045: $list .= '<option value="'.$i.'">'.&mt('Current').'</option>'."\n";
4046: $numversions ++;
4047: }
4048: } elsif (defined($record{'resource.'.$i.'.0.status'})) {
4049: unless ($i == $env{'form.previousversion'}) {
4050: $numversions ++;
4051: }
4052: $list .= '<option value="'.$i.'">'.$i.'</option>'."\n";
4053: }
4054: }
4055: if ($numversions) {
4056: $symb = &HTML::Entities::encode($symb,'<>"&');
4057: $result .=
4058: '<form name="getprev" method="post" action=""'.
4059: ' onsubmit="return previousVersion('."'$uname','$udom','$symb','$displayed'".');">'.
4060: &Apache::loncommon::start_data_table().
4061: &Apache::loncommon::start_data_table_row().
4062: '<th align="left">'.$rowtitle.'</th>'.
4063: '<td><select name="version">'.
4064: '<option>'.&mt('Select').'</option>'.
4065: $list.
4066: '</select></td>'.
4067: &Apache::loncommon::end_data_table_row();
4068: unless ($nomenu) {
4069: $result .= &Apache::loncommon::start_data_table_row().
4070: '<th align="left">'.&mt('Open in new window').'</th>'.
4071: '<td><span class="LC_nobreak">'.
4072: '<label><input type="radio" name="prevwin" value="1" />'.
4073: &mt('Yes').'</label>'.
4074: '<label><input type="radio" name="prevwin" value="0" checked="checked" />'.&mt('No').'</label>'.
4075: '</span></td>'.
4076: &Apache::loncommon::end_data_table_row();
4077: }
4078: $result .=
4079: &Apache::loncommon::start_data_table_row().
4080: '<th align="left"> </th>'.
4081: '<td>'.
4082: '<input type="submit" name="prevsub" value="'.&mt('Display').'" />'.
4083: '</td>'.
4084: &Apache::loncommon::end_data_table_row().
4085: &Apache::loncommon::end_data_table().
4086: '</form>';
4087: $js = &previous_display_javascript($nomenu,$current);
4088: } elsif ($displayed && $nomenu) {
4089: $result .= '<a href="javascript:window.close()">'.&mt('Close window').'</a>';
4090: } else {
4091: $result .= &mt('No previous versions to show for this student');
4092: }
4093: $result .= '</div>';
4094: }
4095: return ($current,$displayed,$result,$js);
4096: }
4097:
4098: sub previous_display_javascript {
4099: my ($nomenu,$current) = @_;
4100: my $js = <<"JSONE";
4101: <script type="text/javascript">
4102: // <![CDATA[
4103: function previousVersion(uname,udom,symb) {
4104: var current = '$current';
4105: var version = document.getprev.version.options[document.getprev.version.selectedIndex].value;
4106: var prevstr = new RegExp("^\\\\d+\$");
4107: if (!prevstr.test(version)) {
4108: return false;
4109: }
4110: var url = '';
4111: if (version == current) {
4112: url = '/adm/grades?student='+uname+'&userdom='+udom+'&symb='+symb+'&command=submission';
4113: } else {
4114: url = '/adm/grades?student='+uname+'&userdom='+udom+'&symb='+symb+'&command=versionsub&previousversion='+version;
4115: }
4116: JSONE
4117: if ($nomenu) {
4118: $js .= <<"JSTWO";
4119: document.location.href = url;
4120: JSTWO
4121: } else {
4122: $js .= <<"JSTHREE";
4123: var newwin = 0;
4124: for (var i=0; i<document.getprev.prevwin.length; i++) {
4125: if (document.getprev.prevwin[i].checked == true) {
4126: newwin = document.getprev.prevwin[i].value;
4127: }
4128: }
4129: if (newwin == 1) {
4130: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
4131: url = url+'&inhibitmenu=yes';
4132: if (typeof(previousWin) == 'undefined' || previousWin.closed) {
4133: previousWin = window.open(url,'',options,1);
4134: } else {
4135: previousWin.location.href = url;
4136: }
4137: previousWin.focus();
4138: return false;
4139: } else {
4140: document.location.href = url;
4141: return false;
4142: }
4143: JSTHREE
4144: }
4145: $js .= <<"ENDJS";
4146: return false;
4147: }
4148: // ]]>
4149: </script>
4150: ENDJS
4151:
4152: }
4153:
1.44 ng 4154: #--- Called from submission routine
1.38 ng 4155: sub processHandGrade {
1.608 www 4156: my ($request,$symb) = @_;
1.324 albertel 4157: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.257 albertel 4158: my $button = $env{'form.gradeOpt'};
4159: my $ngrade = $env{'form.NCT'};
4160: my $ntstu = $env{'form.NTSTU'};
1.301 albertel 4161: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4162: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.786 raeburn 4163: my ($res_error,%queueable);
4164: my ($partlist,$handgrade,$responseType,$numresp,$numessay) = &response_type($symb,\$res_error);
4165: if ($res_error) {
4166: $request->print(&navmap_errormsg());
4167: return;
4168: } else {
4169: foreach my $part (@{$partlist}) {
4170: if (ref($responseType->{$part}) eq 'HASH') {
4171: foreach my $id (keys(%{$responseType->{$part}})) {
4172: if (($responseType->{$part}->{$id} eq 'essay') ||
4173: (lc($handgrade->{$part.'_'.$id}) eq 'yes')) {
4174: $queueable{$part} = 1;
4175: last;
4176: }
4177: }
4178: }
4179: }
4180: }
1.301 albertel 4181:
1.44 ng 4182: if ($button eq 'Save & Next') {
1.798 raeburn 4183: my %needpb = &passbacks_for_symb($cdom,$cnum,$symb);
4184: my (%skip_passback,%pbsave,%pbcollab);
1.44 ng 4185: my $ctr = 0;
4186: while ($ctr < $ngrade) {
1.257 albertel 4187: my ($uname,$udom) = split(/:/,$env{'form.unamedom'.$ctr});
1.726 raeburn 4188: my ($errorflag,$pts,$wgt,$numhidden) =
1.798 raeburn 4189: &saveHandGrade($request,$symb,$uname,$udom,$ctr,undef,undef,\%queueable,\%needpb,\%skip_passback,\%pbsave);
1.71 ng 4190: if ($errorflag eq 'no_score') {
4191: $ctr++;
4192: next;
4193: }
1.104 albertel 4194: if ($errorflag eq 'not_allowed') {
1.721 bisitz 4195: $request->print(
4196: '<span class="LC_error">'
4197: .&mt('Not allowed to modify grades for [_1]',"$uname:$udom")
4198: .'</span>');
1.104 albertel 4199: $ctr++;
4200: next;
4201: }
1.726 raeburn 4202: if ($numhidden) {
4203: $request->print(
4204: '<span class="LC_info">'
4205: .&mt('For [_1]: [quant,_2,transaction] hidden',"$uname:$udom",$numhidden)
4206: .'</span><br />');
4207: }
1.257 albertel 4208: my $includemsg = $env{'form.includemsg'.$ctr};
1.44 ng 4209: my ($subject,$message,$msgstatus) = ('','','');
1.418 albertel 4210: my $restitle = &Apache::lonnet::gettitle($symb);
4211: my ($feedurl,$showsymb) =
4212: &get_feedurl_and_symb($symb,$uname,$udom);
4213: my $messagetail;
1.62 albertel 4214: if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.298 www 4215: $subject = $env{'form.msgsub'} if ($includemsg =~ /msgsub/);
1.295 www 4216: unless ($subject=~/\w/) { $subject=&mt('Grading Feedback'); }
1.386 raeburn 4217: $subject.=' ['.$restitle.']';
1.44 ng 4218: my (@msgnum) = split(/,/,$includemsg);
4219: foreach (@msgnum) {
1.257 albertel 4220: $message.=$env{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
1.44 ng 4221: }
1.80 ng 4222: $message =&Apache::lonfeedback::clear_out_html($message);
1.298 www 4223: if ($env{'form.withgrades'.$ctr}) {
4224: $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
1.386 raeburn 4225: $messagetail = " for <a href=\"".
1.605 www 4226: $feedurl."?symb=$showsymb\">$restitle</a>";
1.386 raeburn 4227: }
4228: $msgstatus =
4229: &Apache::lonmsg::user_normal_msg($uname,$udom,$subject,
4230: $message.$messagetail,
1.418 albertel 4231: undef,$feedurl,undef,
1.386 raeburn 4232: undef,undef,$showsymb,
4233: $restitle);
1.574 bisitz 4234: $request->print('<br />'.&mt('Sending message to [_1]',$uname.':'.$udom).': '.
1.652 raeburn 4235: $msgstatus.'<br />');
1.44 ng 4236: }
1.257 albertel 4237: if ($env{'form.collaborator'.$ctr}) {
1.155 albertel 4238: my @collabstrs=&Apache::loncommon::get_env_multiple("form.collaborator$ctr");
1.150 albertel 4239: foreach my $collabstr (@collabstrs) {
4240: my ($part,@collaborators) = split(/:/,$collabstr);
1.310 banghart 4241: foreach my $collaborator (@collaborators) {
1.803 raeburn 4242: my ($errorflag,$pts,$wgt,$numchg,$numupdate) =
1.324 albertel 4243: &saveHandGrade($request,$symb,$collaborator,$udom,$ctr,
1.803 raeburn 4244: $env{'form.unamedom'.$ctr},$part,\%queueable);
1.150 albertel 4245: if ($errorflag eq 'not_allowed') {
1.362 albertel 4246: $request->print("<span class=\"LC_error\">".&mt('Not allowed to modify grades for [_1]',"$collaborator:$udom")."</span>");
1.150 albertel 4247: next;
1.798 raeburn 4248: } else {
1.803 raeburn 4249: if ($numchg || $numupdate) {
4250: $pbcollab{$collaborator}{$part} = [$pts,$wgt];
4251: }
1.798 raeburn 4252: if ($message ne '') {
1.800 raeburn 4253: my ($baseurl,$showsymb) =
4254: &get_feedurl_and_symb($symb,$collaborator,
1.801 raeburn 4255: $udom);
1.800 raeburn 4256: if ($env{'form.withgrades'.$ctr}) {
4257: $messagetail = " for <a href=\"".
4258: $baseurl."?symb=$showsymb\">$restitle</a>";
4259: }
4260: $msgstatus =
4261: &Apache::lonmsg::user_normal_msg($collaborator,$udom,$subject,$message.$messagetail,undef,$baseurl,undef,undef,undef,$showsymb,$restitle);
1.150 albertel 4262: }
1.800 raeburn 4263: }
1.44 ng 4264: }
4265: }
4266: }
4267: $ctr++;
4268: }
1.798 raeburn 4269: if ((keys(%pbcollab)) && (keys(%needpb))) {
1.803 raeburn 4270: foreach my $user (keys(%pbcollab)) {
4271: my ($clbuname,$clbudom) = split(/:/,$user);
4272: my $clbusec = &Apache::lonnet::getsection($clbudom,$clbuname,$cdom.'_'.$cnum);
4273: if (ref($pbcollab{$user}) eq 'HASH') {
4274: my @clparts = keys(%{$pbcollab{$user}});
4275: if (@clparts) {
4276: my $navmap = Apache::lonnavmaps::navmap->new($clbuname,$clbudom,$clbusec);
4277: if (ref($navmap)) {
4278: my $res = $navmap->getBySymb($symb);
4279: if (ref($res)) {
4280: my $partlist = $res->parts();
4281: if (ref($partlist) eq 'ARRAY') {
4282: my (%weights,%awardeds,%excuseds);
4283: foreach my $part (@{$partlist}) {
4284: if ($res->status($part) eq $res->EXCUSED) {
4285: $excuseds{$symb}{$part} = 1;
4286: } else {
4287: $excuseds{$symb}{$part} = '';
4288: }
4289: if ((exists($pbcollab{$user}{$part})) && (ref($pbcollab{$user}{$part}) eq 'ARRAY')) {
4290: my $pts = $pbcollab{$user}{$part}[0];
4291: my $wt = $pbcollab{$user}{$part}[1];
4292: if ($wt) {
4293: $awardeds{$symb}{$part} = $pts/$wt;
4294: $weights{$symb}{$part} = $wt;
4295: } else {
4296: $awardeds{$symb}{$part} = 0;
4297: $weights{$symb}{$part} = 0;
4298: }
4299: } else {
4300: $awardeds{$symb}{$part} = $res->awarded($part);
4301: $weights{$symb}{$part} = $res->weight($part);
4302: }
4303: }
4304: &process_passbacks('handgrade',[$symb],$cdom,$cnum,$clbudom,$clbuname,$clbusec,\%weights,
4305: \%awardeds,\%excuseds,\%needpb,\%skip_passback,\%pbsave);
4306: }
4307: }
4308: }
4309: }
4310: }
4311: }
1.798 raeburn 4312: }
1.44 ng 4313: }
4314:
1.773 raeburn 4315: my %keyhash = ();
4316: if ($numessay) {
1.119 ng 4317: # Keywords sorted in alphabatical order
1.257 albertel 4318: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
4319: $env{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
1.775 raeburn 4320: $env{'form.keywords'} =~ s/^\s+|\s+$//g;
1.257 albertel 4321: my (@keywords) = sort(split(/\s+/,$env{'form.keywords'}));
4322: $env{'form.keywords'} = join(' ',@keywords);
4323: $keyhash{$symb.'_keywords'} = $env{'form.keywords'};
4324: $keyhash{$symb.'_subject'} = $env{'form.msgsub'};
4325: $keyhash{$loginuser.'_kwclr'} = $env{'form.kwclr'};
4326: $keyhash{$loginuser.'_kwsize'} = $env{'form.kwsize'};
4327: $keyhash{$loginuser.'_kwstyle'} = $env{'form.kwstyle'};
1.773 raeburn 4328: }
1.119 ng 4329:
1.773 raeburn 4330: if ($env{'form.compmsg'}) {
1.119 ng 4331: # message center - Order of message gets changed. Blank line is eliminated.
1.257 albertel 4332: # New messages are saved in env for the next student.
1.119 ng 4333: # All messages are saved in nohist_handgrade.db
4334: my ($ctr,$idx) = (1,1);
1.257 albertel 4335: while ($ctr <= $env{'form.savemsgN'}) {
4336: if ($env{'form.savemsg'.$ctr} ne '') {
4337: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.savemsg'.$ctr};
1.119 ng 4338: $idx++;
4339: }
4340: $ctr++;
1.41 ng 4341: }
1.119 ng 4342: $ctr = 0;
4343: while ($ctr < $ngrade) {
1.257 albertel 4344: if ($env{'form.newmsg'.$ctr} ne '') {
1.773 raeburn 4345: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.newmsg'.$ctr};
4346: $env{'form.savemsg'.$idx} = $env{'form.newmsg'.$ctr};
4347: $idx++;
1.119 ng 4348: }
4349: $ctr++;
1.41 ng 4350: }
1.257 albertel 4351: $env{'form.savemsgN'} = --$idx;
4352: $keyhash{$symb.'_savemsgN'} = $env{'form.savemsgN'};
1.41 ng 4353: }
1.773 raeburn 4354: if (($numessay) || ($env{'form.compmsg'})) {
4355: my $putresult = &Apache::lonnet::put
4356: ('nohist_handgrade',\%keyhash,$cdom,$cnum);
4357: }
4358:
1.44 ng 4359: # Called by Save & Refresh from Highlight Attribute Window
1.257 albertel 4360: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
4361: if ($env{'form.refresh'} eq 'on') {
1.86 ng 4362: my ($ctr,$total) = (0,0);
4363: while ($ctr < $ngrade) {
1.257 albertel 4364: $total++ if $env{'form.unamedom'.$ctr} ne '';
1.86 ng 4365: $ctr++;
4366: }
1.257 albertel 4367: $env{'form.NTSTU'}=$ngrade;
1.86 ng 4368: $ctr = 0;
4369: while ($ctr < $total) {
1.257 albertel 4370: my $processUser = $env{'form.unamedom'.$ctr};
4371: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
4372: $env{'form.fullname'} = $$fullname{$processUser};
1.625 www 4373: &submission($request,$ctr,$total-1,$symb);
1.41 ng 4374: $ctr++;
4375: }
4376: return '';
4377: }
1.36 ng 4378:
1.44 ng 4379: # Get the next/previous one or group of students
1.257 albertel 4380: my $firststu = $env{'form.unamedom0'};
4381: my $laststu = $env{'form.unamedom'.($ngrade-1)};
1.119 ng 4382: my $ctr = 2;
1.41 ng 4383: while ($laststu eq '') {
1.257 albertel 4384: $laststu = $env{'form.unamedom'.($ngrade-$ctr)};
1.41 ng 4385: $ctr++;
4386: $laststu = $firststu if ($ctr > $ngrade);
4387: }
1.44 ng 4388:
1.41 ng 4389: my (@parsedlist,@nextlist);
4390: my ($nextflg) = 0;
1.524 raeburn 4391: foreach my $item (sort
1.294 albertel 4392: {
4393: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
4394: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
4395: }
4396: return $a cmp $b;
4397: } (keys(%$fullname))) {
1.41 ng 4398: if ($nextflg == 1 && $button =~ /Next$/) {
1.524 raeburn 4399: push(@parsedlist,$item);
1.41 ng 4400: }
1.524 raeburn 4401: $nextflg = 1 if ($item eq $laststu);
1.41 ng 4402: if ($button eq 'Previous') {
1.524 raeburn 4403: last if ($item eq $firststu);
4404: push(@parsedlist,$item);
1.41 ng 4405: }
4406: }
4407: $ctr = 0;
4408: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
4409: foreach my $student (@parsedlist) {
1.257 albertel 4410: my $submitonly=$env{'form.submitonly'};
1.41 ng 4411: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 4412:
4413: if ($submitonly eq 'queued') {
4414: my %queue_status =
4415: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
4416: $udom,$uname);
4417: next if (!defined($queue_status{'gradingqueue'}));
4418: }
4419:
1.156 albertel 4420: if ($submitonly =~ /^(yes|graded|incorrect)$/) {
1.257 albertel 4421: # my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 4422: my %status=&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 4423: my $submitted = 0;
1.248 albertel 4424: my $ungraded = 0;
4425: my $incorrect = 0;
1.524 raeburn 4426: foreach my $item (keys(%status)) {
4427: $submitted = 1 if ($status{$item} ne 'nothing');
4428: $ungraded = 1 if ($status{$item} =~ /^ungraded/);
4429: $incorrect = 1 if ($status{$item} =~ /^incorrect/);
4430: my ($foo,$partid,$foo1) = split(/\./,$item);
1.145 albertel 4431: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
4432: $submitted = 0;
4433: }
1.41 ng 4434: }
1.156 albertel 4435: next if (!$submitted && ($submitonly eq 'yes' ||
4436: $submitonly eq 'incorrect' ||
4437: $submitonly eq 'graded'));
1.248 albertel 4438: next if (!$ungraded && ($submitonly eq 'graded'));
4439: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 4440: }
1.524 raeburn 4441: push(@nextlist,$student) if ($ctr < $ntstu);
1.129 ng 4442: last if ($ctr == $ntstu);
1.41 ng 4443: $ctr++;
4444: }
1.36 ng 4445:
1.41 ng 4446: $ctr = 0;
4447: my $total = scalar(@nextlist)-1;
1.39 ng 4448:
1.524 raeburn 4449: foreach (sort(@nextlist)) {
1.41 ng 4450: my ($uname,$udom,$submitter) = split(/:/);
1.257 albertel 4451: $env{'form.student'} = $uname;
4452: $env{'form.userdom'} = $udom;
4453: $env{'form.fullname'} = $$fullname{$_};
1.625 www 4454: &submission($request,$ctr,$total,$symb);
1.41 ng 4455: $ctr++;
4456: }
4457: if ($total < 0) {
1.653 raeburn 4458: my $the_end.='<p>'.&mt('[_1]Message:[_2] No more students for this section or class.','<b>','</b>').'</p>'."\n";
1.41 ng 4459: $request->print($the_end);
4460: }
4461: return '';
1.38 ng 4462: }
1.36 ng 4463:
1.44 ng 4464: #---- Save the score and award for each student, if changed
1.38 ng 4465: sub saveHandGrade {
1.808 raeburn 4466: my ($request,$symb,$stuname,$domain,$newflg,$submitter,
4467: $part,$queueable,$needpb,$skip_passback,$pbsave) = @_;
1.342 banghart 4468: my @version_parts;
1.104 albertel 4469: my $usec = &Apache::lonnet::getsection($domain,$stuname,
1.257 albertel 4470: $env{'request.course.id'});
1.104 albertel 4471: if (!&canmodify($usec)) { return('not_allowed'); }
1.337 banghart 4472: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
1.251 banghart 4473: my @parts_graded;
1.77 ng 4474: my %newrecord = ();
1.809 raeburn 4475: my ($pts,$wgt,$totchg,$sendupdate,$poss_pb) = ('','',0,0,0);
1.269 raeburn 4476: my %aggregate = ();
4477: my $aggregateflag = 0;
1.726 raeburn 4478: if ($env{'form.HIDE'.$newflg}) {
1.727 raeburn 4479: my ($version,$parts) = split(/:/,$env{'form.HIDE'.$newflg},2);
1.728 raeburn 4480: my $numchgs = &makehidden($version,$parts,\%record,$symb,$domain,$stuname,1);
1.726 raeburn 4481: $totchg += $numchgs;
4482: }
1.808 raeburn 4483: if ((ref($needpb) eq 'HASH') && (keys(%{$needpb}))) {
4484: $poss_pb = 1;
4485: }
1.798 raeburn 4486: my (%weights,%awardeds,%excuseds);
1.301 albertel 4487: my @parts = split(/:/,$env{'form.partlist'.$newflg});
4488: foreach my $new_part (@parts) {
1.803 raeburn 4489: #collaborator ($submitter may vary for different parts)
1.259 banghart 4490: if ($submitter && $new_part ne $part) { next; }
4491: my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
1.808 raeburn 4492: if ($poss_pb) {
4493: $weights{$symb}{$new_part} =
1.810 ! raeburn 4494: &Apache::lonnet::EXT('resource.'.$new_part.'.weight',$symb,$domain,$stuname);
1.808 raeburn 4495: } elsif ($env{'form.WGT'.$newflg.'_'.$new_part} eq '') {
1.798 raeburn 4496: $weights{$symb}{$new_part} = 1;
4497: } else {
4498: $weights{$symb}{$new_part} = $env{'form.WGT'.$newflg.'_'.$new_part};
4499: }
1.125 ng 4500: if ($dropMenu eq 'excused') {
1.798 raeburn 4501: $excuseds{$symb}{$new_part} = 1;
4502: $awardeds{$symb}{$new_part} = '';
1.259 banghart 4503: if ($record{'resource.'.$new_part.'.solved'} ne 'excused') {
4504: $newrecord{'resource.'.$new_part.'.solved'} = 'excused';
4505: if (exists($record{'resource.'.$new_part.'.awarded'})) {
4506: $newrecord{'resource.'.$new_part.'.awarded'} = '';
1.58 albertel 4507: }
1.364 banghart 4508: $newrecord{'resource.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.803 raeburn 4509: $sendupdate ++;
1.58 albertel 4510: }
1.125 ng 4511: } elsif ($dropMenu eq 'reset status'
1.259 banghart 4512: && exists($record{'resource.'.$new_part.'.solved'})) { #don't bother if no old records -> no attempts
1.524 raeburn 4513: foreach my $key (keys(%record)) {
1.259 banghart 4514: if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
1.197 albertel 4515: }
1.259 banghart 4516: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 4517: "$env{'user.name'}:$env{'user.domain'}";
1.270 albertel 4518: my $totaltries = $record{'resource.'.$part.'.tries'};
4519:
4520: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
4521: [$new_part]);
4522: my $aggtries =$totaltries;
1.269 raeburn 4523: if ($last_resets{$new_part}) {
1.270 albertel 4524: $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
4525: $new_part);
1.269 raeburn 4526: }
1.270 albertel 4527:
4528: my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
1.269 raeburn 4529: if ($aggtries > 0) {
1.327 albertel 4530: &decrement_aggs($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
1.269 raeburn 4531: $aggregateflag = 1;
4532: }
1.803 raeburn 4533: $sendupdate ++;
1.798 raeburn 4534: $excuseds{$symb}{$new_part} = '';
4535: $awardeds{$symb}{$new_part} = '';
1.125 ng 4536: } elsif ($dropMenu eq '') {
1.259 banghart 4537: $pts = ($env{'form.GD_BOX'.$newflg.'_'.$new_part} ne '' ?
4538: $env{'form.GD_BOX'.$newflg.'_'.$new_part} :
4539: $env{'form.RADVAL'.$newflg.'_'.$new_part});
4540: if ($pts eq '' && $env{'form.GD_SEL'.$newflg.'_'.$new_part} eq '') {
1.153 albertel 4541: next;
4542: }
1.259 banghart 4543: $wgt = $env{'form.WGT'.$newflg.'_'.$new_part} eq '' ? 1 :
4544: $env{'form.WGT'.$newflg.'_'.$new_part};
1.41 ng 4545: my $partial= $pts/$wgt;
1.798 raeburn 4546: $awardeds{$symb}{$new_part} = $partial;
4547: $excuseds{$symb}{$new_part} = '';
1.259 banghart 4548: if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
1.153 albertel 4549: #do not update score for part if not changed.
1.346 banghart 4550: &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
1.153 albertel 4551: next;
1.251 banghart 4552: } else {
1.524 raeburn 4553: push(@parts_graded,$new_part);
1.803 raeburn 4554: $sendupdate ++;
1.153 albertel 4555: }
1.259 banghart 4556: if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
4557: $newrecord{'resource.'.$new_part.'.awarded'} = $partial;
1.153 albertel 4558: }
1.259 banghart 4559: my $reckey = 'resource.'.$new_part.'.solved';
1.41 ng 4560: if ($partial == 0) {
1.153 albertel 4561: if ($record{$reckey} ne 'incorrect_by_override') {
4562: $newrecord{$reckey} = 'incorrect_by_override';
4563: }
1.41 ng 4564: } else {
1.153 albertel 4565: if ($record{$reckey} ne 'correct_by_override') {
4566: $newrecord{$reckey} = 'correct_by_override';
4567: }
4568: }
4569: if ($submitter &&
1.259 banghart 4570: ($record{'resource.'.$new_part.'.submitted_by'} ne $submitter)) {
4571: $newrecord{'resource.'.$new_part.'.submitted_by'} = $submitter;
1.41 ng 4572: }
1.259 banghart 4573: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 4574: "$env{'user.name'}:$env{'user.domain'}";
1.41 ng 4575: }
1.259 banghart 4576: # unless problem has been graded, set flag to version the submitted files
1.305 banghart 4577: unless ($record{'resource.'.$new_part.'.solved'} =~ /^correct_/ ||
4578: $record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override' ||
4579: $dropMenu eq 'reset status')
4580: {
1.524 raeburn 4581: push(@version_parts,$new_part);
1.259 banghart 4582: }
1.41 ng 4583: }
1.301 albertel 4584: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4585: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4586:
1.344 albertel 4587: if (%newrecord) {
4588: if (@version_parts) {
1.364 banghart 4589: my @changed_keys = &version_portfiles(\%record, \@parts_graded,
4590: $env{'request.course.id'}, $symb, $domain, $stuname, \@version_parts);
1.344 albertel 4591: @newrecord{@changed_keys} = @record{@changed_keys};
1.367 albertel 4592: foreach my $new_part (@version_parts) {
4593: &handback_files($request,$symb,$stuname,$domain,$newflg,
4594: $new_part,\%newrecord);
4595: }
1.259 banghart 4596: }
1.44 ng 4597: &Apache::lonnet::cstore(\%newrecord,$symb,
1.257 albertel 4598: $env{'request.course.id'},$domain,$stuname);
1.380 albertel 4599: &check_and_remove_from_queue(\@parts,\%record,\%newrecord,$symb,
1.786 raeburn 4600: $cdom,$cnum,$domain,$stuname,$queueable);
1.41 ng 4601: }
1.269 raeburn 4602: if ($aggregateflag) {
4603: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 4604: $cdom,$cnum);
1.269 raeburn 4605: }
1.808 raeburn 4606: if (($sendupdate || $totchg) && (!$submitter) && ($poss_pb)) {
4607: &process_passbacks('handgrade',[$symb],$cdom,$cnum,$domain,$stuname,$usec,\%weights,
4608: \%awardeds,\%excuseds,$needpb,$skip_passback,$pbsave);
1.798 raeburn 4609: }
1.803 raeburn 4610: return ('',$pts,$wgt,$totchg,$sendupdate);
1.726 raeburn 4611: }
4612:
4613: sub makehidden {
1.728 raeburn 4614: my ($version,$parts,$record,$symb,$domain,$stuname,$tolog) = @_;
1.726 raeburn 4615: return unless (ref($record) eq 'HASH');
4616: my %modified;
4617: my $numchanged = 0;
4618: if (exists($record->{$version.':keys'})) {
4619: my $partsregexp = $parts;
4620: $partsregexp =~ s/,/|/g;
4621: foreach my $key (split(/\:/,$record->{$version.':keys'})) {
4622: if ($key =~ /^resource\.(?:$partsregexp)\.([^\.]+)$/) {
4623: my $item = $1;
4624: unless (($item eq 'solved') || ($item =~ /^award(|msg|ed)$/)) {
4625: $modified{$key} = $record->{$version.':'.$key};
4626: }
4627: } elsif ($key =~ m{^(resource\.(?:$partsregexp)\.[^\.]+\.)(.+)$}) {
4628: $modified{$1.'hidden'.$2} = $record->{$version.':'.$key};
4629: } elsif ($key =~ /^(ip|timestamp|host)$/) {
4630: $modified{$key} = $record->{$version.':'.$key};
4631: }
4632: }
4633: if (keys(%modified)) {
4634: if (&Apache::lonnet::putstore($env{'request.course.id'},$symb,$version,\%modified,
1.728 raeburn 4635: $domain,$stuname,$tolog) eq 'ok') {
1.726 raeburn 4636: $numchanged ++;
4637: }
4638: }
4639: }
4640: return $numchanged;
1.36 ng 4641: }
1.322 albertel 4642:
1.380 albertel 4643: sub check_and_remove_from_queue {
1.786 raeburn 4644: my ($parts,$record,$newrecord,$symb,$cdom,$cnum,$domain,$stuname,$queueable) = @_;
1.380 albertel 4645: my @ungraded_parts;
4646: foreach my $part (@{$parts}) {
4647: if ( $record->{ 'resource.'.$part.'.awarded'} eq ''
4648: && $record->{ 'resource.'.$part.'.solved' } ne 'excused'
4649: && $newrecord->{'resource.'.$part.'.awarded'} eq ''
4650: && $newrecord->{'resource.'.$part.'.solved' } ne 'excused'
4651: ) {
1.786 raeburn 4652: if ($queueable->{$part}) {
4653: push(@ungraded_parts, $part);
4654: }
1.380 albertel 4655: }
4656: }
4657: if ( !@ungraded_parts ) {
4658: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,
4659: $cnum,$domain,$stuname);
4660: }
4661: }
4662:
1.337 banghart 4663: sub handback_files {
4664: my ($request,$symb,$stuname,$domain,$newflg,$new_part,$newrecord) = @_;
1.517 raeburn 4665: my $portfolio_root = '/userfiles/portfolio';
1.582 raeburn 4666: my $res_error;
4667: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
4668: if ($res_error) {
4669: $request->print('<br />'.&navmap_errormsg().'<br />');
4670: return;
4671: }
1.654 raeburn 4672: my @handedback;
4673: my $file_msg;
1.375 albertel 4674: my @part_response_id = &flatten_responseType($responseType);
4675: foreach my $part_response_id (@part_response_id) {
4676: my ($part_id,$resp_id) = @{ $part_response_id };
4677: my $part_resp = join('_',@{ $part_response_id });
1.654 raeburn 4678: if (($env{'form.'.$newflg.'_'.$part_resp.'_countreturndoc'} =~ /^\d+$/) & ($new_part eq $part_id)) {
4679: for (my $counter=1; $counter<=$env{'form.'.$newflg.'_'.$part_resp.'_countreturndoc'}; $counter++) {
4680: # if multiple files are uploaded names will be 'returndoc2','returndoc3'
4681: if ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$counter}) {
4682: my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$counter.'.filename'};
1.338 banghart 4683: my ($directory,$answer_file) =
1.654 raeburn 4684: ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$counter} =~ /^(.*?)([^\/]*)$/);
1.338 banghart 4685: my ($answer_name,$answer_ver,$answer_ext) =
1.729 raeburn 4686: &Apache::lonnet::file_name_version_ext($answer_file);
1.355 banghart 4687: my ($portfolio_path) = ($directory =~ /^.+$stuname\/portfolio(.*)/);
1.517 raeburn 4688: my $getpropath = 1;
1.773 raeburn 4689: my ($dir_list,$listerror) =
1.662 raeburn 4690: &Apache::lonnet::dirlist($portfolio_root.$portfolio_path,
4691: $domain,$stuname,$getpropath);
1.729 raeburn 4692: my $version = &Apache::lonnet::get_next_version($answer_name,$answer_ext,$dir_list);
1.686 bisitz 4693: # fix filename
1.355 banghart 4694: my ($save_file_name) = (($directory.$answer_name.".$version.".$answer_ext) =~ /^.+\/${stuname}\/(.*)/);
4695: my $result=&Apache::lonnet::finishuserfileupload($stuname,$domain,
1.654 raeburn 4696: $newflg.'_'.$part_resp.'_returndoc'.$counter,
1.355 banghart 4697: $save_file_name);
1.337 banghart 4698: if ($result !~ m|^/uploaded/|) {
1.536 raeburn 4699: $request->print('<br /><span class="LC_error">'.
4700: &mt('An error occurred ([_1]) while trying to upload [_2].',
1.654 raeburn 4701: $result,$newflg.'_'.$part_resp.'_returndoc'.$counter).
1.536 raeburn 4702: '</span>');
1.356 banghart 4703: } else {
1.360 banghart 4704: # mark the file as read only
1.654 raeburn 4705: push(@handedback,$save_file_name);
1.367 albertel 4706: if (exists($$newrecord{"resource.$new_part.$resp_id.handback"})) {
4707: $$newrecord{"resource.$new_part.$resp_id.handback"}.=',';
4708: }
4709: $$newrecord{"resource.$new_part.$resp_id.handback"} .= $save_file_name;
1.654 raeburn 4710: $file_msg.= '<span class="LC_filename"><a href="/uploaded/'."$domain/$stuname/".$save_file_name.'">'.$save_file_name."</a></span> <br />";
1.337 banghart 4711: }
1.686 bisitz 4712: $request->print('<br />'.&mt('[_1] will be the uploaded filename [_2]','<span class="LC_info">'.$fname.'</span>','<span class="LC_filename">'.$env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$counter}.'</span>'));
1.337 banghart 4713: }
4714: }
4715: }
1.654 raeburn 4716: }
4717: if (@handedback > 0) {
4718: $request->print('<br />');
4719: my @what = ($symb,$env{'request.course.id'},'handback');
4720: &Apache::lonnet::mark_as_readonly($domain,$stuname,\@handedback,\@what);
4721: my $user_lh = &Apache::loncommon::user_lang($stuname,$domain,$env{'request.course.id'});
4722: my ($subject,$message);
4723: if (scalar(@handedback) == 1) {
4724: $subject = &mt_user($user_lh,'File Handed Back by Instructor');
4725: $message = &mt_user($user_lh,'A file has been returned that was originally submitted in response to: ');
4726: } else {
4727: $subject = &mt_user($user_lh,'Files Handed Back by Instructor');
4728: $message = &mt_user($user_lh,'Files have been returned that were originally submitted in response to: ');
4729: }
4730: $message .= "<p><strong>".&Apache::lonnet::gettitle($symb)." </strong></p>";
4731: $message .= &mt_user($user_lh,'The returned file(s) are named: [_1]',"<br />$file_msg <br />").
4732: &mt_user($user_lh,'The file(s) can be found in your [_1]portfolio[_2].','<a href="/adm/portfolio">','</a>');
4733: my ($feedurl,$showsymb) =
4734: &get_feedurl_and_symb($symb,$domain,$stuname);
4735: my $restitle = &Apache::lonnet::gettitle($symb);
4736: $subject .= ' '.&mt_user($user_lh,'(File Returned)').' ['.$restitle.']';
4737: my $msgstatus =
4738: &Apache::lonmsg::user_normal_msg($stuname,$domain,$subject,
4739: $message,undef,$feedurl,undef,undef,undef,$showsymb,
4740: $restitle);
4741: if ($msgstatus) {
4742: $request->print(&mt('Notification message status: [_1]','<span class="LC_info">'.$msgstatus.'</span>').'<br />');
4743: }
4744: }
1.338 banghart 4745: return;
1.337 banghart 4746: }
4747:
1.418 albertel 4748: sub get_feedurl_and_symb {
4749: my ($symb,$uname,$udom) = @_;
4750: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
4751: $url = &Apache::lonnet::clutter($url);
4752: my $encrypturl=&Apache::lonnet::EXT('resource.0.encrypturl',
4753: $symb,$udom,$uname);
4754: if ($encrypturl =~ /^yes$/i) {
4755: &Apache::lonenc::encrypted(\$url,1);
4756: &Apache::lonenc::encrypted(\$symb,1);
4757: }
4758: return ($url,$symb);
4759: }
4760:
1.313 banghart 4761: sub get_submitted_files {
4762: my ($udom,$uname,$partid,$respid,$record) = @_;
4763: my @files;
4764: if ($$record{"resource.$partid.$respid.portfiles"}) {
4765: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
4766: foreach my $file (split(',',$$record{"resource.$partid.$respid.portfiles"})) {
4767: push(@files,$file_url.$file);
4768: }
4769: }
4770: if ($$record{"resource.$partid.$respid.uploadedurl"}) {
4771: push(@files,$$record{"resource.$partid.$respid.uploadedurl"});
4772: }
4773: return (\@files);
4774: }
1.322 albertel 4775:
1.269 raeburn 4776: # ----------- Provides number of tries since last reset.
4777: sub get_num_tries {
4778: my ($record,$last_reset,$part) = @_;
4779: my $timestamp = '';
4780: my $num_tries = 0;
4781: if ($$record{'version'}) {
4782: for (my $version=$$record{'version'};$version>=1;$version--) {
4783: if (exists($$record{$version.':resource.'.$part.'.solved'})) {
4784: $timestamp = $$record{$version.':timestamp'};
4785: if ($timestamp > $last_reset) {
4786: $num_tries ++;
4787: } else {
4788: last;
4789: }
4790: }
4791: }
4792: }
4793: return $num_tries;
4794: }
4795:
4796: # ----------- Determine decrements required in aggregate totals
4797: sub decrement_aggs {
4798: my ($symb,$part,$aggregate,$aggtries,$totaltries,$solvedstatus) = @_;
4799: my %decrement = (
4800: attempts => 0,
4801: users => 0,
4802: correct => 0
4803: );
4804: $decrement{'attempts'} = $aggtries;
4805: if ($solvedstatus =~ /^correct/) {
4806: $decrement{'correct'} = 1;
4807: }
4808: if ($aggtries == $totaltries) {
4809: $decrement{'users'} = 1;
4810: }
1.524 raeburn 4811: foreach my $type (keys(%decrement)) {
1.269 raeburn 4812: $$aggregate{$symb."\0".$part."\0".$type} = -$decrement{$type};
4813: }
4814: return;
4815: }
4816:
4817: # ----------- Determine timestamps for last reset of aggregate totals for parts
4818: sub get_last_resets {
1.270 albertel 4819: my ($symb,$courseid,$partids) =@_;
4820: my %last_resets;
1.269 raeburn 4821: my $cdom = $env{'course.'.$courseid.'.domain'};
4822: my $cname = $env{'course.'.$courseid.'.num'};
1.271 albertel 4823: my @keys;
4824: foreach my $part (@{$partids}) {
4825: push(@keys,"$symb\0$part\0resettime");
4826: }
4827: my %results=&Apache::lonnet::get('nohist_resourcetracker',\@keys,
4828: $cdom,$cname);
4829: foreach my $part (@{$partids}) {
4830: $last_resets{$part}=$results{"$symb\0$part\0resettime"};
1.269 raeburn 4831: }
1.270 albertel 4832: return %last_resets;
1.269 raeburn 4833: }
4834:
1.251 banghart 4835: # ----------- Handles creating versions for portfolio files as answers
4836: sub version_portfiles {
1.343 banghart 4837: my ($record, $parts_graded, $courseid, $symb, $domain, $stu_name, $v_flag) = @_;
1.263 banghart 4838: my $version_parts = join('|',@$v_flag);
1.343 banghart 4839: my @returned_keys;
1.255 banghart 4840: my $parts = join('|', @$parts_graded);
1.277 albertel 4841: foreach my $key (keys(%$record)) {
1.259 banghart 4842: my $new_portfiles;
1.263 banghart 4843: if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
1.342 banghart 4844: my @versioned_portfiles;
1.367 albertel 4845: my @portfiles = split(/\s*,\s*/,$$record{$key});
1.729 raeburn 4846: if (@portfiles) {
4847: &Apache::lonnet::portfiles_versioning($symb,$domain,$stu_name,\@portfiles,
4848: \@versioned_portfiles);
1.252 banghart 4849: }
1.343 banghart 4850: $$record{$key} = join(',',@versioned_portfiles);
4851: push(@returned_keys,$key);
1.251 banghart 4852: }
1.794 raeburn 4853: }
4854: return (@returned_keys);
1.305 banghart 4855: }
4856:
1.44 ng 4857: #--------------------------------------------------------------------------------------
4858: #
4859: #-------------------------- Next few routines handles grading by section or whole class
4860: #
4861: #--- Javascript to handle grading by section or whole class
1.42 ng 4862: sub viewgrades_js {
4863: my ($request) = shift;
4864:
1.539 riegler 4865: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
1.736 damieng 4866: &js_escape(\$alertmsg);
1.597 wenzelju 4867: $request->print(&Apache::lonhtmlcommon::scripttag(<<VIEWJAVASCRIPT));
1.45 ng 4868: function writePoint(partid,weight,point) {
1.125 ng 4869: var radioButton = document.classgrade["RADVAL_"+partid];
4870: var textbox = document.classgrade["TEXTVAL_"+partid];
1.42 ng 4871: if (point == "textval") {
1.125 ng 4872: point = document.classgrade["TEXTVAL_"+partid].value;
1.109 matthew 4873: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 4874: alert("$alertmsg"+parseFloat(point));
1.42 ng 4875: var resetbox = false;
4876: for (var i=0; i<radioButton.length; i++) {
4877: if (radioButton[i].checked) {
4878: textbox.value = i;
4879: resetbox = true;
4880: }
4881: }
4882: if (!resetbox) {
4883: textbox.value = "";
4884: }
4885: return;
4886: }
1.109 matthew 4887: if (parseFloat(point) > parseFloat(weight)) {
4888: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 4889: ") greater than the weight for the part. Accept?");
4890: if (resp == false) {
4891: textbox.value = "";
4892: return;
4893: }
4894: }
1.42 ng 4895: for (var i=0; i<radioButton.length; i++) {
4896: radioButton[i].checked=false;
1.109 matthew 4897: if (parseFloat(point) == i) {
1.42 ng 4898: radioButton[i].checked=true;
4899: }
4900: }
1.41 ng 4901:
1.42 ng 4902: } else {
1.125 ng 4903: textbox.value = parseFloat(point);
1.42 ng 4904: }
1.41 ng 4905: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 4906: var user = document.classgrade["ctr"+i].value;
1.289 albertel 4907: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 4908: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
4909: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
4910: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 4911: if (saveval != "correct") {
4912: scorename.value = point;
1.43 ng 4913: if (selname[0].selected != true) {
4914: selname[0].selected = true;
4915: }
1.42 ng 4916: }
4917: }
1.125 ng 4918: document.classgrade["SELVAL_"+partid][0].selected = true;
1.42 ng 4919: }
4920:
4921: function writeRadText(partid,weight) {
1.125 ng 4922: var selval = document.classgrade["SELVAL_"+partid];
4923: var radioButton = document.classgrade["RADVAL_"+partid];
1.265 www 4924: var override = document.classgrade["FORCE_"+partid].checked;
1.125 ng 4925: var textbox = document.classgrade["TEXTVAL_"+partid];
4926: if (selval[1].selected || selval[2].selected) {
1.42 ng 4927: for (var i=0; i<radioButton.length; i++) {
4928: radioButton[i].checked=false;
4929:
4930: }
4931: textbox.value = "";
4932:
4933: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 4934: var user = document.classgrade["ctr"+i].value;
1.289 albertel 4935: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 4936: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
4937: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
4938: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 4939: if ((saveval != "correct") || override) {
1.42 ng 4940: scorename.value = "";
1.125 ng 4941: if (selval[1].selected) {
4942: selname[1].selected = true;
4943: } else {
4944: selname[2].selected = true;
4945: if (Number(document.classgrade["GD_"+user+"_"+partid+"_tries"].value))
4946: {document.classgrade["GD_"+user+"_"+partid+"_tries"].value = '0';}
4947: }
1.42 ng 4948: }
4949: }
1.43 ng 4950: } else {
4951: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 4952: var user = document.classgrade["ctr"+i].value;
1.289 albertel 4953: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 4954: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
4955: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
4956: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 4957: if ((saveval != "correct") || override) {
1.125 ng 4958: scorename.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
1.43 ng 4959: selname[0].selected = true;
4960: }
4961: }
4962: }
1.42 ng 4963: }
4964:
4965: function changeSelect(partid,user) {
1.125 ng 4966: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
4967: var textbox = document.classgrade["GD_"+user+'_'+partid+"_awarded"];
1.44 ng 4968: var point = textbox.value;
1.125 ng 4969: var weight = document.classgrade["weight_"+partid].value;
1.44 ng 4970:
1.109 matthew 4971: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 4972: alert("$alertmsg"+parseFloat(point));
1.44 ng 4973: textbox.value = "";
4974: return;
4975: }
1.109 matthew 4976: if (parseFloat(point) > parseFloat(weight)) {
4977: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 4978: ") greater than the weight of the part. Accept?");
4979: if (resp == false) {
4980: textbox.value = "";
4981: return;
4982: }
4983: }
1.42 ng 4984: selval[0].selected = true;
4985: }
4986:
4987: function changeOneScore(partid,user) {
1.125 ng 4988: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
4989: if (selval[1].selected || selval[2].selected) {
4990: document.classgrade["GD_"+user+'_'+partid+"_awarded"].value = "";
4991: if (selval[2].selected) {
4992: document.classgrade["GD_"+user+'_'+partid+"_tries"].value = "0";
4993: }
1.269 raeburn 4994: }
1.42 ng 4995: }
4996:
4997: function resetEntry(numpart) {
4998: for (ctpart=0;ctpart<numpart;ctpart++) {
1.125 ng 4999: var partid = document.classgrade["partid_"+ctpart].value;
5000: var radioButton = document.classgrade["RADVAL_"+partid];
5001: var textbox = document.classgrade["TEXTVAL_"+partid];
5002: var selval = document.classgrade["SELVAL_"+partid];
1.42 ng 5003: for (var i=0; i<radioButton.length; i++) {
5004: radioButton[i].checked=false;
5005:
5006: }
5007: textbox.value = "";
5008: selval[0].selected = true;
5009:
5010: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 5011: var user = document.classgrade["ctr"+i].value;
1.289 albertel 5012: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 5013: var resetscore = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
5014: resetscore.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
5015: var resettries = document.classgrade["GD_"+user+"_"+partid+"_tries"];
5016: resettries.value = document.classgrade["GD_"+user+"_"+partid+"_tries_s"].value;
5017: var saveselval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
5018: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 5019: if (saveselval == "excused") {
1.43 ng 5020: if (selname[1].selected == false) { selname[1].selected = true;}
1.42 ng 5021: } else {
1.43 ng 5022: if (selname[0].selected == false) {selname[0].selected = true};
1.42 ng 5023: }
5024: }
1.41 ng 5025: }
1.42 ng 5026: }
5027:
1.41 ng 5028: VIEWJAVASCRIPT
1.42 ng 5029: }
5030:
1.44 ng 5031: #--- show scores for a section or whole class w/ option to change/update a score
1.42 ng 5032: sub viewgrades {
1.608 www 5033: my ($request,$symb) = @_;
1.745 raeburn 5034: my ($is_tool,$toolsymb);
5035: if ($symb =~ /ext\.tool$/) {
5036: $is_tool = 1;
5037: $toolsymb = $symb;
5038: }
1.42 ng 5039: &viewgrades_js($request);
1.41 ng 5040:
1.168 albertel 5041: #need to make sure we have the correct data for later EXT calls,
5042: #thus invalidate the cache
5043: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 5044: $env{'course.'.$env{'request.course.id'}.'.num'},
5045: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 5046: &Apache::lonnet::clear_EXT_cache_status();
5047:
1.398 albertel 5048: my $result='<h3><span class="LC_info">'.&mt('Manual Grading').'</span></h3>';
1.41 ng 5049:
5050: #view individual student submission form - called using Javascript viewOneStudent
1.324 albertel 5051: $result.=&jscriptNform($symb);
1.41 ng 5052:
1.44 ng 5053: #beginning of class grading form
1.442 banghart 5054: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.41 ng 5055: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1.418 albertel 5056: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.38 ng 5057: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.432 banghart 5058: &build_section_inputs().
1.442 banghart 5059: '<input type="hidden" name="Status" value="'.$env{'stu_status'}.'" />'."\n".
1.72 ng 5060:
1.738 raeburn 5061: #retrieve selected groups
5062: my (@groups,$group_display);
5063: @groups = &Apache::loncommon::get_env_multiple('form.group');
5064: if (grep(/^all$/,@groups)) {
5065: @groups = ('all');
5066: } elsif (grep(/^none$/,@groups)) {
5067: @groups = ('none');
5068: } elsif (@groups > 0) {
5069: $group_display = join(', ',@groups);
5070: }
5071:
5072: my ($common_header,$specific_header,@sections,$section_display);
1.780 raeburn 5073: if ($env{'request.course.sec'} ne '') {
5074: @sections = ($env{'request.course.sec'});
5075: } else {
5076: @sections = &Apache::loncommon::get_env_multiple('form.section');
5077: }
5078:
5079: # Check if Save button should be usable
5080: my $disabled = ' disabled="disabled"';
5081: if ($perm{'mgr'}) {
5082: if (grep(/^all$/,@sections)) {
5083: undef($disabled);
5084: } else {
5085: foreach my $sec (@sections) {
5086: if (&canmodify($sec)) {
5087: undef($disabled);
5088: last;
5089: }
5090: }
5091: }
5092: }
1.738 raeburn 5093: if (grep(/^all$/,@sections)) {
5094: @sections = ('all');
5095: if ($group_display) {
5096: $common_header = &mt('Assign Common Grade to Students in Group(s) [_1]',$group_display);
5097: $specific_header = &mt('Assign Grade to Specific Students in Group(s) [_1]',$group_display);
5098: } elsif (grep(/^none$/,@groups)) {
5099: $common_header = &mt('Assign Common Grade to Students not assigned to any groups');
5100: $specific_header = &mt('Assign Grade to Specific Students not assigned to any groups');
5101: } else {
5102: $common_header = &mt('Assign Common Grade to Class');
5103: $specific_header = &mt('Assign Grade to Specific Students in Class');
5104: }
5105: } elsif (grep(/^none$/,@sections)) {
5106: @sections = ('none');
5107: if ($group_display) {
5108: $common_header = &mt('Assign Common Grade to Students in no Section and in Group(s) [_1]',$group_display);
5109: $specific_header = &mt('Assign Grade to Specific Students in no Section and in Group(s)',$group_display);
5110: } elsif (grep(/^none$/,@groups)) {
5111: $common_header = &mt('Assign Common Grade to Students in no Section and in no Group');
5112: $specific_header = &mt('Assign Grade to Specific Students in no Section and in no Group');
5113: } else {
5114: $common_header = &mt('Assign Common Grade to Students in no Section');
5115: $specific_header = &mt('Assign Grade to Specific Students in no Section');
5116: }
5117: } else {
5118: $section_display = join (", ",@sections);
5119: if ($group_display) {
5120: $common_header = &mt('Assign Common Grade to Students in Section(s) [_1], and in Group(s) [_2]',
5121: $section_display,$group_display);
5122: $specific_header = &mt('Assign Grade to Specific Students in Section(s) [_1], and in Group(s) [_2]',
5123: $section_display,$group_display);
5124: } elsif (grep(/^none$/,@groups)) {
5125: $common_header = &mt('Assign Common Grade to Students in Section(s) [_1] and no Group',$section_display);
5126: $specific_header = &mt('Assign Grade to Specific Students in Section(s) [_1] and no Group',$section_display);
5127: } else {
5128: $common_header = &mt('Assign Common Grade to Students in Section(s) [_1]',$section_display);
5129: $specific_header = &mt('Assign Grade to Specific Students in Section(s) [_1]',$section_display);
5130: }
5131: }
5132: my %submit_types = &substatus_options();
5133: my $submission_status = $submit_types{$env{'form.submitonly'}};
5134:
5135: if ($env{'form.submitonly'} eq 'all') {
5136: $result.= '<h3>'.$common_header.'</h3>';
5137: } else {
1.745 raeburn 5138: my $text;
5139: if ($is_tool) {
5140: $text = &mt('(transaction status: "[_1]")',$submission_status);
5141: } else {
5142: $text = &mt('(submission status: "[_1]")',$submission_status);
5143: }
5144: $result.= '<h3>'.$common_header.' '.$text.'</h3>';
1.52 albertel 5145: }
1.738 raeburn 5146: $result .= &Apache::loncommon::start_data_table();
1.44 ng 5147: #radio buttons/text box for assigning points for a section or class.
5148: #handles different parts of a problem
1.582 raeburn 5149: my $res_error;
5150: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
5151: if ($res_error) {
5152: return &navmap_errormsg();
5153: }
1.42 ng 5154: my %weight = ();
5155: my $ctsparts = 0;
1.45 ng 5156: my %seen = ();
1.745 raeburn 5157: my @part_response_id;
5158: if ($is_tool) {
5159: @part_response_id = ([0,'']);
5160: } else {
5161: @part_response_id = &flatten_responseType($responseType);
5162: }
1.375 albertel 5163: foreach my $part_response_id (@part_response_id) {
5164: my ($partid,$respid) = @{ $part_response_id };
5165: my $part_resp = join('_',@{ $part_response_id });
1.45 ng 5166: next if $seen{$partid};
5167: $seen{$partid}++;
1.42 ng 5168: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
5169: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
5170:
1.324 albertel 5171: my $display_part=&get_display_part($partid,$symb);
1.485 albertel 5172: my $radio.='<table border="0"><tr>';
1.41 ng 5173: my $ctr = 0;
1.42 ng 5174: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
1.485 albertel 5175: $radio.= '<td><label><input type="radio" name="RADVAL_'.$partid.'" '.
1.54 albertel 5176: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.288 albertel 5177: ','.$ctr.')" />'.$ctr."</label></td>\n";
1.41 ng 5178: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
5179: $ctr++;
5180: }
1.485 albertel 5181: $radio.='</tr></table>';
5182: my $line = '<input type="text" name="TEXTVAL_'.
1.589 bisitz 5183: $partid.'" size="4" '.'onchange="javascript:writePoint(\''.
1.54 albertel 5184: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.539 riegler 5185: $weight{$partid}.' '.&mt('(problem weight)').'</td>'."\n";
1.701 bisitz 5186: $line.= '<td><b>'.&mt('Grade Status').':</b>'.
5187: '<select name="SELVAL_'.$partid.'" '.
5188: 'onchange="javascript:writeRadText(\''.$partid.'\','.
5189: $weight{$partid}.')"> '.
1.401 albertel 5190: '<option selected="selected"> </option>'.
1.485 albertel 5191: '<option value="excused">'.&mt('excused').'</option>'.
5192: '<option value="reset status">'.&mt('reset status').'</option>'.
5193: '</select></td>'.
5194: '<td><label><input type="checkbox" name="FORCE_'.$partid.'" />'.&mt('Override "Correct"').'</label>';
5195: $line.='<input type="hidden" name="partid_'.
5196: $ctsparts.'" value="'.$partid.'" />'."\n";
5197: $line.='<input type="hidden" name="weight_'.
5198: $partid.'" value="'.$weight{$partid}.'" />'."\n";
5199:
5200: $result.=
5201: &Apache::loncommon::start_data_table_row()."\n".
1.577 bisitz 5202: '<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 5203: &Apache::loncommon::end_data_table_row()."\n";
1.42 ng 5204: $ctsparts++;
1.41 ng 5205: }
1.474 albertel 5206: $result.=&Apache::loncommon::end_data_table()."\n".
1.52 albertel 5207: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.485 albertel 5208: $result.='<input type="button" value="'.&mt('Revert to Default').'" '.
1.589 bisitz 5209: 'onclick="javascript:resetEntry('.$ctsparts.');" />';
1.41 ng 5210:
1.44 ng 5211: #table listing all the students in a section/class
5212: #header of table
1.738 raeburn 5213: if ($env{'form.submitonly'} eq 'all') {
5214: $result.= '<h3>'.$specific_header.'</h3>';
5215: } else {
1.745 raeburn 5216: my $text;
5217: if ($is_tool) {
5218: $text = &mt('(transaction status: "[_1]")',$submission_status);
5219: } else {
5220: $text = &mt('(submission status: "[_1]")',$submission_status);
5221: }
5222: $result.= '<h3>'.$specific_header.' '.$text.'</h3>';
1.738 raeburn 5223: }
5224: $result.= &Apache::loncommon::start_data_table().
1.560 raeburn 5225: &Apache::loncommon::start_data_table_header_row().
5226: '<th>'.&mt('No.').'</th>'.
5227: '<th>'.&nameUserString('header')."</th>\n";
1.582 raeburn 5228: my $partserror;
5229: my (@parts) = sort(&getpartlist($symb,\$partserror));
5230: if ($partserror) {
5231: return &navmap_errormsg();
5232: }
1.324 albertel 5233: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.269 raeburn 5234: my @partids = ();
1.41 ng 5235: foreach my $part (@parts) {
1.745 raeburn 5236: my $display=&Apache::lonnet::metadata($url,$part.'.display',$toolsymb);
1.539 riegler 5237: my $narrowtext = &mt('Tries');
5238: $display =~ s|^Number of Attempts|$narrowtext <br />|; # makes the column narrower
1.745 raeburn 5239: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name',$toolsymb); }
1.207 albertel 5240: my ($partid) = &split_part_type($part);
1.524 raeburn 5241: push(@partids,$partid);
1.628 www 5242: #
5243: # FIXME: Looks like $display looks at English text
5244: #
1.324 albertel 5245: my $display_part=&get_display_part($partid,$symb);
1.41 ng 5246: if ($display =~ /^Partial Credit Factor/) {
1.485 albertel 5247: $result.='<th>'.
1.697 bisitz 5248: &mt('Score Part: [_1][_2](weight = [_3])',
5249: $display_part,'<br />',$weight{$partid}).'</th>'."\n";
1.41 ng 5250: next;
1.485 albertel 5251:
1.207 albertel 5252: } else {
1.485 albertel 5253: if ($display =~ /Problem Status/) {
5254: my $grade_status_mt = &mt('Grade Status');
5255: $display =~ s{Problem Status}{$grade_status_mt<br />};
5256: }
5257: my $part_mt = &mt('Part:');
5258: $display =~s{\[Part: \Q$partid\E\]}{$part_mt $display_part};
1.41 ng 5259: }
1.485 albertel 5260:
1.474 albertel 5261: $result.='<th>'.$display.'</th>'."\n";
1.41 ng 5262: }
1.474 albertel 5263: $result.=&Apache::loncommon::end_data_table_header_row();
1.44 ng 5264:
1.270 albertel 5265: my %last_resets =
5266: &get_last_resets($symb,$env{'request.course.id'},\@partids);
1.269 raeburn 5267:
1.41 ng 5268: #get info for each student
1.44 ng 5269: #list all the students - with points and grade status
1.738 raeburn 5270: my (undef,undef,$fullname) = &getclasslist(\@sections,'1',\@groups);
1.41 ng 5271: my $ctr = 0;
1.294 albertel 5272: foreach (sort
5273: {
5274: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
5275: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
5276: }
5277: return $a cmp $b;
5278: } (keys(%$fullname))) {
1.324 albertel 5279: $result.=&viewstudentgrade($symb,$env{'request.course.id'},
1.745 raeburn 5280: $_,$$fullname{$_},\@parts,\%weight,\$ctr,\%last_resets,$is_tool);
1.41 ng 5281: }
1.474 albertel 5282: $result.=&Apache::loncommon::end_data_table();
1.41 ng 5283: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.780 raeburn 5284: $result.='<input type="button" value="'.&mt('Save').'"'.$disabled.' '.
1.589 bisitz 5285: 'onclick="javascript:submit();" target="_self" /></form>'."\n";
1.738 raeburn 5286: if ($ctr == 0) {
1.442 banghart 5287: my $stu_status = join(' or ',&Apache::loncommon::get_env_multiple('form.Status'));
1.738 raeburn 5288: $result='<h3><span class="LC_info">'.&mt('Manual Grading').'</span></h3>'.
5289: '<span class="LC_warning">';
5290: if ($env{'form.submitonly'} eq 'all') {
5291: if (grep(/^all$/,@sections)) {
5292: if (grep(/^all$/,@groups)) {
5293: $result .= &mt('There are no students with enrollment status [_1] to modify or grade.',
5294: $stu_status);
5295: } elsif (grep(/^none$/,@groups)) {
5296: $result .= &mt('There are no students with no group assigned and with enrollment status [_1] to modify or grade.',
5297: $stu_status);
5298: } else {
5299: $result .= &mt('There are no students in group(s) [_1] with enrollment status [_2] to modify or grade.',
5300: $group_display,$stu_status);
5301: }
5302: } elsif (grep(/^none$/,@sections)) {
5303: if (grep(/^all$/,@groups)) {
5304: $result .= &mt('There are no students in no section with enrollment status [_1] to modify or grade.',
5305: $stu_status);
5306: } elsif (grep(/^none$/,@groups)) {
5307: $result .= &mt('There are no students in no section and no group with enrollment status [_1] to modify or grade.',
5308: $stu_status);
5309: } else {
5310: $result .= &mt('There are no students in no section in group(s) [_1] with enrollment status [_2] to modify or grade.',
5311: $group_display,$stu_status);
5312: }
5313: } else {
5314: if (grep(/^all$/,@groups)) {
5315: $result .= &mt('There are no students in section(s) [_1] with enrollment status [_2] to modify or grade.',
5316: $section_display,$stu_status);
5317: } elsif (grep(/^none$/,@groups)) {
1.739 raeburn 5318: $result .= &mt('There are no students in section(s) [_1] and no group with enrollment status [_2] to modify or grade.',
1.738 raeburn 5319: $section_display,$stu_status);
5320: } else {
5321: $result .= &mt('There are no students in section(s) [_1] and group(s) [_2] with enrollment status [_3] to modify or grade.',
5322: $section_display,$group_display,$stu_status);
5323: }
5324: }
5325: } else {
5326: if (grep(/^all$/,@sections)) {
5327: if (grep(/^all$/,@groups)) {
5328: $result .= &mt('There are no students with enrollment status [_1] and submission status "[_2]" to modify or grade.',
5329: $stu_status,$submission_status);
5330: } elsif (grep(/^none$/,@groups)) {
5331: $result .= &mt('There are no students with no group assigned with enrollment status [_1] and submission status "[_2]" to modify or grade.',
5332: $stu_status,$submission_status);
5333: } else {
5334: $result .= &mt('There are no students in group(s) [_1] with enrollment status [_2] and submission status "[_3]" to modify or grade.',
5335: $group_display,$stu_status,$submission_status);
5336: }
5337: } elsif (grep(/^none$/,@sections)) {
5338: if (grep(/^all$/,@groups)) {
5339: $result .= &mt('There are no students in no section with enrollment status [_1] and submission status "[_2]" to modify or grade.',
5340: $stu_status,$submission_status);
5341: } elsif (grep(/^none$/,@groups)) {
5342: $result .= &mt('There are no students in no section and no group with enrollment status [_1] and submission status "[_2]" to modify or grade.',
5343: $stu_status,$submission_status);
5344: } else {
5345: $result .= &mt('There are no students in no section in group(s) [_1] with enrollment status [_2] and submission status "[_3]" to modify or grade.',
5346: $group_display,$stu_status,$submission_status);
5347: }
5348: } else {
5349: if (grep(/^all$/,@groups)) {
5350: $result .= &mt('There are no students in section(s) [_1] with enrollment status [_2] and submission status "[_3]" to modify or grade.',
5351: $section_display,$stu_status,$submission_status);
5352: } elsif (grep(/^none$/,@groups)) {
5353: $result .= &mt('There are no students in section(s) [_1] and no group with enrollment status [_2] and submission status "[_3]" to modify or grade.',
5354: $section_display,$stu_status,$submission_status);
5355: } else {
5356: $result .= &mt('There are no students in section(s) [_1] and group(s) [_2] with enrollment status [_3] and submission status "[_4]" to modify or grade.',
5357: $section_display,$group_display,$stu_status,$submission_status);
5358: }
5359: }
5360: }
5361: $result .= '</span><br />';
1.96 albertel 5362: }
1.41 ng 5363: return $result;
5364: }
5365:
1.738 raeburn 5366: #--- call by previous routine to display each student who satisfies submission filter.
1.41 ng 5367: sub viewstudentgrade {
1.745 raeburn 5368: my ($symb,$courseid,$student,$fullname,$parts,$weight,$ctr,$last_resets,$is_tool) = @_;
1.44 ng 5369: my ($uname,$udom) = split(/:/,$student);
5370: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.738 raeburn 5371: my $submitonly = $env{'form.submitonly'};
5372: unless (($submitonly eq 'all') || ($submitonly eq 'queued')) {
5373: my %partstatus = ();
5374: if (ref($parts) eq 'ARRAY') {
5375: foreach my $apart (@{$parts}) {
5376: my ($part,$type) = &split_part_type($apart);
5377: my ($status,undef) = split(/_/,$record{"resource.$part.solved"},2);
5378: $status = 'nothing' if ($status eq '');
5379: $partstatus{$part} = $status;
5380: my $subkey = "resource.$part.submitted_by";
5381: $partstatus{$subkey} = $record{$subkey} if ($record{$subkey} ne '');
5382: }
5383: my $submitted = 0;
5384: my $graded = 0;
5385: my $incorrect = 0;
5386: foreach my $key (keys(%partstatus)) {
5387: $submitted = 1 if ($partstatus{$key} ne 'nothing');
5388: $graded = 1 if ($partstatus{$key} =~ /^ungraded/);
5389: $incorrect = 1 if ($partstatus{$key} =~ /^incorrect/);
5390:
5391: my $partid = (split(/\./,$key))[1];
5392: if ($partstatus{'resource.'.$partid.'.'.$key.'.submitted_by'} ne '') {
5393: $submitted = 0;
5394: }
5395: }
5396: return if (!$submitted && ($submitonly eq 'yes' ||
5397: $submitonly eq 'incorrect' ||
5398: $submitonly eq 'graded'));
5399: return if (!$graded && ($submitonly eq 'graded'));
5400: return if (!$incorrect && $submitonly eq 'incorrect');
5401: }
5402: }
5403: if ($submitonly eq 'queued') {
5404: my ($cdom,$cnum) = split(/_/,$courseid);
5405: my %queue_status =
5406: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
5407: $udom,$uname);
5408: return if (!defined($queue_status{'gradingqueue'}));
5409: }
5410: $$ctr++;
5411: my %aggregates = ();
1.474 albertel 5412: my $result=&Apache::loncommon::start_data_table_row().'<td align="right">'.
1.738 raeburn 5413: '<input type="hidden" name="ctr'.($$ctr-1).'" value="'.$student.'" />'.
5414: "\n".$$ctr.' </td><td> '.
1.44 ng 5415: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 5416: '\');" target="_self">'.$fullname.'</a> '.
1.398 albertel 5417: '<span class="LC_internal_info">('.$uname.($env{'user.domain'} eq $udom ? '' : ':'.$udom).')</span></td>'."\n";
1.281 albertel 5418: $student=~s/:/_/; # colon doen't work in javascript for names
1.63 albertel 5419: foreach my $apart (@$parts) {
5420: my ($part,$type) = &split_part_type($apart);
1.41 ng 5421: my $score=$record{"resource.$part.$type"};
1.276 albertel 5422: $result.='<td align="center">';
1.269 raeburn 5423: my ($aggtries,$totaltries);
5424: unless (exists($aggregates{$part})) {
1.270 albertel 5425: $totaltries = $record{'resource.'.$part.'.tries'};
5426: $aggtries = $totaltries;
1.269 raeburn 5427: if ($$last_resets{$part}) {
1.270 albertel 5428: $aggtries = &get_num_tries(\%record,$$last_resets{$part},
5429: $part);
5430: }
1.269 raeburn 5431: $result.='<input type="hidden" name="'.
5432: 'GD_'.$student.'_'.$part.'_aggtries" value="'.$aggtries.'" />'."\n";
5433: $result.='<input type="hidden" name="'.
5434: 'GD_'.$student.'_'.$part.'_totaltries" value="'.$totaltries.'" />'."\n";
5435: $aggregates{$part} = 1;
5436: }
1.41 ng 5437: if ($type eq 'awarded') {
1.320 albertel 5438: my $pts = $score eq '' ? '' : &compute_points($score,$$weight{$part});
1.42 ng 5439: $result.='<input type="hidden" name="'.
1.89 albertel 5440: 'GD_'.$student.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.233 albertel 5441: $result.='<input type="text" name="'.
1.89 albertel 5442: 'GD_'.$student.'_'.$part.'_awarded" '.
1.589 bisitz 5443: 'onchange="javascript:changeSelect(\''.$part.'\',\''.$student.
1.44 ng 5444: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41 ng 5445: } elsif ($type eq 'solved') {
5446: my ($status,$foo)=split(/_/,$score,2);
5447: $status = 'nothing' if ($status eq '');
1.89 albertel 5448: $result.='<input type="hidden" name="'.'GD_'.$student.'_'.
1.54 albertel 5449: $part.'_solved_s" value="'.$status.'" />'."\n";
1.233 albertel 5450: $result.=' <select name="'.
1.89 albertel 5451: 'GD_'.$student.'_'.$part.'_solved" '.
1.589 bisitz 5452: 'onchange="javascript:changeOneScore(\''.$part.'\',\''.$student.'\')" >'."\n";
1.485 albertel 5453: $result.= (($status eq 'excused') ? '<option> </option><option selected="selected" value="excused">'.&mt('excused').'</option>'
5454: : '<option selected="selected"> </option><option value="excused">'.&mt('excused').'</option>')."\n";
5455: $result.='<option value="reset status">'.&mt('reset status').'</option>';
1.126 ng 5456: $result.="</select> </td>\n";
1.122 ng 5457: } else {
5458: $result.='<input type="hidden" name="'.
5459: 'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
5460: "\n";
1.233 albertel 5461: $result.='<input type="text" name="'.
1.122 ng 5462: 'GD_'.$student.'_'.$part.'_'.$type.'" '.
5463: 'value="'.$score.'" size="4" /></td>'."\n";
1.41 ng 5464: }
5465: }
1.474 albertel 5466: $result.=&Apache::loncommon::end_data_table_row();
1.41 ng 5467: return $result;
1.38 ng 5468: }
5469:
1.44 ng 5470: #--- change scores for all the students in a section/class
5471: # record does not get update if unchanged
1.38 ng 5472: sub editgrades {
1.608 www 5473: my ($request,$symb) = @_;
1.745 raeburn 5474: my $toolsymb;
5475: if ($symb =~ /ext\.tool$/) {
5476: $toolsymb = $symb;
5477: }
1.41 ng 5478:
1.433 banghart 5479: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.477 albertel 5480: my $title='<h2>'.&mt('Current Grade Status').'</h2>';
1.768 raeburn 5481: $title.='<h4><b>'.&mt('Section:').'</b> '.$section_display.'</h4>'."\n";
1.126 ng 5482:
1.477 albertel 5483: my $result= &Apache::loncommon::start_data_table().
5484: &Apache::loncommon::start_data_table_header_row().
5485: '<th rowspan="2" valign="middle">'.&mt('No.').'</th>'.
5486: '<th rowspan="2" valign="middle">'.&nameUserString('header')."</th>\n";
1.43 ng 5487: my %scoreptr = (
5488: 'correct' =>'correct_by_override',
5489: 'incorrect'=>'incorrect_by_override',
5490: 'excused' =>'excused',
5491: 'ungraded' =>'ungraded_attempted',
1.596 raeburn 5492: 'credited' =>'credit_attempted',
1.43 ng 5493: 'nothing' => '',
5494: );
1.257 albertel 5495: my ($classlist,undef,$fullname) = &getclasslist($env{'form.section'},'0');
1.34 ng 5496:
1.798 raeburn 5497: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5498: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5499: my %needpb = &passbacks_for_symb($cdom,$cnum,$symb);
5500:
1.44 ng 5501: my (@partid);
5502: my %weight = ();
1.54 albertel 5503: my %columns = ();
1.44 ng 5504: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54 albertel 5505:
1.582 raeburn 5506: my $partserror;
5507: my (@parts) = sort(&getpartlist($symb,\$partserror));
5508: if ($partserror) {
5509: return &navmap_errormsg();
5510: }
1.54 albertel 5511: my $header;
1.257 albertel 5512: while ($ctr < $env{'form.totalparts'}) {
5513: my $partid = $env{'form.partid_'.$ctr};
1.524 raeburn 5514: push(@partid,$partid);
1.257 albertel 5515: $weight{$partid} = $env{'form.weight_'.$partid};
1.44 ng 5516: $ctr++;
1.54 albertel 5517: }
1.324 albertel 5518: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.748 raeburn 5519: my $totcolspan = 0;
1.54 albertel 5520: foreach my $partid (@partid) {
1.478 albertel 5521: $header .= '<th align="center">'.&mt('Old Score').'</th>'.
5522: '<th align="center">'.&mt('New Score').'</th>';
1.54 albertel 5523: $columns{$partid}=2;
5524: foreach my $stores (@parts) {
5525: my ($part,$type) = &split_part_type($stores);
5526: if ($part !~ m/^\Q$partid\E/) { next;}
5527: if ($type eq 'awarded' || $type eq 'solved') { next; }
1.745 raeburn 5528: my $display=&Apache::lonnet::metadata($url,$stores.'.display',$toolsymb);
1.551 raeburn 5529: $display =~ s/\[Part: \Q$part\E\]//;
1.539 riegler 5530: my $narrowtext = &mt('Tries');
5531: $display =~ s/Number of Attempts/$narrowtext/;
5532: $header .= '<th align="center">'.&mt('Old').' '.$display.'</th>'.
5533: '<th align="center">'.&mt('New').' '.$display.'</th>';
1.54 albertel 5534: $columns{$partid}+=2;
5535: }
1.748 raeburn 5536: $totcolspan += $columns{$partid};
1.54 albertel 5537: }
5538: foreach my $partid (@partid) {
1.324 albertel 5539: my $display_part=&get_display_part($partid,$symb);
1.478 albertel 5540: $result .= '<th colspan="'.$columns{$partid}.'" align="center">'.
5541: &mt('Part: [_1] (Weight = [_2])',$display_part,$weight{$partid}).
5542: '</th>';
1.54 albertel 5543:
1.44 ng 5544: }
1.477 albertel 5545: $result .= &Apache::loncommon::end_data_table_header_row().
5546: &Apache::loncommon::start_data_table_header_row().
5547: $header.
5548: &Apache::loncommon::end_data_table_header_row();
5549: my @noupdate;
1.126 ng 5550: my ($updateCtr,$noupdateCtr) = (1,1);
1.798 raeburn 5551: my ($got_types,%queueable,%pbsave,%skip_passback);
1.257 albertel 5552: for ($i=0; $i<$env{'form.total'}; $i++) {
5553: my $user = $env{'form.ctr'.$i};
1.281 albertel 5554: my ($uname,$udom)=split(/:/,$user);
1.44 ng 5555: my %newrecord;
5556: my $updateflag = 0;
1.108 albertel 5557: my $usec=$classlist->{"$uname:$udom"}[5];
1.748 raeburn 5558: my $canmodify = &canmodify($usec);
5559: my $line = '<td'.($canmodify?'':' colspan="2"').'>'.
5560: &nameUserString(undef,$$fullname{$user},$uname,$udom).'</td>';
5561: if (!$canmodify) {
1.477 albertel 5562: push(@noupdate,
1.748 raeburn 5563: $line."<td colspan=\"$totcolspan\"><span class=\"LC_warning\">".
5564: &mt('Not allowed to modify student')."</span></td>");
1.105 albertel 5565: next;
5566: }
1.269 raeburn 5567: my %aggregate = ();
5568: my $aggregateflag = 0;
1.281 albertel 5569: $user=~s/:/_/; # colon doen't work in javascript for names
1.798 raeburn 5570: my (%weights,%awardeds,%excuseds);
1.44 ng 5571: foreach (@partid) {
1.257 albertel 5572: my $old_aw = $env{'form.GD_'.$user.'_'.$_.'_awarded_s'};
1.54 albertel 5573: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
5574: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
1.257 albertel 5575: my $old_score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
5576: my $awarded = $env{'form.GD_'.$user.'_'.$_.'_awarded'};
1.54 albertel 5577: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
5578: my $partial = $awarded eq '' ? '' : $pcr;
1.798 raeburn 5579: $awardeds{$symb}{$_} = $partial;
1.44 ng 5580: my $score;
5581: if ($partial eq '') {
1.257 albertel 5582: $score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 5583: } elsif ($partial > 0) {
5584: $score = 'correct_by_override';
5585: } elsif ($partial == 0) {
5586: $score = 'incorrect_by_override';
5587: }
1.257 albertel 5588: my $dropMenu = $env{'form.GD_'.$user.'_'.$_.'_solved'};
1.125 ng 5589: $score = 'excused' if (($dropMenu eq 'excused') && ($score ne 'excused'));
5590:
1.292 albertel 5591: $newrecord{'resource.'.$_.'.regrader'}=
5592: "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 5593: if ($dropMenu eq 'reset status' &&
5594: $old_score ne '') { # ignore if no previous attempts => nothing to reset
1.299 albertel 5595: $newrecord{'resource.'.$_.'.tries'} = '';
1.125 ng 5596: $newrecord{'resource.'.$_.'.solved'} = '';
5597: $newrecord{'resource.'.$_.'.award'} = '';
1.299 albertel 5598: $newrecord{'resource.'.$_.'.awarded'} = '';
1.125 ng 5599: $updateflag = 1;
1.269 raeburn 5600: if ($env{'form.GD_'.$user.'_'.$_.'_aggtries'} > 0) {
5601: my $aggtries = $env{'form.GD_'.$user.'_'.$_.'_aggtries'};
5602: my $totaltries = $env{'form.GD_'.$user.'_'.$_.'_totaltries'};
5603: my $solvedstatus = $env{'form.GD_'.$user.'_'.$_.'_solved_s'};
5604: &decrement_aggs($symb,$_,\%aggregate,$aggtries,$totaltries,$solvedstatus);
5605: $aggregateflag = 1;
5606: }
1.139 albertel 5607: } elsif (!($old_part eq $partial && $old_score eq $score)) {
5608: $updateflag = 1;
5609: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
5610: $newrecord{'resource.'.$_.'.solved'} = $score;
5611: $rec_update++;
1.125 ng 5612: }
5613:
1.93 albertel 5614: $line .= '<td align="center">'.$old_aw.' </td>'.
1.44 ng 5615: '<td align="center">'.$awarded.
5616: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 5617:
1.54 albertel 5618:
5619: my $partid=$_;
1.798 raeburn 5620: if ($score eq 'excused') {
5621: $excuseds{$symb}{$partid} = 1;
5622: } else {
5623: $excuseds{$symb}{$partid} = '';
5624: }
1.54 albertel 5625: foreach my $stores (@parts) {
5626: my ($part,$type) = &split_part_type($stores);
5627: if ($part !~ m/^\Q$partid\E/) { next;}
5628: if ($type eq 'awarded' || $type eq 'solved') { next; }
1.257 albertel 5629: my $old_aw = $env{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
5630: my $awarded = $env{'form.GD_'.$user.'_'.$part.'_'.$type};
1.54 albertel 5631: if ($awarded ne '' && $awarded ne $old_aw) {
5632: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.257 albertel 5633: $newrecord{'resource.'.$part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.54 albertel 5634: $updateflag=1;
5635: }
1.93 albertel 5636: $line .= '<td align="center">'.$old_aw.' </td>'.
1.54 albertel 5637: '<td align="center">'.$awarded.' </td>';
5638: }
1.44 ng 5639: }
1.477 albertel 5640: $line.="\n";
1.301 albertel 5641:
1.44 ng 5642: if ($updateflag) {
5643: $count++;
1.257 albertel 5644: &Apache::lonnet::cstore(\%newrecord,$symb,$env{'request.course.id'},
1.89 albertel 5645: $udom,$uname);
1.301 albertel 5646:
5647: if (&Apache::bridgetask::in_queue('gradingqueue',$symb,$cdom,
5648: $cnum,$udom,$uname)) {
5649: # need to figure out if should be in queue.
5650: my %record =
5651: &Apache::lonnet::restore($symb,$env{'request.course.id'},
5652: $udom,$uname);
5653: my $all_graded = 1;
5654: my $none_graded = 1;
1.786 raeburn 5655: unless ($got_types) {
5656: my $error;
5657: my ($plist,$handgrd,$resptype) = &response_type($symb,\$error);
5658: unless ($error) {
5659: foreach my $part (@parts) {
5660: if (ref($resptype->{$part}) eq 'HASH') {
5661: foreach my $id (keys(%{$resptype->{$part}})) {
5662: if (($resptype->{$part}->{$id} eq 'essay') ||
5663: (lc($handgrd->{$part.'_'.$id}) eq 'yes')) {
5664: $queueable{$part} = 1;
5665: last;
5666: }
5667: }
5668: }
5669: }
5670: }
5671: $got_types = 1;
5672: }
1.301 albertel 5673: foreach my $part (@parts) {
1.786 raeburn 5674: if ($queueable{$part}) {
5675: if ( $record{'resource.'.$part.'.awarded'} eq '' ) {
5676: $all_graded = 0;
5677: } else {
5678: $none_graded = 0;
5679: }
1.301 albertel 5680: }
1.786 raeburn 5681: }
1.301 albertel 5682: if ($all_graded || $none_graded) {
5683: &Apache::bridgetask::remove_from_queue('gradingqueue',
5684: $symb,$cdom,$cnum,
5685: $udom,$uname);
5686: }
5687: }
5688:
1.477 albertel 5689: $result.=&Apache::loncommon::start_data_table_row().
5690: '<td align="right"> '.$updateCtr.' </td>'.$line.
5691: &Apache::loncommon::end_data_table_row();
1.126 ng 5692: $updateCtr++;
1.798 raeburn 5693: if (keys(%needpb)) {
5694: $weights{$symb} = \%weight;
1.802 raeburn 5695: &process_passbacks('editgrades',[$symb],$cdom,$cnum,$udom,$uname,$usec,\%weights,
1.798 raeburn 5696: \%awardeds,\%excuseds,\%needpb,\%skip_passback,\%pbsave);
5697: }
1.93 albertel 5698: } else {
1.477 albertel 5699: push(@noupdate,
5700: '<td align="right"> '.$noupdateCtr.' </td>'.$line);
1.126 ng 5701: $noupdateCtr++;
1.44 ng 5702: }
1.269 raeburn 5703: if ($aggregateflag) {
5704: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 5705: $cdom,$cnum);
1.269 raeburn 5706: }
1.93 albertel 5707: }
1.477 albertel 5708: if (@noupdate) {
1.748 raeburn 5709: my $numcols=$totcolspan+2;
1.477 albertel 5710: $result .= &Apache::loncommon::start_data_table_row('LC_empty_row').
1.478 albertel 5711: '<td align="center" colspan="'.$numcols.'">'.
5712: &mt('No Changes Occurred For the Students Below').
5713: '</td>'.
1.477 albertel 5714: &Apache::loncommon::end_data_table_row();
5715: foreach my $line (@noupdate) {
5716: $result.=
5717: &Apache::loncommon::start_data_table_row().
5718: $line.
5719: &Apache::loncommon::end_data_table_row();
5720: }
1.44 ng 5721: }
1.614 www 5722: $result .= &Apache::loncommon::end_data_table();
1.478 albertel 5723: my $msg = '<p><b>'.
5724: &mt('Number of records updated = [_1] for [quant,_2,student].',
5725: $rec_update,$count).'</b><br />'.
5726: '<b>'.&mt('Total number of students = [_1]',$env{'form.total'}).
5727: '</b></p>';
1.44 ng 5728: return $title.$msg.$result;
1.5 albertel 5729: }
1.54 albertel 5730:
5731: sub split_part_type {
5732: my ($partstr) = @_;
5733: my ($temp,@allparts)=split(/_/,$partstr);
5734: my $type=pop(@allparts);
1.439 albertel 5735: my $part=join('_',@allparts);
1.54 albertel 5736: return ($part,$type);
5737: }
5738:
1.44 ng 5739: #------------- end of section for handling grading by section/class ---------
5740: #
5741: #----------------------------------------------------------------------------
5742:
1.5 albertel 5743:
1.44 ng 5744: #----------------------------------------------------------------------------
5745: #
5746: #-------------------------- Next few routines handles grading by csv upload
5747: #
5748: #--- Javascript to handle csv upload
1.27 albertel 5749: sub csvupload_javascript_reverse_associate {
1.743 raeburn 5750: my $error1=&mt('You need to specify the username, the student/employee ID, or the clicker ID');
1.246 albertel 5751: my $error2=&mt('You need to specify at least one grading field');
1.736 damieng 5752: &js_escape(\$error1);
5753: &js_escape(\$error2);
1.27 albertel 5754: return(<<ENDPICK);
5755: function verify(vf) {
5756: var foundsomething=0;
5757: var founduname=0;
1.243 albertel 5758: var foundID=0;
1.743 raeburn 5759: var foundclicker=0;
1.27 albertel 5760: for (i=0;i<=vf.nfields.value;i++) {
5761: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 5762: if (i==0 && tw!=0) { foundID=1; }
5763: if (i==1 && tw!=0) { founduname=1; }
1.743 raeburn 5764: if (i==2 && tw!=0) { foundclicker=1; }
5765: if (i!=0 && i!=1 && i!=2 && i!=3 && tw!=0) { foundsomething=1; }
1.27 albertel 5766: }
1.743 raeburn 5767: if (founduname==0 && foundID==0 && foundclicker==0) {
1.246 albertel 5768: alert('$error1');
5769: return;
1.27 albertel 5770: }
5771: if (foundsomething==0) {
1.246 albertel 5772: alert('$error2');
5773: return;
1.27 albertel 5774: }
5775: vf.submit();
5776: }
5777: function flip(vf,tf) {
5778: var nw=eval('vf.f'+tf+'.selectedIndex');
5779: var i;
5780: for (i=0;i<=vf.nfields.value;i++) {
5781: //can not pick the same destination field for both name and domain
5782: if (((i ==0)||(i ==1)) &&
5783: ((tf==0)||(tf==1)) &&
5784: (i!=tf) &&
5785: (eval('vf.f'+i+'.selectedIndex')==nw)) {
5786: eval('vf.f'+i+'.selectedIndex=0;')
5787: }
5788: }
5789: }
5790: ENDPICK
5791: }
5792:
5793: sub csvupload_javascript_forward_associate {
1.743 raeburn 5794: my $error1=&mt('You need to specify the username, the student/employee ID, or the clicker ID');
1.246 albertel 5795: my $error2=&mt('You need to specify at least one grading field');
1.736 damieng 5796: &js_escape(\$error1);
5797: &js_escape(\$error2);
1.27 albertel 5798: return(<<ENDPICK);
5799: function verify(vf) {
5800: var foundsomething=0;
5801: var founduname=0;
1.243 albertel 5802: var foundID=0;
1.743 raeburn 5803: var foundclicker=0;
1.27 albertel 5804: for (i=0;i<=vf.nfields.value;i++) {
5805: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 5806: if (tw==1) { foundID=1; }
5807: if (tw==2) { founduname=1; }
1.745 raeburn 5808: if (tw==3) { foundclicker=1; }
1.743 raeburn 5809: if (tw>4) { foundsomething=1; }
1.27 albertel 5810: }
1.743 raeburn 5811: if (founduname==0 && foundID==0 && Æ’oundclicker==0) {
1.246 albertel 5812: alert('$error1');
5813: return;
1.27 albertel 5814: }
5815: if (foundsomething==0) {
1.246 albertel 5816: alert('$error2');
5817: return;
1.27 albertel 5818: }
5819: vf.submit();
5820: }
5821: function flip(vf,tf) {
5822: var nw=eval('vf.f'+tf+'.selectedIndex');
5823: var i;
5824: //can not pick the same destination field twice
5825: for (i=0;i<=vf.nfields.value;i++) {
5826: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
5827: eval('vf.f'+i+'.selectedIndex=0;')
5828: }
5829: }
5830: }
5831: ENDPICK
5832: }
5833:
1.26 albertel 5834: sub csvuploadmap_header {
1.324 albertel 5835: my ($request,$symb,$datatoken,$distotal)= @_;
1.41 ng 5836: my $javascript;
1.257 albertel 5837: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 5838: $javascript=&csvupload_javascript_reverse_associate();
5839: } else {
5840: $javascript=&csvupload_javascript_forward_associate();
5841: }
1.45 ng 5842:
1.418 albertel 5843: $symb = &Apache::lonenc::check_encrypt($symb);
1.632 www 5844: $request->print('<form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">'.
5845: &mt('Total number of records found in file: [_1]',$distotal).'<hr />'.
5846: &mt('Associate entries from the uploaded file with as many fields as you can.'));
5847: my $reverse=&mt("Reverse Association");
1.41 ng 5848: $request->print(<<ENDPICK);
1.632 www 5849: <br />
5850: <input type="button" value="$reverse" onclick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1.26 albertel 5851: <input type="hidden" name="associate" value="" />
5852: <input type="hidden" name="phase" value="three" />
5853: <input type="hidden" name="datatoken" value="$datatoken" />
1.257 albertel 5854: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
5855: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
1.26 albertel 5856: <input type="hidden" name="upfile_associate"
1.257 albertel 5857: value="$env{'form.upfile_associate'}" />
1.26 albertel 5858: <input type="hidden" name="symb" value="$symb" />
1.246 albertel 5859: <input type="hidden" name="command" value="csvuploadoptions" />
1.26 albertel 5860: <hr />
5861: ENDPICK
1.597 wenzelju 5862: $request->print(&Apache::lonhtmlcommon::scripttag($javascript));
1.118 ng 5863: return '';
1.26 albertel 5864:
5865: }
5866:
5867: sub csvupload_fields {
1.582 raeburn 5868: my ($symb,$errorref) = @_;
1.745 raeburn 5869: my $toolsymb;
5870: if ($symb =~ /ext\.tool$/) {
5871: $toolsymb = $symb;
5872: }
1.582 raeburn 5873: my (@parts) = &getpartlist($symb,$errorref);
5874: if (ref($errorref)) {
5875: if ($$errorref) {
5876: return;
5877: }
5878: }
5879:
1.556 weissno 5880: my @fields=(['ID','Student/Employee ID'],
1.243 albertel 5881: ['username','Student Username'],
1.743 raeburn 5882: ['clicker','Clicker ID'],
1.243 albertel 5883: ['domain','Student Domain']);
1.324 albertel 5884: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.41 ng 5885: foreach my $part (sort(@parts)) {
5886: my @datum;
1.745 raeburn 5887: my $display=&Apache::lonnet::metadata($url,$part.'.display',$toolsymb);
1.41 ng 5888: my $name=$part;
1.745 raeburn 5889: if (!$display) { $display = $name; }
1.41 ng 5890: @datum=($name,$display);
1.244 albertel 5891: if ($name=~/^stores_(.*)_awarded/) {
5892: push(@fields,['stores_'.$1.'_points',"Points [Part: $1]"]);
5893: }
1.41 ng 5894: push(@fields,\@datum);
5895: }
5896: return (@fields);
1.26 albertel 5897: }
5898:
5899: sub csvuploadmap_footer {
1.41 ng 5900: my ($request,$i,$keyfields) =@_;
1.703 bisitz 5901: my $buttontext = &mt('Assign Grades');
1.41 ng 5902: $request->print(<<ENDPICK);
1.26 albertel 5903: </table>
5904: <input type="hidden" name="nfields" value="$i" />
5905: <input type="hidden" name="keyfields" value="$keyfields" />
1.703 bisitz 5906: <input type="button" onclick="javascript:verify(this.form)" value="$buttontext" /><br />
1.26 albertel 5907: </form>
5908: ENDPICK
5909: }
5910:
1.283 albertel 5911: sub checkforfile_js {
1.638 www 5912: my $alertmsg = &mt('Please use the browse button to select a file from your local directory.');
1.736 damieng 5913: &js_escape(\$alertmsg);
1.597 wenzelju 5914: my $result = &Apache::lonhtmlcommon::scripttag(<<CSVFORMJS);
1.86 ng 5915: function checkUpload(formname) {
5916: if (formname.upfile.value == "") {
1.539 riegler 5917: alert("$alertmsg");
1.86 ng 5918: return false;
5919: }
5920: formname.submit();
5921: }
5922: CSVFORMJS
1.283 albertel 5923: return $result;
5924: }
5925:
5926: sub upcsvScores_form {
1.608 www 5927: my ($request,$symb) = @_;
1.283 albertel 5928: if (!$symb) {return '';}
5929: my $result=&checkforfile_js();
1.632 www 5930: $result.=&Apache::loncommon::start_data_table().
5931: &Apache::loncommon::start_data_table_header_row().
5932: '<th>'.&mt('Specify a file containing the class scores for current resource.').'</th>'.
5933: &Apache::loncommon::end_data_table_header_row().
5934: &Apache::loncommon::start_data_table_row().'<td>';
1.370 www 5935: my $upload=&mt("Upload Scores");
1.86 ng 5936: my $upfile_select=&Apache::loncommon::upfile_select_html();
1.245 albertel 5937: my $ignore=&mt('Ignore First Line');
1.418 albertel 5938: $symb = &Apache::lonenc::check_encrypt($symb);
1.86 ng 5939: $result.=<<ENDUPFORM;
1.106 albertel 5940: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.86 ng 5941: <input type="hidden" name="symb" value="$symb" />
5942: <input type="hidden" name="command" value="csvuploadmap" />
5943: $upfile_select
1.589 bisitz 5944: <br /><input type="button" onclick="javascript:checkUpload(this.form);" value="$upload" />
1.86 ng 5945: </form>
5946: ENDUPFORM
1.370 www 5947: $result.=&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
1.632 www 5948: &mt("How do I create a CSV file from a spreadsheet")).
5949: '</td>'.
5950: &Apache::loncommon::end_data_table_row().
5951: &Apache::loncommon::end_data_table();
1.86 ng 5952: return $result;
5953: }
5954:
5955:
1.26 albertel 5956: sub csvuploadmap {
1.768 raeburn 5957: my ($request,$symb) = @_;
1.41 ng 5958: if (!$symb) {return '';}
1.72 ng 5959:
1.41 ng 5960: my $datatoken;
1.257 albertel 5961: if (!$env{'form.datatoken'}) {
1.41 ng 5962: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 5963: } else {
1.742 raeburn 5964: $datatoken=&Apache::loncommon::valid_datatoken($env{'form.datatoken'});
5965: if ($datatoken ne '') {
5966: &Apache::loncommon::load_tmp_file($request,$datatoken);
5967: }
1.26 albertel 5968: }
1.41 ng 5969: my @records=&Apache::loncommon::upfile_record_sep();
1.324 albertel 5970: &csvuploadmap_header($request,$symb,$datatoken,$#records+1);
1.41 ng 5971: my ($i,$keyfields);
5972: if (@records) {
1.582 raeburn 5973: my $fieldserror;
5974: my @fields=&csvupload_fields($symb,\$fieldserror);
5975: if ($fieldserror) {
5976: $request->print(&navmap_errormsg());
5977: return;
5978: }
1.257 albertel 5979: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 5980: &Apache::loncommon::csv_print_samples($request,\@records);
5981: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
5982: \@fields);
5983: foreach (@fields) { $keyfields.=$_->[0].','; }
5984: chop($keyfields);
5985: } else {
5986: unshift(@fields,['none','']);
5987: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
5988: \@fields);
1.311 banghart 5989: foreach my $rec (@records) {
5990: my %temp = &Apache::loncommon::record_sep($rec);
5991: if (%temp) {
5992: $keyfields=join(',',sort(keys(%temp)));
5993: last;
5994: }
5995: }
1.41 ng 5996: }
5997: }
5998: &csvuploadmap_footer($request,$i,$keyfields);
1.72 ng 5999:
1.41 ng 6000: return '';
1.27 albertel 6001: }
6002:
1.246 albertel 6003: sub csvuploadoptions {
1.608 www 6004: my ($request,$symb)= @_;
1.632 www 6005: my $overwrite=&mt('Overwrite any existing score');
1.246 albertel 6006: $request->print(<<ENDPICK);
6007: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
6008: <input type="hidden" name="command" value="csvuploadassign" />
6009: <p>
6010: <label>
6011: <input type="checkbox" name="overwite_scores" checked="checked" />
1.632 www 6012: $overwrite
1.246 albertel 6013: </label>
6014: </p>
6015: ENDPICK
6016: my %fields=&get_fields();
6017: if (!defined($fields{'domain'})) {
1.257 albertel 6018: my $domform = &Apache::loncommon::select_dom_form($env{'request.role.domain'},'default_domain');
1.632 www 6019: $request->print("\n<p>".&mt('Users are in domain: [_1]',$domform)."</p>\n");
1.246 albertel 6020: }
1.257 albertel 6021: foreach my $key (sort(keys(%env))) {
1.246 albertel 6022: if ($key !~ /^form\.(.*)$/) { next; }
6023: my $cleankey=$1;
6024: if ($cleankey eq 'command') { next; }
6025: $request->print('<input type="hidden" name="'.$cleankey.
1.257 albertel 6026: '" value="'.$env{$key}.'" />'."\n");
1.246 albertel 6027: }
6028: # FIXME do a check for any duplicated user ids...
6029: # FIXME do a check for any invalid user ids?...
1.703 bisitz 6030: $request->print('<input type="submit" value="'.&mt('Assign Grades').'" /><br />
1.290 albertel 6031: <hr /></form>'."\n");
1.246 albertel 6032: return '';
6033: }
6034:
6035: sub get_fields {
6036: my %fields;
1.257 albertel 6037: my @keyfields = split(/\,/,$env{'form.keyfields'});
6038: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
6039: if ($env{'form.upfile_associate'} eq 'reverse') {
6040: if ($env{'form.f'.$i} ne 'none') {
6041: $fields{$keyfields[$i]}=$env{'form.f'.$i};
1.41 ng 6042: }
6043: } else {
1.257 albertel 6044: if ($env{'form.f'.$i} ne 'none') {
6045: $fields{$env{'form.f'.$i}}=$keyfields[$i];
1.41 ng 6046: }
6047: }
1.27 albertel 6048: }
1.246 albertel 6049: return %fields;
6050: }
6051:
6052: sub csvuploadassign {
1.766 raeburn 6053: my ($request,$symb) = @_;
1.246 albertel 6054: if (!$symb) {return '';}
1.345 bowersj2 6055: my $error_msg = '';
1.742 raeburn 6056: my $datatoken = &Apache::loncommon::valid_datatoken($env{'form.datatoken'});
6057: if ($datatoken ne '') {
6058: &Apache::loncommon::load_tmp_file($request,$datatoken);
6059: }
1.246 albertel 6060: my @gradedata = &Apache::loncommon::upfile_record_sep();
6061: my %fields=&get_fields();
1.257 albertel 6062: my $courseid=$env{'request.course.id'};
1.798 raeburn 6063: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6064: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.97 albertel 6065: my ($classlist) = &getclasslist('all',0);
1.106 albertel 6066: my @notallowed;
1.41 ng 6067: my @skipped;
1.657 raeburn 6068: my @warnings;
1.41 ng 6069: my $countdone=0;
1.798 raeburn 6070: my @parts;
6071: my %needpb = &passbacks_for_symb($cdom,$cnum,$symb);
6072: my $passback;
6073: if (keys(%needpb)) {
6074: $passback = 1;
6075: my $navmap = Apache::lonnavmaps::navmap->new();
6076: if (ref($navmap)) {
6077: my $res = $navmap->getBySymb($symb);
6078: if (ref($res)) {
6079: my $partlist = $res->parts();
6080: if (ref($partlist) eq 'ARRAY') {
6081: @parts = sort(@{$partlist});
6082: }
6083: }
6084: } else {
6085: return &navmap_errormsg();
6086: }
6087: }
6088: my (%skip_passback,%pbsave,%weights,%awardeds,%excuseds);
6089:
1.41 ng 6090: foreach my $grade (@gradedata) {
6091: my %entries=&Apache::loncommon::record_sep($grade);
1.246 albertel 6092: my $domain;
6093: if ($entries{$fields{'domain'}}) {
6094: $domain=$entries{$fields{'domain'}};
6095: } else {
1.257 albertel 6096: $domain=$env{'form.default_domain'};
1.246 albertel 6097: }
1.243 albertel 6098: $domain=~s/\s//g;
1.41 ng 6099: my $username=$entries{$fields{'username'}};
1.160 albertel 6100: $username=~s/\s//g;
1.243 albertel 6101: if (!$username) {
6102: my $id=$entries{$fields{'ID'}};
1.247 albertel 6103: $id=~s/\s//g;
1.737 raeburn 6104: if ($id ne '') {
6105: my %ids=&Apache::lonnet::idget($domain,[$id]);
6106: $username=$ids{$id};
6107: } else {
6108: if ($entries{$fields{'clicker'}}) {
6109: my $clicker = $entries{$fields{'clicker'}};
6110: $clicker=~s/\s//g;
6111: if ($clicker ne '') {
6112: my %clickers = &Apache::lonnet::idget($domain,[$clicker],'clickers');
6113: if ($clickers{$clicker} ne '') {
6114: my $match = 0;
6115: my @inclass;
6116: foreach my $poss (split(/,/,$clickers{$clicker})) {
6117: if (exists($$classlist{"$poss:$domain"})) {
6118: $username = $poss;
6119: push(@inclass,$poss);
6120: $match ++;
6121:
6122: }
6123: }
6124: if ($match > 1) {
6125: undef($username);
6126: $request->print('<p class="LC_warning">'.
6127: &mt('Score not saved for clicker: [_1] (matched multiple usernames: [_2])',
6128: $clicker,join(', ',@inclass)).'</p>');
6129: }
6130: }
6131: }
6132: }
6133: }
1.243 albertel 6134: }
1.41 ng 6135: if (!exists($$classlist{"$username:$domain"})) {
1.247 albertel 6136: my $id=$entries{$fields{'ID'}};
6137: $id=~s/\s//g;
1.737 raeburn 6138: my $clicker = $entries{$fields{'clicker'}};
6139: $clicker=~s/\s//g;
6140: if ($clicker) {
6141: push(@skipped,"$clicker:$domain");
6142: } elsif ($id) {
1.247 albertel 6143: push(@skipped,"$id:$domain");
6144: } else {
6145: push(@skipped,"$username:$domain");
6146: }
1.41 ng 6147: next;
6148: }
1.108 albertel 6149: my $usec=$classlist->{"$username:$domain"}[5];
1.106 albertel 6150: if (!&canmodify($usec)) {
6151: push(@notallowed,"$username:$domain");
6152: next;
6153: }
1.244 albertel 6154: my %points;
1.41 ng 6155: my %grades;
6156: foreach my $dest (keys(%fields)) {
1.244 albertel 6157: if ($dest eq 'ID' || $dest eq 'username' ||
6158: $dest eq 'domain') { next; }
6159: if ($entries{$fields{$dest}} =~ /^\s*$/) { next; }
6160: if ($dest=~/stores_(.*)_points/) {
6161: my $part=$1;
6162: my $wgt =&Apache::lonnet::EXT('resource.'.$part.'.weight',
6163: $symb,$domain,$username);
1.798 raeburn 6164: $weights{$symb}{$part} = $wgt;
1.345 bowersj2 6165: if ($wgt) {
6166: $entries{$fields{$dest}}=~s/\s//g;
6167: my $pcr=$entries{$fields{$dest}} / $wgt;
1.798 raeburn 6168: if ($passback) {
6169: $awardeds{$symb}{$part} = $pcr;
6170: $excuseds{$symb}{$part} = '';
6171: }
1.463 albertel 6172: my $award=($pcr == 0) ? 'incorrect_by_override'
6173: : 'correct_by_override';
1.638 www 6174: if ($pcr>1) {
1.657 raeburn 6175: push(@warnings,&mt("[_1]: point value larger than weight","$username:$domain"));
1.638 www 6176: }
1.345 bowersj2 6177: $grades{"resource.$part.awarded"}=$pcr;
6178: $grades{"resource.$part.solved"}=$award;
6179: $points{$part}=1;
6180: } else {
6181: $error_msg = "<br />" .
6182: &mt("Some point values were assigned"
6183: ." for problems with a weight "
6184: ."of zero. These values were "
6185: ."ignored.");
6186: }
1.244 albertel 6187: } else {
6188: if ($dest=~/stores_(.*)_awarded/) { if ($points{$1}) {next;} }
6189: if ($dest=~/stores_(.*)_solved/) { if ($points{$1}) {next;} }
6190: my $store_key=$dest;
1.798 raeburn 6191: if ($passback) {
6192: if ($store_key=~/stores_(.*)_(awarded|solved)/) {
6193: my ($part,$key) = ($1,$2);
6194: unless ((ref($weights{$symb}) eq 'HASH') && (exists($weights{$symb}{$part}))) {
6195: $weights{$symb}{$part} = &Apache::lonnet::EXT('resource.'.$part.'.weight',
6196: $symb,$domain,$username);
6197: }
6198: if ($key eq 'awarded') {
6199: $awardeds{$symb}{$part} = $entries{$fields{$dest}};
6200: } elsif ($key eq 'solved') {
6201: if ($entries{$fields{$dest}} =~ /^excused/) {
6202: $excuseds{$symb}{$part} = 1;
6203: }
6204: }
6205: }
6206: }
1.244 albertel 6207: $store_key=~s/^stores/resource/;
6208: $store_key=~s/_/\./g;
6209: $grades{$store_key}=$entries{$fields{$dest}};
6210: }
1.41 ng 6211: }
1.766 raeburn 6212: if (! %grades) {
1.508 www 6213: push(@skipped,&mt("[_1]: no data to save","$username:$domain"));
6214: } else {
6215: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
6216: my $result=&Apache::lonnet::cstore(\%grades,$symb,
1.302 albertel 6217: $env{'request.course.id'},
6218: $domain,$username);
1.508 www 6219: if ($result eq 'ok') {
1.627 www 6220: # Successfully stored
1.508 www 6221: $request->print('.');
1.627 www 6222: # Remove from grading queue
1.798 raeburn 6223: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,$cnum,
1.801 raeburn 6224: $domain,$username);
1.627 www 6225: $countdone++;
1.798 raeburn 6226: if ($passback) {
6227: my @parts_in_upload;
6228: if (ref($weights{$symb}) eq 'HASH') {
6229: @parts_in_upload = sort(keys(%{$weights{$symb}}));
6230: }
6231: my @diffs = &Apache::loncommon::compare_arrays(\@parts_in_upload,\@parts);
6232: if (@diffs > 0) {
6233: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$username);
6234: foreach my $part (@parts) {
6235: next if (grep(/^\Q$part\E$/,@parts_in_upload));
6236: $weights{$symb}{$part} = &Apache::lonnet::EXT('resource.'.$part.'.weight',
6237: $symb,$domain,$username);
6238: if ($record{"resource.$part.solved"} =~/^excused/) {
6239: $excuseds{$symb}{$part} = 1;
6240: } else {
6241: $excuseds{$symb}{$part} = '';
6242: }
6243: $awardeds{$symb}{$part} = $record{"resource.$part.awarded"};
6244: }
6245: }
1.802 raeburn 6246: &process_passbacks('csvupload',[$symb],$cdom,$cnum,$domain,$username,$usec,\%weights,
1.798 raeburn 6247: \%awardeds,\%excuseds,\%needpb,\%skip_passback,\%pbsave);
6248: }
1.627 www 6249: } else {
1.508 www 6250: $request->print("<p><span class=\"LC_error\">".
6251: &mt("Failed to save data for student [_1]. Message when trying to save was: [_2]",
6252: "$username:$domain",$result)."</span></p>");
6253: }
6254: $request->rflush();
6255: }
1.41 ng 6256: }
1.570 www 6257: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt("Saved scores for [quant,_1,student]",$countdone),$countdone==0));
1.657 raeburn 6258: if (@warnings) {
6259: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('Warnings generated for the following saved scores:'),1).'<br />');
6260: $request->print(join(', ',@warnings));
6261: }
1.41 ng 6262: if (@skipped) {
1.571 www 6263: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('No scores stored for the following username(s):'),1).'<br />');
6264: $request->print(join(', ',@skipped));
1.106 albertel 6265: }
6266: if (@notallowed) {
1.571 www 6267: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('Modification of scores not allowed for the following username(s):'),1).'<br />');
6268: $request->print(join(', ',@notallowed));
1.41 ng 6269: }
1.106 albertel 6270: $request->print("<br />\n");
1.345 bowersj2 6271: return $error_msg;
1.26 albertel 6272: }
1.44 ng 6273: #------------- end of section for handling csv file upload ---------
6274: #
6275: #-------------------------------------------------------------------
6276: #
1.122 ng 6277: #-------------- Next few routines handle grading by page/sequence
1.72 ng 6278: #
6279: #--- Select a page/sequence and a student to grade
1.68 ng 6280: sub pickStudentPage {
1.608 www 6281: my ($request,$symb) = @_;
1.68 ng 6282:
1.539 riegler 6283: my $alertmsg = &mt('Please select the student you wish to grade.');
1.736 damieng 6284: &js_escape(\$alertmsg);
1.597 wenzelju 6285: $request->print(&Apache::lonhtmlcommon::scripttag(<<LISTJAVASCRIPT));
1.68 ng 6286:
6287: function checkPickOne(formname) {
1.76 ng 6288: if (radioSelection(formname.student) == null) {
1.539 riegler 6289: alert("$alertmsg");
1.68 ng 6290: return;
6291: }
1.125 ng 6292: ptr = pullDownSelection(formname.selectpage);
6293: formname.page.value = formname["page"+ptr].value;
6294: formname.title.value = formname["title"+ptr].value;
1.68 ng 6295: formname.submit();
6296: }
6297:
6298: LISTJAVASCRIPT
1.118 ng 6299: &commonJSfunctions($request);
1.608 www 6300:
1.257 albertel 6301: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
6302: my $cnum = $env{"course.$env{'request.course.id'}.num"};
6303: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.761 raeburn 6304: my $getgroup = $env{'form.group'} eq '' ? 'all' : $env{'form.group'};
1.68 ng 6305:
1.398 albertel 6306: my $result='<h3><span class="LC_info"> '.
1.485 albertel 6307: &mt('Manual Grading by Page or Sequence').'</span></h3>';
1.68 ng 6308:
1.80 ng 6309: $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
1.582 raeburn 6310: my $map_error;
6311: my ($titles,$symbx) = &getSymbMap($map_error);
6312: if ($map_error) {
6313: $request->print(&navmap_errormsg());
6314: return;
6315: }
1.137 albertel 6316: my ($curpage) =&Apache::lonnet::decode_symb($symb);
6317: # my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb);
6318: # my $type=($curpage =~ /\.(page|sequence)/);
1.700 bisitz 6319:
6320: # Collection of hidden fields
1.70 ng 6321: my $ctr=0;
1.68 ng 6322: foreach (@$titles) {
1.700 bisitz 6323: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
6324: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
6325: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
6326: $ctr++;
1.68 ng 6327: }
1.700 bisitz 6328: $result.='<input type="hidden" name="page" />'."\n".
6329: '<input type="hidden" name="title" />'."\n";
6330:
6331: $result.=&build_section_inputs();
6332: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
6333: $result.='<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
6334: '<input type="hidden" name="command" value="displayPage" />'."\n".
6335: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.485 albertel 6336:
1.700 bisitz 6337: # Show grading options
6338: $result.=&Apache::lonhtmlcommon::start_pick_box();
6339: my $select = '<select name="selectpage">'."\n";
1.70 ng 6340: $ctr=0;
6341: foreach (@$titles) {
6342: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.700 bisitz 6343: $select.='<option value="'.$ctr.'"'.
6344: ($$symbx{$_} =~ /$curpage$/ ? ' selected="selected"' : '').
6345: '>'.$showtitle.'</option>'."\n";
1.70 ng 6346: $ctr++;
6347: }
1.700 bisitz 6348: $select.= '</select>';
1.68 ng 6349:
1.700 bisitz 6350: $result.=
6351: &Apache::lonhtmlcommon::row_title(&mt('Problems from'))
6352: .$select
6353: .&Apache::lonhtmlcommon::row_closure();
6354:
6355: $result.=
6356: &Apache::lonhtmlcommon::row_title(&mt('View Problem Text'))
6357: .'<label><input type="radio" name="vProb" value="no"'
6358: .' checked="checked" /> '.&mt('no').' </label>'."\n"
6359: .'<label><input type="radio" name="vProb" value="yes" />'
6360: .&mt('yes').'</label>'."\n"
6361: .&Apache::lonhtmlcommon::row_closure();
6362:
6363: $result.=
6364: &Apache::lonhtmlcommon::row_title(&mt('View Submissions'))
6365: .'<label><input type="radio" name="lastSub" value="none" /> '
6366: .&mt('none').' </label>'."\n"
6367: .'<label><input type="radio" name="lastSub" value="datesub"'
6368: .' checked="checked" /> '.&mt('all submissions').'</label>'."\n"
6369: .'<label><input type="radio" name="lastSub" value="all" /> '
6370: .&mt('all submissions with details').' </label>'
6371: .&Apache::lonhtmlcommon::row_closure();
1.432 banghart 6372:
1.700 bisitz 6373: $result.=
6374: &Apache::lonhtmlcommon::row_title(&mt('Use CODE'))
6375: .'<input type="text" name="CODE" value="" />'
6376: .&Apache::lonhtmlcommon::row_closure(1)
6377: .&Apache::lonhtmlcommon::end_pick_box();
1.382 albertel 6378:
1.700 bisitz 6379: # Show list of students to select for grading
6380: $result.='<br /><input type="button" '.
1.589 bisitz 6381: 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /><br />'."\n";
1.72 ng 6382:
1.68 ng 6383: $request->print($result);
6384:
1.485 albertel 6385: my $studentTable.=' <b>'.&mt('Select a student you wish to grade and then click on the Next button.').'</b><br />'.
1.484 albertel 6386: &Apache::loncommon::start_data_table().
6387: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 6388: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 6389: '<th>'.&nameUserString('header').'</th>'.
1.485 albertel 6390: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 6391: '<th>'.&nameUserString('header').'</th>'.
6392: &Apache::loncommon::end_data_table_header_row();
1.68 ng 6393:
1.761 raeburn 6394: my (undef,undef,$fullname) = &getclasslist($getsec,'1',$getgroup);
1.68 ng 6395: my $ptr = 1;
1.294 albertel 6396: foreach my $student (sort
6397: {
6398: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
6399: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
6400: }
6401: return $a cmp $b;
6402: } (keys(%$fullname))) {
1.68 ng 6403: my ($uname,$udom) = split(/:/,$student);
1.484 albertel 6404: $studentTable.=($ptr%2==1 ? &Apache::loncommon::start_data_table_row()
6405: : '</td>');
1.126 ng 6406: $studentTable.='<td align="right">'.$ptr.' </td>';
1.288 albertel 6407: $studentTable.='<td> <label><input type="radio" name="student" value="'.$student.'" /> '
6408: .&nameUserString(undef,$$fullname{$student},$uname,$udom)."</label>\n";
1.484 albertel 6409: $studentTable.=
6410: ($ptr%2 == 0 ? '</td>'.&Apache::loncommon::end_data_table_row()
6411: : '');
1.68 ng 6412: $ptr++;
6413: }
1.484 albertel 6414: if ($ptr%2 == 0) {
6415: $studentTable.='</td><td> </td><td> </td>'.
6416: &Apache::loncommon::end_data_table_row();
6417: }
6418: $studentTable.=&Apache::loncommon::end_data_table()."\n";
1.126 ng 6419: $studentTable.='<input type="button" '.
1.589 bisitz 6420: 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /></form>'."\n";
1.68 ng 6421:
6422: $request->print($studentTable);
6423:
6424: return '';
6425: }
6426:
6427: sub getSymbMap {
1.582 raeburn 6428: my ($map_error) = @_;
1.132 bowersj2 6429: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 6430: unless (ref($navmap)) {
6431: if (ref($map_error)) {
6432: $$map_error = 'navmap';
6433: }
6434: return;
6435: }
1.68 ng 6436: my %symbx = ();
6437: my @titles = ();
1.117 bowersj2 6438: my $minder = 0;
6439:
6440: # Gather every sequence that has problems.
1.240 albertel 6441: my @sequences = $navmap->retrieveResources(undef, sub { shift->is_map(); },
6442: 1,0,1);
1.117 bowersj2 6443: for my $sequence ($navmap->getById('0.0'), @sequences) {
1.745 raeburn 6444: if ($navmap->hasResource($sequence, sub { shift->is_gradable(); }, 0) ) {
1.381 albertel 6445: my $title = $minder.'.'.
6446: &HTML::Entities::encode($sequence->compTitle(),'"\'&');
6447: push(@titles, $title); # minder in case two titles are identical
6448: $symbx{$title} = &HTML::Entities::encode($sequence->symb(),'"\'&');
1.117 bowersj2 6449: $minder++;
1.241 albertel 6450: }
1.68 ng 6451: }
6452: return \@titles,\%symbx;
6453: }
6454:
1.72 ng 6455: #
6456: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68 ng 6457: sub displayPage {
1.608 www 6458: my ($request,$symb) = @_;
1.257 albertel 6459: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
6460: my $cnum = $env{"course.$env{'request.course.id'}.num"};
6461: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
6462: my $pageTitle = $env{'form.page'};
1.103 albertel 6463: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 6464: my ($uname,$udom) = split(/:/,$env{'form.student'});
6465: my $usec=$classlist->{$env{'form.student'}}[5];
1.168 albertel 6466:
6467: #need to make sure we have the correct data for later EXT calls,
6468: #thus invalidate the cache
6469: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 6470: $env{'course.'.$env{'request.course.id'}.'.num'},
6471: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 6472: &Apache::lonnet::clear_EXT_cache_status();
6473:
1.103 albertel 6474: if (!&canview($usec)) {
1.712 bisitz 6475: $request->print(
6476: '<span class="LC_warning">'.
6477: &mt('Unable to view requested student. ([_1])',
6478: $env{'form.student'}).
6479: '</span>');
6480: return;
1.103 albertel 6481: }
1.398 albertel 6482: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.485 albertel 6483: $result.='<h3> '.&mt('Student: [_1]',&nameUserString(undef,$$fullname{$env{'form.student'}},$uname,$udom)).
1.129 ng 6484: '</h3>'."\n";
1.500 albertel 6485: $env{'form.CODE'} = uc($env{'form.CODE'});
1.501 foxr 6486: if (&Apache::lonnet::validCODE(uc($env{'form.CODE'}))) {
1.485 albertel 6487: $result.='<h3> '.&mt('CODE: [_1]',$env{'form.CODE'}).'</h3>'."\n";
1.382 albertel 6488: } else {
6489: delete($env{'form.CODE'});
6490: }
1.71 ng 6491: &sub_page_js($request);
6492: $request->print($result);
6493:
1.132 bowersj2 6494: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 6495: unless (ref($navmap)) {
6496: $request->print(&navmap_errormsg());
6497: return;
6498: }
1.257 albertel 6499: my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($env{'form.page'});
1.68 ng 6500: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 6501: if (!$map) {
1.485 albertel 6502: $request->print('<span class="LC_warning">'.&mt('Unable to view requested sequence. ([_1])',$resUrl).'</span>');
1.288 albertel 6503: return;
6504: }
1.68 ng 6505: my $iterator = $navmap->getIterator($map->map_start(),
6506: $map->map_finish());
6507:
1.71 ng 6508: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72 ng 6509: '<input type="hidden" name="command" value="gradeByPage" />'."\n".
1.257 albertel 6510: '<input type="hidden" name="fullname" value="'.$$fullname{$env{'form.student'}}.'" />'."\n".
6511: '<input type="hidden" name="student" value="'.$env{'form.student'}.'" />'."\n".
1.72 ng 6512: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
1.257 albertel 6513: '<input type="hidden" name="title" value="'.$env{'form.title'}.'" />'."\n".
1.418 albertel 6514: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.613 www 6515: '<input type="hidden" name="overRideScore" value="no" />'."\n";
1.71 ng 6516:
1.382 albertel 6517: if (defined($env{'form.CODE'})) {
6518: $studentTable.=
6519: '<input type="hidden" name="CODE" value="'.$env{'form.CODE'}.'" />'."\n";
6520: }
1.381 albertel 6521: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 6522: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 6523:
1.594 bisitz 6524: $studentTable.=' <span class="LC_info">'.
6525: &mt('Problems graded correct by the computer are marked with a [_1] symbol.',$checkIcon).
6526: '</span>'."\n".
1.484 albertel 6527: &Apache::loncommon::start_data_table().
6528: &Apache::loncommon::start_data_table_header_row().
1.700 bisitz 6529: '<th>'.&mt('Prob.').'</th>'.
1.485 albertel 6530: '<th> '.($env{'form.vProb'} eq 'no' ? &mt('Title') : &mt('Problem Text')).'/'.&mt('Grade').'</th>'.
1.484 albertel 6531: &Apache::loncommon::end_data_table_header_row();
1.71 ng 6532:
1.329 albertel 6533: &Apache::lonxml::clear_problem_counter();
1.196 albertel 6534: my ($depth,$question,$prob) = (1,1,1);
1.68 ng 6535: $iterator->next(); # skip the first BEGIN_MAP
6536: my $curRes = $iterator->next(); # for "current resource"
1.101 albertel 6537: while ($depth > 0) {
1.68 ng 6538: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 6539: if($curRes == $iterator->END_MAP) { $depth--; }
1.68 ng 6540:
1.745 raeburn 6541: if (ref($curRes) && $curRes->is_gradable()) {
1.91 albertel 6542: my $parts = $curRes->parts();
1.68 ng 6543: my $title = $curRes->compTitle();
1.71 ng 6544: my $symbx = $curRes->symb();
1.746 raeburn 6545: my $is_tool = ($symbx =~ /ext\.tool$/);
1.484 albertel 6546: $studentTable.=
6547: &Apache::loncommon::start_data_table_row().
6548: '<td align="center" valign="top" >'.$prob.
1.485 albertel 6549: (scalar(@{$parts}) == 1 ? ''
1.681 raeburn 6550: : '<br />('.&mt('[_1]parts',
6551: scalar(@{$parts}).' ').')'
1.485 albertel 6552: ).
6553: '</td>';
1.71 ng 6554: $studentTable.='<td valign="top">';
1.382 albertel 6555: my %form = ('CODE' => $env{'form.CODE'},);
1.749 raeburn 6556: if ($is_tool) {
6557: $studentTable.=' <b>'.$title.'</b><br />';
6558: } else {
1.745 raeburn 6559: if ($env{'form.vProb'} eq 'yes' ) {
6560: $studentTable.=&show_problem($request,$symbx,$uname,$udom,1,
6561: undef,'both',\%form);
6562: } else {
6563: my $companswer = &Apache::loncommon::get_student_answers($symbx,$uname,$udom,$env{'request.course.id'},%form);
6564: $companswer =~ s|<form(.*?)>||g;
6565: $companswer =~ s|</form>||g;
6566: # while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
6567: # $companswer =~ s/$1/ /ms;
6568: # $request->print('match='.$1."<br />\n");
6569: # }
6570: # $companswer =~ s|<table border=\"1\">|<table border=\"0\">|g;
6571: $studentTable.=' <b>'.$title.'</b> <br /> <b>'.&mt('Correct answer').':</b><br />'.$companswer;
6572: }
1.71 ng 6573: }
6574:
1.257 albertel 6575: my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
1.125 ng 6576:
1.257 albertel 6577: if ($env{'form.lastSub'} eq 'datesub') {
1.71 ng 6578: if ($record{'version'} eq '') {
1.745 raeburn 6579: my $msg = &mt('No recorded submission for this problem.');
6580: if ($is_tool) {
6581: $msg = &mt('No recorded transactions for this external tool');
6582: }
6583: $studentTable.='<br /> <span class="LC_warning">'.$msg.'</span><br />';
1.71 ng 6584: } else {
1.116 ng 6585: my %responseType = ();
6586: foreach my $partid (@{$parts}) {
1.147 albertel 6587: my @responseIds =$curRes->responseIds($partid);
6588: my @responseType =$curRes->responseType($partid);
6589: my %responseIds;
6590: for (my $i=0;$i<=$#responseIds;$i++) {
6591: $responseIds{$responseIds[$i]}=$responseType[$i];
6592: }
6593: $responseType{$partid} = \%responseIds;
1.116 ng 6594: }
1.148 albertel 6595: $studentTable.= &displaySubByDates($symbx,\%record,$parts,\%responseType,$checkIcon,$uname,$udom);
1.71 ng 6596: }
1.257 albertel 6597: } elsif ($env{'form.lastSub'} eq 'all') {
6598: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.726 raeburn 6599: my $identifier = (&canmodify($usec)? $prob : '');
1.71 ng 6600: $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
1.257 albertel 6601: $env{'request.course.id'},
1.726 raeburn 6602: '','.submission',undef,
6603: $usec,$identifier);
1.71 ng 6604:
6605: }
1.103 albertel 6606: if (&canmodify($usec)) {
1.585 bisitz 6607: $studentTable.=&gradeBox_start();
1.103 albertel 6608: foreach my $partid (@{$parts}) {
6609: $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
6610: $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
6611: $question++;
6612: }
1.585 bisitz 6613: $studentTable.=&gradeBox_end();
1.196 albertel 6614: $prob++;
1.71 ng 6615: }
6616: $studentTable.='</td></tr>';
1.68 ng 6617:
1.103 albertel 6618: }
1.68 ng 6619: $curRes = $iterator->next();
6620: }
1.780 raeburn 6621: my $disabled;
6622: unless (&canmodify($usec)) {
6623: $disabled = ' disabled="disabled"';
6624: }
1.68 ng 6625:
1.589 bisitz 6626: $studentTable.=
6627: '</table>'."\n".
1.780 raeburn 6628: '<input type="button" value="'.&mt('Save').'"'.$disabled.' '.
1.589 bisitz 6629: 'onclick="javascript:checkSubmitPage(this.form,'.$question.');" />'.
6630: '</form>'."\n";
1.71 ng 6631: $request->print($studentTable);
6632:
6633: return '';
1.119 ng 6634: }
6635:
6636: sub displaySubByDates {
1.148 albertel 6637: my ($symb,$record,$parts,$responseType,$checkIcon,$uname,$udom) = @_;
1.224 albertel 6638: my $isCODE=0;
1.335 albertel 6639: my $isTask = ($symb =~/\.task$/);
1.747 raeburn 6640: my $is_tool = ($symb =~/\.tool$/);
1.224 albertel 6641: if (exists($record->{'resource.CODE'})) { $isCODE=1; }
1.467 albertel 6642: my $studentTable=&Apache::loncommon::start_data_table().
6643: &Apache::loncommon::start_data_table_header_row().
6644: '<th>'.&mt('Date/Time').'</th>'.
6645: ($isCODE?'<th>'.&mt('CODE').'</th>':'').
1.671 raeburn 6646: ($isTask?'<th>'.&mt('Version').'</th>':'').
1.749 raeburn 6647: '<th>'.($is_tool?&mt('Grade'):&mt('Submission')).'</th>'.
1.467 albertel 6648: '<th>'.&mt('Status').'</th>'.
6649: &Apache::loncommon::end_data_table_header_row();
1.119 ng 6650: my ($version);
6651: my %mark;
1.148 albertel 6652: my %orders;
1.119 ng 6653: $mark{'correct_by_student'} = $checkIcon;
1.147 albertel 6654: if (!exists($$record{'1:timestamp'})) {
1.747 raeburn 6655: if ($is_tool) {
6656: return '<br /> <span class="LC_warning">'.&mt('No grade passed back.').'</span><br />';
6657: } else {
6658: return '<br /> <span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br />';
6659: }
1.147 albertel 6660: }
1.335 albertel 6661:
6662: my $interaction;
1.525 raeburn 6663: my $no_increment = 1;
1.735 raeburn 6664: my (%lastrndseed,%lasttype);
1.119 ng 6665: for ($version=1;$version<=$$record{'version'};$version++) {
1.467 albertel 6666: my $timestamp =
6667: &Apache::lonlocal::locallocaltime($$record{$version.':timestamp'});
1.335 albertel 6668: if (exists($$record{$version.':resource.0.version'})) {
6669: $interaction = $$record{$version.':resource.0.version'};
6670: }
1.671 raeburn 6671: if ($isTask && $env{'form.previousversion'}) {
6672: next unless ($interaction == $env{'form.previousversion'});
6673: }
1.335 albertel 6674: my $where = ($isTask ? "$version:resource.$interaction"
6675: : "$version:resource");
1.467 albertel 6676: $studentTable.=&Apache::loncommon::start_data_table_row().
6677: '<td>'.$timestamp.'</td>';
1.224 albertel 6678: if ($isCODE) {
6679: $studentTable.='<td>'.$record->{$version.':resource.CODE'}.'</td>';
6680: }
1.671 raeburn 6681: if ($isTask) {
6682: $studentTable.='<td>'.$interaction.'</td>';
6683: }
1.119 ng 6684: my @versionKeys = split(/\:/,$$record{$version.':keys'});
6685: my @displaySub = ();
6686: foreach my $partid (@{$parts}) {
1.640 raeburn 6687: my ($hidden,$type);
6688: $type = $$record{$version.':resource.'.$partid.'.type'};
6689: if (($type eq 'anonsurvey') || ($type eq 'anonsurveycred')) {
1.596 raeburn 6690: $hidden = 1;
6691: }
1.749 raeburn 6692: my @matchKey;
6693: if ($isTask) {
1.769 raeburn 6694: @matchKey = sort(grep(/^resource\.\d+\.\Q$partid\E\.award$/,@versionKeys));
1.749 raeburn 6695: } elsif ($is_tool) {
1.769 raeburn 6696: @matchKey = sort(grep(/^resource\.\Q$partid\E\.awarded$/,@versionKeys));
1.749 raeburn 6697: } else {
1.769 raeburn 6698: @matchKey = sort(grep(/^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys));
1.749 raeburn 6699: }
1.122 ng 6700: # next if ($$record{"$version:resource.$partid.solved"} eq '');
1.324 albertel 6701: my $display_part=&get_display_part($partid,$symb);
1.147 albertel 6702: foreach my $matchKey (@matchKey) {
1.198 albertel 6703: if (exists($$record{$version.':'.$matchKey}) &&
6704: $$record{$version.':'.$matchKey} ne '') {
1.749 raeburn 6705: if ($is_tool) {
6706: $displaySub[0].=$$record{"$version:resource.$partid.awarded"};
1.596 raeburn 6707: } else {
1.749 raeburn 6708: my ($responseId)= ($isTask ? ($matchKey=~ /^resource\.(.*?)\.\Q$partid\E\.award$/)
6709: : ($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/));
6710: $displaySub[0].='<span class="LC_nobreak">';
6711: $displaySub[0].='<b>'.&mt('Part: [_1]',$display_part).'</b>'
6712: .' <span class="LC_internal_info">'
6713: .'('.&mt('Response ID: [_1]',$responseId).')'
6714: .'</span>'
6715: .' <b>';
6716: if ($hidden) {
6717: $displaySub[0].= &mt('Anonymous Survey').'</b>';
6718: } else {
6719: my ($trial,$rndseed,$newvariation);
6720: if ($type eq 'randomizetry') {
6721: $trial = $$record{"$where.$partid.tries"};
6722: $rndseed = $$record{"$where.$partid.rndseed"};
6723: }
6724: if ($$record{"$where.$partid.tries"} eq '') {
6725: $displaySub[0].=&mt('Trial not counted');
6726: } else {
6727: $displaySub[0].=&mt('Trial: [_1]',
6728: $$record{"$where.$partid.tries"});
6729: if (($rndseed ne '') && ($lastrndseed{$partid} ne '')) {
6730: if (($rndseed ne $lastrndseed{$partid}) &&
6731: (($type eq 'randomizetry') || ($lasttype{$partid} eq 'randomizetry'))) {
6732: $newvariation = ' ('.&mt('New variation this try').')';
6733: }
1.640 raeburn 6734: }
1.749 raeburn 6735: $lastrndseed{$partid} = $rndseed;
6736: $lasttype{$partid} = $type;
6737: }
6738: my $responseType=($isTask ? 'Task'
1.335 albertel 6739: : $responseType->{$partid}->{$responseId});
1.749 raeburn 6740: if (!exists($orders{$partid})) { $orders{$partid}={}; }
6741: if ((!exists($orders{$partid}->{$responseId})) || ($trial)) {
6742: $orders{$partid}->{$responseId}=
6743: &get_order($partid,$responseId,$symb,$uname,$udom,
6744: $no_increment,$type,$trial,$rndseed);
6745: }
6746: $displaySub[0].='</b>'.$newvariation.'</span>'; # /nobreak
6747: $displaySub[0].=' '.
6748: &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:",$uname,$udom,$type,$trial,$rndseed).'<br />';
6749: }
1.596 raeburn 6750: }
1.147 albertel 6751: }
6752: }
1.335 albertel 6753: if (exists($$record{"$where.$partid.checkedin"})) {
1.485 albertel 6754: $displaySub[1].=&mt('Checked in by [_1] into slot [_2]',
6755: $$record{"$where.$partid.checkedin"},
6756: $$record{"$where.$partid.checkedin.slot"}).
6757: '<br />';
1.335 albertel 6758: }
6759: if (exists $$record{"$where.$partid.award"}) {
1.485 albertel 6760: $displaySub[1].='<b>'.&mt('Part:').'</b> '.$display_part.' '.
1.335 albertel 6761: lc($$record{"$where.$partid.award"}).' '.
6762: $mark{$$record{"$where.$partid.solved"}}.
1.147 albertel 6763: '<br />';
1.749 raeburn 6764: } elsif (($is_tool) && (exists($$record{"$version:resource.$partid.solved"}))) {
6765: if ($$record{"$version:resource.$partid.solved"} =~ /^(in|)correct_by_passback$/) {
6766: $displaySub[1].=&mt('Grade passed back by external tool');
6767: }
1.147 albertel 6768: }
1.335 albertel 6769: if (exists $$record{"$where.$partid.regrader"}) {
1.749 raeburn 6770: $displaySub[2].=$$record{"$where.$partid.regrader"};
6771: unless ($is_tool) {
6772: $displaySub[2].=' (<b>'.&mt('Part').':</b> '.$display_part.')';
6773: }
1.335 albertel 6774: } elsif ($$record{"$version:resource.$partid.regrader"} =~ /\S/) {
6775: $displaySub[2].=
1.749 raeburn 6776: $$record{"$version:resource.$partid.regrader"};
6777: unless ($is_tool) {
6778: $displaySub[2].=' (<b>'.&mt('Part').':</b> '.$display_part.')';
6779: }
1.147 albertel 6780: }
6781: }
6782: # needed because old essay regrader has not parts info
6783: if (exists $$record{"$version:resource.regrader"}) {
6784: $displaySub[2].=$$record{"$version:resource.regrader"};
6785: }
6786: $studentTable.='<td>'.$displaySub[0].' </td><td>'.$displaySub[1];
6787: if ($displaySub[2]) {
1.467 albertel 6788: $studentTable.=&mt('Manually graded by [_1]',$displaySub[2]);
1.147 albertel 6789: }
1.467 albertel 6790: $studentTable.=' </td>'.
6791: &Apache::loncommon::end_data_table_row();
1.119 ng 6792: }
1.467 albertel 6793: $studentTable.=&Apache::loncommon::end_data_table();
1.119 ng 6794: return $studentTable;
1.71 ng 6795: }
6796:
6797: sub updateGradeByPage {
1.608 www 6798: my ($request,$symb) = @_;
1.71 ng 6799:
1.257 albertel 6800: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
6801: my $cnum = $env{"course.$env{'request.course.id'}.num"};
6802: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
6803: my $pageTitle = $env{'form.page'};
1.103 albertel 6804: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 6805: my ($uname,$udom) = split(/:/,$env{'form.student'});
6806: my $usec=$classlist->{$env{'form.student'}}[5];
1.103 albertel 6807: if (!&canmodify($usec)) {
1.526 raeburn 6808: $request->print('<span class="LC_warning">'.&mt('Unable to modify requested student ([_1])',$env{'form.student'}).'</span>');
1.103 albertel 6809: return;
6810: }
1.398 albertel 6811: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.526 raeburn 6812: $result.='<h3> '.&mt('Student: ').&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
1.129 ng 6813: '</h3>'."\n";
1.70 ng 6814:
1.68 ng 6815: $request->print($result);
6816:
1.582 raeburn 6817:
1.132 bowersj2 6818: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 6819: unless (ref($navmap)) {
6820: $request->print(&navmap_errormsg());
6821: return;
6822: }
1.257 albertel 6823: my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $env{'form.page'});
1.71 ng 6824: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 6825: if (!$map) {
1.527 raeburn 6826: $request->print('<span class="LC_warning">'.&mt('Unable to grade requested sequence ([_1]).',$resUrl).'</span>');
1.288 albertel 6827: return;
6828: }
1.71 ng 6829: my $iterator = $navmap->getIterator($map->map_start(),
6830: $map->map_finish());
1.70 ng 6831:
1.484 albertel 6832: my $studentTable=
6833: &Apache::loncommon::start_data_table().
6834: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 6835: '<th align="center"> '.&mt('Prob.').' </th>'.
6836: '<th> '.&mt('Title').' </th>'.
6837: '<th> '.&mt('Previous Score').' </th>'.
6838: '<th> '.&mt('New Score').' </th>'.
1.484 albertel 6839: &Apache::loncommon::end_data_table_header_row();
1.71 ng 6840:
6841: $iterator->next(); # skip the first BEGIN_MAP
6842: my $curRes = $iterator->next(); # for "current resource"
1.726 raeburn 6843: my ($depth,$question,$prob,$changeflag,$hideflag)= (1,1,1,0,0);
1.798 raeburn 6844: my (@updates,%weights,%excuseds,%awardeds,@symbs_in_map);
1.101 albertel 6845: while ($depth > 0) {
1.71 ng 6846: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 6847: if($curRes == $iterator->END_MAP) { $depth--; }
1.71 ng 6848:
1.385 albertel 6849: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 6850: my $parts = $curRes->parts();
1.71 ng 6851: my $title = $curRes->compTitle();
6852: my $symbx = $curRes->symb();
1.798 raeburn 6853: push(@symbs_in_map,$symbx);
1.484 albertel 6854: $studentTable.=
6855: &Apache::loncommon::start_data_table_row().
6856: '<td align="center" valign="top" >'.$prob.
1.485 albertel 6857: (scalar(@{$parts}) == 1 ? ''
1.640 raeburn 6858: : '<br />('.&mt('[quant,_1,part]',scalar(@{$parts}))
1.526 raeburn 6859: .')').'</td>';
1.71 ng 6860: $studentTable.='<td valign="top"> <b>'.$title.'</b> </td>';
6861:
6862: my %newrecord=();
6863: my @displayPts=();
1.269 raeburn 6864: my %aggregate = ();
6865: my $aggregateflag = 0;
1.787 raeburn 6866: my %queueable;
1.726 raeburn 6867: if ($env{'form.HIDE'.$prob}) {
6868: my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
1.727 raeburn 6869: my ($version,$parts) = split(/:/,$env{'form.HIDE'.$prob},2);
1.728 raeburn 6870: my $numchgs = &makehidden($version,$parts,\%record,$symbx,$udom,$uname,1);
1.798 raeburn 6871: if ($numchgs) {
6872: push(@updates,$symbx);
6873: }
1.726 raeburn 6874: $hideflag += $numchgs;
6875: }
1.71 ng 6876: foreach my $partid (@{$parts}) {
1.257 albertel 6877: my $newpts = $env{'form.GD_BOX'.$question.'_'.$partid};
6878: my $oldpts = $env{'form.oldpts'.$question.'_'.$partid};
1.787 raeburn 6879: my @types = $curRes->responseType($partid);
1.786 raeburn 6880: if (grep(/^essay$/,@types)) {
6881: $queueable{$partid} = 1;
6882: } else {
1.787 raeburn 6883: my @ids = $curRes->responseIds($partid);
1.786 raeburn 6884: for (my $i=0; $i < scalar(@ids); $i++) {
1.787 raeburn 6885: my $hndgrd = &Apache::lonnet::EXT('resource.'.$partid.'_'.$ids[$i].
1.786 raeburn 6886: '.handgrade',$symb);
6887: if (lc($hndgrd) eq 'yes') {
6888: $queueable{$partid} = 1;
6889: last;
6890: }
6891: }
6892: }
1.257 albertel 6893: my $wgt = $env{'form.WGT'.$question.'_'.$partid} != 0 ?
6894: $env{'form.WGT'.$question.'_'.$partid} : 1;
1.798 raeburn 6895: $weights{$symbx}{$partid} = $wgt;
6896: $excuseds{$symbx}{$partid} = '';
1.71 ng 6897: my $partial = $newpts/$wgt;
6898: my $score;
6899: if ($partial > 0) {
6900: $score = 'correct_by_override';
1.125 ng 6901: } elsif ($newpts ne '') { #empty is taken as 0
1.71 ng 6902: $score = 'incorrect_by_override';
6903: }
1.257 albertel 6904: my $dropMenu = $env{'form.GD_SEL'.$question.'_'.$partid};
1.125 ng 6905: if ($dropMenu eq 'excused') {
1.71 ng 6906: $partial = '';
6907: $score = 'excused';
1.798 raeburn 6908: $excuseds{$symbx}{$partid} = 1;
1.125 ng 6909: } elsif ($dropMenu eq 'reset status'
1.257 albertel 6910: && $env{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
1.125 ng 6911: $newrecord{'resource.'.$partid.'.tries'} = 0;
6912: $newrecord{'resource.'.$partid.'.solved'} = '';
6913: $newrecord{'resource.'.$partid.'.award'} = '';
6914: $newrecord{'resource.'.$partid.'.awarded'} = 0;
1.257 albertel 6915: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 6916: $changeflag++;
6917: $newpts = '';
1.269 raeburn 6918:
6919: my $aggtries = $env{'form.aggtries'.$question.'_'.$partid};
6920: my $totaltries = $env{'form.totaltries'.$question.'_'.$partid};
6921: my $solvedstatus = $env{'form.solved'.$question.'_'.$partid};
6922: if ($aggtries > 0) {
6923: &decrement_aggs($symbx,$partid,\%aggregate,$aggtries,$totaltries,$solvedstatus);
6924: $aggregateflag = 1;
6925: }
1.71 ng 6926: }
1.324 albertel 6927: my $display_part=&get_display_part($partid,$curRes->symb());
1.257 albertel 6928: my $oldstatus = $env{'form.solved'.$question.'_'.$partid};
1.526 raeburn 6929: $displayPts[0].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.71 ng 6930: (($oldstatus eq 'excused') ? 'excused' : $oldpts).
1.326 albertel 6931: ' <br />';
1.526 raeburn 6932: $displayPts[1].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.125 ng 6933: (($score eq 'excused') ? 'excused' : $newpts).
1.326 albertel 6934: ' <br />';
1.71 ng 6935: $question++;
1.798 raeburn 6936: if (($newpts eq '') || ($partial eq '')) {
6937: $awardeds{$symbx}{$partid} = 0;
6938: } else {
6939: $awardeds{$symbx}{$partid} = $partial;
6940: }
1.380 albertel 6941: next if ($dropMenu eq 'reset status' || ($newpts eq $oldpts && $score ne 'excused'));
1.125 ng 6942:
1.71 ng 6943: $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
1.125 ng 6944: $newrecord{'resource.'.$partid.'.solved'} = $score if $score ne '';
1.257 albertel 6945: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}"
1.125 ng 6946: if (scalar(keys(%newrecord)) > 0);
1.71 ng 6947:
6948: $changeflag++;
6949: }
6950: if (scalar(keys(%newrecord)) > 0) {
1.382 albertel 6951: my %record =
6952: &Apache::lonnet::restore($symbx,$env{'request.course.id'},
6953: $udom,$uname);
6954:
6955: if (&Apache::lonnet::validCODE($env{'form.CODE'})) {
6956: $newrecord{'resource.CODE'} = $env{'form.CODE'};
6957: } elsif (&Apache::lonnet::validCODE($record{'resource.CODE'})) {
6958: $newrecord{'resource.CODE'} = '';
6959: }
1.257 albertel 6960: &Apache::lonnet::cstore(\%newrecord,$symbx,$env{'request.course.id'},
1.71 ng 6961: $udom,$uname);
1.382 albertel 6962: %record = &Apache::lonnet::restore($symbx,
6963: $env{'request.course.id'},
6964: $udom,$uname);
1.380 albertel 6965: &check_and_remove_from_queue($parts,\%record,undef,$symbx,
1.786 raeburn 6966: $cdom,$cnum,$udom,$uname,\%queueable);
1.71 ng 6967: }
1.380 albertel 6968:
1.269 raeburn 6969: if ($aggregateflag) {
6970: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
6971: $env{'course.'.$env{'request.course.id'}.'.domain'},
6972: $env{'course.'.$env{'request.course.id'}.'.num'});
6973: }
1.125 ng 6974:
1.71 ng 6975: $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
6976: '<td valign="top">'.$displayPts[1].'</td>'.
1.484 albertel 6977: &Apache::loncommon::end_data_table_row();
1.68 ng 6978:
1.196 albertel 6979: $prob++;
1.798 raeburn 6980: if ($changeflag) {
6981: push(@updates,$symbx);
6982: }
1.68 ng 6983: }
1.71 ng 6984: $curRes = $iterator->next();
1.68 ng 6985: }
1.98 albertel 6986:
1.484 albertel 6987: $studentTable.=&Apache::loncommon::end_data_table();
1.526 raeburn 6988: my $grademsg=($changeflag == 0 ? &mt('No score was changed or updated.') :
6989: &mt('The scores were changed for [quant,_1,problem].',
1.726 raeburn 6990: $changeflag).'<br />');
6991: my $hidemsg=($hideflag == 0 ? '' :
6992: &mt('Submissions were marked "hidden" for [quant,_1,transaction].',
6993: $hideflag).'<br />');
6994: $request->print($hidemsg.$grademsg.$studentTable);
1.68 ng 6995:
1.798 raeburn 6996: if (@updates) {
6997: my (@allsymbs,$mapsymb,@recurseup,%parentmapsymbs,%possmappb,%possrespb);
6998: @allsymbs = @updates;
6999: if (ref($map)) {
7000: $mapsymb = $map->symb();
7001: push(@allsymbs,$mapsymb);
7002: @recurseup = $navmap->recurseup_maps($map->src,1);
7003: }
7004: if (@recurseup) {
7005: push(@allsymbs,@recurseup);
7006: map { $parentmapsymbs{$_} = 1; } @recurseup;
7007: }
7008: my %passback = &Apache::lonnet::get('nohist_linkprot_passback',\@allsymbs,$cdom,$cnum);
1.806 raeburn 7009: my (%uniqsymbs,$use_symbs_in_map,%launch_to_symb);
1.798 raeburn 7010: if (keys(%passback)) {
7011: foreach my $possible (keys(%passback)) {
7012: if (ref($passback{$possible}) eq 'HASH') {
7013: if ($possible eq $mapsymb) {
7014: foreach my $launcher (keys(%{$passback{$possible}})) {
7015: $possmappb{$launcher} = 1;
1.806 raeburn 7016: $launch_to_symb{$launcher} = $possible;
1.798 raeburn 7017: }
7018: $use_symbs_in_map = 1;
7019: } elsif (exists($parentmapsymbs{$possible})) {
7020: foreach my $launcher (keys(%{$passback{$possible}})) {
7021: my ($linkuri,$linkprotector,$scope) = split(/\0/,$launcher);
7022: if ($scope eq 'rec') {
7023: $possmappb{$launcher} = 1;
7024: $use_symbs_in_map = 1;
1.806 raeburn 7025: $launch_to_symb{$launcher} = $possible;
1.798 raeburn 7026: }
7027: }
7028: } elsif (grep(/^\Q$possible$\E$/,@updates)) {
7029: foreach my $launcher (keys(%{$passback{$possible}})) {
7030: $possrespb{$launcher} = 1;
1.806 raeburn 7031: $launch_to_symb{$launcher} = $possible;
1.798 raeburn 7032: }
7033: $uniqsymbs{$possible} = 1;
7034: }
7035: }
7036: }
7037: }
7038: if ($use_symbs_in_map) {
7039: map { $uniqsymbs{$_} = 1; } @symbs_in_map;
7040: }
7041: my @posslaunchers;
7042: if (keys(%possmappb)) {
7043: push(@posslaunchers,keys(%possmappb));
7044: }
7045: if (keys(%possrespb)) {
7046: push(@posslaunchers,keys(%possrespb));
7047: }
7048: if (@posslaunchers) {
7049: my (%pbsave,%skip_passback,%needpb);
7050: my %pbids = &Apache::lonnet::get('nohist_'.$cdom.'_'.$cnum.'_linkprot_pb',\@posslaunchers,$udom,$uname);
7051: foreach my $key (keys(%pbids)) {
7052: if (ref($pbids{$key}) eq 'ARRAY') {
1.806 raeburn 7053: if ($launch_to_symb{$key}) {
7054: $needpb{$key} = $launch_to_symb{$key};
7055: }
1.798 raeburn 7056: }
7057: }
7058: my @symbs = keys(%uniqsymbs);
1.802 raeburn 7059: &process_passbacks('updatebypage',\@symbs,$cdom,$cnum,$udom,$uname,$usec,\%weights,
1.798 raeburn 7060: \%awardeds,\%excuseds,\%needpb,\%skip_passback,\%pbsave,\%pbids);
1.801 raeburn 7061: if (@Apache::grades::ltipassback) {
1.798 raeburn 7062: unless ($registered_cleanup) {
7063: my $handlers = $request->get_handlers('PerlCleanupHandler');
7064: $request->set_handlers('PerlCleanupHandler' =>
1.801 raeburn 7065: [\&Apache::grades::make_passback,@{$handlers}]);
7066: $registered_cleanup=1;
1.798 raeburn 7067: }
7068: }
7069: }
7070: }
1.70 ng 7071: return '';
7072: }
7073:
1.801 raeburn 7074: sub make_passback {
7075: if (@Apache::grades::ltipassback) {
7076: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
7077: my $ip = &Apache::lonnet::get_host_ip($lonhost);
7078: foreach my $item (@Apache::grades::ltipassback) {
7079: &Apache::lonhomework::run_passback($item,$lonhost,$ip);
7080: }
7081: undef(@Apache::grades::ltipassback);
7082: }
7083: }
7084:
1.72 ng 7085: #-------- end of section for handling grading by page/sequence ---------
7086: #
7087: #-------------------------------------------------------------------
7088:
1.581 www 7089: #-------------------- Bubblesheet (Scantron) Grading -------------------
1.75 albertel 7090: #
7091: #------ start of section for handling grading by page/sequence ---------
7092:
1.423 albertel 7093: =pod
7094:
7095: =head1 Bubble sheet grading routines
7096:
1.424 albertel 7097: For this documentation:
7098:
7099: 'scanline' refers to the full line of characters
7100: from the file that we are parsing that represents one entire sheet
7101:
7102: 'bubble line' refers to the data
1.659 raeburn 7103: representing the line of bubbles that are on the physical bubblesheet
1.424 albertel 7104:
7105:
1.659 raeburn 7106: The overall process is that a scanned in bubblesheet data is uploaded
1.424 albertel 7107: into a course. When a user wants to grade, they select a
1.659 raeburn 7108: sequence/folder of resources, a file of bubblesheet info, and pick
1.424 albertel 7109: one of the predefined configurations for what each scanline looks
7110: like.
7111:
7112: Next each scanline is checked for any errors of either 'missing
1.435 foxr 7113: bubbles' (it's an error because it may have been mis-scanned
1.424 albertel 7114: because too light bubbling), 'double bubble' (each bubble line should
1.703 bisitz 7115: have no more than one letter picked), invalid or duplicated CODE,
1.556 weissno 7116: invalid student/employee ID
1.424 albertel 7117:
7118: If the CODE option is used that determines the randomization of the
1.556 weissno 7119: homework problems, either way the student/employee ID is looked up into a
1.424 albertel 7120: username:domain.
7121:
7122: During the validation phase the instructor can choose to skip scanlines.
7123:
1.659 raeburn 7124: After the validation phase, there are now 3 bubblesheet files
1.424 albertel 7125:
7126: scantron_original_filename (unmodified original file)
7127: scantron_corrected_filename (file where the corrected information has replaced the original information)
7128: scantron_skipped_filename (contains the exact text of scanlines that where skipped)
7129:
7130: Also there is a separate hash nohist_scantrondata that contains extra
1.659 raeburn 7131: correction information that isn't representable in the bubblesheet
1.424 albertel 7132: file (see &scantron_getfile() for more information)
7133:
7134: After all scanlines are either valid, marked as valid or skipped, then
7135: foreach line foreach problem in the picked sequence, an ssi request is
7136: made that simulates a user submitting their selected letter(s) against
7137: the homework problem.
1.423 albertel 7138:
7139: =over 4
7140:
7141:
7142:
7143: =item defaultFormData
7144:
7145: Returns html hidden inputs used to hold context/default values.
7146:
7147: Arguments:
7148: $symb - $symb of the current resource
7149:
7150: =cut
1.422 foxr 7151:
1.81 albertel 7152: sub defaultFormData {
1.324 albertel 7153: my ($symb)=@_;
1.766 raeburn 7154: return '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />';
1.81 albertel 7155: }
7156:
1.447 foxr 7157:
1.423 albertel 7158: =pod
7159:
7160: =item getSequenceDropDown
7161:
7162: Return html dropdown of possible sequences to grade
7163:
7164: Arguments:
1.582 raeburn 7165: $symb - $symb of the current resource
7166: $map_error - ref to scalar which will container error if
7167: $navmap object is unavailable in &getSymbMap().
1.423 albertel 7168:
7169: =cut
1.422 foxr 7170:
1.75 albertel 7171: sub getSequenceDropDown {
1.582 raeburn 7172: my ($symb,$map_error)=@_;
1.75 albertel 7173: my $result='<select name="selectpage">'."\n";
1.582 raeburn 7174: my ($titles,$symbx) = &getSymbMap($map_error);
7175: if (ref($map_error)) {
7176: return if ($$map_error);
7177: }
1.137 albertel 7178: my ($curpage)=&Apache::lonnet::decode_symb($symb);
1.75 albertel 7179: my $ctr=0;
7180: foreach (@$titles) {
7181: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
7182: $result.='<option value="'.$$symbx{$_}.'" '.
1.401 albertel 7183: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.75 albertel 7184: '>'.$showtitle.'</option>'."\n";
7185: $ctr++;
7186: }
7187: $result.= '</select>';
7188: return $result;
7189: }
7190:
1.495 albertel 7191: my %bubble_lines_per_response; # no. bubble lines for each response.
1.554 raeburn 7192: # key is zero-based index - 0, 1, 2 ...
1.495 albertel 7193:
7194: my %first_bubble_line; # First bubble line no. for each bubble.
7195:
1.509 raeburn 7196: my %subdivided_bubble_lines; # no. bubble lines for optionresponse,
7197: # matchresponse or rankresponse, where
7198: # an individual response can have multiple
7199: # lines
1.503 raeburn 7200:
7201: my %responsetype_per_response; # responsetype for each response
7202:
1.691 raeburn 7203: my %masterseq_id_responsenum; # src_id (e.g., 12.3_0.11 etc.) for each
7204: # numbered response. Needed when randomorder
7205: # or randompick are in use. Key is ID, value
7206: # is response number.
7207:
1.495 albertel 7208: # Save and restore the bubble lines array to the form env.
7209:
7210:
7211: sub save_bubble_lines {
7212: foreach my $line (keys(%bubble_lines_per_response)) {
7213: $env{"form.scantron.bubblelines.$line"} = $bubble_lines_per_response{$line};
7214: $env{"form.scantron.first_bubble_line.$line"} =
7215: $first_bubble_line{$line};
1.503 raeburn 7216: $env{"form.scantron.sub_bubblelines.$line"} =
7217: $subdivided_bubble_lines{$line};
7218: $env{"form.scantron.responsetype.$line"} =
7219: $responsetype_per_response{$line};
1.495 albertel 7220: }
1.691 raeburn 7221: foreach my $resid (keys(%masterseq_id_responsenum)) {
7222: my $line = $masterseq_id_responsenum{$resid};
7223: $env{"form.scantron.residpart.$line"} = $resid;
7224: }
1.495 albertel 7225: }
7226:
7227:
7228: sub restore_bubble_lines {
7229: my $line = 0;
7230: %bubble_lines_per_response = ();
1.691 raeburn 7231: %masterseq_id_responsenum = ();
1.495 albertel 7232: while ($env{"form.scantron.bubblelines.$line"}) {
7233: my $value = $env{"form.scantron.bubblelines.$line"};
7234: $bubble_lines_per_response{$line} = $value;
7235: $first_bubble_line{$line} =
7236: $env{"form.scantron.first_bubble_line.$line"};
1.503 raeburn 7237: $subdivided_bubble_lines{$line} =
7238: $env{"form.scantron.sub_bubblelines.$line"};
7239: $responsetype_per_response{$line} =
7240: $env{"form.scantron.responsetype.$line"};
1.691 raeburn 7241: my $id = $env{"form.scantron.residpart.$line"};
7242: $masterseq_id_responsenum{$id} = $line;
1.495 albertel 7243: $line++;
7244: }
7245: }
7246:
1.423 albertel 7247: =pod
7248:
7249: =item scantron_filenames
7250:
7251: Returns a list of the scantron files in the current course
7252:
7253: =cut
1.422 foxr 7254:
1.202 albertel 7255: sub scantron_filenames {
1.257 albertel 7256: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7257: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
1.517 raeburn 7258: my $getpropath = 1;
1.662 raeburn 7259: my ($dirlist,$listerror) = &Apache::lonnet::dirlist('userfiles',$cdom,
7260: $cname,$getpropath);
1.202 albertel 7261: my @possiblenames;
1.662 raeburn 7262: if (ref($dirlist) eq 'ARRAY') {
7263: foreach my $filename (sort(@{$dirlist})) {
7264: ($filename)=split(/&/,$filename);
7265: if ($filename!~/^scantron_orig_/) { next ; }
7266: $filename=~s/^scantron_orig_//;
7267: push(@possiblenames,$filename);
7268: }
1.202 albertel 7269: }
7270: return @possiblenames;
7271: }
7272:
1.423 albertel 7273: =pod
7274:
7275: =item scantron_uploads
7276:
7277: Returns html drop-down list of scantron files in current course.
7278:
7279: Arguments:
7280: $file2grade - filename to set as selected in the dropdown
7281:
7282: =cut
1.422 foxr 7283:
1.202 albertel 7284: sub scantron_uploads {
1.209 ng 7285: my ($file2grade) = @_;
1.202 albertel 7286: my $result= '<select name="scantron_selectfile">';
7287: $result.="<option></option>";
7288: foreach my $filename (sort(&scantron_filenames())) {
1.401 albertel 7289: $result.="<option".($filename eq $file2grade ? ' selected="selected"':'').">$filename</option>\n";
1.81 albertel 7290: }
7291: $result.="</select>";
7292: return $result;
7293: }
7294:
1.423 albertel 7295: =pod
7296:
7297: =item scantron_scantab
7298:
7299: Returns html drop down of the scantron formats in the scantronformat.tab
7300: file.
7301:
7302: =cut
1.422 foxr 7303:
1.82 albertel 7304: sub scantron_scantab {
7305: my $result='<select name="scantron_format">'."\n";
1.191 albertel 7306: $result.='<option></option>'."\n";
1.754 raeburn 7307: my @lines = &Apache::lonnet::get_scantronformat_file();
1.518 raeburn 7308: if (@lines > 0) {
7309: foreach my $line (@lines) {
7310: next if (($line =~ /^\#/) || ($line eq ''));
7311: my ($name,$descrip)=split(/:/,$line);
7312: $result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
7313: }
1.82 albertel 7314: }
7315: $result.='</select>'."\n";
1.518 raeburn 7316: return $result;
7317: }
7318:
1.423 albertel 7319: =pod
7320:
7321: =item scantron_CODElist
7322:
7323: Returns html drop down of the saved CODE lists from current course,
7324: generated from earlier printings.
7325:
7326: =cut
1.422 foxr 7327:
1.186 albertel 7328: sub scantron_CODElist {
1.257 albertel 7329: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7330: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.186 albertel 7331: my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
7332: my $namechoice='<option></option>';
1.225 albertel 7333: foreach my $name (sort {uc($a) cmp uc($b)} @names) {
1.191 albertel 7334: if ($name =~ /^error: 2 /) { next; }
1.278 albertel 7335: if ($name =~ /^type\0/) { next; }
1.186 albertel 7336: $namechoice.='<option value="'.$name.'">'.$name.'</option>';
7337: }
7338: $namechoice='<select name="scantron_CODElist">'.$namechoice.'</select>';
7339: return $namechoice;
7340: }
7341:
1.423 albertel 7342: =pod
7343:
7344: =item scantron_CODEunique
7345:
7346: Returns the html for "Each CODE to be used once" radio.
7347:
7348: =cut
1.422 foxr 7349:
1.186 albertel 7350: sub scantron_CODEunique {
1.532 bisitz 7351: my $result='<span class="LC_nobreak">
1.272 albertel 7352: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 7353: value="yes" checked="checked" />'.&mt('Yes').' </label>
1.381 albertel 7354: </span>
1.532 bisitz 7355: <span class="LC_nobreak">
1.272 albertel 7356: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 7357: value="no" />'.&mt('No').' </label>
1.381 albertel 7358: </span>';
1.186 albertel 7359: return $result;
7360: }
1.423 albertel 7361:
7362: =pod
7363:
7364: =item scantron_selectphase
7365:
1.659 raeburn 7366: Generates the initial screen to start the bubblesheet process.
1.423 albertel 7367: Allows for - starting a grading run.
1.424 albertel 7368: - downloading existing scan data (original, corrected
1.423 albertel 7369: or skipped info)
7370:
7371: - uploading new scan data
7372:
7373: Arguments:
7374: $r - The Apache request object
7375: $file2grade - name of the file that contain the scanned data to score
7376:
7377: =cut
1.186 albertel 7378:
1.75 albertel 7379: sub scantron_selectphase {
1.608 www 7380: my ($r,$file2grade,$symb) = @_;
1.75 albertel 7381: if (!$symb) {return '';}
1.582 raeburn 7382: my $map_error;
7383: my $sequence_selector=&getSequenceDropDown($symb,\$map_error);
7384: if ($map_error) {
7385: $r->print('<br />'.&navmap_errormsg().'<br />');
7386: return;
7387: }
1.324 albertel 7388: my $default_form_data=&defaultFormData($symb);
1.209 ng 7389: my $file_selector=&scantron_uploads($file2grade);
1.82 albertel 7390: my $format_selector=&scantron_scantab();
1.186 albertel 7391: my $CODE_selector=&scantron_CODElist();
7392: my $CODE_unique=&scantron_CODEunique();
1.75 albertel 7393: my $result;
1.422 foxr 7394:
1.513 foxr 7395: $ssi_error = 0;
7396:
1.770 raeburn 7397: if (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) || $perm{'usc'}) {
1.606 wenzelju 7398:
7399: # Chunk of form to prompt for a scantron file upload.
7400:
7401: $r->print('
1.754 raeburn 7402: <br />');
1.606 wenzelju 7403: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
7404: my $cnum= $env{'course.'.$env{'request.course.id'}.'.num'};
1.770 raeburn 7405: my $csec= $env{'request.course.sec'};
1.736 damieng 7406: my $alertmsg = &mt('Please use the browse button to select a file from your local directory.');
7407: &js_escape(\$alertmsg);
1.754 raeburn 7408: my ($formatoptions,$formattitle,$formatjs) = &scantron_upload_dataformat($cdom);
1.606 wenzelju 7409: $r->print(&Apache::lonhtmlcommon::scripttag('
7410: function checkUpload(formname) {
7411: if (formname.upfile.value == "") {
1.736 damieng 7412: alert("'.$alertmsg.'");
1.606 wenzelju 7413: return false;
7414: }
7415: formname.submit();
1.756 raeburn 7416: }'."\n".$formatjs));
1.606 wenzelju 7417: $r->print('
7418: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
7419: '.$default_form_data.'
7420: <input name="courseid" type="hidden" value="'.$cnum.'" />
1.770 raeburn 7421: <input name="coursesec" type="hidden" value="'.$csec.'" />
1.606 wenzelju 7422: <input name="domainid" type="hidden" value="'.$cdom.'" />
7423: <input name="command" value="scantronupload_save" type="hidden" />
1.754 raeburn 7424: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
7425: '.&Apache::loncommon::start_data_table_header_row().'
7426: <th>
7427: '.&mt('Specify a bubblesheet data file to upload.').'
7428: </th>
7429: '.&Apache::loncommon::end_data_table_header_row().'
7430: '.&Apache::loncommon::start_data_table_row().'
7431: <td>
7432: '.&mt('File to upload: [_1]','<input type="file" name="upfile" size="50" />').'<br />'."\n");
7433: if ($formatoptions) {
7434: $r->print('</td>
7435: '.&Apache::loncommon::end_data_table_row().'
7436: '.&Apache::loncommon::start_data_table_row().'
7437: <td>'.$formattitle.(' 'x2).$formatoptions.'
7438: </td>
7439: '.&Apache::loncommon::end_data_table_row().'
7440: '.&Apache::loncommon::start_data_table_row().'
7441: <td>'
7442: );
7443: } else {
7444: $r->print(' <br />');
7445: }
7446: $r->print('<input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
7447: </td>
7448: '.&Apache::loncommon::end_data_table_row().'
7449: '.&Apache::loncommon::end_data_table().'
7450: </form>'
7451: );
1.606 wenzelju 7452:
7453: }
7454:
1.422 foxr 7455: # Chunk of form to prompt for a file to grade and how:
7456:
1.489 albertel 7457: $result.= '
7458: <br />
7459: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantron_process">
7460: <input type="hidden" name="command" value="scantron_warning" />
7461: '.$default_form_data.'
7462: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
7463: '.&Apache::loncommon::start_data_table_header_row().'
7464: <th colspan="2">
1.492 albertel 7465: '.&mt('Specify file and which Folder/Sequence to grade').'
1.489 albertel 7466: </th>
7467: '.&Apache::loncommon::end_data_table_header_row().'
7468: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 7469: <td> '.&mt('Sequence to grade:').' </td><td> '.$sequence_selector.' </td>
1.489 albertel 7470: '.&Apache::loncommon::end_data_table_row().'
7471: '.&Apache::loncommon::start_data_table_row().'
1.572 www 7472: <td> '.&mt('Filename of bubblesheet data file:').' </td><td> '.$file_selector.' </td>
1.489 albertel 7473: '.&Apache::loncommon::end_data_table_row().'
7474: '.&Apache::loncommon::start_data_table_row().'
1.572 www 7475: <td> '.&mt('Format of bubblesheet data file:').' </td><td> '.$format_selector.' </td>
1.489 albertel 7476: '.&Apache::loncommon::end_data_table_row().'
7477: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 7478: <td> '.&mt('Saved CODEs to validate against:').' </td><td> '.$CODE_selector.' </td>
1.489 albertel 7479: '.&Apache::loncommon::end_data_table_row().'
7480: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 7481: <td> '.&mt('Each CODE is only to be used once:').'</td><td> '.$CODE_unique.' </td>
1.489 albertel 7482: '.&Apache::loncommon::end_data_table_row().'
7483: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 7484: <td> '.&mt('Options:').' </td>
1.187 albertel 7485: <td>
1.492 albertel 7486: <label><input type="checkbox" name="scantron_options_redo" value="redo_skipped"/> '.&mt('Do only previously skipped records').'</label> <br />
7487: <label><input type="checkbox" name="scantron_options_ignore" value="ignore_corrections"/> '.&mt('Remove all existing corrections').'</label> <br />
7488: <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources when grading').'</label>
1.187 albertel 7489: </td>
1.489 albertel 7490: '.&Apache::loncommon::end_data_table_row().'
7491: '.&Apache::loncommon::start_data_table_row().'
1.174 albertel 7492: <td colspan="2">
1.572 www 7493: <input type="submit" value="'.&mt('Grading: Validate Bubblesheet Records').'" />
1.162 albertel 7494: </td>
1.489 albertel 7495: '.&Apache::loncommon::end_data_table_row().'
7496: '.&Apache::loncommon::end_data_table().'
7497: </form>
7498: ';
1.162 albertel 7499:
7500: $r->print($result);
7501:
1.422 foxr 7502: # Chunk of the form that prompts to view a scoring office file,
7503: # corrected file, skipped records in a file.
7504:
1.489 albertel 7505: $r->print('
7506: <br />
7507: <form action="/adm/grades" name="scantron_download">
7508: '.$default_form_data.'
7509: <input type="hidden" name="command" value="scantron_download" />
7510: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
7511: '.&Apache::loncommon::start_data_table_header_row().'
7512: <th>
1.492 albertel 7513: '.&mt('Download a scoring office file').'
1.489 albertel 7514: </th>
7515: '.&Apache::loncommon::end_data_table_header_row().'
7516: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 7517: <td> '.&mt('Filename of scoring office file: [_1]',$file_selector).'
1.489 albertel 7518: <br />
1.492 albertel 7519: <input type="submit" value="'.&mt('Download: Show List of Associated Files').'" />
1.489 albertel 7520: '.&Apache::loncommon::end_data_table_row().'
7521: '.&Apache::loncommon::end_data_table().'
7522: </form>
7523: <br />
7524: ');
1.162 albertel 7525:
1.457 banghart 7526: &Apache::lonpickcode::code_list($r,2);
1.523 raeburn 7527:
1.694 bisitz 7528: $r->print('<br /><form method="post" name="checkscantron" action="">'.
1.523 raeburn 7529: $default_form_data."\n".
7530: &Apache::loncommon::start_data_table('LC_scantron_action')."\n".
7531: &Apache::loncommon::start_data_table_header_row()."\n".
7532: '<th colspan="2">
1.572 www 7533: '.&mt('Review bubblesheet data and submissions for a previously graded folder/sequence')."\n".
1.523 raeburn 7534: '</th>'."\n".
7535: &Apache::loncommon::end_data_table_header_row()."\n".
7536: &Apache::loncommon::start_data_table_row()."\n".
7537: '<td> '.&mt('Graded folder/sequence:').' </td>'."\n".
7538: '<td> '.$sequence_selector.' </td>'.
7539: &Apache::loncommon::end_data_table_row()."\n".
7540: &Apache::loncommon::start_data_table_row()."\n".
7541: '<td> '.&mt('Filename of scoring office file:').' </td>'."\n".
7542: '<td> '.$file_selector.' </td>'."\n".
7543: &Apache::loncommon::end_data_table_row()."\n".
7544: &Apache::loncommon::start_data_table_row()."\n".
7545: '<td> '.&mt('Format of data file:').' </td>'."\n".
7546: '<td> '.$format_selector.' </td>'."\n".
7547: &Apache::loncommon::end_data_table_row()."\n".
7548: &Apache::loncommon::start_data_table_row()."\n".
1.557 raeburn 7549: '<td> '.&mt('Options').' </td>'."\n".
7550: '<td> <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources').'</label></td>'.
7551: &Apache::loncommon::end_data_table_row()."\n".
7552: &Apache::loncommon::start_data_table_row()."\n".
1.523 raeburn 7553: '<td colspan="2">'."\n".
7554: '<input type="hidden" name="command" value="checksubmissions" />'."\n".
1.575 www 7555: '<input type="submit" value="'.&mt('Review Bubblesheet Data and Submission Records').'" />'."\n".
1.523 raeburn 7556: '</td>'."\n".
7557: &Apache::loncommon::end_data_table_row()."\n".
7558: &Apache::loncommon::end_data_table()."\n".
7559: '</form><br />');
7560: return;
1.75 albertel 7561: }
7562:
1.423 albertel 7563: =pod
7564:
7565: =item username_to_idmap
7566:
1.556 weissno 7567: creates a hash keyed by student/employee ID with values of the corresponding
1.731 raeburn 7568: student username:domain. If a single ID occurs for more than one student,
7569: the status of the student is checked, and if Active, the value in the hash
7570: will be set to the Active student.
1.423 albertel 7571:
7572: Arguments:
7573:
7574: $classlist - reference to the class list hash. This is a hash
7575: keyed by student name:domain whose elements are references
1.424 albertel 7576: to arrays containing various chunks of information
1.423 albertel 7577: about the student. (See loncoursedata for more info).
7578:
7579: Returns
7580: %idmap - the constructed hash
7581:
7582: =cut
7583:
1.82 albertel 7584: sub username_to_idmap {
7585: my ($classlist)= @_;
7586: my %idmap;
7587: foreach my $student (keys(%$classlist)) {
1.731 raeburn 7588: my $id = $classlist->{$student}->[&Apache::loncoursedata::CL_ID];
7589: unless ($id eq '') {
7590: if (!exists($idmap{$id})) {
7591: $idmap{$id} = $student;
7592: } else {
7593: my $status = $classlist->{$student}->[&Apache::loncoursedata::CL_STATUS];
7594: if ($status eq 'Active') {
7595: $idmap{$id} = $student;
7596: }
7597: }
7598: }
1.82 albertel 7599: }
7600: return %idmap;
7601: }
1.423 albertel 7602:
7603: =pod
7604:
1.424 albertel 7605: =item scantron_fixup_scanline
1.423 albertel 7606:
7607: Process a requested correction to a scanline.
7608:
7609: Arguments:
1.754 raeburn 7610: $scantron_config - hash from &Apache::lonnet::get_scantron_config()
1.423 albertel 7611: $scan_data - hash of correction information
7612: (see &scantron_getfile())
7613: $line - existing scanline
7614: $whichline - line number of the passed in scanline
7615: $field - type of change to process
7616: (either
1.573 bisitz 7617: 'ID' -> correct the student/employee ID
1.423 albertel 7618: 'CODE' -> correct the CODE
7619: 'answer' -> fixup the submitted answers)
7620:
7621: $args - hash of additional info,
7622: - 'ID'
7623: 'newid' -> studentID to use in replacement
1.424 albertel 7624: of existing one
1.423 albertel 7625: - 'CODE'
7626: 'CODE_ignore_dup' - set to true if duplicates
7627: should be ignored.
7628: 'CODE' - is new code or 'use_unfound'
1.424 albertel 7629: if the existing unfound code should
1.423 albertel 7630: be used as is
7631: - 'answer'
7632: 'response' - new answer or 'none' if blank
7633: 'question' - the bubble line to change
1.503 raeburn 7634: 'questionnum' - the question identifier,
7635: may include subquestion.
1.423 albertel 7636:
7637: Returns:
7638: $line - the modified scanline
7639:
7640: Side effects:
7641: $scan_data - may be updated
7642:
7643: =cut
7644:
1.82 albertel 7645:
1.157 albertel 7646: sub scantron_fixup_scanline {
7647: my ($scantron_config,$scan_data,$line,$whichline,$field,$args)=@_;
7648: if ($field eq 'ID') {
7649: if (length($args->{'newid'}) > $$scantron_config{'IDlength'}) {
1.186 albertel 7650: return ($line,1,'New value too large');
1.157 albertel 7651: }
7652: if (length($args->{'newid'}) < $$scantron_config{'IDlength'}) {
7653: $args->{'newid'}=sprintf('%-'.$$scantron_config{'IDlength'}.'s',
7654: $args->{'newid'});
7655: }
7656: substr($line,$$scantron_config{'IDstart'}-1,
7657: $$scantron_config{'IDlength'})=$args->{'newid'};
7658: if ($args->{'newid'}=~/^\s*$/) {
7659: &scan_data($scan_data,"$whichline.user",
7660: $args->{'username'}.':'.$args->{'domain'});
7661: }
1.186 albertel 7662: } elsif ($field eq 'CODE') {
1.192 albertel 7663: if ($args->{'CODE_ignore_dup'}) {
7664: &scan_data($scan_data,"$whichline.CODE_ignore_dup",'1');
7665: }
7666: &scan_data($scan_data,"$whichline.useCODE",'1');
7667: if ($args->{'CODE'} ne 'use_unfound') {
1.191 albertel 7668: if (length($args->{'CODE'}) > $$scantron_config{'CODElength'}) {
7669: return ($line,1,'New CODE value too large');
7670: }
7671: if (length($args->{'CODE'}) < $$scantron_config{'CODElength'}) {
7672: $args->{'CODE'}=sprintf('%-'.$$scantron_config{'CODElength'}.'s',$args->{'CODE'});
7673: }
7674: substr($line,$$scantron_config{'CODEstart'}-1,
7675: $$scantron_config{'CODElength'})=$args->{'CODE'};
1.186 albertel 7676: }
1.157 albertel 7677: } elsif ($field eq 'answer') {
1.497 foxr 7678: my $length=$scantron_config->{'Qlength'};
1.157 albertel 7679: my $off=$scantron_config->{'Qoff'};
7680: my $on=$scantron_config->{'Qon'};
1.497 foxr 7681: my $answer=${off}x$length;
7682: if ($args->{'response'} eq 'none') {
7683: &scan_data($scan_data,
1.503 raeburn 7684: "$whichline.no_bubble.".$args->{'questionnum'},'1');
1.497 foxr 7685: } else {
7686: if ($on eq 'letter') {
7687: my @alphabet=('A'..'Z');
7688: $answer=$alphabet[$args->{'response'}];
7689: } elsif ($on eq 'number') {
7690: $answer=$args->{'response'}+1;
7691: if ($answer == 10) { $answer = '0'; }
1.274 albertel 7692: } else {
1.497 foxr 7693: substr($answer,$args->{'response'},1)=$on;
1.274 albertel 7694: }
1.497 foxr 7695: &scan_data($scan_data,
1.503 raeburn 7696: "$whichline.no_bubble.".$args->{'questionnum'},undef,'1');
1.157 albertel 7697: }
1.497 foxr 7698: my $where=$length*($args->{'question'}-1)+$scantron_config->{'Qstart'};
7699: substr($line,$where-1,$length)=$answer;
1.157 albertel 7700: }
7701: return $line;
7702: }
1.423 albertel 7703:
7704: =pod
7705:
7706: =item scan_data
7707:
7708: Edit or look up an item in the scan_data hash.
7709:
7710: Arguments:
7711: $scan_data - The hash (see scantron_getfile)
7712: $key - shorthand of the key to edit (actual key is
1.424 albertel 7713: scantronfilename_key).
1.423 albertel 7714: $data - New value of the hash entry.
7715: $delete - If true, the entry is removed from the hash.
7716:
7717: Returns:
7718: The new value of the hash table field (undefined if deleted).
7719:
7720: =cut
7721:
7722:
1.157 albertel 7723: sub scan_data {
7724: my ($scan_data,$key,$value,$delete)=@_;
1.257 albertel 7725: my $filename=$env{'form.scantron_selectfile'};
1.157 albertel 7726: if (defined($value)) {
7727: $scan_data->{$filename.'_'.$key} = $value;
7728: }
7729: if ($delete) { delete($scan_data->{$filename.'_'.$key}); }
7730: return $scan_data->{$filename.'_'.$key};
7731: }
1.423 albertel 7732:
1.495 albertel 7733: # ----- These first few routines are general use routines.----
7734:
7735: # Return the number of occurences of a pattern in a string.
7736:
7737: sub occurence_count {
7738: my ($string, $pattern) = @_;
7739:
7740: my @matches = ($string =~ /$pattern/g);
7741:
7742: return scalar(@matches);
7743: }
7744:
7745:
7746: # Take a string known to have digits and convert all the
7747: # digits into letters in the range J,A..I.
7748:
7749: sub digits_to_letters {
7750: my ($input) = @_;
7751:
7752: my @alphabet = ('J', 'A'..'I');
7753:
7754: my @input = split(//, $input);
7755: my $output ='';
7756: for (my $i = 0; $i < scalar(@input); $i++) {
7757: if ($input[$i] =~ /\d/) {
7758: $output .= $alphabet[$input[$i]];
7759: } else {
7760: $output .= $input[$i];
7761: }
7762: }
7763: return $output;
7764: }
7765:
1.423 albertel 7766: =pod
7767:
7768: =item scantron_parse_scanline
7769:
1.711 bisitz 7770: Decodes a scanline from the selected bubblesheet file
1.423 albertel 7771:
7772: Arguments:
1.711 bisitz 7773: line - The text of the bubblesheet file line to process
1.423 albertel 7774: whichline - Line number
1.711 bisitz 7775: scantron_config - Hash describing the format of the bubblesheet lines.
1.423 albertel 7776: scan_data - Hash of extra information about the scanline
7777: (see scantron_getfile for more information)
7778: just_header - True if should not process question answers but only
7779: the stuff to the left of the answers.
1.691 raeburn 7780: randomorder - True if randomorder in use
7781: randompick - True if randompick in use
7782: sequence - Exam folder URL
7783: master_seq - Ref to array containing symbs in exam folder
7784: symb_to_resource - Ref to hash of symbs for resources in exam folder
7785: (corresponding values are resource objects)
7786: partids_by_symb - Ref to hash of symb -> array ref of partIDs
7787: orderedforcode - Ref to hash of arrays. keys are CODEs and values
7788: are refs to an array of resource objects, ordered
7789: according to order used for CODE, when randomorder
7790: and or randompick are in use.
7791: respnumlookup - Ref to hash mapping question numbers in bubble lines
7792: for current line to question number used for same question
7793: in "Master Sequence" (as seen by Course Coordinator).
7794: startline - Ref to hash where key is question number (0 is first)
7795: and value is number of first bubble line for current
7796: student or code-based randompick and/or randomorder.
7797: totalref - Ref of scalar used to score total number of bubble
7798: lines needed for responses in a scan line (used when
7799: randompick in use.
7800:
1.423 albertel 7801: Returns:
7802: Hash containing the result of parsing the scanline
7803:
7804: Keys are all proceeded by the string 'scantron.'
7805:
7806: CODE - the CODE in use for this scanline
7807: useCODE - 1 if the CODE is invalid but it usage has been forced
7808: by the operator
7809: CODE_ignore_dup - 1 if the CODE is a duplicated use when unique
7810: CODEs were selected, but the usage has been
7811: forced by the operator
1.556 weissno 7812: ID - student/employee ID
1.423 albertel 7813: PaperID - if used, the ID number printed on the sheet when the
7814: paper was scanned
7815: FirstName - first name from the sheet
7816: LastName - last name from the sheet
7817:
7818: if just_header was not true these key may also exist
7819:
1.447 foxr 7820: missingerror - a list of bubble ranges that are considered to be answers
7821: to a single question that don't have any bubbles filled in.
7822: Of the form questionnumber:firstbubblenumber:count.
7823: doubleerror - a list of bubble ranges that are considered to be answers
7824: to a single question that have more than one bubble filled in.
7825: Of the form questionnumber::firstbubblenumber:count
7826:
7827: In the above, count is the number of bubble responses in the
7828: input line needed to represent the possible answers to the question.
7829: e.g. a radioresponse with 15 choices in an answer sheet with 10 choices
7830: per line would have count = 2.
7831:
1.423 albertel 7832: maxquest - the number of the last bubble line that was parsed
7833:
7834: (<number> starts at 1)
7835: <number>.answer - zero or more letters representing the selected
7836: letters from the scanline for the bubble line
7837: <number>.
7838: if blank there was either no bubble or there where
7839: multiple bubbles, (consult the keys missingerror and
7840: doubleerror if this is an error condition)
7841:
7842: =cut
7843:
1.82 albertel 7844: sub scantron_parse_scanline {
1.691 raeburn 7845: my ($line,$whichline,$scantron_config,$scan_data,$just_header,$idmap,
7846: $randomorder,$randompick,$sequence,$master_seq,$symb_to_resource,
7847: $partids_by_symb,$orderedforcode,$respnumlookup,$startline,$totalref)=@_;
1.470 foxr 7848:
1.82 albertel 7849: my %record;
1.691 raeburn 7850: my $data=substr($line,0,$$scantron_config{'Qstart'}-1); # stuff before answers
1.278 albertel 7851: if (!($$scantron_config{'CODElocation'} eq 0 ||
7852: $$scantron_config{'CODElocation'} eq 'none')) {
7853: if ($$scantron_config{'CODElocation'} < 0 ||
7854: $$scantron_config{'CODElocation'} eq 'letter' ||
7855: $$scantron_config{'CODElocation'} eq 'number') {
1.191 albertel 7856: $record{'scantron.CODE'}=substr($data,
7857: $$scantron_config{'CODEstart'}-1,
1.83 albertel 7858: $$scantron_config{'CODElength'});
1.191 albertel 7859: if (&scan_data($scan_data,"$whichline.useCODE")) {
7860: $record{'scantron.useCODE'}=1;
7861: }
1.192 albertel 7862: if (&scan_data($scan_data,"$whichline.CODE_ignore_dup")) {
7863: $record{'scantron.CODE_ignore_dup'}=1;
7864: }
1.82 albertel 7865: } else {
7866: #FIXME interpret first N questions
7867: }
7868: }
1.83 albertel 7869: $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
7870: $$scantron_config{'IDlength'});
1.157 albertel 7871: $record{'scantron.PaperID'}=
7872: substr($data,$$scantron_config{'PaperID'}-1,
7873: $$scantron_config{'PaperIDlength'});
7874: $record{'scantron.FirstName'}=
7875: substr($data,$$scantron_config{'FirstName'}-1,
7876: $$scantron_config{'FirstNamelength'});
7877: $record{'scantron.LastName'}=
7878: substr($data,$$scantron_config{'LastName'}-1,
7879: $$scantron_config{'LastNamelength'});
1.423 albertel 7880: if ($just_header) { return \%record; }
1.194 albertel 7881:
1.82 albertel 7882: my @alphabet=('A'..'Z');
7883: my $questnum=0;
1.447 foxr 7884: my $ansnum =1; # Multiple 'answer lines'/question.
7885:
1.691 raeburn 7886: my $lastpos = $env{'form.scantron_maxbubble'}*$$scantron_config{'Qlength'};
7887: if ($randompick || $randomorder) {
7888: my $total = &get_respnum_lookups($sequence,$scan_data,$idmap,$line,\%record,
7889: $master_seq,$symb_to_resource,
7890: $partids_by_symb,$orderedforcode,
7891: $respnumlookup,$startline);
7892: if ($total) {
7893: $lastpos = $total*$$scantron_config{'Qlength'};
7894: }
7895: if (ref($totalref)) {
7896: $$totalref = $total;
7897: }
7898: }
7899: my $questions=substr($line,$$scantron_config{'Qstart'}-1,$lastpos); # Answers
1.470 foxr 7900: chomp($questions); # Get rid of any trailing \n.
7901: $questions =~ s/\r$//; # Get rid of trailing \r too (MAC or Win uploads).
7902: while (length($questions)) {
1.691 raeburn 7903: my $answers_needed;
7904: if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
7905: $answers_needed = $bubble_lines_per_response{$respnumlookup->{$questnum}};
7906: } else {
7907: $answers_needed = $bubble_lines_per_response{$questnum};
7908: }
1.503 raeburn 7909: my $answer_length = ($$scantron_config{'Qlength'} * $answers_needed)
7910: || 1;
7911: $questnum++;
7912: my $quest_id = $questnum;
7913: my $currentquest = substr($questions,0,$answer_length);
7914: $questions = substr($questions,$answer_length);
7915: if (length($currentquest) < $answer_length) { next; }
7916:
1.691 raeburn 7917: my $subdivided;
7918: if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
7919: $subdivided = $subdivided_bubble_lines{$respnumlookup->{$questnum-1}};
7920: } else {
7921: $subdivided = $subdivided_bubble_lines{$questnum-1};
7922: }
7923: if ($subdivided =~ /,/) {
1.503 raeburn 7924: my $subquestnum = 1;
7925: my $subquestions = $currentquest;
1.691 raeburn 7926: my @subanswers_needed = split(/,/,$subdivided);
1.503 raeburn 7927: foreach my $subans (@subanswers_needed) {
7928: my $subans_length =
7929: ($$scantron_config{'Qlength'} * $subans) || 1;
7930: my $currsubquest = substr($subquestions,0,$subans_length);
7931: $subquestions = substr($subquestions,$subans_length);
7932: $quest_id = "$questnum.$subquestnum";
7933: if (($$scantron_config{'Qon'} eq 'letter') ||
7934: ($$scantron_config{'Qon'} eq 'number')) {
7935: $ansnum = &scantron_validator_lettnum($ansnum,
7936: $questnum,$quest_id,$subans,$currsubquest,$whichline,
1.691 raeburn 7937: \@alphabet,\%record,$scantron_config,$scan_data,
7938: $randomorder,$randompick,$respnumlookup);
1.503 raeburn 7939: } else {
7940: $ansnum = &scantron_validator_positional($ansnum,
1.691 raeburn 7941: $questnum,$quest_id,$subans,$currsubquest,$whichline,
7942: \@alphabet,\%record,$scantron_config,$scan_data,
7943: $randomorder,$randompick,$respnumlookup);
1.503 raeburn 7944: }
7945: $subquestnum ++;
7946: }
7947: } else {
7948: if (($$scantron_config{'Qon'} eq 'letter') ||
7949: ($$scantron_config{'Qon'} eq 'number')) {
7950: $ansnum = &scantron_validator_lettnum($ansnum,$questnum,
7951: $quest_id,$answers_needed,$currentquest,$whichline,
1.691 raeburn 7952: \@alphabet,\%record,$scantron_config,$scan_data,
7953: $randomorder,$randompick,$respnumlookup);
1.503 raeburn 7954: } else {
7955: $ansnum = &scantron_validator_positional($ansnum,$questnum,
7956: $quest_id,$answers_needed,$currentquest,$whichline,
1.691 raeburn 7957: \@alphabet,\%record,$scantron_config,$scan_data,
7958: $randomorder,$randompick,$respnumlookup);
1.503 raeburn 7959: }
7960: }
7961: }
7962: $record{'scantron.maxquest'}=$questnum;
7963: return \%record;
7964: }
1.447 foxr 7965:
1.691 raeburn 7966: sub get_master_seq {
1.788 raeburn 7967: my ($resources,$master_seq,$symb_to_resource,$need_symb_in_map,$symb_for_examcode) = @_;
1.691 raeburn 7968: return unless ((ref($resources) eq 'ARRAY') && (ref($master_seq) eq 'ARRAY') &&
7969: (ref($symb_to_resource) eq 'HASH'));
1.788 raeburn 7970: if ($need_symb_in_map) {
7971: return unless (ref($symb_for_examcode) eq 'HASH');
7972: }
1.691 raeburn 7973: my $resource_error;
7974: foreach my $resource (@{$resources}) {
7975: my $ressymb;
7976: if (ref($resource)) {
7977: $ressymb = $resource->symb();
7978: push(@{$master_seq},$ressymb);
7979: $symb_to_resource->{$ressymb} = $resource;
1.788 raeburn 7980: if ($need_symb_in_map) {
7981: unless ($resource->is_map()) {
7982: my $map=(&Apache::lonnet::decode_symb($ressymb))[0];
7983: unless (exists($symb_for_examcode->{$map})) {
7984: $symb_for_examcode->{$map} = $ressymb;
7985: }
7986: }
7987: }
1.691 raeburn 7988: } else {
7989: $resource_error = 1;
7990: last;
7991: }
7992: }
7993: return $resource_error;
7994: }
7995:
7996: sub get_respnum_lookups {
7997: my ($sequence,$scan_data,$idmap,$line,$record,$master_seq,$symb_to_resource,
7998: $partids_by_symb,$orderedforcode,$respnumlookup,$startline) = @_;
7999: return unless ((ref($record) eq 'HASH') && (ref($master_seq) eq 'ARRAY') &&
8000: (ref($symb_to_resource) eq 'HASH') && (ref($partids_by_symb) eq 'HASH') &&
8001: (ref($orderedforcode) eq 'HASH') && (ref($respnumlookup) eq 'HASH') &&
8002: (ref($startline) eq 'HASH'));
8003: my ($user,$scancode);
8004: if ((exists($record->{'scantron.CODE'})) &&
8005: (&Apache::lonnet::validCODE($record->{'scantron.CODE'}))) {
8006: $scancode = $record->{'scantron.CODE'};
8007: } else {
8008: $user = &scantron_find_student($record,$scan_data,$idmap,$line);
8009: }
8010: my @mapresources =
8011: &users_order($user,$scancode,$sequence,$master_seq,$symb_to_resource,
8012: $orderedforcode);
8013: my $total = 0;
8014: my $count = 0;
8015: foreach my $resource (@mapresources) {
8016: my $id = $resource->id();
8017: my $symb = $resource->symb();
8018: if (ref($partids_by_symb->{$symb}) eq 'ARRAY') {
8019: foreach my $partid (@{$partids_by_symb->{$symb}}) {
8020: my $respnum = $masterseq_id_responsenum{$id.'_'.$partid};
8021: if ($respnum ne '') {
8022: $respnumlookup->{$count} = $respnum;
8023: $startline->{$count} = $total;
8024: $total += $bubble_lines_per_response{$respnum};
8025: $count ++;
8026: }
8027: }
8028: }
8029: }
8030: return $total;
8031: }
8032:
1.503 raeburn 8033: sub scantron_validator_lettnum {
8034: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,$whichline,
1.691 raeburn 8035: $alphabet,$record,$scantron_config,$scan_data,$randomorder,
8036: $randompick,$respnumlookup) = @_;
1.503 raeburn 8037:
8038: # Qon 'letter' implies for each slot in currquest we have:
8039: # ? or * for doubles, a letter in A-Z for a bubble, and
8040: # about anything else (esp. a value of Qoff) for missing
8041: # bubbles.
8042: #
8043: # Qon 'number' implies each slot gives a digit that indexes the
8044: # bubbles filled, or Qoff, or a non-number for unbubbled lines,
8045: # and * or ? for double bubbles on a single line.
8046: #
1.447 foxr 8047:
1.503 raeburn 8048: my $matchon;
8049: if ($$scantron_config{'Qon'} eq 'letter') {
8050: $matchon = '[A-Z]';
8051: } elsif ($$scantron_config{'Qon'} eq 'number') {
8052: $matchon = '\d';
8053: }
8054: my $occurrences = 0;
1.691 raeburn 8055: my $responsenum = $questnum-1;
8056: if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
8057: $responsenum = $respnumlookup->{$questnum-1}
8058: }
8059: if (($responsetype_per_response{$responsenum} eq 'essayresponse') ||
8060: ($responsetype_per_response{$responsenum} eq 'formularesponse') ||
8061: ($responsetype_per_response{$responsenum} eq 'stringresponse') ||
8062: ($responsetype_per_response{$responsenum} eq 'imageresponse') ||
8063: ($responsetype_per_response{$responsenum} eq 'reactionresponse') ||
8064: ($responsetype_per_response{$responsenum} eq 'organicresponse')) {
1.503 raeburn 8065: my @singlelines = split('',$currquest);
8066: foreach my $entry (@singlelines) {
8067: $occurrences = &occurence_count($entry,$matchon);
8068: if ($occurrences > 1) {
8069: last;
8070: }
1.691 raeburn 8071: }
1.503 raeburn 8072: } else {
8073: $occurrences = &occurence_count($currquest,$matchon);
8074: }
8075: if (($currquest =~ /\?/ || $currquest =~ /\*/) || ($occurrences > 1)) {
8076: push(@{$record->{'scantron.doubleerror'}},$quest_id);
8077: for (my $ans=0; $ans<$answers_needed; $ans++) {
8078: my $bubble = substr($currquest,$ans,1);
8079: if ($bubble =~ /$matchon/ ) {
8080: if ($$scantron_config{'Qon'} eq 'number') {
8081: if ($bubble == 0) {
8082: $bubble = 10;
8083: }
8084: $record->{"scantron.$ansnum.answer"} =
8085: $alphabet->[$bubble-1];
8086: } else {
8087: $record->{"scantron.$ansnum.answer"} = $bubble;
8088: }
8089: } else {
8090: $record->{"scantron.$ansnum.answer"}='';
8091: }
8092: $ansnum++;
8093: }
8094: } elsif (!defined($currquest)
8095: || (&occurence_count($currquest, $$scantron_config{'Qoff'}) == length($currquest))
8096: || (&occurence_count($currquest,$matchon) == 0)) {
8097: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
8098: $record->{"scantron.$ansnum.answer"}='';
8099: $ansnum++;
8100: }
8101: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
8102: push(@{$record->{'scantron.missingerror'}},$quest_id);
8103: }
8104: } else {
8105: if ($$scantron_config{'Qon'} eq 'number') {
8106: $currquest = &digits_to_letters($currquest);
8107: }
8108: for (my $ans=0; $ans<$answers_needed; $ans++) {
8109: my $bubble = substr($currquest,$ans,1);
8110: $record->{"scantron.$ansnum.answer"} = $bubble;
8111: $ansnum++;
8112: }
8113: }
8114: return $ansnum;
8115: }
1.447 foxr 8116:
1.503 raeburn 8117: sub scantron_validator_positional {
8118: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,
1.691 raeburn 8119: $whichline,$alphabet,$record,$scantron_config,$scan_data,
8120: $randomorder,$randompick,$respnumlookup) = @_;
1.447 foxr 8121:
1.503 raeburn 8122: # Otherwise there's a positional notation;
8123: # each bubble line requires Qlength items, and there are filled in
8124: # bubbles for each case where there 'Qon' characters.
8125: #
1.447 foxr 8126:
1.503 raeburn 8127: my @array=split($$scantron_config{'Qon'},$currquest,-1);
1.447 foxr 8128:
1.503 raeburn 8129: # If the split only gives us one element.. the full length of the
8130: # answer string, no bubbles are filled in:
1.447 foxr 8131:
1.507 raeburn 8132: if ($answers_needed eq '') {
8133: return;
8134: }
8135:
1.503 raeburn 8136: if (length($array[0]) eq $$scantron_config{'Qlength'}*$answers_needed) {
8137: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
8138: $record->{"scantron.$ansnum.answer"}='';
8139: $ansnum++;
8140: }
8141: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
8142: push(@{$record->{"scantron.missingerror"}},$quest_id);
8143: }
8144: } elsif (scalar(@array) == 2) {
8145: my $location = length($array[0]);
8146: my $line_num = int($location / $$scantron_config{'Qlength'});
8147: my $bubble = $alphabet->[$location % $$scantron_config{'Qlength'}];
8148: for (my $ans=0; $ans<$answers_needed; $ans++) {
8149: if ($ans eq $line_num) {
8150: $record->{"scantron.$ansnum.answer"} = $bubble;
8151: } else {
8152: $record->{"scantron.$ansnum.answer"} = ' ';
8153: }
8154: $ansnum++;
8155: }
8156: } else {
8157: # If there's more than one instance of a bubble character
8158: # That's a double bubble; with positional notation we can
8159: # record all the bubbles filled in as well as the
8160: # fact this response consists of multiple bubbles.
8161: #
1.691 raeburn 8162: my $responsenum = $questnum-1;
8163: if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
8164: $responsenum = $respnumlookup->{$questnum-1}
8165: }
8166: if (($responsetype_per_response{$responsenum} eq 'essayresponse') ||
8167: ($responsetype_per_response{$responsenum} eq 'formularesponse') ||
8168: ($responsetype_per_response{$responsenum} eq 'stringresponse') ||
8169: ($responsetype_per_response{$responsenum} eq 'imageresponse') ||
8170: ($responsetype_per_response{$responsenum} eq 'reactionresponse') ||
8171: ($responsetype_per_response{$responsenum} eq 'organicresponse')) {
1.503 raeburn 8172: my $doubleerror = 0;
8173: while (($currquest >= $$scantron_config{'Qlength'}) &&
8174: (!$doubleerror)) {
8175: my $currline = substr($currquest,0,$$scantron_config{'Qlength'});
8176: $currquest = substr($currquest,$$scantron_config{'Qlength'});
8177: my @currarray = split($$scantron_config{'Qon'},$currline,-1);
8178: if (length(@currarray) > 2) {
8179: $doubleerror = 1;
8180: }
8181: }
8182: if ($doubleerror) {
8183: push(@{$record->{'scantron.doubleerror'}},$quest_id);
8184: }
8185: } else {
8186: push(@{$record->{'scantron.doubleerror'}},$quest_id);
8187: }
8188: my $item = $ansnum;
8189: for (my $ans=0; $ans<$answers_needed; $ans++) {
8190: $record->{"scantron.$item.answer"} = '';
8191: $item ++;
8192: }
1.447 foxr 8193:
1.503 raeburn 8194: my @ans=@array;
8195: my $i=0;
8196: my $increment = 0;
8197: while ($#ans) {
8198: $i+=length($ans[0]) + $increment;
8199: my $line = int($i/$$scantron_config{'Qlength'} + $ansnum);
8200: my $bubble = $i%$$scantron_config{'Qlength'};
8201: $record->{"scantron.$line.answer"}.=$alphabet->[$bubble];
8202: shift(@ans);
8203: $increment = 1;
8204: }
8205: $ansnum += $answers_needed;
1.82 albertel 8206: }
1.503 raeburn 8207: return $ansnum;
1.82 albertel 8208: }
8209:
1.423 albertel 8210: =pod
8211:
8212: =item scantron_add_delay
8213:
8214: Adds an error message that occurred during the grading phase to a
8215: queue of messages to be shown after grading pass is complete
8216:
8217: Arguments:
1.424 albertel 8218: $delayqueue - arrary ref of hash ref of error messages
1.423 albertel 8219: $scanline - the scanline that caused the error
8220: $errormesage - the error message
8221: $errorcode - a numeric code for the error
8222:
8223: Side Effects:
1.424 albertel 8224: updates the $delayqueue to have a new hash ref of the error
1.423 albertel 8225:
8226: =cut
8227:
1.82 albertel 8228: sub scantron_add_delay {
1.140 albertel 8229: my ($delayqueue,$scanline,$errormessage,$errorcode)=@_;
8230: push(@$delayqueue,
8231: {'line' => $scanline, 'emsg' => $errormessage,
8232: 'ecode' => $errorcode }
8233: );
1.82 albertel 8234: }
8235:
1.423 albertel 8236: =pod
8237:
8238: =item scantron_find_student
8239:
1.424 albertel 8240: Finds the username for the current scanline
8241:
8242: Arguments:
8243: $scantron_record - hash result from scantron_parse_scanline
8244: $scan_data - hash of correction information
8245: (see &scantron_getfile() form more information)
8246: $idmap - hash from &username_to_idmap()
8247: $line - number of current scanline
8248:
8249: Returns:
8250: Either 'username:domain' or undef if unknown
8251:
1.423 albertel 8252: =cut
8253:
1.82 albertel 8254: sub scantron_find_student {
1.157 albertel 8255: my ($scantron_record,$scan_data,$idmap,$line)=@_;
1.83 albertel 8256: my $scanID=$$scantron_record{'scantron.ID'};
1.157 albertel 8257: if ($scanID =~ /^\s*$/) {
8258: return &scan_data($scan_data,"$line.user");
8259: }
1.83 albertel 8260: foreach my $id (keys(%$idmap)) {
1.157 albertel 8261: if (lc($id) eq lc($scanID)) {
8262: return $$idmap{$id};
8263: }
1.83 albertel 8264: }
8265: return undef;
8266: }
8267:
1.423 albertel 8268: =pod
8269:
8270: =item scantron_filter
8271:
1.424 albertel 8272: Filter sub for lonnavmaps, filters out hidden resources if ignore
8273: hidden resources was selected
8274:
1.423 albertel 8275: =cut
8276:
1.83 albertel 8277: sub scantron_filter {
8278: my ($curres)=@_;
1.331 albertel 8279:
8280: if (ref($curres) && $curres->is_problem()) {
8281: # if the user has asked to not have either hidden
8282: # or 'randomout' controlled resources to be graded
8283: # don't include them
8284: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
8285: && $curres->randomout) {
8286: return 0;
8287: }
1.83 albertel 8288: return 1;
8289: }
8290: return 0;
1.82 albertel 8291: }
8292:
1.423 albertel 8293: =pod
8294:
8295: =item scantron_process_corrections
8296:
1.424 albertel 8297: Gets correction information out of submitted form data and corrects
8298: the scanline
8299:
1.423 albertel 8300: =cut
8301:
1.157 albertel 8302: sub scantron_process_corrections {
8303: my ($r) = @_;
1.754 raeburn 8304: my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.157 albertel 8305: my ($scanlines,$scan_data)=&scantron_getfile();
8306: my $classlist=&Apache::loncoursedata::get_classlist();
1.257 albertel 8307: my $which=$env{'form.scantron_line'};
1.200 albertel 8308: my $line=&scantron_get_line($scanlines,$scan_data,$which);
1.157 albertel 8309: my ($skip,$err,$errmsg);
1.257 albertel 8310: if ($env{'form.scantron_skip_record'}) {
1.157 albertel 8311: $skip=1;
1.257 albertel 8312: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)ID$/) {
8313: my $newstudent=$env{'form.scantron_username'}.':'.
8314: $env{'form.scantron_domain'};
1.157 albertel 8315: my $newid=$classlist->{$newstudent}->[&Apache::loncoursedata::CL_ID];
8316: ($line,$err,$errmsg)=
8317: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
8318: 'ID',{'newid'=>$newid,
1.257 albertel 8319: 'username'=>$env{'form.scantron_username'},
8320: 'domain'=>$env{'form.scantron_domain'}});
8321: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)CODE$/) {
8322: my $resolution=$env{'form.scantron_CODE_resolution'};
1.190 albertel 8323: my $newCODE;
1.192 albertel 8324: my %args;
1.190 albertel 8325: if ($resolution eq 'use_unfound') {
1.191 albertel 8326: $newCODE='use_unfound';
1.190 albertel 8327: } elsif ($resolution eq 'use_found') {
1.257 albertel 8328: $newCODE=$env{'form.scantron_CODE_selectedvalue'};
1.190 albertel 8329: } elsif ($resolution eq 'use_typed') {
1.257 albertel 8330: $newCODE=$env{'form.scantron_CODE_newvalue'};
1.194 albertel 8331: } elsif ($resolution =~ /^use_closest_(\d+)/) {
1.257 albertel 8332: $newCODE=$env{"form.scantron_CODE_closest_$1"};
1.190 albertel 8333: }
1.257 albertel 8334: if ($env{'form.scantron_corrections'} eq 'duplicateCODE') {
1.192 albertel 8335: $args{'CODE_ignore_dup'}=1;
8336: }
8337: $args{'CODE'}=$newCODE;
1.186 albertel 8338: ($line,$err,$errmsg)=
8339: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
1.192 albertel 8340: 'CODE',\%args);
1.257 albertel 8341: } elsif ($env{'form.scantron_corrections'} =~ /^(missing|double)bubble$/) {
8342: foreach my $question (split(',',$env{'form.scantron_questions'})) {
1.157 albertel 8343: ($line,$err,$errmsg)=
8344: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,
8345: $which,'answer',
8346: { 'question'=>$question,
1.503 raeburn 8347: 'response'=>$env{"form.scantron_correct_Q_$question"},
8348: 'questionnum'=>$env{"form.scantron_questionnum_Q_$question"}});
1.157 albertel 8349: if ($err) { last; }
8350: }
8351: }
8352: if ($err) {
1.703 bisitz 8353: $r->print(
8354: '<p class="LC_error">'
8355: .&mt('Unable to accept last correction, an error occurred: [_1]',
8356: $errmsg)
1.704 raeburn 8357: .'</p>');
1.157 albertel 8358: } else {
1.200 albertel 8359: &scantron_put_line($scanlines,$scan_data,$which,$line,$skip);
1.157 albertel 8360: &scantron_putfile($scanlines,$scan_data);
8361: }
8362: }
8363:
1.423 albertel 8364: =pod
8365:
8366: =item reset_skipping_status
8367:
1.424 albertel 8368: Forgets the current set of remember skipped scanlines (and thus
8369: reverts back to considering all lines in the
8370: scantron_skipped_<filename> file)
8371:
1.423 albertel 8372: =cut
8373:
1.200 albertel 8374: sub reset_skipping_status {
8375: my ($scanlines,$scan_data)=&scantron_getfile();
8376: &scan_data($scan_data,'remember_skipping',undef,1);
8377: &scantron_putfile(undef,$scan_data);
8378: }
8379:
1.423 albertel 8380: =pod
8381:
8382: =item start_skipping
8383:
1.424 albertel 8384: Marks a scanline to be skipped.
8385:
1.423 albertel 8386: =cut
8387:
1.376 albertel 8388: sub start_skipping {
1.200 albertel 8389: my ($scan_data,$i)=@_;
8390: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 8391: if ($env{'form.scantron_options_redo'} =~ /^redo_/) {
8392: $remembered{$i}=2;
8393: } else {
8394: $remembered{$i}=1;
8395: }
1.200 albertel 8396: &scan_data($scan_data,'remember_skipping',join(':',%remembered));
8397: }
8398:
1.423 albertel 8399: =pod
8400:
8401: =item should_be_skipped
8402:
1.424 albertel 8403: Checks whether a scanline should be skipped.
8404:
1.423 albertel 8405: =cut
8406:
1.200 albertel 8407: sub should_be_skipped {
1.376 albertel 8408: my ($scanlines,$scan_data,$i)=@_;
1.257 albertel 8409: if ($env{'form.scantron_options_redo'} !~ /^redo_/) {
1.200 albertel 8410: # not redoing old skips
1.376 albertel 8411: if ($scanlines->{'skipped'}[$i]) { return 1; }
1.200 albertel 8412: return 0;
8413: }
8414: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 8415:
8416: if (exists($remembered{$i}) && $remembered{$i} != 2 ) {
8417: return 0;
8418: }
1.200 albertel 8419: return 1;
8420: }
8421:
1.423 albertel 8422: =pod
8423:
8424: =item remember_current_skipped
8425:
1.424 albertel 8426: Discovers what scanlines are in the scantron_skipped_<filename>
8427: file and remembers them into scan_data for later use.
8428:
1.423 albertel 8429: =cut
8430:
1.200 albertel 8431: sub remember_current_skipped {
8432: my ($scanlines,$scan_data)=&scantron_getfile();
8433: my %to_remember;
8434: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
8435: if ($scanlines->{'skipped'}[$i]) {
8436: $to_remember{$i}=1;
8437: }
8438: }
1.376 albertel 8439:
1.200 albertel 8440: &scan_data($scan_data,'remember_skipping',join(':',%to_remember));
8441: &scantron_putfile(undef,$scan_data);
8442: }
8443:
1.423 albertel 8444: =pod
8445:
8446: =item check_for_error
8447:
1.424 albertel 8448: Checks if there was an error when attempting to remove a specific
1.659 raeburn 8449: scantron_.. bubblesheet data file. Prints out an error if
1.424 albertel 8450: something went wrong.
8451:
1.423 albertel 8452: =cut
8453:
1.200 albertel 8454: sub check_for_error {
8455: my ($r,$result)=@_;
8456: if ($result ne 'ok' && $result ne 'not_found' ) {
1.492 albertel 8457: $r->print(&mt("An error occurred ([_1]) when trying to remove the existing corrections.",$result));
1.200 albertel 8458: }
8459: }
1.157 albertel 8460:
1.423 albertel 8461: =pod
8462:
8463: =item scantron_warning_screen
8464:
1.424 albertel 8465: Interstitial screen to make sure the operator has selected the
8466: correct options before we start the validation phase.
8467:
1.423 albertel 8468: =cut
8469:
1.203 albertel 8470: sub scantron_warning_screen {
1.650 raeburn 8471: my ($button_text,$symb)=@_;
1.257 albertel 8472: my $title=&Apache::lonnet::gettitle($env{'form.selectpage'});
1.754 raeburn 8473: my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.373 albertel 8474: my $CODElist;
1.284 albertel 8475: if ($scantron_config{'CODElocation'} &&
8476: $scantron_config{'CODEstart'} &&
8477: $scantron_config{'CODElength'}) {
8478: $CODElist=$env{'form.scantron_CODElist'};
1.721 bisitz 8479: if ($env{'form.scantron_CODElist'} eq '') { $CODElist='<span class="LC_warning">'.&mt('None').'</span>'; }
1.284 albertel 8480: $CODElist=
1.492 albertel 8481: '<tr><td><b>'.&mt('List of CODES to validate against:').'</b></td><td><tt>'.
1.373 albertel 8482: $env{'form.scantron_CODElist'}.'</tt></td></tr>';
1.284 albertel 8483: }
1.663 raeburn 8484: my $lastbubblepoints;
8485: if ($env{'form.scantron_lastbubblepoints'} ne '') {
8486: $lastbubblepoints =
8487: '<tr><td><b>'.&mt('Hand-graded items: points from last bubble in row').'</b></td><td><tt>'.
8488: $env{'form.scantron_lastbubblepoints'}.'</tt></td></tr>';
8489: }
1.770 raeburn 8490: return '
1.203 albertel 8491: <p>
1.492 albertel 8492: <span class="LC_warning">
1.705 raeburn 8493: '.&mt("Please double check the information below before clicking on '[_1]'",&mt($button_text)).'</span>
1.203 albertel 8494: </p>
8495: <table>
1.492 albertel 8496: <tr><td><b>'.&mt('Sequence to be Graded:').'</b></td><td>'.$title.'</td></tr>
8497: <tr><td><b>'.&mt('Data File that will be used:').'</b></td><td><tt>'.$env{'form.scantron_selectfile'}.'</tt></td></tr>
1.663 raeburn 8498: '.$CODElist.$lastbubblepoints.'
1.203 albertel 8499: </table>
1.680 raeburn 8500: <p> '.&mt("If this information is correct, please click on '[_1]'.",&mt($button_text)).'<br />
1.650 raeburn 8501: '.&mt('If something is incorrect, please return to [_1]Grade/Manage/Review Bubblesheets[_2] to start over.','<a href="/adm/grades?symb='.$symb.'&command=scantron_selectphase" class="LC_info">','</a>').'</p>
1.770 raeburn 8502: ';
1.203 albertel 8503: }
8504:
1.423 albertel 8505: =pod
8506:
8507: =item scantron_do_warning
8508:
1.424 albertel 8509: Check if the operator has picked something for all required
8510: fields. Error out if something is missing.
8511:
1.423 albertel 8512: =cut
8513:
1.203 albertel 8514: sub scantron_do_warning {
1.608 www 8515: my ($r,$symb)=@_;
1.203 albertel 8516: if (!$symb) {return '';}
1.324 albertel 8517: my $default_form_data=&defaultFormData($symb);
1.203 albertel 8518: $r->print(&scantron_form_start().$default_form_data);
1.257 albertel 8519: if ( $env{'form.selectpage'} eq '' ||
8520: $env{'form.scantron_selectfile'} eq '' ||
8521: $env{'form.scantron_format'} eq '' ) {
1.642 raeburn 8522: $r->print("<p>".&mt('You have forgotten to specify some information. Please go Back and try again.')."</p>");
1.257 albertel 8523: if ( $env{'form.selectpage'} eq '') {
1.492 albertel 8524: $r->print('<p><span class="LC_error">'.&mt('You have not selected a Sequence to grade').'</span></p>');
1.237 albertel 8525: }
1.257 albertel 8526: if ( $env{'form.scantron_selectfile'} eq '') {
1.642 raeburn 8527: $r->print('<p><span class="LC_error">'.&mt("You have not selected a file that contains the student's response data.").'</span></p>');
1.770 raeburn 8528: }
1.257 albertel 8529: if ( $env{'form.scantron_format'} eq '') {
1.642 raeburn 8530: $r->print('<p><span class="LC_error">'.&mt("You have not selected the format of the student's response data.").'</span></p>');
1.770 raeburn 8531: }
1.237 albertel 8532: } else {
1.650 raeburn 8533: my $warning=&scantron_warning_screen('Grading: Validate Records',$symb);
1.770 raeburn 8534: my ($checksec,@possibles) = &gradable_sections();
8535: my $gradesections;
8536: if ($checksec) {
8537: my $file=$env{'form.scantron_selectfile'};
8538: if (&valid_file($file)) {
8539: my %bysec = &scantron_get_sections();
8540: my $table;
8541: if ((keys(%bysec) > 1) || ((keys(%bysec) == 1) && ((keys(%bysec))[0] ne $checksec))) {
8542: $gradesections = &mt('Your current role is for section [_1].','<i>'.$checksec.'</i>').'<br />';
8543: $table = &Apache::loncommon::start_data_table()."\n".
8544: &Apache::loncommon::start_data_table_header_row().
8545: '<th>'.&mt('Section').'</th><th>'.&mt('Number of records').'</th>'.
8546: &Apache::loncommon::end_data_table_header_row()."\n";
8547: if ($bysec{'none'}) {
8548: $table .= &Apache::loncommon::start_data_table_row().
8549: '<td>'.&mt('None').'</td><td>'.$bysec{'none'}.'</td>'.
8550: &Apache::loncommon::end_data_table_row()."\n";
8551: }
8552: foreach my $sec (sort { $a <=> $b } keys(%bysec)) {
8553: next if ($sec eq 'none');
8554: $table .= &Apache::loncommon::start_data_table_row().
8555: '<td>'.$sec.'</td><td>'.$bysec{$sec}.'</td>'.
8556: &Apache::loncommon::end_data_table_row()."\n";
8557: }
8558: $table .= &Apache::loncommon::end_data_table()."\n";
8559: $gradesections .= &mt('Sections represented in the bubblesheet data file (based on bubbled student IDs) are as follows:').
8560: '<p>'.$table.'</p>';
8561: if (@possibles) {
8562: $gradesections .= '<p>'.
8563: &mt('You have role(s) in [quant,_1,other section,other sections] with privileges to manage grades.',
8564: scalar(@possibles)).'<br />'.
8565: &mt('Check which of those section(s), in addition to section [_1], you wish to grade using this bubblesheet file:',
8566: '<i>'.$checksec.'</i>').' ';
8567: foreach my $sec (sort {$a <=> $b } @possibles) {
8568: $gradesections .= '<label><input type="checkbox" name="scantron_othersections" value="'.$sec.'" />'.$sec.'</label>'.(' 'x2);
8569: }
8570: $gradesections .= '</p>';
8571: }
8572: }
8573: } else {
8574: $gradesections = '<p class="LC_error">'.&mt('The selected file is unavailable').'</p>';
8575: }
8576: }
1.663 raeburn 8577: my $bubbledbyhand=&hand_bubble_option();
1.492 albertel 8578: $r->print('
1.770 raeburn 8579: '.$warning.$gradesections.$bubbledbyhand.'
1.492 albertel 8580: <input type="submit" name="submit" value="'.&mt('Grading: Validate Records').'" />
1.203 albertel 8581: <input type="hidden" name="command" value="scantron_validate" />
1.492 albertel 8582: ');
1.237 albertel 8583: }
1.614 www 8584: $r->print("</form><br />");
1.203 albertel 8585: return '';
8586: }
8587:
1.423 albertel 8588: =pod
8589:
8590: =item scantron_form_start
8591:
1.424 albertel 8592: html hidden input for remembering all selected grading options
8593:
1.423 albertel 8594: =cut
8595:
1.203 albertel 8596: sub scantron_form_start {
8597: my ($max_bubble)=@_;
8598: my $result= <<SCANTRONFORM;
8599: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
1.257 albertel 8600: <input type="hidden" name="selectpage" value="$env{'form.selectpage'}" />
8601: <input type="hidden" name="scantron_format" value="$env{'form.scantron_format'}" />
8602: <input type="hidden" name="scantron_selectfile" value="$env{'form.scantron_selectfile'}" />
1.218 albertel 8603: <input type="hidden" name="scantron_maxbubble" value="$max_bubble" />
1.257 albertel 8604: <input type="hidden" name="scantron_CODElist" value="$env{'form.scantron_CODElist'}" />
8605: <input type="hidden" name="scantron_CODEunique" value="$env{'form.scantron_CODEunique'}" />
8606: <input type="hidden" name="scantron_options_redo" value="$env{'form.scantron_options_redo'}" />
8607: <input type="hidden" name="scantron_options_ignore" value="$env{'form.scantron_options_ignore'}" />
1.331 albertel 8608: <input type="hidden" name="scantron_options_hidden" value="$env{'form.scantron_options_hidden'}" />
1.203 albertel 8609: SCANTRONFORM
1.447 foxr 8610:
8611: my $line = 0;
8612: while (defined($env{"form.scantron.bubblelines.$line"})) {
8613: my $chunk =
8614: '<input type="hidden" name="scantron.bubblelines.'.$line.'" value="'.$env{"form.scantron.bubblelines.$line"}.'" />'."\n";
1.448 foxr 8615: $chunk .=
8616: '<input type="hidden" name="scantron.first_bubble_line.'.$line.'" value="'.$env{"form.scantron.first_bubble_line.$line"}.'" />'."\n";
1.503 raeburn 8617: $chunk .=
8618: '<input type="hidden" name="scantron.sub_bubblelines.'.$line.'" value="'.$env{"form.scantron.sub_bubblelines.$line"}.'" />'."\n";
1.504 raeburn 8619: $chunk .=
8620: '<input type="hidden" name="scantron.responsetype.'.$line.'" value="'.$env{"form.scantron.responsetype.$line"}.'" />'."\n";
1.691 raeburn 8621: $chunk .=
8622: '<input type="hidden" name="scantron.residpart.'.$line.'" value="'.$env{"form.scantron.residpart.$line"}.'" />'."\n";
1.447 foxr 8623: $result .= $chunk;
8624: $line++;
1.691 raeburn 8625: }
1.203 albertel 8626: return $result;
8627: }
8628:
1.423 albertel 8629: =pod
8630:
8631: =item scantron_validate_file
8632:
1.659 raeburn 8633: Dispatch routine for doing validation of a bubblesheet data file.
1.424 albertel 8634:
8635: Also processes any necessary information resets that need to
8636: occur before validation begins (ignore previous corrections,
8637: restarting the skipped records processing)
8638:
1.423 albertel 8639: =cut
8640:
1.157 albertel 8641: sub scantron_validate_file {
1.608 www 8642: my ($r,$symb) = @_;
1.157 albertel 8643: if (!$symb) {return '';}
1.324 albertel 8644: my $default_form_data=&defaultFormData($symb);
1.200 albertel 8645:
1.703 bisitz 8646: # do the detection of only doing skipped records first before we delete
1.424 albertel 8647: # them when doing the corrections reset
1.257 albertel 8648: if ($env{'form.scantron_options_redo'} ne 'redo_skipped_ready') {
1.200 albertel 8649: &reset_skipping_status();
8650: }
1.257 albertel 8651: if ($env{'form.scantron_options_redo'} eq 'redo_skipped') {
1.200 albertel 8652: &remember_current_skipped();
1.257 albertel 8653: $env{'form.scantron_options_redo'}='redo_skipped_ready';
1.200 albertel 8654: }
8655:
1.257 albertel 8656: if ($env{'form.scantron_options_ignore'} eq 'ignore_corrections') {
1.200 albertel 8657: &check_for_error($r,&scantron_remove_file('corrected'));
8658: &check_for_error($r,&scantron_remove_file('skipped'));
8659: &check_for_error($r,&scantron_remove_scan_data());
1.257 albertel 8660: $env{'form.scantron_options_ignore'}='done';
1.192 albertel 8661: }
1.200 albertel 8662:
1.257 albertel 8663: if ($env{'form.scantron_corrections'}) {
1.157 albertel 8664: &scantron_process_corrections($r);
8665: }
1.770 raeburn 8666:
8667: $r->print('<p>'.&mt('Gathering necessary information.').'</p>');
8668: my ($checksec,@gradable);
8669: if ($env{'request.course.sec'}) {
8670: ($checksec,my @possibles) = &gradable_sections();
8671: if ($checksec) {
8672: if (@possibles) {
8673: my @chosensecs = &Apache::loncommon::get_env_multiple('form.scantron_othersections');
8674: if (@chosensecs) {
8675: foreach my $sec (@chosensecs) {
8676: if (grep(/^\Q$sec\E$/,@possibles)) {
8677: unless (grep(/^\Q$sec\E$/,@gradable)) {
8678: push(@gradable,$sec);
8679: }
8680: }
8681: }
8682: }
8683: }
8684: $r->print('<p><table>');
8685: if (@gradable) {
8686: my @showsections = sort { $a <=> $b } (@gradable,$checksec);
8687: $r->print(
8688: '<tr><td><b>'.&mt('Sections to be Graded:').'</b></td><td>'.join(', ',@showsections).'</td></tr>');
8689: } else {
8690: $r->print(
8691: '<tr><td><b>'.&mt('Section to be Graded:').'</b></td><td>'.$checksec.'</td></tr>');
8692: }
8693: $r->print('</table></p>');
8694: }
8695: }
8696: $r->rflush();
8697:
1.157 albertel 8698: #get the student pick code ready
8699: $r->print(&Apache::loncommon::studentbrowser_javascript());
1.582 raeburn 8700: my $nav_error;
1.754 raeburn 8701: my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.649 raeburn 8702: my $max_bubble=&scantron_get_maxbubble(\$nav_error,\%scantron_config);
1.582 raeburn 8703: if ($nav_error) {
8704: $r->print(&navmap_errormsg());
8705: return '';
8706: }
1.203 albertel 8707: my $result=&scantron_form_start($max_bubble).$default_form_data;
1.663 raeburn 8708: if ($env{'form.scantron_lastbubblepoints'} ne '') {
8709: $result .= '<input type="hidden" name="scantron_lastbubblepoints" value="'.$env{'form.scantron_lastbubblepoints'}.'" />';
8710: }
1.157 albertel 8711: $r->print($result);
8712:
1.334 albertel 8713: my @validate_phases=( 'sequence',
8714: 'ID',
1.157 albertel 8715: 'CODE',
8716: 'doublebubble',
8717: 'missingbubbles');
1.257 albertel 8718: if (!$env{'form.validatepass'}) {
8719: $env{'form.validatepass'} = 0;
1.157 albertel 8720: }
1.257 albertel 8721: my $currentphase=$env{'form.validatepass'};
1.770 raeburn 8722: my %skipbysec=();
1.448 foxr 8723:
1.157 albertel 8724: my $stop=0;
8725: while (!$stop && $currentphase < scalar(@validate_phases)) {
1.503 raeburn 8726: $r->print(&mt('Validating '.$validate_phases[$currentphase]).'<br />');
1.157 albertel 8727: $r->rflush();
1.691 raeburn 8728:
1.157 albertel 8729: my $which="scantron_validate_".$validate_phases[$currentphase];
8730: {
8731: no strict 'refs';
1.770 raeburn 8732: my @extras=();
8733: if ($validate_phases[$currentphase] eq 'ID') {
8734: @extras = (\%skipbysec,$checksec,@gradable);
8735: }
8736: ($stop,$currentphase)=&$which($r,$currentphase,@extras);
1.157 albertel 8737: }
8738: }
8739: if (!$stop) {
1.650 raeburn 8740: my $warning=&scantron_warning_screen('Start Grading',$symb);
1.770 raeburn 8741: my $secinfo;
8742: if (keys(%skipbysec) > 0) {
8743: my $seclist = '<ul>';
8744: foreach my $sec (sort { $a <=> $b } keys(%skipbysec)) {
8745: $seclist .= '<li>'.&mt('section [_1]: [_2]',$sec,$skipbysec{$sec}).'</li>';
8746: }
8747: $seclist .= '</ul>';
8748: $secinfo = '<p class="LC_info">'.
8749: &mt('Numbers of records for students in sections not being graded [_1]',
8750: $seclist).
8751: '</p>';
8752: }
1.542 raeburn 8753: $r->print(&mt('Validation process complete.').'<br />'.
1.770 raeburn 8754: $secinfo.$warning.
1.542 raeburn 8755: &mt('Perform verification for each student after storage of submissions?').
8756: ' <span class="LC_nobreak"><label>'.
8757: '<input type="radio" name="verifyrecord" value="1" />'.&mt('Yes').'</label>'.
8758: (' 'x3).'<label>'.
8759: '<input type="radio" name="verifyrecord" value="0" checked="checked" />'.&mt('No').
8760: '</label></span><br />'.
8761: &mt('Grading will take longer if you use verification.').'<br />'.
1.650 raeburn 8762: &mt('Otherwise, Grade/Manage/Review Bubblesheets [_1] Review bubblesheet data can be used once grading is complete.','»').'<br /><br />'.
1.542 raeburn 8763: '<input type="submit" name="submit" value="'.&mt('Start Grading').'" />'.
8764: '<input type="hidden" name="command" value="scantron_process" />'."\n");
1.157 albertel 8765: } else {
8766: $r->print('<input type="hidden" name="command" value="scantron_validate" />');
8767: $r->print("<input type='hidden' name='validatepass' value='".$currentphase."' />");
8768: }
8769: if ($stop) {
1.334 albertel 8770: if ($validate_phases[$currentphase] eq 'sequence') {
1.539 riegler 8771: $r->print('<input type="submit" name="submit" value="'.&mt('Ignore').' → " />');
1.492 albertel 8772: $r->print(' '.&mt('this error').' <br />');
1.334 albertel 8773:
1.650 raeburn 8774: $r->print('<p>'.&mt('Or return to [_1]Grade/Manage/Review Bubblesheets[_2] to start over.','<a href="/adm/grades?symb='.$symb.'&command=scantron_selectphase" class="LC_info">','</a>').'</p>');
1.334 albertel 8775: } else {
1.503 raeburn 8776: if ($validate_phases[$currentphase] eq 'doublebubble' || $validate_phases[$currentphase] eq 'missingbubbles') {
1.539 riegler 8777: $r->print('<input type="button" name="submitbutton" value="'.&mt('Continue').' →" onclick="javascript:verify_bubble_radio(this.form)" />');
1.503 raeburn 8778: } else {
1.539 riegler 8779: $r->print('<input type="submit" name="submit" value="'.&mt('Continue').' →" />');
1.503 raeburn 8780: }
1.492 albertel 8781: $r->print(' '.&mt('using corrected info').' <br />');
8782: $r->print("<input type='submit' value='".&mt("Skip")."' name='scantron_skip_record' />");
8783: $r->print(" ".&mt("this scanline saving it for later."));
1.334 albertel 8784: }
1.157 albertel 8785: }
1.614 www 8786: $r->print(" </form><br />");
1.157 albertel 8787: return '';
8788: }
8789:
1.423 albertel 8790:
8791: =pod
8792:
8793: =item scantron_remove_file
8794:
1.659 raeburn 8795: Removes the requested bubblesheet data file, makes sure that
1.424 albertel 8796: scantron_original_<filename> is never removed
8797:
8798:
1.423 albertel 8799: =cut
8800:
1.200 albertel 8801: sub scantron_remove_file {
1.192 albertel 8802: my ($which)=@_;
1.257 albertel 8803: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
8804: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 8805: my $file='scantron_';
1.200 albertel 8806: if ($which eq 'corrected' || $which eq 'skipped') {
8807: $file.=$which.'_';
1.192 albertel 8808: } else {
8809: return 'refused';
8810: }
1.257 albertel 8811: $file.=$env{'form.scantron_selectfile'};
1.200 albertel 8812: return &Apache::lonnet::removeuserfile($cname,$cdom,$file);
8813: }
8814:
1.423 albertel 8815:
8816: =pod
8817:
8818: =item scantron_remove_scan_data
8819:
1.659 raeburn 8820: Removes all scan_data correction for the requested bubblesheet
1.424 albertel 8821: data file. (In the case that both the are doing skipped records we need
8822: to remember the old skipped lines for the time being so that element
8823: persists for a while.)
8824:
1.423 albertel 8825: =cut
8826:
1.200 albertel 8827: sub scantron_remove_scan_data {
1.257 albertel 8828: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
8829: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 8830: my @keys=&Apache::lonnet::getkeys('nohist_scantrondata',$cdom,$cname);
8831: my @todelete;
1.257 albertel 8832: my $filename=$env{'form.scantron_selectfile'};
1.192 albertel 8833: foreach my $key (@keys) {
8834: if ($key=~/^\Q$filename\E_/) {
1.257 albertel 8835: if ($env{'form.scantron_options_redo'} eq 'redo_skipped_ready' &&
1.200 albertel 8836: $key=~/remember_skipping/) {
8837: next;
8838: }
1.192 albertel 8839: push(@todelete,$key);
8840: }
8841: }
1.200 albertel 8842: my $result;
1.192 albertel 8843: if (@todelete) {
1.491 albertel 8844: $result = &Apache::lonnet::del('nohist_scantrondata',
8845: \@todelete,$cdom,$cname);
8846: } else {
8847: $result = 'ok';
1.192 albertel 8848: }
8849: return $result;
8850: }
8851:
1.423 albertel 8852:
8853: =pod
8854:
8855: =item scantron_getfile
8856:
1.659 raeburn 8857: Fetches the requested bubblesheet data file (all 3 versions), and
1.424 albertel 8858: the scan_data hash
8859:
8860: Arguments:
8861: None
8862:
8863: Returns:
8864: 2 hash references
8865:
8866: - first one has
8867: orig -
8868: corrected -
8869: skipped - each of which points to an array ref of the specified
8870: file broken up into individual lines
8871: count - number of scanlines
8872:
8873: - second is the scan_data hash possible keys are
1.425 albertel 8874: ($number refers to scanline numbered $number and thus the key affects
8875: only that scanline
8876: $bubline refers to the specific bubble line element and the aspects
8877: refers to that specific bubble line element)
8878:
8879: $number.user - username:domain to use
8880: $number.CODE_ignore_dup
8881: - ignore the duplicate CODE error
8882: $number.useCODE
8883: - use the CODE in the scanline as is
8884: $number.no_bubble.$bubline
8885: - it is valid that there is no bubbled in bubble
8886: at $number $bubline
8887: remember_skipping
8888: - a frozen hash containing keys of $number and values
8889: of either
8890: 1 - we are on a 'do skipped records pass' and plan
8891: on processing this line
8892: 2 - we are on a 'do skipped records pass' and this
8893: scanline has been marked to skip yet again
1.424 albertel 8894:
1.423 albertel 8895: =cut
8896:
1.157 albertel 8897: sub scantron_getfile {
1.200 albertel 8898: #FIXME really would prefer a scantron directory
1.257 albertel 8899: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
8900: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.157 albertel 8901: my $lines;
8902: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 8903: 'scantron_orig_'.$env{'form.scantron_selectfile'});
1.157 albertel 8904: my %scanlines;
8905: $scanlines{'orig'}=[(split("\n",$lines,-1))];
8906: my $temp=$scanlines{'orig'};
8907: $scanlines{'count'}=$#$temp;
8908:
8909: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 8910: 'scantron_corrected_'.$env{'form.scantron_selectfile'});
1.157 albertel 8911: if ($lines eq '-1') {
8912: $scanlines{'corrected'}=[];
8913: } else {
8914: $scanlines{'corrected'}=[(split("\n",$lines,-1))];
8915: }
8916: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 8917: 'scantron_skipped_'.$env{'form.scantron_selectfile'});
1.157 albertel 8918: if ($lines eq '-1') {
8919: $scanlines{'skipped'}=[];
8920: } else {
8921: $scanlines{'skipped'}=[(split("\n",$lines,-1))];
8922: }
1.175 albertel 8923: my @tmp=&Apache::lonnet::dump('nohist_scantrondata',$cdom,$cname);
1.157 albertel 8924: if ($tmp[0] =~ /^(error:|no_such_host)/) { @tmp=(); }
8925: my %scan_data = @tmp;
8926: return (\%scanlines,\%scan_data);
8927: }
8928:
1.423 albertel 8929: =pod
8930:
8931: =item lonnet_putfile
8932:
1.424 albertel 8933: Wrapper routine to call &Apache::lonnet::finishuserfileupload
8934:
8935: Arguments:
8936: $contents - data to store
8937: $filename - filename to store $contents into
8938:
8939: Returns:
8940: result value from &Apache::lonnet::finishuserfileupload
8941:
1.423 albertel 8942: =cut
8943:
1.157 albertel 8944: sub lonnet_putfile {
8945: my ($contents,$filename)=@_;
1.257 albertel 8946: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
8947: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
8948: $env{'form.sillywaytopassafilearound'}=$contents;
1.275 albertel 8949: &Apache::lonnet::finishuserfileupload($docuname,$docudom,'sillywaytopassafilearound',$filename);
1.157 albertel 8950:
8951: }
8952:
1.423 albertel 8953: =pod
8954:
8955: =item scantron_putfile
8956:
1.659 raeburn 8957: Stores the current version of the bubblesheet data files, and the
1.424 albertel 8958: scan_data hash. (Does not modify the original version only the
8959: corrected and skipped versions.
8960:
8961: Arguments:
8962: $scanlines - hash ref that looks like the first return value from
8963: &scantron_getfile()
8964: $scan_data - hash ref that looks like the second return value from
8965: &scantron_getfile()
8966:
1.423 albertel 8967: =cut
8968:
1.157 albertel 8969: sub scantron_putfile {
8970: my ($scanlines,$scan_data) = @_;
1.200 albertel 8971: #FIXME really would prefer a scantron directory
1.257 albertel 8972: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
8973: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.200 albertel 8974: if ($scanlines) {
8975: my $prefix='scantron_';
1.157 albertel 8976: # no need to update orig, shouldn't change
8977: # &lonnet_putfile(join("\n",@{$scanlines->{'orig'}}),$prefix.'orig_'.
1.257 albertel 8978: # $env{'form.scantron_selectfile'});
1.200 albertel 8979: &lonnet_putfile(join("\n",@{$scanlines->{'corrected'}}),
8980: $prefix.'corrected_'.
1.257 albertel 8981: $env{'form.scantron_selectfile'});
1.200 albertel 8982: &lonnet_putfile(join("\n",@{$scanlines->{'skipped'}}),
8983: $prefix.'skipped_'.
1.257 albertel 8984: $env{'form.scantron_selectfile'});
1.200 albertel 8985: }
1.175 albertel 8986: &Apache::lonnet::put('nohist_scantrondata',$scan_data,$cdom,$cname);
1.157 albertel 8987: }
8988:
1.423 albertel 8989: =pod
8990:
8991: =item scantron_get_line
8992:
1.424 albertel 8993: Returns the correct version of the scanline
8994:
8995: Arguments:
8996: $scanlines - hash ref that looks like the first return value from
8997: &scantron_getfile()
8998: $scan_data - hash ref that looks like the second return value from
8999: &scantron_getfile()
9000: $i - number of the requested line (starts at 0)
9001:
9002: Returns:
9003: A scanline, (either the original or the corrected one if it
9004: exists), or undef if the requested scanline should be
9005: skipped. (Either because it's an skipped scanline, or it's an
9006: unskipped scanline and we are not doing a 'do skipped scanlines'
9007: pass.
9008:
1.423 albertel 9009: =cut
9010:
1.157 albertel 9011: sub scantron_get_line {
1.200 albertel 9012: my ($scanlines,$scan_data,$i)=@_;
1.376 albertel 9013: if (&should_be_skipped($scanlines,$scan_data,$i)) { return undef; }
9014: #if ($scanlines->{'skipped'}[$i]) { return undef; }
1.157 albertel 9015: if ($scanlines->{'corrected'}[$i]) {return $scanlines->{'corrected'}[$i];}
9016: return $scanlines->{'orig'}[$i];
9017: }
9018:
1.423 albertel 9019: =pod
9020:
9021: =item scantron_todo_count
9022:
1.424 albertel 9023: Counts the number of scanlines that need processing.
9024:
9025: Arguments:
9026: $scanlines - hash ref that looks like the first return value from
9027: &scantron_getfile()
9028: $scan_data - hash ref that looks like the second return value from
9029: &scantron_getfile()
9030:
9031: Returns:
9032: $count - number of scanlines to process
9033:
1.423 albertel 9034: =cut
9035:
1.200 albertel 9036: sub get_todo_count {
9037: my ($scanlines,$scan_data)=@_;
9038: my $count=0;
9039: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
9040: my $line=&scantron_get_line($scanlines,$scan_data,$i);
9041: if ($line=~/^[\s\cz]*$/) { next; }
9042: $count++;
9043: }
9044: return $count;
9045: }
9046:
1.423 albertel 9047: =pod
9048:
9049: =item scantron_put_line
9050:
1.659 raeburn 9051: Updates the 'corrected' or 'skipped' versions of the bubblesheet
1.424 albertel 9052: data file.
9053:
9054: Arguments:
9055: $scanlines - hash ref that looks like the first return value from
9056: &scantron_getfile()
9057: $scan_data - hash ref that looks like the second return value from
9058: &scantron_getfile()
9059: $i - line number to update
9060: $newline - contents of the updated scanline
9061: $skip - if true make the line for skipping and update the
9062: 'skipped' file
9063:
1.423 albertel 9064: =cut
9065:
1.157 albertel 9066: sub scantron_put_line {
1.200 albertel 9067: my ($scanlines,$scan_data,$i,$newline,$skip)=@_;
1.157 albertel 9068: if ($skip) {
9069: $scanlines->{'skipped'}[$i]=$newline;
1.376 albertel 9070: &start_skipping($scan_data,$i);
1.157 albertel 9071: return;
9072: }
9073: $scanlines->{'corrected'}[$i]=$newline;
9074: }
9075:
1.423 albertel 9076: =pod
9077:
9078: =item scantron_clear_skip
9079:
1.424 albertel 9080: Remove a line from the 'skipped' file
9081:
9082: Arguments:
9083: $scanlines - hash ref that looks like the first return value from
9084: &scantron_getfile()
9085: $scan_data - hash ref that looks like the second return value from
9086: &scantron_getfile()
9087: $i - line number to update
9088:
1.423 albertel 9089: =cut
9090:
1.376 albertel 9091: sub scantron_clear_skip {
9092: my ($scanlines,$scan_data,$i)=@_;
9093: if (exists($scanlines->{'skipped'}[$i])) {
9094: undef($scanlines->{'skipped'}[$i]);
9095: return 1;
9096: }
9097: return 0;
9098: }
9099:
1.423 albertel 9100: =pod
9101:
9102: =item scantron_filter_not_exam
9103:
1.424 albertel 9104: Filter routine used by &Apache::lonnavmaps::retrieveResources(), to
9105: filter out resources that are not marked as 'exam' mode
9106:
1.423 albertel 9107: =cut
9108:
1.334 albertel 9109: sub scantron_filter_not_exam {
9110: my ($curres)=@_;
9111:
9112: if (ref($curres) && $curres->is_problem() && !$curres->is_exam()) {
9113: # if the user has asked to not have either hidden
9114: # or 'randomout' controlled resources to be graded
9115: # don't include them
9116: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
9117: && $curres->randomout) {
9118: return 0;
9119: }
9120: return 1;
9121: }
9122: return 0;
9123: }
9124:
1.423 albertel 9125: =pod
9126:
9127: =item scantron_validate_sequence
9128:
1.424 albertel 9129: Validates the selected sequence, checking for resource that are
9130: not set to exam mode.
9131:
1.423 albertel 9132: =cut
9133:
1.334 albertel 9134: sub scantron_validate_sequence {
9135: my ($r,$currentphase) = @_;
9136:
9137: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 9138: unless (ref($navmap)) {
9139: $r->print(&navmap_errormsg());
9140: return (1,$currentphase);
9141: }
1.334 albertel 9142: my (undef,undef,$sequence)=
9143: &Apache::lonnet::decode_symb($env{'form.selectpage'});
9144:
9145: my $map=$navmap->getResourceByUrl($sequence);
9146:
9147: $r->print('<input type="hidden" name="validate_sequence_exam"
9148: value="ignore" />');
9149: if ($env{'form.validate_sequence_exam'} ne 'ignore') {
9150: my @resources=
9151: $navmap->retrieveResources($map,\&scantron_filter_not_exam,1,0);
9152: if (@resources) {
1.675 bisitz 9153: $r->print(
9154: '<p class="LC_warning">'
9155: .&mt('Some resources in the sequence currently are not set to'
1.684 bisitz 9156: .' bubblesheet exam mode. Grading these resources currently may not'
1.675 bisitz 9157: .' work correctly.')
9158: .'</p>'
9159: );
1.334 albertel 9160: return (1,$currentphase);
9161: }
9162: }
9163:
9164: return (0,$currentphase+1);
9165: }
9166:
1.423 albertel 9167:
9168:
1.157 albertel 9169: sub scantron_validate_ID {
1.770 raeburn 9170: my ($r,$currentphase,$skipbysec,$checksec,@gradable) = @_;
1.157 albertel 9171:
9172: #get student info
9173: my $classlist=&Apache::loncoursedata::get_classlist();
9174: my %idmap=&username_to_idmap($classlist);
1.770 raeburn 9175: my $secidx = &Apache::loncoursedata::CL_SECTION();
1.157 albertel 9176:
9177: #get scantron line setup
1.754 raeburn 9178: my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.157 albertel 9179: my ($scanlines,$scan_data)=&scantron_getfile();
1.582 raeburn 9180:
9181: my $nav_error;
1.649 raeburn 9182: &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the bubble_lines.. array.
1.582 raeburn 9183: if ($nav_error) {
9184: $r->print(&navmap_errormsg());
9185: return(1,$currentphase);
9186: }
1.157 albertel 9187:
9188: my %found=('ids'=>{},'usernames'=>{});
1.770 raeburn 9189: my $unsavedskips = 0;
1.157 albertel 9190: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 9191: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 9192: if ($line=~/^[\s\cz]*$/) { next; }
9193: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
9194: $scan_data);
9195: my $id=$$scan_record{'scantron.ID'};
9196: my $found;
9197: foreach my $checkid (keys(%idmap)) {
9198: if (lc($checkid) eq lc($id)) { $found=$checkid;last; }
9199: }
9200: if ($found) {
9201: my $username=$idmap{$found};
1.770 raeburn 9202: if ($checksec) {
9203: if (ref($classlist->{$username}) eq 'ARRAY') {
9204: my $stusec = $classlist->{$username}->[$secidx];
9205: if ($stusec ne $checksec) {
9206: unless ((@gradable > 0) && (grep(/^\Q$stusec\E$/,@gradable))) {
9207: my $skip=1;
9208: &scantron_put_line($scanlines,$scan_data,$i,$line,$skip);
9209: if (ref($skipbysec) eq 'HASH') {
9210: if ($stusec eq '') {
9211: $skipbysec->{'none'} ++;
9212: } else {
9213: $skipbysec->{$stusec} ++;
9214: }
9215: }
9216: $unsavedskips ++;
9217: next;
9218: }
9219: }
9220: }
9221: }
1.157 albertel 9222: if ($found{'ids'}{$found}) {
9223: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
9224: $line,'duplicateID',$found);
1.770 raeburn 9225: if ($unsavedskips) {
9226: &scantron_putfile($scanlines,$scan_data);
9227: $unsavedskips = 0;
9228: }
1.194 albertel 9229: return(1,$currentphase);
1.157 albertel 9230: } elsif ($found{'usernames'}{$username}) {
9231: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
9232: $line,'duplicateID',$username);
1.770 raeburn 9233: if ($unsavedskips) {
9234: &scantron_putfile($scanlines,$scan_data);
9235: $unsavedskips = 0;
9236: }
1.194 albertel 9237: return(1,$currentphase);
1.157 albertel 9238: }
1.186 albertel 9239: #FIXME store away line we previously saw the ID on to use above
1.157 albertel 9240: $found{'ids'}{$found}++;
9241: $found{'usernames'}{$username}++;
9242: } else {
9243: if ($id =~ /^\s*$/) {
1.158 albertel 9244: my $username=&scan_data($scan_data,"$i.user");
1.770 raeburn 9245: if (($checksec && $username ne '')) {
9246: if (ref($classlist->{$username}) eq 'ARRAY') {
9247: my $stusec = $classlist->{$username}->[$secidx];
9248: if ($stusec ne $checksec) {
9249: unless ((@gradable > 0) && (grep(/^\Q$stusec\E$/,@gradable))) {
9250: my $skip=1;
9251: &scantron_put_line($scanlines,$scan_data,$i,$line,$skip);
9252: if (ref($skipbysec) eq 'HASH') {
9253: if ($stusec eq '') {
9254: $skipbysec->{'none'} ++;
9255: } else {
9256: $skipbysec->{$stusec} ++;
9257: }
9258: }
9259: $unsavedskips ++;
9260: next;
9261: }
9262: }
9263: }
9264: } elsif (defined($username) && $found{'usernames'}{$username}) {
1.157 albertel 9265: &scantron_get_correction($r,$i,$scan_record,
9266: \%scantron_config,
9267: $line,'duplicateID',$username);
1.770 raeburn 9268: if ($unsavedskips) {
9269: &scantron_putfile($scanlines,$scan_data);
9270: $unsavedskips = 0;
9271: }
1.194 albertel 9272: return(1,$currentphase);
1.157 albertel 9273: } elsif (!defined($username)) {
9274: &scantron_get_correction($r,$i,$scan_record,
9275: \%scantron_config,
9276: $line,'incorrectID');
1.770 raeburn 9277: if ($unsavedskips) {
9278: &scantron_putfile($scanlines,$scan_data);
9279: $unsavedskips = 0;
9280: }
1.194 albertel 9281: return(1,$currentphase);
1.157 albertel 9282: }
9283: $found{'usernames'}{$username}++;
9284: } else {
9285: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
9286: $line,'incorrectID');
1.770 raeburn 9287: if ($unsavedskips) {
9288: &scantron_putfile($scanlines,$scan_data);
9289: $unsavedskips = 0;
9290: }
1.194 albertel 9291: return(1,$currentphase);
1.157 albertel 9292: }
9293: }
9294: }
1.770 raeburn 9295: if ($unsavedskips) {
9296: &scantron_putfile($scanlines,$scan_data);
9297: $unsavedskips = 0;
9298: }
1.157 albertel 9299: return (0,$currentphase+1);
9300: }
9301:
1.770 raeburn 9302: sub scantron_get_sections {
9303: my %bysec;
9304: if ($env{'form.scantron_format'} ne '') {
9305: my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
9306: my ($scanlines,$scan_data)=&scantron_getfile();
9307: my $classlist=&Apache::loncoursedata::get_classlist();
9308: my %idmap=&username_to_idmap($classlist);
9309: foreach my $key (keys(%idmap)) {
9310: my $lckey = lc($key);
9311: $idmap{$lckey} = $idmap{$key};
9312: }
9313: my $secidx = &Apache::loncoursedata::CL_SECTION();
9314: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
9315: my $line=&scantron_get_line($scanlines,$scan_data,$i);
9316: if ($line=~/^[\s\cz]*$/) { next; }
9317: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
9318: $scan_data);
9319: my $id=lc($$scan_record{'scantron.ID'});
9320: if (exists($idmap{$id})) {
9321: if (ref($classlist->{$idmap{$id}}) eq 'ARRAY') {
9322: my $stusec = $classlist->{$idmap{$id}}->[$secidx];
9323: if ($stusec eq '') {
9324: $bysec{'none'} ++;
9325: } else {
9326: $bysec{$stusec} ++;
9327: }
9328: }
9329: }
9330: }
9331: }
9332: return %bysec;
9333: }
1.423 albertel 9334:
1.157 albertel 9335: sub scantron_get_correction {
1.691 raeburn 9336: my ($r,$i,$scan_record,$scan_config,$line,$error,$arg,
9337: $randomorder,$randompick,$respnumlookup,$startline)=@_;
1.454 banghart 9338: #FIXME in the case of a duplicated ID the previous line, probably need
1.157 albertel 9339: #to show both the current line and the previous one and allow skipping
9340: #the previous one or the current one
9341:
1.333 albertel 9342: if ( $$scan_record{'scantron.PaperID'} =~ /\S/) {
1.658 bisitz 9343: $r->print(
9344: '<p class="LC_warning">'
9345: .&mt('An error was detected ([_1]) for PaperID [_2]',
9346: "<b>$error</b>",
9347: '<tt>'.$$scan_record{'scantron.PaperID'}.'</tt>')
9348: ."</p> \n");
1.157 albertel 9349: } else {
1.658 bisitz 9350: $r->print(
9351: '<p class="LC_warning">'
9352: .&mt('An error was detected ([_1]) in scanline [_2] [_3]',
9353: "<b>$error</b>", $i, "<pre>$line</pre>")
9354: ."</p> \n");
9355: }
9356: my $message =
9357: '<p>'
9358: .&mt('The ID on the form is [_1]',
9359: "<tt>$$scan_record{'scantron.ID'}</tt>")
9360: .'<br />'
1.665 raeburn 9361: .&mt('The name on the paper is [_1], [_2]',
1.658 bisitz 9362: $$scan_record{'scantron.LastName'},
9363: $$scan_record{'scantron.FirstName'})
9364: .'</p>';
1.242 albertel 9365:
1.157 albertel 9366: $r->print('<input type="hidden" name="scantron_corrections" value="'.$error.'" />'."\n");
9367: $r->print('<input type="hidden" name="scantron_line" value="'.$i.'" />'."\n");
1.503 raeburn 9368: # Array populated for doublebubble or
9369: my @lines_to_correct; # missingbubble errors to build javascript
9370: # to validate radio button checking
9371:
1.157 albertel 9372: if ($error =~ /ID$/) {
1.186 albertel 9373: if ($error eq 'incorrectID') {
1.658 bisitz 9374: $r->print('<p class="LC_warning">'.&mt("The encoded ID is not in the classlist").
1.492 albertel 9375: "</p>\n");
1.157 albertel 9376: } elsif ($error eq 'duplicateID') {
1.658 bisitz 9377: $r->print('<p class="LC_warning">'.&mt("The encoded ID has also been used by a previous paper [_1]",$arg)."</p>\n");
1.157 albertel 9378: }
1.242 albertel 9379: $r->print($message);
1.492 albertel 9380: $r->print("<p>".&mt("How should I handle this?")." <br /> \n");
1.157 albertel 9381: $r->print("\n<ul><li> ");
9382: #FIXME it would be nice if this sent back the user ID and
9383: #could do partial userID matches
9384: $r->print(&Apache::loncommon::selectstudent_link('scantronupload',
9385: 'scantron_username','scantron_domain'));
9386: $r->print(": <input type='text' name='scantron_username' value='' />");
1.685 bisitz 9387: $r->print("\n:\n".
1.257 albertel 9388: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'scantron_domain'));
1.157 albertel 9389:
9390: $r->print('</li>');
1.186 albertel 9391: } elsif ($error =~ /CODE$/) {
9392: if ($error eq 'incorrectCODE') {
1.658 bisitz 9393: $r->print('<p class="LC_warning">'.&mt("The encoded CODE is not in the list of possible CODEs.")."</p>\n");
1.186 albertel 9394: } elsif ($error eq 'duplicateCODE') {
1.658 bisitz 9395: $r->print('<p class="LC_warning">'.&mt("The encoded CODE has also been used by a previous paper [_1], and CODEs are supposed to be unique.",join(', ',@{$arg}))."</p>\n");
1.186 albertel 9396: }
1.658 bisitz 9397: $r->print("<p>".&mt('The CODE on the form is [_1]',
9398: "<tt>'$$scan_record{'scantron.CODE'}'</tt>")
9399: ."</p>\n");
1.242 albertel 9400: $r->print($message);
1.658 bisitz 9401: $r->print("<p>".&mt("How should I handle this?")."</p>\n");
1.187 albertel 9402: $r->print("\n<br /> ");
1.194 albertel 9403: my $i=0;
1.273 albertel 9404: if ($error eq 'incorrectCODE'
9405: && $$scan_record{'scantron.CODE'}=~/\S/ ) {
1.194 albertel 9406: my ($max,$closest)=&scantron_get_closely_matching_CODEs($arg,$$scan_record{'scantron.CODE'});
1.278 albertel 9407: if ($closest > 0) {
9408: foreach my $testcode (@{$closest}) {
9409: my $checked='';
1.569 bisitz 9410: if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 9411: $r->print("
9412: <label>
1.569 bisitz 9413: <input type='radio' name='scantron_CODE_resolution' value='use_closest_$i'$checked />
1.492 albertel 9414: ".&mt("Use the similar CODE [_1] instead.",
9415: "<b><tt>".$testcode."</tt></b>")."
9416: </label>
9417: <input type='hidden' name='scantron_CODE_closest_$i' value='$testcode' />");
1.278 albertel 9418: $r->print("\n<br />");
9419: $i++;
9420: }
1.194 albertel 9421: }
9422: }
1.273 albertel 9423: if ($$scan_record{'scantron.CODE'}=~/\S/ ) {
1.569 bisitz 9424: my $checked; if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 9425: $r->print("
9426: <label>
1.569 bisitz 9427: <input type='radio' name='scantron_CODE_resolution' value='use_unfound'$checked />
1.659 raeburn 9428: ".&mt("Use the CODE [_1] that was on the paper, ignoring the error.",
1.492 albertel 9429: "<b><tt>".$$scan_record{'scantron.CODE'}."</tt></b>")."
9430: </label>");
1.273 albertel 9431: $r->print("\n<br />");
9432: }
1.194 albertel 9433:
1.597 wenzelju 9434: $r->print(&Apache::lonhtmlcommon::scripttag(<<ENDSCRIPT));
1.188 albertel 9435: function change_radio(field) {
1.190 albertel 9436: var slct=document.scantronupload.scantron_CODE_resolution;
1.188 albertel 9437: var i;
9438: for (i=0;i<slct.length;i++) {
9439: if (slct[i].value==field) { slct[i].checked=true; }
9440: }
9441: }
9442: ENDSCRIPT
1.187 albertel 9443: my $href="/adm/pickcode?".
1.359 www 9444: "form=".&escape("scantronupload").
9445: "&scantron_format=".&escape($env{'form.scantron_format'}).
9446: "&scantron_CODElist=".&escape($env{'form.scantron_CODElist'}).
9447: "&curCODE=".&escape($$scan_record{'scantron.CODE'}).
9448: "&scantron_selectfile=".&escape($env{'form.scantron_selectfile'});
1.332 albertel 9449: if ($env{'form.scantron_CODElist'} =~ /\S/) {
1.492 albertel 9450: $r->print("
9451: <label>
9452: <input type='radio' name='scantron_CODE_resolution' value='use_found' />
9453: ".&mt("[_1]Select[_2] a CODE from the list of all CODEs and use it.",
9454: "<a target='_blank' href='$href'>","</a>")."
9455: </label>
1.558 bisitz 9456: ".&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 9457: $r->print("\n<br />");
9458: }
1.492 albertel 9459: $r->print("
9460: <label>
9461: <input type='radio' name='scantron_CODE_resolution' value='use_typed' />
9462: ".&mt("Use [_1] as the CODE.",
9463: "</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 9464: $r->print("\n<br /><br />");
1.157 albertel 9465: } elsif ($error eq 'doublebubble') {
1.658 bisitz 9466: $r->print('<p class="LC_warning">'.&mt("There have been multiple bubbles scanned for some question(s)")."</p>\n");
1.497 foxr 9467:
9468: # The form field scantron_questions is acutally a list of line numbers.
9469: # represented by this form so:
9470:
1.691 raeburn 9471: my $line_list = &questions_to_line_list($arg,$randomorder,$randompick,
9472: $respnumlookup,$startline);
1.497 foxr 9473:
1.157 albertel 9474: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 9475: $line_list.'" />');
1.242 albertel 9476: $r->print($message);
1.492 albertel 9477: $r->print("<p>".&mt("Please indicate which bubble should be used for grading")."</p>");
1.157 albertel 9478: foreach my $question (@{$arg}) {
1.503 raeburn 9479: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
1.691 raeburn 9480: $scan_record, $error,
9481: $randomorder,$randompick,
9482: $respnumlookup,$startline);
1.524 raeburn 9483: push(@lines_to_correct,@linenums);
1.157 albertel 9484: }
1.503 raeburn 9485: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 9486: } elsif ($error eq 'missingbubble') {
1.658 bisitz 9487: $r->print('<p class="LC_warning">'.&mt("There have been [_1]no[_2] bubbles scanned for some question(s)",'<b>','</b>')."</p>\n");
1.242 albertel 9488: $r->print($message);
1.492 albertel 9489: $r->print("<p>".&mt("Please indicate which bubble should be used for grading.")."</p>");
1.503 raeburn 9490: $r->print(&mt("Some questions have no scanned bubbles.")."\n");
1.497 foxr 9491:
1.503 raeburn 9492: # The form field scantron_questions is actually a list of line numbers not
1.497 foxr 9493: # a list of question numbers. Therefore:
9494: #
1.691 raeburn 9495:
9496: my $line_list = &questions_to_line_list($arg,$randomorder,$randompick,
9497: $respnumlookup,$startline);
1.497 foxr 9498:
1.157 albertel 9499: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 9500: $line_list.'" />');
1.157 albertel 9501: foreach my $question (@{$arg}) {
1.503 raeburn 9502: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
1.691 raeburn 9503: $scan_record, $error,
9504: $randomorder,$randompick,
9505: $respnumlookup,$startline);
1.524 raeburn 9506: push(@lines_to_correct,@linenums);
1.157 albertel 9507: }
1.503 raeburn 9508: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 9509: } else {
9510: $r->print("\n<ul>");
9511: }
9512: $r->print("\n</li></ul>");
1.497 foxr 9513: }
9514:
1.503 raeburn 9515: sub verify_bubbles_checked {
9516: my (@ansnums) = @_;
9517: my $ansnumstr = join('","',@ansnums);
9518: my $warning = &mt("A bubble or 'No bubble' selection has not been made for one or more lines.");
1.736 damieng 9519: &js_escape(\$warning);
1.767 raeburn 9520: my $output = &Apache::lonhtmlcommon::scripttag(<<ENDSCRIPT);
1.503 raeburn 9521: function verify_bubble_radio(form) {
9522: var ansnumArray = new Array ("$ansnumstr");
9523: var need_bubble_count = 0;
9524: for (var i=0; i<ansnumArray.length; i++) {
9525: if (form.elements["scantron_correct_Q_"+ansnumArray[i]].length > 1) {
9526: var bubble_picked = 0;
9527: for (var j=0; j<form.elements["scantron_correct_Q_"+ansnumArray[i]].length; j++) {
9528: if (form.elements["scantron_correct_Q_"+ansnumArray[i]][j].checked == true) {
9529: bubble_picked = 1;
9530: }
9531: }
9532: if (bubble_picked == 0) {
9533: need_bubble_count ++;
9534: }
9535: }
9536: }
9537: if (need_bubble_count) {
9538: alert("$warning");
9539: return;
9540: }
9541: form.submit();
9542: }
9543: ENDSCRIPT
9544: return $output;
9545: }
9546:
1.497 foxr 9547: =pod
9548:
9549: =item questions_to_line_list
1.157 albertel 9550:
1.497 foxr 9551: Converts a list of questions into a string of comma separated
9552: line numbers in the answer sheet used by the questions. This is
9553: used to fill in the scantron_questions form field.
9554:
9555: Arguments:
9556: questions - Reference to an array of questions.
1.691 raeburn 9557: randomorder - True if randomorder in use.
9558: randompick - True if randompick in use.
9559: respnumlookup - Reference to HASH mapping question numbers in bubble lines
9560: for current line to question number used for same question
9561: in "Master Seqence" (as seen by Course Coordinator).
9562: startline - Reference to hash where key is question number (0 is first)
9563: and key is number of first bubble line for current student
9564: or code-based randompick and/or randomorder.
1.693 raeburn 9565:
1.497 foxr 9566: =cut
9567:
9568:
9569: sub questions_to_line_list {
1.691 raeburn 9570: my ($questions,$randomorder,$randompick,$respnumlookup,$startline) = @_;
1.497 foxr 9571: my @lines;
9572:
1.503 raeburn 9573: foreach my $item (@{$questions}) {
9574: my $question = $item;
9575: my ($first,$count,$last);
9576: if ($item =~ /^(\d+)\.(\d+)$/) {
9577: $question = $1;
9578: my $subquestion = $2;
1.691 raeburn 9579: my $responsenum = $question-1;
9580: if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
9581: $responsenum = $respnumlookup->{$question-1};
9582: if (ref($startline) eq 'HASH') {
9583: $first = $startline->{$question-1} + 1;
9584: }
9585: } else {
9586: $first = $first_bubble_line{$responsenum} + 1;
9587: }
9588: my @subans = split(/,/,$subdivided_bubble_lines{$responsenum});
1.503 raeburn 9589: my $subcount = 1;
9590: while ($subcount<$subquestion) {
9591: $first += $subans[$subcount-1];
9592: $subcount ++;
9593: }
9594: $count = $subans[$subquestion-1];
9595: } else {
1.691 raeburn 9596: my $responsenum = $question-1;
9597: if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
9598: $responsenum = $respnumlookup->{$question-1};
9599: if (ref($startline) eq 'HASH') {
9600: $first = $startline->{$question-1} + 1;
9601: }
9602: } else {
9603: $first = $first_bubble_line{$responsenum} + 1;
9604: }
9605: $count = $bubble_lines_per_response{$responsenum};
1.503 raeburn 9606: }
1.506 raeburn 9607: $last = $first+$count-1;
1.503 raeburn 9608: push(@lines, ($first..$last));
1.497 foxr 9609: }
9610: return join(',', @lines);
9611: }
9612:
9613: =pod
9614:
9615: =item prompt_for_corrections
9616:
9617: Prompts for a potentially multiline correction to the
9618: user's bubbling (factors out common code from scantron_get_correction
9619: for multi and missing bubble cases).
9620:
9621: Arguments:
9622: $r - Apache request object.
9623: $question - The question number to prompt for.
9624: $scan_config - The scantron file configuration hash.
9625: $scan_record - Reference to the hash that has the the parsed scanlines.
1.503 raeburn 9626: $error - Type of error
1.691 raeburn 9627: $randomorder - True if randomorder in use.
9628: $randompick - True if randompick in use.
9629: $respnumlookup - Reference to HASH mapping question numbers in bubble lines
9630: for current line to question number used for same question
9631: in "Master Seqence" (as seen by Course Coordinator).
9632: $startline - Reference to hash where key is question number (0 is first)
9633: and value is number of first bubble line for current student
9634: or code-based randompick and/or randomorder.
9635:
1.497 foxr 9636:
9637: Implicit inputs:
9638: %bubble_lines_per_response - Starting line numbers for each question.
9639: Numbered from 0 (but question numbers are from
9640: 1.
9641: %first_bubble_line - Starting bubble line for each question.
1.509 raeburn 9642: %subdivided_bubble_lines - optionresponse, matchresponse and rankresponse
9643: type problems render as separate sub-questions,
1.503 raeburn 9644: in exam mode. This hash contains a
9645: comma-separated list of the lines per
9646: sub-question.
1.510 raeburn 9647: %responsetype_per_response - essayresponse, formularesponse,
9648: stringresponse, imageresponse, reactionresponse,
9649: and organicresponse type problem parts can have
1.503 raeburn 9650: multiple lines per response if the weight
9651: assigned exceeds 10. In this case, only
9652: one bubble per line is permitted, but more
9653: than one line might contain bubbles, e.g.
9654: bubbling of: line 1 - J, line 2 - J,
9655: line 3 - B would assign 22 points.
1.497 foxr 9656:
9657: =cut
9658:
9659: sub prompt_for_corrections {
1.691 raeburn 9660: my ($r, $question, $scan_config, $scan_record, $error, $randomorder,
9661: $randompick, $respnumlookup, $startline) = @_;
1.503 raeburn 9662: my ($current_line,$lines);
9663: my @linenums;
9664: my $questionnum = $question;
1.691 raeburn 9665: my ($first,$responsenum);
1.503 raeburn 9666: if ($question =~ /^(\d+)\.(\d+)$/) {
9667: $question = $1;
9668: my $subquestion = $2;
1.691 raeburn 9669: if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
9670: $responsenum = $respnumlookup->{$question-1};
9671: if (ref($startline) eq 'HASH') {
9672: $first = $startline->{$question-1};
9673: }
9674: } else {
9675: $responsenum = $question-1;
1.714 raeburn 9676: $first = $first_bubble_line{$responsenum};
1.691 raeburn 9677: }
9678: $current_line = $first + 1 ;
9679: my @subans = split(/,/,$subdivided_bubble_lines{$responsenum});
1.503 raeburn 9680: my $subcount = 1;
9681: while ($subcount<$subquestion) {
9682: $current_line += $subans[$subcount-1];
9683: $subcount ++;
9684: }
9685: $lines = $subans[$subquestion-1];
9686: } else {
1.691 raeburn 9687: if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
9688: $responsenum = $respnumlookup->{$question-1};
9689: if (ref($startline) eq 'HASH') {
9690: $first = $startline->{$question-1};
9691: }
9692: } else {
9693: $responsenum = $question-1;
9694: $first = $first_bubble_line{$responsenum};
9695: }
9696: $current_line = $first + 1;
9697: $lines = $bubble_lines_per_response{$responsenum};
1.503 raeburn 9698: }
1.497 foxr 9699: if ($lines > 1) {
1.503 raeburn 9700: $r->print(&mt('The group of bubble lines below responds to a single question.').'<br />');
1.691 raeburn 9701: if (($responsetype_per_response{$responsenum} eq 'essayresponse') ||
9702: ($responsetype_per_response{$responsenum} eq 'formularesponse') ||
9703: ($responsetype_per_response{$responsenum} eq 'stringresponse') ||
9704: ($responsetype_per_response{$responsenum} eq 'imageresponse') ||
9705: ($responsetype_per_response{$responsenum} eq 'reactionresponse') ||
9706: ($responsetype_per_response{$responsenum} eq 'organicresponse')) {
1.684 bisitz 9707: $r->print(
9708: &mt("Although this particular question type requires handgrading, the instructions for this question in the bubblesheet exam directed students to leave [quant,_1,line] blank on their bubblesheets.",$lines)
9709: .'<br /><br />'
9710: .&mt('A non-zero score can be assigned to the student during bubblesheet grading by selecting a bubble in at least one line.')
9711: .'<br />'
9712: .&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.')
9713: .'<br />'
9714: .&mt("To assign a score of zero for this question, mark all lines as 'No bubble'.")
9715: .'<br /><br />'
9716: );
1.503 raeburn 9717: } else {
9718: $r->print(&mt("Select at most one bubble in a single line and select 'No Bubble' in all the other lines. ")."<br />");
9719: }
1.497 foxr 9720: }
9721: for (my $i =0; $i < $lines; $i++) {
1.503 raeburn 9722: my $selected = $$scan_record{"scantron.$current_line.answer"};
1.691 raeburn 9723: &scantron_bubble_selector($r,$scan_config,$current_line,
1.503 raeburn 9724: $questionnum,$error,split('', $selected));
1.524 raeburn 9725: push(@linenums,$current_line);
1.497 foxr 9726: $current_line++;
9727: }
9728: if ($lines > 1) {
9729: $r->print("<hr /><br />");
9730: }
1.503 raeburn 9731: return @linenums;
1.157 albertel 9732: }
1.423 albertel 9733:
9734: =pod
9735:
9736: =item scantron_bubble_selector
9737:
9738: Generates the html radiobuttons to correct a single bubble line
1.424 albertel 9739: possibly showing the existing the selected bubbles if known
1.423 albertel 9740:
9741: Arguments:
9742: $r - Apache request object
1.754 raeburn 9743: $scan_config - hash from &Apache::lonnet::get_scantron_config()
1.497 foxr 9744: $line - Number of the line being displayed.
1.503 raeburn 9745: $questionnum - Question number (may include subquestion)
9746: $error - Type of error.
1.497 foxr 9747: @selected - Array of bubbles picked on this line.
1.423 albertel 9748:
9749: =cut
9750:
1.157 albertel 9751: sub scantron_bubble_selector {
1.503 raeburn 9752: my ($r,$scan_config,$line,$questionnum,$error,@selected)=@_;
1.157 albertel 9753: my $max=$$scan_config{'Qlength'};
1.274 albertel 9754:
9755: my $scmode=$$scan_config{'Qon'};
1.649 raeburn 9756: if ($scmode eq 'number' || $scmode eq 'letter') {
9757: if (($$scan_config{'BubblesPerRow'} =~ /^\d+$/) &&
9758: ($$scan_config{'BubblesPerRow'} > 0)) {
9759: $max=$$scan_config{'BubblesPerRow'};
9760: if (($scmode eq 'number') && ($max > 10)) {
9761: $max = 10;
9762: } elsif (($scmode eq 'letter') && $max > 26) {
9763: $max = 26;
9764: }
9765: } else {
9766: $max = 10;
9767: }
9768: }
1.274 albertel 9769:
1.157 albertel 9770: my @alphabet=('A'..'Z');
1.503 raeburn 9771: $r->print(&Apache::loncommon::start_data_table().
9772: &Apache::loncommon::start_data_table_row());
9773: $r->print('<td rowspan="2" class="LC_leftcol_header">'.$line.'</td>');
1.497 foxr 9774: for (my $i=0;$i<$max+1;$i++) {
9775: $r->print("\n".'<td align="center">');
9776: if ($selected[0] eq $alphabet[$i]) { $r->print('X'); shift(@selected) }
9777: else { $r->print(' '); }
9778: $r->print('</td>');
9779: }
1.503 raeburn 9780: $r->print(&Apache::loncommon::end_data_table_row().
9781: &Apache::loncommon::start_data_table_row());
1.497 foxr 9782: for (my $i=0;$i<$max;$i++) {
9783: $r->print("\n".
9784: '<td><label><input type="radio" name="scantron_correct_Q_'.
9785: $line.'" value="'.$i.'" />'.$alphabet[$i]."</label></td>");
9786: }
1.503 raeburn 9787: my $nobub_checked = ' ';
9788: if ($error eq 'missingbubble') {
9789: $nobub_checked = ' checked = "checked" ';
9790: }
9791: $r->print("\n".'<td><label><input type="radio" name="scantron_correct_Q_'.
9792: $line.'" value="none"'.$nobub_checked.'/>'.&mt('No bubble').
9793: '</label>'."\n".'<input type="hidden" name="scantron_questionnum_Q_'.
9794: $line.'" value="'.$questionnum.'" /></td>');
9795: $r->print(&Apache::loncommon::end_data_table_row().
9796: &Apache::loncommon::end_data_table());
1.157 albertel 9797: }
9798:
1.423 albertel 9799: =pod
9800:
9801: =item num_matches
9802:
1.424 albertel 9803: Counts the number of characters that are the same between the two arguments.
9804:
9805: Arguments:
9806: $orig - CODE from the scanline
9807: $code - CODE to match against
9808:
9809: Returns:
9810: $count - integer count of the number of same characters between the
9811: two arguments
9812:
1.423 albertel 9813: =cut
9814:
1.194 albertel 9815: sub num_matches {
9816: my ($orig,$code) = @_;
9817: my @code=split(//,$code);
9818: my @orig=split(//,$orig);
9819: my $same=0;
9820: for (my $i=0;$i<scalar(@code);$i++) {
9821: if ($code[$i] eq $orig[$i]) { $same++; }
9822: }
9823: return $same;
9824: }
9825:
1.423 albertel 9826: =pod
9827:
9828: =item scantron_get_closely_matching_CODEs
9829:
1.424 albertel 9830: Cycles through all CODEs and finds the set that has the greatest
9831: number of same characters as the provided CODE
9832:
9833: Arguments:
9834: $allcodes - hash ref returned by &get_codes()
9835: $CODE - CODE from the current scanline
9836:
9837: Returns:
9838: 2 element list
9839: - first elements is number of how closely matching the best fit is
9840: (5 means best set has 5 matching characters)
9841: - second element is an arrary ref containing the set of valid CODEs
9842: that best fit the passed in CODE
9843:
1.423 albertel 9844: =cut
9845:
1.194 albertel 9846: sub scantron_get_closely_matching_CODEs {
9847: my ($allcodes,$CODE)=@_;
9848: my @CODEs;
9849: foreach my $testcode (sort(keys(%{$allcodes}))) {
9850: push(@{$CODEs[&num_matches($CODE,$testcode)]},$testcode);
9851: }
9852:
9853: return ($#CODEs,$CODEs[-1]);
9854: }
9855:
1.423 albertel 9856: =pod
9857:
9858: =item get_codes
9859:
1.424 albertel 9860: Builds a hash which has keys of all of the valid CODEs from the selected
9861: set of remembered CODEs.
9862:
9863: Arguments:
9864: $old_name - name of the set of remembered CODEs
9865: $cdom - domain of the course
9866: $cnum - internal course name
9867:
9868: Returns:
9869: %allcodes - keys are the valid CODEs, values are all 1
9870:
1.423 albertel 9871: =cut
9872:
1.194 albertel 9873: sub get_codes {
1.280 foxr 9874: my ($old_name, $cdom, $cnum) = @_;
9875: if (!$old_name) {
9876: $old_name=$env{'form.scantron_CODElist'};
9877: }
9878: if (!$cdom) {
9879: $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
9880: }
9881: if (!$cnum) {
9882: $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
9883: }
1.278 albertel 9884: my %result=&Apache::lonnet::get('CODEs',[$old_name,"type\0$old_name"],
9885: $cdom,$cnum);
9886: my %allcodes;
9887: if ($result{"type\0$old_name"} eq 'number') {
9888: %allcodes=map {($_,1)} split(',',$result{$old_name});
9889: } else {
9890: %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
9891: }
1.194 albertel 9892: return %allcodes;
9893: }
9894:
1.423 albertel 9895: =pod
9896:
9897: =item scantron_validate_CODE
9898:
1.424 albertel 9899: Validates all scanlines in the selected file to not have any
9900: invalid or underspecified CODEs and that none of the codes are
9901: duplicated if this was requested.
9902:
1.423 albertel 9903: =cut
9904:
1.157 albertel 9905: sub scantron_validate_CODE {
9906: my ($r,$currentphase) = @_;
1.754 raeburn 9907: my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.186 albertel 9908: if ($scantron_config{'CODElocation'} &&
9909: $scantron_config{'CODEstart'} &&
9910: $scantron_config{'CODElength'}) {
1.257 albertel 9911: if (!defined($env{'form.scantron_CODElist'})) {
1.186 albertel 9912: &FIXME_blow_up()
9913: }
9914: } else {
9915: return (0,$currentphase+1);
9916: }
9917:
9918: my %usedCODEs;
9919:
1.194 albertel 9920: my %allcodes=&get_codes();
1.186 albertel 9921:
1.582 raeburn 9922: my $nav_error;
1.649 raeburn 9923: &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the lines per response array.
1.582 raeburn 9924: if ($nav_error) {
9925: $r->print(&navmap_errormsg());
9926: return(1,$currentphase);
9927: }
1.447 foxr 9928:
1.186 albertel 9929: my ($scanlines,$scan_data)=&scantron_getfile();
9930: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 9931: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.186 albertel 9932: if ($line=~/^[\s\cz]*$/) { next; }
9933: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
9934: $scan_data);
9935: my $CODE=$$scan_record{'scantron.CODE'};
9936: my $error=0;
1.224 albertel 9937: if (!&Apache::lonnet::validCODE($CODE)) {
9938: &scantron_get_correction($r,$i,$scan_record,
9939: \%scantron_config,
9940: $line,'incorrectCODE',\%allcodes);
9941: return(1,$currentphase);
9942: }
1.221 albertel 9943: if (%allcodes && !exists($allcodes{$CODE})
9944: && !$$scan_record{'scantron.useCODE'}) {
1.186 albertel 9945: &scantron_get_correction($r,$i,$scan_record,
9946: \%scantron_config,
1.194 albertel 9947: $line,'incorrectCODE',\%allcodes);
9948: return(1,$currentphase);
1.186 albertel 9949: }
1.214 albertel 9950: if (exists($usedCODEs{$CODE})
1.257 albertel 9951: && $env{'form.scantron_CODEunique'} eq 'yes'
1.192 albertel 9952: && !$$scan_record{'scantron.CODE_ignore_dup'}) {
1.186 albertel 9953: &scantron_get_correction($r,$i,$scan_record,
9954: \%scantron_config,
1.194 albertel 9955: $line,'duplicateCODE',$usedCODEs{$CODE});
9956: return(1,$currentphase);
1.186 albertel 9957: }
1.524 raeburn 9958: push(@{$usedCODEs{$CODE}},$$scan_record{'scantron.PaperID'});
1.186 albertel 9959: }
1.157 albertel 9960: return (0,$currentphase+1);
9961: }
9962:
1.423 albertel 9963: =pod
9964:
9965: =item scantron_validate_doublebubble
9966:
1.424 albertel 9967: Validates all scanlines in the selected file to not have any
9968: bubble lines with multiple bubbles marked.
9969:
1.423 albertel 9970: =cut
9971:
1.157 albertel 9972: sub scantron_validate_doublebubble {
9973: my ($r,$currentphase) = @_;
9974: #get student info
9975: my $classlist=&Apache::loncoursedata::get_classlist();
9976: my %idmap=&username_to_idmap($classlist);
1.691 raeburn 9977: my (undef,undef,$sequence)=
9978: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.157 albertel 9979:
9980: #get scantron line setup
1.754 raeburn 9981: my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.157 albertel 9982: my ($scanlines,$scan_data)=&scantron_getfile();
1.691 raeburn 9983:
9984: my $navmap = Apache::lonnavmaps::navmap->new();
9985: unless (ref($navmap)) {
9986: $r->print(&navmap_errormsg());
9987: return(1,$currentphase);
9988: }
9989: my $map=$navmap->getResourceByUrl($sequence);
9990: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
9991: my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
9992: %grader_randomlists_by_symb,%orderedforcode,%respnumlookup,%startline);
9993: my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
9994:
1.583 raeburn 9995: my $nav_error;
1.691 raeburn 9996: if (ref($map)) {
9997: $randomorder = $map->randomorder();
9998: $randompick = $map->randompick();
1.788 raeburn 9999: unless ($randomorder || $randompick) {
10000: foreach my $res ($navmap->retrieveResources($map,sub { $_[0]->is_map() },1,0,1)) {
10001: if ($res->randomorder()) {
10002: $randomorder = 1;
10003: }
10004: if ($res->randompick()) {
10005: $randompick = 1;
10006: }
10007: last if ($randomorder || $randompick);
10008: }
10009: }
1.691 raeburn 10010: if ($randomorder || $randompick) {
10011: $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource);
10012: if ($nav_error) {
10013: $r->print(&navmap_errormsg());
10014: return(1,$currentphase);
10015: }
10016: &graders_resources_pass(\@resources,\%grader_partids_by_symb,
10017: \%grader_randomlists_by_symb,$bubbles_per_row);
10018: }
10019: } else {
10020: $r->print(&navmap_errormsg());
10021: return(1,$currentphase);
10022: }
10023:
1.649 raeburn 10024: &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the bubble line array.
1.583 raeburn 10025: if ($nav_error) {
10026: $r->print(&navmap_errormsg());
10027: return(1,$currentphase);
10028: }
1.447 foxr 10029:
1.157 albertel 10030: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 10031: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 10032: if ($line=~/^[\s\cz]*$/) { next; }
10033: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
1.691 raeburn 10034: $scan_data,undef,\%idmap,$randomorder,
10035: $randompick,$sequence,\@master_seq,
10036: \%symb_to_resource,\%grader_partids_by_symb,
10037: \%orderedforcode,\%respnumlookup,\%startline);
1.157 albertel 10038: if (!defined($$scan_record{'scantron.doubleerror'})) { next; }
10039: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,$line,
10040: 'doublebubble',
1.691 raeburn 10041: $$scan_record{'scantron.doubleerror'},
10042: $randomorder,$randompick,\%respnumlookup,\%startline);
1.157 albertel 10043: return (1,$currentphase);
10044: }
10045: return (0,$currentphase+1);
10046: }
10047:
1.423 albertel 10048:
1.503 raeburn 10049: sub scantron_get_maxbubble {
1.649 raeburn 10050: my ($nav_error,$scantron_config) = @_;
1.257 albertel 10051: if (defined($env{'form.scantron_maxbubble'}) &&
10052: $env{'form.scantron_maxbubble'}) {
1.447 foxr 10053: &restore_bubble_lines();
1.257 albertel 10054: return $env{'form.scantron_maxbubble'};
1.191 albertel 10055: }
1.330 albertel 10056:
1.447 foxr 10057: my (undef, undef, $sequence) =
1.257 albertel 10058: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.330 albertel 10059:
1.447 foxr 10060: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 10061: unless (ref($navmap)) {
10062: if (ref($nav_error)) {
10063: $$nav_error = 1;
10064: }
1.591 raeburn 10065: return;
1.582 raeburn 10066: }
1.191 albertel 10067: my $map=$navmap->getResourceByUrl($sequence);
10068: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.649 raeburn 10069: my $bubbles_per_row = &bubblesheet_bubbles_per_row($scantron_config);
1.330 albertel 10070:
10071: &Apache::lonxml::clear_problem_counter();
10072:
1.557 raeburn 10073: my $uname = $env{'user.name'};
10074: my $udom = $env{'user.domain'};
1.435 foxr 10075: my $cid = $env{'request.course.id'};
10076: my $total_lines = 0;
10077: %bubble_lines_per_response = ();
1.447 foxr 10078: %first_bubble_line = ();
1.503 raeburn 10079: %subdivided_bubble_lines = ();
10080: %responsetype_per_response = ();
1.691 raeburn 10081: %masterseq_id_responsenum = ();
1.554 raeburn 10082:
1.447 foxr 10083: my $response_number = 0;
10084: my $bubble_line = 0;
1.191 albertel 10085: foreach my $resource (@resources) {
1.691 raeburn 10086: my $resid = $resource->id();
1.672 raeburn 10087: my ($analysis,$parts) = &scantron_partids_tograde($resource,$cid,$uname,
10088: $udom,undef,$bubbles_per_row);
1.542 raeburn 10089: if ((ref($analysis) eq 'HASH') && (ref($parts) eq 'ARRAY')) {
10090: foreach my $part_id (@{$parts}) {
10091: my $lines;
10092:
10093: # TODO - make this a persistent hash not an array.
10094:
10095: # optionresponse, matchresponse and rankresponse type items
10096: # render as separate sub-questions in exam mode.
10097: if (($analysis->{$part_id.'.type'} eq 'optionresponse') ||
10098: ($analysis->{$part_id.'.type'} eq 'matchresponse') ||
10099: ($analysis->{$part_id.'.type'} eq 'rankresponse')) {
10100: my ($numbub,$numshown);
10101: if ($analysis->{$part_id.'.type'} eq 'optionresponse') {
10102: if (ref($analysis->{$part_id.'.options'}) eq 'ARRAY') {
10103: $numbub = scalar(@{$analysis->{$part_id.'.options'}});
10104: }
10105: } elsif ($analysis->{$part_id.'.type'} eq 'matchresponse') {
10106: if (ref($analysis->{$part_id.'.items'}) eq 'ARRAY') {
10107: $numbub = scalar(@{$analysis->{$part_id.'.items'}});
10108: }
10109: } elsif ($analysis->{$part_id.'.type'} eq 'rankresponse') {
10110: if (ref($analysis->{$part_id.'.foils'}) eq 'ARRAY') {
10111: $numbub = scalar(@{$analysis->{$part_id.'.foils'}});
10112: }
10113: }
10114: if (ref($analysis->{$part_id.'.shown'}) eq 'ARRAY') {
10115: $numshown = scalar(@{$analysis->{$part_id.'.shown'}});
10116: }
1.649 raeburn 10117: my $bubbles_per_row =
10118: &bubblesheet_bubbles_per_row($scantron_config);
10119: my $inner_bubble_lines = int($numbub/$bubbles_per_row);
10120: if (($numbub % $bubbles_per_row) != 0) {
1.542 raeburn 10121: $inner_bubble_lines++;
10122: }
10123: for (my $i=0; $i<$numshown; $i++) {
10124: $subdivided_bubble_lines{$response_number} .=
10125: $inner_bubble_lines.',';
10126: }
10127: $subdivided_bubble_lines{$response_number} =~ s/,$//;
10128: $lines = $numshown * $inner_bubble_lines;
10129: } else {
10130: $lines = $analysis->{"$part_id.bubble_lines"};
1.649 raeburn 10131: }
1.542 raeburn 10132:
10133: $first_bubble_line{$response_number} = $bubble_line;
10134: $bubble_lines_per_response{$response_number} = $lines;
10135: $responsetype_per_response{$response_number} =
10136: $analysis->{$part_id.'.type'};
1.691 raeburn 10137: $masterseq_id_responsenum{$resid.'_'.$part_id} = $response_number;
1.542 raeburn 10138: $response_number++;
10139:
10140: $bubble_line += $lines;
10141: $total_lines += $lines;
10142: }
10143: }
10144: }
1.552 raeburn 10145: &Apache::lonnet::delenv('scantron.');
1.542 raeburn 10146:
10147: &save_bubble_lines();
10148: $env{'form.scantron_maxbubble'} =
10149: $total_lines;
10150: return $env{'form.scantron_maxbubble'};
10151: }
1.523 raeburn 10152:
1.649 raeburn 10153: sub bubblesheet_bubbles_per_row {
10154: my ($scantron_config) = @_;
10155: my $bubbles_per_row;
10156: if (ref($scantron_config) eq 'HASH') {
10157: $bubbles_per_row = $scantron_config->{'BubblesPerRow'};
10158: }
10159: if ((!$bubbles_per_row) || ($bubbles_per_row < 1)) {
10160: $bubbles_per_row = 10;
10161: }
10162: return $bubbles_per_row;
10163: }
10164:
1.157 albertel 10165: sub scantron_validate_missingbubbles {
10166: my ($r,$currentphase) = @_;
10167: #get student info
10168: my $classlist=&Apache::loncoursedata::get_classlist();
10169: my %idmap=&username_to_idmap($classlist);
1.691 raeburn 10170: my (undef,undef,$sequence)=
10171: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.157 albertel 10172:
10173: #get scantron line setup
1.754 raeburn 10174: my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.157 albertel 10175: my ($scanlines,$scan_data)=&scantron_getfile();
1.691 raeburn 10176:
10177: my $navmap = Apache::lonnavmaps::navmap->new();
10178: unless (ref($navmap)) {
10179: $r->print(&navmap_errormsg());
10180: return(1,$currentphase);
10181: }
10182:
10183: my $map=$navmap->getResourceByUrl($sequence);
10184: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
10185: my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
10186: %grader_randomlists_by_symb,%orderedforcode,%respnumlookup,%startline);
10187: my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
10188:
1.582 raeburn 10189: my $nav_error;
1.691 raeburn 10190: if (ref($map)) {
10191: $randomorder = $map->randomorder();
10192: $randompick = $map->randompick();
1.788 raeburn 10193: unless ($randomorder || $randompick) {
10194: foreach my $res ($navmap->retrieveResources($map,sub { $_[0]->is_map() },1,0,1)) {
10195: if ($res->randomorder()) {
10196: $randomorder = 1;
10197: }
10198: if ($res->randompick()) {
10199: $randompick = 1;
10200: }
10201: last if ($randomorder || $randompick);
10202: }
10203: }
1.691 raeburn 10204: if ($randomorder || $randompick) {
10205: $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource);
10206: if ($nav_error) {
10207: $r->print(&navmap_errormsg());
10208: return(1,$currentphase);
10209: }
10210: &graders_resources_pass(\@resources,\%grader_partids_by_symb,
10211: \%grader_randomlists_by_symb,$bubbles_per_row);
10212: }
10213: } else {
10214: $r->print(&navmap_errormsg());
10215: return(1,$currentphase);
10216: }
10217:
10218:
1.649 raeburn 10219: my $max_bubble=&scantron_get_maxbubble(\$nav_error,\%scantron_config);
1.582 raeburn 10220: if ($nav_error) {
1.691 raeburn 10221: $r->print(&navmap_errormsg());
1.693 raeburn 10222: return(1,$currentphase);
1.582 raeburn 10223: }
1.691 raeburn 10224:
1.157 albertel 10225: if (!$max_bubble) { $max_bubble=2**31; }
10226: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 10227: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 10228: if ($line=~/^[\s\cz]*$/) { next; }
1.691 raeburn 10229: my $scan_record =
10230: &scantron_parse_scanline($line,$i,\%scantron_config,$scan_data,undef,\%idmap,
10231: $randomorder,$randompick,$sequence,\@master_seq,
10232: \%symb_to_resource,\%grader_partids_by_symb,
10233: \%orderedforcode,\%respnumlookup,\%startline);
1.157 albertel 10234: if (!defined($$scan_record{'scantron.missingerror'})) { next; }
10235: my @to_correct;
1.470 foxr 10236:
10237: # Probably here's where the error is...
10238:
1.157 albertel 10239: foreach my $missing (@{$$scan_record{'scantron.missingerror'}}) {
1.505 raeburn 10240: my $lastbubble;
10241: if ($missing =~ /^(\d+)\.(\d+)$/) {
10242: my $question = $1;
10243: my $subquestion = $2;
1.691 raeburn 10244: my ($first,$responsenum);
10245: if ($randomorder || $randompick) {
10246: $responsenum = $respnumlookup{$question-1};
10247: $first = $startline{$question-1};
10248: } else {
10249: $responsenum = $question-1;
10250: $first = $first_bubble_line{$responsenum};
10251: }
10252: if (!defined($first)) { next; }
10253: my @subans = split(/,/,$subdivided_bubble_lines{$responsenum});
1.505 raeburn 10254: my $subcount = 1;
10255: while ($subcount<$subquestion) {
10256: $first += $subans[$subcount-1];
10257: $subcount ++;
10258: }
10259: my $count = $subans[$subquestion-1];
10260: $lastbubble = $first + $count;
10261: } else {
1.691 raeburn 10262: my ($first,$responsenum);
10263: if ($randomorder || $randompick) {
10264: $responsenum = $respnumlookup{$missing-1};
10265: $first = $startline{$missing-1};
10266: } else {
10267: $responsenum = $missing-1;
10268: $first = $first_bubble_line{$responsenum};
10269: }
10270: if (!defined($first)) { next; }
10271: $lastbubble = $first + $bubble_lines_per_response{$responsenum};
1.505 raeburn 10272: }
10273: if ($lastbubble > $max_bubble) { next; }
1.157 albertel 10274: push(@to_correct,$missing);
10275: }
10276: if (@to_correct) {
10277: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
1.691 raeburn 10278: $line,'missingbubble',\@to_correct,
10279: $randomorder,$randompick,\%respnumlookup,
10280: \%startline);
1.157 albertel 10281: return (1,$currentphase);
10282: }
10283:
10284: }
10285: return (0,$currentphase+1);
10286: }
10287:
1.663 raeburn 10288: sub hand_bubble_option {
10289: my (undef, undef, $sequence) =
10290: &Apache::lonnet::decode_symb($env{'form.selectpage'});
10291: return if ($sequence eq '');
10292: my $navmap = Apache::lonnavmaps::navmap->new();
10293: unless (ref($navmap)) {
10294: return;
10295: }
10296: my $needs_hand_bubbles;
10297: my $map=$navmap->getResourceByUrl($sequence);
10298: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
10299: foreach my $res (@resources) {
10300: if (ref($res)) {
10301: if ($res->is_problem()) {
10302: my $partlist = $res->parts();
10303: foreach my $part (@{ $partlist }) {
10304: my @types = $res->responseType($part);
10305: if (grep(/^(chem|essay|image|formula|math|string|functionplot)$/,@types)) {
10306: $needs_hand_bubbles = 1;
10307: last;
10308: }
10309: }
10310: }
10311: }
10312: }
10313: if ($needs_hand_bubbles) {
1.754 raeburn 10314: my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.663 raeburn 10315: my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
10316: return &mt('The sequence to be graded contains response types which are handgraded.').'<p>'.
10317: &mt('If you have already graded these by bubbling sheets to indicate points awarded, [_1]what point value is assigned to a filled last bubble in each row?','<br />').
10318: '<label><input type="radio" name="scantron_lastbubblepoints" value="'.$bubbles_per_row.'" checked="checked" />'.&mt('[quant,_1,point]',$bubbles_per_row).'</label> '.&mt('or').' '.
1.722 raeburn 10319: '<label><input type="radio" name="scantron_lastbubblepoints" value="0" />'.&mt('0 points').'</label></p>';
1.663 raeburn 10320: }
10321: return;
10322: }
1.423 albertel 10323:
1.82 albertel 10324: sub scantron_process_students {
1.608 www 10325: my ($r,$symb) = @_;
1.513 foxr 10326:
1.257 albertel 10327: my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($env{'form.selectpage'});
1.513 foxr 10328: if (!$symb) {
10329: return '';
10330: }
1.324 albertel 10331: my $default_form_data=&defaultFormData($symb);
1.82 albertel 10332:
1.754 raeburn 10333: my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.691 raeburn 10334: my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
1.157 albertel 10335: my ($scanlines,$scan_data)=&scantron_getfile();
1.82 albertel 10336: my $classlist=&Apache::loncoursedata::get_classlist();
10337: my %idmap=&username_to_idmap($classlist);
1.132 bowersj2 10338: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 10339: unless (ref($navmap)) {
10340: $r->print(&navmap_errormsg());
10341: return '';
1.691 raeburn 10342: }
1.83 albertel 10343: my $map=$navmap->getResourceByUrl($sequence);
1.691 raeburn 10344: my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
1.788 raeburn 10345: %grader_randomlists_by_symb,%symb_for_examcode);
1.677 raeburn 10346: if (ref($map)) {
10347: $randomorder = $map->randomorder();
1.689 raeburn 10348: $randompick = $map->randompick();
1.788 raeburn 10349: unless ($randomorder || $randompick) {
10350: foreach my $res ($navmap->retrieveResources($map,sub { $_[0]->is_map() },1,0,1)) {
10351: if ($res->randomorder()) {
10352: $randomorder = 1;
10353: }
10354: if ($res->randompick()) {
10355: $randompick = 1;
10356: }
10357: last if ($randomorder || $randompick);
10358: }
10359: }
1.691 raeburn 10360: } else {
10361: $r->print(&navmap_errormsg());
10362: return '';
1.677 raeburn 10363: }
1.691 raeburn 10364: my $nav_error;
1.83 albertel 10365: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.691 raeburn 10366: if ($randomorder || $randompick) {
1.788 raeburn 10367: $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource,1,\%symb_for_examcode);
1.691 raeburn 10368: if ($nav_error) {
10369: $r->print(&navmap_errormsg());
10370: return '';
10371: }
10372: }
1.557 raeburn 10373: &graders_resources_pass(\@resources,\%grader_partids_by_symb,
1.649 raeburn 10374: \%grader_randomlists_by_symb,$bubbles_per_row);
1.557 raeburn 10375:
1.554 raeburn 10376: my ($uname,$udom);
1.82 albertel 10377: my $result= <<SCANTRONFORM;
1.81 albertel 10378: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
10379: <input type="hidden" name="command" value="scantron_configphase" />
10380: $default_form_data
10381: SCANTRONFORM
1.82 albertel 10382: $r->print($result);
10383:
1.770 raeburn 10384: my ($checksec,@possibles)=&gradable_sections();
1.82 albertel 10385: my @delayqueue;
1.542 raeburn 10386: my (%completedstudents,%scandata);
1.770 raeburn 10387:
1.520 www 10388: my $lock=&Apache::lonnet::set_lock(&mt('Grading bubblesheet exam'));
1.200 albertel 10389: my $count=&get_todo_count($scanlines,$scan_data);
1.667 www 10390: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$count);
10391: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,'Processing first student');
1.542 raeburn 10392: $r->print('<br />');
1.140 albertel 10393: my $start=&Time::HiRes::time();
1.158 albertel 10394: my $i=-1;
1.542 raeburn 10395: my $started;
1.447 foxr 10396:
1.649 raeburn 10397: &scantron_get_maxbubble(\$nav_error,\%scantron_config); # Need the bubble lines array to parse.
1.582 raeburn 10398: if ($nav_error) {
10399: $r->print(&navmap_errormsg());
10400: return '';
10401: }
10402:
1.513 foxr 10403: # If an ssi failed in scantron_get_maxbubble, put an error message out to
10404: # the user and return.
10405:
10406: if ($ssi_error) {
10407: $r->print("</form>");
10408: &ssi_print_error($r);
1.520 www 10409: &Apache::lonnet::remove_lock($lock);
1.513 foxr 10410: return ''; # Dunno why the other returns return '' rather than just returning.
10411: }
1.447 foxr 10412:
1.755 raeburn 10413: my %lettdig = &Apache::lonnet::letter_to_digits();
1.542 raeburn 10414: my $numletts = scalar(keys(%lettdig));
1.691 raeburn 10415: my %orderedforcode;
1.542 raeburn 10416:
1.157 albertel 10417: while ($i<$scanlines->{'count'}) {
10418: ($uname,$udom)=('','');
10419: $i++;
1.200 albertel 10420: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 10421: if ($line=~/^[\s\cz]*$/) { next; }
1.200 albertel 10422: if ($started) {
1.667 www 10423: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student');
1.200 albertel 10424: }
10425: $started=1;
1.691 raeburn 10426: my %respnumlookup = ();
10427: my %startline = ();
10428: my $total;
1.157 albertel 10429: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
1.691 raeburn 10430: $scan_data,undef,\%idmap,$randomorder,
10431: $randompick,$sequence,\@master_seq,
10432: \%symb_to_resource,\%grader_partids_by_symb,
10433: \%orderedforcode,\%respnumlookup,\%startline,
10434: \$total);
1.157 albertel 10435: unless ($uname=&scantron_find_student($scan_record,$scan_data,
10436: \%idmap,$i)) {
10437: &scantron_add_delay(\@delayqueue,$line,
10438: 'Unable to find a student that matches',1);
10439: next;
10440: }
10441: if (exists $completedstudents{$uname}) {
10442: &scantron_add_delay(\@delayqueue,$line,
10443: 'Student '.$uname.' has multiple sheets',2);
10444: next;
10445: }
1.677 raeburn 10446: my $usec = $classlist->{$uname}->[&Apache::loncoursedata::CL_SECTION];
1.770 raeburn 10447: if (($checksec ne '') && ($checksec ne $usec)) {
10448: unless (grep(/^\Q$usec\E$/,@possibles)) {
10449: &scantron_add_delay(\@delayqueue,$line,
10450: "No role with manage grades privilege in student's section ($usec)",3);
10451: next;
10452: }
10453: }
1.677 raeburn 10454: my $user = $uname.':'.$usec;
1.157 albertel 10455: ($uname,$udom)=split(/:/,$uname);
1.330 albertel 10456:
1.677 raeburn 10457: my $scancode;
10458: if ((exists($scan_record->{'scantron.CODE'})) &&
10459: (&Apache::lonnet::validCODE($scan_record->{'scantron.CODE'}))) {
10460: $scancode = $scan_record->{'scantron.CODE'};
10461: } else {
10462: $scancode = '';
10463: }
10464:
10465: my @mapresources = @resources;
1.689 raeburn 10466: if ($randomorder || $randompick) {
1.678 raeburn 10467: @mapresources =
1.691 raeburn 10468: &users_order($user,$scancode,$sequence,\@master_seq,\%symb_to_resource,
10469: \%orderedforcode);
1.677 raeburn 10470: }
1.586 raeburn 10471: my (%partids_by_symb,$res_error);
1.677 raeburn 10472: foreach my $resource (@mapresources) {
1.586 raeburn 10473: my $ressymb;
10474: if (ref($resource)) {
10475: $ressymb = $resource->symb();
10476: } else {
10477: $res_error = 1;
10478: last;
10479: }
1.557 raeburn 10480: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
10481: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
1.741 raeburn 10482: my $currcode;
10483: if (exists($grader_randomlists_by_symb{$ressymb})) {
10484: $currcode = $scancode;
10485: }
1.557 raeburn 10486: my ($analysis,$parts) =
1.672 raeburn 10487: &scantron_partids_tograde($resource,$env{'request.course.id'},
1.741 raeburn 10488: $uname,$udom,undef,$bubbles_per_row,
10489: $currcode);
1.557 raeburn 10490: $partids_by_symb{$ressymb} = $parts;
10491: } else {
10492: $partids_by_symb{$ressymb} = $grader_partids_by_symb{$ressymb};
10493: }
1.554 raeburn 10494: }
10495:
1.586 raeburn 10496: if ($res_error) {
10497: &scantron_add_delay(\@delayqueue,$line,
10498: 'An error occurred while grading student '.$uname,2);
10499: next;
10500: }
10501:
1.330 albertel 10502: &Apache::lonxml::clear_problem_counter();
1.514 raeburn 10503: &Apache::lonnet::appenv($scan_record);
1.376 albertel 10504:
10505: if (&scantron_clear_skip($scanlines,$scan_data,$i)) {
10506: &scantron_putfile($scanlines,$scan_data);
10507: }
1.161 albertel 10508:
1.542 raeburn 10509: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
1.677 raeburn 10510: \@mapresources,\%partids_by_symb,
1.691 raeburn 10511: $bubbles_per_row,$randomorder,$randompick,
10512: \%respnumlookup,\%startline)
10513: eq 'ssi_error') {
1.542 raeburn 10514: $ssi_error = 0; # So end of handler error message does not trigger.
10515: $r->print("</form>");
10516: &ssi_print_error($r);
10517: &Apache::lonnet::remove_lock($lock);
10518: return ''; # Why return ''? Beats me.
10519: }
1.513 foxr 10520:
1.692 raeburn 10521: if (($scancode) && ($randomorder || $randompick)) {
1.788 raeburn 10522: foreach my $key (keys(%symb_for_examcode)) {
10523: my $symb_in_map = $symb_for_examcode{$key};
10524: if ($symb_in_map ne '') {
10525: my $parmresult =
10526: &Apache::lonparmset::storeparm_by_symb($symb_in_map,
10527: '0_examcode',2,$scancode,
10528: 'string_examcode',$uname,
10529: $udom);
10530: }
10531: }
1.692 raeburn 10532: }
1.140 albertel 10533: $completedstudents{$uname}={'line'=>$line};
1.542 raeburn 10534: if ($env{'form.verifyrecord'}) {
10535: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
1.691 raeburn 10536: if ($randompick) {
10537: if ($total) {
10538: $lastpos = $total*$scantron_config{'Qlength'};
10539: }
10540: }
10541:
1.542 raeburn 10542: my $studentdata = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
10543: chomp($studentdata);
10544: $studentdata =~ s/\r$//;
10545: my $studentrecord = '';
10546: my $counter = -1;
1.677 raeburn 10547: foreach my $resource (@mapresources) {
1.554 raeburn 10548: my $ressymb = $resource->symb();
1.542 raeburn 10549: ($counter,my $recording) =
10550: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 10551: $counter,$studentdata,$partids_by_symb{$ressymb},
1.691 raeburn 10552: \%scantron_config,\%lettdig,$numletts,$randomorder,
10553: $randompick,\%respnumlookup,\%startline);
1.542 raeburn 10554: $studentrecord .= $recording;
10555: }
10556: if ($studentrecord ne $studentdata) {
1.554 raeburn 10557: &Apache::lonxml::clear_problem_counter();
10558: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
1.677 raeburn 10559: \@mapresources,\%partids_by_symb,
1.691 raeburn 10560: $bubbles_per_row,$randomorder,$randompick,
10561: \%respnumlookup,\%startline)
10562: eq 'ssi_error') {
1.554 raeburn 10563: $ssi_error = 0; # So end of handler error message does not trigger.
10564: $r->print("</form>");
10565: &ssi_print_error($r);
10566: &Apache::lonnet::remove_lock($lock);
10567: delete($completedstudents{$uname});
10568: return '';
10569: }
1.542 raeburn 10570: $counter = -1;
10571: $studentrecord = '';
1.677 raeburn 10572: foreach my $resource (@mapresources) {
1.554 raeburn 10573: my $ressymb = $resource->symb();
1.542 raeburn 10574: ($counter,my $recording) =
10575: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 10576: $counter,$studentdata,$partids_by_symb{$ressymb},
1.691 raeburn 10577: \%scantron_config,\%lettdig,$numletts,
10578: $randomorder,$randompick,\%respnumlookup,
10579: \%startline);
1.542 raeburn 10580: $studentrecord .= $recording;
10581: }
10582: if ($studentrecord ne $studentdata) {
1.658 bisitz 10583: $r->print('<p><span class="LC_warning">');
1.542 raeburn 10584: if ($scancode eq '') {
1.658 bisitz 10585: $r->print(&mt('Mismatch grading bubblesheet for user: [_1] with ID: [_2].',
1.542 raeburn 10586: $uname.':'.$udom,$scan_record->{'scantron.ID'}));
10587: } else {
1.658 bisitz 10588: $r->print(&mt('Mismatch grading bubblesheet for user: [_1] with ID: [_2] and CODE: [_3].',
1.542 raeburn 10589: $uname.':'.$udom,$scan_record->{'scantron.ID'},$scancode));
10590: }
10591: $r->print('</span><br />'.&Apache::loncommon::start_data_table()."\n".
10592: &Apache::loncommon::start_data_table_header_row()."\n".
10593: '<th>'.&mt('Source').'</th><th>'.&mt('Bubbled responses').'</th>'.
10594: &Apache::loncommon::end_data_table_header_row()."\n".
10595: &Apache::loncommon::start_data_table_row().
1.658 bisitz 10596: '<td>'.&mt('Bubblesheet').'</td>'.
1.707 bisitz 10597: '<td><span class="LC_nobreak" style="white-space: pre;"><tt>'.$studentdata.'</tt></span></td>'.
1.542 raeburn 10598: &Apache::loncommon::end_data_table_row().
10599: &Apache::loncommon::start_data_table_row().
1.658 bisitz 10600: '<td>'.&mt('Stored submissions').'</td>'.
1.707 bisitz 10601: '<td><span class="LC_nobreak" style="white-space: pre;"><tt>'.$studentrecord.'</tt></span></td>'."\n".
1.542 raeburn 10602: &Apache::loncommon::end_data_table_row().
10603: &Apache::loncommon::end_data_table().'</p>');
10604: } else {
10605: $r->print('<br /><span class="LC_warning">'.
10606: &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 />'.
10607: &mt("As a consequence, this user's submission history records two tries.").
10608: '</span><br />');
10609: }
10610: }
10611: }
1.543 raeburn 10612: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.140 albertel 10613: } continue {
1.330 albertel 10614: &Apache::lonxml::clear_problem_counter();
1.552 raeburn 10615: &Apache::lonnet::delenv('scantron.');
1.82 albertel 10616: }
1.140 albertel 10617: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.520 www 10618: &Apache::lonnet::remove_lock($lock);
1.172 albertel 10619: # my $lasttime = &Time::HiRes::time()-$start;
10620: # $r->print("<p>took $lasttime</p>");
1.140 albertel 10621:
1.200 albertel 10622: $r->print("</form>");
1.157 albertel 10623: return '';
1.75 albertel 10624: }
1.157 albertel 10625:
1.557 raeburn 10626: sub graders_resources_pass {
1.649 raeburn 10627: my ($resources,$grader_partids_by_symb,$grader_randomlists_by_symb,
10628: $bubbles_per_row) = @_;
1.557 raeburn 10629: if ((ref($resources) eq 'ARRAY') && (ref($grader_partids_by_symb)) &&
10630: (ref($grader_randomlists_by_symb) eq 'HASH')) {
10631: foreach my $resource (@{$resources}) {
10632: my $ressymb = $resource->symb();
10633: my ($analysis,$parts) =
10634: &scantron_partids_tograde($resource,$env{'request.course.id'},
1.672 raeburn 10635: $env{'user.name'},$env{'user.domain'},
10636: 1,$bubbles_per_row);
1.557 raeburn 10637: $grader_partids_by_symb->{$ressymb} = $parts;
10638: if (ref($analysis) eq 'HASH') {
10639: if (ref($analysis->{'parts_withrandomlist'}) eq 'ARRAY') {
10640: $grader_randomlists_by_symb->{$ressymb} =
10641: $analysis->{'parts_withrandomlist'};
10642: }
10643: }
10644: }
10645: }
10646: return;
10647: }
10648:
1.678 raeburn 10649: =pod
10650:
10651: =item users_order
10652:
10653: Returns array of resources in current map, ordered based on either CODE,
10654: if this is a CODEd exam, or based on student's identity if this is a
10655: "NAMEd" exam.
10656:
1.691 raeburn 10657: Should be used when randomorder and/or randompick applied when the
10658: corresponding exam was printed, prior to students completing bubblesheets
10659: for the version of the exam the student received.
1.678 raeburn 10660:
10661: =cut
10662:
10663: sub users_order {
1.691 raeburn 10664: my ($user,$scancode,$mapurl,$master_seq,$symb_to_resource,$orderedforcode) = @_;
1.678 raeburn 10665: my @mapresources;
1.691 raeburn 10666: unless ((ref($master_seq) eq 'ARRAY') && (ref($symb_to_resource) eq 'HASH')) {
1.678 raeburn 10667: return @mapresources;
1.691 raeburn 10668: }
10669: if ($scancode) {
10670: if ((ref($orderedforcode) eq 'HASH') && (ref($orderedforcode->{$scancode}) eq 'ARRAY')) {
10671: @mapresources = @{$orderedforcode->{$scancode}};
10672: } else {
10673: $env{'form.CODE'} = $scancode;
10674: my $actual_seq =
10675: &Apache::lonprintout::master_seq_to_person_seq($mapurl,
10676: $master_seq,
10677: $user,$scancode,1);
10678: if (ref($actual_seq) eq 'ARRAY') {
10679: @mapresources = map { $symb_to_resource->{$_}; } @{$actual_seq};
10680: if (ref($orderedforcode) eq 'HASH') {
10681: if (@mapresources > 0) {
10682: $orderedforcode->{$scancode} = \@mapresources;
10683: }
10684: }
10685: }
10686: delete($env{'form.CODE'});
1.678 raeburn 10687: }
10688: } else {
10689: my $actual_seq =
10690: &Apache::lonprintout::master_seq_to_person_seq($mapurl,
10691: $master_seq,
1.688 raeburn 10692: $user,undef,1);
1.678 raeburn 10693: if (ref($actual_seq) eq 'ARRAY') {
10694: @mapresources =
10695: map { $symb_to_resource->{$_}; } @{$actual_seq};
10696: }
1.691 raeburn 10697: }
10698: return @mapresources;
1.678 raeburn 10699: }
10700:
1.542 raeburn 10701: sub grade_student_bubbles {
1.691 raeburn 10702: my ($r,$uname,$udom,$scan_record,$scancode,$resources,$parts,$bubbles_per_row,
10703: $randomorder,$randompick,$respnumlookup,$startline) = @_;
10704: my $uselookup = 0;
10705: if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH') &&
10706: (ref($startline) eq 'HASH')) {
10707: $uselookup = 1;
10708: }
10709:
1.554 raeburn 10710: if (ref($resources) eq 'ARRAY') {
10711: my $count = 0;
10712: foreach my $resource (@{$resources}) {
10713: my $ressymb = $resource->symb();
10714: my %form = ('submitted' => 'scantron',
10715: 'grade_target' => 'grade',
10716: 'grade_username' => $uname,
10717: 'grade_domain' => $udom,
10718: 'grade_courseid' => $env{'request.course.id'},
10719: 'grade_symb' => $ressymb,
10720: 'CODE' => $scancode
10721: );
1.649 raeburn 10722: if ($bubbles_per_row ne '') {
10723: $form{'bubbles_per_row'} = $bubbles_per_row;
10724: }
1.663 raeburn 10725: if ($env{'form.scantron_lastbubblepoints'} ne '') {
10726: $form{'scantron_lastbubblepoints'} = $env{'form.scantron_lastbubblepoints'};
10727: }
1.554 raeburn 10728: if (ref($parts) eq 'HASH') {
10729: if (ref($parts->{$ressymb}) eq 'ARRAY') {
10730: foreach my $part (@{$parts->{$ressymb}}) {
1.691 raeburn 10731: if ($uselookup) {
10732: $form{'scantron_questnum_start.'.$part} = $startline->{$count} + 1;
10733: } else {
10734: $form{'scantron_questnum_start.'.$part} =
10735: 1+$env{'form.scantron.first_bubble_line.'.$count};
10736: }
1.554 raeburn 10737: $count++;
10738: }
10739: }
10740: }
10741: my $result=&ssi_with_retries($resource->src(),$ssi_retries,%form);
10742: return 'ssi_error' if ($ssi_error);
10743: last if (&Apache::loncommon::connection_aborted($r));
10744: }
1.542 raeburn 10745: }
10746: return;
10747: }
10748:
1.157 albertel 10749: sub scantron_upload_scantron_data {
1.767 raeburn 10750: my ($r,$symb) = @_;
1.565 raeburn 10751: my $dom = $env{'request.role.domain'};
1.754 raeburn 10752: my ($formatoptions,$formattitle,$formatjs) = &scantron_upload_dataformat($dom);
1.565 raeburn 10753: my $domdesc = &Apache::lonnet::domain($dom,'description');
10754: $r->print(&Apache::loncommon::coursebrowser_javascript($dom));
1.157 albertel 10755: my $select_link=&Apache::loncommon::selectcourse_link('rules','courseid',
1.181 albertel 10756: 'domainid',
1.565 raeburn 10757: 'coursename',$dom);
10758: my $syllabuslink = '<a href="javascript:ToSyllabus();">'.&mt('Syllabus').'</a>'.
10759: (' 'x2).&mt('(shows course personnel)');
1.608 www 10760: my $default_form_data=&defaultFormData($symb);
1.579 raeburn 10761: my $nofile_alert = &mt('Please use the browse button to select a file from your local directory.');
1.736 damieng 10762: &js_escape(\$nofile_alert);
1.579 raeburn 10763: 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.736 damieng 10764: &js_escape(\$nocourseid_alert);
1.597 wenzelju 10765: $r->print(&Apache::lonhtmlcommon::scripttag('
1.157 albertel 10766: function checkUpload(formname) {
10767: if (formname.upfile.value == "") {
1.579 raeburn 10768: alert("'.$nofile_alert.'");
1.157 albertel 10769: return false;
10770: }
1.565 raeburn 10771: if (formname.courseid.value == "") {
1.579 raeburn 10772: alert("'.$nocourseid_alert.'");
1.565 raeburn 10773: return false;
10774: }
1.157 albertel 10775: formname.submit();
10776: }
1.565 raeburn 10777:
10778: function ToSyllabus() {
10779: var cdom = '."'$dom'".';
10780: var cnum = document.rules.courseid.value;
10781: if (cdom == "" || cdom == null) {
10782: return;
10783: }
10784: if (cnum == "" || cnum == null) {
10785: return;
10786: }
10787: syllwin=window.open("/public/"+cdom+"/"+cnum+"/syllabus","LONCAPASyllabus",
10788: "height=350,width=350,scrollbars=yes,menubar=no");
10789: return;
10790: }
10791:
1.754 raeburn 10792: '.$formatjs.'
1.597 wenzelju 10793: '));
10794: $r->print('
1.648 bisitz 10795: <h3>'.&mt('Send bubblesheet data to a course').'</h3>
1.566 raeburn 10796:
1.492 albertel 10797: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
1.565 raeburn 10798: '.$default_form_data.
10799: &Apache::lonhtmlcommon::start_pick_box().
10800: &Apache::lonhtmlcommon::row_title(&mt('Course ID')).
10801: '<input name="courseid" type="text" size="30" />'.$select_link.
10802: &Apache::lonhtmlcommon::row_closure().
10803: &Apache::lonhtmlcommon::row_title(&mt('Course Name')).
10804: '<input name="coursename" type="text" size="30" />'.$syllabuslink.
10805: &Apache::lonhtmlcommon::row_closure().
10806: &Apache::lonhtmlcommon::row_title(&mt('Domain')).
10807: '<input name="domainid" type="hidden" />'.$domdesc.
1.754 raeburn 10808: &Apache::lonhtmlcommon::row_closure());
10809: if ($formatoptions) {
10810: $r->print(&Apache::lonhtmlcommon::row_title($formattitle).$formatoptions.
10811: &Apache::lonhtmlcommon::row_closure());
10812: }
10813: $r->print(
1.565 raeburn 10814: &Apache::lonhtmlcommon::row_title(&mt('File to upload')).
10815: '<input type="file" name="upfile" size="50" />'.
10816: &Apache::lonhtmlcommon::row_closure(1).
10817: &Apache::lonhtmlcommon::end_pick_box().'<br />
10818:
1.492 albertel 10819: <input name="command" value="scantronupload_save" type="hidden" />
1.589 bisitz 10820: <input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
1.157 albertel 10821: </form>
1.492 albertel 10822: ');
1.157 albertel 10823: return '';
10824: }
10825:
1.754 raeburn 10826: sub scantron_upload_dataformat {
10827: my ($dom) = @_;
10828: my ($formatoptions,$formattitle,$formatjs);
10829: $formatjs = <<'END';
10830: function toggleScantab(form) {
10831: return;
10832: }
10833: END
10834: my %domconfig = &Apache::lonnet::get_dom('configuration',['scantron'],$dom);
10835: if (ref($domconfig{'scantron'}) eq 'HASH') {
10836: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
10837: if (keys(%{$domconfig{'scantron'}{'config'}}) > 1) {
10838: if (($domconfig{'scantron'}{'config'}{'dat'}) &&
10839: (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH')) {
1.756 raeburn 10840: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
10841: if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}})) {
10842: my ($onclick,$formatextra,$singleline);
10843: my @lines = &Apache::lonnet::get_scantronformat_file();
10844: my $count = 0;
10845: foreach my $line (@lines) {
1.790 raeburn 10846: next if (($line =~ /^\#/) || ($line eq ''));
1.756 raeburn 10847: $singleline = $line;
10848: $count ++;
10849: }
10850: if ($count > 1) {
10851: $formatextra = '<div style="display:none" id="bubbletype">'.
1.757 raeburn 10852: '<span class="LC_nobreak">'.
1.776 raeburn 10853: &mt('Bubblesheet type').': '.
1.757 raeburn 10854: &scantron_scantab().'</span></div>';
1.756 raeburn 10855: $onclick = ' onclick="toggleScantab(this.form);"';
10856: $formatjs = <<"END";
1.754 raeburn 10857: function toggleScantab(form) {
10858: var divid = 'bubbletype';
10859: if (document.getElementById(divid)) {
10860: var radioname = 'fileformat';
10861: var num = form.elements[radioname].length;
10862: if (num) {
10863: for (var i=0; i<num; i++) {
10864: if (form.elements[radioname][i].checked) {
10865: var chosen = form.elements[radioname][i].value;
10866: if (chosen == 'dat') {
10867: document.getElementById(divid).style.display = 'none';
10868: } else if (chosen == 'csv') {
1.757 raeburn 10869: document.getElementById(divid).style.display = 'block';
1.754 raeburn 10870: }
10871: }
10872: }
10873: }
10874: }
10875: return;
10876: }
10877:
10878: END
1.756 raeburn 10879: } elsif ($count == 1) {
10880: my $formatname = (split(/:/,$singleline,2))[0];
10881: $formatextra = '<input type="hidden" name="scantron_format" value="'.$formatname.'" />';
10882: }
10883: $formattitle = &mt('File format');
10884: $formatoptions = '<label><input name="fileformat" type="radio" value="dat" checked="checked"'.$onclick.' />'.
10885: &mt('Plain Text (no delimiters)').
10886: '</label>'.(' 'x2).
10887: '<label><input name="fileformat" type="radio" value="csv"'.$onclick.' />'.
10888: &mt('Comma separated values').'</label>'.$formatextra;
1.754 raeburn 10889: }
10890: }
10891: }
10892: } elsif (keys(%{$domconfig{'scantron'}{'config'}}) == 1) {
1.756 raeburn 10893: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
10894: if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}})) {
1.757 raeburn 10895: $formattitle = &mt('Bubblesheet type');
1.756 raeburn 10896: $formatoptions = &scantron_scantab();
10897: }
1.754 raeburn 10898: }
10899: }
10900: }
10901: }
10902: return ($formatoptions,$formattitle,$formatjs);
10903: }
1.423 albertel 10904:
1.157 albertel 10905: sub scantron_upload_scantron_data_save {
1.767 raeburn 10906: my ($r,$symb) = @_;
1.182 albertel 10907: my $doanotherupload=
10908: '<br /><form action="/adm/grades" method="post">'."\n".
10909: '<input type="hidden" name="command" value="scantronupload" />'."\n".
1.492 albertel 10910: '<input type="submit" name="submit" value="'.&mt('Do Another Upload').'" />'."\n".
1.182 albertel 10911: '</form>'."\n";
1.257 albertel 10912: if (!&Apache::lonnet::allowed('usc',$env{'form.domainid'}) &&
1.162 albertel 10913: !&Apache::lonnet::allowed('usc',
1.770 raeburn 10914: $env{'form.domainid'}.'_'.$env{'form.courseid'}) &&
10915: !&Apache::lonnet::allowed('usc',
10916: $env{'form.domainid'}.'_'.$env{'form.courseid'}.'/'.$env{'form.coursesec'})) {
1.575 www 10917: $r->print(&mt("You are not allowed to upload bubblesheet data to the requested course.")."<br />");
1.614 www 10918: unless ($symb) {
1.182 albertel 10919: $r->print($doanotherupload);
10920: }
1.162 albertel 10921: return '';
10922: }
1.257 albertel 10923: my %coursedata=&Apache::lonnet::coursedescription($env{'form.domainid'}.'_'.$env{'form.courseid'});
1.568 raeburn 10924: my $uploadedfile;
1.710 bisitz 10925: $r->print('<p>'.&mt('Uploading file to [_1]','"'.$coursedata{'description'}.'"').'</p>');
1.257 albertel 10926: if (length($env{'form.upfile'}) < 2) {
1.710 bisitz 10927: $r->print(
10928: &Apache::lonhtmlcommon::confirm_success(
10929: &mt('The file: [_1] you attempted to upload contained no information. Please check that you entered the correct filename.',
10930: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'),1));
1.183 albertel 10931: } else {
1.754 raeburn 10932: my %domconfig = &Apache::lonnet::get_dom('configuration',['scantron'],$env{'form.domainid'});
10933: my $parser;
10934: if (ref($domconfig{'scantron'}) eq 'HASH') {
10935: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
10936: my $is_csv;
10937: my @possibles = keys(%{$domconfig{'scantron'}{'config'}});
10938: if (@possibles > 1) {
10939: if ($env{'form.fileformat'} eq 'csv') {
10940: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.756 raeburn 10941: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
10942: if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}}) > 1) {
10943: $is_csv = 1;
10944: }
1.754 raeburn 10945: }
10946: }
10947: }
10948: } elsif (@possibles == 1) {
10949: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.756 raeburn 10950: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
10951: if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}}) > 1) {
10952: $is_csv = 1;
10953: }
1.754 raeburn 10954: }
10955: }
10956: }
10957: if ($is_csv) {
10958: $parser = $domconfig{'scantron'}{'config'}{'csv'};
10959: }
10960: }
10961: }
10962: my $result =
10963: &Apache::lonnet::userfileupload('upfile','scantron','scantron',$parser,'','',
1.568 raeburn 10964: $env{'form.courseid'},$env{'form.domainid'});
1.710 bisitz 10965: if ($result =~ m{^/uploaded/}) {
10966: $r->print(
10967: &Apache::lonhtmlcommon::confirm_success(&mt('Upload successful')).'<br />'.
10968: &mt('Uploaded [_1] bytes of data into location: [_2]',
10969: (length($env{'form.upfile'})-1),
10970: '<span class="LC_filename">'.$result.'</span>'));
1.568 raeburn 10971: ($uploadedfile) = ($result =~ m{/([^/]+)$});
1.770 raeburn 10972: if ($uploadedfile =~ /^scantron_orig_/) {
10973: my $logname = $uploadedfile;
10974: $logname =~ s/^scantron_orig_//;
10975: if ($logname ne '') {
10976: my $now = time;
10977: my %info = ($logname => { $now => $env{'user.name'}.':'.$env{'user.domain'} });
10978: &Apache::lonnet::put('scantronupload',\%info,$env{'form.domainid'},$env{'form.courseid'});
10979: }
10980: }
1.567 raeburn 10981: $r->print(&validate_uploaded_scantron_file($env{'form.domainid'},
1.770 raeburn 10982: $env{'form.courseid'},$symb,$uploadedfile));
1.710 bisitz 10983: } else {
10984: $r->print(
10985: &Apache::lonhtmlcommon::confirm_success(&mt('Upload failed'),1).'<br />'.
10986: &mt('An error ([_1]) occurred when attempting to upload the file: [_2]',
10987: $result,
1.568 raeburn 10988: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'));
1.183 albertel 10989: }
10990: }
1.174 albertel 10991: if ($symb) {
1.612 www 10992: $r->print(&scantron_selectphase($r,$uploadedfile,$symb));
1.174 albertel 10993: } else {
1.182 albertel 10994: $r->print($doanotherupload);
1.174 albertel 10995: }
1.157 albertel 10996: return '';
10997: }
10998:
1.567 raeburn 10999: sub validate_uploaded_scantron_file {
1.770 raeburn 11000: my ($cdom,$cname,$symb,$fname,$context,$countsref) = @_;
11001:
1.567 raeburn 11002: my $scanlines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.$fname);
11003: my @lines;
11004: if ($scanlines ne '-1') {
11005: @lines=split("\n",$scanlines,-1);
11006: }
1.770 raeburn 11007: my ($output,$secidx,$checksec,$priv,%crsroleshash,@possibles);
11008: $secidx = &Apache::loncoursedata::CL_SECTION();
11009: if ($context eq 'download') {
11010: $priv = 'mgr';
11011: } else {
11012: $priv = 'usc';
11013: }
11014: unless ((&Apache::lonnet::allowed($priv,$env{'request.role.domain'})) ||
11015: (($env{'request.course.id'}) &&
11016: (&Apache::lonnet::allowed($priv,$env{'request.course.id'})))) {
11017: if ($env{'request.course.sec'} ne '') {
11018: unless (&Apache::lonnet::allowed($priv,
11019: "$env{'request.course.id'}/$env{'request.course.sec'}")) {
11020: unless ($context eq 'download') {
11021: $output = '<p class="LC_warning">'.&mt('You do not have permission to upload bubblesheet data').'</p>';
11022: }
11023: return $output;
11024: }
11025: ($checksec,@possibles)=&gradable_sections();
11026: }
11027: }
1.567 raeburn 11028: if (@lines) {
11029: my (%counts,$max_match_format);
1.710 bisitz 11030: my ($found_match_count,$max_match_count,$max_match_pct) = (0,0,0);
1.567 raeburn 11031: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cname);
11032: my %idmap = &username_to_idmap($classlist);
11033: foreach my $key (keys(%idmap)) {
11034: my $lckey = lc($key);
11035: $idmap{$lckey} = $idmap{$key};
11036: }
11037: my %unique_formats;
1.754 raeburn 11038: my @formatlines = &Apache::lonnet::get_scantronformat_file();
1.567 raeburn 11039: foreach my $line (@formatlines) {
1.790 raeburn 11040: next if (($line =~ /^\#/) || ($line eq ''));
1.567 raeburn 11041: my @config = split(/:/,$line);
11042: my $idstart = $config[5];
11043: my $idlength = $config[6];
11044: if (($idstart ne '') && ($idlength > 0)) {
11045: if (ref($unique_formats{$idstart.':'.$idlength}) eq 'ARRAY') {
11046: push(@{$unique_formats{$idstart.':'.$idlength}},$config[0].':'.$config[1]);
11047: } else {
11048: $unique_formats{$idstart.':'.$idlength} = [$config[0].':'.$config[1]];
11049: }
11050: }
11051: }
11052: foreach my $key (keys(%unique_formats)) {
11053: my ($idstart,$idlength) = split(':',$key);
11054: %{$counts{$key}} = (
11055: 'found' => 0,
11056: 'total' => 0,
1.770 raeburn 11057: 'totalanysec' => 0,
11058: 'othersec' => 0,
1.567 raeburn 11059: );
11060: foreach my $line (@lines) {
11061: next if ($line =~ /^#/);
11062: next if ($line =~ /^[\s\cz]*$/);
11063: my $id = substr($line,$idstart-1,$idlength);
11064: $id = lc($id);
11065: if (exists($idmap{$id})) {
1.770 raeburn 11066: if ($checksec ne '') {
11067: $counts{$key}{'totalanysec'} ++;
11068: if (ref($classlist->{$idmap{$id}}) eq 'ARRAY') {
11069: my $stusec = $classlist->{$idmap{$id}}->[$secidx];
11070: if ($stusec ne $checksec) {
11071: if (@possibles) {
11072: unless (grep(/^\Q$stusec\E$/,@possibles)) {
11073: $counts{$key}{'othersec'} ++;
11074: next;
11075: }
11076: } else {
11077: $counts{$key}{'othersec'} ++;
11078: next;
11079: }
11080: }
11081: }
11082: }
1.567 raeburn 11083: $counts{$key}{'found'} ++;
11084: }
11085: $counts{$key}{'total'} ++;
11086: }
11087: if ($counts{$key}{'total'}) {
11088: my $percent_match = (100*$counts{$key}{'found'})/($counts{$key}{'total'});
11089: if (($max_match_format eq '') || ($percent_match > $max_match_pct)) {
11090: $max_match_pct = $percent_match;
11091: $max_match_format = $key;
1.710 bisitz 11092: $found_match_count = $counts{$key}{'found'};
1.567 raeburn 11093: $max_match_count = $counts{$key}{'total'};
11094: }
11095: }
11096: }
1.770 raeburn 11097: if ((ref($unique_formats{$max_match_format}) eq 'ARRAY') && ($context ne 'download')) {
1.567 raeburn 11098: my $format_descs;
11099: my $numwithformat = @{$unique_formats{$max_match_format}};
11100: for (my $i=0; $i<$numwithformat; $i++) {
11101: my ($name,$desc) = split(':',$unique_formats{$max_match_format}[$i]);
11102: if ($i<$numwithformat-2) {
11103: $format_descs .= '"<i>'.$desc.'</i>", ';
11104: } elsif ($i==$numwithformat-2) {
11105: $format_descs .= '"<i>'.$desc.'</i>" '.&mt('and').' ';
11106: } elsif ($i==$numwithformat-1) {
11107: $format_descs .= '"<i>'.$desc.'</i>"';
11108: }
11109: }
11110: my $showpct = sprintf("%.0f",$max_match_pct).'%';
1.710 bisitz 11111: $output .= '<br />';
11112: if ($found_match_count == $max_match_count) {
11113: # 100% matching entries
11114: $output .= &Apache::lonhtmlcommon::confirm_success(
11115: &mt('Comparison of student IDs: [_1] matching ([quant,_2,entry,entries])',
11116: '<b>'.$showpct.'</b>',$found_match_count)).'<br />'.
11117: &mt('Comparison of student IDs in the uploaded file with'.
11118: ' the course roster found matches for [_1] of the [_2] entries'.
11119: ' in the file (for the format defined for [_3]).',
11120: '<b>'.$showpct.'</b>','<b>'.$max_match_count.'</b>',$format_descs);
11121: } else {
11122: # Not all entries matching? -> Show warning and additional info
11123: $output .=
11124: &Apache::lonhtmlcommon::confirm_success(
11125: &mt('Comparison of student IDs: [_1] matching ([_2]/[quant,_3,entry,entries])',
11126: '<b>'.$showpct.'</b>',$found_match_count,$max_match_count).'<br />'.
11127: &mt('Not all entries could be matched!'),1).'<br />'.
11128: &mt('Comparison of student IDs in the uploaded file with'.
11129: ' the course roster found matches for [_1] of the [_2] entries'.
11130: ' in the file (for the format defined for [_3]).',
11131: '<b>'.$showpct.'</b>','<b>'.$max_match_count.'</b>',$format_descs).
11132: '<p class="LC_info">'.
11133: &mt('A low percentage of matches results from one of the following:').
11134: '</p><ul>'.
11135: '<li>'.&mt('The file was uploaded to the wrong course.').'</li>'.
11136: '<li>'.&mt('The data is not in the format expected for the domain: [_1]',
11137: '<i>'.$cdom.'</i>').'</li>'.
11138: '<li>'.&mt('Students did not bubble their IDs, or mis-bubbled them').'</li>'.
11139: '<li>'.&mt('The course roster is not up to date.').'</li>'.
11140: '</ul>';
11141: }
1.770 raeburn 11142: if (($checksec ne '') && (ref($counts{$max_match_format}) eq 'HASH')) {
11143: if ($counts{$max_match_format}{'othersec'}) {
11144: my $percent_nongrade = (100*$counts{$max_match_format}{'othersec'})/($counts{$max_match_format}{'totalanysec'});
11145: my $showpct = sprintf("%.0f",$percent_nongrade).'%';
11146: my $confirmdel = &mt('Are you sure you want to permanently delete this file?');
11147: &js_escape(\$confirmdel);
11148: $output .= '<p class="LC_warning">'.
11149: &mt('Comparison of student IDs in the uploaded file with the course roster found [_1][quant,_2,match,matches][_3] for students in section(s) for which none of your role(s) have privileges to modify grades',
11150: '<b>',$counts{$max_match_format}{'othersec'},'</b>').
11151: '<br />'.
11152: &mt('Unless you are assigned role(s) which allow modification of grades in additional sections, [_1] of the records in this file will be automatically excluded when you perform bubblesheet grading.','<b>'.$showpct.'</b>').
11153: '</p><p>'.
11154: &mt('If you prefer to delete the file now, use: [_1]').
11155: '<form method="post" name="delupload" action="/adm/grades">'.
11156: '<input type="hidden" name="symb" value="'.$symb.'" />'.
11157: '<input type="hidden" name="domainid" value="'.$cdom.'" />'.
11158: '<input type="hidden" name="courseid" value="'.$cname.'" />'.
11159: '<input type="hidden" name="coursesec" value="'.$env{'request.course.sec'}.'" />'.
11160: '<input type="hidden" name="uploadedfile" value="'.$fname.'" />'.
11161: '<input type="hidden" name="command" value="scantronupload_delete" />'.
11162: '<input type="button" name="delbutton" value="'.&mt('Delete Uploaded File').'" onclick="javascript:if (confirm('."'$confirmdel'".')) { document.delupload.submit(); }" />'.
11163: '</form></p>';
11164: }
11165: }
1.567 raeburn 11166: }
1.770 raeburn 11167: if (($context eq 'download') && ($checksec ne '')) {
11168: if ((ref($countsref) eq 'HASH') && (ref($counts{$max_match_format}) eq 'HASH')) {
11169: $countsref->{'totalanysec'} = $counts{$max_match_format}{'totalanysec'};
11170: $countsref->{'othersec'} = $counts{$max_match_format}{'othersec'};
11171: }
11172: }
11173: } elsif ($context ne 'download') {
1.710 bisitz 11174: $output = '<p class="LC_warning">'.&mt('Uploaded file contained no data').'</p>';
1.567 raeburn 11175: }
11176: return $output;
11177: }
11178:
1.770 raeburn 11179: sub gradable_sections {
11180: my $checksec = $env{'request.course.sec'};
11181: my @oksecs;
11182: if ($checksec) {
11183: my %availablesecs = §ions_grade_privs();
11184: if (ref($availablesecs{'mgr'}) eq 'ARRAY') {
11185: foreach my $sec (@{$availablesecs{'mgr'}}) {
11186: unless (grep(/^\Q$sec\E$/,@oksecs)) {
11187: push(@oksecs,$sec);
11188: }
11189: }
11190: if (grep(/^all$/,@oksecs)) {
11191: undef($checksec);
11192: }
11193: }
11194: }
11195: return($checksec,@oksecs);
11196: }
11197:
11198: sub sections_grade_privs {
11199: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11200: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
11201: my %availablesecs = (
11202: mgr => [],
11203: vgr => [],
11204: usc => [],
11205: );
11206: my $ccrole = 'cc';
11207: if ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Community') {
11208: $ccrole = 'co';
11209: }
11210: my %crsroleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},
11211: 'userroles',['active'],
11212: [$ccrole,'in','cr'],$cdom,1);
11213: my $crsid = $cnum.':'.$cdom;
11214: foreach my $item (keys(%crsroleshash)) {
11215: next unless ($item =~ /^$crsid\:/);
11216: my ($crsnum,$crsdom,$role,$sec) = split(/\:/,$item);
11217: my $suffix = "/$cdom/$cnum./$cdom/$cnum";
11218: if ($sec ne '') {
11219: $suffix = "/$cdom/$cnum/$sec./$cdom/$cnum/$sec";
11220: }
11221: if (($role eq $ccrole) || ($role eq 'in')) {
11222: foreach my $priv ('mgr','vgr','usc') {
11223: unless (grep(/^all$/,@{$availablesecs{$priv}})) {
11224: if ($sec eq '') {
11225: $availablesecs{$priv} = ['all'];
11226: } elsif ($sec ne $env{'request.course.sec'}) {
11227: unless (grep(/^\Q$sec\E$/,@{$availablesecs{$priv}})) {
11228: push(@{$availablesecs{$priv}},$sec);
11229: }
11230: }
11231: }
11232: }
11233: } elsif ($role =~ m{^cr/}) {
11234: foreach my $priv ('mgr','vgr','usc') {
11235: unless (grep(/^all$/,@{$availablesecs{$priv}})) {
11236: if ($env{"user.priv.$role.$suffix"} =~ /:$priv&/) {
11237: if ($sec eq '') {
11238: $availablesecs{$priv} = ['all'];
11239: } elsif ($sec ne $env{'request.course.sec'}) {
11240: unless (grep(/^\Q$sec\E$/,@{$availablesecs{$priv}})) {
11241: push(@{$availablesecs{$priv}},$sec);
11242: }
11243: }
11244: }
11245: }
11246: }
11247: }
11248: }
11249: return %availablesecs;
11250: }
11251:
11252: sub scantron_upload_delete {
11253: my ($r,$symb) = @_;
11254: my $filename = $env{'form.uploadedfile'};
11255: if ($filename =~ /^scantron_orig_/) {
11256: if (&Apache::lonnet::allowed('usc',$env{'form.domainid'}) ||
11257: &Apache::lonnet::allowed('usc',
11258: $env{'form.domainid'}.'_'.$env{'form.courseid'}) ||
11259: &Apache::lonnet::allowed('usc',
11260: $env{'form.domainid'}.'_'.$env{'form.courseid'}.'/'.$env{'form.coursesec'})) {
11261: my $uploadurl = '/uploaded/'.$env{'form.domainid'}.'/'.$env{'form.courseid'}.'/'.$env{'form.uploadedfile'};
11262: my $retrieval = &Apache::lonnet::getfile($uploadurl);
11263: if ($retrieval eq '-1') {
11264: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('File deletion failed'),1).'<br />'.
11265: &mt('File requested for deletion not found.'));
11266: } else {
11267: $filename =~ s/^scantron_orig_//;
11268: if ($filename ne '') {
11269: my ($is_valid,$numleft);
11270: my %info = &Apache::lonnet::get('scantronupload',[$filename],$env{'form.domainid'},$env{'form.courseid'});
11271: if (keys(%info)) {
11272: if (ref($info{$filename}) eq 'HASH') {
11273: foreach my $timestamp (sort(keys(%{$info{$filename}}))) {
11274: if ($info{$filename}{$timestamp} eq $env{'user.name'}.':'.$env{'user.domain'}) {
11275: $is_valid = 1;
11276: delete($info{$filename}{$timestamp});
11277: }
11278: }
11279: $numleft = scalar(keys(%{$info{$filename}}));
11280: }
11281: }
11282: if ($is_valid) {
11283: my $result = &Apache::lonnet::removeuploadedurl($uploadurl);
11284: if ($result eq 'ok') {
11285: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('File deletion successful')).'<br />');
11286: if ($numleft) {
11287: &Apache::lonnet::put('scantronupload',\%info,$env{'form.domainid'},$env{'form.courseid'});
11288: } else {
11289: &Apache::lonnet::del('scantronupload',[$filename],$env{'form.domainid'},$env{'form.courseid'});
11290: }
11291: } else {
11292: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('File deletion failed'),1).'<br />'.
11293: &mt('Result was [_1]',$result));
11294: }
11295: } else {
11296: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('File deletion failed'),1).'<br />'.
11297: &mt('File requested for deletion was uploaded by a different user.'));
11298: }
11299: } else {
11300: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('File deletion failed'),1).'<br />'.
11301: &mt('Filename of bubblesheet data file requested for deletion is invalid.'));
11302: }
11303: }
11304: } else {
11305: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('File deletion failed'),1).'<br />'.
11306: &mt('You are not permitted to delete bubblesheet data files from the requested course.'));
11307: }
11308: } else {
11309: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('File deletion failed'),1).'<br />'.
11310: &mt('Filename of bubblesheet data file requested for deletion is invalid.'));
11311: }
11312: return;
11313: }
11314:
1.202 albertel 11315: sub valid_file {
11316: my ($requested_file)=@_;
11317: foreach my $filename (sort(&scantron_filenames())) {
11318: if ($requested_file eq $filename) { return 1; }
11319: }
11320: return 0;
11321: }
11322:
11323: sub scantron_download_scantron_data {
1.767 raeburn 11324: my ($r,$symb) = @_;
1.608 www 11325: my $default_form_data=&defaultFormData($symb);
1.257 albertel 11326: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
11327: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
11328: my $file=$env{'form.scantron_selectfile'};
1.202 albertel 11329: if (! &valid_file($file)) {
1.492 albertel 11330: $r->print('
1.202 albertel 11331: <p>
1.686 bisitz 11332: '.&mt('The requested filename was invalid.').'
1.202 albertel 11333: </p>
1.492 albertel 11334: ');
1.202 albertel 11335: return;
11336: }
1.770 raeburn 11337: my (%uploader,$is_owner,%counts,$percent);
11338: my %uploader = &Apache::lonnet::get('scantronupload',[$file],$cdom,$cname);
11339: if (ref($uploader{$file}) eq 'HASH') {
11340: foreach my $timestamp (sort { $a <=> $b } keys(%{$uploader{$file}})) {
11341: if ($uploader{$file}{$timestamp} eq $env{'user.name'}.':'.$env{'user.domain'}) {
11342: $is_owner = 1;
11343: last;
11344: }
11345: }
11346: }
11347: unless ($is_owner) {
11348: &validate_uploaded_scantron_file($cdom,$cname,$symb,'scantron_orig_'.$file,'download',\%counts);
11349: if ($counts{'totalanysec'}) {
11350: my $percent_othersec = (100*$counts{'othersec'})/($counts{'totalanysec'});
11351: if ($percent_othersec >= 10) {
11352: my $showpct = sprintf("%.0f",$percent_othersec).'%';
11353: $r->print('<p class="LC_warning">'.
11354: &mt('The original uploaded file includes [_1] or more of records for students for which none of your roles have rights to modify grades, so files are unavailable for download.',$showpct).
11355: '</p>');
11356: return;
11357: }
11358: }
11359: }
1.202 albertel 11360: my $orig='/uploaded/'.$cdom.'/'.$cname.'/scantron_orig_'.$file;
11361: my $corrected='/uploaded/'.$cdom.'/'.$cname.'/scantron_corrected_'.$file;
11362: my $skipped='/uploaded/'.$cdom.'/'.$cname.'/scantron_skipped_'.$file;
11363: &Apache::lonnet::allowuploaded('/adm/grades',$orig);
11364: &Apache::lonnet::allowuploaded('/adm/grades',$corrected);
11365: &Apache::lonnet::allowuploaded('/adm/grades',$skipped);
1.492 albertel 11366: $r->print('
1.202 albertel 11367: <p>
1.723 raeburn 11368: '.&mt('[_1]Original[_2] file as uploaded by the bubblesheet scanning office.',
1.492 albertel 11369: '<a href="'.$orig.'">','</a>').'
1.202 albertel 11370: </p>
11371: <p>
1.492 albertel 11372: '.&mt('[_1]Corrections[_2], a file of corrected records that were used in grading.',
11373: '<a href="'.$corrected.'">','</a>').'
1.202 albertel 11374: </p>
11375: <p>
1.492 albertel 11376: '.&mt('[_1]Skipped[_2], a file of records that were skipped.',
11377: '<a href="'.$skipped.'">','</a>').'
1.202 albertel 11378: </p>
1.492 albertel 11379: ');
1.202 albertel 11380: return '';
11381: }
1.157 albertel 11382:
1.523 raeburn 11383: sub checkscantron_results {
1.608 www 11384: my ($r,$symb) = @_;
1.523 raeburn 11385: if (!$symb) {return '';}
11386: my $cid = $env{'request.course.id'};
1.755 raeburn 11387: my %lettdig = &Apache::lonnet::letter_to_digits();
1.523 raeburn 11388: my $numletts = scalar(keys(%lettdig));
11389: my $cnum = $env{'course.'.$cid.'.num'};
11390: my $cdom = $env{'course.'.$cid.'.domain'};
11391: my (undef, undef, $sequence) = &Apache::lonnet::decode_symb($env{'form.selectpage'});
11392: my %record;
11393: my %scantron_config =
1.754 raeburn 11394: &Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.649 raeburn 11395: my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
1.770 raeburn 11396: my ($scanlines,$scan_data)=&scantron_getfile();
1.523 raeburn 11397: my $classlist=&Apache::loncoursedata::get_classlist();
11398: my %idmap=&Apache::grades::username_to_idmap($classlist);
11399: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 11400: unless (ref($navmap)) {
11401: $r->print(&navmap_errormsg());
11402: return '';
11403: }
1.523 raeburn 11404: my $map=$navmap->getResourceByUrl($sequence);
1.691 raeburn 11405: my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
11406: %grader_randomlists_by_symb,%orderedforcode);
1.677 raeburn 11407: if (ref($map)) {
11408: $randomorder=$map->randomorder();
1.689 raeburn 11409: $randompick=$map->randompick();
1.788 raeburn 11410: unless ($randomorder || $randompick) {
11411: foreach my $res ($navmap->retrieveResources($map,sub { $_[0]->is_map() },1,0,1)) {
11412: if ($res->randomorder()) {
11413: $randomorder = 1;
11414: }
11415: if ($res->randompick()) {
11416: $randompick = 1;
11417: }
11418: last if ($randomorder || $randompick);
11419: }
11420: }
1.677 raeburn 11421: }
1.557 raeburn 11422: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.691 raeburn 11423: my $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource);
11424: if ($nav_error) {
11425: $r->print(&navmap_errormsg());
11426: return '';
1.678 raeburn 11427: }
1.673 raeburn 11428: &graders_resources_pass(\@resources,\%grader_partids_by_symb,
11429: \%grader_randomlists_by_symb,$bubbles_per_row);
1.554 raeburn 11430: my ($uname,$udom);
1.523 raeburn 11431: my (%scandata,%lastname,%bylast);
11432: $r->print('
11433: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="checkscantron">'."\n");
11434:
11435: my @delayqueue;
11436: my %completedstudents;
11437:
1.691 raeburn 11438: my $count=&get_todo_count($scanlines,$scan_data);
1.667 www 11439: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$count);
1.706 raeburn 11440: my ($username,$domain,$started);
1.649 raeburn 11441: &scantron_get_maxbubble(\$nav_error,\%scantron_config); # Need the bubble lines array to parse.
1.582 raeburn 11442: if ($nav_error) {
11443: $r->print(&navmap_errormsg());
11444: return '';
11445: }
1.523 raeburn 11446:
1.667 www 11447: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,'Processing first student');
1.523 raeburn 11448: my $start=&Time::HiRes::time();
11449: my $i=-1;
11450:
11451: while ($i<$scanlines->{'count'}) {
11452: ($username,$domain,$uname)=('','','');
11453: $i++;
11454: my $line=&Apache::grades::scantron_get_line($scanlines,$scan_data,$i);
11455: if ($line=~/^[\s\cz]*$/) { next; }
11456: if ($started) {
1.667 www 11457: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student');
1.523 raeburn 11458: }
11459: $started=1;
11460: my $scan_record=
11461: &Apache::grades::scantron_parse_scanline($line,$i,\%scantron_config,
11462: $scan_data);
1.693 raeburn 11463: unless ($uname=&scantron_find_student($scan_record,$scan_data,
11464: \%idmap,$i)) {
1.523 raeburn 11465: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
11466: 'Unable to find a student that matches',1);
11467: next;
11468: }
11469: if (exists $completedstudents{$uname}) {
11470: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
11471: 'Student '.$uname.' has multiple sheets',2);
11472: next;
11473: }
11474: my $pid = $scan_record->{'scantron.ID'};
11475: $lastname{$pid} = $scan_record->{'scantron.LastName'};
11476: push(@{$bylast{$lastname{$pid}}},$pid);
1.678 raeburn 11477: my $usec = $classlist->{$uname}->[&Apache::loncoursedata::CL_SECTION];
11478: my $user = $uname.':'.$usec;
1.523 raeburn 11479: ($username,$domain)=split(/:/,$uname);
1.677 raeburn 11480:
1.678 raeburn 11481: my $scancode;
1.677 raeburn 11482: if ((exists($scan_record->{'scantron.CODE'})) &&
11483: (&Apache::lonnet::validCODE($scan_record->{'scantron.CODE'}))) {
11484: $scancode = $scan_record->{'scantron.CODE'};
11485: } else {
11486: $scancode = '';
11487: }
11488:
11489: my @mapresources = @resources;
1.691 raeburn 11490: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
11491: my %respnumlookup=();
11492: my %startline=();
1.689 raeburn 11493: if ($randomorder || $randompick) {
1.678 raeburn 11494: @mapresources =
1.691 raeburn 11495: &users_order($user,$scancode,$sequence,\@master_seq,\%symb_to_resource,
11496: \%orderedforcode);
11497: my $total = &get_respnum_lookups($sequence,$scan_data,\%idmap,$line,
11498: $scan_record,\@master_seq,\%symb_to_resource,
11499: \%grader_partids_by_symb,\%orderedforcode,
11500: \%respnumlookup,\%startline);
11501: if ($randompick && $total) {
11502: $lastpos = $total*$scantron_config{'Qlength'};
11503: }
1.677 raeburn 11504: }
1.691 raeburn 11505: $scandata{$pid} = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
11506: chomp($scandata{$pid});
11507: $scandata{$pid} =~ s/\r$//;
11508:
1.523 raeburn 11509: my $counter = -1;
1.677 raeburn 11510: foreach my $resource (@mapresources) {
1.557 raeburn 11511: my $parts;
1.554 raeburn 11512: my $ressymb = $resource->symb();
1.557 raeburn 11513: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
11514: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
1.741 raeburn 11515: my $currcode;
11516: if (exists($grader_randomlists_by_symb{$ressymb})) {
11517: $currcode = $scancode;
11518: }
1.557 raeburn 11519: (my $analysis,$parts) =
1.672 raeburn 11520: &scantron_partids_tograde($resource,$env{'request.course.id'},
11521: $username,$domain,undef,
1.741 raeburn 11522: $bubbles_per_row,$currcode);
1.557 raeburn 11523: } else {
11524: $parts = $grader_partids_by_symb{$ressymb};
11525: }
1.542 raeburn 11526: ($counter,my $recording) =
11527: &verify_scantron_grading($resource,$domain,$username,$cid,$counter,
1.554 raeburn 11528: $scandata{$pid},$parts,
1.691 raeburn 11529: \%scantron_config,\%lettdig,$numletts,
11530: $randomorder,$randompick,
11531: \%respnumlookup,\%startline);
1.542 raeburn 11532: $record{$pid} .= $recording;
1.523 raeburn 11533: }
11534: }
11535: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
11536: $r->print('<br />');
11537: my ($okstudents,$badstudents,$numstudents,$passed,$failed);
11538: $passed = 0;
11539: $failed = 0;
11540: $numstudents = 0;
11541: foreach my $last (sort(keys(%bylast))) {
11542: if (ref($bylast{$last}) eq 'ARRAY') {
11543: foreach my $pid (sort(@{$bylast{$last}})) {
11544: my $showscandata = $scandata{$pid};
11545: my $showrecord = $record{$pid};
11546: $showscandata =~ s/\s/ /g;
11547: $showrecord =~ s/\s/ /g;
11548: if ($scandata{$pid} eq $record{$pid}) {
11549: my $css_class = ($passed % 2)?'LC_odd_row':'LC_even_row';
11550: $okstudents .= '<tr class="'.$css_class.'">'.
1.581 www 11551: '<td>'.&mt('Bubblesheet').'</td><td>'.$showscandata.'</td><td rowspan="2">'.$last.'</td><td rowspan="2">'.$pid.'</td>'."\n".
1.523 raeburn 11552: '</tr>'."\n".
11553: '<tr class="'.$css_class.'">'."\n".
1.721 bisitz 11554: '<td>'.&mt('Submissions').'</td><td>'.$showrecord.'</td></tr>'."\n";
1.523 raeburn 11555: $passed ++;
11556: } else {
11557: my $css_class = ($failed % 2)?'LC_odd_row':'LC_even_row';
1.581 www 11558: $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 11559: '</tr>'."\n".
11560: '<tr class="'.$css_class.'">'."\n".
1.721 bisitz 11561: '<td>'.&mt('Submissions').'</td><td><span class="LC_nobreak">'.$record{$pid}.'</span></td>'."\n".
1.523 raeburn 11562: '</tr>'."\n";
11563: $failed ++;
11564: }
11565: $numstudents ++;
11566: }
11567: }
11568: }
1.648 bisitz 11569: $r->print(
11570: '<p>'
11571: .&mt('Comparison of bubblesheet data (including corrections) with corresponding submission records (most recent submission) for [_1][quant,_2,student][_3] ([quant,_4,bubblesheet line] per student).',
11572: '<b>',
11573: $numstudents,
11574: '</b>',
11575: $env{'form.scantron_maxbubble'})
11576: .'</p>'
11577: );
1.682 raeburn 11578: $r->print('<p>'
1.683 raeburn 11579: .&mt('Exact matches for [_1][quant,_2,student][_3].','<b>',$passed,'</b>')
1.682 raeburn 11580: .'<br />'
11581: .&mt('Discrepancies detected for [_1][quant,_2,student][_3].','<b>',$failed,'</b>')
11582: .'</p>'
11583: );
1.523 raeburn 11584: if ($passed) {
1.572 www 11585: $r->print(&mt('Students with exact correspondence between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 11586: $r->print(&Apache::loncommon::start_data_table()."\n".
11587: &Apache::loncommon::start_data_table_header_row()."\n".
11588: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
11589: &Apache::loncommon::end_data_table_header_row()."\n".
11590: $okstudents."\n".
11591: &Apache::loncommon::end_data_table().'<br />');
11592: }
11593: if ($failed) {
1.572 www 11594: $r->print(&mt('Students with differences between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 11595: $r->print(&Apache::loncommon::start_data_table()."\n".
11596: &Apache::loncommon::start_data_table_header_row()."\n".
11597: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
11598: &Apache::loncommon::end_data_table_header_row()."\n".
11599: $badstudents."\n".
11600: &Apache::loncommon::end_data_table()).'<br />'.
1.572 www 11601: &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 11602: }
1.614 www 11603: $r->print('</form><br />');
1.523 raeburn 11604: return;
11605: }
11606:
1.542 raeburn 11607: sub verify_scantron_grading {
1.554 raeburn 11608: my ($resource,$domain,$username,$cid,$counter,$scandata,$partids,
1.691 raeburn 11609: $scantron_config,$lettdig,$numletts,$randomorder,$randompick,
11610: $respnumlookup,$startline) = @_;
1.542 raeburn 11611: my ($record,%expected,%startpos);
11612: return ($counter,$record) if (!ref($resource));
11613: return ($counter,$record) if (!$resource->is_problem());
11614: my $symb = $resource->symb();
1.554 raeburn 11615: return ($counter,$record) if (ref($partids) ne 'ARRAY');
11616: foreach my $part_id (@{$partids}) {
1.542 raeburn 11617: $counter ++;
11618: $expected{$part_id} = 0;
1.691 raeburn 11619: my $respnum = $counter;
11620: if ($randomorder || $randompick) {
11621: $respnum = $respnumlookup->{$counter};
11622: $startpos{$part_id} = $startline->{$counter} + 1;
11623: } else {
11624: $startpos{$part_id} = $env{"form.scantron.first_bubble_line.$counter"};
11625: }
11626: if ($env{"form.scantron.sub_bubblelines.$respnum"}) {
11627: my @sub_lines = split(/,/,$env{"form.scantron.sub_bubblelines.$respnum"});
1.542 raeburn 11628: foreach my $item (@sub_lines) {
11629: $expected{$part_id} += $item;
11630: }
11631: } else {
1.691 raeburn 11632: $expected{$part_id} = $env{"form.scantron.bubblelines.$respnum"};
1.542 raeburn 11633: }
11634: }
11635: if ($symb) {
11636: my %recorded;
11637: my (%returnhash) = &Apache::lonnet::restore($symb,$cid,$domain,$username);
11638: if ($returnhash{'version'}) {
11639: my %lasthash=();
11640: my $version;
11641: for ($version=1;$version<=$returnhash{'version'};$version++) {
11642: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
11643: $lasthash{$key}=$returnhash{$version.':'.$key};
11644: }
11645: }
11646: foreach my $key (keys(%lasthash)) {
11647: if ($key =~ /\.scantron$/) {
11648: my $value = &unescape($lasthash{$key});
11649: my ($part_id) = ($key =~ /^resource\.(.+)\.scantron$/);
11650: if ($value eq '') {
11651: for (my $i=0; $i<$expected{$part_id}; $i++) {
11652: for (my $j=0; $j<$scantron_config->{'length'}; $j++) {
11653: $recorded{$part_id} .= $scantron_config->{'Qoff'};
11654: }
11655: }
11656: } else {
11657: my @tocheck;
11658: my @items = split(//,$value);
11659: if (($scantron_config->{'Qon'} eq 'letter') ||
11660: ($scantron_config->{'Qon'} eq 'number')) {
11661: if (@items < $expected{$part_id}) {
11662: my $fragment = substr($scandata,$startpos{$part_id},$expected{$part_id});
11663: my @singles = split(//,$fragment);
11664: foreach my $pos (@singles) {
11665: if ($pos eq ' ') {
11666: push(@tocheck,$pos);
11667: } else {
11668: my $next = shift(@items);
11669: push(@tocheck,$next);
11670: }
11671: }
11672: } else {
11673: @tocheck = @items;
11674: }
11675: foreach my $letter (@tocheck) {
11676: if ($scantron_config->{'Qon'} eq 'letter') {
11677: if ($letter !~ /^[A-J]$/) {
11678: $letter = $scantron_config->{'Qoff'};
11679: }
11680: $recorded{$part_id} .= $letter;
11681: } elsif ($scantron_config->{'Qon'} eq 'number') {
11682: my $digit;
11683: if ($letter !~ /^[A-J]$/) {
11684: $digit = $scantron_config->{'Qoff'};
11685: } else {
11686: $digit = $lettdig->{$letter};
11687: }
11688: $recorded{$part_id} .= $digit;
11689: }
11690: }
11691: } else {
11692: @tocheck = @items;
11693: for (my $i=0; $i<$expected{$part_id}; $i++) {
11694: my $curr_sub = shift(@tocheck);
11695: my $digit;
11696: if ($curr_sub =~ /^[A-J]$/) {
11697: $digit = $lettdig->{$curr_sub}-1;
11698: }
11699: if ($curr_sub eq 'J') {
11700: $digit += scalar($numletts);
11701: }
11702: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
11703: if ($j == $digit) {
11704: $recorded{$part_id} .= $scantron_config->{'Qon'};
11705: } else {
11706: $recorded{$part_id} .= $scantron_config->{'Qoff'};
11707: }
11708: }
11709: }
11710: }
11711: }
11712: }
11713: }
11714: }
1.554 raeburn 11715: foreach my $part_id (@{$partids}) {
1.542 raeburn 11716: if ($recorded{$part_id} eq '') {
11717: for (my $i=0; $i<$expected{$part_id}; $i++) {
11718: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
11719: $recorded{$part_id} .= $scantron_config->{'Qoff'};
11720: }
11721: }
11722: }
11723: $record .= $recorded{$part_id};
11724: }
11725: }
11726: return ($counter,$record);
11727: }
11728:
1.75 albertel 11729: #-------- end of section for handling grading scantron forms -------
11730: #
11731: #-------------------------------------------------------------------
11732:
1.72 ng 11733: #-------------------------- Menu interface -------------------------
11734: #
1.614 www 11735: #--- Href with symb and command ---
11736:
11737: sub href_symb_cmd {
11738: my ($symb,$cmd)=@_;
1.796 raeburn 11739: return '/adm/grades?symb='.&HTML::Entities::encode(&Apache::lonenc::check_encrypt($symb),'<>&"').'&command='.
11740: &HTML::Entities::encode($cmd,'<>&"');
1.72 ng 11741: }
11742:
1.443 banghart 11743: sub grading_menu {
1.608 www 11744: my ($request,$symb) = @_;
1.443 banghart 11745: if (!$symb) {return '';}
11746:
11747: my %fields = ('symb'=>&Apache::lonenc::check_encrypt($symb),
1.618 www 11748: 'command'=>'individual');
1.538 schulted 11749:
1.598 www 11750: my $url1a = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
11751:
11752: $fields{'command'}='ungraded';
11753: my $url1b=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
11754:
11755: $fields{'command'}='table';
11756: my $url1c=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
11757:
11758: $fields{'command'}='all_for_one';
11759: my $url1d=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
11760:
1.621 www 11761: $fields{'command'}='downloadfilesselect';
11762: my $url1e=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
11763:
1.443 banghart 11764: $fields{'command'} = 'csvform';
1.538 schulted 11765: my $url2 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
11766:
1.443 banghart 11767: $fields{'command'} = 'processclicker';
1.538 schulted 11768: my $url3 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
11769:
1.443 banghart 11770: $fields{'command'} = 'scantron_selectphase';
1.538 schulted 11771: my $url4 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
1.602 www 11772:
11773: $fields{'command'} = 'initialverifyreceipt';
11774: my $url5 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
1.780 raeburn 11775:
11776: my %permissions;
11777: if ($perm{'mgr'}) {
11778: $permissions{'either'} = 'F';
11779: $permissions{'mgr'} = 'F';
11780: }
11781: if ($perm{'vgr'}) {
11782: $permissions{'either'} = 'F';
11783: $permissions{'vgr'} = 'F';
11784: }
11785:
1.598 www 11786: my @menu = ({ categorytitle=>'Hand Grading',
1.538 schulted 11787: items =>[
1.598 www 11788: { linktext => 'Select individual students to grade',
11789: url => $url1a,
1.781 raeburn 11790: permission => $permissions{'either'},
1.636 wenzelju 11791: icon => 'grade_students.png',
1.598 www 11792: linktitle => 'Grade current resource for a selection of students.'
11793: },
1.764 raeburn 11794: { linktext => 'Grade ungraded submissions',
1.598 www 11795: url => $url1b,
1.781 raeburn 11796: permission => $permissions{'either'},
1.636 wenzelju 11797: icon => 'ungrade_sub.png',
1.598 www 11798: linktitle => 'Grade all submissions that have not been graded yet.'
1.538 schulted 11799: },
1.598 www 11800:
11801: { linktext => 'Grading table',
11802: url => $url1c,
1.781 raeburn 11803: permission => $permissions{'either'},
1.636 wenzelju 11804: icon => 'grading_table.png',
1.598 www 11805: linktitle => 'Grade current resource for all students.'
11806: },
1.615 www 11807: { linktext => 'Grade page/folder for one student',
1.598 www 11808: url => $url1d,
1.781 raeburn 11809: permission => $permissions{'either'},
1.636 wenzelju 11810: icon => 'grade_PageFolder.png',
1.598 www 11811: linktitle => 'Grade all resources in current page/sequence/folder for one student.'
1.621 www 11812: },
11813: { linktext => 'Download submissions',
11814: url => $url1e,
1.781 raeburn 11815: permission => $permissions{'either'},
1.636 wenzelju 11816: icon => 'download_sub.png',
1.621 www 11817: linktitle => 'Download all students submissions.'
1.598 www 11818: }]},
11819: { categorytitle=>'Automated Grading',
11820: items =>[
11821:
1.538 schulted 11822: { linktext => 'Upload Scores',
11823: url => $url2,
1.780 raeburn 11824: permission => $permissions{'mgr'},
1.538 schulted 11825: icon => 'uploadscores.png',
11826: linktitle => 'Specify a file containing the class scores for current resource.'
11827: },
11828: { linktext => 'Process Clicker',
11829: url => $url3,
1.780 raeburn 11830: permission => $permissions{'mgr'},
1.538 schulted 11831: icon => 'addClickerInfoFile.png',
11832: linktitle => 'Specify a file containing the clicker information for this resource.'
11833: },
1.587 raeburn 11834: { linktext => 'Grade/Manage/Review Bubblesheets',
1.538 schulted 11835: url => $url4,
1.780 raeburn 11836: permission => $permissions{'mgr'},
1.636 wenzelju 11837: icon => 'bubblesheet.png',
1.648 bisitz 11838: linktitle => 'Grade bubblesheet exams, upload/download bubblesheet data files, and review previously graded bubblesheet exams.'
1.602 www 11839: },
1.616 www 11840: { linktext => 'Verify Receipt Number',
1.602 www 11841: url => $url5,
1.780 raeburn 11842: permission => $permissions{'either'},
1.636 wenzelju 11843: icon => 'receipt_number.png',
1.602 www 11844: linktitle => 'Verify a system-generated receipt number for correct problem solution.'
11845: }
11846:
1.538 schulted 11847: ]
11848: });
1.796 raeburn 11849: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
11850: my $cnum = $env{"course.$env{'request.course.id'}.num"};
11851: my %passback = &Apache::lonnet::dump('nohist_linkprot_passback',$cdom,$cnum);
11852: if (keys(%passback)) {
11853: $fields{'command'} = 'initialpassback';
11854: my $url6 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
11855: push (@{$menu[1]{items}},
11856: { linktext => 'Passback of Scores',
11857: url => $url6,
11858: permission => $permissions{'either'},
11859: icon => 'passback.png',
11860: linktitle => 'Passback scores to launcher CMS for resources accessed via LTI-mediated deep-linking',
11861: });
11862: }
1.443 banghart 11863: # Create the menu
11864: my $Str;
1.445 banghart 11865: $Str .= '<form method="post" action="" name="gradingMenu">';
11866: $Str .= '<input type="hidden" name="command" value="" />'.
1.618 www 11867: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.445 banghart 11868:
1.602 www 11869: $Str .= &Apache::lonhtmlcommon::generate_menu(@menu);
1.443 banghart 11870: return $Str;
11871: }
11872:
1.598 www 11873: sub ungraded {
11874: my ($request)=@_;
11875: &submit_options($request);
11876: }
11877:
1.599 www 11878: sub submit_options_sequence {
1.608 www 11879: my ($request,$symb) = @_;
1.599 www 11880: if (!$symb) {return '';}
1.600 www 11881: &commonJSfunctions($request);
11882: my $result;
1.599 www 11883:
1.600 www 11884: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.618 www 11885: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.632 www 11886: $result.=&selectfield(0).
1.601 www 11887: '<input type="hidden" name="command" value="pickStudentPage" />
1.600 www 11888: <div>
11889: <input type="submit" value="'.&mt('Next').' →" />
11890: </div>
11891: </div>
11892: </form>';
11893: return $result;
11894: }
11895:
11896: sub submit_options_table {
1.608 www 11897: my ($request,$symb) = @_;
1.600 www 11898: if (!$symb) {return '';}
1.599 www 11899: &commonJSfunctions($request);
1.746 raeburn 11900: my $is_tool = ($symb =~ /ext\.tool$/);
1.599 www 11901: my $result;
11902:
11903: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.618 www 11904: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.599 www 11905:
1.745 raeburn 11906: $result.=&selectfield(1,$is_tool).
1.601 www 11907: '<input type="hidden" name="command" value="viewgrades" />
1.599 www 11908: <div>
11909: <input type="submit" value="'.&mt('Next').' →" />
11910: </div>
11911: </div>
11912: </form>';
11913: return $result;
11914: }
1.443 banghart 11915:
1.621 www 11916: sub submit_options_download {
11917: my ($request,$symb) = @_;
11918: if (!$symb) {return '';}
11919:
1.773 raeburn 11920: my $res_error;
11921: my ($partlist,$handgrade,$responseType,$numresp,$numessay,$numdropbox) =
11922: &response_type($symb,\$res_error);
11923: if ($res_error) {
11924: $request->print(&mt('An error occurred retrieving response types'));
11925: return;
11926: }
11927: unless ($numessay) {
11928: $request->print(&mt('No essayresponse items found'));
11929: return;
11930: }
11931: my $table;
11932: if (ref($partlist) eq 'ARRAY') {
11933: if (scalar(@$partlist) > 1 ) {
11934: $table = &showResourceInfo($symb,$partlist,$responseType,'gradingMenu',1,1);
11935: }
11936: }
11937:
1.746 raeburn 11938: my $is_tool = ($symb =~ /ext\.tool$/);
1.621 www 11939: &commonJSfunctions($request);
11940:
11941: my $result='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.773 raeburn 11942: $table."\n".
11943: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.621 www 11944: $result.='
11945: <h2>
1.750 raeburn 11946: '.&mt('Select Students for whom to Download Submissions').'
1.745 raeburn 11947: </h2>'.&selectfield(1,$is_tool).'
1.621 www 11948: <input type="hidden" name="command" value="downloadfileslink" />
11949: <input type="submit" value="'.&mt('Next').' →" />
11950: </div>
11951: </div>
1.600 www 11952:
11953:
1.621 www 11954: </form>';
11955: return $result;
11956: }
11957:
1.443 banghart 11958: #--- Displays the submissions first page -------
11959: sub submit_options {
1.608 www 11960: my ($request,$symb) = @_;
1.72 ng 11961: if (!$symb) {return '';}
11962:
1.746 raeburn 11963: my $is_tool = ($symb =~ /ext\.tool$/);
1.118 ng 11964: &commonJSfunctions($request);
1.473 albertel 11965: my $result;
1.533 bisitz 11966:
1.72 ng 11967: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.618 www 11968: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.745 raeburn 11969: $result.=&selectfield(1,$is_tool).'
1.601 www 11970: <input type="hidden" name="command" value="submission" />
11971: <input type="submit" value="'.&mt('Next').' →" />
11972: </div>
11973: </div>
11974: </form>';
11975: return $result;
11976: }
1.533 bisitz 11977:
1.601 www 11978: sub selectfield {
1.745 raeburn 11979: my ($full,$is_tool)=@_;
11980: my %options;
11981: if ($is_tool) {
11982: %options =
11983: (&transtatus_options,
11984: 'select_form_order' => ['yes','incorrect','all']);
11985: } else {
11986: %options =
11987: (&substatus_options,
11988: 'select_form_order' => ['yes','queued','graded','incorrect','all']);
11989: }
1.782 raeburn 11990:
11991: #
11992: # PrepareClasslist() needs to be called to avoid getting a sections list
11993: # for a different course from the @Sections global in lonstatistics.pm,
11994: # populated by an earlier request.
11995: #
11996: &Apache::lonstatistics::PrepareClasslist();
11997:
1.601 www 11998: my $result='<div class="LC_columnSection">
1.537 harmsja 11999:
1.533 bisitz 12000: <fieldset>
12001: <legend>
12002: '.&mt('Sections').'
12003: </legend>
1.601 www 12004: '.&Apache::lonstatistics::SectionSelect('section','multiple',5).'
1.533 bisitz 12005: </fieldset>
1.537 harmsja 12006:
1.533 bisitz 12007: <fieldset>
12008: <legend>
12009: '.&mt('Groups').'
12010: </legend>
12011: '.&Apache::lonstatistics::GroupSelect('group','multiple',5).'
12012: </fieldset>
1.537 harmsja 12013:
1.533 bisitz 12014: <fieldset>
12015: <legend>
12016: '.&mt('Access Status').'
12017: </legend>
1.601 www 12018: '.&Apache::lonhtmlcommon::StatusOptions(undef,undef,5,undef,'mult').'
12019: </fieldset>';
12020: if ($full) {
1.745 raeburn 12021: my $heading = &mt('Submission Status');
12022: if ($is_tool) {
12023: $heading = &mt('Transaction Status');
12024: }
12025: $result.='
1.533 bisitz 12026: <fieldset>
12027: <legend>
1.745 raeburn 12028: '.$heading.'
1.601 www 12029: </legend>'.
1.635 raeburn 12030: &Apache::loncommon::select_form('all','submitonly',\%options).
1.601 www 12031: '</fieldset>';
12032: }
12033: $result.='</div><br />';
1.44 ng 12034: return $result;
1.2 albertel 12035: }
12036:
1.738 raeburn 12037: sub substatus_options {
12038: return &Apache::lonlocal::texthash(
12039: 'yes' => 'with submissions',
12040: 'queued' => 'in grading queue',
12041: 'graded' => 'with ungraded submissions',
12042: 'incorrect' => 'with incorrect submissions',
1.740 raeburn 12043: 'all' => 'with any status',
12044: );
1.738 raeburn 12045: }
12046:
1.745 raeburn 12047: sub transtatus_options {
12048: return &Apache::lonlocal::texthash(
12049: 'yes' => 'with score transactions',
12050: 'incorrect' => 'with less than full credit',
12051: 'all' => 'with any status',
12052: );
12053: }
12054:
1.285 albertel 12055: sub reset_perm {
12056: undef(%perm);
12057: }
12058:
12059: sub init_perm {
12060: &reset_perm();
1.770 raeburn 12061: foreach my $test_perm ('vgr','mgr','opa','usc') {
1.300 albertel 12062:
12063: my $scope = $env{'request.course.id'};
12064: if (!($perm{$test_perm}=&Apache::lonnet::allowed($test_perm,$scope))) {
12065:
12066: $scope .= '/'.$env{'request.course.sec'};
12067: if ( $perm{$test_perm}=
12068: &Apache::lonnet::allowed($test_perm,$scope)) {
12069: $perm{$test_perm.'_section'}=$env{'request.course.sec'};
12070: } else {
12071: delete($perm{$test_perm});
12072: }
1.285 albertel 12073: }
12074: }
12075: }
12076:
1.674 raeburn 12077: sub init_old_essays {
12078: my ($symb,$apath,$adom,$aname) = @_;
12079: if ($symb ne '') {
12080: my %essays = &Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
12081: if (keys(%essays) > 0) {
12082: $old_essays{$symb} = \%essays;
12083: }
12084: }
12085: return;
12086: }
12087:
12088: sub reset_old_essays {
12089: undef(%old_essays);
12090: }
12091:
1.400 www 12092: sub gather_clicker_ids {
1.408 albertel 12093: my %clicker_ids;
1.400 www 12094:
12095: my $classlist = &Apache::loncoursedata::get_classlist();
12096:
12097: # Set up a couple variables.
1.407 albertel 12098: my $username_idx = &Apache::loncoursedata::CL_SNAME();
12099: my $domain_idx = &Apache::loncoursedata::CL_SDOM();
1.438 www 12100: my $status_idx = &Apache::loncoursedata::CL_STATUS();
1.400 www 12101:
1.407 albertel 12102: foreach my $student (keys(%$classlist)) {
1.438 www 12103: if ($classlist->{$student}->[$status_idx] ne 'Active') { next; }
1.407 albertel 12104: my $username = $classlist->{$student}->[$username_idx];
12105: my $domain = $classlist->{$student}->[$domain_idx];
1.400 www 12106: my $clickers =
1.408 albertel 12107: (&Apache::lonnet::userenvironment($domain,$username,'clickers'))[1];
1.400 www 12108: foreach my $id (split(/\,/,$clickers)) {
1.414 www 12109: $id=~s/^[\#0]+//;
1.421 www 12110: $id=~s/[\-\:]//g;
1.407 albertel 12111: if (exists($clicker_ids{$id})) {
1.408 albertel 12112: $clicker_ids{$id}.=','.$username.':'.$domain;
1.400 www 12113: } else {
1.408 albertel 12114: $clicker_ids{$id}=$username.':'.$domain;
1.400 www 12115: }
12116: }
12117: }
1.407 albertel 12118: return %clicker_ids;
1.400 www 12119: }
12120:
1.402 www 12121: sub gather_adv_clicker_ids {
1.408 albertel 12122: my %clicker_ids;
1.402 www 12123: my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'};
12124: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
12125: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
1.409 albertel 12126: foreach my $element (sort(keys(%coursepersonnel))) {
1.402 www 12127: foreach my $person (split(/\,/,$coursepersonnel{$element})) {
12128: my ($puname,$pudom)=split(/\:/,$person);
12129: my $clickers =
1.408 albertel 12130: (&Apache::lonnet::userenvironment($pudom,$puname,'clickers'))[1];
1.405 www 12131: foreach my $id (split(/\,/,$clickers)) {
1.414 www 12132: $id=~s/^[\#0]+//;
1.421 www 12133: $id=~s/[\-\:]//g;
1.408 albertel 12134: if (exists($clicker_ids{$id})) {
12135: $clicker_ids{$id}.=','.$puname.':'.$pudom;
12136: } else {
12137: $clicker_ids{$id}=$puname.':'.$pudom;
12138: }
1.405 www 12139: }
1.402 www 12140: }
12141: }
1.407 albertel 12142: return %clicker_ids;
1.402 www 12143: }
12144:
1.413 www 12145: sub clicker_grading_parameters {
12146: return ('gradingmechanism' => 'scalar',
12147: 'upfiletype' => 'scalar',
12148: 'specificid' => 'scalar',
12149: 'pcorrect' => 'scalar',
12150: 'pincorrect' => 'scalar');
12151: }
12152:
1.400 www 12153: sub process_clicker {
1.608 www 12154: my ($r,$symb)=@_;
1.400 www 12155: if (!$symb) {return '';}
12156: my $result=&checkforfile_js();
1.632 www 12157: $result.=&Apache::loncommon::start_data_table().
12158: &Apache::loncommon::start_data_table_header_row().
12159: '<th>'.&mt('Specify a file containing clicker information and set grading options.').'</th>'.
12160: &Apache::loncommon::end_data_table_header_row().
12161: &Apache::loncommon::start_data_table_row()."<td>\n";
1.413 www 12162: # Attempt to restore parameters from last session, set defaults if not present
12163: my %Saveable_Parameters=&clicker_grading_parameters();
12164: &Apache::loncommon::restore_course_settings('grades_clicker',
12165: \%Saveable_Parameters);
12166: if (!$env{'form.pcorrect'}) { $env{'form.pcorrect'}=100; }
12167: if (!$env{'form.pincorrect'}) { $env{'form.pincorrect'}=100; }
12168: if (!$env{'form.gradingmechanism'}) { $env{'form.gradingmechanism'}='attendance'; }
12169: if (!$env{'form.upfiletype'}) { $env{'form.upfiletype'}='iclicker'; }
12170:
12171: my %checked;
1.521 www 12172: foreach my $gradingmechanism ('attendance','personnel','specific','given') {
1.413 www 12173: if ($env{'form.gradingmechanism'} eq $gradingmechanism) {
1.569 bisitz 12174: $checked{$gradingmechanism}=' checked="checked"';
1.413 www 12175: }
12176: }
12177:
1.632 www 12178: my $upload=&mt("Evaluate File");
1.400 www 12179: my $type=&mt("Type");
1.402 www 12180: my $attendance=&mt("Award points just for participation");
12181: my $personnel=&mt("Correctness determined from response by course personnel");
1.414 www 12182: my $specific=&mt("Correctness determined from response with clicker ID(s)");
1.521 www 12183: my $given=&mt("Correctness determined from given list of answers").' '.
12184: '<font size="-2"><tt>('.&mt("Provide comma-separated list. Use '*' for any answer correct, '-' for skip").')</tt></font>';
1.402 www 12185: my $pcorrect=&mt("Percentage points for correct solution");
12186: my $pincorrect=&mt("Percentage points for incorrect solution");
1.413 www 12187: my $selectform=&Apache::loncommon::select_form($env{'form.upfiletype'},'upfiletype',
1.635 raeburn 12188: {'iclicker' => 'i>clicker',
1.666 www 12189: 'interwrite' => 'interwrite PRS',
12190: 'turning' => 'Turning Technologies'});
1.418 albertel 12191: $symb = &Apache::lonenc::check_encrypt($symb);
1.597 wenzelju 12192: $result.= &Apache::lonhtmlcommon::scripttag(<<ENDUPFORM);
1.402 www 12193: function sanitycheck() {
12194: // Accept only integer percentages
12195: document.forms.gradesupload.pcorrect.value=Math.round(document.forms.gradesupload.pcorrect.value);
12196: document.forms.gradesupload.pincorrect.value=Math.round(document.forms.gradesupload.pincorrect.value);
12197: // Find out grading choice
12198: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
12199: if (document.forms.gradesupload.gradingmechanism[i].checked) {
12200: gradingchoice=document.forms.gradesupload.gradingmechanism[i].value;
12201: }
12202: }
12203: // By default, new choice equals user selection
12204: newgradingchoice=gradingchoice;
12205: // Not good to give more points for false answers than correct ones
12206: if (Math.round(document.forms.gradesupload.pcorrect.value)<Math.round(document.forms.gradesupload.pincorrect.value)) {
12207: document.forms.gradesupload.pcorrect.value=document.forms.gradesupload.pincorrect.value;
12208: }
12209: // If new choice is attendance only, and old choice was correctness-based, restore defaults
12210: if ((gradingchoice=='attendance') && (document.forms.gradesupload.waschecked.value!='attendance')) {
12211: document.forms.gradesupload.pcorrect.value=100;
12212: document.forms.gradesupload.pincorrect.value=100;
12213: }
12214: // If the values are different, cannot be attendance only
12215: if ((Math.round(document.forms.gradesupload.pcorrect.value)!=Math.round(document.forms.gradesupload.pincorrect.value)) &&
12216: (gradingchoice=='attendance')) {
12217: newgradingchoice='personnel';
12218: }
12219: // Change grading choice to new one
12220: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
12221: if (document.forms.gradesupload.gradingmechanism[i].value==newgradingchoice) {
12222: document.forms.gradesupload.gradingmechanism[i].checked=true;
12223: } else {
12224: document.forms.gradesupload.gradingmechanism[i].checked=false;
12225: }
12226: }
12227: // Remember the old state
12228: document.forms.gradesupload.waschecked.value=newgradingchoice;
12229: }
1.597 wenzelju 12230: ENDUPFORM
12231: $result.= <<ENDUPFORM;
1.400 www 12232: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
12233: <input type="hidden" name="symb" value="$symb" />
12234: <input type="hidden" name="command" value="processclickerfile" />
12235: <input type="file" name="upfile" size="50" />
12236: <br /><label>$type: $selectform</label>
1.632 www 12237: ENDUPFORM
12238: $result.='</td>'.&Apache::loncommon::end_data_table_row().
12239: &Apache::loncommon::start_data_table_row().'<td>'.(<<ENDGRADINGFORM);
12240: <label><input type="radio" name="gradingmechanism" value="attendance"$checked{'attendance'} onclick="sanitycheck()" />$attendance </label>
1.589 bisitz 12241: <br /><label><input type="radio" name="gradingmechanism" value="personnel"$checked{'personnel'} onclick="sanitycheck()" />$personnel</label>
12242: <br /><label><input type="radio" name="gradingmechanism" value="specific"$checked{'specific'} onclick="sanitycheck()" />$specific </label>
1.414 www 12243: <input type="text" name="specificid" value="$env{'form.specificid'}" size="20" />
1.589 bisitz 12244: <br /><label><input type="radio" name="gradingmechanism" value="given"$checked{'given'} onclick="sanitycheck()" />$given </label>
1.521 www 12245: <br />
12246: <input type="text" name="givenanswer" size="50" />
1.413 www 12247: <input type="hidden" name="waschecked" value="$env{'form.gradingmechanism'}" />
1.632 www 12248: ENDGRADINGFORM
1.766 raeburn 12249: $result.='</td>'.&Apache::loncommon::end_data_table_row().
1.632 www 12250: &Apache::loncommon::start_data_table_row().'<td>'.(<<ENDPERCFORM);
12251: <label>$pcorrect: <input type="text" name="pcorrect" size="4" value="$env{'form.pcorrect'}" onchange="sanitycheck()" /></label>
1.589 bisitz 12252: <br /><label>$pincorrect: <input type="text" name="pincorrect" size="4" value="$env{'form.pincorrect'}" onchange="sanitycheck()" /></label>
12253: <br /><input type="button" onclick="javascript:checkUpload(this.form);" value="$upload" />
1.767 raeburn 12254: </form>
1.632 www 12255: ENDPERCFORM
12256: $result.='</td>'.
12257: &Apache::loncommon::end_data_table_row().
12258: &Apache::loncommon::end_data_table();
1.400 www 12259: return $result;
12260: }
12261:
12262: sub process_clicker_file {
1.766 raeburn 12263: my ($r,$symb) = @_;
1.400 www 12264: if (!$symb) {return '';}
1.413 www 12265:
12266: my %Saveable_Parameters=&clicker_grading_parameters();
12267: &Apache::loncommon::store_course_settings('grades_clicker',
12268: \%Saveable_Parameters);
1.598 www 12269: my $result='';
1.404 www 12270: if (($env{'form.gradingmechanism'} eq 'specific') && ($env{'form.specificid'}!~/\w/)) {
1.408 albertel 12271: $result.='<span class="LC_error">'.&mt('You need to specify a clicker ID for the correct answer').'</span>';
1.614 www 12272: return $result;
1.404 www 12273: }
1.522 www 12274: if (($env{'form.gradingmechanism'} eq 'given') && ($env{'form.givenanswer'}!~/\S/)) {
1.521 www 12275: $result.='<span class="LC_error">'.&mt('You need to specify the correct answer').'</span>';
1.614 www 12276: return $result;
1.521 www 12277: }
1.522 www 12278: my $foundgiven=0;
1.521 www 12279: if ($env{'form.gradingmechanism'} eq 'given') {
12280: $env{'form.givenanswer'}=~s/^\s*//gs;
12281: $env{'form.givenanswer'}=~s/\s*$//gs;
1.644 www 12282: $env{'form.givenanswer'}=~s/[^a-zA-Z0-9\.\*\-\+]+/\,/g;
1.521 www 12283: $env{'form.givenanswer'}=uc($env{'form.givenanswer'});
1.522 www 12284: my @answers=split(/\,/,$env{'form.givenanswer'});
12285: $foundgiven=$#answers+1;
1.521 www 12286: }
1.407 albertel 12287: my %clicker_ids=&gather_clicker_ids();
1.408 albertel 12288: my %correct_ids;
1.404 www 12289: if ($env{'form.gradingmechanism'} eq 'personnel') {
1.408 albertel 12290: %correct_ids=&gather_adv_clicker_ids();
1.404 www 12291: }
12292: if ($env{'form.gradingmechanism'} eq 'specific') {
1.414 www 12293: foreach my $correct_id (split(/[\s\,]/,$env{'form.specificid'})) {;
12294: $correct_id=~tr/a-z/A-Z/;
12295: $correct_id=~s/\s//gs;
12296: $correct_id=~s/^[\#0]+//;
1.421 www 12297: $correct_id=~s/[\-\:]//g;
1.414 www 12298: if ($correct_id) {
12299: $correct_ids{$correct_id}='specified';
12300: }
12301: }
1.400 www 12302: }
1.404 www 12303: if ($env{'form.gradingmechanism'} eq 'attendance') {
1.408 albertel 12304: $result.=&mt('Score based on attendance only');
1.521 www 12305: } elsif ($env{'form.gradingmechanism'} eq 'given') {
1.522 www 12306: $result.=&mt('Score based on [_1] ([_2] answers)','<tt>'.$env{'form.givenanswer'}.'</tt>',$foundgiven);
1.404 www 12307: } else {
1.408 albertel 12308: my $number=0;
1.411 www 12309: $result.='<p><b>'.&mt('Correctness determined by the following IDs').'</b>';
1.408 albertel 12310: foreach my $id (sort(keys(%correct_ids))) {
1.411 www 12311: $result.='<br /><tt>'.$id.'</tt> - ';
1.408 albertel 12312: if ($correct_ids{$id} eq 'specified') {
12313: $result.=&mt('specified');
12314: } else {
12315: my ($uname,$udom)=split(/\:/,$correct_ids{$id});
12316: $result.=&Apache::loncommon::plainname($uname,$udom);
12317: }
12318: $number++;
12319: }
1.411 www 12320: $result.="</p>\n";
1.710 bisitz 12321: if ($number==0) {
12322: $result .=
12323: &Apache::lonhtmlcommon::confirm_success(
12324: &mt('No IDs found to determine correct answer'),1);
12325: return $result;
12326: }
1.404 www 12327: }
1.405 www 12328: if (length($env{'form.upfile'}) < 2) {
1.710 bisitz 12329: $result .=
12330: &Apache::lonhtmlcommon::confirm_success(
12331: &mt('The file: [_1] you attempted to upload contained no information. Please check that you entered the correct filename.',
12332: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'),1);
1.614 www 12333: return $result;
1.405 www 12334: }
1.760 raeburn 12335: my $mimetype;
12336: if ($env{'form.upfiletype'} eq 'iclicker') {
12337: my $mm = new File::MMagic;
12338: $mimetype = $mm->checktype_contents($env{'form.upfile'});
12339: unless (($mimetype eq 'text/plain') || ($mimetype eq 'text/html')) {
12340: $result.= '<p>'.
12341: &Apache::lonhtmlcommon::confirm_success(
12342: &mt('File format is neither csv (iclicker 6) nor xml (iclicker 7)'),1).'</p>';
12343: return $result;
12344: }
12345: } elsif (($env{'form.upfiletype'} ne 'interwrite') && ($env{'form.upfiletype'} ne 'turning')) {
12346: $result .= '<p>'.
12347: &Apache::lonhtmlcommon::confirm_success(
12348: &mt('Invalid clicker type: choose one of: i>clicker, Interwrite PRS, or Turning Technologies.'),1).'</p>';
12349: return $result;
12350: }
1.410 www 12351:
12352: # Were able to get all the info needed, now analyze the file
12353:
1.411 www 12354: $result.=&Apache::loncommon::studentbrowser_javascript();
1.418 albertel 12355: $symb = &Apache::lonenc::check_encrypt($symb);
1.632 www 12356: $result.=&Apache::loncommon::start_data_table().
12357: &Apache::loncommon::start_data_table_header_row().
12358: '<th>'.&mt('Evaluate clicker file').'</th>'.
12359: &Apache::loncommon::end_data_table_header_row().
12360: &Apache::loncommon::start_data_table_row().(<<ENDHEADER);
12361: <td>
1.410 www 12362: <form method="post" action="/adm/grades" name="clickeranalysis">
12363: <input type="hidden" name="symb" value="$symb" />
12364: <input type="hidden" name="command" value="assignclickergrades" />
1.411 www 12365: <input type="hidden" name="gradingmechanism" value="$env{'form.gradingmechanism'}" />
12366: <input type="hidden" name="pcorrect" value="$env{'form.pcorrect'}" />
12367: <input type="hidden" name="pincorrect" value="$env{'form.pincorrect'}" />
1.410 www 12368: ENDHEADER
1.522 www 12369: if ($env{'form.gradingmechanism'} eq 'given') {
12370: $result.='<input type="hidden" name="correct:given" value="'.$env{'form.givenanswer'}.'" />';
12371: }
1.408 albertel 12372: my %responses;
12373: my @questiontitles;
1.405 www 12374: my $errormsg='';
12375: my $number=0;
12376: if ($env{'form.upfiletype'} eq 'iclicker') {
1.760 raeburn 12377: if ($mimetype eq 'text/plain') {
12378: ($errormsg,$number)=&iclicker_eval(\@questiontitles,\%responses);
12379: } elsif ($mimetype eq 'text/html') {
12380: ($errormsg,$number)=&iclickerxml_eval(\@questiontitles,\%responses);
12381: }
12382: } elsif ($env{'form.upfiletype'} eq 'interwrite') {
1.419 www 12383: ($errormsg,$number)=&interwrite_eval(\@questiontitles,\%responses);
1.760 raeburn 12384: } elsif ($env{'form.upfiletype'} eq 'turning') {
1.666 www 12385: ($errormsg,$number)=&turning_eval(\@questiontitles,\%responses);
12386: }
1.411 www 12387: $result.='<br />'.&mt('Found [_1] question(s)',$number).'<br />'.
12388: '<input type="hidden" name="number" value="'.$number.'" />'.
12389: &mt('Awarding [_1] percent for correct and [_2] percent for incorrect responses',
12390: $env{'form.pcorrect'},$env{'form.pincorrect'}).
12391: '<br />';
1.522 www 12392: if (($env{'form.gradingmechanism'} eq 'given') && ($number!=$foundgiven)) {
12393: $result.='<span class="LC_error">'.&mt('Number of given answers does not agree with number of questions in file.').'</span>';
1.614 www 12394: return $result;
1.522 www 12395: }
1.414 www 12396: # Remember Question Titles
12397: # FIXME: Possibly need delimiter other than ":"
12398: for (my $i=0;$i<$number;$i++) {
12399: $result.='<input type="hidden" name="question:'.$i.'" value="'.
12400: &HTML::Entities::encode($questiontitles[$i],'"&<>').'" />';
12401: }
1.411 www 12402: my $correct_count=0;
12403: my $student_count=0;
12404: my $unknown_count=0;
1.414 www 12405: # Match answers with usernames
12406: # FIXME: Possibly need delimiter other than ":"
1.409 albertel 12407: foreach my $id (keys(%responses)) {
1.410 www 12408: if ($correct_ids{$id}) {
1.414 www 12409: $result.="\n".'<input type="hidden" name="correct:'.$correct_count.':'.$correct_ids{$id}.'" value="'.$responses{$id}.'" />';
1.411 www 12410: $correct_count++;
1.410 www 12411: } elsif ($clicker_ids{$id}) {
1.437 www 12412: if ($clicker_ids{$id}=~/\,/) {
12413: # More than one user with the same clicker!
1.632 www 12414: $result.="</td>".&Apache::loncommon::end_data_table_row().
12415: &Apache::loncommon::start_data_table_row()."<td>".
12416: &mt('Clicker registered more than once').": <tt>".$id."</tt><br />";
1.437 www 12417: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
12418: "<select name='multi".$id."'>";
12419: foreach my $reguser (sort(split(/\,/,$clicker_ids{$id}))) {
12420: $result.="<option value='".$reguser."'>".&Apache::loncommon::plainname(split(/\:/,$reguser)).' ('.$reguser.')</option>';
12421: }
12422: $result.='</select>';
12423: $unknown_count++;
12424: } else {
12425: # Good: found one and only one user with the right clicker
12426: $result.="\n".'<input type="hidden" name="student:'.$clicker_ids{$id}.'" value="'.$responses{$id}.'" />';
12427: $student_count++;
12428: }
1.410 www 12429: } else {
1.632 www 12430: $result.="</td>".&Apache::loncommon::end_data_table_row().
12431: &Apache::loncommon::start_data_table_row()."<td>".
12432: &mt('Unregistered Clicker')." <tt>".$id."</tt><br />";
1.411 www 12433: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
12434: "\n".&mt("Username").": <input type='text' name='uname".$id."' /> ".
12435: "\n".&mt("Domain").": ".
12436: &Apache::loncommon::select_dom_form($env{'course.'.$env{'request.course.id'}.'.domain'},'udom'.$id).' '.
1.762 raeburn 12437: &Apache::loncommon::selectstudent_link('clickeranalysis','uname'.$id,'udom'.$id,'',$id);
1.411 www 12438: $unknown_count++;
1.410 www 12439: }
1.405 www 12440: }
1.412 www 12441: $result.='<hr />'.
12442: &mt('Found [_1] registered and [_2] unregistered clickers.',$student_count,$unknown_count);
1.521 www 12443: if (($env{'form.gradingmechanism'} ne 'attendance') && ($env{'form.gradingmechanism'} ne 'given')) {
1.412 www 12444: if ($correct_count==0) {
1.696 bisitz 12445: $errormsg.="Found no correct answers for grading!";
1.412 www 12446: } elsif ($correct_count>1) {
1.414 www 12447: $result.='<br /><span class="LC_warning">'.&mt("Found [_1] entries for grading!",$correct_count).'</span>';
1.412 www 12448: }
12449: }
1.428 www 12450: if ($number<1) {
12451: $errormsg.="Found no questions.";
12452: }
1.412 www 12453: if ($errormsg) {
12454: $result.='<br /><span class="LC_error">'.&mt($errormsg).'</span>';
12455: } else {
12456: $result.='<br /><input type="submit" name="finalize" value="'.&mt('Finalize Grading').'" />';
12457: }
1.632 www 12458: $result.='</form></td>'.
12459: &Apache::loncommon::end_data_table_row().
12460: &Apache::loncommon::end_data_table();
1.614 www 12461: return $result;
1.400 www 12462: }
12463:
1.405 www 12464: sub iclicker_eval {
1.406 www 12465: my ($questiontitles,$responses)=@_;
1.405 www 12466: my $number=0;
12467: my $errormsg='';
12468: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
1.410 www 12469: my %components=&Apache::loncommon::record_sep($line);
12470: my @entries=map {$components{$_}} (sort(keys(%components)));
1.408 albertel 12471: if ($entries[0] eq 'Question') {
12472: for (my $i=3;$i<$#entries;$i+=6) {
12473: $$questiontitles[$number]=$entries[$i];
12474: $number++;
12475: }
12476: }
12477: if ($entries[0]=~/^\#/) {
12478: my $id=$entries[0];
12479: my @idresponses;
12480: $id=~s/^[\#0]+//;
12481: for (my $i=0;$i<$number;$i++) {
12482: my $idx=3+$i*6;
1.644 www 12483: $entries[$idx]=~s/[^a-zA-Z0-9\.\*\-\+]+//g;
1.408 albertel 12484: push(@idresponses,$entries[$idx]);
12485: }
12486: $$responses{$id}=join(',',@idresponses);
12487: }
1.405 www 12488: }
12489: return ($errormsg,$number);
12490: }
12491:
1.760 raeburn 12492: sub iclickerxml_eval {
12493: my ($questiontitles,$responses)=@_;
12494: my $number=0;
12495: my $errormsg='';
12496: my @state;
12497: my %respbyid;
12498: my $p = HTML::Parser->new
12499: (
12500: xml_mode => 1,
12501: start_h =>
12502: [sub {
12503: my ($tagname,$attr) = @_;
12504: push(@state,$tagname);
12505: if ("@state" eq "ssn p") {
12506: my $title = $attr->{qn};
12507: $title =~ s/(^\s+|\s+$)//g;
12508: $questiontitles->[$number]=$title;
12509: } elsif ("@state" eq "ssn p v") {
12510: my $id = $attr->{id};
12511: my $entry = $attr->{ans};
12512: $id=~s/^[\#0]+//;
12513: $entry =~s/[^a-zA-Z0-9\.\*\-\+]+//g;
12514: $respbyid{$id}[$number] = $entry;
12515: }
12516: }, "tagname, attr"],
12517: end_h =>
12518: [sub {
12519: my ($tagname) = @_;
12520: if ("@state" eq "ssn p") {
12521: $number++;
12522: }
12523: pop(@state);
12524: }, "tagname"],
12525: );
12526:
12527: $p->parse($env{'form.upfile'});
12528: $p->eof;
12529: foreach my $id (keys(%respbyid)) {
12530: $responses->{$id}=join(',',@{$respbyid{$id}});
12531: }
12532: return ($errormsg,$number);
12533: }
12534:
1.419 www 12535: sub interwrite_eval {
12536: my ($questiontitles,$responses)=@_;
12537: my $number=0;
12538: my $errormsg='';
1.420 www 12539: my $skipline=1;
12540: my $questionnumber=0;
12541: my %idresponses=();
1.419 www 12542: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
12543: my %components=&Apache::loncommon::record_sep($line);
12544: my @entries=map {$components{$_}} (sort(keys(%components)));
1.420 www 12545: if ($entries[1] eq 'Time') { $skipline=0; next; }
12546: if ($entries[1] eq 'Response') { $skipline=1; }
12547: next if $skipline;
12548: if ($entries[0]!=$questionnumber) {
12549: $questionnumber=$entries[0];
12550: $$questiontitles[$number]=&mt('Question [_1]',$questionnumber);
12551: $number++;
1.419 www 12552: }
1.420 www 12553: my $id=$entries[4];
12554: $id=~s/^[\#0]+//;
1.421 www 12555: $id=~s/^v\d*\://i;
12556: $id=~s/[\-\:]//g;
1.420 www 12557: $idresponses{$id}[$number]=$entries[6];
12558: }
1.524 raeburn 12559: foreach my $id (keys(%idresponses)) {
1.420 www 12560: $$responses{$id}=join(',',@{$idresponses{$id}});
12561: $$responses{$id}=~s/^\s*\,//;
1.419 www 12562: }
12563: return ($errormsg,$number);
12564: }
12565:
1.666 www 12566: sub turning_eval {
12567: my ($questiontitles,$responses)=@_;
12568: my $number=0;
12569: my $errormsg='';
12570: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
12571: my %components=&Apache::loncommon::record_sep($line);
12572: my @entries=map {$components{$_}} (sort(keys(%components)));
12573: if ($#entries>$number) { $number=$#entries; }
12574: my $id=$entries[0];
12575: my @idresponses;
12576: $id=~s/^[\#0]+//;
12577: unless ($id) { next; }
12578: for (my $idx=1;$idx<=$#entries;$idx++) {
12579: $entries[$idx]=~s/\,/\;/g;
12580: $entries[$idx]=~s/[^a-zA-Z0-9\.\*\-\+\;]+//g;
12581: push(@idresponses,$entries[$idx]);
12582: }
12583: $$responses{$id}=join(',',@idresponses);
12584: }
12585: for (my $i=1; $i<=$number; $i++) {
12586: $$questiontitles[$i]=&mt('Question [_1]',$i);
12587: }
12588: return ($errormsg,$number);
12589: }
12590:
12591:
1.414 www 12592: sub assign_clicker_grades {
1.766 raeburn 12593: my ($r,$symb) = @_;
1.414 www 12594: if (!$symb) {return '';}
1.416 www 12595: # See which part we are saving to
1.582 raeburn 12596: my $res_error;
12597: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
12598: if ($res_error) {
12599: return &navmap_errormsg();
12600: }
1.804 raeburn 12601: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
12602: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
12603: my %needpb = &passbacks_for_symb($cdom,$cnum,$symb);
12604: my (%skip_passback,%pbsave);
1.416 www 12605: # FIXME: This should probably look for the first handgradeable part
12606: my $part=$$partlist[0];
12607: # Start screen output
1.766 raeburn 12608: my $result = &Apache::loncommon::start_data_table().
12609: &Apache::loncommon::start_data_table_header_row().
12610: '<th>'.&mt('Assigning grades based on clicker file').'</th>'.
12611: &Apache::loncommon::end_data_table_header_row().
12612: &Apache::loncommon::start_data_table_row().'<td>';
1.414 www 12613: # Get correct result
12614: # FIXME: Possibly need delimiter other than ":"
12615: my @correct=();
1.415 www 12616: my $gradingmechanism=$env{'form.gradingmechanism'};
12617: my $number=$env{'form.number'};
12618: if ($gradingmechanism ne 'attendance') {
1.414 www 12619: foreach my $key (keys(%env)) {
12620: if ($key=~/^form\.correct\:/) {
12621: my @input=split(/\,/,$env{$key});
12622: for (my $i=0;$i<=$#input;$i++) {
12623: if (($correct[$i]) && ($input[$i]) &&
12624: ($correct[$i] ne $input[$i])) {
12625: $result.='<br /><span class="LC_warning">'.
12626: &mt('More than one correct result given for question "[_1]": [_2] versus [_3].',
12627: $env{'form.question:'.$i},$correct[$i],$input[$i]).'</span>';
1.644 www 12628: } elsif (($input[$i]) || ($input[$i] eq '0')) {
1.414 www 12629: $correct[$i]=$input[$i];
12630: }
12631: }
12632: }
12633: }
1.415 www 12634: for (my $i=0;$i<$number;$i++) {
1.644 www 12635: if ((!$correct[$i]) && ($correct[$i] ne '0')) {
1.414 www 12636: $result.='<br /><span class="LC_error">'.
12637: &mt('No correct result given for question "[_1]"!',
12638: $env{'form.question:'.$i}).'</span>';
12639: }
12640: }
1.644 www 12641: $result.='<br />'.&mt("Correct answer: [_1]",join(', ',map { ((($_) || ($_ eq '0'))?$_:'-') } @correct));
1.414 www 12642: }
12643: # Start grading
1.415 www 12644: my $pcorrect=$env{'form.pcorrect'};
12645: my $pincorrect=$env{'form.pincorrect'};
1.416 www 12646: my $storecount=0;
1.632 www 12647: my %users=();
1.415 www 12648: foreach my $key (keys(%env)) {
1.420 www 12649: my $user='';
1.415 www 12650: if ($key=~/^form\.student\:(.*)$/) {
1.420 www 12651: $user=$1;
12652: }
12653: if ($key=~/^form\.unknown\:(.*)$/) {
12654: my $id=$1;
12655: if (($env{'form.uname'.$id}) && ($env{'form.udom'.$id})) {
12656: $user=$env{'form.uname'.$id}.':'.$env{'form.udom'.$id};
1.437 www 12657: } elsif ($env{'form.multi'.$id}) {
12658: $user=$env{'form.multi'.$id};
1.420 www 12659: }
12660: }
1.632 www 12661: if ($user) {
12662: if ($users{$user}) {
12663: $result.='<br /><span class="LC_warning">'.
1.696 bisitz 12664: &mt('More than one entry found for [_1]!','<tt>'.$user.'</tt>').
1.632 www 12665: '</span><br />';
12666: }
12667: $users{$user}=1;
1.415 www 12668: my @answer=split(/\,/,$env{$key});
12669: my $sum=0;
1.522 www 12670: my $realnumber=$number;
1.415 www 12671: for (my $i=0;$i<$number;$i++) {
1.576 www 12672: if ($correct[$i] eq '-') {
12673: $realnumber--;
1.766 raeburn 12674: } elsif (($answer[$i]) || ($answer[$i]=~/^[0\.]+$/)) {
1.415 www 12675: if ($gradingmechanism eq 'attendance') {
12676: $sum+=$pcorrect;
1.576 www 12677: } elsif ($correct[$i] eq '*') {
1.522 www 12678: $sum+=$pcorrect;
1.415 www 12679: } else {
1.644 www 12680: # We actually grade if correct or not
12681: my $increment=$pincorrect;
12682: # Special case: numerical answer "0"
12683: if ($correct[$i] eq '0') {
12684: if ($answer[$i]=~/^[0\.]+$/) {
12685: $increment=$pcorrect;
12686: }
12687: # General numerical answer, both evaluate to something non-zero
12688: } elsif ((1.0*$correct[$i]!=0) && (1.0*$answer[$i]!=0)) {
12689: if (1.0*$correct[$i]==1.0*$answer[$i]) {
12690: $increment=$pcorrect;
12691: }
12692: # Must be just alphanumeric
12693: } elsif ($answer[$i] eq $correct[$i]) {
12694: $increment=$pcorrect;
1.415 www 12695: }
1.644 www 12696: $sum+=$increment;
1.415 www 12697: }
12698: }
12699: }
1.522 www 12700: my $ave=$sum/(100*$realnumber);
1.416 www 12701: # Store
12702: my ($username,$domain)=split(/\:/,$user);
12703: my %grades=();
12704: $grades{"resource.$part.solved"}='correct_by_override';
12705: $grades{"resource.$part.awarded"}=$ave;
12706: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
12707: my $returncode=&Apache::lonnet::cstore(\%grades,$symb,
12708: $env{'request.course.id'},
12709: $domain,$username);
12710: if ($returncode ne 'ok') {
12711: $result.="<br /><span class=\"LC_error\">Failed to save student $username:$domain. Message when trying to save was ($returncode)</span>";
12712: } else {
12713: $storecount++;
1.804 raeburn 12714: if (keys(%needpb)) {
12715: my (%weights,%awardeds,%excuseds);
12716: my $usec = &Apache::lonnet::getsection($domain,$username,$env{'request.course.id'});
12717: $weights{$symb}{$part} = &Apache::lonnet::EXT("resource.$part.weight",$symb,$domain,$username,$usec);
12718: $awardeds{$symb}{$part} = $ave;
12719: $excuseds{$symb}{$part} = '';
12720: &process_passbacks('clickergrade',[$symb],$cdom,$cnum,$domain,$username,$usec,\%weights,
12721: \%awardeds,\%excuseds,\%needpb,\%skip_passback,\%pbsave);
12722: }
1.416 www 12723: }
1.415 www 12724: }
12725: }
12726: # We are done
1.549 hauer 12727: $result.='<br />'.&mt('Successfully stored grades for [quant,_1,student].',$storecount).
1.632 www 12728: '</td>'.
12729: &Apache::loncommon::end_data_table_row().
12730: &Apache::loncommon::end_data_table();
1.614 www 12731: return $result;
1.414 www 12732: }
12733:
1.582 raeburn 12734: sub navmap_errormsg {
12735: return '<div class="LC_error">'.
12736: &mt('An error occurred retrieving information about resources in the course.').'<br />'.
1.595 raeburn 12737: &mt('It is recommended that you [_1]re-initialize the course[_2] and then return to this grading page.','<a href="/adm/roles?selectrole=1&newrole='.$env{'request.role'}.'">','</a>').
1.582 raeburn 12738: '</div>';
12739: }
1.607 droeschl 12740:
1.609 www 12741: sub startpage {
1.777 raeburn 12742: my ($r,$symb,$crumbs,$onlyfolderflag,$nodisplayflag,$stuvcurrent,$stuvdisp,$nomenu,$head_extra,$onload,$divforres) = @_;
1.754 raeburn 12743: my %args;
12744: if ($onload) {
12745: my %loaditems = (
12746: 'onload' => $onload,
12747: );
12748: $args{'add_entries'} = \%loaditems;
12749: }
1.671 raeburn 12750: if ($nomenu) {
1.754 raeburn 12751: $args{'only_body'} = 1;
1.777 raeburn 12752: $r->print(&Apache::loncommon::start_page("Student's Version",$head_extra,\%args));
1.671 raeburn 12753: } else {
1.785 raeburn 12754: if ($env{'request.course.id'}) {
12755: unshift(@$crumbs,{href=>&href_symb_cmd($symb,'gradingmenu'),text=>"Grading"});
12756: }
1.754 raeburn 12757: $args{'bread_crumbs'} = $crumbs;
1.777 raeburn 12758: $r->print(&Apache::loncommon::start_page('Grading',$head_extra,\%args));
1.765 raeburn 12759: if ($env{'request.course.id'}) {
12760: &Apache::lonquickgrades::startGradeScreen($r,($env{'form.symb'}?'probgrading':'grading'));
12761: }
1.671 raeburn 12762: }
1.613 www 12763: unless ($nodisplayflag) {
1.773 raeburn 12764: $r->print(&Apache::lonhtmlcommon::resource_info_box($symb,$onlyfolderflag,$stuvcurrent,$stuvdisp,$divforres));
1.613 www 12765: }
1.607 droeschl 12766: }
1.582 raeburn 12767:
1.622 www 12768: sub select_problem {
12769: my ($r)=@_;
1.632 www 12770: $r->print('<h3>'.&mt('Select the problem or one of the problems you want to grade').'</h3><form action="/adm/grades">');
1.771 raeburn 12771: $r->print(&Apache::lonstathelpers::problem_selector('.',undef,1,undef,undef,1,1));
1.622 www 12772: $r->print('<input type="hidden" name="command" value="gradingmenu" />');
12773: $r->print('<input type="submit" value="'.&mt('Next').' →" /></form>');
12774: }
12775:
1.793 raeburn 12776: #----- display problem, answer, and submissions for a single student (no grading)
12777:
12778: sub view_as_user {
12779: my ($symb,$vuname,$vudom,$hasperm) = @_;
12780: my $plainname = &Apache::loncommon::plainname($vuname,$vudom,'lastname');
12781: my $displayname = &nameUserString('',$plainname,$vuname,$vudom);
12782: my $output = &Apache::loncommon::get_student_view($symb,$vuname,$vudom,
12783: $env{'request.course.id'},
12784: undef,{'disable_submit' => 1}).
12785: "\n\n".
12786: '<div class="LC_grade_show_user">'.
12787: '<h2>'.$displayname.'</h2>'.
12788: "\n".
12789: &Apache::loncommon::track_student_link('View recent activity',
12790: $vuname,$vudom,'check').' '.
12791: "\n";
12792: if (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) ||
12793: (($env{'request.course.sec'} ne '') &&
12794: &Apache::lonnet::allowed('opa',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
12795: $output .= &Apache::loncommon::pprmlink(&mt('Set/Change parameters'),
12796: $vuname,$vudom,$symb,'check');
12797: }
12798: $output .= "\n";
12799: my $companswer = &Apache::loncommon::get_student_answers($symb,$vuname,$vudom,
12800: $env{'request.course.id'});
12801: $companswer=~s|<form(.*?)>||g;
12802: $companswer=~s|</form>||g;
12803: $companswer=~s|name="submit"|name="would_have_been_submit"|g;
12804: $output .= '<div class="LC_Box">'.
12805: '<h3 class="LC_hcell">'.&mt('Correct answer for[_1]',$displayname).'</h3>'.
12806: $companswer.
12807: '</div>'."\n";
12808: my $is_tool = ($symb =~ /ext\.tool$/);
12809: my ($essayurl,%coursedesc_by_cid);
12810: (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb);
12811: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$vudom,$vuname);
12812: my $res_error;
12813: my ($partlist,$handgrade,$responseType,$numresp,$numessay) =
12814: &response_type($symb,\$res_error);
12815: my $fullname;
12816: my $collabinfo;
12817: if ($numessay) {
12818: unless ($hasperm) {
12819: &init_perm();
12820: }
12821: ($collabinfo,$fullname)=
12822: &check_collaborators($symb,$vuname,$vudom,\%record,$handgrade,0);
12823: unless ($hasperm) {
12824: &reset_perm();
12825: }
12826: }
12827: my $checkIcon = '<img alt="'.&mt('Check Mark').
12828: '" src="'.$Apache::lonnet::perlvar{'lonIconsURL'}.
12829: '/check.gif" height="16" border="0" />';
12830: my ($lastsubonly,$partinfo) =
12831: &show_last_submission($vuname,$vudom,$symb,$essayurl,$responseType,'datesub',
12832: '',$fullname,\%record,\%coursedesc_by_cid);
12833: $output .= '<div class="LC_Box">'.
12834: '<h3 class="LC_hcell">'.&mt('Submissions').'</h3>'."\n".$collabinfo."\n";
12835: if (($numresp > $numessay) & !$is_tool) {
12836: $output .='<p class="LC_info">'.
12837: &mt('Part(s) graded correct by the computer is marked with a [_1] symbol.',$checkIcon).
12838: "</p>\n";
12839: }
12840: $output .= $partinfo;
12841: $output .= $lastsubonly;
12842: $output .= &displaySubByDates($symb,\%record,$partlist,$responseType,$checkIcon,$vuname,$vudom);
12843: $output .= '</div></div>'."\n";
12844: return $output;
12845: }
12846:
1.1 albertel 12847: sub handler {
1.41 ng 12848: my $request=$_[0];
1.434 albertel 12849: &reset_caches();
1.646 raeburn 12850: if ($request->header_only) {
12851: &Apache::loncommon::content_type($request,'text/html');
12852: $request->send_http_header;
12853: return OK;
12854: }
12855: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
12856:
1.664 raeburn 12857: # see what command we need to execute
12858:
12859: my @commands=&Apache::loncommon::get_env_multiple('form.command');
12860: my $command=$commands[0];
12861:
1.646 raeburn 12862: &init_perm();
12863: if (!$env{'request.course.id'}) {
1.664 raeburn 12864: unless ((&Apache::lonnet::allowed('usc',$env{'request.role.domain'})) &&
12865: ($command =~ /^scantronupload/)) {
12866: # Not in a course.
12867: $env{'user.error.msg'}="/adm/grades::vgr:0:0:Cannot display grades page outside course context";
12868: return HTTP_NOT_ACCEPTABLE;
12869: }
1.646 raeburn 12870: } elsif (!%perm) {
12871: $request->internal_redirect('/adm/quickgrades');
1.687 raeburn 12872: return OK;
1.41 ng 12873: }
1.646 raeburn 12874: &Apache::loncommon::content_type($request,'text/html');
1.41 ng 12875: $request->send_http_header;
1.646 raeburn 12876:
1.160 albertel 12877: if ($#commands > 0) {
12878: &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands));
12879: }
1.608 www 12880:
1.801 raeburn 12881: # -------------------------------------- Flag and buffer for registered cleanup
12882: $registered_cleanup=0;
12883: undef(@Apache::grades::ltipassback);
12884:
1.608 www 12885: # see what the symb is
12886:
12887: my $symb=$env{'form.symb'};
12888: unless ($symb) {
12889: (my $url=$env{'form.url'}) =~ s-^https*://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
12890: $symb=&Apache::lonnet::symbread($url);
12891: }
1.646 raeburn 12892: &Apache::lonenc::check_decrypt(\$symb);
1.608 www 12893:
1.513 foxr 12894: $ssi_error = 0;
1.637 www 12895: if (($symb eq '' || $command eq '') && ($env{'request.course.id'})) {
1.601 www 12896: #
1.637 www 12897: # Not called from a resource, but inside a course
1.601 www 12898: #
1.622 www 12899: &startpage($request,undef,[],1,1);
12900: &select_problem($request);
1.41 ng 12901: } else {
1.104 albertel 12902: if ($command eq 'submission' && $perm{'vgr'}) {
1.773 raeburn 12903: my ($stuvcurrent,$stuvdisp,$versionform,$js,$onload);
1.671 raeburn 12904: if (($env{'form.student'} ne '') && ($env{'form.userdom'} ne '')) {
12905: ($stuvcurrent,$stuvdisp,$versionform,$js) =
12906: &choose_task_version_form($symb,$env{'form.student'},
12907: $env{'form.userdom'});
12908: }
1.773 raeburn 12909: my $divforres;
12910: if ($env{'form.student'} eq '') {
12911: $js .= &part_selector_js();
12912: $onload = "toggleParts('gradesub');";
12913: } else {
12914: $divforres = 1;
12915: }
1.778 raeburn 12916: my $head_extra = $js;
12917: unless ($env{'form.vProb'} eq 'no') {
1.779 raeburn 12918: my $csslinks = &Apache::loncommon::css_links($symb);
1.778 raeburn 12919: if ($csslinks) {
12920: $head_extra .= "\n$csslinks";
12921: }
12922: }
1.777 raeburn 12923: &startpage($request,$symb,[{href=>"", text=>"Student Submissions"}],undef,undef,
12924: $stuvcurrent,$stuvdisp,undef,$head_extra,$onload,$divforres);
1.671 raeburn 12925: if ($versionform) {
1.775 raeburn 12926: if ($divforres) {
12927: $request->print('<div style="padding:0;clear:both;margin:0;border:0"></div>');
12928: }
1.671 raeburn 12929: $request->print($versionform);
12930: }
1.773 raeburn 12931: ($env{'form.student'} eq '' ? &listStudents($request,$symb,'',$divforres) : &submission($request,0,0,$symb,$divforres,$command));
1.671 raeburn 12932: } elsif ($command eq 'versionsub' && $perm{'vgr'}) {
12933: my ($stuvcurrent,$stuvdisp,$versionform,$js) =
12934: &choose_task_version_form($symb,$env{'form.student'},
12935: $env{'form.userdom'},
12936: $env{'form.inhibitmenu'});
1.778 raeburn 12937: my $head_extra = $js;
12938: unless ($env{'form.vProb'} eq 'no') {
1.779 raeburn 12939: my $csslinks = &Apache::loncommon::css_links($symb);
1.778 raeburn 12940: if ($csslinks) {
12941: $head_extra .= "\n$csslinks";
12942: }
12943: }
1.777 raeburn 12944: &startpage($request,$symb,[{href=>"", text=>"Previous Student Version"}],undef,undef,
12945: $stuvcurrent,$stuvdisp,$env{'form.inhibitmenu'},$head_extra);
1.671 raeburn 12946: if ($versionform) {
12947: $request->print($versionform);
12948: }
12949: $request->print('<br clear="all" />');
12950: $request->print(&show_previous_task_version($request,$symb));
1.103 albertel 12951: } elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) {
1.615 www 12952: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'all_for_one'),text=>'Grade page/folder for one student'},
12953: {href=>'',text=>'Select student'}],1,1);
1.608 www 12954: &pickStudentPage($request,$symb);
1.103 albertel 12955: } elsif ($command eq 'displayPage' && $perm{'vgr'}) {
1.778 raeburn 12956: my $csslinks;
12957: unless ($env{'form.vProb'} eq 'no') {
1.779 raeburn 12958: $csslinks = &Apache::loncommon::css_links($symb,'map');
1.778 raeburn 12959: }
1.615 www 12960: &startpage($request,$symb,
12961: [{href=>&href_symb_cmd($symb,'all_for_one'),text=>'Grade page/folder for one student'},
12962: {href=>'',text=>'Select student'},
1.777 raeburn 12963: {href=>'',text=>'Grade student'}],1,1,undef,undef,undef,$csslinks);
1.608 www 12964: &displayPage($request,$symb);
1.104 albertel 12965: } elsif ($command eq 'gradeByPage' && $perm{'mgr'}) {
1.616 www 12966: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'all_for_one'),text=>'Grade page/folder for one student'},
12967: {href=>'',text=>'Select student'},
12968: {href=>'',text=>'Grade student'},
12969: {href=>'',text=>'Store grades'}],1,1);
1.608 www 12970: &updateGradeByPage($request,$symb);
1.104 albertel 12971: } elsif ($command eq 'processGroup' && $perm{'vgr'}) {
1.778 raeburn 12972: my $csslinks;
12973: unless ($env{'form.vProb'} eq 'no') {
1.779 raeburn 12974: $csslinks = &Apache::loncommon::css_links($symb);
1.778 raeburn 12975: }
1.619 www 12976: &startpage($request,$symb,[{href=>'',text=>'...'},
1.777 raeburn 12977: {href=>'',text=>'Modify grades'}],undef,undef,undef,undef,undef,$csslinks,undef,1);
1.608 www 12978: &processGroup($request,$symb);
1.104 albertel 12979: } elsif ($command eq 'gradingmenu' && $perm{'vgr'}) {
1.608 www 12980: &startpage($request,$symb);
12981: $request->print(&grading_menu($request,$symb));
1.598 www 12982: } elsif ($command eq 'individual' && $perm{'vgr'}) {
1.617 www 12983: &startpage($request,$symb,[{href=>'',text=>'Select individual students to grade'}]);
1.608 www 12984: $request->print(&submit_options($request,$symb));
1.598 www 12985: } elsif ($command eq 'ungraded' && $perm{'vgr'}) {
1.773 raeburn 12986: my $js = &part_selector_js();
12987: my $onload = "toggleParts('gradesub');";
12988: &startpage($request,$symb,[{href=>'',text=>'Grade ungraded submissions'}],
12989: undef,undef,undef,undef,undef,$js,$onload);
1.617 www 12990: $request->print(&listStudents($request,$symb,'graded'));
1.598 www 12991: } elsif ($command eq 'table' && $perm{'vgr'}) {
1.614 www 12992: &startpage($request,$symb,[{href=>"", text=>"Grading table"}]);
1.611 www 12993: $request->print(&submit_options_table($request,$symb));
1.598 www 12994: } elsif ($command eq 'all_for_one' && $perm{'vgr'}) {
1.615 www 12995: &startpage($request,$symb,[{href=>'',text=>'Grade page/folder for one student'}],1,1);
1.608 www 12996: $request->print(&submit_options_sequence($request,$symb));
1.104 albertel 12997: } elsif ($command eq 'viewgrades' && $perm{'vgr'}) {
1.614 www 12998: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,"table"), text=>"Grading table"},{href=>'', text=>"Modify grades"}]);
1.608 www 12999: $request->print(&viewgrades($request,$symb));
1.104 albertel 13000: } elsif ($command eq 'handgrade' && $perm{'mgr'}) {
1.620 www 13001: &startpage($request,$symb,[{href=>'',text=>'...'},
13002: {href=>'',text=>'Store grades'}]);
1.608 www 13003: $request->print(&processHandGrade($request,$symb));
1.106 albertel 13004: } elsif ($command eq 'editgrades' && $perm{'mgr'}) {
1.614 www 13005: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,"table"), text=>"Grading table"},
13006: {href=>&href_symb_cmd($symb,'viewgrades').'&group=all§ion=all&Status=Active',
13007: text=>"Modify grades"},
13008: {href=>'', text=>"Store grades"}]);
1.608 www 13009: $request->print(&editgrades($request,$symb));
1.602 www 13010: } elsif ($command eq 'initialverifyreceipt' && $perm{'vgr'}) {
1.616 www 13011: &startpage($request,$symb,[{href=>'',text=>'Verify Receipt Number'}]);
1.611 www 13012: $request->print(&initialverifyreceipt($request,$symb));
1.106 albertel 13013: } elsif ($command eq 'verify' && $perm{'vgr'}) {
1.616 www 13014: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,"initialverifyreceipt"),text=>'Verify Receipt Number'},
13015: {href=>'',text=>'Verification Result'}]);
1.608 www 13016: $request->print(&verifyreceipt($request,$symb));
1.400 www 13017: } elsif ($command eq 'processclicker' && $perm{'mgr'}) {
1.615 www 13018: &startpage($request,$symb,[{href=>'', text=>'Process clicker'}]);
1.608 www 13019: $request->print(&process_clicker($request,$symb));
1.400 www 13020: } elsif ($command eq 'processclickerfile' && $perm{'mgr'}) {
1.615 www 13021: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'processclicker'), text=>'Process clicker'},
13022: {href=>'', text=>'Process clicker file'}]);
1.608 www 13023: $request->print(&process_clicker_file($request,$symb));
1.414 www 13024: } elsif ($command eq 'assignclickergrades' && $perm{'mgr'}) {
1.615 www 13025: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'processclicker'), text=>'Process clicker'},
13026: {href=>'', text=>'Process clicker file'},
13027: {href=>'', text=>'Store grades'}]);
1.608 www 13028: $request->print(&assign_clicker_grades($request,$symb));
1.106 albertel 13029: } elsif ($command eq 'csvform' && $perm{'mgr'}) {
1.627 www 13030: &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
1.608 www 13031: $request->print(&upcsvScores_form($request,$symb));
1.106 albertel 13032: } elsif ($command eq 'csvupload' && $perm{'mgr'}) {
1.627 www 13033: &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
1.608 www 13034: $request->print(&csvupload($request,$symb));
1.106 albertel 13035: } elsif ($command eq 'csvuploadmap' && $perm{'mgr'} ) {
1.627 www 13036: &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
1.608 www 13037: $request->print(&csvuploadmap($request,$symb));
1.246 albertel 13038: } elsif ($command eq 'csvuploadoptions' && $perm{'mgr'}) {
1.257 albertel 13039: if ($env{'form.associate'} ne 'Reverse Association') {
1.627 www 13040: &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
1.608 www 13041: $request->print(&csvuploadoptions($request,$symb));
1.41 ng 13042: } else {
1.257 albertel 13043: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
13044: $env{'form.upfile_associate'} = 'reverse';
1.41 ng 13045: } else {
1.257 albertel 13046: $env{'form.upfile_associate'} = 'forward';
1.41 ng 13047: }
1.627 www 13048: &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
1.608 www 13049: $request->print(&csvuploadmap($request,$symb));
1.41 ng 13050: }
1.246 albertel 13051: } elsif ($command eq 'csvuploadassign' && $perm{'mgr'} ) {
1.627 www 13052: &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
1.608 www 13053: $request->print(&csvuploadassign($request,$symb));
1.106 albertel 13054: } elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
1.754 raeburn 13055: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1,
13056: undef,undef,undef,undef,'toggleScantab(document.rules);');
1.612 www 13057: $request->print(&scantron_selectphase($request,undef,$symb));
1.203 albertel 13058: } elsif ($command eq 'scantron_warning' && $perm{'mgr'}) {
1.616 www 13059: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 13060: $request->print(&scantron_do_warning($request,$symb));
1.142 albertel 13061: } elsif ($command eq 'scantron_validate' && $perm{'mgr'}) {
1.616 www 13062: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 13063: $request->print(&scantron_validate_file($request,$symb));
1.106 albertel 13064: } elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
1.616 www 13065: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 13066: $request->print(&scantron_process_students($request,$symb));
1.157 albertel 13067: } elsif ($command eq 'scantronupload' &&
1.770 raeburn 13068: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) || $perm{'usc'})) {
1.754 raeburn 13069: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1,
13070: undef,undef,undef,undef,'toggleScantab(document.rules);');
1.608 www 13071: $request->print(&scantron_upload_scantron_data($request,$symb));
1.157 albertel 13072: } elsif ($command eq 'scantronupload_save' &&
1.770 raeburn 13073: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) || $perm{'usc'})) {
1.616 www 13074: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 13075: $request->print(&scantron_upload_scantron_data_save($request,$symb));
1.770 raeburn 13076: } elsif ($command eq 'scantron_download' && ($perm{'usc'} || $perm{'mgr'})) {
1.616 www 13077: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 13078: $request->print(&scantron_download_scantron_data($request,$symb));
1.770 raeburn 13079: } elsif ($command eq 'scantronupload_delete' &&
13080: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) || $perm{'usc'})) {
13081: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
13082: &scantron_upload_delete($request,$symb);
1.523 raeburn 13083: } elsif ($command eq 'checksubmissions' && $perm{'vgr'}) {
1.616 www 13084: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.621 www 13085: $request->print(&checkscantron_results($request,$symb));
13086: } elsif ($command eq 'downloadfilesselect' && $perm{'vgr'}) {
1.773 raeburn 13087: my $js = &part_selector_js();
13088: my $onload = "toggleParts('gradingMenu');";
13089: &startpage($request,$symb,[{href=>'', text=>'Select which submissions to download'}],
13090: undef,undef,undef,undef,undef,$js,$onload);
1.621 www 13091: $request->print(&submit_options_download($request,$symb));
13092: } elsif ($command eq 'downloadfileslink' && $perm{'vgr'}) {
13093: &startpage($request,$symb,
13094: [{href=>&href_symb_cmd($symb,'downloadfilesselect'), text=>'Select which submissions to download'},
1.773 raeburn 13095: {href=>'', text=>'Download submitted files'}],
13096: undef,undef,undef,undef,undef,undef,undef,1);
1.775 raeburn 13097: $request->print('<div style="padding:0;clear:both;margin:0;border:0"></div>');
1.621 www 13098: &submit_download_link($request,$symb);
1.796 raeburn 13099: } elsif ($command eq 'initialpassback') {
13100: &startpage($request,$symb,[{href=>'', text=>'Choose Launcher'}],undef,1);
13101: $request->print(&initialpassback($request,$symb));
13102: } elsif ($command eq 'passback') {
13103: &startpage($request,$symb,
13104: [{href=>&href_symb_cmd($symb,'initialpassback'), text=>'Choose Launcher'},
13105: {href=>'', text=>'Types of User'}],undef,1);
13106: $request->print(&passback_filters($request,$symb));
13107: } elsif ($command eq 'passbacknames') {
13108: my $chosen;
13109: if ($env{'form.passback'} ne '') {
13110: if ($env{'form.passback'} eq &unescape($env{'form.passback'})) {
13111: $env{'form.passback'} = &escape($env{'form.passback'} );
13112: }
13113: $chosen = &HTML::Entities::encode($env{'form.passback'},'<>"&');
13114: }
13115: &startpage($request,$symb,
13116: [{href=>&href_symb_cmd($symb,'initialpassback'), text=>'Choose Launcher'},
13117: {href=>&href_symb_cmd($symb,'passback').'&passback='.$chosen, text=>'Types of User'},
13118: {href=>'', text=>'Select Users'}],undef,1);
13119: $request->print(&names_for_passback($request,$symb));
13120: } elsif ($command eq 'passbackscores') {
13121: my ($chosen,$stu_status);
13122: if ($env{'form.passback'} ne '') {
13123: if ($env{'form.passback'} eq &unescape($env{'form.passback'})) {
13124: $env{'form.passback'} = &escape($env{'form.passback'} );
13125: }
13126: $chosen = &HTML::Entities::encode($env{'form.passback'},'<>"&');
13127: }
13128: if ($env{'form.Status'}) {
13129: $stu_status = &HTML::Entities::encode($env{'form.Status'});
13130: }
13131: &startpage($request,$symb,
13132: [{href=>&href_symb_cmd($symb,'initialpassback'), text=>'Choose Launcher'},
13133: {href=>&href_symb_cmd($symb,'passback').'&passback='.$chosen, text=>'Types of User'},
13134: {href=>&href_symb_cmd($symb,'passbacknames').'&Status='.$stu_status.'&passback='.$chosen, text=>'Select Users'},
13135: {href=>'', text=>'Execute Passback'}],undef,1);
13136: $request->print(&do_passback($request,$symb));
1.106 albertel 13137: } elsif ($command) {
1.620 www 13138: &startpage($request,$symb,[{href=>'', text=>'Access denied'}]);
1.562 bisitz 13139: $request->print('<p class="LC_error">'.&mt('Access Denied ([_1])',$command).'</p>');
1.26 albertel 13140: }
1.2 albertel 13141: }
1.513 foxr 13142: if ($ssi_error) {
13143: &ssi_print_error($request);
13144: }
1.671 raeburn 13145: if ($env{'form.inhibitmenu'}) {
13146: $request->print(&Apache::loncommon::end_page());
1.765 raeburn 13147: } elsif ($env{'request.course.id'}) {
1.671 raeburn 13148: &Apache::lonquickgrades::endGradeScreen($request);
13149: }
1.434 albertel 13150: &reset_caches();
1.646 raeburn 13151: return OK;
1.44 ng 13152: }
13153:
1.1 albertel 13154: 1;
13155:
1.13 albertel 13156: __END__;
1.531 jms 13157:
13158:
13159: =head1 NAME
13160:
13161: Apache::grades
13162:
13163: =head1 SYNOPSIS
13164:
13165: Handles the viewing of grades.
13166:
13167: This is part of the LearningOnline Network with CAPA project
13168: described at http://www.lon-capa.org.
13169:
13170: =head1 OVERVIEW
13171:
13172: Do an ssi with retries:
1.715 bisitz 13173: While I'd love to factor out this with the version in lonprintout,
1.531 jms 13174: 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
13175: I'm not quite ready to invent (e.g. an ssi_with_retry object).
13176:
13177: At least the logic that drives this has been pulled out into loncommon.
13178:
13179:
13180:
13181: ssi_with_retries - Does the server side include of a resource.
13182: if the ssi call returns an error we'll retry it up to
13183: the number of times requested by the caller.
1.715 bisitz 13184: If we still have a problem, no text is appended to the
1.531 jms 13185: output and we set some global variables.
13186: to indicate to the caller an SSI error occurred.
13187: All of this is supposed to deal with the issues described
1.715 bisitz 13188: in LON-CAPA BZ 5631 see:
1.531 jms 13189: http://bugs.lon-capa.org/show_bug.cgi?id=5631
13190: by informing the user that this happened.
13191:
13192: Parameters:
13193: resource - The resource to include. This is passed directly, without
13194: interpretation to lonnet::ssi.
13195: form - The form hash parameters that guide the interpretation of the resource
13196:
13197: retries - Number of retries allowed before giving up completely.
13198: Returns:
13199: On success, returns the rendered resource identified by the resource parameter.
13200: Side Effects:
13201: The following global variables can be set:
13202: ssi_error - If an unrecoverable error occurred this becomes true.
13203: It is up to the caller to initialize this to false
13204: if desired.
13205: ssi_error_resource - If an unrecoverable error occurred, this is the value
13206: of the resource that could not be rendered by the ssi
13207: call.
13208: ssi_error_message - The error string fetched from the ssi response
13209: in the event of an error.
13210:
13211:
13212: =head1 HANDLER SUBROUTINE
13213:
13214: ssi_with_retries()
13215:
13216: =head1 SUBROUTINES
13217:
13218: =over
13219:
1.671 raeburn 13220: =head1 Routines to display previous version of a Task for a specific student
13221:
13222: Tasks are graded pass/fail. Students who have yet to pass a particular Task
13223: can receive another opportunity. Access to tasks is slot-based. If a slot
13224: requires a proctor to check-in the student, a new version of the Task will
13225: be created when the student is checked in to the new opportunity.
13226:
13227: If a particular student has tried two or more versions of a particular task,
13228: the submission screen provides a user with vgr privileges (e.g., a Course
13229: Coordinator) the ability to display a previous version worked on by the
13230: student. By default, the current version is displayed. If a previous version
13231: has been selected for display, submission data are only shown that pertain
13232: to that particular version, and the interface to submit grades is not shown.
13233:
13234: =over 4
13235:
13236: =item show_previous_task_version()
13237:
13238: Displays a specified version of a student's Task, as the student sees it.
13239:
13240: Inputs: 2
13241: request - request object
13242: symb - unique symb for current instance of resource
13243:
13244: Output: None.
13245:
13246: Side Effects: calls &show_problem() to print version of Task, with
13247: version contained in form item: $env{'form.previousversion'}
13248:
13249: =item choose_task_version_form()
13250:
13251: Displays a web form used to select which version of a student's view of a
13252: Task should be displayed. Either launches a pop-up window, or replaces
13253: content in existing pop-up, or replaces page in main window.
13254:
13255: Inputs: 4
13256: symb - unique symb for current instance of resource
13257: uname - username of student
13258: udom - domain of student
13259: nomenu - 1 if display is in a pop-up window, and hence no menu
13260: breadcrumbs etc., are displayed
13261:
13262: Output: 4
13263: current - student's current version
13264: displayed - student's version being displayed
13265: result - scalar containing HTML for web form used to switch to
13266: a different version (or a link to close window, if pop-up).
13267: js - javascript for processing selection in versions web form
13268:
13269: Side Effects: None.
13270:
13271: =item previous_display_javascript()
13272:
13273: Inputs: 2
13274: nomenu - 1 if display is in a pop-up window, and hence no menu
13275: breadcrumbs etc., are displayed.
13276: current - student's current version number.
13277:
13278: Output: 1
13279: js - javascript for processing selection in versions web form.
13280:
13281: Side Effects: None.
13282:
13283: =back
13284:
13285: =head1 Routines to process bubblesheet data.
13286:
13287: =over 4
13288:
1.531 jms 13289: =item scantron_get_correction() :
13290:
13291: Builds the interface screen to interact with the operator to fix a
13292: specific error condition in a specific scanline
13293:
13294: Arguments:
13295: $r - Apache request object
13296: $i - number of the current scanline
13297: $scan_record - hash ref as returned from &scantron_parse_scanline()
1.758 raeburn 13298: $scan_config - hash ref as returned from &Apache::lonnet::get_scantron_config()
1.531 jms 13299: $line - full contents of the current scanline
13300: $error - error condition, valid values are
13301: 'incorrectCODE', 'duplicateCODE',
13302: 'doublebubble', 'missingbubble',
13303: 'duplicateID', 'incorrectID'
13304: $arg - extra information needed
13305: For errors:
13306: - duplicateID - paper number that this studentID was seen before on
13307: - duplicateCODE - array ref of the paper numbers this CODE was
13308: seen on before
13309: - incorrectCODE - current incorrect CODE
13310: - doublebubble - array ref of the bubble lines that have double
13311: bubble errors
13312: - missingbubble - array ref of the bubble lines that have missing
13313: bubble errors
13314:
1.788 raeburn 13315: $randomorder - True if exam folder (or a sub-folder) has randomorder set
13316: $randompick - True if exam folder (or a sub-folder) has randompick set
1.691 raeburn 13317: $respnumlookup - Reference to HASH mapping question numbers in bubble lines
13318: for current line to question number used for same question
13319: in "Master Seqence" (as seen by Course Coordinator).
13320: $startline - Reference to hash where key is question number (0 is first)
13321: and value is number of first bubble line for current student
13322: or code-based randompick and/or randomorder.
13323:
13324:
13325:
1.531 jms 13326: =item scantron_get_maxbubble() :
13327:
1.582 raeburn 13328: Arguments:
13329: $nav_error - Reference to scalar which is a flag to indicate a
13330: failure to retrieve a navmap object.
13331: if $nav_error is set to 1 by scantron_get_maxbubble(), the
13332: calling routine should trap the error condition and display the warning
13333: found in &navmap_errormsg().
13334:
1.649 raeburn 13335: $scantron_config - Reference to bubblesheet format configuration hash.
13336:
1.531 jms 13337: Returns the maximum number of bubble lines that are expected to
13338: occur. Does this by walking the selected sequence rendering the
13339: resource and then checking &Apache::lonxml::get_problem_counter()
13340: for what the current value of the problem counter is.
13341:
13342: Caches the results to $env{'form.scantron_maxbubble'},
13343: $env{'form.scantron.bubble_lines.n'},
13344: $env{'form.scantron.first_bubble_line.n'} and
13345: $env{"form.scantron.sub_bubblelines.n"}
1.691 raeburn 13346: which are the total number of bubble lines, the number of bubble
1.531 jms 13347: lines for response n and number of the first bubble line for response n,
13348: and a comma separated list of numbers of bubble lines for sub-questions
13349: (for optionresponse, matchresponse, and rankresponse items), for response n.
13350:
13351:
13352: =item scantron_validate_missingbubbles() :
13353:
13354: Validates all scanlines in the selected file to not have any
13355: answers that don't have bubbles that have not been verified
13356: to be bubble free.
13357:
13358: =item scantron_process_students() :
13359:
1.659 raeburn 13360: Routine that does the actual grading of the bubblesheet information.
1.531 jms 13361:
13362: The parsed scanline hash is added to %env
13363:
13364: Then foreach unskipped scanline it does an &Apache::lonnet::ssi()
13365: foreach resource , with the form data of
13366:
13367: 'submitted' =>'scantron'
13368: 'grade_target' =>'grade',
13369: 'grade_username'=> username of student
13370: 'grade_domain' => domain of student
13371: 'grade_courseid'=> of course
13372: 'grade_symb' => symb of resource to grade
13373:
13374: This triggers a grading pass. The problem grading code takes care
13375: of converting the bubbled letter information (now in %env) into a
13376: valid submission.
13377:
13378: =item scantron_upload_scantron_data() :
13379:
1.659 raeburn 13380: Creates the screen for adding a new bubblesheet data file to a course.
1.531 jms 13381:
13382: =item scantron_upload_scantron_data_save() :
13383:
13384: Adds a provided bubble information data file to the course if user
1.770 raeburn 13385: has the correct privileges to do so.
13386:
13387: = item scantron_upload_delete() :
13388:
13389: Deletes a previously uploaded bubble information data file, if user
13390: was the one who uploaded the file, and has the privileges to do so.
1.531 jms 13391:
13392: =item valid_file() :
13393:
13394: Validates that the requested bubble data file exists in the course.
13395:
13396: =item scantron_download_scantron_data() :
13397:
13398: Shows a list of the three internal files (original, corrected,
1.659 raeburn 13399: skipped) for a specific bubblesheet data file that exists in the
1.531 jms 13400: course.
13401:
13402: =item scantron_validate_ID() :
13403:
13404: Validates all scanlines in the selected file to not have any
1.556 weissno 13405: invalid or underspecified student/employee IDs
1.531 jms 13406:
1.582 raeburn 13407: =item navmap_errormsg() :
13408:
13409: Returns HTML mark-up inside a <div></div> with a link to re-initialize the course.
1.671 raeburn 13410: Should be called whenever the request to instantiate a navmap object fails.
13411:
13412: =back
1.582 raeburn 13413:
1.531 jms 13414: =back
13415:
13416: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>