Annotation of loncom/homework/grades.pm, revision 1.596.2.12.2.60.2.9
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.9(ra 4:an-25): # $Id: grades.pm,v 1.596.2.12.2.60.2.8 2025/01/18 05:20:01 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);
0.2.8(ra 1417:an-25): &Apache::lonnet::store_userdata({'score' => $score},$chosen,$namespace,$udom,$uname,$pb{'ip'});
0.2.7(ra 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);
0.2.8(ra 1884:an-25): &Apache::lonnet::store_userdata({'score' => $score},$launcher,$namespace,$udom,$uname,$pb{'ip'});
0.2.7(ra 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.9(ra 4464:an-25): my ($request,$symb,$stuname,$domain,$newflg,$submitter,
4465:an-25): $part,$queueable,$needpb,$skip_passback,$pbsave) = @_;
1.342 banghart 4466: my @version_parts;
1.104 albertel 4467: my $usec = &Apache::lonnet::getsection($domain,$stuname,
1.257 albertel 4468: $env{'request.course.id'});
1.104 albertel 4469: if (!&canmodify($usec)) { return('not_allowed'); }
1.337 banghart 4470: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
1.251 banghart 4471: my @parts_graded;
1.77 ng 4472: my %newrecord = ();
1.596.2.12.2. 0.2.9(ra 4473:an-25): my ($pts,$wgt,$totchg,$sendupdate,$poss_pb) = ('','',0,0,0);
1.269 raeburn 4474: my %aggregate = ();
4475: my $aggregateflag = 0;
1.596.2.12.2. 1(raebur 4476:5): if ($env{'form.HIDE'.$newflg}) {
4477:5): my ($version,$parts) = split(/:/,$env{'form.HIDE'.$newflg},2);
4478:5): my $numchgs = &makehidden($version,$parts,\%record,$symb,$domain,$stuname,1);
4479:5): $totchg += $numchgs;
4480:5): }
0.2.9(ra 4481:an-25): if ((ref($needpb) eq 'HASH') && (keys(%{$needpb}))) {
4482:an-25): $poss_pb = 1;
4483:an-25): }
0.2.7(ra 4484:an-25): my (%weights,%awardeds,%excuseds);
1.301 albertel 4485: my @parts = split(/:/,$env{'form.partlist'.$newflg});
4486: foreach my $new_part (@parts) {
1.596.2.12.2. 0.2.7(ra 4487:an-25): #collaborator ($submitter may vary for different parts)
1.259 banghart 4488: if ($submitter && $new_part ne $part) { next; }
4489: my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
1.596.2.12.2. 0.2.9(ra 4490:an-25): if ($poss_pb) {
4491:an-25): $weights{$symb}{$new_part} =
4492:an-25): &Apache::lonnet::EXT('resource.'.$new_part.'.weight',$symb,$udom,$uname);
4493:an-25): } elsif ($env{'form.WGT'.$newflg.'_'.$new_part} eq '') {
0.2.7(ra 4494:an-25): $weights{$symb}{$new_part} = 1;
4495:an-25): } else {
4496:an-25): $weights{$symb}{$new_part} = $env{'form.WGT'.$newflg.'_'.$new_part};
4497:an-25): }
1.125 ng 4498: if ($dropMenu eq 'excused') {
1.596.2.12.2. 0.2.7(ra 4499:an-25): $excuseds{$symb}{$new_part} = 1;
4500:an-25): $awardeds{$symb}{$new_part} = '';
1.259 banghart 4501: if ($record{'resource.'.$new_part.'.solved'} ne 'excused') {
4502: $newrecord{'resource.'.$new_part.'.solved'} = 'excused';
4503: if (exists($record{'resource.'.$new_part.'.awarded'})) {
4504: $newrecord{'resource.'.$new_part.'.awarded'} = '';
1.58 albertel 4505: }
1.364 banghart 4506: $newrecord{'resource.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.596.2.12.2. 0.2.7(ra 4507:an-25): $sendupdate ++;
1.58 albertel 4508: }
1.125 ng 4509: } elsif ($dropMenu eq 'reset status'
1.259 banghart 4510: && exists($record{'resource.'.$new_part.'.solved'})) { #don't bother if no old records -> no attempts
1.524 raeburn 4511: foreach my $key (keys(%record)) {
1.259 banghart 4512: if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
1.197 albertel 4513: }
1.259 banghart 4514: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 4515: "$env{'user.name'}:$env{'user.domain'}";
1.270 albertel 4516: my $totaltries = $record{'resource.'.$part.'.tries'};
4517:
4518: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
4519: [$new_part]);
4520: my $aggtries =$totaltries;
1.269 raeburn 4521: if ($last_resets{$new_part}) {
1.270 albertel 4522: $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
4523: $new_part);
1.269 raeburn 4524: }
1.270 albertel 4525:
4526: my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
1.269 raeburn 4527: if ($aggtries > 0) {
1.327 albertel 4528: &decrement_aggs($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
1.269 raeburn 4529: $aggregateflag = 1;
4530: }
1.596.2.12.2. 0.2.7(ra 4531:an-25): $sendupdate ++;
4532:an-25): $excuseds{$symb}{$new_part} = '';
4533:an-25): $awardeds{$symb}{$new_part} = '';
1.125 ng 4534: } elsif ($dropMenu eq '') {
1.259 banghart 4535: $pts = ($env{'form.GD_BOX'.$newflg.'_'.$new_part} ne '' ?
4536: $env{'form.GD_BOX'.$newflg.'_'.$new_part} :
4537: $env{'form.RADVAL'.$newflg.'_'.$new_part});
4538: if ($pts eq '' && $env{'form.GD_SEL'.$newflg.'_'.$new_part} eq '') {
1.153 albertel 4539: next;
4540: }
1.259 banghart 4541: $wgt = $env{'form.WGT'.$newflg.'_'.$new_part} eq '' ? 1 :
4542: $env{'form.WGT'.$newflg.'_'.$new_part};
1.41 ng 4543: my $partial= $pts/$wgt;
1.596.2.12.2. 0.2.7(ra 4544:an-25): $awardeds{$symb}{$new_part} = $partial;
4545:an-25): $excuseds{$symb}{$new_part} = '';
1.259 banghart 4546: if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
1.153 albertel 4547: #do not update score for part if not changed.
1.346 banghart 4548: &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
1.153 albertel 4549: next;
1.251 banghart 4550: } else {
1.524 raeburn 4551: push(@parts_graded,$new_part);
1.596.2.12.2. 0.2.7(ra 4552:an-25): $sendupdate ++;
1.153 albertel 4553: }
1.259 banghart 4554: if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
4555: $newrecord{'resource.'.$new_part.'.awarded'} = $partial;
1.153 albertel 4556: }
1.259 banghart 4557: my $reckey = 'resource.'.$new_part.'.solved';
1.41 ng 4558: if ($partial == 0) {
1.153 albertel 4559: if ($record{$reckey} ne 'incorrect_by_override') {
4560: $newrecord{$reckey} = 'incorrect_by_override';
4561: }
1.41 ng 4562: } else {
1.153 albertel 4563: if ($record{$reckey} ne 'correct_by_override') {
4564: $newrecord{$reckey} = 'correct_by_override';
4565: }
4566: }
4567: if ($submitter &&
1.259 banghart 4568: ($record{'resource.'.$new_part.'.submitted_by'} ne $submitter)) {
4569: $newrecord{'resource.'.$new_part.'.submitted_by'} = $submitter;
1.41 ng 4570: }
1.259 banghart 4571: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 4572: "$env{'user.name'}:$env{'user.domain'}";
1.41 ng 4573: }
1.259 banghart 4574: # unless problem has been graded, set flag to version the submitted files
1.305 banghart 4575: unless ($record{'resource.'.$new_part.'.solved'} =~ /^correct_/ ||
4576: $record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override' ||
4577: $dropMenu eq 'reset status')
4578: {
1.524 raeburn 4579: push(@version_parts,$new_part);
1.259 banghart 4580: }
1.41 ng 4581: }
1.301 albertel 4582: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4583: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4584:
1.344 albertel 4585: if (%newrecord) {
4586: if (@version_parts) {
1.364 banghart 4587: my @changed_keys = &version_portfiles(\%record, \@parts_graded,
4588: $env{'request.course.id'}, $symb, $domain, $stuname, \@version_parts);
1.344 albertel 4589: @newrecord{@changed_keys} = @record{@changed_keys};
1.367 albertel 4590: foreach my $new_part (@version_parts) {
4591: &handback_files($request,$symb,$stuname,$domain,$newflg,
4592: $new_part,\%newrecord);
4593: }
1.259 banghart 4594: }
1.44 ng 4595: &Apache::lonnet::cstore(\%newrecord,$symb,
1.257 albertel 4596: $env{'request.course.id'},$domain,$stuname);
1.380 albertel 4597: &check_and_remove_from_queue(\@parts,\%record,\%newrecord,$symb,
1.596.2.12.2. 8(raebur 4598:1): $cdom,$cnum,$domain,$stuname,$queueable);
1.41 ng 4599: }
1.269 raeburn 4600: if ($aggregateflag) {
4601: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 4602: $cdom,$cnum);
1.269 raeburn 4603: }
1.596.2.12.2. 0.2.9(ra 4604:an-25): if (($sendupdate || $totchg) && (!$submitter) && ($poss_pb)) {
4605:an-25): &process_passbacks('handgrade',[$symb],$cdom,$cnum,$domain,$stuname,$usec,\%weights,
4606:an-25): \%awardeds,\%excuseds,$needpb,$skip_passback,$pbsave);
0.2.7(ra 4607:an-25): }
4608:an-25): return ('',$pts,$wgt,$totchg,$sendupdate);
1(raebur 4609:5): }
4610:5):
4611:5): sub makehidden {
4612:5): my ($version,$parts,$record,$symb,$domain,$stuname,$tolog) = @_;
4613:5): return unless (ref($record) eq 'HASH');
4614:5): my %modified;
4615:5): my $numchanged = 0;
4616:5): if (exists($record->{$version.':keys'})) {
4617:5): my $partsregexp = $parts;
4618:5): $partsregexp =~ s/,/|/g;
4619:5): foreach my $key (split(/\:/,$record->{$version.':keys'})) {
4620:5): if ($key =~ /^resource\.(?:$partsregexp)\.([^\.]+)$/) {
4621:5): my $item = $1;
4622:5): unless (($item eq 'solved') || ($item =~ /^award(|msg|ed)$/)) {
4623:5): $modified{$key} = $record->{$version.':'.$key};
4624:5): }
4625:5): } elsif ($key =~ m{^(resource\.(?:$partsregexp)\.[^\.]+\.)(.+)$}) {
4626:5): $modified{$1.'hidden'.$2} = $record->{$version.':'.$key};
4627:5): } elsif ($key =~ /^(ip|timestamp|host)$/) {
4628:5): $modified{$key} = $record->{$version.':'.$key};
4629:5): }
4630:5): }
4631:5): if (keys(%modified)) {
4632:5): if (&Apache::lonnet::putstore($env{'request.course.id'},$symb,$version,\%modified,
4633:5): $domain,$stuname,$tolog) eq 'ok') {
4634:5): $numchanged ++;
4635:5): }
4636:5): }
4637:5): }
4638:5): return $numchanged;
1.36 ng 4639: }
1.322 albertel 4640:
1.380 albertel 4641: sub check_and_remove_from_queue {
1.596.2.12.2. 8(raebur 4642:1): my ($parts,$record,$newrecord,$symb,$cdom,$cnum,$domain,$stuname,$queueable) = @_;
1.380 albertel 4643: my @ungraded_parts;
4644: foreach my $part (@{$parts}) {
4645: if ( $record->{ 'resource.'.$part.'.awarded'} eq ''
4646: && $record->{ 'resource.'.$part.'.solved' } ne 'excused'
4647: && $newrecord->{'resource.'.$part.'.awarded'} eq ''
4648: && $newrecord->{'resource.'.$part.'.solved' } ne 'excused'
4649: ) {
1.596.2.12.2. 8(raebur 4650:1): if ($queueable->{$part}) {
4651:1): push(@ungraded_parts, $part);
4652:1): }
1.380 albertel 4653: }
4654: }
4655: if ( !@ungraded_parts ) {
4656: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,
4657: $cnum,$domain,$stuname);
4658: }
4659: }
4660:
1.337 banghart 4661: sub handback_files {
4662: my ($request,$symb,$stuname,$domain,$newflg,$new_part,$newrecord) = @_;
1.517 raeburn 4663: my $portfolio_root = '/userfiles/portfolio';
1.582 raeburn 4664: my $res_error;
4665: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
4666: if ($res_error) {
4667: $request->print('<br />'.&navmap_errormsg().'<br />');
4668: return;
4669: }
1.596.2.4 raeburn 4670: my @handedback;
4671: my $file_msg;
1.375 albertel 4672: my @part_response_id = &flatten_responseType($responseType);
4673: foreach my $part_response_id (@part_response_id) {
4674: my ($part_id,$resp_id) = @{ $part_response_id };
4675: my $part_resp = join('_',@{ $part_response_id });
1.596.2.4 raeburn 4676: if (($env{'form.'.$newflg.'_'.$part_resp.'_countreturndoc'} =~ /^\d+$/) & ($new_part eq $part_id)) {
4677: for (my $counter=1; $counter<=$env{'form.'.$newflg.'_'.$part_resp.'_countreturndoc'}; $counter++) {
1.337 banghart 4678: # if multiple files are uploaded names will be 'returndoc2','returndoc3'
1.596.2.4 raeburn 4679: if ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$counter}) {
4680: my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$counter.'.filename'};
1.338 banghart 4681: my ($directory,$answer_file) =
1.596.2.4 raeburn 4682: ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$counter} =~ /^(.*?)([^\/]*)$/);
1.338 banghart 4683: my ($answer_name,$answer_ver,$answer_ext) =
4684: &file_name_version_ext($answer_file);
1.355 banghart 4685: my ($portfolio_path) = ($directory =~ /^.+$stuname\/portfolio(.*)/);
1.517 raeburn 4686: my $getpropath = 1;
1.596.2.12.2. (raeburn 4687:): my ($dir_list,$listerror) =
4688:): &Apache::lonnet::dirlist($portfolio_root.$portfolio_path,
4689:): $domain,$stuname,$getpropath);
4690:): my $version = &get_next_version($answer_name,$answer_ext,$dir_list);
3(raebur 4691:3): # fix filename
1.355 banghart 4692: my ($save_file_name) = (($directory.$answer_name.".$version.".$answer_ext) =~ /^.+\/${stuname}\/(.*)/);
4693: my $result=&Apache::lonnet::finishuserfileupload($stuname,$domain,
1.596.2.4 raeburn 4694: $newflg.'_'.$part_resp.'_returndoc'.$counter,
1.355 banghart 4695: $save_file_name);
1.337 banghart 4696: if ($result !~ m|^/uploaded/|) {
1.536 raeburn 4697: $request->print('<br /><span class="LC_error">'.
4698: &mt('An error occurred ([_1]) while trying to upload [_2].',
1.596.2.4 raeburn 4699: $result,$newflg.'_'.$part_resp.'_returndoc'.$counter).
1.536 raeburn 4700: '</span>');
1.356 banghart 4701: } else {
1.360 banghart 4702: # mark the file as read only
1.596.2.4 raeburn 4703: push(@handedback,$save_file_name);
1.367 albertel 4704: if (exists($$newrecord{"resource.$new_part.$resp_id.handback"})) {
4705: $$newrecord{"resource.$new_part.$resp_id.handback"}.=',';
4706: }
4707: $$newrecord{"resource.$new_part.$resp_id.handback"} .= $save_file_name;
1.596.2.4 raeburn 4708: $file_msg.='<span class="LC_filename"><a href="/uploaded/'."$domain/$stuname/".$save_file_name.'">'.$save_file_name."</a></span> <br />";
1.367 albertel 4709:
1.337 banghart 4710: }
1.596.2.12.2. 3(raebur 4711: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 4712: }
4713: }
4714: }
1.596.2.4 raeburn 4715: }
4716: if (@handedback > 0) {
4717: $request->print('<br />');
4718: my @what = ($symb,$env{'request.course.id'},'handback');
4719: &Apache::lonnet::mark_as_readonly($domain,$stuname,\@handedback,\@what);
4720: my $user_lh = &Apache::loncommon::user_lang($stuname,$domain,$env{'request.course.id'});
4721: my ($subject,$message);
4722: if (scalar(@handedback) == 1) {
4723: $subject = &mt_user($user_lh,'File Handed Back by Instructor');
1.596.2.12.2. 1(raebur 4724:0): $message = &mt_user($user_lh,'A file has been returned that was originally submitted in response to: ');
1.596.2.4 raeburn 4725: } else {
4726: $subject = &mt_user($user_lh,'Files Handed Back by Instructor');
4727: $message = &mt_user($user_lh,'Files have been returned that were originally submitted in response to: ');
4728: }
4729: $message .= "<p><strong>".&Apache::lonnet::gettitle($symb)." </strong></p>";
4730: $message .= &mt_user($user_lh,'The returned file(s) are named: [_1]',"<br />$file_msg <br />").
4731: &mt_user($user_lh,'The file(s) can be found in your [_1]portfolio[_2].','<a href="/adm/portfolio">','</a>');
4732: my ($feedurl,$showsymb) =
4733: &get_feedurl_and_symb($symb,$domain,$stuname);
4734: my $restitle = &Apache::lonnet::gettitle($symb);
4735: $subject .= ' '.&mt_user($user_lh,'(File Returned)').' ['.$restitle.']';
4736: my $msgstatus =
4737: &Apache::lonmsg::user_normal_msg($stuname,$domain,$subject,
4738: $message,undef,$feedurl,undef,undef,undef,$showsymb,
4739: $restitle);
4740: if ($msgstatus) {
4741: $request->print(&mt('Notification message status: [_1]','<span class="LC_info">'.$msgstatus.'</span>').'<br />');
4742: }
4743: }
1.338 banghart 4744: return;
1.337 banghart 4745: }
4746:
1.418 albertel 4747: sub get_feedurl_and_symb {
4748: my ($symb,$uname,$udom) = @_;
4749: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
4750: $url = &Apache::lonnet::clutter($url);
4751: my $encrypturl=&Apache::lonnet::EXT('resource.0.encrypturl',
4752: $symb,$udom,$uname);
4753: if ($encrypturl =~ /^yes$/i) {
4754: &Apache::lonenc::encrypted(\$url,1);
4755: &Apache::lonenc::encrypted(\$symb,1);
4756: }
4757: return ($url,$symb);
4758: }
4759:
1.313 banghart 4760: sub get_submitted_files {
4761: my ($udom,$uname,$partid,$respid,$record) = @_;
4762: my @files;
4763: if ($$record{"resource.$partid.$respid.portfiles"}) {
4764: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
4765: foreach my $file (split(',',$$record{"resource.$partid.$respid.portfiles"})) {
4766: push(@files,$file_url.$file);
4767: }
4768: }
4769: if ($$record{"resource.$partid.$respid.uploadedurl"}) {
4770: push(@files,$$record{"resource.$partid.$respid.uploadedurl"});
4771: }
4772: return (\@files);
4773: }
1.322 albertel 4774:
1.269 raeburn 4775: # ----------- Provides number of tries since last reset.
4776: sub get_num_tries {
4777: my ($record,$last_reset,$part) = @_;
4778: my $timestamp = '';
4779: my $num_tries = 0;
4780: if ($$record{'version'}) {
4781: for (my $version=$$record{'version'};$version>=1;$version--) {
4782: if (exists($$record{$version.':resource.'.$part.'.solved'})) {
4783: $timestamp = $$record{$version.':timestamp'};
4784: if ($timestamp > $last_reset) {
4785: $num_tries ++;
4786: } else {
4787: last;
4788: }
4789: }
4790: }
4791: }
4792: return $num_tries;
4793: }
4794:
4795: # ----------- Determine decrements required in aggregate totals
4796: sub decrement_aggs {
4797: my ($symb,$part,$aggregate,$aggtries,$totaltries,$solvedstatus) = @_;
4798: my %decrement = (
4799: attempts => 0,
4800: users => 0,
4801: correct => 0
4802: );
4803: $decrement{'attempts'} = $aggtries;
4804: if ($solvedstatus =~ /^correct/) {
4805: $decrement{'correct'} = 1;
4806: }
4807: if ($aggtries == $totaltries) {
4808: $decrement{'users'} = 1;
4809: }
1.524 raeburn 4810: foreach my $type (keys(%decrement)) {
1.269 raeburn 4811: $$aggregate{$symb."\0".$part."\0".$type} = -$decrement{$type};
4812: }
4813: return;
4814: }
4815:
4816: # ----------- Determine timestamps for last reset of aggregate totals for parts
4817: sub get_last_resets {
1.270 albertel 4818: my ($symb,$courseid,$partids) =@_;
4819: my %last_resets;
1.269 raeburn 4820: my $cdom = $env{'course.'.$courseid.'.domain'};
4821: my $cname = $env{'course.'.$courseid.'.num'};
1.271 albertel 4822: my @keys;
4823: foreach my $part (@{$partids}) {
4824: push(@keys,"$symb\0$part\0resettime");
4825: }
4826: my %results=&Apache::lonnet::get('nohist_resourcetracker',\@keys,
4827: $cdom,$cname);
4828: foreach my $part (@{$partids}) {
4829: $last_resets{$part}=$results{"$symb\0$part\0resettime"};
1.269 raeburn 4830: }
1.270 albertel 4831: return %last_resets;
1.269 raeburn 4832: }
4833:
1.251 banghart 4834: # ----------- Handles creating versions for portfolio files as answers
4835: sub version_portfiles {
1.343 banghart 4836: my ($record, $parts_graded, $courseid, $symb, $domain, $stu_name, $v_flag) = @_;
1.263 banghart 4837: my $version_parts = join('|',@$v_flag);
1.343 banghart 4838: my @returned_keys;
1.255 banghart 4839: my $parts = join('|', @$parts_graded);
1.517 raeburn 4840: my $portfolio_root = '/userfiles/portfolio';
1.277 albertel 4841: foreach my $key (keys(%$record)) {
1.259 banghart 4842: my $new_portfiles;
1.263 banghart 4843: if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
1.342 banghart 4844: my @versioned_portfiles;
1.367 albertel 4845: my @portfiles = split(/\s*,\s*/,$$record{$key});
1.252 banghart 4846: foreach my $file (@portfiles) {
1.306 banghart 4847: &Apache::lonnet::unmark_as_readonly($domain,$stu_name,[$symb,$env{'request.course.id'}],$file);
1.304 albertel 4848: my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*)$/);
4849: my ($answer_name,$answer_ver,$answer_ext) =
4850: &file_name_version_ext($answer_file);
1.596.2.12.2. (raeburn 4851:): my $getpropath = 1;
4852:): my ($dir_list,$listerror) =
4853:): &Apache::lonnet::dirlist($portfolio_root.$directory,$domain,
4854:): $stu_name,$getpropath);
4855:): my $version = &get_next_version($answer_name,$answer_ext,$dir_list);
1.306 banghart 4856: my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version);
4857: if ($new_answer ne 'problem getting file') {
1.342 banghart 4858: push(@versioned_portfiles, $directory.$new_answer);
1.306 banghart 4859: &Apache::lonnet::mark_as_readonly($domain,$stu_name,
1.367 albertel 4860: [$directory.$new_answer],
1.306 banghart 4861: [$symb,$env{'request.course.id'},'graded']);
1.259 banghart 4862: }
1.252 banghart 4863: }
1.343 banghart 4864: $$record{$key} = join(',',@versioned_portfiles);
4865: push(@returned_keys,$key);
1.251 banghart 4866: }
1.596.2.12.2. 0.2.6(ra 4867:ug-24): }
4868:ug-24): return (@returned_keys);
1.305 banghart 4869: }
4870:
1.307 banghart 4871: sub get_next_version {
1.341 banghart 4872: my ($answer_name, $answer_ext, $dir_list) = @_;
1.307 banghart 4873: my $version;
1.596.2.12.2. (raeburn 4874:): if (ref($dir_list) eq 'ARRAY') {
4875:): foreach my $row (@{$dir_list}) {
4876:): my ($file) = split(/\&/,$row,2);
4877:): my ($file_name,$file_version,$file_ext) =
4878:): &file_name_version_ext($file);
4879:): if (($file_name eq $answer_name) &&
4880:): ($file_ext eq $answer_ext)) {
4881:): # gets here if filename and extension match,
4882:): # regardless of version
1.307 banghart 4883: if ($file_version ne '') {
1.596.2.12.2. (raeburn 4884:): # a versioned file is found so save it for later
4885:): if ($file_version > $version) {
4886:): $version = $file_version;
4887:): }
1.307 banghart 4888: }
4889: }
4890: }
1.596.2.12.2. (raeburn 4891:): }
1.307 banghart 4892: $version ++;
4893: return($version);
4894: }
4895:
1.305 banghart 4896: sub version_selected_portfile {
1.306 banghart 4897: my ($domain,$stu_name,$directory,$file_name,$version) = @_;
4898: my ($answer_name,$answer_ver,$answer_ext) =
4899: &file_name_version_ext($file_name);
4900: my $new_answer;
4901: $env{'form.copy'} = &Apache::lonnet::getfile("/uploaded/$domain/$stu_name/portfolio$directory$file_name");
4902: if($env{'form.copy'} eq '-1') {
4903: $new_answer = 'problem getting file';
4904: } else {
4905: $new_answer = $answer_name.'.'.$version.'.'.$answer_ext;
4906: my $copy_result = &Apache::lonnet::finishuserfileupload(
4907: $stu_name,$domain,'copy',
4908: '/portfolio'.$directory.$new_answer);
4909: }
4910: return ($new_answer);
1.251 banghart 4911: }
4912:
1.304 albertel 4913: sub file_name_version_ext {
4914: my ($file)=@_;
4915: my @file_parts = split(/\./, $file);
4916: my ($name,$version,$ext);
4917: if (@file_parts > 1) {
4918: $ext=pop(@file_parts);
4919: if (@file_parts > 1 && $file_parts[-1] =~ /^\d+$/) {
4920: $version=pop(@file_parts);
4921: }
4922: $name=join('.',@file_parts);
4923: } else {
4924: $name=join('.',@file_parts);
4925: }
4926: return($name,$version,$ext);
4927: }
4928:
1.44 ng 4929: #--------------------------------------------------------------------------------------
4930: #
4931: #-------------------------- Next few routines handles grading by section or whole class
4932: #
4933: #--- Javascript to handle grading by section or whole class
1.42 ng 4934: sub viewgrades_js {
4935: my ($request) = shift;
4936:
1.539 riegler 4937: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
1.596.2.12.2. 6(raebur 4938:6): &js_escape(\$alertmsg);
1(raebur 4939:0): $request->print(&Apache::lonhtmlcommon::scripttag(<<VIEWJAVASCRIPT));
1.45 ng 4940: function writePoint(partid,weight,point) {
1.125 ng 4941: var radioButton = document.classgrade["RADVAL_"+partid];
4942: var textbox = document.classgrade["TEXTVAL_"+partid];
1.42 ng 4943: if (point == "textval") {
1.125 ng 4944: point = document.classgrade["TEXTVAL_"+partid].value;
1.109 matthew 4945: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 4946: alert("$alertmsg"+parseFloat(point));
1.42 ng 4947: var resetbox = false;
4948: for (var i=0; i<radioButton.length; i++) {
4949: if (radioButton[i].checked) {
4950: textbox.value = i;
4951: resetbox = true;
4952: }
4953: }
4954: if (!resetbox) {
4955: textbox.value = "";
4956: }
4957: return;
4958: }
1.109 matthew 4959: if (parseFloat(point) > parseFloat(weight)) {
4960: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 4961: ") greater than the weight for the part. Accept?");
4962: if (resp == false) {
4963: textbox.value = "";
4964: return;
4965: }
4966: }
1.42 ng 4967: for (var i=0; i<radioButton.length; i++) {
4968: radioButton[i].checked=false;
1.109 matthew 4969: if (parseFloat(point) == i) {
1.42 ng 4970: radioButton[i].checked=true;
4971: }
4972: }
1.41 ng 4973:
1.42 ng 4974: } else {
1.125 ng 4975: textbox.value = parseFloat(point);
1.42 ng 4976: }
1.41 ng 4977: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 4978: var user = document.classgrade["ctr"+i].value;
1.289 albertel 4979: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 4980: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
4981: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
4982: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 4983: if (saveval != "correct") {
4984: scorename.value = point;
1.43 ng 4985: if (selname[0].selected != true) {
4986: selname[0].selected = true;
4987: }
1.42 ng 4988: }
4989: }
1.125 ng 4990: document.classgrade["SELVAL_"+partid][0].selected = true;
1.42 ng 4991: }
4992:
4993: function writeRadText(partid,weight) {
1.125 ng 4994: var selval = document.classgrade["SELVAL_"+partid];
4995: var radioButton = document.classgrade["RADVAL_"+partid];
1.265 www 4996: var override = document.classgrade["FORCE_"+partid].checked;
1.125 ng 4997: var textbox = document.classgrade["TEXTVAL_"+partid];
4998: if (selval[1].selected || selval[2].selected) {
1.42 ng 4999: for (var i=0; i<radioButton.length; i++) {
5000: radioButton[i].checked=false;
5001:
5002: }
5003: textbox.value = "";
5004:
5005: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 5006: var user = document.classgrade["ctr"+i].value;
1.289 albertel 5007: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 5008: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
5009: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
5010: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 5011: if ((saveval != "correct") || override) {
1.42 ng 5012: scorename.value = "";
1.125 ng 5013: if (selval[1].selected) {
5014: selname[1].selected = true;
5015: } else {
5016: selname[2].selected = true;
5017: if (Number(document.classgrade["GD_"+user+"_"+partid+"_tries"].value))
5018: {document.classgrade["GD_"+user+"_"+partid+"_tries"].value = '0';}
5019: }
1.42 ng 5020: }
5021: }
1.43 ng 5022: } else {
5023: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 5024: var user = document.classgrade["ctr"+i].value;
1.289 albertel 5025: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 5026: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
5027: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
5028: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 5029: if ((saveval != "correct") || override) {
1.125 ng 5030: scorename.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
1.43 ng 5031: selname[0].selected = true;
5032: }
5033: }
5034: }
1.42 ng 5035: }
5036:
5037: function changeSelect(partid,user) {
1.125 ng 5038: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
5039: var textbox = document.classgrade["GD_"+user+'_'+partid+"_awarded"];
1.44 ng 5040: var point = textbox.value;
1.125 ng 5041: var weight = document.classgrade["weight_"+partid].value;
1.44 ng 5042:
1.109 matthew 5043: if (isNaN(point) || parseFloat(point) < 0) {
1.539 riegler 5044: alert("$alertmsg"+parseFloat(point));
1.44 ng 5045: textbox.value = "";
5046: return;
5047: }
1.109 matthew 5048: if (parseFloat(point) > parseFloat(weight)) {
5049: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 5050: ") greater than the weight of the part. Accept?");
5051: if (resp == false) {
5052: textbox.value = "";
5053: return;
5054: }
5055: }
1.42 ng 5056: selval[0].selected = true;
5057: }
5058:
5059: function changeOneScore(partid,user) {
1.125 ng 5060: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
5061: if (selval[1].selected || selval[2].selected) {
5062: document.classgrade["GD_"+user+'_'+partid+"_awarded"].value = "";
5063: if (selval[2].selected) {
5064: document.classgrade["GD_"+user+'_'+partid+"_tries"].value = "0";
5065: }
1.269 raeburn 5066: }
1.42 ng 5067: }
5068:
5069: function resetEntry(numpart) {
5070: for (ctpart=0;ctpart<numpart;ctpart++) {
1.125 ng 5071: var partid = document.classgrade["partid_"+ctpart].value;
5072: var radioButton = document.classgrade["RADVAL_"+partid];
5073: var textbox = document.classgrade["TEXTVAL_"+partid];
5074: var selval = document.classgrade["SELVAL_"+partid];
1.42 ng 5075: for (var i=0; i<radioButton.length; i++) {
5076: radioButton[i].checked=false;
5077:
5078: }
5079: textbox.value = "";
5080: selval[0].selected = true;
5081:
5082: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 5083: var user = document.classgrade["ctr"+i].value;
1.289 albertel 5084: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 5085: var resetscore = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
5086: resetscore.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
5087: var resettries = document.classgrade["GD_"+user+"_"+partid+"_tries"];
5088: resettries.value = document.classgrade["GD_"+user+"_"+partid+"_tries_s"].value;
5089: var saveselval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
5090: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 5091: if (saveselval == "excused") {
1.43 ng 5092: if (selname[1].selected == false) { selname[1].selected = true;}
1.42 ng 5093: } else {
1.43 ng 5094: if (selname[0].selected == false) {selname[0].selected = true};
1.42 ng 5095: }
5096: }
1.41 ng 5097: }
1.42 ng 5098: }
5099:
1.41 ng 5100: VIEWJAVASCRIPT
1.42 ng 5101: }
5102:
1.44 ng 5103: #--- show scores for a section or whole class w/ option to change/update a score
1.42 ng 5104: sub viewgrades {
1.596.2.12.2. 1(raebur 5105:0): my ($request,$symb) = @_;
0.2.4(ra 5106:ul-23): my ($is_tool,$toolsymb);
5107:ul-23): if ($symb =~ /ext\.tool$/) {
5108:ul-23): $is_tool = 1;
5109:ul-23): $toolsymb = $symb;
5110:ul-23): }
1.42 ng 5111: &viewgrades_js($request);
1.41 ng 5112:
1.168 albertel 5113: #need to make sure we have the correct data for later EXT calls,
5114: #thus invalidate the cache
5115: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 5116: $env{'course.'.$env{'request.course.id'}.'.num'},
5117: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 5118: &Apache::lonnet::clear_EXT_cache_status();
5119:
1.398 albertel 5120: my $result='<h3><span class="LC_info">'.&mt('Manual Grading').'</span></h3>';
1.41 ng 5121:
5122: #view individual student submission form - called using Javascript viewOneStudent
1.324 albertel 5123: $result.=&jscriptNform($symb);
1.41 ng 5124:
1.44 ng 5125: #beginning of class grading form
1.442 banghart 5126: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.41 ng 5127: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1.418 albertel 5128: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.38 ng 5129: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.432 banghart 5130: &build_section_inputs().
1.442 banghart 5131: '<input type="hidden" name="Status" value="'.$env{'stu_status'}.'" />'."\n".
1.72 ng 5132:
1.596.2.12.2. 7(raebur 5133:6): #retrieve selected groups
5134:6): my (@groups,$group_display);
8(raebur 5135:6): @groups = &Apache::loncommon::get_env_multiple('form.group');
7(raebur 5136:6): if (grep(/^all$/,@groups)) {
5137:6): @groups = ('all');
5138:6): } elsif (grep(/^none$/,@groups)) {
5139:6): @groups = ('none');
5140:6): } elsif (@groups > 0) {
5141:6): $group_display = join(', ',@groups);
5142:6): }
5143:6):
5144:6): my ($common_header,$specific_header,@sections,$section_display);
6(raebur 5145:1): if ($env{'request.course.sec'} ne '') {
5146:1): @sections = ($env{'request.course.sec'});
5147:1): } else {
5148:1): @sections = &Apache::loncommon::get_env_multiple('form.section');
5149:1): }
5150:1):
5151:1): # Check if Save button should be usable
5152:1): my $disabled = ' disabled="disabled"';
5153:1): if ($perm{'mgr'}) {
5154:1): if (grep(/^all$/,@sections)) {
5155:1): undef($disabled);
5156:1): } else {
5157:1): foreach my $sec (@sections) {
5158:1): if (&canmodify($sec)) {
5159:1): undef($disabled);
5160:1): last;
5161:1): }
5162:1): }
5163:1): }
5164:1): }
7(raebur 5165:6): if (grep(/^all$/,@sections)) {
5166:6): @sections = ('all');
5167:6): if ($group_display) {
5168:6): $common_header = &mt('Assign Common Grade to Students in Group(s) [_1]',$group_display);
5169:6): $specific_header = &mt('Assign Grade to Specific Students in Group(s) [_1]',$group_display);
5170:6): } elsif (grep(/^none$/,@groups)) {
5171:6): $common_header = &mt('Assign Common Grade to Students not assigned to any groups');
5172:6): $specific_header = &mt('Assign Grade to Specific Students not assigned to any groups');
5173:6): } else {
5174:6): $common_header = &mt('Assign Common Grade to Class');
5175:6): $specific_header = &mt('Assign Grade to Specific Students in Class');
5176:6): }
5177:6): } elsif (grep(/^none$/,@sections)) {
5178:6): @sections = ('none');
5179:6): if ($group_display) {
5180:6): $common_header = &mt('Assign Common Grade to Students in no Section and in Group(s) [_1]',$group_display);
5181:6): $specific_header = &mt('Assign Grade to Specific Students in no Section and in Group(s)',$group_display);
5182:6): } elsif (grep(/^none$/,@groups)) {
5183:6): $common_header = &mt('Assign Common Grade to Students in no Section and in no Group');
5184:6): $specific_header = &mt('Assign Grade to Specific Students in no Section and in no Group');
5185:6): } else {
5186:6): $common_header = &mt('Assign Common Grade to Students in no Section');
5187:6): $specific_header = &mt('Assign Grade to Specific Students in no Section');
5188:6): }
5189:6): } else {
5190:6): $section_display = join (", ",@sections);
5191:6): if ($group_display) {
5192:6): $common_header = &mt('Assign Common Grade to Students in Section(s) [_1], and in Group(s) [_2]',
5193:6): $section_display,$group_display);
5194:6): $specific_header = &mt('Assign Grade to Specific Students in Section(s) [_1], and in Group(s) [_2]',
5195:6): $section_display,$group_display);
5196:6): } elsif (grep(/^none$/,@groups)) {
5197:6): $common_header = &mt('Assign Common Grade to Students in Section(s) [_1] and no Group',$section_display);
5198:6): $specific_header = &mt('Assign Grade to Specific Students in Section(s) [_1] and no Group',$section_display);
5199:6): } else {
5200:6): $common_header = &mt('Assign Common Grade to Students in Section(s) [_1]',$section_display);
5201:6): $specific_header = &mt('Assign Grade to Specific Students in Section(s) [_1]',$section_display);
5202:6): }
1.52 albertel 5203: }
1.596.2.12.2. 7(raebur 5204:6): my %submit_types = &substatus_options();
5205:6): my $submission_status = $submit_types{$env{'form.submitonly'}};
5206:6):
5207:6): if ($env{'form.submitonly'} eq 'all') {
5208:6): $result.= '<h3>'.$common_header.'</h3>';
5209:6): } else {
0.2.4(ra 5210:ul-23): my $text;
5211:ul-23): if ($is_tool) {
5212:ul-23): $text = &mt('(transaction status: "[_1]")',$submission_status);
5213:ul-23): } else {
5214:ul-23): $text = &mt('(submission status: "[_1]")',$submission_status);
5215:ul-23): }
5216:ul-23): $result.= '<h3>'.$common_header.' '.$text.'</h3>';
7(raebur 5217:6): }
5218:6): $result .= &Apache::loncommon::start_data_table();
1.44 ng 5219: #radio buttons/text box for assigning points for a section or class.
5220: #handles different parts of a problem
1.582 raeburn 5221: my $res_error;
5222: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
5223: if ($res_error) {
5224: return &navmap_errormsg();
5225: }
1.42 ng 5226: my %weight = ();
5227: my $ctsparts = 0;
1.45 ng 5228: my %seen = ();
1.596.2.12.2. 0.2.4(ra 5229:ul-23): my @part_response_id;
5230:ul-23): if ($is_tool) {
5231:ul-23): @part_response_id = ([0,'']);
5232:ul-23): } else {
5233:ul-23): @part_response_id = &flatten_responseType($responseType);
5234:ul-23): }
1.375 albertel 5235: foreach my $part_response_id (@part_response_id) {
5236: my ($partid,$respid) = @{ $part_response_id };
5237: my $part_resp = join('_',@{ $part_response_id });
1.45 ng 5238: next if $seen{$partid};
5239: $seen{$partid}++;
1.42 ng 5240: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
5241: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
5242:
1.324 albertel 5243: my $display_part=&get_display_part($partid,$symb);
1.485 albertel 5244: my $radio.='<table border="0"><tr>';
1.41 ng 5245: my $ctr = 0;
1.42 ng 5246: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
1.485 albertel 5247: $radio.= '<td><label><input type="radio" name="RADVAL_'.$partid.'" '.
1.54 albertel 5248: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.288 albertel 5249: ','.$ctr.')" />'.$ctr."</label></td>\n";
1.41 ng 5250: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
5251: $ctr++;
5252: }
1.485 albertel 5253: $radio.='</tr></table>';
5254: my $line = '<input type="text" name="TEXTVAL_'.
1.589 bisitz 5255: $partid.'" size="4" '.'onchange="javascript:writePoint(\''.
1.54 albertel 5256: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.539 riegler 5257: $weight{$partid}.' '.&mt('(problem weight)').'</td>'."\n";
1.596.2.12.2. 9(raebur 5258:3): $line.= '<td><b>'.&mt('Grade Status').':</b>'.
5259:3): '<select name="SELVAL_'.$partid.'" '.
5260:3): 'onchange="javascript:writeRadText(\''.$partid.'\','.
1.59 albertel 5261: $weight{$partid}.')"> '.
1.401 albertel 5262: '<option selected="selected"> </option>'.
1.485 albertel 5263: '<option value="excused">'.&mt('excused').'</option>'.
5264: '<option value="reset status">'.&mt('reset status').'</option>'.
5265: '</select></td>'.
5266: '<td><label><input type="checkbox" name="FORCE_'.$partid.'" />'.&mt('Override "Correct"').'</label>';
5267: $line.='<input type="hidden" name="partid_'.
5268: $ctsparts.'" value="'.$partid.'" />'."\n";
5269: $line.='<input type="hidden" name="weight_'.
5270: $partid.'" value="'.$weight{$partid}.'" />'."\n";
5271:
5272: $result.=
5273: &Apache::loncommon::start_data_table_row()."\n".
1.577 bisitz 5274: '<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 5275: &Apache::loncommon::end_data_table_row()."\n";
1.42 ng 5276: $ctsparts++;
1.41 ng 5277: }
1.474 albertel 5278: $result.=&Apache::loncommon::end_data_table()."\n".
1.52 albertel 5279: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.485 albertel 5280: $result.='<input type="button" value="'.&mt('Revert to Default').'" '.
1.589 bisitz 5281: 'onclick="javascript:resetEntry('.$ctsparts.');" />';
1.41 ng 5282:
1.44 ng 5283: #table listing all the students in a section/class
5284: #header of table
1.596.2.12.2. 0.2.4(ra 5285:ul-23): if ($env{'form.submitonly'} eq 'all') {
7(raebur 5286:6): $result.= '<h3>'.$specific_header.'</h3>';
5287:6): } else {
0.2.4(ra 5288:ul-23): my $text;
5289:ul-23): if ($is_tool) {
5290:ul-23): $text = &mt('(transaction status: "[_1]")',$submission_status);
5291:ul-23): } else {
5292:ul-23): $text = &mt('(submission status: "[_1]")',$submission_status);
5293:ul-23): }
5294:ul-23): $result.= '<h3>'.$specific_header.' '.$text.'</h3>';
7(raebur 5295:6): }
5296:6): $result.= &Apache::loncommon::start_data_table().
1.560 raeburn 5297: &Apache::loncommon::start_data_table_header_row().
5298: '<th>'.&mt('No.').'</th>'.
5299: '<th>'.&nameUserString('header')."</th>\n";
1.582 raeburn 5300: my $partserror;
5301: my (@parts) = sort(&getpartlist($symb,\$partserror));
5302: if ($partserror) {
5303: return &navmap_errormsg();
5304: }
1.324 albertel 5305: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.269 raeburn 5306: my @partids = ();
1.41 ng 5307: foreach my $part (@parts) {
1.596.2.12.2. 0.2.4(ra 5308:ul-23): my $display=&Apache::lonnet::metadata($url,$part.'.display',$toolsymb);
1.539 riegler 5309: my $narrowtext = &mt('Tries');
5310: $display =~ s|^Number of Attempts|$narrowtext <br />|; # makes the column narrower
1.596.2.12.2. 0.2.4(ra 5311:ul-23): if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name',$toolsymb); }
1.207 albertel 5312: my ($partid) = &split_part_type($part);
1.524 raeburn 5313: push(@partids,$partid);
1.596.2.12.2. 1(raebur 5314:0): #
5315:0): # FIXME: Looks like $display looks at English text
5316:0): #
1.324 albertel 5317: my $display_part=&get_display_part($partid,$symb);
1.41 ng 5318: if ($display =~ /^Partial Credit Factor/) {
1.485 albertel 5319: $result.='<th>'.
1.596.2.12.2. 8(raebur 5320:3): &mt('Score Part: [_1][_2](weight = [_3])',
5321:3): $display_part,'<br />',$weight{$partid}).'</th>'."\n";
1.41 ng 5322: next;
1.485 albertel 5323:
1.207 albertel 5324: } else {
1.485 albertel 5325: if ($display =~ /Problem Status/) {
5326: my $grade_status_mt = &mt('Grade Status');
5327: $display =~ s{Problem Status}{$grade_status_mt<br />};
5328: }
5329: my $part_mt = &mt('Part:');
5330: $display =~s{\[Part: \Q$partid\E\]}{$part_mt $display_part};
1.41 ng 5331: }
1.485 albertel 5332:
1.474 albertel 5333: $result.='<th>'.$display.'</th>'."\n";
1.41 ng 5334: }
1.474 albertel 5335: $result.=&Apache::loncommon::end_data_table_header_row();
1.44 ng 5336:
1.270 albertel 5337: my %last_resets =
5338: &get_last_resets($symb,$env{'request.course.id'},\@partids);
1.269 raeburn 5339:
1.41 ng 5340: #get info for each student
1.44 ng 5341: #list all the students - with points and grade status
1.596.2.12.2. 7(raebur 5342:6): my (undef,undef,$fullname) = &getclasslist(\@sections,'1',\@groups);
1.41 ng 5343: my $ctr = 0;
1.294 albertel 5344: foreach (sort
5345: {
5346: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
5347: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
5348: }
5349: return $a cmp $b;
5350: } (keys(%$fullname))) {
1.324 albertel 5351: $result.=&viewstudentgrade($symb,$env{'request.course.id'},
1.596.2.12.2. 0.2.4(ra 5352:ul-23): $_,$$fullname{$_},\@parts,\%weight,\$ctr,\%last_resets,$is_tool);
1.41 ng 5353: }
1.474 albertel 5354: $result.=&Apache::loncommon::end_data_table();
1.41 ng 5355: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.596.2.12.2. 6(raebur 5356:1): $result.='<input type="button" value="'.&mt('Save').'"'.$disabled.' '.
1.589 bisitz 5357: 'onclick="javascript:submit();" target="_self" /></form>'."\n";
1.596.2.12.2. 7(raebur 5358:6): if ($ctr == 0) {
1.442 banghart 5359: my $stu_status = join(' or ',&Apache::loncommon::get_env_multiple('form.Status'));
1.596.2.12.2. 7(raebur 5360:6): $result='<h3><span class="LC_info">'.&mt('Manual Grading').'</span></h3>'.
5361:6): '<span class="LC_warning">';
5362:6): if ($env{'form.submitonly'} eq 'all') {
5363:6): if (grep(/^all$/,@sections)) {
5364:6): if (grep(/^all$/,@groups)) {
5365:6): $result .= &mt('There are no students with enrollment status [_1] to modify or grade.',
5366:6): $stu_status);
5367:6): } elsif (grep(/^none$/,@groups)) {
5368:6): $result .= &mt('There are no students with no group assigned and with enrollment status [_1] to modify or grade.',
5369:6): $stu_status);
5370:6): } else {
5371:6): $result .= &mt('There are no students in group(s) [_1] with enrollment status [_2] to modify or grade.',
5372:6): $group_display,$stu_status);
5373:6): }
5374:6): } elsif (grep(/^none$/,@sections)) {
5375:6): if (grep(/^all$/,@groups)) {
5376:6): $result .= &mt('There are no students in no section with enrollment status [_1] to modify or grade.',
5377:6): $stu_status);
5378:6): } elsif (grep(/^none$/,@groups)) {
5379:6): $result .= &mt('There are no students in no section and no group with enrollment status [_1] to modify or grade.',
5380:6): $stu_status);
5381:6): } else {
5382:6): $result .= &mt('There are no students in no section in group(s) [_1] with enrollment status [_2] to modify or grade.',
5383:6): $group_display,$stu_status);
5384:6): }
5385:6): } else {
5386:6): if (grep(/^all$/,@groups)) {
5387:6): $result .= &mt('There are no students in section(s) [_1] with enrollment status [_2] to modify or grade.',
5388:6): $section_display,$stu_status);
5389:6): } elsif (grep(/^none$/,@groups)) {
9(raebur 5390:7): $result .= &mt('There are no students in section(s) [_1] and no group with enrollment status [_2] to modify or grade.',
7(raebur 5391:6): $section_display,$stu_status);
5392:6): } else {
5393:6): $result .= &mt('There are no students in section(s) [_1] and group(s) [_2] with enrollment status [_3] to modify or grade.',
5394:6): $section_display,$group_display,$stu_status);
5395:6): }
5396:6): }
5397:6): } else {
5398:6): if (grep(/^all$/,@sections)) {
5399:6): if (grep(/^all$/,@groups)) {
5400:6): $result .= &mt('There are no students with enrollment status [_1] and submission status "[_2]" to modify or grade.',
5401:6): $stu_status,$submission_status);
5402:6): } elsif (grep(/^none$/,@groups)) {
5403:6): $result .= &mt('There are no students with no group assigned with enrollment status [_1] and submission status "[_2]" to modify or grade.',
5404:6): $stu_status,$submission_status);
5405:6): } else {
5406:6): $result .= &mt('There are no students in group(s) [_1] with enrollment status [_2] and submission status "[_3]" to modify or grade.',
5407:6): $group_display,$stu_status,$submission_status);
5408:6): }
5409:6): } elsif (grep(/^none$/,@sections)) {
5410:6): if (grep(/^all$/,@groups)) {
5411:6): $result .= &mt('There are no students in no section with enrollment status [_1] and submission status "[_2]" to modify or grade.',
5412:6): $stu_status,$submission_status);
5413:6): } elsif (grep(/^none$/,@groups)) {
5414: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.',
5415:6): $stu_status,$submission_status);
5416:6): } else {
5417: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.',
5418:6): $group_display,$stu_status,$submission_status);
5419:6): }
5420:6): } else {
5421:6): if (grep(/^all$/,@groups)) {
5422:6): $result .= &mt('There are no students in section(s) [_1] with enrollment status [_2] and submission status "[_3]" to modify or grade.',
5423:6): $section_display,$stu_status,$submission_status);
5424:6): } elsif (grep(/^none$/,@groups)) {
5425: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.',
5426:6): $section_display,$stu_status,$submission_status);
5427:6): } else {
5428: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.',
5429:6): $section_display,$group_display,$stu_status,$submission_status);
5430:6): }
5431:6): }
5432:6): }
5433:6): $result .= '</span><br />';
1.96 albertel 5434: }
1.41 ng 5435: return $result;
5436: }
5437:
1.596.2.12.2. 7(raebur 5438:6): #--- call by previous routine to display each student who satisfies submission filter.
1.41 ng 5439: sub viewstudentgrade {
1.596.2.12.2. 0.2.4(ra 5440:ul-23): my ($symb,$courseid,$student,$fullname,$parts,$weight,$ctr,$last_resets,$is_tool) = @_;
1.44 ng 5441: my ($uname,$udom) = split(/:/,$student);
5442: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.596.2.12.2. 7(raebur 5443:6): my $submitonly = $env{'form.submitonly'};
5444:6): unless (($submitonly eq 'all') || ($submitonly eq 'queued')) {
5445:6): my %partstatus = ();
5446:6): if (ref($parts) eq 'ARRAY') {
5447:6): foreach my $apart (@{$parts}) {
5448:6): my ($part,$type) = &split_part_type($apart);
5449:6): my ($status,undef) = split(/_/,$record{"resource.$part.solved"},2);
5450:6): $status = 'nothing' if ($status eq '');
5451:6): $partstatus{$part} = $status;
5452:6): my $subkey = "resource.$part.submitted_by";
5453:6): $partstatus{$subkey} = $record{$subkey} if ($record{$subkey} ne '');
5454:6): }
5455:6): my $submitted = 0;
5456:6): my $graded = 0;
5457:6): my $incorrect = 0;
5458:6): foreach my $key (keys(%partstatus)) {
5459:6): $submitted = 1 if ($partstatus{$key} ne 'nothing');
5460:6): $graded = 1 if ($partstatus{$key} =~ /^ungraded/);
5461:6): $incorrect = 1 if ($partstatus{$key} =~ /^incorrect/);
5462:6):
5463:6): my $partid = (split(/\./,$key))[1];
5464:6): if ($partstatus{'resource.'.$partid.'.'.$key.'.submitted_by'} ne '') {
5465:6): $submitted = 0;
5466:6): }
5467:6): }
5468:6): return if (!$submitted && ($submitonly eq 'yes' ||
5469:6): $submitonly eq 'incorrect' ||
5470:6): $submitonly eq 'graded'));
5471:6): return if (!$graded && ($submitonly eq 'graded'));
5472:6): return if (!$incorrect && $submitonly eq 'incorrect');
5473:6): }
5474:6): }
5475:6): if ($submitonly eq 'queued') {
5476:6): my ($cdom,$cnum) = split(/_/,$courseid);
5477:6): my %queue_status =
5478:6): &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
5479:6): $udom,$uname);
5480:6): return if (!defined($queue_status{'gradingqueue'}));
5481:6): }
5482:6): $$ctr++;
5483:6): my %aggregates = ();
1.474 albertel 5484: my $result=&Apache::loncommon::start_data_table_row().'<td align="right">'.
1.596.2.12.2. 7(raebur 5485:6): '<input type="hidden" name="ctr'.($$ctr-1).'" value="'.$student.'" />'.
5486:6): "\n".$$ctr.' </td><td> '.
1.44 ng 5487: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 5488: '\');" target="_self">'.$fullname.'</a> '.
1.398 albertel 5489: '<span class="LC_internal_info">('.$uname.($env{'user.domain'} eq $udom ? '' : ':'.$udom).')</span></td>'."\n";
1.281 albertel 5490: $student=~s/:/_/; # colon doen't work in javascript for names
1.63 albertel 5491: foreach my $apart (@$parts) {
5492: my ($part,$type) = &split_part_type($apart);
1.41 ng 5493: my $score=$record{"resource.$part.$type"};
1.276 albertel 5494: $result.='<td align="center">';
1.269 raeburn 5495: my ($aggtries,$totaltries);
5496: unless (exists($aggregates{$part})) {
1.270 albertel 5497: $totaltries = $record{'resource.'.$part.'.tries'};
5498: $aggtries = $totaltries;
1.269 raeburn 5499: if ($$last_resets{$part}) {
1.270 albertel 5500: $aggtries = &get_num_tries(\%record,$$last_resets{$part},
5501: $part);
5502: }
1.269 raeburn 5503: $result.='<input type="hidden" name="'.
5504: 'GD_'.$student.'_'.$part.'_aggtries" value="'.$aggtries.'" />'."\n";
5505: $result.='<input type="hidden" name="'.
5506: 'GD_'.$student.'_'.$part.'_totaltries" value="'.$totaltries.'" />'."\n";
5507: $aggregates{$part} = 1;
5508: }
1.41 ng 5509: if ($type eq 'awarded') {
1.320 albertel 5510: my $pts = $score eq '' ? '' : &compute_points($score,$$weight{$part});
1.42 ng 5511: $result.='<input type="hidden" name="'.
1.89 albertel 5512: 'GD_'.$student.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.233 albertel 5513: $result.='<input type="text" name="'.
1.89 albertel 5514: 'GD_'.$student.'_'.$part.'_awarded" '.
1.589 bisitz 5515: 'onchange="javascript:changeSelect(\''.$part.'\',\''.$student.
1.44 ng 5516: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41 ng 5517: } elsif ($type eq 'solved') {
5518: my ($status,$foo)=split(/_/,$score,2);
5519: $status = 'nothing' if ($status eq '');
1.89 albertel 5520: $result.='<input type="hidden" name="'.'GD_'.$student.'_'.
1.54 albertel 5521: $part.'_solved_s" value="'.$status.'" />'."\n";
1.233 albertel 5522: $result.=' <select name="'.
1.89 albertel 5523: 'GD_'.$student.'_'.$part.'_solved" '.
1.589 bisitz 5524: 'onchange="javascript:changeOneScore(\''.$part.'\',\''.$student.'\')" >'."\n";
1.485 albertel 5525: $result.= (($status eq 'excused') ? '<option> </option><option selected="selected" value="excused">'.&mt('excused').'</option>'
5526: : '<option selected="selected"> </option><option value="excused">'.&mt('excused').'</option>')."\n";
5527: $result.='<option value="reset status">'.&mt('reset status').'</option>';
1.126 ng 5528: $result.="</select> </td>\n";
1.122 ng 5529: } else {
5530: $result.='<input type="hidden" name="'.
5531: 'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
5532: "\n";
1.233 albertel 5533: $result.='<input type="text" name="'.
1.122 ng 5534: 'GD_'.$student.'_'.$part.'_'.$type.'" '.
5535: 'value="'.$score.'" size="4" /></td>'."\n";
1.41 ng 5536: }
5537: }
1.474 albertel 5538: $result.=&Apache::loncommon::end_data_table_row();
1.41 ng 5539: return $result;
1.38 ng 5540: }
5541:
1.44 ng 5542: #--- change scores for all the students in a section/class
5543: # record does not get update if unchanged
1.38 ng 5544: sub editgrades {
1.596.2.12.2. 1(raebur 5545:0): my ($request,$symb) = @_;
0.2.4(ra 5546:ul-23): my $toolsymb;
5547:ul-23): if ($symb =~ /ext\.tool$/) {
5548:ul-23): $toolsymb = $symb;
5549:ul-23): }
1.41 ng 5550:
1.433 banghart 5551: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.477 albertel 5552: my $title='<h2>'.&mt('Current Grade Status').'</h2>';
1.596.2.12.2. 9(raebur 5553:3): $title.='<h4><b>'.&mt('Section:').'</b> '.$section_display.'</h4>'."\n";
1.126 ng 5554:
1.477 albertel 5555: my $result= &Apache::loncommon::start_data_table().
5556: &Apache::loncommon::start_data_table_header_row().
5557: '<th rowspan="2" valign="middle">'.&mt('No.').'</th>'.
5558: '<th rowspan="2" valign="middle">'.&nameUserString('header')."</th>\n";
1.43 ng 5559: my %scoreptr = (
5560: 'correct' =>'correct_by_override',
5561: 'incorrect'=>'incorrect_by_override',
5562: 'excused' =>'excused',
5563: 'ungraded' =>'ungraded_attempted',
1.596 raeburn 5564: 'credited' =>'credit_attempted',
1.43 ng 5565: 'nothing' => '',
5566: );
1.257 albertel 5567: my ($classlist,undef,$fullname) = &getclasslist($env{'form.section'},'0');
1.34 ng 5568:
1.596.2.12.2. 0.2.7(ra 5569:an-25): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
5570:an-25): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
5571:an-25): my %needpb = &passbacks_for_symb($cdom,$cnum,$symb);
5572:an-25):
1.44 ng 5573: my (@partid);
5574: my %weight = ();
1.54 albertel 5575: my %columns = ();
1.44 ng 5576: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54 albertel 5577:
1.582 raeburn 5578: my $partserror;
5579: my (@parts) = sort(&getpartlist($symb,\$partserror));
5580: if ($partserror) {
5581: return &navmap_errormsg();
5582: }
1.54 albertel 5583: my $header;
1.257 albertel 5584: while ($ctr < $env{'form.totalparts'}) {
5585: my $partid = $env{'form.partid_'.$ctr};
1.524 raeburn 5586: push(@partid,$partid);
1.257 albertel 5587: $weight{$partid} = $env{'form.weight_'.$partid};
1.44 ng 5588: $ctr++;
1.54 albertel 5589: }
1.324 albertel 5590: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.596.2.12.2. 2(raebur 5591:8): my $totcolspan = 0;
1.54 albertel 5592: foreach my $partid (@partid) {
1.478 albertel 5593: $header .= '<th align="center">'.&mt('Old Score').'</th>'.
5594: '<th align="center">'.&mt('New Score').'</th>';
1.54 albertel 5595: $columns{$partid}=2;
5596: foreach my $stores (@parts) {
5597: my ($part,$type) = &split_part_type($stores);
5598: if ($part !~ m/^\Q$partid\E/) { next;}
5599: if ($type eq 'awarded' || $type eq 'solved') { next; }
1.596.2.12.2. 0.2.4(ra 5600:ul-23): my $display=&Apache::lonnet::metadata($url,$stores.'.display',$toolsymb);
1.551 raeburn 5601: $display =~ s/\[Part: \Q$part\E\]//;
1.539 riegler 5602: my $narrowtext = &mt('Tries');
5603: $display =~ s/Number of Attempts/$narrowtext/;
5604: $header .= '<th align="center">'.&mt('Old').' '.$display.'</th>'.
5605: '<th align="center">'.&mt('New').' '.$display.'</th>';
1.54 albertel 5606: $columns{$partid}+=2;
5607: }
1.596.2.12.2. 2(raebur 5608:8): $totcolspan += $columns{$partid};
1.54 albertel 5609: }
5610: foreach my $partid (@partid) {
1.324 albertel 5611: my $display_part=&get_display_part($partid,$symb);
1.478 albertel 5612: $result .= '<th colspan="'.$columns{$partid}.'" align="center">'.
5613: &mt('Part: [_1] (Weight = [_2])',$display_part,$weight{$partid}).
5614: '</th>';
1.54 albertel 5615:
1.44 ng 5616: }
1.477 albertel 5617: $result .= &Apache::loncommon::end_data_table_header_row().
5618: &Apache::loncommon::start_data_table_header_row().
5619: $header.
5620: &Apache::loncommon::end_data_table_header_row();
5621: my @noupdate;
1.126 ng 5622: my ($updateCtr,$noupdateCtr) = (1,1);
1.596.2.12.2. 0.2.7(ra 5623:an-25): my ($got_types,%queueable,%pbsave,%skip_passback);
1.257 albertel 5624: for ($i=0; $i<$env{'form.total'}; $i++) {
5625: my $user = $env{'form.ctr'.$i};
1.281 albertel 5626: my ($uname,$udom)=split(/:/,$user);
1.44 ng 5627: my %newrecord;
5628: my $updateflag = 0;
1.596.2.12.2. 2(raebur 5629:8): my $usec=$classlist->{"$uname:$udom"}[5];
5630:8): my $canmodify = &canmodify($usec);
5631:8): my $line = '<td'.($canmodify?'':' colspan="2"').'>'.
5632:8): &nameUserString(undef,$$fullname{$user},$uname,$udom).'</td>';
5633:8): if (!$canmodify) {
5634:8): push(@noupdate,
5635:8): $line."<td colspan=\"$totcolspan\"><span class=\"LC_warning\">".
5636:8): &mt('Not allowed to modify student')."</span></td>");
5637:8): next;
5638:8): }
1.269 raeburn 5639: my %aggregate = ();
5640: my $aggregateflag = 0;
1.281 albertel 5641: $user=~s/:/_/; # colon doen't work in javascript for names
1.596.2.12.2. 0.2.7(ra 5642:an-25): my (%weights,%awardeds,%excuseds);
1.44 ng 5643: foreach (@partid) {
1.257 albertel 5644: my $old_aw = $env{'form.GD_'.$user.'_'.$_.'_awarded_s'};
1.54 albertel 5645: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
5646: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
1.257 albertel 5647: my $old_score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
5648: my $awarded = $env{'form.GD_'.$user.'_'.$_.'_awarded'};
1.54 albertel 5649: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
5650: my $partial = $awarded eq '' ? '' : $pcr;
1.596.2.12.2. 0.2.7(ra 5651:an-25): $awardeds{$symb}{$_} = $partial;
1.44 ng 5652: my $score;
5653: if ($partial eq '') {
1.257 albertel 5654: $score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 5655: } elsif ($partial > 0) {
5656: $score = 'correct_by_override';
5657: } elsif ($partial == 0) {
5658: $score = 'incorrect_by_override';
5659: }
1.257 albertel 5660: my $dropMenu = $env{'form.GD_'.$user.'_'.$_.'_solved'};
1.125 ng 5661: $score = 'excused' if (($dropMenu eq 'excused') && ($score ne 'excused'));
5662:
1.292 albertel 5663: $newrecord{'resource.'.$_.'.regrader'}=
5664: "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 5665: if ($dropMenu eq 'reset status' &&
5666: $old_score ne '') { # ignore if no previous attempts => nothing to reset
1.299 albertel 5667: $newrecord{'resource.'.$_.'.tries'} = '';
1.125 ng 5668: $newrecord{'resource.'.$_.'.solved'} = '';
5669: $newrecord{'resource.'.$_.'.award'} = '';
1.299 albertel 5670: $newrecord{'resource.'.$_.'.awarded'} = '';
1.125 ng 5671: $updateflag = 1;
1.269 raeburn 5672: if ($env{'form.GD_'.$user.'_'.$_.'_aggtries'} > 0) {
5673: my $aggtries = $env{'form.GD_'.$user.'_'.$_.'_aggtries'};
5674: my $totaltries = $env{'form.GD_'.$user.'_'.$_.'_totaltries'};
5675: my $solvedstatus = $env{'form.GD_'.$user.'_'.$_.'_solved_s'};
5676: &decrement_aggs($symb,$_,\%aggregate,$aggtries,$totaltries,$solvedstatus);
5677: $aggregateflag = 1;
5678: }
1.139 albertel 5679: } elsif (!($old_part eq $partial && $old_score eq $score)) {
5680: $updateflag = 1;
5681: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
5682: $newrecord{'resource.'.$_.'.solved'} = $score;
5683: $rec_update++;
1.125 ng 5684: }
5685:
1.93 albertel 5686: $line .= '<td align="center">'.$old_aw.' </td>'.
1.44 ng 5687: '<td align="center">'.$awarded.
5688: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 5689:
1.54 albertel 5690:
5691: my $partid=$_;
1.596.2.12.2. 0.2.7(ra 5692:an-25): if ($score eq 'excused') {
5693:an-25): $excuseds{$symb}{$partid} = 1;
5694:an-25): } else {
5695:an-25): $excuseds{$symb}{$partid} = '';
5696:an-25): }
1.54 albertel 5697: foreach my $stores (@parts) {
5698: my ($part,$type) = &split_part_type($stores);
5699: if ($part !~ m/^\Q$partid\E/) { next;}
5700: if ($type eq 'awarded' || $type eq 'solved') { next; }
1.257 albertel 5701: my $old_aw = $env{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
5702: my $awarded = $env{'form.GD_'.$user.'_'.$part.'_'.$type};
1.54 albertel 5703: if ($awarded ne '' && $awarded ne $old_aw) {
5704: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.257 albertel 5705: $newrecord{'resource.'.$part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.54 albertel 5706: $updateflag=1;
5707: }
1.93 albertel 5708: $line .= '<td align="center">'.$old_aw.' </td>'.
1.54 albertel 5709: '<td align="center">'.$awarded.' </td>';
5710: }
1.44 ng 5711: }
1.477 albertel 5712: $line.="\n";
1.301 albertel 5713:
1.44 ng 5714: if ($updateflag) {
5715: $count++;
1.257 albertel 5716: &Apache::lonnet::cstore(\%newrecord,$symb,$env{'request.course.id'},
1.89 albertel 5717: $udom,$uname);
1.301 albertel 5718:
5719: if (&Apache::bridgetask::in_queue('gradingqueue',$symb,$cdom,
5720: $cnum,$udom,$uname)) {
5721: # need to figure out if should be in queue.
5722: my %record =
5723: &Apache::lonnet::restore($symb,$env{'request.course.id'},
5724: $udom,$uname);
5725: my $all_graded = 1;
5726: my $none_graded = 1;
1.596.2.12.2. 8(raebur 5727:1): unless ($got_types) {
5728:1): my $error;
5729:1): my ($plist,$handgrd,$resptype) = &response_type($symb,\$error);
5730:1): unless ($error) {
5731:1): foreach my $part (@parts) {
5732:1): if (ref($resptype->{$part}) eq 'HASH') {
5733:1): foreach my $id (keys(%{$resptype->{$part}})) {
5734:1): if (($resptype->{$part}->{$id} eq 'essay') ||
5735:1): (lc($handgrd->{$part.'_'.$id}) eq 'yes')) {
5736:1): $queueable{$part} = 1;
5737:1): last;
5738:1): }
5739:1): }
5740:1): }
5741:1): }
5742:1): }
5743:1): $got_types = 1;
5744:1): }
1.301 albertel 5745: foreach my $part (@parts) {
1.596.2.12.2. 8(raebur 5746:1): if ($queueable{$part}) {
5747:1): if ( $record{'resource.'.$part.'.awarded'} eq '' ) {
5748:1): $all_graded = 0;
5749:1): } else {
5750:1): $none_graded = 0;
5751:1): }
5752:1): }
1.301 albertel 5753: }
5754:
5755: if ($all_graded || $none_graded) {
5756: &Apache::bridgetask::remove_from_queue('gradingqueue',
5757: $symb,$cdom,$cnum,
5758: $udom,$uname);
5759: }
5760: }
5761:
1.477 albertel 5762: $result.=&Apache::loncommon::start_data_table_row().
5763: '<td align="right"> '.$updateCtr.' </td>'.$line.
5764: &Apache::loncommon::end_data_table_row();
1.126 ng 5765: $updateCtr++;
1.596.2.12.2. 0.2.7(ra 5766:an-25): if (keys(%needpb)) {
5767:an-25): $weights{$symb} = \%weight;
5768:an-25): &process_passbacks('editgrades',[$symb],$cdom,$cnum,$udom,$uname,$usec,\%weights,
5769:an-25): \%awardeds,\%excuseds,\%needpb,\%skip_passback,\%pbsave);
5770:an-25): }
1.93 albertel 5771: } else {
1.477 albertel 5772: push(@noupdate,
5773: '<td align="right"> '.$noupdateCtr.' </td>'.$line);
1.126 ng 5774: $noupdateCtr++;
1.44 ng 5775: }
1.269 raeburn 5776: if ($aggregateflag) {
5777: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 5778: $cdom,$cnum);
1.269 raeburn 5779: }
1.93 albertel 5780: }
1.477 albertel 5781: if (@noupdate) {
1.596.2.12.2. 2(raebur 5782:8): my $numcols=$totcolspan+2;
1.477 albertel 5783: $result .= &Apache::loncommon::start_data_table_row('LC_empty_row').
1.478 albertel 5784: '<td align="center" colspan="'.$numcols.'">'.
5785: &mt('No Changes Occurred For the Students Below').
5786: '</td>'.
1.477 albertel 5787: &Apache::loncommon::end_data_table_row();
5788: foreach my $line (@noupdate) {
5789: $result.=
5790: &Apache::loncommon::start_data_table_row().
5791: $line.
5792: &Apache::loncommon::end_data_table_row();
5793: }
1.44 ng 5794: }
1.596.2.12.2. 1(raebur 5795:0): $result .= &Apache::loncommon::end_data_table();
1.478 albertel 5796: my $msg = '<p><b>'.
5797: &mt('Number of records updated = [_1] for [quant,_2,student].',
5798: $rec_update,$count).'</b><br />'.
5799: '<b>'.&mt('Total number of students = [_1]',$env{'form.total'}).
5800: '</b></p>';
1.44 ng 5801: return $title.$msg.$result;
1.5 albertel 5802: }
1.54 albertel 5803:
5804: sub split_part_type {
5805: my ($partstr) = @_;
5806: my ($temp,@allparts)=split(/_/,$partstr);
5807: my $type=pop(@allparts);
1.439 albertel 5808: my $part=join('_',@allparts);
1.54 albertel 5809: return ($part,$type);
5810: }
5811:
1.44 ng 5812: #------------- end of section for handling grading by section/class ---------
5813: #
5814: #----------------------------------------------------------------------------
5815:
1.5 albertel 5816:
1.44 ng 5817: #----------------------------------------------------------------------------
5818: #
5819: #-------------------------- Next few routines handles grading by csv upload
5820: #
5821: #--- Javascript to handle csv upload
1.27 albertel 5822: sub csvupload_javascript_reverse_associate {
1.573 bisitz 5823: my $error1=&mt('You need to specify the username or the student/employee ID');
1.246 albertel 5824: my $error2=&mt('You need to specify at least one grading field');
1.596.2.12.2. 6(raebur 5825:6): &js_escape(\$error1);
5826:6): &js_escape(\$error2);
1.27 albertel 5827: return(<<ENDPICK);
5828: function verify(vf) {
5829: var foundsomething=0;
5830: var founduname=0;
1.243 albertel 5831: var foundID=0;
1.27 albertel 5832: for (i=0;i<=vf.nfields.value;i++) {
5833: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 5834: if (i==0 && tw!=0) { foundID=1; }
5835: if (i==1 && tw!=0) { founduname=1; }
5836: if (i!=0 && i!=1 && i!=2 && tw!=0) { foundsomething=1; }
1.27 albertel 5837: }
1.246 albertel 5838: if (founduname==0 && foundID==0) {
5839: alert('$error1');
5840: return;
1.27 albertel 5841: }
5842: if (foundsomething==0) {
1.246 albertel 5843: alert('$error2');
5844: return;
1.27 albertel 5845: }
5846: vf.submit();
5847: }
5848: function flip(vf,tf) {
5849: var nw=eval('vf.f'+tf+'.selectedIndex');
5850: var i;
5851: for (i=0;i<=vf.nfields.value;i++) {
5852: //can not pick the same destination field for both name and domain
5853: if (((i ==0)||(i ==1)) &&
5854: ((tf==0)||(tf==1)) &&
5855: (i!=tf) &&
5856: (eval('vf.f'+i+'.selectedIndex')==nw)) {
5857: eval('vf.f'+i+'.selectedIndex=0;')
5858: }
5859: }
5860: }
5861: ENDPICK
5862: }
5863:
5864: sub csvupload_javascript_forward_associate {
1.573 bisitz 5865: my $error1=&mt('You need to specify the username or the student/employee ID');
1.246 albertel 5866: my $error2=&mt('You need to specify at least one grading field');
1.596.2.12.2. 6(raebur 5867:6): &js_escape(\$error1);
5868:6): &js_escape(\$error2);
1.27 albertel 5869: return(<<ENDPICK);
5870: function verify(vf) {
5871: var foundsomething=0;
5872: var founduname=0;
1.243 albertel 5873: var foundID=0;
1.27 albertel 5874: for (i=0;i<=vf.nfields.value;i++) {
5875: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 5876: if (tw==1) { foundID=1; }
5877: if (tw==2) { founduname=1; }
5878: if (tw>3) { foundsomething=1; }
1.27 albertel 5879: }
1.246 albertel 5880: if (founduname==0 && foundID==0) {
5881: alert('$error1');
5882: return;
1.27 albertel 5883: }
5884: if (foundsomething==0) {
1.246 albertel 5885: alert('$error2');
5886: return;
1.27 albertel 5887: }
5888: vf.submit();
5889: }
5890: function flip(vf,tf) {
5891: var nw=eval('vf.f'+tf+'.selectedIndex');
5892: var i;
5893: //can not pick the same destination field twice
5894: for (i=0;i<=vf.nfields.value;i++) {
5895: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
5896: eval('vf.f'+i+'.selectedIndex=0;')
5897: }
5898: }
5899: }
5900: ENDPICK
5901: }
5902:
1.26 albertel 5903: sub csvuploadmap_header {
1.324 albertel 5904: my ($request,$symb,$datatoken,$distotal)= @_;
1.41 ng 5905: my $javascript;
1.257 albertel 5906: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 5907: $javascript=&csvupload_javascript_reverse_associate();
5908: } else {
5909: $javascript=&csvupload_javascript_forward_associate();
5910: }
1.45 ng 5911:
1.257 albertel 5912: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1.245 albertel 5913: my $ignore=&mt('Ignore First Line');
1.418 albertel 5914: $symb = &Apache::lonenc::check_encrypt($symb);
1.596.2.12.2. 1(raebur 5915:0): $request->print('<form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">'.
5916:0): &mt('Total number of records found in file: [_1]',$distotal).'<hr />'.
5917:0): &mt('Associate entries from the uploaded file with as many fields as you can.'));
5918:0): my $reverse=&mt("Reverse Association");
1.41 ng 5919: $request->print(<<ENDPICK);
1.596.2.12.2. 1(raebur 5920:0): <br />
5921:0): <input type="button" value="$reverse" onclick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1.245 albertel 5922: <label><input type="checkbox" name="noFirstLine" $checked />$ignore</label>
1.26 albertel 5923: <input type="hidden" name="associate" value="" />
5924: <input type="hidden" name="phase" value="three" />
5925: <input type="hidden" name="datatoken" value="$datatoken" />
1.257 albertel 5926: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
5927: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
1.26 albertel 5928: <input type="hidden" name="upfile_associate"
1.257 albertel 5929: value="$env{'form.upfile_associate'}" />
1.26 albertel 5930: <input type="hidden" name="symb" value="$symb" />
1.246 albertel 5931: <input type="hidden" name="command" value="csvuploadoptions" />
1.26 albertel 5932: <hr />
5933: ENDPICK
1.596.2.12.2. 1(raebur 5934:0): $request->print(&Apache::lonhtmlcommon::scripttag($javascript));
1.118 ng 5935: return '';
1.26 albertel 5936:
5937: }
5938:
5939: sub csvupload_fields {
1.582 raeburn 5940: my ($symb,$errorref) = @_;
1.596.2.12.2. 0.2.4(ra 5941:ul-23): my $toolsymb;
5942:ul-23): if ($symb =~ /ext\.tool$/) {
5943:ul-23): $toolsymb = $symb;
5944:ul-23): }
1.582 raeburn 5945: my (@parts) = &getpartlist($symb,$errorref);
5946: if (ref($errorref)) {
5947: if ($$errorref) {
5948: return;
5949: }
5950: }
5951:
1.556 weissno 5952: my @fields=(['ID','Student/Employee ID'],
1.243 albertel 5953: ['username','Student Username'],
5954: ['domain','Student Domain']);
1.324 albertel 5955: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.41 ng 5956: foreach my $part (sort(@parts)) {
5957: my @datum;
1.596.2.12.2. 0.2.4(ra 5958:ul-23): my $display=&Apache::lonnet::metadata($url,$part.'.display',$toolsymb);
1.41 ng 5959: my $name=$part;
5960: if (!$display) { $display = $name; }
5961: @datum=($name,$display);
1.244 albertel 5962: if ($name=~/^stores_(.*)_awarded/) {
5963: push(@fields,['stores_'.$1.'_points',"Points [Part: $1]"]);
5964: }
1.41 ng 5965: push(@fields,\@datum);
5966: }
5967: return (@fields);
1.26 albertel 5968: }
5969:
5970: sub csvuploadmap_footer {
1.41 ng 5971: my ($request,$i,$keyfields) =@_;
1.596.2.12.2. 0(raebur 5972:3): my $buttontext = &mt('Assign Grades');
1.41 ng 5973: $request->print(<<ENDPICK);
1.26 albertel 5974: </table>
5975: <input type="hidden" name="nfields" value="$i" />
5976: <input type="hidden" name="keyfields" value="$keyfields" />
1.596.2.12.2. 0(raebur 5977:3): <input type="button" onclick="javascript:verify(this.form)" value="$buttontext" /><br />
1.26 albertel 5978: </form>
5979: ENDPICK
5980: }
5981:
1.283 albertel 5982: sub checkforfile_js {
1.539 riegler 5983: my $alertmsg = &mt('Please use the browse button to select a file from your local directory.');
1.596.2.12.2. 6(raebur 5984:6): &js_escape(\$alertmsg);
1(raebur 5985:0): my $result = &Apache::lonhtmlcommon::scripttag(<<CSVFORMJS);
1.86 ng 5986: function checkUpload(formname) {
5987: if (formname.upfile.value == "") {
1.539 riegler 5988: alert("$alertmsg");
1.86 ng 5989: return false;
5990: }
5991: formname.submit();
5992: }
5993: CSVFORMJS
1.283 albertel 5994: return $result;
5995: }
5996:
5997: sub upcsvScores_form {
1.596.2.12.2. 1(raebur 5998:0): my ($request,$symb) = @_;
1.283 albertel 5999: if (!$symb) {return '';}
6000: my $result=&checkforfile_js();
1.596.2.12.2. 1(raebur 6001:0): $result.=&Apache::loncommon::start_data_table().
6002:0): &Apache::loncommon::start_data_table_header_row().
6003:0): '<th>'.&mt('Specify a file containing the class scores for current resource.').'</th>'.
6004:0): &Apache::loncommon::end_data_table_header_row().
6005:0): &Apache::loncommon::start_data_table_row().'<td>';
1.370 www 6006: my $upload=&mt("Upload Scores");
1.86 ng 6007: my $upfile_select=&Apache::loncommon::upfile_select_html();
1.245 albertel 6008: my $ignore=&mt('Ignore First Line');
1.418 albertel 6009: $symb = &Apache::lonenc::check_encrypt($symb);
1.86 ng 6010: $result.=<<ENDUPFORM;
1.106 albertel 6011: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.86 ng 6012: <input type="hidden" name="symb" value="$symb" />
6013: <input type="hidden" name="command" value="csvuploadmap" />
6014: $upfile_select
1.589 bisitz 6015: <br /><input type="button" onclick="javascript:checkUpload(this.form);" value="$upload" />
1.283 albertel 6016: <label><input type="checkbox" name="noFirstLine" />$ignore</label>
1.86 ng 6017: </form>
6018: ENDUPFORM
1.370 www 6019: $result.=&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
1.596.2.12.2. 1(raebur 6020:0): &mt("How do I create a CSV file from a spreadsheet")).
6021:0): '</td>'.
6022:0): &Apache::loncommon::end_data_table_row().
6023:0): &Apache::loncommon::end_data_table();
1.86 ng 6024: return $result;
6025: }
6026:
6027:
1.26 albertel 6028: sub csvuploadmap {
1.596.2.12.2. 1(raebur 6029:0): my ($request,$symb) = @_;
1.41 ng 6030: if (!$symb) {return '';}
1.72 ng 6031:
1.41 ng 6032: my $datatoken;
1.257 albertel 6033: if (!$env{'form.datatoken'}) {
1.41 ng 6034: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 6035: } else {
1.596.2.12.2. 3(raebur 6036:8): $datatoken=&Apache::loncommon::valid_datatoken($env{'form.datatoken'});
6037:8): if ($datatoken ne '') {
6038:8): &Apache::loncommon::load_tmp_file($request,$datatoken);
6039:8): }
1.26 albertel 6040: }
1.41 ng 6041: my @records=&Apache::loncommon::upfile_record_sep();
1.257 albertel 6042: if ($env{'form.noFirstLine'}) { shift(@records); }
1.324 albertel 6043: &csvuploadmap_header($request,$symb,$datatoken,$#records+1);
1.41 ng 6044: my ($i,$keyfields);
6045: if (@records) {
1.582 raeburn 6046: my $fieldserror;
6047: my @fields=&csvupload_fields($symb,\$fieldserror);
6048: if ($fieldserror) {
6049: $request->print(&navmap_errormsg());
6050: return;
6051: }
1.257 albertel 6052: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 6053: &Apache::loncommon::csv_print_samples($request,\@records);
6054: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
6055: \@fields);
6056: foreach (@fields) { $keyfields.=$_->[0].','; }
6057: chop($keyfields);
6058: } else {
6059: unshift(@fields,['none','']);
6060: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
6061: \@fields);
1.311 banghart 6062: foreach my $rec (@records) {
6063: my %temp = &Apache::loncommon::record_sep($rec);
6064: if (%temp) {
6065: $keyfields=join(',',sort(keys(%temp)));
6066: last;
6067: }
6068: }
1.41 ng 6069: }
6070: }
6071: &csvuploadmap_footer($request,$i,$keyfields);
1.72 ng 6072:
1.41 ng 6073: return '';
1.27 albertel 6074: }
6075:
1.246 albertel 6076: sub csvuploadoptions {
1.596.2.12.2. 1(raebur 6077:0): my ($request,$symb)= @_;
6078:0): my $overwrite=&mt('Overwrite any existing score');
1.257 albertel 6079: my $checked=(($env{'form.noFirstLine'})?'1':'0');
1.246 albertel 6080: my $ignore=&mt('Ignore First Line');
6081: $request->print(<<ENDPICK);
6082: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
6083: <input type="hidden" name="command" value="csvuploadassign" />
6084: <p>
6085: <label>
6086: <input type="checkbox" name="overwite_scores" checked="checked" />
1.596.2.12.2. 1(raebur 6087:0): $overwrite
1.246 albertel 6088: </label>
6089: </p>
6090: ENDPICK
6091: my %fields=&get_fields();
6092: if (!defined($fields{'domain'})) {
1.257 albertel 6093: my $domform = &Apache::loncommon::select_dom_form($env{'request.role.domain'},'default_domain');
1.596.2.12.2. 1(raebur 6094:0): $request->print("\n<p>".&mt('Users are in domain: [_1]',$domform)."</p>\n");
1.246 albertel 6095: }
1.257 albertel 6096: foreach my $key (sort(keys(%env))) {
1.246 albertel 6097: if ($key !~ /^form\.(.*)$/) { next; }
6098: my $cleankey=$1;
6099: if ($cleankey eq 'command') { next; }
6100: $request->print('<input type="hidden" name="'.$cleankey.
1.257 albertel 6101: '" value="'.$env{$key}.'" />'."\n");
1.246 albertel 6102: }
6103: # FIXME do a check for any duplicated user ids...
6104: # FIXME do a check for any invalid user ids?...
1.596.2.12.2. 0(raebur 6105:3): $request->print('<input type="submit" value="'.&mt('Assign Grades').'" /><br />
1.290 albertel 6106: <hr /></form>'."\n");
1.246 albertel 6107: return '';
6108: }
6109:
6110: sub get_fields {
6111: my %fields;
1.257 albertel 6112: my @keyfields = split(/\,/,$env{'form.keyfields'});
6113: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
6114: if ($env{'form.upfile_associate'} eq 'reverse') {
6115: if ($env{'form.f'.$i} ne 'none') {
6116: $fields{$keyfields[$i]}=$env{'form.f'.$i};
1.41 ng 6117: }
6118: } else {
1.257 albertel 6119: if ($env{'form.f'.$i} ne 'none') {
6120: $fields{$env{'form.f'.$i}}=$keyfields[$i];
1.41 ng 6121: }
6122: }
1.27 albertel 6123: }
1.246 albertel 6124: return %fields;
6125: }
6126:
6127: sub csvuploadassign {
1.596.2.12.2. 1(raebur 6128:0): my ($request,$symb) = @_;
1.246 albertel 6129: if (!$symb) {return '';}
1.345 bowersj2 6130: my $error_msg = '';
1.596.2.12.2. 3(raebur 6131:8): my $datatoken = &Apache::loncommon::valid_datatoken($env{'form.datatoken'});
6132:8): if ($datatoken ne '') {
6133:8): &Apache::loncommon::load_tmp_file($request,$datatoken);
6134:8): }
1.246 albertel 6135: my @gradedata = &Apache::loncommon::upfile_record_sep();
1.257 albertel 6136: if ($env{'form.noFirstLine'}) { shift(@gradedata); }
1.246 albertel 6137: my %fields=&get_fields();
1.257 albertel 6138: my $courseid=$env{'request.course.id'};
1.596.2.12.2. 0.2.7(ra 6139:an-25): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
6140:an-25): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.97 albertel 6141: my ($classlist) = &getclasslist('all',0);
1.106 albertel 6142: my @notallowed;
1.41 ng 6143: my @skipped;
1.596.2.4 raeburn 6144: my @warnings;
1.41 ng 6145: my $countdone=0;
1.596.2.12.2. 0.2.7(ra 6146:an-25): my @parts;
6147:an-25): my %needpb = &passbacks_for_symb($cdom,$cnum,$symb);
6148:an-25): my $passback;
6149:an-25): if (keys(%needpb)) {
6150:an-25): $passback = 1;
6151:an-25): my $navmap = Apache::lonnavmaps::navmap->new();
6152:an-25): if (ref($navmap)) {
6153:an-25): my $res = $navmap->getBySymb($symb);
6154:an-25): if (ref($res)) {
6155:an-25): my $partlist = $res->parts();
6156:an-25): if (ref($partlist) eq 'ARRAY') {
6157:an-25): @parts = sort(@{$partlist});
6158:an-25): }
6159:an-25): }
6160:an-25): } else {
6161:an-25): return &navmap_errormsg();
6162:an-25): }
6163:an-25): }
6164:an-25): my (%skip_passback,%pbsave,%weights,%awardeds,%excuseds);
6165:an-25):
1.41 ng 6166: foreach my $grade (@gradedata) {
6167: my %entries=&Apache::loncommon::record_sep($grade);
1.246 albertel 6168: my $domain;
6169: if ($entries{$fields{'domain'}}) {
6170: $domain=$entries{$fields{'domain'}};
6171: } else {
1.257 albertel 6172: $domain=$env{'form.default_domain'};
1.246 albertel 6173: }
1.243 albertel 6174: $domain=~s/\s//g;
1.41 ng 6175: my $username=$entries{$fields{'username'}};
1.160 albertel 6176: $username=~s/\s//g;
1.243 albertel 6177: if (!$username) {
6178: my $id=$entries{$fields{'ID'}};
1.247 albertel 6179: $id=~s/\s//g;
1.243 albertel 6180: my %ids=&Apache::lonnet::idget($domain,$id);
6181: $username=$ids{$id};
6182: }
1.41 ng 6183: if (!exists($$classlist{"$username:$domain"})) {
1.247 albertel 6184: my $id=$entries{$fields{'ID'}};
6185: $id=~s/\s//g;
6186: if ($id) {
6187: push(@skipped,"$id:$domain");
6188: } else {
6189: push(@skipped,"$username:$domain");
6190: }
1.41 ng 6191: next;
6192: }
1.108 albertel 6193: my $usec=$classlist->{"$username:$domain"}[5];
1.106 albertel 6194: if (!&canmodify($usec)) {
6195: push(@notallowed,"$username:$domain");
6196: next;
6197: }
1.244 albertel 6198: my %points;
1.41 ng 6199: my %grades;
6200: foreach my $dest (keys(%fields)) {
1.244 albertel 6201: if ($dest eq 'ID' || $dest eq 'username' ||
6202: $dest eq 'domain') { next; }
6203: if ($entries{$fields{$dest}} =~ /^\s*$/) { next; }
6204: if ($dest=~/stores_(.*)_points/) {
6205: my $part=$1;
6206: my $wgt =&Apache::lonnet::EXT('resource.'.$part.'.weight',
6207: $symb,$domain,$username);
1.596.2.12.2. 0.2.7(ra 6208:an-25): $weights{$symb}{$part} = $wgt;
1.345 bowersj2 6209: if ($wgt) {
6210: $entries{$fields{$dest}}=~s/\s//g;
6211: my $pcr=$entries{$fields{$dest}} / $wgt;
1.596.2.12.2. 0.2.7(ra 6212:an-25): if ($passback) {
6213:an-25): $awardeds{$symb}{$part} = $pcr;
6214:an-25): $excuseds{$symb}{$part} = '';
6215:an-25): }
1.463 albertel 6216: my $award=($pcr == 0) ? 'incorrect_by_override'
6217: : 'correct_by_override';
1.596.2.4 raeburn 6218: if ($pcr>1) {
6219: push(@warnings,&mt("[_1]: point value larger than weight","$username:$domain"));
6220: }
1.345 bowersj2 6221: $grades{"resource.$part.awarded"}=$pcr;
6222: $grades{"resource.$part.solved"}=$award;
6223: $points{$part}=1;
6224: } else {
6225: $error_msg = "<br />" .
6226: &mt("Some point values were assigned"
6227: ." for problems with a weight "
6228: ."of zero. These values were "
6229: ."ignored.");
6230: }
1.244 albertel 6231: } else {
6232: if ($dest=~/stores_(.*)_awarded/) { if ($points{$1}) {next;} }
6233: if ($dest=~/stores_(.*)_solved/) { if ($points{$1}) {next;} }
6234: my $store_key=$dest;
1.596.2.12.2. 0.2.7(ra 6235:an-25): if ($passback) {
6236:an-25): if ($store_key=~/stores_(.*)_(awarded|solved)/) {
6237:an-25): my ($part,$key) = ($1,$2);
6238:an-25): unless ((ref($weights{$symb}) eq 'HASH') && (exists($weights{$symb}{$part}))) {
6239:an-25): $weights{$symb}{$part} = &Apache::lonnet::EXT('resource.'.$part.'.weight',
6240:an-25): $symb,$domain,$username);
6241:an-25): }
6242:an-25): if ($key eq 'awarded') {
6243:an-25): $awardeds{$symb}{$part} = $entries{$fields{$dest}};
6244:an-25): } elsif ($key eq 'solved') {
6245:an-25): if ($entries{$fields{$dest}} =~ /^excused/) {
6246:an-25): $excuseds{$symb}{$part} = 1;
6247:an-25): }
6248:an-25): }
6249:an-25): }
6250:an-25): }
1.244 albertel 6251: $store_key=~s/^stores/resource/;
6252: $store_key=~s/_/\./g;
6253: $grades{$store_key}=$entries{$fields{$dest}};
6254: }
1.41 ng 6255: }
1.596.2.12.2. 1(raebur 6256:0): if (! %grades) {
1.508 www 6257: push(@skipped,&mt("[_1]: no data to save","$username:$domain"));
6258: } else {
6259: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
6260: my $result=&Apache::lonnet::cstore(\%grades,$symb,
1.302 albertel 6261: $env{'request.course.id'},
6262: $domain,$username);
1.508 www 6263: if ($result eq 'ok') {
1.596.2.12.2. 1(raebur 6264:0): # Successfully stored
1.508 www 6265: $request->print('.');
1.596.2.4 raeburn 6266: # Remove from grading queue
1.596.2.12.2. 0.2.7(ra 6267:an-25): &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,$cnum,
6268:an-25): $domain,$username);
6269:an-25): $countdone++;
6270:an-25): if ($passback) {
6271:an-25): my @parts_in_upload;
6272:an-25): if (ref($weights{$symb}) eq 'HASH') {
6273:an-25): @parts_in_upload = sort(keys(%{$weights{$symb}}));
6274:an-25): }
6275:an-25): my @diffs = &Apache::loncommon::compare_arrays(\@parts_in_upload,\@parts);
6276:an-25): if (@diffs > 0) {
6277:an-25): my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$username);
6278:an-25): foreach my $part (@parts) {
6279:an-25): next if (grep(/^\Q$part\E$/,@parts_in_upload));
6280:an-25): $weights{$symb}{$part} = &Apache::lonnet::EXT('resource.'.$part.'.weight',
6281:an-25): $symb,$domain,$username);
6282:an-25): if ($record{"resource.$part.solved"} =~/^excused/) {
6283:an-25): $excuseds{$symb}{$part} = 1;
6284:an-25): } else {
6285:an-25): $excuseds{$symb}{$part} = '';
6286:an-25): }
6287:an-25): $awardeds{$symb}{$part} = $record{"resource.$part.awarded"};
6288:an-25): }
6289:an-25): }
6290:an-25): &process_passbacks('csvupload',[$symb],$cdom,$cnum,$domain,$username,$usec,\%weights,
6291:an-25): \%awardeds,\%excuseds,\%needpb,\%skip_passback,\%pbsave);
6292:an-25): }
1.508 www 6293: } else {
6294: $request->print("<p><span class=\"LC_error\">".
6295: &mt("Failed to save data for student [_1]. Message when trying to save was: [_2]",
6296: "$username:$domain",$result)."</span></p>");
6297: }
6298: $request->rflush();
6299: }
1.41 ng 6300: }
1.570 www 6301: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt("Saved scores for [quant,_1,student]",$countdone),$countdone==0));
1.596.2.4 raeburn 6302: if (@warnings) {
6303: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('Warnings generated for the following saved scores:'),1).'<br />');
6304: $request->print(join(', ',@warnings));
6305: }
1.41 ng 6306: if (@skipped) {
1.571 www 6307: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('No scores stored for the following username(s):'),1).'<br />');
6308: $request->print(join(', ',@skipped));
1.106 albertel 6309: }
6310: if (@notallowed) {
1.571 www 6311: $request->print('<br />'.&Apache::lonhtmlcommon::confirm_success(&mt('Modification of scores not allowed for the following username(s):'),1).'<br />');
6312: $request->print(join(', ',@notallowed));
1.41 ng 6313: }
1.106 albertel 6314: $request->print("<br />\n");
1.345 bowersj2 6315: return $error_msg;
1.26 albertel 6316: }
1.44 ng 6317: #------------- end of section for handling csv file upload ---------
6318: #
6319: #-------------------------------------------------------------------
6320: #
1.122 ng 6321: #-------------- Next few routines handle grading by page/sequence
1.72 ng 6322: #
6323: #--- Select a page/sequence and a student to grade
1.68 ng 6324: sub pickStudentPage {
1.596.2.12.2. 1(raebur 6325:0): my ($request,$symb) = @_;
1.68 ng 6326:
1.539 riegler 6327: my $alertmsg = &mt('Please select the student you wish to grade.');
1.596.2.12.2. 6(raebur 6328:6): &js_escape(\$alertmsg);
1(raebur 6329:0): $request->print(&Apache::lonhtmlcommon::scripttag(<<LISTJAVASCRIPT));
1.68 ng 6330:
6331: function checkPickOne(formname) {
1.76 ng 6332: if (radioSelection(formname.student) == null) {
1.539 riegler 6333: alert("$alertmsg");
1.68 ng 6334: return;
6335: }
1.125 ng 6336: ptr = pullDownSelection(formname.selectpage);
6337: formname.page.value = formname["page"+ptr].value;
6338: formname.title.value = formname["title"+ptr].value;
1.68 ng 6339: formname.submit();
6340: }
6341:
6342: LISTJAVASCRIPT
1.118 ng 6343: &commonJSfunctions($request);
1.596.2.12.2. 1(raebur 6344:0):
1.257 albertel 6345: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
6346: my $cnum = $env{"course.$env{'request.course.id'}.num"};
6347: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.596.2.12.2. 8(raebur 6348:9): my $getgroup = $env{'form.group'} eq '' ? 'all' : $env{'form.group'};
1.68 ng 6349:
1.398 albertel 6350: my $result='<h3><span class="LC_info"> '.
1.485 albertel 6351: &mt('Manual Grading by Page or Sequence').'</span></h3>';
1.68 ng 6352:
1.80 ng 6353: $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
1.582 raeburn 6354: my $map_error;
6355: my ($titles,$symbx) = &getSymbMap($map_error);
6356: if ($map_error) {
6357: $request->print(&navmap_errormsg());
6358: return;
6359: }
1.137 albertel 6360: my ($curpage) =&Apache::lonnet::decode_symb($symb);
6361: # my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb);
6362: # my $type=($curpage =~ /\.(page|sequence)/);
1.485 albertel 6363:
1.596.2.12.2. 1(raebur 6364:0): # Collection of hidden fields
6365:0): my $ctr=0;
1.70 ng 6366: foreach (@$titles) {
6367: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
6368: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
6369: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
6370: $ctr++;
6371: }
1.72 ng 6372: $result.='<input type="hidden" name="page" />'."\n".
6373: '<input type="hidden" name="title" />'."\n";
1.68 ng 6374:
1.432 banghart 6375: $result.=&build_section_inputs();
1.442 banghart 6376: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
6377: $result.='<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.596.2.12.2. 1(raebur 6378:0): '<input type="hidden" name="command" value="displayPage" />'."\n".
6379:0): '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
6380:0):
6381:0): # Show grading options
6382:0): $result.=&Apache::lonhtmlcommon::start_pick_box();
6383:0): my $select = '<select name="selectpage">'."\n";
6384:0): $ctr=0;
6385:0): foreach (@$titles) {
6386:0): my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
6387:0): $select.='<option value="'.$ctr.'"'.
6388:0): ($$symbx{$_} =~ /$curpage$/ ? ' selected="selected"' : '').
6389:0): '>'.$showtitle.'</option>'."\n";
6390:0): $ctr++;
6391:0): }
6392:0): $select.= '</select>';
1.72 ng 6393:
1.596.2.12.2. 1(raebur 6394:0): $result.=
6395:0): &Apache::lonhtmlcommon::row_title(&mt('Problems from'))
6396:0): .$select
6397:0): .&Apache::lonhtmlcommon::row_closure();
6398:0):
6399:0): $result.=
6400:0): &Apache::lonhtmlcommon::row_title(&mt('View Problem Text'))
6401:0): .'<label><input type="radio" name="vProb" value="no"'
6402:0): .' checked="checked" /> '.&mt('no').' </label>'."\n"
6403:0): .'<label><input type="radio" name="vProb" value="yes" />'
6404:0): .&mt('yes').'</label>'."\n"
6405:0): .&Apache::lonhtmlcommon::row_closure();
6406:0):
6407:0): $result.=
6408:0): &Apache::lonhtmlcommon::row_title(&mt('View Submissions'))
6409:0): .'<label><input type="radio" name="lastSub" value="none" /> '
6410:0): .&mt('none').' </label>'."\n"
6411:0): .'<label><input type="radio" name="lastSub" value="datesub"'
6412:0): .' checked="checked" /> '.&mt('all submissions').'</label>'."\n"
6413:0): .'<label><input type="radio" name="lastSub" value="all" /> '
6414:0): .&mt('all submissions with details').' </label>'
6415:0): .&Apache::lonhtmlcommon::row_closure();
6416:0):
6417:0): $result.=
6418:0): &Apache::lonhtmlcommon::row_title(&mt('Use CODE'))
6419:0): .'<input type="text" name="CODE" value="" />'
6420:0): .&Apache::lonhtmlcommon::row_closure(1)
6421:0): .&Apache::lonhtmlcommon::end_pick_box();
1.382 albertel 6422:
1.596.2.12.2. 1(raebur 6423:0): # Show list of students to select for grading
6424:0): $result.='<br /><input type="button" '.
1.589 bisitz 6425: 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /><br />'."\n";
1.72 ng 6426:
1.68 ng 6427: $request->print($result);
6428:
1.485 albertel 6429: my $studentTable.=' <b>'.&mt('Select a student you wish to grade and then click on the Next button.').'</b><br />'.
1.484 albertel 6430: &Apache::loncommon::start_data_table().
6431: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 6432: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 6433: '<th>'.&nameUserString('header').'</th>'.
1.485 albertel 6434: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 6435: '<th>'.&nameUserString('header').'</th>'.
6436: &Apache::loncommon::end_data_table_header_row();
1.68 ng 6437:
1.596.2.12.2. 8(raebur 6438:9): my (undef,undef,$fullname) = &getclasslist($getsec,'1',$getgroup);
1.68 ng 6439: my $ptr = 1;
1.294 albertel 6440: foreach my $student (sort
6441: {
6442: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
6443: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
6444: }
6445: return $a cmp $b;
6446: } (keys(%$fullname))) {
1.68 ng 6447: my ($uname,$udom) = split(/:/,$student);
1.484 albertel 6448: $studentTable.=($ptr%2==1 ? &Apache::loncommon::start_data_table_row()
6449: : '</td>');
1.126 ng 6450: $studentTable.='<td align="right">'.$ptr.' </td>';
1.288 albertel 6451: $studentTable.='<td> <label><input type="radio" name="student" value="'.$student.'" /> '
6452: .&nameUserString(undef,$$fullname{$student},$uname,$udom)."</label>\n";
1.484 albertel 6453: $studentTable.=
6454: ($ptr%2 == 0 ? '</td>'.&Apache::loncommon::end_data_table_row()
6455: : '');
1.68 ng 6456: $ptr++;
6457: }
1.484 albertel 6458: if ($ptr%2 == 0) {
6459: $studentTable.='</td><td> </td><td> </td>'.
6460: &Apache::loncommon::end_data_table_row();
6461: }
6462: $studentTable.=&Apache::loncommon::end_data_table()."\n";
1.126 ng 6463: $studentTable.='<input type="button" '.
1.589 bisitz 6464: 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /></form>'."\n";
1.68 ng 6465:
6466: $request->print($studentTable);
6467:
6468: return '';
6469: }
6470:
6471: sub getSymbMap {
1.582 raeburn 6472: my ($map_error) = @_;
1.132 bowersj2 6473: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 6474: unless (ref($navmap)) {
6475: if (ref($map_error)) {
6476: $$map_error = 'navmap';
6477: }
6478: return;
6479: }
1.68 ng 6480: my %symbx = ();
6481: my @titles = ();
1.117 bowersj2 6482: my $minder = 0;
6483:
6484: # Gather every sequence that has problems.
1.240 albertel 6485: my @sequences = $navmap->retrieveResources(undef, sub { shift->is_map(); },
6486: 1,0,1);
1.117 bowersj2 6487: for my $sequence ($navmap->getById('0.0'), @sequences) {
1.596.2.12.2. 0.2.4(ra 6488:ul-23): if ($navmap->hasResource($sequence, sub { shift->is_gradable(); }, 0) ) {
1.381 albertel 6489: my $title = $minder.'.'.
6490: &HTML::Entities::encode($sequence->compTitle(),'"\'&');
6491: push(@titles, $title); # minder in case two titles are identical
6492: $symbx{$title} = &HTML::Entities::encode($sequence->symb(),'"\'&');
1.117 bowersj2 6493: $minder++;
1.241 albertel 6494: }
1.68 ng 6495: }
6496: return \@titles,\%symbx;
6497: }
6498:
1.72 ng 6499: #
6500: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68 ng 6501: sub displayPage {
1.596.2.12.2. 1(raebur 6502:0): my ($request,$symb) = @_;
1.257 albertel 6503: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
6504: my $cnum = $env{"course.$env{'request.course.id'}.num"};
6505: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
6506: my $pageTitle = $env{'form.page'};
1.103 albertel 6507: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 6508: my ($uname,$udom) = split(/:/,$env{'form.student'});
6509: my $usec=$classlist->{$env{'form.student'}}[5];
1.168 albertel 6510:
6511: #need to make sure we have the correct data for later EXT calls,
6512: #thus invalidate the cache
6513: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 6514: $env{'course.'.$env{'request.course.id'}.'.num'},
6515: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 6516: &Apache::lonnet::clear_EXT_cache_status();
6517:
1.103 albertel 6518: if (!&canview($usec)) {
1.596.2.12.2. 1(raebur 6519:0): $request->print(
6520:0): '<span class="LC_warning">'.
6521:0): &mt('Unable to view requested student. ([_1])',
6522:0): $env{'form.student'}).
6523:0): '</span>');
8(raebur 6524:4): return;
1.103 albertel 6525: }
1.398 albertel 6526: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.485 albertel 6527: $result.='<h3> '.&mt('Student: [_1]',&nameUserString(undef,$$fullname{$env{'form.student'}},$uname,$udom)).
1.129 ng 6528: '</h3>'."\n";
1.500 albertel 6529: $env{'form.CODE'} = uc($env{'form.CODE'});
1.501 foxr 6530: if (&Apache::lonnet::validCODE(uc($env{'form.CODE'}))) {
1.485 albertel 6531: $result.='<h3> '.&mt('CODE: [_1]',$env{'form.CODE'}).'</h3>'."\n";
1.382 albertel 6532: } else {
6533: delete($env{'form.CODE'});
6534: }
1.71 ng 6535: &sub_page_js($request);
6536: $request->print($result);
6537:
1.132 bowersj2 6538: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 6539: unless (ref($navmap)) {
6540: $request->print(&navmap_errormsg());
6541: return;
6542: }
1.257 albertel 6543: my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($env{'form.page'});
1.68 ng 6544: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 6545: if (!$map) {
1.485 albertel 6546: $request->print('<span class="LC_warning">'.&mt('Unable to view requested sequence. ([_1])',$resUrl).'</span>');
1.288 albertel 6547: return;
6548: }
1.68 ng 6549: my $iterator = $navmap->getIterator($map->map_start(),
6550: $map->map_finish());
6551:
1.71 ng 6552: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72 ng 6553: '<input type="hidden" name="command" value="gradeByPage" />'."\n".
1.257 albertel 6554: '<input type="hidden" name="fullname" value="'.$$fullname{$env{'form.student'}}.'" />'."\n".
6555: '<input type="hidden" name="student" value="'.$env{'form.student'}.'" />'."\n".
1.72 ng 6556: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
1.257 albertel 6557: '<input type="hidden" name="title" value="'.$env{'form.title'}.'" />'."\n".
1.418 albertel 6558: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.596.2.12.2. 1(raebur 6559:0): '<input type="hidden" name="overRideScore" value="no" />'."\n";
1.71 ng 6560:
1.382 albertel 6561: if (defined($env{'form.CODE'})) {
6562: $studentTable.=
6563: '<input type="hidden" name="CODE" value="'.$env{'form.CODE'}.'" />'."\n";
6564: }
1.381 albertel 6565: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 6566: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 6567:
1.594 bisitz 6568: $studentTable.=' <span class="LC_info">'.
6569: &mt('Problems graded correct by the computer are marked with a [_1] symbol.',$checkIcon).
6570: '</span>'."\n".
1.484 albertel 6571: &Apache::loncommon::start_data_table().
6572: &Apache::loncommon::start_data_table_header_row().
1.596.2.12.2. 1(raebur 6573:0): '<th>'.&mt('Prob.').'</th>'.
1.485 albertel 6574: '<th> '.($env{'form.vProb'} eq 'no' ? &mt('Title') : &mt('Problem Text')).'/'.&mt('Grade').'</th>'.
1.484 albertel 6575: &Apache::loncommon::end_data_table_header_row();
1.71 ng 6576:
1.329 albertel 6577: &Apache::lonxml::clear_problem_counter();
1.196 albertel 6578: my ($depth,$question,$prob) = (1,1,1);
1.68 ng 6579: $iterator->next(); # skip the first BEGIN_MAP
6580: my $curRes = $iterator->next(); # for "current resource"
1.101 albertel 6581: while ($depth > 0) {
1.68 ng 6582: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 6583: if($curRes == $iterator->END_MAP) { $depth--; }
1.68 ng 6584:
1.596.2.12.2. 0.2.4(ra 6585:ul-23): if (ref($curRes) && $curRes->is_gradable()) {
1.91 albertel 6586: my $parts = $curRes->parts();
1.68 ng 6587: my $title = $curRes->compTitle();
1.71 ng 6588: my $symbx = $curRes->symb();
1.596.2.12.2. 0.2.4(ra 6589:ul-23): my $is_tool = ($symbx =~ /ext\.tool$/);
1.484 albertel 6590: $studentTable.=
6591: &Apache::loncommon::start_data_table_row().
6592: '<td align="center" valign="top" >'.$prob.
1.485 albertel 6593: (scalar(@{$parts}) == 1 ? ''
1.596.2.12.2. 2(raebur 6594:2): : '<br />('.&mt('[_1]parts',
6595:2): scalar(@{$parts}).' ').')'
1.485 albertel 6596: ).
6597: '</td>';
1.71 ng 6598: $studentTable.='<td valign="top">';
1.382 albertel 6599: my %form = ('CODE' => $env{'form.CODE'},);
1.596.2.12.2. 0.2.4(ra 6600:ul-23): if ($is_tool) {
6601:ul-23): $studentTable.=' <b>'.$title.'</b><br />';
6602:ul-23): } else {
6603:ul-23): if ($env{'form.vProb'} eq 'yes' ) {
6604:ul-23): $studentTable.=&show_problem($request,$symbx,$uname,$udom,1,
6605:ul-23): undef,'both',\%form);
6606:ul-23): } else {
6607:ul-23): my $companswer = &Apache::loncommon::get_student_answers($symbx,$uname,$udom,$env{'request.course.id'},%form);
6608:ul-23): $companswer =~ s|<form(.*?)>||g;
6609:ul-23): $companswer =~ s|</form>||g;
6610:ul-23): # while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
6611:ul-23): # $companswer =~ s/$1/ /ms;
6612:ul-23): # $request->print('match='.$1."<br />\n");
6613:ul-23): # }
6614:ul-23): # $companswer =~ s|<table border=\"1\">|<table border=\"0\">|g;
6615:ul-23): $studentTable.=' <b>'.$title.'</b> <br /> <b>'.&mt('Correct answer').':</b><br />'.$companswer;
6616:ul-23): }
1.71 ng 6617: }
6618:
1.257 albertel 6619: my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
1.125 ng 6620:
1.257 albertel 6621: if ($env{'form.lastSub'} eq 'datesub') {
1.71 ng 6622: if ($record{'version'} eq '') {
1.596.2.12.2. 0.2.4(ra 6623:ul-23): my $msg = &mt('No recorded submission for this problem.');
6624:ul-23): if ($is_tool) {
6625:ul-23): $msg = &mt('No recorded transactions for this external tool');
6626:ul-23): }
6627:ul-23): $studentTable.='<br /> <span class="LC_warning">'.$msg.'</span><br />';
1.71 ng 6628: } else {
1.116 ng 6629: my %responseType = ();
6630: foreach my $partid (@{$parts}) {
1.147 albertel 6631: my @responseIds =$curRes->responseIds($partid);
6632: my @responseType =$curRes->responseType($partid);
6633: my %responseIds;
6634: for (my $i=0;$i<=$#responseIds;$i++) {
6635: $responseIds{$responseIds[$i]}=$responseType[$i];
6636: }
6637: $responseType{$partid} = \%responseIds;
1.116 ng 6638: }
1.148 albertel 6639: $studentTable.= &displaySubByDates($symbx,\%record,$parts,\%responseType,$checkIcon,$uname,$udom);
1.147 albertel 6640:
1.71 ng 6641: }
1.257 albertel 6642: } elsif ($env{'form.lastSub'} eq 'all') {
6643: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.596.2.12.2. 1(raebur 6644:5): my $identifier = (&canmodify($usec)? $prob : '');
1.71 ng 6645: $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
1.257 albertel 6646: $env{'request.course.id'},
1.596.2.12.2. 1(raebur 6647:5): '','.submission',undef,
6648:5): $usec,$identifier);
1.71 ng 6649:
6650: }
1.103 albertel 6651: if (&canmodify($usec)) {
1.585 bisitz 6652: $studentTable.=&gradeBox_start();
1.103 albertel 6653: foreach my $partid (@{$parts}) {
6654: $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
6655: $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
6656: $question++;
6657: }
1.585 bisitz 6658: $studentTable.=&gradeBox_end();
1.196 albertel 6659: $prob++;
1.71 ng 6660: }
6661: $studentTable.='</td></tr>';
1.68 ng 6662:
1.103 albertel 6663: }
1.68 ng 6664: $curRes = $iterator->next();
6665: }
1.596.2.12.2. 6(raebur 6666:1): my $disabled;
6667:1): unless (&canmodify($usec)) {
6668:1): $disabled = ' disabled="disabled"';
6669:1): }
1.68 ng 6670:
1.589 bisitz 6671: $studentTable.=
6672: '</table>'."\n".
1.596.2.12.2. 6(raebur 6673:1): '<input type="button" value="'.&mt('Save').'"'.$disabled.' '.
1.589 bisitz 6674: 'onclick="javascript:checkSubmitPage(this.form,'.$question.');" />'.
6675: '</form>'."\n";
1.71 ng 6676: $request->print($studentTable);
6677:
6678: return '';
1.119 ng 6679: }
6680:
6681: sub displaySubByDates {
1.148 albertel 6682: my ($symb,$record,$parts,$responseType,$checkIcon,$uname,$udom) = @_;
1.224 albertel 6683: my $isCODE=0;
1.335 albertel 6684: my $isTask = ($symb =~/\.task$/);
1.596.2.12.2. 0.2.4(ra 6685:ul-23): my $is_tool = ($symb =~/\.tool$/);
1.224 albertel 6686: if (exists($record->{'resource.CODE'})) { $isCODE=1; }
1.467 albertel 6687: my $studentTable=&Apache::loncommon::start_data_table().
6688: &Apache::loncommon::start_data_table_header_row().
6689: '<th>'.&mt('Date/Time').'</th>'.
6690: ($isCODE?'<th>'.&mt('CODE').'</th>':'').
1.596.2.12.2. (raeburn 6691:): ($isTask?'<th>'.&mt('Version').'</th>':'').
0.2.4(ra 6692:ul-23): '<th>'.($is_tool?&mt('Grade'):&mt('Submission')).'</th>'.
1.467 albertel 6693: '<th>'.&mt('Status').'</th>'.
6694: &Apache::loncommon::end_data_table_header_row();
1.119 ng 6695: my ($version);
6696: my %mark;
1.148 albertel 6697: my %orders;
1.119 ng 6698: $mark{'correct_by_student'} = $checkIcon;
1.147 albertel 6699: if (!exists($$record{'1:timestamp'})) {
1.596.2.12.2. 0.2.4(ra 6700:ul-23): if ($is_tool) {
6701:ul-23): return '<br /> <span class="LC_warning">'.&mt('No grade passed back.').'</span><br />';
6702:ul-23): } else {
6703:ul-23): return '<br /> <span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br />';
6704:ul-23): }
1.147 albertel 6705: }
1.335 albertel 6706:
6707: my $interaction;
1.525 raeburn 6708: my $no_increment = 1;
1.596.2.12.2. 5(raebur 6709:5): my (%lastrndseed,%lasttype);
1.119 ng 6710: for ($version=1;$version<=$$record{'version'};$version++) {
1.467 albertel 6711: my $timestamp =
6712: &Apache::lonlocal::locallocaltime($$record{$version.':timestamp'});
1.335 albertel 6713: if (exists($$record{$version.':resource.0.version'})) {
6714: $interaction = $$record{$version.':resource.0.version'};
6715: }
1.596.2.12.2. (raeburn 6716:): if ($isTask && $env{'form.previousversion'}) {
6717:): next unless ($interaction == $env{'form.previousversion'});
6718:): }
1.335 albertel 6719: my $where = ($isTask ? "$version:resource.$interaction"
6720: : "$version:resource");
1.467 albertel 6721: $studentTable.=&Apache::loncommon::start_data_table_row().
6722: '<td>'.$timestamp.'</td>';
1.224 albertel 6723: if ($isCODE) {
6724: $studentTable.='<td>'.$record->{$version.':resource.CODE'}.'</td>';
6725: }
1.596.2.12.2. (raeburn 6726:): if ($isTask) {
6727:): $studentTable.='<td>'.$interaction.'</td>';
6728:): }
1.119 ng 6729: my @versionKeys = split(/\:/,$$record{$version.':keys'});
6730: my @displaySub = ();
6731: foreach my $partid (@{$parts}) {
1.596.2.2 raeburn 6732: my ($hidden,$type);
6733: $type = $$record{$version.':resource.'.$partid.'.type'};
6734: if (($type eq 'anonsurvey') || ($type eq 'anonsurveycred')) {
1.596 raeburn 6735: $hidden = 1;
6736: }
1.596.2.12.2. 1(raebur 6737:0): my @matchKey;
6738:0): if ($isTask) {
6739:0): @matchKey = sort(grep(/^resource\.\d+\.\Q$partid\E\.award$/,@versionKeys));
0.2.4(ra 6740:ul-23): } elsif ($is_tool) {
6741:ul-23): @matchKey = sort(grep(/^resource\.\Q$partid\E\.awarded$/,@versionKeys));
1(raebur 6742:0): } else {
6743:0): @matchKey = sort(grep(/^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys));
6744:0): }
1.122 ng 6745: # next if ($$record{"$version:resource.$partid.solved"} eq '');
1.324 albertel 6746: my $display_part=&get_display_part($partid,$symb);
1.147 albertel 6747: foreach my $matchKey (@matchKey) {
1.198 albertel 6748: if (exists($$record{$version.':'.$matchKey}) &&
6749: $$record{$version.':'.$matchKey} ne '') {
1.596.2.12.2. 0.2.4(ra 6750:ul-23): if ($is_tool) {
6751:ul-23): $displaySub[0].=$$record{"$version:resource.$partid.awarded"};
1.596 raeburn 6752: } else {
1.596.2.12.2. 0.2.4(ra 6753:ul-23): my ($responseId)= ($isTask ? ($matchKey=~ /^resource\.(.*?)\.\Q$partid\E\.award$/)
6754:ul-23): : ($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/));
6755:ul-23): $displaySub[0].='<span class="LC_nobreak">';
6756:ul-23): $displaySub[0].='<b>'.&mt('Part: [_1]',$display_part).'</b>'
6757:ul-23): .' <span class="LC_internal_info">'
6758:ul-23): .'('.&mt('Response ID: [_1]',$responseId).')'
6759:ul-23): .'</span>'
6760:ul-23): .' <b>';
6761:ul-23): if ($hidden) {
6762:ul-23): $displaySub[0].= &mt('Anonymous Survey').'</b>';
6763:ul-23): } else {
6764:ul-23): my ($trial,$rndseed,$newvariation);
6765:ul-23): if ($type eq 'randomizetry') {
6766:ul-23): $trial = $$record{"$where.$partid.tries"};
6767:ul-23): $rndseed = $$record{"$where.$partid.rndseed"};
1.596.2.2 raeburn 6768: }
1.596.2.12.2. 0.2.4(ra 6769:ul-23): if ($$record{"$where.$partid.tries"} eq '') {
6770:ul-23): $displaySub[0].=&mt('Trial not counted');
6771:ul-23): } else {
6772:ul-23): $displaySub[0].=&mt('Trial: [_1]',
6773:ul-23): $$record{"$where.$partid.tries"});
6774:ul-23): if (($rndseed ne '') && ($lastrndseed{$partid} ne '')) {
6775:ul-23): if (($rndseed ne $lastrndseed{$partid}) &&
6776:ul-23): (($type eq 'randomizetry') || ($lasttype{$partid} eq 'randomizetry'))) {
6777:ul-23): $newvariation = ' ('.&mt('New variation this try').')';
6778:ul-23): }
6779:ul-23): }
6780:ul-23): $lastrndseed{$partid} = $rndseed;
6781:ul-23): $lasttype{$partid} = $type;
6782:ul-23): }
6783:ul-23): my $responseType=($isTask ? 'Task'
6784:ul-23): : $responseType->{$partid}->{$responseId});
6785:ul-23): if (!exists($orders{$partid})) { $orders{$partid}={}; }
6786:ul-23): if ((!exists($orders{$partid}->{$responseId})) || ($trial)) {
6787:ul-23): $orders{$partid}->{$responseId}=
6788:ul-23): &get_order($partid,$responseId,$symb,$uname,$udom,
6789:ul-23): $no_increment,$type,$trial,$rndseed);
6790:ul-23): }
6791:ul-23): $displaySub[0].='</b>'.$newvariation.'</span>'; # /nobreak
6792:ul-23): $displaySub[0].=' '.
6793:ul-23): &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:",$uname,$udom,$type,$trial,$rndseed).'<br />';
6794:ul-23): }
1.596 raeburn 6795: }
1.147 albertel 6796: }
6797: }
1.335 albertel 6798: if (exists($$record{"$where.$partid.checkedin"})) {
1.485 albertel 6799: $displaySub[1].=&mt('Checked in by [_1] into slot [_2]',
6800: $$record{"$where.$partid.checkedin"},
6801: $$record{"$where.$partid.checkedin.slot"}).
6802: '<br />';
1.335 albertel 6803: }
6804: if (exists $$record{"$where.$partid.award"}) {
1.485 albertel 6805: $displaySub[1].='<b>'.&mt('Part:').'</b> '.$display_part.' '.
1.335 albertel 6806: lc($$record{"$where.$partid.award"}).' '.
6807: $mark{$$record{"$where.$partid.solved"}}.
1.147 albertel 6808: '<br />';
1.596.2.12.2. 0.2.4(ra 6809:ul-23): } elsif (($is_tool) && (exists($$record{"$version:resource.$partid.solved"}))) {
6810:ul-23): if ($$record{"$version:resource.$partid.solved"} =~ /^(in|)correct_by_passback$/) {
6811:ul-23): $displaySub[1].=&mt('Grade passed back by external tool');
6812:ul-23): }
1.147 albertel 6813: }
1.335 albertel 6814: if (exists $$record{"$where.$partid.regrader"}) {
1.596.2.12.2. 0.2.4(ra 6815:ul-23): $displaySub[2].=$$record{"$where.$partid.regrader"};
6816:ul-23): unless ($is_tool) {
6817:ul-23): $displaySub[2].=' (<b>'.&mt('Part').':</b> '.$display_part.')';
6818:ul-23): }
1.335 albertel 6819: } elsif ($$record{"$version:resource.$partid.regrader"} =~ /\S/) {
6820: $displaySub[2].=
1.596.2.12.2. 0.2.4(ra 6821:ul-23): $$record{"$version:resource.$partid.regrader"};
6822:ul-23): unless ($is_tool) {
6823:ul-23): $displaySub[2].=' (<b>'.&mt('Part').':</b> '.$display_part.')';
6824:ul-23): }
1.147 albertel 6825: }
6826: }
6827: # needed because old essay regrader has not parts info
6828: if (exists $$record{"$version:resource.regrader"}) {
6829: $displaySub[2].=$$record{"$version:resource.regrader"};
6830: }
6831: $studentTable.='<td>'.$displaySub[0].' </td><td>'.$displaySub[1];
6832: if ($displaySub[2]) {
1.467 albertel 6833: $studentTable.=&mt('Manually graded by [_1]',$displaySub[2]);
1.147 albertel 6834: }
1.467 albertel 6835: $studentTable.=' </td>'.
6836: &Apache::loncommon::end_data_table_row();
1.119 ng 6837: }
1.467 albertel 6838: $studentTable.=&Apache::loncommon::end_data_table();
1.119 ng 6839: return $studentTable;
1.71 ng 6840: }
6841:
6842: sub updateGradeByPage {
1.596.2.12.2. 1(raebur 6843:0): my ($request,$symb) = @_;
1.71 ng 6844:
1.257 albertel 6845: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
6846: my $cnum = $env{"course.$env{'request.course.id'}.num"};
6847: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
6848: my $pageTitle = $env{'form.page'};
1.103 albertel 6849: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 6850: my ($uname,$udom) = split(/:/,$env{'form.student'});
6851: my $usec=$classlist->{$env{'form.student'}}[5];
1.103 albertel 6852: if (!&canmodify($usec)) {
1.526 raeburn 6853: $request->print('<span class="LC_warning">'.&mt('Unable to modify requested student ([_1])',$env{'form.student'}).'</span>');
1.103 albertel 6854: return;
6855: }
1.398 albertel 6856: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.526 raeburn 6857: $result.='<h3> '.&mt('Student: ').&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
1.129 ng 6858: '</h3>'."\n";
1.70 ng 6859:
1.68 ng 6860: $request->print($result);
6861:
1.582 raeburn 6862:
1.132 bowersj2 6863: my $navmap = Apache::lonnavmaps::navmap->new();
1.582 raeburn 6864: unless (ref($navmap)) {
6865: $request->print(&navmap_errormsg());
6866: return;
6867: }
1.257 albertel 6868: my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $env{'form.page'});
1.71 ng 6869: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 6870: if (!$map) {
1.527 raeburn 6871: $request->print('<span class="LC_warning">'.&mt('Unable to grade requested sequence ([_1]).',$resUrl).'</span>');
1.288 albertel 6872: return;
6873: }
1.71 ng 6874: my $iterator = $navmap->getIterator($map->map_start(),
6875: $map->map_finish());
1.70 ng 6876:
1.484 albertel 6877: my $studentTable=
6878: &Apache::loncommon::start_data_table().
6879: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 6880: '<th align="center"> '.&mt('Prob.').' </th>'.
6881: '<th> '.&mt('Title').' </th>'.
6882: '<th> '.&mt('Previous Score').' </th>'.
6883: '<th> '.&mt('New Score').' </th>'.
1.484 albertel 6884: &Apache::loncommon::end_data_table_header_row();
1.71 ng 6885:
6886: $iterator->next(); # skip the first BEGIN_MAP
6887: my $curRes = $iterator->next(); # for "current resource"
1.596.2.12.2. 1(raebur 6888:5): my ($depth,$question,$prob,$changeflag,$hideflag)= (1,1,1,0,0);
0.2.7(ra 6889:an-25): my (@updates,%weights,%excuseds,%awardeds,@symbs_in_map);
1.101 albertel 6890: while ($depth > 0) {
1.71 ng 6891: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 6892: if($curRes == $iterator->END_MAP) { $depth--; }
1.71 ng 6893:
1.385 albertel 6894: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 6895: my $parts = $curRes->parts();
1.71 ng 6896: my $title = $curRes->compTitle();
6897: my $symbx = $curRes->symb();
1.596.2.12.2. 0.2.7(ra 6898:an-25): push(@symbs_in_map,$symbx);
1.484 albertel 6899: $studentTable.=
6900: &Apache::loncommon::start_data_table_row().
6901: '<td align="center" valign="top" >'.$prob.
1.485 albertel 6902: (scalar(@{$parts}) == 1 ? ''
1.596.2.2 raeburn 6903: : '<br />('.&mt('[quant,_1,part]',scalar(@{$parts}))
1.526 raeburn 6904: .')').'</td>';
1.71 ng 6905: $studentTable.='<td valign="top"> <b>'.$title.'</b> </td>';
6906:
6907: my %newrecord=();
6908: my @displayPts=();
1.269 raeburn 6909: my %aggregate = ();
6910: my $aggregateflag = 0;
1.596.2.12.2. 9(raebur 6911:1): my %queueable;
1(raebur 6912:5): if ($env{'form.HIDE'.$prob}) {
6913:5): my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
6914:5): my ($version,$parts) = split(/:/,$env{'form.HIDE'.$prob},2);
6915:5): my $numchgs = &makehidden($version,$parts,\%record,$symbx,$udom,$uname,1);
0.2.7(ra 6916:an-25): if ($numchgs) {
6917:an-25): push(@updates,$symbx);
6918:an-25): }
1(raebur 6919:5): $hideflag += $numchgs;
6920:5): }
1.71 ng 6921: foreach my $partid (@{$parts}) {
1.257 albertel 6922: my $newpts = $env{'form.GD_BOX'.$question.'_'.$partid};
6923: my $oldpts = $env{'form.oldpts'.$question.'_'.$partid};
1.596.2.12.2. 9(raebur 6924:1): my @types = $curRes->responseType($partid);
8(raebur 6925:1): if (grep(/^essay$/,@types)) {
6926:1): $queueable{$partid} = 1;
6927:1): } else {
9(raebur 6928:1): my @ids = $curRes->responseIds($partid);
8(raebur 6929:1): for (my $i=0; $i < scalar(@ids); $i++) {
9(raebur 6930:1): my $hndgrd = &Apache::lonnet::EXT('resource.'.$partid.'_'.$ids[$i].
8(raebur 6931:1): '.handgrade',$symb);
6932:1): if (lc($hndgrd) eq 'yes') {
6933:1): $queueable{$partid} = 1;
6934:1): last;
6935:1): }
6936:1): }
6937:1): }
1.257 albertel 6938: my $wgt = $env{'form.WGT'.$question.'_'.$partid} != 0 ?
6939: $env{'form.WGT'.$question.'_'.$partid} : 1;
1.596.2.12.2. 0.2.7(ra 6940:an-25): $weights{$symbx}{$partid} = $wgt;
6941:an-25): $excuseds{$symbx}{$partid} = '';
1.71 ng 6942: my $partial = $newpts/$wgt;
6943: my $score;
6944: if ($partial > 0) {
6945: $score = 'correct_by_override';
1.125 ng 6946: } elsif ($newpts ne '') { #empty is taken as 0
1.71 ng 6947: $score = 'incorrect_by_override';
6948: }
1.257 albertel 6949: my $dropMenu = $env{'form.GD_SEL'.$question.'_'.$partid};
1.125 ng 6950: if ($dropMenu eq 'excused') {
1.71 ng 6951: $partial = '';
6952: $score = 'excused';
1.596.2.12.2. 0.2.7(ra 6953:an-25): $excuseds{$symbx}{$partid} = 1;
1.125 ng 6954: } elsif ($dropMenu eq 'reset status'
1.257 albertel 6955: && $env{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
1.125 ng 6956: $newrecord{'resource.'.$partid.'.tries'} = 0;
6957: $newrecord{'resource.'.$partid.'.solved'} = '';
6958: $newrecord{'resource.'.$partid.'.award'} = '';
6959: $newrecord{'resource.'.$partid.'.awarded'} = 0;
1.257 albertel 6960: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 6961: $changeflag++;
6962: $newpts = '';
1.269 raeburn 6963:
6964: my $aggtries = $env{'form.aggtries'.$question.'_'.$partid};
6965: my $totaltries = $env{'form.totaltries'.$question.'_'.$partid};
6966: my $solvedstatus = $env{'form.solved'.$question.'_'.$partid};
6967: if ($aggtries > 0) {
6968: &decrement_aggs($symbx,$partid,\%aggregate,$aggtries,$totaltries,$solvedstatus);
6969: $aggregateflag = 1;
6970: }
1.71 ng 6971: }
1.324 albertel 6972: my $display_part=&get_display_part($partid,$curRes->symb());
1.257 albertel 6973: my $oldstatus = $env{'form.solved'.$question.'_'.$partid};
1.526 raeburn 6974: $displayPts[0].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.71 ng 6975: (($oldstatus eq 'excused') ? 'excused' : $oldpts).
1.326 albertel 6976: ' <br />';
1.526 raeburn 6977: $displayPts[1].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.125 ng 6978: (($score eq 'excused') ? 'excused' : $newpts).
1.326 albertel 6979: ' <br />';
1.71 ng 6980: $question++;
1.596.2.12.2. 0.2.7(ra 6981:an-25): if (($newpts eq '') || ($partial eq '')) {
6982:an-25): $awardeds{$symbx}{$partid} = 0;
6983:an-25): } else {
6984:an-25): $awardeds{$symbx}{$partid} = $partial;
6985:an-25): }
1.380 albertel 6986: next if ($dropMenu eq 'reset status' || ($newpts eq $oldpts && $score ne 'excused'));
1.125 ng 6987:
1.71 ng 6988: $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
1.125 ng 6989: $newrecord{'resource.'.$partid.'.solved'} = $score if $score ne '';
1.257 albertel 6990: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}"
1.125 ng 6991: if (scalar(keys(%newrecord)) > 0);
1.71 ng 6992:
6993: $changeflag++;
6994: }
6995: if (scalar(keys(%newrecord)) > 0) {
1.382 albertel 6996: my %record =
6997: &Apache::lonnet::restore($symbx,$env{'request.course.id'},
6998: $udom,$uname);
6999:
7000: if (&Apache::lonnet::validCODE($env{'form.CODE'})) {
7001: $newrecord{'resource.CODE'} = $env{'form.CODE'};
7002: } elsif (&Apache::lonnet::validCODE($record{'resource.CODE'})) {
7003: $newrecord{'resource.CODE'} = '';
7004: }
1.257 albertel 7005: &Apache::lonnet::cstore(\%newrecord,$symbx,$env{'request.course.id'},
1.71 ng 7006: $udom,$uname);
1.382 albertel 7007: %record = &Apache::lonnet::restore($symbx,
7008: $env{'request.course.id'},
7009: $udom,$uname);
1.380 albertel 7010: &check_and_remove_from_queue($parts,\%record,undef,$symbx,
1.596.2.12.2. 8(raebur 7011:1): $cdom,$cnum,$udom,$uname,\%queueable);
1.71 ng 7012: }
1.380 albertel 7013:
1.269 raeburn 7014: if ($aggregateflag) {
7015: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
7016: $env{'course.'.$env{'request.course.id'}.'.domain'},
7017: $env{'course.'.$env{'request.course.id'}.'.num'});
7018: }
1.125 ng 7019:
1.71 ng 7020: $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
7021: '<td valign="top">'.$displayPts[1].'</td>'.
1.484 albertel 7022: &Apache::loncommon::end_data_table_row();
1.68 ng 7023:
1.196 albertel 7024: $prob++;
1.596.2.12.2. 0.2.7(ra 7025:an-25): if ($changeflag) {
7026:an-25): push(@updates,$symbx);
7027:an-25): }
1.68 ng 7028: }
1.71 ng 7029: $curRes = $iterator->next();
1.68 ng 7030: }
1.98 albertel 7031:
1.484 albertel 7032: $studentTable.=&Apache::loncommon::end_data_table();
1.526 raeburn 7033: my $grademsg=($changeflag == 0 ? &mt('No score was changed or updated.') :
7034: &mt('The scores were changed for [quant,_1,problem].',
1.596.2.12.2. 1(raebur 7035:5): $changeflag).'<br />');
7036:5): my $hidemsg=($hideflag == 0 ? '' :
7037:5): &mt('Submissions were marked "hidden" for [quant,_1,transaction].',
7038:5): $hideflag).'<br />');
7039:5): $request->print($hidemsg.$grademsg.$studentTable);
1.68 ng 7040:
1.596.2.12.2. 0.2.7(ra 7041:an-25): if (@updates) {
7042:an-25): my (@allsymbs,$mapsymb,@recurseup,%parentmapsymbs,%possmappb,%possrespb);
7043:an-25): @allsymbs = @updates;
7044:an-25): if (ref($map)) {
7045:an-25): $mapsymb = $map->symb();
7046:an-25): push(@allsymbs,$mapsymb);
7047:an-25): @recurseup = $navmap->recurseup_maps($map->src,1);
7048:an-25): }
7049:an-25): if (@recurseup) {
7050:an-25): push(@allsymbs,@recurseup);
7051:an-25): map { $parentmapsymbs{$_} = 1; } @recurseup;
7052:an-25): }
7053:an-25): my %passback = &Apache::lonnet::get('nohist_linkprot_passback',\@allsymbs,$cdom,$cnum);
7054:an-25): my (%uniqsymbs,$use_symbs_in_map,%launch_to_symb);
7055:an-25): if (keys(%passback)) {
7056:an-25): foreach my $possible (keys(%passback)) {
7057:an-25): if (ref($passback{$possible}) eq 'HASH') {
7058:an-25): if ($possible eq $mapsymb) {
7059:an-25): foreach my $launcher (keys(%{$passback{$possible}})) {
7060:an-25): $possmappb{$launcher} = 1;
7061:an-25): $launch_to_symb{$launcher} = $possible;
7062:an-25): }
7063:an-25): $use_symbs_in_map = 1;
7064:an-25): } elsif (exists($parentmapsymbs{$possible})) {
7065:an-25): foreach my $launcher (keys(%{$passback{$possible}})) {
7066:an-25): my ($linkuri,$linkprotector,$scope) = split(/\0/,$launcher);
7067:an-25): if ($scope eq 'rec') {
7068:an-25): $possmappb{$launcher} = 1;
7069:an-25): $use_symbs_in_map = 1;
7070:an-25): $launch_to_symb{$launcher} = $possible;
7071:an-25): }
7072:an-25): }
7073:an-25): } elsif (grep(/^\Q$possible$\E$/,@updates)) {
7074:an-25): foreach my $launcher (keys(%{$passback{$possible}})) {
7075:an-25): $possrespb{$launcher} = 1;
7076:an-25): $launch_to_symb{$launcher} = $possible;
7077:an-25): }
7078:an-25): $uniqsymbs{$possible} = 1;
7079:an-25): }
7080:an-25): }
7081:an-25): }
7082:an-25): }
7083:an-25): if ($use_symbs_in_map) {
7084:an-25): map { $uniqsymbs{$_} = 1; } @symbs_in_map;
7085:an-25): }
7086:an-25): my @posslaunchers;
7087:an-25): if (keys(%possmappb)) {
7088:an-25): push(@posslaunchers,keys(%possmappb));
7089:an-25): }
7090:an-25): if (keys(%possrespb)) {
7091:an-25): push(@posslaunchers,keys(%possrespb));
7092:an-25): }
7093:an-25): if (@posslaunchers) {
7094:an-25): my (%pbsave,%skip_passback,%needpb);
7095:an-25): my %pbids = &Apache::lonnet::get('nohist_'.$cdom.'_'.$cnum.'_linkprot_pb',\@posslaunchers,$udom,$uname);
7096:an-25): foreach my $key (keys(%pbids)) {
7097:an-25): if (ref($pbids{$key}) eq 'ARRAY') {
7098:an-25): if ($launch_to_symb{$key}) {
7099:an-25): $needpb{$key} = $launch_to_symb{$key};
7100:an-25): }
7101:an-25): }
7102:an-25): }
7103:an-25): my @symbs = keys(%uniqsymbs);
7104:an-25): &process_passbacks('updatebypage',\@symbs,$cdom,$cnum,$udom,$uname,$usec,\%weights,
7105:an-25): \%awardeds,\%excuseds,\%needpb,\%skip_passback,\%pbsave,\%pbids);
7106:an-25): if (@Apache::grades::ltipassback) {
7107:an-25): unless ($registered_cleanup) {
7108:an-25): my $handlers = $request->get_handlers('PerlCleanupHandler');
7109:an-25): $request->set_handlers('PerlCleanupHandler' =>
7110:an-25): [\&Apache::grades::make_passback,@{$handlers}]);
7111:an-25): $registered_cleanup=1;
7112:an-25): }
7113:an-25): }
7114:an-25): }
7115:an-25): }
1.70 ng 7116: return '';
7117: }
7118:
1.596.2.12.2. 0.2.7(ra 7119:an-25): sub make_passback {
7120:an-25): if (@Apache::grades::ltipassback) {
7121:an-25): my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
7122:an-25): my $ip = &Apache::lonnet::get_host_ip($lonhost);
7123:an-25): foreach my $item (@Apache::grades::ltipassback) {
7124:an-25): &Apache::lonhomework::run_passback($item,$lonhost,$ip);
7125:an-25): }
7126:an-25): undef(@Apache::grades::ltipassback);
7127:an-25): }
7128:an-25): }
7129:an-25):
1.72 ng 7130: #-------- end of section for handling grading by page/sequence ---------
7131: #
7132: #-------------------------------------------------------------------
7133:
1.581 www 7134: #-------------------- Bubblesheet (Scantron) Grading -------------------
1.75 albertel 7135: #
7136: #------ start of section for handling grading by page/sequence ---------
7137:
1.423 albertel 7138: =pod
7139:
7140: =head1 Bubble sheet grading routines
7141:
1.424 albertel 7142: For this documentation:
7143:
7144: 'scanline' refers to the full line of characters
7145: from the file that we are parsing that represents one entire sheet
7146:
7147: 'bubble line' refers to the data
1.596.2.6 raeburn 7148: representing the line of bubbles that are on the physical bubblesheet
1.424 albertel 7149:
7150:
1.596.2.6 raeburn 7151: The overall process is that a scanned in bubblesheet data is uploaded
1.424 albertel 7152: into a course. When a user wants to grade, they select a
1.596.2.6 raeburn 7153: sequence/folder of resources, a file of bubblesheet info, and pick
1.424 albertel 7154: one of the predefined configurations for what each scanline looks
7155: like.
7156:
7157: Next each scanline is checked for any errors of either 'missing
1.435 foxr 7158: bubbles' (it's an error because it may have been mis-scanned
1.424 albertel 7159: because too light bubbling), 'double bubble' (each bubble line should
1.596.2.12.2. 0(raebur 7160:3): have no more than one letter picked), invalid or duplicated CODE,
1.556 weissno 7161: invalid student/employee ID
1.424 albertel 7162:
7163: If the CODE option is used that determines the randomization of the
1.556 weissno 7164: homework problems, either way the student/employee ID is looked up into a
1.424 albertel 7165: username:domain.
7166:
7167: During the validation phase the instructor can choose to skip scanlines.
7168:
1.596.2.6 raeburn 7169: After the validation phase, there are now 3 bubblesheet files
1.424 albertel 7170:
7171: scantron_original_filename (unmodified original file)
7172: scantron_corrected_filename (file where the corrected information has replaced the original information)
7173: scantron_skipped_filename (contains the exact text of scanlines that where skipped)
7174:
7175: Also there is a separate hash nohist_scantrondata that contains extra
1.596.2.6 raeburn 7176: correction information that isn't representable in the bubblesheet
1.424 albertel 7177: file (see &scantron_getfile() for more information)
7178:
7179: After all scanlines are either valid, marked as valid or skipped, then
7180: foreach line foreach problem in the picked sequence, an ssi request is
7181: made that simulates a user submitting their selected letter(s) against
7182: the homework problem.
1.423 albertel 7183:
7184: =over 4
7185:
7186:
7187:
7188: =item defaultFormData
7189:
7190: Returns html hidden inputs used to hold context/default values.
7191:
7192: Arguments:
7193: $symb - $symb of the current resource
7194:
7195: =cut
1.422 foxr 7196:
1.81 albertel 7197: sub defaultFormData {
1.324 albertel 7198: my ($symb)=@_;
1.596.2.12.2. 1(raebur 7199:0): return '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />';
1.81 albertel 7200: }
7201:
1.447 foxr 7202:
1.423 albertel 7203: =pod
7204:
7205: =item getSequenceDropDown
7206:
7207: Return html dropdown of possible sequences to grade
7208:
7209: Arguments:
1.582 raeburn 7210: $symb - $symb of the current resource
7211: $map_error - ref to scalar which will container error if
7212: $navmap object is unavailable in &getSymbMap().
1.423 albertel 7213:
7214: =cut
1.422 foxr 7215:
1.75 albertel 7216: sub getSequenceDropDown {
1.582 raeburn 7217: my ($symb,$map_error)=@_;
1.75 albertel 7218: my $result='<select name="selectpage">'."\n";
1.582 raeburn 7219: my ($titles,$symbx) = &getSymbMap($map_error);
7220: if (ref($map_error)) {
7221: return if ($$map_error);
7222: }
1.137 albertel 7223: my ($curpage)=&Apache::lonnet::decode_symb($symb);
1.75 albertel 7224: my $ctr=0;
7225: foreach (@$titles) {
7226: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
7227: $result.='<option value="'.$$symbx{$_}.'" '.
1.401 albertel 7228: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.75 albertel 7229: '>'.$showtitle.'</option>'."\n";
7230: $ctr++;
7231: }
7232: $result.= '</select>';
7233: return $result;
7234: }
7235:
1.495 albertel 7236: my %bubble_lines_per_response; # no. bubble lines for each response.
1.554 raeburn 7237: # key is zero-based index - 0, 1, 2 ...
1.495 albertel 7238:
7239: my %first_bubble_line; # First bubble line no. for each bubble.
7240:
1.509 raeburn 7241: my %subdivided_bubble_lines; # no. bubble lines for optionresponse,
7242: # matchresponse or rankresponse, where
7243: # an individual response can have multiple
7244: # lines
1.503 raeburn 7245:
7246: my %responsetype_per_response; # responsetype for each response
7247:
1.596.2.12.2. 6(raebur 7248:3): my %masterseq_id_responsenum; # src_id (e.g., 12.3_0.11 etc.) for each
7249:3): # numbered response. Needed when randomorder
7250:3): # or randompick are in use. Key is ID, value
7251:3): # is response number.
7252:3):
1.495 albertel 7253: # Save and restore the bubble lines array to the form env.
7254:
7255:
7256: sub save_bubble_lines {
7257: foreach my $line (keys(%bubble_lines_per_response)) {
7258: $env{"form.scantron.bubblelines.$line"} = $bubble_lines_per_response{$line};
7259: $env{"form.scantron.first_bubble_line.$line"} =
7260: $first_bubble_line{$line};
1.503 raeburn 7261: $env{"form.scantron.sub_bubblelines.$line"} =
7262: $subdivided_bubble_lines{$line};
7263: $env{"form.scantron.responsetype.$line"} =
7264: $responsetype_per_response{$line};
1.495 albertel 7265: }
1.596.2.12.2. 6(raebur 7266:3): foreach my $resid (keys(%masterseq_id_responsenum)) {
7267:3): my $line = $masterseq_id_responsenum{$resid};
7268:3): $env{"form.scantron.residpart.$line"} = $resid;
7269:3): }
1.495 albertel 7270: }
7271:
7272:
7273: sub restore_bubble_lines {
7274: my $line = 0;
7275: %bubble_lines_per_response = ();
1.596.2.12.2. 6(raebur 7276:3): %masterseq_id_responsenum = ();
1.495 albertel 7277: while ($env{"form.scantron.bubblelines.$line"}) {
7278: my $value = $env{"form.scantron.bubblelines.$line"};
7279: $bubble_lines_per_response{$line} = $value;
7280: $first_bubble_line{$line} =
7281: $env{"form.scantron.first_bubble_line.$line"};
1.503 raeburn 7282: $subdivided_bubble_lines{$line} =
7283: $env{"form.scantron.sub_bubblelines.$line"};
7284: $responsetype_per_response{$line} =
7285: $env{"form.scantron.responsetype.$line"};
1.596.2.12.2. 6(raebur 7286:3): my $id = $env{"form.scantron.residpart.$line"};
7287:3): $masterseq_id_responsenum{$id} = $line;
1.495 albertel 7288: $line++;
7289: }
7290: }
7291:
1.423 albertel 7292: =pod
7293:
7294: =item scantron_filenames
7295:
7296: Returns a list of the scantron files in the current course
7297:
7298: =cut
1.422 foxr 7299:
1.202 albertel 7300: sub scantron_filenames {
1.257 albertel 7301: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7302: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
1.517 raeburn 7303: my $getpropath = 1;
1.596.2.12.2. (raeburn 7304:): my ($dirlist,$listerror) = &Apache::lonnet::dirlist('userfiles',$cdom,
7305:): $cname,$getpropath);
1.202 albertel 7306: my @possiblenames;
1.596.2.12.2. (raeburn 7307:): if (ref($dirlist) eq 'ARRAY') {
7308:): foreach my $filename (sort(@{$dirlist})) {
7309:): ($filename)=split(/&/,$filename);
7310:): if ($filename!~/^scantron_orig_/) { next ; }
7311:): $filename=~s/^scantron_orig_//;
7312:): push(@possiblenames,$filename);
7313:): }
1.202 albertel 7314: }
7315: return @possiblenames;
7316: }
7317:
1.423 albertel 7318: =pod
7319:
7320: =item scantron_uploads
7321:
7322: Returns html drop-down list of scantron files in current course.
7323:
7324: Arguments:
7325: $file2grade - filename to set as selected in the dropdown
7326:
7327: =cut
1.422 foxr 7328:
1.202 albertel 7329: sub scantron_uploads {
1.209 ng 7330: my ($file2grade) = @_;
1.202 albertel 7331: my $result= '<select name="scantron_selectfile">';
7332: $result.="<option></option>";
7333: foreach my $filename (sort(&scantron_filenames())) {
1.401 albertel 7334: $result.="<option".($filename eq $file2grade ? ' selected="selected"':'').">$filename</option>\n";
1.81 albertel 7335: }
7336: $result.="</select>";
7337: return $result;
7338: }
7339:
1.423 albertel 7340: =pod
7341:
7342: =item scantron_scantab
7343:
7344: Returns html drop down of the scantron formats in the scantronformat.tab
7345: file.
7346:
7347: =cut
1.422 foxr 7348:
1.82 albertel 7349: sub scantron_scantab {
7350: my $result='<select name="scantron_format">'."\n";
1.191 albertel 7351: $result.='<option></option>'."\n";
1.596.2.12.2. 9(raebur 7352:9): my @lines = &Apache::lonnet::get_scantronformat_file();
1.518 raeburn 7353: if (@lines > 0) {
7354: foreach my $line (@lines) {
7355: next if (($line =~ /^\#/) || ($line eq ''));
7356: my ($name,$descrip)=split(/:/,$line);
7357: $result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
7358: }
1.82 albertel 7359: }
7360: $result.='</select>'."\n";
1.518 raeburn 7361: return $result;
7362: }
7363:
1.423 albertel 7364: =pod
7365:
7366: =item scantron_CODElist
7367:
7368: Returns html drop down of the saved CODE lists from current course,
7369: generated from earlier printings.
7370:
7371: =cut
1.422 foxr 7372:
1.186 albertel 7373: sub scantron_CODElist {
1.257 albertel 7374: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7375: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.186 albertel 7376: my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
7377: my $namechoice='<option></option>';
1.225 albertel 7378: foreach my $name (sort {uc($a) cmp uc($b)} @names) {
1.191 albertel 7379: if ($name =~ /^error: 2 /) { next; }
1.278 albertel 7380: if ($name =~ /^type\0/) { next; }
1.186 albertel 7381: $namechoice.='<option value="'.$name.'">'.$name.'</option>';
7382: }
7383: $namechoice='<select name="scantron_CODElist">'.$namechoice.'</select>';
7384: return $namechoice;
7385: }
7386:
1.423 albertel 7387: =pod
7388:
7389: =item scantron_CODEunique
7390:
7391: Returns the html for "Each CODE to be used once" radio.
7392:
7393: =cut
1.422 foxr 7394:
1.186 albertel 7395: sub scantron_CODEunique {
1.532 bisitz 7396: my $result='<span class="LC_nobreak">
1.272 albertel 7397: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 7398: value="yes" checked="checked" />'.&mt('Yes').' </label>
1.381 albertel 7399: </span>
1.532 bisitz 7400: <span class="LC_nobreak">
1.272 albertel 7401: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 7402: value="no" />'.&mt('No').' </label>
1.381 albertel 7403: </span>';
1.186 albertel 7404: return $result;
7405: }
1.423 albertel 7406:
7407: =pod
7408:
7409: =item scantron_selectphase
7410:
1.596.2.6 raeburn 7411: Generates the initial screen to start the bubblesheet process.
1.423 albertel 7412: Allows for - starting a grading run.
1.424 albertel 7413: - downloading existing scan data (original, corrected
1.423 albertel 7414: or skipped info)
7415:
7416: - uploading new scan data
7417:
7418: Arguments:
7419: $r - The Apache request object
7420: $file2grade - name of the file that contain the scanned data to score
7421:
7422: =cut
1.186 albertel 7423:
1.75 albertel 7424: sub scantron_selectphase {
1.596.2.12.2. 1(raebur 7425:0): my ($r,$file2grade,$symb) = @_;
1.75 albertel 7426: if (!$symb) {return '';}
1.582 raeburn 7427: my $map_error;
7428: my $sequence_selector=&getSequenceDropDown($symb,\$map_error);
7429: if ($map_error) {
7430: $r->print('<br />'.&navmap_errormsg().'<br />');
7431: return;
7432: }
1.324 albertel 7433: my $default_form_data=&defaultFormData($symb);
1.209 ng 7434: my $file_selector=&scantron_uploads($file2grade);
1.82 albertel 7435: my $format_selector=&scantron_scantab();
1.186 albertel 7436: my $CODE_selector=&scantron_CODElist();
7437: my $CODE_unique=&scantron_CODEunique();
1.75 albertel 7438: my $result;
1.422 foxr 7439:
1.513 foxr 7440: $ssi_error = 0;
7441:
1.596.2.4 raeburn 7442: if (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) ||
7443: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
7444:
7445: # Chunk of form to prompt for a scantron file upload.
7446:
7447: $r->print('
1.596.2.12.2. 9(raebur 7448:9): <br />');
7449:9): my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
7450:9): my $cnum= $env{'course.'.$env{'request.course.id'}.'.num'};
7451:9): my $alertmsg = &mt('Please use the browse button to select a file from your local directory.');
7452:9): &js_escape(\$alertmsg);
7453:9): my ($formatoptions,$formattitle,$formatjs) = &scantron_upload_dataformat($cdom);
7454:9): $r->print(&Apache::lonhtmlcommon::scripttag('
1.596.2.4 raeburn 7455: function checkUpload(formname) {
7456: if (formname.upfile.value == "") {
1.596.2.12.2. 6(raebur 7457:6): alert("'.$alertmsg.'");
1.596.2.4 raeburn 7458: return false;
7459: }
7460: formname.submit();
1.596.2.12.2. 9(raebur 7461:9): }'."\n".$formatjs));
7462:9): $r->print('
1.596.2.4 raeburn 7463: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
7464: '.$default_form_data.'
7465: <input name="courseid" type="hidden" value="'.$cnum.'" />
7466: <input name="domainid" type="hidden" value="'.$cdom.'" />
7467: <input name="command" value="scantronupload_save" type="hidden" />
1.596.2.12.2. 9(raebur 7468:9): '.&Apache::loncommon::start_data_table('LC_scantron_action').'
7469:9): '.&Apache::loncommon::start_data_table_header_row().'
7470:9): <th>
7471:9): '.&mt('Specify a bubblesheet data file to upload.').'
7472:9): </th>
7473:9): '.&Apache::loncommon::end_data_table_header_row().'
7474:9): '.&Apache::loncommon::start_data_table_row().'
7475:9): <td>
7476:9): '.&mt('File to upload: [_1]','<input type="file" name="upfile" size="50" />').'<br />'."\n");
7477:9): if ($formatoptions) {
7478:9): $r->print('</td>
7479:9): '.&Apache::loncommon::end_data_table_row().'
7480:9): '.&Apache::loncommon::start_data_table_row().'
7481:9): <td>'.$formattitle.(' 'x2).$formatoptions.'
7482:9): </td>
7483:9): '.&Apache::loncommon::end_data_table_row().'
7484:9): '.&Apache::loncommon::start_data_table_row().'
7485:9): <td>'
7486:9): );
7487:9): } else {
7488:9): $r->print(' <br />');
7489:9): }
7490:9): $r->print('<input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
7491:9): </td>
7492:9): '.&Apache::loncommon::end_data_table_row().'
7493:9): '.&Apache::loncommon::end_data_table().'
7494:9): </form>'
7495:9): );
1.596.2.4 raeburn 7496:
7497: }
7498:
1.422 foxr 7499: # Chunk of form to prompt for a file to grade and how:
7500:
1.489 albertel 7501: $result.= '
7502: <br />
7503: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantron_process">
7504: <input type="hidden" name="command" value="scantron_warning" />
7505: '.$default_form_data.'
7506: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
7507: '.&Apache::loncommon::start_data_table_header_row().'
7508: <th colspan="2">
1.492 albertel 7509: '.&mt('Specify file and which Folder/Sequence to grade').'
1.489 albertel 7510: </th>
7511: '.&Apache::loncommon::end_data_table_header_row().'
7512: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 7513: <td> '.&mt('Sequence to grade:').' </td><td> '.$sequence_selector.' </td>
1.489 albertel 7514: '.&Apache::loncommon::end_data_table_row().'
7515: '.&Apache::loncommon::start_data_table_row().'
1.572 www 7516: <td> '.&mt('Filename of bubblesheet data file:').' </td><td> '.$file_selector.' </td>
1.489 albertel 7517: '.&Apache::loncommon::end_data_table_row().'
7518: '.&Apache::loncommon::start_data_table_row().'
1.572 www 7519: <td> '.&mt('Format of bubblesheet data file:').' </td><td> '.$format_selector.' </td>
1.489 albertel 7520: '.&Apache::loncommon::end_data_table_row().'
7521: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 7522: <td> '.&mt('Saved CODEs to validate against:').' </td><td> '.$CODE_selector.' </td>
1.489 albertel 7523: '.&Apache::loncommon::end_data_table_row().'
7524: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 7525: <td> '.&mt('Each CODE is only to be used once:').'</td><td> '.$CODE_unique.' </td>
1.489 albertel 7526: '.&Apache::loncommon::end_data_table_row().'
7527: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 7528: <td> '.&mt('Options:').' </td>
1.187 albertel 7529: <td>
1.492 albertel 7530: <label><input type="checkbox" name="scantron_options_redo" value="redo_skipped"/> '.&mt('Do only previously skipped records').'</label> <br />
7531: <label><input type="checkbox" name="scantron_options_ignore" value="ignore_corrections"/> '.&mt('Remove all existing corrections').'</label> <br />
7532: <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources when grading').'</label>
1.187 albertel 7533: </td>
1.489 albertel 7534: '.&Apache::loncommon::end_data_table_row().'
7535: '.&Apache::loncommon::start_data_table_row().'
1.174 albertel 7536: <td colspan="2">
1.572 www 7537: <input type="submit" value="'.&mt('Grading: Validate Bubblesheet Records').'" />
1.162 albertel 7538: </td>
1.489 albertel 7539: '.&Apache::loncommon::end_data_table_row().'
7540: '.&Apache::loncommon::end_data_table().'
7541: </form>
7542: ';
1.162 albertel 7543:
7544: $r->print($result);
7545:
1.422 foxr 7546: # Chunk of the form that prompts to view a scoring office file,
7547: # corrected file, skipped records in a file.
7548:
1.489 albertel 7549: $r->print('
7550: <br />
7551: <form action="/adm/grades" name="scantron_download">
7552: '.$default_form_data.'
7553: <input type="hidden" name="command" value="scantron_download" />
7554: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
7555: '.&Apache::loncommon::start_data_table_header_row().'
7556: <th>
1.492 albertel 7557: '.&mt('Download a scoring office file').'
1.489 albertel 7558: </th>
7559: '.&Apache::loncommon::end_data_table_header_row().'
7560: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 7561: <td> '.&mt('Filename of scoring office file: [_1]',$file_selector).'
1.489 albertel 7562: <br />
1.492 albertel 7563: <input type="submit" value="'.&mt('Download: Show List of Associated Files').'" />
1.489 albertel 7564: '.&Apache::loncommon::end_data_table_row().'
7565: '.&Apache::loncommon::end_data_table().'
7566: </form>
7567: <br />
7568: ');
1.162 albertel 7569:
1.457 banghart 7570: &Apache::lonpickcode::code_list($r,2);
1.523 raeburn 7571:
1.596.2.12.2. 8(raebur 7572:3): $r->print('<br /><form method="post" name="checkscantron" action="">'.
1.523 raeburn 7573: $default_form_data."\n".
7574: &Apache::loncommon::start_data_table('LC_scantron_action')."\n".
7575: &Apache::loncommon::start_data_table_header_row()."\n".
7576: '<th colspan="2">
1.572 www 7577: '.&mt('Review bubblesheet data and submissions for a previously graded folder/sequence')."\n".
1.523 raeburn 7578: '</th>'."\n".
7579: &Apache::loncommon::end_data_table_header_row()."\n".
7580: &Apache::loncommon::start_data_table_row()."\n".
7581: '<td> '.&mt('Graded folder/sequence:').' </td>'."\n".
7582: '<td> '.$sequence_selector.' </td>'.
7583: &Apache::loncommon::end_data_table_row()."\n".
7584: &Apache::loncommon::start_data_table_row()."\n".
7585: '<td> '.&mt('Filename of scoring office file:').' </td>'."\n".
7586: '<td> '.$file_selector.' </td>'."\n".
7587: &Apache::loncommon::end_data_table_row()."\n".
7588: &Apache::loncommon::start_data_table_row()."\n".
7589: '<td> '.&mt('Format of data file:').' </td>'."\n".
7590: '<td> '.$format_selector.' </td>'."\n".
7591: &Apache::loncommon::end_data_table_row()."\n".
7592: &Apache::loncommon::start_data_table_row()."\n".
1.557 raeburn 7593: '<td> '.&mt('Options').' </td>'."\n".
7594: '<td> <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources').'</label></td>'.
7595: &Apache::loncommon::end_data_table_row()."\n".
7596: &Apache::loncommon::start_data_table_row()."\n".
1.523 raeburn 7597: '<td colspan="2">'."\n".
7598: '<input type="hidden" name="command" value="checksubmissions" />'."\n".
1.575 www 7599: '<input type="submit" value="'.&mt('Review Bubblesheet Data and Submission Records').'" />'."\n".
1.523 raeburn 7600: '</td>'."\n".
7601: &Apache::loncommon::end_data_table_row()."\n".
7602: &Apache::loncommon::end_data_table()."\n".
7603: '</form><br />');
7604: return;
1.75 albertel 7605: }
7606:
1.423 albertel 7607: =pod
7608:
7609: =item username_to_idmap
7610:
1.556 weissno 7611: creates a hash keyed by student/employee ID with values of the corresponding
1.423 albertel 7612: student username:domain.
7613:
7614: Arguments:
7615:
7616: $classlist - reference to the class list hash. This is a hash
7617: keyed by student name:domain whose elements are references
1.424 albertel 7618: to arrays containing various chunks of information
1.423 albertel 7619: about the student. (See loncoursedata for more info).
7620:
7621: Returns
7622: %idmap - the constructed hash
7623:
7624: =cut
7625:
1.82 albertel 7626: sub username_to_idmap {
7627: my ($classlist)= @_;
7628: my %idmap;
7629: foreach my $student (keys(%$classlist)) {
1.596.2.12.2. 3(raebur 7630:5): my $id = $classlist->{$student}->[&Apache::loncoursedata::CL_ID];
7631:5): unless ($id eq '') {
7632:5): if (!exists($idmap{$id})) {
7633:5): $idmap{$id} = $student;
7634:5): } else {
7635:5): my $status = $classlist->{$student}->[&Apache::loncoursedata::CL_STATUS];
7636:5): if ($status eq 'Active') {
7637:5): $idmap{$id} = $student;
7638:5): }
7639:5): }
7640:5): }
1.82 albertel 7641: }
7642: return %idmap;
7643: }
1.423 albertel 7644:
7645: =pod
7646:
1.424 albertel 7647: =item scantron_fixup_scanline
1.423 albertel 7648:
7649: Process a requested correction to a scanline.
7650:
7651: Arguments:
1.596.2.12.2. 9(raebur 7652:9): $scantron_config - hash from &Apache::lonnet::get_scantron_config()
1.423 albertel 7653: $scan_data - hash of correction information
7654: (see &scantron_getfile())
7655: $line - existing scanline
7656: $whichline - line number of the passed in scanline
7657: $field - type of change to process
7658: (either
1.573 bisitz 7659: 'ID' -> correct the student/employee ID
1.423 albertel 7660: 'CODE' -> correct the CODE
7661: 'answer' -> fixup the submitted answers)
7662:
7663: $args - hash of additional info,
7664: - 'ID'
7665: 'newid' -> studentID to use in replacement
1.424 albertel 7666: of existing one
1.423 albertel 7667: - 'CODE'
7668: 'CODE_ignore_dup' - set to true if duplicates
7669: should be ignored.
7670: 'CODE' - is new code or 'use_unfound'
1.424 albertel 7671: if the existing unfound code should
1.423 albertel 7672: be used as is
7673: - 'answer'
7674: 'response' - new answer or 'none' if blank
7675: 'question' - the bubble line to change
1.503 raeburn 7676: 'questionnum' - the question identifier,
7677: may include subquestion.
1.423 albertel 7678:
7679: Returns:
7680: $line - the modified scanline
7681:
7682: Side effects:
7683: $scan_data - may be updated
7684:
7685: =cut
7686:
1.82 albertel 7687:
1.157 albertel 7688: sub scantron_fixup_scanline {
7689: my ($scantron_config,$scan_data,$line,$whichline,$field,$args)=@_;
7690: if ($field eq 'ID') {
7691: if (length($args->{'newid'}) > $$scantron_config{'IDlength'}) {
1.186 albertel 7692: return ($line,1,'New value too large');
1.157 albertel 7693: }
7694: if (length($args->{'newid'}) < $$scantron_config{'IDlength'}) {
7695: $args->{'newid'}=sprintf('%-'.$$scantron_config{'IDlength'}.'s',
7696: $args->{'newid'});
7697: }
7698: substr($line,$$scantron_config{'IDstart'}-1,
7699: $$scantron_config{'IDlength'})=$args->{'newid'};
7700: if ($args->{'newid'}=~/^\s*$/) {
7701: &scan_data($scan_data,"$whichline.user",
7702: $args->{'username'}.':'.$args->{'domain'});
7703: }
1.186 albertel 7704: } elsif ($field eq 'CODE') {
1.192 albertel 7705: if ($args->{'CODE_ignore_dup'}) {
7706: &scan_data($scan_data,"$whichline.CODE_ignore_dup",'1');
7707: }
7708: &scan_data($scan_data,"$whichline.useCODE",'1');
7709: if ($args->{'CODE'} ne 'use_unfound') {
1.191 albertel 7710: if (length($args->{'CODE'}) > $$scantron_config{'CODElength'}) {
7711: return ($line,1,'New CODE value too large');
7712: }
7713: if (length($args->{'CODE'}) < $$scantron_config{'CODElength'}) {
7714: $args->{'CODE'}=sprintf('%-'.$$scantron_config{'CODElength'}.'s',$args->{'CODE'});
7715: }
7716: substr($line,$$scantron_config{'CODEstart'}-1,
7717: $$scantron_config{'CODElength'})=$args->{'CODE'};
1.186 albertel 7718: }
1.157 albertel 7719: } elsif ($field eq 'answer') {
1.497 foxr 7720: my $length=$scantron_config->{'Qlength'};
1.157 albertel 7721: my $off=$scantron_config->{'Qoff'};
7722: my $on=$scantron_config->{'Qon'};
1.497 foxr 7723: my $answer=${off}x$length;
7724: if ($args->{'response'} eq 'none') {
7725: &scan_data($scan_data,
1.503 raeburn 7726: "$whichline.no_bubble.".$args->{'questionnum'},'1');
1.497 foxr 7727: } else {
7728: if ($on eq 'letter') {
7729: my @alphabet=('A'..'Z');
7730: $answer=$alphabet[$args->{'response'}];
7731: } elsif ($on eq 'number') {
7732: $answer=$args->{'response'}+1;
7733: if ($answer == 10) { $answer = '0'; }
1.274 albertel 7734: } else {
1.497 foxr 7735: substr($answer,$args->{'response'},1)=$on;
1.274 albertel 7736: }
1.497 foxr 7737: &scan_data($scan_data,
1.503 raeburn 7738: "$whichline.no_bubble.".$args->{'questionnum'},undef,'1');
1.157 albertel 7739: }
1.497 foxr 7740: my $where=$length*($args->{'question'}-1)+$scantron_config->{'Qstart'};
7741: substr($line,$where-1,$length)=$answer;
1.157 albertel 7742: }
7743: return $line;
7744: }
1.423 albertel 7745:
7746: =pod
7747:
7748: =item scan_data
7749:
7750: Edit or look up an item in the scan_data hash.
7751:
7752: Arguments:
7753: $scan_data - The hash (see scantron_getfile)
7754: $key - shorthand of the key to edit (actual key is
1.424 albertel 7755: scantronfilename_key).
1.423 albertel 7756: $data - New value of the hash entry.
7757: $delete - If true, the entry is removed from the hash.
7758:
7759: Returns:
7760: The new value of the hash table field (undefined if deleted).
7761:
7762: =cut
7763:
7764:
1.157 albertel 7765: sub scan_data {
7766: my ($scan_data,$key,$value,$delete)=@_;
1.257 albertel 7767: my $filename=$env{'form.scantron_selectfile'};
1.157 albertel 7768: if (defined($value)) {
7769: $scan_data->{$filename.'_'.$key} = $value;
7770: }
7771: if ($delete) { delete($scan_data->{$filename.'_'.$key}); }
7772: return $scan_data->{$filename.'_'.$key};
7773: }
1.423 albertel 7774:
1.495 albertel 7775: # ----- These first few routines are general use routines.----
7776:
7777: # Return the number of occurences of a pattern in a string.
7778:
7779: sub occurence_count {
7780: my ($string, $pattern) = @_;
7781:
7782: my @matches = ($string =~ /$pattern/g);
7783:
7784: return scalar(@matches);
7785: }
7786:
7787:
7788: # Take a string known to have digits and convert all the
7789: # digits into letters in the range J,A..I.
7790:
7791: sub digits_to_letters {
7792: my ($input) = @_;
7793:
7794: my @alphabet = ('J', 'A'..'I');
7795:
7796: my @input = split(//, $input);
7797: my $output ='';
7798: for (my $i = 0; $i < scalar(@input); $i++) {
7799: if ($input[$i] =~ /\d/) {
7800: $output .= $alphabet[$input[$i]];
7801: } else {
7802: $output .= $input[$i];
7803: }
7804: }
7805: return $output;
7806: }
7807:
1.423 albertel 7808: =pod
7809:
7810: =item scantron_parse_scanline
7811:
7812: Decodes a scanline from the selected scantron file
7813:
7814: Arguments:
7815: line - The text of the scantron file line to process
7816: whichline - Line number
7817: scantron_config - Hash describing the format of the scantron lines.
7818: scan_data - Hash of extra information about the scanline
7819: (see scantron_getfile for more information)
7820: just_header - True if should not process question answers but only
7821: the stuff to the left of the answers.
1.596.2.12.2. 6(raebur 7822:3): randomorder - True if randomorder in use
7823:3): randompick - True if randompick in use
7824:3): sequence - Exam folder URL
7825:3): master_seq - Ref to array containing symbs in exam folder
7826:3): symb_to_resource - Ref to hash of symbs for resources in exam folder
7827:3): (corresponding values are resource objects)
7828:3): partids_by_symb - Ref to hash of symb -> array ref of partIDs
7829:3): orderedforcode - Ref to hash of arrays. keys are CODEs and values
7830:3): are refs to an array of resource objects, ordered
7831:3): according to order used for CODE, when randomorder
7832:3): and or randompick are in use.
7833:3): respnumlookup - Ref to hash mapping question numbers in bubble lines
7834:3): for current line to question number used for same question
7835:3): in "Master Sequence" (as seen by Course Coordinator).
7836:3): startline - Ref to hash where key is question number (0 is first)
7837:3): and value is number of first bubble line for current
7838:3): student or code-based randompick and/or randomorder.
7839:3): totalref - Ref of scalar used to score total number of bubble
7840:3): lines needed for responses in a scan line (used when
7841:3): randompick in use.
7842:3):
1.423 albertel 7843: Returns:
7844: Hash containing the result of parsing the scanline
7845:
7846: Keys are all proceeded by the string 'scantron.'
7847:
7848: CODE - the CODE in use for this scanline
7849: useCODE - 1 if the CODE is invalid but it usage has been forced
7850: by the operator
7851: CODE_ignore_dup - 1 if the CODE is a duplicated use when unique
7852: CODEs were selected, but the usage has been
7853: forced by the operator
1.556 weissno 7854: ID - student/employee ID
1.423 albertel 7855: PaperID - if used, the ID number printed on the sheet when the
7856: paper was scanned
7857: FirstName - first name from the sheet
7858: LastName - last name from the sheet
7859:
7860: if just_header was not true these key may also exist
7861:
1.447 foxr 7862: missingerror - a list of bubble ranges that are considered to be answers
7863: to a single question that don't have any bubbles filled in.
7864: Of the form questionnumber:firstbubblenumber:count.
7865: doubleerror - a list of bubble ranges that are considered to be answers
7866: to a single question that have more than one bubble filled in.
7867: Of the form questionnumber::firstbubblenumber:count
7868:
7869: In the above, count is the number of bubble responses in the
7870: input line needed to represent the possible answers to the question.
7871: e.g. a radioresponse with 15 choices in an answer sheet with 10 choices
7872: per line would have count = 2.
7873:
1.423 albertel 7874: maxquest - the number of the last bubble line that was parsed
7875:
7876: (<number> starts at 1)
7877: <number>.answer - zero or more letters representing the selected
7878: letters from the scanline for the bubble line
7879: <number>.
7880: if blank there was either no bubble or there where
7881: multiple bubbles, (consult the keys missingerror and
7882: doubleerror if this is an error condition)
7883:
7884: =cut
7885:
1.82 albertel 7886: sub scantron_parse_scanline {
1.596.2.12.2. 6(raebur 7887:3): my ($line,$whichline,$scantron_config,$scan_data,$just_header,$idmap,
7888:3): $randomorder,$randompick,$sequence,$master_seq,$symb_to_resource,
7889:3): $partids_by_symb,$orderedforcode,$respnumlookup,$startline,$totalref)=@_;
1.470 foxr 7890:
1.82 albertel 7891: my %record;
1.596.2.12.2. 6(raebur 7892:3): my $data=substr($line,0,$$scantron_config{'Qstart'}-1); # stuff before answers
1.278 albertel 7893: if (!($$scantron_config{'CODElocation'} eq 0 ||
7894: $$scantron_config{'CODElocation'} eq 'none')) {
7895: if ($$scantron_config{'CODElocation'} < 0 ||
7896: $$scantron_config{'CODElocation'} eq 'letter' ||
7897: $$scantron_config{'CODElocation'} eq 'number') {
1.191 albertel 7898: $record{'scantron.CODE'}=substr($data,
7899: $$scantron_config{'CODEstart'}-1,
1.83 albertel 7900: $$scantron_config{'CODElength'});
1.191 albertel 7901: if (&scan_data($scan_data,"$whichline.useCODE")) {
7902: $record{'scantron.useCODE'}=1;
7903: }
1.192 albertel 7904: if (&scan_data($scan_data,"$whichline.CODE_ignore_dup")) {
7905: $record{'scantron.CODE_ignore_dup'}=1;
7906: }
1.82 albertel 7907: } else {
7908: #FIXME interpret first N questions
7909: }
7910: }
1.83 albertel 7911: $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
7912: $$scantron_config{'IDlength'});
1.157 albertel 7913: $record{'scantron.PaperID'}=
7914: substr($data,$$scantron_config{'PaperID'}-1,
7915: $$scantron_config{'PaperIDlength'});
7916: $record{'scantron.FirstName'}=
7917: substr($data,$$scantron_config{'FirstName'}-1,
7918: $$scantron_config{'FirstNamelength'});
7919: $record{'scantron.LastName'}=
7920: substr($data,$$scantron_config{'LastName'}-1,
7921: $$scantron_config{'LastNamelength'});
1.423 albertel 7922: if ($just_header) { return \%record; }
1.194 albertel 7923:
1.82 albertel 7924: my @alphabet=('A'..'Z');
7925: my $questnum=0;
1.447 foxr 7926: my $ansnum =1; # Multiple 'answer lines'/question.
7927:
1.596.2.12.2. 6(raebur 7928:3): my $lastpos = $env{'form.scantron_maxbubble'}*$$scantron_config{'Qlength'};
7929:3): if ($randompick || $randomorder) {
7930:3): my $total = &get_respnum_lookups($sequence,$scan_data,$idmap,$line,\%record,
7931:3): $master_seq,$symb_to_resource,
7932:3): $partids_by_symb,$orderedforcode,
7933:3): $respnumlookup,$startline);
7934:3): if ($total) {
7935:3): $lastpos = $total*$$scantron_config{'Qlength'};
7936:3): }
7937:3): if (ref($totalref)) {
7938:3): $$totalref = $total;
7939:3): }
7940:3): }
7941:3): my $questions=substr($line,$$scantron_config{'Qstart'}-1,$lastpos); # Answers
1.470 foxr 7942: chomp($questions); # Get rid of any trailing \n.
7943: $questions =~ s/\r$//; # Get rid of trailing \r too (MAC or Win uploads).
7944: while (length($questions)) {
1.596.2.12.2. 6(raebur 7945:3): my $answers_needed;
7946:3): if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
7947:3): $answers_needed = $bubble_lines_per_response{$respnumlookup->{$questnum}};
7948:3): } else {
7949:3): $answers_needed = $bubble_lines_per_response{$questnum};
7950:3): }
1.503 raeburn 7951: my $answer_length = ($$scantron_config{'Qlength'} * $answers_needed)
7952: || 1;
7953: $questnum++;
7954: my $quest_id = $questnum;
7955: my $currentquest = substr($questions,0,$answer_length);
7956: $questions = substr($questions,$answer_length);
7957: if (length($currentquest) < $answer_length) { next; }
7958:
1.596.2.12.2. 6(raebur 7959:3): my $subdivided;
7960:3): if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
7961:3): $subdivided = $subdivided_bubble_lines{$respnumlookup->{$questnum-1}};
7962:3): } else {
7963:3): $subdivided = $subdivided_bubble_lines{$questnum-1};
7964:3): }
7965:3): if ($subdivided =~ /,/) {
1.503 raeburn 7966: my $subquestnum = 1;
7967: my $subquestions = $currentquest;
1.596.2.12.2. 6(raebur 7968:3): my @subanswers_needed = split(/,/,$subdivided);
1.503 raeburn 7969: foreach my $subans (@subanswers_needed) {
7970: my $subans_length =
7971: ($$scantron_config{'Qlength'} * $subans) || 1;
7972: my $currsubquest = substr($subquestions,0,$subans_length);
7973: $subquestions = substr($subquestions,$subans_length);
7974: $quest_id = "$questnum.$subquestnum";
7975: if (($$scantron_config{'Qon'} eq 'letter') ||
7976: ($$scantron_config{'Qon'} eq 'number')) {
7977: $ansnum = &scantron_validator_lettnum($ansnum,
7978: $questnum,$quest_id,$subans,$currsubquest,$whichline,
1.596.2.12.2. 6(raebur 7979:3): \@alphabet,\%record,$scantron_config,$scan_data,
7980:3): $randomorder,$randompick,$respnumlookup);
1.503 raeburn 7981: } else {
7982: $ansnum = &scantron_validator_positional($ansnum,
1.596.2.12.2. 6(raebur 7983:3): $questnum,$quest_id,$subans,$currsubquest,$whichline,
7984:3): \@alphabet,\%record,$scantron_config,$scan_data,
7985:3): $randomorder,$randompick,$respnumlookup);
1.503 raeburn 7986: }
7987: $subquestnum ++;
7988: }
7989: } else {
7990: if (($$scantron_config{'Qon'} eq 'letter') ||
7991: ($$scantron_config{'Qon'} eq 'number')) {
7992: $ansnum = &scantron_validator_lettnum($ansnum,$questnum,
7993: $quest_id,$answers_needed,$currentquest,$whichline,
1.596.2.12.2. 6(raebur 7994:3): \@alphabet,\%record,$scantron_config,$scan_data,
7995:3): $randomorder,$randompick,$respnumlookup);
1.503 raeburn 7996: } else {
7997: $ansnum = &scantron_validator_positional($ansnum,$questnum,
7998: $quest_id,$answers_needed,$currentquest,$whichline,
1.596.2.12.2. 6(raebur 7999:3): \@alphabet,\%record,$scantron_config,$scan_data,
8000:3): $randomorder,$randompick,$respnumlookup);
1.503 raeburn 8001: }
8002: }
8003: }
8004: $record{'scantron.maxquest'}=$questnum;
8005: return \%record;
8006: }
1.447 foxr 8007:
1.596.2.12.2. 6(raebur 8008:3): sub get_master_seq {
0(raebur 8009:2): my ($resources,$master_seq,$symb_to_resource,$need_symb_in_map,$symb_for_examcode) = @_;
6(raebur 8010:3): return unless ((ref($resources) eq 'ARRAY') && (ref($master_seq) eq 'ARRAY') &&
8011:3): (ref($symb_to_resource) eq 'HASH'));
0(raebur 8012:2): if ($need_symb_in_map) {
8013:2): return unless (ref($symb_for_examcode) eq 'HASH');
8014:2): }
6(raebur 8015:3): my $resource_error;
8016:3): foreach my $resource (@{$resources}) {
8017:3): my $ressymb;
8018:3): if (ref($resource)) {
8019:3): $ressymb = $resource->symb();
8020:3): push(@{$master_seq},$ressymb);
8021:3): $symb_to_resource->{$ressymb} = $resource;
0(raebur 8022:2): if ($need_symb_in_map) {
8023:2): unless ($resource->is_map()) {
8024:2): my $map=(&Apache::lonnet::decode_symb($ressymb))[0];
8025:2): unless (exists($symb_for_examcode->{$map})) {
8026:2): $symb_for_examcode->{$map} = $ressymb;
8027:2): }
8028:2): }
8029:2): }
6(raebur 8030:3): } else {
8031:3): $resource_error = 1;
8032:3): last;
8033:3): }
8034:3): }
8035:3): return $resource_error;
8036:3): }
8037:3):
8038:3): sub get_respnum_lookups {
8039:3): my ($sequence,$scan_data,$idmap,$line,$record,$master_seq,$symb_to_resource,
8040:3): $partids_by_symb,$orderedforcode,$respnumlookup,$startline) = @_;
8041:3): return unless ((ref($record) eq 'HASH') && (ref($master_seq) eq 'ARRAY') &&
8042:3): (ref($symb_to_resource) eq 'HASH') && (ref($partids_by_symb) eq 'HASH') &&
8043:3): (ref($orderedforcode) eq 'HASH') && (ref($respnumlookup) eq 'HASH') &&
8044:3): (ref($startline) eq 'HASH'));
8045:3): my ($user,$scancode);
8046:3): if ((exists($record->{'scantron.CODE'})) &&
8047:3): (&Apache::lonnet::validCODE($record->{'scantron.CODE'}))) {
8048:3): $scancode = $record->{'scantron.CODE'};
8049:3): } else {
8050:3): $user = &scantron_find_student($record,$scan_data,$idmap,$line);
8051:3): }
8052:3): my @mapresources =
8053:3): &users_order($user,$scancode,$sequence,$master_seq,$symb_to_resource,
8054:3): $orderedforcode);
8055:3): my $total = 0;
8056:3): my $count = 0;
8057:3): foreach my $resource (@mapresources) {
8058:3): my $id = $resource->id();
8059:3): my $symb = $resource->symb();
8060:3): if (ref($partids_by_symb->{$symb}) eq 'ARRAY') {
8061:3): foreach my $partid (@{$partids_by_symb->{$symb}}) {
8062:3): my $respnum = $masterseq_id_responsenum{$id.'_'.$partid};
8063:3): if ($respnum ne '') {
8064:3): $respnumlookup->{$count} = $respnum;
8065:3): $startline->{$count} = $total;
8066:3): $total += $bubble_lines_per_response{$respnum};
8067:3): $count ++;
8068:3): }
8069:3): }
8070:3): }
8071:3): }
8072:3): return $total;
8073:3): }
8074:3):
1.503 raeburn 8075: sub scantron_validator_lettnum {
8076: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,$whichline,
1.596.2.12.2. 6(raebur 8077:3): $alphabet,$record,$scantron_config,$scan_data,$randomorder,
8078:3): $randompick,$respnumlookup) = @_;
1.503 raeburn 8079:
8080: # Qon 'letter' implies for each slot in currquest we have:
8081: # ? or * for doubles, a letter in A-Z for a bubble, and
8082: # about anything else (esp. a value of Qoff) for missing
8083: # bubbles.
8084: #
8085: # Qon 'number' implies each slot gives a digit that indexes the
8086: # bubbles filled, or Qoff, or a non-number for unbubbled lines,
8087: # and * or ? for double bubbles on a single line.
8088: #
1.447 foxr 8089:
1.503 raeburn 8090: my $matchon;
8091: if ($$scantron_config{'Qon'} eq 'letter') {
8092: $matchon = '[A-Z]';
8093: } elsif ($$scantron_config{'Qon'} eq 'number') {
8094: $matchon = '\d';
8095: }
8096: my $occurrences = 0;
1.596.2.12.2. 6(raebur 8097:3): my $responsenum = $questnum-1;
8098:3): if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
8099:3): $responsenum = $respnumlookup->{$questnum-1}
8100:3): }
8101:3): if (($responsetype_per_response{$responsenum} eq 'essayresponse') ||
8102:3): ($responsetype_per_response{$responsenum} eq 'formularesponse') ||
8103:3): ($responsetype_per_response{$responsenum} eq 'stringresponse') ||
8104:3): ($responsetype_per_response{$responsenum} eq 'imageresponse') ||
8105:3): ($responsetype_per_response{$responsenum} eq 'reactionresponse') ||
8106:3): ($responsetype_per_response{$responsenum} eq 'organicresponse')) {
1.503 raeburn 8107: my @singlelines = split('',$currquest);
8108: foreach my $entry (@singlelines) {
8109: $occurrences = &occurence_count($entry,$matchon);
8110: if ($occurrences > 1) {
8111: last;
8112: }
1.596.2.12.2. 6(raebur 8113:3): }
1.503 raeburn 8114: } else {
8115: $occurrences = &occurence_count($currquest,$matchon);
8116: }
8117: if (($currquest =~ /\?/ || $currquest =~ /\*/) || ($occurrences > 1)) {
8118: push(@{$record->{'scantron.doubleerror'}},$quest_id);
8119: for (my $ans=0; $ans<$answers_needed; $ans++) {
8120: my $bubble = substr($currquest,$ans,1);
8121: if ($bubble =~ /$matchon/ ) {
8122: if ($$scantron_config{'Qon'} eq 'number') {
8123: if ($bubble == 0) {
8124: $bubble = 10;
8125: }
8126: $record->{"scantron.$ansnum.answer"} =
8127: $alphabet->[$bubble-1];
8128: } else {
8129: $record->{"scantron.$ansnum.answer"} = $bubble;
8130: }
8131: } else {
8132: $record->{"scantron.$ansnum.answer"}='';
8133: }
8134: $ansnum++;
8135: }
8136: } elsif (!defined($currquest)
8137: || (&occurence_count($currquest, $$scantron_config{'Qoff'}) == length($currquest))
8138: || (&occurence_count($currquest,$matchon) == 0)) {
8139: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
8140: $record->{"scantron.$ansnum.answer"}='';
8141: $ansnum++;
8142: }
8143: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
8144: push(@{$record->{'scantron.missingerror'}},$quest_id);
8145: }
8146: } else {
8147: if ($$scantron_config{'Qon'} eq 'number') {
8148: $currquest = &digits_to_letters($currquest);
8149: }
8150: for (my $ans=0; $ans<$answers_needed; $ans++) {
8151: my $bubble = substr($currquest,$ans,1);
8152: $record->{"scantron.$ansnum.answer"} = $bubble;
8153: $ansnum++;
8154: }
8155: }
8156: return $ansnum;
8157: }
1.447 foxr 8158:
1.503 raeburn 8159: sub scantron_validator_positional {
8160: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,
1.596.2.12.2. 6(raebur 8161:3): $whichline,$alphabet,$record,$scantron_config,$scan_data,
8162:3): $randomorder,$randompick,$respnumlookup) = @_;
1.447 foxr 8163:
1.503 raeburn 8164: # Otherwise there's a positional notation;
8165: # each bubble line requires Qlength items, and there are filled in
8166: # bubbles for each case where there 'Qon' characters.
8167: #
1.447 foxr 8168:
1.503 raeburn 8169: my @array=split($$scantron_config{'Qon'},$currquest,-1);
1.447 foxr 8170:
1.503 raeburn 8171: # If the split only gives us one element.. the full length of the
8172: # answer string, no bubbles are filled in:
1.447 foxr 8173:
1.507 raeburn 8174: if ($answers_needed eq '') {
8175: return;
8176: }
8177:
1.503 raeburn 8178: if (length($array[0]) eq $$scantron_config{'Qlength'}*$answers_needed) {
8179: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
8180: $record->{"scantron.$ansnum.answer"}='';
8181: $ansnum++;
8182: }
8183: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
8184: push(@{$record->{"scantron.missingerror"}},$quest_id);
8185: }
8186: } elsif (scalar(@array) == 2) {
8187: my $location = length($array[0]);
8188: my $line_num = int($location / $$scantron_config{'Qlength'});
8189: my $bubble = $alphabet->[$location % $$scantron_config{'Qlength'}];
8190: for (my $ans=0; $ans<$answers_needed; $ans++) {
8191: if ($ans eq $line_num) {
8192: $record->{"scantron.$ansnum.answer"} = $bubble;
8193: } else {
8194: $record->{"scantron.$ansnum.answer"} = ' ';
8195: }
8196: $ansnum++;
8197: }
8198: } else {
8199: # If there's more than one instance of a bubble character
8200: # That's a double bubble; with positional notation we can
8201: # record all the bubbles filled in as well as the
8202: # fact this response consists of multiple bubbles.
8203: #
1.596.2.12.2. 6(raebur 8204:3): my $responsenum = $questnum-1;
8205:3): if (($randompick || $randomorder) && (ref($respnumlookup) eq 'HASH')) {
8206:3): $responsenum = $respnumlookup->{$questnum-1}
8207:3): }
8208:3): if (($responsetype_per_response{$responsenum} eq 'essayresponse') ||
8209:3): ($responsetype_per_response{$responsenum} eq 'formularesponse') ||
8210:3): ($responsetype_per_response{$responsenum} eq 'stringresponse') ||
8211:3): ($responsetype_per_response{$responsenum} eq 'imageresponse') ||
8212:3): ($responsetype_per_response{$responsenum} eq 'reactionresponse') ||
8213:3): ($responsetype_per_response{$responsenum} eq 'organicresponse')) {
1.503 raeburn 8214: my $doubleerror = 0;
8215: while (($currquest >= $$scantron_config{'Qlength'}) &&
8216: (!$doubleerror)) {
8217: my $currline = substr($currquest,0,$$scantron_config{'Qlength'});
8218: $currquest = substr($currquest,$$scantron_config{'Qlength'});
8219: my @currarray = split($$scantron_config{'Qon'},$currline,-1);
8220: if (length(@currarray) > 2) {
8221: $doubleerror = 1;
8222: }
8223: }
8224: if ($doubleerror) {
8225: push(@{$record->{'scantron.doubleerror'}},$quest_id);
8226: }
8227: } else {
8228: push(@{$record->{'scantron.doubleerror'}},$quest_id);
8229: }
8230: my $item = $ansnum;
8231: for (my $ans=0; $ans<$answers_needed; $ans++) {
8232: $record->{"scantron.$item.answer"} = '';
8233: $item ++;
8234: }
1.447 foxr 8235:
1.503 raeburn 8236: my @ans=@array;
8237: my $i=0;
8238: my $increment = 0;
8239: while ($#ans) {
8240: $i+=length($ans[0]) + $increment;
8241: my $line = int($i/$$scantron_config{'Qlength'} + $ansnum);
8242: my $bubble = $i%$$scantron_config{'Qlength'};
8243: $record->{"scantron.$line.answer"}.=$alphabet->[$bubble];
8244: shift(@ans);
8245: $increment = 1;
8246: }
8247: $ansnum += $answers_needed;
1.82 albertel 8248: }
1.503 raeburn 8249: return $ansnum;
1.82 albertel 8250: }
8251:
1.423 albertel 8252: =pod
8253:
8254: =item scantron_add_delay
8255:
8256: Adds an error message that occurred during the grading phase to a
8257: queue of messages to be shown after grading pass is complete
8258:
8259: Arguments:
1.424 albertel 8260: $delayqueue - arrary ref of hash ref of error messages
1.423 albertel 8261: $scanline - the scanline that caused the error
8262: $errormesage - the error message
8263: $errorcode - a numeric code for the error
8264:
8265: Side Effects:
1.424 albertel 8266: updates the $delayqueue to have a new hash ref of the error
1.423 albertel 8267:
8268: =cut
8269:
1.82 albertel 8270: sub scantron_add_delay {
1.140 albertel 8271: my ($delayqueue,$scanline,$errormessage,$errorcode)=@_;
8272: push(@$delayqueue,
8273: {'line' => $scanline, 'emsg' => $errormessage,
8274: 'ecode' => $errorcode }
8275: );
1.82 albertel 8276: }
8277:
1.423 albertel 8278: =pod
8279:
8280: =item scantron_find_student
8281:
1.424 albertel 8282: Finds the username for the current scanline
8283:
8284: Arguments:
8285: $scantron_record - hash result from scantron_parse_scanline
8286: $scan_data - hash of correction information
8287: (see &scantron_getfile() form more information)
8288: $idmap - hash from &username_to_idmap()
8289: $line - number of current scanline
8290:
8291: Returns:
8292: Either 'username:domain' or undef if unknown
8293:
1.423 albertel 8294: =cut
8295:
1.82 albertel 8296: sub scantron_find_student {
1.157 albertel 8297: my ($scantron_record,$scan_data,$idmap,$line)=@_;
1.83 albertel 8298: my $scanID=$$scantron_record{'scantron.ID'};
1.157 albertel 8299: if ($scanID =~ /^\s*$/) {
8300: return &scan_data($scan_data,"$line.user");
8301: }
1.83 albertel 8302: foreach my $id (keys(%$idmap)) {
1.157 albertel 8303: if (lc($id) eq lc($scanID)) {
8304: return $$idmap{$id};
8305: }
1.83 albertel 8306: }
8307: return undef;
8308: }
8309:
1.423 albertel 8310: =pod
8311:
8312: =item scantron_filter
8313:
1.424 albertel 8314: Filter sub for lonnavmaps, filters out hidden resources if ignore
8315: hidden resources was selected
8316:
1.423 albertel 8317: =cut
8318:
1.83 albertel 8319: sub scantron_filter {
8320: my ($curres)=@_;
1.331 albertel 8321:
8322: if (ref($curres) && $curres->is_problem()) {
8323: # if the user has asked to not have either hidden
8324: # or 'randomout' controlled resources to be graded
8325: # don't include them
8326: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
8327: && $curres->randomout) {
8328: return 0;
8329: }
1.83 albertel 8330: return 1;
8331: }
8332: return 0;
1.82 albertel 8333: }
8334:
1.423 albertel 8335: =pod
8336:
8337: =item scantron_process_corrections
8338:
1.424 albertel 8339: Gets correction information out of submitted form data and corrects
8340: the scanline
8341:
1.423 albertel 8342: =cut
8343:
1.157 albertel 8344: sub scantron_process_corrections {
8345: my ($r) = @_;
1.596.2.12.2. 9(raebur 8346:9): my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.157 albertel 8347: my ($scanlines,$scan_data)=&scantron_getfile();
8348: my $classlist=&Apache::loncoursedata::get_classlist();
1.257 albertel 8349: my $which=$env{'form.scantron_line'};
1.200 albertel 8350: my $line=&scantron_get_line($scanlines,$scan_data,$which);
1.157 albertel 8351: my ($skip,$err,$errmsg);
1.257 albertel 8352: if ($env{'form.scantron_skip_record'}) {
1.157 albertel 8353: $skip=1;
1.257 albertel 8354: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)ID$/) {
8355: my $newstudent=$env{'form.scantron_username'}.':'.
8356: $env{'form.scantron_domain'};
1.157 albertel 8357: my $newid=$classlist->{$newstudent}->[&Apache::loncoursedata::CL_ID];
8358: ($line,$err,$errmsg)=
8359: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
8360: 'ID',{'newid'=>$newid,
1.257 albertel 8361: 'username'=>$env{'form.scantron_username'},
8362: 'domain'=>$env{'form.scantron_domain'}});
8363: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)CODE$/) {
8364: my $resolution=$env{'form.scantron_CODE_resolution'};
1.190 albertel 8365: my $newCODE;
1.192 albertel 8366: my %args;
1.190 albertel 8367: if ($resolution eq 'use_unfound') {
1.191 albertel 8368: $newCODE='use_unfound';
1.190 albertel 8369: } elsif ($resolution eq 'use_found') {
1.257 albertel 8370: $newCODE=$env{'form.scantron_CODE_selectedvalue'};
1.190 albertel 8371: } elsif ($resolution eq 'use_typed') {
1.257 albertel 8372: $newCODE=$env{'form.scantron_CODE_newvalue'};
1.194 albertel 8373: } elsif ($resolution =~ /^use_closest_(\d+)/) {
1.257 albertel 8374: $newCODE=$env{"form.scantron_CODE_closest_$1"};
1.190 albertel 8375: }
1.257 albertel 8376: if ($env{'form.scantron_corrections'} eq 'duplicateCODE') {
1.192 albertel 8377: $args{'CODE_ignore_dup'}=1;
8378: }
8379: $args{'CODE'}=$newCODE;
1.186 albertel 8380: ($line,$err,$errmsg)=
8381: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
1.192 albertel 8382: 'CODE',\%args);
1.257 albertel 8383: } elsif ($env{'form.scantron_corrections'} =~ /^(missing|double)bubble$/) {
8384: foreach my $question (split(',',$env{'form.scantron_questions'})) {
1.157 albertel 8385: ($line,$err,$errmsg)=
8386: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,
8387: $which,'answer',
8388: { 'question'=>$question,
1.503 raeburn 8389: 'response'=>$env{"form.scantron_correct_Q_$question"},
8390: 'questionnum'=>$env{"form.scantron_questionnum_Q_$question"}});
1.157 albertel 8391: if ($err) { last; }
8392: }
8393: }
8394: if ($err) {
1.596.2.12.2. 0(raebur 8395:3): $r->print(
8396:3): '<p class="LC_error">'
8397:3): .&mt('Unable to accept last correction, an error occurred: [_1]',
8398:3): $errmsg)
1(raebur 8399:3): .'</p>');
1.157 albertel 8400: } else {
1.200 albertel 8401: &scantron_put_line($scanlines,$scan_data,$which,$line,$skip);
1.157 albertel 8402: &scantron_putfile($scanlines,$scan_data);
8403: }
8404: }
8405:
1.423 albertel 8406: =pod
8407:
8408: =item reset_skipping_status
8409:
1.424 albertel 8410: Forgets the current set of remember skipped scanlines (and thus
8411: reverts back to considering all lines in the
8412: scantron_skipped_<filename> file)
8413:
1.423 albertel 8414: =cut
8415:
1.200 albertel 8416: sub reset_skipping_status {
8417: my ($scanlines,$scan_data)=&scantron_getfile();
8418: &scan_data($scan_data,'remember_skipping',undef,1);
8419: &scantron_putfile(undef,$scan_data);
8420: }
8421:
1.423 albertel 8422: =pod
8423:
8424: =item start_skipping
8425:
1.424 albertel 8426: Marks a scanline to be skipped.
8427:
1.423 albertel 8428: =cut
8429:
1.376 albertel 8430: sub start_skipping {
1.200 albertel 8431: my ($scan_data,$i)=@_;
8432: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 8433: if ($env{'form.scantron_options_redo'} =~ /^redo_/) {
8434: $remembered{$i}=2;
8435: } else {
8436: $remembered{$i}=1;
8437: }
1.200 albertel 8438: &scan_data($scan_data,'remember_skipping',join(':',%remembered));
8439: }
8440:
1.423 albertel 8441: =pod
8442:
8443: =item should_be_skipped
8444:
1.424 albertel 8445: Checks whether a scanline should be skipped.
8446:
1.423 albertel 8447: =cut
8448:
1.200 albertel 8449: sub should_be_skipped {
1.376 albertel 8450: my ($scanlines,$scan_data,$i)=@_;
1.257 albertel 8451: if ($env{'form.scantron_options_redo'} !~ /^redo_/) {
1.200 albertel 8452: # not redoing old skips
1.376 albertel 8453: if ($scanlines->{'skipped'}[$i]) { return 1; }
1.200 albertel 8454: return 0;
8455: }
8456: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 8457:
8458: if (exists($remembered{$i}) && $remembered{$i} != 2 ) {
8459: return 0;
8460: }
1.200 albertel 8461: return 1;
8462: }
8463:
1.423 albertel 8464: =pod
8465:
8466: =item remember_current_skipped
8467:
1.424 albertel 8468: Discovers what scanlines are in the scantron_skipped_<filename>
8469: file and remembers them into scan_data for later use.
8470:
1.423 albertel 8471: =cut
8472:
1.200 albertel 8473: sub remember_current_skipped {
8474: my ($scanlines,$scan_data)=&scantron_getfile();
8475: my %to_remember;
8476: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
8477: if ($scanlines->{'skipped'}[$i]) {
8478: $to_remember{$i}=1;
8479: }
8480: }
1.376 albertel 8481:
1.200 albertel 8482: &scan_data($scan_data,'remember_skipping',join(':',%to_remember));
8483: &scantron_putfile(undef,$scan_data);
8484: }
8485:
1.423 albertel 8486: =pod
8487:
8488: =item check_for_error
8489:
1.424 albertel 8490: Checks if there was an error when attempting to remove a specific
1.596.2.6 raeburn 8491: scantron_.. bubblesheet data file. Prints out an error if
1.424 albertel 8492: something went wrong.
8493:
1.423 albertel 8494: =cut
8495:
1.200 albertel 8496: sub check_for_error {
8497: my ($r,$result)=@_;
8498: if ($result ne 'ok' && $result ne 'not_found' ) {
1.492 albertel 8499: $r->print(&mt("An error occurred ([_1]) when trying to remove the existing corrections.",$result));
1.200 albertel 8500: }
8501: }
1.157 albertel 8502:
1.423 albertel 8503: =pod
8504:
8505: =item scantron_warning_screen
8506:
1.424 albertel 8507: Interstitial screen to make sure the operator has selected the
8508: correct options before we start the validation phase.
8509:
1.423 albertel 8510: =cut
8511:
1.203 albertel 8512: sub scantron_warning_screen {
1.596.2.12.2. 1(raebur 8513:0): my ($button_text,$symb)=@_;
1.257 albertel 8514: my $title=&Apache::lonnet::gettitle($env{'form.selectpage'});
1.596.2.12.2. 9(raebur 8515:9): my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.373 albertel 8516: my $CODElist;
1.284 albertel 8517: if ($scantron_config{'CODElocation'} &&
8518: $scantron_config{'CODEstart'} &&
8519: $scantron_config{'CODElength'}) {
8520: $CODElist=$env{'form.scantron_CODElist'};
1.596.2.12.2. 8(raebur 8521:4): if ($env{'form.scantron_CODElist'} eq '') { $CODElist='<span class="LC_warning">'.&mt('None').'</span>'; }
1.284 albertel 8522: $CODElist=
1.492 albertel 8523: '<tr><td><b>'.&mt('List of CODES to validate against:').'</b></td><td><tt>'.
1.373 albertel 8524: $env{'form.scantron_CODElist'}.'</tt></td></tr>';
1.284 albertel 8525: }
1.596.2.12.2. (raeburn 8526:): my $lastbubblepoints;
8527:): if ($env{'form.scantron_lastbubblepoints'} ne '') {
8528:): $lastbubblepoints =
8529:): '<tr><td><b>'.&mt('Hand-graded items: points from last bubble in row').'</b></td><td><tt>'.
8530:): $env{'form.scantron_lastbubblepoints'}.'</tt></td></tr>';
8531:): }
1.492 albertel 8532: return ('
1.203 albertel 8533: <p>
1.492 albertel 8534: <span class="LC_warning">
1.596.2.12.2. 6(raebur 8535:3): '.&mt("Please double check the information below before clicking on '[_1]'",&mt($button_text)).'</span>
1.203 albertel 8536: </p>
8537: <table>
1.492 albertel 8538: <tr><td><b>'.&mt('Sequence to be Graded:').'</b></td><td>'.$title.'</td></tr>
8539: <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 8540:): '.$CODElist.$lastbubblepoints.'
1.203 albertel 8541: </table>
1.596.2.12.2. 1(raebur 8542:0): <p> '.&mt("If this information is correct, please click on '[_1]'.",&mt($button_text)).'<br />
8543: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 8544:
8545: <br />
1.492 albertel 8546: ');
1.203 albertel 8547: }
8548:
1.423 albertel 8549: =pod
8550:
8551: =item scantron_do_warning
8552:
1.424 albertel 8553: Check if the operator has picked something for all required
8554: fields. Error out if something is missing.
8555:
1.423 albertel 8556: =cut
8557:
1.203 albertel 8558: sub scantron_do_warning {
1.596.2.12.2. 1(raebur 8559:0): my ($r,$symb)=@_;
1.203 albertel 8560: if (!$symb) {return '';}
1.324 albertel 8561: my $default_form_data=&defaultFormData($symb);
1.203 albertel 8562: $r->print(&scantron_form_start().$default_form_data);
1.257 albertel 8563: if ( $env{'form.selectpage'} eq '' ||
8564: $env{'form.scantron_selectfile'} eq '' ||
8565: $env{'form.scantron_format'} eq '' ) {
1.596.2.4 raeburn 8566: $r->print("<p>".&mt('You have forgotten to specify some information. Please go Back and try again.')."</p>");
1.257 albertel 8567: if ( $env{'form.selectpage'} eq '') {
1.492 albertel 8568: $r->print('<p><span class="LC_error">'.&mt('You have not selected a Sequence to grade').'</span></p>');
1.237 albertel 8569: }
1.257 albertel 8570: if ( $env{'form.scantron_selectfile'} eq '') {
1.596.2.4 raeburn 8571: $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 8572: }
1.257 albertel 8573: if ( $env{'form.scantron_format'} eq '') {
1.596.2.5 raeburn 8574: $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 8575: }
8576: } else {
1.596.2.12.2. 1(raebur 8577:0): my $warning=&scantron_warning_screen('Grading: Validate Records',$symb);
(raeburn 8578:): my $bubbledbyhand=&hand_bubble_option();
1.492 albertel 8579: $r->print('
1.596.2.12.2. (raeburn 8580:): '.$warning.$bubbledbyhand.'
1.492 albertel 8581: <input type="submit" name="submit" value="'.&mt('Grading: Validate Records').'" />
1.203 albertel 8582: <input type="hidden" name="command" value="scantron_validate" />
1.492 albertel 8583: ');
1.237 albertel 8584: }
1.596.2.12.2. 1(raebur 8585:0): $r->print("</form><br />");
1.203 albertel 8586: return '';
8587: }
8588:
1.423 albertel 8589: =pod
8590:
8591: =item scantron_form_start
8592:
1.424 albertel 8593: html hidden input for remembering all selected grading options
8594:
1.423 albertel 8595: =cut
8596:
1.203 albertel 8597: sub scantron_form_start {
8598: my ($max_bubble)=@_;
8599: my $result= <<SCANTRONFORM;
8600: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
1.257 albertel 8601: <input type="hidden" name="selectpage" value="$env{'form.selectpage'}" />
8602: <input type="hidden" name="scantron_format" value="$env{'form.scantron_format'}" />
8603: <input type="hidden" name="scantron_selectfile" value="$env{'form.scantron_selectfile'}" />
1.218 albertel 8604: <input type="hidden" name="scantron_maxbubble" value="$max_bubble" />
1.257 albertel 8605: <input type="hidden" name="scantron_CODElist" value="$env{'form.scantron_CODElist'}" />
8606: <input type="hidden" name="scantron_CODEunique" value="$env{'form.scantron_CODEunique'}" />
8607: <input type="hidden" name="scantron_options_redo" value="$env{'form.scantron_options_redo'}" />
8608: <input type="hidden" name="scantron_options_ignore" value="$env{'form.scantron_options_ignore'}" />
1.331 albertel 8609: <input type="hidden" name="scantron_options_hidden" value="$env{'form.scantron_options_hidden'}" />
1.203 albertel 8610: SCANTRONFORM
1.447 foxr 8611:
8612: my $line = 0;
8613: while (defined($env{"form.scantron.bubblelines.$line"})) {
8614: my $chunk =
8615: '<input type="hidden" name="scantron.bubblelines.'.$line.'" value="'.$env{"form.scantron.bubblelines.$line"}.'" />'."\n";
1.448 foxr 8616: $chunk .=
8617: '<input type="hidden" name="scantron.first_bubble_line.'.$line.'" value="'.$env{"form.scantron.first_bubble_line.$line"}.'" />'."\n";
1.503 raeburn 8618: $chunk .=
8619: '<input type="hidden" name="scantron.sub_bubblelines.'.$line.'" value="'.$env{"form.scantron.sub_bubblelines.$line"}.'" />'."\n";
1.504 raeburn 8620: $chunk .=
8621: '<input type="hidden" name="scantron.responsetype.'.$line.'" value="'.$env{"form.scantron.responsetype.$line"}.'" />'."\n";
1.596.2.12.2. 6(raebur 8622:3): $chunk .=
8623:3): '<input type="hidden" name="scantron.residpart.'.$line.'" value="'.$env{"form.scantron.residpart.$line"}.'" />'."\n";
1.447 foxr 8624: $result .= $chunk;
8625: $line++;
1.596.2.12.2. 6(raebur 8626:3): }
1.203 albertel 8627: return $result;
8628: }
8629:
1.423 albertel 8630: =pod
8631:
8632: =item scantron_validate_file
8633:
1.596.2.6 raeburn 8634: Dispatch routine for doing validation of a bubblesheet data file.
1.424 albertel 8635:
8636: Also processes any necessary information resets that need to
8637: occur before validation begins (ignore previous corrections,
8638: restarting the skipped records processing)
8639:
1.423 albertel 8640: =cut
8641:
1.157 albertel 8642: sub scantron_validate_file {
1.596.2.12.2. 1(raebur 8643:0): my ($r,$symb) = @_;
1.157 albertel 8644: if (!$symb) {return '';}
1.324 albertel 8645: my $default_form_data=&defaultFormData($symb);
1.200 albertel 8646:
1.596.2.12.2. 0(raebur 8647:3): # do the detection of only doing skipped records first before we delete
1.424 albertel 8648: # them when doing the corrections reset
1.257 albertel 8649: if ($env{'form.scantron_options_redo'} ne 'redo_skipped_ready') {
1.200 albertel 8650: &reset_skipping_status();
8651: }
1.257 albertel 8652: if ($env{'form.scantron_options_redo'} eq 'redo_skipped') {
1.200 albertel 8653: &remember_current_skipped();
1.257 albertel 8654: $env{'form.scantron_options_redo'}='redo_skipped_ready';
1.200 albertel 8655: }
8656:
1.257 albertel 8657: if ($env{'form.scantron_options_ignore'} eq 'ignore_corrections') {
1.200 albertel 8658: &check_for_error($r,&scantron_remove_file('corrected'));
8659: &check_for_error($r,&scantron_remove_file('skipped'));
8660: &check_for_error($r,&scantron_remove_scan_data());
1.257 albertel 8661: $env{'form.scantron_options_ignore'}='done';
1.192 albertel 8662: }
1.200 albertel 8663:
1.257 albertel 8664: if ($env{'form.scantron_corrections'}) {
1.157 albertel 8665: &scantron_process_corrections($r);
8666: }
1.503 raeburn 8667: $r->print('<p>'.&mt('Gathering necessary information.').'</p>');$r->rflush();
1.157 albertel 8668: #get the student pick code ready
8669: $r->print(&Apache::loncommon::studentbrowser_javascript());
1.582 raeburn 8670: my $nav_error;
1.596.2.12.2. 9(raebur 8671:9): my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
(raeburn 8672:): my $max_bubble=&scantron_get_maxbubble(\$nav_error,\%scantron_config);
1.582 raeburn 8673: if ($nav_error) {
8674: $r->print(&navmap_errormsg());
8675: return '';
8676: }
1.203 albertel 8677: my $result=&scantron_form_start($max_bubble).$default_form_data;
1.596.2.12.2. (raeburn 8678:): if ($env{'form.scantron_lastbubblepoints'} ne '') {
8679:): $result .= '<input type="hidden" name="scantron_lastbubblepoints" value="'.$env{'form.scantron_lastbubblepoints'}.'" />';
8680:): }
1.157 albertel 8681: $r->print($result);
8682:
1.334 albertel 8683: my @validate_phases=( 'sequence',
8684: 'ID',
1.157 albertel 8685: 'CODE',
8686: 'doublebubble',
8687: 'missingbubbles');
1.257 albertel 8688: if (!$env{'form.validatepass'}) {
8689: $env{'form.validatepass'} = 0;
1.157 albertel 8690: }
1.257 albertel 8691: my $currentphase=$env{'form.validatepass'};
1.157 albertel 8692:
1.448 foxr 8693:
1.157 albertel 8694: my $stop=0;
8695: while (!$stop && $currentphase < scalar(@validate_phases)) {
1.503 raeburn 8696: $r->print(&mt('Validating '.$validate_phases[$currentphase]).'<br />');
1.157 albertel 8697: $r->rflush();
1.596.2.12.2. 6(raebur 8698:3):
1.157 albertel 8699: my $which="scantron_validate_".$validate_phases[$currentphase];
8700: {
8701: no strict 'refs';
8702: ($stop,$currentphase)=&$which($r,$currentphase);
8703: }
8704: }
8705: if (!$stop) {
1.596.2.12.2. 1(raebur 8706:0): my $warning=&scantron_warning_screen('Start Grading',$symb);
1.542 raeburn 8707: $r->print(&mt('Validation process complete.').'<br />'.
8708: $warning.
8709: &mt('Perform verification for each student after storage of submissions?').
8710: ' <span class="LC_nobreak"><label>'.
8711: '<input type="radio" name="verifyrecord" value="1" />'.&mt('Yes').'</label>'.
8712: (' 'x3).'<label>'.
8713: '<input type="radio" name="verifyrecord" value="0" checked="checked" />'.&mt('No').
8714: '</label></span><br />'.
8715: &mt('Grading will take longer if you use verification.').'<br />'.
1.596.2.12.2. 1(raebur 8716:0): &mt('Otherwise, Grade/Manage/Review Bubblesheets [_1] Review bubblesheet data can be used once grading is complete.','»').'<br /><br />'.
1.542 raeburn 8717: '<input type="submit" name="submit" value="'.&mt('Start Grading').'" />'.
8718: '<input type="hidden" name="command" value="scantron_process" />'."\n");
1.157 albertel 8719: } else {
8720: $r->print('<input type="hidden" name="command" value="scantron_validate" />');
8721: $r->print("<input type='hidden' name='validatepass' value='".$currentphase."' />");
8722: }
8723: if ($stop) {
1.334 albertel 8724: if ($validate_phases[$currentphase] eq 'sequence') {
1.539 riegler 8725: $r->print('<input type="submit" name="submit" value="'.&mt('Ignore').' → " />');
1.492 albertel 8726: $r->print(' '.&mt('this error').' <br />');
1.334 albertel 8727:
1.596.2.12.2. 1(raebur 8728: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 8729: } else {
1.503 raeburn 8730: if ($validate_phases[$currentphase] eq 'doublebubble' || $validate_phases[$currentphase] eq 'missingbubbles') {
1.539 riegler 8731: $r->print('<input type="button" name="submitbutton" value="'.&mt('Continue').' →" onclick="javascript:verify_bubble_radio(this.form)" />');
1.503 raeburn 8732: } else {
1.539 riegler 8733: $r->print('<input type="submit" name="submit" value="'.&mt('Continue').' →" />');
1.503 raeburn 8734: }
1.492 albertel 8735: $r->print(' '.&mt('using corrected info').' <br />');
8736: $r->print("<input type='submit' value='".&mt("Skip")."' name='scantron_skip_record' />");
8737: $r->print(" ".&mt("this scanline saving it for later."));
1.334 albertel 8738: }
1.157 albertel 8739: }
1.596.2.12.2. 1(raebur 8740:0): $r->print(" </form><br />");
1.157 albertel 8741: return '';
8742: }
8743:
1.423 albertel 8744:
8745: =pod
8746:
8747: =item scantron_remove_file
8748:
1.596.2.6 raeburn 8749: Removes the requested bubblesheet data file, makes sure that
1.424 albertel 8750: scantron_original_<filename> is never removed
8751:
8752:
1.423 albertel 8753: =cut
8754:
1.200 albertel 8755: sub scantron_remove_file {
1.192 albertel 8756: my ($which)=@_;
1.257 albertel 8757: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
8758: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 8759: my $file='scantron_';
1.200 albertel 8760: if ($which eq 'corrected' || $which eq 'skipped') {
8761: $file.=$which.'_';
1.192 albertel 8762: } else {
8763: return 'refused';
8764: }
1.257 albertel 8765: $file.=$env{'form.scantron_selectfile'};
1.200 albertel 8766: return &Apache::lonnet::removeuserfile($cname,$cdom,$file);
8767: }
8768:
1.423 albertel 8769:
8770: =pod
8771:
8772: =item scantron_remove_scan_data
8773:
1.596.2.6 raeburn 8774: Removes all scan_data correction for the requested bubblesheet
1.424 albertel 8775: data file. (In the case that both the are doing skipped records we need
8776: to remember the old skipped lines for the time being so that element
8777: persists for a while.)
8778:
1.423 albertel 8779: =cut
8780:
1.200 albertel 8781: sub scantron_remove_scan_data {
1.257 albertel 8782: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
8783: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 8784: my @keys=&Apache::lonnet::getkeys('nohist_scantrondata',$cdom,$cname);
8785: my @todelete;
1.257 albertel 8786: my $filename=$env{'form.scantron_selectfile'};
1.192 albertel 8787: foreach my $key (@keys) {
8788: if ($key=~/^\Q$filename\E_/) {
1.257 albertel 8789: if ($env{'form.scantron_options_redo'} eq 'redo_skipped_ready' &&
1.200 albertel 8790: $key=~/remember_skipping/) {
8791: next;
8792: }
1.192 albertel 8793: push(@todelete,$key);
8794: }
8795: }
1.200 albertel 8796: my $result;
1.192 albertel 8797: if (@todelete) {
1.491 albertel 8798: $result = &Apache::lonnet::del('nohist_scantrondata',
8799: \@todelete,$cdom,$cname);
8800: } else {
8801: $result = 'ok';
1.192 albertel 8802: }
8803: return $result;
8804: }
8805:
1.423 albertel 8806:
8807: =pod
8808:
8809: =item scantron_getfile
8810:
1.596.2.6 raeburn 8811: Fetches the requested bubblesheet data file (all 3 versions), and
1.424 albertel 8812: the scan_data hash
8813:
8814: Arguments:
8815: None
8816:
8817: Returns:
8818: 2 hash references
8819:
8820: - first one has
8821: orig -
8822: corrected -
8823: skipped - each of which points to an array ref of the specified
8824: file broken up into individual lines
8825: count - number of scanlines
8826:
8827: - second is the scan_data hash possible keys are
1.425 albertel 8828: ($number refers to scanline numbered $number and thus the key affects
8829: only that scanline
8830: $bubline refers to the specific bubble line element and the aspects
8831: refers to that specific bubble line element)
8832:
8833: $number.user - username:domain to use
8834: $number.CODE_ignore_dup
8835: - ignore the duplicate CODE error
8836: $number.useCODE
8837: - use the CODE in the scanline as is
8838: $number.no_bubble.$bubline
8839: - it is valid that there is no bubbled in bubble
8840: at $number $bubline
8841: remember_skipping
8842: - a frozen hash containing keys of $number and values
8843: of either
8844: 1 - we are on a 'do skipped records pass' and plan
8845: on processing this line
8846: 2 - we are on a 'do skipped records pass' and this
8847: scanline has been marked to skip yet again
1.424 albertel 8848:
1.423 albertel 8849: =cut
8850:
1.157 albertel 8851: sub scantron_getfile {
1.200 albertel 8852: #FIXME really would prefer a scantron directory
1.257 albertel 8853: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
8854: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.157 albertel 8855: my $lines;
8856: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 8857: 'scantron_orig_'.$env{'form.scantron_selectfile'});
1.157 albertel 8858: my %scanlines;
8859: $scanlines{'orig'}=[(split("\n",$lines,-1))];
8860: my $temp=$scanlines{'orig'};
8861: $scanlines{'count'}=$#$temp;
8862:
8863: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 8864: 'scantron_corrected_'.$env{'form.scantron_selectfile'});
1.157 albertel 8865: if ($lines eq '-1') {
8866: $scanlines{'corrected'}=[];
8867: } else {
8868: $scanlines{'corrected'}=[(split("\n",$lines,-1))];
8869: }
8870: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 8871: 'scantron_skipped_'.$env{'form.scantron_selectfile'});
1.157 albertel 8872: if ($lines eq '-1') {
8873: $scanlines{'skipped'}=[];
8874: } else {
8875: $scanlines{'skipped'}=[(split("\n",$lines,-1))];
8876: }
1.175 albertel 8877: my @tmp=&Apache::lonnet::dump('nohist_scantrondata',$cdom,$cname);
1.157 albertel 8878: if ($tmp[0] =~ /^(error:|no_such_host)/) { @tmp=(); }
8879: my %scan_data = @tmp;
8880: return (\%scanlines,\%scan_data);
8881: }
8882:
1.423 albertel 8883: =pod
8884:
8885: =item lonnet_putfile
8886:
1.424 albertel 8887: Wrapper routine to call &Apache::lonnet::finishuserfileupload
8888:
8889: Arguments:
8890: $contents - data to store
8891: $filename - filename to store $contents into
8892:
8893: Returns:
8894: result value from &Apache::lonnet::finishuserfileupload
8895:
1.423 albertel 8896: =cut
8897:
1.157 albertel 8898: sub lonnet_putfile {
8899: my ($contents,$filename)=@_;
1.257 albertel 8900: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
8901: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
8902: $env{'form.sillywaytopassafilearound'}=$contents;
1.275 albertel 8903: &Apache::lonnet::finishuserfileupload($docuname,$docudom,'sillywaytopassafilearound',$filename);
1.157 albertel 8904:
8905: }
8906:
1.423 albertel 8907: =pod
8908:
8909: =item scantron_putfile
8910:
1.596.2.6 raeburn 8911: Stores the current version of the bubblesheet data files, and the
1.424 albertel 8912: scan_data hash. (Does not modify the original version only the
8913: corrected and skipped versions.
8914:
8915: Arguments:
8916: $scanlines - hash ref that looks like the first return value from
8917: &scantron_getfile()
8918: $scan_data - hash ref that looks like the second return value from
8919: &scantron_getfile()
8920:
1.423 albertel 8921: =cut
8922:
1.157 albertel 8923: sub scantron_putfile {
8924: my ($scanlines,$scan_data) = @_;
1.200 albertel 8925: #FIXME really would prefer a scantron directory
1.257 albertel 8926: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
8927: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.200 albertel 8928: if ($scanlines) {
8929: my $prefix='scantron_';
1.157 albertel 8930: # no need to update orig, shouldn't change
8931: # &lonnet_putfile(join("\n",@{$scanlines->{'orig'}}),$prefix.'orig_'.
1.257 albertel 8932: # $env{'form.scantron_selectfile'});
1.200 albertel 8933: &lonnet_putfile(join("\n",@{$scanlines->{'corrected'}}),
8934: $prefix.'corrected_'.
1.257 albertel 8935: $env{'form.scantron_selectfile'});
1.200 albertel 8936: &lonnet_putfile(join("\n",@{$scanlines->{'skipped'}}),
8937: $prefix.'skipped_'.
1.257 albertel 8938: $env{'form.scantron_selectfile'});
1.200 albertel 8939: }
1.175 albertel 8940: &Apache::lonnet::put('nohist_scantrondata',$scan_data,$cdom,$cname);
1.157 albertel 8941: }
8942:
1.423 albertel 8943: =pod
8944:
8945: =item scantron_get_line
8946:
1.424 albertel 8947: Returns the correct version of the scanline
8948:
8949: Arguments:
8950: $scanlines - hash ref that looks like the first return value from
8951: &scantron_getfile()
8952: $scan_data - hash ref that looks like the second return value from
8953: &scantron_getfile()
8954: $i - number of the requested line (starts at 0)
8955:
8956: Returns:
8957: A scanline, (either the original or the corrected one if it
8958: exists), or undef if the requested scanline should be
8959: skipped. (Either because it's an skipped scanline, or it's an
8960: unskipped scanline and we are not doing a 'do skipped scanlines'
8961: pass.
8962:
1.423 albertel 8963: =cut
8964:
1.157 albertel 8965: sub scantron_get_line {
1.200 albertel 8966: my ($scanlines,$scan_data,$i)=@_;
1.376 albertel 8967: if (&should_be_skipped($scanlines,$scan_data,$i)) { return undef; }
8968: #if ($scanlines->{'skipped'}[$i]) { return undef; }
1.157 albertel 8969: if ($scanlines->{'corrected'}[$i]) {return $scanlines->{'corrected'}[$i];}
8970: return $scanlines->{'orig'}[$i];
8971: }
8972:
1.423 albertel 8973: =pod
8974:
8975: =item scantron_todo_count
8976:
1.424 albertel 8977: Counts the number of scanlines that need processing.
8978:
8979: Arguments:
8980: $scanlines - hash ref that looks like the first return value from
8981: &scantron_getfile()
8982: $scan_data - hash ref that looks like the second return value from
8983: &scantron_getfile()
8984:
8985: Returns:
8986: $count - number of scanlines to process
8987:
1.423 albertel 8988: =cut
8989:
1.200 albertel 8990: sub get_todo_count {
8991: my ($scanlines,$scan_data)=@_;
8992: my $count=0;
8993: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
8994: my $line=&scantron_get_line($scanlines,$scan_data,$i);
8995: if ($line=~/^[\s\cz]*$/) { next; }
8996: $count++;
8997: }
8998: return $count;
8999: }
9000:
1.423 albertel 9001: =pod
9002:
9003: =item scantron_put_line
9004:
1.596.2.6 raeburn 9005: Updates the 'corrected' or 'skipped' versions of the bubblesheet
1.424 albertel 9006: data file.
9007:
9008: Arguments:
9009: $scanlines - hash ref that looks like the first return value from
9010: &scantron_getfile()
9011: $scan_data - hash ref that looks like the second return value from
9012: &scantron_getfile()
9013: $i - line number to update
9014: $newline - contents of the updated scanline
9015: $skip - if true make the line for skipping and update the
9016: 'skipped' file
9017:
1.423 albertel 9018: =cut
9019:
1.157 albertel 9020: sub scantron_put_line {
1.200 albertel 9021: my ($scanlines,$scan_data,$i,$newline,$skip)=@_;
1.157 albertel 9022: if ($skip) {
9023: $scanlines->{'skipped'}[$i]=$newline;
1.376 albertel 9024: &start_skipping($scan_data,$i);
1.157 albertel 9025: return;
9026: }
9027: $scanlines->{'corrected'}[$i]=$newline;
9028: }
9029:
1.423 albertel 9030: =pod
9031:
9032: =item scantron_clear_skip
9033:
1.424 albertel 9034: Remove a line from the 'skipped' file
9035:
9036: Arguments:
9037: $scanlines - hash ref that looks like the first return value from
9038: &scantron_getfile()
9039: $scan_data - hash ref that looks like the second return value from
9040: &scantron_getfile()
9041: $i - line number to update
9042:
1.423 albertel 9043: =cut
9044:
1.376 albertel 9045: sub scantron_clear_skip {
9046: my ($scanlines,$scan_data,$i)=@_;
9047: if (exists($scanlines->{'skipped'}[$i])) {
9048: undef($scanlines->{'skipped'}[$i]);
9049: return 1;
9050: }
9051: return 0;
9052: }
9053:
1.423 albertel 9054: =pod
9055:
9056: =item scantron_filter_not_exam
9057:
1.424 albertel 9058: Filter routine used by &Apache::lonnavmaps::retrieveResources(), to
9059: filter out resources that are not marked as 'exam' mode
9060:
1.423 albertel 9061: =cut
9062:
1.334 albertel 9063: sub scantron_filter_not_exam {
9064: my ($curres)=@_;
9065:
9066: if (ref($curres) && $curres->is_problem() && !$curres->is_exam()) {
9067: # if the user has asked to not have either hidden
9068: # or 'randomout' controlled resources to be graded
9069: # don't include them
9070: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
9071: && $curres->randomout) {
9072: return 0;
9073: }
9074: return 1;
9075: }
9076: return 0;
9077: }
9078:
1.423 albertel 9079: =pod
9080:
9081: =item scantron_validate_sequence
9082:
1.424 albertel 9083: Validates the selected sequence, checking for resource that are
9084: not set to exam mode.
9085:
1.423 albertel 9086: =cut
9087:
1.334 albertel 9088: sub scantron_validate_sequence {
9089: my ($r,$currentphase) = @_;
9090:
9091: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 9092: unless (ref($navmap)) {
9093: $r->print(&navmap_errormsg());
9094: return (1,$currentphase);
9095: }
1.334 albertel 9096: my (undef,undef,$sequence)=
9097: &Apache::lonnet::decode_symb($env{'form.selectpage'});
9098:
9099: my $map=$navmap->getResourceByUrl($sequence);
9100:
9101: $r->print('<input type="hidden" name="validate_sequence_exam"
9102: value="ignore" />');
9103: if ($env{'form.validate_sequence_exam'} ne 'ignore') {
9104: my @resources=
9105: $navmap->retrieveResources($map,\&scantron_filter_not_exam,1,0);
9106: if (@resources) {
1.596.2.12.2. 0(raebur 9107:2): $r->print('<p class="LC_warning">'
9108:2): .&mt('Some resources in the sequence currently are not set to'
9109:2): .' exam mode. Grading these resources currently may not'
9110:2): .' work correctly.')
9111:2): .'</p>'
9112:2): );
1.334 albertel 9113: return (1,$currentphase);
9114: }
9115: }
9116:
9117: return (0,$currentphase+1);
9118: }
9119:
1.423 albertel 9120:
9121:
1.157 albertel 9122: sub scantron_validate_ID {
9123: my ($r,$currentphase) = @_;
9124:
9125: #get student info
9126: my $classlist=&Apache::loncoursedata::get_classlist();
9127: my %idmap=&username_to_idmap($classlist);
9128:
9129: #get scantron line setup
1.596.2.12.2. 9(raebur 9130:9): my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.157 albertel 9131: my ($scanlines,$scan_data)=&scantron_getfile();
1.582 raeburn 9132:
9133: my $nav_error;
1.596.2.12.2. (raeburn 9134:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the bubble_lines.. array.
1.582 raeburn 9135: if ($nav_error) {
9136: $r->print(&navmap_errormsg());
9137: return(1,$currentphase);
9138: }
1.157 albertel 9139:
9140: my %found=('ids'=>{},'usernames'=>{});
9141: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 9142: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 9143: if ($line=~/^[\s\cz]*$/) { next; }
9144: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
9145: $scan_data);
9146: my $id=$$scan_record{'scantron.ID'};
9147: my $found;
9148: foreach my $checkid (keys(%idmap)) {
9149: if (lc($checkid) eq lc($id)) { $found=$checkid;last; }
9150: }
9151: if ($found) {
9152: my $username=$idmap{$found};
9153: if ($found{'ids'}{$found}) {
9154: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
9155: $line,'duplicateID',$found);
1.194 albertel 9156: return(1,$currentphase);
1.157 albertel 9157: } elsif ($found{'usernames'}{$username}) {
9158: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
9159: $line,'duplicateID',$username);
1.194 albertel 9160: return(1,$currentphase);
1.157 albertel 9161: }
1.186 albertel 9162: #FIXME store away line we previously saw the ID on to use above
1.157 albertel 9163: $found{'ids'}{$found}++;
9164: $found{'usernames'}{$username}++;
9165: } else {
9166: if ($id =~ /^\s*$/) {
1.158 albertel 9167: my $username=&scan_data($scan_data,"$i.user");
1.157 albertel 9168: if (defined($username) && $found{'usernames'}{$username}) {
9169: &scantron_get_correction($r,$i,$scan_record,
9170: \%scantron_config,
9171: $line,'duplicateID',$username);
1.194 albertel 9172: return(1,$currentphase);
1.157 albertel 9173: } elsif (!defined($username)) {
9174: &scantron_get_correction($r,$i,$scan_record,
9175: \%scantron_config,
9176: $line,'incorrectID');
1.194 albertel 9177: return(1,$currentphase);
1.157 albertel 9178: }
9179: $found{'usernames'}{$username}++;
9180: } else {
9181: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
9182: $line,'incorrectID');
1.194 albertel 9183: return(1,$currentphase);
1.157 albertel 9184: }
9185: }
9186: }
9187:
9188: return (0,$currentphase+1);
9189: }
9190:
1.423 albertel 9191:
1.157 albertel 9192: sub scantron_get_correction {
1.596.2.12.2. 6(raebur 9193:3): my ($r,$i,$scan_record,$scan_config,$line,$error,$arg,
9194:3): $randomorder,$randompick,$respnumlookup,$startline)=@_;
1.454 banghart 9195: #FIXME in the case of a duplicated ID the previous line, probably need
1.157 albertel 9196: #to show both the current line and the previous one and allow skipping
9197: #the previous one or the current one
9198:
1.333 albertel 9199: if ( $$scan_record{'scantron.PaperID'} =~ /\S/) {
1.596.2.6 raeburn 9200: $r->print(
9201: '<p class="LC_warning">'
9202: .&mt('An error was detected ([_1]) for PaperID [_2]',
9203: "<b>$error</b>",
9204: '<tt>'.$$scan_record{'scantron.PaperID'}.'</tt>')
9205: ."</p> \n");
1.157 albertel 9206: } else {
1.596.2.6 raeburn 9207: $r->print(
9208: '<p class="LC_warning">'
9209: .&mt('An error was detected ([_1]) in scanline [_2] [_3]',
9210: "<b>$error</b>", $i, "<pre>$line</pre>")
9211: ."</p> \n");
9212: }
9213: my $message =
9214: '<p>'
9215: .&mt('The ID on the form is [_1]',
9216: "<tt>$$scan_record{'scantron.ID'}</tt>")
9217: .'<br />'
1.596.2.12 raeburn 9218: .&mt('The name on the paper is [_1], [_2]',
1.596.2.6 raeburn 9219: $$scan_record{'scantron.LastName'},
9220: $$scan_record{'scantron.FirstName'})
9221: .'</p>';
1.242 albertel 9222:
1.157 albertel 9223: $r->print('<input type="hidden" name="scantron_corrections" value="'.$error.'" />'."\n");
9224: $r->print('<input type="hidden" name="scantron_line" value="'.$i.'" />'."\n");
1.503 raeburn 9225: # Array populated for doublebubble or
9226: my @lines_to_correct; # missingbubble errors to build javascript
9227: # to validate radio button checking
9228:
1.157 albertel 9229: if ($error =~ /ID$/) {
1.186 albertel 9230: if ($error eq 'incorrectID') {
1.596.2.6 raeburn 9231: $r->print('<p class="LC_warning">'.&mt("The encoded ID is not in the classlist").
1.492 albertel 9232: "</p>\n");
1.157 albertel 9233: } elsif ($error eq 'duplicateID') {
1.596.2.6 raeburn 9234: $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 9235: }
1.242 albertel 9236: $r->print($message);
1.492 albertel 9237: $r->print("<p>".&mt("How should I handle this?")." <br /> \n");
1.157 albertel 9238: $r->print("\n<ul><li> ");
9239: #FIXME it would be nice if this sent back the user ID and
9240: #could do partial userID matches
9241: $r->print(&Apache::loncommon::selectstudent_link('scantronupload',
9242: 'scantron_username','scantron_domain'));
9243: $r->print(": <input type='text' name='scantron_username' value='' />");
1.596.2.12.2. 3(raebur 9244:3): $r->print("\n:\n".
1.257 albertel 9245: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'scantron_domain'));
1.157 albertel 9246:
9247: $r->print('</li>');
1.186 albertel 9248: } elsif ($error =~ /CODE$/) {
9249: if ($error eq 'incorrectCODE') {
1.596.2.6 raeburn 9250: $r->print('<p class="LC_warning">'.&mt("The encoded CODE is not in the list of possible CODEs.")."</p>\n");
1.186 albertel 9251: } elsif ($error eq 'duplicateCODE') {
1.596.2.6 raeburn 9252: $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 9253: }
1.596.2.6 raeburn 9254: $r->print("<p>".&mt('The CODE on the form is [_1]',
9255: "<tt>'$$scan_record{'scantron.CODE'}'</tt>")
9256: ."</p>\n");
1.242 albertel 9257: $r->print($message);
1.596.2.6 raeburn 9258: $r->print("<p>".&mt("How should I handle this?")."</p>\n");
1.187 albertel 9259: $r->print("\n<br /> ");
1.194 albertel 9260: my $i=0;
1.273 albertel 9261: if ($error eq 'incorrectCODE'
9262: && $$scan_record{'scantron.CODE'}=~/\S/ ) {
1.194 albertel 9263: my ($max,$closest)=&scantron_get_closely_matching_CODEs($arg,$$scan_record{'scantron.CODE'});
1.278 albertel 9264: if ($closest > 0) {
9265: foreach my $testcode (@{$closest}) {
9266: my $checked='';
1.569 bisitz 9267: if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 9268: $r->print("
9269: <label>
1.569 bisitz 9270: <input type='radio' name='scantron_CODE_resolution' value='use_closest_$i'$checked />
1.492 albertel 9271: ".&mt("Use the similar CODE [_1] instead.",
9272: "<b><tt>".$testcode."</tt></b>")."
9273: </label>
9274: <input type='hidden' name='scantron_CODE_closest_$i' value='$testcode' />");
1.278 albertel 9275: $r->print("\n<br />");
9276: $i++;
9277: }
1.194 albertel 9278: }
9279: }
1.273 albertel 9280: if ($$scan_record{'scantron.CODE'}=~/\S/ ) {
1.569 bisitz 9281: my $checked; if (!$i) { $checked=' checked="checked"'; }
1.492 albertel 9282: $r->print("
9283: <label>
1.569 bisitz 9284: <input type='radio' name='scantron_CODE_resolution' value='use_unfound'$checked />
1.596.2.6 raeburn 9285: ".&mt("Use the CODE [_1] that was on the paper, ignoring the error.",
1.492 albertel 9286: "<b><tt>".$$scan_record{'scantron.CODE'}."</tt></b>")."
9287: </label>");
1.273 albertel 9288: $r->print("\n<br />");
9289: }
1.194 albertel 9290:
1.596.2.12.2. 1(raebur 9291:0): $r->print(&Apache::lonhtmlcommon::scripttag(<<ENDSCRIPT));
1.188 albertel 9292: function change_radio(field) {
1.190 albertel 9293: var slct=document.scantronupload.scantron_CODE_resolution;
1.188 albertel 9294: var i;
9295: for (i=0;i<slct.length;i++) {
9296: if (slct[i].value==field) { slct[i].checked=true; }
9297: }
9298: }
9299: ENDSCRIPT
1.187 albertel 9300: my $href="/adm/pickcode?".
1.359 www 9301: "form=".&escape("scantronupload").
9302: "&scantron_format=".&escape($env{'form.scantron_format'}).
9303: "&scantron_CODElist=".&escape($env{'form.scantron_CODElist'}).
9304: "&curCODE=".&escape($$scan_record{'scantron.CODE'}).
9305: "&scantron_selectfile=".&escape($env{'form.scantron_selectfile'});
1.332 albertel 9306: if ($env{'form.scantron_CODElist'} =~ /\S/) {
1.492 albertel 9307: $r->print("
9308: <label>
9309: <input type='radio' name='scantron_CODE_resolution' value='use_found' />
9310: ".&mt("[_1]Select[_2] a CODE from the list of all CODEs and use it.",
9311: "<a target='_blank' href='$href'>","</a>")."
9312: </label>
1.558 bisitz 9313: ".&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 9314: $r->print("\n<br />");
9315: }
1.492 albertel 9316: $r->print("
9317: <label>
9318: <input type='radio' name='scantron_CODE_resolution' value='use_typed' />
9319: ".&mt("Use [_1] as the CODE.",
9320: "</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 9321: $r->print("\n<br /><br />");
1.157 albertel 9322: } elsif ($error eq 'doublebubble') {
1.596.2.6 raeburn 9323: $r->print('<p class="LC_warning">'.&mt("There have been multiple bubbles scanned for some question(s)")."</p>\n");
1.497 foxr 9324:
9325: # The form field scantron_questions is acutally a list of line numbers.
9326: # represented by this form so:
9327:
1.596.2.12.2. 6(raebur 9328:3): my $line_list = &questions_to_line_list($arg,$randomorder,$randompick,
9329:3): $respnumlookup,$startline);
1.497 foxr 9330:
1.157 albertel 9331: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 9332: $line_list.'" />');
1.242 albertel 9333: $r->print($message);
1.492 albertel 9334: $r->print("<p>".&mt("Please indicate which bubble should be used for grading")."</p>");
1.157 albertel 9335: foreach my $question (@{$arg}) {
1.503 raeburn 9336: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
1.596.2.12.2. 6(raebur 9337:3): $scan_record, $error,
9338:3): $randomorder,$randompick,
9339:3): $respnumlookup,$startline);
1.524 raeburn 9340: push(@lines_to_correct,@linenums);
1.157 albertel 9341: }
1.503 raeburn 9342: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 9343: } elsif ($error eq 'missingbubble') {
1.596.2.9 raeburn 9344: $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 9345: $r->print($message);
1.492 albertel 9346: $r->print("<p>".&mt("Please indicate which bubble should be used for grading.")."</p>");
1.503 raeburn 9347: $r->print(&mt("Some questions have no scanned bubbles.")."\n");
1.497 foxr 9348:
1.503 raeburn 9349: # The form field scantron_questions is actually a list of line numbers not
1.497 foxr 9350: # a list of question numbers. Therefore:
9351: #
9352:
1.596.2.12.2. 6(raebur 9353:3): my $line_list = &questions_to_line_list($arg,$randomorder,$randompick,
9354:3): $respnumlookup,$startline);
1.497 foxr 9355:
1.157 albertel 9356: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 9357: $line_list.'" />');
1.157 albertel 9358: foreach my $question (@{$arg}) {
1.503 raeburn 9359: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
1.596.2.12.2. 6(raebur 9360:3): $scan_record, $error,
9361:3): $randomorder,$randompick,
9362:3): $respnumlookup,$startline);
1.524 raeburn 9363: push(@lines_to_correct,@linenums);
1.157 albertel 9364: }
1.503 raeburn 9365: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 9366: } else {
9367: $r->print("\n<ul>");
9368: }
9369: $r->print("\n</li></ul>");
1.497 foxr 9370: }
9371:
1.503 raeburn 9372: sub verify_bubbles_checked {
9373: my (@ansnums) = @_;
9374: my $ansnumstr = join('","',@ansnums);
9375: 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 9376:6): &js_escape(\$warning);
1(raebur 9377:0): my $output = &Apache::lonhtmlcommon::scripttag(<<ENDSCRIPT);
1.503 raeburn 9378: function verify_bubble_radio(form) {
9379: var ansnumArray = new Array ("$ansnumstr");
9380: var need_bubble_count = 0;
9381: for (var i=0; i<ansnumArray.length; i++) {
9382: if (form.elements["scantron_correct_Q_"+ansnumArray[i]].length > 1) {
9383: var bubble_picked = 0;
9384: for (var j=0; j<form.elements["scantron_correct_Q_"+ansnumArray[i]].length; j++) {
9385: if (form.elements["scantron_correct_Q_"+ansnumArray[i]][j].checked == true) {
9386: bubble_picked = 1;
9387: }
9388: }
9389: if (bubble_picked == 0) {
9390: need_bubble_count ++;
9391: }
9392: }
9393: }
9394: if (need_bubble_count) {
9395: alert("$warning");
9396: return;
9397: }
9398: form.submit();
9399: }
9400: ENDSCRIPT
9401: return $output;
9402: }
9403:
1.497 foxr 9404: =pod
9405:
9406: =item questions_to_line_list
1.157 albertel 9407:
1.497 foxr 9408: Converts a list of questions into a string of comma separated
9409: line numbers in the answer sheet used by the questions. This is
9410: used to fill in the scantron_questions form field.
9411:
9412: Arguments:
9413: questions - Reference to an array of questions.
1.596.2.12.2. 6(raebur 9414:3): randomorder - True if randomorder in use.
9415:3): randompick - True if randompick in use.
9416:3): respnumlookup - Reference to HASH mapping question numbers in bubble lines
9417:3): for current line to question number used for same question
9418:3): in "Master Seqence" (as seen by Course Coordinator).
9419:3): startline - Reference to hash where key is question number (0 is first)
9420:3): and key is number of first bubble line for current student
9421:3): or code-based randompick and/or randomorder.
1.497 foxr 9422:
9423: =cut
9424:
9425:
9426: sub questions_to_line_list {
1.596.2.12.2. 6(raebur 9427:3): my ($questions,$randomorder,$randompick,$respnumlookup,$startline) = @_;
1.497 foxr 9428: my @lines;
9429:
1.503 raeburn 9430: foreach my $item (@{$questions}) {
9431: my $question = $item;
9432: my ($first,$count,$last);
9433: if ($item =~ /^(\d+)\.(\d+)$/) {
9434: $question = $1;
9435: my $subquestion = $2;
1.596.2.12.2. 6(raebur 9436:3): my $responsenum = $question-1;
9437:3): if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
9438:3): $responsenum = $respnumlookup->{$question-1};
9439:3): if (ref($startline) eq 'HASH') {
9440:3): $first = $startline->{$question-1} + 1;
9441:3): }
9442:3): } else {
9443:3): $first = $first_bubble_line{$responsenum} + 1;
9444:3): }
7(raebur 9445:3): my @subans = split(/,/,$subdivided_bubble_lines{$responsenum});
1.503 raeburn 9446: my $subcount = 1;
9447: while ($subcount<$subquestion) {
9448: $first += $subans[$subcount-1];
9449: $subcount ++;
9450: }
9451: $count = $subans[$subquestion-1];
9452: } else {
1.596.2.12.2. 7(raebur 9453:3): my $responsenum = $question-1;
9454:3): if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
9455:3): $responsenum = $respnumlookup->{$question-1};
9456:3): if (ref($startline) eq 'HASH') {
9457:3): $first = $startline->{$question-1} + 1;
9458:3): }
9459:3): } else {
9460:3): $first = $first_bubble_line{$responsenum} + 1;
9461:3): }
9462:3): $count = $bubble_lines_per_response{$responsenum};
1.503 raeburn 9463: }
1.506 raeburn 9464: $last = $first+$count-1;
1.503 raeburn 9465: push(@lines, ($first..$last));
1.497 foxr 9466: }
9467: return join(',', @lines);
9468: }
9469:
9470: =pod
9471:
9472: =item prompt_for_corrections
9473:
9474: Prompts for a potentially multiline correction to the
9475: user's bubbling (factors out common code from scantron_get_correction
9476: for multi and missing bubble cases).
9477:
9478: Arguments:
9479: $r - Apache request object.
9480: $question - The question number to prompt for.
9481: $scan_config - The scantron file configuration hash.
9482: $scan_record - Reference to the hash that has the the parsed scanlines.
1.503 raeburn 9483: $error - Type of error
1.596.2.12.2. 7(raebur 9484:3): $randomorder - True if randomorder in use.
9485:3): $randompick - True if randompick in use.
9486:3): $respnumlookup - Reference to HASH mapping question numbers in bubble lines
9487:3): for current line to question number used for same question
9488:3): in "Master Seqence" (as seen by Course Coordinator).
9489:3): $startline - Reference to hash where key is question number (0 is first)
9490:3): and value is number of first bubble line for current student
9491:3): or code-based randompick and/or randomorder.
1.497 foxr 9492:
9493: Implicit inputs:
9494: %bubble_lines_per_response - Starting line numbers for each question.
9495: Numbered from 0 (but question numbers are from
9496: 1.
9497: %first_bubble_line - Starting bubble line for each question.
1.509 raeburn 9498: %subdivided_bubble_lines - optionresponse, matchresponse and rankresponse
9499: type problems render as separate sub-questions,
1.503 raeburn 9500: in exam mode. This hash contains a
9501: comma-separated list of the lines per
9502: sub-question.
1.510 raeburn 9503: %responsetype_per_response - essayresponse, formularesponse,
9504: stringresponse, imageresponse, reactionresponse,
9505: and organicresponse type problem parts can have
1.503 raeburn 9506: multiple lines per response if the weight
9507: assigned exceeds 10. In this case, only
9508: one bubble per line is permitted, but more
9509: than one line might contain bubbles, e.g.
9510: bubbling of: line 1 - J, line 2 - J,
9511: line 3 - B would assign 22 points.
1.497 foxr 9512:
9513: =cut
9514:
9515: sub prompt_for_corrections {
1.596.2.12.2. 6(raebur 9516:3): my ($r, $question, $scan_config, $scan_record, $error, $randomorder,
9517:3): $randompick, $respnumlookup, $startline) = @_;
1.503 raeburn 9518: my ($current_line,$lines);
9519: my @linenums;
9520: my $questionnum = $question;
1.596.2.12.2. 6(raebur 9521:3): my ($first,$responsenum);
1.503 raeburn 9522: if ($question =~ /^(\d+)\.(\d+)$/) {
9523: $question = $1;
9524: my $subquestion = $2;
1.596.2.12.2. 6(raebur 9525:3): if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
9526:3): $responsenum = $respnumlookup->{$question-1};
9527:3): if (ref($startline) eq 'HASH') {
9528:3): $first = $startline->{$question-1};
9529:3): }
9530:3): } else {
9531:3): $responsenum = $question-1;
7(raebur 9532:4): $first = $first_bubble_line{$responsenum};
6(raebur 9533:3): }
9534:3): $current_line = $first + 1 ;
9535:3): my @subans = split(/,/,$subdivided_bubble_lines{$responsenum});
1.503 raeburn 9536: my $subcount = 1;
9537: while ($subcount<$subquestion) {
9538: $current_line += $subans[$subcount-1];
9539: $subcount ++;
9540: }
9541: $lines = $subans[$subquestion-1];
9542: } else {
1.596.2.12.2. 6(raebur 9543:3): if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH')) {
9544:3): $responsenum = $respnumlookup->{$question-1};
9545:3): if (ref($startline) eq 'HASH') {
9546:3): $first = $startline->{$question-1};
9547:3): }
9548:3): } else {
9549:3): $responsenum = $question-1;
9550:3): $first = $first_bubble_line{$responsenum};
9551:3): }
9552:3): $current_line = $first + 1;
9553:3): $lines = $bubble_lines_per_response{$responsenum};
1.503 raeburn 9554: }
1.497 foxr 9555: if ($lines > 1) {
1.503 raeburn 9556: $r->print(&mt('The group of bubble lines below responds to a single question.').'<br />');
1.596.2.12.2. 6(raebur 9557:3): if (($responsetype_per_response{$responsenum} eq 'essayresponse') ||
9558:3): ($responsetype_per_response{$responsenum} eq 'formularesponse') ||
9559:3): ($responsetype_per_response{$responsenum} eq 'stringresponse') ||
9560:3): ($responsetype_per_response{$responsenum} eq 'imageresponse') ||
9561:3): ($responsetype_per_response{$responsenum} eq 'reactionresponse') ||
9562:3): ($responsetype_per_response{$responsenum} eq 'organicresponse')) {
4(raebur 9563: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 9564: } else {
9565: $r->print(&mt("Select at most one bubble in a single line and select 'No Bubble' in all the other lines. ")."<br />");
9566: }
1.497 foxr 9567: }
9568: for (my $i =0; $i < $lines; $i++) {
1.503 raeburn 9569: my $selected = $$scan_record{"scantron.$current_line.answer"};
1.596.2.12.2. 6(raebur 9570:3): &scantron_bubble_selector($r,$scan_config,$current_line,
1.503 raeburn 9571: $questionnum,$error,split('', $selected));
1.524 raeburn 9572: push(@linenums,$current_line);
1.497 foxr 9573: $current_line++;
9574: }
9575: if ($lines > 1) {
9576: $r->print("<hr /><br />");
9577: }
1.503 raeburn 9578: return @linenums;
1.157 albertel 9579: }
1.423 albertel 9580:
9581: =pod
9582:
9583: =item scantron_bubble_selector
9584:
9585: Generates the html radiobuttons to correct a single bubble line
1.424 albertel 9586: possibly showing the existing the selected bubbles if known
1.423 albertel 9587:
9588: Arguments:
9589: $r - Apache request object
1.596.2.12.2. 9(raebur 9590:9): $scan_config - hash from &Apache::lonnet::get_scantron_config()
1.497 foxr 9591: $line - Number of the line being displayed.
1.503 raeburn 9592: $questionnum - Question number (may include subquestion)
9593: $error - Type of error.
1.497 foxr 9594: @selected - Array of bubbles picked on this line.
1.423 albertel 9595:
9596: =cut
9597:
1.157 albertel 9598: sub scantron_bubble_selector {
1.503 raeburn 9599: my ($r,$scan_config,$line,$questionnum,$error,@selected)=@_;
1.157 albertel 9600: my $max=$$scan_config{'Qlength'};
1.274 albertel 9601:
9602: my $scmode=$$scan_config{'Qon'};
1.596.2.12.2. (raeburn 9603:): if ($scmode eq 'number' || $scmode eq 'letter') {
9604:): if (($$scan_config{'BubblesPerRow'} =~ /^\d+$/) &&
9605:): ($$scan_config{'BubblesPerRow'} > 0)) {
9606:): $max=$$scan_config{'BubblesPerRow'};
9607:): if (($scmode eq 'number') && ($max > 10)) {
9608:): $max = 10;
9609:): } elsif (($scmode eq 'letter') && $max > 26) {
9610:): $max = 26;
9611:): }
9612:): } else {
9613:): $max = 10;
9614:): }
9615:): }
1.274 albertel 9616:
1.157 albertel 9617: my @alphabet=('A'..'Z');
1.503 raeburn 9618: $r->print(&Apache::loncommon::start_data_table().
9619: &Apache::loncommon::start_data_table_row());
9620: $r->print('<td rowspan="2" class="LC_leftcol_header">'.$line.'</td>');
1.497 foxr 9621: for (my $i=0;$i<$max+1;$i++) {
9622: $r->print("\n".'<td align="center">');
9623: if ($selected[0] eq $alphabet[$i]) { $r->print('X'); shift(@selected) }
9624: else { $r->print(' '); }
9625: $r->print('</td>');
9626: }
1.503 raeburn 9627: $r->print(&Apache::loncommon::end_data_table_row().
9628: &Apache::loncommon::start_data_table_row());
1.497 foxr 9629: for (my $i=0;$i<$max;$i++) {
9630: $r->print("\n".
9631: '<td><label><input type="radio" name="scantron_correct_Q_'.
9632: $line.'" value="'.$i.'" />'.$alphabet[$i]."</label></td>");
9633: }
1.503 raeburn 9634: my $nobub_checked = ' ';
9635: if ($error eq 'missingbubble') {
9636: $nobub_checked = ' checked = "checked" ';
9637: }
9638: $r->print("\n".'<td><label><input type="radio" name="scantron_correct_Q_'.
9639: $line.'" value="none"'.$nobub_checked.'/>'.&mt('No bubble').
9640: '</label>'."\n".'<input type="hidden" name="scantron_questionnum_Q_'.
9641: $line.'" value="'.$questionnum.'" /></td>');
9642: $r->print(&Apache::loncommon::end_data_table_row().
9643: &Apache::loncommon::end_data_table());
1.157 albertel 9644: }
9645:
1.423 albertel 9646: =pod
9647:
9648: =item num_matches
9649:
1.424 albertel 9650: Counts the number of characters that are the same between the two arguments.
9651:
9652: Arguments:
9653: $orig - CODE from the scanline
9654: $code - CODE to match against
9655:
9656: Returns:
9657: $count - integer count of the number of same characters between the
9658: two arguments
9659:
1.423 albertel 9660: =cut
9661:
1.194 albertel 9662: sub num_matches {
9663: my ($orig,$code) = @_;
9664: my @code=split(//,$code);
9665: my @orig=split(//,$orig);
9666: my $same=0;
9667: for (my $i=0;$i<scalar(@code);$i++) {
9668: if ($code[$i] eq $orig[$i]) { $same++; }
9669: }
9670: return $same;
9671: }
9672:
1.423 albertel 9673: =pod
9674:
9675: =item scantron_get_closely_matching_CODEs
9676:
1.424 albertel 9677: Cycles through all CODEs and finds the set that has the greatest
9678: number of same characters as the provided CODE
9679:
9680: Arguments:
9681: $allcodes - hash ref returned by &get_codes()
9682: $CODE - CODE from the current scanline
9683:
9684: Returns:
9685: 2 element list
9686: - first elements is number of how closely matching the best fit is
9687: (5 means best set has 5 matching characters)
9688: - second element is an arrary ref containing the set of valid CODEs
9689: that best fit the passed in CODE
9690:
1.423 albertel 9691: =cut
9692:
1.194 albertel 9693: sub scantron_get_closely_matching_CODEs {
9694: my ($allcodes,$CODE)=@_;
9695: my @CODEs;
9696: foreach my $testcode (sort(keys(%{$allcodes}))) {
9697: push(@{$CODEs[&num_matches($CODE,$testcode)]},$testcode);
9698: }
9699:
9700: return ($#CODEs,$CODEs[-1]);
9701: }
9702:
1.423 albertel 9703: =pod
9704:
9705: =item get_codes
9706:
1.424 albertel 9707: Builds a hash which has keys of all of the valid CODEs from the selected
9708: set of remembered CODEs.
9709:
9710: Arguments:
9711: $old_name - name of the set of remembered CODEs
9712: $cdom - domain of the course
9713: $cnum - internal course name
9714:
9715: Returns:
9716: %allcodes - keys are the valid CODEs, values are all 1
9717:
1.423 albertel 9718: =cut
9719:
1.194 albertel 9720: sub get_codes {
1.280 foxr 9721: my ($old_name, $cdom, $cnum) = @_;
9722: if (!$old_name) {
9723: $old_name=$env{'form.scantron_CODElist'};
9724: }
9725: if (!$cdom) {
9726: $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
9727: }
9728: if (!$cnum) {
9729: $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
9730: }
1.278 albertel 9731: my %result=&Apache::lonnet::get('CODEs',[$old_name,"type\0$old_name"],
9732: $cdom,$cnum);
9733: my %allcodes;
9734: if ($result{"type\0$old_name"} eq 'number') {
9735: %allcodes=map {($_,1)} split(',',$result{$old_name});
9736: } else {
9737: %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
9738: }
1.194 albertel 9739: return %allcodes;
9740: }
9741:
1.423 albertel 9742: =pod
9743:
9744: =item scantron_validate_CODE
9745:
1.424 albertel 9746: Validates all scanlines in the selected file to not have any
9747: invalid or underspecified CODEs and that none of the codes are
9748: duplicated if this was requested.
9749:
1.423 albertel 9750: =cut
9751:
1.157 albertel 9752: sub scantron_validate_CODE {
9753: my ($r,$currentphase) = @_;
1.596.2.12.2. 9(raebur 9754:9): my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.186 albertel 9755: if ($scantron_config{'CODElocation'} &&
9756: $scantron_config{'CODEstart'} &&
9757: $scantron_config{'CODElength'}) {
1.257 albertel 9758: if (!defined($env{'form.scantron_CODElist'})) {
1.186 albertel 9759: &FIXME_blow_up()
9760: }
9761: } else {
9762: return (0,$currentphase+1);
9763: }
9764:
9765: my %usedCODEs;
9766:
1.194 albertel 9767: my %allcodes=&get_codes();
1.186 albertel 9768:
1.582 raeburn 9769: my $nav_error;
1.596.2.12.2. (raeburn 9770:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the lines per response array.
1.582 raeburn 9771: if ($nav_error) {
9772: $r->print(&navmap_errormsg());
9773: return(1,$currentphase);
9774: }
1.447 foxr 9775:
1.186 albertel 9776: my ($scanlines,$scan_data)=&scantron_getfile();
9777: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 9778: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.186 albertel 9779: if ($line=~/^[\s\cz]*$/) { next; }
9780: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
9781: $scan_data);
9782: my $CODE=$$scan_record{'scantron.CODE'};
9783: my $error=0;
1.224 albertel 9784: if (!&Apache::lonnet::validCODE($CODE)) {
9785: &scantron_get_correction($r,$i,$scan_record,
9786: \%scantron_config,
9787: $line,'incorrectCODE',\%allcodes);
9788: return(1,$currentphase);
9789: }
1.221 albertel 9790: if (%allcodes && !exists($allcodes{$CODE})
9791: && !$$scan_record{'scantron.useCODE'}) {
1.186 albertel 9792: &scantron_get_correction($r,$i,$scan_record,
9793: \%scantron_config,
1.194 albertel 9794: $line,'incorrectCODE',\%allcodes);
9795: return(1,$currentphase);
1.186 albertel 9796: }
1.214 albertel 9797: if (exists($usedCODEs{$CODE})
1.257 albertel 9798: && $env{'form.scantron_CODEunique'} eq 'yes'
1.192 albertel 9799: && !$$scan_record{'scantron.CODE_ignore_dup'}) {
1.186 albertel 9800: &scantron_get_correction($r,$i,$scan_record,
9801: \%scantron_config,
1.194 albertel 9802: $line,'duplicateCODE',$usedCODEs{$CODE});
9803: return(1,$currentphase);
1.186 albertel 9804: }
1.524 raeburn 9805: push(@{$usedCODEs{$CODE}},$$scan_record{'scantron.PaperID'});
1.186 albertel 9806: }
1.157 albertel 9807: return (0,$currentphase+1);
9808: }
9809:
1.423 albertel 9810: =pod
9811:
9812: =item scantron_validate_doublebubble
9813:
1.424 albertel 9814: Validates all scanlines in the selected file to not have any
9815: bubble lines with multiple bubbles marked.
9816:
1.423 albertel 9817: =cut
9818:
1.157 albertel 9819: sub scantron_validate_doublebubble {
9820: my ($r,$currentphase) = @_;
9821: #get student info
9822: my $classlist=&Apache::loncoursedata::get_classlist();
9823: my %idmap=&username_to_idmap($classlist);
1.596.2.12.2. 6(raebur 9824:3): my (undef,undef,$sequence)=
9825:3): &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.157 albertel 9826:
9827: #get scantron line setup
1.596.2.12.2. 9(raebur 9828:9): my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.157 albertel 9829: my ($scanlines,$scan_data)=&scantron_getfile();
1.596.2.12.2. 6(raebur 9830:3):
9831:3): my $navmap = Apache::lonnavmaps::navmap->new();
9832:3): unless (ref($navmap)) {
9833:3): $r->print(&navmap_errormsg());
9834:3): return(1,$currentphase);
9835:3): }
9836:3): my $map=$navmap->getResourceByUrl($sequence);
9837:3): my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
9838:3): my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
9839:3): %grader_randomlists_by_symb,%orderedforcode,%respnumlookup,%startline);
9840:3): my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
9841:3):
1.583 raeburn 9842: my $nav_error;
1.596.2.12.2. 6(raebur 9843:3): if (ref($map)) {
9844:3): $randomorder = $map->randomorder();
9845:3): $randompick = $map->randompick();
0(raebur 9846:2): unless ($randomorder || $randompick) {
9847:2): foreach my $res ($navmap->retrieveResources($map,sub { $_[0]->is_map() },1,0,1)) {
9848:2): if ($res->randomorder()) {
9849:2): $randomorder = 1;
9850:2): }
9851:2): if ($res->randompick()) {
9852:2): $randompick = 1;
9853:2): }
9854:2): last if ($randomorder || $randompick);
9855:2): }
9856:2): }
6(raebur 9857:3): if ($randomorder || $randompick) {
9858:3): $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource);
9859:3): if ($nav_error) {
9860:3): $r->print(&navmap_errormsg());
9861:3): return(1,$currentphase);
9862:3): }
9863:3): &graders_resources_pass(\@resources,\%grader_partids_by_symb,
9864:3): \%grader_randomlists_by_symb,$bubbles_per_row);
9865:3): }
9866:3): } else {
9867:3): $r->print(&navmap_errormsg());
9868:3): return(1,$currentphase);
9869:3): }
9870:3):
(raeburn 9871:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # parse needs the bubble line array.
1.583 raeburn 9872: if ($nav_error) {
9873: $r->print(&navmap_errormsg());
9874: return(1,$currentphase);
9875: }
1.447 foxr 9876:
1.157 albertel 9877: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 9878: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 9879: if ($line=~/^[\s\cz]*$/) { next; }
9880: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
1.596.2.12.2. 6(raebur 9881:3): $scan_data,undef,\%idmap,$randomorder,
9882:3): $randompick,$sequence,\@master_seq,
9883:3): \%symb_to_resource,\%grader_partids_by_symb,
9884:3): \%orderedforcode,\%respnumlookup,\%startline);
1.157 albertel 9885: if (!defined($$scan_record{'scantron.doubleerror'})) { next; }
9886: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,$line,
9887: 'doublebubble',
1.596.2.12.2. 6(raebur 9888:3): $$scan_record{'scantron.doubleerror'},
9889:3): $randomorder,$randompick,\%respnumlookup,\%startline);
1.157 albertel 9890: return (1,$currentphase);
9891: }
9892: return (0,$currentphase+1);
9893: }
9894:
1.423 albertel 9895:
1.503 raeburn 9896: sub scantron_get_maxbubble {
1.596.2.12.2. (raeburn 9897:): my ($nav_error,$scantron_config) = @_;
1.257 albertel 9898: if (defined($env{'form.scantron_maxbubble'}) &&
9899: $env{'form.scantron_maxbubble'}) {
1.447 foxr 9900: &restore_bubble_lines();
1.257 albertel 9901: return $env{'form.scantron_maxbubble'};
1.191 albertel 9902: }
1.330 albertel 9903:
1.447 foxr 9904: my (undef, undef, $sequence) =
1.257 albertel 9905: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.330 albertel 9906:
1.447 foxr 9907: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 9908: unless (ref($navmap)) {
9909: if (ref($nav_error)) {
9910: $$nav_error = 1;
9911: }
1.591 raeburn 9912: return;
1.582 raeburn 9913: }
1.191 albertel 9914: my $map=$navmap->getResourceByUrl($sequence);
9915: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.596.2.12.2. (raeburn 9916:): my $bubbles_per_row = &bubblesheet_bubbles_per_row($scantron_config);
1.330 albertel 9917:
9918: &Apache::lonxml::clear_problem_counter();
9919:
1.557 raeburn 9920: my $uname = $env{'user.name'};
9921: my $udom = $env{'user.domain'};
1.435 foxr 9922: my $cid = $env{'request.course.id'};
9923: my $total_lines = 0;
9924: %bubble_lines_per_response = ();
1.447 foxr 9925: %first_bubble_line = ();
1.503 raeburn 9926: %subdivided_bubble_lines = ();
9927: %responsetype_per_response = ();
1.596.2.12.2. 6(raebur 9928:3): %masterseq_id_responsenum = ();
1.554 raeburn 9929:
1.447 foxr 9930: my $response_number = 0;
9931: my $bubble_line = 0;
1.191 albertel 9932: foreach my $resource (@resources) {
1.596.2.12.2. 6(raebur 9933:3): my $resid = $resource->id();
(raeburn 9934:): my ($analysis,$parts) = &scantron_partids_tograde($resource,$cid,$uname,
7(raebur 9935:3): $udom,undef,$bubbles_per_row);
1.542 raeburn 9936: if ((ref($analysis) eq 'HASH') && (ref($parts) eq 'ARRAY')) {
9937: foreach my $part_id (@{$parts}) {
9938: my $lines;
9939:
9940: # TODO - make this a persistent hash not an array.
9941:
9942: # optionresponse, matchresponse and rankresponse type items
9943: # render as separate sub-questions in exam mode.
9944: if (($analysis->{$part_id.'.type'} eq 'optionresponse') ||
9945: ($analysis->{$part_id.'.type'} eq 'matchresponse') ||
9946: ($analysis->{$part_id.'.type'} eq 'rankresponse')) {
9947: my ($numbub,$numshown);
9948: if ($analysis->{$part_id.'.type'} eq 'optionresponse') {
9949: if (ref($analysis->{$part_id.'.options'}) eq 'ARRAY') {
9950: $numbub = scalar(@{$analysis->{$part_id.'.options'}});
9951: }
9952: } elsif ($analysis->{$part_id.'.type'} eq 'matchresponse') {
9953: if (ref($analysis->{$part_id.'.items'}) eq 'ARRAY') {
9954: $numbub = scalar(@{$analysis->{$part_id.'.items'}});
9955: }
9956: } elsif ($analysis->{$part_id.'.type'} eq 'rankresponse') {
9957: if (ref($analysis->{$part_id.'.foils'}) eq 'ARRAY') {
9958: $numbub = scalar(@{$analysis->{$part_id.'.foils'}});
9959: }
9960: }
9961: if (ref($analysis->{$part_id.'.shown'}) eq 'ARRAY') {
9962: $numshown = scalar(@{$analysis->{$part_id.'.shown'}});
9963: }
1.596.2.12.2. (raeburn 9964:): my $bubbles_per_row =
9965:): &bubblesheet_bubbles_per_row($scantron_config);
9966:): my $inner_bubble_lines = int($numbub/$bubbles_per_row);
9967:): if (($numbub % $bubbles_per_row) != 0) {
1.542 raeburn 9968: $inner_bubble_lines++;
9969: }
9970: for (my $i=0; $i<$numshown; $i++) {
9971: $subdivided_bubble_lines{$response_number} .=
9972: $inner_bubble_lines.',';
9973: }
9974: $subdivided_bubble_lines{$response_number} =~ s/,$//;
9975: $lines = $numshown * $inner_bubble_lines;
9976: } else {
9977: $lines = $analysis->{"$part_id.bubble_lines"};
1.596.2.12.2. (raeburn 9978:): }
1.542 raeburn 9979:
9980: $first_bubble_line{$response_number} = $bubble_line;
9981: $bubble_lines_per_response{$response_number} = $lines;
9982: $responsetype_per_response{$response_number} =
9983: $analysis->{$part_id.'.type'};
1.596.2.12.2. 6(raebur 9984:3): $masterseq_id_responsenum{$resid.'_'.$part_id} = $response_number;
1.542 raeburn 9985: $response_number++;
9986:
9987: $bubble_line += $lines;
9988: $total_lines += $lines;
9989: }
9990: }
9991: }
1.552 raeburn 9992: &Apache::lonnet::delenv('scantron.');
1.542 raeburn 9993:
9994: &save_bubble_lines();
9995: $env{'form.scantron_maxbubble'} =
9996: $total_lines;
9997: return $env{'form.scantron_maxbubble'};
9998: }
1.523 raeburn 9999:
1.596.2.12.2. (raeburn 10000:): sub bubblesheet_bubbles_per_row {
10001:): my ($scantron_config) = @_;
10002:): my $bubbles_per_row;
10003:): if (ref($scantron_config) eq 'HASH') {
10004:): $bubbles_per_row = $scantron_config->{'BubblesPerRow'};
10005:): }
10006:): if ((!$bubbles_per_row) || ($bubbles_per_row < 1)) {
10007:): $bubbles_per_row = 10;
10008:): }
10009:): return $bubbles_per_row;
10010:): }
10011:):
1.157 albertel 10012: sub scantron_validate_missingbubbles {
10013: my ($r,$currentphase) = @_;
10014: #get student info
10015: my $classlist=&Apache::loncoursedata::get_classlist();
10016: my %idmap=&username_to_idmap($classlist);
1.596.2.12.2. 6(raebur 10017:3): my (undef,undef,$sequence)=
10018:3): &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.157 albertel 10019:
10020: #get scantron line setup
1.596.2.12.2. 9(raebur 10021:9): my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
1.157 albertel 10022: my ($scanlines,$scan_data)=&scantron_getfile();
1.596.2.12.2. 6(raebur 10023:3):
10024:3): my $navmap = Apache::lonnavmaps::navmap->new();
10025:3): unless (ref($navmap)) {
10026:3): $r->print(&navmap_errormsg());
10027:3): return(1,$currentphase);
10028:3): }
10029:3):
10030:3): my $map=$navmap->getResourceByUrl($sequence);
10031:3): my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
10032:3): my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
10033:3): %grader_randomlists_by_symb,%orderedforcode,%respnumlookup,%startline);
10034:3): my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
10035:3):
1.582 raeburn 10036: my $nav_error;
1.596.2.12.2. 6(raebur 10037:3): if (ref($map)) {
10038:3): $randomorder = $map->randomorder();
10039:3): $randompick = $map->randompick();
0(raebur 10040:2): unless ($randomorder || $randompick) {
10041:2): foreach my $res ($navmap->retrieveResources($map,sub { $_[0]->is_map() },1,0,1)) {
10042:2): if ($res->randomorder()) {
10043:2): $randomorder = 1;
10044:2): }
10045:2): if ($res->randompick()) {
10046:2): $randompick = 1;
10047:2): }
10048:2): last if ($randomorder || $randompick);
10049:2): }
10050:2): }
7(raebur 10051:3): if ($randomorder || $randompick) {
10052:3): $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource);
10053:3): if ($nav_error) {
10054:3): $r->print(&navmap_errormsg());
10055:3): return(1,$currentphase);
10056:3): }
10057:3): &graders_resources_pass(\@resources,\%grader_partids_by_symb,
10058:3): \%grader_randomlists_by_symb,$bubbles_per_row);
10059:3): }
6(raebur 10060:3): } else {
10061:3): $r->print(&navmap_errormsg());
7(raebur 10062:3): return(1,$currentphase);
6(raebur 10063:3): }
10064:3):
10065:3):
(raeburn 10066:): my $max_bubble=&scantron_get_maxbubble(\$nav_error,\%scantron_config);
1.582 raeburn 10067: if ($nav_error) {
1.596.2.12.2. 6(raebur 10068:3): $r->print(&navmap_errormsg());
1.582 raeburn 10069: return(1,$currentphase);
10070: }
1.596.2.12.2. 6(raebur 10071:3):
1.157 albertel 10072: if (!$max_bubble) { $max_bubble=2**31; }
10073: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 10074: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 10075: if ($line=~/^[\s\cz]*$/) { next; }
1.596.2.12.2. 6(raebur 10076:3): my $scan_record =
10077:3): &scantron_parse_scanline($line,$i,\%scantron_config,$scan_data,undef,\%idmap,
10078:3): $randomorder,$randompick,$sequence,\@master_seq,
10079:3): \%symb_to_resource,\%grader_partids_by_symb,
10080:3): \%orderedforcode,\%respnumlookup,\%startline);
1.157 albertel 10081: if (!defined($$scan_record{'scantron.missingerror'})) { next; }
10082: my @to_correct;
1.470 foxr 10083:
10084: # Probably here's where the error is...
10085:
1.157 albertel 10086: foreach my $missing (@{$$scan_record{'scantron.missingerror'}}) {
1.505 raeburn 10087: my $lastbubble;
10088: if ($missing =~ /^(\d+)\.(\d+)$/) {
1.596.2.12.2. 6(raebur 10089:3): my $question = $1;
10090:3): my $subquestion = $2;
10091:3): my ($first,$responsenum);
10092:3): if ($randomorder || $randompick) {
10093:3): $responsenum = $respnumlookup{$question-1};
10094:3): $first = $startline{$question-1};
10095:3): } else {
10096:3): $responsenum = $question-1;
10097:3): $first = $first_bubble_line{$responsenum};
10098:3): }
10099:3): if (!defined($first)) { next; }
7(raebur 10100:3): my @subans = split(/,/,$subdivided_bubble_lines{$responsenum});
6(raebur 10101:3): my $subcount = 1;
10102:3): while ($subcount<$subquestion) {
10103:3): $first += $subans[$subcount-1];
10104:3): $subcount ++;
10105:3): }
10106:3): my $count = $subans[$subquestion-1];
10107:3): $lastbubble = $first + $count;
1.505 raeburn 10108: } else {
1.596.2.12.2. 6(raebur 10109:3): my ($first,$responsenum);
10110:3): if ($randomorder || $randompick) {
10111:3): $responsenum = $respnumlookup{$missing-1};
10112:3): $first = $startline{$missing-1};
10113:3): } else {
10114:3): $responsenum = $missing-1;
10115:3): $first = $first_bubble_line{$responsenum};
10116:3): }
10117:3): if (!defined($first)) { next; }
10118:3): $lastbubble = $first + $bubble_lines_per_response{$responsenum};
1.505 raeburn 10119: }
10120: if ($lastbubble > $max_bubble) { next; }
1.157 albertel 10121: push(@to_correct,$missing);
10122: }
10123: if (@to_correct) {
10124: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
1.596.2.12.2. 6(raebur 10125:3): $line,'missingbubble',\@to_correct,
10126:3): $randomorder,$randompick,\%respnumlookup,
10127:3): \%startline);
1.157 albertel 10128: return (1,$currentphase);
10129: }
10130:
10131: }
10132: return (0,$currentphase+1);
10133: }
10134:
1.596.2.12.2. (raeburn 10135:): sub hand_bubble_option {
10136:): my (undef, undef, $sequence) =
10137:): &Apache::lonnet::decode_symb($env{'form.selectpage'});
10138:): return if ($sequence eq '');
10139:): my $navmap = Apache::lonnavmaps::navmap->new();
10140:): unless (ref($navmap)) {
10141:): return;
10142:): }
10143:): my $needs_hand_bubbles;
10144:): my $map=$navmap->getResourceByUrl($sequence);
10145:): my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
10146:): foreach my $res (@resources) {
10147:): if (ref($res)) {
10148:): if ($res->is_problem()) {
10149:): my $partlist = $res->parts();
10150:): foreach my $part (@{ $partlist }) {
10151:): my @types = $res->responseType($part);
10152:): if (grep(/^(chem|essay|image|formula|math|string|functionplot)$/,@types)) {
10153:): $needs_hand_bubbles = 1;
10154:): last;
10155:): }
10156:): }
10157:): }
10158:): }
10159:): }
10160:): if ($needs_hand_bubbles) {
9(raebur 10161:9): my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
(raeburn 10162:): my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
10163:): return &mt('The sequence to be graded contains response types which are handgraded.').'<p>'.
10164:): &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 />').
10165:): '<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 10166:4): '<label><input type="radio" name="scantron_lastbubblepoints" value="0" />'.&mt('0 points').'</label></p>';
(raeburn 10167:): }
10168:): return;
10169:): }
1.423 albertel 10170:
1.82 albertel 10171: sub scantron_process_students {
1.596.2.12.2. 1(raebur 10172:0): my ($r,$symb) = @_;
1.513 foxr 10173:
1.257 albertel 10174: my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($env{'form.selectpage'});
1.513 foxr 10175: if (!$symb) {
10176: return '';
10177: }
1.324 albertel 10178: my $default_form_data=&defaultFormData($symb);
1.82 albertel 10179:
1.596.2.12.2. 9(raebur 10180:9): my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
6(raebur 10181:3): my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
1.157 albertel 10182: my ($scanlines,$scan_data)=&scantron_getfile();
1.82 albertel 10183: my $classlist=&Apache::loncoursedata::get_classlist();
10184: my %idmap=&username_to_idmap($classlist);
1.132 bowersj2 10185: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 10186: unless (ref($navmap)) {
10187: $r->print(&navmap_errormsg());
10188: return '';
1.596.2.12.2. 6(raebur 10189:3): }
1.83 albertel 10190: my $map=$navmap->getResourceByUrl($sequence);
1.596.2.12.2. 6(raebur 10191:3): my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
0(raebur 10192:2): %grader_randomlists_by_symb,%symb_for_examcode);
1(raebur 10193:2): if (ref($map)) {
10194:2): $randomorder = $map->randomorder();
6(raebur 10195:3): $randompick = $map->randompick();
0(raebur 10196:2): unless ($randomorder || $randompick) {
10197:2): foreach my $res ($navmap->retrieveResources($map,sub { $_[0]->is_map() },1,0,1)) {
10198:2): if ($res->randomorder()) {
10199:2): $randomorder = 1;
10200:2): }
10201:2): if ($res->randompick()) {
10202:2): $randompick = 1;
10203:2): }
10204:2): last if ($randomorder || $randompick);
10205:2): }
10206:2): }
6(raebur 10207:3): } else {
10208:3): $r->print(&navmap_errormsg());
10209:3): return '';
1(raebur 10210:2): }
6(raebur 10211:3): my $nav_error;
1.83 albertel 10212: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.596.2.12.2. 6(raebur 10213:3): if ($randomorder || $randompick) {
0(raebur 10214:2): $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource,1,\%symb_for_examcode);
6(raebur 10215:3): if ($nav_error) {
10216:3): $r->print(&navmap_errormsg());
10217:3): return '';
1.586 raeburn 10218: }
10219: }
1.596.2.12.2. 6(raebur 10220:3): &graders_resources_pass(\@resources,\%grader_partids_by_symb,
10221:3): \%grader_randomlists_by_symb,$bubbles_per_row);
1.557 raeburn 10222:
1.554 raeburn 10223: my ($uname,$udom);
1.82 albertel 10224: my $result= <<SCANTRONFORM;
1.81 albertel 10225: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
10226: <input type="hidden" name="command" value="scantron_configphase" />
10227: $default_form_data
10228: SCANTRONFORM
1.82 albertel 10229: $r->print($result);
10230:
10231: my @delayqueue;
1.542 raeburn 10232: my (%completedstudents,%scandata);
1.140 albertel 10233:
1.520 www 10234: my $lock=&Apache::lonnet::set_lock(&mt('Grading bubblesheet exam'));
1.200 albertel 10235: my $count=&get_todo_count($scanlines,$scan_data);
1.596.2.12.2. (raeburn 10236:): my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$count);
1(raebur 10237:0): &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,'Processing first student');
1.542 raeburn 10238: $r->print('<br />');
1.140 albertel 10239: my $start=&Time::HiRes::time();
1.158 albertel 10240: my $i=-1;
1.542 raeburn 10241: my $started;
1.447 foxr 10242:
1.596.2.12.2. (raeburn 10243:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # Need the bubble lines array to parse.
1.582 raeburn 10244: if ($nav_error) {
10245: $r->print(&navmap_errormsg());
10246: return '';
10247: }
10248:
1.513 foxr 10249: # If an ssi failed in scantron_get_maxbubble, put an error message out to
10250: # the user and return.
10251:
10252: if ($ssi_error) {
10253: $r->print("</form>");
10254: &ssi_print_error($r);
1.520 www 10255: &Apache::lonnet::remove_lock($lock);
1.513 foxr 10256: return ''; # Dunno why the other returns return '' rather than just returning.
10257: }
1.447 foxr 10258:
1.596.2.12.2. 9(raebur 10259:9): my %lettdig = &Apache::lonnet::letter_to_digits();
1.542 raeburn 10260: my $numletts = scalar(keys(%lettdig));
1.596.2.12.2. 6(raebur 10261:3): my %orderedforcode;
1.542 raeburn 10262:
1.157 albertel 10263: while ($i<$scanlines->{'count'}) {
10264: ($uname,$udom)=('','');
10265: $i++;
1.200 albertel 10266: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 10267: if ($line=~/^[\s\cz]*$/) { next; }
1.200 albertel 10268: if ($started) {
1.596.2.12.2. 1(raebur 10269:0): &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student');
1.200 albertel 10270: }
10271: $started=1;
1.596.2.12.2. 6(raebur 10272:3): my %respnumlookup = ();
10273:3): my %startline = ();
10274:3): my $total;
1.157 albertel 10275: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
1.596.2.12.2. 6(raebur 10276:3): $scan_data,undef,\%idmap,$randomorder,
10277:3): $randompick,$sequence,\@master_seq,
10278:3): \%symb_to_resource,\%grader_partids_by_symb,
10279:3): \%orderedforcode,\%respnumlookup,\%startline,
10280:3): \$total);
1.157 albertel 10281: unless ($uname=&scantron_find_student($scan_record,$scan_data,
10282: \%idmap,$i)) {
10283: &scantron_add_delay(\@delayqueue,$line,
10284: 'Unable to find a student that matches',1);
10285: next;
10286: }
10287: if (exists $completedstudents{$uname}) {
10288: &scantron_add_delay(\@delayqueue,$line,
10289: 'Student '.$uname.' has multiple sheets',2);
10290: next;
10291: }
1.596.2.12.2. 1(raebur 10292:2): my $usec = $classlist->{$uname}->[&Apache::loncoursedata::CL_SECTION];
10293:2): my $user = $uname.':'.$usec;
1.157 albertel 10294: ($uname,$udom)=split(/:/,$uname);
1.330 albertel 10295:
1.596.2.12.2. 1(raebur 10296:2): my $scancode;
10297:2): if ((exists($scan_record->{'scantron.CODE'})) &&
10298:2): (&Apache::lonnet::validCODE($scan_record->{'scantron.CODE'}))) {
10299:2): $scancode = $scan_record->{'scantron.CODE'};
10300:2): } else {
10301:2): $scancode = '';
10302:2): }
10303:2):
10304:2): my @mapresources = @resources;
6(raebur 10305:3): if ($randomorder || $randompick) {
1(raebur 10306:2): @mapresources =
6(raebur 10307:3): &users_order($user,$scancode,$sequence,\@master_seq,\%symb_to_resource,
10308:3): \%orderedforcode);
1(raebur 10309:2): }
1.586 raeburn 10310: my (%partids_by_symb,$res_error);
1.596.2.12.2. 1(raebur 10311:2): foreach my $resource (@mapresources) {
1.586 raeburn 10312: my $ressymb;
10313: if (ref($resource)) {
10314: $ressymb = $resource->symb();
10315: } else {
10316: $res_error = 1;
10317: last;
10318: }
1.557 raeburn 10319: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
10320: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
1.596.2.12.2. 1(raebur 10321:7): my $currcode;
10322:7): if (exists($grader_randomlists_by_symb{$ressymb})) {
10323:7): $currcode = $scancode;
10324:7): }
1.557 raeburn 10325: my ($analysis,$parts) =
1.596.2.12.2. (raeburn 10326:): &scantron_partids_tograde($resource,$env{'request.course.id'},
1(raebur 10327:7): $uname,$udom,undef,$bubbles_per_row,
10328:7): $currcode);
1.557 raeburn 10329: $partids_by_symb{$ressymb} = $parts;
10330: } else {
10331: $partids_by_symb{$ressymb} = $grader_partids_by_symb{$ressymb};
10332: }
1.554 raeburn 10333: }
10334:
1.586 raeburn 10335: if ($res_error) {
10336: &scantron_add_delay(\@delayqueue,$line,
10337: 'An error occurred while grading student '.$uname,2);
10338: next;
10339: }
10340:
1.330 albertel 10341: &Apache::lonxml::clear_problem_counter();
1.514 raeburn 10342: &Apache::lonnet::appenv($scan_record);
1.376 albertel 10343:
10344: if (&scantron_clear_skip($scanlines,$scan_data,$i)) {
10345: &scantron_putfile($scanlines,$scan_data);
10346: }
1.161 albertel 10347:
1.542 raeburn 10348: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
1.596.2.12.2. 1(raebur 10349:2): \@mapresources,\%partids_by_symb,
6(raebur 10350:3): $bubbles_per_row,$randomorder,$randompick,
10351:3): \%respnumlookup,\%startline)
10352:3): eq 'ssi_error') {
1.542 raeburn 10353: $ssi_error = 0; # So end of handler error message does not trigger.
10354: $r->print("</form>");
10355: &ssi_print_error($r);
10356: &Apache::lonnet::remove_lock($lock);
10357: return ''; # Why return ''? Beats me.
10358: }
1.513 foxr 10359:
1.596.2.12.2. 6(raebur 10360:3): if (($scancode) && ($randomorder || $randompick)) {
0(raebur 10361:2): foreach my $key (keys(%symb_for_examcode)) {
10362:2): my $symb_in_map = $symb_for_examcode{$key};
10363:2): if ($symb_in_map ne '') {
10364:2): my $parmresult =
10365:2): &Apache::lonparmset::storeparm_by_symb($symb_in_map,
10366:2): '0_examcode',2,$scancode,
10367:2): 'string_examcode',$uname,
10368:2): $udom);
10369:2): }
10370:2): }
6(raebur 10371:3): }
1.140 albertel 10372: $completedstudents{$uname}={'line'=>$line};
1.542 raeburn 10373: if ($env{'form.verifyrecord'}) {
10374: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
1.596.2.12.2. 6(raebur 10375:3): if ($randompick) {
10376:3): if ($total) {
10377:3): $lastpos = $total*$scantron_config{'Qlength'};
10378:3): }
10379:3): }
10380:3):
1.542 raeburn 10381: my $studentdata = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
10382: chomp($studentdata);
10383: $studentdata =~ s/\r$//;
10384: my $studentrecord = '';
10385: my $counter = -1;
1.596.2.12.2. 1(raebur 10386:2): foreach my $resource (@mapresources) {
1.554 raeburn 10387: my $ressymb = $resource->symb();
1.542 raeburn 10388: ($counter,my $recording) =
10389: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 10390: $counter,$studentdata,$partids_by_symb{$ressymb},
1.596.2.12.2. 6(raebur 10391:3): \%scantron_config,\%lettdig,$numletts,$randomorder,
10392:3): $randompick,\%respnumlookup,\%startline);
1.542 raeburn 10393: $studentrecord .= $recording;
10394: }
10395: if ($studentrecord ne $studentdata) {
1.554 raeburn 10396: &Apache::lonxml::clear_problem_counter();
10397: if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode,
1.596.2.12.2. 1(raebur 10398:2): \@mapresources,\%partids_by_symb,
6(raebur 10399:3): $bubbles_per_row,$randomorder,$randompick,
10400:3): \%respnumlookup,\%startline)
10401:3): eq 'ssi_error') {
1.554 raeburn 10402: $ssi_error = 0; # So end of handler error message does not trigger.
10403: $r->print("</form>");
10404: &ssi_print_error($r);
10405: &Apache::lonnet::remove_lock($lock);
10406: delete($completedstudents{$uname});
10407: return '';
10408: }
1.542 raeburn 10409: $counter = -1;
10410: $studentrecord = '';
1.596.2.12.2. 1(raebur 10411:2): foreach my $resource (@mapresources) {
1.554 raeburn 10412: my $ressymb = $resource->symb();
1.542 raeburn 10413: ($counter,my $recording) =
10414: &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'},
1.554 raeburn 10415: $counter,$studentdata,$partids_by_symb{$ressymb},
1.596.2.12.2. 6(raebur 10416:3): \%scantron_config,\%lettdig,$numletts,
10417:3): $randomorder,$randompick,\%respnumlookup,
10418:3): \%startline);
1.542 raeburn 10419: $studentrecord .= $recording;
10420: }
10421: if ($studentrecord ne $studentdata) {
1.596.2.6 raeburn 10422: $r->print('<p><span class="LC_warning">');
1.542 raeburn 10423: if ($scancode eq '') {
1.596.2.6 raeburn 10424: $r->print(&mt('Mismatch grading bubblesheet for user: [_1] with ID: [_2].',
1.542 raeburn 10425: $uname.':'.$udom,$scan_record->{'scantron.ID'}));
10426: } else {
1.596.2.6 raeburn 10427: $r->print(&mt('Mismatch grading bubblesheet for user: [_1] with ID: [_2] and CODE: [_3].',
1.542 raeburn 10428: $uname.':'.$udom,$scan_record->{'scantron.ID'},$scancode));
10429: }
10430: $r->print('</span><br />'.&Apache::loncommon::start_data_table()."\n".
10431: &Apache::loncommon::start_data_table_header_row()."\n".
10432: '<th>'.&mt('Source').'</th><th>'.&mt('Bubbled responses').'</th>'.
10433: &Apache::loncommon::end_data_table_header_row()."\n".
10434: &Apache::loncommon::start_data_table_row().
1.596.2.6 raeburn 10435: '<td>'.&mt('Bubblesheet').'</td>'.
1.596.2.12.2. 4(raebur 10436:3): '<td><span class="LC_nobreak" style="white-space: pre;"><tt>'.$studentdata.'</tt></span></td>'.
1.542 raeburn 10437: &Apache::loncommon::end_data_table_row().
10438: &Apache::loncommon::start_data_table_row().
1.596.2.6 raeburn 10439: '<td>'.&mt('Stored submissions').'</td>'.
1.596.2.12.2. 4(raebur 10440:3): '<td><span class="LC_nobreak" style="white-space: pre;"><tt>'.$studentrecord.'</tt></span></td>'."\n".
1.542 raeburn 10441: &Apache::loncommon::end_data_table_row().
10442: &Apache::loncommon::end_data_table().'</p>');
10443: } else {
10444: $r->print('<br /><span class="LC_warning">'.
10445: &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 />'.
10446: &mt("As a consequence, this user's submission history records two tries.").
10447: '</span><br />');
10448: }
10449: }
10450: }
1.543 raeburn 10451: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.140 albertel 10452: } continue {
1.330 albertel 10453: &Apache::lonxml::clear_problem_counter();
1.552 raeburn 10454: &Apache::lonnet::delenv('scantron.');
1.82 albertel 10455: }
1.140 albertel 10456: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.520 www 10457: &Apache::lonnet::remove_lock($lock);
1.172 albertel 10458: # my $lasttime = &Time::HiRes::time()-$start;
10459: # $r->print("<p>took $lasttime</p>");
1.140 albertel 10460:
1.200 albertel 10461: $r->print("</form>");
1.157 albertel 10462: return '';
1.75 albertel 10463: }
1.157 albertel 10464:
1.557 raeburn 10465: sub graders_resources_pass {
1.596.2.12.2. (raeburn 10466:): my ($resources,$grader_partids_by_symb,$grader_randomlists_by_symb,
10467:): $bubbles_per_row) = @_;
1.557 raeburn 10468: if ((ref($resources) eq 'ARRAY') && (ref($grader_partids_by_symb)) &&
10469: (ref($grader_randomlists_by_symb) eq 'HASH')) {
10470: foreach my $resource (@{$resources}) {
10471: my $ressymb = $resource->symb();
10472: my ($analysis,$parts) =
10473: &scantron_partids_tograde($resource,$env{'request.course.id'},
1.596.2.12.2. (raeburn 10474:): $env{'user.name'},$env{'user.domain'},
10475:): 1,$bubbles_per_row);
1.557 raeburn 10476: $grader_partids_by_symb->{$ressymb} = $parts;
10477: if (ref($analysis) eq 'HASH') {
10478: if (ref($analysis->{'parts_withrandomlist'}) eq 'ARRAY') {
10479: $grader_randomlists_by_symb->{$ressymb} =
10480: $analysis->{'parts_withrandomlist'};
10481: }
10482: }
10483: }
10484: }
10485: return;
10486: }
10487:
1.596.2.12.2. 1(raebur 10488:2): =pod
10489:2):
10490:2): =item users_order
10491:2):
10492:2): Returns array of resources in current map, ordered based on either CODE,
10493:2): if this is a CODEd exam, or based on student's identity if this is a
10494:2): "NAMEd" exam.
10495:2):
6(raebur 10496:3): Should be used when randomorder and/or randompick applied when the
10497:3): corresponding exam was printed, prior to students completing bubblesheets
10498:3): for the version of the exam the student received.
1(raebur 10499:2):
10500:2): =cut
10501:2):
10502:2): sub users_order {
6(raebur 10503:3): my ($user,$scancode,$mapurl,$master_seq,$symb_to_resource,$orderedforcode) = @_;
1(raebur 10504:2): my @mapresources;
6(raebur 10505:3): unless ((ref($master_seq) eq 'ARRAY') && (ref($symb_to_resource) eq 'HASH')) {
1(raebur 10506:2): return @mapresources;
10507:2): }
6(raebur 10508:3): if ($scancode) {
10509:3): if ((ref($orderedforcode) eq 'HASH') && (ref($orderedforcode->{$scancode}) eq 'ARRAY')) {
10510:3): @mapresources = @{$orderedforcode->{$scancode}};
10511:3): } else {
10512:3): $env{'form.CODE'} = $scancode;
10513:3): my $actual_seq =
10514:3): &Apache::lonprintout::master_seq_to_person_seq($mapurl,
10515:3): $master_seq,
10516:3): $user,$scancode,1);
10517:3): if (ref($actual_seq) eq 'ARRAY') {
10518:3): @mapresources = map { $symb_to_resource->{$_}; } @{$actual_seq};
10519:3): if (ref($orderedforcode) eq 'HASH') {
10520:3): if (@mapresources > 0) {
10521:3): $orderedforcode->{$scancode} = \@mapresources;
10522:3): }
10523:3): }
10524:3): }
10525:3): delete($env{'form.CODE'});
1(raebur 10526:2): }
10527:2): } else {
10528:2): my $actual_seq =
10529:2): &Apache::lonprintout::master_seq_to_person_seq($mapurl,
10530:2): $master_seq,
5(raebur 10531:3): $user,undef,1);
1(raebur 10532:2): if (ref($actual_seq) eq 'ARRAY') {
10533:2): @mapresources =
10534:2): map { $symb_to_resource->{$_}; } @{$actual_seq};
10535:2): }
6(raebur 10536:3): }
10537:3): return @mapresources;
1(raebur 10538:2): }
10539:2):
1.542 raeburn 10540: sub grade_student_bubbles {
1.596.2.12.2. 6(raebur 10541:3): my ($r,$uname,$udom,$scan_record,$scancode,$resources,$parts,$bubbles_per_row,
10542:3): $randomorder,$randompick,$respnumlookup,$startline) = @_;
10543:3): my $uselookup = 0;
10544:3): if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH') &&
10545:3): (ref($startline) eq 'HASH')) {
10546:3): $uselookup = 1;
10547:3): }
10548:3):
1.554 raeburn 10549: if (ref($resources) eq 'ARRAY') {
10550: my $count = 0;
10551: foreach my $resource (@{$resources}) {
10552: my $ressymb = $resource->symb();
10553: my %form = ('submitted' => 'scantron',
10554: 'grade_target' => 'grade',
10555: 'grade_username' => $uname,
10556: 'grade_domain' => $udom,
10557: 'grade_courseid' => $env{'request.course.id'},
10558: 'grade_symb' => $ressymb,
10559: 'CODE' => $scancode
10560: );
1.596.2.12.2. (raeburn 10561:): if ($bubbles_per_row ne '') {
10562:): $form{'bubbles_per_row'} = $bubbles_per_row;
10563:): }
10564:): if ($env{'form.scantron_lastbubblepoints'} ne '') {
10565:): $form{'scantron_lastbubblepoints'} = $env{'form.scantron_lastbubblepoints'};
10566:): }
1.554 raeburn 10567: if (ref($parts) eq 'HASH') {
10568: if (ref($parts->{$ressymb}) eq 'ARRAY') {
10569: foreach my $part (@{$parts->{$ressymb}}) {
1.596.2.12.2. 6(raebur 10570:3): if ($uselookup) {
10571:3): $form{'scantron_questnum_start.'.$part} = $startline->{$count} + 1;
10572:3): } else {
10573:3): $form{'scantron_questnum_start.'.$part} =
10574:3): 1+$env{'form.scantron.first_bubble_line.'.$count};
10575:3): }
1.554 raeburn 10576: $count++;
10577: }
10578: }
10579: }
10580: my $result=&ssi_with_retries($resource->src(),$ssi_retries,%form);
10581: return 'ssi_error' if ($ssi_error);
10582: last if (&Apache::loncommon::connection_aborted($r));
10583: }
1.542 raeburn 10584: }
10585: return;
10586: }
10587:
1.157 albertel 10588: sub scantron_upload_scantron_data {
1.596.2.12.2. 1(raebur 10589:0): my ($r,$symb) = @_;
1.565 raeburn 10590: my $dom = $env{'request.role.domain'};
1.596.2.12.2. 9(raebur 10591:9): my ($formatoptions,$formattitle,$formatjs) = &scantron_upload_dataformat($dom);
1.565 raeburn 10592: my $domdesc = &Apache::lonnet::domain($dom,'description');
10593: $r->print(&Apache::loncommon::coursebrowser_javascript($dom));
1.157 albertel 10594: my $select_link=&Apache::loncommon::selectcourse_link('rules','courseid',
1.181 albertel 10595: 'domainid',
1.565 raeburn 10596: 'coursename',$dom);
10597: my $syllabuslink = '<a href="javascript:ToSyllabus();">'.&mt('Syllabus').'</a>'.
1.596.2.12.2. (raeburn 10598:): (' 'x2).&mt('(shows course personnel)');
10599:): my $default_form_data=&defaultFormData($symb);
1.579 raeburn 10600: my $nofile_alert = &mt('Please use the browse button to select a file from your local directory.');
1.596.2.12.2. 7(raebur 10601:6): &js_escape(\$nofile_alert);
1.579 raeburn 10602: 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 10603:6): &js_escape(\$nocourseid_alert);
9(raebur 10604:9): $r->print(&Apache::lonhtmlcommon::scripttag('
1.157 albertel 10605: function checkUpload(formname) {
10606: if (formname.upfile.value == "") {
1.579 raeburn 10607: alert("'.$nofile_alert.'");
1.157 albertel 10608: return false;
10609: }
1.565 raeburn 10610: if (formname.courseid.value == "") {
1.579 raeburn 10611: alert("'.$nocourseid_alert.'");
1.565 raeburn 10612: return false;
10613: }
1.157 albertel 10614: formname.submit();
10615: }
1.565 raeburn 10616:
10617: function ToSyllabus() {
10618: var cdom = '."'$dom'".';
10619: var cnum = document.rules.courseid.value;
10620: if (cdom == "" || cdom == null) {
10621: return;
10622: }
10623: if (cnum == "" || cnum == null) {
10624: return;
10625: }
10626: syllwin=window.open("/public/"+cdom+"/"+cnum+"/syllabus","LONCAPASyllabus",
10627: "height=350,width=350,scrollbars=yes,menubar=no");
10628: return;
10629: }
10630:
1.596.2.12.2. 9(raebur 10631:9): '.$formatjs.'
10632:9): '));
10633:9): $r->print('
1.596.2.4 raeburn 10634: <h3>'.&mt('Send bubblesheet data to a course').'</h3>
1.566 raeburn 10635:
1.492 albertel 10636: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
1.565 raeburn 10637: '.$default_form_data.
10638: &Apache::lonhtmlcommon::start_pick_box().
10639: &Apache::lonhtmlcommon::row_title(&mt('Course ID')).
10640: '<input name="courseid" type="text" size="30" />'.$select_link.
10641: &Apache::lonhtmlcommon::row_closure().
10642: &Apache::lonhtmlcommon::row_title(&mt('Course Name')).
10643: '<input name="coursename" type="text" size="30" />'.$syllabuslink.
10644: &Apache::lonhtmlcommon::row_closure().
10645: &Apache::lonhtmlcommon::row_title(&mt('Domain')).
10646: '<input name="domainid" type="hidden" />'.$domdesc.
1.596.2.12.2. 9(raebur 10647:9): &Apache::lonhtmlcommon::row_closure());
10648:9): if ($formatoptions) {
10649:9): $r->print(&Apache::lonhtmlcommon::row_title($formattitle).$formatoptions.
10650:9): &Apache::lonhtmlcommon::row_closure());
10651:9): }
10652:9): $r->print(
1.565 raeburn 10653: &Apache::lonhtmlcommon::row_title(&mt('File to upload')).
10654: '<input type="file" name="upfile" size="50" />'.
10655: &Apache::lonhtmlcommon::row_closure(1).
10656: &Apache::lonhtmlcommon::end_pick_box().'<br />
10657:
1.492 albertel 10658: <input name="command" value="scantronupload_save" type="hidden" />
1.589 bisitz 10659: <input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
1.157 albertel 10660: </form>
1.492 albertel 10661: ');
1.157 albertel 10662: return '';
10663: }
10664:
1.596.2.12.2. 9(raebur 10665:9): sub scantron_upload_dataformat {
10666:9): my ($dom) = @_;
10667:9): my ($formatoptions,$formattitle,$formatjs);
10668:9): $formatjs = <<'END';
10669:9): function toggleScantab(form) {
10670:9): return;
10671:9): }
10672:9): END
10673:9): my %domconfig = &Apache::lonnet::get_dom('configuration',['scantron'],$dom);
10674:9): if (ref($domconfig{'scantron'}) eq 'HASH') {
10675:9): if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
10676:9): if (keys(%{$domconfig{'scantron'}{'config'}}) > 1) {
10677:9): if (($domconfig{'scantron'}{'config'}{'dat'}) &&
10678:9): (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH')) {
10679:9): if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
10680:9): if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}})) {
10681:9): my ($onclick,$formatextra,$singleline);
10682:9): my @lines = &Apache::lonnet::get_scantronformat_file();
10683:9): my $count = 0;
10684:9): foreach my $line (@lines) {
0.2.1(ra 10685:an-23): next if (($line =~ /^\#/) || ($line eq ''));
9(raebur 10686:9): $singleline = $line;
10687:9): $count ++;
10688:9): }
10689:9): if ($count > 1) {
10690:9): $formatextra = '<div style="display:none" id="bubbletype">'.
10691:9): '<span class="LC_nobreak">'.
4(raebur 10692:0): &mt('Bubblesheet type').': '.
9(raebur 10693:9): &scantron_scantab().'</span></div>';
10694:9): $onclick = ' onclick="toggleScantab(this.form);"';
10695:9): $formatjs = <<"END";
10696:9): function toggleScantab(form) {
10697:9): var divid = 'bubbletype';
10698:9): if (document.getElementById(divid)) {
10699:9): var radioname = 'fileformat';
10700:9): var num = form.elements[radioname].length;
10701:9): if (num) {
10702:9): for (var i=0; i<num; i++) {
10703:9): if (form.elements[radioname][i].checked) {
10704:9): var chosen = form.elements[radioname][i].value;
10705:9): if (chosen == 'dat') {
10706:9): document.getElementById(divid).style.display = 'none';
10707:9): } else if (chosen == 'csv') {
10708:9): document.getElementById(divid).style.display = 'block';
10709:9): }
10710:9): }
10711:9): }
10712:9): }
10713:9): }
10714:9): return;
10715:9): }
10716:9):
10717:9): END
10718:9): } elsif ($count == 1) {
10719:9): my $formatname = (split(/:/,$singleline,2))[0];
10720:9): $formatextra = '<input type="hidden" name="scantron_format" value="'.$formatname.'" />';
10721:9): }
10722:9): $formattitle = &mt('File format');
10723:9): $formatoptions = '<label><input name="fileformat" type="radio" value="dat" checked="checked"'.$onclick.' />'.
10724:9): &mt('Plain Text (no delimiters)').
10725:9): '</label>'.(' 'x2).
10726:9): '<label><input name="fileformat" type="radio" value="csv"'.$onclick.' />'.
10727:9): &mt('Comma separated values').'</label>'.$formatextra;
10728:9): }
10729:9): }
10730:9): }
10731:9): } elsif (keys(%{$domconfig{'scantron'}{'config'}}) == 1) {
10732:9): if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
10733:9): if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}})) {
10734:9): $formattitle = &mt('Bubblesheet type');
10735:9): $formatoptions = &scantron_scantab();
10736:9): }
10737:9): }
10738:9): }
10739:9): }
10740:9): }
10741:9): return ($formatoptions,$formattitle,$formatjs);
10742:9): }
1.423 albertel 10743:
1.157 albertel 10744: sub scantron_upload_scantron_data_save {
1.596.2.12.2. 1(raebur 10745:0): my ($r,$symb) = @_;
1.182 albertel 10746: my $doanotherupload=
10747: '<br /><form action="/adm/grades" method="post">'."\n".
10748: '<input type="hidden" name="command" value="scantronupload" />'."\n".
1.492 albertel 10749: '<input type="submit" name="submit" value="'.&mt('Do Another Upload').'" />'."\n".
1.182 albertel 10750: '</form>'."\n";
1.257 albertel 10751: if (!&Apache::lonnet::allowed('usc',$env{'form.domainid'}) &&
1.162 albertel 10752: !&Apache::lonnet::allowed('usc',
1.257 albertel 10753: $env{'form.domainid'}.'_'.$env{'form.courseid'})) {
1.575 www 10754: $r->print(&mt("You are not allowed to upload bubblesheet data to the requested course.")."<br />");
1.596.2.12.2. 1(raebur 10755:0): unless ($symb) {
1.182 albertel 10756: $r->print($doanotherupload);
10757: }
1.162 albertel 10758: return '';
10759: }
1.257 albertel 10760: my %coursedata=&Apache::lonnet::coursedescription($env{'form.domainid'}.'_'.$env{'form.courseid'});
1.568 raeburn 10761: my $uploadedfile;
1.596.2.12.2. 5(raebur 10762:3): $r->print('<p>'.&mt("Uploading file to [_1]",$coursedata{'description'}).'</p>');
1.257 albertel 10763: if (length($env{'form.upfile'}) < 2) {
1.596.2.12.2. 5(raebur 10764:3): $r->print(
10765:3): &Apache::lonhtmlcommon::confirm_success(
10766:3): &mt('The file: [_1] you attempted to upload contained no information. Please check that you entered the correct filename.',
10767:3): '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'),1));
1.183 albertel 10768: } else {
1.596.2.12.2. 9(raebur 10769:9): my %domconfig = &Apache::lonnet::get_dom('configuration',['scantron'],$env{'form.domainid'});
10770:9): my $parser;
10771:9): if (ref($domconfig{'scantron'}) eq 'HASH') {
10772:9): if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
10773:9): my $is_csv;
10774:9): my @possibles = keys(%{$domconfig{'scantron'}{'config'}});
10775:9): if (@possibles > 1) {
10776:9): if ($env{'form.fileformat'} eq 'csv') {
10777:9): if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
10778:9): if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
10779:9): if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}}) > 1) {
10780:9): $is_csv = 1;
10781:9): }
10782:9): }
10783:9): }
10784:9): }
10785:9): } elsif (@possibles == 1) {
10786:9): if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
10787:9): if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
10788:9): if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}}) > 1) {
10789:9): $is_csv = 1;
10790:9): }
10791:9): }
10792:9): }
10793:9): }
10794:9): if ($is_csv) {
10795:9): $parser = $domconfig{'scantron'}{'config'}{'csv'};
10796:9): }
10797:9): }
10798:9): }
10799:9): my $result =
10800:9): &Apache::lonnet::userfileupload('upfile','scantron','scantron',$parser,'','',
1.568 raeburn 10801: $env{'form.courseid'},$env{'form.domainid'});
10802: if ($result =~ m{^/uploaded/}) {
1.596.2.12.2. 5(raebur 10803:3): $r->print(
10804:3): &Apache::lonhtmlcommon::confirm_success(&mt('Upload successful')).'<br />'.
10805:3): &mt('Uploaded [_1] bytes of data into location: [_2]',
10806:3): (length($env{'form.upfile'})-1),
10807:3): '<span class="LC_filename">'.$result.'</span>'));
1.568 raeburn 10808: ($uploadedfile) = ($result =~ m{/([^/]+)$});
1.567 raeburn 10809: $r->print(&validate_uploaded_scantron_file($env{'form.domainid'},
1.568 raeburn 10810: $env{'form.courseid'},$uploadedfile));
1.210 albertel 10811: } else {
1.596.2.12.2. 5(raebur 10812:3): $r->print(
10813:3): &Apache::lonhtmlcommon::confirm_success(&mt('Upload failed'),1).'<br />'.
10814:3): &mt('An error ([_1]) occurred when attempting to upload the file: [_2]',
10815:3): $result,
1.568 raeburn 10816: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'));
1.183 albertel 10817: }
10818: }
1.174 albertel 10819: if ($symb) {
1.596.2.12.2. 1(raebur 10820:0): $r->print(&scantron_selectphase($r,$uploadedfile,$symb));
1.174 albertel 10821: } else {
1.182 albertel 10822: $r->print($doanotherupload);
1.174 albertel 10823: }
1.157 albertel 10824: return '';
10825: }
10826:
1.567 raeburn 10827: sub validate_uploaded_scantron_file {
10828: my ($cdom,$cname,$fname) = @_;
10829: my $scanlines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.$fname);
10830: my @lines;
10831: if ($scanlines ne '-1') {
10832: @lines=split("\n",$scanlines,-1);
10833: }
10834: my $output;
10835: if (@lines) {
10836: my (%counts,$max_match_format);
1.596.2.12.2. 5(raebur 10837:3): my ($found_match_count,$max_match_count,$max_match_pct) = (0,0,0);
1.567 raeburn 10838: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cname);
10839: my %idmap = &username_to_idmap($classlist);
10840: foreach my $key (keys(%idmap)) {
10841: my $lckey = lc($key);
10842: $idmap{$lckey} = $idmap{$key};
10843: }
10844: my %unique_formats;
1.596.2.12.2. 9(raebur 10845:9): my @formatlines = &Apache::lonnet::get_scantronformat_file();
1.567 raeburn 10846: foreach my $line (@formatlines) {
1.596.2.12.2. 0.2.1(ra 10847:an-23): next if (($line =~ /^\#/) || ($line eq ''));
1.567 raeburn 10848: my @config = split(/:/,$line);
10849: my $idstart = $config[5];
10850: my $idlength = $config[6];
10851: if (($idstart ne '') && ($idlength > 0)) {
10852: if (ref($unique_formats{$idstart.':'.$idlength}) eq 'ARRAY') {
10853: push(@{$unique_formats{$idstart.':'.$idlength}},$config[0].':'.$config[1]);
10854: } else {
10855: $unique_formats{$idstart.':'.$idlength} = [$config[0].':'.$config[1]];
10856: }
10857: }
10858: }
10859: foreach my $key (keys(%unique_formats)) {
10860: my ($idstart,$idlength) = split(':',$key);
10861: %{$counts{$key}} = (
10862: 'found' => 0,
10863: 'total' => 0,
10864: );
10865: foreach my $line (@lines) {
10866: next if ($line =~ /^#/);
10867: next if ($line =~ /^[\s\cz]*$/);
10868: my $id = substr($line,$idstart-1,$idlength);
10869: $id = lc($id);
10870: if (exists($idmap{$id})) {
10871: $counts{$key}{'found'} ++;
10872: }
10873: $counts{$key}{'total'} ++;
10874: }
10875: if ($counts{$key}{'total'}) {
10876: my $percent_match = (100*$counts{$key}{'found'})/($counts{$key}{'total'});
10877: if (($max_match_format eq '') || ($percent_match > $max_match_pct)) {
10878: $max_match_pct = $percent_match;
10879: $max_match_format = $key;
1.596.2.12.2. 5(raebur 10880:3): $found_match_count = $counts{$key}{'found'};
1.567 raeburn 10881: $max_match_count = $counts{$key}{'total'};
10882: }
10883: }
10884: }
10885: if (ref($unique_formats{$max_match_format}) eq 'ARRAY') {
10886: my $format_descs;
10887: my $numwithformat = @{$unique_formats{$max_match_format}};
10888: for (my $i=0; $i<$numwithformat; $i++) {
10889: my ($name,$desc) = split(':',$unique_formats{$max_match_format}[$i]);
10890: if ($i<$numwithformat-2) {
10891: $format_descs .= '"<i>'.$desc.'</i>", ';
10892: } elsif ($i==$numwithformat-2) {
10893: $format_descs .= '"<i>'.$desc.'</i>" '.&mt('and').' ';
10894: } elsif ($i==$numwithformat-1) {
10895: $format_descs .= '"<i>'.$desc.'</i>"';
10896: }
10897: }
10898: my $showpct = sprintf("%.0f",$max_match_pct).'%';
1.596.2.12.2. 5(raebur 10899:3): $output .= '<br />';
10900:3): if ($found_match_count == $max_match_count) {
10901:3): # 100% matching entries
10902:3): $output .= &Apache::lonhtmlcommon::confirm_success(
10903:3): &mt('Comparison of student IDs: [_1] matching ([quant,_2,entry,entries])',
10904:3): '<b>'.$showpct.'</b>',$found_match_count)).'<br />'.
10905:3): &mt('Comparison of student IDs in the uploaded file with'.
10906:3): ' the course roster found matches for [_1] of the [_2] entries'.
10907:3): ' in the file (for the format defined for [_3]).',
10908:3): '<b>'.$showpct.'</b>','<b>'.$max_match_count.'</b>',$format_descs);
10909:3): } else {
10910:3): # Not all entries matching? -> Show warning and additional info
10911:3): $output .=
10912:3): &Apache::lonhtmlcommon::confirm_success(
10913:3): &mt('Comparison of student IDs: [_1] matching ([_2]/[quant,_3,entry,entries])',
10914:3): '<b>'.$showpct.'</b>',$found_match_count,$max_match_count).'<br />'.
10915:3): &mt('Not all entries could be matched!'),1).'<br />'.
10916:3): &mt('Comparison of student IDs in the uploaded file with'.
10917:3): ' the course roster found matches for [_1] of the [_2] entries'.
10918:3): ' in the file (for the format defined for [_3]).',
10919:3): '<b>'.$showpct.'</b>','<b>'.$max_match_count.'</b>',$format_descs).
10920:3): '<p class="LC_info">'.
10921:3): &mt('A low percentage of matches results from one of the following:').
10922:3): '</p><ul>'.
10923:3): '<li>'.&mt('The file was uploaded to the wrong course.').'</li>'.
10924:3): '<li>'.&mt('The data is not in the format expected for the domain: [_1]',
10925:3): '<i>'.$cdom.'</i>').'</li>'.
10926:3): '<li>'.&mt('Students did not bubble their IDs, or mis-bubbled them').'</li>'.
10927:3): '<li>'.&mt('The course roster is not up to date.').'</li>'.
10928:3): '</ul>';
10929:3): }
1.567 raeburn 10930: }
10931: } else {
1.596.2.12.2. 5(raebur 10932:3): $output = '<p class="LC_warning">'.&mt('Uploaded file contained no data').'</p>';
1.567 raeburn 10933: }
10934: return $output;
10935: }
10936:
1.202 albertel 10937: sub valid_file {
10938: my ($requested_file)=@_;
10939: foreach my $filename (sort(&scantron_filenames())) {
10940: if ($requested_file eq $filename) { return 1; }
10941: }
10942: return 0;
10943: }
10944:
10945: sub scantron_download_scantron_data {
1.596.2.12.2. 1(raebur 10946:0): my ($r,$symb) = @_;
(raeburn 10947:): my $default_form_data=&defaultFormData($symb);
1.257 albertel 10948: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
10949: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
10950: my $file=$env{'form.scantron_selectfile'};
1.202 albertel 10951: if (! &valid_file($file)) {
1.492 albertel 10952: $r->print('
1.202 albertel 10953: <p>
1.596.2.12.2. 3(raebur 10954:3): '.&mt('The requested filename was invalid.').'
1.202 albertel 10955: </p>
1.492 albertel 10956: ');
1.202 albertel 10957: return;
10958: }
10959: my $orig='/uploaded/'.$cdom.'/'.$cname.'/scantron_orig_'.$file;
10960: my $corrected='/uploaded/'.$cdom.'/'.$cname.'/scantron_corrected_'.$file;
10961: my $skipped='/uploaded/'.$cdom.'/'.$cname.'/scantron_skipped_'.$file;
10962: &Apache::lonnet::allowuploaded('/adm/grades',$orig);
10963: &Apache::lonnet::allowuploaded('/adm/grades',$corrected);
10964: &Apache::lonnet::allowuploaded('/adm/grades',$skipped);
1.492 albertel 10965: $r->print('
1.202 albertel 10966: <p>
1.596.2.12.2. 1(raebur 10967:0): '.&mt('[_1]Original[_2] file as uploaded by the bubblesheet scanning office.',
1.492 albertel 10968: '<a href="'.$orig.'">','</a>').'
1.202 albertel 10969: </p>
10970: <p>
1.492 albertel 10971: '.&mt('[_1]Corrections[_2], a file of corrected records that were used in grading.',
10972: '<a href="'.$corrected.'">','</a>').'
1.202 albertel 10973: </p>
10974: <p>
1.492 albertel 10975: '.&mt('[_1]Skipped[_2], a file of records that were skipped.',
10976: '<a href="'.$skipped.'">','</a>').'
1.202 albertel 10977: </p>
1.492 albertel 10978: ');
1.202 albertel 10979: return '';
10980: }
1.157 albertel 10981:
1.523 raeburn 10982: sub checkscantron_results {
1.596.2.12.2. 1(raebur 10983:0): my ($r,$symb) = @_;
1.523 raeburn 10984: if (!$symb) {return '';}
10985: my $cid = $env{'request.course.id'};
1.596.2.12.2. 9(raebur 10986:9): my %lettdig = &Apache::lonnet::letter_to_digits();
1.523 raeburn 10987: my $numletts = scalar(keys(%lettdig));
10988: my $cnum = $env{'course.'.$cid.'.num'};
10989: my $cdom = $env{'course.'.$cid.'.domain'};
10990: my (undef, undef, $sequence) = &Apache::lonnet::decode_symb($env{'form.selectpage'});
10991: my %record;
10992: my %scantron_config =
1.596.2.12.2. 9(raebur 10993:9): &Apache::lonnet::get_scantron_config($env{'form.scantron_format'});
(raeburn 10994:): my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
1.523 raeburn 10995: my ($scanlines,$scan_data)=&Apache::grades::scantron_getfile();
10996: my $classlist=&Apache::loncoursedata::get_classlist();
10997: my %idmap=&Apache::grades::username_to_idmap($classlist);
10998: my $navmap=Apache::lonnavmaps::navmap->new();
1.582 raeburn 10999: unless (ref($navmap)) {
11000: $r->print(&navmap_errormsg());
11001: return '';
11002: }
1.523 raeburn 11003: my $map=$navmap->getResourceByUrl($sequence);
1.596.2.12.2. 6(raebur 11004:3): my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb,
11005:3): %grader_randomlists_by_symb,%orderedforcode);
1(raebur 11006:2): if (ref($map)) {
11007:2): $randomorder=$map->randomorder();
7(raebur 11008:3): $randompick=$map->randompick();
0(raebur 11009:2): unless ($randomorder || $randompick) {
11010:2): foreach my $res ($navmap->retrieveResources($map,sub { $_[0]->is_map() },1,0,1)) {
11011:2): if ($res->randomorder()) {
11012:2): $randomorder = 1;
11013:2): }
11014:2): if ($res->randompick()) {
11015:2): $randompick = 1;
11016:2): }
11017:2): last if ($randomorder || $randompick);
11018:2): }
11019:2): }
1(raebur 11020:2): }
1.557 raeburn 11021: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.596.2.12.2. 6(raebur 11022:3): my $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource);
11023:3): if ($nav_error) {
11024:3): $r->print(&navmap_errormsg());
11025:3): return '';
1(raebur 11026:2): }
(raeburn 11027:): &graders_resources_pass(\@resources,\%grader_partids_by_symb,
11028:): \%grader_randomlists_by_symb,$bubbles_per_row);
1.554 raeburn 11029: my ($uname,$udom);
1.523 raeburn 11030: my (%scandata,%lastname,%bylast);
11031: $r->print('
11032: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="checkscantron">'."\n");
11033:
11034: my @delayqueue;
11035: my %completedstudents;
11036:
1.596.2.12.2. 6(raebur 11037:3): my $count=&get_todo_count($scanlines,$scan_data);
(raeburn 11038:): my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$count);
6(raebur 11039:3): my ($username,$domain,$started);
(raeburn 11040:): &scantron_get_maxbubble(\$nav_error,\%scantron_config); # Need the bubble lines array to parse.
1.582 raeburn 11041: if ($nav_error) {
11042: $r->print(&navmap_errormsg());
11043: return '';
11044: }
1.523 raeburn 11045:
11046: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
11047: 'Processing first student');
11048: my $start=&Time::HiRes::time();
11049: my $i=-1;
11050:
11051: while ($i<$scanlines->{'count'}) {
11052: ($username,$domain,$uname)=('','','');
11053: $i++;
11054: my $line=&Apache::grades::scantron_get_line($scanlines,$scan_data,$i);
11055: if ($line=~/^[\s\cz]*$/) { next; }
11056: if ($started) {
11057: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
11058: 'last student');
11059: }
11060: $started=1;
11061: my $scan_record=
11062: &Apache::grades::scantron_parse_scanline($line,$i,\%scantron_config,
11063: $scan_data);
1.596.2.12.2. 6(raebur 11064:3): unless ($uname=&scantron_find_student($scan_record,$scan_data,
11065:3): \%idmap,$i)) {
1.523 raeburn 11066: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
11067: 'Unable to find a student that matches',1);
11068: next;
11069: }
11070: if (exists $completedstudents{$uname}) {
11071: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
11072: 'Student '.$uname.' has multiple sheets',2);
11073: next;
11074: }
11075: my $pid = $scan_record->{'scantron.ID'};
11076: $lastname{$pid} = $scan_record->{'scantron.LastName'};
11077: push(@{$bylast{$lastname{$pid}}},$pid);
1.596.2.12.2. 1(raebur 11078:2): my $usec = $classlist->{$uname}->[&Apache::loncoursedata::CL_SECTION];
11079:2): my $user = $uname.':'.$usec;
1.523 raeburn 11080: ($username,$domain)=split(/:/,$uname);
1.596.2.12.2. 1(raebur 11081:2):
11082:2): my $scancode;
11083:2): if ((exists($scan_record->{'scantron.CODE'})) &&
11084:2): (&Apache::lonnet::validCODE($scan_record->{'scantron.CODE'}))) {
11085:2): $scancode = $scan_record->{'scantron.CODE'};
11086:2): } else {
11087:2): $scancode = '';
11088:2): }
11089:2):
11090:2): my @mapresources = @resources;
6(raebur 11091:3): my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
11092:3): my %respnumlookup=();
11093:3): my %startline=();
11094:3): if ($randomorder || $randompick) {
1(raebur 11095:2): @mapresources =
6(raebur 11096:3): &users_order($user,$scancode,$sequence,\@master_seq,\%symb_to_resource,
11097:3): \%orderedforcode);
11098:3): my $total = &get_respnum_lookups($sequence,$scan_data,\%idmap,$line,
11099:3): $scan_record,\@master_seq,\%symb_to_resource,
11100:3): \%grader_partids_by_symb,\%orderedforcode,
11101:3): \%respnumlookup,\%startline);
11102:3): if ($randompick && $total) {
11103:3): $lastpos = $total*$scantron_config{'Qlength'};
11104:3): }
1(raebur 11105:2): }
6(raebur 11106:3): $scandata{$pid} = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
11107:3): chomp($scandata{$pid});
11108:3): $scandata{$pid} =~ s/\r$//;
11109:3):
1.523 raeburn 11110: my $counter = -1;
1.596.2.12.2. 1(raebur 11111:2): foreach my $resource (@mapresources) {
1.557 raeburn 11112: my $parts;
1.554 raeburn 11113: my $ressymb = $resource->symb();
1.557 raeburn 11114: if ((exists($grader_randomlists_by_symb{$ressymb})) ||
11115: (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) {
1.596.2.12.2. 1(raebur 11116:7): my $currcode;
11117:7): if (exists($grader_randomlists_by_symb{$ressymb})) {
11118:7): $currcode = $scancode;
11119:7): }
1.557 raeburn 11120: (my $analysis,$parts) =
1.596.2.12.2. (raeburn 11121:): &scantron_partids_tograde($resource,$env{'request.course.id'},
11122:): $username,$domain,undef,
1(raebur 11123:7): $bubbles_per_row,$currcode);
1.557 raeburn 11124: } else {
11125: $parts = $grader_partids_by_symb{$ressymb};
11126: }
1.542 raeburn 11127: ($counter,my $recording) =
11128: &verify_scantron_grading($resource,$domain,$username,$cid,$counter,
1.554 raeburn 11129: $scandata{$pid},$parts,
1.596.2.12.2. 6(raebur 11130:3): \%scantron_config,\%lettdig,$numletts,
11131:3): $randomorder,$randompick,
11132:3): \%respnumlookup,\%startline);
1.542 raeburn 11133: $record{$pid} .= $recording;
1.523 raeburn 11134: }
11135: }
11136: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
11137: $r->print('<br />');
11138: my ($okstudents,$badstudents,$numstudents,$passed,$failed);
11139: $passed = 0;
11140: $failed = 0;
11141: $numstudents = 0;
11142: foreach my $last (sort(keys(%bylast))) {
11143: if (ref($bylast{$last}) eq 'ARRAY') {
11144: foreach my $pid (sort(@{$bylast{$last}})) {
11145: my $showscandata = $scandata{$pid};
11146: my $showrecord = $record{$pid};
11147: $showscandata =~ s/\s/ /g;
11148: $showrecord =~ s/\s/ /g;
11149: if ($scandata{$pid} eq $record{$pid}) {
11150: my $css_class = ($passed % 2)?'LC_odd_row':'LC_even_row';
11151: $okstudents .= '<tr class="'.$css_class.'">'.
1.581 www 11152: '<td>'.&mt('Bubblesheet').'</td><td>'.$showscandata.'</td><td rowspan="2">'.$last.'</td><td rowspan="2">'.$pid.'</td>'."\n".
1.523 raeburn 11153: '</tr>'."\n".
11154: '<tr class="'.$css_class.'">'."\n".
1.596.2.12.2. 8(raebur 11155:4): '<td>'.&mt('Submissions').'</td><td>'.$showrecord.'</td></tr>'."\n";
1.523 raeburn 11156: $passed ++;
11157: } else {
11158: my $css_class = ($failed % 2)?'LC_odd_row':'LC_even_row';
1.581 www 11159: $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 11160: '</tr>'."\n".
11161: '<tr class="'.$css_class.'">'."\n".
1.596.2.12.2. 8(raebur 11162:4): '<td>'.&mt('Submissions').'</td><td><span class="LC_nobreak">'.$record{$pid}.'</span></td>'."\n".
1.523 raeburn 11163: '</tr>'."\n";
11164: $failed ++;
11165: }
11166: $numstudents ++;
11167: }
11168: }
11169: }
1.596.2.4 raeburn 11170: $r->print('<p>'.
1.596.2.8 raeburn 11171: &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 11172: '<b>',
11173: $numstudents,
11174: '</b>',
11175: $env{'form.scantron_maxbubble'}).
11176: '</p>'
11177: );
1.596.2.12.2. 2(raebur 11178:2): $r->print('<p>'
11179:2): .&mt('Exact matches for [_1][quant,_2,student][_3].','<b>',$passed,'</b>')
11180:2): .'<br />'
11181:2): .&mt('Discrepancies detected for [_1][quant,_2,student][_3].','<b>',$failed,'</b>')
11182:2): .'</p>');
1.523 raeburn 11183: if ($passed) {
1.572 www 11184: $r->print(&mt('Students with exact correspondence between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 11185: $r->print(&Apache::loncommon::start_data_table()."\n".
11186: &Apache::loncommon::start_data_table_header_row()."\n".
11187: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
11188: &Apache::loncommon::end_data_table_header_row()."\n".
11189: $okstudents."\n".
11190: &Apache::loncommon::end_data_table().'<br />');
11191: }
11192: if ($failed) {
1.572 www 11193: $r->print(&mt('Students with differences between bubblesheet data and submissions are as follows:').'<br /><br />');
1.523 raeburn 11194: $r->print(&Apache::loncommon::start_data_table()."\n".
11195: &Apache::loncommon::start_data_table_header_row()."\n".
11196: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
11197: &Apache::loncommon::end_data_table_header_row()."\n".
11198: $badstudents."\n".
11199: &Apache::loncommon::end_data_table()).'<br />'.
1.572 www 11200: &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 11201: }
1.596.2.12.2. 1(raebur 11202:0): $r->print('</form><br />');
1.523 raeburn 11203: return;
11204: }
11205:
1.542 raeburn 11206: sub verify_scantron_grading {
1.554 raeburn 11207: my ($resource,$domain,$username,$cid,$counter,$scandata,$partids,
1.596.2.12.2. 6(raebur 11208:3): $scantron_config,$lettdig,$numletts,$randomorder,$randompick,
11209:3): $respnumlookup,$startline) = @_;
1.542 raeburn 11210: my ($record,%expected,%startpos);
11211: return ($counter,$record) if (!ref($resource));
11212: return ($counter,$record) if (!$resource->is_problem());
11213: my $symb = $resource->symb();
1.554 raeburn 11214: return ($counter,$record) if (ref($partids) ne 'ARRAY');
11215: foreach my $part_id (@{$partids}) {
1.542 raeburn 11216: $counter ++;
11217: $expected{$part_id} = 0;
1.596.2.12.2. 6(raebur 11218:3): my $respnum = $counter;
11219:3): if ($randomorder || $randompick) {
11220:3): $respnum = $respnumlookup->{$counter};
11221:3): $startpos{$part_id} = $startline->{$counter} + 1;
11222:3): } else {
11223:3): $startpos{$part_id} = $env{"form.scantron.first_bubble_line.$counter"};
11224:3): }
11225:3): if ($env{"form.scantron.sub_bubblelines.$respnum"}) {
11226:3): my @sub_lines = split(/,/,$env{"form.scantron.sub_bubblelines.$respnum"});
1.542 raeburn 11227: foreach my $item (@sub_lines) {
11228: $expected{$part_id} += $item;
11229: }
11230: } else {
1.596.2.12.2. 6(raebur 11231:3): $expected{$part_id} = $env{"form.scantron.bubblelines.$respnum"};
1.542 raeburn 11232: }
11233: }
11234: if ($symb) {
11235: my %recorded;
11236: my (%returnhash) = &Apache::lonnet::restore($symb,$cid,$domain,$username);
11237: if ($returnhash{'version'}) {
11238: my %lasthash=();
11239: my $version;
11240: for ($version=1;$version<=$returnhash{'version'};$version++) {
11241: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
11242: $lasthash{$key}=$returnhash{$version.':'.$key};
11243: }
11244: }
11245: foreach my $key (keys(%lasthash)) {
11246: if ($key =~ /\.scantron$/) {
11247: my $value = &unescape($lasthash{$key});
11248: my ($part_id) = ($key =~ /^resource\.(.+)\.scantron$/);
11249: if ($value eq '') {
11250: for (my $i=0; $i<$expected{$part_id}; $i++) {
11251: for (my $j=0; $j<$scantron_config->{'length'}; $j++) {
11252: $recorded{$part_id} .= $scantron_config->{'Qoff'};
11253: }
11254: }
11255: } else {
11256: my @tocheck;
11257: my @items = split(//,$value);
11258: if (($scantron_config->{'Qon'} eq 'letter') ||
11259: ($scantron_config->{'Qon'} eq 'number')) {
11260: if (@items < $expected{$part_id}) {
11261: my $fragment = substr($scandata,$startpos{$part_id},$expected{$part_id});
11262: my @singles = split(//,$fragment);
11263: foreach my $pos (@singles) {
11264: if ($pos eq ' ') {
11265: push(@tocheck,$pos);
11266: } else {
11267: my $next = shift(@items);
11268: push(@tocheck,$next);
11269: }
11270: }
11271: } else {
11272: @tocheck = @items;
11273: }
11274: foreach my $letter (@tocheck) {
11275: if ($scantron_config->{'Qon'} eq 'letter') {
11276: if ($letter !~ /^[A-J]$/) {
11277: $letter = $scantron_config->{'Qoff'};
11278: }
11279: $recorded{$part_id} .= $letter;
11280: } elsif ($scantron_config->{'Qon'} eq 'number') {
11281: my $digit;
11282: if ($letter !~ /^[A-J]$/) {
11283: $digit = $scantron_config->{'Qoff'};
11284: } else {
11285: $digit = $lettdig->{$letter};
11286: }
11287: $recorded{$part_id} .= $digit;
11288: }
11289: }
11290: } else {
11291: @tocheck = @items;
11292: for (my $i=0; $i<$expected{$part_id}; $i++) {
11293: my $curr_sub = shift(@tocheck);
11294: my $digit;
11295: if ($curr_sub =~ /^[A-J]$/) {
11296: $digit = $lettdig->{$curr_sub}-1;
11297: }
11298: if ($curr_sub eq 'J') {
11299: $digit += scalar($numletts);
11300: }
11301: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
11302: if ($j == $digit) {
11303: $recorded{$part_id} .= $scantron_config->{'Qon'};
11304: } else {
11305: $recorded{$part_id} .= $scantron_config->{'Qoff'};
11306: }
11307: }
11308: }
11309: }
11310: }
11311: }
11312: }
11313: }
1.554 raeburn 11314: foreach my $part_id (@{$partids}) {
1.542 raeburn 11315: if ($recorded{$part_id} eq '') {
11316: for (my $i=0; $i<$expected{$part_id}; $i++) {
11317: for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) {
11318: $recorded{$part_id} .= $scantron_config->{'Qoff'};
11319: }
11320: }
11321: }
11322: $record .= $recorded{$part_id};
11323: }
11324: }
11325: return ($counter,$record);
11326: }
11327:
1.75 albertel 11328: #-------- end of section for handling grading scantron forms -------
11329: #
11330: #-------------------------------------------------------------------
11331:
1.72 ng 11332: #-------------------------- Menu interface -------------------------
11333: #
1.596.2.12.2. (raeburn 11334:): #--- Href with symb and command ---
11335:):
11336:): sub href_symb_cmd {
11337:): my ($symb,$cmd)=@_;
0.2.7(ra 11338:an-25): return '/adm/grades?symb='.&HTML::Entities::encode(&Apache::lonenc::check_encrypt($symb),'<>&"').'&command='.
11339:an-25): &HTML::Entities::encode($cmd,'<>&"');
(raeburn 11340:): }
11341:):
1.443 banghart 11342: sub grading_menu {
1.596.2.12.2. 1(raebur 11343:0): my ($request,$symb) = @_;
1.443 banghart 11344: if (!$symb) {return '';}
11345:
11346: my %fields = ('symb'=>&Apache::lonenc::check_encrypt($symb),
1.596.2.12.2. 1(raebur 11347:0): 'command'=>'individual');
11348:0):
11349:0): my $url1a = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
11350:0):
11351:0): $fields{'command'}='ungraded';
11352:0): my $url1b=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
11353:0):
11354:0): $fields{'command'}='table';
11355:0): my $url1c=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
11356:0):
11357:0): $fields{'command'}='all_for_one';
11358:0): my $url1d=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
11359:0):
11360:0): $fields{'command'}='downloadfilesselect';
11361:0): my $url1e=&Apache::lonhtmlcommon::build_url('grades/',\%fields);
1.538 schulted 11362:
1.443 banghart 11363: $fields{'command'} = 'csvform';
1.538 schulted 11364: my $url2 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
11365:
1.443 banghart 11366: $fields{'command'} = 'processclicker';
1.538 schulted 11367: my $url3 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
11368:
1.443 banghart 11369: $fields{'command'} = 'scantron_selectphase';
1.538 schulted 11370: my $url4 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
1.596.2.12.2. 1(raebur 11371:0):
11372:0): $fields{'command'} = 'initialverifyreceipt';
11373:0): my $url5 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
6(raebur 11374:1):
11375:1): my %permissions;
11376:1): if ($perm{'mgr'}) {
11377:1): $permissions{'either'} = 'F';
11378:1): $permissions{'mgr'} = 'F';
11379:1): }
11380:1): if ($perm{'vgr'}) {
11381:1): $permissions{'either'} = 'F';
11382:1): $permissions{'vgr'} = 'F';
11383:1): }
11384:1):
1(raebur 11385:0): my @menu = ({ categorytitle=>'Hand Grading',
1.538 schulted 11386: items =>[
1.596.2.12.2. 1(raebur 11387:0): { linktext => 'Select individual students to grade',
11388:0): url => $url1a,
6(raebur 11389:1): permission => $permissions{'either'},
1(raebur 11390:0): icon => 'grade_students.png',
11391:0): linktitle => 'Grade current resource for a selection of students.'
11392:0): },
11393:0): { linktext => 'Grade ungraded submissions',
11394:0): url => $url1b,
6(raebur 11395:1): permission => $permissions{'either'},
1(raebur 11396:0): icon => 'ungrade_sub.png',
11397:0): linktitle => 'Grade all submissions that have not been graded yet.'
11398:0): },
11399:0):
11400:0): { linktext => 'Grading table',
11401:0): url => $url1c,
6(raebur 11402:1): permission => $permissions{'either'},
1(raebur 11403:0): icon => 'grading_table.png',
11404:0): linktitle => 'Grade current resource for all students.'
11405:0): },
11406:0): { linktext => 'Grade page/folder for one student',
11407:0): url => $url1d,
6(raebur 11408:1): permission => $permissions{'either'},
1(raebur 11409:0): icon => 'grade_PageFolder.png',
11410:0): linktitle => 'Grade all resources in current page/sequence/folder for one student.'
1.538 schulted 11411: },
1.596.2.12.2. 3(raebur 11412:0): { linktext => 'Download submitted files',
1(raebur 11413:0): url => $url1e,
6(raebur 11414:1): permission => $permissions{'either'},
1(raebur 11415:0): icon => 'download_sub.png',
3(raebur 11416:0): linktitle => 'Download all files submitted by students.'
1(raebur 11417:0): }]},
11418:0): { categorytitle=>'Automated Grading',
11419:0): items =>[
11420:0):
1.538 schulted 11421: { linktext => 'Upload Scores',
11422: url => $url2,
1.596.2.12.2. 6(raebur 11423:1): permission => $permissions{'mgr'},
1.538 schulted 11424: icon => 'uploadscores.png',
11425: linktitle => 'Specify a file containing the class scores for current resource.'
11426: },
11427: { linktext => 'Process Clicker',
11428: url => $url3,
1.596.2.12.2. 6(raebur 11429:1): permission => $permissions{'mgr'},
1.538 schulted 11430: icon => 'addClickerInfoFile.png',
11431: linktitle => 'Specify a file containing the clicker information for this resource.'
11432: },
1.587 raeburn 11433: { linktext => 'Grade/Manage/Review Bubblesheets',
1.538 schulted 11434: url => $url4,
1.596.2.12.2. 6(raebur 11435:1): permission => $permissions{'mgr'},
1(raebur 11436:0): icon => 'bubblesheet.png',
1.596.2.4 raeburn 11437: linktitle => 'Grade bubblesheet exams, upload/download bubblesheet data files, and review previously graded bubblesheet exams.'
1.596.2.12.2. 1(raebur 11438:0): },
11439:0): { linktext => 'Verify Receipt Number',
11440:0): url => $url5,
6(raebur 11441:1): permission => $permissions{'either'},
1(raebur 11442:0): icon => 'receipt_number.png',
11443:0): linktitle => 'Verify a system-generated receipt number for correct problem solution.'
11444:0): }
11445:0):
1.538 schulted 11446: ]
11447: });
1.596.2.12.2. 0.2.7(ra 11448:an-25): my $cdom = $env{"course.$env{'request.course.id'}.domain"};
11449:an-25): my $cnum = $env{"course.$env{'request.course.id'}.num"};
11450:an-25): my %passback = &Apache::lonnet::dump('nohist_linkprot_passback',$cdom,$cnum);
11451:an-25): if (keys(%passback)) {
11452:an-25): $fields{'command'} = 'initialpassback';
11453:an-25): my $url6 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
11454:an-25): push (@{$menu[1]{items}},
11455:an-25): { linktext => 'Passback of Scores',
11456:an-25): url => $url6,
11457:an-25): permission => $permissions{'either'},
11458:an-25): icon => 'passback.png',
11459:an-25): linktitle => 'Passback scores to launcher CMS for resources accessed via LTI-mediated deep-linking',
11460:an-25): });
11461:an-25): }
1.443 banghart 11462: # Create the menu
11463: my $Str;
1.445 banghart 11464: $Str .= '<form method="post" action="" name="gradingMenu">';
11465: $Str .= '<input type="hidden" name="command" value="" />'.
1.596.2.12.2. 1(raebur 11466:0): '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.443 banghart 11467:
1.596.2.12.2. 1(raebur 11468:0): $Str .= &Apache::lonhtmlcommon::generate_menu(@menu);
1.443 banghart 11469: return $Str;
11470: }
11471:
1.596.2.12.2. 1(raebur 11472:0): sub ungraded {
11473:0): my ($request)=@_;
11474:0): &submit_options($request);
11475:0): }
1.443 banghart 11476:
1.596.2.12.2. 1(raebur 11477:0): sub submit_options_sequence {
11478:0): my ($request,$symb) = @_;
1.72 ng 11479: if (!$symb) {return '';}
1.596.2.12.2. 1(raebur 11480:0): &commonJSfunctions($request);
11481:0): my $result;
1.72 ng 11482:
1.596.2.12.2. 1(raebur 11483:0): $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
11484:0): '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
11485:0): $result.=&selectfield(0).
11486:0): '<input type="hidden" name="command" value="pickStudentPage" />
11487:0): <div>
11488:0): <input type="submit" value="'.&mt('Next').' →" />
11489:0): </div>
11490:0): </div>
11491:0): </form>';
11492:0): return $result;
11493:0): }
11494:0):
11495:0): sub submit_options_table {
11496:0): my ($request,$symb) = @_;
11497:0): if (!$symb) {return '';}
1.118 ng 11498: &commonJSfunctions($request);
1.596.2.12.2. 0.2.4(ra 11499:ul-23): my $is_tool = ($symb =~ /ext\.tool$/);
1.473 albertel 11500: my $result;
1.596.2.12.2. 1(raebur 11501:0):
11502:0): $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
11503:0): '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
11504:0):
0.2.4(ra 11505:ul-23): $result.=&selectfield(1,$is_tool).
1(raebur 11506:0): '<input type="hidden" name="command" value="viewgrades" />
11507:0): <div>
11508:0): <input type="submit" value="'.&mt('Next').' →" />
11509:0): </div>
11510:0): </div>
11511:0): </form>';
11512:0): return $result;
11513:0): }
11514:0):
11515:0): sub submit_options_download {
11516:0): my ($request,$symb) = @_;
11517:0): if (!$symb) {return '';}
11518:0):
11519:0): my $res_error;
11520:0): my ($partlist,$handgrade,$responseType,$numresp,$numessay,$numdropbox) =
11521:0): &response_type($symb,\$res_error);
11522:0): if ($res_error) {
11523:0): $request->print(&mt('An error occurred retrieving response types'));
11524:0): return;
11525:0): }
11526:0): unless ($numessay) {
11527:0): $request->print(&mt('No essayresponse items found'));
11528:0): return;
11529:0): }
11530:0): my $table;
11531:0): if (ref($partlist) eq 'ARRAY') {
11532:0): if (scalar(@$partlist) > 1 ) {
11533:0): $table = &showResourceInfo($symb,$partlist,$responseType,'gradingMenu',1,1);
1.533 bisitz 11534: }
11535: }
11536:
1.596.2.12.2. 0.2.4(ra 11537:ul-23): my $is_tool = ($symb =~ /ext\.tool$/);
1(raebur 11538:0): &commonJSfunctions($request);
1.72 ng 11539:
1.596.2.12.2. 1(raebur 11540:0): my $result='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
11541:0): $table."\n".
11542:0): '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
1.472 albertel 11543: $result.='
1.533 bisitz 11544: <h2>
1.596.2.12.2. 3(raebur 11545:0): '.&mt('Select Students for whom to Download Submitted Files').'
0.2.4(ra 11546:ul-23): </h2>'.&selectfield(1,$is_tool).'
1(raebur 11547:0): <input type="hidden" name="command" value="downloadfileslink" />
11548:0): <input type="submit" value="'.&mt('Next').' →" />
11549:0): </div>
11550:0): </div>
11551:0):
11552:0):
11553:0): </form>';
11554:0): return $result;
11555:0): }
11556:0):
11557:0): #--- Displays the submissions first page -------
11558:0): sub submit_options {
11559:0): my ($request,$symb) = @_;
11560:0): if (!$symb) {return '';}
11561:0):
0.2.4(ra 11562:ul-23): my $is_tool = ($symb =~ /ext\.tool$/);
1(raebur 11563:0): &commonJSfunctions($request);
11564:0): my $result;
11565:0):
11566:0): $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
11567:0): '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n";
0.2.4(ra 11568:ul-23): $result.=&selectfield(1,$is_tool).'
1(raebur 11569:0): <input type="hidden" name="command" value="submission" />
11570:0): <input type="submit" value="'.&mt('Next').' →" />
11571:0): </div>
11572:0): </div>
11573:0): </form>';
11574:0): return $result;
11575:0): }
11576:0):
11577:0): sub selectfield {
0.2.4(ra 11578:ul-23): my ($full,$is_tool)=@_;
11579:ul-23): my %options;
11580:ul-23): if ($is_tool) {
11581:ul-23): %options =
11582:ul-23): (&transtatus_options,
11583:ul-23): 'select_form_order' => ['yes','incorrect','all']);
11584:ul-23): } else {
11585:ul-23): %options =
11586:ul-23): (&substatus_options,
11587:ul-23): 'select_form_order' => ['yes','queued','graded','incorrect','all']);
11588:ul-23): }
7(raebur 11589:1):
11590:1): #
11591:1): # PrepareClasslist() needs to be called to avoid getting a sections list
11592:1): # for a different course from the @Sections global in lonstatistics.pm,
11593:1): # populated by an earlier request.
11594:1): #
11595:1): &Apache::lonstatistics::PrepareClasslist();
11596:1):
1(raebur 11597:0): my $result='<div class="LC_columnSection">
1.533 bisitz 11598:
11599: <fieldset>
11600: <legend>
11601: '.&mt('Sections').'
11602: </legend>
1.596.2.12.2. 1(raebur 11603:0): '.&Apache::lonstatistics::SectionSelect('section','multiple',5).'
1.533 bisitz 11604: </fieldset>
1.596.2.12.2. 1(raebur 11605:0):
1.533 bisitz 11606: <fieldset>
11607: <legend>
11608: '.&mt('Groups').'
11609: </legend>
11610: '.&Apache::lonstatistics::GroupSelect('group','multiple',5).'
11611: </fieldset>
1.596.2.12.2. 1(raebur 11612:0):
1.533 bisitz 11613: <fieldset>
11614: <legend>
11615: '.&mt('Access Status').'
11616: </legend>
1.596.2.12.2. 1(raebur 11617:0): '.&Apache::lonhtmlcommon::StatusOptions(undef,undef,5,undef,'mult').'
11618:0): </fieldset>';
11619:0): if ($full) {
0.2.4(ra 11620:ul-23): my $heading = &mt('Submission Status');
11621:ul-23): if ($is_tool) {
11622:ul-23): $heading = &mt('Transaction Status');
11623:ul-23): }
1(raebur 11624:0): $result.='
1.533 bisitz 11625: <fieldset>
11626: <legend>
1.596.2.12.2. 0.2.4(ra 11627:ul-23): '.$heading.'
1(raebur 11628:0): </legend>'.
11629:0): &Apache::loncommon::select_form('all','submitonly',\%options).
11630:0): '</fieldset>';
11631:0): }
11632:0): $result.='</div><br />';
1.44 ng 11633: return $result;
1.2 albertel 11634: }
11635:
1.596.2.12.2. 7(raebur 11636:6): sub substatus_options {
11637:6): return &Apache::lonlocal::texthash(
11638:6): 'yes' => 'with submissions',
11639:6): 'queued' => 'in grading queue',
11640:6): 'graded' => 'with ungraded submissions',
11641:6): 'incorrect' => 'with incorrect submissions',
0(raebur 11642:7): 'all' => 'with any status',
11643:7): );
7(raebur 11644:6): }
11645:6):
1(raebur 11646:0): sub transtatus_options {
11647:0): return &Apache::lonlocal::texthash(
11648:0): 'yes' => 'with score transactions',
11649:0): 'incorrect' => 'with less than full credit',
11650:0): 'all' => 'with any status',
11651:0): );
11652:0): }
11653:0):
1.285 albertel 11654: sub reset_perm {
11655: undef(%perm);
11656: }
11657:
11658: sub init_perm {
11659: &reset_perm();
1.300 albertel 11660: foreach my $test_perm ('vgr','mgr','opa') {
11661:
11662: my $scope = $env{'request.course.id'};
11663: if (!($perm{$test_perm}=&Apache::lonnet::allowed($test_perm,$scope))) {
11664:
11665: $scope .= '/'.$env{'request.course.sec'};
11666: if ( $perm{$test_perm}=
11667: &Apache::lonnet::allowed($test_perm,$scope)) {
11668: $perm{$test_perm.'_section'}=$env{'request.course.sec'};
11669: } else {
11670: delete($perm{$test_perm});
11671: }
1.285 albertel 11672: }
11673: }
11674: }
11675:
1.596.2.12.2. (raeburn 11676:): sub init_old_essays {
11677:): my ($symb,$apath,$adom,$aname) = @_;
11678:): if ($symb ne '') {
11679:): my %essays = &Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
11680:): if (keys(%essays) > 0) {
11681:): $old_essays{$symb} = \%essays;
11682:): }
11683:): }
11684:): return;
11685:): }
11686:):
11687:): sub reset_old_essays {
11688:): undef(%old_essays);
11689:): }
11690:):
1.400 www 11691: sub gather_clicker_ids {
1.408 albertel 11692: my %clicker_ids;
1.400 www 11693:
11694: my $classlist = &Apache::loncoursedata::get_classlist();
11695:
11696: # Set up a couple variables.
1.407 albertel 11697: my $username_idx = &Apache::loncoursedata::CL_SNAME();
11698: my $domain_idx = &Apache::loncoursedata::CL_SDOM();
1.438 www 11699: my $status_idx = &Apache::loncoursedata::CL_STATUS();
1.400 www 11700:
1.407 albertel 11701: foreach my $student (keys(%$classlist)) {
1.438 www 11702: if ($classlist->{$student}->[$status_idx] ne 'Active') { next; }
1.407 albertel 11703: my $username = $classlist->{$student}->[$username_idx];
11704: my $domain = $classlist->{$student}->[$domain_idx];
1.400 www 11705: my $clickers =
1.408 albertel 11706: (&Apache::lonnet::userenvironment($domain,$username,'clickers'))[1];
1.400 www 11707: foreach my $id (split(/\,/,$clickers)) {
1.414 www 11708: $id=~s/^[\#0]+//;
1.421 www 11709: $id=~s/[\-\:]//g;
1.407 albertel 11710: if (exists($clicker_ids{$id})) {
1.408 albertel 11711: $clicker_ids{$id}.=','.$username.':'.$domain;
1.400 www 11712: } else {
1.408 albertel 11713: $clicker_ids{$id}=$username.':'.$domain;
1.400 www 11714: }
11715: }
11716: }
1.407 albertel 11717: return %clicker_ids;
1.400 www 11718: }
11719:
1.402 www 11720: sub gather_adv_clicker_ids {
1.408 albertel 11721: my %clicker_ids;
1.402 www 11722: my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'};
11723: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
11724: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
1.409 albertel 11725: foreach my $element (sort(keys(%coursepersonnel))) {
1.402 www 11726: foreach my $person (split(/\,/,$coursepersonnel{$element})) {
11727: my ($puname,$pudom)=split(/\:/,$person);
11728: my $clickers =
1.408 albertel 11729: (&Apache::lonnet::userenvironment($pudom,$puname,'clickers'))[1];
1.405 www 11730: foreach my $id (split(/\,/,$clickers)) {
1.414 www 11731: $id=~s/^[\#0]+//;
1.421 www 11732: $id=~s/[\-\:]//g;
1.408 albertel 11733: if (exists($clicker_ids{$id})) {
11734: $clicker_ids{$id}.=','.$puname.':'.$pudom;
11735: } else {
11736: $clicker_ids{$id}=$puname.':'.$pudom;
11737: }
1.405 www 11738: }
1.402 www 11739: }
11740: }
1.407 albertel 11741: return %clicker_ids;
1.402 www 11742: }
11743:
1.413 www 11744: sub clicker_grading_parameters {
11745: return ('gradingmechanism' => 'scalar',
11746: 'upfiletype' => 'scalar',
11747: 'specificid' => 'scalar',
11748: 'pcorrect' => 'scalar',
11749: 'pincorrect' => 'scalar');
11750: }
11751:
1.400 www 11752: sub process_clicker {
1.596.2.12.2. 1(raebur 11753:0): my ($r,$symb)=@_;
1.400 www 11754: if (!$symb) {return '';}
11755: my $result=&checkforfile_js();
1.596.2.12.2. 1(raebur 11756:0): $result.=&Apache::loncommon::start_data_table().
11757:0): &Apache::loncommon::start_data_table_header_row().
11758:0): '<th>'.&mt('Specify a file containing clicker information and set grading options.').'</th>'.
11759:0): &Apache::loncommon::end_data_table_header_row().
11760:0): &Apache::loncommon::start_data_table_row()."<td>\n";
1.413 www 11761: # Attempt to restore parameters from last session, set defaults if not present
11762: my %Saveable_Parameters=&clicker_grading_parameters();
11763: &Apache::loncommon::restore_course_settings('grades_clicker',
11764: \%Saveable_Parameters);
11765: if (!$env{'form.pcorrect'}) { $env{'form.pcorrect'}=100; }
11766: if (!$env{'form.pincorrect'}) { $env{'form.pincorrect'}=100; }
11767: if (!$env{'form.gradingmechanism'}) { $env{'form.gradingmechanism'}='attendance'; }
11768: if (!$env{'form.upfiletype'}) { $env{'form.upfiletype'}='iclicker'; }
11769:
11770: my %checked;
1.521 www 11771: foreach my $gradingmechanism ('attendance','personnel','specific','given') {
1.413 www 11772: if ($env{'form.gradingmechanism'} eq $gradingmechanism) {
1.569 bisitz 11773: $checked{$gradingmechanism}=' checked="checked"';
1.413 www 11774: }
11775: }
11776:
1.596.2.12.2. 1(raebur 11777:0): my $upload=&mt("Evaluate File");
1.400 www 11778: my $type=&mt("Type");
1.402 www 11779: my $attendance=&mt("Award points just for participation");
11780: my $personnel=&mt("Correctness determined from response by course personnel");
1.414 www 11781: my $specific=&mt("Correctness determined from response with clicker ID(s)");
1.521 www 11782: my $given=&mt("Correctness determined from given list of answers").' '.
11783: '<font size="-2"><tt>('.&mt("Provide comma-separated list. Use '*' for any answer correct, '-' for skip").')</tt></font>';
1.402 www 11784: my $pcorrect=&mt("Percentage points for correct solution");
11785: my $pincorrect=&mt("Percentage points for incorrect solution");
1.413 www 11786: my $selectform=&Apache::loncommon::select_form($env{'form.upfiletype'},'upfiletype',
1.596.2.1 raeburn 11787: {'iclicker' => 'i>clicker',
1.596.2.12.2. (raeburn 11788:): 'interwrite' => 'interwrite PRS',
11789:): 'turning' => 'Turning Technologies'});
1.418 albertel 11790: $symb = &Apache::lonenc::check_encrypt($symb);
1.596.2.12.2. 1(raebur 11791:0): $result.= &Apache::lonhtmlcommon::scripttag(<<ENDUPFORM);
1.402 www 11792: function sanitycheck() {
11793: // Accept only integer percentages
11794: document.forms.gradesupload.pcorrect.value=Math.round(document.forms.gradesupload.pcorrect.value);
11795: document.forms.gradesupload.pincorrect.value=Math.round(document.forms.gradesupload.pincorrect.value);
11796: // Find out grading choice
11797: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
11798: if (document.forms.gradesupload.gradingmechanism[i].checked) {
11799: gradingchoice=document.forms.gradesupload.gradingmechanism[i].value;
11800: }
11801: }
11802: // By default, new choice equals user selection
11803: newgradingchoice=gradingchoice;
11804: // Not good to give more points for false answers than correct ones
11805: if (Math.round(document.forms.gradesupload.pcorrect.value)<Math.round(document.forms.gradesupload.pincorrect.value)) {
11806: document.forms.gradesupload.pcorrect.value=document.forms.gradesupload.pincorrect.value;
11807: }
11808: // If new choice is attendance only, and old choice was correctness-based, restore defaults
11809: if ((gradingchoice=='attendance') && (document.forms.gradesupload.waschecked.value!='attendance')) {
11810: document.forms.gradesupload.pcorrect.value=100;
11811: document.forms.gradesupload.pincorrect.value=100;
11812: }
11813: // If the values are different, cannot be attendance only
11814: if ((Math.round(document.forms.gradesupload.pcorrect.value)!=Math.round(document.forms.gradesupload.pincorrect.value)) &&
11815: (gradingchoice=='attendance')) {
11816: newgradingchoice='personnel';
11817: }
11818: // Change grading choice to new one
11819: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
11820: if (document.forms.gradesupload.gradingmechanism[i].value==newgradingchoice) {
11821: document.forms.gradesupload.gradingmechanism[i].checked=true;
11822: } else {
11823: document.forms.gradesupload.gradingmechanism[i].checked=false;
11824: }
11825: }
11826: // Remember the old state
11827: document.forms.gradesupload.waschecked.value=newgradingchoice;
11828: }
1.596.2.12.2. 1(raebur 11829:0): ENDUPFORM
11830:0): $result.= <<ENDUPFORM;
1.400 www 11831: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
11832: <input type="hidden" name="symb" value="$symb" />
11833: <input type="hidden" name="command" value="processclickerfile" />
11834: <input type="file" name="upfile" size="50" />
11835: <br /><label>$type: $selectform</label>
1.596.2.12.2. 1(raebur 11836:0): ENDUPFORM
11837:0): $result.='</td>'.&Apache::loncommon::end_data_table_row().
11838:0): &Apache::loncommon::start_data_table_row().'<td>'.(<<ENDGRADINGFORM);
11839:0): <label><input type="radio" name="gradingmechanism" value="attendance"$checked{'attendance'} onclick="sanitycheck()" />$attendance </label>
1.589 bisitz 11840: <br /><label><input type="radio" name="gradingmechanism" value="personnel"$checked{'personnel'} onclick="sanitycheck()" />$personnel</label>
11841: <br /><label><input type="radio" name="gradingmechanism" value="specific"$checked{'specific'} onclick="sanitycheck()" />$specific </label>
1.414 www 11842: <input type="text" name="specificid" value="$env{'form.specificid'}" size="20" />
1.589 bisitz 11843: <br /><label><input type="radio" name="gradingmechanism" value="given"$checked{'given'} onclick="sanitycheck()" />$given </label>
1.521 www 11844: <br />
11845: <input type="text" name="givenanswer" size="50" />
1.413 www 11846: <input type="hidden" name="waschecked" value="$env{'form.gradingmechanism'}" />
1.596.2.12.2. 1(raebur 11847:0): ENDGRADINGFORM
11848:0): $result.='</td>'.&Apache::loncommon::end_data_table_row().
11849:0): &Apache::loncommon::start_data_table_row().'<td>'.(<<ENDPERCFORM);
11850:0): <label>$pcorrect: <input type="text" name="pcorrect" size="4" value="$env{'form.pcorrect'}" onchange="sanitycheck()" /></label>
1.589 bisitz 11851: <br /><label>$pincorrect: <input type="text" name="pincorrect" size="4" value="$env{'form.pincorrect'}" onchange="sanitycheck()" /></label>
11852: <br /><input type="button" onclick="javascript:checkUpload(this.form);" value="$upload" />
1.400 www 11853: </form>
1.596.2.12.2. 1(raebur 11854:0): ENDPERCFORM
11855:0): $result.='</td>'.
11856:0): &Apache::loncommon::end_data_table_row().
11857:0): &Apache::loncommon::end_data_table();
1.400 www 11858: return $result;
11859: }
11860:
11861: sub process_clicker_file {
1.596.2.12.2. 1(raebur 11862:0): my ($r,$symb) = @_;
1.400 www 11863: if (!$symb) {return '';}
1.413 www 11864:
11865: my %Saveable_Parameters=&clicker_grading_parameters();
11866: &Apache::loncommon::store_course_settings('grades_clicker',
11867: \%Saveable_Parameters);
1.596.2.12.2. 1(raebur 11868:0): my $result='';
1.404 www 11869: if (($env{'form.gradingmechanism'} eq 'specific') && ($env{'form.specificid'}!~/\w/)) {
1.408 albertel 11870: $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 11871:0): return $result;
1.404 www 11872: }
1.522 www 11873: if (($env{'form.gradingmechanism'} eq 'given') && ($env{'form.givenanswer'}!~/\S/)) {
1.521 www 11874: $result.='<span class="LC_error">'.&mt('You need to specify the correct answer').'</span>';
1.596.2.12.2. 1(raebur 11875:0): return $result;
1.521 www 11876: }
1.522 www 11877: my $foundgiven=0;
1.521 www 11878: if ($env{'form.gradingmechanism'} eq 'given') {
11879: $env{'form.givenanswer'}=~s/^\s*//gs;
11880: $env{'form.givenanswer'}=~s/\s*$//gs;
1.596.2.4 raeburn 11881: $env{'form.givenanswer'}=~s/[^a-zA-Z0-9\.\*\-\+]+/\,/g;
1.521 www 11882: $env{'form.givenanswer'}=uc($env{'form.givenanswer'});
1.522 www 11883: my @answers=split(/\,/,$env{'form.givenanswer'});
11884: $foundgiven=$#answers+1;
1.521 www 11885: }
1.407 albertel 11886: my %clicker_ids=&gather_clicker_ids();
1.408 albertel 11887: my %correct_ids;
1.404 www 11888: if ($env{'form.gradingmechanism'} eq 'personnel') {
1.408 albertel 11889: %correct_ids=&gather_adv_clicker_ids();
1.404 www 11890: }
11891: if ($env{'form.gradingmechanism'} eq 'specific') {
1.414 www 11892: foreach my $correct_id (split(/[\s\,]/,$env{'form.specificid'})) {;
11893: $correct_id=~tr/a-z/A-Z/;
11894: $correct_id=~s/\s//gs;
11895: $correct_id=~s/^[\#0]+//;
1.421 www 11896: $correct_id=~s/[\-\:]//g;
1.414 www 11897: if ($correct_id) {
11898: $correct_ids{$correct_id}='specified';
11899: }
11900: }
1.400 www 11901: }
1.404 www 11902: if ($env{'form.gradingmechanism'} eq 'attendance') {
1.408 albertel 11903: $result.=&mt('Score based on attendance only');
1.521 www 11904: } elsif ($env{'form.gradingmechanism'} eq 'given') {
1.522 www 11905: $result.=&mt('Score based on [_1] ([_2] answers)','<tt>'.$env{'form.givenanswer'}.'</tt>',$foundgiven);
1.404 www 11906: } else {
1.408 albertel 11907: my $number=0;
1.411 www 11908: $result.='<p><b>'.&mt('Correctness determined by the following IDs').'</b>';
1.408 albertel 11909: foreach my $id (sort(keys(%correct_ids))) {
1.411 www 11910: $result.='<br /><tt>'.$id.'</tt> - ';
1.408 albertel 11911: if ($correct_ids{$id} eq 'specified') {
11912: $result.=&mt('specified');
11913: } else {
11914: my ($uname,$udom)=split(/\:/,$correct_ids{$id});
11915: $result.=&Apache::loncommon::plainname($uname,$udom);
11916: }
11917: $number++;
11918: }
1.411 www 11919: $result.="</p>\n";
1.596.2.12.2. 5(raebur 11920:3): if ($number==0) {
11921:3): $result .=
11922:3): &Apache::lonhtmlcommon::confirm_success(
11923:3): &mt('No IDs found to determine correct answer'),1);
1(raebur 11924:0): return $result;
5(raebur 11925:3): }
1.404 www 11926: }
1.405 www 11927: if (length($env{'form.upfile'}) < 2) {
1.596.2.12.2. 5(raebur 11928:3): $result .=
11929:3): &Apache::lonhtmlcommon::confirm_success(
11930:3): &mt('The file: [_1] you attempted to upload contained no information. Please check that you entered the correct filename.',
11931:3): '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'),1);
1(raebur 11932:0): return $result;
1.405 www 11933: }
1.596.2.12.2. 7(raebur 11934:9): my $mimetype;
11935:9): if ($env{'form.upfiletype'} eq 'iclicker') {
11936:9): my $mm = new File::MMagic;
11937:9): $mimetype = $mm->checktype_contents($env{'form.upfile'});
11938:9): unless (($mimetype eq 'text/plain') || ($mimetype eq 'text/html')) {
11939:9): $result.= '<p>'.
11940:9): &Apache::lonhtmlcommon::confirm_success(
11941:9): &mt('File format is neither csv (iclicker 6) nor xml (iclicker 7)'),1).'</p>';
1(raebur 11942:0): return $result;
7(raebur 11943:9): }
11944:9): } elsif (($env{'form.upfiletype'} ne 'interwrite') && ($env{'form.upfiletype'} ne 'turning')) {
11945:9): $result .= '<p>'.
11946:9): &Apache::lonhtmlcommon::confirm_success(
11947:9): &mt('Invalid clicker type: choose one of: i>clicker, Interwrite PRS, or Turning Technologies.'),1).'</p>';
1(raebur 11948:0): return $result;
7(raebur 11949:9): }
1.410 www 11950:
11951: # Were able to get all the info needed, now analyze the file
11952:
1.411 www 11953: $result.=&Apache::loncommon::studentbrowser_javascript();
1.418 albertel 11954: $symb = &Apache::lonenc::check_encrypt($symb);
1.596.2.12.2. 1(raebur 11955:0): $result.=&Apache::loncommon::start_data_table().
11956:0): &Apache::loncommon::start_data_table_header_row().
11957:0): '<th>'.&mt('Evaluate clicker file').'</th>'.
11958:0): &Apache::loncommon::end_data_table_header_row().
11959:0): &Apache::loncommon::start_data_table_row().(<<ENDHEADER);
11960:0): <td>
1.410 www 11961: <form method="post" action="/adm/grades" name="clickeranalysis">
11962: <input type="hidden" name="symb" value="$symb" />
11963: <input type="hidden" name="command" value="assignclickergrades" />
1.411 www 11964: <input type="hidden" name="gradingmechanism" value="$env{'form.gradingmechanism'}" />
11965: <input type="hidden" name="pcorrect" value="$env{'form.pcorrect'}" />
11966: <input type="hidden" name="pincorrect" value="$env{'form.pincorrect'}" />
1.410 www 11967: ENDHEADER
1.522 www 11968: if ($env{'form.gradingmechanism'} eq 'given') {
11969: $result.='<input type="hidden" name="correct:given" value="'.$env{'form.givenanswer'}.'" />';
11970: }
1.408 albertel 11971: my %responses;
11972: my @questiontitles;
1.405 www 11973: my $errormsg='';
11974: my $number=0;
11975: if ($env{'form.upfiletype'} eq 'iclicker') {
1.596.2.12.2. 7(raebur 11976:9): if ($mimetype eq 'text/plain') {
11977:9): ($errormsg,$number)=&iclicker_eval(\@questiontitles,\%responses);
11978:9): } elsif ($mimetype eq 'text/html') {
11979:9): ($errormsg,$number)=&iclickerxml_eval(\@questiontitles,\%responses);
11980:9): }
11981:9): } elsif ($env{'form.upfiletype'} eq 'interwrite') {
1.419 www 11982: ($errormsg,$number)=&interwrite_eval(\@questiontitles,\%responses);
1.596.2.12.2. 7(raebur 11983:9): } elsif ($env{'form.upfiletype'} eq 'turning') {
(raeburn 11984:): ($errormsg,$number)=&turning_eval(\@questiontitles,\%responses);
11985:): }
1.411 www 11986: $result.='<br />'.&mt('Found [_1] question(s)',$number).'<br />'.
11987: '<input type="hidden" name="number" value="'.$number.'" />'.
11988: &mt('Awarding [_1] percent for correct and [_2] percent for incorrect responses',
11989: $env{'form.pcorrect'},$env{'form.pincorrect'}).
11990: '<br />';
1.522 www 11991: if (($env{'form.gradingmechanism'} eq 'given') && ($number!=$foundgiven)) {
11992: $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 11993:0): return $result;
1.522 www 11994: }
1.414 www 11995: # Remember Question Titles
11996: # FIXME: Possibly need delimiter other than ":"
11997: for (my $i=0;$i<$number;$i++) {
11998: $result.='<input type="hidden" name="question:'.$i.'" value="'.
11999: &HTML::Entities::encode($questiontitles[$i],'"&<>').'" />';
12000: }
1.411 www 12001: my $correct_count=0;
12002: my $student_count=0;
12003: my $unknown_count=0;
1.414 www 12004: # Match answers with usernames
12005: # FIXME: Possibly need delimiter other than ":"
1.409 albertel 12006: foreach my $id (keys(%responses)) {
1.410 www 12007: if ($correct_ids{$id}) {
1.414 www 12008: $result.="\n".'<input type="hidden" name="correct:'.$correct_count.':'.$correct_ids{$id}.'" value="'.$responses{$id}.'" />';
1.411 www 12009: $correct_count++;
1.410 www 12010: } elsif ($clicker_ids{$id}) {
1.437 www 12011: if ($clicker_ids{$id}=~/\,/) {
12012: # More than one user with the same clicker!
1.596.2.12.2. 1(raebur 12013:0): $result.="</td>".&Apache::loncommon::end_data_table_row().
12014:0): &Apache::loncommon::start_data_table_row()."<td>".
12015:0): &mt('Clicker registered more than once').": <tt>".$id."</tt><br />";
1.437 www 12016: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
12017: "<select name='multi".$id."'>";
12018: foreach my $reguser (sort(split(/\,/,$clicker_ids{$id}))) {
12019: $result.="<option value='".$reguser."'>".&Apache::loncommon::plainname(split(/\:/,$reguser)).' ('.$reguser.')</option>';
12020: }
12021: $result.='</select>';
12022: $unknown_count++;
12023: } else {
12024: # Good: found one and only one user with the right clicker
12025: $result.="\n".'<input type="hidden" name="student:'.$clicker_ids{$id}.'" value="'.$responses{$id}.'" />';
12026: $student_count++;
12027: }
1.410 www 12028: } else {
1.596.2.12.2. 1(raebur 12029:0): $result.="</td>".&Apache::loncommon::end_data_table_row().
12030:0): &Apache::loncommon::start_data_table_row()."<td>".
12031:0): &mt('Unregistered Clicker')." <tt>".$id."</tt><br />";
1.411 www 12032: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
12033: "\n".&mt("Username").": <input type='text' name='uname".$id."' /> ".
12034: "\n".&mt("Domain").": ".
12035: &Apache::loncommon::select_dom_form($env{'course.'.$env{'request.course.id'}.'.domain'},'udom'.$id).' '.
1.596.2.12.2. 0(raebur 12036:0): &Apache::loncommon::selectstudent_link('clickeranalysis','uname'.$id,'udom'.$id,'',$id);
1.411 www 12037: $unknown_count++;
1.410 www 12038: }
1.405 www 12039: }
1.412 www 12040: $result.='<hr />'.
12041: &mt('Found [_1] registered and [_2] unregistered clickers.',$student_count,$unknown_count);
1.521 www 12042: if (($env{'form.gradingmechanism'} ne 'attendance') && ($env{'form.gradingmechanism'} ne 'given')) {
1.412 www 12043: if ($correct_count==0) {
1.596.2.12.2. 8(raebur 12044:3): $errormsg.="Found no correct answers for grading!";
1.412 www 12045: } elsif ($correct_count>1) {
1.414 www 12046: $result.='<br /><span class="LC_warning">'.&mt("Found [_1] entries for grading!",$correct_count).'</span>';
1.412 www 12047: }
12048: }
1.428 www 12049: if ($number<1) {
12050: $errormsg.="Found no questions.";
12051: }
1.412 www 12052: if ($errormsg) {
12053: $result.='<br /><span class="LC_error">'.&mt($errormsg).'</span>';
12054: } else {
12055: $result.='<br /><input type="submit" name="finalize" value="'.&mt('Finalize Grading').'" />';
12056: }
1.596.2.12.2. 1(raebur 12057:0): $result.='</form></td>'.
12058:0): &Apache::loncommon::end_data_table_row().
12059:0): &Apache::loncommon::end_data_table();
12060:0): return $result;
1.400 www 12061: }
12062:
1.405 www 12063: sub iclicker_eval {
1.406 www 12064: my ($questiontitles,$responses)=@_;
1.405 www 12065: my $number=0;
12066: my $errormsg='';
12067: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
1.410 www 12068: my %components=&Apache::loncommon::record_sep($line);
12069: my @entries=map {$components{$_}} (sort(keys(%components)));
1.408 albertel 12070: if ($entries[0] eq 'Question') {
12071: for (my $i=3;$i<$#entries;$i+=6) {
12072: $$questiontitles[$number]=$entries[$i];
12073: $number++;
12074: }
12075: }
12076: if ($entries[0]=~/^\#/) {
12077: my $id=$entries[0];
12078: my @idresponses;
12079: $id=~s/^[\#0]+//;
12080: for (my $i=0;$i<$number;$i++) {
12081: my $idx=3+$i*6;
1.596.2.4 raeburn 12082: $entries[$idx]=~s/[^a-zA-Z0-9\.\*\-\+]+//g;
1.408 albertel 12083: push(@idresponses,$entries[$idx]);
12084: }
12085: $$responses{$id}=join(',',@idresponses);
12086: }
1.405 www 12087: }
12088: return ($errormsg,$number);
12089: }
12090:
1.596.2.12.2. 7(raebur 12091:9): sub iclickerxml_eval {
12092:9): my ($questiontitles,$responses)=@_;
12093:9): my $number=0;
12094:9): my $errormsg='';
12095:9): my @state;
12096:9): my %respbyid;
12097:9): my $p = HTML::Parser->new
12098:9): (
12099:9): xml_mode => 1,
12100:9): start_h =>
12101:9): [sub {
12102:9): my ($tagname,$attr) = @_;
12103:9): push(@state,$tagname);
12104:9): if ("@state" eq "ssn p") {
12105:9): my $title = $attr->{qn};
12106:9): $title =~ s/(^\s+|\s+$)//g;
12107:9): $questiontitles->[$number]=$title;
12108:9): } elsif ("@state" eq "ssn p v") {
12109:9): my $id = $attr->{id};
12110:9): my $entry = $attr->{ans};
12111:9): $id=~s/^[\#0]+//;
12112:9): $entry =~s/[^a-zA-Z0-9\.\*\-\+]+//g;
12113:9): $respbyid{$id}[$number] = $entry;
12114:9): }
12115:9): }, "tagname, attr"],
12116:9): end_h =>
12117:9): [sub {
12118:9): my ($tagname) = @_;
12119:9): if ("@state" eq "ssn p") {
12120:9): $number++;
12121:9): }
12122:9): pop(@state);
12123:9): }, "tagname"],
12124:9): );
12125:9):
12126:9): $p->parse($env{'form.upfile'});
12127:9): $p->eof;
12128:9): foreach my $id (keys(%respbyid)) {
12129:9): $responses->{$id}=join(',',@{$respbyid{$id}});
12130:9): }
12131:9): return ($errormsg,$number);
12132:9): }
12133:9):
1.419 www 12134: sub interwrite_eval {
12135: my ($questiontitles,$responses)=@_;
12136: my $number=0;
12137: my $errormsg='';
1.420 www 12138: my $skipline=1;
12139: my $questionnumber=0;
12140: my %idresponses=();
1.419 www 12141: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
12142: my %components=&Apache::loncommon::record_sep($line);
12143: my @entries=map {$components{$_}} (sort(keys(%components)));
1.420 www 12144: if ($entries[1] eq 'Time') { $skipline=0; next; }
12145: if ($entries[1] eq 'Response') { $skipline=1; }
12146: next if $skipline;
12147: if ($entries[0]!=$questionnumber) {
12148: $questionnumber=$entries[0];
12149: $$questiontitles[$number]=&mt('Question [_1]',$questionnumber);
12150: $number++;
1.419 www 12151: }
1.420 www 12152: my $id=$entries[4];
12153: $id=~s/^[\#0]+//;
1.421 www 12154: $id=~s/^v\d*\://i;
12155: $id=~s/[\-\:]//g;
1.420 www 12156: $idresponses{$id}[$number]=$entries[6];
12157: }
1.524 raeburn 12158: foreach my $id (keys(%idresponses)) {
1.420 www 12159: $$responses{$id}=join(',',@{$idresponses{$id}});
12160: $$responses{$id}=~s/^\s*\,//;
1.419 www 12161: }
12162: return ($errormsg,$number);
12163: }
12164:
1.596.2.12.2. (raeburn 12165:): sub turning_eval {
12166:): my ($questiontitles,$responses)=@_;
12167:): my $number=0;
12168:): my $errormsg='';
12169:): foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
12170:): my %components=&Apache::loncommon::record_sep($line);
12171:): my @entries=map {$components{$_}} (sort(keys(%components)));
12172:): if ($#entries>$number) { $number=$#entries; }
12173:): my $id=$entries[0];
12174:): my @idresponses;
12175:): $id=~s/^[\#0]+//;
12176:): unless ($id) { next; }
12177:): for (my $idx=1;$idx<=$#entries;$idx++) {
12178:): $entries[$idx]=~s/\,/\;/g;
12179:): $entries[$idx]=~s/[^a-zA-Z0-9\.\*\-\+\;]+//g;
12180:): push(@idresponses,$entries[$idx]);
12181:): }
12182:): $$responses{$id}=join(',',@idresponses);
12183:): }
12184:): for (my $i=1; $i<=$number; $i++) {
12185:): $$questiontitles[$i]=&mt('Question [_1]',$i);
12186:): }
12187:): return ($errormsg,$number);
12188:): }
12189:):
1.414 www 12190: sub assign_clicker_grades {
1.596.2.12.2. 1(raebur 12191:0): my ($r,$symb) = @_;
1.414 www 12192: if (!$symb) {return '';}
1.416 www 12193: # See which part we are saving to
1.582 raeburn 12194: my $res_error;
12195: my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
12196: if ($res_error) {
12197: return &navmap_errormsg();
12198: }
1.596.2.12.2. 0.2.7(ra 12199:an-25): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
12200:an-25): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
12201:an-25): my %needpb = &passbacks_for_symb($cdom,$cnum,$symb);
12202:an-25): my (%skip_passback,%pbsave);
1.416 www 12203: # FIXME: This should probably look for the first handgradeable part
12204: my $part=$$partlist[0];
12205: # Start screen output
1.596.2.12.2. 1(raebur 12206:0): my $result = &Apache::loncommon::start_data_table().
12207:0): &Apache::loncommon::start_data_table_header_row().
12208:0): '<th>'.&mt('Assigning grades based on clicker file').'</th>'.
12209:0): &Apache::loncommon::end_data_table_header_row().
12210:0): &Apache::loncommon::start_data_table_row().'<td>';
1.414 www 12211: # Get correct result
12212: # FIXME: Possibly need delimiter other than ":"
12213: my @correct=();
1.415 www 12214: my $gradingmechanism=$env{'form.gradingmechanism'};
12215: my $number=$env{'form.number'};
12216: if ($gradingmechanism ne 'attendance') {
1.414 www 12217: foreach my $key (keys(%env)) {
12218: if ($key=~/^form\.correct\:/) {
12219: my @input=split(/\,/,$env{$key});
12220: for (my $i=0;$i<=$#input;$i++) {
12221: if (($correct[$i]) && ($input[$i]) &&
12222: ($correct[$i] ne $input[$i])) {
12223: $result.='<br /><span class="LC_warning">'.
12224: &mt('More than one correct result given for question "[_1]": [_2] versus [_3].',
12225: $env{'form.question:'.$i},$correct[$i],$input[$i]).'</span>';
1.596.2.4 raeburn 12226: } elsif (($input[$i]) || ($input[$i] eq '0')) {
1.414 www 12227: $correct[$i]=$input[$i];
12228: }
12229: }
12230: }
12231: }
1.415 www 12232: for (my $i=0;$i<$number;$i++) {
1.596.2.4 raeburn 12233: if ((!$correct[$i]) && ($correct[$i] ne '0')) {
1.414 www 12234: $result.='<br /><span class="LC_error">'.
12235: &mt('No correct result given for question "[_1]"!',
12236: $env{'form.question:'.$i}).'</span>';
12237: }
12238: }
1.596.2.4 raeburn 12239: $result.='<br />'.&mt("Correct answer: [_1]",join(', ',map { ((($_) || ($_ eq '0'))?$_:'-') } @correct));
1.414 www 12240: }
12241: # Start grading
1.415 www 12242: my $pcorrect=$env{'form.pcorrect'};
12243: my $pincorrect=$env{'form.pincorrect'};
1.416 www 12244: my $storecount=0;
1.596.2.4 raeburn 12245: my %users=();
1.415 www 12246: foreach my $key (keys(%env)) {
1.420 www 12247: my $user='';
1.415 www 12248: if ($key=~/^form\.student\:(.*)$/) {
1.420 www 12249: $user=$1;
12250: }
12251: if ($key=~/^form\.unknown\:(.*)$/) {
12252: my $id=$1;
12253: if (($env{'form.uname'.$id}) && ($env{'form.udom'.$id})) {
12254: $user=$env{'form.uname'.$id}.':'.$env{'form.udom'.$id};
1.437 www 12255: } elsif ($env{'form.multi'.$id}) {
12256: $user=$env{'form.multi'.$id};
1.420 www 12257: }
12258: }
1.596.2.4 raeburn 12259: if ($user) {
12260: if ($users{$user}) {
12261: $result.='<br /><span class="LC_warning">'.
1.596.2.12.2. 8(raebur 12262:3): &mt('More than one entry found for [_1]!','<tt>'.$user.'</tt>').
1.596.2.4 raeburn 12263: '</span><br />';
12264: }
12265: $users{$user}=1;
1.415 www 12266: my @answer=split(/\,/,$env{$key});
12267: my $sum=0;
1.522 www 12268: my $realnumber=$number;
1.415 www 12269: for (my $i=0;$i<$number;$i++) {
1.576 www 12270: if ($correct[$i] eq '-') {
12271: $realnumber--;
1.596.2.12.2. 1(raebur 12272:0): } elsif (($answer[$i]) || ($answer[$i]=~/^[0\.]+$/)) {
1.415 www 12273: if ($gradingmechanism eq 'attendance') {
12274: $sum+=$pcorrect;
1.576 www 12275: } elsif ($correct[$i] eq '*') {
1.522 www 12276: $sum+=$pcorrect;
1.415 www 12277: } else {
1.596.2.4 raeburn 12278: # We actually grade if correct or not
12279: my $increment=$pincorrect;
12280: # Special case: numerical answer "0"
12281: if ($correct[$i] eq '0') {
12282: if ($answer[$i]=~/^[0\.]+$/) {
12283: $increment=$pcorrect;
12284: }
12285: # General numerical answer, both evaluate to something non-zero
12286: } elsif ((1.0*$correct[$i]!=0) && (1.0*$answer[$i]!=0)) {
12287: if (1.0*$correct[$i]==1.0*$answer[$i]) {
12288: $increment=$pcorrect;
12289: }
12290: # Must be just alphanumeric
12291: } elsif ($answer[$i] eq $correct[$i]) {
12292: $increment=$pcorrect;
1.415 www 12293: }
1.596.2.4 raeburn 12294: $sum+=$increment;
1.415 www 12295: }
12296: }
12297: }
1.522 www 12298: my $ave=$sum/(100*$realnumber);
1.416 www 12299: # Store
12300: my ($username,$domain)=split(/\:/,$user);
12301: my %grades=();
12302: $grades{"resource.$part.solved"}='correct_by_override';
12303: $grades{"resource.$part.awarded"}=$ave;
12304: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
12305: my $returncode=&Apache::lonnet::cstore(\%grades,$symb,
12306: $env{'request.course.id'},
12307: $domain,$username);
12308: if ($returncode ne 'ok') {
12309: $result.="<br /><span class=\"LC_error\">Failed to save student $username:$domain. Message when trying to save was ($returncode)</span>";
12310: } else {
12311: $storecount++;
1.596.2.12.2. 0.2.7(ra 12312:an-25): if (keys(%needpb)) {
12313:an-25): my (%weights,%awardeds,%excuseds);
12314:an-25): my $usec = &Apache::lonnet::getsection($domain,$username,$env{'request.course.id'});
12315:an-25): $weights{$symb}{$part} = &Apache::lonnet::EXT("resource.$part.weight",$symb,$domain,$username,$usec);
12316:an-25): $awardeds{$symb}{$part} = $ave;
12317:an-25): $excuseds{$symb}{$part} = '';
12318:an-25): &process_passbacks('clickergrade',[$symb],$cdom,$cnum,$domain,$username,$usec,\%weights,
12319:an-25): \%awardeds,\%excuseds,\%needpb,\%skip_passback,\%pbsave);
12320:an-25): }
1.416 www 12321: }
1.415 www 12322: }
12323: }
12324: # We are done
1.549 hauer 12325: $result.='<br />'.&mt('Successfully stored grades for [quant,_1,student].',$storecount).
1.596.2.4 raeburn 12326: '</td>'.
12327: &Apache::loncommon::end_data_table_row().
1.596.2.12.2. 1(raebur 12328:0): &Apache::loncommon::end_data_table();
12329:0): return $result;
1.414 www 12330: }
12331:
1.582 raeburn 12332: sub navmap_errormsg {
12333: return '<div class="LC_error">'.
12334: &mt('An error occurred retrieving information about resources in the course.').'<br />'.
1.595 raeburn 12335: &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 12336: '</div>';
12337: }
12338:
1.596.2.12.2. (raeburn 12339:): sub startpage {
5(raebur 12340:0): my ($r,$symb,$crumbs,$onlyfolderflag,$nodisplayflag,$stuvcurrent,$stuvdisp,$nomenu,$head_extra,$onload,$divforres) = @_;
9(raebur 12341:9): my %args;
12342:9): if ($onload) {
12343:9): my %loaditems = (
12344:9): 'onload' => $onload,
12345:9): );
12346:9): $args{'add_entries'} = \%loaditems;
12347:9): }
(raeburn 12348:): if ($nomenu) {
9(raebur 12349:9): $args{'only_body'} = 1;
5(raebur 12350:0): $r->print(&Apache::loncommon::start_page("Student's Version",$head_extra,\%args));
(raeburn 12351:): } else {
8(raebur 12352:1): if ($env{'request.course.id'}) {
12353:1): unshift(@$crumbs,{href=>&href_symb_cmd($symb,'gradingmenu'),text=>"Grading"});
12354:1): }
9(raebur 12355:9): $args{'bread_crumbs'} = $crumbs;
5(raebur 12356:0): $r->print(&Apache::loncommon::start_page('Grading',$head_extra,\%args));
(raeburn 12357:): }
12358:): unless ($nodisplayflag) {
1(raebur 12359:0): $r->print(&Apache::lonhtmlcommon::resource_info_box($symb,$onlyfolderflag,$stuvcurrent,$stuvdisp,$divforres));
(raeburn 12360:): }
12361:): }
12362:):
1(raebur 12363:0): sub select_problem {
12364:0): my ($r)=@_;
12365:0): $r->print('<h3>'.&mt('Select the problem or one of the problems you want to grade').'</h3><form action="/adm/grades">');
12366:0): $r->print(&Apache::lonstathelpers::problem_selector('.',undef,1,undef,undef,1));
12367:0): $r->print('<input type="hidden" name="command" value="gradingmenu" />');
12368:0): $r->print('<input type="submit" value="'.&mt('Next').' →" /></form>');
12369:0): }
12370:0):
0.2.5(ra 12371:ep-23): #----- display problem, answer, and submissions for a single student (no grading)
12372:ep-23):
12373:ep-23): sub view_as_user {
12374:ep-23): my ($symb,$vuname,$vudom,$hasperm) = @_;
12375:ep-23): my $plainname = &Apache::loncommon::plainname($vuname,$vudom,'lastname');
12376:ep-23): my $displayname = &nameUserString('',$plainname,$vuname,$vudom);
12377:ep-23): my $output = &Apache::loncommon::get_student_view($symb,$vuname,$vudom,
12378:ep-23): $env{'request.course.id'},
12379:ep-23): undef,{'disable_submit' => 1}).
12380:ep-23): "\n\n".
12381:ep-23): '<div class="LC_grade_show_user">'.
12382:ep-23): '<h2>'.$displayname.'</h2>'.
12383:ep-23): "\n".
12384:ep-23): &Apache::loncommon::track_student_link('View recent activity',
12385:ep-23): $vuname,$vudom,'check').' '.
12386:ep-23): "\n";
12387:ep-23): if (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) ||
12388:ep-23): (($env{'request.course.sec'} ne '') &&
12389:ep-23): &Apache::lonnet::allowed('opa',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
12390:ep-23): $output .= &Apache::loncommon::pprmlink(&mt('Set/Change parameters'),
12391:ep-23): $vuname,$vudom,$symb,'check');
12392:ep-23): }
12393:ep-23): $output .= "\n";
12394:ep-23): my $companswer = &Apache::loncommon::get_student_answers($symb,$vuname,$vudom,
12395:ep-23): $env{'request.course.id'});
12396:ep-23): $companswer=~s|<form(.*?)>||g;
12397:ep-23): $companswer=~s|</form>||g;
12398:ep-23): $companswer=~s|name="submit"|name="would_have_been_submit"|g;
12399:ep-23): $output .= '<div class="LC_Box">'.
12400:ep-23): '<h3 class="LC_hcell">'.&mt('Correct answer for[_1]',$displayname).'</h3>'.
12401:ep-23): $companswer.
12402:ep-23): '</div>'."\n";
12403:ep-23): my $is_tool = ($symb =~ /ext\.tool$/);
12404:ep-23): my ($essayurl,%coursedesc_by_cid);
12405:ep-23): (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb);
12406:ep-23): my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$vudom,$vuname);
12407:ep-23): my $res_error;
12408:ep-23): my ($partlist,$handgrade,$responseType,$numresp,$numessay) =
12409:ep-23): &response_type($symb,\$res_error);
12410:ep-23): my $fullname;
12411:ep-23): my $collabinfo;
12412:ep-23): if ($numessay) {
12413:ep-23): unless ($hasperm) {
12414:ep-23): &init_perm();
12415:ep-23): }
12416:ep-23): ($collabinfo,$fullname)=
12417:ep-23): &check_collaborators($symb,$vuname,$vudom,\%record,$handgrade,0);
12418:ep-23): unless ($hasperm) {
12419:ep-23): &reset_perm();
12420:ep-23): }
12421:ep-23): }
12422:ep-23): my $checkIcon = '<img alt="'.&mt('Check Mark').
12423:ep-23): '" src="'.$Apache::lonnet::perlvar{'lonIconsURL'}.
12424:ep-23): '/check.gif" height="16" border="0" />';
12425:ep-23): my ($lastsubonly,$partinfo) =
12426:ep-23): &show_last_submission($vuname,$vudom,$symb,$essayurl,$responseType,'datesub',
12427:ep-23): '',$fullname,\%record,\%coursedesc_by_cid);
12428:ep-23): $output .= '<div class="LC_Box">'.
12429:ep-23): '<h3 class="LC_hcell">'.&mt('Submissions').'</h3>'."\n".$collabinfo."\n";
12430:ep-23): if (($numresp > $numessay) & !$is_tool) {
12431:ep-23): $output .='<p class="LC_info">'.
12432:ep-23): &mt('Part(s) graded correct by the computer is marked with a [_1] symbol.',$checkIcon).
12433:ep-23): "</p>\n";
12434:ep-23): }
12435:ep-23): $output .= $partinfo;
12436:ep-23): $output .= $lastsubonly;
12437:ep-23): $output .= &displaySubByDates($symb,\%record,$partlist,$responseType,$checkIcon,$vuname,$vudom);
12438:ep-23): $output .= '</div></div>'."\n";
12439:ep-23): return $output;
12440:ep-23): }
12441:ep-23):
1.1 albertel 12442: sub handler {
1.41 ng 12443: my $request=$_[0];
1.434 albertel 12444: &reset_caches();
1.596.2.4 raeburn 12445: if ($request->header_only) {
12446: &Apache::loncommon::content_type($request,'text/html');
12447: $request->send_http_header;
12448: return OK;
1.41 ng 12449: }
12450: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.596.2.4 raeburn 12451:
1.596.2.12.2. 1(raebur 12452:0): # see what command we need to execute
12453:0):
1.160 albertel 12454: my @commands=&Apache::loncommon::get_env_multiple('form.command');
12455: my $command=$commands[0];
1.447 foxr 12456:
1.596.2.12.2. 1(raebur 12457:0): &init_perm();
12458:0): if (!$env{'request.course.id'}) {
12459:0): unless ((&Apache::lonnet::allowed('usc',$env{'request.role.domain'})) &&
12460:0): ($command =~ /^scantronupload/)) {
12461:0): # Not in a course.
12462:0): $env{'user.error.msg'}="/adm/grades::vgr:0:0:Cannot display grades page outside course context";
12463:0): return HTTP_NOT_ACCEPTABLE;
12464:0): }
12465:0): } elsif (!%perm) {
12466:0): $request->internal_redirect('/adm/quickgrades');
12467:0): return OK;
12468:0): }
12469:0): &Apache::loncommon::content_type($request,'text/html');
12470:0): $request->send_http_header;
12471:0):
1.160 albertel 12472: if ($#commands > 0) {
12473: &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands));
12474: }
1.447 foxr 12475:
1.596.2.12.2. 0.2.7(ra 12476:an-25): # -------------------------------------- Flag and buffer for registered cleanup
12477:an-25): $registered_cleanup=0;
12478:an-25): undef(@Apache::grades::ltipassback);
12479:an-25):
1(raebur 12480:0): # see what the symb is
12481:0):
12482:0): my $symb=$env{'form.symb'};
12483:0): unless ($symb) {
12484:0): (my $url=$env{'form.url'}) =~ s-^https*://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
12485:0): $symb=&Apache::lonnet::symbread($url);
12486:0): }
12487:0): &Apache::lonenc::check_decrypt(\$symb);
12488:0):
1.513 foxr 12489: $ssi_error = 0;
1.596.2.12.2. 1(raebur 12490:0): if (($symb eq '' || $command eq '') && ($env{'request.course.id'})) {
12491:0): #
12492:0): # Not called from a resource, but inside a course
12493:0): #
12494:0): &startpage($request,undef,[],1,1);
12495:0): &select_problem($request);
1.41 ng 12496: } else {
1.596.2.12.2. 1(raebur 12497:0): if ($command eq 'submission' && $perm{'vgr'}) {
12498:0): my ($stuvcurrent,$stuvdisp,$versionform,$js,$onload);
(raeburn 12499:): if (($env{'form.student'} ne '') && ($env{'form.userdom'} ne '')) {
12500:): ($stuvcurrent,$stuvdisp,$versionform,$js) =
12501:): &choose_task_version_form($symb,$env{'form.student'},
12502:): $env{'form.userdom'});
12503:): }
1(raebur 12504:0): my $divforres;
12505:0): if ($env{'form.student'} eq '') {
12506:0): $js .= &part_selector_js();
12507:0): $onload = "toggleParts('gradesub');";
12508:0): } else {
12509:0): $divforres = 1;
12510:0): }
5(raebur 12511:0): my $head_extra = $js;
12512:0): unless ($env{'form.vProb'} eq 'no') {
12513:0): my $csslinks = &Apache::loncommon::css_links($symb);
12514:0): if ($csslinks) {
12515:0): $head_extra .= "\n$csslinks";
12516:0): }
12517:0): }
12518:0): &startpage($request,$symb,[{href=>"", text=>"Student Submissions"}],undef,undef,
12519:0): $stuvcurrent,$stuvdisp,undef,$head_extra,$onload,$divforres);
(raeburn 12520:): if ($versionform) {
2(raebur 12521:0): if ($divforres) {
12522:0): $request->print('<div style="padding:0;clear:both;margin:0;border:0"></div>');
12523:0): }
(raeburn 12524:): $request->print($versionform);
12525:): }
1(raebur 12526:0): ($env{'form.student'} eq '' ? &listStudents($request,$symb,'',$divforres) : &submission($request,0,0,$symb,$divforres,$command));
(raeburn 12527:): } elsif ($command eq 'versionsub' && $perm{'vgr'}) {
12528:): my ($stuvcurrent,$stuvdisp,$versionform,$js) =
12529:): &choose_task_version_form($symb,$env{'form.student'},
12530:): $env{'form.userdom'},
12531:): $env{'form.inhibitmenu'});
5(raebur 12532:0): my $head_extra = $js;
12533:0): unless ($env{'form.vProb'} eq 'no') {
12534:0): my $csslinks = &Apache::loncommon::css_links($symb);
12535:0): if ($csslinks) {
12536:0): $head_extra .= "\n$csslinks";
12537:0): }
12538:0): }
12539:0): &startpage($request,$symb,[{href=>"", text=>"Previous Student Version"}],undef,undef,
12540:0): $stuvcurrent,$stuvdisp,$env{'form.inhibitmenu'},$head_extra);
(raeburn 12541:): if ($versionform) {
12542:): $request->print($versionform);
12543:): }
12544:): $request->print('<br clear="all" />');
12545:): $request->print(&show_previous_task_version($request,$symb));
1(raebur 12546:0): } elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) {
12547:0): &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'all_for_one'),text=>'Grade page/folder for one student'},
12548:0): {href=>'',text=>'Select student'}],1,1);
12549:0): &pickStudentPage($request,$symb);
12550:0): } elsif ($command eq 'displayPage' && $perm{'vgr'}) {
5(raebur 12551:0): my $csslinks;
12552:0): unless ($env{'form.vProb'} eq 'no') {
12553:0): $csslinks = &Apache::loncommon::css_links($symb,'map');
12554:0): }
1(raebur 12555:0): &startpage($request,$symb,
12556:0): [{href=>&href_symb_cmd($symb,'all_for_one'),text=>'Grade page/folder for one student'},
12557:0): {href=>'',text=>'Select student'},
5(raebur 12558:0): {href=>'',text=>'Grade student'}],1,1,undef,undef,undef,$csslinks);
1(raebur 12559:0): &displayPage($request,$symb);
12560:0): } elsif ($command eq 'gradeByPage' && $perm{'mgr'}) {
12561:0): &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'all_for_one'),text=>'Grade page/folder for one student'},
12562:0): {href=>'',text=>'Select student'},
12563:0): {href=>'',text=>'Grade student'},
12564:0): {href=>'',text=>'Store grades'}],1,1);
12565:0): &updateGradeByPage($request,$symb);
12566:0): } elsif ($command eq 'processGroup' && $perm{'vgr'}) {
5(raebur 12567:0): my $csslinks;
12568:0): unless ($env{'form.vProb'} eq 'no') {
12569:0): $csslinks = &Apache::loncommon::css_links($symb);
12570:0): }
1(raebur 12571:0): &startpage($request,$symb,[{href=>'',text=>'...'},
5(raebur 12572:0): {href=>'',text=>'Modify grades'}],undef,undef,undef,undef,undef,$csslinks,undef,1);
1(raebur 12573:0): &processGroup($request,$symb);
12574:0): } elsif ($command eq 'gradingmenu' && $perm{'vgr'}) {
12575:0): &startpage($request,$symb);
12576:0): $request->print(&grading_menu($request,$symb));
12577:0): } elsif ($command eq 'individual' && $perm{'vgr'}) {
12578:0): &startpage($request,$symb,[{href=>'',text=>'Select individual students to grade'}]);
12579:0): $request->print(&submit_options($request,$symb));
12580:0): } elsif ($command eq 'ungraded' && $perm{'vgr'}) {
12581:0): my $js = &part_selector_js();
12582:0): my $onload = "toggleParts('gradesub');";
12583:0): &startpage($request,$symb,[{href=>'',text=>'Grade ungraded submissions'}],
12584:0): undef,undef,undef,undef,undef,$js,$onload);
12585:0): $request->print(&listStudents($request,$symb,'graded'));
12586:0): } elsif ($command eq 'table' && $perm{'vgr'}) {
12587:0): &startpage($request,$symb,[{href=>"", text=>"Grading table"}]);
12588:0): $request->print(&submit_options_table($request,$symb));
12589:0): } elsif ($command eq 'all_for_one' && $perm{'vgr'}) {
12590:0): &startpage($request,$symb,[{href=>'',text=>'Grade page/folder for one student'}],1,1);
12591:0): $request->print(&submit_options_sequence($request,$symb));
12592:0): } elsif ($command eq 'viewgrades' && $perm{'vgr'}) {
12593:0): &startpage($request,$symb,[{href=>&href_symb_cmd($symb,"table"), text=>"Grading table"},{href=>'', text=>"Modify grades"}]);
12594:0): $request->print(&viewgrades($request,$symb));
12595:0): } elsif ($command eq 'handgrade' && $perm{'mgr'}) {
12596:0): &startpage($request,$symb,[{href=>'',text=>'...'},
12597:0): {href=>'',text=>'Store grades'}]);
12598:0): $request->print(&processHandGrade($request,$symb));
12599:0): } elsif ($command eq 'editgrades' && $perm{'mgr'}) {
12600:0): &startpage($request,$symb,[{href=>&href_symb_cmd($symb,"table"), text=>"Grading table"},
12601:0): {href=>&href_symb_cmd($symb,'viewgrades').'&group=all§ion=all&Status=Active',
12602:0): text=>"Modify grades"},
12603:0): {href=>'', text=>"Store grades"}]);
12604:0): $request->print(&editgrades($request,$symb));
12605:0): } elsif ($command eq 'initialverifyreceipt' && $perm{'vgr'}) {
12606:0): &startpage($request,$symb,[{href=>'',text=>'Verify Receipt Number'}]);
12607:0): $request->print(&initialverifyreceipt($request,$symb));
12608:0): } elsif ($command eq 'verify' && $perm{'vgr'}) {
12609:0): &startpage($request,$symb,[{href=>&href_symb_cmd($symb,"initialverifyreceipt"),text=>'Verify Receipt Number'},
12610:0): {href=>'',text=>'Verification Result'}]);
12611:0): $request->print(&verifyreceipt($request,$symb));
1.400 www 12612: } elsif ($command eq 'processclicker' && $perm{'mgr'}) {
1.596.2.12.2. 1(raebur 12613:0): &startpage($request,$symb,[{href=>'', text=>'Process clicker'}]);
12614:0): $request->print(&process_clicker($request,$symb));
1.400 www 12615: } elsif ($command eq 'processclickerfile' && $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): $request->print(&process_clicker_file($request,$symb));
1.414 www 12619: } elsif ($command eq 'assignclickergrades' && $perm{'mgr'}) {
1.596.2.12.2. 1(raebur 12620:0): &startpage($request,$symb,[{href=>&href_symb_cmd($symb,'processclicker'), text=>'Process clicker'},
12621:0): {href=>'', text=>'Process clicker file'},
12622:0): {href=>'', text=>'Store grades'}]);
12623:0): $request->print(&assign_clicker_grades($request,$symb));
12624:0): } elsif ($command eq 'csvform' && $perm{'mgr'}) {
12625:0): &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
12626:0): $request->print(&upcsvScores_form($request,$symb));
12627:0): } elsif ($command eq 'csvupload' && $perm{'mgr'}) {
12628:0): &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
12629:0): $request->print(&csvupload($request,$symb));
12630:0): } elsif ($command eq 'csvuploadmap' && $perm{'mgr'} ) {
12631:0): &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
12632:0): $request->print(&csvuploadmap($request,$symb));
12633:0): } elsif ($command eq 'csvuploadoptions' && $perm{'mgr'}) {
12634:0): if ($env{'form.associate'} ne 'Reverse Association') {
12635:0): &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
12636:0): $request->print(&csvuploadoptions($request,$symb));
12637:0): } else {
12638:0): if ( $env{'form.upfile_associate'} ne 'reverse' ) {
12639:0): $env{'form.upfile_associate'} = 'reverse';
12640:0): } else {
12641:0): $env{'form.upfile_associate'} = 'forward';
12642:0): }
12643:0): &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
12644:0): $request->print(&csvuploadmap($request,$symb));
12645:0): }
12646:0): } elsif ($command eq 'csvuploadassign' && $perm{'mgr'} ) {
12647:0): &startpage($request,$symb,[{href=>'', text=>'Upload Scores'}],1,1);
12648:0): $request->print(&csvuploadassign($request,$symb));
12649:0): } elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
12650:0): &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1,
12651:0): undef,undef,undef,undef,'toggleScantab(document.rules);');
12652:0): $request->print(&scantron_selectphase($request,undef,$symb));
12653:0): } elsif ($command eq 'scantron_warning' && $perm{'mgr'}) {
12654:0): &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
12655:0): $request->print(&scantron_do_warning($request,$symb));
12656:0): } elsif ($command eq 'scantron_validate' && $perm{'mgr'}) {
12657:0): &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
12658:0): $request->print(&scantron_validate_file($request,$symb));
12659:0): } elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
12660:0): &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
12661:0): $request->print(&scantron_process_students($request,$symb));
12662:0): } elsif ($command eq 'scantronupload' &&
12663:0): (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
12664:0): &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
12665:0): &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1,
12666:0): undef,undef,undef,undef,'toggleScantab(document.rules);');
12667:0): $request->print(&scantron_upload_scantron_data($request,$symb));
12668:0): } elsif ($command eq 'scantronupload_save' &&
12669:0): (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
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_upload_scantron_data_save($request,$symb));
12673:0): } elsif ($command eq 'scantron_download' &&
12674:0): &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
12675:0): &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
12676:0): $request->print(&scantron_download_scantron_data($request,$symb));
1.523 raeburn 12677: } elsif ($command eq 'checksubmissions' && $perm{'vgr'}) {
1.596.2.12.2. 1(raebur 12678:0): &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1);
12679:0): $request->print(&checkscantron_results($request,$symb));
12680:0): } elsif ($command eq 'downloadfilesselect' && $perm{'vgr'}) {
12681:0): my $js = &part_selector_js();
12682:0): my $onload = "toggleParts('gradingMenu');";
12683:0): &startpage($request,$symb,[{href=>'', text=>'Select which submissions to download'}],
12684:0): undef,undef,undef,undef,undef,$js,$onload);
12685:0): $request->print(&submit_options_download($request,$symb));
12686:0): } elsif ($command eq 'downloadfileslink' && $perm{'vgr'}) {
12687:0): &startpage($request,$symb,
12688:0): [{href=>&href_symb_cmd($symb,'downloadfilesselect'), text=>'Select which submissions to download'},
12689:0): {href=>'', text=>'Download submitted files'}],
12690:0): undef,undef,undef,undef,undef,undef,undef,1);
2(raebur 12691:0): $request->print('<div style="padding:0;clear:both;margin:0;border:0"></div>');
1(raebur 12692:0): &submit_download_link($request,$symb);
0.2.7(ra 12693:an-25): } elsif ($command eq 'initialpassback') {
12694:an-25): &startpage($request,$symb,[{href=>'', text=>'Choose Launcher'}],undef,1);
12695:an-25): $request->print(&initialpassback($request,$symb));
12696:an-25): } elsif ($command eq 'passback') {
12697:an-25): &startpage($request,$symb,
12698:an-25): [{href=>&href_symb_cmd($symb,'initialpassback'), text=>'Choose Launcher'},
12699:an-25): {href=>'', text=>'Types of User'}],undef,1);
12700:an-25): $request->print(&passback_filters($request,$symb));
12701:an-25): } elsif ($command eq 'passbacknames') {
12702:an-25): my $chosen;
12703:an-25): if ($env{'form.passback'} ne '') {
12704:an-25): if ($env{'form.passback'} eq &unescape($env{'form.passback'})) {
12705:an-25): $env{'form.passback'} = &escape($env{'form.passback'} );
12706:an-25): }
12707:an-25): $chosen = &HTML::Entities::encode($env{'form.passback'},'<>"&');
12708:an-25): }
12709:an-25): &startpage($request,$symb,
12710:an-25): [{href=>&href_symb_cmd($symb,'initialpassback'), text=>'Choose Launcher'},
12711:an-25): {href=>&href_symb_cmd($symb,'passback').'&passback='.$chosen, text=>'Types of User'},
12712:an-25): {href=>'', text=>'Select Users'}],undef,1);
12713:an-25): $request->print(&names_for_passback($request,$symb));
12714:an-25): } elsif ($command eq 'passbackscores') {
12715:an-25): my ($chosen,$stu_status);
12716:an-25): if ($env{'form.passback'} ne '') {
12717:an-25): if ($env{'form.passback'} eq &unescape($env{'form.passback'})) {
12718:an-25): $env{'form.passback'} = &escape($env{'form.passback'} );
12719:an-25): }
12720:an-25): $chosen = &HTML::Entities::encode($env{'form.passback'},'<>"&');
12721:an-25): }
12722:an-25): if ($env{'form.Status'}) {
12723:an-25): $stu_status = &HTML::Entities::encode($env{'form.Status'});
12724:an-25): }
12725:an-25): &startpage($request,$symb,
12726:an-25): [{href=>&href_symb_cmd($symb,'initialpassback'), text=>'Choose Launcher'},
12727:an-25): {href=>&href_symb_cmd($symb,'passback').'&passback='.$chosen, text=>'Types of User'},
12728:an-25): {href=>&href_symb_cmd($symb,'passbacknames').'&Status='.$stu_status.'&passback='.$chosen, text=>'Select Users'},
12729:an-25): {href=>'', text=>'Execute Passback'}],undef,1);
12730:an-25): $request->print(&do_passback($request,$symb));
1(raebur 12731:0): } elsif ($command) {
12732:0): &startpage($request,$symb,[{href=>'', text=>'Access denied'}]);
12733:0): $request->print('<p class="LC_error">'.&mt('Access Denied ([_1])',$command).'</p>');
12734:0): }
1.2 albertel 12735: }
1.513 foxr 12736: if ($ssi_error) {
12737: &ssi_print_error($request);
12738: }
1.353 albertel 12739: $request->print(&Apache::loncommon::end_page());
1.434 albertel 12740: &reset_caches();
1.596.2.4 raeburn 12741: return OK;
1.44 ng 12742: }
12743:
1.1 albertel 12744: 1;
12745:
1.13 albertel 12746: __END__;
1.531 jms 12747:
12748:
12749: =head1 NAME
12750:
12751: Apache::grades
12752:
12753: =head1 SYNOPSIS
12754:
12755: Handles the viewing of grades.
12756:
12757: This is part of the LearningOnline Network with CAPA project
12758: described at http://www.lon-capa.org.
12759:
12760: =head1 OVERVIEW
12761:
12762: Do an ssi with retries:
12763: While I'd love to factor out this with the vesrion in lonprintout,
12764: 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
12765: I'm not quite ready to invent (e.g. an ssi_with_retry object).
12766:
12767: At least the logic that drives this has been pulled out into loncommon.
12768:
12769:
12770:
12771: ssi_with_retries - Does the server side include of a resource.
12772: if the ssi call returns an error we'll retry it up to
12773: the number of times requested by the caller.
1.596.2.12.2. 8(raebur 12774:4): If we still have a problem, no text is appended to the
1.531 jms 12775: output and we set some global variables.
12776: to indicate to the caller an SSI error occurred.
12777: All of this is supposed to deal with the issues described
1.596.2.12.2. 8(raebur 12778:4): in LON-CAPA BZ 5631 see:
1.531 jms 12779: http://bugs.lon-capa.org/show_bug.cgi?id=5631
12780: by informing the user that this happened.
12781:
12782: Parameters:
12783: resource - The resource to include. This is passed directly, without
12784: interpretation to lonnet::ssi.
12785: form - The form hash parameters that guide the interpretation of the resource
12786:
12787: retries - Number of retries allowed before giving up completely.
12788: Returns:
12789: On success, returns the rendered resource identified by the resource parameter.
12790: Side Effects:
12791: The following global variables can be set:
12792: ssi_error - If an unrecoverable error occurred this becomes true.
12793: It is up to the caller to initialize this to false
12794: if desired.
12795: ssi_error_resource - If an unrecoverable error occurred, this is the value
12796: of the resource that could not be rendered by the ssi
12797: call.
12798: ssi_error_message - The error string fetched from the ssi response
12799: in the event of an error.
12800:
12801:
12802: =head1 HANDLER SUBROUTINE
12803:
12804: ssi_with_retries()
12805:
12806: =head1 SUBROUTINES
12807:
12808: =over
12809:
12810: =item scantron_get_correction() :
12811:
12812: Builds the interface screen to interact with the operator to fix a
12813: specific error condition in a specific scanline
12814:
12815: Arguments:
12816: $r - Apache request object
12817: $i - number of the current scanline
12818: $scan_record - hash ref as returned from &scantron_parse_scanline()
1.596.2.12.2. 9(raebur 12819:9): $scan_config - hash ref as returned from &Apache::lonnet::get_scantron_config()
1.531 jms 12820: $line - full contents of the current scanline
12821: $error - error condition, valid values are
12822: 'incorrectCODE', 'duplicateCODE',
12823: 'doublebubble', 'missingbubble',
12824: 'duplicateID', 'incorrectID'
12825: $arg - extra information needed
12826: For errors:
12827: - duplicateID - paper number that this studentID was seen before on
12828: - duplicateCODE - array ref of the paper numbers this CODE was
12829: seen on before
12830: - incorrectCODE - current incorrect CODE
12831: - doublebubble - array ref of the bubble lines that have double
12832: bubble errors
12833: - missingbubble - array ref of the bubble lines that have missing
12834: bubble errors
12835:
1.596.2.12.2. 0(raebur 12836:2): $randomorder - True if exam folder (or a sub-folder) has randomorder set
12837:2): $randompick - True if exam folder (or a sub-folder) has randompick set
6(raebur 12838:3): $respnumlookup - Reference to HASH mapping question numbers in bubble lines
12839:3): for current line to question number used for same question
12840:3): in "Master Seqence" (as seen by Course Coordinator).
12841:3): $startline - Reference to hash where key is question number (0 is first)
12842:3): and value is number of first bubble line for current student
12843:3): or code-based randompick and/or randomorder.
12844:3):
12845:3):
1.531 jms 12846: =item scantron_get_maxbubble() :
12847:
1.582 raeburn 12848: Arguments:
12849: $nav_error - Reference to scalar which is a flag to indicate a
12850: failure to retrieve a navmap object.
12851: if $nav_error is set to 1 by scantron_get_maxbubble(), the
12852: calling routine should trap the error condition and display the warning
12853: found in &navmap_errormsg().
12854:
1.596.2.12.2. (raeburn 12855:): $scantron_config - Reference to bubblesheet format configuration hash.
12856:):
1.531 jms 12857: Returns the maximum number of bubble lines that are expected to
12858: occur. Does this by walking the selected sequence rendering the
12859: resource and then checking &Apache::lonxml::get_problem_counter()
12860: for what the current value of the problem counter is.
12861:
12862: Caches the results to $env{'form.scantron_maxbubble'},
12863: $env{'form.scantron.bubble_lines.n'},
12864: $env{'form.scantron.first_bubble_line.n'} and
12865: $env{"form.scantron.sub_bubblelines.n"}
1.596.2.12.2. 6(raebur 12866:3): which are the total number of bubble lines, the number of bubble
1.531 jms 12867: lines for response n and number of the first bubble line for response n,
12868: and a comma separated list of numbers of bubble lines for sub-questions
12869: (for optionresponse, matchresponse, and rankresponse items), for response n.
12870:
12871:
12872: =item scantron_validate_missingbubbles() :
12873:
12874: Validates all scanlines in the selected file to not have any
12875: answers that don't have bubbles that have not been verified
12876: to be bubble free.
12877:
12878: =item scantron_process_students() :
12879:
1.596.2.6 raeburn 12880: Routine that does the actual grading of the bubblesheet information.
1.531 jms 12881:
12882: The parsed scanline hash is added to %env
12883:
12884: Then foreach unskipped scanline it does an &Apache::lonnet::ssi()
12885: foreach resource , with the form data of
12886:
12887: 'submitted' =>'scantron'
12888: 'grade_target' =>'grade',
12889: 'grade_username'=> username of student
12890: 'grade_domain' => domain of student
12891: 'grade_courseid'=> of course
12892: 'grade_symb' => symb of resource to grade
12893:
12894: This triggers a grading pass. The problem grading code takes care
12895: of converting the bubbled letter information (now in %env) into a
12896: valid submission.
12897:
12898: =item scantron_upload_scantron_data() :
12899:
1.596.2.6 raeburn 12900: Creates the screen for adding a new bubblesheet data file to a course.
1.531 jms 12901:
12902: =item scantron_upload_scantron_data_save() :
12903:
12904: Adds a provided bubble information data file to the course if user
12905: has the correct privileges to do so.
12906:
12907: =item valid_file() :
12908:
12909: Validates that the requested bubble data file exists in the course.
12910:
12911: =item scantron_download_scantron_data() :
12912:
12913: Shows a list of the three internal files (original, corrected,
1.596.2.6 raeburn 12914: skipped) for a specific bubblesheet data file that exists in the
1.531 jms 12915: course.
12916:
12917: =item scantron_validate_ID() :
12918:
12919: Validates all scanlines in the selected file to not have any
1.556 weissno 12920: invalid or underspecified student/employee IDs
1.531 jms 12921:
1.582 raeburn 12922: =item navmap_errormsg() :
12923:
12924: Returns HTML mark-up inside a <div></div> with a link to re-initialize the course.
12925: Should be called whenever the request to instantiate a navmap object fails.
12926:
1.531 jms 12927: =back
12928:
12929: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>