Annotation of loncom/homework/grades.pm, revision 1.596.2.12.2.60.2.7
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.596.2.12.2. 0.2.7(ra 4:an-25): # $Id: grades.pm,v 1.596.2.12.2.60.2.6 2024/08/23 20:52:28 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.596.2.4 raeburn 43: use Apache::Constants qw(:common :http);
1.167 sakharuk 44: use Apache::lonlocal;
1.386 raeburn 45: use Apache::lonenc;
1.596.2.12.2. 1(raebur 46:0): use Apache::lonstathelpers;
1.596.2.4 raeburn 47: use Apache::bridgetask();
1.596.2.12.2. 4(raebur 48:8): use Apache::lontexconvert();
0.2.7(ra 49:an-25): use Apache::loncourserespicker;
0.2.4(ra 50:ul-23): use String::Similarity;
7(raebur 51:9): use HTML::Parser();
52:9): use File::MMagic;
1.359 www 53: use LONCAPA;
1.596.2.12.2. 0.2.7(ra 54:an-25): use LONCAPA::ltiutils();
1.359 www 55:
1.315 bowersj2 56: use POSIX qw(floor);
1.87 www 57:
1.435 foxr 58:
1.513 foxr 59:
1.435 foxr 60: my %perm=();
1.596.2.12.2. (raeburn 61:): my %old_essays=();
1.447 foxr 62:
1.513 foxr 63: # These variables are used to recover from ssi errors
64:
65: my $ssi_retries = 5;
66: my $ssi_error;
67: my $ssi_error_resource;
68: my $ssi_error_message;
1.596.2.12.2. 0.2.7(ra 69:an-25): my $registered_cleanup;
1.513 foxr 70:
71: sub ssi_with_retries {
72: my ($resource, $retries, %form) = @_;
73: my ($content, $response) = &Apache::loncommon::ssi_with_retries($resource, $retries, %form);
74: if ($response->is_error) {
75: $ssi_error = 1;
76: $ssi_error_resource = $resource;
77: $ssi_error_message = $response->code . " " . $response->message;
78: }
79:
80: return $content;
81:
82: }
83: #
84: # Prodcuces an ssi retry failure error message to the user:
85: #
86:
87: sub ssi_print_error {
88: my ($r) = @_;
1.516 raeburn 89: my $helpurl = &Apache::loncommon::top_nav_help('Helpdesk');
90: $r->print('
91: <br />
92: <h2>'.&mt('An unrecoverable network error occurred:').'</h2>
93: <p>
94: '.&mt('Unable to retrieve a resource from a server:').'<br />
95: '.&mt('Resource:').' '.$ssi_error_resource.'<br />
96: '.&mt('Error:').' '.$ssi_error_message.'
97: </p>
98: <p>'.
99: &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 />'.
100: &mt('If the error persists, please contact the [_1] for assistance.',$helpurl).
101: '</p>');
102: return;
1.513 foxr 103: }
104:
1.44 ng 105: #
1.146 albertel 106: # --- Retrieve the parts from the metadata file.---
1.596.2.12.2. 1(raebur 107:0): # Returns an array of everything that the resources stores away
108:0): #
109:0):
1.44 ng 110: sub getpartlist {
1.582 raeburn 111: my ($symb,$errorref) = @_;
1.439 albertel 112:
113: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 114: unless (ref($navmap)) {
115: if (ref($errorref)) {
116: $$errorref = 'navmap';
117: return;
118: }
119: }
1.439 albertel 120: my $res = $navmap->getBySymb($symb);
121: my $partlist = $res->parts();
122: my $url = $res->src();
1.596.2.12.2. 0.2.4(ra 123:ul-23): my $toolsymb;
124:ul-23): if ($url =~ /ext\.tool$/) {
125:ul-23): $toolsymb = $symb;
126:ul-23): }
127:ul-23): my @metakeys = split(/,/,&Apache::lonnet::metadata($url,'keys',$toolsymb));
1.439 albertel 128:
1.146 albertel 129: my @stores;
1.439 albertel 130: foreach my $part (@{ $partlist }) {
1.146 albertel 131: foreach my $key (@metakeys) {
132: if ($key =~ m/^stores_\Q$part\E_/) { push(@stores,$key); }
133: }
134: }
135: return @stores;
1.2 albertel 136: }
137:
1.129 ng 138: #--- Format fullname, username:domain if different for display
139: #--- Use anywhere where the student names are listed
140: sub nameUserString {
141: my ($type,$fullname,$uname,$udom) = @_;
142: if ($type eq 'header') {
1.485 albertel 143: return '<b> '.&mt('Fullname').' </b><span class="LC_internal_info">('.&mt('Username').')</span>';
1.129 ng 144: } else {
1.398 albertel 145: return ' '.$fullname.'<span class="LC_internal_info"> ('.$uname.
146: ($env{'user.domain'} eq $udom ? '' : ' ('.$udom.')').')</span>';
1.129 ng 147: }
148: }
149:
1.44 ng 150: #--- Get the partlist and the response type for a given problem. ---
151: #--- Indicate if a response type is coded handgraded or not. ---
1.596.2.12.2. 1(raebur 152:0): #--- Count responseIDs, essayresponse items, and dropbox items ---
153:0): #--- 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.596.2.12.2. 1(raebur 170:0): 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.596.2.12.2. 1(raebur 180:0): $numresp ++;
1.377 albertel 181: $response_types{$part}{$ids[$i]} = $types[$i];
1.596.2.12.2. 1(raebur 182:0): if ($types[$i] eq 'essay') {
183:0): $numessay ++;
184:0): if (&Apache::lonnet::EXT("resource.$part".'_'.$ids[$i].".uploadedfiletypes",$symb)) {
185:0): $numdropbox ++;
186:0): }
187:0): }
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.596.2.12.2. 1(raebur 193:0): 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.596.2.12.2. 1(raebur 220:0): #--- Show parts and response type
1.118 ng 221: sub showResourceInfo {
1.596.2.12.2. 1(raebur 222:0): my ($symb,$partlist,$responseType,$formname,$checkboxes,$uploads) = @_;
223:0): unless ((ref($partlist) eq 'ARRAY') && (ref($responseType) eq 'HASH')) {
224:0): return '<br clear="all">';
225:0): }
226:0): my $coltitle = &mt('Problem Part Shown');
227:0): if ($checkboxes) {
228:0): $coltitle = &mt('Problem Part');
229:0): } else {
230:0): my $checkedparts = 0;
231:0): foreach my $partid (&Apache::loncommon::get_env_multiple('form.vPart')) {
232:0): if (grep(/^\Q$partid\E$/,@{$partlist})) {
233:0): $checkedparts ++;
234:0): }
235:0): }
236:0): if ($checkedparts == scalar(@{$partlist})) {
237:0): return '<br clear="all">';
238:0): }
239:0): if ($uploads) {
240:0): $coltitle = &mt('Problem Part Selected');
1.582 raeburn 241: }
242: }
1.596.2.12.2. 1(raebur 243:0): my $result = '<div class="LC_left_float" style="display:inline-block;">';
1.584 bisitz 244: if ($checkboxes) {
1.596.2.12.2. 1(raebur 245:0): my $legend = &mt('Parts to display');
246:0): if ($uploads) {
247:0): $legend = &mt('Part(s) with dropbox');
248:0): }
249:0): $result .= '<fieldset style="display:inline-block;"><legend>'.$legend.'</legend>'.
250:0): '<span class="LC_nobreak">'.
251:0): '<label><input type="radio" name="chooseparts" value="0" onclick="toggleParts('."'$formname'".');" checked="checked" />'.
252:0): &mt('All parts').'</label>'.(' 'x2).
253:0): '<label><input type="radio" name="chooseparts" value="1" onclick="toggleParts('."'$formname'".');" />'.
254:0): &mt('Selected parts').'</label></span>'.
255:0): '<div id="LC_partselector" style="display:none">';
1.584 bisitz 256: }
1.596.2.12.2. 1(raebur 257:0): $result .= &Apache::loncommon::start_data_table()
258:0): .&Apache::loncommon::start_data_table_header_row();
259:0): if ($checkboxes) {
260:0): $result .= '<th>'.&mt('Display?').'</th>';
261:0): }
262:0): $result .= '<th>'.$coltitle.'</th>'
263:0): .'<th>'.&mt('Res. ID').'</th>'
264:0): .'<th>'.&mt('Type').'</th>'
265:0): .&Apache::loncommon::end_data_table_header_row();
1.154 albertel 266: my %partsseen;
1.524 raeburn 267: foreach my $partID (sort(keys(%$responseType))) {
1.584 bisitz 268: foreach my $resID (sort(keys(%{ $responseType->{$partID} }))) {
269: my $responsetype = $responseType->{$partID}->{$resID};
1.596.2.12.2. 1(raebur 270:0): if ($uploads) {
271:0): next unless ($responsetype eq 'essay');
272:0): next unless (&Apache::lonnet::EXT("resource.$partID".'_'."$resID.uploadedfiletypes",$symb));
273:0): }
274:0): my $display_part=&get_display_part($partID,$symb);
275:0): if (exists($partsseen{$partID})) {
276:0): $result.=&Apache::loncommon::continue_data_table_row();
277:0): } else {
278:0): $partsseen{$partID}=scalar(keys(%{$responseType->{$partID}}));
279:0): $result.=&Apache::loncommon::start_data_table_row().
280:0): '<td rowspan="'.$partsseen{$partID}.'" style="vertical-align:middle">';
281:0): if ($checkboxes) {
282:0): $result.='<input type="checkbox" name="vPart" checked="checked" value="'.$partID.'" /></td>'.
283:0): '<td rowspan="'.$partsseen{$partID}.'" style="vertical-align:middle">'.$display_part.'</td>';
1.584 bisitz 284: } else {
1.596.2.12.2. 1(raebur 285:0): $result.=$display_part.'</td>';
1.584 bisitz 286: }
287: }
1.596.2.12.2. 1(raebur 288:0): $result.='<td>'.'<span class="LC_internal_info">'.$resID.'</span></td>'
1.584 bisitz 289: .'<td>'.&mt($responsetype).'</td>'
290: .&Apache::loncommon::end_data_table_row();
291: }
1.118 ng 292: }
1.584 bisitz 293: $result.=&Apache::loncommon::end_data_table();
1.596.2.12.2. 1(raebur 294:0): if ($checkboxes) {
295:0): $result .= '</div></fieldset>';
296:0): }
297:0): $result .= '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
2(raebur 298:0): if (!keys(%partsseen)) {
299:0): $result = '';
300:0): if ($uploads) {
301:0): return '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
302:0): '<p class="LC_info">'.
303:0): &mt('No dropbox items or essayresponse items with uploadedfiletypes set.').
304:0): '</p>';
305:0): } else {
306:0): return '<br clear="all" />';
307:0): }
0.2.4(ra 308:ul-23): }
1(raebur 309:0): return $result;
310:0): }
311:0):
312:0): sub part_selector_js {
313:0): my $js = <<"END";
314:0): function toggleParts(formname) {
315:0): if (document.getElementById('LC_partselector')) {
316:0): var index = '';
317:0): if (document.forms.length) {
318:0): for (var i=0; i<document.forms.length; i++) {
319:0): if (document.forms[i].name == formname) {
320:0): index = i;
321:0): break;
322:0): }
323:0): }
324:0): }
325:0): if ((index != '') && (document.forms[index].elements['chooseparts'].length > 1)) {
326:0): for (var i=0; i<document.forms[index].elements['chooseparts'].length; i++) {
327:0): if (document.forms[index].elements['chooseparts'][i].checked) {
328:0): var val = document.forms[index].elements['chooseparts'][i].value;
329:0): if (document.forms[index].elements['chooseparts'][i].value == 1) {
330:0): document.getElementById('LC_partselector').style.display = 'block';
331:0): } else {
332:0): document.getElementById('LC_partselector').style.display = 'none';
333:0): }
334:0): }
335:0): }
336:0): }
337:0): }
338:0): }
339:0): END
340:0): return &Apache::lonhtmlcommon::scripttag($js);
1.118 ng 341: }
342:
1.434 albertel 343: sub reset_caches {
344: &reset_analyze_cache();
345: &reset_perm();
1.596.2.12.2. (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.596.2.12.2. (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.596.2.2 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.596.2.12.2. (raeburn 393:): if ($bubbles_per_row ne '') {
394:): $form{'bubbles_per_row'} = $bubbles_per_row;
395:): }
1.596.2.2 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.596.2.2 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.596.2.2 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.596.2.2 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.596.2.12.2. 1(raebur 436:7): 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.596.2.12.2. 1(raebur 444:7): if ($scancode) {
445:7): if (ref($add_to_form) eq 'HASH') {
446:7): $add_to_form->{'code_for_randomlist'} = $scancode;
447:7): } else {
448:7): $add_to_form = { 'code_for_randomlist' => $scancode,};
449:7): }
450:7): }
(raeburn 451:): my $analyze =
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.596.2.2 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.596.2.12.2. 8(raebur 480:4): my @answer = %answer;
481:4): %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.596.2.1 raeburn 495: $bottomrow.'</tr></table></blockquote>';
1.148 albertel 496: } elsif ($response eq 'match') {
497: my %answer=&Apache::lonnet::str2hash($answer);
1.596.2.12.2. 8(raebur 498:4): my @answer = %answer;
499:4): %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.596.2.8 raeburn 519: $bottomrow.'</tr></table></blockquote>';
1.148 albertel 520: } elsif ($response eq 'radiobutton') {
521: my %answer=&Apache::lonnet::str2hash($answer);
1.596.2.12.2. 1(raebur 522:0): my @answer = %answer;
523:0): %answer = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.148 albertel 524: my ($toprow,$bottomrow);
1.434 albertel 525: my $correct =
1.596.2.2 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.596.2.4 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.596.2.12.2. 4(raebur 556:8): $answer = &Apache::lontexconvert::msgtexconverted($answer);
2(raebur 557:5): return '<br /><br /><blockquote><tt>'.&keywords_highlight($answer).'</tt></blockquote>';
1.268 albertel 558: } elsif ( $response eq 'organic') {
1.596.2.12.2. 8(raebur 559:4): my $result=&mt('Smile representation: [_1]',
560:4): '"<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.596.2.12.2. 8(raebur 594:4): } elsif ( $response =~ m/(?:numerical|formula|custom)/) {
0.2.4(ra 595:ul-23): # Respect multiple input fields, see Bug #5409
1.440 albertel 596: $answer =
597: &Apache::loncommon::format_previous_attempt_value('submission',
598: $answer);
1.596.2.12.2. 1(raebur 599:0): return $answer;
1.122 ng 600: }
1.596.2.12.2. 8(raebur 601:4): 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.596.2.12.2. 1(raebur 607:0): $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.596.2.12.2. 0.2.7(ra 641:an-25): 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.596.2.12.2. 0.2.7(ra 669:an-25): my %passback;
1(raebur 670:0): my ($cdom,$cnum,$partlist);
671:0): if (($filterbysubmstatus) && ($submitonly ne 'all') && ($symb ne '')) {
672:0): $cdom = $env{"course.$env{'request.course.id'}.domain"};
673:0): $cnum = $env{"course.$env{'request.course.id'}.num"};
674:0): my $res_error;
675:0): ($partlist) = &response_type($symb,\$res_error);
0.2.7(ra 676:an-25): } elsif ($filterbypbid) {
677:an-25): $cdom = $env{"course.$env{'request.course.id'}.domain"};
678:an-25): $cnum = $env{"course.$env{'request.course.id'}.num"};
1(raebur 679:0): }
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.596.2.12.2. 1(raebur 696:0): 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.596.2.12.2. 1(raebur 713:0): $exclude = 0;
1.453 banghart 714: }
1.450 banghart 715: }
716: if ($exclude) {
717: delete($classlist->{$student});
1.596.2.12.2. 1(raebur 718:0): next;
1.450 banghart 719: }
720: }
1.596.2.12.2. 1(raebur 721:0): if (($filterbysubmstatus) && ($submitonly ne 'all') && ($symb ne '')) {
722:0): my $udom =
723:0): $classlist->{$student}->[&Apache::loncoursedata::CL_SDOM()];
724:0): my $uname =
725:0): $classlist->{$student}->[&Apache::loncoursedata::CL_SNAME()];
726:0): if (($symb ne '') && ($udom ne '') && ($uname ne '')) {
727:0): if ($submitonly eq 'queued') {
728:0): my %queue_status =
729:0): &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
730:0): $udom,$uname);
731:0): if (!defined($queue_status{'gradingqueue'})) {
732:0): delete($classlist->{$student});
733:0): next;
734:0): }
735:0): } else {
736:0): my (%status) =&student_gradeStatus($symb,$udom,$uname,$partlist);
737:0): my $submitted = 0;
738:0): my $graded = 0;
739:0): my $incorrect = 0;
740:0): foreach (keys(%status)) {
741:0): $submitted = 1 if ($status{$_} ne 'nothing');
742:0): $graded = 1 if ($status{$_} =~ /^ungraded/);
743:0): $incorrect = 1 if ($status{$_} =~ /^incorrect/);
744:0):
745:0): my ($foo,$partid,$foo1) = split(/\./,$_);
746:0): if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
747:0): $submitted = 0;
748:0): }
749:0): }
750:0): if (!$submitted && ($submitonly eq 'yes' ||
751:0): $submitonly eq 'incorrect' ||
752:0): $submitonly eq 'graded')) {
753:0): delete($classlist->{$student});
754:0): next;
755:0): } elsif (!$graded && ($submitonly eq 'graded')) {
756:0): delete($classlist->{$student});
757:0): next;
758:0): } elsif (!$incorrect && $submitonly eq 'incorrect') {
759:0): delete($classlist->{$student});
760:0): next;
761:0): }
762:0): }
763:0): }
764:0): }
0.2.7(ra 765:an-25): if ($filterbypbid) {
766:an-25): if (ref($possibles) eq 'HASH') {
767:an-25): unless (exists($possibles->{$student})) {
768:an-25): delete($classlist->{$student});
769:an-25): next;
770:an-25): }
771:an-25): }
772:an-25): my $udom =
773:an-25): $classlist->{$student}->[&Apache::loncoursedata::CL_SDOM()];
774:an-25): my $uname =
775:an-25): $classlist->{$student}->[&Apache::loncoursedata::CL_SNAME()];
776:an-25): if (($udom ne '') && ($uname ne '')) {
777:an-25): my %pbinfo = &Apache::lonnet::get('nohist_'.$cdom.'_'.$cnum.'_linkprot_pb',[$filterbypbid],$udom,$uname);
778:an-25): if (ref($pbinfo{$filterbypbid}) eq 'ARRAY') {
779:an-25): $passback{$student} = $pbinfo{$filterbypbid};
780:an-25): } else {
781:an-25): delete($classlist->{$student});
782:an-25): next;
783:an-25): }
784:an-25): }
785:an-25): }
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.596.2.12.2. 0.2.7(ra 801:an-25): 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.596.2.12.2. 1(raebur 815:0): # 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.596.2.12.2. 1(raebur 828:0): # can view whole class
1.103 albertel 829: return 1;
830: } else {
831: if ($sec eq $perm{'vgr_section'}) {
1.596.2.12.2. 1(raebur 832:0): #can view the requested section
1.103 albertel 833: return 1;
834: } else {
1.596.2.12.2. 1(raebur 835:0): # can't view the requested section
1.103 albertel 836: return 0;
837: }
838: }
839: }
1.596.2.12.2. 1(raebur 840:0): #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.596.2.12.2. 1(raebur 865:0): 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.596.2.12.2. 1(raebur 871:0): "\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.596.2.12.2. (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.596.2.4 raeburn 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.596.2.12.2. (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.596.2.12.2. (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.596.2.12.2. (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.596.2.12.2. 1(raebur 967:0):
968:0): sub initialverifyreceipt {
969:0): my ($request,$symb) = @_;
970:0): &commonJSfunctions($request);
971:0): return '<form name="gradingMenu" action=""><input type="submit" value="'.&mt('Verify Receipt Number.').'" />'.
972:0): &Apache::lonnet::recprefix($env{'request.course.id'}).
973:0): '-<input type="text" name="receipt" size="4" />'.
974:0): '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
975:0): '<input type="hidden" name="command" value="verify" />'.
976:0): "</form>\n";
977:0): }
978:0):
1.44 ng 979: #--- Check whether a receipt number is valid.---
980: sub verifyreceipt {
1.596.2.12.2. 1(raebur 981:0): 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.596.2.12.2. 1(raebur 988:0): my $title =
1.487 albertel 989: '<h3><span class="LC_info">'.
1.596.2.12.2. 1(raebur 990:0): &mt('Verifying Receipt Number [_1]',$receipt).
991:0): '</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.596.2.12.2. 1(raebur 1061:0): return $string;
1.44 ng 1062: }
1063:
1.596.2.12.2. 0.2.7(ra 1064:an-25): #-------------------------------------------------------------------
1065:an-25):
1066:an-25): #------------------------------------------- Grade Passback Routines
1067:an-25): #
1068:an-25):
1069:an-25): sub initialpassback {
1070:an-25): my ($request,$symb) = @_;
1071:an-25): my $cdom = $env{"course.$env{'request.course.id'}.domain"};
1072:an-25): my $cnum = $env{"course.$env{'request.course.id'}.num"};
1073:an-25): my $crstype = &Apache::loncommon::course_type();
1074:an-25): my %passback = &Apache::lonnet::dump('nohist_linkprot_passback',$cdom,$cnum);
1075:an-25): my $readonly;
1076:an-25): unless ($perm{'mgr'}) {
1077:an-25): $readonly = 1;
1078:an-25): }
1079:an-25): my $formname = 'initialpassback';
1080:an-25): my $navmap = Apache::lonnavmaps::navmap->new();
1081:an-25): my $output;
1082:an-25): if (!defined($navmap)) {
1083:an-25): if ($crstype eq 'Community') {
1084:an-25): $output = &mt('Unable to retrieve information about community contents');
1085:an-25): } else {
1086:an-25): $output = &mt('Unable to retrieve information about course contents');
1087:an-25): }
1088:an-25): return '<p>'.$output.'</p>';
1089:an-25): }
1090:an-25): return &Apache::loncourserespicker::create_picker($navmap,'passback',$formname,$crstype,undef,
1091:an-25): undef,undef,undef,undef,undef,undef,
1092:an-25): \%passback,$readonly);
1093:an-25): }
1094:an-25):
1095:an-25): sub passback_filters {
1096:an-25): my ($request,$symb) = @_;
1097:an-25): my $cdom = $env{"course.$env{'request.course.id'}.domain"};
1098:an-25): my $cnum = $env{"course.$env{'request.course.id'}.num"};
1099:an-25): my $crstype = &Apache::loncommon::course_type();
1100:an-25): my ($launcher,$appname,$setter,$linkuri,$linkprotector,$scope,$chosen);
1101:an-25): if ($env{'form.passback'} ne '') {
1102:an-25): $chosen = &unescape($env{'form.passback'});
1103:an-25): ($linkuri,$linkprotector,$scope) = split("\0",$chosen);
1104:an-25): ($launcher,$appname,$setter) = &get_passback_launcher($cdom,$cnum,$chosen);
1105:an-25): }
1106:an-25): my $result;
1107:an-25): if ($launcher ne '') {
1108:an-25): $result = &launcher_info_box($launcher,$appname,$setter,$linkuri,$scope).
1109:an-25): '<p><br />'.&mt('Set criteria to use to list students for possible passback of scores, then push Next [_1]',
1110:an-25): '→').
1111:an-25): '</p>';
1112:an-25): }
1113:an-25): $result .= '<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1114:an-25): '<input type="hidden" name="passback" value="'.&escape($chosen).'" />'."\n".
1115:an-25): '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1116:an-25): my ($submittext,$newcommand);
1117:an-25): if ($launcher ne '') {
1118:an-25): $submittext = &mt('Next').' →';
1119:an-25): $newcommand = 'passbacknames';
1120:an-25): $result .= &selectfield(0)."\n";
1121:an-25): } else {
1122:an-25): $submittext = '← '.&mt('Previous');
1123:an-25): $newcommand = 'initialpassback';
1124:an-25): if ($env{'form.passback'}) {
1125:an-25): $result .= '<span class="LC_warning">'.&mt('Invalid launcher').'</span>'."\n";
1126:an-25): } else {
1127:an-25): $result .= '<span class="LC_warning">'.&mt('No launcher selected').'</span>'."\n";
1128:an-25): }
1129:an-25): }
1130:an-25): $result .= '<input type="hidden" name="command" value="'.$newcommand.'" />'."\n".
1131:an-25): '<div>'."\n".
1132:an-25): '<input type="submit" value="'.$submittext.'" />'."\n".
1133:an-25): '</div>'."\n".
1134:an-25): '</form>'."\n";
1135:an-25): return $result;
1136:an-25): }
1137:an-25):
1138:an-25): sub names_for_passback {
1139:an-25): my ($request,$symb) = @_;
1140:an-25): my $cdom = $env{"course.$env{'request.course.id'}.domain"};
1141:an-25): my $cnum = $env{"course.$env{'request.course.id'}.num"};
1142:an-25): my $crstype = &Apache::loncommon::course_type();
1143:an-25): my ($launcher,$appname,$setter,$linkuri,$linkprotector,$scope,$chosen);
1144:an-25): if ($env{'form.passback'} ne '') {
1145:an-25): $chosen = &unescape($env{'form.passback'});
1146:an-25): ($linkuri,$linkprotector,$scope) = split("\0",$chosen);
1147:an-25): ($launcher,$appname,$setter) = &get_passback_launcher($cdom,$cnum,$chosen);
1148:an-25): }
1149:an-25): my ($result,$ctr,$newcommand,$submittext);
1150:an-25): if ($launcher ne '') {
1151:an-25): $result = &launcher_info_box($launcher,$appname,$setter,$linkuri,$scope);
1152:an-25): }
1153:an-25): $ctr = 0;
1154:an-25): my @statuses = &Apache::loncommon::get_env_multiple('form.Status');
1155:an-25): my $stu_status = join(':',@statuses);
1156:an-25): $result .= '<form action="/adm/grades" method="post" name="passbackusers">'."\n".
1157:an-25): '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1158:an-25): if ($launcher ne '') {
1159:an-25): $result .= '<input type="hidden" name="passback" value="'.&escape($chosen).'" />'."\n".
1160:an-25): '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n";
1161:an-25): my ($sections,$groups,$group_display,$disabled) = §ions_and_groups();
1162:an-25): my $section_display = join(' ',@{$sections});
1163:an-25): my $status_display;
1164:an-25): if ((grep(/^Any$/,@statuses)) ||
1165:an-25): (@statuses == 3)) {
1166:an-25): $status_display = &mt('Any');
1167:an-25): } else {
1168:an-25): $status_display = join(' '.&mt('or').' ',map { &mt($_); } @statuses);
1169:an-25): }
1170:an-25): $result .= '<p>'.&mt('Student(s) with stored passback credentials for [_1], and also satisfy:',
1171:an-25): '<span class="LC_cusr_emph">'.$linkuri.'</span>').
1172:an-25): '<ul>'.
1173:an-25): '<li>'.&mt('Section(s)').": $section_display</li>\n".
1174:an-25): '<li>'.&mt('Group(s)').": $group_display</li>\n".
1175:an-25): '<li>'.&mt('Status').": $status_display</li>\n".
1176:an-25): '</ul>';
1177:an-25): my ($classlist,undef,$fullname) = &getclasslist($sections,'1',$groups,'','','',$chosen);
1178:an-25): if (keys(%$fullname)) {
1179:an-25): $newcommand = 'passbackscores';
1180:an-25): $result .= &build_section_inputs().
1181:an-25): &checkselect_js('passbackusers').
1182:an-25): '<p><br />'.
1183:an-25): &mt("To send scores, check box(es) next to the student's name(s), then push 'Send Scores'.").
1184:an-25): '</p>'.
1185:an-25): &check_script('passbackusers', 'stuinfo')."\n".
1186:an-25): '<input type="button" '."\n".
1187:an-25): 'onclick="javascript:checkSelect(this.form.stuinfo);" '."\n".
1188:an-25): 'value="'.&mt('Send Scores').'" /> <br />'."\n".
1189:an-25): &check_buttons()."\n".
1190:an-25): &Apache::loncommon::start_data_table().
1191:an-25): &Apache::loncommon::start_data_table_header_row();
1192:an-25): my $loop = 0;
1193:an-25): while ($loop < 2) {
1194:an-25): $result .= '<th>'.&mt('No.').'</th><th>'.&mt('Select').'</th>'.
1195:an-25): '<th>'.&nameUserString('header').' '.&mt('Section/Group').'</th>';
1196:an-25): $loop++;
1197:an-25): }
1198:an-25): $result .= &Apache::loncommon::end_data_table_header_row()."\n";
1199:an-25): foreach my $student (sort
1200:an-25): {
1201:an-25): if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
1202:an-25): return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
1203:an-25): }
1204:an-25): return $a cmp $b;
1205:an-25): }
1206:an-25): (keys(%$fullname))) {
1207:an-25): $ctr++;
1208:an-25): my $section = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
1209:an-25): my $group = $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1210:an-25): my $udom = $classlist->{$student}->[&Apache::loncoursedata::CL_SDOM()];
1211:an-25): my $uname = $classlist->{$student}->[&Apache::loncoursedata::CL_SNAME()];
1212:an-25): if ( $perm{'vgr'} eq 'F' ) {
1213:an-25): if ($ctr%2 ==1) {
1214:an-25): $result.= &Apache::loncommon::start_data_table_row();
1215:an-25): }
1216:an-25): $result .= '<td align="right">'.$ctr.' </td>'.
1217:an-25): '<td align="center"><label><input type="checkbox" name="stuinfo" value="'.
1218:an-25): $student.':'.$$fullname{$student}.':::SECTION'.$section.
1219:an-25): ') " /> </label></td>'."\n".'<td>'.
1220:an-25): &nameUserString(undef,$$fullname{$student},$uname,$udom).
1221:an-25): ' '.$section.($group ne '' ?'/'.$group:'').'</td>'."\n";
1222:an-25):
1223:an-25): if ($ctr%2 ==0) {
1224:an-25): $result .= &Apache::loncommon::end_data_table_row()."\n";
1225:an-25): }
1226:an-25): }
1227:an-25): }
1228:an-25): if ($ctr%2 ==1) {
1229:an-25): $result .= &Apache::loncommon::end_data_table_row();
1230:an-25): }
1231:an-25): $result .= &Apache::loncommon::end_data_table()."\n";
1232:an-25): if ($ctr) {
1233:an-25): $result .= '<input type="button" '.
1234:an-25): 'onclick="javascript:checkSelect(this.form.stuinfo);" '.
1235:an-25): 'value="'.&mt('Send Scores').'" />'."\n";
1236:an-25): }
1237:an-25): } else {
1238:an-25): $submittext = '← '.&mt('Previous');
1239:an-25): $newcommand = 'passback';
1240:an-25): $result .= '<span class="LC_warning">'.&mt('No students match the selection criteria').'</p>';
1241:an-25): }
1242:an-25): } else {
1243:an-25): $newcommand = 'initialpassback';
1244:an-25): $submittext = &mt('Start over');
1245:an-25): if ($env{'form.passback'}) {
1246:an-25): $result .= '<span class="LC_warning">'.&mt('Invalid launcher').'</span>'."\n";
1247:an-25): } else {
1248:an-25): $result .= '<span class="LC_warning">'.&mt('No launcher selected').'</span>'."\n";
1249:an-25): }
1250:an-25): }
1251:an-25): $result .= '<input type="hidden" name="command" value="'.$newcommand.'" />'."\n";
1252:an-25): if (!$ctr) {
1253:an-25): $result .= '<div>'."\n".
1254:an-25): '<input type="submit" value="'.$submittext.'" />'."\n".
1255:an-25): '</div>'."\n";
1256:an-25): }
1257:an-25): $result .= '</form>'."\n";
1258:an-25): return $result;
1259:an-25): }
1260:an-25):
1261:an-25): sub do_passback {
1262:an-25): my ($request,$symb) = @_;
1263:an-25): my $cdom = $env{"course.$env{'request.course.id'}.domain"};
1264:an-25): my $cnum = $env{"course.$env{'request.course.id'}.num"};
1265:an-25): my $crstype = &Apache::loncommon::course_type();
1266:an-25): my ($launchsymb,$appname,$setter,$linkuri,$linkprotector,$scope,$chosen);
1267:an-25): if ($env{'form.passback'} ne '') {
1268:an-25): $chosen = &unescape($env{'form.passback'});
1269:an-25): ($linkuri,$linkprotector,$scope) = split("\0",$chosen);
1270:an-25): ($launchsymb,$appname,$setter) = &get_passback_launcher($cdom,$cnum,$chosen);
1271:an-25): }
1272:an-25): if ($launchsymb ne '') {
1273:an-25): $request->print(&launcher_info_box($launchsymb,$appname,$setter,$linkuri,$scope));
1274:an-25): }
1275:an-25): my $error;
1276:an-25): if ($perm{'mgr'}) {
1277:an-25): if ($launchsymb ne '') {
1278:an-25): my @poss_students = &Apache::loncommon::get_env_multiple('form.stuinfo');
1279:an-25): if (@poss_students) {
1280:an-25): my %possibles;
1281:an-25): foreach my $item (@poss_students) {
1282:an-25): my ($stuname,$studom) = split(/:/,$item,3);
1283:an-25): $possibles{$stuname.':'.$studom} = 1;
1284:an-25): }
1285:an-25): my ($sections,$groups,$group_display,$disabled) = §ions_and_groups();
1286:an-25): my ($classlist,undef,$fullname,$pbinfo) =
1287:an-25): &getclasslist($sections,'1',$groups,'','','',$chosen,\%possibles);
1288:an-25): if ((ref($classlist) eq 'HASH') && (ref($pbinfo) eq 'HASH')) {
1289:an-25): my %passback = %{$pbinfo};
1290:an-25): my (%tosend,%remotenotok,%scorenotok,%zeroposs,%nopbinfo);
1291:an-25): foreach my $possible (keys(%possibles)) {
1292:an-25): if ((exists($classlist->{$possible})) &&
1293:an-25): (exists($passback{$possible})) && (ref($passback{$possible}) eq 'ARRAY')) {
1294:an-25): $tosend{$possible} = 1;
1295:an-25): }
1296:an-25): }
1297:an-25): if (keys(%tosend)) {
1298:an-25): my ($lti_in_use,$crsdef);
1299:an-25): my ($ltinum,$ltitype) = ($linkprotector =~ /^(\d+)(c|d)$/);
1300:an-25): if ($ltitype eq 'c') {
1301:an-25): my %crslti = &Apache::lonnet::get_course_lti($cnum,$cdom,'provider');
1302:an-25): $lti_in_use = $crslti{$ltinum};
1303:an-25): $crsdef = 1;
1304:an-25): } else {
1305:an-25): my %domlti = &Apache::lonnet::get_domain_lti($cdom,'linkprot');
1306:an-25): $lti_in_use = $domlti{$ltinum};
1307:an-25): }
1308:an-25): if (ref($lti_in_use) eq 'HASH') {
1309:an-25): my $msgformat = $lti_in_use->{'passbackformat'};
1310:an-25): my $keynum = $lti_in_use->{'cipher'};
1311:an-25): my $scoretype = 'decimal';
1312:an-25): if ($lti_in_use->{'scoreformat'} =~ /^(decimal|ratio|percentage)$/) {
1313:an-25): $scoretype = $1;
1314:an-25): }
1315:an-25): my $pbmap;
1316:an-25): if ($launchsymb =~ /\.(page|sequence)$/) {
1317:an-25): $pbmap = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($launchsymb))[2]);
1318:an-25): } else {
1319:an-25): $pbmap = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($launchsymb))[0]);
1320:an-25): }
1321:an-25): $pbmap = &Apache::lonnet::clutter($pbmap);
1322:an-25): my $pbscope;
1323:an-25): if ($scope eq 'res') {
1324:an-25): $pbscope = 'resource';
1325:an-25): } elsif ($scope eq 'map') {
1326:an-25): $pbscope = 'nonrec';
1327:an-25): } elsif ($scope eq 'rec') {
1328:an-25): $pbscope = 'map';
1329:an-25): }
1330:an-25): my %pb = &common_passback_info();
1331:an-25): my $numstudents = scalar(keys(%tosend));
1332:an-25): my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($request,$numstudents);
1333:an-25): my $outcome = &Apache::loncommon::start_data_table().
1334:an-25): &Apache::loncommon::start_data_table_header_row();
1335:an-25): my $loop = 0;
1336:an-25): while ($loop < 2) {
1337:an-25): $outcome .= '<th>'.&mt('No.').'</th>'.
1338:an-25): '<th>'.&nameUserString('header').' '.&mt('Section/Group').'</th>'.
1339:an-25): '<th>'.&mt('Score').'</th>';
1340:an-25): $loop++;
1341:an-25): }
1342:an-25): $outcome .= &Apache::loncommon::end_data_table_header_row()."\n";
1343:an-25): my $ctr=0;
1344:an-25): foreach my $student (sort
1345:an-25): {
1346:an-25): if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
1347:an-25): return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
1348:an-25): }
1349:an-25): return $a cmp $b;
1350:an-25): } (keys(%$fullname))) {
1351:an-25): next unless ($tosend{$student});
1352:an-25): my ($uname,$udom) = split(/:/,$student);
1353:an-25): &Apache::lonhtmlcommon::Increment_PrgWin($request,\%prog_state,'last student');
1354:an-25): my ($uname,$udom) = split(/:/,$student);
1355:an-25): my $uhome = &Apache::lonnet::homeserver($uname,$udom),
1356:an-25): my $id = $passback{$student}[0],
1357:an-25): my $url = $passback{$student}[1],
1358:an-25): my ($total,$possible,$usec);
1359:an-25): if (ref($classlist->{$student}) eq 'ARRAY') {
1360:an-25): $usec = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION];
1361:an-25): }
1362:an-25): if ($pbscope eq 'resource') {
1363:an-25): $total = 0;
1364:an-25): $possible = 0;
1365:an-25): my $navmap = Apache::lonnavmaps::navmap->new($uname,$udom);
1366:an-25): if (ref($navmap)) {
1367:an-25): my $res = $navmap->getBySymb($launchsymb);
1368:an-25): if (ref($res)) {
1369:an-25): my $partlist = $res->parts();
1370:an-25): if (ref($partlist) eq 'ARRAY') {
1371:an-25): my %record = &Apache::lonnet::restore($launchsymb,$env{'request.course.id'},$udom,$uname);
1372:an-25): foreach my $part (@{$partlist}) {
1373:an-25): next if ($record{"resource.$part.solved"} =~/^excused/);
1374:an-25): my $weight = &Apache::lonnet::EXT("resource.$part.weight",$launchsymb,$udom,$uname,$usec);
1375:an-25): $possible += $weight;
1376:an-25): if (($record{'version'}) && (exists($record{"resource.$part.awarded"}))) {
1377:an-25): my $awarded = $record{"resource.$part.awarded"};
1378:an-25): if ($awarded) {
1379:an-25): $total += $weight * $awarded;
1380:an-25): }
1381:an-25): }
1382:an-25): }
1383:an-25): }
1384:an-25): }
1385:an-25): }
1386:an-25): } elsif (($pbscope eq 'map') || ($pbscope eq 'nonrec')) {
1387:an-25): ($total,$possible) =
1388:an-25): &Apache::lonhomework::get_lti_score($uname,$udom,$usec,$pbmap,$pbscope);
1389:an-25): }
1390:an-25): if (($id ne '') && ($url ne '') && ($possible)) {
1391:an-25): my ($sent,$score,$code,$result) =
1392:an-25): &LONCAPA::ltiutils::send_grade($cdom,$cnum,$crsdef,$pb{'type'},$ltinum,$keynum,$id,
1393:an-25): $url,$scoretype,$pb{'sigmethod'},$msgformat,$total,$possible);
1394:an-25): my $no_passback;
1395:an-25): if ($sent) {
1396:an-25): if ($code == 200) {
1397:an-25): delete($tosend{$student});
1398:an-25): my $namespace = $cdom.'_'.$cnum.'_lp_passback';
1399:an-25): my $store = {
1400:an-25): 'score' => $score,
1401:an-25): 'ip' => $pb{'ip'},
1402:an-25): 'host' => $pb{'lonhost'},
1403:an-25): 'protector' => $linkprotector,
1404:an-25): 'deeplink' => $linkuri,
1405:an-25): 'scope' => $scope,
1406:an-25): 'url' => $url,
1407:an-25): 'id' => $id,
1408:an-25): 'clientip' => $pb{'clientip'},
1409:an-25): 'whodoneit' => $env{'user.name'}.':'.$env{'user.domain'},
1410:an-25): };
1411:an-25): my $value='';
1412:an-25): foreach my $key (keys(%{$store})) {
1413:an-25): $value.=&escape($key).'='.&Apache::lonnet::freeze_escape($store->{$key}).'&';
1414:an-25): }
1415:an-25): $value=~s/\&$//;
1416:an-25): &Apache::lonnet::courselog(&escape($linkuri).':'.$uname.':'.$udom.':EXPORT:'.$value);
1417:an-25): &Apache::lonnet::cstore({'score' => $score},$chosen,$namespace,$udom,$uname,'',$pb{'ip'},1);
1418:an-25): $ctr++;
1419:an-25): if ($ctr%2 ==1) {
1420:an-25): $outcome .= &Apache::loncommon::start_data_table_row();
1421:an-25): }
1422:an-25): my $group = $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1423:an-25): $outcome .= '<td align="right">'.$ctr.' </td>'.
1424:an-25): '<td>'.&nameUserString(undef,$$fullname{$student},$uname,$udom).
1425:an-25): ' '.$usec.($group ne '' ?'/'.$group:'').'</td>'.
1426:an-25): '<td>'.$score.'</td>'."\n";
1427:an-25): if ($ctr%2 ==0) {
1428:an-25): $outcome .= &Apache::loncommon::end_data_table_row()."\n";
1429:an-25): }
1430:an-25): } else {
1431:an-25): $remotenotok{$student} = 1;
1432:an-25): $no_passback = "Passback response for ".$linkprotector." was $code ($result)";
1433:an-25): &Apache::lonnet::logthis($no_passback." for $uname:$udom in ${cdom}_${cnum}");
1434:an-25): }
1435:an-25): } else {
1436:an-25): $scorenotok{$student} = 1;
1437:an-25): $no_passback = "Passback of grades not sent for ".$linkprotector;
1438:an-25): &Apache::lonnet::logthis($no_passback." for $uname:$udom in ${cdom}_${cnum}");
1439:an-25): }
1440:an-25): if ($no_passback) {
1441:an-25): &Apache::lonnet::log($udom,$uname,$uhome,$no_passback." score: $score; total: $total; possible: $possible");
1442:an-25): my $key = &Time::HiRes::time().':'.$uname.':'.$udom.':'.
1443:an-25): "$linkuri\0$linkprotector\0$scope";
1444:an-25): my $ltigrade = {
1445:an-25): $key => {
1446:an-25): 'ltinum' => $ltinum,
1447:an-25): 'lti' => $lti_in_use,
1448:an-25): 'crsdef' => $crsdef,
1449:an-25): 'cid' => $cdom.'_'.$cnum,
1450:an-25): 'uname' => $uname,
1451:an-25): 'udom' => $udom,
1452:an-25): 'uhome' => $uhome,
1453:an-25): 'pbid' => $id,
1454:an-25): 'pburl' => $url,
1455:an-25): 'pbtype' => $pb{'type'},
1456:an-25): 'pbscope' => $pbscope,
1457:an-25): 'pbmap' => $pbmap,
1458:an-25): 'pbsymb' => $launchsymb,
1459:an-25): 'format' => $scoretype,
1460:an-25): 'scope' => $scope,
1461:an-25): 'clientip' => $pb{'clientip'},
1462:an-25): 'linkprot' => $linkprotector.':'.$linkuri,
1463:an-25): 'total' => $total,
1464:an-25): 'possible' => $possible,
1465:an-25): 'score' => $score,
1466:an-25): },
1467:an-25): };
1468:an-25): &Apache::lonnet::put('linkprot_passback_pending',$ltigrade,$cdom,$cnum);
1469:an-25): }
1470:an-25): } else {
1471:an-25): if (($id ne '') && ($url ne '')) {
1472:an-25): $zeroposs{$student} = 1;
1473:an-25): } else {
1474:an-25): $nopbinfo{$student} = 1;
1475:an-25): }
1476:an-25): }
1477:an-25): }
1478:an-25): &Apache::lonhtmlcommon::Close_PrgWin($request,\%prog_state);
1479:an-25): if ($ctr%2 ==1) {
1480:an-25): $outcome .= &Apache::loncommon::end_data_table_row();
1481:an-25): }
1482:an-25): $outcome .= &Apache::loncommon::end_data_table();
1483:an-25): if ($ctr) {
1484:an-25): $request->print('<p><br />'.&mt('Scores sent to launcher CMS').'</p>'.
1485:an-25): '<p>'.$outcome.'</p>');
1486:an-25): } else {
1487:an-25): $request->print('<p>'.&mt('No scores sent to launcher CMS').'</p>');
1488:an-25): }
1489:an-25): if (keys(%tosend)) {
1490:an-25): $request->print('<p>'.&mt('No scores sent for following'));
1491:an-25): my ($zeros,$nopbcreds,$noconfirm,$noscore);
1492:an-25): foreach my $student (sort
1493:an-25): {
1494:an-25): if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
1495:an-25): return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
1496:an-25): }
1497:an-25): return $a cmp $b;
1498:an-25): } (keys(%$fullname))) {
1499:an-25): next unless ($tosend{$student});
1500:an-25): my ($uname,$udom) = split(/:/,$student);
1501:an-25): my $line = '<li>'.&nameUserString(undef,$$fullname{$student},$uname,$udom).'</li>'."\n";
1502:an-25): if ($zeroposs{$student}) {
1503:an-25): $zeros .= $line;
1504:an-25): } elsif ($nopbinfo{$student}) {
1505:an-25): $nopbcreds .= $line;
1506:an-25): } elsif ($remotenotok{$student}) {
1507:an-25): $noconfirm .= $line;
1508:an-25): } elsif ($scorenotok{$student}) {
1509:an-25): $noscore .= $line;
1510:an-25): }
1511:an-25): }
1512:an-25): if ($zeros) {
1513:an-25): $request->print('<br />'.&mt('Total points possible was 0').':'.
1514:an-25): '<ul>'.$zeros.'</ul><br />');
1515:an-25): }
1516:an-25): if ($nopbcreds) {
1517:an-25): $request->print('<br />'.&mt('Missing unique identifier and/or passback location').':'.
1518:an-25): '<ul>'.$nopbcreds.'</ul><br />');
1519:an-25): }
1520:an-25): if ($noconfirm) {
1521:an-25): $request->print('<br />'.&mt('Score receipt not confirmed by receiving CMS').':'.
1522:an-25): '<ul>'.$noconfirm.'</ul><br />');
1523:an-25): }
1524:an-25): if ($noscore) {
1525:an-25): $request->print('<br />'.&mt('Score computation or transmission failed').':'.
1526:an-25): '<ul>'.$noscore.'</ul><br />');
1527:an-25): }
1528:an-25): $request->print('</p>');
1529:an-25): }
1530:an-25): } else {
1531:an-25): $error = &mt('Settings for deep-link launch target unavailable, so no scores were sent');
1532:an-25): }
1533:an-25): } else {
1534:an-25): $error = &mt('No available students for whom scores can be sent.');
1535:an-25): }
1536:an-25): } else {
1537:an-25): $error = &mt('Classlist could not be retrieved so no scores were sent.');
1538:an-25): }
1539:an-25): } else {
1540:an-25): $error = &mt('No students selected to receive scores so none were sent.');
1541:an-25): }
1542:an-25): } else {
1543:an-25): if ($env{'form.passback'}) {
1544:an-25): $error = &mt('Deep-link launch target was invalid so no scores were sent.');
1545:an-25): } else {
1546:an-25): $error = &mt('Deep-link launch target was missing so no scores were sent.');
1547:an-25): }
1548:an-25): }
1549:an-25): } else {
1550:an-25): $error = &mt('You do not have permission to manage grades, so no scores were sent');
1551:an-25): }
1552:an-25): if ($error) {
1553:an-25): $request->print('<p class="LC_info">'.$error.'</p>');
1554:an-25): }
1555:an-25): return;
1556:an-25): }
1557:an-25):
1558:an-25): sub get_passback_launcher {
1559:an-25): my ($cdom,$cnum,$chosen) = @_;
1560:an-25): my ($linkuri,$linkprotector,$scope) = split("\0",$chosen);
1561:an-25): my ($ltinum,$ltitype) = ($linkprotector =~ /^(\d+)(c|d)$/);
1562:an-25): my ($appname,$setter);
1563:an-25): if ($ltitype eq 'c') {
1564:an-25): my %lti = &Apache::lonnet::get_course_lti($cnum,$cdom,'provider');
1565:an-25): if (ref($lti{$ltinum}) eq 'HASH') {
1566:an-25): $appname = $lti{$ltinum}{'name'};
1567:an-25): if ($appname) {
1568:an-25): $setter = ' (defined in course)';
1569:an-25): }
1570:an-25): }
1571:an-25): } elsif ($ltitype eq 'd') {
1572:an-25): my %lti = &Apache::lonnet::get_domain_lti($cdom,'linkprot');
1573:an-25): if (ref($lti{$ltinum}) eq 'HASH') {
1574:an-25): $appname = $lti{$ltinum}{'name'};
1575:an-25): if ($appname) {
1576:an-25): $setter = ' (defined in domain)';
1577:an-25): }
1578:an-25): }
1579:an-25): }
1580:an-25): my $launchsymb = &Apache::loncommon::symb_from_tinyurl($linkuri,$cnum,$cdom);
1581:an-25): if ($launchsymb eq '') {
1582:an-25): my %passback = &Apache::lonnet::dump('nohist_linkprot_passback',$cdom,$cnum);
1583:an-25): foreach my $poss_symb (keys(%passback)) {
1584:an-25): if (ref($passback{$poss_symb}) eq 'HASH') {
1585:an-25): if (exists($passback{$poss_symb}{$chosen})) {
1586:an-25): $launchsymb = $poss_symb;
1587:an-25): last;
1588:an-25): }
1589:an-25): }
1590:an-25): }
1591:an-25): if ($launchsymb ne '') {
1592:an-25): return ($launchsymb,$appname,$setter);
1593:an-25): }
1594:an-25): } else {
1595:an-25): my %passback = &Apache::lonnet::get('nohist_linkprot_passback',[$launchsymb],$cdom,$cnum);
1596:an-25): if (ref($passback{$launchsymb}) eq 'HASH') {
1597:an-25): if (exists($passback{$launchsymb}{$chosen})) {
1598:an-25): return ($launchsymb,$appname,$setter);
1599:an-25): }
1600:an-25): }
1601:an-25): }
1602:an-25): return ();
1603:an-25): }
1604:an-25):
1605:an-25): sub sections_and_groups {
1606:an-25): my (@sections,@groups,$group_display);
1607:an-25): @groups = &Apache::loncommon::get_env_multiple('form.group');
1608:an-25): if (grep(/^all$/,@groups)) {
1609:an-25): @groups = ('all');
1610:an-25): $group_display = 'all';
1611:an-25): } elsif (grep(/^none$/,@groups)) {
1612:an-25): @groups = ('none');
1613:an-25): $group_display = 'none';
1614:an-25): } elsif (@groups > 0) {
1615:an-25): $group_display = join(', ',@groups);
1616:an-25): }
1617:an-25): if ($env{'request.course.sec'} ne '') {
1618:an-25): @sections = ($env{'request.course.sec'});
1619:an-25): } else {
1620:an-25): @sections = &Apache::loncommon::get_env_multiple('form.section');
1621:an-25): }
1622:an-25): my $disabled = ' disabled="disabled"';
1623:an-25): if ($perm{'mgr'}) {
1624:an-25): if (grep(/^all$/,@sections)) {
1625:an-25): undef($disabled);
1626:an-25): } else {
1627:an-25): foreach my $sec (@sections) {
1628:an-25): if (&canmodify($sec)) {
1629:an-25): undef($disabled);
1630:an-25): last;
1631:an-25): }
1632:an-25): }
1633:an-25): }
1634:an-25): }
1635:an-25): if (grep(/^all$/,@sections)) {
1636:an-25): @sections = ('all');
1637:an-25): }
1638:an-25): return(\@sections,\@groups,$group_display,$disabled);
1639:an-25): }
1640:an-25):
1641:an-25): sub launcher_info_box {
1642:an-25): my ($launcher,$appname,$setter,$linkuri,$scope) = @_;
1643:an-25): my $shownscope;
1644:an-25): if ($scope eq 'res') {
1645:an-25): $shownscope = &mt('Resource');
1646:an-25): } elsif ($scope eq 'map') {
1647:an-25): $shownscope = &mt('Folder');
1648:an-25): } elsif ($scope eq 'rec') {
1649:an-25): $shownscope = &mt('Folder + sub-folders');
1650:an-25): }
1651:an-25): return '<p>'.
1652:an-25): &Apache::lonhtmlcommon::start_pick_box().
1653:an-25): &Apache::lonhtmlcommon::row_title(&mt('Launch Item Title')).
1654:an-25): &Apache::lonnet::gettitle($launcher).
1655:an-25): &Apache::lonhtmlcommon::row_closure().
1656:an-25): &Apache::lonhtmlcommon::row_title(&mt('Deep-link')).
1657:an-25): $linkuri.
1658:an-25): &Apache::lonhtmlcommon::row_closure().
1659:an-25): &Apache::lonhtmlcommon::row_title(&mt('Launcher')).
1660:an-25): $appname.' '.$setter.
1661:an-25): &Apache::lonhtmlcommon::row_closure().
1662:an-25): &Apache::lonhtmlcommon::row_title(&mt('Score Type')).
1663:an-25): $shownscope.
1664:an-25): &Apache::lonhtmlcommon::row_closure(1).
1665:an-25): &Apache::lonhtmlcommon::end_pick_box().'</p>'."\n";
1666:an-25): }
1667:an-25):
1668:an-25): sub passbacks_for_symb {
1669:an-25): my ($cdom,$cnum,$symb) = @_;
1670:an-25): my %passback = &Apache::lonnet::dump('nohist_linkprot_passback',$cdom,$cnum);
1671:an-25): my %needpb;
1672:an-25): if (keys(%passback)) {
1673:an-25): my $checkpb = 1;
1674:an-25): if (exists($passback{$symb})) {
1675:an-25): if (keys(%passback) == 1) {
1676:an-25): undef($checkpb);
1677:an-25): }
1678:an-25): if (ref($passback{$symb}) eq 'HASH') {
1679:an-25): foreach my $launcher (keys(%{$passback{$symb}})) {
1680:an-25): $needpb{$launcher} = $symb;
1681:an-25): }
1682:an-25): }
1683:an-25): }
1684:an-25): if ($checkpb) {
1685:an-25): my ($map,$id,$url) = &Apache::lonnet::decode_symb($symb);
1686:an-25): my $navmap = Apache::lonnavmaps::navmap->new();
1687:an-25): if (ref($navmap)) {
1688:an-25): my $mapres = $navmap->getResourceByUrl($map);
1689:an-25): if (ref($mapres)) {
1690:an-25): my $mapsymb = $mapres->symb();
1691:an-25): if (exists($passback{$mapsymb})) {
1692:an-25): if (keys(%passback) == 1) {
1693:an-25): undef($checkpb);
1694:an-25): }
1695:an-25): if (ref($passback{$mapsymb}) eq 'HASH') {
1696:an-25): foreach my $launcher (keys(%{$passback{$mapsymb}})) {
1697:an-25): $needpb{$launcher} = $mapsymb;
1698:an-25): }
1699:an-25): }
1700:an-25): }
1701:an-25): my %posspb;
1702:an-25): if ($checkpb) {
1703:an-25): my @recurseup = $navmap->recurseup_maps($map,1);
1704:an-25): if (@recurseup) {
1705:an-25): map { $posspb{$_} = 1; } @recurseup;
1706:an-25): }
1707:an-25): }
1708:an-25): foreach my $key (keys(%passback)) {
1709:an-25): if (exists($posspb{$key})) {
1710:an-25): if (ref($passback{$key}) eq 'HASH') {
1711:an-25): foreach my $launcher (keys(%{$passback{$key}})) {
1712:an-25): my ($linkuri,$linkprotector,$scope) = split("\0",$launcher);
1713:an-25): next unless ($scope eq 'rec');
1714:an-25): $needpb{$launcher} = $key;
1715:an-25): }
1716:an-25): }
1717:an-25): }
1718:an-25): }
1719:an-25): }
1720:an-25): }
1721:an-25): }
1722:an-25): }
1723:an-25): return %needpb;
1724:an-25): }
1725:an-25):
1726:an-25): sub process_passbacks {
1727:an-25): my ($context,$symbs,$cdom,$cnum,$udom,$uname,$usec,$weights,$awardeds,$excuseds,$needpb,
1728:an-25): $skip_passback,$pbsave,$pbids) = @_;
1729:an-25): if ((ref($needpb) eq 'HASH') && (ref($skip_passback) eq 'HASH') && (ref($pbsave) eq 'HASH')) {
1730:an-25): my (%weight,%awarded,%excused);
1731:an-25): if ((ref($symbs) eq 'ARRAY') && (ref($weights) eq 'HASH') && (ref($awardeds) eq 'HASH') &&
1732:an-25): (ref($excuseds) eq 'HASH')) {
1733:an-25): %weight = %{$weights};
1734:an-25): %awarded = %{$awardeds};
1735:an-25): %excused = %{$excuseds};
1736:an-25): }
1737:an-25): my $uhome = &Apache::lonnet::homeserver($uname,$udom);
1738:an-25): my @launchers = keys(%{$needpb});
1739:an-25): my %pbinfo;
1740:an-25): if (ref($pbids) eq 'HASH') {
1741:an-25): %pbinfo = %{$pbids};
1742:an-25): } else {
1743:an-25): %pbinfo = &Apache::lonnet::get('nohist_'.$cdom.'_'.$cnum.'_linkprot_pb',\@launchers,$udom,$uname);
1744:an-25): }
1745:an-25): my %pbc = &common_passback_info();
1746:an-25): foreach my $launcher (@launchers) {
1747:an-25): if (ref($pbinfo{$launcher}) eq 'ARRAY') {
1748:an-25): my $pbid = $pbinfo{$launcher}[0];
1749:an-25): my $pburl = $pbinfo{$launcher}[1];
1750:an-25): my (%total_by_symb,%possible_by_symb);
1751:an-25): if (($pbid ne '') && ($pburl ne '')) {
1752:an-25): next if ($skip_passback->{$launcher});
1753:an-25): my %pb = %pbc;
1754:an-25): if ((exists($pbsave->{$launcher})) &&
1755:an-25): (ref($pbsave->{$launcher}) eq 'HASH')) {
1756:an-25): foreach my $item ('lti_in_use','crsdef','ltinum','keynum','scoretype','msgformat',
1757:an-25): 'symb','map','pbscope','linkuri','linkprotector','scope') {
1758:an-25): $pb{$item} = $pbsave->{$launcher}{$item};
1759:an-25): }
1760:an-25): } else {
1761:an-25): my $ltitype;
1762:an-25): ($pb{'linkuri'},$pb{'linkprotector'},$pb{'scope'}) = split("\0",$launcher);
1763:an-25): ($pb{'ltinum'},$ltitype) = ($pb{'linkprotector'} =~ /^(\d+)(c|d)$/);
1764:an-25): if ($ltitype eq 'c') {
1765:an-25): my %crslti = &Apache::lonnet::get_course_lti($cnum,$cdom,'provider');
1766:an-25): $pb{'lti_in_use'} = $crslti{$pb{'ltinum'}};
1767:an-25): $pb{'crsdef'} = 1;
1768:an-25): } else {
1769:an-25): my %domlti = &Apache::lonnet::get_domain_lti($cdom,'linkprot');
1770:an-25): $pb{'lti_in_use'} = $domlti{$pb{'ltinum'}};
1771:an-25): }
1772:an-25): if (ref($pb{'lti_in_use'}) eq 'HASH') {
1773:an-25): $pb{'msgformat'} = $pb{'lti_in_use'}->{'passbackformat'};
1774:an-25): $pb{'keynum'} = $pb{'lti_in_use'}->{'cipher'};
1775:an-25): $pb{'scoretype'} = 'decimal';
1776:an-25): if ($pb{'lti_in_use'}->{'scoreformat'} =~ /^(decimal|ratio|percentage)$/) {
1777:an-25): $pb{'scoretype'} = $1;
1778:an-25): }
1779:an-25): $pb{'symb'} = $needpb->{$launcher};
1780:an-25): if ($pb{'symb'} =~ /\.(page|sequence)$/) {
1781:an-25): $pb{'map'} = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($pb{'symb'}))[2]);
1782:an-25): } else {
1783:an-25): $pb{'map'} = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($pb{'symb'}))[0]);
1784:an-25): }
1785:an-25): $pb{'map'} = &Apache::lonnet::clutter($pb{'map'});
1786:an-25): if ($pb{'scope'} eq 'res') {
1787:an-25): $pb{'pbscope'} = 'resource';
1788:an-25): } elsif ($pb{'scope'} eq 'map') {
1789:an-25): $pb{'pbscope'} = 'nonrec';
1790:an-25): } elsif ($pb{'scope'} eq 'rec') {
1791:an-25): $pb{'pbscope'} = 'map';
1792:an-25): }
1793:an-25): foreach my $item ('lti_in_use','crsdef','ltinum','keynum','scoretype','msgformat',
1794:an-25): 'symb','map','pbscope','linkuri','linkprotector','scope') {
1795:an-25): $pbsave->{$launcher}{$item} = $pb{$item};
1796:an-25): }
1797:an-25): } else {
1798:an-25): $skip_passback->{$launcher} = 1;
1799:an-25): }
1800:an-25): }
1801:an-25): if (ref($symbs) eq 'ARRAY') {
1802:an-25): foreach my $symb (@{$symbs}) {
1803:an-25): if ((ref($weight{$symb}) eq 'HASH') && (ref($awarded{$symb}) eq 'HASH') &&
1804:an-25): (ref($excused{$symb}) eq 'HASH')) {
1805:an-25): foreach my $part (keys(%{$weight{$symb}})) {
1806:an-25): if ($excused{$symb}{$part}) {
1807:an-25): next;
1808:an-25): }
1809:an-25): my $partweight = $weight{$symb}{$part} eq '' ? 1 :
1810:an-25): $weight{$symb}{$part};
1811:an-25): if ($awarded{$symb}{$part}) {
1812:an-25): $total_by_symb{$symb} += $partweight * $awarded{$symb}{$part};
1813:an-25): }
1814:an-25): $possible_by_symb{$symb} += $partweight;
1815:an-25): }
1816:an-25): }
1817:an-25): }
1818:an-25): }
1819:an-25): if ($context eq 'updatebypage') {
1820:an-25): my $ltigrade = {
1821:an-25): 'ltinum' => $pb{'ltinum'},
1822:an-25): 'lti' => $pb{'lti_in_use'},
1823:an-25): 'crsdef' => $pb{'crsdef'},
1824:an-25): 'cid' => $cdom.'_'.$cnum,
1825:an-25): 'uname' => $uname,
1826:an-25): 'udom' => $udom,
1827:an-25): 'uhome' => $uhome,
1828:an-25): 'usec' => $usec,
1829:an-25): 'pbid' => $pbid,
1830:an-25): 'pburl' => $pburl,
1831:an-25): 'pbtype' => $pb{'type'},
1832:an-25): 'pbscope' => $pb{'pbscope'},
1833:an-25): 'pbmap' => $pb{'map'},
1834:an-25): 'pbsymb' => $pb{'symb'},
1835:an-25): 'format' => $pb{'scoretype'},
1836:an-25): 'scope' => $pb{'scope'},
1837:an-25): 'clientip' => $pb{'clientip'},
1838:an-25): 'linkprot' => $pb{'linkprotector'}.':'.$pb{'linkuri'},
1839:an-25): 'total_s' => \%total_by_symb,
1840:an-25): 'possible_s' => \%possible_by_symb,
1841:an-25): };
1842:an-25): push(@Apache::grades::ltipassback,$ltigrade);
1843:an-25): next;
1844:an-25): }
1845:an-25): my ($total,$possible);
1846:an-25): if ($pb{'pbscope'} eq 'resource') {
1847:an-25): $total = $total_by_symb{$pb{'symb'}};
1848:an-25): $possible = $possible_by_symb{$pb{'symb'}};
1849:an-25): } elsif (($pb{'pbscope'} eq 'map') || ($pb{'pbscope'} eq 'nonrec')) {
1850:an-25): ($total,$possible) =
1851:an-25): &Apache::lonhomework::get_lti_score($uname,$udom,$usec,$pb{'map'},$pb{'pbscope'},
1852:an-25): \%total_by_symb,\%possible_by_symb);
1853:an-25): }
1854:an-25): if (!$possible) {
1855:an-25): $total = 0;
1856:an-25): $possible = 1;
1857:an-25): }
1858:an-25): my ($sent,$score,$code,$result) =
1859:an-25): &LONCAPA::ltiutils::send_grade($cdom,$cnum,$pb{'crsdef'},$pb{'type'},$pb{'ltinum'},
1860:an-25): $pb{'keynum'},$pbid,$pburl,$pb{'scoretype'},$pb{'sigmethod'},
1861:an-25): $pb{'msgformat'},$total,$possible);
1862:an-25): my $no_passback;
1863:an-25): if ($sent) {
1864:an-25): if ($code == 200) {
1865:an-25): my $namespace = $cdom.'_'.$cnum.'_lp_passback';
1866:an-25): my $store = {
1867:an-25): 'score' => $score,
1868:an-25): 'ip' => $pb{'ip'},
1869:an-25): 'host' => $pb{'lonhost'},
1870:an-25): 'protector' => $pb{'linkprotector'},
1871:an-25): 'deeplink' => $pb{'linkuri'},
1872:an-25): 'scope' => $pb{'scope'},
1873:an-25): 'url' => $pburl,
1874:an-25): 'id' => $pbid,
1875:an-25): 'clientip' => $pb{'clientip'},
1876:an-25): 'whodoneit' => $env{'user.name'}.':'.$env{'user.domain'},
1877:an-25): };
1878:an-25): my $value='';
1879:an-25): foreach my $key (keys(%{$store})) {
1880:an-25): $value.=&escape($key).'='.&Apache::lonnet::freeze_escape($store->{$key}).'&';
1881:an-25): }
1882:an-25): $value=~s/\&$//;
1883:an-25): &Apache::lonnet::courselog(&escape($pb{'linkuri'}).':'.$uname.':'.$udom.':EXPORT:'.$value);
1884:an-25): &Apache::lonnet::cstore({'score' => $score},$launcher,$namespace,$udom,$uname,'',$pb{'ip'},1);
1885:an-25): } else {
1886:an-25): $no_passback = 1;
1887:an-25): }
1888:an-25): } else {
1889:an-25): $no_passback = 1;
1890:an-25): }
1891:an-25): if ($no_passback) {
1892:an-25): &Apache::lonnet::log($udom,$uname,$uhome,$no_passback." score: $score; total: $total; possible: $possible");
1893:an-25): my $ltigrade = {
1894:an-25): 'ltinum' => $pb{'ltinum'},
1895:an-25): 'lti' => $pb{'lti_in_use'},
1896:an-25): 'crsdef' => $pb{'crsdef'},
1897:an-25): 'cid' => $cdom.'_'.$cnum,
1898:an-25): 'uname' => $uname,
1899:an-25): 'udom' => $udom,
1900:an-25): 'uhome' => $uhome,
1901:an-25): 'pbid' => $pbid,
1902:an-25): 'pburl' => $pburl,
1903:an-25): 'pbtype' => $pb{'type'},
1904:an-25): 'pbscope' => $pb{'pbscope'},
1905:an-25): 'pbmap' => $pb{'map'},
1906:an-25): 'pbsymb' => $pb{'symb'},
1907:an-25): 'format' => $pb{'scoretype'},
1908:an-25): 'scope' => $pb{'scope'},
1909:an-25): 'clientip' => $pb{'clientip'},
1910:an-25): 'linkprot' => $pb{'linkprotector'}.':'.$pb{'linkuri'},
1911:an-25): 'total' => $total,
1912:an-25): 'possible' => $possible,
1913:an-25): 'score' => $score,
1914:an-25): };
1915:an-25): &Apache::lonnet::put('linkprot_passback_pending',$ltigrade,$cdom,$cnum);
1916:an-25): }
1917:an-25): }
1918:an-25): }
1919:an-25): }
1920:an-25): }
1921:an-25): return;
1922:an-25): }
1923:an-25):
1924:an-25): sub common_passback_info {
1925:an-25): my %pbc = (
1926:an-25): sigmethod => 'HMAC-SHA1',
1927:an-25): type => 'linkprot',
1928:an-25): clientip => &Apache::lonnet::get_requestor_ip(),
1929:an-25): lonhost => $Apache::lonnet::perlvar{'lonHostID'},
1930:an-25): ip => &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}),
1931:an-25): );
1932:an-25): return %pbc;
1933:an-25): }
1934:an-25):
1.44 ng 1935: #--- This is called by a number of programs.
1936: #--- Called from the Grading Menu - View/Grade an individual student
1937: #--- Also called directly when one clicks on the subm button
1938: # on the problem page.
1.30 ng 1939: sub listStudents {
1.596.2.12.2. 1(raebur 1940:0): my ($request,$symb,$submitonly,$divforres) = @_;
1.49 albertel 1941:
1.596.2.12.2. 0.2.4(ra 1942:ul-23): my $is_tool = ($symb =~ /ext\.tool$/);
1.257 albertel 1943: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
1944: my $cnum = $env{"course.$env{'request.course.id'}.num"};
1945: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.449 banghart 1946: my $getgroup = $env{'form.group'} eq '' ? 'all' : $env{'form.group'};
1.596.2.12.2. 1(raebur 1947:0): unless ($submitonly) {
1948:0): $submitonly = $env{'form.submitonly'} eq '' ? 'all' : $env{'form.submitonly'};
1949:0): }
1950:0):
1951:0): my $result='';
1952:0): my $res_error;
1953:0): my ($partlist,$handgrade,$responseType,$numresp,$numessay) = &response_type($symb,\$res_error);
1.118 ng 1954:
1.596.2.12.2. 1(raebur 1955:0): my $table;
1956:0): if (ref($partlist) eq 'ARRAY') {
1957:0): if (scalar(@$partlist) > 1 ) {
1958:0): $table = &showResourceInfo($symb,$partlist,$responseType,'gradesub',1);
1959:0): } elsif ($divforres) {
1960:0): $table = '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1961:0): } else {
1962:0): $table = '<br clear="all" />';
1963:0): }
1964:0): }
1.49 albertel 1965:
1.596.2.12.2. 0.2.7(ra 1966:an-25): $request->print(&checkselect_js());
1(raebur 1967:0): $request->print(&Apache::lonhtmlcommon::scripttag(<<LISTJAVASCRIPT));
1.110 ng 1968:
1969: function reLoadList(formname) {
1.112 ng 1970: if (formname.saveStatusOld.value == pullDownSelection(formname.Status)) {return;}
1.110 ng 1971: formname.command.value = 'submission';
1972: formname.submit();
1973: }
1.45 ng 1974: LISTJAVASCRIPT
1975:
1.118 ng 1976: &commonJSfunctions($request);
1.41 ng 1977: $request->print($result);
1.39 ng 1978:
1.154 albertel 1979: my $gradeTable='<form action="/adm/grades" method="post" name="gradesub">'.
1.485 albertel 1980: "\n".$table;
1.596.2.12.2. 1(raebur 1981:0):
1.561 bisitz 1982: $gradeTable .= &Apache::lonhtmlcommon::start_pick_box();
1.596.2.12.2. 0.2.4(ra 1983:ul-23): unless ($is_tool) {
1984:ul-23): $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Problem Text'))
1985:ul-23): .'<label><input type="radio" name="vProb" value="no" checked="checked" /> '.&mt('no').' </label>'."\n"
1986:ul-23): .'<label><input type="radio" name="vProb" value="yes" /> '.&mt('one student').' </label>'."\n"
1987:ul-23): .'<label><input type="radio" name="vProb" value="all" /> '.&mt('all students').' </label><br />'."\n"
1988:ul-23): .&Apache::lonhtmlcommon::row_closure();
1989:ul-23): $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('View Answer'))
1990:ul-23): .'<label><input type="radio" name="vAns" value="no" /> '.&mt('no').' </label>'."\n"
1991:ul-23): .'<label><input type="radio" name="vAns" value="yes" /> '.&mt('one student').' </label>'."\n"
1992:ul-23): .'<label><input type="radio" name="vAns" value="all" checked="checked" /> '.&mt('all students').' </label><br />'."\n"
1993:ul-23): .&Apache::lonhtmlcommon::row_closure();
1994:ul-23): }
1.485 albertel 1995:
1.442 banghart 1996: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1997: my $saveStatus = $stu_status eq '' ? 'Active' : $stu_status;
1.257 albertel 1998: $env{'form.Status'} = $saveStatus;
1.596.2.12.2. 0.2.4(ra 1999:ul-23): my %optiontext;
2000:ul-23): if ($is_tool) {
2001:ul-23): %optiontext = &Apache::lonlocal::texthash (
2002:ul-23): lastonly => 'last transaction',
2003:ul-23): last => 'last transaction with details',
2004:ul-23): datesub => 'all transactions',
2005:ul-23): all => 'all transactions with details',
2006:ul-23): );
2007:ul-23): } else {
2008:ul-23): %optiontext = &Apache::lonlocal::texthash (
1(raebur 2009:0): lastonly => 'last submission',
2010:0): last => 'last submission with details',
2011:0): datesub => 'all submissions',
2012:0): all => 'all submissions with details',
2013:0): );
0.2.4(ra 2014:ul-23): }
1(raebur 2015:0): my $submission_options =
1.592 bisitz 2016: '<span class="LC_nobreak">'.
1.596.2.12.2. 1(raebur 2017:0): '<label><input type="radio" name="lastSub" value="lastonly" /> '.
2018:0): $optiontext{'lastonly'}.' </label></span>'."\n".
1.592 bisitz 2019: '<span class="LC_nobreak">'.
2020: '<label><input type="radio" name="lastSub" value="last" /> '.
1.596.2.12.2. 1(raebur 2021:0): $optiontext{'last'}.' </label></span>'."\n".
1.592 bisitz 2022: '<span class="LC_nobreak">'.
1.596.2.12.2. 1(raebur 2023:0): '<label><input type="radio" name="lastSub" value="datesub" checked="checked" /> '.
2024:0): $optiontext{'datesub'}.'</label></span>'."\n".
1.592 bisitz 2025: '<span class="LC_nobreak">'.
2026: '<label><input type="radio" name="lastSub" value="all" /> '.
1.596.2.12.2. 1(raebur 2027:0): $optiontext{'all'}.'</label></span>';
0.2.4(ra 2028:ul-23): my $viewtitle;
2029:ul-23): if ($is_tool) {
2030:ul-23): $viewtitle = &mt('View Transactions');
2031:ul-23): } else {
2032:ul-23): $viewtitle = &mt('View Submissions');
2033:ul-23): }
1(raebur 2034:0): my ($compmsg,$nocompmsg);
2035:0): $nocompmsg = ' checked="checked"';
2036:0): if ($numessay) {
2037:0): $compmsg = $nocompmsg;
2038:0): $nocompmsg = '';
2039:0): }
0.2.4(ra 2040:ul-23): $gradeTable .= &Apache::lonhtmlcommon::row_title($viewtitle)
6(raebur 2041:1): .$submission_options;
2042:1): # Check if any gradable
2043:1): my $showmore;
2044:1): if ($perm{'mgr'}) {
2045:1): my @sections;
2046:1): if ($env{'request.course.sec'} ne '') {
2047:1): @sections = ($env{'request.course.sec'});
7(raebur 2048:1): } elsif ($env{'form.section'} eq '') {
2049:1): @sections = ('all');
6(raebur 2050:1): } else {
2051:1): @sections = &Apache::loncommon::get_env_multiple('form.section');
2052:1): }
2053:1): if (grep(/^all$/,@sections)) {
2054:1): $showmore = 1;
2055:1): } else {
2056:1): foreach my $sec (@sections) {
2057:1): if (&canmodify($sec)) {
2058:1): $showmore = 1;
2059:1): last;
2060:1): }
2061:1): }
2062:1): }
2063:1): }
2064:1):
2065:1): if ($showmore) {
2066:1): $gradeTable .=
2067:1): &Apache::lonhtmlcommon::row_closure()
1(raebur 2068:0): .&Apache::lonhtmlcommon::row_title(&mt('Send Messages'))
2069:0): .'<span class="LC_nobreak">'
2070:0): .'<label><input type="radio" name="compmsg" value="0"'.$nocompmsg.' />'
2071:0): .&mt('No').(' 'x2).'</label>'
2072:0): .'<label><input type="radio" name="compmsg" value="1"'.$compmsg.' />'
2073:0): .&mt('Yes').(' 'x2).'</label>'
1.561 bisitz 2074: .&Apache::lonhtmlcommon::row_closure();
2075:
1.596.2.12.2. 6(raebur 2076:1): $gradeTable .=
2077:1): &Apache::lonhtmlcommon::row_title(&mt('Grading Increments'))
1.561 bisitz 2078: .'<select name="increment">'
2079: .'<option value="1">'.&mt('Whole Points').'</option>'
2080: .'<option value=".5">'.&mt('Half Points').'</option>'
2081: .'<option value=".25">'.&mt('Quarter Points').'</option>'
2082: .'<option value=".1">'.&mt('Tenths of a Point').'</option>'
1.596.2.12.2. 1(raebur 2083:0): .'</select>';
6(raebur 2084:1): }
1.485 albertel 2085: $gradeTable .=
1.432 banghart 2086: &build_section_inputs().
1.45 ng 2087: '<input type="hidden" name="submitonly" value="'.$submitonly.'" />'."\n".
1.418 albertel 2088: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.110 ng 2089: '<input type="hidden" name="saveStatusOld" value="'.$saveStatus.'" />'."\n";
1.596.2.12.2. 1(raebur 2090:0): if (exists($env{'form.Status'})) {
7(raebur 2091:1): $gradeTable .= '<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n";
1.124 ng 2092: } else {
1.596.2.12.2. 1(raebur 2093:0): $gradeTable .= &Apache::lonhtmlcommon::row_closure()
2094:0): .&Apache::lonhtmlcommon::row_title(&mt('Student Status'))
1.561 bisitz 2095: .&Apache::lonhtmlcommon::StatusOptions(
1.596.2.12.2. 1(raebur 2096:0): $saveStatus,undef,1,'javascript:reLoadList(this.form);');
1.124 ng 2097: }
1.596.2.12.2. 1(raebur 2098:0): if ($numessay) {
2099:0): $gradeTable .= &Apache::lonhtmlcommon::row_closure()
2100:0): .&Apache::lonhtmlcommon::row_title(&mt('Check For Plagiarism'))
2101:0): .'<input type="checkbox" name="checkPlag" checked="checked" />';
2102:0): }
2103:0): $gradeTable .= &Apache::lonhtmlcommon::row_closure(1)
1.561 bisitz 2104: .&Apache::lonhtmlcommon::end_pick_box();
1.596.2.12.2. 0.2.4(ra 2105:ul-23): my $regrademsg;
2106:ul-23): if ($is_tool) {
2107:ul-23): $regrademsg =&mt("To view/grade/regrade, click on the check box(es) next to the student's name(s). Then click on the Next button.");
2108:ul-23): } else {
2109:ul-23): $regrademsg = &mt("To view/grade/regrade a submission or a group of submissions, click on the check box(es) next to the student's name(s). Then click on the Next button.");
2110:ul-23): }
1.561 bisitz 2111: $gradeTable .= '<p>'
1.596.2.12.2. 0.2.4(ra 2112:ul-23): .$regrademsg."\n"
1.561 bisitz 2113: .'<input type="hidden" name="command" value="processGroup" />'
2114: .'</p>';
1.249 albertel 2115:
2116: # checkall buttons
2117: $gradeTable.=&check_script('gradesub', 'stuinfo');
1.110 ng 2118: $gradeTable.='<input type="button" '."\n".
1.589 bisitz 2119: 'onclick="javascript:checkSelect(this.form.stuinfo);" '."\n".
2120: 'value="'.&mt('Next').' →" /> <br />'."\n";
1.249 albertel 2121: $gradeTable.=&check_buttons();
1.450 banghart 2122: my ($classlist, undef, $fullname) = &getclasslist($getsec,'1',$getgroup);
1.474 albertel 2123: $gradeTable.= &Apache::loncommon::start_data_table().
2124: &Apache::loncommon::start_data_table_header_row();
1.110 ng 2125: my $loop = 0;
2126: while ($loop < 2) {
1.485 albertel 2127: $gradeTable.='<th>'.&mt('No.').'</th><th>'.&mt('Select').'</th>'.
2128: '<th>'.&nameUserString('header').' '.&mt('Section/Group').'</th>';
1.596.2.12.2. 1(raebur 2129:0): if (($submitonly ne 'queued') && ($submitonly ne 'all')) {
1.485 albertel 2130: foreach my $part (sort(@$partlist)) {
2131: my $display_part=
2132: &get_display_part((split(/_/,$part))[0],$symb);
2133: $gradeTable.=
2134: '<th>'.&mt('Part: [_1] Status',$display_part).'</th>';
1.110 ng 2135: }
1.301 albertel 2136: } elsif ($submitonly eq 'queued') {
1.474 albertel 2137: $gradeTable.='<th>'.&mt('Queue Status').' </th>';
1.110 ng 2138: }
2139: $loop++;
1.126 ng 2140: # $gradeTable.='<td></td>' if ($loop%2 ==1);
1.41 ng 2141: }
1.474 albertel 2142: $gradeTable.=&Apache::loncommon::end_data_table_header_row()."\n";
1.41 ng 2143:
1.45 ng 2144: my $ctr = 0;
1.294 albertel 2145: foreach my $student (sort
2146: {
2147: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
2148: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
2149: }
2150: return $a cmp $b;
2151: }
2152: (keys(%$fullname))) {
1.41 ng 2153: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 2154:
1.110 ng 2155: my %status = ();
1.301 albertel 2156:
2157: if ($submitonly eq 'queued') {
2158: my %queue_status =
2159: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
2160: $udom,$uname);
2161: next if (!defined($queue_status{'gradingqueue'}));
2162: $status{'gradingqueue'} = $queue_status{'gradingqueue'};
2163: }
2164:
1.596.2.12.2. 1(raebur 2165:0): if (($submitonly ne 'queued') && ($submitonly ne 'all')) {
1.324 albertel 2166: (%status) =&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 2167: my $submitted = 0;
1.164 albertel 2168: my $graded = 0;
1.248 albertel 2169: my $incorrect = 0;
1.110 ng 2170: foreach (keys(%status)) {
1.145 albertel 2171: $submitted = 1 if ($status{$_} ne 'nothing');
1.248 albertel 2172: $graded = 1 if ($status{$_} =~ /^ungraded/);
2173: $incorrect = 1 if ($status{$_} =~ /^incorrect/);
2174:
1.110 ng 2175: my ($foo,$partid,$foo1) = split(/\./,$_);
2176: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
1.145 albertel 2177: $submitted = 0;
1.150 albertel 2178: my ($part)=split(/\./,$partid);
1.110 ng 2179: $gradeTable.='<input type="hidden" name="'.
1.150 albertel 2180: $student.':'.$part.':submitted_by" value="'.
1.110 ng 2181: $status{'resource.'.$partid.'.submitted_by'}.'" />';
2182: }
1.41 ng 2183: }
1.248 albertel 2184:
1.156 albertel 2185: next if (!$submitted && ($submitonly eq 'yes' ||
2186: $submitonly eq 'incorrect' ||
2187: $submitonly eq 'graded'));
1.248 albertel 2188: next if (!$graded && ($submitonly eq 'graded'));
2189: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 2190: }
1.34 ng 2191:
1.45 ng 2192: $ctr++;
1.249 albertel 2193: my $section = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
1.452 banghart 2194: my $group = $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1.104 albertel 2195: if ( $perm{'vgr'} eq 'F' ) {
1.474 albertel 2196: if ($ctr%2 ==1) {
2197: $gradeTable.= &Apache::loncommon::start_data_table_row();
2198: }
1.126 ng 2199: $gradeTable.='<td align="right">'.$ctr.' </td>'.
1.563 bisitz 2200: '<td align="center"><label><input type="checkbox" name="stuinfo" value="'.
1.249 albertel 2201: $student.':'.$$fullname{$student}.':::SECTION'.$section.
2202: ') " /> </label></td>'."\n".'<td>'.
2203: &nameUserString(undef,$$fullname{$student},$uname,$udom).
1.474 albertel 2204: ' '.$section.($group ne '' ?'/'.$group:'').'</td>'."\n";
1.110 ng 2205:
1.596.2.12.2. 1(raebur 2206:0): if ($submitonly ne 'all') {
1.524 raeburn 2207: foreach (sort(keys(%status))) {
1.485 albertel 2208: next if ($_ =~ /^resource.*?submitted_by$/);
2209: $gradeTable.='<td align="center"> '.&mt($status{$_}).' </td>'."\n";
1.110 ng 2210: }
1.41 ng 2211: }
1.126 ng 2212: # $gradeTable.='<td></td>' if ($ctr%2 ==1);
1.474 albertel 2213: if ($ctr%2 ==0) {
2214: $gradeTable.=&Apache::loncommon::end_data_table_row()."\n";
2215: }
1.41 ng 2216: }
2217: }
1.110 ng 2218: if ($ctr%2 ==1) {
1.126 ng 2219: $gradeTable.='<td> </td><td> </td><td> </td>';
1.596.2.12.2. 1(raebur 2220:0): if (($submitonly ne 'queued') && ($submitonly ne 'all')) {
1.110 ng 2221: foreach (@$partlist) {
2222: $gradeTable.='<td> </td>';
2223: }
1.301 albertel 2224: } elsif ($submitonly eq 'queued') {
2225: $gradeTable.='<td> </td>';
1.110 ng 2226: }
1.474 albertel 2227: $gradeTable.=&Apache::loncommon::end_data_table_row();
1.110 ng 2228: }
2229:
1.474 albertel 2230: $gradeTable.=&Apache::loncommon::end_data_table()."\n".
1.589 bisitz 2231: '<input type="button" '.
2232: 'onclick="javascript:checkSelect(this.form.stuinfo);" '.
2233: 'value="'.&mt('Next').' →" /></form>'."\n";
1.45 ng 2234: if ($ctr == 0) {
1.96 albertel 2235: my $num_students=(scalar(keys(%$fullname)));
2236: if ($num_students eq 0) {
1.485 albertel 2237: $gradeTable='<br /> <span class="LC_warning">'.&mt('There are no students currently enrolled.').'</span>';
1.96 albertel 2238: } else {
1.171 albertel 2239: my $submissions='submissions';
2240: if ($submitonly eq 'incorrect') { $submissions = 'incorrect submissions'; }
2241: if ($submitonly eq 'graded' ) { $submissions = 'ungraded submissions'; }
1.301 albertel 2242: if ($submitonly eq 'queued' ) { $submissions = 'queued submissions'; }
1.398 albertel 2243: $gradeTable='<br /> <span class="LC_warning">'.
1.596.2.12.2. 4(raebur 2244:3): &mt('No '.$submissions.' found for this resource for any students. ([quant,_1,student] checked for '.$submissions.')',
1.485 albertel 2245: $num_students).
2246: '</span><br />';
1.96 albertel 2247: }
1.46 ng 2248: } elsif ($ctr == 1) {
1.474 albertel 2249: $gradeTable =~ s/type="checkbox"/type="checkbox" checked="checked"/;
1.45 ng 2250: }
2251: $request->print($gradeTable);
1.44 ng 2252: return '';
1.10 ng 2253: }
2254:
1.596.2.12.2. 0.2.7(ra 2255:an-25): #---- Called from the listStudents and the names_for_passback routines.
2256:an-25):
2257:an-25): sub checkselect_js {
2258:an-25): my ($formname) = @_;
2259:an-25): if ($formname eq '') {
2260:an-25): $formname = 'gradesub';
2261:an-25): }
2262:an-25): my %js_lt;
2263:an-25): if ($formname eq 'passbackusers') {
2264:an-25): %js_lt = &Apache::lonlocal::texthash (
2265:an-25): 'multiple' => 'Please select a student or group of students before pushing the Save Scores button.',
2266:an-25): 'single' => 'Please select the student before pushing the Save Scores button.',
2267:an-25): );
2268:an-25): } else {
2269:an-25): %js_lt = &Apache::lonlocal::texthash (
2270:an-25): 'multiple' => 'Please select a student or group of students before clicking on the Next button.',
2271:an-25): 'single' => 'Please select the student before clicking on the Next button.',
2272:an-25): );
2273:an-25): }
2274:an-25): &js_escape(\%js_lt);
2275:an-25): return &Apache::lonhtmlcommon::scripttag(<<LISTJAVASCRIPT);
2276:an-25):
2277:an-25): function checkSelect(checkBox) {
2278:an-25): var ctr=0;
2279:an-25): var sense="";
2280:an-25): var len = checkBox.length;
2281:an-25): if (len == undefined) len = 1;
2282:an-25): if (len > 1) {
2283:an-25): for (var i=0; i<len; i++) {
2284:an-25): if (checkBox[i].checked) {
2285:an-25): ctr++;
2286:an-25): }
2287:an-25): }
2288:an-25): sense = '$js_lt{'multiple'}';
2289:an-25): } else {
2290:an-25): if (checkBox.checked) {
2291:an-25): ctr = 1;
2292:an-25): }
2293:an-25): sense = '$js_lt{'single'}';
2294:an-25): }
2295:an-25): if (ctr == 0) {
2296:an-25): alert(sense);
2297:an-25): return false;
2298:an-25): }
2299:an-25): document.$formname.submit();
2300:an-25): }
2301:an-25): LISTJAVASCRIPT
2302:an-25):
2303:an-25): }
1.249 albertel 2304:
2305: sub check_script {
1.596.2.12.2. 1(raebur 2306:0): my ($form,$type) = @_;
2307:0): my $chkallscript = &Apache::lonhtmlcommon::scripttag('
1.249 albertel 2308: function checkall() {
2309: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
2310: ele = document.forms.'.$form.'.elements[i];
2311: if (ele.name == "'.$type.'") {
2312: document.forms.'.$form.'.elements[i].checked=true;
2313: }
2314: }
2315: }
2316:
2317: function checksec() {
2318: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
2319: ele = document.forms.'.$form.'.elements[i];
2320: string = document.forms.'.$form.'.chksec.value;
2321: if
2322: (ele.value.indexOf(":::SECTION"+string)>0) {
2323: document.forms.'.$form.'.elements[i].checked=true;
2324: }
2325: }
2326: }
2327:
2328:
2329: function uncheckall() {
2330: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
2331: ele = document.forms.'.$form.'.elements[i];
2332: if (ele.name == "'.$type.'") {
2333: document.forms.'.$form.'.elements[i].checked=false;
2334: }
2335: }
2336: }
2337:
1.596.2.12.2. 1(raebur 2338:0): '."\n");
1.249 albertel 2339: return $chkallscript;
2340: }
2341:
2342: sub check_buttons {
1.485 albertel 2343: my $buttons.='<input type="button" onclick="checkall()" value="'.&mt('Check All').'" />';
2344: $buttons.='<input type="button" onclick="uncheckall()" value="'.&mt('Uncheck All').'" /> ';
2345: $buttons.='<input type="button" onclick="checksec()" value="'.&mt('Check Section/Group').'" />';
1.249 albertel 2346: $buttons.='<input type="text" size="5" name="chksec" /> ';
2347: return $buttons;
2348: }
2349:
1.44 ng 2350: # Displays the submissions for one student or a group of students
1.34 ng 2351: sub processGroup {
1.596.2.12.2. 1(raebur 2352:0): my ($request,$symb) = @_;
1.41 ng 2353: my $ctr = 0;
1.155 albertel 2354: my @stuchecked = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.41 ng 2355: my $total = scalar(@stuchecked)-1;
1.45 ng 2356:
1.396 banghart 2357: foreach my $student (@stuchecked) {
2358: my ($uname,$udom,$fullname) = split(/:/,$student);
1.257 albertel 2359: $env{'form.student'} = $uname;
2360: $env{'form.userdom'} = $udom;
2361: $env{'form.fullname'} = $fullname;
1.596.2.12.2. 1(raebur 2362:0): &submission($request,$ctr,$total,$symb);
1.41 ng 2363: $ctr++;
2364: }
2365: return '';
1.35 ng 2366: }
1.34 ng 2367:
1.44 ng 2368: #------------------------------------------------------------------------------------
2369: #
2370: #-------------------------- Next few routines handles grading by student, essentially
2371: # handles essay response type problem/part
2372: #
2373: #--- Javascript to handle the submission page functionality ---
2374: sub sub_page_js {
2375: my $request = shift;
1.596.2.12.2. 6(raebur 2376:6): my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
7(raebur 2377:6): &js_escape(\$alertmsg);
1(raebur 2378:0): $request->print(&Apache::lonhtmlcommon::scripttag(<<SUBJAVASCRIPT));
1.71 ng 2379: function updateRadio(formname,id,weight) {
1.125 ng 2380: var gradeBox = formname["GD_BOX"+id];
2381: var radioButton = formname["RADVAL"+id];
2382: var oldpts = formname["oldpts"+id].value;
1.72 ng 2383: var pts = checkSolved(formname,id) == 'update' ? gradeBox.value : oldpts;
1.71 ng 2384: gradeBox.value = pts;
2385: var resetbox = false;
2386: if (isNaN(pts) || pts < 0) {
1.539 riegler 2387: alert("$alertmsg"+pts);
1.71 ng 2388: for (var i=0; i<radioButton.length; i++) {
2389: if (radioButton[i].checked) {
2390: gradeBox.value = i;
2391: resetbox = true;
2392: }
2393: }
2394: if (!resetbox) {
2395: formtextbox.value = "";
2396: }
2397: return;
1.44 ng 2398: }
1.71 ng 2399:
2400: if (pts > weight) {
2401: var resp = confirm("You entered a value ("+pts+
2402: ") greater than the weight for the part. Accept?");
2403: if (resp == false) {
1.125 ng 2404: gradeBox.value = oldpts;
1.71 ng 2405: return;
2406: }
1.44 ng 2407: }
1.13 albertel 2408:
1.71 ng 2409: for (var i=0; i<radioButton.length; i++) {
2410: radioButton[i].checked=false;
2411: if (pts == i && pts != "") {
2412: radioButton[i].checked=true;
2413: }
2414: }
2415: updateSelect(formname,id);
1.125 ng 2416: formname["stores"+id].value = "0";
1.41 ng 2417: }
1.5 albertel 2418:
1.72 ng 2419: function writeBox(formname,id,pts) {
1.125 ng 2420: var gradeBox = formname["GD_BOX"+id];
1.71 ng 2421: if (checkSolved(formname,id) == 'update') {
2422: gradeBox.value = pts;
2423: } else {
1.125 ng 2424: var oldpts = formname["oldpts"+id].value;
1.72 ng 2425: gradeBox.value = oldpts;
1.125 ng 2426: var radioButton = formname["RADVAL"+id];
1.71 ng 2427: for (var i=0; i<radioButton.length; i++) {
2428: radioButton[i].checked=false;
1.72 ng 2429: if (i == oldpts) {
1.71 ng 2430: radioButton[i].checked=true;
2431: }
2432: }
1.41 ng 2433: }
1.125 ng 2434: formname["stores"+id].value = "0";
1.71 ng 2435: updateSelect(formname,id);
2436: return;
1.41 ng 2437: }
1.44 ng 2438:
1.71 ng 2439: function clearRadBox(formname,id) {
2440: if (checkSolved(formname,id) == 'noupdate') {
2441: updateSelect(formname,id);
2442: return;
2443: }
1.125 ng 2444: gradeSelect = formname["GD_SEL"+id];
1.71 ng 2445: for (var i=0; i<gradeSelect.length; i++) {
2446: if (gradeSelect[i].selected) {
2447: var selectx=i;
2448: }
2449: }
1.125 ng 2450: var stores = formname["stores"+id];
1.71 ng 2451: if (selectx == stores.value) { return };
1.125 ng 2452: var gradeBox = formname["GD_BOX"+id];
1.71 ng 2453: gradeBox.value = "";
1.125 ng 2454: var radioButton = formname["RADVAL"+id];
1.71 ng 2455: for (var i=0; i<radioButton.length; i++) {
2456: radioButton[i].checked=false;
2457: }
2458: stores.value = selectx;
2459: }
1.5 albertel 2460:
1.71 ng 2461: function checkSolved(formname,id) {
1.125 ng 2462: if (formname["solved"+id].value == "correct_by_student" && formname.overRideScore.value == 'no') {
1.118 ng 2463: var reply = confirm("This problem has been graded correct by the computer. Do you want to change the score?");
2464: if (!reply) {return "noupdate";}
1.120 ng 2465: formname.overRideScore.value = 'yes';
1.41 ng 2466: }
1.71 ng 2467: return "update";
1.13 albertel 2468: }
1.71 ng 2469:
2470: function updateSelect(formname,id) {
1.125 ng 2471: formname["GD_SEL"+id][0].selected = true;
1.71 ng 2472: return;
1.41 ng 2473: }
1.33 ng 2474:
1.121 ng 2475: //=========== Check that a point is assigned for all the parts ============
1.71 ng 2476: function checksubmit(formname,val,total,parttot) {
1.121 ng 2477: formname.gradeOpt.value = val;
1.71 ng 2478: if (val == "Save & Next") {
2479: for (i=0;i<=total;i++) {
2480: for (j=0;j<parttot;j++) {
1.125 ng 2481: var partid = formname["partid"+i+"_"+j].value;
1.127 ng 2482: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 2483: var points = formname["GD_BOX"+i+"_"+partid].value;
1.71 ng 2484: if (points == "") {
1.125 ng 2485: var name = formname["name"+i].value;
1.129 ng 2486: var studentID = (name != '' ? name : formname["unamedom"+i].value);
2487: var resp = confirm("You did not assign a score for "+studentID+
2488: ", part "+partid+". Continue?");
1.71 ng 2489: if (resp == false) {
1.125 ng 2490: formname["GD_BOX"+i+"_"+partid].focus();
1.71 ng 2491: return false;
2492: }
2493: }
2494: }
2495: }
2496: }
2497: }
1.120 ng 2498: formname.submit();
2499: }
2500:
1.71 ng 2501: //======= Check that a score is assigned for all the problems (page/sequence grading only) =========
2502: function checkSubmitPage(formname,total) {
2503: noscore = new Array(100);
2504: var ptr = 0;
2505: for (i=1;i<total;i++) {
1.125 ng 2506: var partid = formname["q_"+i].value;
1.127 ng 2507: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 2508: var points = formname["GD_BOX"+i+"_"+partid].value;
2509: var status = formname["solved"+i+"_"+partid].value;
1.71 ng 2510: if (points == "" && status != "correct_by_student") {
2511: noscore[ptr] = i;
2512: ptr++;
2513: }
2514: }
2515: }
2516: if (ptr != 0) {
2517: var sense = ptr == 1 ? ": " : "s: ";
2518: var prolist = "";
2519: if (ptr == 1) {
2520: prolist = noscore[0];
2521: } else {
2522: var i = 0;
2523: while (i < ptr-1) {
2524: prolist += noscore[i]+", ";
2525: i++;
2526: }
2527: prolist += "and "+noscore[i];
2528: }
2529: var resp = confirm("You did not assign any score for the following problem"+sense+prolist+". Continue?");
2530: if (resp == false) {
2531: return false;
2532: }
2533: }
1.45 ng 2534:
1.71 ng 2535: formname.submit();
2536: }
2537: SUBJAVASCRIPT
2538: }
1.45 ng 2539:
1.596.2.12.2. 1(raebur 2540:0): #--- javascript for grading message center
2541:0): sub sub_grademessage_js {
1.71 ng 2542: my $request = shift;
1.80 ng 2543: my $iconpath = $request->dir_config('lonIconsURL');
1.118 ng 2544: &commonJSfunctions($request);
1.350 albertel 2545:
1.596.2.12.2. 1(raebur 2546:0): my $inner_js_msg_central= (<<INNERJS);
2547:0): <script type="text/javascript">
1.350 albertel 2548: function checkInput() {
2549: opener.document.SCORE.msgsub.value = opener.checkEntities(document.msgcenter.msgsub.value);
2550: var nmsg = opener.document.SCORE.savemsgN.value;
2551: var usrctr = document.msgcenter.usrctr.value;
2552: var newval = opener.document.SCORE["newmsg"+usrctr];
2553: newval.value = opener.checkEntities(document.msgcenter.newmsg.value);
2554:
2555: var msgchk = "";
2556: if (document.msgcenter.subchk.checked) {
2557: msgchk = "msgsub,";
2558: }
2559: var includemsg = 0;
2560: for (var i=1; i<=nmsg; i++) {
2561: var opnmsg = opener.document.SCORE["savemsg"+i];
2562: var frmmsg = document.msgcenter["msg"+i];
2563: opnmsg.value = opener.checkEntities(frmmsg.value);
2564: var showflg = opener.document.SCORE["shownOnce"+i];
2565: showflg.value = "1";
2566: var chkbox = document.msgcenter["msgn"+i];
2567: if (chkbox.checked) {
2568: msgchk += "savemsg"+i+",";
2569: includemsg = 1;
2570: }
2571: }
2572: if (document.msgcenter.newmsgchk.checked) {
2573: msgchk += "newmsg"+usrctr;
2574: includemsg = 1;
2575: }
2576: imgformname = opener.document.SCORE["mailicon"+usrctr];
2577: imgformname.src = "$iconpath/"+((includemsg) ? "mailto.gif" : "mailbkgrd.gif");
2578: var includemsg = opener.document.SCORE["includemsg"+usrctr];
2579: includemsg.value = msgchk;
2580:
2581: self.close()
2582:
2583: }
1.351 albertel 2584: </script>
2585: INNERJS
2586:
1.596.2.12.2. 1(raebur 2587:0): my $start_page_msg_central =
1.351 albertel 2588: &Apache::loncommon::start_page('Message Central',$inner_js_msg_central,
2589: {'js_ready' => 1,
2590: 'only_body' => 1,
2591: 'bgcolor' =>'#FFFFFF',});
1.596.2.12.2. 1(raebur 2592:0): my $end_page_msg_central =
1.351 albertel 2593: &Apache::loncommon::end_page({'js_ready' => 1});
2594:
1.219 www 2595: my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
1.236 albertel 2596: $docopen=~s/^document\.//;
1.596.2.12.2. 1(raebur 2597:0):
6(raebur 2598:6): my %html_js_lt = &Apache::lonlocal::texthash(
1.596.2.4 raeburn 2599: comp => 'Compose Message for: ',
2600: incl => 'Include',
2601: type => 'Type',
2602: subj => 'Subject',
2603: mesa => 'Message',
2604: new => 'New',
2605: save => 'Save',
2606: canc => 'Cancel',
2607: );
1.596.2.12.2. 6(raebur 2608:6): &html_escape(\%html_js_lt);
2609:6): &js_escape(\%html_js_lt);
1(raebur 2610:0): $request->print(&Apache::lonhtmlcommon::scripttag(<<SUBJAVASCRIPT));
1.44 ng 2611:
2612: //===================== Script to view submitted by ==================
2613: function viewSubmitter(submitter) {
2614: document.SCORE.refresh.value = "on";
2615: document.SCORE.NCT.value = "1";
2616: document.SCORE.unamedom0.value = submitter;
2617: document.SCORE.submit();
2618: return;
2619: }
2620:
2621: //====================== Script for composing message ==============
1.80 ng 2622: // preload images
2623: img1 = new Image();
2624: img1.src = "$iconpath/mailbkgrd.gif";
2625: img2 = new Image();
2626: img2.src = "$iconpath/mailto.gif";
2627:
1.44 ng 2628: function msgCenter(msgform,usrctr,fullname) {
2629: var Nmsg = msgform.savemsgN.value;
2630: savedMsgHeader(Nmsg,usrctr,fullname);
2631: var subject = msgform.msgsub.value;
1.127 ng 2632: var msgchk = document.SCORE["includemsg"+usrctr].value;
1.44 ng 2633: re = /msgsub/;
2634: var shwsel = "";
2635: if (re.test(msgchk)) { shwsel = "checked" }
1.123 ng 2636: subject = (document.SCORE.shownSub.value == 0 ? checkEntities(subject) : subject);
2637: displaySubject(checkEntities(subject),shwsel);
1.44 ng 2638: for (var i=1; i<=Nmsg; i++) {
1.123 ng 2639: var testmsg = "savemsg"+i+",";
2640: re = new RegExp(testmsg,"g");
1.44 ng 2641: shwsel = "";
2642: if (re.test(msgchk)) { shwsel = "checked" }
1.125 ng 2643: var message = document.SCORE["savemsg"+i].value;
1.126 ng 2644: message = (document.SCORE["shownOnce"+i].value == 0 ? checkEntities(message) : message);
1.123 ng 2645: displaySavedMsg(i,message,shwsel); //I do not get it. w/o checkEntities on saved messages,
2646: //any < is already converted to <, etc. However, only once!!
1.44 ng 2647: }
1.125 ng 2648: newmsg = document.SCORE["newmsg"+usrctr].value;
1.44 ng 2649: shwsel = "";
2650: re = /newmsg/;
2651: if (re.test(msgchk)) { shwsel = "checked" }
2652: newMsg(newmsg,shwsel);
2653: msgTail();
2654: return;
2655: }
2656:
1.123 ng 2657: function checkEntities(strx) {
2658: if (strx.length == 0) return strx;
2659: var orgStr = ["&", "<", ">", '"'];
2660: var newStr = ["&", "<", ">", """];
2661: var counter = 0;
2662: while (counter < 4) {
2663: strx = strReplace(strx,orgStr[counter],newStr[counter]);
2664: counter++;
2665: }
2666: return strx;
2667: }
2668:
2669: function strReplace(strx, orgStr, newStr) {
2670: return strx.split(orgStr).join(newStr);
2671: }
2672:
1.44 ng 2673: function savedMsgHeader(Nmsg,usrctr,fullname) {
1.76 ng 2674: var height = 70*Nmsg+250;
1.44 ng 2675: if (height > 600) {
2676: height = 600;
2677: }
1.118 ng 2678: var xpos = (screen.width-600)/2;
2679: xpos = (xpos < 0) ? '0' : xpos;
2680: var ypos = (screen.height-height)/2-30;
2681: ypos = (ypos < 0) ? '0' : ypos;
2682:
1.596.2.12.2. (raeburn 2683:): pWin = window.open('', 'MessageCenter', 'resizable=yes,toolbar=no,location=no,scrollbars=yes,screenx='+xpos+',screeny='+ypos+',width=700,height='+height);
1.76 ng 2684: pWin.focus();
2685: pDoc = pWin.document;
1.219 www 2686: pDoc.$docopen;
1.351 albertel 2687: pDoc.write('$start_page_msg_central');
1.76 ng 2688:
2689: pDoc.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
2690: pDoc.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
1.596.2.12.2. 1(raebur 2691:0): pDoc.write("<h1> $html_js_lt{'comp'}\"+fullname+\"<\\/h1>");
1.76 ng 2692:
1.596.2.12.2. 1(raebur 2693:0): pDoc.write('<table style="border:1px solid black;"><tr>');
2694:0): pDoc.write("<td><b>$html_js_lt{'incl'}<\\/b><\\/td><td><b>$html_js_lt{'type'}<\\/b><\\/td><td><b>$html_js_lt{'mesa'}<\\/td><\\/tr>");
1.44 ng 2695: }
2696: function displaySubject(msg,shwsel) {
1.76 ng 2697: pDoc = pWin.document;
1.596.2.12.2. 1(raebur 2698:0): pDoc.write("<tr>");
1.465 albertel 2699: pDoc.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1.596.2.12.2. 1(raebur 2700:0): pDoc.write("<td>$html_js_lt{'subj'}<\\/td>");
2701:0): pDoc.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+"\\"size=\\"40\\" maxlength=\\"80\\"><\\/td><\\/tr>");
1.44 ng 2702: }
2703:
1.72 ng 2704: function displaySavedMsg(ctr,msg,shwsel) {
1.76 ng 2705: pDoc = pWin.document;
1.596.2.12.2. 1(raebur 2706:0): pDoc.write("<tr>");
1.465 albertel 2707: pDoc.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1.596.2.12.2. 1(raebur 2708:0): pDoc.write("<td align=\\"center\\">"+ctr+"<\\/td>");
1.465 albertel 2709: pDoc.write("<td><textarea name=\\"msg"+ctr+"\\" cols=\\"60\\" rows=\\"3\\">"+msg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 2710: }
2711:
2712: function newMsg(newmsg,shwsel) {
1.76 ng 2713: pDoc = pWin.document;
1.596.2.12.2. 1(raebur 2714:0): pDoc.write("<tr>");
1.465 albertel 2715: pDoc.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1.596.2.12.2. 1(raebur 2716:0): pDoc.write("<td align=\\"center\\">$html_js_lt{'new'}<\\/td>");
1.465 albertel 2717: pDoc.write("<td><textarea name=\\"newmsg\\" cols=\\"60\\" rows=\\"3\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" >"+newmsg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 2718: }
2719:
2720: function msgTail() {
1.76 ng 2721: pDoc = pWin.document;
1.465 albertel 2722: pDoc.write("<\\/td><\\/tr><\\/table> ");
1.596.2.12.2. 6(raebur 2723:6): pDoc.write("<input type=\\"button\\" value=\\"$html_js_lt{'save'}\\" onclick=\\"javascript:checkInput()\\"> ");
2724:6): pDoc.write("<input type=\\"button\\" value=\\"$html_js_lt{'canc'}\\" onclick=\\"self.close()\\"><br /><br />");
1.465 albertel 2725: pDoc.write("<\\/form>");
1.351 albertel 2726: pDoc.write('$end_page_msg_central');
1.128 ng 2727: pDoc.close();
1.44 ng 2728: }
2729:
1.596.2.12.2. 1(raebur 2730:0): SUBJAVASCRIPT
2731:0): }
2732:0):
2733:0): #--- javascript for essay type problem --
2734:0): sub sub_page_kw_js {
2735:0): my $request = shift;
2736:0):
2737:0): unless ($env{'form.compmsg'}) {
2738:0): &commonJSfunctions($request);
2739:0): }
2740:0):
2741:0): my $inner_js_highlight_central= (<<INNERJS);
2742:0): <script type="text/javascript">
2743:0): function updateChoice(flag) {
2744:0): opener.document.SCORE.kwclr.value = opener.radioSelection(document.hlCenter.kwdclr);
2745:0): opener.document.SCORE.kwsize.value = opener.radioSelection(document.hlCenter.kwdsize);
2746:0): opener.document.SCORE.kwstyle.value = opener.radioSelection(document.hlCenter.kwdstyle);
2747:0): opener.document.SCORE.refresh.value = "on";
2748:0): if (opener.document.SCORE.keywords.value!=""){
2749:0): opener.document.SCORE.submit();
2750:0): }
2751:0): self.close()
2752:0): }
2753:0): </script>
2754:0): INNERJS
2755:0):
2756:0): my $start_page_highlight_central =
2757:0): &Apache::loncommon::start_page('Highlight Central',
2758:0): $inner_js_highlight_central,
2759:0): {'js_ready' => 1,
2760:0): 'only_body' => 1,
2761:0): 'bgcolor' =>'#FFFFFF',});
2762:0): my $end_page_highlight_central =
2763:0): &Apache::loncommon::end_page({'js_ready' => 1});
2764:0):
2765:0): my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
2766:0): $docopen=~s/^document\.//;
2767:0):
2768:0): my %js_lt = &Apache::lonlocal::texthash(
2769:0): keyw => 'Keywords list, separated by a space. Add/delete to list if desired.',
2770:0): plse => 'Please select a word or group of words from document and then click this link.',
2771:0): adds => 'Add selection to keyword list? Edit if desired.',
2772:0): col1 => 'red',
2773:0): col2 => 'green',
2774:0): col3 => 'blue',
2775:0): siz1 => 'normal',
2776:0): siz2 => '+1',
2777:0): siz3 => '+2',
2778:0): sty1 => 'normal',
2779:0): sty2 => 'italic',
2780:0): sty3 => 'bold',
2781:0): );
2782:0): my %html_js_lt = &Apache::lonlocal::texthash(
2783:0): save => 'Save',
2784:0): canc => 'Cancel',
2785:0): kehi => 'Keyword Highlight Options',
2786:0): txtc => 'Text Color',
2787:0): font => 'Font Size',
2788:0): fnst => 'Font Style',
2789:0): );
2790:0): &js_escape(\%js_lt);
2791:0): &html_escape(\%html_js_lt);
2792:0): &js_escape(\%html_js_lt);
2793:0): $request->print(&Apache::lonhtmlcommon::scripttag(<<SUBJAVASCRIPT));
2794:0):
2795:0): //===================== Show list of keywords ====================
2796:0): function keywords(formname) {
2797:0): var nret = prompt("$js_lt{'keyw'}",formname.keywords.value);
2798:0): if (nret==null) return;
2799:0): formname.keywords.value = nret;
2800:0):
2801:0): if (formname.keywords.value != "") {
2802:0): formname.refresh.value = "on";
2803:0): formname.submit();
2804:0): }
2805:0): return;
2806:0): }
2807:0):
2808:0): //===================== Script to add keyword(s) ==================
2809:0): function getSel() {
2810:0): if (document.getSelection) txt = document.getSelection();
2811:0): else if (document.selection) txt = document.selection.createRange().text;
2812:0): else return;
2813:0): if (typeof(txt) != 'string') {
2814:0): txt = String(txt);
2815:0): }
2816:0): var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
2817:0): if (cleantxt=="") {
2818:0): alert("$js_lt{'plse'}");
2819:0): return;
2820:0): }
2821:0): var nret = prompt("$js_lt{'adds'}",cleantxt);
2822:0): if (nret==null) return;
2823:0): document.SCORE.keywords.value = document.SCORE.keywords.value+" "+nret;
2824:0): if (document.SCORE.keywords.value != "") {
2825:0): document.SCORE.refresh.value = "on";
2826:0): document.SCORE.submit();
2827:0): }
2828:0): return;
2829:0): }
2830:0):
1.44 ng 2831: //====================== Script for keyword highlight options ==============
2832: function kwhighlight() {
2833: var kwclr = document.SCORE.kwclr.value;
2834: var kwsize = document.SCORE.kwsize.value;
2835: var kwstyle = document.SCORE.kwstyle.value;
2836: var redsel = "";
2837: var grnsel = "";
2838: var blusel = "";
1.596.2.12.2. 6(raebur 2839:6): var txtcol1 = "$js_lt{'col1'}";
2840:6): var txtcol2 = "$js_lt{'col2'}";
2841:6): var txtcol3 = "$js_lt{'col3'}";
2842:6): var txtsiz1 = "$js_lt{'siz1'}";
2843:6): var txtsiz2 = "$js_lt{'siz2'}";
2844:6): var txtsiz3 = "$js_lt{'siz3'}";
2845:6): var txtsty1 = "$js_lt{'sty1'}";
2846:6): var txtsty2 = "$js_lt{'sty2'}";
2847:6): var txtsty3 = "$js_lt{'sty3'}";
8(raebur 2848:4): if (kwclr=="red") {var redsel="checked='checked'"};
2849:4): if (kwclr=="green") {var grnsel="checked='checked'"};
2850:4): if (kwclr=="blue") {var blusel="checked='checked'"};
1.44 ng 2851: var sznsel = "";
2852: var sz1sel = "";
2853: var sz2sel = "";
1.596.2.12.2. 8(raebur 2854:4): if (kwsize=="0") {var sznsel="checked='checked'"};
2855:4): if (kwsize=="+1") {var sz1sel="checked='checked'"};
2856:4): if (kwsize=="+2") {var sz2sel="checked='checked'"};
1.44 ng 2857: var synsel = "";
2858: var syisel = "";
2859: var sybsel = "";
1.596.2.12.2. 8(raebur 2860:4): if (kwstyle=="") {var synsel="checked='checked'"};
2861:4): if (kwstyle=="<i>") {var syisel="checked='checked'"};
2862:4): if (kwstyle=="<b>") {var sybsel="checked='checked'"};
1.44 ng 2863: highlightCentral();
1.596.2.12.2. 8(raebur 2864:4): highlightbody('red',txtcol1,redsel,'0',txtsiz1,sznsel,'',txtsty1,synsel);
2865:4): highlightbody('green',txtcol2,grnsel,'+1',txtsiz2,sz1sel,'<i>',txtsty2,syisel);
2866:4): highlightbody('blue',txtcol3,blusel,'+2',txtsiz3,sz2sel,'<b>',txtsty3,sybsel);
1.44 ng 2867: highlightend();
2868: return;
2869: }
2870:
2871: function highlightCentral() {
1.76 ng 2872: // if (window.hwdWin) window.hwdWin.close();
1.118 ng 2873: var xpos = (screen.width-400)/2;
2874: xpos = (xpos < 0) ? '0' : xpos;
2875: var ypos = (screen.height-330)/2-30;
2876: ypos = (ypos < 0) ? '0' : ypos;
2877:
1.206 albertel 2878: hwdWin = window.open('', 'KeywordHighlightCentral', 'resizeable=yes,toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx='+xpos+',screeny='+ypos);
1.76 ng 2879: hwdWin.focus();
2880: var hDoc = hwdWin.document;
1.219 www 2881: hDoc.$docopen;
1.351 albertel 2882: hDoc.write('$start_page_highlight_central');
1.76 ng 2883: hDoc.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
1.596.2.12.2. 6(raebur 2884:6): hDoc.write("<h1>$html_js_lt{'kehi'}<\\/h1>");
1.76 ng 2885:
1.596.2.12.2. 8(raebur 2886:4): hDoc.write('<table border="0" width="100%"><tr style="background-color:#A1D676">');
6(raebur 2887:6): hDoc.write("<th>$html_js_lt{'txtc'}<\\/th><th>$html_js_lt{'font'}<\\/th><th>$html_js_lt{'fnst'}<\\/th><\\/tr>");
1.44 ng 2888: }
2889:
2890: function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) {
1.76 ng 2891: var hDoc = hwdWin.document;
1.596.2.12.2. 8(raebur 2892:4): hDoc.write("<tr>");
1.76 ng 2893: hDoc.write("<td align=\\"left\\">");
1.596.2.12.2. 8(raebur 2894:4): hDoc.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+" \\/> "+clrtxt+"<\\/td>");
1.76 ng 2895: hDoc.write("<td align=\\"left\\">");
1.596.2.12.2. 8(raebur 2896:4): hDoc.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+" \\/> "+sztxt+"<\\/td>");
1.76 ng 2897: hDoc.write("<td align=\\"left\\">");
1.596.2.12.2. 8(raebur 2898:4): hDoc.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+" \\/> "+sytxt+"<\\/td>");
1.465 albertel 2899: hDoc.write("<\\/tr>");
1.44 ng 2900: }
2901:
2902: function highlightend() {
1.76 ng 2903: var hDoc = hwdWin.document;
1.596.2.12.2. 8(raebur 2904:4): hDoc.write("<\\/table><br \\/>");
6(raebur 2905:6): hDoc.write("<input type=\\"button\\" value=\\"$html_js_lt{'save'}\\" onclick=\\"javascript:updateChoice(1)\\" \\/> ");
2906:6): hDoc.write("<input type=\\"button\\" value=\\"$html_js_lt{'canc'}\\" onclick=\\"self.close()\\" \\/><br /><br />");
1.465 albertel 2907: hDoc.write("<\\/form>");
1.351 albertel 2908: hDoc.write('$end_page_highlight_central');
1.128 ng 2909: hDoc.close();
1.44 ng 2910: }
2911:
2912: SUBJAVASCRIPT
2913: }
2914:
1.349 albertel 2915: sub get_increment {
1.348 bowersj2 2916: my $increment = $env{'form.increment'};
2917: if ($increment != 1 && $increment != .5 && $increment != .25 &&
2918: $increment != .1) {
2919: $increment = 1;
2920: }
2921: return $increment;
2922: }
2923:
1.585 bisitz 2924: sub gradeBox_start {
2925: return (
2926: &Apache::loncommon::start_data_table()
2927: .&Apache::loncommon::start_data_table_header_row()
2928: .'<th>'.&mt('Part').'</th>'
2929: .'<th>'.&mt('Points').'</th>'
2930: .'<th> </th>'
2931: .'<th>'.&mt('Assign Grade').'</th>'
2932: .'<th>'.&mt('Weight').'</th>'
2933: .'<th>'.&mt('Grade Status').'</th>'
2934: .&Apache::loncommon::end_data_table_header_row()
2935: );
2936: }
2937:
2938: sub gradeBox_end {
2939: return (
2940: &Apache::loncommon::end_data_table()
2941: );
2942: }
1.71 ng 2943: #--- displays the grading box, used in essay type problem and grading by page/sequence
2944: sub gradeBox {
1.322 albertel 2945: my ($request,$symb,$uname,$udom,$counter,$partid,$record) = @_;
1.381 albertel 2946: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 2947: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 2948: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
1.466 albertel 2949: my $wgtmsg = ($wgt > 0) ? &mt('(problem weight)')
2950: : '<span class="LC_info">'.&mt('problem weight assigned by computer').'</span>';
1.71 ng 2951: $wgt = ($wgt > 0 ? $wgt : '1');
2952: my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
1.320 albertel 2953: '' : &compute_points($$record{'resource.'.$partid.'.awarded'},$wgt));
1.596.2.12.2. 8(raebur 2954:3): my $data_WGT='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />'."\n";
1.466 albertel 2955: my $display_part= &get_display_part($partid,$symb);
1.270 albertel 2956: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
2957: [$partid]);
2958: my $aggtries = $$record{'resource.'.$partid.'.tries'};
1.269 raeburn 2959: if ($last_resets{$partid}) {
2960: $aggtries = &get_num_tries($record,$last_resets{$partid},$partid);
2961: }
1.596.2.12.2. 8(raebur 2962:3): my $result=&Apache::loncommon::start_data_table_row();
1.71 ng 2963: my $ctr = 0;
1.348 bowersj2 2964: my $thisweight = 0;
1.349 albertel 2965: my $increment = &get_increment();
1.485 albertel 2966:
2967: my $radio.='<table border="0"><tr>'."\n"; # display radio buttons in a nice table 10 across
1.348 bowersj2 2968: while ($thisweight<=$wgt) {
1.532 bisitz 2969: $radio.= '<td><span class="LC_nobreak"><label><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
1.589 bisitz 2970: 'onclick="javascript:writeBox(this.form,\''.$counter.'_'.$partid.'\','.
1.348 bowersj2 2971: $thisweight.')" value="'.$thisweight.'" '.
1.401 albertel 2972: ($score eq $thisweight ? 'checked="checked"':'').' /> '.$thisweight."</label></span></td>\n";
1.485 albertel 2973: $radio.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1.348 bowersj2 2974: $thisweight += $increment;
1.71 ng 2975: $ctr++;
2976: }
1.485 albertel 2977: $radio.='</tr></table>';
2978:
2979: my $line.='<input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
1.71 ng 2980: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
1.589 bisitz 2981: 'onchange="javascript:updateRadio(this.form,\''.$counter.'_'.$partid.'\','.
1.71 ng 2982: $wgt.')" /></td>'."\n";
1.485 albertel 2983: $line.='<td>/'.$wgt.' '.$wgtmsg.
1.71 ng 2984: ($$record{'resource.'.$partid.'.solved'} eq 'correct_by_student' ? ' '.$checkIcon : '').
1.585 bisitz 2985: ' </td>'."\n";
2986: $line.='<td><select name="GD_SEL'.$counter.'_'.$partid.'" '.
1.589 bisitz 2987: 'onchange="javascript:clearRadBox(this.form,\''.$counter.'_'.$partid.'\')" >'."\n";
1.71 ng 2988: if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
1.485 albertel 2989: $line.='<option></option>'.
2990: '<option value="excused" selected="selected">'.&mt('excused').'</option>';
1.71 ng 2991: } else {
1.485 albertel 2992: $line.='<option selected="selected"></option>'.
2993: '<option value="excused" >'.&mt('excused').'</option>';
1.71 ng 2994: }
1.485 albertel 2995: $line.='<option value="reset status">'.&mt('reset status').'</option></select>'."\n";
2996:
2997:
2998: $result .=
1.596.2.12.2. 8(raebur 2999:3): '<td>'.$data_WGT.$display_part.'</td><td>'.$radio.'</td><td>'.&mt('or').'</td><td>'.$line.'</td>';
1(raebur 3000:0): $result.=&Apache::loncommon::end_data_table_row();
3001:0): $result.=&Apache::loncommon::start_data_table_row().'<td colspan="6">';
1.71 ng 3002: $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="" />'."\n".
3003: '<input type="hidden" name="oldpts'.$counter.'_'.$partid.'" value="'.$score.'" />'."\n".
3004: '<input type="hidden" name="solved'.$counter.'_'.$partid.'" value="'.
1.269 raeburn 3005: $$record{'resource.'.$partid.'.solved'}.'" />'."\n".
3006: '<input type="hidden" name="totaltries'.$counter.'_'.$partid.'" value="'.
3007: $$record{'resource.'.$partid.'.tries'}.'" />'."\n".
3008: '<input type="hidden" name="aggtries'.$counter.'_'.$partid.'" value="'.
3009: $aggtries.'" />'."\n";
1.582 raeburn 3010: my $res_error;
3011: $result.=&handback_box($symb,$uname,$udom,$counter,$partid,$record,\$res_error);
1.596.2.12.2. 8(raebur 3012:3): $result.='</td>'.&Apache::loncommon::end_data_table_row();
1.582 raeburn 3013: if ($res_error) {
3014: return &navmap_errormsg();
3015: }
1.318 banghart 3016: return $result;
3017: }
1.322 albertel 3018:
3019: sub handback_box {
1.596.2.12.2. 1(raebur 3020:0): my ($symb,$uname,$udom,$counter,$partid,$record,$res_error_pointer) = @_;
3021:0): my ($partlist,$handgrade,$responseType,$numresp,$numessay) = &response_type($symb,$res_error_pointer);
3022:0): return unless ($numessay);
1.323 banghart 3023: my (@respids);
1.596.2.4 raeburn 3024: my @part_response_id = &flatten_responseType($responseType);
1.375 albertel 3025: foreach my $part_response_id (@part_response_id) {
3026: my ($part,$resp) = @{ $part_response_id };
1.323 banghart 3027: if ($part eq $partid) {
1.375 albertel 3028: push(@respids,$resp);
1.323 banghart 3029: }
3030: }
1.318 banghart 3031: my $result;
1.323 banghart 3032: foreach my $respid (@respids) {
1.322 albertel 3033: my $prefix = $counter.'_'.$partid.'_'.$respid.'_';
3034: my $files=&get_submitted_files($udom,$uname,$partid,$respid,$record);
3035: next if (!@$files);
1.596.2.4 raeburn 3036: my $file_counter = 0;
1.313 banghart 3037: foreach my $file (@$files) {
1.368 banghart 3038: if ($file =~ /\/portfolio\//) {
1.596.2.4 raeburn 3039: $file_counter++;
1.368 banghart 3040: my ($file_path, $file_disp) = ($file =~ m|(.+/)(.+)$|);
3041: my ($name,$version,$ext) = &file_name_version_ext($file_disp);
3042: $file_disp = "$name.$ext";
3043: $file = $file_path.$file_disp;
3044: $result.=&mt('Return commented version of [_1] to student.',
3045: '<span class="LC_filename">'.$file_disp.'</span>');
3046: $result.='<input type="file" name="'.$prefix.'returndoc'.$file_counter.'" />'."\n";
1.596.2.4 raeburn 3047: $result.='<input type="hidden" name="'.$prefix.'origdoc'.$file_counter.'" value="'.$file.'" /><br />'."\n";
1.368 banghart 3048: }
1.322 albertel 3049: }
1.596.2.4 raeburn 3050: if ($file_counter) {
3051: $result .= '<input type="hidden" name="'.$prefix.'countreturndoc" value="'.$file_counter.'" />'."\n".
3052: '<span class="LC_info">'.
3053: '('.&mt('File(s) will be uploaded when you click on Save & Next below.',$file_counter).')</span><br /><br />';
3054: }
1.313 banghart 3055: }
1.318 banghart 3056: return $result;
1.71 ng 3057: }
1.44 ng 3058:
1.58 albertel 3059: sub show_problem {
1.382 albertel 3060: my ($request,$symb,$uname,$udom,$removeform,$viewon,$mode,$form) = @_;
1.144 albertel 3061: my $rendered;
1.382 albertel 3062: my %form = ((ref($form) eq 'HASH')? %{$form} : ());
1.329 albertel 3063: &Apache::lonxml::remember_problem_counter();
1.144 albertel 3064: if ($mode eq 'both' or $mode eq 'text') {
3065: $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
1.382 albertel 3066: $env{'request.course.id'},
3067: undef,\%form);
1.144 albertel 3068: }
1.58 albertel 3069: if ($removeform) {
3070: $rendered=~s|<form(.*?)>||g;
3071: $rendered=~s|</form>||g;
1.374 albertel 3072: $rendered=~s|(<input[^>]*name\s*=\s*"?)(\w+)("?)|$1would_have_been_$2$3|g;
1.58 albertel 3073: }
1.144 albertel 3074: my $companswer;
3075: if ($mode eq 'both' or $mode eq 'answer') {
1.329 albertel 3076: &Apache::lonxml::restore_problem_counter();
1.382 albertel 3077: $companswer=
3078: &Apache::loncommon::get_student_answers($symb,$uname,$udom,
3079: $env{'request.course.id'},
3080: %form);
1.144 albertel 3081: }
1.58 albertel 3082: if ($removeform) {
3083: $companswer=~s|<form(.*?)>||g;
3084: $companswer=~s|</form>||g;
1.144 albertel 3085: $companswer=~s|name="submit"|name="would_have_been_submit"|g;
1.58 albertel 3086: }
1.596.2.12.2. (raeburn 3087:): my $renderheading = &mt('View of the problem');
3088:): my $answerheading = &mt('Correct answer');
3089:): if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3090:): my $stu_fullname = $env{'form.fullname'};
3091:): if ($stu_fullname eq '') {
3092:): $stu_fullname = &Apache::loncommon::plainname($uname,$udom,'lastname');
3093:): }
3094:): my $forwhom = &nameUserString(undef,$stu_fullname,$uname,$udom);
3095:): if ($forwhom ne '') {
3096:): $renderheading = &mt('View of the problem for[_1]',$forwhom);
3097:): $answerheading = &mt('Correct answer for[_1]',$forwhom);
3098:): }
3099:): }
1.468 albertel 3100: $rendered=
1.588 bisitz 3101: '<div class="LC_Box">'
1.596.2.12.2. (raeburn 3102:): .'<h3 class="LC_hcell">'.$renderheading.'</h3>'
1.588 bisitz 3103: .$rendered
3104: .'</div>';
1.468 albertel 3105: $companswer=
1.588 bisitz 3106: '<div class="LC_Box">'
1.596.2.12.2. (raeburn 3107:): .'<h3 class="LC_hcell">'.$answerheading.'</h3>'
1.588 bisitz 3108: .$companswer
3109: .'</div>';
1.468 albertel 3110: my $result;
1.144 albertel 3111: if ($mode eq 'both') {
1.588 bisitz 3112: $result=$rendered.$companswer;
1.144 albertel 3113: } elsif ($mode eq 'text') {
1.588 bisitz 3114: $result=$rendered;
1.144 albertel 3115: } elsif ($mode eq 'answer') {
1.588 bisitz 3116: $result=$companswer;
1.144 albertel 3117: }
1.71 ng 3118: return $result;
1.58 albertel 3119: }
1.397 albertel 3120:
1.396 banghart 3121: sub files_exist {
3122: my ($r, $symb) = @_;
3123: my @students = &Apache::loncommon::get_env_multiple('form.stuinfo');
3124: foreach my $student (@students) {
3125: my ($uname,$udom,$fullname) = split(/:/,$student);
1.397 albertel 3126: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
3127: $udom,$uname);
1.596.2.12.2. 0.2.2(ra 3128:ar-23): my ($string)= &get_last_submission(\%record);
1.397 albertel 3129: foreach my $submission (@$string) {
3130: my ($partid,$respid) =
3131: ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
3132: my $files=&get_submitted_files($udom,$uname,$partid,$respid,
3133: \%record);
3134: return 1 if (@$files);
1.396 banghart 3135: }
3136: }
1.397 albertel 3137: return 0;
1.396 banghart 3138: }
1.397 albertel 3139:
1.394 banghart 3140: sub download_all_link {
3141: my ($r,$symb) = @_;
1.596.2.12.2. 1(raebur 3142:0): unless (&files_exist($r, $symb)) {
3143:0): $r->print(&mt('There are currently no submitted documents.'));
3144:0): return;
3145:0): }
1.395 albertel 3146: my $all_students =
3147: join("\n", &Apache::loncommon::get_env_multiple('form.stuinfo'));
3148:
3149: my $parts =
3150: join("\n",&Apache::loncommon::get_env_multiple('form.vPart'));
3151:
1.394 banghart 3152: my $identifier = &Apache::loncommon::get_cgi_id();
1.514 raeburn 3153: &Apache::lonnet::appenv({'cgi.'.$identifier.'.students' => $all_students,
3154: 'cgi.'.$identifier.'.symb' => $symb,
3155: 'cgi.'.$identifier.'.parts' => $parts,});
1.395 albertel 3156: $r->print('<a href="/cgi-bin/multidownload.pl?'.$identifier.'">'.
3157: &mt('Download All Submitted Documents').'</a>');
1.596.2.12.2. 1(raebur 3158:0): return;
3159:0): }
3160:0):
3161:0): sub submit_download_link {
3162:0): my ($request,$symb) = @_;
3163:0): if (!$symb) { return ''; }
3164:0): my $res_error;
3165:0): my ($partlist,$handgrade,$responseType,$numresp,$numessay,$numdropbox) =
3166:0): &response_type($symb,\$res_error);
3167:0): if ($res_error) {
3168:0): $request->print(&mt('An error occurred retrieving response types'));
3169:0): return;
3170:0): }
3171:0): unless ($numessay) {
3172:0): $request->print(&mt('No essayresponse items found'));
3173:0): return;
3174:0): }
3175:0): my @chosenparts = &Apache::loncommon::get_env_multiple('form.vPart');
3176:0): if (@chosenparts) {
3177:0): $request->print(&showResourceInfo($symb,$partlist,$responseType,
3178:0): undef,undef,1));
3179:0): }
3180:0): if ($numessay) {
3181:0): my $submitonly= $env{'form.submitonly'} eq '' ? 'all' : $env{'form.submitonly'};
3182:0): my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
3183:0): my $getgroup = $env{'form.group'} eq '' ? 'all' : $env{'form.group'};
3184:0): (undef,undef,my $fullname) = &getclasslist($getsec,1,$getgroup,$symb,$submitonly,1);
3185:0): if (ref($fullname) eq 'HASH') {
3186:0): my @students = map { $_.':'.$fullname->{$_} } (keys(%{$fullname}));
3187:0): if (@students) {
3188:0): @{$env{'form.stuinfo'}} = @students;
3189:0): if ($numdropbox) {
3190:0): &download_all_link($request,$symb);
3191:0): } else {
3192:0): $request->print(&mt('No essayrespose items with dropbox found'));
3193:0): }
3194:0): # FIXME Need a mechanism to download essays, i.e., if $numessay > $numdropbox
3195:0): # Needs to omit user's identity if resource instance is for an anonymous survey.
3196:0): } else {
3197:0): $request->print(&mt('No students match the criteria you selected'));
3198:0): }
3199:0): } else {
3200:0): $request->print(&mt('Could not retrieve student information'));
3201:0): }
3202:0): } else {
3203:0): $request->print(&mt('No essayresponse items found'));
3204:0): }
3205:0): return;
1.394 banghart 3206: }
1.395 albertel 3207:
1.432 banghart 3208: sub build_section_inputs {
3209: my $section_inputs;
3210: if ($env{'form.section'} eq '') {
3211: $section_inputs .= '<input type="hidden" name="section" value="all" />'."\n";
3212: } else {
3213: my @sections = &Apache::loncommon::get_env_multiple('form.section');
1.434 albertel 3214: foreach my $section (@sections) {
1.432 banghart 3215: $section_inputs .= '<input type="hidden" name="section" value="'.$section.'" />'."\n";
3216: }
3217: }
3218: return $section_inputs;
3219: }
3220:
1.44 ng 3221: # --------------------------- show submissions of a student, option to grade
3222: sub submission {
1.596.2.12.2. 1(raebur 3223:0): my ($request,$counter,$total,$symb,$divforres,$calledby) = @_;
1.257 albertel 3224: my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
3225: $udom = ($udom eq '' ? $env{'user.domain'} : $udom); #has form.userdom changed for a student?
3226: my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
3227: $env{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $env{'form.fullname'} eq '';
1.596.2.12.2. 1(raebur 3228:0):
1.324 albertel 3229: if ($symb eq '') { $request->print("Unable to handle ambiguous references:."); return ''; }
1.596.2.12.2. 1(raebur 3230:0): my $probtitle=&Apache::lonnet::gettitle($symb);
0.2.4(ra 3231:ul-23): my $is_tool = ($symb =~ /ext\.tool$/);
5(raebur 3232:9): my ($essayurl,%coursedesc_by_cid);
1.104 albertel 3233:
3234: if (!&canview($usec)) {
1.596.2.12.2. 8(raebur 3235:4): $request->print(
3236:4): '<span class="LC_warning">'.
3237:4): &mt('Unable to view requested student.').
3238:4): ' '.&mt('([_1] in section [_2] in course id [_3])',
3239:4): $uname.':'.$udom,$usec,$env{'request.course.id'}).
3240:4): '</span>');
1.104 albertel 3241: return;
3242: }
3243:
1.596.2.12.2. 1(raebur 3244:0): my $res_error;
3245:0): my ($partlist,$handgrade,$responseType,$numresp,$numessay) =
3246:0): &response_type($symb,\$res_error);
3247:0): if ($res_error) {
3248:0): $request->print(&navmap_errormsg());
3249:0): return;
3250:0): }
3251:0):
1.257 albertel 3252: if (!$env{'form.lastSub'}) { $env{'form.lastSub'} = 'datesub'; }
1.596.2.12.2. 0.2.4(ra 3253:ul-23): unless ($is_tool) {
3254:ul-23): if (!$env{'form.vProb'}) { $env{'form.vProb'} = 'yes'; }
3255:ul-23): if (!$env{'form.vAns'}) { $env{'form.vAns'} = 'yes'; }
3256:ul-23): }
1(raebur 3257:0): if (($numessay) && ($calledby eq 'submission') && (!exists($env{'form.compmsg'}))) {
3258:0): $env{'form.compmsg'} = 1;
3259:0): }
1.257 albertel 3260: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.381 albertel 3261: my $checkIcon = '<img alt="'.&mt('Check Mark').
3262: '" src="'.$request->dir_config('lonIconsURL').
1.122 ng 3263: '/check.gif" height="16" border="0" />';
1.41 ng 3264:
3265: # header info
3266: if ($counter == 0) {
1.596.2.12.2. 1(raebur 3267:0): my @chosenparts = &Apache::loncommon::get_env_multiple('form.vPart');
3268:0): if (@chosenparts) {
3269:0): $request->print(&showResourceInfo($symb,$partlist,$responseType,'gradesub'));
3270:0): } elsif ($divforres) {
3271:0): $request->print('<div style="padding:0;clear:both;margin:0;border:0"></div>');
3272:0): } else {
3273:0): $request->print('<br clear="all" />');
3274:0): }
1.41 ng 3275: &sub_page_js($request);
1.596.2.12.2. 1(raebur 3276:0): &sub_grademessage_js($request) if ($env{'form.compmsg'});
3277:0): &sub_page_kw_js($request) if ($numessay);
1.118 ng 3278:
1.44 ng 3279: # option to display problem, only once else it cause problems
3280: # with the form later since the problem has a form.
1.257 albertel 3281: if ($env{'form.vProb'} eq 'yes' or $env{'form.vAns'} eq 'yes') {
1.144 albertel 3282: my $mode;
1.257 albertel 3283: if ($env{'form.vProb'} eq 'yes' && $env{'form.vAns'} eq 'yes') {
1.144 albertel 3284: $mode='both';
1.257 albertel 3285: } elsif ($env{'form.vProb'} eq 'yes') {
1.144 albertel 3286: $mode='text';
1.257 albertel 3287: } elsif ($env{'form.vAns'} eq 'yes') {
1.144 albertel 3288: $mode='answer';
3289: }
1.329 albertel 3290: &Apache::lonxml::clear_problem_counter();
1.144 albertel 3291: $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
1.41 ng 3292: }
1.441 www 3293:
1.41 ng 3294: my %keyhash = ();
1.596.2.12.2. 1(raebur 3295:0): if (($env{'form.kwclr'} eq '' && $numessay) || ($env{'form.compmsg'})) {
1.41 ng 3296: %keyhash = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 3297: $env{'course.'.$env{'request.course.id'}.'.domain'},
3298: $env{'course.'.$env{'request.course.id'}.'.num'});
1.596.2.12.2. 1(raebur 3299:0): }
3300:0): # kwclr is the only variable that is guaranteed not to be blank
3301:0): # if this subroutine has been called once.
3302:0): if ($env{'form.kwclr'} eq '' && $numessay) {
1.257 albertel 3303: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
3304: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
3305: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
3306: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
3307: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
1.596.2.12.2. 1(raebur 3308:0): }
3309:0): if ($env{'form.compmsg'}) {
3310:0): $env{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
3311:0): $keyhash{$symb.'_subject'} : $probtitle;
1.257 albertel 3312: $env{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1.41 ng 3313: }
1.596.2.12.2. 1(raebur 3314:0):
1.257 albertel 3315: my $overRideScore = $env{'form.overRideScore'} eq '' ? 'no' : $env{'form.overRideScore'};
1.442 banghart 3316: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.303 banghart 3317: $request->print('<form action="/adm/grades" method="post" name="SCORE" enctype="multipart/form-data">'."\n".
1.41 ng 3318: '<input type="hidden" name="command" value="handgrade" />'."\n".
1.442 banghart 3319: '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.120 ng 3320: '<input type="hidden" name="overRideScore" value="'.$overRideScore.'" />'."\n".
1.41 ng 3321: '<input type="hidden" name="refresh" value="off" />'."\n".
1.120 ng 3322: '<input type="hidden" name="studentNo" value="" />'."\n".
3323: '<input type="hidden" name="gradeOpt" value="" />'."\n".
1.418 albertel 3324: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 3325: '<input type="hidden" name="vProb" value="'.$env{'form.vProb'}.'" />'."\n".
3326: '<input type="hidden" name="vAns" value="'.$env{'form.vAns'}.'" />'."\n".
3327: '<input type="hidden" name="lastSub" value="'.$env{'form.lastSub'}.'" />'."\n".
1.596.2.12.2. 1(raebur 3328:0): '<input type="hidden" name="compmsg" value="'.$env{'form.compmsg'}.'" />'."\n".
1.432 banghart 3329: &build_section_inputs().
1.326 albertel 3330: '<input type="hidden" name="submitonly" value="'.$env{'form.submitonly'}.'" />'."\n".
1.41 ng 3331: '<input type="hidden" name="NCT"'.
1.257 albertel 3332: ' value="'.($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : $total+1).'" />'."\n");
1.596.2.12.2. 1(raebur 3333:0): if ($env{'form.compmsg'}) {
3334:0): $request->print('<input type="hidden" name="msgsub" value="'.$env{'form.msgsub'}.'" />'."\n".
3335:0): '<input type="hidden" name="shownSub" value="0" />'."\n".
3336:0): '<input type="hidden" name="savemsgN" value="'.$env{'form.savemsgN'}.'" />'."\n");
3337:0): }
3338:0): if ($numessay) {
1.257 albertel 3339: $request->print('<input type="hidden" name="keywords" value="'.$env{'form.keywords'}.'" />'."\n".
3340: '<input type="hidden" name="kwclr" value="'.$env{'form.kwclr'}.'" />'."\n".
3341: '<input type="hidden" name="kwsize" value="'.$env{'form.kwsize'}.'" />'."\n".
1.596.2.12.2. 1(raebur 3342:0): '<input type="hidden" name="kwstyle" value="'.$env{'form.kwstyle'}.'" />'."\n");
1.123 ng 3343: }
1.596.2.12.2. 1(raebur 3344:0):
1.41 ng 3345: my ($cts,$prnmsg) = (1,'');
1.257 albertel 3346: while ($cts <= $env{'form.savemsgN'}) {
1.41 ng 3347: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
1.123 ng 3348: (!exists($keyhash{$symb.'_savemsg'.$cts}) ?
1.257 albertel 3349: &Apache::lonfeedback::clear_out_html($env{'form.savemsg'.$cts}) :
1.80 ng 3350: &Apache::lonfeedback::clear_out_html($keyhash{$symb.'_savemsg'.$cts})).
1.123 ng 3351: '" />'."\n".
3352: '<input type="hidden" name="shownOnce'.$cts.'" value="0" />'."\n";
1.41 ng 3353: $cts++;
3354: }
3355: $request->print($prnmsg);
1.32 ng 3356:
1.596.2.12.2. 1(raebur 3357:0): if ($numessay) {
1.596.2.4 raeburn 3358:
3359: my %lt = &Apache::lonlocal::texthash(
1.596.2.12.2. 8(raebur 3360:4): keyh => 'Keyword Highlighting for Essays',
1.596.2.4 raeburn 3361: keyw => 'Keyword Options',
3362: list => 'List',
3363: past => 'Paste Selection to List',
1.596.2.9 raeburn 3364: high => 'Highlight Attribute',
1.596.2.4 raeburn 3365: );
1.88 www 3366: #
3367: # Print out the keyword options line
3368: #
1.596.2.12.2. 1(raebur 3369:0): $request->print(
8(raebur 3370:4): '<div class="LC_columnSection">'
3371:4): .'<fieldset><legend>'.$lt{'keyh'}.'</legend>'
3372:4): .&Apache::lonhtmlcommon::funclist_from_array(
3373:4): ['<a href="javascript:keywords(document.SCORE);" target="_self">'.$lt{'list'}.'</a>',
3374:4): '<a href="#" onmousedown="javascript:getSel(); return false"
3375:4): class="page">'.$lt{'past'}.'</a>',
3376:4): '<a href="javascript:kwhighlight();" target="_self">'.$lt{'high'}.'</a>'],
3377:4): {legend => $lt{'keyw'}})
3378:4): .'</fieldset></div>'
3379:4): );
3380:4):
1.88 www 3381: #
3382: # Load the other essays for similarity check
3383: #
1.596.2.12.2. 5(raebur 3384:9): (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb);
3385:9): if ($essayurl eq 'lib/templates/simpleproblem.problem') {
3386:9): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3387:9): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3388:9): if ($cdom ne '' && $cnum ne '') {
3389:9): my ($map,$id,$res) = &Apache::lonnet::decode_symb($symb);
3390:9): if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(default(?:|_\d+)\.(?:sequence|page))$}) {
3391:9): my $apath = $1.'_'.$id;
3392:9): $apath=~s/\W/\_/gs;
3393:9): &init_old_essays($symb,$apath,$cdom,$cnum);
3394:9): }
3395:9): }
3396:9): } else {
3397:9): my ($adom,$aname,$apath)=($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
3398:9): $apath=&escape($apath);
3399:9): $apath=~s/\W/\_/gs;
3400:9): &init_old_essays($symb,$apath,$adom,$aname);
3401:9): }
1.41 ng 3402: }
3403: }
1.44 ng 3404:
1.441 www 3405: # This is where output for one specific student would start
1.592 bisitz 3406: my $add_class = ($counter%2) ? ' LC_grade_show_user_odd_row' : '';
3407: $request->print(
3408: "\n\n"
3409: .'<div class="LC_grade_show_user'.$add_class.'">'
3410: .'<h2>'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).'</h2>'
3411: ."\n"
3412: );
1.441 www 3413:
1.592 bisitz 3414: # Show additional functions if allowed
3415: if ($perm{'vgr'}) {
3416: $request->print(
3417: &Apache::loncommon::track_student_link(
1.596.2.12.2. 4(raebur 3418:3): 'View recent activity',
1.592 bisitz 3419: $uname,$udom,'check')
3420: .' '
3421: );
3422: }
3423: if ($perm{'opa'}) {
3424: $request->print(
3425: &Apache::loncommon::pprmlink(
3426: &mt('Set/Change parameters'),
3427: $uname,$udom,$symb,'check'));
3428: }
3429:
3430: # Show Problem
1.257 albertel 3431: if ($env{'form.vProb'} eq 'all' or $env{'form.vAns'} eq 'all') {
1.144 albertel 3432: my $mode;
1.257 albertel 3433: if ($env{'form.vProb'} eq 'all' && $env{'form.vAns'} eq 'all') {
1.144 albertel 3434: $mode='both';
1.257 albertel 3435: } elsif ($env{'form.vProb'} eq 'all' ) {
1.144 albertel 3436: $mode='text';
1.257 albertel 3437: } elsif ($env{'form.vAns'} eq 'all') {
1.144 albertel 3438: $mode='answer';
3439: }
1.329 albertel 3440: &Apache::lonxml::clear_problem_counter();
1.475 albertel 3441: $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode,{'request.prefix' => 'ctr'.$counter}));
1.58 albertel 3442: }
1.144 albertel 3443:
1.257 albertel 3444: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.41 ng 3445:
1.44 ng 3446: # Display student info
1.41 ng 3447: $request->print(($counter == 0 ? '' : '<br />'));
1.590 bisitz 3448:
1.596.2.12.2. 0.2.4(ra 3449:ul-23): my $boxtitle = &mt('Submissions');
3450:ul-23): if ($is_tool) {
3451:ul-23): $boxtitle = &mt('Transactions')
3452:ul-23): }
1.590 bisitz 3453: my $result='<div class="LC_Box">'
1.596.2.12.2. 0.2.4(ra 3454:ul-23): .'<h3 class="LC_hcell">'.$boxtitle.'</h3>';
1.45 ng 3455: $result.='<input type="hidden" name="name'.$counter.
1.588 bisitz 3456: '" value="'.$env{'form.fullname'}.'" />'."\n";
1.596.2.12.2. 0.2.4(ra 3457:ul-23): if (($numresp > $numessay) && !$is_tool) {
1.588 bisitz 3458: $result.='<p class="LC_info">'
3459: .&mt('Part(s) graded correct by the computer is marked with a [_1] symbol.',$checkIcon)
3460: ."</p>\n";
1.469 albertel 3461: }
3462:
1.596.2.12.2. 1(raebur 3463:0): # If any part of the problem is an essayresponse, then check for collaborators
1.464 albertel 3464: my $fullname;
3465: my $col_fullnames = [];
1.596.2.12.2. 1(raebur 3466:0): if ($numessay) {
1.464 albertel 3467: (my $sub_result,$fullname,$col_fullnames)=
3468: &check_collaborators($symb,$uname,$udom,\%record,$handgrade,
3469: $counter);
3470: $result.=$sub_result;
1.41 ng 3471: }
1.44 ng 3472: $request->print($result."\n");
1.588 bisitz 3473:
1.44 ng 3474: # print student answer/submission
1.596.2.12.2. 1(raebur 3475:0): # Options are (1) Last submission only
3476:0): # (2) Last submission (with detailed information for that submission)
3477:0): # (3) All transactions (by date)
3478:0): # (4) The whole record (with detailed information for all transactions)
3479:0):
0.2.5(ra 3480:ep-23): my ($lastsubonly,$partinfo) =
3481:ep-23): &show_last_submission($uname,$udom,$symb,$essayurl,$responseType,$env{'form.lastSub'},
3482:ep-23): $is_tool,$fullname,\%record,\%coursedesc_by_cid);
3483:ep-23): $request->print($partinfo);
1(raebur 3484:0): $request->print($lastsubonly);
0.2.5(ra 3485:ep-23):
1(raebur 3486:0): if ($env{'form.lastSub'} eq 'datesub') {
3487:0): my ($parts,$handgrade,$responseType) = &response_type($symb,\$res_error);
1.148 albertel 3488: $request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
1.596.2.12.2. 1(raebur 3489:3): }
3490:3): if ($env{'form.lastSub'} =~ /^(last|all)$/) {
3491:5): my $identifier = (&canmodify($usec)? $counter : '');
1.41 ng 3492: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
1.257 albertel 3493: $env{'request.course.id'},
1.44 ng 3494: $last,'.submission',
1.596.2.12.2. 1(raebur 3495:5): 'Apache::grades::keywords_highlight',
3496:5): $usec,$identifier));
1.41 ng 3497: }
1.121 ng 3498: $request->print('<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
3499: .$udom.'" />'."\n");
1.44 ng 3500: # return if view submission with no grading option
1.596.2.12.2. 1(raebur 3501:0): if (!&canmodify($usec)) {
3502:0): $request->print('<p><span class="LC_warning">'.&mt('No grading privileges').'</span></p></div>');
3503:0): return;
1.180 albertel 3504: } else {
1.468 albertel 3505: $request->print('</div>'."\n");
1.41 ng 3506: }
1.33 ng 3507:
1.596.2.12.2. 1(raebur 3508:0): # grading message center
3509:0):
3510:0): if ($env{'form.compmsg'}) {
3511:0): my $result='<div class="LC_Box">'.
3512:0): '<h3 class="LC_hcell">'.&mt('Send Message').'</h3>'.
3513:0): '<div class="LC_grade_message_center_body">';
3514:0): my ($lastname,$givenn) = split(/,/,$env{'form.fullname'});
3515:0): my $msgfor = $givenn.' '.$lastname;
3516:0): if (scalar(@$col_fullnames) > 0) {
3517:0): my $lastone = pop(@$col_fullnames);
3518:0): $msgfor .= ', '.(join ', ',@$col_fullnames).' and '.$lastone.'.';
3519:0): }
3520:0): $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
3521:0): $result.='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
3522:0): '<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n".
3523:0): ' <a href="javascript:msgCenter(document.SCORE,'.$counter.
3524:0): ',\''.$msgfor.'\');" target="_self">'.
3525:0): &mt('Compose message to student'.(scalar(@$col_fullnames) >= 1 ? 's' : '')).'</a><label> ('.
3526:0): &mt('incl. grades').' <input type="checkbox" name="withgrades'.$counter.'" /></label>)'.
3527:0): ' <img src="'.$request->dir_config('lonIconsURL').
3528:0): '/mailbkgrd.gif" width="14" height="10" alt="" name="mailicon'.$counter.'" />'."\n".
3529:0): '<br /> ('.
3530:0): &mt('Message will be sent when you click on Save & Next below.').")\n".
3531:0): '</div></div>';
3532:0): $request->print($result);
1.118 ng 3533: }
1.41 ng 3534:
3535: my %seen = ();
3536: my @partlist;
1.129 ng 3537: my @gradePartRespid;
1.596.2.12.2. 0.2.4(ra 3538:ul-23): my @part_response_id;
3539:ul-23): if ($is_tool) {
3540:ul-23): @part_response_id = ([0,'']);
3541:ul-23): } else {
3542:ul-23): @part_response_id = &flatten_responseType($responseType);
3543:ul-23): }
1.585 bisitz 3544: $request->print(
1.588 bisitz 3545: '<div class="LC_Box">'
3546: .'<h3 class="LC_hcell">'.&mt('Assign Grades').'</h3>'
1.585 bisitz 3547: );
1.592 bisitz 3548: $request->print(&gradeBox_start());
1.375 albertel 3549: foreach my $part_response_id (@part_response_id) {
3550: my ($partid,$respid) = @{ $part_response_id };
3551: my $part_resp = join('_',@{ $part_response_id });
1.322 albertel 3552: next if ($seen{$partid} > 0);
1.41 ng 3553: $seen{$partid}++;
1.524 raeburn 3554: push(@partlist,$partid);
3555: push(@gradePartRespid,$partid.'.'.$respid);
1.322 albertel 3556: $request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
1.41 ng 3557: }
1.585 bisitz 3558: $request->print(&gradeBox_end()); # </div>
3559: $request->print('</div>');
1.468 albertel 3560:
3561: $request->print('<div class="LC_grade_info_links">');
3562: $request->print('</div>');
3563:
1.45 ng 3564: $result='<input type="hidden" name="partlist'.$counter.
3565: '" value="'.(join ":",@partlist).'" />'."\n";
1.129 ng 3566: $result.='<input type="hidden" name="gradePartRespid'.
3567: '" value="'.(join ":",@gradePartRespid).'" />'."\n" if ($counter == 0);
1.45 ng 3568: my $ctr = 0;
3569: while ($ctr < scalar(@partlist)) {
3570: $result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
3571: $partlist[$ctr].'" />'."\n";
3572: $ctr++;
3573: }
1.468 albertel 3574: $request->print($result.''."\n");
1.41 ng 3575:
1.441 www 3576: # Done with printing info for one student
3577:
1.468 albertel 3578: $request->print('</div>');#LC_grade_show_user
1.441 www 3579:
3580:
1.41 ng 3581: # print end of form
3582: if ($counter == $total) {
1.592 bisitz 3583: my $endform='<br /><hr /><table border="0"><tr><td>'."\n";
1.485 albertel 3584: $endform.='<input type="button" value="'.&mt('Save & Next').'" '.
1.589 bisitz 3585: 'onclick="javascript:checksubmit(this.form,\'Save & Next\','.
1.417 albertel 3586: $total.','.scalar(@partlist).');" target="_self" /> '."\n";
1.119 ng 3587: my $ntstu ='<select name="NTSTU">'.
3588: '<option>1</option><option>2</option>'.
3589: '<option>3</option><option>5</option>'.
3590: '<option>7</option><option>10</option></select>'."\n";
1.257 albertel 3591: my $nsel = ($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : '1');
1.401 albertel 3592: $ntstu =~ s/<option>$nsel</<option selected="selected">$nsel</;
1.578 raeburn 3593: $endform.=&mt('[_1]student(s)',$ntstu);
1.485 albertel 3594: $endform.=' <input type="button" value="'.&mt('Previous').'" '.
1.589 bisitz 3595: 'onclick="javascript:checksubmit(this.form,\'Previous\');" target="_self" /> '."\n".
1.485 albertel 3596: '<input type="button" value="'.&mt('Next').'" '.
1.589 bisitz 3597: 'onclick="javascript:checksubmit(this.form,\'Next\');" target="_self" /> ';
1.592 bisitz 3598: $endform.='<span class="LC_warning">'.
3599: &mt('(Next and Previous (student) do not save the scores.)').
3600: '</span>'."\n" ;
1.349 albertel 3601: $endform.="<input type='hidden' value='".&get_increment().
1.348 bowersj2 3602: "' name='increment' />";
1.485 albertel 3603: $endform.='</td></tr></table></form>';
1.41 ng 3604: $request->print($endform);
3605: }
3606: return '';
1.38 ng 3607: }
3608:
1.596.2.12.2. 0.2.5(ra 3609:ep-23): sub show_last_submission {
3610:ep-23): my ($uname,$udom,$symb,$essayurl,$responseType,$viewtype,$is_tool,$fullname,
3611:ep-23): $record,$coursedesc_by_cid) = @_;
3612:ep-23): my ($string,$timestamp,$lastgradetime,$lastsubmittime) =
3613:ep-23): &get_last_submission($record,$is_tool);
3614:ep-23):
3615:ep-23): my ($lastsubonly,$partinfo);
3616:ep-23): if ($timestamp eq '') {
3617:ep-23): $lastsubonly.='<div class="LC_grade_submissions_body">'.$string->[0].'</div>';
3618:ep-23): } elsif ($is_tool) {
3619:ep-23): $lastsubonly =
3620:ep-23): '<div class="LC_grade_submissions_body">'
3621:ep-23): .'<b>'.&mt('Date Grade Passed Back:').'</b> '.$timestamp."</div>\n";
3622:ep-23): } else {
3623:ep-23): my ($shownsubmdate,$showngradedate);
3624:ep-23): if ($lastsubmittime && $lastgradetime) {
3625:ep-23): $shownsubmdate = &Apache::lonlocal::locallocaltime($lastsubmittime);
3626:ep-23): if ($lastgradetime > $lastsubmittime) {
3627:ep-23): $showngradedate = &Apache::lonlocal::locallocaltime($lastgradetime);
3628:ep-23): }
3629:ep-23): } else {
3630:ep-23): $shownsubmdate = $timestamp;
3631:ep-23): }
3632:ep-23): $lastsubonly =
3633:ep-23): '<div class="LC_grade_submissions_body">'
3634:ep-23): .'<b>'.&mt('Date Submitted:').'</b> '.$shownsubmdate."\n";
3635:ep-23): if ($showngradedate) {
3636:ep-23): $lastsubonly .= '<br /><b>'.&mt('Date Graded:').'</b> '.$showngradedate."\n";
3637:ep-23): }
3638:ep-23):
3639:ep-23): my %seenparts;
3640:ep-23): my @part_response_id = &flatten_responseType($responseType);
3641:ep-23): foreach my $part (@part_response_id) {
3642:ep-23): my ($partid,$respid) = @{ $part };
3643:ep-23): my $display_part=&get_display_part($partid,$symb);
3644:ep-23): if ($env{"form.$uname:$udom:$partid:submitted_by"}) {
3645:ep-23): if (exists($seenparts{$partid})) { next; }
3646:ep-23): $seenparts{$partid}=1;
3647:ep-23): $partinfo .=
3648:ep-23): '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
3649:ep-23): ' <b>'.&mt('Collaborative submission by: [_1]',
3650:ep-23): '<a href="javascript:viewSubmitter(\''.
3651:ep-23): $env{"form.$uname:$udom:$partid:submitted_by"}.
3652:ep-23): '\');" target="_self">'.
3653:ep-23): $$fullname{$env{"form.$uname:$udom:$partid:submitted_by"}}.'</a>').
3654:ep-23): '<br />';
3655:ep-23): next;
3656:ep-23): }
3657:ep-23): my $responsetype = $responseType->{$partid}->{$respid};
3658:ep-23): if (!exists($record->{"resource.$partid.$respid.submission"})) {
3659:ep-23): $lastsubonly.="\n".'<div class="LC_grade_submission_part">'.
3660:ep-23): '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
3661:ep-23): ' <span class="LC_internal_info">'.
3662:ep-23): '('.&mt('Response ID: [_1]',$respid).')'.
3663:ep-23): '</span> '.
3664:ep-23): '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br /><br /></div>';
3665:ep-23): next;
3666:ep-23): }
3667:ep-23): foreach my $submission (@$string) {
3668:ep-23): my ($partid,$respid) = ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
3669:ep-23): if (join('_',@{$part}) ne ($partid.'_'.$respid)) { next; }
3670:ep-23): my ($ressub,$hide,$draft,$subval) = split(/:/,$submission,4);
3671:ep-23): # Similarity check
3672:ep-23): my $similar='';
3673:ep-23): my ($type,$trial,$rndseed);
3674:ep-23): if ($hide eq 'rand') {
3675:ep-23): $type = 'randomizetry';
3676:ep-23): $trial = $record->{"resource.$partid.tries"};
3677:ep-23): $rndseed = $record->{"resource.$partid.rndseed"};
3678:ep-23): }
3679:ep-23): if ($env{'form.checkPlag'}) {
3680:ep-23): my ($oname,$odom,$ocrsid,$oessay,$osim)=
3681:ep-23): &most_similar($uname,$udom,$symb,$subval);
3682:ep-23): if ($osim) {
3683:ep-23): $osim=int($osim*100.0);
3684:ep-23): if ($hide eq 'anon') {
3685:ep-23): $similar='<hr /><span class="LC_warning">'.&mt("Essay was found to be similar to another essay submitted for this assignment.").'<br />'.
3686:ep-23): &mt('As the current submission is for an anonymous survey, no other details are available.').'</span><hr />';
3687:ep-23): } else {
3688:ep-23): $similar='<hr />';
3689:ep-23): if ($essayurl eq 'lib/templates/simpleproblem.problem') {
3690:ep-23): $similar .= '<h3><span class="LC_warning">'.
3691:ep-23): &mt('Essay is [_1]% similar to an essay by [_2]',
3692:ep-23): $osim,
3693:ep-23): &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')').
3694:ep-23): '</span></h3>';
3695:ep-23): } else {
3696:ep-23): my %old_course_desc;
3697:ep-23): if ($ocrsid ne '') {
3698:ep-23): if (ref($coursedesc_by_cid->{$ocrsid}) eq 'HASH') {
3699:ep-23): %old_course_desc = %{$coursedesc_by_cid->{$ocrsid}};
3700:ep-23): } else {
3701:ep-23): my $args;
3702:ep-23): if ($ocrsid ne $env{'request.course.id'}) {
3703:ep-23): $args = {'one_time' => 1};
3704:ep-23): }
3705:ep-23): %old_course_desc =
3706:ep-23): &Apache::lonnet::coursedescription($ocrsid,$args);
3707:ep-23): $coursedesc_by_cid->{$ocrsid} = \%old_course_desc;
3708:ep-23): }
3709:ep-23): $similar .=
3710:ep-23): '<h3><span class="LC_warning">'.
3711:ep-23): &mt('Essay is [_1]% similar to an essay by [_2] in course [_3] (course id [_4]:[_5])',
3712:ep-23): $osim,
3713:ep-23): &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')',
3714:ep-23): $old_course_desc{'description'},
3715:ep-23): $old_course_desc{'num'},
3716:ep-23): $old_course_desc{'domain'}).
3717:ep-23): '</span></h3>';
3718:ep-23): } else {
3719:ep-23): $similar .=
3720:ep-23): '<h3><span class="LC_warning">'.
3721:ep-23): &mt('Essay is [_1]% similar to an essay by [_2] in an unknown course',
3722:ep-23): $osim,
3723:ep-23): &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')').
3724:ep-23): '</span></h3>';
3725:ep-23): }
3726:ep-23): }
3727:ep-23): $similar .= '<blockquote><i>'.
3728:ep-23): &keywords_highlight($oessay).
3729:ep-23): '</i></blockquote><hr />';
3730:ep-23): }
3731:ep-23): }
3732:ep-23): }
3733:ep-23): my $order=&get_order($partid,$respid,$symb,$uname,$udom,
3734:ep-23): undef,$type,$trial,$rndseed);
3735:ep-23): if (($viewtype eq 'lastonly') ||
3736:ep-23): ($viewtype eq 'datesub') ||
3737:ep-23): ($viewtype =~ /^(last|all)$/)) {
3738:ep-23): my $display_part=&get_display_part($partid,$symb);
3739:ep-23): $lastsubonly.='<div class="LC_grade_submission_part">'.
3740:ep-23): '<b>'.&mt('Part: [_1]',$display_part).'</b>'.
3741:ep-23): ' <span class="LC_internal_info">'.
3742:ep-23): '('.&mt('Response ID: [_1]',$respid).')'.
3743:ep-23): '</span> ';
3744:ep-23): my $files=&get_submitted_files($udom,$uname,$partid,$respid,$record);
3745:ep-23): if (@$files) {
3746:ep-23): if ($hide eq 'anon') {
3747:ep-23): $lastsubonly.='<br />'.&mt('[quant,_1,file] uploaded to this anonymous survey',scalar(@{$files}));
3748:ep-23): } else {
3749:ep-23): $lastsubonly.='<br /><br />'.'<b>'.&mt('Submitted Files:').'</b>'
3750:ep-23): .'<br /><span class="LC_warning">';
3751:ep-23): if(@$files == 1) {
3752:ep-23): $lastsubonly .= &mt('Like all files provided by users, this file may contain viruses!');
3753:ep-23): } else {
3754:ep-23): $lastsubonly .= &mt('Like all files provided by users, these files may contain viruses!');
3755:ep-23): }
3756:ep-23): $lastsubonly .= '</span>';
3757:ep-23): foreach my $file (@$files) {
3758:ep-23): &Apache::lonnet::allowuploaded('/adm/grades',$file);
3759:ep-23): $lastsubonly.='<br /><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.&Apache::loncommon::icon($file).'" border="0" alt="" /> '.$file.'</a>';
3760:ep-23): }
3761:ep-23): }
3762:ep-23): $lastsubonly.='<br />';
3763:ep-23): }
3764:ep-23): if ($hide eq 'anon') {
3765:ep-23): $lastsubonly.='<br /><b>'.&mt('Anonymous Survey').'</b>';
3766:ep-23): } else {
3767:ep-23): $lastsubonly.='<br /><b>'.&mt('Submitted Answer:').' </b>';
3768:ep-23): if ($draft) {
3769:ep-23): $lastsubonly.= ' <span class="LC_warning">'.&mt('Draft Copy').'</span>';
3770:ep-23): }
3771:ep-23): $subval =
3772:ep-23): &cleanRecord($subval,$responsetype,$symb,$partid,
3773:ep-23): $respid,$record,$order,undef,$uname,$udom,$type,$trial,$rndseed);
3774:ep-23): if ($responsetype eq 'essay') {
3775:ep-23): $subval =~ s{\n}{<br />}g;
3776:ep-23): }
3777:ep-23): $lastsubonly.=$subval."\n";
3778:ep-23): }
3779:ep-23): if ($similar) {$lastsubonly.="<br /><br />$similar\n";}
3780:ep-23): $lastsubonly.='</div>';
3781:ep-23): }
3782:ep-23): }
3783:ep-23): }
3784:ep-23): $lastsubonly.='</div>'."\n"; # End: LC_grade_submissions_body
3785:ep-23): }
3786:ep-23): return ($lastsubonly,$partinfo);
3787:ep-23): }
3788:ep-23):
1.464 albertel 3789: sub check_collaborators {
3790: my ($symb,$uname,$udom,$record,$handgrade,$counter) = @_;
3791: my ($result,@col_fullnames);
3792: my ($classlist,undef,$fullname) = &getclasslist('all','0');
3793: foreach my $part (keys(%$handgrade)) {
3794: my $ncol = &Apache::lonnet::EXT('resource.'.$part.
3795: '.maxcollaborators',
3796: $symb,$udom,$uname);
3797: next if ($ncol <= 0);
3798: $part =~ s/\_/\./g;
3799: next if ($record->{'resource.'.$part.'.collaborators'} eq '');
3800: my (@good_collaborators, @bad_collaborators);
3801: foreach my $possible_collaborator
1.596.2.4 raeburn 3802: (split(/[,;\s]+/,$record->{'resource.'.$part.'.collaborators'})) {
1.464 albertel 3803: $possible_collaborator =~ s/[\$\^\(\)]//g;
3804: next if ($possible_collaborator eq '');
1.596.2.8 raeburn 3805: my ($co_name,$co_dom) = split(/:/,$possible_collaborator);
1.464 albertel 3806: $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
3807: next if ($co_name eq $uname && $co_dom eq $udom);
3808: # Doing this grep allows 'fuzzy' specification
3809: my @matches = grep(/^\Q$co_name\E:\Q$co_dom\E$/i,
3810: keys(%$classlist));
3811: if (! scalar(@matches)) {
3812: push(@bad_collaborators, $possible_collaborator);
3813: } else {
3814: push(@good_collaborators, @matches);
3815: }
3816: }
3817: if (scalar(@good_collaborators) != 0) {
1.596.2.8 raeburn 3818: $result.='<br />'.&mt('Collaborators:').'<ol>';
1.464 albertel 3819: foreach my $name (@good_collaborators) {
3820: my ($lastname,$givenn) = split(/,/,$$fullname{$name});
3821: push(@col_fullnames, $givenn.' '.$lastname);
1.596.2.4 raeburn 3822: $result.='<li>'.$fullname->{$name}.'</li>';
1.464 albertel 3823: }
1.596.2.4 raeburn 3824: $result.='</ol><br />'."\n";
1.466 albertel 3825: my ($part)=split(/\./,$part);
1.464 albertel 3826: $result.='<input type="hidden" name="collaborator'.$counter.
3827: '" value="'.$part.':'.(join ':',@good_collaborators).'" />'.
3828: "\n";
3829: }
3830: if (scalar(@bad_collaborators) > 0) {
1.466 albertel 3831: $result.='<div class="LC_warning">';
1.464 albertel 3832: $result.=&mt('This student has submitted [quant,_1,invalid collaborator]: [_2]',scalar(@bad_collaborators),join(', ',@bad_collaborators));
3833: $result .= '</div>';
3834: }
3835: if (scalar(@bad_collaborators > $ncol)) {
1.466 albertel 3836: $result .= '<div class="LC_warning">';
1.464 albertel 3837: $result .= &mt('This student has submitted too many '.
3838: 'collaborators. Maximum is [_1].',$ncol);
3839: $result .= '</div>';
3840: }
3841: }
3842: return ($result,$fullname,\@col_fullnames);
3843: }
3844:
1.44 ng 3845: #--- Retrieve the last submission for all the parts
1.38 ng 3846: sub get_last_submission {
1.596.2.12.2. 0.2.4(ra 3847:ul-23): my ($returnhash,$is_tool)=@_;
0.2.2(ra 3848:ar-23): my (@string,$timestamp,$lastgradetime,$lastsubmittime);
1.119 ng 3849: if ($$returnhash{'version'}) {
1.46 ng 3850: my %lasthash=();
1.596.2.12.2. 0.2.2(ra 3851:ar-23): my %prevsolved=();
3852:ar-23): my %solved=();
3853:ar-23): my $version;
1.119 ng 3854: for ($version=1;$version<=$$returnhash{'version'};$version++) {
1.596.2.12.2. 0.2.2(ra 3855:ar-23): my %handgraded = ();
1.397 albertel 3856: foreach my $key (sort(split(/\:/,
3857: $$returnhash{$version.':keys'}))) {
3858: $lasthash{$key}=$$returnhash{$version.':'.$key};
1.596.2.12.2. 0.2.2(ra 3859:ar-23): if ($key =~ /\.([^.]+)\.regrader$/) {
3860:ar-23): $handgraded{$1} = 1;
3861:ar-23): } elsif ($key =~ /\.portfiles$/) {
3862:ar-23): if (($$returnhash{$version.':'.$key} ne '') &&
3863:ar-23): ($$returnhash{$version.':'.$key} !~ /\.\d+\.\w+$/)) {
3864:ar-23): $lastsubmittime = $$returnhash{$version.':timestamp'};
3865:ar-23): }
3866:ar-23): } elsif ($key =~ /\.submission$/) {
3867:ar-23): if ($$returnhash{$version.':'.$key} ne '') {
3868:ar-23): $lastsubmittime = $$returnhash{$version.':timestamp'};
3869:ar-23): }
3870:ar-23): } elsif ($key =~ /\.([^.]+)\.solved$/) {
3871:ar-23): $prevsolved{$1} = $solved{$1};
3872:ar-23): $solved{$1} = $lasthash{$key};
3873:ar-23): }
0.2.3(ra 3874:ar-23): }
0.2.2(ra 3875:ar-23): foreach my $partid (keys(%handgraded)) {
3876:ar-23): if (($prevsolved{$partid} eq 'ungraded_attempted') &&
3877:ar-23): (($solved{$partid} eq 'incorrect_by_override') ||
3878:ar-23): ($solved{$partid} eq 'correct_by_override'))) {
3879:ar-23): $lastgradetime = $$returnhash{$version.':timestamp'};
3880:ar-23): }
3881:ar-23): if ($solved{$partid} ne '') {
3882:ar-23): $prevsolved{$partid} = $solved{$partid};
3883:ar-23): }
3884:ar-23): }
1.46 ng 3885: }
1.596.2.12.2. 0.2.6(ra 3886:ug-24): #
3887:ug-24): # Timestamp is for last transaction for this resource, which does not
3888:ug-24): # necessarily correspond to the time of last submission for problem (or part).
3889:ug-24): #
3890:ug-24): if ($lasthash{'timestamp'} ne '') {
3891:ug-24): $timestamp = &Apache::lonlocal::locallocaltime($lasthash{'timestamp'});
3892:ug-24): }
1.596.2.2 raeburn 3893: my (%typeparts,%randombytry);
1.596 raeburn 3894: my $showsurv =
3895: &Apache::lonnet::allowed('vas',$env{'request.course.id'});
3896: foreach my $key (sort(keys(%lasthash))) {
3897: if ($key =~ /\.type$/) {
3898: if (($lasthash{$key} eq 'anonsurvey') ||
1.596.2.2 raeburn 3899: ($lasthash{$key} eq 'anonsurveycred') ||
3900: ($lasthash{$key} eq 'randomizetry')) {
1.596 raeburn 3901: my ($ign,@parts) = split(/\./,$key);
3902: pop(@parts);
1.596.2.3 raeburn 3903: my $id = join('.',@parts);
1.596.2.2 raeburn 3904: if ($lasthash{$key} eq 'randomizetry') {
3905: $randombytry{$ign.'.'.$id} = $lasthash{$key};
3906: } else {
3907: unless ($showsurv) {
3908: $typeparts{$ign.'.'.$id} = $lasthash{$key};
3909: }
1.596 raeburn 3910: }
3911: delete($lasthash{$key});
3912: }
3913: }
3914: }
3915: my @hidden = keys(%typeparts);
1.596.2.2 raeburn 3916: my @randomize = keys(%randombytry);
1.397 albertel 3917: foreach my $key (keys(%lasthash)) {
3918: next if ($key !~ /\.submission$/);
1.596 raeburn 3919: my $hide;
3920: if (@hidden) {
3921: foreach my $id (@hidden) {
3922: if ($key =~ /^\Q$id\E/) {
1.596.2.2 raeburn 3923: $hide = 'anon';
1.596 raeburn 3924: last;
3925: }
3926: }
3927: }
1.596.2.2 raeburn 3928: unless ($hide) {
3929: if (@randomize) {
1.596.2.12.2. 3(raebur 3930:5): foreach my $id (@randomize) {
1.596.2.2 raeburn 3931: if ($key =~ /^\Q$id\E/) {
3932: $hide = 'rand';
3933: last;
3934: }
3935: }
3936: }
3937: }
1.397 albertel 3938: my ($partid,$foo) = split(/submission$/,$key);
1.596.2.12.2. 1(raebur 3939:0): my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ? 1 : 0;
0(raebur 3940:4): push(@string, join(':', $key, $hide, $draft, (
8(raebur 3941:4): ref($lasthash{$key}) eq 'ARRAY' ?
3942:4): join(',', @{$lasthash{$key}}) : $lasthash{$key}) ));
1.41 ng 3943: }
3944: }
1.397 albertel 3945: if (!@string) {
1.596.2.12.2. 0.2.4(ra 3946:ul-23): my $msg;
3947:ul-23): if ($is_tool) {
3948:ul-23): $msg = &mt('No grade passed back.');
3949:ul-23): } else {
3950:ul-23): $msg = &mt('Nothing submitted - no attempts.');
3951:ul-23): }
1.397 albertel 3952: $string[0] =
1.596.2.12.2. 0.2.4(ra 3953:ul-23): '<span class="LC_warning">'.$msg.'</span>';
1.397 albertel 3954: }
1.596.2.12.2. 0.2.2(ra 3955:ar-23): return (\@string,$timestamp,$lastgradetime,$lastsubmittime);
1.38 ng 3956: }
1.35 ng 3957:
1.44 ng 3958: #--- High light keywords, with style choosen by user.
1.38 ng 3959: sub keywords_highlight {
1.44 ng 3960: my $string = shift;
1.257 albertel 3961: my $size = $env{'form.kwsize'} eq '0' ? '' : 'size='.$env{'form.kwsize'};
3962: my $styleon = $env{'form.kwstyle'} eq '' ? '' : $env{'form.kwstyle'};
1.41 ng 3963: (my $styleoff = $styleon) =~ s/\</\<\//;
1.257 albertel 3964: my @keylist = split(/[,\s+]/,$env{'form.keywords'});
1.398 albertel 3965: foreach my $keyword (@keylist) {
3966: $string =~ s/\b\Q$keyword\E(\b|\.)/<font color\=$env{'form.kwclr'} $size\>$styleon$keyword$styleoff<\/font>/gi;
1.41 ng 3967: }
3968: return $string;
1.38 ng 3969: }
1.36 ng 3970:
1.596.2.12.2. (raeburn 3971:): # For Tasks provide a mechanism to display previous version for one specific student
3972:):
3973:): sub show_previous_task_version {
3974:): my ($request,$symb) = @_;
3975:): if ($symb eq '') {
8(raebur 3976:4): $request->print(
3977:4): '<span class="LC_error">'.
3978:4): &mt('Unable to handle ambiguous references.').
3979:4): '</span>');
(raeburn 3980:): return '';
3981:): }
3982:): my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
3983:): my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
3984:): if (!&canview($usec)) {
8(raebur 3985:4): $request->print('<span class="LC_warning">'.
3986:4): &mt('Unable to view previous version for requested student.').
3987:4): ' '.&mt('([_1] in section [_2] in course id [_3])',
9(raebur 3988:4): $uname.':'.$udom,$usec,$env{'request.course.id'}).
8(raebur 3989:4): '</span>');
(raeburn 3990:): return;
3991:): }
3992:): my $mode = 'both';
3993:): my $isTask = ($symb =~/\.task$/);
3994:): if ($isTask) {
3995:): if ($env{'form.previousversion'} =~ /^\d+$/) {
3996:): if ($env{'form.fullname'} eq '') {
3997:): $env{'form.fullname'} =
3998:): &Apache::loncommon::plainname($uname,$udom,'lastname');
3999:): }
4000:): my $probtitle=&Apache::lonnet::gettitle($symb);
4001:): $request->print("\n\n".
4002:): '<div class="LC_grade_show_user">'.
4003:): '<h2>'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
4004:): '</h2>'."\n");
4005:): &Apache::lonxml::clear_problem_counter();
4006:): $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode,
4007:): {'previousversion' => $env{'form.previousversion'} }));
4008:): $request->print("\n</div>");
4009:): }
4010:): }
4011:): return;
4012:): }
4013:):
4014:): sub choose_task_version_form {
4015:): my ($symb,$uname,$udom,$nomenu) = @_;
4016:): my $isTask = ($symb =~/\.task$/);
4017:): my ($current,$version,$result,$js,$displayed,$rowtitle);
4018:): if ($isTask) {
4019:): my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
4020:): $udom,$uname);
4021:): if (($record{'resource.0.version'} eq '') ||
4022:): ($record{'resource.0.version'} < 2)) {
4023:): return ($record{'resource.0.version'},
4024:): $record{'resource.0.version'},$result,$js);
4025:): } else {
4026:): $current = $record{'resource.0.version'};
4027:): }
4028:): if ($env{'form.previousversion'}) {
4029:): $displayed = $env{'form.previousversion'};
4030:): $rowtitle = &mt('Choose another version:')
4031:): } else {
4032:): $displayed = $current;
4033:): $rowtitle = &mt('Show earlier version:');
4034:): }
4035:): $result = '<div class="LC_left_float">';
4036:): my $list;
4037:): my $numversions = 0;
4038:): for (my $i=1; $i<=$record{'resource.0.version'}; $i++) {
4039:): if ($i == $current) {
4040:): if (!$env{'form.previousversion'} || $nomenu) {
4041:): next;
4042:): } else {
4043:): $list .= '<option value="'.$i.'">'.&mt('Current').'</option>'."\n";
4044:): $numversions ++;
4045:): }
4046:): } elsif (defined($record{'resource.'.$i.'.0.status'})) {
4047:): unless ($i == $env{'form.previousversion'}) {
4048:): $numversions ++;
4049:): }
4050:): $list .= '<option value="'.$i.'">'.$i.'</option>'."\n";
4051:): }
4052:): }
4053:): if ($numversions) {
4054:): $symb = &HTML::Entities::encode($symb,'<>"&');
4055:): $result .=
4056:): '<form name="getprev" method="post" action=""'.
4057:): ' onsubmit="return previousVersion('."'$uname','$udom','$symb','$displayed'".');">'.
4058:): &Apache::loncommon::start_data_table().
4059:): &Apache::loncommon::start_data_table_row().
4060:): '<th align="left">'.$rowtitle.'</th>'.
4061:): '<td><select name="version">'.
4062:): '<option>'.&mt('Select').'</option>'.
4063:): $list.
4064:): '</select></td>'.
4065:): &Apache::loncommon::end_data_table_row();
4066:): unless ($nomenu) {
4067:): $result .= &Apache::loncommon::start_data_table_row().
4068:): '<th align="left">'.&mt('Open in new window').'</th>'.
4069:): '<td><span class="LC_nobreak">'.
4070:): '<label><input type="radio" name="prevwin" value="1" />'.
4071:): &mt('Yes').'</label>'.
4072:): '<label><input type="radio" name="prevwin" value="0" checked="checked" />'.&mt('No').'</label>'.
4073:): '</span></td>'.
4074:): &Apache::loncommon::end_data_table_row();
4075:): }
4076:): $result .=
4077:): &Apache::loncommon::start_data_table_row().
4078:): '<th align="left"> </th>'.
4079:): '<td>'.
4080:): '<input type="submit" name="prevsub" value="'.&mt('Display').'" />'.
4081:): '</td>'.
4082:): &Apache::loncommon::end_data_table_row().
4083:): &Apache::loncommon::end_data_table().
4084:): '</form>';
4085:): $js = &previous_display_javascript($nomenu,$current);
4086:): } elsif ($displayed && $nomenu) {
4087:): $result .= '<a href="javascript:window.close()">'.&mt('Close window').'</a>';
4088:): } else {
4089:): $result .= &mt('No previous versions to show for this student');
4090:): }
4091:): $result .= '</div>';
4092:): }
4093:): return ($current,$displayed,$result,$js);
4094:): }
4095:):
4096:): sub previous_display_javascript {
4097:): my ($nomenu,$current) = @_;
4098:): my $js = <<"JSONE";
4099:): <script type="text/javascript">
4100:): // <![CDATA[
4101:): function previousVersion(uname,udom,symb) {
4102:): var current = '$current';
4103:): var version = document.getprev.version.options[document.getprev.version.selectedIndex].value;
4104:): var prevstr = new RegExp("^\\\\d+\$");
4105:): if (!prevstr.test(version)) {
4106:): return false;
4107:): }
4108:): var url = '';
4109:): if (version == current) {
4110:): url = '/adm/grades?student='+uname+'&userdom='+udom+'&symb='+symb+'&command=submission';
4111:): } else {
4112:): url = '/adm/grades?student='+uname+'&userdom='+udom+'&symb='+symb+'&command=versionsub&previousversion='+version;
4113:): }
4114:): JSONE
4115:): if ($nomenu) {
4116:): $js .= <<"JSTWO";
4117:): document.location.href = url;
4118:): JSTWO
4119:): } else {
4120:): $js .= <<"JSTHREE";
4121:): var newwin = 0;
4122:): for (var i=0; i<document.getprev.prevwin.length; i++) {
4123:): if (document.getprev.prevwin[i].checked == true) {
4124:): newwin = document.getprev.prevwin[i].value;
4125:): }
4126:): }
4127:): if (newwin == 1) {
4128:): var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
4129:): url = url+'&inhibitmenu=yes';
4130:): if (typeof(previousWin) == 'undefined' || previousWin.closed) {
4131:): previousWin = window.open(url,'',options,1);
4132:): } else {
4133:): previousWin.location.href = url;
4134:): }
4135:): previousWin.focus();
4136:): return false;
4137:): } else {
4138:): document.location.href = url;
4139:): return false;
4140:): }
4141:): JSTHREE
4142:): }
4143:): $js .= <<"ENDJS";
4144:): return false;
4145:): }
4146:): // ]]>
4147:): </script>
4148:): ENDJS
4149:):
4150:): }
4151:):
1.44 ng 4152: #--- Called from submission routine
1.38 ng 4153: sub processHandGrade {
1.596.2.12.2. 1(raebur 4154:0): my ($request,$symb) = @_;
1.324 albertel 4155: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.257 albertel 4156: my $button = $env{'form.gradeOpt'};
4157: my $ngrade = $env{'form.NCT'};
4158: my $ntstu = $env{'form.NTSTU'};
1.301 albertel 4159: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4160: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.596.2.12.2. 8(raebur 4161:1): my ($res_error,%queueable);
4162:1): my ($partlist,$handgrade,$responseType,$numresp,$numessay) = &response_type($symb,\$res_error);
4163:1): if ($res_error) {
4164:1): $request->print(&navmap_errormsg());
4165:1): return;
4166:1): } else {
4167:1): foreach my $part (@{$partlist}) {
4168:1): if (ref($responseType->{$part}) eq 'HASH') {
4169:1): foreach my $id (keys(%{$responseType->{$part}})) {
4170:1): if (($responseType->{$part}->{$id} eq 'essay') ||
4171:1): (lc($handgrade->{$part.'_'.$id}) eq 'yes')) {
4172:1): $queueable{$part} = 1;
4173:1): last;
4174:1): }
4175:1): }
4176:1): }
4177:1): }
4178:1): }
1.301 albertel 4179:
1.44 ng 4180: if ($button eq 'Save & Next') {
1.596.2.12.2. 0.2.7(ra 4181:an-25): my %needpb = &passbacks_for_symb($cdom,$cnum,$symb);
4182:an-25): my (%skip_passback,%pbsave,%pbcollab);
1.44 ng 4183: my $ctr = 0;
4184: while ($ctr < $ngrade) {
1.257 albertel 4185: my ($uname,$udom) = split(/:/,$env{'form.unamedom'.$ctr});
1.596.2.12.2. 1(raebur 4186:5): my ($errorflag,$pts,$wgt,$numhidden) =
0.2.7(ra 4187:an-25): &saveHandGrade($request,$symb,$uname,$udom,$ctr,undef,undef,\%queueable,\%needpb,\%skip_passback,\%pbsave);
1.71 ng 4188: if ($errorflag eq 'no_score') {
4189: $ctr++;
4190: next;
4191: }
1.104 albertel 4192: if ($errorflag eq 'not_allowed') {
1.596.2.12.2. 8(raebur 4193:4): $request->print(
4194:4): '<span class="LC_error">'
4195:4): .&mt('Not allowed to modify grades for [_1]',"$uname:$udom")
4196:4): .'</span>');
1.104 albertel 4197: $ctr++;
4198: next;
4199: }
1.596.2.12.2. 1(raebur 4200:5): if ($numhidden) {
4201:5): $request->print(
4202:5): '<span class="LC_info">'
4203:5): .&mt('For [_1]: [quant,_2,transaction] hidden',"$uname:$udom",$numhidden)
4204:5): .'</span><br />');
4205:5): }
1.257 albertel 4206: my $includemsg = $env{'form.includemsg'.$ctr};
1.44 ng 4207: my ($subject,$message,$msgstatus) = ('','','');
1.418 albertel 4208: my $restitle = &Apache::lonnet::gettitle($symb);
4209: my ($feedurl,$showsymb) =
4210: &get_feedurl_and_symb($symb,$uname,$udom);
4211: my $messagetail;
1.62 albertel 4212: if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.298 www 4213: $subject = $env{'form.msgsub'} if ($includemsg =~ /msgsub/);
1.295 www 4214: unless ($subject=~/\w/) { $subject=&mt('Grading Feedback'); }
1.386 raeburn 4215: $subject.=' ['.$restitle.']';
1.44 ng 4216: my (@msgnum) = split(/,/,$includemsg);
4217: foreach (@msgnum) {
1.257 albertel 4218: $message.=$env{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
1.44 ng 4219: }
1.80 ng 4220: $message =&Apache::lonfeedback::clear_out_html($message);
1.298 www 4221: if ($env{'form.withgrades'.$ctr}) {
4222: $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
1.386 raeburn 4223: $messagetail = " for <a href=\"".
1.596.2.12.2. 1(raebur 4224:0): $feedurl."?symb=$showsymb\">$restitle</a>";
1.386 raeburn 4225: }
4226: $msgstatus =
4227: &Apache::lonmsg::user_normal_msg($uname,$udom,$subject,
4228: $message.$messagetail,
1.418 albertel 4229: undef,$feedurl,undef,
1.386 raeburn 4230: undef,undef,$showsymb,
4231: $restitle);
1.574 bisitz 4232: $request->print('<br />'.&mt('Sending message to [_1]',$uname.':'.$udom).': '.
1.596.2.4 raeburn 4233: $msgstatus.'<br />');
1.44 ng 4234: }
1.257 albertel 4235: if ($env{'form.collaborator'.$ctr}) {
1.155 albertel 4236: my @collabstrs=&Apache::loncommon::get_env_multiple("form.collaborator$ctr");
1.150 albertel 4237: foreach my $collabstr (@collabstrs) {
4238: my ($part,@collaborators) = split(/:/,$collabstr);
1.310 banghart 4239: foreach my $collaborator (@collaborators) {
1.596.2.12.2. 0.2.7(ra 4240:an-25): my ($errorflag,$pts,$wgt,$numchg,$numupdate) =
1.324 albertel 4241: &saveHandGrade($request,$symb,$collaborator,$udom,$ctr,
1.596.2.12.2. 8(raebur 4242:1): $env{'form.unamedom'.$ctr},$part,\%queueable);
1.150 albertel 4243: if ($errorflag eq 'not_allowed') {
1.362 albertel 4244: $request->print("<span class=\"LC_error\">".&mt('Not allowed to modify grades for [_1]',"$collaborator:$udom")."</span>");
1.150 albertel 4245: next;
1.596.2.12.2. 0.2.7(ra 4246:an-25): } else {
4247:an-25): if ($numchg || $numupdate) {
4248:an-25): $pbcollab{$collaborator}{$part} = [$pts,$wgt];
4249:an-25): }
4250:an-25): if ($message ne '') {
4251:an-25): my ($baseurl,$showsymb) =
4252:an-25): &get_feedurl_and_symb($symb,$collaborator,
4253:an-25): $udom);
4254:an-25): if ($env{'form.withgrades'.$ctr}) {
4255:an-25): $messagetail = " for <a href=\"".
4256:an-25): $baseurl."?symb=$showsymb\">$restitle</a>";
4257:an-25): }
4258:an-25): $msgstatus =
4259:an-25): &Apache::lonmsg::user_normal_msg($collaborator,$udom,$subject,$message.$messagetail,undef,$baseurl,undef,undef,undef,$showsymb,$restitle);
4260:an-25): }
1.104 albertel 4261: }
1.44 ng 4262: }
4263: }
4264: }
4265: $ctr++;
4266: }
1.596.2.12.2. 0.2.7(ra 4267:an-25): if ((keys(%pbcollab)) && (keys(%needpb))) {
4268:an-25): foreach my $user (keys(%pbcollab)) {
4269:an-25): my ($clbuname,$clbudom) = split(/:/,$user);
4270:an-25): my $clbusec = &Apache::lonnet::getsection($clbudom,$clbuname,$cdom.'_'.$cnum);
4271:an-25): if (ref($pbcollab{$user}) eq 'HASH') {
4272:an-25): my @clparts = keys(%{$pbcollab{$user}});
4273:an-25): if (@clparts) {
4274:an-25): my $navmap = Apache::lonnavmaps::navmap->new($clbuname,$clbudom,$clbusec);
4275:an-25): if (ref($navmap)) {
4276:an-25): my $res = $navmap->getBySymb($symb);
4277:an-25): if (ref($res)) {
4278:an-25): my $partlist = $res->parts();
4279:an-25): if (ref($partlist) eq 'ARRAY') {
4280:an-25): my (%weights,%awardeds,%excuseds);
4281:an-25): foreach my $part (@{$partlist}) {
4282:an-25): if ($res->status($part) eq $res->EXCUSED) {
4283:an-25): $excuseds{$symb}{$part} = 1;
4284:an-25): } else {
4285:an-25): $excuseds{$symb}{$part} = '';
4286:an-25): }
4287:an-25): if ((exists($pbcollab{$user}{$part})) && (ref($pbcollab{$user}{$part}) eq 'ARRAY')) {
4288:an-25): my $pts = $pbcollab{$user}{$part}[0];
4289:an-25): my $wt = $pbcollab{$user}{$part}[1];
4290:an-25): if ($wt) {
4291:an-25): $awardeds{$symb}{$part} = $pts/$wt;
4292:an-25): $weights{$symb}{$part} = $wt;
4293:an-25): } else {
4294:an-25): $awardeds{$symb}{$part} = 0;
4295:an-25): $weights{$symb}{$part} = 0;
4296:an-25): }
4297:an-25): } else {
4298:an-25): $awardeds{$symb}{$part} = $res->awarded($part);
4299:an-25): $weights{$symb}{$part} = $res->weight($part);
4300:an-25): }
4301:an-25): }
4302:an-25): &process_passbacks('handgrade',[$symb],$cdom,$cnum,$clbudom,$clbuname,$clbusec,\%weights,
4303:an-25): \%awardeds,\%excuseds,\%needpb,\%skip_passback,\%pbsave);
4304:an-25): }
4305:an-25): }
4306:an-25): }
4307:an-25): }
4308:an-25): }
4309:an-25): }
4310:an-25): }
1.44 ng 4311: }
4312:
1.596.2.12.2. 1(raebur 4313:0): my %keyhash = ();
4314:0): if ($numessay) {
1.119 ng 4315: # Keywords sorted in alphabatical order
1.257 albertel 4316: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
4317: $env{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
1.596.2.12.2. 2(raebur 4318:0): $env{'form.keywords'} =~ s/^\s+|\s+$//g;
1.257 albertel 4319: my (@keywords) = sort(split(/\s+/,$env{'form.keywords'}));
4320: $env{'form.keywords'} = join(' ',@keywords);
4321: $keyhash{$symb.'_keywords'} = $env{'form.keywords'};
4322: $keyhash{$symb.'_subject'} = $env{'form.msgsub'};
4323: $keyhash{$loginuser.'_kwclr'} = $env{'form.kwclr'};
4324: $keyhash{$loginuser.'_kwsize'} = $env{'form.kwsize'};
4325: $keyhash{$loginuser.'_kwstyle'} = $env{'form.kwstyle'};
1.596.2.12.2. 1(raebur 4326:0): }
1.119 ng 4327:
1.596.2.12.2. 1(raebur 4328:0): if ($env{'form.compmsg'}) {
1.119 ng 4329: # message center - Order of message gets changed. Blank line is eliminated.
1.257 albertel 4330: # New messages are saved in env for the next student.
1.119 ng 4331: # All messages are saved in nohist_handgrade.db
4332: my ($ctr,$idx) = (1,1);
1.257 albertel 4333: while ($ctr <= $env{'form.savemsgN'}) {
4334: if ($env{'form.savemsg'.$ctr} ne '') {
4335: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.savemsg'.$ctr};
1.119 ng 4336: $idx++;
4337: }
4338: $ctr++;
1.41 ng 4339: }
1.119 ng 4340: $ctr = 0;
4341: while ($ctr < $ngrade) {
1.257 albertel 4342: if ($env{'form.newmsg'.$ctr} ne '') {
4343: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.newmsg'.$ctr};
4344: $env{'form.savemsg'.$idx} = $env{'form.newmsg'.$ctr};
1.119 ng 4345: $idx++;
4346: }
4347: $ctr++;
1.41 ng 4348: }
1.257 albertel 4349: $env{'form.savemsgN'} = --$idx;
4350: $keyhash{$symb.'_savemsgN'} = $env{'form.savemsgN'};
1.596.2.12.2. 1(raebur 4351:0): }
4352:0): if (($numessay) || ($env{'form.compmsg'})) {
1.119 ng 4353: my $putresult = &Apache::lonnet::put
1.301 albertel 4354: ('nohist_handgrade',\%keyhash,$cdom,$cnum);
1.41 ng 4355: }
1.596.2.12.2. 1(raebur 4356:0):
1.44 ng 4357: # Called by Save & Refresh from Highlight Attribute Window
1.257 albertel 4358: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
4359: if ($env{'form.refresh'} eq 'on') {
1.86 ng 4360: my ($ctr,$total) = (0,0);
4361: while ($ctr < $ngrade) {
1.257 albertel 4362: $total++ if $env{'form.unamedom'.$ctr} ne '';
1.86 ng 4363: $ctr++;
4364: }
1.257 albertel 4365: $env{'form.NTSTU'}=$ngrade;
1.86 ng 4366: $ctr = 0;
4367: while ($ctr < $total) {
1.257 albertel 4368: my $processUser = $env{'form.unamedom'.$ctr};
4369: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
4370: $env{'form.fullname'} = $$fullname{$processUser};
1.596.2.12.2. 1(raebur 4371:0): &submission($request,$ctr,$total-1,$symb);
1.41 ng 4372: $ctr++;
4373: }
4374: return '';
4375: }
1.36 ng 4376:
1.44 ng 4377: # Get the next/previous one or group of students
1.257 albertel 4378: my $firststu = $env{'form.unamedom0'};
4379: my $laststu = $env{'form.unamedom'.($ngrade-1)};
1.119 ng 4380: my $ctr = 2;
1.41 ng 4381: while ($laststu eq '') {
1.257 albertel 4382: $laststu = $env{'form.unamedom'.($ngrade-$ctr)};
1.41 ng 4383: $ctr++;
4384: $laststu = $firststu if ($ctr > $ngrade);
4385: }
1.44 ng 4386:
1.41 ng 4387: my (@parsedlist,@nextlist);
4388: my ($nextflg) = 0;
1.524 raeburn 4389: foreach my $item (sort
1.294 albertel 4390: {
4391: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
4392: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
4393: }
4394: return $a cmp $b;
4395: } (keys(%$fullname))) {
1.41 ng 4396: if ($nextflg == 1 && $button =~ /Next$/) {
1.524 raeburn 4397: push(@parsedlist,$item);
1.41 ng 4398: }
1.524 raeburn 4399: $nextflg = 1 if ($item eq $laststu);
1.41 ng 4400: if ($button eq 'Previous') {
1.524 raeburn 4401: last if ($item eq $firststu);
4402: push(@parsedlist,$item);
1.41 ng 4403: }
4404: }
4405: $ctr = 0;
4406: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
4407: foreach my $student (@parsedlist) {
1.257 albertel 4408: my $submitonly=$env{'form.submitonly'};
1.41 ng 4409: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 4410:
4411: if ($submitonly eq 'queued') {
4412: my %queue_status =
4413: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
4414: $udom,$uname);
4415: next if (!defined($queue_status{'gradingqueue'}));
4416: }
4417:
1.156 albertel 4418: if ($submitonly =~ /^(yes|graded|incorrect)$/) {
1.257 albertel 4419: # my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 4420: my %status=&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 4421: my $submitted = 0;
1.248 albertel 4422: my $ungraded = 0;
4423: my $incorrect = 0;
1.524 raeburn 4424: foreach my $item (keys(%status)) {
4425: $submitted = 1 if ($status{$item} ne 'nothing');
4426: $ungraded = 1 if ($status{$item} =~ /^ungraded/);
4427: $incorrect = 1 if ($status{$item} =~ /^incorrect/);
4428: my ($foo,$partid,$foo1) = split(/\./,$item);
1.145 albertel 4429: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
4430: $submitted = 0;
4431: }
1.41 ng 4432: }
1.156 albertel 4433: next if (!$submitted && ($submitonly eq 'yes' ||
4434: $submitonly eq 'incorrect' ||
4435: $submitonly eq 'graded'));
1.248 albertel 4436: next if (!$ungraded && ($submitonly eq 'graded'));
4437: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 4438: }
1.524 raeburn 4439: push(@nextlist,$student) if ($ctr < $ntstu);
1.129 ng 4440: last if ($ctr == $ntstu);
1.41 ng 4441: $ctr++;
4442: }
1.36 ng 4443:
1.41 ng 4444: $ctr = 0;
4445: my $total = scalar(@nextlist)-1;
1.39 ng 4446:
1.524 raeburn 4447: foreach (sort(@nextlist)) {
1.41 ng 4448: my ($uname,$udom,$submitter) = split(/:/);
1.257 albertel 4449: $env{'form.student'} = $uname;
4450: $env{'form.userdom'} = $udom;
4451: $env{'form.fullname'} = $$fullname{$_};
1.596.2.12.2. 1(raebur 4452:0): &submission($request,$ctr,$total,$symb);
1.41 ng 4453: $ctr++;
4454: }
4455: if ($total < 0) {
1.596.2.12.2. 1(raebur 4456:0): my $the_end.='<p>'.&mt('[_1]Message:[_2] No more students for this section or class.','<b>','</b>').'</p>'."\n";
1.41 ng 4457: $request->print($the_end);
4458: }
4459: return '';
1.38 ng 4460: }
1.36 ng 4461:
1.44 ng 4462: #---- Save the score and award for each student, if changed
1.38 ng 4463: sub saveHandGrade {
1.596.2.12.2. 0.2.7(ra 4464:an-25): my ($request,$symb,$stuname,$domain,$newflg,$submitter,$part,$queueable,$needpb,$skip_passback,$pbsave) = @_;
1.342 banghart 4465: my @version_parts;
1.104 albertel 4466: my $usec = &Apache::lonnet::getsection($domain,$stuname,
1.257 albertel 4467: $env{'request.course.id'});
1.104 albertel 4468: if (!&canmodify($usec)) { return('not_allowed'); }
1.337 banghart 4469: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
1.251 banghart 4470: my @parts_graded;
1.77 ng 4471: my %newrecord = ();
1.596.2.12.2. 0.2.7(ra 4472:an-25): my ($pts,$wgt,$totchg,$sendupdate) = ('','',0,0);
1.269 raeburn 4473: my %aggregate = ();
4474: my $aggregateflag = 0;
1.596.2.12.2. 1(raebur 4475:5): if ($env{'form.HIDE'.$newflg}) {
4476:5): my ($version,$parts) = split(/:/,$env{'form.HIDE'.$newflg},2);
4477:5): my $numchgs = &makehidden($version,$parts,\%record,$symb,$domain,$stuname,1);
4478:5): $totchg += $numchgs;
4479:5): }
0.2.7(ra 4480:an-25): my (%weights,%awardeds,%excuseds);
1.301 albertel 4481: my @parts = split(/:/,$env{'form.partlist'.$newflg});
4482: foreach my $new_part (@parts) {
1.596.2.12.2. 0.2.7(ra 4483:an-25): #collaborator ($submitter may vary for different parts)
1.259 banghart 4484: if ($submitter && $new_part ne $part) { next; }
4485: my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
1.596.2.12.2. 0.2.7(ra 4486:an-25): if ($env{'form.WGT'.$newflg.'_'.$new_part} eq '') {
4487:an-25): $weights{$symb}{$new_part} = 1;
4488:an-25): } else {
4489:an-25): $weights{$symb}{$new_part} = $env{'form.WGT'.$newflg.'_'.$new_part};
4490:an-25): }
1.125 ng 4491: if ($dropMenu eq 'excused') {
1.596.2.12.2. 0.2.7(ra 4492:an-25): $excuseds{$symb}{$new_part} = 1;
4493:an-25): $awardeds{$symb}{$new_part} = '';
1.259 banghart 4494: if ($record{'resource.'.$new_part.'.solved'} ne 'excused') {
4495: $newrecord{'resource.'.$new_part.'.solved'} = 'excused';
4496: if (exists($record{'resource.'.$new_part.'.awarded'})) {
4497: $newrecord{'resource.'.$new_part.'.awarded'} = '';
1.58 albertel 4498: }
1.364 banghart 4499: $newrecord{'resource.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.596.2.12.2. 0.2.7(ra 4500:an-25): $sendupdate ++;
1.58 albertel 4501: }
1.125 ng 4502: } elsif ($dropMenu eq 'reset status'
1.259 banghart 4503: && exists($record{'resource.'.$new_part.'.solved'})) { #don't bother if no old records -> no attempts
1.524 raeburn 4504: foreach my $key (keys(%record)) {
1.259 banghart 4505: if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
1.197 albertel 4506: }
1.259 banghart 4507: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 4508: "$env{'user.name'}:$env{'user.domain'}";
1.270 albertel 4509: my $totaltries = $record{'resource.'.$part.'.tries'};
4510:
4511: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
4512: [$new_part]);
4513: my $aggtries =$totaltries;
1.269 raeburn 4514: if ($last_resets{$new_part}) {
1.270 albertel 4515: $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
4516: $new_part);
1.269 raeburn 4517: }
1.270 albertel 4518:
4519: my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
1.269 raeburn 4520: if ($aggtries > 0) {
1.327 albertel 4521: &decrement_aggs($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
1.269 raeburn 4522: $aggregateflag = 1;
4523: }
1.596.2.12.2. 0.2.7(ra 4524:an-25): $sendupdate ++;
4525:an-25): $excuseds{$symb}{$new_part} = '';
4526:an-25): $awardeds{$symb}{$new_part} = '';
1.125 ng 4527: } elsif ($dropMenu eq '') {
1.259 banghart 4528: $pts = ($env{'form.GD_BOX'.$newflg.'_'.$new_part} ne '' ?
4529: $env{'form.GD_BOX'.$newflg.'_'.$new_part} :
4530: $env{'form.RADVAL'.$newflg.'_'.$new_part});
4531: if ($pts eq '' && $env{'form.GD_SEL'.$newflg.'_'.$new_part} eq '') {
1.153 albertel 4532: next;
4533: }
1.259 banghart 4534: $wgt = $env{'form.WGT'.$newflg.'_'.$new_part} eq '' ? 1 :
4535: $env{'form.WGT'.$newflg.'_'.$new_part};
1.41 ng 4536: my $partial= $pts/$wgt;
1.596.2.12.2. 0.2.7(ra 4537:an-25): $awardeds{$symb}{$new_part} = $partial;
4538:an-25): $excuseds{$symb}{$new_part} = '';
1.259 banghart 4539: if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
1.153 albertel 4540: #do not update score for part if not changed.
1.346 banghart 4541: &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
1.153 albertel 4542: next;
1.251 banghart 4543: } else {
1.524 raeburn 4544: push(@parts_graded,$new_part);
1.596.2.12.2. 0.2.7(ra 4545:an-25): $sendupdate ++;
1.153 albertel 4546: }
1.259 banghart 4547: if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
4548: $newrecord{'resource.'.$new_part.'.awarded'} = $partial;
1.153 albertel 4549: }
1.259 banghart 4550: my $reckey = 'resource.'.$new_part.'.solved';
1.41 ng 4551: if ($partial == 0) {
1.153 albertel 4552: if ($record{$reckey} ne 'incorrect_by_override') {
4553: $newrecord{$reckey} = 'incorrect_by_override';
4554: }
1.41 ng 4555: } else {
1.153 albertel 4556: if ($record{$reckey} ne 'correct_by_override') {
4557: $newrecord{$reckey} = 'correct_by_override';
4558: }
4559: }
4560: if ($submitter &&
1.259 banghart 4561: ($record{'resource.'.$new_part.'.submitted_by'} ne $submitter)) {
4562: $newrecord{'resource.'.$new_part.'.submitted_by'} = $submitter;
1.41 ng 4563: }
1.259 banghart 4564: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 4565: "$env{'user.name'}:$env{'user.domain'}";
1.41 ng 4566: }
1.259 banghart 4567: # unless problem has been graded, set flag to version the submitted files
1.305 banghart 4568: unless ($record{'resource.'.$new_part.'.solved'} =~ /^correct_/ ||
4569: $record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override' ||
4570: $dropMenu eq 'reset status')
4571: {
1.524 raeburn 4572: push(@version_parts,$new_part);
1.259 banghart 4573: }
1.41 ng 4574: }
1.301 albertel 4575: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4576: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4577:
1.344 albertel 4578: if (%newrecord) {
4579: if (@version_parts) {
1.364 banghart 4580: my @changed_keys = &version_portfiles(\%record, \@parts_graded,
4581: $env{'request.course.id'}, $symb, $domain, $stuname, \@version_parts);
1.344 albertel 4582: @newrecord{@changed_keys} = @record{@changed_keys};
1.367 albertel 4583: foreach my $new_part (@version_parts) {
4584: &handback_files($request,$symb,$stuname,$domain,$newflg,
4585: $new_part,\%newrecord);
4586: }
1.259 banghart 4587: }
1.44 ng 4588: &Apache::lonnet::cstore(\%newrecord,$symb,
1.257 albertel 4589: $env{'request.course.id'},$domain,$stuname);
1.380 albertel 4590: &check_and_remove_from_queue(\@parts,\%record,\%newrecord,$symb,
1.596.2.12.2. 8(raebur 4591:1): $cdom,$cnum,$domain,$stuname,$queueable);
1.41 ng 4592: }
1.269 raeburn 4593: if ($aggregateflag) {
4594: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 4595: $cdom,$cnum);
1.269 raeburn 4596: }
1.596.2.12.2. 0.2.7(ra 4597:an-25): if (($sendupdate || $totchg) && (!$submitter)) {
4598:an-25): if ((ref($needpb) eq 'HASH') &&
4599:an-25): (keys(%{$needpb}))) {
4600:an-25): &process_passbacks('handgrade',[$symb],$cdom,$cnum,$domain,$stuname,$usec,\%weights,
4601:an-25): \%awardeds,\%excuseds,$needpb,$skip_passback,$pbsave);
4602:an-25): }
4603:an-25): }
4604:an-25): return ('',$pts,$wgt,$totchg,$sendupdate);
1(raebur 4605:5): }
4606:5):
4607:5): sub makehidden {
4608:5): my ($version,$parts,$record,$symb,$domain,$stuname,$tolog) = @_;
4609:5): return unless (ref($record) eq 'HASH');
4610:5): my %modified;
4611:5): my $numchanged = 0;
4612:5): if (exists($record->{$version.':keys'})) {
4613:5): my $partsregexp = $parts;
4614:5): $partsregexp =~ s/,/|/g;
4615:5): foreach my $key (split(/\:/,$record->{$version.':keys'})) {
4616:5): if ($key =~ /^resource\.(?:$partsregexp)\.([^\.]+)$/) {
4617:5): my $item = $1;
4618:5): unless (($item eq 'solved') || ($item =~ /^award(|msg|ed)$/)) {
4619:5): $modified{$key} = $record->{$version.':'.$key};
4620:5): }
4621:5): } elsif ($key =~ m{^(resource\.(?:$partsregexp)\.[^\.]+\.)(.+)$}) {
4622:5): $modified{$1.'hidden'.$2} = $record->{$version.':'.$key};
4623:5): } elsif ($key =~ /^(ip|timestamp|host)$/) {
4624:5): $modified{$key} = $record->{$version.':'.$key};
4625:5): }
4626:5): }
4627:5): if (keys(%modified)) {
4628:5): if (&Apache::lonnet::putstore($env{'request.course.id'},$symb,$version,\%modified,
4629:5): $domain,$stuname,$tolog) eq 'ok') {
4630:5): $numchanged ++;
4631:5): }
4632:5): }
4633:5): }
4634:5): return $numchanged;
1.36 ng 4635: }
1.322 albertel 4636:
1.380 albertel 4637: sub check_and_remove_from_queue {
1.596.2.12.2. 8(raebur 4638:1): my ($parts,$record,$newrecord,$symb,$cdom,$cnum,$domain,$stuname,$queueable) = @_;
1.380 albertel 4639: my @ungraded_parts;
4640: foreach my $part (@{$parts}) {
4641: if ( $record->{ 'resource.'.$part.'.awarded'} eq ''
4642: && $record->{ 'resource.'.$part.'.solved' } ne 'excused'
4643: && $newrecord->{'resource.'.$part.'.awarded'} eq ''
4644: && $newrecord->{'resource.'.$part.'.solved' } ne 'excused'
4645: ) {
1.596.2.12.2. 8(raebur 4646:1): if ($queueable->{$part}) {
4647:1): push(@ungraded_parts, $part);
4648:1): }
1.380 albertel 4649: }
4650: }
4651: if ( !@ungraded_parts ) {
4652: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,
4653: $cnum,$domain,$stuname);
4654: }
4655: }
4656:
1.337 banghart 4657: sub handback_files {
4658: my ($request,$symb,$stuname,$domain,$newflg,$new_part,$newrecord) = @_;
1.517 raeburn 4659: my $portfolio_root = '/userfiles/portfolio';
1.582 raeburn 4660: my $res_error;
4661: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
4662: if ($res_error) {
4663: $request->print('<br />'.&navmap_errormsg().'<br />');
4664: return;
4665: }
1.596.2.4 raeburn 4666: my @handedback;
4667: my $file_msg;
1.375 albertel 4668: my @part_response_id = &flatten_responseType($responseType);
4669: foreach my $part_response_id (@part_response_id) {
4670: my ($part_id,$resp_id) = @{ $part_response_id };
4671: my $part_resp = join('_',@{ $part_response_id });
1.596.2.4 raeburn 4672: if (($env{'form.'.$newflg.'_'.$part_resp.'_countreturndoc'} =~ /^\d+$/) & ($new_part eq $part_id)) {
4673: for (my $counter=1; $counter<=$env{'form.'.$newflg.'_'.$part_resp.'_countreturndoc'}; $counter++) {
1.337 banghart 4674: # if multiple files are uploaded names will be 'returndoc2','returndoc3'
1.596.2.4 raeburn 4675: if ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$counter}) {
4676: my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$counter.'.filename'};
1.338 banghart 4677: my ($directory,$answer_file) =
1.596.2.4 raeburn 4678: ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$counter} =~ /^(.*?)([^\/]*)$/);
1.338 banghart 4679: my ($answer_name,$answer_ver,$answer_ext) =
4680: &file_name_version_ext($answer_file);
1.355 banghart 4681: my ($portfolio_path) = ($directory =~ /^.+$stuname\/portfolio(.*)/);
1.517 raeburn 4682: my $getpropath = 1;
1.596.2.12.2. (raeburn 4683:): my ($dir_list,$listerror) =
4684:): &Apache::lonnet::dirlist($portfolio_root.$portfolio_path,
4685:): $domain,$stuname,$getpropath);
4686:): my $version = &get_next_version($answer_name,$answer_ext,$dir_list);
3(raebur 4687:3): # fix filename
1.355 banghart 4688: my ($save_file_name) = (($directory.$answer_name.".$version.".$answer_ext) =~ /^.+\/${stuname}\/(.*)/);
4689: my $result=&Apache::lonnet::finishuserfileupload($stuname,$domain,
1.596.2.4 raeburn 4690: $newflg.'_'.$part_resp.'_returndoc'.$counter,
1.355 banghart 4691: $save_file_name);
1.337 banghart 4692: if ($result !~ m|^/uploaded/|) {
1.536 raeburn 4693: $request->print('<br /><span class="LC_error">'.
4694: &mt('An error occurred ([_1]) while trying to upload [_2].',
1.596.2.4 raeburn 4695: $result,$newflg.'_'.$part_resp.'_returndoc'.$counter).
1.536 raeburn 4696: '</span>');
1.356 banghart 4697: } else {
1.360 banghart 4698: # mark the file as read only
1.596.2.4 raeburn 4699: push(@handedback,$save_file_name);
1.367 albertel 4700: if (exists($$newrecord{"resource.$new_part.$resp_id.handback"})) {
4701: $$newrecord{"resource.$new_part.$resp_id.handback"}.=',';
4702: }
4703: $$newrecord{"resource.$new_part.$resp_id.handback"} .= $save_file_name;
1.596.2.4 raeburn 4704: $file_msg.='<span class="LC_filename"><a href="/uploaded/'."$domain/$stuname/".$save_file_name.'">'.$save_file_name."</a></span> <br />";
1.367 albertel 4705:
1.337 banghart 4706: }
1.596.2.12.2. 3(raebur 4707:3): $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 4708: }
4709: }
4710: }
1.596.2.4 raeburn 4711: }
4712: if (@handedback > 0) {
4713: $request->print('<br />');
4714: my @what = ($symb,$env{'request.course.id'},'handback');
4715: &Apache::lonnet::mark_as_readonly($domain,$stuname,\@handedback,\@what);
4716: my $user_lh = &Apache::loncommon::user_lang($stuname,$domain,$env{'request.course.id'});
4717: my ($subject,$message);
4718: if (scalar(@handedback) == 1) {
4719: $subject = &mt_user($user_lh,'File Handed Back by Instructor');
1.596.2.12.2. 1(raebur 4720:0): $message = &mt_user($user_lh,'A file has been returned that was originally submitted in response to: ');
1.596.2.4 raeburn 4721: } else {
4722: $subject = &mt_user($user_lh,'Files Handed Back by Instructor');
4723: $message = &mt_user($user_lh,'Files have been returned that were originally submitted in response to: ');
4724: }
4725: $message .= "<p><strong>".&Apache::lonnet::gettitle($symb)." </strong></p>";
4726: $message .= &mt_user($user_lh,'The returned file(s) are named: [_1]',"<br />$file_msg <br />").
4727: &mt_user($user_lh,'The file(s) can be found in your [_1]portfolio[_2].','<a href="/adm/portfolio">','</a>');
4728: my ($feedurl,$showsymb) =
4729: &get_feedurl_and_symb($symb,$domain,$stuname);
4730: my $restitle = &Apache::lonnet::gettitle($symb);
4731: $subject .= ' '.&mt_user($user_lh,'(File Returned)').' ['.$restitle.']';
4732: my $msgstatus =
4733: &Apache::lonmsg::user_normal_msg($stuname,$domain,$subject,
4734: $message,undef,$feedurl,undef,undef,undef,$showsymb,
4735: $restitle);
4736: if ($msgstatus) {
4737: $request->print(&mt('Notification message status: [_1]','<span class="LC_info">'.$msgstatus.'</span>').'<br />');
4738: }
4739: }
1.338 banghart 4740: return;
1.337 banghart 4741: }
4742:
1.418 albertel 4743: sub get_feedurl_and_symb {
4744: my ($symb,$uname,$udom) = @_;
4745: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
4746: $url = &Apache::lonnet::clutter($url);
4747: my $encrypturl=&Apache::lonnet::EXT('resource.0.encrypturl',
4748: $symb,$udom,$uname);
4749: if ($encrypturl =~ /^yes$/i) {
4750: &Apache::lonenc::encrypted(\$url,1);
4751: &Apache::lonenc::encrypted(\$symb,1);
4752: }
4753: return ($url,$symb);
4754: }
4755:
1.313 banghart 4756: sub get_submitted_files {
4757: my ($udom,$uname,$partid,$respid,$record) = @_;
4758: my @files;
4759: if ($$record{"resource.$partid.$respid.portfiles"}) {
4760: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
4761: foreach my $file (split(',',$$record{"resource.$partid.$respid.portfiles"})) {
4762: push(@files,$file_url.$file);
4763: }
4764: }
4765: if ($$record{"resource.$partid.$respid.uploadedurl"}) {
4766: push(@files,$$record{"resource.$partid.$respid.uploadedurl"});
4767: }
4768: return (\@files);
4769: }
1.322 albertel 4770:
1.269 raeburn 4771: # ----------- Provides number of tries since last reset.
4772: sub get_num_tries {
4773: my ($record,$last_reset,$part) = @_;
4774: my $timestamp = '';
4775: my $num_tries = 0;
4776: if ($$record{'version'}) {
4777: for (my $version=$$record{'version'};$version>=1;$version--) {
4778: if (exists($$record{$version.':resource.'.$part.'.solved'})) {
4779: $timestamp = $$record{$version.':timestamp'};
4780: if ($timestamp > $last_reset) {
4781: $num_tries ++;
4782: } else {
4783: last;
4784: }
4785: }
4786: }
4787: }
4788: return $num_tries;
4789: }
4790:
4791: # ----------- Determine decrements required in aggregate totals
4792: sub decrement_aggs {
4793: my ($symb,$part,$aggregate,$aggtries,$totaltries,$solvedstatus) = @_;
4794: my %decrement = (
4795: attempts => 0,
4796: users => 0,
4797: correct => 0
4798: );
4799: $decrement{'attempts'} = $aggtries;
4800: if ($solvedstatus =~ /^correct/) {
4801: $decrement{'correct'} = 1;
4802: }
4803: if ($aggtries == $totaltries) {
4804: $decrement{'users'} = 1;
4805: }
1.524 raeburn 4806: foreach my $type (keys(%decrement)) {
1.269 raeburn 4807: $$aggregate{$symb."\0".$part."\0".$type} = -$decrement{$type};
4808: }
4809: return;
4810: }
4811:
4812: # ----------- Determine timestamps for last reset of aggregate totals for parts
4813: sub get_last_resets {
1.270 albertel 4814: my ($symb,$courseid,$partids) =@_;
4815: my %last_resets;
1.269 raeburn 4816: my $cdom = $env{'course.'.$courseid.'.domain'};
4817: my $cname = $env{'course.'.$courseid.'.num'};
1.271 albertel 4818: my @keys;
4819: foreach my $part (@{$partids}) {
4820: push(@keys,"$symb\0$part\0resettime");
4821: }
4822: my %results=&Apache::lonnet::get('nohist_resourcetracker',\@keys,
4823: $cdom,$cname);
4824: foreach my $part (@{$partids}) {
4825: $last_resets{$part}=$results{"$symb\0$part\0resettime"};
1.269 raeburn 4826: }
1.270 albertel 4827: return %last_resets;
1.269 raeburn 4828: }
4829:
1.251 banghart 4830: # ----------- Handles creating versions for portfolio files as answers
4831: sub version_portfiles {
1.343 banghart 4832: my ($record, $parts_graded, $courseid, $symb, $domain, $stu_name, $v_flag) = @_;
1.263 banghart 4833: my $version_parts = join('|',@$v_flag);
1.343 banghart 4834: my @returned_keys;
1.255 banghart 4835: my $parts = join('|', @$parts_graded);
1.517 raeburn 4836: my $portfolio_root = '/userfiles/portfolio';
1.277 albertel 4837: foreach my $key (keys(%$record)) {
1.259 banghart 4838: my $new_portfiles;
1.263 banghart 4839: if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
1.342 banghart 4840: my @versioned_portfiles;
1.367 albertel 4841: my @portfiles = split(/\s*,\s*/,$$record{$key});
1.252 banghart 4842: foreach my $file (@portfiles) {
1.306 banghart 4843: &Apache::lonnet::unmark_as_readonly($domain,$stu_name,[$symb,$env{'request.course.id'}],$file);
1.304 albertel 4844: my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*)$/);
4845: my ($answer_name,$answer_ver,$answer_ext) =
4846: &file_name_version_ext($answer_file);
1.596.2.12.2. (raeburn 4847:): my $getpropath = 1;
4848:): my ($dir_list,$listerror) =
4849:): &Apache::lonnet::dirlist($portfolio_root.$directory,$domain,
4850:): $stu_name,$getpropath);
4851:): my $version = &get_next_version($answer_name,$answer_ext,$dir_list);
1.306 banghart 4852: my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version);
4853: if ($new_answer ne 'problem getting file') {
1.342 banghart 4854: push(@versioned_portfiles, $directory.$new_answer);
1.306 banghart 4855: &Apache::lonnet::mark_as_readonly($domain,$stu_name,
1.367 albertel 4856: [$directory.$new_answer],
1.306 banghart 4857: [$symb,$env{'request.course.id'},'graded']);
1.259 banghart 4858: }
1.252 banghart 4859: }
1.343 banghart 4860: $$record{$key} = join(',',@versioned_portfiles);
4861: push(@returned_keys,$key);
1.251 banghart 4862: }
1.596.2.12.2. 0.2.6(ra 4863:ug-24): }
4864:ug-24): return (@returned_keys);
1.305 banghart 4865: }
4866:
1.307 banghart 4867: sub get_next_version {
1.341 banghart 4868: my ($answer_name, $answer_ext, $dir_list) = @_;
1.307 banghart 4869: my $version;
1.596.2.12.2. (raeburn 4870:): if (ref($dir_list) eq 'ARRAY') {
4871:): foreach my $row (@{$dir_list}) {
4872:): my ($file) = split(/\&/,$row,2);
4873:): my ($file_name,$file_version,$file_ext) =
4874:): &file_name_version_ext($file);
4875:): if (($file_name eq $answer_name) &&
4876:): ($file_ext eq $answer_ext)) {
4877:): # gets here if filename and extension match,
4878:): # regardless of version
1.307 banghart 4879: if ($file_version ne '') {
1.596.2.12.2. (raeburn 4880:): # a versioned file is found so save it for later
4881:): if ($file_version > $version) {
4882:): $version = $file_version;
4883:): }
1.307 banghart 4884: }
4885: }
4886: }
1.596.2.12.2. (raeburn 4887:): }
1.307 banghart 4888: $version ++;
4889: return($version);
4890: }
4891:
1.305 banghart 4892: sub version_selected_portfile {
1.306 banghart 4893: my ($domain,$stu_name,$directory,$file_name,$version) = @_;
4894: my ($answer_name,$answer_ver,$answer_ext) =
4895: &file_name_version_ext($file_name);
4896: my $new_answer;
4897: $env{'form.copy'} = &Apache::lonnet::getfile("/uploaded/$domain/$stu_name/portfolio$directory$file_name");
4898: if($env{'form.copy'} eq '-1') {
4899: $new_answer = 'problem getting file';
4900: } else {
4901: $new_answer = $answer_name.'.'.$version.'.'.$answer_ext;
4902: my $copy_result = &Apache::lonnet::finishuserfileupload(
4903: $stu_name,$domain,'copy',
4904: '/portfolio'.$directory.$new_answer);
4905: }
4906: return ($new_answer);
1.251 banghart 4907: }
4908:
1.304 albertel 4909: sub file_name_version_ext {
4910: my ($file)=@_;
4911: my @file_parts = split(/\./, $file);
4912: my ($name,$version,$ext);
4913: if (@file_parts > 1) {
4914: $ext=pop(@file_parts);
4915: if (@file_parts > 1 && $file_parts[-1] =~ /^\d+$/) {
4916: $version=pop(@file_parts);
4917: }
4918: $name=join('.',@file_parts);
4919: } else {
4920: $name=join('.',@file_parts);
4921: }
4922: return($name,$version,$ext);
4923: }
4924:
1.44 ng 4925: #--------------------------------------------------------------------------------------
4926: #
4927: #-------------------------- Next few routines handles grading by section or whole class
4928: #
4929: #--- Javascript to handle grading by section or whole class
1.42 ng 4930: sub viewgrades_js {
4931: my ($request) = shift;
4932:
1.539 riegler 4933: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
1.596.2.12.2. 6(raebur 4934:6): &js_escape(\$alertmsg);
1(raebur 4935:0): $request->print(&Apache::lonhtmlcommon::scripttag(<<VIEWJAVASCRIPT));
1.45 ng 4936: function writePoint(partid,weight,point) {
1.125 ng 4937: var radioButton = document.classgrade["RADVAL_"+partid];
4938: var textbox = document.classgrade["TEXTVAL_"+partid];
1.42 ng 4939: if (point == "textval") {
1.125 ng 4940: point = document.classgrade["TEXTVAL_"+partid].value;
1.109 matthew 4941: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 4942: alert("$alertmsg"+parseFloat(point));
1.42 ng 4943: var resetbox = false;
4944: for (var i=0; i<radioButton.length; i++) {
4945: if (radioButton[i].checked) {
4946: textbox.value = i;
4947: resetbox = true;
4948: }
4949: }
4950: if (!resetbox) {
4951: textbox.value = "";
4952: }
4953: return;
4954: }
1.109 matthew 4955: if (parseFloat(point) > parseFloat(weight)) {
4956: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 4957: ") greater than the weight for the part. Accept?");
4958: if (resp == false) {
4959: textbox.value = "";
4960: return;
4961: }
4962: }
1.42 ng 4963: for (var i=0; i<radioButton.length; i++) {
4964: radioButton[i].checked=false;
1.109 matthew 4965: if (parseFloat(point) == i) {
1.42 ng 4966: radioButton[i].checked=true;
4967: }
4968: }
1.41 ng 4969:
1.42 ng 4970: } else {
1.125 ng 4971: textbox.value = parseFloat(point);
1.42 ng 4972: }
1.41 ng 4973: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 4974: var user = document.classgrade["ctr"+i].value;
1.289 albertel 4975: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 4976: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
4977: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
4978: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 4979: if (saveval != "correct") {
4980: scorename.value = point;
1.43 ng 4981: if (selname[0].selected != true) {
4982: selname[0].selected = true;
4983: }
1.42 ng 4984: }
4985: }
1.125 ng 4986: document.classgrade["SELVAL_"+partid][0].selected = true;
1.42 ng 4987: }
4988:
4989: function writeRadText(partid,weight) {
1.125 ng 4990: var selval = document.classgrade["SELVAL_"+partid];
4991: var radioButton = document.classgrade["RADVAL_"+partid];
1.265 www 4992: var override = document.classgrade["FORCE_"+partid].checked;
1.125 ng 4993: var textbox = document.classgrade["TEXTVAL_"+partid];
4994: if (selval[1].selected || selval[2].selected) {
1.42 ng 4995: for (var i=0; i<radioButton.length; i++) {
4996: radioButton[i].checked=false;
4997:
4998: }
4999: textbox.value = "";
5000:
5001: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 5002: var user = document.classgrade["ctr"+i].value;
1.289 albertel 5003: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 5004: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
5005: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
5006: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 5007: if ((saveval != "correct") || override) {
1.42 ng 5008: scorename.value = "";
1.125 ng 5009: if (selval[1].selected) {
5010: selname[1].selected = true;
5011: } else {
5012: selname[2].selected = true;
5013: if (Number(document.classgrade["GD_"+user+"_"+partid+"_tries"].value))
5014: {document.classgrade["GD_"+user+"_"+partid+"_tries"].value = '0';}
5015: }
1.42 ng 5016: }
5017: }
1.43 ng 5018: } else {
5019: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 5020: var user = document.classgrade["ctr"+i].value;
1.289 albertel 5021: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 5022: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
5023: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
5024: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 5025: if ((saveval != "correct") || override) {
1.125 ng 5026: scorename.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
1.43 ng 5027: selname[0].selected = true;
5028: }
5029: }
5030: }
1.42 ng 5031: }
5032:
5033: function changeSelect(partid,user) {
1.125 ng 5034: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
5035: var textbox = document.classgrade["GD_"+user+'_'+partid+"_awarded"];
1.44 ng 5036: var point = textbox.value;
1.125 ng 5037: var weight = document.classgrade["weight_"+partid].value;
1.44 ng 5038:
1.109 matthew 5039: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 5040: alert("$alertmsg"+parseFloat(point));
1.44 ng 5041: textbox.value = "";
5042: return;
5043: }
1.109 matthew 5044: if (parseFloat(point) > parseFloat(weight)) {
5045: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 5046: ") greater than the weight of the part. Accept?");
5047: if (resp == false) {
5048: textbox.value = "";
5049: return;
5050: }
5051: }
1.42 ng 5052: selval[0].selected = true;
5053: }
5054:
5055: function changeOneScore(partid,user) {
1.125 ng 5056: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
5057: if (selval[1].selected || selval[2].selected) {
5058: document.classgrade["GD_"+user+'_'+partid+"_awarded"].value = "";
5059: if (selval[2].selected) {
5060: document.classgrade["GD_"+user+'_'+partid+"_tries"].value = "0";
5061: }
1.269 raeburn 5062: }
1.42 ng 5063: }
5064:
5065: function resetEntry(numpart) {
5066: for (ctpart=0;ctpart<numpart;ctpart++) {
1.125 ng 5067: var partid = document.classgrade["partid_"+ctpart].value;
5068: var radioButton = document.classgrade["RADVAL_"+partid];
5069: var textbox = document.classgrade["TEXTVAL_"+partid];
5070: var selval = document.classgrade["SELVAL_"+partid];
1.42 ng 5071: for (var i=0; i<radioButton.length; i++) {
5072: radioButton[i].checked=false;
5073:
5074: }
5075: textbox.value = "";
5076: selval[0].selected = true;
5077:
5078: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 5079: var user = document.classgrade["ctr"+i].value;
1.289 albertel 5080: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 5081: var resetscore = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
5082: resetscore.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
5083: var resettries = document.classgrade["GD_"+user+"_"+partid+"_tries"];
5084: resettries.value = document.classgrade["GD_"+user+"_"+partid+"_tries_s"].value;
5085: var saveselval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
5086: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 5087: if (saveselval == "excused") {
1.43 ng 5088: if (selname[1].selected == false) { selname[1].selected = true;}
1.42 ng 5089: } else {
1.43 ng 5090: if (selname[0].selected == false) {selname[0].selected = true};
1.42 ng 5091: }
5092: }
1.41 ng 5093: }
1.42 ng 5094: }
5095:
1.41 ng 5096: VIEWJAVASCRIPT
1.42 ng 5097: }
5098:
1.44 ng 5099: #--- show scores for a section or whole class w/ option to change/update a score
1.42 ng 5100: sub viewgrades {
1.596.2.12.2. 1(raebur 5101:0): my ($request,$symb) = @_;
0.2.4(ra 5102:ul-23): my ($is_tool,$toolsymb);
5103:ul-23): if ($symb =~ /ext\.tool$/) {
5104:ul-23): $is_tool = 1;
5105:ul-23): $toolsymb = $symb;
5106:ul-23): }
1.42 ng 5107: &viewgrades_js($request);
1.41 ng 5108:
1.168 albertel 5109: #need to make sure we have the correct data for later EXT calls,
5110: #thus invalidate the cache
5111: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 5112: $env{'course.'.$env{'request.course.id'}.'.num'},
5113: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 5114: &Apache::lonnet::clear_EXT_cache_status();
5115:
1.398 albertel 5116: my $result='<h3><span class="LC_info">'.&mt('Manual Grading').'</span></h3>';
1.41 ng 5117:
5118: #view individual student submission form - called using Javascript viewOneStudent
1.324 albertel 5119: $result.=&jscriptNform($symb);
1.41 ng 5120:
1.44 ng 5121: #beginning of class grading form
1.442 banghart 5122: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.41 ng 5123: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1.418 albertel 5124: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.38 ng 5125: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.432 banghart 5126: &build_section_inputs().
1.442 banghart 5127: '<input type="hidden" name="Status" value="'.$env{'stu_status'}.'" />'."\n".
1.72 ng 5128:
1.596.2.12.2. 7(raebur 5129:6): #retrieve selected groups
5130:6): my (@groups,$group_display);
8(raebur 5131:6): @groups = &Apache::loncommon::get_env_multiple('form.group');
7(raebur 5132:6): if (grep(/^all$/,@groups)) {
5133:6): @groups = ('all');
5134:6): } elsif (grep(/^none$/,@groups)) {
5135:6): @groups = ('none');
5136:6): } elsif (@groups > 0) {
5137:6): $group_display = join(', ',@groups);
5138:6): }
5139:6):
5140:6): my ($common_header,$specific_header,@sections,$section_display);
6(raebur 5141:1): if ($env{'request.course.sec'} ne '') {
5142:1): @sections = ($env{'request.course.sec'});
5143:1): } else {
5144:1): @sections = &Apache::loncommon::get_env_multiple('form.section');
5145:1): }
5146:1):
5147:1): # Check if Save button should be usable
5148:1): my $disabled = ' disabled="disabled"';
5149:1): if ($perm{'mgr'}) {
5150:1): if (grep(/^all$/,@sections)) {
5151:1): undef($disabled);
5152:1): } else {
5153:1): foreach my $sec (@sections) {
5154:1): if (&canmodify($sec)) {
5155:1): undef($disabled);
5156:1): last;
5157:1): }
5158:1): }
5159:1): }
5160:1): }
7(raebur 5161:6): if (grep(/^all$/,@sections)) {
5162:6): @sections = ('all');
5163:6): if ($group_display) {
5164:6): $common_header = &mt('Assign Common Grade to Students in Group(s) [_1]',$group_display);
5165:6): $specific_header = &mt('Assign Grade to Specific Students in Group(s) [_1]',$group_display);
5166:6): } elsif (grep(/^none$/,@groups)) {
5167:6): $common_header = &mt('Assign Common Grade to Students not assigned to any groups');
5168:6): $specific_header = &mt('Assign Grade to Specific Students not assigned to any groups');
5169:6): } else {
5170:6): $common_header = &mt('Assign Common Grade to Class');
5171:6): $specific_header = &mt('Assign Grade to Specific Students in Class');
5172:6): }
5173:6): } elsif (grep(/^none$/,@sections)) {
5174:6): @sections = ('none');
5175:6): if ($group_display) {
5176:6): $common_header = &mt('Assign Common Grade to Students in no Section and in Group(s) [_1]',$group_display);
5177:6): $specific_header = &mt('Assign Grade to Specific Students in no Section and in Group(s)',$group_display);
5178:6): } elsif (grep(/^none$/,@groups)) {
5179:6): $common_header = &mt('Assign Common Grade to Students in no Section and in no Group');
5180:6): $specific_header = &mt('Assign Grade to Specific Students in no Section and in no Group');
5181:6): } else {
5182:6): $common_header = &mt('Assign Common Grade to Students in no Section');
5183:6): $specific_header = &mt('Assign Grade to Specific Students in no Section');
5184:6): }
5185:6): } else {
5186:6): $section_display = join (", ",@sections);
5187:6): if ($group_display) {
5188:6): $common_header = &mt('Assign Common Grade to Students in Section(s) [_1], and in Group(s) [_2]',
5189:6): $section_display,$group_display);
5190:6): $specific_header = &mt('Assign Grade to Specific Students in Section(s) [_1], and in Group(s) [_2]',
5191:6): $section_display,$group_display);
5192:6): } elsif (grep(/^none$/,@groups)) {
5193:6): $common_header = &mt('Assign Common Grade to Students in Section(s) [_1] and no Group',$section_display);
5194:6): $specific_header = &mt('Assign Grade to Specific Students in Section(s) [_1] and no Group',$section_display);
5195:6): } else {
5196:6): $common_header = &mt('Assign Common Grade to Students in Section(s) [_1]',$section_display);
5197:6): $specific_header = &mt('Assign Grade to Specific Students in Section(s) [_1]',$section_display);
5198:6): }
1.52 albertel 5199: }
1.596.2.12.2. 7(raebur 5200:6): my %submit_types = &substatus_options();
5201:6): my $submission_status = $submit_types{$env{'form.submitonly'}};
5202:6):
5203:6): if ($env{'form.submitonly'} eq 'all') {
5204:6): $result.= '<h3>'.$common_header.'</h3>';
5205:6): } else {
0.2.4(ra 5206:ul-23): my $text;
5207:ul-23): if ($is_tool) {
5208:ul-23): $text = &mt('(transaction status: "[_1]")',$submission_status);
5209:ul-23): } else {
5210:ul-23): $text = &mt('(submission status: "[_1]")',$submission_status);
5211:ul-23): }
5212:ul-23): $result.= '<h3>'.$common_header.' '.$text.'</h3>';
7(raebur 5213:6): }
5214:6): $result .= &Apache::loncommon::start_data_table();
1.44 ng 5215: #radio buttons/text box for assigning points for a section or class.
5216: #handles different parts of a problem
1.582 raeburn 5217: my $res_error;
5218: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
5219: if ($res_error) {
5220: return &navmap_errormsg();
5221: }
1.42 ng 5222: my %weight = ();
5223: my $ctsparts = 0;
1.45 ng 5224: my %seen = ();
1.596.2.12.2. 0.2.4(ra 5225:ul-23): my @part_response_id;
5226:ul-23): if ($is_tool) {
5227:ul-23): @part_response_id = ([0,'']);
5228:ul-23): } else {
5229:ul-23): @part_response_id = &flatten_responseType($responseType);
5230:ul-23): }
1.375 albertel 5231: foreach my $part_response_id (@part_response_id) {
5232: my ($partid,$respid) = @{ $part_response_id };
5233: my $part_resp = join('_',@{ $part_response_id });
1.45 ng 5234: next if $seen{$partid};
5235: $seen{$partid}++;
1.42 ng 5236: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
5237: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
5238:
1.324 albertel 5239: my $display_part=&get_display_part($partid,$symb);
1.485 albertel 5240: my $radio.='<table border="0"><tr>';
1.41 ng 5241: my $ctr = 0;
1.42 ng 5242: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
1.485 albertel 5243: $radio.= '<td><label><input type="radio" name="RADVAL_'.$partid.'" '.
1.54 albertel 5244: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.288 albertel 5245: ','.$ctr.')" />'.$ctr."</label></td>\n";
1.41 ng 5246: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
5247: $ctr++;
5248: }
1.485 albertel 5249: $radio.='</tr></table>';
5250: my $line = '<input type="text" name="TEXTVAL_'.
1.589 bisitz 5251: $partid.'" size="4" '.'onchange="javascript:writePoint(\''.
1.54 albertel 5252: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.539 riegler 5253: $weight{$partid}.' '.&mt('(problem weight)').'</td>'."\n";
1.596.2.12.2. 9(raebur 5254:3): $line.= '<td><b>'.&mt('Grade Status').':</b>'.
5255:3): '<select name="SELVAL_'.$partid.'" '.
5256:3): 'onchange="javascript:writeRadText(\''.$partid.'\','.
1.59 albertel 5257: $weight{$partid}.')"> '.
1.401 albertel 5258: '<option selected="selected"> </option>'.
1.485 albertel 5259: '<option value="excused">'.&mt('excused').'</option>'.
5260: '<option value="reset status">'.&mt('reset status').'</option>'.
5261: '</select></td>'.
5262: '<td><label><input type="checkbox" name="FORCE_'.$partid.'" />'.&mt('Override "Correct"').'</label>';
5263: $line.='<input type="hidden" name="partid_'.
5264: $ctsparts.'" value="'.$partid.'" />'."\n";
5265: $line.='<input type="hidden" name="weight_'.
5266: $partid.'" value="'.$weight{$partid}.'" />'."\n";
5267:
5268: $result.=
5269: &Apache::loncommon::start_data_table_row()."\n".
1.577 bisitz 5270: '<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 5271: &Apache::loncommon::end_data_table_row()."\n";
1.42 ng 5272: $ctsparts++;
1.41 ng 5273: }
1.474 albertel 5274: $result.=&Apache::loncommon::end_data_table()."\n".
1.52 albertel 5275: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.485 albertel 5276: $result.='<input type="button" value="'.&mt('Revert to Default').'" '.
1.589 bisitz 5277: 'onclick="javascript:resetEntry('.$ctsparts.');" />';
1.41 ng 5278:
1.44 ng 5279: #table listing all the students in a section/class
5280: #header of table
1.596.2.12.2. 0.2.4(ra 5281:ul-23): if ($env{'form.submitonly'} eq 'all') {
7(raebur 5282:6): $result.= '<h3>'.$specific_header.'</h3>';
5283:6): } else {
0.2.4(ra 5284:ul-23): my $text;
5285:ul-23): if ($is_tool) {
5286:ul-23): $text = &mt('(transaction status: "[_1]")',$submission_status);
5287:ul-23): } else {
5288:ul-23): $text = &mt('(submission status: "[_1]")',$submission_status);
5289:ul-23): }
5290:ul-23): $result.= '<h3>'.$specific_header.' '.$text.'</h3>';
7(raebur 5291:6): }
5292:6): $result.= &Apache::loncommon::start_data_table().
1.560 raeburn 5293: &Apache::loncommon::start_data_table_header_row().
5294: '<th>'.&mt('No.').'</th>'.
5295: '<th>'.&nameUserString('header')."</th>\n";
1.582 raeburn 5296: my $partserror;
5297: my (@parts) = sort(&getpartlist($symb,\$partserror));
5298: if ($partserror) {
5299: return &navmap_errormsg();
5300: }
1.324 albertel 5301: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.269 raeburn 5302: my @partids = ();
1.41 ng 5303: foreach my $part (@parts) {
1.596.2.12.2. 0.2.4(ra 5304:ul-23): my $display=&Apache::lonnet::metadata($url,$part.'.display',$toolsymb);
1.539 riegler 5305: my $narrowtext = &mt('Tries');
5306: $display =~ s|^Number of Attempts|$narrowtext <br />|; # makes the column narrower
1.596.2.12.2. 0.2.4(ra 5307:ul-23): if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name',$toolsymb); }
1.207 albertel 5308: my ($partid) = &split_part_type($part);
1.524 raeburn 5309: push(@partids,$partid);
1.596.2.12.2. 1(raebur 5310:0): #
5311:0): # FIXME: Looks like $display looks at English text
5312:0): #
1.324 albertel 5313: my $display_part=&get_display_part($partid,$symb);
1.41 ng 5314: if ($display =~ /^Partial Credit Factor/) {
1.485 albertel 5315: $result.='<th>'.
1.596.2.12.2. 8(raebur 5316:3): &mt('Score Part: [_1][_2](weight = [_3])',
5317:3): $display_part,'<br />',$weight{$partid}).'</th>'."\n";
1.41 ng 5318: next;
1.485 albertel 5319:
1.207 albertel 5320: } else {
1.485 albertel 5321: if ($display =~ /Problem Status/) {
5322: my $grade_status_mt = &mt('Grade Status');
5323: $display =~ s{Problem Status}{$grade_status_mt<br />};
5324: }
5325: my $part_mt = &mt('Part:');
5326: $display =~s{\[Part: \Q$partid\E\]}{$part_mt $display_part};
1.41 ng 5327: }
1.485 albertel 5328:
1.474 albertel 5329: $result.='<th>'.$display.'</th>'."\n";
1.41 ng 5330: }
1.474 albertel 5331: $result.=&Apache::loncommon::end_data_table_header_row();
1.44 ng 5332:
1.270 albertel 5333: my %last_resets =
5334: &get_last_resets($symb,$env{'request.course.id'},\@partids);
1.269 raeburn 5335:
1.41 ng 5336: #get info for each student
1.44 ng 5337: #list all the students - with points and grade status
1.596.2.12.2. 7(raebur 5338:6): my (undef,undef,$fullname) = &getclasslist(\@sections,'1',\@groups);
1.41 ng 5339: my $ctr = 0;
1.294 albertel 5340: foreach (sort
5341: {
5342: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
5343: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
5344: }
5345: return $a cmp $b;
5346: } (keys(%$fullname))) {
1.324 albertel 5347: $result.=&viewstudentgrade($symb,$env{'request.course.id'},
1.596.2.12.2. 0.2.4(ra 5348:ul-23): $_,$$fullname{$_},\@parts,\%weight,\$ctr,\%last_resets,$is_tool);
1.41 ng 5349: }
1.474 albertel 5350: $result.=&Apache::loncommon::end_data_table();
1.41 ng 5351: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.596.2.12.2. 6(raebur 5352:1): $result.='<input type="button" value="'.&mt('Save').'"'.$disabled.' '.
1.589 bisitz 5353: 'onclick="javascript:submit();" target="_self" /></form>'."\n";
1.596.2.12.2. 7(raebur 5354:6): if ($ctr == 0) {
1.442 banghart 5355: my $stu_status = join(' or ',&Apache::loncommon::get_env_multiple('form.Status'));
1.596.2.12.2. 7(raebur 5356:6): $result='<h3><span class="LC_info">'.&mt('Manual Grading').'</span></h3>'.
5357:6): '<span class="LC_warning">';
5358:6): if ($env{'form.submitonly'} eq 'all') {
5359:6): if (grep(/^all$/,@sections)) {
5360:6): if (grep(/^all$/,@groups)) {
5361:6): $result .= &mt('There are no students with enrollment status [_1] to modify or grade.',
5362:6): $stu_status);
5363:6): } elsif (grep(/^none$/,@groups)) {
5364:6): $result .= &mt('There are no students with no group assigned and with enrollment status [_1] to modify or grade.',
5365:6): $stu_status);
5366:6): } else {
5367:6): $result .= &mt('There are no students in group(s) [_1] with enrollment status [_2] to modify or grade.',
5368:6): $group_display,$stu_status);
5369:6): }
5370:6): } elsif (grep(/^none$/,@sections)) {
5371:6): if (grep(/^all$/,@groups)) {
5372:6): $result .= &mt('There are no students in no section with enrollment status [_1] to modify or grade.',
5373:6): $stu_status);
5374:6): } elsif (grep(/^none$/,@groups)) {
5375:6): $result .= &mt('There are no students in no section and no group with enrollment status [_1] to modify or grade.',
5376:6): $stu_status);
5377:6): } else {
5378:6): $result .= &mt('There are no students in no section in group(s) [_1] with enrollment status [_2] to modify or grade.',
5379:6): $group_display,$stu_status);
5380:6): }
5381:6): } else {
5382:6): if (grep(/^all$/,@groups)) {
5383:6): $result .= &mt('There are no students in section(s) [_1] with enrollment status [_2] to modify or grade.',
5384:6): $section_display,$stu_status);
5385:6): } elsif (grep(/^none$/,@groups)) {
9(raebur 5386:7): $result .= &mt('There are no students in section(s) [_1] and no group with enrollment status [_2] to modify or grade.',
7(raebur 5387:6): $section_display,$stu_status);
5388:6): } else {
5389:6): $result .= &mt('There are no students in section(s) [_1] and group(s) [_2] with enrollment status [_3] to modify or grade.',
5390:6): $section_display,$group_display,$stu_status);
5391:6): }
5392:6): }
5393:6): } else {
5394:6): if (grep(/^all$/,@sections)) {
5395:6): if (grep(/^all$/,@groups)) {
5396:6): $result .= &mt('There are no students with enrollment status [_1] and submission status "[_2]" to modify or grade.',
5397:6): $stu_status,$submission_status);
5398:6): } elsif (grep(/^none$/,@groups)) {
5399:6): $result .= &mt('There are no students with no group assigned with enrollment status [_1] and submission status "[_2]" to modify or grade.',
5400:6): $stu_status,$submission_status);
5401:6): } else {
5402:6): $result .= &mt('There are no students in group(s) [_1] with enrollment status [_2] and submission status "[_3]" to modify or grade.',
5403:6): $group_display,$stu_status,$submission_status);
5404:6): }
5405:6): } elsif (grep(/^none$/,@sections)) {
5406:6): if (grep(/^all$/,@groups)) {
5407:6): $result .= &mt('There are no students in no section with enrollment status [_1] and submission status "[_2]" to modify or grade.',
5408:6): $stu_status,$submission_status);
5409:6): } elsif (grep(/^none$/,@groups)) {
5410:6): $result .= &mt('There are no students in no section and no group with enrollment status [_1] and submission status "[_2]" to modify or grade.',
5411:6): $stu_status,$submission_status);
5412:6): } else {
5413:6): $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.',
5414:6): $group_display,$stu_status,$submission_status);
5415:6): }
5416:6): } else {
5417:6): if (grep(/^all$/,@groups)) {
5418:6): $result .= &mt('There are no students in section(s) [_1] with enrollment status [_2] and submission status "[_3]" to modify or grade.',
5419:6): $section_display,$stu_status,$submission_status);
5420:6): } elsif (grep(/^none$/,@groups)) {
5421:6): $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.',
5422:6): $section_display,$stu_status,$submission_status);
5423:6): } else {
5424:6): $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.',
5425:6): $section_display,$group_display,$stu_status,$submission_status);
5426:6): }
5427:6): }
5428:6): }
5429:6): $result .= '</span><br />';
1.96 albertel 5430: }
1.41 ng 5431: return $result;
5432: }
5433:
1.596.2.12.2. 7(raebur 5434:6): #--- call by previous routine to display each student who satisfies submission filter.
1.41 ng 5435: sub viewstudentgrade {
1.596.2.12.2. 0.2.4(ra 5436:ul-23): my ($symb,$courseid,$student,$fullname,$parts,$weight,$ctr,$last_resets,$is_tool) = @_;
1.44 ng 5437: my ($uname,$udom) = split(/:/,$student);
5438: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.596.2.12.2. 7(raebur 5439:6): my $submitonly = $env{'form.submitonly'};
5440:6): unless (($submitonly eq 'all') || ($submitonly eq 'queued')) {
5441:6): my %partstatus = ();
5442:6): if (ref($parts) eq 'ARRAY') {
5443:6): foreach my $apart (@{$parts}) {
5444:6): my ($part,$type) = &split_part_type($apart);
5445:6): my ($status,undef) = split(/_/,$record{"resource.$part.solved"},2);
5446:6): $status = 'nothing' if ($status eq '');
5447:6): $partstatus{$part} = $status;
5448:6): my $subkey = "resource.$part.submitted_by";
5449:6): $partstatus{$subkey} = $record{$subkey} if ($record{$subkey} ne '');
5450:6): }
5451:6): my $submitted = 0;
5452:6): my $graded = 0;
5453:6): my $incorrect = 0;
5454:6): foreach my $key (keys(%partstatus)) {
5455:6): $submitted = 1 if ($partstatus{$key} ne 'nothing');
5456:6): $graded = 1 if ($partstatus{$key} =~ /^ungraded/);
5457:6): $incorrect = 1 if ($partstatus{$key} =~ /^incorrect/);
5458:6):
5459:6): my $partid = (split(/\./,$key))[1];
5460:6): if ($partstatus{'resource.'.$partid.'.'.$key.'.submitted_by'} ne '') {
5461:6): $submitted = 0;
5462:6): }
5463:6): }
5464:6): return if (!$submitted && ($submitonly eq 'yes' ||
5465:6): $submitonly eq 'incorrect' ||
5466:6): $submitonly eq 'graded'));
5467:6): return if (!$graded && ($submitonly eq 'graded'));
5468:6): return if (!$incorrect && $submitonly eq 'incorrect');
5469:6): }
5470:6): }
5471:6): if ($submitonly eq 'queued') {
5472:6): my ($cdom,$cnum) = split(/_/,$courseid);
5473:6): my %queue_status =
5474:6): &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
5475:6): $udom,$uname);
5476:6): return if (!defined($queue_status{'gradingqueue'}));
5477:6): }
5478:6): $$ctr++;
5479:6): my %aggregates = ();
1.474 albertel 5480: my $result=&Apache::loncommon::start_data_table_row().'<td align="right">'.
1.596.2.12.2. 7(raebur 5481:6): '<input type="hidden" name="ctr'.($$ctr-1).'" value="'.$student.'" />'.
5482:6): "\n".$$ctr.' </td><td> '.
1.44 ng 5483: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 5484: '\');" target="_self">'.$fullname.'</a> '.
1.398 albertel 5485: '<span class="LC_internal_info">('.$uname.($env{'user.domain'} eq $udom ? '' : ':'.$udom).')</span></td>'."\n";
1.281 albertel 5486: $student=~s/:/_/; # colon doen't work in javascript for names
1.63 albertel 5487: foreach my $apart (@$parts) {
5488: my ($part,$type) = &split_part_type($apart);
1.41 ng 5489: my $score=$record{"resource.$part.$type"};
1.276 albertel 5490: $result.='<td align="center">';
1.269 raeburn 5491: my ($aggtries,$totaltries);
5492: unless (exists($aggregates{$part})) {
1.270 albertel 5493: $totaltries = $record{'resource.'.$part.'.tries'};
5494: $aggtries = $totaltries;
1.269 raeburn 5495: if ($$last_resets{$part}) {
1.270 albertel 5496: $aggtries = &get_num_tries(\%record,$$last_resets{$part},
5497: $part);
5498: }
1.269 raeburn 5499: $result.='<input type="hidden" name="'.
5500: 'GD_'.$student.'_'.$part.'_aggtries" value="'.$aggtries.'" />'."\n";
5501: $result.='<input type="hidden" name="'.
5502: 'GD_'.$student.'_'.$part.'_totaltries" value="'.$totaltries.'" />'."\n";
5503: $aggregates{$part} = 1;
5504: }
1.41 ng 5505: if ($type eq 'awarded') {
1.320 albertel 5506: my $pts = $score eq '' ? '' : &compute_points($score,$$weight{$part});
1.42 ng 5507: $result.='<input type="hidden" name="'.
1.89 albertel 5508: 'GD_'.$student.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.233 albertel 5509: $result.='<input type="text" name="'.
1.89 albertel 5510: 'GD_'.$student.'_'.$part.'_awarded" '.
1.589 bisitz 5511: 'onchange="javascript:changeSelect(\''.$part.'\',\''.$student.
1.44 ng 5512: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41 ng 5513: } elsif ($type eq 'solved') {
5514: my ($status,$foo)=split(/_/,$score,2);
5515: $status = 'nothing' if ($status eq '');
1.89 albertel 5516: $result.='<input type="hidden" name="'.'GD_'.$student.'_'.
1.54 albertel 5517: $part.'_solved_s" value="'.$status.'" />'."\n";
1.233 albertel 5518: $result.=' <select name="'.
1.89 albertel 5519: 'GD_'.$student.'_'.$part.'_solved" '.
1.589 bisitz 5520: 'onchange="javascript:changeOneScore(\''.$part.'\',\''.$student.'\')" >'."\n";
1.485 albertel 5521: $result.= (($status eq 'excused') ? '<option> </option><option selected="selected" value="excused">'.&mt('excused').'</option>'
5522: : '<option selected="selected"> </option><option value="excused">'.&mt('excused').'</option>')."\n";
5523: $result.='<option value="reset status">'.&mt('reset status').'</option>';
1.126 ng 5524: $result.="</select> </td>\n";
1.122 ng 5525: } else {
5526: $result.='<input type="hidden" name="'.
5527: 'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
5528: "\n";
1.233 albertel 5529: $result.='<input type="text" name="'.
1.122 ng 5530: 'GD_'.$student.'_'.$part.'_'.$type.'" '.
5531: 'value="'.$score.'" size="4" /></td>'."\n";
1.41 ng 5532: }
5533: }
1.474 albertel 5534: $result.=&Apache::loncommon::end_data_table_row();
1.41 ng 5535: return $result;
1.38 ng 5536: }
5537:
1.44 ng 5538: #--- change scores for all the students in a section/class
5539: # record does not get update if unchanged
1.38 ng 5540: sub editgrades {
1.596.2.12.2. 1(raebur 5541:0): my ($request,$symb) = @_;
0.2.4(ra 5542:ul-23): my $toolsymb;
5543:ul-23): if ($symb =~ /ext\.tool$/) {
5544:ul-23): $toolsymb = $symb;
5545:ul-23): }
1.41 ng 5546:
1.433 banghart 5547: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.477 albertel 5548: my $title='<h2>'.&mt('Current Grade Status').'</h2>';
1.596.2.12.2. 9(raebur 5549:3): $title.='<h4><b>'.&mt('Section:').'</b> '.$section_display.'</h4>'."\n";
1.126 ng 5550:
1.477 albertel 5551: my $result= &Apache::loncommon::start_data_table().
5552: &Apache::loncommon::start_data_table_header_row().
5553: '<th rowspan="2" valign="middle">'.&mt('No.').'</th>'.
5554: '<th rowspan="2" valign="middle">'.&nameUserString('header')."</th>\n";
1.43 ng 5555: my %scoreptr = (
5556: 'correct' =>'correct_by_override',
5557: 'incorrect'=>'incorrect_by_override',
5558: 'excused' =>'excused',
5559: 'ungraded' =>'ungraded_attempted',
1.596 raeburn 5560: 'credited' =>'credit_attempted',
1.43 ng 5561: 'nothing' => '',
5562: );
1.257 albertel 5563: my ($classlist,undef,$fullname) = &getclasslist($env{'form.section'},'0');
1.34 ng 5564:
1.596.2.12.2. 0.2.7(ra 5565:an-25): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5566:an-25): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5567:an-25): my %needpb = &passbacks_for_symb($cdom,$cnum,$symb);
5568:an-25):
1.44 ng 5569: my (@partid);
5570: my %weight = ();
1.54 albertel 5571: my %columns = ();
1.44 ng 5572: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54 albertel 5573:
1.582 raeburn 5574: my $partserror;
5575: my (@parts) = sort(&getpartlist($symb,\$partserror));
5576: if ($partserror) {
5577: return &navmap_errormsg();
5578: }
1.54 albertel 5579: my $header;
1.257 albertel 5580: while ($ctr < $env{'form.totalparts'}) {
5581: my $partid = $env{'form.partid_'.$ctr};
1.524 raeburn 5582: push(@partid,$partid);
1.257 albertel 5583: $weight{$partid} = $env{'form.weight_'.$partid};
1.44 ng 5584: $ctr++;
1.54 albertel 5585: }
1.324 albertel 5586: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.596.2.12.2. 2(raebur 5587:8): my $totcolspan = 0;
1.54 albertel 5588: foreach my $partid (@partid) {
1.478 albertel 5589: $header .= '<th align="center">'.&mt('Old Score').'</th>'.
5590: '<th align="center">'.&mt('New Score').'</th>';
1.54 albertel 5591: $columns{$partid}=2;
5592: foreach my $stores (@parts) {
5593: my ($part,$type) = &split_part_type($stores);
5594: if ($part !~ m/^\Q$partid\E/) { next;}
5595: if ($type eq 'awarded' || $type eq 'solved') { next; }
1.596.2.12.2. 0.2.4(ra 5596:ul-23): my $display=&Apache::lonnet::metadata($url,$stores.'.display',$toolsymb);
1.551 raeburn 5597: $display =~ s/\[Part: \Q$part\E\]//;
1.539 riegler 5598: my $narrowtext = &mt('Tries');
5599: $display =~ s/Number of Attempts/$narrowtext/;
5600: $header .= '<th align="center">'.&mt('Old').' '.$display.'</th>'.
5601: '<th align="center">'.&mt('New').' '.$display.'</th>';
1.54 albertel 5602: $columns{$partid}+=2;
5603: }
1.596.2.12.2. 2(raebur 5604:8): $totcolspan += $columns{$partid};
1.54 albertel 5605: }
5606: foreach my $partid (@partid) {
1.324 albertel 5607: my $display_part=&get_display_part($partid,$symb);
1.478 albertel 5608: $result .= '<th colspan="'.$columns{$partid}.'" align="center">'.
5609: &mt('Part: [_1] (Weight = [_2])',$display_part,$weight{$partid}).
5610: '</th>';
1.54 albertel 5611:
1.44 ng 5612: }
1.477 albertel 5613: $result .= &Apache::loncommon::end_data_table_header_row().
5614: &Apache::loncommon::start_data_table_header_row().
5615: $header.
5616: &Apache::loncommon::end_data_table_header_row();
5617: my @noupdate;
1.126 ng 5618: my ($updateCtr,$noupdateCtr) = (1,1);
1.596.2.12.2. 0.2.7(ra 5619:an-25): my ($got_types,%queueable,%pbsave,%skip_passback);
1.257 albertel 5620: for ($i=0; $i<$env{'form.total'}; $i++) {
5621: my $user = $env{'form.ctr'.$i};
1.281 albertel 5622: my ($uname,$udom)=split(/:/,$user);
1.44 ng 5623: my %newrecord;
5624: my $updateflag = 0;
1.596.2.12.2. 2(raebur 5625:8): my $usec=$classlist->{"$uname:$udom"}[5];
5626:8): my $canmodify = &canmodify($usec);
5627:8): my $line = '<td'.($canmodify?'':' colspan="2"').'>'.
5628:8): &nameUserString(undef,$$fullname{$user},$uname,$udom).'</td>';
5629:8): if (!$canmodify) {
5630:8): push(@noupdate,
5631:8): $line."<td colspan=\"$totcolspan\"><span class=\"LC_warning\">".
5632:8): &mt('Not allowed to modify student')."</span></td>");
5633:8): next;
5634:8): }
1.269 raeburn 5635: my %aggregate = ();
5636: my $aggregateflag = 0;
1.281 albertel 5637: $user=~s/:/_/; # colon doen't work in javascript for names
1.596.2.12.2. 0.2.7(ra 5638:an-25): my (%weights,%awardeds,%excuseds);
1.44 ng 5639: foreach (@partid) {
1.257 albertel 5640: my $old_aw = $env{'form.GD_'.$user.'_'.$_.'_awarded_s'};
1.54 albertel 5641: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
5642: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
1.257 albertel 5643: my $old_score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
5644: my $awarded = $env{'form.GD_'.$user.'_'.$_.'_awarded'};
1.54 albertel 5645: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
5646: my $partial = $awarded eq '' ? '' : $pcr;
1.596.2.12.2. 0.2.7(ra 5647:an-25): $awardeds{$symb}{$_} = $partial;
1.44 ng 5648: my $score;
5649: if ($partial eq '') {
1.257 albertel 5650: $score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 5651: } elsif ($partial > 0) {
5652: $score = 'correct_by_override';
5653: } elsif ($partial == 0) {
5654: $score = 'incorrect_by_override';
5655: }
1.257 albertel 5656: my $dropMenu = $env{'form.GD_'.$user.'_'.$_.'_solved'};
1.125 ng 5657: $score = 'excused' if (($dropMenu eq 'excused') && ($score ne 'excused'));
5658:
1.292 albertel 5659: $newrecord{'resource.'.$_.'.regrader'}=
5660: "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 5661: if ($dropMenu eq 'reset status' &&
5662: $old_score ne '') { # ignore if no previous attempts => nothing to reset
1.299 albertel 5663: $newrecord{'resource.'.$_.'.tries'} = '';
1.125 ng 5664: $newrecord{'resource.'.$_.'.solved'} = '';
5665: $newrecord{'resource.'.$_.'.award'} = '';
1.299 albertel 5666: $newrecord{'resource.'.$_.'.awarded'} = '';
1.125 ng 5667: $updateflag = 1;
1.269 raeburn 5668: if ($env{'form.GD_'.$user.'_'.$_.'_aggtries'} > 0) {
5669: my $aggtries = $env{'form.GD_'.$user.'_'.$_.'_aggtries'};
5670: my $totaltries = $env{'form.GD_'.$user.'_'.$_.'_totaltries'};
5671: my $solvedstatus = $env{'form.GD_'.$user.'_'.$_.'_solved_s'};
5672: &decrement_aggs($symb,$_,\%aggregate,$aggtries,$totaltries,$solvedstatus);
5673: $aggregateflag = 1;
5674: }
1.139 albertel 5675: } elsif (!($old_part eq $partial && $old_score eq $score)) {
5676: $updateflag = 1;
5677: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
5678: $newrecord{'resource.'.$_.'.solved'} = $score;
5679: $rec_update++;
1.125 ng 5680: }
5681:
1.93 albertel 5682: $line .= '<td align="center">'.$old_aw.' </td>'.
1.44 ng 5683: '<td align="center">'.$awarded.
5684: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 5685:
1.54 albertel 5686:
5687: my $partid=$_;
1.596.2.12.2. 0.2.7(ra 5688:an-25): if ($score eq 'excused') {
5689:an-25): $excuseds{$symb}{$partid} = 1;
5690:an-25): } else {
5691:an-25): $excuseds{$symb}{$partid} = '';
5692:an-25): }
1.54 albertel 5693: foreach my $stores (@parts) {
5694: my ($part,$type) = &split_part_type($stores);
5695: if ($part !~ m/^\Q$partid\E/) { next;}
5696: if ($type eq 'awarded' || $type eq 'solved') { next; }
1.257 albertel 5697: my $old_aw = $env{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
5698: my $awarded = $env{'form.GD_'.$user.'_'.$part.'_'.$type};
1.54 albertel 5699: if ($awarded ne '' && $awarded ne $old_aw) {
5700: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.257 albertel 5701: $newrecord{'resource.'.$part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.54 albertel 5702: $updateflag=1;
5703: }
1.93 albertel 5704: $line .= '<td align="center">'.$old_aw.' </td>'.
1.54 albertel 5705: '<td align="center">'.$awarded.' </td>';
5706: }
1.44 ng 5707: }
1.477 albertel 5708: $line.="\n";
1.301 albertel 5709:
1.44 ng 5710: if ($updateflag) {
5711: $count++;
1.257 albertel 5712: &Apache::lonnet::cstore(\%newrecord,$symb,$env{'request.course.id'},
1.89 albertel 5713: $udom,$uname);
1.301 albertel 5714:
5715: if (&Apache::bridgetask::in_queue('gradingqueue',$symb,$cdom,
5716: $cnum,$udom,$uname)) {
5717: # need to figure out if should be in queue.
5718: my %record =
5719: &Apache::lonnet::restore($symb,$env{'request.course.id'},
5720: $udom,$uname);
5721: my $all_graded = 1;
5722: my $none_graded = 1;
1.596.2.12.2. 8(raebur 5723:1): unless ($got_types) {
5724:1): my $error;
5725:1): my ($plist,$handgrd,$resptype) = &response_type($symb,\$error);
5726:1): unless ($error) {
5727:1): foreach my $part (@parts) {
5728:1): if (ref($resptype->{$part}) eq 'HASH') {
5729:1): foreach my $id (keys(%{$resptype->{$part}})) {
5730:1): if (($resptype->{$part}->{$id} eq 'essay') ||
5731:1): (lc($handgrd->{$part.'_'.$id}) eq 'yes')) {
5732:1): $queueable{$part} = 1;
5733:1): last;
5734:1): }
5735:1): }
5736:1): }
5737:1): }
5738:1): }
5739:1): $got_types = 1;
5740:1): }
1.301 albertel 5741: foreach my $part (@parts) {
1.596.2.12.2. 8(raebur 5742:1): if ($queueable{$part}) {
5743:1): if ( $record{'resource.'.$part.'.awarded'} eq '' ) {
5744:1): $all_graded = 0;
5745:1): } else {
5746:1): $none_graded = 0;
5747:1): }
5748:1): }
1.301 albertel 5749: }
5750:
5751: if ($all_graded || $none_graded) {
5752: &Apache::bridgetask::remove_from_queue('gradingqueue',
5753: $symb,$cdom,$cnum,
5754: $udom,$uname);
5755: }
5756: }
5757:
1.477 albertel 5758: $result.=&Apache::loncommon::start_data_table_row().
5759: '<td align="right"> '.$updateCtr.' </td>'.$line.
5760: &Apache::loncommon::end_data_table_row();
1.126 ng 5761: $updateCtr++;
1.596.2.12.2. 0.2.7(ra 5762:an-25): if (keys(%needpb)) {
5763:an-25): $weights{$symb} = \%weight;
5764:an-25): &process_passbacks('editgrades',[$symb],$cdom,$cnum,$udom,$uname,$usec,\%weights,
5765:an-25): \%awardeds,\%excuseds,\%needpb,\%skip_passback,\%pbsave);
5766:an-25): }
1.93 albertel 5767: } else {
1.477 albertel 5768: push(@noupdate,
5769: '<td align="right"> '.$noupdateCtr.' </td>'.$line);
1.126 ng 5770: $noupdateCtr++;
1.44 ng 5771: }
1.269 raeburn 5772: if ($aggregateflag) {
5773: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 5774: $cdom,$cnum);
1.269 raeburn 5775: }
1.93 albertel 5776: }
1.477 albertel 5777: if (@noupdate) {
1.596.2.12.2. 2(raebur 5778:8): my $numcols=$totcolspan+2;
1.477 albertel 5779: $result .= &Apache::loncommon::start_data_table_row('LC_empty_row').
1.478 albertel 5780: '<td align="center" colspan="'.$numcols.'">'.
5781: &mt('No Changes Occurred For the Students Below').
5782: '</td>'.
1.477 albertel 5783: &Apache::loncommon::end_data_table_row();
5784: foreach my $line (@noupdate) {
5785: $result.=
5786: &Apache::loncommon::start_data_table_row().
5787: $line.
5788: &Apache::loncommon::end_data_table_row();
5789: }
1.44 ng 5790: }
1.596.2.12.2. 1(raebur 5791:0): $result .= &Apache::loncommon::end_data_table();
1.478 albertel 5792: my $msg = '<p><b>'.
5793: &mt('Number of records updated = [_1] for [quant,_2,student].',
5794: $rec_update,$count).'</b><br />'.
5795: '<b>'.&mt('Total number of students = [_1]',$env{'form.total'}).
5796: '</b></p>';
1.44 ng 5797: return $title.$msg.$result;
1.5 albertel 5798: }
1.54 albertel 5799:
5800: sub split_part_type {
5801: my ($partstr) = @_;
5802: my ($temp,@allparts)=split(/_/,$partstr);
5803: my $type=pop(@allparts);
1.439 albertel 5804: my $part=join('_',@allparts);
1.54 albertel 5805: return ($part,$type);
5806: }
5807:
1.44 ng 5808: #------------- end of section for handling grading by section/class ---------
5809: #
5810: #----------------------------------------------------------------------------
5811:
1.5 albertel 5812:
1.44 ng 5813: #----------------------------------------------------------------------------
5814: #
5815: #-------------------------- Next few routines handles grading by csv upload
5816: #
5817: #--- Javascript to handle csv upload
1.27 albertel 5818: sub csvupload_javascript_reverse_associate {
1.573 bisitz 5819: my $error1=&mt('You need to specify the username or the student/employee ID');
1.246 albertel 5820: my $error2=&mt('You need to specify at least one grading field');
1.596.2.12.2. 6(raebur 5821:6): &js_escape(\$error1);
5822:6): &js_escape(\$error2);
1.27 albertel 5823: return(<<ENDPICK);
5824: function verify(vf) {
5825: var foundsomething=0;
5826: var founduname=0;
1.243 albertel 5827: var foundID=0;
1.27 albertel 5828: for (i=0;i<=vf.nfields.value;i++) {
5829: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 5830: if (i==0 && tw!=0) { foundID=1; }
5831: if (i==1 && tw!=0) { founduname=1; }
5832: if (i!=0 && i!=1 && i!=2 && tw!=0) { foundsomething=1; }
1.27 albertel 5833: }
1.246 albertel 5834: if (founduname==0 && foundID==0) {
5835: alert('$error1');
5836: return;
1.27 albertel 5837: }
5838: if (foundsomething==0) {
1.246 albertel 5839: alert('$error2');
5840: return;
1.27 albertel 5841: }
5842: vf.submit();
5843: }
5844: function flip(vf,tf) {
5845: var nw=eval('vf.f'+tf+'.selectedIndex');
5846: var i;
5847: for (i=0;i<=vf.nfields.value;i++) {
5848: //can not pick the same destination field for both name and domain
5849: if (((i ==0)||(i ==1)) &&
5850: ((tf==0)||(tf==1)) &&
5851: (i!=tf) &&
5852: (eval('vf.f'+i+'.selectedIndex')==nw)) {
5853: eval('vf.f'+i+'.selectedIndex=0;')
5854: }
5855: }
5856: }
5857: ENDPICK
5858: }
5859:
5860: sub csvupload_javascript_forward_associate {
1.573 bisitz 5861: my $error1=&mt('You need to specify the username or the student/employee ID');
1.246 albertel 5862: my $error2=&mt('You need to specify at least one grading field');
1.596.2.12.2. 6(raebur 5863:6): &js_escape(\$error1);
5864:6): &js_escape(\$error2);
1.27 albertel 5865: return(<<ENDPICK);
5866: function verify(vf) {
5867: var foundsomething=0;
5868: var founduname=0;
1.243 albertel 5869: var foundID=0;
1.27 albertel 5870: for (i=0;i<=vf.nfields.value;i++) {
5871: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 5872: if (tw==1) { foundID=1; }
5873: if (tw==2) { founduname=1; }
5874: if (tw>3) { foundsomething=1; }
1.27 albertel 5875: }
1.246 albertel 5876: if (founduname==0 && foundID==0) {
5877: alert('$error1');
5878: return;
1.27 albertel 5879: }
5880: if (foundsomething==0) {
1.246 albertel 5881: alert('$error2');
5882: return;
1.27 albertel 5883: }
5884: vf.submit();
5885: }
5886: function flip(vf,tf) {
5887: var nw=eval('vf.f'+tf+'.selectedIndex');
5888: var i;
5889: //can not pick the same destination field twice
5890: for (i=0;i<=vf.nfields.value;i++) {
5891: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
5892: eval('vf.f'+i+'.selectedIndex=0;')
5893: }
5894: }
5895: }
5896: ENDPICK
5897: }
5898:
1.26 albertel 5899: sub csvuploadmap_header {
1.324 albertel 5900: my ($request,$symb,$datatoken,$distotal)= @_;
1.41 ng 5901: my $javascript;
1.257 albertel 5902: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 5903: $javascript=&csvupload_javascript_reverse_associate();
5904: } else {
5905: $javascript=&csvupload_javascript_forward_associate();
5906: }
1.45 ng 5907:
1.257 albertel 5908: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1.245 albertel 5909: my $ignore=&mt('Ignore First Line');
1.418 albertel 5910: $symb = &Apache::lonenc::check_encrypt($symb);
1.596.2.12.2. 1(raebur 5911:0): $request->print('<form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">'.
5912:0): &mt('Total number of records found in file: [_1]',$distotal).'<hr />'.
5913:0): &mt('Associate entries from the uploaded file with as many fields as you can.'));
5914:0): my $reverse=&mt("Reverse Association");
1.41 ng 5915: $request->print(<<ENDPICK);
1.596.2.12.2. 1(raebur 5916:0): <br />
5917:0): <input type="button" value="$reverse" onclick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1.245 albertel 5918: <label><input type="checkbox" name="noFirstLine" $checked />$ignore</label>
1.26 albertel 5919: <input type="hidden" name="associate" value="" />
5920: <input type="hidden" name="phase" value="three" />
5921: <input type="hidden" name="datatoken" value="$datatoken" />
1.257 albertel 5922: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
5923: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
1.26 albertel 5924: <input type="hidden" name="upfile_associate"
1.257 albertel 5925: value="$env{'form.upfile_associate'}" />
1.26 albertel 5926: <input type="hidden" name="symb" value="$symb" />
1.246 albertel 5927: <input type="hidden" name="command" value="csvuploadoptions" />
1.26 albertel 5928: <hr />
5929: ENDPICK
1.596.2.12.2. 1(raebur 5930:0): $request->print(&Apache::lonhtmlcommon::scripttag($javascript));
1.118 ng 5931: return '';
1.26 albertel 5932:
5933: }
5934:
5935: sub csvupload_fields {
1.582 raeburn 5936: my ($symb,$errorref) = @_;
1.596.2.12.2. 0.2.4(ra 5937:ul-23): my $toolsymb;
5938:ul-23): if ($symb =~ /ext\.tool$/) {
5939:ul-23): $toolsymb = $symb;
5940:ul-23): }
1.582 raeburn 5941: my (@parts) = &getpartlist($symb,$errorref);
5942: if (ref($errorref)) {
5943: if ($$errorref) {
5944: return;
5945: }
5946: }
5947:
1.556 weissno 5948: my @fields=(['ID','Student/Employee ID'],
1.243 albertel 5949: ['username','Student Username'],
5950: ['domain','Student Domain']);
1.324 albertel 5951: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.41 ng 5952: foreach my $part (sort(@parts)) {
5953: my @datum;
1.596.2.12.2. 0.2.4(ra 5954:ul-23): my $display=&Apache::lonnet::metadata($url,$part.'.display',$toolsymb);
1.41 ng 5955: my $name=$part;
5956: if (!$display) { $display = $name; }
5957: @datum=($name,$display);
1.244 albertel 5958: if ($name=~/^stores_(.*)_awarded/) {
5959: push(@fields,['stores_'.$1.'_points',"Points [Part: $1]"]);
5960: }
1.41 ng 5961: push(@fields,\@datum);
5962: }
5963: return (@fields);
1.26 albertel 5964: }
5965:
5966: sub csvuploadmap_footer {
1.41 ng 5967: my ($request,$i,$keyfields) =@_;
1.596.2.12.2. 0(raebur 5968:3): my $buttontext = &mt('Assign Grades');
1.41 ng 5969: $request->print(<<ENDPICK);
1.26 albertel 5970: </table>
5971: <input type="hidden" name="nfields" value="$i" />
5972: <input type="hidden" name="keyfields" value="$keyfields" />
1.596.2.12.2. 0(raebur 5973:3): <input type="button" onclick="javascript:verify(this.form)" value="$buttontext" /><br />
1.26 albertel 5974: </form>
5975: ENDPICK
5976: }
5977:
1.283 albertel 5978: sub checkforfile_js {
1.539 riegler 5979: my $alertmsg = &mt('Please use the browse button to select a file from your local directory.');
1.596.2.12.2. 6(raebur 5980:6): &js_escape(\$alertmsg);
1(raebur 5981:0): my $result = &Apache::lonhtmlcommon::scripttag(<<CSVFORMJS);
1.86 ng 5982: function checkUpload(formname) {
5983: if (formname.upfile.value == "") {
1.539 riegler 5984: alert("$alertmsg");
1.86 ng 5985: return false;
5986: }
5987: formname.submit();
5988: }
5989: CSVFORMJS
1.283 albertel 5990: return $result;
5991: }
5992:
5993: sub upcsvScores_form {
1.596.2.12.2. 1(raebur 5994:0): my ($request,$symb) = @_;
1.283 albertel 5995: if (!$symb) {return '';}
5996: my $result=&checkforfile_js();
1.596.2.12.2. 1(raebur 5997:0): $result.=&Apache::loncommon::start_data_table().
5998:0): &Apache::loncommon::start_data_table_header_row().
5999:0): '<th>'.&mt('Specify a file containing the class scores for current resource.').'</th>'.
6000:0): &Apache::loncommon::end_data_table_header_row().
6001:0): &Apache::loncommon::start_data_table_row().'<td>';
1.370 www 6002: my $upload=&mt("Upload Scores");
1.86 ng 6003: my $upfile_select=&Apache::loncommon::upfile_select_html();
1.245 albertel 6004: my $ignore=&mt('Ignore First Line');
1.418 albertel 6005: $symb = &Apache::lonenc::check_encrypt($symb);
1.86 ng 6006: $result.=<<ENDUPFORM;
1.106 albertel 6007: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.86 ng 6008: <input type="hidden" name="symb" value="$symb" />
6009: <input type="hidden" name="command" value="csvuploadmap" />
6010: $upfile_select
1.589 bisitz 6011: <br /><input type="button" onclick="javascript:checkUpload(this.form);" value="$upload" />
1.283 albertel 6012: <label><input type="checkbox" name="noFirstLine" />$ignore</label>
1.86 ng 6013: </form>
6014: ENDUPFORM
1.370 www 6015: $result.=&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
1.596.2.12.2. 1(raebur 6016:0): &mt("How do I create a CSV file from a spreadsheet")).
6017:0): '</td>'.
6018:0): &Apache::loncommon::end_data_table_row().
6019:0): &Apache::loncommon::end_data_table();
1.86 ng 6020: return $result;
6021: }
6022:
6023:
1.26 albertel 6024: sub csvuploadmap {
1.596.2.12.2. 1(raebur 6025:0): my ($request,$symb) = @_;
1.41 ng 6026: if (!$symb) {return '';}
1.72 ng 6027:
1.41 ng 6028: my $datatoken;
1.257 albertel 6029: if (!$env{'form.datatoken'}) {
1.41 ng 6030: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 6031: } else {
1.596.2.12.2. 3(raebur 6032:8): $datatoken=&Apache::loncommon::valid_datatoken($env{'form.datatoken'});
6033:8): if ($datatoken ne '') {
6034:8): &Apache::loncommon::load_tmp_file($request,$datatoken);
6035:8): }
1.26 albertel 6036: }
1.41 ng 6037: my @records=&Apache::loncommon::upfile_record_sep();
1.257 albertel 6038: if ($env{'form.noFirstLine'}) { shift(@records); }
1.324 albertel 6039: &csvuploadmap_header($request,$symb,$datatoken,$#records+1);
1.41 ng 6040: my ($i,$keyfields);
6041: if (@records) {
1.582 raeburn 6042: my $fieldserror;
6043: my @fields=&csvupload_fields($symb,\$fieldserror);
6044: if ($fieldserror) {
6045: $request->print(&navmap_errormsg());
6046: return;
6047: }
1.257 albertel 6048: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 6049: &Apache::loncommon::csv_print_samples($request,\@records);
6050: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
6051: \@fields);
6052: foreach (@fields) { $keyfields.=$_->[0].','; }
6053: chop($keyfields);
6054: } else {
6055: unshift(@fields,['none','']);
6056: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
6057: \@fields);
1.311 banghart 6058: foreach my $rec (@records) {
6059: my %temp = &Apache::loncommon::record_sep($rec);
6060: if (%temp) {
6061: $keyfields=join(',',sort(keys(%temp)));
6062: last;
6063: }
6064: }
1.41 ng 6065: }
6066: }
6067: &csvuploadmap_footer($request,$i,$keyfields);
1.72 ng 6068:
1.41 ng 6069: return '';
1.27 albertel 6070: }
6071:
1.246 albertel 6072: sub csvuploadoptions {
1.596.2.12.2. 1(raebur 6073:0): my ($request,$symb)= @_;
6074:0): my $overwrite=&mt('Overwrite any existing score');
1.257 albertel 6075: my $checked=(($env{'form.noFirstLine'})?'1':'0');
1.246 albertel 6076: my $ignore=&mt('Ignore First Line');
6077: $request->print(<<ENDPICK);
6078: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
6079: <input type="hidden" name="command" value="csvuploadassign" />
6080: <p>
6081: <label>
6082: <input type="checkbox" name="overwite_scores" checked="checked" />
1.596.2.12.2. 1(raebur 6083:0): $overwrite
1.246 albertel 6084: </label>
6085: </p>
6086: ENDPICK
6087: my %fields=&get_fields();
6088: if (!defined($fields{'domain'})) {
1.257 albertel 6089: my $domform = &Apache::loncommon::select_dom_form($env{'request.role.domain'},'default_domain');
1.596.2.12.2. 1(raebur 6090:0): $request->print("\n<p>".&mt('Users are in domain: [_1]',$domform)."</p>\n");
1.246 albertel 6091: }
1.257 albertel 6092: foreach my $key (sort(keys(%env))) {
1.246 albertel 6093: if ($key !~ /^form\.(.*)$/) { next; }
6094: my $cleankey=$1;
6095: if ($cleankey eq 'command') { next; }
6096: $request->print('<input type="hidden" name="'.$cleankey.
1.257 albertel 6097: '" value="'.$env{$key}.'" />'."\n");
1.246 albertel 6098: }
6099: # FIXME do a check for any duplicated user ids...
6100: # FIXME do a check for any invalid user ids?...
1.596.2.12.2. 0(raebur 6101:3): $request->print('<input type="submit" value="'.&mt('Assign Grades').'" /><br />
1.290 albertel 6102: <hr /></form>'."\n");
1.246 albertel 6103: return '';
6104: }
6105:
6106: sub get_fields {
6107: my %fields;
1.257 albertel 6108: my @keyfields = split(/\,/,$env{'form.keyfields'});
6109: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
6110: if ($env{'form.upfile_associate'} eq 'reverse') {
6111: if ($env{'form.f'.$i} ne 'none') {
6112: $fields{$keyfields[$i]}=$env{'form.f'.$i};
1.41 ng 6113: }
6114: } else {
1.257 albertel 6115: if ($env{'form.f'.$i} ne 'none') {
6116: $fields{$env{'form.f'.$i}}=$keyfields[$i];
1.41 ng 6117: }
6118: }
1.27 albertel 6119: }
1.246 albertel 6120: return %fields;
6121: }
6122:
6123: sub csvuploadassign {
1.596.2.12.2. 1(raebur 6124:0): my ($request,$symb) = @_;
1.246 albertel 6125: if (!$symb) {return '';}
1.345 bowersj2 6126: my $error_msg = '';
1.596.2.12.2. 3(raebur 6127:8): my $datatoken = &Apache::loncommon::valid_datatoken($env{'form.datatoken'});
6128:8): if ($datatoken ne '') {
6129:8): &Apache::loncommon::load_tmp_file($request,$datatoken);
6130:8): }
1.246 albertel 6131: my @gradedata = &Apache::loncommon::upfile_record_sep();
1.257 albertel 6132: if ($env{'form.noFirstLine'}) { shift(@gradedata); }
1.246 albertel 6133: my %fields=&get_fields();
1.257 albertel 6134: my $courseid=$env{'request.course.id'};
1.596.2.12.2. 0.2.7(ra 6135:an-25): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6136:an-25): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.97 albertel 6137: my ($classlist) = &getclasslist('all',0);
1.106 albertel 6138: my @notallowed;
1.41 ng 6139: my @skipped;
1.596.2.4 raeburn 6140: my @warnings;
1.41 ng 6141: my $countdone=0;
1.596.2.12.2. 0.2.7(ra 6142:an-25): my @parts;
6143:an-25): my %needpb = &passbacks_for_symb($cdom,$cnum,$symb);
6144:an-25): my $passback;
6145:an-25): if (keys(%needpb)) {
6146:an-25): $passback = 1;
6147:an-25): my $navmap = Apache::lonnavmaps::navmap->new();
6148:an-25): if (ref($navmap)) {
6149:an-25): my $res = $navmap->getBySymb($symb);
6150:an-25): if (ref($res)) {
6151:an-25): my $partlist = $res->parts();
6152:an-25): if (ref($partlist) eq 'ARRAY') {
6153:an-25): @parts = sort(@{$partlist});
6154:an-25): }
6155:an-25): }
6156:an-25): } else {
6157:an-25): return &navmap_errormsg();
6158:an-25): }
6159:an-25): }
6160:an-25): my (%skip_passback,%pbsave,%weights,%awardeds,%excuseds);
6161:an-25):
1.41 ng 6162: foreach my $grade (@gradedata) {
6163: my %entries=&Apache::loncommon::record_sep($grade);
1.246 albertel 6164: my $domain;
6165: if ($entries{$fields{'domain'}}) {
6166: $domain=$entries{$fields{'domain'}};
6167: } else {
1.257 albertel 6168: $domain=$env{'form.default_domain'};
1.246 albertel 6169: }
1.243 albertel 6170: $domain=~s/\s//g;
1.41 ng 6171: my $username=$entries{$fields{'username'}};
1.160 albertel 6172: $username=~s/\s//g;
1.243 albertel 6173: if (!$username) {
6174: my $id=$entries{$fields{'ID'}};
1.247 albertel 6175: $id=~s/\s//g;
1.243 albertel 6176: my %ids=&Apache::lonnet::idget($domain,$id);
6177: $username=$ids{$id};
6178: }
1.41 ng 6179: if (!exists($$classlist{"$username:$domain"})) {
1.247 albertel 6180: my $id=$entries{$fields{'ID'}};
6181: $id=~s/\s//g;
6182: if ($id) {
6183: push(@skipped,"$id:$domain");
6184: } else {
6185: push(@skipped,"$username:$domain");
6186: }
1.41 ng 6187: next;
6188: }
1.108 albertel 6189: my $usec=$classlist->{"$username:$domain"}[5];
1.106 albertel 6190: if (!&canmodify($usec)) {
6191: push(@notallowed,"$username:$domain");
6192: next;
6193: }
1.244 albertel 6194: my %points;
1.41 ng 6195: my %grades;
6196: foreach my $dest (keys(%fields)) {
1.244 albertel 6197: if ($dest eq 'ID' || $dest eq 'username' ||
6198: $dest eq 'domain') { next; }
6199: if ($entries{$fields{$dest}} =~ /^\s*$/) { next; }
6200: if ($dest=~/stores_(.*)_points/) {
6201: my $part=$1;
6202: my $wgt =&Apache::lonnet::EXT('resource.'.$part.'.weight',
6203: $symb,$domain,$username);
1.596.2.12.2. 0.2.7(ra 6204:an-25): $weights{$symb}{$part} = $wgt;
1.345 bowersj2 6205: if ($wgt) {
6206: $entries{$fields{$dest}}=~s/\s//g;
6207: my $pcr=$entries{$fields{$dest}} / $wgt;
1.596.2.12.2. 0.2.7(ra 6208:an-25): if ($passback) {
6209:an-25): $awardeds{$symb}{$part} = $pcr;
6210:an-25): $excuseds{$symb}{$part} = '';
6211:an-25): }
1.463 albertel 6212: my $award=($pcr == 0) ? 'incorrect_by_override'
6213: : 'correct_by_override';
1.596.2.4 raeburn 6214: if ($pcr>1) {
6215: push(@warnings,&mt("[_1]: point value larger than weight","$username:$domain"));
6216: }
1.345 bowersj2 6217: $grades{"resource.$part.awarded"}=$pcr;
6218: $grades{"resource.$part.solved"}=$award;
6219: $points{$part}=1;
6220: } else {
6221: $error_msg = "<br />" .
6222: &mt("Some point values were assigned"
6223: ." for problems with a weight "
6224: ."of zero. These values were "
6225: ."ignored.");
6226: }
1.244 albertel 6227: } else {
6228: if ($dest=~/stores_(.*)_awarded/) { if ($points{$1}) {next;} }
6229: if ($dest=~/stores_(.*)_solved/) { if ($points{$1}) {next;} }
6230: my $store_key=$dest;
1.596.2.12.2. 0.2.7(ra 6231:an-25): if ($passback) {
6232:an-25): if ($store_key=~/stores_(.*)_(awarded|solved)/) {
6233:an-25): my ($part,$key) = ($1,$2);
6234:an-25): unless ((ref($weights{$symb}) eq 'HASH') && (exists($weights{$symb}{$part}))) {
6235:an-25): $weights{$symb}{$part} = &Apache::lonnet::EXT('resource.'.$part.'.weight',
6236:an-25): $symb,$domain,$username);
6237:an-25): }
6238:an-25): if ($key eq 'awarded') {
6239:an-25): $awardeds{$symb}{$part} = $entries{$fields{$dest}};
6240:an-25): } elsif ($key eq 'solved') {
6241:an-25): if ($entries{$fields{$dest}} =~ /^excused/) {
6242:an-25): $excuseds{$symb}{$part} = 1;
6243:an-25): }
6244:an-25): }
6245:an-25): }
6246:an-25): }
1.244 albertel 6247: $store_key=~s/^stores/resource/;
6248: $store_key=~s/_/\./g;
6249: $grades{$store_key}=$entries{$fields{$dest}};
6250: }
1.41 ng 6251: }
1.596.2.12.2. 1(raebur 6252:0): if (! %grades) {
1.508 www 6253: push(@skipped,&mt("[_1]: no data to save","$username:$domain"));
6254: } else {
6255: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
6256: my $result=&Apache::lonnet::cstore(\%grades,$symb,
1.302 albertel 6257: $env{'request.course.id'},
6258: $domain,$username);
1.508 www 6259: if ($result eq 'ok') {
1.596.2.12.2. 1(raebur 6260:0): # Successfully stored
1.508 www 6261: $request->print('.');
1.596.2.4 raeburn 6262: # Remove from grading queue
1.596.2.12.2. 0.2.7(ra 6263:an-25): &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,$cnum,
6264:an-25): $domain,$username);
6265:an-25): $countdone++;
6266:an-25): if ($passback) {
6267:an-25): my @parts_in_upload;
6268:an-25): if (ref($weights{$symb}) eq 'HASH') {
6269:an-25): @parts_in_upload = sort(keys(%{$weights{$symb}}));
6270:an-25): }
6271:an-25): my @diffs = &Apache::loncommon::compare_arrays(\@parts_in_upload,\@parts);
6272:an-25): if (@diffs > 0) {
6273:an-25): my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$username);
6274:an-25): foreach my $part (@parts) {
6275:an-25): next if (grep(/^\Q$part\E$/,@parts_in_upload));
6276:an-25): $weights{$symb}{$part} = &Apache::lonnet::EXT('resource.'.$part.'.weight',
6277:an-25): $symb,$domain,$username);
6278:an-25): if ($record{"resource.$part.solved"} =~/^excused/) {
6279:an-25): $excuseds{$symb}{$part} = 1;
6280:an-25): } else {
6281:an-25): $excuseds{$symb}{$part} = '';
6282:an-25): }
6283:an-25): $awardeds{$symb}{$part} = $record{"resource.$part.awarded"};
6284:an-25): }
6285:an-25): }
6286:an-25): &process_passbacks('csvupload',[$symb],$cdom,$cnum,$domain,$username,$usec,\%weights,
6287:an-25): \%awardeds,\%excuseds,\%needpb,\%skip_passback,\%pbsave);
6288:an-25): }
1.508 www 6289: } else {
6290: $request->print("<p><span class=\"LC_error\">".
6291: &mt("Failed to save data for student [_1]. Message when trying to save was: [_2]",
6292: "$username:$domain",$result)."</span></p>");
6293: }
6294: $request->rflush();
6295: }
1.41 ng 6296: }
1.570 www 6297: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt("Saved scores for [quant,_1,student]",$countdone),$countdone==0));
1.596.2.4 raeburn 6298: if (@warnings) {
6299: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('Warnings generated for the following saved scores:'),1).'<br />');
6300: $request->print(join(', ',@warnings));
6301: }
1.41 ng 6302: if (@skipped) {
1.571 www 6303: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('No scores stored for the following username(s):'),1).'<br />');
6304: $request->print(join(', ',@skipped));
1.106 albertel 6305: }
6306: if (@notallowed) {
1.571 www 6307: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('Modification of scores not allowed for the following username(s):'),1).'<br />');
6308: $request->print(join(', ',@notallowed));
1.41 ng 6309: }
1.106 albertel 6310: $request->print("<br />\n");
1.345 bowersj2 6311: return $error_msg;
1.26 albertel 6312: }
1.44 ng 6313: #------------- end of section for handling csv file upload ---------
6314: #
6315: #-------------------------------------------------------------------
6316: #
1.122 ng 6317: #-------------- Next few routines handle grading by page/sequence
1.72 ng 6318: #
6319: #--- Select a page/sequence and a student to grade
1.68 ng 6320: sub pickStudentPage {
1.596.2.12.2. 1(raebur 6321:0): my ($request,$symb) = @_;
1.68 ng 6322:
1.539 riegler 6323: my $alertmsg = &mt('Please select the student you wish to grade.');
1.596.2.12.2. 6(raebur 6324:6): &js_escape(\$alertmsg);
1(raebur 6325:0): $request->print(&Apache::lonhtmlcommon::scripttag(<<LISTJAVASCRIPT));
1.68 ng 6326:
6327: function checkPickOne(formname) {
1.76 ng 6328: if (radioSelection(formname.student) == null) {
1.539 riegler 6329: alert("$alertmsg");
1.68 ng 6330: return;
6331: }
1.125 ng 6332: ptr = pullDownSelection(formname.selectpage);
6333: formname.page.value = formname["page"+ptr].value;
6334: formname.title.value = formname["title"+ptr].value;
1.68 ng 6335: formname.submit();
6336: }
6337:
6338: LISTJAVASCRIPT
1.118 ng 6339: &commonJSfunctions($request);
1.596.2.12.2. 1(raebur 6340:0):
1.257 albertel 6341: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
6342: my $cnum = $env{"course.$env{'request.course.id'}.num"};
6343: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.596.2.12.2. 8(raebur 6344:9): my $getgroup = $env{'form.group'} eq '' ? 'all' : $env{'form.group'};
1.68 ng 6345:
1.398 albertel 6346: my $result='<h3><span class="LC_info"> '.
1.485 albertel 6347: &mt('Manual Grading by Page or Sequence').'</span></h3>';
1.68 ng 6348:
1.80 ng 6349: $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
1.582 raeburn 6350: my $map_error;
6351: my ($titles,$symbx) = &getSymbMap($map_error);
6352: if ($map_error) {
6353: $request->print(&navmap_errormsg());
6354: return;
6355: }
1.137 albertel 6356: my ($curpage) =&Apache::lonnet::decode_symb($symb);
6357: # my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb);
6358: # my $type=($curpage =~ /\.(page|sequence)/);
1.485 albertel 6359:
1.596.2.12.2. 1(raebur 6360:0): # Collection of hidden fields
6361:0): my $ctr=0;
1.70 ng 6362: foreach (@$titles) {
6363: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
6364: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
6365: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
6366: $ctr++;
6367: }
1.72 ng 6368: $result.='<input type="hidden" name="page" />'."\n".
6369: '<input type="hidden" name="title" />'."\n";
1.68 ng 6370:
1.432 banghart 6371: $result.=&build_section_inputs();
1.442 banghart 6372: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
6373: $result.='<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.596.2.12.2. 1(raebur 6374:0): '<input type="hidden" name="command" value="displayPage" />'."\n".
6375:0): '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
6376:0):
6377:0): # Show grading options
6378:0): $result.=&Apache::lonhtmlcommon::start_pick_box();
6379:0): my $select = '<select name="selectpage">'."\n";
6380:0): $ctr=0;
6381:0): foreach (@$titles) {
6382:0): my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
6383:0): $select.='<option value="'.$ctr.'"'.
6384:0): ($$symbx{$_} =~ /$curpage$/ ? ' selected="selected"' : '').
6385:0): '>'.$showtitle.'</option>'."\n";
6386:0): $ctr++;
6387:0): }
6388:0): $select.= '</select>';
1.72 ng 6389:
1.596.2.12.2. 1(raebur 6390:0): $result.=
6391:0): &Apache::lonhtmlcommon::row_title(&mt('Problems from'))
6392:0): .$select
6393:0): .&Apache::lonhtmlcommon::row_closure();
6394:0):
6395:0): $result.=
6396:0): &Apache::lonhtmlcommon::row_title(&mt('View Problem Text'))
6397:0): .'<label><input type="radio" name="vProb" value="no"'
6398:0): .' checked="checked" /> '.&mt('no').' </label>'."\n"
6399:0): .'<label><input type="radio" name="vProb" value="yes" />'
6400:0): .&mt('yes').'</label>'."\n"
6401:0): .&Apache::lonhtmlcommon::row_closure();
6402:0):
6403:0): $result.=
6404:0): &Apache::lonhtmlcommon::row_title(&mt('View Submissions'))
6405:0): .'<label><input type="radio" name="lastSub" value="none" /> '
6406:0): .&mt('none').' </label>'."\n"
6407:0): .'<label><input type="radio" name="lastSub" value="datesub"'
6408:0): .' checked="checked" /> '.&mt('all submissions').'</label>'."\n"
6409:0): .'<label><input type="radio" name="lastSub" value="all" /> '
6410:0): .&mt('all submissions with details').' </label>'
6411:0): .&Apache::lonhtmlcommon::row_closure();
6412:0):
6413:0): $result.=
6414:0): &Apache::lonhtmlcommon::row_title(&mt('Use CODE'))
6415:0): .'<input type="text" name="CODE" value="" />'
6416:0): .&Apache::lonhtmlcommon::row_closure(1)
6417:0): .&Apache::lonhtmlcommon::end_pick_box();
1.382 albertel 6418:
1.596.2.12.2. 1(raebur 6419:0): # Show list of students to select for grading
6420:0): $result.='<br /><input type="button" '.
1.589 bisitz 6421: 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /><br />'."\n";
1.72 ng 6422:
1.68 ng 6423: $request->print($result);
6424:
1.485 albertel 6425: my $studentTable.=' <b>'.&mt('Select a student you wish to grade and then click on the Next button.').'</b><br />'.
1.484 albertel 6426: &Apache::loncommon::start_data_table().
6427: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 6428: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 6429: '<th>'.&nameUserString('header').'</th>'.
1.485 albertel 6430: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 6431: '<th>'.&nameUserString('header').'</th>'.
6432: &Apache::loncommon::end_data_table_header_row();
1.68 ng 6433:
1.596.2.12.2. 8(raebur 6434:9): my (undef,undef,$fullname) = &getclasslist($getsec,'1',$getgroup);
1.68 ng 6435: my $ptr = 1;
1.294 albertel 6436: foreach my $student (sort
6437: {
6438: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
6439: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
6440: }
6441: return $a cmp $b;
6442: } (keys(%$fullname))) {
1.68 ng 6443: my ($uname,$udom) = split(/:/,$student);
1.484 albertel 6444: $studentTable.=($ptr%2==1 ? &Apache::loncommon::start_data_table_row()
6445: : '</td>');
1.126 ng 6446: $studentTable.='<td align="right">'.$ptr.' </td>';
1.288 albertel 6447: $studentTable.='<td> <label><input type="radio" name="student" value="'.$student.'" /> '
6448: .&nameUserString(undef,$$fullname{$student},$uname,$udom)."</label>\n";
1.484 albertel 6449: $studentTable.=
6450: ($ptr%2 == 0 ? '</td>'.&Apache::loncommon::end_data_table_row()
6451: : '');
1.68 ng 6452: $ptr++;
6453: }
1.484 albertel 6454: if ($ptr%2 == 0) {
6455: $studentTable.='</td><td> </td><td> </td>'.
6456: &Apache::loncommon::end_data_table_row();
6457: }
6458: $studentTable.=&Apache::loncommon::end_data_table()."\n";
1.126 ng 6459: $studentTable.='<input type="button" '.
1.589 bisitz 6460: 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /></form>'."\n";
1.68 ng 6461:
6462: $request->print($studentTable);
6463:
6464: return '';
6465: }
6466:
6467: sub getSymbMap {
1.582 raeburn 6468: my ($map_error) = @_;
1.132 bowersj2 6469: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 6470: unless (ref($navmap)) {
6471: if (ref($map_error)) {
6472: $$map_error = 'navmap';
6473: }
6474: return;
6475: }
1.68 ng 6476: my %symbx = ();
6477: my @titles = ();
1.117 bowersj2 6478: my $minder = 0;
6479:
6480: # Gather every sequence that has problems.
1.240 albertel 6481: my @sequences = $navmap->retrieveResources(undef, sub { shift->is_map(); },
6482: 1,0,1);
1.117 bowersj2 6483: for my $sequence ($navmap->getById('0.0'), @sequences) {
1.596.2.12.2. 0.2.4(ra 6484:ul-23): if ($navmap->hasResource($sequence, sub { shift->is_gradable(); }, 0) ) {
1.381 albertel 6485: my $title = $minder.'.'.
6486: &HTML::Entities::encode($sequence->compTitle(),'"\'&');
6487: push(@titles, $title); # minder in case two titles are identical
6488: $symbx{$title} = &HTML::Entities::encode($sequence->symb(),'"\'&');
1.117 bowersj2 6489: $minder++;
1.241 albertel 6490: }
1.68 ng 6491: }
6492: return \@titles,\%symbx;
6493: }
6494:
1.72 ng 6495: #
6496: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68 ng 6497: sub displayPage {
1.596.2.12.2. 1(raebur 6498:0): my ($request,$symb) = @_;
1.257 albertel 6499: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
6500: my $cnum = $env{"course.$env{'request.course.id'}.num"};
6501: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
6502: my $pageTitle = $env{'form.page'};
1.103 albertel 6503: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 6504: my ($uname,$udom) = split(/:/,$env{'form.student'});
6505: my $usec=$classlist->{$env{'form.student'}}[5];
1.168 albertel 6506:
6507: #need to make sure we have the correct data for later EXT calls,
6508: #thus invalidate the cache
6509: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 6510: $env{'course.'.$env{'request.course.id'}.'.num'},
6511: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 6512: &Apache::lonnet::clear_EXT_cache_status();
6513:
1.103 albertel 6514: if (!&canview($usec)) {
1.596.2.12.2. 1(raebur 6515:0): $request->print(
6516:0): '<span class="LC_warning">'.
6517:0): &mt('Unable to view requested student. ([_1])',
6518:0): $env{'form.student'}).
6519:0): '</span>');
8(raebur 6520:4): return;
1.103 albertel 6521: }
1.398 albertel 6522: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.485 albertel 6523: $result.='<h3> '.&mt('Student: [_1]',&nameUserString(undef,$$fullname{$env{'form.student'}},$uname,$udom)).
1.129 ng 6524: '</h3>'."\n";
1.500 albertel 6525: $env{'form.CODE'} = uc($env{'form.CODE'});
1.501 foxr 6526: if (&Apache::lonnet::validCODE(uc($env{'form.CODE'}))) {
1.485 albertel 6527: $result.='<h3> '.&mt('CODE: [_1]',$env{'form.CODE'}).'</h3>'."\n";
1.382 albertel 6528: } else {
6529: delete($env{'form.CODE'});
6530: }
1.71 ng 6531: &sub_page_js($request);
6532: $request->print($result);
6533:
1.132 bowersj2 6534: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 6535: unless (ref($navmap)) {
6536: $request->print(&navmap_errormsg());
6537: return;
6538: }
1.257 albertel 6539: my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($env{'form.page'});
1.68 ng 6540: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 6541: if (!$map) {
1.485 albertel 6542: $request->print('<span class="LC_warning">'.&mt('Unable to view requested sequence. ([_1])',$resUrl).'</span>');
1.288 albertel 6543: return;
6544: }
1.68 ng 6545: my $iterator = $navmap->getIterator($map->map_start(),
6546: $map->map_finish());
6547:
1.71 ng 6548: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72 ng 6549: '<input type="hidden" name="command" value="gradeByPage" />'."\n".
1.257 albertel 6550: '<input type="hidden" name="fullname" value="'.$$fullname{$env{'form.student'}}.'" />'."\n".
6551: '<input type="hidden" name="student" value="'.$env{'form.student'}.'" />'."\n".
1.72 ng 6552: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
1.257 albertel 6553: '<input type="hidden" name="title" value="'.$env{'form.title'}.'" />'."\n".
1.418 albertel 6554: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.596.2.12.2. 1(raebur 6555:0): '<input type="hidden" name="overRideScore" value="no" />'."\n";
1.71 ng 6556:
1.382 albertel 6557: if (defined($env{'form.CODE'})) {
6558: $studentTable.=
6559: '<input type="hidden" name="CODE" value="'.$env{'form.CODE'}.'" />'."\n";
6560: }
1.381 albertel 6561: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 6562: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 6563:
1.594 bisitz 6564: $studentTable.=' <span class="LC_info">'.
6565: &mt('Problems graded correct by the computer are marked with a [_1] symbol.',$checkIcon).
6566: '</span>'."\n".
1.484 albertel 6567: &Apache::loncommon::start_data_table().
6568: &Apache::loncommon::start_data_table_header_row().
1.596.2.12.2. 1(raebur 6569:0): '<th>'.&mt('Prob.').'</th>'.
1.485 albertel 6570: '<th> '.($env{'form.vProb'} eq 'no' ? &mt('Title') : &mt('Problem Text')).'/'.&mt('Grade').'</th>'.
1.484 albertel 6571: &Apache::loncommon::end_data_table_header_row();
1.71 ng 6572:
1.329 albertel 6573: &Apache::lonxml::clear_problem_counter();
1.196 albertel 6574: my ($depth,$question,$prob) = (1,1,1);
1.68 ng 6575: $iterator->next(); # skip the first BEGIN_MAP
6576: my $curRes = $iterator->next(); # for "current resource"
1.101 albertel 6577: while ($depth > 0) {
1.68 ng 6578: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 6579: if($curRes == $iterator->END_MAP) { $depth--; }
1.68 ng 6580:
1.596.2.12.2. 0.2.4(ra 6581:ul-23): if (ref($curRes) && $curRes->is_gradable()) {
1.91 albertel 6582: my $parts = $curRes->parts();
1.68 ng 6583: my $title = $curRes->compTitle();
1.71 ng 6584: my $symbx = $curRes->symb();
1.596.2.12.2. 0.2.4(ra 6585:ul-23): my $is_tool = ($symbx =~ /ext\.tool$/);
1.484 albertel 6586: $studentTable.=
6587: &Apache::loncommon::start_data_table_row().
6588: '<td align="center" valign="top" >'.$prob.
1.485 albertel 6589: (scalar(@{$parts}) == 1 ? ''
1.596.2.12.2. 2(raebur 6590:2): : '<br />('.&mt('[_1]parts',
6591:2): scalar(@{$parts}).' ').')'
1.485 albertel 6592: ).
6593: '</td>';
1.71 ng 6594: $studentTable.='<td valign="top">';
1.382 albertel 6595: my %form = ('CODE' => $env{'form.CODE'},);
1.596.2.12.2. 0.2.4(ra 6596:ul-23): if ($is_tool) {
6597:ul-23): $studentTable.=' <b>'.$title.'</b><br />';
6598:ul-23): } else {
6599:ul-23): if ($env{'form.vProb'} eq 'yes' ) {
6600:ul-23): $studentTable.=&show_problem($request,$symbx,$uname,$udom,1,
6601:ul-23): undef,'both',\%form);
6602:ul-23): } else {
6603:ul-23): my $companswer = &Apache::loncommon::get_student_answers($symbx,$uname,$udom,$env{'request.course.id'},%form);
6604:ul-23): $companswer =~ s|<form(.*?)>||g;
6605:ul-23): $companswer =~ s|</form>||g;
6606:ul-23): # while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
6607:ul-23): # $companswer =~ s/$1/ /ms;
6608:ul-23): # $request->print('match='.$1."<br />\n");
6609:ul-23): # }
6610:ul-23): # $companswer =~ s|<table border=\"1\">|<table border=\"0\">|g;
6611:ul-23): $studentTable.=' <b>'.$title.'</b> <br /> <b>'.&mt('Correct answer').':</b><br />'.$companswer;
6612:ul-23): }
1.71 ng 6613: }
6614:
1.257 albertel 6615: my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
1.125 ng 6616:
1.257 albertel 6617: if ($env{'form.lastSub'} eq 'datesub') {
1.71 ng 6618: if ($record{'version'} eq '') {
1.596.2.12.2. 0.2.4(ra 6619:ul-23): my $msg = &mt('No recorded submission for this problem.');
6620:ul-23): if ($is_tool) {
6621:ul-23): $msg = &mt('No recorded transactions for this external tool');
6622:ul-23): }
6623:ul-23): $studentTable.='<br /> <span class="LC_warning">'.$msg.'</span><br />';
1.71 ng 6624: } else {
1.116 ng 6625: my %responseType = ();
6626: foreach my $partid (@{$parts}) {
1.147 albertel 6627: my @responseIds =$curRes->responseIds($partid);
6628: my @responseType =$curRes->responseType($partid);
6629: my %responseIds;
6630: for (my $i=0;$i<=$#responseIds;$i++) {
6631: $responseIds{$responseIds[$i]}=$responseType[$i];
6632: }
6633: $responseType{$partid} = \%responseIds;
1.116 ng 6634: }
1.148 albertel 6635: $studentTable.= &displaySubByDates($symbx,\%record,$parts,\%responseType,$checkIcon,$uname,$udom);
1.147 albertel 6636:
1.71 ng 6637: }
1.257 albertel 6638: } elsif ($env{'form.lastSub'} eq 'all') {
6639: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.596.2.12.2. 1(raebur 6640:5): my $identifier = (&canmodify($usec)? $prob : '');
1.71 ng 6641: $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
1.257 albertel 6642: $env{'request.course.id'},
1.596.2.12.2. 1(raebur 6643:5): '','.submission',undef,
6644:5): $usec,$identifier);
1.71 ng 6645:
6646: }
1.103 albertel 6647: if (&canmodify($usec)) {
1.585 bisitz 6648: $studentTable.=&gradeBox_start();
1.103 albertel 6649: foreach my $partid (@{$parts}) {
6650: $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
6651: $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
6652: $question++;
6653: }
1.585 bisitz 6654: $studentTable.=&gradeBox_end();
1.196 albertel 6655: $prob++;
1.71 ng 6656: }
6657: $studentTable.='</td></tr>';
1.68 ng 6658:
1.103 albertel 6659: }
1.68 ng 6660: $curRes = $iterator->next();
6661: }
1.596.2.12.2. 6(raebur 6662:1): my $disabled;
6663:1): unless (&canmodify($usec)) {
6664:1): $disabled = ' disabled="disabled"';
6665:1): }
1.68 ng 6666:
1.589 bisitz 6667: $studentTable.=
6668: '</table>'."\n".
1.596.2.12.2. 6(raebur 6669:1): '<input type="button" value="'.&mt('Save').'"'.$disabled.' '.
1.589 bisitz 6670: 'onclick="javascript:checkSubmitPage(this.form,'.$question.');" />'.
6671: '</form>'."\n";
1.71 ng 6672: $request->print($studentTable);
6673:
6674: return '';
1.119 ng 6675: }
6676:
6677: sub displaySubByDates {
1.148 albertel 6678: my ($symb,$record,$parts,$responseType,$checkIcon,$uname,$udom) = @_;
1.224 albertel 6679: my $isCODE=0;
1.335 albertel 6680: my $isTask = ($symb =~/\.task$/);
1.596.2.12.2. 0.2.4(ra 6681:ul-23): my $is_tool = ($symb =~/\.tool$/);
1.224 albertel 6682: if (exists($record->{'resource.CODE'})) { $isCODE=1; }
1.467 albertel 6683: my $studentTable=&Apache::loncommon::start_data_table().
6684: &Apache::loncommon::start_data_table_header_row().
6685: '<th>'.&mt('Date/Time').'</th>'.
6686: ($isCODE?'<th>'.&mt('CODE').'</th>':'').
1.596.2.12.2. (raeburn 6687:): ($isTask?'<th>'.&mt('Version').'</th>':'').
0.2.4(ra 6688:ul-23): '<th>'.($is_tool?&mt('Grade'):&mt('Submission')).'</th>'.
1.467 albertel 6689: '<th>'.&mt('Status').'</th>'.
6690: &Apache::loncommon::end_data_table_header_row();
1.119 ng 6691: my ($version);
6692: my %mark;
1.148 albertel 6693: my %orders;
1.119 ng 6694: $mark{'correct_by_student'} = $checkIcon;
1.147 albertel 6695: if (!exists($$record{'1:timestamp'})) {
1.596.2.12.2. 0.2.4(ra 6696:ul-23): if ($is_tool) {
6697:ul-23): return '<br /> <span class="LC_warning">'.&mt('No grade passed back.').'</span><br />';
6698:ul-23): } else {
6699:ul-23): return '<br /> <span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br />';
6700:ul-23): }
1.147 albertel 6701: }
1.335 albertel 6702:
6703: my $interaction;
1.525 raeburn 6704: my $no_increment = 1;
1.596.2.12.2. 5(raebur 6705:5): my (%lastrndseed,%lasttype);
1.119 ng 6706: for ($version=1;$version<=$$record{'version'};$version++) {
1.467 albertel 6707: my $timestamp =
6708: &Apache::lonlocal::locallocaltime($$record{$version.':timestamp'});
1.335 albertel 6709: if (exists($$record{$version.':resource.0.version'})) {
6710: $interaction = $$record{$version.':resource.0.version'};
6711: }
1.596.2.12.2. (raeburn 6712:): if ($isTask && $env{'form.previousversion'}) {
6713:): next unless ($interaction == $env{'form.previousversion'});
6714:): }
1.335 albertel 6715: my $where = ($isTask ? "$version:resource.$interaction"
6716: : "$version:resource");
1.467 albertel 6717: $studentTable.=&Apache::loncommon::start_data_table_row().
6718: '<td>'.$timestamp.'</td>';
1.224 albertel 6719: if ($isCODE) {
6720: $studentTable.='<td>'.$record->{$version.':resource.CODE'}.'</td>';
6721: }
1.596.2.12.2. (raeburn 6722:): if ($isTask) {
6723:): $studentTable.='<td>'.$interaction.'</td>';
6724:): }
1.119 ng 6725: my @versionKeys = split(/\:/,$$record{$version.':keys'});
6726: my @displaySub = ();
6727: foreach my $partid (@{$parts}) {
1.596.2.2 raeburn 6728: my ($hidden,$type);
6729: $type = $$record{$version.':resource.'.$partid.'.type'};
6730: if (($type eq 'anonsurvey') || ($type eq 'anonsurveycred')) {
1.596 raeburn 6731: $hidden = 1;
6732: }
1.596.2.12.2. 1(raebur 6733:0): my @matchKey;
6734:0): if ($isTask) {
6735:0): @matchKey = sort(grep(/^resource\.\d+\.\Q$partid\E\.award$/,@versionKeys));
0.2.4(ra 6736:ul-23): } elsif ($is_tool) {
6737:ul-23): @matchKey = sort(grep(/^resource\.\Q$partid\E\.awarded$/,@versionKeys));
1(raebur 6738:0): } else {
6739:0): @matchKey = sort(grep(/^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys));
6740:0): }
1.122 ng 6741: # next if ($$record{"$version:resource.$partid.solved"} eq '');
1.324 albertel 6742: my $display_part=&get_display_part($partid,$symb);
1.147 albertel 6743: foreach my $matchKey (@matchKey) {
1.198 albertel 6744: if (exists($$record{$version.':'.$matchKey}) &&
6745: $$record{$version.':'.$matchKey} ne '') {
1.596.2.12.2. 0.2.4(ra 6746:ul-23): if ($is_tool) {
6747:ul-23): $displaySub[0].=$$record{"$version:resource.$partid.awarded"};
1.596 raeburn 6748: } else {
1.596.2.12.2. 0.2.4(ra 6749:ul-23): my ($responseId)= ($isTask ? ($matchKey=~ /^resource\.(.*?)\.\Q$partid\E\.award$/)
6750:ul-23): : ($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/));
6751:ul-23): $displaySub[0].='<span class="LC_nobreak">';
6752:ul-23): $displaySub[0].='<b>'.&mt('Part: [_1]',$display_part).'</b>'
6753:ul-23): .' <span class="LC_internal_info">'
6754:ul-23): .'('.&mt('Response ID: [_1]',$responseId).')'
6755:ul-23): .'</span>'
6756:ul-23): .' <b>';
6757:ul-23): if ($hidden) {
6758:ul-23): $displaySub[0].= &mt('Anonymous Survey').'</b>';
6759:ul-23): } else {
6760:ul-23): my ($trial,$rndseed,$newvariation);
6761:ul-23): if ($type eq 'randomizetry') {
6762:ul-23): $trial = $$record{"$where.$partid.tries"};
6763:ul-23): $rndseed = $$record{"$where.$partid.rndseed"};
1.596.2.2 raeburn 6764: }
1.596.2.12.2. 0.2.4(ra 6765:ul-23): if ($$record{"$where.$partid.tries"} eq '') {
6766:ul-23): $displaySub[0].=&mt('Trial not counted');
6767:ul-23): } else {
6768:ul-23): $displaySub[0].=&mt('Trial: [_1]',
6769:ul-23): $$record{"$where.$partid.tries"});
6770:ul-23): if (($rndseed ne '') && ($lastrndseed{$partid} ne '')) {
6771:ul-23): if (($rndseed ne $lastrndseed{$partid}) &&
6772:ul-23): (($type eq 'randomizetry') || ($lasttype{$partid} eq 'randomizetry'))) {
6773:ul-23): $newvariation = ' ('.&mt('New variation this try').')';
6774:ul-23): }
6775:ul-23): }
6776:ul-23): $lastrndseed{$partid} = $rndseed;
6777:ul-23): $lasttype{$partid} = $type;
6778:ul-23): }
6779:ul-23): my $responseType=($isTask ? 'Task'
6780:ul-23): : $responseType->{$partid}->{$responseId});
6781:ul-23): if (!exists($orders{$partid})) { $orders{$partid}={}; }
6782:ul-23): if ((!exists($orders{$partid}->{$responseId})) || ($trial)) {
6783:ul-23): $orders{$partid}->{$responseId}=
6784:ul-23): &get_order($partid,$responseId,$symb,$uname,$udom,
6785:ul-23): $no_increment,$type,$trial,$rndseed);
6786:ul-23): }
6787:ul-23): $displaySub[0].='</b>'.$newvariation.'</span>'; # /nobreak
6788:ul-23): $displaySub[0].=' '.
6789:ul-23): &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:",$uname,$udom,$type,$trial,$rndseed).'<br />';
6790:ul-23): }
1.596 raeburn 6791: }
1.147 albertel 6792: }
6793: }
1.335 albertel 6794: if (exists($$record{"$where.$partid.checkedin"})) {
1.485 albertel 6795: $displaySub[1].=&mt('Checked in by [_1] into slot [_2]',
6796: $$record{"$where.$partid.checkedin"},
6797: $$record{"$where.$partid.checkedin.slot"}).
6798: '<br />';
1.335 albertel 6799: }
6800: if (exists $$record{"$where.$partid.award"}) {
1.485 albertel 6801: $displaySub[1].='<b>'.&mt('Part:').'</b> '.$display_part.' '.
1.335 albertel 6802: lc($$record{"$where.$partid.award"}).' '.
6803: $mark{$$record{"$where.$partid.solved"}}.
1.147 albertel 6804: '<br />';
1.596.2.12.2. 0.2.4(ra 6805:ul-23): } elsif (($is_tool) && (exists($$record{"$version:resource.$partid.solved"}))) {
6806:ul-23): if ($$record{"$version:resource.$partid.solved"} =~ /^(in|)correct_by_passback$/) {
6807:ul-23): $displaySub[1].=&mt('Grade passed back by external tool');
6808:ul-23): }
1.147 albertel 6809: }
1.335 albertel 6810: if (exists $$record{"$where.$partid.regrader"}) {
1.596.2.12.2. 0.2.4(ra 6811:ul-23): $displaySub[2].=$$record{"$where.$partid.regrader"};
6812:ul-23): unless ($is_tool) {
6813:ul-23): $displaySub[2].=' (<b>'.&mt('Part').':</b> '.$display_part.')';
6814:ul-23): }
1.335 albertel 6815: } elsif ($$record{"$version:resource.$partid.regrader"} =~ /\S/) {
6816: $displaySub[2].=
1.596.2.12.2. 0.2.4(ra 6817:ul-23): $$record{"$version:resource.$partid.regrader"};
6818:ul-23): unless ($is_tool) {
6819:ul-23): $displaySub[2].=' (<b>'.&mt('Part').':</b> '.$display_part.')';
6820:ul-23): }
1.147 albertel 6821: }
6822: }
6823: # needed because old essay regrader has not parts info
6824: if (exists $$record{"$version:resource.regrader"}) {
6825: $displaySub[2].=$$record{"$version:resource.regrader"};
6826: }
6827: $studentTable.='<td>'.$displaySub[0].' </td><td>'.$displaySub[1];
6828: if ($displaySub[2]) {
1.467 albertel 6829: $studentTable.=&mt('Manually graded by [_1]',$displaySub[2]);
1.147 albertel 6830: }
1.467 albertel 6831: $studentTable.=' </td>'.
6832: &Apache::loncommon::end_data_table_row();
1.119 ng 6833: }
1.467 albertel 6834: $studentTable.=&Apache::loncommon::end_data_table();
1.119 ng 6835: return $studentTable;
1.71 ng 6836: }
6837:
6838: sub updateGradeByPage {
1.596.2.12.2. 1(raebur 6839:0): my ($request,$symb) = @_;
1.71 ng 6840:
1.257 albertel 6841: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
6842: my $cnum = $env{"course.$env{'request.course.id'}.num"};
6843: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
6844: my $pageTitle = $env{'form.page'};
1.103 albertel 6845: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 6846: my ($uname,$udom) = split(/:/,$env{'form.student'});
6847: my $usec=$classlist->{$env{'form.student'}}[5];
1.103 albertel 6848: if (!&canmodify($usec)) {
1.526 raeburn 6849: $request->print('<span class="LC_warning">'.&mt('Unable to modify requested student ([_1])',$env{'form.student'}).'</span>');
1.103 albertel 6850: return;
6851: }
1.398 albertel 6852: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.526 raeburn 6853: $result.='<h3> '.&mt('Student: ').&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
1.129 ng 6854: '</h3>'."\n";
1.70 ng 6855:
1.68 ng 6856: $request->print($result);
6857:
1.582 raeburn 6858:
1.132 bowersj2 6859: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 6860: unless (ref($navmap)) {
6861: $request->print(&navmap_errormsg());
6862: return;
6863: }
1.257 albertel 6864: my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $env{'form.page'});
1.71 ng 6865: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 6866: if (!$map) {
1.527 raeburn 6867: $request->print('<span class="LC_warning">'.&mt('Unable to grade requested sequence ([_1]).',$resUrl).'</span>');
1.288 albertel 6868: return;
6869: }
1.71 ng 6870: my $iterator = $navmap->getIterator($map->map_start(),
6871: $map->map_finish());
1.70 ng 6872:
1.484 albertel 6873: my $studentTable=
6874: &Apache::loncommon::start_data_table().
6875: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 6876: '<th align="center"> '.&mt('Prob.').' </th>'.
6877: '<th> '.&mt('Title').' </th>'.
6878: '<th> '.&mt('Previous Score').' </th>'.
6879: '<th> '.&mt('New Score').' </th>'.
1.484 albertel 6880: &Apache::loncommon::end_data_table_header_row();
1.71 ng 6881:
6882: $iterator->next(); # skip the first BEGIN_MAP
6883: my $curRes = $iterator->next(); # for "current resource"
1.596.2.12.2. 1(raebur 6884:5): my ($depth,$question,$prob,$changeflag,$hideflag)= (1,1,1,0,0);
0.2.7(ra 6885:an-25): my (@updates,%weights,%excuseds,%awardeds,@symbs_in_map);
1.101 albertel 6886: while ($depth > 0) {
1.71 ng 6887: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 6888: if($curRes == $iterator->END_MAP) { $depth--; }
1.71 ng 6889:
1.385 albertel 6890: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 6891: my $parts = $curRes->parts();
1.71 ng 6892: my $title = $curRes->compTitle();
6893: my $symbx = $curRes->symb();
1.596.2.12.2. 0.2.7(ra 6894:an-25): push(@symbs_in_map,$symbx);
1.484 albertel 6895: $studentTable.=
6896: &Apache::loncommon::start_data_table_row().
6897: '<td align="center" valign="top" >'.$prob.
1.485 albertel 6898: (scalar(@{$parts}) == 1 ? ''
1.596.2.2 raeburn 6899: : '<br />('.&mt('[quant,_1,part]',scalar(@{$parts}))
1.526 raeburn 6900: .')').'</td>';
1.71 ng 6901: $studentTable.='<td valign="top"> <b>'.$title.'</b> </td>';
6902:
6903: my %newrecord=();
6904: my @displayPts=();
1.269 raeburn 6905: my %aggregate = ();
6906: my $aggregateflag = 0;
1.596.2.12.2. 9(raebur 6907:1): my %queueable;
1(raebur 6908:5): if ($env{'form.HIDE'.$prob}) {
6909:5): my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
6910:5): my ($version,$parts) = split(/:/,$env{'form.HIDE'.$prob},2);
6911:5): my $numchgs = &makehidden($version,$parts,\%record,$symbx,$udom,$uname,1);
0.2.7(ra 6912:an-25): if ($numchgs) {
6913:an-25): push(@updates,$symbx);
6914:an-25): }
1(raebur 6915:5): $hideflag += $numchgs;
6916:5): }
1.71 ng 6917: foreach my $partid (@{$parts}) {
1.257 albertel 6918: my $newpts = $env{'form.GD_BOX'.$question.'_'.$partid};
6919: my $oldpts = $env{'form.oldpts'.$question.'_'.$partid};
1.596.2.12.2. 9(raebur 6920:1): my @types = $curRes->responseType($partid);
8(raebur 6921:1): if (grep(/^essay$/,@types)) {
6922:1): $queueable{$partid} = 1;
6923:1): } else {
9(raebur 6924:1): my @ids = $curRes->responseIds($partid);
8(raebur 6925:1): for (my $i=0; $i < scalar(@ids); $i++) {
9(raebur 6926:1): my $hndgrd = &Apache::lonnet::EXT('resource.'.$partid.'_'.$ids[$i].
8(raebur 6927:1): '.handgrade',$symb);
6928:1): if (lc($hndgrd) eq 'yes') {
6929:1): $queueable{$partid} = 1;
6930:1): last;
6931:1): }
6932:1): }
6933:1): }
1.257 albertel 6934: my $wgt = $env{'form.WGT'.$question.'_'.$partid} != 0 ?
6935: $env{'form.WGT'.$question.'_'.$partid} : 1;
1.596.2.12.2. 0.2.7(ra 6936:an-25): $weights{$symbx}{$partid} = $wgt;
6937:an-25): $excuseds{$symbx}{$partid} = '';
1.71 ng 6938: my $partial = $newpts/$wgt;
6939: my $score;
6940: if ($partial > 0) {
6941: $score = 'correct_by_override';
1.125 ng 6942: } elsif ($newpts ne '') { #empty is taken as 0
1.71 ng 6943: $score = 'incorrect_by_override';
6944: }
1.257 albertel 6945: my $dropMenu = $env{'form.GD_SEL'.$question.'_'.$partid};
1.125 ng 6946: if ($dropMenu eq 'excused') {
1.71 ng 6947: $partial = '';
6948: $score = 'excused';
1.596.2.12.2. 0.2.7(ra 6949:an-25): $excuseds{$symbx}{$partid} = 1;
1.125 ng 6950: } elsif ($dropMenu eq 'reset status'
1.257 albertel 6951: && $env{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
1.125 ng 6952: $newrecord{'resource.'.$partid.'.tries'} = 0;
6953: $newrecord{'resource.'.$partid.'.solved'} = '';
6954: $newrecord{'resource.'.$partid.'.award'} = '';
6955: $newrecord{'resource.'.$partid.'.awarded'} = 0;
1.257 albertel 6956: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 6957: $changeflag++;
6958: $newpts = '';
1.269 raeburn 6959:
6960: my $aggtries = $env{'form.aggtries'.$question.'_'.$partid};
6961: my $totaltries = $env{'form.totaltries'.$question.'_'.$partid};
6962: my $solvedstatus = $env{'form.solved'.$question.'_'.$partid};
6963: if ($aggtries > 0) {
6964: &decrement_aggs($symbx,$partid,\%aggregate,$aggtries,$totaltries,$solvedstatus);
6965: $aggregateflag = 1;
6966: }
1.71 ng 6967: }
1.324 albertel 6968: my $display_part=&get_display_part($partid,$curRes->symb());
1.257 albertel 6969: my $oldstatus = $env{'form.solved'.$question.'_'.$partid};
1.526 raeburn 6970: $displayPts[0].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.71 ng 6971: (($oldstatus eq 'excused') ? 'excused' : $oldpts).
1.326 albertel 6972: ' <br />';
1.526 raeburn 6973: $displayPts[1].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.125 ng 6974: (($score eq 'excused') ? 'excused' : $newpts).
1.326 albertel 6975: ' <br />';
1.71 ng 6976: $question++;
1.596.2.12.2. 0.2.7(ra 6977:an-25): if (($newpts eq '') || ($partial eq '')) {
6978:an-25): $awardeds{$symbx}{$partid} = 0;
6979:an-25): } else {
6980:an-25): $awardeds{$symbx}{$partid} = $partial;
6981:an-25): }
1.380 albertel 6982: next if ($dropMenu eq 'reset status' || ($newpts eq $oldpts && $score ne 'excused'));
1.125 ng 6983:
1.71 ng 6984: $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
1.125 ng 6985: $newrecord{'resource.'.$partid.'.solved'} = $score if $score ne '';
1.257 albertel 6986: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}"
1.125 ng 6987: if (scalar(keys(%newrecord)) > 0);
1.71 ng 6988:
6989: $changeflag++;
6990: }
6991: if (scalar(keys(%newrecord)) > 0) {
1.382 albertel 6992: my %record =
6993: &Apache::lonnet::restore($symbx,$env{'request.course.id'},
6994: $udom,$uname);
6995:
6996: if (&Apache::lonnet::validCODE($env{'form.CODE'})) {
6997: $newrecord{'resource.CODE'} = $env{'form.CODE'};
6998: } elsif (&Apache::lonnet::validCODE($record{'resource.CODE'})) {
6999: $newrecord{'resource.CODE'} = '';
7000: }
1.257 albertel 7001: &Apache::lonnet::cstore(\%newrecord,$symbx,$env{'request.course.id'},
1.71 ng 7002: $udom,$uname);
1.382 albertel 7003: %record = &Apache::lonnet::restore($symbx,
7004: $env{'request.course.id'},
7005: $udom,$uname);
1.380 albertel 7006: &check_and_remove_from_queue($parts,\%record,undef,$symbx,
1.596.2.12.2. 8(raebur 7007:1): $cdom,$cnum,$udom,$uname,\%queueable);
1.71 ng 7008: }
1.380 albertel 7009:
1.269 raeburn 7010: if ($aggregateflag) {
7011: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
7012: $env{'course.'.$env{'request.course.id'}.'.domain'},
7013: $env{'course.'.$env{'request.course.id'}.'.num'});
7014: }
1.125 ng 7015:
1.71 ng 7016: $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
7017: '<td valign="top">'.$displayPts[1].'</td>'.
1.484 albertel 7018: &Apache::loncommon::end_data_table_row();
1.68 ng 7019:
1.196 albertel 7020: $prob++;
1.596.2.12.2. 0.2.7(ra 7021:an-25): if ($changeflag) {
7022:an-25): push(@updates,$symbx);
7023:an-25): }
1.68 ng 7024: }
1.71 ng 7025: $curRes = $iterator->next();
1.68 ng 7026: }
1.98 albertel 7027:
1.484 albertel 7028: $studentTable.=&Apache::loncommon::end_data_table();
1.526 raeburn 7029: my $grademsg=($changeflag == 0 ? &mt('No score was changed or updated.') :
7030: &mt('The scores were changed for [quant,_1,problem].',
1.596.2.12.2. 1(raebur 7031:5): $changeflag).'<br />');
7032:5): my $hidemsg=($hideflag == 0 ? '' :
7033:5): &mt('Submissions were marked "hidden" for [quant,_1,transaction].',
7034:5): $hideflag).'<br />');
7035:5): $request->print($hidemsg.$grademsg.$studentTable);
1.68 ng 7036:
1.596.2.12.2. 0.2.7(ra 7037:an-25): if (@updates) {
7038:an-25): my (@allsymbs,$mapsymb,@recurseup,%parentmapsymbs,%possmappb,%possrespb);
7039:an-25): @allsymbs = @updates;
7040:an-25): if (ref($map)) {
7041:an-25): $mapsymb = $map->symb();
7042:an-25): push(@allsymbs,$mapsymb);
7043:an-25): @recurseup = $navmap->recurseup_maps($map->src,1);
7044:an-25): }
7045:an-25): if (@recurseup) {
7046:an-25): push(@allsymbs,@recurseup);
7047:an-25): map { $parentmapsymbs{$_} = 1; } @recurseup;
7048:an-25): }
7049:an-25): my %passback = &Apache::lonnet::get('nohist_linkprot_passback',\@allsymbs,$cdom,$cnum);
7050:an-25): my (%uniqsymbs,$use_symbs_in_map,%launch_to_symb);
7051:an-25): if (keys(%passback)) {
7052:an-25): foreach my $possible (keys(%passback)) {
7053:an-25): if (ref($passback{$possible}) eq 'HASH') {
7054:an-25): if ($possible eq $mapsymb) {
7055:an-25): foreach my $launcher (keys(%{$passback{$possible}})) {
7056:an-25): $possmappb{$launcher} = 1;
7057:an-25): $launch_to_symb{$launcher} = $possible;
7058:an-25): }
7059:an-25): $use_symbs_in_map = 1;
7060:an-25): } elsif (exists($parentmapsymbs{$possible})) {
7061:an-25): foreach my $launcher (keys(%{$passback{$possible}})) {
7062:an-25): my ($linkuri,$linkprotector,$scope) = split(/\0/,$launcher);
7063:an-25): if ($scope eq 'rec') {
7064:an-25): $possmappb{$launcher} = 1;
7065:an-25): $use_symbs_in_map = 1;
7066:an-25): $launch_to_symb{$launcher} = $possible;
7067:an-25): }
7068:an-25): }
7069:an-25): } elsif (grep(/^\Q$possible$\E$/,@updates)) {
7070:an-25): foreach my $launcher (keys(%{$passback{$possible}})) {
7071:an-25): $possrespb{$launcher} = 1;
7072:an-25): $launch_to_symb{$launcher} = $possible;
7073:an-25): }
7074:an-25): $uniqsymbs{$possible} = 1;
7075:an-25): }
7076:an-25): }
7077:an-25): }
7078:an-25): }
7079:an-25): if ($use_symbs_in_map) {
7080:an-25): map { $uniqsymbs{$_} = 1; } @symbs_in_map;
7081:an-25): }
7082:an-25): my @posslaunchers;
7083:an-25): if (keys(%possmappb)) {
7084:an-25): push(@posslaunchers,keys(%possmappb));
7085:an-25): }
7086:an-25): if (keys(%possrespb)) {
7087:an-25): push(@posslaunchers,keys(%possrespb));
7088:an-25): }
7089:an-25): if (@posslaunchers) {
7090:an-25): my (%pbsave,%skip_passback,%needpb);
7091:an-25): my %pbids = &Apache::lonnet::get('nohist_'.$cdom.'_'.$cnum.'_linkprot_pb',\@posslaunchers,$udom,$uname);
7092:an-25): foreach my $key (keys(%pbids)) {
7093:an-25): if (ref($pbids{$key}) eq 'ARRAY') {
7094:an-25): if ($launch_to_symb{$key}) {
7095:an-25): $needpb{$key} = $launch_to_symb{$key};
7096:an-25): }
7097:an-25): }
7098:an-25): }
7099:an-25): my @symbs = keys(%uniqsymbs);
7100:an-25): &process_passbacks('updatebypage',\@symbs,$cdom,$cnum,$udom,$uname,$usec,\%weights,
7101:an-25): \%awardeds,\%excuseds,\%needpb,\%skip_passback,\%pbsave,\%pbids);
7102:an-25): if (@Apache::grades::ltipassback) {
7103:an-25): unless ($registered_cleanup) {
7104:an-25): my $handlers = $request->get_handlers('PerlCleanupHandler');
7105:an-25): $request->set_handlers('PerlCleanupHandler' =>
7106:an-25): [\&Apache::grades::make_passback,@{$handlers}]);
7107:an-25): $registered_cleanup=1;
7108:an-25): }
7109:an-25): }
7110:an-25): }
7111:an-25): }
1.70 ng 7112: return '';
7113: }
7114:
1.596.2.12.2. 0.2.7(ra 7115:an-25): sub make_passback {
7116:an-25): if (@Apache::grades::ltipassback) {
7117:an-25): my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
7118:an-25): my $ip = &Apache::lonnet::get_host_ip($lonhost);
7119:an-25): foreach my $item (@Apache::grades::ltipassback) {
7120:an-25): &Apache::lonhomework::run_passback($item,$lonhost,$ip);
7121:an-25): }
7122:an-25): undef(@Apache::grades::ltipassback);
7123:an-25): }
7124:an-25): }
7125:an-25):
1.72 ng 7126: #-------- end of section for handling grading by page/sequence ---------
7127: #
7128: #-------------------------------------------------------------------
7129:
1.581 www 7130: #-------------------- Bubblesheet (Scantron) Grading -------------------
1.75 albertel 7131: #
7132: #------ start of section for handling grading by page/sequence ---------
7133:
1.423 albertel 7134: =pod
7135:
7136: =head1 Bubble sheet grading routines
7137:
1.424 albertel 7138: For this documentation:
7139:
7140: 'scanline' refers to the full line of characters
7141: from the file that we are parsing that represents one entire sheet
7142:
7143: 'bubble line' refers to the data
1.596.2.6 raeburn 7144: representing the line of bubbles that are on the physical bubblesheet
1.424 albertel 7145:
7146:
1.596.2.6 raeburn 7147: The overall process is that a scanned in bubblesheet data is uploaded
1.424 albertel 7148: into a course. When a user wants to grade, they select a
1.596.2.6 raeburn 7149: sequence/folder of resources, a file of bubblesheet info, and pick
1.424 albertel 7150: one of the predefined configurations for what each scanline looks
7151: like.
7152:
7153: Next each scanline is checked for any errors of either 'missing
1.435 foxr 7154: bubbles' (it's an error because it may have been mis-scanned
1.424 albertel 7155: because too light bubbling), 'double bubble' (each bubble line should
1.596.2.12.2. 0(raebur 7156:3): have no more than one letter picked), invalid or duplicated CODE,
1.556 weissno 7157: invalid student/employee ID
1.424 albertel 7158:
7159: If the CODE option is used that determines the randomization of the
1.556 weissno 7160: homework problems, either way the student/employee ID is looked up into a
1.424 albertel 7161: username:domain.
7162:
7163: During the validation phase the instructor can choose to skip scanlines.
7164:
1.596.2.6 raeburn 7165: After the validation phase, there are now 3 bubblesheet files
1.424 albertel 7166:
7167: scantron_original_filename (unmodified original file)
7168: scantron_corrected_filename (file where the corrected information has replaced the original information)
7169: scantron_skipped_filename (contains the exact text of scanlines that where skipped)
7170:
7171: Also there is a separate hash nohist_scantrondata that contains extra
1.596.2.6 raeburn 7172: correction information that isn't representable in the bubblesheet
1.424 albertel 7173: file (see &scantron_getfile() for more information)
7174:
7175: After all scanlines are either valid, marked as valid or skipped, then
7176: foreach line foreach problem in the picked sequence, an ssi request is
7177: made that simulates a user submitting their selected letter(s) against
7178: the homework problem.
1.423 albertel 7179:
7180: =over 4
7181:
7182:
7183:
7184: =item defaultFormData
7185:
7186: Returns html hidden inputs used to hold context/default values.
7187:
7188: Arguments:
7189: $symb - $symb of the current resource
7190:
7191: =cut
1.422 foxr 7192:
1.81 albertel 7193: sub defaultFormData {
1.324 albertel 7194: my ($symb)=@_;
1.596.2.12.2. 1(raebur 7195:0): return '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />';
1.81 albertel 7196: }
7197:
1.447 foxr 7198:
1.423 albertel 7199: =pod
7200:
7201: =item getSequenceDropDown
7202:
7203: Return html dropdown of possible sequences to grade
7204:
7205: Arguments:
1.582 raeburn 7206: $symb - $symb of the current resource
7207: $map_error - ref to scalar which will container error if
7208: $navmap object is unavailable in &getSymbMap().
1.423 albertel 7209:
7210: =cut
1.422 foxr 7211:
1.75 albertel 7212: sub getSequenceDropDown {
1.582 raeburn 7213: my ($symb,$map_error)=@_;
1.75 albertel 7214: my $result='<select name="selectpage">'."\n";
1.582 raeburn 7215: my ($titles,$symbx) = &getSymbMap($map_error);
7216: if (ref($map_error)) {
7217: return if ($$map_error);
7218: }
1.137 albertel 7219: my ($curpage)=&Apache::lonnet::decode_symb($symb);
1.75 albertel 7220: my $ctr=0;
7221: foreach (@$titles) {
7222: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
7223: $result.='<option value="'.$$symbx{$_}.'" '.
1.401 albertel 7224: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.75 albertel 7225: '>'.$showtitle.'</option>'."\n";
7226: $ctr++;
7227: }
7228: $result.= '</select>';
7229: return $result;
7230: }
7231:
1.495 albertel 7232: my %bubble_lines_per_response; # no. bubble lines for each response.
1.554 raeburn 7233: # key is zero-based index - 0, 1, 2 ...
1.495 albertel 7234:
7235: my %first_bubble_line; # First bubble line no. for each bubble.
7236:
1.509 raeburn 7237: my %subdivided_bubble_lines; # no. bubble lines for optionresponse,
7238: # matchresponse or rankresponse, where
7239: # an individual response can have multiple
7240: # lines
1.503 raeburn 7241:
7242: my %responsetype_per_response; # responsetype for each response
7243:
1.596.2.12.2. 6(raebur 7244:3): my %masterseq_id_responsenum; # src_id (e.g., 12.3_0.11 etc.) for each
7245:3): # numbered response. Needed when randomorder
7246:3): # or randompick are in use. Key is ID, value
7247:3): # is response number.
7248:3):
1.495 albertel 7249: # Save and restore the bubble lines array to the form env.
7250:
7251:
7252: sub save_bubble_lines {
7253: foreach my $line (keys(%bubble_lines_per_response)) {
7254: $env{"form.scantron.bubblelines.$line"} = $bubble_lines_per_response{$line};
7255: $env{"form.scantron.first_bubble_line.$line"} =
7256: $first_bubble_line{$line};
1.503 raeburn 7257: $env{"form.scantron.sub_bubblelines.$line"} =
7258: $subdivided_bubble_lines{$line};
7259: $env{"form.scantron.responsetype.$line"} =
7260: $responsetype_per_response{$line};
1.495 albertel 7261: }
1.596.2.12.2. 6(raebur 7262:3): foreach my $resid (keys(%masterseq_id_responsenum)) {
7263:3): my $line = $masterseq_id_responsenum{$resid};
7264:3): $env{"form.scantron.residpart.$line"} = $resid;
7265:3): }
1.495 albertel 7266: }
7267:
7268:
7269: sub restore_bubble_lines {
7270: my $line = 0;
7271: %bubble_lines_per_response = ();
1.596.2.12.2. 6(raebur 7272:3): %masterseq_id_responsenum = ();
1.495 albertel 7273: while ($env{"form.scantron.bubblelines.$line"}) {
7274: my $value = $env{"form.scantron.bubblelines.$line"};
7275: $bubble_lines_per_response{$line} = $value;
7276: $first_bubble_line{$line} =
7277: $env{"form.scantron.first_bubble_line.$line"};
1.503 raeburn 7278: $subdivided_bubble_lines{$line} =
7279: $env{"form.scantron.sub_bubblelines.$line"};
7280: $responsetype_per_response{$line} =
7281: $env{"form.scantron.responsetype.$line"};
1.596.2.12.2. 6(raebur 7282:3): my $id = $env{"form.scantron.residpart.$line"};
7283:3): $masterseq_id_responsenum{$id} = $line;
1.495 albertel 7284: $line++;
7285: }
7286: }
7287:
1.423 albertel 7288: =pod
7289:
7290: =item scantron_filenames
7291:
7292: Returns a list of the scantron files in the current course
7293:
7294: =cut
1.422 foxr 7295:
1.202 albertel 7296: sub scantron_filenames {
1.257 albertel 7297: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7298: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
1.517 raeburn 7299: my $getpropath = 1;
1.596.2.12.2. (raeburn 7300:): my ($dirlist,$listerror) = &Apache::lonnet::dirlist('userfiles',$cdom,
7301:): $cname,$getpropath);
1.202 albertel 7302: my @possiblenames;
1.596.2.12.2. (raeburn 7303:): if (ref($dirlist) eq 'ARRAY') {
7304:): foreach my $filename (sort(@{$dirlist})) {
7305:): ($filename)=split(/&/,$filename);
7306:): if ($filename!~/^scantron_orig_/) { next ; }
7307:): $filename=~s/^scantron_orig_//;
7308:): push(@possiblenames,$filename);
7309:): }
1.202 albertel 7310: }
7311: return @possiblenames;
7312: }
7313:
1.423 albertel 7314: =pod
7315:
7316: =item scantron_uploads
7317:
7318: Returns html drop-down list of scantron files in current course.
7319:
7320: Arguments:
7321: $file2grade - filename to set as selected in the dropdown
7322:
7323: =cut
1.422 foxr 7324:
1.202 albertel 7325: sub scantron_uploads {
1.209 ng 7326: my ($file2grade) = @_;
1.202 albertel 7327: my $result= '<select name="scantron_selectfile">';
7328: $result.="<option></option>";
7329: foreach my $filename (sort(&scantron_filenames())) {
1.401 albertel 7330: $result.="<option".($filename eq $file2grade ? ' selected="selected"':'').">$filename</option>\n";
1.81 albertel 7331: }
7332: $result.="</select>";
7333: return $result;
7334: }
7335:
1.423 albertel 7336: =pod
7337:
7338: =item scantron_scantab
7339:
7340: Returns html drop down of the scantron formats in the scantronformat.tab
7341: file.
7342:
7343: =cut
1.422 foxr 7344:
1.82 albertel 7345: sub scantron_scantab {
7346: my $result='<select name="scantron_format">'."\n";
1.191 albertel 7347: $result.='<option></option>'."\n";
1.596.2.12.2. 9(raebur 7348:9): my @lines = &Apache::lonnet::get_scantronformat_file();
1.518 raeburn 7349: if (@lines > 0) {
7350: foreach my $line (@lines) {
7351: next if (($line =~ /^\#/) || ($line eq ''));
7352: my ($name,$descrip)=split(/:/,$line);
7353: $result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
7354: }
1.82 albertel 7355: }
7356: $result.='</select>'."\n";
1.518 raeburn 7357: return $result;
7358: }
7359:
1.423 albertel 7360: =pod
7361:
7362: =item scantron_CODElist
7363:
7364: Returns html drop down of the saved CODE lists from current course,
7365: generated from earlier printings.
7366:
7367: =cut
1.422 foxr 7368:
1.186 albertel 7369: sub scantron_CODElist {
1.257 albertel 7370: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7371: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.186 albertel 7372: my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
7373: my $namechoice='<option></option>';
1.225 albertel 7374: foreach my $name (sort {uc($a) cmp uc($b)} @names) {
1.191 albertel 7375: if ($name =~ /^error: 2 /) { next; }
1.278 albertel 7376: if ($name =~ /^type\0/) { next; }
1.186 albertel 7377: $namechoice.='<option value="'.$name.'">'.$name.'</option>';
7378: }
7379: $namechoice='<select name="scantron_CODElist">'.$namechoice.'</select>';
7380: return $namechoice;
7381: }
7382:
1.423 albertel 7383: =pod
7384:
7385: =item scantron_CODEunique
7386:
7387: Returns the html for "Each CODE to be used once" radio.
7388:
7389: =cut
1.422 foxr 7390:
1.186 albertel 7391: sub scantron_CODEunique {
1.532 bisitz 7392: my $result='<span class="LC_nobreak">
1.272 albertel 7393: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 7394: value="yes" checked="checked" />'.&mt('Yes').' </label>
1.381 albertel 7395: </span>
1.532 bisitz 7396: <span class="LC_nobreak">
1.272 albertel 7397: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 7398: value="no" />'.&mt('No').' </label>
1.381 albertel 7399: </span>';
1.186 albertel 7400: return $result;
7401: }
1.423 albertel 7402:
7403: =pod
7404:
7405: =item scantron_selectphase
7406:
1.596.2.6 raeburn 7407: Generates the initial screen to start the bubblesheet process.
1.423 albertel 7408: Allows for - starting a grading run.
1.424 albertel 7409: - downloading existing scan data (original, corrected
1.423 albertel 7410: or skipped info)
7411:
7412: - uploading new scan data
7413:
7414: Arguments:
7415: $r - The Apache request object
7416: $file2grade - name of the file that contain the scanned data to score
7417:
7418: =cut
1.186 albertel 7419:
1.75 albertel 7420: sub scantron_selectphase {
1.596.2.12.2. 1(raebur 7421:0): my ($r,$file2grade,$symb) = @_;
1.75 albertel 7422: if (!$symb) {return '';}
1.582 raeburn 7423: my $map_error;
7424: my $sequence_selector=&getSequenceDropDown($symb,\$map_error);
7425: if ($map_error) {
7426: $r->print('<br />'.&navmap_errormsg().'<br />');
7427: return;
7428: }
1.324 albertel 7429: my $default_form_data=&defaultFormData($symb);
1.209 ng 7430: my $file_selector=&scantron_uploads($file2grade);
1.82 albertel 7431: my $format_selector=&scantron_scantab();
1.186 albertel 7432: my $CODE_selector=&scantron_CODElist();
7433: my $CODE_unique=&scantron_CODEunique();
1.75 albertel 7434: my $result;
1.422 foxr 7435:
1.513 foxr 7436: $ssi_error = 0;
7437:
1.596.2.4 raeburn 7438: if (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) ||
7439: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
7440:
7441: # Chunk of form to prompt for a scantron file upload.
7442:
7443: $r->print('
1.596.2.12.2. 9(raebur 7444:9): <br />');
7445:9): my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
7446:9): my $cnum= $env{'course.'.$env{'request.course.id'}.'.num'};
7447:9): my $alertmsg = &mt('Please use the browse button to select a file from your local directory.');
7448:9): &js_escape(\$alertmsg);
7449:9): my ($formatoptions,$formattitle,$formatjs) = &scantron_upload_dataformat($cdom);
7450:9): $r->print(&Apache::lonhtmlcommon::scripttag('
1.596.2.4 raeburn 7451: function checkUpload(formname) {
7452: if (formname.upfile.value == "") {
1.596.2.12.2. 6(raebur 7453:6): alert("'.$alertmsg.'");
1.596.2.4 raeburn 7454: return false;
7455: }
7456: formname.submit();
1.596.2.12.2. 9(raebur 7457:9): }'."\n".$formatjs));
7458:9): $r->print('
1.596.2.4 raeburn 7459: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
7460: '.$default_form_data.'
7461: <input name="courseid" type="hidden" value="'.$cnum.'" />
7462: <input name="domainid" type="hidden" value="'.$cdom.'" />
7463: <input name="command" value="scantronupload_save" type="hidden" />
1.596.2.12.2. 9(raebur 7464:9): '.&Apache::loncommon::start_data_table('LC_scantron_action').'
7465:9): '.&Apache::loncommon::start_data_table_header_row().'
7466:9): <th>
7467:9): '.&mt('Specify a bubblesheet data file to upload.').'
7468:9): </th>
7469:9): '.&Apache::loncommon::end_data_table_header_row().'
7470:9): '.&Apache::loncommon::start_data_table_row().'
7471:9): <td>
7472:9): '.&mt('File to upload: [_1]','<input type="file" name="upfile" size="50" />').'<br />'."\n");
7473:9): if ($formatoptions) {
7474:9): $r->print('</td>
7475:9): '.&Apache::loncommon::end_data_table_row().'
7476:9): '.&Apache::loncommon::start_data_table_row().'
7477:9): <td>'.$formattitle.(' 'x2).$formatoptions.'
7478:9): </td>
7479:9): '.&Apache::loncommon::end_data_table_row().'
7480:9): '.&Apache::loncommon::start_data_table_row().'
7481:9): <td>'
7482:9): );
7483:9): } else {
7484:9): $r->print(' <br />');
7485:9): }
7486:9): $r->print('<input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
7487:9): </td>
7488:9): '.&Apache::loncommon::end_data_table_row().'
7489:9): '.&Apache::loncommon::end_data_table().'
7490:9): </form>'
7491:9): );
1.596.2.4 raeburn 7492:
7493: }
7494:
1.422 foxr 7495: # Chunk of form to prompt for a file to grade and how:
7496:
1.489 albertel 7497: $result.= '
7498: <br />
7499: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantron_process">
7500: <input type="hidden" name="command" value="scantron_warning" />
7501: '.$default_form_data.'
7502: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
7503: '.&Apache::loncommon::start_data_table_header_row().'
7504: <th colspan="2">
1.492 albertel 7505: '.&mt('Specify file and which Folder/Sequence to grade').'
1.489 albertel 7506: </th>
7507: '.&Apache::loncommon::end_data_table_header_row().'
7508: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 7509: <td> '.&mt('Sequence to grade:').' </td><td> '.$sequence_selector.' </td>
1.489 albertel 7510: '.&Apache::loncommon::end_data_table_row().'
7511: '.&Apache::loncommon::start_data_table_row().'
1.572 www 7512: <td> '.&mt('Filename of bubblesheet data file:').' </td><td> '.$file_selector.' </td>
1.489 albertel 7513: '.&Apache::loncommon::end_data_table_row().'
7514: '.&Apache::loncommon::start_data_table_row().'
1.572 www 7515: <td> '.&mt('Format of bubblesheet data file:').' </td><td> '.$format_selector.' </td>
1.489 albertel 7516: '.&Apache::loncommon::end_data_table_row().'
7517: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 7518: <td> '.&mt('Saved CODEs to validate against:').' </td><td> '.$CODE_selector.' </td>
1.489 albertel 7519: '.&Apache::loncommon::end_data_table_row().'
7520: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 7521: <td> '.&mt('Each CODE is only to be used once:').'</td><td> '.$CODE_unique.' </td>
1.489 albertel 7522: '.&Apache::loncommon::end_data_table_row().'
7523: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 7524: <td> '.&mt('Options:').' </td>
1.187 albertel 7525: <td>
1.492 albertel 7526: <label><input type="checkbox" name="scantron_options_redo" value="redo_skipped"/> '.&mt('Do only previously skipped records').'</label> <br />
7527: <label><input type="checkbox" name="scantron_options_ignore" value="ignore_corrections"/> '.&mt('Remove all existing corrections').'</label> <br />
7528: <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources when grading').'</label>
1.187 albertel 7529: </td>
1.489 albertel 7530: '.&Apache::loncommon::end_data_table_row().'
7531: '.&Apache::loncommon::start_data_table_row().'
1.174 albertel 7532: <td colspan="2">
1.572 www 7533: <input type="submit" value="'.&mt('Grading: Validate Bubblesheet Records').'" />
1.162 albertel 7534: </td>
1.489 albertel 7535: '.&Apache::loncommon::end_data_table_row().'
7536: '.&Apache::loncommon::end_data_table().'
7537: </form>
7538: ';
1.162 albertel 7539:
7540: $r->print($result);
7541:
1.422 foxr 7542: # Chunk of the form that prompts to view a scoring office file,
7543: # corrected file, skipped records in a file.
7544:
1.489 albertel 7545: $r->print('
7546: <br />
7547: <form action="/adm/grades" name="scantron_download">
7548: '.$default_form_data.'
7549: <input type="hidden" name="command" value="scantron_download" />
7550: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
7551: '.&Apache::loncommon::start_data_table_header_row().'
7552: <th>
1.492 albertel 7553: '.&mt('Download a scoring office file').'
1.489 albertel 7554: </th>
7555: '.&Apache::loncommon::end_data_table_header_row().'
7556: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 7557: <td> '.&mt('Filename of scoring office file: [_1]',$file_selector).'
1.489 albertel 7558: <br />
1.492 albertel 7559: <input type="submit" value="'.&mt('Download: Show List of Associated Files').'" />
1.489 albertel 7560: '.&Apache::loncommon::end_data_table_row().'
7561: '.&Apache::loncommon::end_data_table().'
7562: </form>
7563: <br />
7564: ');
1.162 albertel 7565:
1.457 banghart 7566: &Apache::lonpickcode::code_list($r,2);
1.523 raeburn 7567:
1.596.2.12.2. 8(raebur 7568:3): $r->print('<br /><form method="post" name="checkscantron" action="">'.
1.523 raeburn 7569: $default_form_data."\n".
7570: &Apache::loncommon::start_data_table('LC_scantron_action')."\n".
7571: &Apache::loncommon::start_data_table_header_row()."\n".
7572: '<th colspan="2">
1.572 www 7573: '.&mt('Review bubblesheet data and submissions for a previously graded folder/sequence')."\n".
1.523 raeburn 7574: '</th>'."\n".
7575: &Apache::loncommon::end_data_table_header_row()."\n".
7576: &Apache::loncommon::start_data_table_row()."\n".
7577: '<td> '.&mt('Graded folder/sequence:').' </td>'."\n".
7578: '<td> '.$sequence_selector.' </td>'.
7579: &Apache::loncommon::end_data_table_row()."\n".
7580: &Apache::loncommon::start_data_table_row()."\n".
7581: '<td> '.&mt('Filename of scoring office file:').' </td>'."\n".
7582: '<td> '.$file_selector.' </td>'."\n".
7583: &Apache::loncommon::end_data_table_row()."\n".
7584: &Apache::loncommon::start_data_table_row()."\n".
7585: '<td> '.&mt('Format of data file:').' </td>'."\n".
7586: '<td> '.$format_selector.' </td>'."\n".
7587: &Apache::loncommon::end_data_table_row()."\n".
7588: &Apache::loncommon::start_data_table_row()."\n".
1.557 raeburn 7589: '<td> '.&mt('Options').' </td>'."\n".
7590: '<td> <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources').'</label></td>'.
7591: &Apache::loncommon::end_data_table_row()."\n".
7592: &Apache::loncommon::start_data_table_row()."\n".
1.523 raeburn 7593: '<td colspan="2">'."\n".
7594: '<input type="hidden" name="command" value="checksubmissions" />'."\n".
1.575 www 7595: '<input type="submit" value="'.&mt('Review Bubblesheet Data and Submission Records').'" />'."\n".
1.523 raeburn 7596: '</td>'."\n".
7597: &Apache::loncommon::end_data_table_row()."\n".
7598: &Apache::loncommon::end_data_table()."\n".
7599: '</form><br />');
7600: return;
1.75 albertel 7601: }
7602:
1.423 albertel 7603: =pod
7604:
7605: =item username_to_idmap
7606:
1.556 weissno 7607: creates a hash keyed by student/employee ID with values of the corresponding
1.423 albertel 7608: student username:domain.
7609:
7610: Arguments:
7611:
7612: $classlist - reference to the class list hash. This is a hash
7613: keyed by student name:domain whose elements are references
1.424 albertel 7614: to arrays containing various chunks of information
1.423 albertel 7615: about the student. (See loncoursedata for more info).
7616:
7617: Returns
7618: %idmap - the constructed hash
7619:
7620: =cut
7621:
1.82 albertel 7622: sub username_to_idmap {
7623: my ($classlist)= @_;
7624: my %idmap;
7625: foreach my $student (keys(%$classlist)) {
1.596.2.12.2. 3(raebur 7626:5): my $id = $classlist->{$student}->[&Apache::loncoursedata::CL_ID];
7627:5): unless ($id eq '') {
7628:5): if (!exists($idmap{$id})) {
7629:5): $idmap{$id} = $student;
7630:5): } else {
7631:5): my $status = $classlist->{$student}->[&Apache::loncoursedata::CL_STATUS];
7632:5): if ($status eq 'Active') {
7633:5): $idmap{$id} = $student;
7634:5): }
7635:5): }
7636:5): }
1.82 albertel 7637: }
7638: return %idmap;
7639: }
1.423 albertel 7640:
7641: =pod
7642:
1.424 albertel 7643: =item scantron_fixup_scanline
1.423 albertel 7644:
7645: Process a requested correction to a scanline.
7646:
7647: Arguments:
1.596.2.12.2. 9(raebur 7648:9): $scantron_config - hash from &Apache::lonnet::get_scantron_config()
1.423 albertel 7649: $scan_data - hash of correction information
7650: (see &scantron_getfile())
7651: $line - existing scanline
7652: $whichline - line number of the passed in scanline
7653: $field - type of change to process
7654: (either
1.573 bisitz 7655: 'ID' -> correct the student/employee ID
1.423 albertel 7656: 'CODE' -> correct the CODE
7657: 'answer' -> fixup the submitted answers)
7658:
7659: $args - hash of additional info,
7660: - 'ID'
7661: 'newid' -> studentID to use in replacement
1.424 albertel 7662: of existing one
1.423 albertel 7663: - 'CODE'
7664: 'CODE_ignore_dup' - set to true if duplicates
7665: should be ignored.
7666: 'CODE' - is new code or 'use_unfound'
1.424 albertel 7667: if the existing unfound code should
1.423 albertel 7668: be used as is
7669: - 'answer'
7670: 'response' - new answer or 'none' if blank
7671: 'question' - the bubble line to change
1.503 raeburn 7672: 'questionnum' - the question identifier,
7673: may include subquestion.
1.423 albertel 7674:
7675: Returns:
7676: $line - the modified scanline
7677:
7678: Side effects:
7679: $scan_data - may be updated
7680:
7681: =cut
7682:
1.82 albertel 7683:
1.157 albertel 7684: sub scantron_fixup_scanline {
7685: my ($scantron_config,$scan_data,$line,$whichline,$field,$args)=@_;
7686: if ($field eq 'ID') {
7687: if (length($args->{'newid'}) > $$scantron_config{'IDlength'}) {
1.186 albertel 7688: return ($line,1,'New value too large');
1.157 albertel 7689: }
7690: if (length($args->{'newid'}) < $$scantron_config{'IDlength'}) {
7691: $args->{'newid'}=sprintf('%-'.$$scantron_config{'IDlength'}.'s',
7692: $args->{'newid'});
7693: }
7694: substr($line,$$scantron_config{'IDstart'}-1,
7695: $$scantron_config{'IDlength'})=$args->{'newid'};
7696: if ($args->{'newid'}=~/^\s*$/) {
7697: &scan_data($scan_data,"$whichline.user",
7698: $args->{'username'}.':'.$args->{'domain'});
7699: }
1.186 albertel 7700: } elsif ($field eq 'CODE') {
1.192 albertel 7701: if ($args->{'CODE_ignore_dup'}) {
7702: &scan_data($scan_data,"$whichline.CODE_ignore_dup",'1');
7703: }
7704: &scan_data($scan_data,"$whichline.useCODE",'1');
7705: if ($args->{'CODE'} ne 'use_unfound') {
1.191 albertel 7706: if (length($args->{'CODE'}) > $$scantron_config{'CODElength'}) {
7707: return ($line,1,'New CODE value too large');
7708: }
7709: if (length($args->{'CODE'}) < $$scantron_config{'CODElength'}) {
7710: $args->{'CODE'}=sprintf('%-'.$$scantron_config{'CODElength'}.'s',$args->{'CODE'});
7711: }
7712: substr($line,$$scantron_config{'CODEstart'}-1,
7713: $$scantron_config{'CODElength'})=$args->{'CODE'};
1.186 albertel 7714: }
1.157 albertel 7715: } elsif ($field eq 'answer') {
1.497 foxr 7716: my $length=$scantron_config->{'Qlength'};
1.157 albertel 7717: my $off=$scantron_config->{'Qoff'};
7718: my $on=$scantron_config->{'Qon'};
1.497 foxr 7719: my $answer=${off}x$length;
7720: if ($args->{'response'} eq 'none') {
7721: &scan_data($scan_data,
1.503 raeburn 7722: "$whichline.no_bubble.".$args->{'questionnum'},'1');
1.497 foxr 7723: } else {
7724: if ($on eq 'letter') {
7725: my @alphabet=('A'..'Z');
7726: $answer=$alphabet[$args->{'response'}];
7727: } elsif ($on eq 'number') {
7728: $answer=$args->{'response'}+1;
7729: if ($answer == 10) { $answer = '0'; }
1.274 albertel 7730: } else {
1.497 foxr 7731: substr($answer,$args->{'response'},1)=$on;
1.274 albertel 7732: }
1.497 foxr 7733: &scan_data($scan_data,
1.503 raeburn 7734: "$whichline.no_bubble.".$args->{'questionnum'},undef,'1');
1.157 albertel 7735: }
1.497 foxr 7736: my $where=$length*($args->{'question'}-1)+$scantron_config->{'Qstart'};
7737: substr($line,$where-1,$length)=$answer;
1.157 albertel 7738: }
7739: return $line;
7740: }
1.423 albertel 7741:
7742: =pod
7743:
7744: =item scan_data
7745:
7746: Edit or look up an item in the scan_data hash.
7747:
7748: Arguments:
7749: $scan_data - The hash (see scantron_getfile)
7750: $key - shorthand of the key to edit (actual key is
1.424 albertel 7751: scantronfilename_key).
1.423 albertel 7752: $data - New value of the hash entry.
7753: $delete - If true, the entry is removed from the hash.
7754:
7755: Returns:
7756: The new value of the hash table field (undefined if deleted).
7757:
7758: =cut
7759:
7760:
1.157 albertel 7761: sub scan_data {
7762: my ($scan_data,$key,$value,$delete)=@_;
1.257 albertel 7763: my $filename=$env{'form.scantron_selectfile'};
1.157 albertel 7764: if (defined($value)) {
7765: $scan_data->{$filename.'_'.$key} = $value;
7766: }
7767: if ($delete) { delete($scan_data->{$filename.'_'.$key}); }
7768: return $scan_data->{$filename.'_'.$key};
7769: }
1.423 albertel 7770:
1.495 albertel 7771: # ----- These first few routines are general use routines.----
7772:
7773: # Return the number of occurences of a pattern in a string.
7774:
7775: sub occurence_count {
7776: my ($string, $pattern) = @_;
7777:
7778: my @matches = ($string =~ /$pattern/g);
7779:
7780: return scalar(@matches);
7781: }
7782:
7783:
7784: # Take a string known to have digits and convert all the
7785: # digits into letters in the range J,A..I.
7786:
7787: sub digits_to_letters {
7788: my ($input) = @_;
7789:
7790: my @alphabet = ('J', 'A'..'I');
7791:
7792: my @input = split(//, $input);
7793: my $output ='';
7794: for (my $i = 0; $i < scalar(@input); $i++) {
7795: if ($input[$i] =~ /\d/) {
7796: $output .= $alphabet[$input[$i]];
7797: } else {
7798: $output .= $input[$i];
7799: }
7800: }
7801: return $output;
7802: }
7803:
1.423 albertel 7804: =pod
7805:
7806: =item scantron_parse_scanline
7807:
7808: Decodes a scanline from the selected scantron file
7809:
7810: Arguments:
7811: line - The text of the scantron file line to process
7812: whichline - Line number
7813: scantron_config - Hash describing the format of the scantron lines.
7814: scan_data - Hash of extra information about the scanline
7815: (see scantron_getfile for more information)
7816: just_header - True if should not process question answers but only
7817: the stuff to the left of the answers.
1.596.2.12.2. 6(raebur 7818:3): randomorder - True if randomorder in use
7819:3): randompick - True if randompick in use
7820:3): sequence - Exam folder URL
7821:3): master_seq - Ref to array containing symbs in exam folder
7822:3): symb_to_resource - Ref to hash of symbs for resources in exam folder
7823:3): (corresponding values are resource objects)
7824:3): partids_by_symb - Ref to hash of symb -> array ref of partIDs
7825:3): orderedforcode - Ref to hash of arrays. keys are CODEs and values
7826:3): are refs to an array of resource objects, ordered
7827:3): according to order used for CODE, when randomorder
7828:3): and or randompick are in use.
7829:3): respnumlookup - Ref to hash mapping question numbers in bubble lines
7830:3): for current line to question number used for same question
7831:3): in "Master Sequence" (as seen by Course Coordinator).
7832:3): startline - Ref to hash where key is question number (0 is first)
7833:3): and value is number of first bubble line for current
7834:3): student or code-based randompick and/or randomorder.
7835:3): totalref - Ref of scalar used to score total number of bubble
7836:3): lines needed for responses in a scan line (used when
7837:3): randompick in use.
7838:3):
1.423 albertel 7839: Returns:
7840: Hash containing the result of parsing the scanline
7841:
7842: Keys are all proceeded by the string 'scantron.'
7843:
7844: CODE - the CODE in use for this scanline
7845: useCODE - 1 if the CODE is invalid but it usage has been forced
7846: by the operator
7847: CODE_ignore_dup - 1 if the CODE is a duplicated use when unique
7848: CODEs were selected, but the usage has been
7849: forced by the operator
1.556 weissno 7850: ID - student/employee ID
1.423 albertel 7851: PaperID - if used, the ID number printed on the sheet when the
7852: paper was scanned
7853: FirstName - first name from the sheet
7854: LastName - last name from the sheet
7855:
7856: if just_header was not true these key may also exist
7857:
1.447 foxr 7858: missingerror - a list of bubble ranges that are considered to be answers
7859: to a single question that don't have any bubbles filled in.
7860: Of the form questionnumber:firstbubblenumber:count.
7861: doubleerror - a list of bubble ranges that are considered to be answers
7862: to a single question that have more than one bubble filled in.
7863: Of the form questionnumber::firstbubblenumber:count
7864:
7865: In the above, count is the number of bubble responses in the
7866: input line needed to represent the possible answers to the question.
7867: e.g. a radioresponse with 15 choices in an answer sheet with 10 choices
7868: per line would have count = 2.
7869:
1.423 albertel 7870: maxquest - the number of the last bubble line that was parsed
7871:
7872: (<number> starts at 1)
7873: <number>.answer - zero or more letters representing the selected
7874: letters from the scanline for the bubble line
7875: <number>.
7876: if blank there was either no bubble or there where
7877: multiple bubbles, (consult the keys missingerror and
7878: doubleerror if this is an error condition)
7879:
7880: =cut
7881:
1.82 albertel 7882: sub scantron_parse_scanline {
1.596.2.12.2. 6(raebur 7883:3): my ($line,$whichline,$scantron_config,$scan_data,$just_header,$idmap,
7884:3): $randomorder,$randompick,$sequence,$master_seq,$symb_to_resource,
7885:3): $partids_by_symb,$orderedforcode,$respnumlookup,$startline,$totalref)=@_;
1.470 foxr 7886:
1.82 albertel 7887: my %record;
1.596.2.12.2. 6(raebur 7888:3): my $data=substr($line,0,$$scantron_config{'Qstart'}-1); # stuff before answers
1.278 albertel 7889: if (!($$scantron_config{'CODElocation'} eq 0 ||
7890: $$scantron_config{'CODElocation'} eq 'none')) {
7891: if ($$scantron_config{'CODElocation'} < 0 ||
7892: $$scantron_config{'CODElocation'} eq 'letter' ||
7893: $$scantron_config{'CODElocation'} eq 'number') {
1.191 albertel 7894: $record{'scantron.CODE'}=substr($data,
7895: $$scantron_config{'CODEstart'}-1,
1.83 albertel 7896: $$scantron_config{'CODElength'});
1.191 albertel 7897: if (&scan_data($scan_data,"$whichline.useCODE")) {
7898: $record{'scantron.useCODE'}=1;
7899: }
1.192 albertel 7900: if (&scan_data($scan_data,"$whichline.CODE_ignore_dup")) {
7901: $record{'scantron.CODE_ignore_dup'}=1;
7902: }
1.82 albertel 7903: } else {
7904: #FIXME interpret first N questions
7905: }
7906: }
1.83 albertel 7907: $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
7908: $$scantron_config{'IDlength'});
1.157 albertel 7909: $record{'scantron.PaperID'}=
7910: substr($data,$$scantron_config{'PaperID'}-1,
7911: $$scantron_config{'PaperIDlength'});
7912: $record{'scantron.FirstName'}=
7913: substr($data,$$scantron_config{'FirstName'}-1,
7914: $$scantron_config{'FirstNamelength'});
7915: $record{'scantron.LastName'}=
7916: substr($data,$$scantron_config{'LastName'}-1,
7917: $$scantron_config{'LastNamelength'});
1.423 albertel 7918: if ($just_header) { return \%record; }
1.194 albertel 7919:
1.82 albertel 7920: my @alphabet=('A'..'Z');
7921: my $questnum=0;
1.447 foxr 7922: my $ansnum =1; # Multiple 'answer lines'/question.
7923:
1.596.2.12.2. 6(raebur 7924:3): my $lastpos = $env{'form.scantron_maxbubble'}*$$scantron_config{'Qlength'};
7925:3): if ($randompick || $randomorder) {
7926:3): my $total = &get_respnum_lookups($sequence,$scan_data,$idmap,$line,\%record,
7927:3): $master_seq,$symb_to_resource,
7928:3): $partids_by_symb,$orderedforcode,
7929:3): $respnumlookup,$startline);
7930:3): if ($total) {
7931:3): $lastpos = $total*$$scantron_config{'Qlength'};
7932:3): }
7933:3): if (ref($totalref)) {
7934:3): $$totalref = $total;
7935:3): }
7936:3): }
7937:3): my $questions=substr($line,$$scantron_config{'Qstart'}-1,$lastpos); # Answers
1.470 foxr 7938: chomp($questions); # Get rid of any trailing \n.
7939: $questions =~ s/\r$//; # Get rid of trailing \r too (MAC or Win uploads).
7940: while (length($questions)) {
1.596.2.12.2. 6(raebur 7941:3): my $answers_needed;
7942:3): if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
7943:3): $answers_needed = $bubble_lines_per_response{$respnumlookup->{$questnum}};
7944:3): } else {
7945:3): $answers_needed = $bubble_lines_per_response{$questnum};
7946:3): }
1.503 raeburn 7947: my $answer_length = ($$scantron_config{'Qlength'} * $answers_needed)
7948: || 1;
7949: $questnum++;
7950: my $quest_id = $questnum;
7951: my $currentquest = substr($questions,0,$answer_length);
7952: $questions = substr($questions,$answer_length);
7953: if (length($currentquest) < $answer_length) { next; }
7954:
1.596.2.12.2. 6(raebur 7955:3): my $subdivided;
7956:3): if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
7957:3): $subdivided = $subdivided_bubble_lines{$respnumlookup->{$questnum-1}};
7958:3): } else {
7959:3): $subdivided = $subdivided_bubble_lines{$questnum-1};
7960:3): }
7961:3): if ($subdivided =~ /,/) {
1.503 raeburn 7962: my $subquestnum = 1;
7963: my $subquestions = $currentquest;
1.596.2.12.2. 6(raebur 7964:3): my @subanswers_needed = split(/,/,$subdivided);
1.503 raeburn 7965: foreach my $subans (@subanswers_needed) {
7966: my $subans_length =
7967: ($$scantron_config{'Qlength'} * $subans) || 1;
7968: my $currsubquest = substr($subquestions,0,$subans_length);
7969: $subquestions = substr($subquestions,$subans_length);
7970: $quest_id = "$questnum.$subquestnum";
7971: if (($$scantron_config{'Qon'} eq 'letter') ||
7972: ($$scantron_config{'Qon'} eq 'number')) {
7973: $ansnum = &scantron_validator_lettnum($ansnum,
7974: $questnum,$quest_id,$subans,$currsubquest,$whichline,
1.596.2.12.2. 6(raebur 7975:3): \@alphabet,\%record,$scantron_config,$scan_data,
7976:3): $randomorder,$randompick,$respnumlookup);
1.503 raeburn 7977: } else {
7978: $ansnum = &scantron_validator_positional($ansnum,
1.596.2.12.2. 6(raebur 7979:3): $questnum,$quest_id,$subans,$currsubquest,$whichline,
7980:3): \@alphabet,\%record,$scantron_config,$scan_data,
7981:3): $randomorder,$randompick,$respnumlookup);
1.503 raeburn 7982: }
7983: $subquestnum ++;
7984: }
7985: } else {
7986: if (($$scantron_config{'Qon'} eq 'letter') ||
7987: ($$scantron_config{'Qon'} eq 'number')) {
7988: $ansnum = &scantron_validator_lettnum($ansnum,$questnum,
7989: $quest_id,$answers_needed,$currentquest,$whichline,
1.596.2.12.2. 6(raebur 7990:3): \@alphabet,\%record,$scantron_config,$scan_data,
7991:3): $randomorder,$randompick,$respnumlookup);
1.503 raeburn 7992: } else {
7993: $ansnum = &scantron_validator_positional($ansnum,$questnum,
7994: $quest_id,$answers_needed,$currentquest,$whichline,
1.596.2.12.2. 6(raebur 7995:3): \@alphabet,\%record,$scantron_config,$scan_data,
7996:3): $randomorder,$randompick,$respnumlookup);
1.503 raeburn 7997: }
7998: }
7999: }
8000: $record{'scantron.maxquest'}=$questnum;
8001: return \%record;
8002: }
1.447 foxr 8003:
1.596.2.12.2. 6(raebur 8004:3): sub get_master_seq {
0(raebur 8005:2): my ($resources,$master_seq,$symb_to_resource,$need_symb_in_map,$symb_for_examcode) = @_;
6(raebur 8006:3): return unless ((ref($resources) eq 'ARRAY') && (ref($master_seq) eq 'ARRAY') &&
8007:3): (ref($symb_to_resource) eq 'HASH'));
0(raebur 8008:2): if ($need_symb_in_map) {
8009:2): return unless (ref($symb_for_examcode) eq 'HASH');
8010:2): }
6(raebur 8011:3): my $resource_error;
8012:3): foreach my $resource (@{$resources}) {
8013:3): my $ressymb;
8014:3): if (ref($resource)) {
8015:3): $ressymb = $resource->symb();
8016:3): push(@{$master_seq},$ressymb);
8017:3): $symb_to_resource->{$ressymb} = $resource;
0(raebur 8018:2): if ($need_symb_in_map) {
8019:2): unless ($resource->is_map()) {
8020:2): my $map=(&Apache::lonnet::decode_symb($ressymb))[0];
8021:2): unless (exists($symb_for_examcode->{$map})) {
8022:2): $symb_for_examcode->{$map} = $ressymb;
8023:2): }
8024:2): }
8025:2): }
6(raebur 8026:3): } else {
8027:3): $resource_error = 1;
8028:3): last;
8029:3): }
8030:3): }
8031:3): return $resource_error;
8032:3): }
8033:3):
8034:3): sub get_respnum_lookups {
8035:3): my ($sequence,$scan_data,$idmap,$line,$record,$master_seq,$symb_to_resource,
8036:3): $partids_by_symb,$orderedforcode,$respnumlookup,$startline) = @_;
8037:3): return unless ((ref($record) eq 'HASH') && (ref($master_seq) eq 'ARRAY') &&
8038:3): (ref($symb_to_resource) eq 'HASH') && (ref($partids_by_symb) eq 'HASH') &&
8039:3): (ref($orderedforcode) eq 'HASH') && (ref($respnumlookup) eq 'HASH') &&
8040:3): (ref($startline) eq 'HASH'));
8041:3): my ($user,$scancode);
8042:3): if ((exists($record->{'scantron.CODE'})) &&
8043:3): (&Apache::lonnet::validCODE($record->{'scantron.CODE'}))) {
8044:3): $scancode = $record->{'scantron.CODE'};
8045:3): } else {
8046:3): $user = &scantron_find_student($record,$scan_data,$idmap,$line);
8047:3): }
8048:3): my @mapresources =
8049:3): &users_order($user,$scancode,$sequence,$master_seq,$symb_to_resource,
8050:3): $orderedforcode);
8051:3): my $total = 0;
8052:3): my $count = 0;
8053:3): foreach my $resource (@mapresources) {
8054:3): my $id = $resource->id();
8055:3): my $symb = $resource->symb();
8056:3): if (ref($partids_by_symb->{$symb}) eq 'ARRAY') {
8057:3): foreach my $partid (@{$partids_by_symb->{$symb}}) {
8058:3): my $respnum = $masterseq_id_responsenum{$id.'_'.$partid};
8059:3): if ($respnum ne '') {
8060:3): $respnumlookup->{$count} = $respnum;
8061:3): $startline->{$count} = $total;
8062:3): $total += $bubble_lines_per_response{$respnum};
8063:3): $count ++;
8064:3): }
8065:3): }
8066:3): }
8067:3): }
8068:3): return $total;
8069:3): }
8070:3):
1.503 raeburn 8071: sub scantron_validator_lettnum {
8072: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,$whichline,
1.596.2.12.2. 6(raebur 8073:3): $alphabet,$record,$scantron_config,$scan_data,$randomorder,
8074:3): $randompick,$respnumlookup) = @_;
1.503 raeburn 8075:
8076: # Qon 'letter' implies for each slot in currquest we have:
8077: # ? or * for doubles, a letter in A-Z for a bubble, and
8078: # about anything else (esp. a value of Qoff) for missing
8079: # bubbles.
8080: #
8081: # Qon 'number' implies each slot gives a digit that indexes the
8082: # bubbles filled, or Qoff, or a non-number for unbubbled lines,
8083: # and * or ? for double bubbles on a single line.
8084: #
1.447 foxr 8085:
1.503 raeburn 8086: my $matchon;
8087: if ($$scantron_config{'Qon'} eq 'letter') {
8088: $matchon = '[A-Z]';
8089: } elsif ($$scantron_config{'Qon'} eq 'number') {
8090: $matchon = '\d';
8091: }
8092: my $occurrences = 0;
1.596.2.12.2. 6(raebur 8093:3): my $responsenum = $questnum-1;
8094:3): if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
8095:3): $responsenum = $respnumlookup->{$questnum-1}
8096:3): }
8097:3): if (($responsetype_per_response{$responsenum} eq 'essayresponse') ||
8098:3): ($responsetype_per_response{$responsenum} eq 'formularesponse') ||
8099:3): ($responsetype_per_response{$responsenum} eq 'stringresponse') ||
8100:3): ($responsetype_per_response{$responsenum} eq 'imageresponse') ||
8101:3): ($responsetype_per_response{$responsenum} eq 'reactionresponse') ||
8102:3): ($responsetype_per_response{$responsenum} eq 'organicresponse')) {
1.503 raeburn 8103: my @singlelines = split('',$currquest);
8104: foreach my $entry (@singlelines) {
8105: $occurrences = &occurence_count($entry,$matchon);
8106: if ($occurrences > 1) {
8107: last;
8108: }
1.596.2.12.2. 6(raebur 8109:3): }
1.503 raeburn 8110: } else {
8111: $occurrences = &occurence_count($currquest,$matchon);
8112: }
8113: if (($currquest =~ /\?/ || $currquest =~ /\*/) || ($occurrences > 1)) {
8114: push(@{$record->{'scantron.doubleerror'}},$quest_id);
8115: for (my $ans=0; $ans<$answers_needed; $ans++) {
8116: my $bubble = substr($currquest,$ans,1);
8117: if ($bubble =~ /$matchon/ ) {
8118: if ($$scantron_config{'Qon'} eq 'number') {
8119: if ($bubble == 0) {
8120: $bubble = 10;
8121: }
8122: $record->{"scantron.$ansnum.answer"} =
8123: $alphabet->[$bubble-1];
8124: } else {
8125: $record->{"scantron.$ansnum.answer"} = $bubble;
8126: }
8127: } else {
8128: $record->{"scantron.$ansnum.answer"}='';
8129: }
8130: $ansnum++;
8131: }
8132: } elsif (!defined($currquest)
8133: || (&occurence_count($currquest, $$scantron_config{'Qoff'}) == length($currquest))
8134: || (&occurence_count($currquest,$matchon) == 0)) {
8135: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
8136: $record->{"scantron.$ansnum.answer"}='';
8137: $ansnum++;
8138: }
8139: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
8140: push(@{$record->{'scantron.missingerror'}},$quest_id);
8141: }
8142: } else {
8143: if ($$scantron_config{'Qon'} eq 'number') {
8144: $currquest = &digits_to_letters($currquest);
8145: }
8146: for (my $ans=0; $ans<$answers_needed; $ans++) {
8147: my $bubble = substr($currquest,$ans,1);
8148: $record->{"scantron.$ansnum.answer"} = $bubble;
8149: $ansnum++;
8150: }
8151: }
8152: return $ansnum;
8153: }
1.447 foxr 8154:
1.503 raeburn 8155: sub scantron_validator_positional {
8156: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,
1.596.2.12.2. 6(raebur 8157:3): $whichline,$alphabet,$record,$scantron_config,$scan_data,
8158:3): $randomorder,$randompick,$respnumlookup) = @_;
1.447 foxr 8159:
1.503 raeburn 8160: # Otherwise there's a positional notation;
8161: # each bubble line requires Qlength items, and there are filled in
8162: # bubbles for each case where there 'Qon' characters.
8163: #
1.447 foxr 8164:
1.503 raeburn 8165: my @array=split($$scantron_config{'Qon'},$currquest,-1);
1.447 foxr 8166:
1.503 raeburn 8167: # If the split only gives us one element.. the full length of the
8168: # answer string, no bubbles are filled in:
1.447 foxr 8169:
1.507 raeburn 8170: if ($answers_needed eq '') {
8171: return;
8172: }
8173:
1.503 raeburn 8174: if (length($array[0]) eq $$scantron_config{'Qlength'}*$answers_needed) {
8175: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
8176: $record->{"scantron.$ansnum.answer"}='';
8177: $ansnum++;
8178: }
8179: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
8180: push(@{$record->{"scantron.missingerror"}},$quest_id);
8181: }
8182: } elsif (scalar(@array) == 2) {
8183: my $location = length($array[0]);
8184: my $line_num = int($location / $$scantron_config{'Qlength'});
8185: my $bubble = $alphabet->[$location % $$scantron_config{'Qlength'}];
8186: for (my $ans=0; $ans<$answers_needed; $ans++) {
8187: if ($ans eq $line_num) {
8188: $record->{"scantron.$ansnum.answer"} = $bubble;
8189: } else {
8190: $record->{"scantron.$ansnum.answer"} = ' ';
8191: }
8192: $ansnum++;
8193: }
8194: } else {
8195: # If there's more than one instance of a bubble character
8196: # That's a double bubble; with positional notation we can
8197: # record all the bubbles filled in as well as the
8198: # fact this response consists of multiple bubbles.
8199: #
1.596.2.12.2. 6(raebur 8200:3): my $responsenum = $questnum-1;
8201:3): if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
8202:3): $responsenum = $respnumlookup->{$questnum-1}
8203:3): }
8204:3): if (($responsetype_per_response{$responsenum} eq 'essayresponse') ||
8205:3): ($responsetype_per_response{$responsenum} eq 'formularesponse') ||
8206:3): ($responsetype_per_response{$responsenum} eq 'stringresponse') ||
8207:3): ($responsetype_per_response{$responsenum} eq 'imageresponse') ||
8208:3): ($responsetype_per_response{$responsenum} eq 'reactionresponse') ||
8209:3): ($responsetype_per_response{$responsenum} eq 'organicresponse')) {
1.503 raeburn 8210: my $doubleerror = 0;
8211: while (($currquest >= $$scantron_config{'Qlength'}) &&
8212: (!$doubleerror)) {
8213: my $currline = substr($currquest,0,$$scantron_config{'Qlength'});
8214: $currquest = substr($currquest,$$scantron_config{'Qlength'});
8215: my @currarray = split($$scantron_config{'Qon'},$currline,-1);
8216: if (length(@currarray) > 2) {
8217: $doubleerror = 1;
8218: }
8219: }
8220: if ($doubleerror) {
8221: push(@{$record->{'scantron.doubleerror'}},$quest_id);
8222: }
8223: } else {
8224: push(@{$record->{'scantron.doubleerror'}},$quest_id);
8225: }
8226: my $item = $ansnum;
8227: for (my $ans=0; $ans<$answers_needed; $ans++) {
8228: $record->{"scantron.$item.answer"} = '';
8229: $item ++;
8230: }
1.447 foxr 8231:
1.503 raeburn 8232: my @ans=@array;
8233: my $i=0;
8234: my $increment = 0;
8235: while ($#ans) {
8236: $i+=length($ans[0]) + $increment;
8237: my $line = int($i/$$scantron_config{'Qlength'} + $ansnum);
8238: my $bubble = $i%$$scantron_config{'Qlength'};
8239: $record->{"scantron.$line.answer"}.=$alphabet->[$bubble];
8240: shift(@ans);
8241: $increment = 1;
8242: }
8243: $ansnum += $answers_needed;
1.82 albertel 8244: }
1.503 raeburn 8245: return $ansnum;
1.82 albertel 8246: }
8247:
1.423 albertel 8248: =pod
8249:
8250: =item scantron_add_delay
8251:
8252: Adds an error message that occurred during the grading phase to a
8253: queue of messages to be shown after grading pass is complete
8254:
8255: Arguments:
1.424 albertel 8256: $delayqueue - arrary ref of hash ref of error messages
1.423 albertel 8257: $scanline - the scanline that caused the error
8258: $errormesage - the error message
8259: $errorcode - a numeric code for the error
8260:
8261: Side Effects:
1.424 albertel 8262: updates the $delayqueue to have a new hash ref of the error
1.423 albertel 8263:
8264: =cut
8265:
1.82 albertel 8266: sub scantron_add_delay {
1.140 albertel 8267: my ($delayqueue,$scanline,$errormessage,$errorcode)=@_;
8268: push(@$delayqueue,
8269: {'line' => $scanline, 'emsg' => $errormessage,
8270: 'ecode' => $errorcode }
8271: );
1.82 albertel 8272: }
8273:
1.423 albertel 8274: =pod
8275:
8276: =item scantron_find_student
8277:
1.424 albertel 8278: Finds the username for the current scanline
8279:
8280: Arguments:
8281: $scantron_record - hash result from scantron_parse_scanline
8282: $scan_data - hash of correction information
8283: (see &scantron_getfile() form more information)
8284: $idmap - hash from &username_to_idmap()
8285: $line - number of current scanline
8286:
8287: Returns:
8288: Either 'username:domain' or undef if unknown
8289:
1.423 albertel 8290: =cut
8291:
1.82 albertel 8292: sub scantron_find_student {
1.157 albertel 8293: my ($scantron_record,$scan_data,$idmap,$line)=@_;
1.83 albertel 8294: my $scanID=$$scantron_record{'scantron.ID'};
1.157 albertel 8295: if ($scanID =~ /^\s*$/) {
8296: return &scan_data($scan_data,"$line.user");
8297: }
1.83 albertel 8298: foreach my $id (keys(%$idmap)) {
1.157 albertel 8299: if (lc($id) eq lc($scanID)) {
8300: return $$idmap{$id};
8301: }
1.83 albertel 8302: }
8303: return undef;
8304: }
8305:
1.423 albertel 8306: =pod
8307:
8308: =item scantron_filter
8309:
1.424 albertel 8310: Filter sub for lonnavmaps, filters out hidden resources if ignore
8311: hidden resources was selected
8312:
1.423 albertel 8313: =cut
8314:
1.83 albertel 8315: sub scantron_filter {
8316: my ($curres)=@_;
1.331 albertel 8317:
8318: if (ref($curres) && $curres->is_problem()) {
8319: # if the user has asked to not have either hidden
8320: # or 'randomout' controlled resources to be graded
8321: # don't include them
8322: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
8323: && $curres->randomout) {
8324: return 0;
8325: }
1.83 albertel 8326: return 1;
8327: }
8328: return 0;
1.82 albertel 8329: }
8330:
1.423 albertel 8331: =pod
8332:
8333: =item scantron_process_corrections
8334:
1.424 albertel 8335: Gets correction information out of submitted form data and corrects
8336: the scanline
8337:
1.423 albertel 8338: =cut
8339:
1.157 albertel 8340: sub scantron_process_corrections {
8341: my ($r) = @_;
1.596.2.12.2. 9(raebur 8342:9): my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.157 albertel 8343: my ($scanlines,$scan_data)=&scantron_getfile();
8344: my $classlist=&Apache::loncoursedata::get_classlist();
1.257 albertel 8345: my $which=$env{'form.scantron_line'};
1.200 albertel 8346: my $line=&scantron_get_line($scanlines,$scan_data,$which);
1.157 albertel 8347: my ($skip,$err,$errmsg);
1.257 albertel 8348: if ($env{'form.scantron_skip_record'}) {
1.157 albertel 8349: $skip=1;
1.257 albertel 8350: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)ID$/) {
8351: my $newstudent=$env{'form.scantron_username'}.':'.
8352: $env{'form.scantron_domain'};
1.157 albertel 8353: my $newid=$classlist->{$newstudent}->[&Apache::loncoursedata::CL_ID];
8354: ($line,$err,$errmsg)=
8355: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
8356: 'ID',{'newid'=>$newid,
1.257 albertel 8357: 'username'=>$env{'form.scantron_username'},
8358: 'domain'=>$env{'form.scantron_domain'}});
8359: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)CODE$/) {
8360: my $resolution=$env{'form.scantron_CODE_resolution'};
1.190 albertel 8361: my $newCODE;
1.192 albertel 8362: my %args;
1.190 albertel 8363: if ($resolution eq 'use_unfound') {
1.191 albertel 8364: $newCODE='use_unfound';
1.190 albertel 8365: } elsif ($resolution eq 'use_found') {
1.257 albertel 8366: $newCODE=$env{'form.scantron_CODE_selectedvalue'};
1.190 albertel 8367: } elsif ($resolution eq 'use_typed') {
1.257 albertel 8368: $newCODE=$env{'form.scantron_CODE_newvalue'};
1.194 albertel 8369: } elsif ($resolution =~ /^use_closest_(\d+)/) {
1.257 albertel 8370: $newCODE=$env{"form.scantron_CODE_closest_$1"};
1.190 albertel 8371: }
1.257 albertel 8372: if ($env{'form.scantron_corrections'} eq 'duplicateCODE') {
1.192 albertel 8373: $args{'CODE_ignore_dup'}=1;
8374: }
8375: $args{'CODE'}=$newCODE;
1.186 albertel 8376: ($line,$err,$errmsg)=
8377: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
1.192 albertel 8378: 'CODE',\%args);
1.257 albertel 8379: } elsif ($env{'form.scantron_corrections'} =~ /^(missing|double)bubble$/) {
8380: foreach my $question (split(',',$env{'form.scantron_questions'})) {
1.157 albertel 8381: ($line,$err,$errmsg)=
8382: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,
8383: $which,'answer',
8384: { 'question'=>$question,
1.503 raeburn 8385: 'response'=>$env{"form.scantron_correct_Q_$question"},
8386: 'questionnum'=>$env{"form.scantron_questionnum_Q_$question"}});
1.157 albertel 8387: if ($err) { last; }
8388: }
8389: }
8390: if ($err) {
1.596.2.12.2. 0(raebur 8391:3): $r->print(
8392:3): '<p class="LC_error">'
8393:3): .&mt('Unable to accept last correction, an error occurred: [_1]',
8394:3): $errmsg)
1(raebur 8395:3): .'</p>');
1.157 albertel 8396: } else {
1.200 albertel 8397: &scantron_put_line($scanlines,$scan_data,$which,$line,$skip);
1.157 albertel 8398: &scantron_putfile($scanlines,$scan_data);
8399: }
8400: }
8401:
1.423 albertel 8402: =pod
8403:
8404: =item reset_skipping_status
8405:
1.424 albertel 8406: Forgets the current set of remember skipped scanlines (and thus
8407: reverts back to considering all lines in the
8408: scantron_skipped_<filename> file)
8409:
1.423 albertel 8410: =cut
8411:
1.200 albertel 8412: sub reset_skipping_status {
8413: my ($scanlines,$scan_data)=&scantron_getfile();
8414: &scan_data($scan_data,'remember_skipping',undef,1);
8415: &scantron_putfile(undef,$scan_data);
8416: }
8417:
1.423 albertel 8418: =pod
8419:
8420: =item start_skipping
8421:
1.424 albertel 8422: Marks a scanline to be skipped.
8423:
1.423 albertel 8424: =cut
8425:
1.376 albertel 8426: sub start_skipping {
1.200 albertel 8427: my ($scan_data,$i)=@_;
8428: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 8429: if ($env{'form.scantron_options_redo'} =~ /^redo_/) {
8430: $remembered{$i}=2;
8431: } else {
8432: $remembered{$i}=1;
8433: }
1.200 albertel 8434: &scan_data($scan_data,'remember_skipping',join(':',%remembered));
8435: }
8436:
1.423 albertel 8437: =pod
8438:
8439: =item should_be_skipped
8440:
1.424 albertel 8441: Checks whether a scanline should be skipped.
8442:
1.423 albertel 8443: =cut
8444:
1.200 albertel 8445: sub should_be_skipped {
1.376 albertel 8446: my ($scanlines,$scan_data,$i)=@_;
1.257 albertel 8447: if ($env{'form.scantron_options_redo'} !~ /^redo_/) {
1.200 albertel 8448: # not redoing old skips
1.376 albertel 8449: if ($scanlines->{'skipped'}[$i]) { return 1; }
1.200 albertel 8450: return 0;
8451: }
8452: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 8453:
8454: if (exists($remembered{$i}) && $remembered{$i} != 2 ) {
8455: return 0;
8456: }
1.200 albertel 8457: return 1;
8458: }
8459:
1.423 albertel 8460: =pod
8461:
8462: =item remember_current_skipped
8463:
1.424 albertel 8464: Discovers what scanlines are in the scantron_skipped_<filename>
8465: file and remembers them into scan_data for later use.
8466:
1.423 albertel 8467: =cut
8468:
1.200 albertel 8469: sub remember_current_skipped {
8470: my ($scanlines,$scan_data)=&scantron_getfile();
8471: my %to_remember;
8472: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
8473: if ($scanlines->{'skipped'}[$i]) {
8474: $to_remember{$i}=1;
8475: }
8476: }
1.376 albertel 8477:
1.200 albertel 8478: &scan_data($scan_data,'remember_skipping',join(':',%to_remember));
8479: &scantron_putfile(undef,$scan_data);
8480: }
8481:
1.423 albertel 8482: =pod
8483:
8484: =item check_for_error
8485:
1.424 albertel 8486: Checks if there was an error when attempting to remove a specific
1.596.2.6 raeburn 8487: scantron_.. bubblesheet data file. Prints out an error if
1.424 albertel 8488: something went wrong.
8489:
1.423 albertel 8490: =cut
8491:
1.200 albertel 8492: sub check_for_error {
8493: my ($r,$result)=@_;
8494: if ($result ne 'ok' && $result ne 'not_found' ) {
1.492 albertel 8495: $r->print(&mt("An error occurred ([_1]) when trying to remove the existing corrections.",$result));
1.200 albertel 8496: }
8497: }
1.157 albertel 8498:
1.423 albertel 8499: =pod
8500:
8501: =item scantron_warning_screen
8502:
1.424 albertel 8503: Interstitial screen to make sure the operator has selected the
8504: correct options before we start the validation phase.
8505:
1.423 albertel 8506: =cut
8507:
1.203 albertel 8508: sub scantron_warning_screen {
1.596.2.12.2. 1(raebur 8509:0): my ($button_text,$symb)=@_;
1.257 albertel 8510: my $title=&Apache::lonnet::gettitle($env{'form.selectpage'});
1.596.2.12.2. 9(raebur 8511:9): my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.373 albertel 8512: my $CODElist;
1.284 albertel 8513: if ($scantron_config{'CODElocation'} &&
8514: $scantron_config{'CODEstart'} &&
8515: $scantron_config{'CODElength'}) {
8516: $CODElist=$env{'form.scantron_CODElist'};
1.596.2.12.2. 8(raebur 8517:4): if ($env{'form.scantron_CODElist'} eq '') { $CODElist='<span class="LC_warning">'.&mt('None').'</span>'; }
1.284 albertel 8518: $CODElist=
1.492 albertel 8519: '<tr><td><b>'.&mt('List of CODES to validate against:').'</b></td><td><tt>'.
1.373 albertel 8520: $env{'form.scantron_CODElist'}.'</tt></td></tr>';
1.284 albertel 8521: }
1.596.2.12.2. (raeburn 8522:): my $lastbubblepoints;
8523:): if ($env{'form.scantron_lastbubblepoints'} ne '') {
8524:): $lastbubblepoints =
8525:): '<tr><td><b>'.&mt('Hand-graded items: points from last bubble in row').'</b></td><td><tt>'.
8526:): $env{'form.scantron_lastbubblepoints'}.'</tt></td></tr>';
8527:): }
1.492 albertel 8528: return ('
1.203 albertel 8529: <p>
1.492 albertel 8530: <span class="LC_warning">
1.596.2.12.2. 6(raebur 8531:3): '.&mt("Please double check the information below before clicking on '[_1]'",&mt($button_text)).'</span>
1.203 albertel 8532: </p>
8533: <table>
1.492 albertel 8534: <tr><td><b>'.&mt('Sequence to be Graded:').'</b></td><td>'.$title.'</td></tr>
8535: <tr><td><b>'.&mt('Data File that will be used:').'</b></td><td><tt>'.$env{'form.scantron_selectfile'}.'</tt></td></tr>
1.596.2.12.2. (raeburn 8536:): '.$CODElist.$lastbubblepoints.'
1.203 albertel 8537: </table>
1.596.2.12.2. 1(raebur 8538:0): <p> '.&mt("If this information is correct, please click on '[_1]'.",&mt($button_text)).'<br />
8539:0): '.&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.203 albertel 8540:
8541: <br />
1.492 albertel 8542: ');
1.203 albertel 8543: }
8544:
1.423 albertel 8545: =pod
8546:
8547: =item scantron_do_warning
8548:
1.424 albertel 8549: Check if the operator has picked something for all required
8550: fields. Error out if something is missing.
8551:
1.423 albertel 8552: =cut
8553:
1.203 albertel 8554: sub scantron_do_warning {
1.596.2.12.2. 1(raebur 8555:0): my ($r,$symb)=@_;
1.203 albertel 8556: if (!$symb) {return '';}
1.324 albertel 8557: my $default_form_data=&defaultFormData($symb);
1.203 albertel 8558: $r->print(&scantron_form_start().$default_form_data);
1.257 albertel 8559: if ( $env{'form.selectpage'} eq '' ||
8560: $env{'form.scantron_selectfile'} eq '' ||
8561: $env{'form.scantron_format'} eq '' ) {
1.596.2.4 raeburn 8562: $r->print("<p>".&mt('You have forgotten to specify some information. Please go Back and try again.')."</p>");
1.257 albertel 8563: if ( $env{'form.selectpage'} eq '') {
1.492 albertel 8564: $r->print('<p><span class="LC_error">'.&mt('You have not selected a Sequence to grade').'</span></p>');
1.237 albertel 8565: }
1.257 albertel 8566: if ( $env{'form.scantron_selectfile'} eq '') {
1.596.2.4 raeburn 8567: $r->print('<p><span class="LC_error">'.&mt("You have not selected a file that contains the student's response data.").'</span></p>');
1.237 albertel 8568: }
1.257 albertel 8569: if ( $env{'form.scantron_format'} eq '') {
1.596.2.5 raeburn 8570: $r->print('<p><span class="LC_error">'.&mt("You have not selected the format of the student's response data.").'</span></p>');
1.237 albertel 8571: }
8572: } else {
1.596.2.12.2. 1(raebur 8573:0): my $warning=&scantron_warning_screen('Grading: Validate Records',$symb);
(raeburn 8574:): my $bubbledbyhand=&hand_bubble_option();
1.492 albertel 8575: $r->print('
1.596.2.12.2. (raeburn 8576:): '.$warning.$bubbledbyhand.'
1.492 albertel 8577: <input type="submit" name="submit" value="'.&mt('Grading: Validate Records').'" />
1.203 albertel 8578: <input type="hidden" name="command" value="scantron_validate" />
1.492 albertel 8579: ');
1.237 albertel 8580: }
1.596.2.12.2. 1(raebur 8581:0): $r->print("</form><br />");
1.203 albertel 8582: return '';
8583: }
8584:
1.423 albertel 8585: =pod
8586:
8587: =item scantron_form_start
8588:
1.424 albertel 8589: html hidden input for remembering all selected grading options
8590:
1.423 albertel 8591: =cut
8592:
1.203 albertel 8593: sub scantron_form_start {
8594: my ($max_bubble)=@_;
8595: my $result= <<SCANTRONFORM;
8596: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
1.257 albertel 8597: <input type="hidden" name="selectpage" value="$env{'form.selectpage'}" />
8598: <input type="hidden" name="scantron_format" value="$env{'form.scantron_format'}" />
8599: <input type="hidden" name="scantron_selectfile" value="$env{'form.scantron_selectfile'}" />
1.218 albertel 8600: <input type="hidden" name="scantron_maxbubble" value="$max_bubble" />
1.257 albertel 8601: <input type="hidden" name="scantron_CODElist" value="$env{'form.scantron_CODElist'}" />
8602: <input type="hidden" name="scantron_CODEunique" value="$env{'form.scantron_CODEunique'}" />
8603: <input type="hidden" name="scantron_options_redo" value="$env{'form.scantron_options_redo'}" />
8604: <input type="hidden" name="scantron_options_ignore" value="$env{'form.scantron_options_ignore'}" />
1.331 albertel 8605: <input type="hidden" name="scantron_options_hidden" value="$env{'form.scantron_options_hidden'}" />
1.203 albertel 8606: SCANTRONFORM
1.447 foxr 8607:
8608: my $line = 0;
8609: while (defined($env{"form.scantron.bubblelines.$line"})) {
8610: my $chunk =
8611: '<input type="hidden" name="scantron.bubblelines.'.$line.'" value="'.$env{"form.scantron.bubblelines.$line"}.'" />'."\n";
1.448 foxr 8612: $chunk .=
8613: '<input type="hidden" name="scantron.first_bubble_line.'.$line.'" value="'.$env{"form.scantron.first_bubble_line.$line"}.'" />'."\n";
1.503 raeburn 8614: $chunk .=
8615: '<input type="hidden" name="scantron.sub_bubblelines.'.$line.'" value="'.$env{"form.scantron.sub_bubblelines.$line"}.'" />'."\n";
1.504 raeburn 8616: $chunk .=
8617: '<input type="hidden" name="scantron.responsetype.'.$line.'" value="'.$env{"form.scantron.responsetype.$line"}.'" />'."\n";
1.596.2.12.2. 6(raebur 8618:3): $chunk .=
8619:3): '<input type="hidden" name="scantron.residpart.'.$line.'" value="'.$env{"form.scantron.residpart.$line"}.'" />'."\n";
1.447 foxr 8620: $result .= $chunk;
8621: $line++;
1.596.2.12.2. 6(raebur 8622:3): }
1.203 albertel 8623: return $result;
8624: }
8625:
1.423 albertel 8626: =pod
8627:
8628: =item scantron_validate_file
8629:
1.596.2.6 raeburn 8630: Dispatch routine for doing validation of a bubblesheet data file.
1.424 albertel 8631:
8632: Also processes any necessary information resets that need to
8633: occur before validation begins (ignore previous corrections,
8634: restarting the skipped records processing)
8635:
1.423 albertel 8636: =cut
8637:
1.157 albertel 8638: sub scantron_validate_file {
1.596.2.12.2. 1(raebur 8639:0): my ($r,$symb) = @_;
1.157 albertel 8640: if (!$symb) {return '';}
1.324 albertel 8641: my $default_form_data=&defaultFormData($symb);
1.200 albertel 8642:
1.596.2.12.2. 0(raebur 8643:3): # do the detection of only doing skipped records first before we delete
1.424 albertel 8644: # them when doing the corrections reset
1.257 albertel 8645: if ($env{'form.scantron_options_redo'} ne 'redo_skipped_ready') {
1.200 albertel 8646: &reset_skipping_status();
8647: }
1.257 albertel 8648: if ($env{'form.scantron_options_redo'} eq 'redo_skipped') {
1.200 albertel 8649: &remember_current_skipped();
1.257 albertel 8650: $env{'form.scantron_options_redo'}='redo_skipped_ready';
1.200 albertel 8651: }
8652:
1.257 albertel 8653: if ($env{'form.scantron_options_ignore'} eq 'ignore_corrections') {
1.200 albertel 8654: &check_for_error($r,&scantron_remove_file('corrected'));
8655: &check_for_error($r,&scantron_remove_file('skipped'));
8656: &check_for_error($r,&scantron_remove_scan_data());
1.257 albertel 8657: $env{'form.scantron_options_ignore'}='done';
1.192 albertel 8658: }
1.200 albertel 8659:
1.257 albertel 8660: if ($env{'form.scantron_corrections'}) {
1.157 albertel 8661: &scantron_process_corrections($r);
8662: }
1.503 raeburn 8663: $r->print('<p>'.&mt('Gathering necessary information.').'</p>');$r->rflush();
1.157 albertel 8664: #get the student pick code ready
8665: $r->print(&Apache::loncommon::studentbrowser_javascript());
1.582 raeburn 8666: my $nav_error;
1.596.2.12.2. 9(raebur 8667:9): my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
(raeburn 8668:): my $max_bubble=&scantron_get_maxbubble(\$nav_error,\%scantron_config);
1.582 raeburn 8669: if ($nav_error) {
8670: $r->print(&navmap_errormsg());
8671: return '';
8672: }
1.203 albertel 8673: my $result=&scantron_form_start($max_bubble).$default_form_data;
1.596.2.12.2. (raeburn 8674:): if ($env{'form.scantron_lastbubblepoints'} ne '') {
8675:): $result .= '<input type="hidden" name="scantron_lastbubblepoints" value="'.$env{'form.scantron_lastbubblepoints'}.'" />';
8676:): }
1.157 albertel 8677: $r->print($result);
8678:
1.334 albertel 8679: my @validate_phases=( 'sequence',
8680: 'ID',
1.157 albertel 8681: 'CODE',
8682: 'doublebubble',
8683: 'missingbubbles');
1.257 albertel 8684: if (!$env{'form.validatepass'}) {
8685: $env{'form.validatepass'} = 0;
1.157 albertel 8686: }
1.257 albertel 8687: my $currentphase=$env{'form.validatepass'};
1.157 albertel 8688:
1.448 foxr 8689:
1.157 albertel 8690: my $stop=0;
8691: while (!$stop && $currentphase < scalar(@validate_phases)) {
1.503 raeburn 8692: $r->print(&mt('Validating '.$validate_phases[$currentphase]).'<br />');
1.157 albertel 8693: $r->rflush();
1.596.2.12.2. 6(raebur 8694:3):
1.157 albertel 8695: my $which="scantron_validate_".$validate_phases[$currentphase];
8696: {
8697: no strict 'refs';
8698: ($stop,$currentphase)=&$which($r,$currentphase);
8699: }
8700: }
8701: if (!$stop) {
1.596.2.12.2. 1(raebur 8702:0): my $warning=&scantron_warning_screen('Start Grading',$symb);
1.542 raeburn 8703: $r->print(&mt('Validation process complete.').'<br />'.
8704: $warning.
8705: &mt('Perform verification for each student after storage of submissions?').
8706: ' <span class="LC_nobreak"><label>'.
8707: '<input type="radio" name="verifyrecord" value="1" />'.&mt('Yes').'</label>'.
8708: (' 'x3).'<label>'.
8709: '<input type="radio" name="verifyrecord" value="0" checked="checked" />'.&mt('No').
8710: '</label></span><br />'.
8711: &mt('Grading will take longer if you use verification.').'<br />'.
1.596.2.12.2. 1(raebur 8712:0): &mt('Otherwise, Grade/Manage/Review Bubblesheets [_1] Review bubblesheet data can be used once grading is complete.','»').'<br /><br />'.
1.542 raeburn 8713: '<input type="submit" name="submit" value="'.&mt('Start Grading').'" />'.
8714: '<input type="hidden" name="command" value="scantron_process" />'."\n");
1.157 albertel 8715: } else {
8716: $r->print('<input type="hidden" name="command" value="scantron_validate" />');
8717: $r->print("<input type='hidden' name='validatepass' value='".$currentphase."' />");
8718: }
8719: if ($stop) {
1.334 albertel 8720: if ($validate_phases[$currentphase] eq 'sequence') {
1.539 riegler 8721: $r->print('<input type="submit" name="submit" value="'.&mt('Ignore').' → " />');
1.492 albertel 8722: $r->print(' '.&mt('this error').' <br />');
1.334 albertel 8723:
1.596.2.12.2. 1(raebur 8724:0): $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 8725: } else {
1.503 raeburn 8726: if ($validate_phases[$currentphase] eq 'doublebubble' || $validate_phases[$currentphase] eq 'missingbubbles') {
1.539 riegler 8727: $r->print('<input type="button" name="submitbutton" value="'.&mt('Continue').' →" onclick="javascript:verify_bubble_radio(this.form)" />');
1.503 raeburn 8728: } else {
1.539 riegler 8729: $r->print('<input type="submit" name="submit" value="'.&mt('Continue').' →" />');
1.503 raeburn 8730: }
1.492 albertel 8731: $r->print(' '.&mt('using corrected info').' <br />');
8732: $r->print("<input type='submit' value='".&mt("Skip")."' name='scantron_skip_record' />");
8733: $r->print(" ".&mt("this scanline saving it for later."));
1.334 albertel 8734: }
1.157 albertel 8735: }
1.596.2.12.2. 1(raebur 8736:0): $r->print(" </form><br />");
1.157 albertel 8737: return '';
8738: }
8739:
1.423 albertel 8740:
8741: =pod
8742:
8743: =item scantron_remove_file
8744:
1.596.2.6 raeburn 8745: Removes the requested bubblesheet data file, makes sure that
1.424 albertel 8746: scantron_original_<filename> is never removed
8747:
8748:
1.423 albertel 8749: =cut
8750:
1.200 albertel 8751: sub scantron_remove_file {
1.192 albertel 8752: my ($which)=@_;
1.257 albertel 8753: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
8754: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 8755: my $file='scantron_';
1.200 albertel 8756: if ($which eq 'corrected' || $which eq 'skipped') {
8757: $file.=$which.'_';
1.192 albertel 8758: } else {
8759: return 'refused';
8760: }
1.257 albertel 8761: $file.=$env{'form.scantron_selectfile'};
1.200 albertel 8762: return &Apache::lonnet::removeuserfile($cname,$cdom,$file);
8763: }
8764:
1.423 albertel 8765:
8766: =pod
8767:
8768: =item scantron_remove_scan_data
8769:
1.596.2.6 raeburn 8770: Removes all scan_data correction for the requested bubblesheet
1.424 albertel 8771: data file. (In the case that both the are doing skipped records we need
8772: to remember the old skipped lines for the time being so that element
8773: persists for a while.)
8774:
1.423 albertel 8775: =cut
8776:
1.200 albertel 8777: sub scantron_remove_scan_data {
1.257 albertel 8778: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
8779: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 8780: my @keys=&Apache::lonnet::getkeys('nohist_scantrondata',$cdom,$cname);
8781: my @todelete;
1.257 albertel 8782: my $filename=$env{'form.scantron_selectfile'};
1.192 albertel 8783: foreach my $key (@keys) {
8784: if ($key=~/^\Q$filename\E_/) {
1.257 albertel 8785: if ($env{'form.scantron_options_redo'} eq 'redo_skipped_ready' &&
1.200 albertel 8786: $key=~/remember_skipping/) {
8787: next;
8788: }
1.192 albertel 8789: push(@todelete,$key);
8790: }
8791: }
1.200 albertel 8792: my $result;
1.192 albertel 8793: if (@todelete) {
1.491 albertel 8794: $result = &Apache::lonnet::del('nohist_scantrondata',
8795: \@todelete,$cdom,$cname);
8796: } else {
8797: $result = 'ok';
1.192 albertel 8798: }
8799: return $result;
8800: }
8801:
1.423 albertel 8802:
8803: =pod
8804:
8805: =item scantron_getfile
8806:
1.596.2.6 raeburn 8807: Fetches the requested bubblesheet data file (all 3 versions), and
1.424 albertel 8808: the scan_data hash
8809:
8810: Arguments:
8811: None
8812:
8813: Returns:
8814: 2 hash references
8815:
8816: - first one has
8817: orig -
8818: corrected -
8819: skipped - each of which points to an array ref of the specified
8820: file broken up into individual lines
8821: count - number of scanlines
8822:
8823: - second is the scan_data hash possible keys are
1.425 albertel 8824: ($number refers to scanline numbered $number and thus the key affects
8825: only that scanline
8826: $bubline refers to the specific bubble line element and the aspects
8827: refers to that specific bubble line element)
8828:
8829: $number.user - username:domain to use
8830: $number.CODE_ignore_dup
8831: - ignore the duplicate CODE error
8832: $number.useCODE
8833: - use the CODE in the scanline as is
8834: $number.no_bubble.$bubline
8835: - it is valid that there is no bubbled in bubble
8836: at $number $bubline
8837: remember_skipping
8838: - a frozen hash containing keys of $number and values
8839: of either
8840: 1 - we are on a 'do skipped records pass' and plan
8841: on processing this line
8842: 2 - we are on a 'do skipped records pass' and this
8843: scanline has been marked to skip yet again
1.424 albertel 8844:
1.423 albertel 8845: =cut
8846:
1.157 albertel 8847: sub scantron_getfile {
1.200 albertel 8848: #FIXME really would prefer a scantron directory
1.257 albertel 8849: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
8850: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.157 albertel 8851: my $lines;
8852: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 8853: 'scantron_orig_'.$env{'form.scantron_selectfile'});
1.157 albertel 8854: my %scanlines;
8855: $scanlines{'orig'}=[(split("\n",$lines,-1))];
8856: my $temp=$scanlines{'orig'};
8857: $scanlines{'count'}=$#$temp;
8858:
8859: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 8860: 'scantron_corrected_'.$env{'form.scantron_selectfile'});
1.157 albertel 8861: if ($lines eq '-1') {
8862: $scanlines{'corrected'}=[];
8863: } else {
8864: $scanlines{'corrected'}=[(split("\n",$lines,-1))];
8865: }
8866: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 8867: 'scantron_skipped_'.$env{'form.scantron_selectfile'});
1.157 albertel 8868: if ($lines eq '-1') {
8869: $scanlines{'skipped'}=[];
8870: } else {
8871: $scanlines{'skipped'}=[(split("\n",$lines,-1))];
8872: }
1.175 albertel 8873: my @tmp=&Apache::lonnet::dump('nohist_scantrondata',$cdom,$cname);
1.157 albertel 8874: if ($tmp[0] =~ /^(error:|no_such_host)/) { @tmp=(); }
8875: my %scan_data = @tmp;
8876: return (\%scanlines,\%scan_data);
8877: }
8878:
1.423 albertel 8879: =pod
8880:
8881: =item lonnet_putfile
8882:
1.424 albertel 8883: Wrapper routine to call &Apache::lonnet::finishuserfileupload
8884:
8885: Arguments:
8886: $contents - data to store
8887: $filename - filename to store $contents into
8888:
8889: Returns:
8890: result value from &Apache::lonnet::finishuserfileupload
8891:
1.423 albertel 8892: =cut
8893:
1.157 albertel 8894: sub lonnet_putfile {
8895: my ($contents,$filename)=@_;
1.257 albertel 8896: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
8897: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
8898: $env{'form.sillywaytopassafilearound'}=$contents;
1.275 albertel 8899: &Apache::lonnet::finishuserfileupload($docuname,$docudom,'sillywaytopassafilearound',$filename);
1.157 albertel 8900:
8901: }
8902:
1.423 albertel 8903: =pod
8904:
8905: =item scantron_putfile
8906:
1.596.2.6 raeburn 8907: Stores the current version of the bubblesheet data files, and the
1.424 albertel 8908: scan_data hash. (Does not modify the original version only the
8909: corrected and skipped versions.
8910:
8911: Arguments:
8912: $scanlines - hash ref that looks like the first return value from
8913: &scantron_getfile()
8914: $scan_data - hash ref that looks like the second return value from
8915: &scantron_getfile()
8916:
1.423 albertel 8917: =cut
8918:
1.157 albertel 8919: sub scantron_putfile {
8920: my ($scanlines,$scan_data) = @_;
1.200 albertel 8921: #FIXME really would prefer a scantron directory
1.257 albertel 8922: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
8923: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.200 albertel 8924: if ($scanlines) {
8925: my $prefix='scantron_';
1.157 albertel 8926: # no need to update orig, shouldn't change
8927: # &lonnet_putfile(join("\n",@{$scanlines->{'orig'}}),$prefix.'orig_'.
1.257 albertel 8928: # $env{'form.scantron_selectfile'});
1.200 albertel 8929: &lonnet_putfile(join("\n",@{$scanlines->{'corrected'}}),
8930: $prefix.'corrected_'.
1.257 albertel 8931: $env{'form.scantron_selectfile'});
1.200 albertel 8932: &lonnet_putfile(join("\n",@{$scanlines->{'skipped'}}),
8933: $prefix.'skipped_'.
1.257 albertel 8934: $env{'form.scantron_selectfile'});
1.200 albertel 8935: }
1.175 albertel 8936: &Apache::lonnet::put('nohist_scantrondata',$scan_data,$cdom,$cname);
1.157 albertel 8937: }
8938:
1.423 albertel 8939: =pod
8940:
8941: =item scantron_get_line
8942:
1.424 albertel 8943: Returns the correct version of the scanline
8944:
8945: Arguments:
8946: $scanlines - hash ref that looks like the first return value from
8947: &scantron_getfile()
8948: $scan_data - hash ref that looks like the second return value from
8949: &scantron_getfile()
8950: $i - number of the requested line (starts at 0)
8951:
8952: Returns:
8953: A scanline, (either the original or the corrected one if it
8954: exists), or undef if the requested scanline should be
8955: skipped. (Either because it's an skipped scanline, or it's an
8956: unskipped scanline and we are not doing a 'do skipped scanlines'
8957: pass.
8958:
1.423 albertel 8959: =cut
8960:
1.157 albertel 8961: sub scantron_get_line {
1.200 albertel 8962: my ($scanlines,$scan_data,$i)=@_;
1.376 albertel 8963: if (&should_be_skipped($scanlines,$scan_data,$i)) { return undef; }
8964: #if ($scanlines->{'skipped'}[$i]) { return undef; }
1.157 albertel 8965: if ($scanlines->{'corrected'}[$i]) {return $scanlines->{'corrected'}[$i];}
8966: return $scanlines->{'orig'}[$i];
8967: }
8968:
1.423 albertel 8969: =pod
8970:
8971: =item scantron_todo_count
8972:
1.424 albertel 8973: Counts the number of scanlines that need processing.
8974:
8975: Arguments:
8976: $scanlines - hash ref that looks like the first return value from
8977: &scantron_getfile()
8978: $scan_data - hash ref that looks like the second return value from
8979: &scantron_getfile()
8980:
8981: Returns:
8982: $count - number of scanlines to process
8983:
1.423 albertel 8984: =cut
8985:
1.200 albertel 8986: sub get_todo_count {
8987: my ($scanlines,$scan_data)=@_;
8988: my $count=0;
8989: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
8990: my $line=&scantron_get_line($scanlines,$scan_data,$i);
8991: if ($line=~/^[\s\cz]*$/) { next; }
8992: $count++;
8993: }
8994: return $count;
8995: }
8996:
1.423 albertel 8997: =pod
8998:
8999: =item scantron_put_line
9000:
1.596.2.6 raeburn 9001: Updates the 'corrected' or 'skipped' versions of the bubblesheet
1.424 albertel 9002: data file.
9003:
9004: Arguments:
9005: $scanlines - hash ref that looks like the first return value from
9006: &scantron_getfile()
9007: $scan_data - hash ref that looks like the second return value from
9008: &scantron_getfile()
9009: $i - line number to update
9010: $newline - contents of the updated scanline
9011: $skip - if true make the line for skipping and update the
9012: 'skipped' file
9013:
1.423 albertel 9014: =cut
9015:
1.157 albertel 9016: sub scantron_put_line {
1.200 albertel 9017: my ($scanlines,$scan_data,$i,$newline,$skip)=@_;
1.157 albertel 9018: if ($skip) {
9019: $scanlines->{'skipped'}[$i]=$newline;
1.376 albertel 9020: &start_skipping($scan_data,$i);
1.157 albertel 9021: return;
9022: }
9023: $scanlines->{'corrected'}[$i]=$newline;
9024: }
9025:
1.423 albertel 9026: =pod
9027:
9028: =item scantron_clear_skip
9029:
1.424 albertel 9030: Remove a line from the 'skipped' file
9031:
9032: Arguments:
9033: $scanlines - hash ref that looks like the first return value from
9034: &scantron_getfile()
9035: $scan_data - hash ref that looks like the second return value from
9036: &scantron_getfile()
9037: $i - line number to update
9038:
1.423 albertel 9039: =cut
9040:
1.376 albertel 9041: sub scantron_clear_skip {
9042: my ($scanlines,$scan_data,$i)=@_;
9043: if (exists($scanlines->{'skipped'}[$i])) {
9044: undef($scanlines->{'skipped'}[$i]);
9045: return 1;
9046: }
9047: return 0;
9048: }
9049:
1.423 albertel 9050: =pod
9051:
9052: =item scantron_filter_not_exam
9053:
1.424 albertel 9054: Filter routine used by &Apache::lonnavmaps::retrieveResources(), to
9055: filter out resources that are not marked as 'exam' mode
9056:
1.423 albertel 9057: =cut
9058:
1.334 albertel 9059: sub scantron_filter_not_exam {
9060: my ($curres)=@_;
9061:
9062: if (ref($curres) && $curres->is_problem() && !$curres->is_exam()) {
9063: # if the user has asked to not have either hidden
9064: # or 'randomout' controlled resources to be graded
9065: # don't include them
9066: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
9067: && $curres->randomout) {
9068: return 0;
9069: }
9070: return 1;
9071: }
9072: return 0;
9073: }
9074:
1.423 albertel 9075: =pod
9076:
9077: =item scantron_validate_sequence
9078:
1.424 albertel 9079: Validates the selected sequence, checking for resource that are
9080: not set to exam mode.
9081:
1.423 albertel 9082: =cut
9083:
1.334 albertel 9084: sub scantron_validate_sequence {
9085: my ($r,$currentphase) = @_;
9086:
9087: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 9088: unless (ref($navmap)) {
9089: $r->print(&navmap_errormsg());
9090: return (1,$currentphase);
9091: }
1.334 albertel 9092: my (undef,undef,$sequence)=
9093: &Apache::lonnet::decode_symb($env{'form.selectpage'});
9094:
9095: my $map=$navmap->getResourceByUrl($sequence);
9096:
9097: $r->print('<input type="hidden" name="validate_sequence_exam"
9098: value="ignore" />');
9099: if ($env{'form.validate_sequence_exam'} ne 'ignore') {
9100: my @resources=
9101: $navmap->retrieveResources($map,\&scantron_filter_not_exam,1,0);
9102: if (@resources) {
1.596.2.12.2. 0(raebur 9103:2): $r->print('<p class="LC_warning">'
9104:2): .&mt('Some resources in the sequence currently are not set to'
9105:2): .' exam mode. Grading these resources currently may not'
9106:2): .' work correctly.')
9107:2): .'</p>'
9108:2): );
1.334 albertel 9109: return (1,$currentphase);
9110: }
9111: }
9112:
9113: return (0,$currentphase+1);
9114: }
9115:
1.423 albertel 9116:
9117:
1.157 albertel 9118: sub scantron_validate_ID {
9119: my ($r,$currentphase) = @_;
9120:
9121: #get student info
9122: my $classlist=&Apache::loncoursedata::get_classlist();
9123: my %idmap=&username_to_idmap($classlist);
9124:
9125: #get scantron line setup
1.596.2.12.2. 9(raebur 9126:9): my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.157 albertel 9127: my ($scanlines,$scan_data)=&scantron_getfile();
1.582 raeburn 9128:
9129: my $nav_error;
1.596.2.12.2. (raeburn 9130:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the bubble_lines.. array.
1.582 raeburn 9131: if ($nav_error) {
9132: $r->print(&navmap_errormsg());
9133: return(1,$currentphase);
9134: }
1.157 albertel 9135:
9136: my %found=('ids'=>{},'usernames'=>{});
9137: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 9138: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 9139: if ($line=~/^[\s\cz]*$/) { next; }
9140: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
9141: $scan_data);
9142: my $id=$$scan_record{'scantron.ID'};
9143: my $found;
9144: foreach my $checkid (keys(%idmap)) {
9145: if (lc($checkid) eq lc($id)) { $found=$checkid;last; }
9146: }
9147: if ($found) {
9148: my $username=$idmap{$found};
9149: if ($found{'ids'}{$found}) {
9150: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
9151: $line,'duplicateID',$found);
1.194 albertel 9152: return(1,$currentphase);
1.157 albertel 9153: } elsif ($found{'usernames'}{$username}) {
9154: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
9155: $line,'duplicateID',$username);
1.194 albertel 9156: return(1,$currentphase);
1.157 albertel 9157: }
1.186 albertel 9158: #FIXME store away line we previously saw the ID on to use above
1.157 albertel 9159: $found{'ids'}{$found}++;
9160: $found{'usernames'}{$username}++;
9161: } else {
9162: if ($id =~ /^\s*$/) {
1.158 albertel 9163: my $username=&scan_data($scan_data,"$i.user");
1.157 albertel 9164: if (defined($username) && $found{'usernames'}{$username}) {
9165: &scantron_get_correction($r,$i,$scan_record,
9166: \%scantron_config,
9167: $line,'duplicateID',$username);
1.194 albertel 9168: return(1,$currentphase);
1.157 albertel 9169: } elsif (!defined($username)) {
9170: &scantron_get_correction($r,$i,$scan_record,
9171: \%scantron_config,
9172: $line,'incorrectID');
1.194 albertel 9173: return(1,$currentphase);
1.157 albertel 9174: }
9175: $found{'usernames'}{$username}++;
9176: } else {
9177: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
9178: $line,'incorrectID');
1.194 albertel 9179: return(1,$currentphase);
1.157 albertel 9180: }
9181: }
9182: }
9183:
9184: return (0,$currentphase+1);
9185: }
9186:
1.423 albertel 9187:
1.157 albertel 9188: sub scantron_get_correction {
1.596.2.12.2. 6(raebur 9189:3): my ($r,$i,$scan_record,$scan_config,$line,$error,$arg,
9190:3): $randomorder,$randompick,$respnumlookup,$startline)=@_;
1.454 banghart 9191: #FIXME in the case of a duplicated ID the previous line, probably need
1.157 albertel 9192: #to show both the current line and the previous one and allow skipping
9193: #the previous one or the current one
9194:
1.333 albertel 9195: if ( $$scan_record{'scantron.PaperID'} =~ /\S/) {
1.596.2.6 raeburn 9196: $r->print(
9197: '<p class="LC_warning">'
9198: .&mt('An error was detected ([_1]) for PaperID [_2]',
9199: "<b>$error</b>",
9200: '<tt>'.$$scan_record{'scantron.PaperID'}.'</tt>')
9201: ."</p> \n");
1.157 albertel 9202: } else {
1.596.2.6 raeburn 9203: $r->print(
9204: '<p class="LC_warning">'
9205: .&mt('An error was detected ([_1]) in scanline [_2] [_3]',
9206: "<b>$error</b>", $i, "<pre>$line</pre>")
9207: ."</p> \n");
9208: }
9209: my $message =
9210: '<p>'
9211: .&mt('The ID on the form is [_1]',
9212: "<tt>$$scan_record{'scantron.ID'}</tt>")
9213: .'<br />'
1.596.2.12 raeburn 9214: .&mt('The name on the paper is [_1], [_2]',
1.596.2.6 raeburn 9215: $$scan_record{'scantron.LastName'},
9216: $$scan_record{'scantron.FirstName'})
9217: .'</p>';
1.242 albertel 9218:
1.157 albertel 9219: $r->print('<input type="hidden" name="scantron_corrections" value="'.$error.'" />'."\n");
9220: $r->print('<input type="hidden" name="scantron_line" value="'.$i.'" />'."\n");
1.503 raeburn 9221: # Array populated for doublebubble or
9222: my @lines_to_correct; # missingbubble errors to build javascript
9223: # to validate radio button checking
9224:
1.157 albertel 9225: if ($error =~ /ID$/) {
1.186 albertel 9226: if ($error eq 'incorrectID') {
1.596.2.6 raeburn 9227: $r->print('<p class="LC_warning">'.&mt("The encoded ID is not in the classlist").
1.492 albertel 9228: "</p>\n");
1.157 albertel 9229: } elsif ($error eq 'duplicateID') {
1.596.2.6 raeburn 9230: $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 9231: }
1.242 albertel 9232: $r->print($message);
1.492 albertel 9233: $r->print("<p>".&mt("How should I handle this?")." <br /> \n");
1.157 albertel 9234: $r->print("\n<ul><li> ");
9235: #FIXME it would be nice if this sent back the user ID and
9236: #could do partial userID matches
9237: $r->print(&Apache::loncommon::selectstudent_link('scantronupload',
9238: 'scantron_username','scantron_domain'));
9239: $r->print(": <input type='text' name='scantron_username' value='' />");
1.596.2.12.2. 3(raebur 9240:3): $r->print("\n:\n".
1.257 albertel 9241: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'scantron_domain'));
1.157 albertel 9242:
9243: $r->print('</li>');
1.186 albertel 9244: } elsif ($error =~ /CODE$/) {
9245: if ($error eq 'incorrectCODE') {
1.596.2.6 raeburn 9246: $r->print('<p class="LC_warning">'.&mt("The encoded CODE is not in the list of possible CODEs.")."</p>\n");
1.186 albertel 9247: } elsif ($error eq 'duplicateCODE') {
1.596.2.6 raeburn 9248: $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 9249: }
1.596.2.6 raeburn 9250: $r->print("<p>".&mt('The CODE on the form is [_1]',
9251: "<tt>'$$scan_record{'scantron.CODE'}'</tt>")
9252: ."</p>\n");
1.242 albertel 9253: $r->print($message);
1.596.2.6 raeburn 9254: $r->print("<p>".&mt("How should I handle this?")."</p>\n");
1.187 albertel 9255: $r->print("\n<br /> ");
1.194 albertel 9256: my $i=0;
1.273 albertel 9257: if ($error eq 'incorrectCODE'
9258: && $$scan_record{'scantron.CODE'}=~/\S/ ) {
1.194 albertel 9259: my ($max,$closest)=&scantron_get_closely_matching_CODEs($arg,$$scan_record{'scantron.CODE'});
1.278 albertel 9260: if ($closest > 0) {
9261: foreach my $testcode (@{$closest}) {
9262: my $checked='';
1.569 bisitz 9263: if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 9264: $r->print("
9265: <label>
1.569 bisitz 9266: <input type='radio' name='scantron_CODE_resolution' value='use_closest_$i'$checked />
1.492 albertel 9267: ".&mt("Use the similar CODE [_1] instead.",
9268: "<b><tt>".$testcode."</tt></b>")."
9269: </label>
9270: <input type='hidden' name='scantron_CODE_closest_$i' value='$testcode' />");
1.278 albertel 9271: $r->print("\n<br />");
9272: $i++;
9273: }
1.194 albertel 9274: }
9275: }
1.273 albertel 9276: if ($$scan_record{'scantron.CODE'}=~/\S/ ) {
1.569 bisitz 9277: my $checked; if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 9278: $r->print("
9279: <label>
1.569 bisitz 9280: <input type='radio' name='scantron_CODE_resolution' value='use_unfound'$checked />
1.596.2.6 raeburn 9281: ".&mt("Use the CODE [_1] that was on the paper, ignoring the error.",
1.492 albertel 9282: "<b><tt>".$$scan_record{'scantron.CODE'}."</tt></b>")."
9283: </label>");
1.273 albertel 9284: $r->print("\n<br />");
9285: }
1.194 albertel 9286:
1.596.2.12.2. 1(raebur 9287:0): $r->print(&Apache::lonhtmlcommon::scripttag(<<ENDSCRIPT));
1.188 albertel 9288: function change_radio(field) {
1.190 albertel 9289: var slct=document.scantronupload.scantron_CODE_resolution;
1.188 albertel 9290: var i;
9291: for (i=0;i<slct.length;i++) {
9292: if (slct[i].value==field) { slct[i].checked=true; }
9293: }
9294: }
9295: ENDSCRIPT
1.187 albertel 9296: my $href="/adm/pickcode?".
1.359 www 9297: "form=".&escape("scantronupload").
9298: "&scantron_format=".&escape($env{'form.scantron_format'}).
9299: "&scantron_CODElist=".&escape($env{'form.scantron_CODElist'}).
9300: "&curCODE=".&escape($$scan_record{'scantron.CODE'}).
9301: "&scantron_selectfile=".&escape($env{'form.scantron_selectfile'});
1.332 albertel 9302: if ($env{'form.scantron_CODElist'} =~ /\S/) {
1.492 albertel 9303: $r->print("
9304: <label>
9305: <input type='radio' name='scantron_CODE_resolution' value='use_found' />
9306: ".&mt("[_1]Select[_2] a CODE from the list of all CODEs and use it.",
9307: "<a target='_blank' href='$href'>","</a>")."
9308: </label>
1.558 bisitz 9309: ".&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 9310: $r->print("\n<br />");
9311: }
1.492 albertel 9312: $r->print("
9313: <label>
9314: <input type='radio' name='scantron_CODE_resolution' value='use_typed' />
9315: ".&mt("Use [_1] as the CODE.",
9316: "</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 9317: $r->print("\n<br /><br />");
1.157 albertel 9318: } elsif ($error eq 'doublebubble') {
1.596.2.6 raeburn 9319: $r->print('<p class="LC_warning">'.&mt("There have been multiple bubbles scanned for some question(s)")."</p>\n");
1.497 foxr 9320:
9321: # The form field scantron_questions is acutally a list of line numbers.
9322: # represented by this form so:
9323:
1.596.2.12.2. 6(raebur 9324:3): my $line_list = &questions_to_line_list($arg,$randomorder,$randompick,
9325:3): $respnumlookup,$startline);
1.497 foxr 9326:
1.157 albertel 9327: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 9328: $line_list.'" />');
1.242 albertel 9329: $r->print($message);
1.492 albertel 9330: $r->print("<p>".&mt("Please indicate which bubble should be used for grading")."</p>");
1.157 albertel 9331: foreach my $question (@{$arg}) {
1.503 raeburn 9332: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
1.596.2.12.2. 6(raebur 9333:3): $scan_record, $error,
9334:3): $randomorder,$randompick,
9335:3): $respnumlookup,$startline);
1.524 raeburn 9336: push(@lines_to_correct,@linenums);
1.157 albertel 9337: }
1.503 raeburn 9338: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 9339: } elsif ($error eq 'missingbubble') {
1.596.2.9 raeburn 9340: $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 9341: $r->print($message);
1.492 albertel 9342: $r->print("<p>".&mt("Please indicate which bubble should be used for grading.")."</p>");
1.503 raeburn 9343: $r->print(&mt("Some questions have no scanned bubbles.")."\n");
1.497 foxr 9344:
1.503 raeburn 9345: # The form field scantron_questions is actually a list of line numbers not
1.497 foxr 9346: # a list of question numbers. Therefore:
9347: #
9348:
1.596.2.12.2. 6(raebur 9349:3): my $line_list = &questions_to_line_list($arg,$randomorder,$randompick,
9350:3): $respnumlookup,$startline);
1.497 foxr 9351:
1.157 albertel 9352: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 9353: $line_list.'" />');
1.157 albertel 9354: foreach my $question (@{$arg}) {
1.503 raeburn 9355: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
1.596.2.12.2. 6(raebur 9356:3): $scan_record, $error,
9357:3): $randomorder,$randompick,
9358:3): $respnumlookup,$startline);
1.524 raeburn 9359: push(@lines_to_correct,@linenums);
1.157 albertel 9360: }
1.503 raeburn 9361: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 9362: } else {
9363: $r->print("\n<ul>");
9364: }
9365: $r->print("\n</li></ul>");
1.497 foxr 9366: }
9367:
1.503 raeburn 9368: sub verify_bubbles_checked {
9369: my (@ansnums) = @_;
9370: my $ansnumstr = join('","',@ansnums);
9371: my $warning = &mt("A bubble or 'No bubble' selection has not been made for one or more lines.");
1.596.2.12.2. 6(raebur 9372:6): &js_escape(\$warning);
1(raebur 9373:0): my $output = &Apache::lonhtmlcommon::scripttag(<<ENDSCRIPT);
1.503 raeburn 9374: function verify_bubble_radio(form) {
9375: var ansnumArray = new Array ("$ansnumstr");
9376: var need_bubble_count = 0;
9377: for (var i=0; i<ansnumArray.length; i++) {
9378: if (form.elements["scantron_correct_Q_"+ansnumArray[i]].length > 1) {
9379: var bubble_picked = 0;
9380: for (var j=0; j<form.elements["scantron_correct_Q_"+ansnumArray[i]].length; j++) {
9381: if (form.elements["scantron_correct_Q_"+ansnumArray[i]][j].checked == true) {
9382: bubble_picked = 1;
9383: }
9384: }
9385: if (bubble_picked == 0) {
9386: need_bubble_count ++;
9387: }
9388: }
9389: }
9390: if (need_bubble_count) {
9391: alert("$warning");
9392: return;
9393: }
9394: form.submit();
9395: }
9396: ENDSCRIPT
9397: return $output;
9398: }
9399:
1.497 foxr 9400: =pod
9401:
9402: =item questions_to_line_list
1.157 albertel 9403:
1.497 foxr 9404: Converts a list of questions into a string of comma separated
9405: line numbers in the answer sheet used by the questions. This is
9406: used to fill in the scantron_questions form field.
9407:
9408: Arguments:
9409: questions - Reference to an array of questions.
1.596.2.12.2. 6(raebur 9410:3): randomorder - True if randomorder in use.
9411:3): randompick - True if randompick in use.
9412:3): respnumlookup - Reference to HASH mapping question numbers in bubble lines
9413:3): for current line to question number used for same question
9414:3): in "Master Seqence" (as seen by Course Coordinator).
9415:3): startline - Reference to hash where key is question number (0 is first)
9416:3): and key is number of first bubble line for current student
9417:3): or code-based randompick and/or randomorder.
1.497 foxr 9418:
9419: =cut
9420:
9421:
9422: sub questions_to_line_list {
1.596.2.12.2. 6(raebur 9423:3): my ($questions,$randomorder,$randompick,$respnumlookup,$startline) = @_;
1.497 foxr 9424: my @lines;
9425:
1.503 raeburn 9426: foreach my $item (@{$questions}) {
9427: my $question = $item;
9428: my ($first,$count,$last);
9429: if ($item =~ /^(\d+)\.(\d+)$/) {
9430: $question = $1;
9431: my $subquestion = $2;
1.596.2.12.2. 6(raebur 9432:3): my $responsenum = $question-1;
9433:3): if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
9434:3): $responsenum = $respnumlookup->{$question-1};
9435:3): if (ref($startline) eq 'HASH') {
9436:3): $first = $startline->{$question-1} + 1;
9437:3): }
9438:3): } else {
9439:3): $first = $first_bubble_line{$responsenum} + 1;
9440:3): }
7(raebur 9441:3): my @subans = split(/,/,$subdivided_bubble_lines{$responsenum});
1.503 raeburn 9442: my $subcount = 1;
9443: while ($subcount<$subquestion) {
9444: $first += $subans[$subcount-1];
9445: $subcount ++;
9446: }
9447: $count = $subans[$subquestion-1];
9448: } else {
1.596.2.12.2. 7(raebur 9449:3): my $responsenum = $question-1;
9450:3): if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
9451:3): $responsenum = $respnumlookup->{$question-1};
9452:3): if (ref($startline) eq 'HASH') {
9453:3): $first = $startline->{$question-1} + 1;
9454:3): }
9455:3): } else {
9456:3): $first = $first_bubble_line{$responsenum} + 1;
9457:3): }
9458:3): $count = $bubble_lines_per_response{$responsenum};
1.503 raeburn 9459: }
1.506 raeburn 9460: $last = $first+$count-1;
1.503 raeburn 9461: push(@lines, ($first..$last));
1.497 foxr 9462: }
9463: return join(',', @lines);
9464: }
9465:
9466: =pod
9467:
9468: =item prompt_for_corrections
9469:
9470: Prompts for a potentially multiline correction to the
9471: user's bubbling (factors out common code from scantron_get_correction
9472: for multi and missing bubble cases).
9473:
9474: Arguments:
9475: $r - Apache request object.
9476: $question - The question number to prompt for.
9477: $scan_config - The scantron file configuration hash.
9478: $scan_record - Reference to the hash that has the the parsed scanlines.
1.503 raeburn 9479: $error - Type of error
1.596.2.12.2. 7(raebur 9480:3): $randomorder - True if randomorder in use.
9481:3): $randompick - True if randompick in use.
9482:3): $respnumlookup - Reference to HASH mapping question numbers in bubble lines
9483:3): for current line to question number used for same question
9484:3): in "Master Seqence" (as seen by Course Coordinator).
9485:3): $startline - Reference to hash where key is question number (0 is first)
9486:3): and value is number of first bubble line for current student
9487:3): or code-based randompick and/or randomorder.
1.497 foxr 9488:
9489: Implicit inputs:
9490: %bubble_lines_per_response - Starting line numbers for each question.
9491: Numbered from 0 (but question numbers are from
9492: 1.
9493: %first_bubble_line - Starting bubble line for each question.
1.509 raeburn 9494: %subdivided_bubble_lines - optionresponse, matchresponse and rankresponse
9495: type problems render as separate sub-questions,
1.503 raeburn 9496: in exam mode. This hash contains a
9497: comma-separated list of the lines per
9498: sub-question.
1.510 raeburn 9499: %responsetype_per_response - essayresponse, formularesponse,
9500: stringresponse, imageresponse, reactionresponse,
9501: and organicresponse type problem parts can have
1.503 raeburn 9502: multiple lines per response if the weight
9503: assigned exceeds 10. In this case, only
9504: one bubble per line is permitted, but more
9505: than one line might contain bubbles, e.g.
9506: bubbling of: line 1 - J, line 2 - J,
9507: line 3 - B would assign 22 points.
1.497 foxr 9508:
9509: =cut
9510:
9511: sub prompt_for_corrections {
1.596.2.12.2. 6(raebur 9512:3): my ($r, $question, $scan_config, $scan_record, $error, $randomorder,
9513:3): $randompick, $respnumlookup, $startline) = @_;
1.503 raeburn 9514: my ($current_line,$lines);
9515: my @linenums;
9516: my $questionnum = $question;
1.596.2.12.2. 6(raebur 9517:3): my ($first,$responsenum);
1.503 raeburn 9518: if ($question =~ /^(\d+)\.(\d+)$/) {
9519: $question = $1;
9520: my $subquestion = $2;
1.596.2.12.2. 6(raebur 9521:3): if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
9522:3): $responsenum = $respnumlookup->{$question-1};
9523:3): if (ref($startline) eq 'HASH') {
9524:3): $first = $startline->{$question-1};
9525:3): }
9526:3): } else {
9527:3): $responsenum = $question-1;
7(raebur 9528:4): $first = $first_bubble_line{$responsenum};
6(raebur 9529:3): }
9530:3): $current_line = $first + 1 ;
9531:3): my @subans = split(/,/,$subdivided_bubble_lines{$responsenum});
1.503 raeburn 9532: my $subcount = 1;
9533: while ($subcount<$subquestion) {
9534: $current_line += $subans[$subcount-1];
9535: $subcount ++;
9536: }
9537: $lines = $subans[$subquestion-1];
9538: } else {
1.596.2.12.2. 6(raebur 9539:3): if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
9540:3): $responsenum = $respnumlookup->{$question-1};
9541:3): if (ref($startline) eq 'HASH') {
9542:3): $first = $startline->{$question-1};
9543:3): }
9544:3): } else {
9545:3): $responsenum = $question-1;
9546:3): $first = $first_bubble_line{$responsenum};
9547:3): }
9548:3): $current_line = $first + 1;
9549:3): $lines = $bubble_lines_per_response{$responsenum};
1.503 raeburn 9550: }
1.497 foxr 9551: if ($lines > 1) {
1.503 raeburn 9552: $r->print(&mt('The group of bubble lines below responds to a single question.').'<br />');
1.596.2.12.2. 6(raebur 9553:3): if (($responsetype_per_response{$responsenum} eq 'essayresponse') ||
9554:3): ($responsetype_per_response{$responsenum} eq 'formularesponse') ||
9555:3): ($responsetype_per_response{$responsenum} eq 'stringresponse') ||
9556:3): ($responsetype_per_response{$responsenum} eq 'imageresponse') ||
9557:3): ($responsetype_per_response{$responsenum} eq 'reactionresponse') ||
9558:3): ($responsetype_per_response{$responsenum} eq 'organicresponse')) {
4(raebur 9559:3): $r->print(&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).'<br /><br />'.&mt('A non-zero score can be assigned to the student during bubblesheet grading by selecting a bubble in at least one line.').'<br />'.&mt('The score for this question will be a sum of the numeric values for the selected bubbles from each line, where A=1 point, B=2 points etc.').'<br />'.&mt("To assign a score of zero for this question, mark all lines as 'No bubble'.").'<br /><br />');
1.503 raeburn 9560: } else {
9561: $r->print(&mt("Select at most one bubble in a single line and select 'No Bubble' in all the other lines. ")."<br />");
9562: }
1.497 foxr 9563: }
9564: for (my $i =0; $i < $lines; $i++) {
1.503 raeburn 9565: my $selected = $$scan_record{"scantron.$current_line.answer"};
1.596.2.12.2. 6(raebur 9566:3): &scantron_bubble_selector($r,$scan_config,$current_line,
1.503 raeburn 9567: $questionnum,$error,split('', $selected));
1.524 raeburn 9568: push(@linenums,$current_line);
1.497 foxr 9569: $current_line++;
9570: }
9571: if ($lines > 1) {
9572: $r->print("<hr /><br />");
9573: }
1.503 raeburn 9574: return @linenums;
1.157 albertel 9575: }
1.423 albertel 9576:
9577: =pod
9578:
9579: =item scantron_bubble_selector
9580:
9581: Generates the html radiobuttons to correct a single bubble line
1.424 albertel 9582: possibly showing the existing the selected bubbles if known
1.423 albertel 9583:
9584: Arguments:
9585: $r - Apache request object
1.596.2.12.2. 9(raebur 9586:9): $scan_config - hash from &Apache::lonnet::get_scantron_config()
1.497 foxr 9587: $line - Number of the line being displayed.
1.503 raeburn 9588: $questionnum - Question number (may include subquestion)
9589: $error - Type of error.
1.497 foxr 9590: @selected - Array of bubbles picked on this line.
1.423 albertel 9591:
9592: =cut
9593:
1.157 albertel 9594: sub scantron_bubble_selector {
1.503 raeburn 9595: my ($r,$scan_config,$line,$questionnum,$error,@selected)=@_;
1.157 albertel 9596: my $max=$$scan_config{'Qlength'};
1.274 albertel 9597:
9598: my $scmode=$$scan_config{'Qon'};
1.596.2.12.2. (raeburn 9599:): if ($scmode eq 'number' || $scmode eq 'letter') {
9600:): if (($$scan_config{'BubblesPerRow'} =~ /^\d+$/) &&
9601:): ($$scan_config{'BubblesPerRow'} > 0)) {
9602:): $max=$$scan_config{'BubblesPerRow'};
9603:): if (($scmode eq 'number') && ($max > 10)) {
9604:): $max = 10;
9605:): } elsif (($scmode eq 'letter') && $max > 26) {
9606:): $max = 26;
9607:): }
9608:): } else {
9609:): $max = 10;
9610:): }
9611:): }
1.274 albertel 9612:
1.157 albertel 9613: my @alphabet=('A'..'Z');
1.503 raeburn 9614: $r->print(&Apache::loncommon::start_data_table().
9615: &Apache::loncommon::start_data_table_row());
9616: $r->print('<td rowspan="2" class="LC_leftcol_header">'.$line.'</td>');
1.497 foxr 9617: for (my $i=0;$i<$max+1;$i++) {
9618: $r->print("\n".'<td align="center">');
9619: if ($selected[0] eq $alphabet[$i]) { $r->print('X'); shift(@selected) }
9620: else { $r->print(' '); }
9621: $r->print('</td>');
9622: }
1.503 raeburn 9623: $r->print(&Apache::loncommon::end_data_table_row().
9624: &Apache::loncommon::start_data_table_row());
1.497 foxr 9625: for (my $i=0;$i<$max;$i++) {
9626: $r->print("\n".
9627: '<td><label><input type="radio" name="scantron_correct_Q_'.
9628: $line.'" value="'.$i.'" />'.$alphabet[$i]."</label></td>");
9629: }
1.503 raeburn 9630: my $nobub_checked = ' ';
9631: if ($error eq 'missingbubble') {
9632: $nobub_checked = ' checked = "checked" ';
9633: }
9634: $r->print("\n".'<td><label><input type="radio" name="scantron_correct_Q_'.
9635: $line.'" value="none"'.$nobub_checked.'/>'.&mt('No bubble').
9636: '</label>'."\n".'<input type="hidden" name="scantron_questionnum_Q_'.
9637: $line.'" value="'.$questionnum.'" /></td>');
9638: $r->print(&Apache::loncommon::end_data_table_row().
9639: &Apache::loncommon::end_data_table());
1.157 albertel 9640: }
9641:
1.423 albertel 9642: =pod
9643:
9644: =item num_matches
9645:
1.424 albertel 9646: Counts the number of characters that are the same between the two arguments.
9647:
9648: Arguments:
9649: $orig - CODE from the scanline
9650: $code - CODE to match against
9651:
9652: Returns:
9653: $count - integer count of the number of same characters between the
9654: two arguments
9655:
1.423 albertel 9656: =cut
9657:
1.194 albertel 9658: sub num_matches {
9659: my ($orig,$code) = @_;
9660: my @code=split(//,$code);
9661: my @orig=split(//,$orig);
9662: my $same=0;
9663: for (my $i=0;$i<scalar(@code);$i++) {
9664: if ($code[$i] eq $orig[$i]) { $same++; }
9665: }
9666: return $same;
9667: }
9668:
1.423 albertel 9669: =pod
9670:
9671: =item scantron_get_closely_matching_CODEs
9672:
1.424 albertel 9673: Cycles through all CODEs and finds the set that has the greatest
9674: number of same characters as the provided CODE
9675:
9676: Arguments:
9677: $allcodes - hash ref returned by &get_codes()
9678: $CODE - CODE from the current scanline
9679:
9680: Returns:
9681: 2 element list
9682: - first elements is number of how closely matching the best fit is
9683: (5 means best set has 5 matching characters)
9684: - second element is an arrary ref containing the set of valid CODEs
9685: that best fit the passed in CODE
9686:
1.423 albertel 9687: =cut
9688:
1.194 albertel 9689: sub scantron_get_closely_matching_CODEs {
9690: my ($allcodes,$CODE)=@_;
9691: my @CODEs;
9692: foreach my $testcode (sort(keys(%{$allcodes}))) {
9693: push(@{$CODEs[&num_matches($CODE,$testcode)]},$testcode);
9694: }
9695:
9696: return ($#CODEs,$CODEs[-1]);
9697: }
9698:
1.423 albertel 9699: =pod
9700:
9701: =item get_codes
9702:
1.424 albertel 9703: Builds a hash which has keys of all of the valid CODEs from the selected
9704: set of remembered CODEs.
9705:
9706: Arguments:
9707: $old_name - name of the set of remembered CODEs
9708: $cdom - domain of the course
9709: $cnum - internal course name
9710:
9711: Returns:
9712: %allcodes - keys are the valid CODEs, values are all 1
9713:
1.423 albertel 9714: =cut
9715:
1.194 albertel 9716: sub get_codes {
1.280 foxr 9717: my ($old_name, $cdom, $cnum) = @_;
9718: if (!$old_name) {
9719: $old_name=$env{'form.scantron_CODElist'};
9720: }
9721: if (!$cdom) {
9722: $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
9723: }
9724: if (!$cnum) {
9725: $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
9726: }
1.278 albertel 9727: my %result=&Apache::lonnet::get('CODEs',[$old_name,"type\0$old_name"],
9728: $cdom,$cnum);
9729: my %allcodes;
9730: if ($result{"type\0$old_name"} eq 'number') {
9731: %allcodes=map {($_,1)} split(',',$result{$old_name});
9732: } else {
9733: %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
9734: }
1.194 albertel 9735: return %allcodes;
9736: }
9737:
1.423 albertel 9738: =pod
9739:
9740: =item scantron_validate_CODE
9741:
1.424 albertel 9742: Validates all scanlines in the selected file to not have any
9743: invalid or underspecified CODEs and that none of the codes are
9744: duplicated if this was requested.
9745:
1.423 albertel 9746: =cut
9747:
1.157 albertel 9748: sub scantron_validate_CODE {
9749: my ($r,$currentphase) = @_;
1.596.2.12.2. 9(raebur 9750:9): my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.186 albertel 9751: if ($scantron_config{'CODElocation'} &&
9752: $scantron_config{'CODEstart'} &&
9753: $scantron_config{'CODElength'}) {
1.257 albertel 9754: if (!defined($env{'form.scantron_CODElist'})) {
1.186 albertel 9755: &FIXME_blow_up()
9756: }
9757: } else {
9758: return (0,$currentphase+1);
9759: }
9760:
9761: my %usedCODEs;
9762:
1.194 albertel 9763: my %allcodes=&get_codes();
1.186 albertel 9764:
1.582 raeburn 9765: my $nav_error;
1.596.2.12.2. (raeburn 9766:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the lines per response array.
1.582 raeburn 9767: if ($nav_error) {
9768: $r->print(&navmap_errormsg());
9769: return(1,$currentphase);
9770: }
1.447 foxr 9771:
1.186 albertel 9772: my ($scanlines,$scan_data)=&scantron_getfile();
9773: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 9774: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.186 albertel 9775: if ($line=~/^[\s\cz]*$/) { next; }
9776: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
9777: $scan_data);
9778: my $CODE=$$scan_record{'scantron.CODE'};
9779: my $error=0;
1.224 albertel 9780: if (!&Apache::lonnet::validCODE($CODE)) {
9781: &scantron_get_correction($r,$i,$scan_record,
9782: \%scantron_config,
9783: $line,'incorrectCODE',\%allcodes);
9784: return(1,$currentphase);
9785: }
1.221 albertel 9786: if (%allcodes && !exists($allcodes{$CODE})
9787: && !$$scan_record{'scantron.useCODE'}) {
1.186 albertel 9788: &scantron_get_correction($r,$i,$scan_record,
9789: \%scantron_config,
1.194 albertel 9790: $line,'incorrectCODE',\%allcodes);
9791: return(1,$currentphase);
1.186 albertel 9792: }
1.214 albertel 9793: if (exists($usedCODEs{$CODE})
1.257 albertel 9794: && $env{'form.scantron_CODEunique'} eq 'yes'
1.192 albertel 9795: && !$$scan_record{'scantron.CODE_ignore_dup'}) {
1.186 albertel 9796: &scantron_get_correction($r,$i,$scan_record,
9797: \%scantron_config,
1.194 albertel 9798: $line,'duplicateCODE',$usedCODEs{$CODE});
9799: return(1,$currentphase);
1.186 albertel 9800: }
1.524 raeburn 9801: push(@{$usedCODEs{$CODE}},$$scan_record{'scantron.PaperID'});
1.186 albertel 9802: }
1.157 albertel 9803: return (0,$currentphase+1);
9804: }
9805:
1.423 albertel 9806: =pod
9807:
9808: =item scantron_validate_doublebubble
9809:
1.424 albertel 9810: Validates all scanlines in the selected file to not have any
9811: bubble lines with multiple bubbles marked.
9812:
1.423 albertel 9813: =cut
9814:
1.157 albertel 9815: sub scantron_validate_doublebubble {
9816: my ($r,$currentphase) = @_;
9817: #get student info
9818: my $classlist=&Apache::loncoursedata::get_classlist();
9819: my %idmap=&username_to_idmap($classlist);
1.596.2.12.2. 6(raebur 9820:3): my (undef,undef,$sequence)=
9821:3): &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.157 albertel 9822:
9823: #get scantron line setup
1.596.2.12.2. 9(raebur 9824:9): my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.157 albertel 9825: my ($scanlines,$scan_data)=&scantron_getfile();
1.596.2.12.2. 6(raebur 9826:3):
9827:3): my $navmap = Apache::lonnavmaps::navmap->new();
9828:3): unless (ref($navmap)) {
9829:3): $r->print(&navmap_errormsg());
9830:3): return(1,$currentphase);
9831:3): }
9832:3): my $map=$navmap->getResourceByUrl($sequence);
9833:3): my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
9834:3): my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
9835:3): %grader_randomlists_by_symb,%orderedforcode,%respnumlookup,%startline);
9836:3): my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
9837:3):
1.583 raeburn 9838: my $nav_error;
1.596.2.12.2. 6(raebur 9839:3): if (ref($map)) {
9840:3): $randomorder = $map->randomorder();
9841:3): $randompick = $map->randompick();
0(raebur 9842:2): unless ($randomorder || $randompick) {
9843:2): foreach my $res ($navmap->retrieveResources($map,sub { $_[0]->is_map() },1,0,1)) {
9844:2): if ($res->randomorder()) {
9845:2): $randomorder = 1;
9846:2): }
9847:2): if ($res->randompick()) {
9848:2): $randompick = 1;
9849:2): }
9850:2): last if ($randomorder || $randompick);
9851:2): }
9852:2): }
6(raebur 9853:3): if ($randomorder || $randompick) {
9854:3): $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource);
9855:3): if ($nav_error) {
9856:3): $r->print(&navmap_errormsg());
9857:3): return(1,$currentphase);
9858:3): }
9859:3): &graders_resources_pass(\@resources,\%grader_partids_by_symb,
9860:3): \%grader_randomlists_by_symb,$bubbles_per_row);
9861:3): }
9862:3): } else {
9863:3): $r->print(&navmap_errormsg());
9864:3): return(1,$currentphase);
9865:3): }
9866:3):
(raeburn 9867:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the bubble line array.
1.583 raeburn 9868: if ($nav_error) {
9869: $r->print(&navmap_errormsg());
9870: return(1,$currentphase);
9871: }
1.447 foxr 9872:
1.157 albertel 9873: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 9874: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 9875: if ($line=~/^[\s\cz]*$/) { next; }
9876: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
1.596.2.12.2. 6(raebur 9877:3): $scan_data,undef,\%idmap,$randomorder,
9878:3): $randompick,$sequence,\@master_seq,
9879:3): \%symb_to_resource,\%grader_partids_by_symb,
9880:3): \%orderedforcode,\%respnumlookup,\%startline);
1.157 albertel 9881: if (!defined($$scan_record{'scantron.doubleerror'})) { next; }
9882: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,$line,
9883: 'doublebubble',
1.596.2.12.2. 6(raebur 9884:3): $$scan_record{'scantron.doubleerror'},
9885:3): $randomorder,$randompick,\%respnumlookup,\%startline);
1.157 albertel 9886: return (1,$currentphase);
9887: }
9888: return (0,$currentphase+1);
9889: }
9890:
1.423 albertel 9891:
1.503 raeburn 9892: sub scantron_get_maxbubble {
1.596.2.12.2. (raeburn 9893:): my ($nav_error,$scantron_config) = @_;
1.257 albertel 9894: if (defined($env{'form.scantron_maxbubble'}) &&
9895: $env{'form.scantron_maxbubble'}) {
1.447 foxr 9896: &restore_bubble_lines();
1.257 albertel 9897: return $env{'form.scantron_maxbubble'};
1.191 albertel 9898: }
1.330 albertel 9899:
1.447 foxr 9900: my (undef, undef, $sequence) =
1.257 albertel 9901: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.330 albertel 9902:
1.447 foxr 9903: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 9904: unless (ref($navmap)) {
9905: if (ref($nav_error)) {
9906: $$nav_error = 1;
9907: }
1.591 raeburn 9908: return;
1.582 raeburn 9909: }
1.191 albertel 9910: my $map=$navmap->getResourceByUrl($sequence);
9911: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.596.2.12.2. (raeburn 9912:): my $bubbles_per_row = &bubblesheet_bubbles_per_row($scantron_config);
1.330 albertel 9913:
9914: &Apache::lonxml::clear_problem_counter();
9915:
1.557 raeburn 9916: my $uname = $env{'user.name'};
9917: my $udom = $env{'user.domain'};
1.435 foxr 9918: my $cid = $env{'request.course.id'};
9919: my $total_lines = 0;
9920: %bubble_lines_per_response = ();
1.447 foxr 9921: %first_bubble_line = ();
1.503 raeburn 9922: %subdivided_bubble_lines = ();
9923: %responsetype_per_response = ();
1.596.2.12.2. 6(raebur 9924:3): %masterseq_id_responsenum = ();
1.554 raeburn 9925:
1.447 foxr 9926: my $response_number = 0;
9927: my $bubble_line = 0;
1.191 albertel 9928: foreach my $resource (@resources) {
1.596.2.12.2. 6(raebur 9929:3): my $resid = $resource->id();
(raeburn 9930:): my ($analysis,$parts) = &scantron_partids_tograde($resource,$cid,$uname,
7(raebur 9931:3): $udom,undef,$bubbles_per_row);
1.542 raeburn 9932: if ((ref($analysis) eq 'HASH') && (ref($parts) eq 'ARRAY')) {
9933: foreach my $part_id (@{$parts}) {
9934: my $lines;
9935:
9936: # TODO - make this a persistent hash not an array.
9937:
9938: # optionresponse, matchresponse and rankresponse type items
9939: # render as separate sub-questions in exam mode.
9940: if (($analysis->{$part_id.'.type'} eq 'optionresponse') ||
9941: ($analysis->{$part_id.'.type'} eq 'matchresponse') ||
9942: ($analysis->{$part_id.'.type'} eq 'rankresponse')) {
9943: my ($numbub,$numshown);
9944: if ($analysis->{$part_id.'.type'} eq 'optionresponse') {
9945: if (ref($analysis->{$part_id.'.options'}) eq 'ARRAY') {
9946: $numbub = scalar(@{$analysis->{$part_id.'.options'}});
9947: }
9948: } elsif ($analysis->{$part_id.'.type'} eq 'matchresponse') {
9949: if (ref($analysis->{$part_id.'.items'}) eq 'ARRAY') {
9950: $numbub = scalar(@{$analysis->{$part_id.'.items'}});
9951: }
9952: } elsif ($analysis->{$part_id.'.type'} eq 'rankresponse') {
9953: if (ref($analysis->{$part_id.'.foils'}) eq 'ARRAY') {
9954: $numbub = scalar(@{$analysis->{$part_id.'.foils'}});
9955: }
9956: }
9957: if (ref($analysis->{$part_id.'.shown'}) eq 'ARRAY') {
9958: $numshown = scalar(@{$analysis->{$part_id.'.shown'}});
9959: }
1.596.2.12.2. (raeburn 9960:): my $bubbles_per_row =
9961:): &bubblesheet_bubbles_per_row($scantron_config);
9962:): my $inner_bubble_lines = int($numbub/$bubbles_per_row);
9963:): if (($numbub % $bubbles_per_row) != 0) {
1.542 raeburn 9964: $inner_bubble_lines++;
9965: }
9966: for (my $i=0; $i<$numshown; $i++) {
9967: $subdivided_bubble_lines{$response_number} .=
9968: $inner_bubble_lines.',';
9969: }
9970: $subdivided_bubble_lines{$response_number} =~ s/,$//;
9971: $lines = $numshown * $inner_bubble_lines;
9972: } else {
9973: $lines = $analysis->{"$part_id.bubble_lines"};
1.596.2.12.2. (raeburn 9974:): }
1.542 raeburn 9975:
9976: $first_bubble_line{$response_number} = $bubble_line;
9977: $bubble_lines_per_response{$response_number} = $lines;
9978: $responsetype_per_response{$response_number} =
9979: $analysis->{$part_id.'.type'};
1.596.2.12.2. 6(raebur 9980:3): $masterseq_id_responsenum{$resid.'_'.$part_id} = $response_number;
1.542 raeburn 9981: $response_number++;
9982:
9983: $bubble_line += $lines;
9984: $total_lines += $lines;
9985: }
9986: }
9987: }
1.552 raeburn 9988: &Apache::lonnet::delenv('scantron.');
1.542 raeburn 9989:
9990: &save_bubble_lines();
9991: $env{'form.scantron_maxbubble'} =
9992: $total_lines;
9993: return $env{'form.scantron_maxbubble'};
9994: }
1.523 raeburn 9995:
1.596.2.12.2. (raeburn 9996:): sub bubblesheet_bubbles_per_row {
9997:): my ($scantron_config) = @_;
9998:): my $bubbles_per_row;
9999:): if (ref($scantron_config) eq 'HASH') {
10000:): $bubbles_per_row = $scantron_config->{'BubblesPerRow'};
10001:): }
10002:): if ((!$bubbles_per_row) || ($bubbles_per_row < 1)) {
10003:): $bubbles_per_row = 10;
10004:): }
10005:): return $bubbles_per_row;
10006:): }
10007:):
1.157 albertel 10008: sub scantron_validate_missingbubbles {
10009: my ($r,$currentphase) = @_;
10010: #get student info
10011: my $classlist=&Apache::loncoursedata::get_classlist();
10012: my %idmap=&username_to_idmap($classlist);
1.596.2.12.2. 6(raebur 10013:3): my (undef,undef,$sequence)=
10014:3): &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.157 albertel 10015:
10016: #get scantron line setup
1.596.2.12.2. 9(raebur 10017:9): my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.157 albertel 10018: my ($scanlines,$scan_data)=&scantron_getfile();
1.596.2.12.2. 6(raebur 10019:3):
10020:3): my $navmap = Apache::lonnavmaps::navmap->new();
10021:3): unless (ref($navmap)) {
10022:3): $r->print(&navmap_errormsg());
10023:3): return(1,$currentphase);
10024:3): }
10025:3):
10026:3): my $map=$navmap->getResourceByUrl($sequence);
10027:3): my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
10028:3): my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
10029:3): %grader_randomlists_by_symb,%orderedforcode,%respnumlookup,%startline);
10030:3): my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
10031:3):
1.582 raeburn 10032: my $nav_error;
1.596.2.12.2. 6(raebur 10033:3): if (ref($map)) {
10034:3): $randomorder = $map->randomorder();
10035:3): $randompick = $map->randompick();
0(raebur 10036:2): unless ($randomorder || $randompick) {
10037:2): foreach my $res ($navmap->retrieveResources($map,sub { $_[0]->is_map() },1,0,1)) {
10038:2): if ($res->randomorder()) {
10039:2): $randomorder = 1;
10040:2): }
10041:2): if ($res->randompick()) {
10042:2): $randompick = 1;
10043:2): }
10044:2): last if ($randomorder || $randompick);
10045:2): }
10046:2): }
7(raebur 10047:3): if ($randomorder || $randompick) {
10048:3): $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource);
10049:3): if ($nav_error) {
10050:3): $r->print(&navmap_errormsg());
10051:3): return(1,$currentphase);
10052:3): }
10053:3): &graders_resources_pass(\@resources,\%grader_partids_by_symb,
10054:3): \%grader_randomlists_by_symb,$bubbles_per_row);
10055:3): }
6(raebur 10056:3): } else {
10057:3): $r->print(&navmap_errormsg());
7(raebur 10058:3): return(1,$currentphase);
6(raebur 10059:3): }
10060:3):
10061:3):
(raeburn 10062:): my $max_bubble=&scantron_get_maxbubble(\$nav_error,\%scantron_config);
1.582 raeburn 10063: if ($nav_error) {
1.596.2.12.2. 6(raebur 10064:3): $r->print(&navmap_errormsg());
1.582 raeburn 10065: return(1,$currentphase);
10066: }
1.596.2.12.2. 6(raebur 10067:3):
1.157 albertel 10068: if (!$max_bubble) { $max_bubble=2**31; }
10069: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 10070: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 10071: if ($line=~/^[\s\cz]*$/) { next; }
1.596.2.12.2. 6(raebur 10072:3): my $scan_record =
10073:3): &scantron_parse_scanline($line,$i,\%scantron_config,$scan_data,undef,\%idmap,
10074:3): $randomorder,$randompick,$sequence,\@master_seq,
10075:3): \%symb_to_resource,\%grader_partids_by_symb,
10076:3): \%orderedforcode,\%respnumlookup,\%startline);
1.157 albertel 10077: if (!defined($$scan_record{'scantron.missingerror'})) { next; }
10078: my @to_correct;
1.470 foxr 10079:
10080: # Probably here's where the error is...
10081:
1.157 albertel 10082: foreach my $missing (@{$$scan_record{'scantron.missingerror'}}) {
1.505 raeburn 10083: my $lastbubble;
10084: if ($missing =~ /^(\d+)\.(\d+)$/) {
1.596.2.12.2. 6(raebur 10085:3): my $question = $1;
10086:3): my $subquestion = $2;
10087:3): my ($first,$responsenum);
10088:3): if ($randomorder || $randompick) {
10089:3): $responsenum = $respnumlookup{$question-1};
10090:3): $first = $startline{$question-1};
10091:3): } else {
10092:3): $responsenum = $question-1;
10093:3): $first = $first_bubble_line{$responsenum};
10094:3): }
10095:3): if (!defined($first)) { next; }
7(raebur 10096:3): my @subans = split(/,/,$subdivided_bubble_lines{$responsenum});
6(raebur 10097:3): my $subcount = 1;
10098:3): while ($subcount<$subquestion) {
10099:3): $first += $subans[$subcount-1];
10100:3): $subcount ++;
10101:3): }
10102:3): my $count = $subans[$subquestion-1];
10103:3): $lastbubble = $first + $count;
1.505 raeburn 10104: } else {
1.596.2.12.2. 6(raebur 10105:3): my ($first,$responsenum);
10106:3): if ($randomorder || $randompick) {
10107:3): $responsenum = $respnumlookup{$missing-1};
10108:3): $first = $startline{$missing-1};
10109:3): } else {
10110:3): $responsenum = $missing-1;
10111:3): $first = $first_bubble_line{$responsenum};
10112:3): }
10113:3): if (!defined($first)) { next; }
10114:3): $lastbubble = $first + $bubble_lines_per_response{$responsenum};
1.505 raeburn 10115: }
10116: if ($lastbubble > $max_bubble) { next; }
1.157 albertel 10117: push(@to_correct,$missing);
10118: }
10119: if (@to_correct) {
10120: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
1.596.2.12.2. 6(raebur 10121:3): $line,'missingbubble',\@to_correct,
10122:3): $randomorder,$randompick,\%respnumlookup,
10123:3): \%startline);
1.157 albertel 10124: return (1,$currentphase);
10125: }
10126:
10127: }
10128: return (0,$currentphase+1);
10129: }
10130:
1.596.2.12.2. (raeburn 10131:): sub hand_bubble_option {
10132:): my (undef, undef, $sequence) =
10133:): &Apache::lonnet::decode_symb($env{'form.selectpage'});
10134:): return if ($sequence eq '');
10135:): my $navmap = Apache::lonnavmaps::navmap->new();
10136:): unless (ref($navmap)) {
10137:): return;
10138:): }
10139:): my $needs_hand_bubbles;
10140:): my $map=$navmap->getResourceByUrl($sequence);
10141:): my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
10142:): foreach my $res (@resources) {
10143:): if (ref($res)) {
10144:): if ($res->is_problem()) {
10145:): my $partlist = $res->parts();
10146:): foreach my $part (@{ $partlist }) {
10147:): my @types = $res->responseType($part);
10148:): if (grep(/^(chem|essay|image|formula|math|string|functionplot)$/,@types)) {
10149:): $needs_hand_bubbles = 1;
10150:): last;
10151:): }
10152:): }
10153:): }
10154:): }
10155:): }
10156:): if ($needs_hand_bubbles) {
9(raebur 10157:9): my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
(raeburn 10158:): my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
10159:): return &mt('The sequence to be graded contains response types which are handgraded.').'<p>'.
10160:): &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 />').
10161:): '<label><input type="radio" name="scantron_lastbubblepoints" value="'.$bubbles_per_row.'" checked="checked" />'.&mt('[quant,_1,point]',$bubbles_per_row).'</label> '.&mt('or').' '.
8(raebur 10162:4): '<label><input type="radio" name="scantron_lastbubblepoints" value="0" />'.&mt('0 points').'</label></p>';
(raeburn 10163:): }
10164:): return;
10165:): }
1.423 albertel 10166:
1.82 albertel 10167: sub scantron_process_students {
1.596.2.12.2. 1(raebur 10168:0): my ($r,$symb) = @_;
1.513 foxr 10169:
1.257 albertel 10170: my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($env{'form.selectpage'});
1.513 foxr 10171: if (!$symb) {
10172: return '';
10173: }
1.324 albertel 10174: my $default_form_data=&defaultFormData($symb);
1.82 albertel 10175:
1.596.2.12.2. 9(raebur 10176:9): my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
6(raebur 10177:3): my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
1.157 albertel 10178: my ($scanlines,$scan_data)=&scantron_getfile();
1.82 albertel 10179: my $classlist=&Apache::loncoursedata::get_classlist();
10180: my %idmap=&username_to_idmap($classlist);
1.132 bowersj2 10181: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 10182: unless (ref($navmap)) {
10183: $r->print(&navmap_errormsg());
10184: return '';
1.596.2.12.2. 6(raebur 10185:3): }
1.83 albertel 10186: my $map=$navmap->getResourceByUrl($sequence);
1.596.2.12.2. 6(raebur 10187:3): my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
0(raebur 10188:2): %grader_randomlists_by_symb,%symb_for_examcode);
1(raebur 10189:2): if (ref($map)) {
10190:2): $randomorder = $map->randomorder();
6(raebur 10191:3): $randompick = $map->randompick();
0(raebur 10192:2): unless ($randomorder || $randompick) {
10193:2): foreach my $res ($navmap->retrieveResources($map,sub { $_[0]->is_map() },1,0,1)) {
10194:2): if ($res->randomorder()) {
10195:2): $randomorder = 1;
10196:2): }
10197:2): if ($res->randompick()) {
10198:2): $randompick = 1;
10199:2): }
10200:2): last if ($randomorder || $randompick);
10201:2): }
10202:2): }
6(raebur 10203:3): } else {
10204:3): $r->print(&navmap_errormsg());
10205:3): return '';
1(raebur 10206:2): }
6(raebur 10207:3): my $nav_error;
1.83 albertel 10208: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.596.2.12.2. 6(raebur 10209:3): if ($randomorder || $randompick) {
0(raebur 10210:2): $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource,1,\%symb_for_examcode);
6(raebur 10211:3): if ($nav_error) {
10212:3): $r->print(&navmap_errormsg());
10213:3): return '';
1.586 raeburn 10214: }
10215: }
1.596.2.12.2. 6(raebur 10216:3): &graders_resources_pass(\@resources,\%grader_partids_by_symb,
10217:3): \%grader_randomlists_by_symb,$bubbles_per_row);
1.557 raeburn 10218:
1.554 raeburn 10219: my ($uname,$udom);
1.82 albertel 10220: my $result= <<SCANTRONFORM;
1.81 albertel 10221: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
10222: <input type="hidden" name="command" value="scantron_configphase" />
10223: $default_form_data
10224: SCANTRONFORM
1.82 albertel 10225: $r->print($result);
10226:
10227: my @delayqueue;
1.542 raeburn 10228: my (%completedstudents,%scandata);
1.140 albertel 10229:
1.520 www 10230: my $lock=&Apache::lonnet::set_lock(&mt('Grading bubblesheet exam'));
1.200 albertel 10231: my $count=&get_todo_count($scanlines,$scan_data);
1.596.2.12.2. (raeburn 10232:): my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$count);
1(raebur 10233:0): &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,'Processing first student');
1.542 raeburn 10234: $r->print('<br />');
1.140 albertel 10235: my $start=&Time::HiRes::time();
1.158 albertel 10236: my $i=-1;
1.542 raeburn 10237: my $started;
1.447 foxr 10238:
1.596.2.12.2. (raeburn 10239:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # Need the bubble lines array to parse.
1.582 raeburn 10240: if ($nav_error) {
10241: $r->print(&navmap_errormsg());
10242: return '';
10243: }
10244:
1.513 foxr 10245: # If an ssi failed in scantron_get_maxbubble, put an error message out to
10246: # the user and return.
10247:
10248: if ($ssi_error) {
10249: $r->print("</form>");
10250: &ssi_print_error($r);
1.520 www 10251: &Apache::lonnet::remove_lock($lock);
1.513 foxr 10252: return ''; # Dunno why the other returns return '' rather than just returning.
10253: }
1.447 foxr 10254:
1.596.2.12.2. 9(raebur 10255:9): my %lettdig = &Apache::lonnet::letter_to_digits();
1.542 raeburn 10256: my $numletts = scalar(keys(%lettdig));
1.596.2.12.2. 6(raebur 10257:3): my %orderedforcode;
1.542 raeburn 10258:
1.157 albertel 10259: while ($i<$scanlines->{'count'}) {
10260: ($uname,$udom)=('','');
10261: $i++;
1.200 albertel 10262: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 10263: if ($line=~/^[\s\cz]*$/) { next; }
1.200 albertel 10264: if ($started) {
1.596.2.12.2. 1(raebur 10265:0): &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student');
1.200 albertel 10266: }
10267: $started=1;
1.596.2.12.2. 6(raebur 10268:3): my %respnumlookup = ();
10269:3): my %startline = ();
10270:3): my $total;
1.157 albertel 10271: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
1.596.2.12.2. 6(raebur 10272:3): $scan_data,undef,\%idmap,$randomorder,
10273:3): $randompick,$sequence,\@master_seq,
10274:3): \%symb_to_resource,\%grader_partids_by_symb,
10275:3): \%orderedforcode,\%respnumlookup,\%startline,
10276:3): \$total);
1.157 albertel 10277: unless ($uname=&scantron_find_student($scan_record,$scan_data,
10278: \%idmap,$i)) {
10279: &scantron_add_delay(\@delayqueue,$line,
10280: 'Unable to find a student that matches',1);
10281: next;
10282: }
10283: if (exists $completedstudents{$uname}) {
10284: &scantron_add_delay(\@delayqueue,$line,
10285: 'Student '.$uname.' has multiple sheets',2);
10286: next;
10287: }
1.596.2.12.2. 1(raebur 10288:2): my $usec = $classlist->{$uname}->[&Apache::loncoursedata::CL_SECTION];
10289:2): my $user = $uname.':'.$usec;
1.157 albertel 10290: ($uname,$udom)=split(/:/,$uname);
1.330 albertel 10291:
1.596.2.12.2. 1(raebur 10292:2): my $scancode;
10293:2): if ((exists($scan_record->{'scantron.CODE'})) &&
10294:2): (&Apache::lonnet::validCODE($scan_record->{'scantron.CODE'}))) {
10295:2): $scancode = $scan_record->{'scantron.CODE'};
10296:2): } else {
10297:2): $scancode = '';
10298:2): }
10299:2):
10300:2): my @mapresources = @resources;
6(raebur 10301:3): if ($randomorder || $randompick) {
1(raebur 10302:2): @mapresources =
6(raebur 10303:3): &users_order($user,$scancode,$sequence,\@master_seq,\%symb_to_resource,
10304:3): \%orderedforcode);
1(raebur 10305:2): }
1.586 raeburn 10306: my (%partids_by_symb,$res_error);
1.596.2.12.2. 1(raebur 10307:2): foreach my $resource (@mapresources) {
1.586 raeburn 10308: my $ressymb;
10309: if (ref($resource)) {
10310: $ressymb = $resource->symb();
10311: } else {
10312: $res_error = 1;
10313: last;
10314: }
1.557 raeburn 10315: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
10316: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
1.596.2.12.2. 1(raebur 10317:7): my $currcode;
10318:7): if (exists($grader_randomlists_by_symb{$ressymb})) {
10319:7): $currcode = $scancode;
10320:7): }
1.557 raeburn 10321: my ($analysis,$parts) =
1.596.2.12.2. (raeburn 10322:): &scantron_partids_tograde($resource,$env{'request.course.id'},
1(raebur 10323:7): $uname,$udom,undef,$bubbles_per_row,
10324:7): $currcode);
1.557 raeburn 10325: $partids_by_symb{$ressymb} = $parts;
10326: } else {
10327: $partids_by_symb{$ressymb} = $grader_partids_by_symb{$ressymb};
10328: }
1.554 raeburn 10329: }
10330:
1.586 raeburn 10331: if ($res_error) {
10332: &scantron_add_delay(\@delayqueue,$line,
10333: 'An error occurred while grading student '.$uname,2);
10334: next;
10335: }
10336:
1.330 albertel 10337: &Apache::lonxml::clear_problem_counter();
1.514 raeburn 10338: &Apache::lonnet::appenv($scan_record);
1.376 albertel 10339:
10340: if (&scantron_clear_skip($scanlines,$scan_data,$i)) {
10341: &scantron_putfile($scanlines,$scan_data);
10342: }
1.161 albertel 10343:
1.542 raeburn 10344: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
1.596.2.12.2. 1(raebur 10345:2): \@mapresources,\%partids_by_symb,
6(raebur 10346:3): $bubbles_per_row,$randomorder,$randompick,
10347:3): \%respnumlookup,\%startline)
10348:3): eq 'ssi_error') {
1.542 raeburn 10349: $ssi_error = 0; # So end of handler error message does not trigger.
10350: $r->print("</form>");
10351: &ssi_print_error($r);
10352: &Apache::lonnet::remove_lock($lock);
10353: return ''; # Why return ''? Beats me.
10354: }
1.513 foxr 10355:
1.596.2.12.2. 6(raebur 10356:3): if (($scancode) && ($randomorder || $randompick)) {
0(raebur 10357:2): foreach my $key (keys(%symb_for_examcode)) {
10358:2): my $symb_in_map = $symb_for_examcode{$key};
10359:2): if ($symb_in_map ne '') {
10360:2): my $parmresult =
10361:2): &Apache::lonparmset::storeparm_by_symb($symb_in_map,
10362:2): '0_examcode',2,$scancode,
10363:2): 'string_examcode',$uname,
10364:2): $udom);
10365:2): }
10366:2): }
6(raebur 10367:3): }
1.140 albertel 10368: $completedstudents{$uname}={'line'=>$line};
1.542 raeburn 10369: if ($env{'form.verifyrecord'}) {
10370: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
1.596.2.12.2. 6(raebur 10371:3): if ($randompick) {
10372:3): if ($total) {
10373:3): $lastpos = $total*$scantron_config{'Qlength'};
10374:3): }
10375:3): }
10376:3):
1.542 raeburn 10377: my $studentdata = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
10378: chomp($studentdata);
10379: $studentdata =~ s/\r$//;
10380: my $studentrecord = '';
10381: my $counter = -1;
1.596.2.12.2. 1(raebur 10382:2): foreach my $resource (@mapresources) {
1.554 raeburn 10383: my $ressymb = $resource->symb();
1.542 raeburn 10384: ($counter,my $recording) =
10385: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 10386: $counter,$studentdata,$partids_by_symb{$ressymb},
1.596.2.12.2. 6(raebur 10387:3): \%scantron_config,\%lettdig,$numletts,$randomorder,
10388:3): $randompick,\%respnumlookup,\%startline);
1.542 raeburn 10389: $studentrecord .= $recording;
10390: }
10391: if ($studentrecord ne $studentdata) {
1.554 raeburn 10392: &Apache::lonxml::clear_problem_counter();
10393: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
1.596.2.12.2. 1(raebur 10394:2): \@mapresources,\%partids_by_symb,
6(raebur 10395:3): $bubbles_per_row,$randomorder,$randompick,
10396:3): \%respnumlookup,\%startline)
10397:3): eq 'ssi_error') {
1.554 raeburn 10398: $ssi_error = 0; # So end of handler error message does not trigger.
10399: $r->print("</form>");
10400: &ssi_print_error($r);
10401: &Apache::lonnet::remove_lock($lock);
10402: delete($completedstudents{$uname});
10403: return '';
10404: }
1.542 raeburn 10405: $counter = -1;
10406: $studentrecord = '';
1.596.2.12.2. 1(raebur 10407:2): foreach my $resource (@mapresources) {
1.554 raeburn 10408: my $ressymb = $resource->symb();
1.542 raeburn 10409: ($counter,my $recording) =
10410: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 10411: $counter,$studentdata,$partids_by_symb{$ressymb},
1.596.2.12.2. 6(raebur 10412:3): \%scantron_config,\%lettdig,$numletts,
10413:3): $randomorder,$randompick,\%respnumlookup,
10414:3): \%startline);
1.542 raeburn 10415: $studentrecord .= $recording;
10416: }
10417: if ($studentrecord ne $studentdata) {
1.596.2.6 raeburn 10418: $r->print('<p><span class="LC_warning">');
1.542 raeburn 10419: if ($scancode eq '') {
1.596.2.6 raeburn 10420: $r->print(&mt('Mismatch grading bubblesheet for user: [_1] with ID: [_2].',
1.542 raeburn 10421: $uname.':'.$udom,$scan_record->{'scantron.ID'}));
10422: } else {
1.596.2.6 raeburn 10423: $r->print(&mt('Mismatch grading bubblesheet for user: [_1] with ID: [_2] and CODE: [_3].',
1.542 raeburn 10424: $uname.':'.$udom,$scan_record->{'scantron.ID'},$scancode));
10425: }
10426: $r->print('</span><br />'.&Apache::loncommon::start_data_table()."\n".
10427: &Apache::loncommon::start_data_table_header_row()."\n".
10428: '<th>'.&mt('Source').'</th><th>'.&mt('Bubbled responses').'</th>'.
10429: &Apache::loncommon::end_data_table_header_row()."\n".
10430: &Apache::loncommon::start_data_table_row().
1.596.2.6 raeburn 10431: '<td>'.&mt('Bubblesheet').'</td>'.
1.596.2.12.2. 4(raebur 10432:3): '<td><span class="LC_nobreak" style="white-space: pre;"><tt>'.$studentdata.'</tt></span></td>'.
1.542 raeburn 10433: &Apache::loncommon::end_data_table_row().
10434: &Apache::loncommon::start_data_table_row().
1.596.2.6 raeburn 10435: '<td>'.&mt('Stored submissions').'</td>'.
1.596.2.12.2. 4(raebur 10436:3): '<td><span class="LC_nobreak" style="white-space: pre;"><tt>'.$studentrecord.'</tt></span></td>'."\n".
1.542 raeburn 10437: &Apache::loncommon::end_data_table_row().
10438: &Apache::loncommon::end_data_table().'</p>');
10439: } else {
10440: $r->print('<br /><span class="LC_warning">'.
10441: &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 />'.
10442: &mt("As a consequence, this user's submission history records two tries.").
10443: '</span><br />');
10444: }
10445: }
10446: }
1.543 raeburn 10447: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.140 albertel 10448: } continue {
1.330 albertel 10449: &Apache::lonxml::clear_problem_counter();
1.552 raeburn 10450: &Apache::lonnet::delenv('scantron.');
1.82 albertel 10451: }
1.140 albertel 10452: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.520 www 10453: &Apache::lonnet::remove_lock($lock);
1.172 albertel 10454: # my $lasttime = &Time::HiRes::time()-$start;
10455: # $r->print("<p>took $lasttime</p>");
1.140 albertel 10456:
1.200 albertel 10457: $r->print("</form>");
1.157 albertel 10458: return '';
1.75 albertel 10459: }
1.157 albertel 10460:
1.557 raeburn 10461: sub graders_resources_pass {
1.596.2.12.2. (raeburn 10462:): my ($resources,$grader_partids_by_symb,$grader_randomlists_by_symb,
10463:): $bubbles_per_row) = @_;
1.557 raeburn 10464: if ((ref($resources) eq 'ARRAY') && (ref($grader_partids_by_symb)) &&
10465: (ref($grader_randomlists_by_symb) eq 'HASH')) {
10466: foreach my $resource (@{$resources}) {
10467: my $ressymb = $resource->symb();
10468: my ($analysis,$parts) =
10469: &scantron_partids_tograde($resource,$env{'request.course.id'},
1.596.2.12.2. (raeburn 10470:): $env{'user.name'},$env{'user.domain'},
10471:): 1,$bubbles_per_row);
1.557 raeburn 10472: $grader_partids_by_symb->{$ressymb} = $parts;
10473: if (ref($analysis) eq 'HASH') {
10474: if (ref($analysis->{'parts_withrandomlist'}) eq 'ARRAY') {
10475: $grader_randomlists_by_symb->{$ressymb} =
10476: $analysis->{'parts_withrandomlist'};
10477: }
10478: }
10479: }
10480: }
10481: return;
10482: }
10483:
1.596.2.12.2. 1(raebur 10484:2): =pod
10485:2):
10486:2): =item users_order
10487:2):
10488:2): Returns array of resources in current map, ordered based on either CODE,
10489:2): if this is a CODEd exam, or based on student's identity if this is a
10490:2): "NAMEd" exam.
10491:2):
6(raebur 10492:3): Should be used when randomorder and/or randompick applied when the
10493:3): corresponding exam was printed, prior to students completing bubblesheets
10494:3): for the version of the exam the student received.
1(raebur 10495:2):
10496:2): =cut
10497:2):
10498:2): sub users_order {
6(raebur 10499:3): my ($user,$scancode,$mapurl,$master_seq,$symb_to_resource,$orderedforcode) = @_;
1(raebur 10500:2): my @mapresources;
6(raebur 10501:3): unless ((ref($master_seq) eq 'ARRAY') && (ref($symb_to_resource) eq 'HASH')) {
1(raebur 10502:2): return @mapresources;
10503:2): }
6(raebur 10504:3): if ($scancode) {
10505:3): if ((ref($orderedforcode) eq 'HASH') && (ref($orderedforcode->{$scancode}) eq 'ARRAY')) {
10506:3): @mapresources = @{$orderedforcode->{$scancode}};
10507:3): } else {
10508:3): $env{'form.CODE'} = $scancode;
10509:3): my $actual_seq =
10510:3): &Apache::lonprintout::master_seq_to_person_seq($mapurl,
10511:3): $master_seq,
10512:3): $user,$scancode,1);
10513:3): if (ref($actual_seq) eq 'ARRAY') {
10514:3): @mapresources = map { $symb_to_resource->{$_}; } @{$actual_seq};
10515:3): if (ref($orderedforcode) eq 'HASH') {
10516:3): if (@mapresources > 0) {
10517:3): $orderedforcode->{$scancode} = \@mapresources;
10518:3): }
10519:3): }
10520:3): }
10521:3): delete($env{'form.CODE'});
1(raebur 10522:2): }
10523:2): } else {
10524:2): my $actual_seq =
10525:2): &Apache::lonprintout::master_seq_to_person_seq($mapurl,
10526:2): $master_seq,
5(raebur 10527:3): $user,undef,1);
1(raebur 10528:2): if (ref($actual_seq) eq 'ARRAY') {
10529:2): @mapresources =
10530:2): map { $symb_to_resource->{$_}; } @{$actual_seq};
10531:2): }
6(raebur 10532:3): }
10533:3): return @mapresources;
1(raebur 10534:2): }
10535:2):
1.542 raeburn 10536: sub grade_student_bubbles {
1.596.2.12.2. 6(raebur 10537:3): my ($r,$uname,$udom,$scan_record,$scancode,$resources,$parts,$bubbles_per_row,
10538:3): $randomorder,$randompick,$respnumlookup,$startline) = @_;
10539:3): my $uselookup = 0;
10540:3): if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH') &&
10541:3): (ref($startline) eq 'HASH')) {
10542:3): $uselookup = 1;
10543:3): }
10544:3):
1.554 raeburn 10545: if (ref($resources) eq 'ARRAY') {
10546: my $count = 0;
10547: foreach my $resource (@{$resources}) {
10548: my $ressymb = $resource->symb();
10549: my %form = ('submitted' => 'scantron',
10550: 'grade_target' => 'grade',
10551: 'grade_username' => $uname,
10552: 'grade_domain' => $udom,
10553: 'grade_courseid' => $env{'request.course.id'},
10554: 'grade_symb' => $ressymb,
10555: 'CODE' => $scancode
10556: );
1.596.2.12.2. (raeburn 10557:): if ($bubbles_per_row ne '') {
10558:): $form{'bubbles_per_row'} = $bubbles_per_row;
10559:): }
10560:): if ($env{'form.scantron_lastbubblepoints'} ne '') {
10561:): $form{'scantron_lastbubblepoints'} = $env{'form.scantron_lastbubblepoints'};
10562:): }
1.554 raeburn 10563: if (ref($parts) eq 'HASH') {
10564: if (ref($parts->{$ressymb}) eq 'ARRAY') {
10565: foreach my $part (@{$parts->{$ressymb}}) {
1.596.2.12.2. 6(raebur 10566:3): if ($uselookup) {
10567:3): $form{'scantron_questnum_start.'.$part} = $startline->{$count} + 1;
10568:3): } else {
10569:3): $form{'scantron_questnum_start.'.$part} =
10570:3): 1+$env{'form.scantron.first_bubble_line.'.$count};
10571:3): }
1.554 raeburn 10572: $count++;
10573: }
10574: }
10575: }
10576: my $result=&ssi_with_retries($resource->src(),$ssi_retries,%form);
10577: return 'ssi_error' if ($ssi_error);
10578: last if (&Apache::loncommon::connection_aborted($r));
10579: }
1.542 raeburn 10580: }
10581: return;
10582: }
10583:
1.157 albertel 10584: sub scantron_upload_scantron_data {
1.596.2.12.2. 1(raebur 10585:0): my ($r,$symb) = @_;
1.565 raeburn 10586: my $dom = $env{'request.role.domain'};
1.596.2.12.2. 9(raebur 10587:9): my ($formatoptions,$formattitle,$formatjs) = &scantron_upload_dataformat($dom);
1.565 raeburn 10588: my $domdesc = &Apache::lonnet::domain($dom,'description');
10589: $r->print(&Apache::loncommon::coursebrowser_javascript($dom));
1.157 albertel 10590: my $select_link=&Apache::loncommon::selectcourse_link('rules','courseid',
1.181 albertel 10591: 'domainid',
1.565 raeburn 10592: 'coursename',$dom);
10593: my $syllabuslink = '<a href="javascript:ToSyllabus();">'.&mt('Syllabus').'</a>'.
1.596.2.12.2. (raeburn 10594:): (' 'x2).&mt('(shows course personnel)');
10595:): my $default_form_data=&defaultFormData($symb);
1.579 raeburn 10596: my $nofile_alert = &mt('Please use the browse button to select a file from your local directory.');
1.596.2.12.2. 7(raebur 10597:6): &js_escape(\$nofile_alert);
1.579 raeburn 10598: 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.596.2.12.2. 6(raebur 10599:6): &js_escape(\$nocourseid_alert);
9(raebur 10600:9): $r->print(&Apache::lonhtmlcommon::scripttag('
1.157 albertel 10601: function checkUpload(formname) {
10602: if (formname.upfile.value == "") {
1.579 raeburn 10603: alert("'.$nofile_alert.'");
1.157 albertel 10604: return false;
10605: }
1.565 raeburn 10606: if (formname.courseid.value == "") {
1.579 raeburn 10607: alert("'.$nocourseid_alert.'");
1.565 raeburn 10608: return false;
10609: }
1.157 albertel 10610: formname.submit();
10611: }
1.565 raeburn 10612:
10613: function ToSyllabus() {
10614: var cdom = '."'$dom'".';
10615: var cnum = document.rules.courseid.value;
10616: if (cdom == "" || cdom == null) {
10617: return;
10618: }
10619: if (cnum == "" || cnum == null) {
10620: return;
10621: }
10622: syllwin=window.open("/public/"+cdom+"/"+cnum+"/syllabus","LONCAPASyllabus",
10623: "height=350,width=350,scrollbars=yes,menubar=no");
10624: return;
10625: }
10626:
1.596.2.12.2. 9(raebur 10627:9): '.$formatjs.'
10628:9): '));
10629:9): $r->print('
1.596.2.4 raeburn 10630: <h3>'.&mt('Send bubblesheet data to a course').'</h3>
1.566 raeburn 10631:
1.492 albertel 10632: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
1.565 raeburn 10633: '.$default_form_data.
10634: &Apache::lonhtmlcommon::start_pick_box().
10635: &Apache::lonhtmlcommon::row_title(&mt('Course ID')).
10636: '<input name="courseid" type="text" size="30" />'.$select_link.
10637: &Apache::lonhtmlcommon::row_closure().
10638: &Apache::lonhtmlcommon::row_title(&mt('Course Name')).
10639: '<input name="coursename" type="text" size="30" />'.$syllabuslink.
10640: &Apache::lonhtmlcommon::row_closure().
10641: &Apache::lonhtmlcommon::row_title(&mt('Domain')).
10642: '<input name="domainid" type="hidden" />'.$domdesc.
1.596.2.12.2. 9(raebur 10643:9): &Apache::lonhtmlcommon::row_closure());
10644:9): if ($formatoptions) {
10645:9): $r->print(&Apache::lonhtmlcommon::row_title($formattitle).$formatoptions.
10646:9): &Apache::lonhtmlcommon::row_closure());
10647:9): }
10648:9): $r->print(
1.565 raeburn 10649: &Apache::lonhtmlcommon::row_title(&mt('File to upload')).
10650: '<input type="file" name="upfile" size="50" />'.
10651: &Apache::lonhtmlcommon::row_closure(1).
10652: &Apache::lonhtmlcommon::end_pick_box().'<br />
10653:
1.492 albertel 10654: <input name="command" value="scantronupload_save" type="hidden" />
1.589 bisitz 10655: <input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
1.157 albertel 10656: </form>
1.492 albertel 10657: ');
1.157 albertel 10658: return '';
10659: }
10660:
1.596.2.12.2. 9(raebur 10661:9): sub scantron_upload_dataformat {
10662:9): my ($dom) = @_;
10663:9): my ($formatoptions,$formattitle,$formatjs);
10664:9): $formatjs = <<'END';
10665:9): function toggleScantab(form) {
10666:9): return;
10667:9): }
10668:9): END
10669:9): my %domconfig = &Apache::lonnet::get_dom('configuration',['scantron'],$dom);
10670:9): if (ref($domconfig{'scantron'}) eq 'HASH') {
10671:9): if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
10672:9): if (keys(%{$domconfig{'scantron'}{'config'}}) > 1) {
10673:9): if (($domconfig{'scantron'}{'config'}{'dat'}) &&
10674:9): (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH')) {
10675:9): if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
10676:9): if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}})) {
10677:9): my ($onclick,$formatextra,$singleline);
10678:9): my @lines = &Apache::lonnet::get_scantronformat_file();
10679:9): my $count = 0;
10680:9): foreach my $line (@lines) {
0.2.1(ra 10681:an-23): next if (($line =~ /^\#/) || ($line eq ''));
9(raebur 10682:9): $singleline = $line;
10683:9): $count ++;
10684:9): }
10685:9): if ($count > 1) {
10686:9): $formatextra = '<div style="display:none" id="bubbletype">'.
10687:9): '<span class="LC_nobreak">'.
4(raebur 10688:0): &mt('Bubblesheet type').': '.
9(raebur 10689:9): &scantron_scantab().'</span></div>';
10690:9): $onclick = ' onclick="toggleScantab(this.form);"';
10691:9): $formatjs = <<"END";
10692:9): function toggleScantab(form) {
10693:9): var divid = 'bubbletype';
10694:9): if (document.getElementById(divid)) {
10695:9): var radioname = 'fileformat';
10696:9): var num = form.elements[radioname].length;
10697:9): if (num) {
10698:9): for (var i=0; i<num; i++) {
10699:9): if (form.elements[radioname][i].checked) {
10700:9): var chosen = form.elements[radioname][i].value;
10701:9): if (chosen == 'dat') {
10702:9): document.getElementById(divid).style.display = 'none';
10703:9): } else if (chosen == 'csv') {
10704:9): document.getElementById(divid).style.display = 'block';
10705:9): }
10706:9): }
10707:9): }
10708:9): }
10709:9): }
10710:9): return;
10711:9): }
10712:9):
10713:9): END
10714:9): } elsif ($count == 1) {
10715:9): my $formatname = (split(/:/,$singleline,2))[0];
10716:9): $formatextra = '<input type="hidden" name="scantron_format" value="'.$formatname.'" />';
10717:9): }
10718:9): $formattitle = &mt('File format');
10719:9): $formatoptions = '<label><input name="fileformat" type="radio" value="dat" checked="checked"'.$onclick.' />'.
10720:9): &mt('Plain Text (no delimiters)').
10721:9): '</label>'.(' 'x2).
10722:9): '<label><input name="fileformat" type="radio" value="csv"'.$onclick.' />'.
10723:9): &mt('Comma separated values').'</label>'.$formatextra;
10724:9): }
10725:9): }
10726:9): }
10727:9): } elsif (keys(%{$domconfig{'scantron'}{'config'}}) == 1) {
10728:9): if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
10729:9): if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}})) {
10730:9): $formattitle = &mt('Bubblesheet type');
10731:9): $formatoptions = &scantron_scantab();
10732:9): }
10733:9): }
10734:9): }
10735:9): }
10736:9): }
10737:9): return ($formatoptions,$formattitle,$formatjs);
10738:9): }
1.423 albertel 10739:
1.157 albertel 10740: sub scantron_upload_scantron_data_save {
1.596.2.12.2. 1(raebur 10741:0): my ($r,$symb) = @_;
1.182 albertel 10742: my $doanotherupload=
10743: '<br /><form action="/adm/grades" method="post">'."\n".
10744: '<input type="hidden" name="command" value="scantronupload" />'."\n".
1.492 albertel 10745: '<input type="submit" name="submit" value="'.&mt('Do Another Upload').'" />'."\n".
1.182 albertel 10746: '</form>'."\n";
1.257 albertel 10747: if (!&Apache::lonnet::allowed('usc',$env{'form.domainid'}) &&
1.162 albertel 10748: !&Apache::lonnet::allowed('usc',
1.257 albertel 10749: $env{'form.domainid'}.'_'.$env{'form.courseid'})) {
1.575 www 10750: $r->print(&mt("You are not allowed to upload bubblesheet data to the requested course.")."<br />");
1.596.2.12.2. 1(raebur 10751:0): unless ($symb) {
1.182 albertel 10752: $r->print($doanotherupload);
10753: }
1.162 albertel 10754: return '';
10755: }
1.257 albertel 10756: my %coursedata=&Apache::lonnet::coursedescription($env{'form.domainid'}.'_'.$env{'form.courseid'});
1.568 raeburn 10757: my $uploadedfile;
1.596.2.12.2. 5(raebur 10758:3): $r->print('<p>'.&mt("Uploading file to [_1]",$coursedata{'description'}).'</p>');
1.257 albertel 10759: if (length($env{'form.upfile'}) < 2) {
1.596.2.12.2. 5(raebur 10760:3): $r->print(
10761:3): &Apache::lonhtmlcommon::confirm_success(
10762:3): &mt('The file: [_1] you attempted to upload contained no information. Please check that you entered the correct filename.',
10763:3): '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'),1));
1.183 albertel 10764: } else {
1.596.2.12.2. 9(raebur 10765:9): my %domconfig = &Apache::lonnet::get_dom('configuration',['scantron'],$env{'form.domainid'});
10766:9): my $parser;
10767:9): if (ref($domconfig{'scantron'}) eq 'HASH') {
10768:9): if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
10769:9): my $is_csv;
10770:9): my @possibles = keys(%{$domconfig{'scantron'}{'config'}});
10771:9): if (@possibles > 1) {
10772:9): if ($env{'form.fileformat'} eq 'csv') {
10773:9): if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
10774:9): if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
10775:9): if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}}) > 1) {
10776:9): $is_csv = 1;
10777:9): }
10778:9): }
10779:9): }
10780:9): }
10781:9): } elsif (@possibles == 1) {
10782:9): if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
10783:9): if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
10784:9): if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}}) > 1) {
10785:9): $is_csv = 1;
10786:9): }
10787:9): }
10788:9): }
10789:9): }
10790:9): if ($is_csv) {
10791:9): $parser = $domconfig{'scantron'}{'config'}{'csv'};
10792:9): }
10793:9): }
10794:9): }
10795:9): my $result =
10796:9): &Apache::lonnet::userfileupload('upfile','scantron','scantron',$parser,'','',
1.568 raeburn 10797: $env{'form.courseid'},$env{'form.domainid'});
10798: if ($result =~ m{^/uploaded/}) {
1.596.2.12.2. 5(raebur 10799:3): $r->print(
10800:3): &Apache::lonhtmlcommon::confirm_success(&mt('Upload successful')).'<br />'.
10801:3): &mt('Uploaded [_1] bytes of data into location: [_2]',
10802:3): (length($env{'form.upfile'})-1),
10803:3): '<span class="LC_filename">'.$result.'</span>'));
1.568 raeburn 10804: ($uploadedfile) = ($result =~ m{/([^/]+)$});
1.567 raeburn 10805: $r->print(&validate_uploaded_scantron_file($env{'form.domainid'},
1.568 raeburn 10806: $env{'form.courseid'},$uploadedfile));
1.210 albertel 10807: } else {
1.596.2.12.2. 5(raebur 10808:3): $r->print(
10809:3): &Apache::lonhtmlcommon::confirm_success(&mt('Upload failed'),1).'<br />'.
10810:3): &mt('An error ([_1]) occurred when attempting to upload the file: [_2]',
10811:3): $result,
1.568 raeburn 10812: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'));
1.183 albertel 10813: }
10814: }
1.174 albertel 10815: if ($symb) {
1.596.2.12.2. 1(raebur 10816:0): $r->print(&scantron_selectphase($r,$uploadedfile,$symb));
1.174 albertel 10817: } else {
1.182 albertel 10818: $r->print($doanotherupload);
1.174 albertel 10819: }
1.157 albertel 10820: return '';
10821: }
10822:
1.567 raeburn 10823: sub validate_uploaded_scantron_file {
10824: my ($cdom,$cname,$fname) = @_;
10825: my $scanlines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.$fname);
10826: my @lines;
10827: if ($scanlines ne '-1') {
10828: @lines=split("\n",$scanlines,-1);
10829: }
10830: my $output;
10831: if (@lines) {
10832: my (%counts,$max_match_format);
1.596.2.12.2. 5(raebur 10833:3): my ($found_match_count,$max_match_count,$max_match_pct) = (0,0,0);
1.567 raeburn 10834: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cname);
10835: my %idmap = &username_to_idmap($classlist);
10836: foreach my $key (keys(%idmap)) {
10837: my $lckey = lc($key);
10838: $idmap{$lckey} = $idmap{$key};
10839: }
10840: my %unique_formats;
1.596.2.12.2. 9(raebur 10841:9): my @formatlines = &Apache::lonnet::get_scantronformat_file();
1.567 raeburn 10842: foreach my $line (@formatlines) {
1.596.2.12.2. 0.2.1(ra 10843:an-23): next if (($line =~ /^\#/) || ($line eq ''));
1.567 raeburn 10844: my @config = split(/:/,$line);
10845: my $idstart = $config[5];
10846: my $idlength = $config[6];
10847: if (($idstart ne '') && ($idlength > 0)) {
10848: if (ref($unique_formats{$idstart.':'.$idlength}) eq 'ARRAY') {
10849: push(@{$unique_formats{$idstart.':'.$idlength}},$config[0].':'.$config[1]);
10850: } else {
10851: $unique_formats{$idstart.':'.$idlength} = [$config[0].':'.$config[1]];
10852: }
10853: }
10854: }
10855: foreach my $key (keys(%unique_formats)) {
10856: my ($idstart,$idlength) = split(':',$key);
10857: %{$counts{$key}} = (
10858: 'found' => 0,
10859: 'total' => 0,
10860: );
10861: foreach my $line (@lines) {
10862: next if ($line =~ /^#/);
10863: next if ($line =~ /^[\s\cz]*$/);
10864: my $id = substr($line,$idstart-1,$idlength);
10865: $id = lc($id);
10866: if (exists($idmap{$id})) {
10867: $counts{$key}{'found'} ++;
10868: }
10869: $counts{$key}{'total'} ++;
10870: }
10871: if ($counts{$key}{'total'}) {
10872: my $percent_match = (100*$counts{$key}{'found'})/($counts{$key}{'total'});
10873: if (($max_match_format eq '') || ($percent_match > $max_match_pct)) {
10874: $max_match_pct = $percent_match;
10875: $max_match_format = $key;
1.596.2.12.2. 5(raebur 10876:3): $found_match_count = $counts{$key}{'found'};
1.567 raeburn 10877: $max_match_count = $counts{$key}{'total'};
10878: }
10879: }
10880: }
10881: if (ref($unique_formats{$max_match_format}) eq 'ARRAY') {
10882: my $format_descs;
10883: my $numwithformat = @{$unique_formats{$max_match_format}};
10884: for (my $i=0; $i<$numwithformat; $i++) {
10885: my ($name,$desc) = split(':',$unique_formats{$max_match_format}[$i]);
10886: if ($i<$numwithformat-2) {
10887: $format_descs .= '"<i>'.$desc.'</i>", ';
10888: } elsif ($i==$numwithformat-2) {
10889: $format_descs .= '"<i>'.$desc.'</i>" '.&mt('and').' ';
10890: } elsif ($i==$numwithformat-1) {
10891: $format_descs .= '"<i>'.$desc.'</i>"';
10892: }
10893: }
10894: my $showpct = sprintf("%.0f",$max_match_pct).'%';
1.596.2.12.2. 5(raebur 10895:3): $output .= '<br />';
10896:3): if ($found_match_count == $max_match_count) {
10897:3): # 100% matching entries
10898:3): $output .= &Apache::lonhtmlcommon::confirm_success(
10899:3): &mt('Comparison of student IDs: [_1] matching ([quant,_2,entry,entries])',
10900:3): '<b>'.$showpct.'</b>',$found_match_count)).'<br />'.
10901:3): &mt('Comparison of student IDs in the uploaded file with'.
10902:3): ' the course roster found matches for [_1] of the [_2] entries'.
10903:3): ' in the file (for the format defined for [_3]).',
10904:3): '<b>'.$showpct.'</b>','<b>'.$max_match_count.'</b>',$format_descs);
10905:3): } else {
10906:3): # Not all entries matching? -> Show warning and additional info
10907:3): $output .=
10908:3): &Apache::lonhtmlcommon::confirm_success(
10909:3): &mt('Comparison of student IDs: [_1] matching ([_2]/[quant,_3,entry,entries])',
10910:3): '<b>'.$showpct.'</b>',$found_match_count,$max_match_count).'<br />'.
10911:3): &mt('Not all entries could be matched!'),1).'<br />'.
10912:3): &mt('Comparison of student IDs in the uploaded file with'.
10913:3): ' the course roster found matches for [_1] of the [_2] entries'.
10914:3): ' in the file (for the format defined for [_3]).',
10915:3): '<b>'.$showpct.'</b>','<b>'.$max_match_count.'</b>',$format_descs).
10916:3): '<p class="LC_info">'.
10917:3): &mt('A low percentage of matches results from one of the following:').
10918:3): '</p><ul>'.
10919:3): '<li>'.&mt('The file was uploaded to the wrong course.').'</li>'.
10920:3): '<li>'.&mt('The data is not in the format expected for the domain: [_1]',
10921:3): '<i>'.$cdom.'</i>').'</li>'.
10922:3): '<li>'.&mt('Students did not bubble their IDs, or mis-bubbled them').'</li>'.
10923:3): '<li>'.&mt('The course roster is not up to date.').'</li>'.
10924:3): '</ul>';
10925:3): }
1.567 raeburn 10926: }
10927: } else {
1.596.2.12.2. 5(raebur 10928:3): $output = '<p class="LC_warning">'.&mt('Uploaded file contained no data').'</p>';
1.567 raeburn 10929: }
10930: return $output;
10931: }
10932:
1.202 albertel 10933: sub valid_file {
10934: my ($requested_file)=@_;
10935: foreach my $filename (sort(&scantron_filenames())) {
10936: if ($requested_file eq $filename) { return 1; }
10937: }
10938: return 0;
10939: }
10940:
10941: sub scantron_download_scantron_data {
1.596.2.12.2. 1(raebur 10942:0): my ($r,$symb) = @_;
(raeburn 10943:): my $default_form_data=&defaultFormData($symb);
1.257 albertel 10944: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
10945: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
10946: my $file=$env{'form.scantron_selectfile'};
1.202 albertel 10947: if (! &valid_file($file)) {
1.492 albertel 10948: $r->print('
1.202 albertel 10949: <p>
1.596.2.12.2. 3(raebur 10950:3): '.&mt('The requested filename was invalid.').'
1.202 albertel 10951: </p>
1.492 albertel 10952: ');
1.202 albertel 10953: return;
10954: }
10955: my $orig='/uploaded/'.$cdom.'/'.$cname.'/scantron_orig_'.$file;
10956: my $corrected='/uploaded/'.$cdom.'/'.$cname.'/scantron_corrected_'.$file;
10957: my $skipped='/uploaded/'.$cdom.'/'.$cname.'/scantron_skipped_'.$file;
10958: &Apache::lonnet::allowuploaded('/adm/grades',$orig);
10959: &Apache::lonnet::allowuploaded('/adm/grades',$corrected);
10960: &Apache::lonnet::allowuploaded('/adm/grades',$skipped);
1.492 albertel 10961: $r->print('
1.202 albertel 10962: <p>
1.596.2.12.2. 1(raebur 10963:0): '.&mt('[_1]Original[_2] file as uploaded by the bubblesheet scanning office.',
1.492 albertel 10964: '<a href="'.$orig.'">','</a>').'
1.202 albertel 10965: </p>
10966: <p>
1.492 albertel 10967: '.&mt('[_1]Corrections[_2], a file of corrected records that were used in grading.',
10968: '<a href="'.$corrected.'">','</a>').'
1.202 albertel 10969: </p>
10970: <p>
1.492 albertel 10971: '.&mt('[_1]Skipped[_2], a file of records that were skipped.',
10972: '<a href="'.$skipped.'">','</a>').'
1.202 albertel 10973: </p>
1.492 albertel 10974: ');
1.202 albertel 10975: return '';
10976: }
1.157 albertel 10977:
1.523 raeburn 10978: sub checkscantron_results {
1.596.2.12.2. 1(raebur 10979:0): my ($r,$symb) = @_;
1.523 raeburn 10980: if (!$symb) {return '';}
10981: my $cid = $env{'request.course.id'};
1.596.2.12.2. 9(raebur 10982:9): my %lettdig = &Apache::lonnet::letter_to_digits();
1.523 raeburn 10983: my $numletts = scalar(keys(%lettdig));
10984: my $cnum = $env{'course.'.$cid.'.num'};
10985: my $cdom = $env{'course.'.$cid.'.domain'};
10986: my (undef, undef, $sequence) = &Apache::lonnet::decode_symb($env{'form.selectpage'});
10987: my %record;
10988: my %scantron_config =
1.596.2.12.2. 9(raebur 10989:9): &Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
(raeburn 10990:): my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
1.523 raeburn 10991: my ($scanlines,$scan_data)=&Apache::grades::scantron_getfile();
10992: my $classlist=&Apache::loncoursedata::get_classlist();
10993: my %idmap=&Apache::grades::username_to_idmap($classlist);
10994: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 10995: unless (ref($navmap)) {
10996: $r->print(&navmap_errormsg());
10997: return '';
10998: }
1.523 raeburn 10999: my $map=$navmap->getResourceByUrl($sequence);
1.596.2.12.2. 6(raebur 11000:3): my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
11001:3): %grader_randomlists_by_symb,%orderedforcode);
1(raebur 11002:2): if (ref($map)) {
11003:2): $randomorder=$map->randomorder();
7(raebur 11004:3): $randompick=$map->randompick();
0(raebur 11005:2): unless ($randomorder || $randompick) {
11006:2): foreach my $res ($navmap->retrieveResources($map,sub { $_[0]->is_map() },1,0,1)) {
11007:2): if ($res->randomorder()) {
11008:2): $randomorder = 1;
11009:2): }
11010:2): if ($res->randompick()) {
11011:2): $randompick = 1;
11012:2): }
11013:2): last if ($randomorder || $randompick);
11014:2): }
11015:2): }
1(raebur 11016:2): }
1.557 raeburn 11017: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.596.2.12.2. 6(raebur 11018:3): my $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource);
11019:3): if ($nav_error) {
11020:3): $r->print(&navmap_errormsg());
11021:3): return '';
1(raebur 11022:2): }
(raeburn 11023:): &graders_resources_pass(\@resources,\%grader_partids_by_symb,
11024:): \%grader_randomlists_by_symb,$bubbles_per_row);
1.554 raeburn 11025: my ($uname,$udom);
1.523 raeburn 11026: my (%scandata,%lastname,%bylast);
11027: $r->print('
11028: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="checkscantron">'."\n");
11029:
11030: my @delayqueue;
11031: my %completedstudents;
11032:
1.596.2.12.2. 6(raebur 11033:3): my $count=&get_todo_count($scanlines,$scan_data);
(raeburn 11034:): my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$count);
6(raebur 11035:3): my ($username,$domain,$started);
(raeburn 11036:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # Need the bubble lines array to parse.
1.582 raeburn 11037: if ($nav_error) {
11038: $r->print(&navmap_errormsg());
11039: return '';
11040: }
1.523 raeburn 11041:
11042: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
11043: 'Processing first student');
11044: my $start=&Time::HiRes::time();
11045: my $i=-1;
11046:
11047: while ($i<$scanlines->{'count'}) {
11048: ($username,$domain,$uname)=('','','');
11049: $i++;
11050: my $line=&Apache::grades::scantron_get_line($scanlines,$scan_data,$i);
11051: if ($line=~/^[\s\cz]*$/) { next; }
11052: if ($started) {
11053: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
11054: 'last student');
11055: }
11056: $started=1;
11057: my $scan_record=
11058: &Apache::grades::scantron_parse_scanline($line,$i,\%scantron_config,
11059: $scan_data);
1.596.2.12.2. 6(raebur 11060:3): unless ($uname=&scantron_find_student($scan_record,$scan_data,
11061:3): \%idmap,$i)) {
1.523 raeburn 11062: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
11063: 'Unable to find a student that matches',1);
11064: next;
11065: }
11066: if (exists $completedstudents{$uname}) {
11067: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
11068: 'Student '.$uname.' has multiple sheets',2);
11069: next;
11070: }
11071: my $pid = $scan_record->{'scantron.ID'};
11072: $lastname{$pid} = $scan_record->{'scantron.LastName'};
11073: push(@{$bylast{$lastname{$pid}}},$pid);
1.596.2.12.2. 1(raebur 11074:2): my $usec = $classlist->{$uname}->[&Apache::loncoursedata::CL_SECTION];
11075:2): my $user = $uname.':'.$usec;
1.523 raeburn 11076: ($username,$domain)=split(/:/,$uname);
1.596.2.12.2. 1(raebur 11077:2):
11078:2): my $scancode;
11079:2): if ((exists($scan_record->{'scantron.CODE'})) &&
11080:2): (&Apache::lonnet::validCODE($scan_record->{'scantron.CODE'}))) {
11081:2): $scancode = $scan_record->{'scantron.CODE'};
11082:2): } else {
11083:2): $scancode = '';
11084:2): }
11085:2):
11086:2): my @mapresources = @resources;
6(raebur 11087:3): my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
11088:3): my %respnumlookup=();
11089:3): my %startline=();
11090:3): if ($randomorder || $randompick) {
1(raebur 11091:2): @mapresources =
6(raebur 11092:3): &users_order($user,$scancode,$sequence,\@master_seq,\%symb_to_resource,
11093:3): \%orderedforcode);
11094:3): my $total = &get_respnum_lookups($sequence,$scan_data,\%idmap,$line,
11095:3): $scan_record,\@master_seq,\%symb_to_resource,
11096:3): \%grader_partids_by_symb,\%orderedforcode,
11097:3): \%respnumlookup,\%startline);
11098:3): if ($randompick && $total) {
11099:3): $lastpos = $total*$scantron_config{'Qlength'};
11100:3): }
1(raebur 11101:2): }
6(raebur 11102:3): $scandata{$pid} = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
11103:3): chomp($scandata{$pid});
11104:3): $scandata{$pid} =~ s/\r$//;
11105:3):
1.523 raeburn 11106: my $counter = -1;
1.596.2.12.2. 1(raebur 11107:2): foreach my $resource (@mapresources) {
1.557 raeburn 11108: my $parts;
1.554 raeburn 11109: my $ressymb = $resource->symb();
1.557 raeburn 11110: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
11111: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
1.596.2.12.2. 1(raebur 11112:7): my $currcode;
11113:7): if (exists($grader_randomlists_by_symb{$ressymb})) {
11114:7): $currcode = $scancode;
11115:7): }
1.557 raeburn 11116: (my $analysis,$parts) =
1.596.2.12.2. (raeburn 11117:): &scantron_partids_tograde($resource,$env{'request.course.id'},
11118:): $username,$domain,undef,
1(raebur 11119:7): $bubbles_per_row,$currcode);
1.557 raeburn 11120: } else {
11121: $parts = $grader_partids_by_symb{$ressymb};
11122: }
1.542 raeburn 11123: ($counter,my $recording) =
11124: &verify_scantron_grading($resource,$domain,$username,$cid,$counter,
1.554 raeburn 11125: $scandata{$pid},$parts,
1.596.2.12.2. 6(raebur 11126:3): \%scantron_config,\%lettdig,$numletts,
11127:3): $randomorder,$randompick,
11128:3): \%respnumlookup,\%startline);
1.542 raeburn 11129: $record{$pid} .= $recording;
1.523 raeburn 11130: }
11131: }
11132: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
11133: $r->print('<br />');
11134: my ($okstudents,$badstudents,$numstudents,$passed,$failed);
11135: $passed = 0;
11136: $failed = 0;
11137: $numstudents = 0;
11138: foreach my $last (sort(keys(%bylast))) {
11139: if (ref($bylast{$last}) eq 'ARRAY') {
11140: foreach my $pid (sort(@{$bylast{$last}})) {
11141: my $showscandata = $scandata{$pid};
11142: my $showrecord = $record{$pid};
11143: $showscandata =~ s/\s/ /g;
11144: $showrecord =~ s/\s/ /g;
11145: if ($scandata{$pid} eq $record{$pid}) {
11146: my $css_class = ($passed % 2)?'LC_odd_row':'LC_even_row';
11147: $okstudents .= '<tr class="'.$css_class.'">'.
1.581 www 11148: '<td>'.&mt('Bubblesheet').'</td><td>'.$showscandata.'</td><td rowspan="2">'.$last.'</td><td rowspan="2">'.$pid.'</td>'."\n".
1.523 raeburn 11149: '</tr>'."\n".
11150: '<tr class="'.$css_class.'">'."\n".
1.596.2.12.2. 8(raebur 11151:4): '<td>'.&mt('Submissions').'</td><td>'.$showrecord.'</td></tr>'."\n";
1.523 raeburn 11152: $passed ++;
11153: } else {
11154: my $css_class = ($failed % 2)?'LC_odd_row':'LC_even_row';
1.581 www 11155: $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 11156: '</tr>'."\n".
11157: '<tr class="'.$css_class.'">'."\n".
1.596.2.12.2. 8(raebur 11158:4): '<td>'.&mt('Submissions').'</td><td><span class="LC_nobreak">'.$record{$pid}.'</span></td>'."\n".
1.523 raeburn 11159: '</tr>'."\n";
11160: $failed ++;
11161: }
11162: $numstudents ++;
11163: }
11164: }
11165: }
1.596.2.4 raeburn 11166: $r->print('<p>'.
1.596.2.8 raeburn 11167: &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).',
1.596.2.4 raeburn 11168: '<b>',
11169: $numstudents,
11170: '</b>',
11171: $env{'form.scantron_maxbubble'}).
11172: '</p>'
11173: );
1.596.2.12.2. 2(raebur 11174:2): $r->print('<p>'
11175:2): .&mt('Exact matches for [_1][quant,_2,student][_3].','<b>',$passed,'</b>')
11176:2): .'<br />'
11177:2): .&mt('Discrepancies detected for [_1][quant,_2,student][_3].','<b>',$failed,'</b>')
11178:2): .'</p>');
1.523 raeburn 11179: if ($passed) {
1.572 www 11180: $r->print(&mt('Students with exact correspondence between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 11181: $r->print(&Apache::loncommon::start_data_table()."\n".
11182: &Apache::loncommon::start_data_table_header_row()."\n".
11183: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
11184: &Apache::loncommon::end_data_table_header_row()."\n".
11185: $okstudents."\n".
11186: &Apache::loncommon::end_data_table().'<br />');
11187: }
11188: if ($failed) {
1.572 www 11189: $r->print(&mt('Students with differences between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 11190: $r->print(&Apache::loncommon::start_data_table()."\n".
11191: &Apache::loncommon::start_data_table_header_row()."\n".
11192: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
11193: &Apache::loncommon::end_data_table_header_row()."\n".
11194: $badstudents."\n".
11195: &Apache::loncommon::end_data_table()).'<br />'.
1.572 www 11196: &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 11197: }
1.596.2.12.2. 1(raebur 11198:0): $r->print('</form><br />');
1.523 raeburn 11199: return;
11200: }
11201:
1.542 raeburn 11202: sub verify_scantron_grading {
1.554 raeburn 11203: my ($resource,$domain,$username,$cid,$counter,$scandata,$partids,
1.596.2.12.2. 6(raebur 11204:3): $scantron_config,$lettdig,$numletts,$randomorder,$randompick,
11205:3): $respnumlookup,$startline) = @_;
1.542 raeburn 11206: my ($record,%expected,%startpos);
11207: return ($counter,$record) if (!ref($resource));
11208: return ($counter,$record) if (!$resource->is_problem());
11209: my $symb = $resource->symb();
1.554 raeburn 11210: return ($counter,$record) if (ref($partids) ne 'ARRAY');
11211: foreach my $part_id (@{$partids}) {
1.542 raeburn 11212: $counter ++;
11213: $expected{$part_id} = 0;
1.596.2.12.2. 6(raebur 11214:3): my $respnum = $counter;
11215:3): if ($randomorder || $randompick) {
11216:3): $respnum = $respnumlookup->{$counter};
11217:3): $startpos{$part_id} = $startline->{$counter} + 1;
11218:3): } else {
11219:3): $startpos{$part_id} = $env{"form.scantron.first_bubble_line.$counter"};
11220:3): }
11221:3): if ($env{"form.scantron.sub_bubblelines.$respnum"}) {
11222:3): my @sub_lines = split(/,/,$env{"form.scantron.sub_bubblelines.$respnum"});
1.542 raeburn 11223: foreach my $item (@sub_lines) {
11224: $expected{$part_id} += $item;
11225: }
11226: } else {
1.596.2.12.2. 6(raebur 11227:3): $expected{$part_id} = $env{"form.scantron.bubblelines.$respnum"};
1.542 raeburn 11228: }
11229: }
11230: if ($symb) {
11231: my %recorded;
11232: my (%returnhash) = &Apache::lonnet::restore($symb,$cid,$domain,$username);
11233: if ($returnhash{'version'}) {
11234: my %lasthash=();
11235: my $version;
11236: for ($version=1;$version<=$returnhash{'version'};$version++) {
11237: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
11238: $lasthash{$key}=$returnhash{$version.':'.$key};
11239: }
11240: }
11241: foreach my $key (keys(%lasthash)) {
11242: if ($key =~ /\.scantron$/) {
11243: my $value = &unescape($lasthash{$key});
11244: my ($part_id) = ($key =~ /^resource\.(.+)\.scantron$/);
11245: if ($value eq '') {
11246: for (my $i=0; $i<$expected{$part_id}; $i++) {
11247: for (my $j=0; $j<$scantron_config->{'length'}; $j++) {
11248: $recorded{$part_id} .= $scantron_config->{'Qoff'};
11249: }
11250: }
11251: } else {
11252: my @tocheck;
11253: my @items = split(//,$value);
11254: if (($scantron_config->{'Qon'} eq 'letter') ||
11255: ($scantron_config->{'Qon'} eq 'number')) {
11256: if (@items < $expected{$part_id}) {
11257: my $fragment = substr($scandata,$startpos{$part_id},$expected{$part_id});
11258: my @singles = split(//,$fragment);
11259: foreach my $pos (@singles) {
11260: if ($pos eq ' ') {
11261: push(@tocheck,$pos);
11262: } else {
11263: my $next = shift(@items);
11264: push(@tocheck,$next);
11265: }
11266: }
11267: } else {
11268: @tocheck = @items;
11269: }
11270: foreach my $letter (@tocheck) {
11271: if ($scantron_config->{'Qon'} eq 'letter') {
11272: if ($letter !~ /^[A-J]$/) {
11273: $letter = $scantron_config->{'Qoff'};
11274: }
11275: $recorded{$part_id} .= $letter;
11276: } elsif ($scantron_config->{'Qon'} eq 'number') {
11277: my $digit;
11278: if ($letter !~ /^[A-J]$/) {
11279: $digit = $scantron_config->{'Qoff'};
11280: } else {
11281: $digit = $lettdig->{$letter};
11282: }
11283: $recorded{$part_id} .= $digit;
11284: }
11285: }
11286: } else {
11287: @tocheck = @items;
11288: for (my $i=0; $i<$expected{$part_id}; $i++) {
11289: my $curr_sub = shift(@tocheck);
11290: my $digit;
11291: if ($curr_sub =~ /^[A-J]$/) {
11292: $digit = $lettdig->{$curr_sub}-1;
11293: }
11294: if ($curr_sub eq 'J') {
11295: $digit += scalar($numletts);
11296: }
11297: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
11298: if ($j == $digit) {
11299: $recorded{$part_id} .= $scantron_config->{'Qon'};
11300: } else {
11301: $recorded{$part_id} .= $scantron_config->{'Qoff'};
11302: }
11303: }
11304: }
11305: }
11306: }
11307: }
11308: }
11309: }
1.554 raeburn 11310: foreach my $part_id (@{$partids}) {
1.542 raeburn 11311: if ($recorded{$part_id} eq '') {
11312: for (my $i=0; $i<$expected{$part_id}; $i++) {
11313: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
11314: $recorded{$part_id} .= $scantron_config->{'Qoff'};
11315: }
11316: }
11317: }
11318: $record .= $recorded{$part_id};
11319: }
11320: }
11321: return ($counter,$record);
11322: }
11323:
1.75 albertel 11324: #-------- end of section for handling grading scantron forms -------
11325: #
11326: #-------------------------------------------------------------------
11327:
1.72 ng 11328: #-------------------------- Menu interface -------------------------
11329: #
1.596.2.12.2. (raeburn 11330:): #--- Href with symb and command ---
11331:):
11332:): sub href_symb_cmd {
11333:): my ($symb,$cmd)=@_;
0.2.7(ra 11334:an-25): return '/adm/grades?symb='.&HTML::Entities::encode(&Apache::lonenc::check_encrypt($symb),'<>&"').'&command='.
11335:an-25): &HTML::Entities::encode($cmd,'<>&"');
(raeburn 11336:): }
11337:):
1.443 banghart 11338: sub grading_menu {
1.596.2.12.2. 1(raebur 11339:0): my ($request,$symb) = @_;
1.443 banghart 11340: if (!$symb) {return '';}
11341:
11342: my %fields = ('symb'=>&Apache::lonenc::check_encrypt($symb),
1.596.2.12.2. 1(raebur 11343:0): 'command'=>'individual');
11344:0):
11345:0): my $url1a = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
11346:0):
11347:0): $fields{'command'}='ungraded';
11348:0): my $url1b=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
11349:0):
11350:0): $fields{'command'}='table';
11351:0): my $url1c=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
11352:0):
11353:0): $fields{'command'}='all_for_one';
11354:0): my $url1d=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
11355:0):
11356:0): $fields{'command'}='downloadfilesselect';
11357:0): my $url1e=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
1.538 schulted 11358:
1.443 banghart 11359: $fields{'command'} = 'csvform';
1.538 schulted 11360: my $url2 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
11361:
1.443 banghart 11362: $fields{'command'} = 'processclicker';
1.538 schulted 11363: my $url3 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
11364:
1.443 banghart 11365: $fields{'command'} = 'scantron_selectphase';
1.538 schulted 11366: my $url4 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
1.596.2.12.2. 1(raebur 11367:0):
11368:0): $fields{'command'} = 'initialverifyreceipt';
11369:0): my $url5 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
6(raebur 11370:1):
11371:1): my %permissions;
11372:1): if ($perm{'mgr'}) {
11373:1): $permissions{'either'} = 'F';
11374:1): $permissions{'mgr'} = 'F';
11375:1): }
11376:1): if ($perm{'vgr'}) {
11377:1): $permissions{'either'} = 'F';
11378:1): $permissions{'vgr'} = 'F';
11379:1): }
11380:1):
1(raebur 11381:0): my @menu = ({ categorytitle=>'Hand Grading',
1.538 schulted 11382: items =>[
1.596.2.12.2. 1(raebur 11383:0): { linktext => 'Select individual students to grade',
11384:0): url => $url1a,
6(raebur 11385:1): permission => $permissions{'either'},
1(raebur 11386:0): icon => 'grade_students.png',
11387:0): linktitle => 'Grade current resource for a selection of students.'
11388:0): },
11389:0): { linktext => 'Grade ungraded submissions',
11390:0): url => $url1b,
6(raebur 11391:1): permission => $permissions{'either'},
1(raebur 11392:0): icon => 'ungrade_sub.png',
11393:0): linktitle => 'Grade all submissions that have not been graded yet.'
11394:0): },
11395:0):
11396:0): { linktext => 'Grading table',
11397:0): url => $url1c,
6(raebur 11398:1): permission => $permissions{'either'},
1(raebur 11399:0): icon => 'grading_table.png',
11400:0): linktitle => 'Grade current resource for all students.'
11401:0): },
11402:0): { linktext => 'Grade page/folder for one student',
11403:0): url => $url1d,
6(raebur 11404:1): permission => $permissions{'either'},
1(raebur 11405:0): icon => 'grade_PageFolder.png',
11406:0): linktitle => 'Grade all resources in current page/sequence/folder for one student.'
1.538 schulted 11407: },
1.596.2.12.2. 3(raebur 11408:0): { linktext => 'Download submitted files',
1(raebur 11409:0): url => $url1e,
6(raebur 11410:1): permission => $permissions{'either'},
1(raebur 11411:0): icon => 'download_sub.png',
3(raebur 11412:0): linktitle => 'Download all files submitted by students.'
1(raebur 11413:0): }]},
11414:0): { categorytitle=>'Automated Grading',
11415:0): items =>[
11416:0):
1.538 schulted 11417: { linktext => 'Upload Scores',
11418: url => $url2,
1.596.2.12.2. 6(raebur 11419:1): permission => $permissions{'mgr'},
1.538 schulted 11420: icon => 'uploadscores.png',
11421: linktitle => 'Specify a file containing the class scores for current resource.'
11422: },
11423: { linktext => 'Process Clicker',
11424: url => $url3,
1.596.2.12.2. 6(raebur 11425:1): permission => $permissions{'mgr'},
1.538 schulted 11426: icon => 'addClickerInfoFile.png',
11427: linktitle => 'Specify a file containing the clicker information for this resource.'
11428: },
1.587 raeburn 11429: { linktext => 'Grade/Manage/Review Bubblesheets',
1.538 schulted 11430: url => $url4,
1.596.2.12.2. 6(raebur 11431:1): permission => $permissions{'mgr'},
1(raebur 11432:0): icon => 'bubblesheet.png',
1.596.2.4 raeburn 11433: linktitle => 'Grade bubblesheet exams, upload/download bubblesheet data files, and review previously graded bubblesheet exams.'
1.596.2.12.2. 1(raebur 11434:0): },
11435:0): { linktext => 'Verify Receipt Number',
11436:0): url => $url5,
6(raebur 11437:1): permission => $permissions{'either'},
1(raebur 11438:0): icon => 'receipt_number.png',
11439:0): linktitle => 'Verify a system-generated receipt number for correct problem solution.'
11440:0): }
11441:0):
1.538 schulted 11442: ]
11443: });
1.596.2.12.2. 0.2.7(ra 11444:an-25): my $cdom = $env{"course.$env{'request.course.id'}.domain"};
11445:an-25): my $cnum = $env{"course.$env{'request.course.id'}.num"};
11446:an-25): my %passback = &Apache::lonnet::dump('nohist_linkprot_passback',$cdom,$cnum);
11447:an-25): if (keys(%passback)) {
11448:an-25): $fields{'command'} = 'initialpassback';
11449:an-25): my $url6 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
11450:an-25): push (@{$menu[1]{items}},
11451:an-25): { linktext => 'Passback of Scores',
11452:an-25): url => $url6,
11453:an-25): permission => $permissions{'either'},
11454:an-25): icon => 'passback.png',
11455:an-25): linktitle => 'Passback scores to launcher CMS for resources accessed via LTI-mediated deep-linking',
11456:an-25): });
11457:an-25): }
1.443 banghart 11458: # Create the menu
11459: my $Str;
1.445 banghart 11460: $Str .= '<form method="post" action="" name="gradingMenu">';
11461: $Str .= '<input type="hidden" name="command" value="" />'.
1.596.2.12.2. 1(raebur 11462:0): '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.443 banghart 11463:
1.596.2.12.2. 1(raebur 11464:0): $Str .= &Apache::lonhtmlcommon::generate_menu(@menu);
1.443 banghart 11465: return $Str;
11466: }
11467:
1.596.2.12.2. 1(raebur 11468:0): sub ungraded {
11469:0): my ($request)=@_;
11470:0): &submit_options($request);
11471:0): }
1.443 banghart 11472:
1.596.2.12.2. 1(raebur 11473:0): sub submit_options_sequence {
11474:0): my ($request,$symb) = @_;
1.72 ng 11475: if (!$symb) {return '';}
1.596.2.12.2. 1(raebur 11476:0): &commonJSfunctions($request);
11477:0): my $result;
1.72 ng 11478:
1.596.2.12.2. 1(raebur 11479:0): $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
11480:0): '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
11481:0): $result.=&selectfield(0).
11482:0): '<input type="hidden" name="command" value="pickStudentPage" />
11483:0): <div>
11484:0): <input type="submit" value="'.&mt('Next').' →" />
11485:0): </div>
11486:0): </div>
11487:0): </form>';
11488:0): return $result;
11489:0): }
11490:0):
11491:0): sub submit_options_table {
11492:0): my ($request,$symb) = @_;
11493:0): if (!$symb) {return '';}
1.118 ng 11494: &commonJSfunctions($request);
1.596.2.12.2. 0.2.4(ra 11495:ul-23): my $is_tool = ($symb =~ /ext\.tool$/);
1.473 albertel 11496: my $result;
1.596.2.12.2. 1(raebur 11497:0):
11498:0): $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
11499:0): '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
11500:0):
0.2.4(ra 11501:ul-23): $result.=&selectfield(1,$is_tool).
1(raebur 11502:0): '<input type="hidden" name="command" value="viewgrades" />
11503:0): <div>
11504:0): <input type="submit" value="'.&mt('Next').' →" />
11505:0): </div>
11506:0): </div>
11507:0): </form>';
11508:0): return $result;
11509:0): }
11510:0):
11511:0): sub submit_options_download {
11512:0): my ($request,$symb) = @_;
11513:0): if (!$symb) {return '';}
11514:0):
11515:0): my $res_error;
11516:0): my ($partlist,$handgrade,$responseType,$numresp,$numessay,$numdropbox) =
11517:0): &response_type($symb,\$res_error);
11518:0): if ($res_error) {
11519:0): $request->print(&mt('An error occurred retrieving response types'));
11520:0): return;
11521:0): }
11522:0): unless ($numessay) {
11523:0): $request->print(&mt('No essayresponse items found'));
11524:0): return;
11525:0): }
11526:0): my $table;
11527:0): if (ref($partlist) eq 'ARRAY') {
11528:0): if (scalar(@$partlist) > 1 ) {
11529:0): $table = &showResourceInfo($symb,$partlist,$responseType,'gradingMenu',1,1);
1.533 bisitz 11530: }
11531: }
11532:
1.596.2.12.2. 0.2.4(ra 11533:ul-23): my $is_tool = ($symb =~ /ext\.tool$/);
1(raebur 11534:0): &commonJSfunctions($request);
1.72 ng 11535:
1.596.2.12.2. 1(raebur 11536:0): my $result='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
11537:0): $table."\n".
11538:0): '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.472 albertel 11539: $result.='
1.533 bisitz 11540: <h2>
1.596.2.12.2. 3(raebur 11541:0): '.&mt('Select Students for whom to Download Submitted Files').'
0.2.4(ra 11542:ul-23): </h2>'.&selectfield(1,$is_tool).'
1(raebur 11543:0): <input type="hidden" name="command" value="downloadfileslink" />
11544:0): <input type="submit" value="'.&mt('Next').' →" />
11545:0): </div>
11546:0): </div>
11547:0):
11548:0):
11549:0): </form>';
11550:0): return $result;
11551:0): }
11552:0):
11553:0): #--- Displays the submissions first page -------
11554:0): sub submit_options {
11555:0): my ($request,$symb) = @_;
11556:0): if (!$symb) {return '';}
11557:0):
0.2.4(ra 11558:ul-23): my $is_tool = ($symb =~ /ext\.tool$/);
1(raebur 11559:0): &commonJSfunctions($request);
11560:0): my $result;
11561:0):
11562:0): $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
11563:0): '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
0.2.4(ra 11564:ul-23): $result.=&selectfield(1,$is_tool).'
1(raebur 11565:0): <input type="hidden" name="command" value="submission" />
11566:0): <input type="submit" value="'.&mt('Next').' →" />
11567:0): </div>
11568:0): </div>
11569:0): </form>';
11570:0): return $result;
11571:0): }
11572:0):
11573:0): sub selectfield {
0.2.4(ra 11574:ul-23): my ($full,$is_tool)=@_;
11575:ul-23): my %options;
11576:ul-23): if ($is_tool) {
11577:ul-23): %options =
11578:ul-23): (&transtatus_options,
11579:ul-23): 'select_form_order' => ['yes','incorrect','all']);
11580:ul-23): } else {
11581:ul-23): %options =
11582:ul-23): (&substatus_options,
11583:ul-23): 'select_form_order' => ['yes','queued','graded','incorrect','all']);
11584:ul-23): }
7(raebur 11585:1):
11586:1): #
11587:1): # PrepareClasslist() needs to be called to avoid getting a sections list
11588:1): # for a different course from the @Sections global in lonstatistics.pm,
11589:1): # populated by an earlier request.
11590:1): #
11591:1): &Apache::lonstatistics::PrepareClasslist();
11592:1):
1(raebur 11593:0): my $result='<div class="LC_columnSection">
1.533 bisitz 11594:
11595: <fieldset>
11596: <legend>
11597: '.&mt('Sections').'
11598: </legend>
1.596.2.12.2. 1(raebur 11599:0): '.&Apache::lonstatistics::SectionSelect('section','multiple',5).'
1.533 bisitz 11600: </fieldset>
1.596.2.12.2. 1(raebur 11601:0):
1.533 bisitz 11602: <fieldset>
11603: <legend>
11604: '.&mt('Groups').'
11605: </legend>
11606: '.&Apache::lonstatistics::GroupSelect('group','multiple',5).'
11607: </fieldset>
1.596.2.12.2. 1(raebur 11608:0):
1.533 bisitz 11609: <fieldset>
11610: <legend>
11611: '.&mt('Access Status').'
11612: </legend>
1.596.2.12.2. 1(raebur 11613:0): '.&Apache::lonhtmlcommon::StatusOptions(undef,undef,5,undef,'mult').'
11614:0): </fieldset>';
11615:0): if ($full) {
0.2.4(ra 11616:ul-23): my $heading = &mt('Submission Status');
11617:ul-23): if ($is_tool) {
11618:ul-23): $heading = &mt('Transaction Status');
11619:ul-23): }
1(raebur 11620:0): $result.='
1.533 bisitz 11621: <fieldset>
11622: <legend>
1.596.2.12.2. 0.2.4(ra 11623:ul-23): '.$heading.'
1(raebur 11624:0): </legend>'.
11625:0): &Apache::loncommon::select_form('all','submitonly',\%options).
11626:0): '</fieldset>';
11627:0): }
11628:0): $result.='</div><br />';
1.44 ng 11629: return $result;
1.2 albertel 11630: }
11631:
1.596.2.12.2. 7(raebur 11632:6): sub substatus_options {
11633:6): return &Apache::lonlocal::texthash(
11634:6): 'yes' => 'with submissions',
11635:6): 'queued' => 'in grading queue',
11636:6): 'graded' => 'with ungraded submissions',
11637:6): 'incorrect' => 'with incorrect submissions',
0(raebur 11638:7): 'all' => 'with any status',
11639:7): );
7(raebur 11640:6): }
11641:6):
1(raebur 11642:0): sub transtatus_options {
11643:0): return &Apache::lonlocal::texthash(
11644:0): 'yes' => 'with score transactions',
11645:0): 'incorrect' => 'with less than full credit',
11646:0): 'all' => 'with any status',
11647:0): );
11648:0): }
11649:0):
1.285 albertel 11650: sub reset_perm {
11651: undef(%perm);
11652: }
11653:
11654: sub init_perm {
11655: &reset_perm();
1.300 albertel 11656: foreach my $test_perm ('vgr','mgr','opa') {
11657:
11658: my $scope = $env{'request.course.id'};
11659: if (!($perm{$test_perm}=&Apache::lonnet::allowed($test_perm,$scope))) {
11660:
11661: $scope .= '/'.$env{'request.course.sec'};
11662: if ( $perm{$test_perm}=
11663: &Apache::lonnet::allowed($test_perm,$scope)) {
11664: $perm{$test_perm.'_section'}=$env{'request.course.sec'};
11665: } else {
11666: delete($perm{$test_perm});
11667: }
1.285 albertel 11668: }
11669: }
11670: }
11671:
1.596.2.12.2. (raeburn 11672:): sub init_old_essays {
11673:): my ($symb,$apath,$adom,$aname) = @_;
11674:): if ($symb ne '') {
11675:): my %essays = &Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
11676:): if (keys(%essays) > 0) {
11677:): $old_essays{$symb} = \%essays;
11678:): }
11679:): }
11680:): return;
11681:): }
11682:):
11683:): sub reset_old_essays {
11684:): undef(%old_essays);
11685:): }
11686:):
1.400 www 11687: sub gather_clicker_ids {
1.408 albertel 11688: my %clicker_ids;
1.400 www 11689:
11690: my $classlist = &Apache::loncoursedata::get_classlist();
11691:
11692: # Set up a couple variables.
1.407 albertel 11693: my $username_idx = &Apache::loncoursedata::CL_SNAME();
11694: my $domain_idx = &Apache::loncoursedata::CL_SDOM();
1.438 www 11695: my $status_idx = &Apache::loncoursedata::CL_STATUS();
1.400 www 11696:
1.407 albertel 11697: foreach my $student (keys(%$classlist)) {
1.438 www 11698: if ($classlist->{$student}->[$status_idx] ne 'Active') { next; }
1.407 albertel 11699: my $username = $classlist->{$student}->[$username_idx];
11700: my $domain = $classlist->{$student}->[$domain_idx];
1.400 www 11701: my $clickers =
1.408 albertel 11702: (&Apache::lonnet::userenvironment($domain,$username,'clickers'))[1];
1.400 www 11703: foreach my $id (split(/\,/,$clickers)) {
1.414 www 11704: $id=~s/^[\#0]+//;
1.421 www 11705: $id=~s/[\-\:]//g;
1.407 albertel 11706: if (exists($clicker_ids{$id})) {
1.408 albertel 11707: $clicker_ids{$id}.=','.$username.':'.$domain;
1.400 www 11708: } else {
1.408 albertel 11709: $clicker_ids{$id}=$username.':'.$domain;
1.400 www 11710: }
11711: }
11712: }
1.407 albertel 11713: return %clicker_ids;
1.400 www 11714: }
11715:
1.402 www 11716: sub gather_adv_clicker_ids {
1.408 albertel 11717: my %clicker_ids;
1.402 www 11718: my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'};
11719: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
11720: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
1.409 albertel 11721: foreach my $element (sort(keys(%coursepersonnel))) {
1.402 www 11722: foreach my $person (split(/\,/,$coursepersonnel{$element})) {
11723: my ($puname,$pudom)=split(/\:/,$person);
11724: my $clickers =
1.408 albertel 11725: (&Apache::lonnet::userenvironment($pudom,$puname,'clickers'))[1];
1.405 www 11726: foreach my $id (split(/\,/,$clickers)) {
1.414 www 11727: $id=~s/^[\#0]+//;
1.421 www 11728: $id=~s/[\-\:]//g;
1.408 albertel 11729: if (exists($clicker_ids{$id})) {
11730: $clicker_ids{$id}.=','.$puname.':'.$pudom;
11731: } else {
11732: $clicker_ids{$id}=$puname.':'.$pudom;
11733: }
1.405 www 11734: }
1.402 www 11735: }
11736: }
1.407 albertel 11737: return %clicker_ids;
1.402 www 11738: }
11739:
1.413 www 11740: sub clicker_grading_parameters {
11741: return ('gradingmechanism' => 'scalar',
11742: 'upfiletype' => 'scalar',
11743: 'specificid' => 'scalar',
11744: 'pcorrect' => 'scalar',
11745: 'pincorrect' => 'scalar');
11746: }
11747:
1.400 www 11748: sub process_clicker {
1.596.2.12.2. 1(raebur 11749:0): my ($r,$symb)=@_;
1.400 www 11750: if (!$symb) {return '';}
11751: my $result=&checkforfile_js();
1.596.2.12.2. 1(raebur 11752:0): $result.=&Apache::loncommon::start_data_table().
11753:0): &Apache::loncommon::start_data_table_header_row().
11754:0): '<th>'.&mt('Specify a file containing clicker information and set grading options.').'</th>'.
11755:0): &Apache::loncommon::end_data_table_header_row().
11756:0): &Apache::loncommon::start_data_table_row()."<td>\n";
1.413 www 11757: # Attempt to restore parameters from last session, set defaults if not present
11758: my %Saveable_Parameters=&clicker_grading_parameters();
11759: &Apache::loncommon::restore_course_settings('grades_clicker',
11760: \%Saveable_Parameters);
11761: if (!$env{'form.pcorrect'}) { $env{'form.pcorrect'}=100; }
11762: if (!$env{'form.pincorrect'}) { $env{'form.pincorrect'}=100; }
11763: if (!$env{'form.gradingmechanism'}) { $env{'form.gradingmechanism'}='attendance'; }
11764: if (!$env{'form.upfiletype'}) { $env{'form.upfiletype'}='iclicker'; }
11765:
11766: my %checked;
1.521 www 11767: foreach my $gradingmechanism ('attendance','personnel','specific','given') {
1.413 www 11768: if ($env{'form.gradingmechanism'} eq $gradingmechanism) {
1.569 bisitz 11769: $checked{$gradingmechanism}=' checked="checked"';
1.413 www 11770: }
11771: }
11772:
1.596.2.12.2. 1(raebur 11773:0): my $upload=&mt("Evaluate File");
1.400 www 11774: my $type=&mt("Type");
1.402 www 11775: my $attendance=&mt("Award points just for participation");
11776: my $personnel=&mt("Correctness determined from response by course personnel");
1.414 www 11777: my $specific=&mt("Correctness determined from response with clicker ID(s)");
1.521 www 11778: my $given=&mt("Correctness determined from given list of answers").' '.
11779: '<font size="-2"><tt>('.&mt("Provide comma-separated list. Use '*' for any answer correct, '-' for skip").')</tt></font>';
1.402 www 11780: my $pcorrect=&mt("Percentage points for correct solution");
11781: my $pincorrect=&mt("Percentage points for incorrect solution");
1.413 www 11782: my $selectform=&Apache::loncommon::select_form($env{'form.upfiletype'},'upfiletype',
1.596.2.1 raeburn 11783: {'iclicker' => 'i>clicker',
1.596.2.12.2. (raeburn 11784:): 'interwrite' => 'interwrite PRS',
11785:): 'turning' => 'Turning Technologies'});
1.418 albertel 11786: $symb = &Apache::lonenc::check_encrypt($symb);
1.596.2.12.2. 1(raebur 11787:0): $result.= &Apache::lonhtmlcommon::scripttag(<<ENDUPFORM);
1.402 www 11788: function sanitycheck() {
11789: // Accept only integer percentages
11790: document.forms.gradesupload.pcorrect.value=Math.round(document.forms.gradesupload.pcorrect.value);
11791: document.forms.gradesupload.pincorrect.value=Math.round(document.forms.gradesupload.pincorrect.value);
11792: // Find out grading choice
11793: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
11794: if (document.forms.gradesupload.gradingmechanism[i].checked) {
11795: gradingchoice=document.forms.gradesupload.gradingmechanism[i].value;
11796: }
11797: }
11798: // By default, new choice equals user selection
11799: newgradingchoice=gradingchoice;
11800: // Not good to give more points for false answers than correct ones
11801: if (Math.round(document.forms.gradesupload.pcorrect.value)<Math.round(document.forms.gradesupload.pincorrect.value)) {
11802: document.forms.gradesupload.pcorrect.value=document.forms.gradesupload.pincorrect.value;
11803: }
11804: // If new choice is attendance only, and old choice was correctness-based, restore defaults
11805: if ((gradingchoice=='attendance') && (document.forms.gradesupload.waschecked.value!='attendance')) {
11806: document.forms.gradesupload.pcorrect.value=100;
11807: document.forms.gradesupload.pincorrect.value=100;
11808: }
11809: // If the values are different, cannot be attendance only
11810: if ((Math.round(document.forms.gradesupload.pcorrect.value)!=Math.round(document.forms.gradesupload.pincorrect.value)) &&
11811: (gradingchoice=='attendance')) {
11812: newgradingchoice='personnel';
11813: }
11814: // Change grading choice to new one
11815: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
11816: if (document.forms.gradesupload.gradingmechanism[i].value==newgradingchoice) {
11817: document.forms.gradesupload.gradingmechanism[i].checked=true;
11818: } else {
11819: document.forms.gradesupload.gradingmechanism[i].checked=false;
11820: }
11821: }
11822: // Remember the old state
11823: document.forms.gradesupload.waschecked.value=newgradingchoice;
11824: }
1.596.2.12.2. 1(raebur 11825:0): ENDUPFORM
11826:0): $result.= <<ENDUPFORM;
1.400 www 11827: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
11828: <input type="hidden" name="symb" value="$symb" />
11829: <input type="hidden" name="command" value="processclickerfile" />
11830: <input type="file" name="upfile" size="50" />
11831: <br /><label>$type: $selectform</label>
1.596.2.12.2. 1(raebur 11832:0): ENDUPFORM
11833:0): $result.='</td>'.&Apache::loncommon::end_data_table_row().
11834:0): &Apache::loncommon::start_data_table_row().'<td>'.(<<ENDGRADINGFORM);
11835:0): <label><input type="radio" name="gradingmechanism" value="attendance"$checked{'attendance'} onclick="sanitycheck()" />$attendance </label>
1.589 bisitz 11836: <br /><label><input type="radio" name="gradingmechanism" value="personnel"$checked{'personnel'} onclick="sanitycheck()" />$personnel</label>
11837: <br /><label><input type="radio" name="gradingmechanism" value="specific"$checked{'specific'} onclick="sanitycheck()" />$specific </label>
1.414 www 11838: <input type="text" name="specificid" value="$env{'form.specificid'}" size="20" />
1.589 bisitz 11839: <br /><label><input type="radio" name="gradingmechanism" value="given"$checked{'given'} onclick="sanitycheck()" />$given </label>
1.521 www 11840: <br />
11841: <input type="text" name="givenanswer" size="50" />
1.413 www 11842: <input type="hidden" name="waschecked" value="$env{'form.gradingmechanism'}" />
1.596.2.12.2. 1(raebur 11843:0): ENDGRADINGFORM
11844:0): $result.='</td>'.&Apache::loncommon::end_data_table_row().
11845:0): &Apache::loncommon::start_data_table_row().'<td>'.(<<ENDPERCFORM);
11846:0): <label>$pcorrect: <input type="text" name="pcorrect" size="4" value="$env{'form.pcorrect'}" onchange="sanitycheck()" /></label>
1.589 bisitz 11847: <br /><label>$pincorrect: <input type="text" name="pincorrect" size="4" value="$env{'form.pincorrect'}" onchange="sanitycheck()" /></label>
11848: <br /><input type="button" onclick="javascript:checkUpload(this.form);" value="$upload" />
1.400 www 11849: </form>
1.596.2.12.2. 1(raebur 11850:0): ENDPERCFORM
11851:0): $result.='</td>'.
11852:0): &Apache::loncommon::end_data_table_row().
11853:0): &Apache::loncommon::end_data_table();
1.400 www 11854: return $result;
11855: }
11856:
11857: sub process_clicker_file {
1.596.2.12.2. 1(raebur 11858:0): my ($r,$symb) = @_;
1.400 www 11859: if (!$symb) {return '';}
1.413 www 11860:
11861: my %Saveable_Parameters=&clicker_grading_parameters();
11862: &Apache::loncommon::store_course_settings('grades_clicker',
11863: \%Saveable_Parameters);
1.596.2.12.2. 1(raebur 11864:0): my $result='';
1.404 www 11865: if (($env{'form.gradingmechanism'} eq 'specific') && ($env{'form.specificid'}!~/\w/)) {
1.408 albertel 11866: $result.='<span class="LC_error">'.&mt('You need to specify a clicker ID for the correct answer').'</span>';
1.596.2.12.2. 1(raebur 11867:0): return $result;
1.404 www 11868: }
1.522 www 11869: if (($env{'form.gradingmechanism'} eq 'given') && ($env{'form.givenanswer'}!~/\S/)) {
1.521 www 11870: $result.='<span class="LC_error">'.&mt('You need to specify the correct answer').'</span>';
1.596.2.12.2. 1(raebur 11871:0): return $result;
1.521 www 11872: }
1.522 www 11873: my $foundgiven=0;
1.521 www 11874: if ($env{'form.gradingmechanism'} eq 'given') {
11875: $env{'form.givenanswer'}=~s/^\s*//gs;
11876: $env{'form.givenanswer'}=~s/\s*$//gs;
1.596.2.4 raeburn 11877: $env{'form.givenanswer'}=~s/[^a-zA-Z0-9\.\*\-\+]+/\,/g;
1.521 www 11878: $env{'form.givenanswer'}=uc($env{'form.givenanswer'});
1.522 www 11879: my @answers=split(/\,/,$env{'form.givenanswer'});
11880: $foundgiven=$#answers+1;
1.521 www 11881: }
1.407 albertel 11882: my %clicker_ids=&gather_clicker_ids();
1.408 albertel 11883: my %correct_ids;
1.404 www 11884: if ($env{'form.gradingmechanism'} eq 'personnel') {
1.408 albertel 11885: %correct_ids=&gather_adv_clicker_ids();
1.404 www 11886: }
11887: if ($env{'form.gradingmechanism'} eq 'specific') {
1.414 www 11888: foreach my $correct_id (split(/[\s\,]/,$env{'form.specificid'})) {;
11889: $correct_id=~tr/a-z/A-Z/;
11890: $correct_id=~s/\s//gs;
11891: $correct_id=~s/^[\#0]+//;
1.421 www 11892: $correct_id=~s/[\-\:]//g;
1.414 www 11893: if ($correct_id) {
11894: $correct_ids{$correct_id}='specified';
11895: }
11896: }
1.400 www 11897: }
1.404 www 11898: if ($env{'form.gradingmechanism'} eq 'attendance') {
1.408 albertel 11899: $result.=&mt('Score based on attendance only');
1.521 www 11900: } elsif ($env{'form.gradingmechanism'} eq 'given') {
1.522 www 11901: $result.=&mt('Score based on [_1] ([_2] answers)','<tt>'.$env{'form.givenanswer'}.'</tt>',$foundgiven);
1.404 www 11902: } else {
1.408 albertel 11903: my $number=0;
1.411 www 11904: $result.='<p><b>'.&mt('Correctness determined by the following IDs').'</b>';
1.408 albertel 11905: foreach my $id (sort(keys(%correct_ids))) {
1.411 www 11906: $result.='<br /><tt>'.$id.'</tt> - ';
1.408 albertel 11907: if ($correct_ids{$id} eq 'specified') {
11908: $result.=&mt('specified');
11909: } else {
11910: my ($uname,$udom)=split(/\:/,$correct_ids{$id});
11911: $result.=&Apache::loncommon::plainname($uname,$udom);
11912: }
11913: $number++;
11914: }
1.411 www 11915: $result.="</p>\n";
1.596.2.12.2. 5(raebur 11916:3): if ($number==0) {
11917:3): $result .=
11918:3): &Apache::lonhtmlcommon::confirm_success(
11919:3): &mt('No IDs found to determine correct answer'),1);
1(raebur 11920:0): return $result;
5(raebur 11921:3): }
1.404 www 11922: }
1.405 www 11923: if (length($env{'form.upfile'}) < 2) {
1.596.2.12.2. 5(raebur 11924:3): $result .=
11925:3): &Apache::lonhtmlcommon::confirm_success(
11926:3): &mt('The file: [_1] you attempted to upload contained no information. Please check that you entered the correct filename.',
11927:3): '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'),1);
1(raebur 11928:0): return $result;
1.405 www 11929: }
1.596.2.12.2. 7(raebur 11930:9): my $mimetype;
11931:9): if ($env{'form.upfiletype'} eq 'iclicker') {
11932:9): my $mm = new File::MMagic;
11933:9): $mimetype = $mm->checktype_contents($env{'form.upfile'});
11934:9): unless (($mimetype eq 'text/plain') || ($mimetype eq 'text/html')) {
11935:9): $result.= '<p>'.
11936:9): &Apache::lonhtmlcommon::confirm_success(
11937:9): &mt('File format is neither csv (iclicker 6) nor xml (iclicker 7)'),1).'</p>';
1(raebur 11938:0): return $result;
7(raebur 11939:9): }
11940:9): } elsif (($env{'form.upfiletype'} ne 'interwrite') && ($env{'form.upfiletype'} ne 'turning')) {
11941:9): $result .= '<p>'.
11942:9): &Apache::lonhtmlcommon::confirm_success(
11943:9): &mt('Invalid clicker type: choose one of: i>clicker, Interwrite PRS, or Turning Technologies.'),1).'</p>';
1(raebur 11944:0): return $result;
7(raebur 11945:9): }
1.410 www 11946:
11947: # Were able to get all the info needed, now analyze the file
11948:
1.411 www 11949: $result.=&Apache::loncommon::studentbrowser_javascript();
1.418 albertel 11950: $symb = &Apache::lonenc::check_encrypt($symb);
1.596.2.12.2. 1(raebur 11951:0): $result.=&Apache::loncommon::start_data_table().
11952:0): &Apache::loncommon::start_data_table_header_row().
11953:0): '<th>'.&mt('Evaluate clicker file').'</th>'.
11954:0): &Apache::loncommon::end_data_table_header_row().
11955:0): &Apache::loncommon::start_data_table_row().(<<ENDHEADER);
11956:0): <td>
1.410 www 11957: <form method="post" action="/adm/grades" name="clickeranalysis">
11958: <input type="hidden" name="symb" value="$symb" />
11959: <input type="hidden" name="command" value="assignclickergrades" />
1.411 www 11960: <input type="hidden" name="gradingmechanism" value="$env{'form.gradingmechanism'}" />
11961: <input type="hidden" name="pcorrect" value="$env{'form.pcorrect'}" />
11962: <input type="hidden" name="pincorrect" value="$env{'form.pincorrect'}" />
1.410 www 11963: ENDHEADER
1.522 www 11964: if ($env{'form.gradingmechanism'} eq 'given') {
11965: $result.='<input type="hidden" name="correct:given" value="'.$env{'form.givenanswer'}.'" />';
11966: }
1.408 albertel 11967: my %responses;
11968: my @questiontitles;
1.405 www 11969: my $errormsg='';
11970: my $number=0;
11971: if ($env{'form.upfiletype'} eq 'iclicker') {
1.596.2.12.2. 7(raebur 11972:9): if ($mimetype eq 'text/plain') {
11973:9): ($errormsg,$number)=&iclicker_eval(\@questiontitles,\%responses);
11974:9): } elsif ($mimetype eq 'text/html') {
11975:9): ($errormsg,$number)=&iclickerxml_eval(\@questiontitles,\%responses);
11976:9): }
11977:9): } elsif ($env{'form.upfiletype'} eq 'interwrite') {
1.419 www 11978: ($errormsg,$number)=&interwrite_eval(\@questiontitles,\%responses);
1.596.2.12.2. 7(raebur 11979:9): } elsif ($env{'form.upfiletype'} eq 'turning') {
(raeburn 11980:): ($errormsg,$number)=&turning_eval(\@questiontitles,\%responses);
11981:): }
1.411 www 11982: $result.='<br />'.&mt('Found [_1] question(s)',$number).'<br />'.
11983: '<input type="hidden" name="number" value="'.$number.'" />'.
11984: &mt('Awarding [_1] percent for correct and [_2] percent for incorrect responses',
11985: $env{'form.pcorrect'},$env{'form.pincorrect'}).
11986: '<br />';
1.522 www 11987: if (($env{'form.gradingmechanism'} eq 'given') && ($number!=$foundgiven)) {
11988: $result.='<span class="LC_error">'.&mt('Number of given answers does not agree with number of questions in file.').'</span>';
1.596.2.12.2. 1(raebur 11989:0): return $result;
1.522 www 11990: }
1.414 www 11991: # Remember Question Titles
11992: # FIXME: Possibly need delimiter other than ":"
11993: for (my $i=0;$i<$number;$i++) {
11994: $result.='<input type="hidden" name="question:'.$i.'" value="'.
11995: &HTML::Entities::encode($questiontitles[$i],'"&<>').'" />';
11996: }
1.411 www 11997: my $correct_count=0;
11998: my $student_count=0;
11999: my $unknown_count=0;
1.414 www 12000: # Match answers with usernames
12001: # FIXME: Possibly need delimiter other than ":"
1.409 albertel 12002: foreach my $id (keys(%responses)) {
1.410 www 12003: if ($correct_ids{$id}) {
1.414 www 12004: $result.="\n".'<input type="hidden" name="correct:'.$correct_count.':'.$correct_ids{$id}.'" value="'.$responses{$id}.'" />';
1.411 www 12005: $correct_count++;
1.410 www 12006: } elsif ($clicker_ids{$id}) {
1.437 www 12007: if ($clicker_ids{$id}=~/\,/) {
12008: # More than one user with the same clicker!
1.596.2.12.2. 1(raebur 12009:0): $result.="</td>".&Apache::loncommon::end_data_table_row().
12010:0): &Apache::loncommon::start_data_table_row()."<td>".
12011:0): &mt('Clicker registered more than once').": <tt>".$id."</tt><br />";
1.437 www 12012: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
12013: "<select name='multi".$id."'>";
12014: foreach my $reguser (sort(split(/\,/,$clicker_ids{$id}))) {
12015: $result.="<option value='".$reguser."'>".&Apache::loncommon::plainname(split(/\:/,$reguser)).' ('.$reguser.')</option>';
12016: }
12017: $result.='</select>';
12018: $unknown_count++;
12019: } else {
12020: # Good: found one and only one user with the right clicker
12021: $result.="\n".'<input type="hidden" name="student:'.$clicker_ids{$id}.'" value="'.$responses{$id}.'" />';
12022: $student_count++;
12023: }
1.410 www 12024: } else {
1.596.2.12.2. 1(raebur 12025:0): $result.="</td>".&Apache::loncommon::end_data_table_row().
12026:0): &Apache::loncommon::start_data_table_row()."<td>".
12027:0): &mt('Unregistered Clicker')." <tt>".$id."</tt><br />";
1.411 www 12028: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
12029: "\n".&mt("Username").": <input type='text' name='uname".$id."' /> ".
12030: "\n".&mt("Domain").": ".
12031: &Apache::loncommon::select_dom_form($env{'course.'.$env{'request.course.id'}.'.domain'},'udom'.$id).' '.
1.596.2.12.2. 0(raebur 12032:0): &Apache::loncommon::selectstudent_link('clickeranalysis','uname'.$id,'udom'.$id,'',$id);
1.411 www 12033: $unknown_count++;
1.410 www 12034: }
1.405 www 12035: }
1.412 www 12036: $result.='<hr />'.
12037: &mt('Found [_1] registered and [_2] unregistered clickers.',$student_count,$unknown_count);
1.521 www 12038: if (($env{'form.gradingmechanism'} ne 'attendance') && ($env{'form.gradingmechanism'} ne 'given')) {
1.412 www 12039: if ($correct_count==0) {
1.596.2.12.2. 8(raebur 12040:3): $errormsg.="Found no correct answers for grading!";
1.412 www 12041: } elsif ($correct_count>1) {
1.414 www 12042: $result.='<br /><span class="LC_warning">'.&mt("Found [_1] entries for grading!",$correct_count).'</span>';
1.412 www 12043: }
12044: }
1.428 www 12045: if ($number<1) {
12046: $errormsg.="Found no questions.";
12047: }
1.412 www 12048: if ($errormsg) {
12049: $result.='<br /><span class="LC_error">'.&mt($errormsg).'</span>';
12050: } else {
12051: $result.='<br /><input type="submit" name="finalize" value="'.&mt('Finalize Grading').'" />';
12052: }
1.596.2.12.2. 1(raebur 12053:0): $result.='</form></td>'.
12054:0): &Apache::loncommon::end_data_table_row().
12055:0): &Apache::loncommon::end_data_table();
12056:0): return $result;
1.400 www 12057: }
12058:
1.405 www 12059: sub iclicker_eval {
1.406 www 12060: my ($questiontitles,$responses)=@_;
1.405 www 12061: my $number=0;
12062: my $errormsg='';
12063: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
1.410 www 12064: my %components=&Apache::loncommon::record_sep($line);
12065: my @entries=map {$components{$_}} (sort(keys(%components)));
1.408 albertel 12066: if ($entries[0] eq 'Question') {
12067: for (my $i=3;$i<$#entries;$i+=6) {
12068: $$questiontitles[$number]=$entries[$i];
12069: $number++;
12070: }
12071: }
12072: if ($entries[0]=~/^\#/) {
12073: my $id=$entries[0];
12074: my @idresponses;
12075: $id=~s/^[\#0]+//;
12076: for (my $i=0;$i<$number;$i++) {
12077: my $idx=3+$i*6;
1.596.2.4 raeburn 12078: $entries[$idx]=~s/[^a-zA-Z0-9\.\*\-\+]+//g;
1.408 albertel 12079: push(@idresponses,$entries[$idx]);
12080: }
12081: $$responses{$id}=join(',',@idresponses);
12082: }
1.405 www 12083: }
12084: return ($errormsg,$number);
12085: }
12086:
1.596.2.12.2. 7(raebur 12087:9): sub iclickerxml_eval {
12088:9): my ($questiontitles,$responses)=@_;
12089:9): my $number=0;
12090:9): my $errormsg='';
12091:9): my @state;
12092:9): my %respbyid;
12093:9): my $p = HTML::Parser->new
12094:9): (
12095:9): xml_mode => 1,
12096:9): start_h =>
12097:9): [sub {
12098:9): my ($tagname,$attr) = @_;
12099:9): push(@state,$tagname);
12100:9): if ("@state" eq "ssn p") {
12101:9): my $title = $attr->{qn};
12102:9): $title =~ s/(^\s+|\s+$)//g;
12103:9): $questiontitles->[$number]=$title;
12104:9): } elsif ("@state" eq "ssn p v") {
12105:9): my $id = $attr->{id};
12106:9): my $entry = $attr->{ans};
12107:9): $id=~s/^[\#0]+//;
12108:9): $entry =~s/[^a-zA-Z0-9\.\*\-\+]+//g;
12109:9): $respbyid{$id}[$number] = $entry;
12110:9): }
12111:9): }, "tagname, attr"],
12112:9): end_h =>
12113:9): [sub {
12114:9): my ($tagname) = @_;
12115:9): if ("@state" eq "ssn p") {
12116:9): $number++;
12117:9): }
12118:9): pop(@state);
12119:9): }, "tagname"],
12120:9): );
12121:9):
12122:9): $p->parse($env{'form.upfile'});
12123:9): $p->eof;
12124:9): foreach my $id (keys(%respbyid)) {
12125:9): $responses->{$id}=join(',',@{$respbyid{$id}});
12126:9): }
12127:9): return ($errormsg,$number);
12128:9): }
12129:9):
1.419 www 12130: sub interwrite_eval {
12131: my ($questiontitles,$responses)=@_;
12132: my $number=0;
12133: my $errormsg='';
1.420 www 12134: my $skipline=1;
12135: my $questionnumber=0;
12136: my %idresponses=();
1.419 www 12137: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
12138: my %components=&Apache::loncommon::record_sep($line);
12139: my @entries=map {$components{$_}} (sort(keys(%components)));
1.420 www 12140: if ($entries[1] eq 'Time') { $skipline=0; next; }
12141: if ($entries[1] eq 'Response') { $skipline=1; }
12142: next if $skipline;
12143: if ($entries[0]!=$questionnumber) {
12144: $questionnumber=$entries[0];
12145: $$questiontitles[$number]=&mt('Question [_1]',$questionnumber);
12146: $number++;
1.419 www 12147: }
1.420 www 12148: my $id=$entries[4];
12149: $id=~s/^[\#0]+//;
1.421 www 12150: $id=~s/^v\d*\://i;
12151: $id=~s/[\-\:]//g;
1.420 www 12152: $idresponses{$id}[$number]=$entries[6];
12153: }
1.524 raeburn 12154: foreach my $id (keys(%idresponses)) {
1.420 www 12155: $$responses{$id}=join(',',@{$idresponses{$id}});
12156: $$responses{$id}=~s/^\s*\,//;
1.419 www 12157: }
12158: return ($errormsg,$number);
12159: }
12160:
1.596.2.12.2. (raeburn 12161:): sub turning_eval {
12162:): my ($questiontitles,$responses)=@_;
12163:): my $number=0;
12164:): my $errormsg='';
12165:): foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
12166:): my %components=&Apache::loncommon::record_sep($line);
12167:): my @entries=map {$components{$_}} (sort(keys(%components)));
12168:): if ($#entries>$number) { $number=$#entries; }
12169:): my $id=$entries[0];
12170:): my @idresponses;
12171:): $id=~s/^[\#0]+//;
12172:): unless ($id) { next; }
12173:): for (my $idx=1;$idx<=$#entries;$idx++) {
12174:): $entries[$idx]=~s/\,/\;/g;
12175:): $entries[$idx]=~s/[^a-zA-Z0-9\.\*\-\+\;]+//g;
12176:): push(@idresponses,$entries[$idx]);
12177:): }
12178:): $$responses{$id}=join(',',@idresponses);
12179:): }
12180:): for (my $i=1; $i<=$number; $i++) {
12181:): $$questiontitles[$i]=&mt('Question [_1]',$i);
12182:): }
12183:): return ($errormsg,$number);
12184:): }
12185:):
1.414 www 12186: sub assign_clicker_grades {
1.596.2.12.2. 1(raebur 12187:0): my ($r,$symb) = @_;
1.414 www 12188: if (!$symb) {return '';}
1.416 www 12189: # See which part we are saving to
1.582 raeburn 12190: my $res_error;
12191: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
12192: if ($res_error) {
12193: return &navmap_errormsg();
12194: }
1.596.2.12.2. 0.2.7(ra 12195:an-25): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
12196:an-25): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
12197:an-25): my %needpb = &passbacks_for_symb($cdom,$cnum,$symb);
12198:an-25): my (%skip_passback,%pbsave);
1.416 www 12199: # FIXME: This should probably look for the first handgradeable part
12200: my $part=$$partlist[0];
12201: # Start screen output
1.596.2.12.2. 1(raebur 12202:0): my $result = &Apache::loncommon::start_data_table().
12203:0): &Apache::loncommon::start_data_table_header_row().
12204:0): '<th>'.&mt('Assigning grades based on clicker file').'</th>'.
12205:0): &Apache::loncommon::end_data_table_header_row().
12206:0): &Apache::loncommon::start_data_table_row().'<td>';
1.414 www 12207: # Get correct result
12208: # FIXME: Possibly need delimiter other than ":"
12209: my @correct=();
1.415 www 12210: my $gradingmechanism=$env{'form.gradingmechanism'};
12211: my $number=$env{'form.number'};
12212: if ($gradingmechanism ne 'attendance') {
1.414 www 12213: foreach my $key (keys(%env)) {
12214: if ($key=~/^form\.correct\:/) {
12215: my @input=split(/\,/,$env{$key});
12216: for (my $i=0;$i<=$#input;$i++) {
12217: if (($correct[$i]) && ($input[$i]) &&
12218: ($correct[$i] ne $input[$i])) {
12219: $result.='<br /><span class="LC_warning">'.
12220: &mt('More than one correct result given for question "[_1]": [_2] versus [_3].',
12221: $env{'form.question:'.$i},$correct[$i],$input[$i]).'</span>';
1.596.2.4 raeburn 12222: } elsif (($input[$i]) || ($input[$i] eq '0')) {
1.414 www 12223: $correct[$i]=$input[$i];
12224: }
12225: }
12226: }
12227: }
1.415 www 12228: for (my $i=0;$i<$number;$i++) {
1.596.2.4 raeburn 12229: if ((!$correct[$i]) && ($correct[$i] ne '0')) {
1.414 www 12230: $result.='<br /><span class="LC_error">'.
12231: &mt('No correct result given for question "[_1]"!',
12232: $env{'form.question:'.$i}).'</span>';
12233: }
12234: }
1.596.2.4 raeburn 12235: $result.='<br />'.&mt("Correct answer: [_1]",join(', ',map { ((($_) || ($_ eq '0'))?$_:'-') } @correct));
1.414 www 12236: }
12237: # Start grading
1.415 www 12238: my $pcorrect=$env{'form.pcorrect'};
12239: my $pincorrect=$env{'form.pincorrect'};
1.416 www 12240: my $storecount=0;
1.596.2.4 raeburn 12241: my %users=();
1.415 www 12242: foreach my $key (keys(%env)) {
1.420 www 12243: my $user='';
1.415 www 12244: if ($key=~/^form\.student\:(.*)$/) {
1.420 www 12245: $user=$1;
12246: }
12247: if ($key=~/^form\.unknown\:(.*)$/) {
12248: my $id=$1;
12249: if (($env{'form.uname'.$id}) && ($env{'form.udom'.$id})) {
12250: $user=$env{'form.uname'.$id}.':'.$env{'form.udom'.$id};
1.437 www 12251: } elsif ($env{'form.multi'.$id}) {
12252: $user=$env{'form.multi'.$id};
1.420 www 12253: }
12254: }
1.596.2.4 raeburn 12255: if ($user) {
12256: if ($users{$user}) {
12257: $result.='<br /><span class="LC_warning">'.
1.596.2.12.2. 8(raebur 12258:3): &mt('More than one entry found for [_1]!','<tt>'.$user.'</tt>').
1.596.2.4 raeburn 12259: '</span><br />';
12260: }
12261: $users{$user}=1;
1.415 www 12262: my @answer=split(/\,/,$env{$key});
12263: my $sum=0;
1.522 www 12264: my $realnumber=$number;
1.415 www 12265: for (my $i=0;$i<$number;$i++) {
1.576 www 12266: if ($correct[$i] eq '-') {
12267: $realnumber--;
1.596.2.12.2. 1(raebur 12268:0): } elsif (($answer[$i]) || ($answer[$i]=~/^[0\.]+$/)) {
1.415 www 12269: if ($gradingmechanism eq 'attendance') {
12270: $sum+=$pcorrect;
1.576 www 12271: } elsif ($correct[$i] eq '*') {
1.522 www 12272: $sum+=$pcorrect;
1.415 www 12273: } else {
1.596.2.4 raeburn 12274: # We actually grade if correct or not
12275: my $increment=$pincorrect;
12276: # Special case: numerical answer "0"
12277: if ($correct[$i] eq '0') {
12278: if ($answer[$i]=~/^[0\.]+$/) {
12279: $increment=$pcorrect;
12280: }
12281: # General numerical answer, both evaluate to something non-zero
12282: } elsif ((1.0*$correct[$i]!=0) && (1.0*$answer[$i]!=0)) {
12283: if (1.0*$correct[$i]==1.0*$answer[$i]) {
12284: $increment=$pcorrect;
12285: }
12286: # Must be just alphanumeric
12287: } elsif ($answer[$i] eq $correct[$i]) {
12288: $increment=$pcorrect;
1.415 www 12289: }
1.596.2.4 raeburn 12290: $sum+=$increment;
1.415 www 12291: }
12292: }
12293: }
1.522 www 12294: my $ave=$sum/(100*$realnumber);
1.416 www 12295: # Store
12296: my ($username,$domain)=split(/\:/,$user);
12297: my %grades=();
12298: $grades{"resource.$part.solved"}='correct_by_override';
12299: $grades{"resource.$part.awarded"}=$ave;
12300: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
12301: my $returncode=&Apache::lonnet::cstore(\%grades,$symb,
12302: $env{'request.course.id'},
12303: $domain,$username);
12304: if ($returncode ne 'ok') {
12305: $result.="<br /><span class=\"LC_error\">Failed to save student $username:$domain. Message when trying to save was ($returncode)</span>";
12306: } else {
12307: $storecount++;
1.596.2.12.2. 0.2.7(ra 12308:an-25): if (keys(%needpb)) {
12309:an-25): my (%weights,%awardeds,%excuseds);
12310:an-25): my $usec = &Apache::lonnet::getsection($domain,$username,$env{'request.course.id'});
12311:an-25): $weights{$symb}{$part} = &Apache::lonnet::EXT("resource.$part.weight",$symb,$domain,$username,$usec);
12312:an-25): $awardeds{$symb}{$part} = $ave;
12313:an-25): $excuseds{$symb}{$part} = '';
12314:an-25): &process_passbacks('clickergrade',[$symb],$cdom,$cnum,$domain,$username,$usec,\%weights,
12315:an-25): \%awardeds,\%excuseds,\%needpb,\%skip_passback,\%pbsave);
12316:an-25): }
1.416 www 12317: }
1.415 www 12318: }
12319: }
12320: # We are done
1.549 hauer 12321: $result.='<br />'.&mt('Successfully stored grades for [quant,_1,student].',$storecount).
1.596.2.4 raeburn 12322: '</td>'.
12323: &Apache::loncommon::end_data_table_row().
1.596.2.12.2. 1(raebur 12324:0): &Apache::loncommon::end_data_table();
12325:0): return $result;
1.414 www 12326: }
12327:
1.582 raeburn 12328: sub navmap_errormsg {
12329: return '<div class="LC_error">'.
12330: &mt('An error occurred retrieving information about resources in the course.').'<br />'.
1.595 raeburn 12331: &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 12332: '</div>';
12333: }
12334:
1.596.2.12.2. (raeburn 12335:): sub startpage {
5(raebur 12336:0): my ($r,$symb,$crumbs,$onlyfolderflag,$nodisplayflag,$stuvcurrent,$stuvdisp,$nomenu,$head_extra,$onload,$divforres) = @_;
9(raebur 12337:9): my %args;
12338:9): if ($onload) {
12339:9): my %loaditems = (
12340:9): 'onload' => $onload,
12341:9): );
12342:9): $args{'add_entries'} = \%loaditems;
12343:9): }
(raeburn 12344:): if ($nomenu) {
9(raebur 12345:9): $args{'only_body'} = 1;
5(raebur 12346:0): $r->print(&Apache::loncommon::start_page("Student's Version",$head_extra,\%args));
(raeburn 12347:): } else {
8(raebur 12348:1): if ($env{'request.course.id'}) {
12349:1): unshift(@$crumbs,{href=>&href_symb_cmd($symb,'gradingmenu'),text=>"Grading"});
12350:1): }
9(raebur 12351:9): $args{'bread_crumbs'} = $crumbs;
5(raebur 12352:0): $r->print(&Apache::loncommon::start_page('Grading',$head_extra,\%args));
(raeburn 12353:): }
12354:): unless ($nodisplayflag) {
1(raebur 12355:0): $r->print(&Apache::lonhtmlcommon::resource_info_box($symb,$onlyfolderflag,$stuvcurrent,$stuvdisp,$divforres));
(raeburn 12356:): }
12357:): }
12358:):
1(raebur 12359:0): sub select_problem {
12360:0): my ($r)=@_;
12361:0): $r->print('<h3>'.&mt('Select the problem or one of the problems you want to grade').'</h3><form action="/adm/grades">');
12362:0): $r->print(&Apache::lonstathelpers::problem_selector('.',undef,1,undef,undef,1));
12363:0): $r->print('<input type="hidden" name="command" value="gradingmenu" />');
12364:0): $r->print('<input type="submit" value="'.&mt('Next').' →" /></form>');
12365:0): }
12366:0):
0.2.5(ra 12367:ep-23): #----- display problem, answer, and submissions for a single student (no grading)
12368:ep-23):
12369:ep-23): sub view_as_user {
12370:ep-23): my ($symb,$vuname,$vudom,$hasperm) = @_;
12371:ep-23): my $plainname = &Apache::loncommon::plainname($vuname,$vudom,'lastname');
12372:ep-23): my $displayname = &nameUserString('',$plainname,$vuname,$vudom);
12373:ep-23): my $output = &Apache::loncommon::get_student_view($symb,$vuname,$vudom,
12374:ep-23): $env{'request.course.id'},
12375:ep-23): undef,{'disable_submit' => 1}).
12376:ep-23): "\n\n".
12377:ep-23): '<div class="LC_grade_show_user">'.
12378:ep-23): '<h2>'.$displayname.'</h2>'.
12379:ep-23): "\n".
12380:ep-23): &Apache::loncommon::track_student_link('View recent activity',
12381:ep-23): $vuname,$vudom,'check').' '.
12382:ep-23): "\n";
12383:ep-23): if (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) ||
12384:ep-23): (($env{'request.course.sec'} ne '') &&
12385:ep-23): &Apache::lonnet::allowed('opa',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
12386:ep-23): $output .= &Apache::loncommon::pprmlink(&mt('Set/Change parameters'),
12387:ep-23): $vuname,$vudom,$symb,'check');
12388:ep-23): }
12389:ep-23): $output .= "\n";
12390:ep-23): my $companswer = &Apache::loncommon::get_student_answers($symb,$vuname,$vudom,
12391:ep-23): $env{'request.course.id'});
12392:ep-23): $companswer=~s|<form(.*?)>||g;
12393:ep-23): $companswer=~s|</form>||g;
12394:ep-23): $companswer=~s|name="submit"|name="would_have_been_submit"|g;
12395:ep-23): $output .= '<div class="LC_Box">'.
12396:ep-23): '<h3 class="LC_hcell">'.&mt('Correct answer for[_1]',$displayname).'</h3>'.
12397:ep-23): $companswer.
12398:ep-23): '</div>'."\n";
12399:ep-23): my $is_tool = ($symb =~ /ext\.tool$/);
12400:ep-23): my ($essayurl,%coursedesc_by_cid);
12401:ep-23): (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb);
12402:ep-23): my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$vudom,$vuname);
12403:ep-23): my $res_error;
12404:ep-23): my ($partlist,$handgrade,$responseType,$numresp,$numessay) =
12405:ep-23): &response_type($symb,\$res_error);
12406:ep-23): my $fullname;
12407:ep-23): my $collabinfo;
12408:ep-23): if ($numessay) {
12409:ep-23): unless ($hasperm) {
12410:ep-23): &init_perm();
12411:ep-23): }
12412:ep-23): ($collabinfo,$fullname)=
12413:ep-23): &check_collaborators($symb,$vuname,$vudom,\%record,$handgrade,0);
12414:ep-23): unless ($hasperm) {
12415:ep-23): &reset_perm();
12416:ep-23): }
12417:ep-23): }
12418:ep-23): my $checkIcon = '<img alt="'.&mt('Check Mark').
12419:ep-23): '" src="'.$Apache::lonnet::perlvar{'lonIconsURL'}.
12420:ep-23): '/check.gif" height="16" border="0" />';
12421:ep-23): my ($lastsubonly,$partinfo) =
12422:ep-23): &show_last_submission($vuname,$vudom,$symb,$essayurl,$responseType,'datesub',
12423:ep-23): '',$fullname,\%record,\%coursedesc_by_cid);
12424:ep-23): $output .= '<div class="LC_Box">'.
12425:ep-23): '<h3 class="LC_hcell">'.&mt('Submissions').'</h3>'."\n".$collabinfo."\n";
12426:ep-23): if (($numresp > $numessay) & !$is_tool) {
12427:ep-23): $output .='<p class="LC_info">'.
12428:ep-23): &mt('Part(s) graded correct by the computer is marked with a [_1] symbol.',$checkIcon).
12429:ep-23): "</p>\n";
12430:ep-23): }
12431:ep-23): $output .= $partinfo;
12432:ep-23): $output .= $lastsubonly;
12433:ep-23): $output .= &displaySubByDates($symb,\%record,$partlist,$responseType,$checkIcon,$vuname,$vudom);
12434:ep-23): $output .= '</div></div>'."\n";
12435:ep-23): return $output;
12436:ep-23): }
12437:ep-23):
1.1 albertel 12438: sub handler {
1.41 ng 12439: my $request=$_[0];
1.434 albertel 12440: &reset_caches();
1.596.2.4 raeburn 12441: if ($request->header_only) {
12442: &Apache::loncommon::content_type($request,'text/html');
12443: $request->send_http_header;
12444: return OK;
1.41 ng 12445: }
12446: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.596.2.4 raeburn 12447:
1.596.2.12.2. 1(raebur 12448:0): # see what command we need to execute
12449:0):
1.160 albertel 12450: my @commands=&Apache::loncommon::get_env_multiple('form.command');
12451: my $command=$commands[0];
1.447 foxr 12452:
1.596.2.12.2. 1(raebur 12453:0): &init_perm();
12454:0): if (!$env{'request.course.id'}) {
12455:0): unless ((&Apache::lonnet::allowed('usc',$env{'request.role.domain'})) &&
12456:0): ($command =~ /^scantronupload/)) {
12457:0): # Not in a course.
12458:0): $env{'user.error.msg'}="/adm/grades::vgr:0:0:Cannot display grades page outside course context";
12459:0): return HTTP_NOT_ACCEPTABLE;
12460:0): }
12461:0): } elsif (!%perm) {
12462:0): $request->internal_redirect('/adm/quickgrades');
12463:0): return OK;
12464:0): }
12465:0): &Apache::loncommon::content_type($request,'text/html');
12466:0): $request->send_http_header;
12467:0):
1.160 albertel 12468: if ($#commands > 0) {
12469: &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands));
12470: }
1.447 foxr 12471:
1.596.2.12.2. 0.2.7(ra 12472:an-25): # -------------------------------------- Flag and buffer for registered cleanup
12473:an-25): $registered_cleanup=0;
12474:an-25): undef(@Apache::grades::ltipassback);
12475:an-25):
1(raebur 12476:0): # see what the symb is
12477:0):
12478:0): my $symb=$env{'form.symb'};
12479:0): unless ($symb) {
12480:0): (my $url=$env{'form.url'}) =~ s-^https*://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
12481:0): $symb=&Apache::lonnet::symbread($url);
12482:0): }
12483:0): &Apache::lonenc::check_decrypt(\$symb);
12484:0):
1.513 foxr 12485: $ssi_error = 0;
1.596.2.12.2. 1(raebur 12486:0): if (($symb eq '' || $command eq '') && ($env{'request.course.id'})) {
12487:0): #
12488:0): # Not called from a resource, but inside a course
12489:0): #
12490:0): &startpage($request,undef,[],1,1);
12491:0): &select_problem($request);
1.41 ng 12492: } else {
1.596.2.12.2. 1(raebur 12493:0): if ($command eq 'submission' && $perm{'vgr'}) {
12494:0): my ($stuvcurrent,$stuvdisp,$versionform,$js,$onload);
(raeburn 12495:): if (($env{'form.student'} ne '') && ($env{'form.userdom'} ne '')) {
12496:): ($stuvcurrent,$stuvdisp,$versionform,$js) =
12497:): &choose_task_version_form($symb,$env{'form.student'},
12498:): $env{'form.userdom'});
12499:): }
1(raebur 12500:0): my $divforres;
12501:0): if ($env{'form.student'} eq '') {
12502:0): $js .= &part_selector_js();
12503:0): $onload = "toggleParts('gradesub');";
12504:0): } else {
12505:0): $divforres = 1;
12506:0): }
5(raebur 12507:0): my $head_extra = $js;
12508:0): unless ($env{'form.vProb'} eq 'no') {
12509:0): my $csslinks = &Apache::loncommon::css_links($symb);
12510:0): if ($csslinks) {
12511:0): $head_extra .= "\n$csslinks";
12512:0): }
12513:0): }
12514:0): &startpage($request,$symb,[{href=>"", text=>"Student Submissions"}],undef,undef,
12515:0): $stuvcurrent,$stuvdisp,undef,$head_extra,$onload,$divforres);
(raeburn 12516:): if ($versionform) {
2(raebur 12517:0): if ($divforres) {
12518:0): $request->print('<div style="padding:0;clear:both;margin:0;border:0"></div>');
12519:0): }
(raeburn 12520:): $request->print($versionform);
12521:): }
1(raebur 12522:0): ($env{'form.student'} eq '' ? &listStudents($request,$symb,'',$divforres) : &submission($request,0,0,$symb,$divforres,$command));
(raeburn 12523:): } elsif ($command eq 'versionsub' && $perm{'vgr'}) {
12524:): my ($stuvcurrent,$stuvdisp,$versionform,$js) =
12525:): &choose_task_version_form($symb,$env{'form.student'},
12526:): $env{'form.userdom'},
12527:): $env{'form.inhibitmenu'});
5(raebur 12528:0): my $head_extra = $js;
12529:0): unless ($env{'form.vProb'} eq 'no') {
12530:0): my $csslinks = &Apache::loncommon::css_links($symb);
12531:0): if ($csslinks) {
12532:0): $head_extra .= "\n$csslinks";
12533:0): }
12534:0): }
12535:0): &startpage($request,$symb,[{href=>"", text=>"Previous Student Version"}],undef,undef,
12536:0): $stuvcurrent,$stuvdisp,$env{'form.inhibitmenu'},$head_extra);
(raeburn 12537:): if ($versionform) {
12538:): $request->print($versionform);
12539:): }
12540:): $request->print('<br clear="all" />');
12541:): $request->print(&show_previous_task_version($request,$symb));
1(raebur 12542:0): } elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) {
12543:0): &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'all_for_one'),text=>'Grade page/folder for one student'},
12544:0): {href=>'',text=>'Select student'}],1,1);
12545:0): &pickStudentPage($request,$symb);
12546:0): } elsif ($command eq 'displayPage' && $perm{'vgr'}) {
5(raebur 12547:0): my $csslinks;
12548:0): unless ($env{'form.vProb'} eq 'no') {
12549:0): $csslinks = &Apache::loncommon::css_links($symb,'map');
12550:0): }
1(raebur 12551:0): &startpage($request,$symb,
12552:0): [{href=>&href_symb_cmd($symb,'all_for_one'),text=>'Grade page/folder for one student'},
12553:0): {href=>'',text=>'Select student'},
5(raebur 12554:0): {href=>'',text=>'Grade student'}],1,1,undef,undef,undef,$csslinks);
1(raebur 12555:0): &displayPage($request,$symb);
12556:0): } elsif ($command eq 'gradeByPage' && $perm{'mgr'}) {
12557:0): &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'all_for_one'),text=>'Grade page/folder for one student'},
12558:0): {href=>'',text=>'Select student'},
12559:0): {href=>'',text=>'Grade student'},
12560:0): {href=>'',text=>'Store grades'}],1,1);
12561:0): &updateGradeByPage($request,$symb);
12562:0): } elsif ($command eq 'processGroup' && $perm{'vgr'}) {
5(raebur 12563:0): my $csslinks;
12564:0): unless ($env{'form.vProb'} eq 'no') {
12565:0): $csslinks = &Apache::loncommon::css_links($symb);
12566:0): }
1(raebur 12567:0): &startpage($request,$symb,[{href=>'',text=>'...'},
5(raebur 12568:0): {href=>'',text=>'Modify grades'}],undef,undef,undef,undef,undef,$csslinks,undef,1);
1(raebur 12569:0): &processGroup($request,$symb);
12570:0): } elsif ($command eq 'gradingmenu' && $perm{'vgr'}) {
12571:0): &startpage($request,$symb);
12572:0): $request->print(&grading_menu($request,$symb));
12573:0): } elsif ($command eq 'individual' && $perm{'vgr'}) {
12574:0): &startpage($request,$symb,[{href=>'',text=>'Select individual students to grade'}]);
12575:0): $request->print(&submit_options($request,$symb));
12576:0): } elsif ($command eq 'ungraded' && $perm{'vgr'}) {
12577:0): my $js = &part_selector_js();
12578:0): my $onload = "toggleParts('gradesub');";
12579:0): &startpage($request,$symb,[{href=>'',text=>'Grade ungraded submissions'}],
12580:0): undef,undef,undef,undef,undef,$js,$onload);
12581:0): $request->print(&listStudents($request,$symb,'graded'));
12582:0): } elsif ($command eq 'table' && $perm{'vgr'}) {
12583:0): &startpage($request,$symb,[{href=>"", text=>"Grading table"}]);
12584:0): $request->print(&submit_options_table($request,$symb));
12585:0): } elsif ($command eq 'all_for_one' && $perm{'vgr'}) {
12586:0): &startpage($request,$symb,[{href=>'',text=>'Grade page/folder for one student'}],1,1);
12587:0): $request->print(&submit_options_sequence($request,$symb));
12588:0): } elsif ($command eq 'viewgrades' && $perm{'vgr'}) {
12589:0): &startpage($request,$symb,[{href=>&href_symb_cmd($symb,"table"), text=>"Grading table"},{href=>'', text=>"Modify grades"}]);
12590:0): $request->print(&viewgrades($request,$symb));
12591:0): } elsif ($command eq 'handgrade' && $perm{'mgr'}) {
12592:0): &startpage($request,$symb,[{href=>'',text=>'...'},
12593:0): {href=>'',text=>'Store grades'}]);
12594:0): $request->print(&processHandGrade($request,$symb));
12595:0): } elsif ($command eq 'editgrades' && $perm{'mgr'}) {
12596:0): &startpage($request,$symb,[{href=>&href_symb_cmd($symb,"table"), text=>"Grading table"},
12597:0): {href=>&href_symb_cmd($symb,'viewgrades').'&group=all§ion=all&Status=Active',
12598:0): text=>"Modify grades"},
12599:0): {href=>'', text=>"Store grades"}]);
12600:0): $request->print(&editgrades($request,$symb));
12601:0): } elsif ($command eq 'initialverifyreceipt' && $perm{'vgr'}) {
12602:0): &startpage($request,$symb,[{href=>'',text=>'Verify Receipt Number'}]);
12603:0): $request->print(&initialverifyreceipt($request,$symb));
12604:0): } elsif ($command eq 'verify' && $perm{'vgr'}) {
12605:0): &startpage($request,$symb,[{href=>&href_symb_cmd($symb,"initialverifyreceipt"),text=>'Verify Receipt Number'},
12606:0): {href=>'',text=>'Verification Result'}]);
12607:0): $request->print(&verifyreceipt($request,$symb));
1.400 www 12608: } elsif ($command eq 'processclicker' && $perm{'mgr'}) {
1.596.2.12.2. 1(raebur 12609:0): &startpage($request,$symb,[{href=>'', text=>'Process clicker'}]);
12610:0): $request->print(&process_clicker($request,$symb));
1.400 www 12611: } elsif ($command eq 'processclickerfile' && $perm{'mgr'}) {
1.596.2.12.2. 1(raebur 12612:0): &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'processclicker'), text=>'Process clicker'},
12613:0): {href=>'', text=>'Process clicker file'}]);
12614:0): $request->print(&process_clicker_file($request,$symb));
1.414 www 12615: } elsif ($command eq 'assignclickergrades' && $perm{'mgr'}) {
1.596.2.12.2. 1(raebur 12616:0): &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'processclicker'), text=>'Process clicker'},
12617:0): {href=>'', text=>'Process clicker file'},
12618:0): {href=>'', text=>'Store grades'}]);
12619:0): $request->print(&assign_clicker_grades($request,$symb));
12620:0): } elsif ($command eq 'csvform' && $perm{'mgr'}) {
12621:0): &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
12622:0): $request->print(&upcsvScores_form($request,$symb));
12623:0): } elsif ($command eq 'csvupload' && $perm{'mgr'}) {
12624:0): &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
12625:0): $request->print(&csvupload($request,$symb));
12626:0): } elsif ($command eq 'csvuploadmap' && $perm{'mgr'} ) {
12627:0): &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
12628:0): $request->print(&csvuploadmap($request,$symb));
12629:0): } elsif ($command eq 'csvuploadoptions' && $perm{'mgr'}) {
12630:0): if ($env{'form.associate'} ne 'Reverse Association') {
12631:0): &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
12632:0): $request->print(&csvuploadoptions($request,$symb));
12633:0): } else {
12634:0): if ( $env{'form.upfile_associate'} ne 'reverse' ) {
12635:0): $env{'form.upfile_associate'} = 'reverse';
12636:0): } else {
12637:0): $env{'form.upfile_associate'} = 'forward';
12638:0): }
12639:0): &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
12640:0): $request->print(&csvuploadmap($request,$symb));
12641:0): }
12642:0): } elsif ($command eq 'csvuploadassign' && $perm{'mgr'} ) {
12643:0): &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
12644:0): $request->print(&csvuploadassign($request,$symb));
12645:0): } elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
12646:0): &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1,
12647:0): undef,undef,undef,undef,'toggleScantab(document.rules);');
12648:0): $request->print(&scantron_selectphase($request,undef,$symb));
12649:0): } elsif ($command eq 'scantron_warning' && $perm{'mgr'}) {
12650:0): &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
12651:0): $request->print(&scantron_do_warning($request,$symb));
12652:0): } elsif ($command eq 'scantron_validate' && $perm{'mgr'}) {
12653:0): &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
12654:0): $request->print(&scantron_validate_file($request,$symb));
12655:0): } elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
12656:0): &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
12657:0): $request->print(&scantron_process_students($request,$symb));
12658:0): } elsif ($command eq 'scantronupload' &&
12659:0): (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
12660:0): &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
12661:0): &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1,
12662:0): undef,undef,undef,undef,'toggleScantab(document.rules);');
12663:0): $request->print(&scantron_upload_scantron_data($request,$symb));
12664:0): } elsif ($command eq 'scantronupload_save' &&
12665:0): (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
12666:0): &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
12667:0): &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
12668:0): $request->print(&scantron_upload_scantron_data_save($request,$symb));
12669:0): } elsif ($command eq 'scantron_download' &&
12670:0): &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
12671:0): &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
12672:0): $request->print(&scantron_download_scantron_data($request,$symb));
1.523 raeburn 12673: } elsif ($command eq 'checksubmissions' && $perm{'vgr'}) {
1.596.2.12.2. 1(raebur 12674:0): &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
12675:0): $request->print(&checkscantron_results($request,$symb));
12676:0): } elsif ($command eq 'downloadfilesselect' && $perm{'vgr'}) {
12677:0): my $js = &part_selector_js();
12678:0): my $onload = "toggleParts('gradingMenu');";
12679:0): &startpage($request,$symb,[{href=>'', text=>'Select which submissions to download'}],
12680:0): undef,undef,undef,undef,undef,$js,$onload);
12681:0): $request->print(&submit_options_download($request,$symb));
12682:0): } elsif ($command eq 'downloadfileslink' && $perm{'vgr'}) {
12683:0): &startpage($request,$symb,
12684:0): [{href=>&href_symb_cmd($symb,'downloadfilesselect'), text=>'Select which submissions to download'},
12685:0): {href=>'', text=>'Download submitted files'}],
12686:0): undef,undef,undef,undef,undef,undef,undef,1);
2(raebur 12687:0): $request->print('<div style="padding:0;clear:both;margin:0;border:0"></div>');
1(raebur 12688:0): &submit_download_link($request,$symb);
0.2.7(ra 12689:an-25): } elsif ($command eq 'initialpassback') {
12690:an-25): &startpage($request,$symb,[{href=>'', text=>'Choose Launcher'}],undef,1);
12691:an-25): $request->print(&initialpassback($request,$symb));
12692:an-25): } elsif ($command eq 'passback') {
12693:an-25): &startpage($request,$symb,
12694:an-25): [{href=>&href_symb_cmd($symb,'initialpassback'), text=>'Choose Launcher'},
12695:an-25): {href=>'', text=>'Types of User'}],undef,1);
12696:an-25): $request->print(&passback_filters($request,$symb));
12697:an-25): } elsif ($command eq 'passbacknames') {
12698:an-25): my $chosen;
12699:an-25): if ($env{'form.passback'} ne '') {
12700:an-25): if ($env{'form.passback'} eq &unescape($env{'form.passback'})) {
12701:an-25): $env{'form.passback'} = &escape($env{'form.passback'} );
12702:an-25): }
12703:an-25): $chosen = &HTML::Entities::encode($env{'form.passback'},'<>"&');
12704:an-25): }
12705:an-25): &startpage($request,$symb,
12706:an-25): [{href=>&href_symb_cmd($symb,'initialpassback'), text=>'Choose Launcher'},
12707:an-25): {href=>&href_symb_cmd($symb,'passback').'&passback='.$chosen, text=>'Types of User'},
12708:an-25): {href=>'', text=>'Select Users'}],undef,1);
12709:an-25): $request->print(&names_for_passback($request,$symb));
12710:an-25): } elsif ($command eq 'passbackscores') {
12711:an-25): my ($chosen,$stu_status);
12712:an-25): if ($env{'form.passback'} ne '') {
12713:an-25): if ($env{'form.passback'} eq &unescape($env{'form.passback'})) {
12714:an-25): $env{'form.passback'} = &escape($env{'form.passback'} );
12715:an-25): }
12716:an-25): $chosen = &HTML::Entities::encode($env{'form.passback'},'<>"&');
12717:an-25): }
12718:an-25): if ($env{'form.Status'}) {
12719:an-25): $stu_status = &HTML::Entities::encode($env{'form.Status'});
12720:an-25): }
12721:an-25): &startpage($request,$symb,
12722:an-25): [{href=>&href_symb_cmd($symb,'initialpassback'), text=>'Choose Launcher'},
12723:an-25): {href=>&href_symb_cmd($symb,'passback').'&passback='.$chosen, text=>'Types of User'},
12724:an-25): {href=>&href_symb_cmd($symb,'passbacknames').'&Status='.$stu_status.'&passback='.$chosen, text=>'Select Users'},
12725:an-25): {href=>'', text=>'Execute Passback'}],undef,1);
12726:an-25): $request->print(&do_passback($request,$symb));
1(raebur 12727:0): } elsif ($command) {
12728:0): &startpage($request,$symb,[{href=>'', text=>'Access denied'}]);
12729:0): $request->print('<p class="LC_error">'.&mt('Access Denied ([_1])',$command).'</p>');
12730:0): }
1.2 albertel 12731: }
1.513 foxr 12732: if ($ssi_error) {
12733: &ssi_print_error($request);
12734: }
1.353 albertel 12735: $request->print(&Apache::loncommon::end_page());
1.434 albertel 12736: &reset_caches();
1.596.2.4 raeburn 12737: return OK;
1.44 ng 12738: }
12739:
1.1 albertel 12740: 1;
12741:
1.13 albertel 12742: __END__;
1.531 jms 12743:
12744:
12745: =head1 NAME
12746:
12747: Apache::grades
12748:
12749: =head1 SYNOPSIS
12750:
12751: Handles the viewing of grades.
12752:
12753: This is part of the LearningOnline Network with CAPA project
12754: described at http://www.lon-capa.org.
12755:
12756: =head1 OVERVIEW
12757:
12758: Do an ssi with retries:
12759: While I'd love to factor out this with the vesrion in lonprintout,
12760: 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
12761: I'm not quite ready to invent (e.g. an ssi_with_retry object).
12762:
12763: At least the logic that drives this has been pulled out into loncommon.
12764:
12765:
12766:
12767: ssi_with_retries - Does the server side include of a resource.
12768: if the ssi call returns an error we'll retry it up to
12769: the number of times requested by the caller.
1.596.2.12.2. 8(raebur 12770:4): If we still have a problem, no text is appended to the
1.531 jms 12771: output and we set some global variables.
12772: to indicate to the caller an SSI error occurred.
12773: All of this is supposed to deal with the issues described
1.596.2.12.2. 8(raebur 12774:4): in LON-CAPA BZ 5631 see:
1.531 jms 12775: http://bugs.lon-capa.org/show_bug.cgi?id=5631
12776: by informing the user that this happened.
12777:
12778: Parameters:
12779: resource - The resource to include. This is passed directly, without
12780: interpretation to lonnet::ssi.
12781: form - The form hash parameters that guide the interpretation of the resource
12782:
12783: retries - Number of retries allowed before giving up completely.
12784: Returns:
12785: On success, returns the rendered resource identified by the resource parameter.
12786: Side Effects:
12787: The following global variables can be set:
12788: ssi_error - If an unrecoverable error occurred this becomes true.
12789: It is up to the caller to initialize this to false
12790: if desired.
12791: ssi_error_resource - If an unrecoverable error occurred, this is the value
12792: of the resource that could not be rendered by the ssi
12793: call.
12794: ssi_error_message - The error string fetched from the ssi response
12795: in the event of an error.
12796:
12797:
12798: =head1 HANDLER SUBROUTINE
12799:
12800: ssi_with_retries()
12801:
12802: =head1 SUBROUTINES
12803:
12804: =over
12805:
12806: =item scantron_get_correction() :
12807:
12808: Builds the interface screen to interact with the operator to fix a
12809: specific error condition in a specific scanline
12810:
12811: Arguments:
12812: $r - Apache request object
12813: $i - number of the current scanline
12814: $scan_record - hash ref as returned from &scantron_parse_scanline()
1.596.2.12.2. 9(raebur 12815:9): $scan_config - hash ref as returned from &Apache::lonnet::get_scantron_config()
1.531 jms 12816: $line - full contents of the current scanline
12817: $error - error condition, valid values are
12818: 'incorrectCODE', 'duplicateCODE',
12819: 'doublebubble', 'missingbubble',
12820: 'duplicateID', 'incorrectID'
12821: $arg - extra information needed
12822: For errors:
12823: - duplicateID - paper number that this studentID was seen before on
12824: - duplicateCODE - array ref of the paper numbers this CODE was
12825: seen on before
12826: - incorrectCODE - current incorrect CODE
12827: - doublebubble - array ref of the bubble lines that have double
12828: bubble errors
12829: - missingbubble - array ref of the bubble lines that have missing
12830: bubble errors
12831:
1.596.2.12.2. 0(raebur 12832:2): $randomorder - True if exam folder (or a sub-folder) has randomorder set
12833:2): $randompick - True if exam folder (or a sub-folder) has randompick set
6(raebur 12834:3): $respnumlookup - Reference to HASH mapping question numbers in bubble lines
12835:3): for current line to question number used for same question
12836:3): in "Master Seqence" (as seen by Course Coordinator).
12837:3): $startline - Reference to hash where key is question number (0 is first)
12838:3): and value is number of first bubble line for current student
12839:3): or code-based randompick and/or randomorder.
12840:3):
12841:3):
1.531 jms 12842: =item scantron_get_maxbubble() :
12843:
1.582 raeburn 12844: Arguments:
12845: $nav_error - Reference to scalar which is a flag to indicate a
12846: failure to retrieve a navmap object.
12847: if $nav_error is set to 1 by scantron_get_maxbubble(), the
12848: calling routine should trap the error condition and display the warning
12849: found in &navmap_errormsg().
12850:
1.596.2.12.2. (raeburn 12851:): $scantron_config - Reference to bubblesheet format configuration hash.
12852:):
1.531 jms 12853: Returns the maximum number of bubble lines that are expected to
12854: occur. Does this by walking the selected sequence rendering the
12855: resource and then checking &Apache::lonxml::get_problem_counter()
12856: for what the current value of the problem counter is.
12857:
12858: Caches the results to $env{'form.scantron_maxbubble'},
12859: $env{'form.scantron.bubble_lines.n'},
12860: $env{'form.scantron.first_bubble_line.n'} and
12861: $env{"form.scantron.sub_bubblelines.n"}
1.596.2.12.2. 6(raebur 12862:3): which are the total number of bubble lines, the number of bubble
1.531 jms 12863: lines for response n and number of the first bubble line for response n,
12864: and a comma separated list of numbers of bubble lines for sub-questions
12865: (for optionresponse, matchresponse, and rankresponse items), for response n.
12866:
12867:
12868: =item scantron_validate_missingbubbles() :
12869:
12870: Validates all scanlines in the selected file to not have any
12871: answers that don't have bubbles that have not been verified
12872: to be bubble free.
12873:
12874: =item scantron_process_students() :
12875:
1.596.2.6 raeburn 12876: Routine that does the actual grading of the bubblesheet information.
1.531 jms 12877:
12878: The parsed scanline hash is added to %env
12879:
12880: Then foreach unskipped scanline it does an &Apache::lonnet::ssi()
12881: foreach resource , with the form data of
12882:
12883: 'submitted' =>'scantron'
12884: 'grade_target' =>'grade',
12885: 'grade_username'=> username of student
12886: 'grade_domain' => domain of student
12887: 'grade_courseid'=> of course
12888: 'grade_symb' => symb of resource to grade
12889:
12890: This triggers a grading pass. The problem grading code takes care
12891: of converting the bubbled letter information (now in %env) into a
12892: valid submission.
12893:
12894: =item scantron_upload_scantron_data() :
12895:
1.596.2.6 raeburn 12896: Creates the screen for adding a new bubblesheet data file to a course.
1.531 jms 12897:
12898: =item scantron_upload_scantron_data_save() :
12899:
12900: Adds a provided bubble information data file to the course if user
12901: has the correct privileges to do so.
12902:
12903: =item valid_file() :
12904:
12905: Validates that the requested bubble data file exists in the course.
12906:
12907: =item scantron_download_scantron_data() :
12908:
12909: Shows a list of the three internal files (original, corrected,
1.596.2.6 raeburn 12910: skipped) for a specific bubblesheet data file that exists in the
1.531 jms 12911: course.
12912:
12913: =item scantron_validate_ID() :
12914:
12915: Validates all scanlines in the selected file to not have any
1.556 weissno 12916: invalid or underspecified student/employee IDs
1.531 jms 12917:
1.582 raeburn 12918: =item navmap_errormsg() :
12919:
12920: Returns HTML mark-up inside a <div></div> with a link to re-initialize the course.
12921: Should be called whenever the request to instantiate a navmap object fails.
12922:
1.531 jms 12923: =back
12924:
12925: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>