Annotation of loncom/homework/grades.pm, revision 1.539
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.539 ! riegler 4: # $Id: grades.pm,v 1.538 2008/12/20 04:04:36 schulted Exp $
1.17 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
1.529 jms 29:
30:
1.1 albertel 31: package Apache::grades;
32: use strict;
33: use Apache::style;
34: use Apache::lonxml;
35: use Apache::lonnet;
1.3 albertel 36: use Apache::loncommon;
1.112 ng 37: use Apache::lonhtmlcommon;
1.68 ng 38: use Apache::lonnavmaps;
1.1 albertel 39: use Apache::lonhomework;
1.456 banghart 40: use Apache::lonpickcode;
1.55 matthew 41: use Apache::loncoursedata;
1.362 albertel 42: use Apache::lonmsg();
1.1 albertel 43: use Apache::Constants qw(:common);
1.167 sakharuk 44: use Apache::lonlocal;
1.386 raeburn 45: use Apache::lonenc;
1.170 albertel 46: use String::Similarity;
1.359 www 47: use LONCAPA;
48:
1.315 bowersj2 49: use POSIX qw(floor);
1.87 www 50:
1.435 foxr 51:
1.513 foxr 52:
1.435 foxr 53: my %perm=();
1.447 foxr 54:
1.513 foxr 55: # These variables are used to recover from ssi errors
56:
57: my $ssi_retries = 5;
58: my $ssi_error;
59: my $ssi_error_resource;
60: my $ssi_error_message;
61:
62:
63: sub ssi_with_retries {
64: my ($resource, $retries, %form) = @_;
65: my ($content, $response) = &Apache::loncommon::ssi_with_retries($resource, $retries, %form);
66: if ($response->is_error) {
67: $ssi_error = 1;
68: $ssi_error_resource = $resource;
69: $ssi_error_message = $response->code . " " . $response->message;
70: }
71:
72: return $content;
73:
74: }
75: #
76: # Prodcuces an ssi retry failure error message to the user:
77: #
78:
79: sub ssi_print_error {
80: my ($r) = @_;
1.516 raeburn 81: my $helpurl = &Apache::loncommon::top_nav_help('Helpdesk');
82: $r->print('
83: <br />
84: <h2>'.&mt('An unrecoverable network error occurred:').'</h2>
85: <p>
86: '.&mt('Unable to retrieve a resource from a server:').'<br />
87: '.&mt('Resource:').' '.$ssi_error_resource.'<br />
88: '.&mt('Error:').' '.$ssi_error_message.'
89: </p>
90: <p>'.
91: &mt('It is recommended that you try again later, as this error may mean the server was just temporarily unavailable, or is down for maintenance.').'<br />'.
92: &mt('If the error persists, please contact the [_1] for assistance.',$helpurl).
93: '</p>');
94: return;
1.513 foxr 95: }
96:
1.44 ng 97: #
1.146 albertel 98: # --- Retrieve the parts from the metadata file.---
1.44 ng 99: sub getpartlist {
1.324 albertel 100: my ($symb) = @_;
1.439 albertel 101:
102: my $navmap = Apache::lonnavmaps::navmap->new();
103: my $res = $navmap->getBySymb($symb);
104: my $partlist = $res->parts();
105: my $url = $res->src();
106: my @metakeys = split(/,/,&Apache::lonnet::metadata($url,'keys'));
107:
1.146 albertel 108: my @stores;
1.439 albertel 109: foreach my $part (@{ $partlist }) {
1.146 albertel 110: foreach my $key (@metakeys) {
111: if ($key =~ m/^stores_\Q$part\E_/) { push(@stores,$key); }
112: }
113: }
114: return @stores;
1.2 albertel 115: }
116:
1.44 ng 117: # --- Get the symbolic name of a problem and the url
1.324 albertel 118: sub get_symb {
1.173 albertel 119: my ($request,$silent) = @_;
1.257 albertel 120: (my $url=$env{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
121: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
1.173 albertel 122: if ($symb eq '') {
123: if (!$silent) {
124: $request->print("Unable to handle ambiguous references:$url:.");
125: return ();
126: }
127: }
1.418 albertel 128: &Apache::lonenc::check_decrypt(\$symb);
1.324 albertel 129: return ($symb);
1.32 ng 130: }
131:
1.129 ng 132: #--- Format fullname, username:domain if different for display
133: #--- Use anywhere where the student names are listed
134: sub nameUserString {
135: my ($type,$fullname,$uname,$udom) = @_;
136: if ($type eq 'header') {
1.485 albertel 137: return '<b> '.&mt('Fullname').' </b><span class="LC_internal_info">('.&mt('Username').')</span>';
1.129 ng 138: } else {
1.398 albertel 139: return ' '.$fullname.'<span class="LC_internal_info"> ('.$uname.
140: ($env{'user.domain'} eq $udom ? '' : ' ('.$udom.')').')</span>';
1.129 ng 141: }
142: }
143:
1.44 ng 144: #--- Get the partlist and the response type for a given problem. ---
145: #--- Indicate if a response type is coded handgraded or not. ---
1.39 ng 146: sub response_type {
1.324 albertel 147: my ($symb) = shift;
1.377 albertel 148:
149: my $navmap = Apache::lonnavmaps::navmap->new();
150: my $res = $navmap->getBySymb($symb);
151: my $partlist = $res->parts();
1.392 albertel 152: my %vPart =
153: map { $_ => 1 } (&Apache::loncommon::get_env_multiple('form.vPart'));
1.377 albertel 154: my (%response_types,%handgrade);
155: foreach my $part (@{ $partlist }) {
1.392 albertel 156: next if (%vPart && !exists($vPart{$part}));
157:
1.377 albertel 158: my @types = $res->responseType($part);
159: my @ids = $res->responseIds($part);
160: for (my $i=0; $i < scalar(@ids); $i++) {
161: $response_types{$part}{$ids[$i]} = $types[$i];
162: $handgrade{$part.'_'.$ids[$i]} =
163: &Apache::lonnet::EXT('resource.'.$part.'_'.$ids[$i].
164: '.handgrade',$symb);
1.41 ng 165: }
166: }
1.377 albertel 167: return ($partlist,\%handgrade,\%response_types);
1.39 ng 168: }
169:
1.375 albertel 170: sub flatten_responseType {
171: my ($responseType) = @_;
172: my @part_response_id =
173: map {
174: my $part = $_;
175: map {
176: [$part,$_]
177: } sort(keys(%{ $responseType->{$part} }));
178: } sort(keys(%$responseType));
179: return @part_response_id;
180: }
181:
1.207 albertel 182: sub get_display_part {
1.324 albertel 183: my ($partID,$symb)=@_;
1.207 albertel 184: my $display=&Apache::lonnet::EXT('resource.'.$partID.'.display',$symb);
185: if (defined($display) and $display ne '') {
1.398 albertel 186: $display.= " (<span class=\"LC_internal_info\">id $partID</span>)";
1.207 albertel 187: } else {
188: $display=$partID;
189: }
190: return $display;
191: }
1.269 raeburn 192:
1.118 ng 193: #--- Show resource title
194: #--- and parts and response type
195: sub showResourceInfo {
1.324 albertel 196: my ($symb,$probTitle,$checkboxes) = @_;
1.154 albertel 197: my $col=3;
198: if ($checkboxes) { $col=4; }
1.398 albertel 199: my $result = '<h3>'.&mt('Current Resource').': '.$probTitle.'</h3>'."\n";
200: $result .='<table border="0">';
1.324 albertel 201: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.126 ng 202: my %resptype = ();
1.122 ng 203: my $hdgrade='no';
1.154 albertel 204: my %partsseen;
1.524 raeburn 205: foreach my $partID (sort(keys(%$responseType))) {
206: foreach my $resID (sort(keys(%{ $responseType->{$partID} }))) {
1.375 albertel 207: my $handgrade=$$handgrade{$partID.'_'.$resID};
208: my $responsetype = $responseType->{$partID}->{$resID};
209: $hdgrade = $handgrade if ($handgrade eq 'yes');
210: $result.='<tr>';
211: if ($checkboxes) {
212: if (exists($partsseen{$partID})) {
213: $result.="<td> </td>";
214: } else {
1.401 albertel 215: $result.="<td><input type='checkbox' name='vPart' value='$partID' checked='checked' /></td>";
1.375 albertel 216: }
217: $partsseen{$partID}=1;
1.154 albertel 218: }
1.375 albertel 219: my $display_part=&get_display_part($partID,$symb);
1.539 ! riegler 220: $result.='<td><b>'.&mt('Part').': </b>'.$display_part.
! 221: ' <span class="LC_internal_info">'.$resID.'</span></td>'.
! 222: '<td><b>'.&mt('Type').': </b>'.$responsetype.'</td></tr>';
1.485 albertel 223: # '<td>'.&mt('<b>Handgrade: </b>[_1]',$handgrade).'</td></tr>';
1.154 albertel 224: }
1.118 ng 225: }
226: $result.='</table>'."\n";
1.147 albertel 227: return $result,$responseType,$hdgrade,$partlist,$handgrade;
1.118 ng 228: }
229:
1.434 albertel 230: sub reset_caches {
231: &reset_analyze_cache();
232: &reset_perm();
233: }
234:
235: {
236: my %analyze_cache;
1.148 albertel 237:
1.434 albertel 238: sub reset_analyze_cache {
239: undef(%analyze_cache);
240: }
241:
242: sub get_analyze {
1.525 raeburn 243: my ($symb,$uname,$udom,$no_increment)=@_;
1.434 albertel 244: my $key = "$symb\0$uname\0$udom";
245: return $analyze_cache{$key} if (exists($analyze_cache{$key}));
246:
247: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
248: $url=&Apache::lonnet::clutter($url);
1.513 foxr 249: my $subresult=&ssi_with_retries($url, $ssi_retries,
1.516 raeburn 250: ('grade_target' => 'analyze',
251: 'grade_domain' => $udom,
252: 'grade_symb' => $symb,
253: 'grade_courseid' =>
254: $env{'request.course.id'},
1.525 raeburn 255: 'grade_username' => $uname,
256: 'grade_noincrement' => $no_increment));
1.434 albertel 257: (undef,$subresult)=split(/_HASH_REF__/,$subresult,2);
258: my %analyze=&Apache::lonnet::str2hash($subresult);
259: return $analyze_cache{$key} = \%analyze;
260: }
261:
262: sub get_order {
1.525 raeburn 263: my ($partid,$respid,$symb,$uname,$udom,$no_increment)=@_;
264: my $analyze = &get_analyze($symb,$uname,$udom,$no_increment);
1.434 albertel 265: return $analyze->{"$partid.$respid.shown"};
266: }
267:
268: sub get_radiobutton_correct_foil {
269: my ($partid,$respid,$symb,$uname,$udom)=@_;
270: my $analyze = &get_analyze($symb,$uname,$udom);
271: foreach my $foil (@{&get_order($partid,$respid,$symb,$uname,$udom)}) {
272: if ($analyze->{"$partid.$respid.foil.value.$foil"} eq 'true') {
273: return $foil;
274: }
275: }
276: }
1.148 albertel 277: }
1.434 albertel 278:
1.118 ng 279: #--- Clean response type for display
1.335 albertel 280: #--- Currently filters option/rank/radiobutton/match/essay/Task
281: # response types only.
1.118 ng 282: sub cleanRecord {
1.336 albertel 283: my ($answer,$response,$symb,$partid,$respid,$record,$order,$version,
284: $uname,$udom) = @_;
1.398 albertel 285: my $grayFont = '<span class="LC_internal_info">';
1.148 albertel 286: if ($response =~ /^(option|rank)$/) {
287: my %answer=&Apache::lonnet::str2hash($answer);
288: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
289: my ($toprow,$bottomrow);
290: foreach my $foil (@$order) {
291: if ($grading{$foil} == 1) {
292: $toprow.='<td><b>'.$answer{$foil}.' </b></td>';
293: } else {
294: $toprow.='<td><i>'.$answer{$foil}.' </i></td>';
295: }
1.398 albertel 296: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.148 albertel 297: }
298: return '<blockquote><table border="1">'.
1.466 albertel 299: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
300: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.148 albertel 301: $grayFont.$bottomrow.'</tr>'.'</table></blockquote>';
302: } elsif ($response eq 'match') {
303: my %answer=&Apache::lonnet::str2hash($answer);
304: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
305: my @items=&Apache::lonnet::str2array($record->{$version."resource.$partid.$respid.submissionitems"});
306: my ($toprow,$middlerow,$bottomrow);
307: foreach my $foil (@$order) {
308: my $item=shift(@items);
309: if ($grading{$foil} == 1) {
310: $toprow.='<td><b>'.$item.' </b></td>';
1.398 albertel 311: $middlerow.='<td><b>'.$grayFont.$answer{$foil}.' </span></b></td>';
1.148 albertel 312: } else {
313: $toprow.='<td><i>'.$item.' </i></td>';
1.398 albertel 314: $middlerow.='<td><i>'.$grayFont.$answer{$foil}.' </span></i></td>';
1.148 albertel 315: }
1.398 albertel 316: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.118 ng 317: }
1.126 ng 318: return '<blockquote><table border="1">'.
1.466 albertel 319: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
320: '<tr valign="top"><td>'.$grayFont.&mt('Item ID').'</span></td>'.
1.148 albertel 321: $middlerow.'</tr>'.
1.466 albertel 322: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.148 albertel 323: $bottomrow.'</tr>'.'</table></blockquote>';
324: } elsif ($response eq 'radiobutton') {
325: my %answer=&Apache::lonnet::str2hash($answer);
326: my ($toprow,$bottomrow);
1.434 albertel 327: my $correct =
328: &get_radiobutton_correct_foil($partid,$respid,$symb,$uname,$udom);
329: foreach my $foil (@$order) {
1.148 albertel 330: if (exists($answer{$foil})) {
1.434 albertel 331: if ($foil eq $correct) {
1.466 albertel 332: $toprow.='<td><b>'.&mt('true').'</b></td>';
1.148 albertel 333: } else {
1.466 albertel 334: $toprow.='<td><i>'.&mt('true').'</i></td>';
1.148 albertel 335: }
336: } else {
1.466 albertel 337: $toprow.='<td>'.&mt('false').'</td>';
1.148 albertel 338: }
1.398 albertel 339: $bottomrow.='<td>'.$grayFont.$foil.'</span> </td>';
1.148 albertel 340: }
341: return '<blockquote><table border="1">'.
1.466 albertel 342: '<tr valign="top"><td>'.&mt('Answer').'</td>'.$toprow.'</tr>'.
343: '<tr valign="top"><td>'.$grayFont.&mt('Option ID').'</span></td>'.
1.148 albertel 344: $grayFont.$bottomrow.'</tr>'.'</table></blockquote>';
345: } elsif ($response eq 'essay') {
1.257 albertel 346: if (! exists ($env{'form.'.$symb})) {
1.122 ng 347: my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 348: $env{'course.'.$env{'request.course.id'}.'.domain'},
349: $env{'course.'.$env{'request.course.id'}.'.num'});
1.122 ng 350:
1.257 albertel 351: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
352: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
353: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
354: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
355: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
356: $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 357: }
1.166 albertel 358: $answer =~ s-\n-<br />-g;
359: return '<br /><br /><blockquote><tt>'.&keywords_highlight($answer).'</tt></blockquote>';
1.268 albertel 360: } elsif ( $response eq 'organic') {
361: my $result='Smile representation: "<tt>'.$answer.'</tt>"';
362: my $jme=$record->{$version."resource.$partid.$respid.molecule"};
363: $result.=&Apache::chemresponse::jme_img($jme,$answer,400);
364: return $result;
1.335 albertel 365: } elsif ( $response eq 'Task') {
366: if ( $answer eq 'SUBMITTED') {
367: my $files = $record->{$version."resource.$respid.$partid.bridgetask.portfiles"};
1.336 albertel 368: my $result = &Apache::bridgetask::file_list($files,$uname,$udom);
1.335 albertel 369: return $result;
370: } elsif ( grep(/^\Q$version\E.*?\.instance$/, keys(%{$record})) ) {
371: my @matches = grep(/^\Q$version\E.*?\.instance$/,
372: keys(%{$record}));
373: return join('<br />',($version,@matches));
374:
375:
376: } else {
377: my $result =
378: '<p>'
379: .&mt('Overall result: [_1]',
380: $record->{$version."resource.$respid.$partid.status"})
381: .'</p>';
382:
383: $result .= '<ul>';
384: my @grade = grep(/^\Q${version}resource.$respid.$partid.\E[^.]*[.]status$/,
385: keys(%{$record}));
386: foreach my $grade (sort(@grade)) {
387: my ($dim) = ($grade =~/[.]([^.]+)[.]status$/);
388: $result.= '<li>'.&mt("Dimension: [_1], status [_2] ",
389: $dim, $record->{$grade}).
390: '</li>';
391: }
392: $result.='</ul>';
393: return $result;
394: }
1.440 albertel 395: } elsif ( $response =~ m/(?:numerical|formula)/) {
396: $answer =
397: &Apache::loncommon::format_previous_attempt_value('submission',
398: $answer);
1.122 ng 399: }
1.118 ng 400: return $answer;
401: }
402:
403: #-- A couple of common js functions
404: sub commonJSfunctions {
405: my $request = shift;
406: $request->print(<<COMMONJSFUNCTIONS);
407: <script type="text/javascript" language="javascript">
408: function radioSelection(radioButton) {
409: var selection=null;
410: if (radioButton.length > 1) {
411: for (var i=0; i<radioButton.length; i++) {
412: if (radioButton[i].checked) {
413: return radioButton[i].value;
414: }
415: }
416: } else {
417: if (radioButton.checked) return radioButton.value;
418: }
419: return selection;
420: }
421:
422: function pullDownSelection(selectOne) {
423: var selection="";
424: if (selectOne.length > 1) {
425: for (var i=0; i<selectOne.length; i++) {
426: if (selectOne[i].selected) {
427: return selectOne[i].value;
428: }
429: }
430: } else {
1.138 albertel 431: // only one value it must be the selected one
432: return selectOne.value;
1.118 ng 433: }
434: }
435: </script>
436: COMMONJSFUNCTIONS
437: }
438:
1.44 ng 439: #--- Dumps the class list with usernames,list of sections,
440: #--- section, ids and fullnames for each user.
441: sub getclasslist {
1.449 banghart 442: my ($getsec,$filterlist,$getgroup) = @_;
1.291 albertel 443: my @getsec;
1.450 banghart 444: my @getgroup;
1.442 banghart 445: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.291 albertel 446: if (!ref($getsec)) {
447: if ($getsec ne '' && $getsec ne 'all') {
448: @getsec=($getsec);
449: }
450: } else {
451: @getsec=@{$getsec};
452: }
453: if (grep(/^all$/,@getsec)) { undef(@getsec); }
1.450 banghart 454: if (!ref($getgroup)) {
455: if ($getgroup ne '' && $getgroup ne 'all') {
456: @getgroup=($getgroup);
457: }
458: } else {
459: @getgroup=@{$getgroup};
460: }
461: if (grep(/^all$/,@getgroup)) { undef(@getgroup); }
1.291 albertel 462:
1.449 banghart 463: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
1.49 albertel 464: # Bail out if we were unable to get the classlist
1.56 matthew 465: return if (! defined($classlist));
1.449 banghart 466: &Apache::loncoursedata::get_group_memberships($classlist,$keylist);
1.56 matthew 467: #
468: my %sections;
469: my %fullnames;
1.205 matthew 470: foreach my $student (keys(%$classlist)) {
471: my $end =
472: $classlist->{$student}->[&Apache::loncoursedata::CL_END()];
473: my $start =
474: $classlist->{$student}->[&Apache::loncoursedata::CL_START()];
475: my $id =
476: $classlist->{$student}->[&Apache::loncoursedata::CL_ID()];
477: my $section =
478: $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
479: my $fullname =
480: $classlist->{$student}->[&Apache::loncoursedata::CL_FULLNAME()];
481: my $status =
482: $classlist->{$student}->[&Apache::loncoursedata::CL_STATUS()];
1.449 banghart 483: my $group =
484: $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1.76 ng 485: # filter students according to status selected
1.442 banghart 486: if ($filterlist && (!($stu_status =~ /Any/))) {
487: if (!($stu_status =~ $status)) {
1.450 banghart 488: delete($classlist->{$student});
1.76 ng 489: next;
490: }
491: }
1.450 banghart 492: # filter students according to groups selected
1.453 banghart 493: my @stu_groups = split(/,/,$group);
1.450 banghart 494: if (@getgroup) {
495: my $exclude = 1;
1.454 banghart 496: foreach my $grp (@getgroup) {
497: foreach my $stu_group (@stu_groups) {
1.453 banghart 498: if ($stu_group eq $grp) {
499: $exclude = 0;
500: }
1.450 banghart 501: }
1.453 banghart 502: if (($grp eq 'none') && !$group) {
503: $exclude = 0;
504: }
1.450 banghart 505: }
506: if ($exclude) {
507: delete($classlist->{$student});
508: }
509: }
1.205 matthew 510: $section = ($section ne '' ? $section : 'none');
1.106 albertel 511: if (&canview($section)) {
1.291 albertel 512: if (!@getsec || grep(/^\Q$section\E$/,@getsec)) {
1.103 albertel 513: $sections{$section}++;
1.450 banghart 514: if ($classlist->{$student}) {
515: $fullnames{$student}=$fullname;
516: }
1.103 albertel 517: } else {
1.205 matthew 518: delete($classlist->{$student});
1.103 albertel 519: }
520: } else {
1.205 matthew 521: delete($classlist->{$student});
1.103 albertel 522: }
1.44 ng 523: }
524: my %seen = ();
1.56 matthew 525: my @sections = sort(keys(%sections));
526: return ($classlist,\@sections,\%fullnames);
1.44 ng 527: }
528:
1.103 albertel 529: sub canmodify {
530: my ($sec)=@_;
531: if ($perm{'mgr'}) {
532: if (!defined($perm{'mgr_section'})) {
533: # can modify whole class
534: return 1;
535: } else {
536: if ($sec eq $perm{'mgr_section'}) {
537: #can modify the requested section
538: return 1;
539: } else {
540: # can't modify the request section
541: return 0;
542: }
543: }
544: }
545: #can't modify
546: return 0;
547: }
548:
549: sub canview {
550: my ($sec)=@_;
551: if ($perm{'vgr'}) {
552: if (!defined($perm{'vgr_section'})) {
553: # can modify whole class
554: return 1;
555: } else {
556: if ($sec eq $perm{'vgr_section'}) {
557: #can modify the requested section
558: return 1;
559: } else {
560: # can't modify the request section
561: return 0;
562: }
563: }
564: }
565: #can't modify
566: return 0;
567: }
568:
1.44 ng 569: #--- Retrieve the grade status of a student for all the parts
570: sub student_gradeStatus {
1.324 albertel 571: my ($symb,$udom,$uname,$partlist) = @_;
1.257 albertel 572: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.44 ng 573: my %partstatus = ();
574: foreach (@$partlist) {
1.128 ng 575: my ($status,undef) = split(/_/,$record{"resource.$_.solved"},2);
1.44 ng 576: $status = 'nothing' if ($status eq '');
577: $partstatus{$_} = $status;
578: my $subkey = "resource.$_.submitted_by";
579: $partstatus{$subkey} = $record{$subkey} if ($record{$subkey} ne '');
580: }
581: return %partstatus;
582: }
583:
1.45 ng 584: # hidden form and javascript that calls the form
585: # Use by verifyscript and viewgrades
586: # Shows a student's view of problem and submission
587: sub jscriptNform {
1.324 albertel 588: my ($symb) = @_;
1.442 banghart 589: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.45 ng 590: my $jscript='<script type="text/javascript" language="javascript">'."\n".
591: ' function viewOneStudent(user,domain) {'."\n".
592: ' document.onestudent.student.value = user;'."\n".
593: ' document.onestudent.userdom.value = domain;'."\n".
594: ' document.onestudent.submit();'."\n".
595: ' }'."\n".
596: '</script>'."\n";
597: $jscript.= '<form action="/adm/grades" method="post" name="onestudent">'."\n".
1.418 albertel 598: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 599: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
600: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.442 banghart 601: '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.45 ng 602: '<input type="hidden" name="command" value="submission" />'."\n".
603: '<input type="hidden" name="student" value="" />'."\n".
604: '<input type="hidden" name="userdom" value="" />'."\n".
605: '</form>'."\n";
606: return $jscript;
607: }
1.39 ng 608:
1.447 foxr 609:
610:
1.315 bowersj2 611: # Given the score (as a number [0-1] and the weight) what is the final
612: # point value? This function will round to the nearest tenth, third,
613: # or quarter if one of those is within the tolerance of .00001.
1.316 albertel 614: sub compute_points {
1.315 bowersj2 615: my ($score, $weight) = @_;
616:
617: my $tolerance = .00001;
618: my $points = $score * $weight;
619:
620: # Check for nearness to 1/x.
621: my $check_for_nearness = sub {
622: my ($factor) = @_;
623: my $num = ($points * $factor) + $tolerance;
624: my $floored_num = floor($num);
1.316 albertel 625: if ($num - $floored_num < 2 * $tolerance * $factor) {
1.315 bowersj2 626: return $floored_num / $factor;
627: }
628: return $points;
629: };
630:
631: $points = $check_for_nearness->(10);
632: $points = $check_for_nearness->(3);
633: $points = $check_for_nearness->(4);
634:
635: return $points;
636: }
637:
1.44 ng 638: #------------------ End of general use routines --------------------
1.87 www 639:
640: #
641: # Find most similar essay
642: #
643:
644: sub most_similar {
1.426 albertel 645: my ($uname,$udom,$uessay,$old_essays)=@_;
1.87 www 646:
647: # ignore spaces and punctuation
648:
649: $uessay=~s/\W+/ /gs;
650:
1.282 www 651: # ignore empty submissions (occuring when only files are sent)
652:
653: unless ($uessay=~/\w+/) { return ''; }
654:
1.87 www 655: # these will be returned. Do not care if not at least 50 percent similar
1.88 www 656: my $limit=0.6;
1.87 www 657: my $sname='';
658: my $sdom='';
659: my $scrsid='';
660: my $sessay='';
661: # go through all essays ...
1.426 albertel 662: foreach my $tkey (keys(%$old_essays)) {
663: my ($tname,$tdom,$tcrsid)=map {&unescape($_)} (split(/\./,$tkey));
1.87 www 664: # ... except the same student
1.426 albertel 665: next if (($tname eq $uname) && ($tdom eq $udom));
666: my $tessay=$old_essays->{$tkey};
667: $tessay=~s/\W+/ /gs;
1.87 www 668: # String similarity gives up if not even limit
1.426 albertel 669: my $tsimilar=&String::Similarity::similarity($uessay,$tessay,$limit);
1.87 www 670: # Found one
1.426 albertel 671: if ($tsimilar>$limit) {
672: $limit=$tsimilar;
673: $sname=$tname;
674: $sdom=$tdom;
675: $scrsid=$tcrsid;
676: $sessay=$old_essays->{$tkey};
677: }
1.87 www 678: }
1.88 www 679: if ($limit>0.6) {
1.87 www 680: return ($sname,$sdom,$scrsid,$sessay,$limit);
681: } else {
682: return ('','','','',0);
683: }
684: }
685:
1.44 ng 686: #-------------------------------------------------------------------
687:
688: #------------------------------------ Receipt Verification Routines
1.45 ng 689: #
1.44 ng 690: #--- Check whether a receipt number is valid.---
691: sub verifyreceipt {
692: my $request = shift;
693:
1.257 albertel 694: my $courseid = $env{'request.course.id'};
1.184 www 695: my $receipt = &Apache::lonnet::recprefix($courseid).'-'.
1.257 albertel 696: $env{'form.receipt'};
1.44 ng 697: $receipt =~ s/[^\-\d]//g;
1.378 albertel 698: my ($symb) = &get_symb($request);
1.44 ng 699:
1.487 albertel 700: my $title.=
701: '<h3><span class="LC_info">'.
702: &mt('Verifying Submission Receipt [_1]',$receipt).
703: '</span></h3>'."\n".
704: '<h4>'.&mt('<b>Resource: </b>[_1]',$env{'form.probTitle'}).
705: '</h4>'."\n";
1.44 ng 706:
707: my ($string,$contents,$matches) = ('','',0);
1.56 matthew 708: my (undef,undef,$fullname) = &getclasslist('all','0');
1.177 albertel 709:
710: my $receiptparts=0;
1.390 albertel 711: if ($env{"course.$courseid.receiptalg"} eq 'receipt2' ||
712: $env{"course.$courseid.receiptalg"} eq 'receipt3') { $receiptparts=1; }
1.177 albertel 713: my $parts=['0'];
1.324 albertel 714: if ($receiptparts) { ($parts)=&response_type($symb); }
1.486 albertel 715:
716: my $header =
717: &Apache::loncommon::start_data_table().
718: &Apache::loncommon::start_data_table_header_row().
1.487 albertel 719: '<th> '.&mt('Fullname').' </th>'."\n".
720: '<th> '.&mt('Username').' </th>'."\n".
721: '<th> '.&mt('Domain').' </th>';
1.486 albertel 722: if ($receiptparts) {
1.487 albertel 723: $header.='<th> '.&mt('Problem Part').' </th>';
1.486 albertel 724: }
725: $header.=
726: &Apache::loncommon::end_data_table_header_row();
727:
1.294 albertel 728: foreach (sort
729: {
730: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
731: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
732: }
733: return $a cmp $b;
734: } (keys(%$fullname))) {
1.44 ng 735: my ($uname,$udom)=split(/\:/);
1.177 albertel 736: foreach my $part (@$parts) {
737: if ($receipt eq &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb,$part)) {
1.486 albertel 738: $contents.=
739: &Apache::loncommon::start_data_table_row().
740: '<td> '."\n".
1.177 albertel 741: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 742: '\');" target="_self">'.$$fullname{$_}.'</a> </td>'."\n".
1.177 albertel 743: '<td> '.$uname.' </td>'.
744: '<td> '.$udom.' </td>';
745: if ($receiptparts) {
746: $contents.='<td> '.$part.' </td>';
747: }
1.486 albertel 748: $contents.=
749: &Apache::loncommon::end_data_table_row()."\n";
1.177 albertel 750:
751: $matches++;
752: }
1.44 ng 753: }
754: }
755: if ($matches == 0) {
1.487 albertel 756: $string = $title.&mt('No match found for the above receipt.');
1.44 ng 757: } else {
1.324 albertel 758: $string = &jscriptNform($symb).$title.
1.487 albertel 759: '<p>'.
760: &mt('The above receipt matches the following [numerate,_1,student].',$matches).
761: '</p>'.
1.486 albertel 762: $header.
763: $contents.
764: &Apache::loncommon::end_data_table()."\n";
1.44 ng 765: }
1.324 albertel 766: return $string.&show_grading_menu_form($symb);
1.44 ng 767: }
768:
769: #--- This is called by a number of programs.
770: #--- Called from the Grading Menu - View/Grade an individual student
771: #--- Also called directly when one clicks on the subm button
772: # on the problem page.
1.30 ng 773: sub listStudents {
1.41 ng 774: my ($request) = shift;
1.49 albertel 775:
1.324 albertel 776: my ($symb) = &get_symb($request);
1.257 albertel 777: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
778: my $cnum = $env{"course.$env{'request.course.id'}.num"};
779: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.449 banghart 780: my $getgroup = $env{'form.group'} eq '' ? 'all' : $env{'form.group'};
1.257 albertel 781: my $submitonly= $env{'form.submitonly'} eq '' ? 'all' : $env{'form.submitonly'};
1.539 ! riegler 782: my $viewgrade = $env{'form.showgrading'} eq 'yes' ? &mt('View/Grade/Regrade') : &mt('View');
1.257 albertel 783: $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
784: &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
1.49 albertel 785:
1.539 ! riegler 786: my $result='<h3><span class="LC_info"> '.$viewgrade.
! 787: &mt(' Submissions for a Student or a Group of Students')
1.485 albertel 788: .'</span></h3>';
1.118 ng 789:
1.324 albertel 790: my ($table,undef,$hdgrade,$partlist,$handgrade) = &showResourceInfo($symb,$env{'form.probTitle'},($env{'form.showgrading'} eq 'yes'));
1.49 albertel 791:
1.485 albertel 792: my %lt = ( 'multiple' =>
1.539 ! riegler 793: &mt("Please select a student or group of students before clicking on the Next button."),
1.485 albertel 794: 'single' =>
1.539 ! riegler 795: &mt("Please select the student before clicking on the Next button."),
1.485 albertel 796: );
797: %lt = &Apache::lonlocal::texthash(%lt);
1.45 ng 798: $request->print(<<LISTJAVASCRIPT);
799: <script type="text/javascript" language="javascript">
1.110 ng 800: function checkSelect(checkBox) {
801: var ctr=0;
802: var sense="";
803: if (checkBox.length > 1) {
804: for (var i=0; i<checkBox.length; i++) {
805: if (checkBox[i].checked) {
806: ctr++;
807: }
808: }
1.485 albertel 809: sense = '$lt{'multiple'}';
1.110 ng 810: } else {
811: if (checkBox.checked) {
812: ctr = 1;
813: }
1.485 albertel 814: sense = '$lt{'single'}';
1.110 ng 815: }
816: if (ctr == 0) {
1.485 albertel 817: alert(sense);
1.110 ng 818: return false;
819: }
820: document.gradesub.submit();
821: }
822:
823: function reLoadList(formname) {
1.112 ng 824: if (formname.saveStatusOld.value == pullDownSelection(formname.Status)) {return;}
1.110 ng 825: formname.command.value = 'submission';
826: formname.submit();
827: }
1.45 ng 828: </script>
829: LISTJAVASCRIPT
830:
1.118 ng 831: &commonJSfunctions($request);
1.41 ng 832: $request->print($result);
1.39 ng 833:
1.401 albertel 834: my $checkhdgrade = ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1 ) ? 'checked="checked"' : '';
835: my $checklastsub = $checkhdgrade eq '' ? 'checked="checked"' : '';
1.154 albertel 836: my $gradeTable='<form action="/adm/grades" method="post" name="gradesub">'.
1.485 albertel 837: "\n".$table;
838:
839: $gradeTable .=
1.539 ! riegler 840: ' <b>'.&mt('View Problem Text').': </b>'.
1.485 albertel 841: '<label><input type="radio" name="vProb" value="no" checked="checked" /> '.&mt('no').' </label>'."\n".
842: '<label><input type="radio" name="vProb" value="yes" /> '.&mt('one student').' </label>'."\n".
1.539 ! riegler 843: '<label><input type="radio" name="vProb" value="all" /> '.&mt('all students').' </label><br />'."\n";
1.485 albertel 844: $gradeTable .=
1.539 ! riegler 845: ' <b>'.&mt('View Answer').': </b>'.
1.485 albertel 846: '<label><input type="radio" name="vAns" value="no" /> '.&mt('no').' </label>'."\n".
847: '<label><input type="radio" name="vAns" value="yes" /> '.&mt('one student').' </label>'."\n".
1.539 ! riegler 848: '<label><input type="radio" name="vAns" value="all" checked="checked" /> '.&mt('all students').' </label><br />'."\n";
1.485 albertel 849:
850: my $submission_options;
1.257 albertel 851: if ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1) {
1.485 albertel 852: $submission_options.=
853: '<label><input type="radio" name="lastSub" value="hdgrade" '.$checkhdgrade.' /> '.&mt('essay part only').' </label>'."\n";
1.49 albertel 854: }
1.442 banghart 855: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
856: my $saveStatus = $stu_status eq '' ? 'Active' : $stu_status;
1.257 albertel 857: $env{'form.Status'} = $saveStatus;
1.485 albertel 858: $submission_options.=
859: '<label><input type="radio" name="lastSub" value="lastonly" '.$checklastsub.' /> '.&mt('last submission only').' </label>'."\n".
860: '<label><input type="radio" name="lastSub" value="last" /> '.&mt('last submission & parts info').' </label>'."\n".
861: '<label><input type="radio" name="lastSub" value="datesub" /> '.&mt('by dates and submissions').' </label>'."\n".
862: '<label><input type="radio" name="lastSub" value="all" /> '.&mt('all details').'</label>';
863: $gradeTable .=
1.539 ! riegler 864: ' <b>'.&mt('Submissions').': </b>'.$submission_options.'<br />'."\n";
1.485 albertel 865:
866: $gradeTable .=
1.539 ! riegler 867: ' <b>'.&mt('Grading Increments').': </b>'.
1.485 albertel 868: '<select name="increment">'.
869: '<option value="1">'.&mt('Whole Points').'</option>'.
870: '<option value=".5">'.&mt('Half Points').'</option>'.
871: '<option value=".25">'.&mt('Quarter Points').'</option>'.
872: '<option value=".1">'.&mt('Tenths of a Point').'</option>'.
1.539 ! riegler 873: '</select>';
1.485 albertel 874:
875: $gradeTable .=
1.432 banghart 876: &build_section_inputs().
1.45 ng 877: '<input type="hidden" name="submitonly" value="'.$submitonly.'" />'."\n".
1.257 albertel 878: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" /><br />'."\n".
879: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" /><br />'."\n".
880: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
881: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.418 albertel 882: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.110 ng 883: '<input type="hidden" name="saveStatusOld" value="'.$saveStatus.'" />'."\n";
884:
1.257 albertel 885: if (exists($env{'form.gradingMenu'}) && exists($env{'form.Status'})) {
1.442 banghart 886: $gradeTable.='<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n";
1.124 ng 887: } else {
1.485 albertel 888: $gradeTable.=&mt('<b>Student Status:</b> [_1]',
889: &Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,1,'javascript:reLoadList(this.form);')).'<br />';
1.124 ng 890: }
1.112 ng 891:
1.539 ! riegler 892: $gradeTable.=&mt('To [_1] 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.',lc($viewgrade)).'<br />'."\n".
1.110 ng 893: '<input type="hidden" name="command" value="processGroup" />'."\n";
1.249 albertel 894:
895: # checkall buttons
896: $gradeTable.=&check_script('gradesub', 'stuinfo');
1.110 ng 897: $gradeTable.='<input type="button" '."\n".
1.45 ng 898: 'onClick="javascript:checkSelect(this.form.stuinfo);" '."\n".
1.539 ! riegler 899: 'value="'.&mt('Next').' →" /> <br />'."\n";
1.249 albertel 900: $gradeTable.=&check_buttons();
1.485 albertel 901: $gradeTable.='<label><input type="checkbox" name="checkPlag" checked="checked" />'.&mt('Check For Plagiarism').'</label>';
1.450 banghart 902: my ($classlist, undef, $fullname) = &getclasslist($getsec,'1',$getgroup);
1.474 albertel 903: $gradeTable.= &Apache::loncommon::start_data_table().
904: &Apache::loncommon::start_data_table_header_row();
1.110 ng 905: my $loop = 0;
906: while ($loop < 2) {
1.485 albertel 907: $gradeTable.='<th>'.&mt('No.').'</th><th>'.&mt('Select').'</th>'.
908: '<th>'.&nameUserString('header').' '.&mt('Section/Group').'</th>';
1.301 albertel 909: if ($env{'form.showgrading'} eq 'yes'
910: && $submitonly ne 'queued'
911: && $submitonly ne 'all') {
1.485 albertel 912: foreach my $part (sort(@$partlist)) {
913: my $display_part=
914: &get_display_part((split(/_/,$part))[0],$symb);
915: $gradeTable.=
916: '<th>'.&mt('Part: [_1] Status',$display_part).'</th>';
1.110 ng 917: }
1.301 albertel 918: } elsif ($submitonly eq 'queued') {
1.474 albertel 919: $gradeTable.='<th>'.&mt('Queue Status').' </th>';
1.110 ng 920: }
921: $loop++;
1.126 ng 922: # $gradeTable.='<td></td>' if ($loop%2 ==1);
1.41 ng 923: }
1.474 albertel 924: $gradeTable.=&Apache::loncommon::end_data_table_header_row()."\n";
1.41 ng 925:
1.45 ng 926: my $ctr = 0;
1.294 albertel 927: foreach my $student (sort
928: {
929: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
930: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
931: }
932: return $a cmp $b;
933: }
934: (keys(%$fullname))) {
1.41 ng 935: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 936:
1.110 ng 937: my %status = ();
1.301 albertel 938:
939: if ($submitonly eq 'queued') {
940: my %queue_status =
941: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
942: $udom,$uname);
943: next if (!defined($queue_status{'gradingqueue'}));
944: $status{'gradingqueue'} = $queue_status{'gradingqueue'};
945: }
946:
947: if ($env{'form.showgrading'} eq 'yes'
948: && $submitonly ne 'queued'
949: && $submitonly ne 'all') {
1.324 albertel 950: (%status) =&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 951: my $submitted = 0;
1.164 albertel 952: my $graded = 0;
1.248 albertel 953: my $incorrect = 0;
1.110 ng 954: foreach (keys(%status)) {
1.145 albertel 955: $submitted = 1 if ($status{$_} ne 'nothing');
1.248 albertel 956: $graded = 1 if ($status{$_} =~ /^ungraded/);
957: $incorrect = 1 if ($status{$_} =~ /^incorrect/);
958:
1.110 ng 959: my ($foo,$partid,$foo1) = split(/\./,$_);
960: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
1.145 albertel 961: $submitted = 0;
1.150 albertel 962: my ($part)=split(/\./,$partid);
1.110 ng 963: $gradeTable.='<input type="hidden" name="'.
1.150 albertel 964: $student.':'.$part.':submitted_by" value="'.
1.110 ng 965: $status{'resource.'.$partid.'.submitted_by'}.'" />';
966: }
1.41 ng 967: }
1.248 albertel 968:
1.156 albertel 969: next if (!$submitted && ($submitonly eq 'yes' ||
970: $submitonly eq 'incorrect' ||
971: $submitonly eq 'graded'));
1.248 albertel 972: next if (!$graded && ($submitonly eq 'graded'));
973: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 974: }
1.34 ng 975:
1.45 ng 976: $ctr++;
1.249 albertel 977: my $section = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
1.452 banghart 978: my $group = $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
1.104 albertel 979: if ( $perm{'vgr'} eq 'F' ) {
1.474 albertel 980: if ($ctr%2 ==1) {
981: $gradeTable.= &Apache::loncommon::start_data_table_row();
982: }
1.126 ng 983: $gradeTable.='<td align="right">'.$ctr.' </td>'.
1.249 albertel 984: '<td align="center"><label><input type=checkbox name="stuinfo" value="'.
985: $student.':'.$$fullname{$student}.':::SECTION'.$section.
986: ') " /> </label></td>'."\n".'<td>'.
987: &nameUserString(undef,$$fullname{$student},$uname,$udom).
1.474 albertel 988: ' '.$section.($group ne '' ?'/'.$group:'').'</td>'."\n";
1.110 ng 989:
1.257 albertel 990: if ($env{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
1.524 raeburn 991: foreach (sort(keys(%status))) {
1.485 albertel 992: next if ($_ =~ /^resource.*?submitted_by$/);
993: $gradeTable.='<td align="center"> '.&mt($status{$_}).' </td>'."\n";
1.110 ng 994: }
1.41 ng 995: }
1.126 ng 996: # $gradeTable.='<td></td>' if ($ctr%2 ==1);
1.474 albertel 997: if ($ctr%2 ==0) {
998: $gradeTable.=&Apache::loncommon::end_data_table_row()."\n";
999: }
1.41 ng 1000: }
1001: }
1.110 ng 1002: if ($ctr%2 ==1) {
1.126 ng 1003: $gradeTable.='<td> </td><td> </td><td> </td>';
1.301 albertel 1004: if ($env{'form.showgrading'} eq 'yes'
1005: && $submitonly ne 'queued'
1006: && $submitonly ne 'all') {
1.110 ng 1007: foreach (@$partlist) {
1008: $gradeTable.='<td> </td>';
1009: }
1.301 albertel 1010: } elsif ($submitonly eq 'queued') {
1011: $gradeTable.='<td> </td>';
1.110 ng 1012: }
1.474 albertel 1013: $gradeTable.=&Apache::loncommon::end_data_table_row();
1.110 ng 1014: }
1015:
1.474 albertel 1016: $gradeTable.=&Apache::loncommon::end_data_table()."\n".
1.45 ng 1017: '<input type="button" '.
1018: 'onClick="javascript:checkSelect(this.form.stuinfo);" '.
1.539 ! riegler 1019: 'value="'.&mt('Next').' →" /></form>'."\n";
1.45 ng 1020: if ($ctr == 0) {
1.96 albertel 1021: my $num_students=(scalar(keys(%$fullname)));
1022: if ($num_students eq 0) {
1.485 albertel 1023: $gradeTable='<br /> <span class="LC_warning">'.&mt('There are no students currently enrolled.').'</span>';
1.96 albertel 1024: } else {
1.171 albertel 1025: my $submissions='submissions';
1026: if ($submitonly eq 'incorrect') { $submissions = 'incorrect submissions'; }
1027: if ($submitonly eq 'graded' ) { $submissions = 'ungraded submissions'; }
1.301 albertel 1028: if ($submitonly eq 'queued' ) { $submissions = 'queued submissions'; }
1.398 albertel 1029: $gradeTable='<br /> <span class="LC_warning">'.
1.485 albertel 1030: &mt('No '.$submissions.' found for this resource for any students. ([_1] students checked for '.$submissions.')',
1031: $num_students).
1032: '</span><br />';
1.96 albertel 1033: }
1.46 ng 1034: } elsif ($ctr == 1) {
1.474 albertel 1035: $gradeTable =~ s/type="checkbox"/type="checkbox" checked="checked"/;
1.45 ng 1036: }
1.324 albertel 1037: $gradeTable.=&show_grading_menu_form($symb);
1.45 ng 1038: $request->print($gradeTable);
1.44 ng 1039: return '';
1.10 ng 1040: }
1041:
1.44 ng 1042: #---- Called from the listStudents routine
1.249 albertel 1043:
1044: sub check_script {
1045: my ($form, $type)=@_;
1046: my $chkallscript='<script type="text/javascript">
1047: function checkall() {
1048: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1049: ele = document.forms.'.$form.'.elements[i];
1050: if (ele.name == "'.$type.'") {
1051: document.forms.'.$form.'.elements[i].checked=true;
1052: }
1053: }
1054: }
1055:
1056: function checksec() {
1057: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1058: ele = document.forms.'.$form.'.elements[i];
1059: string = document.forms.'.$form.'.chksec.value;
1060: if
1061: (ele.value.indexOf(":::SECTION"+string)>0) {
1062: document.forms.'.$form.'.elements[i].checked=true;
1063: }
1064: }
1065: }
1066:
1067:
1068: function uncheckall() {
1069: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
1070: ele = document.forms.'.$form.'.elements[i];
1071: if (ele.name == "'.$type.'") {
1072: document.forms.'.$form.'.elements[i].checked=false;
1073: }
1074: }
1075: }
1076:
1077: </script>'."\n";
1078: return $chkallscript;
1079: }
1080:
1081: sub check_buttons {
1.485 albertel 1082: my $buttons.='<input type="button" onclick="checkall()" value="'.&mt('Check All').'" />';
1083: $buttons.='<input type="button" onclick="uncheckall()" value="'.&mt('Uncheck All').'" /> ';
1084: $buttons.='<input type="button" onclick="checksec()" value="'.&mt('Check Section/Group').'" />';
1.249 albertel 1085: $buttons.='<input type="text" size="5" name="chksec" /> ';
1086: return $buttons;
1087: }
1088:
1.44 ng 1089: # Displays the submissions for one student or a group of students
1.34 ng 1090: sub processGroup {
1.41 ng 1091: my ($request) = shift;
1092: my $ctr = 0;
1.155 albertel 1093: my @stuchecked = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.41 ng 1094: my $total = scalar(@stuchecked)-1;
1.45 ng 1095:
1.396 banghart 1096: foreach my $student (@stuchecked) {
1097: my ($uname,$udom,$fullname) = split(/:/,$student);
1.257 albertel 1098: $env{'form.student'} = $uname;
1099: $env{'form.userdom'} = $udom;
1100: $env{'form.fullname'} = $fullname;
1.41 ng 1101: &submission($request,$ctr,$total);
1102: $ctr++;
1103: }
1104: return '';
1.35 ng 1105: }
1.34 ng 1106:
1.44 ng 1107: #------------------------------------------------------------------------------------
1108: #
1109: #-------------------------- Next few routines handles grading by student, essentially
1110: # handles essay response type problem/part
1111: #
1112: #--- Javascript to handle the submission page functionality ---
1113: sub sub_page_js {
1114: my $request = shift;
1.539 ! riegler 1115: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
1.44 ng 1116: $request->print(<<SUBJAVASCRIPT);
1117: <script type="text/javascript" language="javascript">
1.71 ng 1118: function updateRadio(formname,id,weight) {
1.125 ng 1119: var gradeBox = formname["GD_BOX"+id];
1120: var radioButton = formname["RADVAL"+id];
1121: var oldpts = formname["oldpts"+id].value;
1.72 ng 1122: var pts = checkSolved(formname,id) == 'update' ? gradeBox.value : oldpts;
1.71 ng 1123: gradeBox.value = pts;
1124: var resetbox = false;
1125: if (isNaN(pts) || pts < 0) {
1.539 ! riegler 1126: alert("$alertmsg"+pts);
1.71 ng 1127: for (var i=0; i<radioButton.length; i++) {
1128: if (radioButton[i].checked) {
1129: gradeBox.value = i;
1130: resetbox = true;
1131: }
1132: }
1133: if (!resetbox) {
1134: formtextbox.value = "";
1135: }
1136: return;
1.44 ng 1137: }
1.71 ng 1138:
1139: if (pts > weight) {
1140: var resp = confirm("You entered a value ("+pts+
1141: ") greater than the weight for the part. Accept?");
1142: if (resp == false) {
1.125 ng 1143: gradeBox.value = oldpts;
1.71 ng 1144: return;
1145: }
1.44 ng 1146: }
1.13 albertel 1147:
1.71 ng 1148: for (var i=0; i<radioButton.length; i++) {
1149: radioButton[i].checked=false;
1150: if (pts == i && pts != "") {
1151: radioButton[i].checked=true;
1152: }
1153: }
1154: updateSelect(formname,id);
1.125 ng 1155: formname["stores"+id].value = "0";
1.41 ng 1156: }
1.5 albertel 1157:
1.72 ng 1158: function writeBox(formname,id,pts) {
1.125 ng 1159: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1160: if (checkSolved(formname,id) == 'update') {
1161: gradeBox.value = pts;
1162: } else {
1.125 ng 1163: var oldpts = formname["oldpts"+id].value;
1.72 ng 1164: gradeBox.value = oldpts;
1.125 ng 1165: var radioButton = formname["RADVAL"+id];
1.71 ng 1166: for (var i=0; i<radioButton.length; i++) {
1167: radioButton[i].checked=false;
1.72 ng 1168: if (i == oldpts) {
1.71 ng 1169: radioButton[i].checked=true;
1170: }
1171: }
1.41 ng 1172: }
1.125 ng 1173: formname["stores"+id].value = "0";
1.71 ng 1174: updateSelect(formname,id);
1175: return;
1.41 ng 1176: }
1.44 ng 1177:
1.71 ng 1178: function clearRadBox(formname,id) {
1179: if (checkSolved(formname,id) == 'noupdate') {
1180: updateSelect(formname,id);
1181: return;
1182: }
1.125 ng 1183: gradeSelect = formname["GD_SEL"+id];
1.71 ng 1184: for (var i=0; i<gradeSelect.length; i++) {
1185: if (gradeSelect[i].selected) {
1186: var selectx=i;
1187: }
1188: }
1.125 ng 1189: var stores = formname["stores"+id];
1.71 ng 1190: if (selectx == stores.value) { return };
1.125 ng 1191: var gradeBox = formname["GD_BOX"+id];
1.71 ng 1192: gradeBox.value = "";
1.125 ng 1193: var radioButton = formname["RADVAL"+id];
1.71 ng 1194: for (var i=0; i<radioButton.length; i++) {
1195: radioButton[i].checked=false;
1196: }
1197: stores.value = selectx;
1198: }
1.5 albertel 1199:
1.71 ng 1200: function checkSolved(formname,id) {
1.125 ng 1201: if (formname["solved"+id].value == "correct_by_student" && formname.overRideScore.value == 'no') {
1.118 ng 1202: var reply = confirm("This problem has been graded correct by the computer. Do you want to change the score?");
1203: if (!reply) {return "noupdate";}
1.120 ng 1204: formname.overRideScore.value = 'yes';
1.41 ng 1205: }
1.71 ng 1206: return "update";
1.13 albertel 1207: }
1.71 ng 1208:
1209: function updateSelect(formname,id) {
1.125 ng 1210: formname["GD_SEL"+id][0].selected = true;
1.71 ng 1211: return;
1.41 ng 1212: }
1.33 ng 1213:
1.121 ng 1214: //=========== Check that a point is assigned for all the parts ============
1.71 ng 1215: function checksubmit(formname,val,total,parttot) {
1.121 ng 1216: formname.gradeOpt.value = val;
1.71 ng 1217: if (val == "Save & Next") {
1218: for (i=0;i<=total;i++) {
1219: for (j=0;j<parttot;j++) {
1.125 ng 1220: var partid = formname["partid"+i+"_"+j].value;
1.127 ng 1221: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1222: var points = formname["GD_BOX"+i+"_"+partid].value;
1.71 ng 1223: if (points == "") {
1.125 ng 1224: var name = formname["name"+i].value;
1.129 ng 1225: var studentID = (name != '' ? name : formname["unamedom"+i].value);
1226: var resp = confirm("You did not assign a score for "+studentID+
1227: ", part "+partid+". Continue?");
1.71 ng 1228: if (resp == false) {
1.125 ng 1229: formname["GD_BOX"+i+"_"+partid].focus();
1.71 ng 1230: return false;
1231: }
1232: }
1233: }
1234:
1235: }
1236: }
1237:
1238: }
1.121 ng 1239: if (val == "Grade Student") {
1240: formname.showgrading.value = "yes";
1241: if (formname.Status.value == "") {
1242: formname.Status.value = "Active";
1243: }
1244: formname.studentNo.value = total;
1245: }
1.120 ng 1246: formname.submit();
1247: }
1248:
1.71 ng 1249: //======= Check that a score is assigned for all the problems (page/sequence grading only) =========
1250: function checkSubmitPage(formname,total) {
1251: noscore = new Array(100);
1252: var ptr = 0;
1253: for (i=1;i<total;i++) {
1.125 ng 1254: var partid = formname["q_"+i].value;
1.127 ng 1255: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1256: var points = formname["GD_BOX"+i+"_"+partid].value;
1257: var status = formname["solved"+i+"_"+partid].value;
1.71 ng 1258: if (points == "" && status != "correct_by_student") {
1259: noscore[ptr] = i;
1260: ptr++;
1261: }
1262: }
1263: }
1264: if (ptr != 0) {
1265: var sense = ptr == 1 ? ": " : "s: ";
1266: var prolist = "";
1267: if (ptr == 1) {
1268: prolist = noscore[0];
1269: } else {
1270: var i = 0;
1271: while (i < ptr-1) {
1272: prolist += noscore[i]+", ";
1273: i++;
1274: }
1275: prolist += "and "+noscore[i];
1276: }
1277: var resp = confirm("You did not assign any score for the following problem"+sense+prolist+". Continue?");
1278: if (resp == false) {
1279: return false;
1280: }
1281: }
1.45 ng 1282:
1.71 ng 1283: formname.submit();
1284: }
1285: </script>
1286: SUBJAVASCRIPT
1287: }
1.45 ng 1288:
1.71 ng 1289: #--- javascript for essay type problem --
1290: sub sub_page_kw_js {
1291: my $request = shift;
1.80 ng 1292: my $iconpath = $request->dir_config('lonIconsURL');
1.118 ng 1293: &commonJSfunctions($request);
1.350 albertel 1294:
1.351 albertel 1295: my $inner_js_msg_central=<<INNERJS;
1.350 albertel 1296: <script text="text/javascript">
1297: function checkInput() {
1298: opener.document.SCORE.msgsub.value = opener.checkEntities(document.msgcenter.msgsub.value);
1299: var nmsg = opener.document.SCORE.savemsgN.value;
1300: var usrctr = document.msgcenter.usrctr.value;
1301: var newval = opener.document.SCORE["newmsg"+usrctr];
1302: newval.value = opener.checkEntities(document.msgcenter.newmsg.value);
1303:
1304: var msgchk = "";
1305: if (document.msgcenter.subchk.checked) {
1306: msgchk = "msgsub,";
1307: }
1308: var includemsg = 0;
1309: for (var i=1; i<=nmsg; i++) {
1310: var opnmsg = opener.document.SCORE["savemsg"+i];
1311: var frmmsg = document.msgcenter["msg"+i];
1312: opnmsg.value = opener.checkEntities(frmmsg.value);
1313: var showflg = opener.document.SCORE["shownOnce"+i];
1314: showflg.value = "1";
1315: var chkbox = document.msgcenter["msgn"+i];
1316: if (chkbox.checked) {
1317: msgchk += "savemsg"+i+",";
1318: includemsg = 1;
1319: }
1320: }
1321: if (document.msgcenter.newmsgchk.checked) {
1322: msgchk += "newmsg"+usrctr;
1323: includemsg = 1;
1324: }
1325: imgformname = opener.document.SCORE["mailicon"+usrctr];
1326: imgformname.src = "$iconpath/"+((includemsg) ? "mailto.gif" : "mailbkgrd.gif");
1327: var includemsg = opener.document.SCORE["includemsg"+usrctr];
1328: includemsg.value = msgchk;
1329:
1330: self.close()
1331:
1332: }
1333: </script>
1334: INNERJS
1335:
1.351 albertel 1336: my $inner_js_highlight_central=<<INNERJS;
1337: <script type="text/javascript">
1338: function updateChoice(flag) {
1339: opener.document.SCORE.kwclr.value = opener.radioSelection(document.hlCenter.kwdclr);
1340: opener.document.SCORE.kwsize.value = opener.radioSelection(document.hlCenter.kwdsize);
1341: opener.document.SCORE.kwstyle.value = opener.radioSelection(document.hlCenter.kwdstyle);
1342: opener.document.SCORE.refresh.value = "on";
1343: if (opener.document.SCORE.keywords.value!=""){
1344: opener.document.SCORE.submit();
1345: }
1346: self.close()
1347: }
1348: </script>
1349: INNERJS
1350:
1351: my $start_page_msg_central =
1352: &Apache::loncommon::start_page('Message Central',$inner_js_msg_central,
1353: {'js_ready' => 1,
1354: 'only_body' => 1,
1355: 'bgcolor' =>'#FFFFFF',});
1356: my $end_page_msg_central =
1357: &Apache::loncommon::end_page({'js_ready' => 1});
1358:
1359:
1360: my $start_page_highlight_central =
1361: &Apache::loncommon::start_page('Highlight Central',
1362: $inner_js_highlight_central,
1.350 albertel 1363: {'js_ready' => 1,
1364: 'only_body' => 1,
1365: 'bgcolor' =>'#FFFFFF',});
1.351 albertel 1366: my $end_page_highlight_central =
1.350 albertel 1367: &Apache::loncommon::end_page({'js_ready' => 1});
1368:
1.219 www 1369: my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
1.236 albertel 1370: $docopen=~s/^document\.//;
1.539 ! riegler 1371: my $alertmsg = &mt('Please select a word or group of words from document and then click this link.');
1.71 ng 1372: $request->print(<<SUBJAVASCRIPT);
1373: <script type="text/javascript" language="javascript">
1.45 ng 1374:
1.44 ng 1375: //===================== Show list of keywords ====================
1.122 ng 1376: function keywords(formname) {
1377: var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",formname.keywords.value);
1.44 ng 1378: if (nret==null) return;
1.122 ng 1379: formname.keywords.value = nret;
1.44 ng 1380:
1.122 ng 1381: if (formname.keywords.value != "") {
1.128 ng 1382: formname.refresh.value = "on";
1.122 ng 1383: formname.submit();
1.44 ng 1384: }
1385: return;
1386: }
1387:
1388: //===================== Script to view submitted by ==================
1389: function viewSubmitter(submitter) {
1390: document.SCORE.refresh.value = "on";
1391: document.SCORE.NCT.value = "1";
1392: document.SCORE.unamedom0.value = submitter;
1393: document.SCORE.submit();
1394: return;
1395: }
1396:
1397: //===================== Script to add keyword(s) ==================
1398: function getSel() {
1399: if (document.getSelection) txt = document.getSelection();
1400: else if (document.selection) txt = document.selection.createRange().text;
1401: else return;
1402: var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
1403: if (cleantxt=="") {
1.539 ! riegler 1404: alert("$alertmsg");
1.44 ng 1405: return;
1406: }
1407: var nret = prompt("Add selection to keyword list? Edit if desired.",cleantxt);
1408: if (nret==null) return;
1.127 ng 1409: document.SCORE.keywords.value = document.SCORE.keywords.value+" "+nret;
1.44 ng 1410: if (document.SCORE.keywords.value != "") {
1.127 ng 1411: document.SCORE.refresh.value = "on";
1.44 ng 1412: document.SCORE.submit();
1413: }
1414: return;
1415: }
1416:
1417: //====================== Script for composing message ==============
1.80 ng 1418: // preload images
1419: img1 = new Image();
1420: img1.src = "$iconpath/mailbkgrd.gif";
1421: img2 = new Image();
1422: img2.src = "$iconpath/mailto.gif";
1423:
1.44 ng 1424: function msgCenter(msgform,usrctr,fullname) {
1425: var Nmsg = msgform.savemsgN.value;
1426: savedMsgHeader(Nmsg,usrctr,fullname);
1427: var subject = msgform.msgsub.value;
1.127 ng 1428: var msgchk = document.SCORE["includemsg"+usrctr].value;
1.44 ng 1429: re = /msgsub/;
1430: var shwsel = "";
1431: if (re.test(msgchk)) { shwsel = "checked" }
1.123 ng 1432: subject = (document.SCORE.shownSub.value == 0 ? checkEntities(subject) : subject);
1433: displaySubject(checkEntities(subject),shwsel);
1.44 ng 1434: for (var i=1; i<=Nmsg; i++) {
1.123 ng 1435: var testmsg = "savemsg"+i+",";
1436: re = new RegExp(testmsg,"g");
1.44 ng 1437: shwsel = "";
1438: if (re.test(msgchk)) { shwsel = "checked" }
1.125 ng 1439: var message = document.SCORE["savemsg"+i].value;
1.126 ng 1440: message = (document.SCORE["shownOnce"+i].value == 0 ? checkEntities(message) : message);
1.123 ng 1441: displaySavedMsg(i,message,shwsel); //I do not get it. w/o checkEntities on saved messages,
1442: //any < is already converted to <, etc. However, only once!!
1.44 ng 1443: }
1.125 ng 1444: newmsg = document.SCORE["newmsg"+usrctr].value;
1.44 ng 1445: shwsel = "";
1446: re = /newmsg/;
1447: if (re.test(msgchk)) { shwsel = "checked" }
1448: newMsg(newmsg,shwsel);
1449: msgTail();
1450: return;
1451: }
1452:
1.123 ng 1453: function checkEntities(strx) {
1454: if (strx.length == 0) return strx;
1455: var orgStr = ["&", "<", ">", '"'];
1456: var newStr = ["&", "<", ">", """];
1457: var counter = 0;
1458: while (counter < 4) {
1459: strx = strReplace(strx,orgStr[counter],newStr[counter]);
1460: counter++;
1461: }
1462: return strx;
1463: }
1464:
1465: function strReplace(strx, orgStr, newStr) {
1466: return strx.split(orgStr).join(newStr);
1467: }
1468:
1.44 ng 1469: function savedMsgHeader(Nmsg,usrctr,fullname) {
1.76 ng 1470: var height = 70*Nmsg+250;
1.44 ng 1471: var scrollbar = "no";
1472: if (height > 600) {
1473: height = 600;
1474: scrollbar = "yes";
1475: }
1.118 ng 1476: var xpos = (screen.width-600)/2;
1477: xpos = (xpos < 0) ? '0' : xpos;
1478: var ypos = (screen.height-height)/2-30;
1479: ypos = (ypos < 0) ? '0' : ypos;
1480:
1.206 albertel 1481: pWin = window.open('', 'MessageCenter', 'resizable=yes,toolbar=no,location=no,scrollbars='+scrollbar+',screenx='+xpos+',screeny='+ypos+',width=600,height='+height);
1.76 ng 1482: pWin.focus();
1483: pDoc = pWin.document;
1.219 www 1484: pDoc.$docopen;
1.351 albertel 1485: pDoc.write('$start_page_msg_central');
1.76 ng 1486:
1487: pDoc.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
1488: pDoc.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
1.465 albertel 1489: pDoc.write("<h3><span class=\\"LC_info\\"> Compose Message for \"+fullname+\"<\\/span><\\/h3><br /><br />");
1.76 ng 1490:
1491: pDoc.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
1492: pDoc.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
1.465 albertel 1493: pDoc.write("<td><b>Type<\\/b><\\/td><td><b>Include<\\/b><\\/td><td><b>Message<\\/td><\\/tr>");
1.44 ng 1494: }
1495: function displaySubject(msg,shwsel) {
1.76 ng 1496: pDoc = pWin.document;
1497: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.465 albertel 1498: pDoc.write("<td>Subject<\\/td>");
1499: pDoc.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1500: pDoc.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+"\\"size=\\"60\\" maxlength=\\"80\\"><\\/td><\\/tr>");
1.44 ng 1501: }
1502:
1.72 ng 1503: function displaySavedMsg(ctr,msg,shwsel) {
1.76 ng 1504: pDoc = pWin.document;
1505: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.465 albertel 1506: pDoc.write("<td align=\\"center\\">"+ctr+"<\\/td>");
1507: pDoc.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1508: pDoc.write("<td><textarea name=\\"msg"+ctr+"\\" cols=\\"60\\" rows=\\"3\\">"+msg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 1509: }
1510:
1511: function newMsg(newmsg,shwsel) {
1.76 ng 1512: pDoc = pWin.document;
1513: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1.465 albertel 1514: pDoc.write("<td align=\\"center\\">New<\\/td>");
1515: pDoc.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"><\\/td>");
1516: pDoc.write("<td><textarea name=\\"newmsg\\" cols=\\"60\\" rows=\\"3\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" >"+newmsg+"<\\/textarea><\\/td><\\/tr>");
1.44 ng 1517: }
1518:
1519: function msgTail() {
1.76 ng 1520: pDoc = pWin.document;
1.465 albertel 1521: pDoc.write("<\\/table>");
1522: pDoc.write("<\\/td><\\/tr><\\/table> ");
1.76 ng 1523: pDoc.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:checkInput()\\"> ");
1.326 albertel 1524: pDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br /><br />");
1.465 albertel 1525: pDoc.write("<\\/form>");
1.351 albertel 1526: pDoc.write('$end_page_msg_central');
1.128 ng 1527: pDoc.close();
1.44 ng 1528: }
1529:
1530: //====================== Script for keyword highlight options ==============
1531: function kwhighlight() {
1532: var kwclr = document.SCORE.kwclr.value;
1533: var kwsize = document.SCORE.kwsize.value;
1534: var kwstyle = document.SCORE.kwstyle.value;
1535: var redsel = "";
1536: var grnsel = "";
1537: var blusel = "";
1538: if (kwclr=="red") {var redsel="checked"};
1539: if (kwclr=="green") {var grnsel="checked"};
1540: if (kwclr=="blue") {var blusel="checked"};
1541: var sznsel = "";
1542: var sz1sel = "";
1543: var sz2sel = "";
1544: if (kwsize=="0") {var sznsel="checked"};
1545: if (kwsize=="+1") {var sz1sel="checked"};
1546: if (kwsize=="+2") {var sz2sel="checked"};
1547: var synsel = "";
1548: var syisel = "";
1549: var sybsel = "";
1550: if (kwstyle=="") {var synsel="checked"};
1551: if (kwstyle=="<i>") {var syisel="checked"};
1552: if (kwstyle=="<b>") {var sybsel="checked"};
1553: highlightCentral();
1554: highlightbody('red','red',redsel,'0','normal',sznsel,'','normal',synsel);
1555: highlightbody('green','green',grnsel,'+1','+1',sz1sel,'<i>','italic',syisel);
1556: highlightbody('blue','blue',blusel,'+2','+2',sz2sel,'<b>','bold',sybsel);
1557: highlightend();
1558: return;
1559: }
1560:
1561: function highlightCentral() {
1.76 ng 1562: // if (window.hwdWin) window.hwdWin.close();
1.118 ng 1563: var xpos = (screen.width-400)/2;
1564: xpos = (xpos < 0) ? '0' : xpos;
1565: var ypos = (screen.height-330)/2-30;
1566: ypos = (ypos < 0) ? '0' : ypos;
1567:
1.206 albertel 1568: hwdWin = window.open('', 'KeywordHighlightCentral', 'resizeable=yes,toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx='+xpos+',screeny='+ypos);
1.76 ng 1569: hwdWin.focus();
1570: var hDoc = hwdWin.document;
1.219 www 1571: hDoc.$docopen;
1.351 albertel 1572: hDoc.write('$start_page_highlight_central');
1.76 ng 1573: hDoc.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
1.465 albertel 1574: hDoc.write("<h3><span class=\\"LC_info\\"> Keyword Highlight Options<\\/span><\\/h3><br /><br />");
1.76 ng 1575:
1576: hDoc.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
1577: hDoc.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
1.465 albertel 1578: hDoc.write("<td><b>Text Color<\\/b><\\/td><td><b>Font Size<\\/b><\\/td><td><b>Font Style<\\/td><\\/tr>");
1.44 ng 1579: }
1580:
1581: function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) {
1.76 ng 1582: var hDoc = hwdWin.document;
1583: hDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1584: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1585: hDoc.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+"> "+clrtxt+"<\\/td>");
1.76 ng 1586: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1587: hDoc.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+"> "+sztxt+"<\\/td>");
1.76 ng 1588: hDoc.write("<td align=\\"left\\">");
1.465 albertel 1589: hDoc.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+"> "+sytxt+"<\\/td>");
1590: hDoc.write("<\\/tr>");
1.44 ng 1591: }
1592:
1593: function highlightend() {
1.76 ng 1594: var hDoc = hwdWin.document;
1.465 albertel 1595: hDoc.write("<\\/table>");
1596: hDoc.write("<\\/td><\\/tr><\\/table> ");
1.76 ng 1597: hDoc.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:updateChoice(1)\\"> ");
1.326 albertel 1598: hDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br /><br />");
1.465 albertel 1599: hDoc.write("<\\/form>");
1.351 albertel 1600: hDoc.write('$end_page_highlight_central');
1.128 ng 1601: hDoc.close();
1.44 ng 1602: }
1603:
1604: </script>
1605: SUBJAVASCRIPT
1606: }
1607:
1.349 albertel 1608: sub get_increment {
1.348 bowersj2 1609: my $increment = $env{'form.increment'};
1610: if ($increment != 1 && $increment != .5 && $increment != .25 &&
1611: $increment != .1) {
1612: $increment = 1;
1613: }
1614: return $increment;
1615: }
1616:
1.71 ng 1617: #--- displays the grading box, used in essay type problem and grading by page/sequence
1618: sub gradeBox {
1.322 albertel 1619: my ($request,$symb,$uname,$udom,$counter,$partid,$record) = @_;
1.381 albertel 1620: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 1621: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 1622: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
1.466 albertel 1623: my $wgtmsg = ($wgt > 0) ? &mt('(problem weight)')
1624: : '<span class="LC_info">'.&mt('problem weight assigned by computer').'</span>';
1.71 ng 1625: $wgt = ($wgt > 0 ? $wgt : '1');
1626: my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
1.320 albertel 1627: '' : &compute_points($$record{'resource.'.$partid.'.awarded'},$wgt));
1.71 ng 1628: my $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />'."\n";
1.466 albertel 1629: my $display_part= &get_display_part($partid,$symb);
1.270 albertel 1630: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
1631: [$partid]);
1632: my $aggtries = $$record{'resource.'.$partid.'.tries'};
1.269 raeburn 1633: if ($last_resets{$partid}) {
1634: $aggtries = &get_num_tries($record,$last_resets{$partid},$partid);
1635: }
1.485 albertel 1636: $result.='<table border="0"><tr>';
1.71 ng 1637: my $ctr = 0;
1.348 bowersj2 1638: my $thisweight = 0;
1.349 albertel 1639: my $increment = &get_increment();
1.485 albertel 1640:
1641: my $radio.='<table border="0"><tr>'."\n"; # display radio buttons in a nice table 10 across
1.348 bowersj2 1642: while ($thisweight<=$wgt) {
1.532 bisitz 1643: $radio.= '<td><span class="LC_nobreak"><label><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
1.71 ng 1644: 'onclick="javascript:writeBox(this.form,\''.$counter.'_'.$partid.'\','.
1.348 bowersj2 1645: $thisweight.')" value="'.$thisweight.'" '.
1.401 albertel 1646: ($score eq $thisweight ? 'checked="checked"':'').' /> '.$thisweight."</label></span></td>\n";
1.485 albertel 1647: $radio.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1.348 bowersj2 1648: $thisweight += $increment;
1.71 ng 1649: $ctr++;
1650: }
1.485 albertel 1651: $radio.='</tr></table>';
1652:
1653: my $line.='<input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
1.71 ng 1654: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
1655: 'onChange="javascript:updateRadio(this.form,\''.$counter.'_'.$partid.'\','.
1656: $wgt.')" /></td>'."\n";
1.485 albertel 1657: $line.='<td>/'.$wgt.' '.$wgtmsg.
1.71 ng 1658: ($$record{'resource.'.$partid.'.solved'} eq 'correct_by_student' ? ' '.$checkIcon : '').
1659: ' </td><td>'."\n";
1.485 albertel 1660: $line.='<select name="GD_SEL'.$counter.'_'.$partid.'" '.
1.71 ng 1661: 'onChange="javascript:clearRadBox(this.form,\''.$counter.'_'.$partid.'\')" >'."\n";
1662: if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
1.485 albertel 1663: $line.='<option></option>'.
1664: '<option value="excused" selected="selected">'.&mt('excused').'</option>';
1.71 ng 1665: } else {
1.485 albertel 1666: $line.='<option selected="selected"></option>'.
1667: '<option value="excused" >'.&mt('excused').'</option>';
1.71 ng 1668: }
1.485 albertel 1669: $line.='<option value="reset status">'.&mt('reset status').'</option></select>'."\n";
1670:
1671:
1672: $result .=
1673: &mt('<td><b>Part:</b></td><td>[_1]</td><td><b>Points:</b></td><td>[_2]</td><td>or</td><td>[_3]</td>',$display_part,$radio,$line);
1674:
1675:
1676: $result.='</tr></table>'."\n";
1.71 ng 1677: $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="" />'."\n".
1678: '<input type="hidden" name="oldpts'.$counter.'_'.$partid.'" value="'.$score.'" />'."\n".
1679: '<input type="hidden" name="solved'.$counter.'_'.$partid.'" value="'.
1.269 raeburn 1680: $$record{'resource.'.$partid.'.solved'}.'" />'."\n".
1681: '<input type="hidden" name="totaltries'.$counter.'_'.$partid.'" value="'.
1682: $$record{'resource.'.$partid.'.tries'}.'" />'."\n".
1683: '<input type="hidden" name="aggtries'.$counter.'_'.$partid.'" value="'.
1684: $aggtries.'" />'."\n";
1.323 banghart 1685: $result.=&handback_box($symb,$uname,$udom,$counter,$partid,$record);
1.318 banghart 1686: return $result;
1687: }
1.322 albertel 1688:
1689: sub handback_box {
1.323 banghart 1690: my ($symb,$uname,$udom,$counter,$partid,$record) = @_;
1.324 albertel 1691: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.323 banghart 1692: my (@respids);
1.375 albertel 1693: my @part_response_id = &flatten_responseType($responseType);
1694: foreach my $part_response_id (@part_response_id) {
1695: my ($part,$resp) = @{ $part_response_id };
1.323 banghart 1696: if ($part eq $partid) {
1.375 albertel 1697: push(@respids,$resp);
1.323 banghart 1698: }
1699: }
1.318 banghart 1700: my $result;
1.323 banghart 1701: foreach my $respid (@respids) {
1.322 albertel 1702: my $prefix = $counter.'_'.$partid.'_'.$respid.'_';
1703: my $files=&get_submitted_files($udom,$uname,$partid,$respid,$record);
1704: next if (!@$files);
1705: my $file_counter = 1;
1.313 banghart 1706: foreach my $file (@$files) {
1.368 banghart 1707: if ($file =~ /\/portfolio\//) {
1708: my ($file_path, $file_disp) = ($file =~ m|(.+/)(.+)$|);
1709: my ($name,$version,$ext) = &file_name_version_ext($file_disp);
1710: $file_disp = "$name.$ext";
1711: $file = $file_path.$file_disp;
1712: $result.=&mt('Return commented version of [_1] to student.',
1713: '<span class="LC_filename">'.$file_disp.'</span>');
1714: $result.='<input type="file" name="'.$prefix.'returndoc'.$file_counter.'" />'."\n";
1715: $result.='<input type="hidden" name="'.$prefix.'origdoc'.$file_counter.'" value="'.$file.'" /><br />';
1.485 albertel 1716: $result.='('.&mt('File will be uploaded when you click on Save & Next below.').')<br />';
1.368 banghart 1717: $file_counter++;
1718: }
1.322 albertel 1719: }
1.313 banghart 1720: }
1.318 banghart 1721: return $result;
1.71 ng 1722: }
1.44 ng 1723:
1.58 albertel 1724: sub show_problem {
1.382 albertel 1725: my ($request,$symb,$uname,$udom,$removeform,$viewon,$mode,$form) = @_;
1.144 albertel 1726: my $rendered;
1.382 albertel 1727: my %form = ((ref($form) eq 'HASH')? %{$form} : ());
1.329 albertel 1728: &Apache::lonxml::remember_problem_counter();
1.144 albertel 1729: if ($mode eq 'both' or $mode eq 'text') {
1730: $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
1.382 albertel 1731: $env{'request.course.id'},
1732: undef,\%form);
1.144 albertel 1733: }
1.58 albertel 1734: if ($removeform) {
1735: $rendered=~s|<form(.*?)>||g;
1736: $rendered=~s|</form>||g;
1.374 albertel 1737: $rendered=~s|(<input[^>]*name\s*=\s*"?)(\w+)("?)|$1would_have_been_$2$3|g;
1.58 albertel 1738: }
1.144 albertel 1739: my $companswer;
1740: if ($mode eq 'both' or $mode eq 'answer') {
1.329 albertel 1741: &Apache::lonxml::restore_problem_counter();
1.382 albertel 1742: $companswer=
1743: &Apache::loncommon::get_student_answers($symb,$uname,$udom,
1744: $env{'request.course.id'},
1745: %form);
1.144 albertel 1746: }
1.58 albertel 1747: if ($removeform) {
1748: $companswer=~s|<form(.*?)>||g;
1749: $companswer=~s|</form>||g;
1.144 albertel 1750: $companswer=~s|name="submit"|name="would_have_been_submit"|g;
1.58 albertel 1751: }
1.468 albertel 1752: $rendered=
1753: '<div class="LC_grade_show_problem_header">'.
1754: &mt('View of the problem').
1755: '</div><div class="LC_grade_show_problem_problem">'.
1756: $rendered.
1757: '</div>';
1758: $companswer=
1759: '<div class="LC_grade_show_problem_header">'.
1760: &mt('Correct answer').
1761: '</div><div class="LC_grade_show_problem_problem">'.
1762: $companswer.
1763: '</div>';
1764: my $result;
1.144 albertel 1765: if ($mode eq 'both') {
1.468 albertel 1766: $result=$rendered.$companswer;
1.144 albertel 1767: } elsif ($mode eq 'text') {
1.468 albertel 1768: $result=$rendered;
1.144 albertel 1769: } elsif ($mode eq 'answer') {
1.468 albertel 1770: $result=$companswer;
1.144 albertel 1771: }
1.468 albertel 1772: $result='<div class="LC_grade_show_problem">'.$result.'</div>';
1.71 ng 1773: return $result;
1.58 albertel 1774: }
1.397 albertel 1775:
1.396 banghart 1776: sub files_exist {
1777: my ($r, $symb) = @_;
1778: my @students = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.397 albertel 1779:
1.396 banghart 1780: foreach my $student (@students) {
1781: my ($uname,$udom,$fullname) = split(/:/,$student);
1.397 albertel 1782: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
1783: $udom,$uname);
1.396 banghart 1784: my ($string,$timestamp)= &get_last_submission(\%record);
1.397 albertel 1785: foreach my $submission (@$string) {
1786: my ($partid,$respid) =
1787: ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
1788: my $files=&get_submitted_files($udom,$uname,$partid,$respid,
1789: \%record);
1790: return 1 if (@$files);
1.396 banghart 1791: }
1792: }
1.397 albertel 1793: return 0;
1.396 banghart 1794: }
1.397 albertel 1795:
1.394 banghart 1796: sub download_all_link {
1797: my ($r,$symb) = @_;
1.395 albertel 1798: my $all_students =
1799: join("\n", &Apache::loncommon::get_env_multiple('form.stuinfo'));
1800:
1801: my $parts =
1802: join("\n",&Apache::loncommon::get_env_multiple('form.vPart'));
1803:
1.394 banghart 1804: my $identifier = &Apache::loncommon::get_cgi_id();
1.514 raeburn 1805: &Apache::lonnet::appenv({'cgi.'.$identifier.'.students' => $all_students,
1806: 'cgi.'.$identifier.'.symb' => $symb,
1807: 'cgi.'.$identifier.'.parts' => $parts,});
1.395 albertel 1808: $r->print('<a href="/cgi-bin/multidownload.pl?'.$identifier.'">'.
1809: &mt('Download All Submitted Documents').'</a>');
1.394 banghart 1810: return
1811: }
1.395 albertel 1812:
1.432 banghart 1813: sub build_section_inputs {
1814: my $section_inputs;
1815: if ($env{'form.section'} eq '') {
1816: $section_inputs .= '<input type="hidden" name="section" value="all" />'."\n";
1817: } else {
1818: my @sections = &Apache::loncommon::get_env_multiple('form.section');
1.434 albertel 1819: foreach my $section (@sections) {
1.432 banghart 1820: $section_inputs .= '<input type="hidden" name="section" value="'.$section.'" />'."\n";
1821: }
1822: }
1823: return $section_inputs;
1824: }
1825:
1.44 ng 1826: # --------------------------- show submissions of a student, option to grade
1827: sub submission {
1828: my ($request,$counter,$total) = @_;
1.257 albertel 1829: my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
1830: $udom = ($udom eq '' ? $env{'user.domain'} : $udom); #has form.userdom changed for a student?
1831: my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
1832: $env{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $env{'form.fullname'} eq '';
1.324 albertel 1833: my $symb = &get_symb($request);
1834: if ($symb eq '') { $request->print("Unable to handle ambiguous references:."); return ''; }
1.104 albertel 1835:
1836: if (!&canview($usec)) {
1.398 albertel 1837: $request->print('<span class="LC_warning">Unable to view requested student.('.
1838: $uname.':'.$udom.' in section '.$usec.' in course id '.
1839: $env{'request.course.id'}.')</span>');
1.324 albertel 1840: $request->print(&show_grading_menu_form($symb));
1.104 albertel 1841: return;
1842: }
1843:
1.257 albertel 1844: if (!$env{'form.lastSub'}) { $env{'form.lastSub'} = 'datesub'; }
1845: if (!$env{'form.vProb'}) { $env{'form.vProb'} = 'yes'; }
1846: if (!$env{'form.vAns'}) { $env{'form.vAns'} = 'yes'; }
1847: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.381 albertel 1848: my $checkIcon = '<img alt="'.&mt('Check Mark').
1849: '" src="'.$request->dir_config('lonIconsURL').
1.122 ng 1850: '/check.gif" height="16" border="0" />';
1.41 ng 1851:
1.426 albertel 1852: my %old_essays;
1.41 ng 1853: # header info
1854: if ($counter == 0) {
1855: &sub_page_js($request);
1.257 albertel 1856: &sub_page_kw_js($request) if ($env{'form.handgrade'} eq 'yes');
1857: $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
1858: &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
1.397 albertel 1859: if ($env{'form.handgrade'} eq 'yes' && &files_exist($request, $symb)) {
1.396 banghart 1860: &download_all_link($request, $symb);
1861: }
1.485 albertel 1862: $request->print('<h3> <span class="LC_info">'.&mt('Submission Record').'</span></h3>'."\n".
1863: '<h4> '.&mt('<b>Resource: </b> [_1]',$env{'form.probTitle'}).'</h4>'."\n");
1.118 ng 1864:
1.44 ng 1865: # option to display problem, only once else it cause problems
1866: # with the form later since the problem has a form.
1.257 albertel 1867: if ($env{'form.vProb'} eq 'yes' or $env{'form.vAns'} eq 'yes') {
1.144 albertel 1868: my $mode;
1.257 albertel 1869: if ($env{'form.vProb'} eq 'yes' && $env{'form.vAns'} eq 'yes') {
1.144 albertel 1870: $mode='both';
1.257 albertel 1871: } elsif ($env{'form.vProb'} eq 'yes') {
1.144 albertel 1872: $mode='text';
1.257 albertel 1873: } elsif ($env{'form.vAns'} eq 'yes') {
1.144 albertel 1874: $mode='answer';
1875: }
1.329 albertel 1876: &Apache::lonxml::clear_problem_counter();
1.144 albertel 1877: $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
1.41 ng 1878: }
1.441 www 1879:
1.44 ng 1880: # kwclr is the only variable that is guaranteed to be non blank
1881: # if this subroutine has been called once.
1.41 ng 1882: my %keyhash = ();
1.257 albertel 1883: if ($env{'form.kwclr'} eq '' && $env{'form.handgrade'} eq 'yes') {
1.41 ng 1884: %keyhash = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 1885: $env{'course.'.$env{'request.course.id'}.'.domain'},
1886: $env{'course.'.$env{'request.course.id'}.'.num'});
1.41 ng 1887:
1.257 albertel 1888: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1889: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
1890: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
1891: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
1892: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
1893: $env{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
1894: $keyhash{$symb.'_subject'} : $env{'form.probTitle'};
1895: $env{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1.41 ng 1896: }
1.257 albertel 1897: my $overRideScore = $env{'form.overRideScore'} eq '' ? 'no' : $env{'form.overRideScore'};
1.442 banghart 1898: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.303 banghart 1899: $request->print('<form action="/adm/grades" method="post" name="SCORE" enctype="multipart/form-data">'."\n".
1.41 ng 1900: '<input type="hidden" name="command" value="handgrade" />'."\n".
1.257 albertel 1901: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.442 banghart 1902: '<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.120 ng 1903: '<input type="hidden" name="overRideScore" value="'.$overRideScore.'" />'."\n".
1.257 albertel 1904: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.41 ng 1905: '<input type="hidden" name="refresh" value="off" />'."\n".
1.120 ng 1906: '<input type="hidden" name="studentNo" value="" />'."\n".
1907: '<input type="hidden" name="gradeOpt" value="" />'."\n".
1.418 albertel 1908: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 1909: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" />'."\n".
1910: '<input type="hidden" name="vProb" value="'.$env{'form.vProb'}.'" />'."\n".
1911: '<input type="hidden" name="vAns" value="'.$env{'form.vAns'}.'" />'."\n".
1912: '<input type="hidden" name="lastSub" value="'.$env{'form.lastSub'}.'" />'."\n".
1.432 banghart 1913: &build_section_inputs().
1.326 albertel 1914: '<input type="hidden" name="submitonly" value="'.$env{'form.submitonly'}.'" />'."\n".
1915: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" />'."\n".
1.41 ng 1916: '<input type="hidden" name="NCT"'.
1.257 albertel 1917: ' value="'.($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : $total+1).'" />'."\n");
1918: if ($env{'form.handgrade'} eq 'yes') {
1919: $request->print('<input type="hidden" name="keywords" value="'.$env{'form.keywords'}.'" />'."\n".
1920: '<input type="hidden" name="kwclr" value="'.$env{'form.kwclr'}.'" />'."\n".
1921: '<input type="hidden" name="kwsize" value="'.$env{'form.kwsize'}.'" />'."\n".
1922: '<input type="hidden" name="kwstyle" value="'.$env{'form.kwstyle'}.'" />'."\n".
1923: '<input type="hidden" name="msgsub" value="'.$env{'form.msgsub'}.'" />'."\n".
1.123 ng 1924: '<input type="hidden" name="shownSub" value="0" />'."\n".
1.257 albertel 1925: '<input type="hidden" name="savemsgN" value="'.$env{'form.savemsgN'}.'" />'."\n");
1.154 albertel 1926: foreach my $partid (&Apache::loncommon::get_env_multiple('form.vPart')) {
1927: $request->print('<input type="hidden" name="vPart" value="'.$partid.'" />'."\n");
1928: }
1.123 ng 1929: }
1.41 ng 1930:
1931: my ($cts,$prnmsg) = (1,'');
1.257 albertel 1932: while ($cts <= $env{'form.savemsgN'}) {
1.41 ng 1933: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
1.123 ng 1934: (!exists($keyhash{$symb.'_savemsg'.$cts}) ?
1.257 albertel 1935: &Apache::lonfeedback::clear_out_html($env{'form.savemsg'.$cts}) :
1.80 ng 1936: &Apache::lonfeedback::clear_out_html($keyhash{$symb.'_savemsg'.$cts})).
1.123 ng 1937: '" />'."\n".
1938: '<input type="hidden" name="shownOnce'.$cts.'" value="0" />'."\n";
1.41 ng 1939: $cts++;
1940: }
1941: $request->print($prnmsg);
1.32 ng 1942:
1.257 albertel 1943: if ($env{'form.handgrade'} eq 'yes' && $env{'form.showgrading'} eq 'yes') {
1.88 www 1944: #
1945: # Print out the keyword options line
1946: #
1.41 ng 1947: $request->print(<<KEYWORDS);
1.38 ng 1948: <b>Keyword Options:</b>
1.417 albertel 1949: <a href="javascript:keywords(document.SCORE);" target="_self">List</a>
1.38 ng 1950: <a href="#" onMouseDown="javascript:getSel(); return false"
1951: CLASS="page">Paste Selection to List</a>
1.417 albertel 1952: <a href="javascript:kwhighlight();" target="_self">Highlight Attribute</a><br /><br />
1.38 ng 1953: KEYWORDS
1.88 www 1954: #
1955: # Load the other essays for similarity check
1956: #
1.324 albertel 1957: my (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb);
1.384 albertel 1958: my ($adom,$aname,$apath)=($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
1.359 www 1959: $apath=&escape($apath);
1.88 www 1960: $apath=~s/\W/\_/gs;
1.426 albertel 1961: %old_essays=&Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
1.41 ng 1962: }
1963: }
1.44 ng 1964:
1.441 www 1965: # This is where output for one specific student would start
1.468 albertel 1966: my $add_class = ($counter%2) ? 'LC_grade_show_user_odd_row' : '';
1.441 www 1967: $request->print("\n\n".
1.468 albertel 1968: '<div class="LC_grade_show_user '.$add_class.'">'.
1969: '<div class="LC_grade_user_name">'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).'</div>'.
1970: '<div class="LC_grade_show_user_body">'."\n");
1.441 www 1971:
1.257 albertel 1972: if ($env{'form.vProb'} eq 'all' or $env{'form.vAns'} eq 'all') {
1.144 albertel 1973: my $mode;
1.257 albertel 1974: if ($env{'form.vProb'} eq 'all' && $env{'form.vAns'} eq 'all') {
1.144 albertel 1975: $mode='both';
1.257 albertel 1976: } elsif ($env{'form.vProb'} eq 'all' ) {
1.144 albertel 1977: $mode='text';
1.257 albertel 1978: } elsif ($env{'form.vAns'} eq 'all') {
1.144 albertel 1979: $mode='answer';
1980: }
1.329 albertel 1981: &Apache::lonxml::clear_problem_counter();
1.475 albertel 1982: $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode,{'request.prefix' => 'ctr'.$counter}));
1.58 albertel 1983: }
1.144 albertel 1984:
1.257 albertel 1985: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 1986: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.41 ng 1987:
1.44 ng 1988: # Display student info
1.41 ng 1989: $request->print(($counter == 0 ? '' : '<br />'));
1.468 albertel 1990: my $result='<div class="LC_grade_submissions">';
1991:
1992: $result.='<div class="LC_grade_submissions_header">';
1993: $result.= &mt('Submissions');
1.45 ng 1994: $result.='<input type="hidden" name="name'.$counter.
1.257 albertel 1995: '" value="'.$env{'form.fullname'}.'" />'."\n";
1.469 albertel 1996: if ($env{'form.handgrade'} eq 'no') {
1997: $result.='<span class="LC_grade_check_note">'.
1998: &mt('Part(s) graded correct by the computer is marked with a [_1] symbol.',$checkIcon)."</span>\n";
1999:
2000: }
2001:
2002:
1.41 ng 2003:
1.118 ng 2004: # If any part of the problem is an essay-response (handgraded), then check for collaborators
1.464 albertel 2005: my $fullname;
2006: my $col_fullnames = [];
1.257 albertel 2007: if ($env{'form.handgrade'} eq 'yes') {
1.464 albertel 2008: (my $sub_result,$fullname,$col_fullnames)=
2009: &check_collaborators($symb,$uname,$udom,\%record,$handgrade,
2010: $counter);
2011: $result.=$sub_result;
1.41 ng 2012: }
1.44 ng 2013: $request->print($result."\n");
1.468 albertel 2014: $request->print('</div>'."\n");
1.44 ng 2015: # print student answer/submission
2016: # Options are (1) Handgaded submission only
2017: # (2) Last submission, includes submission that is not handgraded
2018: # (for multi-response type part)
2019: # (3) Last submission plus the parts info
2020: # (4) The whole record for this student
1.257 albertel 2021: if ($env{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
1.151 albertel 2022: my ($string,$timestamp)= &get_last_submission(\%record);
1.468 albertel 2023:
2024: my $lastsubonly;
2025:
1.151 albertel 2026: if ($$timestamp eq '') {
1.468 albertel 2027: $lastsubonly.='<div class="LC_grade_submissions_body">'.$$string[0].'</div>';
1.151 albertel 2028: } else {
1.468 albertel 2029: $lastsubonly = '<div class="LC_grade_submissions_body"> <b>Date Submitted:</b> '.$$timestamp."\n";
2030:
1.151 albertel 2031: my %seenparts;
1.375 albertel 2032: my @part_response_id = &flatten_responseType($responseType);
2033: foreach my $part (@part_response_id) {
1.393 albertel 2034: next if ($env{'form.lastSub'} eq 'hdgrade'
2035: && $$handgrade{$$part[0].'_'.$$part[1]} ne 'yes');
2036:
1.375 albertel 2037: my ($partid,$respid) = @{ $part };
1.324 albertel 2038: my $display_part=&get_display_part($partid,$symb);
1.257 albertel 2039: if ($env{"form.$uname:$udom:$partid:submitted_by"}) {
1.151 albertel 2040: if (exists($seenparts{$partid})) { next; }
2041: $seenparts{$partid}=1;
1.207 albertel 2042: my $submitby='<b>Part:</b> '.$display_part.
2043: ' <b>Collaborative submission by:</b> '.
1.151 albertel 2044: '<a href="javascript:viewSubmitter(\''.
1.257 albertel 2045: $env{"form.$uname:$udom:$partid:submitted_by"}.
1.417 albertel 2046: '\');" target="_self">'.
1.257 albertel 2047: $$fullname{$env{"form.$uname:$udom:$partid:submitted_by"}}.'</a><br />';
1.151 albertel 2048: $request->print($submitby);
2049: next;
2050: }
2051: my $responsetype = $responseType->{$partid}->{$respid};
2052: if (!exists($record{"resource.$partid.$respid.submission"})) {
1.468 albertel 2053: $lastsubonly.="\n".'<div class="LC_grade_submission_part"><b>Part:</b> '.
1.398 albertel 2054: $display_part.' <span class="LC_internal_info">( ID '.$respid.
2055: ' )</span> '.
1.539 ! riegler 2056: '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br /><br /></div>';
1.151 albertel 2057: next;
2058: }
1.468 albertel 2059: foreach my $submission (@$string) {
2060: my ($partid,$respid) = ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
1.375 albertel 2061: if (join('_',@{$part}) ne ($partid.'_'.$respid)) { next; }
1.468 albertel 2062: my ($ressub,$subval) = split(/:/,$submission,2);
1.151 albertel 2063: # Similarity check
2064: my $similar='';
1.257 albertel 2065: if($env{'form.checkPlag'}){
1.151 albertel 2066: my ($oname,$odom,$ocrsid,$oessay,$osim)=
1.426 albertel 2067: &most_similar($uname,$udom,$subval,\%old_essays);
1.151 albertel 2068: if ($osim) {
2069: $osim=int($osim*100.0);
1.426 albertel 2070: my %old_course_desc =
2071: &Apache::lonnet::coursedescription($ocrsid,
2072: {'one_time' => 1});
2073:
2074: $similar="<hr /><h3><span class=\"LC_warning\">".
1.427 albertel 2075: &mt('Essay is [_1]% similar to an essay by [_2] ([_3]:[_4]) in course [_5] (course id [_6]:[_7])',
1.426 albertel 2076: $osim,
2077: &Apache::loncommon::plainname($oname,$odom),
1.427 albertel 2078: $oname,$odom,
1.426 albertel 2079: $old_course_desc{'description'},
1.427 albertel 2080: $old_course_desc{'num'},
1.426 albertel 2081: $old_course_desc{'domain'}).
1.398 albertel 2082: '</span></h3><blockquote><i>'.
1.151 albertel 2083: &keywords_highlight($oessay).
2084: '</i></blockquote><hr />';
2085: }
1.150 albertel 2086: }
1.151 albertel 2087: my $order=&get_order($partid,$respid,$symb,$uname,$udom);
1.257 albertel 2088: if ($env{'form.lastSub'} eq 'lastonly' ||
2089: ($env{'form.lastSub'} eq 'hdgrade' &&
1.377 albertel 2090: $$handgrade{$$part[0].'_'.$$part[1]} eq 'yes')) {
1.324 albertel 2091: my $display_part=&get_display_part($partid,$symb);
1.468 albertel 2092: $lastsubonly.='<div class="LC_grade_submission_part"><b>Part:</b> '.
1.403 albertel 2093: $display_part.' <span class="LC_internal_info">( ID '.$respid.
1.398 albertel 2094: ' )</span> ';
1.313 banghart 2095: my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record);
2096: if (@$files) {
1.468 albertel 2097: $lastsubonly.='<br /><span class="LC_warning">'.&mt('Like all files provided by users, this file may contain virusses').'</span><br />';
1.303 banghart 2098: my $file_counter = 0;
1.313 banghart 2099: foreach my $file (@$files) {
1.468 albertel 2100: $file_counter++;
1.232 albertel 2101: &Apache::lonnet::allowuploaded('/adm/grades',$file);
1.335 albertel 2102: $lastsubonly.='<br /><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.&Apache::loncommon::icon($file).'" border=0"> '.$file.'</a>';
1.232 albertel 2103: }
1.236 albertel 2104: $lastsubonly.='<br />';
1.41 ng 2105: }
1.468 albertel 2106: $lastsubonly.='<b>'.&mt('Submitted Answer:').' </b>'.
1.151 albertel 2107: &cleanRecord($subval,$responsetype,$symb,$partid,
2108: $respid,\%record,$order);
2109: if ($similar) {$lastsubonly.="<br /><br />$similar\n";}
1.468 albertel 2110: $lastsubonly.='</div>';
1.41 ng 2111: }
2112: }
2113: }
1.468 albertel 2114: $lastsubonly.='</div>'."\n";
1.151 albertel 2115: }
2116: $request->print($lastsubonly);
1.468 albertel 2117: } elsif ($env{'form.lastSub'} eq 'datesub') {
1.324 albertel 2118: my (undef,$responseType,undef,$parts) = &showResourceInfo($symb);
1.148 albertel 2119: $request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
1.257 albertel 2120: } elsif ($env{'form.lastSub'} =~ /^(last|all)$/) {
1.41 ng 2121: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
1.257 albertel 2122: $env{'request.course.id'},
1.44 ng 2123: $last,'.submission',
2124: 'Apache::grades::keywords_highlight'));
1.41 ng 2125: }
1.120 ng 2126:
1.121 ng 2127: $request->print('<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
2128: .$udom.'" />'."\n");
1.44 ng 2129: # return if view submission with no grading option
1.257 albertel 2130: if ($env{'form.showgrading'} eq '' || (!&canmodify($usec))) {
1.120 ng 2131: my $toGrade.='<input type="button" value="Grade Student" '.
1.121 ng 2132: 'onClick="javascript:checksubmit(this.form,\'Grade Student\',\''
1.417 albertel 2133: .$counter.'\');" target="_self" /> '."\n" if (&canmodify($usec));
1.468 albertel 2134: $toGrade.='</div>'."\n";
1.257 albertel 2135: if (($env{'form.command'} eq 'submission') ||
2136: ($env{'form.command'} eq 'processGroup' && $counter == $total)) {
1.324 albertel 2137: $toGrade.='</form>'.&show_grading_menu_form($symb);
1.169 albertel 2138: }
1.180 albertel 2139: $request->print($toGrade);
1.41 ng 2140: return;
1.180 albertel 2141: } else {
1.468 albertel 2142: $request->print('</div>'."\n");
1.41 ng 2143: }
1.33 ng 2144:
1.121 ng 2145: # essay grading message center
1.257 albertel 2146: if ($env{'form.handgrade'} eq 'yes') {
1.468 albertel 2147: my $result='<div class="LC_grade_message_center">';
2148:
2149: $result.='<div class="LC_grade_message_center_header">'.
2150: &mt('Send Message').'</div><div class="LC_grade_message_center_body">';
1.257 albertel 2151: my ($lastname,$givenn) = split(/,/,$env{'form.fullname'});
1.118 ng 2152: my $msgfor = $givenn.' '.$lastname;
1.464 albertel 2153: if (scalar(@$col_fullnames) > 0) {
2154: my $lastone = pop(@$col_fullnames);
2155: $msgfor .= ', '.(join ', ',@$col_fullnames).' and '.$lastone.'.';
1.118 ng 2156: }
2157: $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
1.468 albertel 2158: $result.='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
1.121 ng 2159: '<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n";
2160: $result.=' <a href="javascript:msgCenter(document.SCORE,'.$counter.
1.417 albertel 2161: ',\''.$msgfor.'\');" target="_self">'.
1.464 albertel 2162: &mt('Compose message to student').(scalar(@$col_fullnames) >= 1 ? 's' : '').'</a><label> ('.
1.350 albertel 2163: &mt('incl. grades').' <input type="checkbox" name="withgrades'.$counter.'" /></label>)'.
1.118 ng 2164: '<img src="'.$request->dir_config('lonIconsURL').
2165: '/mailbkgrd.gif" width="14" height="10" name="mailicon'.$counter.'" />'."\n".
1.298 www 2166: '<br /> ('.
1.468 albertel 2167: &mt('Message will be sent when you click on Save & Next below.').")\n";
2168: $result.='</div></div>';
1.121 ng 2169: $request->print($result);
1.118 ng 2170: }
1.41 ng 2171:
2172: my %seen = ();
2173: my @partlist;
1.129 ng 2174: my @gradePartRespid;
1.375 albertel 2175: my @part_response_id = &flatten_responseType($responseType);
1.468 albertel 2176: $request->print('<div class="LC_grade_assign">'.
2177:
2178: '<div class="LC_grade_assign_header">'.
2179: &mt('Assign Grades').'</div>'.
2180: '<div class="LC_grade_assign_body">');
1.375 albertel 2181: foreach my $part_response_id (@part_response_id) {
2182: my ($partid,$respid) = @{ $part_response_id };
2183: my $part_resp = join('_',@{ $part_response_id });
1.322 albertel 2184: next if ($seen{$partid} > 0);
1.41 ng 2185: $seen{$partid}++;
1.393 albertel 2186: next if ($$handgrade{$part_resp} ne 'yes'
2187: && $env{'form.lastSub'} eq 'hdgrade');
1.524 raeburn 2188: push(@partlist,$partid);
2189: push(@gradePartRespid,$partid.'.'.$respid);
1.322 albertel 2190: $request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
1.41 ng 2191: }
1.468 albertel 2192: $request->print('</div></div>');
2193:
2194: $request->print('<div class="LC_grade_info_links">');
2195: if ($perm{'vgr'}) {
2196: $request->print(
2197: &Apache::loncommon::track_student_link(&mt('View recent activity'),
2198: $uname,$udom,'check'));
2199: }
2200: if ($perm{'opa'}) {
2201: $request->print(
2202: &Apache::loncommon::pprmlink(&mt('Set/Change parameters'),
2203: $uname,$udom,$symb,'check'));
2204: }
2205: $request->print('</div>');
2206:
1.45 ng 2207: $result='<input type="hidden" name="partlist'.$counter.
2208: '" value="'.(join ":",@partlist).'" />'."\n";
1.129 ng 2209: $result.='<input type="hidden" name="gradePartRespid'.
2210: '" value="'.(join ":",@gradePartRespid).'" />'."\n" if ($counter == 0);
1.45 ng 2211: my $ctr = 0;
2212: while ($ctr < scalar(@partlist)) {
2213: $result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
2214: $partlist[$ctr].'" />'."\n";
2215: $ctr++;
2216: }
1.468 albertel 2217: $request->print($result.''."\n");
1.41 ng 2218:
1.441 www 2219: # Done with printing info for one student
2220:
1.468 albertel 2221: $request->print('</div>');#LC_grade_show_user_body
2222: $request->print('</div>');#LC_grade_show_user
1.441 www 2223:
2224:
1.41 ng 2225: # print end of form
2226: if ($counter == $total) {
1.297 www 2227: my $endform='<table border="0"><tr><td>'."\n";
1.485 albertel 2228: $endform.='<input type="button" value="'.&mt('Save & Next').'" '.
1.119 ng 2229: 'onClick="javascript:checksubmit(this.form,\'Save & Next\','.
1.417 albertel 2230: $total.','.scalar(@partlist).');" target="_self" /> '."\n";
1.119 ng 2231: my $ntstu ='<select name="NTSTU">'.
2232: '<option>1</option><option>2</option>'.
2233: '<option>3</option><option>5</option>'.
2234: '<option>7</option><option>10</option></select>'."\n";
1.257 albertel 2235: my $nsel = ($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : '1');
1.401 albertel 2236: $ntstu =~ s/<option>$nsel</<option selected="selected">$nsel</;
1.485 albertel 2237: $endform.=&mt('[_1]student(s)',$ntstu);
2238: $endform.=' <input type="button" value="'.&mt('Previous').'" '.
1.417 albertel 2239: 'onClick="javascript:checksubmit(this.form,\'Previous\');" target="_self" /> '."\n".
1.485 albertel 2240: '<input type="button" value="'.&mt('Next').'" '.
1.417 albertel 2241: 'onClick="javascript:checksubmit(this.form,\'Next\');" target="_self" /> ';
1.485 albertel 2242: $endform.=&mt('(Next and Previous (student) do not save the scores.)')."\n" ;
1.349 albertel 2243: $endform.="<input type='hidden' value='".&get_increment().
1.348 bowersj2 2244: "' name='increment' />";
1.485 albertel 2245: $endform.='</td></tr></table></form>';
1.324 albertel 2246: $endform.=&show_grading_menu_form($symb);
1.41 ng 2247: $request->print($endform);
2248: }
2249: return '';
1.38 ng 2250: }
2251:
1.464 albertel 2252: sub check_collaborators {
2253: my ($symb,$uname,$udom,$record,$handgrade,$counter) = @_;
2254: my ($result,@col_fullnames);
2255: my ($classlist,undef,$fullname) = &getclasslist('all','0');
2256: foreach my $part (keys(%$handgrade)) {
2257: my $ncol = &Apache::lonnet::EXT('resource.'.$part.
2258: '.maxcollaborators',
2259: $symb,$udom,$uname);
2260: next if ($ncol <= 0);
2261: $part =~ s/\_/\./g;
2262: next if ($record->{'resource.'.$part.'.collaborators'} eq '');
2263: my (@good_collaborators, @bad_collaborators);
2264: foreach my $possible_collaborator
2265: (split(/,?\s+/,$record->{'resource.'.$part.'.collaborators'})) {
2266: $possible_collaborator =~ s/[\$\^\(\)]//g;
2267: next if ($possible_collaborator eq '');
2268: my ($co_name,$co_dom) = split(/\@|:/,$possible_collaborator);
2269: $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
2270: next if ($co_name eq $uname && $co_dom eq $udom);
2271: # Doing this grep allows 'fuzzy' specification
2272: my @matches = grep(/^\Q$co_name\E:\Q$co_dom\E$/i,
2273: keys(%$classlist));
2274: if (! scalar(@matches)) {
2275: push(@bad_collaborators, $possible_collaborator);
2276: } else {
2277: push(@good_collaborators, @matches);
2278: }
2279: }
2280: if (scalar(@good_collaborators) != 0) {
1.466 albertel 2281: $result.='<br />'.&mt('Collaborators: ');
1.464 albertel 2282: foreach my $name (@good_collaborators) {
2283: my ($lastname,$givenn) = split(/,/,$$fullname{$name});
2284: push(@col_fullnames, $givenn.' '.$lastname);
2285: $result.=$fullname->{$name}.' ';
2286: }
2287: $result.='<br />'."\n";
1.466 albertel 2288: my ($part)=split(/\./,$part);
1.464 albertel 2289: $result.='<input type="hidden" name="collaborator'.$counter.
2290: '" value="'.$part.':'.(join ':',@good_collaborators).'" />'.
2291: "\n";
2292: }
2293: if (scalar(@bad_collaborators) > 0) {
1.466 albertel 2294: $result.='<div class="LC_warning">';
1.464 albertel 2295: $result.=&mt('This student has submitted [quant,_1,invalid collaborator]: [_2]',scalar(@bad_collaborators),join(', ',@bad_collaborators));
2296: $result .= '</div>';
2297: }
2298: if (scalar(@bad_collaborators > $ncol)) {
1.466 albertel 2299: $result .= '<div class="LC_warning">';
1.464 albertel 2300: $result .= &mt('This student has submitted too many '.
2301: 'collaborators. Maximum is [_1].',$ncol);
2302: $result .= '</div>';
2303: }
2304: }
2305: return ($result,$fullname,\@col_fullnames);
2306: }
2307:
1.44 ng 2308: #--- Retrieve the last submission for all the parts
1.38 ng 2309: sub get_last_submission {
1.119 ng 2310: my ($returnhash)=@_;
1.46 ng 2311: my (@string,$timestamp);
1.119 ng 2312: if ($$returnhash{'version'}) {
1.46 ng 2313: my %lasthash=();
2314: my ($version);
1.119 ng 2315: for ($version=1;$version<=$$returnhash{'version'};$version++) {
1.397 albertel 2316: foreach my $key (sort(split(/\:/,
2317: $$returnhash{$version.':keys'}))) {
2318: $lasthash{$key}=$$returnhash{$version.':'.$key};
2319: $timestamp =
2320: scalar(localtime($$returnhash{$version.':timestamp'}));
1.46 ng 2321: }
2322: }
1.397 albertel 2323: foreach my $key (keys(%lasthash)) {
2324: next if ($key !~ /\.submission$/);
2325:
2326: my ($partid,$foo) = split(/submission$/,$key);
2327: my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
1.398 albertel 2328: '<span class="LC_warning">Draft Copy</span> ' : '';
1.397 albertel 2329: push(@string, join(':', $key, $draft.$lasthash{$key}));
1.41 ng 2330: }
2331: }
1.397 albertel 2332: if (!@string) {
2333: $string[0] =
1.539 ! riegler 2334: '<span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span>';
1.397 albertel 2335: }
2336: return (\@string,\$timestamp);
1.38 ng 2337: }
1.35 ng 2338:
1.44 ng 2339: #--- High light keywords, with style choosen by user.
1.38 ng 2340: sub keywords_highlight {
1.44 ng 2341: my $string = shift;
1.257 albertel 2342: my $size = $env{'form.kwsize'} eq '0' ? '' : 'size='.$env{'form.kwsize'};
2343: my $styleon = $env{'form.kwstyle'} eq '' ? '' : $env{'form.kwstyle'};
1.41 ng 2344: (my $styleoff = $styleon) =~ s/\</\<\//;
1.257 albertel 2345: my @keylist = split(/[,\s+]/,$env{'form.keywords'});
1.398 albertel 2346: foreach my $keyword (@keylist) {
2347: $string =~ s/\b\Q$keyword\E(\b|\.)/<font color\=$env{'form.kwclr'} $size\>$styleon$keyword$styleoff<\/font>/gi;
1.41 ng 2348: }
2349: return $string;
1.38 ng 2350: }
1.36 ng 2351:
1.44 ng 2352: #--- Called from submission routine
1.38 ng 2353: sub processHandGrade {
1.41 ng 2354: my ($request) = shift;
1.324 albertel 2355: my $symb = &get_symb($request);
2356: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.257 albertel 2357: my $button = $env{'form.gradeOpt'};
2358: my $ngrade = $env{'form.NCT'};
2359: my $ntstu = $env{'form.NTSTU'};
1.301 albertel 2360: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2361: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2362:
1.44 ng 2363: if ($button eq 'Save & Next') {
2364: my $ctr = 0;
2365: while ($ctr < $ngrade) {
1.257 albertel 2366: my ($uname,$udom) = split(/:/,$env{'form.unamedom'.$ctr});
1.324 albertel 2367: my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$symb,$uname,$udom,$ctr);
1.71 ng 2368: if ($errorflag eq 'no_score') {
2369: $ctr++;
2370: next;
2371: }
1.104 albertel 2372: if ($errorflag eq 'not_allowed') {
1.398 albertel 2373: $request->print("<span class=\"LC_warning\">Not allowed to modify grades for $uname:$udom</span>");
1.104 albertel 2374: $ctr++;
2375: next;
2376: }
1.257 albertel 2377: my $includemsg = $env{'form.includemsg'.$ctr};
1.44 ng 2378: my ($subject,$message,$msgstatus) = ('','','');
1.418 albertel 2379: my $restitle = &Apache::lonnet::gettitle($symb);
2380: my ($feedurl,$showsymb) =
2381: &get_feedurl_and_symb($symb,$uname,$udom);
2382: my $messagetail;
1.62 albertel 2383: if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.298 www 2384: $subject = $env{'form.msgsub'} if ($includemsg =~ /msgsub/);
1.295 www 2385: unless ($subject=~/\w/) { $subject=&mt('Grading Feedback'); }
1.386 raeburn 2386: $subject.=' ['.$restitle.']';
1.44 ng 2387: my (@msgnum) = split(/,/,$includemsg);
2388: foreach (@msgnum) {
1.257 albertel 2389: $message.=$env{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
1.44 ng 2390: }
1.80 ng 2391: $message =&Apache::lonfeedback::clear_out_html($message);
1.298 www 2392: if ($env{'form.withgrades'.$ctr}) {
2393: $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
1.386 raeburn 2394: $messagetail = " for <a href=\"".
1.418 albertel 2395: $feedurl."?symb=$showsymb\">$env{'form.probTitle'}</a>";
1.386 raeburn 2396: }
2397: $msgstatus =
2398: &Apache::lonmsg::user_normal_msg($uname,$udom,$subject,
2399: $message.$messagetail,
1.418 albertel 2400: undef,$feedurl,undef,
1.386 raeburn 2401: undef,undef,$showsymb,
2402: $restitle);
2403: $request->print('<br />'.&mt('Sending message to [_1]:[_2]',$uname,$udom).': '.
1.296 www 2404: $msgstatus);
1.44 ng 2405: }
1.257 albertel 2406: if ($env{'form.collaborator'.$ctr}) {
1.155 albertel 2407: my @collabstrs=&Apache::loncommon::get_env_multiple("form.collaborator$ctr");
1.150 albertel 2408: foreach my $collabstr (@collabstrs) {
2409: my ($part,@collaborators) = split(/:/,$collabstr);
1.310 banghart 2410: foreach my $collaborator (@collaborators) {
1.150 albertel 2411: my ($errorflag,$pts,$wgt) =
1.324 albertel 2412: &saveHandGrade($request,$symb,$collaborator,$udom,$ctr,
1.257 albertel 2413: $env{'form.unamedom'.$ctr},$part);
1.150 albertel 2414: if ($errorflag eq 'not_allowed') {
1.362 albertel 2415: $request->print("<span class=\"LC_error\">".&mt('Not allowed to modify grades for [_1]',"$collaborator:$udom")."</span>");
1.150 albertel 2416: next;
1.418 albertel 2417: } elsif ($message ne '') {
2418: my ($baseurl,$showsymb) =
2419: &get_feedurl_and_symb($symb,$collaborator,
2420: $udom);
2421: if ($env{'form.withgrades'.$ctr}) {
2422: $messagetail = " for <a href=\"".
1.386 raeburn 2423: $baseurl."?symb=$showsymb\">$env{'form.probTitle'}</a>";
1.150 albertel 2424: }
1.418 albertel 2425: $msgstatus =
2426: &Apache::lonmsg::user_normal_msg($collaborator,$udom,$subject,$message.$messagetail,undef,$baseurl,undef,undef,undef,$showsymb,$restitle);
1.104 albertel 2427: }
1.44 ng 2428: }
2429: }
2430: }
2431: $ctr++;
2432: }
2433: }
2434:
1.257 albertel 2435: if ($env{'form.handgrade'} eq 'yes') {
1.119 ng 2436: # Keywords sorted in alphabatical order
1.257 albertel 2437: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1.119 ng 2438: my %keyhash = ();
1.257 albertel 2439: $env{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
2440: $env{'form.keywords'} =~ s/^\s+|\s+$//;
2441: my (@keywords) = sort(split(/\s+/,$env{'form.keywords'}));
2442: $env{'form.keywords'} = join(' ',@keywords);
2443: $keyhash{$symb.'_keywords'} = $env{'form.keywords'};
2444: $keyhash{$symb.'_subject'} = $env{'form.msgsub'};
2445: $keyhash{$loginuser.'_kwclr'} = $env{'form.kwclr'};
2446: $keyhash{$loginuser.'_kwsize'} = $env{'form.kwsize'};
2447: $keyhash{$loginuser.'_kwstyle'} = $env{'form.kwstyle'};
1.119 ng 2448:
2449: # message center - Order of message gets changed. Blank line is eliminated.
1.257 albertel 2450: # New messages are saved in env for the next student.
1.119 ng 2451: # All messages are saved in nohist_handgrade.db
2452: my ($ctr,$idx) = (1,1);
1.257 albertel 2453: while ($ctr <= $env{'form.savemsgN'}) {
2454: if ($env{'form.savemsg'.$ctr} ne '') {
2455: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.savemsg'.$ctr};
1.119 ng 2456: $idx++;
2457: }
2458: $ctr++;
1.41 ng 2459: }
1.119 ng 2460: $ctr = 0;
2461: while ($ctr < $ngrade) {
1.257 albertel 2462: if ($env{'form.newmsg'.$ctr} ne '') {
2463: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.newmsg'.$ctr};
2464: $env{'form.savemsg'.$idx} = $env{'form.newmsg'.$ctr};
1.119 ng 2465: $idx++;
2466: }
2467: $ctr++;
1.41 ng 2468: }
1.257 albertel 2469: $env{'form.savemsgN'} = --$idx;
2470: $keyhash{$symb.'_savemsgN'} = $env{'form.savemsgN'};
1.119 ng 2471: my $putresult = &Apache::lonnet::put
1.301 albertel 2472: ('nohist_handgrade',\%keyhash,$cdom,$cnum);
1.41 ng 2473: }
1.44 ng 2474: # Called by Save & Refresh from Highlight Attribute Window
1.257 albertel 2475: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
2476: if ($env{'form.refresh'} eq 'on') {
1.86 ng 2477: my ($ctr,$total) = (0,0);
2478: while ($ctr < $ngrade) {
1.257 albertel 2479: $total++ if $env{'form.unamedom'.$ctr} ne '';
1.86 ng 2480: $ctr++;
2481: }
1.257 albertel 2482: $env{'form.NTSTU'}=$ngrade;
1.86 ng 2483: $ctr = 0;
2484: while ($ctr < $total) {
1.257 albertel 2485: my $processUser = $env{'form.unamedom'.$ctr};
2486: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2487: $env{'form.fullname'} = $$fullname{$processUser};
1.86 ng 2488: &submission($request,$ctr,$total-1);
1.41 ng 2489: $ctr++;
2490: }
2491: return '';
2492: }
1.36 ng 2493:
1.121 ng 2494: # Go directly to grade student - from submission or link from chart page
1.120 ng 2495: if ($button eq 'Grade Student') {
1.324 albertel 2496: (undef,undef,$env{'form.handgrade'},undef,undef) = &showResourceInfo($symb);
1.257 albertel 2497: my $processUser = $env{'form.unamedom'.$env{'form.studentNo'}};
2498: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2499: $env{'form.fullname'} = $$fullname{$processUser};
1.120 ng 2500: &submission($request,0,0);
2501: return '';
2502: }
2503:
1.44 ng 2504: # Get the next/previous one or group of students
1.257 albertel 2505: my $firststu = $env{'form.unamedom0'};
2506: my $laststu = $env{'form.unamedom'.($ngrade-1)};
1.119 ng 2507: my $ctr = 2;
1.41 ng 2508: while ($laststu eq '') {
1.257 albertel 2509: $laststu = $env{'form.unamedom'.($ngrade-$ctr)};
1.41 ng 2510: $ctr++;
2511: $laststu = $firststu if ($ctr > $ngrade);
2512: }
1.44 ng 2513:
1.41 ng 2514: my (@parsedlist,@nextlist);
2515: my ($nextflg) = 0;
1.524 raeburn 2516: foreach my $item (sort
1.294 albertel 2517: {
2518: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
2519: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
2520: }
2521: return $a cmp $b;
2522: } (keys(%$fullname))) {
1.41 ng 2523: if ($nextflg == 1 && $button =~ /Next$/) {
1.524 raeburn 2524: push(@parsedlist,$item);
1.41 ng 2525: }
1.524 raeburn 2526: $nextflg = 1 if ($item eq $laststu);
1.41 ng 2527: if ($button eq 'Previous') {
1.524 raeburn 2528: last if ($item eq $firststu);
2529: push(@parsedlist,$item);
1.41 ng 2530: }
2531: }
2532: $ctr = 0;
2533: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
1.324 albertel 2534: my ($partlist) = &response_type($symb);
1.41 ng 2535: foreach my $student (@parsedlist) {
1.257 albertel 2536: my $submitonly=$env{'form.submitonly'};
1.41 ng 2537: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 2538:
2539: if ($submitonly eq 'queued') {
2540: my %queue_status =
2541: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
2542: $udom,$uname);
2543: next if (!defined($queue_status{'gradingqueue'}));
2544: }
2545:
1.156 albertel 2546: if ($submitonly =~ /^(yes|graded|incorrect)$/) {
1.257 albertel 2547: # my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.324 albertel 2548: my %status=&student_gradeStatus($symb,$udom,$uname,$partlist);
1.145 albertel 2549: my $submitted = 0;
1.248 albertel 2550: my $ungraded = 0;
2551: my $incorrect = 0;
1.524 raeburn 2552: foreach my $item (keys(%status)) {
2553: $submitted = 1 if ($status{$item} ne 'nothing');
2554: $ungraded = 1 if ($status{$item} =~ /^ungraded/);
2555: $incorrect = 1 if ($status{$item} =~ /^incorrect/);
2556: my ($foo,$partid,$foo1) = split(/\./,$item);
1.145 albertel 2557: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
2558: $submitted = 0;
2559: }
1.41 ng 2560: }
1.156 albertel 2561: next if (!$submitted && ($submitonly eq 'yes' ||
2562: $submitonly eq 'incorrect' ||
2563: $submitonly eq 'graded'));
1.248 albertel 2564: next if (!$ungraded && ($submitonly eq 'graded'));
2565: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 2566: }
1.524 raeburn 2567: push(@nextlist,$student) if ($ctr < $ntstu);
1.129 ng 2568: last if ($ctr == $ntstu);
1.41 ng 2569: $ctr++;
2570: }
1.36 ng 2571:
1.41 ng 2572: $ctr = 0;
2573: my $total = scalar(@nextlist)-1;
1.39 ng 2574:
1.524 raeburn 2575: foreach (sort(@nextlist)) {
1.41 ng 2576: my ($uname,$udom,$submitter) = split(/:/);
1.257 albertel 2577: $env{'form.student'} = $uname;
2578: $env{'form.userdom'} = $udom;
2579: $env{'form.fullname'} = $$fullname{$_};
1.41 ng 2580: &submission($request,$ctr,$total);
2581: $ctr++;
2582: }
2583: if ($total < 0) {
1.485 albertel 2584: my $the_end = '<h3><span class="LC_info">'.&mt('LON-CAPA User Message').'</span></h3><br />'."\n";
2585: $the_end.=&mt('<b>Message: </b> No more students for this section or class.').'<br /><br />'."\n";
2586: $the_end.=&mt('Click on the button below to return to the grading menu.').'<br /><br />'."\n";
1.324 albertel 2587: $the_end.=&show_grading_menu_form($symb);
1.41 ng 2588: $request->print($the_end);
2589: }
2590: return '';
1.38 ng 2591: }
1.36 ng 2592:
1.44 ng 2593: #---- Save the score and award for each student, if changed
1.38 ng 2594: sub saveHandGrade {
1.324 albertel 2595: my ($request,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
1.342 banghart 2596: my @version_parts;
1.104 albertel 2597: my $usec = &Apache::lonnet::getsection($domain,$stuname,
1.257 albertel 2598: $env{'request.course.id'});
1.104 albertel 2599: if (!&canmodify($usec)) { return('not_allowed'); }
1.337 banghart 2600: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
1.251 banghart 2601: my @parts_graded;
1.77 ng 2602: my %newrecord = ();
2603: my ($pts,$wgt) = ('','');
1.269 raeburn 2604: my %aggregate = ();
2605: my $aggregateflag = 0;
1.301 albertel 2606: my @parts = split(/:/,$env{'form.partlist'.$newflg});
2607: foreach my $new_part (@parts) {
1.337 banghart 2608: #collaborator ($submi may vary for different parts
1.259 banghart 2609: if ($submitter && $new_part ne $part) { next; }
2610: my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
1.125 ng 2611: if ($dropMenu eq 'excused') {
1.259 banghart 2612: if ($record{'resource.'.$new_part.'.solved'} ne 'excused') {
2613: $newrecord{'resource.'.$new_part.'.solved'} = 'excused';
2614: if (exists($record{'resource.'.$new_part.'.awarded'})) {
2615: $newrecord{'resource.'.$new_part.'.awarded'} = '';
1.58 albertel 2616: }
1.364 banghart 2617: $newrecord{'resource.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.58 albertel 2618: }
1.125 ng 2619: } elsif ($dropMenu eq 'reset status'
1.259 banghart 2620: && exists($record{'resource.'.$new_part.'.solved'})) { #don't bother if no old records -> no attempts
1.524 raeburn 2621: foreach my $key (keys(%record)) {
1.259 banghart 2622: if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
1.197 albertel 2623: }
1.259 banghart 2624: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2625: "$env{'user.name'}:$env{'user.domain'}";
1.270 albertel 2626: my $totaltries = $record{'resource.'.$part.'.tries'};
2627:
2628: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
2629: [$new_part]);
2630: my $aggtries =$totaltries;
1.269 raeburn 2631: if ($last_resets{$new_part}) {
1.270 albertel 2632: $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
2633: $new_part);
1.269 raeburn 2634: }
1.270 albertel 2635:
2636: my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
1.269 raeburn 2637: if ($aggtries > 0) {
1.327 albertel 2638: &decrement_aggs($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
1.269 raeburn 2639: $aggregateflag = 1;
2640: }
1.125 ng 2641: } elsif ($dropMenu eq '') {
1.259 banghart 2642: $pts = ($env{'form.GD_BOX'.$newflg.'_'.$new_part} ne '' ?
2643: $env{'form.GD_BOX'.$newflg.'_'.$new_part} :
2644: $env{'form.RADVAL'.$newflg.'_'.$new_part});
2645: if ($pts eq '' && $env{'form.GD_SEL'.$newflg.'_'.$new_part} eq '') {
1.153 albertel 2646: next;
2647: }
1.259 banghart 2648: $wgt = $env{'form.WGT'.$newflg.'_'.$new_part} eq '' ? 1 :
2649: $env{'form.WGT'.$newflg.'_'.$new_part};
1.41 ng 2650: my $partial= $pts/$wgt;
1.259 banghart 2651: if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
1.153 albertel 2652: #do not update score for part if not changed.
1.346 banghart 2653: &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
1.153 albertel 2654: next;
1.251 banghart 2655: } else {
1.524 raeburn 2656: push(@parts_graded,$new_part);
1.153 albertel 2657: }
1.259 banghart 2658: if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
2659: $newrecord{'resource.'.$new_part.'.awarded'} = $partial;
1.153 albertel 2660: }
1.259 banghart 2661: my $reckey = 'resource.'.$new_part.'.solved';
1.41 ng 2662: if ($partial == 0) {
1.153 albertel 2663: if ($record{$reckey} ne 'incorrect_by_override') {
2664: $newrecord{$reckey} = 'incorrect_by_override';
2665: }
1.41 ng 2666: } else {
1.153 albertel 2667: if ($record{$reckey} ne 'correct_by_override') {
2668: $newrecord{$reckey} = 'correct_by_override';
2669: }
2670: }
2671: if ($submitter &&
1.259 banghart 2672: ($record{'resource.'.$new_part.'.submitted_by'} ne $submitter)) {
2673: $newrecord{'resource.'.$new_part.'.submitted_by'} = $submitter;
1.41 ng 2674: }
1.259 banghart 2675: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2676: "$env{'user.name'}:$env{'user.domain'}";
1.41 ng 2677: }
1.259 banghart 2678: # unless problem has been graded, set flag to version the submitted files
1.305 banghart 2679: unless ($record{'resource.'.$new_part.'.solved'} =~ /^correct_/ ||
2680: $record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override' ||
2681: $dropMenu eq 'reset status')
2682: {
1.524 raeburn 2683: push(@version_parts,$new_part);
1.259 banghart 2684: }
1.41 ng 2685: }
1.301 albertel 2686: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2687: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2688:
1.344 albertel 2689: if (%newrecord) {
2690: if (@version_parts) {
1.364 banghart 2691: my @changed_keys = &version_portfiles(\%record, \@parts_graded,
2692: $env{'request.course.id'}, $symb, $domain, $stuname, \@version_parts);
1.344 albertel 2693: @newrecord{@changed_keys} = @record{@changed_keys};
1.367 albertel 2694: foreach my $new_part (@version_parts) {
2695: &handback_files($request,$symb,$stuname,$domain,$newflg,
2696: $new_part,\%newrecord);
2697: }
1.259 banghart 2698: }
1.44 ng 2699: &Apache::lonnet::cstore(\%newrecord,$symb,
1.257 albertel 2700: $env{'request.course.id'},$domain,$stuname);
1.380 albertel 2701: &check_and_remove_from_queue(\@parts,\%record,\%newrecord,$symb,
2702: $cdom,$cnum,$domain,$stuname);
1.41 ng 2703: }
1.269 raeburn 2704: if ($aggregateflag) {
2705: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 2706: $cdom,$cnum);
1.269 raeburn 2707: }
1.301 albertel 2708: return ('',$pts,$wgt);
1.36 ng 2709: }
1.322 albertel 2710:
1.380 albertel 2711: sub check_and_remove_from_queue {
2712: my ($parts,$record,$newrecord,$symb,$cdom,$cnum,$domain,$stuname) = @_;
2713: my @ungraded_parts;
2714: foreach my $part (@{$parts}) {
2715: if ( $record->{ 'resource.'.$part.'.awarded'} eq ''
2716: && $record->{ 'resource.'.$part.'.solved' } ne 'excused'
2717: && $newrecord->{'resource.'.$part.'.awarded'} eq ''
2718: && $newrecord->{'resource.'.$part.'.solved' } ne 'excused'
2719: ) {
2720: push(@ungraded_parts, $part);
2721: }
2722: }
2723: if ( !@ungraded_parts ) {
2724: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,
2725: $cnum,$domain,$stuname);
2726: }
2727: }
2728:
1.337 banghart 2729: sub handback_files {
2730: my ($request,$symb,$stuname,$domain,$newflg,$new_part,$newrecord) = @_;
1.517 raeburn 2731: my $portfolio_root = '/userfiles/portfolio';
1.359 www 2732: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.375 albertel 2733:
2734: my @part_response_id = &flatten_responseType($responseType);
2735: foreach my $part_response_id (@part_response_id) {
2736: my ($part_id,$resp_id) = @{ $part_response_id };
2737: my $part_resp = join('_',@{ $part_response_id });
1.337 banghart 2738: if (($env{'form.'.$newflg.'_'.$part_resp.'_returndoc1'}) && ($new_part == $part_id)) {
2739: # if multiple files are uploaded names will be 'returndoc2','returndoc3'
2740: my $file_counter = 1;
1.367 albertel 2741: my $file_msg;
1.337 banghart 2742: while ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter}) {
2743: my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.'.filename'};
1.338 banghart 2744: my ($directory,$answer_file) =
2745: ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter} =~ /^(.*?)([^\/]*)$/);
2746: my ($answer_name,$answer_ver,$answer_ext) =
2747: &file_name_version_ext($answer_file);
1.355 banghart 2748: my ($portfolio_path) = ($directory =~ /^.+$stuname\/portfolio(.*)/);
1.517 raeburn 2749: my $getpropath = 1;
2750: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$portfolio_path,$domain,$stuname,$getpropath);
1.338 banghart 2751: my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
1.355 banghart 2752: # fix file name
2753: my ($save_file_name) = (($directory.$answer_name.".$version.".$answer_ext) =~ /^.+\/${stuname}\/(.*)/);
2754: my $result=&Apache::lonnet::finishuserfileupload($stuname,$domain,
2755: $newflg.'_'.$part_resp.'_returndoc'.$file_counter,
2756: $save_file_name);
1.337 banghart 2757: if ($result !~ m|^/uploaded/|) {
1.536 raeburn 2758: $request->print('<br /><span class="LC_error">'.
2759: &mt('An error occurred ([_1]) while trying to upload [_2].',
2760: $result,$newflg.'_'.$part_resp.'_returndoc'.$file_counter).
2761: '</span>');
1.356 banghart 2762: } else {
1.360 banghart 2763: # mark the file as read only
2764: my @files = ($save_file_name);
1.372 albertel 2765: my @what = ($symb,$env{'request.course.id'},'handback');
1.360 banghart 2766: &Apache::lonnet::mark_as_readonly($domain,$stuname,\@files,\@what);
1.367 albertel 2767: if (exists($$newrecord{"resource.$new_part.$resp_id.handback"})) {
2768: $$newrecord{"resource.$new_part.$resp_id.handback"}.=',';
2769: }
2770: $$newrecord{"resource.$new_part.$resp_id.handback"} .= $save_file_name;
2771: $file_msg.= "\n".'<br /><span class="LC_filename"><a href="/uploaded/'."$domain/$stuname/".$save_file_name.'">'.$save_file_name."</a></span><br />";
2772:
1.337 banghart 2773: }
2774: $request->print("<br />".$fname." will be the uploaded file name");
1.354 albertel 2775: $request->print(" ".$env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter});
1.337 banghart 2776: $file_counter++;
2777: }
1.367 albertel 2778: my $subject = "File Handed Back by Instructor ";
2779: my $message = "A file has been returned that was originally submitted in reponse to: <br />";
2780: $message .= "<strong>".&Apache::lonnet::gettitle($symb)."</strong><br />";
2781: $message .= ' The returned file(s) are named: '. $file_msg;
2782: $message .= " and can be found in your portfolio space.";
1.418 albertel 2783: my ($feedurl,$showsymb) =
2784: &get_feedurl_and_symb($symb,$domain,$stuname);
1.386 raeburn 2785: my $restitle = &Apache::lonnet::gettitle($symb);
2786: my $msgstatus =
2787: &Apache::lonmsg::user_normal_msg($stuname,$domain,$subject.
2788: ' (File Returned) ['.$restitle.']',$message,undef,
1.418 albertel 2789: $feedurl,undef,undef,undef,$showsymb,$restitle);
1.337 banghart 2790: }
2791: }
1.338 banghart 2792: return;
1.337 banghart 2793: }
2794:
1.418 albertel 2795: sub get_feedurl_and_symb {
2796: my ($symb,$uname,$udom) = @_;
2797: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
2798: $url = &Apache::lonnet::clutter($url);
2799: my $encrypturl=&Apache::lonnet::EXT('resource.0.encrypturl',
2800: $symb,$udom,$uname);
2801: if ($encrypturl =~ /^yes$/i) {
2802: &Apache::lonenc::encrypted(\$url,1);
2803: &Apache::lonenc::encrypted(\$symb,1);
2804: }
2805: return ($url,$symb);
2806: }
2807:
1.313 banghart 2808: sub get_submitted_files {
2809: my ($udom,$uname,$partid,$respid,$record) = @_;
2810: my @files;
2811: if ($$record{"resource.$partid.$respid.portfiles"}) {
2812: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
2813: foreach my $file (split(',',$$record{"resource.$partid.$respid.portfiles"})) {
2814: push(@files,$file_url.$file);
2815: }
2816: }
2817: if ($$record{"resource.$partid.$respid.uploadedurl"}) {
2818: push(@files,$$record{"resource.$partid.$respid.uploadedurl"});
2819: }
2820: return (\@files);
2821: }
1.322 albertel 2822:
1.269 raeburn 2823: # ----------- Provides number of tries since last reset.
2824: sub get_num_tries {
2825: my ($record,$last_reset,$part) = @_;
2826: my $timestamp = '';
2827: my $num_tries = 0;
2828: if ($$record{'version'}) {
2829: for (my $version=$$record{'version'};$version>=1;$version--) {
2830: if (exists($$record{$version.':resource.'.$part.'.solved'})) {
2831: $timestamp = $$record{$version.':timestamp'};
2832: if ($timestamp > $last_reset) {
2833: $num_tries ++;
2834: } else {
2835: last;
2836: }
2837: }
2838: }
2839: }
2840: return $num_tries;
2841: }
2842:
2843: # ----------- Determine decrements required in aggregate totals
2844: sub decrement_aggs {
2845: my ($symb,$part,$aggregate,$aggtries,$totaltries,$solvedstatus) = @_;
2846: my %decrement = (
2847: attempts => 0,
2848: users => 0,
2849: correct => 0
2850: );
2851: $decrement{'attempts'} = $aggtries;
2852: if ($solvedstatus =~ /^correct/) {
2853: $decrement{'correct'} = 1;
2854: }
2855: if ($aggtries == $totaltries) {
2856: $decrement{'users'} = 1;
2857: }
1.524 raeburn 2858: foreach my $type (keys(%decrement)) {
1.269 raeburn 2859: $$aggregate{$symb."\0".$part."\0".$type} = -$decrement{$type};
2860: }
2861: return;
2862: }
2863:
2864: # ----------- Determine timestamps for last reset of aggregate totals for parts
2865: sub get_last_resets {
1.270 albertel 2866: my ($symb,$courseid,$partids) =@_;
2867: my %last_resets;
1.269 raeburn 2868: my $cdom = $env{'course.'.$courseid.'.domain'};
2869: my $cname = $env{'course.'.$courseid.'.num'};
1.271 albertel 2870: my @keys;
2871: foreach my $part (@{$partids}) {
2872: push(@keys,"$symb\0$part\0resettime");
2873: }
2874: my %results=&Apache::lonnet::get('nohist_resourcetracker',\@keys,
2875: $cdom,$cname);
2876: foreach my $part (@{$partids}) {
2877: $last_resets{$part}=$results{"$symb\0$part\0resettime"};
1.269 raeburn 2878: }
1.270 albertel 2879: return %last_resets;
1.269 raeburn 2880: }
2881:
1.251 banghart 2882: # ----------- Handles creating versions for portfolio files as answers
2883: sub version_portfiles {
1.343 banghart 2884: my ($record, $parts_graded, $courseid, $symb, $domain, $stu_name, $v_flag) = @_;
1.263 banghart 2885: my $version_parts = join('|',@$v_flag);
1.343 banghart 2886: my @returned_keys;
1.255 banghart 2887: my $parts = join('|', @$parts_graded);
1.517 raeburn 2888: my $portfolio_root = '/userfiles/portfolio';
1.277 albertel 2889: foreach my $key (keys(%$record)) {
1.259 banghart 2890: my $new_portfiles;
1.263 banghart 2891: if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
1.342 banghart 2892: my @versioned_portfiles;
1.367 albertel 2893: my @portfiles = split(/\s*,\s*/,$$record{$key});
1.252 banghart 2894: foreach my $file (@portfiles) {
1.306 banghart 2895: &Apache::lonnet::unmark_as_readonly($domain,$stu_name,[$symb,$env{'request.course.id'}],$file);
1.304 albertel 2896: my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*)$/);
2897: my ($answer_name,$answer_ver,$answer_ext) =
2898: &file_name_version_ext($answer_file);
1.517 raeburn 2899: my $getpropath = 1;
2900: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$directory,$domain,$stu_name,$getpropath);
1.342 banghart 2901: my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
1.306 banghart 2902: my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version);
2903: if ($new_answer ne 'problem getting file') {
1.342 banghart 2904: push(@versioned_portfiles, $directory.$new_answer);
1.306 banghart 2905: &Apache::lonnet::mark_as_readonly($domain,$stu_name,
1.367 albertel 2906: [$directory.$new_answer],
1.306 banghart 2907: [$symb,$env{'request.course.id'},'graded']);
1.259 banghart 2908: }
1.252 banghart 2909: }
1.343 banghart 2910: $$record{$key} = join(',',@versioned_portfiles);
2911: push(@returned_keys,$key);
1.251 banghart 2912: }
2913: }
1.343 banghart 2914: return (@returned_keys);
1.305 banghart 2915: }
2916:
1.307 banghart 2917: sub get_next_version {
1.341 banghart 2918: my ($answer_name, $answer_ext, $dir_list) = @_;
1.307 banghart 2919: my $version;
2920: foreach my $row (@$dir_list) {
2921: my ($file) = split(/\&/,$row,2);
2922: my ($file_name,$file_version,$file_ext) =
2923: &file_name_version_ext($file);
2924: if (($file_name eq $answer_name) &&
2925: ($file_ext eq $answer_ext)) {
2926: # gets here if filename and extension match, regardless of version
2927: if ($file_version ne '') {
2928: # a versioned file is found so save it for later
2929: if ($file_version > $version) {
2930: $version = $file_version;
2931: }
2932: }
2933: }
2934: }
2935: $version ++;
2936: return($version);
2937: }
2938:
1.305 banghart 2939: sub version_selected_portfile {
1.306 banghart 2940: my ($domain,$stu_name,$directory,$file_name,$version) = @_;
2941: my ($answer_name,$answer_ver,$answer_ext) =
2942: &file_name_version_ext($file_name);
2943: my $new_answer;
2944: $env{'form.copy'} = &Apache::lonnet::getfile("/uploaded/$domain/$stu_name/portfolio$directory$file_name");
2945: if($env{'form.copy'} eq '-1') {
2946: $new_answer = 'problem getting file';
2947: } else {
2948: $new_answer = $answer_name.'.'.$version.'.'.$answer_ext;
2949: my $copy_result = &Apache::lonnet::finishuserfileupload(
2950: $stu_name,$domain,'copy',
2951: '/portfolio'.$directory.$new_answer);
2952: }
2953: return ($new_answer);
1.251 banghart 2954: }
2955:
1.304 albertel 2956: sub file_name_version_ext {
2957: my ($file)=@_;
2958: my @file_parts = split(/\./, $file);
2959: my ($name,$version,$ext);
2960: if (@file_parts > 1) {
2961: $ext=pop(@file_parts);
2962: if (@file_parts > 1 && $file_parts[-1] =~ /^\d+$/) {
2963: $version=pop(@file_parts);
2964: }
2965: $name=join('.',@file_parts);
2966: } else {
2967: $name=join('.',@file_parts);
2968: }
2969: return($name,$version,$ext);
2970: }
2971:
1.44 ng 2972: #--------------------------------------------------------------------------------------
2973: #
2974: #-------------------------- Next few routines handles grading by section or whole class
2975: #
2976: #--- Javascript to handle grading by section or whole class
1.42 ng 2977: sub viewgrades_js {
2978: my ($request) = shift;
2979:
1.539 ! riegler 2980: my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
1.41 ng 2981: $request->print(<<VIEWJAVASCRIPT);
2982: <script type="text/javascript" language="javascript">
1.45 ng 2983: function writePoint(partid,weight,point) {
1.125 ng 2984: var radioButton = document.classgrade["RADVAL_"+partid];
2985: var textbox = document.classgrade["TEXTVAL_"+partid];
1.42 ng 2986: if (point == "textval") {
1.125 ng 2987: point = document.classgrade["TEXTVAL_"+partid].value;
1.109 matthew 2988: if (isNaN(point) || parseFloat(point) < 0) {
1.539 ! riegler 2989: alert("$alertmsg"+parseFloat(point));
1.42 ng 2990: var resetbox = false;
2991: for (var i=0; i<radioButton.length; i++) {
2992: if (radioButton[i].checked) {
2993: textbox.value = i;
2994: resetbox = true;
2995: }
2996: }
2997: if (!resetbox) {
2998: textbox.value = "";
2999: }
3000: return;
3001: }
1.109 matthew 3002: if (parseFloat(point) > parseFloat(weight)) {
3003: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 3004: ") greater than the weight for the part. Accept?");
3005: if (resp == false) {
3006: textbox.value = "";
3007: return;
3008: }
3009: }
1.42 ng 3010: for (var i=0; i<radioButton.length; i++) {
3011: radioButton[i].checked=false;
1.109 matthew 3012: if (parseFloat(point) == i) {
1.42 ng 3013: radioButton[i].checked=true;
3014: }
3015: }
1.41 ng 3016:
1.42 ng 3017: } else {
1.125 ng 3018: textbox.value = parseFloat(point);
1.42 ng 3019: }
1.41 ng 3020: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3021: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3022: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3023: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3024: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3025: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 3026: if (saveval != "correct") {
3027: scorename.value = point;
1.43 ng 3028: if (selname[0].selected != true) {
3029: selname[0].selected = true;
3030: }
1.42 ng 3031: }
3032: }
1.125 ng 3033: document.classgrade["SELVAL_"+partid][0].selected = true;
1.42 ng 3034: }
3035:
3036: function writeRadText(partid,weight) {
1.125 ng 3037: var selval = document.classgrade["SELVAL_"+partid];
3038: var radioButton = document.classgrade["RADVAL_"+partid];
1.265 www 3039: var override = document.classgrade["FORCE_"+partid].checked;
1.125 ng 3040: var textbox = document.classgrade["TEXTVAL_"+partid];
3041: if (selval[1].selected || selval[2].selected) {
1.42 ng 3042: for (var i=0; i<radioButton.length; i++) {
3043: radioButton[i].checked=false;
3044:
3045: }
3046: textbox.value = "";
3047:
3048: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3049: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3050: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3051: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3052: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3053: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 3054: if ((saveval != "correct") || override) {
1.42 ng 3055: scorename.value = "";
1.125 ng 3056: if (selval[1].selected) {
3057: selname[1].selected = true;
3058: } else {
3059: selname[2].selected = true;
3060: if (Number(document.classgrade["GD_"+user+"_"+partid+"_tries"].value))
3061: {document.classgrade["GD_"+user+"_"+partid+"_tries"].value = '0';}
3062: }
1.42 ng 3063: }
3064: }
1.43 ng 3065: } else {
3066: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3067: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3068: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3069: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3070: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3071: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 3072: if ((saveval != "correct") || override) {
1.125 ng 3073: scorename.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
1.43 ng 3074: selname[0].selected = true;
3075: }
3076: }
3077: }
1.42 ng 3078: }
3079:
3080: function changeSelect(partid,user) {
1.125 ng 3081: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
3082: var textbox = document.classgrade["GD_"+user+'_'+partid+"_awarded"];
1.44 ng 3083: var point = textbox.value;
1.125 ng 3084: var weight = document.classgrade["weight_"+partid].value;
1.44 ng 3085:
1.109 matthew 3086: if (isNaN(point) || parseFloat(point) < 0) {
1.539 ! riegler 3087: alert("$alertmsg"+parseFloat(point));
1.44 ng 3088: textbox.value = "";
3089: return;
3090: }
1.109 matthew 3091: if (parseFloat(point) > parseFloat(weight)) {
3092: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 3093: ") greater than the weight of the part. Accept?");
3094: if (resp == false) {
3095: textbox.value = "";
3096: return;
3097: }
3098: }
1.42 ng 3099: selval[0].selected = true;
3100: }
3101:
3102: function changeOneScore(partid,user) {
1.125 ng 3103: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
3104: if (selval[1].selected || selval[2].selected) {
3105: document.classgrade["GD_"+user+'_'+partid+"_awarded"].value = "";
3106: if (selval[2].selected) {
3107: document.classgrade["GD_"+user+'_'+partid+"_tries"].value = "0";
3108: }
1.269 raeburn 3109: }
1.42 ng 3110: }
3111:
3112: function resetEntry(numpart) {
3113: for (ctpart=0;ctpart<numpart;ctpart++) {
1.125 ng 3114: var partid = document.classgrade["partid_"+ctpart].value;
3115: var radioButton = document.classgrade["RADVAL_"+partid];
3116: var textbox = document.classgrade["TEXTVAL_"+partid];
3117: var selval = document.classgrade["SELVAL_"+partid];
1.42 ng 3118: for (var i=0; i<radioButton.length; i++) {
3119: radioButton[i].checked=false;
3120:
3121: }
3122: textbox.value = "";
3123: selval[0].selected = true;
3124:
3125: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 3126: var user = document.classgrade["ctr"+i].value;
1.289 albertel 3127: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 3128: var resetscore = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
3129: resetscore.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
3130: var resettries = document.classgrade["GD_"+user+"_"+partid+"_tries"];
3131: resettries.value = document.classgrade["GD_"+user+"_"+partid+"_tries_s"].value;
3132: var saveselval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
3133: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 3134: if (saveselval == "excused") {
1.43 ng 3135: if (selname[1].selected == false) { selname[1].selected = true;}
1.42 ng 3136: } else {
1.43 ng 3137: if (selname[0].selected == false) {selname[0].selected = true};
1.42 ng 3138: }
3139: }
1.41 ng 3140: }
1.42 ng 3141: }
3142:
1.41 ng 3143: </script>
3144: VIEWJAVASCRIPT
1.42 ng 3145: }
3146:
1.44 ng 3147: #--- show scores for a section or whole class w/ option to change/update a score
1.42 ng 3148: sub viewgrades {
3149: my ($request) = shift;
3150: &viewgrades_js($request);
1.41 ng 3151:
1.324 albertel 3152: my ($symb) = &get_symb($request);
1.168 albertel 3153: #need to make sure we have the correct data for later EXT calls,
3154: #thus invalidate the cache
3155: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 3156: $env{'course.'.$env{'request.course.id'}.'.num'},
3157: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 3158: &Apache::lonnet::clear_EXT_cache_status();
3159:
1.398 albertel 3160: my $result='<h3><span class="LC_info">'.&mt('Manual Grading').'</span></h3>';
1.485 albertel 3161: $result.='<h4>'.&mt('<b>Current Resource: </b>[_1]',$env{'form.probTitle'}).'</h4>'."\n";
1.41 ng 3162:
3163: #view individual student submission form - called using Javascript viewOneStudent
1.324 albertel 3164: $result.=&jscriptNform($symb);
1.41 ng 3165:
1.44 ng 3166: #beginning of class grading form
1.442 banghart 3167: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
1.41 ng 3168: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1.418 albertel 3169: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.38 ng 3170: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.432 banghart 3171: &build_section_inputs().
1.257 albertel 3172: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.442 banghart 3173: '<input type="hidden" name="Status" value="'.$env{'stu_status'}.'" />'."\n".
1.257 albertel 3174: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.72 ng 3175:
1.126 ng 3176: my $sectionClass;
1.430 banghart 3177: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.257 albertel 3178: if ($env{'form.section'} eq 'all') {
1.539 ! riegler 3179: $sectionClass=&mt('Class');
1.257 albertel 3180: } elsif ($env{'form.section'} eq 'none') {
1.539 ! riegler 3181: $sectionClass=&mt('Students in no Section');
1.52 albertel 3182: } else {
1.539 ! riegler 3183: $sectionClass=&mt('Students in Section(s) [_1]');
1.52 albertel 3184: }
1.485 albertel 3185: $result.=
3186: '<h3>'.
1.539 ! riegler 3187: &mt("Assign Common Grade to [_1]",$sectionClass,$section_display).'</h3>';
1.474 albertel 3188: $result.= &Apache::loncommon::start_data_table();
1.44 ng 3189: #radio buttons/text box for assigning points for a section or class.
3190: #handles different parts of a problem
1.375 albertel 3191: my ($partlist,$handgrade,$responseType) = &response_type($symb);
1.42 ng 3192: my %weight = ();
3193: my $ctsparts = 0;
1.45 ng 3194: my %seen = ();
1.375 albertel 3195: my @part_response_id = &flatten_responseType($responseType);
3196: foreach my $part_response_id (@part_response_id) {
3197: my ($partid,$respid) = @{ $part_response_id };
3198: my $part_resp = join('_',@{ $part_response_id });
1.45 ng 3199: next if $seen{$partid};
3200: $seen{$partid}++;
1.375 albertel 3201: my $handgrade=$$handgrade{$part_resp};
1.42 ng 3202: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
3203: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
3204:
1.324 albertel 3205: my $display_part=&get_display_part($partid,$symb);
1.485 albertel 3206: my $radio.='<table border="0"><tr>';
1.41 ng 3207: my $ctr = 0;
1.42 ng 3208: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
1.485 albertel 3209: $radio.= '<td><label><input type="radio" name="RADVAL_'.$partid.'" '.
1.54 albertel 3210: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.288 albertel 3211: ','.$ctr.')" />'.$ctr."</label></td>\n";
1.41 ng 3212: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
3213: $ctr++;
3214: }
1.485 albertel 3215: $radio.='</tr></table>';
3216: my $line = '<input type="text" name="TEXTVAL_'.
1.54 albertel 3217: $partid.'" size="4" '.'onChange="javascript:writePoint(\''.
3218: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.539 ! riegler 3219: $weight{$partid}.' '.&mt('(problem weight)').'</td>'."\n";
! 3220: $line.= '<td><b>'.&mt('Grade Status').':</b><select name="SELVAL_'.$partid.'"'.
1.54 albertel 3221: 'onChange="javascript:writeRadText(\''.$partid.'\','.
1.59 albertel 3222: $weight{$partid}.')"> '.
1.401 albertel 3223: '<option selected="selected"> </option>'.
1.485 albertel 3224: '<option value="excused">'.&mt('excused').'</option>'.
3225: '<option value="reset status">'.&mt('reset status').'</option>'.
3226: '</select></td>'.
3227: '<td><label><input type="checkbox" name="FORCE_'.$partid.'" />'.&mt('Override "Correct"').'</label>';
3228: $line.='<input type="hidden" name="partid_'.
3229: $ctsparts.'" value="'.$partid.'" />'."\n";
3230: $line.='<input type="hidden" name="weight_'.
3231: $partid.'" value="'.$weight{$partid}.'" />'."\n";
3232:
1.539 ! riegler 3233: #&mt('<td><b>Part:</b></td><td>[_1]</td><td><b>Points:</b></td><td>[_2]</td><td>or</td><td>[_3]</td>',$display_part,$radio,$line).
1.485 albertel 3234: $result.=
3235: &Apache::loncommon::start_data_table_row()."\n".
1.539 ! riegler 3236: '<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 3237: &Apache::loncommon::end_data_table_row()."\n";
1.42 ng 3238: $ctsparts++;
1.41 ng 3239: }
1.474 albertel 3240: $result.=&Apache::loncommon::end_data_table()."\n".
1.52 albertel 3241: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.485 albertel 3242: $result.='<input type="button" value="'.&mt('Revert to Default').'" '.
1.474 albertel 3243: 'onClick="javascript:resetEntry('.$ctsparts.');" />';
1.41 ng 3244:
1.44 ng 3245: #table listing all the students in a section/class
3246: #header of table
1.539 ! riegler 3247: $result.= '<h3>'.&mt('Assign Grade to Specific Students in ').$sectionClass,
! 3248: $section_display.'</h3>';
1.474 albertel 3249: $result.= &Apache::loncommon::start_data_table().
3250: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 3251: '<th>'.&mt('No.').'</th>'.
1.474 albertel 3252: '<th>'.&nameUserString('header')."</th>\n";
1.324 albertel 3253: my (@parts) = sort(&getpartlist($symb));
3254: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.269 raeburn 3255: my @partids = ();
1.41 ng 3256: foreach my $part (@parts) {
3257: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1.539 ! riegler 3258: my $narrowtext = &mt('Tries');
! 3259: $display =~ s|^Number of Attempts|$narrowtext <br />|; # makes the column narrower
1.41 ng 3260: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
1.207 albertel 3261: my ($partid) = &split_part_type($part);
1.524 raeburn 3262: push(@partids,$partid);
1.324 albertel 3263: my $display_part=&get_display_part($partid,$symb);
1.41 ng 3264: if ($display =~ /^Partial Credit Factor/) {
1.485 albertel 3265: $result.='<th>'.
3266: &mt('Score Part: [_1]<br /> (weight = [_2])',
3267: $display_part,$weight{$partid}).'</th>'."\n";
1.41 ng 3268: next;
1.485 albertel 3269:
1.207 albertel 3270: } else {
1.485 albertel 3271: if ($display =~ /Problem Status/) {
3272: my $grade_status_mt = &mt('Grade Status');
3273: $display =~ s{Problem Status}{$grade_status_mt<br />};
3274: }
3275: my $part_mt = &mt('Part:');
3276: $display =~s{\[Part: \Q$partid\E\]}{$part_mt $display_part};
1.41 ng 3277: }
1.485 albertel 3278:
1.474 albertel 3279: $result.='<th>'.$display.'</th>'."\n";
1.41 ng 3280: }
1.474 albertel 3281: $result.=&Apache::loncommon::end_data_table_header_row();
1.44 ng 3282:
1.270 albertel 3283: my %last_resets =
3284: &get_last_resets($symb,$env{'request.course.id'},\@partids);
1.269 raeburn 3285:
1.41 ng 3286: #get info for each student
1.44 ng 3287: #list all the students - with points and grade status
1.257 albertel 3288: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
1.41 ng 3289: my $ctr = 0;
1.294 albertel 3290: foreach (sort
3291: {
3292: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
3293: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
3294: }
3295: return $a cmp $b;
3296: } (keys(%$fullname))) {
1.126 ng 3297: $ctr++;
1.324 albertel 3298: $result.=&viewstudentgrade($symb,$env{'request.course.id'},
1.269 raeburn 3299: $_,$$fullname{$_},\@parts,\%weight,$ctr,\%last_resets);
1.41 ng 3300: }
1.474 albertel 3301: $result.=&Apache::loncommon::end_data_table();
1.41 ng 3302: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.485 albertel 3303: $result.='<input type="button" value="'.&mt('Save').'" '.
1.417 albertel 3304: 'onClick="javascript:submit();" target="_self" /></form>'."\n";
1.96 albertel 3305: if (scalar(%$fullname) eq 0) {
3306: my $colspan=3+scalar(@parts);
1.433 banghart 3307: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.442 banghart 3308: my $stu_status = join(' or ',&Apache::loncommon::get_env_multiple('form.Status'));
1.433 banghart 3309: $result='<span class="LC_warning">'.
1.485 albertel 3310: &mt('There are no students in section(s) [_1] with enrollment status [_2] to modify or grade.',
1.442 banghart 3311: $section_display, $stu_status).
1.433 banghart 3312: '</span>';
1.96 albertel 3313: }
1.324 albertel 3314: $result.=&show_grading_menu_form($symb);
1.41 ng 3315: return $result;
3316: }
3317:
1.44 ng 3318: #--- call by previous routine to display each student
1.41 ng 3319: sub viewstudentgrade {
1.324 albertel 3320: my ($symb,$courseid,$student,$fullname,$parts,$weight,$ctr,$last_resets) = @_;
1.44 ng 3321: my ($uname,$udom) = split(/:/,$student);
3322: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.269 raeburn 3323: my %aggregates = ();
1.474 albertel 3324: my $result=&Apache::loncommon::start_data_table_row().'<td align="right">'.
1.233 albertel 3325: '<input type="hidden" name="ctr'.($ctr-1).'" value="'.$student.'" />'.
3326: "\n".$ctr.' </td><td> '.
1.44 ng 3327: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.417 albertel 3328: '\');" target="_self">'.$fullname.'</a> '.
1.398 albertel 3329: '<span class="LC_internal_info">('.$uname.($env{'user.domain'} eq $udom ? '' : ':'.$udom).')</span></td>'."\n";
1.281 albertel 3330: $student=~s/:/_/; # colon doen't work in javascript for names
1.63 albertel 3331: foreach my $apart (@$parts) {
3332: my ($part,$type) = &split_part_type($apart);
1.41 ng 3333: my $score=$record{"resource.$part.$type"};
1.276 albertel 3334: $result.='<td align="center">';
1.269 raeburn 3335: my ($aggtries,$totaltries);
3336: unless (exists($aggregates{$part})) {
1.270 albertel 3337: $totaltries = $record{'resource.'.$part.'.tries'};
3338:
3339: $aggtries = $totaltries;
1.269 raeburn 3340: if ($$last_resets{$part}) {
1.270 albertel 3341: $aggtries = &get_num_tries(\%record,$$last_resets{$part},
3342: $part);
3343: }
1.269 raeburn 3344: $result.='<input type="hidden" name="'.
3345: 'GD_'.$student.'_'.$part.'_aggtries" value="'.$aggtries.'" />'."\n";
3346: $result.='<input type="hidden" name="'.
3347: 'GD_'.$student.'_'.$part.'_totaltries" value="'.$totaltries.'" />'."\n";
3348: $aggregates{$part} = 1;
3349: }
1.41 ng 3350: if ($type eq 'awarded') {
1.320 albertel 3351: my $pts = $score eq '' ? '' : &compute_points($score,$$weight{$part});
1.42 ng 3352: $result.='<input type="hidden" name="'.
1.89 albertel 3353: 'GD_'.$student.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.233 albertel 3354: $result.='<input type="text" name="'.
1.89 albertel 3355: 'GD_'.$student.'_'.$part.'_awarded" '.
3356: 'onChange="javascript:changeSelect(\''.$part.'\',\''.$student.
1.44 ng 3357: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41 ng 3358: } elsif ($type eq 'solved') {
3359: my ($status,$foo)=split(/_/,$score,2);
3360: $status = 'nothing' if ($status eq '');
1.89 albertel 3361: $result.='<input type="hidden" name="'.'GD_'.$student.'_'.
1.54 albertel 3362: $part.'_solved_s" value="'.$status.'" />'."\n";
1.233 albertel 3363: $result.=' <select name="'.
1.89 albertel 3364: 'GD_'.$student.'_'.$part.'_solved" '.
3365: 'onChange="javascript:changeOneScore(\''.$part.'\',\''.$student.'\')" >'."\n";
1.485 albertel 3366: $result.= (($status eq 'excused') ? '<option> </option><option selected="selected" value="excused">'.&mt('excused').'</option>'
3367: : '<option selected="selected"> </option><option value="excused">'.&mt('excused').'</option>')."\n";
3368: $result.='<option value="reset status">'.&mt('reset status').'</option>';
1.126 ng 3369: $result.="</select> </td>\n";
1.122 ng 3370: } else {
3371: $result.='<input type="hidden" name="'.
3372: 'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
3373: "\n";
1.233 albertel 3374: $result.='<input type="text" name="'.
1.122 ng 3375: 'GD_'.$student.'_'.$part.'_'.$type.'" '.
3376: 'value="'.$score.'" size="4" /></td>'."\n";
1.41 ng 3377: }
3378: }
1.474 albertel 3379: $result.=&Apache::loncommon::end_data_table_row();
1.41 ng 3380: return $result;
1.38 ng 3381: }
3382:
1.44 ng 3383: #--- change scores for all the students in a section/class
3384: # record does not get update if unchanged
1.38 ng 3385: sub editgrades {
1.41 ng 3386: my ($request) = @_;
3387:
1.324 albertel 3388: my $symb=&get_symb($request);
1.433 banghart 3389: my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
1.477 albertel 3390: my $title='<h2>'.&mt('Current Grade Status').'</h2>';
3391: $title.='<h4>'.&mt('<b>Current Resource: </b>[_1]',$env{'form.probTitle'}).'</h4>'."\n";
1.433 banghart 3392: $title.='<h4>'.&mt('<b>Section: </b>[_1]',$section_display).'</h4>'."\n";
1.126 ng 3393:
1.477 albertel 3394: my $result= &Apache::loncommon::start_data_table().
3395: &Apache::loncommon::start_data_table_header_row().
3396: '<th rowspan="2" valign="middle">'.&mt('No.').'</th>'.
3397: '<th rowspan="2" valign="middle">'.&nameUserString('header')."</th>\n";
1.43 ng 3398: my %scoreptr = (
3399: 'correct' =>'correct_by_override',
3400: 'incorrect'=>'incorrect_by_override',
3401: 'excused' =>'excused',
3402: 'ungraded' =>'ungraded_attempted',
3403: 'nothing' => '',
3404: );
1.257 albertel 3405: my ($classlist,undef,$fullname) = &getclasslist($env{'form.section'},'0');
1.34 ng 3406:
1.44 ng 3407: my (@partid);
3408: my %weight = ();
1.54 albertel 3409: my %columns = ();
1.44 ng 3410: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54 albertel 3411:
1.324 albertel 3412: my (@parts) = sort(&getpartlist($symb));
1.54 albertel 3413: my $header;
1.257 albertel 3414: while ($ctr < $env{'form.totalparts'}) {
3415: my $partid = $env{'form.partid_'.$ctr};
1.524 raeburn 3416: push(@partid,$partid);
1.257 albertel 3417: $weight{$partid} = $env{'form.weight_'.$partid};
1.44 ng 3418: $ctr++;
1.54 albertel 3419: }
1.324 albertel 3420: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.54 albertel 3421: foreach my $partid (@partid) {
1.478 albertel 3422: $header .= '<th align="center">'.&mt('Old Score').'</th>'.
3423: '<th align="center">'.&mt('New Score').'</th>';
1.54 albertel 3424: $columns{$partid}=2;
3425: foreach my $stores (@parts) {
3426: my ($part,$type) = &split_part_type($stores);
3427: if ($part !~ m/^\Q$partid\E/) { next;}
3428: if ($type eq 'awarded' || $type eq 'solved') { next; }
3429: my $display=&Apache::lonnet::metadata($url,$stores.'.display');
3430: $display =~ s/\[Part: (\w)+\]//;
1.539 ! riegler 3431: my $narrowtext = &mt('Tries');
! 3432: $display =~ s/Number of Attempts/$narrowtext/;
! 3433: $header .= '<th align="center">'.&mt('Old').' '.$display.'</th>'.
! 3434: '<th align="center">'.&mt('New').' '.$display.'</th>';
1.54 albertel 3435: $columns{$partid}+=2;
3436: }
3437: }
3438: foreach my $partid (@partid) {
1.324 albertel 3439: my $display_part=&get_display_part($partid,$symb);
1.478 albertel 3440: $result .= '<th colspan="'.$columns{$partid}.'" align="center">'.
3441: &mt('Part: [_1] (Weight = [_2])',$display_part,$weight{$partid}).
3442: '</th>';
1.54 albertel 3443:
1.44 ng 3444: }
1.477 albertel 3445: $result .= &Apache::loncommon::end_data_table_header_row().
3446: &Apache::loncommon::start_data_table_header_row().
3447: $header.
3448: &Apache::loncommon::end_data_table_header_row();
3449: my @noupdate;
1.126 ng 3450: my ($updateCtr,$noupdateCtr) = (1,1);
1.257 albertel 3451: for ($i=0; $i<$env{'form.total'}; $i++) {
1.93 albertel 3452: my $line;
1.257 albertel 3453: my $user = $env{'form.ctr'.$i};
1.281 albertel 3454: my ($uname,$udom)=split(/:/,$user);
1.44 ng 3455: my %newrecord;
3456: my $updateflag = 0;
1.281 albertel 3457: $line .= '<td>'.&nameUserString(undef,$$fullname{$user},$uname,$udom).'</td>';
1.108 albertel 3458: my $usec=$classlist->{"$uname:$udom"}[5];
1.105 albertel 3459: if (!&canmodify($usec)) {
1.126 ng 3460: my $numcols=scalar(@partid)*4+2;
1.477 albertel 3461: push(@noupdate,
1.478 albertel 3462: $line."<td colspan=\"$numcols\"><span class=\"LC_warning\">".
3463: &mt('Not allowed to modify student')."</span></td></tr>");
1.105 albertel 3464: next;
3465: }
1.269 raeburn 3466: my %aggregate = ();
3467: my $aggregateflag = 0;
1.281 albertel 3468: $user=~s/:/_/; # colon doen't work in javascript for names
1.44 ng 3469: foreach (@partid) {
1.257 albertel 3470: my $old_aw = $env{'form.GD_'.$user.'_'.$_.'_awarded_s'};
1.54 albertel 3471: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
3472: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
1.257 albertel 3473: my $old_score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
3474: my $awarded = $env{'form.GD_'.$user.'_'.$_.'_awarded'};
1.54 albertel 3475: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
3476: my $partial = $awarded eq '' ? '' : $pcr;
1.44 ng 3477: my $score;
3478: if ($partial eq '') {
1.257 albertel 3479: $score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 3480: } elsif ($partial > 0) {
3481: $score = 'correct_by_override';
3482: } elsif ($partial == 0) {
3483: $score = 'incorrect_by_override';
3484: }
1.257 albertel 3485: my $dropMenu = $env{'form.GD_'.$user.'_'.$_.'_solved'};
1.125 ng 3486: $score = 'excused' if (($dropMenu eq 'excused') && ($score ne 'excused'));
3487:
1.292 albertel 3488: $newrecord{'resource.'.$_.'.regrader'}=
3489: "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 3490: if ($dropMenu eq 'reset status' &&
3491: $old_score ne '') { # ignore if no previous attempts => nothing to reset
1.299 albertel 3492: $newrecord{'resource.'.$_.'.tries'} = '';
1.125 ng 3493: $newrecord{'resource.'.$_.'.solved'} = '';
3494: $newrecord{'resource.'.$_.'.award'} = '';
1.299 albertel 3495: $newrecord{'resource.'.$_.'.awarded'} = '';
1.125 ng 3496: $updateflag = 1;
1.269 raeburn 3497: if ($env{'form.GD_'.$user.'_'.$_.'_aggtries'} > 0) {
3498: my $aggtries = $env{'form.GD_'.$user.'_'.$_.'_aggtries'};
3499: my $totaltries = $env{'form.GD_'.$user.'_'.$_.'_totaltries'};
3500: my $solvedstatus = $env{'form.GD_'.$user.'_'.$_.'_solved_s'};
3501: &decrement_aggs($symb,$_,\%aggregate,$aggtries,$totaltries,$solvedstatus);
3502: $aggregateflag = 1;
3503: }
1.139 albertel 3504: } elsif (!($old_part eq $partial && $old_score eq $score)) {
3505: $updateflag = 1;
3506: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
3507: $newrecord{'resource.'.$_.'.solved'} = $score;
3508: $rec_update++;
1.125 ng 3509: }
3510:
1.93 albertel 3511: $line .= '<td align="center">'.$old_aw.' </td>'.
1.44 ng 3512: '<td align="center">'.$awarded.
3513: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 3514:
1.54 albertel 3515:
3516: my $partid=$_;
3517: foreach my $stores (@parts) {
3518: my ($part,$type) = &split_part_type($stores);
3519: if ($part !~ m/^\Q$partid\E/) { next;}
3520: if ($type eq 'awarded' || $type eq 'solved') { next; }
1.257 albertel 3521: my $old_aw = $env{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
3522: my $awarded = $env{'form.GD_'.$user.'_'.$part.'_'.$type};
1.54 albertel 3523: if ($awarded ne '' && $awarded ne $old_aw) {
3524: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.257 albertel 3525: $newrecord{'resource.'.$part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.54 albertel 3526: $updateflag=1;
3527: }
1.93 albertel 3528: $line .= '<td align="center">'.$old_aw.' </td>'.
1.54 albertel 3529: '<td align="center">'.$awarded.' </td>';
3530: }
1.44 ng 3531: }
1.477 albertel 3532: $line.="\n";
1.301 albertel 3533:
3534: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3535: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3536:
1.44 ng 3537: if ($updateflag) {
3538: $count++;
1.257 albertel 3539: &Apache::lonnet::cstore(\%newrecord,$symb,$env{'request.course.id'},
1.89 albertel 3540: $udom,$uname);
1.301 albertel 3541:
3542: if (&Apache::bridgetask::in_queue('gradingqueue',$symb,$cdom,
3543: $cnum,$udom,$uname)) {
3544: # need to figure out if should be in queue.
3545: my %record =
3546: &Apache::lonnet::restore($symb,$env{'request.course.id'},
3547: $udom,$uname);
3548: my $all_graded = 1;
3549: my $none_graded = 1;
3550: foreach my $part (@parts) {
3551: if ( $record{'resource.'.$part.'.awarded'} eq '' ) {
3552: $all_graded = 0;
3553: } else {
3554: $none_graded = 0;
3555: }
3556: }
3557:
3558: if ($all_graded || $none_graded) {
3559: &Apache::bridgetask::remove_from_queue('gradingqueue',
3560: $symb,$cdom,$cnum,
3561: $udom,$uname);
3562: }
3563: }
3564:
1.477 albertel 3565: $result.=&Apache::loncommon::start_data_table_row().
3566: '<td align="right"> '.$updateCtr.' </td>'.$line.
3567: &Apache::loncommon::end_data_table_row();
1.126 ng 3568: $updateCtr++;
1.93 albertel 3569: } else {
1.477 albertel 3570: push(@noupdate,
3571: '<td align="right"> '.$noupdateCtr.' </td>'.$line);
1.126 ng 3572: $noupdateCtr++;
1.44 ng 3573: }
1.269 raeburn 3574: if ($aggregateflag) {
3575: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 3576: $cdom,$cnum);
1.269 raeburn 3577: }
1.93 albertel 3578: }
1.477 albertel 3579: if (@noupdate) {
1.126 ng 3580: # my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3;
3581: my $numcols=scalar(@partid)*4+2;
1.477 albertel 3582: $result .= &Apache::loncommon::start_data_table_row('LC_empty_row').
1.478 albertel 3583: '<td align="center" colspan="'.$numcols.'">'.
3584: &mt('No Changes Occurred For the Students Below').
3585: '</td>'.
1.477 albertel 3586: &Apache::loncommon::end_data_table_row();
3587: foreach my $line (@noupdate) {
3588: $result.=
3589: &Apache::loncommon::start_data_table_row().
3590: $line.
3591: &Apache::loncommon::end_data_table_row();
3592: }
1.44 ng 3593: }
1.477 albertel 3594: $result .= &Apache::loncommon::end_data_table().
3595: &show_grading_menu_form($symb);
1.478 albertel 3596: my $msg = '<p><b>'.
3597: &mt('Number of records updated = [_1] for [quant,_2,student].',
3598: $rec_update,$count).'</b><br />'.
3599: '<b>'.&mt('Total number of students = [_1]',$env{'form.total'}).
3600: '</b></p>';
1.44 ng 3601: return $title.$msg.$result;
1.5 albertel 3602: }
1.54 albertel 3603:
3604: sub split_part_type {
3605: my ($partstr) = @_;
3606: my ($temp,@allparts)=split(/_/,$partstr);
3607: my $type=pop(@allparts);
1.439 albertel 3608: my $part=join('_',@allparts);
1.54 albertel 3609: return ($part,$type);
3610: }
3611:
1.44 ng 3612: #------------- end of section for handling grading by section/class ---------
3613: #
3614: #----------------------------------------------------------------------------
3615:
1.5 albertel 3616:
1.44 ng 3617: #----------------------------------------------------------------------------
3618: #
3619: #-------------------------- Next few routines handles grading by csv upload
3620: #
3621: #--- Javascript to handle csv upload
1.27 albertel 3622: sub csvupload_javascript_reverse_associate {
1.246 albertel 3623: my $error1=&mt('You need to specify the username or ID');
3624: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3625: return(<<ENDPICK);
3626: function verify(vf) {
3627: var foundsomething=0;
3628: var founduname=0;
1.243 albertel 3629: var foundID=0;
1.27 albertel 3630: for (i=0;i<=vf.nfields.value;i++) {
3631: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3632: if (i==0 && tw!=0) { foundID=1; }
3633: if (i==1 && tw!=0) { founduname=1; }
3634: if (i!=0 && i!=1 && i!=2 && tw!=0) { foundsomething=1; }
1.27 albertel 3635: }
1.246 albertel 3636: if (founduname==0 && foundID==0) {
3637: alert('$error1');
3638: return;
1.27 albertel 3639: }
3640: if (foundsomething==0) {
1.246 albertel 3641: alert('$error2');
3642: return;
1.27 albertel 3643: }
3644: vf.submit();
3645: }
3646: function flip(vf,tf) {
3647: var nw=eval('vf.f'+tf+'.selectedIndex');
3648: var i;
3649: for (i=0;i<=vf.nfields.value;i++) {
3650: //can not pick the same destination field for both name and domain
3651: if (((i ==0)||(i ==1)) &&
3652: ((tf==0)||(tf==1)) &&
3653: (i!=tf) &&
3654: (eval('vf.f'+i+'.selectedIndex')==nw)) {
3655: eval('vf.f'+i+'.selectedIndex=0;')
3656: }
3657: }
3658: }
3659: ENDPICK
3660: }
3661:
3662: sub csvupload_javascript_forward_associate {
1.246 albertel 3663: my $error1=&mt('You need to specify the username or ID');
3664: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3665: return(<<ENDPICK);
3666: function verify(vf) {
3667: var foundsomething=0;
3668: var founduname=0;
1.243 albertel 3669: var foundID=0;
1.27 albertel 3670: for (i=0;i<=vf.nfields.value;i++) {
3671: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3672: if (tw==1) { foundID=1; }
3673: if (tw==2) { founduname=1; }
3674: if (tw>3) { foundsomething=1; }
1.27 albertel 3675: }
1.246 albertel 3676: if (founduname==0 && foundID==0) {
3677: alert('$error1');
3678: return;
1.27 albertel 3679: }
3680: if (foundsomething==0) {
1.246 albertel 3681: alert('$error2');
3682: return;
1.27 albertel 3683: }
3684: vf.submit();
3685: }
3686: function flip(vf,tf) {
3687: var nw=eval('vf.f'+tf+'.selectedIndex');
3688: var i;
3689: //can not pick the same destination field twice
3690: for (i=0;i<=vf.nfields.value;i++) {
3691: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
3692: eval('vf.f'+i+'.selectedIndex=0;')
3693: }
3694: }
3695: }
3696: ENDPICK
3697: }
3698:
1.26 albertel 3699: sub csvuploadmap_header {
1.324 albertel 3700: my ($request,$symb,$datatoken,$distotal)= @_;
1.41 ng 3701: my $javascript;
1.257 albertel 3702: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3703: $javascript=&csvupload_javascript_reverse_associate();
3704: } else {
3705: $javascript=&csvupload_javascript_forward_associate();
3706: }
1.45 ng 3707:
1.324 albertel 3708: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.257 albertel 3709: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1.245 albertel 3710: my $ignore=&mt('Ignore First Line');
1.418 albertel 3711: $symb = &Apache::lonenc::check_encrypt($symb);
1.41 ng 3712: $request->print(<<ENDPICK);
1.26 albertel 3713: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.398 albertel 3714: <h3><span class="LC_info">Uploading Class Grades</span></h3>
1.45 ng 3715: $result
1.326 albertel 3716: <hr />
1.26 albertel 3717: <h3>Identify fields</h3>
3718: Total number of records found in file: $distotal <hr />
3719: Enter as many fields as you can. The system will inform you and bring you back
3720: to this page if the data selected is insufficient to run your class.<hr />
3721: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1.245 albertel 3722: <label><input type="checkbox" name="noFirstLine" $checked />$ignore</label>
1.26 albertel 3723: <input type="hidden" name="associate" value="" />
3724: <input type="hidden" name="phase" value="three" />
3725: <input type="hidden" name="datatoken" value="$datatoken" />
1.257 albertel 3726: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
3727: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
1.26 albertel 3728: <input type="hidden" name="upfile_associate"
1.257 albertel 3729: value="$env{'form.upfile_associate'}" />
1.26 albertel 3730: <input type="hidden" name="symb" value="$symb" />
1.257 albertel 3731: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
3732: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
1.246 albertel 3733: <input type="hidden" name="command" value="csvuploadoptions" />
1.26 albertel 3734: <hr />
3735: <script type="text/javascript" language="Javascript">
3736: $javascript
3737: </script>
3738: ENDPICK
1.118 ng 3739: return '';
1.26 albertel 3740:
3741: }
3742:
3743: sub csvupload_fields {
1.324 albertel 3744: my ($symb) = @_;
3745: my (@parts) = &getpartlist($symb);
1.243 albertel 3746: my @fields=(['ID','Student ID'],
3747: ['username','Student Username'],
3748: ['domain','Student Domain']);
1.324 albertel 3749: my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
1.41 ng 3750: foreach my $part (sort(@parts)) {
3751: my @datum;
3752: my $display=&Apache::lonnet::metadata($url,$part.'.display');
3753: my $name=$part;
3754: if (!$display) { $display = $name; }
3755: @datum=($name,$display);
1.244 albertel 3756: if ($name=~/^stores_(.*)_awarded/) {
3757: push(@fields,['stores_'.$1.'_points',"Points [Part: $1]"]);
3758: }
1.41 ng 3759: push(@fields,\@datum);
3760: }
3761: return (@fields);
1.26 albertel 3762: }
3763:
3764: sub csvuploadmap_footer {
1.41 ng 3765: my ($request,$i,$keyfields) =@_;
3766: $request->print(<<ENDPICK);
1.26 albertel 3767: </table>
3768: <input type="hidden" name="nfields" value="$i" />
3769: <input type="hidden" name="keyfields" value="$keyfields" />
3770: <input type="button" onClick="javascript:verify(this.form)" value="Assign Grades" /><br />
3771: </form>
3772: ENDPICK
3773: }
3774:
1.283 albertel 3775: sub checkforfile_js {
1.539 ! riegler 3776: my $alertmsg = &mt('Please use the browse button to select a file from your local directory.');
1.86 ng 3777: my $result =<<CSVFORMJS;
3778: <script type="text/javascript" language="javascript">
3779: function checkUpload(formname) {
3780: if (formname.upfile.value == "") {
1.539 ! riegler 3781: alert("$alertmsg");
1.86 ng 3782: return false;
3783: }
3784: formname.submit();
3785: }
3786: </script>
3787: CSVFORMJS
1.283 albertel 3788: return $result;
3789: }
3790:
3791: sub upcsvScores_form {
3792: my ($request) = shift;
1.324 albertel 3793: my ($symb)=&get_symb($request);
1.283 albertel 3794: if (!$symb) {return '';}
3795: my $result=&checkforfile_js();
1.257 albertel 3796: $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
1.324 albertel 3797: my ($table) = &showResourceInfo($symb,$env{'form.probTitle'});
1.118 ng 3798: $result.=$table;
1.326 albertel 3799: $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
3800: $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
1.538 schulted 3801: $result.=' <b>'.&mt('Specify a file containing the class scores for current resource.').
3802: '</b></td></tr>'."\n";
1.86 ng 3803: $result.='<tr bgcolor=#ffffe6><td>'."\n";
1.370 www 3804: my $upload=&mt("Upload Scores");
1.86 ng 3805: my $upfile_select=&Apache::loncommon::upfile_select_html();
1.245 albertel 3806: my $ignore=&mt('Ignore First Line');
1.418 albertel 3807: $symb = &Apache::lonenc::check_encrypt($symb);
1.86 ng 3808: $result.=<<ENDUPFORM;
1.106 albertel 3809: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.86 ng 3810: <input type="hidden" name="symb" value="$symb" />
3811: <input type="hidden" name="command" value="csvuploadmap" />
1.257 albertel 3812: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
3813: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
1.86 ng 3814: $upfile_select
1.370 www 3815: <br /><input type="button" onClick="javascript:checkUpload(this.form);" value="$upload" />
1.283 albertel 3816: <label><input type="checkbox" name="noFirstLine" />$ignore</label>
1.86 ng 3817: </form>
3818: ENDUPFORM
1.370 www 3819: $result.=&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
3820: &mt("How do I create a CSV file from a spreadsheet"))
3821: .'</td></tr></table>'."\n";
1.86 ng 3822: $result.='</td></tr></table><br /><br />'."\n";
1.324 albertel 3823: $result.=&show_grading_menu_form($symb);
1.86 ng 3824: return $result;
3825: }
3826:
3827:
1.26 albertel 3828: sub csvuploadmap {
1.41 ng 3829: my ($request)= @_;
1.324 albertel 3830: my ($symb)=&get_symb($request);
1.41 ng 3831: if (!$symb) {return '';}
1.72 ng 3832:
1.41 ng 3833: my $datatoken;
1.257 albertel 3834: if (!$env{'form.datatoken'}) {
1.41 ng 3835: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 3836: } else {
1.257 albertel 3837: $datatoken=$env{'form.datatoken'};
1.41 ng 3838: &Apache::loncommon::load_tmp_file($request);
1.26 albertel 3839: }
1.41 ng 3840: my @records=&Apache::loncommon::upfile_record_sep();
1.257 albertel 3841: if ($env{'form.noFirstLine'}) { shift(@records); }
1.324 albertel 3842: &csvuploadmap_header($request,$symb,$datatoken,$#records+1);
1.41 ng 3843: my ($i,$keyfields);
3844: if (@records) {
1.324 albertel 3845: my @fields=&csvupload_fields($symb);
1.45 ng 3846:
1.257 albertel 3847: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3848: &Apache::loncommon::csv_print_samples($request,\@records);
3849: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
3850: \@fields);
3851: foreach (@fields) { $keyfields.=$_->[0].','; }
3852: chop($keyfields);
3853: } else {
3854: unshift(@fields,['none','']);
3855: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
3856: \@fields);
1.311 banghart 3857: foreach my $rec (@records) {
3858: my %temp = &Apache::loncommon::record_sep($rec);
3859: if (%temp) {
3860: $keyfields=join(',',sort(keys(%temp)));
3861: last;
3862: }
3863: }
1.41 ng 3864: }
3865: }
3866: &csvuploadmap_footer($request,$i,$keyfields);
1.324 albertel 3867: $request->print(&show_grading_menu_form($symb));
1.72 ng 3868:
1.41 ng 3869: return '';
1.27 albertel 3870: }
3871:
1.246 albertel 3872: sub csvuploadoptions {
1.41 ng 3873: my ($request)= @_;
1.324 albertel 3874: my ($symb)=&get_symb($request);
1.257 albertel 3875: my $checked=(($env{'form.noFirstLine'})?'1':'0');
1.246 albertel 3876: my $ignore=&mt('Ignore First Line');
3877: $request->print(<<ENDPICK);
3878: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.398 albertel 3879: <h3><span class="LC_info">Uploading Class Grade Options</span></h3>
1.246 albertel 3880: <input type="hidden" name="command" value="csvuploadassign" />
1.302 albertel 3881: <!--
1.246 albertel 3882: <p>
3883: <label>
3884: <input type="checkbox" name="show_full_results" />
3885: Show a table of all changes
3886: </label>
3887: </p>
1.302 albertel 3888: -->
1.246 albertel 3889: <p>
3890: <label>
3891: <input type="checkbox" name="overwite_scores" checked="checked" />
3892: Overwrite any existing score
3893: </label>
3894: </p>
3895: ENDPICK
3896: my %fields=&get_fields();
3897: if (!defined($fields{'domain'})) {
1.257 albertel 3898: my $domform = &Apache::loncommon::select_dom_form($env{'request.role.domain'},'default_domain');
1.246 albertel 3899: $request->print("\n<p> Users are in domain: ".$domform."</p>\n");
3900: }
1.257 albertel 3901: foreach my $key (sort(keys(%env))) {
1.246 albertel 3902: if ($key !~ /^form\.(.*)$/) { next; }
3903: my $cleankey=$1;
3904: if ($cleankey eq 'command') { next; }
3905: $request->print('<input type="hidden" name="'.$cleankey.
1.257 albertel 3906: '" value="'.$env{$key}.'" />'."\n");
1.246 albertel 3907: }
3908: # FIXME do a check for any duplicated user ids...
3909: # FIXME do a check for any invalid user ids?...
1.290 albertel 3910: $request->print('<input type="submit" value="Assign Grades" /><br />
3911: <hr /></form>'."\n");
1.324 albertel 3912: $request->print(&show_grading_menu_form($symb));
1.246 albertel 3913: return '';
3914: }
3915:
3916: sub get_fields {
3917: my %fields;
1.257 albertel 3918: my @keyfields = split(/\,/,$env{'form.keyfields'});
3919: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
3920: if ($env{'form.upfile_associate'} eq 'reverse') {
3921: if ($env{'form.f'.$i} ne 'none') {
3922: $fields{$keyfields[$i]}=$env{'form.f'.$i};
1.41 ng 3923: }
3924: } else {
1.257 albertel 3925: if ($env{'form.f'.$i} ne 'none') {
3926: $fields{$env{'form.f'.$i}}=$keyfields[$i];
1.41 ng 3927: }
3928: }
1.27 albertel 3929: }
1.246 albertel 3930: return %fields;
3931: }
3932:
3933: sub csvuploadassign {
3934: my ($request)= @_;
1.324 albertel 3935: my ($symb)=&get_symb($request);
1.246 albertel 3936: if (!$symb) {return '';}
1.345 bowersj2 3937: my $error_msg = '';
1.246 albertel 3938: &Apache::loncommon::load_tmp_file($request);
3939: my @gradedata = &Apache::loncommon::upfile_record_sep();
1.257 albertel 3940: if ($env{'form.noFirstLine'}) { shift(@gradedata); }
1.246 albertel 3941: my %fields=&get_fields();
1.41 ng 3942: $request->print('<h3>Assigning Grades</h3>');
1.257 albertel 3943: my $courseid=$env{'request.course.id'};
1.97 albertel 3944: my ($classlist) = &getclasslist('all',0);
1.106 albertel 3945: my @notallowed;
1.41 ng 3946: my @skipped;
3947: my $countdone=0;
3948: foreach my $grade (@gradedata) {
3949: my %entries=&Apache::loncommon::record_sep($grade);
1.246 albertel 3950: my $domain;
3951: if ($entries{$fields{'domain'}}) {
3952: $domain=$entries{$fields{'domain'}};
3953: } else {
1.257 albertel 3954: $domain=$env{'form.default_domain'};
1.246 albertel 3955: }
1.243 albertel 3956: $domain=~s/\s//g;
1.41 ng 3957: my $username=$entries{$fields{'username'}};
1.160 albertel 3958: $username=~s/\s//g;
1.243 albertel 3959: if (!$username) {
3960: my $id=$entries{$fields{'ID'}};
1.247 albertel 3961: $id=~s/\s//g;
1.243 albertel 3962: my %ids=&Apache::lonnet::idget($domain,$id);
3963: $username=$ids{$id};
3964: }
1.41 ng 3965: if (!exists($$classlist{"$username:$domain"})) {
1.247 albertel 3966: my $id=$entries{$fields{'ID'}};
3967: $id=~s/\s//g;
3968: if ($id) {
3969: push(@skipped,"$id:$domain");
3970: } else {
3971: push(@skipped,"$username:$domain");
3972: }
1.41 ng 3973: next;
3974: }
1.108 albertel 3975: my $usec=$classlist->{"$username:$domain"}[5];
1.106 albertel 3976: if (!&canmodify($usec)) {
3977: push(@notallowed,"$username:$domain");
3978: next;
3979: }
1.244 albertel 3980: my %points;
1.41 ng 3981: my %grades;
3982: foreach my $dest (keys(%fields)) {
1.244 albertel 3983: if ($dest eq 'ID' || $dest eq 'username' ||
3984: $dest eq 'domain') { next; }
3985: if ($entries{$fields{$dest}} =~ /^\s*$/) { next; }
3986: if ($dest=~/stores_(.*)_points/) {
3987: my $part=$1;
3988: my $wgt =&Apache::lonnet::EXT('resource.'.$part.'.weight',
3989: $symb,$domain,$username);
1.345 bowersj2 3990: if ($wgt) {
3991: $entries{$fields{$dest}}=~s/\s//g;
3992: my $pcr=$entries{$fields{$dest}} / $wgt;
1.463 albertel 3993: my $award=($pcr == 0) ? 'incorrect_by_override'
3994: : 'correct_by_override';
1.345 bowersj2 3995: $grades{"resource.$part.awarded"}=$pcr;
3996: $grades{"resource.$part.solved"}=$award;
3997: $points{$part}=1;
3998: } else {
3999: $error_msg = "<br />" .
4000: &mt("Some point values were assigned"
4001: ." for problems with a weight "
4002: ."of zero. These values were "
4003: ."ignored.");
4004: }
1.244 albertel 4005: } else {
4006: if ($dest=~/stores_(.*)_awarded/) { if ($points{$1}) {next;} }
4007: if ($dest=~/stores_(.*)_solved/) { if ($points{$1}) {next;} }
4008: my $store_key=$dest;
4009: $store_key=~s/^stores/resource/;
4010: $store_key=~s/_/\./g;
4011: $grades{$store_key}=$entries{$fields{$dest}};
4012: }
1.41 ng 4013: }
1.508 www 4014: if (! %grades) {
4015: push(@skipped,&mt("[_1]: no data to save","$username:$domain"));
4016: } else {
4017: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
4018: my $result=&Apache::lonnet::cstore(\%grades,$symb,
1.302 albertel 4019: $env{'request.course.id'},
4020: $domain,$username);
1.508 www 4021: if ($result eq 'ok') {
4022: $request->print('.');
4023: } else {
4024: $request->print("<p><span class=\"LC_error\">".
4025: &mt("Failed to save data for student [_1]. Message when trying to save was: [_2]",
4026: "$username:$domain",$result)."</span></p>");
4027: }
4028: $request->rflush();
4029: $countdone++;
4030: }
1.41 ng 4031: }
1.508 www 4032: $request->print('<br /><span class="LC_info">'.&mt("Saved [_1] students",$countdone)."</span>\n");
1.41 ng 4033: if (@skipped) {
1.508 www 4034: $request->print('<p><span class="LC_warning">'.&mt('Skipped Students').'</span></p>');
1.106 albertel 4035: foreach my $student (@skipped) { $request->print("$student<br />\n"); }
4036: }
4037: if (@notallowed) {
1.508 www 4038: $request->print('<p><span class="LC_error">'.&mt('Students Not Allowed to Modify').'</span></p>');
1.106 albertel 4039: foreach my $student (@notallowed) { $request->print("$student<br />\n"); }
1.41 ng 4040: }
1.106 albertel 4041: $request->print("<br />\n");
1.324 albertel 4042: $request->print(&show_grading_menu_form($symb));
1.345 bowersj2 4043: return $error_msg;
1.26 albertel 4044: }
1.44 ng 4045: #------------- end of section for handling csv file upload ---------
4046: #
4047: #-------------------------------------------------------------------
4048: #
1.122 ng 4049: #-------------- Next few routines handle grading by page/sequence
1.72 ng 4050: #
4051: #--- Select a page/sequence and a student to grade
1.68 ng 4052: sub pickStudentPage {
4053: my ($request) = shift;
4054:
1.539 ! riegler 4055: my $alertmsg = &mt('Please select the student you wish to grade.');
1.68 ng 4056: $request->print(<<LISTJAVASCRIPT);
4057: <script type="text/javascript" language="javascript">
4058:
4059: function checkPickOne(formname) {
1.76 ng 4060: if (radioSelection(formname.student) == null) {
1.539 ! riegler 4061: alert("$alertmsg");
1.68 ng 4062: return;
4063: }
1.125 ng 4064: ptr = pullDownSelection(formname.selectpage);
4065: formname.page.value = formname["page"+ptr].value;
4066: formname.title.value = formname["title"+ptr].value;
1.68 ng 4067: formname.submit();
4068: }
4069:
4070: </script>
4071: LISTJAVASCRIPT
1.118 ng 4072: &commonJSfunctions($request);
1.324 albertel 4073: my ($symb) = &get_symb($request);
1.257 albertel 4074: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4075: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4076: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.68 ng 4077:
1.398 albertel 4078: my $result='<h3><span class="LC_info"> '.
1.485 albertel 4079: &mt('Manual Grading by Page or Sequence').'</span></h3>';
1.68 ng 4080:
1.80 ng 4081: $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
1.423 albertel 4082: my ($titles,$symbx) = &getSymbMap();
1.137 albertel 4083: my ($curpage) =&Apache::lonnet::decode_symb($symb);
4084: # my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb);
4085: # my $type=($curpage =~ /\.(page|sequence)/);
1.485 albertel 4086: my $select = '<select name="selectpage">'."\n";
1.70 ng 4087: my $ctr=0;
1.68 ng 4088: foreach (@$titles) {
4089: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.485 albertel 4090: $select.='<option value="'.$ctr.'" '.
1.401 albertel 4091: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.71 ng 4092: '>'.$showtitle.'</option>'."\n";
1.70 ng 4093: $ctr++;
1.68 ng 4094: }
1.485 albertel 4095: $select.= '</select>';
1.539 ! riegler 4096: $result.=' <b>'.&mt('Problems from').':</b> '.$select."<br />\n";
1.485 albertel 4097:
1.70 ng 4098: $ctr=0;
4099: foreach (@$titles) {
4100: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
4101: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
4102: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
4103: $ctr++;
4104: }
1.72 ng 4105: $result.='<input type="hidden" name="page" />'."\n".
4106: '<input type="hidden" name="title" />'."\n";
1.68 ng 4107:
1.485 albertel 4108: my $options =
4109: '<label><input type="radio" name="vProb" value="no" checked="checked" /> '.&mt('no').' </label>'."\n".
4110: '<label><input type="radio" name="vProb" value="yes" /> '.&mt('yes').' </label>'."<br />\n";
1.539 ! riegler 4111: $result.=' <b>'.&mt('View Problem Text').': </b>'.$options;
1.485 albertel 4112:
4113: $options =
4114: '<label><input type="radio" name="lastSub" value="none" /> '.&mt('none').' </label>'."\n".
4115: '<label><input type="radio" name="lastSub" value="datesub" checked="checked" /> '.&mt('by dates and submissions').'</label>'."\n".
4116: '<label><input type="radio" name="lastSub" value="all" /> '.&mt('all details').' </label>'."\n";
1.539 ! riegler 4117: $result.=' <b>'.&mt('Submissions').': </b>'.$options;
1.432 banghart 4118:
4119: $result.=&build_section_inputs();
1.442 banghart 4120: my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
4121: $result.='<input type="hidden" name="Status" value="'.$stu_status.'" />'."\n".
1.72 ng 4122: '<input type="hidden" name="command" value="displayPage" />'."\n".
1.418 albertel 4123: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 4124: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."<br />\n";
1.72 ng 4125:
1.539 ! riegler 4126: $result.=' <b>'.&mt('Use CODE').': </b> <input type="text" name="CODE" value="" /> <br />'."\n";
1.382 albertel 4127:
1.80 ng 4128: $result.=' <input type="button" '.
1.539 ! riegler 4129: 'onClick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /><br />'."\n";
1.72 ng 4130:
1.68 ng 4131: $request->print($result);
4132:
1.485 albertel 4133: my $studentTable.=' <b>'.&mt('Select a student you wish to grade and then click on the Next button.').'</b><br />'.
1.484 albertel 4134: &Apache::loncommon::start_data_table().
4135: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 4136: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 4137: '<th>'.&nameUserString('header').'</th>'.
1.485 albertel 4138: '<th align="right"> '.&mt('No.').'</th>'.
1.484 albertel 4139: '<th>'.&nameUserString('header').'</th>'.
4140: &Apache::loncommon::end_data_table_header_row();
1.68 ng 4141:
1.76 ng 4142: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.68 ng 4143: my $ptr = 1;
1.294 albertel 4144: foreach my $student (sort
4145: {
4146: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
4147: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
4148: }
4149: return $a cmp $b;
4150: } (keys(%$fullname))) {
1.68 ng 4151: my ($uname,$udom) = split(/:/,$student);
1.484 albertel 4152: $studentTable.=($ptr%2==1 ? &Apache::loncommon::start_data_table_row()
4153: : '</td>');
1.126 ng 4154: $studentTable.='<td align="right">'.$ptr.' </td>';
1.288 albertel 4155: $studentTable.='<td> <label><input type="radio" name="student" value="'.$student.'" /> '
4156: .&nameUserString(undef,$$fullname{$student},$uname,$udom)."</label>\n";
1.484 albertel 4157: $studentTable.=
4158: ($ptr%2 == 0 ? '</td>'.&Apache::loncommon::end_data_table_row()
4159: : '');
1.68 ng 4160: $ptr++;
4161: }
1.484 albertel 4162: if ($ptr%2 == 0) {
4163: $studentTable.='</td><td> </td><td> </td>'.
4164: &Apache::loncommon::end_data_table_row();
4165: }
4166: $studentTable.=&Apache::loncommon::end_data_table()."\n";
1.126 ng 4167: $studentTable.='<input type="button" '.
1.539 ! riegler 4168: 'onClick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /></form>'."\n";
1.68 ng 4169:
1.324 albertel 4170: $studentTable.=&show_grading_menu_form($symb);
1.68 ng 4171: $request->print($studentTable);
4172:
4173: return '';
4174: }
4175:
4176: sub getSymbMap {
1.132 bowersj2 4177: my $navmap = Apache::lonnavmaps::navmap->new();
1.68 ng 4178:
4179: my %symbx = ();
4180: my @titles = ();
1.117 bowersj2 4181: my $minder = 0;
4182:
4183: # Gather every sequence that has problems.
1.240 albertel 4184: my @sequences = $navmap->retrieveResources(undef, sub { shift->is_map(); },
4185: 1,0,1);
1.117 bowersj2 4186: for my $sequence ($navmap->getById('0.0'), @sequences) {
1.241 albertel 4187: if ($navmap->hasResource($sequence, sub { shift->is_problem(); }, 0) ) {
1.381 albertel 4188: my $title = $minder.'.'.
4189: &HTML::Entities::encode($sequence->compTitle(),'"\'&');
4190: push(@titles, $title); # minder in case two titles are identical
4191: $symbx{$title} = &HTML::Entities::encode($sequence->symb(),'"\'&');
1.117 bowersj2 4192: $minder++;
1.241 albertel 4193: }
1.68 ng 4194: }
4195: return \@titles,\%symbx;
4196: }
4197:
1.72 ng 4198: #
4199: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68 ng 4200: sub displayPage {
4201: my ($request) = shift;
4202:
1.324 albertel 4203: my ($symb) = &get_symb($request);
1.257 albertel 4204: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4205: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4206: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
4207: my $pageTitle = $env{'form.page'};
1.103 albertel 4208: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 4209: my ($uname,$udom) = split(/:/,$env{'form.student'});
4210: my $usec=$classlist->{$env{'form.student'}}[5];
1.168 albertel 4211:
4212: #need to make sure we have the correct data for later EXT calls,
4213: #thus invalidate the cache
4214: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 4215: $env{'course.'.$env{'request.course.id'}.'.num'},
4216: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 4217: &Apache::lonnet::clear_EXT_cache_status();
4218:
1.103 albertel 4219: if (!&canview($usec)) {
1.485 albertel 4220: $request->print('<span class="LC_warning">'.&mt('Unable to view requested student. ([_1])',$env{'form.student'}).'</span>');
1.324 albertel 4221: $request->print(&show_grading_menu_form($symb));
1.103 albertel 4222: return;
4223: }
1.398 albertel 4224: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.485 albertel 4225: $result.='<h3> '.&mt('Student: [_1]',&nameUserString(undef,$$fullname{$env{'form.student'}},$uname,$udom)).
1.129 ng 4226: '</h3>'."\n";
1.500 albertel 4227: $env{'form.CODE'} = uc($env{'form.CODE'});
1.501 foxr 4228: if (&Apache::lonnet::validCODE(uc($env{'form.CODE'}))) {
1.485 albertel 4229: $result.='<h3> '.&mt('CODE: [_1]',$env{'form.CODE'}).'</h3>'."\n";
1.382 albertel 4230: } else {
4231: delete($env{'form.CODE'});
4232: }
1.71 ng 4233: &sub_page_js($request);
4234: $request->print($result);
4235:
1.132 bowersj2 4236: my $navmap = Apache::lonnavmaps::navmap->new();
1.257 albertel 4237: my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($env{'form.page'});
1.68 ng 4238: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 4239: if (!$map) {
1.485 albertel 4240: $request->print('<span class="LC_warning">'.&mt('Unable to view requested sequence. ([_1])',$resUrl).'</span>');
1.324 albertel 4241: $request->print(&show_grading_menu_form($symb));
1.288 albertel 4242: return;
4243: }
1.68 ng 4244: my $iterator = $navmap->getIterator($map->map_start(),
4245: $map->map_finish());
4246:
1.71 ng 4247: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72 ng 4248: '<input type="hidden" name="command" value="gradeByPage" />'."\n".
1.257 albertel 4249: '<input type="hidden" name="fullname" value="'.$$fullname{$env{'form.student'}}.'" />'."\n".
4250: '<input type="hidden" name="student" value="'.$env{'form.student'}.'" />'."\n".
1.72 ng 4251: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
1.257 albertel 4252: '<input type="hidden" name="title" value="'.$env{'form.title'}.'" />'."\n".
1.418 albertel 4253: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.125 ng 4254: '<input type="hidden" name="overRideScore" value="no" />'."\n".
1.257 albertel 4255: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n";
1.71 ng 4256:
1.382 albertel 4257: if (defined($env{'form.CODE'})) {
4258: $studentTable.=
4259: '<input type="hidden" name="CODE" value="'.$env{'form.CODE'}.'" />'."\n";
4260: }
1.381 albertel 4261: my $checkIcon = '<img alt="'.&mt('Check Mark').
1.485 albertel 4262: '" src="'.&Apache::loncommon::lonhttpdurl($request->dir_config('lonIconsURL').'/check.gif').'" height="16" border="0" />';
1.71 ng 4263:
1.485 albertel 4264: $studentTable.=' '.&mt('<b>Note:</b> Problems graded correct by the computer are marked with a [_1] symbol.',$checkIcon)."\n".
1.484 albertel 4265: &Apache::loncommon::start_data_table().
4266: &Apache::loncommon::start_data_table_header_row().
4267: '<th align="center"> Prob. </th>'.
1.485 albertel 4268: '<th> '.($env{'form.vProb'} eq 'no' ? &mt('Title') : &mt('Problem Text')).'/'.&mt('Grade').'</th>'.
1.484 albertel 4269: &Apache::loncommon::end_data_table_header_row();
1.71 ng 4270:
1.329 albertel 4271: &Apache::lonxml::clear_problem_counter();
1.196 albertel 4272: my ($depth,$question,$prob) = (1,1,1);
1.68 ng 4273: $iterator->next(); # skip the first BEGIN_MAP
4274: my $curRes = $iterator->next(); # for "current resource"
1.101 albertel 4275: while ($depth > 0) {
1.68 ng 4276: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4277: if($curRes == $iterator->END_MAP) { $depth--; }
1.68 ng 4278:
1.385 albertel 4279: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4280: my $parts = $curRes->parts();
1.68 ng 4281: my $title = $curRes->compTitle();
1.71 ng 4282: my $symbx = $curRes->symb();
1.484 albertel 4283: $studentTable.=
4284: &Apache::loncommon::start_data_table_row().
4285: '<td align="center" valign="top" >'.$prob.
1.485 albertel 4286: (scalar(@{$parts}) == 1 ? ''
4287: : '<br />('.&mt('[_1] parts)',
4288: scalar(@{$parts}))
4289: ).
4290: '</td>';
1.71 ng 4291: $studentTable.='<td valign="top">';
1.382 albertel 4292: my %form = ('CODE' => $env{'form.CODE'},);
1.257 albertel 4293: if ($env{'form.vProb'} eq 'yes' ) {
1.144 albertel 4294: $studentTable.=&show_problem($request,$symbx,$uname,$udom,1,
1.383 albertel 4295: undef,'both',\%form);
1.71 ng 4296: } else {
1.382 albertel 4297: my $companswer = &Apache::loncommon::get_student_answers($symbx,$uname,$udom,$env{'request.course.id'},%form);
1.80 ng 4298: $companswer =~ s|<form(.*?)>||g;
4299: $companswer =~ s|</form>||g;
1.71 ng 4300: # while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
1.116 ng 4301: # $companswer =~ s/$1/ /ms;
1.326 albertel 4302: # $request->print('match='.$1."<br />\n");
1.71 ng 4303: # }
1.116 ng 4304: # $companswer =~ s|<table border=\"1\">|<table border=\"0\">|g;
1.539 ! riegler 4305: $studentTable.=' <b>'.$title.'</b> <br /> <b>'.&mt('Correct answer').':</b><br />'.$companswer;
1.71 ng 4306: }
4307:
1.257 albertel 4308: my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
1.125 ng 4309:
1.257 albertel 4310: if ($env{'form.lastSub'} eq 'datesub') {
1.71 ng 4311: if ($record{'version'} eq '') {
1.485 albertel 4312: $studentTable.='<br /> <span class="LC_warning">'.&mt('No recorded submission for this problem.').'</span><br />';
1.71 ng 4313: } else {
1.116 ng 4314: my %responseType = ();
4315: foreach my $partid (@{$parts}) {
1.147 albertel 4316: my @responseIds =$curRes->responseIds($partid);
4317: my @responseType =$curRes->responseType($partid);
4318: my %responseIds;
4319: for (my $i=0;$i<=$#responseIds;$i++) {
4320: $responseIds{$responseIds[$i]}=$responseType[$i];
4321: }
4322: $responseType{$partid} = \%responseIds;
1.116 ng 4323: }
1.148 albertel 4324: $studentTable.= &displaySubByDates($symbx,\%record,$parts,\%responseType,$checkIcon,$uname,$udom);
1.147 albertel 4325:
1.71 ng 4326: }
1.257 albertel 4327: } elsif ($env{'form.lastSub'} eq 'all') {
4328: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.71 ng 4329: $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
1.257 albertel 4330: $env{'request.course.id'},
1.71 ng 4331: '','.submission');
4332:
4333: }
1.103 albertel 4334: if (&canmodify($usec)) {
4335: foreach my $partid (@{$parts}) {
4336: $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
4337: $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
4338: $question++;
4339: }
1.196 albertel 4340: $prob++;
1.71 ng 4341: }
4342: $studentTable.='</td></tr>';
1.68 ng 4343:
1.103 albertel 4344: }
1.68 ng 4345: $curRes = $iterator->next();
4346: }
4347:
1.485 albertel 4348: $studentTable.='</table>'."\n".
4349: '<input type="button" value="'.&mt('Save').'" '.
1.381 albertel 4350: 'onClick="javascript:checkSubmitPage(this.form,'.$question.');" />'.
1.71 ng 4351: '</form>'."\n";
1.324 albertel 4352: $studentTable.=&show_grading_menu_form($symb);
1.71 ng 4353: $request->print($studentTable);
4354:
4355: return '';
1.119 ng 4356: }
4357:
4358: sub displaySubByDates {
1.148 albertel 4359: my ($symb,$record,$parts,$responseType,$checkIcon,$uname,$udom) = @_;
1.224 albertel 4360: my $isCODE=0;
1.335 albertel 4361: my $isTask = ($symb =~/\.task$/);
1.224 albertel 4362: if (exists($record->{'resource.CODE'})) { $isCODE=1; }
1.467 albertel 4363: my $studentTable=&Apache::loncommon::start_data_table().
4364: &Apache::loncommon::start_data_table_header_row().
4365: '<th>'.&mt('Date/Time').'</th>'.
4366: ($isCODE?'<th>'.&mt('CODE').'</th>':'').
4367: '<th>'.&mt('Submission').'</th>'.
4368: '<th>'.&mt('Status').'</th>'.
4369: &Apache::loncommon::end_data_table_header_row();
1.119 ng 4370: my ($version);
4371: my %mark;
1.148 albertel 4372: my %orders;
1.119 ng 4373: $mark{'correct_by_student'} = $checkIcon;
1.147 albertel 4374: if (!exists($$record{'1:timestamp'})) {
1.539 ! riegler 4375: return '<br /> <span class="LC_warning">'.&mt('Nothing submitted - no attempts.').'</span><br />';
1.147 albertel 4376: }
1.335 albertel 4377:
4378: my $interaction;
1.525 raeburn 4379: my $no_increment = 1;
1.119 ng 4380: for ($version=1;$version<=$$record{'version'};$version++) {
1.467 albertel 4381: my $timestamp =
4382: &Apache::lonlocal::locallocaltime($$record{$version.':timestamp'});
1.335 albertel 4383: if (exists($$record{$version.':resource.0.version'})) {
4384: $interaction = $$record{$version.':resource.0.version'};
4385: }
4386:
4387: my $where = ($isTask ? "$version:resource.$interaction"
4388: : "$version:resource");
1.467 albertel 4389: $studentTable.=&Apache::loncommon::start_data_table_row().
4390: '<td>'.$timestamp.'</td>';
1.224 albertel 4391: if ($isCODE) {
4392: $studentTable.='<td>'.$record->{$version.':resource.CODE'}.'</td>';
4393: }
1.119 ng 4394: my @versionKeys = split(/\:/,$$record{$version.':keys'});
4395: my @displaySub = ();
4396: foreach my $partid (@{$parts}) {
1.335 albertel 4397: my @matchKey = ($isTask ? sort(grep /^resource\.\d+\.\Q$partid\E\.award$/,@versionKeys)
4398: : sort(grep /^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys));
4399:
4400:
1.122 ng 4401: # next if ($$record{"$version:resource.$partid.solved"} eq '');
1.324 albertel 4402: my $display_part=&get_display_part($partid,$symb);
1.147 albertel 4403: foreach my $matchKey (@matchKey) {
1.198 albertel 4404: if (exists($$record{$version.':'.$matchKey}) &&
4405: $$record{$version.':'.$matchKey} ne '') {
1.335 albertel 4406:
4407: my ($responseId)= ($isTask ? ($matchKey=~ /^resource\.(.*?)\.\Q$partid\E\.award$/)
4408: : ($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/));
1.467 albertel 4409: $displaySub[0].='<b>'.&mt('Part:').'</b> '.$display_part.' ';
4410: $displaySub[0].='<span class="LC_internal_info">('.&mt('ID').' '.
1.398 albertel 4411: $responseId.')</span> <b>';
1.335 albertel 4412: if ($$record{"$where.$partid.tries"} eq '') {
1.467 albertel 4413: $displaySub[0].=&mt('Trial not counted');
1.147 albertel 4414: } else {
1.467 albertel 4415: $displaySub[0].=&mt('Trial [_1]',
4416: $$record{"$where.$partid.tries"});
1.147 albertel 4417: }
1.335 albertel 4418: my $responseType=($isTask ? 'Task'
4419: : $responseType->{$partid}->{$responseId});
1.148 albertel 4420: if (!exists($orders{$partid})) { $orders{$partid}={}; }
4421: if (!exists($orders{$partid}->{$responseId})) {
4422: $orders{$partid}->{$responseId}=
1.525 raeburn 4423: &get_order($partid,$responseId,$symb,$uname,$udom,
4424: $no_increment);
1.148 albertel 4425: }
1.147 albertel 4426: $displaySub[0].='</b> '.
1.336 albertel 4427: &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:",$uname,$udom).'<br />';
1.147 albertel 4428: }
4429: }
1.335 albertel 4430: if (exists($$record{"$where.$partid.checkedin"})) {
1.485 albertel 4431: $displaySub[1].=&mt('Checked in by [_1] into slot [_2]',
4432: $$record{"$where.$partid.checkedin"},
4433: $$record{"$where.$partid.checkedin.slot"}).
4434: '<br />';
1.335 albertel 4435: }
4436: if (exists $$record{"$where.$partid.award"}) {
1.485 albertel 4437: $displaySub[1].='<b>'.&mt('Part:').'</b> '.$display_part.' '.
1.335 albertel 4438: lc($$record{"$where.$partid.award"}).' '.
4439: $mark{$$record{"$where.$partid.solved"}}.
1.147 albertel 4440: '<br />';
4441: }
1.335 albertel 4442: if (exists $$record{"$where.$partid.regrader"}) {
4443: $displaySub[2].=$$record{"$where.$partid.regrader"}.
4444: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
4445: } elsif ($$record{"$version:resource.$partid.regrader"} =~ /\S/) {
4446: $displaySub[2].=
4447: $$record{"$version:resource.$partid.regrader"}.
1.207 albertel 4448: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
1.147 albertel 4449: }
4450: }
4451: # needed because old essay regrader has not parts info
4452: if (exists $$record{"$version:resource.regrader"}) {
4453: $displaySub[2].=$$record{"$version:resource.regrader"};
4454: }
4455: $studentTable.='<td>'.$displaySub[0].' </td><td>'.$displaySub[1];
4456: if ($displaySub[2]) {
1.467 albertel 4457: $studentTable.=&mt('Manually graded by [_1]',$displaySub[2]);
1.147 albertel 4458: }
1.467 albertel 4459: $studentTable.=' </td>'.
4460: &Apache::loncommon::end_data_table_row();
1.119 ng 4461: }
1.467 albertel 4462: $studentTable.=&Apache::loncommon::end_data_table();
1.119 ng 4463: return $studentTable;
1.71 ng 4464: }
4465:
4466: sub updateGradeByPage {
4467: my ($request) = shift;
4468:
1.257 albertel 4469: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
4470: my $cnum = $env{"course.$env{'request.course.id'}.num"};
4471: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
4472: my $pageTitle = $env{'form.page'};
1.103 albertel 4473: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 4474: my ($uname,$udom) = split(/:/,$env{'form.student'});
4475: my $usec=$classlist->{$env{'form.student'}}[5];
1.103 albertel 4476: if (!&canmodify($usec)) {
1.526 raeburn 4477: $request->print('<span class="LC_warning">'.&mt('Unable to modify requested student ([_1])',$env{'form.student'}).'</span>');
1.324 albertel 4478: $request->print(&show_grading_menu_form($env{'form.symb'}));
1.103 albertel 4479: return;
4480: }
1.398 albertel 4481: my $result='<h3><span class="LC_info"> '.$env{'form.title'}.'</span></h3>';
1.526 raeburn 4482: $result.='<h3> '.&mt('Student: ').&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
1.129 ng 4483: '</h3>'."\n";
1.70 ng 4484:
1.68 ng 4485: $request->print($result);
4486:
1.132 bowersj2 4487: my $navmap = Apache::lonnavmaps::navmap->new();
1.257 albertel 4488: my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $env{'form.page'});
1.71 ng 4489: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 4490: if (!$map) {
1.527 raeburn 4491: $request->print('<span class="LC_warning">'.&mt('Unable to grade requested sequence ([_1]).',$resUrl).'</span>');
1.324 albertel 4492: my ($symb)=&get_symb($request);
4493: $request->print(&show_grading_menu_form($symb));
1.288 albertel 4494: return;
4495: }
1.71 ng 4496: my $iterator = $navmap->getIterator($map->map_start(),
4497: $map->map_finish());
1.70 ng 4498:
1.484 albertel 4499: my $studentTable=
4500: &Apache::loncommon::start_data_table().
4501: &Apache::loncommon::start_data_table_header_row().
1.485 albertel 4502: '<th align="center"> '.&mt('Prob.').' </th>'.
4503: '<th> '.&mt('Title').' </th>'.
4504: '<th> '.&mt('Previous Score').' </th>'.
4505: '<th> '.&mt('New Score').' </th>'.
1.484 albertel 4506: &Apache::loncommon::end_data_table_header_row();
1.71 ng 4507:
4508: $iterator->next(); # skip the first BEGIN_MAP
4509: my $curRes = $iterator->next(); # for "current resource"
1.196 albertel 4510: my ($depth,$question,$prob,$changeflag)= (1,1,1,0);
1.101 albertel 4511: while ($depth > 0) {
1.71 ng 4512: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 4513: if($curRes == $iterator->END_MAP) { $depth--; }
1.71 ng 4514:
1.385 albertel 4515: if (ref($curRes) && $curRes->is_problem()) {
1.91 albertel 4516: my $parts = $curRes->parts();
1.71 ng 4517: my $title = $curRes->compTitle();
4518: my $symbx = $curRes->symb();
1.484 albertel 4519: $studentTable.=
4520: &Apache::loncommon::start_data_table_row().
4521: '<td align="center" valign="top" >'.$prob.
1.485 albertel 4522: (scalar(@{$parts}) == 1 ? ''
1.526 raeburn 4523: : '<br />('.&mt('[quant,_1, part]',scalar(@{$parts}))
4524: .')').'</td>';
1.71 ng 4525: $studentTable.='<td valign="top"> <b>'.$title.'</b> </td>';
4526:
4527: my %newrecord=();
4528: my @displayPts=();
1.269 raeburn 4529: my %aggregate = ();
4530: my $aggregateflag = 0;
1.71 ng 4531: foreach my $partid (@{$parts}) {
1.257 albertel 4532: my $newpts = $env{'form.GD_BOX'.$question.'_'.$partid};
4533: my $oldpts = $env{'form.oldpts'.$question.'_'.$partid};
1.71 ng 4534:
1.257 albertel 4535: my $wgt = $env{'form.WGT'.$question.'_'.$partid} != 0 ?
4536: $env{'form.WGT'.$question.'_'.$partid} : 1;
1.71 ng 4537: my $partial = $newpts/$wgt;
4538: my $score;
4539: if ($partial > 0) {
4540: $score = 'correct_by_override';
1.125 ng 4541: } elsif ($newpts ne '') { #empty is taken as 0
1.71 ng 4542: $score = 'incorrect_by_override';
4543: }
1.257 albertel 4544: my $dropMenu = $env{'form.GD_SEL'.$question.'_'.$partid};
1.125 ng 4545: if ($dropMenu eq 'excused') {
1.71 ng 4546: $partial = '';
4547: $score = 'excused';
1.125 ng 4548: } elsif ($dropMenu eq 'reset status'
1.257 albertel 4549: && $env{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
1.125 ng 4550: $newrecord{'resource.'.$partid.'.tries'} = 0;
4551: $newrecord{'resource.'.$partid.'.solved'} = '';
4552: $newrecord{'resource.'.$partid.'.award'} = '';
4553: $newrecord{'resource.'.$partid.'.awarded'} = 0;
1.257 albertel 4554: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 4555: $changeflag++;
4556: $newpts = '';
1.269 raeburn 4557:
4558: my $aggtries = $env{'form.aggtries'.$question.'_'.$partid};
4559: my $totaltries = $env{'form.totaltries'.$question.'_'.$partid};
4560: my $solvedstatus = $env{'form.solved'.$question.'_'.$partid};
4561: if ($aggtries > 0) {
4562: &decrement_aggs($symbx,$partid,\%aggregate,$aggtries,$totaltries,$solvedstatus);
4563: $aggregateflag = 1;
4564: }
1.71 ng 4565: }
1.324 albertel 4566: my $display_part=&get_display_part($partid,$curRes->symb());
1.257 albertel 4567: my $oldstatus = $env{'form.solved'.$question.'_'.$partid};
1.526 raeburn 4568: $displayPts[0].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.71 ng 4569: (($oldstatus eq 'excused') ? 'excused' : $oldpts).
1.326 albertel 4570: ' <br />';
1.526 raeburn 4571: $displayPts[1].=' <b>'.&mt('Part').':</b> '.$display_part.' = '.
1.125 ng 4572: (($score eq 'excused') ? 'excused' : $newpts).
1.326 albertel 4573: ' <br />';
1.71 ng 4574: $question++;
1.380 albertel 4575: next if ($dropMenu eq 'reset status' || ($newpts eq $oldpts && $score ne 'excused'));
1.125 ng 4576:
1.71 ng 4577: $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
1.125 ng 4578: $newrecord{'resource.'.$partid.'.solved'} = $score if $score ne '';
1.257 albertel 4579: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}"
1.125 ng 4580: if (scalar(keys(%newrecord)) > 0);
1.71 ng 4581:
4582: $changeflag++;
4583: }
4584: if (scalar(keys(%newrecord)) > 0) {
1.382 albertel 4585: my %record =
4586: &Apache::lonnet::restore($symbx,$env{'request.course.id'},
4587: $udom,$uname);
4588:
4589: if (&Apache::lonnet::validCODE($env{'form.CODE'})) {
4590: $newrecord{'resource.CODE'} = $env{'form.CODE'};
4591: } elsif (&Apache::lonnet::validCODE($record{'resource.CODE'})) {
4592: $newrecord{'resource.CODE'} = '';
4593: }
1.257 albertel 4594: &Apache::lonnet::cstore(\%newrecord,$symbx,$env{'request.course.id'},
1.71 ng 4595: $udom,$uname);
1.382 albertel 4596: %record = &Apache::lonnet::restore($symbx,
4597: $env{'request.course.id'},
4598: $udom,$uname);
1.380 albertel 4599: &check_and_remove_from_queue($parts,\%record,undef,$symbx,
4600: $cdom,$cnum,$udom,$uname);
1.71 ng 4601: }
1.380 albertel 4602:
1.269 raeburn 4603: if ($aggregateflag) {
4604: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
4605: $env{'course.'.$env{'request.course.id'}.'.domain'},
4606: $env{'course.'.$env{'request.course.id'}.'.num'});
4607: }
1.125 ng 4608:
1.71 ng 4609: $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
4610: '<td valign="top">'.$displayPts[1].'</td>'.
1.484 albertel 4611: &Apache::loncommon::end_data_table_row();
1.68 ng 4612:
1.196 albertel 4613: $prob++;
1.68 ng 4614: }
1.71 ng 4615: $curRes = $iterator->next();
1.68 ng 4616: }
1.98 albertel 4617:
1.484 albertel 4618: $studentTable.=&Apache::loncommon::end_data_table();
1.324 albertel 4619: $studentTable.=&show_grading_menu_form($env{'form.symb'});
1.526 raeburn 4620: my $grademsg=($changeflag == 0 ? &mt('No score was changed or updated.') :
4621: &mt('The scores were changed for [quant,_1,problem].',
4622: $changeflag));
1.76 ng 4623: $request->print($grademsg.$studentTable);
1.68 ng 4624:
1.70 ng 4625: return '';
4626: }
4627:
1.72 ng 4628: #-------- end of section for handling grading by page/sequence ---------
4629: #
4630: #-------------------------------------------------------------------
4631:
1.75 albertel 4632: #--------------------Scantron Grading-----------------------------------
4633: #
4634: #------ start of section for handling grading by page/sequence ---------
4635:
1.423 albertel 4636: =pod
4637:
4638: =head1 Bubble sheet grading routines
4639:
1.424 albertel 4640: For this documentation:
4641:
4642: 'scanline' refers to the full line of characters
4643: from the file that we are parsing that represents one entire sheet
4644:
4645: 'bubble line' refers to the data
4646: representing the line of bubbles that are on the physical bubble sheet
4647:
4648:
4649: The overall process is that a scanned in bubble sheet data is uploaded
4650: into a course. When a user wants to grade, they select a
4651: sequence/folder of resources, a file of bubble sheet info, and pick
4652: one of the predefined configurations for what each scanline looks
4653: like.
4654:
4655: Next each scanline is checked for any errors of either 'missing
1.435 foxr 4656: bubbles' (it's an error because it may have been mis-scanned
1.424 albertel 4657: because too light bubbling), 'double bubble' (each bubble line should
4658: have no more that one letter picked), invalid or duplicated CODE,
4659: invalid student ID
4660:
4661: If the CODE option is used that determines the randomization of the
4662: homework problems, either way the student ID is looked up into a
4663: username:domain.
4664:
4665: During the validation phase the instructor can choose to skip scanlines.
4666:
1.435 foxr 4667: After the validation phase, there are now 3 bubble sheet files
1.424 albertel 4668:
4669: scantron_original_filename (unmodified original file)
4670: scantron_corrected_filename (file where the corrected information has replaced the original information)
4671: scantron_skipped_filename (contains the exact text of scanlines that where skipped)
4672:
4673: Also there is a separate hash nohist_scantrondata that contains extra
4674: correction information that isn't representable in the bubble sheet
4675: file (see &scantron_getfile() for more information)
4676:
4677: After all scanlines are either valid, marked as valid or skipped, then
4678: foreach line foreach problem in the picked sequence, an ssi request is
4679: made that simulates a user submitting their selected letter(s) against
4680: the homework problem.
1.423 albertel 4681:
4682: =over 4
4683:
4684:
4685:
4686: =item defaultFormData
4687:
4688: Returns html hidden inputs used to hold context/default values.
4689:
4690: Arguments:
4691: $symb - $symb of the current resource
4692:
4693: =cut
1.422 foxr 4694:
1.81 albertel 4695: sub defaultFormData {
1.324 albertel 4696: my ($symb)=@_;
1.447 foxr 4697: return '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 4698: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
4699: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.81 albertel 4700: }
4701:
1.447 foxr 4702:
1.423 albertel 4703: =pod
4704:
4705: =item getSequenceDropDown
4706:
4707: Return html dropdown of possible sequences to grade
4708:
4709: Arguments:
4710: $symb - $symb of the current resource
4711:
4712: =cut
1.422 foxr 4713:
1.75 albertel 4714: sub getSequenceDropDown {
1.423 albertel 4715: my ($symb)=@_;
1.75 albertel 4716: my $result='<select name="selectpage">'."\n";
1.423 albertel 4717: my ($titles,$symbx) = &getSymbMap();
1.137 albertel 4718: my ($curpage)=&Apache::lonnet::decode_symb($symb);
1.75 albertel 4719: my $ctr=0;
4720: foreach (@$titles) {
4721: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
4722: $result.='<option value="'.$$symbx{$_}.'" '.
1.401 albertel 4723: ($$symbx{$_} =~ /$curpage$/ ? 'selected="selected"' : '').
1.75 albertel 4724: '>'.$showtitle.'</option>'."\n";
4725: $ctr++;
4726: }
4727: $result.= '</select>';
4728: return $result;
4729: }
4730:
1.495 albertel 4731: my %bubble_lines_per_response; # no. bubble lines for each response.
4732: # index is "symb.part_id"
4733:
4734: my %first_bubble_line; # First bubble line no. for each bubble.
4735:
1.509 raeburn 4736: my %subdivided_bubble_lines; # no. bubble lines for optionresponse,
4737: # matchresponse or rankresponse, where
4738: # an individual response can have multiple
4739: # lines
1.503 raeburn 4740:
4741: my %responsetype_per_response; # responsetype for each response
4742:
1.495 albertel 4743: # Save and restore the bubble lines array to the form env.
4744:
4745:
4746: sub save_bubble_lines {
4747: foreach my $line (keys(%bubble_lines_per_response)) {
4748: $env{"form.scantron.bubblelines.$line"} = $bubble_lines_per_response{$line};
4749: $env{"form.scantron.first_bubble_line.$line"} =
4750: $first_bubble_line{$line};
1.503 raeburn 4751: $env{"form.scantron.sub_bubblelines.$line"} =
4752: $subdivided_bubble_lines{$line};
4753: $env{"form.scantron.responsetype.$line"} =
4754: $responsetype_per_response{$line};
1.495 albertel 4755: }
4756: }
4757:
4758:
4759: sub restore_bubble_lines {
4760: my $line = 0;
4761: %bubble_lines_per_response = ();
4762: while ($env{"form.scantron.bubblelines.$line"}) {
4763: my $value = $env{"form.scantron.bubblelines.$line"};
4764: $bubble_lines_per_response{$line} = $value;
4765: $first_bubble_line{$line} =
4766: $env{"form.scantron.first_bubble_line.$line"};
1.503 raeburn 4767: $subdivided_bubble_lines{$line} =
4768: $env{"form.scantron.sub_bubblelines.$line"};
4769: $responsetype_per_response{$line} =
4770: $env{"form.scantron.responsetype.$line"};
1.495 albertel 4771: $line++;
4772: }
4773:
4774: }
4775:
4776: # Given the parsed scanline, get the response for
4777: # 'answer' number n:
4778:
4779: sub get_response_bubbles {
4780: my ($parsed_line, $response) = @_;
4781:
4782:
4783: my $bubble_line = $first_bubble_line{$response-1} +1;
4784: my $bubble_lines= $bubble_lines_per_response{$response-1};
4785:
4786: my $selected = "";
4787:
4788: for (my $bline = 0; $bline < $bubble_lines; $bline++) {
4789: $selected .= $$parsed_line{"scantron.$bubble_line.answer"}.":";
4790: $bubble_line++;
4791: }
4792: return $selected;
4793: }
1.423 albertel 4794:
4795: =pod
4796:
4797: =item scantron_filenames
4798:
4799: Returns a list of the scantron files in the current course
4800:
4801: =cut
1.422 foxr 4802:
1.202 albertel 4803: sub scantron_filenames {
1.257 albertel 4804: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4805: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
1.517 raeburn 4806: my $getpropath = 1;
1.157 albertel 4807: my @files=&Apache::lonnet::dirlist('userfiles',$cdom,$cname,
1.517 raeburn 4808: $getpropath);
1.202 albertel 4809: my @possiblenames;
1.201 albertel 4810: foreach my $filename (sort(@files)) {
1.157 albertel 4811: ($filename)=split(/&/,$filename);
4812: if ($filename!~/^scantron_orig_/) { next ; }
4813: $filename=~s/^scantron_orig_//;
1.202 albertel 4814: push(@possiblenames,$filename);
4815: }
4816: return @possiblenames;
4817: }
4818:
1.423 albertel 4819: =pod
4820:
4821: =item scantron_uploads
4822:
4823: Returns html drop-down list of scantron files in current course.
4824:
4825: Arguments:
4826: $file2grade - filename to set as selected in the dropdown
4827:
4828: =cut
1.422 foxr 4829:
1.202 albertel 4830: sub scantron_uploads {
1.209 ng 4831: my ($file2grade) = @_;
1.202 albertel 4832: my $result= '<select name="scantron_selectfile">';
4833: $result.="<option></option>";
4834: foreach my $filename (sort(&scantron_filenames())) {
1.401 albertel 4835: $result.="<option".($filename eq $file2grade ? ' selected="selected"':'').">$filename</option>\n";
1.81 albertel 4836: }
4837: $result.="</select>";
4838: return $result;
4839: }
4840:
1.423 albertel 4841: =pod
4842:
4843: =item scantron_scantab
4844:
4845: Returns html drop down of the scantron formats in the scantronformat.tab
4846: file.
4847:
4848: =cut
1.422 foxr 4849:
1.82 albertel 4850: sub scantron_scantab {
4851: my $result='<select name="scantron_format">'."\n";
1.191 albertel 4852: $result.='<option></option>'."\n";
1.518 raeburn 4853: my @lines = &get_scantronformat_file();
4854: if (@lines > 0) {
4855: foreach my $line (@lines) {
4856: next if (($line =~ /^\#/) || ($line eq ''));
4857: my ($name,$descrip)=split(/:/,$line);
4858: $result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
4859: }
1.82 albertel 4860: }
4861: $result.='</select>'."\n";
1.518 raeburn 4862: return $result;
4863: }
4864:
4865: =pod
4866:
4867: =item get_scantronformat_file
4868:
4869: Returns an array containing lines from the scantron format file for
4870: the domain of the course.
4871:
4872: If a url for a custom.tab file is listed in domain's configuration.db,
4873: lines are from this file.
4874:
4875: Otherwise, if a default.tab has been published in RES space by the
4876: domainconfig user, lines are from this file.
4877:
4878: Otherwise, fall back to getting lines from the legacy file on the
1.519 raeburn 4879: local server: /home/httpd/lonTabs/default_scantronformat.tab
1.82 albertel 4880:
1.518 raeburn 4881: =cut
4882:
4883: sub get_scantronformat_file {
4884: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
4885: my %domconfig = &Apache::lonnet::get_dom('configuration',['scantron'],$cdom);
4886: my $gottab = 0;
4887: my @lines;
4888: if (ref($domconfig{'scantron'}) eq 'HASH') {
4889: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
4890: my $formatfile = &Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.$domconfig{'scantron'}{'scantronformat'});
4891: if ($formatfile ne '-1') {
4892: @lines = split("\n",$formatfile,-1);
4893: $gottab = 1;
4894: }
4895: }
4896: }
4897: if (!$gottab) {
4898: my $confname = $cdom.'-domainconfig';
4899: my $default = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res/'.$cdom.'/'.$confname.'/default.tab';
4900: my $formatfile = &Apache::lonnet::getfile($default);
4901: if ($formatfile ne '-1') {
4902: @lines = split("\n",$formatfile,-1);
4903: $gottab = 1;
4904: }
4905: }
4906: if (!$gottab) {
1.519 raeburn 4907: my @domains = &Apache::lonnet::current_machine_domains();
4908: if (grep(/^\Q$cdom\E$/,@domains)) {
4909: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
4910: @lines = <$fh>;
4911: close($fh);
4912: } else {
4913: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab');
4914: @lines = <$fh>;
4915: close($fh);
4916: }
1.518 raeburn 4917: }
4918: return @lines;
1.82 albertel 4919: }
4920:
1.423 albertel 4921: =pod
4922:
4923: =item scantron_CODElist
4924:
4925: Returns html drop down of the saved CODE lists from current course,
4926: generated from earlier printings.
4927:
4928: =cut
1.422 foxr 4929:
1.186 albertel 4930: sub scantron_CODElist {
1.257 albertel 4931: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4932: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.186 albertel 4933: my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
4934: my $namechoice='<option></option>';
1.225 albertel 4935: foreach my $name (sort {uc($a) cmp uc($b)} @names) {
1.191 albertel 4936: if ($name =~ /^error: 2 /) { next; }
1.278 albertel 4937: if ($name =~ /^type\0/) { next; }
1.186 albertel 4938: $namechoice.='<option value="'.$name.'">'.$name.'</option>';
4939: }
4940: $namechoice='<select name="scantron_CODElist">'.$namechoice.'</select>';
4941: return $namechoice;
4942: }
4943:
1.423 albertel 4944: =pod
4945:
4946: =item scantron_CODEunique
4947:
4948: Returns the html for "Each CODE to be used once" radio.
4949:
4950: =cut
1.422 foxr 4951:
1.186 albertel 4952: sub scantron_CODEunique {
1.532 bisitz 4953: my $result='<span class="LC_nobreak">
1.272 albertel 4954: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 4955: value="yes" checked="checked" />'.&mt('Yes').' </label>
1.381 albertel 4956: </span>
1.532 bisitz 4957: <span class="LC_nobreak">
1.272 albertel 4958: <label><input type="radio" name="scantron_CODEunique"
1.423 albertel 4959: value="no" />'.&mt('No').' </label>
1.381 albertel 4960: </span>';
1.186 albertel 4961: return $result;
4962: }
1.423 albertel 4963:
4964: =pod
4965:
4966: =item scantron_selectphase
4967:
4968: Generates the initial screen to start the bubble sheet process.
4969: Allows for - starting a grading run.
1.424 albertel 4970: - downloading existing scan data (original, corrected
1.423 albertel 4971: or skipped info)
4972:
4973: - uploading new scan data
4974:
4975: Arguments:
4976: $r - The Apache request object
4977: $file2grade - name of the file that contain the scanned data to score
4978:
4979: =cut
1.186 albertel 4980:
1.75 albertel 4981: sub scantron_selectphase {
1.209 ng 4982: my ($r,$file2grade) = @_;
1.324 albertel 4983: my ($symb)=&get_symb($r);
1.75 albertel 4984: if (!$symb) {return '';}
1.423 albertel 4985: my $sequence_selector=&getSequenceDropDown($symb);
1.324 albertel 4986: my $default_form_data=&defaultFormData($symb);
4987: my $grading_menu_button=&show_grading_menu_form($symb);
1.209 ng 4988: my $file_selector=&scantron_uploads($file2grade);
1.82 albertel 4989: my $format_selector=&scantron_scantab();
1.186 albertel 4990: my $CODE_selector=&scantron_CODElist();
4991: my $CODE_unique=&scantron_CODEunique();
1.75 albertel 4992: my $result;
1.422 foxr 4993:
1.513 foxr 4994: $ssi_error = 0;
4995:
1.422 foxr 4996: # Chunk of form to prompt for a file to grade and how:
4997:
1.489 albertel 4998: $result.= '
4999: <br />
5000: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantron_process">
5001: <input type="hidden" name="command" value="scantron_warning" />
5002: '.$default_form_data.'
5003: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5004: '.&Apache::loncommon::start_data_table_header_row().'
5005: <th colspan="2">
1.492 albertel 5006: '.&mt('Specify file and which Folder/Sequence to grade').'
1.489 albertel 5007: </th>
5008: '.&Apache::loncommon::end_data_table_header_row().'
5009: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5010: <td> '.&mt('Sequence to grade:').' </td><td> '.$sequence_selector.' </td>
1.489 albertel 5011: '.&Apache::loncommon::end_data_table_row().'
5012: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5013: <td> '.&mt('Filename of scoring office file:').' </td><td> '.$file_selector.' </td>
1.489 albertel 5014: '.&Apache::loncommon::end_data_table_row().'
5015: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5016: <td> '.&mt('Format of data file:').' </td><td> '.$format_selector.' </td>
1.489 albertel 5017: '.&Apache::loncommon::end_data_table_row().'
5018: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5019: <td> '.&mt('Saved CODEs to validate against:').' </td><td> '.$CODE_selector.' </td>
1.489 albertel 5020: '.&Apache::loncommon::end_data_table_row().'
5021: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5022: <td> '.&mt('Each CODE is only to be used once:').'</td><td> '.$CODE_unique.' </td>
1.489 albertel 5023: '.&Apache::loncommon::end_data_table_row().'
5024: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5025: <td> '.&mt('Options:').' </td>
1.187 albertel 5026: <td>
1.492 albertel 5027: <label><input type="checkbox" name="scantron_options_redo" value="redo_skipped"/> '.&mt('Do only previously skipped records').'</label> <br />
5028: <label><input type="checkbox" name="scantron_options_ignore" value="ignore_corrections"/> '.&mt('Remove all existing corrections').'</label> <br />
5029: <label><input type="checkbox" name="scantron_options_hidden" value="ignore_hidden"/> '.&mt('Skip hidden resources when grading').'</label>
1.187 albertel 5030: </td>
1.489 albertel 5031: '.&Apache::loncommon::end_data_table_row().'
5032: '.&Apache::loncommon::start_data_table_row().'
1.174 albertel 5033: <td colspan="2">
1.492 albertel 5034: <input type="submit" value="'.&mt('Grading: Validate Scantron Records').'" />
1.162 albertel 5035: </td>
1.489 albertel 5036: '.&Apache::loncommon::end_data_table_row().'
5037: '.&Apache::loncommon::end_data_table().'
5038: </form>
5039: ';
1.162 albertel 5040:
5041: $r->print($result);
5042:
1.257 albertel 5043: if (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) ||
5044: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.162 albertel 5045:
1.422 foxr 5046: # Chunk of form to prompt for a scantron file upload.
5047:
1.489 albertel 5048: $r->print('
5049: <br />
5050: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5051: '.&Apache::loncommon::start_data_table_header_row().'
5052: <th>
1.492 albertel 5053: '.&mt('Specify a Scantron data file to upload.').'
1.489 albertel 5054: </th>
5055: '.&Apache::loncommon::end_data_table_header_row().'
5056: '.&Apache::loncommon::start_data_table_row().'
1.162 albertel 5057: <td>
1.489 albertel 5058: ');
1.324 albertel 5059: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.257 albertel 5060: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
5061: my $cnum= $env{'course.'.$env{'request.course.id'}.'.num'};
1.492 albertel 5062: $r->print('
1.174 albertel 5063: <script type="text/javascript" language="javascript">
5064: function checkUpload(formname) {
5065: if (formname.upfile.value == "") {
1.492 albertel 5066: alert("'.&mt('Please use the browse button to select a file from your local directory.').'");
1.174 albertel 5067: return false;
5068: }
5069: formname.submit();
5070: }
5071: </script>
5072:
1.492 albertel 5073: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
5074: '.$default_form_data.'
5075: <input name="courseid" type="hidden" value="'.$cnum.'" />
5076: <input name="domainid" type="hidden" value="'.$cdom.'" />
5077: <input name="command" value="scantronupload_save" type="hidden" />
5078: '.&mt('File to upload: [_1]','<input type="file" name="upfile" size="50" />').'
1.174 albertel 5079: <br />
1.492 albertel 5080: <input type="button" onClick="javascript:checkUpload(this.form);" value="'.&mt('Upload Scantron Data').'" />
1.174 albertel 5081: </form>
1.492 albertel 5082: ');
1.162 albertel 5083:
1.489 albertel 5084: $r->print('
1.162 albertel 5085: </td>
1.489 albertel 5086: '.&Apache::loncommon::end_data_table_row().'
5087: '.&Apache::loncommon::end_data_table().'
5088: ');
1.162 albertel 5089: }
1.422 foxr 5090:
5091: # Chunk of the form that prompts to view a scoring office file,
5092: # corrected file, skipped records in a file.
5093:
1.489 albertel 5094: $r->print('
5095: <br />
5096: <form action="/adm/grades" name="scantron_download">
5097: '.$default_form_data.'
5098: <input type="hidden" name="command" value="scantron_download" />
5099: '.&Apache::loncommon::start_data_table('LC_scantron_action').'
5100: '.&Apache::loncommon::start_data_table_header_row().'
5101: <th>
1.492 albertel 5102: '.&mt('Download a scoring office file').'
1.489 albertel 5103: </th>
5104: '.&Apache::loncommon::end_data_table_header_row().'
5105: '.&Apache::loncommon::start_data_table_row().'
1.492 albertel 5106: <td> '.&mt('Filename of scoring office file: [_1]',$file_selector).'
1.489 albertel 5107: <br />
1.492 albertel 5108: <input type="submit" value="'.&mt('Download: Show List of Associated Files').'" />
1.489 albertel 5109: '.&Apache::loncommon::end_data_table_row().'
5110: '.&Apache::loncommon::end_data_table().'
5111: </form>
5112: <br />
5113: ');
1.162 albertel 5114:
1.457 banghart 5115: &Apache::lonpickcode::code_list($r,2);
1.523 raeburn 5116:
1.528 raeburn 5117: $r->print('<br /><form method="post" name="checkscantron">'.
1.523 raeburn 5118: $default_form_data."\n".
5119: &Apache::loncommon::start_data_table('LC_scantron_action')."\n".
5120: &Apache::loncommon::start_data_table_header_row()."\n".
5121: '<th colspan="2">
5122: '.&mt('Review scantron data and submissions for a previously graded folder/sequence')."\n".
5123: '</th>'."\n".
5124: &Apache::loncommon::end_data_table_header_row()."\n".
5125: &Apache::loncommon::start_data_table_row()."\n".
5126: '<td> '.&mt('Graded folder/sequence:').' </td>'."\n".
5127: '<td> '.$sequence_selector.' </td>'.
5128: &Apache::loncommon::end_data_table_row()."\n".
5129: &Apache::loncommon::start_data_table_row()."\n".
5130: '<td> '.&mt('Filename of scoring office file:').' </td>'."\n".
5131: '<td> '.$file_selector.' </td>'."\n".
5132: &Apache::loncommon::end_data_table_row()."\n".
5133: &Apache::loncommon::start_data_table_row()."\n".
5134: '<td> '.&mt('Format of data file:').' </td>'."\n".
5135: '<td> '.$format_selector.' </td>'."\n".
5136: &Apache::loncommon::end_data_table_row()."\n".
5137: &Apache::loncommon::start_data_table_row()."\n".
5138: '<td colspan="2">'."\n".
5139: '<input type="hidden" name="command" value="checksubmissions" />'."\n".
5140: '<input type="submit" value="'.&mt('Review Scantron Data and Submission Records').'" />'."\n".
5141: '</td>'."\n".
5142: &Apache::loncommon::end_data_table_row()."\n".
5143: &Apache::loncommon::end_data_table()."\n".
5144: '</form><br />');
1.457 banghart 5145: $r->print($grading_menu_button);
1.523 raeburn 5146: return;
1.75 albertel 5147: }
5148:
1.423 albertel 5149: =pod
5150:
5151: =item get_scantron_config
5152:
5153: Parse and return the scantron configuration line selected as a
5154: hash of configuration file fields.
5155:
5156: Arguments:
5157: which - the name of the configuration to parse from the file.
5158:
5159:
5160: Returns:
5161: If the named configuration is not in the file, an empty
5162: hash is returned.
5163: a hash with the fields
5164: name - internal name for the this configuration setup
5165: description - text to display to operator that describes this config
5166: CODElocation - if 0 or the string 'none'
5167: - no CODE exists for this config
5168: if -1 || the string 'letter'
5169: - a CODE exists for this config and is
5170: a string of letters
5171: Unsupported value (but planned for future support)
5172: if a positive integer
5173: - The CODE exists as the first n items from
5174: the question section of the form
5175: if the string 'number'
5176: - The CODE exists for this config and is
5177: a string of numbers
5178: CODEstart - (only matter if a CODE exists) column in the line where
5179: the CODE starts
5180: CODElength - length of the CODE
5181: IDstart - column where the student ID number starts
5182: IDlength - length of the student ID info
5183: Qstart - column where the information from the bubbled
5184: 'questions' start
5185: Qlength - number of columns comprising a single bubble line from
5186: the sheet. (usually either 1 or 10)
1.424 albertel 5187: Qon - either a single character representing the character used
1.423 albertel 5188: to signal a bubble was chosen in the positional setup, or
5189: the string 'letter' if the letter of the chosen bubble is
5190: in the final, or 'number' if a number representing the
5191: chosen bubble is in the file (1->A 0->J)
1.424 albertel 5192: Qoff - the character used to represent that a bubble was
5193: left blank
1.423 albertel 5194: PaperID - if the scanning process generates a unique number for each
5195: sheet scanned the column that this ID number starts in
5196: PaperIDlength - number of columns that comprise the unique ID number
5197: for the sheet of paper
1.424 albertel 5198: FirstName - column that the first name starts in
1.423 albertel 5199: FirstNameLength - number of columns that the first name spans
5200:
5201: LastName - column that the last name starts in
5202: LastNameLength - number of columns that the last name spans
5203:
5204: =cut
1.422 foxr 5205:
1.82 albertel 5206: sub get_scantron_config {
5207: my ($which) = @_;
1.518 raeburn 5208: my @lines = &get_scantronformat_file();
1.82 albertel 5209: my %config;
1.157 albertel 5210: #FIXME probably should move to XML it has already gotten a bit much now
1.518 raeburn 5211: foreach my $line (@lines) {
1.82 albertel 5212: my ($name,$descrip)=split(/:/,$line);
5213: if ($name ne $which ) { next; }
5214: chomp($line);
5215: my @config=split(/:/,$line);
5216: $config{'name'}=$config[0];
5217: $config{'description'}=$config[1];
5218: $config{'CODElocation'}=$config[2];
5219: $config{'CODEstart'}=$config[3];
5220: $config{'CODElength'}=$config[4];
5221: $config{'IDstart'}=$config[5];
5222: $config{'IDlength'}=$config[6];
5223: $config{'Qstart'}=$config[7];
1.497 foxr 5224: $config{'Qlength'}=$config[8];
1.82 albertel 5225: $config{'Qoff'}=$config[9];
5226: $config{'Qon'}=$config[10];
1.157 albertel 5227: $config{'PaperID'}=$config[11];
5228: $config{'PaperIDlength'}=$config[12];
5229: $config{'FirstName'}=$config[13];
5230: $config{'FirstNamelength'}=$config[14];
5231: $config{'LastName'}=$config[15];
5232: $config{'LastNamelength'}=$config[16];
1.82 albertel 5233: last;
5234: }
5235: return %config;
5236: }
5237:
1.423 albertel 5238: =pod
5239:
5240: =item username_to_idmap
5241:
5242: creates a hash keyed by student id with values of the corresponding
5243: student username:domain.
5244:
5245: Arguments:
5246:
5247: $classlist - reference to the class list hash. This is a hash
5248: keyed by student name:domain whose elements are references
1.424 albertel 5249: to arrays containing various chunks of information
1.423 albertel 5250: about the student. (See loncoursedata for more info).
5251:
5252: Returns
5253: %idmap - the constructed hash
5254:
5255: =cut
5256:
1.82 albertel 5257: sub username_to_idmap {
5258: my ($classlist)= @_;
5259: my %idmap;
5260: foreach my $student (keys(%$classlist)) {
5261: $idmap{$classlist->{$student}->[&Apache::loncoursedata::CL_ID]}=
5262: $student;
5263: }
5264: return %idmap;
5265: }
1.423 albertel 5266:
5267: =pod
5268:
1.424 albertel 5269: =item scantron_fixup_scanline
1.423 albertel 5270:
5271: Process a requested correction to a scanline.
5272:
5273: Arguments:
5274: $scantron_config - hash from &get_scantron_config()
5275: $scan_data - hash of correction information
5276: (see &scantron_getfile())
5277: $line - existing scanline
5278: $whichline - line number of the passed in scanline
5279: $field - type of change to process
5280: (either
5281: 'ID' -> correct the student ID number
5282: 'CODE' -> correct the CODE
5283: 'answer' -> fixup the submitted answers)
5284:
5285: $args - hash of additional info,
5286: - 'ID'
5287: 'newid' -> studentID to use in replacement
1.424 albertel 5288: of existing one
1.423 albertel 5289: - 'CODE'
5290: 'CODE_ignore_dup' - set to true if duplicates
5291: should be ignored.
5292: 'CODE' - is new code or 'use_unfound'
1.424 albertel 5293: if the existing unfound code should
1.423 albertel 5294: be used as is
5295: - 'answer'
5296: 'response' - new answer or 'none' if blank
5297: 'question' - the bubble line to change
1.503 raeburn 5298: 'questionnum' - the question identifier,
5299: may include subquestion.
1.423 albertel 5300:
5301: Returns:
5302: $line - the modified scanline
5303:
5304: Side effects:
5305: $scan_data - may be updated
5306:
5307: =cut
5308:
1.82 albertel 5309:
1.157 albertel 5310: sub scantron_fixup_scanline {
5311: my ($scantron_config,$scan_data,$line,$whichline,$field,$args)=@_;
5312: if ($field eq 'ID') {
5313: if (length($args->{'newid'}) > $$scantron_config{'IDlength'}) {
1.186 albertel 5314: return ($line,1,'New value too large');
1.157 albertel 5315: }
5316: if (length($args->{'newid'}) < $$scantron_config{'IDlength'}) {
5317: $args->{'newid'}=sprintf('%-'.$$scantron_config{'IDlength'}.'s',
5318: $args->{'newid'});
5319: }
5320: substr($line,$$scantron_config{'IDstart'}-1,
5321: $$scantron_config{'IDlength'})=$args->{'newid'};
5322: if ($args->{'newid'}=~/^\s*$/) {
5323: &scan_data($scan_data,"$whichline.user",
5324: $args->{'username'}.':'.$args->{'domain'});
5325: }
1.186 albertel 5326: } elsif ($field eq 'CODE') {
1.192 albertel 5327: if ($args->{'CODE_ignore_dup'}) {
5328: &scan_data($scan_data,"$whichline.CODE_ignore_dup",'1');
5329: }
5330: &scan_data($scan_data,"$whichline.useCODE",'1');
5331: if ($args->{'CODE'} ne 'use_unfound') {
1.191 albertel 5332: if (length($args->{'CODE'}) > $$scantron_config{'CODElength'}) {
5333: return ($line,1,'New CODE value too large');
5334: }
5335: if (length($args->{'CODE'}) < $$scantron_config{'CODElength'}) {
5336: $args->{'CODE'}=sprintf('%-'.$$scantron_config{'CODElength'}.'s',$args->{'CODE'});
5337: }
5338: substr($line,$$scantron_config{'CODEstart'}-1,
5339: $$scantron_config{'CODElength'})=$args->{'CODE'};
1.186 albertel 5340: }
1.157 albertel 5341: } elsif ($field eq 'answer') {
1.497 foxr 5342: my $length=$scantron_config->{'Qlength'};
1.157 albertel 5343: my $off=$scantron_config->{'Qoff'};
5344: my $on=$scantron_config->{'Qon'};
1.497 foxr 5345: my $answer=${off}x$length;
5346: if ($args->{'response'} eq 'none') {
5347: &scan_data($scan_data,
1.503 raeburn 5348: "$whichline.no_bubble.".$args->{'questionnum'},'1');
1.497 foxr 5349: } else {
5350: if ($on eq 'letter') {
5351: my @alphabet=('A'..'Z');
5352: $answer=$alphabet[$args->{'response'}];
5353: } elsif ($on eq 'number') {
5354: $answer=$args->{'response'}+1;
5355: if ($answer == 10) { $answer = '0'; }
1.274 albertel 5356: } else {
1.497 foxr 5357: substr($answer,$args->{'response'},1)=$on;
1.274 albertel 5358: }
1.497 foxr 5359: &scan_data($scan_data,
1.503 raeburn 5360: "$whichline.no_bubble.".$args->{'questionnum'},undef,'1');
1.157 albertel 5361: }
1.497 foxr 5362: my $where=$length*($args->{'question'}-1)+$scantron_config->{'Qstart'};
5363: substr($line,$where-1,$length)=$answer;
1.157 albertel 5364: }
5365: return $line;
5366: }
1.423 albertel 5367:
5368: =pod
5369:
5370: =item scan_data
5371:
5372: Edit or look up an item in the scan_data hash.
5373:
5374: Arguments:
5375: $scan_data - The hash (see scantron_getfile)
5376: $key - shorthand of the key to edit (actual key is
1.424 albertel 5377: scantronfilename_key).
1.423 albertel 5378: $data - New value of the hash entry.
5379: $delete - If true, the entry is removed from the hash.
5380:
5381: Returns:
5382: The new value of the hash table field (undefined if deleted).
5383:
5384: =cut
5385:
5386:
1.157 albertel 5387: sub scan_data {
5388: my ($scan_data,$key,$value,$delete)=@_;
1.257 albertel 5389: my $filename=$env{'form.scantron_selectfile'};
1.157 albertel 5390: if (defined($value)) {
5391: $scan_data->{$filename.'_'.$key} = $value;
5392: }
5393: if ($delete) { delete($scan_data->{$filename.'_'.$key}); }
5394: return $scan_data->{$filename.'_'.$key};
5395: }
1.423 albertel 5396:
1.495 albertel 5397: # ----- These first few routines are general use routines.----
5398:
5399: # Return the number of occurences of a pattern in a string.
5400:
5401: sub occurence_count {
5402: my ($string, $pattern) = @_;
5403:
5404: my @matches = ($string =~ /$pattern/g);
5405:
5406: return scalar(@matches);
5407: }
5408:
5409:
5410: # Take a string known to have digits and convert all the
5411: # digits into letters in the range J,A..I.
5412:
5413: sub digits_to_letters {
5414: my ($input) = @_;
5415:
5416: my @alphabet = ('J', 'A'..'I');
5417:
5418: my @input = split(//, $input);
5419: my $output ='';
5420: for (my $i = 0; $i < scalar(@input); $i++) {
5421: if ($input[$i] =~ /\d/) {
5422: $output .= $alphabet[$input[$i]];
5423: } else {
5424: $output .= $input[$i];
5425: }
5426: }
5427: return $output;
5428: }
5429:
1.423 albertel 5430: =pod
5431:
5432: =item scantron_parse_scanline
5433:
5434: Decodes a scanline from the selected scantron file
5435:
5436: Arguments:
5437: line - The text of the scantron file line to process
5438: whichline - Line number
5439: scantron_config - Hash describing the format of the scantron lines.
5440: scan_data - Hash of extra information about the scanline
5441: (see scantron_getfile for more information)
5442: just_header - True if should not process question answers but only
5443: the stuff to the left of the answers.
5444: Returns:
5445: Hash containing the result of parsing the scanline
5446:
5447: Keys are all proceeded by the string 'scantron.'
5448:
5449: CODE - the CODE in use for this scanline
5450: useCODE - 1 if the CODE is invalid but it usage has been forced
5451: by the operator
5452: CODE_ignore_dup - 1 if the CODE is a duplicated use when unique
5453: CODEs were selected, but the usage has been
5454: forced by the operator
5455: ID - student ID
5456: PaperID - if used, the ID number printed on the sheet when the
5457: paper was scanned
5458: FirstName - first name from the sheet
5459: LastName - last name from the sheet
5460:
5461: if just_header was not true these key may also exist
5462:
1.447 foxr 5463: missingerror - a list of bubble ranges that are considered to be answers
5464: to a single question that don't have any bubbles filled in.
5465: Of the form questionnumber:firstbubblenumber:count.
5466: doubleerror - a list of bubble ranges that are considered to be answers
5467: to a single question that have more than one bubble filled in.
5468: Of the form questionnumber::firstbubblenumber:count
5469:
5470: In the above, count is the number of bubble responses in the
5471: input line needed to represent the possible answers to the question.
5472: e.g. a radioresponse with 15 choices in an answer sheet with 10 choices
5473: per line would have count = 2.
5474:
1.423 albertel 5475: maxquest - the number of the last bubble line that was parsed
5476:
5477: (<number> starts at 1)
5478: <number>.answer - zero or more letters representing the selected
5479: letters from the scanline for the bubble line
5480: <number>.
5481: if blank there was either no bubble or there where
5482: multiple bubbles, (consult the keys missingerror and
5483: doubleerror if this is an error condition)
5484:
5485: =cut
5486:
1.82 albertel 5487: sub scantron_parse_scanline {
1.423 albertel 5488: my ($line,$whichline,$scantron_config,$scan_data,$just_header)=@_;
1.470 foxr 5489:
1.82 albertel 5490: my %record;
1.422 foxr 5491: my $questions=substr($line,$$scantron_config{'Qstart'}-1); # Answers
5492: my $data=substr($line,0,$$scantron_config{'Qstart'}-1); # earlier stuff
1.278 albertel 5493: if (!($$scantron_config{'CODElocation'} eq 0 ||
5494: $$scantron_config{'CODElocation'} eq 'none')) {
5495: if ($$scantron_config{'CODElocation'} < 0 ||
5496: $$scantron_config{'CODElocation'} eq 'letter' ||
5497: $$scantron_config{'CODElocation'} eq 'number') {
1.191 albertel 5498: $record{'scantron.CODE'}=substr($data,
5499: $$scantron_config{'CODEstart'}-1,
1.83 albertel 5500: $$scantron_config{'CODElength'});
1.191 albertel 5501: if (&scan_data($scan_data,"$whichline.useCODE")) {
5502: $record{'scantron.useCODE'}=1;
5503: }
1.192 albertel 5504: if (&scan_data($scan_data,"$whichline.CODE_ignore_dup")) {
5505: $record{'scantron.CODE_ignore_dup'}=1;
5506: }
1.82 albertel 5507: } else {
5508: #FIXME interpret first N questions
5509: }
5510: }
1.83 albertel 5511: $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
5512: $$scantron_config{'IDlength'});
1.157 albertel 5513: $record{'scantron.PaperID'}=
5514: substr($data,$$scantron_config{'PaperID'}-1,
5515: $$scantron_config{'PaperIDlength'});
5516: $record{'scantron.FirstName'}=
5517: substr($data,$$scantron_config{'FirstName'}-1,
5518: $$scantron_config{'FirstNamelength'});
5519: $record{'scantron.LastName'}=
5520: substr($data,$$scantron_config{'LastName'}-1,
5521: $$scantron_config{'LastNamelength'});
1.423 albertel 5522: if ($just_header) { return \%record; }
1.194 albertel 5523:
1.82 albertel 5524: my @alphabet=('A'..'Z');
5525: my $questnum=0;
1.447 foxr 5526: my $ansnum =1; # Multiple 'answer lines'/question.
5527:
1.470 foxr 5528: chomp($questions); # Get rid of any trailing \n.
5529: $questions =~ s/\r$//; # Get rid of trailing \r too (MAC or Win uploads).
5530: while (length($questions)) {
1.447 foxr 5531: my $answers_needed = $bubble_lines_per_response{$questnum};
1.503 raeburn 5532: my $answer_length = ($$scantron_config{'Qlength'} * $answers_needed)
5533: || 1;
5534: $questnum++;
5535: my $quest_id = $questnum;
5536: my $currentquest = substr($questions,0,$answer_length);
5537: $questions = substr($questions,$answer_length);
5538: if (length($currentquest) < $answer_length) { next; }
5539:
5540: if ($subdivided_bubble_lines{$questnum-1} =~ /,/) {
5541: my $subquestnum = 1;
5542: my $subquestions = $currentquest;
5543: my @subanswers_needed =
5544: split(/,/,$subdivided_bubble_lines{$questnum-1});
5545: foreach my $subans (@subanswers_needed) {
5546: my $subans_length =
5547: ($$scantron_config{'Qlength'} * $subans) || 1;
5548: my $currsubquest = substr($subquestions,0,$subans_length);
5549: $subquestions = substr($subquestions,$subans_length);
5550: $quest_id = "$questnum.$subquestnum";
5551: if (($$scantron_config{'Qon'} eq 'letter') ||
5552: ($$scantron_config{'Qon'} eq 'number')) {
5553: $ansnum = &scantron_validator_lettnum($ansnum,
5554: $questnum,$quest_id,$subans,$currsubquest,$whichline,
5555: \@alphabet,\%record,$scantron_config,$scan_data);
5556: } else {
5557: $ansnum = &scantron_validator_positional($ansnum,
5558: $questnum,$quest_id,$subans,$currsubquest,$whichline, \@alphabet,\%record,$scantron_config,$scan_data);
5559: }
5560: $subquestnum ++;
5561: }
5562: } else {
5563: if (($$scantron_config{'Qon'} eq 'letter') ||
5564: ($$scantron_config{'Qon'} eq 'number')) {
5565: $ansnum = &scantron_validator_lettnum($ansnum,$questnum,
5566: $quest_id,$answers_needed,$currentquest,$whichline,
5567: \@alphabet,\%record,$scantron_config,$scan_data);
5568: } else {
5569: $ansnum = &scantron_validator_positional($ansnum,$questnum,
5570: $quest_id,$answers_needed,$currentquest,$whichline,
5571: \@alphabet,\%record,$scantron_config,$scan_data);
5572: }
5573: }
5574: }
5575: $record{'scantron.maxquest'}=$questnum;
5576: return \%record;
5577: }
1.447 foxr 5578:
1.503 raeburn 5579: sub scantron_validator_lettnum {
5580: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,$whichline,
5581: $alphabet,$record,$scantron_config,$scan_data) = @_;
5582:
5583: # Qon 'letter' implies for each slot in currquest we have:
5584: # ? or * for doubles, a letter in A-Z for a bubble, and
5585: # about anything else (esp. a value of Qoff) for missing
5586: # bubbles.
5587: #
5588: # Qon 'number' implies each slot gives a digit that indexes the
5589: # bubbles filled, or Qoff, or a non-number for unbubbled lines,
5590: # and * or ? for double bubbles on a single line.
5591: #
1.447 foxr 5592:
1.503 raeburn 5593: my $matchon;
5594: if ($$scantron_config{'Qon'} eq 'letter') {
5595: $matchon = '[A-Z]';
5596: } elsif ($$scantron_config{'Qon'} eq 'number') {
5597: $matchon = '\d';
5598: }
5599: my $occurrences = 0;
5600: if (($responsetype_per_response{$questnum-1} eq 'essayresponse') ||
5601: ($responsetype_per_response{$questnum-1} eq 'formularesponse') ||
1.510 raeburn 5602: ($responsetype_per_response{$questnum-1} eq 'stringresponse') ||
5603: ($responsetype_per_response{$questnum-1} eq 'imageresponse') ||
5604: ($responsetype_per_response{$questnum-1} eq 'reactionresponse') ||
5605: ($responsetype_per_response{$questnum-1} eq 'organicresponse')) {
1.503 raeburn 5606: my @singlelines = split('',$currquest);
5607: foreach my $entry (@singlelines) {
5608: $occurrences = &occurence_count($entry,$matchon);
5609: if ($occurrences > 1) {
5610: last;
5611: }
5612: }
5613: } else {
5614: $occurrences = &occurence_count($currquest,$matchon);
5615: }
5616: if (($currquest =~ /\?/ || $currquest =~ /\*/) || ($occurrences > 1)) {
5617: push(@{$record->{'scantron.doubleerror'}},$quest_id);
5618: for (my $ans=0; $ans<$answers_needed; $ans++) {
5619: my $bubble = substr($currquest,$ans,1);
5620: if ($bubble =~ /$matchon/ ) {
5621: if ($$scantron_config{'Qon'} eq 'number') {
5622: if ($bubble == 0) {
5623: $bubble = 10;
5624: }
5625: $record->{"scantron.$ansnum.answer"} =
5626: $alphabet->[$bubble-1];
5627: } else {
5628: $record->{"scantron.$ansnum.answer"} = $bubble;
5629: }
5630: } else {
5631: $record->{"scantron.$ansnum.answer"}='';
5632: }
5633: $ansnum++;
5634: }
5635: } elsif (!defined($currquest)
5636: || (&occurence_count($currquest, $$scantron_config{'Qoff'}) == length($currquest))
5637: || (&occurence_count($currquest,$matchon) == 0)) {
5638: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
5639: $record->{"scantron.$ansnum.answer"}='';
5640: $ansnum++;
5641: }
5642: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
5643: push(@{$record->{'scantron.missingerror'}},$quest_id);
5644: }
5645: } else {
5646: if ($$scantron_config{'Qon'} eq 'number') {
5647: $currquest = &digits_to_letters($currquest);
5648: }
5649: for (my $ans=0; $ans<$answers_needed; $ans++) {
5650: my $bubble = substr($currquest,$ans,1);
5651: $record->{"scantron.$ansnum.answer"} = $bubble;
5652: $ansnum++;
5653: }
5654: }
5655: return $ansnum;
5656: }
1.447 foxr 5657:
1.503 raeburn 5658: sub scantron_validator_positional {
5659: my ($ansnum,$questnum,$quest_id,$answers_needed,$currquest,
5660: $whichline,$alphabet,$record,$scantron_config,$scan_data) = @_;
1.447 foxr 5661:
1.503 raeburn 5662: # Otherwise there's a positional notation;
5663: # each bubble line requires Qlength items, and there are filled in
5664: # bubbles for each case where there 'Qon' characters.
5665: #
1.447 foxr 5666:
1.503 raeburn 5667: my @array=split($$scantron_config{'Qon'},$currquest,-1);
1.447 foxr 5668:
1.503 raeburn 5669: # If the split only gives us one element.. the full length of the
5670: # answer string, no bubbles are filled in:
1.447 foxr 5671:
1.507 raeburn 5672: if ($answers_needed eq '') {
5673: return;
5674: }
5675:
1.503 raeburn 5676: if (length($array[0]) eq $$scantron_config{'Qlength'}*$answers_needed) {
5677: for (my $ans=0; $ans<$answers_needed; $ans++ ) {
5678: $record->{"scantron.$ansnum.answer"}='';
5679: $ansnum++;
5680: }
5681: if (!&scan_data($scan_data,"$whichline.no_bubble.$quest_id")) {
5682: push(@{$record->{"scantron.missingerror"}},$quest_id);
5683: }
5684: } elsif (scalar(@array) == 2) {
5685: my $location = length($array[0]);
5686: my $line_num = int($location / $$scantron_config{'Qlength'});
5687: my $bubble = $alphabet->[$location % $$scantron_config{'Qlength'}];
5688: for (my $ans=0; $ans<$answers_needed; $ans++) {
5689: if ($ans eq $line_num) {
5690: $record->{"scantron.$ansnum.answer"} = $bubble;
5691: } else {
5692: $record->{"scantron.$ansnum.answer"} = ' ';
5693: }
5694: $ansnum++;
5695: }
5696: } else {
5697: # If there's more than one instance of a bubble character
5698: # That's a double bubble; with positional notation we can
5699: # record all the bubbles filled in as well as the
5700: # fact this response consists of multiple bubbles.
5701: #
5702: if (($responsetype_per_response{$questnum-1} eq 'essayresponse') ||
5703: ($responsetype_per_response{$questnum-1} eq 'formularesponse') ||
1.510 raeburn 5704: ($responsetype_per_response{$questnum-1} eq 'stringresponse') ||
5705: ($responsetype_per_response{$questnum-1} eq 'imageresponse') ||
5706: ($responsetype_per_response{$questnum-1} eq 'reactionresponse') ||
5707: ($responsetype_per_response{$questnum-1} eq 'organicresponse')) {
1.503 raeburn 5708: my $doubleerror = 0;
5709: while (($currquest >= $$scantron_config{'Qlength'}) &&
5710: (!$doubleerror)) {
5711: my $currline = substr($currquest,0,$$scantron_config{'Qlength'});
5712: $currquest = substr($currquest,$$scantron_config{'Qlength'});
5713: my @currarray = split($$scantron_config{'Qon'},$currline,-1);
5714: if (length(@currarray) > 2) {
5715: $doubleerror = 1;
5716: }
5717: }
5718: if ($doubleerror) {
5719: push(@{$record->{'scantron.doubleerror'}},$quest_id);
5720: }
5721: } else {
5722: push(@{$record->{'scantron.doubleerror'}},$quest_id);
5723: }
5724: my $item = $ansnum;
5725: for (my $ans=0; $ans<$answers_needed; $ans++) {
5726: $record->{"scantron.$item.answer"} = '';
5727: $item ++;
5728: }
1.447 foxr 5729:
1.503 raeburn 5730: my @ans=@array;
5731: my $i=0;
5732: my $increment = 0;
5733: while ($#ans) {
5734: $i+=length($ans[0]) + $increment;
5735: my $line = int($i/$$scantron_config{'Qlength'} + $ansnum);
5736: my $bubble = $i%$$scantron_config{'Qlength'};
5737: $record->{"scantron.$line.answer"}.=$alphabet->[$bubble];
5738: shift(@ans);
5739: $increment = 1;
5740: }
5741: $ansnum += $answers_needed;
1.82 albertel 5742: }
1.503 raeburn 5743: return $ansnum;
1.82 albertel 5744: }
5745:
1.423 albertel 5746: =pod
5747:
5748: =item scantron_add_delay
5749:
5750: Adds an error message that occurred during the grading phase to a
5751: queue of messages to be shown after grading pass is complete
5752:
5753: Arguments:
1.424 albertel 5754: $delayqueue - arrary ref of hash ref of error messages
1.423 albertel 5755: $scanline - the scanline that caused the error
5756: $errormesage - the error message
5757: $errorcode - a numeric code for the error
5758:
5759: Side Effects:
1.424 albertel 5760: updates the $delayqueue to have a new hash ref of the error
1.423 albertel 5761:
5762: =cut
5763:
1.82 albertel 5764: sub scantron_add_delay {
1.140 albertel 5765: my ($delayqueue,$scanline,$errormessage,$errorcode)=@_;
5766: push(@$delayqueue,
5767: {'line' => $scanline, 'emsg' => $errormessage,
5768: 'ecode' => $errorcode }
5769: );
1.82 albertel 5770: }
5771:
1.423 albertel 5772: =pod
5773:
5774: =item scantron_find_student
5775:
1.424 albertel 5776: Finds the username for the current scanline
5777:
5778: Arguments:
5779: $scantron_record - hash result from scantron_parse_scanline
5780: $scan_data - hash of correction information
5781: (see &scantron_getfile() form more information)
5782: $idmap - hash from &username_to_idmap()
5783: $line - number of current scanline
5784:
5785: Returns:
5786: Either 'username:domain' or undef if unknown
5787:
1.423 albertel 5788: =cut
5789:
1.82 albertel 5790: sub scantron_find_student {
1.157 albertel 5791: my ($scantron_record,$scan_data,$idmap,$line)=@_;
1.83 albertel 5792: my $scanID=$$scantron_record{'scantron.ID'};
1.157 albertel 5793: if ($scanID =~ /^\s*$/) {
5794: return &scan_data($scan_data,"$line.user");
5795: }
1.83 albertel 5796: foreach my $id (keys(%$idmap)) {
1.157 albertel 5797: if (lc($id) eq lc($scanID)) {
5798: return $$idmap{$id};
5799: }
1.83 albertel 5800: }
5801: return undef;
5802: }
5803:
1.423 albertel 5804: =pod
5805:
5806: =item scantron_filter
5807:
1.424 albertel 5808: Filter sub for lonnavmaps, filters out hidden resources if ignore
5809: hidden resources was selected
5810:
1.423 albertel 5811: =cut
5812:
1.83 albertel 5813: sub scantron_filter {
5814: my ($curres)=@_;
1.331 albertel 5815:
5816: if (ref($curres) && $curres->is_problem()) {
5817: # if the user has asked to not have either hidden
5818: # or 'randomout' controlled resources to be graded
5819: # don't include them
5820: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
5821: && $curres->randomout) {
5822: return 0;
5823: }
1.83 albertel 5824: return 1;
5825: }
5826: return 0;
1.82 albertel 5827: }
5828:
1.423 albertel 5829: =pod
5830:
5831: =item scantron_process_corrections
5832:
1.424 albertel 5833: Gets correction information out of submitted form data and corrects
5834: the scanline
5835:
1.423 albertel 5836: =cut
5837:
1.157 albertel 5838: sub scantron_process_corrections {
5839: my ($r) = @_;
1.257 albertel 5840: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5841: my ($scanlines,$scan_data)=&scantron_getfile();
5842: my $classlist=&Apache::loncoursedata::get_classlist();
1.257 albertel 5843: my $which=$env{'form.scantron_line'};
1.200 albertel 5844: my $line=&scantron_get_line($scanlines,$scan_data,$which);
1.157 albertel 5845: my ($skip,$err,$errmsg);
1.257 albertel 5846: if ($env{'form.scantron_skip_record'}) {
1.157 albertel 5847: $skip=1;
1.257 albertel 5848: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)ID$/) {
5849: my $newstudent=$env{'form.scantron_username'}.':'.
5850: $env{'form.scantron_domain'};
1.157 albertel 5851: my $newid=$classlist->{$newstudent}->[&Apache::loncoursedata::CL_ID];
5852: ($line,$err,$errmsg)=
5853: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
5854: 'ID',{'newid'=>$newid,
1.257 albertel 5855: 'username'=>$env{'form.scantron_username'},
5856: 'domain'=>$env{'form.scantron_domain'}});
5857: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)CODE$/) {
5858: my $resolution=$env{'form.scantron_CODE_resolution'};
1.190 albertel 5859: my $newCODE;
1.192 albertel 5860: my %args;
1.190 albertel 5861: if ($resolution eq 'use_unfound') {
1.191 albertel 5862: $newCODE='use_unfound';
1.190 albertel 5863: } elsif ($resolution eq 'use_found') {
1.257 albertel 5864: $newCODE=$env{'form.scantron_CODE_selectedvalue'};
1.190 albertel 5865: } elsif ($resolution eq 'use_typed') {
1.257 albertel 5866: $newCODE=$env{'form.scantron_CODE_newvalue'};
1.194 albertel 5867: } elsif ($resolution =~ /^use_closest_(\d+)/) {
1.257 albertel 5868: $newCODE=$env{"form.scantron_CODE_closest_$1"};
1.190 albertel 5869: }
1.257 albertel 5870: if ($env{'form.scantron_corrections'} eq 'duplicateCODE') {
1.192 albertel 5871: $args{'CODE_ignore_dup'}=1;
5872: }
5873: $args{'CODE'}=$newCODE;
1.186 albertel 5874: ($line,$err,$errmsg)=
5875: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
1.192 albertel 5876: 'CODE',\%args);
1.257 albertel 5877: } elsif ($env{'form.scantron_corrections'} =~ /^(missing|double)bubble$/) {
5878: foreach my $question (split(',',$env{'form.scantron_questions'})) {
1.157 albertel 5879: ($line,$err,$errmsg)=
5880: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,
5881: $which,'answer',
5882: { 'question'=>$question,
1.503 raeburn 5883: 'response'=>$env{"form.scantron_correct_Q_$question"},
5884: 'questionnum'=>$env{"form.scantron_questionnum_Q_$question"}});
1.157 albertel 5885: if ($err) { last; }
5886: }
5887: }
5888: if ($err) {
1.398 albertel 5889: $r->print("<span class=\"LC_warning\">Unable to accept last correction, an error occurred :$errmsg:</span>");
1.157 albertel 5890: } else {
1.200 albertel 5891: &scantron_put_line($scanlines,$scan_data,$which,$line,$skip);
1.157 albertel 5892: &scantron_putfile($scanlines,$scan_data);
5893: }
5894: }
5895:
1.423 albertel 5896: =pod
5897:
5898: =item reset_skipping_status
5899:
1.424 albertel 5900: Forgets the current set of remember skipped scanlines (and thus
5901: reverts back to considering all lines in the
5902: scantron_skipped_<filename> file)
5903:
1.423 albertel 5904: =cut
5905:
1.200 albertel 5906: sub reset_skipping_status {
5907: my ($scanlines,$scan_data)=&scantron_getfile();
5908: &scan_data($scan_data,'remember_skipping',undef,1);
5909: &scantron_putfile(undef,$scan_data);
5910: }
5911:
1.423 albertel 5912: =pod
5913:
5914: =item start_skipping
5915:
1.424 albertel 5916: Marks a scanline to be skipped.
5917:
1.423 albertel 5918: =cut
5919:
1.376 albertel 5920: sub start_skipping {
1.200 albertel 5921: my ($scan_data,$i)=@_;
5922: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 5923: if ($env{'form.scantron_options_redo'} =~ /^redo_/) {
5924: $remembered{$i}=2;
5925: } else {
5926: $remembered{$i}=1;
5927: }
1.200 albertel 5928: &scan_data($scan_data,'remember_skipping',join(':',%remembered));
5929: }
5930:
1.423 albertel 5931: =pod
5932:
5933: =item should_be_skipped
5934:
1.424 albertel 5935: Checks whether a scanline should be skipped.
5936:
1.423 albertel 5937: =cut
5938:
1.200 albertel 5939: sub should_be_skipped {
1.376 albertel 5940: my ($scanlines,$scan_data,$i)=@_;
1.257 albertel 5941: if ($env{'form.scantron_options_redo'} !~ /^redo_/) {
1.200 albertel 5942: # not redoing old skips
1.376 albertel 5943: if ($scanlines->{'skipped'}[$i]) { return 1; }
1.200 albertel 5944: return 0;
5945: }
5946: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
1.376 albertel 5947:
5948: if (exists($remembered{$i}) && $remembered{$i} != 2 ) {
5949: return 0;
5950: }
1.200 albertel 5951: return 1;
5952: }
5953:
1.423 albertel 5954: =pod
5955:
5956: =item remember_current_skipped
5957:
1.424 albertel 5958: Discovers what scanlines are in the scantron_skipped_<filename>
5959: file and remembers them into scan_data for later use.
5960:
1.423 albertel 5961: =cut
5962:
1.200 albertel 5963: sub remember_current_skipped {
5964: my ($scanlines,$scan_data)=&scantron_getfile();
5965: my %to_remember;
5966: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
5967: if ($scanlines->{'skipped'}[$i]) {
5968: $to_remember{$i}=1;
5969: }
5970: }
1.376 albertel 5971:
1.200 albertel 5972: &scan_data($scan_data,'remember_skipping',join(':',%to_remember));
5973: &scantron_putfile(undef,$scan_data);
5974: }
5975:
1.423 albertel 5976: =pod
5977:
5978: =item check_for_error
5979:
1.424 albertel 5980: Checks if there was an error when attempting to remove a specific
5981: scantron_.. bubble sheet data file. Prints out an error if
5982: something went wrong.
5983:
1.423 albertel 5984: =cut
5985:
1.200 albertel 5986: sub check_for_error {
5987: my ($r,$result)=@_;
5988: if ($result ne 'ok' && $result ne 'not_found' ) {
1.492 albertel 5989: $r->print(&mt("An error occurred ([_1]) when trying to remove the existing corrections.",$result));
1.200 albertel 5990: }
5991: }
1.157 albertel 5992:
1.423 albertel 5993: =pod
5994:
5995: =item scantron_warning_screen
5996:
1.424 albertel 5997: Interstitial screen to make sure the operator has selected the
5998: correct options before we start the validation phase.
5999:
1.423 albertel 6000: =cut
6001:
1.203 albertel 6002: sub scantron_warning_screen {
6003: my ($button_text)=@_;
1.257 albertel 6004: my $title=&Apache::lonnet::gettitle($env{'form.selectpage'});
1.284 albertel 6005: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.373 albertel 6006: my $CODElist;
1.284 albertel 6007: if ($scantron_config{'CODElocation'} &&
6008: $scantron_config{'CODEstart'} &&
6009: $scantron_config{'CODElength'}) {
6010: $CODElist=$env{'form.scantron_CODElist'};
1.398 albertel 6011: if ($env{'form.scantron_CODElist'} eq '') { $CODElist='<span class="LC_warning">None</span>'; }
1.284 albertel 6012: $CODElist=
1.492 albertel 6013: '<tr><td><b>'.&mt('List of CODES to validate against:').'</b></td><td><tt>'.
1.373 albertel 6014: $env{'form.scantron_CODElist'}.'</tt></td></tr>';
1.284 albertel 6015: }
1.492 albertel 6016: return ('
1.203 albertel 6017: <p>
1.492 albertel 6018: <span class="LC_warning">
6019: '.&mt('Please double check the information below before clicking on \'[_1]\'',&mt($button_text)).'</span>
1.203 albertel 6020: </p>
6021: <table>
1.492 albertel 6022: <tr><td><b>'.&mt('Sequence to be Graded:').'</b></td><td>'.$title.'</td></tr>
6023: <tr><td><b>'.&mt('Data File that will be used:').'</b></td><td><tt>'.$env{'form.scantron_selectfile'}.'</tt></td></tr>
6024: '.$CODElist.'
1.203 albertel 6025: </table>
6026: <br />
1.492 albertel 6027: <p> '.&mt('If this information is correct, please click on \'[_1]\'.',&mt($button_text)).'</p>
6028: <p> '.&mt('If something is incorrect, please click the \'Grading Menu\' button to start over.').'</p>
1.203 albertel 6029:
6030: <br />
1.492 albertel 6031: ');
1.203 albertel 6032: }
6033:
1.423 albertel 6034: =pod
6035:
6036: =item scantron_do_warning
6037:
1.424 albertel 6038: Check if the operator has picked something for all required
6039: fields. Error out if something is missing.
6040:
1.423 albertel 6041: =cut
6042:
1.203 albertel 6043: sub scantron_do_warning {
6044: my ($r)=@_;
1.324 albertel 6045: my ($symb)=&get_symb($r);
1.203 albertel 6046: if (!$symb) {return '';}
1.324 albertel 6047: my $default_form_data=&defaultFormData($symb);
1.203 albertel 6048: $r->print(&scantron_form_start().$default_form_data);
1.257 albertel 6049: if ( $env{'form.selectpage'} eq '' ||
6050: $env{'form.scantron_selectfile'} eq '' ||
6051: $env{'form.scantron_format'} eq '' ) {
1.492 albertel 6052: $r->print("<p>".&mt('You have forgetten to specify some information. Please go Back and try again.')."</p>");
1.257 albertel 6053: if ( $env{'form.selectpage'} eq '') {
1.492 albertel 6054: $r->print('<p><span class="LC_error">'.&mt('You have not selected a Sequence to grade').'</span></p>');
1.237 albertel 6055: }
1.257 albertel 6056: if ( $env{'form.scantron_selectfile'} eq '') {
1.492 albertel 6057: $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 6058: }
1.257 albertel 6059: if ( $env{'form.scantron_format'} eq '') {
1.492 albertel 6060: $r->print('<p><span class="LC_error">'.&mt('You have not selected a the format of the student\'s response data.').'</span></p>');
1.237 albertel 6061: }
6062: } else {
1.265 www 6063: my $warning=&scantron_warning_screen('Grading: Validate Records');
1.492 albertel 6064: $r->print('
6065: '.$warning.'
6066: <input type="submit" name="submit" value="'.&mt('Grading: Validate Records').'" />
1.203 albertel 6067: <input type="hidden" name="command" value="scantron_validate" />
1.492 albertel 6068: ');
1.237 albertel 6069: }
1.352 albertel 6070: $r->print("</form><br />".&show_grading_menu_form($symb));
1.203 albertel 6071: return '';
6072: }
6073:
1.423 albertel 6074: =pod
6075:
6076: =item scantron_form_start
6077:
1.424 albertel 6078: html hidden input for remembering all selected grading options
6079:
1.423 albertel 6080: =cut
6081:
1.203 albertel 6082: sub scantron_form_start {
6083: my ($max_bubble)=@_;
6084: my $result= <<SCANTRONFORM;
6085: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
1.257 albertel 6086: <input type="hidden" name="selectpage" value="$env{'form.selectpage'}" />
6087: <input type="hidden" name="scantron_format" value="$env{'form.scantron_format'}" />
6088: <input type="hidden" name="scantron_selectfile" value="$env{'form.scantron_selectfile'}" />
1.218 albertel 6089: <input type="hidden" name="scantron_maxbubble" value="$max_bubble" />
1.257 albertel 6090: <input type="hidden" name="scantron_CODElist" value="$env{'form.scantron_CODElist'}" />
6091: <input type="hidden" name="scantron_CODEunique" value="$env{'form.scantron_CODEunique'}" />
6092: <input type="hidden" name="scantron_options_redo" value="$env{'form.scantron_options_redo'}" />
6093: <input type="hidden" name="scantron_options_ignore" value="$env{'form.scantron_options_ignore'}" />
1.331 albertel 6094: <input type="hidden" name="scantron_options_hidden" value="$env{'form.scantron_options_hidden'}" />
1.203 albertel 6095: SCANTRONFORM
1.447 foxr 6096:
6097: my $line = 0;
6098: while (defined($env{"form.scantron.bubblelines.$line"})) {
6099: my $chunk =
6100: '<input type="hidden" name="scantron.bubblelines.'.$line.'" value="'.$env{"form.scantron.bubblelines.$line"}.'" />'."\n";
1.448 foxr 6101: $chunk .=
6102: '<input type="hidden" name="scantron.first_bubble_line.'.$line.'" value="'.$env{"form.scantron.first_bubble_line.$line"}.'" />'."\n";
1.503 raeburn 6103: $chunk .=
6104: '<input type="hidden" name="scantron.sub_bubblelines.'.$line.'" value="'.$env{"form.scantron.sub_bubblelines.$line"}.'" />'."\n";
1.504 raeburn 6105: $chunk .=
6106: '<input type="hidden" name="scantron.responsetype.'.$line.'" value="'.$env{"form.scantron.responsetype.$line"}.'" />'."\n";
1.447 foxr 6107: $result .= $chunk;
6108: $line++;
6109: }
1.203 albertel 6110: return $result;
6111: }
6112:
1.423 albertel 6113: =pod
6114:
6115: =item scantron_validate_file
6116:
1.424 albertel 6117: Dispatch routine for doing validation of a bubble sheet data file.
6118:
6119: Also processes any necessary information resets that need to
6120: occur before validation begins (ignore previous corrections,
6121: restarting the skipped records processing)
6122:
1.423 albertel 6123: =cut
6124:
1.157 albertel 6125: sub scantron_validate_file {
6126: my ($r) = @_;
1.324 albertel 6127: my ($symb)=&get_symb($r);
1.157 albertel 6128: if (!$symb) {return '';}
1.324 albertel 6129: my $default_form_data=&defaultFormData($symb);
1.200 albertel 6130:
6131: # do the detection of only doing skipped records first befroe we delete
1.424 albertel 6132: # them when doing the corrections reset
1.257 albertel 6133: if ($env{'form.scantron_options_redo'} ne 'redo_skipped_ready') {
1.200 albertel 6134: &reset_skipping_status();
6135: }
1.257 albertel 6136: if ($env{'form.scantron_options_redo'} eq 'redo_skipped') {
1.200 albertel 6137: &remember_current_skipped();
1.257 albertel 6138: $env{'form.scantron_options_redo'}='redo_skipped_ready';
1.200 albertel 6139: }
6140:
1.257 albertel 6141: if ($env{'form.scantron_options_ignore'} eq 'ignore_corrections') {
1.200 albertel 6142: &check_for_error($r,&scantron_remove_file('corrected'));
6143: &check_for_error($r,&scantron_remove_file('skipped'));
6144: &check_for_error($r,&scantron_remove_scan_data());
1.257 albertel 6145: $env{'form.scantron_options_ignore'}='done';
1.192 albertel 6146: }
1.200 albertel 6147:
1.257 albertel 6148: if ($env{'form.scantron_corrections'}) {
1.157 albertel 6149: &scantron_process_corrections($r);
6150: }
1.503 raeburn 6151: $r->print('<p>'.&mt('Gathering necessary information.').'</p>');$r->rflush();
1.157 albertel 6152: #get the student pick code ready
6153: $r->print(&Apache::loncommon::studentbrowser_javascript());
1.330 albertel 6154: my $max_bubble=&scantron_get_maxbubble();
1.203 albertel 6155: my $result=&scantron_form_start($max_bubble).$default_form_data;
1.157 albertel 6156: $r->print($result);
6157:
1.334 albertel 6158: my @validate_phases=( 'sequence',
6159: 'ID',
1.157 albertel 6160: 'CODE',
6161: 'doublebubble',
6162: 'missingbubbles');
1.257 albertel 6163: if (!$env{'form.validatepass'}) {
6164: $env{'form.validatepass'} = 0;
1.157 albertel 6165: }
1.257 albertel 6166: my $currentphase=$env{'form.validatepass'};
1.157 albertel 6167:
1.448 foxr 6168:
1.157 albertel 6169: my $stop=0;
6170: while (!$stop && $currentphase < scalar(@validate_phases)) {
1.503 raeburn 6171: $r->print(&mt('Validating '.$validate_phases[$currentphase]).'<br />');
1.157 albertel 6172: $r->rflush();
6173: my $which="scantron_validate_".$validate_phases[$currentphase];
6174: {
6175: no strict 'refs';
6176: ($stop,$currentphase)=&$which($r,$currentphase);
6177: }
6178: }
6179: if (!$stop) {
1.203 albertel 6180: my $warning=&scantron_warning_screen('Start Grading');
1.512 www 6181: $r->print(&mt('Validation process complete.').'<br />
1.492 albertel 6182: '.$warning.'
6183: <input type="submit" name="submit" value="'.&mt('Start Grading').'" />
1.203 albertel 6184: <input type="hidden" name="command" value="scantron_process" />
1.492 albertel 6185: ');
1.203 albertel 6186:
1.157 albertel 6187: } else {
6188: $r->print('<input type="hidden" name="command" value="scantron_validate" />');
6189: $r->print("<input type='hidden' name='validatepass' value='".$currentphase."' />");
6190: }
6191: if ($stop) {
1.334 albertel 6192: if ($validate_phases[$currentphase] eq 'sequence') {
1.539 ! riegler 6193: $r->print('<input type="submit" name="submit" value="'.&mt('Ignore').' → " />');
1.492 albertel 6194: $r->print(' '.&mt('this error').' <br />');
1.334 albertel 6195:
1.492 albertel 6196: $r->print(" <p>".&mt("Or click the 'Grading Menu' button to start over.")."</p>");
1.334 albertel 6197: } else {
1.503 raeburn 6198: if ($validate_phases[$currentphase] eq 'doublebubble' || $validate_phases[$currentphase] eq 'missingbubbles') {
1.539 ! riegler 6199: $r->print('<input type="button" name="submitbutton" value="'.&mt('Continue').' →" onclick="javascript:verify_bubble_radio(this.form)" />');
1.503 raeburn 6200: } else {
1.539 ! riegler 6201: $r->print('<input type="submit" name="submit" value="'.&mt('Continue').' →" />');
1.503 raeburn 6202: }
1.492 albertel 6203: $r->print(' '.&mt('using corrected info').' <br />');
6204: $r->print("<input type='submit' value='".&mt("Skip")."' name='scantron_skip_record' />");
6205: $r->print(" ".&mt("this scanline saving it for later."));
1.334 albertel 6206: }
1.157 albertel 6207: }
1.352 albertel 6208: $r->print(" </form><br />".&show_grading_menu_form($symb));
1.157 albertel 6209: return '';
6210: }
6211:
1.423 albertel 6212:
6213: =pod
6214:
6215: =item scantron_remove_file
6216:
1.424 albertel 6217: Removes the requested bubble sheet data file, makes sure that
6218: scantron_original_<filename> is never removed
6219:
6220:
1.423 albertel 6221: =cut
6222:
1.200 albertel 6223: sub scantron_remove_file {
1.192 albertel 6224: my ($which)=@_;
1.257 albertel 6225: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6226: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 6227: my $file='scantron_';
1.200 albertel 6228: if ($which eq 'corrected' || $which eq 'skipped') {
6229: $file.=$which.'_';
1.192 albertel 6230: } else {
6231: return 'refused';
6232: }
1.257 albertel 6233: $file.=$env{'form.scantron_selectfile'};
1.200 albertel 6234: return &Apache::lonnet::removeuserfile($cname,$cdom,$file);
6235: }
6236:
1.423 albertel 6237:
6238: =pod
6239:
6240: =item scantron_remove_scan_data
6241:
1.424 albertel 6242: Removes all scan_data correction for the requested bubble sheet
6243: data file. (In the case that both the are doing skipped records we need
6244: to remember the old skipped lines for the time being so that element
6245: persists for a while.)
6246:
1.423 albertel 6247: =cut
6248:
1.200 albertel 6249: sub scantron_remove_scan_data {
1.257 albertel 6250: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6251: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 6252: my @keys=&Apache::lonnet::getkeys('nohist_scantrondata',$cdom,$cname);
6253: my @todelete;
1.257 albertel 6254: my $filename=$env{'form.scantron_selectfile'};
1.192 albertel 6255: foreach my $key (@keys) {
6256: if ($key=~/^\Q$filename\E_/) {
1.257 albertel 6257: if ($env{'form.scantron_options_redo'} eq 'redo_skipped_ready' &&
1.200 albertel 6258: $key=~/remember_skipping/) {
6259: next;
6260: }
1.192 albertel 6261: push(@todelete,$key);
6262: }
6263: }
1.200 albertel 6264: my $result;
1.192 albertel 6265: if (@todelete) {
1.491 albertel 6266: $result = &Apache::lonnet::del('nohist_scantrondata',
6267: \@todelete,$cdom,$cname);
6268: } else {
6269: $result = 'ok';
1.192 albertel 6270: }
6271: return $result;
6272: }
6273:
1.423 albertel 6274:
6275: =pod
6276:
6277: =item scantron_getfile
6278:
1.424 albertel 6279: Fetches the requested bubble sheet data file (all 3 versions), and
6280: the scan_data hash
6281:
6282: Arguments:
6283: None
6284:
6285: Returns:
6286: 2 hash references
6287:
6288: - first one has
6289: orig -
6290: corrected -
6291: skipped - each of which points to an array ref of the specified
6292: file broken up into individual lines
6293: count - number of scanlines
6294:
6295: - second is the scan_data hash possible keys are
1.425 albertel 6296: ($number refers to scanline numbered $number and thus the key affects
6297: only that scanline
6298: $bubline refers to the specific bubble line element and the aspects
6299: refers to that specific bubble line element)
6300:
6301: $number.user - username:domain to use
6302: $number.CODE_ignore_dup
6303: - ignore the duplicate CODE error
6304: $number.useCODE
6305: - use the CODE in the scanline as is
6306: $number.no_bubble.$bubline
6307: - it is valid that there is no bubbled in bubble
6308: at $number $bubline
6309: remember_skipping
6310: - a frozen hash containing keys of $number and values
6311: of either
6312: 1 - we are on a 'do skipped records pass' and plan
6313: on processing this line
6314: 2 - we are on a 'do skipped records pass' and this
6315: scanline has been marked to skip yet again
1.424 albertel 6316:
1.423 albertel 6317: =cut
6318:
1.157 albertel 6319: sub scantron_getfile {
1.200 albertel 6320: #FIXME really would prefer a scantron directory
1.257 albertel 6321: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6322: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.157 albertel 6323: my $lines;
6324: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6325: 'scantron_orig_'.$env{'form.scantron_selectfile'});
1.157 albertel 6326: my %scanlines;
6327: $scanlines{'orig'}=[(split("\n",$lines,-1))];
6328: my $temp=$scanlines{'orig'};
6329: $scanlines{'count'}=$#$temp;
6330:
6331: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6332: 'scantron_corrected_'.$env{'form.scantron_selectfile'});
1.157 albertel 6333: if ($lines eq '-1') {
6334: $scanlines{'corrected'}=[];
6335: } else {
6336: $scanlines{'corrected'}=[(split("\n",$lines,-1))];
6337: }
6338: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 6339: 'scantron_skipped_'.$env{'form.scantron_selectfile'});
1.157 albertel 6340: if ($lines eq '-1') {
6341: $scanlines{'skipped'}=[];
6342: } else {
6343: $scanlines{'skipped'}=[(split("\n",$lines,-1))];
6344: }
1.175 albertel 6345: my @tmp=&Apache::lonnet::dump('nohist_scantrondata',$cdom,$cname);
1.157 albertel 6346: if ($tmp[0] =~ /^(error:|no_such_host)/) { @tmp=(); }
6347: my %scan_data = @tmp;
6348: return (\%scanlines,\%scan_data);
6349: }
6350:
1.423 albertel 6351: =pod
6352:
6353: =item lonnet_putfile
6354:
1.424 albertel 6355: Wrapper routine to call &Apache::lonnet::finishuserfileupload
6356:
6357: Arguments:
6358: $contents - data to store
6359: $filename - filename to store $contents into
6360:
6361: Returns:
6362: result value from &Apache::lonnet::finishuserfileupload
6363:
1.423 albertel 6364: =cut
6365:
1.157 albertel 6366: sub lonnet_putfile {
6367: my ($contents,$filename)=@_;
1.257 albertel 6368: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6369: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6370: $env{'form.sillywaytopassafilearound'}=$contents;
1.275 albertel 6371: &Apache::lonnet::finishuserfileupload($docuname,$docudom,'sillywaytopassafilearound',$filename);
1.157 albertel 6372:
6373: }
6374:
1.423 albertel 6375: =pod
6376:
6377: =item scantron_putfile
6378:
1.424 albertel 6379: Stores the current version of the bubble sheet data files, and the
6380: scan_data hash. (Does not modify the original version only the
6381: corrected and skipped versions.
6382:
6383: Arguments:
6384: $scanlines - hash ref that looks like the first return value from
6385: &scantron_getfile()
6386: $scan_data - hash ref that looks like the second return value from
6387: &scantron_getfile()
6388:
1.423 albertel 6389: =cut
6390:
1.157 albertel 6391: sub scantron_putfile {
6392: my ($scanlines,$scan_data) = @_;
1.200 albertel 6393: #FIXME really would prefer a scantron directory
1.257 albertel 6394: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
6395: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.200 albertel 6396: if ($scanlines) {
6397: my $prefix='scantron_';
1.157 albertel 6398: # no need to update orig, shouldn't change
6399: # &lonnet_putfile(join("\n",@{$scanlines->{'orig'}}),$prefix.'orig_'.
1.257 albertel 6400: # $env{'form.scantron_selectfile'});
1.200 albertel 6401: &lonnet_putfile(join("\n",@{$scanlines->{'corrected'}}),
6402: $prefix.'corrected_'.
1.257 albertel 6403: $env{'form.scantron_selectfile'});
1.200 albertel 6404: &lonnet_putfile(join("\n",@{$scanlines->{'skipped'}}),
6405: $prefix.'skipped_'.
1.257 albertel 6406: $env{'form.scantron_selectfile'});
1.200 albertel 6407: }
1.175 albertel 6408: &Apache::lonnet::put('nohist_scantrondata',$scan_data,$cdom,$cname);
1.157 albertel 6409: }
6410:
1.423 albertel 6411: =pod
6412:
6413: =item scantron_get_line
6414:
1.424 albertel 6415: Returns the correct version of the scanline
6416:
6417: Arguments:
6418: $scanlines - hash ref that looks like the first return value from
6419: &scantron_getfile()
6420: $scan_data - hash ref that looks like the second return value from
6421: &scantron_getfile()
6422: $i - number of the requested line (starts at 0)
6423:
6424: Returns:
6425: A scanline, (either the original or the corrected one if it
6426: exists), or undef if the requested scanline should be
6427: skipped. (Either because it's an skipped scanline, or it's an
6428: unskipped scanline and we are not doing a 'do skipped scanlines'
6429: pass.
6430:
1.423 albertel 6431: =cut
6432:
1.157 albertel 6433: sub scantron_get_line {
1.200 albertel 6434: my ($scanlines,$scan_data,$i)=@_;
1.376 albertel 6435: if (&should_be_skipped($scanlines,$scan_data,$i)) { return undef; }
6436: #if ($scanlines->{'skipped'}[$i]) { return undef; }
1.157 albertel 6437: if ($scanlines->{'corrected'}[$i]) {return $scanlines->{'corrected'}[$i];}
6438: return $scanlines->{'orig'}[$i];
6439: }
6440:
1.423 albertel 6441: =pod
6442:
6443: =item scantron_todo_count
6444:
1.424 albertel 6445: Counts the number of scanlines that need processing.
6446:
6447: Arguments:
6448: $scanlines - hash ref that looks like the first return value from
6449: &scantron_getfile()
6450: $scan_data - hash ref that looks like the second return value from
6451: &scantron_getfile()
6452:
6453: Returns:
6454: $count - number of scanlines to process
6455:
1.423 albertel 6456: =cut
6457:
1.200 albertel 6458: sub get_todo_count {
6459: my ($scanlines,$scan_data)=@_;
6460: my $count=0;
6461: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
6462: my $line=&scantron_get_line($scanlines,$scan_data,$i);
6463: if ($line=~/^[\s\cz]*$/) { next; }
6464: $count++;
6465: }
6466: return $count;
6467: }
6468:
1.423 albertel 6469: =pod
6470:
6471: =item scantron_put_line
6472:
1.424 albertel 6473: Updates the 'corrected' or 'skipped' versions of the bubble sheet
6474: data file.
6475:
6476: Arguments:
6477: $scanlines - hash ref that looks like the first return value from
6478: &scantron_getfile()
6479: $scan_data - hash ref that looks like the second return value from
6480: &scantron_getfile()
6481: $i - line number to update
6482: $newline - contents of the updated scanline
6483: $skip - if true make the line for skipping and update the
6484: 'skipped' file
6485:
1.423 albertel 6486: =cut
6487:
1.157 albertel 6488: sub scantron_put_line {
1.200 albertel 6489: my ($scanlines,$scan_data,$i,$newline,$skip)=@_;
1.157 albertel 6490: if ($skip) {
6491: $scanlines->{'skipped'}[$i]=$newline;
1.376 albertel 6492: &start_skipping($scan_data,$i);
1.157 albertel 6493: return;
6494: }
6495: $scanlines->{'corrected'}[$i]=$newline;
6496: }
6497:
1.423 albertel 6498: =pod
6499:
6500: =item scantron_clear_skip
6501:
1.424 albertel 6502: Remove a line from the 'skipped' file
6503:
6504: Arguments:
6505: $scanlines - hash ref that looks like the first return value from
6506: &scantron_getfile()
6507: $scan_data - hash ref that looks like the second return value from
6508: &scantron_getfile()
6509: $i - line number to update
6510:
1.423 albertel 6511: =cut
6512:
1.376 albertel 6513: sub scantron_clear_skip {
6514: my ($scanlines,$scan_data,$i)=@_;
6515: if (exists($scanlines->{'skipped'}[$i])) {
6516: undef($scanlines->{'skipped'}[$i]);
6517: return 1;
6518: }
6519: return 0;
6520: }
6521:
1.423 albertel 6522: =pod
6523:
6524: =item scantron_filter_not_exam
6525:
1.424 albertel 6526: Filter routine used by &Apache::lonnavmaps::retrieveResources(), to
6527: filter out resources that are not marked as 'exam' mode
6528:
1.423 albertel 6529: =cut
6530:
1.334 albertel 6531: sub scantron_filter_not_exam {
6532: my ($curres)=@_;
6533:
6534: if (ref($curres) && $curres->is_problem() && !$curres->is_exam()) {
6535: # if the user has asked to not have either hidden
6536: # or 'randomout' controlled resources to be graded
6537: # don't include them
6538: if ($env{'form.scantron_options_hidden'} eq 'ignore_hidden'
6539: && $curres->randomout) {
6540: return 0;
6541: }
6542: return 1;
6543: }
6544: return 0;
6545: }
6546:
1.423 albertel 6547: =pod
6548:
6549: =item scantron_validate_sequence
6550:
1.424 albertel 6551: Validates the selected sequence, checking for resource that are
6552: not set to exam mode.
6553:
1.423 albertel 6554: =cut
6555:
1.334 albertel 6556: sub scantron_validate_sequence {
6557: my ($r,$currentphase) = @_;
6558:
6559: my $navmap=Apache::lonnavmaps::navmap->new();
6560: my (undef,undef,$sequence)=
6561: &Apache::lonnet::decode_symb($env{'form.selectpage'});
6562:
6563: my $map=$navmap->getResourceByUrl($sequence);
6564:
6565: $r->print('<input type="hidden" name="validate_sequence_exam"
6566: value="ignore" />');
6567: if ($env{'form.validate_sequence_exam'} ne 'ignore') {
6568: my @resources=
6569: $navmap->retrieveResources($map,\&scantron_filter_not_exam,1,0);
6570: if (@resources) {
1.357 banghart 6571: $r->print("<p>".&mt('Some resources in the sequence currently are not set to exam mode. Grading these resources currently may not work correctly.')."</p>");
1.334 albertel 6572: return (1,$currentphase);
6573: }
6574: }
6575:
6576: return (0,$currentphase+1);
6577: }
6578:
1.423 albertel 6579:
6580:
1.157 albertel 6581: sub scantron_validate_ID {
6582: my ($r,$currentphase) = @_;
6583:
6584: #get student info
6585: my $classlist=&Apache::loncoursedata::get_classlist();
6586: my %idmap=&username_to_idmap($classlist);
6587:
6588: #get scantron line setup
1.257 albertel 6589: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 6590: my ($scanlines,$scan_data)=&scantron_getfile();
1.447 foxr 6591:
6592: &scantron_get_maxbubble(); # parse needs the bubble_lines.. array.
1.157 albertel 6593:
6594: my %found=('ids'=>{},'usernames'=>{});
6595: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 6596: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 6597: if ($line=~/^[\s\cz]*$/) { next; }
6598: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
6599: $scan_data);
6600: my $id=$$scan_record{'scantron.ID'};
6601: my $found;
6602: foreach my $checkid (keys(%idmap)) {
6603: if (lc($checkid) eq lc($id)) { $found=$checkid;last; }
6604: }
6605: if ($found) {
6606: my $username=$idmap{$found};
6607: if ($found{'ids'}{$found}) {
6608: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
6609: $line,'duplicateID',$found);
1.194 albertel 6610: return(1,$currentphase);
1.157 albertel 6611: } elsif ($found{'usernames'}{$username}) {
6612: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
6613: $line,'duplicateID',$username);
1.194 albertel 6614: return(1,$currentphase);
1.157 albertel 6615: }
1.186 albertel 6616: #FIXME store away line we previously saw the ID on to use above
1.157 albertel 6617: $found{'ids'}{$found}++;
6618: $found{'usernames'}{$username}++;
6619: } else {
6620: if ($id =~ /^\s*$/) {
1.158 albertel 6621: my $username=&scan_data($scan_data,"$i.user");
1.157 albertel 6622: if (defined($username) && $found{'usernames'}{$username}) {
6623: &scantron_get_correction($r,$i,$scan_record,
6624: \%scantron_config,
6625: $line,'duplicateID',$username);
1.194 albertel 6626: return(1,$currentphase);
1.157 albertel 6627: } elsif (!defined($username)) {
6628: &scantron_get_correction($r,$i,$scan_record,
6629: \%scantron_config,
6630: $line,'incorrectID');
1.194 albertel 6631: return(1,$currentphase);
1.157 albertel 6632: }
6633: $found{'usernames'}{$username}++;
6634: } else {
6635: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
6636: $line,'incorrectID');
1.194 albertel 6637: return(1,$currentphase);
1.157 albertel 6638: }
6639: }
6640: }
6641:
6642: return (0,$currentphase+1);
6643: }
6644:
1.423 albertel 6645:
1.157 albertel 6646: sub scantron_get_correction {
6647: my ($r,$i,$scan_record,$scan_config,$line,$error,$arg)=@_;
1.454 banghart 6648: #FIXME in the case of a duplicated ID the previous line, probably need
1.157 albertel 6649: #to show both the current line and the previous one and allow skipping
6650: #the previous one or the current one
6651:
1.333 albertel 6652: if ( $$scan_record{'scantron.PaperID'} =~ /\S/) {
1.492 albertel 6653: $r->print("<p>".&mt("<b>An error was detected ($error)</b>".
6654: " for PaperID <tt>[_1]</tt>",
6655: $$scan_record{'scantron.PaperID'})."</p> \n");
1.157 albertel 6656: } else {
1.492 albertel 6657: $r->print("<p>".&mt("<b>An error was detected ($error)</b>".
6658: " in scanline [_1] <pre>[_2]</pre>",
6659: $i,$line)."</p> \n");
6660: }
6661: my $message="<p>".&mt("The ID on the form is <tt>[_1]</tt><br />".
6662: "The name on the paper is [_2],[_3]",
6663: $$scan_record{'scantron.ID'},
6664: $$scan_record{'scantron.LastName'},
6665: $$scan_record{'scantron.FirstName'})."</p>";
1.242 albertel 6666:
1.157 albertel 6667: $r->print('<input type="hidden" name="scantron_corrections" value="'.$error.'" />'."\n");
6668: $r->print('<input type="hidden" name="scantron_line" value="'.$i.'" />'."\n");
1.503 raeburn 6669: # Array populated for doublebubble or
6670: my @lines_to_correct; # missingbubble errors to build javascript
6671: # to validate radio button checking
6672:
1.157 albertel 6673: if ($error =~ /ID$/) {
1.186 albertel 6674: if ($error eq 'incorrectID') {
1.492 albertel 6675: $r->print("<p>".&mt("The encoded ID is not in the classlist").
6676: "</p>\n");
1.157 albertel 6677: } elsif ($error eq 'duplicateID') {
1.492 albertel 6678: $r->print("<p>".&mt("The encoded ID has also been used by a previous paper [_1]",$arg)."</p>\n");
1.157 albertel 6679: }
1.242 albertel 6680: $r->print($message);
1.492 albertel 6681: $r->print("<p>".&mt("How should I handle this?")." <br /> \n");
1.157 albertel 6682: $r->print("\n<ul><li> ");
6683: #FIXME it would be nice if this sent back the user ID and
6684: #could do partial userID matches
6685: $r->print(&Apache::loncommon::selectstudent_link('scantronupload',
6686: 'scantron_username','scantron_domain'));
6687: $r->print(": <input type='text' name='scantron_username' value='' />");
6688: $r->print("\n@".
1.257 albertel 6689: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'scantron_domain'));
1.157 albertel 6690:
6691: $r->print('</li>');
1.186 albertel 6692: } elsif ($error =~ /CODE$/) {
6693: if ($error eq 'incorrectCODE') {
1.492 albertel 6694: $r->print("<p>".&mt("The encoded CODE is not in the list of possible CODEs.")."</p>\n");
1.186 albertel 6695: } elsif ($error eq 'duplicateCODE') {
1.492 albertel 6696: $r->print("<p>".&mt("The encoded CODE has also been used by a previous paper [_1], and CODEs are supposed to be unique.",join(', ',@{$arg}))."</p>\n");
1.186 albertel 6697: }
1.492 albertel 6698: $r->print("<p>".&mt("The CODE on the form is <tt>'[_1]'</tt>",
6699: $$scan_record{'scantron.CODE'})."<br />\n");
1.242 albertel 6700: $r->print($message);
1.492 albertel 6701: $r->print("<p>".&mt("How should I handle this?")." <br /> \n");
1.187 albertel 6702: $r->print("\n<br /> ");
1.194 albertel 6703: my $i=0;
1.273 albertel 6704: if ($error eq 'incorrectCODE'
6705: && $$scan_record{'scantron.CODE'}=~/\S/ ) {
1.194 albertel 6706: my ($max,$closest)=&scantron_get_closely_matching_CODEs($arg,$$scan_record{'scantron.CODE'});
1.278 albertel 6707: if ($closest > 0) {
6708: foreach my $testcode (@{$closest}) {
6709: my $checked='';
1.401 albertel 6710: if (!$i) { $checked=' checked="checked" '; }
1.492 albertel 6711: $r->print("
6712: <label>
6713: <input type='radio' name='scantron_CODE_resolution' value='use_closest_$i' $checked />
6714: ".&mt("Use the similar CODE [_1] instead.",
6715: "<b><tt>".$testcode."</tt></b>")."
6716: </label>
6717: <input type='hidden' name='scantron_CODE_closest_$i' value='$testcode' />");
1.278 albertel 6718: $r->print("\n<br />");
6719: $i++;
6720: }
1.194 albertel 6721: }
6722: }
1.273 albertel 6723: if ($$scan_record{'scantron.CODE'}=~/\S/ ) {
1.401 albertel 6724: my $checked; if (!$i) { $checked=' checked="checked" '; }
1.492 albertel 6725: $r->print("
6726: <label>
6727: <input type='radio' name='scantron_CODE_resolution' value='use_unfound' $checked />
6728: ".&mt("Use the CODE [_1] that is was on the paper, ignoring the error.",
6729: "<b><tt>".$$scan_record{'scantron.CODE'}."</tt></b>")."
6730: </label>");
1.273 albertel 6731: $r->print("\n<br />");
6732: }
1.194 albertel 6733:
1.188 albertel 6734: $r->print(<<ENDSCRIPT);
6735: <script type="text/javascript">
6736: function change_radio(field) {
1.190 albertel 6737: var slct=document.scantronupload.scantron_CODE_resolution;
1.188 albertel 6738: var i;
6739: for (i=0;i<slct.length;i++) {
6740: if (slct[i].value==field) { slct[i].checked=true; }
6741: }
6742: }
6743: </script>
6744: ENDSCRIPT
1.187 albertel 6745: my $href="/adm/pickcode?".
1.359 www 6746: "form=".&escape("scantronupload").
6747: "&scantron_format=".&escape($env{'form.scantron_format'}).
6748: "&scantron_CODElist=".&escape($env{'form.scantron_CODElist'}).
6749: "&curCODE=".&escape($$scan_record{'scantron.CODE'}).
6750: "&scantron_selectfile=".&escape($env{'form.scantron_selectfile'});
1.332 albertel 6751: if ($env{'form.scantron_CODElist'} =~ /\S/) {
1.492 albertel 6752: $r->print("
6753: <label>
6754: <input type='radio' name='scantron_CODE_resolution' value='use_found' />
6755: ".&mt("[_1]Select[_2] a CODE from the list of all CODEs and use it.",
6756: "<a target='_blank' href='$href'>","</a>")."
6757: </label>
6758: ".&mt("Selected CODE is [_1]","<input readonly='true' type='text' size='8' name='scantron_CODE_selectedvalue' onfocus=\"javascript:change_radio('use_found')\" onchange=\"javascript:change_radio('use_found')\" />"));
1.332 albertel 6759: $r->print("\n<br />");
6760: }
1.492 albertel 6761: $r->print("
6762: <label>
6763: <input type='radio' name='scantron_CODE_resolution' value='use_typed' />
6764: ".&mt("Use [_1] as the CODE.",
6765: "</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 6766: $r->print("\n<br /><br />");
1.157 albertel 6767: } elsif ($error eq 'doublebubble') {
1.503 raeburn 6768: $r->print("<p>".&mt("There have been multiple bubbles scanned for some question(s)")."</p>\n");
1.497 foxr 6769:
6770: # The form field scantron_questions is acutally a list of line numbers.
6771: # represented by this form so:
6772:
6773: my $line_list = &questions_to_line_list($arg);
6774:
1.157 albertel 6775: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 6776: $line_list.'" />');
1.242 albertel 6777: $r->print($message);
1.492 albertel 6778: $r->print("<p>".&mt("Please indicate which bubble should be used for grading")."</p>");
1.157 albertel 6779: foreach my $question (@{$arg}) {
1.503 raeburn 6780: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
6781: $scan_record, $error);
1.524 raeburn 6782: push(@lines_to_correct,@linenums);
1.157 albertel 6783: }
1.503 raeburn 6784: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 6785: } elsif ($error eq 'missingbubble') {
1.492 albertel 6786: $r->print("<p>".&mt("There have been <b>no</b> bubbles scanned for some question(s)")."</p>\n");
1.242 albertel 6787: $r->print($message);
1.492 albertel 6788: $r->print("<p>".&mt("Please indicate which bubble should be used for grading.")."</p>");
1.503 raeburn 6789: $r->print(&mt("Some questions have no scanned bubbles.")."\n");
1.497 foxr 6790:
1.503 raeburn 6791: # The form field scantron_questions is actually a list of line numbers not
1.497 foxr 6792: # a list of question numbers. Therefore:
6793: #
6794:
6795: my $line_list = &questions_to_line_list($arg);
6796:
1.157 albertel 6797: $r->print('<input type="hidden" name="scantron_questions" value="'.
1.497 foxr 6798: $line_list.'" />');
1.157 albertel 6799: foreach my $question (@{$arg}) {
1.503 raeburn 6800: my @linenums = &prompt_for_corrections($r,$question,$scan_config,
6801: $scan_record, $error);
1.524 raeburn 6802: push(@lines_to_correct,@linenums);
1.157 albertel 6803: }
1.503 raeburn 6804: $r->print(&verify_bubbles_checked(@lines_to_correct));
1.157 albertel 6805: } else {
6806: $r->print("\n<ul>");
6807: }
6808: $r->print("\n</li></ul>");
1.497 foxr 6809: }
6810:
1.503 raeburn 6811: sub verify_bubbles_checked {
6812: my (@ansnums) = @_;
6813: my $ansnumstr = join('","',@ansnums);
6814: my $warning = &mt("A bubble or 'No bubble' selection has not been made for one or more lines.");
6815: my $output = (<<ENDSCRIPT);
6816: <script type="text/javascript">
6817: function verify_bubble_radio(form) {
6818: var ansnumArray = new Array ("$ansnumstr");
6819: var need_bubble_count = 0;
6820: for (var i=0; i<ansnumArray.length; i++) {
6821: if (form.elements["scantron_correct_Q_"+ansnumArray[i]].length > 1) {
6822: var bubble_picked = 0;
6823: for (var j=0; j<form.elements["scantron_correct_Q_"+ansnumArray[i]].length; j++) {
6824: if (form.elements["scantron_correct_Q_"+ansnumArray[i]][j].checked == true) {
6825: bubble_picked = 1;
6826: }
6827: }
6828: if (bubble_picked == 0) {
6829: need_bubble_count ++;
6830: }
6831: }
6832: }
6833: if (need_bubble_count) {
6834: alert("$warning");
6835: return;
6836: }
6837: form.submit();
6838: }
6839: </script>
6840: ENDSCRIPT
6841: return $output;
6842: }
6843:
1.497 foxr 6844: =pod
6845:
6846: =item questions_to_line_list
1.157 albertel 6847:
1.497 foxr 6848: Converts a list of questions into a string of comma separated
6849: line numbers in the answer sheet used by the questions. This is
6850: used to fill in the scantron_questions form field.
6851:
6852: Arguments:
6853: questions - Reference to an array of questions.
6854:
6855: =cut
6856:
6857:
6858: sub questions_to_line_list {
6859: my ($questions) = @_;
6860: my @lines;
6861:
1.503 raeburn 6862: foreach my $item (@{$questions}) {
6863: my $question = $item;
6864: my ($first,$count,$last);
6865: if ($item =~ /^(\d+)\.(\d+)$/) {
6866: $question = $1;
6867: my $subquestion = $2;
6868: $first = $first_bubble_line{$question-1} + 1;
6869: my @subans = split(/,/,$subdivided_bubble_lines{$question-1});
6870: my $subcount = 1;
6871: while ($subcount<$subquestion) {
6872: $first += $subans[$subcount-1];
6873: $subcount ++;
6874: }
6875: $count = $subans[$subquestion-1];
6876: } else {
6877: $first = $first_bubble_line{$question-1} + 1;
6878: $count = $bubble_lines_per_response{$question-1};
6879: }
1.506 raeburn 6880: $last = $first+$count-1;
1.503 raeburn 6881: push(@lines, ($first..$last));
1.497 foxr 6882: }
6883: return join(',', @lines);
6884: }
6885:
6886: =pod
6887:
6888: =item prompt_for_corrections
6889:
6890: Prompts for a potentially multiline correction to the
6891: user's bubbling (factors out common code from scantron_get_correction
6892: for multi and missing bubble cases).
6893:
6894: Arguments:
6895: $r - Apache request object.
6896: $question - The question number to prompt for.
6897: $scan_config - The scantron file configuration hash.
6898: $scan_record - Reference to the hash that has the the parsed scanlines.
1.503 raeburn 6899: $error - Type of error
1.497 foxr 6900:
6901: Implicit inputs:
6902: %bubble_lines_per_response - Starting line numbers for each question.
6903: Numbered from 0 (but question numbers are from
6904: 1.
6905: %first_bubble_line - Starting bubble line for each question.
1.509 raeburn 6906: %subdivided_bubble_lines - optionresponse, matchresponse and rankresponse
6907: type problems render as separate sub-questions,
1.503 raeburn 6908: in exam mode. This hash contains a
6909: comma-separated list of the lines per
6910: sub-question.
1.510 raeburn 6911: %responsetype_per_response - essayresponse, formularesponse,
6912: stringresponse, imageresponse, reactionresponse,
6913: and organicresponse type problem parts can have
1.503 raeburn 6914: multiple lines per response if the weight
6915: assigned exceeds 10. In this case, only
6916: one bubble per line is permitted, but more
6917: than one line might contain bubbles, e.g.
6918: bubbling of: line 1 - J, line 2 - J,
6919: line 3 - B would assign 22 points.
1.497 foxr 6920:
6921: =cut
6922:
6923: sub prompt_for_corrections {
1.503 raeburn 6924: my ($r, $question, $scan_config, $scan_record, $error) = @_;
6925: my ($current_line,$lines);
6926: my @linenums;
6927: my $questionnum = $question;
6928: if ($question =~ /^(\d+)\.(\d+)$/) {
6929: $question = $1;
6930: $current_line = $first_bubble_line{$question-1} + 1 ;
6931: my $subquestion = $2;
6932: my @subans = split(/,/,$subdivided_bubble_lines{$question-1});
6933: my $subcount = 1;
6934: while ($subcount<$subquestion) {
6935: $current_line += $subans[$subcount-1];
6936: $subcount ++;
6937: }
6938: $lines = $subans[$subquestion-1];
6939: } else {
6940: $current_line = $first_bubble_line{$question-1} + 1 ;
6941: $lines = $bubble_lines_per_response{$question-1};
6942: }
1.497 foxr 6943: if ($lines > 1) {
1.503 raeburn 6944: $r->print(&mt('The group of bubble lines below responds to a single question.').'<br />');
6945: if (($responsetype_per_response{$question-1} eq 'essayresponse') ||
6946: ($responsetype_per_response{$question-1} eq 'formularesponse') ||
1.510 raeburn 6947: ($responsetype_per_response{$question-1} eq 'stringresponse') ||
6948: ($responsetype_per_response{$question-1} eq 'imageresponse') ||
6949: ($responsetype_per_response{$question-1} eq 'reactionresponse') ||
6950: ($responsetype_per_response{$question-1} eq 'organicresponse')) {
1.503 raeburn 6951: $r->print(&mt("Although this particular question type requires handgrading, the instructions for this question in the exam directed students to leave [quant,_1,line] blank on their scantron sheets.",$lines).'<br /><br />'.&mt('A non-zero score can be assigned to the student during scantron 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 />');
6952: } else {
6953: $r->print(&mt("Select at most one bubble in a single line and select 'No Bubble' in all the other lines. ")."<br />");
6954: }
1.497 foxr 6955: }
6956: for (my $i =0; $i < $lines; $i++) {
1.503 raeburn 6957: my $selected = $$scan_record{"scantron.$current_line.answer"};
6958: &scantron_bubble_selector($r,$scan_config,$current_line,
6959: $questionnum,$error,split('', $selected));
1.524 raeburn 6960: push(@linenums,$current_line);
1.497 foxr 6961: $current_line++;
6962: }
6963: if ($lines > 1) {
6964: $r->print("<hr /><br />");
6965: }
1.503 raeburn 6966: return @linenums;
1.157 albertel 6967: }
1.423 albertel 6968:
6969: =pod
6970:
6971: =item scantron_bubble_selector
6972:
6973: Generates the html radiobuttons to correct a single bubble line
1.424 albertel 6974: possibly showing the existing the selected bubbles if known
1.423 albertel 6975:
6976: Arguments:
6977: $r - Apache request object
6978: $scan_config - hash from &get_scantron_config()
1.497 foxr 6979: $line - Number of the line being displayed.
1.503 raeburn 6980: $questionnum - Question number (may include subquestion)
6981: $error - Type of error.
1.497 foxr 6982: @selected - Array of bubbles picked on this line.
1.423 albertel 6983:
6984: =cut
6985:
1.157 albertel 6986: sub scantron_bubble_selector {
1.503 raeburn 6987: my ($r,$scan_config,$line,$questionnum,$error,@selected)=@_;
1.157 albertel 6988: my $max=$$scan_config{'Qlength'};
1.274 albertel 6989:
6990: my $scmode=$$scan_config{'Qon'};
6991: if ($scmode eq 'number' || $scmode eq 'letter') { $max=10; }
6992:
1.157 albertel 6993: my @alphabet=('A'..'Z');
1.503 raeburn 6994: $r->print(&Apache::loncommon::start_data_table().
6995: &Apache::loncommon::start_data_table_row());
6996: $r->print('<td rowspan="2" class="LC_leftcol_header">'.$line.'</td>');
1.497 foxr 6997: for (my $i=0;$i<$max+1;$i++) {
6998: $r->print("\n".'<td align="center">');
6999: if ($selected[0] eq $alphabet[$i]) { $r->print('X'); shift(@selected) }
7000: else { $r->print(' '); }
7001: $r->print('</td>');
7002: }
1.503 raeburn 7003: $r->print(&Apache::loncommon::end_data_table_row().
7004: &Apache::loncommon::start_data_table_row());
1.497 foxr 7005: for (my $i=0;$i<$max;$i++) {
7006: $r->print("\n".
7007: '<td><label><input type="radio" name="scantron_correct_Q_'.
7008: $line.'" value="'.$i.'" />'.$alphabet[$i]."</label></td>");
7009: }
1.503 raeburn 7010: my $nobub_checked = ' ';
7011: if ($error eq 'missingbubble') {
7012: $nobub_checked = ' checked = "checked" ';
7013: }
7014: $r->print("\n".'<td><label><input type="radio" name="scantron_correct_Q_'.
7015: $line.'" value="none"'.$nobub_checked.'/>'.&mt('No bubble').
7016: '</label>'."\n".'<input type="hidden" name="scantron_questionnum_Q_'.
7017: $line.'" value="'.$questionnum.'" /></td>');
7018: $r->print(&Apache::loncommon::end_data_table_row().
7019: &Apache::loncommon::end_data_table());
1.157 albertel 7020: }
7021:
1.423 albertel 7022: =pod
7023:
7024: =item num_matches
7025:
1.424 albertel 7026: Counts the number of characters that are the same between the two arguments.
7027:
7028: Arguments:
7029: $orig - CODE from the scanline
7030: $code - CODE to match against
7031:
7032: Returns:
7033: $count - integer count of the number of same characters between the
7034: two arguments
7035:
1.423 albertel 7036: =cut
7037:
1.194 albertel 7038: sub num_matches {
7039: my ($orig,$code) = @_;
7040: my @code=split(//,$code);
7041: my @orig=split(//,$orig);
7042: my $same=0;
7043: for (my $i=0;$i<scalar(@code);$i++) {
7044: if ($code[$i] eq $orig[$i]) { $same++; }
7045: }
7046: return $same;
7047: }
7048:
1.423 albertel 7049: =pod
7050:
7051: =item scantron_get_closely_matching_CODEs
7052:
1.424 albertel 7053: Cycles through all CODEs and finds the set that has the greatest
7054: number of same characters as the provided CODE
7055:
7056: Arguments:
7057: $allcodes - hash ref returned by &get_codes()
7058: $CODE - CODE from the current scanline
7059:
7060: Returns:
7061: 2 element list
7062: - first elements is number of how closely matching the best fit is
7063: (5 means best set has 5 matching characters)
7064: - second element is an arrary ref containing the set of valid CODEs
7065: that best fit the passed in CODE
7066:
1.423 albertel 7067: =cut
7068:
1.194 albertel 7069: sub scantron_get_closely_matching_CODEs {
7070: my ($allcodes,$CODE)=@_;
7071: my @CODEs;
7072: foreach my $testcode (sort(keys(%{$allcodes}))) {
7073: push(@{$CODEs[&num_matches($CODE,$testcode)]},$testcode);
7074: }
7075:
7076: return ($#CODEs,$CODEs[-1]);
7077: }
7078:
1.423 albertel 7079: =pod
7080:
7081: =item get_codes
7082:
1.424 albertel 7083: Builds a hash which has keys of all of the valid CODEs from the selected
7084: set of remembered CODEs.
7085:
7086: Arguments:
7087: $old_name - name of the set of remembered CODEs
7088: $cdom - domain of the course
7089: $cnum - internal course name
7090:
7091: Returns:
7092: %allcodes - keys are the valid CODEs, values are all 1
7093:
1.423 albertel 7094: =cut
7095:
1.194 albertel 7096: sub get_codes {
1.280 foxr 7097: my ($old_name, $cdom, $cnum) = @_;
7098: if (!$old_name) {
7099: $old_name=$env{'form.scantron_CODElist'};
7100: }
7101: if (!$cdom) {
7102: $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
7103: }
7104: if (!$cnum) {
7105: $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
7106: }
1.278 albertel 7107: my %result=&Apache::lonnet::get('CODEs',[$old_name,"type\0$old_name"],
7108: $cdom,$cnum);
7109: my %allcodes;
7110: if ($result{"type\0$old_name"} eq 'number') {
7111: %allcodes=map {($_,1)} split(',',$result{$old_name});
7112: } else {
7113: %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
7114: }
1.194 albertel 7115: return %allcodes;
7116: }
7117:
1.423 albertel 7118: =pod
7119:
7120: =item scantron_validate_CODE
7121:
1.424 albertel 7122: Validates all scanlines in the selected file to not have any
7123: invalid or underspecified CODEs and that none of the codes are
7124: duplicated if this was requested.
7125:
1.423 albertel 7126: =cut
7127:
1.157 albertel 7128: sub scantron_validate_CODE {
7129: my ($r,$currentphase) = @_;
1.257 albertel 7130: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.186 albertel 7131: if ($scantron_config{'CODElocation'} &&
7132: $scantron_config{'CODEstart'} &&
7133: $scantron_config{'CODElength'}) {
1.257 albertel 7134: if (!defined($env{'form.scantron_CODElist'})) {
1.186 albertel 7135: &FIXME_blow_up()
7136: }
7137: } else {
7138: return (0,$currentphase+1);
7139: }
7140:
7141: my %usedCODEs;
7142:
1.194 albertel 7143: my %allcodes=&get_codes();
1.186 albertel 7144:
1.447 foxr 7145: &scantron_get_maxbubble(); # parse needs the lines per response array.
7146:
1.186 albertel 7147: my ($scanlines,$scan_data)=&scantron_getfile();
7148: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7149: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.186 albertel 7150: if ($line=~/^[\s\cz]*$/) { next; }
7151: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7152: $scan_data);
7153: my $CODE=$$scan_record{'scantron.CODE'};
7154: my $error=0;
1.224 albertel 7155: if (!&Apache::lonnet::validCODE($CODE)) {
7156: &scantron_get_correction($r,$i,$scan_record,
7157: \%scantron_config,
7158: $line,'incorrectCODE',\%allcodes);
7159: return(1,$currentphase);
7160: }
1.221 albertel 7161: if (%allcodes && !exists($allcodes{$CODE})
7162: && !$$scan_record{'scantron.useCODE'}) {
1.186 albertel 7163: &scantron_get_correction($r,$i,$scan_record,
7164: \%scantron_config,
1.194 albertel 7165: $line,'incorrectCODE',\%allcodes);
7166: return(1,$currentphase);
1.186 albertel 7167: }
1.214 albertel 7168: if (exists($usedCODEs{$CODE})
1.257 albertel 7169: && $env{'form.scantron_CODEunique'} eq 'yes'
1.192 albertel 7170: && !$$scan_record{'scantron.CODE_ignore_dup'}) {
1.186 albertel 7171: &scantron_get_correction($r,$i,$scan_record,
7172: \%scantron_config,
1.194 albertel 7173: $line,'duplicateCODE',$usedCODEs{$CODE});
7174: return(1,$currentphase);
1.186 albertel 7175: }
1.524 raeburn 7176: push(@{$usedCODEs{$CODE}},$$scan_record{'scantron.PaperID'});
1.186 albertel 7177: }
1.157 albertel 7178: return (0,$currentphase+1);
7179: }
7180:
1.423 albertel 7181: =pod
7182:
7183: =item scantron_validate_doublebubble
7184:
1.424 albertel 7185: Validates all scanlines in the selected file to not have any
7186: bubble lines with multiple bubbles marked.
7187:
1.423 albertel 7188: =cut
7189:
1.157 albertel 7190: sub scantron_validate_doublebubble {
7191: my ($r,$currentphase) = @_;
7192: #get student info
7193: my $classlist=&Apache::loncoursedata::get_classlist();
7194: my %idmap=&username_to_idmap($classlist);
7195:
7196: #get scantron line setup
1.257 albertel 7197: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7198: my ($scanlines,$scan_data)=&scantron_getfile();
1.447 foxr 7199: &scantron_get_maxbubble(); # parse needs the bubble line array.
7200:
1.157 albertel 7201: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7202: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7203: if ($line=~/^[\s\cz]*$/) { next; }
7204: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7205: $scan_data);
7206: if (!defined($$scan_record{'scantron.doubleerror'})) { next; }
7207: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,$line,
7208: 'doublebubble',
7209: $$scan_record{'scantron.doubleerror'});
7210: return (1,$currentphase);
7211: }
7212: return (0,$currentphase+1);
7213: }
7214:
1.423 albertel 7215:
1.503 raeburn 7216: sub scantron_get_maxbubble {
1.257 albertel 7217: if (defined($env{'form.scantron_maxbubble'}) &&
7218: $env{'form.scantron_maxbubble'}) {
1.447 foxr 7219: &restore_bubble_lines();
1.257 albertel 7220: return $env{'form.scantron_maxbubble'};
1.191 albertel 7221: }
1.330 albertel 7222:
1.447 foxr 7223: my (undef, undef, $sequence) =
1.257 albertel 7224: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.330 albertel 7225:
1.447 foxr 7226: my $navmap=Apache::lonnavmaps::navmap->new();
1.191 albertel 7227: my $map=$navmap->getResourceByUrl($sequence);
7228: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.330 albertel 7229:
7230: &Apache::lonxml::clear_problem_counter();
7231:
1.435 foxr 7232: my $uname = $env{'form.student'};
7233: my $udom = $env{'form.userdom'};
7234: my $cid = $env{'request.course.id'};
7235: my $total_lines = 0;
7236: %bubble_lines_per_response = ();
1.447 foxr 7237: %first_bubble_line = ();
1.503 raeburn 7238: %subdivided_bubble_lines = ();
7239: %responsetype_per_response = ();
1.447 foxr 7240:
7241: my $response_number = 0;
7242: my $bubble_line = 0;
1.191 albertel 7243: foreach my $resource (@resources) {
1.515 raeburn 7244: my $symb = $resource->symb();
1.523 raeburn 7245:
7246: my (@parts,@allparts,@possible_parts);
7247:
1.510 raeburn 7248: # Need to retrieve part IDs and response IDs because essayresponse,
7249: # reactionresponse and organicresponse items are not included in
7250: # $analysis{'parts'} from lonnet::ssi.
1.523 raeburn 7251: if (ref($resource->parts()) eq 'ARRAY') {
1.503 raeburn 7252: foreach my $part (@{$resource->parts()}) {
1.515 raeburn 7253: if (!&Apache::loncommon::check_if_partid_hidden($part,$symb,$udom,$uname)) {
7254: my @resp_ids = $resource->responseIds($part);
7255: foreach my $id (@resp_ids) {
1.523 raeburn 7256: my $part_id = $part.'.'.$id;
7257: push(@possible_parts,$part_id);
1.515 raeburn 7258: }
1.503 raeburn 7259: }
7260: }
7261: }
1.435 foxr 7262:
1.523 raeburn 7263: my $result=&ssi_with_retries($resource->src(), $ssi_retries,
7264: ('symb' => $symb,
7265: 'grade_target' => 'analyze',
7266: 'grade_courseid' => $cid,
7267: 'grade_domain' => $udom,
7268: 'grade_username' => $uname));
7269: my (undef, $an) =
7270: split(/_HASH_REF__/,$result, 2);
1.503 raeburn 7271:
1.435 foxr 7272: my %analysis = &Apache::lonnet::str2hash($an);
7273:
1.503 raeburn 7274: if (ref($analysis{'parts'}) eq 'ARRAY') {
1.515 raeburn 7275: foreach my $part (@{$analysis{'parts'}}) {
7276: my ($id,$respid) = split(/\./,$part);
7277: if (!&Apache::loncommon::check_if_partid_hidden($id,$symb,$udom,$uname)) {
7278: push(@parts,$part);
7279: }
7280: }
1.503 raeburn 7281: }
1.523 raeburn 7282: # Add part_ids for any essayresponse, reactionresponse or
7283: # organicresponse items.
7284: foreach my $part_id (@possible_parts) {
7285: if (grep(/^\Q$part_id\E$/,@parts)) {
7286: push(@allparts,$part_id);
7287: } else {
7288: if (($analysis{$part_id.'.type'} eq 'essayresponse') ||
7289: ($analysis{$part_id.'.type'} eq 'reactionresponse') ||
7290: ($analysis{$part_id.'.type'} eq 'organicresponse')) {
1.524 raeburn 7291: push(@allparts,$part_id);
1.503 raeburn 7292: }
7293: }
7294: }
1.435 foxr 7295:
1.523 raeburn 7296: foreach my $part_id (@allparts) {
7297: my $lines;
1.447 foxr 7298:
7299: # TODO - make this a persistent hash not an array.
7300:
1.509 raeburn 7301: # optionresponse, matchresponse and rankresponse type items
7302: # render as separate sub-questions in exam mode.
1.503 raeburn 7303: if (($analysis{$part_id.'.type'} eq 'optionresponse') ||
1.509 raeburn 7304: ($analysis{$part_id.'.type'} eq 'matchresponse') ||
7305: ($analysis{$part_id.'.type'} eq 'rankresponse')) {
1.503 raeburn 7306: my ($numbub,$numshown);
7307: if ($analysis{$part_id.'.type'} eq 'optionresponse') {
7308: if (ref($analysis{$part_id.'.options'}) eq 'ARRAY') {
7309: $numbub = scalar(@{$analysis{$part_id.'.options'}});
7310: }
7311: } elsif ($analysis{$part_id.'.type'} eq 'matchresponse') {
7312: if (ref($analysis{$part_id.'.items'}) eq 'ARRAY') {
7313: $numbub = scalar(@{$analysis{$part_id.'.items'}});
7314: }
1.509 raeburn 7315: } elsif ($analysis{$part_id.'.type'} eq 'rankresponse') {
7316: if (ref($analysis{$part_id.'.foils'}) eq 'ARRAY') {
7317: $numbub = scalar(@{$analysis{$part_id.'.foils'}});
7318: }
1.503 raeburn 7319: }
7320: if (ref($analysis{$part_id.'.shown'}) eq 'ARRAY') {
7321: $numshown = scalar(@{$analysis{$part_id.'.shown'}});
7322: }
7323: my $bubbles_per_line = 10;
1.523 raeburn 7324: my $inner_bubble_lines = int($numbub/$bubbles_per_line);
7325: if (($numbub % $bubbles_per_line) != 0) {
1.503 raeburn 7326: $inner_bubble_lines++;
7327: }
7328: for (my $i=0; $i<$numshown; $i++) {
7329: $subdivided_bubble_lines{$response_number} .=
7330: $inner_bubble_lines.',';
7331: }
7332: $subdivided_bubble_lines{$response_number} =~ s/,$//;
1.523 raeburn 7333: $lines = $numshown * $inner_bubble_lines;
7334: } else {
7335: $lines = $analysis{"$part_id.bubble_lines"};
1.503 raeburn 7336: }
1.447 foxr 7337:
1.503 raeburn 7338: $first_bubble_line{$response_number} = $bubble_line;
7339: $bubble_lines_per_response{$response_number} = $lines;
7340: $responsetype_per_response{$response_number} =
7341: $analysis{$part_id.'.type'};
1.447 foxr 7342: $response_number++;
7343:
7344: $bubble_line += $lines;
7345: $total_lines += $lines;
1.435 foxr 7346: }
7347:
1.191 albertel 7348: }
7349: &Apache::lonnet::delenv('scantron\.');
1.447 foxr 7350:
7351: &save_bubble_lines();
1.330 albertel 7352: $env{'form.scantron_maxbubble'} =
1.435 foxr 7353: $total_lines;
1.257 albertel 7354: return $env{'form.scantron_maxbubble'};
1.191 albertel 7355: }
7356:
1.423 albertel 7357:
1.157 albertel 7358: sub scantron_validate_missingbubbles {
7359: my ($r,$currentphase) = @_;
7360: #get student info
7361: my $classlist=&Apache::loncoursedata::get_classlist();
7362: my %idmap=&username_to_idmap($classlist);
7363:
7364: #get scantron line setup
1.257 albertel 7365: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7366: my ($scanlines,$scan_data)=&scantron_getfile();
1.191 albertel 7367: my $max_bubble=&scantron_get_maxbubble();
1.157 albertel 7368: if (!$max_bubble) { $max_bubble=2**31; }
7369: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 7370: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7371: if ($line=~/^[\s\cz]*$/) { next; }
7372: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7373: $scan_data);
7374: if (!defined($$scan_record{'scantron.missingerror'})) { next; }
7375: my @to_correct;
1.470 foxr 7376:
7377: # Probably here's where the error is...
7378:
1.157 albertel 7379: foreach my $missing (@{$$scan_record{'scantron.missingerror'}}) {
1.505 raeburn 7380: my $lastbubble;
7381: if ($missing =~ /^(\d+)\.(\d+)$/) {
7382: my $question = $1;
7383: my $subquestion = $2;
7384: if (!defined($first_bubble_line{$question -1})) { next; }
7385: my $first = $first_bubble_line{$question-1};
7386: my @subans = split(/,/,$subdivided_bubble_lines{$question-1});
7387: my $subcount = 1;
7388: while ($subcount<$subquestion) {
7389: $first += $subans[$subcount-1];
7390: $subcount ++;
7391: }
7392: my $count = $subans[$subquestion-1];
7393: $lastbubble = $first + $count;
7394: } else {
7395: if (!defined($first_bubble_line{$missing - 1})) { next; }
7396: $lastbubble = $first_bubble_line{$missing - 1} + $bubble_lines_per_response{$missing - 1};
7397: }
7398: if ($lastbubble > $max_bubble) { next; }
1.157 albertel 7399: push(@to_correct,$missing);
7400: }
7401: if (@to_correct) {
7402: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
7403: $line,'missingbubble',\@to_correct);
7404: return (1,$currentphase);
7405: }
7406:
7407: }
7408: return (0,$currentphase+1);
7409: }
7410:
1.423 albertel 7411:
1.82 albertel 7412: sub scantron_process_students {
1.75 albertel 7413: my ($r) = @_;
1.513 foxr 7414:
1.257 albertel 7415: my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($env{'form.selectpage'});
1.324 albertel 7416: my ($symb)=&get_symb($r);
1.513 foxr 7417: if (!$symb) {
7418: return '';
7419: }
1.324 albertel 7420: my $default_form_data=&defaultFormData($symb);
1.82 albertel 7421:
1.257 albertel 7422: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 7423: my ($scanlines,$scan_data)=&scantron_getfile();
1.82 albertel 7424: my $classlist=&Apache::loncoursedata::get_classlist();
7425: my %idmap=&username_to_idmap($classlist);
1.132 bowersj2 7426: my $navmap=Apache::lonnavmaps::navmap->new();
1.83 albertel 7427: my $map=$navmap->getResourceByUrl($sequence);
7428: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.140 albertel 7429: # $r->print("geto ".scalar(@resources)."<br />");
1.82 albertel 7430: my $result= <<SCANTRONFORM;
1.81 albertel 7431: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
7432: <input type="hidden" name="command" value="scantron_configphase" />
7433: $default_form_data
7434: SCANTRONFORM
1.82 albertel 7435: $r->print($result);
7436:
7437: my @delayqueue;
1.140 albertel 7438: my %completedstudents;
7439:
1.520 www 7440: my $lock=&Apache::lonnet::set_lock(&mt('Grading bubblesheet exam'));
1.200 albertel 7441: my $count=&get_todo_count($scanlines,$scan_data);
1.157 albertel 7442: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Scantron Status',
1.200 albertel 7443: 'Scantron Progress',$count,
1.195 albertel 7444: 'inline',undef,'scantronupload');
1.140 albertel 7445: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
7446: 'Processing first student');
7447: my $start=&Time::HiRes::time();
1.158 albertel 7448: my $i=-1;
1.200 albertel 7449: my ($uname,$udom,$started);
1.447 foxr 7450:
7451: &scantron_get_maxbubble(); # Need the bubble lines array to parse.
1.513 foxr 7452:
7453:
7454: # If an ssi failed in scantron_get_maxbubble, put an error message out to
7455: # the user and return.
7456:
7457: if ($ssi_error) {
7458: $r->print("</form>");
7459: &ssi_print_error($r);
7460: $r->print(&show_grading_menu_form($symb));
1.520 www 7461: &Apache::lonnet::remove_lock($lock);
1.513 foxr 7462: return ''; # Dunno why the other returns return '' rather than just returning.
7463: }
1.447 foxr 7464:
1.157 albertel 7465: while ($i<$scanlines->{'count'}) {
7466: ($uname,$udom)=('','');
7467: $i++;
1.200 albertel 7468: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 7469: if ($line=~/^[\s\cz]*$/) { next; }
1.200 albertel 7470: if ($started) {
7471: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
7472: 'last student');
7473: }
7474: $started=1;
1.157 albertel 7475: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
7476: $scan_data);
7477: unless ($uname=&scantron_find_student($scan_record,$scan_data,
7478: \%idmap,$i)) {
7479: &scantron_add_delay(\@delayqueue,$line,
7480: 'Unable to find a student that matches',1);
7481: next;
7482: }
7483: if (exists $completedstudents{$uname}) {
7484: &scantron_add_delay(\@delayqueue,$line,
7485: 'Student '.$uname.' has multiple sheets',2);
7486: next;
7487: }
7488: ($uname,$udom)=split(/:/,$uname);
1.330 albertel 7489:
7490: &Apache::lonxml::clear_problem_counter();
1.514 raeburn 7491: &Apache::lonnet::appenv($scan_record);
1.376 albertel 7492:
7493: if (&scantron_clear_skip($scanlines,$scan_data,$i)) {
7494: &scantron_putfile($scanlines,$scan_data);
7495: }
1.161 albertel 7496:
7497: my $i=0;
1.83 albertel 7498: foreach my $resource (@resources) {
1.85 albertel 7499: $i++;
1.193 albertel 7500: my %form=('submitted' =>'scantron',
7501: 'grade_target' =>'grade',
7502: 'grade_username'=>$uname,
7503: 'grade_domain' =>$udom,
1.257 albertel 7504: 'grade_courseid'=>$env{'request.course.id'},
1.193 albertel 7505: 'grade_symb' =>$resource->symb());
1.383 albertel 7506: if (exists($scan_record->{'scantron.CODE'})
7507: &&
7508: &Apache::lonnet::validCODE($scan_record->{'scantron.CODE'})) {
1.193 albertel 7509: $form{'CODE'}=$scan_record->{'scantron.CODE'};
1.224 albertel 7510: } else {
7511: $form{'CODE'}='';
1.513 foxr 7512: }
7513: my $result=&ssi_with_retries($resource->src(), $ssi_retries, %form);
7514: if ($ssi_error) {
7515: $ssi_error = 0; # So end of handler error message does not trigger.
7516: $r->print("</form>");
7517: &ssi_print_error($r);
7518: $r->print(&show_grading_menu_form($symb));
1.520 www 7519: &Apache::lonnet::remove_lock($lock);
1.513 foxr 7520: return ''; # Why return ''? Beats me.
1.193 albertel 7521: }
1.513 foxr 7522:
1.213 albertel 7523: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.83 albertel 7524: }
1.140 albertel 7525: $completedstudents{$uname}={'line'=>$line};
1.213 albertel 7526: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.140 albertel 7527: } continue {
1.330 albertel 7528: &Apache::lonxml::clear_problem_counter();
1.83 albertel 7529: &Apache::lonnet::delenv('scantron\.');
1.82 albertel 7530: }
1.140 albertel 7531: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.520 www 7532: &Apache::lonnet::remove_lock($lock);
1.172 albertel 7533: # my $lasttime = &Time::HiRes::time()-$start;
7534: # $r->print("<p>took $lasttime</p>");
1.140 albertel 7535:
1.200 albertel 7536: $r->print("</form>");
1.324 albertel 7537: $r->print(&show_grading_menu_form($symb));
1.157 albertel 7538: return '';
1.75 albertel 7539: }
1.157 albertel 7540:
7541: sub scantron_upload_scantron_data {
7542: my ($r)=@_;
1.257 albertel 7543: $r->print(&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'}));
1.157 albertel 7544: my $select_link=&Apache::loncommon::selectcourse_link('rules','courseid',
1.181 albertel 7545: 'domainid',
7546: 'coursename');
1.257 albertel 7547: my $domsel=&Apache::loncommon::select_dom_form($env{'request.role.domain'},
1.157 albertel 7548: 'domainid');
1.324 albertel 7549: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.492 albertel 7550: $r->print('
1.157 albertel 7551: <script type="text/javascript" language="javascript">
7552: function checkUpload(formname) {
7553: if (formname.upfile.value == "") {
1.539 ! riegler 7554: alert("'.&mt('Please use the browse button to select a file from your local directory.').'");
1.157 albertel 7555: return false;
7556: }
7557: formname.submit();
7558: }
7559: </script>
7560:
1.492 albertel 7561: <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
7562: '.$default_form_data.'
1.181 albertel 7563: <table>
1.492 albertel 7564: <tr><td>'.$select_link.' </td></tr>
7565: <tr><td>'.&mt('Course ID:').' </td>
7566: <td><input name="courseid" type="text" /> </td></tr>
7567: <tr><td>'.&mt('Course Name:').' </td>
7568: <td><input name="coursename" type="text" /> </td></tr>
7569: <tr><td>'.&mt('Domain:').' </td>
7570: <td>'.$domsel.' </td></tr>
7571: <tr><td>'.&mt('File to upload:').'</td>
7572: <td><input type="file" name="upfile" size="50" /></td></tr>
1.181 albertel 7573: </table>
1.492 albertel 7574: <input name="command" value="scantronupload_save" type="hidden" />
7575: <input type="button" onClick="javascript:checkUpload(this.form);" value="'.&mt('Upload Scantron Data').'" />
1.157 albertel 7576: </form>
1.492 albertel 7577: ');
1.157 albertel 7578: return '';
7579: }
7580:
1.423 albertel 7581:
1.157 albertel 7582: sub scantron_upload_scantron_data_save {
7583: my($r)=@_;
1.324 albertel 7584: my ($symb)=&get_symb($r,1);
1.182 albertel 7585: my $doanotherupload=
7586: '<br /><form action="/adm/grades" method="post">'."\n".
7587: '<input type="hidden" name="command" value="scantronupload" />'."\n".
1.492 albertel 7588: '<input type="submit" name="submit" value="'.&mt('Do Another Upload').'" />'."\n".
1.182 albertel 7589: '</form>'."\n";
1.257 albertel 7590: if (!&Apache::lonnet::allowed('usc',$env{'form.domainid'}) &&
1.162 albertel 7591: !&Apache::lonnet::allowed('usc',
1.257 albertel 7592: $env{'form.domainid'}.'_'.$env{'form.courseid'})) {
1.492 albertel 7593: $r->print(&mt("You are not allowed to upload Scantron data to the requested course.")."<br />");
1.182 albertel 7594: if ($symb) {
1.324 albertel 7595: $r->print(&show_grading_menu_form($symb));
1.182 albertel 7596: } else {
7597: $r->print($doanotherupload);
7598: }
1.162 albertel 7599: return '';
7600: }
1.257 albertel 7601: my %coursedata=&Apache::lonnet::coursedescription($env{'form.domainid'}.'_'.$env{'form.courseid'});
1.492 albertel 7602: $r->print(&mt("Doing upload to [_1]",$coursedata{'description'})." <br />");
1.257 albertel 7603: my $fname=$env{'form.upfile.filename'};
1.157 albertel 7604: #FIXME
7605: #copied from lonnet::userfileupload()
7606: #make that function able to target a specified course
7607: # Replace Windows backslashes by forward slashes
7608: $fname=~s/\\/\//g;
7609: # Get rid of everything but the actual filename
7610: $fname=~s/^.*\/([^\/]+)$/$1/;
7611: # Replace spaces by underscores
7612: $fname=~s/\s+/\_/g;
7613: # Replace all other weird characters by nothing
7614: $fname=~s/[^\w\.\-]//g;
7615: # See if there is anything left
7616: unless ($fname) { return 'error: no uploaded file'; }
1.209 ng 7617: my $uploadedfile=$fname;
1.157 albertel 7618: $fname='scantron_orig_'.$fname;
1.257 albertel 7619: if (length($env{'form.upfile'}) < 2) {
1.492 albertel 7620: $r->print(&mt("<span class=\"LC_error\">Error:</span> The file you attempted to upload, [_1] contained no information. Please check that you entered the correct filename.",'<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"')."</span>"));
1.183 albertel 7621: } else {
1.275 albertel 7622: my $result=&Apache::lonnet::finishuserfileupload($env{'form.courseid'},$env{'form.domainid'},'upfile',$fname);
1.210 albertel 7623: if ($result =~ m|^/uploaded/|) {
1.492 albertel 7624: $r->print(&mt("<span class=\"LC_success\">Success:</span> Successfully uploaded [_1] bytes of data into location [_2]",
7625: (length($env{'form.upfile'})-1),
7626: '<span class="LC_filename">'.$result."</span>"));
1.210 albertel 7627: } else {
1.492 albertel 7628: $r->print(&mt("<span class=\"LC_error\">Error:</span> An error ([_1]) occurred when attempting to upload the file, [_2]",
7629: $result,
7630: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"')."</span>"));
7631:
1.183 albertel 7632: }
7633: }
1.174 albertel 7634: if ($symb) {
1.209 ng 7635: $r->print(&scantron_selectphase($r,$uploadedfile));
1.174 albertel 7636: } else {
1.182 albertel 7637: $r->print($doanotherupload);
1.174 albertel 7638: }
1.157 albertel 7639: return '';
7640: }
7641:
1.202 albertel 7642: sub valid_file {
7643: my ($requested_file)=@_;
7644: foreach my $filename (sort(&scantron_filenames())) {
7645: if ($requested_file eq $filename) { return 1; }
7646: }
7647: return 0;
7648: }
7649:
7650: sub scantron_download_scantron_data {
7651: my ($r)=@_;
1.324 albertel 7652: my $default_form_data=&defaultFormData(&get_symb($r,1));
1.257 albertel 7653: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
7654: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7655: my $file=$env{'form.scantron_selectfile'};
1.202 albertel 7656: if (! &valid_file($file)) {
1.492 albertel 7657: $r->print('
1.202 albertel 7658: <p>
1.492 albertel 7659: '.&mt('The requested file name was invalid.').'
1.202 albertel 7660: </p>
1.492 albertel 7661: ');
1.324 albertel 7662: $r->print(&show_grading_menu_form(&get_symb($r,1)));
1.202 albertel 7663: return;
7664: }
7665: my $orig='/uploaded/'.$cdom.'/'.$cname.'/scantron_orig_'.$file;
7666: my $corrected='/uploaded/'.$cdom.'/'.$cname.'/scantron_corrected_'.$file;
7667: my $skipped='/uploaded/'.$cdom.'/'.$cname.'/scantron_skipped_'.$file;
7668: &Apache::lonnet::allowuploaded('/adm/grades',$orig);
7669: &Apache::lonnet::allowuploaded('/adm/grades',$corrected);
7670: &Apache::lonnet::allowuploaded('/adm/grades',$skipped);
1.492 albertel 7671: $r->print('
1.202 albertel 7672: <p>
1.492 albertel 7673: '.&mt('[_1]Original[_2] file as uploaded by the scantron office.',
7674: '<a href="'.$orig.'">','</a>').'
1.202 albertel 7675: </p>
7676: <p>
1.492 albertel 7677: '.&mt('[_1]Corrections[_2], a file of corrected records that were used in grading.',
7678: '<a href="'.$corrected.'">','</a>').'
1.202 albertel 7679: </p>
7680: <p>
1.492 albertel 7681: '.&mt('[_1]Skipped[_2], a file of records that were skipped.',
7682: '<a href="'.$skipped.'">','</a>').'
1.202 albertel 7683: </p>
1.492 albertel 7684: ');
1.324 albertel 7685: $r->print(&show_grading_menu_form(&get_symb($r,1)));
1.202 albertel 7686: return '';
7687: }
1.157 albertel 7688:
1.523 raeburn 7689: sub checkscantron_results {
7690: my ($r) = @_;
7691: my ($symb)=&get_symb($r);
7692: if (!$symb) {return '';}
7693: my $grading_menu_button=&show_grading_menu_form($symb);
7694: my $cid = $env{'request.course.id'};
7695: my %lettdig = (
7696: A => 1,
7697: B => 2,
7698: C => 3,
7699: D => 4,
7700: E => 5,
7701: F => 6,
7702: G => 7,
7703: H => 8,
7704: I => 9,
7705: J => 0,
7706: );
7707: my $numletts = scalar(keys(%lettdig));
7708: my $cnum = $env{'course.'.$cid.'.num'};
7709: my $cdom = $env{'course.'.$cid.'.domain'};
7710: my (undef, undef, $sequence) = &Apache::lonnet::decode_symb($env{'form.selectpage'});
7711: my %record;
7712: my %scantron_config =
7713: &Apache::grades::get_scantron_config($env{'form.scantron_format'});
7714: my ($scanlines,$scan_data)=&Apache::grades::scantron_getfile();
7715: my $classlist=&Apache::loncoursedata::get_classlist();
7716: my %idmap=&Apache::grades::username_to_idmap($classlist);
7717: my $navmap=Apache::lonnavmaps::navmap->new();
7718: my $map=$navmap->getResourceByUrl($sequence);
7719: my @resources=$navmap->retrieveResources($map,undef,1,0);
7720: my (%scandata,%lastname,%bylast);
7721: $r->print('
7722: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="checkscantron">'."\n");
7723:
7724: my @delayqueue;
7725: my %completedstudents;
7726:
7727: my $count=&Apache::grades::get_todo_count($scanlines,$scan_data);
7728: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Scantron/Submissions Comparison Status',
7729: 'Progress of Scantron Data/Submission Records Comparison',$count,
7730: 'inline',undef,'checkscantron');
7731: my ($username,$domain,$uname,$started);
7732:
7733: &Apache::grades::scantron_get_maxbubble(); # Need the bubble lines array to parse.
7734:
7735: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
7736: 'Processing first student');
7737: my $start=&Time::HiRes::time();
7738: my $i=-1;
7739:
7740: while ($i<$scanlines->{'count'}) {
7741: ($username,$domain,$uname)=('','','');
7742: $i++;
7743: my $line=&Apache::grades::scantron_get_line($scanlines,$scan_data,$i);
7744: if ($line=~/^[\s\cz]*$/) { next; }
7745: if ($started) {
7746: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
7747: 'last student');
7748: }
7749: $started=1;
7750: my $scan_record=
7751: &Apache::grades::scantron_parse_scanline($line,$i,\%scantron_config,
7752: $scan_data);
7753: unless ($uname=&Apache::grades::scantron_find_student($scan_record,$scan_data,
7754: \%idmap,$i)) {
7755: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
7756: 'Unable to find a student that matches',1);
7757: next;
7758: }
7759: if (exists $completedstudents{$uname}) {
7760: &Apache::grades::scantron_add_delay(\@delayqueue,$line,
7761: 'Student '.$uname.' has multiple sheets',2);
7762: next;
7763: }
7764: my $pid = $scan_record->{'scantron.ID'};
7765: $lastname{$pid} = $scan_record->{'scantron.LastName'};
7766: push(@{$bylast{$lastname{$pid}}},$pid);
7767: my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'};
7768: $scandata{$pid} = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
7769: chomp($scandata{$pid});
7770: $scandata{$pid} =~ s/\r$//;
7771: ($username,$domain)=split(/:/,$uname);
7772: my $counter = -1;
7773: my (%expected,%startpos);
7774: foreach my $resource (@resources) {
7775: next if (!$resource->is_problem());
7776: my $symb = $resource->symb();
7777: my $partsref = $resource->parts();
7778: my @parts;
7779: my @part_ids = ();
7780: if (ref($partsref) eq 'ARRAY') {
7781: @parts = @{$partsref};
7782: foreach my $part (@parts) {
7783: my @resp_ids = $resource->responseIds($part);
7784: foreach my $resp (@resp_ids) {
7785: $counter ++;
7786: my $part_id = $part.'.'.$resp;
7787: $expected{$part_id} = 0;
7788: push(@part_ids,$part_id);
7789: if ($env{"form.scantron.sub_bubblelines.$counter"}) {
7790: my @sub_lines = split(/,/,$env{"form.scantron.sub_bubblelines.$counter"});
7791: foreach my $item (@sub_lines) {
7792: $expected{$part_id} += $item;
7793: }
7794: } else {
7795: $expected{$part_id} = $env{"form.scantron.bubblelines.$counter"};
7796: }
7797: $startpos{$part_id} = $env{"form.scantron.first_bubble_line.$counter"};
7798: }
7799: }
7800: }
7801: if ($symb) {
7802: my %recorded;
7803: my (%returnhash) =
7804: &Apache::lonnet::restore($symb,$cid,$domain,$username);
7805: if ($returnhash{'version'}) {
7806: my %lasthash=();
7807: my $version;
7808: for ($version=1;$version<=$returnhash{'version'};$version++) {
7809: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
7810: $lasthash{$key}=$returnhash{$version.':'.$key};
7811: }
7812: }
7813: foreach my $key (keys(%lasthash)) {
7814: if ($key =~ /\.scantron$/) {
7815: my $value = &unescape($lasthash{$key});
7816: my ($part_id) = ($key =~ /^resource\.(.+)\.scantron$/);
7817: if ($value eq '') {
7818: for (my $i=0; $i<$expected{$part_id}; $i++) {
7819: for (my $j=0; $j<$scantron_config{'length'}; $j++) {
7820: $recorded{$part_id} .= $;
7821: }
7822: }
7823: } else {
7824: my @tocheck;
7825: my @items = split(//,$value);
7826: if (($scantron_config{'Qon'} eq 'letter') ||
7827: ($scantron_config{'Qon'} eq 'number')) {
7828: if (@items < $expected{$part_id}) {
7829: my $fragment = substr($scandata{$pid},$startpos{$part_id},$expected{$part_id});
7830: my @singles = split(//,$fragment);
7831: foreach my $pos (@singles) {
7832: if ($pos eq ' ') {
7833: push(@tocheck,$pos);
7834: } else {
7835: my $next = shift(@items);
7836: push(@tocheck,$next);
7837: }
7838: }
7839: } else {
7840: @tocheck = @items;
7841: }
7842: foreach my $letter (@tocheck) {
7843: if ($scantron_config{'Qon'} eq 'letter') {
7844: if ($letter !~ /^[A-J]$/) {
7845: $letter = $scantron_config{'Qoff'};
7846: }
7847: $recorded{$part_id} .= $letter;
7848: } elsif ($scantron_config{'Qon'} eq 'number') {
7849: my $digit;
7850: if ($letter !~ /^[A-J]$/) {
7851: $digit = $scantron_config{'Qoff'};
7852: } else {
7853: $digit = $lettdig{$letter};
7854: }
7855: $recorded{$part_id} .= $digit;
7856: }
7857: }
7858: } else {
7859: @tocheck = @items;
7860: for (my $i=0; $i<$expected{$part_id}; $i++) {
7861: my $curr_sub = shift(@tocheck);
7862: my $digit;
7863: if ($curr_sub =~ /^[A-J]$/) {
7864: $digit = $lettdig{$curr_sub}-1;
7865: }
7866: if ($curr_sub eq 'J') {
7867: $digit += scalar($numletts);
7868: }
7869: for (my $j=0; $j<$scantron_config{'Qlength'}; $j++) {
7870: if ($j == $digit) {
7871: $recorded{$part_id} .= $scantron_config{'Qon'};
7872: } else {
7873: $recorded{$part_id} .= $scantron_config{'Qoff'};
7874: }
7875: }
7876: }
7877: }
7878: }
7879: }
7880: }
7881: }
7882: foreach my $part_id (@part_ids) {
7883: if ($recorded{$part_id} eq '') {
7884: for (my $i=0; $i<$expected{$part_id}; $i++) {
7885: for (my $j=0; $j<$scantron_config{'Qlength'}; $j++) {
7886: $recorded{$part_id} .= $scantron_config{'Qoff'};
7887: }
7888: }
7889: }
7890: $record{$pid} .= $recorded{$part_id};
7891: }
7892: }
7893: }
7894: }
7895: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
7896: $r->print('<br />');
7897: my ($okstudents,$badstudents,$numstudents,$passed,$failed);
7898: $passed = 0;
7899: $failed = 0;
7900: $numstudents = 0;
7901: foreach my $last (sort(keys(%bylast))) {
7902: if (ref($bylast{$last}) eq 'ARRAY') {
7903: foreach my $pid (sort(@{$bylast{$last}})) {
7904: my $showscandata = $scandata{$pid};
7905: my $showrecord = $record{$pid};
7906: $showscandata =~ s/\s/ /g;
7907: $showrecord =~ s/\s/ /g;
7908: if ($scandata{$pid} eq $record{$pid}) {
7909: my $css_class = ($passed % 2)?'LC_odd_row':'LC_even_row';
7910: $okstudents .= '<tr class="'.$css_class.'">'.
7911: '<td>'.&mt('Scantron').'</td><td>'.$showscandata.'</td><td rowspan="2">'.$last.'</td><td rowspan="2">'.$pid.'</td>'."\n".
7912: '</tr>'."\n".
7913: '<tr class="'.$css_class.'">'."\n".
7914: '<td>Submissions</td><td>'.$showrecord.'</td></tr>'."\n";
7915: $passed ++;
7916: } else {
7917: my $css_class = ($failed % 2)?'LC_odd_row':'LC_even_row';
7918: $badstudents .= '<tr class="'.$css_class.'"><td>'.&mt('Scantron').'</td><td><span class="LC_nobreak">'.$scandata{$pid}.'</span></td><td rowspan="2">'.$last.'</td><td rowspan="2">'.$pid.'</td>'."\n".
7919: '</tr>'."\n".
7920: '<tr class="'.$css_class.'">'."\n".
7921: '<td>Submissions</td><td><span class="LC_nobreak">'.$record{$pid}.'</span></td>'."\n".
7922: '</tr>'."\n";
7923: $failed ++;
7924: }
7925: $numstudents ++;
7926: }
7927: }
7928: }
7929: $r->print('<p>'.&mt('Comparison of scantron data (including corrections) with corresponding submission records (most recent submission) for <b>[quant,_1,student]</b> ([_2] scantron lines/student).',$numstudents,$env{'form.scantron_maxbubble'}).'</p>');
7930: $r->print('<p>'.&mt('Exact matches for <b>[quant,_1,student]</b>.',$passed).'<br />'.&mt('Discrepancies detected for <b>[quant,_1,student]</b>.',$failed).'</p>');
7931: if ($passed) {
7932: $r->print(&mt('Students with exact correspondence between scantron data and submissions are as follows:').'<br /><br />');
7933: $r->print(&Apache::loncommon::start_data_table()."\n".
7934: &Apache::loncommon::start_data_table_header_row()."\n".
7935: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
7936: &Apache::loncommon::end_data_table_header_row()."\n".
7937: $okstudents."\n".
7938: &Apache::loncommon::end_data_table().'<br />');
7939: }
7940: if ($failed) {
7941: $r->print(&mt('Students with differences between scantron data and submissions are as follows:').'<br /><br />');
7942: $r->print(&Apache::loncommon::start_data_table()."\n".
7943: &Apache::loncommon::start_data_table_header_row()."\n".
7944: '<th>'.&mt('Source').'</th><th>'.&mt('Bubble records').'</th><th>'.&mt('Name').'</th><th>'.&mt('ID').'</th>'.
7945: &Apache::loncommon::end_data_table_header_row()."\n".
7946: $badstudents."\n".
7947: &Apache::loncommon::end_data_table()).'<br />'.
7948: &mt('Differences can occur if submissions were modified using manual grading after a scantron grading pass.').'<br />'.&mt('If unexpected discrepancies were detected, it is recommended that you inspect the original scantron sheets.');
7949: }
7950: $r->print('</form><br />'.$grading_menu_button);
7951: return;
7952: }
7953:
1.423 albertel 7954:
1.75 albertel 7955: #-------- end of section for handling grading scantron forms -------
7956: #
7957: #-------------------------------------------------------------------
7958:
1.72 ng 7959: #-------------------------- Menu interface -------------------------
7960: #
7961: #--- Show a Grading Menu button - Calls the next routine ---
7962: sub show_grading_menu_form {
1.324 albertel 7963: my ($symb)=@_;
1.125 ng 7964: my $result.='<br /><form action="/adm/grades" method="post">'."\n".
1.418 albertel 7965: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.257 albertel 7966: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.72 ng 7967: '<input type="hidden" name="command" value="gradingmenu" />'."\n".
1.478 albertel 7968: '<input type="submit" name="submit" value="'.&mt('Grading Menu').'" />'."\n".
1.72 ng 7969: '</form>'."\n";
7970: return $result;
7971: }
7972:
1.77 ng 7973: # -- Retrieve choices for grading form
7974: sub savedState {
7975: my %savedState = ();
1.257 albertel 7976: if ($env{'form.saveState'}) {
7977: foreach (split(/:/,$env{'form.saveState'})) {
1.77 ng 7978: my ($key,$value) = split(/=/,$_,2);
7979: $savedState{$key} = $value;
7980: }
7981: }
7982: return \%savedState;
7983: }
1.76 ng 7984:
1.443 banghart 7985: sub grading_menu {
7986: my ($request) = @_;
7987: my ($symb)=&get_symb($request);
7988: if (!$symb) {return '';}
7989: my $probTitle = &Apache::lonnet::gettitle($symb);
7990: my ($table,undef,$hdgrade) = &showResourceInfo($symb,$probTitle);
7991:
1.444 banghart 7992: $request->print($table);
1.443 banghart 7993: my %fields = ('symb'=>&Apache::lonenc::check_encrypt($symb),
7994: 'handgrade'=>$hdgrade,
7995: 'probTitle'=>$probTitle,
7996: 'command'=>'submit_options',
7997: 'saveState'=>"",
7998: 'gradingMenu'=>1,
7999: 'showgrading'=>"yes");
1.538 schulted 8000:
8001: my $url1 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8002:
1.443 banghart 8003: $fields{'command'} = 'csvform';
1.538 schulted 8004: my $url2 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8005:
1.443 banghart 8006: $fields{'command'} = 'processclicker';
1.538 schulted 8007: my $url3 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8008:
1.443 banghart 8009: $fields{'command'} = 'scantron_selectphase';
1.538 schulted 8010: my $url4 = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
8011:
8012: my @menu = ({ categorytitle=>'Course Grading',
8013: items =>[
8014: { linktext => 'Manual Grading/View Submissions',
8015: url => $url1,
8016: permission => 'F',
8017: icon => 'edit-find-replace.png',
8018: linktitle => 'Start the process of hand grading submissions.'
8019: },
8020: { linktext => 'Upload Scores',
8021: url => $url2,
8022: permission => 'F',
8023: icon => 'uploadscores.png',
8024: linktitle => 'Specify a file containing the class scores for current resource.'
8025: },
8026: { linktext => 'Process Clicker',
8027: url => $url3,
8028: permission => 'F',
8029: icon => 'addClickerInfoFile.png',
8030: linktitle => 'Specify a file containing the clicker information for this resource.'
8031: },
8032: { linktext => 'Grade/Manage/Review Scantron Forms',
8033: url => $url4,
8034: permission => 'F',
8035: icon => 'stat.png',
8036: linktitle => 'Grade scantron exams, upload/download scantron data files, and review previously graded scantron exams.'
8037: }
8038: ]
8039: });
8040:
8041: #$fields{'command'} = 'verify';
8042: #$url = &Apache::lonhtmlcommon::build_url('grades/',\%fields);
1.443 banghart 8043: #
8044: # Create the menu
8045: my $Str;
1.444 banghart 8046: # $Str .= '<h2>'.&mt('Please select a grading task').'</h2>';
1.445 banghart 8047: $Str .= '<form method="post" action="" name="gradingMenu">';
8048: $Str .= '<input type="hidden" name="command" value="" />'.
8049: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
8050: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
1.476 albertel 8051: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.445 banghart 8052: '<input type="hidden" name="saveState" value="" />'."\n".
8053: '<input type="hidden" name="gradingMenu" value="1" />'."\n".
8054: '<input type="hidden" name="showgrading" value="yes" />'."\n";
8055:
1.538 schulted 8056: $Str .= Apache::lonhtmlcommon::generate_menu(@menu);
8057: #$menudata->{'jscript'}
8058: $Str .='<hr /><input type="button" value="'.&mt('Verify Receipt').'" '.
8059: ' onClick="javascript:checkChoice(document.forms.gradingMenu,\'5\',\'verify\')" '.
8060: ' /> '.
8061: &Apache::lonnet::recprefix($env{'request.course.id'}).
8062: '-<input type="text" name="receipt" size="4" onChange="javascript:checkReceiptNo(this.form,\'OK\')" />';
8063:
1.444 banghart 8064: $Str .="</form>\n";
1.539 ! riegler 8065: my $receiptalert = &mt("Please enter a receipt number given by a student in the receipt box.");
1.443 banghart 8066: $request->print(<<GRADINGMENUJS);
8067: <script type="text/javascript" language="javascript">
8068: function checkChoice(formname,val,cmdx) {
8069: if (val <= 2) {
8070: var cmd = radioSelection(formname.radioChoice);
8071: var cmdsave = cmd;
8072: } else {
8073: cmd = cmdx;
8074: cmdsave = 'submission';
8075: }
8076: formname.command.value = cmd;
8077: if (val < 5) formname.submit();
8078: if (val == 5) {
1.458 banghart 8079: if (!checkReceiptNo(formname,'notOK')) {
8080: return false;
8081: } else {
8082: formname.submit();
8083: }
1.445 banghart 8084: }
8085: }
1.443 banghart 8086:
8087: function checkReceiptNo(formname,nospace) {
8088: var receiptNo = formname.receipt.value;
8089: var checkOpt = false;
8090: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
8091: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
8092: if (checkOpt) {
1.539 ! riegler 8093: alert("$receiptalert");
1.443 banghart 8094: formname.receipt.value = "";
8095: formname.receipt.focus();
8096: return false;
8097: }
8098: return true;
8099: }
8100: </script>
8101: GRADINGMENUJS
8102: &commonJSfunctions($request);
8103: return $Str;
8104: }
8105:
8106:
8107: #--- Displays the submissions first page -------
8108: sub submit_options {
1.72 ng 8109: my ($request) = @_;
1.324 albertel 8110: my ($symb)=&get_symb($request);
1.72 ng 8111: if (!$symb) {return '';}
1.76 ng 8112: my $probTitle = &Apache::lonnet::gettitle($symb);
1.72 ng 8113:
1.539 ! riegler 8114: my $receiptalert = &mt("Please enter a receipt number given by a student in the receipt box.");
1.72 ng 8115: $request->print(<<GRADINGMENUJS);
8116: <script type="text/javascript" language="javascript">
1.116 ng 8117: function checkChoice(formname,val,cmdx) {
8118: if (val <= 2) {
8119: var cmd = radioSelection(formname.radioChoice);
1.118 ng 8120: var cmdsave = cmd;
1.116 ng 8121: } else {
8122: cmd = cmdx;
1.118 ng 8123: cmdsave = 'submission';
1.116 ng 8124: }
8125: formname.command.value = cmd;
1.118 ng 8126: formname.saveState.value = "saveCmd="+cmdsave+":saveSec="+pullDownSelection(formname.section)+
1.145 albertel 8127: ":saveSub="+pullDownSelection(formname.submitonly)+":saveStatus="+pullDownSelection(formname.Status);
1.116 ng 8128: if (val < 5) formname.submit();
8129: if (val == 5) {
1.72 ng 8130: if (!checkReceiptNo(formname,'notOK')) { return false;}
8131: formname.submit();
8132: }
1.238 albertel 8133: if (val < 7) formname.submit();
1.72 ng 8134: }
8135:
8136: function checkReceiptNo(formname,nospace) {
8137: var receiptNo = formname.receipt.value;
8138: var checkOpt = false;
8139: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
8140: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
8141: if (checkOpt) {
1.539 ! riegler 8142: alert("$receiptalert");
1.72 ng 8143: formname.receipt.value = "";
8144: formname.receipt.focus();
8145: return false;
8146: }
8147: return true;
8148: }
8149: </script>
8150: GRADINGMENUJS
1.118 ng 8151: &commonJSfunctions($request);
1.324 albertel 8152: my ($table,undef,$hdgrade) = &showResourceInfo($symb,$probTitle);
1.473 albertel 8153: my $result;
1.76 ng 8154: my (undef,$sections) = &getclasslist('all','0');
1.77 ng 8155: my $savedState = &savedState();
1.118 ng 8156: my $saveCmd = ($$savedState{'saveCmd'} eq '' ? 'submission' : $$savedState{'saveCmd'});
1.77 ng 8157: my $saveSec = ($$savedState{'saveSec'} eq '' ? 'all' : $$savedState{'saveSec'});
1.118 ng 8158: my $saveSub = ($$savedState{'saveSub'} eq '' ? 'all' : $$savedState{'saveSub'});
1.77 ng 8159: my $saveStatus = ($$savedState{'saveStatus'} eq '' ? 'Active' : $$savedState{'saveStatus'});
1.72 ng 8160:
1.533 bisitz 8161: # Preselect sections
8162: my $selsec="";
8163: if (ref($sections)) {
8164: foreach my $section (sort(@$sections)) {
8165: $selsec.='<option value="'.$section.'" '.
8166: ($saveSec eq $section ? 'selected="selected"':'').'>'.$section.'</option>'."\n";
8167: }
8168: }
8169:
1.72 ng 8170: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
1.418 albertel 8171: '<input type="hidden" name="symb" value="'.&Apache::lonenc::check_encrypt($symb).'" />'."\n".
1.72 ng 8172: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
8173: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.116 ng 8174: '<input type="hidden" name="command" value="" />'."\n".
1.77 ng 8175: '<input type="hidden" name="saveState" value="" />'."\n".
1.124 ng 8176: '<input type="hidden" name="gradingMenu" value="1" />'."\n".
1.72 ng 8177: '<input type="hidden" name="showgrading" value="yes" />'."\n";
8178:
1.472 albertel 8179: $result.='
1.533 bisitz 8180: <h2>
8181: '.&mt('Grade Current Resource').'
8182: </h2>
8183: <div>
8184: '.$table.'
8185: </div>
8186:
1.537 harmsja 8187: <div class="LC_columnSection">
8188:
1.533 bisitz 8189: <fieldset>
8190: <legend>
8191: '.&mt('Sections').'
8192: </legend>
8193: <select name="section" multiple="multiple" size="5">'."\n";
8194: $result.= $selsec;
1.401 albertel 8195: $result.= '<option value="all" '.($saveSec eq 'all' ? 'selected="selected"' : ''). '>all</option></select> ';
1.472 albertel 8196: $result.='
1.533 bisitz 8197: </fieldset>
1.537 harmsja 8198:
1.533 bisitz 8199: <fieldset>
8200: <legend>
8201: '.&mt('Groups').'
8202: </legend>
8203: '.&Apache::lonstatistics::GroupSelect('group','multiple',5).'
8204: </fieldset>
1.537 harmsja 8205:
1.533 bisitz 8206: <fieldset>
8207: <legend>
8208: '.&mt('Access Status').'
8209: </legend>
8210: '.&Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,5,undef,'mult').'
8211: </fieldset>
1.537 harmsja 8212:
1.533 bisitz 8213: <fieldset>
8214: <legend>
8215: '.&mt('Submission Status').'
8216: </legend>
8217: <select name="submitonly" size="5">
1.473 albertel 8218: <option value="yes" '. ($saveSub eq 'yes' ? 'selected="selected"' : '').'>'.&mt('with submissions').'</option>
8219: <option value="queued" '. ($saveSub eq 'queued' ? 'selected="selected"' : '').'>'.&mt('in grading queue').'</option>
8220: <option value="graded" '. ($saveSub eq 'graded' ? 'selected="selected"' : '').'>'.&mt('with ungraded submissions').'</option>
8221: <option value="incorrect" '.($saveSub eq 'incorrect' ? 'selected="selected"' : '').'>'.&mt('with incorrect submissions').'</option>
8222: <option value="all" '. ($saveSub eq 'all' ? 'selected="selected"' : '').'>'.&mt('with any status').'</option>
1.533 bisitz 8223: </select>
8224: </fieldset>
1.537 harmsja 8225:
1.533 bisitz 8226: </div>
8227:
8228: <br />
8229: <div>
8230: <div>
1.473 albertel 8231: <label>
8232: <input type="radio" name="radioChoice" value="submission" '.
8233: ($saveCmd eq 'submission' ? 'checked="checked"' : '').' /> '.
8234: &mt('Select individual students to grade and view submissions.').'
8235: </label>
8236: </div>
1.533 bisitz 8237: <div>
1.473 albertel 8238: <label>
8239: <input type="radio" name="radioChoice" value="viewgrades" '.
8240: ($saveCmd eq 'viewgrades' ? 'checked="checked"' : '').' /> '.
8241: &mt('Grade all selected students in a grading table.').'
8242: </label>
8243: </div>
1.533 bisitz 8244: <div>
1.539 ! riegler 8245: <input type="button" onClick="javascript:checkChoice(this.form,\'2\');" value="'.&mt('Next').' →" />
1.473 albertel 8246: </div>
1.472 albertel 8247: </div>
1.533 bisitz 8248:
8249:
1.473 albertel 8250: <h2>
8251: '.&mt('Grade Complete Folder for One Student').'
8252: </h2>
1.533 bisitz 8253: <div>
8254: <div>
1.473 albertel 8255: <label>
8256: <input type="radio" name="radioChoice" value="pickStudentPage" '.
8257: ($saveCmd eq 'pickStudentPage' ? 'checked="checked"' : '').' /> '.
8258: &mt('The <b>complete</b> page/sequence/folder: For one student').'
8259: </label>
8260: </div>
1.533 bisitz 8261: <div>
1.539 ! riegler 8262: <input type="button" onClick="javascript:checkChoice(this.form,\'2\');" value="'.&mt('Next').' →" />
1.473 albertel 8263: </div>
1.472 albertel 8264: </div>
8265: </form>';
1.499 albertel 8266: $result .= &show_grading_menu_form($symb);
1.44 ng 8267: return $result;
1.2 albertel 8268: }
8269:
1.285 albertel 8270: sub reset_perm {
8271: undef(%perm);
8272: }
8273:
8274: sub init_perm {
8275: &reset_perm();
1.300 albertel 8276: foreach my $test_perm ('vgr','mgr','opa') {
8277:
8278: my $scope = $env{'request.course.id'};
8279: if (!($perm{$test_perm}=&Apache::lonnet::allowed($test_perm,$scope))) {
8280:
8281: $scope .= '/'.$env{'request.course.sec'};
8282: if ( $perm{$test_perm}=
8283: &Apache::lonnet::allowed($test_perm,$scope)) {
8284: $perm{$test_perm.'_section'}=$env{'request.course.sec'};
8285: } else {
8286: delete($perm{$test_perm});
8287: }
1.285 albertel 8288: }
8289: }
8290: }
8291:
1.400 www 8292: sub gather_clicker_ids {
1.408 albertel 8293: my %clicker_ids;
1.400 www 8294:
8295: my $classlist = &Apache::loncoursedata::get_classlist();
8296:
8297: # Set up a couple variables.
1.407 albertel 8298: my $username_idx = &Apache::loncoursedata::CL_SNAME();
8299: my $domain_idx = &Apache::loncoursedata::CL_SDOM();
1.438 www 8300: my $status_idx = &Apache::loncoursedata::CL_STATUS();
1.400 www 8301:
1.407 albertel 8302: foreach my $student (keys(%$classlist)) {
1.438 www 8303: if ($classlist->{$student}->[$status_idx] ne 'Active') { next; }
1.407 albertel 8304: my $username = $classlist->{$student}->[$username_idx];
8305: my $domain = $classlist->{$student}->[$domain_idx];
1.400 www 8306: my $clickers =
1.408 albertel 8307: (&Apache::lonnet::userenvironment($domain,$username,'clickers'))[1];
1.400 www 8308: foreach my $id (split(/\,/,$clickers)) {
1.414 www 8309: $id=~s/^[\#0]+//;
1.421 www 8310: $id=~s/[\-\:]//g;
1.407 albertel 8311: if (exists($clicker_ids{$id})) {
1.408 albertel 8312: $clicker_ids{$id}.=','.$username.':'.$domain;
1.400 www 8313: } else {
1.408 albertel 8314: $clicker_ids{$id}=$username.':'.$domain;
1.400 www 8315: }
8316: }
8317: }
1.407 albertel 8318: return %clicker_ids;
1.400 www 8319: }
8320:
1.402 www 8321: sub gather_adv_clicker_ids {
1.408 albertel 8322: my %clicker_ids;
1.402 www 8323: my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'};
8324: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
8325: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
1.409 albertel 8326: foreach my $element (sort(keys(%coursepersonnel))) {
1.402 www 8327: foreach my $person (split(/\,/,$coursepersonnel{$element})) {
8328: my ($puname,$pudom)=split(/\:/,$person);
8329: my $clickers =
1.408 albertel 8330: (&Apache::lonnet::userenvironment($pudom,$puname,'clickers'))[1];
1.405 www 8331: foreach my $id (split(/\,/,$clickers)) {
1.414 www 8332: $id=~s/^[\#0]+//;
1.421 www 8333: $id=~s/[\-\:]//g;
1.408 albertel 8334: if (exists($clicker_ids{$id})) {
8335: $clicker_ids{$id}.=','.$puname.':'.$pudom;
8336: } else {
8337: $clicker_ids{$id}=$puname.':'.$pudom;
8338: }
1.405 www 8339: }
1.402 www 8340: }
8341: }
1.407 albertel 8342: return %clicker_ids;
1.402 www 8343: }
8344:
1.413 www 8345: sub clicker_grading_parameters {
8346: return ('gradingmechanism' => 'scalar',
8347: 'upfiletype' => 'scalar',
8348: 'specificid' => 'scalar',
8349: 'pcorrect' => 'scalar',
8350: 'pincorrect' => 'scalar');
8351: }
8352:
1.400 www 8353: sub process_clicker {
8354: my ($r)=@_;
8355: my ($symb)=&get_symb($r);
8356: if (!$symb) {return '';}
8357: my $result=&checkforfile_js();
8358: $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
8359: my ($table) = &showResourceInfo($symb,$env{'form.probTitle'});
8360: $result.=$table;
8361: $result.='<br /><table width="100%" border="0"><tr><td bgcolor="#777777">'."\n";
8362: $result.='<table width="100%" border="0"><tr bgcolor="#e6ffff"><td>'."\n";
1.538 schulted 8363: $result.=' <b>'.&mt('Specify a file containing the clicker information for this resource.').
8364: '</b></td></tr>'."\n";
1.400 www 8365: $result.='<tr bgcolor=#ffffe6><td>'."\n";
1.413 www 8366: # Attempt to restore parameters from last session, set defaults if not present
8367: my %Saveable_Parameters=&clicker_grading_parameters();
8368: &Apache::loncommon::restore_course_settings('grades_clicker',
8369: \%Saveable_Parameters);
8370: if (!$env{'form.pcorrect'}) { $env{'form.pcorrect'}=100; }
8371: if (!$env{'form.pincorrect'}) { $env{'form.pincorrect'}=100; }
8372: if (!$env{'form.gradingmechanism'}) { $env{'form.gradingmechanism'}='attendance'; }
8373: if (!$env{'form.upfiletype'}) { $env{'form.upfiletype'}='iclicker'; }
8374:
8375: my %checked;
1.521 www 8376: foreach my $gradingmechanism ('attendance','personnel','specific','given') {
1.413 www 8377: if ($env{'form.gradingmechanism'} eq $gradingmechanism) {
8378: $checked{$gradingmechanism}="checked='checked'";
8379: }
8380: }
8381:
1.400 www 8382: my $upload=&mt("Upload File");
8383: my $type=&mt("Type");
1.402 www 8384: my $attendance=&mt("Award points just for participation");
8385: my $personnel=&mt("Correctness determined from response by course personnel");
1.414 www 8386: my $specific=&mt("Correctness determined from response with clicker ID(s)");
1.521 www 8387: my $given=&mt("Correctness determined from given list of answers").' '.
8388: '<font size="-2"><tt>('.&mt("Provide comma-separated list. Use '*' for any answer correct, '-' for skip").')</tt></font>';
1.402 www 8389: my $pcorrect=&mt("Percentage points for correct solution");
8390: my $pincorrect=&mt("Percentage points for incorrect solution");
1.413 www 8391: my $selectform=&Apache::loncommon::select_form($env{'form.upfiletype'},'upfiletype',
1.419 www 8392: ('iclicker' => 'i>clicker',
8393: 'interwrite' => 'interwrite PRS'));
1.418 albertel 8394: $symb = &Apache::lonenc::check_encrypt($symb);
1.400 www 8395: $result.=<<ENDUPFORM;
1.402 www 8396: <script type="text/javascript">
8397: function sanitycheck() {
8398: // Accept only integer percentages
8399: document.forms.gradesupload.pcorrect.value=Math.round(document.forms.gradesupload.pcorrect.value);
8400: document.forms.gradesupload.pincorrect.value=Math.round(document.forms.gradesupload.pincorrect.value);
8401: // Find out grading choice
8402: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
8403: if (document.forms.gradesupload.gradingmechanism[i].checked) {
8404: gradingchoice=document.forms.gradesupload.gradingmechanism[i].value;
8405: }
8406: }
8407: // By default, new choice equals user selection
8408: newgradingchoice=gradingchoice;
8409: // Not good to give more points for false answers than correct ones
8410: if (Math.round(document.forms.gradesupload.pcorrect.value)<Math.round(document.forms.gradesupload.pincorrect.value)) {
8411: document.forms.gradesupload.pcorrect.value=document.forms.gradesupload.pincorrect.value;
8412: }
8413: // If new choice is attendance only, and old choice was correctness-based, restore defaults
8414: if ((gradingchoice=='attendance') && (document.forms.gradesupload.waschecked.value!='attendance')) {
8415: document.forms.gradesupload.pcorrect.value=100;
8416: document.forms.gradesupload.pincorrect.value=100;
8417: }
8418: // If the values are different, cannot be attendance only
8419: if ((Math.round(document.forms.gradesupload.pcorrect.value)!=Math.round(document.forms.gradesupload.pincorrect.value)) &&
8420: (gradingchoice=='attendance')) {
8421: newgradingchoice='personnel';
8422: }
8423: // Change grading choice to new one
8424: for (i=0; i<document.forms.gradesupload.gradingmechanism.length; i++) {
8425: if (document.forms.gradesupload.gradingmechanism[i].value==newgradingchoice) {
8426: document.forms.gradesupload.gradingmechanism[i].checked=true;
8427: } else {
8428: document.forms.gradesupload.gradingmechanism[i].checked=false;
8429: }
8430: }
8431: // Remember the old state
8432: document.forms.gradesupload.waschecked.value=newgradingchoice;
8433: }
8434: </script>
1.400 www 8435: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
8436: <input type="hidden" name="symb" value="$symb" />
8437: <input type="hidden" name="command" value="processclickerfile" />
8438: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
8439: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
8440: <input type="file" name="upfile" size="50" />
8441: <br /><label>$type: $selectform</label>
1.451 albertel 8442: <br /><label><input type="radio" name="gradingmechanism" value="attendance" $checked{'attendance'} onClick="sanitycheck()" />$attendance </label>
8443: <br /><label><input type="radio" name="gradingmechanism" value="personnel" $checked{'personnel'} onClick="sanitycheck()" />$personnel</label>
8444: <br /><label><input type="radio" name="gradingmechanism" value="specific" $checked{'specific'} onClick="sanitycheck()" />$specific </label>
1.414 www 8445: <input type="text" name="specificid" value="$env{'form.specificid'}" size="20" />
1.521 www 8446: <br /><label><input type="radio" name="gradingmechanism" value="given" $checked{'given'} onClick="sanitycheck()" />$given </label>
8447: <br />
8448: <input type="text" name="givenanswer" size="50" />
1.413 www 8449: <input type="hidden" name="waschecked" value="$env{'form.gradingmechanism'}" />
8450: <br /><label>$pcorrect: <input type="text" name="pcorrect" size="4" value="$env{'form.pcorrect'}" onChange="sanitycheck()" /></label>
8451: <br /><label>$pincorrect: <input type="text" name="pincorrect" size="4" value="$env{'form.pincorrect'}" onChange="sanitycheck()" /></label>
1.400 www 8452: <br /><input type="button" onClick="javascript:checkUpload(this.form);" value="$upload" />
8453: </form>
8454: ENDUPFORM
8455: $result.='</td></tr></table>'."\n".
8456: '</td></tr></table><br /><br />'."\n";
8457: $result.=&show_grading_menu_form($symb);
8458: return $result;
8459: }
8460:
8461: sub process_clicker_file {
8462: my ($r)=@_;
8463: my ($symb)=&get_symb($r);
8464: if (!$symb) {return '';}
1.413 www 8465:
8466: my %Saveable_Parameters=&clicker_grading_parameters();
8467: &Apache::loncommon::store_course_settings('grades_clicker',
8468: \%Saveable_Parameters);
8469:
1.400 www 8470: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.404 www 8471: if (($env{'form.gradingmechanism'} eq 'specific') && ($env{'form.specificid'}!~/\w/)) {
1.408 albertel 8472: $result.='<span class="LC_error">'.&mt('You need to specify a clicker ID for the correct answer').'</span>';
8473: return $result.&show_grading_menu_form($symb);
1.404 www 8474: }
1.522 www 8475: if (($env{'form.gradingmechanism'} eq 'given') && ($env{'form.givenanswer'}!~/\S/)) {
1.521 www 8476: $result.='<span class="LC_error">'.&mt('You need to specify the correct answer').'</span>';
8477: return $result.&show_grading_menu_form($symb);
8478: }
1.522 www 8479: my $foundgiven=0;
1.521 www 8480: if ($env{'form.gradingmechanism'} eq 'given') {
8481: $env{'form.givenanswer'}=~s/^\s*//gs;
8482: $env{'form.givenanswer'}=~s/\s*$//gs;
8483: $env{'form.givenanswer'}=~s/[^a-zA-Z0-9\.\*\-]+/\,/g;
8484: $env{'form.givenanswer'}=uc($env{'form.givenanswer'});
1.522 www 8485: my @answers=split(/\,/,$env{'form.givenanswer'});
8486: $foundgiven=$#answers+1;
1.521 www 8487: }
1.407 albertel 8488: my %clicker_ids=&gather_clicker_ids();
1.408 albertel 8489: my %correct_ids;
1.404 www 8490: if ($env{'form.gradingmechanism'} eq 'personnel') {
1.408 albertel 8491: %correct_ids=&gather_adv_clicker_ids();
1.404 www 8492: }
8493: if ($env{'form.gradingmechanism'} eq 'specific') {
1.414 www 8494: foreach my $correct_id (split(/[\s\,]/,$env{'form.specificid'})) {;
8495: $correct_id=~tr/a-z/A-Z/;
8496: $correct_id=~s/\s//gs;
8497: $correct_id=~s/^[\#0]+//;
1.421 www 8498: $correct_id=~s/[\-\:]//g;
1.414 www 8499: if ($correct_id) {
8500: $correct_ids{$correct_id}='specified';
8501: }
8502: }
1.400 www 8503: }
1.404 www 8504: if ($env{'form.gradingmechanism'} eq 'attendance') {
1.408 albertel 8505: $result.=&mt('Score based on attendance only');
1.521 www 8506: } elsif ($env{'form.gradingmechanism'} eq 'given') {
1.522 www 8507: $result.=&mt('Score based on [_1] ([_2] answers)','<tt>'.$env{'form.givenanswer'}.'</tt>',$foundgiven);
1.404 www 8508: } else {
1.408 albertel 8509: my $number=0;
1.411 www 8510: $result.='<p><b>'.&mt('Correctness determined by the following IDs').'</b>';
1.408 albertel 8511: foreach my $id (sort(keys(%correct_ids))) {
1.411 www 8512: $result.='<br /><tt>'.$id.'</tt> - ';
1.408 albertel 8513: if ($correct_ids{$id} eq 'specified') {
8514: $result.=&mt('specified');
8515: } else {
8516: my ($uname,$udom)=split(/\:/,$correct_ids{$id});
8517: $result.=&Apache::loncommon::plainname($uname,$udom);
8518: }
8519: $number++;
8520: }
1.411 www 8521: $result.="</p>\n";
1.408 albertel 8522: if ($number==0) {
8523: $result.='<span class="LC_error">'.&mt('No IDs found to determine correct answer').'</span>';
8524: return $result.&show_grading_menu_form($symb);
8525: }
1.404 www 8526: }
1.405 www 8527: if (length($env{'form.upfile'}) < 2) {
1.407 albertel 8528: $result.=&mt('[_1] Error: [_2] The file you attempted to upload, [_3] contained no information. Please check that you entered the correct filename.',
8529: '<span class="LC_error">',
8530: '</span>',
8531: '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>');
1.405 www 8532: return $result.&show_grading_menu_form($symb);
8533: }
1.410 www 8534:
8535: # Were able to get all the info needed, now analyze the file
8536:
1.411 www 8537: $result.=&Apache::loncommon::studentbrowser_javascript();
1.418 albertel 8538: $symb = &Apache::lonenc::check_encrypt($symb);
1.410 www 8539: my $heading=&mt('Scanning clicker file');
8540: $result.=(<<ENDHEADER);
8541: <br /><table width="100%" border="0"><tr><td bgcolor="#777777">
8542: <table width="100%" border="0"><tr bgcolor="#e6ffff"><td>
8543: <b>$heading</b></td></tr><tr bgcolor=#ffffe6><td>
8544: <form method="post" action="/adm/grades" name="clickeranalysis">
8545: <input type="hidden" name="symb" value="$symb" />
8546: <input type="hidden" name="command" value="assignclickergrades" />
8547: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
8548: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
1.411 www 8549: <input type="hidden" name="gradingmechanism" value="$env{'form.gradingmechanism'}" />
8550: <input type="hidden" name="pcorrect" value="$env{'form.pcorrect'}" />
8551: <input type="hidden" name="pincorrect" value="$env{'form.pincorrect'}" />
1.410 www 8552: ENDHEADER
1.522 www 8553: if ($env{'form.gradingmechanism'} eq 'given') {
8554: $result.='<input type="hidden" name="correct:given" value="'.$env{'form.givenanswer'}.'" />';
8555: }
1.408 albertel 8556: my %responses;
8557: my @questiontitles;
1.405 www 8558: my $errormsg='';
8559: my $number=0;
8560: if ($env{'form.upfiletype'} eq 'iclicker') {
1.408 albertel 8561: ($errormsg,$number)=&iclicker_eval(\@questiontitles,\%responses);
1.406 www 8562: }
1.419 www 8563: if ($env{'form.upfiletype'} eq 'interwrite') {
8564: ($errormsg,$number)=&interwrite_eval(\@questiontitles,\%responses);
8565: }
1.411 www 8566: $result.='<br />'.&mt('Found [_1] question(s)',$number).'<br />'.
8567: '<input type="hidden" name="number" value="'.$number.'" />'.
8568: &mt('Awarding [_1] percent for correct and [_2] percent for incorrect responses',
8569: $env{'form.pcorrect'},$env{'form.pincorrect'}).
8570: '<br />';
1.522 www 8571: if (($env{'form.gradingmechanism'} eq 'given') && ($number!=$foundgiven)) {
8572: $result.='<span class="LC_error">'.&mt('Number of given answers does not agree with number of questions in file.').'</span>';
8573: return $result.&show_grading_menu_form($symb);
8574: }
1.414 www 8575: # Remember Question Titles
8576: # FIXME: Possibly need delimiter other than ":"
8577: for (my $i=0;$i<$number;$i++) {
8578: $result.='<input type="hidden" name="question:'.$i.'" value="'.
8579: &HTML::Entities::encode($questiontitles[$i],'"&<>').'" />';
8580: }
1.411 www 8581: my $correct_count=0;
8582: my $student_count=0;
8583: my $unknown_count=0;
1.414 www 8584: # Match answers with usernames
8585: # FIXME: Possibly need delimiter other than ":"
1.409 albertel 8586: foreach my $id (keys(%responses)) {
1.410 www 8587: if ($correct_ids{$id}) {
1.414 www 8588: $result.="\n".'<input type="hidden" name="correct:'.$correct_count.':'.$correct_ids{$id}.'" value="'.$responses{$id}.'" />';
1.411 www 8589: $correct_count++;
1.410 www 8590: } elsif ($clicker_ids{$id}) {
1.437 www 8591: if ($clicker_ids{$id}=~/\,/) {
8592: # More than one user with the same clicker!
8593: $result.="\n<hr />".&mt('Clicker registered more than once').": <tt>".$id."</tt><br />";
8594: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
8595: "<select name='multi".$id."'>";
8596: foreach my $reguser (sort(split(/\,/,$clicker_ids{$id}))) {
8597: $result.="<option value='".$reguser."'>".&Apache::loncommon::plainname(split(/\:/,$reguser)).' ('.$reguser.')</option>';
8598: }
8599: $result.='</select>';
8600: $unknown_count++;
8601: } else {
8602: # Good: found one and only one user with the right clicker
8603: $result.="\n".'<input type="hidden" name="student:'.$clicker_ids{$id}.'" value="'.$responses{$id}.'" />';
8604: $student_count++;
8605: }
1.410 www 8606: } else {
1.411 www 8607: $result.="\n<hr />".&mt('Unregistered Clicker')." <tt>".$id."</tt><br />";
8608: $result.="\n".'<input type="hidden" name="unknown:'.$id.'" value="'.$responses{$id}.'" />'.
8609: "\n".&mt("Username").": <input type='text' name='uname".$id."' /> ".
8610: "\n".&mt("Domain").": ".
8611: &Apache::loncommon::select_dom_form($env{'course.'.$env{'request.course.id'}.'.domain'},'udom'.$id).' '.
8612: &Apache::loncommon::selectstudent_link('clickeranalysis','uname'.$id,'udom'.$id);
8613: $unknown_count++;
1.410 www 8614: }
1.405 www 8615: }
1.412 www 8616: $result.='<hr />'.
8617: &mt('Found [_1] registered and [_2] unregistered clickers.',$student_count,$unknown_count);
1.521 www 8618: if (($env{'form.gradingmechanism'} ne 'attendance') && ($env{'form.gradingmechanism'} ne 'given')) {
1.412 www 8619: if ($correct_count==0) {
8620: $errormsg.="Found no correct answers answers for grading!";
8621: } elsif ($correct_count>1) {
1.414 www 8622: $result.='<br /><span class="LC_warning">'.&mt("Found [_1] entries for grading!",$correct_count).'</span>';
1.412 www 8623: }
8624: }
1.428 www 8625: if ($number<1) {
8626: $errormsg.="Found no questions.";
8627: }
1.412 www 8628: if ($errormsg) {
8629: $result.='<br /><span class="LC_error">'.&mt($errormsg).'</span>';
8630: } else {
8631: $result.='<br /><input type="submit" name="finalize" value="'.&mt('Finalize Grading').'" />';
8632: }
8633: $result.='</form></td></tr></table>'."\n".
1.410 www 8634: '</td></tr></table><br /><br />'."\n";
1.404 www 8635: return $result.&show_grading_menu_form($symb);
1.400 www 8636: }
8637:
1.405 www 8638: sub iclicker_eval {
1.406 www 8639: my ($questiontitles,$responses)=@_;
1.405 www 8640: my $number=0;
8641: my $errormsg='';
8642: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
1.410 www 8643: my %components=&Apache::loncommon::record_sep($line);
8644: my @entries=map {$components{$_}} (sort(keys(%components)));
1.408 albertel 8645: if ($entries[0] eq 'Question') {
8646: for (my $i=3;$i<$#entries;$i+=6) {
8647: $$questiontitles[$number]=$entries[$i];
8648: $number++;
8649: }
8650: }
8651: if ($entries[0]=~/^\#/) {
8652: my $id=$entries[0];
8653: my @idresponses;
8654: $id=~s/^[\#0]+//;
8655: for (my $i=0;$i<$number;$i++) {
8656: my $idx=3+$i*6;
8657: push(@idresponses,$entries[$idx]);
8658: }
8659: $$responses{$id}=join(',',@idresponses);
8660: }
1.405 www 8661: }
8662: return ($errormsg,$number);
8663: }
8664:
1.419 www 8665: sub interwrite_eval {
8666: my ($questiontitles,$responses)=@_;
8667: my $number=0;
8668: my $errormsg='';
1.420 www 8669: my $skipline=1;
8670: my $questionnumber=0;
8671: my %idresponses=();
1.419 www 8672: foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
8673: my %components=&Apache::loncommon::record_sep($line);
8674: my @entries=map {$components{$_}} (sort(keys(%components)));
1.420 www 8675: if ($entries[1] eq 'Time') { $skipline=0; next; }
8676: if ($entries[1] eq 'Response') { $skipline=1; }
8677: next if $skipline;
8678: if ($entries[0]!=$questionnumber) {
8679: $questionnumber=$entries[0];
8680: $$questiontitles[$number]=&mt('Question [_1]',$questionnumber);
8681: $number++;
1.419 www 8682: }
1.420 www 8683: my $id=$entries[4];
8684: $id=~s/^[\#0]+//;
1.421 www 8685: $id=~s/^v\d*\://i;
8686: $id=~s/[\-\:]//g;
1.420 www 8687: $idresponses{$id}[$number]=$entries[6];
8688: }
1.524 raeburn 8689: foreach my $id (keys(%idresponses)) {
1.420 www 8690: $$responses{$id}=join(',',@{$idresponses{$id}});
8691: $$responses{$id}=~s/^\s*\,//;
1.419 www 8692: }
8693: return ($errormsg,$number);
8694: }
8695:
1.414 www 8696: sub assign_clicker_grades {
8697: my ($r)=@_;
8698: my ($symb)=&get_symb($r);
8699: if (!$symb) {return '';}
1.416 www 8700: # See which part we are saving to
8701: my ($partlist,$handgrade,$responseType) = &response_type($symb);
8702: # FIXME: This should probably look for the first handgradeable part
8703: my $part=$$partlist[0];
8704: # Start screen output
1.414 www 8705: my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
1.416 www 8706:
1.414 www 8707: my $heading=&mt('Assigning grades based on clicker file');
8708: $result.=(<<ENDHEADER);
8709: <br /><table width="100%" border="0"><tr><td bgcolor="#777777">
8710: <table width="100%" border="0"><tr bgcolor="#e6ffff"><td>
8711: <b>$heading</b></td></tr><tr bgcolor=#ffffe6><td>
8712: ENDHEADER
8713: # Get correct result
8714: # FIXME: Possibly need delimiter other than ":"
8715: my @correct=();
1.415 www 8716: my $gradingmechanism=$env{'form.gradingmechanism'};
8717: my $number=$env{'form.number'};
8718: if ($gradingmechanism ne 'attendance') {
1.414 www 8719: foreach my $key (keys(%env)) {
8720: if ($key=~/^form\.correct\:/) {
8721: my @input=split(/\,/,$env{$key});
8722: for (my $i=0;$i<=$#input;$i++) {
8723: if (($correct[$i]) && ($input[$i]) &&
8724: ($correct[$i] ne $input[$i])) {
8725: $result.='<br /><span class="LC_warning">'.
8726: &mt('More than one correct result given for question "[_1]": [_2] versus [_3].',
8727: $env{'form.question:'.$i},$correct[$i],$input[$i]).'</span>';
8728: } elsif ($input[$i]) {
8729: $correct[$i]=$input[$i];
8730: }
8731: }
8732: }
8733: }
1.415 www 8734: for (my $i=0;$i<$number;$i++) {
1.414 www 8735: if (!$correct[$i]) {
8736: $result.='<br /><span class="LC_error">'.
8737: &mt('No correct result given for question "[_1]"!',
8738: $env{'form.question:'.$i}).'</span>';
8739: }
8740: }
8741: $result.='<br />'.&mt("Correct answer: [_1]",join(', ',map { ($_?$_:'-') } @correct));
8742: }
8743: # Start grading
1.415 www 8744: my $pcorrect=$env{'form.pcorrect'};
8745: my $pincorrect=$env{'form.pincorrect'};
1.416 www 8746: my $storecount=0;
1.415 www 8747: foreach my $key (keys(%env)) {
1.420 www 8748: my $user='';
1.415 www 8749: if ($key=~/^form\.student\:(.*)$/) {
1.420 www 8750: $user=$1;
8751: }
8752: if ($key=~/^form\.unknown\:(.*)$/) {
8753: my $id=$1;
8754: if (($env{'form.uname'.$id}) && ($env{'form.udom'.$id})) {
8755: $user=$env{'form.uname'.$id}.':'.$env{'form.udom'.$id};
1.437 www 8756: } elsif ($env{'form.multi'.$id}) {
8757: $user=$env{'form.multi'.$id};
1.420 www 8758: }
8759: }
8760: if ($user) {
1.415 www 8761: my @answer=split(/\,/,$env{$key});
8762: my $sum=0;
1.522 www 8763: my $realnumber=$number;
1.415 www 8764: for (my $i=0;$i<$number;$i++) {
8765: if ($answer[$i]) {
8766: if ($gradingmechanism eq 'attendance') {
8767: $sum+=$pcorrect;
1.522 www 8768: } elsif ($answer[$i] eq '*') {
8769: $sum+=$pcorrect;
8770: } elsif ($answer[$i] eq '-') {
8771: $realnumber--;
1.415 www 8772: } else {
8773: if ($answer[$i] eq $correct[$i]) {
8774: $sum+=$pcorrect;
8775: } else {
8776: $sum+=$pincorrect;
8777: }
8778: }
8779: }
8780: }
1.522 www 8781: my $ave=$sum/(100*$realnumber);
1.416 www 8782: # Store
8783: my ($username,$domain)=split(/\:/,$user);
8784: my %grades=();
8785: $grades{"resource.$part.solved"}='correct_by_override';
8786: $grades{"resource.$part.awarded"}=$ave;
8787: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
8788: my $returncode=&Apache::lonnet::cstore(\%grades,$symb,
8789: $env{'request.course.id'},
8790: $domain,$username);
8791: if ($returncode ne 'ok') {
8792: $result.="<br /><span class=\"LC_error\">Failed to save student $username:$domain. Message when trying to save was ($returncode)</span>";
8793: } else {
8794: $storecount++;
8795: }
1.415 www 8796: }
8797: }
8798: # We are done
1.416 www 8799: $result.='<br />'.&mt('Successfully stored grades for [_1] student(s).',$storecount).
8800: '</td></tr></table>'."\n".
1.414 www 8801: '</td></tr></table><br /><br />'."\n";
8802: return $result.&show_grading_menu_form($symb);
8803: }
8804:
1.1 albertel 8805: sub handler {
1.41 ng 8806: my $request=$_[0];
1.434 albertel 8807: &reset_caches();
1.257 albertel 8808: if ($env{'browser.mathml'}) {
1.141 www 8809: &Apache::loncommon::content_type($request,'text/xml');
1.41 ng 8810: } else {
1.141 www 8811: &Apache::loncommon::content_type($request,'text/html');
1.41 ng 8812: }
8813: $request->send_http_header;
1.44 ng 8814: return '' if $request->header_only;
1.41 ng 8815: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.324 albertel 8816: my $symb=&get_symb($request,1);
1.160 albertel 8817: my @commands=&Apache::loncommon::get_env_multiple('form.command');
8818: my $command=$commands[0];
1.447 foxr 8819:
1.160 albertel 8820: if ($#commands > 0) {
8821: &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands));
8822: }
1.447 foxr 8823:
1.513 foxr 8824: $ssi_error = 0;
1.535 raeburn 8825: my $brcrum = [{href=>"/adm/grades",text=>"Grading"}];
8826: $request->print(&Apache::loncommon::start_page('Grading',undef,
8827: {'bread_crumbs' => $brcrum}));
1.324 albertel 8828: if ($symb eq '' && $command eq '') {
1.257 albertel 8829: if ($env{'user.adv'}) {
8830: if (($env{'form.codeone'}) && ($env{'form.codetwo'}) &&
8831: ($env{'form.codethree'})) {
8832: my $token=$env{'form.codeone'}.'*'.$env{'form.codetwo'}.'*'.
8833: $env{'form.codethree'};
1.41 ng 8834: my ($tsymb,$tuname,$tudom,$tcrsid)=
8835: &Apache::lonnet::checkin($token);
8836: if ($tsymb) {
1.137 albertel 8837: my ($map,$id,$url)=&Apache::lonnet::decode_symb($tsymb);
1.41 ng 8838: if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
1.513 foxr 8839: $request->print(&ssi_with_retries('/res/'.$url, $ssi_retries,
1.99 albertel 8840: ('grade_username' => $tuname,
8841: 'grade_domain' => $tudom,
8842: 'grade_courseid' => $tcrsid,
8843: 'grade_symb' => $tsymb)));
1.41 ng 8844: } else {
1.45 ng 8845: $request->print('<h3>Not authorized: '.$token.'</h3>');
1.99 albertel 8846: }
1.41 ng 8847: } else {
1.45 ng 8848: $request->print('<h3>Not a valid DocID: '.$token.'</h3>');
1.41 ng 8849: }
1.14 www 8850: } else {
1.41 ng 8851: $request->print(&Apache::lonxml::tokeninputfield());
8852: }
8853: }
8854: } else {
1.285 albertel 8855: &init_perm();
1.104 albertel 8856: if ($command eq 'submission' && $perm{'vgr'}) {
1.257 albertel 8857: ($env{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0));
1.103 albertel 8858: } elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) {
1.68 ng 8859: &pickStudentPage($request);
1.103 albertel 8860: } elsif ($command eq 'displayPage' && $perm{'vgr'}) {
1.68 ng 8861: &displayPage($request);
1.104 albertel 8862: } elsif ($command eq 'gradeByPage' && $perm{'mgr'}) {
1.71 ng 8863: &updateGradeByPage($request);
1.104 albertel 8864: } elsif ($command eq 'processGroup' && $perm{'vgr'}) {
1.41 ng 8865: &processGroup($request);
1.104 albertel 8866: } elsif ($command eq 'gradingmenu' && $perm{'vgr'}) {
1.443 banghart 8867: $request->print(&grading_menu($request));
8868: } elsif ($command eq 'submit_options' && $perm{'vgr'}) {
8869: $request->print(&submit_options($request));
1.104 albertel 8870: } elsif ($command eq 'viewgrades' && $perm{'vgr'}) {
1.41 ng 8871: $request->print(&viewgrades($request));
1.104 albertel 8872: } elsif ($command eq 'handgrade' && $perm{'mgr'}) {
1.41 ng 8873: $request->print(&processHandGrade($request));
1.106 albertel 8874: } elsif ($command eq 'editgrades' && $perm{'mgr'}) {
1.41 ng 8875: $request->print(&editgrades($request));
1.106 albertel 8876: } elsif ($command eq 'verify' && $perm{'vgr'}) {
1.41 ng 8877: $request->print(&verifyreceipt($request));
1.400 www 8878: } elsif ($command eq 'processclicker' && $perm{'mgr'}) {
8879: $request->print(&process_clicker($request));
8880: } elsif ($command eq 'processclickerfile' && $perm{'mgr'}) {
8881: $request->print(&process_clicker_file($request));
1.414 www 8882: } elsif ($command eq 'assignclickergrades' && $perm{'mgr'}) {
8883: $request->print(&assign_clicker_grades($request));
1.106 albertel 8884: } elsif ($command eq 'csvform' && $perm{'mgr'}) {
1.72 ng 8885: $request->print(&upcsvScores_form($request));
1.106 albertel 8886: } elsif ($command eq 'csvupload' && $perm{'mgr'}) {
1.41 ng 8887: $request->print(&csvupload($request));
1.106 albertel 8888: } elsif ($command eq 'csvuploadmap' && $perm{'mgr'} ) {
1.41 ng 8889: $request->print(&csvuploadmap($request));
1.246 albertel 8890: } elsif ($command eq 'csvuploadoptions' && $perm{'mgr'}) {
1.257 albertel 8891: if ($env{'form.associate'} ne 'Reverse Association') {
1.246 albertel 8892: $request->print(&csvuploadoptions($request));
1.41 ng 8893: } else {
1.257 albertel 8894: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
8895: $env{'form.upfile_associate'} = 'reverse';
1.41 ng 8896: } else {
1.257 albertel 8897: $env{'form.upfile_associate'} = 'forward';
1.41 ng 8898: }
8899: $request->print(&csvuploadmap($request));
8900: }
1.246 albertel 8901: } elsif ($command eq 'csvuploadassign' && $perm{'mgr'} ) {
8902: $request->print(&csvuploadassign($request));
1.106 albertel 8903: } elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
1.75 albertel 8904: $request->print(&scantron_selectphase($request));
1.203 albertel 8905: } elsif ($command eq 'scantron_warning' && $perm{'mgr'}) {
8906: $request->print(&scantron_do_warning($request));
1.142 albertel 8907: } elsif ($command eq 'scantron_validate' && $perm{'mgr'}) {
8908: $request->print(&scantron_validate_file($request));
1.106 albertel 8909: } elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
1.82 albertel 8910: $request->print(&scantron_process_students($request));
1.157 albertel 8911: } elsif ($command eq 'scantronupload' &&
1.257 albertel 8912: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
8913: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.162 albertel 8914: $request->print(&scantron_upload_scantron_data($request));
1.157 albertel 8915: } elsif ($command eq 'scantronupload_save' &&
1.257 albertel 8916: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
8917: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.157 albertel 8918: $request->print(&scantron_upload_scantron_data_save($request));
1.202 albertel 8919: } elsif ($command eq 'scantron_download' &&
1.257 albertel 8920: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.162 albertel 8921: $request->print(&scantron_download_scantron_data($request));
1.523 raeburn 8922: } elsif ($command eq 'checksubmissions' && $perm{'vgr'}) {
8923: $request->print(&checkscantron_results($request));
1.106 albertel 8924: } elsif ($command) {
1.157 albertel 8925: $request->print("Access Denied ($command)");
1.26 albertel 8926: }
1.2 albertel 8927: }
1.513 foxr 8928: if ($ssi_error) {
8929: &ssi_print_error($request);
8930: }
1.353 albertel 8931: $request->print(&Apache::loncommon::end_page());
1.434 albertel 8932: &reset_caches();
1.44 ng 8933: return '';
8934: }
8935:
1.1 albertel 8936: 1;
8937:
1.13 albertel 8938: __END__;
1.531 jms 8939:
8940:
8941: =head1 NAME
8942:
8943: Apache::grades
8944:
8945: =head1 SYNOPSIS
8946:
8947: Handles the viewing of grades.
8948:
8949: This is part of the LearningOnline Network with CAPA project
8950: described at http://www.lon-capa.org.
8951:
8952: =head1 OVERVIEW
8953:
8954: Do an ssi with retries:
8955: While I'd love to factor out this with the vesrion in lonprintout,
8956: 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
8957: I'm not quite ready to invent (e.g. an ssi_with_retry object).
8958:
8959: At least the logic that drives this has been pulled out into loncommon.
8960:
8961:
8962:
8963: ssi_with_retries - Does the server side include of a resource.
8964: if the ssi call returns an error we'll retry it up to
8965: the number of times requested by the caller.
8966: If we still have a proble, no text is appended to the
8967: output and we set some global variables.
8968: to indicate to the caller an SSI error occurred.
8969: All of this is supposed to deal with the issues described
8970: in LonCAPA BZ 5631 see:
8971: http://bugs.lon-capa.org/show_bug.cgi?id=5631
8972: by informing the user that this happened.
8973:
8974: Parameters:
8975: resource - The resource to include. This is passed directly, without
8976: interpretation to lonnet::ssi.
8977: form - The form hash parameters that guide the interpretation of the resource
8978:
8979: retries - Number of retries allowed before giving up completely.
8980: Returns:
8981: On success, returns the rendered resource identified by the resource parameter.
8982: Side Effects:
8983: The following global variables can be set:
8984: ssi_error - If an unrecoverable error occurred this becomes true.
8985: It is up to the caller to initialize this to false
8986: if desired.
8987: ssi_error_resource - If an unrecoverable error occurred, this is the value
8988: of the resource that could not be rendered by the ssi
8989: call.
8990: ssi_error_message - The error string fetched from the ssi response
8991: in the event of an error.
8992:
8993:
8994: =head1 HANDLER SUBROUTINE
8995:
8996: ssi_with_retries()
8997:
8998: =head1 SUBROUTINES
8999:
9000: =over
9001:
9002: =item scantron_get_correction() :
9003:
9004: Builds the interface screen to interact with the operator to fix a
9005: specific error condition in a specific scanline
9006:
9007: Arguments:
9008: $r - Apache request object
9009: $i - number of the current scanline
9010: $scan_record - hash ref as returned from &scantron_parse_scanline()
9011: $scan_config - hash ref as returned from &get_scantron_config()
9012: $line - full contents of the current scanline
9013: $error - error condition, valid values are
9014: 'incorrectCODE', 'duplicateCODE',
9015: 'doublebubble', 'missingbubble',
9016: 'duplicateID', 'incorrectID'
9017: $arg - extra information needed
9018: For errors:
9019: - duplicateID - paper number that this studentID was seen before on
9020: - duplicateCODE - array ref of the paper numbers this CODE was
9021: seen on before
9022: - incorrectCODE - current incorrect CODE
9023: - doublebubble - array ref of the bubble lines that have double
9024: bubble errors
9025: - missingbubble - array ref of the bubble lines that have missing
9026: bubble errors
9027:
9028: =item scantron_get_maxbubble() :
9029:
9030: Returns the maximum number of bubble lines that are expected to
9031: occur. Does this by walking the selected sequence rendering the
9032: resource and then checking &Apache::lonxml::get_problem_counter()
9033: for what the current value of the problem counter is.
9034:
9035: Caches the results to $env{'form.scantron_maxbubble'},
9036: $env{'form.scantron.bubble_lines.n'},
9037: $env{'form.scantron.first_bubble_line.n'} and
9038: $env{"form.scantron.sub_bubblelines.n"}
9039: which are the total number of bubble, lines, the number of bubble
9040: lines for response n and number of the first bubble line for response n,
9041: and a comma separated list of numbers of bubble lines for sub-questions
9042: (for optionresponse, matchresponse, and rankresponse items), for response n.
9043:
9044:
9045: =item scantron_validate_missingbubbles() :
9046:
9047: Validates all scanlines in the selected file to not have any
9048: answers that don't have bubbles that have not been verified
9049: to be bubble free.
9050:
9051: =item scantron_process_students() :
9052:
9053: Routine that does the actual grading of the bubble sheet information.
9054:
9055: The parsed scanline hash is added to %env
9056:
9057: Then foreach unskipped scanline it does an &Apache::lonnet::ssi()
9058: foreach resource , with the form data of
9059:
9060: 'submitted' =>'scantron'
9061: 'grade_target' =>'grade',
9062: 'grade_username'=> username of student
9063: 'grade_domain' => domain of student
9064: 'grade_courseid'=> of course
9065: 'grade_symb' => symb of resource to grade
9066:
9067: This triggers a grading pass. The problem grading code takes care
9068: of converting the bubbled letter information (now in %env) into a
9069: valid submission.
9070:
9071: =item scantron_upload_scantron_data() :
9072:
9073: Creates the screen for adding a new bubble sheet data file to a course.
9074:
9075: =item scantron_upload_scantron_data_save() :
9076:
9077: Adds a provided bubble information data file to the course if user
9078: has the correct privileges to do so.
9079:
9080: =item valid_file() :
9081:
9082: Validates that the requested bubble data file exists in the course.
9083:
9084: =item scantron_download_scantron_data() :
9085:
9086: Shows a list of the three internal files (original, corrected,
9087: skipped) for a specific bubble sheet data file that exists in the
9088: course.
9089:
9090: =item scantron_validate_ID() :
9091:
9092: Validates all scanlines in the selected file to not have any
9093: invalid or underspecified student IDs
9094:
9095: =back
9096:
9097: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>