Annotation of loncom/homework/grades.pm, revision 1.802
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.802 ! raeburn 4: # $Id: grades.pm,v 1.801 2024/12/09 22:22:57 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();
1266: my ($launcher,$appname,$setter,$linkuri,$linkprotector,$scope,$chosen);
1267: if ($env{'form.passback'} ne '') {
1268: $chosen = &unescape($env{'form.passback'});
1269: ($linkuri,$linkprotector,$scope) = split("\0",$chosen);
1270: ($launcher,$appname,$setter) = &get_passback_launcher($cdom,$cnum,$chosen);
1271: }
1272: if ($launcher ne '') {
1273: $request->print(&launcher_info_box($launcher,$appname,$setter,$linkuri,$scope));
1274: }
1275: my $error;
1276: if ($perm{'mgr'}) {
1277: if ($launcher ne '') {
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 $pbsymb = &Apache::loncommon::symb_from_tinyurl($linkuri,$cnum,$cdom);
1316: my $pbmap;
1317: if ($pbsymb =~ /\.(page|sequence)$/) {
1318: $pbmap = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($pbsymb))[2]);
1319: } else {
1320: $pbmap = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($pbsymb))[0]);
1321: }
1322: $pbmap = &Apache::lonnet::clutter($pbmap);
1323: my $pbscope;
1324: if ($scope eq 'res') {
1325: $pbscope = 'resource';
1326: } elsif ($scope eq 'map') {
1327: $pbscope = 'nonrec';
1328: } elsif ($scope eq 'rec') {
1329: $pbscope = 'map';
1330: }
1.798 raeburn 1331: my %pb = &common_passback_info();
1.796 raeburn 1332: my $numstudents = scalar(keys(%tosend));
1333: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($request,$numstudents);
1334: my $outcome = &Apache::loncommon::start_data_table().
1335: &Apache::loncommon::start_data_table_header_row();
1336: my $loop = 0;
1337: while ($loop < 2) {
1338: $outcome .= '<th>'.&mt('No.').'</th>'.
1339: '<th>'.&nameUserString('header').' '.&mt('Section/Group').'</th>'.
1340: '<th>'.&mt('Score').'</th>';
1341: $loop++;
1342: }
1343: $outcome .= &Apache::loncommon::end_data_table_header_row()."\n";
1344: my $ctr=0;
1345: foreach my $student (sort
1346: {
1347: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
1348: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
1349: }
1350: return $a cmp $b;
1351: } (keys(%$fullname))) {
1352: next unless ($tosend{$student});
1353: my ($uname,$udom) = split(/:/,$student);
1354: &Apache::lonhtmlcommon::Increment_PrgWin($request,\%prog_state,'last student');
1355: my ($uname,$udom) = split(/:/,$student);
1356: my $uhome = &Apache::lonnet::homeserver($uname,$udom),
1357: my $id = $passback{$student}[0],
1358: my $url = $passback{$student}[1],
1359: my ($total,$possible,$usec);
1360: if (ref($classlist->{$student}) eq 'ARRAY') {
1361: $usec = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION];
1362: }
1363: if ($pbscope eq 'resource') {
1364: $total = 0;
1365: $possible = 0;
1366: my $navmap = Apache::lonnavmaps::navmap->new($uname,$udom);
1367: if (ref($navmap)) {
1368: my $res = $navmap->getBySymb($pbsymb);
1369: if (ref($res)) {
1370: my $partlist = $res->parts();
1371: if (ref($partlist) eq 'ARRAY') {
1372: my %record = &Apache::lonnet::restore($pbsymb,$env{'request.course.id'},$udom,$uname);
1373: foreach my $part (@{$partlist}) {
1374: next if ($record{"resource.$part.solved"} =~/^excused/);
1375: my $weight = &Apache::lonnet::EXT("resource.$part.weight",$pbsymb,$udom,$uname,$usec);
1376: $possible += $weight;
1377: if (($record{'version'}) && (exists($record{"resource.$part.awarded"}))) {
1378: my $awarded = $record{"resource.$part.awarded"};
1379: if ($awarded) {
1380: $total += $weight * $awarded;
1381: }
1382: }
1383: }
1384: }
1385: }
1386: }
1387: } elsif (($pbscope eq 'map') || ($pbscope eq 'nonrec')) {
1388: ($total,$possible) =
1389: &Apache::lonhomework::get_lti_score($uname,$udom,$pbmap,$pbscope);
1390: }
1391: if (($id ne '') && ($url ne '') && ($possible)) {
1392: my ($sent,$score,$code,$result) =
1.798 raeburn 1393: &LONCAPA::ltiutils::send_grade($cdom,$cnum,$crsdef,$pb{'type'},$ltinum,$keynum,$id,
1394: $url,$scoretype,$pb{'sigmethod'},$msgformat,$total,$possible);
1.796 raeburn 1395: my $no_passback;
1396: if ($sent) {
1397: if ($code == 200) {
1398: delete($tosend{$student});
1399: my $namespace = $cdom.'_'.$cnum.'_lp_passback';
1400: my $store = {
1401: 'score' => $score,
1.798 raeburn 1402: 'ip' => $pb{'ip'},
1403: 'host' => $pb{'lonhost'},
1.796 raeburn 1404: 'protector' => $linkprotector,
1405: 'deeplink' => $linkuri,
1406: 'scope' => $scope,
1407: 'url' => $url,
1408: 'id' => $id,
1.798 raeburn 1409: 'clientip' => $pb{'clientip'},
1.796 raeburn 1410: 'whodoneit' => $env{'user.name'}.':'.$env{'user.domain'},
1411: };
1412: my $value='';
1413: foreach my $key (keys(%{$store})) {
1414: $value.=&escape($key).'='.&Apache::lonnet::freeze_escape($store->{$key}).'&';
1415: }
1416: $value=~s/\&$//;
1417: &Apache::lonnet::courselog(&escape($linkuri).':'.$uname.':'.$udom.':EXPORT:'.$value);
1.798 raeburn 1418: &Apache::lonnet::cstore({'score' => $score},$chosen,$namespace,$udom,$uname,'',$pb{'ip'},1);
1.796 raeburn 1419: $ctr++;
1420: if ($ctr%2 ==1) {
1421: $outcome .= &Apache::loncommon::start_data_table_row();
1422: }
1423: my $section = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
1424: my $group = $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1425: $outcome .= '<td align="right">'.$ctr.' </td>'.
1426: '<td>'.&nameUserString(undef,$$fullname{$student},$uname,$udom).
1427: ' '.$section.($group ne '' ?'/'.$group:'').'</td>'.
1428: '<td>'.$score.'</td>'."\n";
1429: if ($ctr%2 ==0) {
1430: $outcome .= &Apache::loncommon::end_data_table_row()."\n";
1431: }
1432: } else {
1433: $remotenotok{$student} = 1;
1434: $no_passback = "Passback response for ".$linkprotector." was $code ($result)";
1435: &Apache::lonnet::logthis($no_passback." for $uname:$udom in ${cdom}_${cnum}");
1436: }
1437: } else {
1438: $scorenotok{$student} = 1;
1439: $no_passback = "Passback of grades not sent for ".$linkprotector;
1440: &Apache::lonnet::logthis($no_passback." for $uname:$udom in ${cdom}_${cnum}");
1441: }
1442: if ($no_passback) {
1443: &Apache::lonnet::log($udom,$uname,$uhome,$no_passback." score: $score; total: $total; possible: $possible");
1444: my $ltigrade = {
1445: 'ltinum' => $ltinum,
1446: 'lti' => $lti_in_use,
1447: 'crsdef' => $crsdef,
1448: 'cid' => $cdom.'_'.$cnum,
1449: 'uname' => $uname,
1450: 'udom' => $udom,
1451: 'uhome' => $uhome,
1452: 'pbid' => $id,
1453: 'pburl' => $url,
1.798 raeburn 1454: 'pbtype' => $pb{'type'},
1.796 raeburn 1455: 'pbscope' => $pbscope,
1456: 'pbmap' => $pbmap,
1457: 'pbsymb' => $pbsymb,
1458: 'format' => $scoretype,
1459: 'scope' => $scope,
1.798 raeburn 1460: 'clientip' => $pb{'clientip'},
1.799 raeburn 1461: 'linkprot' => $linkprotector.':'.$linkuri,
1.796 raeburn 1462: 'total' => $total,
1463: 'possible' => $possible,
1464: 'score' => $score,
1465: };
1466: &Apache::lonnet::put('linkprot_passback_pending',$ltigrade,$cdom,$cnum);
1467: }
1468: } else {
1469: if (($id ne '') && ($url ne '')) {
1470: $zeroposs{$student} = 1;
1471: } else {
1472: $nopbinfo{$student} = 1;
1473: }
1474: }
1475: }
1476: &Apache::lonhtmlcommon::Close_PrgWin($request,\%prog_state);
1477: if ($ctr%2 ==1) {
1478: $outcome .= &Apache::loncommon::end_data_table_row();
1479: }
1480: $outcome .= &Apache::loncommon::end_data_table();
1481: if ($ctr) {
1482: $request->print('<p><br />'.&mt('Scores sent to launcher CMS').'</p>'.
1483: '<p>'.$outcome.'</p>');
1484: } else {
1485: $request->print('<p>'.&mt('No scores sent to launcher CMS').'</p>');
1486: }
1487: if (keys(%tosend)) {
1488: $request->print('<p>'.&mt('No scores sent for following'));
1489: my ($zeros,$nopbcreds,$noconfirm,$noscore);
1490: foreach my $student (sort
1491: {
1492: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
1493: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
1494: }
1495: return $a cmp $b;
1496: } (keys(%$fullname))) {
1497: next unless ($tosend{$student});
1498: my ($uname,$udom) = split(/:/,$student);
1499: my $line = '<li>'.&nameUserString(undef,$$fullname{$student},$uname,$udom).'</li>'."\n";
1500: if ($zeroposs{$student}) {
1501: $zeros .= $line;
1502: } elsif ($nopbinfo{$student}) {
1503: $nopbcreds .= $line;
1504: } elsif ($remotenotok{$student}) {
1505: $noconfirm .= $line;
1506: } elsif ($scorenotok{$student}) {
1507: $noscore .= $line;
1508: }
1509: }
1510: if ($zeros) {
1511: $request->print('<br />'.&mt('Total points possible was 0').':'.
1512: '<ul>'.$zeros.'</ul><br />');
1513: }
1514: if ($nopbcreds) {
1515: $request->print('<br />'.&mt('Missing unique identifier and/or passback location').':'.
1516: '<ul>'.$nopbcreds.'</ul><br />');
1517: }
1518: if ($noconfirm) {
1519: $request->print('<br />'.&mt('Score receipt not confirmed by receiving CMS').':'.
1520: '<ul>'.$noconfirm.'</ul><br />');
1521: }
1522: if ($noscore) {
1523: $request->print('<br />'.&mt('Score computation or transmission failed').':'.
1524: '<ul>'.$noscore.'</ul><br />');
1525: }
1526: $request->print('</p>');
1527: }
1528: } else {
1529: $error = &mt('Settings for deep-link launch target unavailable, so no scores were sent');
1530: }
1531: } else {
1532: $error = &mt('No available students for whom scores can be sent.');
1533: }
1534: } else {
1535: $error = &mt('Classlist could not be retrieved so no scores were sent.');
1536: }
1537: } else {
1538: $error = &mt('No students selected to receive scores so none were sent.');
1539: }
1540: } else {
1541: if ($env{'form.passback'}) {
1542: $error = &mt('Deep-link launch target was invalid so no scores were sent.');
1543: } else {
1544: $error = &mt('Deep-link launch target was missing so no scores were sent.');
1545: }
1546: }
1547: } else {
1548: $error = &mt('You do not have permission to manage grades, so no scores were sent');
1549: }
1550: if ($error) {
1551: $request->print('<p class="LC_info">'.$error.'</p>');
1552: }
1553: return;
1554: }
1555:
1556: sub get_passback_launcher {
1557: my ($cdom,$cnum,$chosen) = @_;
1558: my ($linkuri,$linkprotector,$scope) = split("\0",$chosen);
1559: my ($ltinum,$ltitype) = ($linkprotector =~ /^(\d+)(c|d)$/);
1560: my ($appname,$setter);
1561: if ($ltitype eq 'c') {
1562: my %lti = &Apache::lonnet::get_course_lti($cnum,$cdom,'provider');
1563: if (ref($lti{$ltinum}) eq 'HASH') {
1564: $appname = $lti{$ltinum}{'name'};
1565: if ($appname) {
1566: $setter = ' (defined in course)';
1567: }
1568: }
1569: } elsif ($ltitype eq 'd') {
1570: my %lti = &Apache::lonnet::get_domain_lti($cdom,'linkprot');
1571: if (ref($lti{$ltinum}) eq 'HASH') {
1572: $appname = $lti{$ltinum}{'name'};
1573: if ($appname) {
1574: $setter = ' (defined in domain)';
1575: }
1576: }
1577: }
1578: if ($linkuri =~ m{^\Q/tiny/$cdom/\E(\w+)$}) {
1579: my $key = $1;
1580: my $tinyurl;
1581: my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$cdom."\0".$key);
1582: if (defined($cached)) {
1583: $tinyurl = $result;
1584: } else {
1585: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
1586: my %currtiny = &Apache::lonnet::get('tiny',[$key],$cdom,$configuname);
1587: if ($currtiny{$key} ne '') {
1588: $tinyurl = $currtiny{$key};
1589: &Apache::lonnet::do_cache_new('tiny',$cdom."\0".$key,$currtiny{$key},600);
1590: }
1591: }
1592: if ($tinyurl) {
1593: my ($crsnum,$launchsymb) = split(/\&/,$tinyurl);
1594: if ($crsnum eq $cnum) {
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})) {
1.798 raeburn 1598: return ($launchsymb,$appname,$setter);
1.796 raeburn 1599: }
1600: }
1601: }
1602: }
1603: }
1604: return ();
1605: }
1606:
1607: sub sections_and_groups {
1608: my (@sections,@groups,$group_display);
1609: @groups = &Apache::loncommon::get_env_multiple('form.group');
1610: if (grep(/^all$/,@groups)) {
1611: @groups = ('all');
1612: $group_display = 'all';
1613: } elsif (grep(/^none$/,@groups)) {
1614: @groups = ('none');
1615: $group_display = 'none';
1616: } elsif (@groups > 0) {
1617: $group_display = join(', ',@groups);
1618: }
1619: if ($env{'request.course.sec'} ne '') {
1620: @sections = ($env{'request.course.sec'});
1621: } else {
1622: @sections = &Apache::loncommon::get_env_multiple('form.section');
1623: }
1624: my $disabled = ' disabled="disabled"';
1625: if ($perm{'mgr'}) {
1626: if (grep(/^all$/,@sections)) {
1627: undef($disabled);
1628: } else {
1629: foreach my $sec (@sections) {
1630: if (&canmodify($sec)) {
1631: undef($disabled);
1632: last;
1633: }
1634: }
1635: }
1636: }
1637: if (grep(/^all$/,@sections)) {
1638: @sections = ('all');
1639: }
1640: return(\@sections,\@groups,$group_display,$disabled);
1641: }
1642:
1643: sub launcher_info_box {
1644: my ($launcher,$appname,$setter,$linkuri,$scope) = @_;
1645: my $shownscope;
1646: if ($scope eq 'res') {
1647: $shownscope = &mt('Resource');
1648: } elsif ($scope eq 'map') {
1649: $shownscope = &mt('Folder');
1650: } elsif ($scope eq 'rec') {
1651: $shownscope = &mt('Folder + sub-folders');
1652: }
1653: return '<p>'.
1654: &Apache::lonhtmlcommon::start_pick_box().
1655: &Apache::lonhtmlcommon::row_title(&mt('Launch Item Title')).
1.797 raeburn 1656: &Apache::lonnet::gettitle($launcher).
1.796 raeburn 1657: &Apache::lonhtmlcommon::row_closure().
1658: &Apache::lonhtmlcommon::row_title(&mt('Deep-link')).
1659: $linkuri.
1660: &Apache::lonhtmlcommon::row_closure().
1661: &Apache::lonhtmlcommon::row_title(&mt('Launcher')).
1662: $appname.' '.$setter.
1663: &Apache::lonhtmlcommon::row_closure().
1664: &Apache::lonhtmlcommon::row_title(&mt('Score Type')).
1665: $shownscope.
1666: &Apache::lonhtmlcommon::row_closure(1).
1667: &Apache::lonhtmlcommon::end_pick_box().'</p>'."\n";
1668: }
1669:
1.798 raeburn 1670: sub passbacks_for_symb {
1671: my ($cdom,$cnum,$symb) = @_;
1672: my %passback = &Apache::lonnet::dump('nohist_linkprot_passback',$cdom,$cnum);
1673: my %needpb;
1674: if (keys(%passback)) {
1675: my $checkpb = 1;
1676: if (exists($passback{$symb})) {
1677: if (keys(%passback) == 1) {
1678: undef($checkpb);
1679: }
1680: if (ref($passback{$symb}) eq 'HASH') {
1681: foreach my $launcher (keys(%{$passback{$symb}})) {
1682: $needpb{$launcher} = 1;
1683: }
1684: }
1685: }
1686: if ($checkpb) {
1687: my ($map,$id,$url) = &Apache::lonnet::decode_symb($symb);
1688: my $navmap = Apache::lonnavmaps::navmap->new();
1689: if (ref($navmap)) {
1690: my $mapres = $navmap->getResourceByUrl($map);
1691: if (ref($mapres)) {
1692: my $mapsymb = $mapres->symb();
1693: if (exists($passback{$mapsymb})) {
1694: if (keys(%passback) == 1) {
1695: undef($checkpb);
1696: }
1697: if (ref($passback{$mapsymb}) eq 'HASH') {
1698: foreach my $launcher (keys(%{$passback{$mapsymb}})) {
1699: $needpb{$launcher} = 1;
1700: }
1701: }
1702: }
1703: my %posspb;
1704: if ($checkpb) {
1705: my @recurseup = $navmap->recurseup_maps($map,1);
1706: if (@recurseup) {
1707: map { $posspb{$_} = 1; } @recurseup;
1708: }
1709: }
1710: foreach my $key (keys(%passback)) {
1711: if (exists($posspb{$key})) {
1712: if (ref($passback{$key}) eq 'HASH') {
1713: foreach my $launcher (keys(%{$passback{$key}})) {
1714: my ($linkuri,$linkprotector,$scope) = split("\0",$launcher);
1715: next unless ($scope eq 'rec');
1716: $needpb{$launcher} = 1;
1717: }
1718: }
1719: }
1720: }
1721: }
1722: }
1723: }
1724: }
1725: return %needpb;
1726: }
1727:
1728: sub process_passbacks {
1.802 ! raeburn 1729: my ($context,$symbs,$cdom,$cnum,$udom,$uname,$usec,$weights,$awardeds,$excuseds,$needpb,
1.798 raeburn 1730: $skip_passback,$pbsave,$pbids) = @_;
1731: if ((ref($needpb) eq 'HASH') && (ref($skip_passback) eq 'HASH') && (ref($pbsave) eq 'HASH')) {
1732: my (%weight,%awarded,%excused);
1733: if ((ref($symbs) eq 'ARRAY') && (ref($weights) eq 'HASH') && (ref($awardeds) eq 'HASH') &&
1734: (ref($excuseds) eq 'HASH')) {
1735: %weight = %{$weights};
1736: %awarded = %{$awardeds};
1737: %excused = %{$excuseds};
1738: }
1739: my $uhome = &Apache::lonnet::homeserver($uname,$udom);
1740: my @launchers = keys(%{$needpb});
1741: my %pbinfo;
1742: if (ref($pbids) eq 'HASH') {
1743: %pbinfo = %{$pbids};
1744: } else {
1745: %pbinfo = &Apache::lonnet::get('nohist_'.$cdom.'_'.$cnum.'_linkprot_pb',\@launchers,$udom,$uname);
1746: }
1747: my %pbc = &common_passback_info();
1748: foreach my $launcher (@launchers) {
1749: if (ref($pbinfo{$launcher}) eq 'ARRAY') {
1750: my $pbid = $pbinfo{$launcher}[0];
1751: my $pburl = $pbinfo{$launcher}[1];
1752: my (%total_by_symb,%possible_by_symb);
1753: if (($pbid ne '') && ($pburl ne '')) {
1754: next if ($skip_passback->{$launcher});
1755: my %pb = %pbc;
1756: if ((exists($pbsave->{$launcher})) &&
1757: (ref($pbsave->{$launcher}) eq 'HASH')) {
1758: foreach my $item ('lti_in_use','crsdef','ltinum','keynum','scoretype','msgformat',
1759: 'symb','map','pbscope','linkuri','linkprotector','scope') {
1760: $pb{$item} = $pbsave->{$launcher}{$item};
1761: }
1762: } else {
1763: my $ltitype;
1764: ($pb{'linkuri'},$pb{'linkprotector'},$pb{'scope'}) = split("\0",$launcher);
1765: ($pb{'ltinum'},$ltitype) = ($pb{'linkprotector'} =~ /^(\d+)(c|d)$/);
1766: if ($ltitype eq 'c') {
1767: my %crslti = &Apache::lonnet::get_course_lti($cnum,$cdom,'provider');
1768: $pb{'lti_in_use'} = $crslti{$pb{'ltinum'}};
1769: $pb{'crsdef'} = 1;
1770: } else {
1771: my %domlti = &Apache::lonnet::get_domain_lti($cdom,'linkprot');
1772: $pb{'lti_in_use'} = $domlti{$pb{'ltinum'}};
1773: }
1774: if (ref($pb{'lti_in_use'}) eq 'HASH') {
1775: $pb{'msgformat'} = $pb{'lti_in_use'}->{'passbackformat'};
1776: $pb{'keynum'} = $pb{'lti_in_use'}->{'cipher'};
1777: $pb{'scoretype'} = 'decimal';
1778: if ($pb{'lti_in_use'}->{'scoreformat'} =~ /^(decimal|ratio|percentage)$/) {
1779: $pb{'scoretype'} = $1;
1780: }
1781: $pb{'symb'} = &Apache::loncommon::symb_from_tinyurl($pb{'linkuri'},$cnum,$cdom);
1782: if ($pb{'symb'} =~ /\.(page|sequence)$/) {
1783: $pb{'map'} = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($pb{'symb'}))[2]);
1784: } else {
1785: $pb{'map'} = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($pb{'symb'}))[0]);
1786: }
1787: $pb{'map'} = &Apache::lonnet::clutter($pb{'map'});
1788: if ($pb{'scope'} eq 'res') {
1789: $pb{'pbscope'} = 'resource';
1790: } elsif ($pb{'scope'} eq 'map') {
1791: $pb{'pbscope'} = 'nonrec';
1792: } elsif ($pb{'scope'} eq 'rec') {
1793: $pb{'pbscope'} = 'map';
1794: }
1795: foreach my $item ('lti_in_use','crsdef','ltinum','keynum','scoretype','msgformat',
1796: 'symb','map','pbscope','linkuri','linkprotector','scope') {
1797: $pbsave->{$launcher}{$item} = $pb{$item};
1798: }
1799: } else {
1800: $skip_passback->{$launcher} = 1;
1801: }
1802: }
1803: if (ref($symbs) eq 'ARRAY') {
1804: foreach my $symb (@{$symbs}) {
1805: if ((ref($weight{$symb}) eq 'HASH') && (ref($awarded{$symb}) eq 'HASH') &&
1806: (ref($excused{$symb}) eq 'HASH')) {
1807: foreach my $part (keys(%{$weight{$symb}})) {
1808: if ($excused{$symb}{$part}) {
1809: next;
1810: }
1811: my $partweight = $weight{$symb}{$part} eq '' ? 1 :
1812: $weight{$symb}{$part};
1813: if ($awarded{$symb}{$part}) {
1814: $total_by_symb{$symb} += $partweight * $awarded{$symb}{$part};
1815: }
1816: $possible_by_symb{$symb} += $partweight;
1817: }
1818: }
1819: }
1820: }
1821: if ($context eq 'updatebypage') {
1822: my $ltigrade = {
1823: 'ltinum' => $pb{'ltinum'},
1824: 'lti' => $pb{'lti_in_use'},
1825: 'crsdef' => $pb{'crsdef'},
1826: 'cid' => $cdom.'_'.$cnum,
1827: 'uname' => $uname,
1828: 'udom' => $udom,
1829: 'uhome' => $uhome,
1.802 ! raeburn 1830: 'usec' => $usec,
1.798 raeburn 1831: 'pbid' => $pbid,
1832: 'pburl' => $pburl,
1833: 'pbtype' => $pb{'type'},
1834: 'pbscope' => $pb{'pbscope'},
1835: 'pbmap' => $pb{'map'},
1836: 'pbsymb' => $pb{'symb'},
1837: 'format' => $pb{'scoretype'},
1838: 'scope' => $pb{'scope'},
1839: 'clientip' => $pb{'clientip'},
1.799 raeburn 1840: 'linkprot' => $pb{'linkprotector'}.':'.$pb{'linkuri'},
1.798 raeburn 1841: 'total_s' => \%total_by_symb,
1842: 'possible_s' => \%possible_by_symb,
1843: };
1.801 raeburn 1844: push(@Apache::grades::ltipassback,$ltigrade);
1.798 raeburn 1845: next;
1846: }
1847: my ($total,$possible);
1848: if ($pb{'pbscope'} eq 'resource') {
1849: $total = $total_by_symb{$pb{'symb'}};
1850: $possible = $possible_by_symb{$pb{'symb'}};
1851: } elsif (($pb{'pbscope'} eq 'map') || ($pb{'pbscope'} eq 'nonrec')) {
1852: ($total,$possible) =
1853: &Apache::lonhomework::get_lti_score($uname,$udom,$pb{'map'},$pb{'pbscope'},
1854: \%total_by_symb,\%possible_by_symb);
1855: }
1856: if (!$possible) {
1857: $total = 0;
1858: $possible = 1;
1859: }
1860: my ($sent,$score,$code,$result) =
1861: &LONCAPA::ltiutils::send_grade($cdom,$cnum,$pb{'crsdef'},$pb{'type'},$pb{'ltinum'},
1862: $pb{'keynum'},$pbid,$pburl,$pb{'scoretype'},$pb{'sigmethod'},
1863: $pb{'msgformat'},$total,$possible);
1864: my $no_passback;
1865: if ($sent) {
1866: if ($code == 200) {
1867: my $namespace = $cdom.'_'.$cnum.'_lp_passback';
1868: my $store = {
1869: 'score' => $score,
1870: 'ip' => $pb{'ip'},
1871: 'host' => $pb{'lonhost'},
1872: 'protector' => $pb{'linkprotector'},
1873: 'deeplink' => $pb{'linkuri'},
1874: 'scope' => $pb{'scope'},
1875: 'url' => $pburl,
1876: 'id' => $pbid,
1877: 'clientip' => $pb{'clientip'},
1878: 'whodoneit' => $env{'user.name'}.':'.$env{'user.domain'},
1879: };
1880: my $value='';
1881: foreach my $key (keys(%{$store})) {
1882: $value.=&escape($key).'='.&Apache::lonnet::freeze_escape($store->{$key}).'&';
1883: }
1884: $value=~s/\&$//;
1885: &Apache::lonnet::courselog(&escape($pb{'linkuri'}).':'.$uname.':'.$udom.':EXPORT:'.$value);
1886: &Apache::lonnet::cstore({'score' => $score},$launcher,$namespace,$udom,$uname,'',$pb{'ip'},1);
1887: } else {
1888: $no_passback = 1;
1889: }
1890: } else {
1891: $no_passback = 1;
1892: }
1893: if ($no_passback) {
1894: &Apache::lonnet::log($udom,$uname,$uhome,$no_passback." score: $score; total: $total; possible: $possible");
1895: my $ltigrade = {
1896: 'ltinum' => $pb{'ltinum'},
1897: 'lti' => $pb{'lti_in_use'},
1898: 'crsdef' => $pb{'crsdef'},
1899: 'cid' => $cdom.'_'.$cnum,
1900: 'uname' => $uname,
1901: 'udom' => $udom,
1902: 'uhome' => $uhome,
1903: 'pbid' => $pbid,
1904: 'pburl' => $pburl,
1905: 'pbtype' => $pb{'type'},
1906: 'pbscope' => $pb{'pbscope'},
1907: 'pbmap' => $pb{'map'},
1908: 'pbsymb' => $pb{'symb'},
1909: 'format' => $pb{'scoretype'},
1910: 'scope' => $pb{'scope'},
1911: 'clientip' => $pb{'clientip'},
1.799 raeburn 1912: 'linkprot' => $pb{'linkprotector'}.':'.$pb{'linkuri'},
1.798 raeburn 1913: 'total' => $total,
1914: 'possible' => $possible,
1915: 'score' => $score,
1916: };
1917: &Apache::lonnet::put('linkprot_passback_pending',$ltigrade,$cdom,$cnum);
1918: }
1919: }
1920: }
1921: }
1922: }
1923: return;
1924: }
1925:
1926: sub common_passback_info {
1927: my %pbc = (
1928: sigmethod => 'HMAC-SHA1',
1929: type => 'linkprot',
1930: clientip => &Apache::lonnet::get_requestor_ip(),
1931: lonhost => $Apache::lonnet::perlvar{'lonHostID'},
1932: ip => &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}),
1933: );
1934: return %pbc;
1935: }
1936:
1.44 ng 1937: #--- This is called by a number of programs.
1938: #--- Called from the Grading Menu - View/Grade an individual student
1939: #--- Also called directly when one clicks on the subm button
1940: # on the problem page.
1.30 ng 1941: sub listStudents {
1.773 raeburn 1942: my ($request,$symb,$submitonly,$divforres) = @_;
1.49 albertel 1943:
1.747 raeburn 1944: my $is_tool = ($symb =~ /ext\.tool$/);
1.257 albertel 1945: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
1946: my $cnum = $env{"course.$env{'request.course.id'}.num"};
1947: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.449 banghart 1948: my $getgroup = $env{'form.group'} eq '' ? 'all' : $env{'form.group'};
1.617 www 1949: unless ($submitonly) {
1.766 raeburn 1950: $submitonly = $env{'form.submitonly'} eq '' ? 'all' : $env{'form.submitonly'};
1.617 www 1951: }
1.49 albertel 1952:
1.632 www 1953: my $result='';
1.623 www 1954: my $res_error;
1.773 raeburn 1955: my ($partlist,$handgrade,$responseType,$numresp,$numessay) = &response_type($symb,\$res_error);
1956:
1957: my $table;
1958: if (ref($partlist) eq 'ARRAY') {
1959: if (scalar(@$partlist) > 1 ) {
1960: $table = &showResourceInfo($symb,$partlist,$responseType,'gradesub',1);
1961: } elsif ($divforres) {
1962: $table = '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1963: } else {
1964: $table = '<br clear="all" />';
1965: }
1966: }
1.49 albertel 1967:
1.796 raeburn 1968: $request->print(&checkselect_js());
1.597 wenzelju 1969: $request->print(&Apache::lonhtmlcommon::scripttag(<<LISTJAVASCRIPT));
1.110 ng 1970:
1971: function reLoadList(formname) {
1.112 ng 1972: if (formname.saveStatusOld.value == pullDownSelection(formname.Status)) {return;}
1.110 ng 1973: formname.command.value = 'submission';
1974: formname.submit();
1975: }
1.45 ng 1976: LISTJAVASCRIPT
1977:
1.118 ng 1978: &commonJSfunctions($request);
1.41 ng 1979: $request->print($result);
1.39 ng 1980:
1.154 albertel 1981: my $gradeTable='<form action="/adm/grades" method="post" name="gradesub">'.
1.773 raeburn 1982: "\n".$table;
1983:
1.561 bisitz 1984: $gradeTable .= &Apache::lonhtmlcommon::start_pick_box();
1.745 raeburn 1985: unless ($is_tool) {
1986: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Problem Text'))
1987: .'<label><input type="radio" name="vProb" value="no" checked="checked" /> '.&mt('no').' </label>'."\n"
1988: .'<label><input type="radio" name="vProb" value="yes" /> '.&mt('one student').' </label>'."\n"
1989: .'<label><input type="radio" name="vProb" value="all" /> '.&mt('all students').' </label><br />'."\n"
1990: .&Apache::lonhtmlcommon::row_closure();
1991: $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Answer'))
1992: .'<label><input type="radio" name="vAns" value="no" /> '.&mt('no').' </label>'."\n"
1993: .'<label><input type="radio" name="vAns" value="yes" /> '.&mt('one student').' </label>'."\n"
1994: .'<label><input type="radio" name="vAns" value="all" checked="checked" /> '.&mt('all students').' </label><br />'."\n"
1995: .&Apache::lonhtmlcommon::row_closure();
1996: }
1.485 albertel 1997:
1.442 banghart 1998: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1999: my $saveStatus = $stu_status eq '' ? 'Active' : $stu_status;
1.257 albertel 2000: $env{'form.Status'} = $saveStatus;
1.745 raeburn 2001: my %optiontext;
2002: if ($is_tool) {
2003: %optiontext = &Apache::lonlocal::texthash (
2004: lastonly => 'last transaction',
2005: last => 'last transaction with details',
2006: datesub => 'all transactions',
2007: all => 'all transactions with details',
2008: );
2009: } else {
2010: %optiontext = &Apache::lonlocal::texthash (
2011: lastonly => 'last submission',
2012: last => 'last submission with details',
2013: datesub => 'all submissions',
2014: all => 'all submissions with details',
2015: );
2016: }
1.773 raeburn 2017: my $submission_options =
1.592 bisitz 2018: '<span class="LC_nobreak">'.
1.624 www 2019: '<label><input type="radio" name="lastSub" value="lastonly" /> '.
1.745 raeburn 2020: $optiontext{'lastonly'}.' </label></span>'."\n".
1.592 bisitz 2021: '<span class="LC_nobreak">'.
2022: '<label><input type="radio" name="lastSub" value="last" /> '.
1.745 raeburn 2023: $optiontext{'last'}.' </label></span>'."\n".
1.592 bisitz 2024: '<span class="LC_nobreak">'.
1.628 www 2025: '<label><input type="radio" name="lastSub" value="datesub" checked="checked" /> '.
1.745 raeburn 2026: $optiontext{'datesub'}.'</label></span>'."\n".
1.592 bisitz 2027: '<span class="LC_nobreak">'.
2028: '<label><input type="radio" name="lastSub" value="all" /> '.
1.745 raeburn 2029: $optiontext{'all'}.'</label></span>';
2030: my $viewtitle;
2031: if ($is_tool) {
2032: $viewtitle = &mt('View Transactions');
2033: } else {
2034: $viewtitle = &mt('View Submissions');
2035: }
1.773 raeburn 2036: my ($compmsg,$nocompmsg);
2037: $nocompmsg = ' checked="checked"';
2038: if ($numessay) {
2039: $compmsg = $nocompmsg;
2040: $nocompmsg = '';
2041: }
1.745 raeburn 2042: $gradeTable .= &Apache::lonhtmlcommon::row_title($viewtitle)
1.780 raeburn 2043: .$submission_options;
2044: # Check if any gradable
2045: my $showmore;
2046: if ($perm{'mgr'}) {
2047: my @sections;
2048: if ($env{'request.course.sec'} ne '') {
2049: @sections = ($env{'request.course.sec'});
1.783 raeburn 2050: } elsif ($env{'form.section'} eq '') {
2051: @sections = ('all');
1.780 raeburn 2052: } else {
2053: @sections = &Apache::loncommon::get_env_multiple('form.section');
2054: }
2055: if (grep(/^all$/,@sections)) {
2056: $showmore = 1;
2057: } else {
2058: foreach my $sec (@sections) {
2059: if (&canmodify($sec)) {
2060: $showmore = 1;
2061: last;
2062: }
2063: }
2064: }
2065: }
2066:
2067: if ($showmore) {
2068: $gradeTable .=
2069: &Apache::lonhtmlcommon::row_closure()
1.773 raeburn 2070: .&Apache::lonhtmlcommon::row_title(&mt('Send Messages'))
2071: .'<span class="LC_nobreak">'
2072: .'<label><input type="radio" name="compmsg" value="0"'.$nocompmsg.' />'
2073: .&mt('No').(' 'x2).'</label>'
2074: .'<label><input type="radio" name="compmsg" value="1"'.$compmsg.' />'
2075: .&mt('Yes').(' 'x2).'</label>'
1.561 bisitz 2076: .&Apache::lonhtmlcommon::row_closure();
2077:
1.780 raeburn 2078: $gradeTable .=
2079: &Apache::lonhtmlcommon::row_title(&mt('Grading Increments'))
1.561 bisitz 2080: .'<select name="increment">'
2081: .'<option value="1">'.&mt('Whole Points').'</option>'
2082: .'<option value=".5">'.&mt('Half Points').'</option>'
2083: .'<option value=".25">'.&mt('Quarter Points').'</option>'
2084: .'<option value=".1">'.&mt('Tenths of a Point').'</option>'
1.773 raeburn 2085: .'</select>';
1.780 raeburn 2086: }
1.485 albertel 2087: $gradeTable .=
1.432 banghart 2088: &build_section_inputs().
1.45 ng 2089: '<input type="hidden" name="submitonly" value="'.$submitonly.'" />'."\n".
1.418 albertel 2090: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.110 ng 2091: '<input type="hidden" name="saveStatusOld" value="'.$saveStatus.'" />'."\n";
1.618 www 2092: if (exists($env{'form.Status'})) {
1.784 raeburn 2093: $gradeTable .= '<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n";
1.124 ng 2094: } else {
1.773 raeburn 2095: $gradeTable .= &Apache::lonhtmlcommon::row_closure()
2096: .&Apache::lonhtmlcommon::row_title(&mt('Student Status'))
1.561 bisitz 2097: .&Apache::lonhtmlcommon::StatusOptions(
1.773 raeburn 2098: $saveStatus,undef,1,'javascript:reLoadList(this.form);');
1.124 ng 2099: }
1.773 raeburn 2100: if ($numessay) {
2101: $gradeTable .= &Apache::lonhtmlcommon::row_closure()
2102: .&Apache::lonhtmlcommon::row_title(&mt('Check For Plagiarism'))
2103: .'<input type="checkbox" name="checkPlag" checked="checked" />';
1.745 raeburn 2104: }
1.773 raeburn 2105: $gradeTable .= &Apache::lonhtmlcommon::row_closure(1)
2106: .&Apache::lonhtmlcommon::end_pick_box();
1.745 raeburn 2107: my $regrademsg;
2108: if ($is_tool) {
2109: $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.");
2110: } else {
2111: $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.");
2112: }
1.561 bisitz 2113: $gradeTable .= '<p>'
1.745 raeburn 2114: .$regrademsg."\n"
1.561 bisitz 2115: .'<input type="hidden" name="command" value="processGroup" />'
2116: .'</p>';
1.249 albertel 2117:
2118: # checkall buttons
2119: $gradeTable.=&check_script('gradesub', 'stuinfo');
1.110 ng 2120: $gradeTable.='<input type="button" '."\n".
1.589 bisitz 2121: 'onclick="javascript:checkSelect(this.form.stuinfo);" '."\n".
2122: 'value="'.&mt('Next').' →" /> <br />'."\n";
1.249 albertel 2123: $gradeTable.=&check_buttons();
1.450 banghart 2124: my ($classlist, undef, $fullname) = &getclasslist($getsec,'1',$getgroup);
1.474 albertel 2125: $gradeTable.= &Apache::loncommon::start_data_table().
2126: &Apache::loncommon::start_data_table_header_row();
1.110 ng 2127: my $loop = 0;
2128: while ($loop < 2) {
1.485 albertel 2129: $gradeTable.='<th>'.&mt('No.').'</th><th>'.&mt('Select').'</th>'.
2130: '<th>'.&nameUserString('header').' '.&mt('Section/Group').'</th>';
1.618 www 2131: if (($submitonly ne 'queued') && ($submitonly ne 'all')) {
1.485 albertel 2132: foreach my $part (sort(@$partlist)) {
2133: my $display_part=
2134: &get_display_part((split(/_/,$part))[0],$symb);
2135: $gradeTable.=
2136: '<th>'.&mt('Part: [_1] Status',$display_part).'</th>';
1.110 ng 2137: }
1.301 albertel 2138: } elsif ($submitonly eq 'queued') {
1.474 albertel 2139: $gradeTable.='<th>'.&mt('Queue Status').' </th>';
1.110 ng 2140: }
2141: $loop++;
1.126 ng 2142: # $gradeTable.='<td></td>' if ($loop%2 ==1);
1.41 ng 2143: }
1.474 albertel 2144: $gradeTable.=&Apache::loncommon::end_data_table_header_row()."\n";
1.41 ng 2145:
1.45 ng 2146: my $ctr = 0;
1.294 albertel 2147: foreach my $student (sort
2148: {
2149: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
2150: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
2151: }
2152: return $a cmp $b;
2153: }
2154: (keys(%$fullname))) {
1.41 ng 2155: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 2156:
1.110 ng 2157: my %status = ();
1.301 albertel 2158:
2159: if ($submitonly eq 'queued') {
2160: my %queue_status =
2161: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
2162: $udom,$uname);
2163: next if (!defined($queue_status{'gradingqueue'}));
2164: $status{'gradingqueue'} = $queue_status{'gradingqueue'};
2165: }
2166:
1.618 www 2167: if (($submitonly ne 'queued') && ($submitonly ne 'all')) {
1.324 albertel 2168: (%status) =&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 2169: my $submitted = 0;
1.164 albertel 2170: my $graded = 0;
1.248 albertel 2171: my $incorrect = 0;
1.110 ng 2172: foreach (keys(%status)) {
1.145 albertel 2173: $submitted = 1 if ($status{$_} ne 'nothing');
1.248 albertel 2174: $graded = 1 if ($status{$_} =~ /^ungraded/);
2175: $incorrect = 1 if ($status{$_} =~ /^incorrect/);
2176:
1.110 ng 2177: my ($foo,$partid,$foo1) = split(/\./,$_);
2178: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
1.145 albertel 2179: $submitted = 0;
1.150 albertel 2180: my ($part)=split(/\./,$partid);
1.110 ng 2181: $gradeTable.='<input type="hidden" name="'.
1.150 albertel 2182: $student.':'.$part.':submitted_by" value="'.
1.110 ng 2183: $status{'resource.'.$partid.'.submitted_by'}.'" />';
2184: }
1.41 ng 2185: }
1.248 albertel 2186:
1.156 albertel 2187: next if (!$submitted && ($submitonly eq 'yes' ||
2188: $submitonly eq 'incorrect' ||
2189: $submitonly eq 'graded'));
1.248 albertel 2190: next if (!$graded && ($submitonly eq 'graded'));
2191: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 2192: }
1.34 ng 2193:
1.45 ng 2194: $ctr++;
1.249 albertel 2195: my $section = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
1.452 banghart 2196: my $group = $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1.104 albertel 2197: if ( $perm{'vgr'} eq 'F' ) {
1.474 albertel 2198: if ($ctr%2 ==1) {
2199: $gradeTable.= &Apache::loncommon::start_data_table_row();
2200: }
1.126 ng 2201: $gradeTable.='<td align="right">'.$ctr.' </td>'.
1.563 bisitz 2202: '<td align="center"><label><input type="checkbox" name="stuinfo" value="'.
1.249 albertel 2203: $student.':'.$$fullname{$student}.':::SECTION'.$section.
2204: ') " /> </label></td>'."\n".'<td>'.
2205: &nameUserString(undef,$$fullname{$student},$uname,$udom).
1.474 albertel 2206: ' '.$section.($group ne '' ?'/'.$group:'').'</td>'."\n";
1.110 ng 2207:
1.618 www 2208: if ($submitonly ne 'all') {
1.524 raeburn 2209: foreach (sort(keys(%status))) {
1.485 albertel 2210: next if ($_ =~ /^resource.*?submitted_by$/);
2211: $gradeTable.='<td align="center"> '.&mt($status{$_}).' </td>'."\n";
1.110 ng 2212: }
1.41 ng 2213: }
1.126 ng 2214: # $gradeTable.='<td></td>' if ($ctr%2 ==1);
1.474 albertel 2215: if ($ctr%2 ==0) {
2216: $gradeTable.=&Apache::loncommon::end_data_table_row()."\n";
2217: }
1.41 ng 2218: }
2219: }
1.110 ng 2220: if ($ctr%2 ==1) {
1.126 ng 2221: $gradeTable.='<td> </td><td> </td><td> </td>';
1.618 www 2222: if (($submitonly ne 'queued') && ($submitonly ne 'all')) {
1.110 ng 2223: foreach (@$partlist) {
2224: $gradeTable.='<td> </td>';
2225: }
1.301 albertel 2226: } elsif ($submitonly eq 'queued') {
2227: $gradeTable.='<td> </td>';
1.110 ng 2228: }
1.474 albertel 2229: $gradeTable.=&Apache::loncommon::end_data_table_row();
1.110 ng 2230: }
2231:
1.474 albertel 2232: $gradeTable.=&Apache::loncommon::end_data_table()."\n".
1.589 bisitz 2233: '<input type="button" '.
2234: 'onclick="javascript:checkSelect(this.form.stuinfo);" '.
2235: 'value="'.&mt('Next').' →" /></form>'."\n";
1.45 ng 2236: if ($ctr == 0) {
1.96 albertel 2237: my $num_students=(scalar(keys(%$fullname)));
2238: if ($num_students eq 0) {
1.485 albertel 2239: $gradeTable='<br /> <span class="LC_warning">'.&mt('There are no students currently enrolled.').'</span>';
1.96 albertel 2240: } else {
1.171 albertel 2241: my $submissions='submissions';
2242: if ($submitonly eq 'incorrect') { $submissions = 'incorrect submissions'; }
2243: if ($submitonly eq 'graded' ) { $submissions = 'ungraded submissions'; }
1.301 albertel 2244: if ($submitonly eq 'queued' ) { $submissions = 'queued submissions'; }
1.398 albertel 2245: $gradeTable='<br /> <span class="LC_warning">'.
1.709 bisitz 2246: &mt('No '.$submissions.' found for this resource for any students. ([quant,_1,student] checked for '.$submissions.')',
1.485 albertel 2247: $num_students).
2248: '</span><br />';
1.96 albertel 2249: }
1.46 ng 2250: } elsif ($ctr == 1) {
1.474 albertel 2251: $gradeTable =~ s/type="checkbox"/type="checkbox" checked="checked"/;
1.45 ng 2252: }
2253: $request->print($gradeTable);
1.44 ng 2254: return '';
1.10 ng 2255: }
2256:
1.796 raeburn 2257: #---- Called from the listStudents and the names_for_passback routines.
2258:
2259: sub checkselect_js {
2260: my ($formname) = @_;
2261: if ($formname eq '') {
2262: $formname = 'gradesub';
2263: }
2264: my %js_lt;
2265: if ($formname eq 'passbackusers') {
2266: %js_lt = &Apache::lonlocal::texthash (
2267: 'multiple' => 'Please select a student or group of students before pushing the Save Scores button.',
2268: 'single' => 'Please select the student before pushing the Save Scores button.',
2269: );
2270: } else {
2271: %js_lt = &Apache::lonlocal::texthash (
2272: 'multiple' => 'Please select a student or group of students before clicking on the Next button.',
2273: 'single' => 'Please select the student before clicking on the Next button.',
2274: );
2275: }
2276: &js_escape(\%js_lt);
2277: return &Apache::lonhtmlcommon::scripttag(<<LISTJAVASCRIPT);
2278:
2279: function checkSelect(checkBox) {
2280: var ctr=0;
2281: var sense="";
2282: var len = checkBox.length;
2283: if (len == undefined) len = 1;
2284: if (len > 1) {
2285: for (var i=0; i<len; i++) {
2286: if (checkBox[i].checked) {
2287: ctr++;
2288: }
2289: }
2290: sense = '$js_lt{'multiple'}';
2291: } else {
2292: if (checkBox.checked) {
2293: ctr = 1;
2294: }
2295: sense = '$js_lt{'single'}';
2296: }
2297: if (ctr == 0) {
2298: alert(sense);
2299: return false;
2300: }
2301: document.$formname.submit();
2302: }
2303: LISTJAVASCRIPT
2304:
2305: }
1.249 albertel 2306:
2307: sub check_script {
1.766 raeburn 2308: my ($form,$type) = @_;
2309: my $chkallscript = &Apache::lonhtmlcommon::scripttag('
1.249 albertel 2310: function checkall() {
2311: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
2312: ele = document.forms.'.$form.'.elements[i];
2313: if (ele.name == "'.$type.'") {
2314: document.forms.'.$form.'.elements[i].checked=true;
2315: }
2316: }
2317: }
2318:
2319: function checksec() {
2320: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
2321: ele = document.forms.'.$form.'.elements[i];
2322: string = document.forms.'.$form.'.chksec.value;
2323: if
2324: (ele.value.indexOf(":::SECTION"+string)>0) {
2325: document.forms.'.$form.'.elements[i].checked=true;
2326: }
2327: }
2328: }
2329:
2330:
2331: function uncheckall() {
2332: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
2333: ele = document.forms.'.$form.'.elements[i];
2334: if (ele.name == "'.$type.'") {
2335: document.forms.'.$form.'.elements[i].checked=false;
2336: }
2337: }
2338: }
2339:
1.597 wenzelju 2340: '."\n");
1.249 albertel 2341: return $chkallscript;
2342: }
2343:
2344: sub check_buttons {
1.485 albertel 2345: my $buttons.='<input type="button" onclick="checkall()" value="'.&mt('Check All').'" />';
2346: $buttons.='<input type="button" onclick="uncheckall()" value="'.&mt('Uncheck All').'" /> ';
2347: $buttons.='<input type="button" onclick="checksec()" value="'.&mt('Check Section/Group').'" />';
1.249 albertel 2348: $buttons.='<input type="text" size="5" name="chksec" /> ';
2349: return $buttons;
2350: }
2351:
1.44 ng 2352: # Displays the submissions for one student or a group of students
1.34 ng 2353: sub processGroup {
1.766 raeburn 2354: my ($request,$symb) = @_;
1.41 ng 2355: my $ctr = 0;
1.155 albertel 2356: my @stuchecked = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.41 ng 2357: my $total = scalar(@stuchecked)-1;
1.45 ng 2358:
1.396 banghart 2359: foreach my $student (@stuchecked) {
2360: my ($uname,$udom,$fullname) = split(/:/,$student);
1.257 albertel 2361: $env{'form.student'} = $uname;
2362: $env{'form.userdom'} = $udom;
2363: $env{'form.fullname'} = $fullname;
1.619 www 2364: &submission($request,$ctr,$total,$symb);
1.41 ng 2365: $ctr++;
2366: }
2367: return '';
1.35 ng 2368: }
1.34 ng 2369:
1.44 ng 2370: #------------------------------------------------------------------------------------
2371: #
2372: #-------------------------- Next few routines handles grading by student, essentially
2373: # handles essay response type problem/part
2374: #
2375: #--- Javascript to handle the submission page functionality ---
2376: sub sub_page_js {
2377: my $request = shift;
1.736 damieng 2378: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
2379: &js_escape(\$alertmsg);
1.597 wenzelju 2380: $request->print(&Apache::lonhtmlcommon::scripttag(<<SUBJAVASCRIPT));
1.71 ng 2381: function updateRadio(formname,id,weight) {
1.125 ng 2382: var gradeBox = formname["GD_BOX"+id];
2383: var radioButton = formname["RADVAL"+id];
2384: var oldpts = formname["oldpts"+id].value;
1.72 ng 2385: var pts = checkSolved(formname,id) == 'update' ? gradeBox.value : oldpts;
1.71 ng 2386: gradeBox.value = pts;
2387: var resetbox = false;
2388: if (isNaN(pts) || pts < 0) {
1.539 riegler 2389: alert("$alertmsg"+pts);
1.71 ng 2390: for (var i=0; i<radioButton.length; i++) {
2391: if (radioButton[i].checked) {
2392: gradeBox.value = i;
2393: resetbox = true;
2394: }
2395: }
2396: if (!resetbox) {
2397: formtextbox.value = "";
2398: }
2399: return;
1.44 ng 2400: }
1.71 ng 2401:
2402: if (pts > weight) {
2403: var resp = confirm("You entered a value ("+pts+
2404: ") greater than the weight for the part. Accept?");
2405: if (resp == false) {
1.125 ng 2406: gradeBox.value = oldpts;
1.71 ng 2407: return;
2408: }
1.44 ng 2409: }
1.13 albertel 2410:
1.71 ng 2411: for (var i=0; i<radioButton.length; i++) {
2412: radioButton[i].checked=false;
2413: if (pts == i && pts != "") {
2414: radioButton[i].checked=true;
2415: }
2416: }
2417: updateSelect(formname,id);
1.125 ng 2418: formname["stores"+id].value = "0";
1.41 ng 2419: }
1.5 albertel 2420:
1.72 ng 2421: function writeBox(formname,id,pts) {
1.125 ng 2422: var gradeBox = formname["GD_BOX"+id];
1.71 ng 2423: if (checkSolved(formname,id) == 'update') {
2424: gradeBox.value = pts;
2425: } else {
1.125 ng 2426: var oldpts = formname["oldpts"+id].value;
1.72 ng 2427: gradeBox.value = oldpts;
1.125 ng 2428: var radioButton = formname["RADVAL"+id];
1.71 ng 2429: for (var i=0; i<radioButton.length; i++) {
2430: radioButton[i].checked=false;
1.72 ng 2431: if (i == oldpts) {
1.71 ng 2432: radioButton[i].checked=true;
2433: }
2434: }
1.41 ng 2435: }
1.125 ng 2436: formname["stores"+id].value = "0";
1.71 ng 2437: updateSelect(formname,id);
2438: return;
1.41 ng 2439: }
1.44 ng 2440:
1.71 ng 2441: function clearRadBox(formname,id) {
2442: if (checkSolved(formname,id) == 'noupdate') {
2443: updateSelect(formname,id);
2444: return;
2445: }
1.125 ng 2446: gradeSelect = formname["GD_SEL"+id];
1.71 ng 2447: for (var i=0; i<gradeSelect.length; i++) {
2448: if (gradeSelect[i].selected) {
2449: var selectx=i;
2450: }
2451: }
1.125 ng 2452: var stores = formname["stores"+id];
1.71 ng 2453: if (selectx == stores.value) { return };
1.125 ng 2454: var gradeBox = formname["GD_BOX"+id];
1.71 ng 2455: gradeBox.value = "";
1.125 ng 2456: var radioButton = formname["RADVAL"+id];
1.71 ng 2457: for (var i=0; i<radioButton.length; i++) {
2458: radioButton[i].checked=false;
2459: }
2460: stores.value = selectx;
2461: }
1.5 albertel 2462:
1.71 ng 2463: function checkSolved(formname,id) {
1.125 ng 2464: if (formname["solved"+id].value == "correct_by_student" && formname.overRideScore.value == 'no') {
1.118 ng 2465: var reply = confirm("This problem has been graded correct by the computer. Do you want to change the score?");
2466: if (!reply) {return "noupdate";}
1.120 ng 2467: formname.overRideScore.value = 'yes';
1.41 ng 2468: }
1.71 ng 2469: return "update";
1.13 albertel 2470: }
1.71 ng 2471:
2472: function updateSelect(formname,id) {
1.125 ng 2473: formname["GD_SEL"+id][0].selected = true;
1.71 ng 2474: return;
1.41 ng 2475: }
1.33 ng 2476:
1.121 ng 2477: //=========== Check that a point is assigned for all the parts ============
1.71 ng 2478: function checksubmit(formname,val,total,parttot) {
1.121 ng 2479: formname.gradeOpt.value = val;
1.71 ng 2480: if (val == "Save & Next") {
2481: for (i=0;i<=total;i++) {
2482: for (j=0;j<parttot;j++) {
1.125 ng 2483: var partid = formname["partid"+i+"_"+j].value;
1.127 ng 2484: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 2485: var points = formname["GD_BOX"+i+"_"+partid].value;
1.71 ng 2486: if (points == "") {
1.125 ng 2487: var name = formname["name"+i].value;
1.129 ng 2488: var studentID = (name != '' ? name : formname["unamedom"+i].value);
2489: var resp = confirm("You did not assign a score for "+studentID+
2490: ", part "+partid+". Continue?");
1.71 ng 2491: if (resp == false) {
1.125 ng 2492: formname["GD_BOX"+i+"_"+partid].focus();
1.71 ng 2493: return false;
2494: }
2495: }
2496: }
2497: }
2498: }
2499: }
1.120 ng 2500: formname.submit();
2501: }
2502:
1.71 ng 2503: //======= Check that a score is assigned for all the problems (page/sequence grading only) =========
2504: function checkSubmitPage(formname,total) {
2505: noscore = new Array(100);
2506: var ptr = 0;
2507: for (i=1;i<total;i++) {
1.125 ng 2508: var partid = formname["q_"+i].value;
1.127 ng 2509: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 2510: var points = formname["GD_BOX"+i+"_"+partid].value;
2511: var status = formname["solved"+i+"_"+partid].value;
1.71 ng 2512: if (points == "" && status != "correct_by_student") {
2513: noscore[ptr] = i;
2514: ptr++;
2515: }
2516: }
2517: }
2518: if (ptr != 0) {
2519: var sense = ptr == 1 ? ": " : "s: ";
2520: var prolist = "";
2521: if (ptr == 1) {
2522: prolist = noscore[0];
2523: } else {
2524: var i = 0;
2525: while (i < ptr-1) {
2526: prolist += noscore[i]+", ";
2527: i++;
2528: }
2529: prolist += "and "+noscore[i];
2530: }
2531: var resp = confirm("You did not assign any score for the following problem"+sense+prolist+". Continue?");
2532: if (resp == false) {
2533: return false;
2534: }
2535: }
1.45 ng 2536:
1.71 ng 2537: formname.submit();
2538: }
2539: SUBJAVASCRIPT
2540: }
1.45 ng 2541:
1.773 raeburn 2542: #--- javascript for grading message center
2543: sub sub_grademessage_js {
1.71 ng 2544: my $request = shift;
1.80 ng 2545: my $iconpath = $request->dir_config('lonIconsURL');
1.118 ng 2546: &commonJSfunctions($request);
1.350 albertel 2547:
1.629 www 2548: my $inner_js_msg_central= (<<INNERJS);
2549: <script type="text/javascript">
1.350 albertel 2550: function checkInput() {
2551: opener.document.SCORE.msgsub.value = opener.checkEntities(document.msgcenter.msgsub.value);
2552: var nmsg = opener.document.SCORE.savemsgN.value;
2553: var usrctr = document.msgcenter.usrctr.value;
2554: var newval = opener.document.SCORE["newmsg"+usrctr];
2555: newval.value = opener.checkEntities(document.msgcenter.newmsg.value);
2556:
2557: var msgchk = "";
2558: if (document.msgcenter.subchk.checked) {
2559: msgchk = "msgsub,";
2560: }
2561: var includemsg = 0;
2562: for (var i=1; i<=nmsg; i++) {
2563: var opnmsg = opener.document.SCORE["savemsg"+i];
2564: var frmmsg = document.msgcenter["msg"+i];
2565: opnmsg.value = opener.checkEntities(frmmsg.value);
2566: var showflg = opener.document.SCORE["shownOnce"+i];
2567: showflg.value = "1";
2568: var chkbox = document.msgcenter["msgn"+i];
2569: if (chkbox.checked) {
2570: msgchk += "savemsg"+i+",";
2571: includemsg = 1;
2572: }
2573: }
2574: if (document.msgcenter.newmsgchk.checked) {
2575: msgchk += "newmsg"+usrctr;
2576: includemsg = 1;
2577: }
2578: imgformname = opener.document.SCORE["mailicon"+usrctr];
2579: imgformname.src = "$iconpath/"+((includemsg) ? "mailto.gif" : "mailbkgrd.gif");
2580: var includemsg = opener.document.SCORE["includemsg"+usrctr];
2581: includemsg.value = msgchk;
2582:
2583: self.close()
2584:
2585: }
1.629 www 2586: </script>
1.350 albertel 2587: INNERJS
2588:
1.773 raeburn 2589: my $start_page_msg_central =
1.351 albertel 2590: &Apache::loncommon::start_page('Message Central',$inner_js_msg_central,
2591: {'js_ready' => 1,
2592: 'only_body' => 1,
2593: 'bgcolor' =>'#FFFFFF',});
1.773 raeburn 2594: my $end_page_msg_central =
1.350 albertel 2595: &Apache::loncommon::end_page({'js_ready' => 1});
2596:
1.219 www 2597: my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
1.236 albertel 2598: $docopen=~s/^document\.//;
1.773 raeburn 2599:
1.736 damieng 2600: my %html_js_lt = &Apache::lonlocal::texthash(
1.652 raeburn 2601: comp => 'Compose Message for: ',
2602: incl => 'Include',
1.656 raeburn 2603: type => 'Type',
1.652 raeburn 2604: subj => 'Subject',
2605: mesa => 'Message',
2606: new => 'New',
2607: save => 'Save',
2608: canc => 'Cancel',
2609: );
1.736 damieng 2610: &html_escape(\%html_js_lt);
2611: &js_escape(\%html_js_lt);
1.597 wenzelju 2612: $request->print(&Apache::lonhtmlcommon::scripttag(<<SUBJAVASCRIPT));
1.45 ng 2613:
1.44 ng 2614: //===================== Script to view submitted by ==================
2615: function viewSubmitter(submitter) {
2616: document.SCORE.refresh.value = "on";
2617: document.SCORE.NCT.value = "1";
2618: document.SCORE.unamedom0.value = submitter;
2619: document.SCORE.submit();
2620: return;
2621: }
2622:
2623: //====================== Script for composing message ==============
1.80 ng 2624: // preload images
2625: img1 = new Image();
2626: img1.src = "$iconpath/mailbkgrd.gif";
2627: img2 = new Image();
2628: img2.src = "$iconpath/mailto.gif";
2629:
1.44 ng 2630: function msgCenter(msgform,usrctr,fullname) {
2631: var Nmsg = msgform.savemsgN.value;
2632: savedMsgHeader(Nmsg,usrctr,fullname);
2633: var subject = msgform.msgsub.value;
1.127 ng 2634: var msgchk = document.SCORE["includemsg"+usrctr].value;
1.44 ng 2635: re = /msgsub/;
2636: var shwsel = "";
2637: if (re.test(msgchk)) { shwsel = "checked" }
1.123 ng 2638: subject = (document.SCORE.shownSub.value == 0 ? checkEntities(subject) : subject);
2639: displaySubject(checkEntities(subject),shwsel);
1.44 ng 2640: for (var i=1; i<=Nmsg; i++) {
1.123 ng 2641: var testmsg = "savemsg"+i+",";
2642: re = new RegExp(testmsg,"g");
1.44 ng 2643: shwsel = "";
2644: if (re.test(msgchk)) { shwsel = "checked" }
1.125 ng 2645: var message = document.SCORE["savemsg"+i].value;
1.126 ng 2646: message = (document.SCORE["shownOnce"+i].value == 0 ? checkEntities(message) : message);
1.123 ng 2647: displaySavedMsg(i,message,shwsel); //I do not get it. w/o checkEntities on saved messages,
2648: //any < is already converted to <, etc. However, only once!!
1.44 ng 2649: }
1.125 ng 2650: newmsg = document.SCORE["newmsg"+usrctr].value;
1.44 ng 2651: shwsel = "";
2652: re = /newmsg/;
2653: if (re.test(msgchk)) { shwsel = "checked" }
2654: newMsg(newmsg,shwsel);
2655: msgTail();
2656: return;
2657: }
2658:
1.123 ng 2659: function checkEntities(strx) {
2660: if (strx.length == 0) return strx;
2661: var orgStr = ["&", "<", ">", '"'];
2662: var newStr = ["&", "<", ">", """];
2663: var counter = 0;
2664: while (counter < 4) {
2665: strx = strReplace(strx,orgStr[counter],newStr[counter]);
2666: counter++;
2667: }
2668: return strx;
2669: }
2670:
2671: function strReplace(strx, orgStr, newStr) {
2672: return strx.split(orgStr).join(newStr);
2673: }
2674:
1.44 ng 2675: function savedMsgHeader(Nmsg,usrctr,fullname) {
1.76 ng 2676: var height = 70*Nmsg+250;
1.44 ng 2677: if (height > 600) {
2678: height = 600;
2679: }
1.118 ng 2680: var xpos = (screen.width-600)/2;
2681: xpos = (xpos < 0) ? '0' : xpos;
2682: var ypos = (screen.height-height)/2-30;
2683: ypos = (ypos < 0) ? '0' : ypos;
2684:
1.668 www 2685: pWin = window.open('', 'MessageCenter', 'resizable=yes,toolbar=no,location=no,scrollbars=yes,screenx='+xpos+',screeny='+ypos+',width=700,height='+height);
1.76 ng 2686: pWin.focus();
2687: pDoc = pWin.document;
1.219 www 2688: pDoc.$docopen;
1.351 albertel 2689: pDoc.write('$start_page_msg_central');
1.76 ng 2690:
2691: pDoc.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
2692: pDoc.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
1.736 damieng 2693: pDoc.write("<h1> $html_js_lt{'comp'}\"+fullname+\"<\\/h1>");
1.76 ng 2694:
1.676 golterma 2695: pDoc.write('<table style="border:1px solid black;"><tr>');
1.736 damieng 2696: 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 2697: }
2698: function displaySubject(msg,shwsel) {
1.76 ng 2699: pDoc = pWin.document;
1.676 golterma 2700: pDoc.write("<tr>");
2701: pDoc.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1.736 damieng 2702: pDoc.write("<td>$html_js_lt{'subj'}<\\/td>");
1.676 golterma 2703: pDoc.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+"\\"size=\\"40\\" maxlength=\\"80\\"><\\/td><\\/tr>");
1.44 ng 2704: }
2705:
1.72 ng 2706: function displaySavedMsg(ctr,msg,shwsel) {
1.76 ng 2707: pDoc = pWin.document;
1.676 golterma 2708: pDoc.write("<tr>");
2709: pDoc.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1.465 albertel 2710: pDoc.write("<td align=\\"center\\">"+ctr+"<\\/td>");
2711: pDoc.write("<td><textarea name=\\"msg"+ctr+"\\" cols=\\"60\\" rows=\\"3\\">"+msg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 2712: }
2713:
2714: function newMsg(newmsg,shwsel) {
1.76 ng 2715: pDoc = pWin.document;
1.676 golterma 2716: pDoc.write("<tr>");
2717: pDoc.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1.736 damieng 2718: pDoc.write("<td align=\\"center\\">$html_js_lt{'new'}<\\/td>");
1.465 albertel 2719: pDoc.write("<td><textarea name=\\"newmsg\\" cols=\\"60\\" rows=\\"3\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" >"+newmsg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 2720: }
2721:
2722: function msgTail() {
1.76 ng 2723: pDoc = pWin.document;
1.676 golterma 2724: //pDoc.write("<\\/table>");
1.465 albertel 2725: pDoc.write("<\\/td><\\/tr><\\/table> ");
1.736 damieng 2726: pDoc.write("<input type=\\"button\\" value=\\"$html_js_lt{'save'}\\" onclick=\\"javascript:checkInput()\\"> ");
2727: pDoc.write("<input type=\\"button\\" value=\\"$html_js_lt{'canc'}\\" onclick=\\"self.close()\\"><br /><br />");
1.465 albertel 2728: pDoc.write("<\\/form>");
1.351 albertel 2729: pDoc.write('$end_page_msg_central');
1.128 ng 2730: pDoc.close();
1.44 ng 2731: }
2732:
1.773 raeburn 2733: SUBJAVASCRIPT
2734: }
2735:
2736: #--- javascript for essay type problem --
2737: sub sub_page_kw_js {
2738: my $request = shift;
2739:
2740: unless ($env{'form.compmsg'}) {
2741: &commonJSfunctions($request);
2742: }
2743:
2744: my $inner_js_highlight_central= (<<INNERJS);
2745: <script type="text/javascript">
2746: function updateChoice(flag) {
2747: opener.document.SCORE.kwclr.value = opener.radioSelection(document.hlCenter.kwdclr);
2748: opener.document.SCORE.kwsize.value = opener.radioSelection(document.hlCenter.kwdsize);
2749: opener.document.SCORE.kwstyle.value = opener.radioSelection(document.hlCenter.kwdstyle);
2750: opener.document.SCORE.refresh.value = "on";
2751: if (opener.document.SCORE.keywords.value!=""){
2752: opener.document.SCORE.submit();
2753: }
2754: self.close()
2755: }
2756: </script>
2757: INNERJS
2758:
2759: my $start_page_highlight_central =
2760: &Apache::loncommon::start_page('Highlight Central',
2761: $inner_js_highlight_central,
2762: {'js_ready' => 1,
2763: 'only_body' => 1,
2764: 'bgcolor' =>'#FFFFFF',});
2765: my $end_page_highlight_central =
2766: &Apache::loncommon::end_page({'js_ready' => 1});
2767:
2768: my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
2769: $docopen=~s/^document\.//;
2770:
2771: my %js_lt = &Apache::lonlocal::texthash(
2772: keyw => 'Keywords list, separated by a space. Add/delete to list if desired.',
2773: plse => 'Please select a word or group of words from document and then click this link.',
2774: adds => 'Add selection to keyword list? Edit if desired.',
2775: col1 => 'red',
2776: col2 => 'green',
2777: col3 => 'blue',
2778: siz1 => 'normal',
2779: siz2 => '+1',
2780: siz3 => '+2',
2781: sty1 => 'normal',
2782: sty2 => 'italic',
2783: sty3 => 'bold',
2784: );
2785: my %html_js_lt = &Apache::lonlocal::texthash(
2786: save => 'Save',
2787: canc => 'Cancel',
2788: kehi => 'Keyword Highlight Options',
2789: txtc => 'Text Color',
2790: font => 'Font Size',
2791: fnst => 'Font Style',
2792: );
2793: &js_escape(\%js_lt);
2794: &html_escape(\%html_js_lt);
2795: &js_escape(\%html_js_lt);
2796: $request->print(&Apache::lonhtmlcommon::scripttag(<<SUBJAVASCRIPT));
2797:
2798: //===================== Show list of keywords ====================
2799: function keywords(formname) {
2800: var nret = prompt("$js_lt{'keyw'}",formname.keywords.value);
2801: if (nret==null) return;
2802: formname.keywords.value = nret;
2803:
2804: if (formname.keywords.value != "") {
2805: formname.refresh.value = "on";
2806: formname.submit();
2807: }
2808: return;
2809: }
2810:
2811: //===================== Script to add keyword(s) ==================
2812: function getSel() {
2813: if (document.getSelection) txt = document.getSelection();
2814: else if (document.selection) txt = document.selection.createRange().text;
2815: else return;
2816: if (typeof(txt) != 'string') {
2817: txt = String(txt);
2818: }
2819: var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
2820: if (cleantxt=="") {
2821: alert("$js_lt{'plse'}");
2822: return;
2823: }
2824: var nret = prompt("$js_lt{'adds'}",cleantxt);
2825: if (nret==null) return;
2826: document.SCORE.keywords.value = document.SCORE.keywords.value+" "+nret;
2827: if (document.SCORE.keywords.value != "") {
2828: document.SCORE.refresh.value = "on";
2829: document.SCORE.submit();
2830: }
2831: return;
2832: }
2833:
1.44 ng 2834: //====================== Script for keyword highlight options ==============
2835: function kwhighlight() {
2836: var kwclr = document.SCORE.kwclr.value;
2837: var kwsize = document.SCORE.kwsize.value;
2838: var kwstyle = document.SCORE.kwstyle.value;
2839: var redsel = "";
2840: var grnsel = "";
2841: var blusel = "";
1.736 damieng 2842: var txtcol1 = "$js_lt{'col1'}";
2843: var txtcol2 = "$js_lt{'col2'}";
2844: var txtcol3 = "$js_lt{'col3'}";
2845: var txtsiz1 = "$js_lt{'siz1'}";
2846: var txtsiz2 = "$js_lt{'siz2'}";
2847: var txtsiz3 = "$js_lt{'siz3'}";
2848: var txtsty1 = "$js_lt{'sty1'}";
2849: var txtsty2 = "$js_lt{'sty2'}";
2850: var txtsty3 = "$js_lt{'sty3'}";
1.718 bisitz 2851: if (kwclr=="red") {var redsel="checked='checked'"};
2852: if (kwclr=="green") {var grnsel="checked='checked'"};
2853: if (kwclr=="blue") {var blusel="checked='checked'"};
1.44 ng 2854: var sznsel = "";
2855: var sz1sel = "";
2856: var sz2sel = "";
1.718 bisitz 2857: if (kwsize=="0") {var sznsel="checked='checked'"};
2858: if (kwsize=="+1") {var sz1sel="checked='checked'"};
2859: if (kwsize=="+2") {var sz2sel="checked='checked'"};
1.44 ng 2860: var synsel = "";
2861: var syisel = "";
2862: var sybsel = "";
1.718 bisitz 2863: if (kwstyle=="") {var synsel="checked='checked'"};
2864: if (kwstyle=="<i>") {var syisel="checked='checked'"};
2865: if (kwstyle=="<b>") {var sybsel="checked='checked'"};
1.44 ng 2866: highlightCentral();
1.718 bisitz 2867: highlightbody('red',txtcol1,redsel,'0',txtsiz1,sznsel,'',txtsty1,synsel);
2868: highlightbody('green',txtcol2,grnsel,'+1',txtsiz2,sz1sel,'<i>',txtsty2,syisel);
2869: highlightbody('blue',txtcol3,blusel,'+2',txtsiz3,sz2sel,'<b>',txtsty3,sybsel);
1.44 ng 2870: highlightend();
2871: return;
2872: }
2873:
2874: function highlightCentral() {
1.76 ng 2875: // if (window.hwdWin) window.hwdWin.close();
1.118 ng 2876: var xpos = (screen.width-400)/2;
2877: xpos = (xpos < 0) ? '0' : xpos;
2878: var ypos = (screen.height-330)/2-30;
2879: ypos = (ypos < 0) ? '0' : ypos;
2880:
1.206 albertel 2881: hwdWin = window.open('', 'KeywordHighlightCentral', 'resizeable=yes,toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx='+xpos+',screeny='+ypos);
1.76 ng 2882: hwdWin.focus();
2883: var hDoc = hwdWin.document;
1.219 www 2884: hDoc.$docopen;
1.351 albertel 2885: hDoc.write('$start_page_highlight_central');
1.76 ng 2886: hDoc.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
1.736 damieng 2887: hDoc.write("<h1>$html_js_lt{'kehi'}<\\/h1>");
1.76 ng 2888:
1.718 bisitz 2889: hDoc.write('<table border="0" width="100%"><tr style="background-color:#A1D676">');
1.736 damieng 2890: hDoc.write("<th>$html_js_lt{'txtc'}<\\/th><th>$html_js_lt{'font'}<\\/th><th>$html_js_lt{'fnst'}<\\/th><\\/tr>");
1.44 ng 2891: }
2892:
2893: function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) {
1.76 ng 2894: var hDoc = hwdWin.document;
1.718 bisitz 2895: hDoc.write("<tr>");
1.76 ng 2896: hDoc.write("<td align=\\"left\\">");
1.718 bisitz 2897: hDoc.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+" \\/> "+clrtxt+"<\\/td>");
1.76 ng 2898: hDoc.write("<td align=\\"left\\">");
1.718 bisitz 2899: hDoc.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+" \\/> "+sztxt+"<\\/td>");
1.76 ng 2900: hDoc.write("<td align=\\"left\\">");
1.718 bisitz 2901: hDoc.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+" \\/> "+sytxt+"<\\/td>");
1.465 albertel 2902: hDoc.write("<\\/tr>");
1.44 ng 2903: }
2904:
2905: function highlightend() {
1.76 ng 2906: var hDoc = hwdWin.document;
1.718 bisitz 2907: hDoc.write("<\\/table><br \\/>");
1.736 damieng 2908: hDoc.write("<input type=\\"button\\" value=\\"$html_js_lt{'save'}\\" onclick=\\"javascript:updateChoice(1)\\" \\/> ");
2909: hDoc.write("<input type=\\"button\\" value=\\"$html_js_lt{'canc'}\\" onclick=\\"self.close()\\" \\/><br /><br />");
1.465 albertel 2910: hDoc.write("<\\/form>");
1.351 albertel 2911: hDoc.write('$end_page_highlight_central');
1.128 ng 2912: hDoc.close();
1.44 ng 2913: }
2914:
2915: SUBJAVASCRIPT
2916: }
2917:
1.349 albertel 2918: sub get_increment {
1.348 bowersj2 2919: my $increment = $env{'form.increment'};
2920: if ($increment != 1 && $increment != .5 && $increment != .25 &&
2921: $increment != .1) {
2922: $increment = 1;
2923: }
2924: return $increment;
2925: }
2926:
1.585 bisitz 2927: sub gradeBox_start {
2928: return (
2929: &Apache::loncommon::start_data_table()
2930: .&Apache::loncommon::start_data_table_header_row()
2931: .'<th>'.&mt('Part').'</th>'
2932: .'<th>'.&mt('Points').'</th>'
2933: .'<th> </th>'
2934: .'<th>'.&mt('Assign Grade').'</th>'
2935: .'<th>'.&mt('Weight').'</th>'
2936: .'<th>'.&mt('Grade Status').'</th>'
2937: .&Apache::loncommon::end_data_table_header_row()
2938: );
2939: }
2940:
2941: sub gradeBox_end {
2942: return (
2943: &Apache::loncommon::end_data_table()
2944: );
2945: }
1.71 ng 2946: #--- displays the grading box, used in essay type problem and grading by page/sequence
2947: sub gradeBox {
1.322 albertel 2948: my ($request,$symb,$uname,$udom,$counter,$partid,$record) = @_;
1.381 albertel 2949: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 2950: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 2951: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
1.466 albertel 2952: my $wgtmsg = ($wgt > 0) ? &mt('(problem weight)')
2953: : '<span class="LC_info">'.&mt('problem weight assigned by computer').'</span>';
1.71 ng 2954: $wgt = ($wgt > 0 ? $wgt : '1');
2955: my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
1.320 albertel 2956: '' : &compute_points($$record{'resource.'.$partid.'.awarded'},$wgt));
1.695 bisitz 2957: my $data_WGT='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />'."\n";
1.466 albertel 2958: my $display_part= &get_display_part($partid,$symb);
1.270 albertel 2959: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
2960: [$partid]);
2961: my $aggtries = $$record{'resource.'.$partid.'.tries'};
1.269 raeburn 2962: if ($last_resets{$partid}) {
2963: $aggtries = &get_num_tries($record,$last_resets{$partid},$partid);
2964: }
1.695 bisitz 2965: my $result=&Apache::loncommon::start_data_table_row();
1.71 ng 2966: my $ctr = 0;
1.348 bowersj2 2967: my $thisweight = 0;
1.349 albertel 2968: my $increment = &get_increment();
1.485 albertel 2969:
2970: my $radio.='<table border="0"><tr>'."\n"; # display radio buttons in a nice table 10 across
1.348 bowersj2 2971: while ($thisweight<=$wgt) {
1.532 bisitz 2972: $radio.= '<td><span class="LC_nobreak"><label><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
1.589 bisitz 2973: 'onclick="javascript:writeBox(this.form,\''.$counter.'_'.$partid.'\','.
1.348 bowersj2 2974: $thisweight.')" value="'.$thisweight.'" '.
1.401 albertel 2975: ($score eq $thisweight ? 'checked="checked"':'').' /> '.$thisweight."</label></span></td>\n";
1.485 albertel 2976: $radio.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1.348 bowersj2 2977: $thisweight += $increment;
1.71 ng 2978: $ctr++;
2979: }
1.485 albertel 2980: $radio.='</tr></table>';
2981:
2982: my $line.='<input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
1.71 ng 2983: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
1.589 bisitz 2984: 'onchange="javascript:updateRadio(this.form,\''.$counter.'_'.$partid.'\','.
1.71 ng 2985: $wgt.')" /></td>'."\n";
1.485 albertel 2986: $line.='<td>/'.$wgt.' '.$wgtmsg.
1.71 ng 2987: ($$record{'resource.'.$partid.'.solved'} eq 'correct_by_student' ? ' '.$checkIcon : '').
1.585 bisitz 2988: ' </td>'."\n";
2989: $line.='<td><select name="GD_SEL'.$counter.'_'.$partid.'" '.
1.589 bisitz 2990: 'onchange="javascript:clearRadBox(this.form,\''.$counter.'_'.$partid.'\')" >'."\n";
1.71 ng 2991: if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
1.485 albertel 2992: $line.='<option></option>'.
2993: '<option value="excused" selected="selected">'.&mt('excused').'</option>';
1.71 ng 2994: } else {
1.485 albertel 2995: $line.='<option selected="selected"></option>'.
2996: '<option value="excused" >'.&mt('excused').'</option>';
1.71 ng 2997: }
1.485 albertel 2998: $line.='<option value="reset status">'.&mt('reset status').'</option></select>'."\n";
2999:
3000:
3001: $result .=
1.695 bisitz 3002: '<td>'.$data_WGT.$display_part.'</td><td>'.$radio.'</td><td>'.&mt('or').'</td><td>'.$line.'</td>';
1.585 bisitz 3003: $result.=&Apache::loncommon::end_data_table_row();
1.695 bisitz 3004: $result.=&Apache::loncommon::start_data_table_row().'<td colspan="6">';
1.71 ng 3005: $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="" />'."\n".
3006: '<input type="hidden" name="oldpts'.$counter.'_'.$partid.'" value="'.$score.'" />'."\n".
3007: '<input type="hidden" name="solved'.$counter.'_'.$partid.'" value="'.
1.269 raeburn 3008: $$record{'resource.'.$partid.'.solved'}.'" />'."\n".
3009: '<input type="hidden" name="totaltries'.$counter.'_'.$partid.'" value="'.
3010: $$record{'resource.'.$partid.'.tries'}.'" />'."\n".
3011: '<input type="hidden" name="aggtries'.$counter.'_'.$partid.'" value="'.
3012: $aggtries.'" />'."\n";
1.582 raeburn 3013: my $res_error;
3014: $result.=&handback_box($symb,$uname,$udom,$counter,$partid,$record,\$res_error);
1.695 bisitz 3015: $result.='</td>'.&Apache::loncommon::end_data_table_row();
1.582 raeburn 3016: if ($res_error) {
3017: return &navmap_errormsg();
3018: }
1.318 banghart 3019: return $result;
3020: }
1.322 albertel 3021:
3022: sub handback_box {
1.623 www 3023: my ($symb,$uname,$udom,$counter,$partid,$record,$res_error_pointer) = @_;
1.773 raeburn 3024: my ($partlist,$handgrade,$responseType,$numresp,$numessay) = &response_type($symb,$res_error_pointer);
3025: return unless ($numessay);
1.323 banghart 3026: my (@respids);
1.652 raeburn 3027: my @part_response_id = &flatten_responseType($responseType);
1.375 albertel 3028: foreach my $part_response_id (@part_response_id) {
3029: my ($part,$resp) = @{ $part_response_id };
1.323 banghart 3030: if ($part eq $partid) {
1.375 albertel 3031: push(@respids,$resp);
1.323 banghart 3032: }
3033: }
1.318 banghart 3034: my $result;
1.323 banghart 3035: foreach my $respid (@respids) {
1.322 albertel 3036: my $prefix = $counter.'_'.$partid.'_'.$respid.'_';
3037: my $files=&get_submitted_files($udom,$uname,$partid,$respid,$record);
3038: next if (!@$files);
1.654 raeburn 3039: my $file_counter = 0;
1.313 banghart 3040: foreach my $file (@$files) {
1.368 banghart 3041: if ($file =~ /\/portfolio\//) {
1.654 raeburn 3042: $file_counter++;
1.368 banghart 3043: my ($file_path, $file_disp) = ($file =~ m|(.+/)(.+)$|);
1.729 raeburn 3044: my ($name,$version,$ext) = &Apache::lonnet::file_name_version_ext($file_disp);
1.368 banghart 3045: $file_disp = "$name.$ext";
3046: $file = $file_path.$file_disp;
3047: $result.=&mt('Return commented version of [_1] to student.',
3048: '<span class="LC_filename">'.$file_disp.'</span>');
3049: $result.='<input type="file" name="'.$prefix.'returndoc'.$file_counter.'" />'."\n";
1.654 raeburn 3050: $result.='<input type="hidden" name="'.$prefix.'origdoc'.$file_counter.'" value="'.$file.'" /><br />'."\n";
1.368 banghart 3051: }
1.322 albertel 3052: }
1.654 raeburn 3053: if ($file_counter) {
3054: $result .= '<input type="hidden" name="'.$prefix.'countreturndoc" value="'.$file_counter.'" />'."\n".
3055: '<span class="LC_info">'.
3056: '('.&mt('File(s) will be uploaded when you click on Save & Next below.',$file_counter).')</span><br /><br />';
3057: }
1.313 banghart 3058: }
1.318 banghart 3059: return $result;
1.71 ng 3060: }
1.44 ng 3061:
1.58 albertel 3062: sub show_problem {
1.382 albertel 3063: my ($request,$symb,$uname,$udom,$removeform,$viewon,$mode,$form) = @_;
1.144 albertel 3064: my $rendered;
1.382 albertel 3065: my %form = ((ref($form) eq 'HASH')? %{$form} : ());
1.329 albertel 3066: &Apache::lonxml::remember_problem_counter();
1.144 albertel 3067: if ($mode eq 'both' or $mode eq 'text') {
3068: $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
1.382 albertel 3069: $env{'request.course.id'},
3070: undef,\%form);
1.144 albertel 3071: }
1.58 albertel 3072: if ($removeform) {
3073: $rendered=~s|<form(.*?)>||g;
3074: $rendered=~s|</form>||g;
1.374 albertel 3075: $rendered=~s|(<input[^>]*name\s*=\s*"?)(\w+)("?)|$1would_have_been_$2$3|g;
1.58 albertel 3076: }
1.144 albertel 3077: my $companswer;
3078: if ($mode eq 'both' or $mode eq 'answer') {
1.329 albertel 3079: &Apache::lonxml::restore_problem_counter();
1.382 albertel 3080: $companswer=
3081: &Apache::loncommon::get_student_answers($symb,$uname,$udom,
3082: $env{'request.course.id'},
3083: %form);
1.144 albertel 3084: }
1.58 albertel 3085: if ($removeform) {
3086: $companswer=~s|<form(.*?)>||g;
3087: $companswer=~s|</form>||g;
1.144 albertel 3088: $companswer=~s|name="submit"|name="would_have_been_submit"|g;
1.58 albertel 3089: }
1.671 raeburn 3090: my $renderheading = &mt('View of the problem');
3091: my $answerheading = &mt('Correct answer');
3092: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3093: my $stu_fullname = $env{'form.fullname'};
3094: if ($stu_fullname eq '') {
3095: $stu_fullname = &Apache::loncommon::plainname($uname,$udom,'lastname');
3096: }
3097: my $forwhom = &nameUserString(undef,$stu_fullname,$uname,$udom);
3098: if ($forwhom ne '') {
3099: $renderheading = &mt('View of the problem for[_1]',$forwhom);
3100: $answerheading = &mt('Correct answer for[_1]',$forwhom);
3101: }
3102: }
1.468 albertel 3103: $rendered=
1.588 bisitz 3104: '<div class="LC_Box">'
1.671 raeburn 3105: .'<h3 class="LC_hcell">'.$renderheading.'</h3>'
1.588 bisitz 3106: .$rendered
3107: .'</div>';
1.468 albertel 3108: $companswer=
1.588 bisitz 3109: '<div class="LC_Box">'
1.671 raeburn 3110: .'<h3 class="LC_hcell">'.$answerheading.'</h3>'
1.588 bisitz 3111: .$companswer
3112: .'</div>';
1.468 albertel 3113: my $result;
1.144 albertel 3114: if ($mode eq 'both') {
1.588 bisitz 3115: $result=$rendered.$companswer;
1.144 albertel 3116: } elsif ($mode eq 'text') {
1.588 bisitz 3117: $result=$rendered;
1.144 albertel 3118: } elsif ($mode eq 'answer') {
1.588 bisitz 3119: $result=$companswer;
1.144 albertel 3120: }
1.71 ng 3121: return $result;
1.58 albertel 3122: }
1.397 albertel 3123:
1.396 banghart 3124: sub files_exist {
3125: my ($r, $symb) = @_;
3126: my @students = &Apache::loncommon::get_env_multiple('form.stuinfo');
3127: foreach my $student (@students) {
3128: my ($uname,$udom,$fullname) = split(/:/,$student);
1.397 albertel 3129: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
3130: $udom,$uname);
1.792 raeburn 3131: my ($string)= &get_last_submission(\%record);
1.397 albertel 3132: foreach my $submission (@$string) {
3133: my ($partid,$respid) =
3134: ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
3135: my $files=&get_submitted_files($udom,$uname,$partid,$respid,
3136: \%record);
3137: return 1 if (@$files);
1.396 banghart 3138: }
3139: }
1.397 albertel 3140: return 0;
1.396 banghart 3141: }
1.397 albertel 3142:
1.394 banghart 3143: sub download_all_link {
3144: my ($r,$symb) = @_;
1.621 www 3145: unless (&files_exist($r, $symb)) {
1.766 raeburn 3146: $r->print(&mt('There are currently no submitted documents.'));
3147: return;
1.621 www 3148: }
1.395 albertel 3149: my $all_students =
3150: join("\n", &Apache::loncommon::get_env_multiple('form.stuinfo'));
3151:
3152: my $parts =
3153: join("\n",&Apache::loncommon::get_env_multiple('form.vPart'));
3154:
1.394 banghart 3155: my $identifier = &Apache::loncommon::get_cgi_id();
1.514 raeburn 3156: &Apache::lonnet::appenv({'cgi.'.$identifier.'.students' => $all_students,
3157: 'cgi.'.$identifier.'.symb' => $symb,
3158: 'cgi.'.$identifier.'.parts' => $parts,});
1.395 albertel 3159: $r->print('<a href="/cgi-bin/multidownload.pl?'.$identifier.'">'.
3160: &mt('Download All Submitted Documents').'</a>');
1.621 www 3161: return;
3162: }
3163:
3164: sub submit_download_link {
3165: my ($request,$symb) = @_;
3166: if (!$symb) { return ''; }
1.750 raeburn 3167: my $res_error;
1.773 raeburn 3168: my ($partlist,$handgrade,$responseType,$numresp,$numessay,$numdropbox) =
3169: &response_type($symb,\$res_error);
3170: if ($res_error) {
3171: $request->print(&mt('An error occurred retrieving response types'));
3172: return;
3173: }
3174: unless ($numessay) {
3175: $request->print(&mt('No essayresponse items found'));
3176: return;
1.750 raeburn 3177: }
1.773 raeburn 3178: my @chosenparts = &Apache::loncommon::get_env_multiple('form.vPart');
3179: if (@chosenparts) {
3180: $request->print(&showResourceInfo($symb,$partlist,$responseType,
3181: undef,undef,1));
1.750 raeburn 3182: }
1.773 raeburn 3183: if ($numessay) {
1.750 raeburn 3184: my $submitonly= $env{'form.submitonly'} eq '' ? 'all' : $env{'form.submitonly'};
3185: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
3186: my $getgroup = $env{'form.group'} eq '' ? 'all' : $env{'form.group'};
3187: (undef,undef,my $fullname) = &getclasslist($getsec,1,$getgroup,$symb,$submitonly,1);
3188: if (ref($fullname) eq 'HASH') {
3189: my @students = map { $_.':'.$fullname->{$_} } (keys(%{$fullname}));
3190: if (@students) {
3191: @{$env{'form.stuinfo'}} = @students;
1.773 raeburn 3192: if ($numdropbox) {
1.750 raeburn 3193: &download_all_link($request,$symb);
1.773 raeburn 3194: } else {
3195: $request->print(&mt('No essayrespose items with dropbox found'));
1.750 raeburn 3196: }
1.773 raeburn 3197: # FIXME Need a mechanism to download essays, i.e., if $numessay > $numdropbox
1.750 raeburn 3198: # Needs to omit user's identity if resource instance is for an anonymous survey.
3199: } else {
3200: $request->print(&mt('No students match the criteria you selected'));
3201: }
3202: } else {
3203: $request->print(&mt('Could not retrieve student information'));
3204: }
3205: } else {
3206: $request->print(&mt('No essayresponse items found'));
3207: }
3208: return;
1.394 banghart 3209: }
1.395 albertel 3210:
1.432 banghart 3211: sub build_section_inputs {
3212: my $section_inputs;
3213: if ($env{'form.section'} eq '') {
3214: $section_inputs .= '<input type="hidden" name="section" value="all" />'."\n";
3215: } else {
3216: my @sections = &Apache::loncommon::get_env_multiple('form.section');
1.434 albertel 3217: foreach my $section (@sections) {
1.432 banghart 3218: $section_inputs .= '<input type="hidden" name="section" value="'.$section.'" />'."\n";
3219: }
3220: }
3221: return $section_inputs;
3222: }
3223:
1.44 ng 3224: # --------------------------- show submissions of a student, option to grade
3225: sub submission {
1.773 raeburn 3226: my ($request,$counter,$total,$symb,$divforres,$calledby) = @_;
1.257 albertel 3227: my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
3228: $udom = ($udom eq '' ? $env{'user.domain'} : $udom); #has form.userdom changed for a student?
3229: my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
3230: $env{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $env{'form.fullname'} eq '';
1.608 www 3231:
1.324 albertel 3232: if ($symb eq '') { $request->print("Unable to handle ambiguous references:."); return ''; }
1.773 raeburn 3233: my $probtitle=&Apache::lonnet::gettitle($symb);
1.746 raeburn 3234: my $is_tool = ($symb =~ /ext\.tool$/);
1.753 raeburn 3235: my ($essayurl,%coursedesc_by_cid);
1.104 albertel 3236:
3237: if (!&canview($usec)) {
1.712 bisitz 3238: $request->print(
3239: '<span class="LC_warning">'.
1.713 bisitz 3240: &mt('Unable to view requested student.').
1.712 bisitz 3241: ' '.&mt('([_1] in section [_2] in course id [_3])',
3242: $uname.':'.$udom,$usec,$env{'request.course.id'}).
3243: '</span>');
1.104 albertel 3244: return;
3245: }
3246:
1.773 raeburn 3247: my $res_error;
3248: my ($partlist,$handgrade,$responseType,$numresp,$numessay) =
3249: &response_type($symb,\$res_error);
3250: if ($res_error) {
3251: $request->print(&navmap_errormsg());
3252: return;
3253: }
3254:
1.257 albertel 3255: if (!$env{'form.lastSub'}) { $env{'form.lastSub'} = 'datesub'; }
1.745 raeburn 3256: unless ($is_tool) {
3257: if (!$env{'form.vProb'}) { $env{'form.vProb'} = 'yes'; }
3258: if (!$env{'form.vAns'}) { $env{'form.vAns'} = 'yes'; }
3259: }
1.773 raeburn 3260: if (($numessay) && ($calledby eq 'submission') && (!exists($env{'form.compmsg'}))) {
3261: $env{'form.compmsg'} = 1;
3262: }
1.257 albertel 3263: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.381 albertel 3264: my $checkIcon = '<img alt="'.&mt('Check Mark').
3265: '" src="'.$request->dir_config('lonIconsURL').
1.122 ng 3266: '/check.gif" height="16" border="0" />';
1.41 ng 3267:
3268: # header info
3269: if ($counter == 0) {
1.773 raeburn 3270: my @chosenparts = &Apache::loncommon::get_env_multiple('form.vPart');
3271: if (@chosenparts) {
3272: $request->print(&showResourceInfo($symb,$partlist,$responseType,'gradesub'));
3273: } elsif ($divforres) {
3274: $request->print('<div style="padding:0;clear:both;margin:0;border:0"></div>');
3275: } else {
3276: $request->print('<br clear="all" />');
3277: }
1.41 ng 3278: &sub_page_js($request);
1.773 raeburn 3279: &sub_grademessage_js($request) if ($env{'form.compmsg'});
3280: &sub_page_kw_js($request) if ($numessay);
1.118 ng 3281:
1.44 ng 3282: # option to display problem, only once else it cause problems
3283: # with the form later since the problem has a form.
1.257 albertel 3284: if ($env{'form.vProb'} eq 'yes' or $env{'form.vAns'} eq 'yes') {
1.144 albertel 3285: my $mode;
1.257 albertel 3286: if ($env{'form.vProb'} eq 'yes' && $env{'form.vAns'} eq 'yes') {
1.144 albertel 3287: $mode='both';
1.257 albertel 3288: } elsif ($env{'form.vProb'} eq 'yes') {
1.144 albertel 3289: $mode='text';
1.257 albertel 3290: } elsif ($env{'form.vAns'} eq 'yes') {
1.144 albertel 3291: $mode='answer';
3292: }
1.329 albertel 3293: &Apache::lonxml::clear_problem_counter();
1.144 albertel 3294: $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
1.41 ng 3295: }
1.441 www 3296:
1.41 ng 3297: my %keyhash = ();
1.773 raeburn 3298: if (($env{'form.kwclr'} eq '' && $numessay) || ($env{'form.compmsg'})) {
1.41 ng 3299: %keyhash = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 3300: $env{'course.'.$env{'request.course.id'}.'.domain'},
3301: $env{'course.'.$env{'request.course.id'}.'.num'});
1.773 raeburn 3302: }
3303: # kwclr is the only variable that is guaranteed not to be blank
3304: # if this subroutine has been called once.
3305: if ($env{'form.kwclr'} eq '' && $numessay) {
1.257 albertel 3306: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
3307: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
3308: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
3309: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
3310: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
1.773 raeburn 3311: }
3312: if ($env{'form.compmsg'}) {
3313: $env{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
1.605 www 3314: $keyhash{$symb.'_subject'} : $probtitle;
1.257 albertel 3315: $env{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1.41 ng 3316: }
1.773 raeburn 3317:
1.257 albertel 3318: my $overRideScore = $env{'form.overRideScore'} eq '' ? 'no' : $env{'form.overRideScore'};
1.442 banghart 3319: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.303 banghart 3320: $request->print('<form action="/adm/grades" method="post" name="SCORE" enctype="multipart/form-data">'."\n".
1.41 ng 3321: '<input type="hidden" name="command" value="handgrade" />'."\n".
1.442 banghart 3322: '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.120 ng 3323: '<input type="hidden" name="overRideScore" value="'.$overRideScore.'" />'."\n".
1.41 ng 3324: '<input type="hidden" name="refresh" value="off" />'."\n".
1.120 ng 3325: '<input type="hidden" name="studentNo" value="" />'."\n".
3326: '<input type="hidden" name="gradeOpt" value="" />'."\n".
1.418 albertel 3327: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 3328: '<input type="hidden" name="vProb" value="'.$env{'form.vProb'}.'" />'."\n".
3329: '<input type="hidden" name="vAns" value="'.$env{'form.vAns'}.'" />'."\n".
3330: '<input type="hidden" name="lastSub" value="'.$env{'form.lastSub'}.'" />'."\n".
1.773 raeburn 3331: '<input type="hidden" name="compmsg" value="'.$env{'form.compmsg'}.'" />'."\n".
1.432 banghart 3332: &build_section_inputs().
1.326 albertel 3333: '<input type="hidden" name="submitonly" value="'.$env{'form.submitonly'}.'" />'."\n".
1.41 ng 3334: '<input type="hidden" name="NCT"'.
1.257 albertel 3335: ' value="'.($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : $total+1).'" />'."\n");
1.773 raeburn 3336: if ($env{'form.compmsg'}) {
3337: $request->print('<input type="hidden" name="msgsub" value="'.$env{'form.msgsub'}.'" />'."\n".
3338: '<input type="hidden" name="shownSub" value="0" />'."\n".
3339: '<input type="hidden" name="savemsgN" value="'.$env{'form.savemsgN'}.'" />'."\n");
3340: }
3341: if ($numessay) {
1.257 albertel 3342: $request->print('<input type="hidden" name="keywords" value="'.$env{'form.keywords'}.'" />'."\n".
3343: '<input type="hidden" name="kwclr" value="'.$env{'form.kwclr'}.'" />'."\n".
3344: '<input type="hidden" name="kwsize" value="'.$env{'form.kwsize'}.'" />'."\n".
1.773 raeburn 3345: '<input type="hidden" name="kwstyle" value="'.$env{'form.kwstyle'}.'" />'."\n");
1.123 ng 3346: }
1.773 raeburn 3347:
1.41 ng 3348: my ($cts,$prnmsg) = (1,'');
1.257 albertel 3349: while ($cts <= $env{'form.savemsgN'}) {
1.41 ng 3350: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
1.123 ng 3351: (!exists($keyhash{$symb.'_savemsg'.$cts}) ?
1.257 albertel 3352: &Apache::lonfeedback::clear_out_html($env{'form.savemsg'.$cts}) :
1.80 ng 3353: &Apache::lonfeedback::clear_out_html($keyhash{$symb.'_savemsg'.$cts})).
1.123 ng 3354: '" />'."\n".
3355: '<input type="hidden" name="shownOnce'.$cts.'" value="0" />'."\n";
1.41 ng 3356: $cts++;
3357: }
3358: $request->print($prnmsg);
1.32 ng 3359:
1.773 raeburn 3360: if ($numessay) {
1.652 raeburn 3361:
3362: my %lt = &Apache::lonlocal::texthash(
1.719 bisitz 3363: keyh => 'Keyword Highlighting for Essays',
1.652 raeburn 3364: keyw => 'Keyword Options',
1.655 raeburn 3365: list => 'List',
1.652 raeburn 3366: past => 'Paste Selection to List',
1.661 www 3367: high => 'Highlight Attribute',
1.773 raeburn 3368: );
1.88 www 3369: #
3370: # Print out the keyword options line
3371: #
1.718 bisitz 3372: $request->print(
3373: '<div class="LC_columnSection">'
3374: .'<fieldset><legend>'.$lt{'keyh'}.'</legend>'
3375: .&Apache::lonhtmlcommon::funclist_from_array(
3376: ['<a href="javascript:keywords(document.SCORE);" target="_self">'.$lt{'list'}.'</a>',
3377: '<a href="#" onmousedown="javascript:getSel(); return false"
3378: class="page">'.$lt{'past'}.'</a>',
3379: '<a href="javascript:kwhighlight();" target="_self">'.$lt{'high'}.'</a>'],
3380: {legend => $lt{'keyw'}})
3381: .'</fieldset></div>'
3382: );
3383:
1.88 www 3384: #
3385: # Load the other essays for similarity check
3386: #
1.753 raeburn 3387: (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb);
3388: if ($essayurl eq 'lib/templates/simpleproblem.problem') {
3389: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3390: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3391: if ($cdom ne '' && $cnum ne '') {
3392: my ($map,$id,$res) = &Apache::lonnet::decode_symb($symb);
3393: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(default(?:|_\d+)\.(?:sequence|page))$}) {
3394: my $apath = $1.'_'.$id;
3395: $apath=~s/\W/\_/gs;
3396: &init_old_essays($symb,$apath,$cdom,$cnum);
3397: }
3398: }
3399: } else {
3400: my ($adom,$aname,$apath)=($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
3401: $apath=&escape($apath);
3402: $apath=~s/\W/\_/gs;
3403: &init_old_essays($symb,$apath,$adom,$aname);
3404: }
1.41 ng 3405: }
3406: }
1.44 ng 3407:
1.441 www 3408: # This is where output for one specific student would start
1.592 bisitz 3409: my $add_class = ($counter%2) ? ' LC_grade_show_user_odd_row' : '';
3410: $request->print(
3411: "\n\n"
3412: .'<div class="LC_grade_show_user'.$add_class.'">'
3413: .'<h2>'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).'</h2>'
3414: ."\n"
3415: );
1.441 www 3416:
1.592 bisitz 3417: # Show additional functions if allowed
3418: if ($perm{'vgr'}) {
3419: $request->print(
3420: &Apache::loncommon::track_student_link(
1.708 bisitz 3421: 'View recent activity',
1.592 bisitz 3422: $uname,$udom,'check')
3423: .' '
3424: );
3425: }
3426: if ($perm{'opa'}) {
3427: $request->print(
3428: &Apache::loncommon::pprmlink(
3429: &mt('Set/Change parameters'),
3430: $uname,$udom,$symb,'check'));
3431: }
3432:
3433: # Show Problem
1.257 albertel 3434: if ($env{'form.vProb'} eq 'all' or $env{'form.vAns'} eq 'all') {
1.144 albertel 3435: my $mode;
1.257 albertel 3436: if ($env{'form.vProb'} eq 'all' && $env{'form.vAns'} eq 'all') {
1.144 albertel 3437: $mode='both';
1.257 albertel 3438: } elsif ($env{'form.vProb'} eq 'all' ) {
1.144 albertel 3439: $mode='text';
1.257 albertel 3440: } elsif ($env{'form.vAns'} eq 'all') {
1.144 albertel 3441: $mode='answer';
3442: }
1.329 albertel 3443: &Apache::lonxml::clear_problem_counter();
1.475 albertel 3444: $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode,{'request.prefix' => 'ctr'.$counter}));
1.58 albertel 3445: }
1.144 albertel 3446:
1.257 albertel 3447: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.41 ng 3448:
1.44 ng 3449: # Display student info
1.41 ng 3450: $request->print(($counter == 0 ? '' : '<br />'));
1.590 bisitz 3451:
1.745 raeburn 3452: my $boxtitle = &mt('Submissions');
3453: if ($is_tool) {
3454: $boxtitle = &mt('Transactions')
3455: }
1.590 bisitz 3456: my $result='<div class="LC_Box">'
1.745 raeburn 3457: .'<h3 class="LC_hcell">'.$boxtitle.'</h3>';
1.45 ng 3458: $result.='<input type="hidden" name="name'.$counter.
1.588 bisitz 3459: '" value="'.$env{'form.fullname'}.'" />'."\n";
1.773 raeburn 3460: if (($numresp > $numessay) && !$is_tool) {
1.588 bisitz 3461: $result.='<p class="LC_info">'
3462: .&mt('Part(s) graded correct by the computer is marked with a [_1] symbol.',$checkIcon)
3463: ."</p>\n";
1.469 albertel 3464: }
3465:
1.773 raeburn 3466: # If any part of the problem is an essayresponse, then check for collaborators
1.464 albertel 3467: my $fullname;
3468: my $col_fullnames = [];
1.773 raeburn 3469: if ($numessay) {
1.464 albertel 3470: (my $sub_result,$fullname,$col_fullnames)=
3471: &check_collaborators($symb,$uname,$udom,\%record,$handgrade,
3472: $counter);
3473: $result.=$sub_result;
1.41 ng 3474: }
1.44 ng 3475: $request->print($result."\n");
1.773 raeburn 3476:
1.44 ng 3477: # print student answer/submission
1.773 raeburn 3478: # Options are (1) Last submission only
3479: # (2) Last submission (with detailed information for that submission)
3480: # (3) All transactions (by date)
3481: # (4) The whole record (with detailed information for all transactions)
3482:
1.793 raeburn 3483: my ($lastsubonly,$partinfo) =
3484: &show_last_submission($uname,$udom,$symb,$essayurl,$responseType,$env{'form.lastSub'},
3485: $is_tool,$fullname,\%record,\%coursedesc_by_cid);
3486: $request->print($partinfo);
3487: $request->print($lastsubonly);
3488:
3489: if ($env{'form.lastSub'} eq 'datesub') {
3490: my ($parts,$handgrade,$responseType) = &response_type($symb,\$res_error);
3491: $request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
3492: }
3493: if ($env{'form.lastSub'} =~ /^(last|all)$/) {
3494: my $identifier = (&canmodify($usec)? $counter : '');
3495: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
3496: $env{'request.course.id'},
3497: $last,'.submission',
3498: 'Apache::grades::keywords_highlight',
3499: $usec,$identifier));
3500: }
3501: $request->print('<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
3502: .$udom.'" />'."\n");
3503: # return if view submission with no grading option
3504: if (!&canmodify($usec)) {
3505: $request->print('<p><span class="LC_warning">'.&mt('No grading privileges').'</span></p></div>');
3506: return;
3507: } else {
3508: $request->print('</div>'."\n");
3509: }
3510:
3511: # grading message center
3512:
3513: if ($env{'form.compmsg'}) {
3514: my $result='<div class="LC_Box">'.
3515: '<h3 class="LC_hcell">'.&mt('Send Message').'</h3>'.
3516: '<div class="LC_grade_message_center_body">';
3517: my ($lastname,$givenn) = split(/,/,$env{'form.fullname'});
3518: my $msgfor = $givenn.' '.$lastname;
3519: if (scalar(@$col_fullnames) > 0) {
3520: my $lastone = pop(@$col_fullnames);
3521: $msgfor .= ', '.(join ', ',@$col_fullnames).' and '.$lastone.'.';
3522: }
3523: $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
3524: $result.='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
3525: '<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n".
3526: ' <a href="javascript:msgCenter(document.SCORE,'.$counter.
3527: ',\''.$msgfor.'\');" target="_self">'.
3528: &mt('Compose message to student'.(scalar(@$col_fullnames) >= 1 ? 's' : '')).'</a><label> ('.
3529: &mt('incl. grades').' <input type="checkbox" name="withgrades'.$counter.'" /></label>)'.
3530: ' <img src="'.$request->dir_config('lonIconsURL').
3531: '/mailbkgrd.gif" width="14" height="10" alt="" name="mailicon'.$counter.'" />'."\n".
3532: '<br /> ('.
3533: &mt('Message will be sent when you click on Save & Next below.').")\n".
3534: '</div></div>';
3535: $request->print($result);
3536: }
3537:
3538: my %seen = ();
3539: my @partlist;
3540: my @gradePartRespid;
3541: my @part_response_id;
3542: if ($is_tool) {
3543: @part_response_id = ([0,'']);
3544: } else {
3545: @part_response_id = &flatten_responseType($responseType);
3546: }
3547: $request->print(
3548: '<div class="LC_Box">'
3549: .'<h3 class="LC_hcell">'.&mt('Assign Grades').'</h3>'
3550: );
3551: $request->print(&gradeBox_start());
3552: foreach my $part_response_id (@part_response_id) {
3553: my ($partid,$respid) = @{ $part_response_id };
3554: my $part_resp = join('_',@{ $part_response_id });
3555: next if ($seen{$partid} > 0);
3556: $seen{$partid}++;
3557: push(@partlist,$partid);
3558: push(@gradePartRespid,$partid.'.'.$respid);
3559: $request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
3560: }
3561: $request->print(&gradeBox_end()); # </div>
3562: $request->print('</div>');
3563:
3564: $request->print('<div class="LC_grade_info_links">');
3565: $request->print('</div>');
3566:
3567: $result='<input type="hidden" name="partlist'.$counter.
3568: '" value="'.(join ":",@partlist).'" />'."\n";
3569: $result.='<input type="hidden" name="gradePartRespid'.
3570: '" value="'.(join ":",@gradePartRespid).'" />'."\n" if ($counter == 0);
3571: my $ctr = 0;
3572: while ($ctr < scalar(@partlist)) {
3573: $result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
3574: $partlist[$ctr].'" />'."\n";
3575: $ctr++;
3576: }
3577: $request->print($result.''."\n");
3578:
3579: # Done with printing info for one student
3580:
3581: $request->print('</div>');#LC_grade_show_user
3582:
3583:
3584: # print end of form
3585: if ($counter == $total) {
3586: my $endform='<br /><hr /><table border="0"><tr><td>'."\n";
3587: $endform.='<input type="button" value="'.&mt('Save & Next').'" '.
3588: 'onclick="javascript:checksubmit(this.form,\'Save & Next\','.
3589: $total.','.scalar(@partlist).');" target="_self" /> '."\n";
3590: my $ntstu ='<select name="NTSTU">'.
3591: '<option>1</option><option>2</option>'.
3592: '<option>3</option><option>5</option>'.
3593: '<option>7</option><option>10</option></select>'."\n";
3594: my $nsel = ($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : '1');
3595: $ntstu =~ s/<option>$nsel</<option selected="selected">$nsel</;
3596: $endform.=&mt('[_1]student(s)',$ntstu);
3597: $endform.=' <input type="button" value="'.&mt('Previous').'" '.
3598: 'onclick="javascript:checksubmit(this.form,\'Previous\');" target="_self" /> '."\n".
3599: '<input type="button" value="'.&mt('Next').'" '.
3600: 'onclick="javascript:checksubmit(this.form,\'Next\');" target="_self" /> ';
3601: $endform.='<span class="LC_warning">'.
3602: &mt('(Next and Previous (student) do not save the scores.)').
3603: '</span>'."\n" ;
3604: $endform.="<input type='hidden' value='".&get_increment().
3605: "' name='increment' />";
3606: $endform.='</td></tr></table></form>';
3607: $request->print($endform);
3608: }
3609: return '';
3610: }
3611:
3612: sub show_last_submission {
3613: my ($uname,$udom,$symb,$essayurl,$responseType,$viewtype,$is_tool,$fullname,
3614: $record,$coursedesc_by_cid) = @_;
1.792 raeburn 3615: my ($string,$timestamp,$lastgradetime,$lastsubmittime) =
1.793 raeburn 3616: &get_last_submission($record,$is_tool);
1.468 albertel 3617:
1.793 raeburn 3618: my ($lastsubonly,$partinfo);
1.792 raeburn 3619: if ($timestamp eq '') {
1.793 raeburn 3620: $lastsubonly.='<div class="LC_grade_submissions_body">'.$string->[0].'</div>';
1.745 raeburn 3621: } elsif ($is_tool) {
3622: $lastsubonly =
3623: '<div class="LC_grade_submissions_body">'
1.792 raeburn 3624: .'<b>'.&mt('Date Grade Passed Back:').'</b> '.$timestamp."</div>\n";
1.702 kruse 3625: } else {
1.792 raeburn 3626: my ($shownsubmdate,$showngradedate);
3627: if ($lastsubmittime && $lastgradetime) {
3628: $shownsubmdate = &Apache::lonlocal::locallocaltime($lastsubmittime);
3629: if ($lastgradetime > $lastsubmittime) {
3630: $showngradedate = &Apache::lonlocal::locallocaltime($lastgradetime);
3631: }
3632: } else {
3633: $shownsubmdate = $timestamp;
3634: }
1.702 kruse 3635: $lastsubonly =
3636: '<div class="LC_grade_submissions_body">'
1.792 raeburn 3637: .'<b>'.&mt('Date Submitted:').'</b> '.$shownsubmdate."\n";
3638: if ($showngradedate) {
3639: $lastsubonly .= '<br /><b>'.&mt('Date Graded:').'</b> '.$showngradedate."\n";
3640: }
1.702 kruse 3641:
1.793 raeburn 3642: my %seenparts;
3643: my @part_response_id = &flatten_responseType($responseType);
3644: foreach my $part (@part_response_id) {
3645: my ($partid,$respid) = @{ $part };
3646: my $display_part=&get_display_part($partid,$symb);
3647: if ($env{"form.$uname:$udom:$partid:submitted_by"}) {
3648: if (exists($seenparts{$partid})) { next; }
3649: $seenparts{$partid}=1;
3650: $partinfo .=
1.702 kruse 3651: '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
3652: ' <b>'.&mt('Collaborative submission by: [_1]',
3653: '<a href="javascript:viewSubmitter(\''.
3654: $env{"form.$uname:$udom:$partid:submitted_by"}.
3655: '\');" target="_self">'.
3656: $$fullname{$env{"form.$uname:$udom:$partid:submitted_by"}}.'</a>').
1.793 raeburn 3657: '<br />';
3658: next;
3659: }
3660: my $responsetype = $responseType->{$partid}->{$respid};
3661: if (!exists($record->{"resource.$partid.$respid.submission"})) {
1.702 kruse 3662: $lastsubonly.="\n".'<div class="LC_grade_submission_part">'.
3663: '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
3664: ' <span class="LC_internal_info">'.
3665: '('.&mt('Response ID: [_1]',$respid).')'.
3666: '</span> '.
1.793 raeburn 3667: '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br /><br /></div>';
3668: next;
3669: }
3670: foreach my $submission (@$string) {
3671: my ($partid,$respid) = ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
3672: if (join('_',@{$part}) ne ($partid.'_'.$respid)) { next; }
3673: my ($ressub,$hide,$draft,$subval) = split(/:/,$submission,4);
3674: # Similarity check
1.702 kruse 3675: my $similar='';
3676: my ($type,$trial,$rndseed);
3677: if ($hide eq 'rand') {
3678: $type = 'randomizetry';
1.793 raeburn 3679: $trial = $record->{"resource.$partid.tries"};
3680: $rndseed = $record->{"resource.$partid.rndseed"};
1.702 kruse 3681: }
1.793 raeburn 3682: if ($env{'form.checkPlag'}) {
3683: my ($oname,$odom,$ocrsid,$oessay,$osim)=
3684: &most_similar($uname,$udom,$symb,$subval);
3685: if ($osim) {
3686: $osim=int($osim*100.0);
1.702 kruse 3687: if ($hide eq 'anon') {
3688: $similar='<hr /><span class="LC_warning">'.&mt("Essay was found to be similar to another essay submitted for this assignment.").'<br />'.
3689: &mt('As the current submission is for an anonymous survey, no other details are available.').'</span><hr />';
3690: } else {
1.793 raeburn 3691: $similar='<hr />';
1.753 raeburn 3692: if ($essayurl eq 'lib/templates/simpleproblem.problem') {
3693: $similar .= '<h3><span class="LC_warning">'.
3694: &mt('Essay is [_1]% similar to an essay by [_2]',
3695: $osim,
3696: &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')').
3697: '</span></h3>';
3698: } else {
3699: my %old_course_desc;
3700: if ($ocrsid ne '') {
1.793 raeburn 3701: if (ref($coursedesc_by_cid->{$ocrsid}) eq 'HASH') {
3702: %old_course_desc = %{$coursedesc_by_cid->{$ocrsid}};
1.753 raeburn 3703: } else {
3704: my $args;
3705: if ($ocrsid ne $env{'request.course.id'}) {
3706: $args = {'one_time' => 1};
3707: }
3708: %old_course_desc =
3709: &Apache::lonnet::coursedescription($ocrsid,$args);
1.793 raeburn 3710: $coursedesc_by_cid->{$ocrsid} = \%old_course_desc;
1.753 raeburn 3711: }
3712: $similar .=
3713: '<h3><span class="LC_warning">'.
3714: &mt('Essay is [_1]% similar to an essay by [_2] in course [_3] (course id [_4]:[_5])',
3715: $osim,
3716: &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')',
3717: $old_course_desc{'description'},
3718: $old_course_desc{'num'},
3719: $old_course_desc{'domain'}).
3720: '</span></h3>';
3721: } else {
3722: $similar .=
3723: '<h3><span class="LC_warning">'.
3724: &mt('Essay is [_1]% similar to an essay by [_2] in an unknown course',
3725: $osim,
3726: &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')').
3727: '</span></h3>';
3728: }
3729: }
3730: $similar .= '<blockquote><i>'.
3731: &keywords_highlight($oessay).
3732: '</i></blockquote><hr />';
1.702 kruse 3733: }
1.793 raeburn 3734: }
3735: }
3736: my $order=&get_order($partid,$respid,$symb,$uname,$udom,
1.702 kruse 3737: undef,$type,$trial,$rndseed);
1.793 raeburn 3738: if (($viewtype eq 'lastonly') ||
3739: ($viewtype eq 'datesub') ||
3740: ($viewtype =~ /^(last|all)$/)) {
3741: my $display_part=&get_display_part($partid,$symb);
1.702 kruse 3742: $lastsubonly.='<div class="LC_grade_submission_part">'.
3743: '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
3744: ' <span class="LC_internal_info">'.
3745: '('.&mt('Response ID: [_1]',$respid).')'.
3746: '</span> ';
1.793 raeburn 3747: my $files=&get_submitted_files($udom,$uname,$partid,$respid,$record);
3748: if (@$files) {
1.702 kruse 3749: if ($hide eq 'anon') {
3750: $lastsubonly.='<br />'.&mt('[quant,_1,file] uploaded to this anonymous survey',scalar(@{$files}));
3751: } else {
3752: $lastsubonly.='<br /><br />'.'<b>'.&mt('Submitted Files:').'</b>'
3753: .'<br /><span class="LC_warning">';
3754: if(@$files == 1) {
3755: $lastsubonly .= &mt('Like all files provided by users, this file may contain viruses!');
1.596 raeburn 3756: } else {
1.702 kruse 3757: $lastsubonly .= &mt('Like all files provided by users, these files may contain viruses!');
3758: }
1.774 raeburn 3759: $lastsubonly .= '</span>';
1.702 kruse 3760: foreach my $file (@$files) {
3761: &Apache::lonnet::allowuploaded('/adm/grades',$file);
3762: $lastsubonly.='<br /><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.&Apache::loncommon::icon($file).'" border="0" alt="" /> '.$file.'</a>';
1.596 raeburn 3763: }
3764: }
1.793 raeburn 3765: $lastsubonly.='<br />';
1.702 kruse 3766: }
3767: if ($hide eq 'anon') {
1.793 raeburn 3768: $lastsubonly.='<br /><b>'.&mt('Anonymous Survey').'</b>';
1.702 kruse 3769: } else {
1.774 raeburn 3770: $lastsubonly.='<br /><b>'.&mt('Submitted Answer:').' </b>';
1.724 raeburn 3771: if ($draft) {
3772: $lastsubonly.= ' <span class="LC_warning">'.&mt('Draft Copy').'</span>';
3773: }
3774: $subval =
1.793 raeburn 3775: &cleanRecord($subval,$responsetype,$symb,$partid,
3776: $respid,$record,$order,undef,$uname,$udom,$type,$trial,$rndseed);
1.724 raeburn 3777: if ($responsetype eq 'essay') {
3778: $subval =~ s{\n}{<br />}g;
3779: }
3780: $lastsubonly.=$subval."\n";
1.702 kruse 3781: }
1.774 raeburn 3782: if ($similar) {$lastsubonly.="<br /><br />$similar\n";}
1.793 raeburn 3783: $lastsubonly.='</div>';
3784: }
1.702 kruse 3785: }
1.773 raeburn 3786: }
1.793 raeburn 3787: $lastsubonly.='</div>'."\n"; # End: LC_grade_submissions_body
1.118 ng 3788: }
1.793 raeburn 3789: return ($lastsubonly,$partinfo);
1.38 ng 3790: }
3791:
1.464 albertel 3792: sub check_collaborators {
3793: my ($symb,$uname,$udom,$record,$handgrade,$counter) = @_;
3794: my ($result,@col_fullnames);
3795: my ($classlist,undef,$fullname) = &getclasslist('all','0');
3796: foreach my $part (keys(%$handgrade)) {
3797: my $ncol = &Apache::lonnet::EXT('resource.'.$part.
3798: '.maxcollaborators',
3799: $symb,$udom,$uname);
3800: next if ($ncol <= 0);
3801: $part =~ s/\_/\./g;
3802: next if ($record->{'resource.'.$part.'.collaborators'} eq '');
3803: my (@good_collaborators, @bad_collaborators);
3804: foreach my $possible_collaborator
1.630 www 3805: (split(/[,;\s]+/,$record->{'resource.'.$part.'.collaborators'})) {
1.464 albertel 3806: $possible_collaborator =~ s/[\$\^\(\)]//g;
3807: next if ($possible_collaborator eq '');
1.631 www 3808: my ($co_name,$co_dom) = split(/:/,$possible_collaborator);
1.464 albertel 3809: $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
3810: next if ($co_name eq $uname && $co_dom eq $udom);
3811: # Doing this grep allows 'fuzzy' specification
3812: my @matches = grep(/^\Q$co_name\E:\Q$co_dom\E$/i,
3813: keys(%$classlist));
3814: if (! scalar(@matches)) {
3815: push(@bad_collaborators, $possible_collaborator);
3816: } else {
3817: push(@good_collaborators, @matches);
3818: }
3819: }
3820: if (scalar(@good_collaborators) != 0) {
1.630 www 3821: $result.='<br />'.&mt('Collaborators:').'<ol>';
1.464 albertel 3822: foreach my $name (@good_collaborators) {
3823: my ($lastname,$givenn) = split(/,/,$$fullname{$name});
3824: push(@col_fullnames, $givenn.' '.$lastname);
1.630 www 3825: $result.='<li>'.$fullname->{$name}.'</li>';
1.464 albertel 3826: }
1.630 www 3827: $result.='</ol><br />'."\n";
1.466 albertel 3828: my ($part)=split(/\./,$part);
1.464 albertel 3829: $result.='<input type="hidden" name="collaborator'.$counter.
3830: '" value="'.$part.':'.(join ':',@good_collaborators).'" />'.
3831: "\n";
3832: }
3833: if (scalar(@bad_collaborators) > 0) {
1.466 albertel 3834: $result.='<div class="LC_warning">';
1.464 albertel 3835: $result.=&mt('This student has submitted [quant,_1,invalid collaborator]: [_2]',scalar(@bad_collaborators),join(', ',@bad_collaborators));
3836: $result .= '</div>';
3837: }
3838: if (scalar(@bad_collaborators > $ncol)) {
1.466 albertel 3839: $result .= '<div class="LC_warning">';
1.464 albertel 3840: $result .= &mt('This student has submitted too many '.
3841: 'collaborators. Maximum is [_1].',$ncol);
3842: $result .= '</div>';
3843: }
3844: }
3845: return ($result,$fullname,\@col_fullnames);
3846: }
3847:
1.44 ng 3848: #--- Retrieve the last submission for all the parts
1.38 ng 3849: sub get_last_submission {
1.745 raeburn 3850: my ($returnhash,$is_tool)=@_;
1.792 raeburn 3851: my (@string,$timestamp,$lastgradetime,$lastsubmittime);
1.119 ng 3852: if ($$returnhash{'version'}) {
1.46 ng 3853: my %lasthash=();
1.792 raeburn 3854: my %prevsolved=();
3855: my %solved=();
3856: my $version;
1.119 ng 3857: for ($version=1;$version<=$$returnhash{'version'};$version++) {
1.792 raeburn 3858: my %handgraded = ();
1.397 albertel 3859: foreach my $key (sort(split(/\:/,
3860: $$returnhash{$version.':keys'}))) {
3861: $lasthash{$key}=$$returnhash{$version.':'.$key};
1.792 raeburn 3862: if ($key =~ /\.([^.]+)\.regrader$/) {
3863: $handgraded{$1} = 1;
3864: } elsif ($key =~ /\.portfiles$/) {
3865: if (($$returnhash{$version.':'.$key} ne '') &&
3866: ($$returnhash{$version.':'.$key} !~ /\.\d+\.\w+$/)) {
3867: $lastsubmittime = $$returnhash{$version.':timestamp'};
3868: }
3869: } elsif ($key =~ /\.submission$/) {
3870: if ($$returnhash{$version.':'.$key} ne '') {
3871: $lastsubmittime = $$returnhash{$version.':timestamp'};
3872: }
3873: } elsif ($key =~ /\.([^.]+)\.solved$/) {
3874: $prevsolved{$1} = $solved{$1};
3875: $solved{$1} = $lasthash{$key};
3876: }
3877: }
3878: foreach my $partid (keys(%handgraded)) {
3879: if (($prevsolved{$partid} eq 'ungraded_attempted') &&
3880: (($solved{$partid} eq 'incorrect_by_override') ||
3881: ($solved{$partid} eq 'correct_by_override'))) {
3882: $lastgradetime = $$returnhash{$version.':timestamp'};
3883: }
3884: if ($solved{$partid} ne '') {
3885: $prevsolved{$partid} = $solved{$partid};
3886: }
1.46 ng 3887: }
3888: }
1.795 raeburn 3889: #
3890: # Timestamp is for last transaction for this resource, which does not
3891: # necessarily correspond to the time of last submission for problem (or part).
3892: #
3893: if ($lasthash{'timestamp'} ne '') {
3894: $timestamp = &Apache::lonlocal::locallocaltime($lasthash{'timestamp'});
3895: }
1.640 raeburn 3896: my (%typeparts,%randombytry);
1.596 raeburn 3897: my $showsurv =
3898: &Apache::lonnet::allowed('vas',$env{'request.course.id'});
3899: foreach my $key (sort(keys(%lasthash))) {
3900: if ($key =~ /\.type$/) {
3901: if (($lasthash{$key} eq 'anonsurvey') ||
1.640 raeburn 3902: ($lasthash{$key} eq 'anonsurveycred') ||
3903: ($lasthash{$key} eq 'randomizetry')) {
1.596 raeburn 3904: my ($ign,@parts) = split(/\./,$key);
3905: pop(@parts);
1.641 raeburn 3906: my $id = join('.',@parts);
1.640 raeburn 3907: if ($lasthash{$key} eq 'randomizetry') {
3908: $randombytry{$ign.'.'.$id} = $lasthash{$key};
3909: } else {
3910: unless ($showsurv) {
3911: $typeparts{$ign.'.'.$id} = $lasthash{$key};
3912: }
1.596 raeburn 3913: }
3914: delete($lasthash{$key});
3915: }
3916: }
3917: }
3918: my @hidden = keys(%typeparts);
1.640 raeburn 3919: my @randomize = keys(%randombytry);
1.397 albertel 3920: foreach my $key (keys(%lasthash)) {
3921: next if ($key !~ /\.submission$/);
1.596 raeburn 3922: my $hide;
3923: if (@hidden) {
3924: foreach my $id (@hidden) {
3925: if ($key =~ /^\Q$id\E/) {
1.640 raeburn 3926: $hide = 'anon';
1.596 raeburn 3927: last;
3928: }
3929: }
3930: }
1.640 raeburn 3931: unless ($hide) {
3932: if (@randomize) {
1.732 raeburn 3933: foreach my $id (@randomize) {
1.640 raeburn 3934: if ($key =~ /^\Q$id\E/) {
3935: $hide = 'rand';
3936: last;
3937: }
3938: }
3939: }
3940: }
1.397 albertel 3941: my ($partid,$foo) = split(/submission$/,$key);
1.724 raeburn 3942: my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ? 1 : 0;
3943: push(@string, join(':', $key, $hide, $draft, (
1.716 bisitz 3944: ref($lasthash{$key}) eq 'ARRAY' ?
3945: join(',', @{$lasthash{$key}}) : $lasthash{$key}) ));
1.41 ng 3946: }
3947: }
1.397 albertel 3948: if (!@string) {
1.745 raeburn 3949: my $msg;
3950: if ($is_tool) {
1.747 raeburn 3951: $msg = &mt('No grade passed back.');
1.745 raeburn 3952: } else {
3953: $msg = &mt('Nothing submitted - no attempts.');
3954: }
1.397 albertel 3955: $string[0] =
1.745 raeburn 3956: '<span class="LC_warning">'.$msg.'</span>';
1.397 albertel 3957: }
1.792 raeburn 3958: return (\@string,$timestamp,$lastgradetime,$lastsubmittime);
1.38 ng 3959: }
1.35 ng 3960:
1.44 ng 3961: #--- High light keywords, with style choosen by user.
1.38 ng 3962: sub keywords_highlight {
1.44 ng 3963: my $string = shift;
1.257 albertel 3964: my $size = $env{'form.kwsize'} eq '0' ? '' : 'size='.$env{'form.kwsize'};
3965: my $styleon = $env{'form.kwstyle'} eq '' ? '' : $env{'form.kwstyle'};
1.41 ng 3966: (my $styleoff = $styleon) =~ s/\</\<\//;
1.257 albertel 3967: my @keylist = split(/[,\s+]/,$env{'form.keywords'});
1.398 albertel 3968: foreach my $keyword (@keylist) {
3969: $string =~ s/\b\Q$keyword\E(\b|\.)/<font color\=$env{'form.kwclr'} $size\>$styleon$keyword$styleoff<\/font>/gi;
1.41 ng 3970: }
3971: return $string;
1.38 ng 3972: }
1.36 ng 3973:
1.671 raeburn 3974: # For Tasks provide a mechanism to display previous version for one specific student
3975:
3976: sub show_previous_task_version {
3977: my ($request,$symb) = @_;
3978: if ($symb eq '') {
1.717 bisitz 3979: $request->print(
3980: '<span class="LC_error">'.
3981: &mt('Unable to handle ambiguous references.').
3982: '</span>');
1.671 raeburn 3983: return '';
3984: }
3985: my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
3986: my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
3987: if (!&canview($usec)) {
1.712 bisitz 3988: $request->print(
3989: '<span class="LC_warning">'.
1.713 bisitz 3990: &mt('Unable to view previous version for requested student.').
1.712 bisitz 3991: ' '.&mt('([_1] in section [_2] in course id [_3])',
3992: $uname.':'.$udom,$usec,$env{'request.course.id'}).
3993: '</span>');
1.671 raeburn 3994: return;
3995: }
3996: my $mode = 'both';
3997: my $isTask = ($symb =~/\.task$/);
3998: if ($isTask) {
3999: if ($env{'form.previousversion'} =~ /^\d+$/) {
4000: if ($env{'form.fullname'} eq '') {
4001: $env{'form.fullname'} =
4002: &Apache::loncommon::plainname($uname,$udom,'lastname');
4003: }
4004: my $probtitle=&Apache::lonnet::gettitle($symb);
4005: $request->print("\n\n".
4006: '<div class="LC_grade_show_user">'.
4007: '<h2>'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
4008: '</h2>'."\n");
4009: &Apache::lonxml::clear_problem_counter();
4010: $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode,
4011: {'previousversion' => $env{'form.previousversion'} }));
4012: $request->print("\n</div>");
4013: }
4014: }
4015: return;
4016: }
4017:
4018: sub choose_task_version_form {
4019: my ($symb,$uname,$udom,$nomenu) = @_;
4020: my $isTask = ($symb =~/\.task$/);
4021: my ($current,$version,$result,$js,$displayed,$rowtitle);
4022: if ($isTask) {
4023: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
4024: $udom,$uname);
4025: if (($record{'resource.0.version'} eq '') ||
4026: ($record{'resource.0.version'} < 2)) {
4027: return ($record{'resource.0.version'},
4028: $record{'resource.0.version'},$result,$js);
4029: } else {
4030: $current = $record{'resource.0.version'};
4031: }
4032: if ($env{'form.previousversion'}) {
4033: $displayed = $env{'form.previousversion'};
4034: $rowtitle = &mt('Choose another version:')
4035: } else {
4036: $displayed = $current;
4037: $rowtitle = &mt('Show earlier version:');
4038: }
4039: $result = '<div class="LC_left_float">';
4040: my $list;
4041: my $numversions = 0;
4042: for (my $i=1; $i<=$record{'resource.0.version'}; $i++) {
4043: if ($i == $current) {
4044: if (!$env{'form.previousversion'} || $nomenu) {
4045: next;
4046: } else {
4047: $list .= '<option value="'.$i.'">'.&mt('Current').'</option>'."\n";
4048: $numversions ++;
4049: }
4050: } elsif (defined($record{'resource.'.$i.'.0.status'})) {
4051: unless ($i == $env{'form.previousversion'}) {
4052: $numversions ++;
4053: }
4054: $list .= '<option value="'.$i.'">'.$i.'</option>'."\n";
4055: }
4056: }
4057: if ($numversions) {
4058: $symb = &HTML::Entities::encode($symb,'<>"&');
4059: $result .=
4060: '<form name="getprev" method="post" action=""'.
4061: ' onsubmit="return previousVersion('."'$uname','$udom','$symb','$displayed'".');">'.
4062: &Apache::loncommon::start_data_table().
4063: &Apache::loncommon::start_data_table_row().
4064: '<th align="left">'.$rowtitle.'</th>'.
4065: '<td><select name="version">'.
4066: '<option>'.&mt('Select').'</option>'.
4067: $list.
4068: '</select></td>'.
4069: &Apache::loncommon::end_data_table_row();
4070: unless ($nomenu) {
4071: $result .= &Apache::loncommon::start_data_table_row().
4072: '<th align="left">'.&mt('Open in new window').'</th>'.
4073: '<td><span class="LC_nobreak">'.
4074: '<label><input type="radio" name="prevwin" value="1" />'.
4075: &mt('Yes').'</label>'.
4076: '<label><input type="radio" name="prevwin" value="0" checked="checked" />'.&mt('No').'</label>'.
4077: '</span></td>'.
4078: &Apache::loncommon::end_data_table_row();
4079: }
4080: $result .=
4081: &Apache::loncommon::start_data_table_row().
4082: '<th align="left"> </th>'.
4083: '<td>'.
4084: '<input type="submit" name="prevsub" value="'.&mt('Display').'" />'.
4085: '</td>'.
4086: &Apache::loncommon::end_data_table_row().
4087: &Apache::loncommon::end_data_table().
4088: '</form>';
4089: $js = &previous_display_javascript($nomenu,$current);
4090: } elsif ($displayed && $nomenu) {
4091: $result .= '<a href="javascript:window.close()">'.&mt('Close window').'</a>';
4092: } else {
4093: $result .= &mt('No previous versions to show for this student');
4094: }
4095: $result .= '</div>';
4096: }
4097: return ($current,$displayed,$result,$js);
4098: }
4099:
4100: sub previous_display_javascript {
4101: my ($nomenu,$current) = @_;
4102: my $js = <<"JSONE";
4103: <script type="text/javascript">
4104: // <![CDATA[
4105: function previousVersion(uname,udom,symb) {
4106: var current = '$current';
4107: var version = document.getprev.version.options[document.getprev.version.selectedIndex].value;
4108: var prevstr = new RegExp("^\\\\d+\$");
4109: if (!prevstr.test(version)) {
4110: return false;
4111: }
4112: var url = '';
4113: if (version == current) {
4114: url = '/adm/grades?student='+uname+'&userdom='+udom+'&symb='+symb+'&command=submission';
4115: } else {
4116: url = '/adm/grades?student='+uname+'&userdom='+udom+'&symb='+symb+'&command=versionsub&previousversion='+version;
4117: }
4118: JSONE
4119: if ($nomenu) {
4120: $js .= <<"JSTWO";
4121: document.location.href = url;
4122: JSTWO
4123: } else {
4124: $js .= <<"JSTHREE";
4125: var newwin = 0;
4126: for (var i=0; i<document.getprev.prevwin.length; i++) {
4127: if (document.getprev.prevwin[i].checked == true) {
4128: newwin = document.getprev.prevwin[i].value;
4129: }
4130: }
4131: if (newwin == 1) {
4132: var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
4133: url = url+'&inhibitmenu=yes';
4134: if (typeof(previousWin) == 'undefined' || previousWin.closed) {
4135: previousWin = window.open(url,'',options,1);
4136: } else {
4137: previousWin.location.href = url;
4138: }
4139: previousWin.focus();
4140: return false;
4141: } else {
4142: document.location.href = url;
4143: return false;
4144: }
4145: JSTHREE
4146: }
4147: $js .= <<"ENDJS";
4148: return false;
4149: }
4150: // ]]>
4151: </script>
4152: ENDJS
4153:
4154: }
4155:
1.44 ng 4156: #--- Called from submission routine
1.38 ng 4157: sub processHandGrade {
1.608 www 4158: my ($request,$symb) = @_;
1.324 albertel 4159: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.257 albertel 4160: my $button = $env{'form.gradeOpt'};
4161: my $ngrade = $env{'form.NCT'};
4162: my $ntstu = $env{'form.NTSTU'};
1.301 albertel 4163: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4164: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.786 raeburn 4165: my ($res_error,%queueable);
4166: my ($partlist,$handgrade,$responseType,$numresp,$numessay) = &response_type($symb,\$res_error);
4167: if ($res_error) {
4168: $request->print(&navmap_errormsg());
4169: return;
4170: } else {
4171: foreach my $part (@{$partlist}) {
4172: if (ref($responseType->{$part}) eq 'HASH') {
4173: foreach my $id (keys(%{$responseType->{$part}})) {
4174: if (($responseType->{$part}->{$id} eq 'essay') ||
4175: (lc($handgrade->{$part.'_'.$id}) eq 'yes')) {
4176: $queueable{$part} = 1;
4177: last;
4178: }
4179: }
4180: }
4181: }
4182: }
1.301 albertel 4183:
1.44 ng 4184: if ($button eq 'Save & Next') {
1.798 raeburn 4185: my %needpb = &passbacks_for_symb($cdom,$cnum,$symb);
4186: my (%skip_passback,%pbsave,%pbcollab);
1.44 ng 4187: my $ctr = 0;
4188: while ($ctr < $ngrade) {
1.257 albertel 4189: my ($uname,$udom) = split(/:/,$env{'form.unamedom'.$ctr});
1.726 raeburn 4190: my ($errorflag,$pts,$wgt,$numhidden) =
1.798 raeburn 4191: &saveHandGrade($request,$symb,$uname,$udom,$ctr,undef,undef,\%queueable,\%needpb,\%skip_passback,\%pbsave);
1.71 ng 4192: if ($errorflag eq 'no_score') {
4193: $ctr++;
4194: next;
4195: }
1.104 albertel 4196: if ($errorflag eq 'not_allowed') {
1.721 bisitz 4197: $request->print(
4198: '<span class="LC_error">'
4199: .&mt('Not allowed to modify grades for [_1]',"$uname:$udom")
4200: .'</span>');
1.104 albertel 4201: $ctr++;
4202: next;
4203: }
1.726 raeburn 4204: if ($numhidden) {
4205: $request->print(
4206: '<span class="LC_info">'
4207: .&mt('For [_1]: [quant,_2,transaction] hidden',"$uname:$udom",$numhidden)
4208: .'</span><br />');
4209: }
1.257 albertel 4210: my $includemsg = $env{'form.includemsg'.$ctr};
1.44 ng 4211: my ($subject,$message,$msgstatus) = ('','','');
1.418 albertel 4212: my $restitle = &Apache::lonnet::gettitle($symb);
4213: my ($feedurl,$showsymb) =
4214: &get_feedurl_and_symb($symb,$uname,$udom);
4215: my $messagetail;
1.62 albertel 4216: if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.298 www 4217: $subject = $env{'form.msgsub'} if ($includemsg =~ /msgsub/);
1.295 www 4218: unless ($subject=~/\w/) { $subject=&mt('Grading Feedback'); }
1.386 raeburn 4219: $subject.=' ['.$restitle.']';
1.44 ng 4220: my (@msgnum) = split(/,/,$includemsg);
4221: foreach (@msgnum) {
1.257 albertel 4222: $message.=$env{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
1.44 ng 4223: }
1.80 ng 4224: $message =&Apache::lonfeedback::clear_out_html($message);
1.298 www 4225: if ($env{'form.withgrades'.$ctr}) {
4226: $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
1.386 raeburn 4227: $messagetail = " for <a href=\"".
1.605 www 4228: $feedurl."?symb=$showsymb\">$restitle</a>";
1.386 raeburn 4229: }
4230: $msgstatus =
4231: &Apache::lonmsg::user_normal_msg($uname,$udom,$subject,
4232: $message.$messagetail,
1.418 albertel 4233: undef,$feedurl,undef,
1.386 raeburn 4234: undef,undef,$showsymb,
4235: $restitle);
1.574 bisitz 4236: $request->print('<br />'.&mt('Sending message to [_1]',$uname.':'.$udom).': '.
1.652 raeburn 4237: $msgstatus.'<br />');
1.44 ng 4238: }
1.257 albertel 4239: if ($env{'form.collaborator'.$ctr}) {
1.155 albertel 4240: my @collabstrs=&Apache::loncommon::get_env_multiple("form.collaborator$ctr");
1.150 albertel 4241: foreach my $collabstr (@collabstrs) {
4242: my ($part,@collaborators) = split(/:/,$collabstr);
1.310 banghart 4243: foreach my $collaborator (@collaborators) {
1.150 albertel 4244: my ($errorflag,$pts,$wgt) =
1.324 albertel 4245: &saveHandGrade($request,$symb,$collaborator,$udom,$ctr,
1.798 raeburn 4246: $env{'form.unamedom'.$ctr},$part,\%queueable,\%needpb,\%skip_passback,%pbsave);
1.150 albertel 4247: if ($errorflag eq 'not_allowed') {
1.362 albertel 4248: $request->print("<span class=\"LC_error\">".&mt('Not allowed to modify grades for [_1]',"$collaborator:$udom")."</span>");
1.150 albertel 4249: next;
1.798 raeburn 4250: } else {
4251: $pbcollab{$collaborator}{$part} = [$pts,$wgt];
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))) {
4270: # FIXME passback scores for collaborators
4271: }
1.44 ng 4272: }
4273:
1.773 raeburn 4274: my %keyhash = ();
4275: if ($numessay) {
1.119 ng 4276: # Keywords sorted in alphabatical order
1.257 albertel 4277: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
4278: $env{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
1.775 raeburn 4279: $env{'form.keywords'} =~ s/^\s+|\s+$//g;
1.257 albertel 4280: my (@keywords) = sort(split(/\s+/,$env{'form.keywords'}));
4281: $env{'form.keywords'} = join(' ',@keywords);
4282: $keyhash{$symb.'_keywords'} = $env{'form.keywords'};
4283: $keyhash{$symb.'_subject'} = $env{'form.msgsub'};
4284: $keyhash{$loginuser.'_kwclr'} = $env{'form.kwclr'};
4285: $keyhash{$loginuser.'_kwsize'} = $env{'form.kwsize'};
4286: $keyhash{$loginuser.'_kwstyle'} = $env{'form.kwstyle'};
1.773 raeburn 4287: }
1.119 ng 4288:
1.773 raeburn 4289: if ($env{'form.compmsg'}) {
1.119 ng 4290: # message center - Order of message gets changed. Blank line is eliminated.
1.257 albertel 4291: # New messages are saved in env for the next student.
1.119 ng 4292: # All messages are saved in nohist_handgrade.db
4293: my ($ctr,$idx) = (1,1);
1.257 albertel 4294: while ($ctr <= $env{'form.savemsgN'}) {
4295: if ($env{'form.savemsg'.$ctr} ne '') {
4296: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.savemsg'.$ctr};
1.119 ng 4297: $idx++;
4298: }
4299: $ctr++;
1.41 ng 4300: }
1.119 ng 4301: $ctr = 0;
4302: while ($ctr < $ngrade) {
1.257 albertel 4303: if ($env{'form.newmsg'.$ctr} ne '') {
1.773 raeburn 4304: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.newmsg'.$ctr};
4305: $env{'form.savemsg'.$idx} = $env{'form.newmsg'.$ctr};
4306: $idx++;
1.119 ng 4307: }
4308: $ctr++;
1.41 ng 4309: }
1.257 albertel 4310: $env{'form.savemsgN'} = --$idx;
4311: $keyhash{$symb.'_savemsgN'} = $env{'form.savemsgN'};
1.41 ng 4312: }
1.773 raeburn 4313: if (($numessay) || ($env{'form.compmsg'})) {
4314: my $putresult = &Apache::lonnet::put
4315: ('nohist_handgrade',\%keyhash,$cdom,$cnum);
4316: }
4317:
1.44 ng 4318: # Called by Save & Refresh from Highlight Attribute Window
1.257 albertel 4319: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
4320: if ($env{'form.refresh'} eq 'on') {
1.86 ng 4321: my ($ctr,$total) = (0,0);
4322: while ($ctr < $ngrade) {
1.257 albertel 4323: $total++ if $env{'form.unamedom'.$ctr} ne '';
1.86 ng 4324: $ctr++;
4325: }
1.257 albertel 4326: $env{'form.NTSTU'}=$ngrade;
1.86 ng 4327: $ctr = 0;
4328: while ($ctr < $total) {
1.257 albertel 4329: my $processUser = $env{'form.unamedom'.$ctr};
4330: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
4331: $env{'form.fullname'} = $$fullname{$processUser};
1.625 www 4332: &submission($request,$ctr,$total-1,$symb);
1.41 ng 4333: $ctr++;
4334: }
4335: return '';
4336: }
1.36 ng 4337:
1.44 ng 4338: # Get the next/previous one or group of students
1.257 albertel 4339: my $firststu = $env{'form.unamedom0'};
4340: my $laststu = $env{'form.unamedom'.($ngrade-1)};
1.119 ng 4341: my $ctr = 2;
1.41 ng 4342: while ($laststu eq '') {
1.257 albertel 4343: $laststu = $env{'form.unamedom'.($ngrade-$ctr)};
1.41 ng 4344: $ctr++;
4345: $laststu = $firststu if ($ctr > $ngrade);
4346: }
1.44 ng 4347:
1.41 ng 4348: my (@parsedlist,@nextlist);
4349: my ($nextflg) = 0;
1.524 raeburn 4350: foreach my $item (sort
1.294 albertel 4351: {
4352: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
4353: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
4354: }
4355: return $a cmp $b;
4356: } (keys(%$fullname))) {
1.41 ng 4357: if ($nextflg == 1 && $button =~ /Next$/) {
1.524 raeburn 4358: push(@parsedlist,$item);
1.41 ng 4359: }
1.524 raeburn 4360: $nextflg = 1 if ($item eq $laststu);
1.41 ng 4361: if ($button eq 'Previous') {
1.524 raeburn 4362: last if ($item eq $firststu);
4363: push(@parsedlist,$item);
1.41 ng 4364: }
4365: }
4366: $ctr = 0;
4367: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
4368: foreach my $student (@parsedlist) {
1.257 albertel 4369: my $submitonly=$env{'form.submitonly'};
1.41 ng 4370: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 4371:
4372: if ($submitonly eq 'queued') {
4373: my %queue_status =
4374: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
4375: $udom,$uname);
4376: next if (!defined($queue_status{'gradingqueue'}));
4377: }
4378:
1.156 albertel 4379: if ($submitonly =~ /^(yes|graded|incorrect)$/) {
1.257 albertel 4380: # my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 4381: my %status=&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 4382: my $submitted = 0;
1.248 albertel 4383: my $ungraded = 0;
4384: my $incorrect = 0;
1.524 raeburn 4385: foreach my $item (keys(%status)) {
4386: $submitted = 1 if ($status{$item} ne 'nothing');
4387: $ungraded = 1 if ($status{$item} =~ /^ungraded/);
4388: $incorrect = 1 if ($status{$item} =~ /^incorrect/);
4389: my ($foo,$partid,$foo1) = split(/\./,$item);
1.145 albertel 4390: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
4391: $submitted = 0;
4392: }
1.41 ng 4393: }
1.156 albertel 4394: next if (!$submitted && ($submitonly eq 'yes' ||
4395: $submitonly eq 'incorrect' ||
4396: $submitonly eq 'graded'));
1.248 albertel 4397: next if (!$ungraded && ($submitonly eq 'graded'));
4398: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 4399: }
1.524 raeburn 4400: push(@nextlist,$student) if ($ctr < $ntstu);
1.129 ng 4401: last if ($ctr == $ntstu);
1.41 ng 4402: $ctr++;
4403: }
1.36 ng 4404:
1.41 ng 4405: $ctr = 0;
4406: my $total = scalar(@nextlist)-1;
1.39 ng 4407:
1.524 raeburn 4408: foreach (sort(@nextlist)) {
1.41 ng 4409: my ($uname,$udom,$submitter) = split(/:/);
1.257 albertel 4410: $env{'form.student'} = $uname;
4411: $env{'form.userdom'} = $udom;
4412: $env{'form.fullname'} = $$fullname{$_};
1.625 www 4413: &submission($request,$ctr,$total,$symb);
1.41 ng 4414: $ctr++;
4415: }
4416: if ($total < 0) {
1.653 raeburn 4417: my $the_end.='<p>'.&mt('[_1]Message:[_2] No more students for this section or class.','<b>','</b>').'</p>'."\n";
1.41 ng 4418: $request->print($the_end);
4419: }
4420: return '';
1.38 ng 4421: }
1.36 ng 4422:
1.44 ng 4423: #---- Save the score and award for each student, if changed
1.38 ng 4424: sub saveHandGrade {
1.798 raeburn 4425: my ($request,$symb,$stuname,$domain,$newflg,$submitter,$part,$queueable,$needpb,$skip_passback,$pbsave) = @_;
1.342 banghart 4426: my @version_parts;
1.104 albertel 4427: my $usec = &Apache::lonnet::getsection($domain,$stuname,
1.257 albertel 4428: $env{'request.course.id'});
1.104 albertel 4429: if (!&canmodify($usec)) { return('not_allowed'); }
1.337 banghart 4430: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
1.251 banghart 4431: my @parts_graded;
1.77 ng 4432: my %newrecord = ();
1.726 raeburn 4433: my ($pts,$wgt,$totchg) = ('','',0);
1.269 raeburn 4434: my %aggregate = ();
4435: my $aggregateflag = 0;
1.798 raeburn 4436: my $sendupdate;
1.726 raeburn 4437: if ($env{'form.HIDE'.$newflg}) {
1.727 raeburn 4438: my ($version,$parts) = split(/:/,$env{'form.HIDE'.$newflg},2);
1.728 raeburn 4439: my $numchgs = &makehidden($version,$parts,\%record,$symb,$domain,$stuname,1);
1.726 raeburn 4440: $totchg += $numchgs;
1.798 raeburn 4441: if ($numchgs) {
4442: $sendupdate = 1;
4443: }
1.726 raeburn 4444: }
1.798 raeburn 4445: my (%weights,%awardeds,%excuseds);
1.301 albertel 4446: my @parts = split(/:/,$env{'form.partlist'.$newflg});
4447: foreach my $new_part (@parts) {
1.337 banghart 4448: #collaborator ($submi may vary for different parts
1.259 banghart 4449: if ($submitter && $new_part ne $part) { next; }
4450: my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
1.798 raeburn 4451: if ($env{'form.WGT'.$newflg.'_'.$new_part} eq '') {
4452: $weights{$symb}{$new_part} = 1;
4453: } else {
4454: $weights{$symb}{$new_part} = $env{'form.WGT'.$newflg.'_'.$new_part};
4455: }
1.125 ng 4456: if ($dropMenu eq 'excused') {
1.798 raeburn 4457: $excuseds{$symb}{$new_part} = 1;
4458: $awardeds{$symb}{$new_part} = '';
1.259 banghart 4459: if ($record{'resource.'.$new_part.'.solved'} ne 'excused') {
4460: $newrecord{'resource.'.$new_part.'.solved'} = 'excused';
4461: if (exists($record{'resource.'.$new_part.'.awarded'})) {
4462: $newrecord{'resource.'.$new_part.'.awarded'} = '';
1.58 albertel 4463: }
1.364 banghart 4464: $newrecord{'resource.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.798 raeburn 4465: $sendupdate = 1;
1.58 albertel 4466: }
1.125 ng 4467: } elsif ($dropMenu eq 'reset status'
1.259 banghart 4468: && exists($record{'resource.'.$new_part.'.solved'})) { #don't bother if no old records -> no attempts
1.524 raeburn 4469: foreach my $key (keys(%record)) {
1.259 banghart 4470: if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
1.197 albertel 4471: }
1.259 banghart 4472: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 4473: "$env{'user.name'}:$env{'user.domain'}";
1.270 albertel 4474: my $totaltries = $record{'resource.'.$part.'.tries'};
4475:
4476: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
4477: [$new_part]);
4478: my $aggtries =$totaltries;
1.269 raeburn 4479: if ($last_resets{$new_part}) {
1.270 albertel 4480: $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
4481: $new_part);
1.269 raeburn 4482: }
1.270 albertel 4483:
4484: my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
1.269 raeburn 4485: if ($aggtries > 0) {
1.327 albertel 4486: &decrement_aggs($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
1.269 raeburn 4487: $aggregateflag = 1;
4488: }
1.798 raeburn 4489: $sendupdate = 1;
4490: $excuseds{$symb}{$new_part} = '';
4491: $awardeds{$symb}{$new_part} = '';
1.125 ng 4492: } elsif ($dropMenu eq '') {
1.259 banghart 4493: $pts = ($env{'form.GD_BOX'.$newflg.'_'.$new_part} ne '' ?
4494: $env{'form.GD_BOX'.$newflg.'_'.$new_part} :
4495: $env{'form.RADVAL'.$newflg.'_'.$new_part});
4496: if ($pts eq '' && $env{'form.GD_SEL'.$newflg.'_'.$new_part} eq '') {
1.153 albertel 4497: next;
4498: }
1.259 banghart 4499: $wgt = $env{'form.WGT'.$newflg.'_'.$new_part} eq '' ? 1 :
4500: $env{'form.WGT'.$newflg.'_'.$new_part};
1.41 ng 4501: my $partial= $pts/$wgt;
1.798 raeburn 4502: $awardeds{$symb}{$new_part} = $partial;
4503: $excuseds{$symb}{$new_part} = '';
1.259 banghart 4504: if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
1.153 albertel 4505: #do not update score for part if not changed.
1.346 banghart 4506: &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
1.153 albertel 4507: next;
1.251 banghart 4508: } else {
1.524 raeburn 4509: push(@parts_graded,$new_part);
1.798 raeburn 4510: $sendupdate = 1;
1.153 albertel 4511: }
1.259 banghart 4512: if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
4513: $newrecord{'resource.'.$new_part.'.awarded'} = $partial;
1.153 albertel 4514: }
1.259 banghart 4515: my $reckey = 'resource.'.$new_part.'.solved';
1.41 ng 4516: if ($partial == 0) {
1.153 albertel 4517: if ($record{$reckey} ne 'incorrect_by_override') {
4518: $newrecord{$reckey} = 'incorrect_by_override';
4519: }
1.41 ng 4520: } else {
1.153 albertel 4521: if ($record{$reckey} ne 'correct_by_override') {
4522: $newrecord{$reckey} = 'correct_by_override';
4523: }
4524: }
4525: if ($submitter &&
1.259 banghart 4526: ($record{'resource.'.$new_part.'.submitted_by'} ne $submitter)) {
4527: $newrecord{'resource.'.$new_part.'.submitted_by'} = $submitter;
1.41 ng 4528: }
1.259 banghart 4529: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 4530: "$env{'user.name'}:$env{'user.domain'}";
1.41 ng 4531: }
1.259 banghart 4532: # unless problem has been graded, set flag to version the submitted files
1.305 banghart 4533: unless ($record{'resource.'.$new_part.'.solved'} =~ /^correct_/ ||
4534: $record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override' ||
4535: $dropMenu eq 'reset status')
4536: {
1.524 raeburn 4537: push(@version_parts,$new_part);
1.259 banghart 4538: }
1.41 ng 4539: }
1.301 albertel 4540: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4541: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4542:
1.344 albertel 4543: if (%newrecord) {
4544: if (@version_parts) {
1.364 banghart 4545: my @changed_keys = &version_portfiles(\%record, \@parts_graded,
4546: $env{'request.course.id'}, $symb, $domain, $stuname, \@version_parts);
1.344 albertel 4547: @newrecord{@changed_keys} = @record{@changed_keys};
1.367 albertel 4548: foreach my $new_part (@version_parts) {
4549: &handback_files($request,$symb,$stuname,$domain,$newflg,
4550: $new_part,\%newrecord);
4551: }
1.259 banghart 4552: }
1.44 ng 4553: &Apache::lonnet::cstore(\%newrecord,$symb,
1.257 albertel 4554: $env{'request.course.id'},$domain,$stuname);
1.380 albertel 4555: &check_and_remove_from_queue(\@parts,\%record,\%newrecord,$symb,
1.786 raeburn 4556: $cdom,$cnum,$domain,$stuname,$queueable);
1.41 ng 4557: }
1.269 raeburn 4558: if ($aggregateflag) {
4559: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 4560: $cdom,$cnum);
1.269 raeburn 4561: }
1.798 raeburn 4562: if (($sendupdate) && (!$submitter)) {
4563: if ((ref($needpb) eq 'HASH') &&
4564: (keys(%{$needpb}))) {
1.802 ! raeburn 4565: &process_passbacks('handgrade',[$symb],$cdom,$cnum,$domain,$stuname,$usec,\%weights,
1.798 raeburn 4566: \%awardeds,\%excuseds,$needpb,$skip_passback,$pbsave);
4567: }
4568: }
1.726 raeburn 4569: return ('',$pts,$wgt,$totchg);
4570: }
4571:
4572: sub makehidden {
1.728 raeburn 4573: my ($version,$parts,$record,$symb,$domain,$stuname,$tolog) = @_;
1.726 raeburn 4574: return unless (ref($record) eq 'HASH');
4575: my %modified;
4576: my $numchanged = 0;
4577: if (exists($record->{$version.':keys'})) {
4578: my $partsregexp = $parts;
4579: $partsregexp =~ s/,/|/g;
4580: foreach my $key (split(/\:/,$record->{$version.':keys'})) {
4581: if ($key =~ /^resource\.(?:$partsregexp)\.([^\.]+)$/) {
4582: my $item = $1;
4583: unless (($item eq 'solved') || ($item =~ /^award(|msg|ed)$/)) {
4584: $modified{$key} = $record->{$version.':'.$key};
4585: }
4586: } elsif ($key =~ m{^(resource\.(?:$partsregexp)\.[^\.]+\.)(.+)$}) {
4587: $modified{$1.'hidden'.$2} = $record->{$version.':'.$key};
4588: } elsif ($key =~ /^(ip|timestamp|host)$/) {
4589: $modified{$key} = $record->{$version.':'.$key};
4590: }
4591: }
4592: if (keys(%modified)) {
4593: if (&Apache::lonnet::putstore($env{'request.course.id'},$symb,$version,\%modified,
1.728 raeburn 4594: $domain,$stuname,$tolog) eq 'ok') {
1.726 raeburn 4595: $numchanged ++;
4596: }
4597: }
4598: }
4599: return $numchanged;
1.36 ng 4600: }
1.322 albertel 4601:
1.380 albertel 4602: sub check_and_remove_from_queue {
1.786 raeburn 4603: my ($parts,$record,$newrecord,$symb,$cdom,$cnum,$domain,$stuname,$queueable) = @_;
1.380 albertel 4604: my @ungraded_parts;
4605: foreach my $part (@{$parts}) {
4606: if ( $record->{ 'resource.'.$part.'.awarded'} eq ''
4607: && $record->{ 'resource.'.$part.'.solved' } ne 'excused'
4608: && $newrecord->{'resource.'.$part.'.awarded'} eq ''
4609: && $newrecord->{'resource.'.$part.'.solved' } ne 'excused'
4610: ) {
1.786 raeburn 4611: if ($queueable->{$part}) {
4612: push(@ungraded_parts, $part);
4613: }
1.380 albertel 4614: }
4615: }
4616: if ( !@ungraded_parts ) {
4617: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,
4618: $cnum,$domain,$stuname);
4619: }
4620: }
4621:
1.337 banghart 4622: sub handback_files {
4623: my ($request,$symb,$stuname,$domain,$newflg,$new_part,$newrecord) = @_;
1.517 raeburn 4624: my $portfolio_root = '/userfiles/portfolio';
1.582 raeburn 4625: my $res_error;
4626: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
4627: if ($res_error) {
4628: $request->print('<br />'.&navmap_errormsg().'<br />');
4629: return;
4630: }
1.654 raeburn 4631: my @handedback;
4632: my $file_msg;
1.375 albertel 4633: my @part_response_id = &flatten_responseType($responseType);
4634: foreach my $part_response_id (@part_response_id) {
4635: my ($part_id,$resp_id) = @{ $part_response_id };
4636: my $part_resp = join('_',@{ $part_response_id });
1.654 raeburn 4637: if (($env{'form.'.$newflg.'_'.$part_resp.'_countreturndoc'} =~ /^\d+$/) & ($new_part eq $part_id)) {
4638: for (my $counter=1; $counter<=$env{'form.'.$newflg.'_'.$part_resp.'_countreturndoc'}; $counter++) {
4639: # if multiple files are uploaded names will be 'returndoc2','returndoc3'
4640: if ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$counter}) {
4641: my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$counter.'.filename'};
1.338 banghart 4642: my ($directory,$answer_file) =
1.654 raeburn 4643: ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$counter} =~ /^(.*?)([^\/]*)$/);
1.338 banghart 4644: my ($answer_name,$answer_ver,$answer_ext) =
1.729 raeburn 4645: &Apache::lonnet::file_name_version_ext($answer_file);
1.355 banghart 4646: my ($portfolio_path) = ($directory =~ /^.+$stuname\/portfolio(.*)/);
1.517 raeburn 4647: my $getpropath = 1;
1.773 raeburn 4648: my ($dir_list,$listerror) =
1.662 raeburn 4649: &Apache::lonnet::dirlist($portfolio_root.$portfolio_path,
4650: $domain,$stuname,$getpropath);
1.729 raeburn 4651: my $version = &Apache::lonnet::get_next_version($answer_name,$answer_ext,$dir_list);
1.686 bisitz 4652: # fix filename
1.355 banghart 4653: my ($save_file_name) = (($directory.$answer_name.".$version.".$answer_ext) =~ /^.+\/${stuname}\/(.*)/);
4654: my $result=&Apache::lonnet::finishuserfileupload($stuname,$domain,
1.654 raeburn 4655: $newflg.'_'.$part_resp.'_returndoc'.$counter,
1.355 banghart 4656: $save_file_name);
1.337 banghart 4657: if ($result !~ m|^/uploaded/|) {
1.536 raeburn 4658: $request->print('<br /><span class="LC_error">'.
4659: &mt('An error occurred ([_1]) while trying to upload [_2].',
1.654 raeburn 4660: $result,$newflg.'_'.$part_resp.'_returndoc'.$counter).
1.536 raeburn 4661: '</span>');
1.356 banghart 4662: } else {
1.360 banghart 4663: # mark the file as read only
1.654 raeburn 4664: push(@handedback,$save_file_name);
1.367 albertel 4665: if (exists($$newrecord{"resource.$new_part.$resp_id.handback"})) {
4666: $$newrecord{"resource.$new_part.$resp_id.handback"}.=',';
4667: }
4668: $$newrecord{"resource.$new_part.$resp_id.handback"} .= $save_file_name;
1.654 raeburn 4669: $file_msg.= '<span class="LC_filename"><a href="/uploaded/'."$domain/$stuname/".$save_file_name.'">'.$save_file_name."</a></span> <br />";
1.337 banghart 4670: }
1.686 bisitz 4671: $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 4672: }
4673: }
4674: }
1.654 raeburn 4675: }
4676: if (@handedback > 0) {
4677: $request->print('<br />');
4678: my @what = ($symb,$env{'request.course.id'},'handback');
4679: &Apache::lonnet::mark_as_readonly($domain,$stuname,\@handedback,\@what);
4680: my $user_lh = &Apache::loncommon::user_lang($stuname,$domain,$env{'request.course.id'});
4681: my ($subject,$message);
4682: if (scalar(@handedback) == 1) {
4683: $subject = &mt_user($user_lh,'File Handed Back by Instructor');
4684: $message = &mt_user($user_lh,'A file has been returned that was originally submitted in response to: ');
4685: } else {
4686: $subject = &mt_user($user_lh,'Files Handed Back by Instructor');
4687: $message = &mt_user($user_lh,'Files have been returned that were originally submitted in response to: ');
4688: }
4689: $message .= "<p><strong>".&Apache::lonnet::gettitle($symb)." </strong></p>";
4690: $message .= &mt_user($user_lh,'The returned file(s) are named: [_1]',"<br />$file_msg <br />").
4691: &mt_user($user_lh,'The file(s) can be found in your [_1]portfolio[_2].','<a href="/adm/portfolio">','</a>');
4692: my ($feedurl,$showsymb) =
4693: &get_feedurl_and_symb($symb,$domain,$stuname);
4694: my $restitle = &Apache::lonnet::gettitle($symb);
4695: $subject .= ' '.&mt_user($user_lh,'(File Returned)').' ['.$restitle.']';
4696: my $msgstatus =
4697: &Apache::lonmsg::user_normal_msg($stuname,$domain,$subject,
4698: $message,undef,$feedurl,undef,undef,undef,$showsymb,
4699: $restitle);
4700: if ($msgstatus) {
4701: $request->print(&mt('Notification message status: [_1]','<span class="LC_info">'.$msgstatus.'</span>').'<br />');
4702: }
4703: }
1.338 banghart 4704: return;
1.337 banghart 4705: }
4706:
1.418 albertel 4707: sub get_feedurl_and_symb {
4708: my ($symb,$uname,$udom) = @_;
4709: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
4710: $url = &Apache::lonnet::clutter($url);
4711: my $encrypturl=&Apache::lonnet::EXT('resource.0.encrypturl',
4712: $symb,$udom,$uname);
4713: if ($encrypturl =~ /^yes$/i) {
4714: &Apache::lonenc::encrypted(\$url,1);
4715: &Apache::lonenc::encrypted(\$symb,1);
4716: }
4717: return ($url,$symb);
4718: }
4719:
1.313 banghart 4720: sub get_submitted_files {
4721: my ($udom,$uname,$partid,$respid,$record) = @_;
4722: my @files;
4723: if ($$record{"resource.$partid.$respid.portfiles"}) {
4724: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
4725: foreach my $file (split(',',$$record{"resource.$partid.$respid.portfiles"})) {
4726: push(@files,$file_url.$file);
4727: }
4728: }
4729: if ($$record{"resource.$partid.$respid.uploadedurl"}) {
4730: push(@files,$$record{"resource.$partid.$respid.uploadedurl"});
4731: }
4732: return (\@files);
4733: }
1.322 albertel 4734:
1.269 raeburn 4735: # ----------- Provides number of tries since last reset.
4736: sub get_num_tries {
4737: my ($record,$last_reset,$part) = @_;
4738: my $timestamp = '';
4739: my $num_tries = 0;
4740: if ($$record{'version'}) {
4741: for (my $version=$$record{'version'};$version>=1;$version--) {
4742: if (exists($$record{$version.':resource.'.$part.'.solved'})) {
4743: $timestamp = $$record{$version.':timestamp'};
4744: if ($timestamp > $last_reset) {
4745: $num_tries ++;
4746: } else {
4747: last;
4748: }
4749: }
4750: }
4751: }
4752: return $num_tries;
4753: }
4754:
4755: # ----------- Determine decrements required in aggregate totals
4756: sub decrement_aggs {
4757: my ($symb,$part,$aggregate,$aggtries,$totaltries,$solvedstatus) = @_;
4758: my %decrement = (
4759: attempts => 0,
4760: users => 0,
4761: correct => 0
4762: );
4763: $decrement{'attempts'} = $aggtries;
4764: if ($solvedstatus =~ /^correct/) {
4765: $decrement{'correct'} = 1;
4766: }
4767: if ($aggtries == $totaltries) {
4768: $decrement{'users'} = 1;
4769: }
1.524 raeburn 4770: foreach my $type (keys(%decrement)) {
1.269 raeburn 4771: $$aggregate{$symb."\0".$part."\0".$type} = -$decrement{$type};
4772: }
4773: return;
4774: }
4775:
4776: # ----------- Determine timestamps for last reset of aggregate totals for parts
4777: sub get_last_resets {
1.270 albertel 4778: my ($symb,$courseid,$partids) =@_;
4779: my %last_resets;
1.269 raeburn 4780: my $cdom = $env{'course.'.$courseid.'.domain'};
4781: my $cname = $env{'course.'.$courseid.'.num'};
1.271 albertel 4782: my @keys;
4783: foreach my $part (@{$partids}) {
4784: push(@keys,"$symb\0$part\0resettime");
4785: }
4786: my %results=&Apache::lonnet::get('nohist_resourcetracker',\@keys,
4787: $cdom,$cname);
4788: foreach my $part (@{$partids}) {
4789: $last_resets{$part}=$results{"$symb\0$part\0resettime"};
1.269 raeburn 4790: }
1.270 albertel 4791: return %last_resets;
1.269 raeburn 4792: }
4793:
1.251 banghart 4794: # ----------- Handles creating versions for portfolio files as answers
4795: sub version_portfiles {
1.343 banghart 4796: my ($record, $parts_graded, $courseid, $symb, $domain, $stu_name, $v_flag) = @_;
1.263 banghart 4797: my $version_parts = join('|',@$v_flag);
1.343 banghart 4798: my @returned_keys;
1.255 banghart 4799: my $parts = join('|', @$parts_graded);
1.277 albertel 4800: foreach my $key (keys(%$record)) {
1.259 banghart 4801: my $new_portfiles;
1.263 banghart 4802: if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
1.342 banghart 4803: my @versioned_portfiles;
1.367 albertel 4804: my @portfiles = split(/\s*,\s*/,$$record{$key});
1.729 raeburn 4805: if (@portfiles) {
4806: &Apache::lonnet::portfiles_versioning($symb,$domain,$stu_name,\@portfiles,
4807: \@versioned_portfiles);
1.252 banghart 4808: }
1.343 banghart 4809: $$record{$key} = join(',',@versioned_portfiles);
4810: push(@returned_keys,$key);
1.251 banghart 4811: }
1.794 raeburn 4812: }
4813: return (@returned_keys);
1.305 banghart 4814: }
4815:
1.44 ng 4816: #--------------------------------------------------------------------------------------
4817: #
4818: #-------------------------- Next few routines handles grading by section or whole class
4819: #
4820: #--- Javascript to handle grading by section or whole class
1.42 ng 4821: sub viewgrades_js {
4822: my ($request) = shift;
4823:
1.539 riegler 4824: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
1.736 damieng 4825: &js_escape(\$alertmsg);
1.597 wenzelju 4826: $request->print(&Apache::lonhtmlcommon::scripttag(<<VIEWJAVASCRIPT));
1.45 ng 4827: function writePoint(partid,weight,point) {
1.125 ng 4828: var radioButton = document.classgrade["RADVAL_"+partid];
4829: var textbox = document.classgrade["TEXTVAL_"+partid];
1.42 ng 4830: if (point == "textval") {
1.125 ng 4831: point = document.classgrade["TEXTVAL_"+partid].value;
1.109 matthew 4832: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 4833: alert("$alertmsg"+parseFloat(point));
1.42 ng 4834: var resetbox = false;
4835: for (var i=0; i<radioButton.length; i++) {
4836: if (radioButton[i].checked) {
4837: textbox.value = i;
4838: resetbox = true;
4839: }
4840: }
4841: if (!resetbox) {
4842: textbox.value = "";
4843: }
4844: return;
4845: }
1.109 matthew 4846: if (parseFloat(point) > parseFloat(weight)) {
4847: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 4848: ") greater than the weight for the part. Accept?");
4849: if (resp == false) {
4850: textbox.value = "";
4851: return;
4852: }
4853: }
1.42 ng 4854: for (var i=0; i<radioButton.length; i++) {
4855: radioButton[i].checked=false;
1.109 matthew 4856: if (parseFloat(point) == i) {
1.42 ng 4857: radioButton[i].checked=true;
4858: }
4859: }
1.41 ng 4860:
1.42 ng 4861: } else {
1.125 ng 4862: textbox.value = parseFloat(point);
1.42 ng 4863: }
1.41 ng 4864: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 4865: var user = document.classgrade["ctr"+i].value;
1.289 albertel 4866: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 4867: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
4868: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
4869: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 4870: if (saveval != "correct") {
4871: scorename.value = point;
1.43 ng 4872: if (selname[0].selected != true) {
4873: selname[0].selected = true;
4874: }
1.42 ng 4875: }
4876: }
1.125 ng 4877: document.classgrade["SELVAL_"+partid][0].selected = true;
1.42 ng 4878: }
4879:
4880: function writeRadText(partid,weight) {
1.125 ng 4881: var selval = document.classgrade["SELVAL_"+partid];
4882: var radioButton = document.classgrade["RADVAL_"+partid];
1.265 www 4883: var override = document.classgrade["FORCE_"+partid].checked;
1.125 ng 4884: var textbox = document.classgrade["TEXTVAL_"+partid];
4885: if (selval[1].selected || selval[2].selected) {
1.42 ng 4886: for (var i=0; i<radioButton.length; i++) {
4887: radioButton[i].checked=false;
4888:
4889: }
4890: textbox.value = "";
4891:
4892: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 4893: var user = document.classgrade["ctr"+i].value;
1.289 albertel 4894: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 4895: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
4896: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
4897: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 4898: if ((saveval != "correct") || override) {
1.42 ng 4899: scorename.value = "";
1.125 ng 4900: if (selval[1].selected) {
4901: selname[1].selected = true;
4902: } else {
4903: selname[2].selected = true;
4904: if (Number(document.classgrade["GD_"+user+"_"+partid+"_tries"].value))
4905: {document.classgrade["GD_"+user+"_"+partid+"_tries"].value = '0';}
4906: }
1.42 ng 4907: }
4908: }
1.43 ng 4909: } else {
4910: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 4911: var user = document.classgrade["ctr"+i].value;
1.289 albertel 4912: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 4913: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
4914: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
4915: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 4916: if ((saveval != "correct") || override) {
1.125 ng 4917: scorename.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
1.43 ng 4918: selname[0].selected = true;
4919: }
4920: }
4921: }
1.42 ng 4922: }
4923:
4924: function changeSelect(partid,user) {
1.125 ng 4925: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
4926: var textbox = document.classgrade["GD_"+user+'_'+partid+"_awarded"];
1.44 ng 4927: var point = textbox.value;
1.125 ng 4928: var weight = document.classgrade["weight_"+partid].value;
1.44 ng 4929:
1.109 matthew 4930: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 4931: alert("$alertmsg"+parseFloat(point));
1.44 ng 4932: textbox.value = "";
4933: return;
4934: }
1.109 matthew 4935: if (parseFloat(point) > parseFloat(weight)) {
4936: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 4937: ") greater than the weight of the part. Accept?");
4938: if (resp == false) {
4939: textbox.value = "";
4940: return;
4941: }
4942: }
1.42 ng 4943: selval[0].selected = true;
4944: }
4945:
4946: function changeOneScore(partid,user) {
1.125 ng 4947: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
4948: if (selval[1].selected || selval[2].selected) {
4949: document.classgrade["GD_"+user+'_'+partid+"_awarded"].value = "";
4950: if (selval[2].selected) {
4951: document.classgrade["GD_"+user+'_'+partid+"_tries"].value = "0";
4952: }
1.269 raeburn 4953: }
1.42 ng 4954: }
4955:
4956: function resetEntry(numpart) {
4957: for (ctpart=0;ctpart<numpart;ctpart++) {
1.125 ng 4958: var partid = document.classgrade["partid_"+ctpart].value;
4959: var radioButton = document.classgrade["RADVAL_"+partid];
4960: var textbox = document.classgrade["TEXTVAL_"+partid];
4961: var selval = document.classgrade["SELVAL_"+partid];
1.42 ng 4962: for (var i=0; i<radioButton.length; i++) {
4963: radioButton[i].checked=false;
4964:
4965: }
4966: textbox.value = "";
4967: selval[0].selected = true;
4968:
4969: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 4970: var user = document.classgrade["ctr"+i].value;
1.289 albertel 4971: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 4972: var resetscore = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
4973: resetscore.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
4974: var resettries = document.classgrade["GD_"+user+"_"+partid+"_tries"];
4975: resettries.value = document.classgrade["GD_"+user+"_"+partid+"_tries_s"].value;
4976: var saveselval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
4977: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 4978: if (saveselval == "excused") {
1.43 ng 4979: if (selname[1].selected == false) { selname[1].selected = true;}
1.42 ng 4980: } else {
1.43 ng 4981: if (selname[0].selected == false) {selname[0].selected = true};
1.42 ng 4982: }
4983: }
1.41 ng 4984: }
1.42 ng 4985: }
4986:
1.41 ng 4987: VIEWJAVASCRIPT
1.42 ng 4988: }
4989:
1.44 ng 4990: #--- show scores for a section or whole class w/ option to change/update a score
1.42 ng 4991: sub viewgrades {
1.608 www 4992: my ($request,$symb) = @_;
1.745 raeburn 4993: my ($is_tool,$toolsymb);
4994: if ($symb =~ /ext\.tool$/) {
4995: $is_tool = 1;
4996: $toolsymb = $symb;
4997: }
1.42 ng 4998: &viewgrades_js($request);
1.41 ng 4999:
1.168 albertel 5000: #need to make sure we have the correct data for later EXT calls,
5001: #thus invalidate the cache
5002: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 5003: $env{'course.'.$env{'request.course.id'}.'.num'},
5004: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 5005: &Apache::lonnet::clear_EXT_cache_status();
5006:
1.398 albertel 5007: my $result='<h3><span class="LC_info">'.&mt('Manual Grading').'</span></h3>';
1.41 ng 5008:
5009: #view individual student submission form - called using Javascript viewOneStudent
1.324 albertel 5010: $result.=&jscriptNform($symb);
1.41 ng 5011:
1.44 ng 5012: #beginning of class grading form
1.442 banghart 5013: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.41 ng 5014: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1.418 albertel 5015: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.38 ng 5016: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.432 banghart 5017: &build_section_inputs().
1.442 banghart 5018: '<input type="hidden" name="Status" value="'.$env{'stu_status'}.'" />'."\n".
1.72 ng 5019:
1.738 raeburn 5020: #retrieve selected groups
5021: my (@groups,$group_display);
5022: @groups = &Apache::loncommon::get_env_multiple('form.group');
5023: if (grep(/^all$/,@groups)) {
5024: @groups = ('all');
5025: } elsif (grep(/^none$/,@groups)) {
5026: @groups = ('none');
5027: } elsif (@groups > 0) {
5028: $group_display = join(', ',@groups);
5029: }
5030:
5031: my ($common_header,$specific_header,@sections,$section_display);
1.780 raeburn 5032: if ($env{'request.course.sec'} ne '') {
5033: @sections = ($env{'request.course.sec'});
5034: } else {
5035: @sections = &Apache::loncommon::get_env_multiple('form.section');
5036: }
5037:
5038: # Check if Save button should be usable
5039: my $disabled = ' disabled="disabled"';
5040: if ($perm{'mgr'}) {
5041: if (grep(/^all$/,@sections)) {
5042: undef($disabled);
5043: } else {
5044: foreach my $sec (@sections) {
5045: if (&canmodify($sec)) {
5046: undef($disabled);
5047: last;
5048: }
5049: }
5050: }
5051: }
1.738 raeburn 5052: if (grep(/^all$/,@sections)) {
5053: @sections = ('all');
5054: if ($group_display) {
5055: $common_header = &mt('Assign Common Grade to Students in Group(s) [_1]',$group_display);
5056: $specific_header = &mt('Assign Grade to Specific Students in Group(s) [_1]',$group_display);
5057: } elsif (grep(/^none$/,@groups)) {
5058: $common_header = &mt('Assign Common Grade to Students not assigned to any groups');
5059: $specific_header = &mt('Assign Grade to Specific Students not assigned to any groups');
5060: } else {
5061: $common_header = &mt('Assign Common Grade to Class');
5062: $specific_header = &mt('Assign Grade to Specific Students in Class');
5063: }
5064: } elsif (grep(/^none$/,@sections)) {
5065: @sections = ('none');
5066: if ($group_display) {
5067: $common_header = &mt('Assign Common Grade to Students in no Section and in Group(s) [_1]',$group_display);
5068: $specific_header = &mt('Assign Grade to Specific Students in no Section and in Group(s)',$group_display);
5069: } elsif (grep(/^none$/,@groups)) {
5070: $common_header = &mt('Assign Common Grade to Students in no Section and in no Group');
5071: $specific_header = &mt('Assign Grade to Specific Students in no Section and in no Group');
5072: } else {
5073: $common_header = &mt('Assign Common Grade to Students in no Section');
5074: $specific_header = &mt('Assign Grade to Specific Students in no Section');
5075: }
5076: } else {
5077: $section_display = join (", ",@sections);
5078: if ($group_display) {
5079: $common_header = &mt('Assign Common Grade to Students in Section(s) [_1], and in Group(s) [_2]',
5080: $section_display,$group_display);
5081: $specific_header = &mt('Assign Grade to Specific Students in Section(s) [_1], and in Group(s) [_2]',
5082: $section_display,$group_display);
5083: } elsif (grep(/^none$/,@groups)) {
5084: $common_header = &mt('Assign Common Grade to Students in Section(s) [_1] and no Group',$section_display);
5085: $specific_header = &mt('Assign Grade to Specific Students in Section(s) [_1] and no Group',$section_display);
5086: } else {
5087: $common_header = &mt('Assign Common Grade to Students in Section(s) [_1]',$section_display);
5088: $specific_header = &mt('Assign Grade to Specific Students in Section(s) [_1]',$section_display);
5089: }
5090: }
5091: my %submit_types = &substatus_options();
5092: my $submission_status = $submit_types{$env{'form.submitonly'}};
5093:
5094: if ($env{'form.submitonly'} eq 'all') {
5095: $result.= '<h3>'.$common_header.'</h3>';
5096: } else {
1.745 raeburn 5097: my $text;
5098: if ($is_tool) {
5099: $text = &mt('(transaction status: "[_1]")',$submission_status);
5100: } else {
5101: $text = &mt('(submission status: "[_1]")',$submission_status);
5102: }
5103: $result.= '<h3>'.$common_header.' '.$text.'</h3>';
1.52 albertel 5104: }
1.738 raeburn 5105: $result .= &Apache::loncommon::start_data_table();
1.44 ng 5106: #radio buttons/text box for assigning points for a section or class.
5107: #handles different parts of a problem
1.582 raeburn 5108: my $res_error;
5109: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
5110: if ($res_error) {
5111: return &navmap_errormsg();
5112: }
1.42 ng 5113: my %weight = ();
5114: my $ctsparts = 0;
1.45 ng 5115: my %seen = ();
1.745 raeburn 5116: my @part_response_id;
5117: if ($is_tool) {
5118: @part_response_id = ([0,'']);
5119: } else {
5120: @part_response_id = &flatten_responseType($responseType);
5121: }
1.375 albertel 5122: foreach my $part_response_id (@part_response_id) {
5123: my ($partid,$respid) = @{ $part_response_id };
5124: my $part_resp = join('_',@{ $part_response_id });
1.45 ng 5125: next if $seen{$partid};
5126: $seen{$partid}++;
1.42 ng 5127: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
5128: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
5129:
1.324 albertel 5130: my $display_part=&get_display_part($partid,$symb);
1.485 albertel 5131: my $radio.='<table border="0"><tr>';
1.41 ng 5132: my $ctr = 0;
1.42 ng 5133: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
1.485 albertel 5134: $radio.= '<td><label><input type="radio" name="RADVAL_'.$partid.'" '.
1.54 albertel 5135: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.288 albertel 5136: ','.$ctr.')" />'.$ctr."</label></td>\n";
1.41 ng 5137: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
5138: $ctr++;
5139: }
1.485 albertel 5140: $radio.='</tr></table>';
5141: my $line = '<input type="text" name="TEXTVAL_'.
1.589 bisitz 5142: $partid.'" size="4" '.'onchange="javascript:writePoint(\''.
1.54 albertel 5143: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.539 riegler 5144: $weight{$partid}.' '.&mt('(problem weight)').'</td>'."\n";
1.701 bisitz 5145: $line.= '<td><b>'.&mt('Grade Status').':</b>'.
5146: '<select name="SELVAL_'.$partid.'" '.
5147: 'onchange="javascript:writeRadText(\''.$partid.'\','.
5148: $weight{$partid}.')"> '.
1.401 albertel 5149: '<option selected="selected"> </option>'.
1.485 albertel 5150: '<option value="excused">'.&mt('excused').'</option>'.
5151: '<option value="reset status">'.&mt('reset status').'</option>'.
5152: '</select></td>'.
5153: '<td><label><input type="checkbox" name="FORCE_'.$partid.'" />'.&mt('Override "Correct"').'</label>';
5154: $line.='<input type="hidden" name="partid_'.
5155: $ctsparts.'" value="'.$partid.'" />'."\n";
5156: $line.='<input type="hidden" name="weight_'.
5157: $partid.'" value="'.$weight{$partid}.'" />'."\n";
5158:
5159: $result.=
5160: &Apache::loncommon::start_data_table_row()."\n".
1.577 bisitz 5161: '<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 5162: &Apache::loncommon::end_data_table_row()."\n";
1.42 ng 5163: $ctsparts++;
1.41 ng 5164: }
1.474 albertel 5165: $result.=&Apache::loncommon::end_data_table()."\n".
1.52 albertel 5166: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.485 albertel 5167: $result.='<input type="button" value="'.&mt('Revert to Default').'" '.
1.589 bisitz 5168: 'onclick="javascript:resetEntry('.$ctsparts.');" />';
1.41 ng 5169:
1.44 ng 5170: #table listing all the students in a section/class
5171: #header of table
1.738 raeburn 5172: if ($env{'form.submitonly'} eq 'all') {
5173: $result.= '<h3>'.$specific_header.'</h3>';
5174: } else {
1.745 raeburn 5175: my $text;
5176: if ($is_tool) {
5177: $text = &mt('(transaction status: "[_1]")',$submission_status);
5178: } else {
5179: $text = &mt('(submission status: "[_1]")',$submission_status);
5180: }
5181: $result.= '<h3>'.$specific_header.' '.$text.'</h3>';
1.738 raeburn 5182: }
5183: $result.= &Apache::loncommon::start_data_table().
1.560 raeburn 5184: &Apache::loncommon::start_data_table_header_row().
5185: '<th>'.&mt('No.').'</th>'.
5186: '<th>'.&nameUserString('header')."</th>\n";
1.582 raeburn 5187: my $partserror;
5188: my (@parts) = sort(&getpartlist($symb,\$partserror));
5189: if ($partserror) {
5190: return &navmap_errormsg();
5191: }
1.324 albertel 5192: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.269 raeburn 5193: my @partids = ();
1.41 ng 5194: foreach my $part (@parts) {
1.745 raeburn 5195: my $display=&Apache::lonnet::metadata($url,$part.'.display',$toolsymb);
1.539 riegler 5196: my $narrowtext = &mt('Tries');
5197: $display =~ s|^Number of Attempts|$narrowtext <br />|; # makes the column narrower
1.745 raeburn 5198: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name',$toolsymb); }
1.207 albertel 5199: my ($partid) = &split_part_type($part);
1.524 raeburn 5200: push(@partids,$partid);
1.628 www 5201: #
5202: # FIXME: Looks like $display looks at English text
5203: #
1.324 albertel 5204: my $display_part=&get_display_part($partid,$symb);
1.41 ng 5205: if ($display =~ /^Partial Credit Factor/) {
1.485 albertel 5206: $result.='<th>'.
1.697 bisitz 5207: &mt('Score Part: [_1][_2](weight = [_3])',
5208: $display_part,'<br />',$weight{$partid}).'</th>'."\n";
1.41 ng 5209: next;
1.485 albertel 5210:
1.207 albertel 5211: } else {
1.485 albertel 5212: if ($display =~ /Problem Status/) {
5213: my $grade_status_mt = &mt('Grade Status');
5214: $display =~ s{Problem Status}{$grade_status_mt<br />};
5215: }
5216: my $part_mt = &mt('Part:');
5217: $display =~s{\[Part: \Q$partid\E\]}{$part_mt $display_part};
1.41 ng 5218: }
1.485 albertel 5219:
1.474 albertel 5220: $result.='<th>'.$display.'</th>'."\n";
1.41 ng 5221: }
1.474 albertel 5222: $result.=&Apache::loncommon::end_data_table_header_row();
1.44 ng 5223:
1.270 albertel 5224: my %last_resets =
5225: &get_last_resets($symb,$env{'request.course.id'},\@partids);
1.269 raeburn 5226:
1.41 ng 5227: #get info for each student
1.44 ng 5228: #list all the students - with points and grade status
1.738 raeburn 5229: my (undef,undef,$fullname) = &getclasslist(\@sections,'1',\@groups);
1.41 ng 5230: my $ctr = 0;
1.294 albertel 5231: foreach (sort
5232: {
5233: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
5234: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
5235: }
5236: return $a cmp $b;
5237: } (keys(%$fullname))) {
1.324 albertel 5238: $result.=&viewstudentgrade($symb,$env{'request.course.id'},
1.745 raeburn 5239: $_,$$fullname{$_},\@parts,\%weight,\$ctr,\%last_resets,$is_tool);
1.41 ng 5240: }
1.474 albertel 5241: $result.=&Apache::loncommon::end_data_table();
1.41 ng 5242: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.780 raeburn 5243: $result.='<input type="button" value="'.&mt('Save').'"'.$disabled.' '.
1.589 bisitz 5244: 'onclick="javascript:submit();" target="_self" /></form>'."\n";
1.738 raeburn 5245: if ($ctr == 0) {
1.442 banghart 5246: my $stu_status = join(' or ',&Apache::loncommon::get_env_multiple('form.Status'));
1.738 raeburn 5247: $result='<h3><span class="LC_info">'.&mt('Manual Grading').'</span></h3>'.
5248: '<span class="LC_warning">';
5249: if ($env{'form.submitonly'} eq 'all') {
5250: if (grep(/^all$/,@sections)) {
5251: if (grep(/^all$/,@groups)) {
5252: $result .= &mt('There are no students with enrollment status [_1] to modify or grade.',
5253: $stu_status);
5254: } elsif (grep(/^none$/,@groups)) {
5255: $result .= &mt('There are no students with no group assigned and with enrollment status [_1] to modify or grade.',
5256: $stu_status);
5257: } else {
5258: $result .= &mt('There are no students in group(s) [_1] with enrollment status [_2] to modify or grade.',
5259: $group_display,$stu_status);
5260: }
5261: } elsif (grep(/^none$/,@sections)) {
5262: if (grep(/^all$/,@groups)) {
5263: $result .= &mt('There are no students in no section with enrollment status [_1] to modify or grade.',
5264: $stu_status);
5265: } elsif (grep(/^none$/,@groups)) {
5266: $result .= &mt('There are no students in no section and no group with enrollment status [_1] to modify or grade.',
5267: $stu_status);
5268: } else {
5269: $result .= &mt('There are no students in no section in group(s) [_1] with enrollment status [_2] to modify or grade.',
5270: $group_display,$stu_status);
5271: }
5272: } else {
5273: if (grep(/^all$/,@groups)) {
5274: $result .= &mt('There are no students in section(s) [_1] with enrollment status [_2] to modify or grade.',
5275: $section_display,$stu_status);
5276: } elsif (grep(/^none$/,@groups)) {
1.739 raeburn 5277: $result .= &mt('There are no students in section(s) [_1] and no group with enrollment status [_2] to modify or grade.',
1.738 raeburn 5278: $section_display,$stu_status);
5279: } else {
5280: $result .= &mt('There are no students in section(s) [_1] and group(s) [_2] with enrollment status [_3] to modify or grade.',
5281: $section_display,$group_display,$stu_status);
5282: }
5283: }
5284: } else {
5285: if (grep(/^all$/,@sections)) {
5286: if (grep(/^all$/,@groups)) {
5287: $result .= &mt('There are no students with enrollment status [_1] and submission status "[_2]" to modify or grade.',
5288: $stu_status,$submission_status);
5289: } elsif (grep(/^none$/,@groups)) {
5290: $result .= &mt('There are no students with no group assigned with enrollment status [_1] and submission status "[_2]" to modify or grade.',
5291: $stu_status,$submission_status);
5292: } else {
5293: $result .= &mt('There are no students in group(s) [_1] with enrollment status [_2] and submission status "[_3]" to modify or grade.',
5294: $group_display,$stu_status,$submission_status);
5295: }
5296: } elsif (grep(/^none$/,@sections)) {
5297: if (grep(/^all$/,@groups)) {
5298: $result .= &mt('There are no students in no section with enrollment status [_1] and submission status "[_2]" to modify or grade.',
5299: $stu_status,$submission_status);
5300: } elsif (grep(/^none$/,@groups)) {
5301: $result .= &mt('There are no students in no section and no group with enrollment status [_1] and submission status "[_2]" to modify or grade.',
5302: $stu_status,$submission_status);
5303: } else {
5304: $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.',
5305: $group_display,$stu_status,$submission_status);
5306: }
5307: } else {
5308: if (grep(/^all$/,@groups)) {
5309: $result .= &mt('There are no students in section(s) [_1] with enrollment status [_2] and submission status "[_3]" to modify or grade.',
5310: $section_display,$stu_status,$submission_status);
5311: } elsif (grep(/^none$/,@groups)) {
5312: $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.',
5313: $section_display,$stu_status,$submission_status);
5314: } else {
5315: $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.',
5316: $section_display,$group_display,$stu_status,$submission_status);
5317: }
5318: }
5319: }
5320: $result .= '</span><br />';
1.96 albertel 5321: }
1.41 ng 5322: return $result;
5323: }
5324:
1.738 raeburn 5325: #--- call by previous routine to display each student who satisfies submission filter.
1.41 ng 5326: sub viewstudentgrade {
1.745 raeburn 5327: my ($symb,$courseid,$student,$fullname,$parts,$weight,$ctr,$last_resets,$is_tool) = @_;
1.44 ng 5328: my ($uname,$udom) = split(/:/,$student);
5329: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.738 raeburn 5330: my $submitonly = $env{'form.submitonly'};
5331: unless (($submitonly eq 'all') || ($submitonly eq 'queued')) {
5332: my %partstatus = ();
5333: if (ref($parts) eq 'ARRAY') {
5334: foreach my $apart (@{$parts}) {
5335: my ($part,$type) = &split_part_type($apart);
5336: my ($status,undef) = split(/_/,$record{"resource.$part.solved"},2);
5337: $status = 'nothing' if ($status eq '');
5338: $partstatus{$part} = $status;
5339: my $subkey = "resource.$part.submitted_by";
5340: $partstatus{$subkey} = $record{$subkey} if ($record{$subkey} ne '');
5341: }
5342: my $submitted = 0;
5343: my $graded = 0;
5344: my $incorrect = 0;
5345: foreach my $key (keys(%partstatus)) {
5346: $submitted = 1 if ($partstatus{$key} ne 'nothing');
5347: $graded = 1 if ($partstatus{$key} =~ /^ungraded/);
5348: $incorrect = 1 if ($partstatus{$key} =~ /^incorrect/);
5349:
5350: my $partid = (split(/\./,$key))[1];
5351: if ($partstatus{'resource.'.$partid.'.'.$key.'.submitted_by'} ne '') {
5352: $submitted = 0;
5353: }
5354: }
5355: return if (!$submitted && ($submitonly eq 'yes' ||
5356: $submitonly eq 'incorrect' ||
5357: $submitonly eq 'graded'));
5358: return if (!$graded && ($submitonly eq 'graded'));
5359: return if (!$incorrect && $submitonly eq 'incorrect');
5360: }
5361: }
5362: if ($submitonly eq 'queued') {
5363: my ($cdom,$cnum) = split(/_/,$courseid);
5364: my %queue_status =
5365: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
5366: $udom,$uname);
5367: return if (!defined($queue_status{'gradingqueue'}));
5368: }
5369: $$ctr++;
5370: my %aggregates = ();
1.474 albertel 5371: my $result=&Apache::loncommon::start_data_table_row().'<td align="right">'.
1.738 raeburn 5372: '<input type="hidden" name="ctr'.($$ctr-1).'" value="'.$student.'" />'.
5373: "\n".$$ctr.' </td><td> '.
1.44 ng 5374: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 5375: '\');" target="_self">'.$fullname.'</a> '.
1.398 albertel 5376: '<span class="LC_internal_info">('.$uname.($env{'user.domain'} eq $udom ? '' : ':'.$udom).')</span></td>'."\n";
1.281 albertel 5377: $student=~s/:/_/; # colon doen't work in javascript for names
1.63 albertel 5378: foreach my $apart (@$parts) {
5379: my ($part,$type) = &split_part_type($apart);
1.41 ng 5380: my $score=$record{"resource.$part.$type"};
1.276 albertel 5381: $result.='<td align="center">';
1.269 raeburn 5382: my ($aggtries,$totaltries);
5383: unless (exists($aggregates{$part})) {
1.270 albertel 5384: $totaltries = $record{'resource.'.$part.'.tries'};
5385: $aggtries = $totaltries;
1.269 raeburn 5386: if ($$last_resets{$part}) {
1.270 albertel 5387: $aggtries = &get_num_tries(\%record,$$last_resets{$part},
5388: $part);
5389: }
1.269 raeburn 5390: $result.='<input type="hidden" name="'.
5391: 'GD_'.$student.'_'.$part.'_aggtries" value="'.$aggtries.'" />'."\n";
5392: $result.='<input type="hidden" name="'.
5393: 'GD_'.$student.'_'.$part.'_totaltries" value="'.$totaltries.'" />'."\n";
5394: $aggregates{$part} = 1;
5395: }
1.41 ng 5396: if ($type eq 'awarded') {
1.320 albertel 5397: my $pts = $score eq '' ? '' : &compute_points($score,$$weight{$part});
1.42 ng 5398: $result.='<input type="hidden" name="'.
1.89 albertel 5399: 'GD_'.$student.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.233 albertel 5400: $result.='<input type="text" name="'.
1.89 albertel 5401: 'GD_'.$student.'_'.$part.'_awarded" '.
1.589 bisitz 5402: 'onchange="javascript:changeSelect(\''.$part.'\',\''.$student.
1.44 ng 5403: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41 ng 5404: } elsif ($type eq 'solved') {
5405: my ($status,$foo)=split(/_/,$score,2);
5406: $status = 'nothing' if ($status eq '');
1.89 albertel 5407: $result.='<input type="hidden" name="'.'GD_'.$student.'_'.
1.54 albertel 5408: $part.'_solved_s" value="'.$status.'" />'."\n";
1.233 albertel 5409: $result.=' <select name="'.
1.89 albertel 5410: 'GD_'.$student.'_'.$part.'_solved" '.
1.589 bisitz 5411: 'onchange="javascript:changeOneScore(\''.$part.'\',\''.$student.'\')" >'."\n";
1.485 albertel 5412: $result.= (($status eq 'excused') ? '<option> </option><option selected="selected" value="excused">'.&mt('excused').'</option>'
5413: : '<option selected="selected"> </option><option value="excused">'.&mt('excused').'</option>')."\n";
5414: $result.='<option value="reset status">'.&mt('reset status').'</option>';
1.126 ng 5415: $result.="</select> </td>\n";
1.122 ng 5416: } else {
5417: $result.='<input type="hidden" name="'.
5418: 'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
5419: "\n";
1.233 albertel 5420: $result.='<input type="text" name="'.
1.122 ng 5421: 'GD_'.$student.'_'.$part.'_'.$type.'" '.
5422: 'value="'.$score.'" size="4" /></td>'."\n";
1.41 ng 5423: }
5424: }
1.474 albertel 5425: $result.=&Apache::loncommon::end_data_table_row();
1.41 ng 5426: return $result;
1.38 ng 5427: }
5428:
1.44 ng 5429: #--- change scores for all the students in a section/class
5430: # record does not get update if unchanged
1.38 ng 5431: sub editgrades {
1.608 www 5432: my ($request,$symb) = @_;
1.745 raeburn 5433: my $toolsymb;
5434: if ($symb =~ /ext\.tool$/) {
5435: $toolsymb = $symb;
5436: }
1.41 ng 5437:
1.433 banghart 5438: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.477 albertel 5439: my $title='<h2>'.&mt('Current Grade Status').'</h2>';
1.768 raeburn 5440: $title.='<h4><b>'.&mt('Section:').'</b> '.$section_display.'</h4>'."\n";
1.126 ng 5441:
1.477 albertel 5442: my $result= &Apache::loncommon::start_data_table().
5443: &Apache::loncommon::start_data_table_header_row().
5444: '<th rowspan="2" valign="middle">'.&mt('No.').'</th>'.
5445: '<th rowspan="2" valign="middle">'.&nameUserString('header')."</th>\n";
1.43 ng 5446: my %scoreptr = (
5447: 'correct' =>'correct_by_override',
5448: 'incorrect'=>'incorrect_by_override',
5449: 'excused' =>'excused',
5450: 'ungraded' =>'ungraded_attempted',
1.596 raeburn 5451: 'credited' =>'credit_attempted',
1.43 ng 5452: 'nothing' => '',
5453: );
1.257 albertel 5454: my ($classlist,undef,$fullname) = &getclasslist($env{'form.section'},'0');
1.34 ng 5455:
1.798 raeburn 5456: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5457: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5458: my %needpb = &passbacks_for_symb($cdom,$cnum,$symb);
5459:
1.44 ng 5460: my (@partid);
5461: my %weight = ();
1.54 albertel 5462: my %columns = ();
1.44 ng 5463: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54 albertel 5464:
1.582 raeburn 5465: my $partserror;
5466: my (@parts) = sort(&getpartlist($symb,\$partserror));
5467: if ($partserror) {
5468: return &navmap_errormsg();
5469: }
1.54 albertel 5470: my $header;
1.257 albertel 5471: while ($ctr < $env{'form.totalparts'}) {
5472: my $partid = $env{'form.partid_'.$ctr};
1.524 raeburn 5473: push(@partid,$partid);
1.257 albertel 5474: $weight{$partid} = $env{'form.weight_'.$partid};
1.44 ng 5475: $ctr++;
1.54 albertel 5476: }
1.324 albertel 5477: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.748 raeburn 5478: my $totcolspan = 0;
1.54 albertel 5479: foreach my $partid (@partid) {
1.478 albertel 5480: $header .= '<th align="center">'.&mt('Old Score').'</th>'.
5481: '<th align="center">'.&mt('New Score').'</th>';
1.54 albertel 5482: $columns{$partid}=2;
5483: foreach my $stores (@parts) {
5484: my ($part,$type) = &split_part_type($stores);
5485: if ($part !~ m/^\Q$partid\E/) { next;}
5486: if ($type eq 'awarded' || $type eq 'solved') { next; }
1.745 raeburn 5487: my $display=&Apache::lonnet::metadata($url,$stores.'.display',$toolsymb);
1.551 raeburn 5488: $display =~ s/\[Part: \Q$part\E\]//;
1.539 riegler 5489: my $narrowtext = &mt('Tries');
5490: $display =~ s/Number of Attempts/$narrowtext/;
5491: $header .= '<th align="center">'.&mt('Old').' '.$display.'</th>'.
5492: '<th align="center">'.&mt('New').' '.$display.'</th>';
1.54 albertel 5493: $columns{$partid}+=2;
5494: }
1.748 raeburn 5495: $totcolspan += $columns{$partid};
1.54 albertel 5496: }
5497: foreach my $partid (@partid) {
1.324 albertel 5498: my $display_part=&get_display_part($partid,$symb);
1.478 albertel 5499: $result .= '<th colspan="'.$columns{$partid}.'" align="center">'.
5500: &mt('Part: [_1] (Weight = [_2])',$display_part,$weight{$partid}).
5501: '</th>';
1.54 albertel 5502:
1.44 ng 5503: }
1.477 albertel 5504: $result .= &Apache::loncommon::end_data_table_header_row().
5505: &Apache::loncommon::start_data_table_header_row().
5506: $header.
5507: &Apache::loncommon::end_data_table_header_row();
5508: my @noupdate;
1.126 ng 5509: my ($updateCtr,$noupdateCtr) = (1,1);
1.798 raeburn 5510: my ($got_types,%queueable,%pbsave,%skip_passback);
1.257 albertel 5511: for ($i=0; $i<$env{'form.total'}; $i++) {
5512: my $user = $env{'form.ctr'.$i};
1.281 albertel 5513: my ($uname,$udom)=split(/:/,$user);
1.44 ng 5514: my %newrecord;
5515: my $updateflag = 0;
1.108 albertel 5516: my $usec=$classlist->{"$uname:$udom"}[5];
1.748 raeburn 5517: my $canmodify = &canmodify($usec);
5518: my $line = '<td'.($canmodify?'':' colspan="2"').'>'.
5519: &nameUserString(undef,$$fullname{$user},$uname,$udom).'</td>';
5520: if (!$canmodify) {
1.477 albertel 5521: push(@noupdate,
1.748 raeburn 5522: $line."<td colspan=\"$totcolspan\"><span class=\"LC_warning\">".
5523: &mt('Not allowed to modify student')."</span></td>");
1.105 albertel 5524: next;
5525: }
1.269 raeburn 5526: my %aggregate = ();
5527: my $aggregateflag = 0;
1.281 albertel 5528: $user=~s/:/_/; # colon doen't work in javascript for names
1.798 raeburn 5529: my (%weights,%awardeds,%excuseds);
1.44 ng 5530: foreach (@partid) {
1.257 albertel 5531: my $old_aw = $env{'form.GD_'.$user.'_'.$_.'_awarded_s'};
1.54 albertel 5532: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
5533: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
1.257 albertel 5534: my $old_score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
5535: my $awarded = $env{'form.GD_'.$user.'_'.$_.'_awarded'};
1.54 albertel 5536: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
5537: my $partial = $awarded eq '' ? '' : $pcr;
1.798 raeburn 5538: $awardeds{$symb}{$_} = $partial;
1.44 ng 5539: my $score;
5540: if ($partial eq '') {
1.257 albertel 5541: $score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 5542: } elsif ($partial > 0) {
5543: $score = 'correct_by_override';
5544: } elsif ($partial == 0) {
5545: $score = 'incorrect_by_override';
5546: }
1.257 albertel 5547: my $dropMenu = $env{'form.GD_'.$user.'_'.$_.'_solved'};
1.125 ng 5548: $score = 'excused' if (($dropMenu eq 'excused') && ($score ne 'excused'));
5549:
1.292 albertel 5550: $newrecord{'resource.'.$_.'.regrader'}=
5551: "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 5552: if ($dropMenu eq 'reset status' &&
5553: $old_score ne '') { # ignore if no previous attempts => nothing to reset
1.299 albertel 5554: $newrecord{'resource.'.$_.'.tries'} = '';
1.125 ng 5555: $newrecord{'resource.'.$_.'.solved'} = '';
5556: $newrecord{'resource.'.$_.'.award'} = '';
1.299 albertel 5557: $newrecord{'resource.'.$_.'.awarded'} = '';
1.125 ng 5558: $updateflag = 1;
1.269 raeburn 5559: if ($env{'form.GD_'.$user.'_'.$_.'_aggtries'} > 0) {
5560: my $aggtries = $env{'form.GD_'.$user.'_'.$_.'_aggtries'};
5561: my $totaltries = $env{'form.GD_'.$user.'_'.$_.'_totaltries'};
5562: my $solvedstatus = $env{'form.GD_'.$user.'_'.$_.'_solved_s'};
5563: &decrement_aggs($symb,$_,\%aggregate,$aggtries,$totaltries,$solvedstatus);
5564: $aggregateflag = 1;
5565: }
1.139 albertel 5566: } elsif (!($old_part eq $partial && $old_score eq $score)) {
5567: $updateflag = 1;
5568: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
5569: $newrecord{'resource.'.$_.'.solved'} = $score;
5570: $rec_update++;
1.125 ng 5571: }
5572:
1.93 albertel 5573: $line .= '<td align="center">'.$old_aw.' </td>'.
1.44 ng 5574: '<td align="center">'.$awarded.
5575: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 5576:
1.54 albertel 5577:
5578: my $partid=$_;
1.798 raeburn 5579: if ($score eq 'excused') {
5580: $excuseds{$symb}{$partid} = 1;
5581: } else {
5582: $excuseds{$symb}{$partid} = '';
5583: }
1.54 albertel 5584: foreach my $stores (@parts) {
5585: my ($part,$type) = &split_part_type($stores);
5586: if ($part !~ m/^\Q$partid\E/) { next;}
5587: if ($type eq 'awarded' || $type eq 'solved') { next; }
1.257 albertel 5588: my $old_aw = $env{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
5589: my $awarded = $env{'form.GD_'.$user.'_'.$part.'_'.$type};
1.54 albertel 5590: if ($awarded ne '' && $awarded ne $old_aw) {
5591: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.257 albertel 5592: $newrecord{'resource.'.$part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.54 albertel 5593: $updateflag=1;
5594: }
1.93 albertel 5595: $line .= '<td align="center">'.$old_aw.' </td>'.
1.54 albertel 5596: '<td align="center">'.$awarded.' </td>';
5597: }
1.44 ng 5598: }
1.477 albertel 5599: $line.="\n";
1.301 albertel 5600:
1.44 ng 5601: if ($updateflag) {
5602: $count++;
1.257 albertel 5603: &Apache::lonnet::cstore(\%newrecord,$symb,$env{'request.course.id'},
1.89 albertel 5604: $udom,$uname);
1.301 albertel 5605:
5606: if (&Apache::bridgetask::in_queue('gradingqueue',$symb,$cdom,
5607: $cnum,$udom,$uname)) {
5608: # need to figure out if should be in queue.
5609: my %record =
5610: &Apache::lonnet::restore($symb,$env{'request.course.id'},
5611: $udom,$uname);
5612: my $all_graded = 1;
5613: my $none_graded = 1;
1.786 raeburn 5614: unless ($got_types) {
5615: my $error;
5616: my ($plist,$handgrd,$resptype) = &response_type($symb,\$error);
5617: unless ($error) {
5618: foreach my $part (@parts) {
5619: if (ref($resptype->{$part}) eq 'HASH') {
5620: foreach my $id (keys(%{$resptype->{$part}})) {
5621: if (($resptype->{$part}->{$id} eq 'essay') ||
5622: (lc($handgrd->{$part.'_'.$id}) eq 'yes')) {
5623: $queueable{$part} = 1;
5624: last;
5625: }
5626: }
5627: }
5628: }
5629: }
5630: $got_types = 1;
5631: }
1.301 albertel 5632: foreach my $part (@parts) {
1.786 raeburn 5633: if ($queueable{$part}) {
5634: if ( $record{'resource.'.$part.'.awarded'} eq '' ) {
5635: $all_graded = 0;
5636: } else {
5637: $none_graded = 0;
5638: }
1.301 albertel 5639: }
1.786 raeburn 5640: }
1.301 albertel 5641: if ($all_graded || $none_graded) {
5642: &Apache::bridgetask::remove_from_queue('gradingqueue',
5643: $symb,$cdom,$cnum,
5644: $udom,$uname);
5645: }
5646: }
5647:
1.477 albertel 5648: $result.=&Apache::loncommon::start_data_table_row().
5649: '<td align="right"> '.$updateCtr.' </td>'.$line.
5650: &Apache::loncommon::end_data_table_row();
1.126 ng 5651: $updateCtr++;
1.798 raeburn 5652: if (keys(%needpb)) {
5653: $weights{$symb} = \%weight;
1.802 ! raeburn 5654: &process_passbacks('editgrades',[$symb],$cdom,$cnum,$udom,$uname,$usec,\%weights,
1.798 raeburn 5655: \%awardeds,\%excuseds,\%needpb,\%skip_passback,\%pbsave);
5656: }
1.93 albertel 5657: } else {
1.477 albertel 5658: push(@noupdate,
5659: '<td align="right"> '.$noupdateCtr.' </td>'.$line);
1.126 ng 5660: $noupdateCtr++;
1.44 ng 5661: }
1.269 raeburn 5662: if ($aggregateflag) {
5663: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 5664: $cdom,$cnum);
1.269 raeburn 5665: }
1.93 albertel 5666: }
1.477 albertel 5667: if (@noupdate) {
1.748 raeburn 5668: my $numcols=$totcolspan+2;
1.477 albertel 5669: $result .= &Apache::loncommon::start_data_table_row('LC_empty_row').
1.478 albertel 5670: '<td align="center" colspan="'.$numcols.'">'.
5671: &mt('No Changes Occurred For the Students Below').
5672: '</td>'.
1.477 albertel 5673: &Apache::loncommon::end_data_table_row();
5674: foreach my $line (@noupdate) {
5675: $result.=
5676: &Apache::loncommon::start_data_table_row().
5677: $line.
5678: &Apache::loncommon::end_data_table_row();
5679: }
1.44 ng 5680: }
1.614 www 5681: $result .= &Apache::loncommon::end_data_table();
1.478 albertel 5682: my $msg = '<p><b>'.
5683: &mt('Number of records updated = [_1] for [quant,_2,student].',
5684: $rec_update,$count).'</b><br />'.
5685: '<b>'.&mt('Total number of students = [_1]',$env{'form.total'}).
5686: '</b></p>';
1.44 ng 5687: return $title.$msg.$result;
1.5 albertel 5688: }
1.54 albertel 5689:
5690: sub split_part_type {
5691: my ($partstr) = @_;
5692: my ($temp,@allparts)=split(/_/,$partstr);
5693: my $type=pop(@allparts);
1.439 albertel 5694: my $part=join('_',@allparts);
1.54 albertel 5695: return ($part,$type);
5696: }
5697:
1.44 ng 5698: #------------- end of section for handling grading by section/class ---------
5699: #
5700: #----------------------------------------------------------------------------
5701:
1.5 albertel 5702:
1.44 ng 5703: #----------------------------------------------------------------------------
5704: #
5705: #-------------------------- Next few routines handles grading by csv upload
5706: #
5707: #--- Javascript to handle csv upload
1.27 albertel 5708: sub csvupload_javascript_reverse_associate {
1.743 raeburn 5709: my $error1=&mt('You need to specify the username, the student/employee ID, or the clicker ID');
1.246 albertel 5710: my $error2=&mt('You need to specify at least one grading field');
1.736 damieng 5711: &js_escape(\$error1);
5712: &js_escape(\$error2);
1.27 albertel 5713: return(<<ENDPICK);
5714: function verify(vf) {
5715: var foundsomething=0;
5716: var founduname=0;
1.243 albertel 5717: var foundID=0;
1.743 raeburn 5718: var foundclicker=0;
1.27 albertel 5719: for (i=0;i<=vf.nfields.value;i++) {
5720: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 5721: if (i==0 && tw!=0) { foundID=1; }
5722: if (i==1 && tw!=0) { founduname=1; }
1.743 raeburn 5723: if (i==2 && tw!=0) { foundclicker=1; }
5724: if (i!=0 && i!=1 && i!=2 && i!=3 && tw!=0) { foundsomething=1; }
1.27 albertel 5725: }
1.743 raeburn 5726: if (founduname==0 && foundID==0 && foundclicker==0) {
1.246 albertel 5727: alert('$error1');
5728: return;
1.27 albertel 5729: }
5730: if (foundsomething==0) {
1.246 albertel 5731: alert('$error2');
5732: return;
1.27 albertel 5733: }
5734: vf.submit();
5735: }
5736: function flip(vf,tf) {
5737: var nw=eval('vf.f'+tf+'.selectedIndex');
5738: var i;
5739: for (i=0;i<=vf.nfields.value;i++) {
5740: //can not pick the same destination field for both name and domain
5741: if (((i ==0)||(i ==1)) &&
5742: ((tf==0)||(tf==1)) &&
5743: (i!=tf) &&
5744: (eval('vf.f'+i+'.selectedIndex')==nw)) {
5745: eval('vf.f'+i+'.selectedIndex=0;')
5746: }
5747: }
5748: }
5749: ENDPICK
5750: }
5751:
5752: sub csvupload_javascript_forward_associate {
1.743 raeburn 5753: my $error1=&mt('You need to specify the username, the student/employee ID, or the clicker ID');
1.246 albertel 5754: my $error2=&mt('You need to specify at least one grading field');
1.736 damieng 5755: &js_escape(\$error1);
5756: &js_escape(\$error2);
1.27 albertel 5757: return(<<ENDPICK);
5758: function verify(vf) {
5759: var foundsomething=0;
5760: var founduname=0;
1.243 albertel 5761: var foundID=0;
1.743 raeburn 5762: var foundclicker=0;
1.27 albertel 5763: for (i=0;i<=vf.nfields.value;i++) {
5764: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 5765: if (tw==1) { foundID=1; }
5766: if (tw==2) { founduname=1; }
1.745 raeburn 5767: if (tw==3) { foundclicker=1; }
1.743 raeburn 5768: if (tw>4) { foundsomething=1; }
1.27 albertel 5769: }
1.743 raeburn 5770: if (founduname==0 && foundID==0 && Æ’oundclicker==0) {
1.246 albertel 5771: alert('$error1');
5772: return;
1.27 albertel 5773: }
5774: if (foundsomething==0) {
1.246 albertel 5775: alert('$error2');
5776: return;
1.27 albertel 5777: }
5778: vf.submit();
5779: }
5780: function flip(vf,tf) {
5781: var nw=eval('vf.f'+tf+'.selectedIndex');
5782: var i;
5783: //can not pick the same destination field twice
5784: for (i=0;i<=vf.nfields.value;i++) {
5785: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
5786: eval('vf.f'+i+'.selectedIndex=0;')
5787: }
5788: }
5789: }
5790: ENDPICK
5791: }
5792:
1.26 albertel 5793: sub csvuploadmap_header {
1.324 albertel 5794: my ($request,$symb,$datatoken,$distotal)= @_;
1.41 ng 5795: my $javascript;
1.257 albertel 5796: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 5797: $javascript=&csvupload_javascript_reverse_associate();
5798: } else {
5799: $javascript=&csvupload_javascript_forward_associate();
5800: }
1.45 ng 5801:
1.418 albertel 5802: $symb = &Apache::lonenc::check_encrypt($symb);
1.632 www 5803: $request->print('<form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">'.
5804: &mt('Total number of records found in file: [_1]',$distotal).'<hr />'.
5805: &mt('Associate entries from the uploaded file with as many fields as you can.'));
5806: my $reverse=&mt("Reverse Association");
1.41 ng 5807: $request->print(<<ENDPICK);
1.632 www 5808: <br />
5809: <input type="button" value="$reverse" onclick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1.26 albertel 5810: <input type="hidden" name="associate" value="" />
5811: <input type="hidden" name="phase" value="three" />
5812: <input type="hidden" name="datatoken" value="$datatoken" />
1.257 albertel 5813: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
5814: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
1.26 albertel 5815: <input type="hidden" name="upfile_associate"
1.257 albertel 5816: value="$env{'form.upfile_associate'}" />
1.26 albertel 5817: <input type="hidden" name="symb" value="$symb" />
1.246 albertel 5818: <input type="hidden" name="command" value="csvuploadoptions" />
1.26 albertel 5819: <hr />
5820: ENDPICK
1.597 wenzelju 5821: $request->print(&Apache::lonhtmlcommon::scripttag($javascript));
1.118 ng 5822: return '';
1.26 albertel 5823:
5824: }
5825:
5826: sub csvupload_fields {
1.582 raeburn 5827: my ($symb,$errorref) = @_;
1.745 raeburn 5828: my $toolsymb;
5829: if ($symb =~ /ext\.tool$/) {
5830: $toolsymb = $symb;
5831: }
1.582 raeburn 5832: my (@parts) = &getpartlist($symb,$errorref);
5833: if (ref($errorref)) {
5834: if ($$errorref) {
5835: return;
5836: }
5837: }
5838:
1.556 weissno 5839: my @fields=(['ID','Student/Employee ID'],
1.243 albertel 5840: ['username','Student Username'],
1.743 raeburn 5841: ['clicker','Clicker ID'],
1.243 albertel 5842: ['domain','Student Domain']);
1.324 albertel 5843: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.41 ng 5844: foreach my $part (sort(@parts)) {
5845: my @datum;
1.745 raeburn 5846: my $display=&Apache::lonnet::metadata($url,$part.'.display',$toolsymb);
1.41 ng 5847: my $name=$part;
1.745 raeburn 5848: if (!$display) { $display = $name; }
1.41 ng 5849: @datum=($name,$display);
1.244 albertel 5850: if ($name=~/^stores_(.*)_awarded/) {
5851: push(@fields,['stores_'.$1.'_points',"Points [Part: $1]"]);
5852: }
1.41 ng 5853: push(@fields,\@datum);
5854: }
5855: return (@fields);
1.26 albertel 5856: }
5857:
5858: sub csvuploadmap_footer {
1.41 ng 5859: my ($request,$i,$keyfields) =@_;
1.703 bisitz 5860: my $buttontext = &mt('Assign Grades');
1.41 ng 5861: $request->print(<<ENDPICK);
1.26 albertel 5862: </table>
5863: <input type="hidden" name="nfields" value="$i" />
5864: <input type="hidden" name="keyfields" value="$keyfields" />
1.703 bisitz 5865: <input type="button" onclick="javascript:verify(this.form)" value="$buttontext" /><br />
1.26 albertel 5866: </form>
5867: ENDPICK
5868: }
5869:
1.283 albertel 5870: sub checkforfile_js {
1.638 www 5871: my $alertmsg = &mt('Please use the browse button to select a file from your local directory.');
1.736 damieng 5872: &js_escape(\$alertmsg);
1.597 wenzelju 5873: my $result = &Apache::lonhtmlcommon::scripttag(<<CSVFORMJS);
1.86 ng 5874: function checkUpload(formname) {
5875: if (formname.upfile.value == "") {
1.539 riegler 5876: alert("$alertmsg");
1.86 ng 5877: return false;
5878: }
5879: formname.submit();
5880: }
5881: CSVFORMJS
1.283 albertel 5882: return $result;
5883: }
5884:
5885: sub upcsvScores_form {
1.608 www 5886: my ($request,$symb) = @_;
1.283 albertel 5887: if (!$symb) {return '';}
5888: my $result=&checkforfile_js();
1.632 www 5889: $result.=&Apache::loncommon::start_data_table().
5890: &Apache::loncommon::start_data_table_header_row().
5891: '<th>'.&mt('Specify a file containing the class scores for current resource.').'</th>'.
5892: &Apache::loncommon::end_data_table_header_row().
5893: &Apache::loncommon::start_data_table_row().'<td>';
1.370 www 5894: my $upload=&mt("Upload Scores");
1.86 ng 5895: my $upfile_select=&Apache::loncommon::upfile_select_html();
1.245 albertel 5896: my $ignore=&mt('Ignore First Line');
1.418 albertel 5897: $symb = &Apache::lonenc::check_encrypt($symb);
1.86 ng 5898: $result.=<<ENDUPFORM;
1.106 albertel 5899: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.86 ng 5900: <input type="hidden" name="symb" value="$symb" />
5901: <input type="hidden" name="command" value="csvuploadmap" />
5902: $upfile_select
1.589 bisitz 5903: <br /><input type="button" onclick="javascript:checkUpload(this.form);" value="$upload" />
1.86 ng 5904: </form>
5905: ENDUPFORM
1.370 www 5906: $result.=&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
1.632 www 5907: &mt("How do I create a CSV file from a spreadsheet")).
5908: '</td>'.
5909: &Apache::loncommon::end_data_table_row().
5910: &Apache::loncommon::end_data_table();
1.86 ng 5911: return $result;
5912: }
5913:
5914:
1.26 albertel 5915: sub csvuploadmap {
1.768 raeburn 5916: my ($request,$symb) = @_;
1.41 ng 5917: if (!$symb) {return '';}
1.72 ng 5918:
1.41 ng 5919: my $datatoken;
1.257 albertel 5920: if (!$env{'form.datatoken'}) {
1.41 ng 5921: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 5922: } else {
1.742 raeburn 5923: $datatoken=&Apache::loncommon::valid_datatoken($env{'form.datatoken'});
5924: if ($datatoken ne '') {
5925: &Apache::loncommon::load_tmp_file($request,$datatoken);
5926: }
1.26 albertel 5927: }
1.41 ng 5928: my @records=&Apache::loncommon::upfile_record_sep();
1.324 albertel 5929: &csvuploadmap_header($request,$symb,$datatoken,$#records+1);
1.41 ng 5930: my ($i,$keyfields);
5931: if (@records) {
1.582 raeburn 5932: my $fieldserror;
5933: my @fields=&csvupload_fields($symb,\$fieldserror);
5934: if ($fieldserror) {
5935: $request->print(&navmap_errormsg());
5936: return;
5937: }
1.257 albertel 5938: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 5939: &Apache::loncommon::csv_print_samples($request,\@records);
5940: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
5941: \@fields);
5942: foreach (@fields) { $keyfields.=$_->[0].','; }
5943: chop($keyfields);
5944: } else {
5945: unshift(@fields,['none','']);
5946: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
5947: \@fields);
1.311 banghart 5948: foreach my $rec (@records) {
5949: my %temp = &Apache::loncommon::record_sep($rec);
5950: if (%temp) {
5951: $keyfields=join(',',sort(keys(%temp)));
5952: last;
5953: }
5954: }
1.41 ng 5955: }
5956: }
5957: &csvuploadmap_footer($request,$i,$keyfields);
1.72 ng 5958:
1.41 ng 5959: return '';
1.27 albertel 5960: }
5961:
1.246 albertel 5962: sub csvuploadoptions {
1.608 www 5963: my ($request,$symb)= @_;
1.632 www 5964: my $overwrite=&mt('Overwrite any existing score');
1.246 albertel 5965: $request->print(<<ENDPICK);
5966: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
5967: <input type="hidden" name="command" value="csvuploadassign" />
5968: <p>
5969: <label>
5970: <input type="checkbox" name="overwite_scores" checked="checked" />
1.632 www 5971: $overwrite
1.246 albertel 5972: </label>
5973: </p>
5974: ENDPICK
5975: my %fields=&get_fields();
5976: if (!defined($fields{'domain'})) {
1.257 albertel 5977: my $domform = &Apache::loncommon::select_dom_form($env{'request.role.domain'},'default_domain');
1.632 www 5978: $request->print("\n<p>".&mt('Users are in domain: [_1]',$domform)."</p>\n");
1.246 albertel 5979: }
1.257 albertel 5980: foreach my $key (sort(keys(%env))) {
1.246 albertel 5981: if ($key !~ /^form\.(.*)$/) { next; }
5982: my $cleankey=$1;
5983: if ($cleankey eq 'command') { next; }
5984: $request->print('<input type="hidden" name="'.$cleankey.
1.257 albertel 5985: '" value="'.$env{$key}.'" />'."\n");
1.246 albertel 5986: }
5987: # FIXME do a check for any duplicated user ids...
5988: # FIXME do a check for any invalid user ids?...
1.703 bisitz 5989: $request->print('<input type="submit" value="'.&mt('Assign Grades').'" /><br />
1.290 albertel 5990: <hr /></form>'."\n");
1.246 albertel 5991: return '';
5992: }
5993:
5994: sub get_fields {
5995: my %fields;
1.257 albertel 5996: my @keyfields = split(/\,/,$env{'form.keyfields'});
5997: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
5998: if ($env{'form.upfile_associate'} eq 'reverse') {
5999: if ($env{'form.f'.$i} ne 'none') {
6000: $fields{$keyfields[$i]}=$env{'form.f'.$i};
1.41 ng 6001: }
6002: } else {
1.257 albertel 6003: if ($env{'form.f'.$i} ne 'none') {
6004: $fields{$env{'form.f'.$i}}=$keyfields[$i];
1.41 ng 6005: }
6006: }
1.27 albertel 6007: }
1.246 albertel 6008: return %fields;
6009: }
6010:
6011: sub csvuploadassign {
1.766 raeburn 6012: my ($request,$symb) = @_;
1.246 albertel 6013: if (!$symb) {return '';}
1.345 bowersj2 6014: my $error_msg = '';
1.742 raeburn 6015: my $datatoken = &Apache::loncommon::valid_datatoken($env{'form.datatoken'});
6016: if ($datatoken ne '') {
6017: &Apache::loncommon::load_tmp_file($request,$datatoken);
6018: }
1.246 albertel 6019: my @gradedata = &Apache::loncommon::upfile_record_sep();
6020: my %fields=&get_fields();
1.257 albertel 6021: my $courseid=$env{'request.course.id'};
1.798 raeburn 6022: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6023: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.97 albertel 6024: my ($classlist) = &getclasslist('all',0);
1.106 albertel 6025: my @notallowed;
1.41 ng 6026: my @skipped;
1.657 raeburn 6027: my @warnings;
1.41 ng 6028: my $countdone=0;
1.798 raeburn 6029: my @parts;
6030: my %needpb = &passbacks_for_symb($cdom,$cnum,$symb);
6031: my $passback;
6032: if (keys(%needpb)) {
6033: $passback = 1;
6034: my $navmap = Apache::lonnavmaps::navmap->new();
6035: if (ref($navmap)) {
6036: my $res = $navmap->getBySymb($symb);
6037: if (ref($res)) {
6038: my $partlist = $res->parts();
6039: if (ref($partlist) eq 'ARRAY') {
6040: @parts = sort(@{$partlist});
6041: }
6042: }
6043: } else {
6044: return &navmap_errormsg();
6045: }
6046: }
6047: my (%skip_passback,%pbsave,%weights,%awardeds,%excuseds);
6048:
1.41 ng 6049: foreach my $grade (@gradedata) {
6050: my %entries=&Apache::loncommon::record_sep($grade);
1.246 albertel 6051: my $domain;
6052: if ($entries{$fields{'domain'}}) {
6053: $domain=$entries{$fields{'domain'}};
6054: } else {
1.257 albertel 6055: $domain=$env{'form.default_domain'};
1.246 albertel 6056: }
1.243 albertel 6057: $domain=~s/\s//g;
1.41 ng 6058: my $username=$entries{$fields{'username'}};
1.160 albertel 6059: $username=~s/\s//g;
1.243 albertel 6060: if (!$username) {
6061: my $id=$entries{$fields{'ID'}};
1.247 albertel 6062: $id=~s/\s//g;
1.737 raeburn 6063: if ($id ne '') {
6064: my %ids=&Apache::lonnet::idget($domain,[$id]);
6065: $username=$ids{$id};
6066: } else {
6067: if ($entries{$fields{'clicker'}}) {
6068: my $clicker = $entries{$fields{'clicker'}};
6069: $clicker=~s/\s//g;
6070: if ($clicker ne '') {
6071: my %clickers = &Apache::lonnet::idget($domain,[$clicker],'clickers');
6072: if ($clickers{$clicker} ne '') {
6073: my $match = 0;
6074: my @inclass;
6075: foreach my $poss (split(/,/,$clickers{$clicker})) {
6076: if (exists($$classlist{"$poss:$domain"})) {
6077: $username = $poss;
6078: push(@inclass,$poss);
6079: $match ++;
6080:
6081: }
6082: }
6083: if ($match > 1) {
6084: undef($username);
6085: $request->print('<p class="LC_warning">'.
6086: &mt('Score not saved for clicker: [_1] (matched multiple usernames: [_2])',
6087: $clicker,join(', ',@inclass)).'</p>');
6088: }
6089: }
6090: }
6091: }
6092: }
1.243 albertel 6093: }
1.41 ng 6094: if (!exists($$classlist{"$username:$domain"})) {
1.247 albertel 6095: my $id=$entries{$fields{'ID'}};
6096: $id=~s/\s//g;
1.737 raeburn 6097: my $clicker = $entries{$fields{'clicker'}};
6098: $clicker=~s/\s//g;
6099: if ($clicker) {
6100: push(@skipped,"$clicker:$domain");
6101: } elsif ($id) {
1.247 albertel 6102: push(@skipped,"$id:$domain");
6103: } else {
6104: push(@skipped,"$username:$domain");
6105: }
1.41 ng 6106: next;
6107: }
1.108 albertel 6108: my $usec=$classlist->{"$username:$domain"}[5];
1.106 albertel 6109: if (!&canmodify($usec)) {
6110: push(@notallowed,"$username:$domain");
6111: next;
6112: }
1.244 albertel 6113: my %points;
1.41 ng 6114: my %grades;
6115: foreach my $dest (keys(%fields)) {
1.244 albertel 6116: if ($dest eq 'ID' || $dest eq 'username' ||
6117: $dest eq 'domain') { next; }
6118: if ($entries{$fields{$dest}} =~ /^\s*$/) { next; }
6119: if ($dest=~/stores_(.*)_points/) {
6120: my $part=$1;
6121: my $wgt =&Apache::lonnet::EXT('resource.'.$part.'.weight',
6122: $symb,$domain,$username);
1.798 raeburn 6123: $weights{$symb}{$part} = $wgt;
1.345 bowersj2 6124: if ($wgt) {
6125: $entries{$fields{$dest}}=~s/\s//g;
6126: my $pcr=$entries{$fields{$dest}} / $wgt;
1.798 raeburn 6127: if ($passback) {
6128: $awardeds{$symb}{$part} = $pcr;
6129: $excuseds{$symb}{$part} = '';
6130: }
1.463 albertel 6131: my $award=($pcr == 0) ? 'incorrect_by_override'
6132: : 'correct_by_override';
1.638 www 6133: if ($pcr>1) {
1.657 raeburn 6134: push(@warnings,&mt("[_1]: point value larger than weight","$username:$domain"));
1.638 www 6135: }
1.345 bowersj2 6136: $grades{"resource.$part.awarded"}=$pcr;
6137: $grades{"resource.$part.solved"}=$award;
6138: $points{$part}=1;
6139: } else {
6140: $error_msg = "<br />" .
6141: &mt("Some point values were assigned"
6142: ." for problems with a weight "
6143: ."of zero. These values were "
6144: ."ignored.");
6145: }
1.244 albertel 6146: } else {
6147: if ($dest=~/stores_(.*)_awarded/) { if ($points{$1}) {next;} }
6148: if ($dest=~/stores_(.*)_solved/) { if ($points{$1}) {next;} }
6149: my $store_key=$dest;
1.798 raeburn 6150: if ($passback) {
6151: if ($store_key=~/stores_(.*)_(awarded|solved)/) {
6152: my ($part,$key) = ($1,$2);
6153: unless ((ref($weights{$symb}) eq 'HASH') && (exists($weights{$symb}{$part}))) {
6154: $weights{$symb}{$part} = &Apache::lonnet::EXT('resource.'.$part.'.weight',
6155: $symb,$domain,$username);
6156: }
6157: if ($key eq 'awarded') {
6158: $awardeds{$symb}{$part} = $entries{$fields{$dest}};
6159: } elsif ($key eq 'solved') {
6160: if ($entries{$fields{$dest}} =~ /^excused/) {
6161: $excuseds{$symb}{$part} = 1;
6162: }
6163: }
6164: }
6165: }
1.244 albertel 6166: $store_key=~s/^stores/resource/;
6167: $store_key=~s/_/\./g;
6168: $grades{$store_key}=$entries{$fields{$dest}};
6169: }
1.41 ng 6170: }
1.766 raeburn 6171: if (! %grades) {
1.508 www 6172: push(@skipped,&mt("[_1]: no data to save","$username:$domain"));
6173: } else {
6174: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
6175: my $result=&Apache::lonnet::cstore(\%grades,$symb,
1.302 albertel 6176: $env{'request.course.id'},
6177: $domain,$username);
1.508 www 6178: if ($result eq 'ok') {
1.627 www 6179: # Successfully stored
1.508 www 6180: $request->print('.');
1.627 www 6181: # Remove from grading queue
1.798 raeburn 6182: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,$cnum,
1.801 raeburn 6183: $domain,$username);
1.627 www 6184: $countdone++;
1.798 raeburn 6185: if ($passback) {
6186: my @parts_in_upload;
6187: if (ref($weights{$symb}) eq 'HASH') {
6188: @parts_in_upload = sort(keys(%{$weights{$symb}}));
6189: }
6190: my @diffs = &Apache::loncommon::compare_arrays(\@parts_in_upload,\@parts);
6191: if (@diffs > 0) {
6192: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$username);
6193: foreach my $part (@parts) {
6194: next if (grep(/^\Q$part\E$/,@parts_in_upload));
6195: $weights{$symb}{$part} = &Apache::lonnet::EXT('resource.'.$part.'.weight',
6196: $symb,$domain,$username);
6197: if ($record{"resource.$part.solved"} =~/^excused/) {
6198: $excuseds{$symb}{$part} = 1;
6199: } else {
6200: $excuseds{$symb}{$part} = '';
6201: }
6202: $awardeds{$symb}{$part} = $record{"resource.$part.awarded"};
6203: }
6204: }
1.802 ! raeburn 6205: &process_passbacks('csvupload',[$symb],$cdom,$cnum,$domain,$username,$usec,\%weights,
1.798 raeburn 6206: \%awardeds,\%excuseds,\%needpb,\%skip_passback,\%pbsave);
6207: }
1.627 www 6208: } else {
1.508 www 6209: $request->print("<p><span class=\"LC_error\">".
6210: &mt("Failed to save data for student [_1]. Message when trying to save was: [_2]",
6211: "$username:$domain",$result)."</span></p>");
6212: }
6213: $request->rflush();
6214: }
1.41 ng 6215: }
1.570 www 6216: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt("Saved scores for [quant,_1,student]",$countdone),$countdone==0));
1.657 raeburn 6217: if (@warnings) {
6218: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('Warnings generated for the following saved scores:'),1).'<br />');
6219: $request->print(join(', ',@warnings));
6220: }
1.41 ng 6221: if (@skipped) {
1.571 www 6222: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('No scores stored for the following username(s):'),1).'<br />');
6223: $request->print(join(', ',@skipped));
1.106 albertel 6224: }
6225: if (@notallowed) {
1.571 www 6226: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('Modification of scores not allowed for the following username(s):'),1).'<br />');
6227: $request->print(join(', ',@notallowed));
1.41 ng 6228: }
1.106 albertel 6229: $request->print("<br />\n");
1.345 bowersj2 6230: return $error_msg;
1.26 albertel 6231: }
1.44 ng 6232: #------------- end of section for handling csv file upload ---------
6233: #
6234: #-------------------------------------------------------------------
6235: #
1.122 ng 6236: #-------------- Next few routines handle grading by page/sequence
1.72 ng 6237: #
6238: #--- Select a page/sequence and a student to grade
1.68 ng 6239: sub pickStudentPage {
1.608 www 6240: my ($request,$symb) = @_;
1.68 ng 6241:
1.539 riegler 6242: my $alertmsg = &mt('Please select the student you wish to grade.');
1.736 damieng 6243: &js_escape(\$alertmsg);
1.597 wenzelju 6244: $request->print(&Apache::lonhtmlcommon::scripttag(<<LISTJAVASCRIPT));
1.68 ng 6245:
6246: function checkPickOne(formname) {
1.76 ng 6247: if (radioSelection(formname.student) == null) {
1.539 riegler 6248: alert("$alertmsg");
1.68 ng 6249: return;
6250: }
1.125 ng 6251: ptr = pullDownSelection(formname.selectpage);
6252: formname.page.value = formname["page"+ptr].value;
6253: formname.title.value = formname["title"+ptr].value;
1.68 ng 6254: formname.submit();
6255: }
6256:
6257: LISTJAVASCRIPT
1.118 ng 6258: &commonJSfunctions($request);
1.608 www 6259:
1.257 albertel 6260: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
6261: my $cnum = $env{"course.$env{'request.course.id'}.num"};
6262: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.761 raeburn 6263: my $getgroup = $env{'form.group'} eq '' ? 'all' : $env{'form.group'};
1.68 ng 6264:
1.398 albertel 6265: my $result='<h3><span class="LC_info"> '.
1.485 albertel 6266: &mt('Manual Grading by Page or Sequence').'</span></h3>';
1.68 ng 6267:
1.80 ng 6268: $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
1.582 raeburn 6269: my $map_error;
6270: my ($titles,$symbx) = &getSymbMap($map_error);
6271: if ($map_error) {
6272: $request->print(&navmap_errormsg());
6273: return;
6274: }
1.137 albertel 6275: my ($curpage) =&Apache::lonnet::decode_symb($symb);
6276: # my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb);
6277: # my $type=($curpage =~ /\.(page|sequence)/);
1.700 bisitz 6278:
6279: # Collection of hidden fields
1.70 ng 6280: my $ctr=0;
1.68 ng 6281: foreach (@$titles) {
1.700 bisitz 6282: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
6283: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
6284: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
6285: $ctr++;
1.68 ng 6286: }
1.700 bisitz 6287: $result.='<input type="hidden" name="page" />'."\n".
6288: '<input type="hidden" name="title" />'."\n";
6289:
6290: $result.=&build_section_inputs();
6291: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
6292: $result.='<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
6293: '<input type="hidden" name="command" value="displayPage" />'."\n".
6294: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.485 albertel 6295:
1.700 bisitz 6296: # Show grading options
6297: $result.=&Apache::lonhtmlcommon::start_pick_box();
6298: my $select = '<select name="selectpage">'."\n";
1.70 ng 6299: $ctr=0;
6300: foreach (@$titles) {
6301: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.700 bisitz 6302: $select.='<option value="'.$ctr.'"'.
6303: ($$symbx{$_} =~ /$curpage$/ ? ' selected="selected"' : '').
6304: '>'.$showtitle.'</option>'."\n";
1.70 ng 6305: $ctr++;
6306: }
1.700 bisitz 6307: $select.= '</select>';
1.68 ng 6308:
1.700 bisitz 6309: $result.=
6310: &Apache::lonhtmlcommon::row_title(&mt('Problems from'))
6311: .$select
6312: .&Apache::lonhtmlcommon::row_closure();
6313:
6314: $result.=
6315: &Apache::lonhtmlcommon::row_title(&mt('View Problem Text'))
6316: .'<label><input type="radio" name="vProb" value="no"'
6317: .' checked="checked" /> '.&mt('no').' </label>'."\n"
6318: .'<label><input type="radio" name="vProb" value="yes" />'
6319: .&mt('yes').'</label>'."\n"
6320: .&Apache::lonhtmlcommon::row_closure();
6321:
6322: $result.=
6323: &Apache::lonhtmlcommon::row_title(&mt('View Submissions'))
6324: .'<label><input type="radio" name="lastSub" value="none" /> '
6325: .&mt('none').' </label>'."\n"
6326: .'<label><input type="radio" name="lastSub" value="datesub"'
6327: .' checked="checked" /> '.&mt('all submissions').'</label>'."\n"
6328: .'<label><input type="radio" name="lastSub" value="all" /> '
6329: .&mt('all submissions with details').' </label>'
6330: .&Apache::lonhtmlcommon::row_closure();
1.432 banghart 6331:
1.700 bisitz 6332: $result.=
6333: &Apache::lonhtmlcommon::row_title(&mt('Use CODE'))
6334: .'<input type="text" name="CODE" value="" />'
6335: .&Apache::lonhtmlcommon::row_closure(1)
6336: .&Apache::lonhtmlcommon::end_pick_box();
1.382 albertel 6337:
1.700 bisitz 6338: # Show list of students to select for grading
6339: $result.='<br /><input type="button" '.
1.589 bisitz 6340: 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /><br />'."\n";
1.72 ng 6341:
1.68 ng 6342: $request->print($result);
6343:
1.485 albertel 6344: my $studentTable.=' <b>'.&mt('Select a student you wish to grade and then click on the Next button.').'</b><br />'.
1.484 albertel 6345: &Apache::loncommon::start_data_table().
6346: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 6347: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 6348: '<th>'.&nameUserString('header').'</th>'.
1.485 albertel 6349: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 6350: '<th>'.&nameUserString('header').'</th>'.
6351: &Apache::loncommon::end_data_table_header_row();
1.68 ng 6352:
1.761 raeburn 6353: my (undef,undef,$fullname) = &getclasslist($getsec,'1',$getgroup);
1.68 ng 6354: my $ptr = 1;
1.294 albertel 6355: foreach my $student (sort
6356: {
6357: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
6358: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
6359: }
6360: return $a cmp $b;
6361: } (keys(%$fullname))) {
1.68 ng 6362: my ($uname,$udom) = split(/:/,$student);
1.484 albertel 6363: $studentTable.=($ptr%2==1 ? &Apache::loncommon::start_data_table_row()
6364: : '</td>');
1.126 ng 6365: $studentTable.='<td align="right">'.$ptr.' </td>';
1.288 albertel 6366: $studentTable.='<td> <label><input type="radio" name="student" value="'.$student.'" /> '
6367: .&nameUserString(undef,$$fullname{$student},$uname,$udom)."</label>\n";
1.484 albertel 6368: $studentTable.=
6369: ($ptr%2 == 0 ? '</td>'.&Apache::loncommon::end_data_table_row()
6370: : '');
1.68 ng 6371: $ptr++;
6372: }
1.484 albertel 6373: if ($ptr%2 == 0) {
6374: $studentTable.='</td><td> </td><td> </td>'.
6375: &Apache::loncommon::end_data_table_row();
6376: }
6377: $studentTable.=&Apache::loncommon::end_data_table()."\n";
1.126 ng 6378: $studentTable.='<input type="button" '.
1.589 bisitz 6379: 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /></form>'."\n";
1.68 ng 6380:
6381: $request->print($studentTable);
6382:
6383: return '';
6384: }
6385:
6386: sub getSymbMap {
1.582 raeburn 6387: my ($map_error) = @_;
1.132 bowersj2 6388: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 6389: unless (ref($navmap)) {
6390: if (ref($map_error)) {
6391: $$map_error = 'navmap';
6392: }
6393: return;
6394: }
1.68 ng 6395: my %symbx = ();
6396: my @titles = ();
1.117 bowersj2 6397: my $minder = 0;
6398:
6399: # Gather every sequence that has problems.
1.240 albertel 6400: my @sequences = $navmap->retrieveResources(undef, sub { shift->is_map(); },
6401: 1,0,1);
1.117 bowersj2 6402: for my $sequence ($navmap->getById('0.0'), @sequences) {
1.745 raeburn 6403: if ($navmap->hasResource($sequence, sub { shift->is_gradable(); }, 0) ) {
1.381 albertel 6404: my $title = $minder.'.'.
6405: &HTML::Entities::encode($sequence->compTitle(),'"\'&');
6406: push(@titles, $title); # minder in case two titles are identical
6407: $symbx{$title} = &HTML::Entities::encode($sequence->symb(),'"\'&');
1.117 bowersj2 6408: $minder++;
1.241 albertel 6409: }
1.68 ng 6410: }
6411: return \@titles,\%symbx;
6412: }
6413:
1.72 ng 6414: #
6415: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68 ng 6416: sub displayPage {
1.608 www 6417: my ($request,$symb) = @_;
1.257 albertel 6418: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
6419: my $cnum = $env{"course.$env{'request.course.id'}.num"};
6420: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
6421: my $pageTitle = $env{'form.page'};
1.103 albertel 6422: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 6423: my ($uname,$udom) = split(/:/,$env{'form.student'});
6424: my $usec=$classlist->{$env{'form.student'}}[5];
1.168 albertel 6425:
6426: #need to make sure we have the correct data for later EXT calls,
6427: #thus invalidate the cache
6428: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 6429: $env{'course.'.$env{'request.course.id'}.'.num'},
6430: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 6431: &Apache::lonnet::clear_EXT_cache_status();
6432:
1.103 albertel 6433: if (!&canview($usec)) {
1.712 bisitz 6434: $request->print(
6435: '<span class="LC_warning">'.
6436: &mt('Unable to view requested student. ([_1])',
6437: $env{'form.student'}).
6438: '</span>');
6439: return;
1.103 albertel 6440: }
1.398 albertel 6441: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.485 albertel 6442: $result.='<h3> '.&mt('Student: [_1]',&nameUserString(undef,$$fullname{$env{'form.student'}},$uname,$udom)).
1.129 ng 6443: '</h3>'."\n";
1.500 albertel 6444: $env{'form.CODE'} = uc($env{'form.CODE'});
1.501 foxr 6445: if (&Apache::lonnet::validCODE(uc($env{'form.CODE'}))) {
1.485 albertel 6446: $result.='<h3> '.&mt('CODE: [_1]',$env{'form.CODE'}).'</h3>'."\n";
1.382 albertel 6447: } else {
6448: delete($env{'form.CODE'});
6449: }
1.71 ng 6450: &sub_page_js($request);
6451: $request->print($result);
6452:
1.132 bowersj2 6453: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 6454: unless (ref($navmap)) {
6455: $request->print(&navmap_errormsg());
6456: return;
6457: }
1.257 albertel 6458: my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($env{'form.page'});
1.68 ng 6459: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 6460: if (!$map) {
1.485 albertel 6461: $request->print('<span class="LC_warning">'.&mt('Unable to view requested sequence. ([_1])',$resUrl).'</span>');
1.288 albertel 6462: return;
6463: }
1.68 ng 6464: my $iterator = $navmap->getIterator($map->map_start(),
6465: $map->map_finish());
6466:
1.71 ng 6467: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72 ng 6468: '<input type="hidden" name="command" value="gradeByPage" />'."\n".
1.257 albertel 6469: '<input type="hidden" name="fullname" value="'.$$fullname{$env{'form.student'}}.'" />'."\n".
6470: '<input type="hidden" name="student" value="'.$env{'form.student'}.'" />'."\n".
1.72 ng 6471: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
1.257 albertel 6472: '<input type="hidden" name="title" value="'.$env{'form.title'}.'" />'."\n".
1.418 albertel 6473: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.613 www 6474: '<input type="hidden" name="overRideScore" value="no" />'."\n";
1.71 ng 6475:
1.382 albertel 6476: if (defined($env{'form.CODE'})) {
6477: $studentTable.=
6478: '<input type="hidden" name="CODE" value="'.$env{'form.CODE'}.'" />'."\n";
6479: }
1.381 albertel 6480: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 6481: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 6482:
1.594 bisitz 6483: $studentTable.=' <span class="LC_info">'.
6484: &mt('Problems graded correct by the computer are marked with a [_1] symbol.',$checkIcon).
6485: '</span>'."\n".
1.484 albertel 6486: &Apache::loncommon::start_data_table().
6487: &Apache::loncommon::start_data_table_header_row().
1.700 bisitz 6488: '<th>'.&mt('Prob.').'</th>'.
1.485 albertel 6489: '<th> '.($env{'form.vProb'} eq 'no' ? &mt('Title') : &mt('Problem Text')).'/'.&mt('Grade').'</th>'.
1.484 albertel 6490: &Apache::loncommon::end_data_table_header_row();
1.71 ng 6491:
1.329 albertel 6492: &Apache::lonxml::clear_problem_counter();
1.196 albertel 6493: my ($depth,$question,$prob) = (1,1,1);
1.68 ng 6494: $iterator->next(); # skip the first BEGIN_MAP
6495: my $curRes = $iterator->next(); # for "current resource"
1.101 albertel 6496: while ($depth > 0) {
1.68 ng 6497: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 6498: if($curRes == $iterator->END_MAP) { $depth--; }
1.68 ng 6499:
1.745 raeburn 6500: if (ref($curRes) && $curRes->is_gradable()) {
1.91 albertel 6501: my $parts = $curRes->parts();
1.68 ng 6502: my $title = $curRes->compTitle();
1.71 ng 6503: my $symbx = $curRes->symb();
1.746 raeburn 6504: my $is_tool = ($symbx =~ /ext\.tool$/);
1.484 albertel 6505: $studentTable.=
6506: &Apache::loncommon::start_data_table_row().
6507: '<td align="center" valign="top" >'.$prob.
1.485 albertel 6508: (scalar(@{$parts}) == 1 ? ''
1.681 raeburn 6509: : '<br />('.&mt('[_1]parts',
6510: scalar(@{$parts}).' ').')'
1.485 albertel 6511: ).
6512: '</td>';
1.71 ng 6513: $studentTable.='<td valign="top">';
1.382 albertel 6514: my %form = ('CODE' => $env{'form.CODE'},);
1.749 raeburn 6515: if ($is_tool) {
6516: $studentTable.=' <b>'.$title.'</b><br />';
6517: } else {
1.745 raeburn 6518: if ($env{'form.vProb'} eq 'yes' ) {
6519: $studentTable.=&show_problem($request,$symbx,$uname,$udom,1,
6520: undef,'both',\%form);
6521: } else {
6522: my $companswer = &Apache::loncommon::get_student_answers($symbx,$uname,$udom,$env{'request.course.id'},%form);
6523: $companswer =~ s|<form(.*?)>||g;
6524: $companswer =~ s|</form>||g;
6525: # while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
6526: # $companswer =~ s/$1/ /ms;
6527: # $request->print('match='.$1."<br />\n");
6528: # }
6529: # $companswer =~ s|<table border=\"1\">|<table border=\"0\">|g;
6530: $studentTable.=' <b>'.$title.'</b> <br /> <b>'.&mt('Correct answer').':</b><br />'.$companswer;
6531: }
1.71 ng 6532: }
6533:
1.257 albertel 6534: my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
1.125 ng 6535:
1.257 albertel 6536: if ($env{'form.lastSub'} eq 'datesub') {
1.71 ng 6537: if ($record{'version'} eq '') {
1.745 raeburn 6538: my $msg = &mt('No recorded submission for this problem.');
6539: if ($is_tool) {
6540: $msg = &mt('No recorded transactions for this external tool');
6541: }
6542: $studentTable.='<br /> <span class="LC_warning">'.$msg.'</span><br />';
1.71 ng 6543: } else {
1.116 ng 6544: my %responseType = ();
6545: foreach my $partid (@{$parts}) {
1.147 albertel 6546: my @responseIds =$curRes->responseIds($partid);
6547: my @responseType =$curRes->responseType($partid);
6548: my %responseIds;
6549: for (my $i=0;$i<=$#responseIds;$i++) {
6550: $responseIds{$responseIds[$i]}=$responseType[$i];
6551: }
6552: $responseType{$partid} = \%responseIds;
1.116 ng 6553: }
1.148 albertel 6554: $studentTable.= &displaySubByDates($symbx,\%record,$parts,\%responseType,$checkIcon,$uname,$udom);
1.71 ng 6555: }
1.257 albertel 6556: } elsif ($env{'form.lastSub'} eq 'all') {
6557: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.726 raeburn 6558: my $identifier = (&canmodify($usec)? $prob : '');
1.71 ng 6559: $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
1.257 albertel 6560: $env{'request.course.id'},
1.726 raeburn 6561: '','.submission',undef,
6562: $usec,$identifier);
1.71 ng 6563:
6564: }
1.103 albertel 6565: if (&canmodify($usec)) {
1.585 bisitz 6566: $studentTable.=&gradeBox_start();
1.103 albertel 6567: foreach my $partid (@{$parts}) {
6568: $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
6569: $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
6570: $question++;
6571: }
1.585 bisitz 6572: $studentTable.=&gradeBox_end();
1.196 albertel 6573: $prob++;
1.71 ng 6574: }
6575: $studentTable.='</td></tr>';
1.68 ng 6576:
1.103 albertel 6577: }
1.68 ng 6578: $curRes = $iterator->next();
6579: }
1.780 raeburn 6580: my $disabled;
6581: unless (&canmodify($usec)) {
6582: $disabled = ' disabled="disabled"';
6583: }
1.68 ng 6584:
1.589 bisitz 6585: $studentTable.=
6586: '</table>'."\n".
1.780 raeburn 6587: '<input type="button" value="'.&mt('Save').'"'.$disabled.' '.
1.589 bisitz 6588: 'onclick="javascript:checkSubmitPage(this.form,'.$question.');" />'.
6589: '</form>'."\n";
1.71 ng 6590: $request->print($studentTable);
6591:
6592: return '';
1.119 ng 6593: }
6594:
6595: sub displaySubByDates {
1.148 albertel 6596: my ($symb,$record,$parts,$responseType,$checkIcon,$uname,$udom) = @_;
1.224 albertel 6597: my $isCODE=0;
1.335 albertel 6598: my $isTask = ($symb =~/\.task$/);
1.747 raeburn 6599: my $is_tool = ($symb =~/\.tool$/);
1.224 albertel 6600: if (exists($record->{'resource.CODE'})) { $isCODE=1; }
1.467 albertel 6601: my $studentTable=&Apache::loncommon::start_data_table().
6602: &Apache::loncommon::start_data_table_header_row().
6603: '<th>'.&mt('Date/Time').'</th>'.
6604: ($isCODE?'<th>'.&mt('CODE').'</th>':'').
1.671 raeburn 6605: ($isTask?'<th>'.&mt('Version').'</th>':'').
1.749 raeburn 6606: '<th>'.($is_tool?&mt('Grade'):&mt('Submission')).'</th>'.
1.467 albertel 6607: '<th>'.&mt('Status').'</th>'.
6608: &Apache::loncommon::end_data_table_header_row();
1.119 ng 6609: my ($version);
6610: my %mark;
1.148 albertel 6611: my %orders;
1.119 ng 6612: $mark{'correct_by_student'} = $checkIcon;
1.147 albertel 6613: if (!exists($$record{'1:timestamp'})) {
1.747 raeburn 6614: if ($is_tool) {
6615: return '<br /> <span class="LC_warning">'.&mt('No grade passed back.').'</span><br />';
6616: } else {
6617: return '<br /> <span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br />';
6618: }
1.147 albertel 6619: }
1.335 albertel 6620:
6621: my $interaction;
1.525 raeburn 6622: my $no_increment = 1;
1.735 raeburn 6623: my (%lastrndseed,%lasttype);
1.119 ng 6624: for ($version=1;$version<=$$record{'version'};$version++) {
1.467 albertel 6625: my $timestamp =
6626: &Apache::lonlocal::locallocaltime($$record{$version.':timestamp'});
1.335 albertel 6627: if (exists($$record{$version.':resource.0.version'})) {
6628: $interaction = $$record{$version.':resource.0.version'};
6629: }
1.671 raeburn 6630: if ($isTask && $env{'form.previousversion'}) {
6631: next unless ($interaction == $env{'form.previousversion'});
6632: }
1.335 albertel 6633: my $where = ($isTask ? "$version:resource.$interaction"
6634: : "$version:resource");
1.467 albertel 6635: $studentTable.=&Apache::loncommon::start_data_table_row().
6636: '<td>'.$timestamp.'</td>';
1.224 albertel 6637: if ($isCODE) {
6638: $studentTable.='<td>'.$record->{$version.':resource.CODE'}.'</td>';
6639: }
1.671 raeburn 6640: if ($isTask) {
6641: $studentTable.='<td>'.$interaction.'</td>';
6642: }
1.119 ng 6643: my @versionKeys = split(/\:/,$$record{$version.':keys'});
6644: my @displaySub = ();
6645: foreach my $partid (@{$parts}) {
1.640 raeburn 6646: my ($hidden,$type);
6647: $type = $$record{$version.':resource.'.$partid.'.type'};
6648: if (($type eq 'anonsurvey') || ($type eq 'anonsurveycred')) {
1.596 raeburn 6649: $hidden = 1;
6650: }
1.749 raeburn 6651: my @matchKey;
6652: if ($isTask) {
1.769 raeburn 6653: @matchKey = sort(grep(/^resource\.\d+\.\Q$partid\E\.award$/,@versionKeys));
1.749 raeburn 6654: } elsif ($is_tool) {
1.769 raeburn 6655: @matchKey = sort(grep(/^resource\.\Q$partid\E\.awarded$/,@versionKeys));
1.749 raeburn 6656: } else {
1.769 raeburn 6657: @matchKey = sort(grep(/^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys));
1.749 raeburn 6658: }
1.122 ng 6659: # next if ($$record{"$version:resource.$partid.solved"} eq '');
1.324 albertel 6660: my $display_part=&get_display_part($partid,$symb);
1.147 albertel 6661: foreach my $matchKey (@matchKey) {
1.198 albertel 6662: if (exists($$record{$version.':'.$matchKey}) &&
6663: $$record{$version.':'.$matchKey} ne '') {
1.749 raeburn 6664: if ($is_tool) {
6665: $displaySub[0].=$$record{"$version:resource.$partid.awarded"};
1.596 raeburn 6666: } else {
1.749 raeburn 6667: my ($responseId)= ($isTask ? ($matchKey=~ /^resource\.(.*?)\.\Q$partid\E\.award$/)
6668: : ($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/));
6669: $displaySub[0].='<span class="LC_nobreak">';
6670: $displaySub[0].='<b>'.&mt('Part: [_1]',$display_part).'</b>'
6671: .' <span class="LC_internal_info">'
6672: .'('.&mt('Response ID: [_1]',$responseId).')'
6673: .'</span>'
6674: .' <b>';
6675: if ($hidden) {
6676: $displaySub[0].= &mt('Anonymous Survey').'</b>';
6677: } else {
6678: my ($trial,$rndseed,$newvariation);
6679: if ($type eq 'randomizetry') {
6680: $trial = $$record{"$where.$partid.tries"};
6681: $rndseed = $$record{"$where.$partid.rndseed"};
6682: }
6683: if ($$record{"$where.$partid.tries"} eq '') {
6684: $displaySub[0].=&mt('Trial not counted');
6685: } else {
6686: $displaySub[0].=&mt('Trial: [_1]',
6687: $$record{"$where.$partid.tries"});
6688: if (($rndseed ne '') && ($lastrndseed{$partid} ne '')) {
6689: if (($rndseed ne $lastrndseed{$partid}) &&
6690: (($type eq 'randomizetry') || ($lasttype{$partid} eq 'randomizetry'))) {
6691: $newvariation = ' ('.&mt('New variation this try').')';
6692: }
1.640 raeburn 6693: }
1.749 raeburn 6694: $lastrndseed{$partid} = $rndseed;
6695: $lasttype{$partid} = $type;
6696: }
6697: my $responseType=($isTask ? 'Task'
1.335 albertel 6698: : $responseType->{$partid}->{$responseId});
1.749 raeburn 6699: if (!exists($orders{$partid})) { $orders{$partid}={}; }
6700: if ((!exists($orders{$partid}->{$responseId})) || ($trial)) {
6701: $orders{$partid}->{$responseId}=
6702: &get_order($partid,$responseId,$symb,$uname,$udom,
6703: $no_increment,$type,$trial,$rndseed);
6704: }
6705: $displaySub[0].='</b>'.$newvariation.'</span>'; # /nobreak
6706: $displaySub[0].=' '.
6707: &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:",$uname,$udom,$type,$trial,$rndseed).'<br />';
6708: }
1.596 raeburn 6709: }
1.147 albertel 6710: }
6711: }
1.335 albertel 6712: if (exists($$record{"$where.$partid.checkedin"})) {
1.485 albertel 6713: $displaySub[1].=&mt('Checked in by [_1] into slot [_2]',
6714: $$record{"$where.$partid.checkedin"},
6715: $$record{"$where.$partid.checkedin.slot"}).
6716: '<br />';
1.335 albertel 6717: }
6718: if (exists $$record{"$where.$partid.award"}) {
1.485 albertel 6719: $displaySub[1].='<b>'.&mt('Part:').'</b> '.$display_part.' '.
1.335 albertel 6720: lc($$record{"$where.$partid.award"}).' '.
6721: $mark{$$record{"$where.$partid.solved"}}.
1.147 albertel 6722: '<br />';
1.749 raeburn 6723: } elsif (($is_tool) && (exists($$record{"$version:resource.$partid.solved"}))) {
6724: if ($$record{"$version:resource.$partid.solved"} =~ /^(in|)correct_by_passback$/) {
6725: $displaySub[1].=&mt('Grade passed back by external tool');
6726: }
1.147 albertel 6727: }
1.335 albertel 6728: if (exists $$record{"$where.$partid.regrader"}) {
1.749 raeburn 6729: $displaySub[2].=$$record{"$where.$partid.regrader"};
6730: unless ($is_tool) {
6731: $displaySub[2].=' (<b>'.&mt('Part').':</b> '.$display_part.')';
6732: }
1.335 albertel 6733: } elsif ($$record{"$version:resource.$partid.regrader"} =~ /\S/) {
6734: $displaySub[2].=
1.749 raeburn 6735: $$record{"$version:resource.$partid.regrader"};
6736: unless ($is_tool) {
6737: $displaySub[2].=' (<b>'.&mt('Part').':</b> '.$display_part.')';
6738: }
1.147 albertel 6739: }
6740: }
6741: # needed because old essay regrader has not parts info
6742: if (exists $$record{"$version:resource.regrader"}) {
6743: $displaySub[2].=$$record{"$version:resource.regrader"};
6744: }
6745: $studentTable.='<td>'.$displaySub[0].' </td><td>'.$displaySub[1];
6746: if ($displaySub[2]) {
1.467 albertel 6747: $studentTable.=&mt('Manually graded by [_1]',$displaySub[2]);
1.147 albertel 6748: }
1.467 albertel 6749: $studentTable.=' </td>'.
6750: &Apache::loncommon::end_data_table_row();
1.119 ng 6751: }
1.467 albertel 6752: $studentTable.=&Apache::loncommon::end_data_table();
1.119 ng 6753: return $studentTable;
1.71 ng 6754: }
6755:
6756: sub updateGradeByPage {
1.608 www 6757: my ($request,$symb) = @_;
1.71 ng 6758:
1.257 albertel 6759: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
6760: my $cnum = $env{"course.$env{'request.course.id'}.num"};
6761: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
6762: my $pageTitle = $env{'form.page'};
1.103 albertel 6763: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 6764: my ($uname,$udom) = split(/:/,$env{'form.student'});
6765: my $usec=$classlist->{$env{'form.student'}}[5];
1.103 albertel 6766: if (!&canmodify($usec)) {
1.526 raeburn 6767: $request->print('<span class="LC_warning">'.&mt('Unable to modify requested student ([_1])',$env{'form.student'}).'</span>');
1.103 albertel 6768: return;
6769: }
1.398 albertel 6770: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.526 raeburn 6771: $result.='<h3> '.&mt('Student: ').&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
1.129 ng 6772: '</h3>'."\n";
1.70 ng 6773:
1.68 ng 6774: $request->print($result);
6775:
1.582 raeburn 6776:
1.132 bowersj2 6777: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 6778: unless (ref($navmap)) {
6779: $request->print(&navmap_errormsg());
6780: return;
6781: }
1.257 albertel 6782: my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $env{'form.page'});
1.71 ng 6783: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 6784: if (!$map) {
1.527 raeburn 6785: $request->print('<span class="LC_warning">'.&mt('Unable to grade requested sequence ([_1]).',$resUrl).'</span>');
1.288 albertel 6786: return;
6787: }
1.71 ng 6788: my $iterator = $navmap->getIterator($map->map_start(),
6789: $map->map_finish());
1.70 ng 6790:
1.484 albertel 6791: my $studentTable=
6792: &Apache::loncommon::start_data_table().
6793: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 6794: '<th align="center"> '.&mt('Prob.').' </th>'.
6795: '<th> '.&mt('Title').' </th>'.
6796: '<th> '.&mt('Previous Score').' </th>'.
6797: '<th> '.&mt('New Score').' </th>'.
1.484 albertel 6798: &Apache::loncommon::end_data_table_header_row();
1.71 ng 6799:
6800: $iterator->next(); # skip the first BEGIN_MAP
6801: my $curRes = $iterator->next(); # for "current resource"
1.726 raeburn 6802: my ($depth,$question,$prob,$changeflag,$hideflag)= (1,1,1,0,0);
1.798 raeburn 6803: my (@updates,%weights,%excuseds,%awardeds,@symbs_in_map);
1.101 albertel 6804: while ($depth > 0) {
1.71 ng 6805: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 6806: if($curRes == $iterator->END_MAP) { $depth--; }
1.71 ng 6807:
1.385 albertel 6808: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 6809: my $parts = $curRes->parts();
1.71 ng 6810: my $title = $curRes->compTitle();
6811: my $symbx = $curRes->symb();
1.798 raeburn 6812: push(@symbs_in_map,$symbx);
1.484 albertel 6813: $studentTable.=
6814: &Apache::loncommon::start_data_table_row().
6815: '<td align="center" valign="top" >'.$prob.
1.485 albertel 6816: (scalar(@{$parts}) == 1 ? ''
1.640 raeburn 6817: : '<br />('.&mt('[quant,_1,part]',scalar(@{$parts}))
1.526 raeburn 6818: .')').'</td>';
1.71 ng 6819: $studentTable.='<td valign="top"> <b>'.$title.'</b> </td>';
6820:
6821: my %newrecord=();
6822: my @displayPts=();
1.269 raeburn 6823: my %aggregate = ();
6824: my $aggregateflag = 0;
1.787 raeburn 6825: my %queueable;
1.726 raeburn 6826: if ($env{'form.HIDE'.$prob}) {
6827: my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
1.727 raeburn 6828: my ($version,$parts) = split(/:/,$env{'form.HIDE'.$prob},2);
1.728 raeburn 6829: my $numchgs = &makehidden($version,$parts,\%record,$symbx,$udom,$uname,1);
1.798 raeburn 6830: if ($numchgs) {
6831: push(@updates,$symbx);
6832: }
1.726 raeburn 6833: $hideflag += $numchgs;
6834: }
1.71 ng 6835: foreach my $partid (@{$parts}) {
1.257 albertel 6836: my $newpts = $env{'form.GD_BOX'.$question.'_'.$partid};
6837: my $oldpts = $env{'form.oldpts'.$question.'_'.$partid};
1.787 raeburn 6838: my @types = $curRes->responseType($partid);
1.786 raeburn 6839: if (grep(/^essay$/,@types)) {
6840: $queueable{$partid} = 1;
6841: } else {
1.787 raeburn 6842: my @ids = $curRes->responseIds($partid);
1.786 raeburn 6843: for (my $i=0; $i < scalar(@ids); $i++) {
1.787 raeburn 6844: my $hndgrd = &Apache::lonnet::EXT('resource.'.$partid.'_'.$ids[$i].
1.786 raeburn 6845: '.handgrade',$symb);
6846: if (lc($hndgrd) eq 'yes') {
6847: $queueable{$partid} = 1;
6848: last;
6849: }
6850: }
6851: }
1.257 albertel 6852: my $wgt = $env{'form.WGT'.$question.'_'.$partid} != 0 ?
6853: $env{'form.WGT'.$question.'_'.$partid} : 1;
1.798 raeburn 6854: $weights{$symbx}{$partid} = $wgt;
6855: $excuseds{$symbx}{$partid} = '';
1.71 ng 6856: my $partial = $newpts/$wgt;
6857: my $score;
6858: if ($partial > 0) {
6859: $score = 'correct_by_override';
1.125 ng 6860: } elsif ($newpts ne '') { #empty is taken as 0
1.71 ng 6861: $score = 'incorrect_by_override';
6862: }
1.257 albertel 6863: my $dropMenu = $env{'form.GD_SEL'.$question.'_'.$partid};
1.125 ng 6864: if ($dropMenu eq 'excused') {
1.71 ng 6865: $partial = '';
6866: $score = 'excused';
1.798 raeburn 6867: $excuseds{$symbx}{$partid} = 1;
1.125 ng 6868: } elsif ($dropMenu eq 'reset status'
1.257 albertel 6869: && $env{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
1.125 ng 6870: $newrecord{'resource.'.$partid.'.tries'} = 0;
6871: $newrecord{'resource.'.$partid.'.solved'} = '';
6872: $newrecord{'resource.'.$partid.'.award'} = '';
6873: $newrecord{'resource.'.$partid.'.awarded'} = 0;
1.257 albertel 6874: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 6875: $changeflag++;
6876: $newpts = '';
1.269 raeburn 6877:
6878: my $aggtries = $env{'form.aggtries'.$question.'_'.$partid};
6879: my $totaltries = $env{'form.totaltries'.$question.'_'.$partid};
6880: my $solvedstatus = $env{'form.solved'.$question.'_'.$partid};
6881: if ($aggtries > 0) {
6882: &decrement_aggs($symbx,$partid,\%aggregate,$aggtries,$totaltries,$solvedstatus);
6883: $aggregateflag = 1;
6884: }
1.71 ng 6885: }
1.324 albertel 6886: my $display_part=&get_display_part($partid,$curRes->symb());
1.257 albertel 6887: my $oldstatus = $env{'form.solved'.$question.'_'.$partid};
1.526 raeburn 6888: $displayPts[0].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.71 ng 6889: (($oldstatus eq 'excused') ? 'excused' : $oldpts).
1.326 albertel 6890: ' <br />';
1.526 raeburn 6891: $displayPts[1].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.125 ng 6892: (($score eq 'excused') ? 'excused' : $newpts).
1.326 albertel 6893: ' <br />';
1.71 ng 6894: $question++;
1.798 raeburn 6895: if (($newpts eq '') || ($partial eq '')) {
6896: $awardeds{$symbx}{$partid} = 0;
6897: } else {
6898: $awardeds{$symbx}{$partid} = $partial;
6899: }
1.380 albertel 6900: next if ($dropMenu eq 'reset status' || ($newpts eq $oldpts && $score ne 'excused'));
1.125 ng 6901:
1.71 ng 6902: $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
1.125 ng 6903: $newrecord{'resource.'.$partid.'.solved'} = $score if $score ne '';
1.257 albertel 6904: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}"
1.125 ng 6905: if (scalar(keys(%newrecord)) > 0);
1.71 ng 6906:
6907: $changeflag++;
6908: }
6909: if (scalar(keys(%newrecord)) > 0) {
1.382 albertel 6910: my %record =
6911: &Apache::lonnet::restore($symbx,$env{'request.course.id'},
6912: $udom,$uname);
6913:
6914: if (&Apache::lonnet::validCODE($env{'form.CODE'})) {
6915: $newrecord{'resource.CODE'} = $env{'form.CODE'};
6916: } elsif (&Apache::lonnet::validCODE($record{'resource.CODE'})) {
6917: $newrecord{'resource.CODE'} = '';
6918: }
1.257 albertel 6919: &Apache::lonnet::cstore(\%newrecord,$symbx,$env{'request.course.id'},
1.71 ng 6920: $udom,$uname);
1.382 albertel 6921: %record = &Apache::lonnet::restore($symbx,
6922: $env{'request.course.id'},
6923: $udom,$uname);
1.380 albertel 6924: &check_and_remove_from_queue($parts,\%record,undef,$symbx,
1.786 raeburn 6925: $cdom,$cnum,$udom,$uname,\%queueable);
1.71 ng 6926: }
1.380 albertel 6927:
1.269 raeburn 6928: if ($aggregateflag) {
6929: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
6930: $env{'course.'.$env{'request.course.id'}.'.domain'},
6931: $env{'course.'.$env{'request.course.id'}.'.num'});
6932: }
1.125 ng 6933:
1.71 ng 6934: $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
6935: '<td valign="top">'.$displayPts[1].'</td>'.
1.484 albertel 6936: &Apache::loncommon::end_data_table_row();
1.68 ng 6937:
1.196 albertel 6938: $prob++;
1.798 raeburn 6939: if ($changeflag) {
6940: push(@updates,$symbx);
6941: }
1.68 ng 6942: }
1.71 ng 6943: $curRes = $iterator->next();
1.68 ng 6944: }
1.98 albertel 6945:
1.484 albertel 6946: $studentTable.=&Apache::loncommon::end_data_table();
1.526 raeburn 6947: my $grademsg=($changeflag == 0 ? &mt('No score was changed or updated.') :
6948: &mt('The scores were changed for [quant,_1,problem].',
1.726 raeburn 6949: $changeflag).'<br />');
6950: my $hidemsg=($hideflag == 0 ? '' :
6951: &mt('Submissions were marked "hidden" for [quant,_1,transaction].',
6952: $hideflag).'<br />');
6953: $request->print($hidemsg.$grademsg.$studentTable);
1.68 ng 6954:
1.798 raeburn 6955: if (@updates) {
6956: my (@allsymbs,$mapsymb,@recurseup,%parentmapsymbs,%possmappb,%possrespb);
6957: @allsymbs = @updates;
6958: if (ref($map)) {
6959: $mapsymb = $map->symb();
6960: push(@allsymbs,$mapsymb);
6961: @recurseup = $navmap->recurseup_maps($map->src,1);
6962: }
6963: if (@recurseup) {
6964: push(@allsymbs,@recurseup);
6965: map { $parentmapsymbs{$_} = 1; } @recurseup;
6966: }
6967: my %passback = &Apache::lonnet::get('nohist_linkprot_passback',\@allsymbs,$cdom,$cnum);
6968: my (%uniqsymbs,$use_symbs_in_map);
6969: if (keys(%passback)) {
6970: foreach my $possible (keys(%passback)) {
6971: if (ref($passback{$possible}) eq 'HASH') {
6972: if ($possible eq $mapsymb) {
6973: foreach my $launcher (keys(%{$passback{$possible}})) {
6974: $possmappb{$launcher} = 1;
6975: }
6976: $use_symbs_in_map = 1;
6977: } elsif (exists($parentmapsymbs{$possible})) {
6978: foreach my $launcher (keys(%{$passback{$possible}})) {
6979: my ($linkuri,$linkprotector,$scope) = split(/\0/,$launcher);
6980: if ($scope eq 'rec') {
6981: $possmappb{$launcher} = 1;
6982: $use_symbs_in_map = 1;
6983: }
6984: }
6985: } elsif (grep(/^\Q$possible$\E$/,@updates)) {
6986: foreach my $launcher (keys(%{$passback{$possible}})) {
6987: $possrespb{$launcher} = 1;
6988: }
6989: $uniqsymbs{$possible} = 1;
6990: }
6991: }
6992: }
6993: }
6994: if ($use_symbs_in_map) {
6995: map { $uniqsymbs{$_} = 1; } @symbs_in_map;
6996: }
6997: my @posslaunchers;
6998: if (keys(%possmappb)) {
6999: push(@posslaunchers,keys(%possmappb));
7000: }
7001: if (keys(%possrespb)) {
7002: push(@posslaunchers,keys(%possrespb));
7003: }
7004: if (@posslaunchers) {
7005: my (%pbsave,%skip_passback,%needpb);
7006: my %pbids = &Apache::lonnet::get('nohist_'.$cdom.'_'.$cnum.'_linkprot_pb',\@posslaunchers,$udom,$uname);
7007: foreach my $key (keys(%pbids)) {
7008: if (ref($pbids{$key}) eq 'ARRAY') {
7009: $needpb{$key} = 1;
7010: }
7011: }
7012: my @symbs = keys(%uniqsymbs);
1.802 ! raeburn 7013: &process_passbacks('updatebypage',\@symbs,$cdom,$cnum,$udom,$uname,$usec,\%weights,
1.798 raeburn 7014: \%awardeds,\%excuseds,\%needpb,\%skip_passback,\%pbsave,\%pbids);
1.801 raeburn 7015: if (@Apache::grades::ltipassback) {
1.798 raeburn 7016: unless ($registered_cleanup) {
7017: my $handlers = $request->get_handlers('PerlCleanupHandler');
7018: $request->set_handlers('PerlCleanupHandler' =>
1.801 raeburn 7019: [\&Apache::grades::make_passback,@{$handlers}]);
7020: $registered_cleanup=1;
1.798 raeburn 7021: }
7022: }
7023: }
7024: }
1.70 ng 7025: return '';
7026: }
7027:
1.801 raeburn 7028: sub make_passback {
7029: if (@Apache::grades::ltipassback) {
7030: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
7031: my $ip = &Apache::lonnet::get_host_ip($lonhost);
7032: foreach my $item (@Apache::grades::ltipassback) {
7033: &Apache::lonhomework::run_passback($item,$lonhost,$ip);
7034: }
7035: undef(@Apache::grades::ltipassback);
7036: }
7037: }
7038:
1.72 ng 7039: #-------- end of section for handling grading by page/sequence ---------
7040: #
7041: #-------------------------------------------------------------------
7042:
1.581 www 7043: #-------------------- Bubblesheet (Scantron) Grading -------------------
1.75 albertel 7044: #
7045: #------ start of section for handling grading by page/sequence ---------
7046:
1.423 albertel 7047: =pod
7048:
7049: =head1 Bubble sheet grading routines
7050:
1.424 albertel 7051: For this documentation:
7052:
7053: 'scanline' refers to the full line of characters
7054: from the file that we are parsing that represents one entire sheet
7055:
7056: 'bubble line' refers to the data
1.659 raeburn 7057: representing the line of bubbles that are on the physical bubblesheet
1.424 albertel 7058:
7059:
1.659 raeburn 7060: The overall process is that a scanned in bubblesheet data is uploaded
1.424 albertel 7061: into a course. When a user wants to grade, they select a
1.659 raeburn 7062: sequence/folder of resources, a file of bubblesheet info, and pick
1.424 albertel 7063: one of the predefined configurations for what each scanline looks
7064: like.
7065:
7066: Next each scanline is checked for any errors of either 'missing
1.435 foxr 7067: bubbles' (it's an error because it may have been mis-scanned
1.424 albertel 7068: because too light bubbling), 'double bubble' (each bubble line should
1.703 bisitz 7069: have no more than one letter picked), invalid or duplicated CODE,
1.556 weissno 7070: invalid student/employee ID
1.424 albertel 7071:
7072: If the CODE option is used that determines the randomization of the
1.556 weissno 7073: homework problems, either way the student/employee ID is looked up into a
1.424 albertel 7074: username:domain.
7075:
7076: During the validation phase the instructor can choose to skip scanlines.
7077:
1.659 raeburn 7078: After the validation phase, there are now 3 bubblesheet files
1.424 albertel 7079:
7080: scantron_original_filename (unmodified original file)
7081: scantron_corrected_filename (file where the corrected information has replaced the original information)
7082: scantron_skipped_filename (contains the exact text of scanlines that where skipped)
7083:
7084: Also there is a separate hash nohist_scantrondata that contains extra
1.659 raeburn 7085: correction information that isn't representable in the bubblesheet
1.424 albertel 7086: file (see &scantron_getfile() for more information)
7087:
7088: After all scanlines are either valid, marked as valid or skipped, then
7089: foreach line foreach problem in the picked sequence, an ssi request is
7090: made that simulates a user submitting their selected letter(s) against
7091: the homework problem.
1.423 albertel 7092:
7093: =over 4
7094:
7095:
7096:
7097: =item defaultFormData
7098:
7099: Returns html hidden inputs used to hold context/default values.
7100:
7101: Arguments:
7102: $symb - $symb of the current resource
7103:
7104: =cut
1.422 foxr 7105:
1.81 albertel 7106: sub defaultFormData {
1.324 albertel 7107: my ($symb)=@_;
1.766 raeburn 7108: return '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />';
1.81 albertel 7109: }
7110:
1.447 foxr 7111:
1.423 albertel 7112: =pod
7113:
7114: =item getSequenceDropDown
7115:
7116: Return html dropdown of possible sequences to grade
7117:
7118: Arguments:
1.582 raeburn 7119: $symb - $symb of the current resource
7120: $map_error - ref to scalar which will container error if
7121: $navmap object is unavailable in &getSymbMap().
1.423 albertel 7122:
7123: =cut
1.422 foxr 7124:
1.75 albertel 7125: sub getSequenceDropDown {
1.582 raeburn 7126: my ($symb,$map_error)=@_;
1.75 albertel 7127: my $result='<select name="selectpage">'."\n";
1.582 raeburn 7128: my ($titles,$symbx) = &getSymbMap($map_error);
7129: if (ref($map_error)) {
7130: return if ($$map_error);
7131: }
1.137 albertel 7132: my ($curpage)=&Apache::lonnet::decode_symb($symb);
1.75 albertel 7133: my $ctr=0;
7134: foreach (@$titles) {
7135: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
7136: $result.='<option value="'.$$symbx{$_}.'" '.
1.401 albertel 7137: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.75 albertel 7138: '>'.$showtitle.'</option>'."\n";
7139: $ctr++;
7140: }
7141: $result.= '</select>';
7142: return $result;
7143: }
7144:
1.495 albertel 7145: my %bubble_lines_per_response; # no. bubble lines for each response.
1.554 raeburn 7146: # key is zero-based index - 0, 1, 2 ...
1.495 albertel 7147:
7148: my %first_bubble_line; # First bubble line no. for each bubble.
7149:
1.509 raeburn 7150: my %subdivided_bubble_lines; # no. bubble lines for optionresponse,
7151: # matchresponse or rankresponse, where
7152: # an individual response can have multiple
7153: # lines
1.503 raeburn 7154:
7155: my %responsetype_per_response; # responsetype for each response
7156:
1.691 raeburn 7157: my %masterseq_id_responsenum; # src_id (e.g., 12.3_0.11 etc.) for each
7158: # numbered response. Needed when randomorder
7159: # or randompick are in use. Key is ID, value
7160: # is response number.
7161:
1.495 albertel 7162: # Save and restore the bubble lines array to the form env.
7163:
7164:
7165: sub save_bubble_lines {
7166: foreach my $line (keys(%bubble_lines_per_response)) {
7167: $env{"form.scantron.bubblelines.$line"} = $bubble_lines_per_response{$line};
7168: $env{"form.scantron.first_bubble_line.$line"} =
7169: $first_bubble_line{$line};
1.503 raeburn 7170: $env{"form.scantron.sub_bubblelines.$line"} =
7171: $subdivided_bubble_lines{$line};
7172: $env{"form.scantron.responsetype.$line"} =
7173: $responsetype_per_response{$line};
1.495 albertel 7174: }
1.691 raeburn 7175: foreach my $resid (keys(%masterseq_id_responsenum)) {
7176: my $line = $masterseq_id_responsenum{$resid};
7177: $env{"form.scantron.residpart.$line"} = $resid;
7178: }
1.495 albertel 7179: }
7180:
7181:
7182: sub restore_bubble_lines {
7183: my $line = 0;
7184: %bubble_lines_per_response = ();
1.691 raeburn 7185: %masterseq_id_responsenum = ();
1.495 albertel 7186: while ($env{"form.scantron.bubblelines.$line"}) {
7187: my $value = $env{"form.scantron.bubblelines.$line"};
7188: $bubble_lines_per_response{$line} = $value;
7189: $first_bubble_line{$line} =
7190: $env{"form.scantron.first_bubble_line.$line"};
1.503 raeburn 7191: $subdivided_bubble_lines{$line} =
7192: $env{"form.scantron.sub_bubblelines.$line"};
7193: $responsetype_per_response{$line} =
7194: $env{"form.scantron.responsetype.$line"};
1.691 raeburn 7195: my $id = $env{"form.scantron.residpart.$line"};
7196: $masterseq_id_responsenum{$id} = $line;
1.495 albertel 7197: $line++;
7198: }
7199: }
7200:
1.423 albertel 7201: =pod
7202:
7203: =item scantron_filenames
7204:
7205: Returns a list of the scantron files in the current course
7206:
7207: =cut
1.422 foxr 7208:
1.202 albertel 7209: sub scantron_filenames {
1.257 albertel 7210: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7211: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
1.517 raeburn 7212: my $getpropath = 1;
1.662 raeburn 7213: my ($dirlist,$listerror) = &Apache::lonnet::dirlist('userfiles',$cdom,
7214: $cname,$getpropath);
1.202 albertel 7215: my @possiblenames;
1.662 raeburn 7216: if (ref($dirlist) eq 'ARRAY') {
7217: foreach my $filename (sort(@{$dirlist})) {
7218: ($filename)=split(/&/,$filename);
7219: if ($filename!~/^scantron_orig_/) { next ; }
7220: $filename=~s/^scantron_orig_//;
7221: push(@possiblenames,$filename);
7222: }
1.202 albertel 7223: }
7224: return @possiblenames;
7225: }
7226:
1.423 albertel 7227: =pod
7228:
7229: =item scantron_uploads
7230:
7231: Returns html drop-down list of scantron files in current course.
7232:
7233: Arguments:
7234: $file2grade - filename to set as selected in the dropdown
7235:
7236: =cut
1.422 foxr 7237:
1.202 albertel 7238: sub scantron_uploads {
1.209 ng 7239: my ($file2grade) = @_;
1.202 albertel 7240: my $result= '<select name="scantron_selectfile">';
7241: $result.="<option></option>";
7242: foreach my $filename (sort(&scantron_filenames())) {
1.401 albertel 7243: $result.="<option".($filename eq $file2grade ? ' selected="selected"':'').">$filename</option>\n";
1.81 albertel 7244: }
7245: $result.="</select>";
7246: return $result;
7247: }
7248:
1.423 albertel 7249: =pod
7250:
7251: =item scantron_scantab
7252:
7253: Returns html drop down of the scantron formats in the scantronformat.tab
7254: file.
7255:
7256: =cut
1.422 foxr 7257:
1.82 albertel 7258: sub scantron_scantab {
7259: my $result='<select name="scantron_format">'."\n";
1.191 albertel 7260: $result.='<option></option>'."\n";
1.754 raeburn 7261: my @lines = &Apache::lonnet::get_scantronformat_file();
1.518 raeburn 7262: if (@lines > 0) {
7263: foreach my $line (@lines) {
7264: next if (($line =~ /^\#/) || ($line eq ''));
7265: my ($name,$descrip)=split(/:/,$line);
7266: $result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
7267: }
1.82 albertel 7268: }
7269: $result.='</select>'."\n";
1.518 raeburn 7270: return $result;
7271: }
7272:
1.423 albertel 7273: =pod
7274:
7275: =item scantron_CODElist
7276:
7277: Returns html drop down of the saved CODE lists from current course,
7278: generated from earlier printings.
7279:
7280: =cut
1.422 foxr 7281:
1.186 albertel 7282: sub scantron_CODElist {
1.257 albertel 7283: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7284: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.186 albertel 7285: my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
7286: my $namechoice='<option></option>';
1.225 albertel 7287: foreach my $name (sort {uc($a) cmp uc($b)} @names) {
1.191 albertel 7288: if ($name =~ /^error: 2 /) { next; }
1.278 albertel 7289: if ($name =~ /^type\0/) { next; }
1.186 albertel 7290: $namechoice.='<option value="'.$name.'">'.$name.'</option>';
7291: }
7292: $namechoice='<select name="scantron_CODElist">'.$namechoice.'</select>';
7293: return $namechoice;
7294: }
7295:
1.423 albertel 7296: =pod
7297:
7298: =item scantron_CODEunique
7299:
7300: Returns the html for "Each CODE to be used once" radio.
7301:
7302: =cut
1.422 foxr 7303:
1.186 albertel 7304: sub scantron_CODEunique {
1.532 bisitz 7305: my $result='<span class="LC_nobreak">
1.272 albertel 7306: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 7307: value="yes" checked="checked" />'.&mt('Yes').' </label>
1.381 albertel 7308: </span>
1.532 bisitz 7309: <span class="LC_nobreak">
1.272 albertel 7310: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 7311: value="no" />'.&mt('No').' </label>
1.381 albertel 7312: </span>';
1.186 albertel 7313: return $result;
7314: }
1.423 albertel 7315:
7316: =pod
7317:
7318: =item scantron_selectphase
7319:
1.659 raeburn 7320: Generates the initial screen to start the bubblesheet process.
1.423 albertel 7321: Allows for - starting a grading run.
1.424 albertel 7322: - downloading existing scan data (original, corrected
1.423 albertel 7323: or skipped info)
7324:
7325: - uploading new scan data
7326:
7327: Arguments:
7328: $r - The Apache request object
7329: $file2grade - name of the file that contain the scanned data to score
7330:
7331: =cut
1.186 albertel 7332:
1.75 albertel 7333: sub scantron_selectphase {
1.608 www 7334: my ($r,$file2grade,$symb) = @_;
1.75 albertel 7335: if (!$symb) {return '';}
1.582 raeburn 7336: my $map_error;
7337: my $sequence_selector=&getSequenceDropDown($symb,\$map_error);
7338: if ($map_error) {
7339: $r->print('<br />'.&navmap_errormsg().'<br />');
7340: return;
7341: }
1.324 albertel 7342: my $default_form_data=&defaultFormData($symb);
1.209 ng 7343: my $file_selector=&scantron_uploads($file2grade);
1.82 albertel 7344: my $format_selector=&scantron_scantab();
1.186 albertel 7345: my $CODE_selector=&scantron_CODElist();
7346: my $CODE_unique=&scantron_CODEunique();
1.75 albertel 7347: my $result;
1.422 foxr 7348:
1.513 foxr 7349: $ssi_error = 0;
7350:
1.770 raeburn 7351: if (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) || $perm{'usc'}) {
1.606 wenzelju 7352:
7353: # Chunk of form to prompt for a scantron file upload.
7354:
7355: $r->print('
1.754 raeburn 7356: <br />');
1.606 wenzelju 7357: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
7358: my $cnum= $env{'course.'.$env{'request.course.id'}.'.num'};
1.770 raeburn 7359: my $csec= $env{'request.course.sec'};
1.736 damieng 7360: my $alertmsg = &mt('Please use the browse button to select a file from your local directory.');
7361: &js_escape(\$alertmsg);
1.754 raeburn 7362: my ($formatoptions,$formattitle,$formatjs) = &scantron_upload_dataformat($cdom);
1.606 wenzelju 7363: $r->print(&Apache::lonhtmlcommon::scripttag('
7364: function checkUpload(formname) {
7365: if (formname.upfile.value == "") {
1.736 damieng 7366: alert("'.$alertmsg.'");
1.606 wenzelju 7367: return false;
7368: }
7369: formname.submit();
1.756 raeburn 7370: }'."\n".$formatjs));
1.606 wenzelju 7371: $r->print('
7372: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
7373: '.$default_form_data.'
7374: <input name="courseid" type="hidden" value="'.$cnum.'" />
1.770 raeburn 7375: <input name="coursesec" type="hidden" value="'.$csec.'" />
1.606 wenzelju 7376: <input name="domainid" type="hidden" value="'.$cdom.'" />
7377: <input name="command" value="scantronupload_save" type="hidden" />
1.754 raeburn 7378: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
7379: '.&Apache::loncommon::start_data_table_header_row().'
7380: <th>
7381: '.&mt('Specify a bubblesheet data file to upload.').'
7382: </th>
7383: '.&Apache::loncommon::end_data_table_header_row().'
7384: '.&Apache::loncommon::start_data_table_row().'
7385: <td>
7386: '.&mt('File to upload: [_1]','<input type="file" name="upfile" size="50" />').'<br />'."\n");
7387: if ($formatoptions) {
7388: $r->print('</td>
7389: '.&Apache::loncommon::end_data_table_row().'
7390: '.&Apache::loncommon::start_data_table_row().'
7391: <td>'.$formattitle.(' 'x2).$formatoptions.'
7392: </td>
7393: '.&Apache::loncommon::end_data_table_row().'
7394: '.&Apache::loncommon::start_data_table_row().'
7395: <td>'
7396: );
7397: } else {
7398: $r->print(' <br />');
7399: }
7400: $r->print('<input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
7401: </td>
7402: '.&Apache::loncommon::end_data_table_row().'
7403: '.&Apache::loncommon::end_data_table().'
7404: </form>'
7405: );
1.606 wenzelju 7406:
7407: }
7408:
1.422 foxr 7409: # Chunk of form to prompt for a file to grade and how:
7410:
1.489 albertel 7411: $result.= '
7412: <br />
7413: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantron_process">
7414: <input type="hidden" name="command" value="scantron_warning" />
7415: '.$default_form_data.'
7416: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
7417: '.&Apache::loncommon::start_data_table_header_row().'
7418: <th colspan="2">
1.492 albertel 7419: '.&mt('Specify file and which Folder/Sequence to grade').'
1.489 albertel 7420: </th>
7421: '.&Apache::loncommon::end_data_table_header_row().'
7422: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 7423: <td> '.&mt('Sequence to grade:').' </td><td> '.$sequence_selector.' </td>
1.489 albertel 7424: '.&Apache::loncommon::end_data_table_row().'
7425: '.&Apache::loncommon::start_data_table_row().'
1.572 www 7426: <td> '.&mt('Filename of bubblesheet data file:').' </td><td> '.$file_selector.' </td>
1.489 albertel 7427: '.&Apache::loncommon::end_data_table_row().'
7428: '.&Apache::loncommon::start_data_table_row().'
1.572 www 7429: <td> '.&mt('Format of bubblesheet data file:').' </td><td> '.$format_selector.' </td>
1.489 albertel 7430: '.&Apache::loncommon::end_data_table_row().'
7431: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 7432: <td> '.&mt('Saved CODEs to validate against:').' </td><td> '.$CODE_selector.' </td>
1.489 albertel 7433: '.&Apache::loncommon::end_data_table_row().'
7434: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 7435: <td> '.&mt('Each CODE is only to be used once:').'</td><td> '.$CODE_unique.' </td>
1.489 albertel 7436: '.&Apache::loncommon::end_data_table_row().'
7437: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 7438: <td> '.&mt('Options:').' </td>
1.187 albertel 7439: <td>
1.492 albertel 7440: <label><input type="checkbox" name="scantron_options_redo" value="redo_skipped"/> '.&mt('Do only previously skipped records').'</label> <br />
7441: <label><input type="checkbox" name="scantron_options_ignore" value="ignore_corrections"/> '.&mt('Remove all existing corrections').'</label> <br />
7442: <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources when grading').'</label>
1.187 albertel 7443: </td>
1.489 albertel 7444: '.&Apache::loncommon::end_data_table_row().'
7445: '.&Apache::loncommon::start_data_table_row().'
1.174 albertel 7446: <td colspan="2">
1.572 www 7447: <input type="submit" value="'.&mt('Grading: Validate Bubblesheet Records').'" />
1.162 albertel 7448: </td>
1.489 albertel 7449: '.&Apache::loncommon::end_data_table_row().'
7450: '.&Apache::loncommon::end_data_table().'
7451: </form>
7452: ';
1.162 albertel 7453:
7454: $r->print($result);
7455:
1.422 foxr 7456: # Chunk of the form that prompts to view a scoring office file,
7457: # corrected file, skipped records in a file.
7458:
1.489 albertel 7459: $r->print('
7460: <br />
7461: <form action="/adm/grades" name="scantron_download">
7462: '.$default_form_data.'
7463: <input type="hidden" name="command" value="scantron_download" />
7464: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
7465: '.&Apache::loncommon::start_data_table_header_row().'
7466: <th>
1.492 albertel 7467: '.&mt('Download a scoring office file').'
1.489 albertel 7468: </th>
7469: '.&Apache::loncommon::end_data_table_header_row().'
7470: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 7471: <td> '.&mt('Filename of scoring office file: [_1]',$file_selector).'
1.489 albertel 7472: <br />
1.492 albertel 7473: <input type="submit" value="'.&mt('Download: Show List of Associated Files').'" />
1.489 albertel 7474: '.&Apache::loncommon::end_data_table_row().'
7475: '.&Apache::loncommon::end_data_table().'
7476: </form>
7477: <br />
7478: ');
1.162 albertel 7479:
1.457 banghart 7480: &Apache::lonpickcode::code_list($r,2);
1.523 raeburn 7481:
1.694 bisitz 7482: $r->print('<br /><form method="post" name="checkscantron" action="">'.
1.523 raeburn 7483: $default_form_data."\n".
7484: &Apache::loncommon::start_data_table('LC_scantron_action')."\n".
7485: &Apache::loncommon::start_data_table_header_row()."\n".
7486: '<th colspan="2">
1.572 www 7487: '.&mt('Review bubblesheet data and submissions for a previously graded folder/sequence')."\n".
1.523 raeburn 7488: '</th>'."\n".
7489: &Apache::loncommon::end_data_table_header_row()."\n".
7490: &Apache::loncommon::start_data_table_row()."\n".
7491: '<td> '.&mt('Graded folder/sequence:').' </td>'."\n".
7492: '<td> '.$sequence_selector.' </td>'.
7493: &Apache::loncommon::end_data_table_row()."\n".
7494: &Apache::loncommon::start_data_table_row()."\n".
7495: '<td> '.&mt('Filename of scoring office file:').' </td>'."\n".
7496: '<td> '.$file_selector.' </td>'."\n".
7497: &Apache::loncommon::end_data_table_row()."\n".
7498: &Apache::loncommon::start_data_table_row()."\n".
7499: '<td> '.&mt('Format of data file:').' </td>'."\n".
7500: '<td> '.$format_selector.' </td>'."\n".
7501: &Apache::loncommon::end_data_table_row()."\n".
7502: &Apache::loncommon::start_data_table_row()."\n".
1.557 raeburn 7503: '<td> '.&mt('Options').' </td>'."\n".
7504: '<td> <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources').'</label></td>'.
7505: &Apache::loncommon::end_data_table_row()."\n".
7506: &Apache::loncommon::start_data_table_row()."\n".
1.523 raeburn 7507: '<td colspan="2">'."\n".
7508: '<input type="hidden" name="command" value="checksubmissions" />'."\n".
1.575 www 7509: '<input type="submit" value="'.&mt('Review Bubblesheet Data and Submission Records').'" />'."\n".
1.523 raeburn 7510: '</td>'."\n".
7511: &Apache::loncommon::end_data_table_row()."\n".
7512: &Apache::loncommon::end_data_table()."\n".
7513: '</form><br />');
7514: return;
1.75 albertel 7515: }
7516:
1.423 albertel 7517: =pod
7518:
7519: =item username_to_idmap
7520:
1.556 weissno 7521: creates a hash keyed by student/employee ID with values of the corresponding
1.731 raeburn 7522: student username:domain. If a single ID occurs for more than one student,
7523: the status of the student is checked, and if Active, the value in the hash
7524: will be set to the Active student.
1.423 albertel 7525:
7526: Arguments:
7527:
7528: $classlist - reference to the class list hash. This is a hash
7529: keyed by student name:domain whose elements are references
1.424 albertel 7530: to arrays containing various chunks of information
1.423 albertel 7531: about the student. (See loncoursedata for more info).
7532:
7533: Returns
7534: %idmap - the constructed hash
7535:
7536: =cut
7537:
1.82 albertel 7538: sub username_to_idmap {
7539: my ($classlist)= @_;
7540: my %idmap;
7541: foreach my $student (keys(%$classlist)) {
1.731 raeburn 7542: my $id = $classlist->{$student}->[&Apache::loncoursedata::CL_ID];
7543: unless ($id eq '') {
7544: if (!exists($idmap{$id})) {
7545: $idmap{$id} = $student;
7546: } else {
7547: my $status = $classlist->{$student}->[&Apache::loncoursedata::CL_STATUS];
7548: if ($status eq 'Active') {
7549: $idmap{$id} = $student;
7550: }
7551: }
7552: }
1.82 albertel 7553: }
7554: return %idmap;
7555: }
1.423 albertel 7556:
7557: =pod
7558:
1.424 albertel 7559: =item scantron_fixup_scanline
1.423 albertel 7560:
7561: Process a requested correction to a scanline.
7562:
7563: Arguments:
1.754 raeburn 7564: $scantron_config - hash from &Apache::lonnet::get_scantron_config()
1.423 albertel 7565: $scan_data - hash of correction information
7566: (see &scantron_getfile())
7567: $line - existing scanline
7568: $whichline - line number of the passed in scanline
7569: $field - type of change to process
7570: (either
1.573 bisitz 7571: 'ID' -> correct the student/employee ID
1.423 albertel 7572: 'CODE' -> correct the CODE
7573: 'answer' -> fixup the submitted answers)
7574:
7575: $args - hash of additional info,
7576: - 'ID'
7577: 'newid' -> studentID to use in replacement
1.424 albertel 7578: of existing one
1.423 albertel 7579: - 'CODE'
7580: 'CODE_ignore_dup' - set to true if duplicates
7581: should be ignored.
7582: 'CODE' - is new code or 'use_unfound'
1.424 albertel 7583: if the existing unfound code should
1.423 albertel 7584: be used as is
7585: - 'answer'
7586: 'response' - new answer or 'none' if blank
7587: 'question' - the bubble line to change
1.503 raeburn 7588: 'questionnum' - the question identifier,
7589: may include subquestion.
1.423 albertel 7590:
7591: Returns:
7592: $line - the modified scanline
7593:
7594: Side effects:
7595: $scan_data - may be updated
7596:
7597: =cut
7598:
1.82 albertel 7599:
1.157 albertel 7600: sub scantron_fixup_scanline {
7601: my ($scantron_config,$scan_data,$line,$whichline,$field,$args)=@_;
7602: if ($field eq 'ID') {
7603: if (length($args->{'newid'}) > $$scantron_config{'IDlength'}) {
1.186 albertel 7604: return ($line,1,'New value too large');
1.157 albertel 7605: }
7606: if (length($args->{'newid'}) < $$scantron_config{'IDlength'}) {
7607: $args->{'newid'}=sprintf('%-'.$$scantron_config{'IDlength'}.'s',
7608: $args->{'newid'});
7609: }
7610: substr($line,$$scantron_config{'IDstart'}-1,
7611: $$scantron_config{'IDlength'})=$args->{'newid'};
7612: if ($args->{'newid'}=~/^\s*$/) {
7613: &scan_data($scan_data,"$whichline.user",
7614: $args->{'username'}.':'.$args->{'domain'});
7615: }
1.186 albertel 7616: } elsif ($field eq 'CODE') {
1.192 albertel 7617: if ($args->{'CODE_ignore_dup'}) {
7618: &scan_data($scan_data,"$whichline.CODE_ignore_dup",'1');
7619: }
7620: &scan_data($scan_data,"$whichline.useCODE",'1');
7621: if ($args->{'CODE'} ne 'use_unfound') {
1.191 albertel 7622: if (length($args->{'CODE'}) > $$scantron_config{'CODElength'}) {
7623: return ($line,1,'New CODE value too large');
7624: }
7625: if (length($args->{'CODE'}) < $$scantron_config{'CODElength'}) {
7626: $args->{'CODE'}=sprintf('%-'.$$scantron_config{'CODElength'}.'s',$args->{'CODE'});
7627: }
7628: substr($line,$$scantron_config{'CODEstart'}-1,
7629: $$scantron_config{'CODElength'})=$args->{'CODE'};
1.186 albertel 7630: }
1.157 albertel 7631: } elsif ($field eq 'answer') {
1.497 foxr 7632: my $length=$scantron_config->{'Qlength'};
1.157 albertel 7633: my $off=$scantron_config->{'Qoff'};
7634: my $on=$scantron_config->{'Qon'};
1.497 foxr 7635: my $answer=${off}x$length;
7636: if ($args->{'response'} eq 'none') {
7637: &scan_data($scan_data,
1.503 raeburn 7638: "$whichline.no_bubble.".$args->{'questionnum'},'1');
1.497 foxr 7639: } else {
7640: if ($on eq 'letter') {
7641: my @alphabet=('A'..'Z');
7642: $answer=$alphabet[$args->{'response'}];
7643: } elsif ($on eq 'number') {
7644: $answer=$args->{'response'}+1;
7645: if ($answer == 10) { $answer = '0'; }
1.274 albertel 7646: } else {
1.497 foxr 7647: substr($answer,$args->{'response'},1)=$on;
1.274 albertel 7648: }
1.497 foxr 7649: &scan_data($scan_data,
1.503 raeburn 7650: "$whichline.no_bubble.".$args->{'questionnum'},undef,'1');
1.157 albertel 7651: }
1.497 foxr 7652: my $where=$length*($args->{'question'}-1)+$scantron_config->{'Qstart'};
7653: substr($line,$where-1,$length)=$answer;
1.157 albertel 7654: }
7655: return $line;
7656: }
1.423 albertel 7657:
7658: =pod
7659:
7660: =item scan_data
7661:
7662: Edit or look up an item in the scan_data hash.
7663:
7664: Arguments:
7665: $scan_data - The hash (see scantron_getfile)
7666: $key - shorthand of the key to edit (actual key is
1.424 albertel 7667: scantronfilename_key).
1.423 albertel 7668: $data - New value of the hash entry.
7669: $delete - If true, the entry is removed from the hash.
7670:
7671: Returns:
7672: The new value of the hash table field (undefined if deleted).
7673:
7674: =cut
7675:
7676:
1.157 albertel 7677: sub scan_data {
7678: my ($scan_data,$key,$value,$delete)=@_;
1.257 albertel 7679: my $filename=$env{'form.scantron_selectfile'};
1.157 albertel 7680: if (defined($value)) {
7681: $scan_data->{$filename.'_'.$key} = $value;
7682: }
7683: if ($delete) { delete($scan_data->{$filename.'_'.$key}); }
7684: return $scan_data->{$filename.'_'.$key};
7685: }
1.423 albertel 7686:
1.495 albertel 7687: # ----- These first few routines are general use routines.----
7688:
7689: # Return the number of occurences of a pattern in a string.
7690:
7691: sub occurence_count {
7692: my ($string, $pattern) = @_;
7693:
7694: my @matches = ($string =~ /$pattern/g);
7695:
7696: return scalar(@matches);
7697: }
7698:
7699:
7700: # Take a string known to have digits and convert all the
7701: # digits into letters in the range J,A..I.
7702:
7703: sub digits_to_letters {
7704: my ($input) = @_;
7705:
7706: my @alphabet = ('J', 'A'..'I');
7707:
7708: my @input = split(//, $input);
7709: my $output ='';
7710: for (my $i = 0; $i < scalar(@input); $i++) {
7711: if ($input[$i] =~ /\d/) {
7712: $output .= $alphabet[$input[$i]];
7713: } else {
7714: $output .= $input[$i];
7715: }
7716: }
7717: return $output;
7718: }
7719:
1.423 albertel 7720: =pod
7721:
7722: =item scantron_parse_scanline
7723:
1.711 bisitz 7724: Decodes a scanline from the selected bubblesheet file
1.423 albertel 7725:
7726: Arguments:
1.711 bisitz 7727: line - The text of the bubblesheet file line to process
1.423 albertel 7728: whichline - Line number
1.711 bisitz 7729: scantron_config - Hash describing the format of the bubblesheet lines.
1.423 albertel 7730: scan_data - Hash of extra information about the scanline
7731: (see scantron_getfile for more information)
7732: just_header - True if should not process question answers but only
7733: the stuff to the left of the answers.
1.691 raeburn 7734: randomorder - True if randomorder in use
7735: randompick - True if randompick in use
7736: sequence - Exam folder URL
7737: master_seq - Ref to array containing symbs in exam folder
7738: symb_to_resource - Ref to hash of symbs for resources in exam folder
7739: (corresponding values are resource objects)
7740: partids_by_symb - Ref to hash of symb -> array ref of partIDs
7741: orderedforcode - Ref to hash of arrays. keys are CODEs and values
7742: are refs to an array of resource objects, ordered
7743: according to order used for CODE, when randomorder
7744: and or randompick are in use.
7745: respnumlookup - Ref to hash mapping question numbers in bubble lines
7746: for current line to question number used for same question
7747: in "Master Sequence" (as seen by Course Coordinator).
7748: startline - Ref to hash where key is question number (0 is first)
7749: and value is number of first bubble line for current
7750: student or code-based randompick and/or randomorder.
7751: totalref - Ref of scalar used to score total number of bubble
7752: lines needed for responses in a scan line (used when
7753: randompick in use.
7754:
1.423 albertel 7755: Returns:
7756: Hash containing the result of parsing the scanline
7757:
7758: Keys are all proceeded by the string 'scantron.'
7759:
7760: CODE - the CODE in use for this scanline
7761: useCODE - 1 if the CODE is invalid but it usage has been forced
7762: by the operator
7763: CODE_ignore_dup - 1 if the CODE is a duplicated use when unique
7764: CODEs were selected, but the usage has been
7765: forced by the operator
1.556 weissno 7766: ID - student/employee ID
1.423 albertel 7767: PaperID - if used, the ID number printed on the sheet when the
7768: paper was scanned
7769: FirstName - first name from the sheet
7770: LastName - last name from the sheet
7771:
7772: if just_header was not true these key may also exist
7773:
1.447 foxr 7774: missingerror - a list of bubble ranges that are considered to be answers
7775: to a single question that don't have any bubbles filled in.
7776: Of the form questionnumber:firstbubblenumber:count.
7777: doubleerror - a list of bubble ranges that are considered to be answers
7778: to a single question that have more than one bubble filled in.
7779: Of the form questionnumber::firstbubblenumber:count
7780:
7781: In the above, count is the number of bubble responses in the
7782: input line needed to represent the possible answers to the question.
7783: e.g. a radioresponse with 15 choices in an answer sheet with 10 choices
7784: per line would have count = 2.
7785:
1.423 albertel 7786: maxquest - the number of the last bubble line that was parsed
7787:
7788: (<number> starts at 1)
7789: <number>.answer - zero or more letters representing the selected
7790: letters from the scanline for the bubble line
7791: <number>.
7792: if blank there was either no bubble or there where
7793: multiple bubbles, (consult the keys missingerror and
7794: doubleerror if this is an error condition)
7795:
7796: =cut
7797:
1.82 albertel 7798: sub scantron_parse_scanline {
1.691 raeburn 7799: my ($line,$whichline,$scantron_config,$scan_data,$just_header,$idmap,
7800: $randomorder,$randompick,$sequence,$master_seq,$symb_to_resource,
7801: $partids_by_symb,$orderedforcode,$respnumlookup,$startline,$totalref)=@_;
1.470 foxr 7802:
1.82 albertel 7803: my %record;
1.691 raeburn 7804: my $data=substr($line,0,$$scantron_config{'Qstart'}-1); # stuff before answers
1.278 albertel 7805: if (!($$scantron_config{'CODElocation'} eq 0 ||
7806: $$scantron_config{'CODElocation'} eq 'none')) {
7807: if ($$scantron_config{'CODElocation'} < 0 ||
7808: $$scantron_config{'CODElocation'} eq 'letter' ||
7809: $$scantron_config{'CODElocation'} eq 'number') {
1.191 albertel 7810: $record{'scantron.CODE'}=substr($data,
7811: $$scantron_config{'CODEstart'}-1,
1.83 albertel 7812: $$scantron_config{'CODElength'});
1.191 albertel 7813: if (&scan_data($scan_data,"$whichline.useCODE")) {
7814: $record{'scantron.useCODE'}=1;
7815: }
1.192 albertel 7816: if (&scan_data($scan_data,"$whichline.CODE_ignore_dup")) {
7817: $record{'scantron.CODE_ignore_dup'}=1;
7818: }
1.82 albertel 7819: } else {
7820: #FIXME interpret first N questions
7821: }
7822: }
1.83 albertel 7823: $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
7824: $$scantron_config{'IDlength'});
1.157 albertel 7825: $record{'scantron.PaperID'}=
7826: substr($data,$$scantron_config{'PaperID'}-1,
7827: $$scantron_config{'PaperIDlength'});
7828: $record{'scantron.FirstName'}=
7829: substr($data,$$scantron_config{'FirstName'}-1,
7830: $$scantron_config{'FirstNamelength'});
7831: $record{'scantron.LastName'}=
7832: substr($data,$$scantron_config{'LastName'}-1,
7833: $$scantron_config{'LastNamelength'});
1.423 albertel 7834: if ($just_header) { return \%record; }
1.194 albertel 7835:
1.82 albertel 7836: my @alphabet=('A'..'Z');
7837: my $questnum=0;
1.447 foxr 7838: my $ansnum =1; # Multiple 'answer lines'/question.
7839:
1.691 raeburn 7840: my $lastpos = $env{'form.scantron_maxbubble'}*$$scantron_config{'Qlength'};
7841: if ($randompick || $randomorder) {
7842: my $total = &get_respnum_lookups($sequence,$scan_data,$idmap,$line,\%record,
7843: $master_seq,$symb_to_resource,
7844: $partids_by_symb,$orderedforcode,
7845: $respnumlookup,$startline);
7846: if ($total) {
7847: $lastpos = $total*$$scantron_config{'Qlength'};
7848: }
7849: if (ref($totalref)) {
7850: $$totalref = $total;
7851: }
7852: }
7853: my $questions=substr($line,$$scantron_config{'Qstart'}-1,$lastpos); # Answers
1.470 foxr 7854: chomp($questions); # Get rid of any trailing \n.
7855: $questions =~ s/\r$//; # Get rid of trailing \r too (MAC or Win uploads).
7856: while (length($questions)) {
1.691 raeburn 7857: my $answers_needed;
7858: if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
7859: $answers_needed = $bubble_lines_per_response{$respnumlookup->{$questnum}};
7860: } else {
7861: $answers_needed = $bubble_lines_per_response{$questnum};
7862: }
1.503 raeburn 7863: my $answer_length = ($$scantron_config{'Qlength'} * $answers_needed)
7864: || 1;
7865: $questnum++;
7866: my $quest_id = $questnum;
7867: my $currentquest = substr($questions,0,$answer_length);
7868: $questions = substr($questions,$answer_length);
7869: if (length($currentquest) < $answer_length) { next; }
7870:
1.691 raeburn 7871: my $subdivided;
7872: if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
7873: $subdivided = $subdivided_bubble_lines{$respnumlookup->{$questnum-1}};
7874: } else {
7875: $subdivided = $subdivided_bubble_lines{$questnum-1};
7876: }
7877: if ($subdivided =~ /,/) {
1.503 raeburn 7878: my $subquestnum = 1;
7879: my $subquestions = $currentquest;
1.691 raeburn 7880: my @subanswers_needed = split(/,/,$subdivided);
1.503 raeburn 7881: foreach my $subans (@subanswers_needed) {
7882: my $subans_length =
7883: ($$scantron_config{'Qlength'} * $subans) || 1;
7884: my $currsubquest = substr($subquestions,0,$subans_length);
7885: $subquestions = substr($subquestions,$subans_length);
7886: $quest_id = "$questnum.$subquestnum";
7887: if (($$scantron_config{'Qon'} eq 'letter') ||
7888: ($$scantron_config{'Qon'} eq 'number')) {
7889: $ansnum = &scantron_validator_lettnum($ansnum,
7890: $questnum,$quest_id,$subans,$currsubquest,$whichline,
1.691 raeburn 7891: \@alphabet,\%record,$scantron_config,$scan_data,
7892: $randomorder,$randompick,$respnumlookup);
1.503 raeburn 7893: } else {
7894: $ansnum = &scantron_validator_positional($ansnum,
1.691 raeburn 7895: $questnum,$quest_id,$subans,$currsubquest,$whichline,
7896: \@alphabet,\%record,$scantron_config,$scan_data,
7897: $randomorder,$randompick,$respnumlookup);
1.503 raeburn 7898: }
7899: $subquestnum ++;
7900: }
7901: } else {
7902: if (($$scantron_config{'Qon'} eq 'letter') ||
7903: ($$scantron_config{'Qon'} eq 'number')) {
7904: $ansnum = &scantron_validator_lettnum($ansnum,$questnum,
7905: $quest_id,$answers_needed,$currentquest,$whichline,
1.691 raeburn 7906: \@alphabet,\%record,$scantron_config,$scan_data,
7907: $randomorder,$randompick,$respnumlookup);
1.503 raeburn 7908: } else {
7909: $ansnum = &scantron_validator_positional($ansnum,$questnum,
7910: $quest_id,$answers_needed,$currentquest,$whichline,
1.691 raeburn 7911: \@alphabet,\%record,$scantron_config,$scan_data,
7912: $randomorder,$randompick,$respnumlookup);
1.503 raeburn 7913: }
7914: }
7915: }
7916: $record{'scantron.maxquest'}=$questnum;
7917: return \%record;
7918: }
1.447 foxr 7919:
1.691 raeburn 7920: sub get_master_seq {
1.788 raeburn 7921: my ($resources,$master_seq,$symb_to_resource,$need_symb_in_map,$symb_for_examcode) = @_;
1.691 raeburn 7922: return unless ((ref($resources) eq 'ARRAY') && (ref($master_seq) eq 'ARRAY') &&
7923: (ref($symb_to_resource) eq 'HASH'));
1.788 raeburn 7924: if ($need_symb_in_map) {
7925: return unless (ref($symb_for_examcode) eq 'HASH');
7926: }
1.691 raeburn 7927: my $resource_error;
7928: foreach my $resource (@{$resources}) {
7929: my $ressymb;
7930: if (ref($resource)) {
7931: $ressymb = $resource->symb();
7932: push(@{$master_seq},$ressymb);
7933: $symb_to_resource->{$ressymb} = $resource;
1.788 raeburn 7934: if ($need_symb_in_map) {
7935: unless ($resource->is_map()) {
7936: my $map=(&Apache::lonnet::decode_symb($ressymb))[0];
7937: unless (exists($symb_for_examcode->{$map})) {
7938: $symb_for_examcode->{$map} = $ressymb;
7939: }
7940: }
7941: }
1.691 raeburn 7942: } else {
7943: $resource_error = 1;
7944: last;
7945: }
7946: }
7947: return $resource_error;
7948: }
7949:
7950: sub get_respnum_lookups {
7951: my ($sequence,$scan_data,$idmap,$line,$record,$master_seq,$symb_to_resource,
7952: $partids_by_symb,$orderedforcode,$respnumlookup,$startline) = @_;
7953: return unless ((ref($record) eq 'HASH') && (ref($master_seq) eq 'ARRAY') &&
7954: (ref($symb_to_resource) eq 'HASH') && (ref($partids_by_symb) eq 'HASH') &&
7955: (ref($orderedforcode) eq 'HASH') && (ref($respnumlookup) eq 'HASH') &&
7956: (ref($startline) eq 'HASH'));
7957: my ($user,$scancode);
7958: if ((exists($record->{'scantron.CODE'})) &&
7959: (&Apache::lonnet::validCODE($record->{'scantron.CODE'}))) {
7960: $scancode = $record->{'scantron.CODE'};
7961: } else {
7962: $user = &scantron_find_student($record,$scan_data,$idmap,$line);
7963: }
7964: my @mapresources =
7965: &users_order($user,$scancode,$sequence,$master_seq,$symb_to_resource,
7966: $orderedforcode);
7967: my $total = 0;
7968: my $count = 0;
7969: foreach my $resource (@mapresources) {
7970: my $id = $resource->id();
7971: my $symb = $resource->symb();
7972: if (ref($partids_by_symb->{$symb}) eq 'ARRAY') {
7973: foreach my $partid (@{$partids_by_symb->{$symb}}) {
7974: my $respnum = $masterseq_id_responsenum{$id.'_'.$partid};
7975: if ($respnum ne '') {
7976: $respnumlookup->{$count} = $respnum;
7977: $startline->{$count} = $total;
7978: $total += $bubble_lines_per_response{$respnum};
7979: $count ++;
7980: }
7981: }
7982: }
7983: }
7984: return $total;
7985: }
7986:
1.503 raeburn 7987: sub scantron_validator_lettnum {
7988: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,$whichline,
1.691 raeburn 7989: $alphabet,$record,$scantron_config,$scan_data,$randomorder,
7990: $randompick,$respnumlookup) = @_;
1.503 raeburn 7991:
7992: # Qon 'letter' implies for each slot in currquest we have:
7993: # ? or * for doubles, a letter in A-Z for a bubble, and
7994: # about anything else (esp. a value of Qoff) for missing
7995: # bubbles.
7996: #
7997: # Qon 'number' implies each slot gives a digit that indexes the
7998: # bubbles filled, or Qoff, or a non-number for unbubbled lines,
7999: # and * or ? for double bubbles on a single line.
8000: #
1.447 foxr 8001:
1.503 raeburn 8002: my $matchon;
8003: if ($$scantron_config{'Qon'} eq 'letter') {
8004: $matchon = '[A-Z]';
8005: } elsif ($$scantron_config{'Qon'} eq 'number') {
8006: $matchon = '\d';
8007: }
8008: my $occurrences = 0;
1.691 raeburn 8009: my $responsenum = $questnum-1;
8010: if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
8011: $responsenum = $respnumlookup->{$questnum-1}
8012: }
8013: if (($responsetype_per_response{$responsenum} eq 'essayresponse') ||
8014: ($responsetype_per_response{$responsenum} eq 'formularesponse') ||
8015: ($responsetype_per_response{$responsenum} eq 'stringresponse') ||
8016: ($responsetype_per_response{$responsenum} eq 'imageresponse') ||
8017: ($responsetype_per_response{$responsenum} eq 'reactionresponse') ||
8018: ($responsetype_per_response{$responsenum} eq 'organicresponse')) {
1.503 raeburn 8019: my @singlelines = split('',$currquest);
8020: foreach my $entry (@singlelines) {
8021: $occurrences = &occurence_count($entry,$matchon);
8022: if ($occurrences > 1) {
8023: last;
8024: }
1.691 raeburn 8025: }
1.503 raeburn 8026: } else {
8027: $occurrences = &occurence_count($currquest,$matchon);
8028: }
8029: if (($currquest =~ /\?/ || $currquest =~ /\*/) || ($occurrences > 1)) {
8030: push(@{$record->{'scantron.doubleerror'}},$quest_id);
8031: for (my $ans=0; $ans<$answers_needed; $ans++) {
8032: my $bubble = substr($currquest,$ans,1);
8033: if ($bubble =~ /$matchon/ ) {
8034: if ($$scantron_config{'Qon'} eq 'number') {
8035: if ($bubble == 0) {
8036: $bubble = 10;
8037: }
8038: $record->{"scantron.$ansnum.answer"} =
8039: $alphabet->[$bubble-1];
8040: } else {
8041: $record->{"scantron.$ansnum.answer"} = $bubble;
8042: }
8043: } else {
8044: $record->{"scantron.$ansnum.answer"}='';
8045: }
8046: $ansnum++;
8047: }
8048: } elsif (!defined($currquest)
8049: || (&occurence_count($currquest, $$scantron_config{'Qoff'}) == length($currquest))
8050: || (&occurence_count($currquest,$matchon) == 0)) {
8051: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
8052: $record->{"scantron.$ansnum.answer"}='';
8053: $ansnum++;
8054: }
8055: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
8056: push(@{$record->{'scantron.missingerror'}},$quest_id);
8057: }
8058: } else {
8059: if ($$scantron_config{'Qon'} eq 'number') {
8060: $currquest = &digits_to_letters($currquest);
8061: }
8062: for (my $ans=0; $ans<$answers_needed; $ans++) {
8063: my $bubble = substr($currquest,$ans,1);
8064: $record->{"scantron.$ansnum.answer"} = $bubble;
8065: $ansnum++;
8066: }
8067: }
8068: return $ansnum;
8069: }
1.447 foxr 8070:
1.503 raeburn 8071: sub scantron_validator_positional {
8072: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,
1.691 raeburn 8073: $whichline,$alphabet,$record,$scantron_config,$scan_data,
8074: $randomorder,$randompick,$respnumlookup) = @_;
1.447 foxr 8075:
1.503 raeburn 8076: # Otherwise there's a positional notation;
8077: # each bubble line requires Qlength items, and there are filled in
8078: # bubbles for each case where there 'Qon' characters.
8079: #
1.447 foxr 8080:
1.503 raeburn 8081: my @array=split($$scantron_config{'Qon'},$currquest,-1);
1.447 foxr 8082:
1.503 raeburn 8083: # If the split only gives us one element.. the full length of the
8084: # answer string, no bubbles are filled in:
1.447 foxr 8085:
1.507 raeburn 8086: if ($answers_needed eq '') {
8087: return;
8088: }
8089:
1.503 raeburn 8090: if (length($array[0]) eq $$scantron_config{'Qlength'}*$answers_needed) {
8091: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
8092: $record->{"scantron.$ansnum.answer"}='';
8093: $ansnum++;
8094: }
8095: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
8096: push(@{$record->{"scantron.missingerror"}},$quest_id);
8097: }
8098: } elsif (scalar(@array) == 2) {
8099: my $location = length($array[0]);
8100: my $line_num = int($location / $$scantron_config{'Qlength'});
8101: my $bubble = $alphabet->[$location % $$scantron_config{'Qlength'}];
8102: for (my $ans=0; $ans<$answers_needed; $ans++) {
8103: if ($ans eq $line_num) {
8104: $record->{"scantron.$ansnum.answer"} = $bubble;
8105: } else {
8106: $record->{"scantron.$ansnum.answer"} = ' ';
8107: }
8108: $ansnum++;
8109: }
8110: } else {
8111: # If there's more than one instance of a bubble character
8112: # That's a double bubble; with positional notation we can
8113: # record all the bubbles filled in as well as the
8114: # fact this response consists of multiple bubbles.
8115: #
1.691 raeburn 8116: my $responsenum = $questnum-1;
8117: if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
8118: $responsenum = $respnumlookup->{$questnum-1}
8119: }
8120: if (($responsetype_per_response{$responsenum} eq 'essayresponse') ||
8121: ($responsetype_per_response{$responsenum} eq 'formularesponse') ||
8122: ($responsetype_per_response{$responsenum} eq 'stringresponse') ||
8123: ($responsetype_per_response{$responsenum} eq 'imageresponse') ||
8124: ($responsetype_per_response{$responsenum} eq 'reactionresponse') ||
8125: ($responsetype_per_response{$responsenum} eq 'organicresponse')) {
1.503 raeburn 8126: my $doubleerror = 0;
8127: while (($currquest >= $$scantron_config{'Qlength'}) &&
8128: (!$doubleerror)) {
8129: my $currline = substr($currquest,0,$$scantron_config{'Qlength'});
8130: $currquest = substr($currquest,$$scantron_config{'Qlength'});
8131: my @currarray = split($$scantron_config{'Qon'},$currline,-1);
8132: if (length(@currarray) > 2) {
8133: $doubleerror = 1;
8134: }
8135: }
8136: if ($doubleerror) {
8137: push(@{$record->{'scantron.doubleerror'}},$quest_id);
8138: }
8139: } else {
8140: push(@{$record->{'scantron.doubleerror'}},$quest_id);
8141: }
8142: my $item = $ansnum;
8143: for (my $ans=0; $ans<$answers_needed; $ans++) {
8144: $record->{"scantron.$item.answer"} = '';
8145: $item ++;
8146: }
1.447 foxr 8147:
1.503 raeburn 8148: my @ans=@array;
8149: my $i=0;
8150: my $increment = 0;
8151: while ($#ans) {
8152: $i+=length($ans[0]) + $increment;
8153: my $line = int($i/$$scantron_config{'Qlength'} + $ansnum);
8154: my $bubble = $i%$$scantron_config{'Qlength'};
8155: $record->{"scantron.$line.answer"}.=$alphabet->[$bubble];
8156: shift(@ans);
8157: $increment = 1;
8158: }
8159: $ansnum += $answers_needed;
1.82 albertel 8160: }
1.503 raeburn 8161: return $ansnum;
1.82 albertel 8162: }
8163:
1.423 albertel 8164: =pod
8165:
8166: =item scantron_add_delay
8167:
8168: Adds an error message that occurred during the grading phase to a
8169: queue of messages to be shown after grading pass is complete
8170:
8171: Arguments:
1.424 albertel 8172: $delayqueue - arrary ref of hash ref of error messages
1.423 albertel 8173: $scanline - the scanline that caused the error
8174: $errormesage - the error message
8175: $errorcode - a numeric code for the error
8176:
8177: Side Effects:
1.424 albertel 8178: updates the $delayqueue to have a new hash ref of the error
1.423 albertel 8179:
8180: =cut
8181:
1.82 albertel 8182: sub scantron_add_delay {
1.140 albertel 8183: my ($delayqueue,$scanline,$errormessage,$errorcode)=@_;
8184: push(@$delayqueue,
8185: {'line' => $scanline, 'emsg' => $errormessage,
8186: 'ecode' => $errorcode }
8187: );
1.82 albertel 8188: }
8189:
1.423 albertel 8190: =pod
8191:
8192: =item scantron_find_student
8193:
1.424 albertel 8194: Finds the username for the current scanline
8195:
8196: Arguments:
8197: $scantron_record - hash result from scantron_parse_scanline
8198: $scan_data - hash of correction information
8199: (see &scantron_getfile() form more information)
8200: $idmap - hash from &username_to_idmap()
8201: $line - number of current scanline
8202:
8203: Returns:
8204: Either 'username:domain' or undef if unknown
8205:
1.423 albertel 8206: =cut
8207:
1.82 albertel 8208: sub scantron_find_student {
1.157 albertel 8209: my ($scantron_record,$scan_data,$idmap,$line)=@_;
1.83 albertel 8210: my $scanID=$$scantron_record{'scantron.ID'};
1.157 albertel 8211: if ($scanID =~ /^\s*$/) {
8212: return &scan_data($scan_data,"$line.user");
8213: }
1.83 albertel 8214: foreach my $id (keys(%$idmap)) {
1.157 albertel 8215: if (lc($id) eq lc($scanID)) {
8216: return $$idmap{$id};
8217: }
1.83 albertel 8218: }
8219: return undef;
8220: }
8221:
1.423 albertel 8222: =pod
8223:
8224: =item scantron_filter
8225:
1.424 albertel 8226: Filter sub for lonnavmaps, filters out hidden resources if ignore
8227: hidden resources was selected
8228:
1.423 albertel 8229: =cut
8230:
1.83 albertel 8231: sub scantron_filter {
8232: my ($curres)=@_;
1.331 albertel 8233:
8234: if (ref($curres) && $curres->is_problem()) {
8235: # if the user has asked to not have either hidden
8236: # or 'randomout' controlled resources to be graded
8237: # don't include them
8238: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
8239: && $curres->randomout) {
8240: return 0;
8241: }
1.83 albertel 8242: return 1;
8243: }
8244: return 0;
1.82 albertel 8245: }
8246:
1.423 albertel 8247: =pod
8248:
8249: =item scantron_process_corrections
8250:
1.424 albertel 8251: Gets correction information out of submitted form data and corrects
8252: the scanline
8253:
1.423 albertel 8254: =cut
8255:
1.157 albertel 8256: sub scantron_process_corrections {
8257: my ($r) = @_;
1.754 raeburn 8258: my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.157 albertel 8259: my ($scanlines,$scan_data)=&scantron_getfile();
8260: my $classlist=&Apache::loncoursedata::get_classlist();
1.257 albertel 8261: my $which=$env{'form.scantron_line'};
1.200 albertel 8262: my $line=&scantron_get_line($scanlines,$scan_data,$which);
1.157 albertel 8263: my ($skip,$err,$errmsg);
1.257 albertel 8264: if ($env{'form.scantron_skip_record'}) {
1.157 albertel 8265: $skip=1;
1.257 albertel 8266: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)ID$/) {
8267: my $newstudent=$env{'form.scantron_username'}.':'.
8268: $env{'form.scantron_domain'};
1.157 albertel 8269: my $newid=$classlist->{$newstudent}->[&Apache::loncoursedata::CL_ID];
8270: ($line,$err,$errmsg)=
8271: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
8272: 'ID',{'newid'=>$newid,
1.257 albertel 8273: 'username'=>$env{'form.scantron_username'},
8274: 'domain'=>$env{'form.scantron_domain'}});
8275: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)CODE$/) {
8276: my $resolution=$env{'form.scantron_CODE_resolution'};
1.190 albertel 8277: my $newCODE;
1.192 albertel 8278: my %args;
1.190 albertel 8279: if ($resolution eq 'use_unfound') {
1.191 albertel 8280: $newCODE='use_unfound';
1.190 albertel 8281: } elsif ($resolution eq 'use_found') {
1.257 albertel 8282: $newCODE=$env{'form.scantron_CODE_selectedvalue'};
1.190 albertel 8283: } elsif ($resolution eq 'use_typed') {
1.257 albertel 8284: $newCODE=$env{'form.scantron_CODE_newvalue'};
1.194 albertel 8285: } elsif ($resolution =~ /^use_closest_(\d+)/) {
1.257 albertel 8286: $newCODE=$env{"form.scantron_CODE_closest_$1"};
1.190 albertel 8287: }
1.257 albertel 8288: if ($env{'form.scantron_corrections'} eq 'duplicateCODE') {
1.192 albertel 8289: $args{'CODE_ignore_dup'}=1;
8290: }
8291: $args{'CODE'}=$newCODE;
1.186 albertel 8292: ($line,$err,$errmsg)=
8293: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
1.192 albertel 8294: 'CODE',\%args);
1.257 albertel 8295: } elsif ($env{'form.scantron_corrections'} =~ /^(missing|double)bubble$/) {
8296: foreach my $question (split(',',$env{'form.scantron_questions'})) {
1.157 albertel 8297: ($line,$err,$errmsg)=
8298: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,
8299: $which,'answer',
8300: { 'question'=>$question,
1.503 raeburn 8301: 'response'=>$env{"form.scantron_correct_Q_$question"},
8302: 'questionnum'=>$env{"form.scantron_questionnum_Q_$question"}});
1.157 albertel 8303: if ($err) { last; }
8304: }
8305: }
8306: if ($err) {
1.703 bisitz 8307: $r->print(
8308: '<p class="LC_error">'
8309: .&mt('Unable to accept last correction, an error occurred: [_1]',
8310: $errmsg)
1.704 raeburn 8311: .'</p>');
1.157 albertel 8312: } else {
1.200 albertel 8313: &scantron_put_line($scanlines,$scan_data,$which,$line,$skip);
1.157 albertel 8314: &scantron_putfile($scanlines,$scan_data);
8315: }
8316: }
8317:
1.423 albertel 8318: =pod
8319:
8320: =item reset_skipping_status
8321:
1.424 albertel 8322: Forgets the current set of remember skipped scanlines (and thus
8323: reverts back to considering all lines in the
8324: scantron_skipped_<filename> file)
8325:
1.423 albertel 8326: =cut
8327:
1.200 albertel 8328: sub reset_skipping_status {
8329: my ($scanlines,$scan_data)=&scantron_getfile();
8330: &scan_data($scan_data,'remember_skipping',undef,1);
8331: &scantron_putfile(undef,$scan_data);
8332: }
8333:
1.423 albertel 8334: =pod
8335:
8336: =item start_skipping
8337:
1.424 albertel 8338: Marks a scanline to be skipped.
8339:
1.423 albertel 8340: =cut
8341:
1.376 albertel 8342: sub start_skipping {
1.200 albertel 8343: my ($scan_data,$i)=@_;
8344: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 8345: if ($env{'form.scantron_options_redo'} =~ /^redo_/) {
8346: $remembered{$i}=2;
8347: } else {
8348: $remembered{$i}=1;
8349: }
1.200 albertel 8350: &scan_data($scan_data,'remember_skipping',join(':',%remembered));
8351: }
8352:
1.423 albertel 8353: =pod
8354:
8355: =item should_be_skipped
8356:
1.424 albertel 8357: Checks whether a scanline should be skipped.
8358:
1.423 albertel 8359: =cut
8360:
1.200 albertel 8361: sub should_be_skipped {
1.376 albertel 8362: my ($scanlines,$scan_data,$i)=@_;
1.257 albertel 8363: if ($env{'form.scantron_options_redo'} !~ /^redo_/) {
1.200 albertel 8364: # not redoing old skips
1.376 albertel 8365: if ($scanlines->{'skipped'}[$i]) { return 1; }
1.200 albertel 8366: return 0;
8367: }
8368: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 8369:
8370: if (exists($remembered{$i}) && $remembered{$i} != 2 ) {
8371: return 0;
8372: }
1.200 albertel 8373: return 1;
8374: }
8375:
1.423 albertel 8376: =pod
8377:
8378: =item remember_current_skipped
8379:
1.424 albertel 8380: Discovers what scanlines are in the scantron_skipped_<filename>
8381: file and remembers them into scan_data for later use.
8382:
1.423 albertel 8383: =cut
8384:
1.200 albertel 8385: sub remember_current_skipped {
8386: my ($scanlines,$scan_data)=&scantron_getfile();
8387: my %to_remember;
8388: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
8389: if ($scanlines->{'skipped'}[$i]) {
8390: $to_remember{$i}=1;
8391: }
8392: }
1.376 albertel 8393:
1.200 albertel 8394: &scan_data($scan_data,'remember_skipping',join(':',%to_remember));
8395: &scantron_putfile(undef,$scan_data);
8396: }
8397:
1.423 albertel 8398: =pod
8399:
8400: =item check_for_error
8401:
1.424 albertel 8402: Checks if there was an error when attempting to remove a specific
1.659 raeburn 8403: scantron_.. bubblesheet data file. Prints out an error if
1.424 albertel 8404: something went wrong.
8405:
1.423 albertel 8406: =cut
8407:
1.200 albertel 8408: sub check_for_error {
8409: my ($r,$result)=@_;
8410: if ($result ne 'ok' && $result ne 'not_found' ) {
1.492 albertel 8411: $r->print(&mt("An error occurred ([_1]) when trying to remove the existing corrections.",$result));
1.200 albertel 8412: }
8413: }
1.157 albertel 8414:
1.423 albertel 8415: =pod
8416:
8417: =item scantron_warning_screen
8418:
1.424 albertel 8419: Interstitial screen to make sure the operator has selected the
8420: correct options before we start the validation phase.
8421:
1.423 albertel 8422: =cut
8423:
1.203 albertel 8424: sub scantron_warning_screen {
1.650 raeburn 8425: my ($button_text,$symb)=@_;
1.257 albertel 8426: my $title=&Apache::lonnet::gettitle($env{'form.selectpage'});
1.754 raeburn 8427: my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.373 albertel 8428: my $CODElist;
1.284 albertel 8429: if ($scantron_config{'CODElocation'} &&
8430: $scantron_config{'CODEstart'} &&
8431: $scantron_config{'CODElength'}) {
8432: $CODElist=$env{'form.scantron_CODElist'};
1.721 bisitz 8433: if ($env{'form.scantron_CODElist'} eq '') { $CODElist='<span class="LC_warning">'.&mt('None').'</span>'; }
1.284 albertel 8434: $CODElist=
1.492 albertel 8435: '<tr><td><b>'.&mt('List of CODES to validate against:').'</b></td><td><tt>'.
1.373 albertel 8436: $env{'form.scantron_CODElist'}.'</tt></td></tr>';
1.284 albertel 8437: }
1.663 raeburn 8438: my $lastbubblepoints;
8439: if ($env{'form.scantron_lastbubblepoints'} ne '') {
8440: $lastbubblepoints =
8441: '<tr><td><b>'.&mt('Hand-graded items: points from last bubble in row').'</b></td><td><tt>'.
8442: $env{'form.scantron_lastbubblepoints'}.'</tt></td></tr>';
8443: }
1.770 raeburn 8444: return '
1.203 albertel 8445: <p>
1.492 albertel 8446: <span class="LC_warning">
1.705 raeburn 8447: '.&mt("Please double check the information below before clicking on '[_1]'",&mt($button_text)).'</span>
1.203 albertel 8448: </p>
8449: <table>
1.492 albertel 8450: <tr><td><b>'.&mt('Sequence to be Graded:').'</b></td><td>'.$title.'</td></tr>
8451: <tr><td><b>'.&mt('Data File that will be used:').'</b></td><td><tt>'.$env{'form.scantron_selectfile'}.'</tt></td></tr>
1.663 raeburn 8452: '.$CODElist.$lastbubblepoints.'
1.203 albertel 8453: </table>
1.680 raeburn 8454: <p> '.&mt("If this information is correct, please click on '[_1]'.",&mt($button_text)).'<br />
1.650 raeburn 8455: '.&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 8456: ';
1.203 albertel 8457: }
8458:
1.423 albertel 8459: =pod
8460:
8461: =item scantron_do_warning
8462:
1.424 albertel 8463: Check if the operator has picked something for all required
8464: fields. Error out if something is missing.
8465:
1.423 albertel 8466: =cut
8467:
1.203 albertel 8468: sub scantron_do_warning {
1.608 www 8469: my ($r,$symb)=@_;
1.203 albertel 8470: if (!$symb) {return '';}
1.324 albertel 8471: my $default_form_data=&defaultFormData($symb);
1.203 albertel 8472: $r->print(&scantron_form_start().$default_form_data);
1.257 albertel 8473: if ( $env{'form.selectpage'} eq '' ||
8474: $env{'form.scantron_selectfile'} eq '' ||
8475: $env{'form.scantron_format'} eq '' ) {
1.642 raeburn 8476: $r->print("<p>".&mt('You have forgotten to specify some information. Please go Back and try again.')."</p>");
1.257 albertel 8477: if ( $env{'form.selectpage'} eq '') {
1.492 albertel 8478: $r->print('<p><span class="LC_error">'.&mt('You have not selected a Sequence to grade').'</span></p>');
1.237 albertel 8479: }
1.257 albertel 8480: if ( $env{'form.scantron_selectfile'} eq '') {
1.642 raeburn 8481: $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 8482: }
1.257 albertel 8483: if ( $env{'form.scantron_format'} eq '') {
1.642 raeburn 8484: $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 8485: }
1.237 albertel 8486: } else {
1.650 raeburn 8487: my $warning=&scantron_warning_screen('Grading: Validate Records',$symb);
1.770 raeburn 8488: my ($checksec,@possibles) = &gradable_sections();
8489: my $gradesections;
8490: if ($checksec) {
8491: my $file=$env{'form.scantron_selectfile'};
8492: if (&valid_file($file)) {
8493: my %bysec = &scantron_get_sections();
8494: my $table;
8495: if ((keys(%bysec) > 1) || ((keys(%bysec) == 1) && ((keys(%bysec))[0] ne $checksec))) {
8496: $gradesections = &mt('Your current role is for section [_1].','<i>'.$checksec.'</i>').'<br />';
8497: $table = &Apache::loncommon::start_data_table()."\n".
8498: &Apache::loncommon::start_data_table_header_row().
8499: '<th>'.&mt('Section').'</th><th>'.&mt('Number of records').'</th>'.
8500: &Apache::loncommon::end_data_table_header_row()."\n";
8501: if ($bysec{'none'}) {
8502: $table .= &Apache::loncommon::start_data_table_row().
8503: '<td>'.&mt('None').'</td><td>'.$bysec{'none'}.'</td>'.
8504: &Apache::loncommon::end_data_table_row()."\n";
8505: }
8506: foreach my $sec (sort { $a <=> $b } keys(%bysec)) {
8507: next if ($sec eq 'none');
8508: $table .= &Apache::loncommon::start_data_table_row().
8509: '<td>'.$sec.'</td><td>'.$bysec{$sec}.'</td>'.
8510: &Apache::loncommon::end_data_table_row()."\n";
8511: }
8512: $table .= &Apache::loncommon::end_data_table()."\n";
8513: $gradesections .= &mt('Sections represented in the bubblesheet data file (based on bubbled student IDs) are as follows:').
8514: '<p>'.$table.'</p>';
8515: if (@possibles) {
8516: $gradesections .= '<p>'.
8517: &mt('You have role(s) in [quant,_1,other section,other sections] with privileges to manage grades.',
8518: scalar(@possibles)).'<br />'.
8519: &mt('Check which of those section(s), in addition to section [_1], you wish to grade using this bubblesheet file:',
8520: '<i>'.$checksec.'</i>').' ';
8521: foreach my $sec (sort {$a <=> $b } @possibles) {
8522: $gradesections .= '<label><input type="checkbox" name="scantron_othersections" value="'.$sec.'" />'.$sec.'</label>'.(' 'x2);
8523: }
8524: $gradesections .= '</p>';
8525: }
8526: }
8527: } else {
8528: $gradesections = '<p class="LC_error">'.&mt('The selected file is unavailable').'</p>';
8529: }
8530: }
1.663 raeburn 8531: my $bubbledbyhand=&hand_bubble_option();
1.492 albertel 8532: $r->print('
1.770 raeburn 8533: '.$warning.$gradesections.$bubbledbyhand.'
1.492 albertel 8534: <input type="submit" name="submit" value="'.&mt('Grading: Validate Records').'" />
1.203 albertel 8535: <input type="hidden" name="command" value="scantron_validate" />
1.492 albertel 8536: ');
1.237 albertel 8537: }
1.614 www 8538: $r->print("</form><br />");
1.203 albertel 8539: return '';
8540: }
8541:
1.423 albertel 8542: =pod
8543:
8544: =item scantron_form_start
8545:
1.424 albertel 8546: html hidden input for remembering all selected grading options
8547:
1.423 albertel 8548: =cut
8549:
1.203 albertel 8550: sub scantron_form_start {
8551: my ($max_bubble)=@_;
8552: my $result= <<SCANTRONFORM;
8553: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
1.257 albertel 8554: <input type="hidden" name="selectpage" value="$env{'form.selectpage'}" />
8555: <input type="hidden" name="scantron_format" value="$env{'form.scantron_format'}" />
8556: <input type="hidden" name="scantron_selectfile" value="$env{'form.scantron_selectfile'}" />
1.218 albertel 8557: <input type="hidden" name="scantron_maxbubble" value="$max_bubble" />
1.257 albertel 8558: <input type="hidden" name="scantron_CODElist" value="$env{'form.scantron_CODElist'}" />
8559: <input type="hidden" name="scantron_CODEunique" value="$env{'form.scantron_CODEunique'}" />
8560: <input type="hidden" name="scantron_options_redo" value="$env{'form.scantron_options_redo'}" />
8561: <input type="hidden" name="scantron_options_ignore" value="$env{'form.scantron_options_ignore'}" />
1.331 albertel 8562: <input type="hidden" name="scantron_options_hidden" value="$env{'form.scantron_options_hidden'}" />
1.203 albertel 8563: SCANTRONFORM
1.447 foxr 8564:
8565: my $line = 0;
8566: while (defined($env{"form.scantron.bubblelines.$line"})) {
8567: my $chunk =
8568: '<input type="hidden" name="scantron.bubblelines.'.$line.'" value="'.$env{"form.scantron.bubblelines.$line"}.'" />'."\n";
1.448 foxr 8569: $chunk .=
8570: '<input type="hidden" name="scantron.first_bubble_line.'.$line.'" value="'.$env{"form.scantron.first_bubble_line.$line"}.'" />'."\n";
1.503 raeburn 8571: $chunk .=
8572: '<input type="hidden" name="scantron.sub_bubblelines.'.$line.'" value="'.$env{"form.scantron.sub_bubblelines.$line"}.'" />'."\n";
1.504 raeburn 8573: $chunk .=
8574: '<input type="hidden" name="scantron.responsetype.'.$line.'" value="'.$env{"form.scantron.responsetype.$line"}.'" />'."\n";
1.691 raeburn 8575: $chunk .=
8576: '<input type="hidden" name="scantron.residpart.'.$line.'" value="'.$env{"form.scantron.residpart.$line"}.'" />'."\n";
1.447 foxr 8577: $result .= $chunk;
8578: $line++;
1.691 raeburn 8579: }
1.203 albertel 8580: return $result;
8581: }
8582:
1.423 albertel 8583: =pod
8584:
8585: =item scantron_validate_file
8586:
1.659 raeburn 8587: Dispatch routine for doing validation of a bubblesheet data file.
1.424 albertel 8588:
8589: Also processes any necessary information resets that need to
8590: occur before validation begins (ignore previous corrections,
8591: restarting the skipped records processing)
8592:
1.423 albertel 8593: =cut
8594:
1.157 albertel 8595: sub scantron_validate_file {
1.608 www 8596: my ($r,$symb) = @_;
1.157 albertel 8597: if (!$symb) {return '';}
1.324 albertel 8598: my $default_form_data=&defaultFormData($symb);
1.200 albertel 8599:
1.703 bisitz 8600: # do the detection of only doing skipped records first before we delete
1.424 albertel 8601: # them when doing the corrections reset
1.257 albertel 8602: if ($env{'form.scantron_options_redo'} ne 'redo_skipped_ready') {
1.200 albertel 8603: &reset_skipping_status();
8604: }
1.257 albertel 8605: if ($env{'form.scantron_options_redo'} eq 'redo_skipped') {
1.200 albertel 8606: &remember_current_skipped();
1.257 albertel 8607: $env{'form.scantron_options_redo'}='redo_skipped_ready';
1.200 albertel 8608: }
8609:
1.257 albertel 8610: if ($env{'form.scantron_options_ignore'} eq 'ignore_corrections') {
1.200 albertel 8611: &check_for_error($r,&scantron_remove_file('corrected'));
8612: &check_for_error($r,&scantron_remove_file('skipped'));
8613: &check_for_error($r,&scantron_remove_scan_data());
1.257 albertel 8614: $env{'form.scantron_options_ignore'}='done';
1.192 albertel 8615: }
1.200 albertel 8616:
1.257 albertel 8617: if ($env{'form.scantron_corrections'}) {
1.157 albertel 8618: &scantron_process_corrections($r);
8619: }
1.770 raeburn 8620:
8621: $r->print('<p>'.&mt('Gathering necessary information.').'</p>');
8622: my ($checksec,@gradable);
8623: if ($env{'request.course.sec'}) {
8624: ($checksec,my @possibles) = &gradable_sections();
8625: if ($checksec) {
8626: if (@possibles) {
8627: my @chosensecs = &Apache::loncommon::get_env_multiple('form.scantron_othersections');
8628: if (@chosensecs) {
8629: foreach my $sec (@chosensecs) {
8630: if (grep(/^\Q$sec\E$/,@possibles)) {
8631: unless (grep(/^\Q$sec\E$/,@gradable)) {
8632: push(@gradable,$sec);
8633: }
8634: }
8635: }
8636: }
8637: }
8638: $r->print('<p><table>');
8639: if (@gradable) {
8640: my @showsections = sort { $a <=> $b } (@gradable,$checksec);
8641: $r->print(
8642: '<tr><td><b>'.&mt('Sections to be Graded:').'</b></td><td>'.join(', ',@showsections).'</td></tr>');
8643: } else {
8644: $r->print(
8645: '<tr><td><b>'.&mt('Section to be Graded:').'</b></td><td>'.$checksec.'</td></tr>');
8646: }
8647: $r->print('</table></p>');
8648: }
8649: }
8650: $r->rflush();
8651:
1.157 albertel 8652: #get the student pick code ready
8653: $r->print(&Apache::loncommon::studentbrowser_javascript());
1.582 raeburn 8654: my $nav_error;
1.754 raeburn 8655: my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.649 raeburn 8656: my $max_bubble=&scantron_get_maxbubble(\$nav_error,\%scantron_config);
1.582 raeburn 8657: if ($nav_error) {
8658: $r->print(&navmap_errormsg());
8659: return '';
8660: }
1.203 albertel 8661: my $result=&scantron_form_start($max_bubble).$default_form_data;
1.663 raeburn 8662: if ($env{'form.scantron_lastbubblepoints'} ne '') {
8663: $result .= '<input type="hidden" name="scantron_lastbubblepoints" value="'.$env{'form.scantron_lastbubblepoints'}.'" />';
8664: }
1.157 albertel 8665: $r->print($result);
8666:
1.334 albertel 8667: my @validate_phases=( 'sequence',
8668: 'ID',
1.157 albertel 8669: 'CODE',
8670: 'doublebubble',
8671: 'missingbubbles');
1.257 albertel 8672: if (!$env{'form.validatepass'}) {
8673: $env{'form.validatepass'} = 0;
1.157 albertel 8674: }
1.257 albertel 8675: my $currentphase=$env{'form.validatepass'};
1.770 raeburn 8676: my %skipbysec=();
1.448 foxr 8677:
1.157 albertel 8678: my $stop=0;
8679: while (!$stop && $currentphase < scalar(@validate_phases)) {
1.503 raeburn 8680: $r->print(&mt('Validating '.$validate_phases[$currentphase]).'<br />');
1.157 albertel 8681: $r->rflush();
1.691 raeburn 8682:
1.157 albertel 8683: my $which="scantron_validate_".$validate_phases[$currentphase];
8684: {
8685: no strict 'refs';
1.770 raeburn 8686: my @extras=();
8687: if ($validate_phases[$currentphase] eq 'ID') {
8688: @extras = (\%skipbysec,$checksec,@gradable);
8689: }
8690: ($stop,$currentphase)=&$which($r,$currentphase,@extras);
1.157 albertel 8691: }
8692: }
8693: if (!$stop) {
1.650 raeburn 8694: my $warning=&scantron_warning_screen('Start Grading',$symb);
1.770 raeburn 8695: my $secinfo;
8696: if (keys(%skipbysec) > 0) {
8697: my $seclist = '<ul>';
8698: foreach my $sec (sort { $a <=> $b } keys(%skipbysec)) {
8699: $seclist .= '<li>'.&mt('section [_1]: [_2]',$sec,$skipbysec{$sec}).'</li>';
8700: }
8701: $seclist .= '</ul>';
8702: $secinfo = '<p class="LC_info">'.
8703: &mt('Numbers of records for students in sections not being graded [_1]',
8704: $seclist).
8705: '</p>';
8706: }
1.542 raeburn 8707: $r->print(&mt('Validation process complete.').'<br />'.
1.770 raeburn 8708: $secinfo.$warning.
1.542 raeburn 8709: &mt('Perform verification for each student after storage of submissions?').
8710: ' <span class="LC_nobreak"><label>'.
8711: '<input type="radio" name="verifyrecord" value="1" />'.&mt('Yes').'</label>'.
8712: (' 'x3).'<label>'.
8713: '<input type="radio" name="verifyrecord" value="0" checked="checked" />'.&mt('No').
8714: '</label></span><br />'.
8715: &mt('Grading will take longer if you use verification.').'<br />'.
1.650 raeburn 8716: &mt('Otherwise, Grade/Manage/Review Bubblesheets [_1] Review bubblesheet data can be used once grading is complete.','»').'<br /><br />'.
1.542 raeburn 8717: '<input type="submit" name="submit" value="'.&mt('Start Grading').'" />'.
8718: '<input type="hidden" name="command" value="scantron_process" />'."\n");
1.157 albertel 8719: } else {
8720: $r->print('<input type="hidden" name="command" value="scantron_validate" />');
8721: $r->print("<input type='hidden' name='validatepass' value='".$currentphase."' />");
8722: }
8723: if ($stop) {
1.334 albertel 8724: if ($validate_phases[$currentphase] eq 'sequence') {
1.539 riegler 8725: $r->print('<input type="submit" name="submit" value="'.&mt('Ignore').' → " />');
1.492 albertel 8726: $r->print(' '.&mt('this error').' <br />');
1.334 albertel 8727:
1.650 raeburn 8728: $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 8729: } else {
1.503 raeburn 8730: if ($validate_phases[$currentphase] eq 'doublebubble' || $validate_phases[$currentphase] eq 'missingbubbles') {
1.539 riegler 8731: $r->print('<input type="button" name="submitbutton" value="'.&mt('Continue').' →" onclick="javascript:verify_bubble_radio(this.form)" />');
1.503 raeburn 8732: } else {
1.539 riegler 8733: $r->print('<input type="submit" name="submit" value="'.&mt('Continue').' →" />');
1.503 raeburn 8734: }
1.492 albertel 8735: $r->print(' '.&mt('using corrected info').' <br />');
8736: $r->print("<input type='submit' value='".&mt("Skip")."' name='scantron_skip_record' />");
8737: $r->print(" ".&mt("this scanline saving it for later."));
1.334 albertel 8738: }
1.157 albertel 8739: }
1.614 www 8740: $r->print(" </form><br />");
1.157 albertel 8741: return '';
8742: }
8743:
1.423 albertel 8744:
8745: =pod
8746:
8747: =item scantron_remove_file
8748:
1.659 raeburn 8749: Removes the requested bubblesheet data file, makes sure that
1.424 albertel 8750: scantron_original_<filename> is never removed
8751:
8752:
1.423 albertel 8753: =cut
8754:
1.200 albertel 8755: sub scantron_remove_file {
1.192 albertel 8756: my ($which)=@_;
1.257 albertel 8757: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
8758: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 8759: my $file='scantron_';
1.200 albertel 8760: if ($which eq 'corrected' || $which eq 'skipped') {
8761: $file.=$which.'_';
1.192 albertel 8762: } else {
8763: return 'refused';
8764: }
1.257 albertel 8765: $file.=$env{'form.scantron_selectfile'};
1.200 albertel 8766: return &Apache::lonnet::removeuserfile($cname,$cdom,$file);
8767: }
8768:
1.423 albertel 8769:
8770: =pod
8771:
8772: =item scantron_remove_scan_data
8773:
1.659 raeburn 8774: Removes all scan_data correction for the requested bubblesheet
1.424 albertel 8775: data file. (In the case that both the are doing skipped records we need
8776: to remember the old skipped lines for the time being so that element
8777: persists for a while.)
8778:
1.423 albertel 8779: =cut
8780:
1.200 albertel 8781: sub scantron_remove_scan_data {
1.257 albertel 8782: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
8783: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 8784: my @keys=&Apache::lonnet::getkeys('nohist_scantrondata',$cdom,$cname);
8785: my @todelete;
1.257 albertel 8786: my $filename=$env{'form.scantron_selectfile'};
1.192 albertel 8787: foreach my $key (@keys) {
8788: if ($key=~/^\Q$filename\E_/) {
1.257 albertel 8789: if ($env{'form.scantron_options_redo'} eq 'redo_skipped_ready' &&
1.200 albertel 8790: $key=~/remember_skipping/) {
8791: next;
8792: }
1.192 albertel 8793: push(@todelete,$key);
8794: }
8795: }
1.200 albertel 8796: my $result;
1.192 albertel 8797: if (@todelete) {
1.491 albertel 8798: $result = &Apache::lonnet::del('nohist_scantrondata',
8799: \@todelete,$cdom,$cname);
8800: } else {
8801: $result = 'ok';
1.192 albertel 8802: }
8803: return $result;
8804: }
8805:
1.423 albertel 8806:
8807: =pod
8808:
8809: =item scantron_getfile
8810:
1.659 raeburn 8811: Fetches the requested bubblesheet data file (all 3 versions), and
1.424 albertel 8812: the scan_data hash
8813:
8814: Arguments:
8815: None
8816:
8817: Returns:
8818: 2 hash references
8819:
8820: - first one has
8821: orig -
8822: corrected -
8823: skipped - each of which points to an array ref of the specified
8824: file broken up into individual lines
8825: count - number of scanlines
8826:
8827: - second is the scan_data hash possible keys are
1.425 albertel 8828: ($number refers to scanline numbered $number and thus the key affects
8829: only that scanline
8830: $bubline refers to the specific bubble line element and the aspects
8831: refers to that specific bubble line element)
8832:
8833: $number.user - username:domain to use
8834: $number.CODE_ignore_dup
8835: - ignore the duplicate CODE error
8836: $number.useCODE
8837: - use the CODE in the scanline as is
8838: $number.no_bubble.$bubline
8839: - it is valid that there is no bubbled in bubble
8840: at $number $bubline
8841: remember_skipping
8842: - a frozen hash containing keys of $number and values
8843: of either
8844: 1 - we are on a 'do skipped records pass' and plan
8845: on processing this line
8846: 2 - we are on a 'do skipped records pass' and this
8847: scanline has been marked to skip yet again
1.424 albertel 8848:
1.423 albertel 8849: =cut
8850:
1.157 albertel 8851: sub scantron_getfile {
1.200 albertel 8852: #FIXME really would prefer a scantron directory
1.257 albertel 8853: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
8854: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.157 albertel 8855: my $lines;
8856: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 8857: 'scantron_orig_'.$env{'form.scantron_selectfile'});
1.157 albertel 8858: my %scanlines;
8859: $scanlines{'orig'}=[(split("\n",$lines,-1))];
8860: my $temp=$scanlines{'orig'};
8861: $scanlines{'count'}=$#$temp;
8862:
8863: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 8864: 'scantron_corrected_'.$env{'form.scantron_selectfile'});
1.157 albertel 8865: if ($lines eq '-1') {
8866: $scanlines{'corrected'}=[];
8867: } else {
8868: $scanlines{'corrected'}=[(split("\n",$lines,-1))];
8869: }
8870: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 8871: 'scantron_skipped_'.$env{'form.scantron_selectfile'});
1.157 albertel 8872: if ($lines eq '-1') {
8873: $scanlines{'skipped'}=[];
8874: } else {
8875: $scanlines{'skipped'}=[(split("\n",$lines,-1))];
8876: }
1.175 albertel 8877: my @tmp=&Apache::lonnet::dump('nohist_scantrondata',$cdom,$cname);
1.157 albertel 8878: if ($tmp[0] =~ /^(error:|no_such_host)/) { @tmp=(); }
8879: my %scan_data = @tmp;
8880: return (\%scanlines,\%scan_data);
8881: }
8882:
1.423 albertel 8883: =pod
8884:
8885: =item lonnet_putfile
8886:
1.424 albertel 8887: Wrapper routine to call &Apache::lonnet::finishuserfileupload
8888:
8889: Arguments:
8890: $contents - data to store
8891: $filename - filename to store $contents into
8892:
8893: Returns:
8894: result value from &Apache::lonnet::finishuserfileupload
8895:
1.423 albertel 8896: =cut
8897:
1.157 albertel 8898: sub lonnet_putfile {
8899: my ($contents,$filename)=@_;
1.257 albertel 8900: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
8901: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
8902: $env{'form.sillywaytopassafilearound'}=$contents;
1.275 albertel 8903: &Apache::lonnet::finishuserfileupload($docuname,$docudom,'sillywaytopassafilearound',$filename);
1.157 albertel 8904:
8905: }
8906:
1.423 albertel 8907: =pod
8908:
8909: =item scantron_putfile
8910:
1.659 raeburn 8911: Stores the current version of the bubblesheet data files, and the
1.424 albertel 8912: scan_data hash. (Does not modify the original version only the
8913: corrected and skipped versions.
8914:
8915: Arguments:
8916: $scanlines - hash ref that looks like the first return value from
8917: &scantron_getfile()
8918: $scan_data - hash ref that looks like the second return value from
8919: &scantron_getfile()
8920:
1.423 albertel 8921: =cut
8922:
1.157 albertel 8923: sub scantron_putfile {
8924: my ($scanlines,$scan_data) = @_;
1.200 albertel 8925: #FIXME really would prefer a scantron directory
1.257 albertel 8926: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
8927: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.200 albertel 8928: if ($scanlines) {
8929: my $prefix='scantron_';
1.157 albertel 8930: # no need to update orig, shouldn't change
8931: # &lonnet_putfile(join("\n",@{$scanlines->{'orig'}}),$prefix.'orig_'.
1.257 albertel 8932: # $env{'form.scantron_selectfile'});
1.200 albertel 8933: &lonnet_putfile(join("\n",@{$scanlines->{'corrected'}}),
8934: $prefix.'corrected_'.
1.257 albertel 8935: $env{'form.scantron_selectfile'});
1.200 albertel 8936: &lonnet_putfile(join("\n",@{$scanlines->{'skipped'}}),
8937: $prefix.'skipped_'.
1.257 albertel 8938: $env{'form.scantron_selectfile'});
1.200 albertel 8939: }
1.175 albertel 8940: &Apache::lonnet::put('nohist_scantrondata',$scan_data,$cdom,$cname);
1.157 albertel 8941: }
8942:
1.423 albertel 8943: =pod
8944:
8945: =item scantron_get_line
8946:
1.424 albertel 8947: Returns the correct version of the scanline
8948:
8949: Arguments:
8950: $scanlines - hash ref that looks like the first return value from
8951: &scantron_getfile()
8952: $scan_data - hash ref that looks like the second return value from
8953: &scantron_getfile()
8954: $i - number of the requested line (starts at 0)
8955:
8956: Returns:
8957: A scanline, (either the original or the corrected one if it
8958: exists), or undef if the requested scanline should be
8959: skipped. (Either because it's an skipped scanline, or it's an
8960: unskipped scanline and we are not doing a 'do skipped scanlines'
8961: pass.
8962:
1.423 albertel 8963: =cut
8964:
1.157 albertel 8965: sub scantron_get_line {
1.200 albertel 8966: my ($scanlines,$scan_data,$i)=@_;
1.376 albertel 8967: if (&should_be_skipped($scanlines,$scan_data,$i)) { return undef; }
8968: #if ($scanlines->{'skipped'}[$i]) { return undef; }
1.157 albertel 8969: if ($scanlines->{'corrected'}[$i]) {return $scanlines->{'corrected'}[$i];}
8970: return $scanlines->{'orig'}[$i];
8971: }
8972:
1.423 albertel 8973: =pod
8974:
8975: =item scantron_todo_count
8976:
1.424 albertel 8977: Counts the number of scanlines that need processing.
8978:
8979: Arguments:
8980: $scanlines - hash ref that looks like the first return value from
8981: &scantron_getfile()
8982: $scan_data - hash ref that looks like the second return value from
8983: &scantron_getfile()
8984:
8985: Returns:
8986: $count - number of scanlines to process
8987:
1.423 albertel 8988: =cut
8989:
1.200 albertel 8990: sub get_todo_count {
8991: my ($scanlines,$scan_data)=@_;
8992: my $count=0;
8993: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
8994: my $line=&scantron_get_line($scanlines,$scan_data,$i);
8995: if ($line=~/^[\s\cz]*$/) { next; }
8996: $count++;
8997: }
8998: return $count;
8999: }
9000:
1.423 albertel 9001: =pod
9002:
9003: =item scantron_put_line
9004:
1.659 raeburn 9005: Updates the 'corrected' or 'skipped' versions of the bubblesheet
1.424 albertel 9006: data file.
9007:
9008: Arguments:
9009: $scanlines - hash ref that looks like the first return value from
9010: &scantron_getfile()
9011: $scan_data - hash ref that looks like the second return value from
9012: &scantron_getfile()
9013: $i - line number to update
9014: $newline - contents of the updated scanline
9015: $skip - if true make the line for skipping and update the
9016: 'skipped' file
9017:
1.423 albertel 9018: =cut
9019:
1.157 albertel 9020: sub scantron_put_line {
1.200 albertel 9021: my ($scanlines,$scan_data,$i,$newline,$skip)=@_;
1.157 albertel 9022: if ($skip) {
9023: $scanlines->{'skipped'}[$i]=$newline;
1.376 albertel 9024: &start_skipping($scan_data,$i);
1.157 albertel 9025: return;
9026: }
9027: $scanlines->{'corrected'}[$i]=$newline;
9028: }
9029:
1.423 albertel 9030: =pod
9031:
9032: =item scantron_clear_skip
9033:
1.424 albertel 9034: Remove a line from the 'skipped' file
9035:
9036: Arguments:
9037: $scanlines - hash ref that looks like the first return value from
9038: &scantron_getfile()
9039: $scan_data - hash ref that looks like the second return value from
9040: &scantron_getfile()
9041: $i - line number to update
9042:
1.423 albertel 9043: =cut
9044:
1.376 albertel 9045: sub scantron_clear_skip {
9046: my ($scanlines,$scan_data,$i)=@_;
9047: if (exists($scanlines->{'skipped'}[$i])) {
9048: undef($scanlines->{'skipped'}[$i]);
9049: return 1;
9050: }
9051: return 0;
9052: }
9053:
1.423 albertel 9054: =pod
9055:
9056: =item scantron_filter_not_exam
9057:
1.424 albertel 9058: Filter routine used by &Apache::lonnavmaps::retrieveResources(), to
9059: filter out resources that are not marked as 'exam' mode
9060:
1.423 albertel 9061: =cut
9062:
1.334 albertel 9063: sub scantron_filter_not_exam {
9064: my ($curres)=@_;
9065:
9066: if (ref($curres) && $curres->is_problem() && !$curres->is_exam()) {
9067: # if the user has asked to not have either hidden
9068: # or 'randomout' controlled resources to be graded
9069: # don't include them
9070: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
9071: && $curres->randomout) {
9072: return 0;
9073: }
9074: return 1;
9075: }
9076: return 0;
9077: }
9078:
1.423 albertel 9079: =pod
9080:
9081: =item scantron_validate_sequence
9082:
1.424 albertel 9083: Validates the selected sequence, checking for resource that are
9084: not set to exam mode.
9085:
1.423 albertel 9086: =cut
9087:
1.334 albertel 9088: sub scantron_validate_sequence {
9089: my ($r,$currentphase) = @_;
9090:
9091: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 9092: unless (ref($navmap)) {
9093: $r->print(&navmap_errormsg());
9094: return (1,$currentphase);
9095: }
1.334 albertel 9096: my (undef,undef,$sequence)=
9097: &Apache::lonnet::decode_symb($env{'form.selectpage'});
9098:
9099: my $map=$navmap->getResourceByUrl($sequence);
9100:
9101: $r->print('<input type="hidden" name="validate_sequence_exam"
9102: value="ignore" />');
9103: if ($env{'form.validate_sequence_exam'} ne 'ignore') {
9104: my @resources=
9105: $navmap->retrieveResources($map,\&scantron_filter_not_exam,1,0);
9106: if (@resources) {
1.675 bisitz 9107: $r->print(
9108: '<p class="LC_warning">'
9109: .&mt('Some resources in the sequence currently are not set to'
1.684 bisitz 9110: .' bubblesheet exam mode. Grading these resources currently may not'
1.675 bisitz 9111: .' work correctly.')
9112: .'</p>'
9113: );
1.334 albertel 9114: return (1,$currentphase);
9115: }
9116: }
9117:
9118: return (0,$currentphase+1);
9119: }
9120:
1.423 albertel 9121:
9122:
1.157 albertel 9123: sub scantron_validate_ID {
1.770 raeburn 9124: my ($r,$currentphase,$skipbysec,$checksec,@gradable) = @_;
1.157 albertel 9125:
9126: #get student info
9127: my $classlist=&Apache::loncoursedata::get_classlist();
9128: my %idmap=&username_to_idmap($classlist);
1.770 raeburn 9129: my $secidx = &Apache::loncoursedata::CL_SECTION();
1.157 albertel 9130:
9131: #get scantron line setup
1.754 raeburn 9132: my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.157 albertel 9133: my ($scanlines,$scan_data)=&scantron_getfile();
1.582 raeburn 9134:
9135: my $nav_error;
1.649 raeburn 9136: &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the bubble_lines.. array.
1.582 raeburn 9137: if ($nav_error) {
9138: $r->print(&navmap_errormsg());
9139: return(1,$currentphase);
9140: }
1.157 albertel 9141:
9142: my %found=('ids'=>{},'usernames'=>{});
1.770 raeburn 9143: my $unsavedskips = 0;
1.157 albertel 9144: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 9145: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 9146: if ($line=~/^[\s\cz]*$/) { next; }
9147: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
9148: $scan_data);
9149: my $id=$$scan_record{'scantron.ID'};
9150: my $found;
9151: foreach my $checkid (keys(%idmap)) {
9152: if (lc($checkid) eq lc($id)) { $found=$checkid;last; }
9153: }
9154: if ($found) {
9155: my $username=$idmap{$found};
1.770 raeburn 9156: if ($checksec) {
9157: if (ref($classlist->{$username}) eq 'ARRAY') {
9158: my $stusec = $classlist->{$username}->[$secidx];
9159: if ($stusec ne $checksec) {
9160: unless ((@gradable > 0) && (grep(/^\Q$stusec\E$/,@gradable))) {
9161: my $skip=1;
9162: &scantron_put_line($scanlines,$scan_data,$i,$line,$skip);
9163: if (ref($skipbysec) eq 'HASH') {
9164: if ($stusec eq '') {
9165: $skipbysec->{'none'} ++;
9166: } else {
9167: $skipbysec->{$stusec} ++;
9168: }
9169: }
9170: $unsavedskips ++;
9171: next;
9172: }
9173: }
9174: }
9175: }
1.157 albertel 9176: if ($found{'ids'}{$found}) {
9177: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
9178: $line,'duplicateID',$found);
1.770 raeburn 9179: if ($unsavedskips) {
9180: &scantron_putfile($scanlines,$scan_data);
9181: $unsavedskips = 0;
9182: }
1.194 albertel 9183: return(1,$currentphase);
1.157 albertel 9184: } elsif ($found{'usernames'}{$username}) {
9185: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
9186: $line,'duplicateID',$username);
1.770 raeburn 9187: if ($unsavedskips) {
9188: &scantron_putfile($scanlines,$scan_data);
9189: $unsavedskips = 0;
9190: }
1.194 albertel 9191: return(1,$currentphase);
1.157 albertel 9192: }
1.186 albertel 9193: #FIXME store away line we previously saw the ID on to use above
1.157 albertel 9194: $found{'ids'}{$found}++;
9195: $found{'usernames'}{$username}++;
9196: } else {
9197: if ($id =~ /^\s*$/) {
1.158 albertel 9198: my $username=&scan_data($scan_data,"$i.user");
1.770 raeburn 9199: if (($checksec && $username ne '')) {
9200: if (ref($classlist->{$username}) eq 'ARRAY') {
9201: my $stusec = $classlist->{$username}->[$secidx];
9202: if ($stusec ne $checksec) {
9203: unless ((@gradable > 0) && (grep(/^\Q$stusec\E$/,@gradable))) {
9204: my $skip=1;
9205: &scantron_put_line($scanlines,$scan_data,$i,$line,$skip);
9206: if (ref($skipbysec) eq 'HASH') {
9207: if ($stusec eq '') {
9208: $skipbysec->{'none'} ++;
9209: } else {
9210: $skipbysec->{$stusec} ++;
9211: }
9212: }
9213: $unsavedskips ++;
9214: next;
9215: }
9216: }
9217: }
9218: } elsif (defined($username) && $found{'usernames'}{$username}) {
1.157 albertel 9219: &scantron_get_correction($r,$i,$scan_record,
9220: \%scantron_config,
9221: $line,'duplicateID',$username);
1.770 raeburn 9222: if ($unsavedskips) {
9223: &scantron_putfile($scanlines,$scan_data);
9224: $unsavedskips = 0;
9225: }
1.194 albertel 9226: return(1,$currentphase);
1.157 albertel 9227: } elsif (!defined($username)) {
9228: &scantron_get_correction($r,$i,$scan_record,
9229: \%scantron_config,
9230: $line,'incorrectID');
1.770 raeburn 9231: if ($unsavedskips) {
9232: &scantron_putfile($scanlines,$scan_data);
9233: $unsavedskips = 0;
9234: }
1.194 albertel 9235: return(1,$currentphase);
1.157 albertel 9236: }
9237: $found{'usernames'}{$username}++;
9238: } else {
9239: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
9240: $line,'incorrectID');
1.770 raeburn 9241: if ($unsavedskips) {
9242: &scantron_putfile($scanlines,$scan_data);
9243: $unsavedskips = 0;
9244: }
1.194 albertel 9245: return(1,$currentphase);
1.157 albertel 9246: }
9247: }
9248: }
1.770 raeburn 9249: if ($unsavedskips) {
9250: &scantron_putfile($scanlines,$scan_data);
9251: $unsavedskips = 0;
9252: }
1.157 albertel 9253: return (0,$currentphase+1);
9254: }
9255:
1.770 raeburn 9256: sub scantron_get_sections {
9257: my %bysec;
9258: if ($env{'form.scantron_format'} ne '') {
9259: my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
9260: my ($scanlines,$scan_data)=&scantron_getfile();
9261: my $classlist=&Apache::loncoursedata::get_classlist();
9262: my %idmap=&username_to_idmap($classlist);
9263: foreach my $key (keys(%idmap)) {
9264: my $lckey = lc($key);
9265: $idmap{$lckey} = $idmap{$key};
9266: }
9267: my $secidx = &Apache::loncoursedata::CL_SECTION();
9268: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
9269: my $line=&scantron_get_line($scanlines,$scan_data,$i);
9270: if ($line=~/^[\s\cz]*$/) { next; }
9271: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
9272: $scan_data);
9273: my $id=lc($$scan_record{'scantron.ID'});
9274: if (exists($idmap{$id})) {
9275: if (ref($classlist->{$idmap{$id}}) eq 'ARRAY') {
9276: my $stusec = $classlist->{$idmap{$id}}->[$secidx];
9277: if ($stusec eq '') {
9278: $bysec{'none'} ++;
9279: } else {
9280: $bysec{$stusec} ++;
9281: }
9282: }
9283: }
9284: }
9285: }
9286: return %bysec;
9287: }
1.423 albertel 9288:
1.157 albertel 9289: sub scantron_get_correction {
1.691 raeburn 9290: my ($r,$i,$scan_record,$scan_config,$line,$error,$arg,
9291: $randomorder,$randompick,$respnumlookup,$startline)=@_;
1.454 banghart 9292: #FIXME in the case of a duplicated ID the previous line, probably need
1.157 albertel 9293: #to show both the current line and the previous one and allow skipping
9294: #the previous one or the current one
9295:
1.333 albertel 9296: if ( $$scan_record{'scantron.PaperID'} =~ /\S/) {
1.658 bisitz 9297: $r->print(
9298: '<p class="LC_warning">'
9299: .&mt('An error was detected ([_1]) for PaperID [_2]',
9300: "<b>$error</b>",
9301: '<tt>'.$$scan_record{'scantron.PaperID'}.'</tt>')
9302: ."</p> \n");
1.157 albertel 9303: } else {
1.658 bisitz 9304: $r->print(
9305: '<p class="LC_warning">'
9306: .&mt('An error was detected ([_1]) in scanline [_2] [_3]',
9307: "<b>$error</b>", $i, "<pre>$line</pre>")
9308: ."</p> \n");
9309: }
9310: my $message =
9311: '<p>'
9312: .&mt('The ID on the form is [_1]',
9313: "<tt>$$scan_record{'scantron.ID'}</tt>")
9314: .'<br />'
1.665 raeburn 9315: .&mt('The name on the paper is [_1], [_2]',
1.658 bisitz 9316: $$scan_record{'scantron.LastName'},
9317: $$scan_record{'scantron.FirstName'})
9318: .'</p>';
1.242 albertel 9319:
1.157 albertel 9320: $r->print('<input type="hidden" name="scantron_corrections" value="'.$error.'" />'."\n");
9321: $r->print('<input type="hidden" name="scantron_line" value="'.$i.'" />'."\n");
1.503 raeburn 9322: # Array populated for doublebubble or
9323: my @lines_to_correct; # missingbubble errors to build javascript
9324: # to validate radio button checking
9325:
1.157 albertel 9326: if ($error =~ /ID$/) {
1.186 albertel 9327: if ($error eq 'incorrectID') {
1.658 bisitz 9328: $r->print('<p class="LC_warning">'.&mt("The encoded ID is not in the classlist").
1.492 albertel 9329: "</p>\n");
1.157 albertel 9330: } elsif ($error eq 'duplicateID') {
1.658 bisitz 9331: $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 9332: }
1.242 albertel 9333: $r->print($message);
1.492 albertel 9334: $r->print("<p>".&mt("How should I handle this?")." <br /> \n");
1.157 albertel 9335: $r->print("\n<ul><li> ");
9336: #FIXME it would be nice if this sent back the user ID and
9337: #could do partial userID matches
9338: $r->print(&Apache::loncommon::selectstudent_link('scantronupload',
9339: 'scantron_username','scantron_domain'));
9340: $r->print(": <input type='text' name='scantron_username' value='' />");
1.685 bisitz 9341: $r->print("\n:\n".
1.257 albertel 9342: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'scantron_domain'));
1.157 albertel 9343:
9344: $r->print('</li>');
1.186 albertel 9345: } elsif ($error =~ /CODE$/) {
9346: if ($error eq 'incorrectCODE') {
1.658 bisitz 9347: $r->print('<p class="LC_warning">'.&mt("The encoded CODE is not in the list of possible CODEs.")."</p>\n");
1.186 albertel 9348: } elsif ($error eq 'duplicateCODE') {
1.658 bisitz 9349: $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 9350: }
1.658 bisitz 9351: $r->print("<p>".&mt('The CODE on the form is [_1]',
9352: "<tt>'$$scan_record{'scantron.CODE'}'</tt>")
9353: ."</p>\n");
1.242 albertel 9354: $r->print($message);
1.658 bisitz 9355: $r->print("<p>".&mt("How should I handle this?")."</p>\n");
1.187 albertel 9356: $r->print("\n<br /> ");
1.194 albertel 9357: my $i=0;
1.273 albertel 9358: if ($error eq 'incorrectCODE'
9359: && $$scan_record{'scantron.CODE'}=~/\S/ ) {
1.194 albertel 9360: my ($max,$closest)=&scantron_get_closely_matching_CODEs($arg,$$scan_record{'scantron.CODE'});
1.278 albertel 9361: if ($closest > 0) {
9362: foreach my $testcode (@{$closest}) {
9363: my $checked='';
1.569 bisitz 9364: if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 9365: $r->print("
9366: <label>
1.569 bisitz 9367: <input type='radio' name='scantron_CODE_resolution' value='use_closest_$i'$checked />
1.492 albertel 9368: ".&mt("Use the similar CODE [_1] instead.",
9369: "<b><tt>".$testcode."</tt></b>")."
9370: </label>
9371: <input type='hidden' name='scantron_CODE_closest_$i' value='$testcode' />");
1.278 albertel 9372: $r->print("\n<br />");
9373: $i++;
9374: }
1.194 albertel 9375: }
9376: }
1.273 albertel 9377: if ($$scan_record{'scantron.CODE'}=~/\S/ ) {
1.569 bisitz 9378: my $checked; if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 9379: $r->print("
9380: <label>
1.569 bisitz 9381: <input type='radio' name='scantron_CODE_resolution' value='use_unfound'$checked />
1.659 raeburn 9382: ".&mt("Use the CODE [_1] that was on the paper, ignoring the error.",
1.492 albertel 9383: "<b><tt>".$$scan_record{'scantron.CODE'}."</tt></b>")."
9384: </label>");
1.273 albertel 9385: $r->print("\n<br />");
9386: }
1.194 albertel 9387:
1.597 wenzelju 9388: $r->print(&Apache::lonhtmlcommon::scripttag(<<ENDSCRIPT));
1.188 albertel 9389: function change_radio(field) {
1.190 albertel 9390: var slct=document.scantronupload.scantron_CODE_resolution;
1.188 albertel 9391: var i;
9392: for (i=0;i<slct.length;i++) {
9393: if (slct[i].value==field) { slct[i].checked=true; }
9394: }
9395: }
9396: ENDSCRIPT
1.187 albertel 9397: my $href="/adm/pickcode?".
1.359 www 9398: "form=".&escape("scantronupload").
9399: "&scantron_format=".&escape($env{'form.scantron_format'}).
9400: "&scantron_CODElist=".&escape($env{'form.scantron_CODElist'}).
9401: "&curCODE=".&escape($$scan_record{'scantron.CODE'}).
9402: "&scantron_selectfile=".&escape($env{'form.scantron_selectfile'});
1.332 albertel 9403: if ($env{'form.scantron_CODElist'} =~ /\S/) {
1.492 albertel 9404: $r->print("
9405: <label>
9406: <input type='radio' name='scantron_CODE_resolution' value='use_found' />
9407: ".&mt("[_1]Select[_2] a CODE from the list of all CODEs and use it.",
9408: "<a target='_blank' href='$href'>","</a>")."
9409: </label>
1.558 bisitz 9410: ".&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 9411: $r->print("\n<br />");
9412: }
1.492 albertel 9413: $r->print("
9414: <label>
9415: <input type='radio' name='scantron_CODE_resolution' value='use_typed' />
9416: ".&mt("Use [_1] as the CODE.",
9417: "</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 9418: $r->print("\n<br /><br />");
1.157 albertel 9419: } elsif ($error eq 'doublebubble') {
1.658 bisitz 9420: $r->print('<p class="LC_warning">'.&mt("There have been multiple bubbles scanned for some question(s)")."</p>\n");
1.497 foxr 9421:
9422: # The form field scantron_questions is acutally a list of line numbers.
9423: # represented by this form so:
9424:
1.691 raeburn 9425: my $line_list = &questions_to_line_list($arg,$randomorder,$randompick,
9426: $respnumlookup,$startline);
1.497 foxr 9427:
1.157 albertel 9428: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 9429: $line_list.'" />');
1.242 albertel 9430: $r->print($message);
1.492 albertel 9431: $r->print("<p>".&mt("Please indicate which bubble should be used for grading")."</p>");
1.157 albertel 9432: foreach my $question (@{$arg}) {
1.503 raeburn 9433: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
1.691 raeburn 9434: $scan_record, $error,
9435: $randomorder,$randompick,
9436: $respnumlookup,$startline);
1.524 raeburn 9437: push(@lines_to_correct,@linenums);
1.157 albertel 9438: }
1.503 raeburn 9439: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 9440: } elsif ($error eq 'missingbubble') {
1.658 bisitz 9441: $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 9442: $r->print($message);
1.492 albertel 9443: $r->print("<p>".&mt("Please indicate which bubble should be used for grading.")."</p>");
1.503 raeburn 9444: $r->print(&mt("Some questions have no scanned bubbles.")."\n");
1.497 foxr 9445:
1.503 raeburn 9446: # The form field scantron_questions is actually a list of line numbers not
1.497 foxr 9447: # a list of question numbers. Therefore:
9448: #
1.691 raeburn 9449:
9450: my $line_list = &questions_to_line_list($arg,$randomorder,$randompick,
9451: $respnumlookup,$startline);
1.497 foxr 9452:
1.157 albertel 9453: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 9454: $line_list.'" />');
1.157 albertel 9455: foreach my $question (@{$arg}) {
1.503 raeburn 9456: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
1.691 raeburn 9457: $scan_record, $error,
9458: $randomorder,$randompick,
9459: $respnumlookup,$startline);
1.524 raeburn 9460: push(@lines_to_correct,@linenums);
1.157 albertel 9461: }
1.503 raeburn 9462: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 9463: } else {
9464: $r->print("\n<ul>");
9465: }
9466: $r->print("\n</li></ul>");
1.497 foxr 9467: }
9468:
1.503 raeburn 9469: sub verify_bubbles_checked {
9470: my (@ansnums) = @_;
9471: my $ansnumstr = join('","',@ansnums);
9472: my $warning = &mt("A bubble or 'No bubble' selection has not been made for one or more lines.");
1.736 damieng 9473: &js_escape(\$warning);
1.767 raeburn 9474: my $output = &Apache::lonhtmlcommon::scripttag(<<ENDSCRIPT);
1.503 raeburn 9475: function verify_bubble_radio(form) {
9476: var ansnumArray = new Array ("$ansnumstr");
9477: var need_bubble_count = 0;
9478: for (var i=0; i<ansnumArray.length; i++) {
9479: if (form.elements["scantron_correct_Q_"+ansnumArray[i]].length > 1) {
9480: var bubble_picked = 0;
9481: for (var j=0; j<form.elements["scantron_correct_Q_"+ansnumArray[i]].length; j++) {
9482: if (form.elements["scantron_correct_Q_"+ansnumArray[i]][j].checked == true) {
9483: bubble_picked = 1;
9484: }
9485: }
9486: if (bubble_picked == 0) {
9487: need_bubble_count ++;
9488: }
9489: }
9490: }
9491: if (need_bubble_count) {
9492: alert("$warning");
9493: return;
9494: }
9495: form.submit();
9496: }
9497: ENDSCRIPT
9498: return $output;
9499: }
9500:
1.497 foxr 9501: =pod
9502:
9503: =item questions_to_line_list
1.157 albertel 9504:
1.497 foxr 9505: Converts a list of questions into a string of comma separated
9506: line numbers in the answer sheet used by the questions. This is
9507: used to fill in the scantron_questions form field.
9508:
9509: Arguments:
9510: questions - Reference to an array of questions.
1.691 raeburn 9511: randomorder - True if randomorder in use.
9512: randompick - True if randompick in use.
9513: respnumlookup - Reference to HASH mapping question numbers in bubble lines
9514: for current line to question number used for same question
9515: in "Master Seqence" (as seen by Course Coordinator).
9516: startline - Reference to hash where key is question number (0 is first)
9517: and key is number of first bubble line for current student
9518: or code-based randompick and/or randomorder.
1.693 raeburn 9519:
1.497 foxr 9520: =cut
9521:
9522:
9523: sub questions_to_line_list {
1.691 raeburn 9524: my ($questions,$randomorder,$randompick,$respnumlookup,$startline) = @_;
1.497 foxr 9525: my @lines;
9526:
1.503 raeburn 9527: foreach my $item (@{$questions}) {
9528: my $question = $item;
9529: my ($first,$count,$last);
9530: if ($item =~ /^(\d+)\.(\d+)$/) {
9531: $question = $1;
9532: my $subquestion = $2;
1.691 raeburn 9533: my $responsenum = $question-1;
9534: if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
9535: $responsenum = $respnumlookup->{$question-1};
9536: if (ref($startline) eq 'HASH') {
9537: $first = $startline->{$question-1} + 1;
9538: }
9539: } else {
9540: $first = $first_bubble_line{$responsenum} + 1;
9541: }
9542: my @subans = split(/,/,$subdivided_bubble_lines{$responsenum});
1.503 raeburn 9543: my $subcount = 1;
9544: while ($subcount<$subquestion) {
9545: $first += $subans[$subcount-1];
9546: $subcount ++;
9547: }
9548: $count = $subans[$subquestion-1];
9549: } else {
1.691 raeburn 9550: my $responsenum = $question-1;
9551: if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
9552: $responsenum = $respnumlookup->{$question-1};
9553: if (ref($startline) eq 'HASH') {
9554: $first = $startline->{$question-1} + 1;
9555: }
9556: } else {
9557: $first = $first_bubble_line{$responsenum} + 1;
9558: }
9559: $count = $bubble_lines_per_response{$responsenum};
1.503 raeburn 9560: }
1.506 raeburn 9561: $last = $first+$count-1;
1.503 raeburn 9562: push(@lines, ($first..$last));
1.497 foxr 9563: }
9564: return join(',', @lines);
9565: }
9566:
9567: =pod
9568:
9569: =item prompt_for_corrections
9570:
9571: Prompts for a potentially multiline correction to the
9572: user's bubbling (factors out common code from scantron_get_correction
9573: for multi and missing bubble cases).
9574:
9575: Arguments:
9576: $r - Apache request object.
9577: $question - The question number to prompt for.
9578: $scan_config - The scantron file configuration hash.
9579: $scan_record - Reference to the hash that has the the parsed scanlines.
1.503 raeburn 9580: $error - Type of error
1.691 raeburn 9581: $randomorder - True if randomorder in use.
9582: $randompick - True if randompick in use.
9583: $respnumlookup - Reference to HASH mapping question numbers in bubble lines
9584: for current line to question number used for same question
9585: in "Master Seqence" (as seen by Course Coordinator).
9586: $startline - Reference to hash where key is question number (0 is first)
9587: and value is number of first bubble line for current student
9588: or code-based randompick and/or randomorder.
9589:
1.497 foxr 9590:
9591: Implicit inputs:
9592: %bubble_lines_per_response - Starting line numbers for each question.
9593: Numbered from 0 (but question numbers are from
9594: 1.
9595: %first_bubble_line - Starting bubble line for each question.
1.509 raeburn 9596: %subdivided_bubble_lines - optionresponse, matchresponse and rankresponse
9597: type problems render as separate sub-questions,
1.503 raeburn 9598: in exam mode. This hash contains a
9599: comma-separated list of the lines per
9600: sub-question.
1.510 raeburn 9601: %responsetype_per_response - essayresponse, formularesponse,
9602: stringresponse, imageresponse, reactionresponse,
9603: and organicresponse type problem parts can have
1.503 raeburn 9604: multiple lines per response if the weight
9605: assigned exceeds 10. In this case, only
9606: one bubble per line is permitted, but more
9607: than one line might contain bubbles, e.g.
9608: bubbling of: line 1 - J, line 2 - J,
9609: line 3 - B would assign 22 points.
1.497 foxr 9610:
9611: =cut
9612:
9613: sub prompt_for_corrections {
1.691 raeburn 9614: my ($r, $question, $scan_config, $scan_record, $error, $randomorder,
9615: $randompick, $respnumlookup, $startline) = @_;
1.503 raeburn 9616: my ($current_line,$lines);
9617: my @linenums;
9618: my $questionnum = $question;
1.691 raeburn 9619: my ($first,$responsenum);
1.503 raeburn 9620: if ($question =~ /^(\d+)\.(\d+)$/) {
9621: $question = $1;
9622: my $subquestion = $2;
1.691 raeburn 9623: if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
9624: $responsenum = $respnumlookup->{$question-1};
9625: if (ref($startline) eq 'HASH') {
9626: $first = $startline->{$question-1};
9627: }
9628: } else {
9629: $responsenum = $question-1;
1.714 raeburn 9630: $first = $first_bubble_line{$responsenum};
1.691 raeburn 9631: }
9632: $current_line = $first + 1 ;
9633: my @subans = split(/,/,$subdivided_bubble_lines{$responsenum});
1.503 raeburn 9634: my $subcount = 1;
9635: while ($subcount<$subquestion) {
9636: $current_line += $subans[$subcount-1];
9637: $subcount ++;
9638: }
9639: $lines = $subans[$subquestion-1];
9640: } else {
1.691 raeburn 9641: if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
9642: $responsenum = $respnumlookup->{$question-1};
9643: if (ref($startline) eq 'HASH') {
9644: $first = $startline->{$question-1};
9645: }
9646: } else {
9647: $responsenum = $question-1;
9648: $first = $first_bubble_line{$responsenum};
9649: }
9650: $current_line = $first + 1;
9651: $lines = $bubble_lines_per_response{$responsenum};
1.503 raeburn 9652: }
1.497 foxr 9653: if ($lines > 1) {
1.503 raeburn 9654: $r->print(&mt('The group of bubble lines below responds to a single question.').'<br />');
1.691 raeburn 9655: if (($responsetype_per_response{$responsenum} eq 'essayresponse') ||
9656: ($responsetype_per_response{$responsenum} eq 'formularesponse') ||
9657: ($responsetype_per_response{$responsenum} eq 'stringresponse') ||
9658: ($responsetype_per_response{$responsenum} eq 'imageresponse') ||
9659: ($responsetype_per_response{$responsenum} eq 'reactionresponse') ||
9660: ($responsetype_per_response{$responsenum} eq 'organicresponse')) {
1.684 bisitz 9661: $r->print(
9662: &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)
9663: .'<br /><br />'
9664: .&mt('A non-zero score can be assigned to the student during bubblesheet grading by selecting a bubble in at least one line.')
9665: .'<br />'
9666: .&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.')
9667: .'<br />'
9668: .&mt("To assign a score of zero for this question, mark all lines as 'No bubble'.")
9669: .'<br /><br />'
9670: );
1.503 raeburn 9671: } else {
9672: $r->print(&mt("Select at most one bubble in a single line and select 'No Bubble' in all the other lines. ")."<br />");
9673: }
1.497 foxr 9674: }
9675: for (my $i =0; $i < $lines; $i++) {
1.503 raeburn 9676: my $selected = $$scan_record{"scantron.$current_line.answer"};
1.691 raeburn 9677: &scantron_bubble_selector($r,$scan_config,$current_line,
1.503 raeburn 9678: $questionnum,$error,split('', $selected));
1.524 raeburn 9679: push(@linenums,$current_line);
1.497 foxr 9680: $current_line++;
9681: }
9682: if ($lines > 1) {
9683: $r->print("<hr /><br />");
9684: }
1.503 raeburn 9685: return @linenums;
1.157 albertel 9686: }
1.423 albertel 9687:
9688: =pod
9689:
9690: =item scantron_bubble_selector
9691:
9692: Generates the html radiobuttons to correct a single bubble line
1.424 albertel 9693: possibly showing the existing the selected bubbles if known
1.423 albertel 9694:
9695: Arguments:
9696: $r - Apache request object
1.754 raeburn 9697: $scan_config - hash from &Apache::lonnet::get_scantron_config()
1.497 foxr 9698: $line - Number of the line being displayed.
1.503 raeburn 9699: $questionnum - Question number (may include subquestion)
9700: $error - Type of error.
1.497 foxr 9701: @selected - Array of bubbles picked on this line.
1.423 albertel 9702:
9703: =cut
9704:
1.157 albertel 9705: sub scantron_bubble_selector {
1.503 raeburn 9706: my ($r,$scan_config,$line,$questionnum,$error,@selected)=@_;
1.157 albertel 9707: my $max=$$scan_config{'Qlength'};
1.274 albertel 9708:
9709: my $scmode=$$scan_config{'Qon'};
1.649 raeburn 9710: if ($scmode eq 'number' || $scmode eq 'letter') {
9711: if (($$scan_config{'BubblesPerRow'} =~ /^\d+$/) &&
9712: ($$scan_config{'BubblesPerRow'} > 0)) {
9713: $max=$$scan_config{'BubblesPerRow'};
9714: if (($scmode eq 'number') && ($max > 10)) {
9715: $max = 10;
9716: } elsif (($scmode eq 'letter') && $max > 26) {
9717: $max = 26;
9718: }
9719: } else {
9720: $max = 10;
9721: }
9722: }
1.274 albertel 9723:
1.157 albertel 9724: my @alphabet=('A'..'Z');
1.503 raeburn 9725: $r->print(&Apache::loncommon::start_data_table().
9726: &Apache::loncommon::start_data_table_row());
9727: $r->print('<td rowspan="2" class="LC_leftcol_header">'.$line.'</td>');
1.497 foxr 9728: for (my $i=0;$i<$max+1;$i++) {
9729: $r->print("\n".'<td align="center">');
9730: if ($selected[0] eq $alphabet[$i]) { $r->print('X'); shift(@selected) }
9731: else { $r->print(' '); }
9732: $r->print('</td>');
9733: }
1.503 raeburn 9734: $r->print(&Apache::loncommon::end_data_table_row().
9735: &Apache::loncommon::start_data_table_row());
1.497 foxr 9736: for (my $i=0;$i<$max;$i++) {
9737: $r->print("\n".
9738: '<td><label><input type="radio" name="scantron_correct_Q_'.
9739: $line.'" value="'.$i.'" />'.$alphabet[$i]."</label></td>");
9740: }
1.503 raeburn 9741: my $nobub_checked = ' ';
9742: if ($error eq 'missingbubble') {
9743: $nobub_checked = ' checked = "checked" ';
9744: }
9745: $r->print("\n".'<td><label><input type="radio" name="scantron_correct_Q_'.
9746: $line.'" value="none"'.$nobub_checked.'/>'.&mt('No bubble').
9747: '</label>'."\n".'<input type="hidden" name="scantron_questionnum_Q_'.
9748: $line.'" value="'.$questionnum.'" /></td>');
9749: $r->print(&Apache::loncommon::end_data_table_row().
9750: &Apache::loncommon::end_data_table());
1.157 albertel 9751: }
9752:
1.423 albertel 9753: =pod
9754:
9755: =item num_matches
9756:
1.424 albertel 9757: Counts the number of characters that are the same between the two arguments.
9758:
9759: Arguments:
9760: $orig - CODE from the scanline
9761: $code - CODE to match against
9762:
9763: Returns:
9764: $count - integer count of the number of same characters between the
9765: two arguments
9766:
1.423 albertel 9767: =cut
9768:
1.194 albertel 9769: sub num_matches {
9770: my ($orig,$code) = @_;
9771: my @code=split(//,$code);
9772: my @orig=split(//,$orig);
9773: my $same=0;
9774: for (my $i=0;$i<scalar(@code);$i++) {
9775: if ($code[$i] eq $orig[$i]) { $same++; }
9776: }
9777: return $same;
9778: }
9779:
1.423 albertel 9780: =pod
9781:
9782: =item scantron_get_closely_matching_CODEs
9783:
1.424 albertel 9784: Cycles through all CODEs and finds the set that has the greatest
9785: number of same characters as the provided CODE
9786:
9787: Arguments:
9788: $allcodes - hash ref returned by &get_codes()
9789: $CODE - CODE from the current scanline
9790:
9791: Returns:
9792: 2 element list
9793: - first elements is number of how closely matching the best fit is
9794: (5 means best set has 5 matching characters)
9795: - second element is an arrary ref containing the set of valid CODEs
9796: that best fit the passed in CODE
9797:
1.423 albertel 9798: =cut
9799:
1.194 albertel 9800: sub scantron_get_closely_matching_CODEs {
9801: my ($allcodes,$CODE)=@_;
9802: my @CODEs;
9803: foreach my $testcode (sort(keys(%{$allcodes}))) {
9804: push(@{$CODEs[&num_matches($CODE,$testcode)]},$testcode);
9805: }
9806:
9807: return ($#CODEs,$CODEs[-1]);
9808: }
9809:
1.423 albertel 9810: =pod
9811:
9812: =item get_codes
9813:
1.424 albertel 9814: Builds a hash which has keys of all of the valid CODEs from the selected
9815: set of remembered CODEs.
9816:
9817: Arguments:
9818: $old_name - name of the set of remembered CODEs
9819: $cdom - domain of the course
9820: $cnum - internal course name
9821:
9822: Returns:
9823: %allcodes - keys are the valid CODEs, values are all 1
9824:
1.423 albertel 9825: =cut
9826:
1.194 albertel 9827: sub get_codes {
1.280 foxr 9828: my ($old_name, $cdom, $cnum) = @_;
9829: if (!$old_name) {
9830: $old_name=$env{'form.scantron_CODElist'};
9831: }
9832: if (!$cdom) {
9833: $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
9834: }
9835: if (!$cnum) {
9836: $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
9837: }
1.278 albertel 9838: my %result=&Apache::lonnet::get('CODEs',[$old_name,"type\0$old_name"],
9839: $cdom,$cnum);
9840: my %allcodes;
9841: if ($result{"type\0$old_name"} eq 'number') {
9842: %allcodes=map {($_,1)} split(',',$result{$old_name});
9843: } else {
9844: %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
9845: }
1.194 albertel 9846: return %allcodes;
9847: }
9848:
1.423 albertel 9849: =pod
9850:
9851: =item scantron_validate_CODE
9852:
1.424 albertel 9853: Validates all scanlines in the selected file to not have any
9854: invalid or underspecified CODEs and that none of the codes are
9855: duplicated if this was requested.
9856:
1.423 albertel 9857: =cut
9858:
1.157 albertel 9859: sub scantron_validate_CODE {
9860: my ($r,$currentphase) = @_;
1.754 raeburn 9861: my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.186 albertel 9862: if ($scantron_config{'CODElocation'} &&
9863: $scantron_config{'CODEstart'} &&
9864: $scantron_config{'CODElength'}) {
1.257 albertel 9865: if (!defined($env{'form.scantron_CODElist'})) {
1.186 albertel 9866: &FIXME_blow_up()
9867: }
9868: } else {
9869: return (0,$currentphase+1);
9870: }
9871:
9872: my %usedCODEs;
9873:
1.194 albertel 9874: my %allcodes=&get_codes();
1.186 albertel 9875:
1.582 raeburn 9876: my $nav_error;
1.649 raeburn 9877: &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the lines per response array.
1.582 raeburn 9878: if ($nav_error) {
9879: $r->print(&navmap_errormsg());
9880: return(1,$currentphase);
9881: }
1.447 foxr 9882:
1.186 albertel 9883: my ($scanlines,$scan_data)=&scantron_getfile();
9884: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 9885: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.186 albertel 9886: if ($line=~/^[\s\cz]*$/) { next; }
9887: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
9888: $scan_data);
9889: my $CODE=$$scan_record{'scantron.CODE'};
9890: my $error=0;
1.224 albertel 9891: if (!&Apache::lonnet::validCODE($CODE)) {
9892: &scantron_get_correction($r,$i,$scan_record,
9893: \%scantron_config,
9894: $line,'incorrectCODE',\%allcodes);
9895: return(1,$currentphase);
9896: }
1.221 albertel 9897: if (%allcodes && !exists($allcodes{$CODE})
9898: && !$$scan_record{'scantron.useCODE'}) {
1.186 albertel 9899: &scantron_get_correction($r,$i,$scan_record,
9900: \%scantron_config,
1.194 albertel 9901: $line,'incorrectCODE',\%allcodes);
9902: return(1,$currentphase);
1.186 albertel 9903: }
1.214 albertel 9904: if (exists($usedCODEs{$CODE})
1.257 albertel 9905: && $env{'form.scantron_CODEunique'} eq 'yes'
1.192 albertel 9906: && !$$scan_record{'scantron.CODE_ignore_dup'}) {
1.186 albertel 9907: &scantron_get_correction($r,$i,$scan_record,
9908: \%scantron_config,
1.194 albertel 9909: $line,'duplicateCODE',$usedCODEs{$CODE});
9910: return(1,$currentphase);
1.186 albertel 9911: }
1.524 raeburn 9912: push(@{$usedCODEs{$CODE}},$$scan_record{'scantron.PaperID'});
1.186 albertel 9913: }
1.157 albertel 9914: return (0,$currentphase+1);
9915: }
9916:
1.423 albertel 9917: =pod
9918:
9919: =item scantron_validate_doublebubble
9920:
1.424 albertel 9921: Validates all scanlines in the selected file to not have any
9922: bubble lines with multiple bubbles marked.
9923:
1.423 albertel 9924: =cut
9925:
1.157 albertel 9926: sub scantron_validate_doublebubble {
9927: my ($r,$currentphase) = @_;
9928: #get student info
9929: my $classlist=&Apache::loncoursedata::get_classlist();
9930: my %idmap=&username_to_idmap($classlist);
1.691 raeburn 9931: my (undef,undef,$sequence)=
9932: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.157 albertel 9933:
9934: #get scantron line setup
1.754 raeburn 9935: my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.157 albertel 9936: my ($scanlines,$scan_data)=&scantron_getfile();
1.691 raeburn 9937:
9938: my $navmap = Apache::lonnavmaps::navmap->new();
9939: unless (ref($navmap)) {
9940: $r->print(&navmap_errormsg());
9941: return(1,$currentphase);
9942: }
9943: my $map=$navmap->getResourceByUrl($sequence);
9944: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
9945: my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
9946: %grader_randomlists_by_symb,%orderedforcode,%respnumlookup,%startline);
9947: my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
9948:
1.583 raeburn 9949: my $nav_error;
1.691 raeburn 9950: if (ref($map)) {
9951: $randomorder = $map->randomorder();
9952: $randompick = $map->randompick();
1.788 raeburn 9953: unless ($randomorder || $randompick) {
9954: foreach my $res ($navmap->retrieveResources($map,sub { $_[0]->is_map() },1,0,1)) {
9955: if ($res->randomorder()) {
9956: $randomorder = 1;
9957: }
9958: if ($res->randompick()) {
9959: $randompick = 1;
9960: }
9961: last if ($randomorder || $randompick);
9962: }
9963: }
1.691 raeburn 9964: if ($randomorder || $randompick) {
9965: $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource);
9966: if ($nav_error) {
9967: $r->print(&navmap_errormsg());
9968: return(1,$currentphase);
9969: }
9970: &graders_resources_pass(\@resources,\%grader_partids_by_symb,
9971: \%grader_randomlists_by_symb,$bubbles_per_row);
9972: }
9973: } else {
9974: $r->print(&navmap_errormsg());
9975: return(1,$currentphase);
9976: }
9977:
1.649 raeburn 9978: &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the bubble line array.
1.583 raeburn 9979: if ($nav_error) {
9980: $r->print(&navmap_errormsg());
9981: return(1,$currentphase);
9982: }
1.447 foxr 9983:
1.157 albertel 9984: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 9985: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 9986: if ($line=~/^[\s\cz]*$/) { next; }
9987: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
1.691 raeburn 9988: $scan_data,undef,\%idmap,$randomorder,
9989: $randompick,$sequence,\@master_seq,
9990: \%symb_to_resource,\%grader_partids_by_symb,
9991: \%orderedforcode,\%respnumlookup,\%startline);
1.157 albertel 9992: if (!defined($$scan_record{'scantron.doubleerror'})) { next; }
9993: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,$line,
9994: 'doublebubble',
1.691 raeburn 9995: $$scan_record{'scantron.doubleerror'},
9996: $randomorder,$randompick,\%respnumlookup,\%startline);
1.157 albertel 9997: return (1,$currentphase);
9998: }
9999: return (0,$currentphase+1);
10000: }
10001:
1.423 albertel 10002:
1.503 raeburn 10003: sub scantron_get_maxbubble {
1.649 raeburn 10004: my ($nav_error,$scantron_config) = @_;
1.257 albertel 10005: if (defined($env{'form.scantron_maxbubble'}) &&
10006: $env{'form.scantron_maxbubble'}) {
1.447 foxr 10007: &restore_bubble_lines();
1.257 albertel 10008: return $env{'form.scantron_maxbubble'};
1.191 albertel 10009: }
1.330 albertel 10010:
1.447 foxr 10011: my (undef, undef, $sequence) =
1.257 albertel 10012: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.330 albertel 10013:
1.447 foxr 10014: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 10015: unless (ref($navmap)) {
10016: if (ref($nav_error)) {
10017: $$nav_error = 1;
10018: }
1.591 raeburn 10019: return;
1.582 raeburn 10020: }
1.191 albertel 10021: my $map=$navmap->getResourceByUrl($sequence);
10022: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.649 raeburn 10023: my $bubbles_per_row = &bubblesheet_bubbles_per_row($scantron_config);
1.330 albertel 10024:
10025: &Apache::lonxml::clear_problem_counter();
10026:
1.557 raeburn 10027: my $uname = $env{'user.name'};
10028: my $udom = $env{'user.domain'};
1.435 foxr 10029: my $cid = $env{'request.course.id'};
10030: my $total_lines = 0;
10031: %bubble_lines_per_response = ();
1.447 foxr 10032: %first_bubble_line = ();
1.503 raeburn 10033: %subdivided_bubble_lines = ();
10034: %responsetype_per_response = ();
1.691 raeburn 10035: %masterseq_id_responsenum = ();
1.554 raeburn 10036:
1.447 foxr 10037: my $response_number = 0;
10038: my $bubble_line = 0;
1.191 albertel 10039: foreach my $resource (@resources) {
1.691 raeburn 10040: my $resid = $resource->id();
1.672 raeburn 10041: my ($analysis,$parts) = &scantron_partids_tograde($resource,$cid,$uname,
10042: $udom,undef,$bubbles_per_row);
1.542 raeburn 10043: if ((ref($analysis) eq 'HASH') && (ref($parts) eq 'ARRAY')) {
10044: foreach my $part_id (@{$parts}) {
10045: my $lines;
10046:
10047: # TODO - make this a persistent hash not an array.
10048:
10049: # optionresponse, matchresponse and rankresponse type items
10050: # render as separate sub-questions in exam mode.
10051: if (($analysis->{$part_id.'.type'} eq 'optionresponse') ||
10052: ($analysis->{$part_id.'.type'} eq 'matchresponse') ||
10053: ($analysis->{$part_id.'.type'} eq 'rankresponse')) {
10054: my ($numbub,$numshown);
10055: if ($analysis->{$part_id.'.type'} eq 'optionresponse') {
10056: if (ref($analysis->{$part_id.'.options'}) eq 'ARRAY') {
10057: $numbub = scalar(@{$analysis->{$part_id.'.options'}});
10058: }
10059: } elsif ($analysis->{$part_id.'.type'} eq 'matchresponse') {
10060: if (ref($analysis->{$part_id.'.items'}) eq 'ARRAY') {
10061: $numbub = scalar(@{$analysis->{$part_id.'.items'}});
10062: }
10063: } elsif ($analysis->{$part_id.'.type'} eq 'rankresponse') {
10064: if (ref($analysis->{$part_id.'.foils'}) eq 'ARRAY') {
10065: $numbub = scalar(@{$analysis->{$part_id.'.foils'}});
10066: }
10067: }
10068: if (ref($analysis->{$part_id.'.shown'}) eq 'ARRAY') {
10069: $numshown = scalar(@{$analysis->{$part_id.'.shown'}});
10070: }
1.649 raeburn 10071: my $bubbles_per_row =
10072: &bubblesheet_bubbles_per_row($scantron_config);
10073: my $inner_bubble_lines = int($numbub/$bubbles_per_row);
10074: if (($numbub % $bubbles_per_row) != 0) {
1.542 raeburn 10075: $inner_bubble_lines++;
10076: }
10077: for (my $i=0; $i<$numshown; $i++) {
10078: $subdivided_bubble_lines{$response_number} .=
10079: $inner_bubble_lines.',';
10080: }
10081: $subdivided_bubble_lines{$response_number} =~ s/,$//;
10082: $lines = $numshown * $inner_bubble_lines;
10083: } else {
10084: $lines = $analysis->{"$part_id.bubble_lines"};
1.649 raeburn 10085: }
1.542 raeburn 10086:
10087: $first_bubble_line{$response_number} = $bubble_line;
10088: $bubble_lines_per_response{$response_number} = $lines;
10089: $responsetype_per_response{$response_number} =
10090: $analysis->{$part_id.'.type'};
1.691 raeburn 10091: $masterseq_id_responsenum{$resid.'_'.$part_id} = $response_number;
1.542 raeburn 10092: $response_number++;
10093:
10094: $bubble_line += $lines;
10095: $total_lines += $lines;
10096: }
10097: }
10098: }
1.552 raeburn 10099: &Apache::lonnet::delenv('scantron.');
1.542 raeburn 10100:
10101: &save_bubble_lines();
10102: $env{'form.scantron_maxbubble'} =
10103: $total_lines;
10104: return $env{'form.scantron_maxbubble'};
10105: }
1.523 raeburn 10106:
1.649 raeburn 10107: sub bubblesheet_bubbles_per_row {
10108: my ($scantron_config) = @_;
10109: my $bubbles_per_row;
10110: if (ref($scantron_config) eq 'HASH') {
10111: $bubbles_per_row = $scantron_config->{'BubblesPerRow'};
10112: }
10113: if ((!$bubbles_per_row) || ($bubbles_per_row < 1)) {
10114: $bubbles_per_row = 10;
10115: }
10116: return $bubbles_per_row;
10117: }
10118:
1.157 albertel 10119: sub scantron_validate_missingbubbles {
10120: my ($r,$currentphase) = @_;
10121: #get student info
10122: my $classlist=&Apache::loncoursedata::get_classlist();
10123: my %idmap=&username_to_idmap($classlist);
1.691 raeburn 10124: my (undef,undef,$sequence)=
10125: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.157 albertel 10126:
10127: #get scantron line setup
1.754 raeburn 10128: my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.157 albertel 10129: my ($scanlines,$scan_data)=&scantron_getfile();
1.691 raeburn 10130:
10131: my $navmap = Apache::lonnavmaps::navmap->new();
10132: unless (ref($navmap)) {
10133: $r->print(&navmap_errormsg());
10134: return(1,$currentphase);
10135: }
10136:
10137: my $map=$navmap->getResourceByUrl($sequence);
10138: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
10139: my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
10140: %grader_randomlists_by_symb,%orderedforcode,%respnumlookup,%startline);
10141: my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
10142:
1.582 raeburn 10143: my $nav_error;
1.691 raeburn 10144: if (ref($map)) {
10145: $randomorder = $map->randomorder();
10146: $randompick = $map->randompick();
1.788 raeburn 10147: unless ($randomorder || $randompick) {
10148: foreach my $res ($navmap->retrieveResources($map,sub { $_[0]->is_map() },1,0,1)) {
10149: if ($res->randomorder()) {
10150: $randomorder = 1;
10151: }
10152: if ($res->randompick()) {
10153: $randompick = 1;
10154: }
10155: last if ($randomorder || $randompick);
10156: }
10157: }
1.691 raeburn 10158: if ($randomorder || $randompick) {
10159: $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource);
10160: if ($nav_error) {
10161: $r->print(&navmap_errormsg());
10162: return(1,$currentphase);
10163: }
10164: &graders_resources_pass(\@resources,\%grader_partids_by_symb,
10165: \%grader_randomlists_by_symb,$bubbles_per_row);
10166: }
10167: } else {
10168: $r->print(&navmap_errormsg());
10169: return(1,$currentphase);
10170: }
10171:
10172:
1.649 raeburn 10173: my $max_bubble=&scantron_get_maxbubble(\$nav_error,\%scantron_config);
1.582 raeburn 10174: if ($nav_error) {
1.691 raeburn 10175: $r->print(&navmap_errormsg());
1.693 raeburn 10176: return(1,$currentphase);
1.582 raeburn 10177: }
1.691 raeburn 10178:
1.157 albertel 10179: if (!$max_bubble) { $max_bubble=2**31; }
10180: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 10181: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 10182: if ($line=~/^[\s\cz]*$/) { next; }
1.691 raeburn 10183: my $scan_record =
10184: &scantron_parse_scanline($line,$i,\%scantron_config,$scan_data,undef,\%idmap,
10185: $randomorder,$randompick,$sequence,\@master_seq,
10186: \%symb_to_resource,\%grader_partids_by_symb,
10187: \%orderedforcode,\%respnumlookup,\%startline);
1.157 albertel 10188: if (!defined($$scan_record{'scantron.missingerror'})) { next; }
10189: my @to_correct;
1.470 foxr 10190:
10191: # Probably here's where the error is...
10192:
1.157 albertel 10193: foreach my $missing (@{$$scan_record{'scantron.missingerror'}}) {
1.505 raeburn 10194: my $lastbubble;
10195: if ($missing =~ /^(\d+)\.(\d+)$/) {
10196: my $question = $1;
10197: my $subquestion = $2;
1.691 raeburn 10198: my ($first,$responsenum);
10199: if ($randomorder || $randompick) {
10200: $responsenum = $respnumlookup{$question-1};
10201: $first = $startline{$question-1};
10202: } else {
10203: $responsenum = $question-1;
10204: $first = $first_bubble_line{$responsenum};
10205: }
10206: if (!defined($first)) { next; }
10207: my @subans = split(/,/,$subdivided_bubble_lines{$responsenum});
1.505 raeburn 10208: my $subcount = 1;
10209: while ($subcount<$subquestion) {
10210: $first += $subans[$subcount-1];
10211: $subcount ++;
10212: }
10213: my $count = $subans[$subquestion-1];
10214: $lastbubble = $first + $count;
10215: } else {
1.691 raeburn 10216: my ($first,$responsenum);
10217: if ($randomorder || $randompick) {
10218: $responsenum = $respnumlookup{$missing-1};
10219: $first = $startline{$missing-1};
10220: } else {
10221: $responsenum = $missing-1;
10222: $first = $first_bubble_line{$responsenum};
10223: }
10224: if (!defined($first)) { next; }
10225: $lastbubble = $first + $bubble_lines_per_response{$responsenum};
1.505 raeburn 10226: }
10227: if ($lastbubble > $max_bubble) { next; }
1.157 albertel 10228: push(@to_correct,$missing);
10229: }
10230: if (@to_correct) {
10231: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
1.691 raeburn 10232: $line,'missingbubble',\@to_correct,
10233: $randomorder,$randompick,\%respnumlookup,
10234: \%startline);
1.157 albertel 10235: return (1,$currentphase);
10236: }
10237:
10238: }
10239: return (0,$currentphase+1);
10240: }
10241:
1.663 raeburn 10242: sub hand_bubble_option {
10243: my (undef, undef, $sequence) =
10244: &Apache::lonnet::decode_symb($env{'form.selectpage'});
10245: return if ($sequence eq '');
10246: my $navmap = Apache::lonnavmaps::navmap->new();
10247: unless (ref($navmap)) {
10248: return;
10249: }
10250: my $needs_hand_bubbles;
10251: my $map=$navmap->getResourceByUrl($sequence);
10252: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
10253: foreach my $res (@resources) {
10254: if (ref($res)) {
10255: if ($res->is_problem()) {
10256: my $partlist = $res->parts();
10257: foreach my $part (@{ $partlist }) {
10258: my @types = $res->responseType($part);
10259: if (grep(/^(chem|essay|image|formula|math|string|functionplot)$/,@types)) {
10260: $needs_hand_bubbles = 1;
10261: last;
10262: }
10263: }
10264: }
10265: }
10266: }
10267: if ($needs_hand_bubbles) {
1.754 raeburn 10268: my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.663 raeburn 10269: my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
10270: return &mt('The sequence to be graded contains response types which are handgraded.').'<p>'.
10271: &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 />').
10272: '<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 10273: '<label><input type="radio" name="scantron_lastbubblepoints" value="0" />'.&mt('0 points').'</label></p>';
1.663 raeburn 10274: }
10275: return;
10276: }
1.423 albertel 10277:
1.82 albertel 10278: sub scantron_process_students {
1.608 www 10279: my ($r,$symb) = @_;
1.513 foxr 10280:
1.257 albertel 10281: my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($env{'form.selectpage'});
1.513 foxr 10282: if (!$symb) {
10283: return '';
10284: }
1.324 albertel 10285: my $default_form_data=&defaultFormData($symb);
1.82 albertel 10286:
1.754 raeburn 10287: my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.691 raeburn 10288: my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
1.157 albertel 10289: my ($scanlines,$scan_data)=&scantron_getfile();
1.82 albertel 10290: my $classlist=&Apache::loncoursedata::get_classlist();
10291: my %idmap=&username_to_idmap($classlist);
1.132 bowersj2 10292: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 10293: unless (ref($navmap)) {
10294: $r->print(&navmap_errormsg());
10295: return '';
1.691 raeburn 10296: }
1.83 albertel 10297: my $map=$navmap->getResourceByUrl($sequence);
1.691 raeburn 10298: my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
1.788 raeburn 10299: %grader_randomlists_by_symb,%symb_for_examcode);
1.677 raeburn 10300: if (ref($map)) {
10301: $randomorder = $map->randomorder();
1.689 raeburn 10302: $randompick = $map->randompick();
1.788 raeburn 10303: unless ($randomorder || $randompick) {
10304: foreach my $res ($navmap->retrieveResources($map,sub { $_[0]->is_map() },1,0,1)) {
10305: if ($res->randomorder()) {
10306: $randomorder = 1;
10307: }
10308: if ($res->randompick()) {
10309: $randompick = 1;
10310: }
10311: last if ($randomorder || $randompick);
10312: }
10313: }
1.691 raeburn 10314: } else {
10315: $r->print(&navmap_errormsg());
10316: return '';
1.677 raeburn 10317: }
1.691 raeburn 10318: my $nav_error;
1.83 albertel 10319: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.691 raeburn 10320: if ($randomorder || $randompick) {
1.788 raeburn 10321: $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource,1,\%symb_for_examcode);
1.691 raeburn 10322: if ($nav_error) {
10323: $r->print(&navmap_errormsg());
10324: return '';
10325: }
10326: }
1.557 raeburn 10327: &graders_resources_pass(\@resources,\%grader_partids_by_symb,
1.649 raeburn 10328: \%grader_randomlists_by_symb,$bubbles_per_row);
1.557 raeburn 10329:
1.554 raeburn 10330: my ($uname,$udom);
1.82 albertel 10331: my $result= <<SCANTRONFORM;
1.81 albertel 10332: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
10333: <input type="hidden" name="command" value="scantron_configphase" />
10334: $default_form_data
10335: SCANTRONFORM
1.82 albertel 10336: $r->print($result);
10337:
1.770 raeburn 10338: my ($checksec,@possibles)=&gradable_sections();
1.82 albertel 10339: my @delayqueue;
1.542 raeburn 10340: my (%completedstudents,%scandata);
1.770 raeburn 10341:
1.520 www 10342: my $lock=&Apache::lonnet::set_lock(&mt('Grading bubblesheet exam'));
1.200 albertel 10343: my $count=&get_todo_count($scanlines,$scan_data);
1.667 www 10344: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$count);
10345: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,'Processing first student');
1.542 raeburn 10346: $r->print('<br />');
1.140 albertel 10347: my $start=&Time::HiRes::time();
1.158 albertel 10348: my $i=-1;
1.542 raeburn 10349: my $started;
1.447 foxr 10350:
1.649 raeburn 10351: &scantron_get_maxbubble(\$nav_error,\%scantron_config); # Need the bubble lines array to parse.
1.582 raeburn 10352: if ($nav_error) {
10353: $r->print(&navmap_errormsg());
10354: return '';
10355: }
10356:
1.513 foxr 10357: # If an ssi failed in scantron_get_maxbubble, put an error message out to
10358: # the user and return.
10359:
10360: if ($ssi_error) {
10361: $r->print("</form>");
10362: &ssi_print_error($r);
1.520 www 10363: &Apache::lonnet::remove_lock($lock);
1.513 foxr 10364: return ''; # Dunno why the other returns return '' rather than just returning.
10365: }
1.447 foxr 10366:
1.755 raeburn 10367: my %lettdig = &Apache::lonnet::letter_to_digits();
1.542 raeburn 10368: my $numletts = scalar(keys(%lettdig));
1.691 raeburn 10369: my %orderedforcode;
1.542 raeburn 10370:
1.157 albertel 10371: while ($i<$scanlines->{'count'}) {
10372: ($uname,$udom)=('','');
10373: $i++;
1.200 albertel 10374: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 10375: if ($line=~/^[\s\cz]*$/) { next; }
1.200 albertel 10376: if ($started) {
1.667 www 10377: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student');
1.200 albertel 10378: }
10379: $started=1;
1.691 raeburn 10380: my %respnumlookup = ();
10381: my %startline = ();
10382: my $total;
1.157 albertel 10383: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
1.691 raeburn 10384: $scan_data,undef,\%idmap,$randomorder,
10385: $randompick,$sequence,\@master_seq,
10386: \%symb_to_resource,\%grader_partids_by_symb,
10387: \%orderedforcode,\%respnumlookup,\%startline,
10388: \$total);
1.157 albertel 10389: unless ($uname=&scantron_find_student($scan_record,$scan_data,
10390: \%idmap,$i)) {
10391: &scantron_add_delay(\@delayqueue,$line,
10392: 'Unable to find a student that matches',1);
10393: next;
10394: }
10395: if (exists $completedstudents{$uname}) {
10396: &scantron_add_delay(\@delayqueue,$line,
10397: 'Student '.$uname.' has multiple sheets',2);
10398: next;
10399: }
1.677 raeburn 10400: my $usec = $classlist->{$uname}->[&Apache::loncoursedata::CL_SECTION];
1.770 raeburn 10401: if (($checksec ne '') && ($checksec ne $usec)) {
10402: unless (grep(/^\Q$usec\E$/,@possibles)) {
10403: &scantron_add_delay(\@delayqueue,$line,
10404: "No role with manage grades privilege in student's section ($usec)",3);
10405: next;
10406: }
10407: }
1.677 raeburn 10408: my $user = $uname.':'.$usec;
1.157 albertel 10409: ($uname,$udom)=split(/:/,$uname);
1.330 albertel 10410:
1.677 raeburn 10411: my $scancode;
10412: if ((exists($scan_record->{'scantron.CODE'})) &&
10413: (&Apache::lonnet::validCODE($scan_record->{'scantron.CODE'}))) {
10414: $scancode = $scan_record->{'scantron.CODE'};
10415: } else {
10416: $scancode = '';
10417: }
10418:
10419: my @mapresources = @resources;
1.689 raeburn 10420: if ($randomorder || $randompick) {
1.678 raeburn 10421: @mapresources =
1.691 raeburn 10422: &users_order($user,$scancode,$sequence,\@master_seq,\%symb_to_resource,
10423: \%orderedforcode);
1.677 raeburn 10424: }
1.586 raeburn 10425: my (%partids_by_symb,$res_error);
1.677 raeburn 10426: foreach my $resource (@mapresources) {
1.586 raeburn 10427: my $ressymb;
10428: if (ref($resource)) {
10429: $ressymb = $resource->symb();
10430: } else {
10431: $res_error = 1;
10432: last;
10433: }
1.557 raeburn 10434: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
10435: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
1.741 raeburn 10436: my $currcode;
10437: if (exists($grader_randomlists_by_symb{$ressymb})) {
10438: $currcode = $scancode;
10439: }
1.557 raeburn 10440: my ($analysis,$parts) =
1.672 raeburn 10441: &scantron_partids_tograde($resource,$env{'request.course.id'},
1.741 raeburn 10442: $uname,$udom,undef,$bubbles_per_row,
10443: $currcode);
1.557 raeburn 10444: $partids_by_symb{$ressymb} = $parts;
10445: } else {
10446: $partids_by_symb{$ressymb} = $grader_partids_by_symb{$ressymb};
10447: }
1.554 raeburn 10448: }
10449:
1.586 raeburn 10450: if ($res_error) {
10451: &scantron_add_delay(\@delayqueue,$line,
10452: 'An error occurred while grading student '.$uname,2);
10453: next;
10454: }
10455:
1.330 albertel 10456: &Apache::lonxml::clear_problem_counter();
1.514 raeburn 10457: &Apache::lonnet::appenv($scan_record);
1.376 albertel 10458:
10459: if (&scantron_clear_skip($scanlines,$scan_data,$i)) {
10460: &scantron_putfile($scanlines,$scan_data);
10461: }
1.161 albertel 10462:
1.542 raeburn 10463: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
1.677 raeburn 10464: \@mapresources,\%partids_by_symb,
1.691 raeburn 10465: $bubbles_per_row,$randomorder,$randompick,
10466: \%respnumlookup,\%startline)
10467: eq 'ssi_error') {
1.542 raeburn 10468: $ssi_error = 0; # So end of handler error message does not trigger.
10469: $r->print("</form>");
10470: &ssi_print_error($r);
10471: &Apache::lonnet::remove_lock($lock);
10472: return ''; # Why return ''? Beats me.
10473: }
1.513 foxr 10474:
1.692 raeburn 10475: if (($scancode) && ($randomorder || $randompick)) {
1.788 raeburn 10476: foreach my $key (keys(%symb_for_examcode)) {
10477: my $symb_in_map = $symb_for_examcode{$key};
10478: if ($symb_in_map ne '') {
10479: my $parmresult =
10480: &Apache::lonparmset::storeparm_by_symb($symb_in_map,
10481: '0_examcode',2,$scancode,
10482: 'string_examcode',$uname,
10483: $udom);
10484: }
10485: }
1.692 raeburn 10486: }
1.140 albertel 10487: $completedstudents{$uname}={'line'=>$line};
1.542 raeburn 10488: if ($env{'form.verifyrecord'}) {
10489: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
1.691 raeburn 10490: if ($randompick) {
10491: if ($total) {
10492: $lastpos = $total*$scantron_config{'Qlength'};
10493: }
10494: }
10495:
1.542 raeburn 10496: my $studentdata = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
10497: chomp($studentdata);
10498: $studentdata =~ s/\r$//;
10499: my $studentrecord = '';
10500: my $counter = -1;
1.677 raeburn 10501: foreach my $resource (@mapresources) {
1.554 raeburn 10502: my $ressymb = $resource->symb();
1.542 raeburn 10503: ($counter,my $recording) =
10504: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 10505: $counter,$studentdata,$partids_by_symb{$ressymb},
1.691 raeburn 10506: \%scantron_config,\%lettdig,$numletts,$randomorder,
10507: $randompick,\%respnumlookup,\%startline);
1.542 raeburn 10508: $studentrecord .= $recording;
10509: }
10510: if ($studentrecord ne $studentdata) {
1.554 raeburn 10511: &Apache::lonxml::clear_problem_counter();
10512: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
1.677 raeburn 10513: \@mapresources,\%partids_by_symb,
1.691 raeburn 10514: $bubbles_per_row,$randomorder,$randompick,
10515: \%respnumlookup,\%startline)
10516: eq 'ssi_error') {
1.554 raeburn 10517: $ssi_error = 0; # So end of handler error message does not trigger.
10518: $r->print("</form>");
10519: &ssi_print_error($r);
10520: &Apache::lonnet::remove_lock($lock);
10521: delete($completedstudents{$uname});
10522: return '';
10523: }
1.542 raeburn 10524: $counter = -1;
10525: $studentrecord = '';
1.677 raeburn 10526: foreach my $resource (@mapresources) {
1.554 raeburn 10527: my $ressymb = $resource->symb();
1.542 raeburn 10528: ($counter,my $recording) =
10529: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 10530: $counter,$studentdata,$partids_by_symb{$ressymb},
1.691 raeburn 10531: \%scantron_config,\%lettdig,$numletts,
10532: $randomorder,$randompick,\%respnumlookup,
10533: \%startline);
1.542 raeburn 10534: $studentrecord .= $recording;
10535: }
10536: if ($studentrecord ne $studentdata) {
1.658 bisitz 10537: $r->print('<p><span class="LC_warning">');
1.542 raeburn 10538: if ($scancode eq '') {
1.658 bisitz 10539: $r->print(&mt('Mismatch grading bubblesheet for user: [_1] with ID: [_2].',
1.542 raeburn 10540: $uname.':'.$udom,$scan_record->{'scantron.ID'}));
10541: } else {
1.658 bisitz 10542: $r->print(&mt('Mismatch grading bubblesheet for user: [_1] with ID: [_2] and CODE: [_3].',
1.542 raeburn 10543: $uname.':'.$udom,$scan_record->{'scantron.ID'},$scancode));
10544: }
10545: $r->print('</span><br />'.&Apache::loncommon::start_data_table()."\n".
10546: &Apache::loncommon::start_data_table_header_row()."\n".
10547: '<th>'.&mt('Source').'</th><th>'.&mt('Bubbled responses').'</th>'.
10548: &Apache::loncommon::end_data_table_header_row()."\n".
10549: &Apache::loncommon::start_data_table_row().
1.658 bisitz 10550: '<td>'.&mt('Bubblesheet').'</td>'.
1.707 bisitz 10551: '<td><span class="LC_nobreak" style="white-space: pre;"><tt>'.$studentdata.'</tt></span></td>'.
1.542 raeburn 10552: &Apache::loncommon::end_data_table_row().
10553: &Apache::loncommon::start_data_table_row().
1.658 bisitz 10554: '<td>'.&mt('Stored submissions').'</td>'.
1.707 bisitz 10555: '<td><span class="LC_nobreak" style="white-space: pre;"><tt>'.$studentrecord.'</tt></span></td>'."\n".
1.542 raeburn 10556: &Apache::loncommon::end_data_table_row().
10557: &Apache::loncommon::end_data_table().'</p>');
10558: } else {
10559: $r->print('<br /><span class="LC_warning">'.
10560: &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 />'.
10561: &mt("As a consequence, this user's submission history records two tries.").
10562: '</span><br />');
10563: }
10564: }
10565: }
1.543 raeburn 10566: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.140 albertel 10567: } continue {
1.330 albertel 10568: &Apache::lonxml::clear_problem_counter();
1.552 raeburn 10569: &Apache::lonnet::delenv('scantron.');
1.82 albertel 10570: }
1.140 albertel 10571: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.520 www 10572: &Apache::lonnet::remove_lock($lock);
1.172 albertel 10573: # my $lasttime = &Time::HiRes::time()-$start;
10574: # $r->print("<p>took $lasttime</p>");
1.140 albertel 10575:
1.200 albertel 10576: $r->print("</form>");
1.157 albertel 10577: return '';
1.75 albertel 10578: }
1.157 albertel 10579:
1.557 raeburn 10580: sub graders_resources_pass {
1.649 raeburn 10581: my ($resources,$grader_partids_by_symb,$grader_randomlists_by_symb,
10582: $bubbles_per_row) = @_;
1.557 raeburn 10583: if ((ref($resources) eq 'ARRAY') && (ref($grader_partids_by_symb)) &&
10584: (ref($grader_randomlists_by_symb) eq 'HASH')) {
10585: foreach my $resource (@{$resources}) {
10586: my $ressymb = $resource->symb();
10587: my ($analysis,$parts) =
10588: &scantron_partids_tograde($resource,$env{'request.course.id'},
1.672 raeburn 10589: $env{'user.name'},$env{'user.domain'},
10590: 1,$bubbles_per_row);
1.557 raeburn 10591: $grader_partids_by_symb->{$ressymb} = $parts;
10592: if (ref($analysis) eq 'HASH') {
10593: if (ref($analysis->{'parts_withrandomlist'}) eq 'ARRAY') {
10594: $grader_randomlists_by_symb->{$ressymb} =
10595: $analysis->{'parts_withrandomlist'};
10596: }
10597: }
10598: }
10599: }
10600: return;
10601: }
10602:
1.678 raeburn 10603: =pod
10604:
10605: =item users_order
10606:
10607: Returns array of resources in current map, ordered based on either CODE,
10608: if this is a CODEd exam, or based on student's identity if this is a
10609: "NAMEd" exam.
10610:
1.691 raeburn 10611: Should be used when randomorder and/or randompick applied when the
10612: corresponding exam was printed, prior to students completing bubblesheets
10613: for the version of the exam the student received.
1.678 raeburn 10614:
10615: =cut
10616:
10617: sub users_order {
1.691 raeburn 10618: my ($user,$scancode,$mapurl,$master_seq,$symb_to_resource,$orderedforcode) = @_;
1.678 raeburn 10619: my @mapresources;
1.691 raeburn 10620: unless ((ref($master_seq) eq 'ARRAY') && (ref($symb_to_resource) eq 'HASH')) {
1.678 raeburn 10621: return @mapresources;
1.691 raeburn 10622: }
10623: if ($scancode) {
10624: if ((ref($orderedforcode) eq 'HASH') && (ref($orderedforcode->{$scancode}) eq 'ARRAY')) {
10625: @mapresources = @{$orderedforcode->{$scancode}};
10626: } else {
10627: $env{'form.CODE'} = $scancode;
10628: my $actual_seq =
10629: &Apache::lonprintout::master_seq_to_person_seq($mapurl,
10630: $master_seq,
10631: $user,$scancode,1);
10632: if (ref($actual_seq) eq 'ARRAY') {
10633: @mapresources = map { $symb_to_resource->{$_}; } @{$actual_seq};
10634: if (ref($orderedforcode) eq 'HASH') {
10635: if (@mapresources > 0) {
10636: $orderedforcode->{$scancode} = \@mapresources;
10637: }
10638: }
10639: }
10640: delete($env{'form.CODE'});
1.678 raeburn 10641: }
10642: } else {
10643: my $actual_seq =
10644: &Apache::lonprintout::master_seq_to_person_seq($mapurl,
10645: $master_seq,
1.688 raeburn 10646: $user,undef,1);
1.678 raeburn 10647: if (ref($actual_seq) eq 'ARRAY') {
10648: @mapresources =
10649: map { $symb_to_resource->{$_}; } @{$actual_seq};
10650: }
1.691 raeburn 10651: }
10652: return @mapresources;
1.678 raeburn 10653: }
10654:
1.542 raeburn 10655: sub grade_student_bubbles {
1.691 raeburn 10656: my ($r,$uname,$udom,$scan_record,$scancode,$resources,$parts,$bubbles_per_row,
10657: $randomorder,$randompick,$respnumlookup,$startline) = @_;
10658: my $uselookup = 0;
10659: if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH') &&
10660: (ref($startline) eq 'HASH')) {
10661: $uselookup = 1;
10662: }
10663:
1.554 raeburn 10664: if (ref($resources) eq 'ARRAY') {
10665: my $count = 0;
10666: foreach my $resource (@{$resources}) {
10667: my $ressymb = $resource->symb();
10668: my %form = ('submitted' => 'scantron',
10669: 'grade_target' => 'grade',
10670: 'grade_username' => $uname,
10671: 'grade_domain' => $udom,
10672: 'grade_courseid' => $env{'request.course.id'},
10673: 'grade_symb' => $ressymb,
10674: 'CODE' => $scancode
10675: );
1.649 raeburn 10676: if ($bubbles_per_row ne '') {
10677: $form{'bubbles_per_row'} = $bubbles_per_row;
10678: }
1.663 raeburn 10679: if ($env{'form.scantron_lastbubblepoints'} ne '') {
10680: $form{'scantron_lastbubblepoints'} = $env{'form.scantron_lastbubblepoints'};
10681: }
1.554 raeburn 10682: if (ref($parts) eq 'HASH') {
10683: if (ref($parts->{$ressymb}) eq 'ARRAY') {
10684: foreach my $part (@{$parts->{$ressymb}}) {
1.691 raeburn 10685: if ($uselookup) {
10686: $form{'scantron_questnum_start.'.$part} = $startline->{$count} + 1;
10687: } else {
10688: $form{'scantron_questnum_start.'.$part} =
10689: 1+$env{'form.scantron.first_bubble_line.'.$count};
10690: }
1.554 raeburn 10691: $count++;
10692: }
10693: }
10694: }
10695: my $result=&ssi_with_retries($resource->src(),$ssi_retries,%form);
10696: return 'ssi_error' if ($ssi_error);
10697: last if (&Apache::loncommon::connection_aborted($r));
10698: }
1.542 raeburn 10699: }
10700: return;
10701: }
10702:
1.157 albertel 10703: sub scantron_upload_scantron_data {
1.767 raeburn 10704: my ($r,$symb) = @_;
1.565 raeburn 10705: my $dom = $env{'request.role.domain'};
1.754 raeburn 10706: my ($formatoptions,$formattitle,$formatjs) = &scantron_upload_dataformat($dom);
1.565 raeburn 10707: my $domdesc = &Apache::lonnet::domain($dom,'description');
10708: $r->print(&Apache::loncommon::coursebrowser_javascript($dom));
1.157 albertel 10709: my $select_link=&Apache::loncommon::selectcourse_link('rules','courseid',
1.181 albertel 10710: 'domainid',
1.565 raeburn 10711: 'coursename',$dom);
10712: my $syllabuslink = '<a href="javascript:ToSyllabus();">'.&mt('Syllabus').'</a>'.
10713: (' 'x2).&mt('(shows course personnel)');
1.608 www 10714: my $default_form_data=&defaultFormData($symb);
1.579 raeburn 10715: my $nofile_alert = &mt('Please use the browse button to select a file from your local directory.');
1.736 damieng 10716: &js_escape(\$nofile_alert);
1.579 raeburn 10717: 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 10718: &js_escape(\$nocourseid_alert);
1.597 wenzelju 10719: $r->print(&Apache::lonhtmlcommon::scripttag('
1.157 albertel 10720: function checkUpload(formname) {
10721: if (formname.upfile.value == "") {
1.579 raeburn 10722: alert("'.$nofile_alert.'");
1.157 albertel 10723: return false;
10724: }
1.565 raeburn 10725: if (formname.courseid.value == "") {
1.579 raeburn 10726: alert("'.$nocourseid_alert.'");
1.565 raeburn 10727: return false;
10728: }
1.157 albertel 10729: formname.submit();
10730: }
1.565 raeburn 10731:
10732: function ToSyllabus() {
10733: var cdom = '."'$dom'".';
10734: var cnum = document.rules.courseid.value;
10735: if (cdom == "" || cdom == null) {
10736: return;
10737: }
10738: if (cnum == "" || cnum == null) {
10739: return;
10740: }
10741: syllwin=window.open("/public/"+cdom+"/"+cnum+"/syllabus","LONCAPASyllabus",
10742: "height=350,width=350,scrollbars=yes,menubar=no");
10743: return;
10744: }
10745:
1.754 raeburn 10746: '.$formatjs.'
1.597 wenzelju 10747: '));
10748: $r->print('
1.648 bisitz 10749: <h3>'.&mt('Send bubblesheet data to a course').'</h3>
1.566 raeburn 10750:
1.492 albertel 10751: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
1.565 raeburn 10752: '.$default_form_data.
10753: &Apache::lonhtmlcommon::start_pick_box().
10754: &Apache::lonhtmlcommon::row_title(&mt('Course ID')).
10755: '<input name="courseid" type="text" size="30" />'.$select_link.
10756: &Apache::lonhtmlcommon::row_closure().
10757: &Apache::lonhtmlcommon::row_title(&mt('Course Name')).
10758: '<input name="coursename" type="text" size="30" />'.$syllabuslink.
10759: &Apache::lonhtmlcommon::row_closure().
10760: &Apache::lonhtmlcommon::row_title(&mt('Domain')).
10761: '<input name="domainid" type="hidden" />'.$domdesc.
1.754 raeburn 10762: &Apache::lonhtmlcommon::row_closure());
10763: if ($formatoptions) {
10764: $r->print(&Apache::lonhtmlcommon::row_title($formattitle).$formatoptions.
10765: &Apache::lonhtmlcommon::row_closure());
10766: }
10767: $r->print(
1.565 raeburn 10768: &Apache::lonhtmlcommon::row_title(&mt('File to upload')).
10769: '<input type="file" name="upfile" size="50" />'.
10770: &Apache::lonhtmlcommon::row_closure(1).
10771: &Apache::lonhtmlcommon::end_pick_box().'<br />
10772:
1.492 albertel 10773: <input name="command" value="scantronupload_save" type="hidden" />
1.589 bisitz 10774: <input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
1.157 albertel 10775: </form>
1.492 albertel 10776: ');
1.157 albertel 10777: return '';
10778: }
10779:
1.754 raeburn 10780: sub scantron_upload_dataformat {
10781: my ($dom) = @_;
10782: my ($formatoptions,$formattitle,$formatjs);
10783: $formatjs = <<'END';
10784: function toggleScantab(form) {
10785: return;
10786: }
10787: END
10788: my %domconfig = &Apache::lonnet::get_dom('configuration',['scantron'],$dom);
10789: if (ref($domconfig{'scantron'}) eq 'HASH') {
10790: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
10791: if (keys(%{$domconfig{'scantron'}{'config'}}) > 1) {
10792: if (($domconfig{'scantron'}{'config'}{'dat'}) &&
10793: (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH')) {
1.756 raeburn 10794: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
10795: if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}})) {
10796: my ($onclick,$formatextra,$singleline);
10797: my @lines = &Apache::lonnet::get_scantronformat_file();
10798: my $count = 0;
10799: foreach my $line (@lines) {
1.790 raeburn 10800: next if (($line =~ /^\#/) || ($line eq ''));
1.756 raeburn 10801: $singleline = $line;
10802: $count ++;
10803: }
10804: if ($count > 1) {
10805: $formatextra = '<div style="display:none" id="bubbletype">'.
1.757 raeburn 10806: '<span class="LC_nobreak">'.
1.776 raeburn 10807: &mt('Bubblesheet type').': '.
1.757 raeburn 10808: &scantron_scantab().'</span></div>';
1.756 raeburn 10809: $onclick = ' onclick="toggleScantab(this.form);"';
10810: $formatjs = <<"END";
1.754 raeburn 10811: function toggleScantab(form) {
10812: var divid = 'bubbletype';
10813: if (document.getElementById(divid)) {
10814: var radioname = 'fileformat';
10815: var num = form.elements[radioname].length;
10816: if (num) {
10817: for (var i=0; i<num; i++) {
10818: if (form.elements[radioname][i].checked) {
10819: var chosen = form.elements[radioname][i].value;
10820: if (chosen == 'dat') {
10821: document.getElementById(divid).style.display = 'none';
10822: } else if (chosen == 'csv') {
1.757 raeburn 10823: document.getElementById(divid).style.display = 'block';
1.754 raeburn 10824: }
10825: }
10826: }
10827: }
10828: }
10829: return;
10830: }
10831:
10832: END
1.756 raeburn 10833: } elsif ($count == 1) {
10834: my $formatname = (split(/:/,$singleline,2))[0];
10835: $formatextra = '<input type="hidden" name="scantron_format" value="'.$formatname.'" />';
10836: }
10837: $formattitle = &mt('File format');
10838: $formatoptions = '<label><input name="fileformat" type="radio" value="dat" checked="checked"'.$onclick.' />'.
10839: &mt('Plain Text (no delimiters)').
10840: '</label>'.(' 'x2).
10841: '<label><input name="fileformat" type="radio" value="csv"'.$onclick.' />'.
10842: &mt('Comma separated values').'</label>'.$formatextra;
1.754 raeburn 10843: }
10844: }
10845: }
10846: } elsif (keys(%{$domconfig{'scantron'}{'config'}}) == 1) {
1.756 raeburn 10847: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
10848: if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}})) {
1.757 raeburn 10849: $formattitle = &mt('Bubblesheet type');
1.756 raeburn 10850: $formatoptions = &scantron_scantab();
10851: }
1.754 raeburn 10852: }
10853: }
10854: }
10855: }
10856: return ($formatoptions,$formattitle,$formatjs);
10857: }
1.423 albertel 10858:
1.157 albertel 10859: sub scantron_upload_scantron_data_save {
1.767 raeburn 10860: my ($r,$symb) = @_;
1.182 albertel 10861: my $doanotherupload=
10862: '<br /><form action="/adm/grades" method="post">'."\n".
10863: '<input type="hidden" name="command" value="scantronupload" />'."\n".
1.492 albertel 10864: '<input type="submit" name="submit" value="'.&mt('Do Another Upload').'" />'."\n".
1.182 albertel 10865: '</form>'."\n";
1.257 albertel 10866: if (!&Apache::lonnet::allowed('usc',$env{'form.domainid'}) &&
1.162 albertel 10867: !&Apache::lonnet::allowed('usc',
1.770 raeburn 10868: $env{'form.domainid'}.'_'.$env{'form.courseid'}) &&
10869: !&Apache::lonnet::allowed('usc',
10870: $env{'form.domainid'}.'_'.$env{'form.courseid'}.'/'.$env{'form.coursesec'})) {
1.575 www 10871: $r->print(&mt("You are not allowed to upload bubblesheet data to the requested course.")."<br />");
1.614 www 10872: unless ($symb) {
1.182 albertel 10873: $r->print($doanotherupload);
10874: }
1.162 albertel 10875: return '';
10876: }
1.257 albertel 10877: my %coursedata=&Apache::lonnet::coursedescription($env{'form.domainid'}.'_'.$env{'form.courseid'});
1.568 raeburn 10878: my $uploadedfile;
1.710 bisitz 10879: $r->print('<p>'.&mt('Uploading file to [_1]','"'.$coursedata{'description'}.'"').'</p>');
1.257 albertel 10880: if (length($env{'form.upfile'}) < 2) {
1.710 bisitz 10881: $r->print(
10882: &Apache::lonhtmlcommon::confirm_success(
10883: &mt('The file: [_1] you attempted to upload contained no information. Please check that you entered the correct filename.',
10884: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'),1));
1.183 albertel 10885: } else {
1.754 raeburn 10886: my %domconfig = &Apache::lonnet::get_dom('configuration',['scantron'],$env{'form.domainid'});
10887: my $parser;
10888: if (ref($domconfig{'scantron'}) eq 'HASH') {
10889: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
10890: my $is_csv;
10891: my @possibles = keys(%{$domconfig{'scantron'}{'config'}});
10892: if (@possibles > 1) {
10893: if ($env{'form.fileformat'} eq 'csv') {
10894: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.756 raeburn 10895: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
10896: if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}}) > 1) {
10897: $is_csv = 1;
10898: }
1.754 raeburn 10899: }
10900: }
10901: }
10902: } elsif (@possibles == 1) {
10903: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.756 raeburn 10904: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
10905: if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}}) > 1) {
10906: $is_csv = 1;
10907: }
1.754 raeburn 10908: }
10909: }
10910: }
10911: if ($is_csv) {
10912: $parser = $domconfig{'scantron'}{'config'}{'csv'};
10913: }
10914: }
10915: }
10916: my $result =
10917: &Apache::lonnet::userfileupload('upfile','scantron','scantron',$parser,'','',
1.568 raeburn 10918: $env{'form.courseid'},$env{'form.domainid'});
1.710 bisitz 10919: if ($result =~ m{^/uploaded/}) {
10920: $r->print(
10921: &Apache::lonhtmlcommon::confirm_success(&mt('Upload successful')).'<br />'.
10922: &mt('Uploaded [_1] bytes of data into location: [_2]',
10923: (length($env{'form.upfile'})-1),
10924: '<span class="LC_filename">'.$result.'</span>'));
1.568 raeburn 10925: ($uploadedfile) = ($result =~ m{/([^/]+)$});
1.770 raeburn 10926: if ($uploadedfile =~ /^scantron_orig_/) {
10927: my $logname = $uploadedfile;
10928: $logname =~ s/^scantron_orig_//;
10929: if ($logname ne '') {
10930: my $now = time;
10931: my %info = ($logname => { $now => $env{'user.name'}.':'.$env{'user.domain'} });
10932: &Apache::lonnet::put('scantronupload',\%info,$env{'form.domainid'},$env{'form.courseid'});
10933: }
10934: }
1.567 raeburn 10935: $r->print(&validate_uploaded_scantron_file($env{'form.domainid'},
1.770 raeburn 10936: $env{'form.courseid'},$symb,$uploadedfile));
1.710 bisitz 10937: } else {
10938: $r->print(
10939: &Apache::lonhtmlcommon::confirm_success(&mt('Upload failed'),1).'<br />'.
10940: &mt('An error ([_1]) occurred when attempting to upload the file: [_2]',
10941: $result,
1.568 raeburn 10942: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'));
1.183 albertel 10943: }
10944: }
1.174 albertel 10945: if ($symb) {
1.612 www 10946: $r->print(&scantron_selectphase($r,$uploadedfile,$symb));
1.174 albertel 10947: } else {
1.182 albertel 10948: $r->print($doanotherupload);
1.174 albertel 10949: }
1.157 albertel 10950: return '';
10951: }
10952:
1.567 raeburn 10953: sub validate_uploaded_scantron_file {
1.770 raeburn 10954: my ($cdom,$cname,$symb,$fname,$context,$countsref) = @_;
10955:
1.567 raeburn 10956: my $scanlines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.$fname);
10957: my @lines;
10958: if ($scanlines ne '-1') {
10959: @lines=split("\n",$scanlines,-1);
10960: }
1.770 raeburn 10961: my ($output,$secidx,$checksec,$priv,%crsroleshash,@possibles);
10962: $secidx = &Apache::loncoursedata::CL_SECTION();
10963: if ($context eq 'download') {
10964: $priv = 'mgr';
10965: } else {
10966: $priv = 'usc';
10967: }
10968: unless ((&Apache::lonnet::allowed($priv,$env{'request.role.domain'})) ||
10969: (($env{'request.course.id'}) &&
10970: (&Apache::lonnet::allowed($priv,$env{'request.course.id'})))) {
10971: if ($env{'request.course.sec'} ne '') {
10972: unless (&Apache::lonnet::allowed($priv,
10973: "$env{'request.course.id'}/$env{'request.course.sec'}")) {
10974: unless ($context eq 'download') {
10975: $output = '<p class="LC_warning">'.&mt('You do not have permission to upload bubblesheet data').'</p>';
10976: }
10977: return $output;
10978: }
10979: ($checksec,@possibles)=&gradable_sections();
10980: }
10981: }
1.567 raeburn 10982: if (@lines) {
10983: my (%counts,$max_match_format);
1.710 bisitz 10984: my ($found_match_count,$max_match_count,$max_match_pct) = (0,0,0);
1.567 raeburn 10985: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cname);
10986: my %idmap = &username_to_idmap($classlist);
10987: foreach my $key (keys(%idmap)) {
10988: my $lckey = lc($key);
10989: $idmap{$lckey} = $idmap{$key};
10990: }
10991: my %unique_formats;
1.754 raeburn 10992: my @formatlines = &Apache::lonnet::get_scantronformat_file();
1.567 raeburn 10993: foreach my $line (@formatlines) {
1.790 raeburn 10994: next if (($line =~ /^\#/) || ($line eq ''));
1.567 raeburn 10995: my @config = split(/:/,$line);
10996: my $idstart = $config[5];
10997: my $idlength = $config[6];
10998: if (($idstart ne '') && ($idlength > 0)) {
10999: if (ref($unique_formats{$idstart.':'.$idlength}) eq 'ARRAY') {
11000: push(@{$unique_formats{$idstart.':'.$idlength}},$config[0].':'.$config[1]);
11001: } else {
11002: $unique_formats{$idstart.':'.$idlength} = [$config[0].':'.$config[1]];
11003: }
11004: }
11005: }
11006: foreach my $key (keys(%unique_formats)) {
11007: my ($idstart,$idlength) = split(':',$key);
11008: %{$counts{$key}} = (
11009: 'found' => 0,
11010: 'total' => 0,
1.770 raeburn 11011: 'totalanysec' => 0,
11012: 'othersec' => 0,
1.567 raeburn 11013: );
11014: foreach my $line (@lines) {
11015: next if ($line =~ /^#/);
11016: next if ($line =~ /^[\s\cz]*$/);
11017: my $id = substr($line,$idstart-1,$idlength);
11018: $id = lc($id);
11019: if (exists($idmap{$id})) {
1.770 raeburn 11020: if ($checksec ne '') {
11021: $counts{$key}{'totalanysec'} ++;
11022: if (ref($classlist->{$idmap{$id}}) eq 'ARRAY') {
11023: my $stusec = $classlist->{$idmap{$id}}->[$secidx];
11024: if ($stusec ne $checksec) {
11025: if (@possibles) {
11026: unless (grep(/^\Q$stusec\E$/,@possibles)) {
11027: $counts{$key}{'othersec'} ++;
11028: next;
11029: }
11030: } else {
11031: $counts{$key}{'othersec'} ++;
11032: next;
11033: }
11034: }
11035: }
11036: }
1.567 raeburn 11037: $counts{$key}{'found'} ++;
11038: }
11039: $counts{$key}{'total'} ++;
11040: }
11041: if ($counts{$key}{'total'}) {
11042: my $percent_match = (100*$counts{$key}{'found'})/($counts{$key}{'total'});
11043: if (($max_match_format eq '') || ($percent_match > $max_match_pct)) {
11044: $max_match_pct = $percent_match;
11045: $max_match_format = $key;
1.710 bisitz 11046: $found_match_count = $counts{$key}{'found'};
1.567 raeburn 11047: $max_match_count = $counts{$key}{'total'};
11048: }
11049: }
11050: }
1.770 raeburn 11051: if ((ref($unique_formats{$max_match_format}) eq 'ARRAY') && ($context ne 'download')) {
1.567 raeburn 11052: my $format_descs;
11053: my $numwithformat = @{$unique_formats{$max_match_format}};
11054: for (my $i=0; $i<$numwithformat; $i++) {
11055: my ($name,$desc) = split(':',$unique_formats{$max_match_format}[$i]);
11056: if ($i<$numwithformat-2) {
11057: $format_descs .= '"<i>'.$desc.'</i>", ';
11058: } elsif ($i==$numwithformat-2) {
11059: $format_descs .= '"<i>'.$desc.'</i>" '.&mt('and').' ';
11060: } elsif ($i==$numwithformat-1) {
11061: $format_descs .= '"<i>'.$desc.'</i>"';
11062: }
11063: }
11064: my $showpct = sprintf("%.0f",$max_match_pct).'%';
1.710 bisitz 11065: $output .= '<br />';
11066: if ($found_match_count == $max_match_count) {
11067: # 100% matching entries
11068: $output .= &Apache::lonhtmlcommon::confirm_success(
11069: &mt('Comparison of student IDs: [_1] matching ([quant,_2,entry,entries])',
11070: '<b>'.$showpct.'</b>',$found_match_count)).'<br />'.
11071: &mt('Comparison of student IDs in the uploaded file with'.
11072: ' the course roster found matches for [_1] of the [_2] entries'.
11073: ' in the file (for the format defined for [_3]).',
11074: '<b>'.$showpct.'</b>','<b>'.$max_match_count.'</b>',$format_descs);
11075: } else {
11076: # Not all entries matching? -> Show warning and additional info
11077: $output .=
11078: &Apache::lonhtmlcommon::confirm_success(
11079: &mt('Comparison of student IDs: [_1] matching ([_2]/[quant,_3,entry,entries])',
11080: '<b>'.$showpct.'</b>',$found_match_count,$max_match_count).'<br />'.
11081: &mt('Not all entries could be matched!'),1).'<br />'.
11082: &mt('Comparison of student IDs in the uploaded file with'.
11083: ' the course roster found matches for [_1] of the [_2] entries'.
11084: ' in the file (for the format defined for [_3]).',
11085: '<b>'.$showpct.'</b>','<b>'.$max_match_count.'</b>',$format_descs).
11086: '<p class="LC_info">'.
11087: &mt('A low percentage of matches results from one of the following:').
11088: '</p><ul>'.
11089: '<li>'.&mt('The file was uploaded to the wrong course.').'</li>'.
11090: '<li>'.&mt('The data is not in the format expected for the domain: [_1]',
11091: '<i>'.$cdom.'</i>').'</li>'.
11092: '<li>'.&mt('Students did not bubble their IDs, or mis-bubbled them').'</li>'.
11093: '<li>'.&mt('The course roster is not up to date.').'</li>'.
11094: '</ul>';
11095: }
1.770 raeburn 11096: if (($checksec ne '') && (ref($counts{$max_match_format}) eq 'HASH')) {
11097: if ($counts{$max_match_format}{'othersec'}) {
11098: my $percent_nongrade = (100*$counts{$max_match_format}{'othersec'})/($counts{$max_match_format}{'totalanysec'});
11099: my $showpct = sprintf("%.0f",$percent_nongrade).'%';
11100: my $confirmdel = &mt('Are you sure you want to permanently delete this file?');
11101: &js_escape(\$confirmdel);
11102: $output .= '<p class="LC_warning">'.
11103: &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',
11104: '<b>',$counts{$max_match_format}{'othersec'},'</b>').
11105: '<br />'.
11106: &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>').
11107: '</p><p>'.
11108: &mt('If you prefer to delete the file now, use: [_1]').
11109: '<form method="post" name="delupload" action="/adm/grades">'.
11110: '<input type="hidden" name="symb" value="'.$symb.'" />'.
11111: '<input type="hidden" name="domainid" value="'.$cdom.'" />'.
11112: '<input type="hidden" name="courseid" value="'.$cname.'" />'.
11113: '<input type="hidden" name="coursesec" value="'.$env{'request.course.sec'}.'" />'.
11114: '<input type="hidden" name="uploadedfile" value="'.$fname.'" />'.
11115: '<input type="hidden" name="command" value="scantronupload_delete" />'.
11116: '<input type="button" name="delbutton" value="'.&mt('Delete Uploaded File').'" onclick="javascript:if (confirm('."'$confirmdel'".')) { document.delupload.submit(); }" />'.
11117: '</form></p>';
11118: }
11119: }
1.567 raeburn 11120: }
1.770 raeburn 11121: if (($context eq 'download') && ($checksec ne '')) {
11122: if ((ref($countsref) eq 'HASH') && (ref($counts{$max_match_format}) eq 'HASH')) {
11123: $countsref->{'totalanysec'} = $counts{$max_match_format}{'totalanysec'};
11124: $countsref->{'othersec'} = $counts{$max_match_format}{'othersec'};
11125: }
11126: }
11127: } elsif ($context ne 'download') {
1.710 bisitz 11128: $output = '<p class="LC_warning">'.&mt('Uploaded file contained no data').'</p>';
1.567 raeburn 11129: }
11130: return $output;
11131: }
11132:
1.770 raeburn 11133: sub gradable_sections {
11134: my $checksec = $env{'request.course.sec'};
11135: my @oksecs;
11136: if ($checksec) {
11137: my %availablesecs = §ions_grade_privs();
11138: if (ref($availablesecs{'mgr'}) eq 'ARRAY') {
11139: foreach my $sec (@{$availablesecs{'mgr'}}) {
11140: unless (grep(/^\Q$sec\E$/,@oksecs)) {
11141: push(@oksecs,$sec);
11142: }
11143: }
11144: if (grep(/^all$/,@oksecs)) {
11145: undef($checksec);
11146: }
11147: }
11148: }
11149: return($checksec,@oksecs);
11150: }
11151:
11152: sub sections_grade_privs {
11153: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11154: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
11155: my %availablesecs = (
11156: mgr => [],
11157: vgr => [],
11158: usc => [],
11159: );
11160: my $ccrole = 'cc';
11161: if ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Community') {
11162: $ccrole = 'co';
11163: }
11164: my %crsroleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},
11165: 'userroles',['active'],
11166: [$ccrole,'in','cr'],$cdom,1);
11167: my $crsid = $cnum.':'.$cdom;
11168: foreach my $item (keys(%crsroleshash)) {
11169: next unless ($item =~ /^$crsid\:/);
11170: my ($crsnum,$crsdom,$role,$sec) = split(/\:/,$item);
11171: my $suffix = "/$cdom/$cnum./$cdom/$cnum";
11172: if ($sec ne '') {
11173: $suffix = "/$cdom/$cnum/$sec./$cdom/$cnum/$sec";
11174: }
11175: if (($role eq $ccrole) || ($role eq 'in')) {
11176: foreach my $priv ('mgr','vgr','usc') {
11177: unless (grep(/^all$/,@{$availablesecs{$priv}})) {
11178: if ($sec eq '') {
11179: $availablesecs{$priv} = ['all'];
11180: } elsif ($sec ne $env{'request.course.sec'}) {
11181: unless (grep(/^\Q$sec\E$/,@{$availablesecs{$priv}})) {
11182: push(@{$availablesecs{$priv}},$sec);
11183: }
11184: }
11185: }
11186: }
11187: } elsif ($role =~ m{^cr/}) {
11188: foreach my $priv ('mgr','vgr','usc') {
11189: unless (grep(/^all$/,@{$availablesecs{$priv}})) {
11190: if ($env{"user.priv.$role.$suffix"} =~ /:$priv&/) {
11191: if ($sec eq '') {
11192: $availablesecs{$priv} = ['all'];
11193: } elsif ($sec ne $env{'request.course.sec'}) {
11194: unless (grep(/^\Q$sec\E$/,@{$availablesecs{$priv}})) {
11195: push(@{$availablesecs{$priv}},$sec);
11196: }
11197: }
11198: }
11199: }
11200: }
11201: }
11202: }
11203: return %availablesecs;
11204: }
11205:
11206: sub scantron_upload_delete {
11207: my ($r,$symb) = @_;
11208: my $filename = $env{'form.uploadedfile'};
11209: if ($filename =~ /^scantron_orig_/) {
11210: if (&Apache::lonnet::allowed('usc',$env{'form.domainid'}) ||
11211: &Apache::lonnet::allowed('usc',
11212: $env{'form.domainid'}.'_'.$env{'form.courseid'}) ||
11213: &Apache::lonnet::allowed('usc',
11214: $env{'form.domainid'}.'_'.$env{'form.courseid'}.'/'.$env{'form.coursesec'})) {
11215: my $uploadurl = '/uploaded/'.$env{'form.domainid'}.'/'.$env{'form.courseid'}.'/'.$env{'form.uploadedfile'};
11216: my $retrieval = &Apache::lonnet::getfile($uploadurl);
11217: if ($retrieval eq '-1') {
11218: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('File deletion failed'),1).'<br />'.
11219: &mt('File requested for deletion not found.'));
11220: } else {
11221: $filename =~ s/^scantron_orig_//;
11222: if ($filename ne '') {
11223: my ($is_valid,$numleft);
11224: my %info = &Apache::lonnet::get('scantronupload',[$filename],$env{'form.domainid'},$env{'form.courseid'});
11225: if (keys(%info)) {
11226: if (ref($info{$filename}) eq 'HASH') {
11227: foreach my $timestamp (sort(keys(%{$info{$filename}}))) {
11228: if ($info{$filename}{$timestamp} eq $env{'user.name'}.':'.$env{'user.domain'}) {
11229: $is_valid = 1;
11230: delete($info{$filename}{$timestamp});
11231: }
11232: }
11233: $numleft = scalar(keys(%{$info{$filename}}));
11234: }
11235: }
11236: if ($is_valid) {
11237: my $result = &Apache::lonnet::removeuploadedurl($uploadurl);
11238: if ($result eq 'ok') {
11239: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('File deletion successful')).'<br />');
11240: if ($numleft) {
11241: &Apache::lonnet::put('scantronupload',\%info,$env{'form.domainid'},$env{'form.courseid'});
11242: } else {
11243: &Apache::lonnet::del('scantronupload',[$filename],$env{'form.domainid'},$env{'form.courseid'});
11244: }
11245: } else {
11246: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('File deletion failed'),1).'<br />'.
11247: &mt('Result was [_1]',$result));
11248: }
11249: } else {
11250: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('File deletion failed'),1).'<br />'.
11251: &mt('File requested for deletion was uploaded by a different user.'));
11252: }
11253: } else {
11254: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('File deletion failed'),1).'<br />'.
11255: &mt('Filename of bubblesheet data file requested for deletion is invalid.'));
11256: }
11257: }
11258: } else {
11259: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('File deletion failed'),1).'<br />'.
11260: &mt('You are not permitted to delete bubblesheet data files from the requested course.'));
11261: }
11262: } else {
11263: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('File deletion failed'),1).'<br />'.
11264: &mt('Filename of bubblesheet data file requested for deletion is invalid.'));
11265: }
11266: return;
11267: }
11268:
1.202 albertel 11269: sub valid_file {
11270: my ($requested_file)=@_;
11271: foreach my $filename (sort(&scantron_filenames())) {
11272: if ($requested_file eq $filename) { return 1; }
11273: }
11274: return 0;
11275: }
11276:
11277: sub scantron_download_scantron_data {
1.767 raeburn 11278: my ($r,$symb) = @_;
1.608 www 11279: my $default_form_data=&defaultFormData($symb);
1.257 albertel 11280: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
11281: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
11282: my $file=$env{'form.scantron_selectfile'};
1.202 albertel 11283: if (! &valid_file($file)) {
1.492 albertel 11284: $r->print('
1.202 albertel 11285: <p>
1.686 bisitz 11286: '.&mt('The requested filename was invalid.').'
1.202 albertel 11287: </p>
1.492 albertel 11288: ');
1.202 albertel 11289: return;
11290: }
1.770 raeburn 11291: my (%uploader,$is_owner,%counts,$percent);
11292: my %uploader = &Apache::lonnet::get('scantronupload',[$file],$cdom,$cname);
11293: if (ref($uploader{$file}) eq 'HASH') {
11294: foreach my $timestamp (sort { $a <=> $b } keys(%{$uploader{$file}})) {
11295: if ($uploader{$file}{$timestamp} eq $env{'user.name'}.':'.$env{'user.domain'}) {
11296: $is_owner = 1;
11297: last;
11298: }
11299: }
11300: }
11301: unless ($is_owner) {
11302: &validate_uploaded_scantron_file($cdom,$cname,$symb,'scantron_orig_'.$file,'download',\%counts);
11303: if ($counts{'totalanysec'}) {
11304: my $percent_othersec = (100*$counts{'othersec'})/($counts{'totalanysec'});
11305: if ($percent_othersec >= 10) {
11306: my $showpct = sprintf("%.0f",$percent_othersec).'%';
11307: $r->print('<p class="LC_warning">'.
11308: &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).
11309: '</p>');
11310: return;
11311: }
11312: }
11313: }
1.202 albertel 11314: my $orig='/uploaded/'.$cdom.'/'.$cname.'/scantron_orig_'.$file;
11315: my $corrected='/uploaded/'.$cdom.'/'.$cname.'/scantron_corrected_'.$file;
11316: my $skipped='/uploaded/'.$cdom.'/'.$cname.'/scantron_skipped_'.$file;
11317: &Apache::lonnet::allowuploaded('/adm/grades',$orig);
11318: &Apache::lonnet::allowuploaded('/adm/grades',$corrected);
11319: &Apache::lonnet::allowuploaded('/adm/grades',$skipped);
1.492 albertel 11320: $r->print('
1.202 albertel 11321: <p>
1.723 raeburn 11322: '.&mt('[_1]Original[_2] file as uploaded by the bubblesheet scanning office.',
1.492 albertel 11323: '<a href="'.$orig.'">','</a>').'
1.202 albertel 11324: </p>
11325: <p>
1.492 albertel 11326: '.&mt('[_1]Corrections[_2], a file of corrected records that were used in grading.',
11327: '<a href="'.$corrected.'">','</a>').'
1.202 albertel 11328: </p>
11329: <p>
1.492 albertel 11330: '.&mt('[_1]Skipped[_2], a file of records that were skipped.',
11331: '<a href="'.$skipped.'">','</a>').'
1.202 albertel 11332: </p>
1.492 albertel 11333: ');
1.202 albertel 11334: return '';
11335: }
1.157 albertel 11336:
1.523 raeburn 11337: sub checkscantron_results {
1.608 www 11338: my ($r,$symb) = @_;
1.523 raeburn 11339: if (!$symb) {return '';}
11340: my $cid = $env{'request.course.id'};
1.755 raeburn 11341: my %lettdig = &Apache::lonnet::letter_to_digits();
1.523 raeburn 11342: my $numletts = scalar(keys(%lettdig));
11343: my $cnum = $env{'course.'.$cid.'.num'};
11344: my $cdom = $env{'course.'.$cid.'.domain'};
11345: my (undef, undef, $sequence) = &Apache::lonnet::decode_symb($env{'form.selectpage'});
11346: my %record;
11347: my %scantron_config =
1.754 raeburn 11348: &Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.649 raeburn 11349: my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
1.770 raeburn 11350: my ($scanlines,$scan_data)=&scantron_getfile();
1.523 raeburn 11351: my $classlist=&Apache::loncoursedata::get_classlist();
11352: my %idmap=&Apache::grades::username_to_idmap($classlist);
11353: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 11354: unless (ref($navmap)) {
11355: $r->print(&navmap_errormsg());
11356: return '';
11357: }
1.523 raeburn 11358: my $map=$navmap->getResourceByUrl($sequence);
1.691 raeburn 11359: my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
11360: %grader_randomlists_by_symb,%orderedforcode);
1.677 raeburn 11361: if (ref($map)) {
11362: $randomorder=$map->randomorder();
1.689 raeburn 11363: $randompick=$map->randompick();
1.788 raeburn 11364: unless ($randomorder || $randompick) {
11365: foreach my $res ($navmap->retrieveResources($map,sub { $_[0]->is_map() },1,0,1)) {
11366: if ($res->randomorder()) {
11367: $randomorder = 1;
11368: }
11369: if ($res->randompick()) {
11370: $randompick = 1;
11371: }
11372: last if ($randomorder || $randompick);
11373: }
11374: }
1.677 raeburn 11375: }
1.557 raeburn 11376: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.691 raeburn 11377: my $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource);
11378: if ($nav_error) {
11379: $r->print(&navmap_errormsg());
11380: return '';
1.678 raeburn 11381: }
1.673 raeburn 11382: &graders_resources_pass(\@resources,\%grader_partids_by_symb,
11383: \%grader_randomlists_by_symb,$bubbles_per_row);
1.554 raeburn 11384: my ($uname,$udom);
1.523 raeburn 11385: my (%scandata,%lastname,%bylast);
11386: $r->print('
11387: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="checkscantron">'."\n");
11388:
11389: my @delayqueue;
11390: my %completedstudents;
11391:
1.691 raeburn 11392: my $count=&get_todo_count($scanlines,$scan_data);
1.667 www 11393: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$count);
1.706 raeburn 11394: my ($username,$domain,$started);
1.649 raeburn 11395: &scantron_get_maxbubble(\$nav_error,\%scantron_config); # Need the bubble lines array to parse.
1.582 raeburn 11396: if ($nav_error) {
11397: $r->print(&navmap_errormsg());
11398: return '';
11399: }
1.523 raeburn 11400:
1.667 www 11401: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,'Processing first student');
1.523 raeburn 11402: my $start=&Time::HiRes::time();
11403: my $i=-1;
11404:
11405: while ($i<$scanlines->{'count'}) {
11406: ($username,$domain,$uname)=('','','');
11407: $i++;
11408: my $line=&Apache::grades::scantron_get_line($scanlines,$scan_data,$i);
11409: if ($line=~/^[\s\cz]*$/) { next; }
11410: if ($started) {
1.667 www 11411: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student');
1.523 raeburn 11412: }
11413: $started=1;
11414: my $scan_record=
11415: &Apache::grades::scantron_parse_scanline($line,$i,\%scantron_config,
11416: $scan_data);
1.693 raeburn 11417: unless ($uname=&scantron_find_student($scan_record,$scan_data,
11418: \%idmap,$i)) {
1.523 raeburn 11419: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
11420: 'Unable to find a student that matches',1);
11421: next;
11422: }
11423: if (exists $completedstudents{$uname}) {
11424: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
11425: 'Student '.$uname.' has multiple sheets',2);
11426: next;
11427: }
11428: my $pid = $scan_record->{'scantron.ID'};
11429: $lastname{$pid} = $scan_record->{'scantron.LastName'};
11430: push(@{$bylast{$lastname{$pid}}},$pid);
1.678 raeburn 11431: my $usec = $classlist->{$uname}->[&Apache::loncoursedata::CL_SECTION];
11432: my $user = $uname.':'.$usec;
1.523 raeburn 11433: ($username,$domain)=split(/:/,$uname);
1.677 raeburn 11434:
1.678 raeburn 11435: my $scancode;
1.677 raeburn 11436: if ((exists($scan_record->{'scantron.CODE'})) &&
11437: (&Apache::lonnet::validCODE($scan_record->{'scantron.CODE'}))) {
11438: $scancode = $scan_record->{'scantron.CODE'};
11439: } else {
11440: $scancode = '';
11441: }
11442:
11443: my @mapresources = @resources;
1.691 raeburn 11444: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
11445: my %respnumlookup=();
11446: my %startline=();
1.689 raeburn 11447: if ($randomorder || $randompick) {
1.678 raeburn 11448: @mapresources =
1.691 raeburn 11449: &users_order($user,$scancode,$sequence,\@master_seq,\%symb_to_resource,
11450: \%orderedforcode);
11451: my $total = &get_respnum_lookups($sequence,$scan_data,\%idmap,$line,
11452: $scan_record,\@master_seq,\%symb_to_resource,
11453: \%grader_partids_by_symb,\%orderedforcode,
11454: \%respnumlookup,\%startline);
11455: if ($randompick && $total) {
11456: $lastpos = $total*$scantron_config{'Qlength'};
11457: }
1.677 raeburn 11458: }
1.691 raeburn 11459: $scandata{$pid} = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
11460: chomp($scandata{$pid});
11461: $scandata{$pid} =~ s/\r$//;
11462:
1.523 raeburn 11463: my $counter = -1;
1.677 raeburn 11464: foreach my $resource (@mapresources) {
1.557 raeburn 11465: my $parts;
1.554 raeburn 11466: my $ressymb = $resource->symb();
1.557 raeburn 11467: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
11468: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
1.741 raeburn 11469: my $currcode;
11470: if (exists($grader_randomlists_by_symb{$ressymb})) {
11471: $currcode = $scancode;
11472: }
1.557 raeburn 11473: (my $analysis,$parts) =
1.672 raeburn 11474: &scantron_partids_tograde($resource,$env{'request.course.id'},
11475: $username,$domain,undef,
1.741 raeburn 11476: $bubbles_per_row,$currcode);
1.557 raeburn 11477: } else {
11478: $parts = $grader_partids_by_symb{$ressymb};
11479: }
1.542 raeburn 11480: ($counter,my $recording) =
11481: &verify_scantron_grading($resource,$domain,$username,$cid,$counter,
1.554 raeburn 11482: $scandata{$pid},$parts,
1.691 raeburn 11483: \%scantron_config,\%lettdig,$numletts,
11484: $randomorder,$randompick,
11485: \%respnumlookup,\%startline);
1.542 raeburn 11486: $record{$pid} .= $recording;
1.523 raeburn 11487: }
11488: }
11489: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
11490: $r->print('<br />');
11491: my ($okstudents,$badstudents,$numstudents,$passed,$failed);
11492: $passed = 0;
11493: $failed = 0;
11494: $numstudents = 0;
11495: foreach my $last (sort(keys(%bylast))) {
11496: if (ref($bylast{$last}) eq 'ARRAY') {
11497: foreach my $pid (sort(@{$bylast{$last}})) {
11498: my $showscandata = $scandata{$pid};
11499: my $showrecord = $record{$pid};
11500: $showscandata =~ s/\s/ /g;
11501: $showrecord =~ s/\s/ /g;
11502: if ($scandata{$pid} eq $record{$pid}) {
11503: my $css_class = ($passed % 2)?'LC_odd_row':'LC_even_row';
11504: $okstudents .= '<tr class="'.$css_class.'">'.
1.581 www 11505: '<td>'.&mt('Bubblesheet').'</td><td>'.$showscandata.'</td><td rowspan="2">'.$last.'</td><td rowspan="2">'.$pid.'</td>'."\n".
1.523 raeburn 11506: '</tr>'."\n".
11507: '<tr class="'.$css_class.'">'."\n".
1.721 bisitz 11508: '<td>'.&mt('Submissions').'</td><td>'.$showrecord.'</td></tr>'."\n";
1.523 raeburn 11509: $passed ++;
11510: } else {
11511: my $css_class = ($failed % 2)?'LC_odd_row':'LC_even_row';
1.581 www 11512: $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 11513: '</tr>'."\n".
11514: '<tr class="'.$css_class.'">'."\n".
1.721 bisitz 11515: '<td>'.&mt('Submissions').'</td><td><span class="LC_nobreak">'.$record{$pid}.'</span></td>'."\n".
1.523 raeburn 11516: '</tr>'."\n";
11517: $failed ++;
11518: }
11519: $numstudents ++;
11520: }
11521: }
11522: }
1.648 bisitz 11523: $r->print(
11524: '<p>'
11525: .&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).',
11526: '<b>',
11527: $numstudents,
11528: '</b>',
11529: $env{'form.scantron_maxbubble'})
11530: .'</p>'
11531: );
1.682 raeburn 11532: $r->print('<p>'
1.683 raeburn 11533: .&mt('Exact matches for [_1][quant,_2,student][_3].','<b>',$passed,'</b>')
1.682 raeburn 11534: .'<br />'
11535: .&mt('Discrepancies detected for [_1][quant,_2,student][_3].','<b>',$failed,'</b>')
11536: .'</p>'
11537: );
1.523 raeburn 11538: if ($passed) {
1.572 www 11539: $r->print(&mt('Students with exact correspondence between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 11540: $r->print(&Apache::loncommon::start_data_table()."\n".
11541: &Apache::loncommon::start_data_table_header_row()."\n".
11542: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
11543: &Apache::loncommon::end_data_table_header_row()."\n".
11544: $okstudents."\n".
11545: &Apache::loncommon::end_data_table().'<br />');
11546: }
11547: if ($failed) {
1.572 www 11548: $r->print(&mt('Students with differences between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 11549: $r->print(&Apache::loncommon::start_data_table()."\n".
11550: &Apache::loncommon::start_data_table_header_row()."\n".
11551: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
11552: &Apache::loncommon::end_data_table_header_row()."\n".
11553: $badstudents."\n".
11554: &Apache::loncommon::end_data_table()).'<br />'.
1.572 www 11555: &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 11556: }
1.614 www 11557: $r->print('</form><br />');
1.523 raeburn 11558: return;
11559: }
11560:
1.542 raeburn 11561: sub verify_scantron_grading {
1.554 raeburn 11562: my ($resource,$domain,$username,$cid,$counter,$scandata,$partids,
1.691 raeburn 11563: $scantron_config,$lettdig,$numletts,$randomorder,$randompick,
11564: $respnumlookup,$startline) = @_;
1.542 raeburn 11565: my ($record,%expected,%startpos);
11566: return ($counter,$record) if (!ref($resource));
11567: return ($counter,$record) if (!$resource->is_problem());
11568: my $symb = $resource->symb();
1.554 raeburn 11569: return ($counter,$record) if (ref($partids) ne 'ARRAY');
11570: foreach my $part_id (@{$partids}) {
1.542 raeburn 11571: $counter ++;
11572: $expected{$part_id} = 0;
1.691 raeburn 11573: my $respnum = $counter;
11574: if ($randomorder || $randompick) {
11575: $respnum = $respnumlookup->{$counter};
11576: $startpos{$part_id} = $startline->{$counter} + 1;
11577: } else {
11578: $startpos{$part_id} = $env{"form.scantron.first_bubble_line.$counter"};
11579: }
11580: if ($env{"form.scantron.sub_bubblelines.$respnum"}) {
11581: my @sub_lines = split(/,/,$env{"form.scantron.sub_bubblelines.$respnum"});
1.542 raeburn 11582: foreach my $item (@sub_lines) {
11583: $expected{$part_id} += $item;
11584: }
11585: } else {
1.691 raeburn 11586: $expected{$part_id} = $env{"form.scantron.bubblelines.$respnum"};
1.542 raeburn 11587: }
11588: }
11589: if ($symb) {
11590: my %recorded;
11591: my (%returnhash) = &Apache::lonnet::restore($symb,$cid,$domain,$username);
11592: if ($returnhash{'version'}) {
11593: my %lasthash=();
11594: my $version;
11595: for ($version=1;$version<=$returnhash{'version'};$version++) {
11596: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
11597: $lasthash{$key}=$returnhash{$version.':'.$key};
11598: }
11599: }
11600: foreach my $key (keys(%lasthash)) {
11601: if ($key =~ /\.scantron$/) {
11602: my $value = &unescape($lasthash{$key});
11603: my ($part_id) = ($key =~ /^resource\.(.+)\.scantron$/);
11604: if ($value eq '') {
11605: for (my $i=0; $i<$expected{$part_id}; $i++) {
11606: for (my $j=0; $j<$scantron_config->{'length'}; $j++) {
11607: $recorded{$part_id} .= $scantron_config->{'Qoff'};
11608: }
11609: }
11610: } else {
11611: my @tocheck;
11612: my @items = split(//,$value);
11613: if (($scantron_config->{'Qon'} eq 'letter') ||
11614: ($scantron_config->{'Qon'} eq 'number')) {
11615: if (@items < $expected{$part_id}) {
11616: my $fragment = substr($scandata,$startpos{$part_id},$expected{$part_id});
11617: my @singles = split(//,$fragment);
11618: foreach my $pos (@singles) {
11619: if ($pos eq ' ') {
11620: push(@tocheck,$pos);
11621: } else {
11622: my $next = shift(@items);
11623: push(@tocheck,$next);
11624: }
11625: }
11626: } else {
11627: @tocheck = @items;
11628: }
11629: foreach my $letter (@tocheck) {
11630: if ($scantron_config->{'Qon'} eq 'letter') {
11631: if ($letter !~ /^[A-J]$/) {
11632: $letter = $scantron_config->{'Qoff'};
11633: }
11634: $recorded{$part_id} .= $letter;
11635: } elsif ($scantron_config->{'Qon'} eq 'number') {
11636: my $digit;
11637: if ($letter !~ /^[A-J]$/) {
11638: $digit = $scantron_config->{'Qoff'};
11639: } else {
11640: $digit = $lettdig->{$letter};
11641: }
11642: $recorded{$part_id} .= $digit;
11643: }
11644: }
11645: } else {
11646: @tocheck = @items;
11647: for (my $i=0; $i<$expected{$part_id}; $i++) {
11648: my $curr_sub = shift(@tocheck);
11649: my $digit;
11650: if ($curr_sub =~ /^[A-J]$/) {
11651: $digit = $lettdig->{$curr_sub}-1;
11652: }
11653: if ($curr_sub eq 'J') {
11654: $digit += scalar($numletts);
11655: }
11656: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
11657: if ($j == $digit) {
11658: $recorded{$part_id} .= $scantron_config->{'Qon'};
11659: } else {
11660: $recorded{$part_id} .= $scantron_config->{'Qoff'};
11661: }
11662: }
11663: }
11664: }
11665: }
11666: }
11667: }
11668: }
1.554 raeburn 11669: foreach my $part_id (@{$partids}) {
1.542 raeburn 11670: if ($recorded{$part_id} eq '') {
11671: for (my $i=0; $i<$expected{$part_id}; $i++) {
11672: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
11673: $recorded{$part_id} .= $scantron_config->{'Qoff'};
11674: }
11675: }
11676: }
11677: $record .= $recorded{$part_id};
11678: }
11679: }
11680: return ($counter,$record);
11681: }
11682:
1.75 albertel 11683: #-------- end of section for handling grading scantron forms -------
11684: #
11685: #-------------------------------------------------------------------
11686:
1.72 ng 11687: #-------------------------- Menu interface -------------------------
11688: #
1.614 www 11689: #--- Href with symb and command ---
11690:
11691: sub href_symb_cmd {
11692: my ($symb,$cmd)=@_;
1.796 raeburn 11693: return '/adm/grades?symb='.&HTML::Entities::encode(&Apache::lonenc::check_encrypt($symb),'<>&"').'&command='.
11694: &HTML::Entities::encode($cmd,'<>&"');
1.72 ng 11695: }
11696:
1.443 banghart 11697: sub grading_menu {
1.608 www 11698: my ($request,$symb) = @_;
1.443 banghart 11699: if (!$symb) {return '';}
11700:
11701: my %fields = ('symb'=>&Apache::lonenc::check_encrypt($symb),
1.618 www 11702: 'command'=>'individual');
1.538 schulted 11703:
1.598 www 11704: my $url1a = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
11705:
11706: $fields{'command'}='ungraded';
11707: my $url1b=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
11708:
11709: $fields{'command'}='table';
11710: my $url1c=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
11711:
11712: $fields{'command'}='all_for_one';
11713: my $url1d=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
11714:
1.621 www 11715: $fields{'command'}='downloadfilesselect';
11716: my $url1e=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
11717:
1.443 banghart 11718: $fields{'command'} = 'csvform';
1.538 schulted 11719: my $url2 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
11720:
1.443 banghart 11721: $fields{'command'} = 'processclicker';
1.538 schulted 11722: my $url3 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
11723:
1.443 banghart 11724: $fields{'command'} = 'scantron_selectphase';
1.538 schulted 11725: my $url4 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
1.602 www 11726:
11727: $fields{'command'} = 'initialverifyreceipt';
11728: my $url5 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
1.780 raeburn 11729:
11730: my %permissions;
11731: if ($perm{'mgr'}) {
11732: $permissions{'either'} = 'F';
11733: $permissions{'mgr'} = 'F';
11734: }
11735: if ($perm{'vgr'}) {
11736: $permissions{'either'} = 'F';
11737: $permissions{'vgr'} = 'F';
11738: }
11739:
1.598 www 11740: my @menu = ({ categorytitle=>'Hand Grading',
1.538 schulted 11741: items =>[
1.598 www 11742: { linktext => 'Select individual students to grade',
11743: url => $url1a,
1.781 raeburn 11744: permission => $permissions{'either'},
1.636 wenzelju 11745: icon => 'grade_students.png',
1.598 www 11746: linktitle => 'Grade current resource for a selection of students.'
11747: },
1.764 raeburn 11748: { linktext => 'Grade ungraded submissions',
1.598 www 11749: url => $url1b,
1.781 raeburn 11750: permission => $permissions{'either'},
1.636 wenzelju 11751: icon => 'ungrade_sub.png',
1.598 www 11752: linktitle => 'Grade all submissions that have not been graded yet.'
1.538 schulted 11753: },
1.598 www 11754:
11755: { linktext => 'Grading table',
11756: url => $url1c,
1.781 raeburn 11757: permission => $permissions{'either'},
1.636 wenzelju 11758: icon => 'grading_table.png',
1.598 www 11759: linktitle => 'Grade current resource for all students.'
11760: },
1.615 www 11761: { linktext => 'Grade page/folder for one student',
1.598 www 11762: url => $url1d,
1.781 raeburn 11763: permission => $permissions{'either'},
1.636 wenzelju 11764: icon => 'grade_PageFolder.png',
1.598 www 11765: linktitle => 'Grade all resources in current page/sequence/folder for one student.'
1.621 www 11766: },
11767: { linktext => 'Download submissions',
11768: url => $url1e,
1.781 raeburn 11769: permission => $permissions{'either'},
1.636 wenzelju 11770: icon => 'download_sub.png',
1.621 www 11771: linktitle => 'Download all students submissions.'
1.598 www 11772: }]},
11773: { categorytitle=>'Automated Grading',
11774: items =>[
11775:
1.538 schulted 11776: { linktext => 'Upload Scores',
11777: url => $url2,
1.780 raeburn 11778: permission => $permissions{'mgr'},
1.538 schulted 11779: icon => 'uploadscores.png',
11780: linktitle => 'Specify a file containing the class scores for current resource.'
11781: },
11782: { linktext => 'Process Clicker',
11783: url => $url3,
1.780 raeburn 11784: permission => $permissions{'mgr'},
1.538 schulted 11785: icon => 'addClickerInfoFile.png',
11786: linktitle => 'Specify a file containing the clicker information for this resource.'
11787: },
1.587 raeburn 11788: { linktext => 'Grade/Manage/Review Bubblesheets',
1.538 schulted 11789: url => $url4,
1.780 raeburn 11790: permission => $permissions{'mgr'},
1.636 wenzelju 11791: icon => 'bubblesheet.png',
1.648 bisitz 11792: linktitle => 'Grade bubblesheet exams, upload/download bubblesheet data files, and review previously graded bubblesheet exams.'
1.602 www 11793: },
1.616 www 11794: { linktext => 'Verify Receipt Number',
1.602 www 11795: url => $url5,
1.780 raeburn 11796: permission => $permissions{'either'},
1.636 wenzelju 11797: icon => 'receipt_number.png',
1.602 www 11798: linktitle => 'Verify a system-generated receipt number for correct problem solution.'
11799: }
11800:
1.538 schulted 11801: ]
11802: });
1.796 raeburn 11803: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
11804: my $cnum = $env{"course.$env{'request.course.id'}.num"};
11805: my %passback = &Apache::lonnet::dump('nohist_linkprot_passback',$cdom,$cnum);
11806: if (keys(%passback)) {
11807: $fields{'command'} = 'initialpassback';
11808: my $url6 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
11809: push (@{$menu[1]{items}},
11810: { linktext => 'Passback of Scores',
11811: url => $url6,
11812: permission => $permissions{'either'},
11813: icon => 'passback.png',
11814: linktitle => 'Passback scores to launcher CMS for resources accessed via LTI-mediated deep-linking',
11815: });
11816: }
1.443 banghart 11817: # Create the menu
11818: my $Str;
1.445 banghart 11819: $Str .= '<form method="post" action="" name="gradingMenu">';
11820: $Str .= '<input type="hidden" name="command" value="" />'.
1.618 www 11821: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.445 banghart 11822:
1.602 www 11823: $Str .= &Apache::lonhtmlcommon::generate_menu(@menu);
1.443 banghart 11824: return $Str;
11825: }
11826:
1.598 www 11827: sub ungraded {
11828: my ($request)=@_;
11829: &submit_options($request);
11830: }
11831:
1.599 www 11832: sub submit_options_sequence {
1.608 www 11833: my ($request,$symb) = @_;
1.599 www 11834: if (!$symb) {return '';}
1.600 www 11835: &commonJSfunctions($request);
11836: my $result;
1.599 www 11837:
1.600 www 11838: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.618 www 11839: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.632 www 11840: $result.=&selectfield(0).
1.601 www 11841: '<input type="hidden" name="command" value="pickStudentPage" />
1.600 www 11842: <div>
11843: <input type="submit" value="'.&mt('Next').' →" />
11844: </div>
11845: </div>
11846: </form>';
11847: return $result;
11848: }
11849:
11850: sub submit_options_table {
1.608 www 11851: my ($request,$symb) = @_;
1.600 www 11852: if (!$symb) {return '';}
1.599 www 11853: &commonJSfunctions($request);
1.746 raeburn 11854: my $is_tool = ($symb =~ /ext\.tool$/);
1.599 www 11855: my $result;
11856:
11857: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.618 www 11858: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.599 www 11859:
1.745 raeburn 11860: $result.=&selectfield(1,$is_tool).
1.601 www 11861: '<input type="hidden" name="command" value="viewgrades" />
1.599 www 11862: <div>
11863: <input type="submit" value="'.&mt('Next').' →" />
11864: </div>
11865: </div>
11866: </form>';
11867: return $result;
11868: }
1.443 banghart 11869:
1.621 www 11870: sub submit_options_download {
11871: my ($request,$symb) = @_;
11872: if (!$symb) {return '';}
11873:
1.773 raeburn 11874: my $res_error;
11875: my ($partlist,$handgrade,$responseType,$numresp,$numessay,$numdropbox) =
11876: &response_type($symb,\$res_error);
11877: if ($res_error) {
11878: $request->print(&mt('An error occurred retrieving response types'));
11879: return;
11880: }
11881: unless ($numessay) {
11882: $request->print(&mt('No essayresponse items found'));
11883: return;
11884: }
11885: my $table;
11886: if (ref($partlist) eq 'ARRAY') {
11887: if (scalar(@$partlist) > 1 ) {
11888: $table = &showResourceInfo($symb,$partlist,$responseType,'gradingMenu',1,1);
11889: }
11890: }
11891:
1.746 raeburn 11892: my $is_tool = ($symb =~ /ext\.tool$/);
1.621 www 11893: &commonJSfunctions($request);
11894:
11895: my $result='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.773 raeburn 11896: $table."\n".
11897: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.621 www 11898: $result.='
11899: <h2>
1.750 raeburn 11900: '.&mt('Select Students for whom to Download Submissions').'
1.745 raeburn 11901: </h2>'.&selectfield(1,$is_tool).'
1.621 www 11902: <input type="hidden" name="command" value="downloadfileslink" />
11903: <input type="submit" value="'.&mt('Next').' →" />
11904: </div>
11905: </div>
1.600 www 11906:
11907:
1.621 www 11908: </form>';
11909: return $result;
11910: }
11911:
1.443 banghart 11912: #--- Displays the submissions first page -------
11913: sub submit_options {
1.608 www 11914: my ($request,$symb) = @_;
1.72 ng 11915: if (!$symb) {return '';}
11916:
1.746 raeburn 11917: my $is_tool = ($symb =~ /ext\.tool$/);
1.118 ng 11918: &commonJSfunctions($request);
1.473 albertel 11919: my $result;
1.533 bisitz 11920:
1.72 ng 11921: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.618 www 11922: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.745 raeburn 11923: $result.=&selectfield(1,$is_tool).'
1.601 www 11924: <input type="hidden" name="command" value="submission" />
11925: <input type="submit" value="'.&mt('Next').' →" />
11926: </div>
11927: </div>
11928: </form>';
11929: return $result;
11930: }
1.533 bisitz 11931:
1.601 www 11932: sub selectfield {
1.745 raeburn 11933: my ($full,$is_tool)=@_;
11934: my %options;
11935: if ($is_tool) {
11936: %options =
11937: (&transtatus_options,
11938: 'select_form_order' => ['yes','incorrect','all']);
11939: } else {
11940: %options =
11941: (&substatus_options,
11942: 'select_form_order' => ['yes','queued','graded','incorrect','all']);
11943: }
1.782 raeburn 11944:
11945: #
11946: # PrepareClasslist() needs to be called to avoid getting a sections list
11947: # for a different course from the @Sections global in lonstatistics.pm,
11948: # populated by an earlier request.
11949: #
11950: &Apache::lonstatistics::PrepareClasslist();
11951:
1.601 www 11952: my $result='<div class="LC_columnSection">
1.537 harmsja 11953:
1.533 bisitz 11954: <fieldset>
11955: <legend>
11956: '.&mt('Sections').'
11957: </legend>
1.601 www 11958: '.&Apache::lonstatistics::SectionSelect('section','multiple',5).'
1.533 bisitz 11959: </fieldset>
1.537 harmsja 11960:
1.533 bisitz 11961: <fieldset>
11962: <legend>
11963: '.&mt('Groups').'
11964: </legend>
11965: '.&Apache::lonstatistics::GroupSelect('group','multiple',5).'
11966: </fieldset>
1.537 harmsja 11967:
1.533 bisitz 11968: <fieldset>
11969: <legend>
11970: '.&mt('Access Status').'
11971: </legend>
1.601 www 11972: '.&Apache::lonhtmlcommon::StatusOptions(undef,undef,5,undef,'mult').'
11973: </fieldset>';
11974: if ($full) {
1.745 raeburn 11975: my $heading = &mt('Submission Status');
11976: if ($is_tool) {
11977: $heading = &mt('Transaction Status');
11978: }
11979: $result.='
1.533 bisitz 11980: <fieldset>
11981: <legend>
1.745 raeburn 11982: '.$heading.'
1.601 www 11983: </legend>'.
1.635 raeburn 11984: &Apache::loncommon::select_form('all','submitonly',\%options).
1.601 www 11985: '</fieldset>';
11986: }
11987: $result.='</div><br />';
1.44 ng 11988: return $result;
1.2 albertel 11989: }
11990:
1.738 raeburn 11991: sub substatus_options {
11992: return &Apache::lonlocal::texthash(
11993: 'yes' => 'with submissions',
11994: 'queued' => 'in grading queue',
11995: 'graded' => 'with ungraded submissions',
11996: 'incorrect' => 'with incorrect submissions',
1.740 raeburn 11997: 'all' => 'with any status',
11998: );
1.738 raeburn 11999: }
12000:
1.745 raeburn 12001: sub transtatus_options {
12002: return &Apache::lonlocal::texthash(
12003: 'yes' => 'with score transactions',
12004: 'incorrect' => 'with less than full credit',
12005: 'all' => 'with any status',
12006: );
12007: }
12008:
1.285 albertel 12009: sub reset_perm {
12010: undef(%perm);
12011: }
12012:
12013: sub init_perm {
12014: &reset_perm();
1.770 raeburn 12015: foreach my $test_perm ('vgr','mgr','opa','usc') {
1.300 albertel 12016:
12017: my $scope = $env{'request.course.id'};
12018: if (!($perm{$test_perm}=&Apache::lonnet::allowed($test_perm,$scope))) {
12019:
12020: $scope .= '/'.$env{'request.course.sec'};
12021: if ( $perm{$test_perm}=
12022: &Apache::lonnet::allowed($test_perm,$scope)) {
12023: $perm{$test_perm.'_section'}=$env{'request.course.sec'};
12024: } else {
12025: delete($perm{$test_perm});
12026: }
1.285 albertel 12027: }
12028: }
12029: }
12030:
1.674 raeburn 12031: sub init_old_essays {
12032: my ($symb,$apath,$adom,$aname) = @_;
12033: if ($symb ne '') {
12034: my %essays = &Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
12035: if (keys(%essays) > 0) {
12036: $old_essays{$symb} = \%essays;
12037: }
12038: }
12039: return;
12040: }
12041:
12042: sub reset_old_essays {
12043: undef(%old_essays);
12044: }
12045:
1.400 www 12046: sub gather_clicker_ids {
1.408 albertel 12047: my %clicker_ids;
1.400 www 12048:
12049: my $classlist = &Apache::loncoursedata::get_classlist();
12050:
12051: # Set up a couple variables.
1.407 albertel 12052: my $username_idx = &Apache::loncoursedata::CL_SNAME();
12053: my $domain_idx = &Apache::loncoursedata::CL_SDOM();
1.438 www 12054: my $status_idx = &Apache::loncoursedata::CL_STATUS();
1.400 www 12055:
1.407 albertel 12056: foreach my $student (keys(%$classlist)) {
1.438 www 12057: if ($classlist->{$student}->[$status_idx] ne 'Active') { next; }
1.407 albertel 12058: my $username = $classlist->{$student}->[$username_idx];
12059: my $domain = $classlist->{$student}->[$domain_idx];
1.400 www 12060: my $clickers =
1.408 albertel 12061: (&Apache::lonnet::userenvironment($domain,$username,'clickers'))[1];
1.400 www 12062: foreach my $id (split(/\,/,$clickers)) {
1.414 www 12063: $id=~s/^[\#0]+//;
1.421 www 12064: $id=~s/[\-\:]//g;
1.407 albertel 12065: if (exists($clicker_ids{$id})) {
1.408 albertel 12066: $clicker_ids{$id}.=','.$username.':'.$domain;
1.400 www 12067: } else {
1.408 albertel 12068: $clicker_ids{$id}=$username.':'.$domain;
1.400 www 12069: }
12070: }
12071: }
1.407 albertel 12072: return %clicker_ids;
1.400 www 12073: }
12074:
1.402 www 12075: sub gather_adv_clicker_ids {
1.408 albertel 12076: my %clicker_ids;
1.402 www 12077: my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'};
12078: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
12079: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
1.409 albertel 12080: foreach my $element (sort(keys(%coursepersonnel))) {
1.402 www 12081: foreach my $person (split(/\,/,$coursepersonnel{$element})) {
12082: my ($puname,$pudom)=split(/\:/,$person);
12083: my $clickers =
1.408 albertel 12084: (&Apache::lonnet::userenvironment($pudom,$puname,'clickers'))[1];
1.405 www 12085: foreach my $id (split(/\,/,$clickers)) {
1.414 www 12086: $id=~s/^[\#0]+//;
1.421 www 12087: $id=~s/[\-\:]//g;
1.408 albertel 12088: if (exists($clicker_ids{$id})) {
12089: $clicker_ids{$id}.=','.$puname.':'.$pudom;
12090: } else {
12091: $clicker_ids{$id}=$puname.':'.$pudom;
12092: }
1.405 www 12093: }
1.402 www 12094: }
12095: }
1.407 albertel 12096: return %clicker_ids;
1.402 www 12097: }
12098:
1.413 www 12099: sub clicker_grading_parameters {
12100: return ('gradingmechanism' => 'scalar',
12101: 'upfiletype' => 'scalar',
12102: 'specificid' => 'scalar',
12103: 'pcorrect' => 'scalar',
12104: 'pincorrect' => 'scalar');
12105: }
12106:
1.400 www 12107: sub process_clicker {
1.608 www 12108: my ($r,$symb)=@_;
1.400 www 12109: if (!$symb) {return '';}
12110: my $result=&checkforfile_js();
1.632 www 12111: $result.=&Apache::loncommon::start_data_table().
12112: &Apache::loncommon::start_data_table_header_row().
12113: '<th>'.&mt('Specify a file containing clicker information and set grading options.').'</th>'.
12114: &Apache::loncommon::end_data_table_header_row().
12115: &Apache::loncommon::start_data_table_row()."<td>\n";
1.413 www 12116: # Attempt to restore parameters from last session, set defaults if not present
12117: my %Saveable_Parameters=&clicker_grading_parameters();
12118: &Apache::loncommon::restore_course_settings('grades_clicker',
12119: \%Saveable_Parameters);
12120: if (!$env{'form.pcorrect'}) { $env{'form.pcorrect'}=100; }
12121: if (!$env{'form.pincorrect'}) { $env{'form.pincorrect'}=100; }
12122: if (!$env{'form.gradingmechanism'}) { $env{'form.gradingmechanism'}='attendance'; }
12123: if (!$env{'form.upfiletype'}) { $env{'form.upfiletype'}='iclicker'; }
12124:
12125: my %checked;
1.521 www 12126: foreach my $gradingmechanism ('attendance','personnel','specific','given') {
1.413 www 12127: if ($env{'form.gradingmechanism'} eq $gradingmechanism) {
1.569 bisitz 12128: $checked{$gradingmechanism}=' checked="checked"';
1.413 www 12129: }
12130: }
12131:
1.632 www 12132: my $upload=&mt("Evaluate File");
1.400 www 12133: my $type=&mt("Type");
1.402 www 12134: my $attendance=&mt("Award points just for participation");
12135: my $personnel=&mt("Correctness determined from response by course personnel");
1.414 www 12136: my $specific=&mt("Correctness determined from response with clicker ID(s)");
1.521 www 12137: my $given=&mt("Correctness determined from given list of answers").' '.
12138: '<font size="-2"><tt>('.&mt("Provide comma-separated list. Use '*' for any answer correct, '-' for skip").')</tt></font>';
1.402 www 12139: my $pcorrect=&mt("Percentage points for correct solution");
12140: my $pincorrect=&mt("Percentage points for incorrect solution");
1.413 www 12141: my $selectform=&Apache::loncommon::select_form($env{'form.upfiletype'},'upfiletype',
1.635 raeburn 12142: {'iclicker' => 'i>clicker',
1.666 www 12143: 'interwrite' => 'interwrite PRS',
12144: 'turning' => 'Turning Technologies'});
1.418 albertel 12145: $symb = &Apache::lonenc::check_encrypt($symb);
1.597 wenzelju 12146: $result.= &Apache::lonhtmlcommon::scripttag(<<ENDUPFORM);
1.402 www 12147: function sanitycheck() {
12148: // Accept only integer percentages
12149: document.forms.gradesupload.pcorrect.value=Math.round(document.forms.gradesupload.pcorrect.value);
12150: document.forms.gradesupload.pincorrect.value=Math.round(document.forms.gradesupload.pincorrect.value);
12151: // Find out grading choice
12152: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
12153: if (document.forms.gradesupload.gradingmechanism[i].checked) {
12154: gradingchoice=document.forms.gradesupload.gradingmechanism[i].value;
12155: }
12156: }
12157: // By default, new choice equals user selection
12158: newgradingchoice=gradingchoice;
12159: // Not good to give more points for false answers than correct ones
12160: if (Math.round(document.forms.gradesupload.pcorrect.value)<Math.round(document.forms.gradesupload.pincorrect.value)) {
12161: document.forms.gradesupload.pcorrect.value=document.forms.gradesupload.pincorrect.value;
12162: }
12163: // If new choice is attendance only, and old choice was correctness-based, restore defaults
12164: if ((gradingchoice=='attendance') && (document.forms.gradesupload.waschecked.value!='attendance')) {
12165: document.forms.gradesupload.pcorrect.value=100;
12166: document.forms.gradesupload.pincorrect.value=100;
12167: }
12168: // If the values are different, cannot be attendance only
12169: if ((Math.round(document.forms.gradesupload.pcorrect.value)!=Math.round(document.forms.gradesupload.pincorrect.value)) &&
12170: (gradingchoice=='attendance')) {
12171: newgradingchoice='personnel';
12172: }
12173: // Change grading choice to new one
12174: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
12175: if (document.forms.gradesupload.gradingmechanism[i].value==newgradingchoice) {
12176: document.forms.gradesupload.gradingmechanism[i].checked=true;
12177: } else {
12178: document.forms.gradesupload.gradingmechanism[i].checked=false;
12179: }
12180: }
12181: // Remember the old state
12182: document.forms.gradesupload.waschecked.value=newgradingchoice;
12183: }
1.597 wenzelju 12184: ENDUPFORM
12185: $result.= <<ENDUPFORM;
1.400 www 12186: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
12187: <input type="hidden" name="symb" value="$symb" />
12188: <input type="hidden" name="command" value="processclickerfile" />
12189: <input type="file" name="upfile" size="50" />
12190: <br /><label>$type: $selectform</label>
1.632 www 12191: ENDUPFORM
12192: $result.='</td>'.&Apache::loncommon::end_data_table_row().
12193: &Apache::loncommon::start_data_table_row().'<td>'.(<<ENDGRADINGFORM);
12194: <label><input type="radio" name="gradingmechanism" value="attendance"$checked{'attendance'} onclick="sanitycheck()" />$attendance </label>
1.589 bisitz 12195: <br /><label><input type="radio" name="gradingmechanism" value="personnel"$checked{'personnel'} onclick="sanitycheck()" />$personnel</label>
12196: <br /><label><input type="radio" name="gradingmechanism" value="specific"$checked{'specific'} onclick="sanitycheck()" />$specific </label>
1.414 www 12197: <input type="text" name="specificid" value="$env{'form.specificid'}" size="20" />
1.589 bisitz 12198: <br /><label><input type="radio" name="gradingmechanism" value="given"$checked{'given'} onclick="sanitycheck()" />$given </label>
1.521 www 12199: <br />
12200: <input type="text" name="givenanswer" size="50" />
1.413 www 12201: <input type="hidden" name="waschecked" value="$env{'form.gradingmechanism'}" />
1.632 www 12202: ENDGRADINGFORM
1.766 raeburn 12203: $result.='</td>'.&Apache::loncommon::end_data_table_row().
1.632 www 12204: &Apache::loncommon::start_data_table_row().'<td>'.(<<ENDPERCFORM);
12205: <label>$pcorrect: <input type="text" name="pcorrect" size="4" value="$env{'form.pcorrect'}" onchange="sanitycheck()" /></label>
1.589 bisitz 12206: <br /><label>$pincorrect: <input type="text" name="pincorrect" size="4" value="$env{'form.pincorrect'}" onchange="sanitycheck()" /></label>
12207: <br /><input type="button" onclick="javascript:checkUpload(this.form);" value="$upload" />
1.767 raeburn 12208: </form>
1.632 www 12209: ENDPERCFORM
12210: $result.='</td>'.
12211: &Apache::loncommon::end_data_table_row().
12212: &Apache::loncommon::end_data_table();
1.400 www 12213: return $result;
12214: }
12215:
12216: sub process_clicker_file {
1.766 raeburn 12217: my ($r,$symb) = @_;
1.400 www 12218: if (!$symb) {return '';}
1.413 www 12219:
12220: my %Saveable_Parameters=&clicker_grading_parameters();
12221: &Apache::loncommon::store_course_settings('grades_clicker',
12222: \%Saveable_Parameters);
1.598 www 12223: my $result='';
1.404 www 12224: if (($env{'form.gradingmechanism'} eq 'specific') && ($env{'form.specificid'}!~/\w/)) {
1.408 albertel 12225: $result.='<span class="LC_error">'.&mt('You need to specify a clicker ID for the correct answer').'</span>';
1.614 www 12226: return $result;
1.404 www 12227: }
1.522 www 12228: if (($env{'form.gradingmechanism'} eq 'given') && ($env{'form.givenanswer'}!~/\S/)) {
1.521 www 12229: $result.='<span class="LC_error">'.&mt('You need to specify the correct answer').'</span>';
1.614 www 12230: return $result;
1.521 www 12231: }
1.522 www 12232: my $foundgiven=0;
1.521 www 12233: if ($env{'form.gradingmechanism'} eq 'given') {
12234: $env{'form.givenanswer'}=~s/^\s*//gs;
12235: $env{'form.givenanswer'}=~s/\s*$//gs;
1.644 www 12236: $env{'form.givenanswer'}=~s/[^a-zA-Z0-9\.\*\-\+]+/\,/g;
1.521 www 12237: $env{'form.givenanswer'}=uc($env{'form.givenanswer'});
1.522 www 12238: my @answers=split(/\,/,$env{'form.givenanswer'});
12239: $foundgiven=$#answers+1;
1.521 www 12240: }
1.407 albertel 12241: my %clicker_ids=&gather_clicker_ids();
1.408 albertel 12242: my %correct_ids;
1.404 www 12243: if ($env{'form.gradingmechanism'} eq 'personnel') {
1.408 albertel 12244: %correct_ids=&gather_adv_clicker_ids();
1.404 www 12245: }
12246: if ($env{'form.gradingmechanism'} eq 'specific') {
1.414 www 12247: foreach my $correct_id (split(/[\s\,]/,$env{'form.specificid'})) {;
12248: $correct_id=~tr/a-z/A-Z/;
12249: $correct_id=~s/\s//gs;
12250: $correct_id=~s/^[\#0]+//;
1.421 www 12251: $correct_id=~s/[\-\:]//g;
1.414 www 12252: if ($correct_id) {
12253: $correct_ids{$correct_id}='specified';
12254: }
12255: }
1.400 www 12256: }
1.404 www 12257: if ($env{'form.gradingmechanism'} eq 'attendance') {
1.408 albertel 12258: $result.=&mt('Score based on attendance only');
1.521 www 12259: } elsif ($env{'form.gradingmechanism'} eq 'given') {
1.522 www 12260: $result.=&mt('Score based on [_1] ([_2] answers)','<tt>'.$env{'form.givenanswer'}.'</tt>',$foundgiven);
1.404 www 12261: } else {
1.408 albertel 12262: my $number=0;
1.411 www 12263: $result.='<p><b>'.&mt('Correctness determined by the following IDs').'</b>';
1.408 albertel 12264: foreach my $id (sort(keys(%correct_ids))) {
1.411 www 12265: $result.='<br /><tt>'.$id.'</tt> - ';
1.408 albertel 12266: if ($correct_ids{$id} eq 'specified') {
12267: $result.=&mt('specified');
12268: } else {
12269: my ($uname,$udom)=split(/\:/,$correct_ids{$id});
12270: $result.=&Apache::loncommon::plainname($uname,$udom);
12271: }
12272: $number++;
12273: }
1.411 www 12274: $result.="</p>\n";
1.710 bisitz 12275: if ($number==0) {
12276: $result .=
12277: &Apache::lonhtmlcommon::confirm_success(
12278: &mt('No IDs found to determine correct answer'),1);
12279: return $result;
12280: }
1.404 www 12281: }
1.405 www 12282: if (length($env{'form.upfile'}) < 2) {
1.710 bisitz 12283: $result .=
12284: &Apache::lonhtmlcommon::confirm_success(
12285: &mt('The file: [_1] you attempted to upload contained no information. Please check that you entered the correct filename.',
12286: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'),1);
1.614 www 12287: return $result;
1.405 www 12288: }
1.760 raeburn 12289: my $mimetype;
12290: if ($env{'form.upfiletype'} eq 'iclicker') {
12291: my $mm = new File::MMagic;
12292: $mimetype = $mm->checktype_contents($env{'form.upfile'});
12293: unless (($mimetype eq 'text/plain') || ($mimetype eq 'text/html')) {
12294: $result.= '<p>'.
12295: &Apache::lonhtmlcommon::confirm_success(
12296: &mt('File format is neither csv (iclicker 6) nor xml (iclicker 7)'),1).'</p>';
12297: return $result;
12298: }
12299: } elsif (($env{'form.upfiletype'} ne 'interwrite') && ($env{'form.upfiletype'} ne 'turning')) {
12300: $result .= '<p>'.
12301: &Apache::lonhtmlcommon::confirm_success(
12302: &mt('Invalid clicker type: choose one of: i>clicker, Interwrite PRS, or Turning Technologies.'),1).'</p>';
12303: return $result;
12304: }
1.410 www 12305:
12306: # Were able to get all the info needed, now analyze the file
12307:
1.411 www 12308: $result.=&Apache::loncommon::studentbrowser_javascript();
1.418 albertel 12309: $symb = &Apache::lonenc::check_encrypt($symb);
1.632 www 12310: $result.=&Apache::loncommon::start_data_table().
12311: &Apache::loncommon::start_data_table_header_row().
12312: '<th>'.&mt('Evaluate clicker file').'</th>'.
12313: &Apache::loncommon::end_data_table_header_row().
12314: &Apache::loncommon::start_data_table_row().(<<ENDHEADER);
12315: <td>
1.410 www 12316: <form method="post" action="/adm/grades" name="clickeranalysis">
12317: <input type="hidden" name="symb" value="$symb" />
12318: <input type="hidden" name="command" value="assignclickergrades" />
1.411 www 12319: <input type="hidden" name="gradingmechanism" value="$env{'form.gradingmechanism'}" />
12320: <input type="hidden" name="pcorrect" value="$env{'form.pcorrect'}" />
12321: <input type="hidden" name="pincorrect" value="$env{'form.pincorrect'}" />
1.410 www 12322: ENDHEADER
1.522 www 12323: if ($env{'form.gradingmechanism'} eq 'given') {
12324: $result.='<input type="hidden" name="correct:given" value="'.$env{'form.givenanswer'}.'" />';
12325: }
1.408 albertel 12326: my %responses;
12327: my @questiontitles;
1.405 www 12328: my $errormsg='';
12329: my $number=0;
12330: if ($env{'form.upfiletype'} eq 'iclicker') {
1.760 raeburn 12331: if ($mimetype eq 'text/plain') {
12332: ($errormsg,$number)=&iclicker_eval(\@questiontitles,\%responses);
12333: } elsif ($mimetype eq 'text/html') {
12334: ($errormsg,$number)=&iclickerxml_eval(\@questiontitles,\%responses);
12335: }
12336: } elsif ($env{'form.upfiletype'} eq 'interwrite') {
1.419 www 12337: ($errormsg,$number)=&interwrite_eval(\@questiontitles,\%responses);
1.760 raeburn 12338: } elsif ($env{'form.upfiletype'} eq 'turning') {
1.666 www 12339: ($errormsg,$number)=&turning_eval(\@questiontitles,\%responses);
12340: }
1.411 www 12341: $result.='<br />'.&mt('Found [_1] question(s)',$number).'<br />'.
12342: '<input type="hidden" name="number" value="'.$number.'" />'.
12343: &mt('Awarding [_1] percent for correct and [_2] percent for incorrect responses',
12344: $env{'form.pcorrect'},$env{'form.pincorrect'}).
12345: '<br />';
1.522 www 12346: if (($env{'form.gradingmechanism'} eq 'given') && ($number!=$foundgiven)) {
12347: $result.='<span class="LC_error">'.&mt('Number of given answers does not agree with number of questions in file.').'</span>';
1.614 www 12348: return $result;
1.522 www 12349: }
1.414 www 12350: # Remember Question Titles
12351: # FIXME: Possibly need delimiter other than ":"
12352: for (my $i=0;$i<$number;$i++) {
12353: $result.='<input type="hidden" name="question:'.$i.'" value="'.
12354: &HTML::Entities::encode($questiontitles[$i],'"&<>').'" />';
12355: }
1.411 www 12356: my $correct_count=0;
12357: my $student_count=0;
12358: my $unknown_count=0;
1.414 www 12359: # Match answers with usernames
12360: # FIXME: Possibly need delimiter other than ":"
1.409 albertel 12361: foreach my $id (keys(%responses)) {
1.410 www 12362: if ($correct_ids{$id}) {
1.414 www 12363: $result.="\n".'<input type="hidden" name="correct:'.$correct_count.':'.$correct_ids{$id}.'" value="'.$responses{$id}.'" />';
1.411 www 12364: $correct_count++;
1.410 www 12365: } elsif ($clicker_ids{$id}) {
1.437 www 12366: if ($clicker_ids{$id}=~/\,/) {
12367: # More than one user with the same clicker!
1.632 www 12368: $result.="</td>".&Apache::loncommon::end_data_table_row().
12369: &Apache::loncommon::start_data_table_row()."<td>".
12370: &mt('Clicker registered more than once').": <tt>".$id."</tt><br />";
1.437 www 12371: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
12372: "<select name='multi".$id."'>";
12373: foreach my $reguser (sort(split(/\,/,$clicker_ids{$id}))) {
12374: $result.="<option value='".$reguser."'>".&Apache::loncommon::plainname(split(/\:/,$reguser)).' ('.$reguser.')</option>';
12375: }
12376: $result.='</select>';
12377: $unknown_count++;
12378: } else {
12379: # Good: found one and only one user with the right clicker
12380: $result.="\n".'<input type="hidden" name="student:'.$clicker_ids{$id}.'" value="'.$responses{$id}.'" />';
12381: $student_count++;
12382: }
1.410 www 12383: } else {
1.632 www 12384: $result.="</td>".&Apache::loncommon::end_data_table_row().
12385: &Apache::loncommon::start_data_table_row()."<td>".
12386: &mt('Unregistered Clicker')." <tt>".$id."</tt><br />";
1.411 www 12387: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
12388: "\n".&mt("Username").": <input type='text' name='uname".$id."' /> ".
12389: "\n".&mt("Domain").": ".
12390: &Apache::loncommon::select_dom_form($env{'course.'.$env{'request.course.id'}.'.domain'},'udom'.$id).' '.
1.762 raeburn 12391: &Apache::loncommon::selectstudent_link('clickeranalysis','uname'.$id,'udom'.$id,'',$id);
1.411 www 12392: $unknown_count++;
1.410 www 12393: }
1.405 www 12394: }
1.412 www 12395: $result.='<hr />'.
12396: &mt('Found [_1] registered and [_2] unregistered clickers.',$student_count,$unknown_count);
1.521 www 12397: if (($env{'form.gradingmechanism'} ne 'attendance') && ($env{'form.gradingmechanism'} ne 'given')) {
1.412 www 12398: if ($correct_count==0) {
1.696 bisitz 12399: $errormsg.="Found no correct answers for grading!";
1.412 www 12400: } elsif ($correct_count>1) {
1.414 www 12401: $result.='<br /><span class="LC_warning">'.&mt("Found [_1] entries for grading!",$correct_count).'</span>';
1.412 www 12402: }
12403: }
1.428 www 12404: if ($number<1) {
12405: $errormsg.="Found no questions.";
12406: }
1.412 www 12407: if ($errormsg) {
12408: $result.='<br /><span class="LC_error">'.&mt($errormsg).'</span>';
12409: } else {
12410: $result.='<br /><input type="submit" name="finalize" value="'.&mt('Finalize Grading').'" />';
12411: }
1.632 www 12412: $result.='</form></td>'.
12413: &Apache::loncommon::end_data_table_row().
12414: &Apache::loncommon::end_data_table();
1.614 www 12415: return $result;
1.400 www 12416: }
12417:
1.405 www 12418: sub iclicker_eval {
1.406 www 12419: my ($questiontitles,$responses)=@_;
1.405 www 12420: my $number=0;
12421: my $errormsg='';
12422: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
1.410 www 12423: my %components=&Apache::loncommon::record_sep($line);
12424: my @entries=map {$components{$_}} (sort(keys(%components)));
1.408 albertel 12425: if ($entries[0] eq 'Question') {
12426: for (my $i=3;$i<$#entries;$i+=6) {
12427: $$questiontitles[$number]=$entries[$i];
12428: $number++;
12429: }
12430: }
12431: if ($entries[0]=~/^\#/) {
12432: my $id=$entries[0];
12433: my @idresponses;
12434: $id=~s/^[\#0]+//;
12435: for (my $i=0;$i<$number;$i++) {
12436: my $idx=3+$i*6;
1.644 www 12437: $entries[$idx]=~s/[^a-zA-Z0-9\.\*\-\+]+//g;
1.408 albertel 12438: push(@idresponses,$entries[$idx]);
12439: }
12440: $$responses{$id}=join(',',@idresponses);
12441: }
1.405 www 12442: }
12443: return ($errormsg,$number);
12444: }
12445:
1.760 raeburn 12446: sub iclickerxml_eval {
12447: my ($questiontitles,$responses)=@_;
12448: my $number=0;
12449: my $errormsg='';
12450: my @state;
12451: my %respbyid;
12452: my $p = HTML::Parser->new
12453: (
12454: xml_mode => 1,
12455: start_h =>
12456: [sub {
12457: my ($tagname,$attr) = @_;
12458: push(@state,$tagname);
12459: if ("@state" eq "ssn p") {
12460: my $title = $attr->{qn};
12461: $title =~ s/(^\s+|\s+$)//g;
12462: $questiontitles->[$number]=$title;
12463: } elsif ("@state" eq "ssn p v") {
12464: my $id = $attr->{id};
12465: my $entry = $attr->{ans};
12466: $id=~s/^[\#0]+//;
12467: $entry =~s/[^a-zA-Z0-9\.\*\-\+]+//g;
12468: $respbyid{$id}[$number] = $entry;
12469: }
12470: }, "tagname, attr"],
12471: end_h =>
12472: [sub {
12473: my ($tagname) = @_;
12474: if ("@state" eq "ssn p") {
12475: $number++;
12476: }
12477: pop(@state);
12478: }, "tagname"],
12479: );
12480:
12481: $p->parse($env{'form.upfile'});
12482: $p->eof;
12483: foreach my $id (keys(%respbyid)) {
12484: $responses->{$id}=join(',',@{$respbyid{$id}});
12485: }
12486: return ($errormsg,$number);
12487: }
12488:
1.419 www 12489: sub interwrite_eval {
12490: my ($questiontitles,$responses)=@_;
12491: my $number=0;
12492: my $errormsg='';
1.420 www 12493: my $skipline=1;
12494: my $questionnumber=0;
12495: my %idresponses=();
1.419 www 12496: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
12497: my %components=&Apache::loncommon::record_sep($line);
12498: my @entries=map {$components{$_}} (sort(keys(%components)));
1.420 www 12499: if ($entries[1] eq 'Time') { $skipline=0; next; }
12500: if ($entries[1] eq 'Response') { $skipline=1; }
12501: next if $skipline;
12502: if ($entries[0]!=$questionnumber) {
12503: $questionnumber=$entries[0];
12504: $$questiontitles[$number]=&mt('Question [_1]',$questionnumber);
12505: $number++;
1.419 www 12506: }
1.420 www 12507: my $id=$entries[4];
12508: $id=~s/^[\#0]+//;
1.421 www 12509: $id=~s/^v\d*\://i;
12510: $id=~s/[\-\:]//g;
1.420 www 12511: $idresponses{$id}[$number]=$entries[6];
12512: }
1.524 raeburn 12513: foreach my $id (keys(%idresponses)) {
1.420 www 12514: $$responses{$id}=join(',',@{$idresponses{$id}});
12515: $$responses{$id}=~s/^\s*\,//;
1.419 www 12516: }
12517: return ($errormsg,$number);
12518: }
12519:
1.666 www 12520: sub turning_eval {
12521: my ($questiontitles,$responses)=@_;
12522: my $number=0;
12523: my $errormsg='';
12524: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
12525: my %components=&Apache::loncommon::record_sep($line);
12526: my @entries=map {$components{$_}} (sort(keys(%components)));
12527: if ($#entries>$number) { $number=$#entries; }
12528: my $id=$entries[0];
12529: my @idresponses;
12530: $id=~s/^[\#0]+//;
12531: unless ($id) { next; }
12532: for (my $idx=1;$idx<=$#entries;$idx++) {
12533: $entries[$idx]=~s/\,/\;/g;
12534: $entries[$idx]=~s/[^a-zA-Z0-9\.\*\-\+\;]+//g;
12535: push(@idresponses,$entries[$idx]);
12536: }
12537: $$responses{$id}=join(',',@idresponses);
12538: }
12539: for (my $i=1; $i<=$number; $i++) {
12540: $$questiontitles[$i]=&mt('Question [_1]',$i);
12541: }
12542: return ($errormsg,$number);
12543: }
12544:
12545:
1.414 www 12546: sub assign_clicker_grades {
1.766 raeburn 12547: my ($r,$symb) = @_;
1.414 www 12548: if (!$symb) {return '';}
1.416 www 12549: # See which part we are saving to
1.582 raeburn 12550: my $res_error;
12551: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
12552: if ($res_error) {
12553: return &navmap_errormsg();
12554: }
1.416 www 12555: # FIXME: This should probably look for the first handgradeable part
12556: my $part=$$partlist[0];
12557: # Start screen output
1.766 raeburn 12558: my $result = &Apache::loncommon::start_data_table().
12559: &Apache::loncommon::start_data_table_header_row().
12560: '<th>'.&mt('Assigning grades based on clicker file').'</th>'.
12561: &Apache::loncommon::end_data_table_header_row().
12562: &Apache::loncommon::start_data_table_row().'<td>';
1.414 www 12563: # Get correct result
12564: # FIXME: Possibly need delimiter other than ":"
12565: my @correct=();
1.415 www 12566: my $gradingmechanism=$env{'form.gradingmechanism'};
12567: my $number=$env{'form.number'};
12568: if ($gradingmechanism ne 'attendance') {
1.414 www 12569: foreach my $key (keys(%env)) {
12570: if ($key=~/^form\.correct\:/) {
12571: my @input=split(/\,/,$env{$key});
12572: for (my $i=0;$i<=$#input;$i++) {
12573: if (($correct[$i]) && ($input[$i]) &&
12574: ($correct[$i] ne $input[$i])) {
12575: $result.='<br /><span class="LC_warning">'.
12576: &mt('More than one correct result given for question "[_1]": [_2] versus [_3].',
12577: $env{'form.question:'.$i},$correct[$i],$input[$i]).'</span>';
1.644 www 12578: } elsif (($input[$i]) || ($input[$i] eq '0')) {
1.414 www 12579: $correct[$i]=$input[$i];
12580: }
12581: }
12582: }
12583: }
1.415 www 12584: for (my $i=0;$i<$number;$i++) {
1.644 www 12585: if ((!$correct[$i]) && ($correct[$i] ne '0')) {
1.414 www 12586: $result.='<br /><span class="LC_error">'.
12587: &mt('No correct result given for question "[_1]"!',
12588: $env{'form.question:'.$i}).'</span>';
12589: }
12590: }
1.644 www 12591: $result.='<br />'.&mt("Correct answer: [_1]",join(', ',map { ((($_) || ($_ eq '0'))?$_:'-') } @correct));
1.414 www 12592: }
12593: # Start grading
1.415 www 12594: my $pcorrect=$env{'form.pcorrect'};
12595: my $pincorrect=$env{'form.pincorrect'};
1.416 www 12596: my $storecount=0;
1.632 www 12597: my %users=();
1.415 www 12598: foreach my $key (keys(%env)) {
1.420 www 12599: my $user='';
1.415 www 12600: if ($key=~/^form\.student\:(.*)$/) {
1.420 www 12601: $user=$1;
12602: }
12603: if ($key=~/^form\.unknown\:(.*)$/) {
12604: my $id=$1;
12605: if (($env{'form.uname'.$id}) && ($env{'form.udom'.$id})) {
12606: $user=$env{'form.uname'.$id}.':'.$env{'form.udom'.$id};
1.437 www 12607: } elsif ($env{'form.multi'.$id}) {
12608: $user=$env{'form.multi'.$id};
1.420 www 12609: }
12610: }
1.632 www 12611: if ($user) {
12612: if ($users{$user}) {
12613: $result.='<br /><span class="LC_warning">'.
1.696 bisitz 12614: &mt('More than one entry found for [_1]!','<tt>'.$user.'</tt>').
1.632 www 12615: '</span><br />';
12616: }
12617: $users{$user}=1;
1.415 www 12618: my @answer=split(/\,/,$env{$key});
12619: my $sum=0;
1.522 www 12620: my $realnumber=$number;
1.415 www 12621: for (my $i=0;$i<$number;$i++) {
1.576 www 12622: if ($correct[$i] eq '-') {
12623: $realnumber--;
1.766 raeburn 12624: } elsif (($answer[$i]) || ($answer[$i]=~/^[0\.]+$/)) {
1.415 www 12625: if ($gradingmechanism eq 'attendance') {
12626: $sum+=$pcorrect;
1.576 www 12627: } elsif ($correct[$i] eq '*') {
1.522 www 12628: $sum+=$pcorrect;
1.415 www 12629: } else {
1.644 www 12630: # We actually grade if correct or not
12631: my $increment=$pincorrect;
12632: # Special case: numerical answer "0"
12633: if ($correct[$i] eq '0') {
12634: if ($answer[$i]=~/^[0\.]+$/) {
12635: $increment=$pcorrect;
12636: }
12637: # General numerical answer, both evaluate to something non-zero
12638: } elsif ((1.0*$correct[$i]!=0) && (1.0*$answer[$i]!=0)) {
12639: if (1.0*$correct[$i]==1.0*$answer[$i]) {
12640: $increment=$pcorrect;
12641: }
12642: # Must be just alphanumeric
12643: } elsif ($answer[$i] eq $correct[$i]) {
12644: $increment=$pcorrect;
1.415 www 12645: }
1.644 www 12646: $sum+=$increment;
1.415 www 12647: }
12648: }
12649: }
1.522 www 12650: my $ave=$sum/(100*$realnumber);
1.416 www 12651: # Store
12652: my ($username,$domain)=split(/\:/,$user);
12653: my %grades=();
12654: $grades{"resource.$part.solved"}='correct_by_override';
12655: $grades{"resource.$part.awarded"}=$ave;
12656: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
12657: my $returncode=&Apache::lonnet::cstore(\%grades,$symb,
12658: $env{'request.course.id'},
12659: $domain,$username);
12660: if ($returncode ne 'ok') {
12661: $result.="<br /><span class=\"LC_error\">Failed to save student $username:$domain. Message when trying to save was ($returncode)</span>";
12662: } else {
12663: $storecount++;
1.798 raeburn 12664: #FIXME Do passback for $user if required
1.416 www 12665: }
1.415 www 12666: }
12667: }
12668: # We are done
1.549 hauer 12669: $result.='<br />'.&mt('Successfully stored grades for [quant,_1,student].',$storecount).
1.632 www 12670: '</td>'.
12671: &Apache::loncommon::end_data_table_row().
12672: &Apache::loncommon::end_data_table();
1.614 www 12673: return $result;
1.414 www 12674: }
12675:
1.582 raeburn 12676: sub navmap_errormsg {
12677: return '<div class="LC_error">'.
12678: &mt('An error occurred retrieving information about resources in the course.').'<br />'.
1.595 raeburn 12679: &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 12680: '</div>';
12681: }
1.607 droeschl 12682:
1.609 www 12683: sub startpage {
1.777 raeburn 12684: my ($r,$symb,$crumbs,$onlyfolderflag,$nodisplayflag,$stuvcurrent,$stuvdisp,$nomenu,$head_extra,$onload,$divforres) = @_;
1.754 raeburn 12685: my %args;
12686: if ($onload) {
12687: my %loaditems = (
12688: 'onload' => $onload,
12689: );
12690: $args{'add_entries'} = \%loaditems;
12691: }
1.671 raeburn 12692: if ($nomenu) {
1.754 raeburn 12693: $args{'only_body'} = 1;
1.777 raeburn 12694: $r->print(&Apache::loncommon::start_page("Student's Version",$head_extra,\%args));
1.671 raeburn 12695: } else {
1.785 raeburn 12696: if ($env{'request.course.id'}) {
12697: unshift(@$crumbs,{href=>&href_symb_cmd($symb,'gradingmenu'),text=>"Grading"});
12698: }
1.754 raeburn 12699: $args{'bread_crumbs'} = $crumbs;
1.777 raeburn 12700: $r->print(&Apache::loncommon::start_page('Grading',$head_extra,\%args));
1.765 raeburn 12701: if ($env{'request.course.id'}) {
12702: &Apache::lonquickgrades::startGradeScreen($r,($env{'form.symb'}?'probgrading':'grading'));
12703: }
1.671 raeburn 12704: }
1.613 www 12705: unless ($nodisplayflag) {
1.773 raeburn 12706: $r->print(&Apache::lonhtmlcommon::resource_info_box($symb,$onlyfolderflag,$stuvcurrent,$stuvdisp,$divforres));
1.613 www 12707: }
1.607 droeschl 12708: }
1.582 raeburn 12709:
1.622 www 12710: sub select_problem {
12711: my ($r)=@_;
1.632 www 12712: $r->print('<h3>'.&mt('Select the problem or one of the problems you want to grade').'</h3><form action="/adm/grades">');
1.771 raeburn 12713: $r->print(&Apache::lonstathelpers::problem_selector('.',undef,1,undef,undef,1,1));
1.622 www 12714: $r->print('<input type="hidden" name="command" value="gradingmenu" />');
12715: $r->print('<input type="submit" value="'.&mt('Next').' →" /></form>');
12716: }
12717:
1.793 raeburn 12718: #----- display problem, answer, and submissions for a single student (no grading)
12719:
12720: sub view_as_user {
12721: my ($symb,$vuname,$vudom,$hasperm) = @_;
12722: my $plainname = &Apache::loncommon::plainname($vuname,$vudom,'lastname');
12723: my $displayname = &nameUserString('',$plainname,$vuname,$vudom);
12724: my $output = &Apache::loncommon::get_student_view($symb,$vuname,$vudom,
12725: $env{'request.course.id'},
12726: undef,{'disable_submit' => 1}).
12727: "\n\n".
12728: '<div class="LC_grade_show_user">'.
12729: '<h2>'.$displayname.'</h2>'.
12730: "\n".
12731: &Apache::loncommon::track_student_link('View recent activity',
12732: $vuname,$vudom,'check').' '.
12733: "\n";
12734: if (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) ||
12735: (($env{'request.course.sec'} ne '') &&
12736: &Apache::lonnet::allowed('opa',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
12737: $output .= &Apache::loncommon::pprmlink(&mt('Set/Change parameters'),
12738: $vuname,$vudom,$symb,'check');
12739: }
12740: $output .= "\n";
12741: my $companswer = &Apache::loncommon::get_student_answers($symb,$vuname,$vudom,
12742: $env{'request.course.id'});
12743: $companswer=~s|<form(.*?)>||g;
12744: $companswer=~s|</form>||g;
12745: $companswer=~s|name="submit"|name="would_have_been_submit"|g;
12746: $output .= '<div class="LC_Box">'.
12747: '<h3 class="LC_hcell">'.&mt('Correct answer for[_1]',$displayname).'</h3>'.
12748: $companswer.
12749: '</div>'."\n";
12750: my $is_tool = ($symb =~ /ext\.tool$/);
12751: my ($essayurl,%coursedesc_by_cid);
12752: (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb);
12753: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$vudom,$vuname);
12754: my $res_error;
12755: my ($partlist,$handgrade,$responseType,$numresp,$numessay) =
12756: &response_type($symb,\$res_error);
12757: my $fullname;
12758: my $collabinfo;
12759: if ($numessay) {
12760: unless ($hasperm) {
12761: &init_perm();
12762: }
12763: ($collabinfo,$fullname)=
12764: &check_collaborators($symb,$vuname,$vudom,\%record,$handgrade,0);
12765: unless ($hasperm) {
12766: &reset_perm();
12767: }
12768: }
12769: my $checkIcon = '<img alt="'.&mt('Check Mark').
12770: '" src="'.$Apache::lonnet::perlvar{'lonIconsURL'}.
12771: '/check.gif" height="16" border="0" />';
12772: my ($lastsubonly,$partinfo) =
12773: &show_last_submission($vuname,$vudom,$symb,$essayurl,$responseType,'datesub',
12774: '',$fullname,\%record,\%coursedesc_by_cid);
12775: $output .= '<div class="LC_Box">'.
12776: '<h3 class="LC_hcell">'.&mt('Submissions').'</h3>'."\n".$collabinfo."\n";
12777: if (($numresp > $numessay) & !$is_tool) {
12778: $output .='<p class="LC_info">'.
12779: &mt('Part(s) graded correct by the computer is marked with a [_1] symbol.',$checkIcon).
12780: "</p>\n";
12781: }
12782: $output .= $partinfo;
12783: $output .= $lastsubonly;
12784: $output .= &displaySubByDates($symb,\%record,$partlist,$responseType,$checkIcon,$vuname,$vudom);
12785: $output .= '</div></div>'."\n";
12786: return $output;
12787: }
12788:
1.1 albertel 12789: sub handler {
1.41 ng 12790: my $request=$_[0];
1.434 albertel 12791: &reset_caches();
1.646 raeburn 12792: if ($request->header_only) {
12793: &Apache::loncommon::content_type($request,'text/html');
12794: $request->send_http_header;
12795: return OK;
12796: }
12797: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
12798:
1.664 raeburn 12799: # see what command we need to execute
12800:
12801: my @commands=&Apache::loncommon::get_env_multiple('form.command');
12802: my $command=$commands[0];
12803:
1.646 raeburn 12804: &init_perm();
12805: if (!$env{'request.course.id'}) {
1.664 raeburn 12806: unless ((&Apache::lonnet::allowed('usc',$env{'request.role.domain'})) &&
12807: ($command =~ /^scantronupload/)) {
12808: # Not in a course.
12809: $env{'user.error.msg'}="/adm/grades::vgr:0:0:Cannot display grades page outside course context";
12810: return HTTP_NOT_ACCEPTABLE;
12811: }
1.646 raeburn 12812: } elsif (!%perm) {
12813: $request->internal_redirect('/adm/quickgrades');
1.687 raeburn 12814: return OK;
1.41 ng 12815: }
1.646 raeburn 12816: &Apache::loncommon::content_type($request,'text/html');
1.41 ng 12817: $request->send_http_header;
1.646 raeburn 12818:
1.160 albertel 12819: if ($#commands > 0) {
12820: &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands));
12821: }
1.608 www 12822:
1.801 raeburn 12823: # -------------------------------------- Flag and buffer for registered cleanup
12824: $registered_cleanup=0;
12825: undef(@Apache::grades::ltipassback);
12826:
1.608 www 12827: # see what the symb is
12828:
12829: my $symb=$env{'form.symb'};
12830: unless ($symb) {
12831: (my $url=$env{'form.url'}) =~ s-^https*://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
12832: $symb=&Apache::lonnet::symbread($url);
12833: }
1.646 raeburn 12834: &Apache::lonenc::check_decrypt(\$symb);
1.608 www 12835:
1.513 foxr 12836: $ssi_error = 0;
1.637 www 12837: if (($symb eq '' || $command eq '') && ($env{'request.course.id'})) {
1.601 www 12838: #
1.637 www 12839: # Not called from a resource, but inside a course
1.601 www 12840: #
1.622 www 12841: &startpage($request,undef,[],1,1);
12842: &select_problem($request);
1.41 ng 12843: } else {
1.104 albertel 12844: if ($command eq 'submission' && $perm{'vgr'}) {
1.773 raeburn 12845: my ($stuvcurrent,$stuvdisp,$versionform,$js,$onload);
1.671 raeburn 12846: if (($env{'form.student'} ne '') && ($env{'form.userdom'} ne '')) {
12847: ($stuvcurrent,$stuvdisp,$versionform,$js) =
12848: &choose_task_version_form($symb,$env{'form.student'},
12849: $env{'form.userdom'});
12850: }
1.773 raeburn 12851: my $divforres;
12852: if ($env{'form.student'} eq '') {
12853: $js .= &part_selector_js();
12854: $onload = "toggleParts('gradesub');";
12855: } else {
12856: $divforres = 1;
12857: }
1.778 raeburn 12858: my $head_extra = $js;
12859: unless ($env{'form.vProb'} eq 'no') {
1.779 raeburn 12860: my $csslinks = &Apache::loncommon::css_links($symb);
1.778 raeburn 12861: if ($csslinks) {
12862: $head_extra .= "\n$csslinks";
12863: }
12864: }
1.777 raeburn 12865: &startpage($request,$symb,[{href=>"", text=>"Student Submissions"}],undef,undef,
12866: $stuvcurrent,$stuvdisp,undef,$head_extra,$onload,$divforres);
1.671 raeburn 12867: if ($versionform) {
1.775 raeburn 12868: if ($divforres) {
12869: $request->print('<div style="padding:0;clear:both;margin:0;border:0"></div>');
12870: }
1.671 raeburn 12871: $request->print($versionform);
12872: }
1.773 raeburn 12873: ($env{'form.student'} eq '' ? &listStudents($request,$symb,'',$divforres) : &submission($request,0,0,$symb,$divforres,$command));
1.671 raeburn 12874: } elsif ($command eq 'versionsub' && $perm{'vgr'}) {
12875: my ($stuvcurrent,$stuvdisp,$versionform,$js) =
12876: &choose_task_version_form($symb,$env{'form.student'},
12877: $env{'form.userdom'},
12878: $env{'form.inhibitmenu'});
1.778 raeburn 12879: my $head_extra = $js;
12880: unless ($env{'form.vProb'} eq 'no') {
1.779 raeburn 12881: my $csslinks = &Apache::loncommon::css_links($symb);
1.778 raeburn 12882: if ($csslinks) {
12883: $head_extra .= "\n$csslinks";
12884: }
12885: }
1.777 raeburn 12886: &startpage($request,$symb,[{href=>"", text=>"Previous Student Version"}],undef,undef,
12887: $stuvcurrent,$stuvdisp,$env{'form.inhibitmenu'},$head_extra);
1.671 raeburn 12888: if ($versionform) {
12889: $request->print($versionform);
12890: }
12891: $request->print('<br clear="all" />');
12892: $request->print(&show_previous_task_version($request,$symb));
1.103 albertel 12893: } elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) {
1.615 www 12894: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'all_for_one'),text=>'Grade page/folder for one student'},
12895: {href=>'',text=>'Select student'}],1,1);
1.608 www 12896: &pickStudentPage($request,$symb);
1.103 albertel 12897: } elsif ($command eq 'displayPage' && $perm{'vgr'}) {
1.778 raeburn 12898: my $csslinks;
12899: unless ($env{'form.vProb'} eq 'no') {
1.779 raeburn 12900: $csslinks = &Apache::loncommon::css_links($symb,'map');
1.778 raeburn 12901: }
1.615 www 12902: &startpage($request,$symb,
12903: [{href=>&href_symb_cmd($symb,'all_for_one'),text=>'Grade page/folder for one student'},
12904: {href=>'',text=>'Select student'},
1.777 raeburn 12905: {href=>'',text=>'Grade student'}],1,1,undef,undef,undef,$csslinks);
1.608 www 12906: &displayPage($request,$symb);
1.104 albertel 12907: } elsif ($command eq 'gradeByPage' && $perm{'mgr'}) {
1.616 www 12908: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'all_for_one'),text=>'Grade page/folder for one student'},
12909: {href=>'',text=>'Select student'},
12910: {href=>'',text=>'Grade student'},
12911: {href=>'',text=>'Store grades'}],1,1);
1.608 www 12912: &updateGradeByPage($request,$symb);
1.104 albertel 12913: } elsif ($command eq 'processGroup' && $perm{'vgr'}) {
1.778 raeburn 12914: my $csslinks;
12915: unless ($env{'form.vProb'} eq 'no') {
1.779 raeburn 12916: $csslinks = &Apache::loncommon::css_links($symb);
1.778 raeburn 12917: }
1.619 www 12918: &startpage($request,$symb,[{href=>'',text=>'...'},
1.777 raeburn 12919: {href=>'',text=>'Modify grades'}],undef,undef,undef,undef,undef,$csslinks,undef,1);
1.608 www 12920: &processGroup($request,$symb);
1.104 albertel 12921: } elsif ($command eq 'gradingmenu' && $perm{'vgr'}) {
1.608 www 12922: &startpage($request,$symb);
12923: $request->print(&grading_menu($request,$symb));
1.598 www 12924: } elsif ($command eq 'individual' && $perm{'vgr'}) {
1.617 www 12925: &startpage($request,$symb,[{href=>'',text=>'Select individual students to grade'}]);
1.608 www 12926: $request->print(&submit_options($request,$symb));
1.598 www 12927: } elsif ($command eq 'ungraded' && $perm{'vgr'}) {
1.773 raeburn 12928: my $js = &part_selector_js();
12929: my $onload = "toggleParts('gradesub');";
12930: &startpage($request,$symb,[{href=>'',text=>'Grade ungraded submissions'}],
12931: undef,undef,undef,undef,undef,$js,$onload);
1.617 www 12932: $request->print(&listStudents($request,$symb,'graded'));
1.598 www 12933: } elsif ($command eq 'table' && $perm{'vgr'}) {
1.614 www 12934: &startpage($request,$symb,[{href=>"", text=>"Grading table"}]);
1.611 www 12935: $request->print(&submit_options_table($request,$symb));
1.598 www 12936: } elsif ($command eq 'all_for_one' && $perm{'vgr'}) {
1.615 www 12937: &startpage($request,$symb,[{href=>'',text=>'Grade page/folder for one student'}],1,1);
1.608 www 12938: $request->print(&submit_options_sequence($request,$symb));
1.104 albertel 12939: } elsif ($command eq 'viewgrades' && $perm{'vgr'}) {
1.614 www 12940: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,"table"), text=>"Grading table"},{href=>'', text=>"Modify grades"}]);
1.608 www 12941: $request->print(&viewgrades($request,$symb));
1.104 albertel 12942: } elsif ($command eq 'handgrade' && $perm{'mgr'}) {
1.620 www 12943: &startpage($request,$symb,[{href=>'',text=>'...'},
12944: {href=>'',text=>'Store grades'}]);
1.608 www 12945: $request->print(&processHandGrade($request,$symb));
1.106 albertel 12946: } elsif ($command eq 'editgrades' && $perm{'mgr'}) {
1.614 www 12947: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,"table"), text=>"Grading table"},
12948: {href=>&href_symb_cmd($symb,'viewgrades').'&group=all§ion=all&Status=Active',
12949: text=>"Modify grades"},
12950: {href=>'', text=>"Store grades"}]);
1.608 www 12951: $request->print(&editgrades($request,$symb));
1.602 www 12952: } elsif ($command eq 'initialverifyreceipt' && $perm{'vgr'}) {
1.616 www 12953: &startpage($request,$symb,[{href=>'',text=>'Verify Receipt Number'}]);
1.611 www 12954: $request->print(&initialverifyreceipt($request,$symb));
1.106 albertel 12955: } elsif ($command eq 'verify' && $perm{'vgr'}) {
1.616 www 12956: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,"initialverifyreceipt"),text=>'Verify Receipt Number'},
12957: {href=>'',text=>'Verification Result'}]);
1.608 www 12958: $request->print(&verifyreceipt($request,$symb));
1.400 www 12959: } elsif ($command eq 'processclicker' && $perm{'mgr'}) {
1.615 www 12960: &startpage($request,$symb,[{href=>'', text=>'Process clicker'}]);
1.608 www 12961: $request->print(&process_clicker($request,$symb));
1.400 www 12962: } elsif ($command eq 'processclickerfile' && $perm{'mgr'}) {
1.615 www 12963: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'processclicker'), text=>'Process clicker'},
12964: {href=>'', text=>'Process clicker file'}]);
1.608 www 12965: $request->print(&process_clicker_file($request,$symb));
1.414 www 12966: } elsif ($command eq 'assignclickergrades' && $perm{'mgr'}) {
1.615 www 12967: &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'processclicker'), text=>'Process clicker'},
12968: {href=>'', text=>'Process clicker file'},
12969: {href=>'', text=>'Store grades'}]);
1.608 www 12970: $request->print(&assign_clicker_grades($request,$symb));
1.106 albertel 12971: } elsif ($command eq 'csvform' && $perm{'mgr'}) {
1.627 www 12972: &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
1.608 www 12973: $request->print(&upcsvScores_form($request,$symb));
1.106 albertel 12974: } elsif ($command eq 'csvupload' && $perm{'mgr'}) {
1.627 www 12975: &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
1.608 www 12976: $request->print(&csvupload($request,$symb));
1.106 albertel 12977: } elsif ($command eq 'csvuploadmap' && $perm{'mgr'} ) {
1.627 www 12978: &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
1.608 www 12979: $request->print(&csvuploadmap($request,$symb));
1.246 albertel 12980: } elsif ($command eq 'csvuploadoptions' && $perm{'mgr'}) {
1.257 albertel 12981: if ($env{'form.associate'} ne 'Reverse Association') {
1.627 www 12982: &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
1.608 www 12983: $request->print(&csvuploadoptions($request,$symb));
1.41 ng 12984: } else {
1.257 albertel 12985: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
12986: $env{'form.upfile_associate'} = 'reverse';
1.41 ng 12987: } else {
1.257 albertel 12988: $env{'form.upfile_associate'} = 'forward';
1.41 ng 12989: }
1.627 www 12990: &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
1.608 www 12991: $request->print(&csvuploadmap($request,$symb));
1.41 ng 12992: }
1.246 albertel 12993: } elsif ($command eq 'csvuploadassign' && $perm{'mgr'} ) {
1.627 www 12994: &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
1.608 www 12995: $request->print(&csvuploadassign($request,$symb));
1.106 albertel 12996: } elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
1.754 raeburn 12997: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1,
12998: undef,undef,undef,undef,'toggleScantab(document.rules);');
1.612 www 12999: $request->print(&scantron_selectphase($request,undef,$symb));
1.203 albertel 13000: } elsif ($command eq 'scantron_warning' && $perm{'mgr'}) {
1.616 www 13001: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 13002: $request->print(&scantron_do_warning($request,$symb));
1.142 albertel 13003: } elsif ($command eq 'scantron_validate' && $perm{'mgr'}) {
1.616 www 13004: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 13005: $request->print(&scantron_validate_file($request,$symb));
1.106 albertel 13006: } elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
1.616 www 13007: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 13008: $request->print(&scantron_process_students($request,$symb));
1.157 albertel 13009: } elsif ($command eq 'scantronupload' &&
1.770 raeburn 13010: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) || $perm{'usc'})) {
1.754 raeburn 13011: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1,
13012: undef,undef,undef,undef,'toggleScantab(document.rules);');
1.608 www 13013: $request->print(&scantron_upload_scantron_data($request,$symb));
1.157 albertel 13014: } elsif ($command eq 'scantronupload_save' &&
1.770 raeburn 13015: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) || $perm{'usc'})) {
1.616 www 13016: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 13017: $request->print(&scantron_upload_scantron_data_save($request,$symb));
1.770 raeburn 13018: } elsif ($command eq 'scantron_download' && ($perm{'usc'} || $perm{'mgr'})) {
1.616 www 13019: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.608 www 13020: $request->print(&scantron_download_scantron_data($request,$symb));
1.770 raeburn 13021: } elsif ($command eq 'scantronupload_delete' &&
13022: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) || $perm{'usc'})) {
13023: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
13024: &scantron_upload_delete($request,$symb);
1.523 raeburn 13025: } elsif ($command eq 'checksubmissions' && $perm{'vgr'}) {
1.616 www 13026: &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
1.621 www 13027: $request->print(&checkscantron_results($request,$symb));
13028: } elsif ($command eq 'downloadfilesselect' && $perm{'vgr'}) {
1.773 raeburn 13029: my $js = &part_selector_js();
13030: my $onload = "toggleParts('gradingMenu');";
13031: &startpage($request,$symb,[{href=>'', text=>'Select which submissions to download'}],
13032: undef,undef,undef,undef,undef,$js,$onload);
1.621 www 13033: $request->print(&submit_options_download($request,$symb));
13034: } elsif ($command eq 'downloadfileslink' && $perm{'vgr'}) {
13035: &startpage($request,$symb,
13036: [{href=>&href_symb_cmd($symb,'downloadfilesselect'), text=>'Select which submissions to download'},
1.773 raeburn 13037: {href=>'', text=>'Download submitted files'}],
13038: undef,undef,undef,undef,undef,undef,undef,1);
1.775 raeburn 13039: $request->print('<div style="padding:0;clear:both;margin:0;border:0"></div>');
1.621 www 13040: &submit_download_link($request,$symb);
1.796 raeburn 13041: } elsif ($command eq 'initialpassback') {
13042: &startpage($request,$symb,[{href=>'', text=>'Choose Launcher'}],undef,1);
13043: $request->print(&initialpassback($request,$symb));
13044: } elsif ($command eq 'passback') {
13045: &startpage($request,$symb,
13046: [{href=>&href_symb_cmd($symb,'initialpassback'), text=>'Choose Launcher'},
13047: {href=>'', text=>'Types of User'}],undef,1);
13048: $request->print(&passback_filters($request,$symb));
13049: } elsif ($command eq 'passbacknames') {
13050: my $chosen;
13051: if ($env{'form.passback'} ne '') {
13052: if ($env{'form.passback'} eq &unescape($env{'form.passback'})) {
13053: $env{'form.passback'} = &escape($env{'form.passback'} );
13054: }
13055: $chosen = &HTML::Entities::encode($env{'form.passback'},'<>"&');
13056: }
13057: &startpage($request,$symb,
13058: [{href=>&href_symb_cmd($symb,'initialpassback'), text=>'Choose Launcher'},
13059: {href=>&href_symb_cmd($symb,'passback').'&passback='.$chosen, text=>'Types of User'},
13060: {href=>'', text=>'Select Users'}],undef,1);
13061: $request->print(&names_for_passback($request,$symb));
13062: } elsif ($command eq 'passbackscores') {
13063: my ($chosen,$stu_status);
13064: if ($env{'form.passback'} ne '') {
13065: if ($env{'form.passback'} eq &unescape($env{'form.passback'})) {
13066: $env{'form.passback'} = &escape($env{'form.passback'} );
13067: }
13068: $chosen = &HTML::Entities::encode($env{'form.passback'},'<>"&');
13069: }
13070: if ($env{'form.Status'}) {
13071: $stu_status = &HTML::Entities::encode($env{'form.Status'});
13072: }
13073: &startpage($request,$symb,
13074: [{href=>&href_symb_cmd($symb,'initialpassback'), text=>'Choose Launcher'},
13075: {href=>&href_symb_cmd($symb,'passback').'&passback='.$chosen, text=>'Types of User'},
13076: {href=>&href_symb_cmd($symb,'passbacknames').'&Status='.$stu_status.'&passback='.$chosen, text=>'Select Users'},
13077: {href=>'', text=>'Execute Passback'}],undef,1);
13078: $request->print(&do_passback($request,$symb));
1.106 albertel 13079: } elsif ($command) {
1.620 www 13080: &startpage($request,$symb,[{href=>'', text=>'Access denied'}]);
1.562 bisitz 13081: $request->print('<p class="LC_error">'.&mt('Access Denied ([_1])',$command).'</p>');
1.26 albertel 13082: }
1.2 albertel 13083: }
1.513 foxr 13084: if ($ssi_error) {
13085: &ssi_print_error($request);
13086: }
1.671 raeburn 13087: if ($env{'form.inhibitmenu'}) {
13088: $request->print(&Apache::loncommon::end_page());
1.765 raeburn 13089: } elsif ($env{'request.course.id'}) {
1.671 raeburn 13090: &Apache::lonquickgrades::endGradeScreen($request);
13091: }
1.434 albertel 13092: &reset_caches();
1.646 raeburn 13093: return OK;
1.44 ng 13094: }
13095:
1.1 albertel 13096: 1;
13097:
1.13 albertel 13098: __END__;
1.531 jms 13099:
13100:
13101: =head1 NAME
13102:
13103: Apache::grades
13104:
13105: =head1 SYNOPSIS
13106:
13107: Handles the viewing of grades.
13108:
13109: This is part of the LearningOnline Network with CAPA project
13110: described at http://www.lon-capa.org.
13111:
13112: =head1 OVERVIEW
13113:
13114: Do an ssi with retries:
1.715 bisitz 13115: While I'd love to factor out this with the version in lonprintout,
1.531 jms 13116: 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
13117: I'm not quite ready to invent (e.g. an ssi_with_retry object).
13118:
13119: At least the logic that drives this has been pulled out into loncommon.
13120:
13121:
13122:
13123: ssi_with_retries - Does the server side include of a resource.
13124: if the ssi call returns an error we'll retry it up to
13125: the number of times requested by the caller.
1.715 bisitz 13126: If we still have a problem, no text is appended to the
1.531 jms 13127: output and we set some global variables.
13128: to indicate to the caller an SSI error occurred.
13129: All of this is supposed to deal with the issues described
1.715 bisitz 13130: in LON-CAPA BZ 5631 see:
1.531 jms 13131: http://bugs.lon-capa.org/show_bug.cgi?id=5631
13132: by informing the user that this happened.
13133:
13134: Parameters:
13135: resource - The resource to include. This is passed directly, without
13136: interpretation to lonnet::ssi.
13137: form - The form hash parameters that guide the interpretation of the resource
13138:
13139: retries - Number of retries allowed before giving up completely.
13140: Returns:
13141: On success, returns the rendered resource identified by the resource parameter.
13142: Side Effects:
13143: The following global variables can be set:
13144: ssi_error - If an unrecoverable error occurred this becomes true.
13145: It is up to the caller to initialize this to false
13146: if desired.
13147: ssi_error_resource - If an unrecoverable error occurred, this is the value
13148: of the resource that could not be rendered by the ssi
13149: call.
13150: ssi_error_message - The error string fetched from the ssi response
13151: in the event of an error.
13152:
13153:
13154: =head1 HANDLER SUBROUTINE
13155:
13156: ssi_with_retries()
13157:
13158: =head1 SUBROUTINES
13159:
13160: =over
13161:
1.671 raeburn 13162: =head1 Routines to display previous version of a Task for a specific student
13163:
13164: Tasks are graded pass/fail. Students who have yet to pass a particular Task
13165: can receive another opportunity. Access to tasks is slot-based. If a slot
13166: requires a proctor to check-in the student, a new version of the Task will
13167: be created when the student is checked in to the new opportunity.
13168:
13169: If a particular student has tried two or more versions of a particular task,
13170: the submission screen provides a user with vgr privileges (e.g., a Course
13171: Coordinator) the ability to display a previous version worked on by the
13172: student. By default, the current version is displayed. If a previous version
13173: has been selected for display, submission data are only shown that pertain
13174: to that particular version, and the interface to submit grades is not shown.
13175:
13176: =over 4
13177:
13178: =item show_previous_task_version()
13179:
13180: Displays a specified version of a student's Task, as the student sees it.
13181:
13182: Inputs: 2
13183: request - request object
13184: symb - unique symb for current instance of resource
13185:
13186: Output: None.
13187:
13188: Side Effects: calls &show_problem() to print version of Task, with
13189: version contained in form item: $env{'form.previousversion'}
13190:
13191: =item choose_task_version_form()
13192:
13193: Displays a web form used to select which version of a student's view of a
13194: Task should be displayed. Either launches a pop-up window, or replaces
13195: content in existing pop-up, or replaces page in main window.
13196:
13197: Inputs: 4
13198: symb - unique symb for current instance of resource
13199: uname - username of student
13200: udom - domain of student
13201: nomenu - 1 if display is in a pop-up window, and hence no menu
13202: breadcrumbs etc., are displayed
13203:
13204: Output: 4
13205: current - student's current version
13206: displayed - student's version being displayed
13207: result - scalar containing HTML for web form used to switch to
13208: a different version (or a link to close window, if pop-up).
13209: js - javascript for processing selection in versions web form
13210:
13211: Side Effects: None.
13212:
13213: =item previous_display_javascript()
13214:
13215: Inputs: 2
13216: nomenu - 1 if display is in a pop-up window, and hence no menu
13217: breadcrumbs etc., are displayed.
13218: current - student's current version number.
13219:
13220: Output: 1
13221: js - javascript for processing selection in versions web form.
13222:
13223: Side Effects: None.
13224:
13225: =back
13226:
13227: =head1 Routines to process bubblesheet data.
13228:
13229: =over 4
13230:
1.531 jms 13231: =item scantron_get_correction() :
13232:
13233: Builds the interface screen to interact with the operator to fix a
13234: specific error condition in a specific scanline
13235:
13236: Arguments:
13237: $r - Apache request object
13238: $i - number of the current scanline
13239: $scan_record - hash ref as returned from &scantron_parse_scanline()
1.758 raeburn 13240: $scan_config - hash ref as returned from &Apache::lonnet::get_scantron_config()
1.531 jms 13241: $line - full contents of the current scanline
13242: $error - error condition, valid values are
13243: 'incorrectCODE', 'duplicateCODE',
13244: 'doublebubble', 'missingbubble',
13245: 'duplicateID', 'incorrectID'
13246: $arg - extra information needed
13247: For errors:
13248: - duplicateID - paper number that this studentID was seen before on
13249: - duplicateCODE - array ref of the paper numbers this CODE was
13250: seen on before
13251: - incorrectCODE - current incorrect CODE
13252: - doublebubble - array ref of the bubble lines that have double
13253: bubble errors
13254: - missingbubble - array ref of the bubble lines that have missing
13255: bubble errors
13256:
1.788 raeburn 13257: $randomorder - True if exam folder (or a sub-folder) has randomorder set
13258: $randompick - True if exam folder (or a sub-folder) has randompick set
1.691 raeburn 13259: $respnumlookup - Reference to HASH mapping question numbers in bubble lines
13260: for current line to question number used for same question
13261: in "Master Seqence" (as seen by Course Coordinator).
13262: $startline - Reference to hash where key is question number (0 is first)
13263: and value is number of first bubble line for current student
13264: or code-based randompick and/or randomorder.
13265:
13266:
13267:
1.531 jms 13268: =item scantron_get_maxbubble() :
13269:
1.582 raeburn 13270: Arguments:
13271: $nav_error - Reference to scalar which is a flag to indicate a
13272: failure to retrieve a navmap object.
13273: if $nav_error is set to 1 by scantron_get_maxbubble(), the
13274: calling routine should trap the error condition and display the warning
13275: found in &navmap_errormsg().
13276:
1.649 raeburn 13277: $scantron_config - Reference to bubblesheet format configuration hash.
13278:
1.531 jms 13279: Returns the maximum number of bubble lines that are expected to
13280: occur. Does this by walking the selected sequence rendering the
13281: resource and then checking &Apache::lonxml::get_problem_counter()
13282: for what the current value of the problem counter is.
13283:
13284: Caches the results to $env{'form.scantron_maxbubble'},
13285: $env{'form.scantron.bubble_lines.n'},
13286: $env{'form.scantron.first_bubble_line.n'} and
13287: $env{"form.scantron.sub_bubblelines.n"}
1.691 raeburn 13288: which are the total number of bubble lines, the number of bubble
1.531 jms 13289: lines for response n and number of the first bubble line for response n,
13290: and a comma separated list of numbers of bubble lines for sub-questions
13291: (for optionresponse, matchresponse, and rankresponse items), for response n.
13292:
13293:
13294: =item scantron_validate_missingbubbles() :
13295:
13296: Validates all scanlines in the selected file to not have any
13297: answers that don't have bubbles that have not been verified
13298: to be bubble free.
13299:
13300: =item scantron_process_students() :
13301:
1.659 raeburn 13302: Routine that does the actual grading of the bubblesheet information.
1.531 jms 13303:
13304: The parsed scanline hash is added to %env
13305:
13306: Then foreach unskipped scanline it does an &Apache::lonnet::ssi()
13307: foreach resource , with the form data of
13308:
13309: 'submitted' =>'scantron'
13310: 'grade_target' =>'grade',
13311: 'grade_username'=> username of student
13312: 'grade_domain' => domain of student
13313: 'grade_courseid'=> of course
13314: 'grade_symb' => symb of resource to grade
13315:
13316: This triggers a grading pass. The problem grading code takes care
13317: of converting the bubbled letter information (now in %env) into a
13318: valid submission.
13319:
13320: =item scantron_upload_scantron_data() :
13321:
1.659 raeburn 13322: Creates the screen for adding a new bubblesheet data file to a course.
1.531 jms 13323:
13324: =item scantron_upload_scantron_data_save() :
13325:
13326: Adds a provided bubble information data file to the course if user
1.770 raeburn 13327: has the correct privileges to do so.
13328:
13329: = item scantron_upload_delete() :
13330:
13331: Deletes a previously uploaded bubble information data file, if user
13332: was the one who uploaded the file, and has the privileges to do so.
1.531 jms 13333:
13334: =item valid_file() :
13335:
13336: Validates that the requested bubble data file exists in the course.
13337:
13338: =item scantron_download_scantron_data() :
13339:
13340: Shows a list of the three internal files (original, corrected,
1.659 raeburn 13341: skipped) for a specific bubblesheet data file that exists in the
1.531 jms 13342: course.
13343:
13344: =item scantron_validate_ID() :
13345:
13346: Validates all scanlines in the selected file to not have any
1.556 weissno 13347: invalid or underspecified student/employee IDs
1.531 jms 13348:
1.582 raeburn 13349: =item navmap_errormsg() :
13350:
13351: Returns HTML mark-up inside a <div></div> with a link to re-initialize the course.
1.671 raeburn 13352: Should be called whenever the request to instantiate a navmap object fails.
13353:
13354: =back
1.582 raeburn 13355:
1.531 jms 13356: =back
13357:
13358: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>